pdf.worker.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.0.647';
  24. PDFJS.build = 'f1c73c2';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  346. function UnknownErrorException(msg, details) {
  347. this.name = 'UnknownErrorException';
  348. this.message = msg;
  349. this.details = details;
  350. }
  351. UnknownErrorException.prototype = new Error();
  352. UnknownErrorException.constructor = UnknownErrorException;
  353. return UnknownErrorException;
  354. })();
  355. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  356. function InvalidPDFException(msg) {
  357. this.name = 'InvalidPDFException';
  358. this.message = msg;
  359. }
  360. InvalidPDFException.prototype = new Error();
  361. InvalidPDFException.constructor = InvalidPDFException;
  362. return InvalidPDFException;
  363. })();
  364. var MissingPDFException = (function MissingPDFExceptionClosure() {
  365. function MissingPDFException(msg) {
  366. this.name = 'MissingPDFException';
  367. this.message = msg;
  368. }
  369. MissingPDFException.prototype = new Error();
  370. MissingPDFException.constructor = MissingPDFException;
  371. return MissingPDFException;
  372. })();
  373. var NotImplementedException = (function NotImplementedExceptionClosure() {
  374. function NotImplementedException(msg) {
  375. this.message = msg;
  376. }
  377. NotImplementedException.prototype = new Error();
  378. NotImplementedException.prototype.name = 'NotImplementedException';
  379. NotImplementedException.constructor = NotImplementedException;
  380. return NotImplementedException;
  381. })();
  382. var MissingDataException = (function MissingDataExceptionClosure() {
  383. function MissingDataException(begin, end) {
  384. this.begin = begin;
  385. this.end = end;
  386. this.message = 'Missing data [' + begin + ', ' + end + ')';
  387. }
  388. MissingDataException.prototype = new Error();
  389. MissingDataException.prototype.name = 'MissingDataException';
  390. MissingDataException.constructor = MissingDataException;
  391. return MissingDataException;
  392. })();
  393. var XRefParseException = (function XRefParseExceptionClosure() {
  394. function XRefParseException(msg) {
  395. this.message = msg;
  396. }
  397. XRefParseException.prototype = new Error();
  398. XRefParseException.prototype.name = 'XRefParseException';
  399. XRefParseException.constructor = XRefParseException;
  400. return XRefParseException;
  401. })();
  402. function bytesToString(bytes) {
  403. var length = bytes.length;
  404. var MAX_ARGUMENT_COUNT = 8192;
  405. if (length < MAX_ARGUMENT_COUNT) {
  406. return String.fromCharCode.apply(null, bytes);
  407. }
  408. var strBuf = [];
  409. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  410. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  411. var chunk = bytes.subarray(i, chunkEnd);
  412. strBuf.push(String.fromCharCode.apply(null, chunk));
  413. }
  414. return strBuf.join('');
  415. }
  416. function stringToBytes(str) {
  417. var length = str.length;
  418. var bytes = new Uint8Array(length);
  419. for (var i = 0; i < length; ++i) {
  420. bytes[i] = str.charCodeAt(i) & 0xFF;
  421. }
  422. return bytes;
  423. }
  424. function string32(value) {
  425. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  426. (value >> 8) & 0xff, value & 0xff);
  427. }
  428. function log2(x) {
  429. var n = 1, i = 0;
  430. while (x > n) {
  431. n <<= 1;
  432. i++;
  433. }
  434. return i;
  435. }
  436. function readInt8(data, start) {
  437. return (data[start] << 24) >> 24;
  438. }
  439. function readUint16(data, offset) {
  440. return (data[offset] << 8) | data[offset + 1];
  441. }
  442. function readUint32(data, offset) {
  443. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  444. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  445. }
  446. // Lazy test the endianness of the platform
  447. // NOTE: This will be 'true' for simulated TypedArrays
  448. function isLittleEndian() {
  449. var buffer8 = new Uint8Array(2);
  450. buffer8[0] = 1;
  451. var buffer16 = new Uint16Array(buffer8.buffer);
  452. return (buffer16[0] === 1);
  453. }
  454. Object.defineProperty(PDFJS, 'isLittleEndian', {
  455. configurable: true,
  456. get: function PDFJS_isLittleEndian() {
  457. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  458. }
  459. });
  460. // Lazy test if the userAgant support CanvasTypedArrays
  461. function hasCanvasTypedArrays() {
  462. var canvas = document.createElement('canvas');
  463. canvas.width = canvas.height = 1;
  464. var ctx = canvas.getContext('2d');
  465. var imageData = ctx.createImageData(1, 1);
  466. return (typeof imageData.data.buffer !== 'undefined');
  467. }
  468. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  469. configurable: true,
  470. get: function PDFJS_hasCanvasTypedArrays() {
  471. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  472. }
  473. });
  474. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  475. function Uint32ArrayView(buffer, length) {
  476. this.buffer = buffer;
  477. this.byteLength = buffer.length;
  478. this.length = length === undefined ? (this.byteLength >> 2) : length;
  479. ensureUint32ArrayViewProps(this.length);
  480. }
  481. Uint32ArrayView.prototype = Object.create(null);
  482. var uint32ArrayViewSetters = 0;
  483. function createUint32ArrayProp(index) {
  484. return {
  485. get: function () {
  486. var buffer = this.buffer, offset = index << 2;
  487. return (buffer[offset] | (buffer[offset + 1] << 8) |
  488. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  489. },
  490. set: function (value) {
  491. var buffer = this.buffer, offset = index << 2;
  492. buffer[offset] = value & 255;
  493. buffer[offset + 1] = (value >> 8) & 255;
  494. buffer[offset + 2] = (value >> 16) & 255;
  495. buffer[offset + 3] = (value >>> 24) & 255;
  496. }
  497. };
  498. }
  499. function ensureUint32ArrayViewProps(length) {
  500. while (uint32ArrayViewSetters < length) {
  501. Object.defineProperty(Uint32ArrayView.prototype,
  502. uint32ArrayViewSetters,
  503. createUint32ArrayProp(uint32ArrayViewSetters));
  504. uint32ArrayViewSetters++;
  505. }
  506. }
  507. return Uint32ArrayView;
  508. })();
  509. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  510. var Util = PDFJS.Util = (function UtilClosure() {
  511. function Util() {}
  512. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  513. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  514. // creating many intermediate strings.
  515. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  516. rgbBuf[1] = rgb[0];
  517. rgbBuf[3] = rgb[1];
  518. rgbBuf[5] = rgb[2];
  519. return rgbBuf.join('');
  520. };
  521. // Concatenates two transformation matrices together and returns the result.
  522. Util.transform = function Util_transform(m1, m2) {
  523. return [
  524. m1[0] * m2[0] + m1[2] * m2[1],
  525. m1[1] * m2[0] + m1[3] * m2[1],
  526. m1[0] * m2[2] + m1[2] * m2[3],
  527. m1[1] * m2[2] + m1[3] * m2[3],
  528. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  529. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  530. ];
  531. };
  532. // For 2d affine transforms
  533. Util.applyTransform = function Util_applyTransform(p, m) {
  534. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  535. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  536. return [xt, yt];
  537. };
  538. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  539. var d = m[0] * m[3] - m[1] * m[2];
  540. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  541. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  542. return [xt, yt];
  543. };
  544. // Applies the transform to the rectangle and finds the minimum axially
  545. // aligned bounding box.
  546. Util.getAxialAlignedBoundingBox =
  547. function Util_getAxialAlignedBoundingBox(r, m) {
  548. var p1 = Util.applyTransform(r, m);
  549. var p2 = Util.applyTransform(r.slice(2, 4), m);
  550. var p3 = Util.applyTransform([r[0], r[3]], m);
  551. var p4 = Util.applyTransform([r[2], r[1]], m);
  552. return [
  553. Math.min(p1[0], p2[0], p3[0], p4[0]),
  554. Math.min(p1[1], p2[1], p3[1], p4[1]),
  555. Math.max(p1[0], p2[0], p3[0], p4[0]),
  556. Math.max(p1[1], p2[1], p3[1], p4[1])
  557. ];
  558. };
  559. Util.inverseTransform = function Util_inverseTransform(m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  562. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  563. };
  564. // Apply a generic 3d matrix M on a 3-vector v:
  565. // | a b c | | X |
  566. // | d e f | x | Y |
  567. // | g h i | | Z |
  568. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  569. // with v as [X,Y,Z]
  570. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  571. return [
  572. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  573. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  574. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  575. ];
  576. };
  577. // This calculation uses Singular Value Decomposition.
  578. // The SVD can be represented with formula A = USV. We are interested in the
  579. // matrix S here because it represents the scale values.
  580. Util.singularValueDecompose2dScale =
  581. function Util_singularValueDecompose2dScale(m) {
  582. var transpose = [m[0], m[2], m[1], m[3]];
  583. // Multiply matrix m with its transpose.
  584. var a = m[0] * transpose[0] + m[1] * transpose[2];
  585. var b = m[0] * transpose[1] + m[1] * transpose[3];
  586. var c = m[2] * transpose[0] + m[3] * transpose[2];
  587. var d = m[2] * transpose[1] + m[3] * transpose[3];
  588. // Solve the second degree polynomial to get roots.
  589. var first = (a + d) / 2;
  590. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  591. var sx = first + second || 1;
  592. var sy = first - second || 1;
  593. // Scale values are the square roots of the eigenvalues.
  594. return [Math.sqrt(sx), Math.sqrt(sy)];
  595. };
  596. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  597. // For coordinate systems whose origin lies in the bottom-left, this
  598. // means normalization to (BL,TR) ordering. For systems with origin in the
  599. // top-left, this means (TL,BR) ordering.
  600. Util.normalizeRect = function Util_normalizeRect(rect) {
  601. var r = rect.slice(0); // clone rect
  602. if (rect[0] > rect[2]) {
  603. r[0] = rect[2];
  604. r[2] = rect[0];
  605. }
  606. if (rect[1] > rect[3]) {
  607. r[1] = rect[3];
  608. r[3] = rect[1];
  609. }
  610. return r;
  611. };
  612. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  613. // intersection of rect1 and rect2. If no intersection, returns 'false'
  614. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  615. Util.intersect = function Util_intersect(rect1, rect2) {
  616. function compare(a, b) {
  617. return a - b;
  618. }
  619. // Order points along the axes
  620. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  621. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  622. result = [];
  623. rect1 = Util.normalizeRect(rect1);
  624. rect2 = Util.normalizeRect(rect2);
  625. // X: first and second points belong to different rectangles?
  626. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  627. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  628. // Intersection must be between second and third points
  629. result[0] = orderedX[1];
  630. result[2] = orderedX[2];
  631. } else {
  632. return false;
  633. }
  634. // Y: first and second points belong to different rectangles?
  635. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  636. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  637. // Intersection must be between second and third points
  638. result[1] = orderedY[1];
  639. result[3] = orderedY[2];
  640. } else {
  641. return false;
  642. }
  643. return result;
  644. };
  645. Util.sign = function Util_sign(num) {
  646. return num < 0 ? -1 : 1;
  647. };
  648. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  649. Array.prototype.push.apply(arr1, arr2);
  650. };
  651. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  652. Array.prototype.unshift.apply(arr1, arr2);
  653. };
  654. Util.extendObj = function extendObj(obj1, obj2) {
  655. for (var key in obj2) {
  656. obj1[key] = obj2[key];
  657. }
  658. };
  659. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  660. name) {
  661. while (dict && !dict.has(name)) {
  662. dict = dict.get('Parent');
  663. }
  664. if (!dict) {
  665. return null;
  666. }
  667. return dict.get(name);
  668. };
  669. Util.inherit = function Util_inherit(sub, base, prototype) {
  670. sub.prototype = Object.create(base.prototype);
  671. sub.prototype.constructor = sub;
  672. for (var prop in prototype) {
  673. sub.prototype[prop] = prototype[prop];
  674. }
  675. };
  676. Util.loadScript = function Util_loadScript(src, callback) {
  677. var script = document.createElement('script');
  678. var loaded = false;
  679. script.setAttribute('src', src);
  680. if (callback) {
  681. script.onload = function() {
  682. if (!loaded) {
  683. callback();
  684. }
  685. loaded = true;
  686. };
  687. }
  688. document.getElementsByTagName('head')[0].appendChild(script);
  689. };
  690. return Util;
  691. })();
  692. /**
  693. * PDF page viewport created based on scale, rotation and offset.
  694. * @class
  695. * @alias PDFJS.PageViewport
  696. */
  697. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  698. /**
  699. * @constructor
  700. * @private
  701. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  702. * @param scale {number} scale of the viewport.
  703. * @param rotation {number} rotations of the viewport in degrees.
  704. * @param offsetX {number} offset X
  705. * @param offsetY {number} offset Y
  706. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  707. */
  708. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  709. this.viewBox = viewBox;
  710. this.scale = scale;
  711. this.rotation = rotation;
  712. this.offsetX = offsetX;
  713. this.offsetY = offsetY;
  714. // creating transform to convert pdf coordinate system to the normal
  715. // canvas like coordinates taking in account scale and rotation
  716. var centerX = (viewBox[2] + viewBox[0]) / 2;
  717. var centerY = (viewBox[3] + viewBox[1]) / 2;
  718. var rotateA, rotateB, rotateC, rotateD;
  719. rotation = rotation % 360;
  720. rotation = rotation < 0 ? rotation + 360 : rotation;
  721. switch (rotation) {
  722. case 180:
  723. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  724. break;
  725. case 90:
  726. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  727. break;
  728. case 270:
  729. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  730. break;
  731. //case 0:
  732. default:
  733. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  734. break;
  735. }
  736. if (dontFlip) {
  737. rotateC = -rotateC; rotateD = -rotateD;
  738. }
  739. var offsetCanvasX, offsetCanvasY;
  740. var width, height;
  741. if (rotateA === 0) {
  742. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  743. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  744. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  745. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  746. } else {
  747. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  748. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  749. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  750. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  751. }
  752. // creating transform for the following operations:
  753. // translate(-centerX, -centerY), rotate and flip vertically,
  754. // scale, and translate(offsetCanvasX, offsetCanvasY)
  755. this.transform = [
  756. rotateA * scale,
  757. rotateB * scale,
  758. rotateC * scale,
  759. rotateD * scale,
  760. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  761. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  762. ];
  763. this.width = width;
  764. this.height = height;
  765. this.fontScale = scale;
  766. }
  767. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  768. /**
  769. * Clones viewport with additional properties.
  770. * @param args {Object} (optional) If specified, may contain the 'scale' or
  771. * 'rotation' properties to override the corresponding properties in
  772. * the cloned viewport.
  773. * @returns {PDFJS.PageViewport} Cloned viewport.
  774. */
  775. clone: function PageViewPort_clone(args) {
  776. args = args || {};
  777. var scale = 'scale' in args ? args.scale : this.scale;
  778. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  779. return new PageViewport(this.viewBox.slice(), scale, rotation,
  780. this.offsetX, this.offsetY, args.dontFlip);
  781. },
  782. /**
  783. * Converts PDF point to the viewport coordinates. For examples, useful for
  784. * converting PDF location into canvas pixel coordinates.
  785. * @param x {number} X coordinate.
  786. * @param y {number} Y coordinate.
  787. * @returns {Object} Object that contains 'x' and 'y' properties of the
  788. * point in the viewport coordinate space.
  789. * @see {@link convertToPdfPoint}
  790. * @see {@link convertToViewportRectangle}
  791. */
  792. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  793. return Util.applyTransform([x, y], this.transform);
  794. },
  795. /**
  796. * Converts PDF rectangle to the viewport coordinates.
  797. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  798. * @returns {Array} Contains corresponding coordinates of the rectangle
  799. * in the viewport coordinate space.
  800. * @see {@link convertToViewportPoint}
  801. */
  802. convertToViewportRectangle:
  803. function PageViewport_convertToViewportRectangle(rect) {
  804. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  805. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  806. return [tl[0], tl[1], br[0], br[1]];
  807. },
  808. /**
  809. * Converts viewport coordinates to the PDF location. For examples, useful
  810. * for converting canvas pixel location into PDF one.
  811. * @param x {number} X coordinate.
  812. * @param y {number} Y coordinate.
  813. * @returns {Object} Object that contains 'x' and 'y' properties of the
  814. * point in the PDF coordinate space.
  815. * @see {@link convertToViewportPoint}
  816. */
  817. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  818. return Util.applyInverseTransform([x, y], this.transform);
  819. }
  820. };
  821. return PageViewport;
  822. })();
  823. var PDFStringTranslateTable = [
  824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  825. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  826. 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,
  827. 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,
  828. 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,
  829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  830. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  831. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  832. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  833. ];
  834. function stringToPDFString(str) {
  835. var i, n = str.length, strBuf = [];
  836. if (str[0] === '\xFE' && str[1] === '\xFF') {
  837. // UTF16BE BOM
  838. for (i = 2; i < n; i += 2) {
  839. strBuf.push(String.fromCharCode(
  840. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  841. }
  842. } else {
  843. for (i = 0; i < n; ++i) {
  844. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  845. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  846. }
  847. }
  848. return strBuf.join('');
  849. }
  850. function stringToUTF8String(str) {
  851. return decodeURIComponent(escape(str));
  852. }
  853. function isEmptyObj(obj) {
  854. for (var key in obj) {
  855. return false;
  856. }
  857. return true;
  858. }
  859. function isBool(v) {
  860. return typeof v === 'boolean';
  861. }
  862. function isInt(v) {
  863. return typeof v === 'number' && ((v | 0) === v);
  864. }
  865. function isNum(v) {
  866. return typeof v === 'number';
  867. }
  868. function isString(v) {
  869. return typeof v === 'string';
  870. }
  871. function isNull(v) {
  872. return v === null;
  873. }
  874. function isName(v) {
  875. return v instanceof Name;
  876. }
  877. function isCmd(v, cmd) {
  878. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  879. }
  880. function isDict(v, type) {
  881. if (!(v instanceof Dict)) {
  882. return false;
  883. }
  884. if (!type) {
  885. return true;
  886. }
  887. var dictType = v.get('Type');
  888. return isName(dictType) && dictType.name === type;
  889. }
  890. function isArray(v) {
  891. return v instanceof Array;
  892. }
  893. function isStream(v) {
  894. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  895. }
  896. function isArrayBuffer(v) {
  897. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  898. }
  899. function isRef(v) {
  900. return v instanceof Ref;
  901. }
  902. /**
  903. * Promise Capability object.
  904. *
  905. * @typedef {Object} PromiseCapability
  906. * @property {Promise} promise - A promise object.
  907. * @property {function} resolve - Fullfills the promise.
  908. * @property {function} reject - Rejects the promise.
  909. */
  910. /**
  911. * Creates a promise capability object.
  912. * @alias PDFJS.createPromiseCapability
  913. *
  914. * @return {PromiseCapability} A capability object contains:
  915. * - a Promise, resolve and reject methods.
  916. */
  917. function createPromiseCapability() {
  918. var capability = {};
  919. capability.promise = new Promise(function (resolve, reject) {
  920. capability.resolve = resolve;
  921. capability.reject = reject;
  922. });
  923. return capability;
  924. }
  925. PDFJS.createPromiseCapability = createPromiseCapability;
  926. /**
  927. * Polyfill for Promises:
  928. * The following promise implementation tries to generally implement the
  929. * Promise/A+ spec. Some notable differences from other promise libaries are:
  930. * - There currently isn't a seperate deferred and promise object.
  931. * - Unhandled rejections eventually show an error if they aren't handled.
  932. *
  933. * Based off of the work in:
  934. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  935. */
  936. (function PromiseClosure() {
  937. if (globalScope.Promise) {
  938. // Promises existing in the DOM/Worker, checking presence of all/resolve
  939. if (typeof globalScope.Promise.all !== 'function') {
  940. globalScope.Promise.all = function (iterable) {
  941. var count = 0, results = [], resolve, reject;
  942. var promise = new globalScope.Promise(function (resolve_, reject_) {
  943. resolve = resolve_;
  944. reject = reject_;
  945. });
  946. iterable.forEach(function (p, i) {
  947. count++;
  948. p.then(function (result) {
  949. results[i] = result;
  950. count--;
  951. if (count === 0) {
  952. resolve(results);
  953. }
  954. }, reject);
  955. });
  956. if (count === 0) {
  957. resolve(results);
  958. }
  959. return promise;
  960. };
  961. }
  962. if (typeof globalScope.Promise.resolve !== 'function') {
  963. globalScope.Promise.resolve = function (value) {
  964. return new globalScope.Promise(function (resolve) { resolve(value); });
  965. };
  966. }
  967. if (typeof globalScope.Promise.reject !== 'function') {
  968. globalScope.Promise.reject = function (reason) {
  969. return new globalScope.Promise(function (resolve, reject) {
  970. reject(reason);
  971. });
  972. };
  973. }
  974. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  975. globalScope.Promise.prototype.catch = function (onReject) {
  976. return globalScope.Promise.prototype.then(undefined, onReject);
  977. };
  978. }
  979. return;
  980. }
  981. var STATUS_PENDING = 0;
  982. var STATUS_RESOLVED = 1;
  983. var STATUS_REJECTED = 2;
  984. // In an attempt to avoid silent exceptions, unhandled rejections are
  985. // tracked and if they aren't handled in a certain amount of time an
  986. // error is logged.
  987. var REJECTION_TIMEOUT = 500;
  988. var HandlerManager = {
  989. handlers: [],
  990. running: false,
  991. unhandledRejections: [],
  992. pendingRejectionCheck: false,
  993. scheduleHandlers: function scheduleHandlers(promise) {
  994. if (promise._status === STATUS_PENDING) {
  995. return;
  996. }
  997. this.handlers = this.handlers.concat(promise._handlers);
  998. promise._handlers = [];
  999. if (this.running) {
  1000. return;
  1001. }
  1002. this.running = true;
  1003. setTimeout(this.runHandlers.bind(this), 0);
  1004. },
  1005. runHandlers: function runHandlers() {
  1006. var RUN_TIMEOUT = 1; // ms
  1007. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1008. while (this.handlers.length > 0) {
  1009. var handler = this.handlers.shift();
  1010. var nextStatus = handler.thisPromise._status;
  1011. var nextValue = handler.thisPromise._value;
  1012. try {
  1013. if (nextStatus === STATUS_RESOLVED) {
  1014. if (typeof handler.onResolve === 'function') {
  1015. nextValue = handler.onResolve(nextValue);
  1016. }
  1017. } else if (typeof handler.onReject === 'function') {
  1018. nextValue = handler.onReject(nextValue);
  1019. nextStatus = STATUS_RESOLVED;
  1020. if (handler.thisPromise._unhandledRejection) {
  1021. this.removeUnhandeledRejection(handler.thisPromise);
  1022. }
  1023. }
  1024. } catch (ex) {
  1025. nextStatus = STATUS_REJECTED;
  1026. nextValue = ex;
  1027. }
  1028. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1029. if (Date.now() >= timeoutAt) {
  1030. break;
  1031. }
  1032. }
  1033. if (this.handlers.length > 0) {
  1034. setTimeout(this.runHandlers.bind(this), 0);
  1035. return;
  1036. }
  1037. this.running = false;
  1038. },
  1039. addUnhandledRejection: function addUnhandledRejection(promise) {
  1040. this.unhandledRejections.push({
  1041. promise: promise,
  1042. time: Date.now()
  1043. });
  1044. this.scheduleRejectionCheck();
  1045. },
  1046. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1047. promise._unhandledRejection = false;
  1048. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1049. if (this.unhandledRejections[i].promise === promise) {
  1050. this.unhandledRejections.splice(i);
  1051. i--;
  1052. }
  1053. }
  1054. },
  1055. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1056. if (this.pendingRejectionCheck) {
  1057. return;
  1058. }
  1059. this.pendingRejectionCheck = true;
  1060. setTimeout(function rejectionCheck() {
  1061. this.pendingRejectionCheck = false;
  1062. var now = Date.now();
  1063. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1064. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1065. var unhandled = this.unhandledRejections[i].promise._value;
  1066. var msg = 'Unhandled rejection: ' + unhandled;
  1067. if (unhandled.stack) {
  1068. msg += '\n' + unhandled.stack;
  1069. }
  1070. warn(msg);
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. if (this.unhandledRejections.length) {
  1076. this.scheduleRejectionCheck();
  1077. }
  1078. }.bind(this), REJECTION_TIMEOUT);
  1079. }
  1080. };
  1081. function Promise(resolver) {
  1082. this._status = STATUS_PENDING;
  1083. this._handlers = [];
  1084. try {
  1085. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1086. } catch (e) {
  1087. this._reject(e);
  1088. }
  1089. }
  1090. /**
  1091. * Builds a promise that is resolved when all the passed in promises are
  1092. * resolved.
  1093. * @param {array} array of data and/or promises to wait for.
  1094. * @return {Promise} New dependant promise.
  1095. */
  1096. Promise.all = function Promise_all(promises) {
  1097. var resolveAll, rejectAll;
  1098. var deferred = new Promise(function (resolve, reject) {
  1099. resolveAll = resolve;
  1100. rejectAll = reject;
  1101. });
  1102. var unresolved = promises.length;
  1103. var results = [];
  1104. if (unresolved === 0) {
  1105. resolveAll(results);
  1106. return deferred;
  1107. }
  1108. function reject(reason) {
  1109. if (deferred._status === STATUS_REJECTED) {
  1110. return;
  1111. }
  1112. results = [];
  1113. rejectAll(reason);
  1114. }
  1115. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1116. var promise = promises[i];
  1117. var resolve = (function(i) {
  1118. return function(value) {
  1119. if (deferred._status === STATUS_REJECTED) {
  1120. return;
  1121. }
  1122. results[i] = value;
  1123. unresolved--;
  1124. if (unresolved === 0) {
  1125. resolveAll(results);
  1126. }
  1127. };
  1128. })(i);
  1129. if (Promise.isPromise(promise)) {
  1130. promise.then(resolve, reject);
  1131. } else {
  1132. resolve(promise);
  1133. }
  1134. }
  1135. return deferred;
  1136. };
  1137. /**
  1138. * Checks if the value is likely a promise (has a 'then' function).
  1139. * @return {boolean} true if value is thenable
  1140. */
  1141. Promise.isPromise = function Promise_isPromise(value) {
  1142. return value && typeof value.then === 'function';
  1143. };
  1144. /**
  1145. * Creates resolved promise
  1146. * @param value resolve value
  1147. * @returns {Promise}
  1148. */
  1149. Promise.resolve = function Promise_resolve(value) {
  1150. return new Promise(function (resolve) { resolve(value); });
  1151. };
  1152. /**
  1153. * Creates rejected promise
  1154. * @param reason rejection value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.reject = function Promise_reject(reason) {
  1158. return new Promise(function (resolve, reject) { reject(reason); });
  1159. };
  1160. Promise.prototype = {
  1161. _status: null,
  1162. _value: null,
  1163. _handlers: null,
  1164. _unhandledRejection: null,
  1165. _updateStatus: function Promise__updateStatus(status, value) {
  1166. if (this._status === STATUS_RESOLVED ||
  1167. this._status === STATUS_REJECTED) {
  1168. return;
  1169. }
  1170. if (status === STATUS_RESOLVED &&
  1171. Promise.isPromise(value)) {
  1172. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1173. this._updateStatus.bind(this, STATUS_REJECTED));
  1174. return;
  1175. }
  1176. this._status = status;
  1177. this._value = value;
  1178. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1179. this._unhandledRejection = true;
  1180. HandlerManager.addUnhandledRejection(this);
  1181. }
  1182. HandlerManager.scheduleHandlers(this);
  1183. },
  1184. _resolve: function Promise_resolve(value) {
  1185. this._updateStatus(STATUS_RESOLVED, value);
  1186. },
  1187. _reject: function Promise_reject(reason) {
  1188. this._updateStatus(STATUS_REJECTED, reason);
  1189. },
  1190. then: function Promise_then(onResolve, onReject) {
  1191. var nextPromise = new Promise(function (resolve, reject) {
  1192. this.resolve = resolve;
  1193. this.reject = reject;
  1194. });
  1195. this._handlers.push({
  1196. thisPromise: this,
  1197. onResolve: onResolve,
  1198. onReject: onReject,
  1199. nextPromise: nextPromise
  1200. });
  1201. HandlerManager.scheduleHandlers(this);
  1202. return nextPromise;
  1203. },
  1204. catch: function Promise_catch(onReject) {
  1205. return this.then(undefined, onReject);
  1206. }
  1207. };
  1208. globalScope.Promise = Promise;
  1209. })();
  1210. var StatTimer = (function StatTimerClosure() {
  1211. function rpad(str, pad, length) {
  1212. while (str.length < length) {
  1213. str += pad;
  1214. }
  1215. return str;
  1216. }
  1217. function StatTimer() {
  1218. this.started = {};
  1219. this.times = [];
  1220. this.enabled = true;
  1221. }
  1222. StatTimer.prototype = {
  1223. time: function StatTimer_time(name) {
  1224. if (!this.enabled) {
  1225. return;
  1226. }
  1227. if (name in this.started) {
  1228. warn('Timer is already running for ' + name);
  1229. }
  1230. this.started[name] = Date.now();
  1231. },
  1232. timeEnd: function StatTimer_timeEnd(name) {
  1233. if (!this.enabled) {
  1234. return;
  1235. }
  1236. if (!(name in this.started)) {
  1237. warn('Timer has not been started for ' + name);
  1238. }
  1239. this.times.push({
  1240. 'name': name,
  1241. 'start': this.started[name],
  1242. 'end': Date.now()
  1243. });
  1244. // Remove timer from started so it can be called again.
  1245. delete this.started[name];
  1246. },
  1247. toString: function StatTimer_toString() {
  1248. var i, ii;
  1249. var times = this.times;
  1250. var out = '';
  1251. // Find the longest name for padding purposes.
  1252. var longest = 0;
  1253. for (i = 0, ii = times.length; i < ii; ++i) {
  1254. var name = times[i]['name'];
  1255. if (name.length > longest) {
  1256. longest = name.length;
  1257. }
  1258. }
  1259. for (i = 0, ii = times.length; i < ii; ++i) {
  1260. var span = times[i];
  1261. var duration = span.end - span.start;
  1262. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1263. }
  1264. return out;
  1265. }
  1266. };
  1267. return StatTimer;
  1268. })();
  1269. PDFJS.createBlob = function createBlob(data, contentType) {
  1270. if (typeof Blob !== 'undefined') {
  1271. return new Blob([data], { type: contentType });
  1272. }
  1273. // Blob builder is deprecated in FF14 and removed in FF18.
  1274. var bb = new MozBlobBuilder();
  1275. bb.append(data);
  1276. return bb.getBlob(contentType);
  1277. };
  1278. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1279. // Blob/createObjectURL is not available, falling back to data schema.
  1280. var digits =
  1281. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1282. return function createObjectURL(data, contentType) {
  1283. if (!PDFJS.disableCreateObjectURL &&
  1284. typeof URL !== 'undefined' && URL.createObjectURL) {
  1285. var blob = PDFJS.createBlob(data, contentType);
  1286. return URL.createObjectURL(blob);
  1287. }
  1288. var buffer = 'data:' + contentType + ';base64,';
  1289. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1290. var b1 = data[i] & 0xFF;
  1291. var b2 = data[i + 1] & 0xFF;
  1292. var b3 = data[i + 2] & 0xFF;
  1293. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1294. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1295. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1296. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1297. }
  1298. return buffer;
  1299. };
  1300. })();
  1301. function MessageHandler(name, comObj) {
  1302. this.name = name;
  1303. this.comObj = comObj;
  1304. this.callbackIndex = 1;
  1305. this.postMessageTransfers = true;
  1306. var callbacksCapabilities = this.callbacksCapabilities = {};
  1307. var ah = this.actionHandler = {};
  1308. ah['console_log'] = [function ahConsoleLog(data) {
  1309. console.log.apply(console, data);
  1310. }];
  1311. ah['console_error'] = [function ahConsoleError(data) {
  1312. console.error.apply(console, data);
  1313. }];
  1314. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1315. UnsupportedManager.notify(data);
  1316. }];
  1317. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1318. var data = event.data;
  1319. if (data.isReply) {
  1320. var callbackId = data.callbackId;
  1321. if (data.callbackId in callbacksCapabilities) {
  1322. var callback = callbacksCapabilities[callbackId];
  1323. delete callbacksCapabilities[callbackId];
  1324. if ('error' in data) {
  1325. callback.reject(data.error);
  1326. } else {
  1327. callback.resolve(data.data);
  1328. }
  1329. } else {
  1330. error('Cannot resolve callback ' + callbackId);
  1331. }
  1332. } else if (data.action in ah) {
  1333. var action = ah[data.action];
  1334. if (data.callbackId) {
  1335. Promise.resolve().then(function () {
  1336. return action[0].call(action[1], data.data);
  1337. }).then(function (result) {
  1338. comObj.postMessage({
  1339. isReply: true,
  1340. callbackId: data.callbackId,
  1341. data: result
  1342. });
  1343. }, function (reason) {
  1344. comObj.postMessage({
  1345. isReply: true,
  1346. callbackId: data.callbackId,
  1347. error: reason
  1348. });
  1349. });
  1350. } else {
  1351. action[0].call(action[1], data.data);
  1352. }
  1353. } else {
  1354. error('Unknown action from worker: ' + data.action);
  1355. }
  1356. };
  1357. }
  1358. MessageHandler.prototype = {
  1359. on: function messageHandlerOn(actionName, handler, scope) {
  1360. var ah = this.actionHandler;
  1361. if (ah[actionName]) {
  1362. error('There is already an actionName called "' + actionName + '"');
  1363. }
  1364. ah[actionName] = [handler, scope];
  1365. },
  1366. /**
  1367. * Sends a message to the comObj to invoke the action with the supplied data.
  1368. * @param {String} actionName Action to call.
  1369. * @param {JSON} data JSON data to send.
  1370. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1371. */
  1372. send: function messageHandlerSend(actionName, data, transfers) {
  1373. var message = {
  1374. action: actionName,
  1375. data: data
  1376. };
  1377. this.postMessage(message, transfers);
  1378. },
  1379. /**
  1380. * Sends a message to the comObj to invoke the action with the supplied data.
  1381. * Expects that other side will callback with the response.
  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. * @returns {Promise} Promise to be resolved with response data.
  1386. */
  1387. sendWithPromise:
  1388. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1389. var callbackId = this.callbackIndex++;
  1390. var message = {
  1391. action: actionName,
  1392. data: data,
  1393. callbackId: callbackId
  1394. };
  1395. var capability = createPromiseCapability();
  1396. this.callbacksCapabilities[callbackId] = capability;
  1397. try {
  1398. this.postMessage(message, transfers);
  1399. } catch (e) {
  1400. capability.reject(e);
  1401. }
  1402. return capability.promise;
  1403. },
  1404. /**
  1405. * Sends raw message to the comObj.
  1406. * @private
  1407. * @param message {Object} Raw message.
  1408. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1409. */
  1410. postMessage: function (message, transfers) {
  1411. if (transfers && this.postMessageTransfers) {
  1412. this.comObj.postMessage(message, transfers);
  1413. } else {
  1414. this.comObj.postMessage(message);
  1415. }
  1416. }
  1417. };
  1418. function loadJpegStream(id, imageUrl, objs) {
  1419. var img = new Image();
  1420. img.onload = (function loadJpegStream_onloadClosure() {
  1421. objs.resolve(id, img);
  1422. });
  1423. img.onerror = (function loadJpegStream_onerrorClosure() {
  1424. objs.resolve(id, null);
  1425. warn('Error during JPEG image loading');
  1426. });
  1427. img.src = imageUrl;
  1428. }
  1429. var NetworkManager = (function NetworkManagerClosure() {
  1430. var OK_RESPONSE = 200;
  1431. var PARTIAL_CONTENT_RESPONSE = 206;
  1432. function NetworkManager(url, args) {
  1433. this.url = url;
  1434. args = args || {};
  1435. this.isHttp = /^https?:/i.test(url);
  1436. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1437. this.withCredentials = args.withCredentials || false;
  1438. this.getXhr = args.getXhr ||
  1439. function NetworkManager_getXhr() {
  1440. return new XMLHttpRequest();
  1441. };
  1442. this.currXhrId = 0;
  1443. this.pendingRequests = {};
  1444. this.loadedRequests = {};
  1445. }
  1446. function getArrayBuffer(xhr) {
  1447. var data = xhr.response;
  1448. if (typeof data !== 'string') {
  1449. return data;
  1450. }
  1451. var length = data.length;
  1452. var buffer = new Uint8Array(length);
  1453. for (var i = 0; i < length; i++) {
  1454. buffer[i] = data.charCodeAt(i) & 0xFF;
  1455. }
  1456. return buffer;
  1457. }
  1458. NetworkManager.prototype = {
  1459. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1460. var args = {
  1461. begin: begin,
  1462. end: end
  1463. };
  1464. for (var prop in listeners) {
  1465. args[prop] = listeners[prop];
  1466. }
  1467. return this.request(args);
  1468. },
  1469. requestFull: function NetworkManager_requestRange(listeners) {
  1470. return this.request(listeners);
  1471. },
  1472. request: function NetworkManager_requestRange(args) {
  1473. var xhr = this.getXhr();
  1474. var xhrId = this.currXhrId++;
  1475. var pendingRequest = this.pendingRequests[xhrId] = {
  1476. xhr: xhr
  1477. };
  1478. xhr.open('GET', this.url);
  1479. xhr.withCredentials = this.withCredentials;
  1480. for (var property in this.httpHeaders) {
  1481. var value = this.httpHeaders[property];
  1482. if (typeof value === 'undefined') {
  1483. continue;
  1484. }
  1485. xhr.setRequestHeader(property, value);
  1486. }
  1487. if (this.isHttp && 'begin' in args && 'end' in args) {
  1488. var rangeStr = args.begin + '-' + (args.end - 1);
  1489. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1490. pendingRequest.expectedStatus = 206;
  1491. } else {
  1492. pendingRequest.expectedStatus = 200;
  1493. }
  1494. xhr.responseType = 'arraybuffer';
  1495. if (args.onProgress) {
  1496. xhr.onprogress = args.onProgress;
  1497. }
  1498. if (args.onError) {
  1499. xhr.onerror = function(evt) {
  1500. args.onError(xhr.status);
  1501. };
  1502. }
  1503. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1504. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1505. pendingRequest.onDone = args.onDone;
  1506. pendingRequest.onError = args.onError;
  1507. xhr.send(null);
  1508. return xhrId;
  1509. },
  1510. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1511. var pendingRequest = this.pendingRequests[xhrId];
  1512. if (!pendingRequest) {
  1513. // Maybe abortRequest was called...
  1514. return;
  1515. }
  1516. var xhr = pendingRequest.xhr;
  1517. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1518. pendingRequest.onHeadersReceived();
  1519. delete pendingRequest.onHeadersReceived;
  1520. }
  1521. if (xhr.readyState !== 4) {
  1522. return;
  1523. }
  1524. if (!(xhrId in this.pendingRequests)) {
  1525. // The XHR request might have been aborted in onHeadersReceived()
  1526. // callback, in which case we should abort request
  1527. return;
  1528. }
  1529. delete this.pendingRequests[xhrId];
  1530. // success status == 0 can be on ftp, file and other protocols
  1531. if (xhr.status === 0 && this.isHttp) {
  1532. if (pendingRequest.onError) {
  1533. pendingRequest.onError(xhr.status);
  1534. }
  1535. return;
  1536. }
  1537. var xhrStatus = xhr.status || OK_RESPONSE;
  1538. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1539. // "A server MAY ignore the Range header". This means it's possible to
  1540. // get a 200 rather than a 206 response from a range request.
  1541. var ok_response_on_range_request =
  1542. xhrStatus === OK_RESPONSE &&
  1543. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1544. if (!ok_response_on_range_request &&
  1545. xhrStatus !== pendingRequest.expectedStatus) {
  1546. if (pendingRequest.onError) {
  1547. pendingRequest.onError(xhr.status);
  1548. }
  1549. return;
  1550. }
  1551. this.loadedRequests[xhrId] = true;
  1552. var chunk = getArrayBuffer(xhr);
  1553. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1554. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1555. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1556. var begin = parseInt(matches[1], 10);
  1557. pendingRequest.onDone({
  1558. begin: begin,
  1559. chunk: chunk
  1560. });
  1561. } else {
  1562. pendingRequest.onDone({
  1563. begin: 0,
  1564. chunk: chunk
  1565. });
  1566. }
  1567. },
  1568. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1569. for (var xhrId in this.pendingRequests) {
  1570. return true;
  1571. }
  1572. return false;
  1573. },
  1574. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1575. return this.pendingRequests[xhrId].xhr;
  1576. },
  1577. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1578. return xhrId in this.pendingRequests;
  1579. },
  1580. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1581. return xhrId in this.loadedRequests;
  1582. },
  1583. abortAllRequests: function NetworkManager_abortAllRequests() {
  1584. for (var xhrId in this.pendingRequests) {
  1585. this.abortRequest(xhrId | 0);
  1586. }
  1587. },
  1588. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1589. var xhr = this.pendingRequests[xhrId].xhr;
  1590. delete this.pendingRequests[xhrId];
  1591. xhr.abort();
  1592. }
  1593. };
  1594. return NetworkManager;
  1595. })();
  1596. var ChunkedStream = (function ChunkedStreamClosure() {
  1597. function ChunkedStream(length, chunkSize, manager) {
  1598. this.bytes = new Uint8Array(length);
  1599. this.start = 0;
  1600. this.pos = 0;
  1601. this.end = length;
  1602. this.chunkSize = chunkSize;
  1603. this.loadedChunks = [];
  1604. this.numChunksLoaded = 0;
  1605. this.numChunks = Math.ceil(length / chunkSize);
  1606. this.manager = manager;
  1607. this.initialDataLength = 0;
  1608. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1609. }
  1610. // required methods for a stream. if a particular stream does not
  1611. // implement these, an error should be thrown
  1612. ChunkedStream.prototype = {
  1613. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1614. var chunks = [];
  1615. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1616. if (!(chunk in this.loadedChunks)) {
  1617. chunks.push(chunk);
  1618. }
  1619. }
  1620. return chunks;
  1621. },
  1622. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1623. return [this];
  1624. },
  1625. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1626. return this.numChunksLoaded === this.numChunks;
  1627. },
  1628. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1629. var end = begin + chunk.byteLength;
  1630. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1631. // Using this.length is inaccurate here since this.start can be moved
  1632. // See ChunkedStream.moveStart()
  1633. var length = this.bytes.length;
  1634. assert(end % this.chunkSize === 0 || end === length,
  1635. 'Bad end offset: ' + end);
  1636. this.bytes.set(new Uint8Array(chunk), begin);
  1637. var chunkSize = this.chunkSize;
  1638. var beginChunk = Math.floor(begin / chunkSize);
  1639. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1640. var curChunk;
  1641. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1642. if (!(curChunk in this.loadedChunks)) {
  1643. this.loadedChunks[curChunk] = true;
  1644. ++this.numChunksLoaded;
  1645. }
  1646. }
  1647. },
  1648. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  1649. this.bytes.set(data);
  1650. this.initialDataLength = data.length;
  1651. var endChunk = (this.end === data.length ?
  1652. this.numChunks : Math.floor(data.length / this.chunkSize));
  1653. for (var i = 0; i < endChunk; i++) {
  1654. this.loadedChunks[i] = true;
  1655. ++this.numChunksLoaded;
  1656. }
  1657. },
  1658. ensureByte: function ChunkedStream_ensureRange(pos) {
  1659. var chunk = Math.floor(pos / this.chunkSize);
  1660. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1661. return;
  1662. }
  1663. if (!(chunk in this.loadedChunks)) {
  1664. throw new MissingDataException(pos, pos + 1);
  1665. }
  1666. this.lastSuccessfulEnsureByteChunk = chunk;
  1667. },
  1668. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1669. if (begin >= end) {
  1670. return;
  1671. }
  1672. if (end <= this.initialDataLength) {
  1673. return;
  1674. }
  1675. var chunkSize = this.chunkSize;
  1676. var beginChunk = Math.floor(begin / chunkSize);
  1677. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1678. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1679. if (!(chunk in this.loadedChunks)) {
  1680. throw new MissingDataException(begin, end);
  1681. }
  1682. }
  1683. },
  1684. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1685. var chunk, n;
  1686. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1687. if (!(chunk in this.loadedChunks)) {
  1688. return chunk;
  1689. }
  1690. }
  1691. // Wrap around to beginning
  1692. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1693. if (!(chunk in this.loadedChunks)) {
  1694. return chunk;
  1695. }
  1696. }
  1697. return null;
  1698. },
  1699. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1700. return chunk in this.loadedChunks;
  1701. },
  1702. get length() {
  1703. return this.end - this.start;
  1704. },
  1705. get isEmpty() {
  1706. return this.length === 0;
  1707. },
  1708. getByte: function ChunkedStream_getByte() {
  1709. var pos = this.pos;
  1710. if (pos >= this.end) {
  1711. return -1;
  1712. }
  1713. this.ensureByte(pos);
  1714. return this.bytes[this.pos++];
  1715. },
  1716. getUint16: function ChunkedStream_getUint16() {
  1717. var b0 = this.getByte();
  1718. var b1 = this.getByte();
  1719. return (b0 << 8) + b1;
  1720. },
  1721. getInt32: function ChunkedStream_getInt32() {
  1722. var b0 = this.getByte();
  1723. var b1 = this.getByte();
  1724. var b2 = this.getByte();
  1725. var b3 = this.getByte();
  1726. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1727. },
  1728. // returns subarray of original buffer
  1729. // should only be read
  1730. getBytes: function ChunkedStream_getBytes(length) {
  1731. var bytes = this.bytes;
  1732. var pos = this.pos;
  1733. var strEnd = this.end;
  1734. if (!length) {
  1735. this.ensureRange(pos, strEnd);
  1736. return bytes.subarray(pos, strEnd);
  1737. }
  1738. var end = pos + length;
  1739. if (end > strEnd) {
  1740. end = strEnd;
  1741. }
  1742. this.ensureRange(pos, end);
  1743. this.pos = end;
  1744. return bytes.subarray(pos, end);
  1745. },
  1746. peekBytes: function ChunkedStream_peekBytes(length) {
  1747. var bytes = this.getBytes(length);
  1748. this.pos -= bytes.length;
  1749. return bytes;
  1750. },
  1751. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1752. this.ensureRange(begin, end);
  1753. return this.bytes.subarray(begin, end);
  1754. },
  1755. skip: function ChunkedStream_skip(n) {
  1756. if (!n) {
  1757. n = 1;
  1758. }
  1759. this.pos += n;
  1760. },
  1761. reset: function ChunkedStream_reset() {
  1762. this.pos = this.start;
  1763. },
  1764. moveStart: function ChunkedStream_moveStart() {
  1765. this.start = this.pos;
  1766. },
  1767. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1768. this.ensureRange(start, start + length);
  1769. function ChunkedStreamSubstream() {}
  1770. ChunkedStreamSubstream.prototype = Object.create(this);
  1771. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1772. var chunkSize = this.chunkSize;
  1773. var beginChunk = Math.floor(this.start / chunkSize);
  1774. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1775. var missingChunks = [];
  1776. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1777. if (!(chunk in this.loadedChunks)) {
  1778. missingChunks.push(chunk);
  1779. }
  1780. }
  1781. return missingChunks;
  1782. };
  1783. var subStream = new ChunkedStreamSubstream();
  1784. subStream.pos = subStream.start = start;
  1785. subStream.end = start + length || this.end;
  1786. subStream.dict = dict;
  1787. return subStream;
  1788. },
  1789. isStream: true
  1790. };
  1791. return ChunkedStream;
  1792. })();
  1793. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1794. function ChunkedStreamManager(length, chunkSize, url, args) {
  1795. this.stream = new ChunkedStream(length, chunkSize, this);
  1796. this.length = length;
  1797. this.chunkSize = chunkSize;
  1798. this.url = url;
  1799. this.disableAutoFetch = args.disableAutoFetch;
  1800. var msgHandler = this.msgHandler = args.msgHandler;
  1801. if (args.chunkedViewerLoading) {
  1802. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1803. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1804. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1805. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1806. };
  1807. } else {
  1808. var getXhr = function getXhr() {
  1809. return new XMLHttpRequest();
  1810. };
  1811. this.networkManager = new NetworkManager(this.url, {
  1812. getXhr: getXhr,
  1813. httpHeaders: args.httpHeaders,
  1814. withCredentials: args.withCredentials
  1815. });
  1816. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1817. this.networkManager.requestRange(begin, end, {
  1818. onDone: this.onReceiveData.bind(this),
  1819. onProgress: this.onProgress.bind(this)
  1820. });
  1821. };
  1822. }
  1823. this.currRequestId = 0;
  1824. this.chunksNeededByRequest = {};
  1825. this.requestsByChunk = {};
  1826. this.callbacksByRequest = {};
  1827. this._loadedStreamCapability = createPromiseCapability();
  1828. if (args.initialData) {
  1829. this.setInitialData(args.initialData);
  1830. }
  1831. }
  1832. ChunkedStreamManager.prototype = {
  1833. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  1834. this.stream.onReceiveInitialData(data);
  1835. if (this.stream.allChunksLoaded()) {
  1836. this._loadedStreamCapability.resolve(this.stream);
  1837. } else if (this.msgHandler) {
  1838. this.msgHandler.send('DocProgress', {
  1839. loaded: data.length,
  1840. total: this.length
  1841. });
  1842. }
  1843. },
  1844. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1845. return this._loadedStreamCapability.promise;
  1846. },
  1847. // Get all the chunks that are not yet loaded and groups them into
  1848. // contiguous ranges to load in as few requests as possible
  1849. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1850. var missingChunks = this.stream.getMissingChunks();
  1851. this.requestChunks(missingChunks);
  1852. return this._loadedStreamCapability.promise;
  1853. },
  1854. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1855. callback) {
  1856. var requestId = this.currRequestId++;
  1857. var chunksNeeded;
  1858. var i, ii;
  1859. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1860. for (i = 0, ii = chunks.length; i < ii; i++) {
  1861. if (!this.stream.hasChunk(chunks[i])) {
  1862. chunksNeeded[chunks[i]] = true;
  1863. }
  1864. }
  1865. if (isEmptyObj(chunksNeeded)) {
  1866. if (callback) {
  1867. callback();
  1868. }
  1869. return;
  1870. }
  1871. this.callbacksByRequest[requestId] = callback;
  1872. var chunksToRequest = [];
  1873. for (var chunk in chunksNeeded) {
  1874. chunk = chunk | 0;
  1875. if (!(chunk in this.requestsByChunk)) {
  1876. this.requestsByChunk[chunk] = [];
  1877. chunksToRequest.push(chunk);
  1878. }
  1879. this.requestsByChunk[chunk].push(requestId);
  1880. }
  1881. if (!chunksToRequest.length) {
  1882. return;
  1883. }
  1884. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1885. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1886. var groupedChunk = groupedChunksToRequest[i];
  1887. var begin = groupedChunk.beginChunk * this.chunkSize;
  1888. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1889. this.sendRequest(begin, end);
  1890. }
  1891. },
  1892. getStream: function ChunkedStreamManager_getStream() {
  1893. return this.stream;
  1894. },
  1895. // Loads any chunks in the requested range that are not yet loaded
  1896. requestRange: function ChunkedStreamManager_requestRange(
  1897. begin, end, callback) {
  1898. end = Math.min(end, this.length);
  1899. var beginChunk = this.getBeginChunk(begin);
  1900. var endChunk = this.getEndChunk(end);
  1901. var chunks = [];
  1902. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1903. chunks.push(chunk);
  1904. }
  1905. this.requestChunks(chunks, callback);
  1906. },
  1907. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1908. callback) {
  1909. ranges = ranges || [];
  1910. var chunksToRequest = [];
  1911. for (var i = 0; i < ranges.length; i++) {
  1912. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1913. var endChunk = this.getEndChunk(ranges[i].end);
  1914. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1915. if (chunksToRequest.indexOf(chunk) < 0) {
  1916. chunksToRequest.push(chunk);
  1917. }
  1918. }
  1919. }
  1920. chunksToRequest.sort(function(a, b) { return a - b; });
  1921. this.requestChunks(chunksToRequest, callback);
  1922. },
  1923. // Groups a sorted array of chunks into as few continguous larger
  1924. // chunks as possible
  1925. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1926. var groupedChunks = [];
  1927. var beginChunk = -1;
  1928. var prevChunk = -1;
  1929. for (var i = 0; i < chunks.length; ++i) {
  1930. var chunk = chunks[i];
  1931. if (beginChunk < 0) {
  1932. beginChunk = chunk;
  1933. }
  1934. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1935. groupedChunks.push({ beginChunk: beginChunk,
  1936. endChunk: prevChunk + 1 });
  1937. beginChunk = chunk;
  1938. }
  1939. if (i + 1 === chunks.length) {
  1940. groupedChunks.push({ beginChunk: beginChunk,
  1941. endChunk: chunk + 1 });
  1942. }
  1943. prevChunk = chunk;
  1944. }
  1945. return groupedChunks;
  1946. },
  1947. onProgress: function ChunkedStreamManager_onProgress(args) {
  1948. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1949. args.loaded);
  1950. this.msgHandler.send('DocProgress', {
  1951. loaded: bytesLoaded,
  1952. total: this.length
  1953. });
  1954. },
  1955. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  1956. var chunk = args.chunk;
  1957. var begin = args.begin;
  1958. var end = begin + chunk.byteLength;
  1959. var beginChunk = this.getBeginChunk(begin);
  1960. var endChunk = this.getEndChunk(end);
  1961. this.stream.onReceiveData(begin, chunk);
  1962. if (this.stream.allChunksLoaded()) {
  1963. this._loadedStreamCapability.resolve(this.stream);
  1964. }
  1965. var loadedRequests = [];
  1966. var i, requestId;
  1967. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  1968. // The server might return more chunks than requested
  1969. var requestIds = this.requestsByChunk[chunk] || [];
  1970. delete this.requestsByChunk[chunk];
  1971. for (i = 0; i < requestIds.length; ++i) {
  1972. requestId = requestIds[i];
  1973. var chunksNeeded = this.chunksNeededByRequest[requestId];
  1974. if (chunk in chunksNeeded) {
  1975. delete chunksNeeded[chunk];
  1976. }
  1977. if (!isEmptyObj(chunksNeeded)) {
  1978. continue;
  1979. }
  1980. loadedRequests.push(requestId);
  1981. }
  1982. }
  1983. // If there are no pending requests, automatically fetch the next
  1984. // unfetched chunk of the PDF
  1985. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  1986. var nextEmptyChunk;
  1987. if (this.stream.numChunksLoaded === 1) {
  1988. // This is a special optimization so that after fetching the first
  1989. // chunk, rather than fetching the second chunk, we fetch the last
  1990. // chunk.
  1991. var lastChunk = this.stream.numChunks - 1;
  1992. if (!this.stream.hasChunk(lastChunk)) {
  1993. nextEmptyChunk = lastChunk;
  1994. }
  1995. } else {
  1996. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  1997. }
  1998. if (isInt(nextEmptyChunk)) {
  1999. this.requestChunks([nextEmptyChunk]);
  2000. }
  2001. }
  2002. for (i = 0; i < loadedRequests.length; ++i) {
  2003. requestId = loadedRequests[i];
  2004. var callback = this.callbacksByRequest[requestId];
  2005. delete this.callbacksByRequest[requestId];
  2006. if (callback) {
  2007. callback();
  2008. }
  2009. }
  2010. this.msgHandler.send('DocProgress', {
  2011. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2012. total: this.length
  2013. });
  2014. },
  2015. onError: function ChunkedStreamManager_onError(err) {
  2016. this._loadedStreamCapability.reject(err);
  2017. },
  2018. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2019. var chunk = Math.floor(begin / this.chunkSize);
  2020. return chunk;
  2021. },
  2022. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2023. if (end % this.chunkSize === 0) {
  2024. return end / this.chunkSize;
  2025. }
  2026. // 0 -> 0
  2027. // 1 -> 1
  2028. // 99 -> 1
  2029. // 100 -> 1
  2030. // 101 -> 2
  2031. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2032. return chunk;
  2033. }
  2034. };
  2035. return ChunkedStreamManager;
  2036. })();
  2037. // The maximum number of bytes fetched per range request
  2038. var RANGE_CHUNK_SIZE = 65536;
  2039. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2040. var BasePdfManager = (function BasePdfManagerClosure() {
  2041. function BasePdfManager() {
  2042. throw new Error('Cannot initialize BaseManagerManager');
  2043. }
  2044. BasePdfManager.prototype = {
  2045. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2046. throw new NotImplementedException();
  2047. },
  2048. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2049. return this.ensure(this.pdfDocument, prop, args);
  2050. },
  2051. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2052. return this.ensure(this.pdfDocument.xref, prop, args);
  2053. },
  2054. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2055. return this.ensure(this.pdfDocument.catalog, prop, args);
  2056. },
  2057. getPage: function BasePdfManager_pagePage(pageIndex) {
  2058. return this.pdfDocument.getPage(pageIndex);
  2059. },
  2060. cleanup: function BasePdfManager_cleanup() {
  2061. return this.pdfDocument.cleanup();
  2062. },
  2063. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2064. return new NotImplementedException();
  2065. },
  2066. requestRange: function BasePdfManager_ensure(begin, end) {
  2067. return new NotImplementedException();
  2068. },
  2069. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2070. return new NotImplementedException();
  2071. },
  2072. updatePassword: function BasePdfManager_updatePassword(password) {
  2073. this.pdfDocument.xref.password = this.password = password;
  2074. if (this._passwordChangedCapability) {
  2075. this._passwordChangedCapability.resolve();
  2076. }
  2077. },
  2078. passwordChanged: function BasePdfManager_passwordChanged() {
  2079. this._passwordChangedCapability = createPromiseCapability();
  2080. return this._passwordChangedCapability.promise;
  2081. },
  2082. terminate: function BasePdfManager_terminate() {
  2083. return new NotImplementedException();
  2084. }
  2085. };
  2086. return BasePdfManager;
  2087. })();
  2088. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2089. function LocalPdfManager(data, password) {
  2090. var stream = new Stream(data);
  2091. this.pdfDocument = new PDFDocument(this, stream, password);
  2092. this._loadedStreamCapability = createPromiseCapability();
  2093. this._loadedStreamCapability.resolve(stream);
  2094. }
  2095. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2096. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2097. LocalPdfManager.prototype.ensure =
  2098. function LocalPdfManager_ensure(obj, prop, args) {
  2099. return new Promise(function (resolve, reject) {
  2100. try {
  2101. var value = obj[prop];
  2102. var result;
  2103. if (typeof value === 'function') {
  2104. result = value.apply(obj, args);
  2105. } else {
  2106. result = value;
  2107. }
  2108. resolve(result);
  2109. } catch (e) {
  2110. reject(e);
  2111. }
  2112. });
  2113. };
  2114. LocalPdfManager.prototype.requestRange =
  2115. function LocalPdfManager_requestRange(begin, end) {
  2116. return Promise.resolve();
  2117. };
  2118. LocalPdfManager.prototype.requestLoadedStream =
  2119. function LocalPdfManager_requestLoadedStream() {
  2120. };
  2121. LocalPdfManager.prototype.onLoadedStream =
  2122. function LocalPdfManager_getLoadedStream() {
  2123. return this._loadedStreamCapability.promise;
  2124. };
  2125. LocalPdfManager.prototype.terminate =
  2126. function LocalPdfManager_terminate() {
  2127. return;
  2128. };
  2129. return LocalPdfManager;
  2130. })();
  2131. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2132. function NetworkPdfManager(args, msgHandler) {
  2133. this.msgHandler = msgHandler;
  2134. var params = {
  2135. msgHandler: msgHandler,
  2136. httpHeaders: args.httpHeaders,
  2137. withCredentials: args.withCredentials,
  2138. chunkedViewerLoading: args.chunkedViewerLoading,
  2139. disableAutoFetch: args.disableAutoFetch,
  2140. initialData: args.initialData
  2141. };
  2142. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2143. args.url, params);
  2144. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2145. args.password);
  2146. }
  2147. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2148. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2149. NetworkPdfManager.prototype.ensure =
  2150. function NetworkPdfManager_ensure(obj, prop, args) {
  2151. var pdfManager = this;
  2152. return new Promise(function (resolve, reject) {
  2153. function ensureHelper() {
  2154. try {
  2155. var result;
  2156. var value = obj[prop];
  2157. if (typeof value === 'function') {
  2158. result = value.apply(obj, args);
  2159. } else {
  2160. result = value;
  2161. }
  2162. resolve(result);
  2163. } catch(e) {
  2164. if (!(e instanceof MissingDataException)) {
  2165. reject(e);
  2166. return;
  2167. }
  2168. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2169. }
  2170. }
  2171. ensureHelper();
  2172. });
  2173. };
  2174. NetworkPdfManager.prototype.requestRange =
  2175. function NetworkPdfManager_requestRange(begin, end) {
  2176. return new Promise(function (resolve) {
  2177. this.streamManager.requestRange(begin, end, function() {
  2178. resolve();
  2179. });
  2180. }.bind(this));
  2181. };
  2182. NetworkPdfManager.prototype.requestLoadedStream =
  2183. function NetworkPdfManager_requestLoadedStream() {
  2184. this.streamManager.requestAllChunks();
  2185. };
  2186. NetworkPdfManager.prototype.onLoadedStream =
  2187. function NetworkPdfManager_getLoadedStream() {
  2188. return this.streamManager.onLoadedStream();
  2189. };
  2190. NetworkPdfManager.prototype.terminate =
  2191. function NetworkPdfManager_terminate() {
  2192. this.streamManager.networkManager.abortAllRequests();
  2193. };
  2194. return NetworkPdfManager;
  2195. })();
  2196. var Page = (function PageClosure() {
  2197. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2198. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2199. this.pdfManager = pdfManager;
  2200. this.pageIndex = pageIndex;
  2201. this.pageDict = pageDict;
  2202. this.xref = xref;
  2203. this.ref = ref;
  2204. this.fontCache = fontCache;
  2205. this.idCounters = {
  2206. obj: 0
  2207. };
  2208. this.resourcesPromise = null;
  2209. }
  2210. Page.prototype = {
  2211. getPageProp: function Page_getPageProp(key) {
  2212. return this.pageDict.get(key);
  2213. },
  2214. getInheritedPageProp: function Page_inheritPageProp(key) {
  2215. var dict = this.pageDict;
  2216. var value = dict.get(key);
  2217. while (value === undefined) {
  2218. dict = dict.get('Parent');
  2219. if (!dict) {
  2220. break;
  2221. }
  2222. value = dict.get(key);
  2223. }
  2224. return value;
  2225. },
  2226. get content() {
  2227. return this.getPageProp('Contents');
  2228. },
  2229. get resources() {
  2230. var value = this.getInheritedPageProp('Resources');
  2231. // For robustness: The spec states that a \Resources entry has to be
  2232. // present, but can be empty. Some document omit it still. In this case
  2233. // return an empty dictionary:
  2234. if (value === undefined) {
  2235. value = Dict.empty;
  2236. }
  2237. return shadow(this, 'resources', value);
  2238. },
  2239. get mediaBox() {
  2240. var obj = this.getInheritedPageProp('MediaBox');
  2241. // Reset invalid media box to letter size.
  2242. if (!isArray(obj) || obj.length !== 4) {
  2243. obj = LETTER_SIZE_MEDIABOX;
  2244. }
  2245. return shadow(this, 'mediaBox', obj);
  2246. },
  2247. get view() {
  2248. var mediaBox = this.mediaBox;
  2249. var cropBox = this.getInheritedPageProp('CropBox');
  2250. if (!isArray(cropBox) || cropBox.length !== 4) {
  2251. return shadow(this, 'view', mediaBox);
  2252. }
  2253. // From the spec, 6th ed., p.963:
  2254. // "The crop, bleed, trim, and art boxes should not ordinarily
  2255. // extend beyond the boundaries of the media box. If they do, they are
  2256. // effectively reduced to their intersection with the media box."
  2257. cropBox = Util.intersect(cropBox, mediaBox);
  2258. if (!cropBox) {
  2259. return shadow(this, 'view', mediaBox);
  2260. }
  2261. return shadow(this, 'view', cropBox);
  2262. },
  2263. get annotationRefs() {
  2264. return shadow(this, 'annotationRefs',
  2265. this.getInheritedPageProp('Annots'));
  2266. },
  2267. get rotate() {
  2268. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2269. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2270. if (rotate % 90 !== 0) {
  2271. rotate = 0;
  2272. } else if (rotate >= 360) {
  2273. rotate = rotate % 360;
  2274. } else if (rotate < 0) {
  2275. // The spec doesn't cover negatives, assume its counterclockwise
  2276. // rotation. The following is the other implementation of modulo.
  2277. rotate = ((rotate % 360) + 360) % 360;
  2278. }
  2279. return shadow(this, 'rotate', rotate);
  2280. },
  2281. getContentStream: function Page_getContentStream() {
  2282. var content = this.content;
  2283. var stream;
  2284. if (isArray(content)) {
  2285. // fetching items
  2286. var xref = this.xref;
  2287. var i, n = content.length;
  2288. var streams = [];
  2289. for (i = 0; i < n; ++i) {
  2290. streams.push(xref.fetchIfRef(content[i]));
  2291. }
  2292. stream = new StreamsSequenceStream(streams);
  2293. } else if (isStream(content)) {
  2294. stream = content;
  2295. } else {
  2296. // replacing non-existent page content with empty one
  2297. stream = new NullStream();
  2298. }
  2299. return stream;
  2300. },
  2301. loadResources: function Page_loadResources(keys) {
  2302. if (!this.resourcesPromise) {
  2303. // TODO: add async getInheritedPageProp and remove this.
  2304. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2305. }
  2306. return this.resourcesPromise.then(function resourceSuccess() {
  2307. var objectLoader = new ObjectLoader(this.resources.map,
  2308. keys,
  2309. this.xref);
  2310. return objectLoader.load();
  2311. }.bind(this));
  2312. },
  2313. getOperatorList: function Page_getOperatorList(handler, intent) {
  2314. var self = this;
  2315. var pdfManager = this.pdfManager;
  2316. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2317. []);
  2318. var resourcesPromise = this.loadResources([
  2319. 'ExtGState',
  2320. 'ColorSpace',
  2321. 'Pattern',
  2322. 'Shading',
  2323. 'XObject',
  2324. 'Font'
  2325. // ProcSet
  2326. // Properties
  2327. ]);
  2328. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2329. handler, this.pageIndex,
  2330. 'p' + this.pageIndex + '_',
  2331. this.idCounters,
  2332. this.fontCache);
  2333. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2334. var pageListPromise = dataPromises.then(function(data) {
  2335. var contentStream = data[0];
  2336. var opList = new OperatorList(intent, handler, self.pageIndex);
  2337. handler.send('StartRenderPage', {
  2338. transparency: partialEvaluator.hasBlendModes(self.resources),
  2339. pageIndex: self.pageIndex,
  2340. intent: intent
  2341. });
  2342. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2343. opList).then(function () {
  2344. return opList;
  2345. });
  2346. });
  2347. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2348. return Promise.all([pageListPromise, annotationsPromise]).then(
  2349. function(datas) {
  2350. var pageOpList = datas[0];
  2351. var annotations = datas[1];
  2352. if (annotations.length === 0) {
  2353. pageOpList.flush(true);
  2354. return pageOpList;
  2355. }
  2356. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2357. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2358. return annotationsReadyPromise.then(function () {
  2359. pageOpList.flush(true);
  2360. return pageOpList;
  2361. });
  2362. });
  2363. },
  2364. extractTextContent: function Page_extractTextContent() {
  2365. var handler = {
  2366. on: function nullHandlerOn() {},
  2367. send: function nullHandlerSend() {}
  2368. };
  2369. var self = this;
  2370. var pdfManager = this.pdfManager;
  2371. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2372. []);
  2373. var resourcesPromise = this.loadResources([
  2374. 'ExtGState',
  2375. 'XObject',
  2376. 'Font'
  2377. ]);
  2378. var dataPromises = Promise.all([contentStreamPromise,
  2379. resourcesPromise]);
  2380. return dataPromises.then(function(data) {
  2381. var contentStream = data[0];
  2382. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2383. handler, self.pageIndex,
  2384. 'p' + self.pageIndex + '_',
  2385. self.idCounters,
  2386. self.fontCache);
  2387. return partialEvaluator.getTextContent(contentStream,
  2388. self.resources);
  2389. });
  2390. },
  2391. getAnnotationsData: function Page_getAnnotationsData() {
  2392. var annotations = this.annotations;
  2393. var annotationsData = [];
  2394. for (var i = 0, n = annotations.length; i < n; ++i) {
  2395. annotationsData.push(annotations[i].getData());
  2396. }
  2397. return annotationsData;
  2398. },
  2399. get annotations() {
  2400. var annotations = [];
  2401. var annotationRefs = (this.annotationRefs || []);
  2402. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2403. var annotationRef = annotationRefs[i];
  2404. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2405. if (annotation) {
  2406. annotations.push(annotation);
  2407. }
  2408. }
  2409. return shadow(this, 'annotations', annotations);
  2410. }
  2411. };
  2412. return Page;
  2413. })();
  2414. /**
  2415. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2416. * `PDFDoc`, this one doesn't have any job management code.
  2417. * Right now there exists one PDFDocument on the main thread + one object
  2418. * for each worker. If there is no worker support enabled, there are two
  2419. * `PDFDocument` objects on the main thread created.
  2420. */
  2421. var PDFDocument = (function PDFDocumentClosure() {
  2422. function PDFDocument(pdfManager, arg, password) {
  2423. if (isStream(arg)) {
  2424. init.call(this, pdfManager, arg, password);
  2425. } else if (isArrayBuffer(arg)) {
  2426. init.call(this, pdfManager, new Stream(arg), password);
  2427. } else {
  2428. error('PDFDocument: Unknown argument type');
  2429. }
  2430. }
  2431. function init(pdfManager, stream, password) {
  2432. assert(stream.length > 0, 'stream must have data');
  2433. this.pdfManager = pdfManager;
  2434. this.stream = stream;
  2435. var xref = new XRef(this.stream, password, pdfManager);
  2436. this.xref = xref;
  2437. }
  2438. function find(stream, needle, limit, backwards) {
  2439. var pos = stream.pos;
  2440. var end = stream.end;
  2441. var strBuf = [];
  2442. if (pos + limit > end) {
  2443. limit = end - pos;
  2444. }
  2445. for (var n = 0; n < limit; ++n) {
  2446. strBuf.push(String.fromCharCode(stream.getByte()));
  2447. }
  2448. var str = strBuf.join('');
  2449. stream.pos = pos;
  2450. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2451. if (index === -1) {
  2452. return false; /* not found */
  2453. }
  2454. stream.pos += index;
  2455. return true; /* found */
  2456. }
  2457. var DocumentInfoValidators = {
  2458. get entries() {
  2459. // Lazily build this since all the validation functions below are not
  2460. // defined until after this file loads.
  2461. return shadow(this, 'entries', {
  2462. Title: isString,
  2463. Author: isString,
  2464. Subject: isString,
  2465. Keywords: isString,
  2466. Creator: isString,
  2467. Producer: isString,
  2468. CreationDate: isString,
  2469. ModDate: isString,
  2470. Trapped: isName
  2471. });
  2472. }
  2473. };
  2474. PDFDocument.prototype = {
  2475. parse: function PDFDocument_parse(recoveryMode) {
  2476. this.setup(recoveryMode);
  2477. try {
  2478. // checking if AcroForm is present
  2479. this.acroForm = this.catalog.catDict.get('AcroForm');
  2480. if (this.acroForm) {
  2481. this.xfa = this.acroForm.get('XFA');
  2482. var fields = this.acroForm.get('Fields');
  2483. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2484. !this.xfa) {
  2485. // no fields and no XFA -- not a form (?)
  2486. this.acroForm = null;
  2487. }
  2488. }
  2489. } catch (ex) {
  2490. info('Something wrong with AcroForm entry');
  2491. this.acroForm = null;
  2492. }
  2493. },
  2494. get linearization() {
  2495. var linearization = null;
  2496. if (this.stream.length) {
  2497. try {
  2498. linearization = Linearization.create(this.stream);
  2499. } catch (err) {
  2500. if (err instanceof MissingDataException) {
  2501. throw err;
  2502. }
  2503. info(err);
  2504. }
  2505. }
  2506. // shadow the prototype getter with a data property
  2507. return shadow(this, 'linearization', linearization);
  2508. },
  2509. get startXRef() {
  2510. var stream = this.stream;
  2511. var startXRef = 0;
  2512. var linearization = this.linearization;
  2513. if (linearization) {
  2514. // Find end of first obj.
  2515. stream.reset();
  2516. if (find(stream, 'endobj', 1024)) {
  2517. startXRef = stream.pos + 6;
  2518. }
  2519. } else {
  2520. // Find startxref by jumping backward from the end of the file.
  2521. var step = 1024;
  2522. var found = false, pos = stream.end;
  2523. while (!found && pos > 0) {
  2524. pos -= step - 'startxref'.length;
  2525. if (pos < 0) {
  2526. pos = 0;
  2527. }
  2528. stream.pos = pos;
  2529. found = find(stream, 'startxref', step, true);
  2530. }
  2531. if (found) {
  2532. stream.skip(9);
  2533. var ch;
  2534. do {
  2535. ch = stream.getByte();
  2536. } while (Lexer.isSpace(ch));
  2537. var str = '';
  2538. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2539. str += String.fromCharCode(ch);
  2540. ch = stream.getByte();
  2541. }
  2542. startXRef = parseInt(str, 10);
  2543. if (isNaN(startXRef)) {
  2544. startXRef = 0;
  2545. }
  2546. }
  2547. }
  2548. // shadow the prototype getter with a data property
  2549. return shadow(this, 'startXRef', startXRef);
  2550. },
  2551. get mainXRefEntriesOffset() {
  2552. var mainXRefEntriesOffset = 0;
  2553. var linearization = this.linearization;
  2554. if (linearization) {
  2555. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2556. }
  2557. // shadow the prototype getter with a data property
  2558. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2559. },
  2560. // Find the header, remove leading garbage and setup the stream
  2561. // starting from the header.
  2562. checkHeader: function PDFDocument_checkHeader() {
  2563. var stream = this.stream;
  2564. stream.reset();
  2565. if (find(stream, '%PDF-', 1024)) {
  2566. // Found the header, trim off any garbage before it.
  2567. stream.moveStart();
  2568. // Reading file format version
  2569. var MAX_VERSION_LENGTH = 12;
  2570. var version = '', ch;
  2571. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2572. if (version.length >= MAX_VERSION_LENGTH) {
  2573. break;
  2574. }
  2575. version += String.fromCharCode(ch);
  2576. }
  2577. // removing "%PDF-"-prefix
  2578. this.pdfFormatVersion = version.substring(5);
  2579. return;
  2580. }
  2581. // May not be a PDF file, continue anyway.
  2582. },
  2583. parseStartXRef: function PDFDocument_parseStartXRef() {
  2584. var startXRef = this.startXRef;
  2585. this.xref.setStartXRef(startXRef);
  2586. },
  2587. setup: function PDFDocument_setup(recoveryMode) {
  2588. this.xref.parse(recoveryMode);
  2589. this.catalog = new Catalog(this.pdfManager, this.xref);
  2590. },
  2591. get numPages() {
  2592. var linearization = this.linearization;
  2593. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2594. // shadow the prototype getter
  2595. return shadow(this, 'numPages', num);
  2596. },
  2597. get documentInfo() {
  2598. var docInfo = {
  2599. PDFFormatVersion: this.pdfFormatVersion,
  2600. IsAcroFormPresent: !!this.acroForm,
  2601. IsXFAPresent: !!this.xfa
  2602. };
  2603. var infoDict;
  2604. try {
  2605. infoDict = this.xref.trailer.get('Info');
  2606. } catch (err) {
  2607. info('The document information dictionary is invalid.');
  2608. }
  2609. if (infoDict) {
  2610. var validEntries = DocumentInfoValidators.entries;
  2611. // Only fill the document info with valid entries from the spec.
  2612. for (var key in validEntries) {
  2613. if (infoDict.has(key)) {
  2614. var value = infoDict.get(key);
  2615. // Make sure the value conforms to the spec.
  2616. if (validEntries[key](value)) {
  2617. docInfo[key] = (typeof value !== 'string' ?
  2618. value : stringToPDFString(value));
  2619. } else {
  2620. info('Bad value in document info for "' + key + '"');
  2621. }
  2622. }
  2623. }
  2624. }
  2625. return shadow(this, 'documentInfo', docInfo);
  2626. },
  2627. get fingerprint() {
  2628. var xref = this.xref, hash, fileID = '';
  2629. if (xref.trailer.has('ID')) {
  2630. hash = stringToBytes(xref.trailer.get('ID')[0]);
  2631. } else {
  2632. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  2633. }
  2634. for (var i = 0, n = hash.length; i < n; i++) {
  2635. fileID += hash[i].toString(16);
  2636. }
  2637. return shadow(this, 'fingerprint', fileID);
  2638. },
  2639. getPage: function PDFDocument_getPage(pageIndex) {
  2640. return this.catalog.getPage(pageIndex);
  2641. },
  2642. cleanup: function PDFDocument_cleanup() {
  2643. return this.catalog.cleanup();
  2644. }
  2645. };
  2646. return PDFDocument;
  2647. })();
  2648. var Name = (function NameClosure() {
  2649. function Name(name) {
  2650. this.name = name;
  2651. }
  2652. Name.prototype = {};
  2653. var nameCache = {};
  2654. Name.get = function Name_get(name) {
  2655. var nameValue = nameCache[name];
  2656. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2657. };
  2658. return Name;
  2659. })();
  2660. var Cmd = (function CmdClosure() {
  2661. function Cmd(cmd) {
  2662. this.cmd = cmd;
  2663. }
  2664. Cmd.prototype = {};
  2665. var cmdCache = {};
  2666. Cmd.get = function Cmd_get(cmd) {
  2667. var cmdValue = cmdCache[cmd];
  2668. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2669. };
  2670. return Cmd;
  2671. })();
  2672. var Dict = (function DictClosure() {
  2673. var nonSerializable = function nonSerializableClosure() {
  2674. return nonSerializable; // creating closure on some variable
  2675. };
  2676. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2677. 'Background': true,
  2678. 'ExtGState': true,
  2679. 'Halftone': true,
  2680. 'Layout': true,
  2681. 'Mask': true,
  2682. 'Pagination': true,
  2683. 'Printing': true
  2684. };
  2685. function isRecursionAllowedFor(dict) {
  2686. if (!isName(dict.Type)) {
  2687. return true;
  2688. }
  2689. var dictType = dict.Type.name;
  2690. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2691. }
  2692. // xref is optional
  2693. function Dict(xref) {
  2694. // Map should only be used internally, use functions below to access.
  2695. this.map = Object.create(null);
  2696. this.xref = xref;
  2697. this.objId = null;
  2698. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2699. }
  2700. Dict.prototype = {
  2701. assignXref: function Dict_assignXref(newXref) {
  2702. this.xref = newXref;
  2703. },
  2704. // automatically dereferences Ref objects
  2705. get: function Dict_get(key1, key2, key3) {
  2706. var value;
  2707. var xref = this.xref;
  2708. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2709. typeof key2 === 'undefined') {
  2710. return xref ? xref.fetchIfRef(value) : value;
  2711. }
  2712. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2713. typeof key3 === 'undefined') {
  2714. return xref ? xref.fetchIfRef(value) : value;
  2715. }
  2716. value = this.map[key3] || null;
  2717. return xref ? xref.fetchIfRef(value) : value;
  2718. },
  2719. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2720. getAsync: function Dict_getAsync(key1, key2, key3) {
  2721. var value;
  2722. var xref = this.xref;
  2723. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2724. typeof key2 === 'undefined') {
  2725. if (xref) {
  2726. return xref.fetchIfRefAsync(value);
  2727. }
  2728. return Promise.resolve(value);
  2729. }
  2730. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2731. typeof key3 === 'undefined') {
  2732. if (xref) {
  2733. return xref.fetchIfRefAsync(value);
  2734. }
  2735. return Promise.resolve(value);
  2736. }
  2737. value = this.map[key3] || null;
  2738. if (xref) {
  2739. return xref.fetchIfRefAsync(value);
  2740. }
  2741. return Promise.resolve(value);
  2742. },
  2743. // no dereferencing
  2744. getRaw: function Dict_getRaw(key) {
  2745. return this.map[key];
  2746. },
  2747. // creates new map and dereferences all Refs
  2748. getAll: function Dict_getAll() {
  2749. var all = Object.create(null);
  2750. var queue = null;
  2751. var key, obj;
  2752. for (key in this.map) {
  2753. obj = this.get(key);
  2754. if (obj instanceof Dict) {
  2755. if (isRecursionAllowedFor(obj)) {
  2756. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2757. } else {
  2758. all[key] = this.getRaw(key);
  2759. }
  2760. } else {
  2761. all[key] = obj;
  2762. }
  2763. }
  2764. if (!queue) {
  2765. return all;
  2766. }
  2767. // trying to take cyclic references into the account
  2768. var processed = Object.create(null);
  2769. while (queue.length > 0) {
  2770. var item = queue.shift();
  2771. var itemObj = item.obj;
  2772. var objId = itemObj.objId;
  2773. if (objId && objId in processed) {
  2774. item.target[item.key] = processed[objId];
  2775. continue;
  2776. }
  2777. var dereferenced = Object.create(null);
  2778. for (key in itemObj.map) {
  2779. obj = itemObj.get(key);
  2780. if (obj instanceof Dict) {
  2781. if (isRecursionAllowedFor(obj)) {
  2782. queue.push({target: dereferenced, key: key, obj: obj});
  2783. } else {
  2784. dereferenced[key] = itemObj.getRaw(key);
  2785. }
  2786. } else {
  2787. dereferenced[key] = obj;
  2788. }
  2789. }
  2790. if (objId) {
  2791. processed[objId] = dereferenced;
  2792. }
  2793. item.target[item.key] = dereferenced;
  2794. }
  2795. return all;
  2796. },
  2797. set: function Dict_set(key, value) {
  2798. this.map[key] = value;
  2799. },
  2800. has: function Dict_has(key) {
  2801. return key in this.map;
  2802. },
  2803. forEach: function Dict_forEach(callback) {
  2804. for (var key in this.map) {
  2805. callback(key, this.get(key));
  2806. }
  2807. }
  2808. };
  2809. Dict.empty = new Dict(null);
  2810. return Dict;
  2811. })();
  2812. var Ref = (function RefClosure() {
  2813. function Ref(num, gen) {
  2814. this.num = num;
  2815. this.gen = gen;
  2816. }
  2817. Ref.prototype = {
  2818. toString: function Ref_toString() {
  2819. // This function is hot, so we make the string as compact as possible.
  2820. // |this.gen| is almost always zero, so we treat that case specially.
  2821. var str = this.num + 'R';
  2822. if (this.gen !== 0) {
  2823. str += this.gen;
  2824. }
  2825. return str;
  2826. }
  2827. };
  2828. return Ref;
  2829. })();
  2830. // The reference is identified by number and generation.
  2831. // This structure stores only one instance of the reference.
  2832. var RefSet = (function RefSetClosure() {
  2833. function RefSet() {
  2834. this.dict = {};
  2835. }
  2836. RefSet.prototype = {
  2837. has: function RefSet_has(ref) {
  2838. return ref.toString() in this.dict;
  2839. },
  2840. put: function RefSet_put(ref) {
  2841. this.dict[ref.toString()] = true;
  2842. },
  2843. remove: function RefSet_remove(ref) {
  2844. delete this.dict[ref.toString()];
  2845. }
  2846. };
  2847. return RefSet;
  2848. })();
  2849. var RefSetCache = (function RefSetCacheClosure() {
  2850. function RefSetCache() {
  2851. this.dict = Object.create(null);
  2852. }
  2853. RefSetCache.prototype = {
  2854. get: function RefSetCache_get(ref) {
  2855. return this.dict[ref.toString()];
  2856. },
  2857. has: function RefSetCache_has(ref) {
  2858. return ref.toString() in this.dict;
  2859. },
  2860. put: function RefSetCache_put(ref, obj) {
  2861. this.dict[ref.toString()] = obj;
  2862. },
  2863. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2864. this.dict[ref.toString()] = this.get(aliasRef);
  2865. },
  2866. forEach: function RefSetCache_forEach(fn, thisArg) {
  2867. for (var i in this.dict) {
  2868. fn.call(thisArg, this.dict[i]);
  2869. }
  2870. },
  2871. clear: function RefSetCache_clear() {
  2872. this.dict = Object.create(null);
  2873. }
  2874. };
  2875. return RefSetCache;
  2876. })();
  2877. var Catalog = (function CatalogClosure() {
  2878. function Catalog(pdfManager, xref) {
  2879. this.pdfManager = pdfManager;
  2880. this.xref = xref;
  2881. this.catDict = xref.getCatalogObj();
  2882. this.fontCache = new RefSetCache();
  2883. assert(isDict(this.catDict),
  2884. 'catalog object is not a dictionary');
  2885. this.pagePromises = [];
  2886. }
  2887. Catalog.prototype = {
  2888. get metadata() {
  2889. var streamRef = this.catDict.getRaw('Metadata');
  2890. if (!isRef(streamRef)) {
  2891. return shadow(this, 'metadata', null);
  2892. }
  2893. var encryptMetadata = (!this.xref.encrypt ? false :
  2894. this.xref.encrypt.encryptMetadata);
  2895. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2896. var metadata;
  2897. if (stream && isDict(stream.dict)) {
  2898. var type = stream.dict.get('Type');
  2899. var subtype = stream.dict.get('Subtype');
  2900. if (isName(type) && isName(subtype) &&
  2901. type.name === 'Metadata' && subtype.name === 'XML') {
  2902. // XXX: This should examine the charset the XML document defines,
  2903. // however since there are currently no real means to decode
  2904. // arbitrary charsets, let's just hope that the author of the PDF
  2905. // was reasonable enough to stick with the XML default charset,
  2906. // which is UTF-8.
  2907. try {
  2908. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2909. } catch (e) {
  2910. info('Skipping invalid metadata.');
  2911. }
  2912. }
  2913. }
  2914. return shadow(this, 'metadata', metadata);
  2915. },
  2916. get toplevelPagesDict() {
  2917. var pagesObj = this.catDict.get('Pages');
  2918. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2919. // shadow the prototype getter
  2920. return shadow(this, 'toplevelPagesDict', pagesObj);
  2921. },
  2922. get documentOutline() {
  2923. var obj = null;
  2924. try {
  2925. obj = this.readDocumentOutline();
  2926. } catch (ex) {
  2927. if (ex instanceof MissingDataException) {
  2928. throw ex;
  2929. }
  2930. warn('Unable to read document outline');
  2931. }
  2932. return shadow(this, 'documentOutline', obj);
  2933. },
  2934. readDocumentOutline: function Catalog_readDocumentOutline() {
  2935. var xref = this.xref;
  2936. var obj = this.catDict.get('Outlines');
  2937. var root = { items: [] };
  2938. if (isDict(obj)) {
  2939. obj = obj.getRaw('First');
  2940. var processed = new RefSet();
  2941. if (isRef(obj)) {
  2942. var queue = [{obj: obj, parent: root}];
  2943. // to avoid recursion keeping track of the items
  2944. // in the processed dictionary
  2945. processed.put(obj);
  2946. while (queue.length > 0) {
  2947. var i = queue.shift();
  2948. var outlineDict = xref.fetchIfRef(i.obj);
  2949. if (outlineDict === null) {
  2950. continue;
  2951. }
  2952. if (!outlineDict.has('Title')) {
  2953. error('Invalid outline item');
  2954. }
  2955. var dest = outlineDict.get('A');
  2956. if (dest) {
  2957. dest = dest.get('D');
  2958. } else if (outlineDict.has('Dest')) {
  2959. dest = outlineDict.getRaw('Dest');
  2960. if (isName(dest)) {
  2961. dest = dest.name;
  2962. }
  2963. }
  2964. var title = outlineDict.get('Title');
  2965. var outlineItem = {
  2966. dest: dest,
  2967. title: stringToPDFString(title),
  2968. color: outlineDict.get('C') || [0, 0, 0],
  2969. count: outlineDict.get('Count'),
  2970. bold: !!(outlineDict.get('F') & 2),
  2971. italic: !!(outlineDict.get('F') & 1),
  2972. items: []
  2973. };
  2974. i.parent.items.push(outlineItem);
  2975. obj = outlineDict.getRaw('First');
  2976. if (isRef(obj) && !processed.has(obj)) {
  2977. queue.push({obj: obj, parent: outlineItem});
  2978. processed.put(obj);
  2979. }
  2980. obj = outlineDict.getRaw('Next');
  2981. if (isRef(obj) && !processed.has(obj)) {
  2982. queue.push({obj: obj, parent: i.parent});
  2983. processed.put(obj);
  2984. }
  2985. }
  2986. }
  2987. }
  2988. return (root.items.length > 0 ? root.items : null);
  2989. },
  2990. get numPages() {
  2991. var obj = this.toplevelPagesDict.get('Count');
  2992. assert(
  2993. isInt(obj),
  2994. 'page count in top level pages object is not an integer'
  2995. );
  2996. // shadow the prototype getter
  2997. return shadow(this, 'num', obj);
  2998. },
  2999. get destinations() {
  3000. function fetchDestination(dest) {
  3001. return isDict(dest) ? dest.get('D') : dest;
  3002. }
  3003. var xref = this.xref;
  3004. var dests = {}, nameTreeRef, nameDictionaryRef;
  3005. var obj = this.catDict.get('Names');
  3006. if (obj && obj.has('Dests')) {
  3007. nameTreeRef = obj.getRaw('Dests');
  3008. } else if (this.catDict.has('Dests')) {
  3009. nameDictionaryRef = this.catDict.get('Dests');
  3010. }
  3011. if (nameDictionaryRef) {
  3012. // reading simple destination dictionary
  3013. obj = nameDictionaryRef;
  3014. obj.forEach(function catalogForEach(key, value) {
  3015. if (!value) {
  3016. return;
  3017. }
  3018. dests[key] = fetchDestination(value);
  3019. });
  3020. }
  3021. if (nameTreeRef) {
  3022. var nameTree = new NameTree(nameTreeRef, xref);
  3023. var names = nameTree.getAll();
  3024. for (var name in names) {
  3025. if (!names.hasOwnProperty(name)) {
  3026. continue;
  3027. }
  3028. dests[name] = fetchDestination(names[name]);
  3029. }
  3030. }
  3031. return shadow(this, 'destinations', dests);
  3032. },
  3033. get attachments() {
  3034. var xref = this.xref;
  3035. var attachments = null, nameTreeRef;
  3036. var obj = this.catDict.get('Names');
  3037. if (obj) {
  3038. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3039. }
  3040. if (nameTreeRef) {
  3041. var nameTree = new NameTree(nameTreeRef, xref);
  3042. var names = nameTree.getAll();
  3043. for (var name in names) {
  3044. if (!names.hasOwnProperty(name)) {
  3045. continue;
  3046. }
  3047. var fs = new FileSpec(names[name], xref);
  3048. if (!attachments) {
  3049. attachments = {};
  3050. }
  3051. attachments[stringToPDFString(name)] = fs.serializable;
  3052. }
  3053. }
  3054. return shadow(this, 'attachments', attachments);
  3055. },
  3056. get javaScript() {
  3057. var xref = this.xref;
  3058. var obj = this.catDict.get('Names');
  3059. var javaScript = [];
  3060. if (obj && obj.has('JavaScript')) {
  3061. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3062. var names = nameTree.getAll();
  3063. for (var name in names) {
  3064. if (!names.hasOwnProperty(name)) {
  3065. continue;
  3066. }
  3067. // We don't really use the JavaScript right now. This code is
  3068. // defensive so we don't cause errors on document load.
  3069. var jsDict = names[name];
  3070. if (!isDict(jsDict)) {
  3071. continue;
  3072. }
  3073. var type = jsDict.get('S');
  3074. if (!isName(type) || type.name !== 'JavaScript') {
  3075. continue;
  3076. }
  3077. var js = jsDict.get('JS');
  3078. if (!isString(js) && !isStream(js)) {
  3079. continue;
  3080. }
  3081. if (isStream(js)) {
  3082. js = bytesToString(js.getBytes());
  3083. }
  3084. javaScript.push(stringToPDFString(js));
  3085. }
  3086. }
  3087. // Append OpenAction actions to javaScript array
  3088. var openactionDict = this.catDict.get('OpenAction');
  3089. if (isDict(openactionDict)) {
  3090. var objType = openactionDict.get('Type');
  3091. var actionType = openactionDict.get('S');
  3092. var action = openactionDict.get('N');
  3093. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3094. isName(actionType) && actionType.name === 'Named' &&
  3095. isName(action) && action.name === 'Print');
  3096. if (isPrintAction) {
  3097. javaScript.push('print(true);');
  3098. }
  3099. }
  3100. return shadow(this, 'javaScript', javaScript);
  3101. },
  3102. cleanup: function Catalog_cleanup() {
  3103. var promises = [];
  3104. this.fontCache.forEach(function (promise) {
  3105. promises.push(promise);
  3106. });
  3107. return Promise.all(promises).then(function (translatedFonts) {
  3108. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3109. var font = translatedFonts[i].dict;
  3110. delete font.translated;
  3111. }
  3112. this.fontCache.clear();
  3113. }.bind(this));
  3114. },
  3115. getPage: function Catalog_getPage(pageIndex) {
  3116. if (!(pageIndex in this.pagePromises)) {
  3117. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3118. function (a) {
  3119. var dict = a[0];
  3120. var ref = a[1];
  3121. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3122. this.fontCache);
  3123. }.bind(this)
  3124. );
  3125. }
  3126. return this.pagePromises[pageIndex];
  3127. },
  3128. getPageDict: function Catalog_getPageDict(pageIndex) {
  3129. var capability = createPromiseCapability();
  3130. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3131. var currentPageIndex = 0;
  3132. var xref = this.xref;
  3133. function next() {
  3134. while (nodesToVisit.length) {
  3135. var currentNode = nodesToVisit.pop();
  3136. if (isRef(currentNode)) {
  3137. xref.fetchAsync(currentNode).then(function (obj) {
  3138. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3139. if (pageIndex === currentPageIndex) {
  3140. capability.resolve([obj, currentNode]);
  3141. } else {
  3142. currentPageIndex++;
  3143. next();
  3144. }
  3145. return;
  3146. }
  3147. nodesToVisit.push(obj);
  3148. next();
  3149. }, capability.reject);
  3150. return;
  3151. }
  3152. // must be a child page dictionary
  3153. assert(
  3154. isDict(currentNode),
  3155. 'page dictionary kid reference points to wrong type of object'
  3156. );
  3157. var count = currentNode.get('Count');
  3158. // Skip nodes where the page can't be.
  3159. if (currentPageIndex + count <= pageIndex) {
  3160. currentPageIndex += count;
  3161. continue;
  3162. }
  3163. var kids = currentNode.get('Kids');
  3164. assert(isArray(kids), 'page dictionary kids object is not an array');
  3165. if (count === kids.length) {
  3166. // Nodes that don't have the page have been skipped and this is the
  3167. // bottom of the tree which means the page requested must be a
  3168. // descendant of this pages node. Ideally we would just resolve the
  3169. // promise with the page ref here, but there is the case where more
  3170. // pages nodes could link to single a page (see issue 3666 pdf). To
  3171. // handle this push it back on the queue so if it is a pages node it
  3172. // will be descended into.
  3173. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3174. currentPageIndex = pageIndex;
  3175. continue;
  3176. } else {
  3177. for (var last = kids.length - 1; last >= 0; last--) {
  3178. nodesToVisit.push(kids[last]);
  3179. }
  3180. }
  3181. }
  3182. capability.reject('Page index ' + pageIndex + ' not found.');
  3183. }
  3184. next();
  3185. return capability.promise;
  3186. },
  3187. getPageIndex: function Catalog_getPageIndex(ref) {
  3188. // The page tree nodes have the count of all the leaves below them. To get
  3189. // how many pages are before we just have to walk up the tree and keep
  3190. // adding the count of siblings to the left of the node.
  3191. var xref = this.xref;
  3192. function pagesBeforeRef(kidRef) {
  3193. var total = 0;
  3194. var parentRef;
  3195. return xref.fetchAsync(kidRef).then(function (node) {
  3196. if (!node) {
  3197. return null;
  3198. }
  3199. parentRef = node.getRaw('Parent');
  3200. return node.getAsync('Parent');
  3201. }).then(function (parent) {
  3202. if (!parent) {
  3203. return null;
  3204. }
  3205. return parent.getAsync('Kids');
  3206. }).then(function (kids) {
  3207. if (!kids) {
  3208. return null;
  3209. }
  3210. var kidPromises = [];
  3211. var found = false;
  3212. for (var i = 0; i < kids.length; i++) {
  3213. var kid = kids[i];
  3214. assert(isRef(kid), 'kids must be a ref');
  3215. if (kid.num === kidRef.num) {
  3216. found = true;
  3217. break;
  3218. }
  3219. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3220. if (kid.has('Count')) {
  3221. var count = kid.get('Count');
  3222. total += count;
  3223. } else { // page leaf node
  3224. total++;
  3225. }
  3226. }));
  3227. }
  3228. if (!found) {
  3229. error('kid ref not found in parents kids');
  3230. }
  3231. return Promise.all(kidPromises).then(function () {
  3232. return [total, parentRef];
  3233. });
  3234. });
  3235. }
  3236. var total = 0;
  3237. function next(ref) {
  3238. return pagesBeforeRef(ref).then(function (args) {
  3239. if (!args) {
  3240. return total;
  3241. }
  3242. var count = args[0];
  3243. var parentRef = args[1];
  3244. total += count;
  3245. return next(parentRef);
  3246. });
  3247. }
  3248. return next(ref);
  3249. }
  3250. };
  3251. return Catalog;
  3252. })();
  3253. var XRef = (function XRefClosure() {
  3254. function XRef(stream, password) {
  3255. this.stream = stream;
  3256. this.entries = [];
  3257. this.xrefstms = {};
  3258. // prepare the XRef cache
  3259. this.cache = [];
  3260. this.password = password;
  3261. this.stats = {
  3262. streamTypes: [],
  3263. fontTypes: []
  3264. };
  3265. }
  3266. XRef.prototype = {
  3267. setStartXRef: function XRef_setStartXRef(startXRef) {
  3268. // Store the starting positions of xref tables as we process them
  3269. // so we can recover from missing data errors
  3270. this.startXRefQueue = [startXRef];
  3271. },
  3272. parse: function XRef_parse(recoveryMode) {
  3273. var trailerDict;
  3274. if (!recoveryMode) {
  3275. trailerDict = this.readXRef();
  3276. } else {
  3277. warn('Indexing all PDF objects');
  3278. trailerDict = this.indexObjects();
  3279. }
  3280. trailerDict.assignXref(this);
  3281. this.trailer = trailerDict;
  3282. var encrypt = trailerDict.get('Encrypt');
  3283. if (encrypt) {
  3284. var ids = trailerDict.get('ID');
  3285. var fileId = (ids && ids.length) ? ids[0] : '';
  3286. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3287. this.password);
  3288. }
  3289. // get the root dictionary (catalog) object
  3290. if (!(this.root = trailerDict.get('Root'))) {
  3291. error('Invalid root reference');
  3292. }
  3293. },
  3294. processXRefTable: function XRef_processXRefTable(parser) {
  3295. if (!('tableState' in this)) {
  3296. // Stores state of the table as we process it so we can resume
  3297. // from middle of table in case of missing data error
  3298. this.tableState = {
  3299. entryNum: 0,
  3300. streamPos: parser.lexer.stream.pos,
  3301. parserBuf1: parser.buf1,
  3302. parserBuf2: parser.buf2
  3303. };
  3304. }
  3305. var obj = this.readXRefTable(parser);
  3306. // Sanity check
  3307. if (!isCmd(obj, 'trailer')) {
  3308. error('Invalid XRef table: could not find trailer dictionary');
  3309. }
  3310. // Read trailer dictionary, e.g.
  3311. // trailer
  3312. // << /Size 22
  3313. // /Root 20R
  3314. // /Info 10R
  3315. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3316. // >>
  3317. // The parser goes through the entire stream << ... >> and provides
  3318. // a getter interface for the key-value table
  3319. var dict = parser.getObj();
  3320. // The pdflib PDF generator can generate a nested trailer dictionary
  3321. if (!isDict(dict) && dict.dict) {
  3322. dict = dict.dict;
  3323. }
  3324. if (!isDict(dict)) {
  3325. error('Invalid XRef table: could not parse trailer dictionary');
  3326. }
  3327. delete this.tableState;
  3328. return dict;
  3329. },
  3330. readXRefTable: function XRef_readXRefTable(parser) {
  3331. // Example of cross-reference table:
  3332. // xref
  3333. // 0 1 <-- subsection header (first obj #, obj count)
  3334. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3335. // 23 2 <-- subsection header ... and so on ...
  3336. // 0000025518 00002 n
  3337. // 0000025635 00000 n
  3338. // trailer
  3339. // ...
  3340. var stream = parser.lexer.stream;
  3341. var tableState = this.tableState;
  3342. stream.pos = tableState.streamPos;
  3343. parser.buf1 = tableState.parserBuf1;
  3344. parser.buf2 = tableState.parserBuf2;
  3345. // Outer loop is over subsection headers
  3346. var obj;
  3347. while (true) {
  3348. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3349. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3350. break;
  3351. }
  3352. tableState.firstEntryNum = obj;
  3353. tableState.entryCount = parser.getObj();
  3354. }
  3355. var first = tableState.firstEntryNum;
  3356. var count = tableState.entryCount;
  3357. if (!isInt(first) || !isInt(count)) {
  3358. error('Invalid XRef table: wrong types in subsection header');
  3359. }
  3360. // Inner loop is over objects themselves
  3361. for (var i = tableState.entryNum; i < count; i++) {
  3362. tableState.streamPos = stream.pos;
  3363. tableState.entryNum = i;
  3364. tableState.parserBuf1 = parser.buf1;
  3365. tableState.parserBuf2 = parser.buf2;
  3366. var entry = {};
  3367. entry.offset = parser.getObj();
  3368. entry.gen = parser.getObj();
  3369. var type = parser.getObj();
  3370. if (isCmd(type, 'f')) {
  3371. entry.free = true;
  3372. } else if (isCmd(type, 'n')) {
  3373. entry.uncompressed = true;
  3374. }
  3375. // Validate entry obj
  3376. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3377. !(entry.free || entry.uncompressed)) {
  3378. console.log(entry.offset, entry.gen, entry.free,
  3379. entry.uncompressed);
  3380. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3381. }
  3382. if (!this.entries[i + first]) {
  3383. this.entries[i + first] = entry;
  3384. }
  3385. }
  3386. tableState.entryNum = 0;
  3387. tableState.streamPos = stream.pos;
  3388. tableState.parserBuf1 = parser.buf1;
  3389. tableState.parserBuf2 = parser.buf2;
  3390. delete tableState.firstEntryNum;
  3391. delete tableState.entryCount;
  3392. }
  3393. // Per issue 3248: hp scanners generate bad XRef
  3394. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3395. // shifting the entries
  3396. this.entries.shift();
  3397. }
  3398. // Sanity check: as per spec, first object must be free
  3399. if (this.entries[0] && !this.entries[0].free) {
  3400. error('Invalid XRef table: unexpected first object');
  3401. }
  3402. return obj;
  3403. },
  3404. processXRefStream: function XRef_processXRefStream(stream) {
  3405. if (!('streamState' in this)) {
  3406. // Stores state of the stream as we process it so we can resume
  3407. // from middle of stream in case of missing data error
  3408. var streamParameters = stream.dict;
  3409. var byteWidths = streamParameters.get('W');
  3410. var range = streamParameters.get('Index');
  3411. if (!range) {
  3412. range = [0, streamParameters.get('Size')];
  3413. }
  3414. this.streamState = {
  3415. entryRanges: range,
  3416. byteWidths: byteWidths,
  3417. entryNum: 0,
  3418. streamPos: stream.pos
  3419. };
  3420. }
  3421. this.readXRefStream(stream);
  3422. delete this.streamState;
  3423. return stream.dict;
  3424. },
  3425. readXRefStream: function XRef_readXRefStream(stream) {
  3426. var i, j;
  3427. var streamState = this.streamState;
  3428. stream.pos = streamState.streamPos;
  3429. var byteWidths = streamState.byteWidths;
  3430. var typeFieldWidth = byteWidths[0];
  3431. var offsetFieldWidth = byteWidths[1];
  3432. var generationFieldWidth = byteWidths[2];
  3433. var entryRanges = streamState.entryRanges;
  3434. while (entryRanges.length > 0) {
  3435. var first = entryRanges[0];
  3436. var n = entryRanges[1];
  3437. if (!isInt(first) || !isInt(n)) {
  3438. error('Invalid XRef range fields: ' + first + ', ' + n);
  3439. }
  3440. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3441. !isInt(generationFieldWidth)) {
  3442. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3443. }
  3444. for (i = streamState.entryNum; i < n; ++i) {
  3445. streamState.entryNum = i;
  3446. streamState.streamPos = stream.pos;
  3447. var type = 0, offset = 0, generation = 0;
  3448. for (j = 0; j < typeFieldWidth; ++j) {
  3449. type = (type << 8) | stream.getByte();
  3450. }
  3451. // if type field is absent, its default value is 1
  3452. if (typeFieldWidth === 0) {
  3453. type = 1;
  3454. }
  3455. for (j = 0; j < offsetFieldWidth; ++j) {
  3456. offset = (offset << 8) | stream.getByte();
  3457. }
  3458. for (j = 0; j < generationFieldWidth; ++j) {
  3459. generation = (generation << 8) | stream.getByte();
  3460. }
  3461. var entry = {};
  3462. entry.offset = offset;
  3463. entry.gen = generation;
  3464. switch (type) {
  3465. case 0:
  3466. entry.free = true;
  3467. break;
  3468. case 1:
  3469. entry.uncompressed = true;
  3470. break;
  3471. case 2:
  3472. break;
  3473. default:
  3474. error('Invalid XRef entry type: ' + type);
  3475. }
  3476. if (!this.entries[first + i]) {
  3477. this.entries[first + i] = entry;
  3478. }
  3479. }
  3480. streamState.entryNum = 0;
  3481. streamState.streamPos = stream.pos;
  3482. entryRanges.splice(0, 2);
  3483. }
  3484. },
  3485. indexObjects: function XRef_indexObjects() {
  3486. // Simple scan through the PDF content to find objects,
  3487. // trailers and XRef streams.
  3488. function readToken(data, offset) {
  3489. var token = '', ch = data[offset];
  3490. while (ch !== 13 && ch !== 10) {
  3491. if (++offset >= data.length) {
  3492. break;
  3493. }
  3494. token += String.fromCharCode(ch);
  3495. ch = data[offset];
  3496. }
  3497. return token;
  3498. }
  3499. function skipUntil(data, offset, what) {
  3500. var length = what.length, dataLength = data.length;
  3501. var skipped = 0;
  3502. // finding byte sequence
  3503. while (offset < dataLength) {
  3504. var i = 0;
  3505. while (i < length && data[offset + i] === what[i]) {
  3506. ++i;
  3507. }
  3508. if (i >= length) {
  3509. break; // sequence found
  3510. }
  3511. offset++;
  3512. skipped++;
  3513. }
  3514. return skipped;
  3515. }
  3516. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3517. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3518. 101, 102]);
  3519. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3520. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3521. var stream = this.stream;
  3522. stream.pos = 0;
  3523. var buffer = stream.getBytes();
  3524. var position = stream.start, length = buffer.length;
  3525. var trailers = [], xrefStms = [];
  3526. while (position < length) {
  3527. var ch = buffer[position];
  3528. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3529. ++position;
  3530. continue;
  3531. }
  3532. if (ch === 37) { // %-comment
  3533. do {
  3534. ++position;
  3535. if (position >= length) {
  3536. break;
  3537. }
  3538. ch = buffer[position];
  3539. } while (ch !== 13 && ch !== 10);
  3540. continue;
  3541. }
  3542. var token = readToken(buffer, position);
  3543. var m;
  3544. if (token === 'xref') {
  3545. position += skipUntil(buffer, position, trailerBytes);
  3546. trailers.push(position);
  3547. position += skipUntil(buffer, position, startxrefBytes);
  3548. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3549. this.entries[m[1]] = {
  3550. offset: position,
  3551. gen: m[2] | 0,
  3552. uncompressed: true
  3553. };
  3554. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3555. var content = buffer.subarray(position, position + contentLength);
  3556. // checking XRef stream suspect
  3557. // (it shall have '/XRef' and next char is not a letter)
  3558. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3559. if (xrefTagOffset < contentLength &&
  3560. content[xrefTagOffset + 5] < 64) {
  3561. xrefStms.push(position);
  3562. this.xrefstms[position] = 1; // don't read it recursively
  3563. }
  3564. position += contentLength;
  3565. } else {
  3566. position += token.length + 1;
  3567. }
  3568. }
  3569. // reading XRef streams
  3570. var i, ii;
  3571. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3572. this.startXRefQueue.push(xrefStms[i]);
  3573. this.readXRef(/* recoveryMode */ true);
  3574. }
  3575. // finding main trailer
  3576. var dict;
  3577. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3578. stream.pos = trailers[i];
  3579. var parser = new Parser(new Lexer(stream), true, this);
  3580. var obj = parser.getObj();
  3581. if (!isCmd(obj, 'trailer')) {
  3582. continue;
  3583. }
  3584. // read the trailer dictionary
  3585. if (!isDict(dict = parser.getObj())) {
  3586. continue;
  3587. }
  3588. // taking the first one with 'ID'
  3589. if (dict.has('ID')) {
  3590. return dict;
  3591. }
  3592. }
  3593. // no tailer with 'ID', taking last one (if exists)
  3594. if (dict) {
  3595. return dict;
  3596. }
  3597. // nothing helps
  3598. // calling error() would reject worker with an UnknownErrorException.
  3599. throw new InvalidPDFException('Invalid PDF structure');
  3600. },
  3601. readXRef: function XRef_readXRef(recoveryMode) {
  3602. var stream = this.stream;
  3603. try {
  3604. while (this.startXRefQueue.length) {
  3605. var startXRef = this.startXRefQueue[0];
  3606. stream.pos = startXRef + stream.start;
  3607. var parser = new Parser(new Lexer(stream), true, this);
  3608. var obj = parser.getObj();
  3609. var dict;
  3610. // Get dictionary
  3611. if (isCmd(obj, 'xref')) {
  3612. // Parse end-of-file XRef
  3613. dict = this.processXRefTable(parser);
  3614. if (!this.topDict) {
  3615. this.topDict = dict;
  3616. }
  3617. // Recursively get other XRefs 'XRefStm', if any
  3618. obj = dict.get('XRefStm');
  3619. if (isInt(obj)) {
  3620. var pos = obj;
  3621. // ignore previously loaded xref streams
  3622. // (possible infinite recursion)
  3623. if (!(pos in this.xrefstms)) {
  3624. this.xrefstms[pos] = 1;
  3625. this.startXRefQueue.push(pos);
  3626. }
  3627. }
  3628. } else if (isInt(obj)) {
  3629. // Parse in-stream XRef
  3630. if (!isInt(parser.getObj()) ||
  3631. !isCmd(parser.getObj(), 'obj') ||
  3632. !isStream(obj = parser.getObj())) {
  3633. error('Invalid XRef stream');
  3634. }
  3635. dict = this.processXRefStream(obj);
  3636. if (!this.topDict) {
  3637. this.topDict = dict;
  3638. }
  3639. if (!dict) {
  3640. error('Failed to read XRef stream');
  3641. }
  3642. } else {
  3643. error('Invalid XRef stream header');
  3644. }
  3645. // Recursively get previous dictionary, if any
  3646. obj = dict.get('Prev');
  3647. if (isInt(obj)) {
  3648. this.startXRefQueue.push(obj);
  3649. } else if (isRef(obj)) {
  3650. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3651. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3652. this.startXRefQueue.push(obj.num);
  3653. }
  3654. this.startXRefQueue.shift();
  3655. }
  3656. return this.topDict;
  3657. } catch (e) {
  3658. if (e instanceof MissingDataException) {
  3659. throw e;
  3660. }
  3661. info('(while reading XRef): ' + e);
  3662. }
  3663. if (recoveryMode) {
  3664. return;
  3665. }
  3666. throw new XRefParseException();
  3667. },
  3668. getEntry: function XRef_getEntry(i) {
  3669. var xrefEntry = this.entries[i];
  3670. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3671. return xrefEntry;
  3672. }
  3673. return null;
  3674. },
  3675. fetchIfRef: function XRef_fetchIfRef(obj) {
  3676. if (!isRef(obj)) {
  3677. return obj;
  3678. }
  3679. return this.fetch(obj);
  3680. },
  3681. fetch: function XRef_fetch(ref, suppressEncryption) {
  3682. assert(isRef(ref), 'ref object is not a reference');
  3683. var num = ref.num;
  3684. if (num in this.cache) {
  3685. var cacheEntry = this.cache[num];
  3686. return cacheEntry;
  3687. }
  3688. var xrefEntry = this.getEntry(num);
  3689. // the referenced entry can be free
  3690. if (xrefEntry === null) {
  3691. return (this.cache[num] = null);
  3692. }
  3693. if (xrefEntry.uncompressed) {
  3694. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3695. } else {
  3696. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3697. }
  3698. if (isDict(xrefEntry)){
  3699. xrefEntry.objId = ref.toString();
  3700. } else if (isStream(xrefEntry)) {
  3701. xrefEntry.dict.objId = ref.toString();
  3702. }
  3703. return xrefEntry;
  3704. },
  3705. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3706. suppressEncryption) {
  3707. var gen = ref.gen;
  3708. var num = ref.num;
  3709. if (xrefEntry.gen !== gen) {
  3710. error('inconsistent generation in XRef');
  3711. }
  3712. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3713. this.stream.start);
  3714. var parser = new Parser(new Lexer(stream), true, this);
  3715. var obj1 = parser.getObj();
  3716. var obj2 = parser.getObj();
  3717. var obj3 = parser.getObj();
  3718. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3719. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3720. !isCmd(obj3)) {
  3721. error('bad XRef entry');
  3722. }
  3723. if (!isCmd(obj3, 'obj')) {
  3724. // some bad PDFs use "obj1234" and really mean 1234
  3725. if (obj3.cmd.indexOf('obj') === 0) {
  3726. num = parseInt(obj3.cmd.substring(3), 10);
  3727. if (!isNaN(num)) {
  3728. return num;
  3729. }
  3730. }
  3731. error('bad XRef entry');
  3732. }
  3733. if (this.encrypt && !suppressEncryption) {
  3734. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3735. } else {
  3736. xrefEntry = parser.getObj();
  3737. }
  3738. if (!isStream(xrefEntry)) {
  3739. this.cache[num] = xrefEntry;
  3740. }
  3741. return xrefEntry;
  3742. },
  3743. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3744. suppressEncryption) {
  3745. var tableOffset = xrefEntry.offset;
  3746. var stream = this.fetch(new Ref(tableOffset, 0));
  3747. if (!isStream(stream)) {
  3748. error('bad ObjStm stream');
  3749. }
  3750. var first = stream.dict.get('First');
  3751. var n = stream.dict.get('N');
  3752. if (!isInt(first) || !isInt(n)) {
  3753. error('invalid first and n parameters for ObjStm stream');
  3754. }
  3755. var parser = new Parser(new Lexer(stream), false, this);
  3756. parser.allowStreams = true;
  3757. var i, entries = [], num, nums = [];
  3758. // read the object numbers to populate cache
  3759. for (i = 0; i < n; ++i) {
  3760. num = parser.getObj();
  3761. if (!isInt(num)) {
  3762. error('invalid object number in the ObjStm stream: ' + num);
  3763. }
  3764. nums.push(num);
  3765. var offset = parser.getObj();
  3766. if (!isInt(offset)) {
  3767. error('invalid object offset in the ObjStm stream: ' + offset);
  3768. }
  3769. }
  3770. // read stream objects for cache
  3771. for (i = 0; i < n; ++i) {
  3772. entries.push(parser.getObj());
  3773. num = nums[i];
  3774. var entry = this.entries[num];
  3775. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3776. this.cache[num] = entries[i];
  3777. }
  3778. }
  3779. xrefEntry = entries[xrefEntry.gen];
  3780. if (xrefEntry === undefined) {
  3781. error('bad XRef entry for compressed object');
  3782. }
  3783. return xrefEntry;
  3784. },
  3785. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3786. if (!isRef(obj)) {
  3787. return Promise.resolve(obj);
  3788. }
  3789. return this.fetchAsync(obj);
  3790. },
  3791. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3792. var streamManager = this.stream.manager;
  3793. var xref = this;
  3794. return new Promise(function tryFetch(resolve, reject) {
  3795. try {
  3796. resolve(xref.fetch(ref, suppressEncryption));
  3797. } catch (e) {
  3798. if (e instanceof MissingDataException) {
  3799. streamManager.requestRange(e.begin, e.end, function () {
  3800. tryFetch(resolve, reject);
  3801. });
  3802. return;
  3803. }
  3804. reject(e);
  3805. }
  3806. });
  3807. },
  3808. getCatalogObj: function XRef_getCatalogObj() {
  3809. return this.root;
  3810. }
  3811. };
  3812. return XRef;
  3813. })();
  3814. /**
  3815. * A NameTree is like a Dict but has some advantageous properties, see the
  3816. * spec (7.9.6) for more details.
  3817. * TODO: implement all the Dict functions and make this more efficent.
  3818. */
  3819. var NameTree = (function NameTreeClosure() {
  3820. function NameTree(root, xref) {
  3821. this.root = root;
  3822. this.xref = xref;
  3823. }
  3824. NameTree.prototype = {
  3825. getAll: function NameTree_getAll() {
  3826. var dict = {};
  3827. if (!this.root) {
  3828. return dict;
  3829. }
  3830. var xref = this.xref;
  3831. // reading name tree
  3832. var processed = new RefSet();
  3833. processed.put(this.root);
  3834. var queue = [this.root];
  3835. while (queue.length > 0) {
  3836. var i, n;
  3837. var obj = xref.fetchIfRef(queue.shift());
  3838. if (!isDict(obj)) {
  3839. continue;
  3840. }
  3841. if (obj.has('Kids')) {
  3842. var kids = obj.get('Kids');
  3843. for (i = 0, n = kids.length; i < n; i++) {
  3844. var kid = kids[i];
  3845. if (processed.has(kid)) {
  3846. error('invalid destinations');
  3847. }
  3848. queue.push(kid);
  3849. processed.put(kid);
  3850. }
  3851. continue;
  3852. }
  3853. var names = obj.get('Names');
  3854. if (names) {
  3855. for (i = 0, n = names.length; i < n; i += 2) {
  3856. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3857. }
  3858. }
  3859. }
  3860. return dict;
  3861. }
  3862. };
  3863. return NameTree;
  3864. })();
  3865. /**
  3866. * "A PDF file can refer to the contents of another file by using a File
  3867. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  3868. * NOTE: Only embedded files are supported (as part of the attachments support)
  3869. * TODO: support the 'URL' file system (with caching if !/V), portable
  3870. * collections attributes and related files (/RF)
  3871. */
  3872. var FileSpec = (function FileSpecClosure() {
  3873. function FileSpec(root, xref) {
  3874. if (!root || !isDict(root)) {
  3875. return;
  3876. }
  3877. this.xref = xref;
  3878. this.root = root;
  3879. if (root.has('FS')) {
  3880. this.fs = root.get('FS');
  3881. }
  3882. this.description = root.has('Desc') ?
  3883. stringToPDFString(root.get('Desc')) :
  3884. '';
  3885. if (root.has('RF')) {
  3886. warn('Related file specifications are not supported');
  3887. }
  3888. this.contentAvailable = true;
  3889. if (!root.has('EF')) {
  3890. this.contentAvailable = false;
  3891. warn('Non-embedded file specifications are not supported');
  3892. }
  3893. }
  3894. function pickPlatformItem(dict) {
  3895. // Look for the filename in this order:
  3896. // UF, F, Unix, Mac, DOS
  3897. if (dict.has('UF')) {
  3898. return dict.get('UF');
  3899. } else if (dict.has('F')) {
  3900. return dict.get('F');
  3901. } else if (dict.has('Unix')) {
  3902. return dict.get('Unix');
  3903. } else if (dict.has('Mac')) {
  3904. return dict.get('Mac');
  3905. } else if (dict.has('DOS')) {
  3906. return dict.get('DOS');
  3907. } else {
  3908. return null;
  3909. }
  3910. }
  3911. FileSpec.prototype = {
  3912. get filename() {
  3913. if (!this._filename && this.root) {
  3914. var filename = pickPlatformItem(this.root) || 'unnamed';
  3915. this._filename = stringToPDFString(filename).
  3916. replace(/\\\\/g, '\\').
  3917. replace(/\\\//g, '/').
  3918. replace(/\\/g, '/');
  3919. }
  3920. return this._filename;
  3921. },
  3922. get content() {
  3923. if (!this.contentAvailable) {
  3924. return null;
  3925. }
  3926. if (!this.contentRef && this.root) {
  3927. this.contentRef = pickPlatformItem(this.root.get('EF'));
  3928. }
  3929. var content = null;
  3930. if (this.contentRef) {
  3931. var xref = this.xref;
  3932. var fileObj = xref.fetchIfRef(this.contentRef);
  3933. if (fileObj && isStream(fileObj)) {
  3934. content = fileObj.getBytes();
  3935. } else {
  3936. warn('Embedded file specification points to non-existing/invalid ' +
  3937. 'content');
  3938. }
  3939. } else {
  3940. warn('Embedded file specification does not have a content');
  3941. }
  3942. return content;
  3943. },
  3944. get serializable() {
  3945. return {
  3946. filename: this.filename,
  3947. content: this.content
  3948. };
  3949. }
  3950. };
  3951. return FileSpec;
  3952. })();
  3953. /**
  3954. * A helper for loading missing data in object graphs. It traverses the graph
  3955. * depth first and queues up any objects that have missing data. Once it has
  3956. * has traversed as many objects that are available it attempts to bundle the
  3957. * missing data requests and then resume from the nodes that weren't ready.
  3958. *
  3959. * NOTE: It provides protection from circular references by keeping track of
  3960. * of loaded references. However, you must be careful not to load any graphs
  3961. * that have references to the catalog or other pages since that will cause the
  3962. * entire PDF document object graph to be traversed.
  3963. */
  3964. var ObjectLoader = (function() {
  3965. function mayHaveChildren(value) {
  3966. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  3967. }
  3968. function addChildren(node, nodesToVisit) {
  3969. var value;
  3970. if (isDict(node) || isStream(node)) {
  3971. var map;
  3972. if (isDict(node)) {
  3973. map = node.map;
  3974. } else {
  3975. map = node.dict.map;
  3976. }
  3977. for (var key in map) {
  3978. value = map[key];
  3979. if (mayHaveChildren(value)) {
  3980. nodesToVisit.push(value);
  3981. }
  3982. }
  3983. } else if (isArray(node)) {
  3984. for (var i = 0, ii = node.length; i < ii; i++) {
  3985. value = node[i];
  3986. if (mayHaveChildren(value)) {
  3987. nodesToVisit.push(value);
  3988. }
  3989. }
  3990. }
  3991. }
  3992. function ObjectLoader(obj, keys, xref) {
  3993. this.obj = obj;
  3994. this.keys = keys;
  3995. this.xref = xref;
  3996. this.refSet = null;
  3997. }
  3998. ObjectLoader.prototype = {
  3999. load: function ObjectLoader_load() {
  4000. var keys = this.keys;
  4001. this.capability = createPromiseCapability();
  4002. // Don't walk the graph if all the data is already loaded.
  4003. if (!(this.xref.stream instanceof ChunkedStream) ||
  4004. this.xref.stream.getMissingChunks().length === 0) {
  4005. this.capability.resolve();
  4006. return this.capability.promise;
  4007. }
  4008. this.refSet = new RefSet();
  4009. // Setup the initial nodes to visit.
  4010. var nodesToVisit = [];
  4011. for (var i = 0; i < keys.length; i++) {
  4012. nodesToVisit.push(this.obj[keys[i]]);
  4013. }
  4014. this.walk(nodesToVisit);
  4015. return this.capability.promise;
  4016. },
  4017. walk: function ObjectLoader_walk(nodesToVisit) {
  4018. var nodesToRevisit = [];
  4019. var pendingRequests = [];
  4020. // DFS walk of the object graph.
  4021. while (nodesToVisit.length) {
  4022. var currentNode = nodesToVisit.pop();
  4023. // Only references or chunked streams can cause missing data exceptions.
  4024. if (isRef(currentNode)) {
  4025. // Skip nodes that have already been visited.
  4026. if (this.refSet.has(currentNode)) {
  4027. continue;
  4028. }
  4029. try {
  4030. var ref = currentNode;
  4031. this.refSet.put(ref);
  4032. currentNode = this.xref.fetch(currentNode);
  4033. } catch (e) {
  4034. if (!(e instanceof MissingDataException)) {
  4035. throw e;
  4036. }
  4037. nodesToRevisit.push(currentNode);
  4038. pendingRequests.push({ begin: e.begin, end: e.end });
  4039. }
  4040. }
  4041. if (currentNode && currentNode.getBaseStreams) {
  4042. var baseStreams = currentNode.getBaseStreams();
  4043. var foundMissingData = false;
  4044. for (var i = 0; i < baseStreams.length; i++) {
  4045. var stream = baseStreams[i];
  4046. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4047. foundMissingData = true;
  4048. pendingRequests.push({
  4049. begin: stream.start,
  4050. end: stream.end
  4051. });
  4052. }
  4053. }
  4054. if (foundMissingData) {
  4055. nodesToRevisit.push(currentNode);
  4056. }
  4057. }
  4058. addChildren(currentNode, nodesToVisit);
  4059. }
  4060. if (pendingRequests.length) {
  4061. this.xref.stream.manager.requestRanges(pendingRequests,
  4062. function pendingRequestCallback() {
  4063. nodesToVisit = nodesToRevisit;
  4064. for (var i = 0; i < nodesToRevisit.length; i++) {
  4065. var node = nodesToRevisit[i];
  4066. // Remove any reference nodes from the currrent refset so they
  4067. // aren't skipped when we revist them.
  4068. if (isRef(node)) {
  4069. this.refSet.remove(node);
  4070. }
  4071. }
  4072. this.walk(nodesToVisit);
  4073. }.bind(this));
  4074. return;
  4075. }
  4076. // Everything is loaded.
  4077. this.refSet = null;
  4078. this.capability.resolve();
  4079. }
  4080. };
  4081. return ObjectLoader;
  4082. })();
  4083. var ISOAdobeCharset = [
  4084. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4085. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4086. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4087. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4088. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4089. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4090. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4091. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4092. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4093. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4094. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4095. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4096. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4097. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4098. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4099. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4100. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4101. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4102. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4103. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4104. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4105. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4106. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4107. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4108. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4109. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4110. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4111. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4112. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4113. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4114. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4115. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4116. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4117. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4118. ];
  4119. var ExpertCharset = [
  4120. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4121. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4122. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4123. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4124. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4125. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4126. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4127. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4128. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4129. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4130. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4131. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4132. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4133. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4134. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4135. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4136. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4137. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4138. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4139. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4140. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4141. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4142. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4143. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4144. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4145. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4146. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4147. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4148. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4149. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4150. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4151. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4152. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4153. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4154. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4155. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4156. 'Ydieresissmall'
  4157. ];
  4158. var ExpertSubsetCharset = [
  4159. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4160. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4161. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4162. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4163. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4164. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4165. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4166. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4167. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4168. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4169. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4170. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4171. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4172. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4173. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4174. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4175. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4176. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4177. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4178. 'periodinferior', 'commainferior'
  4179. ];
  4180. var DEFAULT_ICON_SIZE = 22; // px
  4181. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4182. var Annotation = (function AnnotationClosure() {
  4183. // 12.5.5: Algorithm: Appearance streams
  4184. function getTransformMatrix(rect, bbox, matrix) {
  4185. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4186. var minX = bounds[0];
  4187. var minY = bounds[1];
  4188. var maxX = bounds[2];
  4189. var maxY = bounds[3];
  4190. if (minX === maxX || minY === maxY) {
  4191. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4192. // just apply the transform for rect
  4193. return [1, 0, 0, 1, rect[0], rect[1]];
  4194. }
  4195. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4196. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4197. return [
  4198. xRatio,
  4199. 0,
  4200. 0,
  4201. yRatio,
  4202. rect[0] - minX * xRatio,
  4203. rect[1] - minY * yRatio
  4204. ];
  4205. }
  4206. function getDefaultAppearance(dict) {
  4207. var appearanceState = dict.get('AP');
  4208. if (!isDict(appearanceState)) {
  4209. return;
  4210. }
  4211. var appearance;
  4212. var appearances = appearanceState.get('N');
  4213. if (isDict(appearances)) {
  4214. var as = dict.get('AS');
  4215. if (as && appearances.has(as.name)) {
  4216. appearance = appearances.get(as.name);
  4217. }
  4218. } else {
  4219. appearance = appearances;
  4220. }
  4221. return appearance;
  4222. }
  4223. function Annotation(params) {
  4224. var dict = params.dict;
  4225. var data = this.data = {};
  4226. data.subtype = dict.get('Subtype').name;
  4227. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4228. data.rect = Util.normalizeRect(rect);
  4229. data.annotationFlags = dict.get('F');
  4230. var color = dict.get('C');
  4231. if (isArray(color) && color.length === 3) {
  4232. // TODO(mack): currently only supporting rgb; need support different
  4233. // colorspaces
  4234. data.color = color;
  4235. } else {
  4236. data.color = [0, 0, 0];
  4237. }
  4238. // Some types of annotations have border style dict which has more
  4239. // info than the border array
  4240. if (dict.has('BS')) {
  4241. var borderStyle = dict.get('BS');
  4242. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4243. } else {
  4244. var borderArray = dict.get('Border') || [0, 0, 1];
  4245. data.borderWidth = borderArray[2] || 0;
  4246. // TODO: implement proper support for annotations with line dash patterns.
  4247. var dashArray = borderArray[3];
  4248. if (data.borderWidth > 0 && dashArray) {
  4249. if (!isArray(dashArray)) {
  4250. // Ignore the border if dashArray is not actually an array,
  4251. // this is consistent with the behaviour in Adobe Reader.
  4252. data.borderWidth = 0;
  4253. } else {
  4254. var dashArrayLength = dashArray.length;
  4255. if (dashArrayLength > 0) {
  4256. // According to the PDF specification: the elements in a dashArray
  4257. // shall be numbers that are nonnegative and not all equal to zero.
  4258. var isInvalid = false;
  4259. var numPositive = 0;
  4260. for (var i = 0; i < dashArrayLength; i++) {
  4261. var validNumber = (+dashArray[i] >= 0);
  4262. if (!validNumber) {
  4263. isInvalid = true;
  4264. break;
  4265. } else if (dashArray[i] > 0) {
  4266. numPositive++;
  4267. }
  4268. }
  4269. if (isInvalid || numPositive === 0) {
  4270. data.borderWidth = 0;
  4271. }
  4272. }
  4273. }
  4274. }
  4275. }
  4276. this.appearance = getDefaultAppearance(dict);
  4277. data.hasAppearance = !!this.appearance;
  4278. data.id = params.ref.num;
  4279. }
  4280. Annotation.prototype = {
  4281. getData: function Annotation_getData() {
  4282. return this.data;
  4283. },
  4284. isInvisible: function Annotation_isInvisible() {
  4285. var data = this.data;
  4286. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4287. return false;
  4288. } else {
  4289. return !!(data &&
  4290. data.annotationFlags && // Default: not invisible
  4291. data.annotationFlags & 0x1); // Invisible
  4292. }
  4293. },
  4294. isViewable: function Annotation_isViewable() {
  4295. var data = this.data;
  4296. return !!(!this.isInvisible() &&
  4297. data &&
  4298. (!data.annotationFlags ||
  4299. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4300. data.rect); // rectangle is necessary
  4301. },
  4302. isPrintable: function Annotation_isPrintable() {
  4303. var data = this.data;
  4304. return !!(!this.isInvisible() &&
  4305. data &&
  4306. data.annotationFlags && // Default: not printable
  4307. data.annotationFlags & 0x4 && // Print
  4308. !(data.annotationFlags & 0x2) && // Hidden
  4309. data.rect); // rectangle is necessary
  4310. },
  4311. loadResources: function Annotation_loadResources(keys) {
  4312. return new Promise(function (resolve, reject) {
  4313. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4314. if (!resources) {
  4315. resolve();
  4316. return;
  4317. }
  4318. var objectLoader = new ObjectLoader(resources.map,
  4319. keys,
  4320. resources.xref);
  4321. objectLoader.load().then(function() {
  4322. resolve(resources);
  4323. }, reject);
  4324. }, reject);
  4325. }.bind(this));
  4326. },
  4327. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4328. if (!this.appearance) {
  4329. return Promise.resolve(new OperatorList());
  4330. }
  4331. var data = this.data;
  4332. var appearanceDict = this.appearance.dict;
  4333. var resourcesPromise = this.loadResources([
  4334. 'ExtGState',
  4335. 'ColorSpace',
  4336. 'Pattern',
  4337. 'Shading',
  4338. 'XObject',
  4339. 'Font'
  4340. // ProcSet
  4341. // Properties
  4342. ]);
  4343. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4344. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4345. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4346. var self = this;
  4347. return resourcesPromise.then(function(resources) {
  4348. var opList = new OperatorList();
  4349. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4350. return evaluator.getOperatorList(self.appearance, resources, opList).
  4351. then(function () {
  4352. opList.addOp(OPS.endAnnotation, []);
  4353. self.appearance.reset();
  4354. return opList;
  4355. });
  4356. });
  4357. }
  4358. };
  4359. Annotation.getConstructor =
  4360. function Annotation_getConstructor(subtype, fieldType) {
  4361. if (!subtype) {
  4362. return;
  4363. }
  4364. // TODO(mack): Implement FreeText annotations
  4365. if (subtype === 'Link') {
  4366. return LinkAnnotation;
  4367. } else if (subtype === 'Text') {
  4368. return TextAnnotation;
  4369. } else if (subtype === 'Widget') {
  4370. if (!fieldType) {
  4371. return;
  4372. }
  4373. if (fieldType === 'Tx') {
  4374. return TextWidgetAnnotation;
  4375. } else {
  4376. return WidgetAnnotation;
  4377. }
  4378. } else {
  4379. return Annotation;
  4380. }
  4381. };
  4382. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4383. var dict = xref.fetchIfRef(ref);
  4384. if (!isDict(dict)) {
  4385. return;
  4386. }
  4387. var subtype = dict.get('Subtype');
  4388. subtype = isName(subtype) ? subtype.name : '';
  4389. if (!subtype) {
  4390. return;
  4391. }
  4392. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4393. fieldType = isName(fieldType) ? fieldType.name : '';
  4394. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4395. if (!Constructor) {
  4396. return;
  4397. }
  4398. var params = {
  4399. dict: dict,
  4400. ref: ref,
  4401. };
  4402. var annotation = new Constructor(params);
  4403. if (annotation.isViewable() || annotation.isPrintable()) {
  4404. return annotation;
  4405. } else {
  4406. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4407. warn('unimplemented annotation type: ' + subtype);
  4408. }
  4409. }
  4410. };
  4411. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4412. annotations, opList, pdfManager, partialEvaluator, intent) {
  4413. function reject(e) {
  4414. annotationsReadyCapability.reject(e);
  4415. }
  4416. var annotationsReadyCapability = createPromiseCapability();
  4417. var annotationPromises = [];
  4418. for (var i = 0, n = annotations.length; i < n; ++i) {
  4419. if (intent === 'display' && annotations[i].isViewable() ||
  4420. intent === 'print' && annotations[i].isPrintable()) {
  4421. annotationPromises.push(
  4422. annotations[i].getOperatorList(partialEvaluator));
  4423. }
  4424. }
  4425. Promise.all(annotationPromises).then(function(datas) {
  4426. opList.addOp(OPS.beginAnnotations, []);
  4427. for (var i = 0, n = datas.length; i < n; ++i) {
  4428. var annotOpList = datas[i];
  4429. opList.addOpList(annotOpList);
  4430. }
  4431. opList.addOp(OPS.endAnnotations, []);
  4432. annotationsReadyCapability.resolve();
  4433. }, reject);
  4434. return annotationsReadyCapability.promise;
  4435. };
  4436. return Annotation;
  4437. })();
  4438. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4439. function WidgetAnnotation(params) {
  4440. Annotation.call(this, params);
  4441. var dict = params.dict;
  4442. var data = this.data;
  4443. data.fieldValue = stringToPDFString(
  4444. Util.getInheritableProperty(dict, 'V') || '');
  4445. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4446. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4447. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4448. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4449. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4450. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4451. // Building the full field name by collecting the field and
  4452. // its ancestors 'T' data and joining them using '.'.
  4453. var fieldName = [];
  4454. var namedItem = dict;
  4455. var ref = params.ref;
  4456. while (namedItem) {
  4457. var parent = namedItem.get('Parent');
  4458. var parentRef = namedItem.getRaw('Parent');
  4459. var name = namedItem.get('T');
  4460. if (name) {
  4461. fieldName.unshift(stringToPDFString(name));
  4462. } else {
  4463. // The field name is absent, that means more than one field
  4464. // with the same name may exist. Replacing the empty name
  4465. // with the '`' plus index in the parent's 'Kids' array.
  4466. // This is not in the PDF spec but necessary to id the
  4467. // the input controls.
  4468. var kids = parent.get('Kids');
  4469. var j, jj;
  4470. for (j = 0, jj = kids.length; j < jj; j++) {
  4471. var kidRef = kids[j];
  4472. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4473. break;
  4474. }
  4475. }
  4476. fieldName.unshift('`' + j);
  4477. }
  4478. namedItem = parent;
  4479. ref = parentRef;
  4480. }
  4481. data.fullName = fieldName.join('.');
  4482. }
  4483. var parent = Annotation.prototype;
  4484. Util.inherit(WidgetAnnotation, Annotation, {
  4485. isViewable: function WidgetAnnotation_isViewable() {
  4486. if (this.data.fieldType === 'Sig') {
  4487. warn('unimplemented annotation type: Widget signature');
  4488. return false;
  4489. }
  4490. return parent.isViewable.call(this);
  4491. }
  4492. });
  4493. return WidgetAnnotation;
  4494. })();
  4495. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4496. function TextWidgetAnnotation(params) {
  4497. WidgetAnnotation.call(this, params);
  4498. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4499. this.data.annotationType = AnnotationType.WIDGET;
  4500. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4501. }
  4502. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4503. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4504. if (this.appearance) {
  4505. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4506. }
  4507. var opList = new OperatorList();
  4508. var data = this.data;
  4509. // Even if there is an appearance stream, ignore it. This is the
  4510. // behaviour used by Adobe Reader.
  4511. if (!data.defaultAppearance) {
  4512. return Promise.resolve(opList);
  4513. }
  4514. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4515. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4516. then(function () {
  4517. return opList;
  4518. });
  4519. }
  4520. });
  4521. return TextWidgetAnnotation;
  4522. })();
  4523. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4524. function InteractiveAnnotation(params) {
  4525. Annotation.call(this, params);
  4526. this.data.hasHtml = true;
  4527. }
  4528. Util.inherit(InteractiveAnnotation, Annotation, { });
  4529. return InteractiveAnnotation;
  4530. })();
  4531. var TextAnnotation = (function TextAnnotationClosure() {
  4532. function TextAnnotation(params) {
  4533. InteractiveAnnotation.call(this, params);
  4534. var dict = params.dict;
  4535. var data = this.data;
  4536. var content = dict.get('Contents');
  4537. var title = dict.get('T');
  4538. data.annotationType = AnnotationType.TEXT;
  4539. data.content = stringToPDFString(content || '');
  4540. data.title = stringToPDFString(title || '');
  4541. if (data.hasAppearance) {
  4542. data.name = 'NoIcon';
  4543. } else {
  4544. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4545. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4546. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4547. }
  4548. if (dict.has('C')) {
  4549. data.hasBgColor = true;
  4550. }
  4551. }
  4552. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4553. return TextAnnotation;
  4554. })();
  4555. var LinkAnnotation = (function LinkAnnotationClosure() {
  4556. function LinkAnnotation(params) {
  4557. InteractiveAnnotation.call(this, params);
  4558. var dict = params.dict;
  4559. var data = this.data;
  4560. data.annotationType = AnnotationType.LINK;
  4561. var action = dict.get('A');
  4562. if (action) {
  4563. var linkType = action.get('S').name;
  4564. if (linkType === 'URI') {
  4565. var url = action.get('URI');
  4566. if (isName(url)) {
  4567. // Some bad PDFs do not put parentheses around relative URLs.
  4568. url = '/' + url.name;
  4569. } else if (url) {
  4570. url = addDefaultProtocolToUrl(url);
  4571. }
  4572. // TODO: pdf spec mentions urls can be relative to a Base
  4573. // entry in the dictionary.
  4574. if (!isValidUrl(url, false)) {
  4575. url = '';
  4576. }
  4577. data.url = url;
  4578. } else if (linkType === 'GoTo') {
  4579. data.dest = action.get('D');
  4580. } else if (linkType === 'GoToR') {
  4581. var urlDict = action.get('F');
  4582. if (isDict(urlDict)) {
  4583. // We assume that the 'url' is a Filspec dictionary
  4584. // and fetch the url without checking any further
  4585. url = urlDict.get('F') || '';
  4586. }
  4587. // TODO: pdf reference says that GoToR
  4588. // can also have 'NewWindow' attribute
  4589. if (!isValidUrl(url, false)) {
  4590. url = '';
  4591. }
  4592. data.url = url;
  4593. data.dest = action.get('D');
  4594. } else if (linkType === 'Named') {
  4595. data.action = action.get('N').name;
  4596. } else {
  4597. warn('unrecognized link type: ' + linkType);
  4598. }
  4599. } else if (dict.has('Dest')) {
  4600. // simple destination link
  4601. var dest = dict.get('Dest');
  4602. data.dest = isName(dest) ? dest.name : dest;
  4603. }
  4604. }
  4605. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4606. function addDefaultProtocolToUrl(url) {
  4607. if (url && url.indexOf('www.') === 0) {
  4608. return ('http://' + url);
  4609. }
  4610. return url;
  4611. }
  4612. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  4613. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  4614. return false;
  4615. }
  4616. });
  4617. return LinkAnnotation;
  4618. })();
  4619. var PDFFunction = (function PDFFunctionClosure() {
  4620. var CONSTRUCT_SAMPLED = 0;
  4621. var CONSTRUCT_INTERPOLATED = 2;
  4622. var CONSTRUCT_STICHED = 3;
  4623. var CONSTRUCT_POSTSCRIPT = 4;
  4624. return {
  4625. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4626. str) {
  4627. var i, ii;
  4628. var length = 1;
  4629. for (i = 0, ii = size.length; i < ii; i++) {
  4630. length *= size[i];
  4631. }
  4632. length *= outputSize;
  4633. var array = [];
  4634. var codeSize = 0;
  4635. var codeBuf = 0;
  4636. // 32 is a valid bps so shifting won't work
  4637. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4638. var strBytes = str.getBytes((length * bps + 7) / 8);
  4639. var strIdx = 0;
  4640. for (i = 0; i < length; i++) {
  4641. while (codeSize < bps) {
  4642. codeBuf <<= 8;
  4643. codeBuf |= strBytes[strIdx++];
  4644. codeSize += 8;
  4645. }
  4646. codeSize -= bps;
  4647. array.push((codeBuf >> codeSize) * sampleMul);
  4648. codeBuf &= (1 << codeSize) - 1;
  4649. }
  4650. return array;
  4651. },
  4652. getIR: function PDFFunction_getIR(xref, fn) {
  4653. var dict = fn.dict;
  4654. if (!dict) {
  4655. dict = fn;
  4656. }
  4657. var types = [this.constructSampled,
  4658. null,
  4659. this.constructInterpolated,
  4660. this.constructStiched,
  4661. this.constructPostScript];
  4662. var typeNum = dict.get('FunctionType');
  4663. var typeFn = types[typeNum];
  4664. if (!typeFn) {
  4665. error('Unknown type of function');
  4666. }
  4667. return typeFn.call(this, fn, dict, xref);
  4668. },
  4669. fromIR: function PDFFunction_fromIR(IR) {
  4670. var type = IR[0];
  4671. switch (type) {
  4672. case CONSTRUCT_SAMPLED:
  4673. return this.constructSampledFromIR(IR);
  4674. case CONSTRUCT_INTERPOLATED:
  4675. return this.constructInterpolatedFromIR(IR);
  4676. case CONSTRUCT_STICHED:
  4677. return this.constructStichedFromIR(IR);
  4678. //case CONSTRUCT_POSTSCRIPT:
  4679. default:
  4680. return this.constructPostScriptFromIR(IR);
  4681. }
  4682. },
  4683. parse: function PDFFunction_parse(xref, fn) {
  4684. var IR = this.getIR(xref, fn);
  4685. return this.fromIR(IR);
  4686. },
  4687. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4688. if (!isArray(fnObj)) {
  4689. // not an array -- parsing as regular function
  4690. return this.parse(xref, fnObj);
  4691. }
  4692. var fnArray = [];
  4693. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4694. var obj = xref.fetchIfRef(fnObj[j]);
  4695. fnArray.push(PDFFunction.parse(xref, obj));
  4696. }
  4697. return function (src, srcOffset, dest, destOffset) {
  4698. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4699. fnArray[i](src, srcOffset, dest, destOffset + i);
  4700. }
  4701. };
  4702. },
  4703. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4704. function toMultiArray(arr) {
  4705. var inputLength = arr.length;
  4706. var out = [];
  4707. var index = 0;
  4708. for (var i = 0; i < inputLength; i += 2) {
  4709. out[index] = [arr[i], arr[i + 1]];
  4710. ++index;
  4711. }
  4712. return out;
  4713. }
  4714. var domain = dict.get('Domain');
  4715. var range = dict.get('Range');
  4716. if (!domain || !range) {
  4717. error('No domain or range');
  4718. }
  4719. var inputSize = domain.length / 2;
  4720. var outputSize = range.length / 2;
  4721. domain = toMultiArray(domain);
  4722. range = toMultiArray(range);
  4723. var size = dict.get('Size');
  4724. var bps = dict.get('BitsPerSample');
  4725. var order = dict.get('Order') || 1;
  4726. if (order !== 1) {
  4727. // No description how cubic spline interpolation works in PDF32000:2008
  4728. // As in poppler, ignoring order, linear interpolation may work as good
  4729. info('No support for cubic spline interpolation: ' + order);
  4730. }
  4731. var encode = dict.get('Encode');
  4732. if (!encode) {
  4733. encode = [];
  4734. for (var i = 0; i < inputSize; ++i) {
  4735. encode.push(0);
  4736. encode.push(size[i] - 1);
  4737. }
  4738. }
  4739. encode = toMultiArray(encode);
  4740. var decode = dict.get('Decode');
  4741. if (!decode) {
  4742. decode = range;
  4743. } else {
  4744. decode = toMultiArray(decode);
  4745. }
  4746. var samples = this.getSampleArray(size, outputSize, bps, str);
  4747. return [
  4748. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4749. outputSize, Math.pow(2, bps) - 1, range
  4750. ];
  4751. },
  4752. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4753. // See chapter 3, page 109 of the PDF reference
  4754. function interpolate(x, xmin, xmax, ymin, ymax) {
  4755. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4756. }
  4757. return function constructSampledFromIRResult(src, srcOffset,
  4758. dest, destOffset) {
  4759. // See chapter 3, page 110 of the PDF reference.
  4760. var m = IR[1];
  4761. var domain = IR[2];
  4762. var encode = IR[3];
  4763. var decode = IR[4];
  4764. var samples = IR[5];
  4765. var size = IR[6];
  4766. var n = IR[7];
  4767. //var mask = IR[8];
  4768. var range = IR[9];
  4769. // Building the cube vertices: its part and sample index
  4770. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4771. var cubeVertices = 1 << m;
  4772. var cubeN = new Float64Array(cubeVertices);
  4773. var cubeVertex = new Uint32Array(cubeVertices);
  4774. var i, j;
  4775. for (j = 0; j < cubeVertices; j++) {
  4776. cubeN[j] = 1;
  4777. }
  4778. var k = n, pos = 1;
  4779. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4780. for (i = 0; i < m; ++i) {
  4781. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4782. var domain_2i = domain[i][0];
  4783. var domain_2i_1 = domain[i][1];
  4784. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4785. domain_2i_1);
  4786. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4787. // Encode_2i, Encode_2i+1)
  4788. var e = interpolate(xi, domain_2i, domain_2i_1,
  4789. encode[i][0], encode[i][1]);
  4790. // e_i' = min(max(e_i, 0), Size_i - 1)
  4791. var size_i = size[i];
  4792. e = Math.min(Math.max(e, 0), size_i - 1);
  4793. // Adjusting the cube: N and vertex sample index
  4794. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4795. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4796. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4797. var offset0 = e0 * k;
  4798. var offset1 = offset0 + k; // e1 * k
  4799. for (j = 0; j < cubeVertices; j++) {
  4800. if (j & pos) {
  4801. cubeN[j] *= n1;
  4802. cubeVertex[j] += offset1;
  4803. } else {
  4804. cubeN[j] *= n0;
  4805. cubeVertex[j] += offset0;
  4806. }
  4807. }
  4808. k *= size_i;
  4809. pos <<= 1;
  4810. }
  4811. for (j = 0; j < n; ++j) {
  4812. // Sum all cube vertices' samples portions
  4813. var rj = 0;
  4814. for (i = 0; i < cubeVertices; i++) {
  4815. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4816. }
  4817. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4818. // Decode_2j, Decode_2j+1)
  4819. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  4820. // y_j = min(max(r_j, range_2j), range_2j+1)
  4821. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  4822. range[j][1]);
  4823. }
  4824. };
  4825. },
  4826. constructInterpolated: function PDFFunction_constructInterpolated(str,
  4827. dict) {
  4828. var c0 = dict.get('C0') || [0];
  4829. var c1 = dict.get('C1') || [1];
  4830. var n = dict.get('N');
  4831. if (!isArray(c0) || !isArray(c1)) {
  4832. error('Illegal dictionary for interpolated function');
  4833. }
  4834. var length = c0.length;
  4835. var diff = [];
  4836. for (var i = 0; i < length; ++i) {
  4837. diff.push(c1[i] - c0[i]);
  4838. }
  4839. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  4840. },
  4841. constructInterpolatedFromIR:
  4842. function PDFFunction_constructInterpolatedFromIR(IR) {
  4843. var c0 = IR[1];
  4844. var diff = IR[2];
  4845. var n = IR[3];
  4846. var length = diff.length;
  4847. return function constructInterpolatedFromIRResult(src, srcOffset,
  4848. dest, destOffset) {
  4849. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  4850. for (var j = 0; j < length; ++j) {
  4851. dest[destOffset + j] = c0[j] + (x * diff[j]);
  4852. }
  4853. };
  4854. },
  4855. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  4856. var domain = dict.get('Domain');
  4857. if (!domain) {
  4858. error('No domain');
  4859. }
  4860. var inputSize = domain.length / 2;
  4861. if (inputSize !== 1) {
  4862. error('Bad domain for stiched function');
  4863. }
  4864. var fnRefs = dict.get('Functions');
  4865. var fns = [];
  4866. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  4867. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  4868. }
  4869. var bounds = dict.get('Bounds');
  4870. var encode = dict.get('Encode');
  4871. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  4872. },
  4873. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  4874. var domain = IR[1];
  4875. var bounds = IR[2];
  4876. var encode = IR[3];
  4877. var fnsIR = IR[4];
  4878. var fns = [];
  4879. var tmpBuf = new Float32Array(1);
  4880. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  4881. fns.push(PDFFunction.fromIR(fnsIR[i]));
  4882. }
  4883. return function constructStichedFromIRResult(src, srcOffset,
  4884. dest, destOffset) {
  4885. var clip = function constructStichedFromIRClip(v, min, max) {
  4886. if (v > max) {
  4887. v = max;
  4888. } else if (v < min) {
  4889. v = min;
  4890. }
  4891. return v;
  4892. };
  4893. // clip to domain
  4894. var v = clip(src[srcOffset], domain[0], domain[1]);
  4895. // calulate which bound the value is in
  4896. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  4897. if (v < bounds[i]) {
  4898. break;
  4899. }
  4900. }
  4901. // encode value into domain of function
  4902. var dmin = domain[0];
  4903. if (i > 0) {
  4904. dmin = bounds[i - 1];
  4905. }
  4906. var dmax = domain[1];
  4907. if (i < bounds.length) {
  4908. dmax = bounds[i];
  4909. }
  4910. var rmin = encode[2 * i];
  4911. var rmax = encode[2 * i + 1];
  4912. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  4913. // call the appropriate function
  4914. fns[i](tmpBuf, 0, dest, destOffset);
  4915. };
  4916. },
  4917. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  4918. xref) {
  4919. var domain = dict.get('Domain');
  4920. var range = dict.get('Range');
  4921. if (!domain) {
  4922. error('No domain.');
  4923. }
  4924. if (!range) {
  4925. error('No range.');
  4926. }
  4927. var lexer = new PostScriptLexer(fn);
  4928. var parser = new PostScriptParser(lexer);
  4929. var code = parser.parse();
  4930. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  4931. },
  4932. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  4933. IR) {
  4934. var domain = IR[1];
  4935. var range = IR[2];
  4936. var code = IR[3];
  4937. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  4938. if (compiled) {
  4939. // Compiled function consists of simple expressions such as addition,
  4940. // subtraction, Math.max, and also contains 'var' and 'return'
  4941. // statements. See the generation in the PostScriptCompiler below.
  4942. /*jshint -W054 */
  4943. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  4944. }
  4945. info('Unable to compile PS function');
  4946. var numOutputs = range.length >> 1;
  4947. var numInputs = domain.length >> 1;
  4948. var evaluator = new PostScriptEvaluator(code);
  4949. // Cache the values for a big speed up, the cache size is limited though
  4950. // since the number of possible values can be huge from a PS function.
  4951. var cache = {};
  4952. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  4953. // seen in our tests.
  4954. var MAX_CACHE_SIZE = 2048 * 4;
  4955. var cache_available = MAX_CACHE_SIZE;
  4956. var tmpBuf = new Float32Array(numInputs);
  4957. return function constructPostScriptFromIRResult(src, srcOffset,
  4958. dest, destOffset) {
  4959. var i, value;
  4960. var key = '';
  4961. var input = tmpBuf;
  4962. for (i = 0; i < numInputs; i++) {
  4963. value = src[srcOffset + i];
  4964. input[i] = value;
  4965. key += value + '_';
  4966. }
  4967. var cachedValue = cache[key];
  4968. if (cachedValue !== undefined) {
  4969. cachedValue.set(dest, destOffset);
  4970. return;
  4971. }
  4972. var output = new Float32Array(numOutputs);
  4973. var stack = evaluator.execute(input);
  4974. var stackIndex = stack.length - numOutputs;
  4975. for (i = 0; i < numOutputs; i++) {
  4976. value = stack[stackIndex + i];
  4977. var bound = range[i * 2];
  4978. if (value < bound) {
  4979. value = bound;
  4980. } else {
  4981. bound = range[i * 2 +1];
  4982. if (value > bound) {
  4983. value = bound;
  4984. }
  4985. }
  4986. output[i] = value;
  4987. }
  4988. if (cache_available > 0) {
  4989. cache_available--;
  4990. cache[key] = output;
  4991. }
  4992. output.set(dest, destOffset);
  4993. };
  4994. }
  4995. };
  4996. })();
  4997. function isPDFFunction(v) {
  4998. var fnDict;
  4999. if (typeof v !== 'object') {
  5000. return false;
  5001. } else if (isDict(v)) {
  5002. fnDict = v;
  5003. } else if (isStream(v)) {
  5004. fnDict = v.dict;
  5005. } else {
  5006. return false;
  5007. }
  5008. return fnDict.has('FunctionType');
  5009. }
  5010. var PostScriptStack = (function PostScriptStackClosure() {
  5011. var MAX_STACK_SIZE = 100;
  5012. function PostScriptStack(initialStack) {
  5013. this.stack = !initialStack ? [] :
  5014. Array.prototype.slice.call(initialStack, 0);
  5015. }
  5016. PostScriptStack.prototype = {
  5017. push: function PostScriptStack_push(value) {
  5018. if (this.stack.length >= MAX_STACK_SIZE) {
  5019. error('PostScript function stack overflow.');
  5020. }
  5021. this.stack.push(value);
  5022. },
  5023. pop: function PostScriptStack_pop() {
  5024. if (this.stack.length <= 0) {
  5025. error('PostScript function stack underflow.');
  5026. }
  5027. return this.stack.pop();
  5028. },
  5029. copy: function PostScriptStack_copy(n) {
  5030. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5031. error('PostScript function stack overflow.');
  5032. }
  5033. var stack = this.stack;
  5034. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5035. stack.push(stack[i]);
  5036. }
  5037. },
  5038. index: function PostScriptStack_index(n) {
  5039. this.push(this.stack[this.stack.length - n - 1]);
  5040. },
  5041. // rotate the last n stack elements p times
  5042. roll: function PostScriptStack_roll(n, p) {
  5043. var stack = this.stack;
  5044. var l = stack.length - n;
  5045. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5046. for (i = l, j = r; i < j; i++, j--) {
  5047. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5048. }
  5049. for (i = l, j = c - 1; i < j; i++, j--) {
  5050. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5051. }
  5052. for (i = c, j = r; i < j; i++, j--) {
  5053. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5054. }
  5055. }
  5056. };
  5057. return PostScriptStack;
  5058. })();
  5059. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5060. function PostScriptEvaluator(operators) {
  5061. this.operators = operators;
  5062. }
  5063. PostScriptEvaluator.prototype = {
  5064. execute: function PostScriptEvaluator_execute(initialStack) {
  5065. var stack = new PostScriptStack(initialStack);
  5066. var counter = 0;
  5067. var operators = this.operators;
  5068. var length = operators.length;
  5069. var operator, a, b;
  5070. while (counter < length) {
  5071. operator = operators[counter++];
  5072. if (typeof operator === 'number') {
  5073. // Operator is really an operand and should be pushed to the stack.
  5074. stack.push(operator);
  5075. continue;
  5076. }
  5077. switch (operator) {
  5078. // non standard ps operators
  5079. case 'jz': // jump if false
  5080. b = stack.pop();
  5081. a = stack.pop();
  5082. if (!a) {
  5083. counter = b;
  5084. }
  5085. break;
  5086. case 'j': // jump
  5087. a = stack.pop();
  5088. counter = a;
  5089. break;
  5090. // all ps operators in alphabetical order (excluding if/ifelse)
  5091. case 'abs':
  5092. a = stack.pop();
  5093. stack.push(Math.abs(a));
  5094. break;
  5095. case 'add':
  5096. b = stack.pop();
  5097. a = stack.pop();
  5098. stack.push(a + b);
  5099. break;
  5100. case 'and':
  5101. b = stack.pop();
  5102. a = stack.pop();
  5103. if (isBool(a) && isBool(b)) {
  5104. stack.push(a && b);
  5105. } else {
  5106. stack.push(a & b);
  5107. }
  5108. break;
  5109. case 'atan':
  5110. a = stack.pop();
  5111. stack.push(Math.atan(a));
  5112. break;
  5113. case 'bitshift':
  5114. b = stack.pop();
  5115. a = stack.pop();
  5116. if (a > 0) {
  5117. stack.push(a << b);
  5118. } else {
  5119. stack.push(a >> b);
  5120. }
  5121. break;
  5122. case 'ceiling':
  5123. a = stack.pop();
  5124. stack.push(Math.ceil(a));
  5125. break;
  5126. case 'copy':
  5127. a = stack.pop();
  5128. stack.copy(a);
  5129. break;
  5130. case 'cos':
  5131. a = stack.pop();
  5132. stack.push(Math.cos(a));
  5133. break;
  5134. case 'cvi':
  5135. a = stack.pop() | 0;
  5136. stack.push(a);
  5137. break;
  5138. case 'cvr':
  5139. // noop
  5140. break;
  5141. case 'div':
  5142. b = stack.pop();
  5143. a = stack.pop();
  5144. stack.push(a / b);
  5145. break;
  5146. case 'dup':
  5147. stack.copy(1);
  5148. break;
  5149. case 'eq':
  5150. b = stack.pop();
  5151. a = stack.pop();
  5152. stack.push(a === b);
  5153. break;
  5154. case 'exch':
  5155. stack.roll(2, 1);
  5156. break;
  5157. case 'exp':
  5158. b = stack.pop();
  5159. a = stack.pop();
  5160. stack.push(Math.pow(a, b));
  5161. break;
  5162. case 'false':
  5163. stack.push(false);
  5164. break;
  5165. case 'floor':
  5166. a = stack.pop();
  5167. stack.push(Math.floor(a));
  5168. break;
  5169. case 'ge':
  5170. b = stack.pop();
  5171. a = stack.pop();
  5172. stack.push(a >= b);
  5173. break;
  5174. case 'gt':
  5175. b = stack.pop();
  5176. a = stack.pop();
  5177. stack.push(a > b);
  5178. break;
  5179. case 'idiv':
  5180. b = stack.pop();
  5181. a = stack.pop();
  5182. stack.push((a / b) | 0);
  5183. break;
  5184. case 'index':
  5185. a = stack.pop();
  5186. stack.index(a);
  5187. break;
  5188. case 'le':
  5189. b = stack.pop();
  5190. a = stack.pop();
  5191. stack.push(a <= b);
  5192. break;
  5193. case 'ln':
  5194. a = stack.pop();
  5195. stack.push(Math.log(a));
  5196. break;
  5197. case 'log':
  5198. a = stack.pop();
  5199. stack.push(Math.log(a) / Math.LN10);
  5200. break;
  5201. case 'lt':
  5202. b = stack.pop();
  5203. a = stack.pop();
  5204. stack.push(a < b);
  5205. break;
  5206. case 'mod':
  5207. b = stack.pop();
  5208. a = stack.pop();
  5209. stack.push(a % b);
  5210. break;
  5211. case 'mul':
  5212. b = stack.pop();
  5213. a = stack.pop();
  5214. stack.push(a * b);
  5215. break;
  5216. case 'ne':
  5217. b = stack.pop();
  5218. a = stack.pop();
  5219. stack.push(a !== b);
  5220. break;
  5221. case 'neg':
  5222. a = stack.pop();
  5223. stack.push(-a);
  5224. break;
  5225. case 'not':
  5226. a = stack.pop();
  5227. if (isBool(a)) {
  5228. stack.push(!a);
  5229. } else {
  5230. stack.push(~a);
  5231. }
  5232. break;
  5233. case 'or':
  5234. b = stack.pop();
  5235. a = stack.pop();
  5236. if (isBool(a) && isBool(b)) {
  5237. stack.push(a || b);
  5238. } else {
  5239. stack.push(a | b);
  5240. }
  5241. break;
  5242. case 'pop':
  5243. stack.pop();
  5244. break;
  5245. case 'roll':
  5246. b = stack.pop();
  5247. a = stack.pop();
  5248. stack.roll(a, b);
  5249. break;
  5250. case 'round':
  5251. a = stack.pop();
  5252. stack.push(Math.round(a));
  5253. break;
  5254. case 'sin':
  5255. a = stack.pop();
  5256. stack.push(Math.sin(a));
  5257. break;
  5258. case 'sqrt':
  5259. a = stack.pop();
  5260. stack.push(Math.sqrt(a));
  5261. break;
  5262. case 'sub':
  5263. b = stack.pop();
  5264. a = stack.pop();
  5265. stack.push(a - b);
  5266. break;
  5267. case 'true':
  5268. stack.push(true);
  5269. break;
  5270. case 'truncate':
  5271. a = stack.pop();
  5272. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5273. stack.push(a);
  5274. break;
  5275. case 'xor':
  5276. b = stack.pop();
  5277. a = stack.pop();
  5278. if (isBool(a) && isBool(b)) {
  5279. stack.push(a !== b);
  5280. } else {
  5281. stack.push(a ^ b);
  5282. }
  5283. break;
  5284. default:
  5285. error('Unknown operator ' + operator);
  5286. break;
  5287. }
  5288. }
  5289. return stack.stack;
  5290. }
  5291. };
  5292. return PostScriptEvaluator;
  5293. })();
  5294. // Most of the PDFs functions consist of simple operations such as:
  5295. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5296. //
  5297. // We can compile most of such programs, and at the same moment, we can
  5298. // optimize some expressions using basic math properties. Keeping track of
  5299. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5300. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5301. function AstNode(type) {
  5302. this.type = type;
  5303. }
  5304. AstNode.prototype.visit = function (visitor) {
  5305. throw new Error('abstract method');
  5306. };
  5307. function AstArgument(index, min, max) {
  5308. AstNode.call(this, 'args');
  5309. this.index = index;
  5310. this.min = min;
  5311. this.max = max;
  5312. }
  5313. AstArgument.prototype = Object.create(AstNode.prototype);
  5314. AstArgument.prototype.visit = function (visitor) {
  5315. visitor.visitArgument(this);
  5316. };
  5317. function AstLiteral(number) {
  5318. AstNode.call(this, 'literal');
  5319. this.number = number;
  5320. this.min = number;
  5321. this.max = number;
  5322. }
  5323. AstLiteral.prototype = Object.create(AstNode.prototype);
  5324. AstLiteral.prototype.visit = function (visitor) {
  5325. visitor.visitLiteral(this);
  5326. };
  5327. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5328. AstNode.call(this, 'binary');
  5329. this.op = op;
  5330. this.arg1 = arg1;
  5331. this.arg2 = arg2;
  5332. this.min = min;
  5333. this.max = max;
  5334. }
  5335. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5336. AstBinaryOperation.prototype.visit = function (visitor) {
  5337. visitor.visitBinaryOperation(this);
  5338. };
  5339. function AstMin(arg, max) {
  5340. AstNode.call(this, 'max');
  5341. this.arg = arg;
  5342. this.min = arg.min;
  5343. this.max = max;
  5344. }
  5345. AstMin.prototype = Object.create(AstNode.prototype);
  5346. AstMin.prototype.visit = function (visitor) {
  5347. visitor.visitMin(this);
  5348. };
  5349. function AstVariable(index, min, max) {
  5350. AstNode.call(this, 'var');
  5351. this.index = index;
  5352. this.min = min;
  5353. this.max = max;
  5354. }
  5355. AstVariable.prototype = Object.create(AstNode.prototype);
  5356. AstVariable.prototype.visit = function (visitor) {
  5357. visitor.visitVariable(this);
  5358. };
  5359. function AstVariableDefinition(variable, arg) {
  5360. AstNode.call(this, 'definition');
  5361. this.variable = variable;
  5362. this.arg = arg;
  5363. }
  5364. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5365. AstVariableDefinition.prototype.visit = function (visitor) {
  5366. visitor.visitVariableDefinition(this);
  5367. };
  5368. function ExpressionBuilderVisitor() {
  5369. this.parts = [];
  5370. }
  5371. ExpressionBuilderVisitor.prototype = {
  5372. visitArgument: function (arg) {
  5373. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5374. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5375. },
  5376. visitVariable: function (variable) {
  5377. this.parts.push('v', variable.index);
  5378. },
  5379. visitLiteral: function (literal) {
  5380. this.parts.push(literal.number);
  5381. },
  5382. visitBinaryOperation: function (operation) {
  5383. this.parts.push('(');
  5384. operation.arg1.visit(this);
  5385. this.parts.push(' ', operation.op, ' ');
  5386. operation.arg2.visit(this);
  5387. this.parts.push(')');
  5388. },
  5389. visitVariableDefinition: function (definition) {
  5390. this.parts.push('var ');
  5391. definition.variable.visit(this);
  5392. this.parts.push(' = ');
  5393. definition.arg.visit(this);
  5394. this.parts.push(';');
  5395. },
  5396. visitMin: function (max) {
  5397. this.parts.push('Math.min(');
  5398. max.arg.visit(this);
  5399. this.parts.push(', ', max.max, ')');
  5400. },
  5401. toString: function () {
  5402. return this.parts.join('');
  5403. }
  5404. };
  5405. function buildAddOperation(num1, num2) {
  5406. if (num2.type === 'literal' && num2.number === 0) {
  5407. // optimization: second operand is 0
  5408. return num1;
  5409. }
  5410. if (num1.type === 'literal' && num1.number === 0) {
  5411. // optimization: first operand is 0
  5412. return num2;
  5413. }
  5414. if (num2.type === 'literal' && num1.type === 'literal') {
  5415. // optimization: operands operand are literals
  5416. return new AstLiteral(num1.number + num2.number);
  5417. }
  5418. return new AstBinaryOperation('+', num1, num2,
  5419. num1.min + num2.min, num1.max + num2.max);
  5420. }
  5421. function buildMulOperation(num1, num2) {
  5422. if (num2.type === 'literal') {
  5423. // optimization: second operands is a literal...
  5424. if (num2.number === 0) {
  5425. return new AstLiteral(0); // and it's 0
  5426. } else if (num2.number === 1) {
  5427. return num1; // and it's 1
  5428. } else if (num1.type === 'literal') {
  5429. // ... and first operands is a literal too
  5430. return new AstLiteral(num1.number * num2.number);
  5431. }
  5432. }
  5433. if (num1.type === 'literal') {
  5434. // optimization: first operands is a literal...
  5435. if (num1.number === 0) {
  5436. return new AstLiteral(0); // and it's 0
  5437. } else if (num1.number === 1) {
  5438. return num2; // and it's 1
  5439. }
  5440. }
  5441. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5442. num1.max * num2.min, num1.max * num2.max);
  5443. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5444. num1.max * num2.min, num1.max * num2.max);
  5445. return new AstBinaryOperation('*', num1, num2, min, max);
  5446. }
  5447. function buildSubOperation(num1, num2) {
  5448. if (num2.type === 'literal') {
  5449. // optimization: second operands is a literal...
  5450. if (num2.number === 0) {
  5451. return num1; // ... and it's 0
  5452. } else if (num1.type === 'literal') {
  5453. // ... and first operands is a literal too
  5454. return new AstLiteral(num1.number - num2.number);
  5455. }
  5456. }
  5457. if (num2.type === 'binary' && num2.op === '-' &&
  5458. num1.type === 'literal' && num1.number === 1 &&
  5459. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5460. // optimization for case: 1 - (1 - x)
  5461. return num2.arg2;
  5462. }
  5463. return new AstBinaryOperation('-', num1, num2,
  5464. num1.min - num2.max, num1.max - num2.min);
  5465. }
  5466. function buildMinOperation(num1, max) {
  5467. if (num1.min >= max) {
  5468. // optimization: num1 min value is not less than required max
  5469. return new AstLiteral(max); // just returning max
  5470. } else if (num1.max <= max) {
  5471. // optimization: num1 max value is not greater than required max
  5472. return num1; // just returning an argument
  5473. }
  5474. return new AstMin(num1, max);
  5475. }
  5476. function PostScriptCompiler() {}
  5477. PostScriptCompiler.prototype = {
  5478. compile: function PostScriptCompiler_compile(code, domain, range) {
  5479. var stack = [];
  5480. var i, ii;
  5481. var instructions = [];
  5482. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5483. var lastRegister = 0;
  5484. var n, j, min, max;
  5485. var num1, num2, ast1, ast2, tmpVar, item;
  5486. for (i = 0; i < inputSize; i++) {
  5487. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5488. }
  5489. for (i = 0, ii = code.length; i < ii; i++) {
  5490. item = code[i];
  5491. if (typeof item === 'number') {
  5492. stack.push(new AstLiteral(item));
  5493. continue;
  5494. }
  5495. switch (item) {
  5496. case 'add':
  5497. if (stack.length < 2) {
  5498. return null;
  5499. }
  5500. num2 = stack.pop();
  5501. num1 = stack.pop();
  5502. stack.push(buildAddOperation(num1, num2));
  5503. break;
  5504. case 'cvr':
  5505. if (stack.length < 1) {
  5506. return null;
  5507. }
  5508. break;
  5509. case 'mul':
  5510. if (stack.length < 2) {
  5511. return null;
  5512. }
  5513. num2 = stack.pop();
  5514. num1 = stack.pop();
  5515. stack.push(buildMulOperation(num1, num2));
  5516. break;
  5517. case 'sub':
  5518. if (stack.length < 2) {
  5519. return null;
  5520. }
  5521. num2 = stack.pop();
  5522. num1 = stack.pop();
  5523. stack.push(buildSubOperation(num1, num2));
  5524. break;
  5525. case 'exch':
  5526. if (stack.length < 2) {
  5527. return null;
  5528. }
  5529. ast1 = stack.pop(); ast2 = stack.pop();
  5530. stack.push(ast1, ast2);
  5531. break;
  5532. case 'pop':
  5533. if (stack.length < 1) {
  5534. return null;
  5535. }
  5536. stack.pop();
  5537. break;
  5538. case 'index':
  5539. if (stack.length < 1) {
  5540. return null;
  5541. }
  5542. num1 = stack.pop();
  5543. if (num1.type !== 'literal') {
  5544. return null;
  5545. }
  5546. n = num1.number;
  5547. if (n < 0 || (n|0) !== n || stack.length < n) {
  5548. return null;
  5549. }
  5550. ast1 = stack[stack.length - n - 1];
  5551. if (ast1.type === 'literal' || ast1.type === 'var') {
  5552. stack.push(ast1);
  5553. break;
  5554. }
  5555. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5556. stack[stack.length - n - 1] = tmpVar;
  5557. stack.push(tmpVar);
  5558. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5559. break;
  5560. case 'dup':
  5561. if (stack.length < 1) {
  5562. return null;
  5563. }
  5564. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5565. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5566. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5567. // special case of the commands sequence for the min operation
  5568. num1 = stack.pop();
  5569. stack.push(buildMinOperation(num1, code[i + 1]));
  5570. i += 6;
  5571. break;
  5572. }
  5573. ast1 = stack[stack.length - 1];
  5574. if (ast1.type === 'literal' || ast1.type === 'var') {
  5575. // we don't have to save into intermediate variable a literal or
  5576. // variable.
  5577. stack.push(ast1);
  5578. break;
  5579. }
  5580. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5581. stack[stack.length - 1] = tmpVar;
  5582. stack.push(tmpVar);
  5583. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5584. break;
  5585. case 'roll':
  5586. if (stack.length < 2) {
  5587. return null;
  5588. }
  5589. num2 = stack.pop();
  5590. num1 = stack.pop();
  5591. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5592. // both roll operands must be numbers
  5593. return null;
  5594. }
  5595. j = num2.number;
  5596. n = num1.number;
  5597. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5598. // ... and integers
  5599. return null;
  5600. }
  5601. j = ((j % n) + n) % n;
  5602. if (j === 0) {
  5603. break; // just skipping -- there are nothing to rotate
  5604. }
  5605. Array.prototype.push.apply(stack,
  5606. stack.splice(stack.length - n, n - j));
  5607. break;
  5608. default:
  5609. return null; // unsupported operator
  5610. }
  5611. }
  5612. if (stack.length !== outputSize) {
  5613. return null;
  5614. }
  5615. var result = [];
  5616. instructions.forEach(function (instruction) {
  5617. var statementBuilder = new ExpressionBuilderVisitor();
  5618. instruction.visit(statementBuilder);
  5619. result.push(statementBuilder.toString());
  5620. });
  5621. stack.forEach(function (expr, i) {
  5622. var statementBuilder = new ExpressionBuilderVisitor();
  5623. expr.visit(statementBuilder);
  5624. var min = range[i * 2], max = range[i * 2 + 1];
  5625. var out = [statementBuilder.toString()];
  5626. if (min > expr.min) {
  5627. out.unshift('Math.max(', min, ', ');
  5628. out.push(')');
  5629. }
  5630. if (max < expr.max) {
  5631. out.unshift('Math.min(', max, ', ');
  5632. out.push(')');
  5633. }
  5634. out.unshift('dest[destOffset + ', i, '] = ');
  5635. out.push(';');
  5636. result.push(out.join(''));
  5637. });
  5638. return result.join('\n');
  5639. }
  5640. };
  5641. return PostScriptCompiler;
  5642. })();
  5643. var ColorSpace = (function ColorSpaceClosure() {
  5644. // Constructor should define this.numComps, this.defaultColor, this.name
  5645. function ColorSpace() {
  5646. error('should not call ColorSpace constructor');
  5647. }
  5648. ColorSpace.prototype = {
  5649. /**
  5650. * Converts the color value to the RGB color. The color components are
  5651. * located in the src array starting from the srcOffset. Returns the array
  5652. * of the rgb components, each value ranging from [0,255].
  5653. */
  5654. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5655. var rgb = new Uint8Array(3);
  5656. this.getRgbItem(src, srcOffset, rgb, 0);
  5657. return rgb;
  5658. },
  5659. /**
  5660. * Converts the color value to the RGB color, similar to the getRgb method.
  5661. * The result placed into the dest array starting from the destOffset.
  5662. */
  5663. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5664. dest, destOffset) {
  5665. error('Should not call ColorSpace.getRgbItem');
  5666. },
  5667. /**
  5668. * Converts the specified number of the color values to the RGB colors.
  5669. * The colors are located in the src array starting from the srcOffset.
  5670. * The result is placed into the dest array starting from the destOffset.
  5671. * The src array items shall be in [0,2^bits) range, the dest array items
  5672. * will be in [0,255] range. alpha01 indicates how many alpha components
  5673. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5674. * array).
  5675. */
  5676. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5677. dest, destOffset, bits,
  5678. alpha01) {
  5679. error('Should not call ColorSpace.getRgbBuffer');
  5680. },
  5681. /**
  5682. * Determines the number of bytes required to store the result of the
  5683. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5684. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5685. */
  5686. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5687. alpha01) {
  5688. error('Should not call ColorSpace.getOutputLength');
  5689. },
  5690. /**
  5691. * Returns true if source data will be equal the result/output data.
  5692. */
  5693. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5694. return false;
  5695. },
  5696. /**
  5697. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5698. * how many alpha components there are in the dest array; it will be either
  5699. * 0 (RGB array) or 1 (RGBA array).
  5700. */
  5701. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5702. originalHeight, width, height,
  5703. actualHeight, bpc, comps, alpha01) {
  5704. var count = originalWidth * originalHeight;
  5705. var rgbBuf = null;
  5706. var numComponentColors = 1 << bpc;
  5707. var needsResizing = originalHeight !== height || originalWidth !== width;
  5708. var i, ii;
  5709. if (this.isPassthrough(bpc)) {
  5710. rgbBuf = comps;
  5711. } else if (this.numComps === 1 && count > numComponentColors &&
  5712. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5713. // Optimization: create a color map when there is just one component and
  5714. // we are converting more colors than the size of the color map. We
  5715. // don't build the map if the colorspace is gray or rgb since those
  5716. // methods are faster than building a map. This mainly offers big speed
  5717. // ups for indexed and alternate colorspaces.
  5718. //
  5719. // TODO it may be worth while to cache the color map. While running
  5720. // testing I never hit a cache so I will leave that out for now (perhaps
  5721. // we are reparsing colorspaces too much?).
  5722. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5723. new Uint16Array(numComponentColors);
  5724. var key;
  5725. for (i = 0; i < numComponentColors; i++) {
  5726. allColors[i] = i;
  5727. }
  5728. var colorMap = new Uint8Array(numComponentColors * 3);
  5729. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5730. /* alpha01 = */ 0);
  5731. var destPos, rgbPos;
  5732. if (!needsResizing) {
  5733. // Fill in the RGB values directly into |dest|.
  5734. destPos = 0;
  5735. for (i = 0; i < count; ++i) {
  5736. key = comps[i] * 3;
  5737. dest[destPos++] = colorMap[key];
  5738. dest[destPos++] = colorMap[key + 1];
  5739. dest[destPos++] = colorMap[key + 2];
  5740. destPos += alpha01;
  5741. }
  5742. } else {
  5743. rgbBuf = new Uint8Array(count * 3);
  5744. rgbPos = 0;
  5745. for (i = 0; i < count; ++i) {
  5746. key = comps[i] * 3;
  5747. rgbBuf[rgbPos++] = colorMap[key];
  5748. rgbBuf[rgbPos++] = colorMap[key + 1];
  5749. rgbBuf[rgbPos++] = colorMap[key + 2];
  5750. }
  5751. }
  5752. } else {
  5753. if (!needsResizing) {
  5754. // Fill in the RGB values directly into |dest|.
  5755. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5756. alpha01);
  5757. } else {
  5758. rgbBuf = new Uint8Array(count * 3);
  5759. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5760. /* alpha01 = */ 0);
  5761. }
  5762. }
  5763. if (rgbBuf) {
  5764. if (needsResizing) {
  5765. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5766. height, dest, alpha01);
  5767. } else {
  5768. rgbPos = 0;
  5769. destPos = 0;
  5770. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5771. dest[destPos++] = rgbBuf[rgbPos++];
  5772. dest[destPos++] = rgbBuf[rgbPos++];
  5773. dest[destPos++] = rgbBuf[rgbPos++];
  5774. destPos += alpha01;
  5775. }
  5776. }
  5777. }
  5778. },
  5779. /**
  5780. * True if the colorspace has components in the default range of [0, 1].
  5781. * This should be true for all colorspaces except for lab color spaces
  5782. * which are [0,100], [-128, 127], [-128, 127].
  5783. */
  5784. usesZeroToOneRange: true
  5785. };
  5786. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5787. var IR = ColorSpace.parseToIR(cs, xref, res);
  5788. if (IR instanceof AlternateCS) {
  5789. return IR;
  5790. }
  5791. return ColorSpace.fromIR(IR);
  5792. };
  5793. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5794. var name = isArray(IR) ? IR[0] : IR;
  5795. var whitePoint, blackPoint;
  5796. switch (name) {
  5797. case 'DeviceGrayCS':
  5798. return this.singletons.gray;
  5799. case 'DeviceRgbCS':
  5800. return this.singletons.rgb;
  5801. case 'DeviceCmykCS':
  5802. return this.singletons.cmyk;
  5803. case 'CalGrayCS':
  5804. whitePoint = IR[1].WhitePoint;
  5805. blackPoint = IR[1].BlackPoint;
  5806. var gamma = IR[1].Gamma;
  5807. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5808. case 'PatternCS':
  5809. var basePatternCS = IR[1];
  5810. if (basePatternCS) {
  5811. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5812. }
  5813. return new PatternCS(basePatternCS);
  5814. case 'IndexedCS':
  5815. var baseIndexedCS = IR[1];
  5816. var hiVal = IR[2];
  5817. var lookup = IR[3];
  5818. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  5819. case 'AlternateCS':
  5820. var numComps = IR[1];
  5821. var alt = IR[2];
  5822. var tintFnIR = IR[3];
  5823. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  5824. PDFFunction.fromIR(tintFnIR));
  5825. case 'LabCS':
  5826. whitePoint = IR[1].WhitePoint;
  5827. blackPoint = IR[1].BlackPoint;
  5828. var range = IR[1].Range;
  5829. return new LabCS(whitePoint, blackPoint, range);
  5830. default:
  5831. error('Unknown name ' + name);
  5832. }
  5833. return null;
  5834. };
  5835. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  5836. if (isName(cs)) {
  5837. var colorSpaces = res.get('ColorSpace');
  5838. if (isDict(colorSpaces)) {
  5839. var refcs = colorSpaces.get(cs.name);
  5840. if (refcs) {
  5841. cs = refcs;
  5842. }
  5843. }
  5844. }
  5845. cs = xref.fetchIfRef(cs);
  5846. var mode;
  5847. if (isName(cs)) {
  5848. mode = cs.name;
  5849. this.mode = mode;
  5850. switch (mode) {
  5851. case 'DeviceGray':
  5852. case 'G':
  5853. return 'DeviceGrayCS';
  5854. case 'DeviceRGB':
  5855. case 'RGB':
  5856. return 'DeviceRgbCS';
  5857. case 'DeviceCMYK':
  5858. case 'CMYK':
  5859. return 'DeviceCmykCS';
  5860. case 'Pattern':
  5861. return ['PatternCS', null];
  5862. default:
  5863. error('unrecognized colorspace ' + mode);
  5864. }
  5865. } else if (isArray(cs)) {
  5866. mode = cs[0].name;
  5867. this.mode = mode;
  5868. var numComps, params;
  5869. switch (mode) {
  5870. case 'DeviceGray':
  5871. case 'G':
  5872. return 'DeviceGrayCS';
  5873. case 'DeviceRGB':
  5874. case 'RGB':
  5875. return 'DeviceRgbCS';
  5876. case 'DeviceCMYK':
  5877. case 'CMYK':
  5878. return 'DeviceCmykCS';
  5879. case 'CalGray':
  5880. params = cs[1].getAll();
  5881. return ['CalGrayCS', params];
  5882. case 'CalRGB':
  5883. return 'DeviceRgbCS';
  5884. case 'ICCBased':
  5885. var stream = xref.fetchIfRef(cs[1]);
  5886. var dict = stream.dict;
  5887. numComps = dict.get('N');
  5888. if (numComps === 1) {
  5889. return 'DeviceGrayCS';
  5890. } else if (numComps === 3) {
  5891. return 'DeviceRgbCS';
  5892. } else if (numComps === 4) {
  5893. return 'DeviceCmykCS';
  5894. }
  5895. break;
  5896. case 'Pattern':
  5897. var basePatternCS = cs[1];
  5898. if (basePatternCS) {
  5899. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  5900. }
  5901. return ['PatternCS', basePatternCS];
  5902. case 'Indexed':
  5903. case 'I':
  5904. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  5905. var hiVal = cs[2] + 1;
  5906. var lookup = xref.fetchIfRef(cs[3]);
  5907. if (isStream(lookup)) {
  5908. lookup = lookup.getBytes();
  5909. }
  5910. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  5911. case 'Separation':
  5912. case 'DeviceN':
  5913. var name = cs[1];
  5914. numComps = 1;
  5915. if (isName(name)) {
  5916. numComps = 1;
  5917. } else if (isArray(name)) {
  5918. numComps = name.length;
  5919. }
  5920. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  5921. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  5922. return ['AlternateCS', numComps, alt, tintFnIR];
  5923. case 'Lab':
  5924. params = cs[1].getAll();
  5925. return ['LabCS', params];
  5926. default:
  5927. error('unimplemented color space object "' + mode + '"');
  5928. }
  5929. } else {
  5930. error('unrecognized color space object: "' + cs + '"');
  5931. }
  5932. return null;
  5933. };
  5934. /**
  5935. * Checks if a decode map matches the default decode map for a color space.
  5936. * This handles the general decode maps where there are two values per
  5937. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  5938. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  5939. * slightly different.
  5940. * @param {Array} decode Decode map (usually from an image).
  5941. * @param {Number} n Number of components the color space has.
  5942. */
  5943. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  5944. if (!decode) {
  5945. return true;
  5946. }
  5947. if (n * 2 !== decode.length) {
  5948. warn('The decode map is not the correct length');
  5949. return true;
  5950. }
  5951. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  5952. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  5953. return false;
  5954. }
  5955. }
  5956. return true;
  5957. };
  5958. ColorSpace.singletons = {
  5959. get gray() {
  5960. return shadow(this, 'gray', new DeviceGrayCS());
  5961. },
  5962. get rgb() {
  5963. return shadow(this, 'rgb', new DeviceRgbCS());
  5964. },
  5965. get cmyk() {
  5966. return shadow(this, 'cmyk', new DeviceCmykCS());
  5967. }
  5968. };
  5969. return ColorSpace;
  5970. })();
  5971. /**
  5972. * Alternate color space handles both Separation and DeviceN color spaces. A
  5973. * Separation color space is actually just a DeviceN with one color component.
  5974. * Both color spaces use a tinting function to convert colors to a base color
  5975. * space.
  5976. */
  5977. var AlternateCS = (function AlternateCSClosure() {
  5978. function AlternateCS(numComps, base, tintFn) {
  5979. this.name = 'Alternate';
  5980. this.numComps = numComps;
  5981. this.defaultColor = new Float32Array(numComps);
  5982. for (var i = 0; i < numComps; ++i) {
  5983. this.defaultColor[i] = 1;
  5984. }
  5985. this.base = base;
  5986. this.tintFn = tintFn;
  5987. this.tmpBuf = new Float32Array(base.numComps);
  5988. }
  5989. AlternateCS.prototype = {
  5990. getRgb: ColorSpace.prototype.getRgb,
  5991. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  5992. dest, destOffset) {
  5993. var tmpBuf = this.tmpBuf;
  5994. this.tintFn(src, srcOffset, tmpBuf, 0);
  5995. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  5996. },
  5997. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  5998. dest, destOffset, bits,
  5999. alpha01) {
  6000. var tintFn = this.tintFn;
  6001. var base = this.base;
  6002. var scale = 1 / ((1 << bits) - 1);
  6003. var baseNumComps = base.numComps;
  6004. var usesZeroToOneRange = base.usesZeroToOneRange;
  6005. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6006. alpha01 === 0;
  6007. var pos = isPassthrough ? destOffset : 0;
  6008. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6009. var numComps = this.numComps;
  6010. var scaled = new Float32Array(numComps);
  6011. var tinted = new Float32Array(baseNumComps);
  6012. var i, j;
  6013. if (usesZeroToOneRange) {
  6014. for (i = 0; i < count; i++) {
  6015. for (j = 0; j < numComps; j++) {
  6016. scaled[j] = src[srcOffset++] * scale;
  6017. }
  6018. tintFn(scaled, 0, tinted, 0);
  6019. for (j = 0; j < baseNumComps; j++) {
  6020. baseBuf[pos++] = tinted[j] * 255;
  6021. }
  6022. }
  6023. } else {
  6024. for (i = 0; i < count; i++) {
  6025. for (j = 0; j < numComps; j++) {
  6026. scaled[j] = src[srcOffset++] * scale;
  6027. }
  6028. tintFn(scaled, 0, tinted, 0);
  6029. base.getRgbItem(tinted, 0, baseBuf, pos);
  6030. pos += baseNumComps;
  6031. }
  6032. }
  6033. if (!isPassthrough) {
  6034. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6035. }
  6036. },
  6037. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6038. alpha01) {
  6039. return this.base.getOutputLength(inputLength *
  6040. this.base.numComps / this.numComps,
  6041. alpha01);
  6042. },
  6043. isPassthrough: ColorSpace.prototype.isPassthrough,
  6044. fillRgb: ColorSpace.prototype.fillRgb,
  6045. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6046. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6047. },
  6048. usesZeroToOneRange: true
  6049. };
  6050. return AlternateCS;
  6051. })();
  6052. var PatternCS = (function PatternCSClosure() {
  6053. function PatternCS(baseCS) {
  6054. this.name = 'Pattern';
  6055. this.base = baseCS;
  6056. }
  6057. PatternCS.prototype = {};
  6058. return PatternCS;
  6059. })();
  6060. var IndexedCS = (function IndexedCSClosure() {
  6061. function IndexedCS(base, highVal, lookup) {
  6062. this.name = 'Indexed';
  6063. this.numComps = 1;
  6064. this.defaultColor = new Uint8Array([0]);
  6065. this.base = base;
  6066. this.highVal = highVal;
  6067. var baseNumComps = base.numComps;
  6068. var length = baseNumComps * highVal;
  6069. var lookupArray;
  6070. if (isStream(lookup)) {
  6071. lookupArray = new Uint8Array(length);
  6072. var bytes = lookup.getBytes(length);
  6073. lookupArray.set(bytes);
  6074. } else if (isString(lookup)) {
  6075. lookupArray = new Uint8Array(length);
  6076. for (var i = 0; i < length; ++i) {
  6077. lookupArray[i] = lookup.charCodeAt(i);
  6078. }
  6079. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6080. lookupArray = lookup;
  6081. } else {
  6082. error('Unrecognized lookup table: ' + lookup);
  6083. }
  6084. this.lookup = lookupArray;
  6085. }
  6086. IndexedCS.prototype = {
  6087. getRgb: ColorSpace.prototype.getRgb,
  6088. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6089. dest, destOffset) {
  6090. var numComps = this.base.numComps;
  6091. var start = src[srcOffset] * numComps;
  6092. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6093. },
  6094. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6095. dest, destOffset, bits,
  6096. alpha01) {
  6097. var base = this.base;
  6098. var numComps = base.numComps;
  6099. var outputDelta = base.getOutputLength(numComps, alpha01);
  6100. var lookup = this.lookup;
  6101. for (var i = 0; i < count; ++i) {
  6102. var lookupPos = src[srcOffset++] * numComps;
  6103. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6104. destOffset += outputDelta;
  6105. }
  6106. },
  6107. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6108. return this.base.getOutputLength(inputLength * this.base.numComps,
  6109. alpha01);
  6110. },
  6111. isPassthrough: ColorSpace.prototype.isPassthrough,
  6112. fillRgb: ColorSpace.prototype.fillRgb,
  6113. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6114. // indexed color maps shouldn't be changed
  6115. return true;
  6116. },
  6117. usesZeroToOneRange: true
  6118. };
  6119. return IndexedCS;
  6120. })();
  6121. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6122. function DeviceGrayCS() {
  6123. this.name = 'DeviceGray';
  6124. this.numComps = 1;
  6125. this.defaultColor = new Float32Array([0]);
  6126. }
  6127. DeviceGrayCS.prototype = {
  6128. getRgb: ColorSpace.prototype.getRgb,
  6129. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6130. dest, destOffset) {
  6131. var c = (src[srcOffset] * 255) | 0;
  6132. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6133. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6134. },
  6135. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6136. dest, destOffset, bits,
  6137. alpha01) {
  6138. var scale = 255 / ((1 << bits) - 1);
  6139. var j = srcOffset, q = destOffset;
  6140. for (var i = 0; i < count; ++i) {
  6141. var c = (scale * src[j++]) | 0;
  6142. dest[q++] = c;
  6143. dest[q++] = c;
  6144. dest[q++] = c;
  6145. q += alpha01;
  6146. }
  6147. },
  6148. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6149. alpha01) {
  6150. return inputLength * (3 + alpha01);
  6151. },
  6152. isPassthrough: ColorSpace.prototype.isPassthrough,
  6153. fillRgb: ColorSpace.prototype.fillRgb,
  6154. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6155. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6156. },
  6157. usesZeroToOneRange: true
  6158. };
  6159. return DeviceGrayCS;
  6160. })();
  6161. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6162. function DeviceRgbCS() {
  6163. this.name = 'DeviceRGB';
  6164. this.numComps = 3;
  6165. this.defaultColor = new Float32Array([0, 0, 0]);
  6166. }
  6167. DeviceRgbCS.prototype = {
  6168. getRgb: ColorSpace.prototype.getRgb,
  6169. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6170. dest, destOffset) {
  6171. var r = (src[srcOffset] * 255) | 0;
  6172. var g = (src[srcOffset + 1] * 255) | 0;
  6173. var b = (src[srcOffset + 2] * 255) | 0;
  6174. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6175. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6176. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6177. },
  6178. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6179. dest, destOffset, bits,
  6180. alpha01) {
  6181. if (bits === 8 && alpha01 === 0) {
  6182. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6183. return;
  6184. }
  6185. var scale = 255 / ((1 << bits) - 1);
  6186. var j = srcOffset, q = destOffset;
  6187. for (var i = 0; i < count; ++i) {
  6188. dest[q++] = (scale * src[j++]) | 0;
  6189. dest[q++] = (scale * src[j++]) | 0;
  6190. dest[q++] = (scale * src[j++]) | 0;
  6191. q += alpha01;
  6192. }
  6193. },
  6194. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6195. alpha01) {
  6196. return (inputLength * (3 + alpha01) / 3) | 0;
  6197. },
  6198. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6199. return bits === 8;
  6200. },
  6201. fillRgb: ColorSpace.prototype.fillRgb,
  6202. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6203. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6204. },
  6205. usesZeroToOneRange: true
  6206. };
  6207. return DeviceRgbCS;
  6208. })();
  6209. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6210. // The coefficients below was found using numerical analysis: the method of
  6211. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6212. // where color_value is the tabular value from the table of sampled RGB colors
  6213. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6214. // CMYK color conversion using the estimation below:
  6215. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6216. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6217. var c = src[srcOffset + 0] * srcScale;
  6218. var m = src[srcOffset + 1] * srcScale;
  6219. var y = src[srcOffset + 2] * srcScale;
  6220. var k = src[srcOffset + 3] * srcScale;
  6221. var r =
  6222. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6223. 18.82290502165302 * y + 212.25662451639585 * k +
  6224. -285.2331026137004) +
  6225. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6226. -17.873870861415444 * k - 5.497006427196366) +
  6227. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6228. 17.5119270841813) +
  6229. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6230. var g =
  6231. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6232. 6.871425592049007 * y + 31.159100130055922 * k +
  6233. -79.2970844816548) +
  6234. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6235. 131.35250912493976 * k - 190.9453302588951) +
  6236. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6237. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6238. var b =
  6239. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6240. 30.89978309703729 * y - 0.23883238689178934 * k +
  6241. -14.183576799673286) +
  6242. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6243. 50.606957656360734 * k - 112.23884253719248) +
  6244. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6245. -193.58209356861505) +
  6246. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6247. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6248. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6249. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6250. }
  6251. function DeviceCmykCS() {
  6252. this.name = 'DeviceCMYK';
  6253. this.numComps = 4;
  6254. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6255. }
  6256. DeviceCmykCS.prototype = {
  6257. getRgb: ColorSpace.prototype.getRgb,
  6258. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6259. dest, destOffset) {
  6260. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6261. },
  6262. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6263. dest, destOffset, bits,
  6264. alpha01) {
  6265. var scale = 1 / ((1 << bits) - 1);
  6266. for (var i = 0; i < count; i++) {
  6267. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6268. srcOffset += 4;
  6269. destOffset += 3 + alpha01;
  6270. }
  6271. },
  6272. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6273. alpha01) {
  6274. return (inputLength / 4 * (3 + alpha01)) | 0;
  6275. },
  6276. isPassthrough: ColorSpace.prototype.isPassthrough,
  6277. fillRgb: ColorSpace.prototype.fillRgb,
  6278. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6279. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6280. },
  6281. usesZeroToOneRange: true
  6282. };
  6283. return DeviceCmykCS;
  6284. })();
  6285. //
  6286. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6287. //
  6288. var CalGrayCS = (function CalGrayCSClosure() {
  6289. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6290. this.name = 'CalGray';
  6291. this.numComps = 1;
  6292. this.defaultColor = new Float32Array([0]);
  6293. if (!whitePoint) {
  6294. error('WhitePoint missing - required for color space CalGray');
  6295. }
  6296. blackPoint = blackPoint || [0, 0, 0];
  6297. gamma = gamma || 1;
  6298. // Translate arguments to spec variables.
  6299. this.XW = whitePoint[0];
  6300. this.YW = whitePoint[1];
  6301. this.ZW = whitePoint[2];
  6302. this.XB = blackPoint[0];
  6303. this.YB = blackPoint[1];
  6304. this.ZB = blackPoint[2];
  6305. this.G = gamma;
  6306. // Validate variables as per spec.
  6307. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6308. error('Invalid WhitePoint components for ' + this.name +
  6309. ', no fallback available');
  6310. }
  6311. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6312. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6313. this.XB = this.YB = this.ZB = 0;
  6314. }
  6315. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6316. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6317. ', ZB: ' + this.ZB + ', only default values are supported.');
  6318. }
  6319. if (this.G < 1) {
  6320. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6321. ', falling back to default');
  6322. this.G = 1;
  6323. }
  6324. }
  6325. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6326. // A represents a gray component of a calibrated gray space.
  6327. // A <---> AG in the spec
  6328. var A = src[srcOffset] * scale;
  6329. var AG = Math.pow(A, cs.G);
  6330. // Computes L as per spec. ( = cs.YW * AG )
  6331. // Except if other than default BlackPoint values are used.
  6332. var L = cs.YW * AG;
  6333. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6334. // Convert values to rgb range [0, 255].
  6335. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6336. dest[destOffset] = val;
  6337. dest[destOffset + 1] = val;
  6338. dest[destOffset + 2] = val;
  6339. }
  6340. CalGrayCS.prototype = {
  6341. getRgb: ColorSpace.prototype.getRgb,
  6342. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6343. dest, destOffset) {
  6344. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6345. },
  6346. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6347. dest, destOffset, bits,
  6348. alpha01) {
  6349. var scale = 1 / ((1 << bits) - 1);
  6350. for (var i = 0; i < count; ++i) {
  6351. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6352. srcOffset += 1;
  6353. destOffset += 3 + alpha01;
  6354. }
  6355. },
  6356. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6357. return inputLength * (3 + alpha01);
  6358. },
  6359. isPassthrough: ColorSpace.prototype.isPassthrough,
  6360. fillRgb: ColorSpace.prototype.fillRgb,
  6361. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6362. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6363. },
  6364. usesZeroToOneRange: true
  6365. };
  6366. return CalGrayCS;
  6367. })();
  6368. //
  6369. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6370. //
  6371. var LabCS = (function LabCSClosure() {
  6372. function LabCS(whitePoint, blackPoint, range) {
  6373. this.name = 'Lab';
  6374. this.numComps = 3;
  6375. this.defaultColor = new Float32Array([0, 0, 0]);
  6376. if (!whitePoint) {
  6377. error('WhitePoint missing - required for color space Lab');
  6378. }
  6379. blackPoint = blackPoint || [0, 0, 0];
  6380. range = range || [-100, 100, -100, 100];
  6381. // Translate args to spec variables
  6382. this.XW = whitePoint[0];
  6383. this.YW = whitePoint[1];
  6384. this.ZW = whitePoint[2];
  6385. this.amin = range[0];
  6386. this.amax = range[1];
  6387. this.bmin = range[2];
  6388. this.bmax = range[3];
  6389. // These are here just for completeness - the spec doesn't offer any
  6390. // formulas that use BlackPoint in Lab
  6391. this.XB = blackPoint[0];
  6392. this.YB = blackPoint[1];
  6393. this.ZB = blackPoint[2];
  6394. // Validate vars as per spec
  6395. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6396. error('Invalid WhitePoint components, no fallback available');
  6397. }
  6398. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6399. info('Invalid BlackPoint, falling back to default');
  6400. this.XB = this.YB = this.ZB = 0;
  6401. }
  6402. if (this.amin > this.amax || this.bmin > this.bmax) {
  6403. info('Invalid Range, falling back to defaults');
  6404. this.amin = -100;
  6405. this.amax = 100;
  6406. this.bmin = -100;
  6407. this.bmax = 100;
  6408. }
  6409. }
  6410. // Function g(x) from spec
  6411. function fn_g(x) {
  6412. if (x >= 6 / 29) {
  6413. return x * x * x;
  6414. } else {
  6415. return (108 / 841) * (x - 4 / 29);
  6416. }
  6417. }
  6418. function decode(value, high1, low2, high2) {
  6419. return low2 + (value) * (high2 - low2) / (high1);
  6420. }
  6421. // If decoding is needed maxVal should be 2^bits per component - 1.
  6422. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6423. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6424. // not the usual [0, 1]. If a command like setFillColor is used the src
  6425. // values will already be within the correct range. However, if we are
  6426. // converting an image we have to map the values to the correct range given
  6427. // above.
  6428. // Ls,as,bs <---> L*,a*,b* in the spec
  6429. var Ls = src[srcOffset];
  6430. var as = src[srcOffset + 1];
  6431. var bs = src[srcOffset + 2];
  6432. if (maxVal !== false) {
  6433. Ls = decode(Ls, maxVal, 0, 100);
  6434. as = decode(as, maxVal, cs.amin, cs.amax);
  6435. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6436. }
  6437. // Adjust limits of 'as' and 'bs'
  6438. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6439. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6440. // Computes intermediate variables X,Y,Z as per spec
  6441. var M = (Ls + 16) / 116;
  6442. var L = M + (as / 500);
  6443. var N = M - (bs / 200);
  6444. var X = cs.XW * fn_g(L);
  6445. var Y = cs.YW * fn_g(M);
  6446. var Z = cs.ZW * fn_g(N);
  6447. var r, g, b;
  6448. // Using different conversions for D50 and D65 white points,
  6449. // per http://www.color.org/srgb.pdf
  6450. if (cs.ZW < 1) {
  6451. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6452. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6453. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6454. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6455. } else {
  6456. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6457. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6458. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6459. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6460. }
  6461. // clamp color values to [0,1] range then convert to [0,255] range.
  6462. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6463. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6464. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6465. }
  6466. LabCS.prototype = {
  6467. getRgb: ColorSpace.prototype.getRgb,
  6468. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6469. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6470. },
  6471. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6472. dest, destOffset, bits,
  6473. alpha01) {
  6474. var maxVal = (1 << bits) - 1;
  6475. for (var i = 0; i < count; i++) {
  6476. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6477. srcOffset += 3;
  6478. destOffset += 3 + alpha01;
  6479. }
  6480. },
  6481. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6482. return (inputLength * (3 + alpha01) / 3) | 0;
  6483. },
  6484. isPassthrough: ColorSpace.prototype.isPassthrough,
  6485. fillRgb: ColorSpace.prototype.fillRgb,
  6486. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6487. // XXX: Decoding is handled with the lab conversion because of the strange
  6488. // ranges that are used.
  6489. return true;
  6490. },
  6491. usesZeroToOneRange: false
  6492. };
  6493. return LabCS;
  6494. })();
  6495. var ARCFourCipher = (function ARCFourCipherClosure() {
  6496. function ARCFourCipher(key) {
  6497. this.a = 0;
  6498. this.b = 0;
  6499. var s = new Uint8Array(256);
  6500. var i, j = 0, tmp, keyLength = key.length;
  6501. for (i = 0; i < 256; ++i) {
  6502. s[i] = i;
  6503. }
  6504. for (i = 0; i < 256; ++i) {
  6505. tmp = s[i];
  6506. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6507. s[i] = s[j];
  6508. s[j] = tmp;
  6509. }
  6510. this.s = s;
  6511. }
  6512. ARCFourCipher.prototype = {
  6513. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6514. var i, n = data.length, tmp, tmp2;
  6515. var a = this.a, b = this.b, s = this.s;
  6516. var output = new Uint8Array(n);
  6517. for (i = 0; i < n; ++i) {
  6518. a = (a + 1) & 0xFF;
  6519. tmp = s[a];
  6520. b = (b + tmp) & 0xFF;
  6521. tmp2 = s[b];
  6522. s[a] = tmp2;
  6523. s[b] = tmp;
  6524. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6525. }
  6526. this.a = a;
  6527. this.b = b;
  6528. return output;
  6529. }
  6530. };
  6531. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6532. return ARCFourCipher;
  6533. })();
  6534. var calculateMD5 = (function calculateMD5Closure() {
  6535. var r = new Uint8Array([
  6536. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6537. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6538. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6539. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6540. var k = new Int32Array([
  6541. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6542. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6543. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6544. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6545. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6546. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6547. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6548. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6549. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6550. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6551. -145523070, -1120210379, 718787259, -343485551]);
  6552. function hash(data, offset, length) {
  6553. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6554. // pre-processing
  6555. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6556. var padded = new Uint8Array(paddedLength);
  6557. var i, j, n;
  6558. for (i = 0; i < length; ++i) {
  6559. padded[i] = data[offset++];
  6560. }
  6561. padded[i++] = 0x80;
  6562. n = paddedLength - 8;
  6563. while (i < n) {
  6564. padded[i++] = 0;
  6565. }
  6566. padded[i++] = (length << 3) & 0xFF;
  6567. padded[i++] = (length >> 5) & 0xFF;
  6568. padded[i++] = (length >> 13) & 0xFF;
  6569. padded[i++] = (length >> 21) & 0xFF;
  6570. padded[i++] = (length >>> 29) & 0xFF;
  6571. padded[i++] = 0;
  6572. padded[i++] = 0;
  6573. padded[i++] = 0;
  6574. var w = new Int32Array(16);
  6575. for (i = 0; i < paddedLength;) {
  6576. for (j = 0; j < 16; ++j, i += 4) {
  6577. w[j] = (padded[i] | (padded[i + 1] << 8) |
  6578. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  6579. }
  6580. var a = h0, b = h1, c = h2, d = h3, f, g;
  6581. for (j = 0; j < 64; ++j) {
  6582. if (j < 16) {
  6583. f = (b & c) | ((~b) & d);
  6584. g = j;
  6585. } else if (j < 32) {
  6586. f = (d & b) | ((~d) & c);
  6587. g = (5 * j + 1) & 15;
  6588. } else if (j < 48) {
  6589. f = b ^ c ^ d;
  6590. g = (3 * j + 5) & 15;
  6591. } else {
  6592. f = c ^ (b | (~d));
  6593. g = (7 * j) & 15;
  6594. }
  6595. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  6596. d = c;
  6597. c = b;
  6598. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  6599. a = tmp;
  6600. }
  6601. h0 = (h0 + a) | 0;
  6602. h1 = (h1 + b) | 0;
  6603. h2 = (h2 + c) | 0;
  6604. h3 = (h3 + d) | 0;
  6605. }
  6606. return new Uint8Array([
  6607. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  6608. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  6609. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  6610. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  6611. ]);
  6612. }
  6613. return hash;
  6614. })();
  6615. var Word64 = (function Word64Closure() {
  6616. function Word64(highInteger, lowInteger) {
  6617. this.high = highInteger | 0;
  6618. this.low = lowInteger | 0;
  6619. }
  6620. Word64.prototype = {
  6621. and: function Word64_and(word) {
  6622. this.high &= word.high;
  6623. this.low &= word.low;
  6624. },
  6625. xor: function Word64_xor(word) {
  6626. this.high ^= word.high;
  6627. this.low ^= word.low;
  6628. },
  6629. or: function Word64_or(word) {
  6630. this.high |= word.high;
  6631. this.low |= word.low;
  6632. },
  6633. shiftRight: function Word64_shiftRight(places) {
  6634. if (places >= 32) {
  6635. this.low = (this.high >>> (places - 32)) | 0;
  6636. this.high = 0;
  6637. } else {
  6638. this.low = (this.low >>> places) | (this.high << (32 - places));
  6639. this.high = (this.high >>> places) | 0;
  6640. }
  6641. },
  6642. shiftLeft: function Word64_shiftLeft(places) {
  6643. if (places >= 32) {
  6644. this.high = this.low << (places - 32);
  6645. this.low = 0;
  6646. } else {
  6647. this.high = (this.high << places) | (this.low >>> (32 - places));
  6648. this.low = this.low << places;
  6649. }
  6650. },
  6651. rotateRight: function Word64_rotateRight(places) {
  6652. var low, high;
  6653. if (places & 32) {
  6654. high = this.low;
  6655. low = this.high;
  6656. } else {
  6657. low = this.low;
  6658. high = this.high;
  6659. }
  6660. places &= 31;
  6661. this.low = (low >>> places) | (high << (32 - places));
  6662. this.high = (high >>> places) | (low << (32 - places));
  6663. },
  6664. not: function Word64_not() {
  6665. this.high = ~this.high;
  6666. this.low = ~this.low;
  6667. },
  6668. add: function Word64_add(word) {
  6669. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  6670. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  6671. if (lowAdd > 0xFFFFFFFF) {
  6672. highAdd += 1;
  6673. }
  6674. this.low = lowAdd | 0;
  6675. this.high = highAdd | 0;
  6676. },
  6677. copyTo: function Word64_copyTo(bytes, offset) {
  6678. bytes[offset] = (this.high >>> 24) & 0xFF;
  6679. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  6680. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  6681. bytes[offset + 3] = this.high & 0xFF;
  6682. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  6683. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  6684. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  6685. bytes[offset + 7] = this.low & 0xFF;
  6686. },
  6687. assign: function Word64_assign(word) {
  6688. this.high = word.high;
  6689. this.low = word.low;
  6690. }
  6691. };
  6692. return Word64;
  6693. })();
  6694. var calculateSHA256 = (function calculateSHA256Closure() {
  6695. function rotr(x, n) {
  6696. return (x >>> n) | (x << 32 - n);
  6697. }
  6698. function ch(x, y, z) {
  6699. return (x & y) ^ (~x & z);
  6700. }
  6701. function maj(x, y, z) {
  6702. return (x & y) ^ (x & z) ^ (y & z);
  6703. }
  6704. function sigma(x) {
  6705. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  6706. }
  6707. function sigmaPrime(x) {
  6708. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  6709. }
  6710. function littleSigma(x) {
  6711. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  6712. }
  6713. function littleSigmaPrime(x) {
  6714. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  6715. }
  6716. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  6717. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  6718. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  6719. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  6720. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  6721. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  6722. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  6723. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  6724. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  6725. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  6726. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  6727. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  6728. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  6729. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  6730. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  6731. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  6732. function hash(data, offset, length) {
  6733. // initial hash values
  6734. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  6735. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  6736. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  6737. // pre-processing
  6738. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  6739. var padded = new Uint8Array(paddedLength);
  6740. var i, j, n;
  6741. for (i = 0; i < length; ++i) {
  6742. padded[i] = data[offset++];
  6743. }
  6744. padded[i++] = 0x80;
  6745. n = paddedLength - 8;
  6746. while (i < n) {
  6747. padded[i++] = 0;
  6748. }
  6749. padded[i++] = 0;
  6750. padded[i++] = 0;
  6751. padded[i++] = 0;
  6752. padded[i++] = (length >>> 29) & 0xFF;
  6753. padded[i++] = (length >> 21) & 0xFF;
  6754. padded[i++] = (length >> 13) & 0xFF;
  6755. padded[i++] = (length >> 5) & 0xFF;
  6756. padded[i++] = (length << 3) & 0xFF;
  6757. var w = new Uint32Array(64);
  6758. // for each 512 bit block
  6759. for (i = 0; i < paddedLength;) {
  6760. for (j = 0; j < 16; ++j) {
  6761. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  6762. (padded[i + 2] << 8) | (padded[i + 3]));
  6763. i += 4;
  6764. }
  6765. for (j = 16; j < 64; ++j) {
  6766. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  6767. littleSigma(w[j - 15]) + w[j - 16] | 0;
  6768. }
  6769. var a = h0, b = h1, c = h2, d = h3, e = h4,
  6770. f = h5, g = h6, h = h7, t1, t2;
  6771. for (j = 0; j < 64; ++j) {
  6772. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  6773. t2 = sigma(a) + maj(a, b, c);
  6774. h = g;
  6775. g = f;
  6776. f = e;
  6777. e = (d + t1) | 0;
  6778. d = c;
  6779. c = b;
  6780. b = a;
  6781. a = (t1 + t2) | 0;
  6782. }
  6783. h0 = (h0 + a) | 0;
  6784. h1 = (h1 + b) | 0;
  6785. h2 = (h2 + c) | 0;
  6786. h3 = (h3 + d) | 0;
  6787. h4 = (h4 + e) | 0;
  6788. h5 = (h5 + f) | 0;
  6789. h6 = (h6 + g) | 0;
  6790. h7 = (h7 + h) | 0;
  6791. }
  6792. return new Uint8Array([
  6793. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  6794. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  6795. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  6796. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  6797. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  6798. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  6799. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  6800. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  6801. ]);
  6802. }
  6803. return hash;
  6804. })();
  6805. var calculateSHA512 = (function calculateSHA512Closure() {
  6806. function ch(result, x, y, z, tmp) {
  6807. result.assign(x);
  6808. result.and(y);
  6809. tmp.assign(x);
  6810. tmp.not();
  6811. tmp.and(z);
  6812. result.xor(tmp);
  6813. }
  6814. function maj(result, x, y, z, tmp) {
  6815. result.assign(x);
  6816. result.and(y);
  6817. tmp.assign(x);
  6818. tmp.and(z);
  6819. result.xor(tmp);
  6820. tmp.assign(y);
  6821. tmp.and(z);
  6822. result.xor(tmp);
  6823. }
  6824. function sigma(result, x, tmp) {
  6825. result.assign(x);
  6826. result.rotateRight(28);
  6827. tmp.assign(x);
  6828. tmp.rotateRight(34);
  6829. result.xor(tmp);
  6830. tmp.assign(x);
  6831. tmp.rotateRight(39);
  6832. result.xor(tmp);
  6833. }
  6834. function sigmaPrime(result, x, tmp) {
  6835. result.assign(x);
  6836. result.rotateRight(14);
  6837. tmp.assign(x);
  6838. tmp.rotateRight(18);
  6839. result.xor(tmp);
  6840. tmp.assign(x);
  6841. tmp.rotateRight(41);
  6842. result.xor(tmp);
  6843. }
  6844. function littleSigma(result, x, tmp) {
  6845. result.assign(x);
  6846. result.rotateRight(1);
  6847. tmp.assign(x);
  6848. tmp.rotateRight(8);
  6849. result.xor(tmp);
  6850. tmp.assign(x);
  6851. tmp.shiftRight(7);
  6852. result.xor(tmp);
  6853. }
  6854. function littleSigmaPrime(result, x, tmp) {
  6855. result.assign(x);
  6856. result.rotateRight(19);
  6857. tmp.assign(x);
  6858. tmp.rotateRight(61);
  6859. result.xor(tmp);
  6860. tmp.assign(x);
  6861. tmp.shiftRight(6);
  6862. result.xor(tmp);
  6863. }
  6864. var k = [
  6865. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  6866. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  6867. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  6868. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  6869. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  6870. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  6871. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  6872. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  6873. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  6874. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  6875. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  6876. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  6877. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  6878. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  6879. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  6880. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  6881. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  6882. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  6883. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  6884. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  6885. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  6886. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  6887. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  6888. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  6889. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  6890. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  6891. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  6892. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  6893. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  6894. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  6895. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  6896. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  6897. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  6898. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  6899. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  6900. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  6901. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  6902. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  6903. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  6904. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  6905. function hash(data, offset, length, mode384) {
  6906. mode384 = !!mode384;
  6907. // initial hash values
  6908. var h0, h1, h2, h3, h4, h5, h6, h7;
  6909. if (!mode384) {
  6910. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  6911. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  6912. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  6913. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  6914. h4 = new Word64(0x510e527f, 0xade682d1);
  6915. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  6916. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  6917. h7 = new Word64(0x5be0cd19, 0x137e2179);
  6918. }
  6919. else {
  6920. // SHA384 is exactly the same
  6921. // except with different starting values and a trimmed result
  6922. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  6923. h1 = new Word64(0x629a292a, 0x367cd507);
  6924. h2 = new Word64(0x9159015a, 0x3070dd17);
  6925. h3 = new Word64(0x152fecd8, 0xf70e5939);
  6926. h4 = new Word64(0x67332667, 0xffc00b31);
  6927. h5 = new Word64(0x8eb44a87, 0x68581511);
  6928. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  6929. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  6930. }
  6931. // pre-processing
  6932. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  6933. var padded = new Uint8Array(paddedLength);
  6934. var i, j, n;
  6935. for (i = 0; i < length; ++i) {
  6936. padded[i] = data[offset++];
  6937. }
  6938. padded[i++] = 0x80;
  6939. n = paddedLength - 16;
  6940. while (i < n) {
  6941. padded[i++] = 0;
  6942. }
  6943. padded[i++] = 0;
  6944. padded[i++] = 0;
  6945. padded[i++] = 0;
  6946. padded[i++] = 0;
  6947. padded[i++] = 0;
  6948. padded[i++] = 0;
  6949. padded[i++] = 0;
  6950. padded[i++] = 0;
  6951. padded[i++] = 0;
  6952. padded[i++] = 0;
  6953. padded[i++] = 0;
  6954. padded[i++] = (length >>> 29) & 0xFF;
  6955. padded[i++] = (length >> 21) & 0xFF;
  6956. padded[i++] = (length >> 13) & 0xFF;
  6957. padded[i++] = (length >> 5) & 0xFF;
  6958. padded[i++] = (length << 3) & 0xFF;
  6959. var w = new Array(80);
  6960. for (i = 0; i < 80; i++) {
  6961. w[i] = new Word64(0, 0);
  6962. }
  6963. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  6964. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  6965. var g = new Word64(0, 0), h = new Word64(0, 0);
  6966. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  6967. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  6968. // for each 1024 bit block
  6969. for (i = 0; i < paddedLength;) {
  6970. for (j = 0; j < 16; ++j) {
  6971. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  6972. (padded[i + 2] << 8) | (padded[i + 3]);
  6973. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  6974. (padded[i + 6]) << 8 | (padded[i + 7]);
  6975. i += 8;
  6976. }
  6977. for (j = 16; j < 80; ++j) {
  6978. tmp3 = w[j];
  6979. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  6980. tmp3.add(w[j - 7]);
  6981. littleSigma(tmp1, w[j - 15], tmp2);
  6982. tmp3.add(tmp1);
  6983. tmp3.add(w[j - 16]);
  6984. }
  6985. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  6986. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  6987. for (j = 0; j < 80; ++j) {
  6988. t1.assign(h);
  6989. sigmaPrime(tmp1, e, tmp2);
  6990. t1.add(tmp1);
  6991. ch(tmp1, e, f, g, tmp2);
  6992. t1.add(tmp1);
  6993. t1.add(k[j]);
  6994. t1.add(w[j]);
  6995. sigma(t2, a, tmp2);
  6996. maj(tmp1, a, b, c, tmp2);
  6997. t2.add(tmp1);
  6998. tmp3 = h;
  6999. h = g;
  7000. g = f;
  7001. f = e;
  7002. d.add(t1);
  7003. e = d;
  7004. d = c;
  7005. c = b;
  7006. b = a;
  7007. tmp3.assign(t1);
  7008. tmp3.add(t2);
  7009. a = tmp3;
  7010. }
  7011. h0.add(a);
  7012. h1.add(b);
  7013. h2.add(c);
  7014. h3.add(d);
  7015. h4.add(e);
  7016. h5.add(f);
  7017. h6.add(g);
  7018. h7.add(h);
  7019. }
  7020. var result;
  7021. if (!mode384) {
  7022. result = new Uint8Array(64);
  7023. h0.copyTo(result,0);
  7024. h1.copyTo(result,8);
  7025. h2.copyTo(result,16);
  7026. h3.copyTo(result,24);
  7027. h4.copyTo(result,32);
  7028. h5.copyTo(result,40);
  7029. h6.copyTo(result,48);
  7030. h7.copyTo(result,56);
  7031. }
  7032. else {
  7033. result = new Uint8Array(48);
  7034. h0.copyTo(result,0);
  7035. h1.copyTo(result,8);
  7036. h2.copyTo(result,16);
  7037. h3.copyTo(result,24);
  7038. h4.copyTo(result,32);
  7039. h5.copyTo(result,40);
  7040. }
  7041. return result;
  7042. }
  7043. return hash;
  7044. })();
  7045. var calculateSHA384 = (function calculateSHA384Closure() {
  7046. function hash(data, offset, length) {
  7047. return calculateSHA512(data, offset, length, true);
  7048. }
  7049. return hash;
  7050. })();
  7051. var NullCipher = (function NullCipherClosure() {
  7052. function NullCipher() {
  7053. }
  7054. NullCipher.prototype = {
  7055. decryptBlock: function NullCipher_decryptBlock(data) {
  7056. return data;
  7057. }
  7058. };
  7059. return NullCipher;
  7060. })();
  7061. var AES128Cipher = (function AES128CipherClosure() {
  7062. var rcon = new Uint8Array([
  7063. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7064. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7065. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7066. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7067. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7068. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7069. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7070. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7071. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7072. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7073. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7074. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7075. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7076. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7077. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7078. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7079. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7080. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7081. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7082. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7083. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7084. 0x74, 0xe8, 0xcb, 0x8d]);
  7085. var s = new Uint8Array([
  7086. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7087. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7088. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7089. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7090. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7091. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7092. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7093. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7094. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7095. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7096. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7097. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7098. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7099. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7100. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7101. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7102. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7103. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7104. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7105. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7106. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7107. 0xb0, 0x54, 0xbb, 0x16]);
  7108. var inv_s = new Uint8Array([
  7109. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7110. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7111. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7112. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7113. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7114. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7115. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7116. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7117. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7118. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7119. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7120. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7121. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7122. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7123. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7124. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7125. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7126. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7127. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7128. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7129. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7130. 0x55, 0x21, 0x0c, 0x7d]);
  7131. var mixCol = new Uint8Array(256);
  7132. for (var i = 0; i < 256; i++) {
  7133. if (i < 128) {
  7134. mixCol[i] = i << 1;
  7135. } else {
  7136. mixCol[i] = (i << 1) ^ 0x1b;
  7137. }
  7138. }
  7139. var mix = new Uint32Array([
  7140. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7141. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7142. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7143. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7144. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7145. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7146. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7147. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7148. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7149. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7150. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7151. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7152. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7153. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7154. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7155. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7156. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7157. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7158. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7159. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7160. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7161. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7162. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7163. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7164. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7165. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7166. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7167. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7168. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7169. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7170. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7171. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7172. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7173. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7174. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7175. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7176. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7177. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7178. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7179. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7180. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7181. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7182. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7183. function expandKey128(cipherKey) {
  7184. var b = 176, result = new Uint8Array(b);
  7185. result.set(cipherKey);
  7186. for (var j = 16, i = 1; j < b; ++i) {
  7187. // RotWord
  7188. var t1 = result[j - 3], t2 = result[j - 2],
  7189. t3 = result[j - 1], t4 = result[j - 4];
  7190. // SubWord
  7191. t1 = s[t1];
  7192. t2 = s[t2];
  7193. t3 = s[t3];
  7194. t4 = s[t4];
  7195. // Rcon
  7196. t1 = t1 ^ rcon[i];
  7197. for (var n = 0; n < 4; ++n) {
  7198. result[j] = (t1 ^= result[j - 16]);
  7199. j++;
  7200. result[j] = (t2 ^= result[j - 16]);
  7201. j++;
  7202. result[j] = (t3 ^= result[j - 16]);
  7203. j++;
  7204. result[j] = (t4 ^= result[j - 16]);
  7205. j++;
  7206. }
  7207. }
  7208. return result;
  7209. }
  7210. function decrypt128(input, key) {
  7211. var state = new Uint8Array(16);
  7212. state.set(input);
  7213. var i, j, k;
  7214. var t, u, v;
  7215. // AddRoundKey
  7216. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7217. state[j] ^= key[k];
  7218. }
  7219. for (i = 9; i >= 1; --i) {
  7220. // InvShiftRows
  7221. t = state[13];
  7222. state[13] = state[9];
  7223. state[9] = state[5];
  7224. state[5] = state[1];
  7225. state[1] = t;
  7226. t = state[14];
  7227. u = state[10];
  7228. state[14] = state[6];
  7229. state[10] = state[2];
  7230. state[6] = t;
  7231. state[2] = u;
  7232. t = state[15];
  7233. u = state[11];
  7234. v = state[7];
  7235. state[15] = state[3];
  7236. state[11] = t;
  7237. state[7] = u;
  7238. state[3] = v;
  7239. // InvSubBytes
  7240. for (j = 0; j < 16; ++j) {
  7241. state[j] = inv_s[state[j]];
  7242. }
  7243. // AddRoundKey
  7244. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7245. state[j] ^= key[k];
  7246. }
  7247. // InvMixColumns
  7248. for (j = 0; j < 16; j += 4) {
  7249. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7250. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7251. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7252. (s3 >>> 24) ^ (s3 << 8));
  7253. state[j] = (t >>> 24) & 0xFF;
  7254. state[j + 1] = (t >> 16) & 0xFF;
  7255. state[j + 2] = (t >> 8) & 0xFF;
  7256. state[j + 3] = t & 0xFF;
  7257. }
  7258. }
  7259. // InvShiftRows
  7260. t = state[13];
  7261. state[13] = state[9];
  7262. state[9] = state[5];
  7263. state[5] = state[1];
  7264. state[1] = t;
  7265. t = state[14];
  7266. u = state[10];
  7267. state[14] = state[6];
  7268. state[10] = state[2];
  7269. state[6] = t;
  7270. state[2] = u;
  7271. t = state[15];
  7272. u = state[11];
  7273. v = state[7];
  7274. state[15] = state[3];
  7275. state[11] = t;
  7276. state[7] = u;
  7277. state[3] = v;
  7278. for (j = 0; j < 16; ++j) {
  7279. // InvSubBytes
  7280. state[j] = inv_s[state[j]];
  7281. // AddRoundKey
  7282. state[j] ^= key[j];
  7283. }
  7284. return state;
  7285. }
  7286. function encrypt128(input, key) {
  7287. var t, u, v, k;
  7288. var state = new Uint8Array(16);
  7289. state.set(input);
  7290. for (j = 0; j < 16; ++j) {
  7291. // AddRoundKey
  7292. state[j] ^= key[j];
  7293. }
  7294. for (i = 1; i < 10; i++) {
  7295. //SubBytes
  7296. for (j = 0; j < 16; ++j) {
  7297. state[j] = s[state[j]];
  7298. }
  7299. //ShiftRows
  7300. v = state[1];
  7301. state[1] = state[5];
  7302. state[5] = state[9];
  7303. state[9] = state[13];
  7304. state[13] = v;
  7305. v = state[2];
  7306. u = state[6];
  7307. state[2] = state[10];
  7308. state[6] = state[14];
  7309. state[10] = v;
  7310. state[14] = u;
  7311. v = state[3];
  7312. u = state[7];
  7313. t = state[11];
  7314. state[3] = state[15];
  7315. state[7] = v;
  7316. state[11] = u;
  7317. state[15] = t;
  7318. //MixColumns
  7319. for (var j = 0; j < 16; j += 4) {
  7320. var s0 = state[j + 0], s1 = state[j + 1];
  7321. var s2 = state[j + 2], s3 = state[j + 3];
  7322. t = s0 ^ s1 ^ s2 ^ s3;
  7323. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7324. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7325. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7326. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7327. }
  7328. //AddRoundKey
  7329. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7330. state[j] ^= key[k];
  7331. }
  7332. }
  7333. //SubBytes
  7334. for (j = 0; j < 16; ++j) {
  7335. state[j] = s[state[j]];
  7336. }
  7337. //ShiftRows
  7338. v = state[1];
  7339. state[1] = state[5];
  7340. state[5] = state[9];
  7341. state[9] = state[13];
  7342. state[13] = v;
  7343. v = state[2];
  7344. u = state[6];
  7345. state[2] = state[10];
  7346. state[6] = state[14];
  7347. state[10] = v;
  7348. state[14] = u;
  7349. v = state[3];
  7350. u = state[7];
  7351. t = state[11];
  7352. state[3] = state[15];
  7353. state[7] = v;
  7354. state[11] = u;
  7355. state[15] = t;
  7356. //AddRoundKey
  7357. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7358. state[j] ^= key[k];
  7359. }
  7360. return state;
  7361. }
  7362. function AES128Cipher(key) {
  7363. this.key = expandKey128(key);
  7364. this.buffer = new Uint8Array(16);
  7365. this.bufferPosition = 0;
  7366. }
  7367. function decryptBlock2(data, finalize) {
  7368. var i, j, ii, sourceLength = data.length,
  7369. buffer = this.buffer, bufferLength = this.bufferPosition,
  7370. result = [], iv = this.iv;
  7371. for (i = 0; i < sourceLength; ++i) {
  7372. buffer[bufferLength] = data[i];
  7373. ++bufferLength;
  7374. if (bufferLength < 16) {
  7375. continue;
  7376. }
  7377. // buffer is full, decrypting
  7378. var plain = decrypt128(buffer, this.key);
  7379. // xor-ing the IV vector to get plain text
  7380. for (j = 0; j < 16; ++j) {
  7381. plain[j] ^= iv[j];
  7382. }
  7383. iv = buffer;
  7384. result.push(plain);
  7385. buffer = new Uint8Array(16);
  7386. bufferLength = 0;
  7387. }
  7388. // saving incomplete buffer
  7389. this.buffer = buffer;
  7390. this.bufferLength = bufferLength;
  7391. this.iv = iv;
  7392. if (result.length === 0) {
  7393. return new Uint8Array([]);
  7394. }
  7395. // combining plain text blocks into one
  7396. var outputLength = 16 * result.length;
  7397. if (finalize) {
  7398. // undo a padding that is described in RFC 2898
  7399. var lastBlock = result[result.length - 1];
  7400. var psLen = lastBlock[15];
  7401. if (psLen <= 16) {
  7402. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7403. if (lastBlock[i] !== psLen) {
  7404. // Invalid padding, assume that the block has no padding.
  7405. psLen = 0;
  7406. break;
  7407. }
  7408. }
  7409. outputLength -= psLen;
  7410. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7411. }
  7412. }
  7413. var output = new Uint8Array(outputLength);
  7414. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7415. output.set(result[i], j);
  7416. }
  7417. return output;
  7418. }
  7419. AES128Cipher.prototype = {
  7420. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7421. var i, sourceLength = data.length;
  7422. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7423. // waiting for IV values -- they are at the start of the stream
  7424. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7425. buffer[bufferLength] = data[i];
  7426. }
  7427. if (bufferLength < 16) {
  7428. // need more data
  7429. this.bufferLength = bufferLength;
  7430. return new Uint8Array([]);
  7431. }
  7432. this.iv = buffer;
  7433. this.buffer = new Uint8Array(16);
  7434. this.bufferLength = 0;
  7435. // starting decryption
  7436. this.decryptBlock = decryptBlock2;
  7437. return this.decryptBlock(data.subarray(16), finalize);
  7438. },
  7439. encrypt: function AES128Cipher_encrypt(data, iv) {
  7440. var i, j, ii, sourceLength = data.length,
  7441. buffer = this.buffer, bufferLength = this.bufferPosition,
  7442. result = [];
  7443. if (!iv) {
  7444. iv = new Uint8Array(16);
  7445. }
  7446. for (i = 0; i < sourceLength; ++i) {
  7447. buffer[bufferLength] = data[i];
  7448. ++bufferLength;
  7449. if (bufferLength < 16) {
  7450. continue;
  7451. }
  7452. for (j = 0; j < 16; ++j) {
  7453. buffer[j] ^= iv[j];
  7454. }
  7455. // buffer is full, encrypting
  7456. var cipher = encrypt128(buffer, this.key);
  7457. iv = cipher;
  7458. result.push(cipher);
  7459. buffer = new Uint8Array(16);
  7460. bufferLength = 0;
  7461. }
  7462. // saving incomplete buffer
  7463. this.buffer = buffer;
  7464. this.bufferLength = bufferLength;
  7465. this.iv = iv;
  7466. if (result.length === 0) {
  7467. return new Uint8Array([]);
  7468. }
  7469. // combining plain text blocks into one
  7470. var outputLength = 16 * result.length;
  7471. var output = new Uint8Array(outputLength);
  7472. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7473. output.set(result[i], j);
  7474. }
  7475. return output;
  7476. }
  7477. };
  7478. return AES128Cipher;
  7479. })();
  7480. var AES256Cipher = (function AES256CipherClosure() {
  7481. var rcon = new Uint8Array([
  7482. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7483. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7484. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7485. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7486. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7487. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7488. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7489. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7490. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7491. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7492. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7493. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7494. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7495. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7496. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7497. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7498. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7499. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7500. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7501. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7502. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7503. 0x74, 0xe8, 0xcb, 0x8d]);
  7504. var s = new Uint8Array([
  7505. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7506. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7507. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7508. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7509. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7510. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7511. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7512. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7513. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7514. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7515. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7516. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7517. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7518. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7519. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7520. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7521. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7522. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7523. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7524. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7525. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7526. 0xb0, 0x54, 0xbb, 0x16]);
  7527. var inv_s = new Uint8Array([
  7528. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7529. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7530. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7531. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7532. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7533. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7534. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7535. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7536. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7537. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7538. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7539. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7540. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7541. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7542. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7543. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7544. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7545. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7546. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7547. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7548. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7549. 0x55, 0x21, 0x0c, 0x7d]);
  7550. var mixCol = new Uint8Array(256);
  7551. for (var i = 0; i < 256; i++) {
  7552. if (i < 128) {
  7553. mixCol[i] = i << 1;
  7554. } else {
  7555. mixCol[i] = (i << 1) ^ 0x1b;
  7556. }
  7557. }
  7558. var mix = new Uint32Array([
  7559. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7560. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7561. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7562. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7563. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7564. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7565. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7566. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7567. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7568. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7569. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7570. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7571. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7572. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7573. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7574. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7575. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7576. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7577. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7578. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7579. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7580. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7581. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7582. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7583. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7584. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7585. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7586. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7587. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7588. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7589. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7590. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7591. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7592. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7593. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7594. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7595. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7596. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7597. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7598. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7599. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7600. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7601. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7602. function expandKey256(cipherKey) {
  7603. var b = 240, result = new Uint8Array(b);
  7604. var r = 1;
  7605. result.set(cipherKey);
  7606. for (var j = 32, i = 1; j < b; ++i) {
  7607. if (j % 32 === 16) {
  7608. t1 = s[t1];
  7609. t2 = s[t2];
  7610. t3 = s[t3];
  7611. t4 = s[t4];
  7612. } else if (j % 32 === 0) {
  7613. // RotWord
  7614. var t1 = result[j - 3], t2 = result[j - 2],
  7615. t3 = result[j - 1], t4 = result[j - 4];
  7616. // SubWord
  7617. t1 = s[t1];
  7618. t2 = s[t2];
  7619. t3 = s[t3];
  7620. t4 = s[t4];
  7621. // Rcon
  7622. t1 = t1 ^ r;
  7623. if ((r <<= 1) >= 256) {
  7624. r = (r ^ 0x1b) & 0xFF;
  7625. }
  7626. }
  7627. for (var n = 0; n < 4; ++n) {
  7628. result[j] = (t1 ^= result[j - 32]);
  7629. j++;
  7630. result[j] = (t2 ^= result[j - 32]);
  7631. j++;
  7632. result[j] = (t3 ^= result[j - 32]);
  7633. j++;
  7634. result[j] = (t4 ^= result[j - 32]);
  7635. j++;
  7636. }
  7637. }
  7638. return result;
  7639. }
  7640. function decrypt256(input, key) {
  7641. var state = new Uint8Array(16);
  7642. state.set(input);
  7643. var i, j, k;
  7644. var t, u, v;
  7645. // AddRoundKey
  7646. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7647. state[j] ^= key[k];
  7648. }
  7649. for (i = 13; i >= 1; --i) {
  7650. // InvShiftRows
  7651. t = state[13];
  7652. state[13] = state[9];
  7653. state[9] = state[5];
  7654. state[5] = state[1];
  7655. state[1] = t;
  7656. t = state[14];
  7657. u = state[10];
  7658. state[14] = state[6];
  7659. state[10] = state[2];
  7660. state[6] = t;
  7661. state[2] = u;
  7662. t = state[15];
  7663. u = state[11];
  7664. v = state[7];
  7665. state[15] = state[3];
  7666. state[11] = t;
  7667. state[7] = u;
  7668. state[3] = v;
  7669. // InvSubBytes
  7670. for (j = 0; j < 16; ++j) {
  7671. state[j] = inv_s[state[j]];
  7672. }
  7673. // AddRoundKey
  7674. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7675. state[j] ^= key[k];
  7676. }
  7677. // InvMixColumns
  7678. for (j = 0; j < 16; j += 4) {
  7679. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7680. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7681. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7682. (s3 >>> 24) ^ (s3 << 8));
  7683. state[j] = (t >>> 24) & 0xFF;
  7684. state[j + 1] = (t >> 16) & 0xFF;
  7685. state[j + 2] = (t >> 8) & 0xFF;
  7686. state[j + 3] = t & 0xFF;
  7687. }
  7688. }
  7689. // InvShiftRows
  7690. t = state[13];
  7691. state[13] = state[9];
  7692. state[9] = state[5];
  7693. state[5] = state[1];
  7694. state[1] = t;
  7695. t = state[14];
  7696. u = state[10];
  7697. state[14] = state[6];
  7698. state[10] = state[2];
  7699. state[6] = t;
  7700. state[2] = u;
  7701. t = state[15];
  7702. u = state[11];
  7703. v = state[7];
  7704. state[15] = state[3];
  7705. state[11] = t;
  7706. state[7] = u;
  7707. state[3] = v;
  7708. for (j = 0; j < 16; ++j) {
  7709. // InvSubBytes
  7710. state[j] = inv_s[state[j]];
  7711. // AddRoundKey
  7712. state[j] ^= key[j];
  7713. }
  7714. return state;
  7715. }
  7716. function encrypt256(input, key) {
  7717. var t, u, v, k;
  7718. var state = new Uint8Array(16);
  7719. state.set(input);
  7720. for (j = 0; j < 16; ++j) {
  7721. // AddRoundKey
  7722. state[j] ^= key[j];
  7723. }
  7724. for (i = 1; i < 14; i++) {
  7725. //SubBytes
  7726. for (j = 0; j < 16; ++j) {
  7727. state[j] = s[state[j]];
  7728. }
  7729. //ShiftRows
  7730. v = state[1];
  7731. state[1] = state[5];
  7732. state[5] = state[9];
  7733. state[9] = state[13];
  7734. state[13] = v;
  7735. v = state[2];
  7736. u = state[6];
  7737. state[2] = state[10];
  7738. state[6] = state[14];
  7739. state[10] = v;
  7740. state[14] = u;
  7741. v = state[3];
  7742. u = state[7];
  7743. t = state[11];
  7744. state[3] = state[15];
  7745. state[7] = v;
  7746. state[11] = u;
  7747. state[15] = t;
  7748. //MixColumns
  7749. for (var j = 0; j < 16; j += 4) {
  7750. var s0 = state[j + 0], s1 = state[j + 1];
  7751. var s2 = state[j + 2], s3 = state[j + 3];
  7752. t = s0 ^ s1 ^ s2 ^ s3;
  7753. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7754. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7755. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7756. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7757. }
  7758. //AddRoundKey
  7759. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7760. state[j] ^= key[k];
  7761. }
  7762. }
  7763. //SubBytes
  7764. for (j = 0; j < 16; ++j) {
  7765. state[j] = s[state[j]];
  7766. }
  7767. //ShiftRows
  7768. v = state[1];
  7769. state[1] = state[5];
  7770. state[5] = state[9];
  7771. state[9] = state[13];
  7772. state[13] = v;
  7773. v = state[2];
  7774. u = state[6];
  7775. state[2] = state[10];
  7776. state[6] = state[14];
  7777. state[10] = v;
  7778. state[14] = u;
  7779. v = state[3];
  7780. u = state[7];
  7781. t = state[11];
  7782. state[3] = state[15];
  7783. state[7] = v;
  7784. state[11] = u;
  7785. state[15] = t;
  7786. //AddRoundKey
  7787. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7788. state[j] ^= key[k];
  7789. }
  7790. return state;
  7791. }
  7792. function AES256Cipher(key) {
  7793. this.key = expandKey256(key);
  7794. this.buffer = new Uint8Array(16);
  7795. this.bufferPosition = 0;
  7796. }
  7797. function decryptBlock2(data, finalize) {
  7798. var i, j, ii, sourceLength = data.length,
  7799. buffer = this.buffer, bufferLength = this.bufferPosition,
  7800. result = [], iv = this.iv;
  7801. for (i = 0; i < sourceLength; ++i) {
  7802. buffer[bufferLength] = data[i];
  7803. ++bufferLength;
  7804. if (bufferLength < 16) {
  7805. continue;
  7806. }
  7807. // buffer is full, decrypting
  7808. var plain = decrypt256(buffer, this.key);
  7809. // xor-ing the IV vector to get plain text
  7810. for (j = 0; j < 16; ++j) {
  7811. plain[j] ^= iv[j];
  7812. }
  7813. iv = buffer;
  7814. result.push(plain);
  7815. buffer = new Uint8Array(16);
  7816. bufferLength = 0;
  7817. }
  7818. // saving incomplete buffer
  7819. this.buffer = buffer;
  7820. this.bufferLength = bufferLength;
  7821. this.iv = iv;
  7822. if (result.length === 0) {
  7823. return new Uint8Array([]);
  7824. }
  7825. // combining plain text blocks into one
  7826. var outputLength = 16 * result.length;
  7827. if (finalize) {
  7828. // undo a padding that is described in RFC 2898
  7829. var lastBlock = result[result.length - 1];
  7830. var psLen = lastBlock[15];
  7831. if (psLen <= 16) {
  7832. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7833. if (lastBlock[i] !== psLen) {
  7834. // Invalid padding, assume that the block has no padding.
  7835. psLen = 0;
  7836. break;
  7837. }
  7838. }
  7839. outputLength -= psLen;
  7840. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7841. }
  7842. }
  7843. var output = new Uint8Array(outputLength);
  7844. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7845. output.set(result[i], j);
  7846. }
  7847. return output;
  7848. }
  7849. AES256Cipher.prototype = {
  7850. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  7851. var i, sourceLength = data.length;
  7852. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7853. // if not supplied an IV wait for IV values
  7854. // they are at the start of the stream
  7855. if (iv) {
  7856. this.iv = iv;
  7857. } else {
  7858. for (i = 0; bufferLength < 16 &&
  7859. i < sourceLength; ++i, ++bufferLength) {
  7860. buffer[bufferLength] = data[i];
  7861. }
  7862. if (bufferLength < 16) {
  7863. //need more data
  7864. this.bufferLength = bufferLength;
  7865. return new Uint8Array([]);
  7866. }
  7867. this.iv = buffer;
  7868. data = data.subarray(16);
  7869. }
  7870. this.buffer = new Uint8Array(16);
  7871. this.bufferLength = 0;
  7872. // starting decryption
  7873. this.decryptBlock = decryptBlock2;
  7874. return this.decryptBlock(data, finalize);
  7875. },
  7876. encrypt: function AES256Cipher_encrypt(data, iv) {
  7877. var i, j, ii, sourceLength = data.length,
  7878. buffer = this.buffer, bufferLength = this.bufferPosition,
  7879. result = [];
  7880. if (!iv) {
  7881. iv = new Uint8Array(16);
  7882. }
  7883. for (i = 0; i < sourceLength; ++i) {
  7884. buffer[bufferLength] = data[i];
  7885. ++bufferLength;
  7886. if (bufferLength < 16) {
  7887. continue;
  7888. }
  7889. for (j = 0; j < 16; ++j) {
  7890. buffer[j] ^= iv[j];
  7891. }
  7892. // buffer is full, encrypting
  7893. var cipher = encrypt256(buffer, this.key);
  7894. this.iv = cipher;
  7895. result.push(cipher);
  7896. buffer = new Uint8Array(16);
  7897. bufferLength = 0;
  7898. }
  7899. // saving incomplete buffer
  7900. this.buffer = buffer;
  7901. this.bufferLength = bufferLength;
  7902. this.iv = iv;
  7903. if (result.length === 0) {
  7904. return new Uint8Array([]);
  7905. }
  7906. // combining plain text blocks into one
  7907. var outputLength = 16 * result.length;
  7908. var output = new Uint8Array(outputLength);
  7909. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7910. output.set(result[i], j);
  7911. }
  7912. return output;
  7913. }
  7914. };
  7915. return AES256Cipher;
  7916. })();
  7917. var PDF17 = (function PDF17Closure() {
  7918. function compareByteArrays(array1, array2) {
  7919. if (array1.length !== array2.length) {
  7920. return false;
  7921. }
  7922. for (var i = 0; i < array1.length; i++) {
  7923. if (array1[i] !== array2[i]) {
  7924. return false;
  7925. }
  7926. }
  7927. return true;
  7928. }
  7929. function PDF17() {
  7930. }
  7931. PDF17.prototype = {
  7932. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  7933. ownerValidationSalt,
  7934. userBytes,
  7935. ownerPassword) {
  7936. var hashData = new Uint8Array(password.length + 56);
  7937. hashData.set(password, 0);
  7938. hashData.set(ownerValidationSalt, password.length);
  7939. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  7940. var result = calculateSHA256(hashData, 0, hashData.length);
  7941. return compareByteArrays(result, ownerPassword);
  7942. },
  7943. checkUserPassword: function PDF17_checkUserPassword(password,
  7944. userValidationSalt,
  7945. userPassword) {
  7946. var hashData = new Uint8Array(password.length + 8);
  7947. hashData.set(password, 0);
  7948. hashData.set(userValidationSalt, password.length);
  7949. var result = calculateSHA256(hashData, 0, hashData.length);
  7950. return compareByteArrays(result, userPassword);
  7951. },
  7952. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  7953. ownerEncryption) {
  7954. var hashData = new Uint8Array(password.length + 56);
  7955. hashData.set(password, 0);
  7956. hashData.set(ownerKeySalt, password.length);
  7957. hashData.set(userBytes, password.length + ownerKeySalt.length);
  7958. var key = calculateSHA256(hashData, 0, hashData.length);
  7959. var cipher = new AES256Cipher(key);
  7960. return cipher.decryptBlock(ownerEncryption,
  7961. false,
  7962. new Uint8Array(16));
  7963. },
  7964. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  7965. userEncryption) {
  7966. var hashData = new Uint8Array(password.length + 8);
  7967. hashData.set(password, 0);
  7968. hashData.set(userKeySalt, password.length);
  7969. //key is the decryption key for the UE string
  7970. var key = calculateSHA256(hashData, 0, hashData.length);
  7971. var cipher = new AES256Cipher(key);
  7972. return cipher.decryptBlock(userEncryption,
  7973. false,
  7974. new Uint8Array(16));
  7975. }
  7976. };
  7977. return PDF17;
  7978. })();
  7979. var PDF20 = (function PDF20Closure() {
  7980. function concatArrays(array1, array2) {
  7981. var t = new Uint8Array(array1.length + array2.length);
  7982. t.set(array1, 0);
  7983. t.set(array2, array1.length);
  7984. return t;
  7985. }
  7986. function calculatePDF20Hash(password, input, userBytes) {
  7987. //This refers to Algorithm 2.B as defined in ISO 32000-2
  7988. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  7989. var e = [0];
  7990. var i = 0;
  7991. while (i < 64 || e[e.length - 1] > i - 32) {
  7992. var arrayLength = password.length + k.length + userBytes.length;
  7993. var k1 = new Uint8Array(arrayLength * 64);
  7994. var array = concatArrays(password, k);
  7995. array = concatArrays(array, userBytes);
  7996. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  7997. k1.set(array, pos);
  7998. }
  7999. //AES128 CBC NO PADDING with
  8000. //first 16 bytes of k as the key and the second 16 as the iv.
  8001. var cipher = new AES128Cipher(k.subarray(0, 16));
  8002. e = cipher.encrypt(k1, k.subarray(16, 32));
  8003. //Now we have to take the first 16 bytes of an unsigned
  8004. //big endian integer... and compute the remainder
  8005. //modulo 3.... That is a fairly large number and
  8006. //JavaScript isn't going to handle that well...
  8007. //So we're using a trick that allows us to perform
  8008. //modulo math byte by byte
  8009. var remainder = 0;
  8010. for (var z = 0; z < 16; z++) {
  8011. remainder *= (256 % 3);
  8012. remainder %= 3;
  8013. remainder += ((e[z] >>> 0) % 3);
  8014. remainder %= 3;
  8015. }
  8016. if (remainder === 0) {
  8017. k = calculateSHA256(e, 0, e.length);
  8018. }
  8019. else if (remainder === 1) {
  8020. k = calculateSHA384(e, 0, e.length);
  8021. }
  8022. else if (remainder === 2) {
  8023. k = calculateSHA512(e, 0, e.length);
  8024. }
  8025. i++;
  8026. }
  8027. return k.subarray(0, 32);
  8028. }
  8029. function PDF20() {
  8030. }
  8031. function compareByteArrays(array1, array2) {
  8032. if (array1.length !== array2.length) {
  8033. return false;
  8034. }
  8035. for (var i = 0; i < array1.length; i++) {
  8036. if (array1[i] !== array2[i]) {
  8037. return false;
  8038. }
  8039. }
  8040. return true;
  8041. }
  8042. PDF20.prototype = {
  8043. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8044. return calculatePDF20Hash(password, concatBytes, userBytes);
  8045. },
  8046. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8047. ownerValidationSalt,
  8048. userBytes,
  8049. ownerPassword) {
  8050. var hashData = new Uint8Array(password.length + 56);
  8051. hashData.set(password, 0);
  8052. hashData.set(ownerValidationSalt, password.length);
  8053. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8054. var result = calculatePDF20Hash(password, hashData, userBytes);
  8055. return compareByteArrays(result, ownerPassword);
  8056. },
  8057. checkUserPassword: function PDF20_checkUserPassword(password,
  8058. userValidationSalt,
  8059. userPassword) {
  8060. var hashData = new Uint8Array(password.length + 8);
  8061. hashData.set(password, 0);
  8062. hashData.set(userValidationSalt, password.length);
  8063. var result = calculatePDF20Hash(password, hashData, []);
  8064. return compareByteArrays(result, userPassword);
  8065. },
  8066. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8067. ownerEncryption) {
  8068. var hashData = new Uint8Array(password.length + 56);
  8069. hashData.set(password, 0);
  8070. hashData.set(ownerKeySalt, password.length);
  8071. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8072. var key = calculatePDF20Hash(password, hashData, userBytes);
  8073. var cipher = new AES256Cipher(key);
  8074. return cipher.decryptBlock(ownerEncryption,
  8075. false,
  8076. new Uint8Array(16));
  8077. },
  8078. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8079. userEncryption) {
  8080. var hashData = new Uint8Array(password.length + 8);
  8081. hashData.set(password, 0);
  8082. hashData.set(userKeySalt, password.length);
  8083. //key is the decryption key for the UE string
  8084. var key = calculatePDF20Hash(password, hashData, []);
  8085. var cipher = new AES256Cipher(key);
  8086. return cipher.decryptBlock(userEncryption,
  8087. false,
  8088. new Uint8Array(16));
  8089. }
  8090. };
  8091. return PDF20;
  8092. })();
  8093. var CipherTransform = (function CipherTransformClosure() {
  8094. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8095. this.stringCipherConstructor = stringCipherConstructor;
  8096. this.streamCipherConstructor = streamCipherConstructor;
  8097. }
  8098. CipherTransform.prototype = {
  8099. createStream: function CipherTransform_createStream(stream, length) {
  8100. var cipher = new this.streamCipherConstructor();
  8101. return new DecryptStream(stream, length,
  8102. function cipherTransformDecryptStream(data, finalize) {
  8103. return cipher.decryptBlock(data, finalize);
  8104. }
  8105. );
  8106. },
  8107. decryptString: function CipherTransform_decryptString(s) {
  8108. var cipher = new this.stringCipherConstructor();
  8109. var data = stringToBytes(s);
  8110. data = cipher.decryptBlock(data, true);
  8111. return bytesToString(data);
  8112. }
  8113. };
  8114. return CipherTransform;
  8115. })();
  8116. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8117. var defaultPasswordBytes = new Uint8Array([
  8118. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8119. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8120. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8121. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8122. function createEncryptionKey20(revision, password, ownerPassword,
  8123. ownerValidationSalt, ownerKeySalt, uBytes,
  8124. userPassword, userValidationSalt, userKeySalt,
  8125. ownerEncryption, userEncryption, perms) {
  8126. if (password) {
  8127. var passwordLength = Math.min(127, password.length);
  8128. password = password.subarray(0, passwordLength);
  8129. } else {
  8130. password = [];
  8131. }
  8132. var pdfAlgorithm;
  8133. if (revision === 6) {
  8134. pdfAlgorithm = new PDF20();
  8135. } else {
  8136. pdfAlgorithm = new PDF17();
  8137. }
  8138. if (pdfAlgorithm) {
  8139. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8140. userPassword)) {
  8141. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8142. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8143. uBytes,
  8144. ownerPassword)) {
  8145. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8146. ownerEncryption);
  8147. }
  8148. }
  8149. return null;
  8150. }
  8151. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8152. flags, revision, keyLength, encryptMetadata) {
  8153. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8154. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8155. if (password) {
  8156. n = Math.min(32, password.length);
  8157. for (; i < n; ++i) {
  8158. hashData[i] = password[i];
  8159. }
  8160. }
  8161. j = 0;
  8162. while (i < 32) {
  8163. hashData[i++] = defaultPasswordBytes[j++];
  8164. }
  8165. // as now the padded password in the hashData[0..i]
  8166. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8167. hashData[i++] = ownerPassword[j];
  8168. }
  8169. hashData[i++] = flags & 0xFF;
  8170. hashData[i++] = (flags >> 8) & 0xFF;
  8171. hashData[i++] = (flags >> 16) & 0xFF;
  8172. hashData[i++] = (flags >>> 24) & 0xFF;
  8173. for (j = 0, n = fileId.length; j < n; ++j) {
  8174. hashData[i++] = fileId[j];
  8175. }
  8176. if (revision >= 4 && !encryptMetadata) {
  8177. hashData[i++] = 0xFF;
  8178. hashData[i++] = 0xFF;
  8179. hashData[i++] = 0xFF;
  8180. hashData[i++] = 0xFF;
  8181. }
  8182. var hash = calculateMD5(hashData, 0, i);
  8183. var keyLengthInBytes = keyLength >> 3;
  8184. if (revision >= 3) {
  8185. for (j = 0; j < 50; ++j) {
  8186. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8187. }
  8188. }
  8189. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8190. var cipher, checkData;
  8191. if (revision >= 3) {
  8192. for (i = 0; i < 32; ++i) {
  8193. hashData[i] = defaultPasswordBytes[i];
  8194. }
  8195. for (j = 0, n = fileId.length; j < n; ++j) {
  8196. hashData[i++] = fileId[j];
  8197. }
  8198. cipher = new ARCFourCipher(encryptionKey);
  8199. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8200. n = encryptionKey.length;
  8201. var derivedKey = new Uint8Array(n), k;
  8202. for (j = 1; j <= 19; ++j) {
  8203. for (k = 0; k < n; ++k) {
  8204. derivedKey[k] = encryptionKey[k] ^ j;
  8205. }
  8206. cipher = new ARCFourCipher(derivedKey);
  8207. checkData = cipher.encryptBlock(checkData);
  8208. }
  8209. for (j = 0, n = checkData.length; j < n; ++j) {
  8210. if (userPassword[j] !== checkData[j]) {
  8211. return null;
  8212. }
  8213. }
  8214. } else {
  8215. cipher = new ARCFourCipher(encryptionKey);
  8216. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8217. for (j = 0, n = checkData.length; j < n; ++j) {
  8218. if (userPassword[j] !== checkData[j]) {
  8219. return null;
  8220. }
  8221. }
  8222. }
  8223. return encryptionKey;
  8224. }
  8225. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8226. var hashData = new Uint8Array(32), i = 0, j, n;
  8227. n = Math.min(32, password.length);
  8228. for (; i < n; ++i) {
  8229. hashData[i] = password[i];
  8230. }
  8231. j = 0;
  8232. while (i < 32) {
  8233. hashData[i++] = defaultPasswordBytes[j++];
  8234. }
  8235. var hash = calculateMD5(hashData, 0, i);
  8236. var keyLengthInBytes = keyLength >> 3;
  8237. if (revision >= 3) {
  8238. for (j = 0; j < 50; ++j) {
  8239. hash = calculateMD5(hash, 0, hash.length);
  8240. }
  8241. }
  8242. var cipher, userPassword;
  8243. if (revision >= 3) {
  8244. userPassword = ownerPassword;
  8245. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8246. for (j = 19; j >= 0; j--) {
  8247. for (k = 0; k < keyLengthInBytes; ++k) {
  8248. derivedKey[k] = hash[k] ^ j;
  8249. }
  8250. cipher = new ARCFourCipher(derivedKey);
  8251. userPassword = cipher.encryptBlock(userPassword);
  8252. }
  8253. } else {
  8254. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8255. userPassword = cipher.encryptBlock(ownerPassword);
  8256. }
  8257. return userPassword;
  8258. }
  8259. var identityName = Name.get('Identity');
  8260. function CipherTransformFactory(dict, fileId, password) {
  8261. var filter = dict.get('Filter');
  8262. if (!isName(filter) || filter.name !== 'Standard') {
  8263. error('unknown encryption method');
  8264. }
  8265. this.dict = dict;
  8266. var algorithm = dict.get('V');
  8267. if (!isInt(algorithm) ||
  8268. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8269. algorithm !== 5)) {
  8270. error('unsupported encryption algorithm');
  8271. }
  8272. this.algorithm = algorithm;
  8273. var keyLength = dict.get('Length') || 40;
  8274. if (!isInt(keyLength) ||
  8275. keyLength < 40 || (keyLength % 8) !== 0) {
  8276. error('invalid key length');
  8277. }
  8278. // prepare keys
  8279. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8280. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8281. var flags = dict.get('P');
  8282. var revision = dict.get('R');
  8283. // meaningful when V is 4 or 5
  8284. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8285. dict.get('EncryptMetadata') !== false);
  8286. this.encryptMetadata = encryptMetadata;
  8287. var fileIdBytes = stringToBytes(fileId);
  8288. var passwordBytes;
  8289. if (password) {
  8290. passwordBytes = stringToBytes(password);
  8291. }
  8292. var encryptionKey;
  8293. if (algorithm !== 5) {
  8294. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8295. ownerPassword, userPassword, flags,
  8296. revision, keyLength, encryptMetadata);
  8297. }
  8298. else {
  8299. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8300. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8301. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8302. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8303. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8304. var ownerEncryption = stringToBytes(dict.get('OE'));
  8305. var userEncryption = stringToBytes(dict.get('UE'));
  8306. var perms = stringToBytes(dict.get('Perms'));
  8307. encryptionKey =
  8308. createEncryptionKey20(revision, passwordBytes,
  8309. ownerPassword, ownerValidationSalt,
  8310. ownerKeySalt, uBytes,
  8311. userPassword, userValidationSalt,
  8312. userKeySalt, ownerEncryption,
  8313. userEncryption, perms);
  8314. }
  8315. if (!encryptionKey && !password) {
  8316. throw new PasswordException('No password given',
  8317. PasswordResponses.NEED_PASSWORD);
  8318. } else if (!encryptionKey && password) {
  8319. // Attempting use the password as an owner password
  8320. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8321. revision, keyLength);
  8322. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8323. ownerPassword, userPassword, flags,
  8324. revision, keyLength, encryptMetadata);
  8325. }
  8326. if (!encryptionKey) {
  8327. throw new PasswordException('Incorrect Password',
  8328. PasswordResponses.INCORRECT_PASSWORD);
  8329. }
  8330. this.encryptionKey = encryptionKey;
  8331. if (algorithm >= 4) {
  8332. this.cf = dict.get('CF');
  8333. this.stmf = dict.get('StmF') || identityName;
  8334. this.strf = dict.get('StrF') || identityName;
  8335. this.eff = dict.get('EFF') || this.strf;
  8336. }
  8337. }
  8338. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8339. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8340. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8341. key[i] = encryptionKey[i];
  8342. }
  8343. key[i++] = num & 0xFF;
  8344. key[i++] = (num >> 8) & 0xFF;
  8345. key[i++] = (num >> 16) & 0xFF;
  8346. key[i++] = gen & 0xFF;
  8347. key[i++] = (gen >> 8) & 0xFF;
  8348. if (isAes) {
  8349. key[i++] = 0x73;
  8350. key[i++] = 0x41;
  8351. key[i++] = 0x6C;
  8352. key[i++] = 0x54;
  8353. }
  8354. var hash = calculateMD5(key, 0, i);
  8355. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8356. }
  8357. function buildCipherConstructor(cf, name, num, gen, key) {
  8358. var cryptFilter = cf.get(name.name);
  8359. var cfm;
  8360. if (cryptFilter !== null && cryptFilter !== undefined) {
  8361. cfm = cryptFilter.get('CFM');
  8362. }
  8363. if (!cfm || cfm.name === 'None') {
  8364. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8365. return new NullCipher();
  8366. };
  8367. }
  8368. if ('V2' === cfm.name) {
  8369. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8370. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8371. };
  8372. }
  8373. if ('AESV2' === cfm.name) {
  8374. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8375. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8376. };
  8377. }
  8378. if ('AESV3' === cfm.name) {
  8379. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8380. return new AES256Cipher(key);
  8381. };
  8382. }
  8383. error('Unknown crypto method');
  8384. }
  8385. CipherTransformFactory.prototype = {
  8386. createCipherTransform:
  8387. function CipherTransformFactory_createCipherTransform(num, gen) {
  8388. if (this.algorithm === 4 || this.algorithm === 5) {
  8389. return new CipherTransform(
  8390. buildCipherConstructor(this.cf, this.stmf,
  8391. num, gen, this.encryptionKey),
  8392. buildCipherConstructor(this.cf, this.strf,
  8393. num, gen, this.encryptionKey));
  8394. }
  8395. // algorithms 1 and 2
  8396. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8397. var cipherConstructor = function buildCipherCipherConstructor() {
  8398. return new ARCFourCipher(key);
  8399. };
  8400. return new CipherTransform(cipherConstructor, cipherConstructor);
  8401. }
  8402. };
  8403. return CipherTransformFactory;
  8404. })();
  8405. var PatternType = {
  8406. FUNCTION_BASED: 1,
  8407. AXIAL: 2,
  8408. RADIAL: 3,
  8409. FREE_FORM_MESH: 4,
  8410. LATTICE_FORM_MESH: 5,
  8411. COONS_PATCH_MESH: 6,
  8412. TENSOR_PATCH_MESH: 7
  8413. };
  8414. var Pattern = (function PatternClosure() {
  8415. // Constructor should define this.getPattern
  8416. function Pattern() {
  8417. error('should not call Pattern constructor');
  8418. }
  8419. Pattern.prototype = {
  8420. // Input: current Canvas context
  8421. // Output: the appropriate fillStyle or strokeStyle
  8422. getPattern: function Pattern_getPattern(ctx) {
  8423. error('Should not call Pattern.getStyle: ' + ctx);
  8424. }
  8425. };
  8426. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8427. res) {
  8428. var dict = isStream(shading) ? shading.dict : shading;
  8429. var type = dict.get('ShadingType');
  8430. switch (type) {
  8431. case PatternType.AXIAL:
  8432. case PatternType.RADIAL:
  8433. // Both radial and axial shadings are handled by RadialAxial shading.
  8434. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8435. case PatternType.FREE_FORM_MESH:
  8436. case PatternType.LATTICE_FORM_MESH:
  8437. case PatternType.COONS_PATCH_MESH:
  8438. case PatternType.TENSOR_PATCH_MESH:
  8439. return new Shadings.Mesh(shading, matrix, xref, res);
  8440. default:
  8441. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8442. return new Shadings.Dummy();
  8443. }
  8444. };
  8445. return Pattern;
  8446. })();
  8447. var Shadings = {};
  8448. // A small number to offset the first/last color stops so we can insert ones to
  8449. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8450. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8451. // internally so we have to go bigger.
  8452. Shadings.SMALL_NUMBER = 1e-2;
  8453. // Radial and axial shading have very similar implementations
  8454. // If needed, the implementations can be broken into two classes
  8455. Shadings.RadialAxial = (function RadialAxialClosure() {
  8456. function RadialAxial(dict, matrix, xref, res) {
  8457. this.matrix = matrix;
  8458. this.coordsArr = dict.get('Coords');
  8459. this.shadingType = dict.get('ShadingType');
  8460. this.type = 'Pattern';
  8461. var cs = dict.get('ColorSpace', 'CS');
  8462. cs = ColorSpace.parse(cs, xref, res);
  8463. this.cs = cs;
  8464. var t0 = 0.0, t1 = 1.0;
  8465. if (dict.has('Domain')) {
  8466. var domainArr = dict.get('Domain');
  8467. t0 = domainArr[0];
  8468. t1 = domainArr[1];
  8469. }
  8470. var extendStart = false, extendEnd = false;
  8471. if (dict.has('Extend')) {
  8472. var extendArr = dict.get('Extend');
  8473. extendStart = extendArr[0];
  8474. extendEnd = extendArr[1];
  8475. }
  8476. if (this.shadingType === PatternType.RADIAL &&
  8477. (!extendStart || !extendEnd)) {
  8478. // Radial gradient only currently works if either circle is fully within
  8479. // the other circle.
  8480. var x1 = this.coordsArr[0];
  8481. var y1 = this.coordsArr[1];
  8482. var r1 = this.coordsArr[2];
  8483. var x2 = this.coordsArr[3];
  8484. var y2 = this.coordsArr[4];
  8485. var r2 = this.coordsArr[5];
  8486. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8487. if (r1 <= r2 + distance &&
  8488. r2 <= r1 + distance) {
  8489. warn('Unsupported radial gradient.');
  8490. }
  8491. }
  8492. this.extendStart = extendStart;
  8493. this.extendEnd = extendEnd;
  8494. var fnObj = dict.get('Function');
  8495. var fn = PDFFunction.parseArray(xref, fnObj);
  8496. // 10 samples seems good enough for now, but probably won't work
  8497. // if there are sharp color changes. Ideally, we would implement
  8498. // the spec faithfully and add lossless optimizations.
  8499. var diff = t1 - t0;
  8500. var step = diff / 10;
  8501. var colorStops = this.colorStops = [];
  8502. // Protect against bad domains so we don't end up in an infinte loop below.
  8503. if (t0 >= t1 || step <= 0) {
  8504. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8505. // now.
  8506. info('Bad shading domain.');
  8507. return;
  8508. }
  8509. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8510. var rgbColor;
  8511. for (var i = t0; i <= t1; i += step) {
  8512. ratio[0] = i;
  8513. fn(ratio, 0, color, 0);
  8514. rgbColor = cs.getRgb(color, 0);
  8515. var cssColor = Util.makeCssRgb(rgbColor);
  8516. colorStops.push([(i - t0) / diff, cssColor]);
  8517. }
  8518. var background = 'transparent';
  8519. if (dict.has('Background')) {
  8520. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8521. background = Util.makeCssRgb(rgbColor);
  8522. }
  8523. if (!extendStart) {
  8524. // Insert a color stop at the front and offset the first real color stop
  8525. // so it doesn't conflict with the one we insert.
  8526. colorStops.unshift([0, background]);
  8527. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8528. }
  8529. if (!extendEnd) {
  8530. // Same idea as above in extendStart but for the end.
  8531. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8532. colorStops.push([1, background]);
  8533. }
  8534. this.colorStops = colorStops;
  8535. }
  8536. RadialAxial.prototype = {
  8537. getIR: function RadialAxial_getIR() {
  8538. var coordsArr = this.coordsArr;
  8539. var shadingType = this.shadingType;
  8540. var type, p0, p1, r0, r1;
  8541. if (shadingType === PatternType.AXIAL) {
  8542. p0 = [coordsArr[0], coordsArr[1]];
  8543. p1 = [coordsArr[2], coordsArr[3]];
  8544. r0 = null;
  8545. r1 = null;
  8546. type = 'axial';
  8547. } else if (shadingType === PatternType.RADIAL) {
  8548. p0 = [coordsArr[0], coordsArr[1]];
  8549. p1 = [coordsArr[3], coordsArr[4]];
  8550. r0 = coordsArr[2];
  8551. r1 = coordsArr[5];
  8552. type = 'radial';
  8553. } else {
  8554. error('getPattern type unknown: ' + shadingType);
  8555. }
  8556. var matrix = this.matrix;
  8557. if (matrix) {
  8558. p0 = Util.applyTransform(p0, matrix);
  8559. p1 = Util.applyTransform(p1, matrix);
  8560. }
  8561. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  8562. }
  8563. };
  8564. return RadialAxial;
  8565. })();
  8566. // All mesh shading. For now, they will be presented as set of the triangles
  8567. // to be drawn on the canvas and rgb color for each vertex.
  8568. Shadings.Mesh = (function MeshClosure() {
  8569. function MeshStreamReader(stream, context) {
  8570. this.stream = stream;
  8571. this.context = context;
  8572. this.buffer = 0;
  8573. this.bufferLength = 0;
  8574. var numComps = context.numComps;
  8575. this.tmpCompsBuf = new Float32Array(numComps);
  8576. var csNumComps = context.colorSpace;
  8577. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  8578. this.tmpCompsBuf;
  8579. }
  8580. MeshStreamReader.prototype = {
  8581. get hasData() {
  8582. if (this.stream.end) {
  8583. return this.stream.pos < this.stream.end;
  8584. }
  8585. if (this.bufferLength > 0) {
  8586. return true;
  8587. }
  8588. var nextByte = this.stream.getByte();
  8589. if (nextByte < 0) {
  8590. return false;
  8591. }
  8592. this.buffer = nextByte;
  8593. this.bufferLength = 8;
  8594. return true;
  8595. },
  8596. readBits: function MeshStreamReader_readBits(n) {
  8597. var buffer = this.buffer;
  8598. var bufferLength = this.bufferLength;
  8599. if (n === 32) {
  8600. if (bufferLength === 0) {
  8601. return ((this.stream.getByte() << 24) |
  8602. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  8603. this.stream.getByte()) >>> 0;
  8604. }
  8605. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  8606. (this.stream.getByte() << 8) | this.stream.getByte();
  8607. var nextByte = this.stream.getByte();
  8608. this.buffer = nextByte & ((1 << bufferLength) - 1);
  8609. return ((buffer << (8 - bufferLength)) |
  8610. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  8611. }
  8612. if (n === 8 && bufferLength === 0) {
  8613. return this.stream.getByte();
  8614. }
  8615. while (bufferLength < n) {
  8616. buffer = (buffer << 8) | this.stream.getByte();
  8617. bufferLength += 8;
  8618. }
  8619. bufferLength -= n;
  8620. this.bufferLength = bufferLength;
  8621. this.buffer = buffer & ((1 << bufferLength) - 1);
  8622. return buffer >> bufferLength;
  8623. },
  8624. align: function MeshStreamReader_align() {
  8625. this.buffer = 0;
  8626. this.bufferLength = 0;
  8627. },
  8628. readFlag: function MeshStreamReader_readFlag() {
  8629. return this.readBits(this.context.bitsPerFlag);
  8630. },
  8631. readCoordinate: function MeshStreamReader_readCoordinate() {
  8632. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  8633. var xi = this.readBits(bitsPerCoordinate);
  8634. var yi = this.readBits(bitsPerCoordinate);
  8635. var decode = this.context.decode;
  8636. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  8637. 2.3283064365386963e-10; // 2 ^ -32
  8638. return [
  8639. xi * scale * (decode[1] - decode[0]) + decode[0],
  8640. yi * scale * (decode[3] - decode[2]) + decode[2]
  8641. ];
  8642. },
  8643. readComponents: function MeshStreamReader_readComponents() {
  8644. var numComps = this.context.numComps;
  8645. var bitsPerComponent = this.context.bitsPerComponent;
  8646. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  8647. 2.3283064365386963e-10; // 2 ^ -32
  8648. var decode = this.context.decode;
  8649. var components = this.tmpCompsBuf;
  8650. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  8651. var ci = this.readBits(bitsPerComponent);
  8652. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  8653. }
  8654. var color = this.tmpCsCompsBuf;
  8655. if (this.context.colorFn) {
  8656. this.context.colorFn(components, 0, color, 0);
  8657. }
  8658. return this.context.colorSpace.getRgb(color, 0);
  8659. }
  8660. };
  8661. function decodeType4Shading(mesh, reader) {
  8662. var coords = mesh.coords;
  8663. var colors = mesh.colors;
  8664. var operators = [];
  8665. var ps = []; // not maintaining cs since that will match ps
  8666. var verticesLeft = 0; // assuming we have all data to start a new triangle
  8667. while (reader.hasData) {
  8668. var f = reader.readFlag();
  8669. var coord = reader.readCoordinate();
  8670. var color = reader.readComponents();
  8671. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  8672. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  8673. switch (f) {
  8674. case 0:
  8675. verticesLeft = 3;
  8676. break;
  8677. case 1:
  8678. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  8679. verticesLeft = 1;
  8680. break;
  8681. case 2:
  8682. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  8683. verticesLeft = 1;
  8684. break;
  8685. }
  8686. operators.push(f);
  8687. }
  8688. ps.push(coords.length);
  8689. coords.push(coord);
  8690. colors.push(color);
  8691. verticesLeft--;
  8692. reader.align();
  8693. }
  8694. var psPacked = new Int32Array(ps);
  8695. mesh.figures.push({
  8696. type: 'triangles',
  8697. coords: psPacked,
  8698. colors: psPacked
  8699. });
  8700. }
  8701. function decodeType5Shading(mesh, reader, verticesPerRow) {
  8702. var coords = mesh.coords;
  8703. var colors = mesh.colors;
  8704. var ps = []; // not maintaining cs since that will match ps
  8705. while (reader.hasData) {
  8706. var coord = reader.readCoordinate();
  8707. var color = reader.readComponents();
  8708. ps.push(coords.length);
  8709. coords.push(coord);
  8710. colors.push(color);
  8711. }
  8712. var psPacked = new Int32Array(ps);
  8713. mesh.figures.push({
  8714. type: 'lattice',
  8715. coords: psPacked,
  8716. colors: psPacked,
  8717. verticesPerRow: verticesPerRow
  8718. });
  8719. }
  8720. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  8721. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  8722. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  8723. var getB = (function getBClosure() {
  8724. function buildB(count) {
  8725. var lut = [];
  8726. for (var i = 0; i <= count; i++) {
  8727. var t = i / count, t_ = 1 - t;
  8728. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  8729. 3 * t * t * t_, t * t * t]));
  8730. }
  8731. return lut;
  8732. }
  8733. var cache = [];
  8734. return function getB(count) {
  8735. if (!cache[count]) {
  8736. cache[count] = buildB(count);
  8737. }
  8738. return cache[count];
  8739. };
  8740. })();
  8741. function buildFigureFromPatch(mesh, index) {
  8742. var figure = mesh.figures[index];
  8743. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  8744. var coords = mesh.coords, colors = mesh.colors;
  8745. var pi = figure.coords;
  8746. var ci = figure.colors;
  8747. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  8748. coords[pi[12]][0], coords[pi[15]][0]);
  8749. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  8750. coords[pi[12]][1], coords[pi[15]][1]);
  8751. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  8752. coords[pi[12]][0], coords[pi[15]][0]);
  8753. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  8754. coords[pi[12]][1], coords[pi[15]][1]);
  8755. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  8756. (mesh.bounds[2] - mesh.bounds[0]));
  8757. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  8758. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  8759. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  8760. (mesh.bounds[3] - mesh.bounds[1]));
  8761. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  8762. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  8763. var verticesPerRow = splitXBy + 1;
  8764. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  8765. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  8766. var k = 0;
  8767. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  8768. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  8769. c2 = colors[ci[2]], c3 = colors[ci[3]];
  8770. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  8771. for (var row = 0; row <= splitYBy; row++) {
  8772. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  8773. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  8774. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  8775. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  8776. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  8777. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  8778. for (var col = 0; col <= splitXBy; col++, k++) {
  8779. if ((row === 0 || row === splitYBy) &&
  8780. (col === 0 || col === splitXBy)) {
  8781. continue;
  8782. }
  8783. var x = 0, y = 0;
  8784. var q = 0;
  8785. for (var i = 0; i <= 3; i++) {
  8786. for (var j = 0; j <= 3; j++, q++) {
  8787. var m = bRow[row][i] * bCol[col][j];
  8788. x += coords[pi[q]][0] * m;
  8789. y += coords[pi[q]][1] * m;
  8790. }
  8791. }
  8792. figureCoords[k] = coords.length;
  8793. coords.push([x, y]);
  8794. figureColors[k] = colors.length;
  8795. var newColor = new Uint8Array(3);
  8796. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  8797. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  8798. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  8799. colors.push(newColor);
  8800. }
  8801. }
  8802. figureCoords[0] = pi[0];
  8803. figureColors[0] = ci[0];
  8804. figureCoords[splitXBy] = pi[3];
  8805. figureColors[splitXBy] = ci[1];
  8806. figureCoords[verticesPerRow * splitYBy] = pi[12];
  8807. figureColors[verticesPerRow * splitYBy] = ci[2];
  8808. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  8809. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  8810. mesh.figures[index] = {
  8811. type: 'lattice',
  8812. coords: figureCoords,
  8813. colors: figureColors,
  8814. verticesPerRow: verticesPerRow
  8815. };
  8816. }
  8817. function decodeType6Shading(mesh, reader) {
  8818. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  8819. var coords = mesh.coords;
  8820. var colors = mesh.colors;
  8821. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  8822. var cs = new Int32Array(4); // c00, c30, c03, c33
  8823. while (reader.hasData) {
  8824. var f = reader.readFlag();
  8825. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  8826. var i, ii;
  8827. var pi = coords.length;
  8828. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  8829. coords.push(reader.readCoordinate());
  8830. }
  8831. var ci = colors.length;
  8832. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  8833. colors.push(reader.readComponents());
  8834. }
  8835. var tmp1, tmp2, tmp3, tmp4;
  8836. switch (f) {
  8837. case 0:
  8838. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  8839. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  8840. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  8841. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  8842. cs[2] = ci + 1; cs[3] = ci + 2;
  8843. cs[0] = ci; cs[1] = ci + 3;
  8844. break;
  8845. case 1:
  8846. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  8847. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  8848. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  8849. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  8850. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  8851. tmp1 = cs[2]; tmp2 = cs[3];
  8852. cs[2] = ci + 1; cs[3] = ci;
  8853. cs[0] = tmp1; cs[1] = tmp2;
  8854. break;
  8855. case 2:
  8856. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  8857. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  8858. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  8859. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  8860. cs[2] = cs[3]; cs[3] = ci + 1;
  8861. cs[0] = cs[1]; cs[1] = ci;
  8862. break;
  8863. case 3:
  8864. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  8865. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  8866. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  8867. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  8868. cs[2] = cs[0]; cs[3] = cs[1];
  8869. cs[0] = ci; cs[1] = ci + 1;
  8870. break;
  8871. }
  8872. // set p11, p12, p21, p22
  8873. ps[5] = coords.length;
  8874. coords.push([
  8875. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  8876. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  8877. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  8878. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  8879. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  8880. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  8881. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  8882. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  8883. ]);
  8884. ps[6] = coords.length;
  8885. coords.push([
  8886. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  8887. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  8888. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  8889. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  8890. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  8891. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  8892. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  8893. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  8894. ]);
  8895. ps[9] = coords.length;
  8896. coords.push([
  8897. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  8898. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  8899. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  8900. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  8901. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  8902. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  8903. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  8904. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  8905. ]);
  8906. ps[10] = coords.length;
  8907. coords.push([
  8908. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  8909. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  8910. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  8911. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  8912. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  8913. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  8914. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  8915. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  8916. ]);
  8917. mesh.figures.push({
  8918. type: 'patch',
  8919. coords: new Int32Array(ps), // making copies of ps and cs
  8920. colors: new Int32Array(cs)
  8921. });
  8922. }
  8923. }
  8924. function decodeType7Shading(mesh, reader) {
  8925. var coords = mesh.coords;
  8926. var colors = mesh.colors;
  8927. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  8928. var cs = new Int32Array(4); // c00, c30, c03, c33
  8929. while (reader.hasData) {
  8930. var f = reader.readFlag();
  8931. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  8932. var i, ii;
  8933. var pi = coords.length;
  8934. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  8935. coords.push(reader.readCoordinate());
  8936. }
  8937. var ci = colors.length;
  8938. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  8939. colors.push(reader.readComponents());
  8940. }
  8941. var tmp1, tmp2, tmp3, tmp4;
  8942. switch (f) {
  8943. case 0:
  8944. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  8945. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  8946. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  8947. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  8948. cs[2] = ci + 1; cs[3] = ci + 2;
  8949. cs[0] = ci; cs[1] = ci + 3;
  8950. break;
  8951. case 1:
  8952. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  8953. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  8954. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  8955. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  8956. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  8957. tmp1 = cs[2]; tmp2 = cs[3];
  8958. cs[2] = ci + 1; cs[3] = ci;
  8959. cs[0] = tmp1; cs[1] = tmp2;
  8960. break;
  8961. case 2:
  8962. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  8963. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  8964. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  8965. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  8966. cs[2] = cs[3]; cs[3] = ci + 1;
  8967. cs[0] = cs[1]; cs[1] = ci;
  8968. break;
  8969. case 3:
  8970. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  8971. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  8972. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  8973. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  8974. cs[2] = cs[0]; cs[3] = cs[1];
  8975. cs[0] = ci; cs[1] = ci + 1;
  8976. break;
  8977. }
  8978. mesh.figures.push({
  8979. type: 'patch',
  8980. coords: new Int32Array(ps), // making copies of ps and cs
  8981. colors: new Int32Array(cs)
  8982. });
  8983. }
  8984. }
  8985. function updateBounds(mesh) {
  8986. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  8987. maxX = minX, maxY = minY;
  8988. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  8989. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  8990. minX = minX > x ? x : minX;
  8991. minY = minY > y ? y : minY;
  8992. maxX = maxX < x ? x : maxX;
  8993. maxY = maxY < y ? y : maxY;
  8994. }
  8995. mesh.bounds = [minX, minY, maxX, maxY];
  8996. }
  8997. function packData(mesh) {
  8998. var i, ii, j, jj;
  8999. var coords = mesh.coords;
  9000. var coordsPacked = new Float32Array(coords.length * 2);
  9001. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9002. var xy = coords[i];
  9003. coordsPacked[j++] = xy[0];
  9004. coordsPacked[j++] = xy[1];
  9005. }
  9006. mesh.coords = coordsPacked;
  9007. var colors = mesh.colors;
  9008. var colorsPacked = new Uint8Array(colors.length * 3);
  9009. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9010. var c = colors[i];
  9011. colorsPacked[j++] = c[0];
  9012. colorsPacked[j++] = c[1];
  9013. colorsPacked[j++] = c[2];
  9014. }
  9015. mesh.colors = colorsPacked;
  9016. var figures = mesh.figures;
  9017. for (i = 0, ii = figures.length; i < ii; i++) {
  9018. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9019. for (j = 0, jj = ps.length; j < jj; j++) {
  9020. ps[j] *= 2;
  9021. cs[j] *= 3;
  9022. }
  9023. }
  9024. }
  9025. function Mesh(stream, matrix, xref, res) {
  9026. assert(isStream(stream), 'Mesh data is not a stream');
  9027. var dict = stream.dict;
  9028. this.matrix = matrix;
  9029. this.shadingType = dict.get('ShadingType');
  9030. this.type = 'Pattern';
  9031. this.bbox = dict.get('BBox');
  9032. var cs = dict.get('ColorSpace', 'CS');
  9033. cs = ColorSpace.parse(cs, xref, res);
  9034. this.cs = cs;
  9035. this.background = dict.has('Background') ?
  9036. cs.getRgb(dict.get('Background'), 0) : null;
  9037. var fnObj = dict.get('Function');
  9038. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9039. this.coords = [];
  9040. this.colors = [];
  9041. this.figures = [];
  9042. var decodeContext = {
  9043. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9044. bitsPerComponent: dict.get('BitsPerComponent'),
  9045. bitsPerFlag: dict.get('BitsPerFlag'),
  9046. decode: dict.get('Decode'),
  9047. colorFn: fn,
  9048. colorSpace: cs,
  9049. numComps: fn ? 1 : cs.numComps
  9050. };
  9051. var reader = new MeshStreamReader(stream, decodeContext);
  9052. var patchMesh = false;
  9053. switch (this.shadingType) {
  9054. case PatternType.FREE_FORM_MESH:
  9055. decodeType4Shading(this, reader);
  9056. break;
  9057. case PatternType.LATTICE_FORM_MESH:
  9058. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9059. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9060. decodeType5Shading(this, reader, verticesPerRow);
  9061. break;
  9062. case PatternType.COONS_PATCH_MESH:
  9063. decodeType6Shading(this, reader);
  9064. patchMesh = true;
  9065. break;
  9066. case PatternType.TENSOR_PATCH_MESH:
  9067. decodeType7Shading(this, reader);
  9068. patchMesh = true;
  9069. break;
  9070. default:
  9071. error('Unsupported mesh type.');
  9072. break;
  9073. }
  9074. if (patchMesh) {
  9075. // dirty bounds calculation for determining, how dense shall be triangles
  9076. updateBounds(this);
  9077. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9078. buildFigureFromPatch(this, i);
  9079. }
  9080. }
  9081. // calculate bounds
  9082. updateBounds(this);
  9083. packData(this);
  9084. }
  9085. Mesh.prototype = {
  9086. getIR: function Mesh_getIR() {
  9087. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9088. this.bounds, this.matrix, this.bbox, this.background];
  9089. }
  9090. };
  9091. return Mesh;
  9092. })();
  9093. Shadings.Dummy = (function DummyClosure() {
  9094. function Dummy() {
  9095. this.type = 'Pattern';
  9096. }
  9097. Dummy.prototype = {
  9098. getIR: function Dummy_getIR() {
  9099. return ['Dummy'];
  9100. }
  9101. };
  9102. return Dummy;
  9103. })();
  9104. function getTilingPatternIR(operatorList, dict, args) {
  9105. var matrix = dict.get('Matrix');
  9106. var bbox = dict.get('BBox');
  9107. var xstep = dict.get('XStep');
  9108. var ystep = dict.get('YStep');
  9109. var paintType = dict.get('PaintType');
  9110. var tilingType = dict.get('TilingType');
  9111. return [
  9112. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9113. paintType, tilingType
  9114. ];
  9115. }
  9116. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9117. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9118. uniquePrefix, idCounters, fontCache) {
  9119. this.pdfManager = pdfManager;
  9120. this.xref = xref;
  9121. this.handler = handler;
  9122. this.pageIndex = pageIndex;
  9123. this.uniquePrefix = uniquePrefix;
  9124. this.idCounters = idCounters;
  9125. this.fontCache = fontCache;
  9126. }
  9127. // Trying to minimize Date.now() usage and check every 100 time
  9128. var TIME_SLOT_DURATION_MS = 20;
  9129. var CHECK_TIME_EVERY = 100;
  9130. function TimeSlotManager() {
  9131. this.reset();
  9132. }
  9133. TimeSlotManager.prototype = {
  9134. check: function TimeSlotManager_check() {
  9135. if (++this.checked < CHECK_TIME_EVERY) {
  9136. return false;
  9137. }
  9138. this.checked = 0;
  9139. return this.endTime <= Date.now();
  9140. },
  9141. reset: function TimeSlotManager_reset() {
  9142. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9143. this.checked = 0;
  9144. }
  9145. };
  9146. var deferred = Promise.resolve();
  9147. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9148. PartialEvaluator.prototype = {
  9149. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9150. if (!isDict(resources)) {
  9151. return false;
  9152. }
  9153. var processed = Object.create(null);
  9154. if (resources.objId) {
  9155. processed[resources.objId] = true;
  9156. }
  9157. var nodes = [resources];
  9158. while (nodes.length) {
  9159. var key;
  9160. var node = nodes.shift();
  9161. // First check the current resources for blend modes.
  9162. var graphicStates = node.get('ExtGState');
  9163. if (isDict(graphicStates)) {
  9164. graphicStates = graphicStates.getAll();
  9165. for (key in graphicStates) {
  9166. var graphicState = graphicStates[key];
  9167. var bm = graphicState['BM'];
  9168. if (isName(bm) && bm.name !== 'Normal') {
  9169. return true;
  9170. }
  9171. }
  9172. }
  9173. // Descend into the XObjects to look for more resources and blend modes.
  9174. var xObjects = node.get('XObject');
  9175. if (!isDict(xObjects)) {
  9176. continue;
  9177. }
  9178. xObjects = xObjects.getAll();
  9179. for (key in xObjects) {
  9180. var xObject = xObjects[key];
  9181. if (!isStream(xObject)) {
  9182. continue;
  9183. }
  9184. if (xObject.dict.objId) {
  9185. if (processed[xObject.dict.objId]) {
  9186. // stream has objId and is processed already
  9187. continue;
  9188. }
  9189. processed[xObject.dict.objId] = true;
  9190. }
  9191. var xResources = xObject.dict.get('Resources');
  9192. // Checking objId to detect an infinite loop.
  9193. if (isDict(xResources) &&
  9194. (!xResources.objId || !processed[xResources.objId])) {
  9195. nodes.push(xResources);
  9196. if (xResources.objId) {
  9197. processed[xResources.objId] = true;
  9198. }
  9199. }
  9200. }
  9201. }
  9202. return false;
  9203. },
  9204. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9205. xobj, smask,
  9206. operatorList,
  9207. initialState) {
  9208. var matrix = xobj.dict.get('Matrix');
  9209. var bbox = xobj.dict.get('BBox');
  9210. var group = xobj.dict.get('Group');
  9211. if (group) {
  9212. var groupOptions = {
  9213. matrix: matrix,
  9214. bbox: bbox,
  9215. smask: smask,
  9216. isolated: false,
  9217. knockout: false
  9218. };
  9219. var groupSubtype = group.get('S');
  9220. var colorSpace;
  9221. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9222. groupOptions.isolated = (group.get('I') || false);
  9223. groupOptions.knockout = (group.get('K') || false);
  9224. colorSpace = (group.has('CS') ?
  9225. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9226. }
  9227. if (smask && smask.backdrop) {
  9228. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9229. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9230. }
  9231. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9232. }
  9233. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9234. return this.getOperatorList(xobj,
  9235. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9236. then(function () {
  9237. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9238. if (group) {
  9239. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9240. }
  9241. });
  9242. },
  9243. buildPaintImageXObject:
  9244. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9245. inline, operatorList,
  9246. cacheKey, cache) {
  9247. var self = this;
  9248. var dict = image.dict;
  9249. var w = dict.get('Width', 'W');
  9250. var h = dict.get('Height', 'H');
  9251. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9252. warn('Image dimensions are missing, or not numbers.');
  9253. return;
  9254. }
  9255. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9256. warn('Image exceeded maximum allowed size and was removed.');
  9257. return;
  9258. }
  9259. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9260. var imgData, args;
  9261. if (imageMask) {
  9262. // This depends on a tmpCanvas being filled with the
  9263. // current fillStyle, such that processing the pixel
  9264. // data can't be done here. Instead of creating a
  9265. // complete PDFImage, only read the information needed
  9266. // for later.
  9267. var width = dict.get('Width', 'W');
  9268. var height = dict.get('Height', 'H');
  9269. var bitStrideLength = (width + 7) >> 3;
  9270. var imgArray = image.getBytes(bitStrideLength * height);
  9271. var decode = dict.get('Decode', 'D');
  9272. var inverseDecode = (!!decode && decode[0] > 0);
  9273. imgData = PDFImage.createMask(imgArray, width, height,
  9274. image instanceof DecodeStream,
  9275. inverseDecode);
  9276. imgData.cached = true;
  9277. args = [imgData];
  9278. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9279. if (cacheKey) {
  9280. cache.key = cacheKey;
  9281. cache.fn = OPS.paintImageMaskXObject;
  9282. cache.args = args;
  9283. }
  9284. return;
  9285. }
  9286. var softMask = (dict.get('SMask', 'SM') || false);
  9287. var mask = (dict.get('Mask') || false);
  9288. var SMALL_IMAGE_DIMENSIONS = 200;
  9289. // Inlining small images into the queue as RGB data
  9290. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9291. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9292. var imageObj = new PDFImage(this.xref, resources, image,
  9293. inline, null, null);
  9294. // We force the use of RGBA_32BPP images here, because we can't handle
  9295. // any other kind.
  9296. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9297. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9298. return;
  9299. }
  9300. // If there is no imageMask, create the PDFImage and a lot
  9301. // of image processing can be done here.
  9302. var uniquePrefix = (this.uniquePrefix || '');
  9303. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9304. operatorList.addDependency(objId);
  9305. args = [objId, w, h];
  9306. if (!softMask && !mask && image instanceof JpegStream &&
  9307. image.isNativelySupported(this.xref, resources)) {
  9308. // These JPEGs don't need any more processing so we can just send it.
  9309. operatorList.addOp(OPS.paintJpegXObject, args);
  9310. this.handler.send('obj',
  9311. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9312. return;
  9313. }
  9314. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9315. then(function(imageObj) {
  9316. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9317. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9318. [imgData.data.buffer]);
  9319. }).then(null, function (reason) {
  9320. warn('Unable to decode image: ' + reason);
  9321. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9322. });
  9323. operatorList.addOp(OPS.paintImageXObject, args);
  9324. if (cacheKey) {
  9325. cache.key = cacheKey;
  9326. cache.fn = OPS.paintImageXObject;
  9327. cache.args = args;
  9328. }
  9329. },
  9330. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9331. operatorList,
  9332. stateManager) {
  9333. var smaskContent = smask.get('G');
  9334. var smaskOptions = {
  9335. subtype: smask.get('S').name,
  9336. backdrop: smask.get('BC')
  9337. };
  9338. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9339. operatorList, stateManager.state.clone());
  9340. },
  9341. handleTilingType:
  9342. function PartialEvaluator_handleTilingType(fn, args, resources,
  9343. pattern, patternDict,
  9344. operatorList) {
  9345. // Create an IR of the pattern code.
  9346. var tilingOpList = new OperatorList();
  9347. return this.getOperatorList(pattern,
  9348. (patternDict.get('Resources') || resources), tilingOpList).
  9349. then(function () {
  9350. // Add the dependencies to the parent operator list so they are
  9351. // resolved before sub operator list is executed synchronously.
  9352. operatorList.addDependencies(tilingOpList.dependencies);
  9353. operatorList.addOp(fn, getTilingPatternIR({
  9354. fnArray: tilingOpList.fnArray,
  9355. argsArray: tilingOpList.argsArray
  9356. }, patternDict, args));
  9357. });
  9358. },
  9359. handleSetFont:
  9360. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9361. operatorList, state) {
  9362. // TODO(mack): Not needed?
  9363. var fontName;
  9364. if (fontArgs) {
  9365. fontArgs = fontArgs.slice();
  9366. fontName = fontArgs[0].name;
  9367. }
  9368. var self = this;
  9369. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9370. function (translated) {
  9371. if (!translated.font.isType3Font) {
  9372. return translated;
  9373. }
  9374. return translated.loadType3Data(self, resources, operatorList).then(
  9375. function () {
  9376. return translated;
  9377. });
  9378. }).then(function (translated) {
  9379. state.font = translated.font;
  9380. translated.send(self.handler);
  9381. return translated.loadedName;
  9382. });
  9383. },
  9384. handleText: function PartialEvaluator_handleText(chars, state) {
  9385. var font = state.font;
  9386. var glyphs = font.charsToGlyphs(chars);
  9387. var isAddToPathSet = !!(state.textRenderingMode &
  9388. TextRenderingMode.ADD_TO_PATH_FLAG);
  9389. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9390. var buildPath = function (fontChar) {
  9391. if (!font.renderer.hasBuiltPath(fontChar)) {
  9392. var path = font.renderer.getPathJs(fontChar);
  9393. this.handler.send('commonobj', [
  9394. font.loadedName + '_path_' + fontChar,
  9395. 'FontPath',
  9396. path
  9397. ]);
  9398. }
  9399. }.bind(this);
  9400. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9401. var glyph = glyphs[i];
  9402. if (glyph === null) {
  9403. continue;
  9404. }
  9405. buildPath(glyph.fontChar);
  9406. // If the glyph has an accent we need to build a path for its
  9407. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9408. var accent = glyph.accent;
  9409. if (accent && accent.fontChar) {
  9410. buildPath(accent.fontChar);
  9411. }
  9412. }
  9413. }
  9414. return glyphs;
  9415. },
  9416. setGState: function PartialEvaluator_setGState(resources, gState,
  9417. operatorList, xref,
  9418. stateManager) {
  9419. // TODO(mack): This should be rewritten so that this function returns
  9420. // what should be added to the queue during each iteration
  9421. function setGStateForKey(gStateObj, key, value) {
  9422. switch (key) {
  9423. case 'Type':
  9424. break;
  9425. case 'LW':
  9426. case 'LC':
  9427. case 'LJ':
  9428. case 'ML':
  9429. case 'D':
  9430. case 'RI':
  9431. case 'FL':
  9432. case 'CA':
  9433. case 'ca':
  9434. gStateObj.push([key, value]);
  9435. break;
  9436. case 'Font':
  9437. promise = promise.then(function () {
  9438. return self.handleSetFont(resources, null, value[0],
  9439. operatorList, stateManager.state).
  9440. then(function (loadedName) {
  9441. operatorList.addDependency(loadedName);
  9442. gStateObj.push([key, [loadedName, value[1]]]);
  9443. });
  9444. });
  9445. break;
  9446. case 'BM':
  9447. gStateObj.push([key, value]);
  9448. break;
  9449. case 'SMask':
  9450. if (isName(value) && value.name === 'None') {
  9451. gStateObj.push([key, false]);
  9452. break;
  9453. }
  9454. var dict = xref.fetchIfRef(value);
  9455. if (isDict(dict)) {
  9456. promise = promise.then(function () {
  9457. return self.handleSMask(dict, resources, operatorList,
  9458. stateManager);
  9459. });
  9460. gStateObj.push([key, true]);
  9461. } else {
  9462. warn('Unsupported SMask type');
  9463. }
  9464. break;
  9465. // Only generate info log messages for the following since
  9466. // they are unlikey to have a big impact on the rendering.
  9467. case 'OP':
  9468. case 'op':
  9469. case 'OPM':
  9470. case 'BG':
  9471. case 'BG2':
  9472. case 'UCR':
  9473. case 'UCR2':
  9474. case 'TR':
  9475. case 'TR2':
  9476. case 'HT':
  9477. case 'SM':
  9478. case 'SA':
  9479. case 'AIS':
  9480. case 'TK':
  9481. // TODO implement these operators.
  9482. info('graphic state operator ' + key);
  9483. break;
  9484. default:
  9485. info('Unknown graphic state operator ' + key);
  9486. break;
  9487. }
  9488. }
  9489. // This array holds the converted/processed state data.
  9490. var gStateObj = [];
  9491. var gStateMap = gState.map;
  9492. var self = this;
  9493. var promise = Promise.resolve();
  9494. for (var key in gStateMap) {
  9495. var value = gStateMap[key];
  9496. setGStateForKey(gStateObj, key, value);
  9497. }
  9498. return promise.then(function () {
  9499. operatorList.addOp(OPS.setGState, [gStateObj]);
  9500. });
  9501. },
  9502. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9503. resources) {
  9504. function errorFont() {
  9505. return Promise.resolve(new TranslatedFont('g_font_error',
  9506. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9507. }
  9508. var fontRef;
  9509. if (font) { // Loading by ref.
  9510. assert(isRef(font));
  9511. fontRef = font;
  9512. } else { // Loading by name.
  9513. var fontRes = resources.get('Font');
  9514. if (fontRes) {
  9515. fontRef = fontRes.getRaw(fontName);
  9516. } else {
  9517. warn('fontRes not available');
  9518. return errorFont();
  9519. }
  9520. }
  9521. if (!fontRef) {
  9522. warn('fontRef not available');
  9523. return errorFont();
  9524. }
  9525. if (this.fontCache.has(fontRef)) {
  9526. return this.fontCache.get(fontRef);
  9527. }
  9528. font = xref.fetchIfRef(fontRef);
  9529. if (!isDict(font)) {
  9530. return errorFont();
  9531. }
  9532. // We are holding font.translated references just for fontRef that are not
  9533. // dictionaries (Dict). See explanation below.
  9534. if (font.translated) {
  9535. return font.translated;
  9536. }
  9537. var fontCapability = createPromiseCapability();
  9538. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9539. var descriptor = preEvaluatedFont.descriptor;
  9540. var fontID = fontRef.num + '_' + fontRef.gen;
  9541. if (isDict(descriptor)) {
  9542. if (!descriptor.fontAliases) {
  9543. descriptor.fontAliases = Object.create(null);
  9544. }
  9545. var fontAliases = descriptor.fontAliases;
  9546. var hash = preEvaluatedFont.hash;
  9547. if (fontAliases[hash]) {
  9548. var aliasFontRef = fontAliases[hash].aliasRef;
  9549. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9550. this.fontCache.putAlias(fontRef, aliasFontRef);
  9551. return this.fontCache.get(fontRef);
  9552. }
  9553. }
  9554. if (!fontAliases[hash]) {
  9555. fontAliases[hash] = {
  9556. fontID: Font.getFontID()
  9557. };
  9558. }
  9559. fontAliases[hash].aliasRef = fontRef;
  9560. fontID = fontAliases[hash].fontID;
  9561. }
  9562. // Workaround for bad PDF generators that don't reference fonts
  9563. // properly, i.e. by not using an object identifier.
  9564. // Check if the fontRef is a Dict (as opposed to a standard object),
  9565. // in which case we don't cache the font and instead reference it by
  9566. // fontName in font.loadedName below.
  9567. var fontRefIsDict = isDict(fontRef);
  9568. if (!fontRefIsDict) {
  9569. this.fontCache.put(fontRef, fontCapability.promise);
  9570. }
  9571. // Keep track of each font we translated so the caller can
  9572. // load them asynchronously before calling display on a page.
  9573. font.loadedName = 'g_font_' + (fontRefIsDict ?
  9574. fontName.replace(/\W/g, '') : fontID);
  9575. font.translated = fontCapability.promise;
  9576. // TODO move promises into translate font
  9577. var translatedPromise;
  9578. try {
  9579. translatedPromise = Promise.resolve(
  9580. this.translateFont(preEvaluatedFont, xref));
  9581. } catch (e) {
  9582. translatedPromise = Promise.reject(e);
  9583. }
  9584. translatedPromise.then(function (translatedFont) {
  9585. if (translatedFont.fontType !== undefined) {
  9586. var xrefFontStats = xref.stats.fontTypes;
  9587. xrefFontStats[translatedFont.fontType] = true;
  9588. }
  9589. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9590. translatedFont, font));
  9591. }, function (reason) {
  9592. // TODO fontCapability.reject?
  9593. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  9594. try {
  9595. // error, but it's still nice to have font type reported
  9596. var descriptor = preEvaluatedFont.descriptor;
  9597. var fontFile3 = descriptor && descriptor.get('FontFile3');
  9598. var subtype = fontFile3 && fontFile3.get('Subtype');
  9599. var fontType = getFontType(preEvaluatedFont.type,
  9600. subtype && subtype.name);
  9601. var xrefFontStats = xref.stats.fontTypes;
  9602. xrefFontStats[fontType] = true;
  9603. } catch (ex) { }
  9604. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9605. new ErrorFont(reason instanceof Error ? reason.message : reason),
  9606. font));
  9607. });
  9608. return fontCapability.promise;
  9609. },
  9610. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  9611. var lastIndex = operatorList.length - 1;
  9612. if (!args) {
  9613. args = [];
  9614. }
  9615. if (lastIndex < 0 ||
  9616. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  9617. operatorList.addOp(OPS.constructPath, [[fn], args]);
  9618. } else {
  9619. var opArgs = operatorList.argsArray[lastIndex];
  9620. opArgs[0].push(fn);
  9621. Array.prototype.push.apply(opArgs[1], args);
  9622. }
  9623. },
  9624. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  9625. cs, patterns, resources, xref) {
  9626. // compile tiling patterns
  9627. var patternName = args[args.length - 1];
  9628. // SCN/scn applies patterns along with normal colors
  9629. var pattern;
  9630. if (isName(patternName) &&
  9631. (pattern = patterns.get(patternName.name))) {
  9632. var dict = (isStream(pattern) ? pattern.dict : pattern);
  9633. var typeNum = dict.get('PatternType');
  9634. if (typeNum === TILING_PATTERN) {
  9635. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  9636. return this.handleTilingType(fn, color, resources, pattern,
  9637. dict, operatorList);
  9638. } else if (typeNum === SHADING_PATTERN) {
  9639. var shading = dict.get('Shading');
  9640. var matrix = dict.get('Matrix');
  9641. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  9642. operatorList.addOp(fn, pattern.getIR());
  9643. return Promise.resolve();
  9644. } else {
  9645. return Promise.reject('Unknown PatternType: ' + typeNum);
  9646. }
  9647. }
  9648. // TODO shall we fail here?
  9649. operatorList.addOp(fn, args);
  9650. return Promise.resolve();
  9651. },
  9652. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  9653. resources,
  9654. operatorList,
  9655. initialState) {
  9656. var self = this;
  9657. var xref = this.xref;
  9658. var imageCache = {};
  9659. assert(operatorList);
  9660. resources = (resources || Dict.empty);
  9661. var xobjs = (resources.get('XObject') || Dict.empty);
  9662. var patterns = (resources.get('Pattern') || Dict.empty);
  9663. var stateManager = new StateManager(initialState || new EvalState());
  9664. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9665. var timeSlotManager = new TimeSlotManager();
  9666. return new Promise(function next(resolve, reject) {
  9667. timeSlotManager.reset();
  9668. var stop, operation = {}, i, ii, cs;
  9669. while (!(stop = timeSlotManager.check()) &&
  9670. preprocessor.read(operation)) {
  9671. var args = operation.args;
  9672. var fn = operation.fn;
  9673. switch (fn | 0) {
  9674. case OPS.paintXObject:
  9675. if (args[0].code) {
  9676. break;
  9677. }
  9678. // eagerly compile XForm objects
  9679. var name = args[0].name;
  9680. if (imageCache.key === name) {
  9681. operatorList.addOp(imageCache.fn, imageCache.args);
  9682. args = null;
  9683. continue;
  9684. }
  9685. var xobj = xobjs.get(name);
  9686. if (xobj) {
  9687. assert(isStream(xobj), 'XObject should be a stream');
  9688. var type = xobj.dict.get('Subtype');
  9689. assert(isName(type),
  9690. 'XObject should have a Name subtype');
  9691. if (type.name === 'Form') {
  9692. stateManager.save();
  9693. return self.buildFormXObject(resources, xobj, null,
  9694. operatorList,
  9695. stateManager.state.clone()).
  9696. then(function () {
  9697. stateManager.restore();
  9698. next(resolve, reject);
  9699. }, reject);
  9700. } else if (type.name === 'Image') {
  9701. self.buildPaintImageXObject(resources, xobj, false,
  9702. operatorList, name, imageCache);
  9703. args = null;
  9704. continue;
  9705. } else if (type.name === 'PS') {
  9706. // PostScript XObjects are unused when viewing documents.
  9707. // See section 4.7.1 of Adobe's PDF reference.
  9708. info('Ignored XObject subtype PS');
  9709. continue;
  9710. } else {
  9711. error('Unhandled XObject subtype ' + type.name);
  9712. }
  9713. }
  9714. break;
  9715. case OPS.setFont:
  9716. var fontSize = args[1];
  9717. // eagerly collect all fonts
  9718. return self.handleSetFont(resources, args, null,
  9719. operatorList, stateManager.state).
  9720. then(function (loadedName) {
  9721. operatorList.addDependency(loadedName);
  9722. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  9723. next(resolve, reject);
  9724. }, reject);
  9725. case OPS.endInlineImage:
  9726. var cacheKey = args[0].cacheKey;
  9727. if (cacheKey && imageCache.key === cacheKey) {
  9728. operatorList.addOp(imageCache.fn, imageCache.args);
  9729. args = null;
  9730. continue;
  9731. }
  9732. self.buildPaintImageXObject(resources, args[0], true,
  9733. operatorList, cacheKey, imageCache);
  9734. args = null;
  9735. continue;
  9736. case OPS.showText:
  9737. args[0] = self.handleText(args[0], stateManager.state);
  9738. break;
  9739. case OPS.showSpacedText:
  9740. var arr = args[0];
  9741. var combinedGlyphs = [];
  9742. var arrLength = arr.length;
  9743. for (i = 0; i < arrLength; ++i) {
  9744. var arrItem = arr[i];
  9745. if (isString(arrItem)) {
  9746. Array.prototype.push.apply(combinedGlyphs,
  9747. self.handleText(arrItem, stateManager.state));
  9748. } else if (isNum(arrItem)) {
  9749. combinedGlyphs.push(arrItem);
  9750. }
  9751. }
  9752. args[0] = combinedGlyphs;
  9753. fn = OPS.showText;
  9754. break;
  9755. case OPS.nextLineShowText:
  9756. operatorList.addOp(OPS.nextLine);
  9757. args[0] = self.handleText(args[0], stateManager.state);
  9758. fn = OPS.showText;
  9759. break;
  9760. case OPS.nextLineSetSpacingShowText:
  9761. operatorList.addOp(OPS.nextLine);
  9762. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  9763. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  9764. args[0] = self.handleText(args[0], stateManager.state);
  9765. fn = OPS.showText;
  9766. break;
  9767. case OPS.setTextRenderingMode:
  9768. stateManager.state.textRenderingMode = args[0];
  9769. break;
  9770. case OPS.setFillColorSpace:
  9771. stateManager.state.fillColorSpace =
  9772. ColorSpace.parse(args[0], xref, resources);
  9773. continue;
  9774. case OPS.setStrokeColorSpace:
  9775. stateManager.state.strokeColorSpace =
  9776. ColorSpace.parse(args[0], xref, resources);
  9777. continue;
  9778. case OPS.setFillColor:
  9779. cs = stateManager.state.fillColorSpace;
  9780. args = cs.getRgb(args, 0);
  9781. fn = OPS.setFillRGBColor;
  9782. break;
  9783. case OPS.setStrokeColor:
  9784. cs = stateManager.state.strokeColorSpace;
  9785. args = cs.getRgb(args, 0);
  9786. fn = OPS.setStrokeRGBColor;
  9787. break;
  9788. case OPS.setFillGray:
  9789. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  9790. args = ColorSpace.singletons.gray.getRgb(args, 0);
  9791. fn = OPS.setFillRGBColor;
  9792. break;
  9793. case OPS.setStrokeGray:
  9794. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  9795. args = ColorSpace.singletons.gray.getRgb(args, 0);
  9796. fn = OPS.setStrokeRGBColor;
  9797. break;
  9798. case OPS.setFillCMYKColor:
  9799. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  9800. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  9801. fn = OPS.setFillRGBColor;
  9802. break;
  9803. case OPS.setStrokeCMYKColor:
  9804. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  9805. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  9806. fn = OPS.setStrokeRGBColor;
  9807. break;
  9808. case OPS.setFillRGBColor:
  9809. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  9810. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  9811. break;
  9812. case OPS.setStrokeRGBColor:
  9813. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  9814. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  9815. break;
  9816. case OPS.setFillColorN:
  9817. cs = stateManager.state.fillColorSpace;
  9818. if (cs.name === 'Pattern') {
  9819. return self.handleColorN(operatorList, OPS.setFillColorN,
  9820. args, cs, patterns, resources, xref).then(function() {
  9821. next(resolve, reject);
  9822. }, reject);
  9823. }
  9824. args = cs.getRgb(args, 0);
  9825. fn = OPS.setFillRGBColor;
  9826. break;
  9827. case OPS.setStrokeColorN:
  9828. cs = stateManager.state.strokeColorSpace;
  9829. if (cs.name === 'Pattern') {
  9830. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  9831. args, cs, patterns, resources, xref).then(function() {
  9832. next(resolve, reject);
  9833. }, reject);
  9834. }
  9835. args = cs.getRgb(args, 0);
  9836. fn = OPS.setStrokeRGBColor;
  9837. break;
  9838. case OPS.shadingFill:
  9839. var shadingRes = resources.get('Shading');
  9840. if (!shadingRes) {
  9841. error('No shading resource found');
  9842. }
  9843. var shading = shadingRes.get(args[0].name);
  9844. if (!shading) {
  9845. error('No shading object found');
  9846. }
  9847. var shadingFill = Pattern.parseShading(shading, null, xref,
  9848. resources);
  9849. var patternIR = shadingFill.getIR();
  9850. args = [patternIR];
  9851. fn = OPS.shadingFill;
  9852. break;
  9853. case OPS.setGState:
  9854. var dictName = args[0];
  9855. var extGState = resources.get('ExtGState');
  9856. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  9857. break;
  9858. }
  9859. var gState = extGState.get(dictName.name);
  9860. return self.setGState(resources, gState, operatorList, xref,
  9861. stateManager).then(function() {
  9862. next(resolve, reject);
  9863. }, reject);
  9864. case OPS.moveTo:
  9865. case OPS.lineTo:
  9866. case OPS.curveTo:
  9867. case OPS.curveTo2:
  9868. case OPS.curveTo3:
  9869. case OPS.closePath:
  9870. self.buildPath(operatorList, fn, args);
  9871. continue;
  9872. case OPS.rectangle:
  9873. self.buildPath(operatorList, fn, args);
  9874. continue;
  9875. }
  9876. operatorList.addOp(fn, args);
  9877. }
  9878. if (stop) {
  9879. deferred.then(function () {
  9880. next(resolve, reject);
  9881. });
  9882. return;
  9883. }
  9884. // Some PDFs don't close all restores inside object/form.
  9885. // Closing those for them.
  9886. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  9887. operatorList.addOp(OPS.restore, []);
  9888. }
  9889. resolve();
  9890. });
  9891. },
  9892. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  9893. stateManager) {
  9894. stateManager = (stateManager || new StateManager(new TextState()));
  9895. var textContent = {
  9896. items: [],
  9897. styles: Object.create(null)
  9898. };
  9899. var bidiTexts = textContent.items;
  9900. var SPACE_FACTOR = 0.35;
  9901. var MULTI_SPACE_FACTOR = 1.5;
  9902. var self = this;
  9903. var xref = this.xref;
  9904. resources = (xref.fetchIfRef(resources) || Dict.empty);
  9905. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  9906. var xobjs = null;
  9907. var xobjsCache = {};
  9908. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9909. var textState;
  9910. function newTextChunk() {
  9911. var font = textState.font;
  9912. if (!(font.loadedName in textContent.styles)) {
  9913. textContent.styles[font.loadedName] = {
  9914. fontFamily: font.fallbackName,
  9915. ascent: font.ascent,
  9916. descent: font.descent,
  9917. vertical: font.vertical
  9918. };
  9919. }
  9920. return {
  9921. // |str| is initially an array which we push individual chars to, and
  9922. // then runBidi() overwrites it with the final string.
  9923. str: [],
  9924. dir: null,
  9925. width: 0,
  9926. height: 0,
  9927. transform: null,
  9928. fontName: font.loadedName
  9929. };
  9930. }
  9931. function runBidi(textChunk) {
  9932. var str = textChunk.str.join('');
  9933. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  9934. textChunk.str = bidiResult.str;
  9935. textChunk.dir = bidiResult.dir;
  9936. return textChunk;
  9937. }
  9938. function handleSetFont(fontName, fontRef) {
  9939. return self.loadFont(fontName, fontRef, xref, resources).
  9940. then(function (translated) {
  9941. textState.font = translated.font;
  9942. textState.fontMatrix = translated.font.fontMatrix ||
  9943. FONT_IDENTITY_MATRIX;
  9944. });
  9945. }
  9946. function buildTextGeometry(chars, textChunk) {
  9947. var font = textState.font;
  9948. textChunk = textChunk || newTextChunk();
  9949. if (!textChunk.transform) {
  9950. // 9.4.4 Text Space Details
  9951. var tsm = [textState.fontSize * textState.textHScale, 0,
  9952. 0, textState.fontSize,
  9953. 0, textState.textRise];
  9954. var trm = textChunk.transform = Util.transform(textState.ctm,
  9955. Util.transform(textState.textMatrix, tsm));
  9956. if (!font.vertical) {
  9957. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  9958. } else {
  9959. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  9960. }
  9961. }
  9962. var width = 0;
  9963. var height = 0;
  9964. var glyphs = font.charsToGlyphs(chars);
  9965. var defaultVMetrics = font.defaultVMetrics;
  9966. for (var i = 0; i < glyphs.length; i++) {
  9967. var glyph = glyphs[i];
  9968. if (!glyph) { // Previous glyph was a space.
  9969. width += textState.wordSpacing * textState.textHScale;
  9970. continue;
  9971. }
  9972. var vMetricX = null;
  9973. var vMetricY = null;
  9974. var glyphWidth = null;
  9975. if (font.vertical) {
  9976. if (glyph.vmetric) {
  9977. glyphWidth = glyph.vmetric[0];
  9978. vMetricX = glyph.vmetric[1];
  9979. vMetricY = glyph.vmetric[2];
  9980. } else {
  9981. glyphWidth = glyph.width;
  9982. vMetricX = glyph.width * 0.5;
  9983. vMetricY = defaultVMetrics[2];
  9984. }
  9985. } else {
  9986. glyphWidth = glyph.width;
  9987. }
  9988. var glyphUnicode = glyph.unicode;
  9989. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  9990. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  9991. }
  9992. glyphUnicode = reverseIfRtl(glyphUnicode);
  9993. // The following will calculate the x and y of the individual glyphs.
  9994. // if (font.vertical) {
  9995. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  9996. // textState.fontMatrix[0];
  9997. // tsm[5] -= vMetricY * textState.fontSize *
  9998. // textState.fontMatrix[0];
  9999. // }
  10000. // var trm = Util.transform(textState.textMatrix, tsm);
  10001. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10002. // var x = pt[0];
  10003. // var y = pt[1];
  10004. var tx = 0;
  10005. var ty = 0;
  10006. if (!font.vertical) {
  10007. var w0 = glyphWidth * textState.fontMatrix[0];
  10008. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10009. textState.textHScale;
  10010. width += tx;
  10011. } else {
  10012. var w1 = glyphWidth * textState.fontMatrix[0];
  10013. ty = w1 * textState.fontSize + textState.charSpacing;
  10014. height += ty;
  10015. }
  10016. textState.translateTextMatrix(tx, ty);
  10017. textChunk.str.push(glyphUnicode);
  10018. }
  10019. var a = textState.textLineMatrix[0];
  10020. var b = textState.textLineMatrix[1];
  10021. var scaleLineX = Math.sqrt(a * a + b * b);
  10022. a = textState.ctm[0];
  10023. b = textState.ctm[1];
  10024. var scaleCtmX = Math.sqrt(a * a + b * b);
  10025. if (!font.vertical) {
  10026. textChunk.width += width * scaleCtmX * scaleLineX;
  10027. } else {
  10028. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10029. }
  10030. return textChunk;
  10031. }
  10032. var timeSlotManager = new TimeSlotManager();
  10033. return new Promise(function next(resolve, reject) {
  10034. timeSlotManager.reset();
  10035. var stop, operation = {};
  10036. while (!(stop = timeSlotManager.check()) &&
  10037. (preprocessor.read(operation))) {
  10038. textState = stateManager.state;
  10039. var fn = operation.fn;
  10040. var args = operation.args;
  10041. switch (fn | 0) {
  10042. case OPS.setFont:
  10043. textState.fontSize = args[1];
  10044. return handleSetFont(args[0].name).then(function() {
  10045. next(resolve, reject);
  10046. }, reject);
  10047. case OPS.setTextRise:
  10048. textState.textRise = args[0];
  10049. break;
  10050. case OPS.setHScale:
  10051. textState.textHScale = args[0] / 100;
  10052. break;
  10053. case OPS.setLeading:
  10054. textState.leading = args[0];
  10055. break;
  10056. case OPS.moveText:
  10057. textState.translateTextLineMatrix(args[0], args[1]);
  10058. textState.textMatrix = textState.textLineMatrix.slice();
  10059. break;
  10060. case OPS.setLeadingMoveText:
  10061. textState.leading = -args[1];
  10062. textState.translateTextLineMatrix(args[0], args[1]);
  10063. textState.textMatrix = textState.textLineMatrix.slice();
  10064. break;
  10065. case OPS.nextLine:
  10066. textState.carriageReturn();
  10067. break;
  10068. case OPS.setTextMatrix:
  10069. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10070. args[4], args[5]);
  10071. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10072. args[4], args[5]);
  10073. break;
  10074. case OPS.setCharSpacing:
  10075. textState.charSpacing = args[0];
  10076. break;
  10077. case OPS.setWordSpacing:
  10078. textState.wordSpacing = args[0];
  10079. break;
  10080. case OPS.beginText:
  10081. textState.textMatrix = IDENTITY_MATRIX.slice();
  10082. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10083. break;
  10084. case OPS.showSpacedText:
  10085. var items = args[0];
  10086. var textChunk = newTextChunk();
  10087. var offset;
  10088. for (var j = 0, jj = items.length; j < jj; j++) {
  10089. if (typeof items[j] === 'string') {
  10090. buildTextGeometry(items[j], textChunk);
  10091. } else {
  10092. var val = items[j] / 1000;
  10093. if (!textState.font.vertical) {
  10094. offset = -val * textState.fontSize * textState.textHScale *
  10095. textState.textMatrix[0];
  10096. textState.translateTextMatrix(offset, 0);
  10097. textChunk.width += offset;
  10098. } else {
  10099. offset = -val * textState.fontSize *
  10100. textState.textMatrix[3];
  10101. textState.translateTextMatrix(0, offset);
  10102. textChunk.height += offset;
  10103. }
  10104. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10105. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10106. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10107. fakeSpaces = Math.round(fakeSpaces);
  10108. while (fakeSpaces--) {
  10109. textChunk.str.push(' ');
  10110. }
  10111. } else if (fakeSpaces > SPACE_FACTOR) {
  10112. textChunk.str.push(' ');
  10113. }
  10114. }
  10115. }
  10116. }
  10117. bidiTexts.push(runBidi(textChunk));
  10118. break;
  10119. case OPS.showText:
  10120. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10121. break;
  10122. case OPS.nextLineShowText:
  10123. textState.carriageReturn();
  10124. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10125. break;
  10126. case OPS.nextLineSetSpacingShowText:
  10127. textState.wordSpacing = args[0];
  10128. textState.charSpacing = args[1];
  10129. textState.carriageReturn();
  10130. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10131. break;
  10132. case OPS.paintXObject:
  10133. if (args[0].code) {
  10134. break;
  10135. }
  10136. if (!xobjs) {
  10137. xobjs = (resources.get('XObject') || Dict.empty);
  10138. }
  10139. var name = args[0].name;
  10140. if (xobjsCache.key === name) {
  10141. if (xobjsCache.texts) {
  10142. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10143. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10144. }
  10145. break;
  10146. }
  10147. var xobj = xobjs.get(name);
  10148. if (!xobj) {
  10149. break;
  10150. }
  10151. assert(isStream(xobj), 'XObject should be a stream');
  10152. var type = xobj.dict.get('Subtype');
  10153. assert(isName(type),
  10154. 'XObject should have a Name subtype');
  10155. if ('Form' !== type.name) {
  10156. xobjsCache.key = name;
  10157. xobjsCache.texts = null;
  10158. break;
  10159. }
  10160. stateManager.save();
  10161. var matrix = xobj.dict.get('Matrix');
  10162. if (isArray(matrix) && matrix.length === 6) {
  10163. stateManager.transform(matrix);
  10164. }
  10165. return self.getTextContent(xobj,
  10166. xobj.dict.get('Resources') || resources, stateManager).
  10167. then(function (formTextContent) {
  10168. Util.appendToArray(bidiTexts, formTextContent.items);
  10169. Util.extendObj(textContent.styles, formTextContent.styles);
  10170. stateManager.restore();
  10171. xobjsCache.key = name;
  10172. xobjsCache.texts = formTextContent;
  10173. next(resolve, reject);
  10174. }, reject);
  10175. case OPS.setGState:
  10176. var dictName = args[0];
  10177. var extGState = resources.get('ExtGState');
  10178. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10179. break;
  10180. }
  10181. var gsStateMap = extGState.get(dictName.name);
  10182. var gsStateFont = null;
  10183. for (var key in gsStateMap) {
  10184. if (key === 'Font') {
  10185. assert(!gsStateFont);
  10186. gsStateFont = gsStateMap[key];
  10187. }
  10188. }
  10189. if (gsStateFont) {
  10190. textState.fontSize = gsStateFont[1];
  10191. return handleSetFont(gsStateFont[0]).then(function() {
  10192. next(resolve, reject);
  10193. }, reject);
  10194. }
  10195. break;
  10196. } // switch
  10197. } // while
  10198. if (stop) {
  10199. deferred.then(function () {
  10200. next(resolve, reject);
  10201. });
  10202. return;
  10203. }
  10204. resolve(textContent);
  10205. });
  10206. },
  10207. extractDataStructures: function
  10208. partialEvaluatorExtractDataStructures(dict, baseDict,
  10209. xref, properties) {
  10210. // 9.10.2
  10211. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10212. if (toUnicode) {
  10213. properties.toUnicode = this.readToUnicode(toUnicode);
  10214. }
  10215. if (properties.composite) {
  10216. // CIDSystemInfo helps to match CID to glyphs
  10217. var cidSystemInfo = dict.get('CIDSystemInfo');
  10218. if (isDict(cidSystemInfo)) {
  10219. properties.cidSystemInfo = {
  10220. registry: cidSystemInfo.get('Registry'),
  10221. ordering: cidSystemInfo.get('Ordering'),
  10222. supplement: cidSystemInfo.get('Supplement')
  10223. };
  10224. }
  10225. var cidToGidMap = dict.get('CIDToGIDMap');
  10226. if (isStream(cidToGidMap)) {
  10227. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10228. }
  10229. }
  10230. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10231. // and depends on the font type. The base encoding and differences are
  10232. // read here, but the encoding that is actually used is chosen during
  10233. // glyph mapping in the font.
  10234. // TODO: Loading the built in encoding in the font would allow the
  10235. // differences to be merged in here not require us to hold on to it.
  10236. var differences = [];
  10237. var baseEncodingName = null;
  10238. var encoding;
  10239. if (dict.has('Encoding')) {
  10240. encoding = dict.get('Encoding');
  10241. if (isDict(encoding)) {
  10242. baseEncodingName = encoding.get('BaseEncoding');
  10243. baseEncodingName = (isName(baseEncodingName) ?
  10244. baseEncodingName.name : null);
  10245. // Load the differences between the base and original
  10246. if (encoding.has('Differences')) {
  10247. var diffEncoding = encoding.get('Differences');
  10248. var index = 0;
  10249. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10250. var data = diffEncoding[j];
  10251. if (isNum(data)) {
  10252. index = data;
  10253. } else {
  10254. differences[index++] = data.name;
  10255. }
  10256. }
  10257. }
  10258. } else if (isName(encoding)) {
  10259. baseEncodingName = encoding.name;
  10260. } else {
  10261. error('Encoding is not a Name nor a Dict');
  10262. }
  10263. // According to table 114 if the encoding is a named encoding it must be
  10264. // one of these predefined encodings.
  10265. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10266. baseEncodingName !== 'MacExpertEncoding' &&
  10267. baseEncodingName !== 'WinAnsiEncoding')) {
  10268. baseEncodingName = null;
  10269. }
  10270. }
  10271. if (baseEncodingName) {
  10272. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10273. } else {
  10274. encoding = (properties.type === 'TrueType' ?
  10275. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10276. // The Symbolic attribute can be misused for regular fonts
  10277. // Heuristic: we have to check if the font is a standard one also
  10278. if (!!(properties.flags & FontFlags.Symbolic)) {
  10279. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  10280. Encodings.SymbolSetEncoding :
  10281. Encodings.MacRomanEncoding);
  10282. }
  10283. properties.defaultEncoding = encoding;
  10284. }
  10285. properties.differences = differences;
  10286. properties.baseEncodingName = baseEncodingName;
  10287. properties.dict = dict;
  10288. },
  10289. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10290. var cmap, cmapObj = toUnicode;
  10291. if (isName(cmapObj)) {
  10292. cmap = CMapFactory.create(cmapObj,
  10293. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10294. return new ToUnicodeMap(cmap);
  10295. } else if (isStream(cmapObj)) {
  10296. cmap = CMapFactory.create(cmapObj,
  10297. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10298. // Convert UTF-16BE
  10299. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10300. // to iterate over all keys.
  10301. cmap.forEach(function(token, i) {
  10302. var str = [];
  10303. for (var k = 0; k < token.length; k += 2) {
  10304. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10305. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10306. str.push(w1);
  10307. continue;
  10308. }
  10309. k += 2;
  10310. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10311. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10312. }
  10313. cmap[i] = String.fromCharCode.apply(String, str);
  10314. });
  10315. return new ToUnicodeMap(cmap);
  10316. }
  10317. return null;
  10318. },
  10319. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10320. // Extract the encoding from the CIDToGIDMap
  10321. var glyphsData = cidToGidStream.getBytes();
  10322. // Set encoding 0 to later verify the font has an encoding
  10323. var result = [];
  10324. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10325. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10326. if (glyphID === 0) {
  10327. continue;
  10328. }
  10329. var code = j >> 1;
  10330. result[code] = glyphID;
  10331. }
  10332. return result;
  10333. },
  10334. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10335. descriptor,
  10336. properties) {
  10337. var glyphsWidths = [];
  10338. var defaultWidth = 0;
  10339. var glyphsVMetrics = [];
  10340. var defaultVMetrics;
  10341. var i, ii, j, jj, start, code, widths;
  10342. if (properties.composite) {
  10343. defaultWidth = dict.get('DW') || 1000;
  10344. widths = dict.get('W');
  10345. if (widths) {
  10346. for (i = 0, ii = widths.length; i < ii; i++) {
  10347. start = widths[i++];
  10348. code = xref.fetchIfRef(widths[i]);
  10349. if (isArray(code)) {
  10350. for (j = 0, jj = code.length; j < jj; j++) {
  10351. glyphsWidths[start++] = code[j];
  10352. }
  10353. } else {
  10354. var width = widths[++i];
  10355. for (j = start; j <= code; j++) {
  10356. glyphsWidths[j] = width;
  10357. }
  10358. }
  10359. }
  10360. }
  10361. if (properties.vertical) {
  10362. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10363. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10364. vmetrics = dict.get('W2');
  10365. if (vmetrics) {
  10366. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10367. start = vmetrics[i++];
  10368. code = xref.fetchIfRef(vmetrics[i]);
  10369. if (isArray(code)) {
  10370. for (j = 0, jj = code.length; j < jj; j++) {
  10371. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10372. }
  10373. } else {
  10374. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10375. for (j = start; j <= code; j++) {
  10376. glyphsVMetrics[j] = vmetric;
  10377. }
  10378. }
  10379. }
  10380. }
  10381. }
  10382. } else {
  10383. var firstChar = properties.firstChar;
  10384. widths = dict.get('Widths');
  10385. if (widths) {
  10386. j = firstChar;
  10387. for (i = 0, ii = widths.length; i < ii; i++) {
  10388. glyphsWidths[j++] = widths[i];
  10389. }
  10390. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10391. } else {
  10392. // Trying get the BaseFont metrics (see comment above).
  10393. var baseFontName = dict.get('BaseFont');
  10394. if (isName(baseFontName)) {
  10395. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10396. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10397. properties);
  10398. defaultWidth = metrics.defaultWidth;
  10399. }
  10400. }
  10401. }
  10402. // Heuristic: detection of monospace font by checking all non-zero widths
  10403. var isMonospace = true;
  10404. var firstWidth = defaultWidth;
  10405. for (var glyph in glyphsWidths) {
  10406. var glyphWidth = glyphsWidths[glyph];
  10407. if (!glyphWidth) {
  10408. continue;
  10409. }
  10410. if (!firstWidth) {
  10411. firstWidth = glyphWidth;
  10412. continue;
  10413. }
  10414. if (firstWidth !== glyphWidth) {
  10415. isMonospace = false;
  10416. break;
  10417. }
  10418. }
  10419. if (isMonospace) {
  10420. properties.flags |= FontFlags.FixedPitch;
  10421. }
  10422. properties.defaultWidth = defaultWidth;
  10423. properties.widths = glyphsWidths;
  10424. properties.defaultVMetrics = defaultVMetrics;
  10425. properties.vmetrics = glyphsVMetrics;
  10426. },
  10427. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10428. // Simulating descriptor flags attribute
  10429. var fontNameWoStyle = baseFontName.split('-')[0];
  10430. return (fontNameWoStyle in serifFonts) ||
  10431. (fontNameWoStyle.search(/serif/gi) !== -1);
  10432. },
  10433. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10434. var defaultWidth = 0;
  10435. var widths = [];
  10436. var monospace = false;
  10437. var lookupName = (stdFontMap[name] || name);
  10438. if (!(lookupName in Metrics)) {
  10439. // Use default fonts for looking up font metrics if the passed
  10440. // font is not a base font
  10441. if (this.isSerifFont(name)) {
  10442. lookupName = 'Times-Roman';
  10443. } else {
  10444. lookupName = 'Helvetica';
  10445. }
  10446. }
  10447. var glyphWidths = Metrics[lookupName];
  10448. if (isNum(glyphWidths)) {
  10449. defaultWidth = glyphWidths;
  10450. monospace = true;
  10451. } else {
  10452. widths = glyphWidths;
  10453. }
  10454. return {
  10455. defaultWidth: defaultWidth,
  10456. monospace: monospace,
  10457. widths: widths
  10458. };
  10459. },
  10460. buildCharCodeToWidth:
  10461. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10462. properties) {
  10463. var widths = Object.create(null);
  10464. var differences = properties.differences;
  10465. var encoding = properties.defaultEncoding;
  10466. for (var charCode = 0; charCode < 256; charCode++) {
  10467. if (charCode in differences &&
  10468. widthsByGlyphName[differences[charCode]]) {
  10469. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10470. continue;
  10471. }
  10472. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10473. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10474. continue;
  10475. }
  10476. }
  10477. return widths;
  10478. },
  10479. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10480. var baseDict = dict;
  10481. var type = dict.get('Subtype');
  10482. assert(isName(type), 'invalid font Subtype');
  10483. var composite = false;
  10484. var uint8array;
  10485. if (type.name === 'Type0') {
  10486. // If font is a composite
  10487. // - get the descendant font
  10488. // - set the type according to the descendant font
  10489. // - get the FontDescriptor from the descendant font
  10490. var df = dict.get('DescendantFonts');
  10491. if (!df) {
  10492. error('Descendant fonts are not specified');
  10493. }
  10494. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10495. type = dict.get('Subtype');
  10496. assert(isName(type), 'invalid font Subtype');
  10497. composite = true;
  10498. }
  10499. var descriptor = dict.get('FontDescriptor');
  10500. if (descriptor) {
  10501. var hash = new MurmurHash3_64();
  10502. var encoding = baseDict.getRaw('Encoding');
  10503. if (isName(encoding)) {
  10504. hash.update(encoding.name);
  10505. } else if (isRef(encoding)) {
  10506. hash.update(encoding.num + '_' + encoding.gen);
  10507. }
  10508. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10509. if (isStream(toUnicode)) {
  10510. var stream = toUnicode.str || toUnicode;
  10511. uint8array = stream.buffer ?
  10512. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10513. new Uint8Array(stream.bytes.buffer,
  10514. stream.start, stream.end - stream.start);
  10515. hash.update(uint8array);
  10516. } else if (isName(toUnicode)) {
  10517. hash.update(toUnicode.name);
  10518. }
  10519. var widths = dict.get('Widths') || baseDict.get('Widths');
  10520. if (widths) {
  10521. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10522. hash.update(uint8array);
  10523. }
  10524. }
  10525. return {
  10526. descriptor: descriptor,
  10527. dict: dict,
  10528. baseDict: baseDict,
  10529. composite: composite,
  10530. type: type.name,
  10531. hash: hash ? hash.hexdigest() : ''
  10532. };
  10533. },
  10534. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10535. xref) {
  10536. var baseDict = preEvaluatedFont.baseDict;
  10537. var dict = preEvaluatedFont.dict;
  10538. var composite = preEvaluatedFont.composite;
  10539. var descriptor = preEvaluatedFont.descriptor;
  10540. var type = preEvaluatedFont.type;
  10541. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  10542. var properties;
  10543. if (!descriptor) {
  10544. if (type === 'Type3') {
  10545. // FontDescriptor is only required for Type3 fonts when the document
  10546. // is a tagged pdf. Create a barbebones one to get by.
  10547. descriptor = new Dict(null);
  10548. descriptor.set('FontName', Name.get(type));
  10549. } else {
  10550. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  10551. // FontDescriptor was not required.
  10552. // This case is here for compatibility.
  10553. var baseFontName = dict.get('BaseFont');
  10554. if (!isName(baseFontName)) {
  10555. error('Base font is not specified');
  10556. }
  10557. // Using base font name as a font name.
  10558. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  10559. var metrics = this.getBaseFontMetrics(baseFontName);
  10560. // Simulating descriptor flags attribute
  10561. var fontNameWoStyle = baseFontName.split('-')[0];
  10562. var flags =
  10563. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  10564. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  10565. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  10566. FontFlags.Nonsymbolic);
  10567. properties = {
  10568. type: type,
  10569. name: baseFontName,
  10570. widths: metrics.widths,
  10571. defaultWidth: metrics.defaultWidth,
  10572. flags: flags,
  10573. firstChar: 0,
  10574. lastChar: maxCharIndex
  10575. };
  10576. this.extractDataStructures(dict, dict, xref, properties);
  10577. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  10578. properties);
  10579. return new Font(baseFontName, null, properties);
  10580. }
  10581. }
  10582. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  10583. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  10584. // to ignore this rule when a variant of a standart font is used.
  10585. // TODO Fill the width array depending on which of the base font this is
  10586. // a variant.
  10587. var firstChar = (dict.get('FirstChar') || 0);
  10588. var lastChar = (dict.get('LastChar') || maxCharIndex);
  10589. var fontName = descriptor.get('FontName');
  10590. var baseFont = dict.get('BaseFont');
  10591. // Some bad PDFs have a string as the font name.
  10592. if (isString(fontName)) {
  10593. fontName = Name.get(fontName);
  10594. }
  10595. if (isString(baseFont)) {
  10596. baseFont = Name.get(baseFont);
  10597. }
  10598. if (type !== 'Type3') {
  10599. var fontNameStr = fontName && fontName.name;
  10600. var baseFontStr = baseFont && baseFont.name;
  10601. if (fontNameStr !== baseFontStr) {
  10602. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  10603. '" but should be the same as the Font\'s BaseFont "' +
  10604. baseFontStr + '"');
  10605. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  10606. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  10607. if (fontNameStr && baseFontStr &&
  10608. baseFontStr.indexOf(fontNameStr) === 0) {
  10609. fontName = baseFont;
  10610. }
  10611. }
  10612. }
  10613. fontName = (fontName || baseFont);
  10614. assert(isName(fontName), 'invalid font name');
  10615. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  10616. if (fontFile) {
  10617. if (fontFile.dict) {
  10618. var subtype = fontFile.dict.get('Subtype');
  10619. if (subtype) {
  10620. subtype = subtype.name;
  10621. }
  10622. var length1 = fontFile.dict.get('Length1');
  10623. var length2 = fontFile.dict.get('Length2');
  10624. }
  10625. }
  10626. properties = {
  10627. type: type,
  10628. name: fontName.name,
  10629. subtype: subtype,
  10630. file: fontFile,
  10631. length1: length1,
  10632. length2: length2,
  10633. loadedName: baseDict.loadedName,
  10634. composite: composite,
  10635. wideChars: composite,
  10636. fixedPitch: false,
  10637. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  10638. firstChar: firstChar || 0,
  10639. lastChar: (lastChar || maxCharIndex),
  10640. bbox: descriptor.get('FontBBox'),
  10641. ascent: descriptor.get('Ascent'),
  10642. descent: descriptor.get('Descent'),
  10643. xHeight: descriptor.get('XHeight'),
  10644. capHeight: descriptor.get('CapHeight'),
  10645. flags: descriptor.get('Flags'),
  10646. italicAngle: descriptor.get('ItalicAngle'),
  10647. coded: false
  10648. };
  10649. if (composite) {
  10650. var cidEncoding = baseDict.get('Encoding');
  10651. if (isName(cidEncoding)) {
  10652. properties.cidEncoding = cidEncoding.name;
  10653. }
  10654. properties.cMap = CMapFactory.create(cidEncoding,
  10655. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10656. properties.vertical = properties.cMap.vertical;
  10657. }
  10658. this.extractDataStructures(dict, baseDict, xref, properties);
  10659. this.extractWidths(dict, xref, descriptor, properties);
  10660. if (type === 'Type3') {
  10661. properties.isType3Font = true;
  10662. }
  10663. return new Font(fontName.name, fontFile, properties);
  10664. }
  10665. };
  10666. return PartialEvaluator;
  10667. })();
  10668. var TranslatedFont = (function TranslatedFontClosure() {
  10669. function TranslatedFont(loadedName, font, dict) {
  10670. this.loadedName = loadedName;
  10671. this.font = font;
  10672. this.dict = dict;
  10673. this.type3Loaded = null;
  10674. this.sent = false;
  10675. }
  10676. TranslatedFont.prototype = {
  10677. send: function (handler) {
  10678. if (this.sent) {
  10679. return;
  10680. }
  10681. var fontData = this.font.exportData();
  10682. handler.send('commonobj', [
  10683. this.loadedName,
  10684. 'Font',
  10685. fontData
  10686. ]);
  10687. this.sent = true;
  10688. },
  10689. loadType3Data: function (evaluator, resources, parentOperatorList) {
  10690. assert(this.font.isType3Font);
  10691. if (this.type3Loaded) {
  10692. return this.type3Loaded;
  10693. }
  10694. var translatedFont = this.font;
  10695. var loadCharProcsPromise = Promise.resolve();
  10696. var charProcs = this.dict.get('CharProcs').getAll();
  10697. var fontResources = this.dict.get('Resources') || resources;
  10698. var charProcKeys = Object.keys(charProcs);
  10699. var charProcOperatorList = {};
  10700. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  10701. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  10702. var glyphStream = charProcs[key];
  10703. var operatorList = new OperatorList();
  10704. return evaluator.getOperatorList(glyphStream, fontResources,
  10705. operatorList).then(function () {
  10706. charProcOperatorList[key] = operatorList.getIR();
  10707. // Add the dependencies to the parent operator list so they are
  10708. // resolved before sub operator list is executed synchronously.
  10709. parentOperatorList.addDependencies(operatorList.dependencies);
  10710. }, function (reason) {
  10711. warn('Type3 font resource \"' + key + '\" is not available');
  10712. var operatorList = new OperatorList();
  10713. charProcOperatorList[key] = operatorList.getIR();
  10714. });
  10715. }.bind(this, charProcKeys[i]));
  10716. }
  10717. this.type3Loaded = loadCharProcsPromise.then(function () {
  10718. translatedFont.charProcOperatorList = charProcOperatorList;
  10719. });
  10720. return this.type3Loaded;
  10721. }
  10722. };
  10723. return TranslatedFont;
  10724. })();
  10725. var OperatorList = (function OperatorListClosure() {
  10726. var CHUNK_SIZE = 1000;
  10727. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  10728. function getTransfers(queue) {
  10729. var transfers = [];
  10730. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  10731. for (var i = 0, ii = queue.length; i < ii; i++) {
  10732. switch (fnArray[i]) {
  10733. case OPS.paintInlineImageXObject:
  10734. case OPS.paintInlineImageXObjectGroup:
  10735. case OPS.paintImageMaskXObject:
  10736. var arg = argsArray[i][0]; // first param in imgData
  10737. if (!arg.cached) {
  10738. transfers.push(arg.data.buffer);
  10739. }
  10740. break;
  10741. }
  10742. }
  10743. return transfers;
  10744. }
  10745. function OperatorList(intent, messageHandler, pageIndex) {
  10746. this.messageHandler = messageHandler;
  10747. this.fnArray = [];
  10748. this.argsArray = [];
  10749. this.dependencies = {};
  10750. this.pageIndex = pageIndex;
  10751. this.intent = intent;
  10752. }
  10753. OperatorList.prototype = {
  10754. get length() {
  10755. return this.argsArray.length;
  10756. },
  10757. addOp: function(fn, args) {
  10758. this.fnArray.push(fn);
  10759. this.argsArray.push(args);
  10760. if (this.messageHandler) {
  10761. if (this.fnArray.length >= CHUNK_SIZE) {
  10762. this.flush();
  10763. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  10764. (fn === OPS.restore || fn === OPS.endText)) {
  10765. // heuristic to flush on boundary of restore or endText
  10766. this.flush();
  10767. }
  10768. }
  10769. },
  10770. addDependency: function(dependency) {
  10771. if (dependency in this.dependencies) {
  10772. return;
  10773. }
  10774. this.dependencies[dependency] = true;
  10775. this.addOp(OPS.dependency, [dependency]);
  10776. },
  10777. addDependencies: function(dependencies) {
  10778. for (var key in dependencies) {
  10779. this.addDependency(key);
  10780. }
  10781. },
  10782. addOpList: function(opList) {
  10783. Util.extendObj(this.dependencies, opList.dependencies);
  10784. for (var i = 0, ii = opList.length; i < ii; i++) {
  10785. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  10786. }
  10787. },
  10788. getIR: function() {
  10789. return {
  10790. fnArray: this.fnArray,
  10791. argsArray: this.argsArray,
  10792. length: this.length
  10793. };
  10794. },
  10795. flush: function(lastChunk) {
  10796. if (this.intent !== 'oplist') {
  10797. new QueueOptimizer().optimize(this);
  10798. }
  10799. var transfers = getTransfers(this);
  10800. this.messageHandler.send('RenderPageChunk', {
  10801. operatorList: {
  10802. fnArray: this.fnArray,
  10803. argsArray: this.argsArray,
  10804. lastChunk: lastChunk,
  10805. length: this.length
  10806. },
  10807. pageIndex: this.pageIndex,
  10808. intent: this.intent
  10809. }, transfers);
  10810. this.dependencies = {};
  10811. this.fnArray.length = 0;
  10812. this.argsArray.length = 0;
  10813. }
  10814. };
  10815. return OperatorList;
  10816. })();
  10817. var StateManager = (function StateManagerClosure() {
  10818. function StateManager(initialState) {
  10819. this.state = initialState;
  10820. this.stateStack = [];
  10821. }
  10822. StateManager.prototype = {
  10823. save: function () {
  10824. var old = this.state;
  10825. this.stateStack.push(this.state);
  10826. this.state = old.clone();
  10827. },
  10828. restore: function () {
  10829. var prev = this.stateStack.pop();
  10830. if (prev) {
  10831. this.state = prev;
  10832. }
  10833. },
  10834. transform: function (args) {
  10835. this.state.ctm = Util.transform(this.state.ctm, args);
  10836. }
  10837. };
  10838. return StateManager;
  10839. })();
  10840. var TextState = (function TextStateClosure() {
  10841. function TextState() {
  10842. this.ctm = new Float32Array(IDENTITY_MATRIX);
  10843. this.fontSize = 0;
  10844. this.font = null;
  10845. this.fontMatrix = FONT_IDENTITY_MATRIX;
  10846. this.textMatrix = IDENTITY_MATRIX.slice();
  10847. this.textLineMatrix = IDENTITY_MATRIX.slice();
  10848. this.charSpacing = 0;
  10849. this.wordSpacing = 0;
  10850. this.leading = 0;
  10851. this.textHScale = 1;
  10852. this.textRise = 0;
  10853. }
  10854. TextState.prototype = {
  10855. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  10856. var m = this.textMatrix;
  10857. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  10858. },
  10859. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  10860. var m = this.textLineMatrix;
  10861. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  10862. },
  10863. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  10864. var m = this.textMatrix;
  10865. m[4] = m[0] * x + m[2] * y + m[4];
  10866. m[5] = m[1] * x + m[3] * y + m[5];
  10867. },
  10868. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  10869. var m = this.textLineMatrix;
  10870. m[4] = m[0] * x + m[2] * y + m[4];
  10871. m[5] = m[1] * x + m[3] * y + m[5];
  10872. },
  10873. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  10874. // 9.4.4 Text Space Details
  10875. var tsm = [this.fontSize * this.textHScale, 0,
  10876. 0, this.fontSize,
  10877. 0, this.textRise];
  10878. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  10879. },
  10880. carriageReturn: function TextState_carriageReturn() {
  10881. this.translateTextLineMatrix(0, -this.leading);
  10882. this.textMatrix = this.textLineMatrix.slice();
  10883. },
  10884. clone: function TextState_clone() {
  10885. var clone = Object.create(this);
  10886. clone.textMatrix = this.textMatrix.slice();
  10887. clone.textLineMatrix = this.textLineMatrix.slice();
  10888. clone.fontMatrix = this.fontMatrix.slice();
  10889. return clone;
  10890. }
  10891. };
  10892. return TextState;
  10893. })();
  10894. var EvalState = (function EvalStateClosure() {
  10895. function EvalState() {
  10896. this.ctm = new Float32Array(IDENTITY_MATRIX);
  10897. this.font = null;
  10898. this.textRenderingMode = TextRenderingMode.FILL;
  10899. this.fillColorSpace = ColorSpace.singletons.gray;
  10900. this.strokeColorSpace = ColorSpace.singletons.gray;
  10901. }
  10902. EvalState.prototype = {
  10903. clone: function CanvasExtraState_clone() {
  10904. return Object.create(this);
  10905. },
  10906. };
  10907. return EvalState;
  10908. })();
  10909. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  10910. // Specifies properties for each command
  10911. //
  10912. // If variableArgs === true: [0, `numArgs`] expected
  10913. // If variableArgs === false: exactly `numArgs` expected
  10914. var OP_MAP = {
  10915. // Graphic state
  10916. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  10917. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  10918. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  10919. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  10920. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  10921. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  10922. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  10923. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  10924. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  10925. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  10926. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  10927. // Path
  10928. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  10929. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  10930. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  10931. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  10932. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  10933. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  10934. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  10935. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  10936. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  10937. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  10938. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  10939. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  10940. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  10941. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  10942. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  10943. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  10944. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  10945. // Clipping
  10946. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  10947. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  10948. // Text
  10949. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  10950. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  10951. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  10952. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  10953. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  10954. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  10955. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  10956. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  10957. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  10958. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  10959. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  10960. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  10961. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  10962. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  10963. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  10964. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  10965. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  10966. variableArgs: false },
  10967. // Type3 fonts
  10968. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  10969. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  10970. // Color
  10971. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  10972. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  10973. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  10974. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  10975. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  10976. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  10977. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  10978. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  10979. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  10980. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  10981. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  10982. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  10983. // Shading
  10984. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  10985. // Images
  10986. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  10987. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  10988. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  10989. // XObjects
  10990. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  10991. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  10992. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  10993. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  10994. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  10995. variableArgs: false },
  10996. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  10997. // Compatibility
  10998. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  10999. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11000. // (reserved partial commands for the lexer)
  11001. BM: null,
  11002. BD: null,
  11003. 'true': null,
  11004. fa: null,
  11005. fal: null,
  11006. fals: null,
  11007. 'false': null,
  11008. nu: null,
  11009. nul: null,
  11010. 'null': null
  11011. };
  11012. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11013. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11014. // dictionary
  11015. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11016. this.stateManager = stateManager;
  11017. this.nonProcessedArgs = [];
  11018. }
  11019. EvaluatorPreprocessor.prototype = {
  11020. get savedStatesDepth() {
  11021. return this.stateManager.stateStack.length;
  11022. },
  11023. read: function EvaluatorPreprocessor_read(operation) {
  11024. // We use an array to represent args, except we use |null| to represent
  11025. // no args because it's more compact than an empty array.
  11026. var args = null;
  11027. while (true) {
  11028. var obj = this.parser.getObj();
  11029. if (isCmd(obj)) {
  11030. var cmd = obj.cmd;
  11031. // Check that the command is valid
  11032. var opSpec = OP_MAP[cmd];
  11033. if (!opSpec) {
  11034. warn('Unknown command "' + cmd + '"');
  11035. continue;
  11036. }
  11037. var fn = opSpec.id;
  11038. var numArgs = opSpec.numArgs;
  11039. var argsLength = args !== null ? args.length : 0;
  11040. if (!opSpec.variableArgs) {
  11041. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11042. if (argsLength !== numArgs) {
  11043. var nonProcessedArgs = this.nonProcessedArgs;
  11044. while (argsLength > numArgs) {
  11045. nonProcessedArgs.push(args.shift());
  11046. argsLength--;
  11047. }
  11048. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11049. if (!args) {
  11050. args = [];
  11051. }
  11052. args.unshift(nonProcessedArgs.pop());
  11053. argsLength++;
  11054. }
  11055. }
  11056. if (argsLength < numArgs) {
  11057. // If we receive too few args, it's not possible to possible
  11058. // to execute the command, so skip the command
  11059. info('Command ' + fn + ': because expected ' +
  11060. numArgs + ' args, but received ' + argsLength +
  11061. ' args; skipping');
  11062. args = null;
  11063. continue;
  11064. }
  11065. } else if (argsLength > numArgs) {
  11066. info('Command ' + fn + ': expected [0,' + numArgs +
  11067. '] args, but received ' + argsLength + ' args');
  11068. }
  11069. // TODO figure out how to type-check vararg functions
  11070. this.preprocessCommand(fn, args);
  11071. operation.fn = fn;
  11072. operation.args = args;
  11073. return true;
  11074. } else {
  11075. if (isEOF(obj)) {
  11076. return false; // no more commands
  11077. }
  11078. // argument
  11079. if (obj !== null) {
  11080. if (!args) {
  11081. args = [];
  11082. }
  11083. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11084. assert(args.length <= 33, 'Too many arguments');
  11085. }
  11086. }
  11087. }
  11088. },
  11089. preprocessCommand:
  11090. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11091. switch (fn | 0) {
  11092. case OPS.save:
  11093. this.stateManager.save();
  11094. break;
  11095. case OPS.restore:
  11096. this.stateManager.restore();
  11097. break;
  11098. case OPS.transform:
  11099. this.stateManager.transform(args);
  11100. break;
  11101. }
  11102. }
  11103. };
  11104. return EvaluatorPreprocessor;
  11105. })();
  11106. var QueueOptimizer = (function QueueOptimizerClosure() {
  11107. function addState(parentState, pattern, fn) {
  11108. var state = parentState;
  11109. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11110. var item = pattern[i];
  11111. state = (state[item] || (state[item] = []));
  11112. }
  11113. state[pattern[pattern.length - 1]] = fn;
  11114. }
  11115. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11116. argsArray) {
  11117. // Handles special case of mainly LaTeX documents which use image masks to
  11118. // draw lines with the current fill style.
  11119. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11120. // have been found at iFirstSave.
  11121. var iFirstPIMXO = iFirstSave + 2;
  11122. for (var i = 0; i < count; i++) {
  11123. var arg = argsArray[iFirstPIMXO + 4 * i];
  11124. var imageMask = arg.length === 1 && arg[0];
  11125. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11126. (!imageMask.data.length ||
  11127. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11128. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11129. continue;
  11130. }
  11131. break;
  11132. }
  11133. return count - i;
  11134. }
  11135. var InitialState = [];
  11136. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11137. // sequences with one |paintInlineImageXObjectGroup| operation.
  11138. addState(InitialState,
  11139. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11140. function foundInlineImageGroup(context) {
  11141. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11142. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11143. var MAX_WIDTH = 1000;
  11144. var IMAGE_PADDING = 1;
  11145. var fnArray = context.fnArray, argsArray = context.argsArray;
  11146. var curr = context.iCurr;
  11147. var iFirstSave = curr - 3;
  11148. var iFirstTransform = curr - 2;
  11149. var iFirstPIIXO = curr - 1;
  11150. // Look for the quartets.
  11151. var i = iFirstSave + 4;
  11152. var ii = fnArray.length;
  11153. while (i + 3 < ii) {
  11154. if (fnArray[i] !== OPS.save ||
  11155. fnArray[i + 1] !== OPS.transform ||
  11156. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11157. fnArray[i + 3] !== OPS.restore) {
  11158. break; // ops don't match
  11159. }
  11160. i += 4;
  11161. }
  11162. // At this point, i is the index of the first op past the last valid
  11163. // quartet.
  11164. var count = Math.min((i - iFirstSave) / 4,
  11165. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11166. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11167. return i;
  11168. }
  11169. // assuming that heights of those image is too small (~1 pixel)
  11170. // packing as much as possible by lines
  11171. var maxX = 0;
  11172. var map = [], maxLineHeight = 0;
  11173. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11174. var q;
  11175. for (q = 0; q < count; q++) {
  11176. var transform = argsArray[iFirstTransform + (q << 2)];
  11177. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11178. if (currentX + img.width > MAX_WIDTH) {
  11179. // starting new line
  11180. maxX = Math.max(maxX, currentX);
  11181. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11182. currentX = 0;
  11183. maxLineHeight = 0;
  11184. }
  11185. map.push({
  11186. transform: transform,
  11187. x: currentX, y: currentY,
  11188. w: img.width, h: img.height
  11189. });
  11190. currentX += img.width + 2 * IMAGE_PADDING;
  11191. maxLineHeight = Math.max(maxLineHeight, img.height);
  11192. }
  11193. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11194. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11195. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11196. var imgRowSize = imgWidth << 2;
  11197. for (q = 0; q < count; q++) {
  11198. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11199. // Copy image by lines and extends pixels into padding.
  11200. var rowSize = map[q].w << 2;
  11201. var dataOffset = 0;
  11202. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11203. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11204. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11205. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11206. dataOffset += rowSize;
  11207. offset += imgRowSize;
  11208. }
  11209. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11210. while (offset >= 0) {
  11211. data[offset - 4] = data[offset];
  11212. data[offset - 3] = data[offset + 1];
  11213. data[offset - 2] = data[offset + 2];
  11214. data[offset - 1] = data[offset + 3];
  11215. data[offset + rowSize] = data[offset + rowSize - 4];
  11216. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11217. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11218. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11219. offset -= imgRowSize;
  11220. }
  11221. }
  11222. // Replace queue items.
  11223. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11224. argsArray.splice(iFirstSave, count * 4,
  11225. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11226. data: imgData }, map]);
  11227. return iFirstSave + 1;
  11228. });
  11229. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11230. // sequences with one |paintImageMaskXObjectGroup| or one
  11231. // |paintImageMaskXObjectRepeat| operation.
  11232. addState(InitialState,
  11233. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11234. function foundImageMaskGroup(context) {
  11235. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11236. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11237. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11238. var fnArray = context.fnArray, argsArray = context.argsArray;
  11239. var curr = context.iCurr;
  11240. var iFirstSave = curr - 3;
  11241. var iFirstTransform = curr - 2;
  11242. var iFirstPIMXO = curr - 1;
  11243. // Look for the quartets.
  11244. var i = iFirstSave + 4;
  11245. var ii = fnArray.length;
  11246. while (i + 3 < ii) {
  11247. if (fnArray[i] !== OPS.save ||
  11248. fnArray[i + 1] !== OPS.transform ||
  11249. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11250. fnArray[i + 3] !== OPS.restore) {
  11251. break; // ops don't match
  11252. }
  11253. i += 4;
  11254. }
  11255. // At this point, i is the index of the first op past the last valid
  11256. // quartet.
  11257. var count = (i - iFirstSave) / 4;
  11258. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11259. argsArray);
  11260. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11261. return i;
  11262. }
  11263. var q;
  11264. var isSameImage = false;
  11265. var iTransform, transformArgs;
  11266. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11267. if (argsArray[iFirstTransform][1] === 0 &&
  11268. argsArray[iFirstTransform][2] === 0) {
  11269. isSameImage = true;
  11270. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11271. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11272. iTransform = iFirstTransform + 4;
  11273. var iPIMXO = iFirstPIMXO + 4;
  11274. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11275. transformArgs = argsArray[iTransform];
  11276. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11277. transformArgs[0] !== firstTransformArg0 ||
  11278. transformArgs[1] !== 0 ||
  11279. transformArgs[2] !== 0 ||
  11280. transformArgs[3] !== firstTransformArg3) {
  11281. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11282. isSameImage = false;
  11283. } else {
  11284. count = q;
  11285. }
  11286. break; // different image or transform
  11287. }
  11288. }
  11289. }
  11290. if (isSameImage) {
  11291. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11292. var positions = new Float32Array(count * 2);
  11293. iTransform = iFirstTransform;
  11294. for (q = 0; q < count; q++, iTransform += 4) {
  11295. transformArgs = argsArray[iTransform];
  11296. positions[(q << 1)] = transformArgs[4];
  11297. positions[(q << 1) + 1] = transformArgs[5];
  11298. }
  11299. // Replace queue items.
  11300. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11301. argsArray.splice(iFirstSave, count * 4,
  11302. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11303. } else {
  11304. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11305. var images = [];
  11306. for (q = 0; q < count; q++) {
  11307. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11308. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11309. images.push({ data: maskParams.data, width: maskParams.width,
  11310. height: maskParams.height,
  11311. transform: transformArgs });
  11312. }
  11313. // Replace queue items.
  11314. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11315. argsArray.splice(iFirstSave, count * 4, [images]);
  11316. }
  11317. return iFirstSave + 1;
  11318. });
  11319. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11320. // with one paintImageXObjectRepeat operation, if the |transform| and
  11321. // |paintImageXObjectRepeat| ops are appropriate.
  11322. addState(InitialState,
  11323. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11324. function (context) {
  11325. var MIN_IMAGES_IN_BLOCK = 3;
  11326. var MAX_IMAGES_IN_BLOCK = 1000;
  11327. var fnArray = context.fnArray, argsArray = context.argsArray;
  11328. var curr = context.iCurr;
  11329. var iFirstSave = curr - 3;
  11330. var iFirstTransform = curr - 2;
  11331. var iFirstPIXO = curr - 1;
  11332. var iFirstRestore = curr;
  11333. if (argsArray[iFirstTransform][1] !== 0 ||
  11334. argsArray[iFirstTransform][2] !== 0) {
  11335. return iFirstRestore + 1; // transform has the wrong form
  11336. }
  11337. // Look for the quartets.
  11338. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11339. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11340. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11341. var i = iFirstSave + 4;
  11342. var ii = fnArray.length;
  11343. while (i + 3 < ii) {
  11344. if (fnArray[i] !== OPS.save ||
  11345. fnArray[i + 1] !== OPS.transform ||
  11346. fnArray[i + 2] !== OPS.paintImageXObject ||
  11347. fnArray[i + 3] !== OPS.restore) {
  11348. break; // ops don't match
  11349. }
  11350. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11351. argsArray[i + 1][1] !== 0 ||
  11352. argsArray[i + 1][2] !== 0 ||
  11353. argsArray[i + 1][3] !== firstTransformArg3) {
  11354. break; // transforms don't match
  11355. }
  11356. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11357. break; // images don't match
  11358. }
  11359. i += 4;
  11360. }
  11361. // At this point, i is the index of the first op past the last valid
  11362. // quartet.
  11363. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11364. if (count < MIN_IMAGES_IN_BLOCK) {
  11365. return i;
  11366. }
  11367. // Extract the (x,y) positions from all of the matching transforms.
  11368. var positions = new Float32Array(count * 2);
  11369. var iTransform = iFirstTransform;
  11370. for (var q = 0; q < count; q++, iTransform += 4) {
  11371. var transformArgs = argsArray[iTransform];
  11372. positions[(q << 1)] = transformArgs[4];
  11373. positions[(q << 1) + 1] = transformArgs[5];
  11374. }
  11375. // Replace queue items.
  11376. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11377. positions];
  11378. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11379. argsArray.splice(iFirstSave, count * 4, args);
  11380. return iFirstSave + 1;
  11381. });
  11382. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11383. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11384. // sequences, if the font for each one is the same.
  11385. addState(InitialState,
  11386. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11387. function (context) {
  11388. var MIN_CHARS_IN_BLOCK = 3;
  11389. var MAX_CHARS_IN_BLOCK = 1000;
  11390. var fnArray = context.fnArray, argsArray = context.argsArray;
  11391. var curr = context.iCurr;
  11392. var iFirstBeginText = curr - 4;
  11393. var iFirstSetFont = curr - 3;
  11394. var iFirstSetTextMatrix = curr - 2;
  11395. var iFirstShowText = curr - 1;
  11396. var iFirstEndText = curr;
  11397. // Look for the quintets.
  11398. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11399. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11400. var i = iFirstBeginText + 5;
  11401. var ii = fnArray.length;
  11402. while (i + 4 < ii) {
  11403. if (fnArray[i] !== OPS.beginText ||
  11404. fnArray[i + 1] !== OPS.setFont ||
  11405. fnArray[i + 2] !== OPS.setTextMatrix ||
  11406. fnArray[i + 3] !== OPS.showText ||
  11407. fnArray[i + 4] !== OPS.endText) {
  11408. break; // ops don't match
  11409. }
  11410. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11411. argsArray[i + 1][1] !== firstSetFontArg1) {
  11412. break; // fonts don't match
  11413. }
  11414. i += 5;
  11415. }
  11416. // At this point, i is the index of the first op past the last valid
  11417. // quintet.
  11418. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11419. if (count < MIN_CHARS_IN_BLOCK) {
  11420. return i;
  11421. }
  11422. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11423. // showText, endText), include that as well. (E.g. <something> might be
  11424. // |dependency|.)
  11425. var iFirst = iFirstBeginText;
  11426. if (iFirstBeginText >= 4 &&
  11427. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11428. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11429. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11430. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11431. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11432. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11433. count++;
  11434. iFirst -= 5;
  11435. }
  11436. // Remove (endText, beginText, setFont) trios.
  11437. var iEndText = iFirst + 4;
  11438. for (var q = 1; q < count; q++) {
  11439. fnArray.splice(iEndText, 3);
  11440. argsArray.splice(iEndText, 3);
  11441. iEndText += 2;
  11442. }
  11443. return iEndText + 1;
  11444. });
  11445. function QueueOptimizer() {}
  11446. QueueOptimizer.prototype = {
  11447. optimize: function QueueOptimizer_optimize(queue) {
  11448. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11449. var context = {
  11450. iCurr: 0,
  11451. fnArray: fnArray,
  11452. argsArray: argsArray
  11453. };
  11454. var state;
  11455. var i = 0, ii = fnArray.length;
  11456. while (i < ii) {
  11457. state = (state || InitialState)[fnArray[i]];
  11458. if (typeof state === 'function') { // we found some handler
  11459. context.iCurr = i;
  11460. // state() returns the index of the first non-matching op (if we
  11461. // didn't match) or the first op past the modified ops (if we did
  11462. // match and replace).
  11463. i = state(context);
  11464. state = undefined; // reset the state machine
  11465. ii = context.fnArray.length;
  11466. } else {
  11467. i++;
  11468. }
  11469. }
  11470. }
  11471. };
  11472. return QueueOptimizer;
  11473. })();
  11474. var BUILT_IN_CMAPS = [
  11475. // << Start unicode maps.
  11476. 'Adobe-GB1-UCS2',
  11477. 'Adobe-CNS1-UCS2',
  11478. 'Adobe-Japan1-UCS2',
  11479. 'Adobe-Korea1-UCS2',
  11480. // >> End unicode maps.
  11481. '78-EUC-H',
  11482. '78-EUC-V',
  11483. '78-H',
  11484. '78-RKSJ-H',
  11485. '78-RKSJ-V',
  11486. '78-V',
  11487. '78ms-RKSJ-H',
  11488. '78ms-RKSJ-V',
  11489. '83pv-RKSJ-H',
  11490. '90ms-RKSJ-H',
  11491. '90ms-RKSJ-V',
  11492. '90msp-RKSJ-H',
  11493. '90msp-RKSJ-V',
  11494. '90pv-RKSJ-H',
  11495. '90pv-RKSJ-V',
  11496. 'Add-H',
  11497. 'Add-RKSJ-H',
  11498. 'Add-RKSJ-V',
  11499. 'Add-V',
  11500. 'Adobe-CNS1-0',
  11501. 'Adobe-CNS1-1',
  11502. 'Adobe-CNS1-2',
  11503. 'Adobe-CNS1-3',
  11504. 'Adobe-CNS1-4',
  11505. 'Adobe-CNS1-5',
  11506. 'Adobe-CNS1-6',
  11507. 'Adobe-GB1-0',
  11508. 'Adobe-GB1-1',
  11509. 'Adobe-GB1-2',
  11510. 'Adobe-GB1-3',
  11511. 'Adobe-GB1-4',
  11512. 'Adobe-GB1-5',
  11513. 'Adobe-Japan1-0',
  11514. 'Adobe-Japan1-1',
  11515. 'Adobe-Japan1-2',
  11516. 'Adobe-Japan1-3',
  11517. 'Adobe-Japan1-4',
  11518. 'Adobe-Japan1-5',
  11519. 'Adobe-Japan1-6',
  11520. 'Adobe-Korea1-0',
  11521. 'Adobe-Korea1-1',
  11522. 'Adobe-Korea1-2',
  11523. 'B5-H',
  11524. 'B5-V',
  11525. 'B5pc-H',
  11526. 'B5pc-V',
  11527. 'CNS-EUC-H',
  11528. 'CNS-EUC-V',
  11529. 'CNS1-H',
  11530. 'CNS1-V',
  11531. 'CNS2-H',
  11532. 'CNS2-V',
  11533. 'ETHK-B5-H',
  11534. 'ETHK-B5-V',
  11535. 'ETen-B5-H',
  11536. 'ETen-B5-V',
  11537. 'ETenms-B5-H',
  11538. 'ETenms-B5-V',
  11539. 'EUC-H',
  11540. 'EUC-V',
  11541. 'Ext-H',
  11542. 'Ext-RKSJ-H',
  11543. 'Ext-RKSJ-V',
  11544. 'Ext-V',
  11545. 'GB-EUC-H',
  11546. 'GB-EUC-V',
  11547. 'GB-H',
  11548. 'GB-V',
  11549. 'GBK-EUC-H',
  11550. 'GBK-EUC-V',
  11551. 'GBK2K-H',
  11552. 'GBK2K-V',
  11553. 'GBKp-EUC-H',
  11554. 'GBKp-EUC-V',
  11555. 'GBT-EUC-H',
  11556. 'GBT-EUC-V',
  11557. 'GBT-H',
  11558. 'GBT-V',
  11559. 'GBTpc-EUC-H',
  11560. 'GBTpc-EUC-V',
  11561. 'GBpc-EUC-H',
  11562. 'GBpc-EUC-V',
  11563. 'H',
  11564. 'HKdla-B5-H',
  11565. 'HKdla-B5-V',
  11566. 'HKdlb-B5-H',
  11567. 'HKdlb-B5-V',
  11568. 'HKgccs-B5-H',
  11569. 'HKgccs-B5-V',
  11570. 'HKm314-B5-H',
  11571. 'HKm314-B5-V',
  11572. 'HKm471-B5-H',
  11573. 'HKm471-B5-V',
  11574. 'HKscs-B5-H',
  11575. 'HKscs-B5-V',
  11576. 'Hankaku',
  11577. 'Hiragana',
  11578. 'KSC-EUC-H',
  11579. 'KSC-EUC-V',
  11580. 'KSC-H',
  11581. 'KSC-Johab-H',
  11582. 'KSC-Johab-V',
  11583. 'KSC-V',
  11584. 'KSCms-UHC-H',
  11585. 'KSCms-UHC-HW-H',
  11586. 'KSCms-UHC-HW-V',
  11587. 'KSCms-UHC-V',
  11588. 'KSCpc-EUC-H',
  11589. 'KSCpc-EUC-V',
  11590. 'Katakana',
  11591. 'NWP-H',
  11592. 'NWP-V',
  11593. 'RKSJ-H',
  11594. 'RKSJ-V',
  11595. 'Roman',
  11596. 'UniCNS-UCS2-H',
  11597. 'UniCNS-UCS2-V',
  11598. 'UniCNS-UTF16-H',
  11599. 'UniCNS-UTF16-V',
  11600. 'UniCNS-UTF32-H',
  11601. 'UniCNS-UTF32-V',
  11602. 'UniCNS-UTF8-H',
  11603. 'UniCNS-UTF8-V',
  11604. 'UniGB-UCS2-H',
  11605. 'UniGB-UCS2-V',
  11606. 'UniGB-UTF16-H',
  11607. 'UniGB-UTF16-V',
  11608. 'UniGB-UTF32-H',
  11609. 'UniGB-UTF32-V',
  11610. 'UniGB-UTF8-H',
  11611. 'UniGB-UTF8-V',
  11612. 'UniJIS-UCS2-H',
  11613. 'UniJIS-UCS2-HW-H',
  11614. 'UniJIS-UCS2-HW-V',
  11615. 'UniJIS-UCS2-V',
  11616. 'UniJIS-UTF16-H',
  11617. 'UniJIS-UTF16-V',
  11618. 'UniJIS-UTF32-H',
  11619. 'UniJIS-UTF32-V',
  11620. 'UniJIS-UTF8-H',
  11621. 'UniJIS-UTF8-V',
  11622. 'UniJIS2004-UTF16-H',
  11623. 'UniJIS2004-UTF16-V',
  11624. 'UniJIS2004-UTF32-H',
  11625. 'UniJIS2004-UTF32-V',
  11626. 'UniJIS2004-UTF8-H',
  11627. 'UniJIS2004-UTF8-V',
  11628. 'UniJISPro-UCS2-HW-V',
  11629. 'UniJISPro-UCS2-V',
  11630. 'UniJISPro-UTF8-V',
  11631. 'UniJISX0213-UTF32-H',
  11632. 'UniJISX0213-UTF32-V',
  11633. 'UniJISX02132004-UTF32-H',
  11634. 'UniJISX02132004-UTF32-V',
  11635. 'UniKS-UCS2-H',
  11636. 'UniKS-UCS2-V',
  11637. 'UniKS-UTF16-H',
  11638. 'UniKS-UTF16-V',
  11639. 'UniKS-UTF32-H',
  11640. 'UniKS-UTF32-V',
  11641. 'UniKS-UTF8-H',
  11642. 'UniKS-UTF8-V',
  11643. 'V',
  11644. 'WP-Symbol'];
  11645. // CMap, not to be confused with TrueType's cmap.
  11646. var CMap = (function CMapClosure() {
  11647. function CMap(builtInCMap) {
  11648. // Codespace ranges are stored as follows:
  11649. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  11650. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  11651. this.codespaceRanges = [[], [], [], []];
  11652. this.numCodespaceRanges = 0;
  11653. // Map entries have one of two forms.
  11654. // - cid chars are 16-bit unsigned integers, stored as integers.
  11655. // - bf chars are variable-length byte sequences, stored as strings, with
  11656. // one byte per character.
  11657. this._map = [];
  11658. this.vertical = false;
  11659. this.useCMap = null;
  11660. this.builtInCMap = builtInCMap;
  11661. }
  11662. CMap.prototype = {
  11663. addCodespaceRange: function(n, low, high) {
  11664. this.codespaceRanges[n - 1].push(low, high);
  11665. this.numCodespaceRanges++;
  11666. },
  11667. mapCidRange: function(low, high, dstLow) {
  11668. while (low <= high) {
  11669. this._map[low++] = dstLow++;
  11670. }
  11671. },
  11672. mapBfRange: function(low, high, dstLow) {
  11673. var lastByte = dstLow.length - 1;
  11674. while (low <= high) {
  11675. this._map[low++] = dstLow;
  11676. // Only the last byte has to be incremented.
  11677. dstLow = dstLow.substr(0, lastByte) +
  11678. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  11679. }
  11680. },
  11681. mapBfRangeToArray: function(low, high, array) {
  11682. var i = 0, ii = array.length;
  11683. while (low <= high && i < ii) {
  11684. this._map[low] = array[i++];
  11685. ++low;
  11686. }
  11687. },
  11688. // This is used for both bf and cid chars.
  11689. mapOne: function(src, dst) {
  11690. this._map[src] = dst;
  11691. },
  11692. lookup: function(code) {
  11693. return this._map[code];
  11694. },
  11695. contains: function(code) {
  11696. return this._map[code] !== undefined;
  11697. },
  11698. forEach: function(callback) {
  11699. // Most maps have fewer than 65536 entries, and for those we use normal
  11700. // array iteration. But really sparse tables are possible -- e.g. with
  11701. // indices in the *billions*. For such tables we use for..in, which isn't
  11702. // ideal because it stringifies the indices for all present elements, but
  11703. // it does avoid iterating over every undefined entry.
  11704. var map = this._map;
  11705. var length = map.length;
  11706. var i;
  11707. if (length <= 0x10000) {
  11708. for (i = 0; i < length; i++) {
  11709. if (map[i] !== undefined) {
  11710. callback(i, map[i]);
  11711. }
  11712. }
  11713. } else {
  11714. for (i in this._map) {
  11715. callback(i, map[i]);
  11716. }
  11717. }
  11718. },
  11719. charCodeOf: function(value) {
  11720. return this._map.indexOf(value);
  11721. },
  11722. getMap: function() {
  11723. return this._map;
  11724. },
  11725. readCharCode: function(str, offset) {
  11726. var c = 0;
  11727. var codespaceRanges = this.codespaceRanges;
  11728. var codespaceRangesLen = this.codespaceRanges.length;
  11729. // 9.7.6.2 CMap Mapping
  11730. // The code length is at most 4.
  11731. for (var n = 0; n < codespaceRangesLen; n++) {
  11732. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  11733. // Check each codespace range to see if it falls within.
  11734. var codespaceRange = codespaceRanges[n];
  11735. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  11736. var low = codespaceRange[k++];
  11737. var high = codespaceRange[k++];
  11738. if (c >= low && c <= high) {
  11739. return [c, n + 1];
  11740. }
  11741. }
  11742. }
  11743. return [0, 1];
  11744. }
  11745. };
  11746. return CMap;
  11747. })();
  11748. // A special case of CMap, where the _map array implicitly has a length of
  11749. // 65535 and each element is equal to its index.
  11750. var IdentityCMap = (function IdentityCMapClosure() {
  11751. function IdentityCMap(vertical, n) {
  11752. CMap.call(this);
  11753. this.vertical = vertical;
  11754. this.addCodespaceRange(n, 0, 0xffff);
  11755. }
  11756. Util.inherit(IdentityCMap, CMap, {});
  11757. IdentityCMap.prototype = {
  11758. addCodespaceRange: CMap.prototype.addCodespaceRange,
  11759. mapCidRange: function(low, high, dstLow) {
  11760. error('should not call mapCidRange');
  11761. },
  11762. mapBfRange: function(low, high, dstLow) {
  11763. error('should not call mapBfRange');
  11764. },
  11765. mapBfRangeToArray: function(low, high, array) {
  11766. error('should not call mapBfRangeToArray');
  11767. },
  11768. mapOne: function(src, dst) {
  11769. error('should not call mapCidOne');
  11770. },
  11771. lookup: function(code) {
  11772. return (isInt(code) && code <= 0xffff) ? code : undefined;
  11773. },
  11774. contains: function(code) {
  11775. return isInt(code) && code <= 0xffff;
  11776. },
  11777. forEach: function(callback) {
  11778. for (var i = 0; i <= 0xffff; i++) {
  11779. callback(i, i);
  11780. }
  11781. },
  11782. charCodeOf: function(value) {
  11783. return (isInt(value) && value <= 0xffff) ? value : -1;
  11784. },
  11785. getMap: function() {
  11786. // Sometimes identity maps must be instantiated, but it's rare.
  11787. var map = new Array(0x10000);
  11788. for (var i = 0; i <= 0xffff; i++) {
  11789. map[i] = i;
  11790. }
  11791. return map;
  11792. },
  11793. readCharCode: CMap.prototype.readCharCode
  11794. };
  11795. return IdentityCMap;
  11796. })();
  11797. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  11798. function fetchBinaryData(url) {
  11799. var nonBinaryRequest = PDFJS.disableWorker;
  11800. var request = new XMLHttpRequest();
  11801. request.open('GET', url, false);
  11802. if (!nonBinaryRequest) {
  11803. try {
  11804. request.responseType = 'arraybuffer';
  11805. nonBinaryRequest = request.responseType !== 'arraybuffer';
  11806. } catch (e) {
  11807. nonBinaryRequest = true;
  11808. }
  11809. }
  11810. if (nonBinaryRequest && request.overrideMimeType) {
  11811. request.overrideMimeType('text/plain; charset=x-user-defined');
  11812. }
  11813. request.send(null);
  11814. if (request.status === 0 && /^https?:/i.test(url)) {
  11815. error('Unable to get binary cMap at: ' + url);
  11816. }
  11817. if (nonBinaryRequest) {
  11818. var data = Array.prototype.map.call(request.responseText, function (ch) {
  11819. return ch.charCodeAt(0) & 255;
  11820. });
  11821. return new Uint8Array(data);
  11822. }
  11823. return new Uint8Array(request.response);
  11824. }
  11825. function hexToInt(a, size) {
  11826. var n = 0;
  11827. for (var i = 0; i <= size; i++) {
  11828. n = (n << 8) | a[i];
  11829. }
  11830. return n >>> 0;
  11831. }
  11832. function hexToStr(a, size) {
  11833. // This code is hot. Special-case some common values to avoid creating an
  11834. // object with subarray().
  11835. if (size === 1) {
  11836. return String.fromCharCode(a[0], a[1]);
  11837. }
  11838. if (size === 3) {
  11839. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  11840. }
  11841. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  11842. }
  11843. function addHex(a, b, size) {
  11844. var c = 0;
  11845. for (var i = size; i >= 0; i--) {
  11846. c += a[i] + b[i];
  11847. a[i] = c & 255;
  11848. c >>= 8;
  11849. }
  11850. }
  11851. function incHex(a, size) {
  11852. var c = 1;
  11853. for (var i = size; i >= 0 && c > 0; i--) {
  11854. c += a[i];
  11855. a[i] = c & 255;
  11856. c >>= 8;
  11857. }
  11858. }
  11859. var MAX_NUM_SIZE = 16;
  11860. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  11861. function BinaryCMapStream(data) {
  11862. this.buffer = data;
  11863. this.pos = 0;
  11864. this.end = data.length;
  11865. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  11866. }
  11867. BinaryCMapStream.prototype = {
  11868. readByte: function () {
  11869. if (this.pos >= this.end) {
  11870. return -1;
  11871. }
  11872. return this.buffer[this.pos++];
  11873. },
  11874. readNumber: function () {
  11875. var n = 0;
  11876. var last;
  11877. do {
  11878. var b = this.readByte();
  11879. if (b < 0) {
  11880. error('unexpected EOF in bcmap');
  11881. }
  11882. last = !(b & 0x80);
  11883. n = (n << 7) | (b & 0x7F);
  11884. } while (!last);
  11885. return n;
  11886. },
  11887. readSigned: function () {
  11888. var n = this.readNumber();
  11889. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  11890. },
  11891. readHex: function (num, size) {
  11892. num.set(this.buffer.subarray(this.pos,
  11893. this.pos + size + 1));
  11894. this.pos += size + 1;
  11895. },
  11896. readHexNumber: function (num, size) {
  11897. var last;
  11898. var stack = this.tmpBuf, sp = 0;
  11899. do {
  11900. var b = this.readByte();
  11901. if (b < 0) {
  11902. error('unexpected EOF in bcmap');
  11903. }
  11904. last = !(b & 0x80);
  11905. stack[sp++] = b & 0x7F;
  11906. } while (!last);
  11907. var i = size, buffer = 0, bufferSize = 0;
  11908. while (i >= 0) {
  11909. while (bufferSize < 8 && stack.length > 0) {
  11910. buffer = (stack[--sp] << bufferSize) | buffer;
  11911. bufferSize += 7;
  11912. }
  11913. num[i] = buffer & 255;
  11914. i--;
  11915. buffer >>= 8;
  11916. bufferSize -= 8;
  11917. }
  11918. },
  11919. readHexSigned: function (num, size) {
  11920. this.readHexNumber(num, size);
  11921. var sign = num[size] & 1 ? 255 : 0;
  11922. var c = 0;
  11923. for (var i = 0; i <= size; i++) {
  11924. c = ((c & 1) << 8) | num[i];
  11925. num[i] = (c >> 1) ^ sign;
  11926. }
  11927. },
  11928. readString: function () {
  11929. var len = this.readNumber();
  11930. var s = '';
  11931. for (var i = 0; i < len; i++) {
  11932. s += String.fromCharCode(this.readNumber());
  11933. }
  11934. return s;
  11935. }
  11936. };
  11937. function processBinaryCMap(url, cMap, extend) {
  11938. var data = fetchBinaryData(url);
  11939. var stream = new BinaryCMapStream(data);
  11940. var header = stream.readByte();
  11941. cMap.vertical = !!(header & 1);
  11942. var useCMap = null;
  11943. var start = new Uint8Array(MAX_NUM_SIZE);
  11944. var end = new Uint8Array(MAX_NUM_SIZE);
  11945. var char = new Uint8Array(MAX_NUM_SIZE);
  11946. var charCode = new Uint8Array(MAX_NUM_SIZE);
  11947. var tmp = new Uint8Array(MAX_NUM_SIZE);
  11948. var code;
  11949. var b;
  11950. while ((b = stream.readByte()) >= 0) {
  11951. var type = b >> 5;
  11952. if (type === 7) { // metadata, e.g. comment or usecmap
  11953. switch (b & 0x1F) {
  11954. case 0:
  11955. stream.readString(); // skipping comment
  11956. break;
  11957. case 1:
  11958. useCMap = stream.readString();
  11959. break;
  11960. }
  11961. continue;
  11962. }
  11963. var sequence = !!(b & 0x10);
  11964. var dataSize = b & 15;
  11965. assert(dataSize + 1 <= MAX_NUM_SIZE);
  11966. var ucs2DataSize = 1;
  11967. var subitemsCount = stream.readNumber();
  11968. var i;
  11969. switch (type) {
  11970. case 0: // codespacerange
  11971. stream.readHex(start, dataSize);
  11972. stream.readHexNumber(end, dataSize);
  11973. addHex(end, start, dataSize);
  11974. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  11975. hexToInt(end, dataSize));
  11976. for (i = 1; i < subitemsCount; i++) {
  11977. incHex(end, dataSize);
  11978. stream.readHexNumber(start, dataSize);
  11979. addHex(start, end, dataSize);
  11980. stream.readHexNumber(end, dataSize);
  11981. addHex(end, start, dataSize);
  11982. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  11983. hexToInt(end, dataSize));
  11984. }
  11985. break;
  11986. case 1: // notdefrange
  11987. stream.readHex(start, dataSize);
  11988. stream.readHexNumber(end, dataSize);
  11989. addHex(end, start, dataSize);
  11990. code = stream.readNumber();
  11991. // undefined range, skipping
  11992. for (i = 1; i < subitemsCount; i++) {
  11993. incHex(end, dataSize);
  11994. stream.readHexNumber(start, dataSize);
  11995. addHex(start, end, dataSize);
  11996. stream.readHexNumber(end, dataSize);
  11997. addHex(end, start, dataSize);
  11998. code = stream.readNumber();
  11999. // nop
  12000. }
  12001. break;
  12002. case 2: // cidchar
  12003. stream.readHex(char, dataSize);
  12004. code = stream.readNumber();
  12005. cMap.mapOne(hexToInt(char, dataSize), code);
  12006. for (i = 1; i < subitemsCount; i++) {
  12007. incHex(char, dataSize);
  12008. if (!sequence) {
  12009. stream.readHexNumber(tmp, dataSize);
  12010. addHex(char, tmp, dataSize);
  12011. }
  12012. code = stream.readSigned() + (code + 1);
  12013. cMap.mapOne(hexToInt(char, dataSize), code);
  12014. }
  12015. break;
  12016. case 3: // cidrange
  12017. stream.readHex(start, dataSize);
  12018. stream.readHexNumber(end, dataSize);
  12019. addHex(end, start, dataSize);
  12020. code = stream.readNumber();
  12021. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12022. code);
  12023. for (i = 1; i < subitemsCount; i++) {
  12024. incHex(end, dataSize);
  12025. if (!sequence) {
  12026. stream.readHexNumber(start, dataSize);
  12027. addHex(start, end, dataSize);
  12028. } else {
  12029. start.set(end);
  12030. }
  12031. stream.readHexNumber(end, dataSize);
  12032. addHex(end, start, dataSize);
  12033. code = stream.readNumber();
  12034. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12035. code);
  12036. }
  12037. break;
  12038. case 4: // bfchar
  12039. stream.readHex(char, ucs2DataSize);
  12040. stream.readHex(charCode, dataSize);
  12041. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12042. hexToStr(charCode, dataSize));
  12043. for (i = 1; i < subitemsCount; i++) {
  12044. incHex(char, ucs2DataSize);
  12045. if (!sequence) {
  12046. stream.readHexNumber(tmp, ucs2DataSize);
  12047. addHex(char, tmp, ucs2DataSize);
  12048. }
  12049. incHex(charCode, dataSize);
  12050. stream.readHexSigned(tmp, dataSize);
  12051. addHex(charCode, tmp, dataSize);
  12052. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12053. hexToStr(charCode, dataSize));
  12054. }
  12055. break;
  12056. case 5: // bfrange
  12057. stream.readHex(start, ucs2DataSize);
  12058. stream.readHexNumber(end, ucs2DataSize);
  12059. addHex(end, start, ucs2DataSize);
  12060. stream.readHex(charCode, dataSize);
  12061. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12062. hexToInt(end, ucs2DataSize),
  12063. hexToStr(charCode, dataSize));
  12064. for (i = 1; i < subitemsCount; i++) {
  12065. incHex(end, ucs2DataSize);
  12066. if (!sequence) {
  12067. stream.readHexNumber(start, ucs2DataSize);
  12068. addHex(start, end, ucs2DataSize);
  12069. } else {
  12070. start.set(end);
  12071. }
  12072. stream.readHexNumber(end, ucs2DataSize);
  12073. addHex(end, start, ucs2DataSize);
  12074. stream.readHex(charCode, dataSize);
  12075. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12076. hexToInt(end, ucs2DataSize),
  12077. hexToStr(charCode, dataSize));
  12078. }
  12079. break;
  12080. default:
  12081. error('Unknown type: ' + type);
  12082. break;
  12083. }
  12084. }
  12085. if (useCMap) {
  12086. extend(useCMap);
  12087. }
  12088. return cMap;
  12089. }
  12090. function BinaryCMapReader() {}
  12091. BinaryCMapReader.prototype = {
  12092. read: processBinaryCMap
  12093. };
  12094. return BinaryCMapReader;
  12095. })();
  12096. var CMapFactory = (function CMapFactoryClosure() {
  12097. function strToInt(str) {
  12098. var a = 0;
  12099. for (var i = 0; i < str.length; i++) {
  12100. a = (a << 8) | str.charCodeAt(i);
  12101. }
  12102. return a >>> 0;
  12103. }
  12104. function expectString(obj) {
  12105. if (!isString(obj)) {
  12106. error('Malformed CMap: expected string.');
  12107. }
  12108. }
  12109. function expectInt(obj) {
  12110. if (!isInt(obj)) {
  12111. error('Malformed CMap: expected int.');
  12112. }
  12113. }
  12114. function parseBfChar(cMap, lexer) {
  12115. while (true) {
  12116. var obj = lexer.getObj();
  12117. if (isEOF(obj)) {
  12118. break;
  12119. }
  12120. if (isCmd(obj, 'endbfchar')) {
  12121. return;
  12122. }
  12123. expectString(obj);
  12124. var src = strToInt(obj);
  12125. obj = lexer.getObj();
  12126. // TODO are /dstName used?
  12127. expectString(obj);
  12128. var dst = obj;
  12129. cMap.mapOne(src, dst);
  12130. }
  12131. }
  12132. function parseBfRange(cMap, lexer) {
  12133. while (true) {
  12134. var obj = lexer.getObj();
  12135. if (isEOF(obj)) {
  12136. break;
  12137. }
  12138. if (isCmd(obj, 'endbfrange')) {
  12139. return;
  12140. }
  12141. expectString(obj);
  12142. var low = strToInt(obj);
  12143. obj = lexer.getObj();
  12144. expectString(obj);
  12145. var high = strToInt(obj);
  12146. obj = lexer.getObj();
  12147. if (isInt(obj) || isString(obj)) {
  12148. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12149. cMap.mapBfRange(low, high, dstLow);
  12150. } else if (isCmd(obj, '[')) {
  12151. obj = lexer.getObj();
  12152. var array = [];
  12153. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12154. array.push(obj);
  12155. obj = lexer.getObj();
  12156. }
  12157. cMap.mapBfRangeToArray(low, high, array);
  12158. } else {
  12159. break;
  12160. }
  12161. }
  12162. error('Invalid bf range.');
  12163. }
  12164. function parseCidChar(cMap, lexer) {
  12165. while (true) {
  12166. var obj = lexer.getObj();
  12167. if (isEOF(obj)) {
  12168. break;
  12169. }
  12170. if (isCmd(obj, 'endcidchar')) {
  12171. return;
  12172. }
  12173. expectString(obj);
  12174. var src = strToInt(obj);
  12175. obj = lexer.getObj();
  12176. expectInt(obj);
  12177. var dst = obj;
  12178. cMap.mapOne(src, dst);
  12179. }
  12180. }
  12181. function parseCidRange(cMap, lexer) {
  12182. while (true) {
  12183. var obj = lexer.getObj();
  12184. if (isEOF(obj)) {
  12185. break;
  12186. }
  12187. if (isCmd(obj, 'endcidrange')) {
  12188. return;
  12189. }
  12190. expectString(obj);
  12191. var low = strToInt(obj);
  12192. obj = lexer.getObj();
  12193. expectString(obj);
  12194. var high = strToInt(obj);
  12195. obj = lexer.getObj();
  12196. expectInt(obj);
  12197. var dstLow = obj;
  12198. cMap.mapCidRange(low, high, dstLow);
  12199. }
  12200. }
  12201. function parseCodespaceRange(cMap, lexer) {
  12202. while (true) {
  12203. var obj = lexer.getObj();
  12204. if (isEOF(obj)) {
  12205. break;
  12206. }
  12207. if (isCmd(obj, 'endcodespacerange')) {
  12208. return;
  12209. }
  12210. if (!isString(obj)) {
  12211. break;
  12212. }
  12213. var low = strToInt(obj);
  12214. obj = lexer.getObj();
  12215. if (!isString(obj)) {
  12216. break;
  12217. }
  12218. var high = strToInt(obj);
  12219. cMap.addCodespaceRange(obj.length, low, high);
  12220. }
  12221. error('Invalid codespace range.');
  12222. }
  12223. function parseWMode(cMap, lexer) {
  12224. var obj = lexer.getObj();
  12225. if (isInt(obj)) {
  12226. cMap.vertical = !!obj;
  12227. }
  12228. }
  12229. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12230. var previous;
  12231. var embededUseCMap;
  12232. objLoop: while (true) {
  12233. var obj = lexer.getObj();
  12234. if (isEOF(obj)) {
  12235. break;
  12236. } else if (isName(obj)) {
  12237. if (obj.name === 'WMode') {
  12238. parseWMode(cMap, lexer);
  12239. }
  12240. previous = obj;
  12241. } else if (isCmd(obj)) {
  12242. switch (obj.cmd) {
  12243. case 'endcmap':
  12244. break objLoop;
  12245. case 'usecmap':
  12246. if (isName(previous)) {
  12247. embededUseCMap = previous.name;
  12248. }
  12249. break;
  12250. case 'begincodespacerange':
  12251. parseCodespaceRange(cMap, lexer);
  12252. break;
  12253. case 'beginbfchar':
  12254. parseBfChar(cMap, lexer);
  12255. break;
  12256. case 'begincidchar':
  12257. parseCidChar(cMap, lexer);
  12258. break;
  12259. case 'beginbfrange':
  12260. parseBfRange(cMap, lexer);
  12261. break;
  12262. case 'begincidrange':
  12263. parseCidRange(cMap, lexer);
  12264. break;
  12265. }
  12266. }
  12267. }
  12268. if (!useCMap && embededUseCMap) {
  12269. // Load the usecmap definition from the file only if there wasn't one
  12270. // specified.
  12271. useCMap = embededUseCMap;
  12272. }
  12273. if (useCMap) {
  12274. extendCMap(cMap, builtInCMapParams, useCMap);
  12275. }
  12276. }
  12277. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12278. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12279. // If there aren't any code space ranges defined clone all the parent ones
  12280. // into this cMap.
  12281. if (cMap.numCodespaceRanges === 0) {
  12282. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12283. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12284. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12285. }
  12286. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12287. }
  12288. // Merge the map into the current one, making sure not to override
  12289. // any previously defined entries.
  12290. cMap.useCMap.forEach(function(key, value) {
  12291. if (!cMap.contains(key)) {
  12292. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12293. }
  12294. });
  12295. }
  12296. function parseBinaryCMap(name, builtInCMapParams) {
  12297. var url = builtInCMapParams.url + name + '.bcmap';
  12298. var cMap = new CMap(true);
  12299. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12300. extendCMap(cMap, builtInCMapParams, useCMap);
  12301. });
  12302. return cMap;
  12303. }
  12304. function createBuiltInCMap(name, builtInCMapParams) {
  12305. if (name === 'Identity-H') {
  12306. return new IdentityCMap(false, 2);
  12307. } else if (name === 'Identity-V') {
  12308. return new IdentityCMap(true, 2);
  12309. }
  12310. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12311. error('Unknown cMap name: ' + name);
  12312. }
  12313. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12314. if (builtInCMapParams.packed) {
  12315. return parseBinaryCMap(name, builtInCMapParams);
  12316. }
  12317. var request = new XMLHttpRequest();
  12318. var url = builtInCMapParams.url + name;
  12319. request.open('GET', url, false);
  12320. request.send(null);
  12321. if (request.status === 0 && /^https?:/i.test(url)) {
  12322. error('Unable to get cMap at: ' + url);
  12323. }
  12324. var cMap = new CMap(true);
  12325. var lexer = new Lexer(new StringStream(request.responseText));
  12326. parseCMap(cMap, lexer, builtInCMapParams, null);
  12327. return cMap;
  12328. }
  12329. return {
  12330. create: function (encoding, builtInCMapParams, useCMap) {
  12331. if (isName(encoding)) {
  12332. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12333. } else if (isStream(encoding)) {
  12334. var cMap = new CMap();
  12335. var lexer = new Lexer(encoding);
  12336. try {
  12337. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12338. } catch (e) {
  12339. warn('Invalid CMap data. ' + e);
  12340. }
  12341. return cMap;
  12342. }
  12343. error('Encoding required.');
  12344. }
  12345. };
  12346. })();
  12347. // Unicode Private Use Area
  12348. var PRIVATE_USE_OFFSET_START = 0xE000;
  12349. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12350. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12351. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12352. // except for Type 3 fonts
  12353. var PDF_GLYPH_SPACE_UNITS = 1000;
  12354. // Hinting is currently disabled due to unknown problems on windows
  12355. // in tracemonkey and various other pdfs with type1 fonts.
  12356. var HINTING_ENABLED = false;
  12357. // Accented charactars are not displayed properly on windows, using this flag
  12358. // to control analysis of seac charstrings.
  12359. var SEAC_ANALYSIS_ENABLED = false;
  12360. var FontFlags = {
  12361. FixedPitch: 1,
  12362. Serif: 2,
  12363. Symbolic: 4,
  12364. Script: 8,
  12365. Nonsymbolic: 32,
  12366. Italic: 64,
  12367. AllCap: 65536,
  12368. SmallCap: 131072,
  12369. ForceBold: 262144
  12370. };
  12371. var Encodings = {
  12372. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12373. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12374. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12375. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12376. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12377. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12378. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12379. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12380. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12381. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12382. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12383. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12384. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12385. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12386. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12387. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12388. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12389. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12390. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12391. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12392. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12393. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12394. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12395. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12396. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12397. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12398. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12399. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12400. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12401. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12402. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12403. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12404. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12405. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12406. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12407. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12408. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12409. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12410. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12411. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12412. 'Ydieresissmall'],
  12413. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12414. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12415. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12416. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12417. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12418. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12419. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12420. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12421. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12422. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12423. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12424. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12425. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12426. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12427. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12428. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12429. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12430. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12431. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12432. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12433. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12434. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12435. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12436. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12437. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12438. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12439. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12440. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12441. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12442. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12443. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12444. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12445. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12446. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12447. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12448. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12449. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12450. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12451. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12452. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12453. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12454. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12455. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12456. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12457. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12458. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12459. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12460. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12461. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12462. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12463. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12464. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12465. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12466. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12467. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12468. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12469. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12470. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12471. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12472. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12473. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12474. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12475. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12476. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12477. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12478. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12479. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12480. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12481. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12482. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12483. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12484. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12485. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12486. 'ogonek', 'caron'],
  12487. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12488. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12489. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12490. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12491. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12492. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12493. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12494. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12495. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12496. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12497. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12498. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12499. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12500. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12501. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12502. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12503. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12504. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12505. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12506. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12507. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12508. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12509. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12510. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12511. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12512. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12513. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12514. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12515. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12516. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12517. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12518. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12519. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12520. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12521. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12522. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12523. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12524. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  12525. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  12526. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  12527. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  12528. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  12529. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  12530. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  12531. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  12532. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  12533. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  12534. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  12535. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  12536. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  12537. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  12538. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  12539. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  12540. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  12541. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  12542. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  12543. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  12544. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  12545. 'ydieresis'],
  12546. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12547. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12548. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  12549. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  12550. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  12551. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  12552. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  12553. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  12554. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  12555. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  12556. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  12557. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  12558. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  12559. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  12560. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  12561. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12562. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  12563. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  12564. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  12565. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  12566. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  12567. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  12568. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  12569. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  12570. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  12571. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  12572. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  12573. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  12574. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  12575. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  12576. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  12577. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  12578. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  12579. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  12580. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  12581. 'bracerightbt'],
  12582. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12583. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12584. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  12585. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  12586. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  12587. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  12588. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  12589. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  12590. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  12591. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  12592. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  12593. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12594. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12595. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  12596. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  12597. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  12598. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  12599. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  12600. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  12601. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  12602. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  12603. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  12604. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  12605. 'a188', 'a189', 'a190', 'a191']
  12606. };
  12607. /**
  12608. * Hold a map of decoded fonts and of the standard fourteen Type1
  12609. * fonts and their acronyms.
  12610. */
  12611. var stdFontMap = {
  12612. 'ArialNarrow': 'Helvetica',
  12613. 'ArialNarrow-Bold': 'Helvetica-Bold',
  12614. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  12615. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  12616. 'ArialBlack': 'Helvetica',
  12617. 'ArialBlack-Bold': 'Helvetica-Bold',
  12618. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  12619. 'ArialBlack-Italic': 'Helvetica-Oblique',
  12620. 'Arial': 'Helvetica',
  12621. 'Arial-Bold': 'Helvetica-Bold',
  12622. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  12623. 'Arial-Italic': 'Helvetica-Oblique',
  12624. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  12625. 'Arial-BoldMT': 'Helvetica-Bold',
  12626. 'Arial-ItalicMT': 'Helvetica-Oblique',
  12627. 'ArialMT': 'Helvetica',
  12628. 'Courier-Bold': 'Courier-Bold',
  12629. 'Courier-BoldItalic': 'Courier-BoldOblique',
  12630. 'Courier-Italic': 'Courier-Oblique',
  12631. 'CourierNew': 'Courier',
  12632. 'CourierNew-Bold': 'Courier-Bold',
  12633. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  12634. 'CourierNew-Italic': 'Courier-Oblique',
  12635. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  12636. 'CourierNewPS-BoldMT': 'Courier-Bold',
  12637. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  12638. 'CourierNewPSMT': 'Courier',
  12639. 'Helvetica-Bold': 'Helvetica-Bold',
  12640. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  12641. 'Helvetica-Italic': 'Helvetica-Oblique',
  12642. 'Symbol-Bold': 'Symbol',
  12643. 'Symbol-BoldItalic': 'Symbol',
  12644. 'Symbol-Italic': 'Symbol',
  12645. 'TimesNewRoman': 'Times-Roman',
  12646. 'TimesNewRoman-Bold': 'Times-Bold',
  12647. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  12648. 'TimesNewRoman-Italic': 'Times-Italic',
  12649. 'TimesNewRomanPS': 'Times-Roman',
  12650. 'TimesNewRomanPS-Bold': 'Times-Bold',
  12651. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  12652. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  12653. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  12654. 'TimesNewRomanPS-Italic': 'Times-Italic',
  12655. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  12656. 'TimesNewRomanPSMT': 'Times-Roman',
  12657. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  12658. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  12659. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  12660. };
  12661. /**
  12662. * Holds the map of the non-standard fonts that might be included as a standard
  12663. * fonts without glyph data.
  12664. */
  12665. var nonStdFontMap = {
  12666. 'ComicSansMS': 'Comic Sans MS',
  12667. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  12668. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  12669. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  12670. 'LucidaConsole': 'Courier',
  12671. 'LucidaConsole-Bold': 'Courier-Bold',
  12672. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  12673. 'LucidaConsole-Italic': 'Courier-Oblique',
  12674. 'MS-Gothic': 'MS Gothic',
  12675. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  12676. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  12677. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  12678. 'MS-Mincho': 'MS Mincho',
  12679. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  12680. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  12681. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  12682. 'MS-PGothic': 'MS PGothic',
  12683. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  12684. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  12685. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  12686. 'MS-PMincho': 'MS PMincho',
  12687. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  12688. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  12689. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  12690. };
  12691. var serifFonts = {
  12692. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  12693. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  12694. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  12695. 'Arno': true, 'Aster': true, 'Aurora': true,
  12696. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  12697. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  12698. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  12699. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  12700. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  12701. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  12702. 'Cartier': true, 'Caslon': true, 'Catull': true,
  12703. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  12704. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  12705. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  12706. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  12707. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  12708. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  12709. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  12710. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  12711. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  12712. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  12713. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  12714. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  12715. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  12716. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  12717. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  12718. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  12719. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  12720. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  12721. 'Miller': true, 'Minion': true, 'Modern': true,
  12722. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  12723. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  12724. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  12725. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  12726. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  12727. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  12728. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  12729. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  12730. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  12731. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  12732. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  12733. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  12734. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  12735. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  12736. };
  12737. var symbolsFonts = {
  12738. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  12739. };
  12740. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  12741. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  12742. // glyphs, but common for some set of the standard fonts.
  12743. var GlyphMapForStandardFonts = {
  12744. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  12745. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  12746. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  12747. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  12748. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  12749. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  12750. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  12751. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  12752. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  12753. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  12754. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  12755. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  12756. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  12757. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  12758. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  12759. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  12760. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  12761. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  12762. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  12763. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  12764. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  12765. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  12766. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  12767. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  12768. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  12769. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  12770. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  12771. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  12772. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  12773. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  12774. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  12775. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  12776. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  12777. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  12778. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  12779. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  12780. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  12781. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  12782. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  12783. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  12784. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  12785. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  12786. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  12787. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  12788. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  12789. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  12790. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  12791. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  12792. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  12793. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  12794. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  12795. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  12796. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  12797. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  12798. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  12799. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  12800. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  12801. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  12802. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  12803. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  12804. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  12805. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  12806. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  12807. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  12808. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  12809. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  12810. };
  12811. // Some characters, e.g. copyrightserif, mapped to the private use area and
  12812. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  12813. // to the similar equivalents in the normal characters range.
  12814. function mapSpecialUnicodeValues(code) {
  12815. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  12816. return 0;
  12817. }
  12818. switch (code) {
  12819. case 0xF8E9: // copyrightsans
  12820. case 0xF6D9: // copyrightserif
  12821. return 0x00A9; // copyright
  12822. case 0xF8E8: // registersans
  12823. case 0xF6DA: // registerserif
  12824. return 0x00AE; // registered
  12825. case 0xF8EA: // trademarksans
  12826. case 0xF6DB: // trademarkserif
  12827. return 0x2122; // trademark
  12828. default:
  12829. return code;
  12830. }
  12831. }
  12832. var UnicodeRanges = [
  12833. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  12834. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  12835. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  12836. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  12837. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  12838. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  12839. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  12840. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  12841. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  12842. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  12843. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  12844. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  12845. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  12846. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  12847. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  12848. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  12849. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  12850. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  12851. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  12852. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  12853. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  12854. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  12855. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  12856. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  12857. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  12858. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  12859. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  12860. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  12861. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  12862. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  12863. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  12864. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  12865. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  12866. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  12867. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  12868. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  12869. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  12870. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  12871. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  12872. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  12873. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  12874. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  12875. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  12876. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  12877. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  12878. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  12879. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  12880. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  12881. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  12882. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  12883. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  12884. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  12885. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  12886. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  12887. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  12888. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  12889. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  12890. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  12891. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  12892. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  12893. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  12894. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  12895. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  12896. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  12897. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  12898. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  12899. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  12900. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  12901. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  12902. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  12903. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  12904. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  12905. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  12906. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  12907. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  12908. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  12909. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  12910. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  12911. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  12912. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  12913. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  12914. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  12915. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  12916. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  12917. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  12918. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  12919. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  12920. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  12921. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  12922. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  12923. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  12924. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  12925. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  12926. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  12927. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  12928. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  12929. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  12930. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  12931. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  12932. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  12933. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  12934. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  12935. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  12936. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  12937. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  12938. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  12939. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  12940. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  12941. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  12942. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  12943. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  12944. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  12945. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  12946. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  12947. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  12948. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  12949. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  12950. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  12951. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  12952. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  12953. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  12954. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  12955. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  12956. ];
  12957. var MacStandardGlyphOrdering = [
  12958. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  12959. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  12960. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  12961. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  12962. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  12963. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  12964. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  12965. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  12966. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  12967. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  12968. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  12969. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  12970. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12971. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  12972. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  12973. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  12974. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  12975. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  12976. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  12977. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  12978. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  12979. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  12980. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  12981. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  12982. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  12983. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  12984. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  12985. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  12986. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  12987. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  12988. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  12989. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  12990. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  12991. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  12992. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  12993. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  12994. function getUnicodeRangeFor(value) {
  12995. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  12996. var range = UnicodeRanges[i];
  12997. if (value >= range.begin && value < range.end) {
  12998. return i;
  12999. }
  13000. }
  13001. return -1;
  13002. }
  13003. function isRTLRangeFor(value) {
  13004. var range = UnicodeRanges[13];
  13005. if (value >= range.begin && value < range.end) {
  13006. return true;
  13007. }
  13008. range = UnicodeRanges[11];
  13009. if (value >= range.begin && value < range.end) {
  13010. return true;
  13011. }
  13012. return false;
  13013. }
  13014. // The normalization table is obtained by filtering the Unicode characters
  13015. // database with <compat> entries.
  13016. var NormalizedUnicodes = {
  13017. '\u00A8': '\u0020\u0308',
  13018. '\u00AF': '\u0020\u0304',
  13019. '\u00B4': '\u0020\u0301',
  13020. '\u00B5': '\u03BC',
  13021. '\u00B8': '\u0020\u0327',
  13022. '\u0132': '\u0049\u004A',
  13023. '\u0133': '\u0069\u006A',
  13024. '\u013F': '\u004C\u00B7',
  13025. '\u0140': '\u006C\u00B7',
  13026. '\u0149': '\u02BC\u006E',
  13027. '\u017F': '\u0073',
  13028. '\u01C4': '\u0044\u017D',
  13029. '\u01C5': '\u0044\u017E',
  13030. '\u01C6': '\u0064\u017E',
  13031. '\u01C7': '\u004C\u004A',
  13032. '\u01C8': '\u004C\u006A',
  13033. '\u01C9': '\u006C\u006A',
  13034. '\u01CA': '\u004E\u004A',
  13035. '\u01CB': '\u004E\u006A',
  13036. '\u01CC': '\u006E\u006A',
  13037. '\u01F1': '\u0044\u005A',
  13038. '\u01F2': '\u0044\u007A',
  13039. '\u01F3': '\u0064\u007A',
  13040. '\u02D8': '\u0020\u0306',
  13041. '\u02D9': '\u0020\u0307',
  13042. '\u02DA': '\u0020\u030A',
  13043. '\u02DB': '\u0020\u0328',
  13044. '\u02DC': '\u0020\u0303',
  13045. '\u02DD': '\u0020\u030B',
  13046. '\u037A': '\u0020\u0345',
  13047. '\u0384': '\u0020\u0301',
  13048. '\u03D0': '\u03B2',
  13049. '\u03D1': '\u03B8',
  13050. '\u03D2': '\u03A5',
  13051. '\u03D5': '\u03C6',
  13052. '\u03D6': '\u03C0',
  13053. '\u03F0': '\u03BA',
  13054. '\u03F1': '\u03C1',
  13055. '\u03F2': '\u03C2',
  13056. '\u03F4': '\u0398',
  13057. '\u03F5': '\u03B5',
  13058. '\u03F9': '\u03A3',
  13059. '\u0587': '\u0565\u0582',
  13060. '\u0675': '\u0627\u0674',
  13061. '\u0676': '\u0648\u0674',
  13062. '\u0677': '\u06C7\u0674',
  13063. '\u0678': '\u064A\u0674',
  13064. '\u0E33': '\u0E4D\u0E32',
  13065. '\u0EB3': '\u0ECD\u0EB2',
  13066. '\u0EDC': '\u0EAB\u0E99',
  13067. '\u0EDD': '\u0EAB\u0EA1',
  13068. '\u0F77': '\u0FB2\u0F81',
  13069. '\u0F79': '\u0FB3\u0F81',
  13070. '\u1E9A': '\u0061\u02BE',
  13071. '\u1FBD': '\u0020\u0313',
  13072. '\u1FBF': '\u0020\u0313',
  13073. '\u1FC0': '\u0020\u0342',
  13074. '\u1FFE': '\u0020\u0314',
  13075. '\u2002': '\u0020',
  13076. '\u2003': '\u0020',
  13077. '\u2004': '\u0020',
  13078. '\u2005': '\u0020',
  13079. '\u2006': '\u0020',
  13080. '\u2008': '\u0020',
  13081. '\u2009': '\u0020',
  13082. '\u200A': '\u0020',
  13083. '\u2017': '\u0020\u0333',
  13084. '\u2024': '\u002E',
  13085. '\u2025': '\u002E\u002E',
  13086. '\u2026': '\u002E\u002E\u002E',
  13087. '\u2033': '\u2032\u2032',
  13088. '\u2034': '\u2032\u2032\u2032',
  13089. '\u2036': '\u2035\u2035',
  13090. '\u2037': '\u2035\u2035\u2035',
  13091. '\u203C': '\u0021\u0021',
  13092. '\u203E': '\u0020\u0305',
  13093. '\u2047': '\u003F\u003F',
  13094. '\u2048': '\u003F\u0021',
  13095. '\u2049': '\u0021\u003F',
  13096. '\u2057': '\u2032\u2032\u2032\u2032',
  13097. '\u205F': '\u0020',
  13098. '\u20A8': '\u0052\u0073',
  13099. '\u2100': '\u0061\u002F\u0063',
  13100. '\u2101': '\u0061\u002F\u0073',
  13101. '\u2103': '\u00B0\u0043',
  13102. '\u2105': '\u0063\u002F\u006F',
  13103. '\u2106': '\u0063\u002F\u0075',
  13104. '\u2107': '\u0190',
  13105. '\u2109': '\u00B0\u0046',
  13106. '\u2116': '\u004E\u006F',
  13107. '\u2121': '\u0054\u0045\u004C',
  13108. '\u2135': '\u05D0',
  13109. '\u2136': '\u05D1',
  13110. '\u2137': '\u05D2',
  13111. '\u2138': '\u05D3',
  13112. '\u213B': '\u0046\u0041\u0058',
  13113. '\u2160': '\u0049',
  13114. '\u2161': '\u0049\u0049',
  13115. '\u2162': '\u0049\u0049\u0049',
  13116. '\u2163': '\u0049\u0056',
  13117. '\u2164': '\u0056',
  13118. '\u2165': '\u0056\u0049',
  13119. '\u2166': '\u0056\u0049\u0049',
  13120. '\u2167': '\u0056\u0049\u0049\u0049',
  13121. '\u2168': '\u0049\u0058',
  13122. '\u2169': '\u0058',
  13123. '\u216A': '\u0058\u0049',
  13124. '\u216B': '\u0058\u0049\u0049',
  13125. '\u216C': '\u004C',
  13126. '\u216D': '\u0043',
  13127. '\u216E': '\u0044',
  13128. '\u216F': '\u004D',
  13129. '\u2170': '\u0069',
  13130. '\u2171': '\u0069\u0069',
  13131. '\u2172': '\u0069\u0069\u0069',
  13132. '\u2173': '\u0069\u0076',
  13133. '\u2174': '\u0076',
  13134. '\u2175': '\u0076\u0069',
  13135. '\u2176': '\u0076\u0069\u0069',
  13136. '\u2177': '\u0076\u0069\u0069\u0069',
  13137. '\u2178': '\u0069\u0078',
  13138. '\u2179': '\u0078',
  13139. '\u217A': '\u0078\u0069',
  13140. '\u217B': '\u0078\u0069\u0069',
  13141. '\u217C': '\u006C',
  13142. '\u217D': '\u0063',
  13143. '\u217E': '\u0064',
  13144. '\u217F': '\u006D',
  13145. '\u222C': '\u222B\u222B',
  13146. '\u222D': '\u222B\u222B\u222B',
  13147. '\u222F': '\u222E\u222E',
  13148. '\u2230': '\u222E\u222E\u222E',
  13149. '\u2474': '\u0028\u0031\u0029',
  13150. '\u2475': '\u0028\u0032\u0029',
  13151. '\u2476': '\u0028\u0033\u0029',
  13152. '\u2477': '\u0028\u0034\u0029',
  13153. '\u2478': '\u0028\u0035\u0029',
  13154. '\u2479': '\u0028\u0036\u0029',
  13155. '\u247A': '\u0028\u0037\u0029',
  13156. '\u247B': '\u0028\u0038\u0029',
  13157. '\u247C': '\u0028\u0039\u0029',
  13158. '\u247D': '\u0028\u0031\u0030\u0029',
  13159. '\u247E': '\u0028\u0031\u0031\u0029',
  13160. '\u247F': '\u0028\u0031\u0032\u0029',
  13161. '\u2480': '\u0028\u0031\u0033\u0029',
  13162. '\u2481': '\u0028\u0031\u0034\u0029',
  13163. '\u2482': '\u0028\u0031\u0035\u0029',
  13164. '\u2483': '\u0028\u0031\u0036\u0029',
  13165. '\u2484': '\u0028\u0031\u0037\u0029',
  13166. '\u2485': '\u0028\u0031\u0038\u0029',
  13167. '\u2486': '\u0028\u0031\u0039\u0029',
  13168. '\u2487': '\u0028\u0032\u0030\u0029',
  13169. '\u2488': '\u0031\u002E',
  13170. '\u2489': '\u0032\u002E',
  13171. '\u248A': '\u0033\u002E',
  13172. '\u248B': '\u0034\u002E',
  13173. '\u248C': '\u0035\u002E',
  13174. '\u248D': '\u0036\u002E',
  13175. '\u248E': '\u0037\u002E',
  13176. '\u248F': '\u0038\u002E',
  13177. '\u2490': '\u0039\u002E',
  13178. '\u2491': '\u0031\u0030\u002E',
  13179. '\u2492': '\u0031\u0031\u002E',
  13180. '\u2493': '\u0031\u0032\u002E',
  13181. '\u2494': '\u0031\u0033\u002E',
  13182. '\u2495': '\u0031\u0034\u002E',
  13183. '\u2496': '\u0031\u0035\u002E',
  13184. '\u2497': '\u0031\u0036\u002E',
  13185. '\u2498': '\u0031\u0037\u002E',
  13186. '\u2499': '\u0031\u0038\u002E',
  13187. '\u249A': '\u0031\u0039\u002E',
  13188. '\u249B': '\u0032\u0030\u002E',
  13189. '\u249C': '\u0028\u0061\u0029',
  13190. '\u249D': '\u0028\u0062\u0029',
  13191. '\u249E': '\u0028\u0063\u0029',
  13192. '\u249F': '\u0028\u0064\u0029',
  13193. '\u24A0': '\u0028\u0065\u0029',
  13194. '\u24A1': '\u0028\u0066\u0029',
  13195. '\u24A2': '\u0028\u0067\u0029',
  13196. '\u24A3': '\u0028\u0068\u0029',
  13197. '\u24A4': '\u0028\u0069\u0029',
  13198. '\u24A5': '\u0028\u006A\u0029',
  13199. '\u24A6': '\u0028\u006B\u0029',
  13200. '\u24A7': '\u0028\u006C\u0029',
  13201. '\u24A8': '\u0028\u006D\u0029',
  13202. '\u24A9': '\u0028\u006E\u0029',
  13203. '\u24AA': '\u0028\u006F\u0029',
  13204. '\u24AB': '\u0028\u0070\u0029',
  13205. '\u24AC': '\u0028\u0071\u0029',
  13206. '\u24AD': '\u0028\u0072\u0029',
  13207. '\u24AE': '\u0028\u0073\u0029',
  13208. '\u24AF': '\u0028\u0074\u0029',
  13209. '\u24B0': '\u0028\u0075\u0029',
  13210. '\u24B1': '\u0028\u0076\u0029',
  13211. '\u24B2': '\u0028\u0077\u0029',
  13212. '\u24B3': '\u0028\u0078\u0029',
  13213. '\u24B4': '\u0028\u0079\u0029',
  13214. '\u24B5': '\u0028\u007A\u0029',
  13215. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13216. '\u2A74': '\u003A\u003A\u003D',
  13217. '\u2A75': '\u003D\u003D',
  13218. '\u2A76': '\u003D\u003D\u003D',
  13219. '\u2E9F': '\u6BCD',
  13220. '\u2EF3': '\u9F9F',
  13221. '\u2F00': '\u4E00',
  13222. '\u2F01': '\u4E28',
  13223. '\u2F02': '\u4E36',
  13224. '\u2F03': '\u4E3F',
  13225. '\u2F04': '\u4E59',
  13226. '\u2F05': '\u4E85',
  13227. '\u2F06': '\u4E8C',
  13228. '\u2F07': '\u4EA0',
  13229. '\u2F08': '\u4EBA',
  13230. '\u2F09': '\u513F',
  13231. '\u2F0A': '\u5165',
  13232. '\u2F0B': '\u516B',
  13233. '\u2F0C': '\u5182',
  13234. '\u2F0D': '\u5196',
  13235. '\u2F0E': '\u51AB',
  13236. '\u2F0F': '\u51E0',
  13237. '\u2F10': '\u51F5',
  13238. '\u2F11': '\u5200',
  13239. '\u2F12': '\u529B',
  13240. '\u2F13': '\u52F9',
  13241. '\u2F14': '\u5315',
  13242. '\u2F15': '\u531A',
  13243. '\u2F16': '\u5338',
  13244. '\u2F17': '\u5341',
  13245. '\u2F18': '\u535C',
  13246. '\u2F19': '\u5369',
  13247. '\u2F1A': '\u5382',
  13248. '\u2F1B': '\u53B6',
  13249. '\u2F1C': '\u53C8',
  13250. '\u2F1D': '\u53E3',
  13251. '\u2F1E': '\u56D7',
  13252. '\u2F1F': '\u571F',
  13253. '\u2F20': '\u58EB',
  13254. '\u2F21': '\u5902',
  13255. '\u2F22': '\u590A',
  13256. '\u2F23': '\u5915',
  13257. '\u2F24': '\u5927',
  13258. '\u2F25': '\u5973',
  13259. '\u2F26': '\u5B50',
  13260. '\u2F27': '\u5B80',
  13261. '\u2F28': '\u5BF8',
  13262. '\u2F29': '\u5C0F',
  13263. '\u2F2A': '\u5C22',
  13264. '\u2F2B': '\u5C38',
  13265. '\u2F2C': '\u5C6E',
  13266. '\u2F2D': '\u5C71',
  13267. '\u2F2E': '\u5DDB',
  13268. '\u2F2F': '\u5DE5',
  13269. '\u2F30': '\u5DF1',
  13270. '\u2F31': '\u5DFE',
  13271. '\u2F32': '\u5E72',
  13272. '\u2F33': '\u5E7A',
  13273. '\u2F34': '\u5E7F',
  13274. '\u2F35': '\u5EF4',
  13275. '\u2F36': '\u5EFE',
  13276. '\u2F37': '\u5F0B',
  13277. '\u2F38': '\u5F13',
  13278. '\u2F39': '\u5F50',
  13279. '\u2F3A': '\u5F61',
  13280. '\u2F3B': '\u5F73',
  13281. '\u2F3C': '\u5FC3',
  13282. '\u2F3D': '\u6208',
  13283. '\u2F3E': '\u6236',
  13284. '\u2F3F': '\u624B',
  13285. '\u2F40': '\u652F',
  13286. '\u2F41': '\u6534',
  13287. '\u2F42': '\u6587',
  13288. '\u2F43': '\u6597',
  13289. '\u2F44': '\u65A4',
  13290. '\u2F45': '\u65B9',
  13291. '\u2F46': '\u65E0',
  13292. '\u2F47': '\u65E5',
  13293. '\u2F48': '\u66F0',
  13294. '\u2F49': '\u6708',
  13295. '\u2F4A': '\u6728',
  13296. '\u2F4B': '\u6B20',
  13297. '\u2F4C': '\u6B62',
  13298. '\u2F4D': '\u6B79',
  13299. '\u2F4E': '\u6BB3',
  13300. '\u2F4F': '\u6BCB',
  13301. '\u2F50': '\u6BD4',
  13302. '\u2F51': '\u6BDB',
  13303. '\u2F52': '\u6C0F',
  13304. '\u2F53': '\u6C14',
  13305. '\u2F54': '\u6C34',
  13306. '\u2F55': '\u706B',
  13307. '\u2F56': '\u722A',
  13308. '\u2F57': '\u7236',
  13309. '\u2F58': '\u723B',
  13310. '\u2F59': '\u723F',
  13311. '\u2F5A': '\u7247',
  13312. '\u2F5B': '\u7259',
  13313. '\u2F5C': '\u725B',
  13314. '\u2F5D': '\u72AC',
  13315. '\u2F5E': '\u7384',
  13316. '\u2F5F': '\u7389',
  13317. '\u2F60': '\u74DC',
  13318. '\u2F61': '\u74E6',
  13319. '\u2F62': '\u7518',
  13320. '\u2F63': '\u751F',
  13321. '\u2F64': '\u7528',
  13322. '\u2F65': '\u7530',
  13323. '\u2F66': '\u758B',
  13324. '\u2F67': '\u7592',
  13325. '\u2F68': '\u7676',
  13326. '\u2F69': '\u767D',
  13327. '\u2F6A': '\u76AE',
  13328. '\u2F6B': '\u76BF',
  13329. '\u2F6C': '\u76EE',
  13330. '\u2F6D': '\u77DB',
  13331. '\u2F6E': '\u77E2',
  13332. '\u2F6F': '\u77F3',
  13333. '\u2F70': '\u793A',
  13334. '\u2F71': '\u79B8',
  13335. '\u2F72': '\u79BE',
  13336. '\u2F73': '\u7A74',
  13337. '\u2F74': '\u7ACB',
  13338. '\u2F75': '\u7AF9',
  13339. '\u2F76': '\u7C73',
  13340. '\u2F77': '\u7CF8',
  13341. '\u2F78': '\u7F36',
  13342. '\u2F79': '\u7F51',
  13343. '\u2F7A': '\u7F8A',
  13344. '\u2F7B': '\u7FBD',
  13345. '\u2F7C': '\u8001',
  13346. '\u2F7D': '\u800C',
  13347. '\u2F7E': '\u8012',
  13348. '\u2F7F': '\u8033',
  13349. '\u2F80': '\u807F',
  13350. '\u2F81': '\u8089',
  13351. '\u2F82': '\u81E3',
  13352. '\u2F83': '\u81EA',
  13353. '\u2F84': '\u81F3',
  13354. '\u2F85': '\u81FC',
  13355. '\u2F86': '\u820C',
  13356. '\u2F87': '\u821B',
  13357. '\u2F88': '\u821F',
  13358. '\u2F89': '\u826E',
  13359. '\u2F8A': '\u8272',
  13360. '\u2F8B': '\u8278',
  13361. '\u2F8C': '\u864D',
  13362. '\u2F8D': '\u866B',
  13363. '\u2F8E': '\u8840',
  13364. '\u2F8F': '\u884C',
  13365. '\u2F90': '\u8863',
  13366. '\u2F91': '\u897E',
  13367. '\u2F92': '\u898B',
  13368. '\u2F93': '\u89D2',
  13369. '\u2F94': '\u8A00',
  13370. '\u2F95': '\u8C37',
  13371. '\u2F96': '\u8C46',
  13372. '\u2F97': '\u8C55',
  13373. '\u2F98': '\u8C78',
  13374. '\u2F99': '\u8C9D',
  13375. '\u2F9A': '\u8D64',
  13376. '\u2F9B': '\u8D70',
  13377. '\u2F9C': '\u8DB3',
  13378. '\u2F9D': '\u8EAB',
  13379. '\u2F9E': '\u8ECA',
  13380. '\u2F9F': '\u8F9B',
  13381. '\u2FA0': '\u8FB0',
  13382. '\u2FA1': '\u8FB5',
  13383. '\u2FA2': '\u9091',
  13384. '\u2FA3': '\u9149',
  13385. '\u2FA4': '\u91C6',
  13386. '\u2FA5': '\u91CC',
  13387. '\u2FA6': '\u91D1',
  13388. '\u2FA7': '\u9577',
  13389. '\u2FA8': '\u9580',
  13390. '\u2FA9': '\u961C',
  13391. '\u2FAA': '\u96B6',
  13392. '\u2FAB': '\u96B9',
  13393. '\u2FAC': '\u96E8',
  13394. '\u2FAD': '\u9751',
  13395. '\u2FAE': '\u975E',
  13396. '\u2FAF': '\u9762',
  13397. '\u2FB0': '\u9769',
  13398. '\u2FB1': '\u97CB',
  13399. '\u2FB2': '\u97ED',
  13400. '\u2FB3': '\u97F3',
  13401. '\u2FB4': '\u9801',
  13402. '\u2FB5': '\u98A8',
  13403. '\u2FB6': '\u98DB',
  13404. '\u2FB7': '\u98DF',
  13405. '\u2FB8': '\u9996',
  13406. '\u2FB9': '\u9999',
  13407. '\u2FBA': '\u99AC',
  13408. '\u2FBB': '\u9AA8',
  13409. '\u2FBC': '\u9AD8',
  13410. '\u2FBD': '\u9ADF',
  13411. '\u2FBE': '\u9B25',
  13412. '\u2FBF': '\u9B2F',
  13413. '\u2FC0': '\u9B32',
  13414. '\u2FC1': '\u9B3C',
  13415. '\u2FC2': '\u9B5A',
  13416. '\u2FC3': '\u9CE5',
  13417. '\u2FC4': '\u9E75',
  13418. '\u2FC5': '\u9E7F',
  13419. '\u2FC6': '\u9EA5',
  13420. '\u2FC7': '\u9EBB',
  13421. '\u2FC8': '\u9EC3',
  13422. '\u2FC9': '\u9ECD',
  13423. '\u2FCA': '\u9ED1',
  13424. '\u2FCB': '\u9EF9',
  13425. '\u2FCC': '\u9EFD',
  13426. '\u2FCD': '\u9F0E',
  13427. '\u2FCE': '\u9F13',
  13428. '\u2FCF': '\u9F20',
  13429. '\u2FD0': '\u9F3B',
  13430. '\u2FD1': '\u9F4A',
  13431. '\u2FD2': '\u9F52',
  13432. '\u2FD3': '\u9F8D',
  13433. '\u2FD4': '\u9F9C',
  13434. '\u2FD5': '\u9FA0',
  13435. '\u3036': '\u3012',
  13436. '\u3038': '\u5341',
  13437. '\u3039': '\u5344',
  13438. '\u303A': '\u5345',
  13439. '\u309B': '\u0020\u3099',
  13440. '\u309C': '\u0020\u309A',
  13441. '\u3131': '\u1100',
  13442. '\u3132': '\u1101',
  13443. '\u3133': '\u11AA',
  13444. '\u3134': '\u1102',
  13445. '\u3135': '\u11AC',
  13446. '\u3136': '\u11AD',
  13447. '\u3137': '\u1103',
  13448. '\u3138': '\u1104',
  13449. '\u3139': '\u1105',
  13450. '\u313A': '\u11B0',
  13451. '\u313B': '\u11B1',
  13452. '\u313C': '\u11B2',
  13453. '\u313D': '\u11B3',
  13454. '\u313E': '\u11B4',
  13455. '\u313F': '\u11B5',
  13456. '\u3140': '\u111A',
  13457. '\u3141': '\u1106',
  13458. '\u3142': '\u1107',
  13459. '\u3143': '\u1108',
  13460. '\u3144': '\u1121',
  13461. '\u3145': '\u1109',
  13462. '\u3146': '\u110A',
  13463. '\u3147': '\u110B',
  13464. '\u3148': '\u110C',
  13465. '\u3149': '\u110D',
  13466. '\u314A': '\u110E',
  13467. '\u314B': '\u110F',
  13468. '\u314C': '\u1110',
  13469. '\u314D': '\u1111',
  13470. '\u314E': '\u1112',
  13471. '\u314F': '\u1161',
  13472. '\u3150': '\u1162',
  13473. '\u3151': '\u1163',
  13474. '\u3152': '\u1164',
  13475. '\u3153': '\u1165',
  13476. '\u3154': '\u1166',
  13477. '\u3155': '\u1167',
  13478. '\u3156': '\u1168',
  13479. '\u3157': '\u1169',
  13480. '\u3158': '\u116A',
  13481. '\u3159': '\u116B',
  13482. '\u315A': '\u116C',
  13483. '\u315B': '\u116D',
  13484. '\u315C': '\u116E',
  13485. '\u315D': '\u116F',
  13486. '\u315E': '\u1170',
  13487. '\u315F': '\u1171',
  13488. '\u3160': '\u1172',
  13489. '\u3161': '\u1173',
  13490. '\u3162': '\u1174',
  13491. '\u3163': '\u1175',
  13492. '\u3164': '\u1160',
  13493. '\u3165': '\u1114',
  13494. '\u3166': '\u1115',
  13495. '\u3167': '\u11C7',
  13496. '\u3168': '\u11C8',
  13497. '\u3169': '\u11CC',
  13498. '\u316A': '\u11CE',
  13499. '\u316B': '\u11D3',
  13500. '\u316C': '\u11D7',
  13501. '\u316D': '\u11D9',
  13502. '\u316E': '\u111C',
  13503. '\u316F': '\u11DD',
  13504. '\u3170': '\u11DF',
  13505. '\u3171': '\u111D',
  13506. '\u3172': '\u111E',
  13507. '\u3173': '\u1120',
  13508. '\u3174': '\u1122',
  13509. '\u3175': '\u1123',
  13510. '\u3176': '\u1127',
  13511. '\u3177': '\u1129',
  13512. '\u3178': '\u112B',
  13513. '\u3179': '\u112C',
  13514. '\u317A': '\u112D',
  13515. '\u317B': '\u112E',
  13516. '\u317C': '\u112F',
  13517. '\u317D': '\u1132',
  13518. '\u317E': '\u1136',
  13519. '\u317F': '\u1140',
  13520. '\u3180': '\u1147',
  13521. '\u3181': '\u114C',
  13522. '\u3182': '\u11F1',
  13523. '\u3183': '\u11F2',
  13524. '\u3184': '\u1157',
  13525. '\u3185': '\u1158',
  13526. '\u3186': '\u1159',
  13527. '\u3187': '\u1184',
  13528. '\u3188': '\u1185',
  13529. '\u3189': '\u1188',
  13530. '\u318A': '\u1191',
  13531. '\u318B': '\u1192',
  13532. '\u318C': '\u1194',
  13533. '\u318D': '\u119E',
  13534. '\u318E': '\u11A1',
  13535. '\u3200': '\u0028\u1100\u0029',
  13536. '\u3201': '\u0028\u1102\u0029',
  13537. '\u3202': '\u0028\u1103\u0029',
  13538. '\u3203': '\u0028\u1105\u0029',
  13539. '\u3204': '\u0028\u1106\u0029',
  13540. '\u3205': '\u0028\u1107\u0029',
  13541. '\u3206': '\u0028\u1109\u0029',
  13542. '\u3207': '\u0028\u110B\u0029',
  13543. '\u3208': '\u0028\u110C\u0029',
  13544. '\u3209': '\u0028\u110E\u0029',
  13545. '\u320A': '\u0028\u110F\u0029',
  13546. '\u320B': '\u0028\u1110\u0029',
  13547. '\u320C': '\u0028\u1111\u0029',
  13548. '\u320D': '\u0028\u1112\u0029',
  13549. '\u320E': '\u0028\u1100\u1161\u0029',
  13550. '\u320F': '\u0028\u1102\u1161\u0029',
  13551. '\u3210': '\u0028\u1103\u1161\u0029',
  13552. '\u3211': '\u0028\u1105\u1161\u0029',
  13553. '\u3212': '\u0028\u1106\u1161\u0029',
  13554. '\u3213': '\u0028\u1107\u1161\u0029',
  13555. '\u3214': '\u0028\u1109\u1161\u0029',
  13556. '\u3215': '\u0028\u110B\u1161\u0029',
  13557. '\u3216': '\u0028\u110C\u1161\u0029',
  13558. '\u3217': '\u0028\u110E\u1161\u0029',
  13559. '\u3218': '\u0028\u110F\u1161\u0029',
  13560. '\u3219': '\u0028\u1110\u1161\u0029',
  13561. '\u321A': '\u0028\u1111\u1161\u0029',
  13562. '\u321B': '\u0028\u1112\u1161\u0029',
  13563. '\u321C': '\u0028\u110C\u116E\u0029',
  13564. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  13565. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  13566. '\u3220': '\u0028\u4E00\u0029',
  13567. '\u3221': '\u0028\u4E8C\u0029',
  13568. '\u3222': '\u0028\u4E09\u0029',
  13569. '\u3223': '\u0028\u56DB\u0029',
  13570. '\u3224': '\u0028\u4E94\u0029',
  13571. '\u3225': '\u0028\u516D\u0029',
  13572. '\u3226': '\u0028\u4E03\u0029',
  13573. '\u3227': '\u0028\u516B\u0029',
  13574. '\u3228': '\u0028\u4E5D\u0029',
  13575. '\u3229': '\u0028\u5341\u0029',
  13576. '\u322A': '\u0028\u6708\u0029',
  13577. '\u322B': '\u0028\u706B\u0029',
  13578. '\u322C': '\u0028\u6C34\u0029',
  13579. '\u322D': '\u0028\u6728\u0029',
  13580. '\u322E': '\u0028\u91D1\u0029',
  13581. '\u322F': '\u0028\u571F\u0029',
  13582. '\u3230': '\u0028\u65E5\u0029',
  13583. '\u3231': '\u0028\u682A\u0029',
  13584. '\u3232': '\u0028\u6709\u0029',
  13585. '\u3233': '\u0028\u793E\u0029',
  13586. '\u3234': '\u0028\u540D\u0029',
  13587. '\u3235': '\u0028\u7279\u0029',
  13588. '\u3236': '\u0028\u8CA1\u0029',
  13589. '\u3237': '\u0028\u795D\u0029',
  13590. '\u3238': '\u0028\u52B4\u0029',
  13591. '\u3239': '\u0028\u4EE3\u0029',
  13592. '\u323A': '\u0028\u547C\u0029',
  13593. '\u323B': '\u0028\u5B66\u0029',
  13594. '\u323C': '\u0028\u76E3\u0029',
  13595. '\u323D': '\u0028\u4F01\u0029',
  13596. '\u323E': '\u0028\u8CC7\u0029',
  13597. '\u323F': '\u0028\u5354\u0029',
  13598. '\u3240': '\u0028\u796D\u0029',
  13599. '\u3241': '\u0028\u4F11\u0029',
  13600. '\u3242': '\u0028\u81EA\u0029',
  13601. '\u3243': '\u0028\u81F3\u0029',
  13602. '\u32C0': '\u0031\u6708',
  13603. '\u32C1': '\u0032\u6708',
  13604. '\u32C2': '\u0033\u6708',
  13605. '\u32C3': '\u0034\u6708',
  13606. '\u32C4': '\u0035\u6708',
  13607. '\u32C5': '\u0036\u6708',
  13608. '\u32C6': '\u0037\u6708',
  13609. '\u32C7': '\u0038\u6708',
  13610. '\u32C8': '\u0039\u6708',
  13611. '\u32C9': '\u0031\u0030\u6708',
  13612. '\u32CA': '\u0031\u0031\u6708',
  13613. '\u32CB': '\u0031\u0032\u6708',
  13614. '\u3358': '\u0030\u70B9',
  13615. '\u3359': '\u0031\u70B9',
  13616. '\u335A': '\u0032\u70B9',
  13617. '\u335B': '\u0033\u70B9',
  13618. '\u335C': '\u0034\u70B9',
  13619. '\u335D': '\u0035\u70B9',
  13620. '\u335E': '\u0036\u70B9',
  13621. '\u335F': '\u0037\u70B9',
  13622. '\u3360': '\u0038\u70B9',
  13623. '\u3361': '\u0039\u70B9',
  13624. '\u3362': '\u0031\u0030\u70B9',
  13625. '\u3363': '\u0031\u0031\u70B9',
  13626. '\u3364': '\u0031\u0032\u70B9',
  13627. '\u3365': '\u0031\u0033\u70B9',
  13628. '\u3366': '\u0031\u0034\u70B9',
  13629. '\u3367': '\u0031\u0035\u70B9',
  13630. '\u3368': '\u0031\u0036\u70B9',
  13631. '\u3369': '\u0031\u0037\u70B9',
  13632. '\u336A': '\u0031\u0038\u70B9',
  13633. '\u336B': '\u0031\u0039\u70B9',
  13634. '\u336C': '\u0032\u0030\u70B9',
  13635. '\u336D': '\u0032\u0031\u70B9',
  13636. '\u336E': '\u0032\u0032\u70B9',
  13637. '\u336F': '\u0032\u0033\u70B9',
  13638. '\u3370': '\u0032\u0034\u70B9',
  13639. '\u33E0': '\u0031\u65E5',
  13640. '\u33E1': '\u0032\u65E5',
  13641. '\u33E2': '\u0033\u65E5',
  13642. '\u33E3': '\u0034\u65E5',
  13643. '\u33E4': '\u0035\u65E5',
  13644. '\u33E5': '\u0036\u65E5',
  13645. '\u33E6': '\u0037\u65E5',
  13646. '\u33E7': '\u0038\u65E5',
  13647. '\u33E8': '\u0039\u65E5',
  13648. '\u33E9': '\u0031\u0030\u65E5',
  13649. '\u33EA': '\u0031\u0031\u65E5',
  13650. '\u33EB': '\u0031\u0032\u65E5',
  13651. '\u33EC': '\u0031\u0033\u65E5',
  13652. '\u33ED': '\u0031\u0034\u65E5',
  13653. '\u33EE': '\u0031\u0035\u65E5',
  13654. '\u33EF': '\u0031\u0036\u65E5',
  13655. '\u33F0': '\u0031\u0037\u65E5',
  13656. '\u33F1': '\u0031\u0038\u65E5',
  13657. '\u33F2': '\u0031\u0039\u65E5',
  13658. '\u33F3': '\u0032\u0030\u65E5',
  13659. '\u33F4': '\u0032\u0031\u65E5',
  13660. '\u33F5': '\u0032\u0032\u65E5',
  13661. '\u33F6': '\u0032\u0033\u65E5',
  13662. '\u33F7': '\u0032\u0034\u65E5',
  13663. '\u33F8': '\u0032\u0035\u65E5',
  13664. '\u33F9': '\u0032\u0036\u65E5',
  13665. '\u33FA': '\u0032\u0037\u65E5',
  13666. '\u33FB': '\u0032\u0038\u65E5',
  13667. '\u33FC': '\u0032\u0039\u65E5',
  13668. '\u33FD': '\u0033\u0030\u65E5',
  13669. '\u33FE': '\u0033\u0031\u65E5',
  13670. '\uFB00': '\u0066\u0066',
  13671. '\uFB01': '\u0066\u0069',
  13672. '\uFB02': '\u0066\u006C',
  13673. '\uFB03': '\u0066\u0066\u0069',
  13674. '\uFB04': '\u0066\u0066\u006C',
  13675. '\uFB05': '\u017F\u0074',
  13676. '\uFB06': '\u0073\u0074',
  13677. '\uFB13': '\u0574\u0576',
  13678. '\uFB14': '\u0574\u0565',
  13679. '\uFB15': '\u0574\u056B',
  13680. '\uFB16': '\u057E\u0576',
  13681. '\uFB17': '\u0574\u056D',
  13682. '\uFB4F': '\u05D0\u05DC',
  13683. '\uFB50': '\u0671',
  13684. '\uFB51': '\u0671',
  13685. '\uFB52': '\u067B',
  13686. '\uFB53': '\u067B',
  13687. '\uFB54': '\u067B',
  13688. '\uFB55': '\u067B',
  13689. '\uFB56': '\u067E',
  13690. '\uFB57': '\u067E',
  13691. '\uFB58': '\u067E',
  13692. '\uFB59': '\u067E',
  13693. '\uFB5A': '\u0680',
  13694. '\uFB5B': '\u0680',
  13695. '\uFB5C': '\u0680',
  13696. '\uFB5D': '\u0680',
  13697. '\uFB5E': '\u067A',
  13698. '\uFB5F': '\u067A',
  13699. '\uFB60': '\u067A',
  13700. '\uFB61': '\u067A',
  13701. '\uFB62': '\u067F',
  13702. '\uFB63': '\u067F',
  13703. '\uFB64': '\u067F',
  13704. '\uFB65': '\u067F',
  13705. '\uFB66': '\u0679',
  13706. '\uFB67': '\u0679',
  13707. '\uFB68': '\u0679',
  13708. '\uFB69': '\u0679',
  13709. '\uFB6A': '\u06A4',
  13710. '\uFB6B': '\u06A4',
  13711. '\uFB6C': '\u06A4',
  13712. '\uFB6D': '\u06A4',
  13713. '\uFB6E': '\u06A6',
  13714. '\uFB6F': '\u06A6',
  13715. '\uFB70': '\u06A6',
  13716. '\uFB71': '\u06A6',
  13717. '\uFB72': '\u0684',
  13718. '\uFB73': '\u0684',
  13719. '\uFB74': '\u0684',
  13720. '\uFB75': '\u0684',
  13721. '\uFB76': '\u0683',
  13722. '\uFB77': '\u0683',
  13723. '\uFB78': '\u0683',
  13724. '\uFB79': '\u0683',
  13725. '\uFB7A': '\u0686',
  13726. '\uFB7B': '\u0686',
  13727. '\uFB7C': '\u0686',
  13728. '\uFB7D': '\u0686',
  13729. '\uFB7E': '\u0687',
  13730. '\uFB7F': '\u0687',
  13731. '\uFB80': '\u0687',
  13732. '\uFB81': '\u0687',
  13733. '\uFB82': '\u068D',
  13734. '\uFB83': '\u068D',
  13735. '\uFB84': '\u068C',
  13736. '\uFB85': '\u068C',
  13737. '\uFB86': '\u068E',
  13738. '\uFB87': '\u068E',
  13739. '\uFB88': '\u0688',
  13740. '\uFB89': '\u0688',
  13741. '\uFB8A': '\u0698',
  13742. '\uFB8B': '\u0698',
  13743. '\uFB8C': '\u0691',
  13744. '\uFB8D': '\u0691',
  13745. '\uFB8E': '\u06A9',
  13746. '\uFB8F': '\u06A9',
  13747. '\uFB90': '\u06A9',
  13748. '\uFB91': '\u06A9',
  13749. '\uFB92': '\u06AF',
  13750. '\uFB93': '\u06AF',
  13751. '\uFB94': '\u06AF',
  13752. '\uFB95': '\u06AF',
  13753. '\uFB96': '\u06B3',
  13754. '\uFB97': '\u06B3',
  13755. '\uFB98': '\u06B3',
  13756. '\uFB99': '\u06B3',
  13757. '\uFB9A': '\u06B1',
  13758. '\uFB9B': '\u06B1',
  13759. '\uFB9C': '\u06B1',
  13760. '\uFB9D': '\u06B1',
  13761. '\uFB9E': '\u06BA',
  13762. '\uFB9F': '\u06BA',
  13763. '\uFBA0': '\u06BB',
  13764. '\uFBA1': '\u06BB',
  13765. '\uFBA2': '\u06BB',
  13766. '\uFBA3': '\u06BB',
  13767. '\uFBA4': '\u06C0',
  13768. '\uFBA5': '\u06C0',
  13769. '\uFBA6': '\u06C1',
  13770. '\uFBA7': '\u06C1',
  13771. '\uFBA8': '\u06C1',
  13772. '\uFBA9': '\u06C1',
  13773. '\uFBAA': '\u06BE',
  13774. '\uFBAB': '\u06BE',
  13775. '\uFBAC': '\u06BE',
  13776. '\uFBAD': '\u06BE',
  13777. '\uFBAE': '\u06D2',
  13778. '\uFBAF': '\u06D2',
  13779. '\uFBB0': '\u06D3',
  13780. '\uFBB1': '\u06D3',
  13781. '\uFBD3': '\u06AD',
  13782. '\uFBD4': '\u06AD',
  13783. '\uFBD5': '\u06AD',
  13784. '\uFBD6': '\u06AD',
  13785. '\uFBD7': '\u06C7',
  13786. '\uFBD8': '\u06C7',
  13787. '\uFBD9': '\u06C6',
  13788. '\uFBDA': '\u06C6',
  13789. '\uFBDB': '\u06C8',
  13790. '\uFBDC': '\u06C8',
  13791. '\uFBDD': '\u0677',
  13792. '\uFBDE': '\u06CB',
  13793. '\uFBDF': '\u06CB',
  13794. '\uFBE0': '\u06C5',
  13795. '\uFBE1': '\u06C5',
  13796. '\uFBE2': '\u06C9',
  13797. '\uFBE3': '\u06C9',
  13798. '\uFBE4': '\u06D0',
  13799. '\uFBE5': '\u06D0',
  13800. '\uFBE6': '\u06D0',
  13801. '\uFBE7': '\u06D0',
  13802. '\uFBE8': '\u0649',
  13803. '\uFBE9': '\u0649',
  13804. '\uFBEA': '\u0626\u0627',
  13805. '\uFBEB': '\u0626\u0627',
  13806. '\uFBEC': '\u0626\u06D5',
  13807. '\uFBED': '\u0626\u06D5',
  13808. '\uFBEE': '\u0626\u0648',
  13809. '\uFBEF': '\u0626\u0648',
  13810. '\uFBF0': '\u0626\u06C7',
  13811. '\uFBF1': '\u0626\u06C7',
  13812. '\uFBF2': '\u0626\u06C6',
  13813. '\uFBF3': '\u0626\u06C6',
  13814. '\uFBF4': '\u0626\u06C8',
  13815. '\uFBF5': '\u0626\u06C8',
  13816. '\uFBF6': '\u0626\u06D0',
  13817. '\uFBF7': '\u0626\u06D0',
  13818. '\uFBF8': '\u0626\u06D0',
  13819. '\uFBF9': '\u0626\u0649',
  13820. '\uFBFA': '\u0626\u0649',
  13821. '\uFBFB': '\u0626\u0649',
  13822. '\uFBFC': '\u06CC',
  13823. '\uFBFD': '\u06CC',
  13824. '\uFBFE': '\u06CC',
  13825. '\uFBFF': '\u06CC',
  13826. '\uFC00': '\u0626\u062C',
  13827. '\uFC01': '\u0626\u062D',
  13828. '\uFC02': '\u0626\u0645',
  13829. '\uFC03': '\u0626\u0649',
  13830. '\uFC04': '\u0626\u064A',
  13831. '\uFC05': '\u0628\u062C',
  13832. '\uFC06': '\u0628\u062D',
  13833. '\uFC07': '\u0628\u062E',
  13834. '\uFC08': '\u0628\u0645',
  13835. '\uFC09': '\u0628\u0649',
  13836. '\uFC0A': '\u0628\u064A',
  13837. '\uFC0B': '\u062A\u062C',
  13838. '\uFC0C': '\u062A\u062D',
  13839. '\uFC0D': '\u062A\u062E',
  13840. '\uFC0E': '\u062A\u0645',
  13841. '\uFC0F': '\u062A\u0649',
  13842. '\uFC10': '\u062A\u064A',
  13843. '\uFC11': '\u062B\u062C',
  13844. '\uFC12': '\u062B\u0645',
  13845. '\uFC13': '\u062B\u0649',
  13846. '\uFC14': '\u062B\u064A',
  13847. '\uFC15': '\u062C\u062D',
  13848. '\uFC16': '\u062C\u0645',
  13849. '\uFC17': '\u062D\u062C',
  13850. '\uFC18': '\u062D\u0645',
  13851. '\uFC19': '\u062E\u062C',
  13852. '\uFC1A': '\u062E\u062D',
  13853. '\uFC1B': '\u062E\u0645',
  13854. '\uFC1C': '\u0633\u062C',
  13855. '\uFC1D': '\u0633\u062D',
  13856. '\uFC1E': '\u0633\u062E',
  13857. '\uFC1F': '\u0633\u0645',
  13858. '\uFC20': '\u0635\u062D',
  13859. '\uFC21': '\u0635\u0645',
  13860. '\uFC22': '\u0636\u062C',
  13861. '\uFC23': '\u0636\u062D',
  13862. '\uFC24': '\u0636\u062E',
  13863. '\uFC25': '\u0636\u0645',
  13864. '\uFC26': '\u0637\u062D',
  13865. '\uFC27': '\u0637\u0645',
  13866. '\uFC28': '\u0638\u0645',
  13867. '\uFC29': '\u0639\u062C',
  13868. '\uFC2A': '\u0639\u0645',
  13869. '\uFC2B': '\u063A\u062C',
  13870. '\uFC2C': '\u063A\u0645',
  13871. '\uFC2D': '\u0641\u062C',
  13872. '\uFC2E': '\u0641\u062D',
  13873. '\uFC2F': '\u0641\u062E',
  13874. '\uFC30': '\u0641\u0645',
  13875. '\uFC31': '\u0641\u0649',
  13876. '\uFC32': '\u0641\u064A',
  13877. '\uFC33': '\u0642\u062D',
  13878. '\uFC34': '\u0642\u0645',
  13879. '\uFC35': '\u0642\u0649',
  13880. '\uFC36': '\u0642\u064A',
  13881. '\uFC37': '\u0643\u0627',
  13882. '\uFC38': '\u0643\u062C',
  13883. '\uFC39': '\u0643\u062D',
  13884. '\uFC3A': '\u0643\u062E',
  13885. '\uFC3B': '\u0643\u0644',
  13886. '\uFC3C': '\u0643\u0645',
  13887. '\uFC3D': '\u0643\u0649',
  13888. '\uFC3E': '\u0643\u064A',
  13889. '\uFC3F': '\u0644\u062C',
  13890. '\uFC40': '\u0644\u062D',
  13891. '\uFC41': '\u0644\u062E',
  13892. '\uFC42': '\u0644\u0645',
  13893. '\uFC43': '\u0644\u0649',
  13894. '\uFC44': '\u0644\u064A',
  13895. '\uFC45': '\u0645\u062C',
  13896. '\uFC46': '\u0645\u062D',
  13897. '\uFC47': '\u0645\u062E',
  13898. '\uFC48': '\u0645\u0645',
  13899. '\uFC49': '\u0645\u0649',
  13900. '\uFC4A': '\u0645\u064A',
  13901. '\uFC4B': '\u0646\u062C',
  13902. '\uFC4C': '\u0646\u062D',
  13903. '\uFC4D': '\u0646\u062E',
  13904. '\uFC4E': '\u0646\u0645',
  13905. '\uFC4F': '\u0646\u0649',
  13906. '\uFC50': '\u0646\u064A',
  13907. '\uFC51': '\u0647\u062C',
  13908. '\uFC52': '\u0647\u0645',
  13909. '\uFC53': '\u0647\u0649',
  13910. '\uFC54': '\u0647\u064A',
  13911. '\uFC55': '\u064A\u062C',
  13912. '\uFC56': '\u064A\u062D',
  13913. '\uFC57': '\u064A\u062E',
  13914. '\uFC58': '\u064A\u0645',
  13915. '\uFC59': '\u064A\u0649',
  13916. '\uFC5A': '\u064A\u064A',
  13917. '\uFC5B': '\u0630\u0670',
  13918. '\uFC5C': '\u0631\u0670',
  13919. '\uFC5D': '\u0649\u0670',
  13920. '\uFC5E': '\u0020\u064C\u0651',
  13921. '\uFC5F': '\u0020\u064D\u0651',
  13922. '\uFC60': '\u0020\u064E\u0651',
  13923. '\uFC61': '\u0020\u064F\u0651',
  13924. '\uFC62': '\u0020\u0650\u0651',
  13925. '\uFC63': '\u0020\u0651\u0670',
  13926. '\uFC64': '\u0626\u0631',
  13927. '\uFC65': '\u0626\u0632',
  13928. '\uFC66': '\u0626\u0645',
  13929. '\uFC67': '\u0626\u0646',
  13930. '\uFC68': '\u0626\u0649',
  13931. '\uFC69': '\u0626\u064A',
  13932. '\uFC6A': '\u0628\u0631',
  13933. '\uFC6B': '\u0628\u0632',
  13934. '\uFC6C': '\u0628\u0645',
  13935. '\uFC6D': '\u0628\u0646',
  13936. '\uFC6E': '\u0628\u0649',
  13937. '\uFC6F': '\u0628\u064A',
  13938. '\uFC70': '\u062A\u0631',
  13939. '\uFC71': '\u062A\u0632',
  13940. '\uFC72': '\u062A\u0645',
  13941. '\uFC73': '\u062A\u0646',
  13942. '\uFC74': '\u062A\u0649',
  13943. '\uFC75': '\u062A\u064A',
  13944. '\uFC76': '\u062B\u0631',
  13945. '\uFC77': '\u062B\u0632',
  13946. '\uFC78': '\u062B\u0645',
  13947. '\uFC79': '\u062B\u0646',
  13948. '\uFC7A': '\u062B\u0649',
  13949. '\uFC7B': '\u062B\u064A',
  13950. '\uFC7C': '\u0641\u0649',
  13951. '\uFC7D': '\u0641\u064A',
  13952. '\uFC7E': '\u0642\u0649',
  13953. '\uFC7F': '\u0642\u064A',
  13954. '\uFC80': '\u0643\u0627',
  13955. '\uFC81': '\u0643\u0644',
  13956. '\uFC82': '\u0643\u0645',
  13957. '\uFC83': '\u0643\u0649',
  13958. '\uFC84': '\u0643\u064A',
  13959. '\uFC85': '\u0644\u0645',
  13960. '\uFC86': '\u0644\u0649',
  13961. '\uFC87': '\u0644\u064A',
  13962. '\uFC88': '\u0645\u0627',
  13963. '\uFC89': '\u0645\u0645',
  13964. '\uFC8A': '\u0646\u0631',
  13965. '\uFC8B': '\u0646\u0632',
  13966. '\uFC8C': '\u0646\u0645',
  13967. '\uFC8D': '\u0646\u0646',
  13968. '\uFC8E': '\u0646\u0649',
  13969. '\uFC8F': '\u0646\u064A',
  13970. '\uFC90': '\u0649\u0670',
  13971. '\uFC91': '\u064A\u0631',
  13972. '\uFC92': '\u064A\u0632',
  13973. '\uFC93': '\u064A\u0645',
  13974. '\uFC94': '\u064A\u0646',
  13975. '\uFC95': '\u064A\u0649',
  13976. '\uFC96': '\u064A\u064A',
  13977. '\uFC97': '\u0626\u062C',
  13978. '\uFC98': '\u0626\u062D',
  13979. '\uFC99': '\u0626\u062E',
  13980. '\uFC9A': '\u0626\u0645',
  13981. '\uFC9B': '\u0626\u0647',
  13982. '\uFC9C': '\u0628\u062C',
  13983. '\uFC9D': '\u0628\u062D',
  13984. '\uFC9E': '\u0628\u062E',
  13985. '\uFC9F': '\u0628\u0645',
  13986. '\uFCA0': '\u0628\u0647',
  13987. '\uFCA1': '\u062A\u062C',
  13988. '\uFCA2': '\u062A\u062D',
  13989. '\uFCA3': '\u062A\u062E',
  13990. '\uFCA4': '\u062A\u0645',
  13991. '\uFCA5': '\u062A\u0647',
  13992. '\uFCA6': '\u062B\u0645',
  13993. '\uFCA7': '\u062C\u062D',
  13994. '\uFCA8': '\u062C\u0645',
  13995. '\uFCA9': '\u062D\u062C',
  13996. '\uFCAA': '\u062D\u0645',
  13997. '\uFCAB': '\u062E\u062C',
  13998. '\uFCAC': '\u062E\u0645',
  13999. '\uFCAD': '\u0633\u062C',
  14000. '\uFCAE': '\u0633\u062D',
  14001. '\uFCAF': '\u0633\u062E',
  14002. '\uFCB0': '\u0633\u0645',
  14003. '\uFCB1': '\u0635\u062D',
  14004. '\uFCB2': '\u0635\u062E',
  14005. '\uFCB3': '\u0635\u0645',
  14006. '\uFCB4': '\u0636\u062C',
  14007. '\uFCB5': '\u0636\u062D',
  14008. '\uFCB6': '\u0636\u062E',
  14009. '\uFCB7': '\u0636\u0645',
  14010. '\uFCB8': '\u0637\u062D',
  14011. '\uFCB9': '\u0638\u0645',
  14012. '\uFCBA': '\u0639\u062C',
  14013. '\uFCBB': '\u0639\u0645',
  14014. '\uFCBC': '\u063A\u062C',
  14015. '\uFCBD': '\u063A\u0645',
  14016. '\uFCBE': '\u0641\u062C',
  14017. '\uFCBF': '\u0641\u062D',
  14018. '\uFCC0': '\u0641\u062E',
  14019. '\uFCC1': '\u0641\u0645',
  14020. '\uFCC2': '\u0642\u062D',
  14021. '\uFCC3': '\u0642\u0645',
  14022. '\uFCC4': '\u0643\u062C',
  14023. '\uFCC5': '\u0643\u062D',
  14024. '\uFCC6': '\u0643\u062E',
  14025. '\uFCC7': '\u0643\u0644',
  14026. '\uFCC8': '\u0643\u0645',
  14027. '\uFCC9': '\u0644\u062C',
  14028. '\uFCCA': '\u0644\u062D',
  14029. '\uFCCB': '\u0644\u062E',
  14030. '\uFCCC': '\u0644\u0645',
  14031. '\uFCCD': '\u0644\u0647',
  14032. '\uFCCE': '\u0645\u062C',
  14033. '\uFCCF': '\u0645\u062D',
  14034. '\uFCD0': '\u0645\u062E',
  14035. '\uFCD1': '\u0645\u0645',
  14036. '\uFCD2': '\u0646\u062C',
  14037. '\uFCD3': '\u0646\u062D',
  14038. '\uFCD4': '\u0646\u062E',
  14039. '\uFCD5': '\u0646\u0645',
  14040. '\uFCD6': '\u0646\u0647',
  14041. '\uFCD7': '\u0647\u062C',
  14042. '\uFCD8': '\u0647\u0645',
  14043. '\uFCD9': '\u0647\u0670',
  14044. '\uFCDA': '\u064A\u062C',
  14045. '\uFCDB': '\u064A\u062D',
  14046. '\uFCDC': '\u064A\u062E',
  14047. '\uFCDD': '\u064A\u0645',
  14048. '\uFCDE': '\u064A\u0647',
  14049. '\uFCDF': '\u0626\u0645',
  14050. '\uFCE0': '\u0626\u0647',
  14051. '\uFCE1': '\u0628\u0645',
  14052. '\uFCE2': '\u0628\u0647',
  14053. '\uFCE3': '\u062A\u0645',
  14054. '\uFCE4': '\u062A\u0647',
  14055. '\uFCE5': '\u062B\u0645',
  14056. '\uFCE6': '\u062B\u0647',
  14057. '\uFCE7': '\u0633\u0645',
  14058. '\uFCE8': '\u0633\u0647',
  14059. '\uFCE9': '\u0634\u0645',
  14060. '\uFCEA': '\u0634\u0647',
  14061. '\uFCEB': '\u0643\u0644',
  14062. '\uFCEC': '\u0643\u0645',
  14063. '\uFCED': '\u0644\u0645',
  14064. '\uFCEE': '\u0646\u0645',
  14065. '\uFCEF': '\u0646\u0647',
  14066. '\uFCF0': '\u064A\u0645',
  14067. '\uFCF1': '\u064A\u0647',
  14068. '\uFCF2': '\u0640\u064E\u0651',
  14069. '\uFCF3': '\u0640\u064F\u0651',
  14070. '\uFCF4': '\u0640\u0650\u0651',
  14071. '\uFCF5': '\u0637\u0649',
  14072. '\uFCF6': '\u0637\u064A',
  14073. '\uFCF7': '\u0639\u0649',
  14074. '\uFCF8': '\u0639\u064A',
  14075. '\uFCF9': '\u063A\u0649',
  14076. '\uFCFA': '\u063A\u064A',
  14077. '\uFCFB': '\u0633\u0649',
  14078. '\uFCFC': '\u0633\u064A',
  14079. '\uFCFD': '\u0634\u0649',
  14080. '\uFCFE': '\u0634\u064A',
  14081. '\uFCFF': '\u062D\u0649',
  14082. '\uFD00': '\u062D\u064A',
  14083. '\uFD01': '\u062C\u0649',
  14084. '\uFD02': '\u062C\u064A',
  14085. '\uFD03': '\u062E\u0649',
  14086. '\uFD04': '\u062E\u064A',
  14087. '\uFD05': '\u0635\u0649',
  14088. '\uFD06': '\u0635\u064A',
  14089. '\uFD07': '\u0636\u0649',
  14090. '\uFD08': '\u0636\u064A',
  14091. '\uFD09': '\u0634\u062C',
  14092. '\uFD0A': '\u0634\u062D',
  14093. '\uFD0B': '\u0634\u062E',
  14094. '\uFD0C': '\u0634\u0645',
  14095. '\uFD0D': '\u0634\u0631',
  14096. '\uFD0E': '\u0633\u0631',
  14097. '\uFD0F': '\u0635\u0631',
  14098. '\uFD10': '\u0636\u0631',
  14099. '\uFD11': '\u0637\u0649',
  14100. '\uFD12': '\u0637\u064A',
  14101. '\uFD13': '\u0639\u0649',
  14102. '\uFD14': '\u0639\u064A',
  14103. '\uFD15': '\u063A\u0649',
  14104. '\uFD16': '\u063A\u064A',
  14105. '\uFD17': '\u0633\u0649',
  14106. '\uFD18': '\u0633\u064A',
  14107. '\uFD19': '\u0634\u0649',
  14108. '\uFD1A': '\u0634\u064A',
  14109. '\uFD1B': '\u062D\u0649',
  14110. '\uFD1C': '\u062D\u064A',
  14111. '\uFD1D': '\u062C\u0649',
  14112. '\uFD1E': '\u062C\u064A',
  14113. '\uFD1F': '\u062E\u0649',
  14114. '\uFD20': '\u062E\u064A',
  14115. '\uFD21': '\u0635\u0649',
  14116. '\uFD22': '\u0635\u064A',
  14117. '\uFD23': '\u0636\u0649',
  14118. '\uFD24': '\u0636\u064A',
  14119. '\uFD25': '\u0634\u062C',
  14120. '\uFD26': '\u0634\u062D',
  14121. '\uFD27': '\u0634\u062E',
  14122. '\uFD28': '\u0634\u0645',
  14123. '\uFD29': '\u0634\u0631',
  14124. '\uFD2A': '\u0633\u0631',
  14125. '\uFD2B': '\u0635\u0631',
  14126. '\uFD2C': '\u0636\u0631',
  14127. '\uFD2D': '\u0634\u062C',
  14128. '\uFD2E': '\u0634\u062D',
  14129. '\uFD2F': '\u0634\u062E',
  14130. '\uFD30': '\u0634\u0645',
  14131. '\uFD31': '\u0633\u0647',
  14132. '\uFD32': '\u0634\u0647',
  14133. '\uFD33': '\u0637\u0645',
  14134. '\uFD34': '\u0633\u062C',
  14135. '\uFD35': '\u0633\u062D',
  14136. '\uFD36': '\u0633\u062E',
  14137. '\uFD37': '\u0634\u062C',
  14138. '\uFD38': '\u0634\u062D',
  14139. '\uFD39': '\u0634\u062E',
  14140. '\uFD3A': '\u0637\u0645',
  14141. '\uFD3B': '\u0638\u0645',
  14142. '\uFD3C': '\u0627\u064B',
  14143. '\uFD3D': '\u0627\u064B',
  14144. '\uFD50': '\u062A\u062C\u0645',
  14145. '\uFD51': '\u062A\u062D\u062C',
  14146. '\uFD52': '\u062A\u062D\u062C',
  14147. '\uFD53': '\u062A\u062D\u0645',
  14148. '\uFD54': '\u062A\u062E\u0645',
  14149. '\uFD55': '\u062A\u0645\u062C',
  14150. '\uFD56': '\u062A\u0645\u062D',
  14151. '\uFD57': '\u062A\u0645\u062E',
  14152. '\uFD58': '\u062C\u0645\u062D',
  14153. '\uFD59': '\u062C\u0645\u062D',
  14154. '\uFD5A': '\u062D\u0645\u064A',
  14155. '\uFD5B': '\u062D\u0645\u0649',
  14156. '\uFD5C': '\u0633\u062D\u062C',
  14157. '\uFD5D': '\u0633\u062C\u062D',
  14158. '\uFD5E': '\u0633\u062C\u0649',
  14159. '\uFD5F': '\u0633\u0645\u062D',
  14160. '\uFD60': '\u0633\u0645\u062D',
  14161. '\uFD61': '\u0633\u0645\u062C',
  14162. '\uFD62': '\u0633\u0645\u0645',
  14163. '\uFD63': '\u0633\u0645\u0645',
  14164. '\uFD64': '\u0635\u062D\u062D',
  14165. '\uFD65': '\u0635\u062D\u062D',
  14166. '\uFD66': '\u0635\u0645\u0645',
  14167. '\uFD67': '\u0634\u062D\u0645',
  14168. '\uFD68': '\u0634\u062D\u0645',
  14169. '\uFD69': '\u0634\u062C\u064A',
  14170. '\uFD6A': '\u0634\u0645\u062E',
  14171. '\uFD6B': '\u0634\u0645\u062E',
  14172. '\uFD6C': '\u0634\u0645\u0645',
  14173. '\uFD6D': '\u0634\u0645\u0645',
  14174. '\uFD6E': '\u0636\u062D\u0649',
  14175. '\uFD6F': '\u0636\u062E\u0645',
  14176. '\uFD70': '\u0636\u062E\u0645',
  14177. '\uFD71': '\u0637\u0645\u062D',
  14178. '\uFD72': '\u0637\u0645\u062D',
  14179. '\uFD73': '\u0637\u0645\u0645',
  14180. '\uFD74': '\u0637\u0645\u064A',
  14181. '\uFD75': '\u0639\u062C\u0645',
  14182. '\uFD76': '\u0639\u0645\u0645',
  14183. '\uFD77': '\u0639\u0645\u0645',
  14184. '\uFD78': '\u0639\u0645\u0649',
  14185. '\uFD79': '\u063A\u0645\u0645',
  14186. '\uFD7A': '\u063A\u0645\u064A',
  14187. '\uFD7B': '\u063A\u0645\u0649',
  14188. '\uFD7C': '\u0641\u062E\u0645',
  14189. '\uFD7D': '\u0641\u062E\u0645',
  14190. '\uFD7E': '\u0642\u0645\u062D',
  14191. '\uFD7F': '\u0642\u0645\u0645',
  14192. '\uFD80': '\u0644\u062D\u0645',
  14193. '\uFD81': '\u0644\u062D\u064A',
  14194. '\uFD82': '\u0644\u062D\u0649',
  14195. '\uFD83': '\u0644\u062C\u062C',
  14196. '\uFD84': '\u0644\u062C\u062C',
  14197. '\uFD85': '\u0644\u062E\u0645',
  14198. '\uFD86': '\u0644\u062E\u0645',
  14199. '\uFD87': '\u0644\u0645\u062D',
  14200. '\uFD88': '\u0644\u0645\u062D',
  14201. '\uFD89': '\u0645\u062D\u062C',
  14202. '\uFD8A': '\u0645\u062D\u0645',
  14203. '\uFD8B': '\u0645\u062D\u064A',
  14204. '\uFD8C': '\u0645\u062C\u062D',
  14205. '\uFD8D': '\u0645\u062C\u0645',
  14206. '\uFD8E': '\u0645\u062E\u062C',
  14207. '\uFD8F': '\u0645\u062E\u0645',
  14208. '\uFD92': '\u0645\u062C\u062E',
  14209. '\uFD93': '\u0647\u0645\u062C',
  14210. '\uFD94': '\u0647\u0645\u0645',
  14211. '\uFD95': '\u0646\u062D\u0645',
  14212. '\uFD96': '\u0646\u062D\u0649',
  14213. '\uFD97': '\u0646\u062C\u0645',
  14214. '\uFD98': '\u0646\u062C\u0645',
  14215. '\uFD99': '\u0646\u062C\u0649',
  14216. '\uFD9A': '\u0646\u0645\u064A',
  14217. '\uFD9B': '\u0646\u0645\u0649',
  14218. '\uFD9C': '\u064A\u0645\u0645',
  14219. '\uFD9D': '\u064A\u0645\u0645',
  14220. '\uFD9E': '\u0628\u062E\u064A',
  14221. '\uFD9F': '\u062A\u062C\u064A',
  14222. '\uFDA0': '\u062A\u062C\u0649',
  14223. '\uFDA1': '\u062A\u062E\u064A',
  14224. '\uFDA2': '\u062A\u062E\u0649',
  14225. '\uFDA3': '\u062A\u0645\u064A',
  14226. '\uFDA4': '\u062A\u0645\u0649',
  14227. '\uFDA5': '\u062C\u0645\u064A',
  14228. '\uFDA6': '\u062C\u062D\u0649',
  14229. '\uFDA7': '\u062C\u0645\u0649',
  14230. '\uFDA8': '\u0633\u062E\u0649',
  14231. '\uFDA9': '\u0635\u062D\u064A',
  14232. '\uFDAA': '\u0634\u062D\u064A',
  14233. '\uFDAB': '\u0636\u062D\u064A',
  14234. '\uFDAC': '\u0644\u062C\u064A',
  14235. '\uFDAD': '\u0644\u0645\u064A',
  14236. '\uFDAE': '\u064A\u062D\u064A',
  14237. '\uFDAF': '\u064A\u062C\u064A',
  14238. '\uFDB0': '\u064A\u0645\u064A',
  14239. '\uFDB1': '\u0645\u0645\u064A',
  14240. '\uFDB2': '\u0642\u0645\u064A',
  14241. '\uFDB3': '\u0646\u062D\u064A',
  14242. '\uFDB4': '\u0642\u0645\u062D',
  14243. '\uFDB5': '\u0644\u062D\u0645',
  14244. '\uFDB6': '\u0639\u0645\u064A',
  14245. '\uFDB7': '\u0643\u0645\u064A',
  14246. '\uFDB8': '\u0646\u062C\u062D',
  14247. '\uFDB9': '\u0645\u062E\u064A',
  14248. '\uFDBA': '\u0644\u062C\u0645',
  14249. '\uFDBB': '\u0643\u0645\u0645',
  14250. '\uFDBC': '\u0644\u062C\u0645',
  14251. '\uFDBD': '\u0646\u062C\u062D',
  14252. '\uFDBE': '\u062C\u062D\u064A',
  14253. '\uFDBF': '\u062D\u062C\u064A',
  14254. '\uFDC0': '\u0645\u062C\u064A',
  14255. '\uFDC1': '\u0641\u0645\u064A',
  14256. '\uFDC2': '\u0628\u062D\u064A',
  14257. '\uFDC3': '\u0643\u0645\u0645',
  14258. '\uFDC4': '\u0639\u062C\u0645',
  14259. '\uFDC5': '\u0635\u0645\u0645',
  14260. '\uFDC6': '\u0633\u062E\u064A',
  14261. '\uFDC7': '\u0646\u062C\u064A',
  14262. '\uFE49': '\u203E',
  14263. '\uFE4A': '\u203E',
  14264. '\uFE4B': '\u203E',
  14265. '\uFE4C': '\u203E',
  14266. '\uFE4D': '\u005F',
  14267. '\uFE4E': '\u005F',
  14268. '\uFE4F': '\u005F',
  14269. '\uFE80': '\u0621',
  14270. '\uFE81': '\u0622',
  14271. '\uFE82': '\u0622',
  14272. '\uFE83': '\u0623',
  14273. '\uFE84': '\u0623',
  14274. '\uFE85': '\u0624',
  14275. '\uFE86': '\u0624',
  14276. '\uFE87': '\u0625',
  14277. '\uFE88': '\u0625',
  14278. '\uFE89': '\u0626',
  14279. '\uFE8A': '\u0626',
  14280. '\uFE8B': '\u0626',
  14281. '\uFE8C': '\u0626',
  14282. '\uFE8D': '\u0627',
  14283. '\uFE8E': '\u0627',
  14284. '\uFE8F': '\u0628',
  14285. '\uFE90': '\u0628',
  14286. '\uFE91': '\u0628',
  14287. '\uFE92': '\u0628',
  14288. '\uFE93': '\u0629',
  14289. '\uFE94': '\u0629',
  14290. '\uFE95': '\u062A',
  14291. '\uFE96': '\u062A',
  14292. '\uFE97': '\u062A',
  14293. '\uFE98': '\u062A',
  14294. '\uFE99': '\u062B',
  14295. '\uFE9A': '\u062B',
  14296. '\uFE9B': '\u062B',
  14297. '\uFE9C': '\u062B',
  14298. '\uFE9D': '\u062C',
  14299. '\uFE9E': '\u062C',
  14300. '\uFE9F': '\u062C',
  14301. '\uFEA0': '\u062C',
  14302. '\uFEA1': '\u062D',
  14303. '\uFEA2': '\u062D',
  14304. '\uFEA3': '\u062D',
  14305. '\uFEA4': '\u062D',
  14306. '\uFEA5': '\u062E',
  14307. '\uFEA6': '\u062E',
  14308. '\uFEA7': '\u062E',
  14309. '\uFEA8': '\u062E',
  14310. '\uFEA9': '\u062F',
  14311. '\uFEAA': '\u062F',
  14312. '\uFEAB': '\u0630',
  14313. '\uFEAC': '\u0630',
  14314. '\uFEAD': '\u0631',
  14315. '\uFEAE': '\u0631',
  14316. '\uFEAF': '\u0632',
  14317. '\uFEB0': '\u0632',
  14318. '\uFEB1': '\u0633',
  14319. '\uFEB2': '\u0633',
  14320. '\uFEB3': '\u0633',
  14321. '\uFEB4': '\u0633',
  14322. '\uFEB5': '\u0634',
  14323. '\uFEB6': '\u0634',
  14324. '\uFEB7': '\u0634',
  14325. '\uFEB8': '\u0634',
  14326. '\uFEB9': '\u0635',
  14327. '\uFEBA': '\u0635',
  14328. '\uFEBB': '\u0635',
  14329. '\uFEBC': '\u0635',
  14330. '\uFEBD': '\u0636',
  14331. '\uFEBE': '\u0636',
  14332. '\uFEBF': '\u0636',
  14333. '\uFEC0': '\u0636',
  14334. '\uFEC1': '\u0637',
  14335. '\uFEC2': '\u0637',
  14336. '\uFEC3': '\u0637',
  14337. '\uFEC4': '\u0637',
  14338. '\uFEC5': '\u0638',
  14339. '\uFEC6': '\u0638',
  14340. '\uFEC7': '\u0638',
  14341. '\uFEC8': '\u0638',
  14342. '\uFEC9': '\u0639',
  14343. '\uFECA': '\u0639',
  14344. '\uFECB': '\u0639',
  14345. '\uFECC': '\u0639',
  14346. '\uFECD': '\u063A',
  14347. '\uFECE': '\u063A',
  14348. '\uFECF': '\u063A',
  14349. '\uFED0': '\u063A',
  14350. '\uFED1': '\u0641',
  14351. '\uFED2': '\u0641',
  14352. '\uFED3': '\u0641',
  14353. '\uFED4': '\u0641',
  14354. '\uFED5': '\u0642',
  14355. '\uFED6': '\u0642',
  14356. '\uFED7': '\u0642',
  14357. '\uFED8': '\u0642',
  14358. '\uFED9': '\u0643',
  14359. '\uFEDA': '\u0643',
  14360. '\uFEDB': '\u0643',
  14361. '\uFEDC': '\u0643',
  14362. '\uFEDD': '\u0644',
  14363. '\uFEDE': '\u0644',
  14364. '\uFEDF': '\u0644',
  14365. '\uFEE0': '\u0644',
  14366. '\uFEE1': '\u0645',
  14367. '\uFEE2': '\u0645',
  14368. '\uFEE3': '\u0645',
  14369. '\uFEE4': '\u0645',
  14370. '\uFEE5': '\u0646',
  14371. '\uFEE6': '\u0646',
  14372. '\uFEE7': '\u0646',
  14373. '\uFEE8': '\u0646',
  14374. '\uFEE9': '\u0647',
  14375. '\uFEEA': '\u0647',
  14376. '\uFEEB': '\u0647',
  14377. '\uFEEC': '\u0647',
  14378. '\uFEED': '\u0648',
  14379. '\uFEEE': '\u0648',
  14380. '\uFEEF': '\u0649',
  14381. '\uFEF0': '\u0649',
  14382. '\uFEF1': '\u064A',
  14383. '\uFEF2': '\u064A',
  14384. '\uFEF3': '\u064A',
  14385. '\uFEF4': '\u064A',
  14386. '\uFEF5': '\u0644\u0622',
  14387. '\uFEF6': '\u0644\u0622',
  14388. '\uFEF7': '\u0644\u0623',
  14389. '\uFEF8': '\u0644\u0623',
  14390. '\uFEF9': '\u0644\u0625',
  14391. '\uFEFA': '\u0644\u0625',
  14392. '\uFEFB': '\u0644\u0627',
  14393. '\uFEFC': '\u0644\u0627'
  14394. };
  14395. function reverseIfRtl(chars) {
  14396. var charsLength = chars.length;
  14397. //reverse an arabic ligature
  14398. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14399. return chars;
  14400. }
  14401. var s = '';
  14402. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14403. s += chars[ii];
  14404. }
  14405. return s;
  14406. }
  14407. function adjustWidths(properties) {
  14408. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14409. return;
  14410. }
  14411. // adjusting width to fontMatrix scale
  14412. var scale = 0.001 / properties.fontMatrix[0];
  14413. var glyphsWidths = properties.widths;
  14414. for (var glyph in glyphsWidths) {
  14415. glyphsWidths[glyph] *= scale;
  14416. }
  14417. properties.defaultWidth *= scale;
  14418. }
  14419. function getFontType(type, subtype) {
  14420. switch (type) {
  14421. case 'Type1':
  14422. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14423. case 'CIDFontType0':
  14424. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14425. FontType.CIDFONTTYPE0;
  14426. case 'OpenType':
  14427. return FontType.OPENTYPE;
  14428. case 'TrueType':
  14429. return FontType.TRUETYPE;
  14430. case 'CIDFontType2':
  14431. return FontType.CIDFONTTYPE2;
  14432. case 'MMType1':
  14433. return FontType.MMTYPE1;
  14434. case 'Type0':
  14435. return FontType.TYPE0;
  14436. default:
  14437. return FontType.UNKNOWN;
  14438. }
  14439. }
  14440. var Glyph = (function GlyphClosure() {
  14441. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14442. this.fontChar = fontChar;
  14443. this.unicode = unicode;
  14444. this.accent = accent;
  14445. this.width = width;
  14446. this.vmetric = vmetric;
  14447. this.operatorListId = operatorListId;
  14448. }
  14449. Glyph.prototype.matchesForCache =
  14450. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14451. return this.fontChar === fontChar &&
  14452. this.unicode === unicode &&
  14453. this.accent === accent &&
  14454. this.width === width &&
  14455. this.vmetric === vmetric &&
  14456. this.operatorListId === operatorListId;
  14457. };
  14458. return Glyph;
  14459. })();
  14460. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14461. function ToUnicodeMap(cmap) {
  14462. // The elements of this._map can be integers or strings, depending on how
  14463. // |cmap| was created.
  14464. this._map = cmap;
  14465. }
  14466. ToUnicodeMap.prototype = {
  14467. get length() {
  14468. return this._map.length;
  14469. },
  14470. forEach: function(callback) {
  14471. for (var charCode in this._map) {
  14472. callback(charCode, this._map[charCode].charCodeAt(0));
  14473. }
  14474. },
  14475. get: function(i) {
  14476. return this._map[i];
  14477. },
  14478. charCodeOf: function(v) {
  14479. return this._map.indexOf(v);
  14480. }
  14481. };
  14482. return ToUnicodeMap;
  14483. })();
  14484. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14485. function IdentityToUnicodeMap(firstChar, lastChar) {
  14486. this.firstChar = firstChar;
  14487. this.lastChar = lastChar;
  14488. }
  14489. IdentityToUnicodeMap.prototype = {
  14490. get length() {
  14491. error('should not access .length');
  14492. },
  14493. forEach: function (callback) {
  14494. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  14495. callback(i, i);
  14496. }
  14497. },
  14498. get: function (i) {
  14499. if (this.firstChar <= i && i <= this.lastChar) {
  14500. return String.fromCharCode(i);
  14501. }
  14502. return undefined;
  14503. },
  14504. charCodeOf: function (v) {
  14505. error('should not call .charCodeOf');
  14506. }
  14507. };
  14508. return IdentityToUnicodeMap;
  14509. })();
  14510. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  14511. function writeInt16(dest, offset, num) {
  14512. dest[offset] = (num >> 8) & 0xFF;
  14513. dest[offset + 1] = num & 0xFF;
  14514. }
  14515. function writeInt32(dest, offset, num) {
  14516. dest[offset] = (num >> 24) & 0xFF;
  14517. dest[offset + 1] = (num >> 16) & 0xFF;
  14518. dest[offset + 2] = (num >> 8) & 0xFF;
  14519. dest[offset + 3] = num & 0xFF;
  14520. }
  14521. function writeData(dest, offset, data) {
  14522. var i, ii;
  14523. if (data instanceof Uint8Array) {
  14524. dest.set(data, offset);
  14525. } else if (typeof data === 'string') {
  14526. for (i = 0, ii = data.length; i < ii; i++) {
  14527. dest[offset++] = data.charCodeAt(i) & 0xFF;
  14528. }
  14529. } else {
  14530. // treating everything else as array
  14531. for (i = 0, ii = data.length; i < ii; i++) {
  14532. dest[offset++] = data[i] & 0xFF;
  14533. }
  14534. }
  14535. }
  14536. function OpenTypeFileBuilder(sfnt) {
  14537. this.sfnt = sfnt;
  14538. this.tables = Object.create(null);
  14539. }
  14540. OpenTypeFileBuilder.getSearchParams =
  14541. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  14542. var maxPower2 = 1, log2 = 0;
  14543. while ((maxPower2 ^ entriesCount) > maxPower2) {
  14544. maxPower2 <<= 1;
  14545. log2++;
  14546. }
  14547. var searchRange = maxPower2 * entrySize;
  14548. return {
  14549. range: searchRange,
  14550. entry: log2,
  14551. rangeShift: entrySize * entriesCount - searchRange
  14552. };
  14553. };
  14554. var OTF_HEADER_SIZE = 12;
  14555. var OTF_TABLE_ENTRY_SIZE = 16;
  14556. OpenTypeFileBuilder.prototype = {
  14557. toArray: function OpenTypeFileBuilder_toArray() {
  14558. var sfnt = this.sfnt;
  14559. // Tables needs to be written by ascendant alphabetic order
  14560. var tables = this.tables;
  14561. var tablesNames = Object.keys(tables);
  14562. tablesNames.sort();
  14563. var numTables = tablesNames.length;
  14564. var i, j, jj, table, tableName;
  14565. // layout the tables data
  14566. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  14567. var tableOffsets = [offset];
  14568. for (i = 0; i < numTables; i++) {
  14569. table = tables[tablesNames[i]];
  14570. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  14571. offset += paddedLength;
  14572. tableOffsets.push(offset);
  14573. }
  14574. var file = new Uint8Array(offset);
  14575. // write the table data first (mostly for checksum)
  14576. for (i = 0; i < numTables; i++) {
  14577. table = tables[tablesNames[i]];
  14578. writeData(file, tableOffsets[i], table);
  14579. }
  14580. // sfnt version (4 bytes)
  14581. if (sfnt === 'true') {
  14582. // Windows hates the Mac TrueType sfnt version number
  14583. sfnt = string32(0x00010000);
  14584. }
  14585. file[0] = sfnt.charCodeAt(0) & 0xFF;
  14586. file[1] = sfnt.charCodeAt(1) & 0xFF;
  14587. file[2] = sfnt.charCodeAt(2) & 0xFF;
  14588. file[3] = sfnt.charCodeAt(3) & 0xFF;
  14589. // numTables (2 bytes)
  14590. writeInt16(file, 4, numTables);
  14591. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  14592. // searchRange (2 bytes)
  14593. writeInt16(file, 6, searchParams.range);
  14594. // entrySelector (2 bytes)
  14595. writeInt16(file, 8, searchParams.entry);
  14596. // rangeShift (2 bytes)
  14597. writeInt16(file, 10, searchParams.rangeShift);
  14598. offset = OTF_HEADER_SIZE;
  14599. // writing table entries
  14600. for (i = 0; i < numTables; i++) {
  14601. tableName = tablesNames[i];
  14602. file[offset] = tableName.charCodeAt(0) & 0xFF;
  14603. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  14604. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  14605. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  14606. // checksum
  14607. var checksum = 0;
  14608. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  14609. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  14610. (file[j + 2] << 8) + file[j + 3];
  14611. checksum = (checksum + quad) | 0;
  14612. }
  14613. writeInt32(file, offset + 4, checksum);
  14614. // offset
  14615. writeInt32(file, offset + 8, tableOffsets[i]);
  14616. // length
  14617. writeInt32(file, offset + 12, tables[tableName].length);
  14618. offset += OTF_TABLE_ENTRY_SIZE;
  14619. }
  14620. return file;
  14621. },
  14622. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  14623. if (tag in this.tables) {
  14624. throw new Error('Table ' + tag + ' already exists');
  14625. }
  14626. this.tables[tag] = data;
  14627. }
  14628. };
  14629. return OpenTypeFileBuilder;
  14630. })();
  14631. /**
  14632. * 'Font' is the class the outside world should use, it encapsulate all the font
  14633. * decoding logics whatever type it is (assuming the font type is supported).
  14634. *
  14635. * For example to read a Type1 font and to attach it to the document:
  14636. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  14637. * type1Font.bind();
  14638. */
  14639. var Font = (function FontClosure() {
  14640. function Font(name, file, properties) {
  14641. var charCode, glyphName;
  14642. this.name = name;
  14643. this.loadedName = properties.loadedName;
  14644. this.isType3Font = properties.isType3Font;
  14645. this.sizes = [];
  14646. this.glyphCache = {};
  14647. var names = name.split('+');
  14648. names = names.length > 1 ? names[1] : names[0];
  14649. names = names.split(/[-,_]/g)[0];
  14650. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  14651. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  14652. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  14653. var type = properties.type;
  14654. var subtype = properties.subtype;
  14655. this.type = type;
  14656. this.fallbackName = (this.isMonospace ? 'monospace' :
  14657. (this.isSerifFont ? 'serif' : 'sans-serif'));
  14658. this.differences = properties.differences;
  14659. this.widths = properties.widths;
  14660. this.defaultWidth = properties.defaultWidth;
  14661. this.composite = properties.composite;
  14662. this.wideChars = properties.wideChars;
  14663. this.cMap = properties.cMap;
  14664. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  14665. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  14666. this.fontMatrix = properties.fontMatrix;
  14667. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  14668. this.toFontChar = [];
  14669. if (properties.type === 'Type3') {
  14670. for (charCode = 0; charCode < 256; charCode++) {
  14671. this.toFontChar[charCode] = (this.differences[charCode] ||
  14672. properties.defaultEncoding[charCode]);
  14673. }
  14674. this.fontType = FontType.TYPE3;
  14675. return;
  14676. }
  14677. this.cidEncoding = properties.cidEncoding;
  14678. this.vertical = properties.vertical;
  14679. if (this.vertical) {
  14680. this.vmetrics = properties.vmetrics;
  14681. this.defaultVMetrics = properties.defaultVMetrics;
  14682. }
  14683. if (!file || file.isEmpty) {
  14684. if (file) {
  14685. // Some bad PDF generators will include empty font files,
  14686. // attempting to recover by assuming that no file exists.
  14687. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  14688. }
  14689. this.missingFile = true;
  14690. // The file data is not specified. Trying to fix the font name
  14691. // to be used with the canvas.font.
  14692. var fontName = name.replace(/[,_]/g, '-');
  14693. var isStandardFont = fontName in stdFontMap;
  14694. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  14695. this.bold = (fontName.search(/bold/gi) !== -1);
  14696. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  14697. (fontName.search(/italic/gi) !== -1));
  14698. // Use 'name' instead of 'fontName' here because the original
  14699. // name ArialBlack for example will be replaced by Helvetica.
  14700. this.black = (name.search(/Black/g) !== -1);
  14701. // if at least one width is present, remeasure all chars when exists
  14702. this.remeasure = Object.keys(this.widths).length > 0;
  14703. if (isStandardFont && type === 'CIDFontType2' &&
  14704. properties.cidEncoding.indexOf('Identity-') === 0) {
  14705. // Standard fonts might be embedded as CID font without glyph mapping.
  14706. // Building one based on GlyphMapForStandardFonts.
  14707. var map = [];
  14708. for (var code in GlyphMapForStandardFonts) {
  14709. map[+code] = GlyphMapForStandardFonts[code];
  14710. }
  14711. this.toFontChar = map;
  14712. this.toUnicode = new ToUnicodeMap(map);
  14713. } else if (/Symbol/i.test(fontName)) {
  14714. var symbols = Encodings.SymbolSetEncoding;
  14715. for (charCode in symbols) {
  14716. var fontChar = GlyphsUnicode[symbols[charCode]];
  14717. if (!fontChar) {
  14718. continue;
  14719. }
  14720. this.toFontChar[charCode] = fontChar;
  14721. }
  14722. } else if (isStandardFont) {
  14723. this.toFontChar = [];
  14724. for (charCode in properties.defaultEncoding) {
  14725. glyphName = (properties.differences[charCode] ||
  14726. properties.defaultEncoding[charCode]);
  14727. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  14728. }
  14729. } else {
  14730. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  14731. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  14732. if (notCidFont) {
  14733. glyphName = (properties.differences[charCode] ||
  14734. properties.defaultEncoding[charCode]);
  14735. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  14736. }
  14737. this.toFontChar[charCode] = unicodeCharCode;
  14738. }.bind(this));
  14739. }
  14740. this.loadedName = fontName.split('-')[0];
  14741. this.loading = false;
  14742. this.fontType = getFontType(type, subtype);
  14743. return;
  14744. }
  14745. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  14746. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  14747. // Some TrueType fonts by mistake claim Type1C
  14748. if (isTrueTypeFile(file)) {
  14749. subtype = 'TrueType';
  14750. } else {
  14751. type = 'Type1';
  14752. }
  14753. }
  14754. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  14755. type = 'CIDFontType0';
  14756. }
  14757. // XXX: Temporarily change the type for open type so we trigger a warning.
  14758. // This should be removed when we add support for open type.
  14759. if (subtype === 'OpenType') {
  14760. type = 'OpenType';
  14761. }
  14762. var data;
  14763. switch (type) {
  14764. case 'Type1':
  14765. case 'CIDFontType0':
  14766. this.mimetype = 'font/opentype';
  14767. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  14768. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  14769. adjustWidths(properties);
  14770. // Wrap the CFF data inside an OTF font file
  14771. data = this.convert(name, cff, properties);
  14772. break;
  14773. case 'OpenType':
  14774. case 'TrueType':
  14775. case 'CIDFontType2':
  14776. this.mimetype = 'font/opentype';
  14777. // Repair the TrueType file. It is can be damaged in the point of
  14778. // view of the sanitizer
  14779. data = this.checkAndRepair(name, file, properties);
  14780. if (this.isOpenType) {
  14781. type = 'OpenType';
  14782. }
  14783. break;
  14784. default:
  14785. error('Font ' + type + ' is not supported');
  14786. break;
  14787. }
  14788. this.data = data;
  14789. this.fontType = getFontType(type, subtype);
  14790. // Transfer some properties again that could change during font conversion
  14791. this.fontMatrix = properties.fontMatrix;
  14792. this.widths = properties.widths;
  14793. this.defaultWidth = properties.defaultWidth;
  14794. this.encoding = properties.baseEncoding;
  14795. this.seacMap = properties.seacMap;
  14796. this.loading = true;
  14797. }
  14798. Font.getFontID = (function () {
  14799. var ID = 1;
  14800. return function Font_getFontID() {
  14801. return String(ID++);
  14802. };
  14803. })();
  14804. function int16(b0, b1) {
  14805. return (b0 << 8) + b1;
  14806. }
  14807. function int32(b0, b1, b2, b3) {
  14808. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14809. }
  14810. function string16(value) {
  14811. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  14812. }
  14813. function safeString16(value) {
  14814. // clamp value to the 16-bit int range
  14815. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  14816. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  14817. }
  14818. function isTrueTypeFile(file) {
  14819. var header = file.peekBytes(4);
  14820. return readUint32(header, 0) === 0x00010000;
  14821. }
  14822. /**
  14823. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  14824. * with their unicode value. It also moves char codes that are in known
  14825. * problematic locations.
  14826. * @return {Object} Two properties:
  14827. * 'toFontChar' - maps original char codes(the value that will be read
  14828. * from commands such as show text) to the char codes that will be used in the
  14829. * font that we build
  14830. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  14831. */
  14832. function adjustMapping(charCodeToGlyphId, properties) {
  14833. var toUnicode = properties.toUnicode;
  14834. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  14835. var isIdentityUnicode =
  14836. properties.toUnicode instanceof IdentityToUnicodeMap;
  14837. var isCidFontType2 = (properties.type === 'CIDFontType2');
  14838. var newMap = Object.create(null);
  14839. var toFontChar = [];
  14840. var usedFontCharCodes = [];
  14841. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  14842. for (var originalCharCode in charCodeToGlyphId) {
  14843. originalCharCode |= 0;
  14844. var glyphId = charCodeToGlyphId[originalCharCode];
  14845. var fontCharCode = originalCharCode;
  14846. // First try to map the value to a unicode position if a non identity map
  14847. // was created.
  14848. if (!isIdentityUnicode) {
  14849. if (toUnicode.get(originalCharCode) !== undefined) {
  14850. var unicode = toUnicode.get(fontCharCode);
  14851. // TODO: Try to map ligatures to the correct spot.
  14852. if (unicode.length === 1) {
  14853. fontCharCode = unicode.charCodeAt(0);
  14854. }
  14855. } else if (isCidFontType2) {
  14856. // For CIDFontType2, move characters not present in toUnicode
  14857. // to the private use area (fixes bug 1028735 and issue 4881).
  14858. fontCharCode = nextAvailableFontCharCode;
  14859. }
  14860. }
  14861. // Try to move control characters, special characters and already mapped
  14862. // characters to the private use area since they will not be drawn by
  14863. // canvas if left in their current position. Also, move characters if the
  14864. // font was symbolic and there is only an identity unicode map since the
  14865. // characters probably aren't in the correct position (fixes an issue
  14866. // with firefox and thuluthfont).
  14867. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  14868. fontCharCode <= 0x1f || // Control chars
  14869. fontCharCode === 0x7F || // Control char
  14870. fontCharCode === 0xAD || // Soft hyphen
  14871. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  14872. // Prevent drawing characters in the specials unicode block.
  14873. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  14874. (isSymbolic && isIdentityUnicode)) &&
  14875. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  14876. // Loop to try and find a free spot in the private use area.
  14877. do {
  14878. fontCharCode = nextAvailableFontCharCode++;
  14879. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  14880. fontCharCode = 0xF020;
  14881. nextAvailableFontCharCode = fontCharCode + 1;
  14882. }
  14883. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  14884. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  14885. }
  14886. newMap[fontCharCode] = glyphId;
  14887. toFontChar[originalCharCode] = fontCharCode;
  14888. usedFontCharCodes[fontCharCode] = true;
  14889. }
  14890. return {
  14891. toFontChar: toFontChar,
  14892. charCodeToGlyphId: newMap,
  14893. nextAvailableFontCharCode: nextAvailableFontCharCode
  14894. };
  14895. }
  14896. function getRanges(glyphs) {
  14897. // Array.sort() sorts by characters, not numerically, so convert to an
  14898. // array of characters.
  14899. var codes = [];
  14900. for (var charCode in glyphs) {
  14901. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  14902. }
  14903. codes.sort(function fontGetRangesSort(a, b) {
  14904. return a.fontCharCode - b.fontCharCode;
  14905. });
  14906. // Split the sorted codes into ranges.
  14907. var ranges = [];
  14908. var length = codes.length;
  14909. for (var n = 0; n < length; ) {
  14910. var start = codes[n].fontCharCode;
  14911. var codeIndices = [codes[n].glyphId];
  14912. ++n;
  14913. var end = start;
  14914. while (n < length && end + 1 === codes[n].fontCharCode) {
  14915. codeIndices.push(codes[n].glyphId);
  14916. ++end;
  14917. ++n;
  14918. if (end === 0xFFFF) {
  14919. break;
  14920. }
  14921. }
  14922. ranges.push([start, end, codeIndices]);
  14923. }
  14924. return ranges;
  14925. }
  14926. function createCmapTable(glyphs) {
  14927. var ranges = getRanges(glyphs);
  14928. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  14929. var cmap = '\x00\x00' + // version
  14930. string16(numTables) + // numTables
  14931. '\x00\x03' + // platformID
  14932. '\x00\x01' + // encodingID
  14933. string32(4 + numTables * 8); // start of the table record
  14934. var i, ii, j, jj;
  14935. for (i = ranges.length - 1; i >= 0; --i) {
  14936. if (ranges[i][0] <= 0xFFFF) { break; }
  14937. }
  14938. var bmpLength = i + 1;
  14939. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  14940. ranges[i][1] = 0xFFFE;
  14941. }
  14942. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  14943. var segCount = bmpLength + trailingRangesCount;
  14944. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  14945. // Fill up the 4 parallel arrays describing the segments.
  14946. var startCount = '';
  14947. var endCount = '';
  14948. var idDeltas = '';
  14949. var idRangeOffsets = '';
  14950. var glyphsIds = '';
  14951. var bias = 0;
  14952. var range, start, end, codes;
  14953. for (i = 0, ii = bmpLength; i < ii; i++) {
  14954. range = ranges[i];
  14955. start = range[0];
  14956. end = range[1];
  14957. startCount += string16(start);
  14958. endCount += string16(end);
  14959. codes = range[2];
  14960. var contiguous = true;
  14961. for (j = 1, jj = codes.length; j < jj; ++j) {
  14962. if (codes[j] !== codes[j - 1] + 1) {
  14963. contiguous = false;
  14964. break;
  14965. }
  14966. }
  14967. if (!contiguous) {
  14968. var offset = (segCount - i) * 2 + bias * 2;
  14969. bias += (end - start + 1);
  14970. idDeltas += string16(0);
  14971. idRangeOffsets += string16(offset);
  14972. for (j = 0, jj = codes.length; j < jj; ++j) {
  14973. glyphsIds += string16(codes[j]);
  14974. }
  14975. } else {
  14976. var startCode = codes[0];
  14977. idDeltas += string16((startCode - start) & 0xFFFF);
  14978. idRangeOffsets += string16(0);
  14979. }
  14980. }
  14981. if (trailingRangesCount > 0) {
  14982. endCount += '\xFF\xFF';
  14983. startCount += '\xFF\xFF';
  14984. idDeltas += '\x00\x01';
  14985. idRangeOffsets += '\x00\x00';
  14986. }
  14987. var format314 = '\x00\x00' + // language
  14988. string16(2 * segCount) +
  14989. string16(searchParams.range) +
  14990. string16(searchParams.entry) +
  14991. string16(searchParams.rangeShift) +
  14992. endCount + '\x00\x00' + startCount +
  14993. idDeltas + idRangeOffsets + glyphsIds;
  14994. var format31012 = '';
  14995. var header31012 = '';
  14996. if (numTables > 1) {
  14997. cmap += '\x00\x03' + // platformID
  14998. '\x00\x0A' + // encodingID
  14999. string32(4 + numTables * 8 +
  15000. 4 + format314.length); // start of the table record
  15001. format31012 = '';
  15002. for (i = 0, ii = ranges.length; i < ii; i++) {
  15003. range = ranges[i];
  15004. start = range[0];
  15005. codes = range[2];
  15006. var code = codes[0];
  15007. for (j = 1, jj = codes.length; j < jj; ++j) {
  15008. if (codes[j] !== codes[j - 1] + 1) {
  15009. end = range[0] + j - 1;
  15010. format31012 += string32(start) + // startCharCode
  15011. string32(end) + // endCharCode
  15012. string32(code); // startGlyphID
  15013. start = end + 1;
  15014. code = codes[j];
  15015. }
  15016. }
  15017. format31012 += string32(start) + // startCharCode
  15018. string32(range[1]) + // endCharCode
  15019. string32(code); // startGlyphID
  15020. }
  15021. header31012 = '\x00\x0C' + // format
  15022. '\x00\x00' + // reserved
  15023. string32(format31012.length + 16) + // length
  15024. '\x00\x00\x00\x00' + // language
  15025. string32(format31012.length / 12); // nGroups
  15026. }
  15027. return cmap + '\x00\x04' + // format
  15028. string16(format314.length + 4) + // length
  15029. format314 + header31012 + format31012;
  15030. }
  15031. function validateOS2Table(os2) {
  15032. var stream = new Stream(os2.data);
  15033. var version = stream.getUint16();
  15034. // TODO verify all OS/2 tables fields, but currently we validate only those
  15035. // that give us issues
  15036. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15037. var selection = stream.getUint16();
  15038. if (version < 4 && (selection & 0x0300)) {
  15039. return false;
  15040. }
  15041. var firstChar = stream.getUint16();
  15042. var lastChar = stream.getUint16();
  15043. if (firstChar > lastChar) {
  15044. return false;
  15045. }
  15046. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15047. var usWinAscent = stream.getUint16();
  15048. if (usWinAscent === 0) { // makes font unreadable by windows
  15049. return false;
  15050. }
  15051. // OS/2 appears to be valid, resetting some fields
  15052. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15053. return true;
  15054. }
  15055. function createOS2Table(properties, charstrings, override) {
  15056. override = override || {
  15057. unitsPerEm: 0,
  15058. yMax: 0,
  15059. yMin: 0,
  15060. ascent: 0,
  15061. descent: 0
  15062. };
  15063. var ulUnicodeRange1 = 0;
  15064. var ulUnicodeRange2 = 0;
  15065. var ulUnicodeRange3 = 0;
  15066. var ulUnicodeRange4 = 0;
  15067. var firstCharIndex = null;
  15068. var lastCharIndex = 0;
  15069. if (charstrings) {
  15070. for (var code in charstrings) {
  15071. code |= 0;
  15072. if (firstCharIndex > code || !firstCharIndex) {
  15073. firstCharIndex = code;
  15074. }
  15075. if (lastCharIndex < code) {
  15076. lastCharIndex = code;
  15077. }
  15078. var position = getUnicodeRangeFor(code);
  15079. if (position < 32) {
  15080. ulUnicodeRange1 |= 1 << position;
  15081. } else if (position < 64) {
  15082. ulUnicodeRange2 |= 1 << position - 32;
  15083. } else if (position < 96) {
  15084. ulUnicodeRange3 |= 1 << position - 64;
  15085. } else if (position < 123) {
  15086. ulUnicodeRange4 |= 1 << position - 96;
  15087. } else {
  15088. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15089. }
  15090. }
  15091. } else {
  15092. // TODO
  15093. firstCharIndex = 0;
  15094. lastCharIndex = 255;
  15095. }
  15096. var bbox = properties.bbox || [0, 0, 0, 0];
  15097. var unitsPerEm = (override.unitsPerEm ||
  15098. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15099. // if the font units differ to the PDF glyph space units
  15100. // then scale up the values
  15101. var scale = (properties.ascentScaled ? 1.0 :
  15102. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15103. var typoAscent = (override.ascent ||
  15104. Math.round(scale * (properties.ascent || bbox[3])));
  15105. var typoDescent = (override.descent ||
  15106. Math.round(scale * (properties.descent || bbox[1])));
  15107. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15108. typoDescent = -typoDescent; // fixing incorrect descent
  15109. }
  15110. var winAscent = override.yMax || typoAscent;
  15111. var winDescent = -override.yMin || -typoDescent;
  15112. return '\x00\x03' + // version
  15113. '\x02\x24' + // xAvgCharWidth
  15114. '\x01\xF4' + // usWeightClass
  15115. '\x00\x05' + // usWidthClass
  15116. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15117. '\x02\x8A' + // ySubscriptXSize
  15118. '\x02\xBB' + // ySubscriptYSize
  15119. '\x00\x00' + // ySubscriptXOffset
  15120. '\x00\x8C' + // ySubscriptYOffset
  15121. '\x02\x8A' + // ySuperScriptXSize
  15122. '\x02\xBB' + // ySuperScriptYSize
  15123. '\x00\x00' + // ySuperScriptXOffset
  15124. '\x01\xDF' + // ySuperScriptYOffset
  15125. '\x00\x31' + // yStrikeOutSize
  15126. '\x01\x02' + // yStrikeOutPosition
  15127. '\x00\x00' + // sFamilyClass
  15128. '\x00\x00\x06' +
  15129. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15130. '\x00\x00\x00\x00\x00\x00' + // Panose
  15131. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15132. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15133. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15134. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15135. '\x2A\x32\x31\x2A' + // achVendID
  15136. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15137. string16(firstCharIndex ||
  15138. properties.firstChar) + // usFirstCharIndex
  15139. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15140. string16(typoAscent) + // sTypoAscender
  15141. string16(typoDescent) + // sTypoDescender
  15142. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15143. string16(winAscent) + // usWinAscent
  15144. string16(winDescent) + // usWinDescent
  15145. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15146. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15147. string16(properties.xHeight) + // sxHeight
  15148. string16(properties.capHeight) + // sCapHeight
  15149. string16(0) + // usDefaultChar
  15150. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15151. '\x00\x03'; // usMaxContext
  15152. }
  15153. function createPostTable(properties) {
  15154. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15155. return ('\x00\x03\x00\x00' + // Version number
  15156. string32(angle) + // italicAngle
  15157. '\x00\x00' + // underlinePosition
  15158. '\x00\x00' + // underlineThickness
  15159. string32(properties.fixedPitch) + // isFixedPitch
  15160. '\x00\x00\x00\x00' + // minMemType42
  15161. '\x00\x00\x00\x00' + // maxMemType42
  15162. '\x00\x00\x00\x00' + // minMemType1
  15163. '\x00\x00\x00\x00'); // maxMemType1
  15164. }
  15165. function createNameTable(name, proto) {
  15166. if (!proto) {
  15167. proto = [[], []]; // no strings and unicode strings
  15168. }
  15169. var strings = [
  15170. proto[0][0] || 'Original licence', // 0.Copyright
  15171. proto[0][1] || name, // 1.Font family
  15172. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15173. proto[0][3] || 'uniqueID', // 3.Unique ID
  15174. proto[0][4] || name, // 4.Full font name
  15175. proto[0][5] || 'Version 0.11', // 5.Version
  15176. proto[0][6] || '', // 6.Postscript name
  15177. proto[0][7] || 'Unknown', // 7.Trademark
  15178. proto[0][8] || 'Unknown', // 8.Manufacturer
  15179. proto[0][9] || 'Unknown' // 9.Designer
  15180. ];
  15181. // Mac want 1-byte per character strings while Windows want
  15182. // 2-bytes per character, so duplicate the names table
  15183. var stringsUnicode = [];
  15184. var i, ii, j, jj, str;
  15185. for (i = 0, ii = strings.length; i < ii; i++) {
  15186. str = proto[1][i] || strings[i];
  15187. var strBufUnicode = [];
  15188. for (j = 0, jj = str.length; j < jj; j++) {
  15189. strBufUnicode.push(string16(str.charCodeAt(j)));
  15190. }
  15191. stringsUnicode.push(strBufUnicode.join(''));
  15192. }
  15193. var names = [strings, stringsUnicode];
  15194. var platforms = ['\x00\x01', '\x00\x03'];
  15195. var encodings = ['\x00\x00', '\x00\x01'];
  15196. var languages = ['\x00\x00', '\x04\x09'];
  15197. var namesRecordCount = strings.length * platforms.length;
  15198. var nameTable =
  15199. '\x00\x00' + // format
  15200. string16(namesRecordCount) + // Number of names Record
  15201. string16(namesRecordCount * 12 + 6); // Storage
  15202. // Build the name records field
  15203. var strOffset = 0;
  15204. for (i = 0, ii = platforms.length; i < ii; i++) {
  15205. var strs = names[i];
  15206. for (j = 0, jj = strs.length; j < jj; j++) {
  15207. str = strs[j];
  15208. var nameRecord =
  15209. platforms[i] + // platform ID
  15210. encodings[i] + // encoding ID
  15211. languages[i] + // language ID
  15212. string16(j) + // name ID
  15213. string16(str.length) +
  15214. string16(strOffset);
  15215. nameTable += nameRecord;
  15216. strOffset += str.length;
  15217. }
  15218. }
  15219. nameTable += strings.join('') + stringsUnicode.join('');
  15220. return nameTable;
  15221. }
  15222. Font.prototype = {
  15223. name: null,
  15224. font: null,
  15225. mimetype: null,
  15226. encoding: null,
  15227. get renderer() {
  15228. var renderer = FontRendererFactory.create(this);
  15229. return shadow(this, 'renderer', renderer);
  15230. },
  15231. exportData: function Font_exportData() {
  15232. var data = {};
  15233. for (var i in this) {
  15234. if (this.hasOwnProperty(i)) {
  15235. data[i] = this[i];
  15236. }
  15237. }
  15238. return data;
  15239. },
  15240. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15241. function readTableEntry(file) {
  15242. var tag = bytesToString(file.getBytes(4));
  15243. var checksum = file.getInt32();
  15244. var offset = file.getInt32() >>> 0;
  15245. var length = file.getInt32() >>> 0;
  15246. // Read the table associated data
  15247. var previousPosition = file.pos;
  15248. file.pos = file.start ? file.start : 0;
  15249. file.skip(offset);
  15250. var data = file.getBytes(length);
  15251. file.pos = previousPosition;
  15252. if (tag === 'head') {
  15253. // clearing checksum adjustment
  15254. data[8] = data[9] = data[10] = data[11] = 0;
  15255. data[17] |= 0x20; //Set font optimized for cleartype flag
  15256. }
  15257. return {
  15258. tag: tag,
  15259. checksum: checksum,
  15260. length: length,
  15261. offset: offset,
  15262. data: data
  15263. };
  15264. }
  15265. function readOpenTypeHeader(ttf) {
  15266. return {
  15267. version: bytesToString(ttf.getBytes(4)),
  15268. numTables: ttf.getUint16(),
  15269. searchRange: ttf.getUint16(),
  15270. entrySelector: ttf.getUint16(),
  15271. rangeShift: ttf.getUint16()
  15272. };
  15273. }
  15274. /**
  15275. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15276. * PDF spec
  15277. */
  15278. function readCmapTable(cmap, font, isSymbolicFont) {
  15279. var segment;
  15280. var start = (font.start ? font.start : 0) + cmap.offset;
  15281. font.pos = start;
  15282. var version = font.getUint16();
  15283. var numTables = font.getUint16();
  15284. var potentialTable;
  15285. var canBreak = false;
  15286. // There's an order of preference in terms of which cmap subtable to
  15287. // use:
  15288. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15289. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15290. // The following takes advantage of the fact that the tables are sorted
  15291. // to work.
  15292. for (var i = 0; i < numTables; i++) {
  15293. var platformId = font.getUint16();
  15294. var encodingId = font.getUint16();
  15295. var offset = font.getInt32() >>> 0;
  15296. var useTable = false;
  15297. if (platformId === 1 && encodingId === 0) {
  15298. useTable = true;
  15299. // Continue the loop since there still may be a higher priority
  15300. // table.
  15301. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15302. useTable = true;
  15303. canBreak = true;
  15304. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15305. useTable = true;
  15306. canBreak = true;
  15307. }
  15308. if (useTable) {
  15309. potentialTable = {
  15310. platformId: platformId,
  15311. encodingId: encodingId,
  15312. offset: offset
  15313. };
  15314. }
  15315. if (canBreak) {
  15316. break;
  15317. }
  15318. }
  15319. if (!potentialTable) {
  15320. warn('Could not find a preferred cmap table.');
  15321. return {
  15322. platformId: -1,
  15323. encodingId: -1,
  15324. mappings: [],
  15325. hasShortCmap: false
  15326. };
  15327. }
  15328. font.pos = start + potentialTable.offset;
  15329. var format = font.getUint16();
  15330. var length = font.getUint16();
  15331. var language = font.getUint16();
  15332. var hasShortCmap = false;
  15333. var mappings = [];
  15334. var j, glyphId;
  15335. // TODO(mack): refactor this cmap subtable reading logic out
  15336. if (format === 0) {
  15337. for (j = 0; j < 256; j++) {
  15338. var index = font.getByte();
  15339. if (!index) {
  15340. continue;
  15341. }
  15342. mappings.push({
  15343. charCode: j,
  15344. glyphId: index
  15345. });
  15346. }
  15347. hasShortCmap = true;
  15348. } else if (format === 4) {
  15349. // re-creating the table in format 4 since the encoding
  15350. // might be changed
  15351. var segCount = (font.getUint16() >> 1);
  15352. font.getBytes(6); // skipping range fields
  15353. var segIndex, segments = [];
  15354. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15355. segments.push({ end: font.getUint16() });
  15356. }
  15357. font.getUint16();
  15358. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15359. segments[segIndex].start = font.getUint16();
  15360. }
  15361. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15362. segments[segIndex].delta = font.getUint16();
  15363. }
  15364. var offsetsCount = 0;
  15365. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15366. segment = segments[segIndex];
  15367. var rangeOffset = font.getUint16();
  15368. if (!rangeOffset) {
  15369. segment.offsetIndex = -1;
  15370. continue;
  15371. }
  15372. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15373. segment.offsetIndex = offsetIndex;
  15374. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15375. segment.end - segment.start + 1);
  15376. }
  15377. var offsets = [];
  15378. for (j = 0; j < offsetsCount; j++) {
  15379. offsets.push(font.getUint16());
  15380. }
  15381. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15382. segment = segments[segIndex];
  15383. start = segment.start;
  15384. var end = segment.end;
  15385. var delta = segment.delta;
  15386. offsetIndex = segment.offsetIndex;
  15387. for (j = start; j <= end; j++) {
  15388. if (j === 0xFFFF) {
  15389. continue;
  15390. }
  15391. glyphId = (offsetIndex < 0 ?
  15392. j : offsets[offsetIndex + j - start]);
  15393. glyphId = (glyphId + delta) & 0xFFFF;
  15394. if (glyphId === 0) {
  15395. continue;
  15396. }
  15397. mappings.push({
  15398. charCode: j,
  15399. glyphId: glyphId
  15400. });
  15401. }
  15402. }
  15403. } else if (format === 6) {
  15404. // Format 6 is a 2-bytes dense mapping, which means the font data
  15405. // lives glue together even if they are pretty far in the unicode
  15406. // table. (This looks weird, so I can have missed something), this
  15407. // works on Linux but seems to fails on Mac so let's rewrite the
  15408. // cmap table to a 3-1-4 style
  15409. var firstCode = font.getUint16();
  15410. var entryCount = font.getUint16();
  15411. for (j = 0; j < entryCount; j++) {
  15412. glyphId = font.getUint16();
  15413. var charCode = firstCode + j;
  15414. mappings.push({
  15415. charCode: charCode,
  15416. glyphId: glyphId
  15417. });
  15418. }
  15419. } else {
  15420. error('cmap table has unsupported format: ' + format);
  15421. }
  15422. // removing duplicate entries
  15423. mappings.sort(function (a, b) {
  15424. return a.charCode - b.charCode;
  15425. });
  15426. for (i = 1; i < mappings.length; i++) {
  15427. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15428. mappings.splice(i, 1);
  15429. i--;
  15430. }
  15431. }
  15432. return {
  15433. platformId: potentialTable.platformId,
  15434. encodingId: potentialTable.encodingId,
  15435. mappings: mappings,
  15436. hasShortCmap: hasShortCmap
  15437. };
  15438. }
  15439. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15440. if (!header) {
  15441. if (metrics) {
  15442. metrics.data = null;
  15443. }
  15444. return;
  15445. }
  15446. font.pos = (font.start ? font.start : 0) + header.offset;
  15447. font.pos += header.length - 2;
  15448. var numOfMetrics = font.getUint16();
  15449. if (numOfMetrics > numGlyphs) {
  15450. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  15451. 'greater than the numGlyphs (' + numGlyphs + ')');
  15452. // Reduce numOfMetrics if it is greater than numGlyphs
  15453. numOfMetrics = numGlyphs;
  15454. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  15455. header.data[35] = numOfMetrics & 0x00ff;
  15456. }
  15457. var numOfSidebearings = numGlyphs - numOfMetrics;
  15458. var numMissing = numOfSidebearings -
  15459. ((metrics.length - numOfMetrics * 4) >> 1);
  15460. var i, ii;
  15461. if (numMissing > 0) {
  15462. font.pos = (font.start ? font.start : 0) + metrics.offset;
  15463. var entries = '';
  15464. for (i = 0, ii = metrics.length; i < ii; i++) {
  15465. entries += String.fromCharCode(font.getByte());
  15466. }
  15467. for (i = 0; i < numMissing; i++) {
  15468. entries += '\x00\x00';
  15469. }
  15470. metrics.data = entries;
  15471. }
  15472. }
  15473. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  15474. hintsValid) {
  15475. if (sourceEnd - sourceStart <= 12) {
  15476. // glyph with data less than 12 is invalid one
  15477. return 0;
  15478. }
  15479. var glyf = source.subarray(sourceStart, sourceEnd);
  15480. var contoursCount = (glyf[0] << 8) | glyf[1];
  15481. if (contoursCount & 0x8000) {
  15482. // complex glyph, writing as is
  15483. dest.set(glyf, destStart);
  15484. return glyf.length;
  15485. }
  15486. var i, j = 10, flagsCount = 0;
  15487. for (i = 0; i < contoursCount; i++) {
  15488. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  15489. flagsCount = endPoint + 1;
  15490. j += 2;
  15491. }
  15492. // skipping instructions
  15493. var instructionsStart = j;
  15494. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  15495. j += 2 + instructionsLength;
  15496. var instructionsEnd = j;
  15497. // validating flags
  15498. var coordinatesLength = 0;
  15499. for (i = 0; i < flagsCount; i++) {
  15500. var flag = glyf[j++];
  15501. if (flag & 0xC0) {
  15502. // reserved flags must be zero, cleaning up
  15503. glyf[j - 1] = flag & 0x3F;
  15504. }
  15505. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  15506. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  15507. coordinatesLength += xyLength;
  15508. if (flag & 8) {
  15509. var repeat = glyf[j++];
  15510. i += repeat;
  15511. coordinatesLength += repeat * xyLength;
  15512. }
  15513. }
  15514. // glyph without coordinates will be rejected
  15515. if (coordinatesLength === 0) {
  15516. return 0;
  15517. }
  15518. var glyphDataLength = j + coordinatesLength;
  15519. if (glyphDataLength > glyf.length) {
  15520. // not enough data for coordinates
  15521. return 0;
  15522. }
  15523. if (!hintsValid && instructionsLength > 0) {
  15524. dest.set(glyf.subarray(0, instructionsStart), destStart);
  15525. dest.set([0, 0], destStart + instructionsStart);
  15526. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  15527. destStart + instructionsStart + 2);
  15528. glyphDataLength -= instructionsLength;
  15529. if (glyf.length - glyphDataLength > 3) {
  15530. glyphDataLength = (glyphDataLength + 3) & ~3;
  15531. }
  15532. return glyphDataLength;
  15533. }
  15534. if (glyf.length - glyphDataLength > 3) {
  15535. // truncating and aligning to 4 bytes the long glyph data
  15536. glyphDataLength = (glyphDataLength + 3) & ~3;
  15537. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  15538. return glyphDataLength;
  15539. }
  15540. // glyph data is fine
  15541. dest.set(glyf, destStart);
  15542. return glyf.length;
  15543. }
  15544. function sanitizeHead(head, numGlyphs, locaLength) {
  15545. var data = head.data;
  15546. // Validate version:
  15547. // Should always be 0x00010000
  15548. var version = int32(data[0], data[1], data[2], data[3]);
  15549. if (version >> 16 !== 1) {
  15550. info('Attempting to fix invalid version in head table: ' + version);
  15551. data[0] = 0;
  15552. data[1] = 1;
  15553. data[2] = 0;
  15554. data[3] = 0;
  15555. }
  15556. var indexToLocFormat = int16(data[50], data[51]);
  15557. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  15558. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  15559. indexToLocFormat);
  15560. // The value of indexToLocFormat should be 0 if the loca table
  15561. // consists of short offsets, and should be 1 if the loca table
  15562. // consists of long offsets.
  15563. //
  15564. // The number of entries in the loca table should be numGlyphs + 1.
  15565. //
  15566. // Using this information, we can work backwards to deduce if the
  15567. // size of each offset in the loca table, and thus figure out the
  15568. // appropriate value for indexToLocFormat.
  15569. var numGlyphsPlusOne = numGlyphs + 1;
  15570. if (locaLength === numGlyphsPlusOne << 1) {
  15571. // 0x0000 indicates the loca table consists of short offsets
  15572. data[50] = 0;
  15573. data[51] = 0;
  15574. } else if (locaLength === numGlyphsPlusOne << 2) {
  15575. // 0x0001 indicates the loca table consists of long offsets
  15576. data[50] = 0;
  15577. data[51] = 1;
  15578. } else {
  15579. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  15580. }
  15581. }
  15582. }
  15583. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  15584. isGlyphLocationsLong, hintsValid,
  15585. dupFirstEntry) {
  15586. var itemSize, itemDecode, itemEncode;
  15587. if (isGlyphLocationsLong) {
  15588. itemSize = 4;
  15589. itemDecode = function fontItemDecodeLong(data, offset) {
  15590. return (data[offset] << 24) | (data[offset + 1] << 16) |
  15591. (data[offset + 2] << 8) | data[offset + 3];
  15592. };
  15593. itemEncode = function fontItemEncodeLong(data, offset, value) {
  15594. data[offset] = (value >>> 24) & 0xFF;
  15595. data[offset + 1] = (value >> 16) & 0xFF;
  15596. data[offset + 2] = (value >> 8) & 0xFF;
  15597. data[offset + 3] = value & 0xFF;
  15598. };
  15599. } else {
  15600. itemSize = 2;
  15601. itemDecode = function fontItemDecode(data, offset) {
  15602. return (data[offset] << 9) | (data[offset + 1] << 1);
  15603. };
  15604. itemEncode = function fontItemEncode(data, offset, value) {
  15605. data[offset] = (value >> 9) & 0xFF;
  15606. data[offset + 1] = (value >> 1) & 0xFF;
  15607. };
  15608. }
  15609. var locaData = loca.data;
  15610. var locaDataSize = itemSize * (1 + numGlyphs);
  15611. // is loca.data too short or long?
  15612. if (locaData.length !== locaDataSize) {
  15613. locaData = new Uint8Array(locaDataSize);
  15614. locaData.set(loca.data.subarray(0, locaDataSize));
  15615. loca.data = locaData;
  15616. }
  15617. // removing the invalid glyphs
  15618. var oldGlyfData = glyf.data;
  15619. var oldGlyfDataLength = oldGlyfData.length;
  15620. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  15621. var startOffset = itemDecode(locaData, 0);
  15622. var writeOffset = 0;
  15623. itemEncode(locaData, 0, writeOffset);
  15624. var i, j;
  15625. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15626. var endOffset = itemDecode(locaData, j);
  15627. if (endOffset > oldGlyfDataLength &&
  15628. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  15629. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  15630. // the glyf table size, which makes last glyph out of range.
  15631. endOffset = oldGlyfDataLength;
  15632. }
  15633. if (endOffset > oldGlyfDataLength) {
  15634. // glyph end offset points outside glyf data, rejecting the glyph
  15635. itemEncode(locaData, j, writeOffset);
  15636. startOffset = endOffset;
  15637. continue;
  15638. }
  15639. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  15640. newGlyfData, writeOffset, hintsValid);
  15641. writeOffset += newLength;
  15642. itemEncode(locaData, j, writeOffset);
  15643. startOffset = endOffset;
  15644. }
  15645. if (writeOffset === 0) {
  15646. // glyf table cannot be empty -- redoing the glyf and loca tables
  15647. // to have single glyph with one point
  15648. var simpleGlyph = new Uint8Array(
  15649. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  15650. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15651. itemEncode(locaData, j, simpleGlyph.length);
  15652. }
  15653. glyf.data = simpleGlyph;
  15654. return;
  15655. }
  15656. if (dupFirstEntry) {
  15657. var firstEntryLength = itemDecode(locaData, itemSize);
  15658. if (newGlyfData.length > firstEntryLength + writeOffset) {
  15659. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  15660. } else {
  15661. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  15662. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  15663. }
  15664. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  15665. itemEncode(loca.data, locaData.length - itemSize,
  15666. writeOffset + firstEntryLength);
  15667. } else {
  15668. glyf.data = newGlyfData.subarray(0, writeOffset);
  15669. }
  15670. }
  15671. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  15672. var start = (font.start ? font.start : 0) + post.offset;
  15673. font.pos = start;
  15674. var length = post.length, end = start + length;
  15675. var version = font.getInt32();
  15676. // skip rest to the tables
  15677. font.getBytes(28);
  15678. var glyphNames;
  15679. var valid = true;
  15680. var i;
  15681. switch (version) {
  15682. case 0x00010000:
  15683. glyphNames = MacStandardGlyphOrdering;
  15684. break;
  15685. case 0x00020000:
  15686. var numGlyphs = font.getUint16();
  15687. if (numGlyphs !== maxpNumGlyphs) {
  15688. valid = false;
  15689. break;
  15690. }
  15691. var glyphNameIndexes = [];
  15692. for (i = 0; i < numGlyphs; ++i) {
  15693. var index = font.getUint16();
  15694. if (index >= 32768) {
  15695. valid = false;
  15696. break;
  15697. }
  15698. glyphNameIndexes.push(index);
  15699. }
  15700. if (!valid) {
  15701. break;
  15702. }
  15703. var customNames = [];
  15704. var strBuf = [];
  15705. while (font.pos < end) {
  15706. var stringLength = font.getByte();
  15707. strBuf.length = stringLength;
  15708. for (i = 0; i < stringLength; ++i) {
  15709. strBuf[i] = String.fromCharCode(font.getByte());
  15710. }
  15711. customNames.push(strBuf.join(''));
  15712. }
  15713. glyphNames = [];
  15714. for (i = 0; i < numGlyphs; ++i) {
  15715. var j = glyphNameIndexes[i];
  15716. if (j < 258) {
  15717. glyphNames.push(MacStandardGlyphOrdering[j]);
  15718. continue;
  15719. }
  15720. glyphNames.push(customNames[j - 258]);
  15721. }
  15722. break;
  15723. case 0x00030000:
  15724. break;
  15725. default:
  15726. warn('Unknown/unsupported post table version ' + version);
  15727. valid = false;
  15728. break;
  15729. }
  15730. properties.glyphNames = glyphNames;
  15731. return valid;
  15732. }
  15733. function readNameTable(nameTable) {
  15734. var start = (font.start ? font.start : 0) + nameTable.offset;
  15735. font.pos = start;
  15736. var names = [[], []];
  15737. var length = nameTable.length, end = start + length;
  15738. var format = font.getUint16();
  15739. var FORMAT_0_HEADER_LENGTH = 6;
  15740. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  15741. // unsupported name table format or table "too" small
  15742. return names;
  15743. }
  15744. var numRecords = font.getUint16();
  15745. var stringsStart = font.getUint16();
  15746. var records = [];
  15747. var NAME_RECORD_LENGTH = 12;
  15748. var i, ii;
  15749. for (i = 0; i < numRecords &&
  15750. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  15751. var r = {
  15752. platform: font.getUint16(),
  15753. encoding: font.getUint16(),
  15754. language: font.getUint16(),
  15755. name: font.getUint16(),
  15756. length: font.getUint16(),
  15757. offset: font.getUint16()
  15758. };
  15759. // using only Macintosh and Windows platform/encoding names
  15760. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  15761. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  15762. records.push(r);
  15763. }
  15764. }
  15765. for (i = 0, ii = records.length; i < ii; i++) {
  15766. var record = records[i];
  15767. var pos = start + stringsStart + record.offset;
  15768. if (pos + record.length > end) {
  15769. continue; // outside of name table, ignoring
  15770. }
  15771. font.pos = pos;
  15772. var nameIndex = record.name;
  15773. if (record.encoding) {
  15774. // unicode
  15775. var str = '';
  15776. for (var j = 0, jj = record.length; j < jj; j += 2) {
  15777. str += String.fromCharCode(font.getUint16());
  15778. }
  15779. names[1][nameIndex] = str;
  15780. } else {
  15781. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  15782. }
  15783. }
  15784. return names;
  15785. }
  15786. var TTOpsStackDeltas = [
  15787. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  15788. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  15789. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  15790. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  15791. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  15792. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  15793. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15794. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  15795. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  15796. // 0xC0-DF == -1 and 0xE0-FF == -2
  15797. function sanitizeTTProgram(table, ttContext) {
  15798. var data = table.data;
  15799. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  15800. var stack = [];
  15801. var callstack = [];
  15802. var functionsCalled = [];
  15803. var tooComplexToFollowFunctions =
  15804. ttContext.tooComplexToFollowFunctions;
  15805. var inFDEF = false, ifLevel = 0, inELSE = 0;
  15806. for (var ii = data.length; i < ii;) {
  15807. var op = data[i++];
  15808. // The TrueType instruction set docs can be found at
  15809. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  15810. if (op === 0x40) { // NPUSHB - pushes n bytes
  15811. n = data[i++];
  15812. if (inFDEF || inELSE) {
  15813. i += n;
  15814. } else {
  15815. for (j = 0; j < n; j++) {
  15816. stack.push(data[i++]);
  15817. }
  15818. }
  15819. } else if (op === 0x41) { // NPUSHW - pushes n words
  15820. n = data[i++];
  15821. if (inFDEF || inELSE) {
  15822. i += n * 2;
  15823. } else {
  15824. for (j = 0; j < n; j++) {
  15825. b = data[i++];
  15826. stack.push((b << 8) | data[i++]);
  15827. }
  15828. }
  15829. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  15830. n = op - 0xB0 + 1;
  15831. if (inFDEF || inELSE) {
  15832. i += n;
  15833. } else {
  15834. for (j = 0; j < n; j++) {
  15835. stack.push(data[i++]);
  15836. }
  15837. }
  15838. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  15839. n = op - 0xB8 + 1;
  15840. if (inFDEF || inELSE) {
  15841. i += n * 2;
  15842. } else {
  15843. for (j = 0; j < n; j++) {
  15844. b = data[i++];
  15845. stack.push((b << 8) | data[i++]);
  15846. }
  15847. }
  15848. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  15849. if (!inFDEF && !inELSE) {
  15850. // collecting inforamtion about which functions are used
  15851. funcId = stack[stack.length - 1];
  15852. ttContext.functionsUsed[funcId] = true;
  15853. if (funcId in ttContext.functionsStackDeltas) {
  15854. stack.length += ttContext.functionsStackDeltas[funcId];
  15855. } else if (funcId in ttContext.functionsDefined &&
  15856. functionsCalled.indexOf(funcId) < 0) {
  15857. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  15858. functionsCalled.push(funcId);
  15859. pc = ttContext.functionsDefined[funcId];
  15860. if (!pc) {
  15861. warn('TT: CALL non-existent function');
  15862. ttContext.hintsValid = false;
  15863. return;
  15864. }
  15865. data = pc.data;
  15866. i = pc.i;
  15867. }
  15868. }
  15869. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  15870. if (inFDEF || inELSE) {
  15871. warn('TT: nested FDEFs not allowed');
  15872. tooComplexToFollowFunctions = true;
  15873. }
  15874. inFDEF = true;
  15875. // collecting inforamtion about which functions are defined
  15876. lastDeff = i;
  15877. funcId = stack.pop();
  15878. ttContext.functionsDefined[funcId] = {data: data, i: i};
  15879. } else if (op === 0x2D) { // ENDF - end of function
  15880. if (inFDEF) {
  15881. inFDEF = false;
  15882. lastEndf = i;
  15883. } else {
  15884. pc = callstack.pop();
  15885. if (!pc) {
  15886. warn('TT: ENDF bad stack');
  15887. ttContext.hintsValid = false;
  15888. return;
  15889. }
  15890. funcId = functionsCalled.pop();
  15891. data = pc.data;
  15892. i = pc.i;
  15893. ttContext.functionsStackDeltas[funcId] =
  15894. stack.length - pc.stackTop;
  15895. }
  15896. } else if (op === 0x89) { // IDEF - instruction definition
  15897. if (inFDEF || inELSE) {
  15898. warn('TT: nested IDEFs not allowed');
  15899. tooComplexToFollowFunctions = true;
  15900. }
  15901. inFDEF = true;
  15902. // recording it as a function to track ENDF
  15903. lastDeff = i;
  15904. } else if (op === 0x58) { // IF
  15905. ++ifLevel;
  15906. } else if (op === 0x1B) { // ELSE
  15907. inELSE = ifLevel;
  15908. } else if (op === 0x59) { // EIF
  15909. if (inELSE === ifLevel) {
  15910. inELSE = 0;
  15911. }
  15912. --ifLevel;
  15913. } else if (op === 0x1C) { // JMPR
  15914. if (!inFDEF && !inELSE) {
  15915. var offset = stack[stack.length - 1];
  15916. // only jumping forward to prevent infinite loop
  15917. if (offset > 0) {
  15918. i += offset - 1;
  15919. }
  15920. }
  15921. }
  15922. // Adjusting stack not extactly, but just enough to get function id
  15923. if (!inFDEF && !inELSE) {
  15924. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  15925. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  15926. if (op >= 0x71 && op <= 0x75) {
  15927. n = stack.pop();
  15928. if (n === n) {
  15929. stackDelta = -n * 2;
  15930. }
  15931. }
  15932. while (stackDelta < 0 && stack.length > 0) {
  15933. stack.pop();
  15934. stackDelta++;
  15935. }
  15936. while (stackDelta > 0) {
  15937. stack.push(NaN); // pushing any number into stack
  15938. stackDelta--;
  15939. }
  15940. }
  15941. }
  15942. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  15943. var content = [data];
  15944. if (i > data.length) {
  15945. content.push(new Uint8Array(i - data.length));
  15946. }
  15947. if (lastDeff > lastEndf) {
  15948. warn('TT: complementing a missing function tail');
  15949. // new function definition started, but not finished
  15950. // complete function by [CLEAR, ENDF]
  15951. content.push(new Uint8Array([0x22, 0x2D]));
  15952. }
  15953. foldTTTable(table, content);
  15954. }
  15955. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  15956. if (ttContext.tooComplexToFollowFunctions) {
  15957. return;
  15958. }
  15959. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  15960. warn('TT: more functions defined than expected');
  15961. ttContext.hintsValid = false;
  15962. return;
  15963. }
  15964. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  15965. if (j > maxFunctionDefs) {
  15966. warn('TT: invalid function id: ' + j);
  15967. ttContext.hintsValid = false;
  15968. return;
  15969. }
  15970. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  15971. warn('TT: undefined function: ' + j);
  15972. ttContext.hintsValid = false;
  15973. return;
  15974. }
  15975. }
  15976. }
  15977. function foldTTTable(table, content) {
  15978. if (content.length > 1) {
  15979. // concatenating the content items
  15980. var newLength = 0;
  15981. var j, jj;
  15982. for (j = 0, jj = content.length; j < jj; j++) {
  15983. newLength += content[j].length;
  15984. }
  15985. newLength = (newLength + 3) & ~3;
  15986. var result = new Uint8Array(newLength);
  15987. var pos = 0;
  15988. for (j = 0, jj = content.length; j < jj; j++) {
  15989. result.set(content[j], pos);
  15990. pos += content[j].length;
  15991. }
  15992. table.data = result;
  15993. table.length = newLength;
  15994. }
  15995. }
  15996. function sanitizeTTPrograms(fpgm, prep, cvt) {
  15997. var ttContext = {
  15998. functionsDefined: [],
  15999. functionsUsed: [],
  16000. functionsStackDeltas: [],
  16001. tooComplexToFollowFunctions: false,
  16002. hintsValid: true
  16003. };
  16004. if (fpgm) {
  16005. sanitizeTTProgram(fpgm, ttContext);
  16006. }
  16007. if (prep) {
  16008. sanitizeTTProgram(prep, ttContext);
  16009. }
  16010. if (fpgm) {
  16011. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16012. }
  16013. if (cvt && (cvt.length & 1)) {
  16014. var cvtData = new Uint8Array(cvt.length + 1);
  16015. cvtData.set(cvt.data);
  16016. cvt.data = cvtData;
  16017. }
  16018. return ttContext.hintsValid;
  16019. }
  16020. // The following steps modify the original font data, making copy
  16021. font = new Stream(new Uint8Array(font.getBytes()));
  16022. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16023. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16024. var header = readOpenTypeHeader(font);
  16025. var numTables = header.numTables;
  16026. var cff, cffFile;
  16027. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16028. hmtx: null, maxp: null, name: null, post: null };
  16029. var table;
  16030. for (var i = 0; i < numTables; i++) {
  16031. table = readTableEntry(font);
  16032. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16033. continue; // skipping table if it's not a required or optional table
  16034. }
  16035. if (table.length === 0) {
  16036. continue; // skipping empty tables
  16037. }
  16038. tables[table.tag] = table;
  16039. }
  16040. var isTrueType = !tables['CFF '];
  16041. if (!isTrueType) {
  16042. // OpenType font
  16043. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16044. // no major tables: throwing everything at CFFFont
  16045. cffFile = new Stream(tables['CFF '].data);
  16046. cff = new CFFFont(cffFile, properties);
  16047. return this.convert(name, cff, properties);
  16048. }
  16049. delete tables.glyf;
  16050. delete tables.loca;
  16051. delete tables.fpgm;
  16052. delete tables.prep;
  16053. delete tables['cvt '];
  16054. this.isOpenType = true;
  16055. } else {
  16056. if (!tables.glyf || !tables.loca) {
  16057. error('Required "glyf" or "loca" tables are not found');
  16058. }
  16059. this.isOpenType = false;
  16060. }
  16061. if (!tables.maxp) {
  16062. error('Required "maxp" table is not found');
  16063. }
  16064. font.pos = (font.start || 0) + tables.maxp.offset;
  16065. var version = font.getInt32();
  16066. var numGlyphs = font.getUint16();
  16067. var maxFunctionDefs = 0;
  16068. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16069. // maxZones can be invalid
  16070. font.pos += 8;
  16071. var maxZones = font.getUint16();
  16072. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16073. tables.maxp.data[14] = 0;
  16074. tables.maxp.data[15] = 2;
  16075. }
  16076. font.pos += 4;
  16077. maxFunctionDefs = font.getUint16();
  16078. }
  16079. var dupFirstEntry = false;
  16080. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16081. properties.toUnicode.get(0) > '\u0000') {
  16082. // oracle's defect (see 3427), duplicating first entry
  16083. dupFirstEntry = true;
  16084. numGlyphs++;
  16085. tables.maxp.data[4] = numGlyphs >> 8;
  16086. tables.maxp.data[5] = numGlyphs & 255;
  16087. }
  16088. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16089. tables['cvt '], maxFunctionDefs);
  16090. if (!hintsValid) {
  16091. delete tables.fpgm;
  16092. delete tables.prep;
  16093. delete tables['cvt '];
  16094. }
  16095. // Ensure the hmtx table contains the advance width and
  16096. // sidebearings information for numGlyphs in the maxp table
  16097. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16098. if (!tables.head) {
  16099. error('Required "head" table is not found');
  16100. }
  16101. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16102. if (isTrueType) {
  16103. var isGlyphLocationsLong = int16(tables.head.data[50],
  16104. tables.head.data[51]);
  16105. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16106. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16107. }
  16108. if (!tables.hhea) {
  16109. error('Required "hhea" table is not found');
  16110. }
  16111. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16112. // Sometimes it's 0. That needs to be fixed
  16113. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16114. tables.hhea.data[10] = 0xFF;
  16115. tables.hhea.data[11] = 0xFF;
  16116. }
  16117. // The 'post' table has glyphs names.
  16118. if (tables.post) {
  16119. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16120. if (!valid) {
  16121. tables.post = null;
  16122. }
  16123. }
  16124. var charCodeToGlyphId = [], charCode;
  16125. if (properties.type === 'CIDFontType2') {
  16126. var cidToGidMap = properties.cidToGidMap || [];
  16127. var cidToGidMapLength = cidToGidMap.length;
  16128. properties.cMap.forEach(function(charCode, cid) {
  16129. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16130. var glyphId = -1;
  16131. if (cidToGidMapLength === 0) {
  16132. glyphId = charCode;
  16133. } else if (cidToGidMap[cid] !== undefined) {
  16134. glyphId = cidToGidMap[cid];
  16135. }
  16136. if (glyphId >= 0 && glyphId < numGlyphs) {
  16137. charCodeToGlyphId[charCode] = glyphId;
  16138. }
  16139. });
  16140. if (dupFirstEntry) {
  16141. charCodeToGlyphId[0] = numGlyphs - 1;
  16142. }
  16143. } else {
  16144. // Most of the following logic in this code branch is based on the
  16145. // 9.6.6.4 of the PDF spec.
  16146. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16147. var cmapPlatformId = cmapTable.platformId;
  16148. var cmapEncodingId = cmapTable.encodingId;
  16149. var cmapMappings = cmapTable.mappings;
  16150. var cmapMappingsLength = cmapMappings.length;
  16151. var hasEncoding = properties.differences.length ||
  16152. !!properties.baseEncodingName;
  16153. // The spec seems to imply that if the font is symbolic the encoding
  16154. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16155. // where the the font is symbolic and it has an encoding.
  16156. if (hasEncoding &&
  16157. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16158. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  16159. var baseEncoding = [];
  16160. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16161. properties.baseEncodingName === 'WinAnsiEncoding') {
  16162. baseEncoding = Encodings[properties.baseEncodingName];
  16163. }
  16164. for (charCode = 0; charCode < 256; charCode++) {
  16165. var glyphName;
  16166. if (this.differences && charCode in this.differences) {
  16167. glyphName = this.differences[charCode];
  16168. } else if (charCode in baseEncoding &&
  16169. baseEncoding[charCode] !== '') {
  16170. glyphName = baseEncoding[charCode];
  16171. } else {
  16172. glyphName = Encodings.StandardEncoding[charCode];
  16173. }
  16174. if (!glyphName) {
  16175. continue;
  16176. }
  16177. var unicodeOrCharCode;
  16178. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16179. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16180. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16181. // TODO: the encoding needs to be updated with mac os table.
  16182. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16183. }
  16184. var found = false;
  16185. for (i = 0; i < cmapMappingsLength; ++i) {
  16186. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16187. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16188. found = true;
  16189. break;
  16190. }
  16191. }
  16192. if (!found && properties.glyphNames) {
  16193. // Try to map using the post table. There are currently no known
  16194. // pdfs that this fixes.
  16195. var glyphId = properties.glyphNames.indexOf(glyphName);
  16196. if (glyphId > 0) {
  16197. charCodeToGlyphId[charCode] = glyphId;
  16198. }
  16199. }
  16200. }
  16201. } else {
  16202. // For (3, 0) cmap tables:
  16203. // The charcode key being stored in charCodeToGlyphId is the lower
  16204. // byte of the two-byte charcodes of the cmap table since according to
  16205. // the spec: 'each byte from the string shall be prepended with the
  16206. // high byte of the range [of charcodes in the cmap table], to form
  16207. // a two-byte character, which shall be used to select the
  16208. // associated glyph description from the subtable'.
  16209. //
  16210. // For (1, 0) cmap tables:
  16211. // 'single bytes from the string shall be used to look up the
  16212. // associated glyph descriptions from the subtable'. This means
  16213. // charcodes in the cmap will be single bytes, so no-op since
  16214. // glyph.charCode & 0xFF === glyph.charCode
  16215. for (i = 0; i < cmapMappingsLength; ++i) {
  16216. charCode = cmapMappings[i].charCode & 0xFF;
  16217. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16218. }
  16219. }
  16220. }
  16221. if (charCodeToGlyphId.length === 0) {
  16222. // defines at least one glyph
  16223. charCodeToGlyphId[0] = 0;
  16224. }
  16225. // Converting glyphs and ids into font's cmap table
  16226. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16227. this.toFontChar = newMapping.toFontChar;
  16228. tables.cmap = {
  16229. tag: 'cmap',
  16230. data: createCmapTable(newMapping.charCodeToGlyphId)
  16231. };
  16232. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16233. // extract some more font properties from the OpenType head and
  16234. // hhea tables; yMin and descent value are always negative
  16235. var override = {
  16236. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16237. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16238. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16239. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16240. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16241. };
  16242. tables['OS/2'] = {
  16243. tag: 'OS/2',
  16244. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16245. override)
  16246. };
  16247. }
  16248. // Rewrite the 'post' table if needed
  16249. if (!tables.post) {
  16250. tables.post = {
  16251. tag: 'post',
  16252. data: createPostTable(properties)
  16253. };
  16254. }
  16255. if (!isTrueType) {
  16256. try {
  16257. // Trying to repair CFF file
  16258. cffFile = new Stream(tables['CFF '].data);
  16259. var parser = new CFFParser(cffFile, properties);
  16260. cff = parser.parse();
  16261. var compiler = new CFFCompiler(cff);
  16262. tables['CFF '].data = compiler.compile();
  16263. } catch (e) {
  16264. warn('Failed to compile font ' + properties.loadedName);
  16265. }
  16266. }
  16267. // Re-creating 'name' table
  16268. if (!tables.name) {
  16269. tables.name = {
  16270. tag: 'name',
  16271. data: createNameTable(this.name)
  16272. };
  16273. } else {
  16274. // ... using existing 'name' table as prototype
  16275. var namePrototype = readNameTable(tables.name);
  16276. tables.name.data = createNameTable(name, namePrototype);
  16277. }
  16278. var builder = new OpenTypeFileBuilder(header.version);
  16279. for (var tableTag in tables) {
  16280. builder.addTable(tableTag, tables[tableTag].data);
  16281. }
  16282. return builder.toArray();
  16283. },
  16284. convert: function Font_convert(fontName, font, properties) {
  16285. // TODO: Check the charstring widths to determine this.
  16286. properties.fixedPitch = false;
  16287. var mapping = font.getGlyphMapping(properties);
  16288. var newMapping = adjustMapping(mapping, properties);
  16289. this.toFontChar = newMapping.toFontChar;
  16290. var numGlyphs = font.numGlyphs;
  16291. function getCharCodes(charCodeToGlyphId, glyphId) {
  16292. var charCodes = null;
  16293. for (var charCode in charCodeToGlyphId) {
  16294. if (glyphId === charCodeToGlyphId[charCode]) {
  16295. if (!charCodes) {
  16296. charCodes = [];
  16297. }
  16298. charCodes.push(charCode | 0);
  16299. }
  16300. }
  16301. return charCodes;
  16302. }
  16303. function createCharCode(charCodeToGlyphId, glyphId) {
  16304. for (var charCode in charCodeToGlyphId) {
  16305. if (glyphId === charCodeToGlyphId[charCode]) {
  16306. return charCode | 0;
  16307. }
  16308. }
  16309. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16310. glyphId;
  16311. return newMapping.nextAvailableFontCharCode++;
  16312. }
  16313. var seacs = font.seacs;
  16314. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16315. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16316. var charset = font.getCharset();
  16317. var seacMap = Object.create(null);
  16318. for (var glyphId in seacs) {
  16319. glyphId |= 0;
  16320. var seac = seacs[glyphId];
  16321. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16322. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16323. var baseGlyphId = charset.indexOf(baseGlyphName);
  16324. var accentGlyphId = charset.indexOf(accentGlyphName);
  16325. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16326. continue;
  16327. }
  16328. var accentOffset = {
  16329. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16330. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16331. };
  16332. var charCodes = getCharCodes(mapping, glyphId);
  16333. if (!charCodes) {
  16334. // There's no point in mapping it if the char code was never mapped
  16335. // to begin with.
  16336. continue;
  16337. }
  16338. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16339. var charCode = charCodes[i];
  16340. // Find a fontCharCode that maps to the base and accent glyphs.
  16341. // If one doesn't exists, create it.
  16342. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16343. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16344. baseGlyphId);
  16345. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16346. accentGlyphId);
  16347. seacMap[charCode] = {
  16348. baseFontCharCode: baseFontCharCode,
  16349. accentFontCharCode: accentFontCharCode,
  16350. accentOffset: accentOffset
  16351. };
  16352. }
  16353. }
  16354. properties.seacMap = seacMap;
  16355. }
  16356. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16357. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16358. // PostScript Font Program
  16359. builder.addTable('CFF ', font.data);
  16360. // OS/2 and Windows Specific metrics
  16361. builder.addTable('OS/2', createOS2Table(properties,
  16362. newMapping.charCodeToGlyphId));
  16363. // Character to glyphs mapping
  16364. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16365. // Font header
  16366. builder.addTable('head',
  16367. '\x00\x01\x00\x00' + // Version number
  16368. '\x00\x00\x10\x00' + // fontRevision
  16369. '\x00\x00\x00\x00' + // checksumAdjustement
  16370. '\x5F\x0F\x3C\xF5' + // magicNumber
  16371. '\x00\x00' + // Flags
  16372. safeString16(unitsPerEm) + // unitsPerEM
  16373. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16374. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16375. '\x00\x00' + // xMin
  16376. safeString16(properties.descent) + // yMin
  16377. '\x0F\xFF' + // xMax
  16378. safeString16(properties.ascent) + // yMax
  16379. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16380. '\x00\x11' + // lowestRecPPEM
  16381. '\x00\x00' + // fontDirectionHint
  16382. '\x00\x00' + // indexToLocFormat
  16383. '\x00\x00'); // glyphDataFormat
  16384. // Horizontal header
  16385. builder.addTable('hhea',
  16386. '\x00\x01\x00\x00' + // Version number
  16387. safeString16(properties.ascent) + // Typographic Ascent
  16388. safeString16(properties.descent) + // Typographic Descent
  16389. '\x00\x00' + // Line Gap
  16390. '\xFF\xFF' + // advanceWidthMax
  16391. '\x00\x00' + // minLeftSidebearing
  16392. '\x00\x00' + // minRightSidebearing
  16393. '\x00\x00' + // xMaxExtent
  16394. safeString16(properties.capHeight) + // caretSlopeRise
  16395. safeString16(Math.tan(properties.italicAngle) *
  16396. properties.xHeight) + // caretSlopeRun
  16397. '\x00\x00' + // caretOffset
  16398. '\x00\x00' + // -reserved-
  16399. '\x00\x00' + // -reserved-
  16400. '\x00\x00' + // -reserved-
  16401. '\x00\x00' + // -reserved-
  16402. '\x00\x00' + // metricDataFormat
  16403. string16(numGlyphs)); // Number of HMetrics
  16404. // Horizontal metrics
  16405. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16406. var charstrings = font.charstrings;
  16407. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16408. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16409. // TODO: For CFF fonts the width should technically match th x in
  16410. // the glyph, but it doesn't seem to matter.
  16411. var charstring = charstrings ? charstrings[i - 1] : {};
  16412. var width = 'width' in charstring ? charstring.width : 0;
  16413. hmtx += string16(width) + string16(0);
  16414. }
  16415. return hmtx;
  16416. })());
  16417. // Maximum profile
  16418. builder.addTable('maxp',
  16419. '\x00\x00\x50\x00' + // Version number
  16420. string16(numGlyphs)); // Num of glyphs
  16421. // Naming tables
  16422. builder.addTable('name', createNameTable(fontName));
  16423. // PostScript informations
  16424. builder.addTable('post', createPostTable(properties));
  16425. return builder.toArray();
  16426. },
  16427. /**
  16428. * Builds a char code to unicode map based on section 9.10 of the spec.
  16429. * @param {Object} properties Font properties object.
  16430. * @return {Object} A ToUnicodeMap object.
  16431. */
  16432. buildToUnicode: function Font_buildToUnicode(properties) {
  16433. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16434. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16435. return properties.toUnicode;
  16436. }
  16437. // According to the spec if the font is a simple font we should only map
  16438. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16439. // the differences array only contains adobe standard or symbol set names,
  16440. // in pratice it seems better to always try to create a toUnicode
  16441. // map based of the default encoding.
  16442. var toUnicode, charcode;
  16443. if (!properties.composite /* is simple font */) {
  16444. toUnicode = [];
  16445. var encoding = properties.defaultEncoding.slice();
  16446. var baseEncodingName = properties.baseEncodingName;
  16447. // Merge in the differences array.
  16448. var differences = properties.differences;
  16449. for (charcode in differences) {
  16450. encoding[charcode] = differences[charcode];
  16451. }
  16452. for (charcode in encoding) {
  16453. // a) Map the character code to a character name.
  16454. var glyphName = encoding[charcode];
  16455. // b) Look up the character name in the Adobe Glyph List (see the
  16456. // Bibliography) to obtain the corresponding Unicode value.
  16457. if (glyphName === '') {
  16458. continue;
  16459. } else if (GlyphsUnicode[glyphName] === undefined) {
  16460. // (undocumented) c) Few heuristics to recognize unknown glyphs
  16461. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  16462. var code = 0;
  16463. switch (glyphName[0]) {
  16464. case 'G': // Gxx glyph
  16465. if (glyphName.length === 3) {
  16466. code = parseInt(glyphName.substr(1), 16);
  16467. }
  16468. break;
  16469. case 'g': // g00xx glyph
  16470. if (glyphName.length === 5) {
  16471. code = parseInt(glyphName.substr(1), 16);
  16472. }
  16473. break;
  16474. case 'C': // Cddd glyph
  16475. case 'c': // cddd glyph
  16476. if (glyphName.length >= 3) {
  16477. code = +glyphName.substr(1);
  16478. }
  16479. break;
  16480. }
  16481. if (code) {
  16482. // If |baseEncodingName| is one the predefined encodings,
  16483. // and |code| equals |charcode|, using the glyph defined in the
  16484. // baseEncoding seems to yield a better |toUnicode| mapping
  16485. // (fixes issue 5070).
  16486. if (baseEncodingName && code === +charcode) {
  16487. var baseEncoding = Encodings[baseEncodingName];
  16488. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  16489. toUnicode[charcode] =
  16490. String.fromCharCode(GlyphsUnicode[glyphName]);
  16491. continue;
  16492. }
  16493. }
  16494. toUnicode[charcode] = String.fromCharCode(code);
  16495. }
  16496. continue;
  16497. }
  16498. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  16499. }
  16500. return new ToUnicodeMap(toUnicode);
  16501. }
  16502. // If the font is a composite font that uses one of the predefined CMaps
  16503. // listed in Table 118 (except Identity–H and Identity–V) or whose
  16504. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  16505. // Adobe-Korea1 character collection:
  16506. if (properties.composite && (
  16507. (properties.cMap.builtInCMap &&
  16508. !(properties.cMap instanceof IdentityCMap)) ||
  16509. (properties.cidSystemInfo.registry === 'Adobe' &&
  16510. (properties.cidSystemInfo.ordering === 'GB1' ||
  16511. properties.cidSystemInfo.ordering === 'CNS1' ||
  16512. properties.cidSystemInfo.ordering === 'Japan1' ||
  16513. properties.cidSystemInfo.ordering === 'Korea1')))) {
  16514. // Then:
  16515. // a) Map the character code to a character identifier (CID) according
  16516. // to the font’s CMap.
  16517. // b) Obtain the registry and ordering of the character collection used
  16518. // by the font’s CMap (for example, Adobe and Japan1) from its
  16519. // CIDSystemInfo dictionary.
  16520. var registry = properties.cidSystemInfo.registry;
  16521. var ordering = properties.cidSystemInfo.ordering;
  16522. // c) Construct a second CMap name by concatenating the registry and
  16523. // ordering obtained in step (b) in the format registry–ordering–UCS2
  16524. // (for example, Adobe–Japan1–UCS2).
  16525. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  16526. // d) Obtain the CMap with the name constructed in step (c) (available
  16527. // from the ASN Web site; see the Bibliography).
  16528. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  16529. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16530. var cMap = properties.cMap;
  16531. toUnicode = [];
  16532. cMap.forEach(function(charcode, cid) {
  16533. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16534. // e) Map the CID obtained in step (a) according to the CMap obtained
  16535. // in step (d), producing a Unicode value.
  16536. var ucs2 = ucs2CMap.lookup(cid);
  16537. if (ucs2) {
  16538. toUnicode[charcode] =
  16539. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  16540. ucs2.charCodeAt(1));
  16541. }
  16542. });
  16543. return new ToUnicodeMap(toUnicode);
  16544. }
  16545. // The viewer's choice, just use an identity map.
  16546. return new IdentityToUnicodeMap(properties.firstChar,
  16547. properties.lastChar);
  16548. },
  16549. get spaceWidth() {
  16550. if ('_shadowWidth' in this) {
  16551. return this._shadowWidth;
  16552. }
  16553. // trying to estimate space character width
  16554. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  16555. var width;
  16556. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  16557. var glyphName = possibleSpaceReplacements[i];
  16558. // if possible, getting width by glyph name
  16559. if (glyphName in this.widths) {
  16560. width = this.widths[glyphName];
  16561. break;
  16562. }
  16563. var glyphUnicode = GlyphsUnicode[glyphName];
  16564. // finding the charcode via unicodeToCID map
  16565. var charcode = 0;
  16566. if (this.composite) {
  16567. if (this.cMap.contains(glyphUnicode)) {
  16568. charcode = this.cMap.lookup(glyphUnicode);
  16569. }
  16570. }
  16571. // ... via toUnicode map
  16572. if (!charcode && 'toUnicode' in this) {
  16573. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  16574. }
  16575. // setting it to unicode if negative or undefined
  16576. if (charcode <= 0) {
  16577. charcode = glyphUnicode;
  16578. }
  16579. // trying to get width via charcode
  16580. width = this.widths[charcode];
  16581. if (width) {
  16582. break; // the non-zero width found
  16583. }
  16584. }
  16585. width = width || this.defaultWidth;
  16586. // Do not shadow the property here. See discussion:
  16587. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  16588. this._shadowWidth = width;
  16589. return width;
  16590. },
  16591. charToGlyph: function Font_charToGlyph(charcode) {
  16592. var fontCharCode, width, operatorListId;
  16593. var widthCode = charcode;
  16594. if (this.cMap && this.cMap.contains(charcode)) {
  16595. widthCode = this.cMap.lookup(charcode);
  16596. }
  16597. width = this.widths[widthCode];
  16598. width = isNum(width) ? width : this.defaultWidth;
  16599. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  16600. var unicode = this.toUnicode.get(charcode) || charcode;
  16601. if (typeof unicode === 'number') {
  16602. unicode = String.fromCharCode(unicode);
  16603. }
  16604. // First try the toFontChar map, if it's not there then try falling
  16605. // back to the char code.
  16606. fontCharCode = this.toFontChar[charcode] || charcode;
  16607. if (this.missingFile) {
  16608. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  16609. }
  16610. if (this.isType3Font) {
  16611. // Font char code in this case is actually a glyph name.
  16612. operatorListId = fontCharCode;
  16613. }
  16614. var accent = null;
  16615. if (this.seacMap && this.seacMap[charcode]) {
  16616. var seac = this.seacMap[charcode];
  16617. fontCharCode = seac.baseFontCharCode;
  16618. accent = {
  16619. fontChar: String.fromCharCode(seac.accentFontCharCode),
  16620. offset: seac.accentOffset
  16621. };
  16622. }
  16623. var fontChar = String.fromCharCode(fontCharCode);
  16624. var glyph = this.glyphCache[charcode];
  16625. if (!glyph ||
  16626. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  16627. operatorListId)) {
  16628. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  16629. operatorListId);
  16630. this.glyphCache[charcode] = glyph;
  16631. }
  16632. return glyph;
  16633. },
  16634. charsToGlyphs: function Font_charsToGlyphs(chars) {
  16635. var charsCache = this.charsCache;
  16636. var glyphs, glyph, charcode;
  16637. // if we translated this string before, just grab it from the cache
  16638. if (charsCache) {
  16639. glyphs = charsCache[chars];
  16640. if (glyphs) {
  16641. return glyphs;
  16642. }
  16643. }
  16644. // lazily create the translation cache
  16645. if (!charsCache) {
  16646. charsCache = this.charsCache = Object.create(null);
  16647. }
  16648. glyphs = [];
  16649. var charsCacheKey = chars;
  16650. var i = 0, ii;
  16651. if (this.cMap) {
  16652. // composite fonts have multi-byte strings convert the string from
  16653. // single-byte to multi-byte
  16654. while (i < chars.length) {
  16655. var c = this.cMap.readCharCode(chars, i);
  16656. charcode = c[0];
  16657. var length = c[1];
  16658. i += length;
  16659. glyph = this.charToGlyph(charcode);
  16660. glyphs.push(glyph);
  16661. // placing null after each word break charcode (ASCII SPACE)
  16662. // Ignore occurences of 0x20 in multiple-byte codes.
  16663. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  16664. glyphs.push(null);
  16665. }
  16666. }
  16667. } else {
  16668. for (i = 0, ii = chars.length; i < ii; ++i) {
  16669. charcode = chars.charCodeAt(i);
  16670. glyph = this.charToGlyph(charcode);
  16671. glyphs.push(glyph);
  16672. if (charcode === 0x20) {
  16673. glyphs.push(null);
  16674. }
  16675. }
  16676. }
  16677. // Enter the translated string into the cache
  16678. return (charsCache[charsCacheKey] = glyphs);
  16679. }
  16680. };
  16681. return Font;
  16682. })();
  16683. var ErrorFont = (function ErrorFontClosure() {
  16684. function ErrorFont(error) {
  16685. this.error = error;
  16686. this.loadedName = 'g_font_error';
  16687. this.loading = false;
  16688. }
  16689. ErrorFont.prototype = {
  16690. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  16691. return [];
  16692. },
  16693. exportData: function ErrorFont_exportData() {
  16694. return {error: this.error};
  16695. }
  16696. };
  16697. return ErrorFont;
  16698. })();
  16699. /**
  16700. * Shared logic for building a char code to glyph id mapping for Type1 and
  16701. * simple CFF fonts. See section 9.6.6.2 of the spec.
  16702. * @param {Object} properties Font properties object.
  16703. * @param {Object} builtInEncoding The encoding contained within the actual font
  16704. * data.
  16705. * @param {Array} Array of glyph names where the index is the glyph ID.
  16706. * @returns {Object} A char code to glyph ID map.
  16707. */
  16708. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  16709. var charCodeToGlyphId = Object.create(null);
  16710. var glyphId, charCode, baseEncoding;
  16711. if (properties.baseEncodingName) {
  16712. // If a valid base encoding name was used, the mapping is initialized with
  16713. // that.
  16714. baseEncoding = Encodings[properties.baseEncodingName];
  16715. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  16716. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  16717. if (glyphId >= 0) {
  16718. charCodeToGlyphId[charCode] = glyphId;
  16719. }
  16720. }
  16721. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  16722. // For a symbolic font the encoding should be the fonts built-in
  16723. // encoding.
  16724. for (charCode in builtInEncoding) {
  16725. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  16726. }
  16727. } else {
  16728. // For non-symbolic fonts that don't have a base encoding the standard
  16729. // encoding should be used.
  16730. baseEncoding = Encodings.StandardEncoding;
  16731. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  16732. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  16733. if (glyphId >= 0) {
  16734. charCodeToGlyphId[charCode] = glyphId;
  16735. }
  16736. }
  16737. }
  16738. // Lastly, merge in the differences.
  16739. var differences = properties.differences;
  16740. if (differences) {
  16741. for (charCode in differences) {
  16742. var glyphName = differences[charCode];
  16743. glyphId = glyphNames.indexOf(glyphName);
  16744. if (glyphId >= 0) {
  16745. charCodeToGlyphId[charCode] = glyphId;
  16746. }
  16747. }
  16748. }
  16749. return charCodeToGlyphId;
  16750. }
  16751. /*
  16752. * CharStrings are encoded following the the CharString Encoding sequence
  16753. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  16754. * The value in a byte indicates a command, a number, or subsequent bytes
  16755. * that are to be interpreted in a special way.
  16756. *
  16757. * CharString Number Encoding:
  16758. * A CharString byte containing the values from 32 through 255 inclusive
  16759. * indicate an integer. These values are decoded in four ranges.
  16760. *
  16761. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  16762. * indicate the integer v - 139. Thus, the integer values from -107 through
  16763. * 107 inclusive may be encoded in single byte.
  16764. *
  16765. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  16766. * indicates an integer involving the next byte, w, according to the formula:
  16767. * [(v - 247) x 256] + w + 108
  16768. *
  16769. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  16770. * indicates an integer involving the next byte, w, according to the formula:
  16771. * -[(v - 251) * 256] - w - 108
  16772. *
  16773. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  16774. * are a two complement signed integer. The first of these bytes contains the
  16775. * highest order bits, the second byte contains the next higher order bits
  16776. * and the fourth byte contain the lowest order bits.
  16777. *
  16778. *
  16779. * CharString Command Encoding:
  16780. * CharStrings commands are encoded in 1 or 2 bytes.
  16781. *
  16782. * Single byte commands are encoded in 1 byte that contains a value between
  16783. * 0 and 31 inclusive.
  16784. * If a command byte contains the value 12, then the value in the next byte
  16785. * indicates a command. This "escape" mechanism allows many extra commands
  16786. * to be encoded and this encoding technique helps to minimize the length of
  16787. * the charStrings.
  16788. */
  16789. var Type1CharString = (function Type1CharStringClosure() {
  16790. var COMMAND_MAP = {
  16791. 'hstem': [1],
  16792. 'vstem': [3],
  16793. 'vmoveto': [4],
  16794. 'rlineto': [5],
  16795. 'hlineto': [6],
  16796. 'vlineto': [7],
  16797. 'rrcurveto': [8],
  16798. 'callsubr': [10],
  16799. 'flex': [12, 35],
  16800. 'drop' : [12, 18],
  16801. 'endchar': [14],
  16802. 'rmoveto': [21],
  16803. 'hmoveto': [22],
  16804. 'vhcurveto': [30],
  16805. 'hvcurveto': [31]
  16806. };
  16807. function Type1CharString() {
  16808. this.width = 0;
  16809. this.lsb = 0;
  16810. this.flexing = false;
  16811. this.output = [];
  16812. this.stack = [];
  16813. }
  16814. Type1CharString.prototype = {
  16815. convert: function Type1CharString_convert(encoded, subrs) {
  16816. var count = encoded.length;
  16817. var error = false;
  16818. var wx, sbx, subrNumber;
  16819. for (var i = 0; i < count; i++) {
  16820. var value = encoded[i];
  16821. if (value < 32) {
  16822. if (value === 12) {
  16823. value = (value << 8) + encoded[++i];
  16824. }
  16825. switch (value) {
  16826. case 1: // hstem
  16827. if (!HINTING_ENABLED) {
  16828. this.stack = [];
  16829. break;
  16830. }
  16831. error = this.executeCommand(2, COMMAND_MAP.hstem);
  16832. break;
  16833. case 3: // vstem
  16834. if (!HINTING_ENABLED) {
  16835. this.stack = [];
  16836. break;
  16837. }
  16838. error = this.executeCommand(2, COMMAND_MAP.vstem);
  16839. break;
  16840. case 4: // vmoveto
  16841. if (this.flexing) {
  16842. if (this.stack.length < 1) {
  16843. error = true;
  16844. break;
  16845. }
  16846. // Add the dx for flex and but also swap the values so they are
  16847. // the right order.
  16848. var dy = this.stack.pop();
  16849. this.stack.push(0, dy);
  16850. break;
  16851. }
  16852. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  16853. break;
  16854. case 5: // rlineto
  16855. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  16856. break;
  16857. case 6: // hlineto
  16858. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  16859. break;
  16860. case 7: // vlineto
  16861. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  16862. break;
  16863. case 8: // rrcurveto
  16864. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  16865. break;
  16866. case 9: // closepath
  16867. // closepath is a Type1 command that does not take argument and is
  16868. // useless in Type2 and it can simply be ignored.
  16869. this.stack = [];
  16870. break;
  16871. case 10: // callsubr
  16872. if (this.stack.length < 1) {
  16873. error = true;
  16874. break;
  16875. }
  16876. subrNumber = this.stack.pop();
  16877. error = this.convert(subrs[subrNumber], subrs);
  16878. break;
  16879. case 11: // return
  16880. return error;
  16881. case 13: // hsbw
  16882. if (this.stack.length < 2) {
  16883. error = true;
  16884. break;
  16885. }
  16886. // To convert to type2 we have to move the width value to the
  16887. // first part of the charstring and then use hmoveto with lsb.
  16888. wx = this.stack.pop();
  16889. sbx = this.stack.pop();
  16890. this.lsb = sbx;
  16891. this.width = wx;
  16892. this.stack.push(sbx);
  16893. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  16894. break;
  16895. case 14: // endchar
  16896. this.output.push(COMMAND_MAP.endchar[0]);
  16897. break;
  16898. case 21: // rmoveto
  16899. if (this.flexing) {
  16900. break;
  16901. }
  16902. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  16903. break;
  16904. case 22: // hmoveto
  16905. if (this.flexing) {
  16906. // Add the dy for flex.
  16907. this.stack.push(0);
  16908. break;
  16909. }
  16910. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  16911. break;
  16912. case 30: // vhcurveto
  16913. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  16914. break;
  16915. case 31: // hvcurveto
  16916. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  16917. break;
  16918. case (12 << 8) + 0: // dotsection
  16919. // dotsection is a Type1 command to specify some hinting feature
  16920. // for dots that do not take a parameter and it can safely be
  16921. // ignored for Type2.
  16922. this.stack = [];
  16923. break;
  16924. case (12 << 8) + 1: // vstem3
  16925. if (!HINTING_ENABLED) {
  16926. this.stack = [];
  16927. break;
  16928. }
  16929. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  16930. // multiple parameters, so instead of returning [vh]stem3 take a
  16931. // shortcut and return [vhstem] instead.
  16932. error = this.executeCommand(2, COMMAND_MAP.vstem);
  16933. break;
  16934. case (12 << 8) + 2: // hstem3
  16935. if (!HINTING_ENABLED) {
  16936. this.stack = [];
  16937. break;
  16938. }
  16939. // See vstem3.
  16940. error = this.executeCommand(2, COMMAND_MAP.hstem);
  16941. break;
  16942. case (12 << 8) + 6: // seac
  16943. // seac is like type 2's special endchar but it doesn't use the
  16944. // first argument asb, so remove it.
  16945. if (SEAC_ANALYSIS_ENABLED) {
  16946. this.seac = this.stack.splice(-4, 4);
  16947. error = this.executeCommand(0, COMMAND_MAP.endchar);
  16948. } else {
  16949. error = this.executeCommand(4, COMMAND_MAP.endchar);
  16950. }
  16951. break;
  16952. case (12 << 8) + 7: // sbw
  16953. if (this.stack.length < 4) {
  16954. error = true;
  16955. break;
  16956. }
  16957. // To convert to type2 we have to move the width value to the
  16958. // first part of the charstring and then use rmoveto with
  16959. // (dx, dy). The height argument will not be used for vmtx and
  16960. // vhea tables reconstruction -- ignoring it.
  16961. var wy = this.stack.pop();
  16962. wx = this.stack.pop();
  16963. var sby = this.stack.pop();
  16964. sbx = this.stack.pop();
  16965. this.lsb = sbx;
  16966. this.width = wx;
  16967. this.stack.push(sbx, sby);
  16968. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  16969. break;
  16970. case (12 << 8) + 12: // div
  16971. if (this.stack.length < 2) {
  16972. error = true;
  16973. break;
  16974. }
  16975. var num2 = this.stack.pop();
  16976. var num1 = this.stack.pop();
  16977. this.stack.push(num1 / num2);
  16978. break;
  16979. case (12 << 8) + 16: // callothersubr
  16980. if (this.stack.length < 2) {
  16981. error = true;
  16982. break;
  16983. }
  16984. subrNumber = this.stack.pop();
  16985. var numArgs = this.stack.pop();
  16986. if (subrNumber === 0 && numArgs === 3) {
  16987. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  16988. this.stack.push(
  16989. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  16990. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  16991. flexArgs[4], // bcp2x
  16992. flexArgs[5], // bcp2y
  16993. flexArgs[6], // p2x
  16994. flexArgs[7], // p2y
  16995. flexArgs[8], // bcp3x
  16996. flexArgs[9], // bcp3y
  16997. flexArgs[10], // bcp4x
  16998. flexArgs[11], // bcp4y
  16999. flexArgs[12], // p3x
  17000. flexArgs[13], // p3y
  17001. flexArgs[14] // flexDepth
  17002. // 15 = finalx unused by flex
  17003. // 16 = finaly unused by flex
  17004. );
  17005. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17006. this.flexing = false;
  17007. this.stack.push(flexArgs[15], flexArgs[16]);
  17008. } else if (subrNumber === 1 && numArgs === 0) {
  17009. this.flexing = true;
  17010. }
  17011. break;
  17012. case (12 << 8) + 17: // pop
  17013. // Ignore this since it is only used with othersubr.
  17014. break;
  17015. case (12 << 8) + 33: // setcurrentpoint
  17016. // Ignore for now.
  17017. this.stack = [];
  17018. break;
  17019. default:
  17020. warn('Unknown type 1 charstring command of "' + value + '"');
  17021. break;
  17022. }
  17023. if (error) {
  17024. break;
  17025. }
  17026. continue;
  17027. } else if (value <= 246) {
  17028. value = value - 139;
  17029. } else if (value <= 250) {
  17030. value = ((value - 247) * 256) + encoded[++i] + 108;
  17031. } else if (value <= 254) {
  17032. value = -((value - 251) * 256) - encoded[++i] - 108;
  17033. } else {
  17034. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17035. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17036. }
  17037. this.stack.push(value);
  17038. }
  17039. return error;
  17040. },
  17041. executeCommand: function(howManyArgs, command, keepStack) {
  17042. var stackLength = this.stack.length;
  17043. if (howManyArgs > stackLength) {
  17044. return true;
  17045. }
  17046. var start = stackLength - howManyArgs;
  17047. for (var i = start; i < stackLength; i++) {
  17048. var value = this.stack[i];
  17049. if (value === (value | 0)) { // int
  17050. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17051. } else { // fixed point
  17052. value = (65536 * value) | 0;
  17053. this.output.push(255,
  17054. (value >> 24) & 0xFF,
  17055. (value >> 16) & 0xFF,
  17056. (value >> 8) & 0xFF,
  17057. value & 0xFF);
  17058. }
  17059. }
  17060. this.output.push.apply(this.output, command);
  17061. if (keepStack) {
  17062. this.stack.splice(start, howManyArgs);
  17063. } else {
  17064. this.stack.length = 0;
  17065. }
  17066. return false;
  17067. }
  17068. };
  17069. return Type1CharString;
  17070. })();
  17071. /*
  17072. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17073. * program. Some of its logic depends on the Type2 charstrings
  17074. * structure.
  17075. * Note: this doesn't really parse the font since that would require evaluation
  17076. * of PostScript, but it is possible in most cases to extract what we need
  17077. * without a full parse.
  17078. */
  17079. var Type1Parser = (function Type1ParserClosure() {
  17080. /*
  17081. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17082. * of Plaintext Bytes. The function took a key as a parameter which can be
  17083. * for decrypting the eexec block of for decoding charStrings.
  17084. */
  17085. var EEXEC_ENCRYPT_KEY = 55665;
  17086. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17087. function isHexDigit(code) {
  17088. return code >= 48 && code <= 57 || // '0'-'9'
  17089. code >= 65 && code <= 70 || // 'A'-'F'
  17090. code >= 97 && code <= 102; // 'a'-'f'
  17091. }
  17092. function decrypt(data, key, discardNumber) {
  17093. var r = key | 0, c1 = 52845, c2 = 22719;
  17094. var count = data.length;
  17095. var decrypted = new Uint8Array(count);
  17096. for (var i = 0; i < count; i++) {
  17097. var value = data[i];
  17098. decrypted[i] = value ^ (r >> 8);
  17099. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17100. }
  17101. return Array.prototype.slice.call(decrypted, discardNumber);
  17102. }
  17103. function decryptAscii(data, key, discardNumber) {
  17104. var r = key | 0, c1 = 52845, c2 = 22719;
  17105. var count = data.length, maybeLength = count >>> 1;
  17106. var decrypted = new Uint8Array(maybeLength);
  17107. var i, j;
  17108. for (i = 0, j = 0; i < count; i++) {
  17109. var digit1 = data[i];
  17110. if (!isHexDigit(digit1)) {
  17111. continue;
  17112. }
  17113. i++;
  17114. var digit2;
  17115. while (i < count && !isHexDigit(digit2 = data[i])) {
  17116. i++;
  17117. }
  17118. if (i < count) {
  17119. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17120. decrypted[j++] = value ^ (r >> 8);
  17121. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17122. }
  17123. }
  17124. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17125. }
  17126. function isSpecial(c) {
  17127. return c === 0x2F || // '/'
  17128. c === 0x5B || c === 0x5D || // '[', ']'
  17129. c === 0x7B || c === 0x7D || // '{', '}'
  17130. c === 0x28 || c === 0x29; // '(', ')'
  17131. }
  17132. function Type1Parser(stream, encrypted) {
  17133. if (encrypted) {
  17134. var data = stream.getBytes();
  17135. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17136. isHexDigit(data[2]) && isHexDigit(data[3]));
  17137. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17138. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17139. }
  17140. this.stream = stream;
  17141. this.nextChar();
  17142. }
  17143. Type1Parser.prototype = {
  17144. readNumberArray: function Type1Parser_readNumberArray() {
  17145. this.getToken(); // read '[' or '{' (arrays can start with either)
  17146. var array = [];
  17147. while (true) {
  17148. var token = this.getToken();
  17149. if (token === null || token === ']' || token === '}') {
  17150. break;
  17151. }
  17152. array.push(parseFloat(token || 0));
  17153. }
  17154. return array;
  17155. },
  17156. readNumber: function Type1Parser_readNumber() {
  17157. var token = this.getToken();
  17158. return parseFloat(token || 0);
  17159. },
  17160. readInt: function Type1Parser_readInt() {
  17161. // Use '| 0' to prevent setting a double into length such as the double
  17162. // does not flow into the loop variable.
  17163. var token = this.getToken();
  17164. return parseInt(token || 0, 10) | 0;
  17165. },
  17166. readBoolean: function Type1Parser_readBoolean() {
  17167. var token = this.getToken();
  17168. // Use 1 and 0 since that's what type2 charstrings use.
  17169. return token === 'true' ? 1 : 0;
  17170. },
  17171. nextChar : function Type1_nextChar() {
  17172. return (this.currentChar = this.stream.getByte());
  17173. },
  17174. getToken: function Type1Parser_getToken() {
  17175. // Eat whitespace and comments.
  17176. var comment = false;
  17177. var ch = this.currentChar;
  17178. while (true) {
  17179. if (ch === -1) {
  17180. return null;
  17181. }
  17182. if (comment) {
  17183. if (ch === 0x0A || ch === 0x0D) {
  17184. comment = false;
  17185. }
  17186. } else if (ch === 0x25) { // '%'
  17187. comment = true;
  17188. } else if (!Lexer.isSpace(ch)) {
  17189. break;
  17190. }
  17191. ch = this.nextChar();
  17192. }
  17193. if (isSpecial(ch)) {
  17194. this.nextChar();
  17195. return String.fromCharCode(ch);
  17196. }
  17197. var token = '';
  17198. do {
  17199. token += String.fromCharCode(ch);
  17200. ch = this.nextChar();
  17201. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17202. return token;
  17203. },
  17204. /*
  17205. * Returns an object containing a Subrs array and a CharStrings
  17206. * array extracted from and eexec encrypted block of data
  17207. */
  17208. extractFontProgram: function Type1Parser_extractFontProgram() {
  17209. var stream = this.stream;
  17210. var subrs = [], charstrings = [];
  17211. var program = {
  17212. subrs: [],
  17213. charstrings: [],
  17214. properties: {
  17215. 'privateData': {
  17216. 'lenIV': 4
  17217. }
  17218. }
  17219. };
  17220. var token, length, data, lenIV, encoded;
  17221. while ((token = this.getToken()) !== null) {
  17222. if (token !== '/') {
  17223. continue;
  17224. }
  17225. token = this.getToken();
  17226. switch (token) {
  17227. case 'CharStrings':
  17228. // The number immediately following CharStrings must be greater or
  17229. // equal to the number of CharStrings.
  17230. this.getToken();
  17231. this.getToken(); // read in 'dict'
  17232. this.getToken(); // read in 'dup'
  17233. this.getToken(); // read in 'begin'
  17234. while(true) {
  17235. token = this.getToken();
  17236. if (token === null || token === 'end') {
  17237. break;
  17238. }
  17239. if (token !== '/') {
  17240. continue;
  17241. }
  17242. var glyph = this.getToken();
  17243. length = this.readInt();
  17244. this.getToken(); // read in 'RD' or '-|'
  17245. data = stream.makeSubStream(stream.pos, length);
  17246. lenIV = program.properties.privateData['lenIV'];
  17247. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17248. // Skip past the required space and binary data.
  17249. stream.skip(length);
  17250. this.nextChar();
  17251. token = this.getToken(); // read in 'ND' or '|-'
  17252. if (token === 'noaccess') {
  17253. this.getToken(); // read in 'def'
  17254. }
  17255. charstrings.push({
  17256. glyph: glyph,
  17257. encoded: encoded
  17258. });
  17259. }
  17260. break;
  17261. case 'Subrs':
  17262. var num = this.readInt();
  17263. this.getToken(); // read in 'array'
  17264. while ((token = this.getToken()) === 'dup') {
  17265. var index = this.readInt();
  17266. length = this.readInt();
  17267. this.getToken(); // read in 'RD' or '-|'
  17268. data = stream.makeSubStream(stream.pos, length);
  17269. lenIV = program.properties.privateData['lenIV'];
  17270. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17271. // Skip past the required space and binary data.
  17272. stream.skip(length);
  17273. this.nextChar();
  17274. token = this.getToken(); // read in 'NP' or '|'
  17275. if (token === 'noaccess') {
  17276. this.getToken(); // read in 'put'
  17277. }
  17278. subrs[index] = encoded;
  17279. }
  17280. break;
  17281. case 'BlueValues':
  17282. case 'OtherBlues':
  17283. case 'FamilyBlues':
  17284. case 'FamilyOtherBlues':
  17285. var blueArray = this.readNumberArray();
  17286. // *Blue* values may contain invalid data: disables reading of
  17287. // those values when hinting is disabled.
  17288. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17289. HINTING_ENABLED) {
  17290. program.properties.privateData[token] = blueArray;
  17291. }
  17292. break;
  17293. case 'StemSnapH':
  17294. case 'StemSnapV':
  17295. program.properties.privateData[token] = this.readNumberArray();
  17296. break;
  17297. case 'StdHW':
  17298. case 'StdVW':
  17299. program.properties.privateData[token] =
  17300. this.readNumberArray()[0];
  17301. break;
  17302. case 'BlueShift':
  17303. case 'lenIV':
  17304. case 'BlueFuzz':
  17305. case 'BlueScale':
  17306. case 'LanguageGroup':
  17307. case 'ExpansionFactor':
  17308. program.properties.privateData[token] = this.readNumber();
  17309. break;
  17310. case 'ForceBold':
  17311. program.properties.privateData[token] = this.readBoolean();
  17312. break;
  17313. }
  17314. }
  17315. for (var i = 0; i < charstrings.length; i++) {
  17316. glyph = charstrings[i].glyph;
  17317. encoded = charstrings[i].encoded;
  17318. var charString = new Type1CharString();
  17319. var error = charString.convert(encoded, subrs);
  17320. var output = charString.output;
  17321. if (error) {
  17322. // It seems when FreeType encounters an error while evaluating a glyph
  17323. // that it completely ignores the glyph so we'll mimic that behaviour
  17324. // here and put an endchar to make the validator happy.
  17325. output = [14];
  17326. }
  17327. program.charstrings.push({
  17328. glyphName: glyph,
  17329. charstring: output,
  17330. width: charString.width,
  17331. lsb: charString.lsb,
  17332. seac: charString.seac
  17333. });
  17334. }
  17335. return program;
  17336. },
  17337. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17338. var token;
  17339. while ((token = this.getToken()) !== null) {
  17340. if (token !== '/') {
  17341. continue;
  17342. }
  17343. token = this.getToken();
  17344. switch (token) {
  17345. case 'FontMatrix':
  17346. var matrix = this.readNumberArray();
  17347. properties.fontMatrix = matrix;
  17348. break;
  17349. case 'Encoding':
  17350. var encodingArg = this.getToken();
  17351. var encoding;
  17352. if (!/^\d+$/.test(encodingArg)) {
  17353. // encoding name is specified
  17354. encoding = Encodings[encodingArg];
  17355. } else {
  17356. encoding = [];
  17357. var size = parseInt(encodingArg, 10) | 0;
  17358. this.getToken(); // read in 'array'
  17359. for (var j = 0; j < size; j++) {
  17360. token = this.getToken();
  17361. // skipping till first dup or def (e.g. ignoring for statement)
  17362. while (token !== 'dup' && token !== 'def') {
  17363. token = this.getToken();
  17364. if (token === null) {
  17365. return; // invalid header
  17366. }
  17367. }
  17368. if (token === 'def') {
  17369. break; // read all array data
  17370. }
  17371. var index = this.readInt();
  17372. this.getToken(); // read in '/'
  17373. var glyph = this.getToken();
  17374. encoding[index] = glyph;
  17375. this.getToken(); // read the in 'put'
  17376. }
  17377. }
  17378. properties.builtInEncoding = encoding;
  17379. break;
  17380. case 'FontBBox':
  17381. var fontBBox = this.readNumberArray();
  17382. // adjusting ascent/descent
  17383. properties.ascent = fontBBox[3];
  17384. properties.descent = fontBBox[1];
  17385. properties.ascentScaled = true;
  17386. break;
  17387. }
  17388. }
  17389. }
  17390. };
  17391. return Type1Parser;
  17392. })();
  17393. /**
  17394. * The CFF class takes a Type1 file and wrap it into a
  17395. * 'Compact Font Format' which itself embed Type2 charstrings.
  17396. */
  17397. var CFFStandardStrings = [
  17398. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17399. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17400. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17401. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17402. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17403. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17404. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17405. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17406. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17407. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17408. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17409. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17410. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17411. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17412. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17413. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17414. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17415. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17416. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17417. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17418. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17419. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17420. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17421. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17422. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17423. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17424. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17425. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17426. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17427. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17428. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17429. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17430. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17431. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17432. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17433. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  17434. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  17435. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  17436. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  17437. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  17438. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  17439. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  17440. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  17441. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  17442. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  17443. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  17444. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  17445. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  17446. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  17447. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  17448. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  17449. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  17450. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  17451. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  17452. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  17453. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  17454. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  17455. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  17456. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  17457. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  17458. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  17459. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  17460. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  17461. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  17462. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  17463. ];
  17464. // Type1Font is also a CIDFontType0.
  17465. var Type1Font = function Type1Font(name, file, properties) {
  17466. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  17467. // Also, length1 and length2 might be off by 6 bytes as well.
  17468. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  17469. var PFB_HEADER_SIZE = 6;
  17470. var headerBlockLength = properties.length1;
  17471. var eexecBlockLength = properties.length2;
  17472. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  17473. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  17474. if (pfbHeaderPresent) {
  17475. file.skip(PFB_HEADER_SIZE);
  17476. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17477. (pfbHeader[3] << 8) | pfbHeader[2];
  17478. }
  17479. // Get the data block containing glyphs and subrs informations
  17480. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  17481. var headerBlockParser = new Type1Parser(headerBlock);
  17482. headerBlockParser.extractFontHeader(properties);
  17483. if (pfbHeaderPresent) {
  17484. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  17485. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17486. (pfbHeader[3] << 8) | pfbHeader[2];
  17487. }
  17488. // Decrypt the data blocks and retrieve it's content
  17489. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  17490. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  17491. var data = eexecBlockParser.extractFontProgram();
  17492. for (var info in data.properties) {
  17493. properties[info] = data.properties[info];
  17494. }
  17495. var charstrings = data.charstrings;
  17496. var type2Charstrings = this.getType2Charstrings(charstrings);
  17497. var subrs = this.getType2Subrs(data.subrs);
  17498. this.charstrings = charstrings;
  17499. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  17500. subrs, properties);
  17501. this.seacs = this.getSeacs(data.charstrings);
  17502. };
  17503. Type1Font.prototype = {
  17504. get numGlyphs() {
  17505. return this.charstrings.length + 1;
  17506. },
  17507. getCharset: function Type1Font_getCharset() {
  17508. var charset = ['.notdef'];
  17509. var charstrings = this.charstrings;
  17510. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17511. charset.push(charstrings[glyphId].glyphName);
  17512. }
  17513. return charset;
  17514. },
  17515. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  17516. var charstrings = this.charstrings;
  17517. var glyphNames = ['.notdef'], glyphId;
  17518. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17519. glyphNames.push(charstrings[glyphId].glyphName);
  17520. }
  17521. var encoding = properties.builtInEncoding;
  17522. if (encoding) {
  17523. var builtInEncoding = {};
  17524. for (var charCode in encoding) {
  17525. glyphId = glyphNames.indexOf(encoding[charCode]);
  17526. if (glyphId >= 0) {
  17527. builtInEncoding[charCode] = glyphId;
  17528. }
  17529. }
  17530. }
  17531. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  17532. },
  17533. getSeacs: function Type1Font_getSeacs(charstrings) {
  17534. var i, ii;
  17535. var seacMap = [];
  17536. for (i = 0, ii = charstrings.length; i < ii; i++) {
  17537. var charstring = charstrings[i];
  17538. if (charstring.seac) {
  17539. // Offset by 1 for .notdef
  17540. seacMap[i + 1] = charstring.seac;
  17541. }
  17542. }
  17543. return seacMap;
  17544. },
  17545. getType2Charstrings: function Type1Font_getType2Charstrings(
  17546. type1Charstrings) {
  17547. var type2Charstrings = [];
  17548. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  17549. type2Charstrings.push(type1Charstrings[i].charstring);
  17550. }
  17551. return type2Charstrings;
  17552. },
  17553. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  17554. var bias = 0;
  17555. var count = type1Subrs.length;
  17556. if (count < 1133) {
  17557. bias = 107;
  17558. } else if (count < 33769) {
  17559. bias = 1131;
  17560. } else {
  17561. bias = 32768;
  17562. }
  17563. // Add a bunch of empty subrs to deal with the Type2 bias
  17564. var type2Subrs = [];
  17565. var i;
  17566. for (i = 0; i < bias; i++) {
  17567. type2Subrs.push([0x0B]);
  17568. }
  17569. for (i = 0; i < count; i++) {
  17570. type2Subrs.push(type1Subrs[i]);
  17571. }
  17572. return type2Subrs;
  17573. },
  17574. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  17575. var cff = new CFF();
  17576. cff.header = new CFFHeader(1, 0, 4, 4);
  17577. cff.names = [name];
  17578. var topDict = new CFFTopDict();
  17579. // CFF strings IDs 0...390 are predefined names, so refering
  17580. // to entries in our own String INDEX starts at SID 391.
  17581. topDict.setByName('version', 391);
  17582. topDict.setByName('Notice', 392);
  17583. topDict.setByName('FullName', 393);
  17584. topDict.setByName('FamilyName', 394);
  17585. topDict.setByName('Weight', 395);
  17586. topDict.setByName('Encoding', null); // placeholder
  17587. topDict.setByName('FontMatrix', properties.fontMatrix);
  17588. topDict.setByName('FontBBox', properties.bbox);
  17589. topDict.setByName('charset', null); // placeholder
  17590. topDict.setByName('CharStrings', null); // placeholder
  17591. topDict.setByName('Private', null); // placeholder
  17592. cff.topDict = topDict;
  17593. var strings = new CFFStrings();
  17594. strings.add('Version 0.11'); // Version
  17595. strings.add('See original notice'); // Notice
  17596. strings.add(name); // FullName
  17597. strings.add(name); // FamilyName
  17598. strings.add('Medium'); // Weight
  17599. cff.strings = strings;
  17600. cff.globalSubrIndex = new CFFIndex();
  17601. var count = glyphs.length;
  17602. var charsetArray = [0];
  17603. var i, ii;
  17604. for (i = 0; i < count; i++) {
  17605. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  17606. // TODO: Insert the string and correctly map it. Previously it was
  17607. // thought mapping names that aren't in the standard strings to .notdef
  17608. // was fine, however in issue818 when mapping them all to .notdef the
  17609. // adieresis glyph no longer worked.
  17610. if (index === -1) {
  17611. index = 0;
  17612. }
  17613. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  17614. }
  17615. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  17616. var charStringsIndex = new CFFIndex();
  17617. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  17618. for (i = 0; i < count; i++) {
  17619. charStringsIndex.add(glyphs[i]);
  17620. }
  17621. cff.charStrings = charStringsIndex;
  17622. var privateDict = new CFFPrivateDict();
  17623. privateDict.setByName('Subrs', null); // placeholder
  17624. var fields = [
  17625. 'BlueValues',
  17626. 'OtherBlues',
  17627. 'FamilyBlues',
  17628. 'FamilyOtherBlues',
  17629. 'StemSnapH',
  17630. 'StemSnapV',
  17631. 'BlueShift',
  17632. 'BlueFuzz',
  17633. 'BlueScale',
  17634. 'LanguageGroup',
  17635. 'ExpansionFactor',
  17636. 'ForceBold',
  17637. 'StdHW',
  17638. 'StdVW'
  17639. ];
  17640. for (i = 0, ii = fields.length; i < ii; i++) {
  17641. var field = fields[i];
  17642. if (!properties.privateData.hasOwnProperty(field)) {
  17643. continue;
  17644. }
  17645. var value = properties.privateData[field];
  17646. if (isArray(value)) {
  17647. // All of the private dictionary array data in CFF must be stored as
  17648. // "delta-encoded" numbers.
  17649. for (var j = value.length - 1; j > 0; j--) {
  17650. value[j] -= value[j - 1]; // ... difference from previous value
  17651. }
  17652. }
  17653. privateDict.setByName(field, value);
  17654. }
  17655. cff.topDict.privateDict = privateDict;
  17656. var subrIndex = new CFFIndex();
  17657. for (i = 0, ii = subrs.length; i < ii; i++) {
  17658. subrIndex.add(subrs[i]);
  17659. }
  17660. privateDict.subrsIndex = subrIndex;
  17661. var compiler = new CFFCompiler(cff);
  17662. return compiler.compile();
  17663. }
  17664. };
  17665. var CFFFont = (function CFFFontClosure() {
  17666. function CFFFont(file, properties) {
  17667. this.properties = properties;
  17668. var parser = new CFFParser(file, properties);
  17669. this.cff = parser.parse();
  17670. var compiler = new CFFCompiler(this.cff);
  17671. this.seacs = this.cff.seacs;
  17672. try {
  17673. this.data = compiler.compile();
  17674. } catch (e) {
  17675. warn('Failed to compile font ' + properties.loadedName);
  17676. // There may have just been an issue with the compiler, set the data
  17677. // anyway and hope the font loaded.
  17678. this.data = file;
  17679. }
  17680. }
  17681. CFFFont.prototype = {
  17682. get numGlyphs() {
  17683. return this.cff.charStrings.count;
  17684. },
  17685. getCharset: function CFFFont_getCharset() {
  17686. return this.cff.charset.charset;
  17687. },
  17688. getGlyphMapping: function CFFFont_getGlyphMapping() {
  17689. var cff = this.cff;
  17690. var properties = this.properties;
  17691. var charsets = cff.charset.charset;
  17692. var charCodeToGlyphId;
  17693. var glyphId;
  17694. if (properties.composite) {
  17695. charCodeToGlyphId = Object.create(null);
  17696. if (cff.isCIDFont) {
  17697. // If the font is actually a CID font then we should use the charset
  17698. // to map CIDs to GIDs.
  17699. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  17700. var cid = charsets[glyphId];
  17701. var charCode = properties.cMap.charCodeOf(cid);
  17702. charCodeToGlyphId[charCode] = glyphId;
  17703. }
  17704. } else {
  17705. // If it is NOT actually a CID font then CIDs should be mapped
  17706. // directly to GIDs.
  17707. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  17708. charCodeToGlyphId[glyphId] = glyphId;
  17709. }
  17710. }
  17711. return charCodeToGlyphId;
  17712. }
  17713. var encoding = cff.encoding ? cff.encoding.encoding : null;
  17714. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  17715. return charCodeToGlyphId;
  17716. }
  17717. };
  17718. return CFFFont;
  17719. })();
  17720. var CFFParser = (function CFFParserClosure() {
  17721. var CharstringValidationData = [
  17722. null,
  17723. { id: 'hstem', min: 2, resetStack: true, stem: true },
  17724. null,
  17725. { id: 'vstem', min: 2, resetStack: true, stem: true },
  17726. { id: 'vmoveto', min: 1, resetStack: true },
  17727. { id: 'rlineto', min: 2, resetStack: true },
  17728. { id: 'hlineto', min: 1, resetStack: true },
  17729. { id: 'vlineto', min: 1, resetStack: true },
  17730. { id: 'rrcurveto', min: 6, resetStack: true },
  17731. null,
  17732. { id: 'callsubr', min: 1, undefStack: true },
  17733. { id: 'return', min: 0, undefStack: true },
  17734. null, // 12
  17735. null,
  17736. null, // endchar
  17737. null,
  17738. null,
  17739. null,
  17740. { id: 'hstemhm', min: 2, resetStack: true, stem: true },
  17741. null, // hintmask
  17742. null, // cntrmask
  17743. { id: 'rmoveto', min: 2, resetStack: true },
  17744. { id: 'hmoveto', min: 1, resetStack: true },
  17745. { id: 'vstemhm', min: 2, resetStack: true, stem: true },
  17746. { id: 'rcurveline', min: 8, resetStack: true },
  17747. { id: 'rlinecurve', min: 8, resetStack: true },
  17748. { id: 'vvcurveto', min: 4, resetStack: true },
  17749. { id: 'hhcurveto', min: 4, resetStack: true },
  17750. null, // shortint
  17751. { id: 'callgsubr', min: 1, undefStack: true },
  17752. { id: 'vhcurveto', min: 4, resetStack: true },
  17753. { id: 'hvcurveto', min: 4, resetStack: true }
  17754. ];
  17755. var CharstringValidationData12 = [
  17756. null,
  17757. null,
  17758. null,
  17759. { id: 'and', min: 2, stackDelta: -1 },
  17760. { id: 'or', min: 2, stackDelta: -1 },
  17761. { id: 'not', min: 1, stackDelta: 0 },
  17762. null,
  17763. null,
  17764. null,
  17765. { id: 'abs', min: 1, stackDelta: 0 },
  17766. { id: 'add', min: 2, stackDelta: -1,
  17767. stackFn: function stack_div(stack, index) {
  17768. stack[index - 2] = stack[index - 2] + stack[index - 1];
  17769. }
  17770. },
  17771. { id: 'sub', min: 2, stackDelta: -1,
  17772. stackFn: function stack_div(stack, index) {
  17773. stack[index - 2] = stack[index - 2] - stack[index - 1];
  17774. }
  17775. },
  17776. { id: 'div', min: 2, stackDelta: -1,
  17777. stackFn: function stack_div(stack, index) {
  17778. stack[index - 2] = stack[index - 2] / stack[index - 1];
  17779. }
  17780. },
  17781. null,
  17782. { id: 'neg', min: 1, stackDelta: 0,
  17783. stackFn: function stack_div(stack, index) {
  17784. stack[index - 1] = -stack[index - 1];
  17785. }
  17786. },
  17787. { id: 'eq', min: 2, stackDelta: -1 },
  17788. null,
  17789. null,
  17790. { id: 'drop', min: 1, stackDelta: -1 },
  17791. null,
  17792. { id: 'put', min: 2, stackDelta: -2 },
  17793. { id: 'get', min: 1, stackDelta: 0 },
  17794. { id: 'ifelse', min: 4, stackDelta: -3 },
  17795. { id: 'random', min: 0, stackDelta: 1 },
  17796. { id: 'mul', min: 2, stackDelta: -1,
  17797. stackFn: function stack_div(stack, index) {
  17798. stack[index - 2] = stack[index - 2] * stack[index - 1];
  17799. }
  17800. },
  17801. null,
  17802. { id: 'sqrt', min: 1, stackDelta: 0 },
  17803. { id: 'dup', min: 1, stackDelta: 1 },
  17804. { id: 'exch', min: 2, stackDelta: 0 },
  17805. { id: 'index', min: 2, stackDelta: 0 },
  17806. { id: 'roll', min: 3, stackDelta: -2 },
  17807. null,
  17808. null,
  17809. null,
  17810. { id: 'hflex', min: 7, resetStack: true },
  17811. { id: 'flex', min: 13, resetStack: true },
  17812. { id: 'hflex1', min: 9, resetStack: true },
  17813. { id: 'flex1', min: 11, resetStack: true }
  17814. ];
  17815. function CFFParser(file, properties) {
  17816. this.bytes = file.getBytes();
  17817. this.properties = properties;
  17818. }
  17819. CFFParser.prototype = {
  17820. parse: function CFFParser_parse() {
  17821. var properties = this.properties;
  17822. var cff = new CFF();
  17823. this.cff = cff;
  17824. // The first five sections must be in order, all the others are reached
  17825. // via offsets contained in one of the below.
  17826. var header = this.parseHeader();
  17827. var nameIndex = this.parseIndex(header.endPos);
  17828. var topDictIndex = this.parseIndex(nameIndex.endPos);
  17829. var stringIndex = this.parseIndex(topDictIndex.endPos);
  17830. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  17831. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  17832. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  17833. cff.header = header.obj;
  17834. cff.names = this.parseNameIndex(nameIndex.obj);
  17835. cff.strings = this.parseStringIndex(stringIndex.obj);
  17836. cff.topDict = topDict;
  17837. cff.globalSubrIndex = globalSubrIndex.obj;
  17838. this.parsePrivateDict(cff.topDict);
  17839. cff.isCIDFont = topDict.hasName('ROS');
  17840. var charStringOffset = topDict.getByName('CharStrings');
  17841. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  17842. cff.charStrings = charStringsAndSeacs.charStrings;
  17843. cff.seacs = charStringsAndSeacs.seacs;
  17844. var fontMatrix = topDict.getByName('FontMatrix');
  17845. if (fontMatrix) {
  17846. properties.fontMatrix = fontMatrix;
  17847. }
  17848. var fontBBox = topDict.getByName('FontBBox');
  17849. if (fontBBox) {
  17850. // adjusting ascent/descent
  17851. properties.ascent = fontBBox[3];
  17852. properties.descent = fontBBox[1];
  17853. properties.ascentScaled = true;
  17854. }
  17855. var charset, encoding;
  17856. if (cff.isCIDFont) {
  17857. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  17858. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  17859. var dictRaw = fdArrayIndex.get(i);
  17860. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  17861. cff.strings);
  17862. this.parsePrivateDict(fontDict);
  17863. cff.fdArray.push(fontDict);
  17864. }
  17865. // cid fonts don't have an encoding
  17866. encoding = null;
  17867. charset = this.parseCharsets(topDict.getByName('charset'),
  17868. cff.charStrings.count, cff.strings, true);
  17869. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  17870. cff.charStrings.count);
  17871. } else {
  17872. charset = this.parseCharsets(topDict.getByName('charset'),
  17873. cff.charStrings.count, cff.strings, false);
  17874. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  17875. properties,
  17876. cff.strings, charset.charset);
  17877. }
  17878. cff.charset = charset;
  17879. cff.encoding = encoding;
  17880. return cff;
  17881. },
  17882. parseHeader: function CFFParser_parseHeader() {
  17883. var bytes = this.bytes;
  17884. var bytesLength = bytes.length;
  17885. var offset = 0;
  17886. // Prevent an infinite loop, by checking that the offset is within the
  17887. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  17888. while (offset < bytesLength && bytes[offset] !== 1) {
  17889. ++offset;
  17890. }
  17891. if (offset >= bytesLength) {
  17892. error('Invalid CFF header');
  17893. } else if (offset !== 0) {
  17894. info('cff data is shifted');
  17895. bytes = bytes.subarray(offset);
  17896. this.bytes = bytes;
  17897. }
  17898. var major = bytes[0];
  17899. var minor = bytes[1];
  17900. var hdrSize = bytes[2];
  17901. var offSize = bytes[3];
  17902. var header = new CFFHeader(major, minor, hdrSize, offSize);
  17903. return { obj: header, endPos: hdrSize };
  17904. },
  17905. parseDict: function CFFParser_parseDict(dict) {
  17906. var pos = 0;
  17907. function parseOperand() {
  17908. var value = dict[pos++];
  17909. if (value === 30) {
  17910. return parseFloatOperand(pos);
  17911. } else if (value === 28) {
  17912. value = dict[pos++];
  17913. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  17914. return value;
  17915. } else if (value === 29) {
  17916. value = dict[pos++];
  17917. value = (value << 8) | dict[pos++];
  17918. value = (value << 8) | dict[pos++];
  17919. value = (value << 8) | dict[pos++];
  17920. return value;
  17921. } else if (value >= 32 && value <= 246) {
  17922. return value - 139;
  17923. } else if (value >= 247 && value <= 250) {
  17924. return ((value - 247) * 256) + dict[pos++] + 108;
  17925. } else if (value >= 251 && value <= 254) {
  17926. return -((value - 251) * 256) - dict[pos++] - 108;
  17927. } else {
  17928. error('255 is not a valid DICT command');
  17929. }
  17930. return -1;
  17931. }
  17932. function parseFloatOperand() {
  17933. var str = '';
  17934. var eof = 15;
  17935. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  17936. '9', '.', 'E', 'E-', null, '-'];
  17937. var length = dict.length;
  17938. while (pos < length) {
  17939. var b = dict[pos++];
  17940. var b1 = b >> 4;
  17941. var b2 = b & 15;
  17942. if (b1 === eof) {
  17943. break;
  17944. }
  17945. str += lookup[b1];
  17946. if (b2 === eof) {
  17947. break;
  17948. }
  17949. str += lookup[b2];
  17950. }
  17951. return parseFloat(str);
  17952. }
  17953. var operands = [];
  17954. var entries = [];
  17955. pos = 0;
  17956. var end = dict.length;
  17957. while (pos < end) {
  17958. var b = dict[pos];
  17959. if (b <= 21) {
  17960. if (b === 12) {
  17961. b = (b << 8) | dict[++pos];
  17962. }
  17963. entries.push([b, operands]);
  17964. operands = [];
  17965. ++pos;
  17966. } else {
  17967. operands.push(parseOperand());
  17968. }
  17969. }
  17970. return entries;
  17971. },
  17972. parseIndex: function CFFParser_parseIndex(pos) {
  17973. var cffIndex = new CFFIndex();
  17974. var bytes = this.bytes;
  17975. var count = (bytes[pos++] << 8) | bytes[pos++];
  17976. var offsets = [];
  17977. var end = pos;
  17978. var i, ii;
  17979. if (count !== 0) {
  17980. var offsetSize = bytes[pos++];
  17981. // add 1 for offset to determine size of last object
  17982. var startPos = pos + ((count + 1) * offsetSize) - 1;
  17983. for (i = 0, ii = count + 1; i < ii; ++i) {
  17984. var offset = 0;
  17985. for (var j = 0; j < offsetSize; ++j) {
  17986. offset <<= 8;
  17987. offset += bytes[pos++];
  17988. }
  17989. offsets.push(startPos + offset);
  17990. }
  17991. end = offsets[count];
  17992. }
  17993. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  17994. var offsetStart = offsets[i];
  17995. var offsetEnd = offsets[i + 1];
  17996. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  17997. }
  17998. return {obj: cffIndex, endPos: end};
  17999. },
  18000. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18001. var names = [];
  18002. for (var i = 0, ii = index.count; i < ii; ++i) {
  18003. var name = index.get(i);
  18004. // OTS doesn't allow names to be over 127 characters.
  18005. var length = Math.min(name.length, 127);
  18006. var data = [];
  18007. // OTS also only permits certain characters in the name.
  18008. for (var j = 0; j < length; ++j) {
  18009. var c = name[j];
  18010. if (j === 0 && c === 0) {
  18011. data[j] = c;
  18012. continue;
  18013. }
  18014. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18015. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18016. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18017. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18018. data[j] = 95;
  18019. continue;
  18020. }
  18021. data[j] = c;
  18022. }
  18023. names.push(bytesToString(data));
  18024. }
  18025. return names;
  18026. },
  18027. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18028. var strings = new CFFStrings();
  18029. for (var i = 0, ii = index.count; i < ii; ++i) {
  18030. var data = index.get(i);
  18031. strings.add(bytesToString(data));
  18032. }
  18033. return strings;
  18034. },
  18035. createDict: function CFFParser_createDict(Type, dict, strings) {
  18036. var cffDict = new Type(strings);
  18037. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18038. var pair = dict[i];
  18039. var key = pair[0];
  18040. var value = pair[1];
  18041. cffDict.setByKey(key, value);
  18042. }
  18043. return cffDict;
  18044. },
  18045. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18046. var charStrings = this.parseIndex(charStringOffset).obj;
  18047. var seacs = [];
  18048. var count = charStrings.count;
  18049. for (var i = 0; i < count; i++) {
  18050. var charstring = charStrings.get(i);
  18051. var stackSize = 0;
  18052. var stack = [];
  18053. var undefStack = true;
  18054. var hints = 0;
  18055. var valid = true;
  18056. var data = charstring;
  18057. var length = data.length;
  18058. for (var j = 0; j < length;) {
  18059. var value = data[j++];
  18060. var validationCommand = null;
  18061. if (value === 12) {
  18062. var q = data[j++];
  18063. if (q === 0) {
  18064. // The CFF specification state that the 'dotsection' command
  18065. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18066. // charstrings processors should support them. Unfortunately
  18067. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18068. // is replaced by a useless (0, hmoveto).
  18069. data[j - 2] = 139;
  18070. data[j - 1] = 22;
  18071. stackSize = 0;
  18072. } else {
  18073. validationCommand = CharstringValidationData12[q];
  18074. }
  18075. } else if (value === 28) { // number (16 bit)
  18076. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18077. j += 2;
  18078. stackSize++;
  18079. } else if (value === 14) {
  18080. if (stackSize >= 4) {
  18081. stackSize -= 4;
  18082. if (SEAC_ANALYSIS_ENABLED) {
  18083. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18084. valid = false;
  18085. }
  18086. }
  18087. } else if (value >= 32 && value <= 246) { // number
  18088. stack[stackSize] = value - 139;
  18089. stackSize++;
  18090. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18091. stack[stackSize] = (value < 251 ?
  18092. ((value - 247) << 8) + data[j] + 108 :
  18093. -((value - 251) << 8) - data[j] - 108);
  18094. j++;
  18095. stackSize++;
  18096. } else if (value === 255) { // number (32 bit)
  18097. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18098. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18099. j += 4;
  18100. stackSize++;
  18101. } else if (value === 19 || value === 20) {
  18102. hints += stackSize >> 1;
  18103. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18104. stackSize = 0;
  18105. } else {
  18106. validationCommand = CharstringValidationData[value];
  18107. }
  18108. if (validationCommand) {
  18109. if (validationCommand.stem) {
  18110. hints += stackSize >> 1;
  18111. }
  18112. if ('min' in validationCommand) {
  18113. if (!undefStack && stackSize < validationCommand.min) {
  18114. warn('Not enough parameters for ' + validationCommand.id +
  18115. '; actual: ' + stackSize +
  18116. ', expected: ' + validationCommand.min);
  18117. valid = false;
  18118. break;
  18119. }
  18120. }
  18121. if ('stackDelta' in validationCommand) {
  18122. if ('stackFn' in validationCommand) {
  18123. validationCommand.stackFn(stack, stackSize);
  18124. }
  18125. stackSize += validationCommand.stackDelta;
  18126. } else if (validationCommand.resetStack) {
  18127. stackSize = 0;
  18128. undefStack = false;
  18129. } else if (validationCommand.undefStack) {
  18130. stackSize = 0;
  18131. undefStack = true;
  18132. }
  18133. }
  18134. }
  18135. if (!valid) {
  18136. // resetting invalid charstring to single 'endchar'
  18137. charStrings.set(i, new Uint8Array([14]));
  18138. }
  18139. }
  18140. return { charStrings: charStrings, seacs: seacs };
  18141. },
  18142. emptyPrivateDictionary:
  18143. function CFFParser_emptyPrivateDictionary(parentDict) {
  18144. var privateDict = this.createDict(CFFPrivateDict, [],
  18145. parentDict.strings);
  18146. parentDict.setByKey(18, [0, 0]);
  18147. parentDict.privateDict = privateDict;
  18148. },
  18149. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18150. // no private dict, do nothing
  18151. if (!parentDict.hasName('Private')) {
  18152. this.emptyPrivateDictionary(parentDict);
  18153. return;
  18154. }
  18155. var privateOffset = parentDict.getByName('Private');
  18156. // make sure the params are formatted correctly
  18157. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18158. parentDict.removeByName('Private');
  18159. return;
  18160. }
  18161. var size = privateOffset[0];
  18162. var offset = privateOffset[1];
  18163. // remove empty dicts or ones that refer to invalid location
  18164. if (size === 0 || offset >= this.bytes.length) {
  18165. this.emptyPrivateDictionary(parentDict);
  18166. return;
  18167. }
  18168. var privateDictEnd = offset + size;
  18169. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18170. var dict = this.parseDict(dictData);
  18171. var privateDict = this.createDict(CFFPrivateDict, dict,
  18172. parentDict.strings);
  18173. parentDict.privateDict = privateDict;
  18174. // Parse the Subrs index also since it's relative to the private dict.
  18175. if (!privateDict.getByName('Subrs')) {
  18176. return;
  18177. }
  18178. var subrsOffset = privateDict.getByName('Subrs');
  18179. var relativeOffset = offset + subrsOffset;
  18180. // Validate the offset.
  18181. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18182. this.emptyPrivateDictionary(parentDict);
  18183. return;
  18184. }
  18185. var subrsIndex = this.parseIndex(relativeOffset);
  18186. privateDict.subrsIndex = subrsIndex.obj;
  18187. },
  18188. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18189. if (pos === 0) {
  18190. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18191. ISOAdobeCharset);
  18192. } else if (pos === 1) {
  18193. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18194. ExpertCharset);
  18195. } else if (pos === 2) {
  18196. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18197. ExpertSubsetCharset);
  18198. }
  18199. var bytes = this.bytes;
  18200. var start = pos;
  18201. var format = bytes[pos++];
  18202. var charset = ['.notdef'];
  18203. var id, count, i;
  18204. // subtract 1 for the .notdef glyph
  18205. length -= 1;
  18206. switch (format) {
  18207. case 0:
  18208. for (i = 0; i < length; i++) {
  18209. id = (bytes[pos++] << 8) | bytes[pos++];
  18210. charset.push(cid ? id : strings.get(id));
  18211. }
  18212. break;
  18213. case 1:
  18214. while (charset.length <= length) {
  18215. id = (bytes[pos++] << 8) | bytes[pos++];
  18216. count = bytes[pos++];
  18217. for (i = 0; i <= count; i++) {
  18218. charset.push(cid ? id++ : strings.get(id++));
  18219. }
  18220. }
  18221. break;
  18222. case 2:
  18223. while (charset.length <= length) {
  18224. id = (bytes[pos++] << 8) | bytes[pos++];
  18225. count = (bytes[pos++] << 8) | bytes[pos++];
  18226. for (i = 0; i <= count; i++) {
  18227. charset.push(cid ? id++ : strings.get(id++));
  18228. }
  18229. }
  18230. break;
  18231. default:
  18232. error('Unknown charset format');
  18233. }
  18234. // Raw won't be needed if we actually compile the charset.
  18235. var end = pos;
  18236. var raw = bytes.subarray(start, end);
  18237. return new CFFCharset(false, format, charset, raw);
  18238. },
  18239. parseEncoding: function CFFParser_parseEncoding(pos,
  18240. properties,
  18241. strings,
  18242. charset) {
  18243. var encoding = {};
  18244. var bytes = this.bytes;
  18245. var predefined = false;
  18246. var hasSupplement = false;
  18247. var format, i, ii;
  18248. var raw = null;
  18249. function readSupplement() {
  18250. var supplementsCount = bytes[pos++];
  18251. for (i = 0; i < supplementsCount; i++) {
  18252. var code = bytes[pos++];
  18253. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18254. encoding[code] = charset.indexOf(strings.get(sid));
  18255. }
  18256. }
  18257. if (pos === 0 || pos === 1) {
  18258. predefined = true;
  18259. format = pos;
  18260. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18261. Encodings.StandardEncoding;
  18262. for (i = 0, ii = charset.length; i < ii; i++) {
  18263. var index = baseEncoding.indexOf(charset[i]);
  18264. if (index !== -1) {
  18265. encoding[index] = i;
  18266. }
  18267. }
  18268. } else {
  18269. var dataStart = pos;
  18270. format = bytes[pos++];
  18271. switch (format & 0x7f) {
  18272. case 0:
  18273. var glyphsCount = bytes[pos++];
  18274. for (i = 1; i <= glyphsCount; i++) {
  18275. encoding[bytes[pos++]] = i;
  18276. }
  18277. break;
  18278. case 1:
  18279. var rangesCount = bytes[pos++];
  18280. var gid = 1;
  18281. for (i = 0; i < rangesCount; i++) {
  18282. var start = bytes[pos++];
  18283. var left = bytes[pos++];
  18284. for (var j = start; j <= start + left; j++) {
  18285. encoding[j] = gid++;
  18286. }
  18287. }
  18288. break;
  18289. default:
  18290. error('Unknow encoding format: ' + format + ' in CFF');
  18291. break;
  18292. }
  18293. var dataEnd = pos;
  18294. if (format & 0x80) {
  18295. // The font sanitizer does not support CFF encoding with a
  18296. // supplement, since the encoding is not really used to map
  18297. // between gid to glyph, let's overwrite what is declared in
  18298. // the top dictionary to let the sanitizer think the font use
  18299. // StandardEncoding, that's a lie but that's ok.
  18300. bytes[dataStart] &= 0x7f;
  18301. readSupplement();
  18302. hasSupplement = true;
  18303. }
  18304. raw = bytes.subarray(dataStart, dataEnd);
  18305. }
  18306. format = format & 0x7f;
  18307. return new CFFEncoding(predefined, format, encoding, raw);
  18308. },
  18309. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18310. var start = pos;
  18311. var bytes = this.bytes;
  18312. var format = bytes[pos++];
  18313. var fdSelect = [];
  18314. var i;
  18315. switch (format) {
  18316. case 0:
  18317. for (i = 0; i < length; ++i) {
  18318. var id = bytes[pos++];
  18319. fdSelect.push(id);
  18320. }
  18321. break;
  18322. case 3:
  18323. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18324. for (i = 0; i < rangesCount; ++i) {
  18325. var first = (bytes[pos++] << 8) | bytes[pos++];
  18326. var fdIndex = bytes[pos++];
  18327. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18328. for (var j = first; j < next; ++j) {
  18329. fdSelect.push(fdIndex);
  18330. }
  18331. }
  18332. // Advance past the sentinel(next).
  18333. pos += 2;
  18334. break;
  18335. default:
  18336. error('Unknown fdselect format ' + format);
  18337. break;
  18338. }
  18339. var end = pos;
  18340. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18341. }
  18342. };
  18343. return CFFParser;
  18344. })();
  18345. // Compact Font Format
  18346. var CFF = (function CFFClosure() {
  18347. function CFF() {
  18348. this.header = null;
  18349. this.names = [];
  18350. this.topDict = null;
  18351. this.strings = new CFFStrings();
  18352. this.globalSubrIndex = null;
  18353. // The following could really be per font, but since we only have one font
  18354. // store them here.
  18355. this.encoding = null;
  18356. this.charset = null;
  18357. this.charStrings = null;
  18358. this.fdArray = [];
  18359. this.fdSelect = null;
  18360. this.isCIDFont = false;
  18361. }
  18362. return CFF;
  18363. })();
  18364. var CFFHeader = (function CFFHeaderClosure() {
  18365. function CFFHeader(major, minor, hdrSize, offSize) {
  18366. this.major = major;
  18367. this.minor = minor;
  18368. this.hdrSize = hdrSize;
  18369. this.offSize = offSize;
  18370. }
  18371. return CFFHeader;
  18372. })();
  18373. var CFFStrings = (function CFFStringsClosure() {
  18374. function CFFStrings() {
  18375. this.strings = [];
  18376. }
  18377. CFFStrings.prototype = {
  18378. get: function CFFStrings_get(index) {
  18379. if (index >= 0 && index <= 390) {
  18380. return CFFStandardStrings[index];
  18381. }
  18382. if (index - 391 <= this.strings.length) {
  18383. return this.strings[index - 391];
  18384. }
  18385. return CFFStandardStrings[0];
  18386. },
  18387. add: function CFFStrings_add(value) {
  18388. this.strings.push(value);
  18389. },
  18390. get count() {
  18391. return this.strings.length;
  18392. }
  18393. };
  18394. return CFFStrings;
  18395. })();
  18396. var CFFIndex = (function CFFIndexClosure() {
  18397. function CFFIndex() {
  18398. this.objects = [];
  18399. this.length = 0;
  18400. }
  18401. CFFIndex.prototype = {
  18402. add: function CFFIndex_add(data) {
  18403. this.length += data.length;
  18404. this.objects.push(data);
  18405. },
  18406. set: function CFFIndex_set(index, data) {
  18407. this.length += data.length - this.objects[index].length;
  18408. this.objects[index] = data;
  18409. },
  18410. get: function CFFIndex_get(index) {
  18411. return this.objects[index];
  18412. },
  18413. get count() {
  18414. return this.objects.length;
  18415. }
  18416. };
  18417. return CFFIndex;
  18418. })();
  18419. var CFFDict = (function CFFDictClosure() {
  18420. function CFFDict(tables, strings) {
  18421. this.keyToNameMap = tables.keyToNameMap;
  18422. this.nameToKeyMap = tables.nameToKeyMap;
  18423. this.defaults = tables.defaults;
  18424. this.types = tables.types;
  18425. this.opcodes = tables.opcodes;
  18426. this.order = tables.order;
  18427. this.strings = strings;
  18428. this.values = {};
  18429. }
  18430. CFFDict.prototype = {
  18431. // value should always be an array
  18432. setByKey: function CFFDict_setByKey(key, value) {
  18433. if (!(key in this.keyToNameMap)) {
  18434. return false;
  18435. }
  18436. // ignore empty values
  18437. if (value.length === 0) {
  18438. return true;
  18439. }
  18440. var type = this.types[key];
  18441. // remove the array wrapping these types of values
  18442. if (type === 'num' || type === 'sid' || type === 'offset') {
  18443. value = value[0];
  18444. }
  18445. this.values[key] = value;
  18446. return true;
  18447. },
  18448. setByName: function CFFDict_setByName(name, value) {
  18449. if (!(name in this.nameToKeyMap)) {
  18450. error('Invalid dictionary name "' + name + '"');
  18451. }
  18452. this.values[this.nameToKeyMap[name]] = value;
  18453. },
  18454. hasName: function CFFDict_hasName(name) {
  18455. return this.nameToKeyMap[name] in this.values;
  18456. },
  18457. getByName: function CFFDict_getByName(name) {
  18458. if (!(name in this.nameToKeyMap)) {
  18459. error('Invalid dictionary name "' + name + '"');
  18460. }
  18461. var key = this.nameToKeyMap[name];
  18462. if (!(key in this.values)) {
  18463. return this.defaults[key];
  18464. }
  18465. return this.values[key];
  18466. },
  18467. removeByName: function CFFDict_removeByName(name) {
  18468. delete this.values[this.nameToKeyMap[name]];
  18469. }
  18470. };
  18471. CFFDict.createTables = function CFFDict_createTables(layout) {
  18472. var tables = {
  18473. keyToNameMap: {},
  18474. nameToKeyMap: {},
  18475. defaults: {},
  18476. types: {},
  18477. opcodes: {},
  18478. order: []
  18479. };
  18480. for (var i = 0, ii = layout.length; i < ii; ++i) {
  18481. var entry = layout[i];
  18482. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  18483. tables.keyToNameMap[key] = entry[1];
  18484. tables.nameToKeyMap[entry[1]] = key;
  18485. tables.types[key] = entry[2];
  18486. tables.defaults[key] = entry[3];
  18487. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  18488. tables.order.push(key);
  18489. }
  18490. return tables;
  18491. };
  18492. return CFFDict;
  18493. })();
  18494. var CFFTopDict = (function CFFTopDictClosure() {
  18495. var layout = [
  18496. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  18497. [[12, 20], 'SyntheticBase', 'num', null],
  18498. [0, 'version', 'sid', null],
  18499. [1, 'Notice', 'sid', null],
  18500. [[12, 0], 'Copyright', 'sid', null],
  18501. [2, 'FullName', 'sid', null],
  18502. [3, 'FamilyName', 'sid', null],
  18503. [4, 'Weight', 'sid', null],
  18504. [[12, 1], 'isFixedPitch', 'num', 0],
  18505. [[12, 2], 'ItalicAngle', 'num', 0],
  18506. [[12, 3], 'UnderlinePosition', 'num', -100],
  18507. [[12, 4], 'UnderlineThickness', 'num', 50],
  18508. [[12, 5], 'PaintType', 'num', 0],
  18509. [[12, 6], 'CharstringType', 'num', 2],
  18510. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  18511. [0.001, 0, 0, 0.001, 0, 0]],
  18512. [13, 'UniqueID', 'num', null],
  18513. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  18514. [[12, 8], 'StrokeWidth', 'num', 0],
  18515. [14, 'XUID', 'array', null],
  18516. [15, 'charset', 'offset', 0],
  18517. [16, 'Encoding', 'offset', 0],
  18518. [17, 'CharStrings', 'offset', 0],
  18519. [18, 'Private', ['offset', 'offset'], null],
  18520. [[12, 21], 'PostScript', 'sid', null],
  18521. [[12, 22], 'BaseFontName', 'sid', null],
  18522. [[12, 23], 'BaseFontBlend', 'delta', null],
  18523. [[12, 31], 'CIDFontVersion', 'num', 0],
  18524. [[12, 32], 'CIDFontRevision', 'num', 0],
  18525. [[12, 33], 'CIDFontType', 'num', 0],
  18526. [[12, 34], 'CIDCount', 'num', 8720],
  18527. [[12, 35], 'UIDBase', 'num', null],
  18528. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  18529. // before FDArray.
  18530. [[12, 37], 'FDSelect', 'offset', null],
  18531. [[12, 36], 'FDArray', 'offset', null],
  18532. [[12, 38], 'FontName', 'sid', null]
  18533. ];
  18534. var tables = null;
  18535. function CFFTopDict(strings) {
  18536. if (tables === null) {
  18537. tables = CFFDict.createTables(layout);
  18538. }
  18539. CFFDict.call(this, tables, strings);
  18540. this.privateDict = null;
  18541. }
  18542. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  18543. return CFFTopDict;
  18544. })();
  18545. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  18546. var layout = [
  18547. [6, 'BlueValues', 'delta', null],
  18548. [7, 'OtherBlues', 'delta', null],
  18549. [8, 'FamilyBlues', 'delta', null],
  18550. [9, 'FamilyOtherBlues', 'delta', null],
  18551. [[12, 9], 'BlueScale', 'num', 0.039625],
  18552. [[12, 10], 'BlueShift', 'num', 7],
  18553. [[12, 11], 'BlueFuzz', 'num', 1],
  18554. [10, 'StdHW', 'num', null],
  18555. [11, 'StdVW', 'num', null],
  18556. [[12, 12], 'StemSnapH', 'delta', null],
  18557. [[12, 13], 'StemSnapV', 'delta', null],
  18558. [[12, 14], 'ForceBold', 'num', 0],
  18559. [[12, 17], 'LanguageGroup', 'num', 0],
  18560. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  18561. [[12, 19], 'initialRandomSeed', 'num', 0],
  18562. [20, 'defaultWidthX', 'num', 0],
  18563. [21, 'nominalWidthX', 'num', 0],
  18564. [19, 'Subrs', 'offset', null]
  18565. ];
  18566. var tables = null;
  18567. function CFFPrivateDict(strings) {
  18568. if (tables === null) {
  18569. tables = CFFDict.createTables(layout);
  18570. }
  18571. CFFDict.call(this, tables, strings);
  18572. this.subrsIndex = null;
  18573. }
  18574. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  18575. return CFFPrivateDict;
  18576. })();
  18577. var CFFCharsetPredefinedTypes = {
  18578. ISO_ADOBE: 0,
  18579. EXPERT: 1,
  18580. EXPERT_SUBSET: 2
  18581. };
  18582. var CFFCharset = (function CFFCharsetClosure() {
  18583. function CFFCharset(predefined, format, charset, raw) {
  18584. this.predefined = predefined;
  18585. this.format = format;
  18586. this.charset = charset;
  18587. this.raw = raw;
  18588. }
  18589. return CFFCharset;
  18590. })();
  18591. var CFFEncoding = (function CFFEncodingClosure() {
  18592. function CFFEncoding(predefined, format, encoding, raw) {
  18593. this.predefined = predefined;
  18594. this.format = format;
  18595. this.encoding = encoding;
  18596. this.raw = raw;
  18597. }
  18598. return CFFEncoding;
  18599. })();
  18600. var CFFFDSelect = (function CFFFDSelectClosure() {
  18601. function CFFFDSelect(fdSelect, raw) {
  18602. this.fdSelect = fdSelect;
  18603. this.raw = raw;
  18604. }
  18605. return CFFFDSelect;
  18606. })();
  18607. // Helper class to keep track of where an offset is within the data and helps
  18608. // filling in that offset once it's known.
  18609. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  18610. function CFFOffsetTracker() {
  18611. this.offsets = {};
  18612. }
  18613. CFFOffsetTracker.prototype = {
  18614. isTracking: function CFFOffsetTracker_isTracking(key) {
  18615. return key in this.offsets;
  18616. },
  18617. track: function CFFOffsetTracker_track(key, location) {
  18618. if (key in this.offsets) {
  18619. error('Already tracking location of ' + key);
  18620. }
  18621. this.offsets[key] = location;
  18622. },
  18623. offset: function CFFOffsetTracker_offset(value) {
  18624. for (var key in this.offsets) {
  18625. this.offsets[key] += value;
  18626. }
  18627. },
  18628. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  18629. values,
  18630. output) {
  18631. if (!(key in this.offsets)) {
  18632. error('Not tracking location of ' + key);
  18633. }
  18634. var data = output.data;
  18635. var dataOffset = this.offsets[key];
  18636. var size = 5;
  18637. for (var i = 0, ii = values.length; i < ii; ++i) {
  18638. var offset0 = i * size + dataOffset;
  18639. var offset1 = offset0 + 1;
  18640. var offset2 = offset0 + 2;
  18641. var offset3 = offset0 + 3;
  18642. var offset4 = offset0 + 4;
  18643. // It's easy to screw up offsets so perform this sanity check.
  18644. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  18645. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  18646. error('writing to an offset that is not empty');
  18647. }
  18648. var value = values[i];
  18649. data[offset0] = 0x1d;
  18650. data[offset1] = (value >> 24) & 0xFF;
  18651. data[offset2] = (value >> 16) & 0xFF;
  18652. data[offset3] = (value >> 8) & 0xFF;
  18653. data[offset4] = value & 0xFF;
  18654. }
  18655. }
  18656. };
  18657. return CFFOffsetTracker;
  18658. })();
  18659. // Takes a CFF and converts it to the binary representation.
  18660. var CFFCompiler = (function CFFCompilerClosure() {
  18661. function CFFCompiler(cff) {
  18662. this.cff = cff;
  18663. }
  18664. CFFCompiler.prototype = {
  18665. compile: function CFFCompiler_compile() {
  18666. var cff = this.cff;
  18667. var output = {
  18668. data: [],
  18669. length: 0,
  18670. add: function CFFCompiler_add(data) {
  18671. this.data = this.data.concat(data);
  18672. this.length = this.data.length;
  18673. }
  18674. };
  18675. // Compile the five entries that must be in order.
  18676. var header = this.compileHeader(cff.header);
  18677. output.add(header);
  18678. var nameIndex = this.compileNameIndex(cff.names);
  18679. output.add(nameIndex);
  18680. if (cff.isCIDFont) {
  18681. // The spec is unclear on how font matrices should relate to each other
  18682. // when there is one in the main top dict and the sub top dicts.
  18683. // Windows handles this differently than linux and osx so we have to
  18684. // normalize to work on all.
  18685. // Rules based off of some mailing list discussions:
  18686. // - If main font has a matrix and subfont doesn't, use the main matrix.
  18687. // - If no main font matrix and there is a subfont matrix, use the
  18688. // subfont matrix.
  18689. // - If both have matrices, concat together.
  18690. // - If neither have matrices, use default.
  18691. // To make this work on all platforms we move the top matrix into each
  18692. // sub top dict and concat if necessary.
  18693. if (cff.topDict.hasName('FontMatrix')) {
  18694. var base = cff.topDict.getByName('FontMatrix');
  18695. cff.topDict.removeByName('FontMatrix');
  18696. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  18697. var subDict = cff.fdArray[i];
  18698. var matrix = base.slice(0);
  18699. if (subDict.hasName('FontMatrix')) {
  18700. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  18701. }
  18702. subDict.setByName('FontMatrix', matrix);
  18703. }
  18704. }
  18705. }
  18706. var compiled = this.compileTopDicts([cff.topDict],
  18707. output.length,
  18708. cff.isCIDFont);
  18709. output.add(compiled.output);
  18710. var topDictTracker = compiled.trackers[0];
  18711. var stringIndex = this.compileStringIndex(cff.strings.strings);
  18712. output.add(stringIndex);
  18713. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  18714. output.add(globalSubrIndex);
  18715. // Now start on the other entries that have no specfic order.
  18716. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  18717. if (cff.encoding.predefined) {
  18718. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  18719. output);
  18720. } else {
  18721. var encoding = this.compileEncoding(cff.encoding);
  18722. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  18723. output.add(encoding);
  18724. }
  18725. }
  18726. if (cff.charset && cff.topDict.hasName('charset')) {
  18727. if (cff.charset.predefined) {
  18728. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  18729. output);
  18730. } else {
  18731. var charset = this.compileCharset(cff.charset);
  18732. topDictTracker.setEntryLocation('charset', [output.length], output);
  18733. output.add(charset);
  18734. }
  18735. }
  18736. var charStrings = this.compileCharStrings(cff.charStrings);
  18737. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  18738. output.add(charStrings);
  18739. if (cff.isCIDFont) {
  18740. // For some reason FDSelect must be in front of FDArray on windows. OSX
  18741. // and linux don't seem to care.
  18742. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  18743. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  18744. output.add(fdSelect);
  18745. // It is unclear if the sub font dictionary can have CID related
  18746. // dictionary keys, but the sanitizer doesn't like them so remove them.
  18747. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  18748. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  18749. output.add(compiled.output);
  18750. var fontDictTrackers = compiled.trackers;
  18751. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  18752. }
  18753. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  18754. // If the font data ends with INDEX whose object data is zero-length,
  18755. // the sanitizer will bail out. Add a dummy byte to avoid that.
  18756. output.add([0]);
  18757. return output.data;
  18758. },
  18759. encodeNumber: function CFFCompiler_encodeNumber(value) {
  18760. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  18761. return this.encodeInteger(value);
  18762. } else {
  18763. return this.encodeFloat(value);
  18764. }
  18765. },
  18766. encodeFloat: function CFFCompiler_encodeFloat(num) {
  18767. var value = num.toString();
  18768. // rounding inaccurate doubles
  18769. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  18770. if (m) {
  18771. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  18772. value = (Math.round(num * epsilon) / epsilon).toString();
  18773. }
  18774. var nibbles = '';
  18775. var i, ii;
  18776. for (i = 0, ii = value.length; i < ii; ++i) {
  18777. var a = value[i];
  18778. if (a === 'e') {
  18779. nibbles += value[++i] === '-' ? 'c' : 'b';
  18780. } else if (a === '.') {
  18781. nibbles += 'a';
  18782. } else if (a === '-') {
  18783. nibbles += 'e';
  18784. } else {
  18785. nibbles += a;
  18786. }
  18787. }
  18788. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  18789. var out = [30];
  18790. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  18791. out.push(parseInt(nibbles.substr(i, 2), 16));
  18792. }
  18793. return out;
  18794. },
  18795. encodeInteger: function CFFCompiler_encodeInteger(value) {
  18796. var code;
  18797. if (value >= -107 && value <= 107) {
  18798. code = [value + 139];
  18799. } else if (value >= 108 && value <= 1131) {
  18800. value = [value - 108];
  18801. code = [(value >> 8) + 247, value & 0xFF];
  18802. } else if (value >= -1131 && value <= -108) {
  18803. value = -value - 108;
  18804. code = [(value >> 8) + 251, value & 0xFF];
  18805. } else if (value >= -32768 && value <= 32767) {
  18806. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  18807. } else {
  18808. code = [0x1d,
  18809. (value >> 24) & 0xFF,
  18810. (value >> 16) & 0xFF,
  18811. (value >> 8) & 0xFF,
  18812. value & 0xFF];
  18813. }
  18814. return code;
  18815. },
  18816. compileHeader: function CFFCompiler_compileHeader(header) {
  18817. return [
  18818. header.major,
  18819. header.minor,
  18820. header.hdrSize,
  18821. header.offSize
  18822. ];
  18823. },
  18824. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  18825. var nameIndex = new CFFIndex();
  18826. for (var i = 0, ii = names.length; i < ii; ++i) {
  18827. nameIndex.add(stringToBytes(names[i]));
  18828. }
  18829. return this.compileIndex(nameIndex);
  18830. },
  18831. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  18832. length,
  18833. removeCidKeys) {
  18834. var fontDictTrackers = [];
  18835. var fdArrayIndex = new CFFIndex();
  18836. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  18837. var fontDict = dicts[i];
  18838. if (removeCidKeys) {
  18839. fontDict.removeByName('CIDFontVersion');
  18840. fontDict.removeByName('CIDFontRevision');
  18841. fontDict.removeByName('CIDFontType');
  18842. fontDict.removeByName('CIDCount');
  18843. fontDict.removeByName('UIDBase');
  18844. }
  18845. var fontDictTracker = new CFFOffsetTracker();
  18846. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  18847. fontDictTrackers.push(fontDictTracker);
  18848. fdArrayIndex.add(fontDictData);
  18849. fontDictTracker.offset(length);
  18850. }
  18851. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  18852. return {
  18853. trackers: fontDictTrackers,
  18854. output: fdArrayIndex
  18855. };
  18856. },
  18857. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  18858. trackers,
  18859. output) {
  18860. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  18861. var fontDict = dicts[i];
  18862. assert(fontDict.privateDict && fontDict.hasName('Private'),
  18863. 'There must be an private dictionary.');
  18864. var privateDict = fontDict.privateDict;
  18865. var privateDictTracker = new CFFOffsetTracker();
  18866. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  18867. var outputLength = output.length;
  18868. privateDictTracker.offset(outputLength);
  18869. if (!privateDictData.length) {
  18870. // The private dictionary was empty, set the output length to zero to
  18871. // ensure the offset length isn't out of bounds in the eyes of the
  18872. // sanitizer.
  18873. outputLength = 0;
  18874. }
  18875. trackers[i].setEntryLocation('Private',
  18876. [privateDictData.length, outputLength],
  18877. output);
  18878. output.add(privateDictData);
  18879. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  18880. var subrs = this.compileIndex(privateDict.subrsIndex);
  18881. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  18882. output);
  18883. output.add(subrs);
  18884. }
  18885. }
  18886. },
  18887. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  18888. var out = [];
  18889. // The dictionary keys must be in a certain order.
  18890. var order = dict.order;
  18891. for (var i = 0; i < order.length; ++i) {
  18892. var key = order[i];
  18893. if (!(key in dict.values)) {
  18894. continue;
  18895. }
  18896. var values = dict.values[key];
  18897. var types = dict.types[key];
  18898. if (!isArray(types)) {
  18899. types = [types];
  18900. }
  18901. if (!isArray(values)) {
  18902. values = [values];
  18903. }
  18904. // Remove any empty dict values.
  18905. if (values.length === 0) {
  18906. continue;
  18907. }
  18908. for (var j = 0, jj = types.length; j < jj; ++j) {
  18909. var type = types[j];
  18910. var value = values[j];
  18911. switch (type) {
  18912. case 'num':
  18913. case 'sid':
  18914. out = out.concat(this.encodeNumber(value));
  18915. break;
  18916. case 'offset':
  18917. // For offsets we just insert a 32bit integer so we don't have to
  18918. // deal with figuring out the length of the offset when it gets
  18919. // replaced later on by the compiler.
  18920. var name = dict.keyToNameMap[key];
  18921. // Some offsets have the offset and the length, so just record the
  18922. // position of the first one.
  18923. if (!offsetTracker.isTracking(name)) {
  18924. offsetTracker.track(name, out.length);
  18925. }
  18926. out = out.concat([0x1d, 0, 0, 0, 0]);
  18927. break;
  18928. case 'array':
  18929. case 'delta':
  18930. out = out.concat(this.encodeNumber(value));
  18931. for (var k = 1, kk = values.length; k < kk; ++k) {
  18932. out = out.concat(this.encodeNumber(values[k]));
  18933. }
  18934. break;
  18935. default:
  18936. error('Unknown data type of ' + type);
  18937. break;
  18938. }
  18939. }
  18940. out = out.concat(dict.opcodes[key]);
  18941. }
  18942. return out;
  18943. },
  18944. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  18945. var stringIndex = new CFFIndex();
  18946. for (var i = 0, ii = strings.length; i < ii; ++i) {
  18947. stringIndex.add(stringToBytes(strings[i]));
  18948. }
  18949. return this.compileIndex(stringIndex);
  18950. },
  18951. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  18952. var globalSubrIndex = this.cff.globalSubrIndex;
  18953. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  18954. },
  18955. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  18956. return this.compileIndex(charStrings);
  18957. },
  18958. compileCharset: function CFFCompiler_compileCharset(charset) {
  18959. return this.compileTypedArray(charset.raw);
  18960. },
  18961. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  18962. return this.compileTypedArray(encoding.raw);
  18963. },
  18964. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  18965. return this.compileTypedArray(fdSelect);
  18966. },
  18967. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  18968. var out = [];
  18969. for (var i = 0, ii = data.length; i < ii; ++i) {
  18970. out[i] = data[i];
  18971. }
  18972. return out;
  18973. },
  18974. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  18975. trackers = trackers || [];
  18976. var objects = index.objects;
  18977. // First 2 bytes contains the number of objects contained into this index
  18978. var count = objects.length;
  18979. // If there is no object, just create an index. This technically
  18980. // should just be [0, 0] but OTS has an issue with that.
  18981. if (count === 0) {
  18982. return [0, 0, 0];
  18983. }
  18984. var data = [(count >> 8) & 0xFF, count & 0xff];
  18985. var lastOffset = 1, i;
  18986. for (i = 0; i < count; ++i) {
  18987. lastOffset += objects[i].length;
  18988. }
  18989. var offsetSize;
  18990. if (lastOffset < 0x100) {
  18991. offsetSize = 1;
  18992. } else if (lastOffset < 0x10000) {
  18993. offsetSize = 2;
  18994. } else if (lastOffset < 0x1000000) {
  18995. offsetSize = 3;
  18996. } else {
  18997. offsetSize = 4;
  18998. }
  18999. // Next byte contains the offset size use to reference object in the file
  19000. data.push(offsetSize);
  19001. // Add another offset after this one because we need a new offset
  19002. var relativeOffset = 1;
  19003. for (i = 0; i < count + 1; i++) {
  19004. if (offsetSize === 1) {
  19005. data.push(relativeOffset & 0xFF);
  19006. } else if (offsetSize === 2) {
  19007. data.push((relativeOffset >> 8) & 0xFF,
  19008. relativeOffset & 0xFF);
  19009. } else if (offsetSize === 3) {
  19010. data.push((relativeOffset >> 16) & 0xFF,
  19011. (relativeOffset >> 8) & 0xFF,
  19012. relativeOffset & 0xFF);
  19013. } else {
  19014. data.push((relativeOffset >>> 24) & 0xFF,
  19015. (relativeOffset >> 16) & 0xFF,
  19016. (relativeOffset >> 8) & 0xFF,
  19017. relativeOffset & 0xFF);
  19018. }
  19019. if (objects[i]) {
  19020. relativeOffset += objects[i].length;
  19021. }
  19022. }
  19023. for (i = 0; i < count; i++) {
  19024. // Notify the tracker where the object will be offset in the data.
  19025. if (trackers[i]) {
  19026. trackers[i].offset(data.length);
  19027. }
  19028. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19029. data.push(objects[i][j]);
  19030. }
  19031. }
  19032. return data;
  19033. }
  19034. };
  19035. return CFFCompiler;
  19036. })();
  19037. // Workaround for seac on Windows.
  19038. (function checkSeacSupport() {
  19039. if (/Windows/.test(navigator.userAgent)) {
  19040. SEAC_ANALYSIS_ENABLED = true;
  19041. }
  19042. })();
  19043. // Workaround for Private Use Area characters in Chrome on Windows
  19044. // http://code.google.com/p/chromium/issues/detail?id=122465
  19045. // https://github.com/mozilla/pdf.js/issues/1689
  19046. (function checkChromeWindows() {
  19047. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19048. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19049. }
  19050. })();
  19051. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19052. function getLong(data, offset) {
  19053. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19054. (data[offset + 2] << 8) | data[offset + 3];
  19055. }
  19056. function getUshort(data, offset) {
  19057. return (data[offset] << 8) | data[offset + 1];
  19058. }
  19059. function parseCmap(data, start, end) {
  19060. var offset = (getUshort(data, start + 2) === 1 ?
  19061. getLong(data, start + 8) : getLong(data, start + 16));
  19062. var format = getUshort(data, start + offset);
  19063. var length, ranges, p, i;
  19064. if (format === 4) {
  19065. length = getUshort(data, start + offset + 2);
  19066. var segCount = getUshort(data, start + offset + 6) >> 1;
  19067. p = start + offset + 14;
  19068. ranges = [];
  19069. for (i = 0; i < segCount; i++, p += 2) {
  19070. ranges[i] = {end: getUshort(data, p)};
  19071. }
  19072. p += 2;
  19073. for (i = 0; i < segCount; i++, p += 2) {
  19074. ranges[i].start = getUshort(data, p);
  19075. }
  19076. for (i = 0; i < segCount; i++, p += 2) {
  19077. ranges[i].idDelta = getUshort(data, p);
  19078. }
  19079. for (i = 0; i < segCount; i++, p += 2) {
  19080. var idOffset = getUshort(data, p);
  19081. if (idOffset === 0) {
  19082. continue;
  19083. }
  19084. ranges[i].ids = [];
  19085. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19086. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19087. idOffset += 2;
  19088. }
  19089. }
  19090. return ranges;
  19091. } else if (format === 12) {
  19092. length = getLong(data, start + offset + 4);
  19093. var groups = getLong(data, start + offset + 12);
  19094. p = start + offset + 16;
  19095. ranges = [];
  19096. for (i = 0; i < groups; i++) {
  19097. ranges.push({
  19098. start: getLong(data, p),
  19099. end: getLong(data, p + 4),
  19100. idDelta: getLong(data, p + 8) - getLong(data, p)
  19101. });
  19102. p += 12;
  19103. }
  19104. return ranges;
  19105. }
  19106. error('not supported cmap: ' + format);
  19107. }
  19108. function parseCff(data, start, end) {
  19109. var properties = {};
  19110. var parser = new CFFParser(new Stream(data, start, end - start),
  19111. properties);
  19112. var cff = parser.parse();
  19113. return {
  19114. glyphs: cff.charStrings.objects,
  19115. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19116. cff.topDict.privateDict.subrsIndex.objects),
  19117. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19118. };
  19119. }
  19120. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19121. var itemSize, itemDecode;
  19122. if (isGlyphLocationsLong) {
  19123. itemSize = 4;
  19124. itemDecode = function fontItemDecodeLong(data, offset) {
  19125. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19126. (data[offset + 2] << 8) | data[offset + 3];
  19127. };
  19128. } else {
  19129. itemSize = 2;
  19130. itemDecode = function fontItemDecode(data, offset) {
  19131. return (data[offset] << 9) | (data[offset + 1] << 1);
  19132. };
  19133. }
  19134. var glyphs = [];
  19135. var startOffset = itemDecode(loca, 0);
  19136. for (var j = itemSize; j < loca.length; j += itemSize) {
  19137. var endOffset = itemDecode(loca, j);
  19138. glyphs.push(glyf.subarray(startOffset, endOffset));
  19139. startOffset = endOffset;
  19140. }
  19141. return glyphs;
  19142. }
  19143. function lookupCmap(ranges, unicode) {
  19144. var code = unicode.charCodeAt(0);
  19145. var l = 0, r = ranges.length - 1;
  19146. while (l < r) {
  19147. var c = (l + r + 1) >> 1;
  19148. if (code < ranges[c].start) {
  19149. r = c - 1;
  19150. } else {
  19151. l = c;
  19152. }
  19153. }
  19154. if (ranges[l].start <= code && code <= ranges[l].end) {
  19155. return (ranges[l].idDelta + (ranges[l].ids ?
  19156. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19157. }
  19158. return 0;
  19159. }
  19160. function compileGlyf(code, js, font) {
  19161. function moveTo(x, y) {
  19162. js.push('c.moveTo(' + x + ',' + y + ');');
  19163. }
  19164. function lineTo(x, y) {
  19165. js.push('c.lineTo(' + x + ',' + y + ');');
  19166. }
  19167. function quadraticCurveTo(xa, ya, x, y) {
  19168. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19169. x + ',' + y + ');');
  19170. }
  19171. var i = 0;
  19172. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19173. var flags;
  19174. var x = 0, y = 0;
  19175. i += 10;
  19176. if (numberOfContours < 0) {
  19177. // composite glyph
  19178. do {
  19179. flags = (code[i] << 8) | code[i + 1];
  19180. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19181. i += 4;
  19182. var arg1, arg2;
  19183. if ((flags & 0x01)) {
  19184. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19185. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19186. i += 4;
  19187. } else {
  19188. arg1 = code[i++]; arg2 = code[i++];
  19189. }
  19190. if ((flags & 0x02)) {
  19191. x = arg1;
  19192. y = arg2;
  19193. } else {
  19194. x = 0; y = 0; // TODO "they are points" ?
  19195. }
  19196. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19197. if ((flags & 0x08)) {
  19198. scaleX =
  19199. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19200. i += 2;
  19201. } else if ((flags & 0x40)) {
  19202. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19203. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19204. i += 4;
  19205. } else if ((flags & 0x80)) {
  19206. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19207. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19208. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19209. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19210. i += 8;
  19211. }
  19212. var subglyph = font.glyphs[glyphIndex];
  19213. if (subglyph) {
  19214. js.push('c.save();');
  19215. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19216. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19217. compileGlyf(subglyph, js, font);
  19218. js.push('c.restore();');
  19219. }
  19220. } while ((flags & 0x20));
  19221. } else {
  19222. // simple glyph
  19223. var endPtsOfContours = [];
  19224. var j, jj;
  19225. for (j = 0; j < numberOfContours; j++) {
  19226. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19227. i += 2;
  19228. }
  19229. var instructionLength = (code[i] << 8) | code[i + 1];
  19230. i += 2 + instructionLength; // skipping the instructions
  19231. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19232. var points = [];
  19233. while (points.length < numberOfPoints) {
  19234. flags = code[i++];
  19235. var repeat = 1;
  19236. if ((flags & 0x08)) {
  19237. repeat += code[i++];
  19238. }
  19239. while (repeat-- > 0) {
  19240. points.push({flags: flags});
  19241. }
  19242. }
  19243. for (j = 0; j < numberOfPoints; j++) {
  19244. switch (points[j].flags & 0x12) {
  19245. case 0x00:
  19246. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19247. i += 2;
  19248. break;
  19249. case 0x02:
  19250. x -= code[i++];
  19251. break;
  19252. case 0x12:
  19253. x += code[i++];
  19254. break;
  19255. }
  19256. points[j].x = x;
  19257. }
  19258. for (j = 0; j < numberOfPoints; j++) {
  19259. switch (points[j].flags & 0x24) {
  19260. case 0x00:
  19261. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19262. i += 2;
  19263. break;
  19264. case 0x04:
  19265. y -= code[i++];
  19266. break;
  19267. case 0x24:
  19268. y += code[i++];
  19269. break;
  19270. }
  19271. points[j].y = y;
  19272. }
  19273. var startPoint = 0;
  19274. for (i = 0; i < numberOfContours; i++) {
  19275. var endPoint = endPtsOfContours[i];
  19276. // contours might have implicit points, which is located in the middle
  19277. // between two neighboring off-curve points
  19278. var contour = points.slice(startPoint, endPoint + 1);
  19279. if ((contour[0].flags & 1)) {
  19280. contour.push(contour[0]); // using start point at the contour end
  19281. } else if ((contour[contour.length - 1].flags & 1)) {
  19282. // first is off-curve point, trying to use one from the end
  19283. contour.unshift(contour[contour.length - 1]);
  19284. } else {
  19285. // start and end are off-curve points, creating implicit one
  19286. var p = {
  19287. flags: 1,
  19288. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19289. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19290. };
  19291. contour.unshift(p);
  19292. contour.push(p);
  19293. }
  19294. moveTo(contour[0].x, contour[0].y);
  19295. for (j = 1, jj = contour.length; j < jj; j++) {
  19296. if ((contour[j].flags & 1)) {
  19297. lineTo(contour[j].x, contour[j].y);
  19298. } else if ((contour[j + 1].flags & 1)){
  19299. quadraticCurveTo(contour[j].x, contour[j].y,
  19300. contour[j + 1].x, contour[j + 1].y);
  19301. j++;
  19302. } else {
  19303. quadraticCurveTo(contour[j].x, contour[j].y,
  19304. (contour[j].x + contour[j + 1].x) / 2,
  19305. (contour[j].y + contour[j + 1].y) / 2);
  19306. }
  19307. }
  19308. startPoint = endPoint + 1;
  19309. }
  19310. }
  19311. }
  19312. function compileCharString(code, js, font) {
  19313. var stack = [];
  19314. var x = 0, y = 0;
  19315. var stems = 0;
  19316. function moveTo(x, y) {
  19317. js.push('c.moveTo(' + x + ',' + y + ');');
  19318. }
  19319. function lineTo(x, y) {
  19320. js.push('c.lineTo(' + x + ',' + y + ');');
  19321. }
  19322. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19323. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19324. x + ',' + y + ');');
  19325. }
  19326. function parse(code) {
  19327. var i = 0;
  19328. while (i < code.length) {
  19329. var stackClean = false;
  19330. var v = code[i++];
  19331. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19332. switch (v) {
  19333. case 1: // hstem
  19334. stems += stack.length >> 1;
  19335. stackClean = true;
  19336. break;
  19337. case 3: // vstem
  19338. stems += stack.length >> 1;
  19339. stackClean = true;
  19340. break;
  19341. case 4: // vmoveto
  19342. y += stack.pop();
  19343. moveTo(x, y);
  19344. stackClean = true;
  19345. break;
  19346. case 5: // rlineto
  19347. while (stack.length > 0) {
  19348. x += stack.shift();
  19349. y += stack.shift();
  19350. lineTo(x, y);
  19351. }
  19352. break;
  19353. case 6: // hlineto
  19354. while (stack.length > 0) {
  19355. x += stack.shift();
  19356. lineTo(x, y);
  19357. if (stack.length === 0) {
  19358. break;
  19359. }
  19360. y += stack.shift();
  19361. lineTo(x, y);
  19362. }
  19363. break;
  19364. case 7: // vlineto
  19365. while (stack.length > 0) {
  19366. y += stack.shift();
  19367. lineTo(x, y);
  19368. if (stack.length === 0) {
  19369. break;
  19370. }
  19371. x += stack.shift();
  19372. lineTo(x, y);
  19373. }
  19374. break;
  19375. case 8: // rrcurveto
  19376. while (stack.length > 0) {
  19377. xa = x + stack.shift(); ya = y + stack.shift();
  19378. xb = xa + stack.shift(); yb = ya + stack.shift();
  19379. x = xb + stack.shift(); y = yb + stack.shift();
  19380. bezierCurveTo(xa, ya, xb, yb, x, y);
  19381. }
  19382. break;
  19383. case 10: // callsubr
  19384. n = stack.pop() + font.subrsBias;
  19385. subrCode = font.subrs[n];
  19386. if (subrCode) {
  19387. parse(subrCode);
  19388. }
  19389. break;
  19390. case 11: // return
  19391. return;
  19392. case 12:
  19393. v = code[i++];
  19394. switch (v) {
  19395. case 34: // flex
  19396. xa = x + stack.shift();
  19397. xb = xa + stack.shift(); y1 = y + stack.shift();
  19398. x = xb + stack.shift();
  19399. bezierCurveTo(xa, y, xb, y1, x, y1);
  19400. xa = x + stack.shift();
  19401. xb = xa + stack.shift();
  19402. x = xb + stack.shift();
  19403. bezierCurveTo(xa, y1, xb, y, x, y);
  19404. break;
  19405. case 35: // flex
  19406. xa = x + stack.shift(); ya = y + stack.shift();
  19407. xb = xa + stack.shift(); yb = ya + stack.shift();
  19408. x = xb + stack.shift(); y = yb + stack.shift();
  19409. bezierCurveTo(xa, ya, xb, yb, x, y);
  19410. xa = x + stack.shift(); ya = y + stack.shift();
  19411. xb = xa + stack.shift(); yb = ya + stack.shift();
  19412. x = xb + stack.shift(); y = yb + stack.shift();
  19413. bezierCurveTo(xa, ya, xb, yb, x, y);
  19414. stack.pop(); // fd
  19415. break;
  19416. case 36: // hflex1
  19417. xa = x + stack.shift(); y1 = y + stack.shift();
  19418. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19419. x = xb + stack.shift();
  19420. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19421. xa = x + stack.shift();
  19422. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19423. x = xb + stack.shift();
  19424. bezierCurveTo(xa, y2, xb, y3, x, y);
  19425. break;
  19426. case 37: // flex1
  19427. var x0 = x, y0 = y;
  19428. xa = x + stack.shift(); ya = y + stack.shift();
  19429. xb = xa + stack.shift(); yb = ya + stack.shift();
  19430. x = xb + stack.shift(); y = yb + stack.shift();
  19431. bezierCurveTo(xa, ya, xb, yb, x, y);
  19432. xa = x + stack.shift(); ya = y + stack.shift();
  19433. xb = xa + stack.shift(); yb = ya + stack.shift();
  19434. x = xb; y = yb;
  19435. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19436. x += stack.shift();
  19437. } else {
  19438. y += stack.shift();
  19439. }
  19440. bezierCurveTo(xa, ya, xb, yb, x, y);
  19441. break;
  19442. default:
  19443. error('unknown operator: 12 ' + v);
  19444. }
  19445. break;
  19446. case 14: // endchar
  19447. if (stack.length >= 4) {
  19448. var achar = stack.pop();
  19449. var bchar = stack.pop();
  19450. y = stack.pop();
  19451. x = stack.pop();
  19452. js.push('c.save();');
  19453. js.push('c.translate('+ x + ',' + y + ');');
  19454. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19455. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19456. compileCharString(font.glyphs[gid], js, font);
  19457. js.push('c.restore();');
  19458. gid = lookupCmap(font.cmap, String.fromCharCode(
  19459. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19460. compileCharString(font.glyphs[gid], js, font);
  19461. }
  19462. return;
  19463. case 18: // hstemhm
  19464. stems += stack.length >> 1;
  19465. stackClean = true;
  19466. break;
  19467. case 19: // hintmask
  19468. stems += stack.length >> 1;
  19469. i += (stems + 7) >> 3;
  19470. stackClean = true;
  19471. break;
  19472. case 20: // cntrmask
  19473. stems += stack.length >> 1;
  19474. i += (stems + 7) >> 3;
  19475. stackClean = true;
  19476. break;
  19477. case 21: // rmoveto
  19478. y += stack.pop();
  19479. x += stack.pop();
  19480. moveTo(x, y);
  19481. stackClean = true;
  19482. break;
  19483. case 22: // hmoveto
  19484. x += stack.pop();
  19485. moveTo(x, y);
  19486. stackClean = true;
  19487. break;
  19488. case 23: // vstemhm
  19489. stems += stack.length >> 1;
  19490. stackClean = true;
  19491. break;
  19492. case 24: // rcurveline
  19493. while (stack.length > 2) {
  19494. xa = x + stack.shift(); ya = y + stack.shift();
  19495. xb = xa + stack.shift(); yb = ya + stack.shift();
  19496. x = xb + stack.shift(); y = yb + stack.shift();
  19497. bezierCurveTo(xa, ya, xb, yb, x, y);
  19498. }
  19499. x += stack.shift();
  19500. y += stack.shift();
  19501. lineTo(x, y);
  19502. break;
  19503. case 25: // rlinecurve
  19504. while (stack.length > 6) {
  19505. x += stack.shift();
  19506. y += stack.shift();
  19507. lineTo(x, y);
  19508. }
  19509. xa = x + stack.shift(); ya = y + stack.shift();
  19510. xb = xa + stack.shift(); yb = ya + stack.shift();
  19511. x = xb + stack.shift(); y = yb + stack.shift();
  19512. bezierCurveTo(xa, ya, xb, yb, x, y);
  19513. break;
  19514. case 26: // vvcurveto
  19515. if (stack.length % 2) {
  19516. x += stack.shift();
  19517. }
  19518. while (stack.length > 0) {
  19519. xa = x; ya = y + stack.shift();
  19520. xb = xa + stack.shift(); yb = ya + stack.shift();
  19521. x = xb; y = yb + stack.shift();
  19522. bezierCurveTo(xa, ya, xb, yb, x, y);
  19523. }
  19524. break;
  19525. case 27: // hhcurveto
  19526. if (stack.length % 2) {
  19527. y += stack.shift();
  19528. }
  19529. while (stack.length > 0) {
  19530. xa = x + stack.shift(); ya = y;
  19531. xb = xa + stack.shift(); yb = ya + stack.shift();
  19532. x = xb + stack.shift(); y = yb;
  19533. bezierCurveTo(xa, ya, xb, yb, x, y);
  19534. }
  19535. break;
  19536. case 28:
  19537. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19538. i += 2;
  19539. break;
  19540. case 29: // callgsubr
  19541. n = stack.pop() + font.gsubrsBias;
  19542. subrCode = font.gsubrs[n];
  19543. if (subrCode) {
  19544. parse(subrCode);
  19545. }
  19546. break;
  19547. case 30: // vhcurveto
  19548. while (stack.length > 0) {
  19549. xa = x; ya = y + stack.shift();
  19550. xb = xa + stack.shift(); yb = ya + stack.shift();
  19551. x = xb + stack.shift();
  19552. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19553. bezierCurveTo(xa, ya, xb, yb, x, y);
  19554. if (stack.length === 0) {
  19555. break;
  19556. }
  19557. xa = x + stack.shift(); ya = y;
  19558. xb = xa + stack.shift(); yb = ya + stack.shift();
  19559. y = yb + stack.shift();
  19560. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19561. bezierCurveTo(xa, ya, xb, yb, x, y);
  19562. }
  19563. break;
  19564. case 31: // hvcurveto
  19565. while (stack.length > 0) {
  19566. xa = x + stack.shift(); ya = y;
  19567. xb = xa + stack.shift(); yb = ya + stack.shift();
  19568. y = yb + stack.shift();
  19569. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19570. bezierCurveTo(xa, ya, xb, yb, x, y);
  19571. if (stack.length === 0) {
  19572. break;
  19573. }
  19574. xa = x; ya = y + stack.shift();
  19575. xb = xa + stack.shift(); yb = ya + stack.shift();
  19576. x = xb + stack.shift();
  19577. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19578. bezierCurveTo(xa, ya, xb, yb, x, y);
  19579. }
  19580. break;
  19581. default:
  19582. if (v < 32) {
  19583. error('unknown operator: ' + v);
  19584. }
  19585. if (v < 247) {
  19586. stack.push(v - 139);
  19587. } else if (v < 251) {
  19588. stack.push((v - 247) * 256 + code[i++] + 108);
  19589. } else if (v < 255) {
  19590. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19591. } else {
  19592. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19593. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19594. i += 4;
  19595. }
  19596. break;
  19597. }
  19598. if (stackClean) {
  19599. stack.length = 0;
  19600. }
  19601. }
  19602. }
  19603. parse(code);
  19604. }
  19605. var noop = '';
  19606. function CompiledFont(fontMatrix) {
  19607. this.compiledGlyphs = {};
  19608. this.fontMatrix = fontMatrix;
  19609. }
  19610. CompiledFont.prototype = {
  19611. getPathJs: function (unicode) {
  19612. var gid = lookupCmap(this.cmap, unicode);
  19613. var fn = this.compiledGlyphs[gid];
  19614. if (!fn) {
  19615. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19616. }
  19617. return fn;
  19618. },
  19619. compileGlyph: function (code) {
  19620. if (!code || code.length === 0 || code[0] === 14) {
  19621. return noop;
  19622. }
  19623. var js = [];
  19624. js.push('c.save();');
  19625. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  19626. js.push('c.scale(size, -size);');
  19627. this.compileGlyphImpl(code, js);
  19628. js.push('c.restore();');
  19629. return js.join('\n');
  19630. },
  19631. compileGlyphImpl: function () {
  19632. error('Children classes should implement this.');
  19633. },
  19634. hasBuiltPath: function (unicode) {
  19635. var gid = lookupCmap(this.cmap, unicode);
  19636. return gid in this.compiledGlyphs;
  19637. }
  19638. };
  19639. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19640. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19641. CompiledFont.call(this, fontMatrix);
  19642. this.glyphs = glyphs;
  19643. this.cmap = cmap;
  19644. this.compiledGlyphs = [];
  19645. }
  19646. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19647. compileGlyphImpl: function (code, js) {
  19648. compileGlyf(code, js, this);
  19649. }
  19650. });
  19651. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19652. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19653. CompiledFont.call(this, fontMatrix);
  19654. this.glyphs = cffInfo.glyphs;
  19655. this.gsubrs = cffInfo.gsubrs || [];
  19656. this.subrs = cffInfo.subrs || [];
  19657. this.cmap = cmap;
  19658. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19659. this.compiledGlyphs = [];
  19660. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19661. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19662. this.subrsBias = (this.subrs.length < 1240 ?
  19663. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19664. }
  19665. Util.inherit(Type2Compiled, CompiledFont, {
  19666. compileGlyphImpl: function (code, js) {
  19667. compileCharString(code, js, this);
  19668. }
  19669. });
  19670. return {
  19671. create: function FontRendererFactory_create(font) {
  19672. var data = new Uint8Array(font.data);
  19673. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19674. var numTables = getUshort(data, 4);
  19675. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19676. var tag = bytesToString(data.subarray(p, p + 4));
  19677. var offset = getLong(data, p + 8);
  19678. var length = getLong(data, p + 12);
  19679. switch (tag) {
  19680. case 'cmap':
  19681. cmap = parseCmap(data, offset, offset + length);
  19682. break;
  19683. case 'glyf':
  19684. glyf = data.subarray(offset, offset + length);
  19685. break;
  19686. case 'loca':
  19687. loca = data.subarray(offset, offset + length);
  19688. break;
  19689. case 'head':
  19690. unitsPerEm = getUshort(data, offset + 18);
  19691. indexToLocFormat = getUshort(data, offset + 50);
  19692. break;
  19693. case 'CFF ':
  19694. cff = parseCff(data, offset, offset + length);
  19695. break;
  19696. }
  19697. }
  19698. if (glyf) {
  19699. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  19700. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  19701. return new TrueTypeCompiled(
  19702. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19703. } else {
  19704. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19705. }
  19706. }
  19707. };
  19708. })();
  19709. var GlyphsUnicode = {
  19710. A: 0x0041,
  19711. AE: 0x00C6,
  19712. AEacute: 0x01FC,
  19713. AEmacron: 0x01E2,
  19714. AEsmall: 0xF7E6,
  19715. Aacute: 0x00C1,
  19716. Aacutesmall: 0xF7E1,
  19717. Abreve: 0x0102,
  19718. Abreveacute: 0x1EAE,
  19719. Abrevecyrillic: 0x04D0,
  19720. Abrevedotbelow: 0x1EB6,
  19721. Abrevegrave: 0x1EB0,
  19722. Abrevehookabove: 0x1EB2,
  19723. Abrevetilde: 0x1EB4,
  19724. Acaron: 0x01CD,
  19725. Acircle: 0x24B6,
  19726. Acircumflex: 0x00C2,
  19727. Acircumflexacute: 0x1EA4,
  19728. Acircumflexdotbelow: 0x1EAC,
  19729. Acircumflexgrave: 0x1EA6,
  19730. Acircumflexhookabove: 0x1EA8,
  19731. Acircumflexsmall: 0xF7E2,
  19732. Acircumflextilde: 0x1EAA,
  19733. Acute: 0xF6C9,
  19734. Acutesmall: 0xF7B4,
  19735. Acyrillic: 0x0410,
  19736. Adblgrave: 0x0200,
  19737. Adieresis: 0x00C4,
  19738. Adieresiscyrillic: 0x04D2,
  19739. Adieresismacron: 0x01DE,
  19740. Adieresissmall: 0xF7E4,
  19741. Adotbelow: 0x1EA0,
  19742. Adotmacron: 0x01E0,
  19743. Agrave: 0x00C0,
  19744. Agravesmall: 0xF7E0,
  19745. Ahookabove: 0x1EA2,
  19746. Aiecyrillic: 0x04D4,
  19747. Ainvertedbreve: 0x0202,
  19748. Alpha: 0x0391,
  19749. Alphatonos: 0x0386,
  19750. Amacron: 0x0100,
  19751. Amonospace: 0xFF21,
  19752. Aogonek: 0x0104,
  19753. Aring: 0x00C5,
  19754. Aringacute: 0x01FA,
  19755. Aringbelow: 0x1E00,
  19756. Aringsmall: 0xF7E5,
  19757. Asmall: 0xF761,
  19758. Atilde: 0x00C3,
  19759. Atildesmall: 0xF7E3,
  19760. Aybarmenian: 0x0531,
  19761. B: 0x0042,
  19762. Bcircle: 0x24B7,
  19763. Bdotaccent: 0x1E02,
  19764. Bdotbelow: 0x1E04,
  19765. Becyrillic: 0x0411,
  19766. Benarmenian: 0x0532,
  19767. Beta: 0x0392,
  19768. Bhook: 0x0181,
  19769. Blinebelow: 0x1E06,
  19770. Bmonospace: 0xFF22,
  19771. Brevesmall: 0xF6F4,
  19772. Bsmall: 0xF762,
  19773. Btopbar: 0x0182,
  19774. C: 0x0043,
  19775. Caarmenian: 0x053E,
  19776. Cacute: 0x0106,
  19777. Caron: 0xF6CA,
  19778. Caronsmall: 0xF6F5,
  19779. Ccaron: 0x010C,
  19780. Ccedilla: 0x00C7,
  19781. Ccedillaacute: 0x1E08,
  19782. Ccedillasmall: 0xF7E7,
  19783. Ccircle: 0x24B8,
  19784. Ccircumflex: 0x0108,
  19785. Cdot: 0x010A,
  19786. Cdotaccent: 0x010A,
  19787. Cedillasmall: 0xF7B8,
  19788. Chaarmenian: 0x0549,
  19789. Cheabkhasiancyrillic: 0x04BC,
  19790. Checyrillic: 0x0427,
  19791. Chedescenderabkhasiancyrillic: 0x04BE,
  19792. Chedescendercyrillic: 0x04B6,
  19793. Chedieresiscyrillic: 0x04F4,
  19794. Cheharmenian: 0x0543,
  19795. Chekhakassiancyrillic: 0x04CB,
  19796. Cheverticalstrokecyrillic: 0x04B8,
  19797. Chi: 0x03A7,
  19798. Chook: 0x0187,
  19799. Circumflexsmall: 0xF6F6,
  19800. Cmonospace: 0xFF23,
  19801. Coarmenian: 0x0551,
  19802. Csmall: 0xF763,
  19803. D: 0x0044,
  19804. DZ: 0x01F1,
  19805. DZcaron: 0x01C4,
  19806. Daarmenian: 0x0534,
  19807. Dafrican: 0x0189,
  19808. Dcaron: 0x010E,
  19809. Dcedilla: 0x1E10,
  19810. Dcircle: 0x24B9,
  19811. Dcircumflexbelow: 0x1E12,
  19812. Dcroat: 0x0110,
  19813. Ddotaccent: 0x1E0A,
  19814. Ddotbelow: 0x1E0C,
  19815. Decyrillic: 0x0414,
  19816. Deicoptic: 0x03EE,
  19817. Delta: 0x2206,
  19818. Deltagreek: 0x0394,
  19819. Dhook: 0x018A,
  19820. Dieresis: 0xF6CB,
  19821. DieresisAcute: 0xF6CC,
  19822. DieresisGrave: 0xF6CD,
  19823. Dieresissmall: 0xF7A8,
  19824. Digammagreek: 0x03DC,
  19825. Djecyrillic: 0x0402,
  19826. Dlinebelow: 0x1E0E,
  19827. Dmonospace: 0xFF24,
  19828. Dotaccentsmall: 0xF6F7,
  19829. Dslash: 0x0110,
  19830. Dsmall: 0xF764,
  19831. Dtopbar: 0x018B,
  19832. Dz: 0x01F2,
  19833. Dzcaron: 0x01C5,
  19834. Dzeabkhasiancyrillic: 0x04E0,
  19835. Dzecyrillic: 0x0405,
  19836. Dzhecyrillic: 0x040F,
  19837. E: 0x0045,
  19838. Eacute: 0x00C9,
  19839. Eacutesmall: 0xF7E9,
  19840. Ebreve: 0x0114,
  19841. Ecaron: 0x011A,
  19842. Ecedillabreve: 0x1E1C,
  19843. Echarmenian: 0x0535,
  19844. Ecircle: 0x24BA,
  19845. Ecircumflex: 0x00CA,
  19846. Ecircumflexacute: 0x1EBE,
  19847. Ecircumflexbelow: 0x1E18,
  19848. Ecircumflexdotbelow: 0x1EC6,
  19849. Ecircumflexgrave: 0x1EC0,
  19850. Ecircumflexhookabove: 0x1EC2,
  19851. Ecircumflexsmall: 0xF7EA,
  19852. Ecircumflextilde: 0x1EC4,
  19853. Ecyrillic: 0x0404,
  19854. Edblgrave: 0x0204,
  19855. Edieresis: 0x00CB,
  19856. Edieresissmall: 0xF7EB,
  19857. Edot: 0x0116,
  19858. Edotaccent: 0x0116,
  19859. Edotbelow: 0x1EB8,
  19860. Efcyrillic: 0x0424,
  19861. Egrave: 0x00C8,
  19862. Egravesmall: 0xF7E8,
  19863. Eharmenian: 0x0537,
  19864. Ehookabove: 0x1EBA,
  19865. Eightroman: 0x2167,
  19866. Einvertedbreve: 0x0206,
  19867. Eiotifiedcyrillic: 0x0464,
  19868. Elcyrillic: 0x041B,
  19869. Elevenroman: 0x216A,
  19870. Emacron: 0x0112,
  19871. Emacronacute: 0x1E16,
  19872. Emacrongrave: 0x1E14,
  19873. Emcyrillic: 0x041C,
  19874. Emonospace: 0xFF25,
  19875. Encyrillic: 0x041D,
  19876. Endescendercyrillic: 0x04A2,
  19877. Eng: 0x014A,
  19878. Enghecyrillic: 0x04A4,
  19879. Enhookcyrillic: 0x04C7,
  19880. Eogonek: 0x0118,
  19881. Eopen: 0x0190,
  19882. Epsilon: 0x0395,
  19883. Epsilontonos: 0x0388,
  19884. Ercyrillic: 0x0420,
  19885. Ereversed: 0x018E,
  19886. Ereversedcyrillic: 0x042D,
  19887. Escyrillic: 0x0421,
  19888. Esdescendercyrillic: 0x04AA,
  19889. Esh: 0x01A9,
  19890. Esmall: 0xF765,
  19891. Eta: 0x0397,
  19892. Etarmenian: 0x0538,
  19893. Etatonos: 0x0389,
  19894. Eth: 0x00D0,
  19895. Ethsmall: 0xF7F0,
  19896. Etilde: 0x1EBC,
  19897. Etildebelow: 0x1E1A,
  19898. Euro: 0x20AC,
  19899. Ezh: 0x01B7,
  19900. Ezhcaron: 0x01EE,
  19901. Ezhreversed: 0x01B8,
  19902. F: 0x0046,
  19903. Fcircle: 0x24BB,
  19904. Fdotaccent: 0x1E1E,
  19905. Feharmenian: 0x0556,
  19906. Feicoptic: 0x03E4,
  19907. Fhook: 0x0191,
  19908. Fitacyrillic: 0x0472,
  19909. Fiveroman: 0x2164,
  19910. Fmonospace: 0xFF26,
  19911. Fourroman: 0x2163,
  19912. Fsmall: 0xF766,
  19913. G: 0x0047,
  19914. GBsquare: 0x3387,
  19915. Gacute: 0x01F4,
  19916. Gamma: 0x0393,
  19917. Gammaafrican: 0x0194,
  19918. Gangiacoptic: 0x03EA,
  19919. Gbreve: 0x011E,
  19920. Gcaron: 0x01E6,
  19921. Gcedilla: 0x0122,
  19922. Gcircle: 0x24BC,
  19923. Gcircumflex: 0x011C,
  19924. Gcommaaccent: 0x0122,
  19925. Gdot: 0x0120,
  19926. Gdotaccent: 0x0120,
  19927. Gecyrillic: 0x0413,
  19928. Ghadarmenian: 0x0542,
  19929. Ghemiddlehookcyrillic: 0x0494,
  19930. Ghestrokecyrillic: 0x0492,
  19931. Gheupturncyrillic: 0x0490,
  19932. Ghook: 0x0193,
  19933. Gimarmenian: 0x0533,
  19934. Gjecyrillic: 0x0403,
  19935. Gmacron: 0x1E20,
  19936. Gmonospace: 0xFF27,
  19937. Grave: 0xF6CE,
  19938. Gravesmall: 0xF760,
  19939. Gsmall: 0xF767,
  19940. Gsmallhook: 0x029B,
  19941. Gstroke: 0x01E4,
  19942. H: 0x0048,
  19943. H18533: 0x25CF,
  19944. H18543: 0x25AA,
  19945. H18551: 0x25AB,
  19946. H22073: 0x25A1,
  19947. HPsquare: 0x33CB,
  19948. Haabkhasiancyrillic: 0x04A8,
  19949. Hadescendercyrillic: 0x04B2,
  19950. Hardsigncyrillic: 0x042A,
  19951. Hbar: 0x0126,
  19952. Hbrevebelow: 0x1E2A,
  19953. Hcedilla: 0x1E28,
  19954. Hcircle: 0x24BD,
  19955. Hcircumflex: 0x0124,
  19956. Hdieresis: 0x1E26,
  19957. Hdotaccent: 0x1E22,
  19958. Hdotbelow: 0x1E24,
  19959. Hmonospace: 0xFF28,
  19960. Hoarmenian: 0x0540,
  19961. Horicoptic: 0x03E8,
  19962. Hsmall: 0xF768,
  19963. Hungarumlaut: 0xF6CF,
  19964. Hungarumlautsmall: 0xF6F8,
  19965. Hzsquare: 0x3390,
  19966. I: 0x0049,
  19967. IAcyrillic: 0x042F,
  19968. IJ: 0x0132,
  19969. IUcyrillic: 0x042E,
  19970. Iacute: 0x00CD,
  19971. Iacutesmall: 0xF7ED,
  19972. Ibreve: 0x012C,
  19973. Icaron: 0x01CF,
  19974. Icircle: 0x24BE,
  19975. Icircumflex: 0x00CE,
  19976. Icircumflexsmall: 0xF7EE,
  19977. Icyrillic: 0x0406,
  19978. Idblgrave: 0x0208,
  19979. Idieresis: 0x00CF,
  19980. Idieresisacute: 0x1E2E,
  19981. Idieresiscyrillic: 0x04E4,
  19982. Idieresissmall: 0xF7EF,
  19983. Idot: 0x0130,
  19984. Idotaccent: 0x0130,
  19985. Idotbelow: 0x1ECA,
  19986. Iebrevecyrillic: 0x04D6,
  19987. Iecyrillic: 0x0415,
  19988. Ifraktur: 0x2111,
  19989. Igrave: 0x00CC,
  19990. Igravesmall: 0xF7EC,
  19991. Ihookabove: 0x1EC8,
  19992. Iicyrillic: 0x0418,
  19993. Iinvertedbreve: 0x020A,
  19994. Iishortcyrillic: 0x0419,
  19995. Imacron: 0x012A,
  19996. Imacroncyrillic: 0x04E2,
  19997. Imonospace: 0xFF29,
  19998. Iniarmenian: 0x053B,
  19999. Iocyrillic: 0x0401,
  20000. Iogonek: 0x012E,
  20001. Iota: 0x0399,
  20002. Iotaafrican: 0x0196,
  20003. Iotadieresis: 0x03AA,
  20004. Iotatonos: 0x038A,
  20005. Ismall: 0xF769,
  20006. Istroke: 0x0197,
  20007. Itilde: 0x0128,
  20008. Itildebelow: 0x1E2C,
  20009. Izhitsacyrillic: 0x0474,
  20010. Izhitsadblgravecyrillic: 0x0476,
  20011. J: 0x004A,
  20012. Jaarmenian: 0x0541,
  20013. Jcircle: 0x24BF,
  20014. Jcircumflex: 0x0134,
  20015. Jecyrillic: 0x0408,
  20016. Jheharmenian: 0x054B,
  20017. Jmonospace: 0xFF2A,
  20018. Jsmall: 0xF76A,
  20019. K: 0x004B,
  20020. KBsquare: 0x3385,
  20021. KKsquare: 0x33CD,
  20022. Kabashkircyrillic: 0x04A0,
  20023. Kacute: 0x1E30,
  20024. Kacyrillic: 0x041A,
  20025. Kadescendercyrillic: 0x049A,
  20026. Kahookcyrillic: 0x04C3,
  20027. Kappa: 0x039A,
  20028. Kastrokecyrillic: 0x049E,
  20029. Kaverticalstrokecyrillic: 0x049C,
  20030. Kcaron: 0x01E8,
  20031. Kcedilla: 0x0136,
  20032. Kcircle: 0x24C0,
  20033. Kcommaaccent: 0x0136,
  20034. Kdotbelow: 0x1E32,
  20035. Keharmenian: 0x0554,
  20036. Kenarmenian: 0x053F,
  20037. Khacyrillic: 0x0425,
  20038. Kheicoptic: 0x03E6,
  20039. Khook: 0x0198,
  20040. Kjecyrillic: 0x040C,
  20041. Klinebelow: 0x1E34,
  20042. Kmonospace: 0xFF2B,
  20043. Koppacyrillic: 0x0480,
  20044. Koppagreek: 0x03DE,
  20045. Ksicyrillic: 0x046E,
  20046. Ksmall: 0xF76B,
  20047. L: 0x004C,
  20048. LJ: 0x01C7,
  20049. LL: 0xF6BF,
  20050. Lacute: 0x0139,
  20051. Lambda: 0x039B,
  20052. Lcaron: 0x013D,
  20053. Lcedilla: 0x013B,
  20054. Lcircle: 0x24C1,
  20055. Lcircumflexbelow: 0x1E3C,
  20056. Lcommaaccent: 0x013B,
  20057. Ldot: 0x013F,
  20058. Ldotaccent: 0x013F,
  20059. Ldotbelow: 0x1E36,
  20060. Ldotbelowmacron: 0x1E38,
  20061. Liwnarmenian: 0x053C,
  20062. Lj: 0x01C8,
  20063. Ljecyrillic: 0x0409,
  20064. Llinebelow: 0x1E3A,
  20065. Lmonospace: 0xFF2C,
  20066. Lslash: 0x0141,
  20067. Lslashsmall: 0xF6F9,
  20068. Lsmall: 0xF76C,
  20069. M: 0x004D,
  20070. MBsquare: 0x3386,
  20071. Macron: 0xF6D0,
  20072. Macronsmall: 0xF7AF,
  20073. Macute: 0x1E3E,
  20074. Mcircle: 0x24C2,
  20075. Mdotaccent: 0x1E40,
  20076. Mdotbelow: 0x1E42,
  20077. Menarmenian: 0x0544,
  20078. Mmonospace: 0xFF2D,
  20079. Msmall: 0xF76D,
  20080. Mturned: 0x019C,
  20081. Mu: 0x039C,
  20082. N: 0x004E,
  20083. NJ: 0x01CA,
  20084. Nacute: 0x0143,
  20085. Ncaron: 0x0147,
  20086. Ncedilla: 0x0145,
  20087. Ncircle: 0x24C3,
  20088. Ncircumflexbelow: 0x1E4A,
  20089. Ncommaaccent: 0x0145,
  20090. Ndotaccent: 0x1E44,
  20091. Ndotbelow: 0x1E46,
  20092. Nhookleft: 0x019D,
  20093. Nineroman: 0x2168,
  20094. Nj: 0x01CB,
  20095. Njecyrillic: 0x040A,
  20096. Nlinebelow: 0x1E48,
  20097. Nmonospace: 0xFF2E,
  20098. Nowarmenian: 0x0546,
  20099. Nsmall: 0xF76E,
  20100. Ntilde: 0x00D1,
  20101. Ntildesmall: 0xF7F1,
  20102. Nu: 0x039D,
  20103. O: 0x004F,
  20104. OE: 0x0152,
  20105. OEsmall: 0xF6FA,
  20106. Oacute: 0x00D3,
  20107. Oacutesmall: 0xF7F3,
  20108. Obarredcyrillic: 0x04E8,
  20109. Obarreddieresiscyrillic: 0x04EA,
  20110. Obreve: 0x014E,
  20111. Ocaron: 0x01D1,
  20112. Ocenteredtilde: 0x019F,
  20113. Ocircle: 0x24C4,
  20114. Ocircumflex: 0x00D4,
  20115. Ocircumflexacute: 0x1ED0,
  20116. Ocircumflexdotbelow: 0x1ED8,
  20117. Ocircumflexgrave: 0x1ED2,
  20118. Ocircumflexhookabove: 0x1ED4,
  20119. Ocircumflexsmall: 0xF7F4,
  20120. Ocircumflextilde: 0x1ED6,
  20121. Ocyrillic: 0x041E,
  20122. Odblacute: 0x0150,
  20123. Odblgrave: 0x020C,
  20124. Odieresis: 0x00D6,
  20125. Odieresiscyrillic: 0x04E6,
  20126. Odieresissmall: 0xF7F6,
  20127. Odotbelow: 0x1ECC,
  20128. Ogoneksmall: 0xF6FB,
  20129. Ograve: 0x00D2,
  20130. Ogravesmall: 0xF7F2,
  20131. Oharmenian: 0x0555,
  20132. Ohm: 0x2126,
  20133. Ohookabove: 0x1ECE,
  20134. Ohorn: 0x01A0,
  20135. Ohornacute: 0x1EDA,
  20136. Ohorndotbelow: 0x1EE2,
  20137. Ohorngrave: 0x1EDC,
  20138. Ohornhookabove: 0x1EDE,
  20139. Ohorntilde: 0x1EE0,
  20140. Ohungarumlaut: 0x0150,
  20141. Oi: 0x01A2,
  20142. Oinvertedbreve: 0x020E,
  20143. Omacron: 0x014C,
  20144. Omacronacute: 0x1E52,
  20145. Omacrongrave: 0x1E50,
  20146. Omega: 0x2126,
  20147. Omegacyrillic: 0x0460,
  20148. Omegagreek: 0x03A9,
  20149. Omegaroundcyrillic: 0x047A,
  20150. Omegatitlocyrillic: 0x047C,
  20151. Omegatonos: 0x038F,
  20152. Omicron: 0x039F,
  20153. Omicrontonos: 0x038C,
  20154. Omonospace: 0xFF2F,
  20155. Oneroman: 0x2160,
  20156. Oogonek: 0x01EA,
  20157. Oogonekmacron: 0x01EC,
  20158. Oopen: 0x0186,
  20159. Oslash: 0x00D8,
  20160. Oslashacute: 0x01FE,
  20161. Oslashsmall: 0xF7F8,
  20162. Osmall: 0xF76F,
  20163. Ostrokeacute: 0x01FE,
  20164. Otcyrillic: 0x047E,
  20165. Otilde: 0x00D5,
  20166. Otildeacute: 0x1E4C,
  20167. Otildedieresis: 0x1E4E,
  20168. Otildesmall: 0xF7F5,
  20169. P: 0x0050,
  20170. Pacute: 0x1E54,
  20171. Pcircle: 0x24C5,
  20172. Pdotaccent: 0x1E56,
  20173. Pecyrillic: 0x041F,
  20174. Peharmenian: 0x054A,
  20175. Pemiddlehookcyrillic: 0x04A6,
  20176. Phi: 0x03A6,
  20177. Phook: 0x01A4,
  20178. Pi: 0x03A0,
  20179. Piwrarmenian: 0x0553,
  20180. Pmonospace: 0xFF30,
  20181. Psi: 0x03A8,
  20182. Psicyrillic: 0x0470,
  20183. Psmall: 0xF770,
  20184. Q: 0x0051,
  20185. Qcircle: 0x24C6,
  20186. Qmonospace: 0xFF31,
  20187. Qsmall: 0xF771,
  20188. R: 0x0052,
  20189. Raarmenian: 0x054C,
  20190. Racute: 0x0154,
  20191. Rcaron: 0x0158,
  20192. Rcedilla: 0x0156,
  20193. Rcircle: 0x24C7,
  20194. Rcommaaccent: 0x0156,
  20195. Rdblgrave: 0x0210,
  20196. Rdotaccent: 0x1E58,
  20197. Rdotbelow: 0x1E5A,
  20198. Rdotbelowmacron: 0x1E5C,
  20199. Reharmenian: 0x0550,
  20200. Rfraktur: 0x211C,
  20201. Rho: 0x03A1,
  20202. Ringsmall: 0xF6FC,
  20203. Rinvertedbreve: 0x0212,
  20204. Rlinebelow: 0x1E5E,
  20205. Rmonospace: 0xFF32,
  20206. Rsmall: 0xF772,
  20207. Rsmallinverted: 0x0281,
  20208. Rsmallinvertedsuperior: 0x02B6,
  20209. S: 0x0053,
  20210. SF010000: 0x250C,
  20211. SF020000: 0x2514,
  20212. SF030000: 0x2510,
  20213. SF040000: 0x2518,
  20214. SF050000: 0x253C,
  20215. SF060000: 0x252C,
  20216. SF070000: 0x2534,
  20217. SF080000: 0x251C,
  20218. SF090000: 0x2524,
  20219. SF100000: 0x2500,
  20220. SF110000: 0x2502,
  20221. SF190000: 0x2561,
  20222. SF200000: 0x2562,
  20223. SF210000: 0x2556,
  20224. SF220000: 0x2555,
  20225. SF230000: 0x2563,
  20226. SF240000: 0x2551,
  20227. SF250000: 0x2557,
  20228. SF260000: 0x255D,
  20229. SF270000: 0x255C,
  20230. SF280000: 0x255B,
  20231. SF360000: 0x255E,
  20232. SF370000: 0x255F,
  20233. SF380000: 0x255A,
  20234. SF390000: 0x2554,
  20235. SF400000: 0x2569,
  20236. SF410000: 0x2566,
  20237. SF420000: 0x2560,
  20238. SF430000: 0x2550,
  20239. SF440000: 0x256C,
  20240. SF450000: 0x2567,
  20241. SF460000: 0x2568,
  20242. SF470000: 0x2564,
  20243. SF480000: 0x2565,
  20244. SF490000: 0x2559,
  20245. SF500000: 0x2558,
  20246. SF510000: 0x2552,
  20247. SF520000: 0x2553,
  20248. SF530000: 0x256B,
  20249. SF540000: 0x256A,
  20250. Sacute: 0x015A,
  20251. Sacutedotaccent: 0x1E64,
  20252. Sampigreek: 0x03E0,
  20253. Scaron: 0x0160,
  20254. Scarondotaccent: 0x1E66,
  20255. Scaronsmall: 0xF6FD,
  20256. Scedilla: 0x015E,
  20257. Schwa: 0x018F,
  20258. Schwacyrillic: 0x04D8,
  20259. Schwadieresiscyrillic: 0x04DA,
  20260. Scircle: 0x24C8,
  20261. Scircumflex: 0x015C,
  20262. Scommaaccent: 0x0218,
  20263. Sdotaccent: 0x1E60,
  20264. Sdotbelow: 0x1E62,
  20265. Sdotbelowdotaccent: 0x1E68,
  20266. Seharmenian: 0x054D,
  20267. Sevenroman: 0x2166,
  20268. Shaarmenian: 0x0547,
  20269. Shacyrillic: 0x0428,
  20270. Shchacyrillic: 0x0429,
  20271. Sheicoptic: 0x03E2,
  20272. Shhacyrillic: 0x04BA,
  20273. Shimacoptic: 0x03EC,
  20274. Sigma: 0x03A3,
  20275. Sixroman: 0x2165,
  20276. Smonospace: 0xFF33,
  20277. Softsigncyrillic: 0x042C,
  20278. Ssmall: 0xF773,
  20279. Stigmagreek: 0x03DA,
  20280. T: 0x0054,
  20281. Tau: 0x03A4,
  20282. Tbar: 0x0166,
  20283. Tcaron: 0x0164,
  20284. Tcedilla: 0x0162,
  20285. Tcircle: 0x24C9,
  20286. Tcircumflexbelow: 0x1E70,
  20287. Tcommaaccent: 0x0162,
  20288. Tdotaccent: 0x1E6A,
  20289. Tdotbelow: 0x1E6C,
  20290. Tecyrillic: 0x0422,
  20291. Tedescendercyrillic: 0x04AC,
  20292. Tenroman: 0x2169,
  20293. Tetsecyrillic: 0x04B4,
  20294. Theta: 0x0398,
  20295. Thook: 0x01AC,
  20296. Thorn: 0x00DE,
  20297. Thornsmall: 0xF7FE,
  20298. Threeroman: 0x2162,
  20299. Tildesmall: 0xF6FE,
  20300. Tiwnarmenian: 0x054F,
  20301. Tlinebelow: 0x1E6E,
  20302. Tmonospace: 0xFF34,
  20303. Toarmenian: 0x0539,
  20304. Tonefive: 0x01BC,
  20305. Tonesix: 0x0184,
  20306. Tonetwo: 0x01A7,
  20307. Tretroflexhook: 0x01AE,
  20308. Tsecyrillic: 0x0426,
  20309. Tshecyrillic: 0x040B,
  20310. Tsmall: 0xF774,
  20311. Twelveroman: 0x216B,
  20312. Tworoman: 0x2161,
  20313. U: 0x0055,
  20314. Uacute: 0x00DA,
  20315. Uacutesmall: 0xF7FA,
  20316. Ubreve: 0x016C,
  20317. Ucaron: 0x01D3,
  20318. Ucircle: 0x24CA,
  20319. Ucircumflex: 0x00DB,
  20320. Ucircumflexbelow: 0x1E76,
  20321. Ucircumflexsmall: 0xF7FB,
  20322. Ucyrillic: 0x0423,
  20323. Udblacute: 0x0170,
  20324. Udblgrave: 0x0214,
  20325. Udieresis: 0x00DC,
  20326. Udieresisacute: 0x01D7,
  20327. Udieresisbelow: 0x1E72,
  20328. Udieresiscaron: 0x01D9,
  20329. Udieresiscyrillic: 0x04F0,
  20330. Udieresisgrave: 0x01DB,
  20331. Udieresismacron: 0x01D5,
  20332. Udieresissmall: 0xF7FC,
  20333. Udotbelow: 0x1EE4,
  20334. Ugrave: 0x00D9,
  20335. Ugravesmall: 0xF7F9,
  20336. Uhookabove: 0x1EE6,
  20337. Uhorn: 0x01AF,
  20338. Uhornacute: 0x1EE8,
  20339. Uhorndotbelow: 0x1EF0,
  20340. Uhorngrave: 0x1EEA,
  20341. Uhornhookabove: 0x1EEC,
  20342. Uhorntilde: 0x1EEE,
  20343. Uhungarumlaut: 0x0170,
  20344. Uhungarumlautcyrillic: 0x04F2,
  20345. Uinvertedbreve: 0x0216,
  20346. Ukcyrillic: 0x0478,
  20347. Umacron: 0x016A,
  20348. Umacroncyrillic: 0x04EE,
  20349. Umacrondieresis: 0x1E7A,
  20350. Umonospace: 0xFF35,
  20351. Uogonek: 0x0172,
  20352. Upsilon: 0x03A5,
  20353. Upsilon1: 0x03D2,
  20354. Upsilonacutehooksymbolgreek: 0x03D3,
  20355. Upsilonafrican: 0x01B1,
  20356. Upsilondieresis: 0x03AB,
  20357. Upsilondieresishooksymbolgreek: 0x03D4,
  20358. Upsilonhooksymbol: 0x03D2,
  20359. Upsilontonos: 0x038E,
  20360. Uring: 0x016E,
  20361. Ushortcyrillic: 0x040E,
  20362. Usmall: 0xF775,
  20363. Ustraightcyrillic: 0x04AE,
  20364. Ustraightstrokecyrillic: 0x04B0,
  20365. Utilde: 0x0168,
  20366. Utildeacute: 0x1E78,
  20367. Utildebelow: 0x1E74,
  20368. V: 0x0056,
  20369. Vcircle: 0x24CB,
  20370. Vdotbelow: 0x1E7E,
  20371. Vecyrillic: 0x0412,
  20372. Vewarmenian: 0x054E,
  20373. Vhook: 0x01B2,
  20374. Vmonospace: 0xFF36,
  20375. Voarmenian: 0x0548,
  20376. Vsmall: 0xF776,
  20377. Vtilde: 0x1E7C,
  20378. W: 0x0057,
  20379. Wacute: 0x1E82,
  20380. Wcircle: 0x24CC,
  20381. Wcircumflex: 0x0174,
  20382. Wdieresis: 0x1E84,
  20383. Wdotaccent: 0x1E86,
  20384. Wdotbelow: 0x1E88,
  20385. Wgrave: 0x1E80,
  20386. Wmonospace: 0xFF37,
  20387. Wsmall: 0xF777,
  20388. X: 0x0058,
  20389. Xcircle: 0x24CD,
  20390. Xdieresis: 0x1E8C,
  20391. Xdotaccent: 0x1E8A,
  20392. Xeharmenian: 0x053D,
  20393. Xi: 0x039E,
  20394. Xmonospace: 0xFF38,
  20395. Xsmall: 0xF778,
  20396. Y: 0x0059,
  20397. Yacute: 0x00DD,
  20398. Yacutesmall: 0xF7FD,
  20399. Yatcyrillic: 0x0462,
  20400. Ycircle: 0x24CE,
  20401. Ycircumflex: 0x0176,
  20402. Ydieresis: 0x0178,
  20403. Ydieresissmall: 0xF7FF,
  20404. Ydotaccent: 0x1E8E,
  20405. Ydotbelow: 0x1EF4,
  20406. Yericyrillic: 0x042B,
  20407. Yerudieresiscyrillic: 0x04F8,
  20408. Ygrave: 0x1EF2,
  20409. Yhook: 0x01B3,
  20410. Yhookabove: 0x1EF6,
  20411. Yiarmenian: 0x0545,
  20412. Yicyrillic: 0x0407,
  20413. Yiwnarmenian: 0x0552,
  20414. Ymonospace: 0xFF39,
  20415. Ysmall: 0xF779,
  20416. Ytilde: 0x1EF8,
  20417. Yusbigcyrillic: 0x046A,
  20418. Yusbigiotifiedcyrillic: 0x046C,
  20419. Yuslittlecyrillic: 0x0466,
  20420. Yuslittleiotifiedcyrillic: 0x0468,
  20421. Z: 0x005A,
  20422. Zaarmenian: 0x0536,
  20423. Zacute: 0x0179,
  20424. Zcaron: 0x017D,
  20425. Zcaronsmall: 0xF6FF,
  20426. Zcircle: 0x24CF,
  20427. Zcircumflex: 0x1E90,
  20428. Zdot: 0x017B,
  20429. Zdotaccent: 0x017B,
  20430. Zdotbelow: 0x1E92,
  20431. Zecyrillic: 0x0417,
  20432. Zedescendercyrillic: 0x0498,
  20433. Zedieresiscyrillic: 0x04DE,
  20434. Zeta: 0x0396,
  20435. Zhearmenian: 0x053A,
  20436. Zhebrevecyrillic: 0x04C1,
  20437. Zhecyrillic: 0x0416,
  20438. Zhedescendercyrillic: 0x0496,
  20439. Zhedieresiscyrillic: 0x04DC,
  20440. Zlinebelow: 0x1E94,
  20441. Zmonospace: 0xFF3A,
  20442. Zsmall: 0xF77A,
  20443. Zstroke: 0x01B5,
  20444. a: 0x0061,
  20445. aabengali: 0x0986,
  20446. aacute: 0x00E1,
  20447. aadeva: 0x0906,
  20448. aagujarati: 0x0A86,
  20449. aagurmukhi: 0x0A06,
  20450. aamatragurmukhi: 0x0A3E,
  20451. aarusquare: 0x3303,
  20452. aavowelsignbengali: 0x09BE,
  20453. aavowelsigndeva: 0x093E,
  20454. aavowelsigngujarati: 0x0ABE,
  20455. abbreviationmarkarmenian: 0x055F,
  20456. abbreviationsigndeva: 0x0970,
  20457. abengali: 0x0985,
  20458. abopomofo: 0x311A,
  20459. abreve: 0x0103,
  20460. abreveacute: 0x1EAF,
  20461. abrevecyrillic: 0x04D1,
  20462. abrevedotbelow: 0x1EB7,
  20463. abrevegrave: 0x1EB1,
  20464. abrevehookabove: 0x1EB3,
  20465. abrevetilde: 0x1EB5,
  20466. acaron: 0x01CE,
  20467. acircle: 0x24D0,
  20468. acircumflex: 0x00E2,
  20469. acircumflexacute: 0x1EA5,
  20470. acircumflexdotbelow: 0x1EAD,
  20471. acircumflexgrave: 0x1EA7,
  20472. acircumflexhookabove: 0x1EA9,
  20473. acircumflextilde: 0x1EAB,
  20474. acute: 0x00B4,
  20475. acutebelowcmb: 0x0317,
  20476. acutecmb: 0x0301,
  20477. acutecomb: 0x0301,
  20478. acutedeva: 0x0954,
  20479. acutelowmod: 0x02CF,
  20480. acutetonecmb: 0x0341,
  20481. acyrillic: 0x0430,
  20482. adblgrave: 0x0201,
  20483. addakgurmukhi: 0x0A71,
  20484. adeva: 0x0905,
  20485. adieresis: 0x00E4,
  20486. adieresiscyrillic: 0x04D3,
  20487. adieresismacron: 0x01DF,
  20488. adotbelow: 0x1EA1,
  20489. adotmacron: 0x01E1,
  20490. ae: 0x00E6,
  20491. aeacute: 0x01FD,
  20492. aekorean: 0x3150,
  20493. aemacron: 0x01E3,
  20494. afii00208: 0x2015,
  20495. afii08941: 0x20A4,
  20496. afii10017: 0x0410,
  20497. afii10018: 0x0411,
  20498. afii10019: 0x0412,
  20499. afii10020: 0x0413,
  20500. afii10021: 0x0414,
  20501. afii10022: 0x0415,
  20502. afii10023: 0x0401,
  20503. afii10024: 0x0416,
  20504. afii10025: 0x0417,
  20505. afii10026: 0x0418,
  20506. afii10027: 0x0419,
  20507. afii10028: 0x041A,
  20508. afii10029: 0x041B,
  20509. afii10030: 0x041C,
  20510. afii10031: 0x041D,
  20511. afii10032: 0x041E,
  20512. afii10033: 0x041F,
  20513. afii10034: 0x0420,
  20514. afii10035: 0x0421,
  20515. afii10036: 0x0422,
  20516. afii10037: 0x0423,
  20517. afii10038: 0x0424,
  20518. afii10039: 0x0425,
  20519. afii10040: 0x0426,
  20520. afii10041: 0x0427,
  20521. afii10042: 0x0428,
  20522. afii10043: 0x0429,
  20523. afii10044: 0x042A,
  20524. afii10045: 0x042B,
  20525. afii10046: 0x042C,
  20526. afii10047: 0x042D,
  20527. afii10048: 0x042E,
  20528. afii10049: 0x042F,
  20529. afii10050: 0x0490,
  20530. afii10051: 0x0402,
  20531. afii10052: 0x0403,
  20532. afii10053: 0x0404,
  20533. afii10054: 0x0405,
  20534. afii10055: 0x0406,
  20535. afii10056: 0x0407,
  20536. afii10057: 0x0408,
  20537. afii10058: 0x0409,
  20538. afii10059: 0x040A,
  20539. afii10060: 0x040B,
  20540. afii10061: 0x040C,
  20541. afii10062: 0x040E,
  20542. afii10063: 0xF6C4,
  20543. afii10064: 0xF6C5,
  20544. afii10065: 0x0430,
  20545. afii10066: 0x0431,
  20546. afii10067: 0x0432,
  20547. afii10068: 0x0433,
  20548. afii10069: 0x0434,
  20549. afii10070: 0x0435,
  20550. afii10071: 0x0451,
  20551. afii10072: 0x0436,
  20552. afii10073: 0x0437,
  20553. afii10074: 0x0438,
  20554. afii10075: 0x0439,
  20555. afii10076: 0x043A,
  20556. afii10077: 0x043B,
  20557. afii10078: 0x043C,
  20558. afii10079: 0x043D,
  20559. afii10080: 0x043E,
  20560. afii10081: 0x043F,
  20561. afii10082: 0x0440,
  20562. afii10083: 0x0441,
  20563. afii10084: 0x0442,
  20564. afii10085: 0x0443,
  20565. afii10086: 0x0444,
  20566. afii10087: 0x0445,
  20567. afii10088: 0x0446,
  20568. afii10089: 0x0447,
  20569. afii10090: 0x0448,
  20570. afii10091: 0x0449,
  20571. afii10092: 0x044A,
  20572. afii10093: 0x044B,
  20573. afii10094: 0x044C,
  20574. afii10095: 0x044D,
  20575. afii10096: 0x044E,
  20576. afii10097: 0x044F,
  20577. afii10098: 0x0491,
  20578. afii10099: 0x0452,
  20579. afii10100: 0x0453,
  20580. afii10101: 0x0454,
  20581. afii10102: 0x0455,
  20582. afii10103: 0x0456,
  20583. afii10104: 0x0457,
  20584. afii10105: 0x0458,
  20585. afii10106: 0x0459,
  20586. afii10107: 0x045A,
  20587. afii10108: 0x045B,
  20588. afii10109: 0x045C,
  20589. afii10110: 0x045E,
  20590. afii10145: 0x040F,
  20591. afii10146: 0x0462,
  20592. afii10147: 0x0472,
  20593. afii10148: 0x0474,
  20594. afii10192: 0xF6C6,
  20595. afii10193: 0x045F,
  20596. afii10194: 0x0463,
  20597. afii10195: 0x0473,
  20598. afii10196: 0x0475,
  20599. afii10831: 0xF6C7,
  20600. afii10832: 0xF6C8,
  20601. afii10846: 0x04D9,
  20602. afii299: 0x200E,
  20603. afii300: 0x200F,
  20604. afii301: 0x200D,
  20605. afii57381: 0x066A,
  20606. afii57388: 0x060C,
  20607. afii57392: 0x0660,
  20608. afii57393: 0x0661,
  20609. afii57394: 0x0662,
  20610. afii57395: 0x0663,
  20611. afii57396: 0x0664,
  20612. afii57397: 0x0665,
  20613. afii57398: 0x0666,
  20614. afii57399: 0x0667,
  20615. afii57400: 0x0668,
  20616. afii57401: 0x0669,
  20617. afii57403: 0x061B,
  20618. afii57407: 0x061F,
  20619. afii57409: 0x0621,
  20620. afii57410: 0x0622,
  20621. afii57411: 0x0623,
  20622. afii57412: 0x0624,
  20623. afii57413: 0x0625,
  20624. afii57414: 0x0626,
  20625. afii57415: 0x0627,
  20626. afii57416: 0x0628,
  20627. afii57417: 0x0629,
  20628. afii57418: 0x062A,
  20629. afii57419: 0x062B,
  20630. afii57420: 0x062C,
  20631. afii57421: 0x062D,
  20632. afii57422: 0x062E,
  20633. afii57423: 0x062F,
  20634. afii57424: 0x0630,
  20635. afii57425: 0x0631,
  20636. afii57426: 0x0632,
  20637. afii57427: 0x0633,
  20638. afii57428: 0x0634,
  20639. afii57429: 0x0635,
  20640. afii57430: 0x0636,
  20641. afii57431: 0x0637,
  20642. afii57432: 0x0638,
  20643. afii57433: 0x0639,
  20644. afii57434: 0x063A,
  20645. afii57440: 0x0640,
  20646. afii57441: 0x0641,
  20647. afii57442: 0x0642,
  20648. afii57443: 0x0643,
  20649. afii57444: 0x0644,
  20650. afii57445: 0x0645,
  20651. afii57446: 0x0646,
  20652. afii57448: 0x0648,
  20653. afii57449: 0x0649,
  20654. afii57450: 0x064A,
  20655. afii57451: 0x064B,
  20656. afii57452: 0x064C,
  20657. afii57453: 0x064D,
  20658. afii57454: 0x064E,
  20659. afii57455: 0x064F,
  20660. afii57456: 0x0650,
  20661. afii57457: 0x0651,
  20662. afii57458: 0x0652,
  20663. afii57470: 0x0647,
  20664. afii57505: 0x06A4,
  20665. afii57506: 0x067E,
  20666. afii57507: 0x0686,
  20667. afii57508: 0x0698,
  20668. afii57509: 0x06AF,
  20669. afii57511: 0x0679,
  20670. afii57512: 0x0688,
  20671. afii57513: 0x0691,
  20672. afii57514: 0x06BA,
  20673. afii57519: 0x06D2,
  20674. afii57534: 0x06D5,
  20675. afii57636: 0x20AA,
  20676. afii57645: 0x05BE,
  20677. afii57658: 0x05C3,
  20678. afii57664: 0x05D0,
  20679. afii57665: 0x05D1,
  20680. afii57666: 0x05D2,
  20681. afii57667: 0x05D3,
  20682. afii57668: 0x05D4,
  20683. afii57669: 0x05D5,
  20684. afii57670: 0x05D6,
  20685. afii57671: 0x05D7,
  20686. afii57672: 0x05D8,
  20687. afii57673: 0x05D9,
  20688. afii57674: 0x05DA,
  20689. afii57675: 0x05DB,
  20690. afii57676: 0x05DC,
  20691. afii57677: 0x05DD,
  20692. afii57678: 0x05DE,
  20693. afii57679: 0x05DF,
  20694. afii57680: 0x05E0,
  20695. afii57681: 0x05E1,
  20696. afii57682: 0x05E2,
  20697. afii57683: 0x05E3,
  20698. afii57684: 0x05E4,
  20699. afii57685: 0x05E5,
  20700. afii57686: 0x05E6,
  20701. afii57687: 0x05E7,
  20702. afii57688: 0x05E8,
  20703. afii57689: 0x05E9,
  20704. afii57690: 0x05EA,
  20705. afii57694: 0xFB2A,
  20706. afii57695: 0xFB2B,
  20707. afii57700: 0xFB4B,
  20708. afii57705: 0xFB1F,
  20709. afii57716: 0x05F0,
  20710. afii57717: 0x05F1,
  20711. afii57718: 0x05F2,
  20712. afii57723: 0xFB35,
  20713. afii57793: 0x05B4,
  20714. afii57794: 0x05B5,
  20715. afii57795: 0x05B6,
  20716. afii57796: 0x05BB,
  20717. afii57797: 0x05B8,
  20718. afii57798: 0x05B7,
  20719. afii57799: 0x05B0,
  20720. afii57800: 0x05B2,
  20721. afii57801: 0x05B1,
  20722. afii57802: 0x05B3,
  20723. afii57803: 0x05C2,
  20724. afii57804: 0x05C1,
  20725. afii57806: 0x05B9,
  20726. afii57807: 0x05BC,
  20727. afii57839: 0x05BD,
  20728. afii57841: 0x05BF,
  20729. afii57842: 0x05C0,
  20730. afii57929: 0x02BC,
  20731. afii61248: 0x2105,
  20732. afii61289: 0x2113,
  20733. afii61352: 0x2116,
  20734. afii61573: 0x202C,
  20735. afii61574: 0x202D,
  20736. afii61575: 0x202E,
  20737. afii61664: 0x200C,
  20738. afii63167: 0x066D,
  20739. afii64937: 0x02BD,
  20740. agrave: 0x00E0,
  20741. agujarati: 0x0A85,
  20742. agurmukhi: 0x0A05,
  20743. ahiragana: 0x3042,
  20744. ahookabove: 0x1EA3,
  20745. aibengali: 0x0990,
  20746. aibopomofo: 0x311E,
  20747. aideva: 0x0910,
  20748. aiecyrillic: 0x04D5,
  20749. aigujarati: 0x0A90,
  20750. aigurmukhi: 0x0A10,
  20751. aimatragurmukhi: 0x0A48,
  20752. ainarabic: 0x0639,
  20753. ainfinalarabic: 0xFECA,
  20754. aininitialarabic: 0xFECB,
  20755. ainmedialarabic: 0xFECC,
  20756. ainvertedbreve: 0x0203,
  20757. aivowelsignbengali: 0x09C8,
  20758. aivowelsigndeva: 0x0948,
  20759. aivowelsigngujarati: 0x0AC8,
  20760. akatakana: 0x30A2,
  20761. akatakanahalfwidth: 0xFF71,
  20762. akorean: 0x314F,
  20763. alef: 0x05D0,
  20764. alefarabic: 0x0627,
  20765. alefdageshhebrew: 0xFB30,
  20766. aleffinalarabic: 0xFE8E,
  20767. alefhamzaabovearabic: 0x0623,
  20768. alefhamzaabovefinalarabic: 0xFE84,
  20769. alefhamzabelowarabic: 0x0625,
  20770. alefhamzabelowfinalarabic: 0xFE88,
  20771. alefhebrew: 0x05D0,
  20772. aleflamedhebrew: 0xFB4F,
  20773. alefmaddaabovearabic: 0x0622,
  20774. alefmaddaabovefinalarabic: 0xFE82,
  20775. alefmaksuraarabic: 0x0649,
  20776. alefmaksurafinalarabic: 0xFEF0,
  20777. alefmaksurainitialarabic: 0xFEF3,
  20778. alefmaksuramedialarabic: 0xFEF4,
  20779. alefpatahhebrew: 0xFB2E,
  20780. alefqamatshebrew: 0xFB2F,
  20781. aleph: 0x2135,
  20782. allequal: 0x224C,
  20783. alpha: 0x03B1,
  20784. alphatonos: 0x03AC,
  20785. amacron: 0x0101,
  20786. amonospace: 0xFF41,
  20787. ampersand: 0x0026,
  20788. ampersandmonospace: 0xFF06,
  20789. ampersandsmall: 0xF726,
  20790. amsquare: 0x33C2,
  20791. anbopomofo: 0x3122,
  20792. angbopomofo: 0x3124,
  20793. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  20794. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  20795. angkhankhuthai: 0x0E5A,
  20796. angle: 0x2220,
  20797. anglebracketleft: 0x3008,
  20798. anglebracketleftvertical: 0xFE3F,
  20799. anglebracketright: 0x3009,
  20800. anglebracketrightvertical: 0xFE40,
  20801. angleleft: 0x2329,
  20802. angleright: 0x232A,
  20803. angstrom: 0x212B,
  20804. anoteleia: 0x0387,
  20805. anudattadeva: 0x0952,
  20806. anusvarabengali: 0x0982,
  20807. anusvaradeva: 0x0902,
  20808. anusvaragujarati: 0x0A82,
  20809. aogonek: 0x0105,
  20810. apaatosquare: 0x3300,
  20811. aparen: 0x249C,
  20812. apostrophearmenian: 0x055A,
  20813. apostrophemod: 0x02BC,
  20814. apple: 0xF8FF,
  20815. approaches: 0x2250,
  20816. approxequal: 0x2248,
  20817. approxequalorimage: 0x2252,
  20818. approximatelyequal: 0x2245,
  20819. araeaekorean: 0x318E,
  20820. araeakorean: 0x318D,
  20821. arc: 0x2312,
  20822. arighthalfring: 0x1E9A,
  20823. aring: 0x00E5,
  20824. aringacute: 0x01FB,
  20825. aringbelow: 0x1E01,
  20826. arrowboth: 0x2194,
  20827. arrowdashdown: 0x21E3,
  20828. arrowdashleft: 0x21E0,
  20829. arrowdashright: 0x21E2,
  20830. arrowdashup: 0x21E1,
  20831. arrowdblboth: 0x21D4,
  20832. arrowdbldown: 0x21D3,
  20833. arrowdblleft: 0x21D0,
  20834. arrowdblright: 0x21D2,
  20835. arrowdblup: 0x21D1,
  20836. arrowdown: 0x2193,
  20837. arrowdownleft: 0x2199,
  20838. arrowdownright: 0x2198,
  20839. arrowdownwhite: 0x21E9,
  20840. arrowheaddownmod: 0x02C5,
  20841. arrowheadleftmod: 0x02C2,
  20842. arrowheadrightmod: 0x02C3,
  20843. arrowheadupmod: 0x02C4,
  20844. arrowhorizex: 0xF8E7,
  20845. arrowleft: 0x2190,
  20846. arrowleftdbl: 0x21D0,
  20847. arrowleftdblstroke: 0x21CD,
  20848. arrowleftoverright: 0x21C6,
  20849. arrowleftwhite: 0x21E6,
  20850. arrowright: 0x2192,
  20851. arrowrightdblstroke: 0x21CF,
  20852. arrowrightheavy: 0x279E,
  20853. arrowrightoverleft: 0x21C4,
  20854. arrowrightwhite: 0x21E8,
  20855. arrowtableft: 0x21E4,
  20856. arrowtabright: 0x21E5,
  20857. arrowup: 0x2191,
  20858. arrowupdn: 0x2195,
  20859. arrowupdnbse: 0x21A8,
  20860. arrowupdownbase: 0x21A8,
  20861. arrowupleft: 0x2196,
  20862. arrowupleftofdown: 0x21C5,
  20863. arrowupright: 0x2197,
  20864. arrowupwhite: 0x21E7,
  20865. arrowvertex: 0xF8E6,
  20866. asciicircum: 0x005E,
  20867. asciicircummonospace: 0xFF3E,
  20868. asciitilde: 0x007E,
  20869. asciitildemonospace: 0xFF5E,
  20870. ascript: 0x0251,
  20871. ascriptturned: 0x0252,
  20872. asmallhiragana: 0x3041,
  20873. asmallkatakana: 0x30A1,
  20874. asmallkatakanahalfwidth: 0xFF67,
  20875. asterisk: 0x002A,
  20876. asteriskaltonearabic: 0x066D,
  20877. asteriskarabic: 0x066D,
  20878. asteriskmath: 0x2217,
  20879. asteriskmonospace: 0xFF0A,
  20880. asterisksmall: 0xFE61,
  20881. asterism: 0x2042,
  20882. asuperior: 0xF6E9,
  20883. asymptoticallyequal: 0x2243,
  20884. at: 0x0040,
  20885. atilde: 0x00E3,
  20886. atmonospace: 0xFF20,
  20887. atsmall: 0xFE6B,
  20888. aturned: 0x0250,
  20889. aubengali: 0x0994,
  20890. aubopomofo: 0x3120,
  20891. audeva: 0x0914,
  20892. augujarati: 0x0A94,
  20893. augurmukhi: 0x0A14,
  20894. aulengthmarkbengali: 0x09D7,
  20895. aumatragurmukhi: 0x0A4C,
  20896. auvowelsignbengali: 0x09CC,
  20897. auvowelsigndeva: 0x094C,
  20898. auvowelsigngujarati: 0x0ACC,
  20899. avagrahadeva: 0x093D,
  20900. aybarmenian: 0x0561,
  20901. ayin: 0x05E2,
  20902. ayinaltonehebrew: 0xFB20,
  20903. ayinhebrew: 0x05E2,
  20904. b: 0x0062,
  20905. babengali: 0x09AC,
  20906. backslash: 0x005C,
  20907. backslashmonospace: 0xFF3C,
  20908. badeva: 0x092C,
  20909. bagujarati: 0x0AAC,
  20910. bagurmukhi: 0x0A2C,
  20911. bahiragana: 0x3070,
  20912. bahtthai: 0x0E3F,
  20913. bakatakana: 0x30D0,
  20914. bar: 0x007C,
  20915. barmonospace: 0xFF5C,
  20916. bbopomofo: 0x3105,
  20917. bcircle: 0x24D1,
  20918. bdotaccent: 0x1E03,
  20919. bdotbelow: 0x1E05,
  20920. beamedsixteenthnotes: 0x266C,
  20921. because: 0x2235,
  20922. becyrillic: 0x0431,
  20923. beharabic: 0x0628,
  20924. behfinalarabic: 0xFE90,
  20925. behinitialarabic: 0xFE91,
  20926. behiragana: 0x3079,
  20927. behmedialarabic: 0xFE92,
  20928. behmeeminitialarabic: 0xFC9F,
  20929. behmeemisolatedarabic: 0xFC08,
  20930. behnoonfinalarabic: 0xFC6D,
  20931. bekatakana: 0x30D9,
  20932. benarmenian: 0x0562,
  20933. bet: 0x05D1,
  20934. beta: 0x03B2,
  20935. betasymbolgreek: 0x03D0,
  20936. betdagesh: 0xFB31,
  20937. betdageshhebrew: 0xFB31,
  20938. bethebrew: 0x05D1,
  20939. betrafehebrew: 0xFB4C,
  20940. bhabengali: 0x09AD,
  20941. bhadeva: 0x092D,
  20942. bhagujarati: 0x0AAD,
  20943. bhagurmukhi: 0x0A2D,
  20944. bhook: 0x0253,
  20945. bihiragana: 0x3073,
  20946. bikatakana: 0x30D3,
  20947. bilabialclick: 0x0298,
  20948. bindigurmukhi: 0x0A02,
  20949. birusquare: 0x3331,
  20950. blackcircle: 0x25CF,
  20951. blackdiamond: 0x25C6,
  20952. blackdownpointingtriangle: 0x25BC,
  20953. blackleftpointingpointer: 0x25C4,
  20954. blackleftpointingtriangle: 0x25C0,
  20955. blacklenticularbracketleft: 0x3010,
  20956. blacklenticularbracketleftvertical: 0xFE3B,
  20957. blacklenticularbracketright: 0x3011,
  20958. blacklenticularbracketrightvertical: 0xFE3C,
  20959. blacklowerlefttriangle: 0x25E3,
  20960. blacklowerrighttriangle: 0x25E2,
  20961. blackrectangle: 0x25AC,
  20962. blackrightpointingpointer: 0x25BA,
  20963. blackrightpointingtriangle: 0x25B6,
  20964. blacksmallsquare: 0x25AA,
  20965. blacksmilingface: 0x263B,
  20966. blacksquare: 0x25A0,
  20967. blackstar: 0x2605,
  20968. blackupperlefttriangle: 0x25E4,
  20969. blackupperrighttriangle: 0x25E5,
  20970. blackuppointingsmalltriangle: 0x25B4,
  20971. blackuppointingtriangle: 0x25B2,
  20972. blank: 0x2423,
  20973. blinebelow: 0x1E07,
  20974. block: 0x2588,
  20975. bmonospace: 0xFF42,
  20976. bobaimaithai: 0x0E1A,
  20977. bohiragana: 0x307C,
  20978. bokatakana: 0x30DC,
  20979. bparen: 0x249D,
  20980. bqsquare: 0x33C3,
  20981. braceex: 0xF8F4,
  20982. braceleft: 0x007B,
  20983. braceleftbt: 0xF8F3,
  20984. braceleftmid: 0xF8F2,
  20985. braceleftmonospace: 0xFF5B,
  20986. braceleftsmall: 0xFE5B,
  20987. bracelefttp: 0xF8F1,
  20988. braceleftvertical: 0xFE37,
  20989. braceright: 0x007D,
  20990. bracerightbt: 0xF8FE,
  20991. bracerightmid: 0xF8FD,
  20992. bracerightmonospace: 0xFF5D,
  20993. bracerightsmall: 0xFE5C,
  20994. bracerighttp: 0xF8FC,
  20995. bracerightvertical: 0xFE38,
  20996. bracketleft: 0x005B,
  20997. bracketleftbt: 0xF8F0,
  20998. bracketleftex: 0xF8EF,
  20999. bracketleftmonospace: 0xFF3B,
  21000. bracketlefttp: 0xF8EE,
  21001. bracketright: 0x005D,
  21002. bracketrightbt: 0xF8FB,
  21003. bracketrightex: 0xF8FA,
  21004. bracketrightmonospace: 0xFF3D,
  21005. bracketrighttp: 0xF8F9,
  21006. breve: 0x02D8,
  21007. brevebelowcmb: 0x032E,
  21008. brevecmb: 0x0306,
  21009. breveinvertedbelowcmb: 0x032F,
  21010. breveinvertedcmb: 0x0311,
  21011. breveinverteddoublecmb: 0x0361,
  21012. bridgebelowcmb: 0x032A,
  21013. bridgeinvertedbelowcmb: 0x033A,
  21014. brokenbar: 0x00A6,
  21015. bstroke: 0x0180,
  21016. bsuperior: 0xF6EA,
  21017. btopbar: 0x0183,
  21018. buhiragana: 0x3076,
  21019. bukatakana: 0x30D6,
  21020. bullet: 0x2022,
  21021. bulletinverse: 0x25D8,
  21022. bulletoperator: 0x2219,
  21023. bullseye: 0x25CE,
  21024. c: 0x0063,
  21025. caarmenian: 0x056E,
  21026. cabengali: 0x099A,
  21027. cacute: 0x0107,
  21028. cadeva: 0x091A,
  21029. cagujarati: 0x0A9A,
  21030. cagurmukhi: 0x0A1A,
  21031. calsquare: 0x3388,
  21032. candrabindubengali: 0x0981,
  21033. candrabinducmb: 0x0310,
  21034. candrabindudeva: 0x0901,
  21035. candrabindugujarati: 0x0A81,
  21036. capslock: 0x21EA,
  21037. careof: 0x2105,
  21038. caron: 0x02C7,
  21039. caronbelowcmb: 0x032C,
  21040. caroncmb: 0x030C,
  21041. carriagereturn: 0x21B5,
  21042. cbopomofo: 0x3118,
  21043. ccaron: 0x010D,
  21044. ccedilla: 0x00E7,
  21045. ccedillaacute: 0x1E09,
  21046. ccircle: 0x24D2,
  21047. ccircumflex: 0x0109,
  21048. ccurl: 0x0255,
  21049. cdot: 0x010B,
  21050. cdotaccent: 0x010B,
  21051. cdsquare: 0x33C5,
  21052. cedilla: 0x00B8,
  21053. cedillacmb: 0x0327,
  21054. cent: 0x00A2,
  21055. centigrade: 0x2103,
  21056. centinferior: 0xF6DF,
  21057. centmonospace: 0xFFE0,
  21058. centoldstyle: 0xF7A2,
  21059. centsuperior: 0xF6E0,
  21060. chaarmenian: 0x0579,
  21061. chabengali: 0x099B,
  21062. chadeva: 0x091B,
  21063. chagujarati: 0x0A9B,
  21064. chagurmukhi: 0x0A1B,
  21065. chbopomofo: 0x3114,
  21066. cheabkhasiancyrillic: 0x04BD,
  21067. checkmark: 0x2713,
  21068. checyrillic: 0x0447,
  21069. chedescenderabkhasiancyrillic: 0x04BF,
  21070. chedescendercyrillic: 0x04B7,
  21071. chedieresiscyrillic: 0x04F5,
  21072. cheharmenian: 0x0573,
  21073. chekhakassiancyrillic: 0x04CC,
  21074. cheverticalstrokecyrillic: 0x04B9,
  21075. chi: 0x03C7,
  21076. chieuchacirclekorean: 0x3277,
  21077. chieuchaparenkorean: 0x3217,
  21078. chieuchcirclekorean: 0x3269,
  21079. chieuchkorean: 0x314A,
  21080. chieuchparenkorean: 0x3209,
  21081. chochangthai: 0x0E0A,
  21082. chochanthai: 0x0E08,
  21083. chochingthai: 0x0E09,
  21084. chochoethai: 0x0E0C,
  21085. chook: 0x0188,
  21086. cieucacirclekorean: 0x3276,
  21087. cieucaparenkorean: 0x3216,
  21088. cieuccirclekorean: 0x3268,
  21089. cieuckorean: 0x3148,
  21090. cieucparenkorean: 0x3208,
  21091. cieucuparenkorean: 0x321C,
  21092. circle: 0x25CB,
  21093. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21094. circlemultiply: 0x2297,
  21095. circleot: 0x2299,
  21096. circleplus: 0x2295,
  21097. circlepostalmark: 0x3036,
  21098. circlewithlefthalfblack: 0x25D0,
  21099. circlewithrighthalfblack: 0x25D1,
  21100. circumflex: 0x02C6,
  21101. circumflexbelowcmb: 0x032D,
  21102. circumflexcmb: 0x0302,
  21103. clear: 0x2327,
  21104. clickalveolar: 0x01C2,
  21105. clickdental: 0x01C0,
  21106. clicklateral: 0x01C1,
  21107. clickretroflex: 0x01C3,
  21108. club: 0x2663,
  21109. clubsuitblack: 0x2663,
  21110. clubsuitwhite: 0x2667,
  21111. cmcubedsquare: 0x33A4,
  21112. cmonospace: 0xFF43,
  21113. cmsquaredsquare: 0x33A0,
  21114. coarmenian: 0x0581,
  21115. colon: 0x003A,
  21116. colonmonetary: 0x20A1,
  21117. colonmonospace: 0xFF1A,
  21118. colonsign: 0x20A1,
  21119. colonsmall: 0xFE55,
  21120. colontriangularhalfmod: 0x02D1,
  21121. colontriangularmod: 0x02D0,
  21122. comma: 0x002C,
  21123. commaabovecmb: 0x0313,
  21124. commaaboverightcmb: 0x0315,
  21125. commaaccent: 0xF6C3,
  21126. commaarabic: 0x060C,
  21127. commaarmenian: 0x055D,
  21128. commainferior: 0xF6E1,
  21129. commamonospace: 0xFF0C,
  21130. commareversedabovecmb: 0x0314,
  21131. commareversedmod: 0x02BD,
  21132. commasmall: 0xFE50,
  21133. commasuperior: 0xF6E2,
  21134. commaturnedabovecmb: 0x0312,
  21135. commaturnedmod: 0x02BB,
  21136. compass: 0x263C,
  21137. congruent: 0x2245,
  21138. contourintegral: 0x222E,
  21139. control: 0x2303,
  21140. controlACK: 0x0006,
  21141. controlBEL: 0x0007,
  21142. controlBS: 0x0008,
  21143. controlCAN: 0x0018,
  21144. controlCR: 0x000D,
  21145. controlDC1: 0x0011,
  21146. controlDC2: 0x0012,
  21147. controlDC3: 0x0013,
  21148. controlDC4: 0x0014,
  21149. controlDEL: 0x007F,
  21150. controlDLE: 0x0010,
  21151. controlEM: 0x0019,
  21152. controlENQ: 0x0005,
  21153. controlEOT: 0x0004,
  21154. controlESC: 0x001B,
  21155. controlETB: 0x0017,
  21156. controlETX: 0x0003,
  21157. controlFF: 0x000C,
  21158. controlFS: 0x001C,
  21159. controlGS: 0x001D,
  21160. controlHT: 0x0009,
  21161. controlLF: 0x000A,
  21162. controlNAK: 0x0015,
  21163. controlRS: 0x001E,
  21164. controlSI: 0x000F,
  21165. controlSO: 0x000E,
  21166. controlSOT: 0x0002,
  21167. controlSTX: 0x0001,
  21168. controlSUB: 0x001A,
  21169. controlSYN: 0x0016,
  21170. controlUS: 0x001F,
  21171. controlVT: 0x000B,
  21172. copyright: 0x00A9,
  21173. copyrightsans: 0xF8E9,
  21174. copyrightserif: 0xF6D9,
  21175. cornerbracketleft: 0x300C,
  21176. cornerbracketlefthalfwidth: 0xFF62,
  21177. cornerbracketleftvertical: 0xFE41,
  21178. cornerbracketright: 0x300D,
  21179. cornerbracketrighthalfwidth: 0xFF63,
  21180. cornerbracketrightvertical: 0xFE42,
  21181. corporationsquare: 0x337F,
  21182. cosquare: 0x33C7,
  21183. coverkgsquare: 0x33C6,
  21184. cparen: 0x249E,
  21185. cruzeiro: 0x20A2,
  21186. cstretched: 0x0297,
  21187. curlyand: 0x22CF,
  21188. curlyor: 0x22CE,
  21189. currency: 0x00A4,
  21190. cyrBreve: 0xF6D1,
  21191. cyrFlex: 0xF6D2,
  21192. cyrbreve: 0xF6D4,
  21193. cyrflex: 0xF6D5,
  21194. d: 0x0064,
  21195. daarmenian: 0x0564,
  21196. dabengali: 0x09A6,
  21197. dadarabic: 0x0636,
  21198. dadeva: 0x0926,
  21199. dadfinalarabic: 0xFEBE,
  21200. dadinitialarabic: 0xFEBF,
  21201. dadmedialarabic: 0xFEC0,
  21202. dagesh: 0x05BC,
  21203. dageshhebrew: 0x05BC,
  21204. dagger: 0x2020,
  21205. daggerdbl: 0x2021,
  21206. dagujarati: 0x0AA6,
  21207. dagurmukhi: 0x0A26,
  21208. dahiragana: 0x3060,
  21209. dakatakana: 0x30C0,
  21210. dalarabic: 0x062F,
  21211. dalet: 0x05D3,
  21212. daletdagesh: 0xFB33,
  21213. daletdageshhebrew: 0xFB33,
  21214. dalethebrew: 0x05D3,
  21215. dalfinalarabic: 0xFEAA,
  21216. dammaarabic: 0x064F,
  21217. dammalowarabic: 0x064F,
  21218. dammatanaltonearabic: 0x064C,
  21219. dammatanarabic: 0x064C,
  21220. danda: 0x0964,
  21221. dargahebrew: 0x05A7,
  21222. dargalefthebrew: 0x05A7,
  21223. dasiapneumatacyrilliccmb: 0x0485,
  21224. dblGrave: 0xF6D3,
  21225. dblanglebracketleft: 0x300A,
  21226. dblanglebracketleftvertical: 0xFE3D,
  21227. dblanglebracketright: 0x300B,
  21228. dblanglebracketrightvertical: 0xFE3E,
  21229. dblarchinvertedbelowcmb: 0x032B,
  21230. dblarrowleft: 0x21D4,
  21231. dblarrowright: 0x21D2,
  21232. dbldanda: 0x0965,
  21233. dblgrave: 0xF6D6,
  21234. dblgravecmb: 0x030F,
  21235. dblintegral: 0x222C,
  21236. dbllowline: 0x2017,
  21237. dbllowlinecmb: 0x0333,
  21238. dbloverlinecmb: 0x033F,
  21239. dblprimemod: 0x02BA,
  21240. dblverticalbar: 0x2016,
  21241. dblverticallineabovecmb: 0x030E,
  21242. dbopomofo: 0x3109,
  21243. dbsquare: 0x33C8,
  21244. dcaron: 0x010F,
  21245. dcedilla: 0x1E11,
  21246. dcircle: 0x24D3,
  21247. dcircumflexbelow: 0x1E13,
  21248. dcroat: 0x0111,
  21249. ddabengali: 0x09A1,
  21250. ddadeva: 0x0921,
  21251. ddagujarati: 0x0AA1,
  21252. ddagurmukhi: 0x0A21,
  21253. ddalarabic: 0x0688,
  21254. ddalfinalarabic: 0xFB89,
  21255. dddhadeva: 0x095C,
  21256. ddhabengali: 0x09A2,
  21257. ddhadeva: 0x0922,
  21258. ddhagujarati: 0x0AA2,
  21259. ddhagurmukhi: 0x0A22,
  21260. ddotaccent: 0x1E0B,
  21261. ddotbelow: 0x1E0D,
  21262. decimalseparatorarabic: 0x066B,
  21263. decimalseparatorpersian: 0x066B,
  21264. decyrillic: 0x0434,
  21265. degree: 0x00B0,
  21266. dehihebrew: 0x05AD,
  21267. dehiragana: 0x3067,
  21268. deicoptic: 0x03EF,
  21269. dekatakana: 0x30C7,
  21270. deleteleft: 0x232B,
  21271. deleteright: 0x2326,
  21272. delta: 0x03B4,
  21273. deltaturned: 0x018D,
  21274. denominatorminusonenumeratorbengali: 0x09F8,
  21275. dezh: 0x02A4,
  21276. dhabengali: 0x09A7,
  21277. dhadeva: 0x0927,
  21278. dhagujarati: 0x0AA7,
  21279. dhagurmukhi: 0x0A27,
  21280. dhook: 0x0257,
  21281. dialytikatonos: 0x0385,
  21282. dialytikatonoscmb: 0x0344,
  21283. diamond: 0x2666,
  21284. diamondsuitwhite: 0x2662,
  21285. dieresis: 0x00A8,
  21286. dieresisacute: 0xF6D7,
  21287. dieresisbelowcmb: 0x0324,
  21288. dieresiscmb: 0x0308,
  21289. dieresisgrave: 0xF6D8,
  21290. dieresistonos: 0x0385,
  21291. dihiragana: 0x3062,
  21292. dikatakana: 0x30C2,
  21293. dittomark: 0x3003,
  21294. divide: 0x00F7,
  21295. divides: 0x2223,
  21296. divisionslash: 0x2215,
  21297. djecyrillic: 0x0452,
  21298. dkshade: 0x2593,
  21299. dlinebelow: 0x1E0F,
  21300. dlsquare: 0x3397,
  21301. dmacron: 0x0111,
  21302. dmonospace: 0xFF44,
  21303. dnblock: 0x2584,
  21304. dochadathai: 0x0E0E,
  21305. dodekthai: 0x0E14,
  21306. dohiragana: 0x3069,
  21307. dokatakana: 0x30C9,
  21308. dollar: 0x0024,
  21309. dollarinferior: 0xF6E3,
  21310. dollarmonospace: 0xFF04,
  21311. dollaroldstyle: 0xF724,
  21312. dollarsmall: 0xFE69,
  21313. dollarsuperior: 0xF6E4,
  21314. dong: 0x20AB,
  21315. dorusquare: 0x3326,
  21316. dotaccent: 0x02D9,
  21317. dotaccentcmb: 0x0307,
  21318. dotbelowcmb: 0x0323,
  21319. dotbelowcomb: 0x0323,
  21320. dotkatakana: 0x30FB,
  21321. dotlessi: 0x0131,
  21322. dotlessj: 0xF6BE,
  21323. dotlessjstrokehook: 0x0284,
  21324. dotmath: 0x22C5,
  21325. dottedcircle: 0x25CC,
  21326. doubleyodpatah: 0xFB1F,
  21327. doubleyodpatahhebrew: 0xFB1F,
  21328. downtackbelowcmb: 0x031E,
  21329. downtackmod: 0x02D5,
  21330. dparen: 0x249F,
  21331. dsuperior: 0xF6EB,
  21332. dtail: 0x0256,
  21333. dtopbar: 0x018C,
  21334. duhiragana: 0x3065,
  21335. dukatakana: 0x30C5,
  21336. dz: 0x01F3,
  21337. dzaltone: 0x02A3,
  21338. dzcaron: 0x01C6,
  21339. dzcurl: 0x02A5,
  21340. dzeabkhasiancyrillic: 0x04E1,
  21341. dzecyrillic: 0x0455,
  21342. dzhecyrillic: 0x045F,
  21343. e: 0x0065,
  21344. eacute: 0x00E9,
  21345. earth: 0x2641,
  21346. ebengali: 0x098F,
  21347. ebopomofo: 0x311C,
  21348. ebreve: 0x0115,
  21349. ecandradeva: 0x090D,
  21350. ecandragujarati: 0x0A8D,
  21351. ecandravowelsigndeva: 0x0945,
  21352. ecandravowelsigngujarati: 0x0AC5,
  21353. ecaron: 0x011B,
  21354. ecedillabreve: 0x1E1D,
  21355. echarmenian: 0x0565,
  21356. echyiwnarmenian: 0x0587,
  21357. ecircle: 0x24D4,
  21358. ecircumflex: 0x00EA,
  21359. ecircumflexacute: 0x1EBF,
  21360. ecircumflexbelow: 0x1E19,
  21361. ecircumflexdotbelow: 0x1EC7,
  21362. ecircumflexgrave: 0x1EC1,
  21363. ecircumflexhookabove: 0x1EC3,
  21364. ecircumflextilde: 0x1EC5,
  21365. ecyrillic: 0x0454,
  21366. edblgrave: 0x0205,
  21367. edeva: 0x090F,
  21368. edieresis: 0x00EB,
  21369. edot: 0x0117,
  21370. edotaccent: 0x0117,
  21371. edotbelow: 0x1EB9,
  21372. eegurmukhi: 0x0A0F,
  21373. eematragurmukhi: 0x0A47,
  21374. efcyrillic: 0x0444,
  21375. egrave: 0x00E8,
  21376. egujarati: 0x0A8F,
  21377. eharmenian: 0x0567,
  21378. ehbopomofo: 0x311D,
  21379. ehiragana: 0x3048,
  21380. ehookabove: 0x1EBB,
  21381. eibopomofo: 0x311F,
  21382. eight: 0x0038,
  21383. eightarabic: 0x0668,
  21384. eightbengali: 0x09EE,
  21385. eightcircle: 0x2467,
  21386. eightcircleinversesansserif: 0x2791,
  21387. eightdeva: 0x096E,
  21388. eighteencircle: 0x2471,
  21389. eighteenparen: 0x2485,
  21390. eighteenperiod: 0x2499,
  21391. eightgujarati: 0x0AEE,
  21392. eightgurmukhi: 0x0A6E,
  21393. eighthackarabic: 0x0668,
  21394. eighthangzhou: 0x3028,
  21395. eighthnotebeamed: 0x266B,
  21396. eightideographicparen: 0x3227,
  21397. eightinferior: 0x2088,
  21398. eightmonospace: 0xFF18,
  21399. eightoldstyle: 0xF738,
  21400. eightparen: 0x247B,
  21401. eightperiod: 0x248F,
  21402. eightpersian: 0x06F8,
  21403. eightroman: 0x2177,
  21404. eightsuperior: 0x2078,
  21405. eightthai: 0x0E58,
  21406. einvertedbreve: 0x0207,
  21407. eiotifiedcyrillic: 0x0465,
  21408. ekatakana: 0x30A8,
  21409. ekatakanahalfwidth: 0xFF74,
  21410. ekonkargurmukhi: 0x0A74,
  21411. ekorean: 0x3154,
  21412. elcyrillic: 0x043B,
  21413. element: 0x2208,
  21414. elevencircle: 0x246A,
  21415. elevenparen: 0x247E,
  21416. elevenperiod: 0x2492,
  21417. elevenroman: 0x217A,
  21418. ellipsis: 0x2026,
  21419. ellipsisvertical: 0x22EE,
  21420. emacron: 0x0113,
  21421. emacronacute: 0x1E17,
  21422. emacrongrave: 0x1E15,
  21423. emcyrillic: 0x043C,
  21424. emdash: 0x2014,
  21425. emdashvertical: 0xFE31,
  21426. emonospace: 0xFF45,
  21427. emphasismarkarmenian: 0x055B,
  21428. emptyset: 0x2205,
  21429. enbopomofo: 0x3123,
  21430. encyrillic: 0x043D,
  21431. endash: 0x2013,
  21432. endashvertical: 0xFE32,
  21433. endescendercyrillic: 0x04A3,
  21434. eng: 0x014B,
  21435. engbopomofo: 0x3125,
  21436. enghecyrillic: 0x04A5,
  21437. enhookcyrillic: 0x04C8,
  21438. enspace: 0x2002,
  21439. eogonek: 0x0119,
  21440. eokorean: 0x3153,
  21441. eopen: 0x025B,
  21442. eopenclosed: 0x029A,
  21443. eopenreversed: 0x025C,
  21444. eopenreversedclosed: 0x025E,
  21445. eopenreversedhook: 0x025D,
  21446. eparen: 0x24A0,
  21447. epsilon: 0x03B5,
  21448. epsilontonos: 0x03AD,
  21449. equal: 0x003D,
  21450. equalmonospace: 0xFF1D,
  21451. equalsmall: 0xFE66,
  21452. equalsuperior: 0x207C,
  21453. equivalence: 0x2261,
  21454. erbopomofo: 0x3126,
  21455. ercyrillic: 0x0440,
  21456. ereversed: 0x0258,
  21457. ereversedcyrillic: 0x044D,
  21458. escyrillic: 0x0441,
  21459. esdescendercyrillic: 0x04AB,
  21460. esh: 0x0283,
  21461. eshcurl: 0x0286,
  21462. eshortdeva: 0x090E,
  21463. eshortvowelsigndeva: 0x0946,
  21464. eshreversedloop: 0x01AA,
  21465. eshsquatreversed: 0x0285,
  21466. esmallhiragana: 0x3047,
  21467. esmallkatakana: 0x30A7,
  21468. esmallkatakanahalfwidth: 0xFF6A,
  21469. estimated: 0x212E,
  21470. esuperior: 0xF6EC,
  21471. eta: 0x03B7,
  21472. etarmenian: 0x0568,
  21473. etatonos: 0x03AE,
  21474. eth: 0x00F0,
  21475. etilde: 0x1EBD,
  21476. etildebelow: 0x1E1B,
  21477. etnahtafoukhhebrew: 0x0591,
  21478. etnahtafoukhlefthebrew: 0x0591,
  21479. etnahtahebrew: 0x0591,
  21480. etnahtalefthebrew: 0x0591,
  21481. eturned: 0x01DD,
  21482. eukorean: 0x3161,
  21483. euro: 0x20AC,
  21484. evowelsignbengali: 0x09C7,
  21485. evowelsigndeva: 0x0947,
  21486. evowelsigngujarati: 0x0AC7,
  21487. exclam: 0x0021,
  21488. exclamarmenian: 0x055C,
  21489. exclamdbl: 0x203C,
  21490. exclamdown: 0x00A1,
  21491. exclamdownsmall: 0xF7A1,
  21492. exclammonospace: 0xFF01,
  21493. exclamsmall: 0xF721,
  21494. existential: 0x2203,
  21495. ezh: 0x0292,
  21496. ezhcaron: 0x01EF,
  21497. ezhcurl: 0x0293,
  21498. ezhreversed: 0x01B9,
  21499. ezhtail: 0x01BA,
  21500. f: 0x0066,
  21501. fadeva: 0x095E,
  21502. fagurmukhi: 0x0A5E,
  21503. fahrenheit: 0x2109,
  21504. fathaarabic: 0x064E,
  21505. fathalowarabic: 0x064E,
  21506. fathatanarabic: 0x064B,
  21507. fbopomofo: 0x3108,
  21508. fcircle: 0x24D5,
  21509. fdotaccent: 0x1E1F,
  21510. feharabic: 0x0641,
  21511. feharmenian: 0x0586,
  21512. fehfinalarabic: 0xFED2,
  21513. fehinitialarabic: 0xFED3,
  21514. fehmedialarabic: 0xFED4,
  21515. feicoptic: 0x03E5,
  21516. female: 0x2640,
  21517. ff: 0xFB00,
  21518. ffi: 0xFB03,
  21519. ffl: 0xFB04,
  21520. fi: 0xFB01,
  21521. fifteencircle: 0x246E,
  21522. fifteenparen: 0x2482,
  21523. fifteenperiod: 0x2496,
  21524. figuredash: 0x2012,
  21525. filledbox: 0x25A0,
  21526. filledrect: 0x25AC,
  21527. finalkaf: 0x05DA,
  21528. finalkafdagesh: 0xFB3A,
  21529. finalkafdageshhebrew: 0xFB3A,
  21530. finalkafhebrew: 0x05DA,
  21531. finalmem: 0x05DD,
  21532. finalmemhebrew: 0x05DD,
  21533. finalnun: 0x05DF,
  21534. finalnunhebrew: 0x05DF,
  21535. finalpe: 0x05E3,
  21536. finalpehebrew: 0x05E3,
  21537. finaltsadi: 0x05E5,
  21538. finaltsadihebrew: 0x05E5,
  21539. firsttonechinese: 0x02C9,
  21540. fisheye: 0x25C9,
  21541. fitacyrillic: 0x0473,
  21542. five: 0x0035,
  21543. fivearabic: 0x0665,
  21544. fivebengali: 0x09EB,
  21545. fivecircle: 0x2464,
  21546. fivecircleinversesansserif: 0x278E,
  21547. fivedeva: 0x096B,
  21548. fiveeighths: 0x215D,
  21549. fivegujarati: 0x0AEB,
  21550. fivegurmukhi: 0x0A6B,
  21551. fivehackarabic: 0x0665,
  21552. fivehangzhou: 0x3025,
  21553. fiveideographicparen: 0x3224,
  21554. fiveinferior: 0x2085,
  21555. fivemonospace: 0xFF15,
  21556. fiveoldstyle: 0xF735,
  21557. fiveparen: 0x2478,
  21558. fiveperiod: 0x248C,
  21559. fivepersian: 0x06F5,
  21560. fiveroman: 0x2174,
  21561. fivesuperior: 0x2075,
  21562. fivethai: 0x0E55,
  21563. fl: 0xFB02,
  21564. florin: 0x0192,
  21565. fmonospace: 0xFF46,
  21566. fmsquare: 0x3399,
  21567. fofanthai: 0x0E1F,
  21568. fofathai: 0x0E1D,
  21569. fongmanthai: 0x0E4F,
  21570. forall: 0x2200,
  21571. four: 0x0034,
  21572. fourarabic: 0x0664,
  21573. fourbengali: 0x09EA,
  21574. fourcircle: 0x2463,
  21575. fourcircleinversesansserif: 0x278D,
  21576. fourdeva: 0x096A,
  21577. fourgujarati: 0x0AEA,
  21578. fourgurmukhi: 0x0A6A,
  21579. fourhackarabic: 0x0664,
  21580. fourhangzhou: 0x3024,
  21581. fourideographicparen: 0x3223,
  21582. fourinferior: 0x2084,
  21583. fourmonospace: 0xFF14,
  21584. fournumeratorbengali: 0x09F7,
  21585. fouroldstyle: 0xF734,
  21586. fourparen: 0x2477,
  21587. fourperiod: 0x248B,
  21588. fourpersian: 0x06F4,
  21589. fourroman: 0x2173,
  21590. foursuperior: 0x2074,
  21591. fourteencircle: 0x246D,
  21592. fourteenparen: 0x2481,
  21593. fourteenperiod: 0x2495,
  21594. fourthai: 0x0E54,
  21595. fourthtonechinese: 0x02CB,
  21596. fparen: 0x24A1,
  21597. fraction: 0x2044,
  21598. franc: 0x20A3,
  21599. g: 0x0067,
  21600. gabengali: 0x0997,
  21601. gacute: 0x01F5,
  21602. gadeva: 0x0917,
  21603. gafarabic: 0x06AF,
  21604. gaffinalarabic: 0xFB93,
  21605. gafinitialarabic: 0xFB94,
  21606. gafmedialarabic: 0xFB95,
  21607. gagujarati: 0x0A97,
  21608. gagurmukhi: 0x0A17,
  21609. gahiragana: 0x304C,
  21610. gakatakana: 0x30AC,
  21611. gamma: 0x03B3,
  21612. gammalatinsmall: 0x0263,
  21613. gammasuperior: 0x02E0,
  21614. gangiacoptic: 0x03EB,
  21615. gbopomofo: 0x310D,
  21616. gbreve: 0x011F,
  21617. gcaron: 0x01E7,
  21618. gcedilla: 0x0123,
  21619. gcircle: 0x24D6,
  21620. gcircumflex: 0x011D,
  21621. gcommaaccent: 0x0123,
  21622. gdot: 0x0121,
  21623. gdotaccent: 0x0121,
  21624. gecyrillic: 0x0433,
  21625. gehiragana: 0x3052,
  21626. gekatakana: 0x30B2,
  21627. geometricallyequal: 0x2251,
  21628. gereshaccenthebrew: 0x059C,
  21629. gereshhebrew: 0x05F3,
  21630. gereshmuqdamhebrew: 0x059D,
  21631. germandbls: 0x00DF,
  21632. gershayimaccenthebrew: 0x059E,
  21633. gershayimhebrew: 0x05F4,
  21634. getamark: 0x3013,
  21635. ghabengali: 0x0998,
  21636. ghadarmenian: 0x0572,
  21637. ghadeva: 0x0918,
  21638. ghagujarati: 0x0A98,
  21639. ghagurmukhi: 0x0A18,
  21640. ghainarabic: 0x063A,
  21641. ghainfinalarabic: 0xFECE,
  21642. ghaininitialarabic: 0xFECF,
  21643. ghainmedialarabic: 0xFED0,
  21644. ghemiddlehookcyrillic: 0x0495,
  21645. ghestrokecyrillic: 0x0493,
  21646. gheupturncyrillic: 0x0491,
  21647. ghhadeva: 0x095A,
  21648. ghhagurmukhi: 0x0A5A,
  21649. ghook: 0x0260,
  21650. ghzsquare: 0x3393,
  21651. gihiragana: 0x304E,
  21652. gikatakana: 0x30AE,
  21653. gimarmenian: 0x0563,
  21654. gimel: 0x05D2,
  21655. gimeldagesh: 0xFB32,
  21656. gimeldageshhebrew: 0xFB32,
  21657. gimelhebrew: 0x05D2,
  21658. gjecyrillic: 0x0453,
  21659. glottalinvertedstroke: 0x01BE,
  21660. glottalstop: 0x0294,
  21661. glottalstopinverted: 0x0296,
  21662. glottalstopmod: 0x02C0,
  21663. glottalstopreversed: 0x0295,
  21664. glottalstopreversedmod: 0x02C1,
  21665. glottalstopreversedsuperior: 0x02E4,
  21666. glottalstopstroke: 0x02A1,
  21667. glottalstopstrokereversed: 0x02A2,
  21668. gmacron: 0x1E21,
  21669. gmonospace: 0xFF47,
  21670. gohiragana: 0x3054,
  21671. gokatakana: 0x30B4,
  21672. gparen: 0x24A2,
  21673. gpasquare: 0x33AC,
  21674. gradient: 0x2207,
  21675. grave: 0x0060,
  21676. gravebelowcmb: 0x0316,
  21677. gravecmb: 0x0300,
  21678. gravecomb: 0x0300,
  21679. gravedeva: 0x0953,
  21680. gravelowmod: 0x02CE,
  21681. gravemonospace: 0xFF40,
  21682. gravetonecmb: 0x0340,
  21683. greater: 0x003E,
  21684. greaterequal: 0x2265,
  21685. greaterequalorless: 0x22DB,
  21686. greatermonospace: 0xFF1E,
  21687. greaterorequivalent: 0x2273,
  21688. greaterorless: 0x2277,
  21689. greateroverequal: 0x2267,
  21690. greatersmall: 0xFE65,
  21691. gscript: 0x0261,
  21692. gstroke: 0x01E5,
  21693. guhiragana: 0x3050,
  21694. guillemotleft: 0x00AB,
  21695. guillemotright: 0x00BB,
  21696. guilsinglleft: 0x2039,
  21697. guilsinglright: 0x203A,
  21698. gukatakana: 0x30B0,
  21699. guramusquare: 0x3318,
  21700. gysquare: 0x33C9,
  21701. h: 0x0068,
  21702. haabkhasiancyrillic: 0x04A9,
  21703. haaltonearabic: 0x06C1,
  21704. habengali: 0x09B9,
  21705. hadescendercyrillic: 0x04B3,
  21706. hadeva: 0x0939,
  21707. hagujarati: 0x0AB9,
  21708. hagurmukhi: 0x0A39,
  21709. haharabic: 0x062D,
  21710. hahfinalarabic: 0xFEA2,
  21711. hahinitialarabic: 0xFEA3,
  21712. hahiragana: 0x306F,
  21713. hahmedialarabic: 0xFEA4,
  21714. haitusquare: 0x332A,
  21715. hakatakana: 0x30CF,
  21716. hakatakanahalfwidth: 0xFF8A,
  21717. halantgurmukhi: 0x0A4D,
  21718. hamzaarabic: 0x0621,
  21719. hamzalowarabic: 0x0621,
  21720. hangulfiller: 0x3164,
  21721. hardsigncyrillic: 0x044A,
  21722. harpoonleftbarbup: 0x21BC,
  21723. harpoonrightbarbup: 0x21C0,
  21724. hasquare: 0x33CA,
  21725. hatafpatah: 0x05B2,
  21726. hatafpatah16: 0x05B2,
  21727. hatafpatah23: 0x05B2,
  21728. hatafpatah2f: 0x05B2,
  21729. hatafpatahhebrew: 0x05B2,
  21730. hatafpatahnarrowhebrew: 0x05B2,
  21731. hatafpatahquarterhebrew: 0x05B2,
  21732. hatafpatahwidehebrew: 0x05B2,
  21733. hatafqamats: 0x05B3,
  21734. hatafqamats1b: 0x05B3,
  21735. hatafqamats28: 0x05B3,
  21736. hatafqamats34: 0x05B3,
  21737. hatafqamatshebrew: 0x05B3,
  21738. hatafqamatsnarrowhebrew: 0x05B3,
  21739. hatafqamatsquarterhebrew: 0x05B3,
  21740. hatafqamatswidehebrew: 0x05B3,
  21741. hatafsegol: 0x05B1,
  21742. hatafsegol17: 0x05B1,
  21743. hatafsegol24: 0x05B1,
  21744. hatafsegol30: 0x05B1,
  21745. hatafsegolhebrew: 0x05B1,
  21746. hatafsegolnarrowhebrew: 0x05B1,
  21747. hatafsegolquarterhebrew: 0x05B1,
  21748. hatafsegolwidehebrew: 0x05B1,
  21749. hbar: 0x0127,
  21750. hbopomofo: 0x310F,
  21751. hbrevebelow: 0x1E2B,
  21752. hcedilla: 0x1E29,
  21753. hcircle: 0x24D7,
  21754. hcircumflex: 0x0125,
  21755. hdieresis: 0x1E27,
  21756. hdotaccent: 0x1E23,
  21757. hdotbelow: 0x1E25,
  21758. he: 0x05D4,
  21759. heart: 0x2665,
  21760. heartsuitblack: 0x2665,
  21761. heartsuitwhite: 0x2661,
  21762. hedagesh: 0xFB34,
  21763. hedageshhebrew: 0xFB34,
  21764. hehaltonearabic: 0x06C1,
  21765. heharabic: 0x0647,
  21766. hehebrew: 0x05D4,
  21767. hehfinalaltonearabic: 0xFBA7,
  21768. hehfinalalttwoarabic: 0xFEEA,
  21769. hehfinalarabic: 0xFEEA,
  21770. hehhamzaabovefinalarabic: 0xFBA5,
  21771. hehhamzaaboveisolatedarabic: 0xFBA4,
  21772. hehinitialaltonearabic: 0xFBA8,
  21773. hehinitialarabic: 0xFEEB,
  21774. hehiragana: 0x3078,
  21775. hehmedialaltonearabic: 0xFBA9,
  21776. hehmedialarabic: 0xFEEC,
  21777. heiseierasquare: 0x337B,
  21778. hekatakana: 0x30D8,
  21779. hekatakanahalfwidth: 0xFF8D,
  21780. hekutaarusquare: 0x3336,
  21781. henghook: 0x0267,
  21782. herutusquare: 0x3339,
  21783. het: 0x05D7,
  21784. hethebrew: 0x05D7,
  21785. hhook: 0x0266,
  21786. hhooksuperior: 0x02B1,
  21787. hieuhacirclekorean: 0x327B,
  21788. hieuhaparenkorean: 0x321B,
  21789. hieuhcirclekorean: 0x326D,
  21790. hieuhkorean: 0x314E,
  21791. hieuhparenkorean: 0x320D,
  21792. hihiragana: 0x3072,
  21793. hikatakana: 0x30D2,
  21794. hikatakanahalfwidth: 0xFF8B,
  21795. hiriq: 0x05B4,
  21796. hiriq14: 0x05B4,
  21797. hiriq21: 0x05B4,
  21798. hiriq2d: 0x05B4,
  21799. hiriqhebrew: 0x05B4,
  21800. hiriqnarrowhebrew: 0x05B4,
  21801. hiriqquarterhebrew: 0x05B4,
  21802. hiriqwidehebrew: 0x05B4,
  21803. hlinebelow: 0x1E96,
  21804. hmonospace: 0xFF48,
  21805. hoarmenian: 0x0570,
  21806. hohipthai: 0x0E2B,
  21807. hohiragana: 0x307B,
  21808. hokatakana: 0x30DB,
  21809. hokatakanahalfwidth: 0xFF8E,
  21810. holam: 0x05B9,
  21811. holam19: 0x05B9,
  21812. holam26: 0x05B9,
  21813. holam32: 0x05B9,
  21814. holamhebrew: 0x05B9,
  21815. holamnarrowhebrew: 0x05B9,
  21816. holamquarterhebrew: 0x05B9,
  21817. holamwidehebrew: 0x05B9,
  21818. honokhukthai: 0x0E2E,
  21819. hookabovecomb: 0x0309,
  21820. hookcmb: 0x0309,
  21821. hookpalatalizedbelowcmb: 0x0321,
  21822. hookretroflexbelowcmb: 0x0322,
  21823. hoonsquare: 0x3342,
  21824. horicoptic: 0x03E9,
  21825. horizontalbar: 0x2015,
  21826. horncmb: 0x031B,
  21827. hotsprings: 0x2668,
  21828. house: 0x2302,
  21829. hparen: 0x24A3,
  21830. hsuperior: 0x02B0,
  21831. hturned: 0x0265,
  21832. huhiragana: 0x3075,
  21833. huiitosquare: 0x3333,
  21834. hukatakana: 0x30D5,
  21835. hukatakanahalfwidth: 0xFF8C,
  21836. hungarumlaut: 0x02DD,
  21837. hungarumlautcmb: 0x030B,
  21838. hv: 0x0195,
  21839. hyphen: 0x002D,
  21840. hypheninferior: 0xF6E5,
  21841. hyphenmonospace: 0xFF0D,
  21842. hyphensmall: 0xFE63,
  21843. hyphensuperior: 0xF6E6,
  21844. hyphentwo: 0x2010,
  21845. i: 0x0069,
  21846. iacute: 0x00ED,
  21847. iacyrillic: 0x044F,
  21848. ibengali: 0x0987,
  21849. ibopomofo: 0x3127,
  21850. ibreve: 0x012D,
  21851. icaron: 0x01D0,
  21852. icircle: 0x24D8,
  21853. icircumflex: 0x00EE,
  21854. icyrillic: 0x0456,
  21855. idblgrave: 0x0209,
  21856. ideographearthcircle: 0x328F,
  21857. ideographfirecircle: 0x328B,
  21858. ideographicallianceparen: 0x323F,
  21859. ideographiccallparen: 0x323A,
  21860. ideographiccentrecircle: 0x32A5,
  21861. ideographicclose: 0x3006,
  21862. ideographiccomma: 0x3001,
  21863. ideographiccommaleft: 0xFF64,
  21864. ideographiccongratulationparen: 0x3237,
  21865. ideographiccorrectcircle: 0x32A3,
  21866. ideographicearthparen: 0x322F,
  21867. ideographicenterpriseparen: 0x323D,
  21868. ideographicexcellentcircle: 0x329D,
  21869. ideographicfestivalparen: 0x3240,
  21870. ideographicfinancialcircle: 0x3296,
  21871. ideographicfinancialparen: 0x3236,
  21872. ideographicfireparen: 0x322B,
  21873. ideographichaveparen: 0x3232,
  21874. ideographichighcircle: 0x32A4,
  21875. ideographiciterationmark: 0x3005,
  21876. ideographiclaborcircle: 0x3298,
  21877. ideographiclaborparen: 0x3238,
  21878. ideographicleftcircle: 0x32A7,
  21879. ideographiclowcircle: 0x32A6,
  21880. ideographicmedicinecircle: 0x32A9,
  21881. ideographicmetalparen: 0x322E,
  21882. ideographicmoonparen: 0x322A,
  21883. ideographicnameparen: 0x3234,
  21884. ideographicperiod: 0x3002,
  21885. ideographicprintcircle: 0x329E,
  21886. ideographicreachparen: 0x3243,
  21887. ideographicrepresentparen: 0x3239,
  21888. ideographicresourceparen: 0x323E,
  21889. ideographicrightcircle: 0x32A8,
  21890. ideographicsecretcircle: 0x3299,
  21891. ideographicselfparen: 0x3242,
  21892. ideographicsocietyparen: 0x3233,
  21893. ideographicspace: 0x3000,
  21894. ideographicspecialparen: 0x3235,
  21895. ideographicstockparen: 0x3231,
  21896. ideographicstudyparen: 0x323B,
  21897. ideographicsunparen: 0x3230,
  21898. ideographicsuperviseparen: 0x323C,
  21899. ideographicwaterparen: 0x322C,
  21900. ideographicwoodparen: 0x322D,
  21901. ideographiczero: 0x3007,
  21902. ideographmetalcircle: 0x328E,
  21903. ideographmooncircle: 0x328A,
  21904. ideographnamecircle: 0x3294,
  21905. ideographsuncircle: 0x3290,
  21906. ideographwatercircle: 0x328C,
  21907. ideographwoodcircle: 0x328D,
  21908. ideva: 0x0907,
  21909. idieresis: 0x00EF,
  21910. idieresisacute: 0x1E2F,
  21911. idieresiscyrillic: 0x04E5,
  21912. idotbelow: 0x1ECB,
  21913. iebrevecyrillic: 0x04D7,
  21914. iecyrillic: 0x0435,
  21915. ieungacirclekorean: 0x3275,
  21916. ieungaparenkorean: 0x3215,
  21917. ieungcirclekorean: 0x3267,
  21918. ieungkorean: 0x3147,
  21919. ieungparenkorean: 0x3207,
  21920. igrave: 0x00EC,
  21921. igujarati: 0x0A87,
  21922. igurmukhi: 0x0A07,
  21923. ihiragana: 0x3044,
  21924. ihookabove: 0x1EC9,
  21925. iibengali: 0x0988,
  21926. iicyrillic: 0x0438,
  21927. iideva: 0x0908,
  21928. iigujarati: 0x0A88,
  21929. iigurmukhi: 0x0A08,
  21930. iimatragurmukhi: 0x0A40,
  21931. iinvertedbreve: 0x020B,
  21932. iishortcyrillic: 0x0439,
  21933. iivowelsignbengali: 0x09C0,
  21934. iivowelsigndeva: 0x0940,
  21935. iivowelsigngujarati: 0x0AC0,
  21936. ij: 0x0133,
  21937. ikatakana: 0x30A4,
  21938. ikatakanahalfwidth: 0xFF72,
  21939. ikorean: 0x3163,
  21940. ilde: 0x02DC,
  21941. iluyhebrew: 0x05AC,
  21942. imacron: 0x012B,
  21943. imacroncyrillic: 0x04E3,
  21944. imageorapproximatelyequal: 0x2253,
  21945. imatragurmukhi: 0x0A3F,
  21946. imonospace: 0xFF49,
  21947. increment: 0x2206,
  21948. infinity: 0x221E,
  21949. iniarmenian: 0x056B,
  21950. integral: 0x222B,
  21951. integralbottom: 0x2321,
  21952. integralbt: 0x2321,
  21953. integralex: 0xF8F5,
  21954. integraltop: 0x2320,
  21955. integraltp: 0x2320,
  21956. intersection: 0x2229,
  21957. intisquare: 0x3305,
  21958. invbullet: 0x25D8,
  21959. invcircle: 0x25D9,
  21960. invsmileface: 0x263B,
  21961. iocyrillic: 0x0451,
  21962. iogonek: 0x012F,
  21963. iota: 0x03B9,
  21964. iotadieresis: 0x03CA,
  21965. iotadieresistonos: 0x0390,
  21966. iotalatin: 0x0269,
  21967. iotatonos: 0x03AF,
  21968. iparen: 0x24A4,
  21969. irigurmukhi: 0x0A72,
  21970. ismallhiragana: 0x3043,
  21971. ismallkatakana: 0x30A3,
  21972. ismallkatakanahalfwidth: 0xFF68,
  21973. issharbengali: 0x09FA,
  21974. istroke: 0x0268,
  21975. isuperior: 0xF6ED,
  21976. iterationhiragana: 0x309D,
  21977. iterationkatakana: 0x30FD,
  21978. itilde: 0x0129,
  21979. itildebelow: 0x1E2D,
  21980. iubopomofo: 0x3129,
  21981. iucyrillic: 0x044E,
  21982. ivowelsignbengali: 0x09BF,
  21983. ivowelsigndeva: 0x093F,
  21984. ivowelsigngujarati: 0x0ABF,
  21985. izhitsacyrillic: 0x0475,
  21986. izhitsadblgravecyrillic: 0x0477,
  21987. j: 0x006A,
  21988. jaarmenian: 0x0571,
  21989. jabengali: 0x099C,
  21990. jadeva: 0x091C,
  21991. jagujarati: 0x0A9C,
  21992. jagurmukhi: 0x0A1C,
  21993. jbopomofo: 0x3110,
  21994. jcaron: 0x01F0,
  21995. jcircle: 0x24D9,
  21996. jcircumflex: 0x0135,
  21997. jcrossedtail: 0x029D,
  21998. jdotlessstroke: 0x025F,
  21999. jecyrillic: 0x0458,
  22000. jeemarabic: 0x062C,
  22001. jeemfinalarabic: 0xFE9E,
  22002. jeeminitialarabic: 0xFE9F,
  22003. jeemmedialarabic: 0xFEA0,
  22004. jeharabic: 0x0698,
  22005. jehfinalarabic: 0xFB8B,
  22006. jhabengali: 0x099D,
  22007. jhadeva: 0x091D,
  22008. jhagujarati: 0x0A9D,
  22009. jhagurmukhi: 0x0A1D,
  22010. jheharmenian: 0x057B,
  22011. jis: 0x3004,
  22012. jmonospace: 0xFF4A,
  22013. jparen: 0x24A5,
  22014. jsuperior: 0x02B2,
  22015. k: 0x006B,
  22016. kabashkircyrillic: 0x04A1,
  22017. kabengali: 0x0995,
  22018. kacute: 0x1E31,
  22019. kacyrillic: 0x043A,
  22020. kadescendercyrillic: 0x049B,
  22021. kadeva: 0x0915,
  22022. kaf: 0x05DB,
  22023. kafarabic: 0x0643,
  22024. kafdagesh: 0xFB3B,
  22025. kafdageshhebrew: 0xFB3B,
  22026. kaffinalarabic: 0xFEDA,
  22027. kafhebrew: 0x05DB,
  22028. kafinitialarabic: 0xFEDB,
  22029. kafmedialarabic: 0xFEDC,
  22030. kafrafehebrew: 0xFB4D,
  22031. kagujarati: 0x0A95,
  22032. kagurmukhi: 0x0A15,
  22033. kahiragana: 0x304B,
  22034. kahookcyrillic: 0x04C4,
  22035. kakatakana: 0x30AB,
  22036. kakatakanahalfwidth: 0xFF76,
  22037. kappa: 0x03BA,
  22038. kappasymbolgreek: 0x03F0,
  22039. kapyeounmieumkorean: 0x3171,
  22040. kapyeounphieuphkorean: 0x3184,
  22041. kapyeounpieupkorean: 0x3178,
  22042. kapyeounssangpieupkorean: 0x3179,
  22043. karoriisquare: 0x330D,
  22044. kashidaautoarabic: 0x0640,
  22045. kashidaautonosidebearingarabic: 0x0640,
  22046. kasmallkatakana: 0x30F5,
  22047. kasquare: 0x3384,
  22048. kasraarabic: 0x0650,
  22049. kasratanarabic: 0x064D,
  22050. kastrokecyrillic: 0x049F,
  22051. katahiraprolongmarkhalfwidth: 0xFF70,
  22052. kaverticalstrokecyrillic: 0x049D,
  22053. kbopomofo: 0x310E,
  22054. kcalsquare: 0x3389,
  22055. kcaron: 0x01E9,
  22056. kcedilla: 0x0137,
  22057. kcircle: 0x24DA,
  22058. kcommaaccent: 0x0137,
  22059. kdotbelow: 0x1E33,
  22060. keharmenian: 0x0584,
  22061. kehiragana: 0x3051,
  22062. kekatakana: 0x30B1,
  22063. kekatakanahalfwidth: 0xFF79,
  22064. kenarmenian: 0x056F,
  22065. kesmallkatakana: 0x30F6,
  22066. kgreenlandic: 0x0138,
  22067. khabengali: 0x0996,
  22068. khacyrillic: 0x0445,
  22069. khadeva: 0x0916,
  22070. khagujarati: 0x0A96,
  22071. khagurmukhi: 0x0A16,
  22072. khaharabic: 0x062E,
  22073. khahfinalarabic: 0xFEA6,
  22074. khahinitialarabic: 0xFEA7,
  22075. khahmedialarabic: 0xFEA8,
  22076. kheicoptic: 0x03E7,
  22077. khhadeva: 0x0959,
  22078. khhagurmukhi: 0x0A59,
  22079. khieukhacirclekorean: 0x3278,
  22080. khieukhaparenkorean: 0x3218,
  22081. khieukhcirclekorean: 0x326A,
  22082. khieukhkorean: 0x314B,
  22083. khieukhparenkorean: 0x320A,
  22084. khokhaithai: 0x0E02,
  22085. khokhonthai: 0x0E05,
  22086. khokhuatthai: 0x0E03,
  22087. khokhwaithai: 0x0E04,
  22088. khomutthai: 0x0E5B,
  22089. khook: 0x0199,
  22090. khorakhangthai: 0x0E06,
  22091. khzsquare: 0x3391,
  22092. kihiragana: 0x304D,
  22093. kikatakana: 0x30AD,
  22094. kikatakanahalfwidth: 0xFF77,
  22095. kiroguramusquare: 0x3315,
  22096. kiromeetorusquare: 0x3316,
  22097. kirosquare: 0x3314,
  22098. kiyeokacirclekorean: 0x326E,
  22099. kiyeokaparenkorean: 0x320E,
  22100. kiyeokcirclekorean: 0x3260,
  22101. kiyeokkorean: 0x3131,
  22102. kiyeokparenkorean: 0x3200,
  22103. kiyeoksioskorean: 0x3133,
  22104. kjecyrillic: 0x045C,
  22105. klinebelow: 0x1E35,
  22106. klsquare: 0x3398,
  22107. kmcubedsquare: 0x33A6,
  22108. kmonospace: 0xFF4B,
  22109. kmsquaredsquare: 0x33A2,
  22110. kohiragana: 0x3053,
  22111. kohmsquare: 0x33C0,
  22112. kokaithai: 0x0E01,
  22113. kokatakana: 0x30B3,
  22114. kokatakanahalfwidth: 0xFF7A,
  22115. kooposquare: 0x331E,
  22116. koppacyrillic: 0x0481,
  22117. koreanstandardsymbol: 0x327F,
  22118. koroniscmb: 0x0343,
  22119. kparen: 0x24A6,
  22120. kpasquare: 0x33AA,
  22121. ksicyrillic: 0x046F,
  22122. ktsquare: 0x33CF,
  22123. kturned: 0x029E,
  22124. kuhiragana: 0x304F,
  22125. kukatakana: 0x30AF,
  22126. kukatakanahalfwidth: 0xFF78,
  22127. kvsquare: 0x33B8,
  22128. kwsquare: 0x33BE,
  22129. l: 0x006C,
  22130. labengali: 0x09B2,
  22131. lacute: 0x013A,
  22132. ladeva: 0x0932,
  22133. lagujarati: 0x0AB2,
  22134. lagurmukhi: 0x0A32,
  22135. lakkhangyaothai: 0x0E45,
  22136. lamaleffinalarabic: 0xFEFC,
  22137. lamalefhamzaabovefinalarabic: 0xFEF8,
  22138. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22139. lamalefhamzabelowfinalarabic: 0xFEFA,
  22140. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22141. lamalefisolatedarabic: 0xFEFB,
  22142. lamalefmaddaabovefinalarabic: 0xFEF6,
  22143. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22144. lamarabic: 0x0644,
  22145. lambda: 0x03BB,
  22146. lambdastroke: 0x019B,
  22147. lamed: 0x05DC,
  22148. lameddagesh: 0xFB3C,
  22149. lameddageshhebrew: 0xFB3C,
  22150. lamedhebrew: 0x05DC,
  22151. lamfinalarabic: 0xFEDE,
  22152. lamhahinitialarabic: 0xFCCA,
  22153. laminitialarabic: 0xFEDF,
  22154. lamjeeminitialarabic: 0xFCC9,
  22155. lamkhahinitialarabic: 0xFCCB,
  22156. lamlamhehisolatedarabic: 0xFDF2,
  22157. lammedialarabic: 0xFEE0,
  22158. lammeemhahinitialarabic: 0xFD88,
  22159. lammeeminitialarabic: 0xFCCC,
  22160. largecircle: 0x25EF,
  22161. lbar: 0x019A,
  22162. lbelt: 0x026C,
  22163. lbopomofo: 0x310C,
  22164. lcaron: 0x013E,
  22165. lcedilla: 0x013C,
  22166. lcircle: 0x24DB,
  22167. lcircumflexbelow: 0x1E3D,
  22168. lcommaaccent: 0x013C,
  22169. ldot: 0x0140,
  22170. ldotaccent: 0x0140,
  22171. ldotbelow: 0x1E37,
  22172. ldotbelowmacron: 0x1E39,
  22173. leftangleabovecmb: 0x031A,
  22174. lefttackbelowcmb: 0x0318,
  22175. less: 0x003C,
  22176. lessequal: 0x2264,
  22177. lessequalorgreater: 0x22DA,
  22178. lessmonospace: 0xFF1C,
  22179. lessorequivalent: 0x2272,
  22180. lessorgreater: 0x2276,
  22181. lessoverequal: 0x2266,
  22182. lesssmall: 0xFE64,
  22183. lezh: 0x026E,
  22184. lfblock: 0x258C,
  22185. lhookretroflex: 0x026D,
  22186. lira: 0x20A4,
  22187. liwnarmenian: 0x056C,
  22188. lj: 0x01C9,
  22189. ljecyrillic: 0x0459,
  22190. ll: 0xF6C0,
  22191. lladeva: 0x0933,
  22192. llagujarati: 0x0AB3,
  22193. llinebelow: 0x1E3B,
  22194. llladeva: 0x0934,
  22195. llvocalicbengali: 0x09E1,
  22196. llvocalicdeva: 0x0961,
  22197. llvocalicvowelsignbengali: 0x09E3,
  22198. llvocalicvowelsigndeva: 0x0963,
  22199. lmiddletilde: 0x026B,
  22200. lmonospace: 0xFF4C,
  22201. lmsquare: 0x33D0,
  22202. lochulathai: 0x0E2C,
  22203. logicaland: 0x2227,
  22204. logicalnot: 0x00AC,
  22205. logicalnotreversed: 0x2310,
  22206. logicalor: 0x2228,
  22207. lolingthai: 0x0E25,
  22208. longs: 0x017F,
  22209. lowlinecenterline: 0xFE4E,
  22210. lowlinecmb: 0x0332,
  22211. lowlinedashed: 0xFE4D,
  22212. lozenge: 0x25CA,
  22213. lparen: 0x24A7,
  22214. lslash: 0x0142,
  22215. lsquare: 0x2113,
  22216. lsuperior: 0xF6EE,
  22217. ltshade: 0x2591,
  22218. luthai: 0x0E26,
  22219. lvocalicbengali: 0x098C,
  22220. lvocalicdeva: 0x090C,
  22221. lvocalicvowelsignbengali: 0x09E2,
  22222. lvocalicvowelsigndeva: 0x0962,
  22223. lxsquare: 0x33D3,
  22224. m: 0x006D,
  22225. mabengali: 0x09AE,
  22226. macron: 0x00AF,
  22227. macronbelowcmb: 0x0331,
  22228. macroncmb: 0x0304,
  22229. macronlowmod: 0x02CD,
  22230. macronmonospace: 0xFFE3,
  22231. macute: 0x1E3F,
  22232. madeva: 0x092E,
  22233. magujarati: 0x0AAE,
  22234. magurmukhi: 0x0A2E,
  22235. mahapakhhebrew: 0x05A4,
  22236. mahapakhlefthebrew: 0x05A4,
  22237. mahiragana: 0x307E,
  22238. maichattawalowleftthai: 0xF895,
  22239. maichattawalowrightthai: 0xF894,
  22240. maichattawathai: 0x0E4B,
  22241. maichattawaupperleftthai: 0xF893,
  22242. maieklowleftthai: 0xF88C,
  22243. maieklowrightthai: 0xF88B,
  22244. maiekthai: 0x0E48,
  22245. maiekupperleftthai: 0xF88A,
  22246. maihanakatleftthai: 0xF884,
  22247. maihanakatthai: 0x0E31,
  22248. maitaikhuleftthai: 0xF889,
  22249. maitaikhuthai: 0x0E47,
  22250. maitholowleftthai: 0xF88F,
  22251. maitholowrightthai: 0xF88E,
  22252. maithothai: 0x0E49,
  22253. maithoupperleftthai: 0xF88D,
  22254. maitrilowleftthai: 0xF892,
  22255. maitrilowrightthai: 0xF891,
  22256. maitrithai: 0x0E4A,
  22257. maitriupperleftthai: 0xF890,
  22258. maiyamokthai: 0x0E46,
  22259. makatakana: 0x30DE,
  22260. makatakanahalfwidth: 0xFF8F,
  22261. male: 0x2642,
  22262. mansyonsquare: 0x3347,
  22263. maqafhebrew: 0x05BE,
  22264. mars: 0x2642,
  22265. masoracirclehebrew: 0x05AF,
  22266. masquare: 0x3383,
  22267. mbopomofo: 0x3107,
  22268. mbsquare: 0x33D4,
  22269. mcircle: 0x24DC,
  22270. mcubedsquare: 0x33A5,
  22271. mdotaccent: 0x1E41,
  22272. mdotbelow: 0x1E43,
  22273. meemarabic: 0x0645,
  22274. meemfinalarabic: 0xFEE2,
  22275. meeminitialarabic: 0xFEE3,
  22276. meemmedialarabic: 0xFEE4,
  22277. meemmeeminitialarabic: 0xFCD1,
  22278. meemmeemisolatedarabic: 0xFC48,
  22279. meetorusquare: 0x334D,
  22280. mehiragana: 0x3081,
  22281. meizierasquare: 0x337E,
  22282. mekatakana: 0x30E1,
  22283. mekatakanahalfwidth: 0xFF92,
  22284. mem: 0x05DE,
  22285. memdagesh: 0xFB3E,
  22286. memdageshhebrew: 0xFB3E,
  22287. memhebrew: 0x05DE,
  22288. menarmenian: 0x0574,
  22289. merkhahebrew: 0x05A5,
  22290. merkhakefulahebrew: 0x05A6,
  22291. merkhakefulalefthebrew: 0x05A6,
  22292. merkhalefthebrew: 0x05A5,
  22293. mhook: 0x0271,
  22294. mhzsquare: 0x3392,
  22295. middledotkatakanahalfwidth: 0xFF65,
  22296. middot: 0x00B7,
  22297. mieumacirclekorean: 0x3272,
  22298. mieumaparenkorean: 0x3212,
  22299. mieumcirclekorean: 0x3264,
  22300. mieumkorean: 0x3141,
  22301. mieumpansioskorean: 0x3170,
  22302. mieumparenkorean: 0x3204,
  22303. mieumpieupkorean: 0x316E,
  22304. mieumsioskorean: 0x316F,
  22305. mihiragana: 0x307F,
  22306. mikatakana: 0x30DF,
  22307. mikatakanahalfwidth: 0xFF90,
  22308. minus: 0x2212,
  22309. minusbelowcmb: 0x0320,
  22310. minuscircle: 0x2296,
  22311. minusmod: 0x02D7,
  22312. minusplus: 0x2213,
  22313. minute: 0x2032,
  22314. miribaarusquare: 0x334A,
  22315. mirisquare: 0x3349,
  22316. mlonglegturned: 0x0270,
  22317. mlsquare: 0x3396,
  22318. mmcubedsquare: 0x33A3,
  22319. mmonospace: 0xFF4D,
  22320. mmsquaredsquare: 0x339F,
  22321. mohiragana: 0x3082,
  22322. mohmsquare: 0x33C1,
  22323. mokatakana: 0x30E2,
  22324. mokatakanahalfwidth: 0xFF93,
  22325. molsquare: 0x33D6,
  22326. momathai: 0x0E21,
  22327. moverssquare: 0x33A7,
  22328. moverssquaredsquare: 0x33A8,
  22329. mparen: 0x24A8,
  22330. mpasquare: 0x33AB,
  22331. mssquare: 0x33B3,
  22332. msuperior: 0xF6EF,
  22333. mturned: 0x026F,
  22334. mu: 0x00B5,
  22335. mu1: 0x00B5,
  22336. muasquare: 0x3382,
  22337. muchgreater: 0x226B,
  22338. muchless: 0x226A,
  22339. mufsquare: 0x338C,
  22340. mugreek: 0x03BC,
  22341. mugsquare: 0x338D,
  22342. muhiragana: 0x3080,
  22343. mukatakana: 0x30E0,
  22344. mukatakanahalfwidth: 0xFF91,
  22345. mulsquare: 0x3395,
  22346. multiply: 0x00D7,
  22347. mumsquare: 0x339B,
  22348. munahhebrew: 0x05A3,
  22349. munahlefthebrew: 0x05A3,
  22350. musicalnote: 0x266A,
  22351. musicalnotedbl: 0x266B,
  22352. musicflatsign: 0x266D,
  22353. musicsharpsign: 0x266F,
  22354. mussquare: 0x33B2,
  22355. muvsquare: 0x33B6,
  22356. muwsquare: 0x33BC,
  22357. mvmegasquare: 0x33B9,
  22358. mvsquare: 0x33B7,
  22359. mwmegasquare: 0x33BF,
  22360. mwsquare: 0x33BD,
  22361. n: 0x006E,
  22362. nabengali: 0x09A8,
  22363. nabla: 0x2207,
  22364. nacute: 0x0144,
  22365. nadeva: 0x0928,
  22366. nagujarati: 0x0AA8,
  22367. nagurmukhi: 0x0A28,
  22368. nahiragana: 0x306A,
  22369. nakatakana: 0x30CA,
  22370. nakatakanahalfwidth: 0xFF85,
  22371. napostrophe: 0x0149,
  22372. nasquare: 0x3381,
  22373. nbopomofo: 0x310B,
  22374. nbspace: 0x00A0,
  22375. ncaron: 0x0148,
  22376. ncedilla: 0x0146,
  22377. ncircle: 0x24DD,
  22378. ncircumflexbelow: 0x1E4B,
  22379. ncommaaccent: 0x0146,
  22380. ndotaccent: 0x1E45,
  22381. ndotbelow: 0x1E47,
  22382. nehiragana: 0x306D,
  22383. nekatakana: 0x30CD,
  22384. nekatakanahalfwidth: 0xFF88,
  22385. newsheqelsign: 0x20AA,
  22386. nfsquare: 0x338B,
  22387. ngabengali: 0x0999,
  22388. ngadeva: 0x0919,
  22389. ngagujarati: 0x0A99,
  22390. ngagurmukhi: 0x0A19,
  22391. ngonguthai: 0x0E07,
  22392. nhiragana: 0x3093,
  22393. nhookleft: 0x0272,
  22394. nhookretroflex: 0x0273,
  22395. nieunacirclekorean: 0x326F,
  22396. nieunaparenkorean: 0x320F,
  22397. nieuncieuckorean: 0x3135,
  22398. nieuncirclekorean: 0x3261,
  22399. nieunhieuhkorean: 0x3136,
  22400. nieunkorean: 0x3134,
  22401. nieunpansioskorean: 0x3168,
  22402. nieunparenkorean: 0x3201,
  22403. nieunsioskorean: 0x3167,
  22404. nieuntikeutkorean: 0x3166,
  22405. nihiragana: 0x306B,
  22406. nikatakana: 0x30CB,
  22407. nikatakanahalfwidth: 0xFF86,
  22408. nikhahitleftthai: 0xF899,
  22409. nikhahitthai: 0x0E4D,
  22410. nine: 0x0039,
  22411. ninearabic: 0x0669,
  22412. ninebengali: 0x09EF,
  22413. ninecircle: 0x2468,
  22414. ninecircleinversesansserif: 0x2792,
  22415. ninedeva: 0x096F,
  22416. ninegujarati: 0x0AEF,
  22417. ninegurmukhi: 0x0A6F,
  22418. ninehackarabic: 0x0669,
  22419. ninehangzhou: 0x3029,
  22420. nineideographicparen: 0x3228,
  22421. nineinferior: 0x2089,
  22422. ninemonospace: 0xFF19,
  22423. nineoldstyle: 0xF739,
  22424. nineparen: 0x247C,
  22425. nineperiod: 0x2490,
  22426. ninepersian: 0x06F9,
  22427. nineroman: 0x2178,
  22428. ninesuperior: 0x2079,
  22429. nineteencircle: 0x2472,
  22430. nineteenparen: 0x2486,
  22431. nineteenperiod: 0x249A,
  22432. ninethai: 0x0E59,
  22433. nj: 0x01CC,
  22434. njecyrillic: 0x045A,
  22435. nkatakana: 0x30F3,
  22436. nkatakanahalfwidth: 0xFF9D,
  22437. nlegrightlong: 0x019E,
  22438. nlinebelow: 0x1E49,
  22439. nmonospace: 0xFF4E,
  22440. nmsquare: 0x339A,
  22441. nnabengali: 0x09A3,
  22442. nnadeva: 0x0923,
  22443. nnagujarati: 0x0AA3,
  22444. nnagurmukhi: 0x0A23,
  22445. nnnadeva: 0x0929,
  22446. nohiragana: 0x306E,
  22447. nokatakana: 0x30CE,
  22448. nokatakanahalfwidth: 0xFF89,
  22449. nonbreakingspace: 0x00A0,
  22450. nonenthai: 0x0E13,
  22451. nonuthai: 0x0E19,
  22452. noonarabic: 0x0646,
  22453. noonfinalarabic: 0xFEE6,
  22454. noonghunnaarabic: 0x06BA,
  22455. noonghunnafinalarabic: 0xFB9F,
  22456. nooninitialarabic: 0xFEE7,
  22457. noonjeeminitialarabic: 0xFCD2,
  22458. noonjeemisolatedarabic: 0xFC4B,
  22459. noonmedialarabic: 0xFEE8,
  22460. noonmeeminitialarabic: 0xFCD5,
  22461. noonmeemisolatedarabic: 0xFC4E,
  22462. noonnoonfinalarabic: 0xFC8D,
  22463. notcontains: 0x220C,
  22464. notelement: 0x2209,
  22465. notelementof: 0x2209,
  22466. notequal: 0x2260,
  22467. notgreater: 0x226F,
  22468. notgreaternorequal: 0x2271,
  22469. notgreaternorless: 0x2279,
  22470. notidentical: 0x2262,
  22471. notless: 0x226E,
  22472. notlessnorequal: 0x2270,
  22473. notparallel: 0x2226,
  22474. notprecedes: 0x2280,
  22475. notsubset: 0x2284,
  22476. notsucceeds: 0x2281,
  22477. notsuperset: 0x2285,
  22478. nowarmenian: 0x0576,
  22479. nparen: 0x24A9,
  22480. nssquare: 0x33B1,
  22481. nsuperior: 0x207F,
  22482. ntilde: 0x00F1,
  22483. nu: 0x03BD,
  22484. nuhiragana: 0x306C,
  22485. nukatakana: 0x30CC,
  22486. nukatakanahalfwidth: 0xFF87,
  22487. nuktabengali: 0x09BC,
  22488. nuktadeva: 0x093C,
  22489. nuktagujarati: 0x0ABC,
  22490. nuktagurmukhi: 0x0A3C,
  22491. numbersign: 0x0023,
  22492. numbersignmonospace: 0xFF03,
  22493. numbersignsmall: 0xFE5F,
  22494. numeralsigngreek: 0x0374,
  22495. numeralsignlowergreek: 0x0375,
  22496. numero: 0x2116,
  22497. nun: 0x05E0,
  22498. nundagesh: 0xFB40,
  22499. nundageshhebrew: 0xFB40,
  22500. nunhebrew: 0x05E0,
  22501. nvsquare: 0x33B5,
  22502. nwsquare: 0x33BB,
  22503. nyabengali: 0x099E,
  22504. nyadeva: 0x091E,
  22505. nyagujarati: 0x0A9E,
  22506. nyagurmukhi: 0x0A1E,
  22507. o: 0x006F,
  22508. oacute: 0x00F3,
  22509. oangthai: 0x0E2D,
  22510. obarred: 0x0275,
  22511. obarredcyrillic: 0x04E9,
  22512. obarreddieresiscyrillic: 0x04EB,
  22513. obengali: 0x0993,
  22514. obopomofo: 0x311B,
  22515. obreve: 0x014F,
  22516. ocandradeva: 0x0911,
  22517. ocandragujarati: 0x0A91,
  22518. ocandravowelsigndeva: 0x0949,
  22519. ocandravowelsigngujarati: 0x0AC9,
  22520. ocaron: 0x01D2,
  22521. ocircle: 0x24DE,
  22522. ocircumflex: 0x00F4,
  22523. ocircumflexacute: 0x1ED1,
  22524. ocircumflexdotbelow: 0x1ED9,
  22525. ocircumflexgrave: 0x1ED3,
  22526. ocircumflexhookabove: 0x1ED5,
  22527. ocircumflextilde: 0x1ED7,
  22528. ocyrillic: 0x043E,
  22529. odblacute: 0x0151,
  22530. odblgrave: 0x020D,
  22531. odeva: 0x0913,
  22532. odieresis: 0x00F6,
  22533. odieresiscyrillic: 0x04E7,
  22534. odotbelow: 0x1ECD,
  22535. oe: 0x0153,
  22536. oekorean: 0x315A,
  22537. ogonek: 0x02DB,
  22538. ogonekcmb: 0x0328,
  22539. ograve: 0x00F2,
  22540. ogujarati: 0x0A93,
  22541. oharmenian: 0x0585,
  22542. ohiragana: 0x304A,
  22543. ohookabove: 0x1ECF,
  22544. ohorn: 0x01A1,
  22545. ohornacute: 0x1EDB,
  22546. ohorndotbelow: 0x1EE3,
  22547. ohorngrave: 0x1EDD,
  22548. ohornhookabove: 0x1EDF,
  22549. ohorntilde: 0x1EE1,
  22550. ohungarumlaut: 0x0151,
  22551. oi: 0x01A3,
  22552. oinvertedbreve: 0x020F,
  22553. okatakana: 0x30AA,
  22554. okatakanahalfwidth: 0xFF75,
  22555. okorean: 0x3157,
  22556. olehebrew: 0x05AB,
  22557. omacron: 0x014D,
  22558. omacronacute: 0x1E53,
  22559. omacrongrave: 0x1E51,
  22560. omdeva: 0x0950,
  22561. omega: 0x03C9,
  22562. omega1: 0x03D6,
  22563. omegacyrillic: 0x0461,
  22564. omegalatinclosed: 0x0277,
  22565. omegaroundcyrillic: 0x047B,
  22566. omegatitlocyrillic: 0x047D,
  22567. omegatonos: 0x03CE,
  22568. omgujarati: 0x0AD0,
  22569. omicron: 0x03BF,
  22570. omicrontonos: 0x03CC,
  22571. omonospace: 0xFF4F,
  22572. one: 0x0031,
  22573. onearabic: 0x0661,
  22574. onebengali: 0x09E7,
  22575. onecircle: 0x2460,
  22576. onecircleinversesansserif: 0x278A,
  22577. onedeva: 0x0967,
  22578. onedotenleader: 0x2024,
  22579. oneeighth: 0x215B,
  22580. onefitted: 0xF6DC,
  22581. onegujarati: 0x0AE7,
  22582. onegurmukhi: 0x0A67,
  22583. onehackarabic: 0x0661,
  22584. onehalf: 0x00BD,
  22585. onehangzhou: 0x3021,
  22586. oneideographicparen: 0x3220,
  22587. oneinferior: 0x2081,
  22588. onemonospace: 0xFF11,
  22589. onenumeratorbengali: 0x09F4,
  22590. oneoldstyle: 0xF731,
  22591. oneparen: 0x2474,
  22592. oneperiod: 0x2488,
  22593. onepersian: 0x06F1,
  22594. onequarter: 0x00BC,
  22595. oneroman: 0x2170,
  22596. onesuperior: 0x00B9,
  22597. onethai: 0x0E51,
  22598. onethird: 0x2153,
  22599. oogonek: 0x01EB,
  22600. oogonekmacron: 0x01ED,
  22601. oogurmukhi: 0x0A13,
  22602. oomatragurmukhi: 0x0A4B,
  22603. oopen: 0x0254,
  22604. oparen: 0x24AA,
  22605. openbullet: 0x25E6,
  22606. option: 0x2325,
  22607. ordfeminine: 0x00AA,
  22608. ordmasculine: 0x00BA,
  22609. orthogonal: 0x221F,
  22610. oshortdeva: 0x0912,
  22611. oshortvowelsigndeva: 0x094A,
  22612. oslash: 0x00F8,
  22613. oslashacute: 0x01FF,
  22614. osmallhiragana: 0x3049,
  22615. osmallkatakana: 0x30A9,
  22616. osmallkatakanahalfwidth: 0xFF6B,
  22617. ostrokeacute: 0x01FF,
  22618. osuperior: 0xF6F0,
  22619. otcyrillic: 0x047F,
  22620. otilde: 0x00F5,
  22621. otildeacute: 0x1E4D,
  22622. otildedieresis: 0x1E4F,
  22623. oubopomofo: 0x3121,
  22624. overline: 0x203E,
  22625. overlinecenterline: 0xFE4A,
  22626. overlinecmb: 0x0305,
  22627. overlinedashed: 0xFE49,
  22628. overlinedblwavy: 0xFE4C,
  22629. overlinewavy: 0xFE4B,
  22630. overscore: 0x00AF,
  22631. ovowelsignbengali: 0x09CB,
  22632. ovowelsigndeva: 0x094B,
  22633. ovowelsigngujarati: 0x0ACB,
  22634. p: 0x0070,
  22635. paampssquare: 0x3380,
  22636. paasentosquare: 0x332B,
  22637. pabengali: 0x09AA,
  22638. pacute: 0x1E55,
  22639. padeva: 0x092A,
  22640. pagedown: 0x21DF,
  22641. pageup: 0x21DE,
  22642. pagujarati: 0x0AAA,
  22643. pagurmukhi: 0x0A2A,
  22644. pahiragana: 0x3071,
  22645. paiyannoithai: 0x0E2F,
  22646. pakatakana: 0x30D1,
  22647. palatalizationcyrilliccmb: 0x0484,
  22648. palochkacyrillic: 0x04C0,
  22649. pansioskorean: 0x317F,
  22650. paragraph: 0x00B6,
  22651. parallel: 0x2225,
  22652. parenleft: 0x0028,
  22653. parenleftaltonearabic: 0xFD3E,
  22654. parenleftbt: 0xF8ED,
  22655. parenleftex: 0xF8EC,
  22656. parenleftinferior: 0x208D,
  22657. parenleftmonospace: 0xFF08,
  22658. parenleftsmall: 0xFE59,
  22659. parenleftsuperior: 0x207D,
  22660. parenlefttp: 0xF8EB,
  22661. parenleftvertical: 0xFE35,
  22662. parenright: 0x0029,
  22663. parenrightaltonearabic: 0xFD3F,
  22664. parenrightbt: 0xF8F8,
  22665. parenrightex: 0xF8F7,
  22666. parenrightinferior: 0x208E,
  22667. parenrightmonospace: 0xFF09,
  22668. parenrightsmall: 0xFE5A,
  22669. parenrightsuperior: 0x207E,
  22670. parenrighttp: 0xF8F6,
  22671. parenrightvertical: 0xFE36,
  22672. partialdiff: 0x2202,
  22673. paseqhebrew: 0x05C0,
  22674. pashtahebrew: 0x0599,
  22675. pasquare: 0x33A9,
  22676. patah: 0x05B7,
  22677. patah11: 0x05B7,
  22678. patah1d: 0x05B7,
  22679. patah2a: 0x05B7,
  22680. patahhebrew: 0x05B7,
  22681. patahnarrowhebrew: 0x05B7,
  22682. patahquarterhebrew: 0x05B7,
  22683. patahwidehebrew: 0x05B7,
  22684. pazerhebrew: 0x05A1,
  22685. pbopomofo: 0x3106,
  22686. pcircle: 0x24DF,
  22687. pdotaccent: 0x1E57,
  22688. pe: 0x05E4,
  22689. pecyrillic: 0x043F,
  22690. pedagesh: 0xFB44,
  22691. pedageshhebrew: 0xFB44,
  22692. peezisquare: 0x333B,
  22693. pefinaldageshhebrew: 0xFB43,
  22694. peharabic: 0x067E,
  22695. peharmenian: 0x057A,
  22696. pehebrew: 0x05E4,
  22697. pehfinalarabic: 0xFB57,
  22698. pehinitialarabic: 0xFB58,
  22699. pehiragana: 0x307A,
  22700. pehmedialarabic: 0xFB59,
  22701. pekatakana: 0x30DA,
  22702. pemiddlehookcyrillic: 0x04A7,
  22703. perafehebrew: 0xFB4E,
  22704. percent: 0x0025,
  22705. percentarabic: 0x066A,
  22706. percentmonospace: 0xFF05,
  22707. percentsmall: 0xFE6A,
  22708. period: 0x002E,
  22709. periodarmenian: 0x0589,
  22710. periodcentered: 0x00B7,
  22711. periodhalfwidth: 0xFF61,
  22712. periodinferior: 0xF6E7,
  22713. periodmonospace: 0xFF0E,
  22714. periodsmall: 0xFE52,
  22715. periodsuperior: 0xF6E8,
  22716. perispomenigreekcmb: 0x0342,
  22717. perpendicular: 0x22A5,
  22718. perthousand: 0x2030,
  22719. peseta: 0x20A7,
  22720. pfsquare: 0x338A,
  22721. phabengali: 0x09AB,
  22722. phadeva: 0x092B,
  22723. phagujarati: 0x0AAB,
  22724. phagurmukhi: 0x0A2B,
  22725. phi: 0x03C6,
  22726. phi1: 0x03D5,
  22727. phieuphacirclekorean: 0x327A,
  22728. phieuphaparenkorean: 0x321A,
  22729. phieuphcirclekorean: 0x326C,
  22730. phieuphkorean: 0x314D,
  22731. phieuphparenkorean: 0x320C,
  22732. philatin: 0x0278,
  22733. phinthuthai: 0x0E3A,
  22734. phisymbolgreek: 0x03D5,
  22735. phook: 0x01A5,
  22736. phophanthai: 0x0E1E,
  22737. phophungthai: 0x0E1C,
  22738. phosamphaothai: 0x0E20,
  22739. pi: 0x03C0,
  22740. pieupacirclekorean: 0x3273,
  22741. pieupaparenkorean: 0x3213,
  22742. pieupcieuckorean: 0x3176,
  22743. pieupcirclekorean: 0x3265,
  22744. pieupkiyeokkorean: 0x3172,
  22745. pieupkorean: 0x3142,
  22746. pieupparenkorean: 0x3205,
  22747. pieupsioskiyeokkorean: 0x3174,
  22748. pieupsioskorean: 0x3144,
  22749. pieupsiostikeutkorean: 0x3175,
  22750. pieupthieuthkorean: 0x3177,
  22751. pieuptikeutkorean: 0x3173,
  22752. pihiragana: 0x3074,
  22753. pikatakana: 0x30D4,
  22754. pisymbolgreek: 0x03D6,
  22755. piwrarmenian: 0x0583,
  22756. plus: 0x002B,
  22757. plusbelowcmb: 0x031F,
  22758. pluscircle: 0x2295,
  22759. plusminus: 0x00B1,
  22760. plusmod: 0x02D6,
  22761. plusmonospace: 0xFF0B,
  22762. plussmall: 0xFE62,
  22763. plussuperior: 0x207A,
  22764. pmonospace: 0xFF50,
  22765. pmsquare: 0x33D8,
  22766. pohiragana: 0x307D,
  22767. pointingindexdownwhite: 0x261F,
  22768. pointingindexleftwhite: 0x261C,
  22769. pointingindexrightwhite: 0x261E,
  22770. pointingindexupwhite: 0x261D,
  22771. pokatakana: 0x30DD,
  22772. poplathai: 0x0E1B,
  22773. postalmark: 0x3012,
  22774. postalmarkface: 0x3020,
  22775. pparen: 0x24AB,
  22776. precedes: 0x227A,
  22777. prescription: 0x211E,
  22778. primemod: 0x02B9,
  22779. primereversed: 0x2035,
  22780. product: 0x220F,
  22781. projective: 0x2305,
  22782. prolongedkana: 0x30FC,
  22783. propellor: 0x2318,
  22784. propersubset: 0x2282,
  22785. propersuperset: 0x2283,
  22786. proportion: 0x2237,
  22787. proportional: 0x221D,
  22788. psi: 0x03C8,
  22789. psicyrillic: 0x0471,
  22790. psilipneumatacyrilliccmb: 0x0486,
  22791. pssquare: 0x33B0,
  22792. puhiragana: 0x3077,
  22793. pukatakana: 0x30D7,
  22794. pvsquare: 0x33B4,
  22795. pwsquare: 0x33BA,
  22796. q: 0x0071,
  22797. qadeva: 0x0958,
  22798. qadmahebrew: 0x05A8,
  22799. qafarabic: 0x0642,
  22800. qaffinalarabic: 0xFED6,
  22801. qafinitialarabic: 0xFED7,
  22802. qafmedialarabic: 0xFED8,
  22803. qamats: 0x05B8,
  22804. qamats10: 0x05B8,
  22805. qamats1a: 0x05B8,
  22806. qamats1c: 0x05B8,
  22807. qamats27: 0x05B8,
  22808. qamats29: 0x05B8,
  22809. qamats33: 0x05B8,
  22810. qamatsde: 0x05B8,
  22811. qamatshebrew: 0x05B8,
  22812. qamatsnarrowhebrew: 0x05B8,
  22813. qamatsqatanhebrew: 0x05B8,
  22814. qamatsqatannarrowhebrew: 0x05B8,
  22815. qamatsqatanquarterhebrew: 0x05B8,
  22816. qamatsqatanwidehebrew: 0x05B8,
  22817. qamatsquarterhebrew: 0x05B8,
  22818. qamatswidehebrew: 0x05B8,
  22819. qarneyparahebrew: 0x059F,
  22820. qbopomofo: 0x3111,
  22821. qcircle: 0x24E0,
  22822. qhook: 0x02A0,
  22823. qmonospace: 0xFF51,
  22824. qof: 0x05E7,
  22825. qofdagesh: 0xFB47,
  22826. qofdageshhebrew: 0xFB47,
  22827. qofhebrew: 0x05E7,
  22828. qparen: 0x24AC,
  22829. quarternote: 0x2669,
  22830. qubuts: 0x05BB,
  22831. qubuts18: 0x05BB,
  22832. qubuts25: 0x05BB,
  22833. qubuts31: 0x05BB,
  22834. qubutshebrew: 0x05BB,
  22835. qubutsnarrowhebrew: 0x05BB,
  22836. qubutsquarterhebrew: 0x05BB,
  22837. qubutswidehebrew: 0x05BB,
  22838. question: 0x003F,
  22839. questionarabic: 0x061F,
  22840. questionarmenian: 0x055E,
  22841. questiondown: 0x00BF,
  22842. questiondownsmall: 0xF7BF,
  22843. questiongreek: 0x037E,
  22844. questionmonospace: 0xFF1F,
  22845. questionsmall: 0xF73F,
  22846. quotedbl: 0x0022,
  22847. quotedblbase: 0x201E,
  22848. quotedblleft: 0x201C,
  22849. quotedblmonospace: 0xFF02,
  22850. quotedblprime: 0x301E,
  22851. quotedblprimereversed: 0x301D,
  22852. quotedblright: 0x201D,
  22853. quoteleft: 0x2018,
  22854. quoteleftreversed: 0x201B,
  22855. quotereversed: 0x201B,
  22856. quoteright: 0x2019,
  22857. quoterightn: 0x0149,
  22858. quotesinglbase: 0x201A,
  22859. quotesingle: 0x0027,
  22860. quotesinglemonospace: 0xFF07,
  22861. r: 0x0072,
  22862. raarmenian: 0x057C,
  22863. rabengali: 0x09B0,
  22864. racute: 0x0155,
  22865. radeva: 0x0930,
  22866. radical: 0x221A,
  22867. radicalex: 0xF8E5,
  22868. radoverssquare: 0x33AE,
  22869. radoverssquaredsquare: 0x33AF,
  22870. radsquare: 0x33AD,
  22871. rafe: 0x05BF,
  22872. rafehebrew: 0x05BF,
  22873. ragujarati: 0x0AB0,
  22874. ragurmukhi: 0x0A30,
  22875. rahiragana: 0x3089,
  22876. rakatakana: 0x30E9,
  22877. rakatakanahalfwidth: 0xFF97,
  22878. ralowerdiagonalbengali: 0x09F1,
  22879. ramiddlediagonalbengali: 0x09F0,
  22880. ramshorn: 0x0264,
  22881. ratio: 0x2236,
  22882. rbopomofo: 0x3116,
  22883. rcaron: 0x0159,
  22884. rcedilla: 0x0157,
  22885. rcircle: 0x24E1,
  22886. rcommaaccent: 0x0157,
  22887. rdblgrave: 0x0211,
  22888. rdotaccent: 0x1E59,
  22889. rdotbelow: 0x1E5B,
  22890. rdotbelowmacron: 0x1E5D,
  22891. referencemark: 0x203B,
  22892. reflexsubset: 0x2286,
  22893. reflexsuperset: 0x2287,
  22894. registered: 0x00AE,
  22895. registersans: 0xF8E8,
  22896. registerserif: 0xF6DA,
  22897. reharabic: 0x0631,
  22898. reharmenian: 0x0580,
  22899. rehfinalarabic: 0xFEAE,
  22900. rehiragana: 0x308C,
  22901. rekatakana: 0x30EC,
  22902. rekatakanahalfwidth: 0xFF9A,
  22903. resh: 0x05E8,
  22904. reshdageshhebrew: 0xFB48,
  22905. reshhebrew: 0x05E8,
  22906. reversedtilde: 0x223D,
  22907. reviahebrew: 0x0597,
  22908. reviamugrashhebrew: 0x0597,
  22909. revlogicalnot: 0x2310,
  22910. rfishhook: 0x027E,
  22911. rfishhookreversed: 0x027F,
  22912. rhabengali: 0x09DD,
  22913. rhadeva: 0x095D,
  22914. rho: 0x03C1,
  22915. rhook: 0x027D,
  22916. rhookturned: 0x027B,
  22917. rhookturnedsuperior: 0x02B5,
  22918. rhosymbolgreek: 0x03F1,
  22919. rhotichookmod: 0x02DE,
  22920. rieulacirclekorean: 0x3271,
  22921. rieulaparenkorean: 0x3211,
  22922. rieulcirclekorean: 0x3263,
  22923. rieulhieuhkorean: 0x3140,
  22924. rieulkiyeokkorean: 0x313A,
  22925. rieulkiyeoksioskorean: 0x3169,
  22926. rieulkorean: 0x3139,
  22927. rieulmieumkorean: 0x313B,
  22928. rieulpansioskorean: 0x316C,
  22929. rieulparenkorean: 0x3203,
  22930. rieulphieuphkorean: 0x313F,
  22931. rieulpieupkorean: 0x313C,
  22932. rieulpieupsioskorean: 0x316B,
  22933. rieulsioskorean: 0x313D,
  22934. rieulthieuthkorean: 0x313E,
  22935. rieultikeutkorean: 0x316A,
  22936. rieulyeorinhieuhkorean: 0x316D,
  22937. rightangle: 0x221F,
  22938. righttackbelowcmb: 0x0319,
  22939. righttriangle: 0x22BF,
  22940. rihiragana: 0x308A,
  22941. rikatakana: 0x30EA,
  22942. rikatakanahalfwidth: 0xFF98,
  22943. ring: 0x02DA,
  22944. ringbelowcmb: 0x0325,
  22945. ringcmb: 0x030A,
  22946. ringhalfleft: 0x02BF,
  22947. ringhalfleftarmenian: 0x0559,
  22948. ringhalfleftbelowcmb: 0x031C,
  22949. ringhalfleftcentered: 0x02D3,
  22950. ringhalfright: 0x02BE,
  22951. ringhalfrightbelowcmb: 0x0339,
  22952. ringhalfrightcentered: 0x02D2,
  22953. rinvertedbreve: 0x0213,
  22954. rittorusquare: 0x3351,
  22955. rlinebelow: 0x1E5F,
  22956. rlongleg: 0x027C,
  22957. rlonglegturned: 0x027A,
  22958. rmonospace: 0xFF52,
  22959. rohiragana: 0x308D,
  22960. rokatakana: 0x30ED,
  22961. rokatakanahalfwidth: 0xFF9B,
  22962. roruathai: 0x0E23,
  22963. rparen: 0x24AD,
  22964. rrabengali: 0x09DC,
  22965. rradeva: 0x0931,
  22966. rragurmukhi: 0x0A5C,
  22967. rreharabic: 0x0691,
  22968. rrehfinalarabic: 0xFB8D,
  22969. rrvocalicbengali: 0x09E0,
  22970. rrvocalicdeva: 0x0960,
  22971. rrvocalicgujarati: 0x0AE0,
  22972. rrvocalicvowelsignbengali: 0x09C4,
  22973. rrvocalicvowelsigndeva: 0x0944,
  22974. rrvocalicvowelsigngujarati: 0x0AC4,
  22975. rsuperior: 0xF6F1,
  22976. rtblock: 0x2590,
  22977. rturned: 0x0279,
  22978. rturnedsuperior: 0x02B4,
  22979. ruhiragana: 0x308B,
  22980. rukatakana: 0x30EB,
  22981. rukatakanahalfwidth: 0xFF99,
  22982. rupeemarkbengali: 0x09F2,
  22983. rupeesignbengali: 0x09F3,
  22984. rupiah: 0xF6DD,
  22985. ruthai: 0x0E24,
  22986. rvocalicbengali: 0x098B,
  22987. rvocalicdeva: 0x090B,
  22988. rvocalicgujarati: 0x0A8B,
  22989. rvocalicvowelsignbengali: 0x09C3,
  22990. rvocalicvowelsigndeva: 0x0943,
  22991. rvocalicvowelsigngujarati: 0x0AC3,
  22992. s: 0x0073,
  22993. sabengali: 0x09B8,
  22994. sacute: 0x015B,
  22995. sacutedotaccent: 0x1E65,
  22996. sadarabic: 0x0635,
  22997. sadeva: 0x0938,
  22998. sadfinalarabic: 0xFEBA,
  22999. sadinitialarabic: 0xFEBB,
  23000. sadmedialarabic: 0xFEBC,
  23001. sagujarati: 0x0AB8,
  23002. sagurmukhi: 0x0A38,
  23003. sahiragana: 0x3055,
  23004. sakatakana: 0x30B5,
  23005. sakatakanahalfwidth: 0xFF7B,
  23006. sallallahoualayhewasallamarabic: 0xFDFA,
  23007. samekh: 0x05E1,
  23008. samekhdagesh: 0xFB41,
  23009. samekhdageshhebrew: 0xFB41,
  23010. samekhhebrew: 0x05E1,
  23011. saraaathai: 0x0E32,
  23012. saraaethai: 0x0E41,
  23013. saraaimaimalaithai: 0x0E44,
  23014. saraaimaimuanthai: 0x0E43,
  23015. saraamthai: 0x0E33,
  23016. saraathai: 0x0E30,
  23017. saraethai: 0x0E40,
  23018. saraiileftthai: 0xF886,
  23019. saraiithai: 0x0E35,
  23020. saraileftthai: 0xF885,
  23021. saraithai: 0x0E34,
  23022. saraothai: 0x0E42,
  23023. saraueeleftthai: 0xF888,
  23024. saraueethai: 0x0E37,
  23025. saraueleftthai: 0xF887,
  23026. sarauethai: 0x0E36,
  23027. sarauthai: 0x0E38,
  23028. sarauuthai: 0x0E39,
  23029. sbopomofo: 0x3119,
  23030. scaron: 0x0161,
  23031. scarondotaccent: 0x1E67,
  23032. scedilla: 0x015F,
  23033. schwa: 0x0259,
  23034. schwacyrillic: 0x04D9,
  23035. schwadieresiscyrillic: 0x04DB,
  23036. schwahook: 0x025A,
  23037. scircle: 0x24E2,
  23038. scircumflex: 0x015D,
  23039. scommaaccent: 0x0219,
  23040. sdotaccent: 0x1E61,
  23041. sdotbelow: 0x1E63,
  23042. sdotbelowdotaccent: 0x1E69,
  23043. seagullbelowcmb: 0x033C,
  23044. second: 0x2033,
  23045. secondtonechinese: 0x02CA,
  23046. section: 0x00A7,
  23047. seenarabic: 0x0633,
  23048. seenfinalarabic: 0xFEB2,
  23049. seeninitialarabic: 0xFEB3,
  23050. seenmedialarabic: 0xFEB4,
  23051. segol: 0x05B6,
  23052. segol13: 0x05B6,
  23053. segol1f: 0x05B6,
  23054. segol2c: 0x05B6,
  23055. segolhebrew: 0x05B6,
  23056. segolnarrowhebrew: 0x05B6,
  23057. segolquarterhebrew: 0x05B6,
  23058. segoltahebrew: 0x0592,
  23059. segolwidehebrew: 0x05B6,
  23060. seharmenian: 0x057D,
  23061. sehiragana: 0x305B,
  23062. sekatakana: 0x30BB,
  23063. sekatakanahalfwidth: 0xFF7E,
  23064. semicolon: 0x003B,
  23065. semicolonarabic: 0x061B,
  23066. semicolonmonospace: 0xFF1B,
  23067. semicolonsmall: 0xFE54,
  23068. semivoicedmarkkana: 0x309C,
  23069. semivoicedmarkkanahalfwidth: 0xFF9F,
  23070. sentisquare: 0x3322,
  23071. sentosquare: 0x3323,
  23072. seven: 0x0037,
  23073. sevenarabic: 0x0667,
  23074. sevenbengali: 0x09ED,
  23075. sevencircle: 0x2466,
  23076. sevencircleinversesansserif: 0x2790,
  23077. sevendeva: 0x096D,
  23078. seveneighths: 0x215E,
  23079. sevengujarati: 0x0AED,
  23080. sevengurmukhi: 0x0A6D,
  23081. sevenhackarabic: 0x0667,
  23082. sevenhangzhou: 0x3027,
  23083. sevenideographicparen: 0x3226,
  23084. seveninferior: 0x2087,
  23085. sevenmonospace: 0xFF17,
  23086. sevenoldstyle: 0xF737,
  23087. sevenparen: 0x247A,
  23088. sevenperiod: 0x248E,
  23089. sevenpersian: 0x06F7,
  23090. sevenroman: 0x2176,
  23091. sevensuperior: 0x2077,
  23092. seventeencircle: 0x2470,
  23093. seventeenparen: 0x2484,
  23094. seventeenperiod: 0x2498,
  23095. seventhai: 0x0E57,
  23096. sfthyphen: 0x00AD,
  23097. shaarmenian: 0x0577,
  23098. shabengali: 0x09B6,
  23099. shacyrillic: 0x0448,
  23100. shaddaarabic: 0x0651,
  23101. shaddadammaarabic: 0xFC61,
  23102. shaddadammatanarabic: 0xFC5E,
  23103. shaddafathaarabic: 0xFC60,
  23104. shaddakasraarabic: 0xFC62,
  23105. shaddakasratanarabic: 0xFC5F,
  23106. shade: 0x2592,
  23107. shadedark: 0x2593,
  23108. shadelight: 0x2591,
  23109. shademedium: 0x2592,
  23110. shadeva: 0x0936,
  23111. shagujarati: 0x0AB6,
  23112. shagurmukhi: 0x0A36,
  23113. shalshelethebrew: 0x0593,
  23114. shbopomofo: 0x3115,
  23115. shchacyrillic: 0x0449,
  23116. sheenarabic: 0x0634,
  23117. sheenfinalarabic: 0xFEB6,
  23118. sheeninitialarabic: 0xFEB7,
  23119. sheenmedialarabic: 0xFEB8,
  23120. sheicoptic: 0x03E3,
  23121. sheqel: 0x20AA,
  23122. sheqelhebrew: 0x20AA,
  23123. sheva: 0x05B0,
  23124. sheva115: 0x05B0,
  23125. sheva15: 0x05B0,
  23126. sheva22: 0x05B0,
  23127. sheva2e: 0x05B0,
  23128. shevahebrew: 0x05B0,
  23129. shevanarrowhebrew: 0x05B0,
  23130. shevaquarterhebrew: 0x05B0,
  23131. shevawidehebrew: 0x05B0,
  23132. shhacyrillic: 0x04BB,
  23133. shimacoptic: 0x03ED,
  23134. shin: 0x05E9,
  23135. shindagesh: 0xFB49,
  23136. shindageshhebrew: 0xFB49,
  23137. shindageshshindot: 0xFB2C,
  23138. shindageshshindothebrew: 0xFB2C,
  23139. shindageshsindot: 0xFB2D,
  23140. shindageshsindothebrew: 0xFB2D,
  23141. shindothebrew: 0x05C1,
  23142. shinhebrew: 0x05E9,
  23143. shinshindot: 0xFB2A,
  23144. shinshindothebrew: 0xFB2A,
  23145. shinsindot: 0xFB2B,
  23146. shinsindothebrew: 0xFB2B,
  23147. shook: 0x0282,
  23148. sigma: 0x03C3,
  23149. sigma1: 0x03C2,
  23150. sigmafinal: 0x03C2,
  23151. sigmalunatesymbolgreek: 0x03F2,
  23152. sihiragana: 0x3057,
  23153. sikatakana: 0x30B7,
  23154. sikatakanahalfwidth: 0xFF7C,
  23155. siluqhebrew: 0x05BD,
  23156. siluqlefthebrew: 0x05BD,
  23157. similar: 0x223C,
  23158. sindothebrew: 0x05C2,
  23159. siosacirclekorean: 0x3274,
  23160. siosaparenkorean: 0x3214,
  23161. sioscieuckorean: 0x317E,
  23162. sioscirclekorean: 0x3266,
  23163. sioskiyeokkorean: 0x317A,
  23164. sioskorean: 0x3145,
  23165. siosnieunkorean: 0x317B,
  23166. siosparenkorean: 0x3206,
  23167. siospieupkorean: 0x317D,
  23168. siostikeutkorean: 0x317C,
  23169. six: 0x0036,
  23170. sixarabic: 0x0666,
  23171. sixbengali: 0x09EC,
  23172. sixcircle: 0x2465,
  23173. sixcircleinversesansserif: 0x278F,
  23174. sixdeva: 0x096C,
  23175. sixgujarati: 0x0AEC,
  23176. sixgurmukhi: 0x0A6C,
  23177. sixhackarabic: 0x0666,
  23178. sixhangzhou: 0x3026,
  23179. sixideographicparen: 0x3225,
  23180. sixinferior: 0x2086,
  23181. sixmonospace: 0xFF16,
  23182. sixoldstyle: 0xF736,
  23183. sixparen: 0x2479,
  23184. sixperiod: 0x248D,
  23185. sixpersian: 0x06F6,
  23186. sixroman: 0x2175,
  23187. sixsuperior: 0x2076,
  23188. sixteencircle: 0x246F,
  23189. sixteencurrencydenominatorbengali: 0x09F9,
  23190. sixteenparen: 0x2483,
  23191. sixteenperiod: 0x2497,
  23192. sixthai: 0x0E56,
  23193. slash: 0x002F,
  23194. slashmonospace: 0xFF0F,
  23195. slong: 0x017F,
  23196. slongdotaccent: 0x1E9B,
  23197. smileface: 0x263A,
  23198. smonospace: 0xFF53,
  23199. sofpasuqhebrew: 0x05C3,
  23200. softhyphen: 0x00AD,
  23201. softsigncyrillic: 0x044C,
  23202. sohiragana: 0x305D,
  23203. sokatakana: 0x30BD,
  23204. sokatakanahalfwidth: 0xFF7F,
  23205. soliduslongoverlaycmb: 0x0338,
  23206. solidusshortoverlaycmb: 0x0337,
  23207. sorusithai: 0x0E29,
  23208. sosalathai: 0x0E28,
  23209. sosothai: 0x0E0B,
  23210. sosuathai: 0x0E2A,
  23211. space: 0x0020,
  23212. spacehackarabic: 0x0020,
  23213. spade: 0x2660,
  23214. spadesuitblack: 0x2660,
  23215. spadesuitwhite: 0x2664,
  23216. sparen: 0x24AE,
  23217. squarebelowcmb: 0x033B,
  23218. squarecc: 0x33C4,
  23219. squarecm: 0x339D,
  23220. squarediagonalcrosshatchfill: 0x25A9,
  23221. squarehorizontalfill: 0x25A4,
  23222. squarekg: 0x338F,
  23223. squarekm: 0x339E,
  23224. squarekmcapital: 0x33CE,
  23225. squareln: 0x33D1,
  23226. squarelog: 0x33D2,
  23227. squaremg: 0x338E,
  23228. squaremil: 0x33D5,
  23229. squaremm: 0x339C,
  23230. squaremsquared: 0x33A1,
  23231. squareorthogonalcrosshatchfill: 0x25A6,
  23232. squareupperlefttolowerrightfill: 0x25A7,
  23233. squareupperrighttolowerleftfill: 0x25A8,
  23234. squareverticalfill: 0x25A5,
  23235. squarewhitewithsmallblack: 0x25A3,
  23236. srsquare: 0x33DB,
  23237. ssabengali: 0x09B7,
  23238. ssadeva: 0x0937,
  23239. ssagujarati: 0x0AB7,
  23240. ssangcieuckorean: 0x3149,
  23241. ssanghieuhkorean: 0x3185,
  23242. ssangieungkorean: 0x3180,
  23243. ssangkiyeokkorean: 0x3132,
  23244. ssangnieunkorean: 0x3165,
  23245. ssangpieupkorean: 0x3143,
  23246. ssangsioskorean: 0x3146,
  23247. ssangtikeutkorean: 0x3138,
  23248. ssuperior: 0xF6F2,
  23249. sterling: 0x00A3,
  23250. sterlingmonospace: 0xFFE1,
  23251. strokelongoverlaycmb: 0x0336,
  23252. strokeshortoverlaycmb: 0x0335,
  23253. subset: 0x2282,
  23254. subsetnotequal: 0x228A,
  23255. subsetorequal: 0x2286,
  23256. succeeds: 0x227B,
  23257. suchthat: 0x220B,
  23258. suhiragana: 0x3059,
  23259. sukatakana: 0x30B9,
  23260. sukatakanahalfwidth: 0xFF7D,
  23261. sukunarabic: 0x0652,
  23262. summation: 0x2211,
  23263. sun: 0x263C,
  23264. superset: 0x2283,
  23265. supersetnotequal: 0x228B,
  23266. supersetorequal: 0x2287,
  23267. svsquare: 0x33DC,
  23268. syouwaerasquare: 0x337C,
  23269. t: 0x0074,
  23270. tabengali: 0x09A4,
  23271. tackdown: 0x22A4,
  23272. tackleft: 0x22A3,
  23273. tadeva: 0x0924,
  23274. tagujarati: 0x0AA4,
  23275. tagurmukhi: 0x0A24,
  23276. taharabic: 0x0637,
  23277. tahfinalarabic: 0xFEC2,
  23278. tahinitialarabic: 0xFEC3,
  23279. tahiragana: 0x305F,
  23280. tahmedialarabic: 0xFEC4,
  23281. taisyouerasquare: 0x337D,
  23282. takatakana: 0x30BF,
  23283. takatakanahalfwidth: 0xFF80,
  23284. tatweelarabic: 0x0640,
  23285. tau: 0x03C4,
  23286. tav: 0x05EA,
  23287. tavdages: 0xFB4A,
  23288. tavdagesh: 0xFB4A,
  23289. tavdageshhebrew: 0xFB4A,
  23290. tavhebrew: 0x05EA,
  23291. tbar: 0x0167,
  23292. tbopomofo: 0x310A,
  23293. tcaron: 0x0165,
  23294. tccurl: 0x02A8,
  23295. tcedilla: 0x0163,
  23296. tcheharabic: 0x0686,
  23297. tchehfinalarabic: 0xFB7B,
  23298. tchehinitialarabic: 0xFB7C,
  23299. tchehmedialarabic: 0xFB7D,
  23300. tcircle: 0x24E3,
  23301. tcircumflexbelow: 0x1E71,
  23302. tcommaaccent: 0x0163,
  23303. tdieresis: 0x1E97,
  23304. tdotaccent: 0x1E6B,
  23305. tdotbelow: 0x1E6D,
  23306. tecyrillic: 0x0442,
  23307. tedescendercyrillic: 0x04AD,
  23308. teharabic: 0x062A,
  23309. tehfinalarabic: 0xFE96,
  23310. tehhahinitialarabic: 0xFCA2,
  23311. tehhahisolatedarabic: 0xFC0C,
  23312. tehinitialarabic: 0xFE97,
  23313. tehiragana: 0x3066,
  23314. tehjeeminitialarabic: 0xFCA1,
  23315. tehjeemisolatedarabic: 0xFC0B,
  23316. tehmarbutaarabic: 0x0629,
  23317. tehmarbutafinalarabic: 0xFE94,
  23318. tehmedialarabic: 0xFE98,
  23319. tehmeeminitialarabic: 0xFCA4,
  23320. tehmeemisolatedarabic: 0xFC0E,
  23321. tehnoonfinalarabic: 0xFC73,
  23322. tekatakana: 0x30C6,
  23323. tekatakanahalfwidth: 0xFF83,
  23324. telephone: 0x2121,
  23325. telephoneblack: 0x260E,
  23326. telishagedolahebrew: 0x05A0,
  23327. telishaqetanahebrew: 0x05A9,
  23328. tencircle: 0x2469,
  23329. tenideographicparen: 0x3229,
  23330. tenparen: 0x247D,
  23331. tenperiod: 0x2491,
  23332. tenroman: 0x2179,
  23333. tesh: 0x02A7,
  23334. tet: 0x05D8,
  23335. tetdagesh: 0xFB38,
  23336. tetdageshhebrew: 0xFB38,
  23337. tethebrew: 0x05D8,
  23338. tetsecyrillic: 0x04B5,
  23339. tevirhebrew: 0x059B,
  23340. tevirlefthebrew: 0x059B,
  23341. thabengali: 0x09A5,
  23342. thadeva: 0x0925,
  23343. thagujarati: 0x0AA5,
  23344. thagurmukhi: 0x0A25,
  23345. thalarabic: 0x0630,
  23346. thalfinalarabic: 0xFEAC,
  23347. thanthakhatlowleftthai: 0xF898,
  23348. thanthakhatlowrightthai: 0xF897,
  23349. thanthakhatthai: 0x0E4C,
  23350. thanthakhatupperleftthai: 0xF896,
  23351. theharabic: 0x062B,
  23352. thehfinalarabic: 0xFE9A,
  23353. thehinitialarabic: 0xFE9B,
  23354. thehmedialarabic: 0xFE9C,
  23355. thereexists: 0x2203,
  23356. therefore: 0x2234,
  23357. theta: 0x03B8,
  23358. theta1: 0x03D1,
  23359. thetasymbolgreek: 0x03D1,
  23360. thieuthacirclekorean: 0x3279,
  23361. thieuthaparenkorean: 0x3219,
  23362. thieuthcirclekorean: 0x326B,
  23363. thieuthkorean: 0x314C,
  23364. thieuthparenkorean: 0x320B,
  23365. thirteencircle: 0x246C,
  23366. thirteenparen: 0x2480,
  23367. thirteenperiod: 0x2494,
  23368. thonangmonthothai: 0x0E11,
  23369. thook: 0x01AD,
  23370. thophuthaothai: 0x0E12,
  23371. thorn: 0x00FE,
  23372. thothahanthai: 0x0E17,
  23373. thothanthai: 0x0E10,
  23374. thothongthai: 0x0E18,
  23375. thothungthai: 0x0E16,
  23376. thousandcyrillic: 0x0482,
  23377. thousandsseparatorarabic: 0x066C,
  23378. thousandsseparatorpersian: 0x066C,
  23379. three: 0x0033,
  23380. threearabic: 0x0663,
  23381. threebengali: 0x09E9,
  23382. threecircle: 0x2462,
  23383. threecircleinversesansserif: 0x278C,
  23384. threedeva: 0x0969,
  23385. threeeighths: 0x215C,
  23386. threegujarati: 0x0AE9,
  23387. threegurmukhi: 0x0A69,
  23388. threehackarabic: 0x0663,
  23389. threehangzhou: 0x3023,
  23390. threeideographicparen: 0x3222,
  23391. threeinferior: 0x2083,
  23392. threemonospace: 0xFF13,
  23393. threenumeratorbengali: 0x09F6,
  23394. threeoldstyle: 0xF733,
  23395. threeparen: 0x2476,
  23396. threeperiod: 0x248A,
  23397. threepersian: 0x06F3,
  23398. threequarters: 0x00BE,
  23399. threequartersemdash: 0xF6DE,
  23400. threeroman: 0x2172,
  23401. threesuperior: 0x00B3,
  23402. threethai: 0x0E53,
  23403. thzsquare: 0x3394,
  23404. tihiragana: 0x3061,
  23405. tikatakana: 0x30C1,
  23406. tikatakanahalfwidth: 0xFF81,
  23407. tikeutacirclekorean: 0x3270,
  23408. tikeutaparenkorean: 0x3210,
  23409. tikeutcirclekorean: 0x3262,
  23410. tikeutkorean: 0x3137,
  23411. tikeutparenkorean: 0x3202,
  23412. tilde: 0x02DC,
  23413. tildebelowcmb: 0x0330,
  23414. tildecmb: 0x0303,
  23415. tildecomb: 0x0303,
  23416. tildedoublecmb: 0x0360,
  23417. tildeoperator: 0x223C,
  23418. tildeoverlaycmb: 0x0334,
  23419. tildeverticalcmb: 0x033E,
  23420. timescircle: 0x2297,
  23421. tipehahebrew: 0x0596,
  23422. tipehalefthebrew: 0x0596,
  23423. tippigurmukhi: 0x0A70,
  23424. titlocyrilliccmb: 0x0483,
  23425. tiwnarmenian: 0x057F,
  23426. tlinebelow: 0x1E6F,
  23427. tmonospace: 0xFF54,
  23428. toarmenian: 0x0569,
  23429. tohiragana: 0x3068,
  23430. tokatakana: 0x30C8,
  23431. tokatakanahalfwidth: 0xFF84,
  23432. tonebarextrahighmod: 0x02E5,
  23433. tonebarextralowmod: 0x02E9,
  23434. tonebarhighmod: 0x02E6,
  23435. tonebarlowmod: 0x02E8,
  23436. tonebarmidmod: 0x02E7,
  23437. tonefive: 0x01BD,
  23438. tonesix: 0x0185,
  23439. tonetwo: 0x01A8,
  23440. tonos: 0x0384,
  23441. tonsquare: 0x3327,
  23442. topatakthai: 0x0E0F,
  23443. tortoiseshellbracketleft: 0x3014,
  23444. tortoiseshellbracketleftsmall: 0xFE5D,
  23445. tortoiseshellbracketleftvertical: 0xFE39,
  23446. tortoiseshellbracketright: 0x3015,
  23447. tortoiseshellbracketrightsmall: 0xFE5E,
  23448. tortoiseshellbracketrightvertical: 0xFE3A,
  23449. totaothai: 0x0E15,
  23450. tpalatalhook: 0x01AB,
  23451. tparen: 0x24AF,
  23452. trademark: 0x2122,
  23453. trademarksans: 0xF8EA,
  23454. trademarkserif: 0xF6DB,
  23455. tretroflexhook: 0x0288,
  23456. triagdn: 0x25BC,
  23457. triaglf: 0x25C4,
  23458. triagrt: 0x25BA,
  23459. triagup: 0x25B2,
  23460. ts: 0x02A6,
  23461. tsadi: 0x05E6,
  23462. tsadidagesh: 0xFB46,
  23463. tsadidageshhebrew: 0xFB46,
  23464. tsadihebrew: 0x05E6,
  23465. tsecyrillic: 0x0446,
  23466. tsere: 0x05B5,
  23467. tsere12: 0x05B5,
  23468. tsere1e: 0x05B5,
  23469. tsere2b: 0x05B5,
  23470. tserehebrew: 0x05B5,
  23471. tserenarrowhebrew: 0x05B5,
  23472. tserequarterhebrew: 0x05B5,
  23473. tserewidehebrew: 0x05B5,
  23474. tshecyrillic: 0x045B,
  23475. tsuperior: 0xF6F3,
  23476. ttabengali: 0x099F,
  23477. ttadeva: 0x091F,
  23478. ttagujarati: 0x0A9F,
  23479. ttagurmukhi: 0x0A1F,
  23480. tteharabic: 0x0679,
  23481. ttehfinalarabic: 0xFB67,
  23482. ttehinitialarabic: 0xFB68,
  23483. ttehmedialarabic: 0xFB69,
  23484. tthabengali: 0x09A0,
  23485. tthadeva: 0x0920,
  23486. tthagujarati: 0x0AA0,
  23487. tthagurmukhi: 0x0A20,
  23488. tturned: 0x0287,
  23489. tuhiragana: 0x3064,
  23490. tukatakana: 0x30C4,
  23491. tukatakanahalfwidth: 0xFF82,
  23492. tusmallhiragana: 0x3063,
  23493. tusmallkatakana: 0x30C3,
  23494. tusmallkatakanahalfwidth: 0xFF6F,
  23495. twelvecircle: 0x246B,
  23496. twelveparen: 0x247F,
  23497. twelveperiod: 0x2493,
  23498. twelveroman: 0x217B,
  23499. twentycircle: 0x2473,
  23500. twentyhangzhou: 0x5344,
  23501. twentyparen: 0x2487,
  23502. twentyperiod: 0x249B,
  23503. two: 0x0032,
  23504. twoarabic: 0x0662,
  23505. twobengali: 0x09E8,
  23506. twocircle: 0x2461,
  23507. twocircleinversesansserif: 0x278B,
  23508. twodeva: 0x0968,
  23509. twodotenleader: 0x2025,
  23510. twodotleader: 0x2025,
  23511. twodotleadervertical: 0xFE30,
  23512. twogujarati: 0x0AE8,
  23513. twogurmukhi: 0x0A68,
  23514. twohackarabic: 0x0662,
  23515. twohangzhou: 0x3022,
  23516. twoideographicparen: 0x3221,
  23517. twoinferior: 0x2082,
  23518. twomonospace: 0xFF12,
  23519. twonumeratorbengali: 0x09F5,
  23520. twooldstyle: 0xF732,
  23521. twoparen: 0x2475,
  23522. twoperiod: 0x2489,
  23523. twopersian: 0x06F2,
  23524. tworoman: 0x2171,
  23525. twostroke: 0x01BB,
  23526. twosuperior: 0x00B2,
  23527. twothai: 0x0E52,
  23528. twothirds: 0x2154,
  23529. u: 0x0075,
  23530. uacute: 0x00FA,
  23531. ubar: 0x0289,
  23532. ubengali: 0x0989,
  23533. ubopomofo: 0x3128,
  23534. ubreve: 0x016D,
  23535. ucaron: 0x01D4,
  23536. ucircle: 0x24E4,
  23537. ucircumflex: 0x00FB,
  23538. ucircumflexbelow: 0x1E77,
  23539. ucyrillic: 0x0443,
  23540. udattadeva: 0x0951,
  23541. udblacute: 0x0171,
  23542. udblgrave: 0x0215,
  23543. udeva: 0x0909,
  23544. udieresis: 0x00FC,
  23545. udieresisacute: 0x01D8,
  23546. udieresisbelow: 0x1E73,
  23547. udieresiscaron: 0x01DA,
  23548. udieresiscyrillic: 0x04F1,
  23549. udieresisgrave: 0x01DC,
  23550. udieresismacron: 0x01D6,
  23551. udotbelow: 0x1EE5,
  23552. ugrave: 0x00F9,
  23553. ugujarati: 0x0A89,
  23554. ugurmukhi: 0x0A09,
  23555. uhiragana: 0x3046,
  23556. uhookabove: 0x1EE7,
  23557. uhorn: 0x01B0,
  23558. uhornacute: 0x1EE9,
  23559. uhorndotbelow: 0x1EF1,
  23560. uhorngrave: 0x1EEB,
  23561. uhornhookabove: 0x1EED,
  23562. uhorntilde: 0x1EEF,
  23563. uhungarumlaut: 0x0171,
  23564. uhungarumlautcyrillic: 0x04F3,
  23565. uinvertedbreve: 0x0217,
  23566. ukatakana: 0x30A6,
  23567. ukatakanahalfwidth: 0xFF73,
  23568. ukcyrillic: 0x0479,
  23569. ukorean: 0x315C,
  23570. umacron: 0x016B,
  23571. umacroncyrillic: 0x04EF,
  23572. umacrondieresis: 0x1E7B,
  23573. umatragurmukhi: 0x0A41,
  23574. umonospace: 0xFF55,
  23575. underscore: 0x005F,
  23576. underscoredbl: 0x2017,
  23577. underscoremonospace: 0xFF3F,
  23578. underscorevertical: 0xFE33,
  23579. underscorewavy: 0xFE4F,
  23580. union: 0x222A,
  23581. universal: 0x2200,
  23582. uogonek: 0x0173,
  23583. uparen: 0x24B0,
  23584. upblock: 0x2580,
  23585. upperdothebrew: 0x05C4,
  23586. upsilon: 0x03C5,
  23587. upsilondieresis: 0x03CB,
  23588. upsilondieresistonos: 0x03B0,
  23589. upsilonlatin: 0x028A,
  23590. upsilontonos: 0x03CD,
  23591. uptackbelowcmb: 0x031D,
  23592. uptackmod: 0x02D4,
  23593. uragurmukhi: 0x0A73,
  23594. uring: 0x016F,
  23595. ushortcyrillic: 0x045E,
  23596. usmallhiragana: 0x3045,
  23597. usmallkatakana: 0x30A5,
  23598. usmallkatakanahalfwidth: 0xFF69,
  23599. ustraightcyrillic: 0x04AF,
  23600. ustraightstrokecyrillic: 0x04B1,
  23601. utilde: 0x0169,
  23602. utildeacute: 0x1E79,
  23603. utildebelow: 0x1E75,
  23604. uubengali: 0x098A,
  23605. uudeva: 0x090A,
  23606. uugujarati: 0x0A8A,
  23607. uugurmukhi: 0x0A0A,
  23608. uumatragurmukhi: 0x0A42,
  23609. uuvowelsignbengali: 0x09C2,
  23610. uuvowelsigndeva: 0x0942,
  23611. uuvowelsigngujarati: 0x0AC2,
  23612. uvowelsignbengali: 0x09C1,
  23613. uvowelsigndeva: 0x0941,
  23614. uvowelsigngujarati: 0x0AC1,
  23615. v: 0x0076,
  23616. vadeva: 0x0935,
  23617. vagujarati: 0x0AB5,
  23618. vagurmukhi: 0x0A35,
  23619. vakatakana: 0x30F7,
  23620. vav: 0x05D5,
  23621. vavdagesh: 0xFB35,
  23622. vavdagesh65: 0xFB35,
  23623. vavdageshhebrew: 0xFB35,
  23624. vavhebrew: 0x05D5,
  23625. vavholam: 0xFB4B,
  23626. vavholamhebrew: 0xFB4B,
  23627. vavvavhebrew: 0x05F0,
  23628. vavyodhebrew: 0x05F1,
  23629. vcircle: 0x24E5,
  23630. vdotbelow: 0x1E7F,
  23631. vecyrillic: 0x0432,
  23632. veharabic: 0x06A4,
  23633. vehfinalarabic: 0xFB6B,
  23634. vehinitialarabic: 0xFB6C,
  23635. vehmedialarabic: 0xFB6D,
  23636. vekatakana: 0x30F9,
  23637. venus: 0x2640,
  23638. verticalbar: 0x007C,
  23639. verticallineabovecmb: 0x030D,
  23640. verticallinebelowcmb: 0x0329,
  23641. verticallinelowmod: 0x02CC,
  23642. verticallinemod: 0x02C8,
  23643. vewarmenian: 0x057E,
  23644. vhook: 0x028B,
  23645. vikatakana: 0x30F8,
  23646. viramabengali: 0x09CD,
  23647. viramadeva: 0x094D,
  23648. viramagujarati: 0x0ACD,
  23649. visargabengali: 0x0983,
  23650. visargadeva: 0x0903,
  23651. visargagujarati: 0x0A83,
  23652. vmonospace: 0xFF56,
  23653. voarmenian: 0x0578,
  23654. voicediterationhiragana: 0x309E,
  23655. voicediterationkatakana: 0x30FE,
  23656. voicedmarkkana: 0x309B,
  23657. voicedmarkkanahalfwidth: 0xFF9E,
  23658. vokatakana: 0x30FA,
  23659. vparen: 0x24B1,
  23660. vtilde: 0x1E7D,
  23661. vturned: 0x028C,
  23662. vuhiragana: 0x3094,
  23663. vukatakana: 0x30F4,
  23664. w: 0x0077,
  23665. wacute: 0x1E83,
  23666. waekorean: 0x3159,
  23667. wahiragana: 0x308F,
  23668. wakatakana: 0x30EF,
  23669. wakatakanahalfwidth: 0xFF9C,
  23670. wakorean: 0x3158,
  23671. wasmallhiragana: 0x308E,
  23672. wasmallkatakana: 0x30EE,
  23673. wattosquare: 0x3357,
  23674. wavedash: 0x301C,
  23675. wavyunderscorevertical: 0xFE34,
  23676. wawarabic: 0x0648,
  23677. wawfinalarabic: 0xFEEE,
  23678. wawhamzaabovearabic: 0x0624,
  23679. wawhamzaabovefinalarabic: 0xFE86,
  23680. wbsquare: 0x33DD,
  23681. wcircle: 0x24E6,
  23682. wcircumflex: 0x0175,
  23683. wdieresis: 0x1E85,
  23684. wdotaccent: 0x1E87,
  23685. wdotbelow: 0x1E89,
  23686. wehiragana: 0x3091,
  23687. weierstrass: 0x2118,
  23688. wekatakana: 0x30F1,
  23689. wekorean: 0x315E,
  23690. weokorean: 0x315D,
  23691. wgrave: 0x1E81,
  23692. whitebullet: 0x25E6,
  23693. whitecircle: 0x25CB,
  23694. whitecircleinverse: 0x25D9,
  23695. whitecornerbracketleft: 0x300E,
  23696. whitecornerbracketleftvertical: 0xFE43,
  23697. whitecornerbracketright: 0x300F,
  23698. whitecornerbracketrightvertical: 0xFE44,
  23699. whitediamond: 0x25C7,
  23700. whitediamondcontainingblacksmalldiamond: 0x25C8,
  23701. whitedownpointingsmalltriangle: 0x25BF,
  23702. whitedownpointingtriangle: 0x25BD,
  23703. whiteleftpointingsmalltriangle: 0x25C3,
  23704. whiteleftpointingtriangle: 0x25C1,
  23705. whitelenticularbracketleft: 0x3016,
  23706. whitelenticularbracketright: 0x3017,
  23707. whiterightpointingsmalltriangle: 0x25B9,
  23708. whiterightpointingtriangle: 0x25B7,
  23709. whitesmallsquare: 0x25AB,
  23710. whitesmilingface: 0x263A,
  23711. whitesquare: 0x25A1,
  23712. whitestar: 0x2606,
  23713. whitetelephone: 0x260F,
  23714. whitetortoiseshellbracketleft: 0x3018,
  23715. whitetortoiseshellbracketright: 0x3019,
  23716. whiteuppointingsmalltriangle: 0x25B5,
  23717. whiteuppointingtriangle: 0x25B3,
  23718. wihiragana: 0x3090,
  23719. wikatakana: 0x30F0,
  23720. wikorean: 0x315F,
  23721. wmonospace: 0xFF57,
  23722. wohiragana: 0x3092,
  23723. wokatakana: 0x30F2,
  23724. wokatakanahalfwidth: 0xFF66,
  23725. won: 0x20A9,
  23726. wonmonospace: 0xFFE6,
  23727. wowaenthai: 0x0E27,
  23728. wparen: 0x24B2,
  23729. wring: 0x1E98,
  23730. wsuperior: 0x02B7,
  23731. wturned: 0x028D,
  23732. wynn: 0x01BF,
  23733. x: 0x0078,
  23734. xabovecmb: 0x033D,
  23735. xbopomofo: 0x3112,
  23736. xcircle: 0x24E7,
  23737. xdieresis: 0x1E8D,
  23738. xdotaccent: 0x1E8B,
  23739. xeharmenian: 0x056D,
  23740. xi: 0x03BE,
  23741. xmonospace: 0xFF58,
  23742. xparen: 0x24B3,
  23743. xsuperior: 0x02E3,
  23744. y: 0x0079,
  23745. yaadosquare: 0x334E,
  23746. yabengali: 0x09AF,
  23747. yacute: 0x00FD,
  23748. yadeva: 0x092F,
  23749. yaekorean: 0x3152,
  23750. yagujarati: 0x0AAF,
  23751. yagurmukhi: 0x0A2F,
  23752. yahiragana: 0x3084,
  23753. yakatakana: 0x30E4,
  23754. yakatakanahalfwidth: 0xFF94,
  23755. yakorean: 0x3151,
  23756. yamakkanthai: 0x0E4E,
  23757. yasmallhiragana: 0x3083,
  23758. yasmallkatakana: 0x30E3,
  23759. yasmallkatakanahalfwidth: 0xFF6C,
  23760. yatcyrillic: 0x0463,
  23761. ycircle: 0x24E8,
  23762. ycircumflex: 0x0177,
  23763. ydieresis: 0x00FF,
  23764. ydotaccent: 0x1E8F,
  23765. ydotbelow: 0x1EF5,
  23766. yeharabic: 0x064A,
  23767. yehbarreearabic: 0x06D2,
  23768. yehbarreefinalarabic: 0xFBAF,
  23769. yehfinalarabic: 0xFEF2,
  23770. yehhamzaabovearabic: 0x0626,
  23771. yehhamzaabovefinalarabic: 0xFE8A,
  23772. yehhamzaaboveinitialarabic: 0xFE8B,
  23773. yehhamzaabovemedialarabic: 0xFE8C,
  23774. yehinitialarabic: 0xFEF3,
  23775. yehmedialarabic: 0xFEF4,
  23776. yehmeeminitialarabic: 0xFCDD,
  23777. yehmeemisolatedarabic: 0xFC58,
  23778. yehnoonfinalarabic: 0xFC94,
  23779. yehthreedotsbelowarabic: 0x06D1,
  23780. yekorean: 0x3156,
  23781. yen: 0x00A5,
  23782. yenmonospace: 0xFFE5,
  23783. yeokorean: 0x3155,
  23784. yeorinhieuhkorean: 0x3186,
  23785. yerahbenyomohebrew: 0x05AA,
  23786. yerahbenyomolefthebrew: 0x05AA,
  23787. yericyrillic: 0x044B,
  23788. yerudieresiscyrillic: 0x04F9,
  23789. yesieungkorean: 0x3181,
  23790. yesieungpansioskorean: 0x3183,
  23791. yesieungsioskorean: 0x3182,
  23792. yetivhebrew: 0x059A,
  23793. ygrave: 0x1EF3,
  23794. yhook: 0x01B4,
  23795. yhookabove: 0x1EF7,
  23796. yiarmenian: 0x0575,
  23797. yicyrillic: 0x0457,
  23798. yikorean: 0x3162,
  23799. yinyang: 0x262F,
  23800. yiwnarmenian: 0x0582,
  23801. ymonospace: 0xFF59,
  23802. yod: 0x05D9,
  23803. yoddagesh: 0xFB39,
  23804. yoddageshhebrew: 0xFB39,
  23805. yodhebrew: 0x05D9,
  23806. yodyodhebrew: 0x05F2,
  23807. yodyodpatahhebrew: 0xFB1F,
  23808. yohiragana: 0x3088,
  23809. yoikorean: 0x3189,
  23810. yokatakana: 0x30E8,
  23811. yokatakanahalfwidth: 0xFF96,
  23812. yokorean: 0x315B,
  23813. yosmallhiragana: 0x3087,
  23814. yosmallkatakana: 0x30E7,
  23815. yosmallkatakanahalfwidth: 0xFF6E,
  23816. yotgreek: 0x03F3,
  23817. yoyaekorean: 0x3188,
  23818. yoyakorean: 0x3187,
  23819. yoyakthai: 0x0E22,
  23820. yoyingthai: 0x0E0D,
  23821. yparen: 0x24B4,
  23822. ypogegrammeni: 0x037A,
  23823. ypogegrammenigreekcmb: 0x0345,
  23824. yr: 0x01A6,
  23825. yring: 0x1E99,
  23826. ysuperior: 0x02B8,
  23827. ytilde: 0x1EF9,
  23828. yturned: 0x028E,
  23829. yuhiragana: 0x3086,
  23830. yuikorean: 0x318C,
  23831. yukatakana: 0x30E6,
  23832. yukatakanahalfwidth: 0xFF95,
  23833. yukorean: 0x3160,
  23834. yusbigcyrillic: 0x046B,
  23835. yusbigiotifiedcyrillic: 0x046D,
  23836. yuslittlecyrillic: 0x0467,
  23837. yuslittleiotifiedcyrillic: 0x0469,
  23838. yusmallhiragana: 0x3085,
  23839. yusmallkatakana: 0x30E5,
  23840. yusmallkatakanahalfwidth: 0xFF6D,
  23841. yuyekorean: 0x318B,
  23842. yuyeokorean: 0x318A,
  23843. yyabengali: 0x09DF,
  23844. yyadeva: 0x095F,
  23845. z: 0x007A,
  23846. zaarmenian: 0x0566,
  23847. zacute: 0x017A,
  23848. zadeva: 0x095B,
  23849. zagurmukhi: 0x0A5B,
  23850. zaharabic: 0x0638,
  23851. zahfinalarabic: 0xFEC6,
  23852. zahinitialarabic: 0xFEC7,
  23853. zahiragana: 0x3056,
  23854. zahmedialarabic: 0xFEC8,
  23855. zainarabic: 0x0632,
  23856. zainfinalarabic: 0xFEB0,
  23857. zakatakana: 0x30B6,
  23858. zaqefgadolhebrew: 0x0595,
  23859. zaqefqatanhebrew: 0x0594,
  23860. zarqahebrew: 0x0598,
  23861. zayin: 0x05D6,
  23862. zayindagesh: 0xFB36,
  23863. zayindageshhebrew: 0xFB36,
  23864. zayinhebrew: 0x05D6,
  23865. zbopomofo: 0x3117,
  23866. zcaron: 0x017E,
  23867. zcircle: 0x24E9,
  23868. zcircumflex: 0x1E91,
  23869. zcurl: 0x0291,
  23870. zdot: 0x017C,
  23871. zdotaccent: 0x017C,
  23872. zdotbelow: 0x1E93,
  23873. zecyrillic: 0x0437,
  23874. zedescendercyrillic: 0x0499,
  23875. zedieresiscyrillic: 0x04DF,
  23876. zehiragana: 0x305C,
  23877. zekatakana: 0x30BC,
  23878. zero: 0x0030,
  23879. zeroarabic: 0x0660,
  23880. zerobengali: 0x09E6,
  23881. zerodeva: 0x0966,
  23882. zerogujarati: 0x0AE6,
  23883. zerogurmukhi: 0x0A66,
  23884. zerohackarabic: 0x0660,
  23885. zeroinferior: 0x2080,
  23886. zeromonospace: 0xFF10,
  23887. zerooldstyle: 0xF730,
  23888. zeropersian: 0x06F0,
  23889. zerosuperior: 0x2070,
  23890. zerothai: 0x0E50,
  23891. zerowidthjoiner: 0xFEFF,
  23892. zerowidthnonjoiner: 0x200C,
  23893. zerowidthspace: 0x200B,
  23894. zeta: 0x03B6,
  23895. zhbopomofo: 0x3113,
  23896. zhearmenian: 0x056A,
  23897. zhebrevecyrillic: 0x04C2,
  23898. zhecyrillic: 0x0436,
  23899. zhedescendercyrillic: 0x0497,
  23900. zhedieresiscyrillic: 0x04DD,
  23901. zihiragana: 0x3058,
  23902. zikatakana: 0x30B8,
  23903. zinorhebrew: 0x05AE,
  23904. zlinebelow: 0x1E95,
  23905. zmonospace: 0xFF5A,
  23906. zohiragana: 0x305E,
  23907. zokatakana: 0x30BE,
  23908. zparen: 0x24B5,
  23909. zretroflexhook: 0x0290,
  23910. zstroke: 0x01B6,
  23911. zuhiragana: 0x305A,
  23912. zukatakana: 0x30BA,
  23913. '.notdef': 0x0000
  23914. };
  23915. var PDFImage = (function PDFImageClosure() {
  23916. /**
  23917. * Decode the image in the main thread if it supported. Resovles the promise
  23918. * when the image data is ready.
  23919. */
  23920. function handleImageData(handler, xref, res, image) {
  23921. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  23922. // For natively supported jpegs send them to the main thread for decoding.
  23923. var dict = image.dict;
  23924. var colorSpace = dict.get('ColorSpace', 'CS');
  23925. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  23926. var numComps = colorSpace.numComps;
  23927. var decodePromise = handler.sendWithPromise('JpegDecode',
  23928. [image.getIR(), numComps]);
  23929. return decodePromise.then(function (message) {
  23930. var data = message.data;
  23931. return new Stream(data, 0, data.length, image.dict);
  23932. });
  23933. } else {
  23934. return Promise.resolve(image);
  23935. }
  23936. }
  23937. /**
  23938. * Decode and clamp a value. The formula is different from the spec because we
  23939. * don't decode to float range [0,1], we decode it in the [0,max] range.
  23940. */
  23941. function decodeAndClamp(value, addend, coefficient, max) {
  23942. value = addend + value * coefficient;
  23943. // Clamp the value to the range
  23944. return (value < 0 ? 0 : (value > max ? max : value));
  23945. }
  23946. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  23947. this.image = image;
  23948. var dict = image.dict;
  23949. if (dict.has('Filter')) {
  23950. var filter = dict.get('Filter').name;
  23951. if (filter === 'JPXDecode') {
  23952. var jpxImage = new JpxImage();
  23953. jpxImage.parseImageProperties(image.stream);
  23954. image.stream.reset();
  23955. image.bitsPerComponent = jpxImage.bitsPerComponent;
  23956. image.numComps = jpxImage.componentsCount;
  23957. } else if (filter === 'JBIG2Decode') {
  23958. image.bitsPerComponent = 1;
  23959. image.numComps = 1;
  23960. }
  23961. }
  23962. // TODO cache rendered images?
  23963. this.width = dict.get('Width', 'W');
  23964. this.height = dict.get('Height', 'H');
  23965. if (this.width < 1 || this.height < 1) {
  23966. error('Invalid image width: ' + this.width + ' or height: ' +
  23967. this.height);
  23968. }
  23969. this.interpolate = dict.get('Interpolate', 'I') || false;
  23970. this.imageMask = dict.get('ImageMask', 'IM') || false;
  23971. this.matte = dict.get('Matte') || false;
  23972. var bitsPerComponent = image.bitsPerComponent;
  23973. if (!bitsPerComponent) {
  23974. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  23975. if (!bitsPerComponent) {
  23976. if (this.imageMask) {
  23977. bitsPerComponent = 1;
  23978. } else {
  23979. error('Bits per component missing in image: ' + this.imageMask);
  23980. }
  23981. }
  23982. }
  23983. this.bpc = bitsPerComponent;
  23984. if (!this.imageMask) {
  23985. var colorSpace = dict.get('ColorSpace', 'CS');
  23986. if (!colorSpace) {
  23987. info('JPX images (which do not require color spaces)');
  23988. switch (image.numComps) {
  23989. case 1:
  23990. colorSpace = Name.get('DeviceGray');
  23991. break;
  23992. case 3:
  23993. colorSpace = Name.get('DeviceRGB');
  23994. break;
  23995. case 4:
  23996. colorSpace = Name.get('DeviceCMYK');
  23997. break;
  23998. default:
  23999. error('JPX images with ' + this.numComps +
  24000. ' color components not supported.');
  24001. }
  24002. }
  24003. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24004. this.numComps = this.colorSpace.numComps;
  24005. }
  24006. this.decode = dict.get('Decode', 'D');
  24007. this.needsDecode = false;
  24008. if (this.decode &&
  24009. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24010. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24011. this.needsDecode = true;
  24012. // Do some preprocessing to avoid more math.
  24013. var max = (1 << bitsPerComponent) - 1;
  24014. this.decodeCoefficients = [];
  24015. this.decodeAddends = [];
  24016. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24017. var dmin = this.decode[i];
  24018. var dmax = this.decode[i + 1];
  24019. this.decodeCoefficients[j] = dmax - dmin;
  24020. this.decodeAddends[j] = max * dmin;
  24021. }
  24022. }
  24023. if (smask) {
  24024. this.smask = new PDFImage(xref, res, smask, false);
  24025. } else if (mask) {
  24026. if (isStream(mask)) {
  24027. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24028. } else {
  24029. // Color key mask (just an array).
  24030. this.mask = mask;
  24031. }
  24032. }
  24033. }
  24034. /**
  24035. * Handles processing of image data and returns the Promise that is resolved
  24036. * with a PDFImage when the image is ready to be used.
  24037. */
  24038. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24039. res, image, inline) {
  24040. var imagePromise = handleImageData(handler, xref, res, image);
  24041. var smaskPromise;
  24042. var maskPromise;
  24043. var smask = image.dict.get('SMask');
  24044. var mask = image.dict.get('Mask');
  24045. if (smask) {
  24046. smaskPromise = handleImageData(handler, xref, res, smask);
  24047. maskPromise = Promise.resolve(null);
  24048. } else {
  24049. smaskPromise = Promise.resolve(null);
  24050. if (mask) {
  24051. if (isStream(mask)) {
  24052. maskPromise = handleImageData(handler, xref, res, mask);
  24053. } else if (isArray(mask)) {
  24054. maskPromise = Promise.resolve(mask);
  24055. } else {
  24056. warn('Unsupported mask format.');
  24057. maskPromise = Promise.resolve(null);
  24058. }
  24059. } else {
  24060. maskPromise = Promise.resolve(null);
  24061. }
  24062. }
  24063. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24064. function(results) {
  24065. var imageData = results[0];
  24066. var smaskData = results[1];
  24067. var maskData = results[2];
  24068. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24069. });
  24070. };
  24071. /**
  24072. * Resize an image using the nearest neighbor algorithm. Currently only
  24073. * supports one and three component images.
  24074. * @param {TypedArray} pixels The original image with one component.
  24075. * @param {Number} bpc Number of bits per component.
  24076. * @param {Number} components Number of color components, 1 or 3 is supported.
  24077. * @param {Number} w1 Original width.
  24078. * @param {Number} h1 Original height.
  24079. * @param {Number} w2 New width.
  24080. * @param {Number} h2 New height.
  24081. * @param {TypedArray} dest (Optional) The destination buffer.
  24082. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24083. * @return {TypedArray} Resized image data.
  24084. */
  24085. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24086. w1, h1, w2, h2, dest, alpha01) {
  24087. if (components !== 1 && components !== 3) {
  24088. error('Unsupported component count for resizing.');
  24089. }
  24090. var length = w2 * h2 * components;
  24091. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24092. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24093. var xRatio = w1 / w2;
  24094. var yRatio = h1 / h2;
  24095. var i, j, py, newIndex = 0, oldIndex;
  24096. var xScaled = new Uint16Array(w2);
  24097. var w1Scanline = w1 * components;
  24098. if (alpha01 !== 1) {
  24099. alpha01 = 0;
  24100. }
  24101. for (j = 0; j < w2; j++) {
  24102. xScaled[j] = Math.floor(j * xRatio) * components;
  24103. }
  24104. if (components === 1) {
  24105. for (i = 0; i < h2; i++) {
  24106. py = Math.floor(i * yRatio) * w1Scanline;
  24107. for (j = 0; j < w2; j++) {
  24108. oldIndex = py + xScaled[j];
  24109. temp[newIndex++] = pixels[oldIndex];
  24110. }
  24111. }
  24112. } else if (components === 3) {
  24113. for (i = 0; i < h2; i++) {
  24114. py = Math.floor(i * yRatio) * w1Scanline;
  24115. for (j = 0; j < w2; j++) {
  24116. oldIndex = py + xScaled[j];
  24117. temp[newIndex++] = pixels[oldIndex++];
  24118. temp[newIndex++] = pixels[oldIndex++];
  24119. temp[newIndex++] = pixels[oldIndex++];
  24120. newIndex += alpha01;
  24121. }
  24122. }
  24123. }
  24124. return temp;
  24125. };
  24126. PDFImage.createMask =
  24127. function PDFImage_createMask(imgArray, width, height,
  24128. imageIsFromDecodeStream, inverseDecode) {
  24129. // |imgArray| might not contain full data for every pixel of the mask, so
  24130. // we need to distinguish between |computedLength| and |actualLength|.
  24131. // In particular, if inverseDecode is true, then the array we return must
  24132. // have a length of |computedLength|.
  24133. var computedLength = ((width + 7) >> 3) * height;
  24134. var actualLength = imgArray.byteLength;
  24135. var haveFullData = computedLength === actualLength;
  24136. var data, i;
  24137. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24138. // imgArray came from a DecodeStream and its data is in an appropriate
  24139. // form, so we can just transfer it.
  24140. data = imgArray;
  24141. } else if (!inverseDecode) {
  24142. data = new Uint8Array(actualLength);
  24143. data.set(imgArray);
  24144. } else {
  24145. data = new Uint8Array(computedLength);
  24146. data.set(imgArray);
  24147. for (i = actualLength; i < computedLength; i++) {
  24148. data[i] = 0xff;
  24149. }
  24150. }
  24151. // If necessary, invert the original mask data (but not any extra we might
  24152. // have added above). It's safe to modify the array -- whether it's the
  24153. // original or a copy, we're about to transfer it anyway, so nothing else
  24154. // in this thread can be relying on its contents.
  24155. if (inverseDecode) {
  24156. for (i = 0; i < actualLength; i++) {
  24157. data[i] = ~data[i];
  24158. }
  24159. }
  24160. return {data: data, width: width, height: height};
  24161. };
  24162. PDFImage.prototype = {
  24163. get drawWidth() {
  24164. return Math.max(this.width,
  24165. this.smask && this.smask.width || 0,
  24166. this.mask && this.mask.width || 0);
  24167. },
  24168. get drawHeight() {
  24169. return Math.max(this.height,
  24170. this.smask && this.smask.height || 0,
  24171. this.mask && this.mask.height || 0);
  24172. },
  24173. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24174. var bpc = this.bpc;
  24175. var numComps = this.numComps;
  24176. var decodeAddends = this.decodeAddends;
  24177. var decodeCoefficients = this.decodeCoefficients;
  24178. var max = (1 << bpc) - 1;
  24179. var i, ii;
  24180. if (bpc === 1) {
  24181. // If the buffer needed decode that means it just needs to be inverted.
  24182. for (i = 0, ii = buffer.length; i < ii; i++) {
  24183. buffer[i] = +!(buffer[i]);
  24184. }
  24185. return;
  24186. }
  24187. var index = 0;
  24188. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24189. for (var j = 0; j < numComps; j++) {
  24190. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24191. decodeCoefficients[j], max);
  24192. index++;
  24193. }
  24194. }
  24195. },
  24196. getComponents: function PDFImage_getComponents(buffer) {
  24197. var bpc = this.bpc;
  24198. // This image doesn't require any extra work.
  24199. if (bpc === 8) {
  24200. return buffer;
  24201. }
  24202. var width = this.width;
  24203. var height = this.height;
  24204. var numComps = this.numComps;
  24205. var length = width * height * numComps;
  24206. var bufferPos = 0;
  24207. var output = (bpc <= 8 ? new Uint8Array(length) :
  24208. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24209. var rowComps = width * numComps;
  24210. var max = (1 << bpc) - 1;
  24211. var i = 0, ii, buf;
  24212. if (bpc === 1) {
  24213. // Optimization for reading 1 bpc images.
  24214. var mask, loop1End, loop2End;
  24215. for (var j = 0; j < height; j++) {
  24216. loop1End = i + (rowComps & ~7);
  24217. loop2End = i + rowComps;
  24218. // unroll loop for all full bytes
  24219. while (i < loop1End) {
  24220. buf = buffer[bufferPos++];
  24221. output[i] = (buf >> 7) & 1;
  24222. output[i + 1] = (buf >> 6) & 1;
  24223. output[i + 2] = (buf >> 5) & 1;
  24224. output[i + 3] = (buf >> 4) & 1;
  24225. output[i + 4] = (buf >> 3) & 1;
  24226. output[i + 5] = (buf >> 2) & 1;
  24227. output[i + 6] = (buf >> 1) & 1;
  24228. output[i + 7] = buf & 1;
  24229. i += 8;
  24230. }
  24231. // handle remaing bits
  24232. if (i < loop2End) {
  24233. buf = buffer[bufferPos++];
  24234. mask = 128;
  24235. while (i < loop2End) {
  24236. output[i++] = +!!(buf & mask);
  24237. mask >>= 1;
  24238. }
  24239. }
  24240. }
  24241. } else {
  24242. // The general case that handles all other bpc values.
  24243. var bits = 0;
  24244. buf = 0;
  24245. for (i = 0, ii = length; i < ii; ++i) {
  24246. if (i % rowComps === 0) {
  24247. buf = 0;
  24248. bits = 0;
  24249. }
  24250. while (bits < bpc) {
  24251. buf = (buf << 8) | buffer[bufferPos++];
  24252. bits += 8;
  24253. }
  24254. var remainingBits = bits - bpc;
  24255. var value = buf >> remainingBits;
  24256. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  24257. buf = buf & ((1 << remainingBits) - 1);
  24258. bits = remainingBits;
  24259. }
  24260. }
  24261. return output;
  24262. },
  24263. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  24264. actualHeight, image) {
  24265. var smask = this.smask;
  24266. var mask = this.mask;
  24267. var alphaBuf, sw, sh, i, ii, j;
  24268. if (smask) {
  24269. sw = smask.width;
  24270. sh = smask.height;
  24271. alphaBuf = new Uint8Array(sw * sh);
  24272. smask.fillGrayBuffer(alphaBuf);
  24273. if (sw !== width || sh !== height) {
  24274. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  24275. height);
  24276. }
  24277. } else if (mask) {
  24278. if (mask instanceof PDFImage) {
  24279. sw = mask.width;
  24280. sh = mask.height;
  24281. alphaBuf = new Uint8Array(sw * sh);
  24282. mask.numComps = 1;
  24283. mask.fillGrayBuffer(alphaBuf);
  24284. // Need to invert values in rgbaBuf
  24285. for (i = 0, ii = sw * sh; i < ii; ++i) {
  24286. alphaBuf[i] = 255 - alphaBuf[i];
  24287. }
  24288. if (sw !== width || sh !== height) {
  24289. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  24290. height);
  24291. }
  24292. } else if (isArray(mask)) {
  24293. // Color key mask: if any of the compontents are outside the range
  24294. // then they should be painted.
  24295. alphaBuf = new Uint8Array(width * height);
  24296. var numComps = this.numComps;
  24297. for (i = 0, ii = width * height; i < ii; ++i) {
  24298. var opacity = 0;
  24299. var imageOffset = i * numComps;
  24300. for (j = 0; j < numComps; ++j) {
  24301. var color = image[imageOffset + j];
  24302. var maskOffset = j * 2;
  24303. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  24304. opacity = 255;
  24305. break;
  24306. }
  24307. }
  24308. alphaBuf[i] = opacity;
  24309. }
  24310. } else {
  24311. error('Unknown mask format.');
  24312. }
  24313. }
  24314. if (alphaBuf) {
  24315. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24316. rgbaBuf[j] = alphaBuf[i];
  24317. }
  24318. } else {
  24319. // No mask.
  24320. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24321. rgbaBuf[j] = 255;
  24322. }
  24323. }
  24324. },
  24325. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  24326. var matte = this.smask && this.smask.matte;
  24327. if (!matte) {
  24328. return;
  24329. }
  24330. var matteRgb = this.colorSpace.getRgb(matte, 0);
  24331. var matteR = matteRgb[0];
  24332. var matteG = matteRgb[1];
  24333. var matteB = matteRgb[2];
  24334. var length = width * height * 4;
  24335. var r, g, b;
  24336. for (var i = 0; i < length; i += 4) {
  24337. var alpha = buffer[i + 3];
  24338. if (alpha === 0) {
  24339. // according formula we have to get Infinity in all components
  24340. // making it white (typical paper color) should be okay
  24341. buffer[i] = 255;
  24342. buffer[i + 1] = 255;
  24343. buffer[i + 2] = 255;
  24344. continue;
  24345. }
  24346. var k = 255 / alpha;
  24347. r = (buffer[i] - matteR) * k + matteR;
  24348. g = (buffer[i + 1] - matteG) * k + matteG;
  24349. b = (buffer[i + 2] - matteB) * k + matteB;
  24350. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  24351. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  24352. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  24353. }
  24354. },
  24355. createImageData: function PDFImage_createImageData(forceRGBA) {
  24356. var drawWidth = this.drawWidth;
  24357. var drawHeight = this.drawHeight;
  24358. var imgData = { // other fields are filled in below
  24359. width: drawWidth,
  24360. height: drawHeight
  24361. };
  24362. var numComps = this.numComps;
  24363. var originalWidth = this.width;
  24364. var originalHeight = this.height;
  24365. var bpc = this.bpc;
  24366. // Rows start at byte boundary.
  24367. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  24368. var imgArray;
  24369. if (!forceRGBA) {
  24370. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  24371. // without any complications, we pass a same-sized copy to the main
  24372. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  24373. // of memory for many scanned documents. It's also much faster.
  24374. //
  24375. // Similarly, if it is a 24-bit-per pixel RGB image without any
  24376. // complications, we avoid expanding by 1.333x to RGBA form.
  24377. var kind;
  24378. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  24379. kind = ImageKind.GRAYSCALE_1BPP;
  24380. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  24381. kind = ImageKind.RGB_24BPP;
  24382. }
  24383. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  24384. drawWidth === originalWidth && drawHeight === originalHeight) {
  24385. imgData.kind = kind;
  24386. imgArray = this.getImageBytes(originalHeight * rowBytes);
  24387. // If imgArray came from a DecodeStream, we're safe to transfer it
  24388. // (and thus neuter it) because it will constitute the entire
  24389. // DecodeStream's data. But if it came from a Stream, we need to
  24390. // copy it because it'll only be a portion of the Stream's data, and
  24391. // the rest will be read later on.
  24392. if (this.image instanceof DecodeStream) {
  24393. imgData.data = imgArray;
  24394. } else {
  24395. var newArray = new Uint8Array(imgArray.length);
  24396. newArray.set(imgArray);
  24397. imgData.data = newArray;
  24398. }
  24399. return imgData;
  24400. }
  24401. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  24402. imgData.kind = ImageKind.RGB_24BPP;
  24403. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  24404. drawWidth, drawHeight, true);
  24405. return imgData;
  24406. }
  24407. }
  24408. imgArray = this.getImageBytes(originalHeight * rowBytes);
  24409. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  24410. var actualHeight = 0 | (imgArray.length / rowBytes *
  24411. drawHeight / originalHeight);
  24412. var comps = this.getComponents(imgArray);
  24413. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  24414. // more compact RGB_24BPP form if allowable.
  24415. var alpha01, maybeUndoPreblend;
  24416. if (!forceRGBA && !this.smask && !this.mask) {
  24417. imgData.kind = ImageKind.RGB_24BPP;
  24418. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  24419. alpha01 = 0;
  24420. maybeUndoPreblend = false;
  24421. } else {
  24422. imgData.kind = ImageKind.RGBA_32BPP;
  24423. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  24424. alpha01 = 1;
  24425. maybeUndoPreblend = true;
  24426. // Color key masking (opacity) must be performed before decoding.
  24427. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  24428. comps);
  24429. }
  24430. if (this.needsDecode) {
  24431. this.decodeBuffer(comps);
  24432. }
  24433. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  24434. drawWidth, drawHeight, actualHeight, bpc, comps,
  24435. alpha01);
  24436. if (maybeUndoPreblend) {
  24437. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  24438. }
  24439. return imgData;
  24440. },
  24441. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  24442. var numComps = this.numComps;
  24443. if (numComps !== 1) {
  24444. error('Reading gray scale from a color image: ' + numComps);
  24445. }
  24446. var width = this.width;
  24447. var height = this.height;
  24448. var bpc = this.bpc;
  24449. // rows start at byte boundary
  24450. var rowBytes = (width * numComps * bpc + 7) >> 3;
  24451. var imgArray = this.getImageBytes(height * rowBytes);
  24452. var comps = this.getComponents(imgArray);
  24453. var i, length;
  24454. if (bpc === 1) {
  24455. // inline decoding (= inversion) for 1 bpc images
  24456. length = width * height;
  24457. if (this.needsDecode) {
  24458. // invert and scale to {0, 255}
  24459. for (i = 0; i < length; ++i) {
  24460. buffer[i] = (comps[i] - 1) & 255;
  24461. }
  24462. } else {
  24463. // scale to {0, 255}
  24464. for (i = 0; i < length; ++i) {
  24465. buffer[i] = (-comps[i]) & 255;
  24466. }
  24467. }
  24468. return;
  24469. }
  24470. if (this.needsDecode) {
  24471. this.decodeBuffer(comps);
  24472. }
  24473. length = width * height;
  24474. // we aren't using a colorspace so we need to scale the value
  24475. var scale = 255 / ((1 << bpc) - 1);
  24476. for (i = 0; i < length; ++i) {
  24477. buffer[i] = (scale * comps[i]) | 0;
  24478. }
  24479. },
  24480. getImageBytes: function PDFImage_getImageBytes(length,
  24481. drawWidth, drawHeight,
  24482. forceRGB) {
  24483. this.image.reset();
  24484. this.image.drawWidth = drawWidth || this.width;
  24485. this.image.drawHeight = drawHeight || this.height;
  24486. this.image.forceRGB = !!forceRGB;
  24487. return this.image.getBytes(length);
  24488. }
  24489. };
  24490. return PDFImage;
  24491. })();
  24492. // The Metrics object contains glyph widths (in glyph space units).
  24493. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  24494. // space unit corresponds to 1/1000th of text space unit.
  24495. var Metrics = {
  24496. 'Courier': 600,
  24497. 'Courier-Bold': 600,
  24498. 'Courier-BoldOblique': 600,
  24499. 'Courier-Oblique': 600,
  24500. 'Helvetica' : {
  24501. 'space': 278,
  24502. 'exclam': 278,
  24503. 'quotedbl': 355,
  24504. 'numbersign': 556,
  24505. 'dollar': 556,
  24506. 'percent': 889,
  24507. 'ampersand': 667,
  24508. 'quoteright': 222,
  24509. 'parenleft': 333,
  24510. 'parenright': 333,
  24511. 'asterisk': 389,
  24512. 'plus': 584,
  24513. 'comma': 278,
  24514. 'hyphen': 333,
  24515. 'period': 278,
  24516. 'slash': 278,
  24517. 'zero': 556,
  24518. 'one': 556,
  24519. 'two': 556,
  24520. 'three': 556,
  24521. 'four': 556,
  24522. 'five': 556,
  24523. 'six': 556,
  24524. 'seven': 556,
  24525. 'eight': 556,
  24526. 'nine': 556,
  24527. 'colon': 278,
  24528. 'semicolon': 278,
  24529. 'less': 584,
  24530. 'equal': 584,
  24531. 'greater': 584,
  24532. 'question': 556,
  24533. 'at': 1015,
  24534. 'A': 667,
  24535. 'B': 667,
  24536. 'C': 722,
  24537. 'D': 722,
  24538. 'E': 667,
  24539. 'F': 611,
  24540. 'G': 778,
  24541. 'H': 722,
  24542. 'I': 278,
  24543. 'J': 500,
  24544. 'K': 667,
  24545. 'L': 556,
  24546. 'M': 833,
  24547. 'N': 722,
  24548. 'O': 778,
  24549. 'P': 667,
  24550. 'Q': 778,
  24551. 'R': 722,
  24552. 'S': 667,
  24553. 'T': 611,
  24554. 'U': 722,
  24555. 'V': 667,
  24556. 'W': 944,
  24557. 'X': 667,
  24558. 'Y': 667,
  24559. 'Z': 611,
  24560. 'bracketleft': 278,
  24561. 'backslash': 278,
  24562. 'bracketright': 278,
  24563. 'asciicircum': 469,
  24564. 'underscore': 556,
  24565. 'quoteleft': 222,
  24566. 'a': 556,
  24567. 'b': 556,
  24568. 'c': 500,
  24569. 'd': 556,
  24570. 'e': 556,
  24571. 'f': 278,
  24572. 'g': 556,
  24573. 'h': 556,
  24574. 'i': 222,
  24575. 'j': 222,
  24576. 'k': 500,
  24577. 'l': 222,
  24578. 'm': 833,
  24579. 'n': 556,
  24580. 'o': 556,
  24581. 'p': 556,
  24582. 'q': 556,
  24583. 'r': 333,
  24584. 's': 500,
  24585. 't': 278,
  24586. 'u': 556,
  24587. 'v': 500,
  24588. 'w': 722,
  24589. 'x': 500,
  24590. 'y': 500,
  24591. 'z': 500,
  24592. 'braceleft': 334,
  24593. 'bar': 260,
  24594. 'braceright': 334,
  24595. 'asciitilde': 584,
  24596. 'exclamdown': 333,
  24597. 'cent': 556,
  24598. 'sterling': 556,
  24599. 'fraction': 167,
  24600. 'yen': 556,
  24601. 'florin': 556,
  24602. 'section': 556,
  24603. 'currency': 556,
  24604. 'quotesingle': 191,
  24605. 'quotedblleft': 333,
  24606. 'guillemotleft': 556,
  24607. 'guilsinglleft': 333,
  24608. 'guilsinglright': 333,
  24609. 'fi': 500,
  24610. 'fl': 500,
  24611. 'endash': 556,
  24612. 'dagger': 556,
  24613. 'daggerdbl': 556,
  24614. 'periodcentered': 278,
  24615. 'paragraph': 537,
  24616. 'bullet': 350,
  24617. 'quotesinglbase': 222,
  24618. 'quotedblbase': 333,
  24619. 'quotedblright': 333,
  24620. 'guillemotright': 556,
  24621. 'ellipsis': 1000,
  24622. 'perthousand': 1000,
  24623. 'questiondown': 611,
  24624. 'grave': 333,
  24625. 'acute': 333,
  24626. 'circumflex': 333,
  24627. 'tilde': 333,
  24628. 'macron': 333,
  24629. 'breve': 333,
  24630. 'dotaccent': 333,
  24631. 'dieresis': 333,
  24632. 'ring': 333,
  24633. 'cedilla': 333,
  24634. 'hungarumlaut': 333,
  24635. 'ogonek': 333,
  24636. 'caron': 333,
  24637. 'emdash': 1000,
  24638. 'AE': 1000,
  24639. 'ordfeminine': 370,
  24640. 'Lslash': 556,
  24641. 'Oslash': 778,
  24642. 'OE': 1000,
  24643. 'ordmasculine': 365,
  24644. 'ae': 889,
  24645. 'dotlessi': 278,
  24646. 'lslash': 222,
  24647. 'oslash': 611,
  24648. 'oe': 944,
  24649. 'germandbls': 611,
  24650. 'Idieresis': 278,
  24651. 'eacute': 556,
  24652. 'abreve': 556,
  24653. 'uhungarumlaut': 556,
  24654. 'ecaron': 556,
  24655. 'Ydieresis': 667,
  24656. 'divide': 584,
  24657. 'Yacute': 667,
  24658. 'Acircumflex': 667,
  24659. 'aacute': 556,
  24660. 'Ucircumflex': 722,
  24661. 'yacute': 500,
  24662. 'scommaaccent': 500,
  24663. 'ecircumflex': 556,
  24664. 'Uring': 722,
  24665. 'Udieresis': 722,
  24666. 'aogonek': 556,
  24667. 'Uacute': 722,
  24668. 'uogonek': 556,
  24669. 'Edieresis': 667,
  24670. 'Dcroat': 722,
  24671. 'commaaccent': 250,
  24672. 'copyright': 737,
  24673. 'Emacron': 667,
  24674. 'ccaron': 500,
  24675. 'aring': 556,
  24676. 'Ncommaaccent': 722,
  24677. 'lacute': 222,
  24678. 'agrave': 556,
  24679. 'Tcommaaccent': 611,
  24680. 'Cacute': 722,
  24681. 'atilde': 556,
  24682. 'Edotaccent': 667,
  24683. 'scaron': 500,
  24684. 'scedilla': 500,
  24685. 'iacute': 278,
  24686. 'lozenge': 471,
  24687. 'Rcaron': 722,
  24688. 'Gcommaaccent': 778,
  24689. 'ucircumflex': 556,
  24690. 'acircumflex': 556,
  24691. 'Amacron': 667,
  24692. 'rcaron': 333,
  24693. 'ccedilla': 500,
  24694. 'Zdotaccent': 611,
  24695. 'Thorn': 667,
  24696. 'Omacron': 778,
  24697. 'Racute': 722,
  24698. 'Sacute': 667,
  24699. 'dcaron': 643,
  24700. 'Umacron': 722,
  24701. 'uring': 556,
  24702. 'threesuperior': 333,
  24703. 'Ograve': 778,
  24704. 'Agrave': 667,
  24705. 'Abreve': 667,
  24706. 'multiply': 584,
  24707. 'uacute': 556,
  24708. 'Tcaron': 611,
  24709. 'partialdiff': 476,
  24710. 'ydieresis': 500,
  24711. 'Nacute': 722,
  24712. 'icircumflex': 278,
  24713. 'Ecircumflex': 667,
  24714. 'adieresis': 556,
  24715. 'edieresis': 556,
  24716. 'cacute': 500,
  24717. 'nacute': 556,
  24718. 'umacron': 556,
  24719. 'Ncaron': 722,
  24720. 'Iacute': 278,
  24721. 'plusminus': 584,
  24722. 'brokenbar': 260,
  24723. 'registered': 737,
  24724. 'Gbreve': 778,
  24725. 'Idotaccent': 278,
  24726. 'summation': 600,
  24727. 'Egrave': 667,
  24728. 'racute': 333,
  24729. 'omacron': 556,
  24730. 'Zacute': 611,
  24731. 'Zcaron': 611,
  24732. 'greaterequal': 549,
  24733. 'Eth': 722,
  24734. 'Ccedilla': 722,
  24735. 'lcommaaccent': 222,
  24736. 'tcaron': 317,
  24737. 'eogonek': 556,
  24738. 'Uogonek': 722,
  24739. 'Aacute': 667,
  24740. 'Adieresis': 667,
  24741. 'egrave': 556,
  24742. 'zacute': 500,
  24743. 'iogonek': 222,
  24744. 'Oacute': 778,
  24745. 'oacute': 556,
  24746. 'amacron': 556,
  24747. 'sacute': 500,
  24748. 'idieresis': 278,
  24749. 'Ocircumflex': 778,
  24750. 'Ugrave': 722,
  24751. 'Delta': 612,
  24752. 'thorn': 556,
  24753. 'twosuperior': 333,
  24754. 'Odieresis': 778,
  24755. 'mu': 556,
  24756. 'igrave': 278,
  24757. 'ohungarumlaut': 556,
  24758. 'Eogonek': 667,
  24759. 'dcroat': 556,
  24760. 'threequarters': 834,
  24761. 'Scedilla': 667,
  24762. 'lcaron': 299,
  24763. 'Kcommaaccent': 667,
  24764. 'Lacute': 556,
  24765. 'trademark': 1000,
  24766. 'edotaccent': 556,
  24767. 'Igrave': 278,
  24768. 'Imacron': 278,
  24769. 'Lcaron': 556,
  24770. 'onehalf': 834,
  24771. 'lessequal': 549,
  24772. 'ocircumflex': 556,
  24773. 'ntilde': 556,
  24774. 'Uhungarumlaut': 722,
  24775. 'Eacute': 667,
  24776. 'emacron': 556,
  24777. 'gbreve': 556,
  24778. 'onequarter': 834,
  24779. 'Scaron': 667,
  24780. 'Scommaaccent': 667,
  24781. 'Ohungarumlaut': 778,
  24782. 'degree': 400,
  24783. 'ograve': 556,
  24784. 'Ccaron': 722,
  24785. 'ugrave': 556,
  24786. 'radical': 453,
  24787. 'Dcaron': 722,
  24788. 'rcommaaccent': 333,
  24789. 'Ntilde': 722,
  24790. 'otilde': 556,
  24791. 'Rcommaaccent': 722,
  24792. 'Lcommaaccent': 556,
  24793. 'Atilde': 667,
  24794. 'Aogonek': 667,
  24795. 'Aring': 667,
  24796. 'Otilde': 778,
  24797. 'zdotaccent': 500,
  24798. 'Ecaron': 667,
  24799. 'Iogonek': 278,
  24800. 'kcommaaccent': 500,
  24801. 'minus': 584,
  24802. 'Icircumflex': 278,
  24803. 'ncaron': 556,
  24804. 'tcommaaccent': 278,
  24805. 'logicalnot': 584,
  24806. 'odieresis': 556,
  24807. 'udieresis': 556,
  24808. 'notequal': 549,
  24809. 'gcommaaccent': 556,
  24810. 'eth': 556,
  24811. 'zcaron': 500,
  24812. 'ncommaaccent': 556,
  24813. 'onesuperior': 333,
  24814. 'imacron': 278,
  24815. 'Euro': 556
  24816. },
  24817. 'Helvetica-Bold': {
  24818. 'space': 278,
  24819. 'exclam': 333,
  24820. 'quotedbl': 474,
  24821. 'numbersign': 556,
  24822. 'dollar': 556,
  24823. 'percent': 889,
  24824. 'ampersand': 722,
  24825. 'quoteright': 278,
  24826. 'parenleft': 333,
  24827. 'parenright': 333,
  24828. 'asterisk': 389,
  24829. 'plus': 584,
  24830. 'comma': 278,
  24831. 'hyphen': 333,
  24832. 'period': 278,
  24833. 'slash': 278,
  24834. 'zero': 556,
  24835. 'one': 556,
  24836. 'two': 556,
  24837. 'three': 556,
  24838. 'four': 556,
  24839. 'five': 556,
  24840. 'six': 556,
  24841. 'seven': 556,
  24842. 'eight': 556,
  24843. 'nine': 556,
  24844. 'colon': 333,
  24845. 'semicolon': 333,
  24846. 'less': 584,
  24847. 'equal': 584,
  24848. 'greater': 584,
  24849. 'question': 611,
  24850. 'at': 975,
  24851. 'A': 722,
  24852. 'B': 722,
  24853. 'C': 722,
  24854. 'D': 722,
  24855. 'E': 667,
  24856. 'F': 611,
  24857. 'G': 778,
  24858. 'H': 722,
  24859. 'I': 278,
  24860. 'J': 556,
  24861. 'K': 722,
  24862. 'L': 611,
  24863. 'M': 833,
  24864. 'N': 722,
  24865. 'O': 778,
  24866. 'P': 667,
  24867. 'Q': 778,
  24868. 'R': 722,
  24869. 'S': 667,
  24870. 'T': 611,
  24871. 'U': 722,
  24872. 'V': 667,
  24873. 'W': 944,
  24874. 'X': 667,
  24875. 'Y': 667,
  24876. 'Z': 611,
  24877. 'bracketleft': 333,
  24878. 'backslash': 278,
  24879. 'bracketright': 333,
  24880. 'asciicircum': 584,
  24881. 'underscore': 556,
  24882. 'quoteleft': 278,
  24883. 'a': 556,
  24884. 'b': 611,
  24885. 'c': 556,
  24886. 'd': 611,
  24887. 'e': 556,
  24888. 'f': 333,
  24889. 'g': 611,
  24890. 'h': 611,
  24891. 'i': 278,
  24892. 'j': 278,
  24893. 'k': 556,
  24894. 'l': 278,
  24895. 'm': 889,
  24896. 'n': 611,
  24897. 'o': 611,
  24898. 'p': 611,
  24899. 'q': 611,
  24900. 'r': 389,
  24901. 's': 556,
  24902. 't': 333,
  24903. 'u': 611,
  24904. 'v': 556,
  24905. 'w': 778,
  24906. 'x': 556,
  24907. 'y': 556,
  24908. 'z': 500,
  24909. 'braceleft': 389,
  24910. 'bar': 280,
  24911. 'braceright': 389,
  24912. 'asciitilde': 584,
  24913. 'exclamdown': 333,
  24914. 'cent': 556,
  24915. 'sterling': 556,
  24916. 'fraction': 167,
  24917. 'yen': 556,
  24918. 'florin': 556,
  24919. 'section': 556,
  24920. 'currency': 556,
  24921. 'quotesingle': 238,
  24922. 'quotedblleft': 500,
  24923. 'guillemotleft': 556,
  24924. 'guilsinglleft': 333,
  24925. 'guilsinglright': 333,
  24926. 'fi': 611,
  24927. 'fl': 611,
  24928. 'endash': 556,
  24929. 'dagger': 556,
  24930. 'daggerdbl': 556,
  24931. 'periodcentered': 278,
  24932. 'paragraph': 556,
  24933. 'bullet': 350,
  24934. 'quotesinglbase': 278,
  24935. 'quotedblbase': 500,
  24936. 'quotedblright': 500,
  24937. 'guillemotright': 556,
  24938. 'ellipsis': 1000,
  24939. 'perthousand': 1000,
  24940. 'questiondown': 611,
  24941. 'grave': 333,
  24942. 'acute': 333,
  24943. 'circumflex': 333,
  24944. 'tilde': 333,
  24945. 'macron': 333,
  24946. 'breve': 333,
  24947. 'dotaccent': 333,
  24948. 'dieresis': 333,
  24949. 'ring': 333,
  24950. 'cedilla': 333,
  24951. 'hungarumlaut': 333,
  24952. 'ogonek': 333,
  24953. 'caron': 333,
  24954. 'emdash': 1000,
  24955. 'AE': 1000,
  24956. 'ordfeminine': 370,
  24957. 'Lslash': 611,
  24958. 'Oslash': 778,
  24959. 'OE': 1000,
  24960. 'ordmasculine': 365,
  24961. 'ae': 889,
  24962. 'dotlessi': 278,
  24963. 'lslash': 278,
  24964. 'oslash': 611,
  24965. 'oe': 944,
  24966. 'germandbls': 611,
  24967. 'Idieresis': 278,
  24968. 'eacute': 556,
  24969. 'abreve': 556,
  24970. 'uhungarumlaut': 611,
  24971. 'ecaron': 556,
  24972. 'Ydieresis': 667,
  24973. 'divide': 584,
  24974. 'Yacute': 667,
  24975. 'Acircumflex': 722,
  24976. 'aacute': 556,
  24977. 'Ucircumflex': 722,
  24978. 'yacute': 556,
  24979. 'scommaaccent': 556,
  24980. 'ecircumflex': 556,
  24981. 'Uring': 722,
  24982. 'Udieresis': 722,
  24983. 'aogonek': 556,
  24984. 'Uacute': 722,
  24985. 'uogonek': 611,
  24986. 'Edieresis': 667,
  24987. 'Dcroat': 722,
  24988. 'commaaccent': 250,
  24989. 'copyright': 737,
  24990. 'Emacron': 667,
  24991. 'ccaron': 556,
  24992. 'aring': 556,
  24993. 'Ncommaaccent': 722,
  24994. 'lacute': 278,
  24995. 'agrave': 556,
  24996. 'Tcommaaccent': 611,
  24997. 'Cacute': 722,
  24998. 'atilde': 556,
  24999. 'Edotaccent': 667,
  25000. 'scaron': 556,
  25001. 'scedilla': 556,
  25002. 'iacute': 278,
  25003. 'lozenge': 494,
  25004. 'Rcaron': 722,
  25005. 'Gcommaaccent': 778,
  25006. 'ucircumflex': 611,
  25007. 'acircumflex': 556,
  25008. 'Amacron': 722,
  25009. 'rcaron': 389,
  25010. 'ccedilla': 556,
  25011. 'Zdotaccent': 611,
  25012. 'Thorn': 667,
  25013. 'Omacron': 778,
  25014. 'Racute': 722,
  25015. 'Sacute': 667,
  25016. 'dcaron': 743,
  25017. 'Umacron': 722,
  25018. 'uring': 611,
  25019. 'threesuperior': 333,
  25020. 'Ograve': 778,
  25021. 'Agrave': 722,
  25022. 'Abreve': 722,
  25023. 'multiply': 584,
  25024. 'uacute': 611,
  25025. 'Tcaron': 611,
  25026. 'partialdiff': 494,
  25027. 'ydieresis': 556,
  25028. 'Nacute': 722,
  25029. 'icircumflex': 278,
  25030. 'Ecircumflex': 667,
  25031. 'adieresis': 556,
  25032. 'edieresis': 556,
  25033. 'cacute': 556,
  25034. 'nacute': 611,
  25035. 'umacron': 611,
  25036. 'Ncaron': 722,
  25037. 'Iacute': 278,
  25038. 'plusminus': 584,
  25039. 'brokenbar': 280,
  25040. 'registered': 737,
  25041. 'Gbreve': 778,
  25042. 'Idotaccent': 278,
  25043. 'summation': 600,
  25044. 'Egrave': 667,
  25045. 'racute': 389,
  25046. 'omacron': 611,
  25047. 'Zacute': 611,
  25048. 'Zcaron': 611,
  25049. 'greaterequal': 549,
  25050. 'Eth': 722,
  25051. 'Ccedilla': 722,
  25052. 'lcommaaccent': 278,
  25053. 'tcaron': 389,
  25054. 'eogonek': 556,
  25055. 'Uogonek': 722,
  25056. 'Aacute': 722,
  25057. 'Adieresis': 722,
  25058. 'egrave': 556,
  25059. 'zacute': 500,
  25060. 'iogonek': 278,
  25061. 'Oacute': 778,
  25062. 'oacute': 611,
  25063. 'amacron': 556,
  25064. 'sacute': 556,
  25065. 'idieresis': 278,
  25066. 'Ocircumflex': 778,
  25067. 'Ugrave': 722,
  25068. 'Delta': 612,
  25069. 'thorn': 611,
  25070. 'twosuperior': 333,
  25071. 'Odieresis': 778,
  25072. 'mu': 611,
  25073. 'igrave': 278,
  25074. 'ohungarumlaut': 611,
  25075. 'Eogonek': 667,
  25076. 'dcroat': 611,
  25077. 'threequarters': 834,
  25078. 'Scedilla': 667,
  25079. 'lcaron': 400,
  25080. 'Kcommaaccent': 722,
  25081. 'Lacute': 611,
  25082. 'trademark': 1000,
  25083. 'edotaccent': 556,
  25084. 'Igrave': 278,
  25085. 'Imacron': 278,
  25086. 'Lcaron': 611,
  25087. 'onehalf': 834,
  25088. 'lessequal': 549,
  25089. 'ocircumflex': 611,
  25090. 'ntilde': 611,
  25091. 'Uhungarumlaut': 722,
  25092. 'Eacute': 667,
  25093. 'emacron': 556,
  25094. 'gbreve': 611,
  25095. 'onequarter': 834,
  25096. 'Scaron': 667,
  25097. 'Scommaaccent': 667,
  25098. 'Ohungarumlaut': 778,
  25099. 'degree': 400,
  25100. 'ograve': 611,
  25101. 'Ccaron': 722,
  25102. 'ugrave': 611,
  25103. 'radical': 549,
  25104. 'Dcaron': 722,
  25105. 'rcommaaccent': 389,
  25106. 'Ntilde': 722,
  25107. 'otilde': 611,
  25108. 'Rcommaaccent': 722,
  25109. 'Lcommaaccent': 611,
  25110. 'Atilde': 722,
  25111. 'Aogonek': 722,
  25112. 'Aring': 722,
  25113. 'Otilde': 778,
  25114. 'zdotaccent': 500,
  25115. 'Ecaron': 667,
  25116. 'Iogonek': 278,
  25117. 'kcommaaccent': 556,
  25118. 'minus': 584,
  25119. 'Icircumflex': 278,
  25120. 'ncaron': 611,
  25121. 'tcommaaccent': 333,
  25122. 'logicalnot': 584,
  25123. 'odieresis': 611,
  25124. 'udieresis': 611,
  25125. 'notequal': 549,
  25126. 'gcommaaccent': 611,
  25127. 'eth': 611,
  25128. 'zcaron': 500,
  25129. 'ncommaaccent': 611,
  25130. 'onesuperior': 333,
  25131. 'imacron': 278,
  25132. 'Euro': 556
  25133. },
  25134. 'Helvetica-BoldOblique': {
  25135. 'space': 278,
  25136. 'exclam': 333,
  25137. 'quotedbl': 474,
  25138. 'numbersign': 556,
  25139. 'dollar': 556,
  25140. 'percent': 889,
  25141. 'ampersand': 722,
  25142. 'quoteright': 278,
  25143. 'parenleft': 333,
  25144. 'parenright': 333,
  25145. 'asterisk': 389,
  25146. 'plus': 584,
  25147. 'comma': 278,
  25148. 'hyphen': 333,
  25149. 'period': 278,
  25150. 'slash': 278,
  25151. 'zero': 556,
  25152. 'one': 556,
  25153. 'two': 556,
  25154. 'three': 556,
  25155. 'four': 556,
  25156. 'five': 556,
  25157. 'six': 556,
  25158. 'seven': 556,
  25159. 'eight': 556,
  25160. 'nine': 556,
  25161. 'colon': 333,
  25162. 'semicolon': 333,
  25163. 'less': 584,
  25164. 'equal': 584,
  25165. 'greater': 584,
  25166. 'question': 611,
  25167. 'at': 975,
  25168. 'A': 722,
  25169. 'B': 722,
  25170. 'C': 722,
  25171. 'D': 722,
  25172. 'E': 667,
  25173. 'F': 611,
  25174. 'G': 778,
  25175. 'H': 722,
  25176. 'I': 278,
  25177. 'J': 556,
  25178. 'K': 722,
  25179. 'L': 611,
  25180. 'M': 833,
  25181. 'N': 722,
  25182. 'O': 778,
  25183. 'P': 667,
  25184. 'Q': 778,
  25185. 'R': 722,
  25186. 'S': 667,
  25187. 'T': 611,
  25188. 'U': 722,
  25189. 'V': 667,
  25190. 'W': 944,
  25191. 'X': 667,
  25192. 'Y': 667,
  25193. 'Z': 611,
  25194. 'bracketleft': 333,
  25195. 'backslash': 278,
  25196. 'bracketright': 333,
  25197. 'asciicircum': 584,
  25198. 'underscore': 556,
  25199. 'quoteleft': 278,
  25200. 'a': 556,
  25201. 'b': 611,
  25202. 'c': 556,
  25203. 'd': 611,
  25204. 'e': 556,
  25205. 'f': 333,
  25206. 'g': 611,
  25207. 'h': 611,
  25208. 'i': 278,
  25209. 'j': 278,
  25210. 'k': 556,
  25211. 'l': 278,
  25212. 'm': 889,
  25213. 'n': 611,
  25214. 'o': 611,
  25215. 'p': 611,
  25216. 'q': 611,
  25217. 'r': 389,
  25218. 's': 556,
  25219. 't': 333,
  25220. 'u': 611,
  25221. 'v': 556,
  25222. 'w': 778,
  25223. 'x': 556,
  25224. 'y': 556,
  25225. 'z': 500,
  25226. 'braceleft': 389,
  25227. 'bar': 280,
  25228. 'braceright': 389,
  25229. 'asciitilde': 584,
  25230. 'exclamdown': 333,
  25231. 'cent': 556,
  25232. 'sterling': 556,
  25233. 'fraction': 167,
  25234. 'yen': 556,
  25235. 'florin': 556,
  25236. 'section': 556,
  25237. 'currency': 556,
  25238. 'quotesingle': 238,
  25239. 'quotedblleft': 500,
  25240. 'guillemotleft': 556,
  25241. 'guilsinglleft': 333,
  25242. 'guilsinglright': 333,
  25243. 'fi': 611,
  25244. 'fl': 611,
  25245. 'endash': 556,
  25246. 'dagger': 556,
  25247. 'daggerdbl': 556,
  25248. 'periodcentered': 278,
  25249. 'paragraph': 556,
  25250. 'bullet': 350,
  25251. 'quotesinglbase': 278,
  25252. 'quotedblbase': 500,
  25253. 'quotedblright': 500,
  25254. 'guillemotright': 556,
  25255. 'ellipsis': 1000,
  25256. 'perthousand': 1000,
  25257. 'questiondown': 611,
  25258. 'grave': 333,
  25259. 'acute': 333,
  25260. 'circumflex': 333,
  25261. 'tilde': 333,
  25262. 'macron': 333,
  25263. 'breve': 333,
  25264. 'dotaccent': 333,
  25265. 'dieresis': 333,
  25266. 'ring': 333,
  25267. 'cedilla': 333,
  25268. 'hungarumlaut': 333,
  25269. 'ogonek': 333,
  25270. 'caron': 333,
  25271. 'emdash': 1000,
  25272. 'AE': 1000,
  25273. 'ordfeminine': 370,
  25274. 'Lslash': 611,
  25275. 'Oslash': 778,
  25276. 'OE': 1000,
  25277. 'ordmasculine': 365,
  25278. 'ae': 889,
  25279. 'dotlessi': 278,
  25280. 'lslash': 278,
  25281. 'oslash': 611,
  25282. 'oe': 944,
  25283. 'germandbls': 611,
  25284. 'Idieresis': 278,
  25285. 'eacute': 556,
  25286. 'abreve': 556,
  25287. 'uhungarumlaut': 611,
  25288. 'ecaron': 556,
  25289. 'Ydieresis': 667,
  25290. 'divide': 584,
  25291. 'Yacute': 667,
  25292. 'Acircumflex': 722,
  25293. 'aacute': 556,
  25294. 'Ucircumflex': 722,
  25295. 'yacute': 556,
  25296. 'scommaaccent': 556,
  25297. 'ecircumflex': 556,
  25298. 'Uring': 722,
  25299. 'Udieresis': 722,
  25300. 'aogonek': 556,
  25301. 'Uacute': 722,
  25302. 'uogonek': 611,
  25303. 'Edieresis': 667,
  25304. 'Dcroat': 722,
  25305. 'commaaccent': 250,
  25306. 'copyright': 737,
  25307. 'Emacron': 667,
  25308. 'ccaron': 556,
  25309. 'aring': 556,
  25310. 'Ncommaaccent': 722,
  25311. 'lacute': 278,
  25312. 'agrave': 556,
  25313. 'Tcommaaccent': 611,
  25314. 'Cacute': 722,
  25315. 'atilde': 556,
  25316. 'Edotaccent': 667,
  25317. 'scaron': 556,
  25318. 'scedilla': 556,
  25319. 'iacute': 278,
  25320. 'lozenge': 494,
  25321. 'Rcaron': 722,
  25322. 'Gcommaaccent': 778,
  25323. 'ucircumflex': 611,
  25324. 'acircumflex': 556,
  25325. 'Amacron': 722,
  25326. 'rcaron': 389,
  25327. 'ccedilla': 556,
  25328. 'Zdotaccent': 611,
  25329. 'Thorn': 667,
  25330. 'Omacron': 778,
  25331. 'Racute': 722,
  25332. 'Sacute': 667,
  25333. 'dcaron': 743,
  25334. 'Umacron': 722,
  25335. 'uring': 611,
  25336. 'threesuperior': 333,
  25337. 'Ograve': 778,
  25338. 'Agrave': 722,
  25339. 'Abreve': 722,
  25340. 'multiply': 584,
  25341. 'uacute': 611,
  25342. 'Tcaron': 611,
  25343. 'partialdiff': 494,
  25344. 'ydieresis': 556,
  25345. 'Nacute': 722,
  25346. 'icircumflex': 278,
  25347. 'Ecircumflex': 667,
  25348. 'adieresis': 556,
  25349. 'edieresis': 556,
  25350. 'cacute': 556,
  25351. 'nacute': 611,
  25352. 'umacron': 611,
  25353. 'Ncaron': 722,
  25354. 'Iacute': 278,
  25355. 'plusminus': 584,
  25356. 'brokenbar': 280,
  25357. 'registered': 737,
  25358. 'Gbreve': 778,
  25359. 'Idotaccent': 278,
  25360. 'summation': 600,
  25361. 'Egrave': 667,
  25362. 'racute': 389,
  25363. 'omacron': 611,
  25364. 'Zacute': 611,
  25365. 'Zcaron': 611,
  25366. 'greaterequal': 549,
  25367. 'Eth': 722,
  25368. 'Ccedilla': 722,
  25369. 'lcommaaccent': 278,
  25370. 'tcaron': 389,
  25371. 'eogonek': 556,
  25372. 'Uogonek': 722,
  25373. 'Aacute': 722,
  25374. 'Adieresis': 722,
  25375. 'egrave': 556,
  25376. 'zacute': 500,
  25377. 'iogonek': 278,
  25378. 'Oacute': 778,
  25379. 'oacute': 611,
  25380. 'amacron': 556,
  25381. 'sacute': 556,
  25382. 'idieresis': 278,
  25383. 'Ocircumflex': 778,
  25384. 'Ugrave': 722,
  25385. 'Delta': 612,
  25386. 'thorn': 611,
  25387. 'twosuperior': 333,
  25388. 'Odieresis': 778,
  25389. 'mu': 611,
  25390. 'igrave': 278,
  25391. 'ohungarumlaut': 611,
  25392. 'Eogonek': 667,
  25393. 'dcroat': 611,
  25394. 'threequarters': 834,
  25395. 'Scedilla': 667,
  25396. 'lcaron': 400,
  25397. 'Kcommaaccent': 722,
  25398. 'Lacute': 611,
  25399. 'trademark': 1000,
  25400. 'edotaccent': 556,
  25401. 'Igrave': 278,
  25402. 'Imacron': 278,
  25403. 'Lcaron': 611,
  25404. 'onehalf': 834,
  25405. 'lessequal': 549,
  25406. 'ocircumflex': 611,
  25407. 'ntilde': 611,
  25408. 'Uhungarumlaut': 722,
  25409. 'Eacute': 667,
  25410. 'emacron': 556,
  25411. 'gbreve': 611,
  25412. 'onequarter': 834,
  25413. 'Scaron': 667,
  25414. 'Scommaaccent': 667,
  25415. 'Ohungarumlaut': 778,
  25416. 'degree': 400,
  25417. 'ograve': 611,
  25418. 'Ccaron': 722,
  25419. 'ugrave': 611,
  25420. 'radical': 549,
  25421. 'Dcaron': 722,
  25422. 'rcommaaccent': 389,
  25423. 'Ntilde': 722,
  25424. 'otilde': 611,
  25425. 'Rcommaaccent': 722,
  25426. 'Lcommaaccent': 611,
  25427. 'Atilde': 722,
  25428. 'Aogonek': 722,
  25429. 'Aring': 722,
  25430. 'Otilde': 778,
  25431. 'zdotaccent': 500,
  25432. 'Ecaron': 667,
  25433. 'Iogonek': 278,
  25434. 'kcommaaccent': 556,
  25435. 'minus': 584,
  25436. 'Icircumflex': 278,
  25437. 'ncaron': 611,
  25438. 'tcommaaccent': 333,
  25439. 'logicalnot': 584,
  25440. 'odieresis': 611,
  25441. 'udieresis': 611,
  25442. 'notequal': 549,
  25443. 'gcommaaccent': 611,
  25444. 'eth': 611,
  25445. 'zcaron': 500,
  25446. 'ncommaaccent': 611,
  25447. 'onesuperior': 333,
  25448. 'imacron': 278,
  25449. 'Euro': 556
  25450. },
  25451. 'Helvetica-Oblique' : {
  25452. 'space': 278,
  25453. 'exclam': 278,
  25454. 'quotedbl': 355,
  25455. 'numbersign': 556,
  25456. 'dollar': 556,
  25457. 'percent': 889,
  25458. 'ampersand': 667,
  25459. 'quoteright': 222,
  25460. 'parenleft': 333,
  25461. 'parenright': 333,
  25462. 'asterisk': 389,
  25463. 'plus': 584,
  25464. 'comma': 278,
  25465. 'hyphen': 333,
  25466. 'period': 278,
  25467. 'slash': 278,
  25468. 'zero': 556,
  25469. 'one': 556,
  25470. 'two': 556,
  25471. 'three': 556,
  25472. 'four': 556,
  25473. 'five': 556,
  25474. 'six': 556,
  25475. 'seven': 556,
  25476. 'eight': 556,
  25477. 'nine': 556,
  25478. 'colon': 278,
  25479. 'semicolon': 278,
  25480. 'less': 584,
  25481. 'equal': 584,
  25482. 'greater': 584,
  25483. 'question': 556,
  25484. 'at': 1015,
  25485. 'A': 667,
  25486. 'B': 667,
  25487. 'C': 722,
  25488. 'D': 722,
  25489. 'E': 667,
  25490. 'F': 611,
  25491. 'G': 778,
  25492. 'H': 722,
  25493. 'I': 278,
  25494. 'J': 500,
  25495. 'K': 667,
  25496. 'L': 556,
  25497. 'M': 833,
  25498. 'N': 722,
  25499. 'O': 778,
  25500. 'P': 667,
  25501. 'Q': 778,
  25502. 'R': 722,
  25503. 'S': 667,
  25504. 'T': 611,
  25505. 'U': 722,
  25506. 'V': 667,
  25507. 'W': 944,
  25508. 'X': 667,
  25509. 'Y': 667,
  25510. 'Z': 611,
  25511. 'bracketleft': 278,
  25512. 'backslash': 278,
  25513. 'bracketright': 278,
  25514. 'asciicircum': 469,
  25515. 'underscore': 556,
  25516. 'quoteleft': 222,
  25517. 'a': 556,
  25518. 'b': 556,
  25519. 'c': 500,
  25520. 'd': 556,
  25521. 'e': 556,
  25522. 'f': 278,
  25523. 'g': 556,
  25524. 'h': 556,
  25525. 'i': 222,
  25526. 'j': 222,
  25527. 'k': 500,
  25528. 'l': 222,
  25529. 'm': 833,
  25530. 'n': 556,
  25531. 'o': 556,
  25532. 'p': 556,
  25533. 'q': 556,
  25534. 'r': 333,
  25535. 's': 500,
  25536. 't': 278,
  25537. 'u': 556,
  25538. 'v': 500,
  25539. 'w': 722,
  25540. 'x': 500,
  25541. 'y': 500,
  25542. 'z': 500,
  25543. 'braceleft': 334,
  25544. 'bar': 260,
  25545. 'braceright': 334,
  25546. 'asciitilde': 584,
  25547. 'exclamdown': 333,
  25548. 'cent': 556,
  25549. 'sterling': 556,
  25550. 'fraction': 167,
  25551. 'yen': 556,
  25552. 'florin': 556,
  25553. 'section': 556,
  25554. 'currency': 556,
  25555. 'quotesingle': 191,
  25556. 'quotedblleft': 333,
  25557. 'guillemotleft': 556,
  25558. 'guilsinglleft': 333,
  25559. 'guilsinglright': 333,
  25560. 'fi': 500,
  25561. 'fl': 500,
  25562. 'endash': 556,
  25563. 'dagger': 556,
  25564. 'daggerdbl': 556,
  25565. 'periodcentered': 278,
  25566. 'paragraph': 537,
  25567. 'bullet': 350,
  25568. 'quotesinglbase': 222,
  25569. 'quotedblbase': 333,
  25570. 'quotedblright': 333,
  25571. 'guillemotright': 556,
  25572. 'ellipsis': 1000,
  25573. 'perthousand': 1000,
  25574. 'questiondown': 611,
  25575. 'grave': 333,
  25576. 'acute': 333,
  25577. 'circumflex': 333,
  25578. 'tilde': 333,
  25579. 'macron': 333,
  25580. 'breve': 333,
  25581. 'dotaccent': 333,
  25582. 'dieresis': 333,
  25583. 'ring': 333,
  25584. 'cedilla': 333,
  25585. 'hungarumlaut': 333,
  25586. 'ogonek': 333,
  25587. 'caron': 333,
  25588. 'emdash': 1000,
  25589. 'AE': 1000,
  25590. 'ordfeminine': 370,
  25591. 'Lslash': 556,
  25592. 'Oslash': 778,
  25593. 'OE': 1000,
  25594. 'ordmasculine': 365,
  25595. 'ae': 889,
  25596. 'dotlessi': 278,
  25597. 'lslash': 222,
  25598. 'oslash': 611,
  25599. 'oe': 944,
  25600. 'germandbls': 611,
  25601. 'Idieresis': 278,
  25602. 'eacute': 556,
  25603. 'abreve': 556,
  25604. 'uhungarumlaut': 556,
  25605. 'ecaron': 556,
  25606. 'Ydieresis': 667,
  25607. 'divide': 584,
  25608. 'Yacute': 667,
  25609. 'Acircumflex': 667,
  25610. 'aacute': 556,
  25611. 'Ucircumflex': 722,
  25612. 'yacute': 500,
  25613. 'scommaaccent': 500,
  25614. 'ecircumflex': 556,
  25615. 'Uring': 722,
  25616. 'Udieresis': 722,
  25617. 'aogonek': 556,
  25618. 'Uacute': 722,
  25619. 'uogonek': 556,
  25620. 'Edieresis': 667,
  25621. 'Dcroat': 722,
  25622. 'commaaccent': 250,
  25623. 'copyright': 737,
  25624. 'Emacron': 667,
  25625. 'ccaron': 500,
  25626. 'aring': 556,
  25627. 'Ncommaaccent': 722,
  25628. 'lacute': 222,
  25629. 'agrave': 556,
  25630. 'Tcommaaccent': 611,
  25631. 'Cacute': 722,
  25632. 'atilde': 556,
  25633. 'Edotaccent': 667,
  25634. 'scaron': 500,
  25635. 'scedilla': 500,
  25636. 'iacute': 278,
  25637. 'lozenge': 471,
  25638. 'Rcaron': 722,
  25639. 'Gcommaaccent': 778,
  25640. 'ucircumflex': 556,
  25641. 'acircumflex': 556,
  25642. 'Amacron': 667,
  25643. 'rcaron': 333,
  25644. 'ccedilla': 500,
  25645. 'Zdotaccent': 611,
  25646. 'Thorn': 667,
  25647. 'Omacron': 778,
  25648. 'Racute': 722,
  25649. 'Sacute': 667,
  25650. 'dcaron': 643,
  25651. 'Umacron': 722,
  25652. 'uring': 556,
  25653. 'threesuperior': 333,
  25654. 'Ograve': 778,
  25655. 'Agrave': 667,
  25656. 'Abreve': 667,
  25657. 'multiply': 584,
  25658. 'uacute': 556,
  25659. 'Tcaron': 611,
  25660. 'partialdiff': 476,
  25661. 'ydieresis': 500,
  25662. 'Nacute': 722,
  25663. 'icircumflex': 278,
  25664. 'Ecircumflex': 667,
  25665. 'adieresis': 556,
  25666. 'edieresis': 556,
  25667. 'cacute': 500,
  25668. 'nacute': 556,
  25669. 'umacron': 556,
  25670. 'Ncaron': 722,
  25671. 'Iacute': 278,
  25672. 'plusminus': 584,
  25673. 'brokenbar': 260,
  25674. 'registered': 737,
  25675. 'Gbreve': 778,
  25676. 'Idotaccent': 278,
  25677. 'summation': 600,
  25678. 'Egrave': 667,
  25679. 'racute': 333,
  25680. 'omacron': 556,
  25681. 'Zacute': 611,
  25682. 'Zcaron': 611,
  25683. 'greaterequal': 549,
  25684. 'Eth': 722,
  25685. 'Ccedilla': 722,
  25686. 'lcommaaccent': 222,
  25687. 'tcaron': 317,
  25688. 'eogonek': 556,
  25689. 'Uogonek': 722,
  25690. 'Aacute': 667,
  25691. 'Adieresis': 667,
  25692. 'egrave': 556,
  25693. 'zacute': 500,
  25694. 'iogonek': 222,
  25695. 'Oacute': 778,
  25696. 'oacute': 556,
  25697. 'amacron': 556,
  25698. 'sacute': 500,
  25699. 'idieresis': 278,
  25700. 'Ocircumflex': 778,
  25701. 'Ugrave': 722,
  25702. 'Delta': 612,
  25703. 'thorn': 556,
  25704. 'twosuperior': 333,
  25705. 'Odieresis': 778,
  25706. 'mu': 556,
  25707. 'igrave': 278,
  25708. 'ohungarumlaut': 556,
  25709. 'Eogonek': 667,
  25710. 'dcroat': 556,
  25711. 'threequarters': 834,
  25712. 'Scedilla': 667,
  25713. 'lcaron': 299,
  25714. 'Kcommaaccent': 667,
  25715. 'Lacute': 556,
  25716. 'trademark': 1000,
  25717. 'edotaccent': 556,
  25718. 'Igrave': 278,
  25719. 'Imacron': 278,
  25720. 'Lcaron': 556,
  25721. 'onehalf': 834,
  25722. 'lessequal': 549,
  25723. 'ocircumflex': 556,
  25724. 'ntilde': 556,
  25725. 'Uhungarumlaut': 722,
  25726. 'Eacute': 667,
  25727. 'emacron': 556,
  25728. 'gbreve': 556,
  25729. 'onequarter': 834,
  25730. 'Scaron': 667,
  25731. 'Scommaaccent': 667,
  25732. 'Ohungarumlaut': 778,
  25733. 'degree': 400,
  25734. 'ograve': 556,
  25735. 'Ccaron': 722,
  25736. 'ugrave': 556,
  25737. 'radical': 453,
  25738. 'Dcaron': 722,
  25739. 'rcommaaccent': 333,
  25740. 'Ntilde': 722,
  25741. 'otilde': 556,
  25742. 'Rcommaaccent': 722,
  25743. 'Lcommaaccent': 556,
  25744. 'Atilde': 667,
  25745. 'Aogonek': 667,
  25746. 'Aring': 667,
  25747. 'Otilde': 778,
  25748. 'zdotaccent': 500,
  25749. 'Ecaron': 667,
  25750. 'Iogonek': 278,
  25751. 'kcommaaccent': 500,
  25752. 'minus': 584,
  25753. 'Icircumflex': 278,
  25754. 'ncaron': 556,
  25755. 'tcommaaccent': 278,
  25756. 'logicalnot': 584,
  25757. 'odieresis': 556,
  25758. 'udieresis': 556,
  25759. 'notequal': 549,
  25760. 'gcommaaccent': 556,
  25761. 'eth': 556,
  25762. 'zcaron': 500,
  25763. 'ncommaaccent': 556,
  25764. 'onesuperior': 333,
  25765. 'imacron': 278,
  25766. 'Euro': 556
  25767. },
  25768. 'Symbol': {
  25769. 'space': 250,
  25770. 'exclam': 333,
  25771. 'universal': 713,
  25772. 'numbersign': 500,
  25773. 'existential': 549,
  25774. 'percent': 833,
  25775. 'ampersand': 778,
  25776. 'suchthat': 439,
  25777. 'parenleft': 333,
  25778. 'parenright': 333,
  25779. 'asteriskmath': 500,
  25780. 'plus': 549,
  25781. 'comma': 250,
  25782. 'minus': 549,
  25783. 'period': 250,
  25784. 'slash': 278,
  25785. 'zero': 500,
  25786. 'one': 500,
  25787. 'two': 500,
  25788. 'three': 500,
  25789. 'four': 500,
  25790. 'five': 500,
  25791. 'six': 500,
  25792. 'seven': 500,
  25793. 'eight': 500,
  25794. 'nine': 500,
  25795. 'colon': 278,
  25796. 'semicolon': 278,
  25797. 'less': 549,
  25798. 'equal': 549,
  25799. 'greater': 549,
  25800. 'question': 444,
  25801. 'congruent': 549,
  25802. 'Alpha': 722,
  25803. 'Beta': 667,
  25804. 'Chi': 722,
  25805. 'Delta': 612,
  25806. 'Epsilon': 611,
  25807. 'Phi': 763,
  25808. 'Gamma': 603,
  25809. 'Eta': 722,
  25810. 'Iota': 333,
  25811. 'theta1': 631,
  25812. 'Kappa': 722,
  25813. 'Lambda': 686,
  25814. 'Mu': 889,
  25815. 'Nu': 722,
  25816. 'Omicron': 722,
  25817. 'Pi': 768,
  25818. 'Theta': 741,
  25819. 'Rho': 556,
  25820. 'Sigma': 592,
  25821. 'Tau': 611,
  25822. 'Upsilon': 690,
  25823. 'sigma1': 439,
  25824. 'Omega': 768,
  25825. 'Xi': 645,
  25826. 'Psi': 795,
  25827. 'Zeta': 611,
  25828. 'bracketleft': 333,
  25829. 'therefore': 863,
  25830. 'bracketright': 333,
  25831. 'perpendicular': 658,
  25832. 'underscore': 500,
  25833. 'radicalex': 500,
  25834. 'alpha': 631,
  25835. 'beta': 549,
  25836. 'chi': 549,
  25837. 'delta': 494,
  25838. 'epsilon': 439,
  25839. 'phi': 521,
  25840. 'gamma': 411,
  25841. 'eta': 603,
  25842. 'iota': 329,
  25843. 'phi1': 603,
  25844. 'kappa': 549,
  25845. 'lambda': 549,
  25846. 'mu': 576,
  25847. 'nu': 521,
  25848. 'omicron': 549,
  25849. 'pi': 549,
  25850. 'theta': 521,
  25851. 'rho': 549,
  25852. 'sigma': 603,
  25853. 'tau': 439,
  25854. 'upsilon': 576,
  25855. 'omega1': 713,
  25856. 'omega': 686,
  25857. 'xi': 493,
  25858. 'psi': 686,
  25859. 'zeta': 494,
  25860. 'braceleft': 480,
  25861. 'bar': 200,
  25862. 'braceright': 480,
  25863. 'similar': 549,
  25864. 'Euro': 750,
  25865. 'Upsilon1': 620,
  25866. 'minute': 247,
  25867. 'lessequal': 549,
  25868. 'fraction': 167,
  25869. 'infinity': 713,
  25870. 'florin': 500,
  25871. 'club': 753,
  25872. 'diamond': 753,
  25873. 'heart': 753,
  25874. 'spade': 753,
  25875. 'arrowboth': 1042,
  25876. 'arrowleft': 987,
  25877. 'arrowup': 603,
  25878. 'arrowright': 987,
  25879. 'arrowdown': 603,
  25880. 'degree': 400,
  25881. 'plusminus': 549,
  25882. 'second': 411,
  25883. 'greaterequal': 549,
  25884. 'multiply': 549,
  25885. 'proportional': 713,
  25886. 'partialdiff': 494,
  25887. 'bullet': 460,
  25888. 'divide': 549,
  25889. 'notequal': 549,
  25890. 'equivalence': 549,
  25891. 'approxequal': 549,
  25892. 'ellipsis': 1000,
  25893. 'arrowvertex': 603,
  25894. 'arrowhorizex': 1000,
  25895. 'carriagereturn': 658,
  25896. 'aleph': 823,
  25897. 'Ifraktur': 686,
  25898. 'Rfraktur': 795,
  25899. 'weierstrass': 987,
  25900. 'circlemultiply': 768,
  25901. 'circleplus': 768,
  25902. 'emptyset': 823,
  25903. 'intersection': 768,
  25904. 'union': 768,
  25905. 'propersuperset': 713,
  25906. 'reflexsuperset': 713,
  25907. 'notsubset': 713,
  25908. 'propersubset': 713,
  25909. 'reflexsubset': 713,
  25910. 'element': 713,
  25911. 'notelement': 713,
  25912. 'angle': 768,
  25913. 'gradient': 713,
  25914. 'registerserif': 790,
  25915. 'copyrightserif': 790,
  25916. 'trademarkserif': 890,
  25917. 'product': 823,
  25918. 'radical': 549,
  25919. 'dotmath': 250,
  25920. 'logicalnot': 713,
  25921. 'logicaland': 603,
  25922. 'logicalor': 603,
  25923. 'arrowdblboth': 1042,
  25924. 'arrowdblleft': 987,
  25925. 'arrowdblup': 603,
  25926. 'arrowdblright': 987,
  25927. 'arrowdbldown': 603,
  25928. 'lozenge': 494,
  25929. 'angleleft': 329,
  25930. 'registersans': 790,
  25931. 'copyrightsans': 790,
  25932. 'trademarksans': 786,
  25933. 'summation': 713,
  25934. 'parenlefttp': 384,
  25935. 'parenleftex': 384,
  25936. 'parenleftbt': 384,
  25937. 'bracketlefttp': 384,
  25938. 'bracketleftex': 384,
  25939. 'bracketleftbt': 384,
  25940. 'bracelefttp': 494,
  25941. 'braceleftmid': 494,
  25942. 'braceleftbt': 494,
  25943. 'braceex': 494,
  25944. 'angleright': 329,
  25945. 'integral': 274,
  25946. 'integraltp': 686,
  25947. 'integralex': 686,
  25948. 'integralbt': 686,
  25949. 'parenrighttp': 384,
  25950. 'parenrightex': 384,
  25951. 'parenrightbt': 384,
  25952. 'bracketrighttp': 384,
  25953. 'bracketrightex': 384,
  25954. 'bracketrightbt': 384,
  25955. 'bracerighttp': 494,
  25956. 'bracerightmid': 494,
  25957. 'bracerightbt': 494,
  25958. 'apple': 790
  25959. },
  25960. 'Times-Roman': {
  25961. 'space': 250,
  25962. 'exclam': 333,
  25963. 'quotedbl': 408,
  25964. 'numbersign': 500,
  25965. 'dollar': 500,
  25966. 'percent': 833,
  25967. 'ampersand': 778,
  25968. 'quoteright': 333,
  25969. 'parenleft': 333,
  25970. 'parenright': 333,
  25971. 'asterisk': 500,
  25972. 'plus': 564,
  25973. 'comma': 250,
  25974. 'hyphen': 333,
  25975. 'period': 250,
  25976. 'slash': 278,
  25977. 'zero': 500,
  25978. 'one': 500,
  25979. 'two': 500,
  25980. 'three': 500,
  25981. 'four': 500,
  25982. 'five': 500,
  25983. 'six': 500,
  25984. 'seven': 500,
  25985. 'eight': 500,
  25986. 'nine': 500,
  25987. 'colon': 278,
  25988. 'semicolon': 278,
  25989. 'less': 564,
  25990. 'equal': 564,
  25991. 'greater': 564,
  25992. 'question': 444,
  25993. 'at': 921,
  25994. 'A': 722,
  25995. 'B': 667,
  25996. 'C': 667,
  25997. 'D': 722,
  25998. 'E': 611,
  25999. 'F': 556,
  26000. 'G': 722,
  26001. 'H': 722,
  26002. 'I': 333,
  26003. 'J': 389,
  26004. 'K': 722,
  26005. 'L': 611,
  26006. 'M': 889,
  26007. 'N': 722,
  26008. 'O': 722,
  26009. 'P': 556,
  26010. 'Q': 722,
  26011. 'R': 667,
  26012. 'S': 556,
  26013. 'T': 611,
  26014. 'U': 722,
  26015. 'V': 722,
  26016. 'W': 944,
  26017. 'X': 722,
  26018. 'Y': 722,
  26019. 'Z': 611,
  26020. 'bracketleft': 333,
  26021. 'backslash': 278,
  26022. 'bracketright': 333,
  26023. 'asciicircum': 469,
  26024. 'underscore': 500,
  26025. 'quoteleft': 333,
  26026. 'a': 444,
  26027. 'b': 500,
  26028. 'c': 444,
  26029. 'd': 500,
  26030. 'e': 444,
  26031. 'f': 333,
  26032. 'g': 500,
  26033. 'h': 500,
  26034. 'i': 278,
  26035. 'j': 278,
  26036. 'k': 500,
  26037. 'l': 278,
  26038. 'm': 778,
  26039. 'n': 500,
  26040. 'o': 500,
  26041. 'p': 500,
  26042. 'q': 500,
  26043. 'r': 333,
  26044. 's': 389,
  26045. 't': 278,
  26046. 'u': 500,
  26047. 'v': 500,
  26048. 'w': 722,
  26049. 'x': 500,
  26050. 'y': 500,
  26051. 'z': 444,
  26052. 'braceleft': 480,
  26053. 'bar': 200,
  26054. 'braceright': 480,
  26055. 'asciitilde': 541,
  26056. 'exclamdown': 333,
  26057. 'cent': 500,
  26058. 'sterling': 500,
  26059. 'fraction': 167,
  26060. 'yen': 500,
  26061. 'florin': 500,
  26062. 'section': 500,
  26063. 'currency': 500,
  26064. 'quotesingle': 180,
  26065. 'quotedblleft': 444,
  26066. 'guillemotleft': 500,
  26067. 'guilsinglleft': 333,
  26068. 'guilsinglright': 333,
  26069. 'fi': 556,
  26070. 'fl': 556,
  26071. 'endash': 500,
  26072. 'dagger': 500,
  26073. 'daggerdbl': 500,
  26074. 'periodcentered': 250,
  26075. 'paragraph': 453,
  26076. 'bullet': 350,
  26077. 'quotesinglbase': 333,
  26078. 'quotedblbase': 444,
  26079. 'quotedblright': 444,
  26080. 'guillemotright': 500,
  26081. 'ellipsis': 1000,
  26082. 'perthousand': 1000,
  26083. 'questiondown': 444,
  26084. 'grave': 333,
  26085. 'acute': 333,
  26086. 'circumflex': 333,
  26087. 'tilde': 333,
  26088. 'macron': 333,
  26089. 'breve': 333,
  26090. 'dotaccent': 333,
  26091. 'dieresis': 333,
  26092. 'ring': 333,
  26093. 'cedilla': 333,
  26094. 'hungarumlaut': 333,
  26095. 'ogonek': 333,
  26096. 'caron': 333,
  26097. 'emdash': 1000,
  26098. 'AE': 889,
  26099. 'ordfeminine': 276,
  26100. 'Lslash': 611,
  26101. 'Oslash': 722,
  26102. 'OE': 889,
  26103. 'ordmasculine': 310,
  26104. 'ae': 667,
  26105. 'dotlessi': 278,
  26106. 'lslash': 278,
  26107. 'oslash': 500,
  26108. 'oe': 722,
  26109. 'germandbls': 500,
  26110. 'Idieresis': 333,
  26111. 'eacute': 444,
  26112. 'abreve': 444,
  26113. 'uhungarumlaut': 500,
  26114. 'ecaron': 444,
  26115. 'Ydieresis': 722,
  26116. 'divide': 564,
  26117. 'Yacute': 722,
  26118. 'Acircumflex': 722,
  26119. 'aacute': 444,
  26120. 'Ucircumflex': 722,
  26121. 'yacute': 500,
  26122. 'scommaaccent': 389,
  26123. 'ecircumflex': 444,
  26124. 'Uring': 722,
  26125. 'Udieresis': 722,
  26126. 'aogonek': 444,
  26127. 'Uacute': 722,
  26128. 'uogonek': 500,
  26129. 'Edieresis': 611,
  26130. 'Dcroat': 722,
  26131. 'commaaccent': 250,
  26132. 'copyright': 760,
  26133. 'Emacron': 611,
  26134. 'ccaron': 444,
  26135. 'aring': 444,
  26136. 'Ncommaaccent': 722,
  26137. 'lacute': 278,
  26138. 'agrave': 444,
  26139. 'Tcommaaccent': 611,
  26140. 'Cacute': 667,
  26141. 'atilde': 444,
  26142. 'Edotaccent': 611,
  26143. 'scaron': 389,
  26144. 'scedilla': 389,
  26145. 'iacute': 278,
  26146. 'lozenge': 471,
  26147. 'Rcaron': 667,
  26148. 'Gcommaaccent': 722,
  26149. 'ucircumflex': 500,
  26150. 'acircumflex': 444,
  26151. 'Amacron': 722,
  26152. 'rcaron': 333,
  26153. 'ccedilla': 444,
  26154. 'Zdotaccent': 611,
  26155. 'Thorn': 556,
  26156. 'Omacron': 722,
  26157. 'Racute': 667,
  26158. 'Sacute': 556,
  26159. 'dcaron': 588,
  26160. 'Umacron': 722,
  26161. 'uring': 500,
  26162. 'threesuperior': 300,
  26163. 'Ograve': 722,
  26164. 'Agrave': 722,
  26165. 'Abreve': 722,
  26166. 'multiply': 564,
  26167. 'uacute': 500,
  26168. 'Tcaron': 611,
  26169. 'partialdiff': 476,
  26170. 'ydieresis': 500,
  26171. 'Nacute': 722,
  26172. 'icircumflex': 278,
  26173. 'Ecircumflex': 611,
  26174. 'adieresis': 444,
  26175. 'edieresis': 444,
  26176. 'cacute': 444,
  26177. 'nacute': 500,
  26178. 'umacron': 500,
  26179. 'Ncaron': 722,
  26180. 'Iacute': 333,
  26181. 'plusminus': 564,
  26182. 'brokenbar': 200,
  26183. 'registered': 760,
  26184. 'Gbreve': 722,
  26185. 'Idotaccent': 333,
  26186. 'summation': 600,
  26187. 'Egrave': 611,
  26188. 'racute': 333,
  26189. 'omacron': 500,
  26190. 'Zacute': 611,
  26191. 'Zcaron': 611,
  26192. 'greaterequal': 549,
  26193. 'Eth': 722,
  26194. 'Ccedilla': 667,
  26195. 'lcommaaccent': 278,
  26196. 'tcaron': 326,
  26197. 'eogonek': 444,
  26198. 'Uogonek': 722,
  26199. 'Aacute': 722,
  26200. 'Adieresis': 722,
  26201. 'egrave': 444,
  26202. 'zacute': 444,
  26203. 'iogonek': 278,
  26204. 'Oacute': 722,
  26205. 'oacute': 500,
  26206. 'amacron': 444,
  26207. 'sacute': 389,
  26208. 'idieresis': 278,
  26209. 'Ocircumflex': 722,
  26210. 'Ugrave': 722,
  26211. 'Delta': 612,
  26212. 'thorn': 500,
  26213. 'twosuperior': 300,
  26214. 'Odieresis': 722,
  26215. 'mu': 500,
  26216. 'igrave': 278,
  26217. 'ohungarumlaut': 500,
  26218. 'Eogonek': 611,
  26219. 'dcroat': 500,
  26220. 'threequarters': 750,
  26221. 'Scedilla': 556,
  26222. 'lcaron': 344,
  26223. 'Kcommaaccent': 722,
  26224. 'Lacute': 611,
  26225. 'trademark': 980,
  26226. 'edotaccent': 444,
  26227. 'Igrave': 333,
  26228. 'Imacron': 333,
  26229. 'Lcaron': 611,
  26230. 'onehalf': 750,
  26231. 'lessequal': 549,
  26232. 'ocircumflex': 500,
  26233. 'ntilde': 500,
  26234. 'Uhungarumlaut': 722,
  26235. 'Eacute': 611,
  26236. 'emacron': 444,
  26237. 'gbreve': 500,
  26238. 'onequarter': 750,
  26239. 'Scaron': 556,
  26240. 'Scommaaccent': 556,
  26241. 'Ohungarumlaut': 722,
  26242. 'degree': 400,
  26243. 'ograve': 500,
  26244. 'Ccaron': 667,
  26245. 'ugrave': 500,
  26246. 'radical': 453,
  26247. 'Dcaron': 722,
  26248. 'rcommaaccent': 333,
  26249. 'Ntilde': 722,
  26250. 'otilde': 500,
  26251. 'Rcommaaccent': 667,
  26252. 'Lcommaaccent': 611,
  26253. 'Atilde': 722,
  26254. 'Aogonek': 722,
  26255. 'Aring': 722,
  26256. 'Otilde': 722,
  26257. 'zdotaccent': 444,
  26258. 'Ecaron': 611,
  26259. 'Iogonek': 333,
  26260. 'kcommaaccent': 500,
  26261. 'minus': 564,
  26262. 'Icircumflex': 333,
  26263. 'ncaron': 500,
  26264. 'tcommaaccent': 278,
  26265. 'logicalnot': 564,
  26266. 'odieresis': 500,
  26267. 'udieresis': 500,
  26268. 'notequal': 549,
  26269. 'gcommaaccent': 500,
  26270. 'eth': 500,
  26271. 'zcaron': 444,
  26272. 'ncommaaccent': 500,
  26273. 'onesuperior': 300,
  26274. 'imacron': 278,
  26275. 'Euro': 500
  26276. },
  26277. 'Times-Bold': {
  26278. 'space': 250,
  26279. 'exclam': 333,
  26280. 'quotedbl': 555,
  26281. 'numbersign': 500,
  26282. 'dollar': 500,
  26283. 'percent': 1000,
  26284. 'ampersand': 833,
  26285. 'quoteright': 333,
  26286. 'parenleft': 333,
  26287. 'parenright': 333,
  26288. 'asterisk': 500,
  26289. 'plus': 570,
  26290. 'comma': 250,
  26291. 'hyphen': 333,
  26292. 'period': 250,
  26293. 'slash': 278,
  26294. 'zero': 500,
  26295. 'one': 500,
  26296. 'two': 500,
  26297. 'three': 500,
  26298. 'four': 500,
  26299. 'five': 500,
  26300. 'six': 500,
  26301. 'seven': 500,
  26302. 'eight': 500,
  26303. 'nine': 500,
  26304. 'colon': 333,
  26305. 'semicolon': 333,
  26306. 'less': 570,
  26307. 'equal': 570,
  26308. 'greater': 570,
  26309. 'question': 500,
  26310. 'at': 930,
  26311. 'A': 722,
  26312. 'B': 667,
  26313. 'C': 722,
  26314. 'D': 722,
  26315. 'E': 667,
  26316. 'F': 611,
  26317. 'G': 778,
  26318. 'H': 778,
  26319. 'I': 389,
  26320. 'J': 500,
  26321. 'K': 778,
  26322. 'L': 667,
  26323. 'M': 944,
  26324. 'N': 722,
  26325. 'O': 778,
  26326. 'P': 611,
  26327. 'Q': 778,
  26328. 'R': 722,
  26329. 'S': 556,
  26330. 'T': 667,
  26331. 'U': 722,
  26332. 'V': 722,
  26333. 'W': 1000,
  26334. 'X': 722,
  26335. 'Y': 722,
  26336. 'Z': 667,
  26337. 'bracketleft': 333,
  26338. 'backslash': 278,
  26339. 'bracketright': 333,
  26340. 'asciicircum': 581,
  26341. 'underscore': 500,
  26342. 'quoteleft': 333,
  26343. 'a': 500,
  26344. 'b': 556,
  26345. 'c': 444,
  26346. 'd': 556,
  26347. 'e': 444,
  26348. 'f': 333,
  26349. 'g': 500,
  26350. 'h': 556,
  26351. 'i': 278,
  26352. 'j': 333,
  26353. 'k': 556,
  26354. 'l': 278,
  26355. 'm': 833,
  26356. 'n': 556,
  26357. 'o': 500,
  26358. 'p': 556,
  26359. 'q': 556,
  26360. 'r': 444,
  26361. 's': 389,
  26362. 't': 333,
  26363. 'u': 556,
  26364. 'v': 500,
  26365. 'w': 722,
  26366. 'x': 500,
  26367. 'y': 500,
  26368. 'z': 444,
  26369. 'braceleft': 394,
  26370. 'bar': 220,
  26371. 'braceright': 394,
  26372. 'asciitilde': 520,
  26373. 'exclamdown': 333,
  26374. 'cent': 500,
  26375. 'sterling': 500,
  26376. 'fraction': 167,
  26377. 'yen': 500,
  26378. 'florin': 500,
  26379. 'section': 500,
  26380. 'currency': 500,
  26381. 'quotesingle': 278,
  26382. 'quotedblleft': 500,
  26383. 'guillemotleft': 500,
  26384. 'guilsinglleft': 333,
  26385. 'guilsinglright': 333,
  26386. 'fi': 556,
  26387. 'fl': 556,
  26388. 'endash': 500,
  26389. 'dagger': 500,
  26390. 'daggerdbl': 500,
  26391. 'periodcentered': 250,
  26392. 'paragraph': 540,
  26393. 'bullet': 350,
  26394. 'quotesinglbase': 333,
  26395. 'quotedblbase': 500,
  26396. 'quotedblright': 500,
  26397. 'guillemotright': 500,
  26398. 'ellipsis': 1000,
  26399. 'perthousand': 1000,
  26400. 'questiondown': 500,
  26401. 'grave': 333,
  26402. 'acute': 333,
  26403. 'circumflex': 333,
  26404. 'tilde': 333,
  26405. 'macron': 333,
  26406. 'breve': 333,
  26407. 'dotaccent': 333,
  26408. 'dieresis': 333,
  26409. 'ring': 333,
  26410. 'cedilla': 333,
  26411. 'hungarumlaut': 333,
  26412. 'ogonek': 333,
  26413. 'caron': 333,
  26414. 'emdash': 1000,
  26415. 'AE': 1000,
  26416. 'ordfeminine': 300,
  26417. 'Lslash': 667,
  26418. 'Oslash': 778,
  26419. 'OE': 1000,
  26420. 'ordmasculine': 330,
  26421. 'ae': 722,
  26422. 'dotlessi': 278,
  26423. 'lslash': 278,
  26424. 'oslash': 500,
  26425. 'oe': 722,
  26426. 'germandbls': 556,
  26427. 'Idieresis': 389,
  26428. 'eacute': 444,
  26429. 'abreve': 500,
  26430. 'uhungarumlaut': 556,
  26431. 'ecaron': 444,
  26432. 'Ydieresis': 722,
  26433. 'divide': 570,
  26434. 'Yacute': 722,
  26435. 'Acircumflex': 722,
  26436. 'aacute': 500,
  26437. 'Ucircumflex': 722,
  26438. 'yacute': 500,
  26439. 'scommaaccent': 389,
  26440. 'ecircumflex': 444,
  26441. 'Uring': 722,
  26442. 'Udieresis': 722,
  26443. 'aogonek': 500,
  26444. 'Uacute': 722,
  26445. 'uogonek': 556,
  26446. 'Edieresis': 667,
  26447. 'Dcroat': 722,
  26448. 'commaaccent': 250,
  26449. 'copyright': 747,
  26450. 'Emacron': 667,
  26451. 'ccaron': 444,
  26452. 'aring': 500,
  26453. 'Ncommaaccent': 722,
  26454. 'lacute': 278,
  26455. 'agrave': 500,
  26456. 'Tcommaaccent': 667,
  26457. 'Cacute': 722,
  26458. 'atilde': 500,
  26459. 'Edotaccent': 667,
  26460. 'scaron': 389,
  26461. 'scedilla': 389,
  26462. 'iacute': 278,
  26463. 'lozenge': 494,
  26464. 'Rcaron': 722,
  26465. 'Gcommaaccent': 778,
  26466. 'ucircumflex': 556,
  26467. 'acircumflex': 500,
  26468. 'Amacron': 722,
  26469. 'rcaron': 444,
  26470. 'ccedilla': 444,
  26471. 'Zdotaccent': 667,
  26472. 'Thorn': 611,
  26473. 'Omacron': 778,
  26474. 'Racute': 722,
  26475. 'Sacute': 556,
  26476. 'dcaron': 672,
  26477. 'Umacron': 722,
  26478. 'uring': 556,
  26479. 'threesuperior': 300,
  26480. 'Ograve': 778,
  26481. 'Agrave': 722,
  26482. 'Abreve': 722,
  26483. 'multiply': 570,
  26484. 'uacute': 556,
  26485. 'Tcaron': 667,
  26486. 'partialdiff': 494,
  26487. 'ydieresis': 500,
  26488. 'Nacute': 722,
  26489. 'icircumflex': 278,
  26490. 'Ecircumflex': 667,
  26491. 'adieresis': 500,
  26492. 'edieresis': 444,
  26493. 'cacute': 444,
  26494. 'nacute': 556,
  26495. 'umacron': 556,
  26496. 'Ncaron': 722,
  26497. 'Iacute': 389,
  26498. 'plusminus': 570,
  26499. 'brokenbar': 220,
  26500. 'registered': 747,
  26501. 'Gbreve': 778,
  26502. 'Idotaccent': 389,
  26503. 'summation': 600,
  26504. 'Egrave': 667,
  26505. 'racute': 444,
  26506. 'omacron': 500,
  26507. 'Zacute': 667,
  26508. 'Zcaron': 667,
  26509. 'greaterequal': 549,
  26510. 'Eth': 722,
  26511. 'Ccedilla': 722,
  26512. 'lcommaaccent': 278,
  26513. 'tcaron': 416,
  26514. 'eogonek': 444,
  26515. 'Uogonek': 722,
  26516. 'Aacute': 722,
  26517. 'Adieresis': 722,
  26518. 'egrave': 444,
  26519. 'zacute': 444,
  26520. 'iogonek': 278,
  26521. 'Oacute': 778,
  26522. 'oacute': 500,
  26523. 'amacron': 500,
  26524. 'sacute': 389,
  26525. 'idieresis': 278,
  26526. 'Ocircumflex': 778,
  26527. 'Ugrave': 722,
  26528. 'Delta': 612,
  26529. 'thorn': 556,
  26530. 'twosuperior': 300,
  26531. 'Odieresis': 778,
  26532. 'mu': 556,
  26533. 'igrave': 278,
  26534. 'ohungarumlaut': 500,
  26535. 'Eogonek': 667,
  26536. 'dcroat': 556,
  26537. 'threequarters': 750,
  26538. 'Scedilla': 556,
  26539. 'lcaron': 394,
  26540. 'Kcommaaccent': 778,
  26541. 'Lacute': 667,
  26542. 'trademark': 1000,
  26543. 'edotaccent': 444,
  26544. 'Igrave': 389,
  26545. 'Imacron': 389,
  26546. 'Lcaron': 667,
  26547. 'onehalf': 750,
  26548. 'lessequal': 549,
  26549. 'ocircumflex': 500,
  26550. 'ntilde': 556,
  26551. 'Uhungarumlaut': 722,
  26552. 'Eacute': 667,
  26553. 'emacron': 444,
  26554. 'gbreve': 500,
  26555. 'onequarter': 750,
  26556. 'Scaron': 556,
  26557. 'Scommaaccent': 556,
  26558. 'Ohungarumlaut': 778,
  26559. 'degree': 400,
  26560. 'ograve': 500,
  26561. 'Ccaron': 722,
  26562. 'ugrave': 556,
  26563. 'radical': 549,
  26564. 'Dcaron': 722,
  26565. 'rcommaaccent': 444,
  26566. 'Ntilde': 722,
  26567. 'otilde': 500,
  26568. 'Rcommaaccent': 722,
  26569. 'Lcommaaccent': 667,
  26570. 'Atilde': 722,
  26571. 'Aogonek': 722,
  26572. 'Aring': 722,
  26573. 'Otilde': 778,
  26574. 'zdotaccent': 444,
  26575. 'Ecaron': 667,
  26576. 'Iogonek': 389,
  26577. 'kcommaaccent': 556,
  26578. 'minus': 570,
  26579. 'Icircumflex': 389,
  26580. 'ncaron': 556,
  26581. 'tcommaaccent': 333,
  26582. 'logicalnot': 570,
  26583. 'odieresis': 500,
  26584. 'udieresis': 556,
  26585. 'notequal': 549,
  26586. 'gcommaaccent': 500,
  26587. 'eth': 500,
  26588. 'zcaron': 444,
  26589. 'ncommaaccent': 556,
  26590. 'onesuperior': 300,
  26591. 'imacron': 278,
  26592. 'Euro': 500
  26593. },
  26594. 'Times-BoldItalic': {
  26595. 'space': 250,
  26596. 'exclam': 389,
  26597. 'quotedbl': 555,
  26598. 'numbersign': 500,
  26599. 'dollar': 500,
  26600. 'percent': 833,
  26601. 'ampersand': 778,
  26602. 'quoteright': 333,
  26603. 'parenleft': 333,
  26604. 'parenright': 333,
  26605. 'asterisk': 500,
  26606. 'plus': 570,
  26607. 'comma': 250,
  26608. 'hyphen': 333,
  26609. 'period': 250,
  26610. 'slash': 278,
  26611. 'zero': 500,
  26612. 'one': 500,
  26613. 'two': 500,
  26614. 'three': 500,
  26615. 'four': 500,
  26616. 'five': 500,
  26617. 'six': 500,
  26618. 'seven': 500,
  26619. 'eight': 500,
  26620. 'nine': 500,
  26621. 'colon': 333,
  26622. 'semicolon': 333,
  26623. 'less': 570,
  26624. 'equal': 570,
  26625. 'greater': 570,
  26626. 'question': 500,
  26627. 'at': 832,
  26628. 'A': 667,
  26629. 'B': 667,
  26630. 'C': 667,
  26631. 'D': 722,
  26632. 'E': 667,
  26633. 'F': 667,
  26634. 'G': 722,
  26635. 'H': 778,
  26636. 'I': 389,
  26637. 'J': 500,
  26638. 'K': 667,
  26639. 'L': 611,
  26640. 'M': 889,
  26641. 'N': 722,
  26642. 'O': 722,
  26643. 'P': 611,
  26644. 'Q': 722,
  26645. 'R': 667,
  26646. 'S': 556,
  26647. 'T': 611,
  26648. 'U': 722,
  26649. 'V': 667,
  26650. 'W': 889,
  26651. 'X': 667,
  26652. 'Y': 611,
  26653. 'Z': 611,
  26654. 'bracketleft': 333,
  26655. 'backslash': 278,
  26656. 'bracketright': 333,
  26657. 'asciicircum': 570,
  26658. 'underscore': 500,
  26659. 'quoteleft': 333,
  26660. 'a': 500,
  26661. 'b': 500,
  26662. 'c': 444,
  26663. 'd': 500,
  26664. 'e': 444,
  26665. 'f': 333,
  26666. 'g': 500,
  26667. 'h': 556,
  26668. 'i': 278,
  26669. 'j': 278,
  26670. 'k': 500,
  26671. 'l': 278,
  26672. 'm': 778,
  26673. 'n': 556,
  26674. 'o': 500,
  26675. 'p': 500,
  26676. 'q': 500,
  26677. 'r': 389,
  26678. 's': 389,
  26679. 't': 278,
  26680. 'u': 556,
  26681. 'v': 444,
  26682. 'w': 667,
  26683. 'x': 500,
  26684. 'y': 444,
  26685. 'z': 389,
  26686. 'braceleft': 348,
  26687. 'bar': 220,
  26688. 'braceright': 348,
  26689. 'asciitilde': 570,
  26690. 'exclamdown': 389,
  26691. 'cent': 500,
  26692. 'sterling': 500,
  26693. 'fraction': 167,
  26694. 'yen': 500,
  26695. 'florin': 500,
  26696. 'section': 500,
  26697. 'currency': 500,
  26698. 'quotesingle': 278,
  26699. 'quotedblleft': 500,
  26700. 'guillemotleft': 500,
  26701. 'guilsinglleft': 333,
  26702. 'guilsinglright': 333,
  26703. 'fi': 556,
  26704. 'fl': 556,
  26705. 'endash': 500,
  26706. 'dagger': 500,
  26707. 'daggerdbl': 500,
  26708. 'periodcentered': 250,
  26709. 'paragraph': 500,
  26710. 'bullet': 350,
  26711. 'quotesinglbase': 333,
  26712. 'quotedblbase': 500,
  26713. 'quotedblright': 500,
  26714. 'guillemotright': 500,
  26715. 'ellipsis': 1000,
  26716. 'perthousand': 1000,
  26717. 'questiondown': 500,
  26718. 'grave': 333,
  26719. 'acute': 333,
  26720. 'circumflex': 333,
  26721. 'tilde': 333,
  26722. 'macron': 333,
  26723. 'breve': 333,
  26724. 'dotaccent': 333,
  26725. 'dieresis': 333,
  26726. 'ring': 333,
  26727. 'cedilla': 333,
  26728. 'hungarumlaut': 333,
  26729. 'ogonek': 333,
  26730. 'caron': 333,
  26731. 'emdash': 1000,
  26732. 'AE': 944,
  26733. 'ordfeminine': 266,
  26734. 'Lslash': 611,
  26735. 'Oslash': 722,
  26736. 'OE': 944,
  26737. 'ordmasculine': 300,
  26738. 'ae': 722,
  26739. 'dotlessi': 278,
  26740. 'lslash': 278,
  26741. 'oslash': 500,
  26742. 'oe': 722,
  26743. 'germandbls': 500,
  26744. 'Idieresis': 389,
  26745. 'eacute': 444,
  26746. 'abreve': 500,
  26747. 'uhungarumlaut': 556,
  26748. 'ecaron': 444,
  26749. 'Ydieresis': 611,
  26750. 'divide': 570,
  26751. 'Yacute': 611,
  26752. 'Acircumflex': 667,
  26753. 'aacute': 500,
  26754. 'Ucircumflex': 722,
  26755. 'yacute': 444,
  26756. 'scommaaccent': 389,
  26757. 'ecircumflex': 444,
  26758. 'Uring': 722,
  26759. 'Udieresis': 722,
  26760. 'aogonek': 500,
  26761. 'Uacute': 722,
  26762. 'uogonek': 556,
  26763. 'Edieresis': 667,
  26764. 'Dcroat': 722,
  26765. 'commaaccent': 250,
  26766. 'copyright': 747,
  26767. 'Emacron': 667,
  26768. 'ccaron': 444,
  26769. 'aring': 500,
  26770. 'Ncommaaccent': 722,
  26771. 'lacute': 278,
  26772. 'agrave': 500,
  26773. 'Tcommaaccent': 611,
  26774. 'Cacute': 667,
  26775. 'atilde': 500,
  26776. 'Edotaccent': 667,
  26777. 'scaron': 389,
  26778. 'scedilla': 389,
  26779. 'iacute': 278,
  26780. 'lozenge': 494,
  26781. 'Rcaron': 667,
  26782. 'Gcommaaccent': 722,
  26783. 'ucircumflex': 556,
  26784. 'acircumflex': 500,
  26785. 'Amacron': 667,
  26786. 'rcaron': 389,
  26787. 'ccedilla': 444,
  26788. 'Zdotaccent': 611,
  26789. 'Thorn': 611,
  26790. 'Omacron': 722,
  26791. 'Racute': 667,
  26792. 'Sacute': 556,
  26793. 'dcaron': 608,
  26794. 'Umacron': 722,
  26795. 'uring': 556,
  26796. 'threesuperior': 300,
  26797. 'Ograve': 722,
  26798. 'Agrave': 667,
  26799. 'Abreve': 667,
  26800. 'multiply': 570,
  26801. 'uacute': 556,
  26802. 'Tcaron': 611,
  26803. 'partialdiff': 494,
  26804. 'ydieresis': 444,
  26805. 'Nacute': 722,
  26806. 'icircumflex': 278,
  26807. 'Ecircumflex': 667,
  26808. 'adieresis': 500,
  26809. 'edieresis': 444,
  26810. 'cacute': 444,
  26811. 'nacute': 556,
  26812. 'umacron': 556,
  26813. 'Ncaron': 722,
  26814. 'Iacute': 389,
  26815. 'plusminus': 570,
  26816. 'brokenbar': 220,
  26817. 'registered': 747,
  26818. 'Gbreve': 722,
  26819. 'Idotaccent': 389,
  26820. 'summation': 600,
  26821. 'Egrave': 667,
  26822. 'racute': 389,
  26823. 'omacron': 500,
  26824. 'Zacute': 611,
  26825. 'Zcaron': 611,
  26826. 'greaterequal': 549,
  26827. 'Eth': 722,
  26828. 'Ccedilla': 667,
  26829. 'lcommaaccent': 278,
  26830. 'tcaron': 366,
  26831. 'eogonek': 444,
  26832. 'Uogonek': 722,
  26833. 'Aacute': 667,
  26834. 'Adieresis': 667,
  26835. 'egrave': 444,
  26836. 'zacute': 389,
  26837. 'iogonek': 278,
  26838. 'Oacute': 722,
  26839. 'oacute': 500,
  26840. 'amacron': 500,
  26841. 'sacute': 389,
  26842. 'idieresis': 278,
  26843. 'Ocircumflex': 722,
  26844. 'Ugrave': 722,
  26845. 'Delta': 612,
  26846. 'thorn': 500,
  26847. 'twosuperior': 300,
  26848. 'Odieresis': 722,
  26849. 'mu': 576,
  26850. 'igrave': 278,
  26851. 'ohungarumlaut': 500,
  26852. 'Eogonek': 667,
  26853. 'dcroat': 500,
  26854. 'threequarters': 750,
  26855. 'Scedilla': 556,
  26856. 'lcaron': 382,
  26857. 'Kcommaaccent': 667,
  26858. 'Lacute': 611,
  26859. 'trademark': 1000,
  26860. 'edotaccent': 444,
  26861. 'Igrave': 389,
  26862. 'Imacron': 389,
  26863. 'Lcaron': 611,
  26864. 'onehalf': 750,
  26865. 'lessequal': 549,
  26866. 'ocircumflex': 500,
  26867. 'ntilde': 556,
  26868. 'Uhungarumlaut': 722,
  26869. 'Eacute': 667,
  26870. 'emacron': 444,
  26871. 'gbreve': 500,
  26872. 'onequarter': 750,
  26873. 'Scaron': 556,
  26874. 'Scommaaccent': 556,
  26875. 'Ohungarumlaut': 722,
  26876. 'degree': 400,
  26877. 'ograve': 500,
  26878. 'Ccaron': 667,
  26879. 'ugrave': 556,
  26880. 'radical': 549,
  26881. 'Dcaron': 722,
  26882. 'rcommaaccent': 389,
  26883. 'Ntilde': 722,
  26884. 'otilde': 500,
  26885. 'Rcommaaccent': 667,
  26886. 'Lcommaaccent': 611,
  26887. 'Atilde': 667,
  26888. 'Aogonek': 667,
  26889. 'Aring': 667,
  26890. 'Otilde': 722,
  26891. 'zdotaccent': 389,
  26892. 'Ecaron': 667,
  26893. 'Iogonek': 389,
  26894. 'kcommaaccent': 500,
  26895. 'minus': 606,
  26896. 'Icircumflex': 389,
  26897. 'ncaron': 556,
  26898. 'tcommaaccent': 278,
  26899. 'logicalnot': 606,
  26900. 'odieresis': 500,
  26901. 'udieresis': 556,
  26902. 'notequal': 549,
  26903. 'gcommaaccent': 500,
  26904. 'eth': 500,
  26905. 'zcaron': 389,
  26906. 'ncommaaccent': 556,
  26907. 'onesuperior': 300,
  26908. 'imacron': 278,
  26909. 'Euro': 500
  26910. },
  26911. 'Times-Italic': {
  26912. 'space': 250,
  26913. 'exclam': 333,
  26914. 'quotedbl': 420,
  26915. 'numbersign': 500,
  26916. 'dollar': 500,
  26917. 'percent': 833,
  26918. 'ampersand': 778,
  26919. 'quoteright': 333,
  26920. 'parenleft': 333,
  26921. 'parenright': 333,
  26922. 'asterisk': 500,
  26923. 'plus': 675,
  26924. 'comma': 250,
  26925. 'hyphen': 333,
  26926. 'period': 250,
  26927. 'slash': 278,
  26928. 'zero': 500,
  26929. 'one': 500,
  26930. 'two': 500,
  26931. 'three': 500,
  26932. 'four': 500,
  26933. 'five': 500,
  26934. 'six': 500,
  26935. 'seven': 500,
  26936. 'eight': 500,
  26937. 'nine': 500,
  26938. 'colon': 333,
  26939. 'semicolon': 333,
  26940. 'less': 675,
  26941. 'equal': 675,
  26942. 'greater': 675,
  26943. 'question': 500,
  26944. 'at': 920,
  26945. 'A': 611,
  26946. 'B': 611,
  26947. 'C': 667,
  26948. 'D': 722,
  26949. 'E': 611,
  26950. 'F': 611,
  26951. 'G': 722,
  26952. 'H': 722,
  26953. 'I': 333,
  26954. 'J': 444,
  26955. 'K': 667,
  26956. 'L': 556,
  26957. 'M': 833,
  26958. 'N': 667,
  26959. 'O': 722,
  26960. 'P': 611,
  26961. 'Q': 722,
  26962. 'R': 611,
  26963. 'S': 500,
  26964. 'T': 556,
  26965. 'U': 722,
  26966. 'V': 611,
  26967. 'W': 833,
  26968. 'X': 611,
  26969. 'Y': 556,
  26970. 'Z': 556,
  26971. 'bracketleft': 389,
  26972. 'backslash': 278,
  26973. 'bracketright': 389,
  26974. 'asciicircum': 422,
  26975. 'underscore': 500,
  26976. 'quoteleft': 333,
  26977. 'a': 500,
  26978. 'b': 500,
  26979. 'c': 444,
  26980. 'd': 500,
  26981. 'e': 444,
  26982. 'f': 278,
  26983. 'g': 500,
  26984. 'h': 500,
  26985. 'i': 278,
  26986. 'j': 278,
  26987. 'k': 444,
  26988. 'l': 278,
  26989. 'm': 722,
  26990. 'n': 500,
  26991. 'o': 500,
  26992. 'p': 500,
  26993. 'q': 500,
  26994. 'r': 389,
  26995. 's': 389,
  26996. 't': 278,
  26997. 'u': 500,
  26998. 'v': 444,
  26999. 'w': 667,
  27000. 'x': 444,
  27001. 'y': 444,
  27002. 'z': 389,
  27003. 'braceleft': 400,
  27004. 'bar': 275,
  27005. 'braceright': 400,
  27006. 'asciitilde': 541,
  27007. 'exclamdown': 389,
  27008. 'cent': 500,
  27009. 'sterling': 500,
  27010. 'fraction': 167,
  27011. 'yen': 500,
  27012. 'florin': 500,
  27013. 'section': 500,
  27014. 'currency': 500,
  27015. 'quotesingle': 214,
  27016. 'quotedblleft': 556,
  27017. 'guillemotleft': 500,
  27018. 'guilsinglleft': 333,
  27019. 'guilsinglright': 333,
  27020. 'fi': 500,
  27021. 'fl': 500,
  27022. 'endash': 500,
  27023. 'dagger': 500,
  27024. 'daggerdbl': 500,
  27025. 'periodcentered': 250,
  27026. 'paragraph': 523,
  27027. 'bullet': 350,
  27028. 'quotesinglbase': 333,
  27029. 'quotedblbase': 556,
  27030. 'quotedblright': 556,
  27031. 'guillemotright': 500,
  27032. 'ellipsis': 889,
  27033. 'perthousand': 1000,
  27034. 'questiondown': 500,
  27035. 'grave': 333,
  27036. 'acute': 333,
  27037. 'circumflex': 333,
  27038. 'tilde': 333,
  27039. 'macron': 333,
  27040. 'breve': 333,
  27041. 'dotaccent': 333,
  27042. 'dieresis': 333,
  27043. 'ring': 333,
  27044. 'cedilla': 333,
  27045. 'hungarumlaut': 333,
  27046. 'ogonek': 333,
  27047. 'caron': 333,
  27048. 'emdash': 889,
  27049. 'AE': 889,
  27050. 'ordfeminine': 276,
  27051. 'Lslash': 556,
  27052. 'Oslash': 722,
  27053. 'OE': 944,
  27054. 'ordmasculine': 310,
  27055. 'ae': 667,
  27056. 'dotlessi': 278,
  27057. 'lslash': 278,
  27058. 'oslash': 500,
  27059. 'oe': 667,
  27060. 'germandbls': 500,
  27061. 'Idieresis': 333,
  27062. 'eacute': 444,
  27063. 'abreve': 500,
  27064. 'uhungarumlaut': 500,
  27065. 'ecaron': 444,
  27066. 'Ydieresis': 556,
  27067. 'divide': 675,
  27068. 'Yacute': 556,
  27069. 'Acircumflex': 611,
  27070. 'aacute': 500,
  27071. 'Ucircumflex': 722,
  27072. 'yacute': 444,
  27073. 'scommaaccent': 389,
  27074. 'ecircumflex': 444,
  27075. 'Uring': 722,
  27076. 'Udieresis': 722,
  27077. 'aogonek': 500,
  27078. 'Uacute': 722,
  27079. 'uogonek': 500,
  27080. 'Edieresis': 611,
  27081. 'Dcroat': 722,
  27082. 'commaaccent': 250,
  27083. 'copyright': 760,
  27084. 'Emacron': 611,
  27085. 'ccaron': 444,
  27086. 'aring': 500,
  27087. 'Ncommaaccent': 667,
  27088. 'lacute': 278,
  27089. 'agrave': 500,
  27090. 'Tcommaaccent': 556,
  27091. 'Cacute': 667,
  27092. 'atilde': 500,
  27093. 'Edotaccent': 611,
  27094. 'scaron': 389,
  27095. 'scedilla': 389,
  27096. 'iacute': 278,
  27097. 'lozenge': 471,
  27098. 'Rcaron': 611,
  27099. 'Gcommaaccent': 722,
  27100. 'ucircumflex': 500,
  27101. 'acircumflex': 500,
  27102. 'Amacron': 611,
  27103. 'rcaron': 389,
  27104. 'ccedilla': 444,
  27105. 'Zdotaccent': 556,
  27106. 'Thorn': 611,
  27107. 'Omacron': 722,
  27108. 'Racute': 611,
  27109. 'Sacute': 500,
  27110. 'dcaron': 544,
  27111. 'Umacron': 722,
  27112. 'uring': 500,
  27113. 'threesuperior': 300,
  27114. 'Ograve': 722,
  27115. 'Agrave': 611,
  27116. 'Abreve': 611,
  27117. 'multiply': 675,
  27118. 'uacute': 500,
  27119. 'Tcaron': 556,
  27120. 'partialdiff': 476,
  27121. 'ydieresis': 444,
  27122. 'Nacute': 667,
  27123. 'icircumflex': 278,
  27124. 'Ecircumflex': 611,
  27125. 'adieresis': 500,
  27126. 'edieresis': 444,
  27127. 'cacute': 444,
  27128. 'nacute': 500,
  27129. 'umacron': 500,
  27130. 'Ncaron': 667,
  27131. 'Iacute': 333,
  27132. 'plusminus': 675,
  27133. 'brokenbar': 275,
  27134. 'registered': 760,
  27135. 'Gbreve': 722,
  27136. 'Idotaccent': 333,
  27137. 'summation': 600,
  27138. 'Egrave': 611,
  27139. 'racute': 389,
  27140. 'omacron': 500,
  27141. 'Zacute': 556,
  27142. 'Zcaron': 556,
  27143. 'greaterequal': 549,
  27144. 'Eth': 722,
  27145. 'Ccedilla': 667,
  27146. 'lcommaaccent': 278,
  27147. 'tcaron': 300,
  27148. 'eogonek': 444,
  27149. 'Uogonek': 722,
  27150. 'Aacute': 611,
  27151. 'Adieresis': 611,
  27152. 'egrave': 444,
  27153. 'zacute': 389,
  27154. 'iogonek': 278,
  27155. 'Oacute': 722,
  27156. 'oacute': 500,
  27157. 'amacron': 500,
  27158. 'sacute': 389,
  27159. 'idieresis': 278,
  27160. 'Ocircumflex': 722,
  27161. 'Ugrave': 722,
  27162. 'Delta': 612,
  27163. 'thorn': 500,
  27164. 'twosuperior': 300,
  27165. 'Odieresis': 722,
  27166. 'mu': 500,
  27167. 'igrave': 278,
  27168. 'ohungarumlaut': 500,
  27169. 'Eogonek': 611,
  27170. 'dcroat': 500,
  27171. 'threequarters': 750,
  27172. 'Scedilla': 500,
  27173. 'lcaron': 300,
  27174. 'Kcommaaccent': 667,
  27175. 'Lacute': 556,
  27176. 'trademark': 980,
  27177. 'edotaccent': 444,
  27178. 'Igrave': 333,
  27179. 'Imacron': 333,
  27180. 'Lcaron': 611,
  27181. 'onehalf': 750,
  27182. 'lessequal': 549,
  27183. 'ocircumflex': 500,
  27184. 'ntilde': 500,
  27185. 'Uhungarumlaut': 722,
  27186. 'Eacute': 611,
  27187. 'emacron': 444,
  27188. 'gbreve': 500,
  27189. 'onequarter': 750,
  27190. 'Scaron': 500,
  27191. 'Scommaaccent': 500,
  27192. 'Ohungarumlaut': 722,
  27193. 'degree': 400,
  27194. 'ograve': 500,
  27195. 'Ccaron': 667,
  27196. 'ugrave': 500,
  27197. 'radical': 453,
  27198. 'Dcaron': 722,
  27199. 'rcommaaccent': 389,
  27200. 'Ntilde': 667,
  27201. 'otilde': 500,
  27202. 'Rcommaaccent': 611,
  27203. 'Lcommaaccent': 556,
  27204. 'Atilde': 611,
  27205. 'Aogonek': 611,
  27206. 'Aring': 611,
  27207. 'Otilde': 722,
  27208. 'zdotaccent': 389,
  27209. 'Ecaron': 611,
  27210. 'Iogonek': 333,
  27211. 'kcommaaccent': 444,
  27212. 'minus': 675,
  27213. 'Icircumflex': 333,
  27214. 'ncaron': 500,
  27215. 'tcommaaccent': 278,
  27216. 'logicalnot': 675,
  27217. 'odieresis': 500,
  27218. 'udieresis': 500,
  27219. 'notequal': 549,
  27220. 'gcommaaccent': 500,
  27221. 'eth': 500,
  27222. 'zcaron': 389,
  27223. 'ncommaaccent': 500,
  27224. 'onesuperior': 300,
  27225. 'imacron': 278,
  27226. 'Euro': 500
  27227. },
  27228. 'ZapfDingbats': {
  27229. 'space': 278,
  27230. 'a1': 974,
  27231. 'a2': 961,
  27232. 'a202': 974,
  27233. 'a3': 980,
  27234. 'a4': 719,
  27235. 'a5': 789,
  27236. 'a119': 790,
  27237. 'a118': 791,
  27238. 'a117': 690,
  27239. 'a11': 960,
  27240. 'a12': 939,
  27241. 'a13': 549,
  27242. 'a14': 855,
  27243. 'a15': 911,
  27244. 'a16': 933,
  27245. 'a105': 911,
  27246. 'a17': 945,
  27247. 'a18': 974,
  27248. 'a19': 755,
  27249. 'a20': 846,
  27250. 'a21': 762,
  27251. 'a22': 761,
  27252. 'a23': 571,
  27253. 'a24': 677,
  27254. 'a25': 763,
  27255. 'a26': 760,
  27256. 'a27': 759,
  27257. 'a28': 754,
  27258. 'a6': 494,
  27259. 'a7': 552,
  27260. 'a8': 537,
  27261. 'a9': 577,
  27262. 'a10': 692,
  27263. 'a29': 786,
  27264. 'a30': 788,
  27265. 'a31': 788,
  27266. 'a32': 790,
  27267. 'a33': 793,
  27268. 'a34': 794,
  27269. 'a35': 816,
  27270. 'a36': 823,
  27271. 'a37': 789,
  27272. 'a38': 841,
  27273. 'a39': 823,
  27274. 'a40': 833,
  27275. 'a41': 816,
  27276. 'a42': 831,
  27277. 'a43': 923,
  27278. 'a44': 744,
  27279. 'a45': 723,
  27280. 'a46': 749,
  27281. 'a47': 790,
  27282. 'a48': 792,
  27283. 'a49': 695,
  27284. 'a50': 776,
  27285. 'a51': 768,
  27286. 'a52': 792,
  27287. 'a53': 759,
  27288. 'a54': 707,
  27289. 'a55': 708,
  27290. 'a56': 682,
  27291. 'a57': 701,
  27292. 'a58': 826,
  27293. 'a59': 815,
  27294. 'a60': 789,
  27295. 'a61': 789,
  27296. 'a62': 707,
  27297. 'a63': 687,
  27298. 'a64': 696,
  27299. 'a65': 689,
  27300. 'a66': 786,
  27301. 'a67': 787,
  27302. 'a68': 713,
  27303. 'a69': 791,
  27304. 'a70': 785,
  27305. 'a71': 791,
  27306. 'a72': 873,
  27307. 'a73': 761,
  27308. 'a74': 762,
  27309. 'a203': 762,
  27310. 'a75': 759,
  27311. 'a204': 759,
  27312. 'a76': 892,
  27313. 'a77': 892,
  27314. 'a78': 788,
  27315. 'a79': 784,
  27316. 'a81': 438,
  27317. 'a82': 138,
  27318. 'a83': 277,
  27319. 'a84': 415,
  27320. 'a97': 392,
  27321. 'a98': 392,
  27322. 'a99': 668,
  27323. 'a100': 668,
  27324. 'a89': 390,
  27325. 'a90': 390,
  27326. 'a93': 317,
  27327. 'a94': 317,
  27328. 'a91': 276,
  27329. 'a92': 276,
  27330. 'a205': 509,
  27331. 'a85': 509,
  27332. 'a206': 410,
  27333. 'a86': 410,
  27334. 'a87': 234,
  27335. 'a88': 234,
  27336. 'a95': 334,
  27337. 'a96': 334,
  27338. 'a101': 732,
  27339. 'a102': 544,
  27340. 'a103': 544,
  27341. 'a104': 910,
  27342. 'a106': 667,
  27343. 'a107': 760,
  27344. 'a108': 760,
  27345. 'a112': 776,
  27346. 'a111': 595,
  27347. 'a110': 694,
  27348. 'a109': 626,
  27349. 'a120': 788,
  27350. 'a121': 788,
  27351. 'a122': 788,
  27352. 'a123': 788,
  27353. 'a124': 788,
  27354. 'a125': 788,
  27355. 'a126': 788,
  27356. 'a127': 788,
  27357. 'a128': 788,
  27358. 'a129': 788,
  27359. 'a130': 788,
  27360. 'a131': 788,
  27361. 'a132': 788,
  27362. 'a133': 788,
  27363. 'a134': 788,
  27364. 'a135': 788,
  27365. 'a136': 788,
  27366. 'a137': 788,
  27367. 'a138': 788,
  27368. 'a139': 788,
  27369. 'a140': 788,
  27370. 'a141': 788,
  27371. 'a142': 788,
  27372. 'a143': 788,
  27373. 'a144': 788,
  27374. 'a145': 788,
  27375. 'a146': 788,
  27376. 'a147': 788,
  27377. 'a148': 788,
  27378. 'a149': 788,
  27379. 'a150': 788,
  27380. 'a151': 788,
  27381. 'a152': 788,
  27382. 'a153': 788,
  27383. 'a154': 788,
  27384. 'a155': 788,
  27385. 'a156': 788,
  27386. 'a157': 788,
  27387. 'a158': 788,
  27388. 'a159': 788,
  27389. 'a160': 894,
  27390. 'a161': 838,
  27391. 'a163': 1016,
  27392. 'a164': 458,
  27393. 'a196': 748,
  27394. 'a165': 924,
  27395. 'a192': 748,
  27396. 'a166': 918,
  27397. 'a167': 927,
  27398. 'a168': 928,
  27399. 'a169': 928,
  27400. 'a170': 834,
  27401. 'a171': 873,
  27402. 'a172': 828,
  27403. 'a173': 924,
  27404. 'a162': 924,
  27405. 'a174': 917,
  27406. 'a175': 930,
  27407. 'a176': 931,
  27408. 'a177': 463,
  27409. 'a178': 883,
  27410. 'a179': 836,
  27411. 'a193': 836,
  27412. 'a180': 867,
  27413. 'a199': 867,
  27414. 'a181': 696,
  27415. 'a200': 696,
  27416. 'a182': 874,
  27417. 'a201': 874,
  27418. 'a183': 760,
  27419. 'a184': 946,
  27420. 'a197': 771,
  27421. 'a185': 865,
  27422. 'a194': 771,
  27423. 'a198': 888,
  27424. 'a186': 967,
  27425. 'a195': 888,
  27426. 'a187': 831,
  27427. 'a188': 873,
  27428. 'a189': 927,
  27429. 'a190': 970,
  27430. 'a191': 918
  27431. }
  27432. };
  27433. var EOF = {};
  27434. function isEOF(v) {
  27435. return (v === EOF);
  27436. }
  27437. var Parser = (function ParserClosure() {
  27438. function Parser(lexer, allowStreams, xref) {
  27439. this.lexer = lexer;
  27440. this.allowStreams = allowStreams;
  27441. this.xref = xref;
  27442. this.imageCache = {
  27443. length: 0,
  27444. adler32: 0,
  27445. stream: null
  27446. };
  27447. this.refill();
  27448. }
  27449. Parser.prototype = {
  27450. refill: function Parser_refill() {
  27451. this.buf1 = this.lexer.getObj();
  27452. this.buf2 = this.lexer.getObj();
  27453. },
  27454. shift: function Parser_shift() {
  27455. if (isCmd(this.buf2, 'ID')) {
  27456. this.buf1 = this.buf2;
  27457. this.buf2 = null;
  27458. } else {
  27459. this.buf1 = this.buf2;
  27460. this.buf2 = this.lexer.getObj();
  27461. }
  27462. },
  27463. getObj: function Parser_getObj(cipherTransform) {
  27464. var buf1 = this.buf1;
  27465. this.shift();
  27466. if (buf1 instanceof Cmd) {
  27467. switch (buf1.cmd) {
  27468. case 'BI': // inline image
  27469. return this.makeInlineImage(cipherTransform);
  27470. case '[': // array
  27471. var array = [];
  27472. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  27473. array.push(this.getObj(cipherTransform));
  27474. }
  27475. if (isEOF(this.buf1)) {
  27476. error('End of file inside array');
  27477. }
  27478. this.shift();
  27479. return array;
  27480. case '<<': // dictionary or stream
  27481. var dict = new Dict(this.xref);
  27482. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  27483. if (!isName(this.buf1)) {
  27484. info('Malformed dictionary: key must be a name object');
  27485. this.shift();
  27486. continue;
  27487. }
  27488. var key = this.buf1.name;
  27489. this.shift();
  27490. if (isEOF(this.buf1)) {
  27491. break;
  27492. }
  27493. dict.set(key, this.getObj(cipherTransform));
  27494. }
  27495. if (isEOF(this.buf1)) {
  27496. error('End of file inside dictionary');
  27497. }
  27498. // Stream objects are not allowed inside content streams or
  27499. // object streams.
  27500. if (isCmd(this.buf2, 'stream')) {
  27501. return (this.allowStreams ?
  27502. this.makeStream(dict, cipherTransform) : dict);
  27503. }
  27504. this.shift();
  27505. return dict;
  27506. default: // simple object
  27507. return buf1;
  27508. }
  27509. }
  27510. if (isInt(buf1)) { // indirect reference or integer
  27511. var num = buf1;
  27512. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  27513. var ref = new Ref(num, this.buf1);
  27514. this.shift();
  27515. this.shift();
  27516. return ref;
  27517. }
  27518. return num;
  27519. }
  27520. if (isString(buf1)) { // string
  27521. var str = buf1;
  27522. if (cipherTransform) {
  27523. str = cipherTransform.decryptString(str);
  27524. }
  27525. return str;
  27526. }
  27527. // simple object
  27528. return buf1;
  27529. },
  27530. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27531. var lexer = this.lexer;
  27532. var stream = lexer.stream;
  27533. // parse dictionary
  27534. var dict = new Dict(null);
  27535. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27536. if (!isName(this.buf1)) {
  27537. error('Dictionary key must be a name object');
  27538. }
  27539. var key = this.buf1.name;
  27540. this.shift();
  27541. if (isEOF(this.buf1)) {
  27542. break;
  27543. }
  27544. dict.set(key, this.getObj(cipherTransform));
  27545. }
  27546. // parse image stream
  27547. var startPos = stream.pos;
  27548. // searching for the /EI\s/
  27549. var state = 0, ch, i, ii;
  27550. while (state !== 4 && (ch = stream.getByte()) !== -1) {
  27551. switch (ch | 0) {
  27552. case 0x20:
  27553. case 0x0D:
  27554. case 0x0A:
  27555. // let's check next five bytes to be ASCII... just be sure
  27556. var followingBytes = stream.peekBytes(5);
  27557. for (i = 0, ii = followingBytes.length; i < ii; i++) {
  27558. ch = followingBytes[i];
  27559. if (ch !== 0x0A && ch !== 0x0D && (ch < 0x20 || ch > 0x7F)) {
  27560. // not a LF, CR, SPACE or any visible ASCII character
  27561. state = 0;
  27562. break; // some binary stuff found, resetting the state
  27563. }
  27564. }
  27565. state = (state === 3 ? 4 : 0);
  27566. break;
  27567. case 0x45:
  27568. state = 2;
  27569. break;
  27570. case 0x49:
  27571. state = (state === 2 ? 3 : 0);
  27572. break;
  27573. default:
  27574. state = 0;
  27575. break;
  27576. }
  27577. }
  27578. var length = (stream.pos - 4) - startPos;
  27579. var imageStream = stream.makeSubStream(startPos, length, dict);
  27580. // trying to cache repeat images, first we are trying to "warm up" caching
  27581. // using length, then comparing adler32
  27582. var MAX_LENGTH_TO_CACHE = 1000;
  27583. var cacheImage = false, adler32;
  27584. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  27585. var imageBytes = imageStream.getBytes();
  27586. imageStream.reset();
  27587. var a = 1;
  27588. var b = 0;
  27589. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27590. a = (a + (imageBytes[i] & 0xff)) % 65521;
  27591. b = (b + a) % 65521;
  27592. }
  27593. adler32 = (b << 16) | a;
  27594. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  27595. this.buf2 = Cmd.get('EI');
  27596. this.shift();
  27597. this.imageCache.stream.reset();
  27598. return this.imageCache.stream;
  27599. }
  27600. cacheImage = true;
  27601. }
  27602. if (!cacheImage && !this.imageCache.stream) {
  27603. this.imageCache.length = length;
  27604. this.imageCache.stream = null;
  27605. }
  27606. if (cipherTransform) {
  27607. imageStream = cipherTransform.createStream(imageStream, length);
  27608. }
  27609. imageStream = this.filter(imageStream, dict, length);
  27610. imageStream.dict = dict;
  27611. if (cacheImage) {
  27612. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27613. this.imageCache.adler32 = adler32;
  27614. this.imageCache.stream = imageStream;
  27615. }
  27616. this.buf2 = Cmd.get('EI');
  27617. this.shift();
  27618. return imageStream;
  27619. },
  27620. fetchIfRef: function Parser_fetchIfRef(obj) {
  27621. // not relying on the xref.fetchIfRef -- xref might not be set
  27622. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  27623. },
  27624. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27625. var lexer = this.lexer;
  27626. var stream = lexer.stream;
  27627. // get stream start position
  27628. lexer.skipToNextLine();
  27629. var pos = stream.pos - 1;
  27630. // get length
  27631. var length = this.fetchIfRef(dict.get('Length'));
  27632. if (!isInt(length)) {
  27633. info('Bad ' + length + ' attribute in stream');
  27634. length = 0;
  27635. }
  27636. // skip over the stream data
  27637. stream.pos = pos + length;
  27638. lexer.nextChar();
  27639. this.shift(); // '>>'
  27640. this.shift(); // 'stream'
  27641. if (!isCmd(this.buf1, 'endstream')) {
  27642. // bad stream length, scanning for endstream
  27643. stream.pos = pos;
  27644. var SCAN_BLOCK_SIZE = 2048;
  27645. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27646. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27647. 0x61, 0x6D];
  27648. var skipped = 0, found = false, i, j;
  27649. while (stream.pos < stream.end) {
  27650. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27651. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27652. if (scanLength <= 0) {
  27653. break;
  27654. }
  27655. found = false;
  27656. for (i = 0, j = 0; i < scanLength; i++) {
  27657. var b = scanBytes[i];
  27658. if (b !== ENDSTREAM_SIGNATURE[j]) {
  27659. i -= j;
  27660. j = 0;
  27661. } else {
  27662. j++;
  27663. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27664. i++;
  27665. found = true;
  27666. break;
  27667. }
  27668. }
  27669. }
  27670. if (found) {
  27671. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  27672. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  27673. break;
  27674. }
  27675. skipped += scanLength;
  27676. stream.pos += scanLength;
  27677. }
  27678. if (!found) {
  27679. error('Missing endstream');
  27680. }
  27681. length = skipped;
  27682. lexer.nextChar();
  27683. this.shift();
  27684. this.shift();
  27685. }
  27686. this.shift(); // 'endstream'
  27687. stream = stream.makeSubStream(pos, length, dict);
  27688. if (cipherTransform) {
  27689. stream = cipherTransform.createStream(stream, length);
  27690. }
  27691. stream = this.filter(stream, dict, length);
  27692. stream.dict = dict;
  27693. return stream;
  27694. },
  27695. filter: function Parser_filter(stream, dict, length) {
  27696. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  27697. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  27698. if (isName(filter)) {
  27699. return this.makeFilter(stream, filter.name, length, params);
  27700. }
  27701. var maybeLength = length;
  27702. if (isArray(filter)) {
  27703. var filterArray = filter;
  27704. var paramsArray = params;
  27705. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  27706. filter = filterArray[i];
  27707. if (!isName(filter)) {
  27708. error('Bad filter name: ' + filter);
  27709. }
  27710. params = null;
  27711. if (isArray(paramsArray) && (i in paramsArray)) {
  27712. params = paramsArray[i];
  27713. }
  27714. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  27715. // after the first stream the length variable is invalid
  27716. maybeLength = null;
  27717. }
  27718. }
  27719. return stream;
  27720. },
  27721. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  27722. if (stream.dict.get('Length') === 0) {
  27723. return new NullStream(stream);
  27724. }
  27725. try {
  27726. var xrefStreamStats = this.xref.stats.streamTypes;
  27727. if (name === 'FlateDecode' || name === 'Fl') {
  27728. xrefStreamStats[StreamType.FLATE] = true;
  27729. if (params) {
  27730. return new PredictorStream(new FlateStream(stream, maybeLength),
  27731. maybeLength, params);
  27732. }
  27733. return new FlateStream(stream, maybeLength);
  27734. }
  27735. if (name === 'LZWDecode' || name === 'LZW') {
  27736. xrefStreamStats[StreamType.LZW] = true;
  27737. var earlyChange = 1;
  27738. if (params) {
  27739. if (params.has('EarlyChange')) {
  27740. earlyChange = params.get('EarlyChange');
  27741. }
  27742. return new PredictorStream(
  27743. new LZWStream(stream, maybeLength, earlyChange),
  27744. maybeLength, params);
  27745. }
  27746. return new LZWStream(stream, maybeLength, earlyChange);
  27747. }
  27748. if (name === 'DCTDecode' || name === 'DCT') {
  27749. xrefStreamStats[StreamType.DCT] = true;
  27750. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  27751. }
  27752. if (name === 'JPXDecode' || name === 'JPX') {
  27753. xrefStreamStats[StreamType.JPX] = true;
  27754. return new JpxStream(stream, maybeLength, stream.dict);
  27755. }
  27756. if (name === 'ASCII85Decode' || name === 'A85') {
  27757. xrefStreamStats[StreamType.A85] = true;
  27758. return new Ascii85Stream(stream, maybeLength);
  27759. }
  27760. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  27761. xrefStreamStats[StreamType.AHX] = true;
  27762. return new AsciiHexStream(stream, maybeLength);
  27763. }
  27764. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  27765. xrefStreamStats[StreamType.CCF] = true;
  27766. return new CCITTFaxStream(stream, maybeLength, params);
  27767. }
  27768. if (name === 'RunLengthDecode' || name === 'RL') {
  27769. xrefStreamStats[StreamType.RL] = true;
  27770. return new RunLengthStream(stream, maybeLength);
  27771. }
  27772. if (name === 'JBIG2Decode') {
  27773. xrefStreamStats[StreamType.JBIG] = true;
  27774. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27775. }
  27776. warn('filter "' + name + '" not supported yet');
  27777. return stream;
  27778. } catch (ex) {
  27779. if (ex instanceof MissingDataException) {
  27780. throw ex;
  27781. }
  27782. warn('Invalid stream: \"' + ex + '\"');
  27783. return new NullStream(stream);
  27784. }
  27785. }
  27786. };
  27787. return Parser;
  27788. })();
  27789. var Lexer = (function LexerClosure() {
  27790. function Lexer(stream, knownCommands) {
  27791. this.stream = stream;
  27792. this.nextChar();
  27793. // While lexing, we build up many strings one char at a time. Using += for
  27794. // this can result in lots of garbage strings. It's better to build an
  27795. // array of single-char strings and then join() them together at the end.
  27796. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27797. // purpose uses less memory than using a new array for each string.
  27798. this.strBuf = [];
  27799. // The PDFs might have "glued" commands with other commands, operands or
  27800. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27801. // commands and their prefixes. The prefixes are built the following way:
  27802. // if there a command that is a prefix of the other valid command or
  27803. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27804. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27805. // other commands or literals as a prefix. The knowCommands is optional.
  27806. this.knownCommands = knownCommands;
  27807. }
  27808. Lexer.isSpace = function Lexer_isSpace(ch) {
  27809. // Space is one of the following characters: SPACE, TAB, CR or LF.
  27810. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  27811. };
  27812. // A '1' in this array means the character is white space. A '1' or
  27813. // '2' means the character ends a name or command.
  27814. var specialChars = [
  27815. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27817. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27831. ];
  27832. function toHexDigit(ch) {
  27833. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27834. return ch & 0x0F;
  27835. }
  27836. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27837. // 'A'-'F', 'a'-'f'
  27838. return (ch & 0x0F) + 9;
  27839. }
  27840. return -1;
  27841. }
  27842. Lexer.prototype = {
  27843. nextChar: function Lexer_nextChar() {
  27844. return (this.currentChar = this.stream.getByte());
  27845. },
  27846. peekChar: function Lexer_peekChar() {
  27847. return this.stream.peekBytes(1)[0];
  27848. },
  27849. getNumber: function Lexer_getNumber() {
  27850. var ch = this.currentChar;
  27851. var eNotation = false;
  27852. var divideBy = 0; // different from 0 if it's a floating point value
  27853. var sign = 1;
  27854. if (ch === 0x2D) { // '-'
  27855. sign = -1;
  27856. ch = this.nextChar();
  27857. } else if (ch === 0x2B) { // '+'
  27858. ch = this.nextChar();
  27859. }
  27860. if (ch === 0x2E) { // '.'
  27861. divideBy = 10;
  27862. ch = this.nextChar();
  27863. }
  27864. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27865. error('Invalid number: ' + String.fromCharCode(ch));
  27866. return 0;
  27867. }
  27868. var baseValue = ch - 0x30; // '0'
  27869. var powerValue = 0;
  27870. var powerValueSign = 1;
  27871. while ((ch = this.nextChar()) >= 0) {
  27872. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27873. var currentDigit = ch - 0x30; // '0'
  27874. if (eNotation) { // We are after an 'e' or 'E'
  27875. powerValue = powerValue * 10 + currentDigit;
  27876. } else {
  27877. if (divideBy !== 0) { // We are after a point
  27878. divideBy *= 10;
  27879. }
  27880. baseValue = baseValue * 10 + currentDigit;
  27881. }
  27882. } else if (ch === 0x2E) { // '.'
  27883. if (divideBy === 0) {
  27884. divideBy = 1;
  27885. } else {
  27886. // A number can have only one '.'
  27887. break;
  27888. }
  27889. } else if (ch === 0x2D) { // '-'
  27890. // ignore minus signs in the middle of numbers to match
  27891. // Adobe's behavior
  27892. warn('Badly formated number');
  27893. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27894. // 'E' can be either a scientific notation or the beginning of a new
  27895. // operator
  27896. ch = this.peekChar();
  27897. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27898. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27899. this.nextChar(); // Consume the sign character
  27900. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27901. // The 'E' must be the beginning of a new operator
  27902. break;
  27903. }
  27904. eNotation = true;
  27905. } else {
  27906. // the last character doesn't belong to us
  27907. break;
  27908. }
  27909. }
  27910. if (divideBy !== 0) {
  27911. baseValue /= divideBy;
  27912. }
  27913. if (eNotation) {
  27914. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27915. }
  27916. return sign * baseValue;
  27917. },
  27918. getString: function Lexer_getString() {
  27919. var numParen = 1;
  27920. var done = false;
  27921. var strBuf = this.strBuf;
  27922. strBuf.length = 0;
  27923. var ch = this.nextChar();
  27924. while (true) {
  27925. var charBuffered = false;
  27926. switch (ch | 0) {
  27927. case -1:
  27928. warn('Unterminated string');
  27929. done = true;
  27930. break;
  27931. case 0x28: // '('
  27932. ++numParen;
  27933. strBuf.push('(');
  27934. break;
  27935. case 0x29: // ')'
  27936. if (--numParen === 0) {
  27937. this.nextChar(); // consume strings ')'
  27938. done = true;
  27939. } else {
  27940. strBuf.push(')');
  27941. }
  27942. break;
  27943. case 0x5C: // '\\'
  27944. ch = this.nextChar();
  27945. switch (ch) {
  27946. case -1:
  27947. warn('Unterminated string');
  27948. done = true;
  27949. break;
  27950. case 0x6E: // 'n'
  27951. strBuf.push('\n');
  27952. break;
  27953. case 0x72: // 'r'
  27954. strBuf.push('\r');
  27955. break;
  27956. case 0x74: // 't'
  27957. strBuf.push('\t');
  27958. break;
  27959. case 0x62: // 'b'
  27960. strBuf.push('\b');
  27961. break;
  27962. case 0x66: // 'f'
  27963. strBuf.push('\f');
  27964. break;
  27965. case 0x5C: // '\'
  27966. case 0x28: // '('
  27967. case 0x29: // ')'
  27968. strBuf.push(String.fromCharCode(ch));
  27969. break;
  27970. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  27971. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  27972. var x = ch & 0x0F;
  27973. ch = this.nextChar();
  27974. charBuffered = true;
  27975. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27976. x = (x << 3) + (ch & 0x0F);
  27977. ch = this.nextChar();
  27978. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27979. charBuffered = false;
  27980. x = (x << 3) + (ch & 0x0F);
  27981. }
  27982. }
  27983. strBuf.push(String.fromCharCode(x));
  27984. break;
  27985. case 0x0D: // CR
  27986. if (this.peekChar() === 0x0A) { // LF
  27987. this.nextChar();
  27988. }
  27989. break;
  27990. case 0x0A: // LF
  27991. break;
  27992. default:
  27993. strBuf.push(String.fromCharCode(ch));
  27994. break;
  27995. }
  27996. break;
  27997. default:
  27998. strBuf.push(String.fromCharCode(ch));
  27999. break;
  28000. }
  28001. if (done) {
  28002. break;
  28003. }
  28004. if (!charBuffered) {
  28005. ch = this.nextChar();
  28006. }
  28007. }
  28008. return strBuf.join('');
  28009. },
  28010. getName: function Lexer_getName() {
  28011. var ch;
  28012. var strBuf = this.strBuf;
  28013. strBuf.length = 0;
  28014. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28015. if (ch === 0x23) { // '#'
  28016. ch = this.nextChar();
  28017. var x = toHexDigit(ch);
  28018. if (x !== -1) {
  28019. var x2 = toHexDigit(this.nextChar());
  28020. if (x2 === -1) {
  28021. error('Illegal digit in hex char in name: ' + x2);
  28022. }
  28023. strBuf.push(String.fromCharCode((x << 4) | x2));
  28024. } else {
  28025. strBuf.push('#', String.fromCharCode(ch));
  28026. }
  28027. } else {
  28028. strBuf.push(String.fromCharCode(ch));
  28029. }
  28030. }
  28031. if (strBuf.length > 128) {
  28032. error('Warning: name token is longer than allowed by the spec: ' +
  28033. strBuf.length);
  28034. }
  28035. return Name.get(strBuf.join(''));
  28036. },
  28037. getHexString: function Lexer_getHexString() {
  28038. var strBuf = this.strBuf;
  28039. strBuf.length = 0;
  28040. var ch = this.currentChar;
  28041. var isFirstHex = true;
  28042. var firstDigit;
  28043. var secondDigit;
  28044. while (true) {
  28045. if (ch < 0) {
  28046. warn('Unterminated hex string');
  28047. break;
  28048. } else if (ch === 0x3E) { // '>'
  28049. this.nextChar();
  28050. break;
  28051. } else if (specialChars[ch] === 1) {
  28052. ch = this.nextChar();
  28053. continue;
  28054. } else {
  28055. if (isFirstHex) {
  28056. firstDigit = toHexDigit(ch);
  28057. if (firstDigit === -1) {
  28058. warn('Ignoring invalid character "' + ch + '" in hex string');
  28059. ch = this.nextChar();
  28060. continue;
  28061. }
  28062. } else {
  28063. secondDigit = toHexDigit(ch);
  28064. if (secondDigit === -1) {
  28065. warn('Ignoring invalid character "' + ch + '" in hex string');
  28066. ch = this.nextChar();
  28067. continue;
  28068. }
  28069. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28070. }
  28071. isFirstHex = !isFirstHex;
  28072. ch = this.nextChar();
  28073. }
  28074. }
  28075. return strBuf.join('');
  28076. },
  28077. getObj: function Lexer_getObj() {
  28078. // skip whitespace and comments
  28079. var comment = false;
  28080. var ch = this.currentChar;
  28081. while (true) {
  28082. if (ch < 0) {
  28083. return EOF;
  28084. }
  28085. if (comment) {
  28086. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28087. comment = false;
  28088. }
  28089. } else if (ch === 0x25) { // '%'
  28090. comment = true;
  28091. } else if (specialChars[ch] !== 1) {
  28092. break;
  28093. }
  28094. ch = this.nextChar();
  28095. }
  28096. // start reading token
  28097. switch (ch | 0) {
  28098. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28099. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28100. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28101. return this.getNumber();
  28102. case 0x28: // '('
  28103. return this.getString();
  28104. case 0x2F: // '/'
  28105. return this.getName();
  28106. // array punctuation
  28107. case 0x5B: // '['
  28108. this.nextChar();
  28109. return Cmd.get('[');
  28110. case 0x5D: // ']'
  28111. this.nextChar();
  28112. return Cmd.get(']');
  28113. // hex string or dict punctuation
  28114. case 0x3C: // '<'
  28115. ch = this.nextChar();
  28116. if (ch === 0x3C) {
  28117. // dict punctuation
  28118. this.nextChar();
  28119. return Cmd.get('<<');
  28120. }
  28121. return this.getHexString();
  28122. // dict punctuation
  28123. case 0x3E: // '>'
  28124. ch = this.nextChar();
  28125. if (ch === 0x3E) {
  28126. this.nextChar();
  28127. return Cmd.get('>>');
  28128. }
  28129. return Cmd.get('>');
  28130. case 0x7B: // '{'
  28131. this.nextChar();
  28132. return Cmd.get('{');
  28133. case 0x7D: // '}'
  28134. this.nextChar();
  28135. return Cmd.get('}');
  28136. case 0x29: // ')'
  28137. error('Illegal character: ' + ch);
  28138. break;
  28139. }
  28140. // command
  28141. var str = String.fromCharCode(ch);
  28142. var knownCommands = this.knownCommands;
  28143. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28144. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28145. // stop if known command is found and next character does not make
  28146. // the str a command
  28147. var possibleCommand = str + String.fromCharCode(ch);
  28148. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28149. break;
  28150. }
  28151. if (str.length === 128) {
  28152. error('Command token too long: ' + str.length);
  28153. }
  28154. str = possibleCommand;
  28155. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28156. }
  28157. if (str === 'true') {
  28158. return true;
  28159. }
  28160. if (str === 'false') {
  28161. return false;
  28162. }
  28163. if (str === 'null') {
  28164. return null;
  28165. }
  28166. return Cmd.get(str);
  28167. },
  28168. skipToNextLine: function Lexer_skipToNextLine() {
  28169. var ch = this.currentChar;
  28170. while (ch >= 0) {
  28171. if (ch === 0x0D) { // CR
  28172. ch = this.nextChar();
  28173. if (ch === 0x0A) { // LF
  28174. this.nextChar();
  28175. }
  28176. break;
  28177. } else if (ch === 0x0A) { // LF
  28178. this.nextChar();
  28179. break;
  28180. }
  28181. ch = this.nextChar();
  28182. }
  28183. }
  28184. };
  28185. return Lexer;
  28186. })();
  28187. var Linearization = {
  28188. create: function LinearizationCreate(stream) {
  28189. function getInt(name, allowZeroValue) {
  28190. var obj = linDict.get(name);
  28191. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28192. return obj;
  28193. }
  28194. throw new Error('The "' + name + '" parameter in the linearization ' +
  28195. 'dictionary is invalid.');
  28196. }
  28197. function getHints() {
  28198. var hints = linDict.get('H'), hintsLength, item;
  28199. if (isArray(hints) &&
  28200. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28201. for (var index = 0; index < hintsLength; index++) {
  28202. if (!(isInt(item = hints[index]) && item > 0)) {
  28203. throw new Error('Hint (' + index +
  28204. ') in the linearization dictionary is invalid.');
  28205. }
  28206. }
  28207. return hints;
  28208. }
  28209. throw new Error('Hint array in the linearization dictionary is invalid.');
  28210. }
  28211. var parser = new Parser(new Lexer(stream), false, null);
  28212. var obj1 = parser.getObj();
  28213. var obj2 = parser.getObj();
  28214. var obj3 = parser.getObj();
  28215. var linDict = parser.getObj();
  28216. var obj, length;
  28217. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28218. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28219. return null; // No valid linearization dictionary found.
  28220. } else if ((length = getInt('L')) !== stream.length) {
  28221. throw new Error('The "L" parameter in the linearization dictionary ' +
  28222. 'does not equal the stream length.');
  28223. }
  28224. return {
  28225. length: length,
  28226. hints: getHints(),
  28227. objectNumberFirst: getInt('O'),
  28228. endFirst: getInt('E'),
  28229. numPages: getInt('N'),
  28230. mainXRefEntriesOffset: getInt('T'),
  28231. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28232. };
  28233. }
  28234. };
  28235. var PostScriptParser = (function PostScriptParserClosure() {
  28236. function PostScriptParser(lexer) {
  28237. this.lexer = lexer;
  28238. this.operators = [];
  28239. this.token = null;
  28240. this.prev = null;
  28241. }
  28242. PostScriptParser.prototype = {
  28243. nextToken: function PostScriptParser_nextToken() {
  28244. this.prev = this.token;
  28245. this.token = this.lexer.getToken();
  28246. },
  28247. accept: function PostScriptParser_accept(type) {
  28248. if (this.token.type === type) {
  28249. this.nextToken();
  28250. return true;
  28251. }
  28252. return false;
  28253. },
  28254. expect: function PostScriptParser_expect(type) {
  28255. if (this.accept(type)) {
  28256. return true;
  28257. }
  28258. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  28259. type + '.');
  28260. },
  28261. parse: function PostScriptParser_parse() {
  28262. this.nextToken();
  28263. this.expect(PostScriptTokenTypes.LBRACE);
  28264. this.parseBlock();
  28265. this.expect(PostScriptTokenTypes.RBRACE);
  28266. return this.operators;
  28267. },
  28268. parseBlock: function PostScriptParser_parseBlock() {
  28269. while (true) {
  28270. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  28271. this.operators.push(this.prev.value);
  28272. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  28273. this.operators.push(this.prev.value);
  28274. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28275. this.parseCondition();
  28276. } else {
  28277. return;
  28278. }
  28279. }
  28280. },
  28281. parseCondition: function PostScriptParser_parseCondition() {
  28282. // Add two place holders that will be updated later
  28283. var conditionLocation = this.operators.length;
  28284. this.operators.push(null, null);
  28285. this.parseBlock();
  28286. this.expect(PostScriptTokenTypes.RBRACE);
  28287. if (this.accept(PostScriptTokenTypes.IF)) {
  28288. // The true block is right after the 'if' so it just falls through on
  28289. // true else it jumps and skips the true block.
  28290. this.operators[conditionLocation] = this.operators.length;
  28291. this.operators[conditionLocation + 1] = 'jz';
  28292. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28293. var jumpLocation = this.operators.length;
  28294. this.operators.push(null, null);
  28295. var endOfTrue = this.operators.length;
  28296. this.parseBlock();
  28297. this.expect(PostScriptTokenTypes.RBRACE);
  28298. this.expect(PostScriptTokenTypes.IFELSE);
  28299. // The jump is added at the end of the true block to skip the false
  28300. // block.
  28301. this.operators[jumpLocation] = this.operators.length;
  28302. this.operators[jumpLocation + 1] = 'j';
  28303. this.operators[conditionLocation] = endOfTrue;
  28304. this.operators[conditionLocation + 1] = 'jz';
  28305. } else {
  28306. error('PS Function: error parsing conditional.');
  28307. }
  28308. }
  28309. };
  28310. return PostScriptParser;
  28311. })();
  28312. var PostScriptTokenTypes = {
  28313. LBRACE: 0,
  28314. RBRACE: 1,
  28315. NUMBER: 2,
  28316. OPERATOR: 3,
  28317. IF: 4,
  28318. IFELSE: 5
  28319. };
  28320. var PostScriptToken = (function PostScriptTokenClosure() {
  28321. function PostScriptToken(type, value) {
  28322. this.type = type;
  28323. this.value = value;
  28324. }
  28325. var opCache = {};
  28326. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  28327. var opValue = opCache[op];
  28328. if (opValue) {
  28329. return opValue;
  28330. }
  28331. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  28332. };
  28333. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  28334. '{');
  28335. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  28336. '}');
  28337. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  28338. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  28339. 'IFELSE');
  28340. return PostScriptToken;
  28341. })();
  28342. var PostScriptLexer = (function PostScriptLexerClosure() {
  28343. function PostScriptLexer(stream) {
  28344. this.stream = stream;
  28345. this.nextChar();
  28346. this.strBuf = [];
  28347. }
  28348. PostScriptLexer.prototype = {
  28349. nextChar: function PostScriptLexer_nextChar() {
  28350. return (this.currentChar = this.stream.getByte());
  28351. },
  28352. getToken: function PostScriptLexer_getToken() {
  28353. var comment = false;
  28354. var ch = this.currentChar;
  28355. // skip comments
  28356. while (true) {
  28357. if (ch < 0) {
  28358. return EOF;
  28359. }
  28360. if (comment) {
  28361. if (ch === 0x0A || ch === 0x0D) {
  28362. comment = false;
  28363. }
  28364. } else if (ch === 0x25) { // '%'
  28365. comment = true;
  28366. } else if (!Lexer.isSpace(ch)) {
  28367. break;
  28368. }
  28369. ch = this.nextChar();
  28370. }
  28371. switch (ch | 0) {
  28372. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28373. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28374. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28375. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  28376. this.getNumber());
  28377. case 0x7B: // '{'
  28378. this.nextChar();
  28379. return PostScriptToken.LBRACE;
  28380. case 0x7D: // '}'
  28381. this.nextChar();
  28382. return PostScriptToken.RBRACE;
  28383. }
  28384. // operator
  28385. var strBuf = this.strBuf;
  28386. strBuf.length = 0;
  28387. strBuf[0] = String.fromCharCode(ch);
  28388. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  28389. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  28390. strBuf.push(String.fromCharCode(ch));
  28391. }
  28392. var str = strBuf.join('');
  28393. switch (str.toLowerCase()) {
  28394. case 'if':
  28395. return PostScriptToken.IF;
  28396. case 'ifelse':
  28397. return PostScriptToken.IFELSE;
  28398. default:
  28399. return PostScriptToken.getOperator(str);
  28400. }
  28401. },
  28402. getNumber: function PostScriptLexer_getNumber() {
  28403. var ch = this.currentChar;
  28404. var strBuf = this.strBuf;
  28405. strBuf.length = 0;
  28406. strBuf[0] = String.fromCharCode(ch);
  28407. while ((ch = this.nextChar()) >= 0) {
  28408. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  28409. ch === 0x2D || ch === 0x2E) { // '-', '.'
  28410. strBuf.push(String.fromCharCode(ch));
  28411. } else {
  28412. break;
  28413. }
  28414. }
  28415. var value = parseFloat(strBuf.join(''));
  28416. if (isNaN(value)) {
  28417. error('Invalid floating point number: ' + value);
  28418. }
  28419. return value;
  28420. }
  28421. };
  28422. return PostScriptLexer;
  28423. })();
  28424. var Stream = (function StreamClosure() {
  28425. function Stream(arrayBuffer, start, length, dict) {
  28426. this.bytes = (arrayBuffer instanceof Uint8Array ?
  28427. arrayBuffer : new Uint8Array(arrayBuffer));
  28428. this.start = start || 0;
  28429. this.pos = this.start;
  28430. this.end = (start + length) || this.bytes.length;
  28431. this.dict = dict;
  28432. }
  28433. // required methods for a stream. if a particular stream does not
  28434. // implement these, an error should be thrown
  28435. Stream.prototype = {
  28436. get length() {
  28437. return this.end - this.start;
  28438. },
  28439. get isEmpty() {
  28440. return this.length === 0;
  28441. },
  28442. getByte: function Stream_getByte() {
  28443. if (this.pos >= this.end) {
  28444. return -1;
  28445. }
  28446. return this.bytes[this.pos++];
  28447. },
  28448. getUint16: function Stream_getUint16() {
  28449. var b0 = this.getByte();
  28450. var b1 = this.getByte();
  28451. return (b0 << 8) + b1;
  28452. },
  28453. getInt32: function Stream_getInt32() {
  28454. var b0 = this.getByte();
  28455. var b1 = this.getByte();
  28456. var b2 = this.getByte();
  28457. var b3 = this.getByte();
  28458. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  28459. },
  28460. // returns subarray of original buffer
  28461. // should only be read
  28462. getBytes: function Stream_getBytes(length) {
  28463. var bytes = this.bytes;
  28464. var pos = this.pos;
  28465. var strEnd = this.end;
  28466. if (!length) {
  28467. return bytes.subarray(pos, strEnd);
  28468. }
  28469. var end = pos + length;
  28470. if (end > strEnd) {
  28471. end = strEnd;
  28472. }
  28473. this.pos = end;
  28474. return bytes.subarray(pos, end);
  28475. },
  28476. peekBytes: function Stream_peekBytes(length) {
  28477. var bytes = this.getBytes(length);
  28478. this.pos -= bytes.length;
  28479. return bytes;
  28480. },
  28481. skip: function Stream_skip(n) {
  28482. if (!n) {
  28483. n = 1;
  28484. }
  28485. this.pos += n;
  28486. },
  28487. reset: function Stream_reset() {
  28488. this.pos = this.start;
  28489. },
  28490. moveStart: function Stream_moveStart() {
  28491. this.start = this.pos;
  28492. },
  28493. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  28494. return new Stream(this.bytes.buffer, start, length, dict);
  28495. },
  28496. isStream: true
  28497. };
  28498. return Stream;
  28499. })();
  28500. var StringStream = (function StringStreamClosure() {
  28501. function StringStream(str) {
  28502. var length = str.length;
  28503. var bytes = new Uint8Array(length);
  28504. for (var n = 0; n < length; ++n) {
  28505. bytes[n] = str.charCodeAt(n);
  28506. }
  28507. Stream.call(this, bytes);
  28508. }
  28509. StringStream.prototype = Stream.prototype;
  28510. return StringStream;
  28511. })();
  28512. // super class for the decoding streams
  28513. var DecodeStream = (function DecodeStreamClosure() {
  28514. // Lots of DecodeStreams are created whose buffers are never used. For these
  28515. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  28516. // having special cases that would be required if we used |null| for an empty
  28517. // buffer.
  28518. var emptyBuffer = new Uint8Array(0);
  28519. function DecodeStream(maybeMinBufferLength) {
  28520. this.pos = 0;
  28521. this.bufferLength = 0;
  28522. this.eof = false;
  28523. this.buffer = emptyBuffer;
  28524. this.minBufferLength = 512;
  28525. if (maybeMinBufferLength) {
  28526. // Compute the first power of two that is as big as maybeMinBufferLength.
  28527. while (this.minBufferLength < maybeMinBufferLength) {
  28528. this.minBufferLength *= 2;
  28529. }
  28530. }
  28531. }
  28532. DecodeStream.prototype = {
  28533. get isEmpty() {
  28534. while (!this.eof && this.bufferLength === 0) {
  28535. this.readBlock();
  28536. }
  28537. return this.bufferLength === 0;
  28538. },
  28539. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  28540. var buffer = this.buffer;
  28541. if (requested <= buffer.byteLength) {
  28542. return buffer;
  28543. }
  28544. var size = this.minBufferLength;
  28545. while (size < requested) {
  28546. size *= 2;
  28547. }
  28548. var buffer2 = new Uint8Array(size);
  28549. buffer2.set(buffer);
  28550. return (this.buffer = buffer2);
  28551. },
  28552. getByte: function DecodeStream_getByte() {
  28553. var pos = this.pos;
  28554. while (this.bufferLength <= pos) {
  28555. if (this.eof) {
  28556. return -1;
  28557. }
  28558. this.readBlock();
  28559. }
  28560. return this.buffer[this.pos++];
  28561. },
  28562. getUint16: function DecodeStream_getUint16() {
  28563. var b0 = this.getByte();
  28564. var b1 = this.getByte();
  28565. return (b0 << 8) + b1;
  28566. },
  28567. getInt32: function DecodeStream_getInt32() {
  28568. var b0 = this.getByte();
  28569. var b1 = this.getByte();
  28570. var b2 = this.getByte();
  28571. var b3 = this.getByte();
  28572. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  28573. },
  28574. getBytes: function DecodeStream_getBytes(length) {
  28575. var end, pos = this.pos;
  28576. if (length) {
  28577. this.ensureBuffer(pos + length);
  28578. end = pos + length;
  28579. while (!this.eof && this.bufferLength < end) {
  28580. this.readBlock();
  28581. }
  28582. var bufEnd = this.bufferLength;
  28583. if (end > bufEnd) {
  28584. end = bufEnd;
  28585. }
  28586. } else {
  28587. while (!this.eof) {
  28588. this.readBlock();
  28589. }
  28590. end = this.bufferLength;
  28591. }
  28592. this.pos = end;
  28593. return this.buffer.subarray(pos, end);
  28594. },
  28595. peekBytes: function DecodeStream_peekBytes(length) {
  28596. var bytes = this.getBytes(length);
  28597. this.pos -= bytes.length;
  28598. return bytes;
  28599. },
  28600. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  28601. var end = start + length;
  28602. while (this.bufferLength <= end && !this.eof) {
  28603. this.readBlock();
  28604. }
  28605. return new Stream(this.buffer, start, length, dict);
  28606. },
  28607. skip: function DecodeStream_skip(n) {
  28608. if (!n) {
  28609. n = 1;
  28610. }
  28611. this.pos += n;
  28612. },
  28613. reset: function DecodeStream_reset() {
  28614. this.pos = 0;
  28615. },
  28616. getBaseStreams: function DecodeStream_getBaseStreams() {
  28617. if (this.str && this.str.getBaseStreams) {
  28618. return this.str.getBaseStreams();
  28619. }
  28620. return [];
  28621. }
  28622. };
  28623. return DecodeStream;
  28624. })();
  28625. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  28626. function StreamsSequenceStream(streams) {
  28627. this.streams = streams;
  28628. DecodeStream.call(this, /* maybeLength = */ null);
  28629. }
  28630. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  28631. StreamsSequenceStream.prototype.readBlock =
  28632. function streamSequenceStreamReadBlock() {
  28633. var streams = this.streams;
  28634. if (streams.length === 0) {
  28635. this.eof = true;
  28636. return;
  28637. }
  28638. var stream = streams.shift();
  28639. var chunk = stream.getBytes();
  28640. var bufferLength = this.bufferLength;
  28641. var newLength = bufferLength + chunk.length;
  28642. var buffer = this.ensureBuffer(newLength);
  28643. buffer.set(chunk, bufferLength);
  28644. this.bufferLength = newLength;
  28645. };
  28646. StreamsSequenceStream.prototype.getBaseStreams =
  28647. function StreamsSequenceStream_getBaseStreams() {
  28648. var baseStreams = [];
  28649. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  28650. var stream = this.streams[i];
  28651. if (stream.getBaseStreams) {
  28652. Util.appendToArray(baseStreams, stream.getBaseStreams());
  28653. }
  28654. }
  28655. return baseStreams;
  28656. };
  28657. return StreamsSequenceStream;
  28658. })();
  28659. var FlateStream = (function FlateStreamClosure() {
  28660. var codeLenCodeMap = new Uint32Array([
  28661. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  28662. ]);
  28663. var lengthDecode = new Uint32Array([
  28664. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  28665. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  28666. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  28667. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  28668. ]);
  28669. var distDecode = new Uint32Array([
  28670. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  28671. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  28672. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  28673. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  28674. ]);
  28675. var fixedLitCodeTab = [new Uint32Array([
  28676. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  28677. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  28678. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  28679. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  28680. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  28681. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  28682. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  28683. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  28684. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  28685. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  28686. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  28687. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  28688. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  28689. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  28690. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  28691. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  28692. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  28693. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  28694. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  28695. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  28696. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  28697. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  28698. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  28699. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  28700. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  28701. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  28702. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  28703. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  28704. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  28705. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  28706. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  28707. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  28708. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  28709. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  28710. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  28711. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  28712. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  28713. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  28714. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  28715. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  28716. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  28717. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  28718. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  28719. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  28720. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  28721. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  28722. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  28723. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  28724. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  28725. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  28726. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  28727. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  28728. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  28729. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  28730. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  28731. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  28732. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  28733. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  28734. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  28735. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  28736. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  28737. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  28738. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  28739. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  28740. ]), 9];
  28741. var fixedDistCodeTab = [new Uint32Array([
  28742. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  28743. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  28744. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  28745. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  28746. ]), 5];
  28747. function FlateStream(str, maybeLength) {
  28748. this.str = str;
  28749. this.dict = str.dict;
  28750. var cmf = str.getByte();
  28751. var flg = str.getByte();
  28752. if (cmf === -1 || flg === -1) {
  28753. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  28754. }
  28755. if ((cmf & 0x0f) !== 0x08) {
  28756. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  28757. }
  28758. if ((((cmf << 8) + flg) % 31) !== 0) {
  28759. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  28760. }
  28761. if (flg & 0x20) {
  28762. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  28763. }
  28764. this.codeSize = 0;
  28765. this.codeBuf = 0;
  28766. DecodeStream.call(this, maybeLength);
  28767. }
  28768. FlateStream.prototype = Object.create(DecodeStream.prototype);
  28769. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  28770. var str = this.str;
  28771. var codeSize = this.codeSize;
  28772. var codeBuf = this.codeBuf;
  28773. var b;
  28774. while (codeSize < bits) {
  28775. if ((b = str.getByte()) === -1) {
  28776. error('Bad encoding in flate stream');
  28777. }
  28778. codeBuf |= b << codeSize;
  28779. codeSize += 8;
  28780. }
  28781. b = codeBuf & ((1 << bits) - 1);
  28782. this.codeBuf = codeBuf >> bits;
  28783. this.codeSize = codeSize -= bits;
  28784. return b;
  28785. };
  28786. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  28787. var str = this.str;
  28788. var codes = table[0];
  28789. var maxLen = table[1];
  28790. var codeSize = this.codeSize;
  28791. var codeBuf = this.codeBuf;
  28792. var b;
  28793. while (codeSize < maxLen) {
  28794. if ((b = str.getByte()) === -1) {
  28795. // premature end of stream. code might however still be valid.
  28796. // codeSize < codeLen check below guards against incomplete codeVal.
  28797. break;
  28798. }
  28799. codeBuf |= (b << codeSize);
  28800. codeSize += 8;
  28801. }
  28802. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  28803. var codeLen = code >> 16;
  28804. var codeVal = code & 0xffff;
  28805. if (codeLen < 1 || codeSize < codeLen) {
  28806. error('Bad encoding in flate stream');
  28807. }
  28808. this.codeBuf = (codeBuf >> codeLen);
  28809. this.codeSize = (codeSize - codeLen);
  28810. return codeVal;
  28811. };
  28812. FlateStream.prototype.generateHuffmanTable =
  28813. function flateStreamGenerateHuffmanTable(lengths) {
  28814. var n = lengths.length;
  28815. // find max code length
  28816. var maxLen = 0;
  28817. var i;
  28818. for (i = 0; i < n; ++i) {
  28819. if (lengths[i] > maxLen) {
  28820. maxLen = lengths[i];
  28821. }
  28822. }
  28823. // build the table
  28824. var size = 1 << maxLen;
  28825. var codes = new Uint32Array(size);
  28826. for (var len = 1, code = 0, skip = 2;
  28827. len <= maxLen;
  28828. ++len, code <<= 1, skip <<= 1) {
  28829. for (var val = 0; val < n; ++val) {
  28830. if (lengths[val] === len) {
  28831. // bit-reverse the code
  28832. var code2 = 0;
  28833. var t = code;
  28834. for (i = 0; i < len; ++i) {
  28835. code2 = (code2 << 1) | (t & 1);
  28836. t >>= 1;
  28837. }
  28838. // fill the table entries
  28839. for (i = code2; i < size; i += skip) {
  28840. codes[i] = (len << 16) | val;
  28841. }
  28842. ++code;
  28843. }
  28844. }
  28845. }
  28846. return [codes, maxLen];
  28847. };
  28848. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  28849. var buffer, len;
  28850. var str = this.str;
  28851. // read block header
  28852. var hdr = this.getBits(3);
  28853. if (hdr & 1) {
  28854. this.eof = true;
  28855. }
  28856. hdr >>= 1;
  28857. if (hdr === 0) { // uncompressed block
  28858. var b;
  28859. if ((b = str.getByte()) === -1) {
  28860. error('Bad block header in flate stream');
  28861. }
  28862. var blockLen = b;
  28863. if ((b = str.getByte()) === -1) {
  28864. error('Bad block header in flate stream');
  28865. }
  28866. blockLen |= (b << 8);
  28867. if ((b = str.getByte()) === -1) {
  28868. error('Bad block header in flate stream');
  28869. }
  28870. var check = b;
  28871. if ((b = str.getByte()) === -1) {
  28872. error('Bad block header in flate stream');
  28873. }
  28874. check |= (b << 8);
  28875. if (check !== (~blockLen & 0xffff) &&
  28876. (blockLen !== 0 || check !== 0)) {
  28877. // Ignoring error for bad "empty" block (see issue 1277)
  28878. error('Bad uncompressed block length in flate stream');
  28879. }
  28880. this.codeBuf = 0;
  28881. this.codeSize = 0;
  28882. var bufferLength = this.bufferLength;
  28883. buffer = this.ensureBuffer(bufferLength + blockLen);
  28884. var end = bufferLength + blockLen;
  28885. this.bufferLength = end;
  28886. if (blockLen === 0) {
  28887. if (str.peekBytes(1).length === 0) {
  28888. this.eof = true;
  28889. }
  28890. } else {
  28891. for (var n = bufferLength; n < end; ++n) {
  28892. if ((b = str.getByte()) === -1) {
  28893. this.eof = true;
  28894. break;
  28895. }
  28896. buffer[n] = b;
  28897. }
  28898. }
  28899. return;
  28900. }
  28901. var litCodeTable;
  28902. var distCodeTable;
  28903. if (hdr === 1) { // compressed block, fixed codes
  28904. litCodeTable = fixedLitCodeTab;
  28905. distCodeTable = fixedDistCodeTab;
  28906. } else if (hdr === 2) { // compressed block, dynamic codes
  28907. var numLitCodes = this.getBits(5) + 257;
  28908. var numDistCodes = this.getBits(5) + 1;
  28909. var numCodeLenCodes = this.getBits(4) + 4;
  28910. // build the code lengths code table
  28911. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  28912. var i;
  28913. for (i = 0; i < numCodeLenCodes; ++i) {
  28914. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  28915. }
  28916. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  28917. // build the literal and distance code tables
  28918. len = 0;
  28919. i = 0;
  28920. var codes = numLitCodes + numDistCodes;
  28921. var codeLengths = new Uint8Array(codes);
  28922. var bitsLength, bitsOffset, what;
  28923. while (i < codes) {
  28924. var code = this.getCode(codeLenCodeTab);
  28925. if (code === 16) {
  28926. bitsLength = 2; bitsOffset = 3; what = len;
  28927. } else if (code === 17) {
  28928. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  28929. } else if (code === 18) {
  28930. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  28931. } else {
  28932. codeLengths[i++] = len = code;
  28933. continue;
  28934. }
  28935. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  28936. while (repeatLength-- > 0) {
  28937. codeLengths[i++] = what;
  28938. }
  28939. }
  28940. litCodeTable =
  28941. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  28942. distCodeTable =
  28943. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  28944. } else {
  28945. error('Unknown block type in flate stream');
  28946. }
  28947. buffer = this.buffer;
  28948. var limit = buffer ? buffer.length : 0;
  28949. var pos = this.bufferLength;
  28950. while (true) {
  28951. var code1 = this.getCode(litCodeTable);
  28952. if (code1 < 256) {
  28953. if (pos + 1 >= limit) {
  28954. buffer = this.ensureBuffer(pos + 1);
  28955. limit = buffer.length;
  28956. }
  28957. buffer[pos++] = code1;
  28958. continue;
  28959. }
  28960. if (code1 === 256) {
  28961. this.bufferLength = pos;
  28962. return;
  28963. }
  28964. code1 -= 257;
  28965. code1 = lengthDecode[code1];
  28966. var code2 = code1 >> 16;
  28967. if (code2 > 0) {
  28968. code2 = this.getBits(code2);
  28969. }
  28970. len = (code1 & 0xffff) + code2;
  28971. code1 = this.getCode(distCodeTable);
  28972. code1 = distDecode[code1];
  28973. code2 = code1 >> 16;
  28974. if (code2 > 0) {
  28975. code2 = this.getBits(code2);
  28976. }
  28977. var dist = (code1 & 0xffff) + code2;
  28978. if (pos + len >= limit) {
  28979. buffer = this.ensureBuffer(pos + len);
  28980. limit = buffer.length;
  28981. }
  28982. for (var k = 0; k < len; ++k, ++pos) {
  28983. buffer[pos] = buffer[pos - dist];
  28984. }
  28985. }
  28986. };
  28987. return FlateStream;
  28988. })();
  28989. var PredictorStream = (function PredictorStreamClosure() {
  28990. function PredictorStream(str, maybeLength, params) {
  28991. var predictor = this.predictor = params.get('Predictor') || 1;
  28992. if (predictor <= 1) {
  28993. return str; // no prediction
  28994. }
  28995. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  28996. error('Unsupported predictor: ' + predictor);
  28997. }
  28998. if (predictor === 2) {
  28999. this.readBlock = this.readBlockTiff;
  29000. } else {
  29001. this.readBlock = this.readBlockPng;
  29002. }
  29003. this.str = str;
  29004. this.dict = str.dict;
  29005. var colors = this.colors = params.get('Colors') || 1;
  29006. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29007. var columns = this.columns = params.get('Columns') || 1;
  29008. this.pixBytes = (colors * bits + 7) >> 3;
  29009. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29010. DecodeStream.call(this, maybeLength);
  29011. return this;
  29012. }
  29013. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29014. PredictorStream.prototype.readBlockTiff =
  29015. function predictorStreamReadBlockTiff() {
  29016. var rowBytes = this.rowBytes;
  29017. var bufferLength = this.bufferLength;
  29018. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29019. var bits = this.bits;
  29020. var colors = this.colors;
  29021. var rawBytes = this.str.getBytes(rowBytes);
  29022. this.eof = !rawBytes.length;
  29023. if (this.eof) {
  29024. return;
  29025. }
  29026. var inbuf = 0, outbuf = 0;
  29027. var inbits = 0, outbits = 0;
  29028. var pos = bufferLength;
  29029. var i;
  29030. if (bits === 1) {
  29031. for (i = 0; i < rowBytes; ++i) {
  29032. var c = rawBytes[i];
  29033. inbuf = (inbuf << 8) | c;
  29034. // bitwise addition is exclusive or
  29035. // first shift inbuf and then add
  29036. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  29037. // truncate inbuf (assumes colors < 16)
  29038. inbuf &= 0xFFFF;
  29039. }
  29040. } else if (bits === 8) {
  29041. for (i = 0; i < colors; ++i) {
  29042. buffer[pos++] = rawBytes[i];
  29043. }
  29044. for (; i < rowBytes; ++i) {
  29045. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  29046. pos++;
  29047. }
  29048. } else {
  29049. var compArray = new Uint8Array(colors + 1);
  29050. var bitMask = (1 << bits) - 1;
  29051. var j = 0, k = bufferLength;
  29052. var columns = this.columns;
  29053. for (i = 0; i < columns; ++i) {
  29054. for (var kk = 0; kk < colors; ++kk) {
  29055. if (inbits < bits) {
  29056. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  29057. inbits += 8;
  29058. }
  29059. compArray[kk] = (compArray[kk] +
  29060. (inbuf >> (inbits - bits))) & bitMask;
  29061. inbits -= bits;
  29062. outbuf = (outbuf << bits) | compArray[kk];
  29063. outbits += bits;
  29064. if (outbits >= 8) {
  29065. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  29066. outbits -= 8;
  29067. }
  29068. }
  29069. }
  29070. if (outbits > 0) {
  29071. buffer[k++] = (outbuf << (8 - outbits)) +
  29072. (inbuf & ((1 << (8 - outbits)) - 1));
  29073. }
  29074. }
  29075. this.bufferLength += rowBytes;
  29076. };
  29077. PredictorStream.prototype.readBlockPng =
  29078. function predictorStreamReadBlockPng() {
  29079. var rowBytes = this.rowBytes;
  29080. var pixBytes = this.pixBytes;
  29081. var predictor = this.str.getByte();
  29082. var rawBytes = this.str.getBytes(rowBytes);
  29083. this.eof = !rawBytes.length;
  29084. if (this.eof) {
  29085. return;
  29086. }
  29087. var bufferLength = this.bufferLength;
  29088. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29089. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  29090. if (prevRow.length === 0) {
  29091. prevRow = new Uint8Array(rowBytes);
  29092. }
  29093. var i, j = bufferLength, up, c;
  29094. switch (predictor) {
  29095. case 0:
  29096. for (i = 0; i < rowBytes; ++i) {
  29097. buffer[j++] = rawBytes[i];
  29098. }
  29099. break;
  29100. case 1:
  29101. for (i = 0; i < pixBytes; ++i) {
  29102. buffer[j++] = rawBytes[i];
  29103. }
  29104. for (; i < rowBytes; ++i) {
  29105. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  29106. j++;
  29107. }
  29108. break;
  29109. case 2:
  29110. for (i = 0; i < rowBytes; ++i) {
  29111. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  29112. }
  29113. break;
  29114. case 3:
  29115. for (i = 0; i < pixBytes; ++i) {
  29116. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  29117. }
  29118. for (; i < rowBytes; ++i) {
  29119. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  29120. rawBytes[i]) & 0xFF;
  29121. j++;
  29122. }
  29123. break;
  29124. case 4:
  29125. // we need to save the up left pixels values. the simplest way
  29126. // is to create a new buffer
  29127. for (i = 0; i < pixBytes; ++i) {
  29128. up = prevRow[i];
  29129. c = rawBytes[i];
  29130. buffer[j++] = up + c;
  29131. }
  29132. for (; i < rowBytes; ++i) {
  29133. up = prevRow[i];
  29134. var upLeft = prevRow[i - pixBytes];
  29135. var left = buffer[j - pixBytes];
  29136. var p = left + up - upLeft;
  29137. var pa = p - left;
  29138. if (pa < 0) {
  29139. pa = -pa;
  29140. }
  29141. var pb = p - up;
  29142. if (pb < 0) {
  29143. pb = -pb;
  29144. }
  29145. var pc = p - upLeft;
  29146. if (pc < 0) {
  29147. pc = -pc;
  29148. }
  29149. c = rawBytes[i];
  29150. if (pa <= pb && pa <= pc) {
  29151. buffer[j++] = left + c;
  29152. } else if (pb <= pc) {
  29153. buffer[j++] = up + c;
  29154. } else {
  29155. buffer[j++] = upLeft + c;
  29156. }
  29157. }
  29158. break;
  29159. default:
  29160. error('Unsupported predictor: ' + predictor);
  29161. }
  29162. this.bufferLength += rowBytes;
  29163. };
  29164. return PredictorStream;
  29165. })();
  29166. /**
  29167. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  29168. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  29169. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  29170. * a library to decode these images and the stream behaves like all the other
  29171. * DecodeStreams.
  29172. */
  29173. var JpegStream = (function JpegStreamClosure() {
  29174. function JpegStream(stream, maybeLength, dict, xref) {
  29175. // TODO: per poppler, some images may have 'junk' before that
  29176. // need to be removed
  29177. this.stream = stream;
  29178. this.maybeLength = maybeLength;
  29179. this.dict = dict;
  29180. DecodeStream.call(this, maybeLength);
  29181. }
  29182. JpegStream.prototype = Object.create(DecodeStream.prototype);
  29183. Object.defineProperty(JpegStream.prototype, 'bytes', {
  29184. get: function JpegStream_bytes() {
  29185. // If this.maybeLength is null, we'll get the entire stream.
  29186. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29187. },
  29188. configurable: true
  29189. });
  29190. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  29191. if (this.bufferLength) {
  29192. return;
  29193. }
  29194. try {
  29195. var jpegImage = new JpegImage();
  29196. // checking if values needs to be transformed before conversion
  29197. if (this.dict && isArray(this.dict.get('Decode'))) {
  29198. var decodeArr = this.dict.get('Decode');
  29199. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  29200. var decodeArrLength = decodeArr.length;
  29201. var transform = new Int32Array(decodeArrLength);
  29202. var transformNeeded = false;
  29203. var maxValue = (1 << bitsPerComponent) - 1;
  29204. for (var i = 0; i < decodeArrLength; i += 2) {
  29205. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  29206. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  29207. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  29208. transformNeeded = true;
  29209. }
  29210. }
  29211. if (transformNeeded) {
  29212. jpegImage.decodeTransform = transform;
  29213. }
  29214. }
  29215. jpegImage.parse(this.bytes);
  29216. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  29217. this.forceRGB);
  29218. this.buffer = data;
  29219. this.bufferLength = data.length;
  29220. this.eof = true;
  29221. } catch (e) {
  29222. error('JPEG error: ' + e);
  29223. }
  29224. };
  29225. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  29226. this.ensureBuffer();
  29227. return this.buffer;
  29228. };
  29229. JpegStream.prototype.getIR = function JpegStream_getIR() {
  29230. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  29231. };
  29232. /**
  29233. * Checks if the image can be decoded and displayed by the browser without any
  29234. * further processing such as color space conversions.
  29235. */
  29236. JpegStream.prototype.isNativelySupported =
  29237. function JpegStream_isNativelySupported(xref, res) {
  29238. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29239. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  29240. };
  29241. /**
  29242. * Checks if the image can be decoded by the browser.
  29243. */
  29244. JpegStream.prototype.isNativelyDecodable =
  29245. function JpegStream_isNativelyDecodable(xref, res) {
  29246. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29247. var numComps = cs.numComps;
  29248. return numComps === 1 || numComps === 3;
  29249. };
  29250. return JpegStream;
  29251. })();
  29252. /**
  29253. * For JPEG 2000's we use a library to decode these images and
  29254. * the stream behaves like all the other DecodeStreams.
  29255. */
  29256. var JpxStream = (function JpxStreamClosure() {
  29257. function JpxStream(stream, maybeLength, dict) {
  29258. this.stream = stream;
  29259. this.maybeLength = maybeLength;
  29260. this.dict = dict;
  29261. DecodeStream.call(this, maybeLength);
  29262. }
  29263. JpxStream.prototype = Object.create(DecodeStream.prototype);
  29264. Object.defineProperty(JpxStream.prototype, 'bytes', {
  29265. get: function JpxStream_bytes() {
  29266. // If this.maybeLength is null, we'll get the entire stream.
  29267. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29268. },
  29269. configurable: true
  29270. });
  29271. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  29272. if (this.bufferLength) {
  29273. return;
  29274. }
  29275. var jpxImage = new JpxImage();
  29276. jpxImage.parse(this.bytes);
  29277. var width = jpxImage.width;
  29278. var height = jpxImage.height;
  29279. var componentsCount = jpxImage.componentsCount;
  29280. var tileCount = jpxImage.tiles.length;
  29281. if (tileCount === 1) {
  29282. this.buffer = jpxImage.tiles[0].items;
  29283. } else {
  29284. var data = new Uint8Array(width * height * componentsCount);
  29285. for (var k = 0; k < tileCount; k++) {
  29286. var tileComponents = jpxImage.tiles[k];
  29287. var tileWidth = tileComponents.width;
  29288. var tileHeight = tileComponents.height;
  29289. var tileLeft = tileComponents.left;
  29290. var tileTop = tileComponents.top;
  29291. var src = tileComponents.items;
  29292. var srcPosition = 0;
  29293. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  29294. var imgRowSize = width * componentsCount;
  29295. var tileRowSize = tileWidth * componentsCount;
  29296. for (var j = 0; j < tileHeight; j++) {
  29297. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  29298. data.set(rowBytes, dataPosition);
  29299. srcPosition += tileRowSize;
  29300. dataPosition += imgRowSize;
  29301. }
  29302. }
  29303. this.buffer = data;
  29304. }
  29305. this.bufferLength = this.buffer.length;
  29306. this.eof = true;
  29307. };
  29308. return JpxStream;
  29309. })();
  29310. /**
  29311. * For JBIG2's we use a library to decode these images and
  29312. * the stream behaves like all the other DecodeStreams.
  29313. */
  29314. var Jbig2Stream = (function Jbig2StreamClosure() {
  29315. function Jbig2Stream(stream, maybeLength, dict) {
  29316. this.stream = stream;
  29317. this.maybeLength = maybeLength;
  29318. this.dict = dict;
  29319. DecodeStream.call(this, maybeLength);
  29320. }
  29321. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  29322. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  29323. get: function Jbig2Stream_bytes() {
  29324. // If this.maybeLength is null, we'll get the entire stream.
  29325. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29326. },
  29327. configurable: true
  29328. });
  29329. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  29330. if (this.bufferLength) {
  29331. return;
  29332. }
  29333. var jbig2Image = new Jbig2Image();
  29334. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  29335. // According to the PDF specification, DecodeParms can be either
  29336. // a dictionary, or an array whose elements are dictionaries.
  29337. if (isArray(decodeParams)) {
  29338. if (decodeParams.length > 1) {
  29339. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  29340. 'not supported.');
  29341. }
  29342. decodeParams = decodeParams[0];
  29343. }
  29344. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  29345. var globalsStream = decodeParams.get('JBIG2Globals');
  29346. var globals = globalsStream.getBytes();
  29347. chunks.push({data: globals, start: 0, end: globals.length});
  29348. }
  29349. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  29350. var data = jbig2Image.parseChunks(chunks);
  29351. var dataLength = data.length;
  29352. // JBIG2 had black as 1 and white as 0, inverting the colors
  29353. for (var i = 0; i < dataLength; i++) {
  29354. data[i] ^= 0xFF;
  29355. }
  29356. this.buffer = data;
  29357. this.bufferLength = dataLength;
  29358. this.eof = true;
  29359. };
  29360. return Jbig2Stream;
  29361. })();
  29362. var DecryptStream = (function DecryptStreamClosure() {
  29363. function DecryptStream(str, maybeLength, decrypt) {
  29364. this.str = str;
  29365. this.dict = str.dict;
  29366. this.decrypt = decrypt;
  29367. this.nextChunk = null;
  29368. this.initialized = false;
  29369. DecodeStream.call(this, maybeLength);
  29370. }
  29371. var chunkSize = 512;
  29372. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  29373. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  29374. var chunk;
  29375. if (this.initialized) {
  29376. chunk = this.nextChunk;
  29377. } else {
  29378. chunk = this.str.getBytes(chunkSize);
  29379. this.initialized = true;
  29380. }
  29381. if (!chunk || chunk.length === 0) {
  29382. this.eof = true;
  29383. return;
  29384. }
  29385. this.nextChunk = this.str.getBytes(chunkSize);
  29386. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  29387. var decrypt = this.decrypt;
  29388. chunk = decrypt(chunk, !hasMoreData);
  29389. var bufferLength = this.bufferLength;
  29390. var i, n = chunk.length;
  29391. var buffer = this.ensureBuffer(bufferLength + n);
  29392. for (i = 0; i < n; i++) {
  29393. buffer[bufferLength++] = chunk[i];
  29394. }
  29395. this.bufferLength = bufferLength;
  29396. };
  29397. return DecryptStream;
  29398. })();
  29399. var Ascii85Stream = (function Ascii85StreamClosure() {
  29400. function Ascii85Stream(str, maybeLength) {
  29401. this.str = str;
  29402. this.dict = str.dict;
  29403. this.input = new Uint8Array(5);
  29404. // Most streams increase in size when decoded, but Ascii85 streams
  29405. // typically shrink by ~20%.
  29406. if (maybeLength) {
  29407. maybeLength = 0.8 * maybeLength;
  29408. }
  29409. DecodeStream.call(this, maybeLength);
  29410. }
  29411. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  29412. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  29413. var TILDA_CHAR = 0x7E; // '~'
  29414. var Z_LOWER_CHAR = 0x7A; // 'z'
  29415. var EOF = -1;
  29416. var str = this.str;
  29417. var c = str.getByte();
  29418. while (Lexer.isSpace(c)) {
  29419. c = str.getByte();
  29420. }
  29421. if (c === EOF || c === TILDA_CHAR) {
  29422. this.eof = true;
  29423. return;
  29424. }
  29425. var bufferLength = this.bufferLength, buffer;
  29426. var i;
  29427. // special code for z
  29428. if (c === Z_LOWER_CHAR) {
  29429. buffer = this.ensureBuffer(bufferLength + 4);
  29430. for (i = 0; i < 4; ++i) {
  29431. buffer[bufferLength + i] = 0;
  29432. }
  29433. this.bufferLength += 4;
  29434. } else {
  29435. var input = this.input;
  29436. input[0] = c;
  29437. for (i = 1; i < 5; ++i) {
  29438. c = str.getByte();
  29439. while (Lexer.isSpace(c)) {
  29440. c = str.getByte();
  29441. }
  29442. input[i] = c;
  29443. if (c === EOF || c === TILDA_CHAR) {
  29444. break;
  29445. }
  29446. }
  29447. buffer = this.ensureBuffer(bufferLength + i - 1);
  29448. this.bufferLength += i - 1;
  29449. // partial ending;
  29450. if (i < 5) {
  29451. for (; i < 5; ++i) {
  29452. input[i] = 0x21 + 84;
  29453. }
  29454. this.eof = true;
  29455. }
  29456. var t = 0;
  29457. for (i = 0; i < 5; ++i) {
  29458. t = t * 85 + (input[i] - 0x21);
  29459. }
  29460. for (i = 3; i >= 0; --i) {
  29461. buffer[bufferLength + i] = t & 0xFF;
  29462. t >>= 8;
  29463. }
  29464. }
  29465. };
  29466. return Ascii85Stream;
  29467. })();
  29468. var AsciiHexStream = (function AsciiHexStreamClosure() {
  29469. function AsciiHexStream(str, maybeLength) {
  29470. this.str = str;
  29471. this.dict = str.dict;
  29472. this.firstDigit = -1;
  29473. // Most streams increase in size when decoded, but AsciiHex streams shrink
  29474. // by 50%.
  29475. if (maybeLength) {
  29476. maybeLength = 0.5 * maybeLength;
  29477. }
  29478. DecodeStream.call(this, maybeLength);
  29479. }
  29480. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  29481. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  29482. var UPSTREAM_BLOCK_SIZE = 8000;
  29483. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  29484. if (!bytes.length) {
  29485. this.eof = true;
  29486. return;
  29487. }
  29488. var maxDecodeLength = (bytes.length + 1) >> 1;
  29489. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  29490. var bufferLength = this.bufferLength;
  29491. var firstDigit = this.firstDigit;
  29492. for (var i = 0, ii = bytes.length; i < ii; i++) {
  29493. var ch = bytes[i], digit;
  29494. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29495. digit = ch & 0x0F;
  29496. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29497. // 'A'-'Z', 'a'-'z'
  29498. digit = (ch & 0x0F) + 9;
  29499. } else if (ch === 0x3E) { // '>'
  29500. this.eof = true;
  29501. break;
  29502. } else { // probably whitespace
  29503. continue; // ignoring
  29504. }
  29505. if (firstDigit < 0) {
  29506. firstDigit = digit;
  29507. } else {
  29508. buffer[bufferLength++] = (firstDigit << 4) | digit;
  29509. firstDigit = -1;
  29510. }
  29511. }
  29512. if (firstDigit >= 0 && this.eof) {
  29513. // incomplete byte
  29514. buffer[bufferLength++] = (firstDigit << 4);
  29515. firstDigit = -1;
  29516. }
  29517. this.firstDigit = firstDigit;
  29518. this.bufferLength = bufferLength;
  29519. };
  29520. return AsciiHexStream;
  29521. })();
  29522. var RunLengthStream = (function RunLengthStreamClosure() {
  29523. function RunLengthStream(str, maybeLength) {
  29524. this.str = str;
  29525. this.dict = str.dict;
  29526. DecodeStream.call(this, maybeLength);
  29527. }
  29528. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  29529. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  29530. // The repeatHeader has following format. The first byte defines type of run
  29531. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  29532. // (in addition to the second byte from the header), n = 129 through 255 -
  29533. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  29534. var repeatHeader = this.str.getBytes(2);
  29535. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  29536. this.eof = true;
  29537. return;
  29538. }
  29539. var buffer;
  29540. var bufferLength = this.bufferLength;
  29541. var n = repeatHeader[0];
  29542. if (n < 128) {
  29543. // copy n bytes
  29544. buffer = this.ensureBuffer(bufferLength + n + 1);
  29545. buffer[bufferLength++] = repeatHeader[1];
  29546. if (n > 0) {
  29547. var source = this.str.getBytes(n);
  29548. buffer.set(source, bufferLength);
  29549. bufferLength += n;
  29550. }
  29551. } else {
  29552. n = 257 - n;
  29553. var b = repeatHeader[1];
  29554. buffer = this.ensureBuffer(bufferLength + n + 1);
  29555. for (var i = 0; i < n; i++) {
  29556. buffer[bufferLength++] = b;
  29557. }
  29558. }
  29559. this.bufferLength = bufferLength;
  29560. };
  29561. return RunLengthStream;
  29562. })();
  29563. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  29564. var ccittEOL = -2;
  29565. var twoDimPass = 0;
  29566. var twoDimHoriz = 1;
  29567. var twoDimVert0 = 2;
  29568. var twoDimVertR1 = 3;
  29569. var twoDimVertL1 = 4;
  29570. var twoDimVertR2 = 5;
  29571. var twoDimVertL2 = 6;
  29572. var twoDimVertR3 = 7;
  29573. var twoDimVertL3 = 8;
  29574. var twoDimTable = [
  29575. [-1, -1], [-1, -1], // 000000x
  29576. [7, twoDimVertL3], // 0000010
  29577. [7, twoDimVertR3], // 0000011
  29578. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  29579. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  29580. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  29581. [4, twoDimPass], [4, twoDimPass],
  29582. [4, twoDimPass], [4, twoDimPass],
  29583. [4, twoDimPass], [4, twoDimPass],
  29584. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  29585. [3, twoDimHoriz], [3, twoDimHoriz],
  29586. [3, twoDimHoriz], [3, twoDimHoriz],
  29587. [3, twoDimHoriz], [3, twoDimHoriz],
  29588. [3, twoDimHoriz], [3, twoDimHoriz],
  29589. [3, twoDimHoriz], [3, twoDimHoriz],
  29590. [3, twoDimHoriz], [3, twoDimHoriz],
  29591. [3, twoDimHoriz], [3, twoDimHoriz],
  29592. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  29593. [3, twoDimVertL1], [3, twoDimVertL1],
  29594. [3, twoDimVertL1], [3, twoDimVertL1],
  29595. [3, twoDimVertL1], [3, twoDimVertL1],
  29596. [3, twoDimVertL1], [3, twoDimVertL1],
  29597. [3, twoDimVertL1], [3, twoDimVertL1],
  29598. [3, twoDimVertL1], [3, twoDimVertL1],
  29599. [3, twoDimVertL1], [3, twoDimVertL1],
  29600. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  29601. [3, twoDimVertR1], [3, twoDimVertR1],
  29602. [3, twoDimVertR1], [3, twoDimVertR1],
  29603. [3, twoDimVertR1], [3, twoDimVertR1],
  29604. [3, twoDimVertR1], [3, twoDimVertR1],
  29605. [3, twoDimVertR1], [3, twoDimVertR1],
  29606. [3, twoDimVertR1], [3, twoDimVertR1],
  29607. [3, twoDimVertR1], [3, twoDimVertR1],
  29608. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  29609. [1, twoDimVert0], [1, twoDimVert0],
  29610. [1, twoDimVert0], [1, twoDimVert0],
  29611. [1, twoDimVert0], [1, twoDimVert0],
  29612. [1, twoDimVert0], [1, twoDimVert0],
  29613. [1, twoDimVert0], [1, twoDimVert0],
  29614. [1, twoDimVert0], [1, twoDimVert0],
  29615. [1, twoDimVert0], [1, twoDimVert0],
  29616. [1, twoDimVert0], [1, twoDimVert0],
  29617. [1, twoDimVert0], [1, twoDimVert0],
  29618. [1, twoDimVert0], [1, twoDimVert0],
  29619. [1, twoDimVert0], [1, twoDimVert0],
  29620. [1, twoDimVert0], [1, twoDimVert0],
  29621. [1, twoDimVert0], [1, twoDimVert0],
  29622. [1, twoDimVert0], [1, twoDimVert0],
  29623. [1, twoDimVert0], [1, twoDimVert0],
  29624. [1, twoDimVert0], [1, twoDimVert0],
  29625. [1, twoDimVert0], [1, twoDimVert0],
  29626. [1, twoDimVert0], [1, twoDimVert0],
  29627. [1, twoDimVert0], [1, twoDimVert0],
  29628. [1, twoDimVert0], [1, twoDimVert0],
  29629. [1, twoDimVert0], [1, twoDimVert0],
  29630. [1, twoDimVert0], [1, twoDimVert0],
  29631. [1, twoDimVert0], [1, twoDimVert0],
  29632. [1, twoDimVert0], [1, twoDimVert0],
  29633. [1, twoDimVert0], [1, twoDimVert0],
  29634. [1, twoDimVert0], [1, twoDimVert0],
  29635. [1, twoDimVert0], [1, twoDimVert0],
  29636. [1, twoDimVert0], [1, twoDimVert0],
  29637. [1, twoDimVert0], [1, twoDimVert0],
  29638. [1, twoDimVert0], [1, twoDimVert0],
  29639. [1, twoDimVert0], [1, twoDimVert0]
  29640. ];
  29641. var whiteTable1 = [
  29642. [-1, -1], // 00000
  29643. [12, ccittEOL], // 00001
  29644. [-1, -1], [-1, -1], // 0001x
  29645. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  29646. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  29647. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  29648. [11, 1792], [11, 1792], // 1000x
  29649. [12, 1984], // 10010
  29650. [12, 2048], // 10011
  29651. [12, 2112], // 10100
  29652. [12, 2176], // 10101
  29653. [12, 2240], // 10110
  29654. [12, 2304], // 10111
  29655. [11, 1856], [11, 1856], // 1100x
  29656. [11, 1920], [11, 1920], // 1101x
  29657. [12, 2368], // 11100
  29658. [12, 2432], // 11101
  29659. [12, 2496], // 11110
  29660. [12, 2560] // 11111
  29661. ];
  29662. var whiteTable2 = [
  29663. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  29664. [8, 29], [8, 29], // 00000010x
  29665. [8, 30], [8, 30], // 00000011x
  29666. [8, 45], [8, 45], // 00000100x
  29667. [8, 46], [8, 46], // 00000101x
  29668. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  29669. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  29670. [8, 47], [8, 47], // 00001010x
  29671. [8, 48], [8, 48], // 00001011x
  29672. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  29673. [6, 13], [6, 13], [6, 13], [6, 13],
  29674. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  29675. [8, 33], [8, 33], // 00010010x
  29676. [8, 34], [8, 34], // 00010011x
  29677. [8, 35], [8, 35], // 00010100x
  29678. [8, 36], [8, 36], // 00010101x
  29679. [8, 37], [8, 37], // 00010110x
  29680. [8, 38], [8, 38], // 00010111x
  29681. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  29682. [8, 31], [8, 31], // 00011010x
  29683. [8, 32], [8, 32], // 00011011x
  29684. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  29685. [6, 1], [6, 1], [6, 1], [6, 1],
  29686. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  29687. [6, 12], [6, 12], [6, 12], [6, 12],
  29688. [8, 53], [8, 53], // 00100100x
  29689. [8, 54], [8, 54], // 00100101x
  29690. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  29691. [8, 39], [8, 39], // 00101000x
  29692. [8, 40], [8, 40], // 00101001x
  29693. [8, 41], [8, 41], // 00101010x
  29694. [8, 42], [8, 42], // 00101011x
  29695. [8, 43], [8, 43], // 00101100x
  29696. [8, 44], [8, 44], // 00101101x
  29697. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  29698. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  29699. [8, 61], [8, 61], // 00110010x
  29700. [8, 62], [8, 62], // 00110011x
  29701. [8, 63], [8, 63], // 00110100x
  29702. [8, 0], [8, 0], // 00110101x
  29703. [8, 320], [8, 320], // 00110110x
  29704. [8, 384], [8, 384], // 00110111x
  29705. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  29706. [5, 10], [5, 10], [5, 10], [5, 10],
  29707. [5, 10], [5, 10], [5, 10], [5, 10],
  29708. [5, 10], [5, 10], [5, 10], [5, 10],
  29709. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  29710. [5, 11], [5, 11], [5, 11], [5, 11],
  29711. [5, 11], [5, 11], [5, 11], [5, 11],
  29712. [5, 11], [5, 11], [5, 11], [5, 11],
  29713. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  29714. [8, 59], [8, 59], // 01001010x
  29715. [8, 60], [8, 60], // 01001011x
  29716. [9, 1472], // 010011000
  29717. [9, 1536], // 010011001
  29718. [9, 1600], // 010011010
  29719. [9, 1728], // 010011011
  29720. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  29721. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  29722. [8, 49], [8, 49], // 01010010x
  29723. [8, 50], [8, 50], // 01010011x
  29724. [8, 51], [8, 51], // 01010100x
  29725. [8, 52], [8, 52], // 01010101x
  29726. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  29727. [8, 55], [8, 55], // 01011000x
  29728. [8, 56], [8, 56], // 01011001x
  29729. [8, 57], [8, 57], // 01011010x
  29730. [8, 58], [8, 58], // 01011011x
  29731. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  29732. [6, 192], [6, 192], [6, 192], [6, 192],
  29733. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  29734. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  29735. [8, 448], [8, 448], // 01100100x
  29736. [8, 512], [8, 512], // 01100101x
  29737. [9, 704], // 011001100
  29738. [9, 768], // 011001101
  29739. [8, 640], [8, 640], // 01100111x
  29740. [8, 576], [8, 576], // 01101000x
  29741. [9, 832], // 011010010
  29742. [9, 896], // 011010011
  29743. [9, 960], // 011010100
  29744. [9, 1024], // 011010101
  29745. [9, 1088], // 011010110
  29746. [9, 1152], // 011010111
  29747. [9, 1216], // 011011000
  29748. [9, 1280], // 011011001
  29749. [9, 1344], // 011011010
  29750. [9, 1408], // 011011011
  29751. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  29752. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  29753. [4, 2], [4, 2], [4, 2], [4, 2],
  29754. [4, 2], [4, 2], [4, 2], [4, 2],
  29755. [4, 2], [4, 2], [4, 2], [4, 2],
  29756. [4, 2], [4, 2], [4, 2], [4, 2],
  29757. [4, 2], [4, 2], [4, 2], [4, 2],
  29758. [4, 2], [4, 2], [4, 2], [4, 2],
  29759. [4, 2], [4, 2], [4, 2], [4, 2],
  29760. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  29761. [4, 3], [4, 3], [4, 3], [4, 3],
  29762. [4, 3], [4, 3], [4, 3], [4, 3],
  29763. [4, 3], [4, 3], [4, 3], [4, 3],
  29764. [4, 3], [4, 3], [4, 3], [4, 3],
  29765. [4, 3], [4, 3], [4, 3], [4, 3],
  29766. [4, 3], [4, 3], [4, 3], [4, 3],
  29767. [4, 3], [4, 3], [4, 3], [4, 3],
  29768. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  29769. [5, 128], [5, 128], [5, 128], [5, 128],
  29770. [5, 128], [5, 128], [5, 128], [5, 128],
  29771. [5, 128], [5, 128], [5, 128], [5, 128],
  29772. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  29773. [5, 8], [5, 8], [5, 8], [5, 8],
  29774. [5, 8], [5, 8], [5, 8], [5, 8],
  29775. [5, 8], [5, 8], [5, 8], [5, 8],
  29776. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  29777. [5, 9], [5, 9], [5, 9], [5, 9],
  29778. [5, 9], [5, 9], [5, 9], [5, 9],
  29779. [5, 9], [5, 9], [5, 9], [5, 9],
  29780. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  29781. [6, 16], [6, 16], [6, 16], [6, 16],
  29782. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  29783. [6, 17], [6, 17], [6, 17], [6, 17],
  29784. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  29785. [4, 4], [4, 4], [4, 4], [4, 4],
  29786. [4, 4], [4, 4], [4, 4], [4, 4],
  29787. [4, 4], [4, 4], [4, 4], [4, 4],
  29788. [4, 4], [4, 4], [4, 4], [4, 4],
  29789. [4, 4], [4, 4], [4, 4], [4, 4],
  29790. [4, 4], [4, 4], [4, 4], [4, 4],
  29791. [4, 4], [4, 4], [4, 4], [4, 4],
  29792. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  29793. [4, 5], [4, 5], [4, 5], [4, 5],
  29794. [4, 5], [4, 5], [4, 5], [4, 5],
  29795. [4, 5], [4, 5], [4, 5], [4, 5],
  29796. [4, 5], [4, 5], [4, 5], [4, 5],
  29797. [4, 5], [4, 5], [4, 5], [4, 5],
  29798. [4, 5], [4, 5], [4, 5], [4, 5],
  29799. [4, 5], [4, 5], [4, 5], [4, 5],
  29800. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  29801. [6, 14], [6, 14], [6, 14], [6, 14],
  29802. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  29803. [6, 15], [6, 15], [6, 15], [6, 15],
  29804. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  29805. [5, 64], [5, 64], [5, 64], [5, 64],
  29806. [5, 64], [5, 64], [5, 64], [5, 64],
  29807. [5, 64], [5, 64], [5, 64], [5, 64],
  29808. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  29809. [4, 6], [4, 6], [4, 6], [4, 6],
  29810. [4, 6], [4, 6], [4, 6], [4, 6],
  29811. [4, 6], [4, 6], [4, 6], [4, 6],
  29812. [4, 6], [4, 6], [4, 6], [4, 6],
  29813. [4, 6], [4, 6], [4, 6], [4, 6],
  29814. [4, 6], [4, 6], [4, 6], [4, 6],
  29815. [4, 6], [4, 6], [4, 6], [4, 6],
  29816. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  29817. [4, 7], [4, 7], [4, 7], [4, 7],
  29818. [4, 7], [4, 7], [4, 7], [4, 7],
  29819. [4, 7], [4, 7], [4, 7], [4, 7],
  29820. [4, 7], [4, 7], [4, 7], [4, 7],
  29821. [4, 7], [4, 7], [4, 7], [4, 7],
  29822. [4, 7], [4, 7], [4, 7], [4, 7],
  29823. [4, 7], [4, 7], [4, 7], [4, 7]
  29824. ];
  29825. var blackTable1 = [
  29826. [-1, -1], [-1, -1], // 000000000000x
  29827. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  29828. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  29829. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  29830. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  29831. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  29832. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  29833. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  29834. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  29835. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  29836. [12, 1984], [12, 1984], // 000000010010x
  29837. [12, 2048], [12, 2048], // 000000010011x
  29838. [12, 2112], [12, 2112], // 000000010100x
  29839. [12, 2176], [12, 2176], // 000000010101x
  29840. [12, 2240], [12, 2240], // 000000010110x
  29841. [12, 2304], [12, 2304], // 000000010111x
  29842. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  29843. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  29844. [12, 2368], [12, 2368], // 000000011100x
  29845. [12, 2432], [12, 2432], // 000000011101x
  29846. [12, 2496], [12, 2496], // 000000011110x
  29847. [12, 2560], [12, 2560], // 000000011111x
  29848. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  29849. [10, 18], [10, 18], [10, 18], [10, 18],
  29850. [12, 52], [12, 52], // 000000100100x
  29851. [13, 640], // 0000001001010
  29852. [13, 704], // 0000001001011
  29853. [13, 768], // 0000001001100
  29854. [13, 832], // 0000001001101
  29855. [12, 55], [12, 55], // 000000100111x
  29856. [12, 56], [12, 56], // 000000101000x
  29857. [13, 1280], // 0000001010010
  29858. [13, 1344], // 0000001010011
  29859. [13, 1408], // 0000001010100
  29860. [13, 1472], // 0000001010101
  29861. [12, 59], [12, 59], // 000000101011x
  29862. [12, 60], [12, 60], // 000000101100x
  29863. [13, 1536], // 0000001011010
  29864. [13, 1600], // 0000001011011
  29865. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  29866. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  29867. [13, 1664], // 0000001100100
  29868. [13, 1728], // 0000001100101
  29869. [12, 320], [12, 320], // 000000110011x
  29870. [12, 384], [12, 384], // 000000110100x
  29871. [12, 448], [12, 448], // 000000110101x
  29872. [13, 512], // 0000001101100
  29873. [13, 576], // 0000001101101
  29874. [12, 53], [12, 53], // 000000110111x
  29875. [12, 54], [12, 54], // 000000111000x
  29876. [13, 896], // 0000001110010
  29877. [13, 960], // 0000001110011
  29878. [13, 1024], // 0000001110100
  29879. [13, 1088], // 0000001110101
  29880. [13, 1152], // 0000001110110
  29881. [13, 1216], // 0000001110111
  29882. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  29883. [10, 64], [10, 64], [10, 64], [10, 64]
  29884. ];
  29885. var blackTable2 = [
  29886. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  29887. [8, 13], [8, 13], [8, 13], [8, 13],
  29888. [8, 13], [8, 13], [8, 13], [8, 13],
  29889. [8, 13], [8, 13], [8, 13], [8, 13],
  29890. [11, 23], [11, 23], // 00000101000x
  29891. [12, 50], // 000001010010
  29892. [12, 51], // 000001010011
  29893. [12, 44], // 000001010100
  29894. [12, 45], // 000001010101
  29895. [12, 46], // 000001010110
  29896. [12, 47], // 000001010111
  29897. [12, 57], // 000001011000
  29898. [12, 58], // 000001011001
  29899. [12, 61], // 000001011010
  29900. [12, 256], // 000001011011
  29901. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  29902. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  29903. [12, 48], // 000001100100
  29904. [12, 49], // 000001100101
  29905. [12, 62], // 000001100110
  29906. [12, 63], // 000001100111
  29907. [12, 30], // 000001101000
  29908. [12, 31], // 000001101001
  29909. [12, 32], // 000001101010
  29910. [12, 33], // 000001101011
  29911. [12, 40], // 000001101100
  29912. [12, 41], // 000001101101
  29913. [11, 22], [11, 22], // 00000110111x
  29914. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  29915. [8, 14], [8, 14], [8, 14], [8, 14],
  29916. [8, 14], [8, 14], [8, 14], [8, 14],
  29917. [8, 14], [8, 14], [8, 14], [8, 14],
  29918. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  29919. [7, 10], [7, 10], [7, 10], [7, 10],
  29920. [7, 10], [7, 10], [7, 10], [7, 10],
  29921. [7, 10], [7, 10], [7, 10], [7, 10],
  29922. [7, 10], [7, 10], [7, 10], [7, 10],
  29923. [7, 10], [7, 10], [7, 10], [7, 10],
  29924. [7, 10], [7, 10], [7, 10], [7, 10],
  29925. [7, 10], [7, 10], [7, 10], [7, 10],
  29926. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  29927. [7, 11], [7, 11], [7, 11], [7, 11],
  29928. [7, 11], [7, 11], [7, 11], [7, 11],
  29929. [7, 11], [7, 11], [7, 11], [7, 11],
  29930. [7, 11], [7, 11], [7, 11], [7, 11],
  29931. [7, 11], [7, 11], [7, 11], [7, 11],
  29932. [7, 11], [7, 11], [7, 11], [7, 11],
  29933. [7, 11], [7, 11], [7, 11], [7, 11],
  29934. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  29935. [9, 15], [9, 15], [9, 15], [9, 15],
  29936. [12, 128], // 000011001000
  29937. [12, 192], // 000011001001
  29938. [12, 26], // 000011001010
  29939. [12, 27], // 000011001011
  29940. [12, 28], // 000011001100
  29941. [12, 29], // 000011001101
  29942. [11, 19], [11, 19], // 00001100111x
  29943. [11, 20], [11, 20], // 00001101000x
  29944. [12, 34], // 000011010010
  29945. [12, 35], // 000011010011
  29946. [12, 36], // 000011010100
  29947. [12, 37], // 000011010101
  29948. [12, 38], // 000011010110
  29949. [12, 39], // 000011010111
  29950. [11, 21], [11, 21], // 00001101100x
  29951. [12, 42], // 000011011010
  29952. [12, 43], // 000011011011
  29953. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  29954. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  29955. [7, 12], [7, 12], [7, 12], [7, 12],
  29956. [7, 12], [7, 12], [7, 12], [7, 12],
  29957. [7, 12], [7, 12], [7, 12], [7, 12],
  29958. [7, 12], [7, 12], [7, 12], [7, 12],
  29959. [7, 12], [7, 12], [7, 12], [7, 12],
  29960. [7, 12], [7, 12], [7, 12], [7, 12],
  29961. [7, 12], [7, 12], [7, 12], [7, 12]
  29962. ];
  29963. var blackTable3 = [
  29964. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  29965. [6, 9], // 000100
  29966. [6, 8], // 000101
  29967. [5, 7], [5, 7], // 00011x
  29968. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  29969. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  29970. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  29971. [3, 1], [3, 1], [3, 1], [3, 1],
  29972. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  29973. [3, 4], [3, 4], [3, 4], [3, 4],
  29974. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  29975. [2, 3], [2, 3], [2, 3], [2, 3],
  29976. [2, 3], [2, 3], [2, 3], [2, 3],
  29977. [2, 3], [2, 3], [2, 3], [2, 3],
  29978. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  29979. [2, 2], [2, 2], [2, 2], [2, 2],
  29980. [2, 2], [2, 2], [2, 2], [2, 2],
  29981. [2, 2], [2, 2], [2, 2], [2, 2]
  29982. ];
  29983. function CCITTFaxStream(str, maybeLength, params) {
  29984. this.str = str;
  29985. this.dict = str.dict;
  29986. params = params || Dict.empty;
  29987. this.encoding = params.get('K') || 0;
  29988. this.eoline = params.get('EndOfLine') || false;
  29989. this.byteAlign = params.get('EncodedByteAlign') || false;
  29990. this.columns = params.get('Columns') || 1728;
  29991. this.rows = params.get('Rows') || 0;
  29992. var eoblock = params.get('EndOfBlock');
  29993. if (eoblock === null || eoblock === undefined) {
  29994. eoblock = true;
  29995. }
  29996. this.eoblock = eoblock;
  29997. this.black = params.get('BlackIs1') || false;
  29998. this.codingLine = new Uint32Array(this.columns + 1);
  29999. this.refLine = new Uint32Array(this.columns + 2);
  30000. this.codingLine[0] = this.columns;
  30001. this.codingPos = 0;
  30002. this.row = 0;
  30003. this.nextLine2D = this.encoding < 0;
  30004. this.inputBits = 0;
  30005. this.inputBuf = 0;
  30006. this.outputBits = 0;
  30007. var code1;
  30008. while ((code1 = this.lookBits(12)) === 0) {
  30009. this.eatBits(1);
  30010. }
  30011. if (code1 === 1) {
  30012. this.eatBits(12);
  30013. }
  30014. if (this.encoding > 0) {
  30015. this.nextLine2D = !this.lookBits(1);
  30016. this.eatBits(1);
  30017. }
  30018. DecodeStream.call(this, maybeLength);
  30019. }
  30020. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30021. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30022. while (!this.eof) {
  30023. var c = this.lookChar();
  30024. this.ensureBuffer(this.bufferLength + 1);
  30025. this.buffer[this.bufferLength++] = c;
  30026. }
  30027. };
  30028. CCITTFaxStream.prototype.addPixels =
  30029. function ccittFaxStreamAddPixels(a1, blackPixels) {
  30030. var codingLine = this.codingLine;
  30031. var codingPos = this.codingPos;
  30032. if (a1 > codingLine[codingPos]) {
  30033. if (a1 > this.columns) {
  30034. info('row is wrong length');
  30035. this.err = true;
  30036. a1 = this.columns;
  30037. }
  30038. if ((codingPos & 1) ^ blackPixels) {
  30039. ++codingPos;
  30040. }
  30041. codingLine[codingPos] = a1;
  30042. }
  30043. this.codingPos = codingPos;
  30044. };
  30045. CCITTFaxStream.prototype.addPixelsNeg =
  30046. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30047. var codingLine = this.codingLine;
  30048. var codingPos = this.codingPos;
  30049. if (a1 > codingLine[codingPos]) {
  30050. if (a1 > this.columns) {
  30051. info('row is wrong length');
  30052. this.err = true;
  30053. a1 = this.columns;
  30054. }
  30055. if ((codingPos & 1) ^ blackPixels) {
  30056. ++codingPos;
  30057. }
  30058. codingLine[codingPos] = a1;
  30059. } else if (a1 < codingLine[codingPos]) {
  30060. if (a1 < 0) {
  30061. info('invalid code');
  30062. this.err = true;
  30063. a1 = 0;
  30064. }
  30065. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30066. --codingPos;
  30067. }
  30068. codingLine[codingPos] = a1;
  30069. }
  30070. this.codingPos = codingPos;
  30071. };
  30072. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30073. var refLine = this.refLine;
  30074. var codingLine = this.codingLine;
  30075. var columns = this.columns;
  30076. var refPos, blackPixels, bits, i;
  30077. if (this.outputBits === 0) {
  30078. if (this.eof) {
  30079. return null;
  30080. }
  30081. this.err = false;
  30082. var code1, code2, code3;
  30083. if (this.nextLine2D) {
  30084. for (i = 0; codingLine[i] < columns; ++i) {
  30085. refLine[i] = codingLine[i];
  30086. }
  30087. refLine[i++] = columns;
  30088. refLine[i] = columns;
  30089. codingLine[0] = 0;
  30090. this.codingPos = 0;
  30091. refPos = 0;
  30092. blackPixels = 0;
  30093. while (codingLine[this.codingPos] < columns) {
  30094. code1 = this.getTwoDimCode();
  30095. switch (code1) {
  30096. case twoDimPass:
  30097. this.addPixels(refLine[refPos + 1], blackPixels);
  30098. if (refLine[refPos + 1] < columns) {
  30099. refPos += 2;
  30100. }
  30101. break;
  30102. case twoDimHoriz:
  30103. code1 = code2 = 0;
  30104. if (blackPixels) {
  30105. do {
  30106. code1 += (code3 = this.getBlackCode());
  30107. } while (code3 >= 64);
  30108. do {
  30109. code2 += (code3 = this.getWhiteCode());
  30110. } while (code3 >= 64);
  30111. } else {
  30112. do {
  30113. code1 += (code3 = this.getWhiteCode());
  30114. } while (code3 >= 64);
  30115. do {
  30116. code2 += (code3 = this.getBlackCode());
  30117. } while (code3 >= 64);
  30118. }
  30119. this.addPixels(codingLine[this.codingPos] +
  30120. code1, blackPixels);
  30121. if (codingLine[this.codingPos] < columns) {
  30122. this.addPixels(codingLine[this.codingPos] + code2,
  30123. blackPixels ^ 1);
  30124. }
  30125. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30126. refLine[refPos] < columns) {
  30127. refPos += 2;
  30128. }
  30129. break;
  30130. case twoDimVertR3:
  30131. this.addPixels(refLine[refPos] + 3, blackPixels);
  30132. blackPixels ^= 1;
  30133. if (codingLine[this.codingPos] < columns) {
  30134. ++refPos;
  30135. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30136. refLine[refPos] < columns) {
  30137. refPos += 2;
  30138. }
  30139. }
  30140. break;
  30141. case twoDimVertR2:
  30142. this.addPixels(refLine[refPos] + 2, blackPixels);
  30143. blackPixels ^= 1;
  30144. if (codingLine[this.codingPos] < columns) {
  30145. ++refPos;
  30146. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30147. refLine[refPos] < columns) {
  30148. refPos += 2;
  30149. }
  30150. }
  30151. break;
  30152. case twoDimVertR1:
  30153. this.addPixels(refLine[refPos] + 1, blackPixels);
  30154. blackPixels ^= 1;
  30155. if (codingLine[this.codingPos] < columns) {
  30156. ++refPos;
  30157. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30158. refLine[refPos] < columns) {
  30159. refPos += 2;
  30160. }
  30161. }
  30162. break;
  30163. case twoDimVert0:
  30164. this.addPixels(refLine[refPos], blackPixels);
  30165. blackPixels ^= 1;
  30166. if (codingLine[this.codingPos] < columns) {
  30167. ++refPos;
  30168. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30169. refLine[refPos] < columns) {
  30170. refPos += 2;
  30171. }
  30172. }
  30173. break;
  30174. case twoDimVertL3:
  30175. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30176. blackPixels ^= 1;
  30177. if (codingLine[this.codingPos] < columns) {
  30178. if (refPos > 0) {
  30179. --refPos;
  30180. } else {
  30181. ++refPos;
  30182. }
  30183. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30184. refLine[refPos] < columns) {
  30185. refPos += 2;
  30186. }
  30187. }
  30188. break;
  30189. case twoDimVertL2:
  30190. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30191. blackPixels ^= 1;
  30192. if (codingLine[this.codingPos] < columns) {
  30193. if (refPos > 0) {
  30194. --refPos;
  30195. } else {
  30196. ++refPos;
  30197. }
  30198. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30199. refLine[refPos] < columns) {
  30200. refPos += 2;
  30201. }
  30202. }
  30203. break;
  30204. case twoDimVertL1:
  30205. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30206. blackPixels ^= 1;
  30207. if (codingLine[this.codingPos] < columns) {
  30208. if (refPos > 0) {
  30209. --refPos;
  30210. } else {
  30211. ++refPos;
  30212. }
  30213. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30214. refLine[refPos] < columns) {
  30215. refPos += 2;
  30216. }
  30217. }
  30218. break;
  30219. case EOF:
  30220. this.addPixels(columns, 0);
  30221. this.eof = true;
  30222. break;
  30223. default:
  30224. info('bad 2d code');
  30225. this.addPixels(columns, 0);
  30226. this.err = true;
  30227. }
  30228. }
  30229. } else {
  30230. codingLine[0] = 0;
  30231. this.codingPos = 0;
  30232. blackPixels = 0;
  30233. while (codingLine[this.codingPos] < columns) {
  30234. code1 = 0;
  30235. if (blackPixels) {
  30236. do {
  30237. code1 += (code3 = this.getBlackCode());
  30238. } while (code3 >= 64);
  30239. } else {
  30240. do {
  30241. code1 += (code3 = this.getWhiteCode());
  30242. } while (code3 >= 64);
  30243. }
  30244. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30245. blackPixels ^= 1;
  30246. }
  30247. }
  30248. var gotEOL = false;
  30249. if (!this.eoblock && this.row === this.rows - 1) {
  30250. this.eof = true;
  30251. } else if (this.eoline || !this.byteAlign) {
  30252. code1 = this.lookBits(12);
  30253. if (this.eoline) {
  30254. while (code1 !== EOF && code1 !== 1) {
  30255. this.eatBits(1);
  30256. code1 = this.lookBits(12);
  30257. }
  30258. } else {
  30259. while (code1 === 0) {
  30260. this.eatBits(1);
  30261. code1 = this.lookBits(12);
  30262. }
  30263. }
  30264. if (code1 === 1) {
  30265. this.eatBits(12);
  30266. gotEOL = true;
  30267. } else if (code1 === EOF) {
  30268. this.eof = true;
  30269. }
  30270. }
  30271. if (this.byteAlign && !gotEOL) {
  30272. this.inputBits &= ~7;
  30273. }
  30274. if (!this.eof && this.encoding > 0) {
  30275. this.nextLine2D = !this.lookBits(1);
  30276. this.eatBits(1);
  30277. }
  30278. if (this.eoblock && gotEOL && this.byteAlign) {
  30279. code1 = this.lookBits(12);
  30280. if (code1 === 1) {
  30281. this.eatBits(12);
  30282. if (this.encoding > 0) {
  30283. this.lookBits(1);
  30284. this.eatBits(1);
  30285. }
  30286. if (this.encoding >= 0) {
  30287. for (i = 0; i < 4; ++i) {
  30288. code1 = this.lookBits(12);
  30289. if (code1 !== 1) {
  30290. info('bad rtc code: ' + code1);
  30291. }
  30292. this.eatBits(12);
  30293. if (this.encoding > 0) {
  30294. this.lookBits(1);
  30295. this.eatBits(1);
  30296. }
  30297. }
  30298. }
  30299. this.eof = true;
  30300. }
  30301. } else if (this.err && this.eoline) {
  30302. while (true) {
  30303. code1 = this.lookBits(13);
  30304. if (code1 === EOF) {
  30305. this.eof = true;
  30306. return null;
  30307. }
  30308. if ((code1 >> 1) === 1) {
  30309. break;
  30310. }
  30311. this.eatBits(1);
  30312. }
  30313. this.eatBits(12);
  30314. if (this.encoding > 0) {
  30315. this.eatBits(1);
  30316. this.nextLine2D = !(code1 & 1);
  30317. }
  30318. }
  30319. if (codingLine[0] > 0) {
  30320. this.outputBits = codingLine[this.codingPos = 0];
  30321. } else {
  30322. this.outputBits = codingLine[this.codingPos = 1];
  30323. }
  30324. this.row++;
  30325. }
  30326. var c;
  30327. if (this.outputBits >= 8) {
  30328. c = (this.codingPos & 1) ? 0 : 0xFF;
  30329. this.outputBits -= 8;
  30330. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30331. this.codingPos++;
  30332. this.outputBits = (codingLine[this.codingPos] -
  30333. codingLine[this.codingPos - 1]);
  30334. }
  30335. } else {
  30336. bits = 8;
  30337. c = 0;
  30338. do {
  30339. if (this.outputBits > bits) {
  30340. c <<= bits;
  30341. if (!(this.codingPos & 1)) {
  30342. c |= 0xFF >> (8 - bits);
  30343. }
  30344. this.outputBits -= bits;
  30345. bits = 0;
  30346. } else {
  30347. c <<= this.outputBits;
  30348. if (!(this.codingPos & 1)) {
  30349. c |= 0xFF >> (8 - this.outputBits);
  30350. }
  30351. bits -= this.outputBits;
  30352. this.outputBits = 0;
  30353. if (codingLine[this.codingPos] < columns) {
  30354. this.codingPos++;
  30355. this.outputBits = (codingLine[this.codingPos] -
  30356. codingLine[this.codingPos - 1]);
  30357. } else if (bits > 0) {
  30358. c <<= bits;
  30359. bits = 0;
  30360. }
  30361. }
  30362. } while (bits);
  30363. }
  30364. if (this.black) {
  30365. c ^= 0xFF;
  30366. }
  30367. return c;
  30368. };
  30369. // This functions returns the code found from the table.
  30370. // The start and end parameters set the boundaries for searching the table.
  30371. // The limit parameter is optional. Function returns an array with three
  30372. // values. The first array element indicates whether a valid code is being
  30373. // returned. The second array element is the actual code. The third array
  30374. // element indicates whether EOF was reached.
  30375. CCITTFaxStream.prototype.findTableCode =
  30376. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30377. var limitValue = limit || 0;
  30378. for (var i = start; i <= end; ++i) {
  30379. var code = this.lookBits(i);
  30380. if (code === EOF) {
  30381. return [true, 1, false];
  30382. }
  30383. if (i < end) {
  30384. code <<= end - i;
  30385. }
  30386. if (!limitValue || code >= limitValue) {
  30387. var p = table[code - limitValue];
  30388. if (p[0] === i) {
  30389. this.eatBits(i);
  30390. return [true, p[1], true];
  30391. }
  30392. }
  30393. }
  30394. return [false, 0, false];
  30395. };
  30396. CCITTFaxStream.prototype.getTwoDimCode =
  30397. function ccittFaxStreamGetTwoDimCode() {
  30398. var code = 0;
  30399. var p;
  30400. if (this.eoblock) {
  30401. code = this.lookBits(7);
  30402. p = twoDimTable[code];
  30403. if (p && p[0] > 0) {
  30404. this.eatBits(p[0]);
  30405. return p[1];
  30406. }
  30407. } else {
  30408. var result = this.findTableCode(1, 7, twoDimTable);
  30409. if (result[0] && result[2]) {
  30410. return result[1];
  30411. }
  30412. }
  30413. info('Bad two dim code');
  30414. return EOF;
  30415. };
  30416. CCITTFaxStream.prototype.getWhiteCode =
  30417. function ccittFaxStreamGetWhiteCode() {
  30418. var code = 0;
  30419. var p;
  30420. if (this.eoblock) {
  30421. code = this.lookBits(12);
  30422. if (code === EOF) {
  30423. return 1;
  30424. }
  30425. if ((code >> 5) === 0) {
  30426. p = whiteTable1[code];
  30427. } else {
  30428. p = whiteTable2[code >> 3];
  30429. }
  30430. if (p[0] > 0) {
  30431. this.eatBits(p[0]);
  30432. return p[1];
  30433. }
  30434. } else {
  30435. var result = this.findTableCode(1, 9, whiteTable2);
  30436. if (result[0]) {
  30437. return result[1];
  30438. }
  30439. result = this.findTableCode(11, 12, whiteTable1);
  30440. if (result[0]) {
  30441. return result[1];
  30442. }
  30443. }
  30444. info('bad white code');
  30445. this.eatBits(1);
  30446. return 1;
  30447. };
  30448. CCITTFaxStream.prototype.getBlackCode =
  30449. function ccittFaxStreamGetBlackCode() {
  30450. var code, p;
  30451. if (this.eoblock) {
  30452. code = this.lookBits(13);
  30453. if (code === EOF) {
  30454. return 1;
  30455. }
  30456. if ((code >> 7) === 0) {
  30457. p = blackTable1[code];
  30458. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  30459. p = blackTable2[(code >> 1) - 64];
  30460. } else {
  30461. p = blackTable3[code >> 7];
  30462. }
  30463. if (p[0] > 0) {
  30464. this.eatBits(p[0]);
  30465. return p[1];
  30466. }
  30467. } else {
  30468. var result = this.findTableCode(2, 6, blackTable3);
  30469. if (result[0]) {
  30470. return result[1];
  30471. }
  30472. result = this.findTableCode(7, 12, blackTable2, 64);
  30473. if (result[0]) {
  30474. return result[1];
  30475. }
  30476. result = this.findTableCode(10, 13, blackTable1);
  30477. if (result[0]) {
  30478. return result[1];
  30479. }
  30480. }
  30481. info('bad black code');
  30482. this.eatBits(1);
  30483. return 1;
  30484. };
  30485. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  30486. var c;
  30487. while (this.inputBits < n) {
  30488. if ((c = this.str.getByte()) === -1) {
  30489. if (this.inputBits === 0) {
  30490. return EOF;
  30491. }
  30492. return ((this.inputBuf << (n - this.inputBits)) &
  30493. (0xFFFF >> (16 - n)));
  30494. }
  30495. this.inputBuf = (this.inputBuf << 8) + c;
  30496. this.inputBits += 8;
  30497. }
  30498. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  30499. };
  30500. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  30501. if ((this.inputBits -= n) < 0) {
  30502. this.inputBits = 0;
  30503. }
  30504. };
  30505. return CCITTFaxStream;
  30506. })();
  30507. var LZWStream = (function LZWStreamClosure() {
  30508. function LZWStream(str, maybeLength, earlyChange) {
  30509. this.str = str;
  30510. this.dict = str.dict;
  30511. this.cachedData = 0;
  30512. this.bitsCached = 0;
  30513. var maxLzwDictionarySize = 4096;
  30514. var lzwState = {
  30515. earlyChange: earlyChange,
  30516. codeLength: 9,
  30517. nextCode: 258,
  30518. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  30519. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  30520. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  30521. currentSequence: new Uint8Array(maxLzwDictionarySize),
  30522. currentSequenceLength: 0
  30523. };
  30524. for (var i = 0; i < 256; ++i) {
  30525. lzwState.dictionaryValues[i] = i;
  30526. lzwState.dictionaryLengths[i] = 1;
  30527. }
  30528. this.lzwState = lzwState;
  30529. DecodeStream.call(this, maybeLength);
  30530. }
  30531. LZWStream.prototype = Object.create(DecodeStream.prototype);
  30532. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  30533. var bitsCached = this.bitsCached;
  30534. var cachedData = this.cachedData;
  30535. while (bitsCached < n) {
  30536. var c = this.str.getByte();
  30537. if (c === -1) {
  30538. this.eof = true;
  30539. return null;
  30540. }
  30541. cachedData = (cachedData << 8) | c;
  30542. bitsCached += 8;
  30543. }
  30544. this.bitsCached = (bitsCached -= n);
  30545. this.cachedData = cachedData;
  30546. this.lastCode = null;
  30547. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  30548. };
  30549. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30550. var blockSize = 512;
  30551. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30552. var i, j, q;
  30553. var lzwState = this.lzwState;
  30554. if (!lzwState) {
  30555. return; // eof was found
  30556. }
  30557. var earlyChange = lzwState.earlyChange;
  30558. var nextCode = lzwState.nextCode;
  30559. var dictionaryValues = lzwState.dictionaryValues;
  30560. var dictionaryLengths = lzwState.dictionaryLengths;
  30561. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30562. var codeLength = lzwState.codeLength;
  30563. var prevCode = lzwState.prevCode;
  30564. var currentSequence = lzwState.currentSequence;
  30565. var currentSequenceLength = lzwState.currentSequenceLength;
  30566. var decodedLength = 0;
  30567. var currentBufferLength = this.bufferLength;
  30568. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30569. for (i = 0; i < blockSize; i++) {
  30570. var code = this.readBits(codeLength);
  30571. var hasPrev = currentSequenceLength > 0;
  30572. if (code < 256) {
  30573. currentSequence[0] = code;
  30574. currentSequenceLength = 1;
  30575. } else if (code >= 258) {
  30576. if (code < nextCode) {
  30577. currentSequenceLength = dictionaryLengths[code];
  30578. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30579. currentSequence[j] = dictionaryValues[q];
  30580. q = dictionaryPrevCodes[q];
  30581. }
  30582. } else {
  30583. currentSequence[currentSequenceLength++] = currentSequence[0];
  30584. }
  30585. } else if (code === 256) {
  30586. codeLength = 9;
  30587. nextCode = 258;
  30588. currentSequenceLength = 0;
  30589. continue;
  30590. } else {
  30591. this.eof = true;
  30592. delete this.lzwState;
  30593. break;
  30594. }
  30595. if (hasPrev) {
  30596. dictionaryPrevCodes[nextCode] = prevCode;
  30597. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30598. dictionaryValues[nextCode] = currentSequence[0];
  30599. nextCode++;
  30600. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  30601. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  30602. 0.6931471805599453 + 1, 12) | 0;
  30603. }
  30604. prevCode = code;
  30605. decodedLength += currentSequenceLength;
  30606. if (estimatedDecodedSize < decodedLength) {
  30607. do {
  30608. estimatedDecodedSize += decodedSizeDelta;
  30609. } while (estimatedDecodedSize < decodedLength);
  30610. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30611. }
  30612. for (j = 0; j < currentSequenceLength; j++) {
  30613. buffer[currentBufferLength++] = currentSequence[j];
  30614. }
  30615. }
  30616. lzwState.nextCode = nextCode;
  30617. lzwState.codeLength = codeLength;
  30618. lzwState.prevCode = prevCode;
  30619. lzwState.currentSequenceLength = currentSequenceLength;
  30620. this.bufferLength = currentBufferLength;
  30621. };
  30622. return LZWStream;
  30623. })();
  30624. var NullStream = (function NullStreamClosure() {
  30625. function NullStream() {
  30626. Stream.call(this, new Uint8Array(0));
  30627. }
  30628. NullStream.prototype = Stream.prototype;
  30629. return NullStream;
  30630. })();
  30631. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  30632. setup: function wphSetup(handler) {
  30633. var pdfManager;
  30634. function loadDocument(recoveryMode) {
  30635. var loadDocumentCapability = createPromiseCapability();
  30636. var parseSuccess = function parseSuccess() {
  30637. var numPagesPromise = pdfManager.ensureDoc('numPages');
  30638. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  30639. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  30640. Promise.all([numPagesPromise, fingerprintPromise,
  30641. encryptedPromise]).then(function onDocReady(results) {
  30642. var doc = {
  30643. numPages: results[0],
  30644. fingerprint: results[1],
  30645. encrypted: !!results[2],
  30646. };
  30647. loadDocumentCapability.resolve(doc);
  30648. },
  30649. parseFailure);
  30650. };
  30651. var parseFailure = function parseFailure(e) {
  30652. loadDocumentCapability.reject(e);
  30653. };
  30654. pdfManager.ensureDoc('checkHeader', []).then(function() {
  30655. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  30656. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  30657. parseSuccess, parseFailure);
  30658. }, parseFailure);
  30659. }, parseFailure);
  30660. return loadDocumentCapability.promise;
  30661. }
  30662. function getPdfManager(data) {
  30663. var pdfManagerCapability = createPromiseCapability();
  30664. var source = data.source;
  30665. var disableRange = data.disableRange;
  30666. if (source.data) {
  30667. try {
  30668. pdfManager = new LocalPdfManager(source.data, source.password);
  30669. pdfManagerCapability.resolve();
  30670. } catch (ex) {
  30671. pdfManagerCapability.reject(ex);
  30672. }
  30673. return pdfManagerCapability.promise;
  30674. } else if (source.chunkedViewerLoading) {
  30675. try {
  30676. pdfManager = new NetworkPdfManager(source, handler);
  30677. pdfManagerCapability.resolve();
  30678. } catch (ex) {
  30679. pdfManagerCapability.reject(ex);
  30680. }
  30681. return pdfManagerCapability.promise;
  30682. }
  30683. var networkManager = new NetworkManager(source.url, {
  30684. httpHeaders: source.httpHeaders,
  30685. withCredentials: source.withCredentials
  30686. });
  30687. var fullRequestXhrId = networkManager.requestFull({
  30688. onHeadersReceived: function onHeadersReceived() {
  30689. if (disableRange) {
  30690. return;
  30691. }
  30692. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  30693. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  30694. return;
  30695. }
  30696. var contentEncoding =
  30697. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  30698. if (contentEncoding !== 'identity') {
  30699. return;
  30700. }
  30701. var length = fullRequestXhr.getResponseHeader('Content-Length');
  30702. length = parseInt(length, 10);
  30703. if (!isInt(length)) {
  30704. return;
  30705. }
  30706. source.length = length;
  30707. if (length <= 2 * RANGE_CHUNK_SIZE) {
  30708. // The file size is smaller than the size of two chunks, so it does
  30709. // not make any sense to abort the request and retry with a range
  30710. // request.
  30711. return;
  30712. }
  30713. // NOTE: by cancelling the full request, and then issuing range
  30714. // requests, there will be an issue for sites where you can only
  30715. // request the pdf once. However, if this is the case, then the
  30716. // server should not be returning that it can support range requests.
  30717. networkManager.abortRequest(fullRequestXhrId);
  30718. try {
  30719. pdfManager = new NetworkPdfManager(source, handler);
  30720. pdfManagerCapability.resolve(pdfManager);
  30721. } catch (ex) {
  30722. pdfManagerCapability.reject(ex);
  30723. }
  30724. },
  30725. onDone: function onDone(args) {
  30726. // the data is array, instantiating directly from it
  30727. try {
  30728. pdfManager = new LocalPdfManager(args.chunk, source.password);
  30729. pdfManagerCapability.resolve();
  30730. } catch (ex) {
  30731. pdfManagerCapability.reject(ex);
  30732. }
  30733. },
  30734. onError: function onError(status) {
  30735. if (status === 404) {
  30736. var exception = new MissingPDFException('Missing PDF "' +
  30737. source.url + '".');
  30738. handler.send('MissingPDF', { exception: exception });
  30739. } else {
  30740. handler.send('DocError', 'Unexpected server response (' +
  30741. status + ') while retrieving PDF "' +
  30742. source.url + '".');
  30743. }
  30744. },
  30745. onProgress: function onProgress(evt) {
  30746. handler.send('DocProgress', {
  30747. loaded: evt.loaded,
  30748. total: evt.lengthComputable ? evt.total : source.length
  30749. });
  30750. }
  30751. });
  30752. return pdfManagerCapability.promise;
  30753. }
  30754. handler.on('test', function wphSetupTest(data) {
  30755. // check if Uint8Array can be sent to worker
  30756. if (!(data instanceof Uint8Array)) {
  30757. handler.send('test', false);
  30758. return;
  30759. }
  30760. // making sure postMessage transfers are working
  30761. var supportTransfers = data[0] === 255;
  30762. handler.postMessageTransfers = supportTransfers;
  30763. // check if the response property is supported by xhr
  30764. var xhr = new XMLHttpRequest();
  30765. var responseExists = 'response' in xhr;
  30766. // check if the property is actually implemented
  30767. try {
  30768. var dummy = xhr.responseType;
  30769. } catch (e) {
  30770. responseExists = false;
  30771. }
  30772. if (!responseExists) {
  30773. handler.send('test', false);
  30774. return;
  30775. }
  30776. handler.send('test', {
  30777. supportTypedArray: true,
  30778. supportTransfers: supportTransfers
  30779. });
  30780. });
  30781. handler.on('GetDocRequest', function wphSetupDoc(data) {
  30782. var onSuccess = function(doc) {
  30783. handler.send('GetDoc', { pdfInfo: doc });
  30784. };
  30785. var onFailure = function(e) {
  30786. if (e instanceof PasswordException) {
  30787. if (e.code === PasswordResponses.NEED_PASSWORD) {
  30788. handler.send('NeedPassword', {
  30789. exception: e
  30790. });
  30791. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  30792. handler.send('IncorrectPassword', {
  30793. exception: e
  30794. });
  30795. }
  30796. } else if (e instanceof InvalidPDFException) {
  30797. handler.send('InvalidPDF', {
  30798. exception: e
  30799. });
  30800. } else if (e instanceof MissingPDFException) {
  30801. handler.send('MissingPDF', {
  30802. exception: e
  30803. });
  30804. } else {
  30805. handler.send('UnknownError', {
  30806. exception: new UnknownErrorException(e.message, e.toString())
  30807. });
  30808. }
  30809. };
  30810. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  30811. -1 : data.maxImageSize;
  30812. PDFJS.disableFontFace = data.disableFontFace;
  30813. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  30814. PDFJS.verbosity = data.verbosity;
  30815. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  30816. null : data.cMapUrl;
  30817. PDFJS.cMapPacked = data.cMapPacked === true;
  30818. getPdfManager(data).then(function () {
  30819. pdfManager.onLoadedStream().then(function(stream) {
  30820. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  30821. });
  30822. }).then(function pdfManagerReady() {
  30823. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  30824. // Try again with recoveryMode == true
  30825. if (!(ex instanceof XRefParseException)) {
  30826. if (ex instanceof PasswordException) {
  30827. // after password exception prepare to receive a new password
  30828. // to repeat loading
  30829. pdfManager.passwordChanged().then(pdfManagerReady);
  30830. }
  30831. onFailure(ex);
  30832. return;
  30833. }
  30834. pdfManager.requestLoadedStream();
  30835. pdfManager.onLoadedStream().then(function() {
  30836. loadDocument(true).then(onSuccess, onFailure);
  30837. });
  30838. }, onFailure);
  30839. }, onFailure);
  30840. });
  30841. handler.on('GetPage', function wphSetupGetPage(data) {
  30842. return pdfManager.getPage(data.pageIndex).then(function(page) {
  30843. var rotatePromise = pdfManager.ensure(page, 'rotate');
  30844. var refPromise = pdfManager.ensure(page, 'ref');
  30845. var viewPromise = pdfManager.ensure(page, 'view');
  30846. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  30847. function(results) {
  30848. return {
  30849. rotate: results[0],
  30850. ref: results[1],
  30851. view: results[2]
  30852. };
  30853. });
  30854. });
  30855. });
  30856. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  30857. var ref = new Ref(data.ref.num, data.ref.gen);
  30858. var catalog = pdfManager.pdfDocument.catalog;
  30859. return catalog.getPageIndex(ref);
  30860. });
  30861. handler.on('GetDestinations',
  30862. function wphSetupGetDestinations(data) {
  30863. return pdfManager.ensureCatalog('destinations');
  30864. }
  30865. );
  30866. handler.on('GetAttachments',
  30867. function wphSetupGetAttachments(data) {
  30868. return pdfManager.ensureCatalog('attachments');
  30869. }
  30870. );
  30871. handler.on('GetJavaScript',
  30872. function wphSetupGetJavaScript(data) {
  30873. return pdfManager.ensureCatalog('javaScript');
  30874. }
  30875. );
  30876. handler.on('GetOutline',
  30877. function wphSetupGetOutline(data) {
  30878. return pdfManager.ensureCatalog('documentOutline');
  30879. }
  30880. );
  30881. handler.on('GetMetadata',
  30882. function wphSetupGetMetadata(data) {
  30883. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  30884. pdfManager.ensureCatalog('metadata')]);
  30885. }
  30886. );
  30887. handler.on('GetData', function wphSetupGetData(data) {
  30888. pdfManager.requestLoadedStream();
  30889. return pdfManager.onLoadedStream().then(function(stream) {
  30890. return stream.bytes;
  30891. });
  30892. });
  30893. handler.on('GetStats',
  30894. function wphSetupGetStats(data) {
  30895. return pdfManager.pdfDocument.xref.stats;
  30896. }
  30897. );
  30898. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  30899. pdfManager.updatePassword(data);
  30900. });
  30901. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  30902. return pdfManager.getPage(data.pageIndex).then(function(page) {
  30903. return pdfManager.ensure(page, 'getAnnotationsData', []);
  30904. });
  30905. });
  30906. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  30907. pdfManager.getPage(data.pageIndex).then(function(page) {
  30908. var pageNum = data.pageIndex + 1;
  30909. var start = Date.now();
  30910. // Pre compile the pdf page and fetch the fonts/images.
  30911. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  30912. info('page=' + pageNum + ' - getOperatorList: time=' +
  30913. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  30914. }, function(e) {
  30915. var minimumStackMessage =
  30916. 'worker.js: while trying to getPage() and getOperatorList()';
  30917. var wrappedException;
  30918. // Turn the error into an obj that can be serialized
  30919. if (typeof e === 'string') {
  30920. wrappedException = {
  30921. message: e,
  30922. stack: minimumStackMessage
  30923. };
  30924. } else if (typeof e === 'object') {
  30925. wrappedException = {
  30926. message: e.message || e.toString(),
  30927. stack: e.stack || minimumStackMessage
  30928. };
  30929. } else {
  30930. wrappedException = {
  30931. message: 'Unknown exception type: ' + (typeof e),
  30932. stack: minimumStackMessage
  30933. };
  30934. }
  30935. handler.send('PageError', {
  30936. pageNum: pageNum,
  30937. error: wrappedException,
  30938. intent: data.intent
  30939. });
  30940. });
  30941. });
  30942. }, this);
  30943. handler.on('GetTextContent', function wphExtractText(data) {
  30944. return pdfManager.getPage(data.pageIndex).then(function(page) {
  30945. var pageNum = data.pageIndex + 1;
  30946. var start = Date.now();
  30947. return page.extractTextContent().then(function(textContent) {
  30948. info('text indexing: page=' + pageNum + ' - time=' +
  30949. (Date.now() - start) + 'ms');
  30950. return textContent;
  30951. });
  30952. });
  30953. });
  30954. handler.on('Cleanup', function wphCleanup(data) {
  30955. return pdfManager.cleanup();
  30956. });
  30957. handler.on('Terminate', function wphTerminate(data) {
  30958. pdfManager.terminate();
  30959. });
  30960. }
  30961. };
  30962. var consoleTimer = {};
  30963. var workerConsole = {
  30964. log: function log() {
  30965. var args = Array.prototype.slice.call(arguments);
  30966. globalScope.postMessage({
  30967. action: 'console_log',
  30968. data: args
  30969. });
  30970. },
  30971. error: function error() {
  30972. var args = Array.prototype.slice.call(arguments);
  30973. globalScope.postMessage({
  30974. action: 'console_error',
  30975. data: args
  30976. });
  30977. throw 'pdf.js execution error';
  30978. },
  30979. time: function time(name) {
  30980. consoleTimer[name] = Date.now();
  30981. },
  30982. timeEnd: function timeEnd(name) {
  30983. var time = consoleTimer[name];
  30984. if (!time) {
  30985. error('Unknown timer name ' + name);
  30986. }
  30987. this.log('Timer:', name, Date.now() - time);
  30988. }
  30989. };
  30990. // Worker thread?
  30991. if (typeof window === 'undefined') {
  30992. if (!('console' in globalScope)) {
  30993. globalScope.console = workerConsole;
  30994. }
  30995. // Listen for unsupported features so we can pass them on to the main thread.
  30996. PDFJS.UnsupportedManager.listen(function (msg) {
  30997. globalScope.postMessage({
  30998. action: '_unsupported_feature',
  30999. data: msg
  31000. });
  31001. });
  31002. var handler = new MessageHandler('worker_processor', this);
  31003. WorkerMessageHandler.setup(handler);
  31004. }
  31005. /* This class implements the QM Coder decoding as defined in
  31006. * JPEG 2000 Part I Final Committee Draft Version 1.0
  31007. * Annex C.3 Arithmetic decoding procedure
  31008. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  31009. *
  31010. * The arithmetic decoder is used in conjunction with context models to decode
  31011. * JPEG2000 and JBIG2 streams.
  31012. */
  31013. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  31014. // Table C-2
  31015. var QeTable = [
  31016. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  31017. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  31018. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  31019. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  31020. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  31021. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  31022. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  31023. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  31024. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  31025. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  31026. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  31027. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  31028. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  31029. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  31030. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  31031. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  31032. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  31033. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  31034. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  31035. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  31036. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  31037. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  31038. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  31039. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  31040. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  31041. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  31042. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  31043. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  31044. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  31045. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  31046. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  31047. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  31048. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  31049. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  31050. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  31051. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  31052. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  31053. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  31054. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  31055. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  31056. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  31057. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  31058. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  31059. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  31060. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  31061. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  31062. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  31063. ];
  31064. // C.3.5 Initialisation of the decoder (INITDEC)
  31065. function ArithmeticDecoder(data, start, end) {
  31066. this.data = data;
  31067. this.bp = start;
  31068. this.dataEnd = end;
  31069. this.chigh = data[start];
  31070. this.clow = 0;
  31071. this.byteIn();
  31072. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  31073. this.clow = (this.clow << 7) & 0xFFFF;
  31074. this.ct -= 7;
  31075. this.a = 0x8000;
  31076. }
  31077. ArithmeticDecoder.prototype = {
  31078. // C.3.4 Compressed data input (BYTEIN)
  31079. byteIn: function ArithmeticDecoder_byteIn() {
  31080. var data = this.data;
  31081. var bp = this.bp;
  31082. if (data[bp] === 0xFF) {
  31083. var b1 = data[bp + 1];
  31084. if (b1 > 0x8F) {
  31085. this.clow += 0xFF00;
  31086. this.ct = 8;
  31087. } else {
  31088. bp++;
  31089. this.clow += (data[bp] << 9);
  31090. this.ct = 7;
  31091. this.bp = bp;
  31092. }
  31093. } else {
  31094. bp++;
  31095. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  31096. this.ct = 8;
  31097. this.bp = bp;
  31098. }
  31099. if (this.clow > 0xFFFF) {
  31100. this.chigh += (this.clow >> 16);
  31101. this.clow &= 0xFFFF;
  31102. }
  31103. },
  31104. // C.3.2 Decoding a decision (DECODE)
  31105. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  31106. // contexts are packed into 1 byte:
  31107. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  31108. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  31109. var qeTableIcx = QeTable[cx_index];
  31110. var qeIcx = qeTableIcx.qe;
  31111. var d;
  31112. var a = this.a - qeIcx;
  31113. if (this.chigh < qeIcx) {
  31114. // exchangeLps
  31115. if (a < qeIcx) {
  31116. a = qeIcx;
  31117. d = cx_mps;
  31118. cx_index = qeTableIcx.nmps;
  31119. } else {
  31120. a = qeIcx;
  31121. d = 1 ^ cx_mps;
  31122. if (qeTableIcx.switchFlag === 1) {
  31123. cx_mps = d;
  31124. }
  31125. cx_index = qeTableIcx.nlps;
  31126. }
  31127. } else {
  31128. this.chigh -= qeIcx;
  31129. if ((a & 0x8000) !== 0) {
  31130. this.a = a;
  31131. return cx_mps;
  31132. }
  31133. // exchangeMps
  31134. if (a < qeIcx) {
  31135. d = 1 ^ cx_mps;
  31136. if (qeTableIcx.switchFlag === 1) {
  31137. cx_mps = d;
  31138. }
  31139. cx_index = qeTableIcx.nlps;
  31140. } else {
  31141. d = cx_mps;
  31142. cx_index = qeTableIcx.nmps;
  31143. }
  31144. }
  31145. // C.3.3 renormD;
  31146. do {
  31147. if (this.ct === 0) {
  31148. this.byteIn();
  31149. }
  31150. a <<= 1;
  31151. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  31152. this.clow = (this.clow << 1) & 0xFFFF;
  31153. this.ct--;
  31154. } while ((a & 0x8000) === 0);
  31155. this.a = a;
  31156. contexts[pos] = cx_index << 1 | cx_mps;
  31157. return d;
  31158. }
  31159. };
  31160. return ArithmeticDecoder;
  31161. })();
  31162. var JpegImage = (function jpegImage() {
  31163. var dctZigZag = new Uint8Array([
  31164. 0,
  31165. 1, 8,
  31166. 16, 9, 2,
  31167. 3, 10, 17, 24,
  31168. 32, 25, 18, 11, 4,
  31169. 5, 12, 19, 26, 33, 40,
  31170. 48, 41, 34, 27, 20, 13, 6,
  31171. 7, 14, 21, 28, 35, 42, 49, 56,
  31172. 57, 50, 43, 36, 29, 22, 15,
  31173. 23, 30, 37, 44, 51, 58,
  31174. 59, 52, 45, 38, 31,
  31175. 39, 46, 53, 60,
  31176. 61, 54, 47,
  31177. 55, 62,
  31178. 63
  31179. ]);
  31180. var dctCos1 = 4017; // cos(pi/16)
  31181. var dctSin1 = 799; // sin(pi/16)
  31182. var dctCos3 = 3406; // cos(3*pi/16)
  31183. var dctSin3 = 2276; // sin(3*pi/16)
  31184. var dctCos6 = 1567; // cos(6*pi/16)
  31185. var dctSin6 = 3784; // sin(6*pi/16)
  31186. var dctSqrt2 = 5793; // sqrt(2)
  31187. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  31188. function constructor() {
  31189. }
  31190. function buildHuffmanTable(codeLengths, values) {
  31191. var k = 0, code = [], i, j, length = 16;
  31192. while (length > 0 && !codeLengths[length - 1]) {
  31193. length--;
  31194. }
  31195. code.push({children: [], index: 0});
  31196. var p = code[0], q;
  31197. for (i = 0; i < length; i++) {
  31198. for (j = 0; j < codeLengths[i]; j++) {
  31199. p = code.pop();
  31200. p.children[p.index] = values[k];
  31201. while (p.index > 0) {
  31202. p = code.pop();
  31203. }
  31204. p.index++;
  31205. code.push(p);
  31206. while (code.length <= i) {
  31207. code.push(q = {children: [], index: 0});
  31208. p.children[p.index] = q.children;
  31209. p = q;
  31210. }
  31211. k++;
  31212. }
  31213. if (i + 1 < length) {
  31214. // p here points to last code
  31215. code.push(q = {children: [], index: 0});
  31216. p.children[p.index] = q.children;
  31217. p = q;
  31218. }
  31219. }
  31220. return code[0].children;
  31221. }
  31222. function getBlockBufferOffset(component, row, col) {
  31223. return 64 * ((component.blocksPerLine + 1) * row + col);
  31224. }
  31225. function decodeScan(data, offset, frame, components, resetInterval,
  31226. spectralStart, spectralEnd, successivePrev, successive) {
  31227. var precision = frame.precision;
  31228. var samplesPerLine = frame.samplesPerLine;
  31229. var scanLines = frame.scanLines;
  31230. var mcusPerLine = frame.mcusPerLine;
  31231. var progressive = frame.progressive;
  31232. var maxH = frame.maxH, maxV = frame.maxV;
  31233. var startOffset = offset, bitsData = 0, bitsCount = 0;
  31234. function readBit() {
  31235. if (bitsCount > 0) {
  31236. bitsCount--;
  31237. return (bitsData >> bitsCount) & 1;
  31238. }
  31239. bitsData = data[offset++];
  31240. if (bitsData === 0xFF) {
  31241. var nextByte = data[offset++];
  31242. if (nextByte) {
  31243. throw 'unexpected marker: ' +
  31244. ((bitsData << 8) | nextByte).toString(16);
  31245. }
  31246. // unstuff 0
  31247. }
  31248. bitsCount = 7;
  31249. return bitsData >>> 7;
  31250. }
  31251. function decodeHuffman(tree) {
  31252. var node = tree;
  31253. var bit;
  31254. while ((bit = readBit()) !== null) {
  31255. node = node[bit];
  31256. if (typeof node === 'number') {
  31257. return node;
  31258. }
  31259. if (typeof node !== 'object') {
  31260. throw 'invalid huffman sequence';
  31261. }
  31262. }
  31263. return null;
  31264. }
  31265. function receive(length) {
  31266. var n = 0;
  31267. while (length > 0) {
  31268. var bit = readBit();
  31269. if (bit === null) {
  31270. return;
  31271. }
  31272. n = (n << 1) | bit;
  31273. length--;
  31274. }
  31275. return n;
  31276. }
  31277. function receiveAndExtend(length) {
  31278. if (length === 1) {
  31279. return readBit() === 1 ? 1 : -1;
  31280. }
  31281. var n = receive(length);
  31282. if (n >= 1 << (length - 1)) {
  31283. return n;
  31284. }
  31285. return n + (-1 << length) + 1;
  31286. }
  31287. function decodeBaseline(component, offset) {
  31288. var t = decodeHuffman(component.huffmanTableDC);
  31289. var diff = t === 0 ? 0 : receiveAndExtend(t);
  31290. component.blockData[offset] = (component.pred += diff);
  31291. var k = 1;
  31292. while (k < 64) {
  31293. var rs = decodeHuffman(component.huffmanTableAC);
  31294. var s = rs & 15, r = rs >> 4;
  31295. if (s === 0) {
  31296. if (r < 15) {
  31297. break;
  31298. }
  31299. k += 16;
  31300. continue;
  31301. }
  31302. k += r;
  31303. var z = dctZigZag[k];
  31304. component.blockData[offset + z] = receiveAndExtend(s);
  31305. k++;
  31306. }
  31307. }
  31308. function decodeDCFirst(component, offset) {
  31309. var t = decodeHuffman(component.huffmanTableDC);
  31310. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  31311. component.blockData[offset] = (component.pred += diff);
  31312. }
  31313. function decodeDCSuccessive(component, offset) {
  31314. component.blockData[offset] |= readBit() << successive;
  31315. }
  31316. var eobrun = 0;
  31317. function decodeACFirst(component, offset) {
  31318. if (eobrun > 0) {
  31319. eobrun--;
  31320. return;
  31321. }
  31322. var k = spectralStart, e = spectralEnd;
  31323. while (k <= e) {
  31324. var rs = decodeHuffman(component.huffmanTableAC);
  31325. var s = rs & 15, r = rs >> 4;
  31326. if (s === 0) {
  31327. if (r < 15) {
  31328. eobrun = receive(r) + (1 << r) - 1;
  31329. break;
  31330. }
  31331. k += 16;
  31332. continue;
  31333. }
  31334. k += r;
  31335. var z = dctZigZag[k];
  31336. component.blockData[offset + z] =
  31337. receiveAndExtend(s) * (1 << successive);
  31338. k++;
  31339. }
  31340. }
  31341. var successiveACState = 0, successiveACNextValue;
  31342. function decodeACSuccessive(component, offset) {
  31343. var k = spectralStart;
  31344. var e = spectralEnd;
  31345. var r = 0;
  31346. var s;
  31347. var rs;
  31348. while (k <= e) {
  31349. var z = dctZigZag[k];
  31350. switch (successiveACState) {
  31351. case 0: // initial state
  31352. rs = decodeHuffman(component.huffmanTableAC);
  31353. s = rs & 15;
  31354. r = rs >> 4;
  31355. if (s === 0) {
  31356. if (r < 15) {
  31357. eobrun = receive(r) + (1 << r);
  31358. successiveACState = 4;
  31359. } else {
  31360. r = 16;
  31361. successiveACState = 1;
  31362. }
  31363. } else {
  31364. if (s !== 1) {
  31365. throw 'invalid ACn encoding';
  31366. }
  31367. successiveACNextValue = receiveAndExtend(s);
  31368. successiveACState = r ? 2 : 3;
  31369. }
  31370. continue;
  31371. case 1: // skipping r zero items
  31372. case 2:
  31373. if (component.blockData[offset + z]) {
  31374. component.blockData[offset + z] += (readBit() << successive);
  31375. } else {
  31376. r--;
  31377. if (r === 0) {
  31378. successiveACState = successiveACState === 2 ? 3 : 0;
  31379. }
  31380. }
  31381. break;
  31382. case 3: // set value for a zero item
  31383. if (component.blockData[offset + z]) {
  31384. component.blockData[offset + z] += (readBit() << successive);
  31385. } else {
  31386. component.blockData[offset + z] =
  31387. successiveACNextValue << successive;
  31388. successiveACState = 0;
  31389. }
  31390. break;
  31391. case 4: // eob
  31392. if (component.blockData[offset + z]) {
  31393. component.blockData[offset + z] += (readBit() << successive);
  31394. }
  31395. break;
  31396. }
  31397. k++;
  31398. }
  31399. if (successiveACState === 4) {
  31400. eobrun--;
  31401. if (eobrun === 0) {
  31402. successiveACState = 0;
  31403. }
  31404. }
  31405. }
  31406. function decodeMcu(component, decode, mcu, row, col) {
  31407. var mcuRow = (mcu / mcusPerLine) | 0;
  31408. var mcuCol = mcu % mcusPerLine;
  31409. var blockRow = mcuRow * component.v + row;
  31410. var blockCol = mcuCol * component.h + col;
  31411. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31412. decode(component, offset);
  31413. }
  31414. function decodeBlock(component, decode, mcu) {
  31415. var blockRow = (mcu / component.blocksPerLine) | 0;
  31416. var blockCol = mcu % component.blocksPerLine;
  31417. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31418. decode(component, offset);
  31419. }
  31420. var componentsLength = components.length;
  31421. var component, i, j, k, n;
  31422. var decodeFn;
  31423. if (progressive) {
  31424. if (spectralStart === 0) {
  31425. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  31426. } else {
  31427. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  31428. }
  31429. } else {
  31430. decodeFn = decodeBaseline;
  31431. }
  31432. var mcu = 0, marker;
  31433. var mcuExpected;
  31434. if (componentsLength === 1) {
  31435. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  31436. } else {
  31437. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  31438. }
  31439. if (!resetInterval) {
  31440. resetInterval = mcuExpected;
  31441. }
  31442. var h, v;
  31443. while (mcu < mcuExpected) {
  31444. // reset interval stuff
  31445. for (i = 0; i < componentsLength; i++) {
  31446. components[i].pred = 0;
  31447. }
  31448. eobrun = 0;
  31449. if (componentsLength === 1) {
  31450. component = components[0];
  31451. for (n = 0; n < resetInterval; n++) {
  31452. decodeBlock(component, decodeFn, mcu);
  31453. mcu++;
  31454. }
  31455. } else {
  31456. for (n = 0; n < resetInterval; n++) {
  31457. for (i = 0; i < componentsLength; i++) {
  31458. component = components[i];
  31459. h = component.h;
  31460. v = component.v;
  31461. for (j = 0; j < v; j++) {
  31462. for (k = 0; k < h; k++) {
  31463. decodeMcu(component, decodeFn, mcu, j, k);
  31464. }
  31465. }
  31466. }
  31467. mcu++;
  31468. }
  31469. }
  31470. // find marker
  31471. bitsCount = 0;
  31472. marker = (data[offset] << 8) | data[offset + 1];
  31473. if (marker <= 0xFF00) {
  31474. throw 'marker was not found';
  31475. }
  31476. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  31477. offset += 2;
  31478. } else {
  31479. break;
  31480. }
  31481. }
  31482. return offset - startOffset;
  31483. }
  31484. // A port of poppler's IDCT method which in turn is taken from:
  31485. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  31486. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  31487. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  31488. // 988-991.
  31489. function quantizeAndInverse(component, blockBufferOffset, p) {
  31490. var qt = component.quantizationTable, blockData = component.blockData;
  31491. var v0, v1, v2, v3, v4, v5, v6, v7;
  31492. var p0, p1, p2, p3, p4, p5, p6, p7;
  31493. var t;
  31494. // inverse DCT on rows
  31495. for (var row = 0; row < 64; row += 8) {
  31496. // gather block data
  31497. p0 = blockData[blockBufferOffset + row];
  31498. p1 = blockData[blockBufferOffset + row + 1];
  31499. p2 = blockData[blockBufferOffset + row + 2];
  31500. p3 = blockData[blockBufferOffset + row + 3];
  31501. p4 = blockData[blockBufferOffset + row + 4];
  31502. p5 = blockData[blockBufferOffset + row + 5];
  31503. p6 = blockData[blockBufferOffset + row + 6];
  31504. p7 = blockData[blockBufferOffset + row + 7];
  31505. // dequant p0
  31506. p0 *= qt[row];
  31507. // check for all-zero AC coefficients
  31508. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  31509. t = (dctSqrt2 * p0 + 512) >> 10;
  31510. p[row] = t;
  31511. p[row + 1] = t;
  31512. p[row + 2] = t;
  31513. p[row + 3] = t;
  31514. p[row + 4] = t;
  31515. p[row + 5] = t;
  31516. p[row + 6] = t;
  31517. p[row + 7] = t;
  31518. continue;
  31519. }
  31520. // dequant p1 ... p7
  31521. p1 *= qt[row + 1];
  31522. p2 *= qt[row + 2];
  31523. p3 *= qt[row + 3];
  31524. p4 *= qt[row + 4];
  31525. p5 *= qt[row + 5];
  31526. p6 *= qt[row + 6];
  31527. p7 *= qt[row + 7];
  31528. // stage 4
  31529. v0 = (dctSqrt2 * p0 + 128) >> 8;
  31530. v1 = (dctSqrt2 * p4 + 128) >> 8;
  31531. v2 = p2;
  31532. v3 = p6;
  31533. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  31534. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  31535. v5 = p3 << 4;
  31536. v6 = p5 << 4;
  31537. // stage 3
  31538. v0 = (v0 + v1 + 1) >> 1;
  31539. v1 = v0 - v1;
  31540. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  31541. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  31542. v3 = t;
  31543. v4 = (v4 + v6 + 1) >> 1;
  31544. v6 = v4 - v6;
  31545. v7 = (v7 + v5 + 1) >> 1;
  31546. v5 = v7 - v5;
  31547. // stage 2
  31548. v0 = (v0 + v3 + 1) >> 1;
  31549. v3 = v0 - v3;
  31550. v1 = (v1 + v2 + 1) >> 1;
  31551. v2 = v1 - v2;
  31552. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  31553. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  31554. v7 = t;
  31555. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  31556. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  31557. v6 = t;
  31558. // stage 1
  31559. p[row] = v0 + v7;
  31560. p[row + 7] = v0 - v7;
  31561. p[row + 1] = v1 + v6;
  31562. p[row + 6] = v1 - v6;
  31563. p[row + 2] = v2 + v5;
  31564. p[row + 5] = v2 - v5;
  31565. p[row + 3] = v3 + v4;
  31566. p[row + 4] = v3 - v4;
  31567. }
  31568. // inverse DCT on columns
  31569. for (var col = 0; col < 8; ++col) {
  31570. p0 = p[col];
  31571. p1 = p[col + 8];
  31572. p2 = p[col + 16];
  31573. p3 = p[col + 24];
  31574. p4 = p[col + 32];
  31575. p5 = p[col + 40];
  31576. p6 = p[col + 48];
  31577. p7 = p[col + 56];
  31578. // check for all-zero AC coefficients
  31579. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  31580. t = (dctSqrt2 * p0 + 8192) >> 14;
  31581. // convert to 8 bit
  31582. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  31583. blockData[blockBufferOffset + col] = t;
  31584. blockData[blockBufferOffset + col + 8] = t;
  31585. blockData[blockBufferOffset + col + 16] = t;
  31586. blockData[blockBufferOffset + col + 24] = t;
  31587. blockData[blockBufferOffset + col + 32] = t;
  31588. blockData[blockBufferOffset + col + 40] = t;
  31589. blockData[blockBufferOffset + col + 48] = t;
  31590. blockData[blockBufferOffset + col + 56] = t;
  31591. continue;
  31592. }
  31593. // stage 4
  31594. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  31595. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  31596. v2 = p2;
  31597. v3 = p6;
  31598. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  31599. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  31600. v5 = p3;
  31601. v6 = p5;
  31602. // stage 3
  31603. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  31604. // converting to UInt8 range later.
  31605. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  31606. v1 = v0 - v1;
  31607. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  31608. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  31609. v3 = t;
  31610. v4 = (v4 + v6 + 1) >> 1;
  31611. v6 = v4 - v6;
  31612. v7 = (v7 + v5 + 1) >> 1;
  31613. v5 = v7 - v5;
  31614. // stage 2
  31615. v0 = (v0 + v3 + 1) >> 1;
  31616. v3 = v0 - v3;
  31617. v1 = (v1 + v2 + 1) >> 1;
  31618. v2 = v1 - v2;
  31619. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  31620. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  31621. v7 = t;
  31622. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  31623. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  31624. v6 = t;
  31625. // stage 1
  31626. p0 = v0 + v7;
  31627. p7 = v0 - v7;
  31628. p1 = v1 + v6;
  31629. p6 = v1 - v6;
  31630. p2 = v2 + v5;
  31631. p5 = v2 - v5;
  31632. p3 = v3 + v4;
  31633. p4 = v3 - v4;
  31634. // convert to 8-bit integers
  31635. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  31636. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  31637. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  31638. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  31639. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  31640. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  31641. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  31642. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  31643. // store block data
  31644. blockData[blockBufferOffset + col] = p0;
  31645. blockData[blockBufferOffset + col + 8] = p1;
  31646. blockData[blockBufferOffset + col + 16] = p2;
  31647. blockData[blockBufferOffset + col + 24] = p3;
  31648. blockData[blockBufferOffset + col + 32] = p4;
  31649. blockData[blockBufferOffset + col + 40] = p5;
  31650. blockData[blockBufferOffset + col + 48] = p6;
  31651. blockData[blockBufferOffset + col + 56] = p7;
  31652. }
  31653. }
  31654. function buildComponentData(frame, component) {
  31655. var blocksPerLine = component.blocksPerLine;
  31656. var blocksPerColumn = component.blocksPerColumn;
  31657. var computationBuffer = new Int16Array(64);
  31658. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  31659. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  31660. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31661. quantizeAndInverse(component, offset, computationBuffer);
  31662. }
  31663. }
  31664. return component.blockData;
  31665. }
  31666. function clamp0to255(a) {
  31667. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  31668. }
  31669. constructor.prototype = {
  31670. parse: function parse(data) {
  31671. function readUint16() {
  31672. var value = (data[offset] << 8) | data[offset + 1];
  31673. offset += 2;
  31674. return value;
  31675. }
  31676. function readDataBlock() {
  31677. var length = readUint16();
  31678. var array = data.subarray(offset, offset + length - 2);
  31679. offset += array.length;
  31680. return array;
  31681. }
  31682. function prepareComponents(frame) {
  31683. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  31684. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  31685. for (var i = 0; i < frame.components.length; i++) {
  31686. component = frame.components[i];
  31687. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  31688. component.h / frame.maxH);
  31689. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  31690. component.v / frame.maxV);
  31691. var blocksPerLineForMcu = mcusPerLine * component.h;
  31692. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  31693. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  31694. (blocksPerLineForMcu + 1);
  31695. component.blockData = new Int16Array(blocksBufferSize);
  31696. component.blocksPerLine = blocksPerLine;
  31697. component.blocksPerColumn = blocksPerColumn;
  31698. }
  31699. frame.mcusPerLine = mcusPerLine;
  31700. frame.mcusPerColumn = mcusPerColumn;
  31701. }
  31702. var offset = 0, length = data.length;
  31703. var jfif = null;
  31704. var adobe = null;
  31705. var pixels = null;
  31706. var frame, resetInterval;
  31707. var quantizationTables = [];
  31708. var huffmanTablesAC = [], huffmanTablesDC = [];
  31709. var fileMarker = readUint16();
  31710. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  31711. throw 'SOI not found';
  31712. }
  31713. fileMarker = readUint16();
  31714. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  31715. var i, j, l;
  31716. switch(fileMarker) {
  31717. case 0xFFE0: // APP0 (Application Specific)
  31718. case 0xFFE1: // APP1
  31719. case 0xFFE2: // APP2
  31720. case 0xFFE3: // APP3
  31721. case 0xFFE4: // APP4
  31722. case 0xFFE5: // APP5
  31723. case 0xFFE6: // APP6
  31724. case 0xFFE7: // APP7
  31725. case 0xFFE8: // APP8
  31726. case 0xFFE9: // APP9
  31727. case 0xFFEA: // APP10
  31728. case 0xFFEB: // APP11
  31729. case 0xFFEC: // APP12
  31730. case 0xFFED: // APP13
  31731. case 0xFFEE: // APP14
  31732. case 0xFFEF: // APP15
  31733. case 0xFFFE: // COM (Comment)
  31734. var appData = readDataBlock();
  31735. if (fileMarker === 0xFFE0) {
  31736. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  31737. appData[2] === 0x49 && appData[3] === 0x46 &&
  31738. appData[4] === 0) { // 'JFIF\x00'
  31739. jfif = {
  31740. version: { major: appData[5], minor: appData[6] },
  31741. densityUnits: appData[7],
  31742. xDensity: (appData[8] << 8) | appData[9],
  31743. yDensity: (appData[10] << 8) | appData[11],
  31744. thumbWidth: appData[12],
  31745. thumbHeight: appData[13],
  31746. thumbData: appData.subarray(14, 14 +
  31747. 3 * appData[12] * appData[13])
  31748. };
  31749. }
  31750. }
  31751. // TODO APP1 - Exif
  31752. if (fileMarker === 0xFFEE) {
  31753. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  31754. appData[2] === 0x6F && appData[3] === 0x62 &&
  31755. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  31756. adobe = {
  31757. version: appData[6],
  31758. flags0: (appData[7] << 8) | appData[8],
  31759. flags1: (appData[9] << 8) | appData[10],
  31760. transformCode: appData[11]
  31761. };
  31762. }
  31763. }
  31764. break;
  31765. case 0xFFDB: // DQT (Define Quantization Tables)
  31766. var quantizationTablesLength = readUint16();
  31767. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  31768. var z;
  31769. while (offset < quantizationTablesEnd) {
  31770. var quantizationTableSpec = data[offset++];
  31771. var tableData = new Uint16Array(64);
  31772. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  31773. for (j = 0; j < 64; j++) {
  31774. z = dctZigZag[j];
  31775. tableData[z] = data[offset++];
  31776. }
  31777. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  31778. for (j = 0; j < 64; j++) {
  31779. z = dctZigZag[j];
  31780. tableData[z] = readUint16();
  31781. }
  31782. } else {
  31783. throw 'DQT: invalid table spec';
  31784. }
  31785. quantizationTables[quantizationTableSpec & 15] = tableData;
  31786. }
  31787. break;
  31788. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  31789. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  31790. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  31791. if (frame) {
  31792. throw 'Only single frame JPEGs supported';
  31793. }
  31794. readUint16(); // skip data length
  31795. frame = {};
  31796. frame.extended = (fileMarker === 0xFFC1);
  31797. frame.progressive = (fileMarker === 0xFFC2);
  31798. frame.precision = data[offset++];
  31799. frame.scanLines = readUint16();
  31800. frame.samplesPerLine = readUint16();
  31801. frame.components = [];
  31802. frame.componentIds = {};
  31803. var componentsCount = data[offset++], componentId;
  31804. var maxH = 0, maxV = 0;
  31805. for (i = 0; i < componentsCount; i++) {
  31806. componentId = data[offset];
  31807. var h = data[offset + 1] >> 4;
  31808. var v = data[offset + 1] & 15;
  31809. if (maxH < h) {
  31810. maxH = h;
  31811. }
  31812. if (maxV < v) {
  31813. maxV = v;
  31814. }
  31815. var qId = data[offset + 2];
  31816. l = frame.components.push({
  31817. h: h,
  31818. v: v,
  31819. quantizationTable: quantizationTables[qId]
  31820. });
  31821. frame.componentIds[componentId] = l - 1;
  31822. offset += 3;
  31823. }
  31824. frame.maxH = maxH;
  31825. frame.maxV = maxV;
  31826. prepareComponents(frame);
  31827. break;
  31828. case 0xFFC4: // DHT (Define Huffman Tables)
  31829. var huffmanLength = readUint16();
  31830. for (i = 2; i < huffmanLength;) {
  31831. var huffmanTableSpec = data[offset++];
  31832. var codeLengths = new Uint8Array(16);
  31833. var codeLengthSum = 0;
  31834. for (j = 0; j < 16; j++, offset++) {
  31835. codeLengthSum += (codeLengths[j] = data[offset]);
  31836. }
  31837. var huffmanValues = new Uint8Array(codeLengthSum);
  31838. for (j = 0; j < codeLengthSum; j++, offset++) {
  31839. huffmanValues[j] = data[offset];
  31840. }
  31841. i += 17 + codeLengthSum;
  31842. ((huffmanTableSpec >> 4) === 0 ?
  31843. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  31844. buildHuffmanTable(codeLengths, huffmanValues);
  31845. }
  31846. break;
  31847. case 0xFFDD: // DRI (Define Restart Interval)
  31848. readUint16(); // skip data length
  31849. resetInterval = readUint16();
  31850. break;
  31851. case 0xFFDA: // SOS (Start of Scan)
  31852. var scanLength = readUint16();
  31853. var selectorsCount = data[offset++];
  31854. var components = [], component;
  31855. for (i = 0; i < selectorsCount; i++) {
  31856. var componentIndex = frame.componentIds[data[offset++]];
  31857. component = frame.components[componentIndex];
  31858. var tableSpec = data[offset++];
  31859. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  31860. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  31861. components.push(component);
  31862. }
  31863. var spectralStart = data[offset++];
  31864. var spectralEnd = data[offset++];
  31865. var successiveApproximation = data[offset++];
  31866. var processed = decodeScan(data, offset,
  31867. frame, components, resetInterval,
  31868. spectralStart, spectralEnd,
  31869. successiveApproximation >> 4, successiveApproximation & 15);
  31870. offset += processed;
  31871. break;
  31872. default:
  31873. if (data[offset - 3] === 0xFF &&
  31874. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  31875. // could be incorrect encoding -- last 0xFF byte of the previous
  31876. // block was eaten by the encoder
  31877. offset -= 3;
  31878. break;
  31879. }
  31880. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  31881. }
  31882. fileMarker = readUint16();
  31883. }
  31884. this.width = frame.samplesPerLine;
  31885. this.height = frame.scanLines;
  31886. this.jfif = jfif;
  31887. this.adobe = adobe;
  31888. this.components = [];
  31889. for (i = 0; i < frame.components.length; i++) {
  31890. component = frame.components[i];
  31891. this.components.push({
  31892. output: buildComponentData(frame, component),
  31893. scaleX: component.h / frame.maxH,
  31894. scaleY: component.v / frame.maxV,
  31895. blocksPerLine: component.blocksPerLine,
  31896. blocksPerColumn: component.blocksPerColumn
  31897. });
  31898. }
  31899. this.numComponents = this.components.length;
  31900. },
  31901. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  31902. var scaleX = this.width / width, scaleY = this.height / height;
  31903. var component, componentScaleX, componentScaleY, blocksPerScanline;
  31904. var x, y, i, j, k;
  31905. var index;
  31906. var offset = 0;
  31907. var output;
  31908. var numComponents = this.components.length;
  31909. var dataLength = width * height * numComponents;
  31910. var data = new Uint8Array(dataLength);
  31911. var xScaleBlockOffset = new Uint32Array(width);
  31912. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  31913. for (i = 0; i < numComponents; i++) {
  31914. component = this.components[i];
  31915. componentScaleX = component.scaleX * scaleX;
  31916. componentScaleY = component.scaleY * scaleY;
  31917. offset = i;
  31918. output = component.output;
  31919. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  31920. // precalculate the xScaleBlockOffset
  31921. for (x = 0; x < width; x++) {
  31922. j = 0 | (x * componentScaleX);
  31923. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  31924. }
  31925. // linearize the blocks of the component
  31926. for (y = 0; y < height; y++) {
  31927. j = 0 | (y * componentScaleY);
  31928. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  31929. for (x = 0; x < width; x++) {
  31930. data[offset] = output[index + xScaleBlockOffset[x]];
  31931. offset += numComponents;
  31932. }
  31933. }
  31934. }
  31935. // decodeTransform will contains pairs of multiplier (-256..256) and
  31936. // additive
  31937. var transform = this.decodeTransform;
  31938. if (transform) {
  31939. for (i = 0; i < dataLength;) {
  31940. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  31941. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  31942. }
  31943. }
  31944. }
  31945. return data;
  31946. },
  31947. _isColorConversionNeeded: function isColorConversionNeeded() {
  31948. if (this.adobe && this.adobe.transformCode) {
  31949. // The adobe transform marker overrides any previous setting
  31950. return true;
  31951. } else if (this.numComponents === 3) {
  31952. return true;
  31953. } else {
  31954. return false;
  31955. }
  31956. },
  31957. _convertYccToRgb: function convertYccToRgb(data) {
  31958. var Y, Cb, Cr;
  31959. for (var i = 0, length = data.length; i < length; i += 3) {
  31960. Y = data[i ];
  31961. Cb = data[i + 1];
  31962. Cr = data[i + 2];
  31963. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  31964. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  31965. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  31966. }
  31967. return data;
  31968. },
  31969. _convertYcckToRgb: function convertYcckToRgb(data) {
  31970. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  31971. var offset = 0;
  31972. for (var i = 0, length = data.length; i < length; i += 4) {
  31973. Y = data[i];
  31974. Cb = data[i + 1];
  31975. Cr = data[i + 2];
  31976. k = data[i + 3];
  31977. CbCb = Cb * Cb;
  31978. CbCr = Cb * Cr;
  31979. CbY = Cb * Y;
  31980. Cbk = Cb * k;
  31981. CrCr = Cr * Cr;
  31982. Crk = Cr * k;
  31983. CrY = Cr * Y;
  31984. YY = Y * Y;
  31985. Yk = Y * k;
  31986. kk = k * k;
  31987. var r = - 122.67195406894 -
  31988. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  31989. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  31990. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  31991. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  31992. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  31993. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  31994. 0.000336197177618394 * kk + 0.484791561490776 * k;
  31995. var g = 107.268039397724 +
  31996. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  31997. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  31998. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  31999. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  32000. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  32001. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  32002. 0.000318913117588328 * kk - 0.213742400323665 * k;
  32003. var b = - 20.810012546947 -
  32004. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  32005. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  32006. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  32007. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  32008. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  32009. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  32010. 0.000343531996510555 * kk + 0.24165260232407 * k;
  32011. data[offset++] = clamp0to255(r);
  32012. data[offset++] = clamp0to255(g);
  32013. data[offset++] = clamp0to255(b);
  32014. }
  32015. return data;
  32016. },
  32017. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  32018. var Y, Cb, Cr;
  32019. for (var i = 0, length = data.length; i < length; i += 4) {
  32020. Y = data[i];
  32021. Cb = data[i + 1];
  32022. Cr = data[i + 2];
  32023. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  32024. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  32025. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  32026. // K in data[i + 3] is unchanged
  32027. }
  32028. return data;
  32029. },
  32030. _convertCmykToRgb: function convertCmykToRgb(data) {
  32031. var c, m, y, k;
  32032. var offset = 0;
  32033. var min = -255 * 255 * 255;
  32034. var scale = 1 / 255 / 255;
  32035. for (var i = 0, length = data.length; i < length; i += 4) {
  32036. c = data[i];
  32037. m = data[i + 1];
  32038. y = data[i + 2];
  32039. k = data[i + 3];
  32040. var r =
  32041. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32042. 18.82290502165302 * y + 212.25662451639585 * k -
  32043. 72734.4411664936) +
  32044. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  32045. 17.873870861415444 * k - 1401.7366389350734) +
  32046. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32047. 4465.541406466231) -
  32048. k * (21.86122147463605 * k + 48317.86113160301);
  32049. var g =
  32050. c * (8.841041422036149 * c + 60.118027045597366 * m +
  32051. 6.871425592049007 * y + 31.159100130055922 * k -
  32052. 20220.756542821975) +
  32053. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32054. 131.35250912493976 * k - 48691.05921601825) +
  32055. y * (4.444339102852739 * y + 9.8632861493405 * k -
  32056. 6341.191035517494) -
  32057. k * (20.737325471181034 * k + 47890.15695978492);
  32058. var b =
  32059. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32060. 30.89978309703729 * y - 0.23883238689178934 * k -
  32061. 3616.812083916688) +
  32062. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32063. 50.606957656360734 * k - 28620.90484698408) +
  32064. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  32065. 49363.43385999684) -
  32066. k * (22.33816807309886 * k + 45932.16563550634);
  32067. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  32068. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  32069. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  32070. }
  32071. return data;
  32072. },
  32073. getData: function getData(width, height, forceRGBoutput) {
  32074. if (this.numComponents > 4) {
  32075. throw 'Unsupported color mode';
  32076. }
  32077. // type of data: Uint8Array(width * height * numComponents)
  32078. var data = this._getLinearizedBlockData(width, height);
  32079. if (this.numComponents === 3) {
  32080. return this._convertYccToRgb(data);
  32081. } else if (this.numComponents === 4) {
  32082. if (this._isColorConversionNeeded()) {
  32083. if (forceRGBoutput) {
  32084. return this._convertYcckToRgb(data);
  32085. } else {
  32086. return this._convertYcckToCmyk(data);
  32087. }
  32088. } else if (forceRGBoutput) {
  32089. return this._convertCmykToRgb(data);
  32090. }
  32091. }
  32092. return data;
  32093. }
  32094. };
  32095. return constructor;
  32096. })();
  32097. var JpxImage = (function JpxImageClosure() {
  32098. // Table E.1
  32099. var SubbandsGainLog2 = {
  32100. 'LL': 0,
  32101. 'LH': 1,
  32102. 'HL': 1,
  32103. 'HH': 2
  32104. };
  32105. function JpxImage() {
  32106. this.failOnCorruptedImage = false;
  32107. }
  32108. JpxImage.prototype = {
  32109. parse: function JpxImage_parse(data) {
  32110. var head = readUint16(data, 0);
  32111. // No box header, immediate start of codestream (SOC)
  32112. if (head === 0xFF4F) {
  32113. this.parseCodestream(data, 0, data.length);
  32114. return;
  32115. }
  32116. var position = 0, length = data.length;
  32117. while (position < length) {
  32118. var headerSize = 8;
  32119. var lbox = readUint32(data, position);
  32120. var tbox = readUint32(data, position + 4);
  32121. position += headerSize;
  32122. if (lbox === 1) {
  32123. // XLBox: read UInt64 according to spec.
  32124. // JavaScript's int precision of 53 bit should be sufficient here.
  32125. lbox = readUint32(data, position) * 4294967296 +
  32126. readUint32(data, position + 4);
  32127. position += 8;
  32128. headerSize += 8;
  32129. }
  32130. if (lbox === 0) {
  32131. lbox = length - position + headerSize;
  32132. }
  32133. if (lbox < headerSize) {
  32134. throw new Error('JPX Error: Invalid box field size');
  32135. }
  32136. var dataLength = lbox - headerSize;
  32137. var jumpDataLength = true;
  32138. switch (tbox) {
  32139. case 0x6A501A1A: // 'jP\032\032'
  32140. // TODO
  32141. break;
  32142. case 0x6A703268: // 'jp2h'
  32143. jumpDataLength = false; // parsing child boxes
  32144. break;
  32145. case 0x636F6C72: // 'colr'
  32146. // TODO
  32147. break;
  32148. case 0x6A703263: // 'jp2c'
  32149. this.parseCodestream(data, position, position + dataLength);
  32150. break;
  32151. }
  32152. if (jumpDataLength) {
  32153. position += dataLength;
  32154. }
  32155. }
  32156. },
  32157. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  32158. var newByte = stream.getByte();
  32159. while (newByte >= 0) {
  32160. var oldByte = newByte;
  32161. newByte = stream.getByte();
  32162. var code = (oldByte << 8) | newByte;
  32163. // Image and tile size (SIZ)
  32164. if (code === 0xFF51) {
  32165. stream.skip(4);
  32166. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  32167. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  32168. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  32169. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  32170. stream.skip(16);
  32171. var Csiz = stream.getUint16(); // Byte 36
  32172. this.width = Xsiz - XOsiz;
  32173. this.height = Ysiz - YOsiz;
  32174. this.componentsCount = Csiz;
  32175. // Results are always returned as Uint8Arrays
  32176. this.bitsPerComponent = 8;
  32177. return;
  32178. }
  32179. }
  32180. throw new Error('JPX Error: No size marker found in JPX stream');
  32181. },
  32182. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  32183. var context = {};
  32184. try {
  32185. var doNotRecover = false;
  32186. var position = start;
  32187. while (position + 1 < end) {
  32188. var code = readUint16(data, position);
  32189. position += 2;
  32190. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  32191. switch (code) {
  32192. case 0xFF4F: // Start of codestream (SOC)
  32193. context.mainHeader = true;
  32194. break;
  32195. case 0xFFD9: // End of codestream (EOC)
  32196. break;
  32197. case 0xFF51: // Image and tile size (SIZ)
  32198. length = readUint16(data, position);
  32199. var siz = {};
  32200. siz.Xsiz = readUint32(data, position + 4);
  32201. siz.Ysiz = readUint32(data, position + 8);
  32202. siz.XOsiz = readUint32(data, position + 12);
  32203. siz.YOsiz = readUint32(data, position + 16);
  32204. siz.XTsiz = readUint32(data, position + 20);
  32205. siz.YTsiz = readUint32(data, position + 24);
  32206. siz.XTOsiz = readUint32(data, position + 28);
  32207. siz.YTOsiz = readUint32(data, position + 32);
  32208. var componentsCount = readUint16(data, position + 36);
  32209. siz.Csiz = componentsCount;
  32210. var components = [];
  32211. j = position + 38;
  32212. for (var i = 0; i < componentsCount; i++) {
  32213. var component = {
  32214. precision: (data[j] & 0x7F) + 1,
  32215. isSigned: !!(data[j] & 0x80),
  32216. XRsiz: data[j + 1],
  32217. YRsiz: data[j + 1]
  32218. };
  32219. calculateComponentDimensions(component, siz);
  32220. components.push(component);
  32221. }
  32222. context.SIZ = siz;
  32223. context.components = components;
  32224. calculateTileGrids(context, components);
  32225. context.QCC = [];
  32226. context.COC = [];
  32227. break;
  32228. case 0xFF55: // Tile-part lengths, main header (TLM)
  32229. var Ltlm = readUint16(data, position); // Marker segment length
  32230. // Skip tile length markers
  32231. position += Ltlm;
  32232. break;
  32233. case 0xFF5C: // Quantization default (QCD)
  32234. length = readUint16(data, position);
  32235. var qcd = {};
  32236. j = position + 2;
  32237. sqcd = data[j++];
  32238. switch (sqcd & 0x1F) {
  32239. case 0:
  32240. spqcdSize = 8;
  32241. scalarExpounded = true;
  32242. break;
  32243. case 1:
  32244. spqcdSize = 16;
  32245. scalarExpounded = false;
  32246. break;
  32247. case 2:
  32248. spqcdSize = 16;
  32249. scalarExpounded = true;
  32250. break;
  32251. default:
  32252. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32253. }
  32254. qcd.noQuantization = (spqcdSize === 8);
  32255. qcd.scalarExpounded = scalarExpounded;
  32256. qcd.guardBits = sqcd >> 5;
  32257. spqcds = [];
  32258. while (j < length + position) {
  32259. var spqcd = {};
  32260. if (spqcdSize === 8) {
  32261. spqcd.epsilon = data[j++] >> 3;
  32262. spqcd.mu = 0;
  32263. } else {
  32264. spqcd.epsilon = data[j] >> 3;
  32265. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32266. j += 2;
  32267. }
  32268. spqcds.push(spqcd);
  32269. }
  32270. qcd.SPqcds = spqcds;
  32271. if (context.mainHeader) {
  32272. context.QCD = qcd;
  32273. } else {
  32274. context.currentTile.QCD = qcd;
  32275. context.currentTile.QCC = [];
  32276. }
  32277. break;
  32278. case 0xFF5D: // Quantization component (QCC)
  32279. length = readUint16(data, position);
  32280. var qcc = {};
  32281. j = position + 2;
  32282. var cqcc;
  32283. if (context.SIZ.Csiz < 257) {
  32284. cqcc = data[j++];
  32285. } else {
  32286. cqcc = readUint16(data, j);
  32287. j += 2;
  32288. }
  32289. sqcd = data[j++];
  32290. switch (sqcd & 0x1F) {
  32291. case 0:
  32292. spqcdSize = 8;
  32293. scalarExpounded = true;
  32294. break;
  32295. case 1:
  32296. spqcdSize = 16;
  32297. scalarExpounded = false;
  32298. break;
  32299. case 2:
  32300. spqcdSize = 16;
  32301. scalarExpounded = true;
  32302. break;
  32303. default:
  32304. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32305. }
  32306. qcc.noQuantization = (spqcdSize === 8);
  32307. qcc.scalarExpounded = scalarExpounded;
  32308. qcc.guardBits = sqcd >> 5;
  32309. spqcds = [];
  32310. while (j < (length + position)) {
  32311. spqcd = {};
  32312. if (spqcdSize === 8) {
  32313. spqcd.epsilon = data[j++] >> 3;
  32314. spqcd.mu = 0;
  32315. } else {
  32316. spqcd.epsilon = data[j] >> 3;
  32317. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32318. j += 2;
  32319. }
  32320. spqcds.push(spqcd);
  32321. }
  32322. qcc.SPqcds = spqcds;
  32323. if (context.mainHeader) {
  32324. context.QCC[cqcc] = qcc;
  32325. } else {
  32326. context.currentTile.QCC[cqcc] = qcc;
  32327. }
  32328. break;
  32329. case 0xFF52: // Coding style default (COD)
  32330. length = readUint16(data, position);
  32331. var cod = {};
  32332. j = position + 2;
  32333. var scod = data[j++];
  32334. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  32335. cod.sopMarkerUsed = !!(scod & 2);
  32336. cod.ephMarkerUsed = !!(scod & 4);
  32337. cod.progressionOrder = data[j++];
  32338. cod.layersCount = readUint16(data, j);
  32339. j += 2;
  32340. cod.multipleComponentTransform = data[j++];
  32341. cod.decompositionLevelsCount = data[j++];
  32342. cod.xcb = (data[j++] & 0xF) + 2;
  32343. cod.ycb = (data[j++] & 0xF) + 2;
  32344. var blockStyle = data[j++];
  32345. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  32346. cod.resetContextProbabilities = !!(blockStyle & 2);
  32347. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  32348. cod.verticalyStripe = !!(blockStyle & 8);
  32349. cod.predictableTermination = !!(blockStyle & 16);
  32350. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  32351. cod.reversibleTransformation = data[j++];
  32352. if (cod.entropyCoderWithCustomPrecincts) {
  32353. var precinctsSizes = [];
  32354. while (j < length + position) {
  32355. var precinctsSize = data[j++];
  32356. precinctsSizes.push({
  32357. PPx: precinctsSize & 0xF,
  32358. PPy: precinctsSize >> 4
  32359. });
  32360. }
  32361. cod.precinctsSizes = precinctsSizes;
  32362. }
  32363. var unsupported = [];
  32364. if (cod.sopMarkerUsed) {
  32365. unsupported.push('sopMarkerUsed');
  32366. }
  32367. if (cod.ephMarkerUsed) {
  32368. unsupported.push('ephMarkerUsed');
  32369. }
  32370. if (cod.selectiveArithmeticCodingBypass) {
  32371. unsupported.push('selectiveArithmeticCodingBypass');
  32372. }
  32373. if (cod.resetContextProbabilities) {
  32374. unsupported.push('resetContextProbabilities');
  32375. }
  32376. if (cod.terminationOnEachCodingPass) {
  32377. unsupported.push('terminationOnEachCodingPass');
  32378. }
  32379. if (cod.verticalyStripe) {
  32380. unsupported.push('verticalyStripe');
  32381. }
  32382. if (cod.predictableTermination) {
  32383. unsupported.push('predictableTermination');
  32384. }
  32385. if (unsupported.length > 0) {
  32386. doNotRecover = true;
  32387. throw new Error('JPX Error: Unsupported COD options (' +
  32388. unsupported.join(', ') + ')');
  32389. }
  32390. if (context.mainHeader) {
  32391. context.COD = cod;
  32392. } else {
  32393. context.currentTile.COD = cod;
  32394. context.currentTile.COC = [];
  32395. }
  32396. break;
  32397. case 0xFF90: // Start of tile-part (SOT)
  32398. length = readUint16(data, position);
  32399. tile = {};
  32400. tile.index = readUint16(data, position + 2);
  32401. tile.length = readUint32(data, position + 4);
  32402. tile.dataEnd = tile.length + position - 2;
  32403. tile.partIndex = data[position + 8];
  32404. tile.partsCount = data[position + 9];
  32405. context.mainHeader = false;
  32406. if (tile.partIndex === 0) {
  32407. // reset component specific settings
  32408. tile.COD = context.COD;
  32409. tile.COC = context.COC.slice(0); // clone of the global COC
  32410. tile.QCD = context.QCD;
  32411. tile.QCC = context.QCC.slice(0); // clone of the global COC
  32412. }
  32413. context.currentTile = tile;
  32414. break;
  32415. case 0xFF93: // Start of data (SOD)
  32416. tile = context.currentTile;
  32417. if (tile.partIndex === 0) {
  32418. initializeTile(context, tile.index);
  32419. buildPackets(context);
  32420. }
  32421. // moving to the end of the data
  32422. length = tile.dataEnd - position;
  32423. parseTilePackets(context, data, position, length);
  32424. break;
  32425. case 0xFF64: // Comment (COM)
  32426. length = readUint16(data, position);
  32427. // skipping content
  32428. break;
  32429. case 0xFF53: // Coding style component (COC)
  32430. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  32431. 'not implemented');
  32432. default:
  32433. throw new Error('JPX Error: Unknown codestream code: ' +
  32434. code.toString(16));
  32435. }
  32436. position += length;
  32437. }
  32438. } catch (e) {
  32439. if (doNotRecover || this.failOnCorruptedImage) {
  32440. throw e;
  32441. } else {
  32442. warn('Trying to recover from ' + e.message);
  32443. }
  32444. }
  32445. this.tiles = transformComponents(context);
  32446. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  32447. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  32448. this.componentsCount = context.SIZ.Csiz;
  32449. }
  32450. };
  32451. function calculateComponentDimensions(component, siz) {
  32452. // Section B.2 Component mapping
  32453. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  32454. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  32455. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  32456. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  32457. component.width = component.x1 - component.x0;
  32458. component.height = component.y1 - component.y0;
  32459. }
  32460. function calculateTileGrids(context, components) {
  32461. var siz = context.SIZ;
  32462. // Section B.3 Division into tile and tile-components
  32463. var tile, tiles = [];
  32464. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  32465. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  32466. for (var q = 0; q < numYtiles; q++) {
  32467. for (var p = 0; p < numXtiles; p++) {
  32468. tile = {};
  32469. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  32470. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  32471. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  32472. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  32473. tile.width = tile.tx1 - tile.tx0;
  32474. tile.height = tile.ty1 - tile.ty0;
  32475. tile.components = [];
  32476. tiles.push(tile);
  32477. }
  32478. }
  32479. context.tiles = tiles;
  32480. var componentsCount = siz.Csiz;
  32481. for (var i = 0, ii = componentsCount; i < ii; i++) {
  32482. var component = components[i];
  32483. for (var j = 0, jj = tiles.length; j < jj; j++) {
  32484. var tileComponent = {};
  32485. tile = tiles[j];
  32486. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  32487. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  32488. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  32489. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  32490. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  32491. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  32492. tile.components[i] = tileComponent;
  32493. }
  32494. }
  32495. }
  32496. function getBlocksDimensions(context, component, r) {
  32497. var codOrCoc = component.codingStyleParameters;
  32498. var result = {};
  32499. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  32500. result.PPx = 15;
  32501. result.PPy = 15;
  32502. } else {
  32503. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  32504. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  32505. }
  32506. // calculate codeblock size as described in section B.7
  32507. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  32508. Math.min(codOrCoc.xcb, result.PPx));
  32509. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  32510. Math.min(codOrCoc.ycb, result.PPy));
  32511. return result;
  32512. }
  32513. function buildPrecincts(context, resolution, dimensions) {
  32514. // Section B.6 Division resolution to precincts
  32515. var precinctWidth = 1 << dimensions.PPx;
  32516. var precinctHeight = 1 << dimensions.PPy;
  32517. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  32518. Math.ceil(resolution.trx1 / precinctWidth) -
  32519. Math.floor(resolution.trx0 / precinctWidth) : 0);
  32520. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  32521. Math.ceil(resolution.try1 / precinctHeight) -
  32522. Math.floor(resolution.try0 / precinctHeight) : 0);
  32523. var numprecincts = numprecinctswide * numprecinctshigh;
  32524. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  32525. precinctWidth;
  32526. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  32527. precinctHeight;
  32528. resolution.precinctParameters = {
  32529. precinctXOffset: precinctXOffset,
  32530. precinctYOffset: precinctYOffset,
  32531. precinctWidth: precinctWidth,
  32532. precinctHeight: precinctHeight,
  32533. numprecinctswide: numprecinctswide,
  32534. numprecinctshigh: numprecinctshigh,
  32535. numprecincts: numprecincts
  32536. };
  32537. }
  32538. function buildCodeblocks(context, subband, dimensions) {
  32539. // Section B.7 Division sub-band into code-blocks
  32540. var xcb_ = dimensions.xcb_;
  32541. var ycb_ = dimensions.ycb_;
  32542. var codeblockWidth = 1 << xcb_;
  32543. var codeblockHeight = 1 << ycb_;
  32544. var cbx0 = subband.tbx0 >> xcb_;
  32545. var cby0 = subband.tby0 >> ycb_;
  32546. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  32547. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  32548. var precinctParameters = subband.resolution.precinctParameters;
  32549. var codeblocks = [];
  32550. var precincts = [];
  32551. var i, j, codeblock, precinctNumber;
  32552. for (j = cby0; j < cby1; j++) {
  32553. for (i = cbx0; i < cbx1; i++) {
  32554. codeblock = {
  32555. cbx: i,
  32556. cby: j,
  32557. tbx0: codeblockWidth * i,
  32558. tby0: codeblockHeight * j,
  32559. tbx1: codeblockWidth * (i + 1),
  32560. tby1: codeblockHeight * (j + 1)
  32561. };
  32562. // calculate precinct number
  32563. var pi = Math.floor((codeblock.tbx0 -
  32564. precinctParameters.precinctXOffset) /
  32565. precinctParameters.precinctWidth);
  32566. var pj = Math.floor((codeblock.tby0 -
  32567. precinctParameters.precinctYOffset) /
  32568. precinctParameters.precinctHeight);
  32569. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  32570. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  32571. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  32572. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  32573. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  32574. codeblock.precinctNumber = precinctNumber;
  32575. codeblock.subbandType = subband.type;
  32576. codeblock.Lblock = 3;
  32577. codeblocks.push(codeblock);
  32578. // building precinct for the sub-band
  32579. var precinct = precincts[precinctNumber];
  32580. if (precinct !== undefined) {
  32581. if (i < precinct.cbxMin) {
  32582. precinct.cbxMin = i;
  32583. } else if (i > precinct.cbxMax) {
  32584. precinct.cbxMax = i;
  32585. }
  32586. if (j < precinct.cbyMin) {
  32587. precinct.cbxMin = j;
  32588. } else if (j > precinct.cbyMax) {
  32589. precinct.cbyMax = j;
  32590. }
  32591. } else {
  32592. precincts[precinctNumber] = precinct = {
  32593. cbxMin: i,
  32594. cbyMin: j,
  32595. cbxMax: i,
  32596. cbyMax: j
  32597. };
  32598. }
  32599. codeblock.precinct = precinct;
  32600. }
  32601. }
  32602. subband.codeblockParameters = {
  32603. codeblockWidth: xcb_,
  32604. codeblockHeight: ycb_,
  32605. numcodeblockwide: cbx1 - cbx0 + 1,
  32606. numcodeblockhigh: cby1 - cby1 + 1
  32607. };
  32608. subband.codeblocks = codeblocks;
  32609. subband.precincts = precincts;
  32610. }
  32611. function createPacket(resolution, precinctNumber, layerNumber) {
  32612. var precinctCodeblocks = [];
  32613. // Section B.10.8 Order of info in packet
  32614. var subbands = resolution.subbands;
  32615. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  32616. for (var i = 0, ii = subbands.length; i < ii; i++) {
  32617. var subband = subbands[i];
  32618. var codeblocks = subband.codeblocks;
  32619. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  32620. var codeblock = codeblocks[j];
  32621. if (codeblock.precinctNumber !== precinctNumber) {
  32622. continue;
  32623. }
  32624. precinctCodeblocks.push(codeblock);
  32625. }
  32626. }
  32627. return {
  32628. layerNumber: layerNumber,
  32629. codeblocks: precinctCodeblocks
  32630. };
  32631. }
  32632. function LayerResolutionComponentPositionIterator(context) {
  32633. var siz = context.SIZ;
  32634. var tileIndex = context.currentTile.index;
  32635. var tile = context.tiles[tileIndex];
  32636. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  32637. var componentsCount = siz.Csiz;
  32638. var maxDecompositionLevelsCount = 0;
  32639. for (var q = 0; q < componentsCount; q++) {
  32640. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  32641. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  32642. }
  32643. var l = 0, r = 0, i = 0, k = 0;
  32644. this.nextPacket = function JpxImage_nextPacket() {
  32645. // Section B.12.1.1 Layer-resolution-component-position
  32646. for (; l < layersCount; l++) {
  32647. for (; r <= maxDecompositionLevelsCount; r++) {
  32648. for (; i < componentsCount; i++) {
  32649. var component = tile.components[i];
  32650. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  32651. continue;
  32652. }
  32653. var resolution = component.resolutions[r];
  32654. var numprecincts = resolution.precinctParameters.numprecincts;
  32655. for (; k < numprecincts;) {
  32656. var packet = createPacket(resolution, k, l);
  32657. k++;
  32658. return packet;
  32659. }
  32660. k = 0;
  32661. }
  32662. i = 0;
  32663. }
  32664. r = 0;
  32665. }
  32666. throw new Error('JPX Error: Out of packets');
  32667. };
  32668. }
  32669. function ResolutionLayerComponentPositionIterator(context) {
  32670. var siz = context.SIZ;
  32671. var tileIndex = context.currentTile.index;
  32672. var tile = context.tiles[tileIndex];
  32673. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  32674. var componentsCount = siz.Csiz;
  32675. var maxDecompositionLevelsCount = 0;
  32676. for (var q = 0; q < componentsCount; q++) {
  32677. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  32678. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  32679. }
  32680. var r = 0, l = 0, i = 0, k = 0;
  32681. this.nextPacket = function JpxImage_nextPacket() {
  32682. // Section B.12.1.2 Resolution-layer-component-position
  32683. for (; r <= maxDecompositionLevelsCount; r++) {
  32684. for (; l < layersCount; l++) {
  32685. for (; i < componentsCount; i++) {
  32686. var component = tile.components[i];
  32687. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  32688. continue;
  32689. }
  32690. var resolution = component.resolutions[r];
  32691. var numprecincts = resolution.precinctParameters.numprecincts;
  32692. for (; k < numprecincts;) {
  32693. var packet = createPacket(resolution, k, l);
  32694. k++;
  32695. return packet;
  32696. }
  32697. k = 0;
  32698. }
  32699. i = 0;
  32700. }
  32701. l = 0;
  32702. }
  32703. throw new Error('JPX Error: Out of packets');
  32704. };
  32705. }
  32706. function buildPackets(context) {
  32707. var siz = context.SIZ;
  32708. var tileIndex = context.currentTile.index;
  32709. var tile = context.tiles[tileIndex];
  32710. var componentsCount = siz.Csiz;
  32711. // Creating resolutions and sub-bands for each component
  32712. for (var c = 0; c < componentsCount; c++) {
  32713. var component = tile.components[c];
  32714. var decompositionLevelsCount =
  32715. component.codingStyleParameters.decompositionLevelsCount;
  32716. // Section B.5 Resolution levels and sub-bands
  32717. var resolutions = [];
  32718. var subbands = [];
  32719. for (var r = 0; r <= decompositionLevelsCount; r++) {
  32720. var blocksDimensions = getBlocksDimensions(context, component, r);
  32721. var resolution = {};
  32722. var scale = 1 << (decompositionLevelsCount - r);
  32723. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  32724. resolution.try0 = Math.ceil(component.tcy0 / scale);
  32725. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  32726. resolution.try1 = Math.ceil(component.tcy1 / scale);
  32727. buildPrecincts(context, resolution, blocksDimensions);
  32728. resolutions.push(resolution);
  32729. var subband;
  32730. if (r === 0) {
  32731. // one sub-band (LL) with last decomposition
  32732. subband = {};
  32733. subband.type = 'LL';
  32734. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  32735. subband.tby0 = Math.ceil(component.tcy0 / scale);
  32736. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  32737. subband.tby1 = Math.ceil(component.tcy1 / scale);
  32738. subband.resolution = resolution;
  32739. buildCodeblocks(context, subband, blocksDimensions);
  32740. subbands.push(subband);
  32741. resolution.subbands = [subband];
  32742. } else {
  32743. var bscale = 1 << (decompositionLevelsCount - r + 1);
  32744. var resolutionSubbands = [];
  32745. // three sub-bands (HL, LH and HH) with rest of decompositions
  32746. subband = {};
  32747. subband.type = 'HL';
  32748. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  32749. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  32750. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  32751. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  32752. subband.resolution = resolution;
  32753. buildCodeblocks(context, subband, blocksDimensions);
  32754. subbands.push(subband);
  32755. resolutionSubbands.push(subband);
  32756. subband = {};
  32757. subband.type = 'LH';
  32758. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  32759. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  32760. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  32761. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  32762. subband.resolution = resolution;
  32763. buildCodeblocks(context, subband, blocksDimensions);
  32764. subbands.push(subband);
  32765. resolutionSubbands.push(subband);
  32766. subband = {};
  32767. subband.type = 'HH';
  32768. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  32769. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  32770. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  32771. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  32772. subband.resolution = resolution;
  32773. buildCodeblocks(context, subband, blocksDimensions);
  32774. subbands.push(subband);
  32775. resolutionSubbands.push(subband);
  32776. resolution.subbands = resolutionSubbands;
  32777. }
  32778. }
  32779. component.resolutions = resolutions;
  32780. component.subbands = subbands;
  32781. }
  32782. // Generate the packets sequence
  32783. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  32784. switch (progressionOrder) {
  32785. case 0:
  32786. tile.packetsIterator =
  32787. new LayerResolutionComponentPositionIterator(context);
  32788. break;
  32789. case 1:
  32790. tile.packetsIterator =
  32791. new ResolutionLayerComponentPositionIterator(context);
  32792. break;
  32793. default:
  32794. throw new Error('JPX Error: Unsupported progression order ' +
  32795. progressionOrder);
  32796. }
  32797. }
  32798. function parseTilePackets(context, data, offset, dataLength) {
  32799. var position = 0;
  32800. var buffer, bufferSize = 0, skipNextBit = false;
  32801. function readBits(count) {
  32802. while (bufferSize < count) {
  32803. var b = data[offset + position];
  32804. position++;
  32805. if (skipNextBit) {
  32806. buffer = (buffer << 7) | b;
  32807. bufferSize += 7;
  32808. skipNextBit = false;
  32809. } else {
  32810. buffer = (buffer << 8) | b;
  32811. bufferSize += 8;
  32812. }
  32813. if (b === 0xFF) {
  32814. skipNextBit = true;
  32815. }
  32816. }
  32817. bufferSize -= count;
  32818. return (buffer >>> bufferSize) & ((1 << count) - 1);
  32819. }
  32820. function alignToByte() {
  32821. bufferSize = 0;
  32822. if (skipNextBit) {
  32823. position++;
  32824. skipNextBit = false;
  32825. }
  32826. }
  32827. function readCodingpasses() {
  32828. if (readBits(1) === 0) {
  32829. return 1;
  32830. }
  32831. if (readBits(1) === 0) {
  32832. return 2;
  32833. }
  32834. var value = readBits(2);
  32835. if (value < 3) {
  32836. return value + 3;
  32837. }
  32838. value = readBits(5);
  32839. if (value < 31) {
  32840. return value + 6;
  32841. }
  32842. value = readBits(7);
  32843. return value + 37;
  32844. }
  32845. var tileIndex = context.currentTile.index;
  32846. var tile = context.tiles[tileIndex];
  32847. var packetsIterator = tile.packetsIterator;
  32848. while (position < dataLength) {
  32849. var packet = packetsIterator.nextPacket();
  32850. if (!readBits(1)) {
  32851. alignToByte();
  32852. continue;
  32853. }
  32854. var layerNumber = packet.layerNumber;
  32855. var queue = [], codeblock;
  32856. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  32857. codeblock = packet.codeblocks[i];
  32858. var precinct = codeblock.precinct;
  32859. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  32860. var codeblockRow = codeblock.cby - precinct.cbyMin;
  32861. var codeblockIncluded = false;
  32862. var firstTimeInclusion = false;
  32863. var valueReady;
  32864. if ('included' in codeblock) {
  32865. codeblockIncluded = !!readBits(1);
  32866. } else {
  32867. // reading inclusion tree
  32868. precinct = codeblock.precinct;
  32869. var inclusionTree, zeroBitPlanesTree;
  32870. if ('inclusionTree' in precinct) {
  32871. inclusionTree = precinct.inclusionTree;
  32872. } else {
  32873. // building inclusion and zero bit-planes trees
  32874. var width = precinct.cbxMax - precinct.cbxMin + 1;
  32875. var height = precinct.cbyMax - precinct.cbyMin + 1;
  32876. inclusionTree = new InclusionTree(width, height, layerNumber);
  32877. zeroBitPlanesTree = new TagTree(width, height);
  32878. precinct.inclusionTree = inclusionTree;
  32879. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  32880. }
  32881. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  32882. while (true) {
  32883. if (readBits(1)) {
  32884. valueReady = !inclusionTree.nextLevel();
  32885. if (valueReady) {
  32886. codeblock.included = true;
  32887. codeblockIncluded = firstTimeInclusion = true;
  32888. break;
  32889. }
  32890. } else {
  32891. inclusionTree.incrementValue(layerNumber);
  32892. break;
  32893. }
  32894. }
  32895. }
  32896. }
  32897. if (!codeblockIncluded) {
  32898. continue;
  32899. }
  32900. if (firstTimeInclusion) {
  32901. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  32902. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  32903. while (true) {
  32904. if (readBits(1)) {
  32905. valueReady = !zeroBitPlanesTree.nextLevel();
  32906. if (valueReady) {
  32907. break;
  32908. }
  32909. } else {
  32910. zeroBitPlanesTree.incrementValue();
  32911. }
  32912. }
  32913. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  32914. }
  32915. var codingpasses = readCodingpasses();
  32916. while (readBits(1)) {
  32917. codeblock.Lblock++;
  32918. }
  32919. var codingpassesLog2 = log2(codingpasses);
  32920. // rounding down log2
  32921. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  32922. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  32923. var codedDataLength = readBits(bits);
  32924. queue.push({
  32925. codeblock: codeblock,
  32926. codingpasses: codingpasses,
  32927. dataLength: codedDataLength
  32928. });
  32929. }
  32930. alignToByte();
  32931. while (queue.length > 0) {
  32932. var packetItem = queue.shift();
  32933. codeblock = packetItem.codeblock;
  32934. if (!('data' in codeblock)) {
  32935. codeblock.data = [];
  32936. }
  32937. codeblock.data.push({
  32938. data: data,
  32939. start: offset + position,
  32940. end: offset + position + packetItem.dataLength,
  32941. codingpasses: packetItem.codingpasses
  32942. });
  32943. position += packetItem.dataLength;
  32944. }
  32945. }
  32946. return position;
  32947. }
  32948. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  32949. delta, mb, reversible, segmentationSymbolUsed) {
  32950. var x0 = subband.tbx0;
  32951. var y0 = subband.tby0;
  32952. var width = subband.tbx1 - subband.tbx0;
  32953. var codeblocks = subband.codeblocks;
  32954. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  32955. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  32956. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  32957. var codeblock = codeblocks[i];
  32958. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  32959. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  32960. if (blockWidth === 0 || blockHeight === 0) {
  32961. continue;
  32962. }
  32963. if (!('data' in codeblock)) {
  32964. continue;
  32965. }
  32966. var bitModel, currentCodingpassType;
  32967. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  32968. codeblock.zeroBitPlanes, mb);
  32969. currentCodingpassType = 2; // first bit plane starts from cleanup
  32970. // collect data
  32971. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  32972. var j, jj, dataItem;
  32973. for (j = 0, jj = data.length; j < jj; j++) {
  32974. dataItem = data[j];
  32975. totalLength += dataItem.end - dataItem.start;
  32976. codingpasses += dataItem.codingpasses;
  32977. }
  32978. var encodedData = new Uint8Array(totalLength);
  32979. var position = 0;
  32980. for (j = 0, jj = data.length; j < jj; j++) {
  32981. dataItem = data[j];
  32982. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  32983. encodedData.set(chunk, position);
  32984. position += chunk.length;
  32985. }
  32986. // decoding the item
  32987. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  32988. bitModel.setDecoder(decoder);
  32989. for (j = 0; j < codingpasses; j++) {
  32990. switch (currentCodingpassType) {
  32991. case 0:
  32992. bitModel.runSignificancePropogationPass();
  32993. break;
  32994. case 1:
  32995. bitModel.runMagnitudeRefinementPass();
  32996. break;
  32997. case 2:
  32998. bitModel.runCleanupPass();
  32999. if (segmentationSymbolUsed) {
  33000. bitModel.checkSegmentationSymbol();
  33001. }
  33002. break;
  33003. }
  33004. currentCodingpassType = (currentCodingpassType + 1) % 3;
  33005. }
  33006. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  33007. var sign = bitModel.coefficentsSign;
  33008. var magnitude = bitModel.coefficentsMagnitude;
  33009. var bitsDecoded = bitModel.bitsDecoded;
  33010. var magnitudeCorrection = reversible ? 0 : 0.5;
  33011. var k, n, nb;
  33012. position = 0;
  33013. // Do the interleaving of Section F.3.3 here, so we do not need
  33014. // to copy later. LL level is not interleaved, just copied.
  33015. var interleave = (subband.type !== 'LL');
  33016. for (j = 0; j < blockHeight; j++) {
  33017. var row = (offset / width) | 0; // row in the non-interleaved subband
  33018. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  33019. for (k = 0; k < blockWidth; k++) {
  33020. n = magnitude[position];
  33021. if (n !== 0) {
  33022. n = (n + magnitudeCorrection) * delta;
  33023. if (sign[position] !== 0) {
  33024. n = -n;
  33025. }
  33026. nb = bitsDecoded[position];
  33027. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  33028. if (reversible && (nb >= mb)) {
  33029. coefficients[pos] = n;
  33030. } else {
  33031. coefficients[pos] = n * (1 << (mb - nb));
  33032. }
  33033. }
  33034. offset++;
  33035. position++;
  33036. }
  33037. offset += width - blockWidth;
  33038. }
  33039. }
  33040. }
  33041. function transformTile(context, tile, c) {
  33042. var component = tile.components[c];
  33043. var codingStyleParameters = component.codingStyleParameters;
  33044. var quantizationParameters = component.quantizationParameters;
  33045. var decompositionLevelsCount =
  33046. codingStyleParameters.decompositionLevelsCount;
  33047. var spqcds = quantizationParameters.SPqcds;
  33048. var scalarExpounded = quantizationParameters.scalarExpounded;
  33049. var guardBits = quantizationParameters.guardBits;
  33050. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  33051. var precision = context.components[c].precision;
  33052. var reversible = codingStyleParameters.reversibleTransformation;
  33053. var transform = (reversible ? new ReversibleTransform() :
  33054. new IrreversibleTransform());
  33055. var subbandCoefficients = [];
  33056. var b = 0;
  33057. for (var i = 0; i <= decompositionLevelsCount; i++) {
  33058. var resolution = component.resolutions[i];
  33059. var width = resolution.trx1 - resolution.trx0;
  33060. var height = resolution.try1 - resolution.try0;
  33061. // Allocate space for the whole sublevel.
  33062. var coefficients = new Float32Array(width * height);
  33063. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  33064. var mu, epsilon;
  33065. if (!scalarExpounded) {
  33066. // formula E-5
  33067. mu = spqcds[0].mu;
  33068. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  33069. } else {
  33070. mu = spqcds[b].mu;
  33071. epsilon = spqcds[b].epsilon;
  33072. b++;
  33073. }
  33074. var subband = resolution.subbands[j];
  33075. var gainLog2 = SubbandsGainLog2[subband.type];
  33076. // calulate quantization coefficient (Section E.1.1.1)
  33077. var delta = (reversible ? 1 :
  33078. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  33079. var mb = (guardBits + epsilon - 1);
  33080. // In the first resolution level, copyCoefficients will fill the
  33081. // whole array with coefficients. In the succeding passes,
  33082. // copyCoefficients will consecutively fill in the values that belong
  33083. // to the interleaved positions of the HL, LH, and HH coefficients.
  33084. // The LL coefficients will then be interleaved in Transform.iterate().
  33085. copyCoefficients(coefficients, width, height, subband, delta, mb,
  33086. reversible, segmentationSymbolUsed);
  33087. }
  33088. subbandCoefficients.push({
  33089. width: width,
  33090. height: height,
  33091. items: coefficients
  33092. });
  33093. }
  33094. var result = transform.calculate(subbandCoefficients,
  33095. component.tcx0, component.tcy0);
  33096. return {
  33097. left: component.tcx0,
  33098. top: component.tcy0,
  33099. width: result.width,
  33100. height: result.height,
  33101. items: result.items
  33102. };
  33103. }
  33104. function transformComponents(context) {
  33105. var siz = context.SIZ;
  33106. var components = context.components;
  33107. var componentsCount = siz.Csiz;
  33108. var resultImages = [];
  33109. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  33110. var tile = context.tiles[i];
  33111. var transformedTiles = [];
  33112. var c;
  33113. for (c = 0; c < componentsCount; c++) {
  33114. transformedTiles[c] = transformTile(context, tile, c);
  33115. }
  33116. var tile0 = transformedTiles[0];
  33117. var out = new Uint8Array(tile0.items.length * componentsCount);
  33118. var result = {
  33119. left: tile0.left,
  33120. top: tile0.top,
  33121. width: tile0.width,
  33122. height: tile0.height,
  33123. items: out
  33124. };
  33125. // Section G.2.2 Inverse multi component transform
  33126. var shift, offset, max, min, maxK;
  33127. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  33128. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  33129. var fourComponents = componentsCount === 4;
  33130. var y0items = transformedTiles[0].items;
  33131. var y1items = transformedTiles[1].items;
  33132. var y2items = transformedTiles[2].items;
  33133. var y3items = fourComponents ? transformedTiles[3].items : null;
  33134. // HACK: The multiple component transform formulas below assume that
  33135. // all components have the same precision. With this in mind, we
  33136. // compute shift and offset only once.
  33137. shift = components[0].precision - 8;
  33138. offset = (128 << shift) + 0.5;
  33139. max = 255 * (1 << shift);
  33140. maxK = max * 0.5;
  33141. min = -maxK;
  33142. var component0 = tile.components[0];
  33143. var alpha01 = componentsCount - 3;
  33144. jj = y0items.length;
  33145. if (!component0.codingStyleParameters.reversibleTransformation) {
  33146. // inverse irreversible multiple component transform
  33147. for (j = 0; j < jj; j++, pos += alpha01) {
  33148. y0 = y0items[j] + offset;
  33149. y1 = y1items[j];
  33150. y2 = y2items[j];
  33151. r = y0 + 1.402 * y2;
  33152. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  33153. b = y0 + 1.772 * y1;
  33154. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33155. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33156. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33157. }
  33158. } else {
  33159. // inverse reversible multiple component transform
  33160. for (j = 0; j < jj; j++, pos += alpha01) {
  33161. y0 = y0items[j] + offset;
  33162. y1 = y1items[j];
  33163. y2 = y2items[j];
  33164. g = y0 - ((y2 + y1) >> 2);
  33165. r = g + y2;
  33166. b = g + y1;
  33167. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33168. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33169. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33170. }
  33171. }
  33172. if (fourComponents) {
  33173. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  33174. k = y3items[j];
  33175. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  33176. }
  33177. }
  33178. } else { // no multi-component transform
  33179. for (c = 0; c < componentsCount; c++) {
  33180. var items = transformedTiles[c].items;
  33181. shift = components[c].precision - 8;
  33182. offset = (128 << shift) + 0.5;
  33183. max = (127.5 * (1 << shift));
  33184. min = -max;
  33185. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  33186. val = items[j];
  33187. out[pos] = val <= min ? 0 :
  33188. val >= max ? 255 : (val + offset) >> shift;
  33189. pos += componentsCount;
  33190. }
  33191. }
  33192. }
  33193. resultImages.push(result);
  33194. }
  33195. return resultImages;
  33196. }
  33197. function initializeTile(context, tileIndex) {
  33198. var siz = context.SIZ;
  33199. var componentsCount = siz.Csiz;
  33200. var tile = context.tiles[tileIndex];
  33201. for (var c = 0; c < componentsCount; c++) {
  33202. var component = tile.components[c];
  33203. var qcdOrQcc = (c in context.currentTile.QCC ?
  33204. context.currentTile.QCC[c] : context.currentTile.QCD);
  33205. component.quantizationParameters = qcdOrQcc;
  33206. var codOrCoc = (c in context.currentTile.COC ?
  33207. context.currentTile.COC[c] : context.currentTile.COD);
  33208. component.codingStyleParameters = codOrCoc;
  33209. }
  33210. tile.codingStyleDefaultParameters = context.currentTile.COD;
  33211. }
  33212. // Section B.10.2 Tag trees
  33213. var TagTree = (function TagTreeClosure() {
  33214. function TagTree(width, height) {
  33215. var levelsLength = log2(Math.max(width, height)) + 1;
  33216. this.levels = [];
  33217. for (var i = 0; i < levelsLength; i++) {
  33218. var level = {
  33219. width: width,
  33220. height: height,
  33221. items: []
  33222. };
  33223. this.levels.push(level);
  33224. width = Math.ceil(width / 2);
  33225. height = Math.ceil(height / 2);
  33226. }
  33227. }
  33228. TagTree.prototype = {
  33229. reset: function TagTree_reset(i, j) {
  33230. var currentLevel = 0, value = 0, level;
  33231. while (currentLevel < this.levels.length) {
  33232. level = this.levels[currentLevel];
  33233. var index = i + j * level.width;
  33234. if (index in level.items) {
  33235. value = level.items[index];
  33236. break;
  33237. }
  33238. level.index = index;
  33239. i >>= 1;
  33240. j >>= 1;
  33241. currentLevel++;
  33242. }
  33243. currentLevel--;
  33244. level = this.levels[currentLevel];
  33245. level.items[level.index] = value;
  33246. this.currentLevel = currentLevel;
  33247. delete this.value;
  33248. },
  33249. incrementValue: function TagTree_incrementValue() {
  33250. var level = this.levels[this.currentLevel];
  33251. level.items[level.index]++;
  33252. },
  33253. nextLevel: function TagTree_nextLevel() {
  33254. var currentLevel = this.currentLevel;
  33255. var level = this.levels[currentLevel];
  33256. var value = level.items[level.index];
  33257. currentLevel--;
  33258. if (currentLevel < 0) {
  33259. this.value = value;
  33260. return false;
  33261. }
  33262. this.currentLevel = currentLevel;
  33263. level = this.levels[currentLevel];
  33264. level.items[level.index] = value;
  33265. return true;
  33266. }
  33267. };
  33268. return TagTree;
  33269. })();
  33270. var InclusionTree = (function InclusionTreeClosure() {
  33271. function InclusionTree(width, height, defaultValue) {
  33272. var levelsLength = log2(Math.max(width, height)) + 1;
  33273. this.levels = [];
  33274. for (var i = 0; i < levelsLength; i++) {
  33275. var items = new Uint8Array(width * height);
  33276. for (var j = 0, jj = items.length; j < jj; j++) {
  33277. items[j] = defaultValue;
  33278. }
  33279. var level = {
  33280. width: width,
  33281. height: height,
  33282. items: items
  33283. };
  33284. this.levels.push(level);
  33285. width = Math.ceil(width / 2);
  33286. height = Math.ceil(height / 2);
  33287. }
  33288. }
  33289. InclusionTree.prototype = {
  33290. reset: function InclusionTree_reset(i, j, stopValue) {
  33291. var currentLevel = 0;
  33292. while (currentLevel < this.levels.length) {
  33293. var level = this.levels[currentLevel];
  33294. var index = i + j * level.width;
  33295. level.index = index;
  33296. var value = level.items[index];
  33297. if (value === 0xFF) {
  33298. break;
  33299. }
  33300. if (value > stopValue) {
  33301. this.currentLevel = currentLevel;
  33302. // already know about this one, propagating the value to top levels
  33303. this.propagateValues();
  33304. return false;
  33305. }
  33306. i >>= 1;
  33307. j >>= 1;
  33308. currentLevel++;
  33309. }
  33310. this.currentLevel = currentLevel - 1;
  33311. return true;
  33312. },
  33313. incrementValue: function InclusionTree_incrementValue(stopValue) {
  33314. var level = this.levels[this.currentLevel];
  33315. level.items[level.index] = stopValue + 1;
  33316. this.propagateValues();
  33317. },
  33318. propagateValues: function InclusionTree_propagateValues() {
  33319. var levelIndex = this.currentLevel;
  33320. var level = this.levels[levelIndex];
  33321. var currentValue = level.items[level.index];
  33322. while (--levelIndex >= 0) {
  33323. level = this.levels[levelIndex];
  33324. level.items[level.index] = currentValue;
  33325. }
  33326. },
  33327. nextLevel: function InclusionTree_nextLevel() {
  33328. var currentLevel = this.currentLevel;
  33329. var level = this.levels[currentLevel];
  33330. var value = level.items[level.index];
  33331. level.items[level.index] = 0xFF;
  33332. currentLevel--;
  33333. if (currentLevel < 0) {
  33334. return false;
  33335. }
  33336. this.currentLevel = currentLevel;
  33337. level = this.levels[currentLevel];
  33338. level.items[level.index] = value;
  33339. return true;
  33340. }
  33341. };
  33342. return InclusionTree;
  33343. })();
  33344. // Section D. Coefficient bit modeling
  33345. var BitModel = (function BitModelClosure() {
  33346. var UNIFORM_CONTEXT = 17;
  33347. var RUNLENGTH_CONTEXT = 18;
  33348. // Table D-1
  33349. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  33350. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  33351. var LLAndLHContextsLabel = new Uint8Array([
  33352. 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,
  33353. 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,
  33354. 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
  33355. ]);
  33356. var HLContextLabel = new Uint8Array([
  33357. 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,
  33358. 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,
  33359. 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
  33360. ]);
  33361. var HHContextLabel = new Uint8Array([
  33362. 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,
  33363. 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,
  33364. 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
  33365. ]);
  33366. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  33367. this.width = width;
  33368. this.height = height;
  33369. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  33370. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  33371. var coefficientCount = width * height;
  33372. // coefficients outside the encoding region treated as insignificant
  33373. // add border state cells for significanceState
  33374. this.neighborsSignificance = new Uint8Array(coefficientCount);
  33375. this.coefficentsSign = new Uint8Array(coefficientCount);
  33376. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  33377. mb > 6 ? new Uint16Array(coefficientCount) :
  33378. new Uint8Array(coefficientCount);
  33379. this.processingFlags = new Uint8Array(coefficientCount);
  33380. var bitsDecoded = new Uint8Array(coefficientCount);
  33381. if (zeroBitPlanes !== 0) {
  33382. for (var i = 0; i < coefficientCount; i++) {
  33383. bitsDecoded[i] = zeroBitPlanes;
  33384. }
  33385. }
  33386. this.bitsDecoded = bitsDecoded;
  33387. this.reset();
  33388. }
  33389. BitModel.prototype = {
  33390. setDecoder: function BitModel_setDecoder(decoder) {
  33391. this.decoder = decoder;
  33392. },
  33393. reset: function BitModel_reset() {
  33394. // We have 17 contexts that are accessed via context labels,
  33395. // plus the uniform and runlength context.
  33396. this.contexts = new Int8Array(19);
  33397. // Contexts are packed into 1 byte:
  33398. // highest 7 bits carry the index, lowest bit carries mps
  33399. this.contexts[0] = (4 << 1) | 0;
  33400. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  33401. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  33402. },
  33403. setNeighborsSignificance:
  33404. function BitModel_setNeighborsSignificance(row, column, index) {
  33405. var neighborsSignificance = this.neighborsSignificance;
  33406. var width = this.width, height = this.height;
  33407. var left = (column > 0);
  33408. var right = (column + 1 < width);
  33409. var i;
  33410. if (row > 0) {
  33411. i = index - width;
  33412. if (left) {
  33413. neighborsSignificance[i - 1] += 0x10;
  33414. }
  33415. if (right) {
  33416. neighborsSignificance[i + 1] += 0x10;
  33417. }
  33418. neighborsSignificance[i] += 0x04;
  33419. }
  33420. if (row + 1 < height) {
  33421. i = index + width;
  33422. if (left) {
  33423. neighborsSignificance[i - 1] += 0x10;
  33424. }
  33425. if (right) {
  33426. neighborsSignificance[i + 1] += 0x10;
  33427. }
  33428. neighborsSignificance[i] += 0x04;
  33429. }
  33430. if (left) {
  33431. neighborsSignificance[index - 1] += 0x01;
  33432. }
  33433. if (right) {
  33434. neighborsSignificance[index + 1] += 0x01;
  33435. }
  33436. neighborsSignificance[index] |= 0x80;
  33437. },
  33438. runSignificancePropogationPass:
  33439. function BitModel_runSignificancePropogationPass() {
  33440. var decoder = this.decoder;
  33441. var width = this.width, height = this.height;
  33442. var coefficentsMagnitude = this.coefficentsMagnitude;
  33443. var coefficentsSign = this.coefficentsSign;
  33444. var neighborsSignificance = this.neighborsSignificance;
  33445. var processingFlags = this.processingFlags;
  33446. var contexts = this.contexts;
  33447. var labels = this.contextLabelTable;
  33448. var bitsDecoded = this.bitsDecoded;
  33449. var processedInverseMask = ~1;
  33450. var processedMask = 1;
  33451. var firstMagnitudeBitMask = 2;
  33452. for (var i0 = 0; i0 < height; i0 += 4) {
  33453. for (var j = 0; j < width; j++) {
  33454. var index = i0 * width + j;
  33455. for (var i1 = 0; i1 < 4; i1++, index += width) {
  33456. var i = i0 + i1;
  33457. if (i >= height) {
  33458. break;
  33459. }
  33460. // clear processed flag first
  33461. processingFlags[index] &= processedInverseMask;
  33462. if (coefficentsMagnitude[index] ||
  33463. !neighborsSignificance[index]) {
  33464. continue;
  33465. }
  33466. var contextLabel = labels[neighborsSignificance[index]];
  33467. var decision = decoder.readBit(contexts, contextLabel);
  33468. if (decision) {
  33469. var sign = this.decodeSignBit(i, j, index);
  33470. coefficentsSign[index] = sign;
  33471. coefficentsMagnitude[index] = 1;
  33472. this.setNeighborsSignificance(i, j, index);
  33473. processingFlags[index] |= firstMagnitudeBitMask;
  33474. }
  33475. bitsDecoded[index]++;
  33476. processingFlags[index] |= processedMask;
  33477. }
  33478. }
  33479. }
  33480. },
  33481. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  33482. var width = this.width, height = this.height;
  33483. var coefficentsMagnitude = this.coefficentsMagnitude;
  33484. var coefficentsSign = this.coefficentsSign;
  33485. var contribution, sign0, sign1, significance1;
  33486. var contextLabel, decoded;
  33487. // calculate horizontal contribution
  33488. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  33489. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  33490. sign1 = coefficentsSign[index + 1];
  33491. if (significance1) {
  33492. sign0 = coefficentsSign[index - 1];
  33493. contribution = 1 - sign1 - sign0;
  33494. } else {
  33495. contribution = 1 - sign1 - sign1;
  33496. }
  33497. } else if (significance1) {
  33498. sign0 = coefficentsSign[index - 1];
  33499. contribution = 1 - sign0 - sign0;
  33500. } else {
  33501. contribution = 0;
  33502. }
  33503. var horizontalContribution = 3 * contribution;
  33504. // calculate vertical contribution and combine with the horizontal
  33505. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  33506. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  33507. sign1 = coefficentsSign[index + width];
  33508. if (significance1) {
  33509. sign0 = coefficentsSign[index - width];
  33510. contribution = 1 - sign1 - sign0 + horizontalContribution;
  33511. } else {
  33512. contribution = 1 - sign1 - sign1 + horizontalContribution;
  33513. }
  33514. } else if (significance1) {
  33515. sign0 = coefficentsSign[index - width];
  33516. contribution = 1 - sign0 - sign0 + horizontalContribution;
  33517. } else {
  33518. contribution = horizontalContribution;
  33519. }
  33520. if (contribution >= 0) {
  33521. contextLabel = 9 + contribution;
  33522. decoded = this.decoder.readBit(this.contexts, contextLabel);
  33523. } else {
  33524. contextLabel = 9 - contribution;
  33525. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  33526. }
  33527. return decoded;
  33528. },
  33529. runMagnitudeRefinementPass:
  33530. function BitModel_runMagnitudeRefinementPass() {
  33531. var decoder = this.decoder;
  33532. var width = this.width, height = this.height;
  33533. var coefficentsMagnitude = this.coefficentsMagnitude;
  33534. var neighborsSignificance = this.neighborsSignificance;
  33535. var contexts = this.contexts;
  33536. var bitsDecoded = this.bitsDecoded;
  33537. var processingFlags = this.processingFlags;
  33538. var processedMask = 1;
  33539. var firstMagnitudeBitMask = 2;
  33540. var length = width * height;
  33541. var width4 = width * 4;
  33542. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  33543. indexNext = Math.min(length, index0 + width4);
  33544. for (var j = 0; j < width; j++) {
  33545. for (var index = index0 + j; index < indexNext; index += width) {
  33546. // significant but not those that have just become
  33547. if (!coefficentsMagnitude[index] ||
  33548. (processingFlags[index] & processedMask) !== 0) {
  33549. continue;
  33550. }
  33551. var contextLabel = 16;
  33552. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  33553. processingFlags[index] ^= firstMagnitudeBitMask;
  33554. // first refinement
  33555. var significance = neighborsSignificance[index] & 127;
  33556. contextLabel = significance === 0 ? 15 : 14;
  33557. }
  33558. var bit = decoder.readBit(contexts, contextLabel);
  33559. coefficentsMagnitude[index] =
  33560. (coefficentsMagnitude[index] << 1) | bit;
  33561. bitsDecoded[index]++;
  33562. processingFlags[index] |= processedMask;
  33563. }
  33564. }
  33565. }
  33566. },
  33567. runCleanupPass: function BitModel_runCleanupPass() {
  33568. var decoder = this.decoder;
  33569. var width = this.width, height = this.height;
  33570. var neighborsSignificance = this.neighborsSignificance;
  33571. var coefficentsMagnitude = this.coefficentsMagnitude;
  33572. var coefficentsSign = this.coefficentsSign;
  33573. var contexts = this.contexts;
  33574. var labels = this.contextLabelTable;
  33575. var bitsDecoded = this.bitsDecoded;
  33576. var processingFlags = this.processingFlags;
  33577. var processedMask = 1;
  33578. var firstMagnitudeBitMask = 2;
  33579. var oneRowDown = width;
  33580. var twoRowsDown = width * 2;
  33581. var threeRowsDown = width * 3;
  33582. var iNext;
  33583. for (var i0 = 0; i0 < height; i0 = iNext) {
  33584. iNext = Math.min(i0 + 4, height);
  33585. var indexBase = i0 * width;
  33586. var checkAllEmpty = i0 + 3 < height;
  33587. for (var j = 0; j < width; j++) {
  33588. var index0 = indexBase + j;
  33589. // using the property: labels[neighborsSignificance[index]] === 0
  33590. // when neighborsSignificance[index] === 0
  33591. var allEmpty = (checkAllEmpty &&
  33592. processingFlags[index0] === 0 &&
  33593. processingFlags[index0 + oneRowDown] === 0 &&
  33594. processingFlags[index0 + twoRowsDown] === 0 &&
  33595. processingFlags[index0 + threeRowsDown] === 0 &&
  33596. neighborsSignificance[index0] === 0 &&
  33597. neighborsSignificance[index0 + oneRowDown] === 0 &&
  33598. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  33599. neighborsSignificance[index0 + threeRowsDown] === 0);
  33600. var i1 = 0, index = index0;
  33601. var i = i0, sign;
  33602. if (allEmpty) {
  33603. var hasSignificantCoefficent =
  33604. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  33605. if (!hasSignificantCoefficent) {
  33606. bitsDecoded[index0]++;
  33607. bitsDecoded[index0 + oneRowDown]++;
  33608. bitsDecoded[index0 + twoRowsDown]++;
  33609. bitsDecoded[index0 + threeRowsDown]++;
  33610. continue; // next column
  33611. }
  33612. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  33613. decoder.readBit(contexts, UNIFORM_CONTEXT);
  33614. if (i1 !== 0) {
  33615. i = i0 + i1;
  33616. index += i1 * width;
  33617. }
  33618. sign = this.decodeSignBit(i, j, index);
  33619. coefficentsSign[index] = sign;
  33620. coefficentsMagnitude[index] = 1;
  33621. this.setNeighborsSignificance(i, j, index);
  33622. processingFlags[index] |= firstMagnitudeBitMask;
  33623. index = index0;
  33624. for (var i2 = i0; i2 <= i; i2++, index += width) {
  33625. bitsDecoded[index]++;
  33626. }
  33627. i1++;
  33628. }
  33629. for (i = i0 + i1; i < iNext; i++, index += width) {
  33630. if (coefficentsMagnitude[index] ||
  33631. (processingFlags[index] & processedMask) !== 0) {
  33632. continue;
  33633. }
  33634. var contextLabel = labels[neighborsSignificance[index]];
  33635. var decision = decoder.readBit(contexts, contextLabel);
  33636. if (decision === 1) {
  33637. sign = this.decodeSignBit(i, j, index);
  33638. coefficentsSign[index] = sign;
  33639. coefficentsMagnitude[index] = 1;
  33640. this.setNeighborsSignificance(i, j, index);
  33641. processingFlags[index] |= firstMagnitudeBitMask;
  33642. }
  33643. bitsDecoded[index]++;
  33644. }
  33645. }
  33646. }
  33647. },
  33648. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  33649. var decoder = this.decoder;
  33650. var contexts = this.contexts;
  33651. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  33652. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  33653. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  33654. decoder.readBit(contexts, UNIFORM_CONTEXT);
  33655. if (symbol !== 0xA) {
  33656. throw new Error('JPX Error: Invalid segmentation symbol');
  33657. }
  33658. }
  33659. };
  33660. return BitModel;
  33661. })();
  33662. // Section F, Discrete wavelet transformation
  33663. var Transform = (function TransformClosure() {
  33664. function Transform() {}
  33665. Transform.prototype.calculate =
  33666. function transformCalculate(subbands, u0, v0) {
  33667. var ll = subbands[0];
  33668. for (var i = 1, ii = subbands.length; i < ii; i++) {
  33669. ll = this.iterate(ll, subbands[i], u0, v0);
  33670. }
  33671. return ll;
  33672. };
  33673. Transform.prototype.extend = function extend(buffer, offset, size) {
  33674. // Section F.3.7 extending... using max extension of 4
  33675. var i1 = offset - 1, j1 = offset + 1;
  33676. var i2 = offset + size - 2, j2 = offset + size;
  33677. buffer[i1--] = buffer[j1++];
  33678. buffer[j2++] = buffer[i2--];
  33679. buffer[i1--] = buffer[j1++];
  33680. buffer[j2++] = buffer[i2--];
  33681. buffer[i1--] = buffer[j1++];
  33682. buffer[j2++] = buffer[i2--];
  33683. buffer[i1] = buffer[j1];
  33684. buffer[j2] = buffer[i2];
  33685. };
  33686. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  33687. u0, v0) {
  33688. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  33689. var width = hl_lh_hh.width;
  33690. var height = hl_lh_hh.height;
  33691. var items = hl_lh_hh.items;
  33692. var i, j, k, l, u, v;
  33693. // Interleave LL according to Section F.3.3
  33694. for (k = 0, i = 0; i < llHeight; i++) {
  33695. l = i * 2 * width;
  33696. for (j = 0; j < llWidth; j++, k++, l += 2) {
  33697. items[l] = llItems[k];
  33698. }
  33699. }
  33700. // The LL band is not needed anymore.
  33701. llItems = ll.items = null;
  33702. var bufferPadding = 4;
  33703. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  33704. // Section F.3.4 HOR_SR
  33705. if (width === 1) {
  33706. // if width = 1, when u0 even keep items as is, when odd divide by 2
  33707. if ((u0 & 1) !== 0) {
  33708. for (v = 0, k = 0; v < height; v++, k += width) {
  33709. items[k] *= 0.5;
  33710. }
  33711. }
  33712. } else {
  33713. for (v = 0, k = 0; v < height; v++, k += width) {
  33714. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  33715. this.extend(rowBuffer, bufferPadding, width);
  33716. this.filter(rowBuffer, bufferPadding, width);
  33717. items.set(
  33718. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  33719. k);
  33720. }
  33721. }
  33722. // Accesses to the items array can take long, because it may not fit into
  33723. // CPU cache and has to be fetched from main memory. Since subsequent
  33724. // accesses to the items array are not local when reading columns, we
  33725. // have a cache miss every time. To reduce cache misses, get up to
  33726. // 'numBuffers' items at a time and store them into the individual
  33727. // buffers. The colBuffers should be small enough to fit into CPU cache.
  33728. var numBuffers = 16;
  33729. var colBuffers = [];
  33730. for (i = 0; i < numBuffers; i++) {
  33731. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  33732. }
  33733. var b, currentBuffer = 0;
  33734. ll = bufferPadding + height;
  33735. // Section F.3.5 VER_SR
  33736. if (height === 1) {
  33737. // if height = 1, when v0 even keep items as is, when odd divide by 2
  33738. if ((v0 & 1) !== 0) {
  33739. for (u = 0; u < width; u++) {
  33740. items[u] *= 0.5;
  33741. }
  33742. }
  33743. } else {
  33744. for (u = 0; u < width; u++) {
  33745. // if we ran out of buffers, copy several image columns at once
  33746. if (currentBuffer === 0) {
  33747. numBuffers = Math.min(width - u, numBuffers);
  33748. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  33749. for (b = 0; b < numBuffers; b++) {
  33750. colBuffers[b][l] = items[k + b];
  33751. }
  33752. }
  33753. currentBuffer = numBuffers;
  33754. }
  33755. currentBuffer--;
  33756. var buffer = colBuffers[currentBuffer];
  33757. this.extend(buffer, bufferPadding, height);
  33758. this.filter(buffer, bufferPadding, height);
  33759. // If this is last buffer in this group of buffers, flush all buffers.
  33760. if (currentBuffer === 0) {
  33761. k = u - numBuffers + 1;
  33762. for (l = bufferPadding; l < ll; k += width, l++) {
  33763. for (b = 0; b < numBuffers; b++) {
  33764. items[k + b] = colBuffers[b][l];
  33765. }
  33766. }
  33767. }
  33768. }
  33769. }
  33770. return {
  33771. width: width,
  33772. height: height,
  33773. items: items
  33774. };
  33775. };
  33776. return Transform;
  33777. })();
  33778. // Section 3.8.2 Irreversible 9-7 filter
  33779. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  33780. function IrreversibleTransform() {
  33781. Transform.call(this);
  33782. }
  33783. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  33784. IrreversibleTransform.prototype.filter =
  33785. function irreversibleTransformFilter(x, offset, length) {
  33786. var len = length >> 1;
  33787. offset = offset | 0;
  33788. var j, n, current, next;
  33789. var alpha = -1.586134342059924;
  33790. var beta = -0.052980118572961;
  33791. var gamma = 0.882911075530934;
  33792. var delta = 0.443506852043971;
  33793. var K = 1.230174104914001;
  33794. var K_ = 1 / K;
  33795. // step 1 is combined with step 3
  33796. // step 2
  33797. j = offset - 3;
  33798. for (n = len + 4; n--; j += 2) {
  33799. x[j] *= K_;
  33800. }
  33801. // step 1 & 3
  33802. j = offset - 2;
  33803. current = delta * x[j -1];
  33804. for (n = len + 3; n--; j += 2) {
  33805. next = delta * x[j + 1];
  33806. x[j] = K * x[j] - current - next;
  33807. if (n--) {
  33808. j += 2;
  33809. current = delta * x[j + 1];
  33810. x[j] = K * x[j] - current - next;
  33811. } else {
  33812. break;
  33813. }
  33814. }
  33815. // step 4
  33816. j = offset - 1;
  33817. current = gamma * x[j - 1];
  33818. for (n = len + 2; n--; j += 2) {
  33819. next = gamma * x[j + 1];
  33820. x[j] -= current + next;
  33821. if (n--) {
  33822. j += 2;
  33823. current = gamma * x[j + 1];
  33824. x[j] -= current + next;
  33825. } else {
  33826. break;
  33827. }
  33828. }
  33829. // step 5
  33830. j = offset;
  33831. current = beta * x[j - 1];
  33832. for (n = len + 1; n--; j += 2) {
  33833. next = beta * x[j + 1];
  33834. x[j] -= current + next;
  33835. if (n--) {
  33836. j += 2;
  33837. current = beta * x[j + 1];
  33838. x[j] -= current + next;
  33839. } else {
  33840. break;
  33841. }
  33842. }
  33843. // step 6
  33844. if (len !== 0) {
  33845. j = offset + 1;
  33846. current = alpha * x[j - 1];
  33847. for (n = len; n--; j += 2) {
  33848. next = alpha * x[j + 1];
  33849. x[j] -= current + next;
  33850. if (n--) {
  33851. j += 2;
  33852. current = alpha * x[j + 1];
  33853. x[j] -= current + next;
  33854. } else {
  33855. break;
  33856. }
  33857. }
  33858. }
  33859. };
  33860. return IrreversibleTransform;
  33861. })();
  33862. // Section 3.8.1 Reversible 5-3 filter
  33863. var ReversibleTransform = (function ReversibleTransformClosure() {
  33864. function ReversibleTransform() {
  33865. Transform.call(this);
  33866. }
  33867. ReversibleTransform.prototype = Object.create(Transform.prototype);
  33868. ReversibleTransform.prototype.filter =
  33869. function reversibleTransformFilter(x, offset, length) {
  33870. var len = length >> 1;
  33871. offset = offset | 0;
  33872. var j, n;
  33873. for (j = offset, n = len + 1; n--; j += 2) {
  33874. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  33875. }
  33876. for (j = offset + 1, n = len; n--; j += 2) {
  33877. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  33878. }
  33879. };
  33880. return ReversibleTransform;
  33881. })();
  33882. return JpxImage;
  33883. })();
  33884. var Jbig2Image = (function Jbig2ImageClosure() {
  33885. // Utility data structures
  33886. function ContextCache() {}
  33887. ContextCache.prototype = {
  33888. getContexts: function(id) {
  33889. if (id in this) {
  33890. return this[id];
  33891. }
  33892. return (this[id] = new Int8Array(1 << 16));
  33893. }
  33894. };
  33895. function DecodingContext(data, start, end) {
  33896. this.data = data;
  33897. this.start = start;
  33898. this.end = end;
  33899. }
  33900. DecodingContext.prototype = {
  33901. get decoder() {
  33902. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  33903. return shadow(this, 'decoder', decoder);
  33904. },
  33905. get contextCache() {
  33906. var cache = new ContextCache();
  33907. return shadow(this, 'contextCache', cache);
  33908. }
  33909. };
  33910. // Annex A. Arithmetic Integer Decoding Procedure
  33911. // A.2 Procedure for decoding values
  33912. function decodeInteger(contextCache, procedure, decoder) {
  33913. var contexts = contextCache.getContexts(procedure);
  33914. var prev = 1;
  33915. function readBits(length) {
  33916. var v = 0;
  33917. for (var i = 0; i < length; i++) {
  33918. var bit = decoder.readBit(contexts, prev);
  33919. prev = (prev < 256 ? (prev << 1) | bit :
  33920. (((prev << 1) | bit) & 511) | 256);
  33921. v = (v << 1) | bit;
  33922. }
  33923. return v >>> 0;
  33924. }
  33925. var sign = readBits(1);
  33926. var value = readBits(1) ?
  33927. (readBits(1) ?
  33928. (readBits(1) ?
  33929. (readBits(1) ?
  33930. (readBits(1) ?
  33931. (readBits(32) + 4436) :
  33932. readBits(12) + 340) :
  33933. readBits(8) + 84) :
  33934. readBits(6) + 20) :
  33935. readBits(4) + 4) :
  33936. readBits(2);
  33937. return (sign === 0 ? value : (value > 0 ? -value : null));
  33938. }
  33939. // A.3 The IAID decoding procedure
  33940. function decodeIAID(contextCache, decoder, codeLength) {
  33941. var contexts = contextCache.getContexts('IAID');
  33942. var prev = 1;
  33943. for (var i = 0; i < codeLength; i++) {
  33944. var bit = decoder.readBit(contexts, prev);
  33945. prev = (prev << 1) | bit;
  33946. }
  33947. if (codeLength < 31) {
  33948. return prev & ((1 << codeLength) - 1);
  33949. }
  33950. return prev & 0x7FFFFFFF;
  33951. }
  33952. // 7.3 Segment types
  33953. var SegmentTypes = [
  33954. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  33955. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  33956. null, null, null, null, null, 'patternDictionary', null, null, null,
  33957. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  33958. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  33959. null, null, null, null, null, 'IntermediateGenericRegion', null,
  33960. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  33961. 'IntermediateGenericRefinementRegion', null,
  33962. 'ImmediateGenericRefinementRegion',
  33963. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  33964. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  33965. 'Tables', null, null, null, null, null, null, null, null,
  33966. 'Extension'
  33967. ];
  33968. var CodingTemplates = [
  33969. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  33970. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  33971. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  33972. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  33973. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  33974. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  33975. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  33976. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  33977. {x: -1, y: 0}],
  33978. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  33979. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  33980. ];
  33981. var RefinementTemplates = [
  33982. {
  33983. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  33984. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  33985. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  33986. },
  33987. {
  33988. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  33989. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  33990. {x: 0, y: 1}, {x: 1, y: 1}]
  33991. }
  33992. ];
  33993. // See 6.2.5.7 Decoding the bitmap.
  33994. var ReusedContexts = [
  33995. 0x9B25, // 10011 0110010 0101
  33996. 0x0795, // 0011 110010 101
  33997. 0x00E5, // 001 11001 01
  33998. 0x0195 // 011001 0101
  33999. ];
  34000. var RefinementReusedContexts = [
  34001. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  34002. 0x0008 // '0000' + '001000'
  34003. ];
  34004. function decodeBitmapTemplate0(width, height, decodingContext) {
  34005. var decoder = decodingContext.decoder;
  34006. var contexts = decodingContext.contextCache.getContexts('GB');
  34007. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  34008. // ...ooooo....
  34009. // ..ooooooo... Context template for current pixel (X)
  34010. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  34011. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  34012. for (i = 0; i < height; i++) {
  34013. row = bitmap[i] = new Uint8Array(width);
  34014. row1 = (i < 1) ? row : bitmap[i - 1];
  34015. row2 = (i < 2) ? row : bitmap[i - 2];
  34016. // At the beginning of each row:
  34017. // Fill contextLabel with pixels that are above/right of (X)
  34018. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  34019. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  34020. (row1[3] << 4);
  34021. for (j = 0; j < width; j++) {
  34022. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  34023. // At each pixel: Clear contextLabel pixels that are shifted
  34024. // out of the context, then add new ones.
  34025. // If j + n is out of range at the right image border, then
  34026. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  34027. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  34028. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  34029. }
  34030. }
  34031. return bitmap;
  34032. }
  34033. // 6.2 Generic Region Decoding Procedure
  34034. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  34035. decodingContext) {
  34036. if (mmr) {
  34037. error('JBIG2 error: MMR encoding is not supported');
  34038. }
  34039. // Use optimized version for the most common case
  34040. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  34041. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  34042. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  34043. return decodeBitmapTemplate0(width, height, decodingContext);
  34044. }
  34045. var useskip = !!skip;
  34046. var template = CodingTemplates[templateIndex].concat(at);
  34047. // Sorting is non-standard, and it is not required. But sorting increases
  34048. // the number of template bits that can be reused from the previous
  34049. // contextLabel in the main loop.
  34050. template.sort(function (a, b) {
  34051. return (a.y - b.y) || (a.x - b.x);
  34052. });
  34053. var templateLength = template.length;
  34054. var templateX = new Int8Array(templateLength);
  34055. var templateY = new Int8Array(templateLength);
  34056. var changingTemplateEntries = [];
  34057. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  34058. var c, k;
  34059. for (k = 0; k < templateLength; k++) {
  34060. templateX[k] = template[k].x;
  34061. templateY[k] = template[k].y;
  34062. minX = Math.min(minX, template[k].x);
  34063. maxX = Math.max(maxX, template[k].x);
  34064. minY = Math.min(minY, template[k].y);
  34065. // Check if the template pixel appears in two consecutive context labels,
  34066. // so it can be reused. Otherwise, we add it to the list of changing
  34067. // template entries.
  34068. if (k < templateLength - 1 &&
  34069. template[k].y === template[k + 1].y &&
  34070. template[k].x === template[k + 1].x - 1) {
  34071. reuseMask |= 1 << (templateLength - 1 - k);
  34072. } else {
  34073. changingTemplateEntries.push(k);
  34074. }
  34075. }
  34076. var changingEntriesLength = changingTemplateEntries.length;
  34077. var changingTemplateX = new Int8Array(changingEntriesLength);
  34078. var changingTemplateY = new Int8Array(changingEntriesLength);
  34079. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  34080. for (c = 0; c < changingEntriesLength; c++) {
  34081. k = changingTemplateEntries[c];
  34082. changingTemplateX[c] = template[k].x;
  34083. changingTemplateY[c] = template[k].y;
  34084. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  34085. }
  34086. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  34087. var sbb_left = -minX;
  34088. var sbb_top = -minY;
  34089. var sbb_right = width - maxX;
  34090. var pseudoPixelContext = ReusedContexts[templateIndex];
  34091. var row = new Uint8Array(width);
  34092. var bitmap = [];
  34093. var decoder = decodingContext.decoder;
  34094. var contexts = decodingContext.contextCache.getContexts('GB');
  34095. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  34096. for (var i = 0; i < height; i++) {
  34097. if (prediction) {
  34098. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34099. ltp ^= sltp;
  34100. if (ltp) {
  34101. bitmap.push(row); // duplicate previous row
  34102. continue;
  34103. }
  34104. }
  34105. row = new Uint8Array(row);
  34106. bitmap.push(row);
  34107. for (j = 0; j < width; j++) {
  34108. if (useskip && skip[i][j]) {
  34109. row[j] = 0;
  34110. continue;
  34111. }
  34112. // Are we in the middle of a scanline, so we can reuse contextLabel
  34113. // bits?
  34114. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  34115. // If yes, we can just shift the bits that are reusable and only
  34116. // fetch the remaining ones.
  34117. contextLabel = (contextLabel << 1) & reuseMask;
  34118. for (k = 0; k < changingEntriesLength; k++) {
  34119. i0 = i + changingTemplateY[k];
  34120. j0 = j + changingTemplateX[k];
  34121. bit = bitmap[i0][j0];
  34122. if (bit) {
  34123. bit = changingTemplateBit[k];
  34124. contextLabel |= bit;
  34125. }
  34126. }
  34127. } else {
  34128. // compute the contextLabel from scratch
  34129. contextLabel = 0;
  34130. shift = templateLength - 1;
  34131. for (k = 0; k < templateLength; k++, shift--) {
  34132. j0 = j + templateX[k];
  34133. if (j0 >= 0 && j0 < width) {
  34134. i0 = i + templateY[k];
  34135. if (i0 >= 0) {
  34136. bit = bitmap[i0][j0];
  34137. if (bit) {
  34138. contextLabel |= bit << shift;
  34139. }
  34140. }
  34141. }
  34142. }
  34143. }
  34144. var pixel = decoder.readBit(contexts, contextLabel);
  34145. row[j] = pixel;
  34146. }
  34147. }
  34148. return bitmap;
  34149. }
  34150. // 6.3.2 Generic Refinement Region Decoding Procedure
  34151. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  34152. offsetX, offsetY, prediction, at,
  34153. decodingContext) {
  34154. var codingTemplate = RefinementTemplates[templateIndex].coding;
  34155. if (templateIndex === 0) {
  34156. codingTemplate = codingTemplate.concat([at[0]]);
  34157. }
  34158. var codingTemplateLength = codingTemplate.length;
  34159. var codingTemplateX = new Int32Array(codingTemplateLength);
  34160. var codingTemplateY = new Int32Array(codingTemplateLength);
  34161. var k;
  34162. for (k = 0; k < codingTemplateLength; k++) {
  34163. codingTemplateX[k] = codingTemplate[k].x;
  34164. codingTemplateY[k] = codingTemplate[k].y;
  34165. }
  34166. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  34167. if (templateIndex === 0) {
  34168. referenceTemplate = referenceTemplate.concat([at[1]]);
  34169. }
  34170. var referenceTemplateLength = referenceTemplate.length;
  34171. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  34172. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  34173. for (k = 0; k < referenceTemplateLength; k++) {
  34174. referenceTemplateX[k] = referenceTemplate[k].x;
  34175. referenceTemplateY[k] = referenceTemplate[k].y;
  34176. }
  34177. var referenceWidth = referenceBitmap[0].length;
  34178. var referenceHeight = referenceBitmap.length;
  34179. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  34180. var bitmap = [];
  34181. var decoder = decodingContext.decoder;
  34182. var contexts = decodingContext.contextCache.getContexts('GR');
  34183. var ltp = 0;
  34184. for (var i = 0; i < height; i++) {
  34185. if (prediction) {
  34186. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34187. ltp ^= sltp;
  34188. if (ltp) {
  34189. error('JBIG2 error: prediction is not supported');
  34190. }
  34191. }
  34192. var row = new Uint8Array(width);
  34193. bitmap.push(row);
  34194. for (var j = 0; j < width; j++) {
  34195. var i0, j0;
  34196. var contextLabel = 0;
  34197. for (k = 0; k < codingTemplateLength; k++) {
  34198. i0 = i + codingTemplateY[k];
  34199. j0 = j + codingTemplateX[k];
  34200. if (i0 < 0 || j0 < 0 || j0 >= width) {
  34201. contextLabel <<= 1; // out of bound pixel
  34202. } else {
  34203. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  34204. }
  34205. }
  34206. for (k = 0; k < referenceTemplateLength; k++) {
  34207. i0 = i + referenceTemplateY[k] + offsetY;
  34208. j0 = j + referenceTemplateX[k] + offsetX;
  34209. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  34210. j0 >= referenceWidth) {
  34211. contextLabel <<= 1; // out of bound pixel
  34212. } else {
  34213. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  34214. }
  34215. }
  34216. var pixel = decoder.readBit(contexts, contextLabel);
  34217. row[j] = pixel;
  34218. }
  34219. }
  34220. return bitmap;
  34221. }
  34222. // 6.5.5 Decoding the symbol dictionary
  34223. function decodeSymbolDictionary(huffman, refinement, symbols,
  34224. numberOfNewSymbols, numberOfExportedSymbols,
  34225. huffmanTables, templateIndex, at,
  34226. refinementTemplateIndex, refinementAt,
  34227. decodingContext) {
  34228. if (huffman) {
  34229. error('JBIG2 error: huffman is not supported');
  34230. }
  34231. var newSymbols = [];
  34232. var currentHeight = 0;
  34233. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  34234. var decoder = decodingContext.decoder;
  34235. var contextCache = decodingContext.contextCache;
  34236. while (newSymbols.length < numberOfNewSymbols) {
  34237. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  34238. currentHeight += deltaHeight;
  34239. var currentWidth = 0;
  34240. var totalWidth = 0;
  34241. while (true) {
  34242. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  34243. if (deltaWidth === null) {
  34244. break; // OOB
  34245. }
  34246. currentWidth += deltaWidth;
  34247. totalWidth += currentWidth;
  34248. var bitmap;
  34249. if (refinement) {
  34250. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  34251. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  34252. if (numberOfInstances > 1) {
  34253. bitmap = decodeTextRegion(huffman, refinement,
  34254. currentWidth, currentHeight, 0,
  34255. numberOfInstances, 1, //strip size
  34256. symbols.concat(newSymbols),
  34257. symbolCodeLength,
  34258. 0, //transposed
  34259. 0, //ds offset
  34260. 1, //top left 7.4.3.1.1
  34261. 0, //OR operator
  34262. huffmanTables,
  34263. refinementTemplateIndex, refinementAt,
  34264. decodingContext);
  34265. } else {
  34266. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34267. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34268. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34269. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  34270. newSymbols[symbolId - symbols.length]);
  34271. bitmap = decodeRefinement(currentWidth, currentHeight,
  34272. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  34273. decodingContext);
  34274. }
  34275. } else {
  34276. // 6.5.8.1 Direct-coded symbol bitmap
  34277. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  34278. templateIndex, false, null, at, decodingContext);
  34279. }
  34280. newSymbols.push(bitmap);
  34281. }
  34282. }
  34283. // 6.5.10 Exported symbols
  34284. var exportedSymbols = [];
  34285. var flags = [], currentFlag = false;
  34286. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  34287. while (flags.length < totalSymbolsLength) {
  34288. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  34289. while (runLength--) {
  34290. flags.push(currentFlag);
  34291. }
  34292. currentFlag = !currentFlag;
  34293. }
  34294. for (var i = 0, ii = symbols.length; i < ii; i++) {
  34295. if (flags[i]) {
  34296. exportedSymbols.push(symbols[i]);
  34297. }
  34298. }
  34299. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  34300. if (flags[i]) {
  34301. exportedSymbols.push(newSymbols[j]);
  34302. }
  34303. }
  34304. return exportedSymbols;
  34305. }
  34306. function decodeTextRegion(huffman, refinement, width, height,
  34307. defaultPixelValue, numberOfSymbolInstances,
  34308. stripSize, inputSymbols, symbolCodeLength,
  34309. transposed, dsOffset, referenceCorner,
  34310. combinationOperator, huffmanTables,
  34311. refinementTemplateIndex, refinementAt,
  34312. decodingContext) {
  34313. if (huffman) {
  34314. error('JBIG2 error: huffman is not supported');
  34315. }
  34316. // Prepare bitmap
  34317. var bitmap = [];
  34318. var i, row;
  34319. for (i = 0; i < height; i++) {
  34320. row = new Uint8Array(width);
  34321. if (defaultPixelValue) {
  34322. for (var j = 0; j < width; j++) {
  34323. row[j] = defaultPixelValue;
  34324. }
  34325. }
  34326. bitmap.push(row);
  34327. }
  34328. var decoder = decodingContext.decoder;
  34329. var contextCache = decodingContext.contextCache;
  34330. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  34331. var firstS = 0;
  34332. i = 0;
  34333. while (i < numberOfSymbolInstances) {
  34334. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  34335. stripT += deltaT;
  34336. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  34337. firstS += deltaFirstS;
  34338. var currentS = firstS;
  34339. do {
  34340. var currentT = (stripSize === 1 ? 0 :
  34341. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  34342. var t = stripSize * stripT + currentT;
  34343. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34344. var applyRefinement = (refinement &&
  34345. decodeInteger(contextCache, 'IARI', decoder));
  34346. var symbolBitmap = inputSymbols[symbolId];
  34347. var symbolWidth = symbolBitmap[0].length;
  34348. var symbolHeight = symbolBitmap.length;
  34349. if (applyRefinement) {
  34350. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  34351. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  34352. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34353. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34354. symbolWidth += rdw;
  34355. symbolHeight += rdh;
  34356. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  34357. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  34358. (rdh >> 1) + rdy, false, refinementAt,
  34359. decodingContext);
  34360. }
  34361. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  34362. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  34363. var s2, t2, symbolRow;
  34364. if (transposed) {
  34365. // Place Symbol Bitmap from T1,S1
  34366. for (s2 = 0; s2 < symbolHeight; s2++) {
  34367. row = bitmap[offsetS + s2];
  34368. if (!row) {
  34369. continue;
  34370. }
  34371. symbolRow = symbolBitmap[s2];
  34372. // To ignore Parts of Symbol bitmap which goes
  34373. // outside bitmap region
  34374. var maxWidth = Math.min(width - offsetT, symbolWidth);
  34375. switch (combinationOperator) {
  34376. case 0: // OR
  34377. for (t2 = 0; t2 < maxWidth; t2++) {
  34378. row[offsetT + t2] |= symbolRow[t2];
  34379. }
  34380. break;
  34381. case 2: // XOR
  34382. for (t2 = 0; t2 < maxWidth; t2++) {
  34383. row[offsetT + t2] ^= symbolRow[t2];
  34384. }
  34385. break;
  34386. default:
  34387. error('JBIG2 error: operator ' + combinationOperator +
  34388. ' is not supported');
  34389. }
  34390. }
  34391. currentS += symbolHeight - 1;
  34392. } else {
  34393. for (t2 = 0; t2 < symbolHeight; t2++) {
  34394. row = bitmap[offsetT + t2];
  34395. if (!row) {
  34396. continue;
  34397. }
  34398. symbolRow = symbolBitmap[t2];
  34399. switch (combinationOperator) {
  34400. case 0: // OR
  34401. for (s2 = 0; s2 < symbolWidth; s2++) {
  34402. row[offsetS + s2] |= symbolRow[s2];
  34403. }
  34404. break;
  34405. case 2: // XOR
  34406. for (s2 = 0; s2 < symbolWidth; s2++) {
  34407. row[offsetS + s2] ^= symbolRow[s2];
  34408. }
  34409. break;
  34410. default:
  34411. error('JBIG2 error: operator ' + combinationOperator +
  34412. ' is not supported');
  34413. }
  34414. }
  34415. currentS += symbolWidth - 1;
  34416. }
  34417. i++;
  34418. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  34419. if (deltaS === null) {
  34420. break; // OOB
  34421. }
  34422. currentS += deltaS + dsOffset;
  34423. } while (true);
  34424. }
  34425. return bitmap;
  34426. }
  34427. function readSegmentHeader(data, start) {
  34428. var segmentHeader = {};
  34429. segmentHeader.number = readUint32(data, start);
  34430. var flags = data[start + 4];
  34431. var segmentType = flags & 0x3F;
  34432. if (!SegmentTypes[segmentType]) {
  34433. error('JBIG2 error: invalid segment type: ' + segmentType);
  34434. }
  34435. segmentHeader.type = segmentType;
  34436. segmentHeader.typeName = SegmentTypes[segmentType];
  34437. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  34438. var pageAssociationFieldSize = !!(flags & 0x40);
  34439. var referredFlags = data[start + 5];
  34440. var referredToCount = (referredFlags >> 5) & 7;
  34441. var retainBits = [referredFlags & 31];
  34442. var position = start + 6;
  34443. if (referredFlags === 7) {
  34444. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  34445. position += 3;
  34446. var bytes = (referredToCount + 7) >> 3;
  34447. retainBits[0] = data[position++];
  34448. while (--bytes > 0) {
  34449. retainBits.push(data[position++]);
  34450. }
  34451. } else if (referredFlags === 5 || referredFlags === 6) {
  34452. error('JBIG2 error: invalid referred-to flags');
  34453. }
  34454. segmentHeader.retainBits = retainBits;
  34455. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  34456. (segmentHeader.number <= 65536 ? 2 : 4));
  34457. var referredTo = [];
  34458. var i, ii;
  34459. for (i = 0; i < referredToCount; i++) {
  34460. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  34461. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  34462. readUint32(data, position)));
  34463. referredTo.push(number);
  34464. position += referredToSegmentNumberSize;
  34465. }
  34466. segmentHeader.referredTo = referredTo;
  34467. if (!pageAssociationFieldSize) {
  34468. segmentHeader.pageAssociation = data[position++];
  34469. } else {
  34470. segmentHeader.pageAssociation = readUint32(data, position);
  34471. position += 4;
  34472. }
  34473. segmentHeader.length = readUint32(data, position);
  34474. position += 4;
  34475. if (segmentHeader.length === 0xFFFFFFFF) {
  34476. // 7.2.7 Segment data length, unknown segment length
  34477. if (segmentType === 38) { // ImmediateGenericRegion
  34478. var genericRegionInfo = readRegionSegmentInformation(data, position);
  34479. var genericRegionSegmentFlags = data[position +
  34480. RegionSegmentInformationFieldLength];
  34481. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  34482. // searching for the segment end
  34483. var searchPatternLength = 6;
  34484. var searchPattern = new Uint8Array(searchPatternLength);
  34485. if (!genericRegionMmr) {
  34486. searchPattern[0] = 0xFF;
  34487. searchPattern[1] = 0xAC;
  34488. }
  34489. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  34490. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  34491. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  34492. searchPattern[5] = genericRegionInfo.height & 0xFF;
  34493. for (i = position, ii = data.length; i < ii; i++) {
  34494. var j = 0;
  34495. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  34496. j++;
  34497. }
  34498. if (j === searchPatternLength) {
  34499. segmentHeader.length = i + searchPatternLength;
  34500. break;
  34501. }
  34502. }
  34503. if (segmentHeader.length === 0xFFFFFFFF) {
  34504. error('JBIG2 error: segment end was not found');
  34505. }
  34506. } else {
  34507. error('JBIG2 error: invalid unknown segment length');
  34508. }
  34509. }
  34510. segmentHeader.headerEnd = position;
  34511. return segmentHeader;
  34512. }
  34513. function readSegments(header, data, start, end) {
  34514. var segments = [];
  34515. var position = start;
  34516. while (position < end) {
  34517. var segmentHeader = readSegmentHeader(data, position);
  34518. position = segmentHeader.headerEnd;
  34519. var segment = {
  34520. header: segmentHeader,
  34521. data: data
  34522. };
  34523. if (!header.randomAccess) {
  34524. segment.start = position;
  34525. position += segmentHeader.length;
  34526. segment.end = position;
  34527. }
  34528. segments.push(segment);
  34529. if (segmentHeader.type === 51) {
  34530. break; // end of file is found
  34531. }
  34532. }
  34533. if (header.randomAccess) {
  34534. for (var i = 0, ii = segments.length; i < ii; i++) {
  34535. segments[i].start = position;
  34536. position += segments[i].header.length;
  34537. segments[i].end = position;
  34538. }
  34539. }
  34540. return segments;
  34541. }
  34542. // 7.4.1 Region segment information field
  34543. function readRegionSegmentInformation(data, start) {
  34544. return {
  34545. width: readUint32(data, start),
  34546. height: readUint32(data, start + 4),
  34547. x: readUint32(data, start + 8),
  34548. y: readUint32(data, start + 12),
  34549. combinationOperator: data[start + 16] & 7
  34550. };
  34551. }
  34552. var RegionSegmentInformationFieldLength = 17;
  34553. function processSegment(segment, visitor) {
  34554. var header = segment.header;
  34555. var data = segment.data, position = segment.start, end = segment.end;
  34556. var args, at, i, atLength;
  34557. switch (header.type) {
  34558. case 0: // SymbolDictionary
  34559. // 7.4.2 Symbol dictionary segment syntax
  34560. var dictionary = {};
  34561. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  34562. dictionary.huffman = !!(dictionaryFlags & 1);
  34563. dictionary.refinement = !!(dictionaryFlags & 2);
  34564. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  34565. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  34566. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  34567. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  34568. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  34569. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  34570. dictionary.template = (dictionaryFlags >> 10) & 3;
  34571. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  34572. position += 2;
  34573. if (!dictionary.huffman) {
  34574. atLength = dictionary.template === 0 ? 4 : 1;
  34575. at = [];
  34576. for (i = 0; i < atLength; i++) {
  34577. at.push({
  34578. x: readInt8(data, position),
  34579. y: readInt8(data, position + 1)
  34580. });
  34581. position += 2;
  34582. }
  34583. dictionary.at = at;
  34584. }
  34585. if (dictionary.refinement && !dictionary.refinementTemplate) {
  34586. at = [];
  34587. for (i = 0; i < 2; i++) {
  34588. at.push({
  34589. x: readInt8(data, position),
  34590. y: readInt8(data, position + 1)
  34591. });
  34592. position += 2;
  34593. }
  34594. dictionary.refinementAt = at;
  34595. }
  34596. dictionary.numberOfExportedSymbols = readUint32(data, position);
  34597. position += 4;
  34598. dictionary.numberOfNewSymbols = readUint32(data, position);
  34599. position += 4;
  34600. args = [dictionary, header.number, header.referredTo,
  34601. data, position, end];
  34602. break;
  34603. case 6: // ImmediateTextRegion
  34604. case 7: // ImmediateLosslessTextRegion
  34605. var textRegion = {};
  34606. textRegion.info = readRegionSegmentInformation(data, position);
  34607. position += RegionSegmentInformationFieldLength;
  34608. var textRegionSegmentFlags = readUint16(data, position);
  34609. position += 2;
  34610. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  34611. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  34612. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  34613. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  34614. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  34615. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  34616. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  34617. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  34618. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  34619. if (textRegion.huffman) {
  34620. var textRegionHuffmanFlags = readUint16(data, position);
  34621. position += 2;
  34622. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  34623. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  34624. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  34625. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  34626. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  34627. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  34628. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  34629. textRegion.huffmanRefinementSizeSelector =
  34630. !!(textRegionHuffmanFlags & 14);
  34631. }
  34632. if (textRegion.refinement && !textRegion.refinementTemplate) {
  34633. at = [];
  34634. for (i = 0; i < 2; i++) {
  34635. at.push({
  34636. x: readInt8(data, position),
  34637. y: readInt8(data, position + 1)
  34638. });
  34639. position += 2;
  34640. }
  34641. textRegion.refinementAt = at;
  34642. }
  34643. textRegion.numberOfSymbolInstances = readUint32(data, position);
  34644. position += 4;
  34645. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  34646. if (textRegion.huffman) {
  34647. error('JBIG2 error: huffman is not supported');
  34648. }
  34649. args = [textRegion, header.referredTo, data, position, end];
  34650. break;
  34651. case 38: // ImmediateGenericRegion
  34652. case 39: // ImmediateLosslessGenericRegion
  34653. var genericRegion = {};
  34654. genericRegion.info = readRegionSegmentInformation(data, position);
  34655. position += RegionSegmentInformationFieldLength;
  34656. var genericRegionSegmentFlags = data[position++];
  34657. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  34658. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  34659. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  34660. if (!genericRegion.mmr) {
  34661. atLength = genericRegion.template === 0 ? 4 : 1;
  34662. at = [];
  34663. for (i = 0; i < atLength; i++) {
  34664. at.push({
  34665. x: readInt8(data, position),
  34666. y: readInt8(data, position + 1)
  34667. });
  34668. position += 2;
  34669. }
  34670. genericRegion.at = at;
  34671. }
  34672. args = [genericRegion, data, position, end];
  34673. break;
  34674. case 48: // PageInformation
  34675. var pageInfo = {
  34676. width: readUint32(data, position),
  34677. height: readUint32(data, position + 4),
  34678. resolutionX: readUint32(data, position + 8),
  34679. resolutionY: readUint32(data, position + 12)
  34680. };
  34681. if (pageInfo.height === 0xFFFFFFFF) {
  34682. delete pageInfo.height;
  34683. }
  34684. var pageSegmentFlags = data[position + 16];
  34685. var pageStripingInformatiom = readUint16(data, position + 17);
  34686. pageInfo.lossless = !!(pageSegmentFlags & 1);
  34687. pageInfo.refinement = !!(pageSegmentFlags & 2);
  34688. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  34689. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  34690. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  34691. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  34692. args = [pageInfo];
  34693. break;
  34694. case 49: // EndOfPage
  34695. break;
  34696. case 50: // EndOfStripe
  34697. break;
  34698. case 51: // EndOfFile
  34699. break;
  34700. case 62: // 7.4.15 defines 2 extension types which
  34701. // are comments and can be ignored.
  34702. break;
  34703. default:
  34704. error('JBIG2 error: segment type ' + header.typeName + '(' +
  34705. header.type + ') is not implemented');
  34706. }
  34707. var callbackName = 'on' + header.typeName;
  34708. if (callbackName in visitor) {
  34709. visitor[callbackName].apply(visitor, args);
  34710. }
  34711. }
  34712. function processSegments(segments, visitor) {
  34713. for (var i = 0, ii = segments.length; i < ii; i++) {
  34714. processSegment(segments[i], visitor);
  34715. }
  34716. }
  34717. function parseJbig2(data, start, end) {
  34718. var position = start;
  34719. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  34720. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  34721. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  34722. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  34723. error('JBIG2 error: invalid header');
  34724. }
  34725. var header = {};
  34726. position += 8;
  34727. var flags = data[position++];
  34728. header.randomAccess = !(flags & 1);
  34729. if (!(flags & 2)) {
  34730. header.numberOfPages = readUint32(data, position);
  34731. position += 4;
  34732. }
  34733. var segments = readSegments(header, data, position, end);
  34734. error('Not implemented');
  34735. // processSegments(segments, new SimpleSegmentVisitor());
  34736. }
  34737. function parseJbig2Chunks(chunks) {
  34738. var visitor = new SimpleSegmentVisitor();
  34739. for (var i = 0, ii = chunks.length; i < ii; i++) {
  34740. var chunk = chunks[i];
  34741. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  34742. processSegments(segments, visitor);
  34743. }
  34744. return visitor.buffer;
  34745. }
  34746. function SimpleSegmentVisitor() {}
  34747. SimpleSegmentVisitor.prototype = {
  34748. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  34749. this.currentPageInfo = info;
  34750. var rowSize = (info.width + 7) >> 3;
  34751. var buffer = new Uint8Array(rowSize * info.height);
  34752. // The contents of ArrayBuffers are initialized to 0.
  34753. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  34754. if (info.defaultPixelValue) {
  34755. for (var i = 0, ii = buffer.length; i < ii; i++) {
  34756. buffer[i] = 0xFF;
  34757. }
  34758. }
  34759. this.buffer = buffer;
  34760. },
  34761. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  34762. var pageInfo = this.currentPageInfo;
  34763. var width = regionInfo.width, height = regionInfo.height;
  34764. var rowSize = (pageInfo.width + 7) >> 3;
  34765. var combinationOperator = pageInfo.combinationOperatorOverride ?
  34766. regionInfo.combinationOperator : pageInfo.combinationOperator;
  34767. var buffer = this.buffer;
  34768. var mask0 = 128 >> (regionInfo.x & 7);
  34769. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  34770. var i, j, mask, offset;
  34771. switch (combinationOperator) {
  34772. case 0: // OR
  34773. for (i = 0; i < height; i++) {
  34774. mask = mask0;
  34775. offset = offset0;
  34776. for (j = 0; j < width; j++) {
  34777. if (bitmap[i][j]) {
  34778. buffer[offset] |= mask;
  34779. }
  34780. mask >>= 1;
  34781. if (!mask) {
  34782. mask = 128;
  34783. offset++;
  34784. }
  34785. }
  34786. offset0 += rowSize;
  34787. }
  34788. break;
  34789. case 2: // XOR
  34790. for (i = 0; i < height; i++) {
  34791. mask = mask0;
  34792. offset = offset0;
  34793. for (j = 0; j < width; j++) {
  34794. if (bitmap[i][j]) {
  34795. buffer[offset] ^= mask;
  34796. }
  34797. mask >>= 1;
  34798. if (!mask) {
  34799. mask = 128;
  34800. offset++;
  34801. }
  34802. }
  34803. offset0 += rowSize;
  34804. }
  34805. break;
  34806. default:
  34807. error('JBIG2 error: operator ' + combinationOperator +
  34808. ' is not supported');
  34809. }
  34810. },
  34811. onImmediateGenericRegion:
  34812. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  34813. start, end) {
  34814. var regionInfo = region.info;
  34815. var decodingContext = new DecodingContext(data, start, end);
  34816. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  34817. region.template, region.prediction, null,
  34818. region.at, decodingContext);
  34819. this.drawBitmap(regionInfo, bitmap);
  34820. },
  34821. onImmediateLosslessGenericRegion:
  34822. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  34823. this.onImmediateGenericRegion.apply(this, arguments);
  34824. },
  34825. onSymbolDictionary:
  34826. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  34827. currentSegment,
  34828. referredSegments,
  34829. data, start, end) {
  34830. var huffmanTables;
  34831. if (dictionary.huffman) {
  34832. error('JBIG2 error: huffman is not supported');
  34833. }
  34834. // Combines exported symbols from all referred segments
  34835. var symbols = this.symbols;
  34836. if (!symbols) {
  34837. this.symbols = symbols = {};
  34838. }
  34839. var inputSymbols = [];
  34840. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  34841. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  34842. }
  34843. var decodingContext = new DecodingContext(data, start, end);
  34844. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  34845. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  34846. dictionary.numberOfExportedSymbols, huffmanTables,
  34847. dictionary.template, dictionary.at,
  34848. dictionary.refinementTemplate, dictionary.refinementAt,
  34849. decodingContext);
  34850. },
  34851. onImmediateTextRegion:
  34852. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  34853. referredSegments,
  34854. data, start, end) {
  34855. var regionInfo = region.info;
  34856. var huffmanTables;
  34857. // Combines exported symbols from all referred segments
  34858. var symbols = this.symbols;
  34859. var inputSymbols = [];
  34860. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  34861. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  34862. }
  34863. var symbolCodeLength = log2(inputSymbols.length);
  34864. var decodingContext = new DecodingContext(data, start, end);
  34865. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  34866. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  34867. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  34868. symbolCodeLength, region.transposed, region.dsOffset,
  34869. region.referenceCorner, region.combinationOperator, huffmanTables,
  34870. region.refinementTemplate, region.refinementAt, decodingContext);
  34871. this.drawBitmap(regionInfo, bitmap);
  34872. },
  34873. onImmediateLosslessTextRegion:
  34874. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  34875. this.onImmediateTextRegion.apply(this, arguments);
  34876. }
  34877. };
  34878. function Jbig2Image() {}
  34879. Jbig2Image.prototype = {
  34880. parseChunks: function Jbig2Image_parseChunks(chunks) {
  34881. return parseJbig2Chunks(chunks);
  34882. }
  34883. };
  34884. return Jbig2Image;
  34885. })();
  34886. var bidi = PDFJS.bidi = (function bidiClosure() {
  34887. // Character types for symbols from 0000 to 00FF.
  34888. var baseTypes = [
  34889. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  34890. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  34891. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  34892. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  34893. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  34894. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34895. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  34896. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34897. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34898. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  34899. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  34900. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  34901. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  34902. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  34903. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34904. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34905. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34906. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34907. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  34908. ];
  34909. // Character types for symbols from 0600 to 06FF
  34910. var arabicTypes = [
  34911. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34912. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  34913. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34914. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34915. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34916. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34917. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  34918. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  34919. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  34920. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  34921. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34922. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34923. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34924. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34925. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34926. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34927. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34928. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34929. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  34930. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  34931. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34932. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  34933. ];
  34934. function isOdd(i) {
  34935. return (i & 1) !== 0;
  34936. }
  34937. function isEven(i) {
  34938. return (i & 1) === 0;
  34939. }
  34940. function findUnequal(arr, start, value) {
  34941. for (var j = start, jj = arr.length; j < jj; ++j) {
  34942. if (arr[j] !== value) {
  34943. return j;
  34944. }
  34945. }
  34946. return j;
  34947. }
  34948. function setValues(arr, start, end, value) {
  34949. for (var j = start; j < end; ++j) {
  34950. arr[j] = value;
  34951. }
  34952. }
  34953. function reverseValues(arr, start, end) {
  34954. for (var i = start, j = end - 1; i < j; ++i, --j) {
  34955. var temp = arr[i];
  34956. arr[i] = arr[j];
  34957. arr[j] = temp;
  34958. }
  34959. }
  34960. function createBidiText(str, isLTR, vertical) {
  34961. return {
  34962. str: str,
  34963. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  34964. };
  34965. }
  34966. // These are used in bidi(), which is called frequently. We re-use them on
  34967. // each call to avoid unnecessary allocations.
  34968. var chars = [];
  34969. var types = [];
  34970. function bidi(str, startLevel, vertical) {
  34971. var isLTR = true;
  34972. var strLength = str.length;
  34973. if (strLength === 0 || vertical) {
  34974. return createBidiText(str, isLTR, vertical);
  34975. }
  34976. // Get types and fill arrays
  34977. chars.length = strLength;
  34978. types.length = strLength;
  34979. var numBidi = 0;
  34980. var i, ii;
  34981. for (i = 0; i < strLength; ++i) {
  34982. chars[i] = str.charAt(i);
  34983. var charCode = str.charCodeAt(i);
  34984. var charType = 'L';
  34985. if (charCode <= 0x00ff) {
  34986. charType = baseTypes[charCode];
  34987. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  34988. charType = 'R';
  34989. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  34990. charType = arabicTypes[charCode & 0xff];
  34991. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  34992. charType = 'AL';
  34993. }
  34994. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  34995. numBidi++;
  34996. }
  34997. types[i] = charType;
  34998. }
  34999. // Detect the bidi method
  35000. // - If there are no rtl characters then no bidi needed
  35001. // - If less than 30% chars are rtl then string is primarily ltr
  35002. // - If more than 30% chars are rtl then string is primarily rtl
  35003. if (numBidi === 0) {
  35004. isLTR = true;
  35005. return createBidiText(str, isLTR);
  35006. }
  35007. if (startLevel === -1) {
  35008. if ((strLength / numBidi) < 0.3) {
  35009. isLTR = true;
  35010. startLevel = 0;
  35011. } else {
  35012. isLTR = false;
  35013. startLevel = 1;
  35014. }
  35015. }
  35016. var levels = [];
  35017. for (i = 0; i < strLength; ++i) {
  35018. levels[i] = startLevel;
  35019. }
  35020. /*
  35021. X1-X10: skip most of this, since we are NOT doing the embeddings.
  35022. */
  35023. var e = (isOdd(startLevel) ? 'R' : 'L');
  35024. var sor = e;
  35025. var eor = sor;
  35026. /*
  35027. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  35028. type of the NSM to the type of the previous character. If the NSM is at the
  35029. start of the level run, it will get the type of sor.
  35030. */
  35031. var lastType = sor;
  35032. for (i = 0; i < strLength; ++i) {
  35033. if (types[i] === 'NSM') {
  35034. types[i] = lastType;
  35035. } else {
  35036. lastType = types[i];
  35037. }
  35038. }
  35039. /*
  35040. W2. Search backwards from each instance of a European number until the
  35041. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  35042. the type of the European number to Arabic number.
  35043. */
  35044. lastType = sor;
  35045. var t;
  35046. for (i = 0; i < strLength; ++i) {
  35047. t = types[i];
  35048. if (t === 'EN') {
  35049. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  35050. } else if (t === 'R' || t === 'L' || t === 'AL') {
  35051. lastType = t;
  35052. }
  35053. }
  35054. /*
  35055. W3. Change all ALs to R.
  35056. */
  35057. for (i = 0; i < strLength; ++i) {
  35058. t = types[i];
  35059. if (t === 'AL') {
  35060. types[i] = 'R';
  35061. }
  35062. }
  35063. /*
  35064. W4. A single European separator between two European numbers changes to a
  35065. European number. A single common separator between two numbers of the same
  35066. type changes to that type:
  35067. */
  35068. for (i = 1; i < strLength - 1; ++i) {
  35069. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  35070. types[i] = 'EN';
  35071. }
  35072. if (types[i] === 'CS' &&
  35073. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  35074. types[i + 1] === types[i - 1]) {
  35075. types[i] = types[i - 1];
  35076. }
  35077. }
  35078. /*
  35079. W5. A sequence of European terminators adjacent to European numbers changes
  35080. to all European numbers:
  35081. */
  35082. for (i = 0; i < strLength; ++i) {
  35083. if (types[i] === 'EN') {
  35084. // do before
  35085. var j;
  35086. for (j = i - 1; j >= 0; --j) {
  35087. if (types[j] !== 'ET') {
  35088. break;
  35089. }
  35090. types[j] = 'EN';
  35091. }
  35092. // do after
  35093. for (j = i + 1; j < strLength; --j) {
  35094. if (types[j] !== 'ET') {
  35095. break;
  35096. }
  35097. types[j] = 'EN';
  35098. }
  35099. }
  35100. }
  35101. /*
  35102. W6. Otherwise, separators and terminators change to Other Neutral:
  35103. */
  35104. for (i = 0; i < strLength; ++i) {
  35105. t = types[i];
  35106. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  35107. types[i] = 'ON';
  35108. }
  35109. }
  35110. /*
  35111. W7. Search backwards from each instance of a European number until the
  35112. first strong type (R, L, or sor) is found. If an L is found, then change
  35113. the type of the European number to L.
  35114. */
  35115. lastType = sor;
  35116. for (i = 0; i < strLength; ++i) {
  35117. t = types[i];
  35118. if (t === 'EN') {
  35119. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  35120. } else if (t === 'R' || t === 'L') {
  35121. lastType = t;
  35122. }
  35123. }
  35124. /*
  35125. N1. A sequence of neutrals takes the direction of the surrounding strong
  35126. text if the text on both sides has the same direction. European and Arabic
  35127. numbers are treated as though they were R. Start-of-level-run (sor) and
  35128. end-of-level-run (eor) are used at level run boundaries.
  35129. */
  35130. for (i = 0; i < strLength; ++i) {
  35131. if (types[i] === 'ON') {
  35132. var end = findUnequal(types, i + 1, 'ON');
  35133. var before = sor;
  35134. if (i > 0) {
  35135. before = types[i - 1];
  35136. }
  35137. var after = eor;
  35138. if (end + 1 < strLength) {
  35139. after = types[end + 1];
  35140. }
  35141. if (before !== 'L') {
  35142. before = 'R';
  35143. }
  35144. if (after !== 'L') {
  35145. after = 'R';
  35146. }
  35147. if (before === after) {
  35148. setValues(types, i, end, before);
  35149. }
  35150. i = end - 1; // reset to end (-1 so next iteration is ok)
  35151. }
  35152. }
  35153. /*
  35154. N2. Any remaining neutrals take the embedding direction.
  35155. */
  35156. for (i = 0; i < strLength; ++i) {
  35157. if (types[i] === 'ON') {
  35158. types[i] = e;
  35159. }
  35160. }
  35161. /*
  35162. I1. For all characters with an even (left-to-right) embedding direction,
  35163. those of type R go up one level and those of type AN or EN go up two
  35164. levels.
  35165. I2. For all characters with an odd (right-to-left) embedding direction,
  35166. those of type L, EN or AN go up one level.
  35167. */
  35168. for (i = 0; i < strLength; ++i) {
  35169. t = types[i];
  35170. if (isEven(levels[i])) {
  35171. if (t === 'R') {
  35172. levels[i] += 1;
  35173. } else if (t === 'AN' || t === 'EN') {
  35174. levels[i] += 2;
  35175. }
  35176. } else { // isOdd
  35177. if (t === 'L' || t === 'AN' || t === 'EN') {
  35178. levels[i] += 1;
  35179. }
  35180. }
  35181. }
  35182. /*
  35183. L1. On each line, reset the embedding level of the following characters to
  35184. the paragraph embedding level:
  35185. segment separators,
  35186. paragraph separators,
  35187. any sequence of whitespace characters preceding a segment separator or
  35188. paragraph separator, and any sequence of white space characters at the end
  35189. of the line.
  35190. */
  35191. // don't bother as text is only single line
  35192. /*
  35193. L2. From the highest level found in the text to the lowest odd level on
  35194. each line, reverse any contiguous sequence of characters that are at that
  35195. level or higher.
  35196. */
  35197. // find highest level & lowest odd level
  35198. var highestLevel = -1;
  35199. var lowestOddLevel = 99;
  35200. var level;
  35201. for (i = 0, ii = levels.length; i < ii; ++i) {
  35202. level = levels[i];
  35203. if (highestLevel < level) {
  35204. highestLevel = level;
  35205. }
  35206. if (lowestOddLevel > level && isOdd(level)) {
  35207. lowestOddLevel = level;
  35208. }
  35209. }
  35210. // now reverse between those limits
  35211. for (level = highestLevel; level >= lowestOddLevel; --level) {
  35212. // find segments to reverse
  35213. var start = -1;
  35214. for (i = 0, ii = levels.length; i < ii; ++i) {
  35215. if (levels[i] < level) {
  35216. if (start >= 0) {
  35217. reverseValues(chars, start, i);
  35218. start = -1;
  35219. }
  35220. } else if (start < 0) {
  35221. start = i;
  35222. }
  35223. }
  35224. if (start >= 0) {
  35225. reverseValues(chars, start, levels.length);
  35226. }
  35227. }
  35228. /*
  35229. L3. Combining marks applied to a right-to-left base character will at this
  35230. point precede their base character. If the rendering engine expects them to
  35231. follow the base characters in the final display process, then the ordering
  35232. of the marks and the base character must be reversed.
  35233. */
  35234. // don't bother for now
  35235. /*
  35236. L4. A character that possesses the mirrored property as specified by
  35237. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  35238. directionality of that character is R.
  35239. */
  35240. // don't mirror as characters are already mirrored in the pdf
  35241. // Finally, return string
  35242. var result = '';
  35243. for (i = 0, ii = chars.length; i < ii; ++i) {
  35244. var ch = chars[i];
  35245. if (ch !== '<' && ch !== '>') {
  35246. result += ch;
  35247. }
  35248. }
  35249. return createBidiText(result, isLTR);
  35250. }
  35251. return bidi;
  35252. })();
  35253. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  35254. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  35255. /* Copyright 2014 Opera Software ASA
  35256. *
  35257. * Licensed under the Apache License, Version 2.0 (the "License");
  35258. * you may not use this file except in compliance with the License.
  35259. * You may obtain a copy of the License at
  35260. *
  35261. * http://www.apache.org/licenses/LICENSE-2.0
  35262. *
  35263. * Unless required by applicable law or agreed to in writing, software
  35264. * distributed under the License is distributed on an "AS IS" BASIS,
  35265. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  35266. * See the License for the specific language governing permissions and
  35267. * limitations under the License.
  35268. *
  35269. *
  35270. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  35271. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  35272. */
  35273. /* globals Uint32ArrayView */
  35274. 'use strict';
  35275. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  35276. // Workaround for missing math precison in JS.
  35277. var MASK_HIGH = 0xffff0000;
  35278. var MASK_LOW = 0xffff;
  35279. function MurmurHash3_64 (seed) {
  35280. var SEED = 0xc3d2e1f0;
  35281. this.h1 = seed ? seed & 0xffffffff : SEED;
  35282. this.h2 = seed ? seed & 0xffffffff : SEED;
  35283. }
  35284. var alwaysUseUint32ArrayView = false;
  35285. // old webkits have issues with non-aligned arrays
  35286. try {
  35287. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  35288. } catch (e) {
  35289. alwaysUseUint32ArrayView = true;
  35290. }
  35291. MurmurHash3_64.prototype = {
  35292. update: function MurmurHash3_64_update(input) {
  35293. var useUint32ArrayView = alwaysUseUint32ArrayView;
  35294. var i;
  35295. if (typeof input === 'string') {
  35296. var data = new Uint8Array(input.length * 2);
  35297. var length = 0;
  35298. for (i = 0; i < input.length; i++) {
  35299. var code = input.charCodeAt(i);
  35300. if (code <= 0xff) {
  35301. data[length++] = code;
  35302. }
  35303. else {
  35304. data[length++] = code >>> 8;
  35305. data[length++] = code & 0xff;
  35306. }
  35307. }
  35308. } else if (input instanceof Uint8Array) {
  35309. data = input;
  35310. length = data.length;
  35311. } else if (typeof input === 'object' && ('length' in input)) {
  35312. // processing regular arrays as well, e.g. for IE9
  35313. data = input;
  35314. length = data.length;
  35315. useUint32ArrayView = true;
  35316. } else {
  35317. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  35318. 'Input must be a string or array.');
  35319. }
  35320. var blockCounts = length >> 2;
  35321. var tailLength = length - blockCounts * 4;
  35322. // we don't care about endianness here
  35323. var dataUint32 = useUint32ArrayView ?
  35324. new Uint32ArrayView(data, blockCounts) :
  35325. new Uint32Array(data.buffer, 0, blockCounts);
  35326. var k1 = 0;
  35327. var k2 = 0;
  35328. var h1 = this.h1;
  35329. var h2 = this.h2;
  35330. var C1 = 0xcc9e2d51;
  35331. var C2 = 0x1b873593;
  35332. var C1_LOW = C1 & MASK_LOW;
  35333. var C2_LOW = C2 & MASK_LOW;
  35334. for (i = 0; i < blockCounts; i++) {
  35335. if (i & 1) {
  35336. k1 = dataUint32[i];
  35337. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  35338. k1 = k1 << 15 | k1 >>> 17;
  35339. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  35340. h1 ^= k1;
  35341. h1 = h1 << 13 | h1 >>> 19;
  35342. h1 = h1 * 5 + 0xe6546b64;
  35343. } else {
  35344. k2 = dataUint32[i];
  35345. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  35346. k2 = k2 << 15 | k2 >>> 17;
  35347. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  35348. h2 ^= k2;
  35349. h2 = h2 << 13 | h2 >>> 19;
  35350. h2 = h2 * 5 + 0xe6546b64;
  35351. }
  35352. }
  35353. k1 = 0;
  35354. switch (tailLength) {
  35355. case 3:
  35356. k1 ^= data[blockCounts * 4 + 2] << 16;
  35357. /* falls through */
  35358. case 2:
  35359. k1 ^= data[blockCounts * 4 + 1] << 8;
  35360. /* falls through */
  35361. case 1:
  35362. k1 ^= data[blockCounts * 4];
  35363. /* falls through */
  35364. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  35365. k1 = k1 << 15 | k1 >>> 17;
  35366. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  35367. if (blockCounts & 1) {
  35368. h1 ^= k1;
  35369. } else {
  35370. h2 ^= k1;
  35371. }
  35372. }
  35373. this.h1 = h1;
  35374. this.h2 = h2;
  35375. return this;
  35376. },
  35377. hexdigest: function MurmurHash3_64_hexdigest () {
  35378. var h1 = this.h1;
  35379. var h2 = this.h2;
  35380. h1 ^= h2 >>> 1;
  35381. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  35382. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  35383. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  35384. h1 ^= h2 >>> 1;
  35385. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  35386. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  35387. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  35388. h1 ^= h2 >>> 1;
  35389. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  35390. var hex = (arr[i] >>> 0).toString(16);
  35391. while (hex.length < 8) {
  35392. hex = '0' + hex;
  35393. }
  35394. str += hex;
  35395. }
  35396. return str;
  35397. }
  35398. };
  35399. return MurmurHash3_64;
  35400. })();
  35401. }).call((typeof window === 'undefined') ? this : window);
  35402. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  35403. // workerSrc is not set -- using last script url to define default location
  35404. PDFJS.workerSrc = (function () {
  35405. 'use strict';
  35406. var scriptTagContainer = document.body ||
  35407. document.getElementsByTagName('head')[0];
  35408. var pdfjsSrc = scriptTagContainer.lastChild.src;
  35409. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  35410. })();
  35411. }