pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240
  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.1149';
  24. PDFJS.build = 'bc7a110';
  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. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. PDFJS.shadow = shadow;
  333. var PasswordResponses = PDFJS.PasswordResponses = {
  334. NEED_PASSWORD: 1,
  335. INCORRECT_PASSWORD: 2
  336. };
  337. var PasswordException = (function PasswordExceptionClosure() {
  338. function PasswordException(msg, code) {
  339. this.name = 'PasswordException';
  340. this.message = msg;
  341. this.code = code;
  342. }
  343. PasswordException.prototype = new Error();
  344. PasswordException.constructor = PasswordException;
  345. return PasswordException;
  346. })();
  347. PDFJS.PasswordException = PasswordException;
  348. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  349. function UnknownErrorException(msg, details) {
  350. this.name = 'UnknownErrorException';
  351. this.message = msg;
  352. this.details = details;
  353. }
  354. UnknownErrorException.prototype = new Error();
  355. UnknownErrorException.constructor = UnknownErrorException;
  356. return UnknownErrorException;
  357. })();
  358. PDFJS.UnknownErrorException = UnknownErrorException;
  359. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  360. function InvalidPDFException(msg) {
  361. this.name = 'InvalidPDFException';
  362. this.message = msg;
  363. }
  364. InvalidPDFException.prototype = new Error();
  365. InvalidPDFException.constructor = InvalidPDFException;
  366. return InvalidPDFException;
  367. })();
  368. PDFJS.InvalidPDFException = InvalidPDFException;
  369. var MissingPDFException = (function MissingPDFExceptionClosure() {
  370. function MissingPDFException(msg) {
  371. this.name = 'MissingPDFException';
  372. this.message = msg;
  373. }
  374. MissingPDFException.prototype = new Error();
  375. MissingPDFException.constructor = MissingPDFException;
  376. return MissingPDFException;
  377. })();
  378. PDFJS.MissingPDFException = MissingPDFException;
  379. var UnexpectedResponseException =
  380. (function UnexpectedResponseExceptionClosure() {
  381. function UnexpectedResponseException(msg, status) {
  382. this.name = 'UnexpectedResponseException';
  383. this.message = msg;
  384. this.status = status;
  385. }
  386. UnexpectedResponseException.prototype = new Error();
  387. UnexpectedResponseException.constructor = UnexpectedResponseException;
  388. return UnexpectedResponseException;
  389. })();
  390. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  391. var NotImplementedException = (function NotImplementedExceptionClosure() {
  392. function NotImplementedException(msg) {
  393. this.message = msg;
  394. }
  395. NotImplementedException.prototype = new Error();
  396. NotImplementedException.prototype.name = 'NotImplementedException';
  397. NotImplementedException.constructor = NotImplementedException;
  398. return NotImplementedException;
  399. })();
  400. var MissingDataException = (function MissingDataExceptionClosure() {
  401. function MissingDataException(begin, end) {
  402. this.begin = begin;
  403. this.end = end;
  404. this.message = 'Missing data [' + begin + ', ' + end + ')';
  405. }
  406. MissingDataException.prototype = new Error();
  407. MissingDataException.prototype.name = 'MissingDataException';
  408. MissingDataException.constructor = MissingDataException;
  409. return MissingDataException;
  410. })();
  411. var XRefParseException = (function XRefParseExceptionClosure() {
  412. function XRefParseException(msg) {
  413. this.message = msg;
  414. }
  415. XRefParseException.prototype = new Error();
  416. XRefParseException.prototype.name = 'XRefParseException';
  417. XRefParseException.constructor = XRefParseException;
  418. return XRefParseException;
  419. })();
  420. function bytesToString(bytes) {
  421. assert(bytes !== null && typeof bytes === 'object' &&
  422. bytes.length !== undefined, 'Invalid argument for bytesToString');
  423. var length = bytes.length;
  424. var MAX_ARGUMENT_COUNT = 8192;
  425. if (length < MAX_ARGUMENT_COUNT) {
  426. return String.fromCharCode.apply(null, bytes);
  427. }
  428. var strBuf = [];
  429. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  430. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  431. var chunk = bytes.subarray(i, chunkEnd);
  432. strBuf.push(String.fromCharCode.apply(null, chunk));
  433. }
  434. return strBuf.join('');
  435. }
  436. function stringToBytes(str) {
  437. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  438. var length = str.length;
  439. var bytes = new Uint8Array(length);
  440. for (var i = 0; i < length; ++i) {
  441. bytes[i] = str.charCodeAt(i) & 0xFF;
  442. }
  443. return bytes;
  444. }
  445. function string32(value) {
  446. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  447. (value >> 8) & 0xff, value & 0xff);
  448. }
  449. function log2(x) {
  450. var n = 1, i = 0;
  451. while (x > n) {
  452. n <<= 1;
  453. i++;
  454. }
  455. return i;
  456. }
  457. function readInt8(data, start) {
  458. return (data[start] << 24) >> 24;
  459. }
  460. function readUint16(data, offset) {
  461. return (data[offset] << 8) | data[offset + 1];
  462. }
  463. function readUint32(data, offset) {
  464. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  465. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  466. }
  467. // Lazy test the endianness of the platform
  468. // NOTE: This will be 'true' for simulated TypedArrays
  469. function isLittleEndian() {
  470. var buffer8 = new Uint8Array(2);
  471. buffer8[0] = 1;
  472. var buffer16 = new Uint16Array(buffer8.buffer);
  473. return (buffer16[0] === 1);
  474. }
  475. Object.defineProperty(PDFJS, 'isLittleEndian', {
  476. configurable: true,
  477. get: function PDFJS_isLittleEndian() {
  478. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  479. }
  480. });
  481. // Lazy test if the userAgant support CanvasTypedArrays
  482. function hasCanvasTypedArrays() {
  483. var canvas = document.createElement('canvas');
  484. canvas.width = canvas.height = 1;
  485. var ctx = canvas.getContext('2d');
  486. var imageData = ctx.createImageData(1, 1);
  487. return (typeof imageData.data.buffer !== 'undefined');
  488. }
  489. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  490. configurable: true,
  491. get: function PDFJS_hasCanvasTypedArrays() {
  492. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  493. }
  494. });
  495. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  496. function Uint32ArrayView(buffer, length) {
  497. this.buffer = buffer;
  498. this.byteLength = buffer.length;
  499. this.length = length === undefined ? (this.byteLength >> 2) : length;
  500. ensureUint32ArrayViewProps(this.length);
  501. }
  502. Uint32ArrayView.prototype = Object.create(null);
  503. var uint32ArrayViewSetters = 0;
  504. function createUint32ArrayProp(index) {
  505. return {
  506. get: function () {
  507. var buffer = this.buffer, offset = index << 2;
  508. return (buffer[offset] | (buffer[offset + 1] << 8) |
  509. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  510. },
  511. set: function (value) {
  512. var buffer = this.buffer, offset = index << 2;
  513. buffer[offset] = value & 255;
  514. buffer[offset + 1] = (value >> 8) & 255;
  515. buffer[offset + 2] = (value >> 16) & 255;
  516. buffer[offset + 3] = (value >>> 24) & 255;
  517. }
  518. };
  519. }
  520. function ensureUint32ArrayViewProps(length) {
  521. while (uint32ArrayViewSetters < length) {
  522. Object.defineProperty(Uint32ArrayView.prototype,
  523. uint32ArrayViewSetters,
  524. createUint32ArrayProp(uint32ArrayViewSetters));
  525. uint32ArrayViewSetters++;
  526. }
  527. }
  528. return Uint32ArrayView;
  529. })();
  530. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  531. var Util = PDFJS.Util = (function UtilClosure() {
  532. function Util() {}
  533. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  534. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  535. // creating many intermediate strings.
  536. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  537. rgbBuf[1] = r;
  538. rgbBuf[3] = g;
  539. rgbBuf[5] = b;
  540. return rgbBuf.join('');
  541. };
  542. // Concatenates two transformation matrices together and returns the result.
  543. Util.transform = function Util_transform(m1, m2) {
  544. return [
  545. m1[0] * m2[0] + m1[2] * m2[1],
  546. m1[1] * m2[0] + m1[3] * m2[1],
  547. m1[0] * m2[2] + m1[2] * m2[3],
  548. m1[1] * m2[2] + m1[3] * m2[3],
  549. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  550. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  551. ];
  552. };
  553. // For 2d affine transforms
  554. Util.applyTransform = function Util_applyTransform(p, m) {
  555. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  556. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  557. return [xt, yt];
  558. };
  559. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  562. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  563. return [xt, yt];
  564. };
  565. // Applies the transform to the rectangle and finds the minimum axially
  566. // aligned bounding box.
  567. Util.getAxialAlignedBoundingBox =
  568. function Util_getAxialAlignedBoundingBox(r, m) {
  569. var p1 = Util.applyTransform(r, m);
  570. var p2 = Util.applyTransform(r.slice(2, 4), m);
  571. var p3 = Util.applyTransform([r[0], r[3]], m);
  572. var p4 = Util.applyTransform([r[2], r[1]], m);
  573. return [
  574. Math.min(p1[0], p2[0], p3[0], p4[0]),
  575. Math.min(p1[1], p2[1], p3[1], p4[1]),
  576. Math.max(p1[0], p2[0], p3[0], p4[0]),
  577. Math.max(p1[1], p2[1], p3[1], p4[1])
  578. ];
  579. };
  580. Util.inverseTransform = function Util_inverseTransform(m) {
  581. var d = m[0] * m[3] - m[1] * m[2];
  582. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  583. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  584. };
  585. // Apply a generic 3d matrix M on a 3-vector v:
  586. // | a b c | | X |
  587. // | d e f | x | Y |
  588. // | g h i | | Z |
  589. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  590. // with v as [X,Y,Z]
  591. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  592. return [
  593. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  594. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  595. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  596. ];
  597. };
  598. // This calculation uses Singular Value Decomposition.
  599. // The SVD can be represented with formula A = USV. We are interested in the
  600. // matrix S here because it represents the scale values.
  601. Util.singularValueDecompose2dScale =
  602. function Util_singularValueDecompose2dScale(m) {
  603. var transpose = [m[0], m[2], m[1], m[3]];
  604. // Multiply matrix m with its transpose.
  605. var a = m[0] * transpose[0] + m[1] * transpose[2];
  606. var b = m[0] * transpose[1] + m[1] * transpose[3];
  607. var c = m[2] * transpose[0] + m[3] * transpose[2];
  608. var d = m[2] * transpose[1] + m[3] * transpose[3];
  609. // Solve the second degree polynomial to get roots.
  610. var first = (a + d) / 2;
  611. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  612. var sx = first + second || 1;
  613. var sy = first - second || 1;
  614. // Scale values are the square roots of the eigenvalues.
  615. return [Math.sqrt(sx), Math.sqrt(sy)];
  616. };
  617. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  618. // For coordinate systems whose origin lies in the bottom-left, this
  619. // means normalization to (BL,TR) ordering. For systems with origin in the
  620. // top-left, this means (TL,BR) ordering.
  621. Util.normalizeRect = function Util_normalizeRect(rect) {
  622. var r = rect.slice(0); // clone rect
  623. if (rect[0] > rect[2]) {
  624. r[0] = rect[2];
  625. r[2] = rect[0];
  626. }
  627. if (rect[1] > rect[3]) {
  628. r[1] = rect[3];
  629. r[3] = rect[1];
  630. }
  631. return r;
  632. };
  633. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  634. // intersection of rect1 and rect2. If no intersection, returns 'false'
  635. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  636. Util.intersect = function Util_intersect(rect1, rect2) {
  637. function compare(a, b) {
  638. return a - b;
  639. }
  640. // Order points along the axes
  641. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  642. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  643. result = [];
  644. rect1 = Util.normalizeRect(rect1);
  645. rect2 = Util.normalizeRect(rect2);
  646. // X: first and second points belong to different rectangles?
  647. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  648. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  649. // Intersection must be between second and third points
  650. result[0] = orderedX[1];
  651. result[2] = orderedX[2];
  652. } else {
  653. return false;
  654. }
  655. // Y: first and second points belong to different rectangles?
  656. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  657. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  658. // Intersection must be between second and third points
  659. result[1] = orderedY[1];
  660. result[3] = orderedY[2];
  661. } else {
  662. return false;
  663. }
  664. return result;
  665. };
  666. Util.sign = function Util_sign(num) {
  667. return num < 0 ? -1 : 1;
  668. };
  669. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  670. Array.prototype.push.apply(arr1, arr2);
  671. };
  672. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  673. Array.prototype.unshift.apply(arr1, arr2);
  674. };
  675. Util.extendObj = function extendObj(obj1, obj2) {
  676. for (var key in obj2) {
  677. obj1[key] = obj2[key];
  678. }
  679. };
  680. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  681. name) {
  682. while (dict && !dict.has(name)) {
  683. dict = dict.get('Parent');
  684. }
  685. if (!dict) {
  686. return null;
  687. }
  688. return dict.get(name);
  689. };
  690. Util.inherit = function Util_inherit(sub, base, prototype) {
  691. sub.prototype = Object.create(base.prototype);
  692. sub.prototype.constructor = sub;
  693. for (var prop in prototype) {
  694. sub.prototype[prop] = prototype[prop];
  695. }
  696. };
  697. Util.loadScript = function Util_loadScript(src, callback) {
  698. var script = document.createElement('script');
  699. var loaded = false;
  700. script.setAttribute('src', src);
  701. if (callback) {
  702. script.onload = function() {
  703. if (!loaded) {
  704. callback();
  705. }
  706. loaded = true;
  707. };
  708. }
  709. document.getElementsByTagName('head')[0].appendChild(script);
  710. };
  711. return Util;
  712. })();
  713. /**
  714. * PDF page viewport created based on scale, rotation and offset.
  715. * @class
  716. * @alias PDFJS.PageViewport
  717. */
  718. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  719. /**
  720. * @constructor
  721. * @private
  722. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  723. * @param scale {number} scale of the viewport.
  724. * @param rotation {number} rotations of the viewport in degrees.
  725. * @param offsetX {number} offset X
  726. * @param offsetY {number} offset Y
  727. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  728. */
  729. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  730. this.viewBox = viewBox;
  731. this.scale = scale;
  732. this.rotation = rotation;
  733. this.offsetX = offsetX;
  734. this.offsetY = offsetY;
  735. // creating transform to convert pdf coordinate system to the normal
  736. // canvas like coordinates taking in account scale and rotation
  737. var centerX = (viewBox[2] + viewBox[0]) / 2;
  738. var centerY = (viewBox[3] + viewBox[1]) / 2;
  739. var rotateA, rotateB, rotateC, rotateD;
  740. rotation = rotation % 360;
  741. rotation = rotation < 0 ? rotation + 360 : rotation;
  742. switch (rotation) {
  743. case 180:
  744. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  745. break;
  746. case 90:
  747. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  748. break;
  749. case 270:
  750. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  751. break;
  752. //case 0:
  753. default:
  754. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  755. break;
  756. }
  757. if (dontFlip) {
  758. rotateC = -rotateC; rotateD = -rotateD;
  759. }
  760. var offsetCanvasX, offsetCanvasY;
  761. var width, height;
  762. if (rotateA === 0) {
  763. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  765. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  766. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  767. } else {
  768. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  769. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  770. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  771. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  772. }
  773. // creating transform for the following operations:
  774. // translate(-centerX, -centerY), rotate and flip vertically,
  775. // scale, and translate(offsetCanvasX, offsetCanvasY)
  776. this.transform = [
  777. rotateA * scale,
  778. rotateB * scale,
  779. rotateC * scale,
  780. rotateD * scale,
  781. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  782. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  783. ];
  784. this.width = width;
  785. this.height = height;
  786. this.fontScale = scale;
  787. }
  788. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  789. /**
  790. * Clones viewport with additional properties.
  791. * @param args {Object} (optional) If specified, may contain the 'scale' or
  792. * 'rotation' properties to override the corresponding properties in
  793. * the cloned viewport.
  794. * @returns {PDFJS.PageViewport} Cloned viewport.
  795. */
  796. clone: function PageViewPort_clone(args) {
  797. args = args || {};
  798. var scale = 'scale' in args ? args.scale : this.scale;
  799. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  800. return new PageViewport(this.viewBox.slice(), scale, rotation,
  801. this.offsetX, this.offsetY, args.dontFlip);
  802. },
  803. /**
  804. * Converts PDF point to the viewport coordinates. For examples, useful for
  805. * converting PDF location into canvas pixel coordinates.
  806. * @param x {number} X coordinate.
  807. * @param y {number} Y coordinate.
  808. * @returns {Object} Object that contains 'x' and 'y' properties of the
  809. * point in the viewport coordinate space.
  810. * @see {@link convertToPdfPoint}
  811. * @see {@link convertToViewportRectangle}
  812. */
  813. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  814. return Util.applyTransform([x, y], this.transform);
  815. },
  816. /**
  817. * Converts PDF rectangle to the viewport coordinates.
  818. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  819. * @returns {Array} Contains corresponding coordinates of the rectangle
  820. * in the viewport coordinate space.
  821. * @see {@link convertToViewportPoint}
  822. */
  823. convertToViewportRectangle:
  824. function PageViewport_convertToViewportRectangle(rect) {
  825. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  826. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  827. return [tl[0], tl[1], br[0], br[1]];
  828. },
  829. /**
  830. * Converts viewport coordinates to the PDF location. For examples, useful
  831. * for converting canvas pixel location into PDF one.
  832. * @param x {number} X coordinate.
  833. * @param y {number} Y coordinate.
  834. * @returns {Object} Object that contains 'x' and 'y' properties of the
  835. * point in the PDF coordinate space.
  836. * @see {@link convertToViewportPoint}
  837. */
  838. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  839. return Util.applyInverseTransform([x, y], this.transform);
  840. }
  841. };
  842. return PageViewport;
  843. })();
  844. var PDFStringTranslateTable = [
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  846. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  847. 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,
  848. 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,
  849. 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,
  850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  851. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  852. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  853. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  854. ];
  855. function stringToPDFString(str) {
  856. var i, n = str.length, strBuf = [];
  857. if (str[0] === '\xFE' && str[1] === '\xFF') {
  858. // UTF16BE BOM
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(
  861. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  862. }
  863. } else {
  864. for (i = 0; i < n; ++i) {
  865. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  866. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  867. }
  868. }
  869. return strBuf.join('');
  870. }
  871. function stringToUTF8String(str) {
  872. return decodeURIComponent(escape(str));
  873. }
  874. function isEmptyObj(obj) {
  875. for (var key in obj) {
  876. return false;
  877. }
  878. return true;
  879. }
  880. function isBool(v) {
  881. return typeof v === 'boolean';
  882. }
  883. function isInt(v) {
  884. return typeof v === 'number' && ((v | 0) === v);
  885. }
  886. function isNum(v) {
  887. return typeof v === 'number';
  888. }
  889. function isString(v) {
  890. return typeof v === 'string';
  891. }
  892. function isNull(v) {
  893. return v === null;
  894. }
  895. function isName(v) {
  896. return v instanceof Name;
  897. }
  898. function isCmd(v, cmd) {
  899. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  900. }
  901. function isDict(v, type) {
  902. if (!(v instanceof Dict)) {
  903. return false;
  904. }
  905. if (!type) {
  906. return true;
  907. }
  908. var dictType = v.get('Type');
  909. return isName(dictType) && dictType.name === type;
  910. }
  911. function isArray(v) {
  912. return v instanceof Array;
  913. }
  914. function isStream(v) {
  915. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  916. }
  917. function isArrayBuffer(v) {
  918. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  919. }
  920. function isRef(v) {
  921. return v instanceof Ref;
  922. }
  923. /**
  924. * Promise Capability object.
  925. *
  926. * @typedef {Object} PromiseCapability
  927. * @property {Promise} promise - A promise object.
  928. * @property {function} resolve - Fullfills the promise.
  929. * @property {function} reject - Rejects the promise.
  930. */
  931. /**
  932. * Creates a promise capability object.
  933. * @alias PDFJS.createPromiseCapability
  934. *
  935. * @return {PromiseCapability} A capability object contains:
  936. * - a Promise, resolve and reject methods.
  937. */
  938. function createPromiseCapability() {
  939. var capability = {};
  940. capability.promise = new Promise(function (resolve, reject) {
  941. capability.resolve = resolve;
  942. capability.reject = reject;
  943. });
  944. return capability;
  945. }
  946. PDFJS.createPromiseCapability = createPromiseCapability;
  947. /**
  948. * Polyfill for Promises:
  949. * The following promise implementation tries to generally implement the
  950. * Promise/A+ spec. Some notable differences from other promise libaries are:
  951. * - There currently isn't a seperate deferred and promise object.
  952. * - Unhandled rejections eventually show an error if they aren't handled.
  953. *
  954. * Based off of the work in:
  955. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  956. */
  957. (function PromiseClosure() {
  958. if (globalScope.Promise) {
  959. // Promises existing in the DOM/Worker, checking presence of all/resolve
  960. if (typeof globalScope.Promise.all !== 'function') {
  961. globalScope.Promise.all = function (iterable) {
  962. var count = 0, results = [], resolve, reject;
  963. var promise = new globalScope.Promise(function (resolve_, reject_) {
  964. resolve = resolve_;
  965. reject = reject_;
  966. });
  967. iterable.forEach(function (p, i) {
  968. count++;
  969. p.then(function (result) {
  970. results[i] = result;
  971. count--;
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. }, reject);
  976. });
  977. if (count === 0) {
  978. resolve(results);
  979. }
  980. return promise;
  981. };
  982. }
  983. if (typeof globalScope.Promise.resolve !== 'function') {
  984. globalScope.Promise.resolve = function (value) {
  985. return new globalScope.Promise(function (resolve) { resolve(value); });
  986. };
  987. }
  988. if (typeof globalScope.Promise.reject !== 'function') {
  989. globalScope.Promise.reject = function (reason) {
  990. return new globalScope.Promise(function (resolve, reject) {
  991. reject(reason);
  992. });
  993. };
  994. }
  995. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  996. globalScope.Promise.prototype.catch = function (onReject) {
  997. return globalScope.Promise.prototype.then(undefined, onReject);
  998. };
  999. }
  1000. return;
  1001. }
  1002. var STATUS_PENDING = 0;
  1003. var STATUS_RESOLVED = 1;
  1004. var STATUS_REJECTED = 2;
  1005. // In an attempt to avoid silent exceptions, unhandled rejections are
  1006. // tracked and if they aren't handled in a certain amount of time an
  1007. // error is logged.
  1008. var REJECTION_TIMEOUT = 500;
  1009. var HandlerManager = {
  1010. handlers: [],
  1011. running: false,
  1012. unhandledRejections: [],
  1013. pendingRejectionCheck: false,
  1014. scheduleHandlers: function scheduleHandlers(promise) {
  1015. if (promise._status === STATUS_PENDING) {
  1016. return;
  1017. }
  1018. this.handlers = this.handlers.concat(promise._handlers);
  1019. promise._handlers = [];
  1020. if (this.running) {
  1021. return;
  1022. }
  1023. this.running = true;
  1024. setTimeout(this.runHandlers.bind(this), 0);
  1025. },
  1026. runHandlers: function runHandlers() {
  1027. var RUN_TIMEOUT = 1; // ms
  1028. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1029. while (this.handlers.length > 0) {
  1030. var handler = this.handlers.shift();
  1031. var nextStatus = handler.thisPromise._status;
  1032. var nextValue = handler.thisPromise._value;
  1033. try {
  1034. if (nextStatus === STATUS_RESOLVED) {
  1035. if (typeof handler.onResolve === 'function') {
  1036. nextValue = handler.onResolve(nextValue);
  1037. }
  1038. } else if (typeof handler.onReject === 'function') {
  1039. nextValue = handler.onReject(nextValue);
  1040. nextStatus = STATUS_RESOLVED;
  1041. if (handler.thisPromise._unhandledRejection) {
  1042. this.removeUnhandeledRejection(handler.thisPromise);
  1043. }
  1044. }
  1045. } catch (ex) {
  1046. nextStatus = STATUS_REJECTED;
  1047. nextValue = ex;
  1048. }
  1049. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1050. if (Date.now() >= timeoutAt) {
  1051. break;
  1052. }
  1053. }
  1054. if (this.handlers.length > 0) {
  1055. setTimeout(this.runHandlers.bind(this), 0);
  1056. return;
  1057. }
  1058. this.running = false;
  1059. },
  1060. addUnhandledRejection: function addUnhandledRejection(promise) {
  1061. this.unhandledRejections.push({
  1062. promise: promise,
  1063. time: Date.now()
  1064. });
  1065. this.scheduleRejectionCheck();
  1066. },
  1067. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1068. promise._unhandledRejection = false;
  1069. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1070. if (this.unhandledRejections[i].promise === promise) {
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. },
  1076. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1077. if (this.pendingRejectionCheck) {
  1078. return;
  1079. }
  1080. this.pendingRejectionCheck = true;
  1081. setTimeout(function rejectionCheck() {
  1082. this.pendingRejectionCheck = false;
  1083. var now = Date.now();
  1084. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1085. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1086. var unhandled = this.unhandledRejections[i].promise._value;
  1087. var msg = 'Unhandled rejection: ' + unhandled;
  1088. if (unhandled.stack) {
  1089. msg += '\n' + unhandled.stack;
  1090. }
  1091. warn(msg);
  1092. this.unhandledRejections.splice(i);
  1093. i--;
  1094. }
  1095. }
  1096. if (this.unhandledRejections.length) {
  1097. this.scheduleRejectionCheck();
  1098. }
  1099. }.bind(this), REJECTION_TIMEOUT);
  1100. }
  1101. };
  1102. function Promise(resolver) {
  1103. this._status = STATUS_PENDING;
  1104. this._handlers = [];
  1105. try {
  1106. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1107. } catch (e) {
  1108. this._reject(e);
  1109. }
  1110. }
  1111. /**
  1112. * Builds a promise that is resolved when all the passed in promises are
  1113. * resolved.
  1114. * @param {array} array of data and/or promises to wait for.
  1115. * @return {Promise} New dependant promise.
  1116. */
  1117. Promise.all = function Promise_all(promises) {
  1118. var resolveAll, rejectAll;
  1119. var deferred = new Promise(function (resolve, reject) {
  1120. resolveAll = resolve;
  1121. rejectAll = reject;
  1122. });
  1123. var unresolved = promises.length;
  1124. var results = [];
  1125. if (unresolved === 0) {
  1126. resolveAll(results);
  1127. return deferred;
  1128. }
  1129. function reject(reason) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results = [];
  1134. rejectAll(reason);
  1135. }
  1136. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1137. var promise = promises[i];
  1138. var resolve = (function(i) {
  1139. return function(value) {
  1140. if (deferred._status === STATUS_REJECTED) {
  1141. return;
  1142. }
  1143. results[i] = value;
  1144. unresolved--;
  1145. if (unresolved === 0) {
  1146. resolveAll(results);
  1147. }
  1148. };
  1149. })(i);
  1150. if (Promise.isPromise(promise)) {
  1151. promise.then(resolve, reject);
  1152. } else {
  1153. resolve(promise);
  1154. }
  1155. }
  1156. return deferred;
  1157. };
  1158. /**
  1159. * Checks if the value is likely a promise (has a 'then' function).
  1160. * @return {boolean} true if value is thenable
  1161. */
  1162. Promise.isPromise = function Promise_isPromise(value) {
  1163. return value && typeof value.then === 'function';
  1164. };
  1165. /**
  1166. * Creates resolved promise
  1167. * @param value resolve value
  1168. * @returns {Promise}
  1169. */
  1170. Promise.resolve = function Promise_resolve(value) {
  1171. return new Promise(function (resolve) { resolve(value); });
  1172. };
  1173. /**
  1174. * Creates rejected promise
  1175. * @param reason rejection value
  1176. * @returns {Promise}
  1177. */
  1178. Promise.reject = function Promise_reject(reason) {
  1179. return new Promise(function (resolve, reject) { reject(reason); });
  1180. };
  1181. Promise.prototype = {
  1182. _status: null,
  1183. _value: null,
  1184. _handlers: null,
  1185. _unhandledRejection: null,
  1186. _updateStatus: function Promise__updateStatus(status, value) {
  1187. if (this._status === STATUS_RESOLVED ||
  1188. this._status === STATUS_REJECTED) {
  1189. return;
  1190. }
  1191. if (status === STATUS_RESOLVED &&
  1192. Promise.isPromise(value)) {
  1193. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1194. this._updateStatus.bind(this, STATUS_REJECTED));
  1195. return;
  1196. }
  1197. this._status = status;
  1198. this._value = value;
  1199. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1200. this._unhandledRejection = true;
  1201. HandlerManager.addUnhandledRejection(this);
  1202. }
  1203. HandlerManager.scheduleHandlers(this);
  1204. },
  1205. _resolve: function Promise_resolve(value) {
  1206. this._updateStatus(STATUS_RESOLVED, value);
  1207. },
  1208. _reject: function Promise_reject(reason) {
  1209. this._updateStatus(STATUS_REJECTED, reason);
  1210. },
  1211. then: function Promise_then(onResolve, onReject) {
  1212. var nextPromise = new Promise(function (resolve, reject) {
  1213. this.resolve = resolve;
  1214. this.reject = reject;
  1215. });
  1216. this._handlers.push({
  1217. thisPromise: this,
  1218. onResolve: onResolve,
  1219. onReject: onReject,
  1220. nextPromise: nextPromise
  1221. });
  1222. HandlerManager.scheduleHandlers(this);
  1223. return nextPromise;
  1224. },
  1225. catch: function Promise_catch(onReject) {
  1226. return this.then(undefined, onReject);
  1227. }
  1228. };
  1229. globalScope.Promise = Promise;
  1230. })();
  1231. var StatTimer = (function StatTimerClosure() {
  1232. function rpad(str, pad, length) {
  1233. while (str.length < length) {
  1234. str += pad;
  1235. }
  1236. return str;
  1237. }
  1238. function StatTimer() {
  1239. this.started = {};
  1240. this.times = [];
  1241. this.enabled = true;
  1242. }
  1243. StatTimer.prototype = {
  1244. time: function StatTimer_time(name) {
  1245. if (!this.enabled) {
  1246. return;
  1247. }
  1248. if (name in this.started) {
  1249. warn('Timer is already running for ' + name);
  1250. }
  1251. this.started[name] = Date.now();
  1252. },
  1253. timeEnd: function StatTimer_timeEnd(name) {
  1254. if (!this.enabled) {
  1255. return;
  1256. }
  1257. if (!(name in this.started)) {
  1258. warn('Timer has not been started for ' + name);
  1259. }
  1260. this.times.push({
  1261. 'name': name,
  1262. 'start': this.started[name],
  1263. 'end': Date.now()
  1264. });
  1265. // Remove timer from started so it can be called again.
  1266. delete this.started[name];
  1267. },
  1268. toString: function StatTimer_toString() {
  1269. var i, ii;
  1270. var times = this.times;
  1271. var out = '';
  1272. // Find the longest name for padding purposes.
  1273. var longest = 0;
  1274. for (i = 0, ii = times.length; i < ii; ++i) {
  1275. var name = times[i]['name'];
  1276. if (name.length > longest) {
  1277. longest = name.length;
  1278. }
  1279. }
  1280. for (i = 0, ii = times.length; i < ii; ++i) {
  1281. var span = times[i];
  1282. var duration = span.end - span.start;
  1283. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1284. }
  1285. return out;
  1286. }
  1287. };
  1288. return StatTimer;
  1289. })();
  1290. PDFJS.createBlob = function createBlob(data, contentType) {
  1291. if (typeof Blob !== 'undefined') {
  1292. return new Blob([data], { type: contentType });
  1293. }
  1294. // Blob builder is deprecated in FF14 and removed in FF18.
  1295. var bb = new MozBlobBuilder();
  1296. bb.append(data);
  1297. return bb.getBlob(contentType);
  1298. };
  1299. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1300. // Blob/createObjectURL is not available, falling back to data schema.
  1301. var digits =
  1302. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1303. return function createObjectURL(data, contentType) {
  1304. if (!PDFJS.disableCreateObjectURL &&
  1305. typeof URL !== 'undefined' && URL.createObjectURL) {
  1306. var blob = PDFJS.createBlob(data, contentType);
  1307. return URL.createObjectURL(blob);
  1308. }
  1309. var buffer = 'data:' + contentType + ';base64,';
  1310. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1311. var b1 = data[i] & 0xFF;
  1312. var b2 = data[i + 1] & 0xFF;
  1313. var b3 = data[i + 2] & 0xFF;
  1314. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1315. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1316. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1317. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1318. }
  1319. return buffer;
  1320. };
  1321. })();
  1322. function MessageHandler(name, comObj) {
  1323. this.name = name;
  1324. this.comObj = comObj;
  1325. this.callbackIndex = 1;
  1326. this.postMessageTransfers = true;
  1327. var callbacksCapabilities = this.callbacksCapabilities = {};
  1328. var ah = this.actionHandler = {};
  1329. ah['console_log'] = [function ahConsoleLog(data) {
  1330. console.log.apply(console, data);
  1331. }];
  1332. ah['console_error'] = [function ahConsoleError(data) {
  1333. console.error.apply(console, data);
  1334. }];
  1335. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1336. UnsupportedManager.notify(data);
  1337. }];
  1338. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1339. var data = event.data;
  1340. if (data.isReply) {
  1341. var callbackId = data.callbackId;
  1342. if (data.callbackId in callbacksCapabilities) {
  1343. var callback = callbacksCapabilities[callbackId];
  1344. delete callbacksCapabilities[callbackId];
  1345. if ('error' in data) {
  1346. callback.reject(data.error);
  1347. } else {
  1348. callback.resolve(data.data);
  1349. }
  1350. } else {
  1351. error('Cannot resolve callback ' + callbackId);
  1352. }
  1353. } else if (data.action in ah) {
  1354. var action = ah[data.action];
  1355. if (data.callbackId) {
  1356. Promise.resolve().then(function () {
  1357. return action[0].call(action[1], data.data);
  1358. }).then(function (result) {
  1359. comObj.postMessage({
  1360. isReply: true,
  1361. callbackId: data.callbackId,
  1362. data: result
  1363. });
  1364. }, function (reason) {
  1365. comObj.postMessage({
  1366. isReply: true,
  1367. callbackId: data.callbackId,
  1368. error: reason
  1369. });
  1370. });
  1371. } else {
  1372. action[0].call(action[1], data.data);
  1373. }
  1374. } else {
  1375. error('Unknown action from worker: ' + data.action);
  1376. }
  1377. };
  1378. }
  1379. MessageHandler.prototype = {
  1380. on: function messageHandlerOn(actionName, handler, scope) {
  1381. var ah = this.actionHandler;
  1382. if (ah[actionName]) {
  1383. error('There is already an actionName called "' + actionName + '"');
  1384. }
  1385. ah[actionName] = [handler, scope];
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * @param {String} actionName Action to call.
  1390. * @param {JSON} data JSON data to send.
  1391. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1392. */
  1393. send: function messageHandlerSend(actionName, data, transfers) {
  1394. var message = {
  1395. action: actionName,
  1396. data: data
  1397. };
  1398. this.postMessage(message, transfers);
  1399. },
  1400. /**
  1401. * Sends a message to the comObj to invoke the action with the supplied data.
  1402. * Expects that other side will callback with the response.
  1403. * @param {String} actionName Action to call.
  1404. * @param {JSON} data JSON data to send.
  1405. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1406. * @returns {Promise} Promise to be resolved with response data.
  1407. */
  1408. sendWithPromise:
  1409. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1410. var callbackId = this.callbackIndex++;
  1411. var message = {
  1412. action: actionName,
  1413. data: data,
  1414. callbackId: callbackId
  1415. };
  1416. var capability = createPromiseCapability();
  1417. this.callbacksCapabilities[callbackId] = capability;
  1418. try {
  1419. this.postMessage(message, transfers);
  1420. } catch (e) {
  1421. capability.reject(e);
  1422. }
  1423. return capability.promise;
  1424. },
  1425. /**
  1426. * Sends raw message to the comObj.
  1427. * @private
  1428. * @param message {Object} Raw message.
  1429. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1430. */
  1431. postMessage: function (message, transfers) {
  1432. if (transfers && this.postMessageTransfers) {
  1433. this.comObj.postMessage(message, transfers);
  1434. } else {
  1435. this.comObj.postMessage(message);
  1436. }
  1437. }
  1438. };
  1439. function loadJpegStream(id, imageUrl, objs) {
  1440. var img = new Image();
  1441. img.onload = (function loadJpegStream_onloadClosure() {
  1442. objs.resolve(id, img);
  1443. });
  1444. img.onerror = (function loadJpegStream_onerrorClosure() {
  1445. objs.resolve(id, null);
  1446. warn('Error during JPEG image loading');
  1447. });
  1448. img.src = imageUrl;
  1449. }
  1450. var NetworkManager = (function NetworkManagerClosure() {
  1451. var OK_RESPONSE = 200;
  1452. var PARTIAL_CONTENT_RESPONSE = 206;
  1453. function NetworkManager(url, args) {
  1454. this.url = url;
  1455. args = args || {};
  1456. this.isHttp = /^https?:/i.test(url);
  1457. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1458. this.withCredentials = args.withCredentials || false;
  1459. this.getXhr = args.getXhr ||
  1460. function NetworkManager_getXhr() {
  1461. return new XMLHttpRequest();
  1462. };
  1463. this.currXhrId = 0;
  1464. this.pendingRequests = {};
  1465. this.loadedRequests = {};
  1466. }
  1467. function getArrayBuffer(xhr) {
  1468. var data = xhr.response;
  1469. if (typeof data !== 'string') {
  1470. return data;
  1471. }
  1472. var length = data.length;
  1473. var array = new Uint8Array(length);
  1474. for (var i = 0; i < length; i++) {
  1475. array[i] = data.charCodeAt(i) & 0xFF;
  1476. }
  1477. return array.buffer;
  1478. }
  1479. NetworkManager.prototype = {
  1480. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1481. var args = {
  1482. begin: begin,
  1483. end: end
  1484. };
  1485. for (var prop in listeners) {
  1486. args[prop] = listeners[prop];
  1487. }
  1488. return this.request(args);
  1489. },
  1490. requestFull: function NetworkManager_requestFull(listeners) {
  1491. return this.request(listeners);
  1492. },
  1493. request: function NetworkManager_request(args) {
  1494. var xhr = this.getXhr();
  1495. var xhrId = this.currXhrId++;
  1496. var pendingRequest = this.pendingRequests[xhrId] = {
  1497. xhr: xhr
  1498. };
  1499. xhr.open('GET', this.url);
  1500. xhr.withCredentials = this.withCredentials;
  1501. for (var property in this.httpHeaders) {
  1502. var value = this.httpHeaders[property];
  1503. if (typeof value === 'undefined') {
  1504. continue;
  1505. }
  1506. xhr.setRequestHeader(property, value);
  1507. }
  1508. if (this.isHttp && 'begin' in args && 'end' in args) {
  1509. var rangeStr = args.begin + '-' + (args.end - 1);
  1510. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1511. pendingRequest.expectedStatus = 206;
  1512. } else {
  1513. pendingRequest.expectedStatus = 200;
  1514. }
  1515. if (args.onProgressiveData) {
  1516. // Some legacy browsers might throw an exception.
  1517. try {
  1518. xhr.responseType = 'moz-chunked-arraybuffer';
  1519. } catch(e) {}
  1520. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1521. pendingRequest.onProgressiveData = args.onProgressiveData;
  1522. pendingRequest.mozChunked = true;
  1523. } else {
  1524. xhr.responseType = 'arraybuffer';
  1525. }
  1526. } else {
  1527. xhr.responseType = 'arraybuffer';
  1528. }
  1529. if (args.onError) {
  1530. xhr.onerror = function(evt) {
  1531. args.onError(xhr.status);
  1532. };
  1533. }
  1534. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1535. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1536. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1537. pendingRequest.onDone = args.onDone;
  1538. pendingRequest.onError = args.onError;
  1539. pendingRequest.onProgress = args.onProgress;
  1540. xhr.send(null);
  1541. return xhrId;
  1542. },
  1543. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1544. var pendingRequest = this.pendingRequests[xhrId];
  1545. if (!pendingRequest) {
  1546. // Maybe abortRequest was called...
  1547. return;
  1548. }
  1549. if (pendingRequest.mozChunked) {
  1550. var chunk = getArrayBuffer(pendingRequest.xhr);
  1551. pendingRequest.onProgressiveData(chunk);
  1552. }
  1553. var onProgress = pendingRequest.onProgress;
  1554. if (onProgress) {
  1555. onProgress(evt);
  1556. }
  1557. },
  1558. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1559. var pendingRequest = this.pendingRequests[xhrId];
  1560. if (!pendingRequest) {
  1561. // Maybe abortRequest was called...
  1562. return;
  1563. }
  1564. var xhr = pendingRequest.xhr;
  1565. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1566. pendingRequest.onHeadersReceived();
  1567. delete pendingRequest.onHeadersReceived;
  1568. }
  1569. if (xhr.readyState !== 4) {
  1570. return;
  1571. }
  1572. if (!(xhrId in this.pendingRequests)) {
  1573. // The XHR request might have been aborted in onHeadersReceived()
  1574. // callback, in which case we should abort request
  1575. return;
  1576. }
  1577. delete this.pendingRequests[xhrId];
  1578. // success status == 0 can be on ftp, file and other protocols
  1579. if (xhr.status === 0 && this.isHttp) {
  1580. if (pendingRequest.onError) {
  1581. pendingRequest.onError(xhr.status);
  1582. }
  1583. return;
  1584. }
  1585. var xhrStatus = xhr.status || OK_RESPONSE;
  1586. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1587. // "A server MAY ignore the Range header". This means it's possible to
  1588. // get a 200 rather than a 206 response from a range request.
  1589. var ok_response_on_range_request =
  1590. xhrStatus === OK_RESPONSE &&
  1591. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1592. if (!ok_response_on_range_request &&
  1593. xhrStatus !== pendingRequest.expectedStatus) {
  1594. if (pendingRequest.onError) {
  1595. pendingRequest.onError(xhr.status);
  1596. }
  1597. return;
  1598. }
  1599. this.loadedRequests[xhrId] = true;
  1600. var chunk = getArrayBuffer(xhr);
  1601. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1602. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1603. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1604. var begin = parseInt(matches[1], 10);
  1605. pendingRequest.onDone({
  1606. begin: begin,
  1607. chunk: chunk
  1608. });
  1609. } else if (pendingRequest.onProgressiveData) {
  1610. pendingRequest.onDone(null);
  1611. } else {
  1612. pendingRequest.onDone({
  1613. begin: 0,
  1614. chunk: chunk
  1615. });
  1616. }
  1617. },
  1618. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1619. for (var xhrId in this.pendingRequests) {
  1620. return true;
  1621. }
  1622. return false;
  1623. },
  1624. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1625. return this.pendingRequests[xhrId].xhr;
  1626. },
  1627. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1628. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1629. },
  1630. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1631. return xhrId in this.pendingRequests;
  1632. },
  1633. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1634. return xhrId in this.loadedRequests;
  1635. },
  1636. abortAllRequests: function NetworkManager_abortAllRequests() {
  1637. for (var xhrId in this.pendingRequests) {
  1638. this.abortRequest(xhrId | 0);
  1639. }
  1640. },
  1641. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1642. var xhr = this.pendingRequests[xhrId].xhr;
  1643. delete this.pendingRequests[xhrId];
  1644. xhr.abort();
  1645. }
  1646. };
  1647. return NetworkManager;
  1648. })();
  1649. var ChunkedStream = (function ChunkedStreamClosure() {
  1650. function ChunkedStream(length, chunkSize, manager) {
  1651. this.bytes = new Uint8Array(length);
  1652. this.start = 0;
  1653. this.pos = 0;
  1654. this.end = length;
  1655. this.chunkSize = chunkSize;
  1656. this.loadedChunks = [];
  1657. this.numChunksLoaded = 0;
  1658. this.numChunks = Math.ceil(length / chunkSize);
  1659. this.manager = manager;
  1660. this.progressiveDataLength = 0;
  1661. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1662. }
  1663. // required methods for a stream. if a particular stream does not
  1664. // implement these, an error should be thrown
  1665. ChunkedStream.prototype = {
  1666. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1667. var chunks = [];
  1668. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1669. if (!this.loadedChunks[chunk]) {
  1670. chunks.push(chunk);
  1671. }
  1672. }
  1673. return chunks;
  1674. },
  1675. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1676. return [this];
  1677. },
  1678. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1679. return this.numChunksLoaded === this.numChunks;
  1680. },
  1681. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1682. var end = begin + chunk.byteLength;
  1683. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1684. // Using this.length is inaccurate here since this.start can be moved
  1685. // See ChunkedStream.moveStart()
  1686. var length = this.bytes.length;
  1687. assert(end % this.chunkSize === 0 || end === length,
  1688. 'Bad end offset: ' + end);
  1689. this.bytes.set(new Uint8Array(chunk), begin);
  1690. var chunkSize = this.chunkSize;
  1691. var beginChunk = Math.floor(begin / chunkSize);
  1692. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1693. var curChunk;
  1694. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1695. if (!this.loadedChunks[curChunk]) {
  1696. this.loadedChunks[curChunk] = true;
  1697. ++this.numChunksLoaded;
  1698. }
  1699. }
  1700. },
  1701. onReceiveProgressiveData:
  1702. function ChunkedStream_onReceiveProgressiveData(data) {
  1703. var position = this.progressiveDataLength;
  1704. var beginChunk = Math.floor(position / this.chunkSize);
  1705. this.bytes.set(new Uint8Array(data), position);
  1706. position += data.byteLength;
  1707. this.progressiveDataLength = position;
  1708. var endChunk = position >= this.end ? this.numChunks :
  1709. Math.floor(position / this.chunkSize);
  1710. var curChunk;
  1711. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1712. if (!this.loadedChunks[curChunk]) {
  1713. this.loadedChunks[curChunk] = true;
  1714. ++this.numChunksLoaded;
  1715. }
  1716. }
  1717. },
  1718. ensureByte: function ChunkedStream_ensureByte(pos) {
  1719. var chunk = Math.floor(pos / this.chunkSize);
  1720. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1721. return;
  1722. }
  1723. if (!this.loadedChunks[chunk]) {
  1724. throw new MissingDataException(pos, pos + 1);
  1725. }
  1726. this.lastSuccessfulEnsureByteChunk = chunk;
  1727. },
  1728. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1729. if (begin >= end) {
  1730. return;
  1731. }
  1732. if (end <= this.progressiveDataLength) {
  1733. return;
  1734. }
  1735. var chunkSize = this.chunkSize;
  1736. var beginChunk = Math.floor(begin / chunkSize);
  1737. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1738. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1739. if (!this.loadedChunks[chunk]) {
  1740. throw new MissingDataException(begin, end);
  1741. }
  1742. }
  1743. },
  1744. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1745. var chunk, n;
  1746. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1747. if (!this.loadedChunks[chunk]) {
  1748. return chunk;
  1749. }
  1750. }
  1751. // Wrap around to beginning
  1752. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1753. if (!this.loadedChunks[chunk]) {
  1754. return chunk;
  1755. }
  1756. }
  1757. return null;
  1758. },
  1759. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1760. return !!this.loadedChunks[chunk];
  1761. },
  1762. get length() {
  1763. return this.end - this.start;
  1764. },
  1765. get isEmpty() {
  1766. return this.length === 0;
  1767. },
  1768. getByte: function ChunkedStream_getByte() {
  1769. var pos = this.pos;
  1770. if (pos >= this.end) {
  1771. return -1;
  1772. }
  1773. this.ensureByte(pos);
  1774. return this.bytes[this.pos++];
  1775. },
  1776. getUint16: function ChunkedStream_getUint16() {
  1777. var b0 = this.getByte();
  1778. var b1 = this.getByte();
  1779. if (b0 === -1 || b1 === -1) {
  1780. return -1;
  1781. }
  1782. return (b0 << 8) + b1;
  1783. },
  1784. getInt32: function ChunkedStream_getInt32() {
  1785. var b0 = this.getByte();
  1786. var b1 = this.getByte();
  1787. var b2 = this.getByte();
  1788. var b3 = this.getByte();
  1789. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1790. },
  1791. // returns subarray of original buffer
  1792. // should only be read
  1793. getBytes: function ChunkedStream_getBytes(length) {
  1794. var bytes = this.bytes;
  1795. var pos = this.pos;
  1796. var strEnd = this.end;
  1797. if (!length) {
  1798. this.ensureRange(pos, strEnd);
  1799. return bytes.subarray(pos, strEnd);
  1800. }
  1801. var end = pos + length;
  1802. if (end > strEnd) {
  1803. end = strEnd;
  1804. }
  1805. this.ensureRange(pos, end);
  1806. this.pos = end;
  1807. return bytes.subarray(pos, end);
  1808. },
  1809. peekByte: function ChunkedStream_peekByte() {
  1810. var peekedByte = this.getByte();
  1811. this.pos--;
  1812. return peekedByte;
  1813. },
  1814. peekBytes: function ChunkedStream_peekBytes(length) {
  1815. var bytes = this.getBytes(length);
  1816. this.pos -= bytes.length;
  1817. return bytes;
  1818. },
  1819. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1820. this.ensureRange(begin, end);
  1821. return this.bytes.subarray(begin, end);
  1822. },
  1823. skip: function ChunkedStream_skip(n) {
  1824. if (!n) {
  1825. n = 1;
  1826. }
  1827. this.pos += n;
  1828. },
  1829. reset: function ChunkedStream_reset() {
  1830. this.pos = this.start;
  1831. },
  1832. moveStart: function ChunkedStream_moveStart() {
  1833. this.start = this.pos;
  1834. },
  1835. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1836. this.ensureRange(start, start + length);
  1837. function ChunkedStreamSubstream() {}
  1838. ChunkedStreamSubstream.prototype = Object.create(this);
  1839. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1840. var chunkSize = this.chunkSize;
  1841. var beginChunk = Math.floor(this.start / chunkSize);
  1842. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1843. var missingChunks = [];
  1844. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1845. if (!this.loadedChunks[chunk]) {
  1846. missingChunks.push(chunk);
  1847. }
  1848. }
  1849. return missingChunks;
  1850. };
  1851. var subStream = new ChunkedStreamSubstream();
  1852. subStream.pos = subStream.start = start;
  1853. subStream.end = start + length || this.end;
  1854. subStream.dict = dict;
  1855. return subStream;
  1856. },
  1857. isStream: true
  1858. };
  1859. return ChunkedStream;
  1860. })();
  1861. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1862. function ChunkedStreamManager(length, chunkSize, url, args) {
  1863. this.stream = new ChunkedStream(length, chunkSize, this);
  1864. this.length = length;
  1865. this.chunkSize = chunkSize;
  1866. this.url = url;
  1867. this.disableAutoFetch = args.disableAutoFetch;
  1868. var msgHandler = this.msgHandler = args.msgHandler;
  1869. if (args.chunkedViewerLoading) {
  1870. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1871. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1872. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1873. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1874. };
  1875. } else {
  1876. var getXhr = function getXhr() {
  1877. return new XMLHttpRequest();
  1878. };
  1879. this.networkManager = new NetworkManager(this.url, {
  1880. getXhr: getXhr,
  1881. httpHeaders: args.httpHeaders,
  1882. withCredentials: args.withCredentials
  1883. });
  1884. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1885. this.networkManager.requestRange(begin, end, {
  1886. onDone: this.onReceiveData.bind(this),
  1887. onProgress: this.onProgress.bind(this)
  1888. });
  1889. };
  1890. }
  1891. this.currRequestId = 0;
  1892. this.chunksNeededByRequest = {};
  1893. this.requestsByChunk = {};
  1894. this.callbacksByRequest = {};
  1895. this.progressiveDataLength = 0;
  1896. this._loadedStreamCapability = createPromiseCapability();
  1897. if (args.initialData) {
  1898. this.onReceiveData({chunk: args.initialData});
  1899. }
  1900. }
  1901. ChunkedStreamManager.prototype = {
  1902. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1903. return this._loadedStreamCapability.promise;
  1904. },
  1905. // Get all the chunks that are not yet loaded and groups them into
  1906. // contiguous ranges to load in as few requests as possible
  1907. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1908. var missingChunks = this.stream.getMissingChunks();
  1909. this.requestChunks(missingChunks);
  1910. return this._loadedStreamCapability.promise;
  1911. },
  1912. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1913. callback) {
  1914. var requestId = this.currRequestId++;
  1915. var chunksNeeded;
  1916. var i, ii;
  1917. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1918. for (i = 0, ii = chunks.length; i < ii; i++) {
  1919. if (!this.stream.hasChunk(chunks[i])) {
  1920. chunksNeeded[chunks[i]] = true;
  1921. }
  1922. }
  1923. if (isEmptyObj(chunksNeeded)) {
  1924. if (callback) {
  1925. callback();
  1926. }
  1927. return;
  1928. }
  1929. this.callbacksByRequest[requestId] = callback;
  1930. var chunksToRequest = [];
  1931. for (var chunk in chunksNeeded) {
  1932. chunk = chunk | 0;
  1933. if (!(chunk in this.requestsByChunk)) {
  1934. this.requestsByChunk[chunk] = [];
  1935. chunksToRequest.push(chunk);
  1936. }
  1937. this.requestsByChunk[chunk].push(requestId);
  1938. }
  1939. if (!chunksToRequest.length) {
  1940. return;
  1941. }
  1942. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1943. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1944. var groupedChunk = groupedChunksToRequest[i];
  1945. var begin = groupedChunk.beginChunk * this.chunkSize;
  1946. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1947. this.sendRequest(begin, end);
  1948. }
  1949. },
  1950. getStream: function ChunkedStreamManager_getStream() {
  1951. return this.stream;
  1952. },
  1953. // Loads any chunks in the requested range that are not yet loaded
  1954. requestRange: function ChunkedStreamManager_requestRange(
  1955. begin, end, callback) {
  1956. end = Math.min(end, this.length);
  1957. var beginChunk = this.getBeginChunk(begin);
  1958. var endChunk = this.getEndChunk(end);
  1959. var chunks = [];
  1960. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1961. chunks.push(chunk);
  1962. }
  1963. this.requestChunks(chunks, callback);
  1964. },
  1965. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1966. callback) {
  1967. ranges = ranges || [];
  1968. var chunksToRequest = [];
  1969. for (var i = 0; i < ranges.length; i++) {
  1970. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1971. var endChunk = this.getEndChunk(ranges[i].end);
  1972. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1973. if (chunksToRequest.indexOf(chunk) < 0) {
  1974. chunksToRequest.push(chunk);
  1975. }
  1976. }
  1977. }
  1978. chunksToRequest.sort(function(a, b) { return a - b; });
  1979. this.requestChunks(chunksToRequest, callback);
  1980. },
  1981. // Groups a sorted array of chunks into as few continguous larger
  1982. // chunks as possible
  1983. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1984. var groupedChunks = [];
  1985. var beginChunk = -1;
  1986. var prevChunk = -1;
  1987. for (var i = 0; i < chunks.length; ++i) {
  1988. var chunk = chunks[i];
  1989. if (beginChunk < 0) {
  1990. beginChunk = chunk;
  1991. }
  1992. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1993. groupedChunks.push({ beginChunk: beginChunk,
  1994. endChunk: prevChunk + 1 });
  1995. beginChunk = chunk;
  1996. }
  1997. if (i + 1 === chunks.length) {
  1998. groupedChunks.push({ beginChunk: beginChunk,
  1999. endChunk: chunk + 1 });
  2000. }
  2001. prevChunk = chunk;
  2002. }
  2003. return groupedChunks;
  2004. },
  2005. onProgress: function ChunkedStreamManager_onProgress(args) {
  2006. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2007. args.loaded);
  2008. this.msgHandler.send('DocProgress', {
  2009. loaded: bytesLoaded,
  2010. total: this.length
  2011. });
  2012. },
  2013. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2014. var chunk = args.chunk;
  2015. var isProgressive = args.begin === undefined;
  2016. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2017. var end = begin + chunk.byteLength;
  2018. var beginChunk = Math.floor(begin / this.chunkSize);
  2019. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2020. Math.ceil(end / this.chunkSize);
  2021. if (isProgressive) {
  2022. this.stream.onReceiveProgressiveData(chunk);
  2023. this.progressiveDataLength = end;
  2024. } else {
  2025. this.stream.onReceiveData(begin, chunk);
  2026. }
  2027. if (this.stream.allChunksLoaded()) {
  2028. this._loadedStreamCapability.resolve(this.stream);
  2029. }
  2030. var loadedRequests = [];
  2031. var i, requestId;
  2032. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2033. // The server might return more chunks than requested
  2034. var requestIds = this.requestsByChunk[chunk] || [];
  2035. delete this.requestsByChunk[chunk];
  2036. for (i = 0; i < requestIds.length; ++i) {
  2037. requestId = requestIds[i];
  2038. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2039. if (chunk in chunksNeeded) {
  2040. delete chunksNeeded[chunk];
  2041. }
  2042. if (!isEmptyObj(chunksNeeded)) {
  2043. continue;
  2044. }
  2045. loadedRequests.push(requestId);
  2046. }
  2047. }
  2048. // If there are no pending requests, automatically fetch the next
  2049. // unfetched chunk of the PDF
  2050. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2051. var nextEmptyChunk;
  2052. if (this.stream.numChunksLoaded === 1) {
  2053. // This is a special optimization so that after fetching the first
  2054. // chunk, rather than fetching the second chunk, we fetch the last
  2055. // chunk.
  2056. var lastChunk = this.stream.numChunks - 1;
  2057. if (!this.stream.hasChunk(lastChunk)) {
  2058. nextEmptyChunk = lastChunk;
  2059. }
  2060. } else {
  2061. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2062. }
  2063. if (isInt(nextEmptyChunk)) {
  2064. this.requestChunks([nextEmptyChunk]);
  2065. }
  2066. }
  2067. for (i = 0; i < loadedRequests.length; ++i) {
  2068. requestId = loadedRequests[i];
  2069. var callback = this.callbacksByRequest[requestId];
  2070. delete this.callbacksByRequest[requestId];
  2071. if (callback) {
  2072. callback();
  2073. }
  2074. }
  2075. this.msgHandler.send('DocProgress', {
  2076. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2077. total: this.length
  2078. });
  2079. },
  2080. onError: function ChunkedStreamManager_onError(err) {
  2081. this._loadedStreamCapability.reject(err);
  2082. },
  2083. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2084. var chunk = Math.floor(begin / this.chunkSize);
  2085. return chunk;
  2086. },
  2087. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2088. if (end % this.chunkSize === 0) {
  2089. return end / this.chunkSize;
  2090. }
  2091. // 0 -> 0
  2092. // 1 -> 1
  2093. // 99 -> 1
  2094. // 100 -> 1
  2095. // 101 -> 2
  2096. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2097. return chunk;
  2098. }
  2099. };
  2100. return ChunkedStreamManager;
  2101. })();
  2102. // The maximum number of bytes fetched per range request
  2103. var RANGE_CHUNK_SIZE = 65536;
  2104. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2105. var BasePdfManager = (function BasePdfManagerClosure() {
  2106. function BasePdfManager() {
  2107. throw new Error('Cannot initialize BaseManagerManager');
  2108. }
  2109. BasePdfManager.prototype = {
  2110. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2111. throw new NotImplementedException();
  2112. },
  2113. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2114. return this.ensure(this.pdfDocument, prop, args);
  2115. },
  2116. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2117. return this.ensure(this.pdfDocument.xref, prop, args);
  2118. },
  2119. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2120. return this.ensure(this.pdfDocument.catalog, prop, args);
  2121. },
  2122. getPage: function BasePdfManager_pagePage(pageIndex) {
  2123. return this.pdfDocument.getPage(pageIndex);
  2124. },
  2125. cleanup: function BasePdfManager_cleanup() {
  2126. return this.pdfDocument.cleanup();
  2127. },
  2128. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2129. return new NotImplementedException();
  2130. },
  2131. requestRange: function BasePdfManager_ensure(begin, end) {
  2132. return new NotImplementedException();
  2133. },
  2134. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2135. return new NotImplementedException();
  2136. },
  2137. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2138. return new NotImplementedException();
  2139. },
  2140. updatePassword: function BasePdfManager_updatePassword(password) {
  2141. this.pdfDocument.xref.password = this.password = password;
  2142. if (this._passwordChangedCapability) {
  2143. this._passwordChangedCapability.resolve();
  2144. }
  2145. },
  2146. passwordChanged: function BasePdfManager_passwordChanged() {
  2147. this._passwordChangedCapability = createPromiseCapability();
  2148. return this._passwordChangedCapability.promise;
  2149. },
  2150. terminate: function BasePdfManager_terminate() {
  2151. return new NotImplementedException();
  2152. }
  2153. };
  2154. return BasePdfManager;
  2155. })();
  2156. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2157. function LocalPdfManager(data, password) {
  2158. var stream = new Stream(data);
  2159. this.pdfDocument = new PDFDocument(this, stream, password);
  2160. this._loadedStreamCapability = createPromiseCapability();
  2161. this._loadedStreamCapability.resolve(stream);
  2162. }
  2163. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2164. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2165. LocalPdfManager.prototype.ensure =
  2166. function LocalPdfManager_ensure(obj, prop, args) {
  2167. return new Promise(function (resolve, reject) {
  2168. try {
  2169. var value = obj[prop];
  2170. var result;
  2171. if (typeof value === 'function') {
  2172. result = value.apply(obj, args);
  2173. } else {
  2174. result = value;
  2175. }
  2176. resolve(result);
  2177. } catch (e) {
  2178. reject(e);
  2179. }
  2180. });
  2181. };
  2182. LocalPdfManager.prototype.requestRange =
  2183. function LocalPdfManager_requestRange(begin, end) {
  2184. return Promise.resolve();
  2185. };
  2186. LocalPdfManager.prototype.requestLoadedStream =
  2187. function LocalPdfManager_requestLoadedStream() {
  2188. };
  2189. LocalPdfManager.prototype.onLoadedStream =
  2190. function LocalPdfManager_getLoadedStream() {
  2191. return this._loadedStreamCapability.promise;
  2192. };
  2193. LocalPdfManager.prototype.terminate =
  2194. function LocalPdfManager_terminate() {
  2195. return;
  2196. };
  2197. return LocalPdfManager;
  2198. })();
  2199. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2200. function NetworkPdfManager(args, msgHandler) {
  2201. this.msgHandler = msgHandler;
  2202. var params = {
  2203. msgHandler: msgHandler,
  2204. httpHeaders: args.httpHeaders,
  2205. withCredentials: args.withCredentials,
  2206. chunkedViewerLoading: args.chunkedViewerLoading,
  2207. disableAutoFetch: args.disableAutoFetch,
  2208. initialData: args.initialData
  2209. };
  2210. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2211. args.url, params);
  2212. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2213. args.password);
  2214. }
  2215. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2216. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2217. NetworkPdfManager.prototype.ensure =
  2218. function NetworkPdfManager_ensure(obj, prop, args) {
  2219. var pdfManager = this;
  2220. return new Promise(function (resolve, reject) {
  2221. function ensureHelper() {
  2222. try {
  2223. var result;
  2224. var value = obj[prop];
  2225. if (typeof value === 'function') {
  2226. result = value.apply(obj, args);
  2227. } else {
  2228. result = value;
  2229. }
  2230. resolve(result);
  2231. } catch(e) {
  2232. if (!(e instanceof MissingDataException)) {
  2233. reject(e);
  2234. return;
  2235. }
  2236. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2237. }
  2238. }
  2239. ensureHelper();
  2240. });
  2241. };
  2242. NetworkPdfManager.prototype.requestRange =
  2243. function NetworkPdfManager_requestRange(begin, end) {
  2244. return new Promise(function (resolve) {
  2245. this.streamManager.requestRange(begin, end, function() {
  2246. resolve();
  2247. });
  2248. }.bind(this));
  2249. };
  2250. NetworkPdfManager.prototype.requestLoadedStream =
  2251. function NetworkPdfManager_requestLoadedStream() {
  2252. this.streamManager.requestAllChunks();
  2253. };
  2254. NetworkPdfManager.prototype.sendProgressiveData =
  2255. function NetworkPdfManager_sendProgressiveData(chunk) {
  2256. this.streamManager.onReceiveData({ chunk: chunk });
  2257. };
  2258. NetworkPdfManager.prototype.onLoadedStream =
  2259. function NetworkPdfManager_getLoadedStream() {
  2260. return this.streamManager.onLoadedStream();
  2261. };
  2262. NetworkPdfManager.prototype.terminate =
  2263. function NetworkPdfManager_terminate() {
  2264. this.streamManager.networkManager.abortAllRequests();
  2265. };
  2266. return NetworkPdfManager;
  2267. })();
  2268. var Page = (function PageClosure() {
  2269. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2270. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2271. this.pdfManager = pdfManager;
  2272. this.pageIndex = pageIndex;
  2273. this.pageDict = pageDict;
  2274. this.xref = xref;
  2275. this.ref = ref;
  2276. this.fontCache = fontCache;
  2277. this.idCounters = {
  2278. obj: 0
  2279. };
  2280. this.resourcesPromise = null;
  2281. }
  2282. Page.prototype = {
  2283. getPageProp: function Page_getPageProp(key) {
  2284. return this.pageDict.get(key);
  2285. },
  2286. getInheritedPageProp: function Page_inheritPageProp(key) {
  2287. var dict = this.pageDict;
  2288. var value = dict.get(key);
  2289. while (value === undefined) {
  2290. dict = dict.get('Parent');
  2291. if (!dict) {
  2292. break;
  2293. }
  2294. value = dict.get(key);
  2295. }
  2296. return value;
  2297. },
  2298. get content() {
  2299. return this.getPageProp('Contents');
  2300. },
  2301. get resources() {
  2302. var value = this.getInheritedPageProp('Resources');
  2303. // For robustness: The spec states that a \Resources entry has to be
  2304. // present, but can be empty. Some document omit it still. In this case
  2305. // return an empty dictionary:
  2306. if (value === undefined) {
  2307. value = Dict.empty;
  2308. }
  2309. return shadow(this, 'resources', value);
  2310. },
  2311. get mediaBox() {
  2312. var obj = this.getInheritedPageProp('MediaBox');
  2313. // Reset invalid media box to letter size.
  2314. if (!isArray(obj) || obj.length !== 4) {
  2315. obj = LETTER_SIZE_MEDIABOX;
  2316. }
  2317. return shadow(this, 'mediaBox', obj);
  2318. },
  2319. get view() {
  2320. var mediaBox = this.mediaBox;
  2321. var cropBox = this.getInheritedPageProp('CropBox');
  2322. if (!isArray(cropBox) || cropBox.length !== 4) {
  2323. return shadow(this, 'view', mediaBox);
  2324. }
  2325. // From the spec, 6th ed., p.963:
  2326. // "The crop, bleed, trim, and art boxes should not ordinarily
  2327. // extend beyond the boundaries of the media box. If they do, they are
  2328. // effectively reduced to their intersection with the media box."
  2329. cropBox = Util.intersect(cropBox, mediaBox);
  2330. if (!cropBox) {
  2331. return shadow(this, 'view', mediaBox);
  2332. }
  2333. return shadow(this, 'view', cropBox);
  2334. },
  2335. get annotationRefs() {
  2336. return shadow(this, 'annotationRefs',
  2337. this.getInheritedPageProp('Annots'));
  2338. },
  2339. get rotate() {
  2340. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2341. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2342. if (rotate % 90 !== 0) {
  2343. rotate = 0;
  2344. } else if (rotate >= 360) {
  2345. rotate = rotate % 360;
  2346. } else if (rotate < 0) {
  2347. // The spec doesn't cover negatives, assume its counterclockwise
  2348. // rotation. The following is the other implementation of modulo.
  2349. rotate = ((rotate % 360) + 360) % 360;
  2350. }
  2351. return shadow(this, 'rotate', rotate);
  2352. },
  2353. getContentStream: function Page_getContentStream() {
  2354. var content = this.content;
  2355. var stream;
  2356. if (isArray(content)) {
  2357. // fetching items
  2358. var xref = this.xref;
  2359. var i, n = content.length;
  2360. var streams = [];
  2361. for (i = 0; i < n; ++i) {
  2362. streams.push(xref.fetchIfRef(content[i]));
  2363. }
  2364. stream = new StreamsSequenceStream(streams);
  2365. } else if (isStream(content)) {
  2366. stream = content;
  2367. } else {
  2368. // replacing non-existent page content with empty one
  2369. stream = new NullStream();
  2370. }
  2371. return stream;
  2372. },
  2373. loadResources: function Page_loadResources(keys) {
  2374. if (!this.resourcesPromise) {
  2375. // TODO: add async getInheritedPageProp and remove this.
  2376. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2377. }
  2378. return this.resourcesPromise.then(function resourceSuccess() {
  2379. var objectLoader = new ObjectLoader(this.resources.map,
  2380. keys,
  2381. this.xref);
  2382. return objectLoader.load();
  2383. }.bind(this));
  2384. },
  2385. getOperatorList: function Page_getOperatorList(handler, intent) {
  2386. var self = this;
  2387. var pdfManager = this.pdfManager;
  2388. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2389. []);
  2390. var resourcesPromise = this.loadResources([
  2391. 'ExtGState',
  2392. 'ColorSpace',
  2393. 'Pattern',
  2394. 'Shading',
  2395. 'XObject',
  2396. 'Font'
  2397. // ProcSet
  2398. // Properties
  2399. ]);
  2400. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2401. handler, this.pageIndex,
  2402. 'p' + this.pageIndex + '_',
  2403. this.idCounters,
  2404. this.fontCache);
  2405. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2406. var pageListPromise = dataPromises.then(function(data) {
  2407. var contentStream = data[0];
  2408. var opList = new OperatorList(intent, handler, self.pageIndex);
  2409. handler.send('StartRenderPage', {
  2410. transparency: partialEvaluator.hasBlendModes(self.resources),
  2411. pageIndex: self.pageIndex,
  2412. intent: intent
  2413. });
  2414. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2415. opList).then(function () {
  2416. return opList;
  2417. });
  2418. });
  2419. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2420. return Promise.all([pageListPromise, annotationsPromise]).then(
  2421. function(datas) {
  2422. var pageOpList = datas[0];
  2423. var annotations = datas[1];
  2424. if (annotations.length === 0) {
  2425. pageOpList.flush(true);
  2426. return pageOpList;
  2427. }
  2428. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2429. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2430. return annotationsReadyPromise.then(function () {
  2431. pageOpList.flush(true);
  2432. return pageOpList;
  2433. });
  2434. });
  2435. },
  2436. extractTextContent: function Page_extractTextContent() {
  2437. var handler = {
  2438. on: function nullHandlerOn() {},
  2439. send: function nullHandlerSend() {}
  2440. };
  2441. var self = this;
  2442. var pdfManager = this.pdfManager;
  2443. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2444. []);
  2445. var resourcesPromise = this.loadResources([
  2446. 'ExtGState',
  2447. 'XObject',
  2448. 'Font'
  2449. ]);
  2450. var dataPromises = Promise.all([contentStreamPromise,
  2451. resourcesPromise]);
  2452. return dataPromises.then(function(data) {
  2453. var contentStream = data[0];
  2454. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2455. handler, self.pageIndex,
  2456. 'p' + self.pageIndex + '_',
  2457. self.idCounters,
  2458. self.fontCache);
  2459. return partialEvaluator.getTextContent(contentStream,
  2460. self.resources);
  2461. });
  2462. },
  2463. getAnnotationsData: function Page_getAnnotationsData() {
  2464. var annotations = this.annotations;
  2465. var annotationsData = [];
  2466. for (var i = 0, n = annotations.length; i < n; ++i) {
  2467. annotationsData.push(annotations[i].getData());
  2468. }
  2469. return annotationsData;
  2470. },
  2471. get annotations() {
  2472. var annotations = [];
  2473. var annotationRefs = (this.annotationRefs || []);
  2474. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2475. var annotationRef = annotationRefs[i];
  2476. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2477. if (annotation) {
  2478. annotations.push(annotation);
  2479. }
  2480. }
  2481. return shadow(this, 'annotations', annotations);
  2482. }
  2483. };
  2484. return Page;
  2485. })();
  2486. /**
  2487. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2488. * `PDFDoc`, this one doesn't have any job management code.
  2489. * Right now there exists one PDFDocument on the main thread + one object
  2490. * for each worker. If there is no worker support enabled, there are two
  2491. * `PDFDocument` objects on the main thread created.
  2492. */
  2493. var PDFDocument = (function PDFDocumentClosure() {
  2494. var FINGERPRINT_FIRST_BYTES = 1024;
  2495. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2496. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2497. function PDFDocument(pdfManager, arg, password) {
  2498. if (isStream(arg)) {
  2499. init.call(this, pdfManager, arg, password);
  2500. } else if (isArrayBuffer(arg)) {
  2501. init.call(this, pdfManager, new Stream(arg), password);
  2502. } else {
  2503. error('PDFDocument: Unknown argument type');
  2504. }
  2505. }
  2506. function init(pdfManager, stream, password) {
  2507. assert(stream.length > 0, 'stream must have data');
  2508. this.pdfManager = pdfManager;
  2509. this.stream = stream;
  2510. var xref = new XRef(this.stream, password, pdfManager);
  2511. this.xref = xref;
  2512. }
  2513. function find(stream, needle, limit, backwards) {
  2514. var pos = stream.pos;
  2515. var end = stream.end;
  2516. var strBuf = [];
  2517. if (pos + limit > end) {
  2518. limit = end - pos;
  2519. }
  2520. for (var n = 0; n < limit; ++n) {
  2521. strBuf.push(String.fromCharCode(stream.getByte()));
  2522. }
  2523. var str = strBuf.join('');
  2524. stream.pos = pos;
  2525. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2526. if (index === -1) {
  2527. return false; /* not found */
  2528. }
  2529. stream.pos += index;
  2530. return true; /* found */
  2531. }
  2532. var DocumentInfoValidators = {
  2533. get entries() {
  2534. // Lazily build this since all the validation functions below are not
  2535. // defined until after this file loads.
  2536. return shadow(this, 'entries', {
  2537. Title: isString,
  2538. Author: isString,
  2539. Subject: isString,
  2540. Keywords: isString,
  2541. Creator: isString,
  2542. Producer: isString,
  2543. CreationDate: isString,
  2544. ModDate: isString,
  2545. Trapped: isName
  2546. });
  2547. }
  2548. };
  2549. PDFDocument.prototype = {
  2550. parse: function PDFDocument_parse(recoveryMode) {
  2551. this.setup(recoveryMode);
  2552. try {
  2553. // checking if AcroForm is present
  2554. this.acroForm = this.catalog.catDict.get('AcroForm');
  2555. if (this.acroForm) {
  2556. this.xfa = this.acroForm.get('XFA');
  2557. var fields = this.acroForm.get('Fields');
  2558. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2559. !this.xfa) {
  2560. // no fields and no XFA -- not a form (?)
  2561. this.acroForm = null;
  2562. }
  2563. }
  2564. } catch (ex) {
  2565. info('Something wrong with AcroForm entry');
  2566. this.acroForm = null;
  2567. }
  2568. },
  2569. get linearization() {
  2570. var linearization = null;
  2571. if (this.stream.length) {
  2572. try {
  2573. linearization = Linearization.create(this.stream);
  2574. } catch (err) {
  2575. if (err instanceof MissingDataException) {
  2576. throw err;
  2577. }
  2578. info(err);
  2579. }
  2580. }
  2581. // shadow the prototype getter with a data property
  2582. return shadow(this, 'linearization', linearization);
  2583. },
  2584. get startXRef() {
  2585. var stream = this.stream;
  2586. var startXRef = 0;
  2587. var linearization = this.linearization;
  2588. if (linearization) {
  2589. // Find end of first obj.
  2590. stream.reset();
  2591. if (find(stream, 'endobj', 1024)) {
  2592. startXRef = stream.pos + 6;
  2593. }
  2594. } else {
  2595. // Find startxref by jumping backward from the end of the file.
  2596. var step = 1024;
  2597. var found = false, pos = stream.end;
  2598. while (!found && pos > 0) {
  2599. pos -= step - 'startxref'.length;
  2600. if (pos < 0) {
  2601. pos = 0;
  2602. }
  2603. stream.pos = pos;
  2604. found = find(stream, 'startxref', step, true);
  2605. }
  2606. if (found) {
  2607. stream.skip(9);
  2608. var ch;
  2609. do {
  2610. ch = stream.getByte();
  2611. } while (Lexer.isSpace(ch));
  2612. var str = '';
  2613. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2614. str += String.fromCharCode(ch);
  2615. ch = stream.getByte();
  2616. }
  2617. startXRef = parseInt(str, 10);
  2618. if (isNaN(startXRef)) {
  2619. startXRef = 0;
  2620. }
  2621. }
  2622. }
  2623. // shadow the prototype getter with a data property
  2624. return shadow(this, 'startXRef', startXRef);
  2625. },
  2626. get mainXRefEntriesOffset() {
  2627. var mainXRefEntriesOffset = 0;
  2628. var linearization = this.linearization;
  2629. if (linearization) {
  2630. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2631. }
  2632. // shadow the prototype getter with a data property
  2633. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2634. },
  2635. // Find the header, remove leading garbage and setup the stream
  2636. // starting from the header.
  2637. checkHeader: function PDFDocument_checkHeader() {
  2638. var stream = this.stream;
  2639. stream.reset();
  2640. if (find(stream, '%PDF-', 1024)) {
  2641. // Found the header, trim off any garbage before it.
  2642. stream.moveStart();
  2643. // Reading file format version
  2644. var MAX_VERSION_LENGTH = 12;
  2645. var version = '', ch;
  2646. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2647. if (version.length >= MAX_VERSION_LENGTH) {
  2648. break;
  2649. }
  2650. version += String.fromCharCode(ch);
  2651. }
  2652. // removing "%PDF-"-prefix
  2653. this.pdfFormatVersion = version.substring(5);
  2654. return;
  2655. }
  2656. // May not be a PDF file, continue anyway.
  2657. },
  2658. parseStartXRef: function PDFDocument_parseStartXRef() {
  2659. var startXRef = this.startXRef;
  2660. this.xref.setStartXRef(startXRef);
  2661. },
  2662. setup: function PDFDocument_setup(recoveryMode) {
  2663. this.xref.parse(recoveryMode);
  2664. this.catalog = new Catalog(this.pdfManager, this.xref);
  2665. },
  2666. get numPages() {
  2667. var linearization = this.linearization;
  2668. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2669. // shadow the prototype getter
  2670. return shadow(this, 'numPages', num);
  2671. },
  2672. get documentInfo() {
  2673. var docInfo = {
  2674. PDFFormatVersion: this.pdfFormatVersion,
  2675. IsAcroFormPresent: !!this.acroForm,
  2676. IsXFAPresent: !!this.xfa
  2677. };
  2678. var infoDict;
  2679. try {
  2680. infoDict = this.xref.trailer.get('Info');
  2681. } catch (err) {
  2682. info('The document information dictionary is invalid.');
  2683. }
  2684. if (infoDict) {
  2685. var validEntries = DocumentInfoValidators.entries;
  2686. // Only fill the document info with valid entries from the spec.
  2687. for (var key in validEntries) {
  2688. if (infoDict.has(key)) {
  2689. var value = infoDict.get(key);
  2690. // Make sure the value conforms to the spec.
  2691. if (validEntries[key](value)) {
  2692. docInfo[key] = (typeof value !== 'string' ?
  2693. value : stringToPDFString(value));
  2694. } else {
  2695. info('Bad value in document info for "' + key + '"');
  2696. }
  2697. }
  2698. }
  2699. }
  2700. return shadow(this, 'documentInfo', docInfo);
  2701. },
  2702. get fingerprint() {
  2703. var xref = this.xref, idArray, hash, fileID = '';
  2704. if (xref.trailer.has('ID')) {
  2705. idArray = xref.trailer.get('ID');
  2706. }
  2707. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2708. hash = stringToBytes(idArray[0]);
  2709. } else {
  2710. if (this.stream.ensureRange) {
  2711. this.stream.ensureRange(0,
  2712. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2713. }
  2714. hash = calculateMD5(this.stream.bytes.subarray(0,
  2715. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2716. }
  2717. for (var i = 0, n = hash.length; i < n; i++) {
  2718. var hex = hash[i].toString(16);
  2719. fileID += hex.length === 1 ? '0' + hex : hex;
  2720. }
  2721. return shadow(this, 'fingerprint', fileID);
  2722. },
  2723. getPage: function PDFDocument_getPage(pageIndex) {
  2724. return this.catalog.getPage(pageIndex);
  2725. },
  2726. cleanup: function PDFDocument_cleanup() {
  2727. return this.catalog.cleanup();
  2728. }
  2729. };
  2730. return PDFDocument;
  2731. })();
  2732. var Name = (function NameClosure() {
  2733. function Name(name) {
  2734. this.name = name;
  2735. }
  2736. Name.prototype = {};
  2737. var nameCache = {};
  2738. Name.get = function Name_get(name) {
  2739. var nameValue = nameCache[name];
  2740. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2741. };
  2742. return Name;
  2743. })();
  2744. var Cmd = (function CmdClosure() {
  2745. function Cmd(cmd) {
  2746. this.cmd = cmd;
  2747. }
  2748. Cmd.prototype = {};
  2749. var cmdCache = {};
  2750. Cmd.get = function Cmd_get(cmd) {
  2751. var cmdValue = cmdCache[cmd];
  2752. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2753. };
  2754. return Cmd;
  2755. })();
  2756. var Dict = (function DictClosure() {
  2757. var nonSerializable = function nonSerializableClosure() {
  2758. return nonSerializable; // creating closure on some variable
  2759. };
  2760. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2761. 'Background': true,
  2762. 'ExtGState': true,
  2763. 'Halftone': true,
  2764. 'Layout': true,
  2765. 'Mask': true,
  2766. 'Pagination': true,
  2767. 'Printing': true
  2768. };
  2769. function isRecursionAllowedFor(dict) {
  2770. if (!isName(dict.Type)) {
  2771. return true;
  2772. }
  2773. var dictType = dict.Type.name;
  2774. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2775. }
  2776. // xref is optional
  2777. function Dict(xref) {
  2778. // Map should only be used internally, use functions below to access.
  2779. this.map = Object.create(null);
  2780. this.xref = xref;
  2781. this.objId = null;
  2782. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2783. }
  2784. Dict.prototype = {
  2785. assignXref: function Dict_assignXref(newXref) {
  2786. this.xref = newXref;
  2787. },
  2788. // automatically dereferences Ref objects
  2789. get: function Dict_get(key1, key2, key3) {
  2790. var value;
  2791. var xref = this.xref;
  2792. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2793. typeof key2 === 'undefined') {
  2794. return xref ? xref.fetchIfRef(value) : value;
  2795. }
  2796. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2797. typeof key3 === 'undefined') {
  2798. return xref ? xref.fetchIfRef(value) : value;
  2799. }
  2800. value = this.map[key3] || null;
  2801. return xref ? xref.fetchIfRef(value) : value;
  2802. },
  2803. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2804. getAsync: function Dict_getAsync(key1, key2, key3) {
  2805. var value;
  2806. var xref = this.xref;
  2807. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2808. typeof key2 === 'undefined') {
  2809. if (xref) {
  2810. return xref.fetchIfRefAsync(value);
  2811. }
  2812. return Promise.resolve(value);
  2813. }
  2814. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2815. typeof key3 === 'undefined') {
  2816. if (xref) {
  2817. return xref.fetchIfRefAsync(value);
  2818. }
  2819. return Promise.resolve(value);
  2820. }
  2821. value = this.map[key3] || null;
  2822. if (xref) {
  2823. return xref.fetchIfRefAsync(value);
  2824. }
  2825. return Promise.resolve(value);
  2826. },
  2827. // no dereferencing
  2828. getRaw: function Dict_getRaw(key) {
  2829. return this.map[key];
  2830. },
  2831. // creates new map and dereferences all Refs
  2832. getAll: function Dict_getAll() {
  2833. var all = Object.create(null);
  2834. var queue = null;
  2835. var key, obj;
  2836. for (key in this.map) {
  2837. obj = this.get(key);
  2838. if (obj instanceof Dict) {
  2839. if (isRecursionAllowedFor(obj)) {
  2840. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2841. } else {
  2842. all[key] = this.getRaw(key);
  2843. }
  2844. } else {
  2845. all[key] = obj;
  2846. }
  2847. }
  2848. if (!queue) {
  2849. return all;
  2850. }
  2851. // trying to take cyclic references into the account
  2852. var processed = Object.create(null);
  2853. while (queue.length > 0) {
  2854. var item = queue.shift();
  2855. var itemObj = item.obj;
  2856. var objId = itemObj.objId;
  2857. if (objId && objId in processed) {
  2858. item.target[item.key] = processed[objId];
  2859. continue;
  2860. }
  2861. var dereferenced = Object.create(null);
  2862. for (key in itemObj.map) {
  2863. obj = itemObj.get(key);
  2864. if (obj instanceof Dict) {
  2865. if (isRecursionAllowedFor(obj)) {
  2866. queue.push({target: dereferenced, key: key, obj: obj});
  2867. } else {
  2868. dereferenced[key] = itemObj.getRaw(key);
  2869. }
  2870. } else {
  2871. dereferenced[key] = obj;
  2872. }
  2873. }
  2874. if (objId) {
  2875. processed[objId] = dereferenced;
  2876. }
  2877. item.target[item.key] = dereferenced;
  2878. }
  2879. return all;
  2880. },
  2881. set: function Dict_set(key, value) {
  2882. this.map[key] = value;
  2883. },
  2884. has: function Dict_has(key) {
  2885. return key in this.map;
  2886. },
  2887. forEach: function Dict_forEach(callback) {
  2888. for (var key in this.map) {
  2889. callback(key, this.get(key));
  2890. }
  2891. }
  2892. };
  2893. Dict.empty = new Dict(null);
  2894. return Dict;
  2895. })();
  2896. var Ref = (function RefClosure() {
  2897. function Ref(num, gen) {
  2898. this.num = num;
  2899. this.gen = gen;
  2900. }
  2901. Ref.prototype = {
  2902. toString: function Ref_toString() {
  2903. // This function is hot, so we make the string as compact as possible.
  2904. // |this.gen| is almost always zero, so we treat that case specially.
  2905. var str = this.num + 'R';
  2906. if (this.gen !== 0) {
  2907. str += this.gen;
  2908. }
  2909. return str;
  2910. }
  2911. };
  2912. return Ref;
  2913. })();
  2914. // The reference is identified by number and generation.
  2915. // This structure stores only one instance of the reference.
  2916. var RefSet = (function RefSetClosure() {
  2917. function RefSet() {
  2918. this.dict = {};
  2919. }
  2920. RefSet.prototype = {
  2921. has: function RefSet_has(ref) {
  2922. return ref.toString() in this.dict;
  2923. },
  2924. put: function RefSet_put(ref) {
  2925. this.dict[ref.toString()] = true;
  2926. },
  2927. remove: function RefSet_remove(ref) {
  2928. delete this.dict[ref.toString()];
  2929. }
  2930. };
  2931. return RefSet;
  2932. })();
  2933. var RefSetCache = (function RefSetCacheClosure() {
  2934. function RefSetCache() {
  2935. this.dict = Object.create(null);
  2936. }
  2937. RefSetCache.prototype = {
  2938. get: function RefSetCache_get(ref) {
  2939. return this.dict[ref.toString()];
  2940. },
  2941. has: function RefSetCache_has(ref) {
  2942. return ref.toString() in this.dict;
  2943. },
  2944. put: function RefSetCache_put(ref, obj) {
  2945. this.dict[ref.toString()] = obj;
  2946. },
  2947. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2948. this.dict[ref.toString()] = this.get(aliasRef);
  2949. },
  2950. forEach: function RefSetCache_forEach(fn, thisArg) {
  2951. for (var i in this.dict) {
  2952. fn.call(thisArg, this.dict[i]);
  2953. }
  2954. },
  2955. clear: function RefSetCache_clear() {
  2956. this.dict = Object.create(null);
  2957. }
  2958. };
  2959. return RefSetCache;
  2960. })();
  2961. var Catalog = (function CatalogClosure() {
  2962. function Catalog(pdfManager, xref) {
  2963. this.pdfManager = pdfManager;
  2964. this.xref = xref;
  2965. this.catDict = xref.getCatalogObj();
  2966. this.fontCache = new RefSetCache();
  2967. assert(isDict(this.catDict),
  2968. 'catalog object is not a dictionary');
  2969. this.pagePromises = [];
  2970. }
  2971. Catalog.prototype = {
  2972. get metadata() {
  2973. var streamRef = this.catDict.getRaw('Metadata');
  2974. if (!isRef(streamRef)) {
  2975. return shadow(this, 'metadata', null);
  2976. }
  2977. var encryptMetadata = (!this.xref.encrypt ? false :
  2978. this.xref.encrypt.encryptMetadata);
  2979. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2980. var metadata;
  2981. if (stream && isDict(stream.dict)) {
  2982. var type = stream.dict.get('Type');
  2983. var subtype = stream.dict.get('Subtype');
  2984. if (isName(type) && isName(subtype) &&
  2985. type.name === 'Metadata' && subtype.name === 'XML') {
  2986. // XXX: This should examine the charset the XML document defines,
  2987. // however since there are currently no real means to decode
  2988. // arbitrary charsets, let's just hope that the author of the PDF
  2989. // was reasonable enough to stick with the XML default charset,
  2990. // which is UTF-8.
  2991. try {
  2992. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2993. } catch (e) {
  2994. info('Skipping invalid metadata.');
  2995. }
  2996. }
  2997. }
  2998. return shadow(this, 'metadata', metadata);
  2999. },
  3000. get toplevelPagesDict() {
  3001. var pagesObj = this.catDict.get('Pages');
  3002. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3003. // shadow the prototype getter
  3004. return shadow(this, 'toplevelPagesDict', pagesObj);
  3005. },
  3006. get documentOutline() {
  3007. var obj = null;
  3008. try {
  3009. obj = this.readDocumentOutline();
  3010. } catch (ex) {
  3011. if (ex instanceof MissingDataException) {
  3012. throw ex;
  3013. }
  3014. warn('Unable to read document outline');
  3015. }
  3016. return shadow(this, 'documentOutline', obj);
  3017. },
  3018. readDocumentOutline: function Catalog_readDocumentOutline() {
  3019. var xref = this.xref;
  3020. var obj = this.catDict.get('Outlines');
  3021. var root = { items: [] };
  3022. if (isDict(obj)) {
  3023. obj = obj.getRaw('First');
  3024. var processed = new RefSet();
  3025. if (isRef(obj)) {
  3026. var queue = [{obj: obj, parent: root}];
  3027. // to avoid recursion keeping track of the items
  3028. // in the processed dictionary
  3029. processed.put(obj);
  3030. while (queue.length > 0) {
  3031. var i = queue.shift();
  3032. var outlineDict = xref.fetchIfRef(i.obj);
  3033. if (outlineDict === null) {
  3034. continue;
  3035. }
  3036. if (!outlineDict.has('Title')) {
  3037. error('Invalid outline item');
  3038. }
  3039. var dest = outlineDict.get('A');
  3040. if (dest) {
  3041. dest = dest.get('D');
  3042. } else if (outlineDict.has('Dest')) {
  3043. dest = outlineDict.getRaw('Dest');
  3044. if (isName(dest)) {
  3045. dest = dest.name;
  3046. }
  3047. }
  3048. var title = outlineDict.get('Title');
  3049. var outlineItem = {
  3050. dest: dest,
  3051. title: stringToPDFString(title),
  3052. color: outlineDict.get('C') || [0, 0, 0],
  3053. count: outlineDict.get('Count'),
  3054. bold: !!(outlineDict.get('F') & 2),
  3055. italic: !!(outlineDict.get('F') & 1),
  3056. items: []
  3057. };
  3058. i.parent.items.push(outlineItem);
  3059. obj = outlineDict.getRaw('First');
  3060. if (isRef(obj) && !processed.has(obj)) {
  3061. queue.push({obj: obj, parent: outlineItem});
  3062. processed.put(obj);
  3063. }
  3064. obj = outlineDict.getRaw('Next');
  3065. if (isRef(obj) && !processed.has(obj)) {
  3066. queue.push({obj: obj, parent: i.parent});
  3067. processed.put(obj);
  3068. }
  3069. }
  3070. }
  3071. }
  3072. return (root.items.length > 0 ? root.items : null);
  3073. },
  3074. get numPages() {
  3075. var obj = this.toplevelPagesDict.get('Count');
  3076. assert(
  3077. isInt(obj),
  3078. 'page count in top level pages object is not an integer'
  3079. );
  3080. // shadow the prototype getter
  3081. return shadow(this, 'num', obj);
  3082. },
  3083. get destinations() {
  3084. function fetchDestination(dest) {
  3085. return isDict(dest) ? dest.get('D') : dest;
  3086. }
  3087. var xref = this.xref;
  3088. var dests = {}, nameTreeRef, nameDictionaryRef;
  3089. var obj = this.catDict.get('Names');
  3090. if (obj && obj.has('Dests')) {
  3091. nameTreeRef = obj.getRaw('Dests');
  3092. } else if (this.catDict.has('Dests')) {
  3093. nameDictionaryRef = this.catDict.get('Dests');
  3094. }
  3095. if (nameDictionaryRef) {
  3096. // reading simple destination dictionary
  3097. obj = nameDictionaryRef;
  3098. obj.forEach(function catalogForEach(key, value) {
  3099. if (!value) {
  3100. return;
  3101. }
  3102. dests[key] = fetchDestination(value);
  3103. });
  3104. }
  3105. if (nameTreeRef) {
  3106. var nameTree = new NameTree(nameTreeRef, xref);
  3107. var names = nameTree.getAll();
  3108. for (var name in names) {
  3109. if (!names.hasOwnProperty(name)) {
  3110. continue;
  3111. }
  3112. dests[name] = fetchDestination(names[name]);
  3113. }
  3114. }
  3115. return shadow(this, 'destinations', dests);
  3116. },
  3117. getDestination: function Catalog_getDestination(destinationId) {
  3118. function fetchDestination(dest) {
  3119. return isDict(dest) ? dest.get('D') : dest;
  3120. }
  3121. var xref = this.xref;
  3122. var dest, nameTreeRef, nameDictionaryRef;
  3123. var obj = this.catDict.get('Names');
  3124. if (obj && obj.has('Dests')) {
  3125. nameTreeRef = obj.getRaw('Dests');
  3126. } else if (this.catDict.has('Dests')) {
  3127. nameDictionaryRef = this.catDict.get('Dests');
  3128. }
  3129. if (nameDictionaryRef) {
  3130. // reading simple destination dictionary
  3131. obj = nameDictionaryRef;
  3132. obj.forEach(function catalogForEach(key, value) {
  3133. if (!value) {
  3134. return;
  3135. }
  3136. if (key === destinationId) {
  3137. dest = fetchDestination(value);
  3138. }
  3139. });
  3140. }
  3141. if (nameTreeRef) {
  3142. var nameTree = new NameTree(nameTreeRef, xref);
  3143. dest = fetchDestination(nameTree.get(destinationId));
  3144. }
  3145. return dest;
  3146. },
  3147. get attachments() {
  3148. var xref = this.xref;
  3149. var attachments = null, nameTreeRef;
  3150. var obj = this.catDict.get('Names');
  3151. if (obj) {
  3152. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3153. }
  3154. if (nameTreeRef) {
  3155. var nameTree = new NameTree(nameTreeRef, xref);
  3156. var names = nameTree.getAll();
  3157. for (var name in names) {
  3158. if (!names.hasOwnProperty(name)) {
  3159. continue;
  3160. }
  3161. var fs = new FileSpec(names[name], xref);
  3162. if (!attachments) {
  3163. attachments = {};
  3164. }
  3165. attachments[stringToPDFString(name)] = fs.serializable;
  3166. }
  3167. }
  3168. return shadow(this, 'attachments', attachments);
  3169. },
  3170. get javaScript() {
  3171. var xref = this.xref;
  3172. var obj = this.catDict.get('Names');
  3173. var javaScript = [];
  3174. if (obj && obj.has('JavaScript')) {
  3175. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3176. var names = nameTree.getAll();
  3177. for (var name in names) {
  3178. if (!names.hasOwnProperty(name)) {
  3179. continue;
  3180. }
  3181. // We don't really use the JavaScript right now. This code is
  3182. // defensive so we don't cause errors on document load.
  3183. var jsDict = names[name];
  3184. if (!isDict(jsDict)) {
  3185. continue;
  3186. }
  3187. var type = jsDict.get('S');
  3188. if (!isName(type) || type.name !== 'JavaScript') {
  3189. continue;
  3190. }
  3191. var js = jsDict.get('JS');
  3192. if (!isString(js) && !isStream(js)) {
  3193. continue;
  3194. }
  3195. if (isStream(js)) {
  3196. js = bytesToString(js.getBytes());
  3197. }
  3198. javaScript.push(stringToPDFString(js));
  3199. }
  3200. }
  3201. // Append OpenAction actions to javaScript array
  3202. var openactionDict = this.catDict.get('OpenAction');
  3203. if (isDict(openactionDict)) {
  3204. var objType = openactionDict.get('Type');
  3205. var actionType = openactionDict.get('S');
  3206. var action = openactionDict.get('N');
  3207. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3208. isName(actionType) && actionType.name === 'Named' &&
  3209. isName(action) && action.name === 'Print');
  3210. if (isPrintAction) {
  3211. javaScript.push('print(true);');
  3212. }
  3213. }
  3214. return shadow(this, 'javaScript', javaScript);
  3215. },
  3216. cleanup: function Catalog_cleanup() {
  3217. var promises = [];
  3218. this.fontCache.forEach(function (promise) {
  3219. promises.push(promise);
  3220. });
  3221. return Promise.all(promises).then(function (translatedFonts) {
  3222. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3223. var font = translatedFonts[i].dict;
  3224. delete font.translated;
  3225. }
  3226. this.fontCache.clear();
  3227. }.bind(this));
  3228. },
  3229. getPage: function Catalog_getPage(pageIndex) {
  3230. if (!(pageIndex in this.pagePromises)) {
  3231. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3232. function (a) {
  3233. var dict = a[0];
  3234. var ref = a[1];
  3235. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3236. this.fontCache);
  3237. }.bind(this)
  3238. );
  3239. }
  3240. return this.pagePromises[pageIndex];
  3241. },
  3242. getPageDict: function Catalog_getPageDict(pageIndex) {
  3243. var capability = createPromiseCapability();
  3244. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3245. var currentPageIndex = 0;
  3246. var xref = this.xref;
  3247. function next() {
  3248. while (nodesToVisit.length) {
  3249. var currentNode = nodesToVisit.pop();
  3250. if (isRef(currentNode)) {
  3251. xref.fetchAsync(currentNode).then(function (obj) {
  3252. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3253. if (pageIndex === currentPageIndex) {
  3254. capability.resolve([obj, currentNode]);
  3255. } else {
  3256. currentPageIndex++;
  3257. next();
  3258. }
  3259. return;
  3260. }
  3261. nodesToVisit.push(obj);
  3262. next();
  3263. }, capability.reject);
  3264. return;
  3265. }
  3266. // must be a child page dictionary
  3267. assert(
  3268. isDict(currentNode),
  3269. 'page dictionary kid reference points to wrong type of object'
  3270. );
  3271. var count = currentNode.get('Count');
  3272. // Skip nodes where the page can't be.
  3273. if (currentPageIndex + count <= pageIndex) {
  3274. currentPageIndex += count;
  3275. continue;
  3276. }
  3277. var kids = currentNode.get('Kids');
  3278. assert(isArray(kids), 'page dictionary kids object is not an array');
  3279. if (count === kids.length) {
  3280. // Nodes that don't have the page have been skipped and this is the
  3281. // bottom of the tree which means the page requested must be a
  3282. // descendant of this pages node. Ideally we would just resolve the
  3283. // promise with the page ref here, but there is the case where more
  3284. // pages nodes could link to single a page (see issue 3666 pdf). To
  3285. // handle this push it back on the queue so if it is a pages node it
  3286. // will be descended into.
  3287. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3288. currentPageIndex = pageIndex;
  3289. continue;
  3290. } else {
  3291. for (var last = kids.length - 1; last >= 0; last--) {
  3292. nodesToVisit.push(kids[last]);
  3293. }
  3294. }
  3295. }
  3296. capability.reject('Page index ' + pageIndex + ' not found.');
  3297. }
  3298. next();
  3299. return capability.promise;
  3300. },
  3301. getPageIndex: function Catalog_getPageIndex(ref) {
  3302. // The page tree nodes have the count of all the leaves below them. To get
  3303. // how many pages are before we just have to walk up the tree and keep
  3304. // adding the count of siblings to the left of the node.
  3305. var xref = this.xref;
  3306. function pagesBeforeRef(kidRef) {
  3307. var total = 0;
  3308. var parentRef;
  3309. return xref.fetchAsync(kidRef).then(function (node) {
  3310. if (!node) {
  3311. return null;
  3312. }
  3313. parentRef = node.getRaw('Parent');
  3314. return node.getAsync('Parent');
  3315. }).then(function (parent) {
  3316. if (!parent) {
  3317. return null;
  3318. }
  3319. return parent.getAsync('Kids');
  3320. }).then(function (kids) {
  3321. if (!kids) {
  3322. return null;
  3323. }
  3324. var kidPromises = [];
  3325. var found = false;
  3326. for (var i = 0; i < kids.length; i++) {
  3327. var kid = kids[i];
  3328. assert(isRef(kid), 'kids must be a ref');
  3329. if (kid.num === kidRef.num) {
  3330. found = true;
  3331. break;
  3332. }
  3333. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3334. if (kid.has('Count')) {
  3335. var count = kid.get('Count');
  3336. total += count;
  3337. } else { // page leaf node
  3338. total++;
  3339. }
  3340. }));
  3341. }
  3342. if (!found) {
  3343. error('kid ref not found in parents kids');
  3344. }
  3345. return Promise.all(kidPromises).then(function () {
  3346. return [total, parentRef];
  3347. });
  3348. });
  3349. }
  3350. var total = 0;
  3351. function next(ref) {
  3352. return pagesBeforeRef(ref).then(function (args) {
  3353. if (!args) {
  3354. return total;
  3355. }
  3356. var count = args[0];
  3357. var parentRef = args[1];
  3358. total += count;
  3359. return next(parentRef);
  3360. });
  3361. }
  3362. return next(ref);
  3363. }
  3364. };
  3365. return Catalog;
  3366. })();
  3367. var XRef = (function XRefClosure() {
  3368. function XRef(stream, password) {
  3369. this.stream = stream;
  3370. this.entries = [];
  3371. this.xrefstms = {};
  3372. // prepare the XRef cache
  3373. this.cache = [];
  3374. this.password = password;
  3375. this.stats = {
  3376. streamTypes: [],
  3377. fontTypes: []
  3378. };
  3379. }
  3380. XRef.prototype = {
  3381. setStartXRef: function XRef_setStartXRef(startXRef) {
  3382. // Store the starting positions of xref tables as we process them
  3383. // so we can recover from missing data errors
  3384. this.startXRefQueue = [startXRef];
  3385. },
  3386. parse: function XRef_parse(recoveryMode) {
  3387. var trailerDict;
  3388. if (!recoveryMode) {
  3389. trailerDict = this.readXRef();
  3390. } else {
  3391. warn('Indexing all PDF objects');
  3392. trailerDict = this.indexObjects();
  3393. }
  3394. trailerDict.assignXref(this);
  3395. this.trailer = trailerDict;
  3396. var encrypt = trailerDict.get('Encrypt');
  3397. if (encrypt) {
  3398. var ids = trailerDict.get('ID');
  3399. var fileId = (ids && ids.length) ? ids[0] : '';
  3400. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3401. this.password);
  3402. }
  3403. // get the root dictionary (catalog) object
  3404. if (!(this.root = trailerDict.get('Root'))) {
  3405. error('Invalid root reference');
  3406. }
  3407. },
  3408. processXRefTable: function XRef_processXRefTable(parser) {
  3409. if (!('tableState' in this)) {
  3410. // Stores state of the table as we process it so we can resume
  3411. // from middle of table in case of missing data error
  3412. this.tableState = {
  3413. entryNum: 0,
  3414. streamPos: parser.lexer.stream.pos,
  3415. parserBuf1: parser.buf1,
  3416. parserBuf2: parser.buf2
  3417. };
  3418. }
  3419. var obj = this.readXRefTable(parser);
  3420. // Sanity check
  3421. if (!isCmd(obj, 'trailer')) {
  3422. error('Invalid XRef table: could not find trailer dictionary');
  3423. }
  3424. // Read trailer dictionary, e.g.
  3425. // trailer
  3426. // << /Size 22
  3427. // /Root 20R
  3428. // /Info 10R
  3429. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3430. // >>
  3431. // The parser goes through the entire stream << ... >> and provides
  3432. // a getter interface for the key-value table
  3433. var dict = parser.getObj();
  3434. // The pdflib PDF generator can generate a nested trailer dictionary
  3435. if (!isDict(dict) && dict.dict) {
  3436. dict = dict.dict;
  3437. }
  3438. if (!isDict(dict)) {
  3439. error('Invalid XRef table: could not parse trailer dictionary');
  3440. }
  3441. delete this.tableState;
  3442. return dict;
  3443. },
  3444. readXRefTable: function XRef_readXRefTable(parser) {
  3445. // Example of cross-reference table:
  3446. // xref
  3447. // 0 1 <-- subsection header (first obj #, obj count)
  3448. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3449. // 23 2 <-- subsection header ... and so on ...
  3450. // 0000025518 00002 n
  3451. // 0000025635 00000 n
  3452. // trailer
  3453. // ...
  3454. var stream = parser.lexer.stream;
  3455. var tableState = this.tableState;
  3456. stream.pos = tableState.streamPos;
  3457. parser.buf1 = tableState.parserBuf1;
  3458. parser.buf2 = tableState.parserBuf2;
  3459. // Outer loop is over subsection headers
  3460. var obj;
  3461. while (true) {
  3462. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3463. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3464. break;
  3465. }
  3466. tableState.firstEntryNum = obj;
  3467. tableState.entryCount = parser.getObj();
  3468. }
  3469. var first = tableState.firstEntryNum;
  3470. var count = tableState.entryCount;
  3471. if (!isInt(first) || !isInt(count)) {
  3472. error('Invalid XRef table: wrong types in subsection header');
  3473. }
  3474. // Inner loop is over objects themselves
  3475. for (var i = tableState.entryNum; i < count; i++) {
  3476. tableState.streamPos = stream.pos;
  3477. tableState.entryNum = i;
  3478. tableState.parserBuf1 = parser.buf1;
  3479. tableState.parserBuf2 = parser.buf2;
  3480. var entry = {};
  3481. entry.offset = parser.getObj();
  3482. entry.gen = parser.getObj();
  3483. var type = parser.getObj();
  3484. if (isCmd(type, 'f')) {
  3485. entry.free = true;
  3486. } else if (isCmd(type, 'n')) {
  3487. entry.uncompressed = true;
  3488. }
  3489. // Validate entry obj
  3490. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3491. !(entry.free || entry.uncompressed)) {
  3492. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3493. }
  3494. if (!this.entries[i + first]) {
  3495. this.entries[i + first] = entry;
  3496. }
  3497. }
  3498. tableState.entryNum = 0;
  3499. tableState.streamPos = stream.pos;
  3500. tableState.parserBuf1 = parser.buf1;
  3501. tableState.parserBuf2 = parser.buf2;
  3502. delete tableState.firstEntryNum;
  3503. delete tableState.entryCount;
  3504. }
  3505. // Per issue 3248: hp scanners generate bad XRef
  3506. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3507. // shifting the entries
  3508. this.entries.shift();
  3509. }
  3510. // Sanity check: as per spec, first object must be free
  3511. if (this.entries[0] && !this.entries[0].free) {
  3512. error('Invalid XRef table: unexpected first object');
  3513. }
  3514. return obj;
  3515. },
  3516. processXRefStream: function XRef_processXRefStream(stream) {
  3517. if (!('streamState' in this)) {
  3518. // Stores state of the stream as we process it so we can resume
  3519. // from middle of stream in case of missing data error
  3520. var streamParameters = stream.dict;
  3521. var byteWidths = streamParameters.get('W');
  3522. var range = streamParameters.get('Index');
  3523. if (!range) {
  3524. range = [0, streamParameters.get('Size')];
  3525. }
  3526. this.streamState = {
  3527. entryRanges: range,
  3528. byteWidths: byteWidths,
  3529. entryNum: 0,
  3530. streamPos: stream.pos
  3531. };
  3532. }
  3533. this.readXRefStream(stream);
  3534. delete this.streamState;
  3535. return stream.dict;
  3536. },
  3537. readXRefStream: function XRef_readXRefStream(stream) {
  3538. var i, j;
  3539. var streamState = this.streamState;
  3540. stream.pos = streamState.streamPos;
  3541. var byteWidths = streamState.byteWidths;
  3542. var typeFieldWidth = byteWidths[0];
  3543. var offsetFieldWidth = byteWidths[1];
  3544. var generationFieldWidth = byteWidths[2];
  3545. var entryRanges = streamState.entryRanges;
  3546. while (entryRanges.length > 0) {
  3547. var first = entryRanges[0];
  3548. var n = entryRanges[1];
  3549. if (!isInt(first) || !isInt(n)) {
  3550. error('Invalid XRef range fields: ' + first + ', ' + n);
  3551. }
  3552. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3553. !isInt(generationFieldWidth)) {
  3554. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3555. }
  3556. for (i = streamState.entryNum; i < n; ++i) {
  3557. streamState.entryNum = i;
  3558. streamState.streamPos = stream.pos;
  3559. var type = 0, offset = 0, generation = 0;
  3560. for (j = 0; j < typeFieldWidth; ++j) {
  3561. type = (type << 8) | stream.getByte();
  3562. }
  3563. // if type field is absent, its default value is 1
  3564. if (typeFieldWidth === 0) {
  3565. type = 1;
  3566. }
  3567. for (j = 0; j < offsetFieldWidth; ++j) {
  3568. offset = (offset << 8) | stream.getByte();
  3569. }
  3570. for (j = 0; j < generationFieldWidth; ++j) {
  3571. generation = (generation << 8) | stream.getByte();
  3572. }
  3573. var entry = {};
  3574. entry.offset = offset;
  3575. entry.gen = generation;
  3576. switch (type) {
  3577. case 0:
  3578. entry.free = true;
  3579. break;
  3580. case 1:
  3581. entry.uncompressed = true;
  3582. break;
  3583. case 2:
  3584. break;
  3585. default:
  3586. error('Invalid XRef entry type: ' + type);
  3587. }
  3588. if (!this.entries[first + i]) {
  3589. this.entries[first + i] = entry;
  3590. }
  3591. }
  3592. streamState.entryNum = 0;
  3593. streamState.streamPos = stream.pos;
  3594. entryRanges.splice(0, 2);
  3595. }
  3596. },
  3597. indexObjects: function XRef_indexObjects() {
  3598. // Simple scan through the PDF content to find objects,
  3599. // trailers and XRef streams.
  3600. function readToken(data, offset) {
  3601. var token = '', ch = data[offset];
  3602. while (ch !== 13 && ch !== 10) {
  3603. if (++offset >= data.length) {
  3604. break;
  3605. }
  3606. token += String.fromCharCode(ch);
  3607. ch = data[offset];
  3608. }
  3609. return token;
  3610. }
  3611. function skipUntil(data, offset, what) {
  3612. var length = what.length, dataLength = data.length;
  3613. var skipped = 0;
  3614. // finding byte sequence
  3615. while (offset < dataLength) {
  3616. var i = 0;
  3617. while (i < length && data[offset + i] === what[i]) {
  3618. ++i;
  3619. }
  3620. if (i >= length) {
  3621. break; // sequence found
  3622. }
  3623. offset++;
  3624. skipped++;
  3625. }
  3626. return skipped;
  3627. }
  3628. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3629. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3630. 101, 102]);
  3631. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3632. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3633. var stream = this.stream;
  3634. stream.pos = 0;
  3635. var buffer = stream.getBytes();
  3636. var position = stream.start, length = buffer.length;
  3637. var trailers = [], xrefStms = [];
  3638. while (position < length) {
  3639. var ch = buffer[position];
  3640. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3641. ++position;
  3642. continue;
  3643. }
  3644. if (ch === 37) { // %-comment
  3645. do {
  3646. ++position;
  3647. if (position >= length) {
  3648. break;
  3649. }
  3650. ch = buffer[position];
  3651. } while (ch !== 13 && ch !== 10);
  3652. continue;
  3653. }
  3654. var token = readToken(buffer, position);
  3655. var m;
  3656. if (token === 'xref') {
  3657. position += skipUntil(buffer, position, trailerBytes);
  3658. trailers.push(position);
  3659. position += skipUntil(buffer, position, startxrefBytes);
  3660. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3661. this.entries[m[1]] = {
  3662. offset: position,
  3663. gen: m[2] | 0,
  3664. uncompressed: true
  3665. };
  3666. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3667. var content = buffer.subarray(position, position + contentLength);
  3668. // checking XRef stream suspect
  3669. // (it shall have '/XRef' and next char is not a letter)
  3670. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3671. if (xrefTagOffset < contentLength &&
  3672. content[xrefTagOffset + 5] < 64) {
  3673. xrefStms.push(position);
  3674. this.xrefstms[position] = 1; // don't read it recursively
  3675. }
  3676. position += contentLength;
  3677. } else {
  3678. position += token.length + 1;
  3679. }
  3680. }
  3681. // reading XRef streams
  3682. var i, ii;
  3683. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3684. this.startXRefQueue.push(xrefStms[i]);
  3685. this.readXRef(/* recoveryMode */ true);
  3686. }
  3687. // finding main trailer
  3688. var dict;
  3689. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3690. stream.pos = trailers[i];
  3691. var parser = new Parser(new Lexer(stream), true, this);
  3692. var obj = parser.getObj();
  3693. if (!isCmd(obj, 'trailer')) {
  3694. continue;
  3695. }
  3696. // read the trailer dictionary
  3697. if (!isDict(dict = parser.getObj())) {
  3698. continue;
  3699. }
  3700. // taking the first one with 'ID'
  3701. if (dict.has('ID')) {
  3702. return dict;
  3703. }
  3704. }
  3705. // no tailer with 'ID', taking last one (if exists)
  3706. if (dict) {
  3707. return dict;
  3708. }
  3709. // nothing helps
  3710. // calling error() would reject worker with an UnknownErrorException.
  3711. throw new InvalidPDFException('Invalid PDF structure');
  3712. },
  3713. readXRef: function XRef_readXRef(recoveryMode) {
  3714. var stream = this.stream;
  3715. try {
  3716. while (this.startXRefQueue.length) {
  3717. var startXRef = this.startXRefQueue[0];
  3718. stream.pos = startXRef + stream.start;
  3719. var parser = new Parser(new Lexer(stream), true, this);
  3720. var obj = parser.getObj();
  3721. var dict;
  3722. // Get dictionary
  3723. if (isCmd(obj, 'xref')) {
  3724. // Parse end-of-file XRef
  3725. dict = this.processXRefTable(parser);
  3726. if (!this.topDict) {
  3727. this.topDict = dict;
  3728. }
  3729. // Recursively get other XRefs 'XRefStm', if any
  3730. obj = dict.get('XRefStm');
  3731. if (isInt(obj)) {
  3732. var pos = obj;
  3733. // ignore previously loaded xref streams
  3734. // (possible infinite recursion)
  3735. if (!(pos in this.xrefstms)) {
  3736. this.xrefstms[pos] = 1;
  3737. this.startXRefQueue.push(pos);
  3738. }
  3739. }
  3740. } else if (isInt(obj)) {
  3741. // Parse in-stream XRef
  3742. if (!isInt(parser.getObj()) ||
  3743. !isCmd(parser.getObj(), 'obj') ||
  3744. !isStream(obj = parser.getObj())) {
  3745. error('Invalid XRef stream');
  3746. }
  3747. dict = this.processXRefStream(obj);
  3748. if (!this.topDict) {
  3749. this.topDict = dict;
  3750. }
  3751. if (!dict) {
  3752. error('Failed to read XRef stream');
  3753. }
  3754. } else {
  3755. error('Invalid XRef stream header');
  3756. }
  3757. // Recursively get previous dictionary, if any
  3758. obj = dict.get('Prev');
  3759. if (isInt(obj)) {
  3760. this.startXRefQueue.push(obj);
  3761. } else if (isRef(obj)) {
  3762. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3763. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3764. this.startXRefQueue.push(obj.num);
  3765. }
  3766. this.startXRefQueue.shift();
  3767. }
  3768. return this.topDict;
  3769. } catch (e) {
  3770. if (e instanceof MissingDataException) {
  3771. throw e;
  3772. }
  3773. info('(while reading XRef): ' + e);
  3774. }
  3775. if (recoveryMode) {
  3776. return;
  3777. }
  3778. throw new XRefParseException();
  3779. },
  3780. getEntry: function XRef_getEntry(i) {
  3781. var xrefEntry = this.entries[i];
  3782. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3783. return xrefEntry;
  3784. }
  3785. return null;
  3786. },
  3787. fetchIfRef: function XRef_fetchIfRef(obj) {
  3788. if (!isRef(obj)) {
  3789. return obj;
  3790. }
  3791. return this.fetch(obj);
  3792. },
  3793. fetch: function XRef_fetch(ref, suppressEncryption) {
  3794. assert(isRef(ref), 'ref object is not a reference');
  3795. var num = ref.num;
  3796. if (num in this.cache) {
  3797. var cacheEntry = this.cache[num];
  3798. return cacheEntry;
  3799. }
  3800. var xrefEntry = this.getEntry(num);
  3801. // the referenced entry can be free
  3802. if (xrefEntry === null) {
  3803. return (this.cache[num] = null);
  3804. }
  3805. if (xrefEntry.uncompressed) {
  3806. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3807. } else {
  3808. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3809. }
  3810. if (isDict(xrefEntry)){
  3811. xrefEntry.objId = ref.toString();
  3812. } else if (isStream(xrefEntry)) {
  3813. xrefEntry.dict.objId = ref.toString();
  3814. }
  3815. return xrefEntry;
  3816. },
  3817. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3818. suppressEncryption) {
  3819. var gen = ref.gen;
  3820. var num = ref.num;
  3821. if (xrefEntry.gen !== gen) {
  3822. error('inconsistent generation in XRef');
  3823. }
  3824. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3825. this.stream.start);
  3826. var parser = new Parser(new Lexer(stream), true, this);
  3827. var obj1 = parser.getObj();
  3828. var obj2 = parser.getObj();
  3829. var obj3 = parser.getObj();
  3830. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3831. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3832. !isCmd(obj3)) {
  3833. error('bad XRef entry');
  3834. }
  3835. if (!isCmd(obj3, 'obj')) {
  3836. // some bad PDFs use "obj1234" and really mean 1234
  3837. if (obj3.cmd.indexOf('obj') === 0) {
  3838. num = parseInt(obj3.cmd.substring(3), 10);
  3839. if (!isNaN(num)) {
  3840. return num;
  3841. }
  3842. }
  3843. error('bad XRef entry');
  3844. }
  3845. if (this.encrypt && !suppressEncryption) {
  3846. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3847. } else {
  3848. xrefEntry = parser.getObj();
  3849. }
  3850. if (!isStream(xrefEntry)) {
  3851. this.cache[num] = xrefEntry;
  3852. }
  3853. return xrefEntry;
  3854. },
  3855. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3856. suppressEncryption) {
  3857. var tableOffset = xrefEntry.offset;
  3858. var stream = this.fetch(new Ref(tableOffset, 0));
  3859. if (!isStream(stream)) {
  3860. error('bad ObjStm stream');
  3861. }
  3862. var first = stream.dict.get('First');
  3863. var n = stream.dict.get('N');
  3864. if (!isInt(first) || !isInt(n)) {
  3865. error('invalid first and n parameters for ObjStm stream');
  3866. }
  3867. var parser = new Parser(new Lexer(stream), false, this);
  3868. parser.allowStreams = true;
  3869. var i, entries = [], num, nums = [];
  3870. // read the object numbers to populate cache
  3871. for (i = 0; i < n; ++i) {
  3872. num = parser.getObj();
  3873. if (!isInt(num)) {
  3874. error('invalid object number in the ObjStm stream: ' + num);
  3875. }
  3876. nums.push(num);
  3877. var offset = parser.getObj();
  3878. if (!isInt(offset)) {
  3879. error('invalid object offset in the ObjStm stream: ' + offset);
  3880. }
  3881. }
  3882. // read stream objects for cache
  3883. for (i = 0; i < n; ++i) {
  3884. entries.push(parser.getObj());
  3885. num = nums[i];
  3886. var entry = this.entries[num];
  3887. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3888. this.cache[num] = entries[i];
  3889. }
  3890. }
  3891. xrefEntry = entries[xrefEntry.gen];
  3892. if (xrefEntry === undefined) {
  3893. error('bad XRef entry for compressed object');
  3894. }
  3895. return xrefEntry;
  3896. },
  3897. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3898. if (!isRef(obj)) {
  3899. return Promise.resolve(obj);
  3900. }
  3901. return this.fetchAsync(obj);
  3902. },
  3903. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3904. var streamManager = this.stream.manager;
  3905. var xref = this;
  3906. return new Promise(function tryFetch(resolve, reject) {
  3907. try {
  3908. resolve(xref.fetch(ref, suppressEncryption));
  3909. } catch (e) {
  3910. if (e instanceof MissingDataException) {
  3911. streamManager.requestRange(e.begin, e.end, function () {
  3912. tryFetch(resolve, reject);
  3913. });
  3914. return;
  3915. }
  3916. reject(e);
  3917. }
  3918. });
  3919. },
  3920. getCatalogObj: function XRef_getCatalogObj() {
  3921. return this.root;
  3922. }
  3923. };
  3924. return XRef;
  3925. })();
  3926. /**
  3927. * A NameTree is like a Dict but has some advantageous properties, see the
  3928. * spec (7.9.6) for more details.
  3929. * TODO: implement all the Dict functions and make this more efficent.
  3930. */
  3931. var NameTree = (function NameTreeClosure() {
  3932. function NameTree(root, xref) {
  3933. this.root = root;
  3934. this.xref = xref;
  3935. }
  3936. NameTree.prototype = {
  3937. getAll: function NameTree_getAll() {
  3938. var dict = {};
  3939. if (!this.root) {
  3940. return dict;
  3941. }
  3942. var xref = this.xref;
  3943. // reading name tree
  3944. var processed = new RefSet();
  3945. processed.put(this.root);
  3946. var queue = [this.root];
  3947. while (queue.length > 0) {
  3948. var i, n;
  3949. var obj = xref.fetchIfRef(queue.shift());
  3950. if (!isDict(obj)) {
  3951. continue;
  3952. }
  3953. if (obj.has('Kids')) {
  3954. var kids = obj.get('Kids');
  3955. for (i = 0, n = kids.length; i < n; i++) {
  3956. var kid = kids[i];
  3957. if (processed.has(kid)) {
  3958. error('invalid destinations');
  3959. }
  3960. queue.push(kid);
  3961. processed.put(kid);
  3962. }
  3963. continue;
  3964. }
  3965. var names = obj.get('Names');
  3966. if (names) {
  3967. for (i = 0, n = names.length; i < n; i += 2) {
  3968. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3969. }
  3970. }
  3971. }
  3972. return dict;
  3973. },
  3974. get: function NameTree_get(destinationId) {
  3975. if (!this.root) {
  3976. return null;
  3977. }
  3978. var xref = this.xref;
  3979. var kidsOrNames = xref.fetchIfRef(this.root);
  3980. var loopCount = 0;
  3981. var MAX_NAMES_LEVELS = 10;
  3982. var l, r, m;
  3983. // Perform a binary search to quickly find the entry that
  3984. // contains the named destination we are looking for.
  3985. while (kidsOrNames.has('Kids')) {
  3986. loopCount++;
  3987. if (loopCount > MAX_NAMES_LEVELS) {
  3988. warn('Search depth limit for named destionations has been reached.');
  3989. return null;
  3990. }
  3991. var kids = kidsOrNames.get('Kids');
  3992. if (!isArray(kids)) {
  3993. return null;
  3994. }
  3995. l = 0;
  3996. r = kids.length - 1;
  3997. while (l <= r) {
  3998. m = (l + r) >> 1;
  3999. var kid = xref.fetchIfRef(kids[m]);
  4000. var limits = kid.get('Limits');
  4001. if (destinationId < limits[0]) {
  4002. r = m - 1;
  4003. } else if (destinationId > limits[1]) {
  4004. l = m + 1;
  4005. } else {
  4006. kidsOrNames = xref.fetchIfRef(kids[m]);
  4007. break;
  4008. }
  4009. }
  4010. if (l > r) {
  4011. return null;
  4012. }
  4013. }
  4014. // If we get here, then we have found the right entry. Now
  4015. // go through the named destinations in the Named dictionary
  4016. // until we find the exact destination we're looking for.
  4017. var names = kidsOrNames.get('Names');
  4018. if (isArray(names)) {
  4019. // Perform a binary search to reduce the lookup time.
  4020. l = 0;
  4021. r = names.length - 2;
  4022. while (l <= r) {
  4023. // Check only even indices (0, 2, 4, ...) because the
  4024. // odd indices contain the actual D array.
  4025. m = (l + r) & ~1;
  4026. if (destinationId < names[m]) {
  4027. r = m - 2;
  4028. } else if (destinationId > names[m]) {
  4029. l = m + 2;
  4030. } else {
  4031. return xref.fetchIfRef(names[m + 1]);
  4032. }
  4033. }
  4034. }
  4035. return null;
  4036. }
  4037. };
  4038. return NameTree;
  4039. })();
  4040. /**
  4041. * "A PDF file can refer to the contents of another file by using a File
  4042. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4043. * NOTE: Only embedded files are supported (as part of the attachments support)
  4044. * TODO: support the 'URL' file system (with caching if !/V), portable
  4045. * collections attributes and related files (/RF)
  4046. */
  4047. var FileSpec = (function FileSpecClosure() {
  4048. function FileSpec(root, xref) {
  4049. if (!root || !isDict(root)) {
  4050. return;
  4051. }
  4052. this.xref = xref;
  4053. this.root = root;
  4054. if (root.has('FS')) {
  4055. this.fs = root.get('FS');
  4056. }
  4057. this.description = root.has('Desc') ?
  4058. stringToPDFString(root.get('Desc')) :
  4059. '';
  4060. if (root.has('RF')) {
  4061. warn('Related file specifications are not supported');
  4062. }
  4063. this.contentAvailable = true;
  4064. if (!root.has('EF')) {
  4065. this.contentAvailable = false;
  4066. warn('Non-embedded file specifications are not supported');
  4067. }
  4068. }
  4069. function pickPlatformItem(dict) {
  4070. // Look for the filename in this order:
  4071. // UF, F, Unix, Mac, DOS
  4072. if (dict.has('UF')) {
  4073. return dict.get('UF');
  4074. } else if (dict.has('F')) {
  4075. return dict.get('F');
  4076. } else if (dict.has('Unix')) {
  4077. return dict.get('Unix');
  4078. } else if (dict.has('Mac')) {
  4079. return dict.get('Mac');
  4080. } else if (dict.has('DOS')) {
  4081. return dict.get('DOS');
  4082. } else {
  4083. return null;
  4084. }
  4085. }
  4086. FileSpec.prototype = {
  4087. get filename() {
  4088. if (!this._filename && this.root) {
  4089. var filename = pickPlatformItem(this.root) || 'unnamed';
  4090. this._filename = stringToPDFString(filename).
  4091. replace(/\\\\/g, '\\').
  4092. replace(/\\\//g, '/').
  4093. replace(/\\/g, '/');
  4094. }
  4095. return this._filename;
  4096. },
  4097. get content() {
  4098. if (!this.contentAvailable) {
  4099. return null;
  4100. }
  4101. if (!this.contentRef && this.root) {
  4102. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4103. }
  4104. var content = null;
  4105. if (this.contentRef) {
  4106. var xref = this.xref;
  4107. var fileObj = xref.fetchIfRef(this.contentRef);
  4108. if (fileObj && isStream(fileObj)) {
  4109. content = fileObj.getBytes();
  4110. } else {
  4111. warn('Embedded file specification points to non-existing/invalid ' +
  4112. 'content');
  4113. }
  4114. } else {
  4115. warn('Embedded file specification does not have a content');
  4116. }
  4117. return content;
  4118. },
  4119. get serializable() {
  4120. return {
  4121. filename: this.filename,
  4122. content: this.content
  4123. };
  4124. }
  4125. };
  4126. return FileSpec;
  4127. })();
  4128. /**
  4129. * A helper for loading missing data in object graphs. It traverses the graph
  4130. * depth first and queues up any objects that have missing data. Once it has
  4131. * has traversed as many objects that are available it attempts to bundle the
  4132. * missing data requests and then resume from the nodes that weren't ready.
  4133. *
  4134. * NOTE: It provides protection from circular references by keeping track of
  4135. * of loaded references. However, you must be careful not to load any graphs
  4136. * that have references to the catalog or other pages since that will cause the
  4137. * entire PDF document object graph to be traversed.
  4138. */
  4139. var ObjectLoader = (function() {
  4140. function mayHaveChildren(value) {
  4141. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4142. }
  4143. function addChildren(node, nodesToVisit) {
  4144. var value;
  4145. if (isDict(node) || isStream(node)) {
  4146. var map;
  4147. if (isDict(node)) {
  4148. map = node.map;
  4149. } else {
  4150. map = node.dict.map;
  4151. }
  4152. for (var key in map) {
  4153. value = map[key];
  4154. if (mayHaveChildren(value)) {
  4155. nodesToVisit.push(value);
  4156. }
  4157. }
  4158. } else if (isArray(node)) {
  4159. for (var i = 0, ii = node.length; i < ii; i++) {
  4160. value = node[i];
  4161. if (mayHaveChildren(value)) {
  4162. nodesToVisit.push(value);
  4163. }
  4164. }
  4165. }
  4166. }
  4167. function ObjectLoader(obj, keys, xref) {
  4168. this.obj = obj;
  4169. this.keys = keys;
  4170. this.xref = xref;
  4171. this.refSet = null;
  4172. }
  4173. ObjectLoader.prototype = {
  4174. load: function ObjectLoader_load() {
  4175. var keys = this.keys;
  4176. this.capability = createPromiseCapability();
  4177. // Don't walk the graph if all the data is already loaded.
  4178. if (!(this.xref.stream instanceof ChunkedStream) ||
  4179. this.xref.stream.getMissingChunks().length === 0) {
  4180. this.capability.resolve();
  4181. return this.capability.promise;
  4182. }
  4183. this.refSet = new RefSet();
  4184. // Setup the initial nodes to visit.
  4185. var nodesToVisit = [];
  4186. for (var i = 0; i < keys.length; i++) {
  4187. nodesToVisit.push(this.obj[keys[i]]);
  4188. }
  4189. this.walk(nodesToVisit);
  4190. return this.capability.promise;
  4191. },
  4192. walk: function ObjectLoader_walk(nodesToVisit) {
  4193. var nodesToRevisit = [];
  4194. var pendingRequests = [];
  4195. // DFS walk of the object graph.
  4196. while (nodesToVisit.length) {
  4197. var currentNode = nodesToVisit.pop();
  4198. // Only references or chunked streams can cause missing data exceptions.
  4199. if (isRef(currentNode)) {
  4200. // Skip nodes that have already been visited.
  4201. if (this.refSet.has(currentNode)) {
  4202. continue;
  4203. }
  4204. try {
  4205. var ref = currentNode;
  4206. this.refSet.put(ref);
  4207. currentNode = this.xref.fetch(currentNode);
  4208. } catch (e) {
  4209. if (!(e instanceof MissingDataException)) {
  4210. throw e;
  4211. }
  4212. nodesToRevisit.push(currentNode);
  4213. pendingRequests.push({ begin: e.begin, end: e.end });
  4214. }
  4215. }
  4216. if (currentNode && currentNode.getBaseStreams) {
  4217. var baseStreams = currentNode.getBaseStreams();
  4218. var foundMissingData = false;
  4219. for (var i = 0; i < baseStreams.length; i++) {
  4220. var stream = baseStreams[i];
  4221. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4222. foundMissingData = true;
  4223. pendingRequests.push({
  4224. begin: stream.start,
  4225. end: stream.end
  4226. });
  4227. }
  4228. }
  4229. if (foundMissingData) {
  4230. nodesToRevisit.push(currentNode);
  4231. }
  4232. }
  4233. addChildren(currentNode, nodesToVisit);
  4234. }
  4235. if (pendingRequests.length) {
  4236. this.xref.stream.manager.requestRanges(pendingRequests,
  4237. function pendingRequestCallback() {
  4238. nodesToVisit = nodesToRevisit;
  4239. for (var i = 0; i < nodesToRevisit.length; i++) {
  4240. var node = nodesToRevisit[i];
  4241. // Remove any reference nodes from the currrent refset so they
  4242. // aren't skipped when we revist them.
  4243. if (isRef(node)) {
  4244. this.refSet.remove(node);
  4245. }
  4246. }
  4247. this.walk(nodesToVisit);
  4248. }.bind(this));
  4249. return;
  4250. }
  4251. // Everything is loaded.
  4252. this.refSet = null;
  4253. this.capability.resolve();
  4254. }
  4255. };
  4256. return ObjectLoader;
  4257. })();
  4258. var ISOAdobeCharset = [
  4259. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4260. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4261. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4262. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4263. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4264. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4265. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4266. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4267. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4268. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4269. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4270. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4271. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4272. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4273. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4274. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4275. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4276. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4277. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4278. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4279. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4280. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4281. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4282. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4283. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4284. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4285. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4286. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4287. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4288. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4289. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4290. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4291. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4292. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4293. ];
  4294. var ExpertCharset = [
  4295. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4296. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4297. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4298. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4299. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4300. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4301. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4302. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4303. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4304. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4305. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4306. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4307. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4308. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4309. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4310. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4311. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4312. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4313. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4314. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4315. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4316. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4317. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4318. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4319. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4320. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4321. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4322. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4323. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4324. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4325. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4326. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4327. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4328. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4329. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4330. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4331. 'Ydieresissmall'
  4332. ];
  4333. var ExpertSubsetCharset = [
  4334. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4335. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4336. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4337. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4338. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4339. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4340. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4341. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4342. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4343. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4344. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4345. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4346. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4347. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4348. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4349. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4350. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4351. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4352. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4353. 'periodinferior', 'commainferior'
  4354. ];
  4355. var DEFAULT_ICON_SIZE = 22; // px
  4356. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4357. var Annotation = (function AnnotationClosure() {
  4358. // 12.5.5: Algorithm: Appearance streams
  4359. function getTransformMatrix(rect, bbox, matrix) {
  4360. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4361. var minX = bounds[0];
  4362. var minY = bounds[1];
  4363. var maxX = bounds[2];
  4364. var maxY = bounds[3];
  4365. if (minX === maxX || minY === maxY) {
  4366. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4367. // just apply the transform for rect
  4368. return [1, 0, 0, 1, rect[0], rect[1]];
  4369. }
  4370. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4371. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4372. return [
  4373. xRatio,
  4374. 0,
  4375. 0,
  4376. yRatio,
  4377. rect[0] - minX * xRatio,
  4378. rect[1] - minY * yRatio
  4379. ];
  4380. }
  4381. function getDefaultAppearance(dict) {
  4382. var appearanceState = dict.get('AP');
  4383. if (!isDict(appearanceState)) {
  4384. return;
  4385. }
  4386. var appearance;
  4387. var appearances = appearanceState.get('N');
  4388. if (isDict(appearances)) {
  4389. var as = dict.get('AS');
  4390. if (as && appearances.has(as.name)) {
  4391. appearance = appearances.get(as.name);
  4392. }
  4393. } else {
  4394. appearance = appearances;
  4395. }
  4396. return appearance;
  4397. }
  4398. function Annotation(params) {
  4399. var dict = params.dict;
  4400. var data = this.data = {};
  4401. data.subtype = dict.get('Subtype').name;
  4402. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4403. data.rect = Util.normalizeRect(rect);
  4404. data.annotationFlags = dict.get('F');
  4405. var color = dict.get('C');
  4406. if (!color) {
  4407. // The PDF spec does not mention how a missing color array is interpreted.
  4408. // Adobe Reader seems to default to black in this case.
  4409. data.color = [0, 0, 0];
  4410. } else if (isArray(color)) {
  4411. switch (color.length) {
  4412. case 0:
  4413. // Empty array denotes transparent border.
  4414. data.color = null;
  4415. break;
  4416. case 1:
  4417. // TODO: implement DeviceGray
  4418. break;
  4419. case 3:
  4420. data.color = color;
  4421. break;
  4422. case 4:
  4423. // TODO: implement DeviceCMYK
  4424. break;
  4425. }
  4426. }
  4427. // Some types of annotations have border style dict which has more
  4428. // info than the border array
  4429. if (dict.has('BS')) {
  4430. var borderStyle = dict.get('BS');
  4431. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4432. } else {
  4433. var borderArray = dict.get('Border') || [0, 0, 1];
  4434. data.borderWidth = borderArray[2] || 0;
  4435. // TODO: implement proper support for annotations with line dash patterns.
  4436. var dashArray = borderArray[3];
  4437. if (data.borderWidth > 0 && dashArray) {
  4438. if (!isArray(dashArray)) {
  4439. // Ignore the border if dashArray is not actually an array,
  4440. // this is consistent with the behaviour in Adobe Reader.
  4441. data.borderWidth = 0;
  4442. } else {
  4443. var dashArrayLength = dashArray.length;
  4444. if (dashArrayLength > 0) {
  4445. // According to the PDF specification: the elements in a dashArray
  4446. // shall be numbers that are nonnegative and not all equal to zero.
  4447. var isInvalid = false;
  4448. var numPositive = 0;
  4449. for (var i = 0; i < dashArrayLength; i++) {
  4450. var validNumber = (+dashArray[i] >= 0);
  4451. if (!validNumber) {
  4452. isInvalid = true;
  4453. break;
  4454. } else if (dashArray[i] > 0) {
  4455. numPositive++;
  4456. }
  4457. }
  4458. if (isInvalid || numPositive === 0) {
  4459. data.borderWidth = 0;
  4460. }
  4461. }
  4462. }
  4463. }
  4464. }
  4465. this.appearance = getDefaultAppearance(dict);
  4466. data.hasAppearance = !!this.appearance;
  4467. data.id = params.ref.num;
  4468. }
  4469. Annotation.prototype = {
  4470. getData: function Annotation_getData() {
  4471. return this.data;
  4472. },
  4473. isInvisible: function Annotation_isInvisible() {
  4474. var data = this.data;
  4475. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4476. return false;
  4477. } else {
  4478. return !!(data &&
  4479. data.annotationFlags && // Default: not invisible
  4480. data.annotationFlags & 0x1); // Invisible
  4481. }
  4482. },
  4483. isViewable: function Annotation_isViewable() {
  4484. var data = this.data;
  4485. return !!(!this.isInvisible() &&
  4486. data &&
  4487. (!data.annotationFlags ||
  4488. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4489. data.rect); // rectangle is necessary
  4490. },
  4491. isPrintable: function Annotation_isPrintable() {
  4492. var data = this.data;
  4493. return !!(!this.isInvisible() &&
  4494. data &&
  4495. data.annotationFlags && // Default: not printable
  4496. data.annotationFlags & 0x4 && // Print
  4497. !(data.annotationFlags & 0x2) && // Hidden
  4498. data.rect); // rectangle is necessary
  4499. },
  4500. loadResources: function Annotation_loadResources(keys) {
  4501. return new Promise(function (resolve, reject) {
  4502. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4503. if (!resources) {
  4504. resolve();
  4505. return;
  4506. }
  4507. var objectLoader = new ObjectLoader(resources.map,
  4508. keys,
  4509. resources.xref);
  4510. objectLoader.load().then(function() {
  4511. resolve(resources);
  4512. }, reject);
  4513. }, reject);
  4514. }.bind(this));
  4515. },
  4516. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4517. if (!this.appearance) {
  4518. return Promise.resolve(new OperatorList());
  4519. }
  4520. var data = this.data;
  4521. var appearanceDict = this.appearance.dict;
  4522. var resourcesPromise = this.loadResources([
  4523. 'ExtGState',
  4524. 'ColorSpace',
  4525. 'Pattern',
  4526. 'Shading',
  4527. 'XObject',
  4528. 'Font'
  4529. // ProcSet
  4530. // Properties
  4531. ]);
  4532. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4533. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4534. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4535. var self = this;
  4536. return resourcesPromise.then(function(resources) {
  4537. var opList = new OperatorList();
  4538. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4539. return evaluator.getOperatorList(self.appearance, resources, opList).
  4540. then(function () {
  4541. opList.addOp(OPS.endAnnotation, []);
  4542. self.appearance.reset();
  4543. return opList;
  4544. });
  4545. });
  4546. }
  4547. };
  4548. Annotation.getConstructor =
  4549. function Annotation_getConstructor(subtype, fieldType) {
  4550. if (!subtype) {
  4551. return;
  4552. }
  4553. // TODO(mack): Implement FreeText annotations
  4554. if (subtype === 'Link') {
  4555. return LinkAnnotation;
  4556. } else if (subtype === 'Text') {
  4557. return TextAnnotation;
  4558. } else if (subtype === 'Widget') {
  4559. if (!fieldType) {
  4560. return;
  4561. }
  4562. if (fieldType === 'Tx') {
  4563. return TextWidgetAnnotation;
  4564. } else {
  4565. return WidgetAnnotation;
  4566. }
  4567. } else {
  4568. return Annotation;
  4569. }
  4570. };
  4571. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4572. var dict = xref.fetchIfRef(ref);
  4573. if (!isDict(dict)) {
  4574. return;
  4575. }
  4576. var subtype = dict.get('Subtype');
  4577. subtype = isName(subtype) ? subtype.name : '';
  4578. if (!subtype) {
  4579. return;
  4580. }
  4581. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4582. fieldType = isName(fieldType) ? fieldType.name : '';
  4583. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4584. if (!Constructor) {
  4585. return;
  4586. }
  4587. var params = {
  4588. dict: dict,
  4589. ref: ref,
  4590. };
  4591. var annotation = new Constructor(params);
  4592. if (annotation.isViewable() || annotation.isPrintable()) {
  4593. return annotation;
  4594. } else {
  4595. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4596. warn('unimplemented annotation type: ' + subtype);
  4597. }
  4598. }
  4599. };
  4600. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4601. annotations, opList, pdfManager, partialEvaluator, intent) {
  4602. function reject(e) {
  4603. annotationsReadyCapability.reject(e);
  4604. }
  4605. var annotationsReadyCapability = createPromiseCapability();
  4606. var annotationPromises = [];
  4607. for (var i = 0, n = annotations.length; i < n; ++i) {
  4608. if (intent === 'display' && annotations[i].isViewable() ||
  4609. intent === 'print' && annotations[i].isPrintable()) {
  4610. annotationPromises.push(
  4611. annotations[i].getOperatorList(partialEvaluator));
  4612. }
  4613. }
  4614. Promise.all(annotationPromises).then(function(datas) {
  4615. opList.addOp(OPS.beginAnnotations, []);
  4616. for (var i = 0, n = datas.length; i < n; ++i) {
  4617. var annotOpList = datas[i];
  4618. opList.addOpList(annotOpList);
  4619. }
  4620. opList.addOp(OPS.endAnnotations, []);
  4621. annotationsReadyCapability.resolve();
  4622. }, reject);
  4623. return annotationsReadyCapability.promise;
  4624. };
  4625. return Annotation;
  4626. })();
  4627. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4628. function WidgetAnnotation(params) {
  4629. Annotation.call(this, params);
  4630. var dict = params.dict;
  4631. var data = this.data;
  4632. data.fieldValue = stringToPDFString(
  4633. Util.getInheritableProperty(dict, 'V') || '');
  4634. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4635. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4636. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4637. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4638. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4639. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4640. // Building the full field name by collecting the field and
  4641. // its ancestors 'T' data and joining them using '.'.
  4642. var fieldName = [];
  4643. var namedItem = dict;
  4644. var ref = params.ref;
  4645. while (namedItem) {
  4646. var parent = namedItem.get('Parent');
  4647. var parentRef = namedItem.getRaw('Parent');
  4648. var name = namedItem.get('T');
  4649. if (name) {
  4650. fieldName.unshift(stringToPDFString(name));
  4651. } else if (parent && ref) {
  4652. // The field name is absent, that means more than one field
  4653. // with the same name may exist. Replacing the empty name
  4654. // with the '`' plus index in the parent's 'Kids' array.
  4655. // This is not in the PDF spec but necessary to id the
  4656. // the input controls.
  4657. var kids = parent.get('Kids');
  4658. var j, jj;
  4659. for (j = 0, jj = kids.length; j < jj; j++) {
  4660. var kidRef = kids[j];
  4661. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4662. break;
  4663. }
  4664. }
  4665. fieldName.unshift('`' + j);
  4666. }
  4667. namedItem = parent;
  4668. ref = parentRef;
  4669. }
  4670. data.fullName = fieldName.join('.');
  4671. }
  4672. var parent = Annotation.prototype;
  4673. Util.inherit(WidgetAnnotation, Annotation, {
  4674. isViewable: function WidgetAnnotation_isViewable() {
  4675. if (this.data.fieldType === 'Sig') {
  4676. warn('unimplemented annotation type: Widget signature');
  4677. return false;
  4678. }
  4679. return parent.isViewable.call(this);
  4680. }
  4681. });
  4682. return WidgetAnnotation;
  4683. })();
  4684. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4685. function TextWidgetAnnotation(params) {
  4686. WidgetAnnotation.call(this, params);
  4687. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4688. this.data.annotationType = AnnotationType.WIDGET;
  4689. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4690. }
  4691. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4692. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4693. if (this.appearance) {
  4694. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4695. }
  4696. var opList = new OperatorList();
  4697. var data = this.data;
  4698. // Even if there is an appearance stream, ignore it. This is the
  4699. // behaviour used by Adobe Reader.
  4700. if (!data.defaultAppearance) {
  4701. return Promise.resolve(opList);
  4702. }
  4703. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4704. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4705. then(function () {
  4706. return opList;
  4707. });
  4708. }
  4709. });
  4710. return TextWidgetAnnotation;
  4711. })();
  4712. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4713. function InteractiveAnnotation(params) {
  4714. Annotation.call(this, params);
  4715. this.data.hasHtml = true;
  4716. }
  4717. Util.inherit(InteractiveAnnotation, Annotation, { });
  4718. return InteractiveAnnotation;
  4719. })();
  4720. var TextAnnotation = (function TextAnnotationClosure() {
  4721. function TextAnnotation(params) {
  4722. InteractiveAnnotation.call(this, params);
  4723. var dict = params.dict;
  4724. var data = this.data;
  4725. var content = dict.get('Contents');
  4726. var title = dict.get('T');
  4727. data.annotationType = AnnotationType.TEXT;
  4728. data.content = stringToPDFString(content || '');
  4729. data.title = stringToPDFString(title || '');
  4730. if (data.hasAppearance) {
  4731. data.name = 'NoIcon';
  4732. } else {
  4733. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4734. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4735. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4736. }
  4737. if (dict.has('C')) {
  4738. data.hasBgColor = true;
  4739. }
  4740. }
  4741. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4742. return TextAnnotation;
  4743. })();
  4744. var LinkAnnotation = (function LinkAnnotationClosure() {
  4745. function LinkAnnotation(params) {
  4746. InteractiveAnnotation.call(this, params);
  4747. var dict = params.dict;
  4748. var data = this.data;
  4749. data.annotationType = AnnotationType.LINK;
  4750. var action = dict.get('A');
  4751. if (action && isDict(action)) {
  4752. var linkType = action.get('S').name;
  4753. if (linkType === 'URI') {
  4754. var url = action.get('URI');
  4755. if (isName(url)) {
  4756. // Some bad PDFs do not put parentheses around relative URLs.
  4757. url = '/' + url.name;
  4758. } else if (url) {
  4759. url = addDefaultProtocolToUrl(url);
  4760. }
  4761. // TODO: pdf spec mentions urls can be relative to a Base
  4762. // entry in the dictionary.
  4763. if (!isValidUrl(url, false)) {
  4764. url = '';
  4765. }
  4766. data.url = url;
  4767. } else if (linkType === 'GoTo') {
  4768. data.dest = action.get('D');
  4769. } else if (linkType === 'GoToR') {
  4770. var urlDict = action.get('F');
  4771. if (isDict(urlDict)) {
  4772. // We assume that the 'url' is a Filspec dictionary
  4773. // and fetch the url without checking any further
  4774. url = urlDict.get('F') || '';
  4775. }
  4776. // TODO: pdf reference says that GoToR
  4777. // can also have 'NewWindow' attribute
  4778. if (!isValidUrl(url, false)) {
  4779. url = '';
  4780. }
  4781. data.url = url;
  4782. data.dest = action.get('D');
  4783. } else if (linkType === 'Named') {
  4784. data.action = action.get('N').name;
  4785. } else {
  4786. warn('unrecognized link type: ' + linkType);
  4787. }
  4788. } else if (dict.has('Dest')) {
  4789. // simple destination link
  4790. var dest = dict.get('Dest');
  4791. data.dest = isName(dest) ? dest.name : dest;
  4792. }
  4793. }
  4794. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4795. function addDefaultProtocolToUrl(url) {
  4796. if (url && url.indexOf('www.') === 0) {
  4797. return ('http://' + url);
  4798. }
  4799. return url;
  4800. }
  4801. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4802. return LinkAnnotation;
  4803. })();
  4804. var PDFFunction = (function PDFFunctionClosure() {
  4805. var CONSTRUCT_SAMPLED = 0;
  4806. var CONSTRUCT_INTERPOLATED = 2;
  4807. var CONSTRUCT_STICHED = 3;
  4808. var CONSTRUCT_POSTSCRIPT = 4;
  4809. return {
  4810. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4811. str) {
  4812. var i, ii;
  4813. var length = 1;
  4814. for (i = 0, ii = size.length; i < ii; i++) {
  4815. length *= size[i];
  4816. }
  4817. length *= outputSize;
  4818. var array = new Array(length);
  4819. var codeSize = 0;
  4820. var codeBuf = 0;
  4821. // 32 is a valid bps so shifting won't work
  4822. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4823. var strBytes = str.getBytes((length * bps + 7) / 8);
  4824. var strIdx = 0;
  4825. for (i = 0; i < length; i++) {
  4826. while (codeSize < bps) {
  4827. codeBuf <<= 8;
  4828. codeBuf |= strBytes[strIdx++];
  4829. codeSize += 8;
  4830. }
  4831. codeSize -= bps;
  4832. array[i] = (codeBuf >> codeSize) * sampleMul;
  4833. codeBuf &= (1 << codeSize) - 1;
  4834. }
  4835. return array;
  4836. },
  4837. getIR: function PDFFunction_getIR(xref, fn) {
  4838. var dict = fn.dict;
  4839. if (!dict) {
  4840. dict = fn;
  4841. }
  4842. var types = [this.constructSampled,
  4843. null,
  4844. this.constructInterpolated,
  4845. this.constructStiched,
  4846. this.constructPostScript];
  4847. var typeNum = dict.get('FunctionType');
  4848. var typeFn = types[typeNum];
  4849. if (!typeFn) {
  4850. error('Unknown type of function');
  4851. }
  4852. return typeFn.call(this, fn, dict, xref);
  4853. },
  4854. fromIR: function PDFFunction_fromIR(IR) {
  4855. var type = IR[0];
  4856. switch (type) {
  4857. case CONSTRUCT_SAMPLED:
  4858. return this.constructSampledFromIR(IR);
  4859. case CONSTRUCT_INTERPOLATED:
  4860. return this.constructInterpolatedFromIR(IR);
  4861. case CONSTRUCT_STICHED:
  4862. return this.constructStichedFromIR(IR);
  4863. //case CONSTRUCT_POSTSCRIPT:
  4864. default:
  4865. return this.constructPostScriptFromIR(IR);
  4866. }
  4867. },
  4868. parse: function PDFFunction_parse(xref, fn) {
  4869. var IR = this.getIR(xref, fn);
  4870. return this.fromIR(IR);
  4871. },
  4872. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4873. if (!isArray(fnObj)) {
  4874. // not an array -- parsing as regular function
  4875. return this.parse(xref, fnObj);
  4876. }
  4877. var fnArray = [];
  4878. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4879. var obj = xref.fetchIfRef(fnObj[j]);
  4880. fnArray.push(PDFFunction.parse(xref, obj));
  4881. }
  4882. return function (src, srcOffset, dest, destOffset) {
  4883. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4884. fnArray[i](src, srcOffset, dest, destOffset + i);
  4885. }
  4886. };
  4887. },
  4888. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4889. function toMultiArray(arr) {
  4890. var inputLength = arr.length;
  4891. var out = [];
  4892. var index = 0;
  4893. for (var i = 0; i < inputLength; i += 2) {
  4894. out[index] = [arr[i], arr[i + 1]];
  4895. ++index;
  4896. }
  4897. return out;
  4898. }
  4899. var domain = dict.get('Domain');
  4900. var range = dict.get('Range');
  4901. if (!domain || !range) {
  4902. error('No domain or range');
  4903. }
  4904. var inputSize = domain.length / 2;
  4905. var outputSize = range.length / 2;
  4906. domain = toMultiArray(domain);
  4907. range = toMultiArray(range);
  4908. var size = dict.get('Size');
  4909. var bps = dict.get('BitsPerSample');
  4910. var order = dict.get('Order') || 1;
  4911. if (order !== 1) {
  4912. // No description how cubic spline interpolation works in PDF32000:2008
  4913. // As in poppler, ignoring order, linear interpolation may work as good
  4914. info('No support for cubic spline interpolation: ' + order);
  4915. }
  4916. var encode = dict.get('Encode');
  4917. if (!encode) {
  4918. encode = [];
  4919. for (var i = 0; i < inputSize; ++i) {
  4920. encode.push(0);
  4921. encode.push(size[i] - 1);
  4922. }
  4923. }
  4924. encode = toMultiArray(encode);
  4925. var decode = dict.get('Decode');
  4926. if (!decode) {
  4927. decode = range;
  4928. } else {
  4929. decode = toMultiArray(decode);
  4930. }
  4931. var samples = this.getSampleArray(size, outputSize, bps, str);
  4932. return [
  4933. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4934. outputSize, Math.pow(2, bps) - 1, range
  4935. ];
  4936. },
  4937. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4938. // See chapter 3, page 109 of the PDF reference
  4939. function interpolate(x, xmin, xmax, ymin, ymax) {
  4940. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4941. }
  4942. return function constructSampledFromIRResult(src, srcOffset,
  4943. dest, destOffset) {
  4944. // See chapter 3, page 110 of the PDF reference.
  4945. var m = IR[1];
  4946. var domain = IR[2];
  4947. var encode = IR[3];
  4948. var decode = IR[4];
  4949. var samples = IR[5];
  4950. var size = IR[6];
  4951. var n = IR[7];
  4952. //var mask = IR[8];
  4953. var range = IR[9];
  4954. // Building the cube vertices: its part and sample index
  4955. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4956. var cubeVertices = 1 << m;
  4957. var cubeN = new Float64Array(cubeVertices);
  4958. var cubeVertex = new Uint32Array(cubeVertices);
  4959. var i, j;
  4960. for (j = 0; j < cubeVertices; j++) {
  4961. cubeN[j] = 1;
  4962. }
  4963. var k = n, pos = 1;
  4964. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4965. for (i = 0; i < m; ++i) {
  4966. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4967. var domain_2i = domain[i][0];
  4968. var domain_2i_1 = domain[i][1];
  4969. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4970. domain_2i_1);
  4971. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4972. // Encode_2i, Encode_2i+1)
  4973. var e = interpolate(xi, domain_2i, domain_2i_1,
  4974. encode[i][0], encode[i][1]);
  4975. // e_i' = min(max(e_i, 0), Size_i - 1)
  4976. var size_i = size[i];
  4977. e = Math.min(Math.max(e, 0), size_i - 1);
  4978. // Adjusting the cube: N and vertex sample index
  4979. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4980. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4981. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4982. var offset0 = e0 * k;
  4983. var offset1 = offset0 + k; // e1 * k
  4984. for (j = 0; j < cubeVertices; j++) {
  4985. if (j & pos) {
  4986. cubeN[j] *= n1;
  4987. cubeVertex[j] += offset1;
  4988. } else {
  4989. cubeN[j] *= n0;
  4990. cubeVertex[j] += offset0;
  4991. }
  4992. }
  4993. k *= size_i;
  4994. pos <<= 1;
  4995. }
  4996. for (j = 0; j < n; ++j) {
  4997. // Sum all cube vertices' samples portions
  4998. var rj = 0;
  4999. for (i = 0; i < cubeVertices; i++) {
  5000. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5001. }
  5002. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5003. // Decode_2j, Decode_2j+1)
  5004. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5005. // y_j = min(max(r_j, range_2j), range_2j+1)
  5006. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5007. range[j][1]);
  5008. }
  5009. };
  5010. },
  5011. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5012. dict) {
  5013. var c0 = dict.get('C0') || [0];
  5014. var c1 = dict.get('C1') || [1];
  5015. var n = dict.get('N');
  5016. if (!isArray(c0) || !isArray(c1)) {
  5017. error('Illegal dictionary for interpolated function');
  5018. }
  5019. var length = c0.length;
  5020. var diff = [];
  5021. for (var i = 0; i < length; ++i) {
  5022. diff.push(c1[i] - c0[i]);
  5023. }
  5024. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5025. },
  5026. constructInterpolatedFromIR:
  5027. function PDFFunction_constructInterpolatedFromIR(IR) {
  5028. var c0 = IR[1];
  5029. var diff = IR[2];
  5030. var n = IR[3];
  5031. var length = diff.length;
  5032. return function constructInterpolatedFromIRResult(src, srcOffset,
  5033. dest, destOffset) {
  5034. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5035. for (var j = 0; j < length; ++j) {
  5036. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5037. }
  5038. };
  5039. },
  5040. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5041. var domain = dict.get('Domain');
  5042. if (!domain) {
  5043. error('No domain');
  5044. }
  5045. var inputSize = domain.length / 2;
  5046. if (inputSize !== 1) {
  5047. error('Bad domain for stiched function');
  5048. }
  5049. var fnRefs = dict.get('Functions');
  5050. var fns = [];
  5051. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5052. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5053. }
  5054. var bounds = dict.get('Bounds');
  5055. var encode = dict.get('Encode');
  5056. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5057. },
  5058. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5059. var domain = IR[1];
  5060. var bounds = IR[2];
  5061. var encode = IR[3];
  5062. var fnsIR = IR[4];
  5063. var fns = [];
  5064. var tmpBuf = new Float32Array(1);
  5065. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5066. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5067. }
  5068. return function constructStichedFromIRResult(src, srcOffset,
  5069. dest, destOffset) {
  5070. var clip = function constructStichedFromIRClip(v, min, max) {
  5071. if (v > max) {
  5072. v = max;
  5073. } else if (v < min) {
  5074. v = min;
  5075. }
  5076. return v;
  5077. };
  5078. // clip to domain
  5079. var v = clip(src[srcOffset], domain[0], domain[1]);
  5080. // calulate which bound the value is in
  5081. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5082. if (v < bounds[i]) {
  5083. break;
  5084. }
  5085. }
  5086. // encode value into domain of function
  5087. var dmin = domain[0];
  5088. if (i > 0) {
  5089. dmin = bounds[i - 1];
  5090. }
  5091. var dmax = domain[1];
  5092. if (i < bounds.length) {
  5093. dmax = bounds[i];
  5094. }
  5095. var rmin = encode[2 * i];
  5096. var rmax = encode[2 * i + 1];
  5097. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5098. // call the appropriate function
  5099. fns[i](tmpBuf, 0, dest, destOffset);
  5100. };
  5101. },
  5102. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5103. xref) {
  5104. var domain = dict.get('Domain');
  5105. var range = dict.get('Range');
  5106. if (!domain) {
  5107. error('No domain.');
  5108. }
  5109. if (!range) {
  5110. error('No range.');
  5111. }
  5112. var lexer = new PostScriptLexer(fn);
  5113. var parser = new PostScriptParser(lexer);
  5114. var code = parser.parse();
  5115. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5116. },
  5117. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5118. IR) {
  5119. var domain = IR[1];
  5120. var range = IR[2];
  5121. var code = IR[3];
  5122. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5123. if (compiled) {
  5124. // Compiled function consists of simple expressions such as addition,
  5125. // subtraction, Math.max, and also contains 'var' and 'return'
  5126. // statements. See the generation in the PostScriptCompiler below.
  5127. /*jshint -W054 */
  5128. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5129. }
  5130. info('Unable to compile PS function');
  5131. var numOutputs = range.length >> 1;
  5132. var numInputs = domain.length >> 1;
  5133. var evaluator = new PostScriptEvaluator(code);
  5134. // Cache the values for a big speed up, the cache size is limited though
  5135. // since the number of possible values can be huge from a PS function.
  5136. var cache = {};
  5137. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5138. // seen in our tests.
  5139. var MAX_CACHE_SIZE = 2048 * 4;
  5140. var cache_available = MAX_CACHE_SIZE;
  5141. var tmpBuf = new Float32Array(numInputs);
  5142. return function constructPostScriptFromIRResult(src, srcOffset,
  5143. dest, destOffset) {
  5144. var i, value;
  5145. var key = '';
  5146. var input = tmpBuf;
  5147. for (i = 0; i < numInputs; i++) {
  5148. value = src[srcOffset + i];
  5149. input[i] = value;
  5150. key += value + '_';
  5151. }
  5152. var cachedValue = cache[key];
  5153. if (cachedValue !== undefined) {
  5154. dest.set(cachedValue, destOffset);
  5155. return;
  5156. }
  5157. var output = new Float32Array(numOutputs);
  5158. var stack = evaluator.execute(input);
  5159. var stackIndex = stack.length - numOutputs;
  5160. for (i = 0; i < numOutputs; i++) {
  5161. value = stack[stackIndex + i];
  5162. var bound = range[i * 2];
  5163. if (value < bound) {
  5164. value = bound;
  5165. } else {
  5166. bound = range[i * 2 +1];
  5167. if (value > bound) {
  5168. value = bound;
  5169. }
  5170. }
  5171. output[i] = value;
  5172. }
  5173. if (cache_available > 0) {
  5174. cache_available--;
  5175. cache[key] = output;
  5176. }
  5177. dest.set(output, destOffset);
  5178. };
  5179. }
  5180. };
  5181. })();
  5182. function isPDFFunction(v) {
  5183. var fnDict;
  5184. if (typeof v !== 'object') {
  5185. return false;
  5186. } else if (isDict(v)) {
  5187. fnDict = v;
  5188. } else if (isStream(v)) {
  5189. fnDict = v.dict;
  5190. } else {
  5191. return false;
  5192. }
  5193. return fnDict.has('FunctionType');
  5194. }
  5195. var PostScriptStack = (function PostScriptStackClosure() {
  5196. var MAX_STACK_SIZE = 100;
  5197. function PostScriptStack(initialStack) {
  5198. this.stack = !initialStack ? [] :
  5199. Array.prototype.slice.call(initialStack, 0);
  5200. }
  5201. PostScriptStack.prototype = {
  5202. push: function PostScriptStack_push(value) {
  5203. if (this.stack.length >= MAX_STACK_SIZE) {
  5204. error('PostScript function stack overflow.');
  5205. }
  5206. this.stack.push(value);
  5207. },
  5208. pop: function PostScriptStack_pop() {
  5209. if (this.stack.length <= 0) {
  5210. error('PostScript function stack underflow.');
  5211. }
  5212. return this.stack.pop();
  5213. },
  5214. copy: function PostScriptStack_copy(n) {
  5215. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5216. error('PostScript function stack overflow.');
  5217. }
  5218. var stack = this.stack;
  5219. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5220. stack.push(stack[i]);
  5221. }
  5222. },
  5223. index: function PostScriptStack_index(n) {
  5224. this.push(this.stack[this.stack.length - n - 1]);
  5225. },
  5226. // rotate the last n stack elements p times
  5227. roll: function PostScriptStack_roll(n, p) {
  5228. var stack = this.stack;
  5229. var l = stack.length - n;
  5230. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5231. for (i = l, j = r; i < j; i++, j--) {
  5232. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5233. }
  5234. for (i = l, j = c - 1; i < j; i++, j--) {
  5235. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5236. }
  5237. for (i = c, j = r; i < j; i++, j--) {
  5238. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5239. }
  5240. }
  5241. };
  5242. return PostScriptStack;
  5243. })();
  5244. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5245. function PostScriptEvaluator(operators) {
  5246. this.operators = operators;
  5247. }
  5248. PostScriptEvaluator.prototype = {
  5249. execute: function PostScriptEvaluator_execute(initialStack) {
  5250. var stack = new PostScriptStack(initialStack);
  5251. var counter = 0;
  5252. var operators = this.operators;
  5253. var length = operators.length;
  5254. var operator, a, b;
  5255. while (counter < length) {
  5256. operator = operators[counter++];
  5257. if (typeof operator === 'number') {
  5258. // Operator is really an operand and should be pushed to the stack.
  5259. stack.push(operator);
  5260. continue;
  5261. }
  5262. switch (operator) {
  5263. // non standard ps operators
  5264. case 'jz': // jump if false
  5265. b = stack.pop();
  5266. a = stack.pop();
  5267. if (!a) {
  5268. counter = b;
  5269. }
  5270. break;
  5271. case 'j': // jump
  5272. a = stack.pop();
  5273. counter = a;
  5274. break;
  5275. // all ps operators in alphabetical order (excluding if/ifelse)
  5276. case 'abs':
  5277. a = stack.pop();
  5278. stack.push(Math.abs(a));
  5279. break;
  5280. case 'add':
  5281. b = stack.pop();
  5282. a = stack.pop();
  5283. stack.push(a + b);
  5284. break;
  5285. case 'and':
  5286. b = stack.pop();
  5287. a = stack.pop();
  5288. if (isBool(a) && isBool(b)) {
  5289. stack.push(a && b);
  5290. } else {
  5291. stack.push(a & b);
  5292. }
  5293. break;
  5294. case 'atan':
  5295. a = stack.pop();
  5296. stack.push(Math.atan(a));
  5297. break;
  5298. case 'bitshift':
  5299. b = stack.pop();
  5300. a = stack.pop();
  5301. if (a > 0) {
  5302. stack.push(a << b);
  5303. } else {
  5304. stack.push(a >> b);
  5305. }
  5306. break;
  5307. case 'ceiling':
  5308. a = stack.pop();
  5309. stack.push(Math.ceil(a));
  5310. break;
  5311. case 'copy':
  5312. a = stack.pop();
  5313. stack.copy(a);
  5314. break;
  5315. case 'cos':
  5316. a = stack.pop();
  5317. stack.push(Math.cos(a));
  5318. break;
  5319. case 'cvi':
  5320. a = stack.pop() | 0;
  5321. stack.push(a);
  5322. break;
  5323. case 'cvr':
  5324. // noop
  5325. break;
  5326. case 'div':
  5327. b = stack.pop();
  5328. a = stack.pop();
  5329. stack.push(a / b);
  5330. break;
  5331. case 'dup':
  5332. stack.copy(1);
  5333. break;
  5334. case 'eq':
  5335. b = stack.pop();
  5336. a = stack.pop();
  5337. stack.push(a === b);
  5338. break;
  5339. case 'exch':
  5340. stack.roll(2, 1);
  5341. break;
  5342. case 'exp':
  5343. b = stack.pop();
  5344. a = stack.pop();
  5345. stack.push(Math.pow(a, b));
  5346. break;
  5347. case 'false':
  5348. stack.push(false);
  5349. break;
  5350. case 'floor':
  5351. a = stack.pop();
  5352. stack.push(Math.floor(a));
  5353. break;
  5354. case 'ge':
  5355. b = stack.pop();
  5356. a = stack.pop();
  5357. stack.push(a >= b);
  5358. break;
  5359. case 'gt':
  5360. b = stack.pop();
  5361. a = stack.pop();
  5362. stack.push(a > b);
  5363. break;
  5364. case 'idiv':
  5365. b = stack.pop();
  5366. a = stack.pop();
  5367. stack.push((a / b) | 0);
  5368. break;
  5369. case 'index':
  5370. a = stack.pop();
  5371. stack.index(a);
  5372. break;
  5373. case 'le':
  5374. b = stack.pop();
  5375. a = stack.pop();
  5376. stack.push(a <= b);
  5377. break;
  5378. case 'ln':
  5379. a = stack.pop();
  5380. stack.push(Math.log(a));
  5381. break;
  5382. case 'log':
  5383. a = stack.pop();
  5384. stack.push(Math.log(a) / Math.LN10);
  5385. break;
  5386. case 'lt':
  5387. b = stack.pop();
  5388. a = stack.pop();
  5389. stack.push(a < b);
  5390. break;
  5391. case 'mod':
  5392. b = stack.pop();
  5393. a = stack.pop();
  5394. stack.push(a % b);
  5395. break;
  5396. case 'mul':
  5397. b = stack.pop();
  5398. a = stack.pop();
  5399. stack.push(a * b);
  5400. break;
  5401. case 'ne':
  5402. b = stack.pop();
  5403. a = stack.pop();
  5404. stack.push(a !== b);
  5405. break;
  5406. case 'neg':
  5407. a = stack.pop();
  5408. stack.push(-a);
  5409. break;
  5410. case 'not':
  5411. a = stack.pop();
  5412. if (isBool(a)) {
  5413. stack.push(!a);
  5414. } else {
  5415. stack.push(~a);
  5416. }
  5417. break;
  5418. case 'or':
  5419. b = stack.pop();
  5420. a = stack.pop();
  5421. if (isBool(a) && isBool(b)) {
  5422. stack.push(a || b);
  5423. } else {
  5424. stack.push(a | b);
  5425. }
  5426. break;
  5427. case 'pop':
  5428. stack.pop();
  5429. break;
  5430. case 'roll':
  5431. b = stack.pop();
  5432. a = stack.pop();
  5433. stack.roll(a, b);
  5434. break;
  5435. case 'round':
  5436. a = stack.pop();
  5437. stack.push(Math.round(a));
  5438. break;
  5439. case 'sin':
  5440. a = stack.pop();
  5441. stack.push(Math.sin(a));
  5442. break;
  5443. case 'sqrt':
  5444. a = stack.pop();
  5445. stack.push(Math.sqrt(a));
  5446. break;
  5447. case 'sub':
  5448. b = stack.pop();
  5449. a = stack.pop();
  5450. stack.push(a - b);
  5451. break;
  5452. case 'true':
  5453. stack.push(true);
  5454. break;
  5455. case 'truncate':
  5456. a = stack.pop();
  5457. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5458. stack.push(a);
  5459. break;
  5460. case 'xor':
  5461. b = stack.pop();
  5462. a = stack.pop();
  5463. if (isBool(a) && isBool(b)) {
  5464. stack.push(a !== b);
  5465. } else {
  5466. stack.push(a ^ b);
  5467. }
  5468. break;
  5469. default:
  5470. error('Unknown operator ' + operator);
  5471. break;
  5472. }
  5473. }
  5474. return stack.stack;
  5475. }
  5476. };
  5477. return PostScriptEvaluator;
  5478. })();
  5479. // Most of the PDFs functions consist of simple operations such as:
  5480. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5481. //
  5482. // We can compile most of such programs, and at the same moment, we can
  5483. // optimize some expressions using basic math properties. Keeping track of
  5484. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5485. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5486. function AstNode(type) {
  5487. this.type = type;
  5488. }
  5489. AstNode.prototype.visit = function (visitor) {
  5490. throw new Error('abstract method');
  5491. };
  5492. function AstArgument(index, min, max) {
  5493. AstNode.call(this, 'args');
  5494. this.index = index;
  5495. this.min = min;
  5496. this.max = max;
  5497. }
  5498. AstArgument.prototype = Object.create(AstNode.prototype);
  5499. AstArgument.prototype.visit = function (visitor) {
  5500. visitor.visitArgument(this);
  5501. };
  5502. function AstLiteral(number) {
  5503. AstNode.call(this, 'literal');
  5504. this.number = number;
  5505. this.min = number;
  5506. this.max = number;
  5507. }
  5508. AstLiteral.prototype = Object.create(AstNode.prototype);
  5509. AstLiteral.prototype.visit = function (visitor) {
  5510. visitor.visitLiteral(this);
  5511. };
  5512. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5513. AstNode.call(this, 'binary');
  5514. this.op = op;
  5515. this.arg1 = arg1;
  5516. this.arg2 = arg2;
  5517. this.min = min;
  5518. this.max = max;
  5519. }
  5520. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5521. AstBinaryOperation.prototype.visit = function (visitor) {
  5522. visitor.visitBinaryOperation(this);
  5523. };
  5524. function AstMin(arg, max) {
  5525. AstNode.call(this, 'max');
  5526. this.arg = arg;
  5527. this.min = arg.min;
  5528. this.max = max;
  5529. }
  5530. AstMin.prototype = Object.create(AstNode.prototype);
  5531. AstMin.prototype.visit = function (visitor) {
  5532. visitor.visitMin(this);
  5533. };
  5534. function AstVariable(index, min, max) {
  5535. AstNode.call(this, 'var');
  5536. this.index = index;
  5537. this.min = min;
  5538. this.max = max;
  5539. }
  5540. AstVariable.prototype = Object.create(AstNode.prototype);
  5541. AstVariable.prototype.visit = function (visitor) {
  5542. visitor.visitVariable(this);
  5543. };
  5544. function AstVariableDefinition(variable, arg) {
  5545. AstNode.call(this, 'definition');
  5546. this.variable = variable;
  5547. this.arg = arg;
  5548. }
  5549. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5550. AstVariableDefinition.prototype.visit = function (visitor) {
  5551. visitor.visitVariableDefinition(this);
  5552. };
  5553. function ExpressionBuilderVisitor() {
  5554. this.parts = [];
  5555. }
  5556. ExpressionBuilderVisitor.prototype = {
  5557. visitArgument: function (arg) {
  5558. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5559. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5560. },
  5561. visitVariable: function (variable) {
  5562. this.parts.push('v', variable.index);
  5563. },
  5564. visitLiteral: function (literal) {
  5565. this.parts.push(literal.number);
  5566. },
  5567. visitBinaryOperation: function (operation) {
  5568. this.parts.push('(');
  5569. operation.arg1.visit(this);
  5570. this.parts.push(' ', operation.op, ' ');
  5571. operation.arg2.visit(this);
  5572. this.parts.push(')');
  5573. },
  5574. visitVariableDefinition: function (definition) {
  5575. this.parts.push('var ');
  5576. definition.variable.visit(this);
  5577. this.parts.push(' = ');
  5578. definition.arg.visit(this);
  5579. this.parts.push(';');
  5580. },
  5581. visitMin: function (max) {
  5582. this.parts.push('Math.min(');
  5583. max.arg.visit(this);
  5584. this.parts.push(', ', max.max, ')');
  5585. },
  5586. toString: function () {
  5587. return this.parts.join('');
  5588. }
  5589. };
  5590. function buildAddOperation(num1, num2) {
  5591. if (num2.type === 'literal' && num2.number === 0) {
  5592. // optimization: second operand is 0
  5593. return num1;
  5594. }
  5595. if (num1.type === 'literal' && num1.number === 0) {
  5596. // optimization: first operand is 0
  5597. return num2;
  5598. }
  5599. if (num2.type === 'literal' && num1.type === 'literal') {
  5600. // optimization: operands operand are literals
  5601. return new AstLiteral(num1.number + num2.number);
  5602. }
  5603. return new AstBinaryOperation('+', num1, num2,
  5604. num1.min + num2.min, num1.max + num2.max);
  5605. }
  5606. function buildMulOperation(num1, num2) {
  5607. if (num2.type === 'literal') {
  5608. // optimization: second operands is a literal...
  5609. if (num2.number === 0) {
  5610. return new AstLiteral(0); // and it's 0
  5611. } else if (num2.number === 1) {
  5612. return num1; // and it's 1
  5613. } else if (num1.type === 'literal') {
  5614. // ... and first operands is a literal too
  5615. return new AstLiteral(num1.number * num2.number);
  5616. }
  5617. }
  5618. if (num1.type === 'literal') {
  5619. // optimization: first operands is a literal...
  5620. if (num1.number === 0) {
  5621. return new AstLiteral(0); // and it's 0
  5622. } else if (num1.number === 1) {
  5623. return num2; // and it's 1
  5624. }
  5625. }
  5626. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5627. num1.max * num2.min, num1.max * num2.max);
  5628. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5629. num1.max * num2.min, num1.max * num2.max);
  5630. return new AstBinaryOperation('*', num1, num2, min, max);
  5631. }
  5632. function buildSubOperation(num1, num2) {
  5633. if (num2.type === 'literal') {
  5634. // optimization: second operands is a literal...
  5635. if (num2.number === 0) {
  5636. return num1; // ... and it's 0
  5637. } else if (num1.type === 'literal') {
  5638. // ... and first operands is a literal too
  5639. return new AstLiteral(num1.number - num2.number);
  5640. }
  5641. }
  5642. if (num2.type === 'binary' && num2.op === '-' &&
  5643. num1.type === 'literal' && num1.number === 1 &&
  5644. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5645. // optimization for case: 1 - (1 - x)
  5646. return num2.arg2;
  5647. }
  5648. return new AstBinaryOperation('-', num1, num2,
  5649. num1.min - num2.max, num1.max - num2.min);
  5650. }
  5651. function buildMinOperation(num1, max) {
  5652. if (num1.min >= max) {
  5653. // optimization: num1 min value is not less than required max
  5654. return new AstLiteral(max); // just returning max
  5655. } else if (num1.max <= max) {
  5656. // optimization: num1 max value is not greater than required max
  5657. return num1; // just returning an argument
  5658. }
  5659. return new AstMin(num1, max);
  5660. }
  5661. function PostScriptCompiler() {}
  5662. PostScriptCompiler.prototype = {
  5663. compile: function PostScriptCompiler_compile(code, domain, range) {
  5664. var stack = [];
  5665. var i, ii;
  5666. var instructions = [];
  5667. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5668. var lastRegister = 0;
  5669. var n, j, min, max;
  5670. var num1, num2, ast1, ast2, tmpVar, item;
  5671. for (i = 0; i < inputSize; i++) {
  5672. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5673. }
  5674. for (i = 0, ii = code.length; i < ii; i++) {
  5675. item = code[i];
  5676. if (typeof item === 'number') {
  5677. stack.push(new AstLiteral(item));
  5678. continue;
  5679. }
  5680. switch (item) {
  5681. case 'add':
  5682. if (stack.length < 2) {
  5683. return null;
  5684. }
  5685. num2 = stack.pop();
  5686. num1 = stack.pop();
  5687. stack.push(buildAddOperation(num1, num2));
  5688. break;
  5689. case 'cvr':
  5690. if (stack.length < 1) {
  5691. return null;
  5692. }
  5693. break;
  5694. case 'mul':
  5695. if (stack.length < 2) {
  5696. return null;
  5697. }
  5698. num2 = stack.pop();
  5699. num1 = stack.pop();
  5700. stack.push(buildMulOperation(num1, num2));
  5701. break;
  5702. case 'sub':
  5703. if (stack.length < 2) {
  5704. return null;
  5705. }
  5706. num2 = stack.pop();
  5707. num1 = stack.pop();
  5708. stack.push(buildSubOperation(num1, num2));
  5709. break;
  5710. case 'exch':
  5711. if (stack.length < 2) {
  5712. return null;
  5713. }
  5714. ast1 = stack.pop(); ast2 = stack.pop();
  5715. stack.push(ast1, ast2);
  5716. break;
  5717. case 'pop':
  5718. if (stack.length < 1) {
  5719. return null;
  5720. }
  5721. stack.pop();
  5722. break;
  5723. case 'index':
  5724. if (stack.length < 1) {
  5725. return null;
  5726. }
  5727. num1 = stack.pop();
  5728. if (num1.type !== 'literal') {
  5729. return null;
  5730. }
  5731. n = num1.number;
  5732. if (n < 0 || (n|0) !== n || stack.length < n) {
  5733. return null;
  5734. }
  5735. ast1 = stack[stack.length - n - 1];
  5736. if (ast1.type === 'literal' || ast1.type === 'var') {
  5737. stack.push(ast1);
  5738. break;
  5739. }
  5740. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5741. stack[stack.length - n - 1] = tmpVar;
  5742. stack.push(tmpVar);
  5743. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5744. break;
  5745. case 'dup':
  5746. if (stack.length < 1) {
  5747. return null;
  5748. }
  5749. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5750. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5751. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5752. // special case of the commands sequence for the min operation
  5753. num1 = stack.pop();
  5754. stack.push(buildMinOperation(num1, code[i + 1]));
  5755. i += 6;
  5756. break;
  5757. }
  5758. ast1 = stack[stack.length - 1];
  5759. if (ast1.type === 'literal' || ast1.type === 'var') {
  5760. // we don't have to save into intermediate variable a literal or
  5761. // variable.
  5762. stack.push(ast1);
  5763. break;
  5764. }
  5765. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5766. stack[stack.length - 1] = tmpVar;
  5767. stack.push(tmpVar);
  5768. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5769. break;
  5770. case 'roll':
  5771. if (stack.length < 2) {
  5772. return null;
  5773. }
  5774. num2 = stack.pop();
  5775. num1 = stack.pop();
  5776. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5777. // both roll operands must be numbers
  5778. return null;
  5779. }
  5780. j = num2.number;
  5781. n = num1.number;
  5782. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5783. // ... and integers
  5784. return null;
  5785. }
  5786. j = ((j % n) + n) % n;
  5787. if (j === 0) {
  5788. break; // just skipping -- there are nothing to rotate
  5789. }
  5790. Array.prototype.push.apply(stack,
  5791. stack.splice(stack.length - n, n - j));
  5792. break;
  5793. default:
  5794. return null; // unsupported operator
  5795. }
  5796. }
  5797. if (stack.length !== outputSize) {
  5798. return null;
  5799. }
  5800. var result = [];
  5801. instructions.forEach(function (instruction) {
  5802. var statementBuilder = new ExpressionBuilderVisitor();
  5803. instruction.visit(statementBuilder);
  5804. result.push(statementBuilder.toString());
  5805. });
  5806. stack.forEach(function (expr, i) {
  5807. var statementBuilder = new ExpressionBuilderVisitor();
  5808. expr.visit(statementBuilder);
  5809. var min = range[i * 2], max = range[i * 2 + 1];
  5810. var out = [statementBuilder.toString()];
  5811. if (min > expr.min) {
  5812. out.unshift('Math.max(', min, ', ');
  5813. out.push(')');
  5814. }
  5815. if (max < expr.max) {
  5816. out.unshift('Math.min(', max, ', ');
  5817. out.push(')');
  5818. }
  5819. out.unshift('dest[destOffset + ', i, '] = ');
  5820. out.push(';');
  5821. result.push(out.join(''));
  5822. });
  5823. return result.join('\n');
  5824. }
  5825. };
  5826. return PostScriptCompiler;
  5827. })();
  5828. var ColorSpace = (function ColorSpaceClosure() {
  5829. // Constructor should define this.numComps, this.defaultColor, this.name
  5830. function ColorSpace() {
  5831. error('should not call ColorSpace constructor');
  5832. }
  5833. ColorSpace.prototype = {
  5834. /**
  5835. * Converts the color value to the RGB color. The color components are
  5836. * located in the src array starting from the srcOffset. Returns the array
  5837. * of the rgb components, each value ranging from [0,255].
  5838. */
  5839. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5840. var rgb = new Uint8Array(3);
  5841. this.getRgbItem(src, srcOffset, rgb, 0);
  5842. return rgb;
  5843. },
  5844. /**
  5845. * Converts the color value to the RGB color, similar to the getRgb method.
  5846. * The result placed into the dest array starting from the destOffset.
  5847. */
  5848. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5849. dest, destOffset) {
  5850. error('Should not call ColorSpace.getRgbItem');
  5851. },
  5852. /**
  5853. * Converts the specified number of the color values to the RGB colors.
  5854. * The colors are located in the src array starting from the srcOffset.
  5855. * The result is placed into the dest array starting from the destOffset.
  5856. * The src array items shall be in [0,2^bits) range, the dest array items
  5857. * will be in [0,255] range. alpha01 indicates how many alpha components
  5858. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5859. * array).
  5860. */
  5861. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5862. dest, destOffset, bits,
  5863. alpha01) {
  5864. error('Should not call ColorSpace.getRgbBuffer');
  5865. },
  5866. /**
  5867. * Determines the number of bytes required to store the result of the
  5868. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5869. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5870. */
  5871. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5872. alpha01) {
  5873. error('Should not call ColorSpace.getOutputLength');
  5874. },
  5875. /**
  5876. * Returns true if source data will be equal the result/output data.
  5877. */
  5878. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5879. return false;
  5880. },
  5881. /**
  5882. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5883. * how many alpha components there are in the dest array; it will be either
  5884. * 0 (RGB array) or 1 (RGBA array).
  5885. */
  5886. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5887. originalHeight, width, height,
  5888. actualHeight, bpc, comps, alpha01) {
  5889. var count = originalWidth * originalHeight;
  5890. var rgbBuf = null;
  5891. var numComponentColors = 1 << bpc;
  5892. var needsResizing = originalHeight !== height || originalWidth !== width;
  5893. var i, ii;
  5894. if (this.isPassthrough(bpc)) {
  5895. rgbBuf = comps;
  5896. } else if (this.numComps === 1 && count > numComponentColors &&
  5897. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5898. // Optimization: create a color map when there is just one component and
  5899. // we are converting more colors than the size of the color map. We
  5900. // don't build the map if the colorspace is gray or rgb since those
  5901. // methods are faster than building a map. This mainly offers big speed
  5902. // ups for indexed and alternate colorspaces.
  5903. //
  5904. // TODO it may be worth while to cache the color map. While running
  5905. // testing I never hit a cache so I will leave that out for now (perhaps
  5906. // we are reparsing colorspaces too much?).
  5907. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5908. new Uint16Array(numComponentColors);
  5909. var key;
  5910. for (i = 0; i < numComponentColors; i++) {
  5911. allColors[i] = i;
  5912. }
  5913. var colorMap = new Uint8Array(numComponentColors * 3);
  5914. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5915. /* alpha01 = */ 0);
  5916. var destPos, rgbPos;
  5917. if (!needsResizing) {
  5918. // Fill in the RGB values directly into |dest|.
  5919. destPos = 0;
  5920. for (i = 0; i < count; ++i) {
  5921. key = comps[i] * 3;
  5922. dest[destPos++] = colorMap[key];
  5923. dest[destPos++] = colorMap[key + 1];
  5924. dest[destPos++] = colorMap[key + 2];
  5925. destPos += alpha01;
  5926. }
  5927. } else {
  5928. rgbBuf = new Uint8Array(count * 3);
  5929. rgbPos = 0;
  5930. for (i = 0; i < count; ++i) {
  5931. key = comps[i] * 3;
  5932. rgbBuf[rgbPos++] = colorMap[key];
  5933. rgbBuf[rgbPos++] = colorMap[key + 1];
  5934. rgbBuf[rgbPos++] = colorMap[key + 2];
  5935. }
  5936. }
  5937. } else {
  5938. if (!needsResizing) {
  5939. // Fill in the RGB values directly into |dest|.
  5940. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5941. alpha01);
  5942. } else {
  5943. rgbBuf = new Uint8Array(count * 3);
  5944. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5945. /* alpha01 = */ 0);
  5946. }
  5947. }
  5948. if (rgbBuf) {
  5949. if (needsResizing) {
  5950. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5951. height, dest, alpha01);
  5952. } else {
  5953. rgbPos = 0;
  5954. destPos = 0;
  5955. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5956. dest[destPos++] = rgbBuf[rgbPos++];
  5957. dest[destPos++] = rgbBuf[rgbPos++];
  5958. dest[destPos++] = rgbBuf[rgbPos++];
  5959. destPos += alpha01;
  5960. }
  5961. }
  5962. }
  5963. },
  5964. /**
  5965. * True if the colorspace has components in the default range of [0, 1].
  5966. * This should be true for all colorspaces except for lab color spaces
  5967. * which are [0,100], [-128, 127], [-128, 127].
  5968. */
  5969. usesZeroToOneRange: true
  5970. };
  5971. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5972. var IR = ColorSpace.parseToIR(cs, xref, res);
  5973. if (IR instanceof AlternateCS) {
  5974. return IR;
  5975. }
  5976. return ColorSpace.fromIR(IR);
  5977. };
  5978. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5979. var name = isArray(IR) ? IR[0] : IR;
  5980. var whitePoint, blackPoint, gamma;
  5981. switch (name) {
  5982. case 'DeviceGrayCS':
  5983. return this.singletons.gray;
  5984. case 'DeviceRgbCS':
  5985. return this.singletons.rgb;
  5986. case 'DeviceCmykCS':
  5987. return this.singletons.cmyk;
  5988. case 'CalGrayCS':
  5989. whitePoint = IR[1].WhitePoint;
  5990. blackPoint = IR[1].BlackPoint;
  5991. gamma = IR[1].Gamma;
  5992. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5993. case 'CalRGBCS':
  5994. whitePoint = IR[1].WhitePoint;
  5995. blackPoint = IR[1].BlackPoint;
  5996. gamma = IR[1].Gamma;
  5997. var matrix = IR[1].Matrix;
  5998. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5999. case 'PatternCS':
  6000. var basePatternCS = IR[1];
  6001. if (basePatternCS) {
  6002. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6003. }
  6004. return new PatternCS(basePatternCS);
  6005. case 'IndexedCS':
  6006. var baseIndexedCS = IR[1];
  6007. var hiVal = IR[2];
  6008. var lookup = IR[3];
  6009. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6010. case 'AlternateCS':
  6011. var numComps = IR[1];
  6012. var alt = IR[2];
  6013. var tintFnIR = IR[3];
  6014. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6015. PDFFunction.fromIR(tintFnIR));
  6016. case 'LabCS':
  6017. whitePoint = IR[1].WhitePoint;
  6018. blackPoint = IR[1].BlackPoint;
  6019. var range = IR[1].Range;
  6020. return new LabCS(whitePoint, blackPoint, range);
  6021. default:
  6022. error('Unknown name ' + name);
  6023. }
  6024. return null;
  6025. };
  6026. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6027. if (isName(cs)) {
  6028. var colorSpaces = res.get('ColorSpace');
  6029. if (isDict(colorSpaces)) {
  6030. var refcs = colorSpaces.get(cs.name);
  6031. if (refcs) {
  6032. cs = refcs;
  6033. }
  6034. }
  6035. }
  6036. cs = xref.fetchIfRef(cs);
  6037. var mode;
  6038. if (isName(cs)) {
  6039. mode = cs.name;
  6040. this.mode = mode;
  6041. switch (mode) {
  6042. case 'DeviceGray':
  6043. case 'G':
  6044. return 'DeviceGrayCS';
  6045. case 'DeviceRGB':
  6046. case 'RGB':
  6047. return 'DeviceRgbCS';
  6048. case 'DeviceCMYK':
  6049. case 'CMYK':
  6050. return 'DeviceCmykCS';
  6051. case 'Pattern':
  6052. return ['PatternCS', null];
  6053. default:
  6054. error('unrecognized colorspace ' + mode);
  6055. }
  6056. } else if (isArray(cs)) {
  6057. mode = cs[0].name;
  6058. this.mode = mode;
  6059. var numComps, params;
  6060. switch (mode) {
  6061. case 'DeviceGray':
  6062. case 'G':
  6063. return 'DeviceGrayCS';
  6064. case 'DeviceRGB':
  6065. case 'RGB':
  6066. return 'DeviceRgbCS';
  6067. case 'DeviceCMYK':
  6068. case 'CMYK':
  6069. return 'DeviceCmykCS';
  6070. case 'CalGray':
  6071. params = cs[1].getAll();
  6072. return ['CalGrayCS', params];
  6073. case 'CalRGB':
  6074. params = cs[1].getAll();
  6075. return ['CalRGBCS', params];
  6076. case 'ICCBased':
  6077. var stream = xref.fetchIfRef(cs[1]);
  6078. var dict = stream.dict;
  6079. numComps = dict.get('N');
  6080. if (numComps === 1) {
  6081. return 'DeviceGrayCS';
  6082. } else if (numComps === 3) {
  6083. return 'DeviceRgbCS';
  6084. } else if (numComps === 4) {
  6085. return 'DeviceCmykCS';
  6086. }
  6087. break;
  6088. case 'Pattern':
  6089. var basePatternCS = cs[1];
  6090. if (basePatternCS) {
  6091. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6092. }
  6093. return ['PatternCS', basePatternCS];
  6094. case 'Indexed':
  6095. case 'I':
  6096. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6097. var hiVal = cs[2] + 1;
  6098. var lookup = xref.fetchIfRef(cs[3]);
  6099. if (isStream(lookup)) {
  6100. lookup = lookup.getBytes();
  6101. }
  6102. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6103. case 'Separation':
  6104. case 'DeviceN':
  6105. var name = cs[1];
  6106. numComps = 1;
  6107. if (isName(name)) {
  6108. numComps = 1;
  6109. } else if (isArray(name)) {
  6110. numComps = name.length;
  6111. }
  6112. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  6113. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6114. return ['AlternateCS', numComps, alt, tintFnIR];
  6115. case 'Lab':
  6116. params = cs[1].getAll();
  6117. return ['LabCS', params];
  6118. default:
  6119. error('unimplemented color space object "' + mode + '"');
  6120. }
  6121. } else {
  6122. error('unrecognized color space object: "' + cs + '"');
  6123. }
  6124. return null;
  6125. };
  6126. /**
  6127. * Checks if a decode map matches the default decode map for a color space.
  6128. * This handles the general decode maps where there are two values per
  6129. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6130. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6131. * slightly different.
  6132. * @param {Array} decode Decode map (usually from an image).
  6133. * @param {Number} n Number of components the color space has.
  6134. */
  6135. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6136. if (!decode) {
  6137. return true;
  6138. }
  6139. if (n * 2 !== decode.length) {
  6140. warn('The decode map is not the correct length');
  6141. return true;
  6142. }
  6143. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6144. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6145. return false;
  6146. }
  6147. }
  6148. return true;
  6149. };
  6150. ColorSpace.singletons = {
  6151. get gray() {
  6152. return shadow(this, 'gray', new DeviceGrayCS());
  6153. },
  6154. get rgb() {
  6155. return shadow(this, 'rgb', new DeviceRgbCS());
  6156. },
  6157. get cmyk() {
  6158. return shadow(this, 'cmyk', new DeviceCmykCS());
  6159. }
  6160. };
  6161. return ColorSpace;
  6162. })();
  6163. /**
  6164. * Alternate color space handles both Separation and DeviceN color spaces. A
  6165. * Separation color space is actually just a DeviceN with one color component.
  6166. * Both color spaces use a tinting function to convert colors to a base color
  6167. * space.
  6168. */
  6169. var AlternateCS = (function AlternateCSClosure() {
  6170. function AlternateCS(numComps, base, tintFn) {
  6171. this.name = 'Alternate';
  6172. this.numComps = numComps;
  6173. this.defaultColor = new Float32Array(numComps);
  6174. for (var i = 0; i < numComps; ++i) {
  6175. this.defaultColor[i] = 1;
  6176. }
  6177. this.base = base;
  6178. this.tintFn = tintFn;
  6179. this.tmpBuf = new Float32Array(base.numComps);
  6180. }
  6181. AlternateCS.prototype = {
  6182. getRgb: ColorSpace.prototype.getRgb,
  6183. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6184. dest, destOffset) {
  6185. var tmpBuf = this.tmpBuf;
  6186. this.tintFn(src, srcOffset, tmpBuf, 0);
  6187. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6188. },
  6189. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6190. dest, destOffset, bits,
  6191. alpha01) {
  6192. var tintFn = this.tintFn;
  6193. var base = this.base;
  6194. var scale = 1 / ((1 << bits) - 1);
  6195. var baseNumComps = base.numComps;
  6196. var usesZeroToOneRange = base.usesZeroToOneRange;
  6197. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6198. alpha01 === 0;
  6199. var pos = isPassthrough ? destOffset : 0;
  6200. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6201. var numComps = this.numComps;
  6202. var scaled = new Float32Array(numComps);
  6203. var tinted = new Float32Array(baseNumComps);
  6204. var i, j;
  6205. if (usesZeroToOneRange) {
  6206. for (i = 0; i < count; i++) {
  6207. for (j = 0; j < numComps; j++) {
  6208. scaled[j] = src[srcOffset++] * scale;
  6209. }
  6210. tintFn(scaled, 0, tinted, 0);
  6211. for (j = 0; j < baseNumComps; j++) {
  6212. baseBuf[pos++] = tinted[j] * 255;
  6213. }
  6214. }
  6215. } else {
  6216. for (i = 0; i < count; i++) {
  6217. for (j = 0; j < numComps; j++) {
  6218. scaled[j] = src[srcOffset++] * scale;
  6219. }
  6220. tintFn(scaled, 0, tinted, 0);
  6221. base.getRgbItem(tinted, 0, baseBuf, pos);
  6222. pos += baseNumComps;
  6223. }
  6224. }
  6225. if (!isPassthrough) {
  6226. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6227. }
  6228. },
  6229. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6230. alpha01) {
  6231. return this.base.getOutputLength(inputLength *
  6232. this.base.numComps / this.numComps,
  6233. alpha01);
  6234. },
  6235. isPassthrough: ColorSpace.prototype.isPassthrough,
  6236. fillRgb: ColorSpace.prototype.fillRgb,
  6237. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6238. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6239. },
  6240. usesZeroToOneRange: true
  6241. };
  6242. return AlternateCS;
  6243. })();
  6244. var PatternCS = (function PatternCSClosure() {
  6245. function PatternCS(baseCS) {
  6246. this.name = 'Pattern';
  6247. this.base = baseCS;
  6248. }
  6249. PatternCS.prototype = {};
  6250. return PatternCS;
  6251. })();
  6252. var IndexedCS = (function IndexedCSClosure() {
  6253. function IndexedCS(base, highVal, lookup) {
  6254. this.name = 'Indexed';
  6255. this.numComps = 1;
  6256. this.defaultColor = new Uint8Array([0]);
  6257. this.base = base;
  6258. this.highVal = highVal;
  6259. var baseNumComps = base.numComps;
  6260. var length = baseNumComps * highVal;
  6261. var lookupArray;
  6262. if (isStream(lookup)) {
  6263. lookupArray = new Uint8Array(length);
  6264. var bytes = lookup.getBytes(length);
  6265. lookupArray.set(bytes);
  6266. } else if (isString(lookup)) {
  6267. lookupArray = new Uint8Array(length);
  6268. for (var i = 0; i < length; ++i) {
  6269. lookupArray[i] = lookup.charCodeAt(i);
  6270. }
  6271. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6272. lookupArray = lookup;
  6273. } else {
  6274. error('Unrecognized lookup table: ' + lookup);
  6275. }
  6276. this.lookup = lookupArray;
  6277. }
  6278. IndexedCS.prototype = {
  6279. getRgb: ColorSpace.prototype.getRgb,
  6280. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6281. dest, destOffset) {
  6282. var numComps = this.base.numComps;
  6283. var start = src[srcOffset] * numComps;
  6284. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6285. },
  6286. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6287. dest, destOffset, bits,
  6288. alpha01) {
  6289. var base = this.base;
  6290. var numComps = base.numComps;
  6291. var outputDelta = base.getOutputLength(numComps, alpha01);
  6292. var lookup = this.lookup;
  6293. for (var i = 0; i < count; ++i) {
  6294. var lookupPos = src[srcOffset++] * numComps;
  6295. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6296. destOffset += outputDelta;
  6297. }
  6298. },
  6299. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6300. return this.base.getOutputLength(inputLength * this.base.numComps,
  6301. alpha01);
  6302. },
  6303. isPassthrough: ColorSpace.prototype.isPassthrough,
  6304. fillRgb: ColorSpace.prototype.fillRgb,
  6305. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6306. // indexed color maps shouldn't be changed
  6307. return true;
  6308. },
  6309. usesZeroToOneRange: true
  6310. };
  6311. return IndexedCS;
  6312. })();
  6313. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6314. function DeviceGrayCS() {
  6315. this.name = 'DeviceGray';
  6316. this.numComps = 1;
  6317. this.defaultColor = new Float32Array([0]);
  6318. }
  6319. DeviceGrayCS.prototype = {
  6320. getRgb: ColorSpace.prototype.getRgb,
  6321. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6322. dest, destOffset) {
  6323. var c = (src[srcOffset] * 255) | 0;
  6324. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6325. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6326. },
  6327. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6328. dest, destOffset, bits,
  6329. alpha01) {
  6330. var scale = 255 / ((1 << bits) - 1);
  6331. var j = srcOffset, q = destOffset;
  6332. for (var i = 0; i < count; ++i) {
  6333. var c = (scale * src[j++]) | 0;
  6334. dest[q++] = c;
  6335. dest[q++] = c;
  6336. dest[q++] = c;
  6337. q += alpha01;
  6338. }
  6339. },
  6340. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6341. alpha01) {
  6342. return inputLength * (3 + alpha01);
  6343. },
  6344. isPassthrough: ColorSpace.prototype.isPassthrough,
  6345. fillRgb: ColorSpace.prototype.fillRgb,
  6346. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6347. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6348. },
  6349. usesZeroToOneRange: true
  6350. };
  6351. return DeviceGrayCS;
  6352. })();
  6353. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6354. function DeviceRgbCS() {
  6355. this.name = 'DeviceRGB';
  6356. this.numComps = 3;
  6357. this.defaultColor = new Float32Array([0, 0, 0]);
  6358. }
  6359. DeviceRgbCS.prototype = {
  6360. getRgb: ColorSpace.prototype.getRgb,
  6361. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6362. dest, destOffset) {
  6363. var r = (src[srcOffset] * 255) | 0;
  6364. var g = (src[srcOffset + 1] * 255) | 0;
  6365. var b = (src[srcOffset + 2] * 255) | 0;
  6366. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6367. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6368. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6369. },
  6370. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6371. dest, destOffset, bits,
  6372. alpha01) {
  6373. if (bits === 8 && alpha01 === 0) {
  6374. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6375. return;
  6376. }
  6377. var scale = 255 / ((1 << bits) - 1);
  6378. var j = srcOffset, q = destOffset;
  6379. for (var i = 0; i < count; ++i) {
  6380. dest[q++] = (scale * src[j++]) | 0;
  6381. dest[q++] = (scale * src[j++]) | 0;
  6382. dest[q++] = (scale * src[j++]) | 0;
  6383. q += alpha01;
  6384. }
  6385. },
  6386. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6387. alpha01) {
  6388. return (inputLength * (3 + alpha01) / 3) | 0;
  6389. },
  6390. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6391. return bits === 8;
  6392. },
  6393. fillRgb: ColorSpace.prototype.fillRgb,
  6394. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6395. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6396. },
  6397. usesZeroToOneRange: true
  6398. };
  6399. return DeviceRgbCS;
  6400. })();
  6401. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6402. // The coefficients below was found using numerical analysis: the method of
  6403. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6404. // where color_value is the tabular value from the table of sampled RGB colors
  6405. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6406. // CMYK color conversion using the estimation below:
  6407. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6408. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6409. var c = src[srcOffset + 0] * srcScale;
  6410. var m = src[srcOffset + 1] * srcScale;
  6411. var y = src[srcOffset + 2] * srcScale;
  6412. var k = src[srcOffset + 3] * srcScale;
  6413. var r =
  6414. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6415. 18.82290502165302 * y + 212.25662451639585 * k +
  6416. -285.2331026137004) +
  6417. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6418. -17.873870861415444 * k - 5.497006427196366) +
  6419. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6420. 17.5119270841813) +
  6421. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6422. var g =
  6423. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6424. 6.871425592049007 * y + 31.159100130055922 * k +
  6425. -79.2970844816548) +
  6426. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6427. 131.35250912493976 * k - 190.9453302588951) +
  6428. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6429. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6430. var b =
  6431. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6432. 30.89978309703729 * y - 0.23883238689178934 * k +
  6433. -14.183576799673286) +
  6434. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6435. 50.606957656360734 * k - 112.23884253719248) +
  6436. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6437. -193.58209356861505) +
  6438. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6439. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6440. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6441. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6442. }
  6443. function DeviceCmykCS() {
  6444. this.name = 'DeviceCMYK';
  6445. this.numComps = 4;
  6446. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6447. }
  6448. DeviceCmykCS.prototype = {
  6449. getRgb: ColorSpace.prototype.getRgb,
  6450. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6451. dest, destOffset) {
  6452. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6453. },
  6454. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6455. dest, destOffset, bits,
  6456. alpha01) {
  6457. var scale = 1 / ((1 << bits) - 1);
  6458. for (var i = 0; i < count; i++) {
  6459. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6460. srcOffset += 4;
  6461. destOffset += 3 + alpha01;
  6462. }
  6463. },
  6464. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6465. alpha01) {
  6466. return (inputLength / 4 * (3 + alpha01)) | 0;
  6467. },
  6468. isPassthrough: ColorSpace.prototype.isPassthrough,
  6469. fillRgb: ColorSpace.prototype.fillRgb,
  6470. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6471. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6472. },
  6473. usesZeroToOneRange: true
  6474. };
  6475. return DeviceCmykCS;
  6476. })();
  6477. //
  6478. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6479. //
  6480. var CalGrayCS = (function CalGrayCSClosure() {
  6481. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6482. this.name = 'CalGray';
  6483. this.numComps = 1;
  6484. this.defaultColor = new Float32Array([0]);
  6485. if (!whitePoint) {
  6486. error('WhitePoint missing - required for color space CalGray');
  6487. }
  6488. blackPoint = blackPoint || [0, 0, 0];
  6489. gamma = gamma || 1;
  6490. // Translate arguments to spec variables.
  6491. this.XW = whitePoint[0];
  6492. this.YW = whitePoint[1];
  6493. this.ZW = whitePoint[2];
  6494. this.XB = blackPoint[0];
  6495. this.YB = blackPoint[1];
  6496. this.ZB = blackPoint[2];
  6497. this.G = gamma;
  6498. // Validate variables as per spec.
  6499. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6500. error('Invalid WhitePoint components for ' + this.name +
  6501. ', no fallback available');
  6502. }
  6503. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6504. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6505. this.XB = this.YB = this.ZB = 0;
  6506. }
  6507. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6508. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6509. ', ZB: ' + this.ZB + ', only default values are supported.');
  6510. }
  6511. if (this.G < 1) {
  6512. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6513. ', falling back to default');
  6514. this.G = 1;
  6515. }
  6516. }
  6517. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6518. // A represents a gray component of a calibrated gray space.
  6519. // A <---> AG in the spec
  6520. var A = src[srcOffset] * scale;
  6521. var AG = Math.pow(A, cs.G);
  6522. // Computes L as per spec. ( = cs.YW * AG )
  6523. // Except if other than default BlackPoint values are used.
  6524. var L = cs.YW * AG;
  6525. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6526. // Convert values to rgb range [0, 255].
  6527. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6528. dest[destOffset] = val;
  6529. dest[destOffset + 1] = val;
  6530. dest[destOffset + 2] = val;
  6531. }
  6532. CalGrayCS.prototype = {
  6533. getRgb: ColorSpace.prototype.getRgb,
  6534. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6535. dest, destOffset) {
  6536. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6537. },
  6538. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6539. dest, destOffset, bits,
  6540. alpha01) {
  6541. var scale = 1 / ((1 << bits) - 1);
  6542. for (var i = 0; i < count; ++i) {
  6543. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6544. srcOffset += 1;
  6545. destOffset += 3 + alpha01;
  6546. }
  6547. },
  6548. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6549. return inputLength * (3 + alpha01);
  6550. },
  6551. isPassthrough: ColorSpace.prototype.isPassthrough,
  6552. fillRgb: ColorSpace.prototype.fillRgb,
  6553. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6554. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6555. },
  6556. usesZeroToOneRange: true
  6557. };
  6558. return CalGrayCS;
  6559. })();
  6560. //
  6561. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6562. //
  6563. var CalRGBCS = (function CalRGBCSClosure() {
  6564. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6565. // matrices.
  6566. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6567. 0.8951, 0.2664, -0.1614,
  6568. -0.7502, 1.7135, 0.0367,
  6569. 0.0389, -0.0685, 1.0296]);
  6570. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6571. 0.9869929, -0.1470543, 0.1599627,
  6572. 0.4323053, 0.5183603, 0.0492912,
  6573. -0.0085287, 0.0400428, 0.9684867]);
  6574. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6575. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6576. 3.2404542, -1.5371385, -0.4985314,
  6577. -0.9692660, 1.8760108, 0.0415560,
  6578. 0.0556434, -0.2040259, 1.0572252]);
  6579. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6580. var tempNormalizeMatrix = new Float32Array(3);
  6581. var tempConvertMatrix1 = new Float32Array(3);
  6582. var tempConvertMatrix2 = new Float32Array(3);
  6583. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6584. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6585. this.name = 'CalRGB';
  6586. this.numComps = 3;
  6587. this.defaultColor = new Float32Array(3);
  6588. if (!whitePoint) {
  6589. error('WhitePoint missing - required for color space CalRGB');
  6590. }
  6591. blackPoint = blackPoint || new Float32Array(3);
  6592. gamma = gamma || new Float32Array([1, 1, 1]);
  6593. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6594. // Translate arguments to spec variables.
  6595. var XW = whitePoint[0];
  6596. var YW = whitePoint[1];
  6597. var ZW = whitePoint[2];
  6598. this.whitePoint = whitePoint;
  6599. var XB = blackPoint[0];
  6600. var YB = blackPoint[1];
  6601. var ZB = blackPoint[2];
  6602. this.blackPoint = blackPoint;
  6603. this.GR = gamma[0];
  6604. this.GG = gamma[1];
  6605. this.GB = gamma[2];
  6606. this.MXA = matrix[0];
  6607. this.MYA = matrix[1];
  6608. this.MZA = matrix[2];
  6609. this.MXB = matrix[3];
  6610. this.MYB = matrix[4];
  6611. this.MZB = matrix[5];
  6612. this.MXC = matrix[6];
  6613. this.MYC = matrix[7];
  6614. this.MZC = matrix[8];
  6615. // Validate variables as per spec.
  6616. if (XW < 0 || ZW < 0 || YW !== 1) {
  6617. error('Invalid WhitePoint components for ' + this.name +
  6618. ', no fallback available');
  6619. }
  6620. if (XB < 0 || YB < 0 || ZB < 0) {
  6621. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6622. ', ' + ZB + '], falling back to default');
  6623. this.blackPoint = new Float32Array(3);
  6624. }
  6625. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6626. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6627. '] for ' + this.name + ', falling back to default');
  6628. this.GR = this.GG = this.GB = 1;
  6629. }
  6630. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6631. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6632. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6633. info('Invalid Matrix for ' + this.name + ' [' +
  6634. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6635. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6636. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6637. '], falling back to default');
  6638. this.MXA = this.MYB = this.MZC = 1;
  6639. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6640. }
  6641. }
  6642. function matrixProduct(a, b, result) {
  6643. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6644. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6645. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6646. }
  6647. function convertToFlat(sourceWhitePoint, LMS, result) {
  6648. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6649. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6650. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6651. }
  6652. function convertToD65(sourceWhitePoint, LMS, result) {
  6653. var D65X = 0.95047;
  6654. var D65Y = 1;
  6655. var D65Z = 1.08883;
  6656. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6657. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6658. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6659. }
  6660. function sRGBTransferFunction(color) {
  6661. // See http://en.wikipedia.org/wiki/SRGB.
  6662. if (color <= 0.0031308){
  6663. return adjustToRange(0, 1, 12.92 * color);
  6664. }
  6665. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6666. }
  6667. function adjustToRange(min, max, value) {
  6668. return Math.max(min, Math.min(max, value));
  6669. }
  6670. function decodeL(L) {
  6671. if (L < 0) {
  6672. return -decodeL(-L);
  6673. }
  6674. if (L > 8.0) {
  6675. return Math.pow(((L + 16) / 116), 3);
  6676. }
  6677. return L * DECODE_L_CONSTANT;
  6678. }
  6679. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6680. // In case the blackPoint is already the default blackPoint then there is
  6681. // no need to do compensation.
  6682. if (sourceBlackPoint[0] === 0 &&
  6683. sourceBlackPoint[1] === 0 &&
  6684. sourceBlackPoint[2] === 0) {
  6685. result[0] = XYZ_Flat[0];
  6686. result[1] = XYZ_Flat[1];
  6687. result[2] = XYZ_Flat[2];
  6688. return;
  6689. }
  6690. // For the blackPoint calculation details, please see
  6691. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6692. // AdobeBPC.pdf.
  6693. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6694. var zeroDecodeL = decodeL(0);
  6695. var X_DST = zeroDecodeL;
  6696. var X_SRC = decodeL(sourceBlackPoint[0]);
  6697. var Y_DST = zeroDecodeL;
  6698. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6699. var Z_DST = zeroDecodeL;
  6700. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6701. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6702. var X_Offset = 1 - X_Scale;
  6703. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6704. var Y_Offset = 1 - Y_Scale;
  6705. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6706. var Z_Offset = 1 - Z_Scale;
  6707. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6708. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6709. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6710. }
  6711. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6712. // In case the whitePoint is already flat then there is no need to do
  6713. // normalization.
  6714. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6715. result[0] = XYZ_In[0];
  6716. result[1] = XYZ_In[1];
  6717. result[2] = XYZ_In[2];
  6718. return;
  6719. }
  6720. var LMS = result;
  6721. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6722. var LMS_Flat = tempNormalizeMatrix;
  6723. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6724. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6725. }
  6726. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6727. var LMS = result;
  6728. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6729. var LMS_D65 = tempNormalizeMatrix;
  6730. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6731. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6732. }
  6733. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6734. // A, B and C represent a red, green and blue components of a calibrated
  6735. // rgb space.
  6736. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6737. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6738. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6739. // A <---> AGR in the spec
  6740. // B <---> BGG in the spec
  6741. // C <---> CGB in the spec
  6742. var AGR = Math.pow(A, cs.GR);
  6743. var BGG = Math.pow(B, cs.GG);
  6744. var CGB = Math.pow(C, cs.GB);
  6745. // Computes intermediate variables L, M, N as per spec.
  6746. // To decode X, Y, Z values map L, M, N directly to them.
  6747. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6748. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6749. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6750. // The following calculations are based on this document:
  6751. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6752. // AdobeBPC.pdf.
  6753. var XYZ = tempConvertMatrix1;
  6754. XYZ[0] = X;
  6755. XYZ[1] = Y;
  6756. XYZ[2] = Z;
  6757. var XYZ_Flat = tempConvertMatrix2;
  6758. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6759. var XYZ_Black = tempConvertMatrix1;
  6760. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6761. var XYZ_D65 = tempConvertMatrix2;
  6762. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6763. var SRGB = tempConvertMatrix1;
  6764. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6765. var sR = sRGBTransferFunction(SRGB[0]);
  6766. var sG = sRGBTransferFunction(SRGB[1]);
  6767. var sB = sRGBTransferFunction(SRGB[2]);
  6768. // Convert the values to rgb range [0, 255].
  6769. dest[destOffset] = Math.round(sR * 255);
  6770. dest[destOffset + 1] = Math.round(sG * 255);
  6771. dest[destOffset + 2] = Math.round(sB * 255);
  6772. }
  6773. CalRGBCS.prototype = {
  6774. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6775. var rgb = new Uint8Array(3);
  6776. this.getRgbItem(src, srcOffset, rgb, 0);
  6777. return rgb;
  6778. },
  6779. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6780. dest, destOffset) {
  6781. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6782. },
  6783. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6784. dest, destOffset, bits,
  6785. alpha01) {
  6786. var scale = 1 / ((1 << bits) - 1);
  6787. for (var i = 0; i < count; ++i) {
  6788. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6789. srcOffset += 3;
  6790. destOffset += 3 + alpha01;
  6791. }
  6792. },
  6793. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6794. return (inputLength * (3 + alpha01) / 3) | 0;
  6795. },
  6796. isPassthrough: ColorSpace.prototype.isPassthrough,
  6797. fillRgb: ColorSpace.prototype.fillRgb,
  6798. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6799. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6800. },
  6801. usesZeroToOneRange: true
  6802. };
  6803. return CalRGBCS;
  6804. })();
  6805. //
  6806. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6807. //
  6808. var LabCS = (function LabCSClosure() {
  6809. function LabCS(whitePoint, blackPoint, range) {
  6810. this.name = 'Lab';
  6811. this.numComps = 3;
  6812. this.defaultColor = new Float32Array([0, 0, 0]);
  6813. if (!whitePoint) {
  6814. error('WhitePoint missing - required for color space Lab');
  6815. }
  6816. blackPoint = blackPoint || [0, 0, 0];
  6817. range = range || [-100, 100, -100, 100];
  6818. // Translate args to spec variables
  6819. this.XW = whitePoint[0];
  6820. this.YW = whitePoint[1];
  6821. this.ZW = whitePoint[2];
  6822. this.amin = range[0];
  6823. this.amax = range[1];
  6824. this.bmin = range[2];
  6825. this.bmax = range[3];
  6826. // These are here just for completeness - the spec doesn't offer any
  6827. // formulas that use BlackPoint in Lab
  6828. this.XB = blackPoint[0];
  6829. this.YB = blackPoint[1];
  6830. this.ZB = blackPoint[2];
  6831. // Validate vars as per spec
  6832. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6833. error('Invalid WhitePoint components, no fallback available');
  6834. }
  6835. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6836. info('Invalid BlackPoint, falling back to default');
  6837. this.XB = this.YB = this.ZB = 0;
  6838. }
  6839. if (this.amin > this.amax || this.bmin > this.bmax) {
  6840. info('Invalid Range, falling back to defaults');
  6841. this.amin = -100;
  6842. this.amax = 100;
  6843. this.bmin = -100;
  6844. this.bmax = 100;
  6845. }
  6846. }
  6847. // Function g(x) from spec
  6848. function fn_g(x) {
  6849. if (x >= 6 / 29) {
  6850. return x * x * x;
  6851. } else {
  6852. return (108 / 841) * (x - 4 / 29);
  6853. }
  6854. }
  6855. function decode(value, high1, low2, high2) {
  6856. return low2 + (value) * (high2 - low2) / (high1);
  6857. }
  6858. // If decoding is needed maxVal should be 2^bits per component - 1.
  6859. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6860. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6861. // not the usual [0, 1]. If a command like setFillColor is used the src
  6862. // values will already be within the correct range. However, if we are
  6863. // converting an image we have to map the values to the correct range given
  6864. // above.
  6865. // Ls,as,bs <---> L*,a*,b* in the spec
  6866. var Ls = src[srcOffset];
  6867. var as = src[srcOffset + 1];
  6868. var bs = src[srcOffset + 2];
  6869. if (maxVal !== false) {
  6870. Ls = decode(Ls, maxVal, 0, 100);
  6871. as = decode(as, maxVal, cs.amin, cs.amax);
  6872. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6873. }
  6874. // Adjust limits of 'as' and 'bs'
  6875. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6876. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6877. // Computes intermediate variables X,Y,Z as per spec
  6878. var M = (Ls + 16) / 116;
  6879. var L = M + (as / 500);
  6880. var N = M - (bs / 200);
  6881. var X = cs.XW * fn_g(L);
  6882. var Y = cs.YW * fn_g(M);
  6883. var Z = cs.ZW * fn_g(N);
  6884. var r, g, b;
  6885. // Using different conversions for D50 and D65 white points,
  6886. // per http://www.color.org/srgb.pdf
  6887. if (cs.ZW < 1) {
  6888. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6889. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6890. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6891. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6892. } else {
  6893. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6894. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6895. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6896. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6897. }
  6898. // clamp color values to [0,1] range then convert to [0,255] range.
  6899. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6900. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6901. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6902. }
  6903. LabCS.prototype = {
  6904. getRgb: ColorSpace.prototype.getRgb,
  6905. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6906. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6907. },
  6908. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6909. dest, destOffset, bits,
  6910. alpha01) {
  6911. var maxVal = (1 << bits) - 1;
  6912. for (var i = 0; i < count; i++) {
  6913. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6914. srcOffset += 3;
  6915. destOffset += 3 + alpha01;
  6916. }
  6917. },
  6918. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6919. return (inputLength * (3 + alpha01) / 3) | 0;
  6920. },
  6921. isPassthrough: ColorSpace.prototype.isPassthrough,
  6922. fillRgb: ColorSpace.prototype.fillRgb,
  6923. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6924. // XXX: Decoding is handled with the lab conversion because of the strange
  6925. // ranges that are used.
  6926. return true;
  6927. },
  6928. usesZeroToOneRange: false
  6929. };
  6930. return LabCS;
  6931. })();
  6932. var ARCFourCipher = (function ARCFourCipherClosure() {
  6933. function ARCFourCipher(key) {
  6934. this.a = 0;
  6935. this.b = 0;
  6936. var s = new Uint8Array(256);
  6937. var i, j = 0, tmp, keyLength = key.length;
  6938. for (i = 0; i < 256; ++i) {
  6939. s[i] = i;
  6940. }
  6941. for (i = 0; i < 256; ++i) {
  6942. tmp = s[i];
  6943. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6944. s[i] = s[j];
  6945. s[j] = tmp;
  6946. }
  6947. this.s = s;
  6948. }
  6949. ARCFourCipher.prototype = {
  6950. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6951. var i, n = data.length, tmp, tmp2;
  6952. var a = this.a, b = this.b, s = this.s;
  6953. var output = new Uint8Array(n);
  6954. for (i = 0; i < n; ++i) {
  6955. a = (a + 1) & 0xFF;
  6956. tmp = s[a];
  6957. b = (b + tmp) & 0xFF;
  6958. tmp2 = s[b];
  6959. s[a] = tmp2;
  6960. s[b] = tmp;
  6961. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6962. }
  6963. this.a = a;
  6964. this.b = b;
  6965. return output;
  6966. }
  6967. };
  6968. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6969. return ARCFourCipher;
  6970. })();
  6971. var calculateMD5 = (function calculateMD5Closure() {
  6972. var r = new Uint8Array([
  6973. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6974. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6975. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6976. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6977. var k = new Int32Array([
  6978. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6979. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6980. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6981. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6982. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6983. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6984. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6985. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6986. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6987. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6988. -145523070, -1120210379, 718787259, -343485551]);
  6989. function hash(data, offset, length) {
  6990. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6991. // pre-processing
  6992. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6993. var padded = new Uint8Array(paddedLength);
  6994. var i, j, n;
  6995. for (i = 0; i < length; ++i) {
  6996. padded[i] = data[offset++];
  6997. }
  6998. padded[i++] = 0x80;
  6999. n = paddedLength - 8;
  7000. while (i < n) {
  7001. padded[i++] = 0;
  7002. }
  7003. padded[i++] = (length << 3) & 0xFF;
  7004. padded[i++] = (length >> 5) & 0xFF;
  7005. padded[i++] = (length >> 13) & 0xFF;
  7006. padded[i++] = (length >> 21) & 0xFF;
  7007. padded[i++] = (length >>> 29) & 0xFF;
  7008. padded[i++] = 0;
  7009. padded[i++] = 0;
  7010. padded[i++] = 0;
  7011. var w = new Int32Array(16);
  7012. for (i = 0; i < paddedLength;) {
  7013. for (j = 0; j < 16; ++j, i += 4) {
  7014. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7015. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7016. }
  7017. var a = h0, b = h1, c = h2, d = h3, f, g;
  7018. for (j = 0; j < 64; ++j) {
  7019. if (j < 16) {
  7020. f = (b & c) | ((~b) & d);
  7021. g = j;
  7022. } else if (j < 32) {
  7023. f = (d & b) | ((~d) & c);
  7024. g = (5 * j + 1) & 15;
  7025. } else if (j < 48) {
  7026. f = b ^ c ^ d;
  7027. g = (3 * j + 5) & 15;
  7028. } else {
  7029. f = c ^ (b | (~d));
  7030. g = (7 * j) & 15;
  7031. }
  7032. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7033. d = c;
  7034. c = b;
  7035. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7036. a = tmp;
  7037. }
  7038. h0 = (h0 + a) | 0;
  7039. h1 = (h1 + b) | 0;
  7040. h2 = (h2 + c) | 0;
  7041. h3 = (h3 + d) | 0;
  7042. }
  7043. return new Uint8Array([
  7044. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7045. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7046. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7047. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7048. ]);
  7049. }
  7050. return hash;
  7051. })();
  7052. var Word64 = (function Word64Closure() {
  7053. function Word64(highInteger, lowInteger) {
  7054. this.high = highInteger | 0;
  7055. this.low = lowInteger | 0;
  7056. }
  7057. Word64.prototype = {
  7058. and: function Word64_and(word) {
  7059. this.high &= word.high;
  7060. this.low &= word.low;
  7061. },
  7062. xor: function Word64_xor(word) {
  7063. this.high ^= word.high;
  7064. this.low ^= word.low;
  7065. },
  7066. or: function Word64_or(word) {
  7067. this.high |= word.high;
  7068. this.low |= word.low;
  7069. },
  7070. shiftRight: function Word64_shiftRight(places) {
  7071. if (places >= 32) {
  7072. this.low = (this.high >>> (places - 32)) | 0;
  7073. this.high = 0;
  7074. } else {
  7075. this.low = (this.low >>> places) | (this.high << (32 - places));
  7076. this.high = (this.high >>> places) | 0;
  7077. }
  7078. },
  7079. shiftLeft: function Word64_shiftLeft(places) {
  7080. if (places >= 32) {
  7081. this.high = this.low << (places - 32);
  7082. this.low = 0;
  7083. } else {
  7084. this.high = (this.high << places) | (this.low >>> (32 - places));
  7085. this.low = this.low << places;
  7086. }
  7087. },
  7088. rotateRight: function Word64_rotateRight(places) {
  7089. var low, high;
  7090. if (places & 32) {
  7091. high = this.low;
  7092. low = this.high;
  7093. } else {
  7094. low = this.low;
  7095. high = this.high;
  7096. }
  7097. places &= 31;
  7098. this.low = (low >>> places) | (high << (32 - places));
  7099. this.high = (high >>> places) | (low << (32 - places));
  7100. },
  7101. not: function Word64_not() {
  7102. this.high = ~this.high;
  7103. this.low = ~this.low;
  7104. },
  7105. add: function Word64_add(word) {
  7106. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7107. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7108. if (lowAdd > 0xFFFFFFFF) {
  7109. highAdd += 1;
  7110. }
  7111. this.low = lowAdd | 0;
  7112. this.high = highAdd | 0;
  7113. },
  7114. copyTo: function Word64_copyTo(bytes, offset) {
  7115. bytes[offset] = (this.high >>> 24) & 0xFF;
  7116. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7117. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7118. bytes[offset + 3] = this.high & 0xFF;
  7119. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7120. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7121. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7122. bytes[offset + 7] = this.low & 0xFF;
  7123. },
  7124. assign: function Word64_assign(word) {
  7125. this.high = word.high;
  7126. this.low = word.low;
  7127. }
  7128. };
  7129. return Word64;
  7130. })();
  7131. var calculateSHA256 = (function calculateSHA256Closure() {
  7132. function rotr(x, n) {
  7133. return (x >>> n) | (x << 32 - n);
  7134. }
  7135. function ch(x, y, z) {
  7136. return (x & y) ^ (~x & z);
  7137. }
  7138. function maj(x, y, z) {
  7139. return (x & y) ^ (x & z) ^ (y & z);
  7140. }
  7141. function sigma(x) {
  7142. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7143. }
  7144. function sigmaPrime(x) {
  7145. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7146. }
  7147. function littleSigma(x) {
  7148. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7149. }
  7150. function littleSigmaPrime(x) {
  7151. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7152. }
  7153. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7154. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7155. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7156. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7157. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7158. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7159. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7160. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7161. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7162. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7163. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7164. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7165. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7166. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7167. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7168. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7169. function hash(data, offset, length) {
  7170. // initial hash values
  7171. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7172. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7173. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7174. // pre-processing
  7175. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7176. var padded = new Uint8Array(paddedLength);
  7177. var i, j, n;
  7178. for (i = 0; i < length; ++i) {
  7179. padded[i] = data[offset++];
  7180. }
  7181. padded[i++] = 0x80;
  7182. n = paddedLength - 8;
  7183. while (i < n) {
  7184. padded[i++] = 0;
  7185. }
  7186. padded[i++] = 0;
  7187. padded[i++] = 0;
  7188. padded[i++] = 0;
  7189. padded[i++] = (length >>> 29) & 0xFF;
  7190. padded[i++] = (length >> 21) & 0xFF;
  7191. padded[i++] = (length >> 13) & 0xFF;
  7192. padded[i++] = (length >> 5) & 0xFF;
  7193. padded[i++] = (length << 3) & 0xFF;
  7194. var w = new Uint32Array(64);
  7195. // for each 512 bit block
  7196. for (i = 0; i < paddedLength;) {
  7197. for (j = 0; j < 16; ++j) {
  7198. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7199. (padded[i + 2] << 8) | (padded[i + 3]));
  7200. i += 4;
  7201. }
  7202. for (j = 16; j < 64; ++j) {
  7203. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7204. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7205. }
  7206. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7207. f = h5, g = h6, h = h7, t1, t2;
  7208. for (j = 0; j < 64; ++j) {
  7209. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7210. t2 = sigma(a) + maj(a, b, c);
  7211. h = g;
  7212. g = f;
  7213. f = e;
  7214. e = (d + t1) | 0;
  7215. d = c;
  7216. c = b;
  7217. b = a;
  7218. a = (t1 + t2) | 0;
  7219. }
  7220. h0 = (h0 + a) | 0;
  7221. h1 = (h1 + b) | 0;
  7222. h2 = (h2 + c) | 0;
  7223. h3 = (h3 + d) | 0;
  7224. h4 = (h4 + e) | 0;
  7225. h5 = (h5 + f) | 0;
  7226. h6 = (h6 + g) | 0;
  7227. h7 = (h7 + h) | 0;
  7228. }
  7229. return new Uint8Array([
  7230. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7231. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7232. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7233. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7234. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7235. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7236. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7237. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7238. ]);
  7239. }
  7240. return hash;
  7241. })();
  7242. var calculateSHA512 = (function calculateSHA512Closure() {
  7243. function ch(result, x, y, z, tmp) {
  7244. result.assign(x);
  7245. result.and(y);
  7246. tmp.assign(x);
  7247. tmp.not();
  7248. tmp.and(z);
  7249. result.xor(tmp);
  7250. }
  7251. function maj(result, x, y, z, tmp) {
  7252. result.assign(x);
  7253. result.and(y);
  7254. tmp.assign(x);
  7255. tmp.and(z);
  7256. result.xor(tmp);
  7257. tmp.assign(y);
  7258. tmp.and(z);
  7259. result.xor(tmp);
  7260. }
  7261. function sigma(result, x, tmp) {
  7262. result.assign(x);
  7263. result.rotateRight(28);
  7264. tmp.assign(x);
  7265. tmp.rotateRight(34);
  7266. result.xor(tmp);
  7267. tmp.assign(x);
  7268. tmp.rotateRight(39);
  7269. result.xor(tmp);
  7270. }
  7271. function sigmaPrime(result, x, tmp) {
  7272. result.assign(x);
  7273. result.rotateRight(14);
  7274. tmp.assign(x);
  7275. tmp.rotateRight(18);
  7276. result.xor(tmp);
  7277. tmp.assign(x);
  7278. tmp.rotateRight(41);
  7279. result.xor(tmp);
  7280. }
  7281. function littleSigma(result, x, tmp) {
  7282. result.assign(x);
  7283. result.rotateRight(1);
  7284. tmp.assign(x);
  7285. tmp.rotateRight(8);
  7286. result.xor(tmp);
  7287. tmp.assign(x);
  7288. tmp.shiftRight(7);
  7289. result.xor(tmp);
  7290. }
  7291. function littleSigmaPrime(result, x, tmp) {
  7292. result.assign(x);
  7293. result.rotateRight(19);
  7294. tmp.assign(x);
  7295. tmp.rotateRight(61);
  7296. result.xor(tmp);
  7297. tmp.assign(x);
  7298. tmp.shiftRight(6);
  7299. result.xor(tmp);
  7300. }
  7301. var k = [
  7302. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7303. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7304. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7305. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7306. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7307. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7308. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7309. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7310. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7311. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7312. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7313. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7314. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7315. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7316. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7317. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7318. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7319. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7320. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7321. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7322. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7323. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7324. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7325. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7326. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7327. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7328. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7329. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7330. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7331. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7332. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7333. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7334. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7335. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7336. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7337. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7338. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7339. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7340. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7341. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7342. function hash(data, offset, length, mode384) {
  7343. mode384 = !!mode384;
  7344. // initial hash values
  7345. var h0, h1, h2, h3, h4, h5, h6, h7;
  7346. if (!mode384) {
  7347. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7348. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7349. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7350. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7351. h4 = new Word64(0x510e527f, 0xade682d1);
  7352. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7353. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7354. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7355. }
  7356. else {
  7357. // SHA384 is exactly the same
  7358. // except with different starting values and a trimmed result
  7359. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7360. h1 = new Word64(0x629a292a, 0x367cd507);
  7361. h2 = new Word64(0x9159015a, 0x3070dd17);
  7362. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7363. h4 = new Word64(0x67332667, 0xffc00b31);
  7364. h5 = new Word64(0x8eb44a87, 0x68581511);
  7365. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7366. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7367. }
  7368. // pre-processing
  7369. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7370. var padded = new Uint8Array(paddedLength);
  7371. var i, j, n;
  7372. for (i = 0; i < length; ++i) {
  7373. padded[i] = data[offset++];
  7374. }
  7375. padded[i++] = 0x80;
  7376. n = paddedLength - 16;
  7377. while (i < n) {
  7378. padded[i++] = 0;
  7379. }
  7380. padded[i++] = 0;
  7381. padded[i++] = 0;
  7382. padded[i++] = 0;
  7383. padded[i++] = 0;
  7384. padded[i++] = 0;
  7385. padded[i++] = 0;
  7386. padded[i++] = 0;
  7387. padded[i++] = 0;
  7388. padded[i++] = 0;
  7389. padded[i++] = 0;
  7390. padded[i++] = 0;
  7391. padded[i++] = (length >>> 29) & 0xFF;
  7392. padded[i++] = (length >> 21) & 0xFF;
  7393. padded[i++] = (length >> 13) & 0xFF;
  7394. padded[i++] = (length >> 5) & 0xFF;
  7395. padded[i++] = (length << 3) & 0xFF;
  7396. var w = new Array(80);
  7397. for (i = 0; i < 80; i++) {
  7398. w[i] = new Word64(0, 0);
  7399. }
  7400. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7401. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7402. var g = new Word64(0, 0), h = new Word64(0, 0);
  7403. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7404. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7405. // for each 1024 bit block
  7406. for (i = 0; i < paddedLength;) {
  7407. for (j = 0; j < 16; ++j) {
  7408. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7409. (padded[i + 2] << 8) | (padded[i + 3]);
  7410. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7411. (padded[i + 6]) << 8 | (padded[i + 7]);
  7412. i += 8;
  7413. }
  7414. for (j = 16; j < 80; ++j) {
  7415. tmp3 = w[j];
  7416. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7417. tmp3.add(w[j - 7]);
  7418. littleSigma(tmp1, w[j - 15], tmp2);
  7419. tmp3.add(tmp1);
  7420. tmp3.add(w[j - 16]);
  7421. }
  7422. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7423. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7424. for (j = 0; j < 80; ++j) {
  7425. t1.assign(h);
  7426. sigmaPrime(tmp1, e, tmp2);
  7427. t1.add(tmp1);
  7428. ch(tmp1, e, f, g, tmp2);
  7429. t1.add(tmp1);
  7430. t1.add(k[j]);
  7431. t1.add(w[j]);
  7432. sigma(t2, a, tmp2);
  7433. maj(tmp1, a, b, c, tmp2);
  7434. t2.add(tmp1);
  7435. tmp3 = h;
  7436. h = g;
  7437. g = f;
  7438. f = e;
  7439. d.add(t1);
  7440. e = d;
  7441. d = c;
  7442. c = b;
  7443. b = a;
  7444. tmp3.assign(t1);
  7445. tmp3.add(t2);
  7446. a = tmp3;
  7447. }
  7448. h0.add(a);
  7449. h1.add(b);
  7450. h2.add(c);
  7451. h3.add(d);
  7452. h4.add(e);
  7453. h5.add(f);
  7454. h6.add(g);
  7455. h7.add(h);
  7456. }
  7457. var result;
  7458. if (!mode384) {
  7459. result = new Uint8Array(64);
  7460. h0.copyTo(result,0);
  7461. h1.copyTo(result,8);
  7462. h2.copyTo(result,16);
  7463. h3.copyTo(result,24);
  7464. h4.copyTo(result,32);
  7465. h5.copyTo(result,40);
  7466. h6.copyTo(result,48);
  7467. h7.copyTo(result,56);
  7468. }
  7469. else {
  7470. result = new Uint8Array(48);
  7471. h0.copyTo(result,0);
  7472. h1.copyTo(result,8);
  7473. h2.copyTo(result,16);
  7474. h3.copyTo(result,24);
  7475. h4.copyTo(result,32);
  7476. h5.copyTo(result,40);
  7477. }
  7478. return result;
  7479. }
  7480. return hash;
  7481. })();
  7482. var calculateSHA384 = (function calculateSHA384Closure() {
  7483. function hash(data, offset, length) {
  7484. return calculateSHA512(data, offset, length, true);
  7485. }
  7486. return hash;
  7487. })();
  7488. var NullCipher = (function NullCipherClosure() {
  7489. function NullCipher() {
  7490. }
  7491. NullCipher.prototype = {
  7492. decryptBlock: function NullCipher_decryptBlock(data) {
  7493. return data;
  7494. }
  7495. };
  7496. return NullCipher;
  7497. })();
  7498. var AES128Cipher = (function AES128CipherClosure() {
  7499. var rcon = new Uint8Array([
  7500. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7501. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7502. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7503. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7504. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7505. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7506. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7507. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7508. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7509. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7510. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7511. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7512. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7513. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7514. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7515. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7516. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7517. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7518. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7519. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7520. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7521. 0x74, 0xe8, 0xcb, 0x8d]);
  7522. var s = new Uint8Array([
  7523. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7524. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7525. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7526. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7527. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7528. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7529. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7530. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7531. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7532. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7533. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7534. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7535. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7536. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7537. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7538. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7539. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7540. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7541. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7542. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7543. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7544. 0xb0, 0x54, 0xbb, 0x16]);
  7545. var inv_s = new Uint8Array([
  7546. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7547. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7548. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7549. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7550. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7551. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7552. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7553. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7554. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7555. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7556. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7557. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7558. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7559. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7560. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7561. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7562. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7563. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7564. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7565. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7566. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7567. 0x55, 0x21, 0x0c, 0x7d]);
  7568. var mixCol = new Uint8Array(256);
  7569. for (var i = 0; i < 256; i++) {
  7570. if (i < 128) {
  7571. mixCol[i] = i << 1;
  7572. } else {
  7573. mixCol[i] = (i << 1) ^ 0x1b;
  7574. }
  7575. }
  7576. var mix = new Uint32Array([
  7577. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7578. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7579. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7580. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7581. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7582. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7583. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7584. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7585. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7586. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7587. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7588. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7589. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7590. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7591. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7592. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7593. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7594. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7595. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7596. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7597. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7598. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7599. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7600. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7601. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7602. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7603. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7604. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7605. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7606. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7607. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7608. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7609. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7610. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7611. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7612. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7613. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7614. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7615. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7616. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7617. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7618. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7619. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7620. function expandKey128(cipherKey) {
  7621. var b = 176, result = new Uint8Array(b);
  7622. result.set(cipherKey);
  7623. for (var j = 16, i = 1; j < b; ++i) {
  7624. // RotWord
  7625. var t1 = result[j - 3], t2 = result[j - 2],
  7626. t3 = result[j - 1], t4 = result[j - 4];
  7627. // SubWord
  7628. t1 = s[t1];
  7629. t2 = s[t2];
  7630. t3 = s[t3];
  7631. t4 = s[t4];
  7632. // Rcon
  7633. t1 = t1 ^ rcon[i];
  7634. for (var n = 0; n < 4; ++n) {
  7635. result[j] = (t1 ^= result[j - 16]);
  7636. j++;
  7637. result[j] = (t2 ^= result[j - 16]);
  7638. j++;
  7639. result[j] = (t3 ^= result[j - 16]);
  7640. j++;
  7641. result[j] = (t4 ^= result[j - 16]);
  7642. j++;
  7643. }
  7644. }
  7645. return result;
  7646. }
  7647. function decrypt128(input, key) {
  7648. var state = new Uint8Array(16);
  7649. state.set(input);
  7650. var i, j, k;
  7651. var t, u, v;
  7652. // AddRoundKey
  7653. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7654. state[j] ^= key[k];
  7655. }
  7656. for (i = 9; i >= 1; --i) {
  7657. // InvShiftRows
  7658. t = state[13];
  7659. state[13] = state[9];
  7660. state[9] = state[5];
  7661. state[5] = state[1];
  7662. state[1] = t;
  7663. t = state[14];
  7664. u = state[10];
  7665. state[14] = state[6];
  7666. state[10] = state[2];
  7667. state[6] = t;
  7668. state[2] = u;
  7669. t = state[15];
  7670. u = state[11];
  7671. v = state[7];
  7672. state[15] = state[3];
  7673. state[11] = t;
  7674. state[7] = u;
  7675. state[3] = v;
  7676. // InvSubBytes
  7677. for (j = 0; j < 16; ++j) {
  7678. state[j] = inv_s[state[j]];
  7679. }
  7680. // AddRoundKey
  7681. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7682. state[j] ^= key[k];
  7683. }
  7684. // InvMixColumns
  7685. for (j = 0; j < 16; j += 4) {
  7686. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7687. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7688. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7689. (s3 >>> 24) ^ (s3 << 8));
  7690. state[j] = (t >>> 24) & 0xFF;
  7691. state[j + 1] = (t >> 16) & 0xFF;
  7692. state[j + 2] = (t >> 8) & 0xFF;
  7693. state[j + 3] = t & 0xFF;
  7694. }
  7695. }
  7696. // InvShiftRows
  7697. t = state[13];
  7698. state[13] = state[9];
  7699. state[9] = state[5];
  7700. state[5] = state[1];
  7701. state[1] = t;
  7702. t = state[14];
  7703. u = state[10];
  7704. state[14] = state[6];
  7705. state[10] = state[2];
  7706. state[6] = t;
  7707. state[2] = u;
  7708. t = state[15];
  7709. u = state[11];
  7710. v = state[7];
  7711. state[15] = state[3];
  7712. state[11] = t;
  7713. state[7] = u;
  7714. state[3] = v;
  7715. for (j = 0; j < 16; ++j) {
  7716. // InvSubBytes
  7717. state[j] = inv_s[state[j]];
  7718. // AddRoundKey
  7719. state[j] ^= key[j];
  7720. }
  7721. return state;
  7722. }
  7723. function encrypt128(input, key) {
  7724. var t, u, v, k;
  7725. var state = new Uint8Array(16);
  7726. state.set(input);
  7727. for (j = 0; j < 16; ++j) {
  7728. // AddRoundKey
  7729. state[j] ^= key[j];
  7730. }
  7731. for (i = 1; i < 10; i++) {
  7732. //SubBytes
  7733. for (j = 0; j < 16; ++j) {
  7734. state[j] = s[state[j]];
  7735. }
  7736. //ShiftRows
  7737. v = state[1];
  7738. state[1] = state[5];
  7739. state[5] = state[9];
  7740. state[9] = state[13];
  7741. state[13] = v;
  7742. v = state[2];
  7743. u = state[6];
  7744. state[2] = state[10];
  7745. state[6] = state[14];
  7746. state[10] = v;
  7747. state[14] = u;
  7748. v = state[3];
  7749. u = state[7];
  7750. t = state[11];
  7751. state[3] = state[15];
  7752. state[7] = v;
  7753. state[11] = u;
  7754. state[15] = t;
  7755. //MixColumns
  7756. for (var j = 0; j < 16; j += 4) {
  7757. var s0 = state[j + 0], s1 = state[j + 1];
  7758. var s2 = state[j + 2], s3 = state[j + 3];
  7759. t = s0 ^ s1 ^ s2 ^ s3;
  7760. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7761. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7762. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7763. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7764. }
  7765. //AddRoundKey
  7766. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7767. state[j] ^= key[k];
  7768. }
  7769. }
  7770. //SubBytes
  7771. for (j = 0; j < 16; ++j) {
  7772. state[j] = s[state[j]];
  7773. }
  7774. //ShiftRows
  7775. v = state[1];
  7776. state[1] = state[5];
  7777. state[5] = state[9];
  7778. state[9] = state[13];
  7779. state[13] = v;
  7780. v = state[2];
  7781. u = state[6];
  7782. state[2] = state[10];
  7783. state[6] = state[14];
  7784. state[10] = v;
  7785. state[14] = u;
  7786. v = state[3];
  7787. u = state[7];
  7788. t = state[11];
  7789. state[3] = state[15];
  7790. state[7] = v;
  7791. state[11] = u;
  7792. state[15] = t;
  7793. //AddRoundKey
  7794. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7795. state[j] ^= key[k];
  7796. }
  7797. return state;
  7798. }
  7799. function AES128Cipher(key) {
  7800. this.key = expandKey128(key);
  7801. this.buffer = new Uint8Array(16);
  7802. this.bufferPosition = 0;
  7803. }
  7804. function decryptBlock2(data, finalize) {
  7805. var i, j, ii, sourceLength = data.length,
  7806. buffer = this.buffer, bufferLength = this.bufferPosition,
  7807. result = [], iv = this.iv;
  7808. for (i = 0; i < sourceLength; ++i) {
  7809. buffer[bufferLength] = data[i];
  7810. ++bufferLength;
  7811. if (bufferLength < 16) {
  7812. continue;
  7813. }
  7814. // buffer is full, decrypting
  7815. var plain = decrypt128(buffer, this.key);
  7816. // xor-ing the IV vector to get plain text
  7817. for (j = 0; j < 16; ++j) {
  7818. plain[j] ^= iv[j];
  7819. }
  7820. iv = buffer;
  7821. result.push(plain);
  7822. buffer = new Uint8Array(16);
  7823. bufferLength = 0;
  7824. }
  7825. // saving incomplete buffer
  7826. this.buffer = buffer;
  7827. this.bufferLength = bufferLength;
  7828. this.iv = iv;
  7829. if (result.length === 0) {
  7830. return new Uint8Array([]);
  7831. }
  7832. // combining plain text blocks into one
  7833. var outputLength = 16 * result.length;
  7834. if (finalize) {
  7835. // undo a padding that is described in RFC 2898
  7836. var lastBlock = result[result.length - 1];
  7837. var psLen = lastBlock[15];
  7838. if (psLen <= 16) {
  7839. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7840. if (lastBlock[i] !== psLen) {
  7841. // Invalid padding, assume that the block has no padding.
  7842. psLen = 0;
  7843. break;
  7844. }
  7845. }
  7846. outputLength -= psLen;
  7847. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7848. }
  7849. }
  7850. var output = new Uint8Array(outputLength);
  7851. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7852. output.set(result[i], j);
  7853. }
  7854. return output;
  7855. }
  7856. AES128Cipher.prototype = {
  7857. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7858. var i, sourceLength = data.length;
  7859. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7860. // waiting for IV values -- they are at the start of the stream
  7861. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7862. buffer[bufferLength] = data[i];
  7863. }
  7864. if (bufferLength < 16) {
  7865. // need more data
  7866. this.bufferLength = bufferLength;
  7867. return new Uint8Array([]);
  7868. }
  7869. this.iv = buffer;
  7870. this.buffer = new Uint8Array(16);
  7871. this.bufferLength = 0;
  7872. // starting decryption
  7873. this.decryptBlock = decryptBlock2;
  7874. return this.decryptBlock(data.subarray(16), finalize);
  7875. },
  7876. encrypt: function AES128Cipher_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 = encrypt128(buffer, this.key);
  7894. 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 AES128Cipher;
  7916. })();
  7917. var AES256Cipher = (function AES256CipherClosure() {
  7918. var rcon = new Uint8Array([
  7919. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7920. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7921. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7922. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7923. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7924. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7925. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7926. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7927. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7928. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7929. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7930. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7931. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7932. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7933. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7934. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7935. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7936. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7937. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7938. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7939. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7940. 0x74, 0xe8, 0xcb, 0x8d]);
  7941. var s = new Uint8Array([
  7942. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7943. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7944. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7945. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7946. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7947. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7948. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7949. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7950. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7951. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7952. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7953. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7954. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7955. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7956. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7957. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7958. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7959. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7960. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7961. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7962. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7963. 0xb0, 0x54, 0xbb, 0x16]);
  7964. var inv_s = new Uint8Array([
  7965. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7966. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7967. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7968. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7969. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7970. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7971. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7972. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7973. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7974. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7975. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7976. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7977. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7978. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7979. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7980. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7981. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7982. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7983. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7984. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7985. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7986. 0x55, 0x21, 0x0c, 0x7d]);
  7987. var mixCol = new Uint8Array(256);
  7988. for (var i = 0; i < 256; i++) {
  7989. if (i < 128) {
  7990. mixCol[i] = i << 1;
  7991. } else {
  7992. mixCol[i] = (i << 1) ^ 0x1b;
  7993. }
  7994. }
  7995. var mix = new Uint32Array([
  7996. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7997. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7998. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7999. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8000. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8001. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8002. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8003. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8004. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8005. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8006. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8007. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8008. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8009. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8010. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8011. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8012. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8013. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8014. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8015. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8016. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8017. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8018. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8019. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8020. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8021. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8022. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8023. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8024. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8025. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8026. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8027. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8028. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8029. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8030. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8031. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8032. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8033. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8034. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8035. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8036. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8037. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8038. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8039. function expandKey256(cipherKey) {
  8040. var b = 240, result = new Uint8Array(b);
  8041. var r = 1;
  8042. result.set(cipherKey);
  8043. for (var j = 32, i = 1; j < b; ++i) {
  8044. if (j % 32 === 16) {
  8045. t1 = s[t1];
  8046. t2 = s[t2];
  8047. t3 = s[t3];
  8048. t4 = s[t4];
  8049. } else if (j % 32 === 0) {
  8050. // RotWord
  8051. var t1 = result[j - 3], t2 = result[j - 2],
  8052. t3 = result[j - 1], t4 = result[j - 4];
  8053. // SubWord
  8054. t1 = s[t1];
  8055. t2 = s[t2];
  8056. t3 = s[t3];
  8057. t4 = s[t4];
  8058. // Rcon
  8059. t1 = t1 ^ r;
  8060. if ((r <<= 1) >= 256) {
  8061. r = (r ^ 0x1b) & 0xFF;
  8062. }
  8063. }
  8064. for (var n = 0; n < 4; ++n) {
  8065. result[j] = (t1 ^= result[j - 32]);
  8066. j++;
  8067. result[j] = (t2 ^= result[j - 32]);
  8068. j++;
  8069. result[j] = (t3 ^= result[j - 32]);
  8070. j++;
  8071. result[j] = (t4 ^= result[j - 32]);
  8072. j++;
  8073. }
  8074. }
  8075. return result;
  8076. }
  8077. function decrypt256(input, key) {
  8078. var state = new Uint8Array(16);
  8079. state.set(input);
  8080. var i, j, k;
  8081. var t, u, v;
  8082. // AddRoundKey
  8083. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8084. state[j] ^= key[k];
  8085. }
  8086. for (i = 13; i >= 1; --i) {
  8087. // InvShiftRows
  8088. t = state[13];
  8089. state[13] = state[9];
  8090. state[9] = state[5];
  8091. state[5] = state[1];
  8092. state[1] = t;
  8093. t = state[14];
  8094. u = state[10];
  8095. state[14] = state[6];
  8096. state[10] = state[2];
  8097. state[6] = t;
  8098. state[2] = u;
  8099. t = state[15];
  8100. u = state[11];
  8101. v = state[7];
  8102. state[15] = state[3];
  8103. state[11] = t;
  8104. state[7] = u;
  8105. state[3] = v;
  8106. // InvSubBytes
  8107. for (j = 0; j < 16; ++j) {
  8108. state[j] = inv_s[state[j]];
  8109. }
  8110. // AddRoundKey
  8111. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8112. state[j] ^= key[k];
  8113. }
  8114. // InvMixColumns
  8115. for (j = 0; j < 16; j += 4) {
  8116. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8117. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8118. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8119. (s3 >>> 24) ^ (s3 << 8));
  8120. state[j] = (t >>> 24) & 0xFF;
  8121. state[j + 1] = (t >> 16) & 0xFF;
  8122. state[j + 2] = (t >> 8) & 0xFF;
  8123. state[j + 3] = t & 0xFF;
  8124. }
  8125. }
  8126. // InvShiftRows
  8127. t = state[13];
  8128. state[13] = state[9];
  8129. state[9] = state[5];
  8130. state[5] = state[1];
  8131. state[1] = t;
  8132. t = state[14];
  8133. u = state[10];
  8134. state[14] = state[6];
  8135. state[10] = state[2];
  8136. state[6] = t;
  8137. state[2] = u;
  8138. t = state[15];
  8139. u = state[11];
  8140. v = state[7];
  8141. state[15] = state[3];
  8142. state[11] = t;
  8143. state[7] = u;
  8144. state[3] = v;
  8145. for (j = 0; j < 16; ++j) {
  8146. // InvSubBytes
  8147. state[j] = inv_s[state[j]];
  8148. // AddRoundKey
  8149. state[j] ^= key[j];
  8150. }
  8151. return state;
  8152. }
  8153. function encrypt256(input, key) {
  8154. var t, u, v, k;
  8155. var state = new Uint8Array(16);
  8156. state.set(input);
  8157. for (j = 0; j < 16; ++j) {
  8158. // AddRoundKey
  8159. state[j] ^= key[j];
  8160. }
  8161. for (i = 1; i < 14; i++) {
  8162. //SubBytes
  8163. for (j = 0; j < 16; ++j) {
  8164. state[j] = s[state[j]];
  8165. }
  8166. //ShiftRows
  8167. v = state[1];
  8168. state[1] = state[5];
  8169. state[5] = state[9];
  8170. state[9] = state[13];
  8171. state[13] = v;
  8172. v = state[2];
  8173. u = state[6];
  8174. state[2] = state[10];
  8175. state[6] = state[14];
  8176. state[10] = v;
  8177. state[14] = u;
  8178. v = state[3];
  8179. u = state[7];
  8180. t = state[11];
  8181. state[3] = state[15];
  8182. state[7] = v;
  8183. state[11] = u;
  8184. state[15] = t;
  8185. //MixColumns
  8186. for (var j = 0; j < 16; j += 4) {
  8187. var s0 = state[j + 0], s1 = state[j + 1];
  8188. var s2 = state[j + 2], s3 = state[j + 3];
  8189. t = s0 ^ s1 ^ s2 ^ s3;
  8190. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8191. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8192. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8193. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8194. }
  8195. //AddRoundKey
  8196. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8197. state[j] ^= key[k];
  8198. }
  8199. }
  8200. //SubBytes
  8201. for (j = 0; j < 16; ++j) {
  8202. state[j] = s[state[j]];
  8203. }
  8204. //ShiftRows
  8205. v = state[1];
  8206. state[1] = state[5];
  8207. state[5] = state[9];
  8208. state[9] = state[13];
  8209. state[13] = v;
  8210. v = state[2];
  8211. u = state[6];
  8212. state[2] = state[10];
  8213. state[6] = state[14];
  8214. state[10] = v;
  8215. state[14] = u;
  8216. v = state[3];
  8217. u = state[7];
  8218. t = state[11];
  8219. state[3] = state[15];
  8220. state[7] = v;
  8221. state[11] = u;
  8222. state[15] = t;
  8223. //AddRoundKey
  8224. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8225. state[j] ^= key[k];
  8226. }
  8227. return state;
  8228. }
  8229. function AES256Cipher(key) {
  8230. this.key = expandKey256(key);
  8231. this.buffer = new Uint8Array(16);
  8232. this.bufferPosition = 0;
  8233. }
  8234. function decryptBlock2(data, finalize) {
  8235. var i, j, ii, sourceLength = data.length,
  8236. buffer = this.buffer, bufferLength = this.bufferPosition,
  8237. result = [], iv = this.iv;
  8238. for (i = 0; i < sourceLength; ++i) {
  8239. buffer[bufferLength] = data[i];
  8240. ++bufferLength;
  8241. if (bufferLength < 16) {
  8242. continue;
  8243. }
  8244. // buffer is full, decrypting
  8245. var plain = decrypt256(buffer, this.key);
  8246. // xor-ing the IV vector to get plain text
  8247. for (j = 0; j < 16; ++j) {
  8248. plain[j] ^= iv[j];
  8249. }
  8250. iv = buffer;
  8251. result.push(plain);
  8252. buffer = new Uint8Array(16);
  8253. bufferLength = 0;
  8254. }
  8255. // saving incomplete buffer
  8256. this.buffer = buffer;
  8257. this.bufferLength = bufferLength;
  8258. this.iv = iv;
  8259. if (result.length === 0) {
  8260. return new Uint8Array([]);
  8261. }
  8262. // combining plain text blocks into one
  8263. var outputLength = 16 * result.length;
  8264. if (finalize) {
  8265. // undo a padding that is described in RFC 2898
  8266. var lastBlock = result[result.length - 1];
  8267. var psLen = lastBlock[15];
  8268. if (psLen <= 16) {
  8269. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8270. if (lastBlock[i] !== psLen) {
  8271. // Invalid padding, assume that the block has no padding.
  8272. psLen = 0;
  8273. break;
  8274. }
  8275. }
  8276. outputLength -= psLen;
  8277. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8278. }
  8279. }
  8280. var output = new Uint8Array(outputLength);
  8281. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8282. output.set(result[i], j);
  8283. }
  8284. return output;
  8285. }
  8286. AES256Cipher.prototype = {
  8287. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8288. var i, sourceLength = data.length;
  8289. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8290. // if not supplied an IV wait for IV values
  8291. // they are at the start of the stream
  8292. if (iv) {
  8293. this.iv = iv;
  8294. } else {
  8295. for (i = 0; bufferLength < 16 &&
  8296. i < sourceLength; ++i, ++bufferLength) {
  8297. buffer[bufferLength] = data[i];
  8298. }
  8299. if (bufferLength < 16) {
  8300. //need more data
  8301. this.bufferLength = bufferLength;
  8302. return new Uint8Array([]);
  8303. }
  8304. this.iv = buffer;
  8305. data = data.subarray(16);
  8306. }
  8307. this.buffer = new Uint8Array(16);
  8308. this.bufferLength = 0;
  8309. // starting decryption
  8310. this.decryptBlock = decryptBlock2;
  8311. return this.decryptBlock(data, finalize);
  8312. },
  8313. encrypt: function AES256Cipher_encrypt(data, iv) {
  8314. var i, j, ii, sourceLength = data.length,
  8315. buffer = this.buffer, bufferLength = this.bufferPosition,
  8316. result = [];
  8317. if (!iv) {
  8318. iv = new Uint8Array(16);
  8319. }
  8320. for (i = 0; i < sourceLength; ++i) {
  8321. buffer[bufferLength] = data[i];
  8322. ++bufferLength;
  8323. if (bufferLength < 16) {
  8324. continue;
  8325. }
  8326. for (j = 0; j < 16; ++j) {
  8327. buffer[j] ^= iv[j];
  8328. }
  8329. // buffer is full, encrypting
  8330. var cipher = encrypt256(buffer, this.key);
  8331. this.iv = cipher;
  8332. result.push(cipher);
  8333. buffer = new Uint8Array(16);
  8334. bufferLength = 0;
  8335. }
  8336. // saving incomplete buffer
  8337. this.buffer = buffer;
  8338. this.bufferLength = bufferLength;
  8339. this.iv = iv;
  8340. if (result.length === 0) {
  8341. return new Uint8Array([]);
  8342. }
  8343. // combining plain text blocks into one
  8344. var outputLength = 16 * result.length;
  8345. var output = new Uint8Array(outputLength);
  8346. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8347. output.set(result[i], j);
  8348. }
  8349. return output;
  8350. }
  8351. };
  8352. return AES256Cipher;
  8353. })();
  8354. var PDF17 = (function PDF17Closure() {
  8355. function compareByteArrays(array1, array2) {
  8356. if (array1.length !== array2.length) {
  8357. return false;
  8358. }
  8359. for (var i = 0; i < array1.length; i++) {
  8360. if (array1[i] !== array2[i]) {
  8361. return false;
  8362. }
  8363. }
  8364. return true;
  8365. }
  8366. function PDF17() {
  8367. }
  8368. PDF17.prototype = {
  8369. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8370. ownerValidationSalt,
  8371. userBytes,
  8372. ownerPassword) {
  8373. var hashData = new Uint8Array(password.length + 56);
  8374. hashData.set(password, 0);
  8375. hashData.set(ownerValidationSalt, password.length);
  8376. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8377. var result = calculateSHA256(hashData, 0, hashData.length);
  8378. return compareByteArrays(result, ownerPassword);
  8379. },
  8380. checkUserPassword: function PDF17_checkUserPassword(password,
  8381. userValidationSalt,
  8382. userPassword) {
  8383. var hashData = new Uint8Array(password.length + 8);
  8384. hashData.set(password, 0);
  8385. hashData.set(userValidationSalt, password.length);
  8386. var result = calculateSHA256(hashData, 0, hashData.length);
  8387. return compareByteArrays(result, userPassword);
  8388. },
  8389. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8390. ownerEncryption) {
  8391. var hashData = new Uint8Array(password.length + 56);
  8392. hashData.set(password, 0);
  8393. hashData.set(ownerKeySalt, password.length);
  8394. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8395. var key = calculateSHA256(hashData, 0, hashData.length);
  8396. var cipher = new AES256Cipher(key);
  8397. return cipher.decryptBlock(ownerEncryption,
  8398. false,
  8399. new Uint8Array(16));
  8400. },
  8401. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8402. userEncryption) {
  8403. var hashData = new Uint8Array(password.length + 8);
  8404. hashData.set(password, 0);
  8405. hashData.set(userKeySalt, password.length);
  8406. //key is the decryption key for the UE string
  8407. var key = calculateSHA256(hashData, 0, hashData.length);
  8408. var cipher = new AES256Cipher(key);
  8409. return cipher.decryptBlock(userEncryption,
  8410. false,
  8411. new Uint8Array(16));
  8412. }
  8413. };
  8414. return PDF17;
  8415. })();
  8416. var PDF20 = (function PDF20Closure() {
  8417. function concatArrays(array1, array2) {
  8418. var t = new Uint8Array(array1.length + array2.length);
  8419. t.set(array1, 0);
  8420. t.set(array2, array1.length);
  8421. return t;
  8422. }
  8423. function calculatePDF20Hash(password, input, userBytes) {
  8424. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8425. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8426. var e = [0];
  8427. var i = 0;
  8428. while (i < 64 || e[e.length - 1] > i - 32) {
  8429. var arrayLength = password.length + k.length + userBytes.length;
  8430. var k1 = new Uint8Array(arrayLength * 64);
  8431. var array = concatArrays(password, k);
  8432. array = concatArrays(array, userBytes);
  8433. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8434. k1.set(array, pos);
  8435. }
  8436. //AES128 CBC NO PADDING with
  8437. //first 16 bytes of k as the key and the second 16 as the iv.
  8438. var cipher = new AES128Cipher(k.subarray(0, 16));
  8439. e = cipher.encrypt(k1, k.subarray(16, 32));
  8440. //Now we have to take the first 16 bytes of an unsigned
  8441. //big endian integer... and compute the remainder
  8442. //modulo 3.... That is a fairly large number and
  8443. //JavaScript isn't going to handle that well...
  8444. //So we're using a trick that allows us to perform
  8445. //modulo math byte by byte
  8446. var remainder = 0;
  8447. for (var z = 0; z < 16; z++) {
  8448. remainder *= (256 % 3);
  8449. remainder %= 3;
  8450. remainder += ((e[z] >>> 0) % 3);
  8451. remainder %= 3;
  8452. }
  8453. if (remainder === 0) {
  8454. k = calculateSHA256(e, 0, e.length);
  8455. }
  8456. else if (remainder === 1) {
  8457. k = calculateSHA384(e, 0, e.length);
  8458. }
  8459. else if (remainder === 2) {
  8460. k = calculateSHA512(e, 0, e.length);
  8461. }
  8462. i++;
  8463. }
  8464. return k.subarray(0, 32);
  8465. }
  8466. function PDF20() {
  8467. }
  8468. function compareByteArrays(array1, array2) {
  8469. if (array1.length !== array2.length) {
  8470. return false;
  8471. }
  8472. for (var i = 0; i < array1.length; i++) {
  8473. if (array1[i] !== array2[i]) {
  8474. return false;
  8475. }
  8476. }
  8477. return true;
  8478. }
  8479. PDF20.prototype = {
  8480. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8481. return calculatePDF20Hash(password, concatBytes, userBytes);
  8482. },
  8483. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8484. ownerValidationSalt,
  8485. userBytes,
  8486. ownerPassword) {
  8487. var hashData = new Uint8Array(password.length + 56);
  8488. hashData.set(password, 0);
  8489. hashData.set(ownerValidationSalt, password.length);
  8490. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8491. var result = calculatePDF20Hash(password, hashData, userBytes);
  8492. return compareByteArrays(result, ownerPassword);
  8493. },
  8494. checkUserPassword: function PDF20_checkUserPassword(password,
  8495. userValidationSalt,
  8496. userPassword) {
  8497. var hashData = new Uint8Array(password.length + 8);
  8498. hashData.set(password, 0);
  8499. hashData.set(userValidationSalt, password.length);
  8500. var result = calculatePDF20Hash(password, hashData, []);
  8501. return compareByteArrays(result, userPassword);
  8502. },
  8503. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8504. ownerEncryption) {
  8505. var hashData = new Uint8Array(password.length + 56);
  8506. hashData.set(password, 0);
  8507. hashData.set(ownerKeySalt, password.length);
  8508. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8509. var key = calculatePDF20Hash(password, hashData, userBytes);
  8510. var cipher = new AES256Cipher(key);
  8511. return cipher.decryptBlock(ownerEncryption,
  8512. false,
  8513. new Uint8Array(16));
  8514. },
  8515. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8516. userEncryption) {
  8517. var hashData = new Uint8Array(password.length + 8);
  8518. hashData.set(password, 0);
  8519. hashData.set(userKeySalt, password.length);
  8520. //key is the decryption key for the UE string
  8521. var key = calculatePDF20Hash(password, hashData, []);
  8522. var cipher = new AES256Cipher(key);
  8523. return cipher.decryptBlock(userEncryption,
  8524. false,
  8525. new Uint8Array(16));
  8526. }
  8527. };
  8528. return PDF20;
  8529. })();
  8530. var CipherTransform = (function CipherTransformClosure() {
  8531. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8532. this.stringCipherConstructor = stringCipherConstructor;
  8533. this.streamCipherConstructor = streamCipherConstructor;
  8534. }
  8535. CipherTransform.prototype = {
  8536. createStream: function CipherTransform_createStream(stream, length) {
  8537. var cipher = new this.streamCipherConstructor();
  8538. return new DecryptStream(stream, length,
  8539. function cipherTransformDecryptStream(data, finalize) {
  8540. return cipher.decryptBlock(data, finalize);
  8541. }
  8542. );
  8543. },
  8544. decryptString: function CipherTransform_decryptString(s) {
  8545. var cipher = new this.stringCipherConstructor();
  8546. var data = stringToBytes(s);
  8547. data = cipher.decryptBlock(data, true);
  8548. return bytesToString(data);
  8549. }
  8550. };
  8551. return CipherTransform;
  8552. })();
  8553. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8554. var defaultPasswordBytes = new Uint8Array([
  8555. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8556. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8557. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8558. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8559. function createEncryptionKey20(revision, password, ownerPassword,
  8560. ownerValidationSalt, ownerKeySalt, uBytes,
  8561. userPassword, userValidationSalt, userKeySalt,
  8562. ownerEncryption, userEncryption, perms) {
  8563. if (password) {
  8564. var passwordLength = Math.min(127, password.length);
  8565. password = password.subarray(0, passwordLength);
  8566. } else {
  8567. password = [];
  8568. }
  8569. var pdfAlgorithm;
  8570. if (revision === 6) {
  8571. pdfAlgorithm = new PDF20();
  8572. } else {
  8573. pdfAlgorithm = new PDF17();
  8574. }
  8575. if (pdfAlgorithm) {
  8576. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8577. userPassword)) {
  8578. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8579. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8580. uBytes,
  8581. ownerPassword)) {
  8582. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8583. ownerEncryption);
  8584. }
  8585. }
  8586. return null;
  8587. }
  8588. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8589. flags, revision, keyLength, encryptMetadata) {
  8590. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8591. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8592. if (password) {
  8593. n = Math.min(32, password.length);
  8594. for (; i < n; ++i) {
  8595. hashData[i] = password[i];
  8596. }
  8597. }
  8598. j = 0;
  8599. while (i < 32) {
  8600. hashData[i++] = defaultPasswordBytes[j++];
  8601. }
  8602. // as now the padded password in the hashData[0..i]
  8603. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8604. hashData[i++] = ownerPassword[j];
  8605. }
  8606. hashData[i++] = flags & 0xFF;
  8607. hashData[i++] = (flags >> 8) & 0xFF;
  8608. hashData[i++] = (flags >> 16) & 0xFF;
  8609. hashData[i++] = (flags >>> 24) & 0xFF;
  8610. for (j = 0, n = fileId.length; j < n; ++j) {
  8611. hashData[i++] = fileId[j];
  8612. }
  8613. if (revision >= 4 && !encryptMetadata) {
  8614. hashData[i++] = 0xFF;
  8615. hashData[i++] = 0xFF;
  8616. hashData[i++] = 0xFF;
  8617. hashData[i++] = 0xFF;
  8618. }
  8619. var hash = calculateMD5(hashData, 0, i);
  8620. var keyLengthInBytes = keyLength >> 3;
  8621. if (revision >= 3) {
  8622. for (j = 0; j < 50; ++j) {
  8623. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8624. }
  8625. }
  8626. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8627. var cipher, checkData;
  8628. if (revision >= 3) {
  8629. for (i = 0; i < 32; ++i) {
  8630. hashData[i] = defaultPasswordBytes[i];
  8631. }
  8632. for (j = 0, n = fileId.length; j < n; ++j) {
  8633. hashData[i++] = fileId[j];
  8634. }
  8635. cipher = new ARCFourCipher(encryptionKey);
  8636. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8637. n = encryptionKey.length;
  8638. var derivedKey = new Uint8Array(n), k;
  8639. for (j = 1; j <= 19; ++j) {
  8640. for (k = 0; k < n; ++k) {
  8641. derivedKey[k] = encryptionKey[k] ^ j;
  8642. }
  8643. cipher = new ARCFourCipher(derivedKey);
  8644. checkData = cipher.encryptBlock(checkData);
  8645. }
  8646. for (j = 0, n = checkData.length; j < n; ++j) {
  8647. if (userPassword[j] !== checkData[j]) {
  8648. return null;
  8649. }
  8650. }
  8651. } else {
  8652. cipher = new ARCFourCipher(encryptionKey);
  8653. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8654. for (j = 0, n = checkData.length; j < n; ++j) {
  8655. if (userPassword[j] !== checkData[j]) {
  8656. return null;
  8657. }
  8658. }
  8659. }
  8660. return encryptionKey;
  8661. }
  8662. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8663. var hashData = new Uint8Array(32), i = 0, j, n;
  8664. n = Math.min(32, password.length);
  8665. for (; i < n; ++i) {
  8666. hashData[i] = password[i];
  8667. }
  8668. j = 0;
  8669. while (i < 32) {
  8670. hashData[i++] = defaultPasswordBytes[j++];
  8671. }
  8672. var hash = calculateMD5(hashData, 0, i);
  8673. var keyLengthInBytes = keyLength >> 3;
  8674. if (revision >= 3) {
  8675. for (j = 0; j < 50; ++j) {
  8676. hash = calculateMD5(hash, 0, hash.length);
  8677. }
  8678. }
  8679. var cipher, userPassword;
  8680. if (revision >= 3) {
  8681. userPassword = ownerPassword;
  8682. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8683. for (j = 19; j >= 0; j--) {
  8684. for (k = 0; k < keyLengthInBytes; ++k) {
  8685. derivedKey[k] = hash[k] ^ j;
  8686. }
  8687. cipher = new ARCFourCipher(derivedKey);
  8688. userPassword = cipher.encryptBlock(userPassword);
  8689. }
  8690. } else {
  8691. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8692. userPassword = cipher.encryptBlock(ownerPassword);
  8693. }
  8694. return userPassword;
  8695. }
  8696. var identityName = Name.get('Identity');
  8697. function CipherTransformFactory(dict, fileId, password) {
  8698. var filter = dict.get('Filter');
  8699. if (!isName(filter) || filter.name !== 'Standard') {
  8700. error('unknown encryption method');
  8701. }
  8702. this.dict = dict;
  8703. var algorithm = dict.get('V');
  8704. if (!isInt(algorithm) ||
  8705. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8706. algorithm !== 5)) {
  8707. error('unsupported encryption algorithm');
  8708. }
  8709. this.algorithm = algorithm;
  8710. var keyLength = dict.get('Length') || 40;
  8711. if (!isInt(keyLength) ||
  8712. keyLength < 40 || (keyLength % 8) !== 0) {
  8713. error('invalid key length');
  8714. }
  8715. // prepare keys
  8716. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8717. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8718. var flags = dict.get('P');
  8719. var revision = dict.get('R');
  8720. // meaningful when V is 4 or 5
  8721. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8722. dict.get('EncryptMetadata') !== false);
  8723. this.encryptMetadata = encryptMetadata;
  8724. var fileIdBytes = stringToBytes(fileId);
  8725. var passwordBytes;
  8726. if (password) {
  8727. passwordBytes = stringToBytes(password);
  8728. }
  8729. var encryptionKey;
  8730. if (algorithm !== 5) {
  8731. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8732. ownerPassword, userPassword, flags,
  8733. revision, keyLength, encryptMetadata);
  8734. }
  8735. else {
  8736. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8737. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8738. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8739. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8740. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8741. var ownerEncryption = stringToBytes(dict.get('OE'));
  8742. var userEncryption = stringToBytes(dict.get('UE'));
  8743. var perms = stringToBytes(dict.get('Perms'));
  8744. encryptionKey =
  8745. createEncryptionKey20(revision, passwordBytes,
  8746. ownerPassword, ownerValidationSalt,
  8747. ownerKeySalt, uBytes,
  8748. userPassword, userValidationSalt,
  8749. userKeySalt, ownerEncryption,
  8750. userEncryption, perms);
  8751. }
  8752. if (!encryptionKey && !password) {
  8753. throw new PasswordException('No password given',
  8754. PasswordResponses.NEED_PASSWORD);
  8755. } else if (!encryptionKey && password) {
  8756. // Attempting use the password as an owner password
  8757. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8758. revision, keyLength);
  8759. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8760. ownerPassword, userPassword, flags,
  8761. revision, keyLength, encryptMetadata);
  8762. }
  8763. if (!encryptionKey) {
  8764. throw new PasswordException('Incorrect Password',
  8765. PasswordResponses.INCORRECT_PASSWORD);
  8766. }
  8767. this.encryptionKey = encryptionKey;
  8768. if (algorithm >= 4) {
  8769. this.cf = dict.get('CF');
  8770. this.stmf = dict.get('StmF') || identityName;
  8771. this.strf = dict.get('StrF') || identityName;
  8772. this.eff = dict.get('EFF') || this.strf;
  8773. }
  8774. }
  8775. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8776. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8777. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8778. key[i] = encryptionKey[i];
  8779. }
  8780. key[i++] = num & 0xFF;
  8781. key[i++] = (num >> 8) & 0xFF;
  8782. key[i++] = (num >> 16) & 0xFF;
  8783. key[i++] = gen & 0xFF;
  8784. key[i++] = (gen >> 8) & 0xFF;
  8785. if (isAes) {
  8786. key[i++] = 0x73;
  8787. key[i++] = 0x41;
  8788. key[i++] = 0x6C;
  8789. key[i++] = 0x54;
  8790. }
  8791. var hash = calculateMD5(key, 0, i);
  8792. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8793. }
  8794. function buildCipherConstructor(cf, name, num, gen, key) {
  8795. var cryptFilter = cf.get(name.name);
  8796. var cfm;
  8797. if (cryptFilter !== null && cryptFilter !== undefined) {
  8798. cfm = cryptFilter.get('CFM');
  8799. }
  8800. if (!cfm || cfm.name === 'None') {
  8801. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8802. return new NullCipher();
  8803. };
  8804. }
  8805. if ('V2' === cfm.name) {
  8806. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8807. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8808. };
  8809. }
  8810. if ('AESV2' === cfm.name) {
  8811. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8812. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8813. };
  8814. }
  8815. if ('AESV3' === cfm.name) {
  8816. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8817. return new AES256Cipher(key);
  8818. };
  8819. }
  8820. error('Unknown crypto method');
  8821. }
  8822. CipherTransformFactory.prototype = {
  8823. createCipherTransform:
  8824. function CipherTransformFactory_createCipherTransform(num, gen) {
  8825. if (this.algorithm === 4 || this.algorithm === 5) {
  8826. return new CipherTransform(
  8827. buildCipherConstructor(this.cf, this.stmf,
  8828. num, gen, this.encryptionKey),
  8829. buildCipherConstructor(this.cf, this.strf,
  8830. num, gen, this.encryptionKey));
  8831. }
  8832. // algorithms 1 and 2
  8833. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8834. var cipherConstructor = function buildCipherCipherConstructor() {
  8835. return new ARCFourCipher(key);
  8836. };
  8837. return new CipherTransform(cipherConstructor, cipherConstructor);
  8838. }
  8839. };
  8840. return CipherTransformFactory;
  8841. })();
  8842. var PatternType = {
  8843. FUNCTION_BASED: 1,
  8844. AXIAL: 2,
  8845. RADIAL: 3,
  8846. FREE_FORM_MESH: 4,
  8847. LATTICE_FORM_MESH: 5,
  8848. COONS_PATCH_MESH: 6,
  8849. TENSOR_PATCH_MESH: 7
  8850. };
  8851. var Pattern = (function PatternClosure() {
  8852. // Constructor should define this.getPattern
  8853. function Pattern() {
  8854. error('should not call Pattern constructor');
  8855. }
  8856. Pattern.prototype = {
  8857. // Input: current Canvas context
  8858. // Output: the appropriate fillStyle or strokeStyle
  8859. getPattern: function Pattern_getPattern(ctx) {
  8860. error('Should not call Pattern.getStyle: ' + ctx);
  8861. }
  8862. };
  8863. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8864. res) {
  8865. var dict = isStream(shading) ? shading.dict : shading;
  8866. var type = dict.get('ShadingType');
  8867. try {
  8868. switch (type) {
  8869. case PatternType.AXIAL:
  8870. case PatternType.RADIAL:
  8871. // Both radial and axial shadings are handled by RadialAxial shading.
  8872. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8873. case PatternType.FREE_FORM_MESH:
  8874. case PatternType.LATTICE_FORM_MESH:
  8875. case PatternType.COONS_PATCH_MESH:
  8876. case PatternType.TENSOR_PATCH_MESH:
  8877. return new Shadings.Mesh(shading, matrix, xref, res);
  8878. default:
  8879. throw new Error('Unknown PatternType: ' + type);
  8880. }
  8881. } catch (ex) {
  8882. if (ex instanceof MissingDataException) {
  8883. throw ex;
  8884. }
  8885. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8886. warn(ex);
  8887. return new Shadings.Dummy();
  8888. }
  8889. };
  8890. return Pattern;
  8891. })();
  8892. var Shadings = {};
  8893. // A small number to offset the first/last color stops so we can insert ones to
  8894. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8895. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8896. // internally so we have to go bigger.
  8897. Shadings.SMALL_NUMBER = 1e-2;
  8898. // Radial and axial shading have very similar implementations
  8899. // If needed, the implementations can be broken into two classes
  8900. Shadings.RadialAxial = (function RadialAxialClosure() {
  8901. function RadialAxial(dict, matrix, xref, res) {
  8902. this.matrix = matrix;
  8903. this.coordsArr = dict.get('Coords');
  8904. this.shadingType = dict.get('ShadingType');
  8905. this.type = 'Pattern';
  8906. var cs = dict.get('ColorSpace', 'CS');
  8907. cs = ColorSpace.parse(cs, xref, res);
  8908. this.cs = cs;
  8909. var t0 = 0.0, t1 = 1.0;
  8910. if (dict.has('Domain')) {
  8911. var domainArr = dict.get('Domain');
  8912. t0 = domainArr[0];
  8913. t1 = domainArr[1];
  8914. }
  8915. var extendStart = false, extendEnd = false;
  8916. if (dict.has('Extend')) {
  8917. var extendArr = dict.get('Extend');
  8918. extendStart = extendArr[0];
  8919. extendEnd = extendArr[1];
  8920. }
  8921. if (this.shadingType === PatternType.RADIAL &&
  8922. (!extendStart || !extendEnd)) {
  8923. // Radial gradient only currently works if either circle is fully within
  8924. // the other circle.
  8925. var x1 = this.coordsArr[0];
  8926. var y1 = this.coordsArr[1];
  8927. var r1 = this.coordsArr[2];
  8928. var x2 = this.coordsArr[3];
  8929. var y2 = this.coordsArr[4];
  8930. var r2 = this.coordsArr[5];
  8931. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8932. if (r1 <= r2 + distance &&
  8933. r2 <= r1 + distance) {
  8934. warn('Unsupported radial gradient.');
  8935. }
  8936. }
  8937. this.extendStart = extendStart;
  8938. this.extendEnd = extendEnd;
  8939. var fnObj = dict.get('Function');
  8940. var fn = PDFFunction.parseArray(xref, fnObj);
  8941. // 10 samples seems good enough for now, but probably won't work
  8942. // if there are sharp color changes. Ideally, we would implement
  8943. // the spec faithfully and add lossless optimizations.
  8944. var diff = t1 - t0;
  8945. var step = diff / 10;
  8946. var colorStops = this.colorStops = [];
  8947. // Protect against bad domains so we don't end up in an infinte loop below.
  8948. if (t0 >= t1 || step <= 0) {
  8949. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8950. // now.
  8951. info('Bad shading domain.');
  8952. return;
  8953. }
  8954. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8955. var rgbColor;
  8956. for (var i = t0; i <= t1; i += step) {
  8957. ratio[0] = i;
  8958. fn(ratio, 0, color, 0);
  8959. rgbColor = cs.getRgb(color, 0);
  8960. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8961. colorStops.push([(i - t0) / diff, cssColor]);
  8962. }
  8963. var background = 'transparent';
  8964. if (dict.has('Background')) {
  8965. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8966. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8967. }
  8968. if (!extendStart) {
  8969. // Insert a color stop at the front and offset the first real color stop
  8970. // so it doesn't conflict with the one we insert.
  8971. colorStops.unshift([0, background]);
  8972. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8973. }
  8974. if (!extendEnd) {
  8975. // Same idea as above in extendStart but for the end.
  8976. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8977. colorStops.push([1, background]);
  8978. }
  8979. this.colorStops = colorStops;
  8980. }
  8981. RadialAxial.prototype = {
  8982. getIR: function RadialAxial_getIR() {
  8983. var coordsArr = this.coordsArr;
  8984. var shadingType = this.shadingType;
  8985. var type, p0, p1, r0, r1;
  8986. if (shadingType === PatternType.AXIAL) {
  8987. p0 = [coordsArr[0], coordsArr[1]];
  8988. p1 = [coordsArr[2], coordsArr[3]];
  8989. r0 = null;
  8990. r1 = null;
  8991. type = 'axial';
  8992. } else if (shadingType === PatternType.RADIAL) {
  8993. p0 = [coordsArr[0], coordsArr[1]];
  8994. p1 = [coordsArr[3], coordsArr[4]];
  8995. r0 = coordsArr[2];
  8996. r1 = coordsArr[5];
  8997. type = 'radial';
  8998. } else {
  8999. error('getPattern type unknown: ' + shadingType);
  9000. }
  9001. var matrix = this.matrix;
  9002. if (matrix) {
  9003. p0 = Util.applyTransform(p0, matrix);
  9004. p1 = Util.applyTransform(p1, matrix);
  9005. }
  9006. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9007. }
  9008. };
  9009. return RadialAxial;
  9010. })();
  9011. // All mesh shading. For now, they will be presented as set of the triangles
  9012. // to be drawn on the canvas and rgb color for each vertex.
  9013. Shadings.Mesh = (function MeshClosure() {
  9014. function MeshStreamReader(stream, context) {
  9015. this.stream = stream;
  9016. this.context = context;
  9017. this.buffer = 0;
  9018. this.bufferLength = 0;
  9019. var numComps = context.numComps;
  9020. this.tmpCompsBuf = new Float32Array(numComps);
  9021. var csNumComps = context.colorSpace;
  9022. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9023. this.tmpCompsBuf;
  9024. }
  9025. MeshStreamReader.prototype = {
  9026. get hasData() {
  9027. if (this.stream.end) {
  9028. return this.stream.pos < this.stream.end;
  9029. }
  9030. if (this.bufferLength > 0) {
  9031. return true;
  9032. }
  9033. var nextByte = this.stream.getByte();
  9034. if (nextByte < 0) {
  9035. return false;
  9036. }
  9037. this.buffer = nextByte;
  9038. this.bufferLength = 8;
  9039. return true;
  9040. },
  9041. readBits: function MeshStreamReader_readBits(n) {
  9042. var buffer = this.buffer;
  9043. var bufferLength = this.bufferLength;
  9044. if (n === 32) {
  9045. if (bufferLength === 0) {
  9046. return ((this.stream.getByte() << 24) |
  9047. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9048. this.stream.getByte()) >>> 0;
  9049. }
  9050. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9051. (this.stream.getByte() << 8) | this.stream.getByte();
  9052. var nextByte = this.stream.getByte();
  9053. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9054. return ((buffer << (8 - bufferLength)) |
  9055. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9056. }
  9057. if (n === 8 && bufferLength === 0) {
  9058. return this.stream.getByte();
  9059. }
  9060. while (bufferLength < n) {
  9061. buffer = (buffer << 8) | this.stream.getByte();
  9062. bufferLength += 8;
  9063. }
  9064. bufferLength -= n;
  9065. this.bufferLength = bufferLength;
  9066. this.buffer = buffer & ((1 << bufferLength) - 1);
  9067. return buffer >> bufferLength;
  9068. },
  9069. align: function MeshStreamReader_align() {
  9070. this.buffer = 0;
  9071. this.bufferLength = 0;
  9072. },
  9073. readFlag: function MeshStreamReader_readFlag() {
  9074. return this.readBits(this.context.bitsPerFlag);
  9075. },
  9076. readCoordinate: function MeshStreamReader_readCoordinate() {
  9077. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9078. var xi = this.readBits(bitsPerCoordinate);
  9079. var yi = this.readBits(bitsPerCoordinate);
  9080. var decode = this.context.decode;
  9081. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9082. 2.3283064365386963e-10; // 2 ^ -32
  9083. return [
  9084. xi * scale * (decode[1] - decode[0]) + decode[0],
  9085. yi * scale * (decode[3] - decode[2]) + decode[2]
  9086. ];
  9087. },
  9088. readComponents: function MeshStreamReader_readComponents() {
  9089. var numComps = this.context.numComps;
  9090. var bitsPerComponent = this.context.bitsPerComponent;
  9091. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9092. 2.3283064365386963e-10; // 2 ^ -32
  9093. var decode = this.context.decode;
  9094. var components = this.tmpCompsBuf;
  9095. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9096. var ci = this.readBits(bitsPerComponent);
  9097. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9098. }
  9099. var color = this.tmpCsCompsBuf;
  9100. if (this.context.colorFn) {
  9101. this.context.colorFn(components, 0, color, 0);
  9102. }
  9103. return this.context.colorSpace.getRgb(color, 0);
  9104. }
  9105. };
  9106. function decodeType4Shading(mesh, reader) {
  9107. var coords = mesh.coords;
  9108. var colors = mesh.colors;
  9109. var operators = [];
  9110. var ps = []; // not maintaining cs since that will match ps
  9111. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9112. while (reader.hasData) {
  9113. var f = reader.readFlag();
  9114. var coord = reader.readCoordinate();
  9115. var color = reader.readComponents();
  9116. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9117. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9118. switch (f) {
  9119. case 0:
  9120. verticesLeft = 3;
  9121. break;
  9122. case 1:
  9123. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9124. verticesLeft = 1;
  9125. break;
  9126. case 2:
  9127. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9128. verticesLeft = 1;
  9129. break;
  9130. }
  9131. operators.push(f);
  9132. }
  9133. ps.push(coords.length);
  9134. coords.push(coord);
  9135. colors.push(color);
  9136. verticesLeft--;
  9137. reader.align();
  9138. }
  9139. var psPacked = new Int32Array(ps);
  9140. mesh.figures.push({
  9141. type: 'triangles',
  9142. coords: psPacked,
  9143. colors: psPacked
  9144. });
  9145. }
  9146. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9147. var coords = mesh.coords;
  9148. var colors = mesh.colors;
  9149. var ps = []; // not maintaining cs since that will match ps
  9150. while (reader.hasData) {
  9151. var coord = reader.readCoordinate();
  9152. var color = reader.readComponents();
  9153. ps.push(coords.length);
  9154. coords.push(coord);
  9155. colors.push(color);
  9156. }
  9157. var psPacked = new Int32Array(ps);
  9158. mesh.figures.push({
  9159. type: 'lattice',
  9160. coords: psPacked,
  9161. colors: psPacked,
  9162. verticesPerRow: verticesPerRow
  9163. });
  9164. }
  9165. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9166. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9167. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9168. var getB = (function getBClosure() {
  9169. function buildB(count) {
  9170. var lut = [];
  9171. for (var i = 0; i <= count; i++) {
  9172. var t = i / count, t_ = 1 - t;
  9173. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9174. 3 * t * t * t_, t * t * t]));
  9175. }
  9176. return lut;
  9177. }
  9178. var cache = [];
  9179. return function getB(count) {
  9180. if (!cache[count]) {
  9181. cache[count] = buildB(count);
  9182. }
  9183. return cache[count];
  9184. };
  9185. })();
  9186. function buildFigureFromPatch(mesh, index) {
  9187. var figure = mesh.figures[index];
  9188. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9189. var coords = mesh.coords, colors = mesh.colors;
  9190. var pi = figure.coords;
  9191. var ci = figure.colors;
  9192. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9193. coords[pi[12]][0], coords[pi[15]][0]);
  9194. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9195. coords[pi[12]][1], coords[pi[15]][1]);
  9196. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9197. coords[pi[12]][0], coords[pi[15]][0]);
  9198. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9199. coords[pi[12]][1], coords[pi[15]][1]);
  9200. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9201. (mesh.bounds[2] - mesh.bounds[0]));
  9202. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9203. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9204. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9205. (mesh.bounds[3] - mesh.bounds[1]));
  9206. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9207. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9208. var verticesPerRow = splitXBy + 1;
  9209. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9210. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9211. var k = 0;
  9212. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9213. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9214. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9215. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9216. for (var row = 0; row <= splitYBy; row++) {
  9217. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9218. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9219. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9220. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9221. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9222. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9223. for (var col = 0; col <= splitXBy; col++, k++) {
  9224. if ((row === 0 || row === splitYBy) &&
  9225. (col === 0 || col === splitXBy)) {
  9226. continue;
  9227. }
  9228. var x = 0, y = 0;
  9229. var q = 0;
  9230. for (var i = 0; i <= 3; i++) {
  9231. for (var j = 0; j <= 3; j++, q++) {
  9232. var m = bRow[row][i] * bCol[col][j];
  9233. x += coords[pi[q]][0] * m;
  9234. y += coords[pi[q]][1] * m;
  9235. }
  9236. }
  9237. figureCoords[k] = coords.length;
  9238. coords.push([x, y]);
  9239. figureColors[k] = colors.length;
  9240. var newColor = new Uint8Array(3);
  9241. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9242. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9243. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9244. colors.push(newColor);
  9245. }
  9246. }
  9247. figureCoords[0] = pi[0];
  9248. figureColors[0] = ci[0];
  9249. figureCoords[splitXBy] = pi[3];
  9250. figureColors[splitXBy] = ci[1];
  9251. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9252. figureColors[verticesPerRow * splitYBy] = ci[2];
  9253. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9254. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9255. mesh.figures[index] = {
  9256. type: 'lattice',
  9257. coords: figureCoords,
  9258. colors: figureColors,
  9259. verticesPerRow: verticesPerRow
  9260. };
  9261. }
  9262. function decodeType6Shading(mesh, reader) {
  9263. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9264. var coords = mesh.coords;
  9265. var colors = mesh.colors;
  9266. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9267. var cs = new Int32Array(4); // c00, c30, c03, c33
  9268. while (reader.hasData) {
  9269. var f = reader.readFlag();
  9270. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9271. var i, ii;
  9272. var pi = coords.length;
  9273. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9274. coords.push(reader.readCoordinate());
  9275. }
  9276. var ci = colors.length;
  9277. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9278. colors.push(reader.readComponents());
  9279. }
  9280. var tmp1, tmp2, tmp3, tmp4;
  9281. switch (f) {
  9282. case 0:
  9283. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9284. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9285. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9286. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9287. cs[2] = ci + 1; cs[3] = ci + 2;
  9288. cs[0] = ci; cs[1] = ci + 3;
  9289. break;
  9290. case 1:
  9291. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9292. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9293. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9294. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9295. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9296. tmp1 = cs[2]; tmp2 = cs[3];
  9297. cs[2] = ci + 1; cs[3] = ci;
  9298. cs[0] = tmp1; cs[1] = tmp2;
  9299. break;
  9300. case 2:
  9301. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9302. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9303. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9304. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9305. cs[2] = cs[3]; cs[3] = ci + 1;
  9306. cs[0] = cs[1]; cs[1] = ci;
  9307. break;
  9308. case 3:
  9309. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9310. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9311. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9312. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9313. cs[2] = cs[0]; cs[3] = cs[1];
  9314. cs[0] = ci; cs[1] = ci + 1;
  9315. break;
  9316. }
  9317. // set p11, p12, p21, p22
  9318. ps[5] = coords.length;
  9319. coords.push([
  9320. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9321. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9322. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9323. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9324. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9325. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9326. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9327. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9328. ]);
  9329. ps[6] = coords.length;
  9330. coords.push([
  9331. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9332. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9333. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9334. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9335. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9336. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9337. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9338. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9339. ]);
  9340. ps[9] = coords.length;
  9341. coords.push([
  9342. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9343. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9344. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9345. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9346. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9347. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9348. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9349. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9350. ]);
  9351. ps[10] = coords.length;
  9352. coords.push([
  9353. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9354. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9355. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9356. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9357. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9358. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9359. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9360. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9361. ]);
  9362. mesh.figures.push({
  9363. type: 'patch',
  9364. coords: new Int32Array(ps), // making copies of ps and cs
  9365. colors: new Int32Array(cs)
  9366. });
  9367. }
  9368. }
  9369. function decodeType7Shading(mesh, reader) {
  9370. var coords = mesh.coords;
  9371. var colors = mesh.colors;
  9372. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9373. var cs = new Int32Array(4); // c00, c30, c03, c33
  9374. while (reader.hasData) {
  9375. var f = reader.readFlag();
  9376. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9377. var i, ii;
  9378. var pi = coords.length;
  9379. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9380. coords.push(reader.readCoordinate());
  9381. }
  9382. var ci = colors.length;
  9383. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9384. colors.push(reader.readComponents());
  9385. }
  9386. var tmp1, tmp2, tmp3, tmp4;
  9387. switch (f) {
  9388. case 0:
  9389. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9390. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9391. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9392. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9393. cs[2] = ci + 1; cs[3] = ci + 2;
  9394. cs[0] = ci; cs[1] = ci + 3;
  9395. break;
  9396. case 1:
  9397. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9398. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9399. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9400. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9401. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9402. tmp1 = cs[2]; tmp2 = cs[3];
  9403. cs[2] = ci + 1; cs[3] = ci;
  9404. cs[0] = tmp1; cs[1] = tmp2;
  9405. break;
  9406. case 2:
  9407. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9408. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9409. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9410. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9411. cs[2] = cs[3]; cs[3] = ci + 1;
  9412. cs[0] = cs[1]; cs[1] = ci;
  9413. break;
  9414. case 3:
  9415. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9416. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9417. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9418. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9419. cs[2] = cs[0]; cs[3] = cs[1];
  9420. cs[0] = ci; cs[1] = ci + 1;
  9421. break;
  9422. }
  9423. mesh.figures.push({
  9424. type: 'patch',
  9425. coords: new Int32Array(ps), // making copies of ps and cs
  9426. colors: new Int32Array(cs)
  9427. });
  9428. }
  9429. }
  9430. function updateBounds(mesh) {
  9431. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9432. maxX = minX, maxY = minY;
  9433. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9434. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9435. minX = minX > x ? x : minX;
  9436. minY = minY > y ? y : minY;
  9437. maxX = maxX < x ? x : maxX;
  9438. maxY = maxY < y ? y : maxY;
  9439. }
  9440. mesh.bounds = [minX, minY, maxX, maxY];
  9441. }
  9442. function packData(mesh) {
  9443. var i, ii, j, jj;
  9444. var coords = mesh.coords;
  9445. var coordsPacked = new Float32Array(coords.length * 2);
  9446. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9447. var xy = coords[i];
  9448. coordsPacked[j++] = xy[0];
  9449. coordsPacked[j++] = xy[1];
  9450. }
  9451. mesh.coords = coordsPacked;
  9452. var colors = mesh.colors;
  9453. var colorsPacked = new Uint8Array(colors.length * 3);
  9454. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9455. var c = colors[i];
  9456. colorsPacked[j++] = c[0];
  9457. colorsPacked[j++] = c[1];
  9458. colorsPacked[j++] = c[2];
  9459. }
  9460. mesh.colors = colorsPacked;
  9461. var figures = mesh.figures;
  9462. for (i = 0, ii = figures.length; i < ii; i++) {
  9463. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9464. for (j = 0, jj = ps.length; j < jj; j++) {
  9465. ps[j] *= 2;
  9466. cs[j] *= 3;
  9467. }
  9468. }
  9469. }
  9470. function Mesh(stream, matrix, xref, res) {
  9471. assert(isStream(stream), 'Mesh data is not a stream');
  9472. var dict = stream.dict;
  9473. this.matrix = matrix;
  9474. this.shadingType = dict.get('ShadingType');
  9475. this.type = 'Pattern';
  9476. this.bbox = dict.get('BBox');
  9477. var cs = dict.get('ColorSpace', 'CS');
  9478. cs = ColorSpace.parse(cs, xref, res);
  9479. this.cs = cs;
  9480. this.background = dict.has('Background') ?
  9481. cs.getRgb(dict.get('Background'), 0) : null;
  9482. var fnObj = dict.get('Function');
  9483. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9484. this.coords = [];
  9485. this.colors = [];
  9486. this.figures = [];
  9487. var decodeContext = {
  9488. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9489. bitsPerComponent: dict.get('BitsPerComponent'),
  9490. bitsPerFlag: dict.get('BitsPerFlag'),
  9491. decode: dict.get('Decode'),
  9492. colorFn: fn,
  9493. colorSpace: cs,
  9494. numComps: fn ? 1 : cs.numComps
  9495. };
  9496. var reader = new MeshStreamReader(stream, decodeContext);
  9497. var patchMesh = false;
  9498. switch (this.shadingType) {
  9499. case PatternType.FREE_FORM_MESH:
  9500. decodeType4Shading(this, reader);
  9501. break;
  9502. case PatternType.LATTICE_FORM_MESH:
  9503. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9504. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9505. decodeType5Shading(this, reader, verticesPerRow);
  9506. break;
  9507. case PatternType.COONS_PATCH_MESH:
  9508. decodeType6Shading(this, reader);
  9509. patchMesh = true;
  9510. break;
  9511. case PatternType.TENSOR_PATCH_MESH:
  9512. decodeType7Shading(this, reader);
  9513. patchMesh = true;
  9514. break;
  9515. default:
  9516. error('Unsupported mesh type.');
  9517. break;
  9518. }
  9519. if (patchMesh) {
  9520. // dirty bounds calculation for determining, how dense shall be triangles
  9521. updateBounds(this);
  9522. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9523. buildFigureFromPatch(this, i);
  9524. }
  9525. }
  9526. // calculate bounds
  9527. updateBounds(this);
  9528. packData(this);
  9529. }
  9530. Mesh.prototype = {
  9531. getIR: function Mesh_getIR() {
  9532. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9533. this.bounds, this.matrix, this.bbox, this.background];
  9534. }
  9535. };
  9536. return Mesh;
  9537. })();
  9538. Shadings.Dummy = (function DummyClosure() {
  9539. function Dummy() {
  9540. this.type = 'Pattern';
  9541. }
  9542. Dummy.prototype = {
  9543. getIR: function Dummy_getIR() {
  9544. return ['Dummy'];
  9545. }
  9546. };
  9547. return Dummy;
  9548. })();
  9549. function getTilingPatternIR(operatorList, dict, args) {
  9550. var matrix = dict.get('Matrix');
  9551. var bbox = dict.get('BBox');
  9552. var xstep = dict.get('XStep');
  9553. var ystep = dict.get('YStep');
  9554. var paintType = dict.get('PaintType');
  9555. var tilingType = dict.get('TilingType');
  9556. return [
  9557. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9558. paintType, tilingType
  9559. ];
  9560. }
  9561. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9562. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9563. uniquePrefix, idCounters, fontCache) {
  9564. this.pdfManager = pdfManager;
  9565. this.xref = xref;
  9566. this.handler = handler;
  9567. this.pageIndex = pageIndex;
  9568. this.uniquePrefix = uniquePrefix;
  9569. this.idCounters = idCounters;
  9570. this.fontCache = fontCache;
  9571. }
  9572. // Trying to minimize Date.now() usage and check every 100 time
  9573. var TIME_SLOT_DURATION_MS = 20;
  9574. var CHECK_TIME_EVERY = 100;
  9575. function TimeSlotManager() {
  9576. this.reset();
  9577. }
  9578. TimeSlotManager.prototype = {
  9579. check: function TimeSlotManager_check() {
  9580. if (++this.checked < CHECK_TIME_EVERY) {
  9581. return false;
  9582. }
  9583. this.checked = 0;
  9584. return this.endTime <= Date.now();
  9585. },
  9586. reset: function TimeSlotManager_reset() {
  9587. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9588. this.checked = 0;
  9589. }
  9590. };
  9591. var deferred = Promise.resolve();
  9592. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9593. PartialEvaluator.prototype = {
  9594. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9595. if (!isDict(resources)) {
  9596. return false;
  9597. }
  9598. var processed = Object.create(null);
  9599. if (resources.objId) {
  9600. processed[resources.objId] = true;
  9601. }
  9602. var nodes = [resources];
  9603. while (nodes.length) {
  9604. var key;
  9605. var node = nodes.shift();
  9606. // First check the current resources for blend modes.
  9607. var graphicStates = node.get('ExtGState');
  9608. if (isDict(graphicStates)) {
  9609. graphicStates = graphicStates.getAll();
  9610. for (key in graphicStates) {
  9611. var graphicState = graphicStates[key];
  9612. var bm = graphicState['BM'];
  9613. if (isName(bm) && bm.name !== 'Normal') {
  9614. return true;
  9615. }
  9616. }
  9617. }
  9618. // Descend into the XObjects to look for more resources and blend modes.
  9619. var xObjects = node.get('XObject');
  9620. if (!isDict(xObjects)) {
  9621. continue;
  9622. }
  9623. xObjects = xObjects.getAll();
  9624. for (key in xObjects) {
  9625. var xObject = xObjects[key];
  9626. if (!isStream(xObject)) {
  9627. continue;
  9628. }
  9629. if (xObject.dict.objId) {
  9630. if (processed[xObject.dict.objId]) {
  9631. // stream has objId and is processed already
  9632. continue;
  9633. }
  9634. processed[xObject.dict.objId] = true;
  9635. }
  9636. var xResources = xObject.dict.get('Resources');
  9637. // Checking objId to detect an infinite loop.
  9638. if (isDict(xResources) &&
  9639. (!xResources.objId || !processed[xResources.objId])) {
  9640. nodes.push(xResources);
  9641. if (xResources.objId) {
  9642. processed[xResources.objId] = true;
  9643. }
  9644. }
  9645. }
  9646. }
  9647. return false;
  9648. },
  9649. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9650. xobj, smask,
  9651. operatorList,
  9652. initialState) {
  9653. var matrix = xobj.dict.get('Matrix');
  9654. var bbox = xobj.dict.get('BBox');
  9655. var group = xobj.dict.get('Group');
  9656. if (group) {
  9657. var groupOptions = {
  9658. matrix: matrix,
  9659. bbox: bbox,
  9660. smask: smask,
  9661. isolated: false,
  9662. knockout: false
  9663. };
  9664. var groupSubtype = group.get('S');
  9665. var colorSpace;
  9666. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9667. groupOptions.isolated = (group.get('I') || false);
  9668. groupOptions.knockout = (group.get('K') || false);
  9669. colorSpace = (group.has('CS') ?
  9670. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9671. }
  9672. if (smask && smask.backdrop) {
  9673. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9674. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9675. }
  9676. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9677. }
  9678. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9679. return this.getOperatorList(xobj,
  9680. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9681. then(function () {
  9682. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9683. if (group) {
  9684. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9685. }
  9686. });
  9687. },
  9688. buildPaintImageXObject:
  9689. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9690. inline, operatorList,
  9691. cacheKey, imageCache) {
  9692. var self = this;
  9693. var dict = image.dict;
  9694. var w = dict.get('Width', 'W');
  9695. var h = dict.get('Height', 'H');
  9696. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9697. warn('Image dimensions are missing, or not numbers.');
  9698. return;
  9699. }
  9700. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9701. warn('Image exceeded maximum allowed size and was removed.');
  9702. return;
  9703. }
  9704. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9705. var imgData, args;
  9706. if (imageMask) {
  9707. // This depends on a tmpCanvas being filled with the
  9708. // current fillStyle, such that processing the pixel
  9709. // data can't be done here. Instead of creating a
  9710. // complete PDFImage, only read the information needed
  9711. // for later.
  9712. var width = dict.get('Width', 'W');
  9713. var height = dict.get('Height', 'H');
  9714. var bitStrideLength = (width + 7) >> 3;
  9715. var imgArray = image.getBytes(bitStrideLength * height);
  9716. var decode = dict.get('Decode', 'D');
  9717. var inverseDecode = (!!decode && decode[0] > 0);
  9718. imgData = PDFImage.createMask(imgArray, width, height,
  9719. image instanceof DecodeStream,
  9720. inverseDecode);
  9721. imgData.cached = true;
  9722. args = [imgData];
  9723. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9724. if (cacheKey) {
  9725. imageCache[cacheKey] = {
  9726. fn: OPS.paintImageMaskXObject,
  9727. args: args
  9728. };
  9729. }
  9730. return;
  9731. }
  9732. var softMask = (dict.get('SMask', 'SM') || false);
  9733. var mask = (dict.get('Mask') || false);
  9734. var SMALL_IMAGE_DIMENSIONS = 200;
  9735. // Inlining small images into the queue as RGB data
  9736. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9737. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9738. var imageObj = new PDFImage(this.xref, resources, image,
  9739. inline, null, null);
  9740. // We force the use of RGBA_32BPP images here, because we can't handle
  9741. // any other kind.
  9742. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9743. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9744. return;
  9745. }
  9746. // If there is no imageMask, create the PDFImage and a lot
  9747. // of image processing can be done here.
  9748. var uniquePrefix = (this.uniquePrefix || '');
  9749. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9750. operatorList.addDependency(objId);
  9751. args = [objId, w, h];
  9752. if (!softMask && !mask && image instanceof JpegStream &&
  9753. image.isNativelySupported(this.xref, resources)) {
  9754. // These JPEGs don't need any more processing so we can just send it.
  9755. operatorList.addOp(OPS.paintJpegXObject, args);
  9756. this.handler.send('obj',
  9757. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9758. return;
  9759. }
  9760. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9761. then(function(imageObj) {
  9762. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9763. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9764. [imgData.data.buffer]);
  9765. }).then(undefined, function (reason) {
  9766. warn('Unable to decode image: ' + reason);
  9767. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9768. });
  9769. operatorList.addOp(OPS.paintImageXObject, args);
  9770. if (cacheKey) {
  9771. imageCache[cacheKey] = {
  9772. fn: OPS.paintImageXObject,
  9773. args: args
  9774. };
  9775. }
  9776. },
  9777. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9778. operatorList,
  9779. stateManager) {
  9780. var smaskContent = smask.get('G');
  9781. var smaskOptions = {
  9782. subtype: smask.get('S').name,
  9783. backdrop: smask.get('BC')
  9784. };
  9785. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9786. operatorList, stateManager.state.clone());
  9787. },
  9788. handleTilingType:
  9789. function PartialEvaluator_handleTilingType(fn, args, resources,
  9790. pattern, patternDict,
  9791. operatorList) {
  9792. // Create an IR of the pattern code.
  9793. var tilingOpList = new OperatorList();
  9794. return this.getOperatorList(pattern,
  9795. (patternDict.get('Resources') || resources), tilingOpList).
  9796. then(function () {
  9797. // Add the dependencies to the parent operator list so they are
  9798. // resolved before sub operator list is executed synchronously.
  9799. operatorList.addDependencies(tilingOpList.dependencies);
  9800. operatorList.addOp(fn, getTilingPatternIR({
  9801. fnArray: tilingOpList.fnArray,
  9802. argsArray: tilingOpList.argsArray
  9803. }, patternDict, args));
  9804. });
  9805. },
  9806. handleSetFont:
  9807. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9808. operatorList, state) {
  9809. // TODO(mack): Not needed?
  9810. var fontName;
  9811. if (fontArgs) {
  9812. fontArgs = fontArgs.slice();
  9813. fontName = fontArgs[0].name;
  9814. }
  9815. var self = this;
  9816. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9817. function (translated) {
  9818. if (!translated.font.isType3Font) {
  9819. return translated;
  9820. }
  9821. return translated.loadType3Data(self, resources, operatorList).then(
  9822. function () {
  9823. return translated;
  9824. });
  9825. }).then(function (translated) {
  9826. state.font = translated.font;
  9827. translated.send(self.handler);
  9828. return translated.loadedName;
  9829. });
  9830. },
  9831. handleText: function PartialEvaluator_handleText(chars, state) {
  9832. var font = state.font;
  9833. var glyphs = font.charsToGlyphs(chars);
  9834. var isAddToPathSet = !!(state.textRenderingMode &
  9835. TextRenderingMode.ADD_TO_PATH_FLAG);
  9836. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9837. var buildPath = function (fontChar) {
  9838. if (!font.renderer.hasBuiltPath(fontChar)) {
  9839. var path = font.renderer.getPathJs(fontChar);
  9840. this.handler.send('commonobj', [
  9841. font.loadedName + '_path_' + fontChar,
  9842. 'FontPath',
  9843. path
  9844. ]);
  9845. }
  9846. }.bind(this);
  9847. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9848. var glyph = glyphs[i];
  9849. if (glyph === null) {
  9850. continue;
  9851. }
  9852. buildPath(glyph.fontChar);
  9853. // If the glyph has an accent we need to build a path for its
  9854. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9855. var accent = glyph.accent;
  9856. if (accent && accent.fontChar) {
  9857. buildPath(accent.fontChar);
  9858. }
  9859. }
  9860. }
  9861. return glyphs;
  9862. },
  9863. setGState: function PartialEvaluator_setGState(resources, gState,
  9864. operatorList, xref,
  9865. stateManager) {
  9866. // This array holds the converted/processed state data.
  9867. var gStateObj = [];
  9868. var gStateMap = gState.map;
  9869. var self = this;
  9870. var promise = Promise.resolve();
  9871. for (var key in gStateMap) {
  9872. var value = gStateMap[key];
  9873. switch (key) {
  9874. case 'Type':
  9875. break;
  9876. case 'LW':
  9877. case 'LC':
  9878. case 'LJ':
  9879. case 'ML':
  9880. case 'D':
  9881. case 'RI':
  9882. case 'FL':
  9883. case 'CA':
  9884. case 'ca':
  9885. gStateObj.push([key, value]);
  9886. break;
  9887. case 'Font':
  9888. promise = promise.then(function () {
  9889. return self.handleSetFont(resources, null, value[0],
  9890. operatorList, stateManager.state).
  9891. then(function (loadedName) {
  9892. operatorList.addDependency(loadedName);
  9893. gStateObj.push([key, [loadedName, value[1]]]);
  9894. });
  9895. });
  9896. break;
  9897. case 'BM':
  9898. gStateObj.push([key, value]);
  9899. break;
  9900. case 'SMask':
  9901. if (isName(value) && value.name === 'None') {
  9902. gStateObj.push([key, false]);
  9903. break;
  9904. }
  9905. var dict = xref.fetchIfRef(value);
  9906. if (isDict(dict)) {
  9907. promise = promise.then(function () {
  9908. return self.handleSMask(dict, resources, operatorList,
  9909. stateManager);
  9910. });
  9911. gStateObj.push([key, true]);
  9912. } else {
  9913. warn('Unsupported SMask type');
  9914. }
  9915. break;
  9916. // Only generate info log messages for the following since
  9917. // they are unlikely to have a big impact on the rendering.
  9918. case 'OP':
  9919. case 'op':
  9920. case 'OPM':
  9921. case 'BG':
  9922. case 'BG2':
  9923. case 'UCR':
  9924. case 'UCR2':
  9925. case 'TR':
  9926. case 'TR2':
  9927. case 'HT':
  9928. case 'SM':
  9929. case 'SA':
  9930. case 'AIS':
  9931. case 'TK':
  9932. // TODO implement these operators.
  9933. info('graphic state operator ' + key);
  9934. break;
  9935. default:
  9936. info('Unknown graphic state operator ' + key);
  9937. break;
  9938. }
  9939. }
  9940. return promise.then(function () {
  9941. if (gStateObj.length >= 0) {
  9942. operatorList.addOp(OPS.setGState, [gStateObj]);
  9943. }
  9944. });
  9945. },
  9946. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9947. resources) {
  9948. function errorFont() {
  9949. return Promise.resolve(new TranslatedFont('g_font_error',
  9950. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9951. }
  9952. var fontRef;
  9953. if (font) { // Loading by ref.
  9954. assert(isRef(font));
  9955. fontRef = font;
  9956. } else { // Loading by name.
  9957. var fontRes = resources.get('Font');
  9958. if (fontRes) {
  9959. fontRef = fontRes.getRaw(fontName);
  9960. } else {
  9961. warn('fontRes not available');
  9962. return errorFont();
  9963. }
  9964. }
  9965. if (!fontRef) {
  9966. warn('fontRef not available');
  9967. return errorFont();
  9968. }
  9969. if (this.fontCache.has(fontRef)) {
  9970. return this.fontCache.get(fontRef);
  9971. }
  9972. font = xref.fetchIfRef(fontRef);
  9973. if (!isDict(font)) {
  9974. return errorFont();
  9975. }
  9976. // We are holding font.translated references just for fontRef that are not
  9977. // dictionaries (Dict). See explanation below.
  9978. if (font.translated) {
  9979. return font.translated;
  9980. }
  9981. var fontCapability = createPromiseCapability();
  9982. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9983. var descriptor = preEvaluatedFont.descriptor;
  9984. var fontID = fontRef.num + '_' + fontRef.gen;
  9985. if (isDict(descriptor)) {
  9986. if (!descriptor.fontAliases) {
  9987. descriptor.fontAliases = Object.create(null);
  9988. }
  9989. var fontAliases = descriptor.fontAliases;
  9990. var hash = preEvaluatedFont.hash;
  9991. if (fontAliases[hash]) {
  9992. var aliasFontRef = fontAliases[hash].aliasRef;
  9993. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9994. this.fontCache.putAlias(fontRef, aliasFontRef);
  9995. return this.fontCache.get(fontRef);
  9996. }
  9997. }
  9998. if (!fontAliases[hash]) {
  9999. fontAliases[hash] = {
  10000. fontID: Font.getFontID()
  10001. };
  10002. }
  10003. fontAliases[hash].aliasRef = fontRef;
  10004. fontID = fontAliases[hash].fontID;
  10005. }
  10006. // Workaround for bad PDF generators that don't reference fonts
  10007. // properly, i.e. by not using an object identifier.
  10008. // Check if the fontRef is a Dict (as opposed to a standard object),
  10009. // in which case we don't cache the font and instead reference it by
  10010. // fontName in font.loadedName below.
  10011. var fontRefIsDict = isDict(fontRef);
  10012. if (!fontRefIsDict) {
  10013. this.fontCache.put(fontRef, fontCapability.promise);
  10014. }
  10015. // Keep track of each font we translated so the caller can
  10016. // load them asynchronously before calling display on a page.
  10017. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10018. fontName.replace(/\W/g, '') : fontID);
  10019. font.translated = fontCapability.promise;
  10020. // TODO move promises into translate font
  10021. var translatedPromise;
  10022. try {
  10023. translatedPromise = Promise.resolve(
  10024. this.translateFont(preEvaluatedFont, xref));
  10025. } catch (e) {
  10026. translatedPromise = Promise.reject(e);
  10027. }
  10028. translatedPromise.then(function (translatedFont) {
  10029. if (translatedFont.fontType !== undefined) {
  10030. var xrefFontStats = xref.stats.fontTypes;
  10031. xrefFontStats[translatedFont.fontType] = true;
  10032. }
  10033. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10034. translatedFont, font));
  10035. }, function (reason) {
  10036. // TODO fontCapability.reject?
  10037. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10038. try {
  10039. // error, but it's still nice to have font type reported
  10040. var descriptor = preEvaluatedFont.descriptor;
  10041. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10042. var subtype = fontFile3 && fontFile3.get('Subtype');
  10043. var fontType = getFontType(preEvaluatedFont.type,
  10044. subtype && subtype.name);
  10045. var xrefFontStats = xref.stats.fontTypes;
  10046. xrefFontStats[fontType] = true;
  10047. } catch (ex) { }
  10048. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10049. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10050. font));
  10051. });
  10052. return fontCapability.promise;
  10053. },
  10054. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10055. var lastIndex = operatorList.length - 1;
  10056. if (!args) {
  10057. args = [];
  10058. }
  10059. if (lastIndex < 0 ||
  10060. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10061. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10062. } else {
  10063. var opArgs = operatorList.argsArray[lastIndex];
  10064. opArgs[0].push(fn);
  10065. Array.prototype.push.apply(opArgs[1], args);
  10066. }
  10067. },
  10068. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10069. cs, patterns, resources, xref) {
  10070. // compile tiling patterns
  10071. var patternName = args[args.length - 1];
  10072. // SCN/scn applies patterns along with normal colors
  10073. var pattern;
  10074. if (isName(patternName) &&
  10075. (pattern = patterns.get(patternName.name))) {
  10076. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10077. var typeNum = dict.get('PatternType');
  10078. if (typeNum === TILING_PATTERN) {
  10079. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10080. return this.handleTilingType(fn, color, resources, pattern,
  10081. dict, operatorList);
  10082. } else if (typeNum === SHADING_PATTERN) {
  10083. var shading = dict.get('Shading');
  10084. var matrix = dict.get('Matrix');
  10085. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10086. operatorList.addOp(fn, pattern.getIR());
  10087. return Promise.resolve();
  10088. } else {
  10089. return Promise.reject('Unknown PatternType: ' + typeNum);
  10090. }
  10091. }
  10092. // TODO shall we fail here?
  10093. operatorList.addOp(fn, args);
  10094. return Promise.resolve();
  10095. },
  10096. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10097. resources,
  10098. operatorList,
  10099. initialState) {
  10100. var self = this;
  10101. var xref = this.xref;
  10102. var imageCache = {};
  10103. assert(operatorList);
  10104. resources = (resources || Dict.empty);
  10105. var xobjs = (resources.get('XObject') || Dict.empty);
  10106. var patterns = (resources.get('Pattern') || Dict.empty);
  10107. var stateManager = new StateManager(initialState || new EvalState());
  10108. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10109. var timeSlotManager = new TimeSlotManager();
  10110. return new Promise(function next(resolve, reject) {
  10111. timeSlotManager.reset();
  10112. var stop, operation = {}, i, ii, cs;
  10113. while (!(stop = timeSlotManager.check())) {
  10114. // The arguments parsed by read() are used beyond this loop, so we
  10115. // cannot reuse the same array on each iteration. Therefore we pass
  10116. // in |null| as the initial value (see the comment on
  10117. // EvaluatorPreprocessor_read() for why).
  10118. operation.args = null;
  10119. if (!(preprocessor.read(operation))) {
  10120. break;
  10121. }
  10122. var args = operation.args;
  10123. var fn = operation.fn;
  10124. switch (fn | 0) {
  10125. case OPS.paintXObject:
  10126. if (args[0].code) {
  10127. break;
  10128. }
  10129. // eagerly compile XForm objects
  10130. var name = args[0].name;
  10131. if (imageCache[name] !== undefined) {
  10132. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10133. args = null;
  10134. continue;
  10135. }
  10136. var xobj = xobjs.get(name);
  10137. if (xobj) {
  10138. assert(isStream(xobj), 'XObject should be a stream');
  10139. var type = xobj.dict.get('Subtype');
  10140. assert(isName(type),
  10141. 'XObject should have a Name subtype');
  10142. if (type.name === 'Form') {
  10143. stateManager.save();
  10144. return self.buildFormXObject(resources, xobj, null,
  10145. operatorList,
  10146. stateManager.state.clone()).
  10147. then(function () {
  10148. stateManager.restore();
  10149. next(resolve, reject);
  10150. }, reject);
  10151. } else if (type.name === 'Image') {
  10152. self.buildPaintImageXObject(resources, xobj, false,
  10153. operatorList, name, imageCache);
  10154. args = null;
  10155. continue;
  10156. } else if (type.name === 'PS') {
  10157. // PostScript XObjects are unused when viewing documents.
  10158. // See section 4.7.1 of Adobe's PDF reference.
  10159. info('Ignored XObject subtype PS');
  10160. continue;
  10161. } else {
  10162. error('Unhandled XObject subtype ' + type.name);
  10163. }
  10164. }
  10165. break;
  10166. case OPS.setFont:
  10167. var fontSize = args[1];
  10168. // eagerly collect all fonts
  10169. return self.handleSetFont(resources, args, null,
  10170. operatorList, stateManager.state).
  10171. then(function (loadedName) {
  10172. operatorList.addDependency(loadedName);
  10173. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10174. next(resolve, reject);
  10175. }, reject);
  10176. case OPS.endInlineImage:
  10177. var cacheKey = args[0].cacheKey;
  10178. if (cacheKey) {
  10179. var cacheEntry = imageCache[cacheKey];
  10180. if (cacheEntry !== undefined) {
  10181. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10182. args = null;
  10183. continue;
  10184. }
  10185. }
  10186. self.buildPaintImageXObject(resources, args[0], true,
  10187. operatorList, cacheKey, imageCache);
  10188. args = null;
  10189. continue;
  10190. case OPS.showText:
  10191. args[0] = self.handleText(args[0], stateManager.state);
  10192. break;
  10193. case OPS.showSpacedText:
  10194. var arr = args[0];
  10195. var combinedGlyphs = [];
  10196. var arrLength = arr.length;
  10197. for (i = 0; i < arrLength; ++i) {
  10198. var arrItem = arr[i];
  10199. if (isString(arrItem)) {
  10200. Array.prototype.push.apply(combinedGlyphs,
  10201. self.handleText(arrItem, stateManager.state));
  10202. } else if (isNum(arrItem)) {
  10203. combinedGlyphs.push(arrItem);
  10204. }
  10205. }
  10206. args[0] = combinedGlyphs;
  10207. fn = OPS.showText;
  10208. break;
  10209. case OPS.nextLineShowText:
  10210. operatorList.addOp(OPS.nextLine);
  10211. args[0] = self.handleText(args[0], stateManager.state);
  10212. fn = OPS.showText;
  10213. break;
  10214. case OPS.nextLineSetSpacingShowText:
  10215. operatorList.addOp(OPS.nextLine);
  10216. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10217. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10218. args[0] = self.handleText(args[0], stateManager.state);
  10219. fn = OPS.showText;
  10220. break;
  10221. case OPS.setTextRenderingMode:
  10222. stateManager.state.textRenderingMode = args[0];
  10223. break;
  10224. case OPS.setFillColorSpace:
  10225. stateManager.state.fillColorSpace =
  10226. ColorSpace.parse(args[0], xref, resources);
  10227. continue;
  10228. case OPS.setStrokeColorSpace:
  10229. stateManager.state.strokeColorSpace =
  10230. ColorSpace.parse(args[0], xref, resources);
  10231. continue;
  10232. case OPS.setFillColor:
  10233. cs = stateManager.state.fillColorSpace;
  10234. args = cs.getRgb(args, 0);
  10235. fn = OPS.setFillRGBColor;
  10236. break;
  10237. case OPS.setStrokeColor:
  10238. cs = stateManager.state.strokeColorSpace;
  10239. args = cs.getRgb(args, 0);
  10240. fn = OPS.setStrokeRGBColor;
  10241. break;
  10242. case OPS.setFillGray:
  10243. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10244. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10245. fn = OPS.setFillRGBColor;
  10246. break;
  10247. case OPS.setStrokeGray:
  10248. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10249. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10250. fn = OPS.setStrokeRGBColor;
  10251. break;
  10252. case OPS.setFillCMYKColor:
  10253. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10254. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10255. fn = OPS.setFillRGBColor;
  10256. break;
  10257. case OPS.setStrokeCMYKColor:
  10258. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10259. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10260. fn = OPS.setStrokeRGBColor;
  10261. break;
  10262. case OPS.setFillRGBColor:
  10263. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10264. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10265. break;
  10266. case OPS.setStrokeRGBColor:
  10267. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10268. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10269. break;
  10270. case OPS.setFillColorN:
  10271. cs = stateManager.state.fillColorSpace;
  10272. if (cs.name === 'Pattern') {
  10273. return self.handleColorN(operatorList, OPS.setFillColorN,
  10274. args, cs, patterns, resources, xref).then(function() {
  10275. next(resolve, reject);
  10276. }, reject);
  10277. }
  10278. args = cs.getRgb(args, 0);
  10279. fn = OPS.setFillRGBColor;
  10280. break;
  10281. case OPS.setStrokeColorN:
  10282. cs = stateManager.state.strokeColorSpace;
  10283. if (cs.name === 'Pattern') {
  10284. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10285. args, cs, patterns, resources, xref).then(function() {
  10286. next(resolve, reject);
  10287. }, reject);
  10288. }
  10289. args = cs.getRgb(args, 0);
  10290. fn = OPS.setStrokeRGBColor;
  10291. break;
  10292. case OPS.shadingFill:
  10293. var shadingRes = resources.get('Shading');
  10294. if (!shadingRes) {
  10295. error('No shading resource found');
  10296. }
  10297. var shading = shadingRes.get(args[0].name);
  10298. if (!shading) {
  10299. error('No shading object found');
  10300. }
  10301. var shadingFill = Pattern.parseShading(shading, null, xref,
  10302. resources);
  10303. var patternIR = shadingFill.getIR();
  10304. args = [patternIR];
  10305. fn = OPS.shadingFill;
  10306. break;
  10307. case OPS.setGState:
  10308. var dictName = args[0];
  10309. var extGState = resources.get('ExtGState');
  10310. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10311. break;
  10312. }
  10313. var gState = extGState.get(dictName.name);
  10314. return self.setGState(resources, gState, operatorList, xref,
  10315. stateManager).then(function() {
  10316. next(resolve, reject);
  10317. }, reject);
  10318. case OPS.moveTo:
  10319. case OPS.lineTo:
  10320. case OPS.curveTo:
  10321. case OPS.curveTo2:
  10322. case OPS.curveTo3:
  10323. case OPS.closePath:
  10324. self.buildPath(operatorList, fn, args);
  10325. continue;
  10326. case OPS.rectangle:
  10327. self.buildPath(operatorList, fn, args);
  10328. continue;
  10329. }
  10330. operatorList.addOp(fn, args);
  10331. }
  10332. if (stop) {
  10333. deferred.then(function () {
  10334. next(resolve, reject);
  10335. });
  10336. return;
  10337. }
  10338. // Some PDFs don't close all restores inside object/form.
  10339. // Closing those for them.
  10340. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10341. operatorList.addOp(OPS.restore, []);
  10342. }
  10343. resolve();
  10344. });
  10345. },
  10346. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10347. stateManager) {
  10348. stateManager = (stateManager || new StateManager(new TextState()));
  10349. var textContent = {
  10350. items: [],
  10351. styles: Object.create(null)
  10352. };
  10353. var bidiTexts = textContent.items;
  10354. var SPACE_FACTOR = 0.35;
  10355. var MULTI_SPACE_FACTOR = 1.5;
  10356. var self = this;
  10357. var xref = this.xref;
  10358. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10359. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10360. var xobjs = null;
  10361. var xobjsCache = {};
  10362. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10363. var textState;
  10364. function newTextChunk() {
  10365. var font = textState.font;
  10366. if (!(font.loadedName in textContent.styles)) {
  10367. textContent.styles[font.loadedName] = {
  10368. fontFamily: font.fallbackName,
  10369. ascent: font.ascent,
  10370. descent: font.descent,
  10371. vertical: font.vertical
  10372. };
  10373. }
  10374. return {
  10375. // |str| is initially an array which we push individual chars to, and
  10376. // then runBidi() overwrites it with the final string.
  10377. str: [],
  10378. dir: null,
  10379. width: 0,
  10380. height: 0,
  10381. transform: null,
  10382. fontName: font.loadedName
  10383. };
  10384. }
  10385. function runBidi(textChunk) {
  10386. var str = textChunk.str.join('');
  10387. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10388. textChunk.str = bidiResult.str;
  10389. textChunk.dir = bidiResult.dir;
  10390. return textChunk;
  10391. }
  10392. function handleSetFont(fontName, fontRef) {
  10393. return self.loadFont(fontName, fontRef, xref, resources).
  10394. then(function (translated) {
  10395. textState.font = translated.font;
  10396. textState.fontMatrix = translated.font.fontMatrix ||
  10397. FONT_IDENTITY_MATRIX;
  10398. });
  10399. }
  10400. function buildTextGeometry(chars, textChunk) {
  10401. var font = textState.font;
  10402. textChunk = textChunk || newTextChunk();
  10403. if (!textChunk.transform) {
  10404. // 9.4.4 Text Space Details
  10405. var tsm = [textState.fontSize * textState.textHScale, 0,
  10406. 0, textState.fontSize,
  10407. 0, textState.textRise];
  10408. var trm = textChunk.transform = Util.transform(textState.ctm,
  10409. Util.transform(textState.textMatrix, tsm));
  10410. if (!font.vertical) {
  10411. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10412. } else {
  10413. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10414. }
  10415. }
  10416. var width = 0;
  10417. var height = 0;
  10418. var glyphs = font.charsToGlyphs(chars);
  10419. var defaultVMetrics = font.defaultVMetrics;
  10420. for (var i = 0; i < glyphs.length; i++) {
  10421. var glyph = glyphs[i];
  10422. if (!glyph) { // Previous glyph was a space.
  10423. width += textState.wordSpacing * textState.textHScale;
  10424. continue;
  10425. }
  10426. var vMetricX = null;
  10427. var vMetricY = null;
  10428. var glyphWidth = null;
  10429. if (font.vertical) {
  10430. if (glyph.vmetric) {
  10431. glyphWidth = glyph.vmetric[0];
  10432. vMetricX = glyph.vmetric[1];
  10433. vMetricY = glyph.vmetric[2];
  10434. } else {
  10435. glyphWidth = glyph.width;
  10436. vMetricX = glyph.width * 0.5;
  10437. vMetricY = defaultVMetrics[2];
  10438. }
  10439. } else {
  10440. glyphWidth = glyph.width;
  10441. }
  10442. var glyphUnicode = glyph.unicode;
  10443. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10444. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10445. }
  10446. glyphUnicode = reverseIfRtl(glyphUnicode);
  10447. // The following will calculate the x and y of the individual glyphs.
  10448. // if (font.vertical) {
  10449. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10450. // textState.fontMatrix[0];
  10451. // tsm[5] -= vMetricY * textState.fontSize *
  10452. // textState.fontMatrix[0];
  10453. // }
  10454. // var trm = Util.transform(textState.textMatrix, tsm);
  10455. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10456. // var x = pt[0];
  10457. // var y = pt[1];
  10458. var tx = 0;
  10459. var ty = 0;
  10460. if (!font.vertical) {
  10461. var w0 = glyphWidth * textState.fontMatrix[0];
  10462. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10463. textState.textHScale;
  10464. width += tx;
  10465. } else {
  10466. var w1 = glyphWidth * textState.fontMatrix[0];
  10467. ty = w1 * textState.fontSize + textState.charSpacing;
  10468. height += ty;
  10469. }
  10470. textState.translateTextMatrix(tx, ty);
  10471. textChunk.str.push(glyphUnicode);
  10472. }
  10473. var a = textState.textLineMatrix[0];
  10474. var b = textState.textLineMatrix[1];
  10475. var scaleLineX = Math.sqrt(a * a + b * b);
  10476. a = textState.ctm[0];
  10477. b = textState.ctm[1];
  10478. var scaleCtmX = Math.sqrt(a * a + b * b);
  10479. if (!font.vertical) {
  10480. textChunk.width += width * scaleCtmX * scaleLineX;
  10481. } else {
  10482. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10483. }
  10484. return textChunk;
  10485. }
  10486. var timeSlotManager = new TimeSlotManager();
  10487. return new Promise(function next(resolve, reject) {
  10488. timeSlotManager.reset();
  10489. var stop, operation = {}, args = [];
  10490. while (!(stop = timeSlotManager.check())) {
  10491. // The arguments parsed by read() are not used beyond this loop, so
  10492. // we can reuse the same array on every iteration, thus avoiding
  10493. // unnecessary allocations.
  10494. args.length = 0;
  10495. operation.args = args;
  10496. if (!(preprocessor.read(operation))) {
  10497. break;
  10498. }
  10499. textState = stateManager.state;
  10500. var fn = operation.fn;
  10501. args = operation.args;
  10502. switch (fn | 0) {
  10503. case OPS.setFont:
  10504. textState.fontSize = args[1];
  10505. return handleSetFont(args[0].name).then(function() {
  10506. next(resolve, reject);
  10507. }, reject);
  10508. case OPS.setTextRise:
  10509. textState.textRise = args[0];
  10510. break;
  10511. case OPS.setHScale:
  10512. textState.textHScale = args[0] / 100;
  10513. break;
  10514. case OPS.setLeading:
  10515. textState.leading = args[0];
  10516. break;
  10517. case OPS.moveText:
  10518. textState.translateTextLineMatrix(args[0], args[1]);
  10519. textState.textMatrix = textState.textLineMatrix.slice();
  10520. break;
  10521. case OPS.setLeadingMoveText:
  10522. textState.leading = -args[1];
  10523. textState.translateTextLineMatrix(args[0], args[1]);
  10524. textState.textMatrix = textState.textLineMatrix.slice();
  10525. break;
  10526. case OPS.nextLine:
  10527. textState.carriageReturn();
  10528. break;
  10529. case OPS.setTextMatrix:
  10530. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10531. args[4], args[5]);
  10532. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10533. args[4], args[5]);
  10534. break;
  10535. case OPS.setCharSpacing:
  10536. textState.charSpacing = args[0];
  10537. break;
  10538. case OPS.setWordSpacing:
  10539. textState.wordSpacing = args[0];
  10540. break;
  10541. case OPS.beginText:
  10542. textState.textMatrix = IDENTITY_MATRIX.slice();
  10543. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10544. break;
  10545. case OPS.showSpacedText:
  10546. var items = args[0];
  10547. var textChunk = newTextChunk();
  10548. var offset;
  10549. for (var j = 0, jj = items.length; j < jj; j++) {
  10550. if (typeof items[j] === 'string') {
  10551. buildTextGeometry(items[j], textChunk);
  10552. } else {
  10553. var val = items[j] / 1000;
  10554. if (!textState.font.vertical) {
  10555. offset = -val * textState.fontSize * textState.textHScale *
  10556. textState.textMatrix[0];
  10557. textState.translateTextMatrix(offset, 0);
  10558. textChunk.width += offset;
  10559. } else {
  10560. offset = -val * textState.fontSize *
  10561. textState.textMatrix[3];
  10562. textState.translateTextMatrix(0, offset);
  10563. textChunk.height += offset;
  10564. }
  10565. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10566. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10567. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10568. fakeSpaces = Math.round(fakeSpaces);
  10569. while (fakeSpaces--) {
  10570. textChunk.str.push(' ');
  10571. }
  10572. } else if (fakeSpaces > SPACE_FACTOR) {
  10573. textChunk.str.push(' ');
  10574. }
  10575. }
  10576. }
  10577. }
  10578. bidiTexts.push(runBidi(textChunk));
  10579. break;
  10580. case OPS.showText:
  10581. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10582. break;
  10583. case OPS.nextLineShowText:
  10584. textState.carriageReturn();
  10585. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10586. break;
  10587. case OPS.nextLineSetSpacingShowText:
  10588. textState.wordSpacing = args[0];
  10589. textState.charSpacing = args[1];
  10590. textState.carriageReturn();
  10591. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10592. break;
  10593. case OPS.paintXObject:
  10594. if (args[0].code) {
  10595. break;
  10596. }
  10597. if (!xobjs) {
  10598. xobjs = (resources.get('XObject') || Dict.empty);
  10599. }
  10600. var name = args[0].name;
  10601. if (xobjsCache.key === name) {
  10602. if (xobjsCache.texts) {
  10603. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10604. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10605. }
  10606. break;
  10607. }
  10608. var xobj = xobjs.get(name);
  10609. if (!xobj) {
  10610. break;
  10611. }
  10612. assert(isStream(xobj), 'XObject should be a stream');
  10613. var type = xobj.dict.get('Subtype');
  10614. assert(isName(type),
  10615. 'XObject should have a Name subtype');
  10616. if ('Form' !== type.name) {
  10617. xobjsCache.key = name;
  10618. xobjsCache.texts = null;
  10619. break;
  10620. }
  10621. stateManager.save();
  10622. var matrix = xobj.dict.get('Matrix');
  10623. if (isArray(matrix) && matrix.length === 6) {
  10624. stateManager.transform(matrix);
  10625. }
  10626. return self.getTextContent(xobj,
  10627. xobj.dict.get('Resources') || resources, stateManager).
  10628. then(function (formTextContent) {
  10629. Util.appendToArray(bidiTexts, formTextContent.items);
  10630. Util.extendObj(textContent.styles, formTextContent.styles);
  10631. stateManager.restore();
  10632. xobjsCache.key = name;
  10633. xobjsCache.texts = formTextContent;
  10634. next(resolve, reject);
  10635. }, reject);
  10636. case OPS.setGState:
  10637. var dictName = args[0];
  10638. var extGState = resources.get('ExtGState');
  10639. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10640. break;
  10641. }
  10642. var gsStateMap = extGState.get(dictName.name);
  10643. var gsStateFont = null;
  10644. for (var key in gsStateMap) {
  10645. if (key === 'Font') {
  10646. assert(!gsStateFont);
  10647. gsStateFont = gsStateMap[key];
  10648. }
  10649. }
  10650. if (gsStateFont) {
  10651. textState.fontSize = gsStateFont[1];
  10652. return handleSetFont(gsStateFont[0]).then(function() {
  10653. next(resolve, reject);
  10654. }, reject);
  10655. }
  10656. break;
  10657. } // switch
  10658. } // while
  10659. if (stop) {
  10660. deferred.then(function () {
  10661. next(resolve, reject);
  10662. });
  10663. return;
  10664. }
  10665. resolve(textContent);
  10666. });
  10667. },
  10668. extractDataStructures: function
  10669. partialEvaluatorExtractDataStructures(dict, baseDict,
  10670. xref, properties) {
  10671. // 9.10.2
  10672. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10673. if (toUnicode) {
  10674. properties.toUnicode = this.readToUnicode(toUnicode);
  10675. }
  10676. if (properties.composite) {
  10677. // CIDSystemInfo helps to match CID to glyphs
  10678. var cidSystemInfo = dict.get('CIDSystemInfo');
  10679. if (isDict(cidSystemInfo)) {
  10680. properties.cidSystemInfo = {
  10681. registry: cidSystemInfo.get('Registry'),
  10682. ordering: cidSystemInfo.get('Ordering'),
  10683. supplement: cidSystemInfo.get('Supplement')
  10684. };
  10685. }
  10686. var cidToGidMap = dict.get('CIDToGIDMap');
  10687. if (isStream(cidToGidMap)) {
  10688. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10689. }
  10690. }
  10691. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10692. // and depends on the font type. The base encoding and differences are
  10693. // read here, but the encoding that is actually used is chosen during
  10694. // glyph mapping in the font.
  10695. // TODO: Loading the built in encoding in the font would allow the
  10696. // differences to be merged in here not require us to hold on to it.
  10697. var differences = [];
  10698. var baseEncodingName = null;
  10699. var encoding;
  10700. if (dict.has('Encoding')) {
  10701. encoding = dict.get('Encoding');
  10702. if (isDict(encoding)) {
  10703. baseEncodingName = encoding.get('BaseEncoding');
  10704. baseEncodingName = (isName(baseEncodingName) ?
  10705. baseEncodingName.name : null);
  10706. // Load the differences between the base and original
  10707. if (encoding.has('Differences')) {
  10708. var diffEncoding = encoding.get('Differences');
  10709. var index = 0;
  10710. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10711. var data = diffEncoding[j];
  10712. if (isNum(data)) {
  10713. index = data;
  10714. } else {
  10715. differences[index++] = data.name;
  10716. }
  10717. }
  10718. }
  10719. } else if (isName(encoding)) {
  10720. baseEncodingName = encoding.name;
  10721. } else {
  10722. error('Encoding is not a Name nor a Dict');
  10723. }
  10724. // According to table 114 if the encoding is a named encoding it must be
  10725. // one of these predefined encodings.
  10726. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10727. baseEncodingName !== 'MacExpertEncoding' &&
  10728. baseEncodingName !== 'WinAnsiEncoding')) {
  10729. baseEncodingName = null;
  10730. }
  10731. }
  10732. if (baseEncodingName) {
  10733. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10734. } else {
  10735. encoding = (properties.type === 'TrueType' ?
  10736. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10737. // The Symbolic attribute can be misused for regular fonts
  10738. // Heuristic: we have to check if the font is a standard one also
  10739. if (!!(properties.flags & FontFlags.Symbolic)) {
  10740. encoding = Encodings.MacRomanEncoding;
  10741. if (!properties.file) {
  10742. if (/Symbol/i.test(properties.name)) {
  10743. encoding = Encodings.SymbolSetEncoding;
  10744. } else if (/Dingbats/i.test(properties.name)) {
  10745. encoding = Encodings.ZapfDingbatsEncoding;
  10746. }
  10747. }
  10748. }
  10749. properties.defaultEncoding = encoding;
  10750. }
  10751. properties.differences = differences;
  10752. properties.baseEncodingName = baseEncodingName;
  10753. properties.dict = dict;
  10754. },
  10755. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10756. var cmap, cmapObj = toUnicode;
  10757. if (isName(cmapObj)) {
  10758. cmap = CMapFactory.create(cmapObj,
  10759. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10760. return new ToUnicodeMap(cmap);
  10761. } else if (isStream(cmapObj)) {
  10762. cmap = CMapFactory.create(cmapObj,
  10763. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10764. // Convert UTF-16BE
  10765. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10766. // to iterate over all keys.
  10767. cmap.forEach(function(token, i) {
  10768. var str = [];
  10769. for (var k = 0; k < token.length; k += 2) {
  10770. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10771. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10772. str.push(w1);
  10773. continue;
  10774. }
  10775. k += 2;
  10776. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10777. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10778. }
  10779. cmap[i] = String.fromCharCode.apply(String, str);
  10780. });
  10781. return new ToUnicodeMap(cmap);
  10782. }
  10783. return null;
  10784. },
  10785. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10786. // Extract the encoding from the CIDToGIDMap
  10787. var glyphsData = cidToGidStream.getBytes();
  10788. // Set encoding 0 to later verify the font has an encoding
  10789. var result = [];
  10790. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10791. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10792. if (glyphID === 0) {
  10793. continue;
  10794. }
  10795. var code = j >> 1;
  10796. result[code] = glyphID;
  10797. }
  10798. return result;
  10799. },
  10800. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10801. descriptor,
  10802. properties) {
  10803. var glyphsWidths = [];
  10804. var defaultWidth = 0;
  10805. var glyphsVMetrics = [];
  10806. var defaultVMetrics;
  10807. var i, ii, j, jj, start, code, widths;
  10808. if (properties.composite) {
  10809. defaultWidth = dict.get('DW') || 1000;
  10810. widths = dict.get('W');
  10811. if (widths) {
  10812. for (i = 0, ii = widths.length; i < ii; i++) {
  10813. start = widths[i++];
  10814. code = xref.fetchIfRef(widths[i]);
  10815. if (isArray(code)) {
  10816. for (j = 0, jj = code.length; j < jj; j++) {
  10817. glyphsWidths[start++] = code[j];
  10818. }
  10819. } else {
  10820. var width = widths[++i];
  10821. for (j = start; j <= code; j++) {
  10822. glyphsWidths[j] = width;
  10823. }
  10824. }
  10825. }
  10826. }
  10827. if (properties.vertical) {
  10828. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10829. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10830. vmetrics = dict.get('W2');
  10831. if (vmetrics) {
  10832. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10833. start = vmetrics[i++];
  10834. code = xref.fetchIfRef(vmetrics[i]);
  10835. if (isArray(code)) {
  10836. for (j = 0, jj = code.length; j < jj; j++) {
  10837. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10838. }
  10839. } else {
  10840. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10841. for (j = start; j <= code; j++) {
  10842. glyphsVMetrics[j] = vmetric;
  10843. }
  10844. }
  10845. }
  10846. }
  10847. }
  10848. } else {
  10849. var firstChar = properties.firstChar;
  10850. widths = dict.get('Widths');
  10851. if (widths) {
  10852. j = firstChar;
  10853. for (i = 0, ii = widths.length; i < ii; i++) {
  10854. glyphsWidths[j++] = widths[i];
  10855. }
  10856. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10857. } else {
  10858. // Trying get the BaseFont metrics (see comment above).
  10859. var baseFontName = dict.get('BaseFont');
  10860. if (isName(baseFontName)) {
  10861. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10862. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10863. properties);
  10864. defaultWidth = metrics.defaultWidth;
  10865. }
  10866. }
  10867. }
  10868. // Heuristic: detection of monospace font by checking all non-zero widths
  10869. var isMonospace = true;
  10870. var firstWidth = defaultWidth;
  10871. for (var glyph in glyphsWidths) {
  10872. var glyphWidth = glyphsWidths[glyph];
  10873. if (!glyphWidth) {
  10874. continue;
  10875. }
  10876. if (!firstWidth) {
  10877. firstWidth = glyphWidth;
  10878. continue;
  10879. }
  10880. if (firstWidth !== glyphWidth) {
  10881. isMonospace = false;
  10882. break;
  10883. }
  10884. }
  10885. if (isMonospace) {
  10886. properties.flags |= FontFlags.FixedPitch;
  10887. }
  10888. properties.defaultWidth = defaultWidth;
  10889. properties.widths = glyphsWidths;
  10890. properties.defaultVMetrics = defaultVMetrics;
  10891. properties.vmetrics = glyphsVMetrics;
  10892. },
  10893. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10894. // Simulating descriptor flags attribute
  10895. var fontNameWoStyle = baseFontName.split('-')[0];
  10896. return (fontNameWoStyle in serifFonts) ||
  10897. (fontNameWoStyle.search(/serif/gi) !== -1);
  10898. },
  10899. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10900. var defaultWidth = 0;
  10901. var widths = [];
  10902. var monospace = false;
  10903. var lookupName = (stdFontMap[name] || name);
  10904. if (!(lookupName in Metrics)) {
  10905. // Use default fonts for looking up font metrics if the passed
  10906. // font is not a base font
  10907. if (this.isSerifFont(name)) {
  10908. lookupName = 'Times-Roman';
  10909. } else {
  10910. lookupName = 'Helvetica';
  10911. }
  10912. }
  10913. var glyphWidths = Metrics[lookupName];
  10914. if (isNum(glyphWidths)) {
  10915. defaultWidth = glyphWidths;
  10916. monospace = true;
  10917. } else {
  10918. widths = glyphWidths;
  10919. }
  10920. return {
  10921. defaultWidth: defaultWidth,
  10922. monospace: monospace,
  10923. widths: widths
  10924. };
  10925. },
  10926. buildCharCodeToWidth:
  10927. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10928. properties) {
  10929. var widths = Object.create(null);
  10930. var differences = properties.differences;
  10931. var encoding = properties.defaultEncoding;
  10932. for (var charCode = 0; charCode < 256; charCode++) {
  10933. if (charCode in differences &&
  10934. widthsByGlyphName[differences[charCode]]) {
  10935. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10936. continue;
  10937. }
  10938. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10939. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10940. continue;
  10941. }
  10942. }
  10943. return widths;
  10944. },
  10945. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10946. var baseDict = dict;
  10947. var type = dict.get('Subtype');
  10948. assert(isName(type), 'invalid font Subtype');
  10949. var composite = false;
  10950. var uint8array;
  10951. if (type.name === 'Type0') {
  10952. // If font is a composite
  10953. // - get the descendant font
  10954. // - set the type according to the descendant font
  10955. // - get the FontDescriptor from the descendant font
  10956. var df = dict.get('DescendantFonts');
  10957. if (!df) {
  10958. error('Descendant fonts are not specified');
  10959. }
  10960. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10961. type = dict.get('Subtype');
  10962. assert(isName(type), 'invalid font Subtype');
  10963. composite = true;
  10964. }
  10965. var descriptor = dict.get('FontDescriptor');
  10966. if (descriptor) {
  10967. var hash = new MurmurHash3_64();
  10968. var encoding = baseDict.getRaw('Encoding');
  10969. if (isName(encoding)) {
  10970. hash.update(encoding.name);
  10971. } else if (isRef(encoding)) {
  10972. hash.update(encoding.num + '_' + encoding.gen);
  10973. }
  10974. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10975. if (isStream(toUnicode)) {
  10976. var stream = toUnicode.str || toUnicode;
  10977. uint8array = stream.buffer ?
  10978. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10979. new Uint8Array(stream.bytes.buffer,
  10980. stream.start, stream.end - stream.start);
  10981. hash.update(uint8array);
  10982. } else if (isName(toUnicode)) {
  10983. hash.update(toUnicode.name);
  10984. }
  10985. var widths = dict.get('Widths') || baseDict.get('Widths');
  10986. if (widths) {
  10987. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10988. hash.update(uint8array);
  10989. }
  10990. }
  10991. return {
  10992. descriptor: descriptor,
  10993. dict: dict,
  10994. baseDict: baseDict,
  10995. composite: composite,
  10996. type: type.name,
  10997. hash: hash ? hash.hexdigest() : ''
  10998. };
  10999. },
  11000. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11001. xref) {
  11002. var baseDict = preEvaluatedFont.baseDict;
  11003. var dict = preEvaluatedFont.dict;
  11004. var composite = preEvaluatedFont.composite;
  11005. var descriptor = preEvaluatedFont.descriptor;
  11006. var type = preEvaluatedFont.type;
  11007. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11008. var properties;
  11009. if (!descriptor) {
  11010. if (type === 'Type3') {
  11011. // FontDescriptor is only required for Type3 fonts when the document
  11012. // is a tagged pdf. Create a barbebones one to get by.
  11013. descriptor = new Dict(null);
  11014. descriptor.set('FontName', Name.get(type));
  11015. } else {
  11016. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11017. // FontDescriptor was not required.
  11018. // This case is here for compatibility.
  11019. var baseFontName = dict.get('BaseFont');
  11020. if (!isName(baseFontName)) {
  11021. error('Base font is not specified');
  11022. }
  11023. // Using base font name as a font name.
  11024. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11025. var metrics = this.getBaseFontMetrics(baseFontName);
  11026. // Simulating descriptor flags attribute
  11027. var fontNameWoStyle = baseFontName.split('-')[0];
  11028. var flags =
  11029. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11030. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11031. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11032. FontFlags.Nonsymbolic);
  11033. properties = {
  11034. type: type,
  11035. name: baseFontName,
  11036. widths: metrics.widths,
  11037. defaultWidth: metrics.defaultWidth,
  11038. flags: flags,
  11039. firstChar: 0,
  11040. lastChar: maxCharIndex
  11041. };
  11042. this.extractDataStructures(dict, dict, xref, properties);
  11043. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11044. properties);
  11045. return new Font(baseFontName, null, properties);
  11046. }
  11047. }
  11048. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11049. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11050. // to ignore this rule when a variant of a standart font is used.
  11051. // TODO Fill the width array depending on which of the base font this is
  11052. // a variant.
  11053. var firstChar = (dict.get('FirstChar') || 0);
  11054. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11055. var fontName = descriptor.get('FontName');
  11056. var baseFont = dict.get('BaseFont');
  11057. // Some bad PDFs have a string as the font name.
  11058. if (isString(fontName)) {
  11059. fontName = Name.get(fontName);
  11060. }
  11061. if (isString(baseFont)) {
  11062. baseFont = Name.get(baseFont);
  11063. }
  11064. if (type !== 'Type3') {
  11065. var fontNameStr = fontName && fontName.name;
  11066. var baseFontStr = baseFont && baseFont.name;
  11067. if (fontNameStr !== baseFontStr) {
  11068. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11069. '" but should be the same as the Font\'s BaseFont "' +
  11070. baseFontStr + '"');
  11071. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11072. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11073. if (fontNameStr && baseFontStr &&
  11074. baseFontStr.indexOf(fontNameStr) === 0) {
  11075. fontName = baseFont;
  11076. }
  11077. }
  11078. }
  11079. fontName = (fontName || baseFont);
  11080. assert(isName(fontName), 'invalid font name');
  11081. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11082. if (fontFile) {
  11083. if (fontFile.dict) {
  11084. var subtype = fontFile.dict.get('Subtype');
  11085. if (subtype) {
  11086. subtype = subtype.name;
  11087. }
  11088. var length1 = fontFile.dict.get('Length1');
  11089. var length2 = fontFile.dict.get('Length2');
  11090. }
  11091. }
  11092. properties = {
  11093. type: type,
  11094. name: fontName.name,
  11095. subtype: subtype,
  11096. file: fontFile,
  11097. length1: length1,
  11098. length2: length2,
  11099. loadedName: baseDict.loadedName,
  11100. composite: composite,
  11101. wideChars: composite,
  11102. fixedPitch: false,
  11103. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11104. firstChar: firstChar || 0,
  11105. lastChar: (lastChar || maxCharIndex),
  11106. bbox: descriptor.get('FontBBox'),
  11107. ascent: descriptor.get('Ascent'),
  11108. descent: descriptor.get('Descent'),
  11109. xHeight: descriptor.get('XHeight'),
  11110. capHeight: descriptor.get('CapHeight'),
  11111. flags: descriptor.get('Flags'),
  11112. italicAngle: descriptor.get('ItalicAngle'),
  11113. coded: false
  11114. };
  11115. if (composite) {
  11116. var cidEncoding = baseDict.get('Encoding');
  11117. if (isName(cidEncoding)) {
  11118. properties.cidEncoding = cidEncoding.name;
  11119. }
  11120. properties.cMap = CMapFactory.create(cidEncoding,
  11121. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11122. properties.vertical = properties.cMap.vertical;
  11123. }
  11124. this.extractDataStructures(dict, baseDict, xref, properties);
  11125. this.extractWidths(dict, xref, descriptor, properties);
  11126. if (type === 'Type3') {
  11127. properties.isType3Font = true;
  11128. }
  11129. return new Font(fontName.name, fontFile, properties);
  11130. }
  11131. };
  11132. return PartialEvaluator;
  11133. })();
  11134. var TranslatedFont = (function TranslatedFontClosure() {
  11135. function TranslatedFont(loadedName, font, dict) {
  11136. this.loadedName = loadedName;
  11137. this.font = font;
  11138. this.dict = dict;
  11139. this.type3Loaded = null;
  11140. this.sent = false;
  11141. }
  11142. TranslatedFont.prototype = {
  11143. send: function (handler) {
  11144. if (this.sent) {
  11145. return;
  11146. }
  11147. var fontData = this.font.exportData();
  11148. handler.send('commonobj', [
  11149. this.loadedName,
  11150. 'Font',
  11151. fontData
  11152. ]);
  11153. this.sent = true;
  11154. },
  11155. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11156. assert(this.font.isType3Font);
  11157. if (this.type3Loaded) {
  11158. return this.type3Loaded;
  11159. }
  11160. var translatedFont = this.font;
  11161. var loadCharProcsPromise = Promise.resolve();
  11162. var charProcs = this.dict.get('CharProcs').getAll();
  11163. var fontResources = this.dict.get('Resources') || resources;
  11164. var charProcKeys = Object.keys(charProcs);
  11165. var charProcOperatorList = {};
  11166. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11167. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11168. var glyphStream = charProcs[key];
  11169. var operatorList = new OperatorList();
  11170. return evaluator.getOperatorList(glyphStream, fontResources,
  11171. operatorList).then(function () {
  11172. charProcOperatorList[key] = operatorList.getIR();
  11173. // Add the dependencies to the parent operator list so they are
  11174. // resolved before sub operator list is executed synchronously.
  11175. parentOperatorList.addDependencies(operatorList.dependencies);
  11176. }, function (reason) {
  11177. warn('Type3 font resource \"' + key + '\" is not available');
  11178. var operatorList = new OperatorList();
  11179. charProcOperatorList[key] = operatorList.getIR();
  11180. });
  11181. }.bind(this, charProcKeys[i]));
  11182. }
  11183. this.type3Loaded = loadCharProcsPromise.then(function () {
  11184. translatedFont.charProcOperatorList = charProcOperatorList;
  11185. });
  11186. return this.type3Loaded;
  11187. }
  11188. };
  11189. return TranslatedFont;
  11190. })();
  11191. var OperatorList = (function OperatorListClosure() {
  11192. var CHUNK_SIZE = 1000;
  11193. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11194. function getTransfers(queue) {
  11195. var transfers = [];
  11196. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11197. for (var i = 0, ii = queue.length; i < ii; i++) {
  11198. switch (fnArray[i]) {
  11199. case OPS.paintInlineImageXObject:
  11200. case OPS.paintInlineImageXObjectGroup:
  11201. case OPS.paintImageMaskXObject:
  11202. var arg = argsArray[i][0]; // first param in imgData
  11203. if (!arg.cached) {
  11204. transfers.push(arg.data.buffer);
  11205. }
  11206. break;
  11207. }
  11208. }
  11209. return transfers;
  11210. }
  11211. function OperatorList(intent, messageHandler, pageIndex) {
  11212. this.messageHandler = messageHandler;
  11213. this.fnArray = [];
  11214. this.argsArray = [];
  11215. this.dependencies = {};
  11216. this.pageIndex = pageIndex;
  11217. this.intent = intent;
  11218. }
  11219. OperatorList.prototype = {
  11220. get length() {
  11221. return this.argsArray.length;
  11222. },
  11223. addOp: function(fn, args) {
  11224. this.fnArray.push(fn);
  11225. this.argsArray.push(args);
  11226. if (this.messageHandler) {
  11227. if (this.fnArray.length >= CHUNK_SIZE) {
  11228. this.flush();
  11229. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11230. (fn === OPS.restore || fn === OPS.endText)) {
  11231. // heuristic to flush on boundary of restore or endText
  11232. this.flush();
  11233. }
  11234. }
  11235. },
  11236. addDependency: function(dependency) {
  11237. if (dependency in this.dependencies) {
  11238. return;
  11239. }
  11240. this.dependencies[dependency] = true;
  11241. this.addOp(OPS.dependency, [dependency]);
  11242. },
  11243. addDependencies: function(dependencies) {
  11244. for (var key in dependencies) {
  11245. this.addDependency(key);
  11246. }
  11247. },
  11248. addOpList: function(opList) {
  11249. Util.extendObj(this.dependencies, opList.dependencies);
  11250. for (var i = 0, ii = opList.length; i < ii; i++) {
  11251. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11252. }
  11253. },
  11254. getIR: function() {
  11255. return {
  11256. fnArray: this.fnArray,
  11257. argsArray: this.argsArray,
  11258. length: this.length
  11259. };
  11260. },
  11261. flush: function(lastChunk) {
  11262. if (this.intent !== 'oplist') {
  11263. new QueueOptimizer().optimize(this);
  11264. }
  11265. var transfers = getTransfers(this);
  11266. this.messageHandler.send('RenderPageChunk', {
  11267. operatorList: {
  11268. fnArray: this.fnArray,
  11269. argsArray: this.argsArray,
  11270. lastChunk: lastChunk,
  11271. length: this.length
  11272. },
  11273. pageIndex: this.pageIndex,
  11274. intent: this.intent
  11275. }, transfers);
  11276. this.dependencies = {};
  11277. this.fnArray.length = 0;
  11278. this.argsArray.length = 0;
  11279. }
  11280. };
  11281. return OperatorList;
  11282. })();
  11283. var StateManager = (function StateManagerClosure() {
  11284. function StateManager(initialState) {
  11285. this.state = initialState;
  11286. this.stateStack = [];
  11287. }
  11288. StateManager.prototype = {
  11289. save: function () {
  11290. var old = this.state;
  11291. this.stateStack.push(this.state);
  11292. this.state = old.clone();
  11293. },
  11294. restore: function () {
  11295. var prev = this.stateStack.pop();
  11296. if (prev) {
  11297. this.state = prev;
  11298. }
  11299. },
  11300. transform: function (args) {
  11301. this.state.ctm = Util.transform(this.state.ctm, args);
  11302. }
  11303. };
  11304. return StateManager;
  11305. })();
  11306. var TextState = (function TextStateClosure() {
  11307. function TextState() {
  11308. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11309. this.fontSize = 0;
  11310. this.font = null;
  11311. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11312. this.textMatrix = IDENTITY_MATRIX.slice();
  11313. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11314. this.charSpacing = 0;
  11315. this.wordSpacing = 0;
  11316. this.leading = 0;
  11317. this.textHScale = 1;
  11318. this.textRise = 0;
  11319. }
  11320. TextState.prototype = {
  11321. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11322. var m = this.textMatrix;
  11323. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11324. },
  11325. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11326. var m = this.textLineMatrix;
  11327. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11328. },
  11329. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11330. var m = this.textMatrix;
  11331. m[4] = m[0] * x + m[2] * y + m[4];
  11332. m[5] = m[1] * x + m[3] * y + m[5];
  11333. },
  11334. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11335. var m = this.textLineMatrix;
  11336. m[4] = m[0] * x + m[2] * y + m[4];
  11337. m[5] = m[1] * x + m[3] * y + m[5];
  11338. },
  11339. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11340. // 9.4.4 Text Space Details
  11341. var tsm = [this.fontSize * this.textHScale, 0,
  11342. 0, this.fontSize,
  11343. 0, this.textRise];
  11344. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11345. },
  11346. carriageReturn: function TextState_carriageReturn() {
  11347. this.translateTextLineMatrix(0, -this.leading);
  11348. this.textMatrix = this.textLineMatrix.slice();
  11349. },
  11350. clone: function TextState_clone() {
  11351. var clone = Object.create(this);
  11352. clone.textMatrix = this.textMatrix.slice();
  11353. clone.textLineMatrix = this.textLineMatrix.slice();
  11354. clone.fontMatrix = this.fontMatrix.slice();
  11355. return clone;
  11356. }
  11357. };
  11358. return TextState;
  11359. })();
  11360. var EvalState = (function EvalStateClosure() {
  11361. function EvalState() {
  11362. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11363. this.font = null;
  11364. this.textRenderingMode = TextRenderingMode.FILL;
  11365. this.fillColorSpace = ColorSpace.singletons.gray;
  11366. this.strokeColorSpace = ColorSpace.singletons.gray;
  11367. }
  11368. EvalState.prototype = {
  11369. clone: function CanvasExtraState_clone() {
  11370. return Object.create(this);
  11371. },
  11372. };
  11373. return EvalState;
  11374. })();
  11375. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11376. // Specifies properties for each command
  11377. //
  11378. // If variableArgs === true: [0, `numArgs`] expected
  11379. // If variableArgs === false: exactly `numArgs` expected
  11380. var OP_MAP = {
  11381. // Graphic state
  11382. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11383. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11384. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11385. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11386. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11387. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11388. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11389. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11390. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11391. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11392. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11393. // Path
  11394. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11395. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11396. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11397. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11398. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11399. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11400. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11401. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11402. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11403. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11404. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11405. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11406. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11407. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11408. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11409. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11410. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11411. // Clipping
  11412. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11413. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11414. // Text
  11415. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11416. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11417. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11418. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11419. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11420. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11421. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11422. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11423. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11424. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11425. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11426. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11427. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11428. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11429. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11430. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11431. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11432. variableArgs: false },
  11433. // Type3 fonts
  11434. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11435. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11436. // Color
  11437. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11438. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11439. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11440. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11441. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11442. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11443. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11444. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11445. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11446. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11447. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11448. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11449. // Shading
  11450. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11451. // Images
  11452. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11453. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11454. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11455. // XObjects
  11456. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11457. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11458. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11459. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11460. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11461. variableArgs: false },
  11462. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11463. // Compatibility
  11464. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11465. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11466. // (reserved partial commands for the lexer)
  11467. BM: null,
  11468. BD: null,
  11469. 'true': null,
  11470. fa: null,
  11471. fal: null,
  11472. fals: null,
  11473. 'false': null,
  11474. nu: null,
  11475. nul: null,
  11476. 'null': null
  11477. };
  11478. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11479. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11480. // dictionary
  11481. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11482. this.stateManager = stateManager;
  11483. this.nonProcessedArgs = [];
  11484. }
  11485. EvaluatorPreprocessor.prototype = {
  11486. get savedStatesDepth() {
  11487. return this.stateManager.stateStack.length;
  11488. },
  11489. // |operation| is an object with two fields:
  11490. //
  11491. // - |fn| is an out param.
  11492. //
  11493. // - |args| is an inout param. On entry, it should have one of two values.
  11494. //
  11495. // - An empty array. This indicates that the caller is providing the
  11496. // array in which the args will be stored in. The caller should use
  11497. // this value if it can reuse a single array for each call to read().
  11498. //
  11499. // - |null|. This indicates that the caller needs this function to create
  11500. // the array in which any args are stored in. If there are zero args,
  11501. // this function will leave |operation.args| as |null| (thus avoiding
  11502. // allocations that would occur if we used an empty array to represent
  11503. // zero arguments). Otherwise, it will replace |null| with a new array
  11504. // containing the arguments. The caller should use this value if it
  11505. // cannot reuse an array for each call to read().
  11506. //
  11507. // These two modes are present because this function is very hot and so
  11508. // avoiding allocations where possible is worthwhile.
  11509. //
  11510. read: function EvaluatorPreprocessor_read(operation) {
  11511. var args = operation.args;
  11512. while (true) {
  11513. var obj = this.parser.getObj();
  11514. if (isCmd(obj)) {
  11515. var cmd = obj.cmd;
  11516. // Check that the command is valid
  11517. var opSpec = OP_MAP[cmd];
  11518. if (!opSpec) {
  11519. warn('Unknown command "' + cmd + '"');
  11520. continue;
  11521. }
  11522. var fn = opSpec.id;
  11523. var numArgs = opSpec.numArgs;
  11524. var argsLength = args !== null ? args.length : 0;
  11525. if (!opSpec.variableArgs) {
  11526. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11527. if (argsLength !== numArgs) {
  11528. var nonProcessedArgs = this.nonProcessedArgs;
  11529. while (argsLength > numArgs) {
  11530. nonProcessedArgs.push(args.shift());
  11531. argsLength--;
  11532. }
  11533. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11534. if (!args) {
  11535. args = [];
  11536. }
  11537. args.unshift(nonProcessedArgs.pop());
  11538. argsLength++;
  11539. }
  11540. }
  11541. if (argsLength < numArgs) {
  11542. // If we receive too few args, it's not possible to possible
  11543. // to execute the command, so skip the command
  11544. info('Command ' + fn + ': because expected ' +
  11545. numArgs + ' args, but received ' + argsLength +
  11546. ' args; skipping');
  11547. args = null;
  11548. continue;
  11549. }
  11550. } else if (argsLength > numArgs) {
  11551. info('Command ' + fn + ': expected [0,' + numArgs +
  11552. '] args, but received ' + argsLength + ' args');
  11553. }
  11554. // TODO figure out how to type-check vararg functions
  11555. this.preprocessCommand(fn, args);
  11556. operation.fn = fn;
  11557. operation.args = args;
  11558. return true;
  11559. } else {
  11560. if (isEOF(obj)) {
  11561. return false; // no more commands
  11562. }
  11563. // argument
  11564. if (obj !== null) {
  11565. if (!args) {
  11566. args = [];
  11567. }
  11568. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11569. assert(args.length <= 33, 'Too many arguments');
  11570. }
  11571. }
  11572. }
  11573. },
  11574. preprocessCommand:
  11575. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11576. switch (fn | 0) {
  11577. case OPS.save:
  11578. this.stateManager.save();
  11579. break;
  11580. case OPS.restore:
  11581. this.stateManager.restore();
  11582. break;
  11583. case OPS.transform:
  11584. this.stateManager.transform(args);
  11585. break;
  11586. }
  11587. }
  11588. };
  11589. return EvaluatorPreprocessor;
  11590. })();
  11591. var QueueOptimizer = (function QueueOptimizerClosure() {
  11592. function addState(parentState, pattern, fn) {
  11593. var state = parentState;
  11594. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11595. var item = pattern[i];
  11596. state = (state[item] || (state[item] = []));
  11597. }
  11598. state[pattern[pattern.length - 1]] = fn;
  11599. }
  11600. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11601. argsArray) {
  11602. // Handles special case of mainly LaTeX documents which use image masks to
  11603. // draw lines with the current fill style.
  11604. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11605. // have been found at iFirstSave.
  11606. var iFirstPIMXO = iFirstSave + 2;
  11607. for (var i = 0; i < count; i++) {
  11608. var arg = argsArray[iFirstPIMXO + 4 * i];
  11609. var imageMask = arg.length === 1 && arg[0];
  11610. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11611. (!imageMask.data.length ||
  11612. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11613. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11614. continue;
  11615. }
  11616. break;
  11617. }
  11618. return count - i;
  11619. }
  11620. var InitialState = [];
  11621. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11622. // sequences with one |paintInlineImageXObjectGroup| operation.
  11623. addState(InitialState,
  11624. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11625. function foundInlineImageGroup(context) {
  11626. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11627. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11628. var MAX_WIDTH = 1000;
  11629. var IMAGE_PADDING = 1;
  11630. var fnArray = context.fnArray, argsArray = context.argsArray;
  11631. var curr = context.iCurr;
  11632. var iFirstSave = curr - 3;
  11633. var iFirstTransform = curr - 2;
  11634. var iFirstPIIXO = curr - 1;
  11635. // Look for the quartets.
  11636. var i = iFirstSave + 4;
  11637. var ii = fnArray.length;
  11638. while (i + 3 < ii) {
  11639. if (fnArray[i] !== OPS.save ||
  11640. fnArray[i + 1] !== OPS.transform ||
  11641. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11642. fnArray[i + 3] !== OPS.restore) {
  11643. break; // ops don't match
  11644. }
  11645. i += 4;
  11646. }
  11647. // At this point, i is the index of the first op past the last valid
  11648. // quartet.
  11649. var count = Math.min((i - iFirstSave) / 4,
  11650. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11651. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11652. return i;
  11653. }
  11654. // assuming that heights of those image is too small (~1 pixel)
  11655. // packing as much as possible by lines
  11656. var maxX = 0;
  11657. var map = [], maxLineHeight = 0;
  11658. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11659. var q;
  11660. for (q = 0; q < count; q++) {
  11661. var transform = argsArray[iFirstTransform + (q << 2)];
  11662. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11663. if (currentX + img.width > MAX_WIDTH) {
  11664. // starting new line
  11665. maxX = Math.max(maxX, currentX);
  11666. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11667. currentX = 0;
  11668. maxLineHeight = 0;
  11669. }
  11670. map.push({
  11671. transform: transform,
  11672. x: currentX, y: currentY,
  11673. w: img.width, h: img.height
  11674. });
  11675. currentX += img.width + 2 * IMAGE_PADDING;
  11676. maxLineHeight = Math.max(maxLineHeight, img.height);
  11677. }
  11678. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11679. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11680. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11681. var imgRowSize = imgWidth << 2;
  11682. for (q = 0; q < count; q++) {
  11683. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11684. // Copy image by lines and extends pixels into padding.
  11685. var rowSize = map[q].w << 2;
  11686. var dataOffset = 0;
  11687. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11688. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11689. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11690. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11691. dataOffset += rowSize;
  11692. offset += imgRowSize;
  11693. }
  11694. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11695. while (offset >= 0) {
  11696. data[offset - 4] = data[offset];
  11697. data[offset - 3] = data[offset + 1];
  11698. data[offset - 2] = data[offset + 2];
  11699. data[offset - 1] = data[offset + 3];
  11700. data[offset + rowSize] = data[offset + rowSize - 4];
  11701. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11702. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11703. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11704. offset -= imgRowSize;
  11705. }
  11706. }
  11707. // Replace queue items.
  11708. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11709. argsArray.splice(iFirstSave, count * 4,
  11710. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11711. data: imgData }, map]);
  11712. return iFirstSave + 1;
  11713. });
  11714. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11715. // sequences with one |paintImageMaskXObjectGroup| or one
  11716. // |paintImageMaskXObjectRepeat| operation.
  11717. addState(InitialState,
  11718. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11719. function foundImageMaskGroup(context) {
  11720. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11721. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11722. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11723. var fnArray = context.fnArray, argsArray = context.argsArray;
  11724. var curr = context.iCurr;
  11725. var iFirstSave = curr - 3;
  11726. var iFirstTransform = curr - 2;
  11727. var iFirstPIMXO = curr - 1;
  11728. // Look for the quartets.
  11729. var i = iFirstSave + 4;
  11730. var ii = fnArray.length;
  11731. while (i + 3 < ii) {
  11732. if (fnArray[i] !== OPS.save ||
  11733. fnArray[i + 1] !== OPS.transform ||
  11734. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11735. fnArray[i + 3] !== OPS.restore) {
  11736. break; // ops don't match
  11737. }
  11738. i += 4;
  11739. }
  11740. // At this point, i is the index of the first op past the last valid
  11741. // quartet.
  11742. var count = (i - iFirstSave) / 4;
  11743. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11744. argsArray);
  11745. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11746. return i;
  11747. }
  11748. var q;
  11749. var isSameImage = false;
  11750. var iTransform, transformArgs;
  11751. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11752. if (argsArray[iFirstTransform][1] === 0 &&
  11753. argsArray[iFirstTransform][2] === 0) {
  11754. isSameImage = true;
  11755. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11756. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11757. iTransform = iFirstTransform + 4;
  11758. var iPIMXO = iFirstPIMXO + 4;
  11759. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11760. transformArgs = argsArray[iTransform];
  11761. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11762. transformArgs[0] !== firstTransformArg0 ||
  11763. transformArgs[1] !== 0 ||
  11764. transformArgs[2] !== 0 ||
  11765. transformArgs[3] !== firstTransformArg3) {
  11766. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11767. isSameImage = false;
  11768. } else {
  11769. count = q;
  11770. }
  11771. break; // different image or transform
  11772. }
  11773. }
  11774. }
  11775. if (isSameImage) {
  11776. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11777. var positions = new Float32Array(count * 2);
  11778. iTransform = iFirstTransform;
  11779. for (q = 0; q < count; q++, iTransform += 4) {
  11780. transformArgs = argsArray[iTransform];
  11781. positions[(q << 1)] = transformArgs[4];
  11782. positions[(q << 1) + 1] = transformArgs[5];
  11783. }
  11784. // Replace queue items.
  11785. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11786. argsArray.splice(iFirstSave, count * 4,
  11787. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11788. } else {
  11789. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11790. var images = [];
  11791. for (q = 0; q < count; q++) {
  11792. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11793. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11794. images.push({ data: maskParams.data, width: maskParams.width,
  11795. height: maskParams.height,
  11796. transform: transformArgs });
  11797. }
  11798. // Replace queue items.
  11799. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11800. argsArray.splice(iFirstSave, count * 4, [images]);
  11801. }
  11802. return iFirstSave + 1;
  11803. });
  11804. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11805. // with one paintImageXObjectRepeat operation, if the |transform| and
  11806. // |paintImageXObjectRepeat| ops are appropriate.
  11807. addState(InitialState,
  11808. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11809. function (context) {
  11810. var MIN_IMAGES_IN_BLOCK = 3;
  11811. var MAX_IMAGES_IN_BLOCK = 1000;
  11812. var fnArray = context.fnArray, argsArray = context.argsArray;
  11813. var curr = context.iCurr;
  11814. var iFirstSave = curr - 3;
  11815. var iFirstTransform = curr - 2;
  11816. var iFirstPIXO = curr - 1;
  11817. var iFirstRestore = curr;
  11818. if (argsArray[iFirstTransform][1] !== 0 ||
  11819. argsArray[iFirstTransform][2] !== 0) {
  11820. return iFirstRestore + 1; // transform has the wrong form
  11821. }
  11822. // Look for the quartets.
  11823. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11824. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11825. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11826. var i = iFirstSave + 4;
  11827. var ii = fnArray.length;
  11828. while (i + 3 < ii) {
  11829. if (fnArray[i] !== OPS.save ||
  11830. fnArray[i + 1] !== OPS.transform ||
  11831. fnArray[i + 2] !== OPS.paintImageXObject ||
  11832. fnArray[i + 3] !== OPS.restore) {
  11833. break; // ops don't match
  11834. }
  11835. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11836. argsArray[i + 1][1] !== 0 ||
  11837. argsArray[i + 1][2] !== 0 ||
  11838. argsArray[i + 1][3] !== firstTransformArg3) {
  11839. break; // transforms don't match
  11840. }
  11841. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11842. break; // images don't match
  11843. }
  11844. i += 4;
  11845. }
  11846. // At this point, i is the index of the first op past the last valid
  11847. // quartet.
  11848. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11849. if (count < MIN_IMAGES_IN_BLOCK) {
  11850. return i;
  11851. }
  11852. // Extract the (x,y) positions from all of the matching transforms.
  11853. var positions = new Float32Array(count * 2);
  11854. var iTransform = iFirstTransform;
  11855. for (var q = 0; q < count; q++, iTransform += 4) {
  11856. var transformArgs = argsArray[iTransform];
  11857. positions[(q << 1)] = transformArgs[4];
  11858. positions[(q << 1) + 1] = transformArgs[5];
  11859. }
  11860. // Replace queue items.
  11861. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11862. positions];
  11863. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11864. argsArray.splice(iFirstSave, count * 4, args);
  11865. return iFirstSave + 1;
  11866. });
  11867. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11868. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11869. // sequences, if the font for each one is the same.
  11870. addState(InitialState,
  11871. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11872. function (context) {
  11873. var MIN_CHARS_IN_BLOCK = 3;
  11874. var MAX_CHARS_IN_BLOCK = 1000;
  11875. var fnArray = context.fnArray, argsArray = context.argsArray;
  11876. var curr = context.iCurr;
  11877. var iFirstBeginText = curr - 4;
  11878. var iFirstSetFont = curr - 3;
  11879. var iFirstSetTextMatrix = curr - 2;
  11880. var iFirstShowText = curr - 1;
  11881. var iFirstEndText = curr;
  11882. // Look for the quintets.
  11883. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11884. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11885. var i = iFirstBeginText + 5;
  11886. var ii = fnArray.length;
  11887. while (i + 4 < ii) {
  11888. if (fnArray[i] !== OPS.beginText ||
  11889. fnArray[i + 1] !== OPS.setFont ||
  11890. fnArray[i + 2] !== OPS.setTextMatrix ||
  11891. fnArray[i + 3] !== OPS.showText ||
  11892. fnArray[i + 4] !== OPS.endText) {
  11893. break; // ops don't match
  11894. }
  11895. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11896. argsArray[i + 1][1] !== firstSetFontArg1) {
  11897. break; // fonts don't match
  11898. }
  11899. i += 5;
  11900. }
  11901. // At this point, i is the index of the first op past the last valid
  11902. // quintet.
  11903. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11904. if (count < MIN_CHARS_IN_BLOCK) {
  11905. return i;
  11906. }
  11907. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11908. // showText, endText), include that as well. (E.g. <something> might be
  11909. // |dependency|.)
  11910. var iFirst = iFirstBeginText;
  11911. if (iFirstBeginText >= 4 &&
  11912. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11913. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11914. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11915. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11916. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11917. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11918. count++;
  11919. iFirst -= 5;
  11920. }
  11921. // Remove (endText, beginText, setFont) trios.
  11922. var iEndText = iFirst + 4;
  11923. for (var q = 1; q < count; q++) {
  11924. fnArray.splice(iEndText, 3);
  11925. argsArray.splice(iEndText, 3);
  11926. iEndText += 2;
  11927. }
  11928. return iEndText + 1;
  11929. });
  11930. function QueueOptimizer() {}
  11931. QueueOptimizer.prototype = {
  11932. optimize: function QueueOptimizer_optimize(queue) {
  11933. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11934. var context = {
  11935. iCurr: 0,
  11936. fnArray: fnArray,
  11937. argsArray: argsArray
  11938. };
  11939. var state;
  11940. var i = 0, ii = fnArray.length;
  11941. while (i < ii) {
  11942. state = (state || InitialState)[fnArray[i]];
  11943. if (typeof state === 'function') { // we found some handler
  11944. context.iCurr = i;
  11945. // state() returns the index of the first non-matching op (if we
  11946. // didn't match) or the first op past the modified ops (if we did
  11947. // match and replace).
  11948. i = state(context);
  11949. state = undefined; // reset the state machine
  11950. ii = context.fnArray.length;
  11951. } else {
  11952. i++;
  11953. }
  11954. }
  11955. }
  11956. };
  11957. return QueueOptimizer;
  11958. })();
  11959. var BUILT_IN_CMAPS = [
  11960. // << Start unicode maps.
  11961. 'Adobe-GB1-UCS2',
  11962. 'Adobe-CNS1-UCS2',
  11963. 'Adobe-Japan1-UCS2',
  11964. 'Adobe-Korea1-UCS2',
  11965. // >> End unicode maps.
  11966. '78-EUC-H',
  11967. '78-EUC-V',
  11968. '78-H',
  11969. '78-RKSJ-H',
  11970. '78-RKSJ-V',
  11971. '78-V',
  11972. '78ms-RKSJ-H',
  11973. '78ms-RKSJ-V',
  11974. '83pv-RKSJ-H',
  11975. '90ms-RKSJ-H',
  11976. '90ms-RKSJ-V',
  11977. '90msp-RKSJ-H',
  11978. '90msp-RKSJ-V',
  11979. '90pv-RKSJ-H',
  11980. '90pv-RKSJ-V',
  11981. 'Add-H',
  11982. 'Add-RKSJ-H',
  11983. 'Add-RKSJ-V',
  11984. 'Add-V',
  11985. 'Adobe-CNS1-0',
  11986. 'Adobe-CNS1-1',
  11987. 'Adobe-CNS1-2',
  11988. 'Adobe-CNS1-3',
  11989. 'Adobe-CNS1-4',
  11990. 'Adobe-CNS1-5',
  11991. 'Adobe-CNS1-6',
  11992. 'Adobe-GB1-0',
  11993. 'Adobe-GB1-1',
  11994. 'Adobe-GB1-2',
  11995. 'Adobe-GB1-3',
  11996. 'Adobe-GB1-4',
  11997. 'Adobe-GB1-5',
  11998. 'Adobe-Japan1-0',
  11999. 'Adobe-Japan1-1',
  12000. 'Adobe-Japan1-2',
  12001. 'Adobe-Japan1-3',
  12002. 'Adobe-Japan1-4',
  12003. 'Adobe-Japan1-5',
  12004. 'Adobe-Japan1-6',
  12005. 'Adobe-Korea1-0',
  12006. 'Adobe-Korea1-1',
  12007. 'Adobe-Korea1-2',
  12008. 'B5-H',
  12009. 'B5-V',
  12010. 'B5pc-H',
  12011. 'B5pc-V',
  12012. 'CNS-EUC-H',
  12013. 'CNS-EUC-V',
  12014. 'CNS1-H',
  12015. 'CNS1-V',
  12016. 'CNS2-H',
  12017. 'CNS2-V',
  12018. 'ETHK-B5-H',
  12019. 'ETHK-B5-V',
  12020. 'ETen-B5-H',
  12021. 'ETen-B5-V',
  12022. 'ETenms-B5-H',
  12023. 'ETenms-B5-V',
  12024. 'EUC-H',
  12025. 'EUC-V',
  12026. 'Ext-H',
  12027. 'Ext-RKSJ-H',
  12028. 'Ext-RKSJ-V',
  12029. 'Ext-V',
  12030. 'GB-EUC-H',
  12031. 'GB-EUC-V',
  12032. 'GB-H',
  12033. 'GB-V',
  12034. 'GBK-EUC-H',
  12035. 'GBK-EUC-V',
  12036. 'GBK2K-H',
  12037. 'GBK2K-V',
  12038. 'GBKp-EUC-H',
  12039. 'GBKp-EUC-V',
  12040. 'GBT-EUC-H',
  12041. 'GBT-EUC-V',
  12042. 'GBT-H',
  12043. 'GBT-V',
  12044. 'GBTpc-EUC-H',
  12045. 'GBTpc-EUC-V',
  12046. 'GBpc-EUC-H',
  12047. 'GBpc-EUC-V',
  12048. 'H',
  12049. 'HKdla-B5-H',
  12050. 'HKdla-B5-V',
  12051. 'HKdlb-B5-H',
  12052. 'HKdlb-B5-V',
  12053. 'HKgccs-B5-H',
  12054. 'HKgccs-B5-V',
  12055. 'HKm314-B5-H',
  12056. 'HKm314-B5-V',
  12057. 'HKm471-B5-H',
  12058. 'HKm471-B5-V',
  12059. 'HKscs-B5-H',
  12060. 'HKscs-B5-V',
  12061. 'Hankaku',
  12062. 'Hiragana',
  12063. 'KSC-EUC-H',
  12064. 'KSC-EUC-V',
  12065. 'KSC-H',
  12066. 'KSC-Johab-H',
  12067. 'KSC-Johab-V',
  12068. 'KSC-V',
  12069. 'KSCms-UHC-H',
  12070. 'KSCms-UHC-HW-H',
  12071. 'KSCms-UHC-HW-V',
  12072. 'KSCms-UHC-V',
  12073. 'KSCpc-EUC-H',
  12074. 'KSCpc-EUC-V',
  12075. 'Katakana',
  12076. 'NWP-H',
  12077. 'NWP-V',
  12078. 'RKSJ-H',
  12079. 'RKSJ-V',
  12080. 'Roman',
  12081. 'UniCNS-UCS2-H',
  12082. 'UniCNS-UCS2-V',
  12083. 'UniCNS-UTF16-H',
  12084. 'UniCNS-UTF16-V',
  12085. 'UniCNS-UTF32-H',
  12086. 'UniCNS-UTF32-V',
  12087. 'UniCNS-UTF8-H',
  12088. 'UniCNS-UTF8-V',
  12089. 'UniGB-UCS2-H',
  12090. 'UniGB-UCS2-V',
  12091. 'UniGB-UTF16-H',
  12092. 'UniGB-UTF16-V',
  12093. 'UniGB-UTF32-H',
  12094. 'UniGB-UTF32-V',
  12095. 'UniGB-UTF8-H',
  12096. 'UniGB-UTF8-V',
  12097. 'UniJIS-UCS2-H',
  12098. 'UniJIS-UCS2-HW-H',
  12099. 'UniJIS-UCS2-HW-V',
  12100. 'UniJIS-UCS2-V',
  12101. 'UniJIS-UTF16-H',
  12102. 'UniJIS-UTF16-V',
  12103. 'UniJIS-UTF32-H',
  12104. 'UniJIS-UTF32-V',
  12105. 'UniJIS-UTF8-H',
  12106. 'UniJIS-UTF8-V',
  12107. 'UniJIS2004-UTF16-H',
  12108. 'UniJIS2004-UTF16-V',
  12109. 'UniJIS2004-UTF32-H',
  12110. 'UniJIS2004-UTF32-V',
  12111. 'UniJIS2004-UTF8-H',
  12112. 'UniJIS2004-UTF8-V',
  12113. 'UniJISPro-UCS2-HW-V',
  12114. 'UniJISPro-UCS2-V',
  12115. 'UniJISPro-UTF8-V',
  12116. 'UniJISX0213-UTF32-H',
  12117. 'UniJISX0213-UTF32-V',
  12118. 'UniJISX02132004-UTF32-H',
  12119. 'UniJISX02132004-UTF32-V',
  12120. 'UniKS-UCS2-H',
  12121. 'UniKS-UCS2-V',
  12122. 'UniKS-UTF16-H',
  12123. 'UniKS-UTF16-V',
  12124. 'UniKS-UTF32-H',
  12125. 'UniKS-UTF32-V',
  12126. 'UniKS-UTF8-H',
  12127. 'UniKS-UTF8-V',
  12128. 'V',
  12129. 'WP-Symbol'];
  12130. // CMap, not to be confused with TrueType's cmap.
  12131. var CMap = (function CMapClosure() {
  12132. function CMap(builtInCMap) {
  12133. // Codespace ranges are stored as follows:
  12134. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12135. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12136. this.codespaceRanges = [[], [], [], []];
  12137. this.numCodespaceRanges = 0;
  12138. // Map entries have one of two forms.
  12139. // - cid chars are 16-bit unsigned integers, stored as integers.
  12140. // - bf chars are variable-length byte sequences, stored as strings, with
  12141. // one byte per character.
  12142. this._map = [];
  12143. this.vertical = false;
  12144. this.useCMap = null;
  12145. this.builtInCMap = builtInCMap;
  12146. }
  12147. CMap.prototype = {
  12148. addCodespaceRange: function(n, low, high) {
  12149. this.codespaceRanges[n - 1].push(low, high);
  12150. this.numCodespaceRanges++;
  12151. },
  12152. mapCidRange: function(low, high, dstLow) {
  12153. while (low <= high) {
  12154. this._map[low++] = dstLow++;
  12155. }
  12156. },
  12157. mapBfRange: function(low, high, dstLow) {
  12158. var lastByte = dstLow.length - 1;
  12159. while (low <= high) {
  12160. this._map[low++] = dstLow;
  12161. // Only the last byte has to be incremented.
  12162. dstLow = dstLow.substr(0, lastByte) +
  12163. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12164. }
  12165. },
  12166. mapBfRangeToArray: function(low, high, array) {
  12167. var i = 0, ii = array.length;
  12168. while (low <= high && i < ii) {
  12169. this._map[low] = array[i++];
  12170. ++low;
  12171. }
  12172. },
  12173. // This is used for both bf and cid chars.
  12174. mapOne: function(src, dst) {
  12175. this._map[src] = dst;
  12176. },
  12177. lookup: function(code) {
  12178. return this._map[code];
  12179. },
  12180. contains: function(code) {
  12181. return this._map[code] !== undefined;
  12182. },
  12183. forEach: function(callback) {
  12184. // Most maps have fewer than 65536 entries, and for those we use normal
  12185. // array iteration. But really sparse tables are possible -- e.g. with
  12186. // indices in the *billions*. For such tables we use for..in, which isn't
  12187. // ideal because it stringifies the indices for all present elements, but
  12188. // it does avoid iterating over every undefined entry.
  12189. var map = this._map;
  12190. var length = map.length;
  12191. var i;
  12192. if (length <= 0x10000) {
  12193. for (i = 0; i < length; i++) {
  12194. if (map[i] !== undefined) {
  12195. callback(i, map[i]);
  12196. }
  12197. }
  12198. } else {
  12199. for (i in this._map) {
  12200. callback(i, map[i]);
  12201. }
  12202. }
  12203. },
  12204. charCodeOf: function(value) {
  12205. return this._map.indexOf(value);
  12206. },
  12207. getMap: function() {
  12208. return this._map;
  12209. },
  12210. readCharCode: function(str, offset, out) {
  12211. var c = 0;
  12212. var codespaceRanges = this.codespaceRanges;
  12213. var codespaceRangesLen = this.codespaceRanges.length;
  12214. // 9.7.6.2 CMap Mapping
  12215. // The code length is at most 4.
  12216. for (var n = 0; n < codespaceRangesLen; n++) {
  12217. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12218. // Check each codespace range to see if it falls within.
  12219. var codespaceRange = codespaceRanges[n];
  12220. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12221. var low = codespaceRange[k++];
  12222. var high = codespaceRange[k++];
  12223. if (c >= low && c <= high) {
  12224. out.charcode = c;
  12225. out.length = n + 1;
  12226. return;
  12227. }
  12228. }
  12229. }
  12230. out.charcode = 0;
  12231. out.length = 1;
  12232. }
  12233. };
  12234. return CMap;
  12235. })();
  12236. // A special case of CMap, where the _map array implicitly has a length of
  12237. // 65535 and each element is equal to its index.
  12238. var IdentityCMap = (function IdentityCMapClosure() {
  12239. function IdentityCMap(vertical, n) {
  12240. CMap.call(this);
  12241. this.vertical = vertical;
  12242. this.addCodespaceRange(n, 0, 0xffff);
  12243. }
  12244. Util.inherit(IdentityCMap, CMap, {});
  12245. IdentityCMap.prototype = {
  12246. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12247. mapCidRange: function(low, high, dstLow) {
  12248. error('should not call mapCidRange');
  12249. },
  12250. mapBfRange: function(low, high, dstLow) {
  12251. error('should not call mapBfRange');
  12252. },
  12253. mapBfRangeToArray: function(low, high, array) {
  12254. error('should not call mapBfRangeToArray');
  12255. },
  12256. mapOne: function(src, dst) {
  12257. error('should not call mapCidOne');
  12258. },
  12259. lookup: function(code) {
  12260. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12261. },
  12262. contains: function(code) {
  12263. return isInt(code) && code <= 0xffff;
  12264. },
  12265. forEach: function(callback) {
  12266. for (var i = 0; i <= 0xffff; i++) {
  12267. callback(i, i);
  12268. }
  12269. },
  12270. charCodeOf: function(value) {
  12271. return (isInt(value) && value <= 0xffff) ? value : -1;
  12272. },
  12273. getMap: function() {
  12274. // Sometimes identity maps must be instantiated, but it's rare.
  12275. var map = new Array(0x10000);
  12276. for (var i = 0; i <= 0xffff; i++) {
  12277. map[i] = i;
  12278. }
  12279. return map;
  12280. },
  12281. readCharCode: CMap.prototype.readCharCode
  12282. };
  12283. return IdentityCMap;
  12284. })();
  12285. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12286. function fetchBinaryData(url) {
  12287. var nonBinaryRequest = PDFJS.disableWorker;
  12288. var request = new XMLHttpRequest();
  12289. request.open('GET', url, false);
  12290. if (!nonBinaryRequest) {
  12291. try {
  12292. request.responseType = 'arraybuffer';
  12293. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12294. } catch (e) {
  12295. nonBinaryRequest = true;
  12296. }
  12297. }
  12298. if (nonBinaryRequest && request.overrideMimeType) {
  12299. request.overrideMimeType('text/plain; charset=x-user-defined');
  12300. }
  12301. request.send(null);
  12302. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12303. error('Unable to get binary cMap at: ' + url);
  12304. }
  12305. if (nonBinaryRequest) {
  12306. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12307. return ch.charCodeAt(0) & 255;
  12308. });
  12309. return new Uint8Array(data);
  12310. }
  12311. return new Uint8Array(request.response);
  12312. }
  12313. function hexToInt(a, size) {
  12314. var n = 0;
  12315. for (var i = 0; i <= size; i++) {
  12316. n = (n << 8) | a[i];
  12317. }
  12318. return n >>> 0;
  12319. }
  12320. function hexToStr(a, size) {
  12321. // This code is hot. Special-case some common values to avoid creating an
  12322. // object with subarray().
  12323. if (size === 1) {
  12324. return String.fromCharCode(a[0], a[1]);
  12325. }
  12326. if (size === 3) {
  12327. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12328. }
  12329. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12330. }
  12331. function addHex(a, b, size) {
  12332. var c = 0;
  12333. for (var i = size; i >= 0; i--) {
  12334. c += a[i] + b[i];
  12335. a[i] = c & 255;
  12336. c >>= 8;
  12337. }
  12338. }
  12339. function incHex(a, size) {
  12340. var c = 1;
  12341. for (var i = size; i >= 0 && c > 0; i--) {
  12342. c += a[i];
  12343. a[i] = c & 255;
  12344. c >>= 8;
  12345. }
  12346. }
  12347. var MAX_NUM_SIZE = 16;
  12348. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12349. function BinaryCMapStream(data) {
  12350. this.buffer = data;
  12351. this.pos = 0;
  12352. this.end = data.length;
  12353. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12354. }
  12355. BinaryCMapStream.prototype = {
  12356. readByte: function () {
  12357. if (this.pos >= this.end) {
  12358. return -1;
  12359. }
  12360. return this.buffer[this.pos++];
  12361. },
  12362. readNumber: function () {
  12363. var n = 0;
  12364. var last;
  12365. do {
  12366. var b = this.readByte();
  12367. if (b < 0) {
  12368. error('unexpected EOF in bcmap');
  12369. }
  12370. last = !(b & 0x80);
  12371. n = (n << 7) | (b & 0x7F);
  12372. } while (!last);
  12373. return n;
  12374. },
  12375. readSigned: function () {
  12376. var n = this.readNumber();
  12377. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12378. },
  12379. readHex: function (num, size) {
  12380. num.set(this.buffer.subarray(this.pos,
  12381. this.pos + size + 1));
  12382. this.pos += size + 1;
  12383. },
  12384. readHexNumber: function (num, size) {
  12385. var last;
  12386. var stack = this.tmpBuf, sp = 0;
  12387. do {
  12388. var b = this.readByte();
  12389. if (b < 0) {
  12390. error('unexpected EOF in bcmap');
  12391. }
  12392. last = !(b & 0x80);
  12393. stack[sp++] = b & 0x7F;
  12394. } while (!last);
  12395. var i = size, buffer = 0, bufferSize = 0;
  12396. while (i >= 0) {
  12397. while (bufferSize < 8 && stack.length > 0) {
  12398. buffer = (stack[--sp] << bufferSize) | buffer;
  12399. bufferSize += 7;
  12400. }
  12401. num[i] = buffer & 255;
  12402. i--;
  12403. buffer >>= 8;
  12404. bufferSize -= 8;
  12405. }
  12406. },
  12407. readHexSigned: function (num, size) {
  12408. this.readHexNumber(num, size);
  12409. var sign = num[size] & 1 ? 255 : 0;
  12410. var c = 0;
  12411. for (var i = 0; i <= size; i++) {
  12412. c = ((c & 1) << 8) | num[i];
  12413. num[i] = (c >> 1) ^ sign;
  12414. }
  12415. },
  12416. readString: function () {
  12417. var len = this.readNumber();
  12418. var s = '';
  12419. for (var i = 0; i < len; i++) {
  12420. s += String.fromCharCode(this.readNumber());
  12421. }
  12422. return s;
  12423. }
  12424. };
  12425. function processBinaryCMap(url, cMap, extend) {
  12426. var data = fetchBinaryData(url);
  12427. var stream = new BinaryCMapStream(data);
  12428. var header = stream.readByte();
  12429. cMap.vertical = !!(header & 1);
  12430. var useCMap = null;
  12431. var start = new Uint8Array(MAX_NUM_SIZE);
  12432. var end = new Uint8Array(MAX_NUM_SIZE);
  12433. var char = new Uint8Array(MAX_NUM_SIZE);
  12434. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12435. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12436. var code;
  12437. var b;
  12438. while ((b = stream.readByte()) >= 0) {
  12439. var type = b >> 5;
  12440. if (type === 7) { // metadata, e.g. comment or usecmap
  12441. switch (b & 0x1F) {
  12442. case 0:
  12443. stream.readString(); // skipping comment
  12444. break;
  12445. case 1:
  12446. useCMap = stream.readString();
  12447. break;
  12448. }
  12449. continue;
  12450. }
  12451. var sequence = !!(b & 0x10);
  12452. var dataSize = b & 15;
  12453. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12454. var ucs2DataSize = 1;
  12455. var subitemsCount = stream.readNumber();
  12456. var i;
  12457. switch (type) {
  12458. case 0: // codespacerange
  12459. stream.readHex(start, dataSize);
  12460. stream.readHexNumber(end, dataSize);
  12461. addHex(end, start, dataSize);
  12462. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12463. hexToInt(end, dataSize));
  12464. for (i = 1; i < subitemsCount; i++) {
  12465. incHex(end, dataSize);
  12466. stream.readHexNumber(start, dataSize);
  12467. addHex(start, end, dataSize);
  12468. stream.readHexNumber(end, dataSize);
  12469. addHex(end, start, dataSize);
  12470. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12471. hexToInt(end, dataSize));
  12472. }
  12473. break;
  12474. case 1: // notdefrange
  12475. stream.readHex(start, dataSize);
  12476. stream.readHexNumber(end, dataSize);
  12477. addHex(end, start, dataSize);
  12478. code = stream.readNumber();
  12479. // undefined range, skipping
  12480. for (i = 1; i < subitemsCount; i++) {
  12481. incHex(end, dataSize);
  12482. stream.readHexNumber(start, dataSize);
  12483. addHex(start, end, dataSize);
  12484. stream.readHexNumber(end, dataSize);
  12485. addHex(end, start, dataSize);
  12486. code = stream.readNumber();
  12487. // nop
  12488. }
  12489. break;
  12490. case 2: // cidchar
  12491. stream.readHex(char, dataSize);
  12492. code = stream.readNumber();
  12493. cMap.mapOne(hexToInt(char, dataSize), code);
  12494. for (i = 1; i < subitemsCount; i++) {
  12495. incHex(char, dataSize);
  12496. if (!sequence) {
  12497. stream.readHexNumber(tmp, dataSize);
  12498. addHex(char, tmp, dataSize);
  12499. }
  12500. code = stream.readSigned() + (code + 1);
  12501. cMap.mapOne(hexToInt(char, dataSize), code);
  12502. }
  12503. break;
  12504. case 3: // cidrange
  12505. stream.readHex(start, dataSize);
  12506. stream.readHexNumber(end, dataSize);
  12507. addHex(end, start, dataSize);
  12508. code = stream.readNumber();
  12509. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12510. code);
  12511. for (i = 1; i < subitemsCount; i++) {
  12512. incHex(end, dataSize);
  12513. if (!sequence) {
  12514. stream.readHexNumber(start, dataSize);
  12515. addHex(start, end, dataSize);
  12516. } else {
  12517. start.set(end);
  12518. }
  12519. stream.readHexNumber(end, dataSize);
  12520. addHex(end, start, dataSize);
  12521. code = stream.readNumber();
  12522. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12523. code);
  12524. }
  12525. break;
  12526. case 4: // bfchar
  12527. stream.readHex(char, ucs2DataSize);
  12528. stream.readHex(charCode, dataSize);
  12529. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12530. hexToStr(charCode, dataSize));
  12531. for (i = 1; i < subitemsCount; i++) {
  12532. incHex(char, ucs2DataSize);
  12533. if (!sequence) {
  12534. stream.readHexNumber(tmp, ucs2DataSize);
  12535. addHex(char, tmp, ucs2DataSize);
  12536. }
  12537. incHex(charCode, dataSize);
  12538. stream.readHexSigned(tmp, dataSize);
  12539. addHex(charCode, tmp, dataSize);
  12540. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12541. hexToStr(charCode, dataSize));
  12542. }
  12543. break;
  12544. case 5: // bfrange
  12545. stream.readHex(start, ucs2DataSize);
  12546. stream.readHexNumber(end, ucs2DataSize);
  12547. addHex(end, start, ucs2DataSize);
  12548. stream.readHex(charCode, dataSize);
  12549. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12550. hexToInt(end, ucs2DataSize),
  12551. hexToStr(charCode, dataSize));
  12552. for (i = 1; i < subitemsCount; i++) {
  12553. incHex(end, ucs2DataSize);
  12554. if (!sequence) {
  12555. stream.readHexNumber(start, ucs2DataSize);
  12556. addHex(start, end, ucs2DataSize);
  12557. } else {
  12558. start.set(end);
  12559. }
  12560. stream.readHexNumber(end, ucs2DataSize);
  12561. addHex(end, start, ucs2DataSize);
  12562. stream.readHex(charCode, dataSize);
  12563. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12564. hexToInt(end, ucs2DataSize),
  12565. hexToStr(charCode, dataSize));
  12566. }
  12567. break;
  12568. default:
  12569. error('Unknown type: ' + type);
  12570. break;
  12571. }
  12572. }
  12573. if (useCMap) {
  12574. extend(useCMap);
  12575. }
  12576. return cMap;
  12577. }
  12578. function BinaryCMapReader() {}
  12579. BinaryCMapReader.prototype = {
  12580. read: processBinaryCMap
  12581. };
  12582. return BinaryCMapReader;
  12583. })();
  12584. var CMapFactory = (function CMapFactoryClosure() {
  12585. function strToInt(str) {
  12586. var a = 0;
  12587. for (var i = 0; i < str.length; i++) {
  12588. a = (a << 8) | str.charCodeAt(i);
  12589. }
  12590. return a >>> 0;
  12591. }
  12592. function expectString(obj) {
  12593. if (!isString(obj)) {
  12594. error('Malformed CMap: expected string.');
  12595. }
  12596. }
  12597. function expectInt(obj) {
  12598. if (!isInt(obj)) {
  12599. error('Malformed CMap: expected int.');
  12600. }
  12601. }
  12602. function parseBfChar(cMap, lexer) {
  12603. while (true) {
  12604. var obj = lexer.getObj();
  12605. if (isEOF(obj)) {
  12606. break;
  12607. }
  12608. if (isCmd(obj, 'endbfchar')) {
  12609. return;
  12610. }
  12611. expectString(obj);
  12612. var src = strToInt(obj);
  12613. obj = lexer.getObj();
  12614. // TODO are /dstName used?
  12615. expectString(obj);
  12616. var dst = obj;
  12617. cMap.mapOne(src, dst);
  12618. }
  12619. }
  12620. function parseBfRange(cMap, lexer) {
  12621. while (true) {
  12622. var obj = lexer.getObj();
  12623. if (isEOF(obj)) {
  12624. break;
  12625. }
  12626. if (isCmd(obj, 'endbfrange')) {
  12627. return;
  12628. }
  12629. expectString(obj);
  12630. var low = strToInt(obj);
  12631. obj = lexer.getObj();
  12632. expectString(obj);
  12633. var high = strToInt(obj);
  12634. obj = lexer.getObj();
  12635. if (isInt(obj) || isString(obj)) {
  12636. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12637. cMap.mapBfRange(low, high, dstLow);
  12638. } else if (isCmd(obj, '[')) {
  12639. obj = lexer.getObj();
  12640. var array = [];
  12641. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12642. array.push(obj);
  12643. obj = lexer.getObj();
  12644. }
  12645. cMap.mapBfRangeToArray(low, high, array);
  12646. } else {
  12647. break;
  12648. }
  12649. }
  12650. error('Invalid bf range.');
  12651. }
  12652. function parseCidChar(cMap, lexer) {
  12653. while (true) {
  12654. var obj = lexer.getObj();
  12655. if (isEOF(obj)) {
  12656. break;
  12657. }
  12658. if (isCmd(obj, 'endcidchar')) {
  12659. return;
  12660. }
  12661. expectString(obj);
  12662. var src = strToInt(obj);
  12663. obj = lexer.getObj();
  12664. expectInt(obj);
  12665. var dst = obj;
  12666. cMap.mapOne(src, dst);
  12667. }
  12668. }
  12669. function parseCidRange(cMap, lexer) {
  12670. while (true) {
  12671. var obj = lexer.getObj();
  12672. if (isEOF(obj)) {
  12673. break;
  12674. }
  12675. if (isCmd(obj, 'endcidrange')) {
  12676. return;
  12677. }
  12678. expectString(obj);
  12679. var low = strToInt(obj);
  12680. obj = lexer.getObj();
  12681. expectString(obj);
  12682. var high = strToInt(obj);
  12683. obj = lexer.getObj();
  12684. expectInt(obj);
  12685. var dstLow = obj;
  12686. cMap.mapCidRange(low, high, dstLow);
  12687. }
  12688. }
  12689. function parseCodespaceRange(cMap, lexer) {
  12690. while (true) {
  12691. var obj = lexer.getObj();
  12692. if (isEOF(obj)) {
  12693. break;
  12694. }
  12695. if (isCmd(obj, 'endcodespacerange')) {
  12696. return;
  12697. }
  12698. if (!isString(obj)) {
  12699. break;
  12700. }
  12701. var low = strToInt(obj);
  12702. obj = lexer.getObj();
  12703. if (!isString(obj)) {
  12704. break;
  12705. }
  12706. var high = strToInt(obj);
  12707. cMap.addCodespaceRange(obj.length, low, high);
  12708. }
  12709. error('Invalid codespace range.');
  12710. }
  12711. function parseWMode(cMap, lexer) {
  12712. var obj = lexer.getObj();
  12713. if (isInt(obj)) {
  12714. cMap.vertical = !!obj;
  12715. }
  12716. }
  12717. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12718. var previous;
  12719. var embededUseCMap;
  12720. objLoop: while (true) {
  12721. var obj = lexer.getObj();
  12722. if (isEOF(obj)) {
  12723. break;
  12724. } else if (isName(obj)) {
  12725. if (obj.name === 'WMode') {
  12726. parseWMode(cMap, lexer);
  12727. }
  12728. previous = obj;
  12729. } else if (isCmd(obj)) {
  12730. switch (obj.cmd) {
  12731. case 'endcmap':
  12732. break objLoop;
  12733. case 'usecmap':
  12734. if (isName(previous)) {
  12735. embededUseCMap = previous.name;
  12736. }
  12737. break;
  12738. case 'begincodespacerange':
  12739. parseCodespaceRange(cMap, lexer);
  12740. break;
  12741. case 'beginbfchar':
  12742. parseBfChar(cMap, lexer);
  12743. break;
  12744. case 'begincidchar':
  12745. parseCidChar(cMap, lexer);
  12746. break;
  12747. case 'beginbfrange':
  12748. parseBfRange(cMap, lexer);
  12749. break;
  12750. case 'begincidrange':
  12751. parseCidRange(cMap, lexer);
  12752. break;
  12753. }
  12754. }
  12755. }
  12756. if (!useCMap && embededUseCMap) {
  12757. // Load the usecmap definition from the file only if there wasn't one
  12758. // specified.
  12759. useCMap = embededUseCMap;
  12760. }
  12761. if (useCMap) {
  12762. extendCMap(cMap, builtInCMapParams, useCMap);
  12763. }
  12764. }
  12765. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12766. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12767. // If there aren't any code space ranges defined clone all the parent ones
  12768. // into this cMap.
  12769. if (cMap.numCodespaceRanges === 0) {
  12770. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12771. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12772. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12773. }
  12774. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12775. }
  12776. // Merge the map into the current one, making sure not to override
  12777. // any previously defined entries.
  12778. cMap.useCMap.forEach(function(key, value) {
  12779. if (!cMap.contains(key)) {
  12780. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12781. }
  12782. });
  12783. }
  12784. function parseBinaryCMap(name, builtInCMapParams) {
  12785. var url = builtInCMapParams.url + name + '.bcmap';
  12786. var cMap = new CMap(true);
  12787. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12788. extendCMap(cMap, builtInCMapParams, useCMap);
  12789. });
  12790. return cMap;
  12791. }
  12792. function createBuiltInCMap(name, builtInCMapParams) {
  12793. if (name === 'Identity-H') {
  12794. return new IdentityCMap(false, 2);
  12795. } else if (name === 'Identity-V') {
  12796. return new IdentityCMap(true, 2);
  12797. }
  12798. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12799. error('Unknown cMap name: ' + name);
  12800. }
  12801. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12802. if (builtInCMapParams.packed) {
  12803. return parseBinaryCMap(name, builtInCMapParams);
  12804. }
  12805. var request = new XMLHttpRequest();
  12806. var url = builtInCMapParams.url + name;
  12807. request.open('GET', url, false);
  12808. request.send(null);
  12809. if (!request.responseText) {
  12810. error('Unable to get cMap at: ' + url);
  12811. }
  12812. var cMap = new CMap(true);
  12813. var lexer = new Lexer(new StringStream(request.responseText));
  12814. parseCMap(cMap, lexer, builtInCMapParams, null);
  12815. return cMap;
  12816. }
  12817. return {
  12818. create: function (encoding, builtInCMapParams, useCMap) {
  12819. if (isName(encoding)) {
  12820. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12821. } else if (isStream(encoding)) {
  12822. var cMap = new CMap();
  12823. var lexer = new Lexer(encoding);
  12824. try {
  12825. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12826. } catch (e) {
  12827. warn('Invalid CMap data. ' + e);
  12828. }
  12829. return cMap;
  12830. }
  12831. error('Encoding required.');
  12832. }
  12833. };
  12834. })();
  12835. // Unicode Private Use Area
  12836. var PRIVATE_USE_OFFSET_START = 0xE000;
  12837. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12838. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12839. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12840. // except for Type 3 fonts
  12841. var PDF_GLYPH_SPACE_UNITS = 1000;
  12842. // Hinting is currently disabled due to unknown problems on windows
  12843. // in tracemonkey and various other pdfs with type1 fonts.
  12844. var HINTING_ENABLED = false;
  12845. // Accented charactars are not displayed properly on windows, using this flag
  12846. // to control analysis of seac charstrings.
  12847. var SEAC_ANALYSIS_ENABLED = false;
  12848. var FontFlags = {
  12849. FixedPitch: 1,
  12850. Serif: 2,
  12851. Symbolic: 4,
  12852. Script: 8,
  12853. Nonsymbolic: 32,
  12854. Italic: 64,
  12855. AllCap: 65536,
  12856. SmallCap: 131072,
  12857. ForceBold: 262144
  12858. };
  12859. var Encodings = {
  12860. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12861. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12862. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12863. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12864. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12865. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12866. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12867. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12868. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12869. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12870. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12871. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12872. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12873. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12874. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12875. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12876. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12877. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12878. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12879. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12880. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12881. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12882. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12883. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12884. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12885. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12886. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12887. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12888. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12889. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12890. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12891. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12892. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12893. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12894. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12895. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12896. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12897. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12898. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12899. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12900. 'Ydieresissmall'],
  12901. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12902. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12903. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12904. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12905. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12906. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12907. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12908. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12909. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12910. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12911. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12912. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12913. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12914. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12915. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12916. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12917. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12918. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12919. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12920. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12921. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12922. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12923. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12924. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12925. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12926. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12927. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12928. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12929. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12930. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12931. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12932. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12933. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12934. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12935. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12936. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12937. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12938. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12939. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12940. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12941. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12942. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12943. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12944. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12945. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12946. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12947. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12948. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12949. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12950. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12951. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12952. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12953. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12954. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12955. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12956. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12957. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12958. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12959. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12960. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12961. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12962. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12963. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12964. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12965. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12966. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12967. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12968. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12969. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12970. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12971. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12972. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12973. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12974. 'ogonek', 'caron'],
  12975. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12976. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12977. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12978. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12979. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12980. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12981. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12982. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12983. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12984. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12985. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12986. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12987. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12988. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12989. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12990. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12991. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12992. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12993. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12994. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12995. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12996. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12997. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12998. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12999. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13000. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13001. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13002. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13003. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13004. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13005. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13006. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13007. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13008. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13009. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13010. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13011. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13012. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13013. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13014. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13015. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13016. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13017. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13018. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13019. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13020. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13021. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13022. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13023. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13024. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13025. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13026. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13027. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13028. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13029. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13030. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13031. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13032. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13033. 'ydieresis'],
  13034. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13035. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13036. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13037. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13038. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13039. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13040. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13041. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13042. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13043. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13044. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13045. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13046. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13047. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13048. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13049. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13050. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13051. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13052. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13053. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13054. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13055. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13056. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13057. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13058. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13059. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13060. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13061. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13062. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13063. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13064. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13065. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13066. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13067. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13068. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13069. 'bracerightbt'],
  13070. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13071. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13072. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13073. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13074. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13075. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13076. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13077. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13078. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13079. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13080. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13081. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13082. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13083. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13084. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13085. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13086. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13087. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13088. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13089. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13090. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13091. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13092. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13093. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13094. };
  13095. /**
  13096. * Hold a map of decoded fonts and of the standard fourteen Type1
  13097. * fonts and their acronyms.
  13098. */
  13099. var stdFontMap = {
  13100. 'ArialNarrow': 'Helvetica',
  13101. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13102. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13103. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13104. 'ArialBlack': 'Helvetica',
  13105. 'ArialBlack-Bold': 'Helvetica-Bold',
  13106. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13107. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13108. 'Arial': 'Helvetica',
  13109. 'Arial-Bold': 'Helvetica-Bold',
  13110. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13111. 'Arial-Italic': 'Helvetica-Oblique',
  13112. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13113. 'Arial-BoldMT': 'Helvetica-Bold',
  13114. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13115. 'ArialMT': 'Helvetica',
  13116. 'Courier-Bold': 'Courier-Bold',
  13117. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13118. 'Courier-Italic': 'Courier-Oblique',
  13119. 'CourierNew': 'Courier',
  13120. 'CourierNew-Bold': 'Courier-Bold',
  13121. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13122. 'CourierNew-Italic': 'Courier-Oblique',
  13123. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13124. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13125. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13126. 'CourierNewPSMT': 'Courier',
  13127. 'Helvetica': 'Helvetica',
  13128. 'Helvetica-Bold': 'Helvetica-Bold',
  13129. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13130. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13131. 'Helvetica-Italic': 'Helvetica-Oblique',
  13132. 'Helvetica-Oblique':'Helvetica-Oblique',
  13133. 'Symbol-Bold': 'Symbol',
  13134. 'Symbol-BoldItalic': 'Symbol',
  13135. 'Symbol-Italic': 'Symbol',
  13136. 'TimesNewRoman': 'Times-Roman',
  13137. 'TimesNewRoman-Bold': 'Times-Bold',
  13138. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13139. 'TimesNewRoman-Italic': 'Times-Italic',
  13140. 'TimesNewRomanPS': 'Times-Roman',
  13141. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13142. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13143. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13144. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13145. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13146. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13147. 'TimesNewRomanPSMT': 'Times-Roman',
  13148. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13149. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13150. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13151. };
  13152. /**
  13153. * Holds the map of the non-standard fonts that might be included as a standard
  13154. * fonts without glyph data.
  13155. */
  13156. var nonStdFontMap = {
  13157. 'CenturyGothic': 'Helvetica',
  13158. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13159. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13160. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13161. 'ComicSansMS': 'Comic Sans MS',
  13162. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13163. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13164. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13165. 'LucidaConsole': 'Courier',
  13166. 'LucidaConsole-Bold': 'Courier-Bold',
  13167. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13168. 'LucidaConsole-Italic': 'Courier-Oblique',
  13169. 'MS-Gothic': 'MS Gothic',
  13170. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13171. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13172. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13173. 'MS-Mincho': 'MS Mincho',
  13174. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13175. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13176. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13177. 'MS-PGothic': 'MS PGothic',
  13178. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13179. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13180. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13181. 'MS-PMincho': 'MS PMincho',
  13182. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13183. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13184. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13185. 'Wingdings': 'ZapfDingbats'
  13186. };
  13187. var serifFonts = {
  13188. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13189. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13190. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13191. 'Arno': true, 'Aster': true, 'Aurora': true,
  13192. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13193. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13194. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13195. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13196. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13197. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13198. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13199. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13200. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13201. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13202. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13203. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13204. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13205. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13206. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13207. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13208. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13209. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13210. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13211. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13212. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13213. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13214. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13215. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13216. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13217. 'Miller': true, 'Minion': true, 'Modern': true,
  13218. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13219. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13220. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13221. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13222. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13223. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13224. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13225. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13226. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13227. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13228. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13229. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13230. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13231. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13232. };
  13233. var symbolsFonts = {
  13234. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13235. };
  13236. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13237. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13238. // glyphs, but common for some set of the standard fonts.
  13239. var GlyphMapForStandardFonts = {
  13240. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13241. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13242. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13243. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13244. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13245. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13246. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13247. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13248. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13249. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13250. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13251. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13252. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13253. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13254. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13255. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13256. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13257. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13258. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13259. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13260. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13261. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13262. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13263. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13264. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13265. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13266. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13267. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13268. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13269. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13270. '298': 380, '305': 963,
  13271. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13272. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13273. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13274. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13275. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13276. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13277. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13278. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13279. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13280. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13281. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13282. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13283. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13284. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13285. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13286. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13287. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13288. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13289. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13290. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13291. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13292. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13293. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13294. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13295. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13296. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13297. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13298. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13299. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13300. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13301. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13302. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13303. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13304. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13305. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13306. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13307. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13308. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13309. };
  13310. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13311. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13312. // to the similar equivalents in the normal characters range.
  13313. var SpecialPUASymbols = {
  13314. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13315. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13316. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13317. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13318. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13319. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13320. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13321. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13322. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13323. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13324. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13325. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13326. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13327. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13328. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13329. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13330. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13331. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13332. '63723': 0x239B, // parenlefttp (0xF8EB)
  13333. '63724': 0x239C, // parenleftex (0xF8EC)
  13334. '63725': 0x239D, // parenleftbt (0xF8ED)
  13335. '63734': 0x239E, // parenrighttp (0xF8F6)
  13336. '63735': 0x239F, // parenrightex (0xF8F7)
  13337. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13338. };
  13339. function mapSpecialUnicodeValues(code) {
  13340. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13341. return 0;
  13342. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13343. return (SpecialPUASymbols[code] || code);
  13344. }
  13345. return code;
  13346. }
  13347. var UnicodeRanges = [
  13348. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13349. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13350. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13351. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13352. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13353. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13354. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13355. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13356. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13357. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13358. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13359. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13360. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13361. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13362. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13363. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13364. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13365. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13366. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13367. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13368. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13369. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13370. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13371. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13372. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13373. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13374. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13375. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13376. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13377. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13378. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13379. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13380. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13381. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13382. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13383. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13384. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13385. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13386. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13387. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13388. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13389. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13390. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13391. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13392. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13393. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13394. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13395. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13396. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13397. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13398. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13399. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13400. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13401. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13402. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13403. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13404. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13405. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13406. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13407. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13408. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13409. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13410. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13411. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13412. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13413. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13414. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13415. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13416. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13417. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13418. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13419. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13420. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13421. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13422. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13423. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13424. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13425. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13426. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13427. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13428. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13429. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13430. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13431. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13432. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13433. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13434. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13435. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13436. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13437. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13438. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13439. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13440. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13441. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13442. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13443. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13444. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13445. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13446. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13447. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13448. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13449. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13450. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13451. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13452. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13453. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13454. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13455. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13456. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13457. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13458. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13459. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13460. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13461. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13462. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13463. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13464. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13465. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13466. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13467. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13468. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13469. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13470. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13471. ];
  13472. var MacStandardGlyphOrdering = [
  13473. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13474. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13475. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13476. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13477. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13478. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13479. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13480. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13481. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13482. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13483. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13484. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13485. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13486. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13487. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13488. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13489. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13490. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13491. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13492. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13493. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13494. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13495. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13496. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13497. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13498. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13499. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13500. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13501. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13502. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13503. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13504. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13505. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13506. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13507. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13508. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13509. function getUnicodeRangeFor(value) {
  13510. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13511. var range = UnicodeRanges[i];
  13512. if (value >= range.begin && value < range.end) {
  13513. return i;
  13514. }
  13515. }
  13516. return -1;
  13517. }
  13518. function isRTLRangeFor(value) {
  13519. var range = UnicodeRanges[13];
  13520. if (value >= range.begin && value < range.end) {
  13521. return true;
  13522. }
  13523. range = UnicodeRanges[11];
  13524. if (value >= range.begin && value < range.end) {
  13525. return true;
  13526. }
  13527. return false;
  13528. }
  13529. // The normalization table is obtained by filtering the Unicode characters
  13530. // database with <compat> entries.
  13531. var NormalizedUnicodes = {
  13532. '\u00A8': '\u0020\u0308',
  13533. '\u00AF': '\u0020\u0304',
  13534. '\u00B4': '\u0020\u0301',
  13535. '\u00B5': '\u03BC',
  13536. '\u00B8': '\u0020\u0327',
  13537. '\u0132': '\u0049\u004A',
  13538. '\u0133': '\u0069\u006A',
  13539. '\u013F': '\u004C\u00B7',
  13540. '\u0140': '\u006C\u00B7',
  13541. '\u0149': '\u02BC\u006E',
  13542. '\u017F': '\u0073',
  13543. '\u01C4': '\u0044\u017D',
  13544. '\u01C5': '\u0044\u017E',
  13545. '\u01C6': '\u0064\u017E',
  13546. '\u01C7': '\u004C\u004A',
  13547. '\u01C8': '\u004C\u006A',
  13548. '\u01C9': '\u006C\u006A',
  13549. '\u01CA': '\u004E\u004A',
  13550. '\u01CB': '\u004E\u006A',
  13551. '\u01CC': '\u006E\u006A',
  13552. '\u01F1': '\u0044\u005A',
  13553. '\u01F2': '\u0044\u007A',
  13554. '\u01F3': '\u0064\u007A',
  13555. '\u02D8': '\u0020\u0306',
  13556. '\u02D9': '\u0020\u0307',
  13557. '\u02DA': '\u0020\u030A',
  13558. '\u02DB': '\u0020\u0328',
  13559. '\u02DC': '\u0020\u0303',
  13560. '\u02DD': '\u0020\u030B',
  13561. '\u037A': '\u0020\u0345',
  13562. '\u0384': '\u0020\u0301',
  13563. '\u03D0': '\u03B2',
  13564. '\u03D1': '\u03B8',
  13565. '\u03D2': '\u03A5',
  13566. '\u03D5': '\u03C6',
  13567. '\u03D6': '\u03C0',
  13568. '\u03F0': '\u03BA',
  13569. '\u03F1': '\u03C1',
  13570. '\u03F2': '\u03C2',
  13571. '\u03F4': '\u0398',
  13572. '\u03F5': '\u03B5',
  13573. '\u03F9': '\u03A3',
  13574. '\u0587': '\u0565\u0582',
  13575. '\u0675': '\u0627\u0674',
  13576. '\u0676': '\u0648\u0674',
  13577. '\u0677': '\u06C7\u0674',
  13578. '\u0678': '\u064A\u0674',
  13579. '\u0E33': '\u0E4D\u0E32',
  13580. '\u0EB3': '\u0ECD\u0EB2',
  13581. '\u0EDC': '\u0EAB\u0E99',
  13582. '\u0EDD': '\u0EAB\u0EA1',
  13583. '\u0F77': '\u0FB2\u0F81',
  13584. '\u0F79': '\u0FB3\u0F81',
  13585. '\u1E9A': '\u0061\u02BE',
  13586. '\u1FBD': '\u0020\u0313',
  13587. '\u1FBF': '\u0020\u0313',
  13588. '\u1FC0': '\u0020\u0342',
  13589. '\u1FFE': '\u0020\u0314',
  13590. '\u2002': '\u0020',
  13591. '\u2003': '\u0020',
  13592. '\u2004': '\u0020',
  13593. '\u2005': '\u0020',
  13594. '\u2006': '\u0020',
  13595. '\u2008': '\u0020',
  13596. '\u2009': '\u0020',
  13597. '\u200A': '\u0020',
  13598. '\u2017': '\u0020\u0333',
  13599. '\u2024': '\u002E',
  13600. '\u2025': '\u002E\u002E',
  13601. '\u2026': '\u002E\u002E\u002E',
  13602. '\u2033': '\u2032\u2032',
  13603. '\u2034': '\u2032\u2032\u2032',
  13604. '\u2036': '\u2035\u2035',
  13605. '\u2037': '\u2035\u2035\u2035',
  13606. '\u203C': '\u0021\u0021',
  13607. '\u203E': '\u0020\u0305',
  13608. '\u2047': '\u003F\u003F',
  13609. '\u2048': '\u003F\u0021',
  13610. '\u2049': '\u0021\u003F',
  13611. '\u2057': '\u2032\u2032\u2032\u2032',
  13612. '\u205F': '\u0020',
  13613. '\u20A8': '\u0052\u0073',
  13614. '\u2100': '\u0061\u002F\u0063',
  13615. '\u2101': '\u0061\u002F\u0073',
  13616. '\u2103': '\u00B0\u0043',
  13617. '\u2105': '\u0063\u002F\u006F',
  13618. '\u2106': '\u0063\u002F\u0075',
  13619. '\u2107': '\u0190',
  13620. '\u2109': '\u00B0\u0046',
  13621. '\u2116': '\u004E\u006F',
  13622. '\u2121': '\u0054\u0045\u004C',
  13623. '\u2135': '\u05D0',
  13624. '\u2136': '\u05D1',
  13625. '\u2137': '\u05D2',
  13626. '\u2138': '\u05D3',
  13627. '\u213B': '\u0046\u0041\u0058',
  13628. '\u2160': '\u0049',
  13629. '\u2161': '\u0049\u0049',
  13630. '\u2162': '\u0049\u0049\u0049',
  13631. '\u2163': '\u0049\u0056',
  13632. '\u2164': '\u0056',
  13633. '\u2165': '\u0056\u0049',
  13634. '\u2166': '\u0056\u0049\u0049',
  13635. '\u2167': '\u0056\u0049\u0049\u0049',
  13636. '\u2168': '\u0049\u0058',
  13637. '\u2169': '\u0058',
  13638. '\u216A': '\u0058\u0049',
  13639. '\u216B': '\u0058\u0049\u0049',
  13640. '\u216C': '\u004C',
  13641. '\u216D': '\u0043',
  13642. '\u216E': '\u0044',
  13643. '\u216F': '\u004D',
  13644. '\u2170': '\u0069',
  13645. '\u2171': '\u0069\u0069',
  13646. '\u2172': '\u0069\u0069\u0069',
  13647. '\u2173': '\u0069\u0076',
  13648. '\u2174': '\u0076',
  13649. '\u2175': '\u0076\u0069',
  13650. '\u2176': '\u0076\u0069\u0069',
  13651. '\u2177': '\u0076\u0069\u0069\u0069',
  13652. '\u2178': '\u0069\u0078',
  13653. '\u2179': '\u0078',
  13654. '\u217A': '\u0078\u0069',
  13655. '\u217B': '\u0078\u0069\u0069',
  13656. '\u217C': '\u006C',
  13657. '\u217D': '\u0063',
  13658. '\u217E': '\u0064',
  13659. '\u217F': '\u006D',
  13660. '\u222C': '\u222B\u222B',
  13661. '\u222D': '\u222B\u222B\u222B',
  13662. '\u222F': '\u222E\u222E',
  13663. '\u2230': '\u222E\u222E\u222E',
  13664. '\u2474': '\u0028\u0031\u0029',
  13665. '\u2475': '\u0028\u0032\u0029',
  13666. '\u2476': '\u0028\u0033\u0029',
  13667. '\u2477': '\u0028\u0034\u0029',
  13668. '\u2478': '\u0028\u0035\u0029',
  13669. '\u2479': '\u0028\u0036\u0029',
  13670. '\u247A': '\u0028\u0037\u0029',
  13671. '\u247B': '\u0028\u0038\u0029',
  13672. '\u247C': '\u0028\u0039\u0029',
  13673. '\u247D': '\u0028\u0031\u0030\u0029',
  13674. '\u247E': '\u0028\u0031\u0031\u0029',
  13675. '\u247F': '\u0028\u0031\u0032\u0029',
  13676. '\u2480': '\u0028\u0031\u0033\u0029',
  13677. '\u2481': '\u0028\u0031\u0034\u0029',
  13678. '\u2482': '\u0028\u0031\u0035\u0029',
  13679. '\u2483': '\u0028\u0031\u0036\u0029',
  13680. '\u2484': '\u0028\u0031\u0037\u0029',
  13681. '\u2485': '\u0028\u0031\u0038\u0029',
  13682. '\u2486': '\u0028\u0031\u0039\u0029',
  13683. '\u2487': '\u0028\u0032\u0030\u0029',
  13684. '\u2488': '\u0031\u002E',
  13685. '\u2489': '\u0032\u002E',
  13686. '\u248A': '\u0033\u002E',
  13687. '\u248B': '\u0034\u002E',
  13688. '\u248C': '\u0035\u002E',
  13689. '\u248D': '\u0036\u002E',
  13690. '\u248E': '\u0037\u002E',
  13691. '\u248F': '\u0038\u002E',
  13692. '\u2490': '\u0039\u002E',
  13693. '\u2491': '\u0031\u0030\u002E',
  13694. '\u2492': '\u0031\u0031\u002E',
  13695. '\u2493': '\u0031\u0032\u002E',
  13696. '\u2494': '\u0031\u0033\u002E',
  13697. '\u2495': '\u0031\u0034\u002E',
  13698. '\u2496': '\u0031\u0035\u002E',
  13699. '\u2497': '\u0031\u0036\u002E',
  13700. '\u2498': '\u0031\u0037\u002E',
  13701. '\u2499': '\u0031\u0038\u002E',
  13702. '\u249A': '\u0031\u0039\u002E',
  13703. '\u249B': '\u0032\u0030\u002E',
  13704. '\u249C': '\u0028\u0061\u0029',
  13705. '\u249D': '\u0028\u0062\u0029',
  13706. '\u249E': '\u0028\u0063\u0029',
  13707. '\u249F': '\u0028\u0064\u0029',
  13708. '\u24A0': '\u0028\u0065\u0029',
  13709. '\u24A1': '\u0028\u0066\u0029',
  13710. '\u24A2': '\u0028\u0067\u0029',
  13711. '\u24A3': '\u0028\u0068\u0029',
  13712. '\u24A4': '\u0028\u0069\u0029',
  13713. '\u24A5': '\u0028\u006A\u0029',
  13714. '\u24A6': '\u0028\u006B\u0029',
  13715. '\u24A7': '\u0028\u006C\u0029',
  13716. '\u24A8': '\u0028\u006D\u0029',
  13717. '\u24A9': '\u0028\u006E\u0029',
  13718. '\u24AA': '\u0028\u006F\u0029',
  13719. '\u24AB': '\u0028\u0070\u0029',
  13720. '\u24AC': '\u0028\u0071\u0029',
  13721. '\u24AD': '\u0028\u0072\u0029',
  13722. '\u24AE': '\u0028\u0073\u0029',
  13723. '\u24AF': '\u0028\u0074\u0029',
  13724. '\u24B0': '\u0028\u0075\u0029',
  13725. '\u24B1': '\u0028\u0076\u0029',
  13726. '\u24B2': '\u0028\u0077\u0029',
  13727. '\u24B3': '\u0028\u0078\u0029',
  13728. '\u24B4': '\u0028\u0079\u0029',
  13729. '\u24B5': '\u0028\u007A\u0029',
  13730. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13731. '\u2A74': '\u003A\u003A\u003D',
  13732. '\u2A75': '\u003D\u003D',
  13733. '\u2A76': '\u003D\u003D\u003D',
  13734. '\u2E9F': '\u6BCD',
  13735. '\u2EF3': '\u9F9F',
  13736. '\u2F00': '\u4E00',
  13737. '\u2F01': '\u4E28',
  13738. '\u2F02': '\u4E36',
  13739. '\u2F03': '\u4E3F',
  13740. '\u2F04': '\u4E59',
  13741. '\u2F05': '\u4E85',
  13742. '\u2F06': '\u4E8C',
  13743. '\u2F07': '\u4EA0',
  13744. '\u2F08': '\u4EBA',
  13745. '\u2F09': '\u513F',
  13746. '\u2F0A': '\u5165',
  13747. '\u2F0B': '\u516B',
  13748. '\u2F0C': '\u5182',
  13749. '\u2F0D': '\u5196',
  13750. '\u2F0E': '\u51AB',
  13751. '\u2F0F': '\u51E0',
  13752. '\u2F10': '\u51F5',
  13753. '\u2F11': '\u5200',
  13754. '\u2F12': '\u529B',
  13755. '\u2F13': '\u52F9',
  13756. '\u2F14': '\u5315',
  13757. '\u2F15': '\u531A',
  13758. '\u2F16': '\u5338',
  13759. '\u2F17': '\u5341',
  13760. '\u2F18': '\u535C',
  13761. '\u2F19': '\u5369',
  13762. '\u2F1A': '\u5382',
  13763. '\u2F1B': '\u53B6',
  13764. '\u2F1C': '\u53C8',
  13765. '\u2F1D': '\u53E3',
  13766. '\u2F1E': '\u56D7',
  13767. '\u2F1F': '\u571F',
  13768. '\u2F20': '\u58EB',
  13769. '\u2F21': '\u5902',
  13770. '\u2F22': '\u590A',
  13771. '\u2F23': '\u5915',
  13772. '\u2F24': '\u5927',
  13773. '\u2F25': '\u5973',
  13774. '\u2F26': '\u5B50',
  13775. '\u2F27': '\u5B80',
  13776. '\u2F28': '\u5BF8',
  13777. '\u2F29': '\u5C0F',
  13778. '\u2F2A': '\u5C22',
  13779. '\u2F2B': '\u5C38',
  13780. '\u2F2C': '\u5C6E',
  13781. '\u2F2D': '\u5C71',
  13782. '\u2F2E': '\u5DDB',
  13783. '\u2F2F': '\u5DE5',
  13784. '\u2F30': '\u5DF1',
  13785. '\u2F31': '\u5DFE',
  13786. '\u2F32': '\u5E72',
  13787. '\u2F33': '\u5E7A',
  13788. '\u2F34': '\u5E7F',
  13789. '\u2F35': '\u5EF4',
  13790. '\u2F36': '\u5EFE',
  13791. '\u2F37': '\u5F0B',
  13792. '\u2F38': '\u5F13',
  13793. '\u2F39': '\u5F50',
  13794. '\u2F3A': '\u5F61',
  13795. '\u2F3B': '\u5F73',
  13796. '\u2F3C': '\u5FC3',
  13797. '\u2F3D': '\u6208',
  13798. '\u2F3E': '\u6236',
  13799. '\u2F3F': '\u624B',
  13800. '\u2F40': '\u652F',
  13801. '\u2F41': '\u6534',
  13802. '\u2F42': '\u6587',
  13803. '\u2F43': '\u6597',
  13804. '\u2F44': '\u65A4',
  13805. '\u2F45': '\u65B9',
  13806. '\u2F46': '\u65E0',
  13807. '\u2F47': '\u65E5',
  13808. '\u2F48': '\u66F0',
  13809. '\u2F49': '\u6708',
  13810. '\u2F4A': '\u6728',
  13811. '\u2F4B': '\u6B20',
  13812. '\u2F4C': '\u6B62',
  13813. '\u2F4D': '\u6B79',
  13814. '\u2F4E': '\u6BB3',
  13815. '\u2F4F': '\u6BCB',
  13816. '\u2F50': '\u6BD4',
  13817. '\u2F51': '\u6BDB',
  13818. '\u2F52': '\u6C0F',
  13819. '\u2F53': '\u6C14',
  13820. '\u2F54': '\u6C34',
  13821. '\u2F55': '\u706B',
  13822. '\u2F56': '\u722A',
  13823. '\u2F57': '\u7236',
  13824. '\u2F58': '\u723B',
  13825. '\u2F59': '\u723F',
  13826. '\u2F5A': '\u7247',
  13827. '\u2F5B': '\u7259',
  13828. '\u2F5C': '\u725B',
  13829. '\u2F5D': '\u72AC',
  13830. '\u2F5E': '\u7384',
  13831. '\u2F5F': '\u7389',
  13832. '\u2F60': '\u74DC',
  13833. '\u2F61': '\u74E6',
  13834. '\u2F62': '\u7518',
  13835. '\u2F63': '\u751F',
  13836. '\u2F64': '\u7528',
  13837. '\u2F65': '\u7530',
  13838. '\u2F66': '\u758B',
  13839. '\u2F67': '\u7592',
  13840. '\u2F68': '\u7676',
  13841. '\u2F69': '\u767D',
  13842. '\u2F6A': '\u76AE',
  13843. '\u2F6B': '\u76BF',
  13844. '\u2F6C': '\u76EE',
  13845. '\u2F6D': '\u77DB',
  13846. '\u2F6E': '\u77E2',
  13847. '\u2F6F': '\u77F3',
  13848. '\u2F70': '\u793A',
  13849. '\u2F71': '\u79B8',
  13850. '\u2F72': '\u79BE',
  13851. '\u2F73': '\u7A74',
  13852. '\u2F74': '\u7ACB',
  13853. '\u2F75': '\u7AF9',
  13854. '\u2F76': '\u7C73',
  13855. '\u2F77': '\u7CF8',
  13856. '\u2F78': '\u7F36',
  13857. '\u2F79': '\u7F51',
  13858. '\u2F7A': '\u7F8A',
  13859. '\u2F7B': '\u7FBD',
  13860. '\u2F7C': '\u8001',
  13861. '\u2F7D': '\u800C',
  13862. '\u2F7E': '\u8012',
  13863. '\u2F7F': '\u8033',
  13864. '\u2F80': '\u807F',
  13865. '\u2F81': '\u8089',
  13866. '\u2F82': '\u81E3',
  13867. '\u2F83': '\u81EA',
  13868. '\u2F84': '\u81F3',
  13869. '\u2F85': '\u81FC',
  13870. '\u2F86': '\u820C',
  13871. '\u2F87': '\u821B',
  13872. '\u2F88': '\u821F',
  13873. '\u2F89': '\u826E',
  13874. '\u2F8A': '\u8272',
  13875. '\u2F8B': '\u8278',
  13876. '\u2F8C': '\u864D',
  13877. '\u2F8D': '\u866B',
  13878. '\u2F8E': '\u8840',
  13879. '\u2F8F': '\u884C',
  13880. '\u2F90': '\u8863',
  13881. '\u2F91': '\u897E',
  13882. '\u2F92': '\u898B',
  13883. '\u2F93': '\u89D2',
  13884. '\u2F94': '\u8A00',
  13885. '\u2F95': '\u8C37',
  13886. '\u2F96': '\u8C46',
  13887. '\u2F97': '\u8C55',
  13888. '\u2F98': '\u8C78',
  13889. '\u2F99': '\u8C9D',
  13890. '\u2F9A': '\u8D64',
  13891. '\u2F9B': '\u8D70',
  13892. '\u2F9C': '\u8DB3',
  13893. '\u2F9D': '\u8EAB',
  13894. '\u2F9E': '\u8ECA',
  13895. '\u2F9F': '\u8F9B',
  13896. '\u2FA0': '\u8FB0',
  13897. '\u2FA1': '\u8FB5',
  13898. '\u2FA2': '\u9091',
  13899. '\u2FA3': '\u9149',
  13900. '\u2FA4': '\u91C6',
  13901. '\u2FA5': '\u91CC',
  13902. '\u2FA6': '\u91D1',
  13903. '\u2FA7': '\u9577',
  13904. '\u2FA8': '\u9580',
  13905. '\u2FA9': '\u961C',
  13906. '\u2FAA': '\u96B6',
  13907. '\u2FAB': '\u96B9',
  13908. '\u2FAC': '\u96E8',
  13909. '\u2FAD': '\u9751',
  13910. '\u2FAE': '\u975E',
  13911. '\u2FAF': '\u9762',
  13912. '\u2FB0': '\u9769',
  13913. '\u2FB1': '\u97CB',
  13914. '\u2FB2': '\u97ED',
  13915. '\u2FB3': '\u97F3',
  13916. '\u2FB4': '\u9801',
  13917. '\u2FB5': '\u98A8',
  13918. '\u2FB6': '\u98DB',
  13919. '\u2FB7': '\u98DF',
  13920. '\u2FB8': '\u9996',
  13921. '\u2FB9': '\u9999',
  13922. '\u2FBA': '\u99AC',
  13923. '\u2FBB': '\u9AA8',
  13924. '\u2FBC': '\u9AD8',
  13925. '\u2FBD': '\u9ADF',
  13926. '\u2FBE': '\u9B25',
  13927. '\u2FBF': '\u9B2F',
  13928. '\u2FC0': '\u9B32',
  13929. '\u2FC1': '\u9B3C',
  13930. '\u2FC2': '\u9B5A',
  13931. '\u2FC3': '\u9CE5',
  13932. '\u2FC4': '\u9E75',
  13933. '\u2FC5': '\u9E7F',
  13934. '\u2FC6': '\u9EA5',
  13935. '\u2FC7': '\u9EBB',
  13936. '\u2FC8': '\u9EC3',
  13937. '\u2FC9': '\u9ECD',
  13938. '\u2FCA': '\u9ED1',
  13939. '\u2FCB': '\u9EF9',
  13940. '\u2FCC': '\u9EFD',
  13941. '\u2FCD': '\u9F0E',
  13942. '\u2FCE': '\u9F13',
  13943. '\u2FCF': '\u9F20',
  13944. '\u2FD0': '\u9F3B',
  13945. '\u2FD1': '\u9F4A',
  13946. '\u2FD2': '\u9F52',
  13947. '\u2FD3': '\u9F8D',
  13948. '\u2FD4': '\u9F9C',
  13949. '\u2FD5': '\u9FA0',
  13950. '\u3036': '\u3012',
  13951. '\u3038': '\u5341',
  13952. '\u3039': '\u5344',
  13953. '\u303A': '\u5345',
  13954. '\u309B': '\u0020\u3099',
  13955. '\u309C': '\u0020\u309A',
  13956. '\u3131': '\u1100',
  13957. '\u3132': '\u1101',
  13958. '\u3133': '\u11AA',
  13959. '\u3134': '\u1102',
  13960. '\u3135': '\u11AC',
  13961. '\u3136': '\u11AD',
  13962. '\u3137': '\u1103',
  13963. '\u3138': '\u1104',
  13964. '\u3139': '\u1105',
  13965. '\u313A': '\u11B0',
  13966. '\u313B': '\u11B1',
  13967. '\u313C': '\u11B2',
  13968. '\u313D': '\u11B3',
  13969. '\u313E': '\u11B4',
  13970. '\u313F': '\u11B5',
  13971. '\u3140': '\u111A',
  13972. '\u3141': '\u1106',
  13973. '\u3142': '\u1107',
  13974. '\u3143': '\u1108',
  13975. '\u3144': '\u1121',
  13976. '\u3145': '\u1109',
  13977. '\u3146': '\u110A',
  13978. '\u3147': '\u110B',
  13979. '\u3148': '\u110C',
  13980. '\u3149': '\u110D',
  13981. '\u314A': '\u110E',
  13982. '\u314B': '\u110F',
  13983. '\u314C': '\u1110',
  13984. '\u314D': '\u1111',
  13985. '\u314E': '\u1112',
  13986. '\u314F': '\u1161',
  13987. '\u3150': '\u1162',
  13988. '\u3151': '\u1163',
  13989. '\u3152': '\u1164',
  13990. '\u3153': '\u1165',
  13991. '\u3154': '\u1166',
  13992. '\u3155': '\u1167',
  13993. '\u3156': '\u1168',
  13994. '\u3157': '\u1169',
  13995. '\u3158': '\u116A',
  13996. '\u3159': '\u116B',
  13997. '\u315A': '\u116C',
  13998. '\u315B': '\u116D',
  13999. '\u315C': '\u116E',
  14000. '\u315D': '\u116F',
  14001. '\u315E': '\u1170',
  14002. '\u315F': '\u1171',
  14003. '\u3160': '\u1172',
  14004. '\u3161': '\u1173',
  14005. '\u3162': '\u1174',
  14006. '\u3163': '\u1175',
  14007. '\u3164': '\u1160',
  14008. '\u3165': '\u1114',
  14009. '\u3166': '\u1115',
  14010. '\u3167': '\u11C7',
  14011. '\u3168': '\u11C8',
  14012. '\u3169': '\u11CC',
  14013. '\u316A': '\u11CE',
  14014. '\u316B': '\u11D3',
  14015. '\u316C': '\u11D7',
  14016. '\u316D': '\u11D9',
  14017. '\u316E': '\u111C',
  14018. '\u316F': '\u11DD',
  14019. '\u3170': '\u11DF',
  14020. '\u3171': '\u111D',
  14021. '\u3172': '\u111E',
  14022. '\u3173': '\u1120',
  14023. '\u3174': '\u1122',
  14024. '\u3175': '\u1123',
  14025. '\u3176': '\u1127',
  14026. '\u3177': '\u1129',
  14027. '\u3178': '\u112B',
  14028. '\u3179': '\u112C',
  14029. '\u317A': '\u112D',
  14030. '\u317B': '\u112E',
  14031. '\u317C': '\u112F',
  14032. '\u317D': '\u1132',
  14033. '\u317E': '\u1136',
  14034. '\u317F': '\u1140',
  14035. '\u3180': '\u1147',
  14036. '\u3181': '\u114C',
  14037. '\u3182': '\u11F1',
  14038. '\u3183': '\u11F2',
  14039. '\u3184': '\u1157',
  14040. '\u3185': '\u1158',
  14041. '\u3186': '\u1159',
  14042. '\u3187': '\u1184',
  14043. '\u3188': '\u1185',
  14044. '\u3189': '\u1188',
  14045. '\u318A': '\u1191',
  14046. '\u318B': '\u1192',
  14047. '\u318C': '\u1194',
  14048. '\u318D': '\u119E',
  14049. '\u318E': '\u11A1',
  14050. '\u3200': '\u0028\u1100\u0029',
  14051. '\u3201': '\u0028\u1102\u0029',
  14052. '\u3202': '\u0028\u1103\u0029',
  14053. '\u3203': '\u0028\u1105\u0029',
  14054. '\u3204': '\u0028\u1106\u0029',
  14055. '\u3205': '\u0028\u1107\u0029',
  14056. '\u3206': '\u0028\u1109\u0029',
  14057. '\u3207': '\u0028\u110B\u0029',
  14058. '\u3208': '\u0028\u110C\u0029',
  14059. '\u3209': '\u0028\u110E\u0029',
  14060. '\u320A': '\u0028\u110F\u0029',
  14061. '\u320B': '\u0028\u1110\u0029',
  14062. '\u320C': '\u0028\u1111\u0029',
  14063. '\u320D': '\u0028\u1112\u0029',
  14064. '\u320E': '\u0028\u1100\u1161\u0029',
  14065. '\u320F': '\u0028\u1102\u1161\u0029',
  14066. '\u3210': '\u0028\u1103\u1161\u0029',
  14067. '\u3211': '\u0028\u1105\u1161\u0029',
  14068. '\u3212': '\u0028\u1106\u1161\u0029',
  14069. '\u3213': '\u0028\u1107\u1161\u0029',
  14070. '\u3214': '\u0028\u1109\u1161\u0029',
  14071. '\u3215': '\u0028\u110B\u1161\u0029',
  14072. '\u3216': '\u0028\u110C\u1161\u0029',
  14073. '\u3217': '\u0028\u110E\u1161\u0029',
  14074. '\u3218': '\u0028\u110F\u1161\u0029',
  14075. '\u3219': '\u0028\u1110\u1161\u0029',
  14076. '\u321A': '\u0028\u1111\u1161\u0029',
  14077. '\u321B': '\u0028\u1112\u1161\u0029',
  14078. '\u321C': '\u0028\u110C\u116E\u0029',
  14079. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14080. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14081. '\u3220': '\u0028\u4E00\u0029',
  14082. '\u3221': '\u0028\u4E8C\u0029',
  14083. '\u3222': '\u0028\u4E09\u0029',
  14084. '\u3223': '\u0028\u56DB\u0029',
  14085. '\u3224': '\u0028\u4E94\u0029',
  14086. '\u3225': '\u0028\u516D\u0029',
  14087. '\u3226': '\u0028\u4E03\u0029',
  14088. '\u3227': '\u0028\u516B\u0029',
  14089. '\u3228': '\u0028\u4E5D\u0029',
  14090. '\u3229': '\u0028\u5341\u0029',
  14091. '\u322A': '\u0028\u6708\u0029',
  14092. '\u322B': '\u0028\u706B\u0029',
  14093. '\u322C': '\u0028\u6C34\u0029',
  14094. '\u322D': '\u0028\u6728\u0029',
  14095. '\u322E': '\u0028\u91D1\u0029',
  14096. '\u322F': '\u0028\u571F\u0029',
  14097. '\u3230': '\u0028\u65E5\u0029',
  14098. '\u3231': '\u0028\u682A\u0029',
  14099. '\u3232': '\u0028\u6709\u0029',
  14100. '\u3233': '\u0028\u793E\u0029',
  14101. '\u3234': '\u0028\u540D\u0029',
  14102. '\u3235': '\u0028\u7279\u0029',
  14103. '\u3236': '\u0028\u8CA1\u0029',
  14104. '\u3237': '\u0028\u795D\u0029',
  14105. '\u3238': '\u0028\u52B4\u0029',
  14106. '\u3239': '\u0028\u4EE3\u0029',
  14107. '\u323A': '\u0028\u547C\u0029',
  14108. '\u323B': '\u0028\u5B66\u0029',
  14109. '\u323C': '\u0028\u76E3\u0029',
  14110. '\u323D': '\u0028\u4F01\u0029',
  14111. '\u323E': '\u0028\u8CC7\u0029',
  14112. '\u323F': '\u0028\u5354\u0029',
  14113. '\u3240': '\u0028\u796D\u0029',
  14114. '\u3241': '\u0028\u4F11\u0029',
  14115. '\u3242': '\u0028\u81EA\u0029',
  14116. '\u3243': '\u0028\u81F3\u0029',
  14117. '\u32C0': '\u0031\u6708',
  14118. '\u32C1': '\u0032\u6708',
  14119. '\u32C2': '\u0033\u6708',
  14120. '\u32C3': '\u0034\u6708',
  14121. '\u32C4': '\u0035\u6708',
  14122. '\u32C5': '\u0036\u6708',
  14123. '\u32C6': '\u0037\u6708',
  14124. '\u32C7': '\u0038\u6708',
  14125. '\u32C8': '\u0039\u6708',
  14126. '\u32C9': '\u0031\u0030\u6708',
  14127. '\u32CA': '\u0031\u0031\u6708',
  14128. '\u32CB': '\u0031\u0032\u6708',
  14129. '\u3358': '\u0030\u70B9',
  14130. '\u3359': '\u0031\u70B9',
  14131. '\u335A': '\u0032\u70B9',
  14132. '\u335B': '\u0033\u70B9',
  14133. '\u335C': '\u0034\u70B9',
  14134. '\u335D': '\u0035\u70B9',
  14135. '\u335E': '\u0036\u70B9',
  14136. '\u335F': '\u0037\u70B9',
  14137. '\u3360': '\u0038\u70B9',
  14138. '\u3361': '\u0039\u70B9',
  14139. '\u3362': '\u0031\u0030\u70B9',
  14140. '\u3363': '\u0031\u0031\u70B9',
  14141. '\u3364': '\u0031\u0032\u70B9',
  14142. '\u3365': '\u0031\u0033\u70B9',
  14143. '\u3366': '\u0031\u0034\u70B9',
  14144. '\u3367': '\u0031\u0035\u70B9',
  14145. '\u3368': '\u0031\u0036\u70B9',
  14146. '\u3369': '\u0031\u0037\u70B9',
  14147. '\u336A': '\u0031\u0038\u70B9',
  14148. '\u336B': '\u0031\u0039\u70B9',
  14149. '\u336C': '\u0032\u0030\u70B9',
  14150. '\u336D': '\u0032\u0031\u70B9',
  14151. '\u336E': '\u0032\u0032\u70B9',
  14152. '\u336F': '\u0032\u0033\u70B9',
  14153. '\u3370': '\u0032\u0034\u70B9',
  14154. '\u33E0': '\u0031\u65E5',
  14155. '\u33E1': '\u0032\u65E5',
  14156. '\u33E2': '\u0033\u65E5',
  14157. '\u33E3': '\u0034\u65E5',
  14158. '\u33E4': '\u0035\u65E5',
  14159. '\u33E5': '\u0036\u65E5',
  14160. '\u33E6': '\u0037\u65E5',
  14161. '\u33E7': '\u0038\u65E5',
  14162. '\u33E8': '\u0039\u65E5',
  14163. '\u33E9': '\u0031\u0030\u65E5',
  14164. '\u33EA': '\u0031\u0031\u65E5',
  14165. '\u33EB': '\u0031\u0032\u65E5',
  14166. '\u33EC': '\u0031\u0033\u65E5',
  14167. '\u33ED': '\u0031\u0034\u65E5',
  14168. '\u33EE': '\u0031\u0035\u65E5',
  14169. '\u33EF': '\u0031\u0036\u65E5',
  14170. '\u33F0': '\u0031\u0037\u65E5',
  14171. '\u33F1': '\u0031\u0038\u65E5',
  14172. '\u33F2': '\u0031\u0039\u65E5',
  14173. '\u33F3': '\u0032\u0030\u65E5',
  14174. '\u33F4': '\u0032\u0031\u65E5',
  14175. '\u33F5': '\u0032\u0032\u65E5',
  14176. '\u33F6': '\u0032\u0033\u65E5',
  14177. '\u33F7': '\u0032\u0034\u65E5',
  14178. '\u33F8': '\u0032\u0035\u65E5',
  14179. '\u33F9': '\u0032\u0036\u65E5',
  14180. '\u33FA': '\u0032\u0037\u65E5',
  14181. '\u33FB': '\u0032\u0038\u65E5',
  14182. '\u33FC': '\u0032\u0039\u65E5',
  14183. '\u33FD': '\u0033\u0030\u65E5',
  14184. '\u33FE': '\u0033\u0031\u65E5',
  14185. '\uFB00': '\u0066\u0066',
  14186. '\uFB01': '\u0066\u0069',
  14187. '\uFB02': '\u0066\u006C',
  14188. '\uFB03': '\u0066\u0066\u0069',
  14189. '\uFB04': '\u0066\u0066\u006C',
  14190. '\uFB05': '\u017F\u0074',
  14191. '\uFB06': '\u0073\u0074',
  14192. '\uFB13': '\u0574\u0576',
  14193. '\uFB14': '\u0574\u0565',
  14194. '\uFB15': '\u0574\u056B',
  14195. '\uFB16': '\u057E\u0576',
  14196. '\uFB17': '\u0574\u056D',
  14197. '\uFB4F': '\u05D0\u05DC',
  14198. '\uFB50': '\u0671',
  14199. '\uFB51': '\u0671',
  14200. '\uFB52': '\u067B',
  14201. '\uFB53': '\u067B',
  14202. '\uFB54': '\u067B',
  14203. '\uFB55': '\u067B',
  14204. '\uFB56': '\u067E',
  14205. '\uFB57': '\u067E',
  14206. '\uFB58': '\u067E',
  14207. '\uFB59': '\u067E',
  14208. '\uFB5A': '\u0680',
  14209. '\uFB5B': '\u0680',
  14210. '\uFB5C': '\u0680',
  14211. '\uFB5D': '\u0680',
  14212. '\uFB5E': '\u067A',
  14213. '\uFB5F': '\u067A',
  14214. '\uFB60': '\u067A',
  14215. '\uFB61': '\u067A',
  14216. '\uFB62': '\u067F',
  14217. '\uFB63': '\u067F',
  14218. '\uFB64': '\u067F',
  14219. '\uFB65': '\u067F',
  14220. '\uFB66': '\u0679',
  14221. '\uFB67': '\u0679',
  14222. '\uFB68': '\u0679',
  14223. '\uFB69': '\u0679',
  14224. '\uFB6A': '\u06A4',
  14225. '\uFB6B': '\u06A4',
  14226. '\uFB6C': '\u06A4',
  14227. '\uFB6D': '\u06A4',
  14228. '\uFB6E': '\u06A6',
  14229. '\uFB6F': '\u06A6',
  14230. '\uFB70': '\u06A6',
  14231. '\uFB71': '\u06A6',
  14232. '\uFB72': '\u0684',
  14233. '\uFB73': '\u0684',
  14234. '\uFB74': '\u0684',
  14235. '\uFB75': '\u0684',
  14236. '\uFB76': '\u0683',
  14237. '\uFB77': '\u0683',
  14238. '\uFB78': '\u0683',
  14239. '\uFB79': '\u0683',
  14240. '\uFB7A': '\u0686',
  14241. '\uFB7B': '\u0686',
  14242. '\uFB7C': '\u0686',
  14243. '\uFB7D': '\u0686',
  14244. '\uFB7E': '\u0687',
  14245. '\uFB7F': '\u0687',
  14246. '\uFB80': '\u0687',
  14247. '\uFB81': '\u0687',
  14248. '\uFB82': '\u068D',
  14249. '\uFB83': '\u068D',
  14250. '\uFB84': '\u068C',
  14251. '\uFB85': '\u068C',
  14252. '\uFB86': '\u068E',
  14253. '\uFB87': '\u068E',
  14254. '\uFB88': '\u0688',
  14255. '\uFB89': '\u0688',
  14256. '\uFB8A': '\u0698',
  14257. '\uFB8B': '\u0698',
  14258. '\uFB8C': '\u0691',
  14259. '\uFB8D': '\u0691',
  14260. '\uFB8E': '\u06A9',
  14261. '\uFB8F': '\u06A9',
  14262. '\uFB90': '\u06A9',
  14263. '\uFB91': '\u06A9',
  14264. '\uFB92': '\u06AF',
  14265. '\uFB93': '\u06AF',
  14266. '\uFB94': '\u06AF',
  14267. '\uFB95': '\u06AF',
  14268. '\uFB96': '\u06B3',
  14269. '\uFB97': '\u06B3',
  14270. '\uFB98': '\u06B3',
  14271. '\uFB99': '\u06B3',
  14272. '\uFB9A': '\u06B1',
  14273. '\uFB9B': '\u06B1',
  14274. '\uFB9C': '\u06B1',
  14275. '\uFB9D': '\u06B1',
  14276. '\uFB9E': '\u06BA',
  14277. '\uFB9F': '\u06BA',
  14278. '\uFBA0': '\u06BB',
  14279. '\uFBA1': '\u06BB',
  14280. '\uFBA2': '\u06BB',
  14281. '\uFBA3': '\u06BB',
  14282. '\uFBA4': '\u06C0',
  14283. '\uFBA5': '\u06C0',
  14284. '\uFBA6': '\u06C1',
  14285. '\uFBA7': '\u06C1',
  14286. '\uFBA8': '\u06C1',
  14287. '\uFBA9': '\u06C1',
  14288. '\uFBAA': '\u06BE',
  14289. '\uFBAB': '\u06BE',
  14290. '\uFBAC': '\u06BE',
  14291. '\uFBAD': '\u06BE',
  14292. '\uFBAE': '\u06D2',
  14293. '\uFBAF': '\u06D2',
  14294. '\uFBB0': '\u06D3',
  14295. '\uFBB1': '\u06D3',
  14296. '\uFBD3': '\u06AD',
  14297. '\uFBD4': '\u06AD',
  14298. '\uFBD5': '\u06AD',
  14299. '\uFBD6': '\u06AD',
  14300. '\uFBD7': '\u06C7',
  14301. '\uFBD8': '\u06C7',
  14302. '\uFBD9': '\u06C6',
  14303. '\uFBDA': '\u06C6',
  14304. '\uFBDB': '\u06C8',
  14305. '\uFBDC': '\u06C8',
  14306. '\uFBDD': '\u0677',
  14307. '\uFBDE': '\u06CB',
  14308. '\uFBDF': '\u06CB',
  14309. '\uFBE0': '\u06C5',
  14310. '\uFBE1': '\u06C5',
  14311. '\uFBE2': '\u06C9',
  14312. '\uFBE3': '\u06C9',
  14313. '\uFBE4': '\u06D0',
  14314. '\uFBE5': '\u06D0',
  14315. '\uFBE6': '\u06D0',
  14316. '\uFBE7': '\u06D0',
  14317. '\uFBE8': '\u0649',
  14318. '\uFBE9': '\u0649',
  14319. '\uFBEA': '\u0626\u0627',
  14320. '\uFBEB': '\u0626\u0627',
  14321. '\uFBEC': '\u0626\u06D5',
  14322. '\uFBED': '\u0626\u06D5',
  14323. '\uFBEE': '\u0626\u0648',
  14324. '\uFBEF': '\u0626\u0648',
  14325. '\uFBF0': '\u0626\u06C7',
  14326. '\uFBF1': '\u0626\u06C7',
  14327. '\uFBF2': '\u0626\u06C6',
  14328. '\uFBF3': '\u0626\u06C6',
  14329. '\uFBF4': '\u0626\u06C8',
  14330. '\uFBF5': '\u0626\u06C8',
  14331. '\uFBF6': '\u0626\u06D0',
  14332. '\uFBF7': '\u0626\u06D0',
  14333. '\uFBF8': '\u0626\u06D0',
  14334. '\uFBF9': '\u0626\u0649',
  14335. '\uFBFA': '\u0626\u0649',
  14336. '\uFBFB': '\u0626\u0649',
  14337. '\uFBFC': '\u06CC',
  14338. '\uFBFD': '\u06CC',
  14339. '\uFBFE': '\u06CC',
  14340. '\uFBFF': '\u06CC',
  14341. '\uFC00': '\u0626\u062C',
  14342. '\uFC01': '\u0626\u062D',
  14343. '\uFC02': '\u0626\u0645',
  14344. '\uFC03': '\u0626\u0649',
  14345. '\uFC04': '\u0626\u064A',
  14346. '\uFC05': '\u0628\u062C',
  14347. '\uFC06': '\u0628\u062D',
  14348. '\uFC07': '\u0628\u062E',
  14349. '\uFC08': '\u0628\u0645',
  14350. '\uFC09': '\u0628\u0649',
  14351. '\uFC0A': '\u0628\u064A',
  14352. '\uFC0B': '\u062A\u062C',
  14353. '\uFC0C': '\u062A\u062D',
  14354. '\uFC0D': '\u062A\u062E',
  14355. '\uFC0E': '\u062A\u0645',
  14356. '\uFC0F': '\u062A\u0649',
  14357. '\uFC10': '\u062A\u064A',
  14358. '\uFC11': '\u062B\u062C',
  14359. '\uFC12': '\u062B\u0645',
  14360. '\uFC13': '\u062B\u0649',
  14361. '\uFC14': '\u062B\u064A',
  14362. '\uFC15': '\u062C\u062D',
  14363. '\uFC16': '\u062C\u0645',
  14364. '\uFC17': '\u062D\u062C',
  14365. '\uFC18': '\u062D\u0645',
  14366. '\uFC19': '\u062E\u062C',
  14367. '\uFC1A': '\u062E\u062D',
  14368. '\uFC1B': '\u062E\u0645',
  14369. '\uFC1C': '\u0633\u062C',
  14370. '\uFC1D': '\u0633\u062D',
  14371. '\uFC1E': '\u0633\u062E',
  14372. '\uFC1F': '\u0633\u0645',
  14373. '\uFC20': '\u0635\u062D',
  14374. '\uFC21': '\u0635\u0645',
  14375. '\uFC22': '\u0636\u062C',
  14376. '\uFC23': '\u0636\u062D',
  14377. '\uFC24': '\u0636\u062E',
  14378. '\uFC25': '\u0636\u0645',
  14379. '\uFC26': '\u0637\u062D',
  14380. '\uFC27': '\u0637\u0645',
  14381. '\uFC28': '\u0638\u0645',
  14382. '\uFC29': '\u0639\u062C',
  14383. '\uFC2A': '\u0639\u0645',
  14384. '\uFC2B': '\u063A\u062C',
  14385. '\uFC2C': '\u063A\u0645',
  14386. '\uFC2D': '\u0641\u062C',
  14387. '\uFC2E': '\u0641\u062D',
  14388. '\uFC2F': '\u0641\u062E',
  14389. '\uFC30': '\u0641\u0645',
  14390. '\uFC31': '\u0641\u0649',
  14391. '\uFC32': '\u0641\u064A',
  14392. '\uFC33': '\u0642\u062D',
  14393. '\uFC34': '\u0642\u0645',
  14394. '\uFC35': '\u0642\u0649',
  14395. '\uFC36': '\u0642\u064A',
  14396. '\uFC37': '\u0643\u0627',
  14397. '\uFC38': '\u0643\u062C',
  14398. '\uFC39': '\u0643\u062D',
  14399. '\uFC3A': '\u0643\u062E',
  14400. '\uFC3B': '\u0643\u0644',
  14401. '\uFC3C': '\u0643\u0645',
  14402. '\uFC3D': '\u0643\u0649',
  14403. '\uFC3E': '\u0643\u064A',
  14404. '\uFC3F': '\u0644\u062C',
  14405. '\uFC40': '\u0644\u062D',
  14406. '\uFC41': '\u0644\u062E',
  14407. '\uFC42': '\u0644\u0645',
  14408. '\uFC43': '\u0644\u0649',
  14409. '\uFC44': '\u0644\u064A',
  14410. '\uFC45': '\u0645\u062C',
  14411. '\uFC46': '\u0645\u062D',
  14412. '\uFC47': '\u0645\u062E',
  14413. '\uFC48': '\u0645\u0645',
  14414. '\uFC49': '\u0645\u0649',
  14415. '\uFC4A': '\u0645\u064A',
  14416. '\uFC4B': '\u0646\u062C',
  14417. '\uFC4C': '\u0646\u062D',
  14418. '\uFC4D': '\u0646\u062E',
  14419. '\uFC4E': '\u0646\u0645',
  14420. '\uFC4F': '\u0646\u0649',
  14421. '\uFC50': '\u0646\u064A',
  14422. '\uFC51': '\u0647\u062C',
  14423. '\uFC52': '\u0647\u0645',
  14424. '\uFC53': '\u0647\u0649',
  14425. '\uFC54': '\u0647\u064A',
  14426. '\uFC55': '\u064A\u062C',
  14427. '\uFC56': '\u064A\u062D',
  14428. '\uFC57': '\u064A\u062E',
  14429. '\uFC58': '\u064A\u0645',
  14430. '\uFC59': '\u064A\u0649',
  14431. '\uFC5A': '\u064A\u064A',
  14432. '\uFC5B': '\u0630\u0670',
  14433. '\uFC5C': '\u0631\u0670',
  14434. '\uFC5D': '\u0649\u0670',
  14435. '\uFC5E': '\u0020\u064C\u0651',
  14436. '\uFC5F': '\u0020\u064D\u0651',
  14437. '\uFC60': '\u0020\u064E\u0651',
  14438. '\uFC61': '\u0020\u064F\u0651',
  14439. '\uFC62': '\u0020\u0650\u0651',
  14440. '\uFC63': '\u0020\u0651\u0670',
  14441. '\uFC64': '\u0626\u0631',
  14442. '\uFC65': '\u0626\u0632',
  14443. '\uFC66': '\u0626\u0645',
  14444. '\uFC67': '\u0626\u0646',
  14445. '\uFC68': '\u0626\u0649',
  14446. '\uFC69': '\u0626\u064A',
  14447. '\uFC6A': '\u0628\u0631',
  14448. '\uFC6B': '\u0628\u0632',
  14449. '\uFC6C': '\u0628\u0645',
  14450. '\uFC6D': '\u0628\u0646',
  14451. '\uFC6E': '\u0628\u0649',
  14452. '\uFC6F': '\u0628\u064A',
  14453. '\uFC70': '\u062A\u0631',
  14454. '\uFC71': '\u062A\u0632',
  14455. '\uFC72': '\u062A\u0645',
  14456. '\uFC73': '\u062A\u0646',
  14457. '\uFC74': '\u062A\u0649',
  14458. '\uFC75': '\u062A\u064A',
  14459. '\uFC76': '\u062B\u0631',
  14460. '\uFC77': '\u062B\u0632',
  14461. '\uFC78': '\u062B\u0645',
  14462. '\uFC79': '\u062B\u0646',
  14463. '\uFC7A': '\u062B\u0649',
  14464. '\uFC7B': '\u062B\u064A',
  14465. '\uFC7C': '\u0641\u0649',
  14466. '\uFC7D': '\u0641\u064A',
  14467. '\uFC7E': '\u0642\u0649',
  14468. '\uFC7F': '\u0642\u064A',
  14469. '\uFC80': '\u0643\u0627',
  14470. '\uFC81': '\u0643\u0644',
  14471. '\uFC82': '\u0643\u0645',
  14472. '\uFC83': '\u0643\u0649',
  14473. '\uFC84': '\u0643\u064A',
  14474. '\uFC85': '\u0644\u0645',
  14475. '\uFC86': '\u0644\u0649',
  14476. '\uFC87': '\u0644\u064A',
  14477. '\uFC88': '\u0645\u0627',
  14478. '\uFC89': '\u0645\u0645',
  14479. '\uFC8A': '\u0646\u0631',
  14480. '\uFC8B': '\u0646\u0632',
  14481. '\uFC8C': '\u0646\u0645',
  14482. '\uFC8D': '\u0646\u0646',
  14483. '\uFC8E': '\u0646\u0649',
  14484. '\uFC8F': '\u0646\u064A',
  14485. '\uFC90': '\u0649\u0670',
  14486. '\uFC91': '\u064A\u0631',
  14487. '\uFC92': '\u064A\u0632',
  14488. '\uFC93': '\u064A\u0645',
  14489. '\uFC94': '\u064A\u0646',
  14490. '\uFC95': '\u064A\u0649',
  14491. '\uFC96': '\u064A\u064A',
  14492. '\uFC97': '\u0626\u062C',
  14493. '\uFC98': '\u0626\u062D',
  14494. '\uFC99': '\u0626\u062E',
  14495. '\uFC9A': '\u0626\u0645',
  14496. '\uFC9B': '\u0626\u0647',
  14497. '\uFC9C': '\u0628\u062C',
  14498. '\uFC9D': '\u0628\u062D',
  14499. '\uFC9E': '\u0628\u062E',
  14500. '\uFC9F': '\u0628\u0645',
  14501. '\uFCA0': '\u0628\u0647',
  14502. '\uFCA1': '\u062A\u062C',
  14503. '\uFCA2': '\u062A\u062D',
  14504. '\uFCA3': '\u062A\u062E',
  14505. '\uFCA4': '\u062A\u0645',
  14506. '\uFCA5': '\u062A\u0647',
  14507. '\uFCA6': '\u062B\u0645',
  14508. '\uFCA7': '\u062C\u062D',
  14509. '\uFCA8': '\u062C\u0645',
  14510. '\uFCA9': '\u062D\u062C',
  14511. '\uFCAA': '\u062D\u0645',
  14512. '\uFCAB': '\u062E\u062C',
  14513. '\uFCAC': '\u062E\u0645',
  14514. '\uFCAD': '\u0633\u062C',
  14515. '\uFCAE': '\u0633\u062D',
  14516. '\uFCAF': '\u0633\u062E',
  14517. '\uFCB0': '\u0633\u0645',
  14518. '\uFCB1': '\u0635\u062D',
  14519. '\uFCB2': '\u0635\u062E',
  14520. '\uFCB3': '\u0635\u0645',
  14521. '\uFCB4': '\u0636\u062C',
  14522. '\uFCB5': '\u0636\u062D',
  14523. '\uFCB6': '\u0636\u062E',
  14524. '\uFCB7': '\u0636\u0645',
  14525. '\uFCB8': '\u0637\u062D',
  14526. '\uFCB9': '\u0638\u0645',
  14527. '\uFCBA': '\u0639\u062C',
  14528. '\uFCBB': '\u0639\u0645',
  14529. '\uFCBC': '\u063A\u062C',
  14530. '\uFCBD': '\u063A\u0645',
  14531. '\uFCBE': '\u0641\u062C',
  14532. '\uFCBF': '\u0641\u062D',
  14533. '\uFCC0': '\u0641\u062E',
  14534. '\uFCC1': '\u0641\u0645',
  14535. '\uFCC2': '\u0642\u062D',
  14536. '\uFCC3': '\u0642\u0645',
  14537. '\uFCC4': '\u0643\u062C',
  14538. '\uFCC5': '\u0643\u062D',
  14539. '\uFCC6': '\u0643\u062E',
  14540. '\uFCC7': '\u0643\u0644',
  14541. '\uFCC8': '\u0643\u0645',
  14542. '\uFCC9': '\u0644\u062C',
  14543. '\uFCCA': '\u0644\u062D',
  14544. '\uFCCB': '\u0644\u062E',
  14545. '\uFCCC': '\u0644\u0645',
  14546. '\uFCCD': '\u0644\u0647',
  14547. '\uFCCE': '\u0645\u062C',
  14548. '\uFCCF': '\u0645\u062D',
  14549. '\uFCD0': '\u0645\u062E',
  14550. '\uFCD1': '\u0645\u0645',
  14551. '\uFCD2': '\u0646\u062C',
  14552. '\uFCD3': '\u0646\u062D',
  14553. '\uFCD4': '\u0646\u062E',
  14554. '\uFCD5': '\u0646\u0645',
  14555. '\uFCD6': '\u0646\u0647',
  14556. '\uFCD7': '\u0647\u062C',
  14557. '\uFCD8': '\u0647\u0645',
  14558. '\uFCD9': '\u0647\u0670',
  14559. '\uFCDA': '\u064A\u062C',
  14560. '\uFCDB': '\u064A\u062D',
  14561. '\uFCDC': '\u064A\u062E',
  14562. '\uFCDD': '\u064A\u0645',
  14563. '\uFCDE': '\u064A\u0647',
  14564. '\uFCDF': '\u0626\u0645',
  14565. '\uFCE0': '\u0626\u0647',
  14566. '\uFCE1': '\u0628\u0645',
  14567. '\uFCE2': '\u0628\u0647',
  14568. '\uFCE3': '\u062A\u0645',
  14569. '\uFCE4': '\u062A\u0647',
  14570. '\uFCE5': '\u062B\u0645',
  14571. '\uFCE6': '\u062B\u0647',
  14572. '\uFCE7': '\u0633\u0645',
  14573. '\uFCE8': '\u0633\u0647',
  14574. '\uFCE9': '\u0634\u0645',
  14575. '\uFCEA': '\u0634\u0647',
  14576. '\uFCEB': '\u0643\u0644',
  14577. '\uFCEC': '\u0643\u0645',
  14578. '\uFCED': '\u0644\u0645',
  14579. '\uFCEE': '\u0646\u0645',
  14580. '\uFCEF': '\u0646\u0647',
  14581. '\uFCF0': '\u064A\u0645',
  14582. '\uFCF1': '\u064A\u0647',
  14583. '\uFCF2': '\u0640\u064E\u0651',
  14584. '\uFCF3': '\u0640\u064F\u0651',
  14585. '\uFCF4': '\u0640\u0650\u0651',
  14586. '\uFCF5': '\u0637\u0649',
  14587. '\uFCF6': '\u0637\u064A',
  14588. '\uFCF7': '\u0639\u0649',
  14589. '\uFCF8': '\u0639\u064A',
  14590. '\uFCF9': '\u063A\u0649',
  14591. '\uFCFA': '\u063A\u064A',
  14592. '\uFCFB': '\u0633\u0649',
  14593. '\uFCFC': '\u0633\u064A',
  14594. '\uFCFD': '\u0634\u0649',
  14595. '\uFCFE': '\u0634\u064A',
  14596. '\uFCFF': '\u062D\u0649',
  14597. '\uFD00': '\u062D\u064A',
  14598. '\uFD01': '\u062C\u0649',
  14599. '\uFD02': '\u062C\u064A',
  14600. '\uFD03': '\u062E\u0649',
  14601. '\uFD04': '\u062E\u064A',
  14602. '\uFD05': '\u0635\u0649',
  14603. '\uFD06': '\u0635\u064A',
  14604. '\uFD07': '\u0636\u0649',
  14605. '\uFD08': '\u0636\u064A',
  14606. '\uFD09': '\u0634\u062C',
  14607. '\uFD0A': '\u0634\u062D',
  14608. '\uFD0B': '\u0634\u062E',
  14609. '\uFD0C': '\u0634\u0645',
  14610. '\uFD0D': '\u0634\u0631',
  14611. '\uFD0E': '\u0633\u0631',
  14612. '\uFD0F': '\u0635\u0631',
  14613. '\uFD10': '\u0636\u0631',
  14614. '\uFD11': '\u0637\u0649',
  14615. '\uFD12': '\u0637\u064A',
  14616. '\uFD13': '\u0639\u0649',
  14617. '\uFD14': '\u0639\u064A',
  14618. '\uFD15': '\u063A\u0649',
  14619. '\uFD16': '\u063A\u064A',
  14620. '\uFD17': '\u0633\u0649',
  14621. '\uFD18': '\u0633\u064A',
  14622. '\uFD19': '\u0634\u0649',
  14623. '\uFD1A': '\u0634\u064A',
  14624. '\uFD1B': '\u062D\u0649',
  14625. '\uFD1C': '\u062D\u064A',
  14626. '\uFD1D': '\u062C\u0649',
  14627. '\uFD1E': '\u062C\u064A',
  14628. '\uFD1F': '\u062E\u0649',
  14629. '\uFD20': '\u062E\u064A',
  14630. '\uFD21': '\u0635\u0649',
  14631. '\uFD22': '\u0635\u064A',
  14632. '\uFD23': '\u0636\u0649',
  14633. '\uFD24': '\u0636\u064A',
  14634. '\uFD25': '\u0634\u062C',
  14635. '\uFD26': '\u0634\u062D',
  14636. '\uFD27': '\u0634\u062E',
  14637. '\uFD28': '\u0634\u0645',
  14638. '\uFD29': '\u0634\u0631',
  14639. '\uFD2A': '\u0633\u0631',
  14640. '\uFD2B': '\u0635\u0631',
  14641. '\uFD2C': '\u0636\u0631',
  14642. '\uFD2D': '\u0634\u062C',
  14643. '\uFD2E': '\u0634\u062D',
  14644. '\uFD2F': '\u0634\u062E',
  14645. '\uFD30': '\u0634\u0645',
  14646. '\uFD31': '\u0633\u0647',
  14647. '\uFD32': '\u0634\u0647',
  14648. '\uFD33': '\u0637\u0645',
  14649. '\uFD34': '\u0633\u062C',
  14650. '\uFD35': '\u0633\u062D',
  14651. '\uFD36': '\u0633\u062E',
  14652. '\uFD37': '\u0634\u062C',
  14653. '\uFD38': '\u0634\u062D',
  14654. '\uFD39': '\u0634\u062E',
  14655. '\uFD3A': '\u0637\u0645',
  14656. '\uFD3B': '\u0638\u0645',
  14657. '\uFD3C': '\u0627\u064B',
  14658. '\uFD3D': '\u0627\u064B',
  14659. '\uFD50': '\u062A\u062C\u0645',
  14660. '\uFD51': '\u062A\u062D\u062C',
  14661. '\uFD52': '\u062A\u062D\u062C',
  14662. '\uFD53': '\u062A\u062D\u0645',
  14663. '\uFD54': '\u062A\u062E\u0645',
  14664. '\uFD55': '\u062A\u0645\u062C',
  14665. '\uFD56': '\u062A\u0645\u062D',
  14666. '\uFD57': '\u062A\u0645\u062E',
  14667. '\uFD58': '\u062C\u0645\u062D',
  14668. '\uFD59': '\u062C\u0645\u062D',
  14669. '\uFD5A': '\u062D\u0645\u064A',
  14670. '\uFD5B': '\u062D\u0645\u0649',
  14671. '\uFD5C': '\u0633\u062D\u062C',
  14672. '\uFD5D': '\u0633\u062C\u062D',
  14673. '\uFD5E': '\u0633\u062C\u0649',
  14674. '\uFD5F': '\u0633\u0645\u062D',
  14675. '\uFD60': '\u0633\u0645\u062D',
  14676. '\uFD61': '\u0633\u0645\u062C',
  14677. '\uFD62': '\u0633\u0645\u0645',
  14678. '\uFD63': '\u0633\u0645\u0645',
  14679. '\uFD64': '\u0635\u062D\u062D',
  14680. '\uFD65': '\u0635\u062D\u062D',
  14681. '\uFD66': '\u0635\u0645\u0645',
  14682. '\uFD67': '\u0634\u062D\u0645',
  14683. '\uFD68': '\u0634\u062D\u0645',
  14684. '\uFD69': '\u0634\u062C\u064A',
  14685. '\uFD6A': '\u0634\u0645\u062E',
  14686. '\uFD6B': '\u0634\u0645\u062E',
  14687. '\uFD6C': '\u0634\u0645\u0645',
  14688. '\uFD6D': '\u0634\u0645\u0645',
  14689. '\uFD6E': '\u0636\u062D\u0649',
  14690. '\uFD6F': '\u0636\u062E\u0645',
  14691. '\uFD70': '\u0636\u062E\u0645',
  14692. '\uFD71': '\u0637\u0645\u062D',
  14693. '\uFD72': '\u0637\u0645\u062D',
  14694. '\uFD73': '\u0637\u0645\u0645',
  14695. '\uFD74': '\u0637\u0645\u064A',
  14696. '\uFD75': '\u0639\u062C\u0645',
  14697. '\uFD76': '\u0639\u0645\u0645',
  14698. '\uFD77': '\u0639\u0645\u0645',
  14699. '\uFD78': '\u0639\u0645\u0649',
  14700. '\uFD79': '\u063A\u0645\u0645',
  14701. '\uFD7A': '\u063A\u0645\u064A',
  14702. '\uFD7B': '\u063A\u0645\u0649',
  14703. '\uFD7C': '\u0641\u062E\u0645',
  14704. '\uFD7D': '\u0641\u062E\u0645',
  14705. '\uFD7E': '\u0642\u0645\u062D',
  14706. '\uFD7F': '\u0642\u0645\u0645',
  14707. '\uFD80': '\u0644\u062D\u0645',
  14708. '\uFD81': '\u0644\u062D\u064A',
  14709. '\uFD82': '\u0644\u062D\u0649',
  14710. '\uFD83': '\u0644\u062C\u062C',
  14711. '\uFD84': '\u0644\u062C\u062C',
  14712. '\uFD85': '\u0644\u062E\u0645',
  14713. '\uFD86': '\u0644\u062E\u0645',
  14714. '\uFD87': '\u0644\u0645\u062D',
  14715. '\uFD88': '\u0644\u0645\u062D',
  14716. '\uFD89': '\u0645\u062D\u062C',
  14717. '\uFD8A': '\u0645\u062D\u0645',
  14718. '\uFD8B': '\u0645\u062D\u064A',
  14719. '\uFD8C': '\u0645\u062C\u062D',
  14720. '\uFD8D': '\u0645\u062C\u0645',
  14721. '\uFD8E': '\u0645\u062E\u062C',
  14722. '\uFD8F': '\u0645\u062E\u0645',
  14723. '\uFD92': '\u0645\u062C\u062E',
  14724. '\uFD93': '\u0647\u0645\u062C',
  14725. '\uFD94': '\u0647\u0645\u0645',
  14726. '\uFD95': '\u0646\u062D\u0645',
  14727. '\uFD96': '\u0646\u062D\u0649',
  14728. '\uFD97': '\u0646\u062C\u0645',
  14729. '\uFD98': '\u0646\u062C\u0645',
  14730. '\uFD99': '\u0646\u062C\u0649',
  14731. '\uFD9A': '\u0646\u0645\u064A',
  14732. '\uFD9B': '\u0646\u0645\u0649',
  14733. '\uFD9C': '\u064A\u0645\u0645',
  14734. '\uFD9D': '\u064A\u0645\u0645',
  14735. '\uFD9E': '\u0628\u062E\u064A',
  14736. '\uFD9F': '\u062A\u062C\u064A',
  14737. '\uFDA0': '\u062A\u062C\u0649',
  14738. '\uFDA1': '\u062A\u062E\u064A',
  14739. '\uFDA2': '\u062A\u062E\u0649',
  14740. '\uFDA3': '\u062A\u0645\u064A',
  14741. '\uFDA4': '\u062A\u0645\u0649',
  14742. '\uFDA5': '\u062C\u0645\u064A',
  14743. '\uFDA6': '\u062C\u062D\u0649',
  14744. '\uFDA7': '\u062C\u0645\u0649',
  14745. '\uFDA8': '\u0633\u062E\u0649',
  14746. '\uFDA9': '\u0635\u062D\u064A',
  14747. '\uFDAA': '\u0634\u062D\u064A',
  14748. '\uFDAB': '\u0636\u062D\u064A',
  14749. '\uFDAC': '\u0644\u062C\u064A',
  14750. '\uFDAD': '\u0644\u0645\u064A',
  14751. '\uFDAE': '\u064A\u062D\u064A',
  14752. '\uFDAF': '\u064A\u062C\u064A',
  14753. '\uFDB0': '\u064A\u0645\u064A',
  14754. '\uFDB1': '\u0645\u0645\u064A',
  14755. '\uFDB2': '\u0642\u0645\u064A',
  14756. '\uFDB3': '\u0646\u062D\u064A',
  14757. '\uFDB4': '\u0642\u0645\u062D',
  14758. '\uFDB5': '\u0644\u062D\u0645',
  14759. '\uFDB6': '\u0639\u0645\u064A',
  14760. '\uFDB7': '\u0643\u0645\u064A',
  14761. '\uFDB8': '\u0646\u062C\u062D',
  14762. '\uFDB9': '\u0645\u062E\u064A',
  14763. '\uFDBA': '\u0644\u062C\u0645',
  14764. '\uFDBB': '\u0643\u0645\u0645',
  14765. '\uFDBC': '\u0644\u062C\u0645',
  14766. '\uFDBD': '\u0646\u062C\u062D',
  14767. '\uFDBE': '\u062C\u062D\u064A',
  14768. '\uFDBF': '\u062D\u062C\u064A',
  14769. '\uFDC0': '\u0645\u062C\u064A',
  14770. '\uFDC1': '\u0641\u0645\u064A',
  14771. '\uFDC2': '\u0628\u062D\u064A',
  14772. '\uFDC3': '\u0643\u0645\u0645',
  14773. '\uFDC4': '\u0639\u062C\u0645',
  14774. '\uFDC5': '\u0635\u0645\u0645',
  14775. '\uFDC6': '\u0633\u062E\u064A',
  14776. '\uFDC7': '\u0646\u062C\u064A',
  14777. '\uFE49': '\u203E',
  14778. '\uFE4A': '\u203E',
  14779. '\uFE4B': '\u203E',
  14780. '\uFE4C': '\u203E',
  14781. '\uFE4D': '\u005F',
  14782. '\uFE4E': '\u005F',
  14783. '\uFE4F': '\u005F',
  14784. '\uFE80': '\u0621',
  14785. '\uFE81': '\u0622',
  14786. '\uFE82': '\u0622',
  14787. '\uFE83': '\u0623',
  14788. '\uFE84': '\u0623',
  14789. '\uFE85': '\u0624',
  14790. '\uFE86': '\u0624',
  14791. '\uFE87': '\u0625',
  14792. '\uFE88': '\u0625',
  14793. '\uFE89': '\u0626',
  14794. '\uFE8A': '\u0626',
  14795. '\uFE8B': '\u0626',
  14796. '\uFE8C': '\u0626',
  14797. '\uFE8D': '\u0627',
  14798. '\uFE8E': '\u0627',
  14799. '\uFE8F': '\u0628',
  14800. '\uFE90': '\u0628',
  14801. '\uFE91': '\u0628',
  14802. '\uFE92': '\u0628',
  14803. '\uFE93': '\u0629',
  14804. '\uFE94': '\u0629',
  14805. '\uFE95': '\u062A',
  14806. '\uFE96': '\u062A',
  14807. '\uFE97': '\u062A',
  14808. '\uFE98': '\u062A',
  14809. '\uFE99': '\u062B',
  14810. '\uFE9A': '\u062B',
  14811. '\uFE9B': '\u062B',
  14812. '\uFE9C': '\u062B',
  14813. '\uFE9D': '\u062C',
  14814. '\uFE9E': '\u062C',
  14815. '\uFE9F': '\u062C',
  14816. '\uFEA0': '\u062C',
  14817. '\uFEA1': '\u062D',
  14818. '\uFEA2': '\u062D',
  14819. '\uFEA3': '\u062D',
  14820. '\uFEA4': '\u062D',
  14821. '\uFEA5': '\u062E',
  14822. '\uFEA6': '\u062E',
  14823. '\uFEA7': '\u062E',
  14824. '\uFEA8': '\u062E',
  14825. '\uFEA9': '\u062F',
  14826. '\uFEAA': '\u062F',
  14827. '\uFEAB': '\u0630',
  14828. '\uFEAC': '\u0630',
  14829. '\uFEAD': '\u0631',
  14830. '\uFEAE': '\u0631',
  14831. '\uFEAF': '\u0632',
  14832. '\uFEB0': '\u0632',
  14833. '\uFEB1': '\u0633',
  14834. '\uFEB2': '\u0633',
  14835. '\uFEB3': '\u0633',
  14836. '\uFEB4': '\u0633',
  14837. '\uFEB5': '\u0634',
  14838. '\uFEB6': '\u0634',
  14839. '\uFEB7': '\u0634',
  14840. '\uFEB8': '\u0634',
  14841. '\uFEB9': '\u0635',
  14842. '\uFEBA': '\u0635',
  14843. '\uFEBB': '\u0635',
  14844. '\uFEBC': '\u0635',
  14845. '\uFEBD': '\u0636',
  14846. '\uFEBE': '\u0636',
  14847. '\uFEBF': '\u0636',
  14848. '\uFEC0': '\u0636',
  14849. '\uFEC1': '\u0637',
  14850. '\uFEC2': '\u0637',
  14851. '\uFEC3': '\u0637',
  14852. '\uFEC4': '\u0637',
  14853. '\uFEC5': '\u0638',
  14854. '\uFEC6': '\u0638',
  14855. '\uFEC7': '\u0638',
  14856. '\uFEC8': '\u0638',
  14857. '\uFEC9': '\u0639',
  14858. '\uFECA': '\u0639',
  14859. '\uFECB': '\u0639',
  14860. '\uFECC': '\u0639',
  14861. '\uFECD': '\u063A',
  14862. '\uFECE': '\u063A',
  14863. '\uFECF': '\u063A',
  14864. '\uFED0': '\u063A',
  14865. '\uFED1': '\u0641',
  14866. '\uFED2': '\u0641',
  14867. '\uFED3': '\u0641',
  14868. '\uFED4': '\u0641',
  14869. '\uFED5': '\u0642',
  14870. '\uFED6': '\u0642',
  14871. '\uFED7': '\u0642',
  14872. '\uFED8': '\u0642',
  14873. '\uFED9': '\u0643',
  14874. '\uFEDA': '\u0643',
  14875. '\uFEDB': '\u0643',
  14876. '\uFEDC': '\u0643',
  14877. '\uFEDD': '\u0644',
  14878. '\uFEDE': '\u0644',
  14879. '\uFEDF': '\u0644',
  14880. '\uFEE0': '\u0644',
  14881. '\uFEE1': '\u0645',
  14882. '\uFEE2': '\u0645',
  14883. '\uFEE3': '\u0645',
  14884. '\uFEE4': '\u0645',
  14885. '\uFEE5': '\u0646',
  14886. '\uFEE6': '\u0646',
  14887. '\uFEE7': '\u0646',
  14888. '\uFEE8': '\u0646',
  14889. '\uFEE9': '\u0647',
  14890. '\uFEEA': '\u0647',
  14891. '\uFEEB': '\u0647',
  14892. '\uFEEC': '\u0647',
  14893. '\uFEED': '\u0648',
  14894. '\uFEEE': '\u0648',
  14895. '\uFEEF': '\u0649',
  14896. '\uFEF0': '\u0649',
  14897. '\uFEF1': '\u064A',
  14898. '\uFEF2': '\u064A',
  14899. '\uFEF3': '\u064A',
  14900. '\uFEF4': '\u064A',
  14901. '\uFEF5': '\u0644\u0622',
  14902. '\uFEF6': '\u0644\u0622',
  14903. '\uFEF7': '\u0644\u0623',
  14904. '\uFEF8': '\u0644\u0623',
  14905. '\uFEF9': '\u0644\u0625',
  14906. '\uFEFA': '\u0644\u0625',
  14907. '\uFEFB': '\u0644\u0627',
  14908. '\uFEFC': '\u0644\u0627'
  14909. };
  14910. function reverseIfRtl(chars) {
  14911. var charsLength = chars.length;
  14912. //reverse an arabic ligature
  14913. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14914. return chars;
  14915. }
  14916. var s = '';
  14917. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14918. s += chars[ii];
  14919. }
  14920. return s;
  14921. }
  14922. function adjustWidths(properties) {
  14923. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14924. return;
  14925. }
  14926. // adjusting width to fontMatrix scale
  14927. var scale = 0.001 / properties.fontMatrix[0];
  14928. var glyphsWidths = properties.widths;
  14929. for (var glyph in glyphsWidths) {
  14930. glyphsWidths[glyph] *= scale;
  14931. }
  14932. properties.defaultWidth *= scale;
  14933. }
  14934. function getFontType(type, subtype) {
  14935. switch (type) {
  14936. case 'Type1':
  14937. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14938. case 'CIDFontType0':
  14939. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14940. FontType.CIDFONTTYPE0;
  14941. case 'OpenType':
  14942. return FontType.OPENTYPE;
  14943. case 'TrueType':
  14944. return FontType.TRUETYPE;
  14945. case 'CIDFontType2':
  14946. return FontType.CIDFONTTYPE2;
  14947. case 'MMType1':
  14948. return FontType.MMTYPE1;
  14949. case 'Type0':
  14950. return FontType.TYPE0;
  14951. default:
  14952. return FontType.UNKNOWN;
  14953. }
  14954. }
  14955. var Glyph = (function GlyphClosure() {
  14956. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14957. this.fontChar = fontChar;
  14958. this.unicode = unicode;
  14959. this.accent = accent;
  14960. this.width = width;
  14961. this.vmetric = vmetric;
  14962. this.operatorListId = operatorListId;
  14963. }
  14964. Glyph.prototype.matchesForCache =
  14965. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14966. return this.fontChar === fontChar &&
  14967. this.unicode === unicode &&
  14968. this.accent === accent &&
  14969. this.width === width &&
  14970. this.vmetric === vmetric &&
  14971. this.operatorListId === operatorListId;
  14972. };
  14973. return Glyph;
  14974. })();
  14975. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14976. function ToUnicodeMap(cmap) {
  14977. // The elements of this._map can be integers or strings, depending on how
  14978. // |cmap| was created.
  14979. this._map = cmap;
  14980. }
  14981. ToUnicodeMap.prototype = {
  14982. get length() {
  14983. return this._map.length;
  14984. },
  14985. forEach: function(callback) {
  14986. for (var charCode in this._map) {
  14987. callback(charCode, this._map[charCode].charCodeAt(0));
  14988. }
  14989. },
  14990. has: function(i) {
  14991. return this._map[i] !== undefined;
  14992. },
  14993. get: function(i) {
  14994. return this._map[i];
  14995. },
  14996. charCodeOf: function(v) {
  14997. return this._map.indexOf(v);
  14998. }
  14999. };
  15000. return ToUnicodeMap;
  15001. })();
  15002. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15003. function IdentityToUnicodeMap(firstChar, lastChar) {
  15004. this.firstChar = firstChar;
  15005. this.lastChar = lastChar;
  15006. }
  15007. IdentityToUnicodeMap.prototype = {
  15008. get length() {
  15009. error('should not access .length');
  15010. },
  15011. forEach: function (callback) {
  15012. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15013. callback(i, i);
  15014. }
  15015. },
  15016. has: function (i) {
  15017. return this.firstChar <= i && i <= this.lastChar;
  15018. },
  15019. get: function (i) {
  15020. if (this.firstChar <= i && i <= this.lastChar) {
  15021. return String.fromCharCode(i);
  15022. }
  15023. return undefined;
  15024. },
  15025. charCodeOf: function (v) {
  15026. error('should not call .charCodeOf');
  15027. }
  15028. };
  15029. return IdentityToUnicodeMap;
  15030. })();
  15031. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15032. function writeInt16(dest, offset, num) {
  15033. dest[offset] = (num >> 8) & 0xFF;
  15034. dest[offset + 1] = num & 0xFF;
  15035. }
  15036. function writeInt32(dest, offset, num) {
  15037. dest[offset] = (num >> 24) & 0xFF;
  15038. dest[offset + 1] = (num >> 16) & 0xFF;
  15039. dest[offset + 2] = (num >> 8) & 0xFF;
  15040. dest[offset + 3] = num & 0xFF;
  15041. }
  15042. function writeData(dest, offset, data) {
  15043. var i, ii;
  15044. if (data instanceof Uint8Array) {
  15045. dest.set(data, offset);
  15046. } else if (typeof data === 'string') {
  15047. for (i = 0, ii = data.length; i < ii; i++) {
  15048. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15049. }
  15050. } else {
  15051. // treating everything else as array
  15052. for (i = 0, ii = data.length; i < ii; i++) {
  15053. dest[offset++] = data[i] & 0xFF;
  15054. }
  15055. }
  15056. }
  15057. function OpenTypeFileBuilder(sfnt) {
  15058. this.sfnt = sfnt;
  15059. this.tables = Object.create(null);
  15060. }
  15061. OpenTypeFileBuilder.getSearchParams =
  15062. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15063. var maxPower2 = 1, log2 = 0;
  15064. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15065. maxPower2 <<= 1;
  15066. log2++;
  15067. }
  15068. var searchRange = maxPower2 * entrySize;
  15069. return {
  15070. range: searchRange,
  15071. entry: log2,
  15072. rangeShift: entrySize * entriesCount - searchRange
  15073. };
  15074. };
  15075. var OTF_HEADER_SIZE = 12;
  15076. var OTF_TABLE_ENTRY_SIZE = 16;
  15077. OpenTypeFileBuilder.prototype = {
  15078. toArray: function OpenTypeFileBuilder_toArray() {
  15079. var sfnt = this.sfnt;
  15080. // Tables needs to be written by ascendant alphabetic order
  15081. var tables = this.tables;
  15082. var tablesNames = Object.keys(tables);
  15083. tablesNames.sort();
  15084. var numTables = tablesNames.length;
  15085. var i, j, jj, table, tableName;
  15086. // layout the tables data
  15087. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15088. var tableOffsets = [offset];
  15089. for (i = 0; i < numTables; i++) {
  15090. table = tables[tablesNames[i]];
  15091. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15092. offset += paddedLength;
  15093. tableOffsets.push(offset);
  15094. }
  15095. var file = new Uint8Array(offset);
  15096. // write the table data first (mostly for checksum)
  15097. for (i = 0; i < numTables; i++) {
  15098. table = tables[tablesNames[i]];
  15099. writeData(file, tableOffsets[i], table);
  15100. }
  15101. // sfnt version (4 bytes)
  15102. if (sfnt === 'true') {
  15103. // Windows hates the Mac TrueType sfnt version number
  15104. sfnt = string32(0x00010000);
  15105. }
  15106. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15107. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15108. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15109. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15110. // numTables (2 bytes)
  15111. writeInt16(file, 4, numTables);
  15112. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15113. // searchRange (2 bytes)
  15114. writeInt16(file, 6, searchParams.range);
  15115. // entrySelector (2 bytes)
  15116. writeInt16(file, 8, searchParams.entry);
  15117. // rangeShift (2 bytes)
  15118. writeInt16(file, 10, searchParams.rangeShift);
  15119. offset = OTF_HEADER_SIZE;
  15120. // writing table entries
  15121. for (i = 0; i < numTables; i++) {
  15122. tableName = tablesNames[i];
  15123. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15124. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15125. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15126. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15127. // checksum
  15128. var checksum = 0;
  15129. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15130. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15131. (file[j + 2] << 8) + file[j + 3];
  15132. checksum = (checksum + quad) | 0;
  15133. }
  15134. writeInt32(file, offset + 4, checksum);
  15135. // offset
  15136. writeInt32(file, offset + 8, tableOffsets[i]);
  15137. // length
  15138. writeInt32(file, offset + 12, tables[tableName].length);
  15139. offset += OTF_TABLE_ENTRY_SIZE;
  15140. }
  15141. return file;
  15142. },
  15143. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15144. if (tag in this.tables) {
  15145. throw new Error('Table ' + tag + ' already exists');
  15146. }
  15147. this.tables[tag] = data;
  15148. }
  15149. };
  15150. return OpenTypeFileBuilder;
  15151. })();
  15152. /**
  15153. * 'Font' is the class the outside world should use, it encapsulate all the font
  15154. * decoding logics whatever type it is (assuming the font type is supported).
  15155. *
  15156. * For example to read a Type1 font and to attach it to the document:
  15157. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15158. * type1Font.bind();
  15159. */
  15160. var Font = (function FontClosure() {
  15161. function Font(name, file, properties) {
  15162. var charCode, glyphName, fontChar;
  15163. this.name = name;
  15164. this.loadedName = properties.loadedName;
  15165. this.isType3Font = properties.isType3Font;
  15166. this.sizes = [];
  15167. this.glyphCache = {};
  15168. var names = name.split('+');
  15169. names = names.length > 1 ? names[1] : names[0];
  15170. names = names.split(/[-,_]/g)[0];
  15171. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15172. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15173. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15174. var type = properties.type;
  15175. var subtype = properties.subtype;
  15176. this.type = type;
  15177. this.fallbackName = (this.isMonospace ? 'monospace' :
  15178. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15179. this.differences = properties.differences;
  15180. this.widths = properties.widths;
  15181. this.defaultWidth = properties.defaultWidth;
  15182. this.composite = properties.composite;
  15183. this.wideChars = properties.wideChars;
  15184. this.cMap = properties.cMap;
  15185. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15186. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15187. this.fontMatrix = properties.fontMatrix;
  15188. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15189. this.toFontChar = [];
  15190. if (properties.type === 'Type3') {
  15191. for (charCode = 0; charCode < 256; charCode++) {
  15192. this.toFontChar[charCode] = (this.differences[charCode] ||
  15193. properties.defaultEncoding[charCode]);
  15194. }
  15195. this.fontType = FontType.TYPE3;
  15196. return;
  15197. }
  15198. this.cidEncoding = properties.cidEncoding;
  15199. this.vertical = properties.vertical;
  15200. if (this.vertical) {
  15201. this.vmetrics = properties.vmetrics;
  15202. this.defaultVMetrics = properties.defaultVMetrics;
  15203. }
  15204. if (!file || file.isEmpty) {
  15205. if (file) {
  15206. // Some bad PDF generators will include empty font files,
  15207. // attempting to recover by assuming that no file exists.
  15208. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15209. }
  15210. this.missingFile = true;
  15211. // The file data is not specified. Trying to fix the font name
  15212. // to be used with the canvas.font.
  15213. var fontName = name.replace(/[,_]/g, '-');
  15214. var isStandardFont = !!stdFontMap[fontName] ||
  15215. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15216. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15217. this.bold = (fontName.search(/bold/gi) !== -1);
  15218. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15219. (fontName.search(/italic/gi) !== -1));
  15220. // Use 'name' instead of 'fontName' here because the original
  15221. // name ArialBlack for example will be replaced by Helvetica.
  15222. this.black = (name.search(/Black/g) !== -1);
  15223. // if at least one width is present, remeasure all chars when exists
  15224. this.remeasure = Object.keys(this.widths).length > 0;
  15225. if (isStandardFont && type === 'CIDFontType2' &&
  15226. properties.cidEncoding.indexOf('Identity-') === 0) {
  15227. // Standard fonts might be embedded as CID font without glyph mapping.
  15228. // Building one based on GlyphMapForStandardFonts.
  15229. var map = [];
  15230. for (var code in GlyphMapForStandardFonts) {
  15231. map[+code] = GlyphMapForStandardFonts[code];
  15232. }
  15233. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15234. if (!isIdentityUnicode) {
  15235. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15236. map[+charCode] = unicodeCharCode;
  15237. });
  15238. }
  15239. this.toFontChar = map;
  15240. this.toUnicode = new ToUnicodeMap(map);
  15241. } else if (/Symbol/i.test(fontName)) {
  15242. var symbols = Encodings.SymbolSetEncoding;
  15243. for (charCode in symbols) {
  15244. fontChar = GlyphsUnicode[symbols[charCode]];
  15245. if (!fontChar) {
  15246. continue;
  15247. }
  15248. this.toFontChar[charCode] = fontChar;
  15249. }
  15250. for (charCode in properties.differences) {
  15251. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15252. if (!fontChar) {
  15253. continue;
  15254. }
  15255. this.toFontChar[charCode] = fontChar;
  15256. }
  15257. } else if (/Dingbats/i.test(fontName)) {
  15258. if (/Wingdings/i.test(name)) {
  15259. warn('Wingdings font without embedded font file, ' +
  15260. 'falling back to the ZapfDingbats encoding.');
  15261. }
  15262. var dingbats = Encodings.ZapfDingbatsEncoding;
  15263. for (charCode in dingbats) {
  15264. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15265. if (!fontChar) {
  15266. continue;
  15267. }
  15268. this.toFontChar[charCode] = fontChar;
  15269. }
  15270. for (charCode in properties.differences) {
  15271. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15272. if (!fontChar) {
  15273. continue;
  15274. }
  15275. this.toFontChar[charCode] = fontChar;
  15276. }
  15277. } else if (isStandardFont) {
  15278. this.toFontChar = [];
  15279. for (charCode in properties.defaultEncoding) {
  15280. glyphName = (properties.differences[charCode] ||
  15281. properties.defaultEncoding[charCode]);
  15282. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15283. }
  15284. } else {
  15285. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15286. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15287. if (notCidFont) {
  15288. glyphName = (properties.differences[charCode] ||
  15289. properties.defaultEncoding[charCode]);
  15290. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15291. }
  15292. this.toFontChar[charCode] = unicodeCharCode;
  15293. }.bind(this));
  15294. }
  15295. this.loadedName = fontName.split('-')[0];
  15296. this.loading = false;
  15297. this.fontType = getFontType(type, subtype);
  15298. return;
  15299. }
  15300. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15301. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15302. // Some TrueType fonts by mistake claim Type1C
  15303. if (isTrueTypeFile(file)) {
  15304. subtype = 'TrueType';
  15305. } else {
  15306. type = 'Type1';
  15307. }
  15308. }
  15309. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15310. type = 'CIDFontType0';
  15311. }
  15312. // XXX: Temporarily change the type for open type so we trigger a warning.
  15313. // This should be removed when we add support for open type.
  15314. if (subtype === 'OpenType') {
  15315. type = 'OpenType';
  15316. }
  15317. var data;
  15318. switch (type) {
  15319. case 'MMType1':
  15320. info('MMType1 font (' + name + '), falling back to Type1.');
  15321. /* falls through */
  15322. case 'Type1':
  15323. case 'CIDFontType0':
  15324. this.mimetype = 'font/opentype';
  15325. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15326. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15327. adjustWidths(properties);
  15328. // Wrap the CFF data inside an OTF font file
  15329. data = this.convert(name, cff, properties);
  15330. break;
  15331. case 'OpenType':
  15332. case 'TrueType':
  15333. case 'CIDFontType2':
  15334. this.mimetype = 'font/opentype';
  15335. // Repair the TrueType file. It is can be damaged in the point of
  15336. // view of the sanitizer
  15337. data = this.checkAndRepair(name, file, properties);
  15338. if (this.isOpenType) {
  15339. type = 'OpenType';
  15340. }
  15341. break;
  15342. default:
  15343. error('Font ' + type + ' is not supported');
  15344. break;
  15345. }
  15346. this.data = data;
  15347. this.fontType = getFontType(type, subtype);
  15348. // Transfer some properties again that could change during font conversion
  15349. this.fontMatrix = properties.fontMatrix;
  15350. this.widths = properties.widths;
  15351. this.defaultWidth = properties.defaultWidth;
  15352. this.encoding = properties.baseEncoding;
  15353. this.seacMap = properties.seacMap;
  15354. this.loading = true;
  15355. }
  15356. Font.getFontID = (function () {
  15357. var ID = 1;
  15358. return function Font_getFontID() {
  15359. return String(ID++);
  15360. };
  15361. })();
  15362. function int16(b0, b1) {
  15363. return (b0 << 8) + b1;
  15364. }
  15365. function int32(b0, b1, b2, b3) {
  15366. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15367. }
  15368. function string16(value) {
  15369. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15370. }
  15371. function safeString16(value) {
  15372. // clamp value to the 16-bit int range
  15373. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15374. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15375. }
  15376. function isTrueTypeFile(file) {
  15377. var header = file.peekBytes(4);
  15378. return readUint32(header, 0) === 0x00010000;
  15379. }
  15380. /**
  15381. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15382. * with their unicode value. It also moves char codes that are in known
  15383. * problematic locations.
  15384. * @return {Object} Two properties:
  15385. * 'toFontChar' - maps original char codes(the value that will be read
  15386. * from commands such as show text) to the char codes that will be used in the
  15387. * font that we build
  15388. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15389. */
  15390. function adjustMapping(charCodeToGlyphId, properties) {
  15391. var toUnicode = properties.toUnicode;
  15392. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15393. var isIdentityUnicode =
  15394. properties.toUnicode instanceof IdentityToUnicodeMap;
  15395. var newMap = Object.create(null);
  15396. var toFontChar = [];
  15397. var usedFontCharCodes = [];
  15398. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15399. for (var originalCharCode in charCodeToGlyphId) {
  15400. originalCharCode |= 0;
  15401. var glyphId = charCodeToGlyphId[originalCharCode];
  15402. var fontCharCode = originalCharCode;
  15403. // First try to map the value to a unicode position if a non identity map
  15404. // was created.
  15405. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15406. var unicode = toUnicode.get(fontCharCode);
  15407. // TODO: Try to map ligatures to the correct spot.
  15408. if (unicode.length === 1) {
  15409. fontCharCode = unicode.charCodeAt(0);
  15410. }
  15411. }
  15412. // Try to move control characters, special characters and already mapped
  15413. // characters to the private use area since they will not be drawn by
  15414. // canvas if left in their current position. Also, move characters if the
  15415. // font was symbolic and there is only an identity unicode map since the
  15416. // characters probably aren't in the correct position (fixes an issue
  15417. // with firefox and thuluthfont).
  15418. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15419. fontCharCode <= 0x1f || // Control chars
  15420. fontCharCode === 0x7F || // Control char
  15421. fontCharCode === 0xAD || // Soft hyphen
  15422. fontCharCode === 0xA0 || // Non breaking space
  15423. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15424. // Prevent drawing characters in the specials unicode block.
  15425. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15426. (isSymbolic && isIdentityUnicode)) &&
  15427. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15428. // Loop to try and find a free spot in the private use area.
  15429. do {
  15430. fontCharCode = nextAvailableFontCharCode++;
  15431. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15432. fontCharCode = 0xF020;
  15433. nextAvailableFontCharCode = fontCharCode + 1;
  15434. }
  15435. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15436. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15437. }
  15438. newMap[fontCharCode] = glyphId;
  15439. toFontChar[originalCharCode] = fontCharCode;
  15440. usedFontCharCodes[fontCharCode] = true;
  15441. }
  15442. return {
  15443. toFontChar: toFontChar,
  15444. charCodeToGlyphId: newMap,
  15445. nextAvailableFontCharCode: nextAvailableFontCharCode
  15446. };
  15447. }
  15448. function getRanges(glyphs) {
  15449. // Array.sort() sorts by characters, not numerically, so convert to an
  15450. // array of characters.
  15451. var codes = [];
  15452. for (var charCode in glyphs) {
  15453. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15454. }
  15455. codes.sort(function fontGetRangesSort(a, b) {
  15456. return a.fontCharCode - b.fontCharCode;
  15457. });
  15458. // Split the sorted codes into ranges.
  15459. var ranges = [];
  15460. var length = codes.length;
  15461. for (var n = 0; n < length; ) {
  15462. var start = codes[n].fontCharCode;
  15463. var codeIndices = [codes[n].glyphId];
  15464. ++n;
  15465. var end = start;
  15466. while (n < length && end + 1 === codes[n].fontCharCode) {
  15467. codeIndices.push(codes[n].glyphId);
  15468. ++end;
  15469. ++n;
  15470. if (end === 0xFFFF) {
  15471. break;
  15472. }
  15473. }
  15474. ranges.push([start, end, codeIndices]);
  15475. }
  15476. return ranges;
  15477. }
  15478. function createCmapTable(glyphs) {
  15479. var ranges = getRanges(glyphs);
  15480. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15481. var cmap = '\x00\x00' + // version
  15482. string16(numTables) + // numTables
  15483. '\x00\x03' + // platformID
  15484. '\x00\x01' + // encodingID
  15485. string32(4 + numTables * 8); // start of the table record
  15486. var i, ii, j, jj;
  15487. for (i = ranges.length - 1; i >= 0; --i) {
  15488. if (ranges[i][0] <= 0xFFFF) { break; }
  15489. }
  15490. var bmpLength = i + 1;
  15491. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15492. ranges[i][1] = 0xFFFE;
  15493. }
  15494. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15495. var segCount = bmpLength + trailingRangesCount;
  15496. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15497. // Fill up the 4 parallel arrays describing the segments.
  15498. var startCount = '';
  15499. var endCount = '';
  15500. var idDeltas = '';
  15501. var idRangeOffsets = '';
  15502. var glyphsIds = '';
  15503. var bias = 0;
  15504. var range, start, end, codes;
  15505. for (i = 0, ii = bmpLength; i < ii; i++) {
  15506. range = ranges[i];
  15507. start = range[0];
  15508. end = range[1];
  15509. startCount += string16(start);
  15510. endCount += string16(end);
  15511. codes = range[2];
  15512. var contiguous = true;
  15513. for (j = 1, jj = codes.length; j < jj; ++j) {
  15514. if (codes[j] !== codes[j - 1] + 1) {
  15515. contiguous = false;
  15516. break;
  15517. }
  15518. }
  15519. if (!contiguous) {
  15520. var offset = (segCount - i) * 2 + bias * 2;
  15521. bias += (end - start + 1);
  15522. idDeltas += string16(0);
  15523. idRangeOffsets += string16(offset);
  15524. for (j = 0, jj = codes.length; j < jj; ++j) {
  15525. glyphsIds += string16(codes[j]);
  15526. }
  15527. } else {
  15528. var startCode = codes[0];
  15529. idDeltas += string16((startCode - start) & 0xFFFF);
  15530. idRangeOffsets += string16(0);
  15531. }
  15532. }
  15533. if (trailingRangesCount > 0) {
  15534. endCount += '\xFF\xFF';
  15535. startCount += '\xFF\xFF';
  15536. idDeltas += '\x00\x01';
  15537. idRangeOffsets += '\x00\x00';
  15538. }
  15539. var format314 = '\x00\x00' + // language
  15540. string16(2 * segCount) +
  15541. string16(searchParams.range) +
  15542. string16(searchParams.entry) +
  15543. string16(searchParams.rangeShift) +
  15544. endCount + '\x00\x00' + startCount +
  15545. idDeltas + idRangeOffsets + glyphsIds;
  15546. var format31012 = '';
  15547. var header31012 = '';
  15548. if (numTables > 1) {
  15549. cmap += '\x00\x03' + // platformID
  15550. '\x00\x0A' + // encodingID
  15551. string32(4 + numTables * 8 +
  15552. 4 + format314.length); // start of the table record
  15553. format31012 = '';
  15554. for (i = 0, ii = ranges.length; i < ii; i++) {
  15555. range = ranges[i];
  15556. start = range[0];
  15557. codes = range[2];
  15558. var code = codes[0];
  15559. for (j = 1, jj = codes.length; j < jj; ++j) {
  15560. if (codes[j] !== codes[j - 1] + 1) {
  15561. end = range[0] + j - 1;
  15562. format31012 += string32(start) + // startCharCode
  15563. string32(end) + // endCharCode
  15564. string32(code); // startGlyphID
  15565. start = end + 1;
  15566. code = codes[j];
  15567. }
  15568. }
  15569. format31012 += string32(start) + // startCharCode
  15570. string32(range[1]) + // endCharCode
  15571. string32(code); // startGlyphID
  15572. }
  15573. header31012 = '\x00\x0C' + // format
  15574. '\x00\x00' + // reserved
  15575. string32(format31012.length + 16) + // length
  15576. '\x00\x00\x00\x00' + // language
  15577. string32(format31012.length / 12); // nGroups
  15578. }
  15579. return cmap + '\x00\x04' + // format
  15580. string16(format314.length + 4) + // length
  15581. format314 + header31012 + format31012;
  15582. }
  15583. function validateOS2Table(os2) {
  15584. var stream = new Stream(os2.data);
  15585. var version = stream.getUint16();
  15586. // TODO verify all OS/2 tables fields, but currently we validate only those
  15587. // that give us issues
  15588. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15589. var selection = stream.getUint16();
  15590. if (version < 4 && (selection & 0x0300)) {
  15591. return false;
  15592. }
  15593. var firstChar = stream.getUint16();
  15594. var lastChar = stream.getUint16();
  15595. if (firstChar > lastChar) {
  15596. return false;
  15597. }
  15598. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15599. var usWinAscent = stream.getUint16();
  15600. if (usWinAscent === 0) { // makes font unreadable by windows
  15601. return false;
  15602. }
  15603. // OS/2 appears to be valid, resetting some fields
  15604. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15605. return true;
  15606. }
  15607. function createOS2Table(properties, charstrings, override) {
  15608. override = override || {
  15609. unitsPerEm: 0,
  15610. yMax: 0,
  15611. yMin: 0,
  15612. ascent: 0,
  15613. descent: 0
  15614. };
  15615. var ulUnicodeRange1 = 0;
  15616. var ulUnicodeRange2 = 0;
  15617. var ulUnicodeRange3 = 0;
  15618. var ulUnicodeRange4 = 0;
  15619. var firstCharIndex = null;
  15620. var lastCharIndex = 0;
  15621. if (charstrings) {
  15622. for (var code in charstrings) {
  15623. code |= 0;
  15624. if (firstCharIndex > code || !firstCharIndex) {
  15625. firstCharIndex = code;
  15626. }
  15627. if (lastCharIndex < code) {
  15628. lastCharIndex = code;
  15629. }
  15630. var position = getUnicodeRangeFor(code);
  15631. if (position < 32) {
  15632. ulUnicodeRange1 |= 1 << position;
  15633. } else if (position < 64) {
  15634. ulUnicodeRange2 |= 1 << position - 32;
  15635. } else if (position < 96) {
  15636. ulUnicodeRange3 |= 1 << position - 64;
  15637. } else if (position < 123) {
  15638. ulUnicodeRange4 |= 1 << position - 96;
  15639. } else {
  15640. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15641. }
  15642. }
  15643. } else {
  15644. // TODO
  15645. firstCharIndex = 0;
  15646. lastCharIndex = 255;
  15647. }
  15648. var bbox = properties.bbox || [0, 0, 0, 0];
  15649. var unitsPerEm = (override.unitsPerEm ||
  15650. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15651. // if the font units differ to the PDF glyph space units
  15652. // then scale up the values
  15653. var scale = (properties.ascentScaled ? 1.0 :
  15654. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15655. var typoAscent = (override.ascent ||
  15656. Math.round(scale * (properties.ascent || bbox[3])));
  15657. var typoDescent = (override.descent ||
  15658. Math.round(scale * (properties.descent || bbox[1])));
  15659. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15660. typoDescent = -typoDescent; // fixing incorrect descent
  15661. }
  15662. var winAscent = override.yMax || typoAscent;
  15663. var winDescent = -override.yMin || -typoDescent;
  15664. return '\x00\x03' + // version
  15665. '\x02\x24' + // xAvgCharWidth
  15666. '\x01\xF4' + // usWeightClass
  15667. '\x00\x05' + // usWidthClass
  15668. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15669. '\x02\x8A' + // ySubscriptXSize
  15670. '\x02\xBB' + // ySubscriptYSize
  15671. '\x00\x00' + // ySubscriptXOffset
  15672. '\x00\x8C' + // ySubscriptYOffset
  15673. '\x02\x8A' + // ySuperScriptXSize
  15674. '\x02\xBB' + // ySuperScriptYSize
  15675. '\x00\x00' + // ySuperScriptXOffset
  15676. '\x01\xDF' + // ySuperScriptYOffset
  15677. '\x00\x31' + // yStrikeOutSize
  15678. '\x01\x02' + // yStrikeOutPosition
  15679. '\x00\x00' + // sFamilyClass
  15680. '\x00\x00\x06' +
  15681. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15682. '\x00\x00\x00\x00\x00\x00' + // Panose
  15683. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15684. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15685. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15686. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15687. '\x2A\x32\x31\x2A' + // achVendID
  15688. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15689. string16(firstCharIndex ||
  15690. properties.firstChar) + // usFirstCharIndex
  15691. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15692. string16(typoAscent) + // sTypoAscender
  15693. string16(typoDescent) + // sTypoDescender
  15694. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15695. string16(winAscent) + // usWinAscent
  15696. string16(winDescent) + // usWinDescent
  15697. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15698. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15699. string16(properties.xHeight) + // sxHeight
  15700. string16(properties.capHeight) + // sCapHeight
  15701. string16(0) + // usDefaultChar
  15702. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15703. '\x00\x03'; // usMaxContext
  15704. }
  15705. function createPostTable(properties) {
  15706. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15707. return ('\x00\x03\x00\x00' + // Version number
  15708. string32(angle) + // italicAngle
  15709. '\x00\x00' + // underlinePosition
  15710. '\x00\x00' + // underlineThickness
  15711. string32(properties.fixedPitch) + // isFixedPitch
  15712. '\x00\x00\x00\x00' + // minMemType42
  15713. '\x00\x00\x00\x00' + // maxMemType42
  15714. '\x00\x00\x00\x00' + // minMemType1
  15715. '\x00\x00\x00\x00'); // maxMemType1
  15716. }
  15717. function createNameTable(name, proto) {
  15718. if (!proto) {
  15719. proto = [[], []]; // no strings and unicode strings
  15720. }
  15721. var strings = [
  15722. proto[0][0] || 'Original licence', // 0.Copyright
  15723. proto[0][1] || name, // 1.Font family
  15724. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15725. proto[0][3] || 'uniqueID', // 3.Unique ID
  15726. proto[0][4] || name, // 4.Full font name
  15727. proto[0][5] || 'Version 0.11', // 5.Version
  15728. proto[0][6] || '', // 6.Postscript name
  15729. proto[0][7] || 'Unknown', // 7.Trademark
  15730. proto[0][8] || 'Unknown', // 8.Manufacturer
  15731. proto[0][9] || 'Unknown' // 9.Designer
  15732. ];
  15733. // Mac want 1-byte per character strings while Windows want
  15734. // 2-bytes per character, so duplicate the names table
  15735. var stringsUnicode = [];
  15736. var i, ii, j, jj, str;
  15737. for (i = 0, ii = strings.length; i < ii; i++) {
  15738. str = proto[1][i] || strings[i];
  15739. var strBufUnicode = [];
  15740. for (j = 0, jj = str.length; j < jj; j++) {
  15741. strBufUnicode.push(string16(str.charCodeAt(j)));
  15742. }
  15743. stringsUnicode.push(strBufUnicode.join(''));
  15744. }
  15745. var names = [strings, stringsUnicode];
  15746. var platforms = ['\x00\x01', '\x00\x03'];
  15747. var encodings = ['\x00\x00', '\x00\x01'];
  15748. var languages = ['\x00\x00', '\x04\x09'];
  15749. var namesRecordCount = strings.length * platforms.length;
  15750. var nameTable =
  15751. '\x00\x00' + // format
  15752. string16(namesRecordCount) + // Number of names Record
  15753. string16(namesRecordCount * 12 + 6); // Storage
  15754. // Build the name records field
  15755. var strOffset = 0;
  15756. for (i = 0, ii = platforms.length; i < ii; i++) {
  15757. var strs = names[i];
  15758. for (j = 0, jj = strs.length; j < jj; j++) {
  15759. str = strs[j];
  15760. var nameRecord =
  15761. platforms[i] + // platform ID
  15762. encodings[i] + // encoding ID
  15763. languages[i] + // language ID
  15764. string16(j) + // name ID
  15765. string16(str.length) +
  15766. string16(strOffset);
  15767. nameTable += nameRecord;
  15768. strOffset += str.length;
  15769. }
  15770. }
  15771. nameTable += strings.join('') + stringsUnicode.join('');
  15772. return nameTable;
  15773. }
  15774. Font.prototype = {
  15775. name: null,
  15776. font: null,
  15777. mimetype: null,
  15778. encoding: null,
  15779. get renderer() {
  15780. var renderer = FontRendererFactory.create(this);
  15781. return shadow(this, 'renderer', renderer);
  15782. },
  15783. exportData: function Font_exportData() {
  15784. var data = {};
  15785. for (var i in this) {
  15786. if (this.hasOwnProperty(i)) {
  15787. data[i] = this[i];
  15788. }
  15789. }
  15790. return data;
  15791. },
  15792. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15793. function readTableEntry(file) {
  15794. var tag = bytesToString(file.getBytes(4));
  15795. var checksum = file.getInt32();
  15796. var offset = file.getInt32() >>> 0;
  15797. var length = file.getInt32() >>> 0;
  15798. // Read the table associated data
  15799. var previousPosition = file.pos;
  15800. file.pos = file.start ? file.start : 0;
  15801. file.skip(offset);
  15802. var data = file.getBytes(length);
  15803. file.pos = previousPosition;
  15804. if (tag === 'head') {
  15805. // clearing checksum adjustment
  15806. data[8] = data[9] = data[10] = data[11] = 0;
  15807. data[17] |= 0x20; //Set font optimized for cleartype flag
  15808. }
  15809. return {
  15810. tag: tag,
  15811. checksum: checksum,
  15812. length: length,
  15813. offset: offset,
  15814. data: data
  15815. };
  15816. }
  15817. function readOpenTypeHeader(ttf) {
  15818. return {
  15819. version: bytesToString(ttf.getBytes(4)),
  15820. numTables: ttf.getUint16(),
  15821. searchRange: ttf.getUint16(),
  15822. entrySelector: ttf.getUint16(),
  15823. rangeShift: ttf.getUint16()
  15824. };
  15825. }
  15826. /**
  15827. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15828. * PDF spec
  15829. */
  15830. function readCmapTable(cmap, font, isSymbolicFont) {
  15831. var segment;
  15832. var start = (font.start ? font.start : 0) + cmap.offset;
  15833. font.pos = start;
  15834. var version = font.getUint16();
  15835. var numTables = font.getUint16();
  15836. var potentialTable;
  15837. var canBreak = false;
  15838. // There's an order of preference in terms of which cmap subtable to
  15839. // use:
  15840. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15841. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15842. // The following takes advantage of the fact that the tables are sorted
  15843. // to work.
  15844. for (var i = 0; i < numTables; i++) {
  15845. var platformId = font.getUint16();
  15846. var encodingId = font.getUint16();
  15847. var offset = font.getInt32() >>> 0;
  15848. var useTable = false;
  15849. if (platformId === 0 && encodingId === 0) {
  15850. useTable = true;
  15851. // Continue the loop since there still may be a higher priority
  15852. // table.
  15853. } else if (platformId === 1 && encodingId === 0) {
  15854. useTable = true;
  15855. // Continue the loop since there still may be a higher priority
  15856. // table.
  15857. } else if (platformId === 3 && encodingId === 1 &&
  15858. (!isSymbolicFont || !potentialTable)) {
  15859. useTable = true;
  15860. if (!isSymbolicFont) {
  15861. canBreak = true;
  15862. }
  15863. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15864. useTable = true;
  15865. canBreak = true;
  15866. }
  15867. if (useTable) {
  15868. potentialTable = {
  15869. platformId: platformId,
  15870. encodingId: encodingId,
  15871. offset: offset
  15872. };
  15873. }
  15874. if (canBreak) {
  15875. break;
  15876. }
  15877. }
  15878. if (!potentialTable) {
  15879. warn('Could not find a preferred cmap table.');
  15880. return {
  15881. platformId: -1,
  15882. encodingId: -1,
  15883. mappings: [],
  15884. hasShortCmap: false
  15885. };
  15886. }
  15887. font.pos = start + potentialTable.offset;
  15888. var format = font.getUint16();
  15889. var length = font.getUint16();
  15890. var language = font.getUint16();
  15891. var hasShortCmap = false;
  15892. var mappings = [];
  15893. var j, glyphId;
  15894. // TODO(mack): refactor this cmap subtable reading logic out
  15895. if (format === 0) {
  15896. for (j = 0; j < 256; j++) {
  15897. var index = font.getByte();
  15898. if (!index) {
  15899. continue;
  15900. }
  15901. mappings.push({
  15902. charCode: j,
  15903. glyphId: index
  15904. });
  15905. }
  15906. hasShortCmap = true;
  15907. } else if (format === 4) {
  15908. // re-creating the table in format 4 since the encoding
  15909. // might be changed
  15910. var segCount = (font.getUint16() >> 1);
  15911. font.getBytes(6); // skipping range fields
  15912. var segIndex, segments = [];
  15913. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15914. segments.push({ end: font.getUint16() });
  15915. }
  15916. font.getUint16();
  15917. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15918. segments[segIndex].start = font.getUint16();
  15919. }
  15920. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15921. segments[segIndex].delta = font.getUint16();
  15922. }
  15923. var offsetsCount = 0;
  15924. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15925. segment = segments[segIndex];
  15926. var rangeOffset = font.getUint16();
  15927. if (!rangeOffset) {
  15928. segment.offsetIndex = -1;
  15929. continue;
  15930. }
  15931. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15932. segment.offsetIndex = offsetIndex;
  15933. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15934. segment.end - segment.start + 1);
  15935. }
  15936. var offsets = [];
  15937. for (j = 0; j < offsetsCount; j++) {
  15938. offsets.push(font.getUint16());
  15939. }
  15940. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15941. segment = segments[segIndex];
  15942. start = segment.start;
  15943. var end = segment.end;
  15944. var delta = segment.delta;
  15945. offsetIndex = segment.offsetIndex;
  15946. for (j = start; j <= end; j++) {
  15947. if (j === 0xFFFF) {
  15948. continue;
  15949. }
  15950. glyphId = (offsetIndex < 0 ?
  15951. j : offsets[offsetIndex + j - start]);
  15952. glyphId = (glyphId + delta) & 0xFFFF;
  15953. if (glyphId === 0) {
  15954. continue;
  15955. }
  15956. mappings.push({
  15957. charCode: j,
  15958. glyphId: glyphId
  15959. });
  15960. }
  15961. }
  15962. } else if (format === 6) {
  15963. // Format 6 is a 2-bytes dense mapping, which means the font data
  15964. // lives glue together even if they are pretty far in the unicode
  15965. // table. (This looks weird, so I can have missed something), this
  15966. // works on Linux but seems to fails on Mac so let's rewrite the
  15967. // cmap table to a 3-1-4 style
  15968. var firstCode = font.getUint16();
  15969. var entryCount = font.getUint16();
  15970. for (j = 0; j < entryCount; j++) {
  15971. glyphId = font.getUint16();
  15972. var charCode = firstCode + j;
  15973. mappings.push({
  15974. charCode: charCode,
  15975. glyphId: glyphId
  15976. });
  15977. }
  15978. } else {
  15979. error('cmap table has unsupported format: ' + format);
  15980. }
  15981. // removing duplicate entries
  15982. mappings.sort(function (a, b) {
  15983. return a.charCode - b.charCode;
  15984. });
  15985. for (i = 1; i < mappings.length; i++) {
  15986. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15987. mappings.splice(i, 1);
  15988. i--;
  15989. }
  15990. }
  15991. return {
  15992. platformId: potentialTable.platformId,
  15993. encodingId: potentialTable.encodingId,
  15994. mappings: mappings,
  15995. hasShortCmap: hasShortCmap
  15996. };
  15997. }
  15998. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15999. if (!header) {
  16000. if (metrics) {
  16001. metrics.data = null;
  16002. }
  16003. return;
  16004. }
  16005. font.pos = (font.start ? font.start : 0) + header.offset;
  16006. font.pos += header.length - 2;
  16007. var numOfMetrics = font.getUint16();
  16008. if (numOfMetrics > numGlyphs) {
  16009. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16010. 'greater than the numGlyphs (' + numGlyphs + ')');
  16011. // Reduce numOfMetrics if it is greater than numGlyphs
  16012. numOfMetrics = numGlyphs;
  16013. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16014. header.data[35] = numOfMetrics & 0x00ff;
  16015. }
  16016. var numOfSidebearings = numGlyphs - numOfMetrics;
  16017. var numMissing = numOfSidebearings -
  16018. ((metrics.length - numOfMetrics * 4) >> 1);
  16019. if (numMissing > 0) {
  16020. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16021. // Since we need to add two properties for each glyph, this explains
  16022. // the use of |numMissing * 2| when initializing the typed array.
  16023. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16024. entries.set(metrics.data);
  16025. metrics.data = entries;
  16026. }
  16027. }
  16028. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16029. hintsValid) {
  16030. if (sourceEnd - sourceStart <= 12) {
  16031. // glyph with data less than 12 is invalid one
  16032. return 0;
  16033. }
  16034. var glyf = source.subarray(sourceStart, sourceEnd);
  16035. var contoursCount = (glyf[0] << 8) | glyf[1];
  16036. if (contoursCount & 0x8000) {
  16037. // complex glyph, writing as is
  16038. dest.set(glyf, destStart);
  16039. return glyf.length;
  16040. }
  16041. var i, j = 10, flagsCount = 0;
  16042. for (i = 0; i < contoursCount; i++) {
  16043. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16044. flagsCount = endPoint + 1;
  16045. j += 2;
  16046. }
  16047. // skipping instructions
  16048. var instructionsStart = j;
  16049. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16050. j += 2 + instructionsLength;
  16051. var instructionsEnd = j;
  16052. // validating flags
  16053. var coordinatesLength = 0;
  16054. for (i = 0; i < flagsCount; i++) {
  16055. var flag = glyf[j++];
  16056. if (flag & 0xC0) {
  16057. // reserved flags must be zero, cleaning up
  16058. glyf[j - 1] = flag & 0x3F;
  16059. }
  16060. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16061. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16062. coordinatesLength += xyLength;
  16063. if (flag & 8) {
  16064. var repeat = glyf[j++];
  16065. i += repeat;
  16066. coordinatesLength += repeat * xyLength;
  16067. }
  16068. }
  16069. // glyph without coordinates will be rejected
  16070. if (coordinatesLength === 0) {
  16071. return 0;
  16072. }
  16073. var glyphDataLength = j + coordinatesLength;
  16074. if (glyphDataLength > glyf.length) {
  16075. // not enough data for coordinates
  16076. return 0;
  16077. }
  16078. if (!hintsValid && instructionsLength > 0) {
  16079. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16080. dest.set([0, 0], destStart + instructionsStart);
  16081. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16082. destStart + instructionsStart + 2);
  16083. glyphDataLength -= instructionsLength;
  16084. if (glyf.length - glyphDataLength > 3) {
  16085. glyphDataLength = (glyphDataLength + 3) & ~3;
  16086. }
  16087. return glyphDataLength;
  16088. }
  16089. if (glyf.length - glyphDataLength > 3) {
  16090. // truncating and aligning to 4 bytes the long glyph data
  16091. glyphDataLength = (glyphDataLength + 3) & ~3;
  16092. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16093. return glyphDataLength;
  16094. }
  16095. // glyph data is fine
  16096. dest.set(glyf, destStart);
  16097. return glyf.length;
  16098. }
  16099. function sanitizeHead(head, numGlyphs, locaLength) {
  16100. var data = head.data;
  16101. // Validate version:
  16102. // Should always be 0x00010000
  16103. var version = int32(data[0], data[1], data[2], data[3]);
  16104. if (version >> 16 !== 1) {
  16105. info('Attempting to fix invalid version in head table: ' + version);
  16106. data[0] = 0;
  16107. data[1] = 1;
  16108. data[2] = 0;
  16109. data[3] = 0;
  16110. }
  16111. var indexToLocFormat = int16(data[50], data[51]);
  16112. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16113. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16114. indexToLocFormat);
  16115. // The value of indexToLocFormat should be 0 if the loca table
  16116. // consists of short offsets, and should be 1 if the loca table
  16117. // consists of long offsets.
  16118. //
  16119. // The number of entries in the loca table should be numGlyphs + 1.
  16120. //
  16121. // Using this information, we can work backwards to deduce if the
  16122. // size of each offset in the loca table, and thus figure out the
  16123. // appropriate value for indexToLocFormat.
  16124. var numGlyphsPlusOne = numGlyphs + 1;
  16125. if (locaLength === numGlyphsPlusOne << 1) {
  16126. // 0x0000 indicates the loca table consists of short offsets
  16127. data[50] = 0;
  16128. data[51] = 0;
  16129. } else if (locaLength === numGlyphsPlusOne << 2) {
  16130. // 0x0001 indicates the loca table consists of long offsets
  16131. data[50] = 0;
  16132. data[51] = 1;
  16133. } else {
  16134. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16135. }
  16136. }
  16137. }
  16138. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16139. isGlyphLocationsLong, hintsValid,
  16140. dupFirstEntry) {
  16141. var itemSize, itemDecode, itemEncode;
  16142. if (isGlyphLocationsLong) {
  16143. itemSize = 4;
  16144. itemDecode = function fontItemDecodeLong(data, offset) {
  16145. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16146. (data[offset + 2] << 8) | data[offset + 3];
  16147. };
  16148. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16149. data[offset] = (value >>> 24) & 0xFF;
  16150. data[offset + 1] = (value >> 16) & 0xFF;
  16151. data[offset + 2] = (value >> 8) & 0xFF;
  16152. data[offset + 3] = value & 0xFF;
  16153. };
  16154. } else {
  16155. itemSize = 2;
  16156. itemDecode = function fontItemDecode(data, offset) {
  16157. return (data[offset] << 9) | (data[offset + 1] << 1);
  16158. };
  16159. itemEncode = function fontItemEncode(data, offset, value) {
  16160. data[offset] = (value >> 9) & 0xFF;
  16161. data[offset + 1] = (value >> 1) & 0xFF;
  16162. };
  16163. }
  16164. var locaData = loca.data;
  16165. var locaDataSize = itemSize * (1 + numGlyphs);
  16166. // is loca.data too short or long?
  16167. if (locaData.length !== locaDataSize) {
  16168. locaData = new Uint8Array(locaDataSize);
  16169. locaData.set(loca.data.subarray(0, locaDataSize));
  16170. loca.data = locaData;
  16171. }
  16172. // removing the invalid glyphs
  16173. var oldGlyfData = glyf.data;
  16174. var oldGlyfDataLength = oldGlyfData.length;
  16175. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16176. var startOffset = itemDecode(locaData, 0);
  16177. var writeOffset = 0;
  16178. var missingGlyphData = {};
  16179. itemEncode(locaData, 0, writeOffset);
  16180. var i, j;
  16181. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16182. var endOffset = itemDecode(locaData, j);
  16183. if (endOffset > oldGlyfDataLength &&
  16184. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16185. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16186. // the glyf table size, which makes last glyph out of range.
  16187. endOffset = oldGlyfDataLength;
  16188. }
  16189. if (endOffset > oldGlyfDataLength) {
  16190. // glyph end offset points outside glyf data, rejecting the glyph
  16191. itemEncode(locaData, j, writeOffset);
  16192. startOffset = endOffset;
  16193. continue;
  16194. }
  16195. if (startOffset === endOffset) {
  16196. missingGlyphData[i] = true;
  16197. }
  16198. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16199. newGlyfData, writeOffset, hintsValid);
  16200. writeOffset += newLength;
  16201. itemEncode(locaData, j, writeOffset);
  16202. startOffset = endOffset;
  16203. }
  16204. if (writeOffset === 0) {
  16205. // glyf table cannot be empty -- redoing the glyf and loca tables
  16206. // to have single glyph with one point
  16207. var simpleGlyph = new Uint8Array(
  16208. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16209. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16210. itemEncode(locaData, j, simpleGlyph.length);
  16211. }
  16212. glyf.data = simpleGlyph;
  16213. return missingGlyphData;
  16214. }
  16215. if (dupFirstEntry) {
  16216. var firstEntryLength = itemDecode(locaData, itemSize);
  16217. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16218. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16219. } else {
  16220. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16221. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16222. }
  16223. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16224. itemEncode(loca.data, locaData.length - itemSize,
  16225. writeOffset + firstEntryLength);
  16226. } else {
  16227. glyf.data = newGlyfData.subarray(0, writeOffset);
  16228. }
  16229. return missingGlyphData;
  16230. }
  16231. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16232. var start = (font.start ? font.start : 0) + post.offset;
  16233. font.pos = start;
  16234. var length = post.length, end = start + length;
  16235. var version = font.getInt32();
  16236. // skip rest to the tables
  16237. font.getBytes(28);
  16238. var glyphNames;
  16239. var valid = true;
  16240. var i;
  16241. switch (version) {
  16242. case 0x00010000:
  16243. glyphNames = MacStandardGlyphOrdering;
  16244. break;
  16245. case 0x00020000:
  16246. var numGlyphs = font.getUint16();
  16247. if (numGlyphs !== maxpNumGlyphs) {
  16248. valid = false;
  16249. break;
  16250. }
  16251. var glyphNameIndexes = [];
  16252. for (i = 0; i < numGlyphs; ++i) {
  16253. var index = font.getUint16();
  16254. if (index >= 32768) {
  16255. valid = false;
  16256. break;
  16257. }
  16258. glyphNameIndexes.push(index);
  16259. }
  16260. if (!valid) {
  16261. break;
  16262. }
  16263. var customNames = [];
  16264. var strBuf = [];
  16265. while (font.pos < end) {
  16266. var stringLength = font.getByte();
  16267. strBuf.length = stringLength;
  16268. for (i = 0; i < stringLength; ++i) {
  16269. strBuf[i] = String.fromCharCode(font.getByte());
  16270. }
  16271. customNames.push(strBuf.join(''));
  16272. }
  16273. glyphNames = [];
  16274. for (i = 0; i < numGlyphs; ++i) {
  16275. var j = glyphNameIndexes[i];
  16276. if (j < 258) {
  16277. glyphNames.push(MacStandardGlyphOrdering[j]);
  16278. continue;
  16279. }
  16280. glyphNames.push(customNames[j - 258]);
  16281. }
  16282. break;
  16283. case 0x00030000:
  16284. break;
  16285. default:
  16286. warn('Unknown/unsupported post table version ' + version);
  16287. valid = false;
  16288. break;
  16289. }
  16290. properties.glyphNames = glyphNames;
  16291. return valid;
  16292. }
  16293. function readNameTable(nameTable) {
  16294. var start = (font.start ? font.start : 0) + nameTable.offset;
  16295. font.pos = start;
  16296. var names = [[], []];
  16297. var length = nameTable.length, end = start + length;
  16298. var format = font.getUint16();
  16299. var FORMAT_0_HEADER_LENGTH = 6;
  16300. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16301. // unsupported name table format or table "too" small
  16302. return names;
  16303. }
  16304. var numRecords = font.getUint16();
  16305. var stringsStart = font.getUint16();
  16306. var records = [];
  16307. var NAME_RECORD_LENGTH = 12;
  16308. var i, ii;
  16309. for (i = 0; i < numRecords &&
  16310. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16311. var r = {
  16312. platform: font.getUint16(),
  16313. encoding: font.getUint16(),
  16314. language: font.getUint16(),
  16315. name: font.getUint16(),
  16316. length: font.getUint16(),
  16317. offset: font.getUint16()
  16318. };
  16319. // using only Macintosh and Windows platform/encoding names
  16320. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16321. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16322. records.push(r);
  16323. }
  16324. }
  16325. for (i = 0, ii = records.length; i < ii; i++) {
  16326. var record = records[i];
  16327. var pos = start + stringsStart + record.offset;
  16328. if (pos + record.length > end) {
  16329. continue; // outside of name table, ignoring
  16330. }
  16331. font.pos = pos;
  16332. var nameIndex = record.name;
  16333. if (record.encoding) {
  16334. // unicode
  16335. var str = '';
  16336. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16337. str += String.fromCharCode(font.getUint16());
  16338. }
  16339. names[1][nameIndex] = str;
  16340. } else {
  16341. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16342. }
  16343. }
  16344. return names;
  16345. }
  16346. var TTOpsStackDeltas = [
  16347. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16348. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16349. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16350. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16351. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16352. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16353. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16354. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16355. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16356. // 0xC0-DF == -1 and 0xE0-FF == -2
  16357. function sanitizeTTProgram(table, ttContext) {
  16358. var data = table.data;
  16359. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16360. var stack = [];
  16361. var callstack = [];
  16362. var functionsCalled = [];
  16363. var tooComplexToFollowFunctions =
  16364. ttContext.tooComplexToFollowFunctions;
  16365. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16366. for (var ii = data.length; i < ii;) {
  16367. var op = data[i++];
  16368. // The TrueType instruction set docs can be found at
  16369. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16370. if (op === 0x40) { // NPUSHB - pushes n bytes
  16371. n = data[i++];
  16372. if (inFDEF || inELSE) {
  16373. i += n;
  16374. } else {
  16375. for (j = 0; j < n; j++) {
  16376. stack.push(data[i++]);
  16377. }
  16378. }
  16379. } else if (op === 0x41) { // NPUSHW - pushes n words
  16380. n = data[i++];
  16381. if (inFDEF || inELSE) {
  16382. i += n * 2;
  16383. } else {
  16384. for (j = 0; j < n; j++) {
  16385. b = data[i++];
  16386. stack.push((b << 8) | data[i++]);
  16387. }
  16388. }
  16389. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16390. n = op - 0xB0 + 1;
  16391. if (inFDEF || inELSE) {
  16392. i += n;
  16393. } else {
  16394. for (j = 0; j < n; j++) {
  16395. stack.push(data[i++]);
  16396. }
  16397. }
  16398. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16399. n = op - 0xB8 + 1;
  16400. if (inFDEF || inELSE) {
  16401. i += n * 2;
  16402. } else {
  16403. for (j = 0; j < n; j++) {
  16404. b = data[i++];
  16405. stack.push((b << 8) | data[i++]);
  16406. }
  16407. }
  16408. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16409. if (!inFDEF && !inELSE) {
  16410. // collecting inforamtion about which functions are used
  16411. funcId = stack[stack.length - 1];
  16412. ttContext.functionsUsed[funcId] = true;
  16413. if (funcId in ttContext.functionsStackDeltas) {
  16414. stack.length += ttContext.functionsStackDeltas[funcId];
  16415. } else if (funcId in ttContext.functionsDefined &&
  16416. functionsCalled.indexOf(funcId) < 0) {
  16417. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16418. functionsCalled.push(funcId);
  16419. pc = ttContext.functionsDefined[funcId];
  16420. if (!pc) {
  16421. warn('TT: CALL non-existent function');
  16422. ttContext.hintsValid = false;
  16423. return;
  16424. }
  16425. data = pc.data;
  16426. i = pc.i;
  16427. }
  16428. }
  16429. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16430. if (inFDEF || inELSE) {
  16431. warn('TT: nested FDEFs not allowed');
  16432. tooComplexToFollowFunctions = true;
  16433. }
  16434. inFDEF = true;
  16435. // collecting inforamtion about which functions are defined
  16436. lastDeff = i;
  16437. funcId = stack.pop();
  16438. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16439. } else if (op === 0x2D) { // ENDF - end of function
  16440. if (inFDEF) {
  16441. inFDEF = false;
  16442. lastEndf = i;
  16443. } else {
  16444. pc = callstack.pop();
  16445. if (!pc) {
  16446. warn('TT: ENDF bad stack');
  16447. ttContext.hintsValid = false;
  16448. return;
  16449. }
  16450. funcId = functionsCalled.pop();
  16451. data = pc.data;
  16452. i = pc.i;
  16453. ttContext.functionsStackDeltas[funcId] =
  16454. stack.length - pc.stackTop;
  16455. }
  16456. } else if (op === 0x89) { // IDEF - instruction definition
  16457. if (inFDEF || inELSE) {
  16458. warn('TT: nested IDEFs not allowed');
  16459. tooComplexToFollowFunctions = true;
  16460. }
  16461. inFDEF = true;
  16462. // recording it as a function to track ENDF
  16463. lastDeff = i;
  16464. } else if (op === 0x58) { // IF
  16465. ++ifLevel;
  16466. } else if (op === 0x1B) { // ELSE
  16467. inELSE = ifLevel;
  16468. } else if (op === 0x59) { // EIF
  16469. if (inELSE === ifLevel) {
  16470. inELSE = 0;
  16471. }
  16472. --ifLevel;
  16473. } else if (op === 0x1C) { // JMPR
  16474. if (!inFDEF && !inELSE) {
  16475. var offset = stack[stack.length - 1];
  16476. // only jumping forward to prevent infinite loop
  16477. if (offset > 0) {
  16478. i += offset - 1;
  16479. }
  16480. }
  16481. }
  16482. // Adjusting stack not extactly, but just enough to get function id
  16483. if (!inFDEF && !inELSE) {
  16484. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16485. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16486. if (op >= 0x71 && op <= 0x75) {
  16487. n = stack.pop();
  16488. if (n === n) {
  16489. stackDelta = -n * 2;
  16490. }
  16491. }
  16492. while (stackDelta < 0 && stack.length > 0) {
  16493. stack.pop();
  16494. stackDelta++;
  16495. }
  16496. while (stackDelta > 0) {
  16497. stack.push(NaN); // pushing any number into stack
  16498. stackDelta--;
  16499. }
  16500. }
  16501. }
  16502. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16503. var content = [data];
  16504. if (i > data.length) {
  16505. content.push(new Uint8Array(i - data.length));
  16506. }
  16507. if (lastDeff > lastEndf) {
  16508. warn('TT: complementing a missing function tail');
  16509. // new function definition started, but not finished
  16510. // complete function by [CLEAR, ENDF]
  16511. content.push(new Uint8Array([0x22, 0x2D]));
  16512. }
  16513. foldTTTable(table, content);
  16514. }
  16515. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16516. if (ttContext.tooComplexToFollowFunctions) {
  16517. return;
  16518. }
  16519. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16520. warn('TT: more functions defined than expected');
  16521. ttContext.hintsValid = false;
  16522. return;
  16523. }
  16524. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16525. if (j > maxFunctionDefs) {
  16526. warn('TT: invalid function id: ' + j);
  16527. ttContext.hintsValid = false;
  16528. return;
  16529. }
  16530. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16531. warn('TT: undefined function: ' + j);
  16532. ttContext.hintsValid = false;
  16533. return;
  16534. }
  16535. }
  16536. }
  16537. function foldTTTable(table, content) {
  16538. if (content.length > 1) {
  16539. // concatenating the content items
  16540. var newLength = 0;
  16541. var j, jj;
  16542. for (j = 0, jj = content.length; j < jj; j++) {
  16543. newLength += content[j].length;
  16544. }
  16545. newLength = (newLength + 3) & ~3;
  16546. var result = new Uint8Array(newLength);
  16547. var pos = 0;
  16548. for (j = 0, jj = content.length; j < jj; j++) {
  16549. result.set(content[j], pos);
  16550. pos += content[j].length;
  16551. }
  16552. table.data = result;
  16553. table.length = newLength;
  16554. }
  16555. }
  16556. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16557. var ttContext = {
  16558. functionsDefined: [],
  16559. functionsUsed: [],
  16560. functionsStackDeltas: [],
  16561. tooComplexToFollowFunctions: false,
  16562. hintsValid: true
  16563. };
  16564. if (fpgm) {
  16565. sanitizeTTProgram(fpgm, ttContext);
  16566. }
  16567. if (prep) {
  16568. sanitizeTTProgram(prep, ttContext);
  16569. }
  16570. if (fpgm) {
  16571. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16572. }
  16573. if (cvt && (cvt.length & 1)) {
  16574. var cvtData = new Uint8Array(cvt.length + 1);
  16575. cvtData.set(cvt.data);
  16576. cvt.data = cvtData;
  16577. }
  16578. return ttContext.hintsValid;
  16579. }
  16580. // The following steps modify the original font data, making copy
  16581. font = new Stream(new Uint8Array(font.getBytes()));
  16582. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16583. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16584. var header = readOpenTypeHeader(font);
  16585. var numTables = header.numTables;
  16586. var cff, cffFile;
  16587. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16588. hmtx: null, maxp: null, name: null, post: null };
  16589. var table;
  16590. for (var i = 0; i < numTables; i++) {
  16591. table = readTableEntry(font);
  16592. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16593. continue; // skipping table if it's not a required or optional table
  16594. }
  16595. if (table.length === 0) {
  16596. continue; // skipping empty tables
  16597. }
  16598. tables[table.tag] = table;
  16599. }
  16600. var isTrueType = !tables['CFF '];
  16601. if (!isTrueType) {
  16602. // OpenType font
  16603. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16604. // no major tables: throwing everything at CFFFont
  16605. cffFile = new Stream(tables['CFF '].data);
  16606. cff = new CFFFont(cffFile, properties);
  16607. return this.convert(name, cff, properties);
  16608. }
  16609. delete tables.glyf;
  16610. delete tables.loca;
  16611. delete tables.fpgm;
  16612. delete tables.prep;
  16613. delete tables['cvt '];
  16614. this.isOpenType = true;
  16615. } else {
  16616. if (!tables.glyf || !tables.loca) {
  16617. error('Required "glyf" or "loca" tables are not found');
  16618. }
  16619. this.isOpenType = false;
  16620. }
  16621. if (!tables.maxp) {
  16622. error('Required "maxp" table is not found');
  16623. }
  16624. font.pos = (font.start || 0) + tables.maxp.offset;
  16625. var version = font.getInt32();
  16626. var numGlyphs = font.getUint16();
  16627. var maxFunctionDefs = 0;
  16628. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16629. // maxZones can be invalid
  16630. font.pos += 8;
  16631. var maxZones = font.getUint16();
  16632. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16633. tables.maxp.data[14] = 0;
  16634. tables.maxp.data[15] = 2;
  16635. }
  16636. font.pos += 4;
  16637. maxFunctionDefs = font.getUint16();
  16638. }
  16639. var dupFirstEntry = false;
  16640. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16641. properties.toUnicode.get(0) > '\u0000') {
  16642. // oracle's defect (see 3427), duplicating first entry
  16643. dupFirstEntry = true;
  16644. numGlyphs++;
  16645. tables.maxp.data[4] = numGlyphs >> 8;
  16646. tables.maxp.data[5] = numGlyphs & 255;
  16647. }
  16648. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16649. tables['cvt '], maxFunctionDefs);
  16650. if (!hintsValid) {
  16651. delete tables.fpgm;
  16652. delete tables.prep;
  16653. delete tables['cvt '];
  16654. }
  16655. // Ensure the hmtx table contains the advance width and
  16656. // sidebearings information for numGlyphs in the maxp table
  16657. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16658. if (!tables.head) {
  16659. error('Required "head" table is not found');
  16660. }
  16661. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16662. var missingGlyphs = {};
  16663. if (isTrueType) {
  16664. var isGlyphLocationsLong = int16(tables.head.data[50],
  16665. tables.head.data[51]);
  16666. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  16667. numGlyphs, isGlyphLocationsLong,
  16668. hintsValid, dupFirstEntry);
  16669. }
  16670. if (!tables.hhea) {
  16671. error('Required "hhea" table is not found');
  16672. }
  16673. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16674. // Sometimes it's 0. That needs to be fixed
  16675. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16676. tables.hhea.data[10] = 0xFF;
  16677. tables.hhea.data[11] = 0xFF;
  16678. }
  16679. // The 'post' table has glyphs names.
  16680. if (tables.post) {
  16681. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16682. if (!valid) {
  16683. tables.post = null;
  16684. }
  16685. }
  16686. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  16687. function hasGlyph(glyphId, charCode) {
  16688. if (!missingGlyphs[glyphId]) {
  16689. return true;
  16690. }
  16691. if (charCode >= 0 && toUnicode.has(charCode)) {
  16692. return true;
  16693. }
  16694. return false;
  16695. }
  16696. if (properties.type === 'CIDFontType2') {
  16697. var cidToGidMap = properties.cidToGidMap || [];
  16698. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  16699. properties.cMap.forEach(function(charCode, cid) {
  16700. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16701. var glyphId = -1;
  16702. if (isCidToGidMapEmpty) {
  16703. glyphId = charCode;
  16704. } else if (cidToGidMap[cid] !== undefined) {
  16705. glyphId = cidToGidMap[cid];
  16706. }
  16707. if (glyphId >= 0 && glyphId < numGlyphs &&
  16708. hasGlyph(glyphId, charCode)) {
  16709. charCodeToGlyphId[charCode] = glyphId;
  16710. }
  16711. });
  16712. if (dupFirstEntry) {
  16713. charCodeToGlyphId[0] = numGlyphs - 1;
  16714. }
  16715. } else {
  16716. // Most of the following logic in this code branch is based on the
  16717. // 9.6.6.4 of the PDF spec.
  16718. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16719. var cmapPlatformId = cmapTable.platformId;
  16720. var cmapEncodingId = cmapTable.encodingId;
  16721. var cmapMappings = cmapTable.mappings;
  16722. var cmapMappingsLength = cmapMappings.length;
  16723. var hasEncoding = properties.differences.length ||
  16724. !!properties.baseEncodingName;
  16725. // The spec seems to imply that if the font is symbolic the encoding
  16726. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16727. // where the the font is symbolic and it has an encoding.
  16728. if (hasEncoding &&
  16729. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16730. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16731. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16732. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16733. // When no preferred cmap table was found and |baseEncodingName| is
  16734. // one of the predefined encodings, we seem to obtain a better
  16735. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16736. // TODO: Note that this is a hack which should be removed as soon as
  16737. // we have proper support for more exotic cmap tables.
  16738. var baseEncoding = [];
  16739. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16740. properties.baseEncodingName === 'WinAnsiEncoding') {
  16741. baseEncoding = Encodings[properties.baseEncodingName];
  16742. }
  16743. for (charCode = 0; charCode < 256; charCode++) {
  16744. var glyphName;
  16745. if (this.differences && charCode in this.differences) {
  16746. glyphName = this.differences[charCode];
  16747. } else if (charCode in baseEncoding &&
  16748. baseEncoding[charCode] !== '') {
  16749. glyphName = baseEncoding[charCode];
  16750. } else {
  16751. glyphName = Encodings.StandardEncoding[charCode];
  16752. }
  16753. if (!glyphName) {
  16754. continue;
  16755. }
  16756. var unicodeOrCharCode;
  16757. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16758. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16759. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16760. // TODO: the encoding needs to be updated with mac os table.
  16761. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16762. }
  16763. var found = false;
  16764. for (i = 0; i < cmapMappingsLength; ++i) {
  16765. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  16766. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  16767. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16768. found = true;
  16769. break;
  16770. }
  16771. }
  16772. if (!found && properties.glyphNames) {
  16773. // Try to map using the post table. There are currently no known
  16774. // pdfs that this fixes.
  16775. var glyphId = properties.glyphNames.indexOf(glyphName);
  16776. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  16777. charCodeToGlyphId[charCode] = glyphId;
  16778. }
  16779. }
  16780. }
  16781. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  16782. // Default Unicode semantics, use the charcodes as is.
  16783. for (i = 0; i < cmapMappingsLength; ++i) {
  16784. charCodeToGlyphId[cmapMappings[i].charCode] =
  16785. cmapMappings[i].glyphId;
  16786. }
  16787. } else {
  16788. // For (3, 0) cmap tables:
  16789. // The charcode key being stored in charCodeToGlyphId is the lower
  16790. // byte of the two-byte charcodes of the cmap table since according to
  16791. // the spec: 'each byte from the string shall be prepended with the
  16792. // high byte of the range [of charcodes in the cmap table], to form
  16793. // a two-byte character, which shall be used to select the
  16794. // associated glyph description from the subtable'.
  16795. //
  16796. // For (1, 0) cmap tables:
  16797. // 'single bytes from the string shall be used to look up the
  16798. // associated glyph descriptions from the subtable'. This means
  16799. // charcodes in the cmap will be single bytes, so no-op since
  16800. // glyph.charCode & 0xFF === glyph.charCode
  16801. for (i = 0; i < cmapMappingsLength; ++i) {
  16802. charCode = cmapMappings[i].charCode & 0xFF;
  16803. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16804. }
  16805. }
  16806. }
  16807. if (charCodeToGlyphId.length === 0) {
  16808. // defines at least one glyph
  16809. charCodeToGlyphId[0] = 0;
  16810. }
  16811. // Converting glyphs and ids into font's cmap table
  16812. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16813. this.toFontChar = newMapping.toFontChar;
  16814. tables.cmap = {
  16815. tag: 'cmap',
  16816. data: createCmapTable(newMapping.charCodeToGlyphId)
  16817. };
  16818. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16819. // extract some more font properties from the OpenType head and
  16820. // hhea tables; yMin and descent value are always negative
  16821. var override = {
  16822. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16823. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16824. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16825. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16826. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16827. };
  16828. tables['OS/2'] = {
  16829. tag: 'OS/2',
  16830. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16831. override)
  16832. };
  16833. }
  16834. // Rewrite the 'post' table if needed
  16835. if (!tables.post) {
  16836. tables.post = {
  16837. tag: 'post',
  16838. data: createPostTable(properties)
  16839. };
  16840. }
  16841. if (!isTrueType) {
  16842. try {
  16843. // Trying to repair CFF file
  16844. cffFile = new Stream(tables['CFF '].data);
  16845. var parser = new CFFParser(cffFile, properties);
  16846. cff = parser.parse();
  16847. var compiler = new CFFCompiler(cff);
  16848. tables['CFF '].data = compiler.compile();
  16849. } catch (e) {
  16850. warn('Failed to compile font ' + properties.loadedName);
  16851. }
  16852. }
  16853. // Re-creating 'name' table
  16854. if (!tables.name) {
  16855. tables.name = {
  16856. tag: 'name',
  16857. data: createNameTable(this.name)
  16858. };
  16859. } else {
  16860. // ... using existing 'name' table as prototype
  16861. var namePrototype = readNameTable(tables.name);
  16862. tables.name.data = createNameTable(name, namePrototype);
  16863. }
  16864. var builder = new OpenTypeFileBuilder(header.version);
  16865. for (var tableTag in tables) {
  16866. builder.addTable(tableTag, tables[tableTag].data);
  16867. }
  16868. return builder.toArray();
  16869. },
  16870. convert: function Font_convert(fontName, font, properties) {
  16871. // TODO: Check the charstring widths to determine this.
  16872. properties.fixedPitch = false;
  16873. var mapping = font.getGlyphMapping(properties);
  16874. var newMapping = adjustMapping(mapping, properties);
  16875. this.toFontChar = newMapping.toFontChar;
  16876. var numGlyphs = font.numGlyphs;
  16877. function getCharCodes(charCodeToGlyphId, glyphId) {
  16878. var charCodes = null;
  16879. for (var charCode in charCodeToGlyphId) {
  16880. if (glyphId === charCodeToGlyphId[charCode]) {
  16881. if (!charCodes) {
  16882. charCodes = [];
  16883. }
  16884. charCodes.push(charCode | 0);
  16885. }
  16886. }
  16887. return charCodes;
  16888. }
  16889. function createCharCode(charCodeToGlyphId, glyphId) {
  16890. for (var charCode in charCodeToGlyphId) {
  16891. if (glyphId === charCodeToGlyphId[charCode]) {
  16892. return charCode | 0;
  16893. }
  16894. }
  16895. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16896. glyphId;
  16897. return newMapping.nextAvailableFontCharCode++;
  16898. }
  16899. var seacs = font.seacs;
  16900. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16901. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16902. var charset = font.getCharset();
  16903. var seacMap = Object.create(null);
  16904. for (var glyphId in seacs) {
  16905. glyphId |= 0;
  16906. var seac = seacs[glyphId];
  16907. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16908. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16909. var baseGlyphId = charset.indexOf(baseGlyphName);
  16910. var accentGlyphId = charset.indexOf(accentGlyphName);
  16911. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16912. continue;
  16913. }
  16914. var accentOffset = {
  16915. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16916. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16917. };
  16918. var charCodes = getCharCodes(mapping, glyphId);
  16919. if (!charCodes) {
  16920. // There's no point in mapping it if the char code was never mapped
  16921. // to begin with.
  16922. continue;
  16923. }
  16924. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16925. var charCode = charCodes[i];
  16926. // Find a fontCharCode that maps to the base and accent glyphs.
  16927. // If one doesn't exists, create it.
  16928. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16929. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16930. baseGlyphId);
  16931. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16932. accentGlyphId);
  16933. seacMap[charCode] = {
  16934. baseFontCharCode: baseFontCharCode,
  16935. accentFontCharCode: accentFontCharCode,
  16936. accentOffset: accentOffset
  16937. };
  16938. }
  16939. }
  16940. properties.seacMap = seacMap;
  16941. }
  16942. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16943. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16944. // PostScript Font Program
  16945. builder.addTable('CFF ', font.data);
  16946. // OS/2 and Windows Specific metrics
  16947. builder.addTable('OS/2', createOS2Table(properties,
  16948. newMapping.charCodeToGlyphId));
  16949. // Character to glyphs mapping
  16950. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16951. // Font header
  16952. builder.addTable('head',
  16953. '\x00\x01\x00\x00' + // Version number
  16954. '\x00\x00\x10\x00' + // fontRevision
  16955. '\x00\x00\x00\x00' + // checksumAdjustement
  16956. '\x5F\x0F\x3C\xF5' + // magicNumber
  16957. '\x00\x00' + // Flags
  16958. safeString16(unitsPerEm) + // unitsPerEM
  16959. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16960. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16961. '\x00\x00' + // xMin
  16962. safeString16(properties.descent) + // yMin
  16963. '\x0F\xFF' + // xMax
  16964. safeString16(properties.ascent) + // yMax
  16965. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16966. '\x00\x11' + // lowestRecPPEM
  16967. '\x00\x00' + // fontDirectionHint
  16968. '\x00\x00' + // indexToLocFormat
  16969. '\x00\x00'); // glyphDataFormat
  16970. // Horizontal header
  16971. builder.addTable('hhea',
  16972. '\x00\x01\x00\x00' + // Version number
  16973. safeString16(properties.ascent) + // Typographic Ascent
  16974. safeString16(properties.descent) + // Typographic Descent
  16975. '\x00\x00' + // Line Gap
  16976. '\xFF\xFF' + // advanceWidthMax
  16977. '\x00\x00' + // minLeftSidebearing
  16978. '\x00\x00' + // minRightSidebearing
  16979. '\x00\x00' + // xMaxExtent
  16980. safeString16(properties.capHeight) + // caretSlopeRise
  16981. safeString16(Math.tan(properties.italicAngle) *
  16982. properties.xHeight) + // caretSlopeRun
  16983. '\x00\x00' + // caretOffset
  16984. '\x00\x00' + // -reserved-
  16985. '\x00\x00' + // -reserved-
  16986. '\x00\x00' + // -reserved-
  16987. '\x00\x00' + // -reserved-
  16988. '\x00\x00' + // metricDataFormat
  16989. string16(numGlyphs)); // Number of HMetrics
  16990. // Horizontal metrics
  16991. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16992. var charstrings = font.charstrings;
  16993. var cffWidths = font.cff ? font.cff.widths : null;
  16994. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16995. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16996. var width = 0;
  16997. if (charstrings) {
  16998. var charstring = charstrings[i - 1];
  16999. width = 'width' in charstring ? charstring.width : 0;
  17000. } else if (cffWidths) {
  17001. width = Math.ceil(cffWidths[i] || 0);
  17002. }
  17003. hmtx += string16(width) + string16(0);
  17004. }
  17005. return hmtx;
  17006. })());
  17007. // Maximum profile
  17008. builder.addTable('maxp',
  17009. '\x00\x00\x50\x00' + // Version number
  17010. string16(numGlyphs)); // Num of glyphs
  17011. // Naming tables
  17012. builder.addTable('name', createNameTable(fontName));
  17013. // PostScript informations
  17014. builder.addTable('post', createPostTable(properties));
  17015. return builder.toArray();
  17016. },
  17017. /**
  17018. * Builds a char code to unicode map based on section 9.10 of the spec.
  17019. * @param {Object} properties Font properties object.
  17020. * @return {Object} A ToUnicodeMap object.
  17021. */
  17022. buildToUnicode: function Font_buildToUnicode(properties) {
  17023. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17024. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17025. return properties.toUnicode;
  17026. }
  17027. // According to the spec if the font is a simple font we should only map
  17028. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17029. // the differences array only contains adobe standard or symbol set names,
  17030. // in pratice it seems better to always try to create a toUnicode
  17031. // map based of the default encoding.
  17032. var toUnicode, charcode;
  17033. if (!properties.composite /* is simple font */) {
  17034. toUnicode = [];
  17035. var encoding = properties.defaultEncoding.slice();
  17036. var baseEncodingName = properties.baseEncodingName;
  17037. // Merge in the differences array.
  17038. var differences = properties.differences;
  17039. for (charcode in differences) {
  17040. encoding[charcode] = differences[charcode];
  17041. }
  17042. for (charcode in encoding) {
  17043. // a) Map the character code to a character name.
  17044. var glyphName = encoding[charcode];
  17045. // b) Look up the character name in the Adobe Glyph List (see the
  17046. // Bibliography) to obtain the corresponding Unicode value.
  17047. if (glyphName === '') {
  17048. continue;
  17049. } else if (GlyphsUnicode[glyphName] === undefined) {
  17050. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17051. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17052. var code = 0;
  17053. switch (glyphName[0]) {
  17054. case 'G': // Gxx glyph
  17055. if (glyphName.length === 3) {
  17056. code = parseInt(glyphName.substr(1), 16);
  17057. }
  17058. break;
  17059. case 'g': // g00xx glyph
  17060. if (glyphName.length === 5) {
  17061. code = parseInt(glyphName.substr(1), 16);
  17062. }
  17063. break;
  17064. case 'C': // Cddd glyph
  17065. case 'c': // cddd glyph
  17066. if (glyphName.length >= 3) {
  17067. code = +glyphName.substr(1);
  17068. }
  17069. break;
  17070. }
  17071. if (code) {
  17072. // If |baseEncodingName| is one the predefined encodings,
  17073. // and |code| equals |charcode|, using the glyph defined in the
  17074. // baseEncoding seems to yield a better |toUnicode| mapping
  17075. // (fixes issue 5070).
  17076. if (baseEncodingName && code === +charcode) {
  17077. var baseEncoding = Encodings[baseEncodingName];
  17078. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17079. toUnicode[charcode] =
  17080. String.fromCharCode(GlyphsUnicode[glyphName]);
  17081. continue;
  17082. }
  17083. }
  17084. toUnicode[charcode] = String.fromCharCode(code);
  17085. }
  17086. continue;
  17087. }
  17088. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17089. }
  17090. return new ToUnicodeMap(toUnicode);
  17091. }
  17092. // If the font is a composite font that uses one of the predefined CMaps
  17093. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17094. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17095. // Adobe-Korea1 character collection:
  17096. if (properties.composite && (
  17097. (properties.cMap.builtInCMap &&
  17098. !(properties.cMap instanceof IdentityCMap)) ||
  17099. (properties.cidSystemInfo.registry === 'Adobe' &&
  17100. (properties.cidSystemInfo.ordering === 'GB1' ||
  17101. properties.cidSystemInfo.ordering === 'CNS1' ||
  17102. properties.cidSystemInfo.ordering === 'Japan1' ||
  17103. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17104. // Then:
  17105. // a) Map the character code to a character identifier (CID) according
  17106. // to the font’s CMap.
  17107. // b) Obtain the registry and ordering of the character collection used
  17108. // by the font’s CMap (for example, Adobe and Japan1) from its
  17109. // CIDSystemInfo dictionary.
  17110. var registry = properties.cidSystemInfo.registry;
  17111. var ordering = properties.cidSystemInfo.ordering;
  17112. // c) Construct a second CMap name by concatenating the registry and
  17113. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17114. // (for example, Adobe–Japan1–UCS2).
  17115. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17116. // d) Obtain the CMap with the name constructed in step (c) (available
  17117. // from the ASN Web site; see the Bibliography).
  17118. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17119. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17120. var cMap = properties.cMap;
  17121. toUnicode = [];
  17122. cMap.forEach(function(charcode, cid) {
  17123. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17124. // e) Map the CID obtained in step (a) according to the CMap obtained
  17125. // in step (d), producing a Unicode value.
  17126. var ucs2 = ucs2CMap.lookup(cid);
  17127. if (ucs2) {
  17128. toUnicode[charcode] =
  17129. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17130. ucs2.charCodeAt(1));
  17131. }
  17132. });
  17133. return new ToUnicodeMap(toUnicode);
  17134. }
  17135. // The viewer's choice, just use an identity map.
  17136. return new IdentityToUnicodeMap(properties.firstChar,
  17137. properties.lastChar);
  17138. },
  17139. get spaceWidth() {
  17140. if ('_shadowWidth' in this) {
  17141. return this._shadowWidth;
  17142. }
  17143. // trying to estimate space character width
  17144. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17145. var width;
  17146. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17147. var glyphName = possibleSpaceReplacements[i];
  17148. // if possible, getting width by glyph name
  17149. if (glyphName in this.widths) {
  17150. width = this.widths[glyphName];
  17151. break;
  17152. }
  17153. var glyphUnicode = GlyphsUnicode[glyphName];
  17154. // finding the charcode via unicodeToCID map
  17155. var charcode = 0;
  17156. if (this.composite) {
  17157. if (this.cMap.contains(glyphUnicode)) {
  17158. charcode = this.cMap.lookup(glyphUnicode);
  17159. }
  17160. }
  17161. // ... via toUnicode map
  17162. if (!charcode && 'toUnicode' in this) {
  17163. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17164. }
  17165. // setting it to unicode if negative or undefined
  17166. if (charcode <= 0) {
  17167. charcode = glyphUnicode;
  17168. }
  17169. // trying to get width via charcode
  17170. width = this.widths[charcode];
  17171. if (width) {
  17172. break; // the non-zero width found
  17173. }
  17174. }
  17175. width = width || this.defaultWidth;
  17176. // Do not shadow the property here. See discussion:
  17177. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17178. this._shadowWidth = width;
  17179. return width;
  17180. },
  17181. charToGlyph: function Font_charToGlyph(charcode) {
  17182. var fontCharCode, width, operatorListId;
  17183. var widthCode = charcode;
  17184. if (this.cMap && this.cMap.contains(charcode)) {
  17185. widthCode = this.cMap.lookup(charcode);
  17186. }
  17187. width = this.widths[widthCode];
  17188. width = isNum(width) ? width : this.defaultWidth;
  17189. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17190. var unicode = this.toUnicode.get(charcode) || charcode;
  17191. if (typeof unicode === 'number') {
  17192. unicode = String.fromCharCode(unicode);
  17193. }
  17194. // First try the toFontChar map, if it's not there then try falling
  17195. // back to the char code.
  17196. fontCharCode = this.toFontChar[charcode] || charcode;
  17197. if (this.missingFile) {
  17198. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17199. }
  17200. if (this.isType3Font) {
  17201. // Font char code in this case is actually a glyph name.
  17202. operatorListId = fontCharCode;
  17203. }
  17204. var accent = null;
  17205. if (this.seacMap && this.seacMap[charcode]) {
  17206. var seac = this.seacMap[charcode];
  17207. fontCharCode = seac.baseFontCharCode;
  17208. accent = {
  17209. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17210. offset: seac.accentOffset
  17211. };
  17212. }
  17213. var fontChar = String.fromCharCode(fontCharCode);
  17214. var glyph = this.glyphCache[charcode];
  17215. if (!glyph ||
  17216. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17217. operatorListId)) {
  17218. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17219. operatorListId);
  17220. this.glyphCache[charcode] = glyph;
  17221. }
  17222. return glyph;
  17223. },
  17224. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17225. var charsCache = this.charsCache;
  17226. var glyphs, glyph, charcode;
  17227. // if we translated this string before, just grab it from the cache
  17228. if (charsCache) {
  17229. glyphs = charsCache[chars];
  17230. if (glyphs) {
  17231. return glyphs;
  17232. }
  17233. }
  17234. // lazily create the translation cache
  17235. if (!charsCache) {
  17236. charsCache = this.charsCache = Object.create(null);
  17237. }
  17238. glyphs = [];
  17239. var charsCacheKey = chars;
  17240. var i = 0, ii;
  17241. if (this.cMap) {
  17242. // composite fonts have multi-byte strings convert the string from
  17243. // single-byte to multi-byte
  17244. var c = {};
  17245. while (i < chars.length) {
  17246. this.cMap.readCharCode(chars, i, c);
  17247. charcode = c.charcode;
  17248. var length = c.length;
  17249. i += length;
  17250. glyph = this.charToGlyph(charcode);
  17251. glyphs.push(glyph);
  17252. // placing null after each word break charcode (ASCII SPACE)
  17253. // Ignore occurences of 0x20 in multiple-byte codes.
  17254. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17255. glyphs.push(null);
  17256. }
  17257. }
  17258. } else {
  17259. for (i = 0, ii = chars.length; i < ii; ++i) {
  17260. charcode = chars.charCodeAt(i);
  17261. glyph = this.charToGlyph(charcode);
  17262. glyphs.push(glyph);
  17263. if (charcode === 0x20) {
  17264. glyphs.push(null);
  17265. }
  17266. }
  17267. }
  17268. // Enter the translated string into the cache
  17269. return (charsCache[charsCacheKey] = glyphs);
  17270. }
  17271. };
  17272. return Font;
  17273. })();
  17274. var ErrorFont = (function ErrorFontClosure() {
  17275. function ErrorFont(error) {
  17276. this.error = error;
  17277. this.loadedName = 'g_font_error';
  17278. this.loading = false;
  17279. }
  17280. ErrorFont.prototype = {
  17281. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17282. return [];
  17283. },
  17284. exportData: function ErrorFont_exportData() {
  17285. return {error: this.error};
  17286. }
  17287. };
  17288. return ErrorFont;
  17289. })();
  17290. /**
  17291. * Shared logic for building a char code to glyph id mapping for Type1 and
  17292. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17293. * @param {Object} properties Font properties object.
  17294. * @param {Object} builtInEncoding The encoding contained within the actual font
  17295. * data.
  17296. * @param {Array} Array of glyph names where the index is the glyph ID.
  17297. * @returns {Object} A char code to glyph ID map.
  17298. */
  17299. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17300. var charCodeToGlyphId = Object.create(null);
  17301. var glyphId, charCode, baseEncoding;
  17302. if (properties.baseEncodingName) {
  17303. // If a valid base encoding name was used, the mapping is initialized with
  17304. // that.
  17305. baseEncoding = Encodings[properties.baseEncodingName];
  17306. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17307. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17308. if (glyphId >= 0) {
  17309. charCodeToGlyphId[charCode] = glyphId;
  17310. } else {
  17311. charCodeToGlyphId[charCode] = 0; // notdef
  17312. }
  17313. }
  17314. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17315. // For a symbolic font the encoding should be the fonts built-in
  17316. // encoding.
  17317. for (charCode in builtInEncoding) {
  17318. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17319. }
  17320. } else {
  17321. // For non-symbolic fonts that don't have a base encoding the standard
  17322. // encoding should be used.
  17323. baseEncoding = Encodings.StandardEncoding;
  17324. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17325. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17326. if (glyphId >= 0) {
  17327. charCodeToGlyphId[charCode] = glyphId;
  17328. } else {
  17329. charCodeToGlyphId[charCode] = 0; // notdef
  17330. }
  17331. }
  17332. }
  17333. // Lastly, merge in the differences.
  17334. var differences = properties.differences;
  17335. if (differences) {
  17336. for (charCode in differences) {
  17337. var glyphName = differences[charCode];
  17338. glyphId = glyphNames.indexOf(glyphName);
  17339. if (glyphId >= 0) {
  17340. charCodeToGlyphId[charCode] = glyphId;
  17341. } else {
  17342. charCodeToGlyphId[charCode] = 0; // notdef
  17343. }
  17344. }
  17345. }
  17346. return charCodeToGlyphId;
  17347. }
  17348. /*
  17349. * CharStrings are encoded following the the CharString Encoding sequence
  17350. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17351. * The value in a byte indicates a command, a number, or subsequent bytes
  17352. * that are to be interpreted in a special way.
  17353. *
  17354. * CharString Number Encoding:
  17355. * A CharString byte containing the values from 32 through 255 inclusive
  17356. * indicate an integer. These values are decoded in four ranges.
  17357. *
  17358. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17359. * indicate the integer v - 139. Thus, the integer values from -107 through
  17360. * 107 inclusive may be encoded in single byte.
  17361. *
  17362. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17363. * indicates an integer involving the next byte, w, according to the formula:
  17364. * [(v - 247) x 256] + w + 108
  17365. *
  17366. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17367. * indicates an integer involving the next byte, w, according to the formula:
  17368. * -[(v - 251) * 256] - w - 108
  17369. *
  17370. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17371. * are a two complement signed integer. The first of these bytes contains the
  17372. * highest order bits, the second byte contains the next higher order bits
  17373. * and the fourth byte contain the lowest order bits.
  17374. *
  17375. *
  17376. * CharString Command Encoding:
  17377. * CharStrings commands are encoded in 1 or 2 bytes.
  17378. *
  17379. * Single byte commands are encoded in 1 byte that contains a value between
  17380. * 0 and 31 inclusive.
  17381. * If a command byte contains the value 12, then the value in the next byte
  17382. * indicates a command. This "escape" mechanism allows many extra commands
  17383. * to be encoded and this encoding technique helps to minimize the length of
  17384. * the charStrings.
  17385. */
  17386. var Type1CharString = (function Type1CharStringClosure() {
  17387. var COMMAND_MAP = {
  17388. 'hstem': [1],
  17389. 'vstem': [3],
  17390. 'vmoveto': [4],
  17391. 'rlineto': [5],
  17392. 'hlineto': [6],
  17393. 'vlineto': [7],
  17394. 'rrcurveto': [8],
  17395. 'callsubr': [10],
  17396. 'flex': [12, 35],
  17397. 'drop' : [12, 18],
  17398. 'endchar': [14],
  17399. 'rmoveto': [21],
  17400. 'hmoveto': [22],
  17401. 'vhcurveto': [30],
  17402. 'hvcurveto': [31]
  17403. };
  17404. function Type1CharString() {
  17405. this.width = 0;
  17406. this.lsb = 0;
  17407. this.flexing = false;
  17408. this.output = [];
  17409. this.stack = [];
  17410. }
  17411. Type1CharString.prototype = {
  17412. convert: function Type1CharString_convert(encoded, subrs) {
  17413. var count = encoded.length;
  17414. var error = false;
  17415. var wx, sbx, subrNumber;
  17416. for (var i = 0; i < count; i++) {
  17417. var value = encoded[i];
  17418. if (value < 32) {
  17419. if (value === 12) {
  17420. value = (value << 8) + encoded[++i];
  17421. }
  17422. switch (value) {
  17423. case 1: // hstem
  17424. if (!HINTING_ENABLED) {
  17425. this.stack = [];
  17426. break;
  17427. }
  17428. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17429. break;
  17430. case 3: // vstem
  17431. if (!HINTING_ENABLED) {
  17432. this.stack = [];
  17433. break;
  17434. }
  17435. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17436. break;
  17437. case 4: // vmoveto
  17438. if (this.flexing) {
  17439. if (this.stack.length < 1) {
  17440. error = true;
  17441. break;
  17442. }
  17443. // Add the dx for flex and but also swap the values so they are
  17444. // the right order.
  17445. var dy = this.stack.pop();
  17446. this.stack.push(0, dy);
  17447. break;
  17448. }
  17449. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17450. break;
  17451. case 5: // rlineto
  17452. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17453. break;
  17454. case 6: // hlineto
  17455. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17456. break;
  17457. case 7: // vlineto
  17458. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17459. break;
  17460. case 8: // rrcurveto
  17461. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17462. break;
  17463. case 9: // closepath
  17464. // closepath is a Type1 command that does not take argument and is
  17465. // useless in Type2 and it can simply be ignored.
  17466. this.stack = [];
  17467. break;
  17468. case 10: // callsubr
  17469. if (this.stack.length < 1) {
  17470. error = true;
  17471. break;
  17472. }
  17473. subrNumber = this.stack.pop();
  17474. error = this.convert(subrs[subrNumber], subrs);
  17475. break;
  17476. case 11: // return
  17477. return error;
  17478. case 13: // hsbw
  17479. if (this.stack.length < 2) {
  17480. error = true;
  17481. break;
  17482. }
  17483. // To convert to type2 we have to move the width value to the
  17484. // first part of the charstring and then use hmoveto with lsb.
  17485. wx = this.stack.pop();
  17486. sbx = this.stack.pop();
  17487. this.lsb = sbx;
  17488. this.width = wx;
  17489. this.stack.push(wx, sbx);
  17490. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17491. break;
  17492. case 14: // endchar
  17493. this.output.push(COMMAND_MAP.endchar[0]);
  17494. break;
  17495. case 21: // rmoveto
  17496. if (this.flexing) {
  17497. break;
  17498. }
  17499. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17500. break;
  17501. case 22: // hmoveto
  17502. if (this.flexing) {
  17503. // Add the dy for flex.
  17504. this.stack.push(0);
  17505. break;
  17506. }
  17507. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17508. break;
  17509. case 30: // vhcurveto
  17510. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17511. break;
  17512. case 31: // hvcurveto
  17513. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17514. break;
  17515. case (12 << 8) + 0: // dotsection
  17516. // dotsection is a Type1 command to specify some hinting feature
  17517. // for dots that do not take a parameter and it can safely be
  17518. // ignored for Type2.
  17519. this.stack = [];
  17520. break;
  17521. case (12 << 8) + 1: // vstem3
  17522. if (!HINTING_ENABLED) {
  17523. this.stack = [];
  17524. break;
  17525. }
  17526. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17527. // multiple parameters, so instead of returning [vh]stem3 take a
  17528. // shortcut and return [vhstem] instead.
  17529. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17530. break;
  17531. case (12 << 8) + 2: // hstem3
  17532. if (!HINTING_ENABLED) {
  17533. this.stack = [];
  17534. break;
  17535. }
  17536. // See vstem3.
  17537. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17538. break;
  17539. case (12 << 8) + 6: // seac
  17540. // seac is like type 2's special endchar but it doesn't use the
  17541. // first argument asb, so remove it.
  17542. if (SEAC_ANALYSIS_ENABLED) {
  17543. this.seac = this.stack.splice(-4, 4);
  17544. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17545. } else {
  17546. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17547. }
  17548. break;
  17549. case (12 << 8) + 7: // sbw
  17550. if (this.stack.length < 4) {
  17551. error = true;
  17552. break;
  17553. }
  17554. // To convert to type2 we have to move the width value to the
  17555. // first part of the charstring and then use rmoveto with
  17556. // (dx, dy). The height argument will not be used for vmtx and
  17557. // vhea tables reconstruction -- ignoring it.
  17558. var wy = this.stack.pop();
  17559. wx = this.stack.pop();
  17560. var sby = this.stack.pop();
  17561. sbx = this.stack.pop();
  17562. this.lsb = sbx;
  17563. this.width = wx;
  17564. this.stack.push(wx, sbx, sby);
  17565. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17566. break;
  17567. case (12 << 8) + 12: // div
  17568. if (this.stack.length < 2) {
  17569. error = true;
  17570. break;
  17571. }
  17572. var num2 = this.stack.pop();
  17573. var num1 = this.stack.pop();
  17574. this.stack.push(num1 / num2);
  17575. break;
  17576. case (12 << 8) + 16: // callothersubr
  17577. if (this.stack.length < 2) {
  17578. error = true;
  17579. break;
  17580. }
  17581. subrNumber = this.stack.pop();
  17582. var numArgs = this.stack.pop();
  17583. if (subrNumber === 0 && numArgs === 3) {
  17584. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17585. this.stack.push(
  17586. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17587. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17588. flexArgs[4], // bcp2x
  17589. flexArgs[5], // bcp2y
  17590. flexArgs[6], // p2x
  17591. flexArgs[7], // p2y
  17592. flexArgs[8], // bcp3x
  17593. flexArgs[9], // bcp3y
  17594. flexArgs[10], // bcp4x
  17595. flexArgs[11], // bcp4y
  17596. flexArgs[12], // p3x
  17597. flexArgs[13], // p3y
  17598. flexArgs[14] // flexDepth
  17599. // 15 = finalx unused by flex
  17600. // 16 = finaly unused by flex
  17601. );
  17602. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17603. this.flexing = false;
  17604. this.stack.push(flexArgs[15], flexArgs[16]);
  17605. } else if (subrNumber === 1 && numArgs === 0) {
  17606. this.flexing = true;
  17607. }
  17608. break;
  17609. case (12 << 8) + 17: // pop
  17610. // Ignore this since it is only used with othersubr.
  17611. break;
  17612. case (12 << 8) + 33: // setcurrentpoint
  17613. // Ignore for now.
  17614. this.stack = [];
  17615. break;
  17616. default:
  17617. warn('Unknown type 1 charstring command of "' + value + '"');
  17618. break;
  17619. }
  17620. if (error) {
  17621. break;
  17622. }
  17623. continue;
  17624. } else if (value <= 246) {
  17625. value = value - 139;
  17626. } else if (value <= 250) {
  17627. value = ((value - 247) * 256) + encoded[++i] + 108;
  17628. } else if (value <= 254) {
  17629. value = -((value - 251) * 256) - encoded[++i] - 108;
  17630. } else {
  17631. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17632. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17633. }
  17634. this.stack.push(value);
  17635. }
  17636. return error;
  17637. },
  17638. executeCommand: function(howManyArgs, command, keepStack) {
  17639. var stackLength = this.stack.length;
  17640. if (howManyArgs > stackLength) {
  17641. return true;
  17642. }
  17643. var start = stackLength - howManyArgs;
  17644. for (var i = start; i < stackLength; i++) {
  17645. var value = this.stack[i];
  17646. if (value === (value | 0)) { // int
  17647. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17648. } else { // fixed point
  17649. value = (65536 * value) | 0;
  17650. this.output.push(255,
  17651. (value >> 24) & 0xFF,
  17652. (value >> 16) & 0xFF,
  17653. (value >> 8) & 0xFF,
  17654. value & 0xFF);
  17655. }
  17656. }
  17657. this.output.push.apply(this.output, command);
  17658. if (keepStack) {
  17659. this.stack.splice(start, howManyArgs);
  17660. } else {
  17661. this.stack.length = 0;
  17662. }
  17663. return false;
  17664. }
  17665. };
  17666. return Type1CharString;
  17667. })();
  17668. /*
  17669. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17670. * program. Some of its logic depends on the Type2 charstrings
  17671. * structure.
  17672. * Note: this doesn't really parse the font since that would require evaluation
  17673. * of PostScript, but it is possible in most cases to extract what we need
  17674. * without a full parse.
  17675. */
  17676. var Type1Parser = (function Type1ParserClosure() {
  17677. /*
  17678. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17679. * of Plaintext Bytes. The function took a key as a parameter which can be
  17680. * for decrypting the eexec block of for decoding charStrings.
  17681. */
  17682. var EEXEC_ENCRYPT_KEY = 55665;
  17683. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17684. function isHexDigit(code) {
  17685. return code >= 48 && code <= 57 || // '0'-'9'
  17686. code >= 65 && code <= 70 || // 'A'-'F'
  17687. code >= 97 && code <= 102; // 'a'-'f'
  17688. }
  17689. function decrypt(data, key, discardNumber) {
  17690. var r = key | 0, c1 = 52845, c2 = 22719;
  17691. var count = data.length;
  17692. var decrypted = new Uint8Array(count);
  17693. for (var i = 0; i < count; i++) {
  17694. var value = data[i];
  17695. decrypted[i] = value ^ (r >> 8);
  17696. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17697. }
  17698. return Array.prototype.slice.call(decrypted, discardNumber);
  17699. }
  17700. function decryptAscii(data, key, discardNumber) {
  17701. var r = key | 0, c1 = 52845, c2 = 22719;
  17702. var count = data.length, maybeLength = count >>> 1;
  17703. var decrypted = new Uint8Array(maybeLength);
  17704. var i, j;
  17705. for (i = 0, j = 0; i < count; i++) {
  17706. var digit1 = data[i];
  17707. if (!isHexDigit(digit1)) {
  17708. continue;
  17709. }
  17710. i++;
  17711. var digit2;
  17712. while (i < count && !isHexDigit(digit2 = data[i])) {
  17713. i++;
  17714. }
  17715. if (i < count) {
  17716. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17717. decrypted[j++] = value ^ (r >> 8);
  17718. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17719. }
  17720. }
  17721. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17722. }
  17723. function isSpecial(c) {
  17724. return c === 0x2F || // '/'
  17725. c === 0x5B || c === 0x5D || // '[', ']'
  17726. c === 0x7B || c === 0x7D || // '{', '}'
  17727. c === 0x28 || c === 0x29; // '(', ')'
  17728. }
  17729. function Type1Parser(stream, encrypted) {
  17730. if (encrypted) {
  17731. var data = stream.getBytes();
  17732. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17733. isHexDigit(data[2]) && isHexDigit(data[3]));
  17734. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17735. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17736. }
  17737. this.stream = stream;
  17738. this.nextChar();
  17739. }
  17740. Type1Parser.prototype = {
  17741. readNumberArray: function Type1Parser_readNumberArray() {
  17742. this.getToken(); // read '[' or '{' (arrays can start with either)
  17743. var array = [];
  17744. while (true) {
  17745. var token = this.getToken();
  17746. if (token === null || token === ']' || token === '}') {
  17747. break;
  17748. }
  17749. array.push(parseFloat(token || 0));
  17750. }
  17751. return array;
  17752. },
  17753. readNumber: function Type1Parser_readNumber() {
  17754. var token = this.getToken();
  17755. return parseFloat(token || 0);
  17756. },
  17757. readInt: function Type1Parser_readInt() {
  17758. // Use '| 0' to prevent setting a double into length such as the double
  17759. // does not flow into the loop variable.
  17760. var token = this.getToken();
  17761. return parseInt(token || 0, 10) | 0;
  17762. },
  17763. readBoolean: function Type1Parser_readBoolean() {
  17764. var token = this.getToken();
  17765. // Use 1 and 0 since that's what type2 charstrings use.
  17766. return token === 'true' ? 1 : 0;
  17767. },
  17768. nextChar : function Type1_nextChar() {
  17769. return (this.currentChar = this.stream.getByte());
  17770. },
  17771. getToken: function Type1Parser_getToken() {
  17772. // Eat whitespace and comments.
  17773. var comment = false;
  17774. var ch = this.currentChar;
  17775. while (true) {
  17776. if (ch === -1) {
  17777. return null;
  17778. }
  17779. if (comment) {
  17780. if (ch === 0x0A || ch === 0x0D) {
  17781. comment = false;
  17782. }
  17783. } else if (ch === 0x25) { // '%'
  17784. comment = true;
  17785. } else if (!Lexer.isSpace(ch)) {
  17786. break;
  17787. }
  17788. ch = this.nextChar();
  17789. }
  17790. if (isSpecial(ch)) {
  17791. this.nextChar();
  17792. return String.fromCharCode(ch);
  17793. }
  17794. var token = '';
  17795. do {
  17796. token += String.fromCharCode(ch);
  17797. ch = this.nextChar();
  17798. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17799. return token;
  17800. },
  17801. /*
  17802. * Returns an object containing a Subrs array and a CharStrings
  17803. * array extracted from and eexec encrypted block of data
  17804. */
  17805. extractFontProgram: function Type1Parser_extractFontProgram() {
  17806. var stream = this.stream;
  17807. var subrs = [], charstrings = [];
  17808. var program = {
  17809. subrs: [],
  17810. charstrings: [],
  17811. properties: {
  17812. 'privateData': {
  17813. 'lenIV': 4
  17814. }
  17815. }
  17816. };
  17817. var token, length, data, lenIV, encoded;
  17818. while ((token = this.getToken()) !== null) {
  17819. if (token !== '/') {
  17820. continue;
  17821. }
  17822. token = this.getToken();
  17823. switch (token) {
  17824. case 'CharStrings':
  17825. // The number immediately following CharStrings must be greater or
  17826. // equal to the number of CharStrings.
  17827. this.getToken();
  17828. this.getToken(); // read in 'dict'
  17829. this.getToken(); // read in 'dup'
  17830. this.getToken(); // read in 'begin'
  17831. while(true) {
  17832. token = this.getToken();
  17833. if (token === null || token === 'end') {
  17834. break;
  17835. }
  17836. if (token !== '/') {
  17837. continue;
  17838. }
  17839. var glyph = this.getToken();
  17840. length = this.readInt();
  17841. this.getToken(); // read in 'RD' or '-|'
  17842. data = stream.makeSubStream(stream.pos, length);
  17843. lenIV = program.properties.privateData['lenIV'];
  17844. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17845. // Skip past the required space and binary data.
  17846. stream.skip(length);
  17847. this.nextChar();
  17848. token = this.getToken(); // read in 'ND' or '|-'
  17849. if (token === 'noaccess') {
  17850. this.getToken(); // read in 'def'
  17851. }
  17852. charstrings.push({
  17853. glyph: glyph,
  17854. encoded: encoded
  17855. });
  17856. }
  17857. break;
  17858. case 'Subrs':
  17859. var num = this.readInt();
  17860. this.getToken(); // read in 'array'
  17861. while ((token = this.getToken()) === 'dup') {
  17862. var index = this.readInt();
  17863. length = this.readInt();
  17864. this.getToken(); // read in 'RD' or '-|'
  17865. data = stream.makeSubStream(stream.pos, length);
  17866. lenIV = program.properties.privateData['lenIV'];
  17867. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17868. // Skip past the required space and binary data.
  17869. stream.skip(length);
  17870. this.nextChar();
  17871. token = this.getToken(); // read in 'NP' or '|'
  17872. if (token === 'noaccess') {
  17873. this.getToken(); // read in 'put'
  17874. }
  17875. subrs[index] = encoded;
  17876. }
  17877. break;
  17878. case 'BlueValues':
  17879. case 'OtherBlues':
  17880. case 'FamilyBlues':
  17881. case 'FamilyOtherBlues':
  17882. var blueArray = this.readNumberArray();
  17883. // *Blue* values may contain invalid data: disables reading of
  17884. // those values when hinting is disabled.
  17885. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17886. HINTING_ENABLED) {
  17887. program.properties.privateData[token] = blueArray;
  17888. }
  17889. break;
  17890. case 'StemSnapH':
  17891. case 'StemSnapV':
  17892. program.properties.privateData[token] = this.readNumberArray();
  17893. break;
  17894. case 'StdHW':
  17895. case 'StdVW':
  17896. program.properties.privateData[token] =
  17897. this.readNumberArray()[0];
  17898. break;
  17899. case 'BlueShift':
  17900. case 'lenIV':
  17901. case 'BlueFuzz':
  17902. case 'BlueScale':
  17903. case 'LanguageGroup':
  17904. case 'ExpansionFactor':
  17905. program.properties.privateData[token] = this.readNumber();
  17906. break;
  17907. case 'ForceBold':
  17908. program.properties.privateData[token] = this.readBoolean();
  17909. break;
  17910. }
  17911. }
  17912. for (var i = 0; i < charstrings.length; i++) {
  17913. glyph = charstrings[i].glyph;
  17914. encoded = charstrings[i].encoded;
  17915. var charString = new Type1CharString();
  17916. var error = charString.convert(encoded, subrs);
  17917. var output = charString.output;
  17918. if (error) {
  17919. // It seems when FreeType encounters an error while evaluating a glyph
  17920. // that it completely ignores the glyph so we'll mimic that behaviour
  17921. // here and put an endchar to make the validator happy.
  17922. output = [14];
  17923. }
  17924. program.charstrings.push({
  17925. glyphName: glyph,
  17926. charstring: output,
  17927. width: charString.width,
  17928. lsb: charString.lsb,
  17929. seac: charString.seac
  17930. });
  17931. }
  17932. return program;
  17933. },
  17934. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17935. var token;
  17936. while ((token = this.getToken()) !== null) {
  17937. if (token !== '/') {
  17938. continue;
  17939. }
  17940. token = this.getToken();
  17941. switch (token) {
  17942. case 'FontMatrix':
  17943. var matrix = this.readNumberArray();
  17944. properties.fontMatrix = matrix;
  17945. break;
  17946. case 'Encoding':
  17947. var encodingArg = this.getToken();
  17948. var encoding;
  17949. if (!/^\d+$/.test(encodingArg)) {
  17950. // encoding name is specified
  17951. encoding = Encodings[encodingArg];
  17952. } else {
  17953. encoding = [];
  17954. var size = parseInt(encodingArg, 10) | 0;
  17955. this.getToken(); // read in 'array'
  17956. for (var j = 0; j < size; j++) {
  17957. token = this.getToken();
  17958. // skipping till first dup or def (e.g. ignoring for statement)
  17959. while (token !== 'dup' && token !== 'def') {
  17960. token = this.getToken();
  17961. if (token === null) {
  17962. return; // invalid header
  17963. }
  17964. }
  17965. if (token === 'def') {
  17966. break; // read all array data
  17967. }
  17968. var index = this.readInt();
  17969. this.getToken(); // read in '/'
  17970. var glyph = this.getToken();
  17971. encoding[index] = glyph;
  17972. this.getToken(); // read the in 'put'
  17973. }
  17974. }
  17975. properties.builtInEncoding = encoding;
  17976. break;
  17977. case 'FontBBox':
  17978. var fontBBox = this.readNumberArray();
  17979. // adjusting ascent/descent
  17980. properties.ascent = fontBBox[3];
  17981. properties.descent = fontBBox[1];
  17982. properties.ascentScaled = true;
  17983. break;
  17984. }
  17985. }
  17986. }
  17987. };
  17988. return Type1Parser;
  17989. })();
  17990. /**
  17991. * The CFF class takes a Type1 file and wrap it into a
  17992. * 'Compact Font Format' which itself embed Type2 charstrings.
  17993. */
  17994. var CFFStandardStrings = [
  17995. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17996. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17997. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17998. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17999. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18000. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18001. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18002. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18003. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18004. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18005. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18006. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18007. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18008. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18009. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18010. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18011. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18012. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18013. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18014. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18015. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18016. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18017. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18018. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18019. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18020. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18021. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18022. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18023. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18024. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18025. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18026. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18027. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18028. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18029. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18030. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18031. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18032. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18033. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18034. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18035. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18036. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18037. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18038. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18039. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18040. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18041. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18042. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18043. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18044. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18045. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18046. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18047. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18048. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18049. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18050. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18051. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18052. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18053. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18054. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18055. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18056. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18057. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18058. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18059. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18060. ];
  18061. // Type1Font is also a CIDFontType0.
  18062. var Type1Font = function Type1Font(name, file, properties) {
  18063. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18064. // Also, length1 and length2 might be off by 6 bytes as well.
  18065. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18066. var PFB_HEADER_SIZE = 6;
  18067. var headerBlockLength = properties.length1;
  18068. var eexecBlockLength = properties.length2;
  18069. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18070. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18071. if (pfbHeaderPresent) {
  18072. file.skip(PFB_HEADER_SIZE);
  18073. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18074. (pfbHeader[3] << 8) | pfbHeader[2];
  18075. }
  18076. // Get the data block containing glyphs and subrs informations
  18077. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18078. var headerBlockParser = new Type1Parser(headerBlock);
  18079. headerBlockParser.extractFontHeader(properties);
  18080. if (pfbHeaderPresent) {
  18081. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18082. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18083. (pfbHeader[3] << 8) | pfbHeader[2];
  18084. }
  18085. // Decrypt the data blocks and retrieve it's content
  18086. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18087. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18088. var data = eexecBlockParser.extractFontProgram();
  18089. for (var info in data.properties) {
  18090. properties[info] = data.properties[info];
  18091. }
  18092. var charstrings = data.charstrings;
  18093. var type2Charstrings = this.getType2Charstrings(charstrings);
  18094. var subrs = this.getType2Subrs(data.subrs);
  18095. this.charstrings = charstrings;
  18096. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18097. subrs, properties);
  18098. this.seacs = this.getSeacs(data.charstrings);
  18099. };
  18100. Type1Font.prototype = {
  18101. get numGlyphs() {
  18102. return this.charstrings.length + 1;
  18103. },
  18104. getCharset: function Type1Font_getCharset() {
  18105. var charset = ['.notdef'];
  18106. var charstrings = this.charstrings;
  18107. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18108. charset.push(charstrings[glyphId].glyphName);
  18109. }
  18110. return charset;
  18111. },
  18112. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18113. var charstrings = this.charstrings;
  18114. var glyphNames = ['.notdef'], glyphId;
  18115. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18116. glyphNames.push(charstrings[glyphId].glyphName);
  18117. }
  18118. var encoding = properties.builtInEncoding;
  18119. if (encoding) {
  18120. var builtInEncoding = {};
  18121. for (var charCode in encoding) {
  18122. glyphId = glyphNames.indexOf(encoding[charCode]);
  18123. if (glyphId >= 0) {
  18124. builtInEncoding[charCode] = glyphId;
  18125. }
  18126. }
  18127. }
  18128. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18129. },
  18130. getSeacs: function Type1Font_getSeacs(charstrings) {
  18131. var i, ii;
  18132. var seacMap = [];
  18133. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18134. var charstring = charstrings[i];
  18135. if (charstring.seac) {
  18136. // Offset by 1 for .notdef
  18137. seacMap[i + 1] = charstring.seac;
  18138. }
  18139. }
  18140. return seacMap;
  18141. },
  18142. getType2Charstrings: function Type1Font_getType2Charstrings(
  18143. type1Charstrings) {
  18144. var type2Charstrings = [];
  18145. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18146. type2Charstrings.push(type1Charstrings[i].charstring);
  18147. }
  18148. return type2Charstrings;
  18149. },
  18150. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18151. var bias = 0;
  18152. var count = type1Subrs.length;
  18153. if (count < 1133) {
  18154. bias = 107;
  18155. } else if (count < 33769) {
  18156. bias = 1131;
  18157. } else {
  18158. bias = 32768;
  18159. }
  18160. // Add a bunch of empty subrs to deal with the Type2 bias
  18161. var type2Subrs = [];
  18162. var i;
  18163. for (i = 0; i < bias; i++) {
  18164. type2Subrs.push([0x0B]);
  18165. }
  18166. for (i = 0; i < count; i++) {
  18167. type2Subrs.push(type1Subrs[i]);
  18168. }
  18169. return type2Subrs;
  18170. },
  18171. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18172. var cff = new CFF();
  18173. cff.header = new CFFHeader(1, 0, 4, 4);
  18174. cff.names = [name];
  18175. var topDict = new CFFTopDict();
  18176. // CFF strings IDs 0...390 are predefined names, so refering
  18177. // to entries in our own String INDEX starts at SID 391.
  18178. topDict.setByName('version', 391);
  18179. topDict.setByName('Notice', 392);
  18180. topDict.setByName('FullName', 393);
  18181. topDict.setByName('FamilyName', 394);
  18182. topDict.setByName('Weight', 395);
  18183. topDict.setByName('Encoding', null); // placeholder
  18184. topDict.setByName('FontMatrix', properties.fontMatrix);
  18185. topDict.setByName('FontBBox', properties.bbox);
  18186. topDict.setByName('charset', null); // placeholder
  18187. topDict.setByName('CharStrings', null); // placeholder
  18188. topDict.setByName('Private', null); // placeholder
  18189. cff.topDict = topDict;
  18190. var strings = new CFFStrings();
  18191. strings.add('Version 0.11'); // Version
  18192. strings.add('See original notice'); // Notice
  18193. strings.add(name); // FullName
  18194. strings.add(name); // FamilyName
  18195. strings.add('Medium'); // Weight
  18196. cff.strings = strings;
  18197. cff.globalSubrIndex = new CFFIndex();
  18198. var count = glyphs.length;
  18199. var charsetArray = [0];
  18200. var i, ii;
  18201. for (i = 0; i < count; i++) {
  18202. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18203. // TODO: Insert the string and correctly map it. Previously it was
  18204. // thought mapping names that aren't in the standard strings to .notdef
  18205. // was fine, however in issue818 when mapping them all to .notdef the
  18206. // adieresis glyph no longer worked.
  18207. if (index === -1) {
  18208. index = 0;
  18209. }
  18210. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18211. }
  18212. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18213. var charStringsIndex = new CFFIndex();
  18214. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18215. for (i = 0; i < count; i++) {
  18216. charStringsIndex.add(glyphs[i]);
  18217. }
  18218. cff.charStrings = charStringsIndex;
  18219. var privateDict = new CFFPrivateDict();
  18220. privateDict.setByName('Subrs', null); // placeholder
  18221. var fields = [
  18222. 'BlueValues',
  18223. 'OtherBlues',
  18224. 'FamilyBlues',
  18225. 'FamilyOtherBlues',
  18226. 'StemSnapH',
  18227. 'StemSnapV',
  18228. 'BlueShift',
  18229. 'BlueFuzz',
  18230. 'BlueScale',
  18231. 'LanguageGroup',
  18232. 'ExpansionFactor',
  18233. 'ForceBold',
  18234. 'StdHW',
  18235. 'StdVW'
  18236. ];
  18237. for (i = 0, ii = fields.length; i < ii; i++) {
  18238. var field = fields[i];
  18239. if (!properties.privateData.hasOwnProperty(field)) {
  18240. continue;
  18241. }
  18242. var value = properties.privateData[field];
  18243. if (isArray(value)) {
  18244. // All of the private dictionary array data in CFF must be stored as
  18245. // "delta-encoded" numbers.
  18246. for (var j = value.length - 1; j > 0; j--) {
  18247. value[j] -= value[j - 1]; // ... difference from previous value
  18248. }
  18249. }
  18250. privateDict.setByName(field, value);
  18251. }
  18252. cff.topDict.privateDict = privateDict;
  18253. var subrIndex = new CFFIndex();
  18254. for (i = 0, ii = subrs.length; i < ii; i++) {
  18255. subrIndex.add(subrs[i]);
  18256. }
  18257. privateDict.subrsIndex = subrIndex;
  18258. var compiler = new CFFCompiler(cff);
  18259. return compiler.compile();
  18260. }
  18261. };
  18262. var CFFFont = (function CFFFontClosure() {
  18263. function CFFFont(file, properties) {
  18264. this.properties = properties;
  18265. var parser = new CFFParser(file, properties);
  18266. this.cff = parser.parse();
  18267. var compiler = new CFFCompiler(this.cff);
  18268. this.seacs = this.cff.seacs;
  18269. try {
  18270. this.data = compiler.compile();
  18271. } catch (e) {
  18272. warn('Failed to compile font ' + properties.loadedName);
  18273. // There may have just been an issue with the compiler, set the data
  18274. // anyway and hope the font loaded.
  18275. this.data = file;
  18276. }
  18277. }
  18278. CFFFont.prototype = {
  18279. get numGlyphs() {
  18280. return this.cff.charStrings.count;
  18281. },
  18282. getCharset: function CFFFont_getCharset() {
  18283. return this.cff.charset.charset;
  18284. },
  18285. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18286. var cff = this.cff;
  18287. var properties = this.properties;
  18288. var charsets = cff.charset.charset;
  18289. var charCodeToGlyphId;
  18290. var glyphId;
  18291. if (properties.composite) {
  18292. charCodeToGlyphId = Object.create(null);
  18293. if (cff.isCIDFont) {
  18294. // If the font is actually a CID font then we should use the charset
  18295. // to map CIDs to GIDs.
  18296. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18297. var cid = charsets[glyphId];
  18298. var charCode = properties.cMap.charCodeOf(cid);
  18299. charCodeToGlyphId[charCode] = glyphId;
  18300. }
  18301. } else {
  18302. // If it is NOT actually a CID font then CIDs should be mapped
  18303. // directly to GIDs.
  18304. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18305. charCodeToGlyphId[glyphId] = glyphId;
  18306. }
  18307. }
  18308. return charCodeToGlyphId;
  18309. }
  18310. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18311. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18312. return charCodeToGlyphId;
  18313. }
  18314. };
  18315. return CFFFont;
  18316. })();
  18317. var CFFParser = (function CFFParserClosure() {
  18318. var CharstringValidationData = [
  18319. null,
  18320. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18321. null,
  18322. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18323. { id: 'vmoveto', min: 1, stackClearing: true },
  18324. { id: 'rlineto', min: 2, resetStack: true },
  18325. { id: 'hlineto', min: 1, resetStack: true },
  18326. { id: 'vlineto', min: 1, resetStack: true },
  18327. { id: 'rrcurveto', min: 6, resetStack: true },
  18328. null,
  18329. { id: 'callsubr', min: 1, undefStack: true },
  18330. { id: 'return', min: 0, undefStack: true },
  18331. null, // 12
  18332. null,
  18333. { id: 'endchar', min: 0, stackClearing: true },
  18334. null,
  18335. null,
  18336. null,
  18337. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18338. { id: 'hintmask', min: 0, stackClearing: true },
  18339. { id: 'cntrmask', min: 0, stackClearing: true },
  18340. { id: 'rmoveto', min: 2, stackClearing: true },
  18341. { id: 'hmoveto', min: 1, stackClearing: true },
  18342. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18343. { id: 'rcurveline', min: 8, resetStack: true },
  18344. { id: 'rlinecurve', min: 8, resetStack: true },
  18345. { id: 'vvcurveto', min: 4, resetStack: true },
  18346. { id: 'hhcurveto', min: 4, resetStack: true },
  18347. null, // shortint
  18348. { id: 'callgsubr', min: 1, undefStack: true },
  18349. { id: 'vhcurveto', min: 4, resetStack: true },
  18350. { id: 'hvcurveto', min: 4, resetStack: true }
  18351. ];
  18352. var CharstringValidationData12 = [
  18353. null,
  18354. null,
  18355. null,
  18356. { id: 'and', min: 2, stackDelta: -1 },
  18357. { id: 'or', min: 2, stackDelta: -1 },
  18358. { id: 'not', min: 1, stackDelta: 0 },
  18359. null,
  18360. null,
  18361. null,
  18362. { id: 'abs', min: 1, stackDelta: 0 },
  18363. { id: 'add', min: 2, stackDelta: -1,
  18364. stackFn: function stack_div(stack, index) {
  18365. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18366. }
  18367. },
  18368. { id: 'sub', min: 2, stackDelta: -1,
  18369. stackFn: function stack_div(stack, index) {
  18370. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18371. }
  18372. },
  18373. { id: 'div', min: 2, stackDelta: -1,
  18374. stackFn: function stack_div(stack, index) {
  18375. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18376. }
  18377. },
  18378. null,
  18379. { id: 'neg', min: 1, stackDelta: 0,
  18380. stackFn: function stack_div(stack, index) {
  18381. stack[index - 1] = -stack[index - 1];
  18382. }
  18383. },
  18384. { id: 'eq', min: 2, stackDelta: -1 },
  18385. null,
  18386. null,
  18387. { id: 'drop', min: 1, stackDelta: -1 },
  18388. null,
  18389. { id: 'put', min: 2, stackDelta: -2 },
  18390. { id: 'get', min: 1, stackDelta: 0 },
  18391. { id: 'ifelse', min: 4, stackDelta: -3 },
  18392. { id: 'random', min: 0, stackDelta: 1 },
  18393. { id: 'mul', min: 2, stackDelta: -1,
  18394. stackFn: function stack_div(stack, index) {
  18395. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18396. }
  18397. },
  18398. null,
  18399. { id: 'sqrt', min: 1, stackDelta: 0 },
  18400. { id: 'dup', min: 1, stackDelta: 1 },
  18401. { id: 'exch', min: 2, stackDelta: 0 },
  18402. { id: 'index', min: 2, stackDelta: 0 },
  18403. { id: 'roll', min: 3, stackDelta: -2 },
  18404. null,
  18405. null,
  18406. null,
  18407. { id: 'hflex', min: 7, resetStack: true },
  18408. { id: 'flex', min: 13, resetStack: true },
  18409. { id: 'hflex1', min: 9, resetStack: true },
  18410. { id: 'flex1', min: 11, resetStack: true }
  18411. ];
  18412. function CFFParser(file, properties) {
  18413. this.bytes = file.getBytes();
  18414. this.properties = properties;
  18415. }
  18416. CFFParser.prototype = {
  18417. parse: function CFFParser_parse() {
  18418. var properties = this.properties;
  18419. var cff = new CFF();
  18420. this.cff = cff;
  18421. // The first five sections must be in order, all the others are reached
  18422. // via offsets contained in one of the below.
  18423. var header = this.parseHeader();
  18424. var nameIndex = this.parseIndex(header.endPos);
  18425. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18426. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18427. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18428. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18429. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18430. cff.header = header.obj;
  18431. cff.names = this.parseNameIndex(nameIndex.obj);
  18432. cff.strings = this.parseStringIndex(stringIndex.obj);
  18433. cff.topDict = topDict;
  18434. cff.globalSubrIndex = globalSubrIndex.obj;
  18435. this.parsePrivateDict(cff.topDict);
  18436. cff.isCIDFont = topDict.hasName('ROS');
  18437. var charStringOffset = topDict.getByName('CharStrings');
  18438. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18439. cff.charStrings = charStringsAndSeacs.charStrings;
  18440. cff.seacs = charStringsAndSeacs.seacs;
  18441. cff.widths = charStringsAndSeacs.widths;
  18442. var fontMatrix = topDict.getByName('FontMatrix');
  18443. if (fontMatrix) {
  18444. properties.fontMatrix = fontMatrix;
  18445. }
  18446. var fontBBox = topDict.getByName('FontBBox');
  18447. if (fontBBox) {
  18448. // adjusting ascent/descent
  18449. properties.ascent = fontBBox[3];
  18450. properties.descent = fontBBox[1];
  18451. properties.ascentScaled = true;
  18452. }
  18453. var charset, encoding;
  18454. if (cff.isCIDFont) {
  18455. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18456. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18457. var dictRaw = fdArrayIndex.get(i);
  18458. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18459. cff.strings);
  18460. this.parsePrivateDict(fontDict);
  18461. cff.fdArray.push(fontDict);
  18462. }
  18463. // cid fonts don't have an encoding
  18464. encoding = null;
  18465. charset = this.parseCharsets(topDict.getByName('charset'),
  18466. cff.charStrings.count, cff.strings, true);
  18467. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18468. cff.charStrings.count);
  18469. } else {
  18470. charset = this.parseCharsets(topDict.getByName('charset'),
  18471. cff.charStrings.count, cff.strings, false);
  18472. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18473. properties,
  18474. cff.strings, charset.charset);
  18475. }
  18476. cff.charset = charset;
  18477. cff.encoding = encoding;
  18478. return cff;
  18479. },
  18480. parseHeader: function CFFParser_parseHeader() {
  18481. var bytes = this.bytes;
  18482. var bytesLength = bytes.length;
  18483. var offset = 0;
  18484. // Prevent an infinite loop, by checking that the offset is within the
  18485. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18486. while (offset < bytesLength && bytes[offset] !== 1) {
  18487. ++offset;
  18488. }
  18489. if (offset >= bytesLength) {
  18490. error('Invalid CFF header');
  18491. } else if (offset !== 0) {
  18492. info('cff data is shifted');
  18493. bytes = bytes.subarray(offset);
  18494. this.bytes = bytes;
  18495. }
  18496. var major = bytes[0];
  18497. var minor = bytes[1];
  18498. var hdrSize = bytes[2];
  18499. var offSize = bytes[3];
  18500. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18501. return { obj: header, endPos: hdrSize };
  18502. },
  18503. parseDict: function CFFParser_parseDict(dict) {
  18504. var pos = 0;
  18505. function parseOperand() {
  18506. var value = dict[pos++];
  18507. if (value === 30) {
  18508. return parseFloatOperand(pos);
  18509. } else if (value === 28) {
  18510. value = dict[pos++];
  18511. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18512. return value;
  18513. } else if (value === 29) {
  18514. value = dict[pos++];
  18515. value = (value << 8) | dict[pos++];
  18516. value = (value << 8) | dict[pos++];
  18517. value = (value << 8) | dict[pos++];
  18518. return value;
  18519. } else if (value >= 32 && value <= 246) {
  18520. return value - 139;
  18521. } else if (value >= 247 && value <= 250) {
  18522. return ((value - 247) * 256) + dict[pos++] + 108;
  18523. } else if (value >= 251 && value <= 254) {
  18524. return -((value - 251) * 256) - dict[pos++] - 108;
  18525. } else {
  18526. error('255 is not a valid DICT command');
  18527. }
  18528. return -1;
  18529. }
  18530. function parseFloatOperand() {
  18531. var str = '';
  18532. var eof = 15;
  18533. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18534. '9', '.', 'E', 'E-', null, '-'];
  18535. var length = dict.length;
  18536. while (pos < length) {
  18537. var b = dict[pos++];
  18538. var b1 = b >> 4;
  18539. var b2 = b & 15;
  18540. if (b1 === eof) {
  18541. break;
  18542. }
  18543. str += lookup[b1];
  18544. if (b2 === eof) {
  18545. break;
  18546. }
  18547. str += lookup[b2];
  18548. }
  18549. return parseFloat(str);
  18550. }
  18551. var operands = [];
  18552. var entries = [];
  18553. pos = 0;
  18554. var end = dict.length;
  18555. while (pos < end) {
  18556. var b = dict[pos];
  18557. if (b <= 21) {
  18558. if (b === 12) {
  18559. b = (b << 8) | dict[++pos];
  18560. }
  18561. entries.push([b, operands]);
  18562. operands = [];
  18563. ++pos;
  18564. } else {
  18565. operands.push(parseOperand());
  18566. }
  18567. }
  18568. return entries;
  18569. },
  18570. parseIndex: function CFFParser_parseIndex(pos) {
  18571. var cffIndex = new CFFIndex();
  18572. var bytes = this.bytes;
  18573. var count = (bytes[pos++] << 8) | bytes[pos++];
  18574. var offsets = [];
  18575. var end = pos;
  18576. var i, ii;
  18577. if (count !== 0) {
  18578. var offsetSize = bytes[pos++];
  18579. // add 1 for offset to determine size of last object
  18580. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18581. for (i = 0, ii = count + 1; i < ii; ++i) {
  18582. var offset = 0;
  18583. for (var j = 0; j < offsetSize; ++j) {
  18584. offset <<= 8;
  18585. offset += bytes[pos++];
  18586. }
  18587. offsets.push(startPos + offset);
  18588. }
  18589. end = offsets[count];
  18590. }
  18591. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18592. var offsetStart = offsets[i];
  18593. var offsetEnd = offsets[i + 1];
  18594. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18595. }
  18596. return {obj: cffIndex, endPos: end};
  18597. },
  18598. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18599. var names = [];
  18600. for (var i = 0, ii = index.count; i < ii; ++i) {
  18601. var name = index.get(i);
  18602. // OTS doesn't allow names to be over 127 characters.
  18603. var length = Math.min(name.length, 127);
  18604. var data = [];
  18605. // OTS also only permits certain characters in the name.
  18606. for (var j = 0; j < length; ++j) {
  18607. var c = name[j];
  18608. if (j === 0 && c === 0) {
  18609. data[j] = c;
  18610. continue;
  18611. }
  18612. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18613. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18614. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18615. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18616. data[j] = 95;
  18617. continue;
  18618. }
  18619. data[j] = c;
  18620. }
  18621. names.push(bytesToString(data));
  18622. }
  18623. return names;
  18624. },
  18625. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18626. var strings = new CFFStrings();
  18627. for (var i = 0, ii = index.count; i < ii; ++i) {
  18628. var data = index.get(i);
  18629. strings.add(bytesToString(data));
  18630. }
  18631. return strings;
  18632. },
  18633. createDict: function CFFParser_createDict(Type, dict, strings) {
  18634. var cffDict = new Type(strings);
  18635. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18636. var pair = dict[i];
  18637. var key = pair[0];
  18638. var value = pair[1];
  18639. cffDict.setByKey(key, value);
  18640. }
  18641. return cffDict;
  18642. },
  18643. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18644. var charStrings = this.parseIndex(charStringOffset).obj;
  18645. var seacs = [];
  18646. var widths = [];
  18647. var count = charStrings.count;
  18648. for (var i = 0; i < count; i++) {
  18649. var charstring = charStrings.get(i);
  18650. var stackSize = 0;
  18651. var stack = [];
  18652. var undefStack = true;
  18653. var hints = 0;
  18654. var valid = true;
  18655. var data = charstring;
  18656. var length = data.length;
  18657. var firstStackClearing = true;
  18658. for (var j = 0; j < length;) {
  18659. var value = data[j++];
  18660. var validationCommand = null;
  18661. if (value === 12) {
  18662. var q = data[j++];
  18663. if (q === 0) {
  18664. // The CFF specification state that the 'dotsection' command
  18665. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18666. // charstrings processors should support them. Unfortunately
  18667. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18668. // is replaced by a useless (0, hmoveto).
  18669. data[j - 2] = 139;
  18670. data[j - 1] = 22;
  18671. stackSize = 0;
  18672. } else {
  18673. validationCommand = CharstringValidationData12[q];
  18674. }
  18675. } else if (value === 28) { // number (16 bit)
  18676. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18677. j += 2;
  18678. stackSize++;
  18679. } else if (value === 14) {
  18680. if (stackSize >= 4) {
  18681. stackSize -= 4;
  18682. if (SEAC_ANALYSIS_ENABLED) {
  18683. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18684. valid = false;
  18685. }
  18686. }
  18687. validationCommand = CharstringValidationData[value];
  18688. } else if (value >= 32 && value <= 246) { // number
  18689. stack[stackSize] = value - 139;
  18690. stackSize++;
  18691. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18692. stack[stackSize] = (value < 251 ?
  18693. ((value - 247) << 8) + data[j] + 108 :
  18694. -((value - 251) << 8) - data[j] - 108);
  18695. j++;
  18696. stackSize++;
  18697. } else if (value === 255) { // number (32 bit)
  18698. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18699. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18700. j += 4;
  18701. stackSize++;
  18702. } else if (value === 19 || value === 20) {
  18703. hints += stackSize >> 1;
  18704. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18705. stackSize %= 2;
  18706. validationCommand = CharstringValidationData[value];
  18707. } else {
  18708. validationCommand = CharstringValidationData[value];
  18709. }
  18710. if (validationCommand) {
  18711. if (validationCommand.stem) {
  18712. hints += stackSize >> 1;
  18713. }
  18714. if ('min' in validationCommand) {
  18715. if (!undefStack && stackSize < validationCommand.min) {
  18716. warn('Not enough parameters for ' + validationCommand.id +
  18717. '; actual: ' + stackSize +
  18718. ', expected: ' + validationCommand.min);
  18719. valid = false;
  18720. break;
  18721. }
  18722. }
  18723. if (firstStackClearing && validationCommand.stackClearing) {
  18724. firstStackClearing = false;
  18725. // the optional character width can be found before the first
  18726. // stack-clearing command arguments
  18727. stackSize -= validationCommand.min;
  18728. if (stackSize >= 2 && validationCommand.stem) {
  18729. // there are even amount of arguments for stem commands
  18730. stackSize %= 2;
  18731. } else if (stackSize > 1) {
  18732. warn('Found too many parameters for stack-clearing command');
  18733. }
  18734. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18735. widths[i] = stack[stackSize - 1];
  18736. }
  18737. }
  18738. if ('stackDelta' in validationCommand) {
  18739. if ('stackFn' in validationCommand) {
  18740. validationCommand.stackFn(stack, stackSize);
  18741. }
  18742. stackSize += validationCommand.stackDelta;
  18743. } else if (validationCommand.stackClearing) {
  18744. stackSize = 0;
  18745. } else if (validationCommand.resetStack) {
  18746. stackSize = 0;
  18747. undefStack = false;
  18748. } else if (validationCommand.undefStack) {
  18749. stackSize = 0;
  18750. undefStack = true;
  18751. firstStackClearing = false;
  18752. }
  18753. }
  18754. }
  18755. if (!valid) {
  18756. // resetting invalid charstring to single 'endchar'
  18757. charStrings.set(i, new Uint8Array([14]));
  18758. }
  18759. }
  18760. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18761. },
  18762. emptyPrivateDictionary:
  18763. function CFFParser_emptyPrivateDictionary(parentDict) {
  18764. var privateDict = this.createDict(CFFPrivateDict, [],
  18765. parentDict.strings);
  18766. parentDict.setByKey(18, [0, 0]);
  18767. parentDict.privateDict = privateDict;
  18768. },
  18769. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18770. // no private dict, do nothing
  18771. if (!parentDict.hasName('Private')) {
  18772. this.emptyPrivateDictionary(parentDict);
  18773. return;
  18774. }
  18775. var privateOffset = parentDict.getByName('Private');
  18776. // make sure the params are formatted correctly
  18777. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18778. parentDict.removeByName('Private');
  18779. return;
  18780. }
  18781. var size = privateOffset[0];
  18782. var offset = privateOffset[1];
  18783. // remove empty dicts or ones that refer to invalid location
  18784. if (size === 0 || offset >= this.bytes.length) {
  18785. this.emptyPrivateDictionary(parentDict);
  18786. return;
  18787. }
  18788. var privateDictEnd = offset + size;
  18789. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18790. var dict = this.parseDict(dictData);
  18791. var privateDict = this.createDict(CFFPrivateDict, dict,
  18792. parentDict.strings);
  18793. parentDict.privateDict = privateDict;
  18794. // Parse the Subrs index also since it's relative to the private dict.
  18795. if (!privateDict.getByName('Subrs')) {
  18796. return;
  18797. }
  18798. var subrsOffset = privateDict.getByName('Subrs');
  18799. var relativeOffset = offset + subrsOffset;
  18800. // Validate the offset.
  18801. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18802. this.emptyPrivateDictionary(parentDict);
  18803. return;
  18804. }
  18805. var subrsIndex = this.parseIndex(relativeOffset);
  18806. privateDict.subrsIndex = subrsIndex.obj;
  18807. },
  18808. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18809. if (pos === 0) {
  18810. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18811. ISOAdobeCharset);
  18812. } else if (pos === 1) {
  18813. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18814. ExpertCharset);
  18815. } else if (pos === 2) {
  18816. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18817. ExpertSubsetCharset);
  18818. }
  18819. var bytes = this.bytes;
  18820. var start = pos;
  18821. var format = bytes[pos++];
  18822. var charset = ['.notdef'];
  18823. var id, count, i;
  18824. // subtract 1 for the .notdef glyph
  18825. length -= 1;
  18826. switch (format) {
  18827. case 0:
  18828. for (i = 0; i < length; i++) {
  18829. id = (bytes[pos++] << 8) | bytes[pos++];
  18830. charset.push(cid ? id : strings.get(id));
  18831. }
  18832. break;
  18833. case 1:
  18834. while (charset.length <= length) {
  18835. id = (bytes[pos++] << 8) | bytes[pos++];
  18836. count = bytes[pos++];
  18837. for (i = 0; i <= count; i++) {
  18838. charset.push(cid ? id++ : strings.get(id++));
  18839. }
  18840. }
  18841. break;
  18842. case 2:
  18843. while (charset.length <= length) {
  18844. id = (bytes[pos++] << 8) | bytes[pos++];
  18845. count = (bytes[pos++] << 8) | bytes[pos++];
  18846. for (i = 0; i <= count; i++) {
  18847. charset.push(cid ? id++ : strings.get(id++));
  18848. }
  18849. }
  18850. break;
  18851. default:
  18852. error('Unknown charset format');
  18853. }
  18854. // Raw won't be needed if we actually compile the charset.
  18855. var end = pos;
  18856. var raw = bytes.subarray(start, end);
  18857. return new CFFCharset(false, format, charset, raw);
  18858. },
  18859. parseEncoding: function CFFParser_parseEncoding(pos,
  18860. properties,
  18861. strings,
  18862. charset) {
  18863. var encoding = {};
  18864. var bytes = this.bytes;
  18865. var predefined = false;
  18866. var hasSupplement = false;
  18867. var format, i, ii;
  18868. var raw = null;
  18869. function readSupplement() {
  18870. var supplementsCount = bytes[pos++];
  18871. for (i = 0; i < supplementsCount; i++) {
  18872. var code = bytes[pos++];
  18873. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18874. encoding[code] = charset.indexOf(strings.get(sid));
  18875. }
  18876. }
  18877. if (pos === 0 || pos === 1) {
  18878. predefined = true;
  18879. format = pos;
  18880. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18881. Encodings.StandardEncoding;
  18882. for (i = 0, ii = charset.length; i < ii; i++) {
  18883. var index = baseEncoding.indexOf(charset[i]);
  18884. if (index !== -1) {
  18885. encoding[index] = i;
  18886. }
  18887. }
  18888. } else {
  18889. var dataStart = pos;
  18890. format = bytes[pos++];
  18891. switch (format & 0x7f) {
  18892. case 0:
  18893. var glyphsCount = bytes[pos++];
  18894. for (i = 1; i <= glyphsCount; i++) {
  18895. encoding[bytes[pos++]] = i;
  18896. }
  18897. break;
  18898. case 1:
  18899. var rangesCount = bytes[pos++];
  18900. var gid = 1;
  18901. for (i = 0; i < rangesCount; i++) {
  18902. var start = bytes[pos++];
  18903. var left = bytes[pos++];
  18904. for (var j = start; j <= start + left; j++) {
  18905. encoding[j] = gid++;
  18906. }
  18907. }
  18908. break;
  18909. default:
  18910. error('Unknow encoding format: ' + format + ' in CFF');
  18911. break;
  18912. }
  18913. var dataEnd = pos;
  18914. if (format & 0x80) {
  18915. // The font sanitizer does not support CFF encoding with a
  18916. // supplement, since the encoding is not really used to map
  18917. // between gid to glyph, let's overwrite what is declared in
  18918. // the top dictionary to let the sanitizer think the font use
  18919. // StandardEncoding, that's a lie but that's ok.
  18920. bytes[dataStart] &= 0x7f;
  18921. readSupplement();
  18922. hasSupplement = true;
  18923. }
  18924. raw = bytes.subarray(dataStart, dataEnd);
  18925. }
  18926. format = format & 0x7f;
  18927. return new CFFEncoding(predefined, format, encoding, raw);
  18928. },
  18929. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18930. var start = pos;
  18931. var bytes = this.bytes;
  18932. var format = bytes[pos++];
  18933. var fdSelect = [];
  18934. var i;
  18935. switch (format) {
  18936. case 0:
  18937. for (i = 0; i < length; ++i) {
  18938. var id = bytes[pos++];
  18939. fdSelect.push(id);
  18940. }
  18941. break;
  18942. case 3:
  18943. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18944. for (i = 0; i < rangesCount; ++i) {
  18945. var first = (bytes[pos++] << 8) | bytes[pos++];
  18946. var fdIndex = bytes[pos++];
  18947. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18948. for (var j = first; j < next; ++j) {
  18949. fdSelect.push(fdIndex);
  18950. }
  18951. }
  18952. // Advance past the sentinel(next).
  18953. pos += 2;
  18954. break;
  18955. default:
  18956. error('Unknown fdselect format ' + format);
  18957. break;
  18958. }
  18959. var end = pos;
  18960. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18961. }
  18962. };
  18963. return CFFParser;
  18964. })();
  18965. // Compact Font Format
  18966. var CFF = (function CFFClosure() {
  18967. function CFF() {
  18968. this.header = null;
  18969. this.names = [];
  18970. this.topDict = null;
  18971. this.strings = new CFFStrings();
  18972. this.globalSubrIndex = null;
  18973. // The following could really be per font, but since we only have one font
  18974. // store them here.
  18975. this.encoding = null;
  18976. this.charset = null;
  18977. this.charStrings = null;
  18978. this.fdArray = [];
  18979. this.fdSelect = null;
  18980. this.isCIDFont = false;
  18981. }
  18982. return CFF;
  18983. })();
  18984. var CFFHeader = (function CFFHeaderClosure() {
  18985. function CFFHeader(major, minor, hdrSize, offSize) {
  18986. this.major = major;
  18987. this.minor = minor;
  18988. this.hdrSize = hdrSize;
  18989. this.offSize = offSize;
  18990. }
  18991. return CFFHeader;
  18992. })();
  18993. var CFFStrings = (function CFFStringsClosure() {
  18994. function CFFStrings() {
  18995. this.strings = [];
  18996. }
  18997. CFFStrings.prototype = {
  18998. get: function CFFStrings_get(index) {
  18999. if (index >= 0 && index <= 390) {
  19000. return CFFStandardStrings[index];
  19001. }
  19002. if (index - 391 <= this.strings.length) {
  19003. return this.strings[index - 391];
  19004. }
  19005. return CFFStandardStrings[0];
  19006. },
  19007. add: function CFFStrings_add(value) {
  19008. this.strings.push(value);
  19009. },
  19010. get count() {
  19011. return this.strings.length;
  19012. }
  19013. };
  19014. return CFFStrings;
  19015. })();
  19016. var CFFIndex = (function CFFIndexClosure() {
  19017. function CFFIndex() {
  19018. this.objects = [];
  19019. this.length = 0;
  19020. }
  19021. CFFIndex.prototype = {
  19022. add: function CFFIndex_add(data) {
  19023. this.length += data.length;
  19024. this.objects.push(data);
  19025. },
  19026. set: function CFFIndex_set(index, data) {
  19027. this.length += data.length - this.objects[index].length;
  19028. this.objects[index] = data;
  19029. },
  19030. get: function CFFIndex_get(index) {
  19031. return this.objects[index];
  19032. },
  19033. get count() {
  19034. return this.objects.length;
  19035. }
  19036. };
  19037. return CFFIndex;
  19038. })();
  19039. var CFFDict = (function CFFDictClosure() {
  19040. function CFFDict(tables, strings) {
  19041. this.keyToNameMap = tables.keyToNameMap;
  19042. this.nameToKeyMap = tables.nameToKeyMap;
  19043. this.defaults = tables.defaults;
  19044. this.types = tables.types;
  19045. this.opcodes = tables.opcodes;
  19046. this.order = tables.order;
  19047. this.strings = strings;
  19048. this.values = {};
  19049. }
  19050. CFFDict.prototype = {
  19051. // value should always be an array
  19052. setByKey: function CFFDict_setByKey(key, value) {
  19053. if (!(key in this.keyToNameMap)) {
  19054. return false;
  19055. }
  19056. // ignore empty values
  19057. if (value.length === 0) {
  19058. return true;
  19059. }
  19060. var type = this.types[key];
  19061. // remove the array wrapping these types of values
  19062. if (type === 'num' || type === 'sid' || type === 'offset') {
  19063. value = value[0];
  19064. }
  19065. this.values[key] = value;
  19066. return true;
  19067. },
  19068. setByName: function CFFDict_setByName(name, value) {
  19069. if (!(name in this.nameToKeyMap)) {
  19070. error('Invalid dictionary name "' + name + '"');
  19071. }
  19072. this.values[this.nameToKeyMap[name]] = value;
  19073. },
  19074. hasName: function CFFDict_hasName(name) {
  19075. return this.nameToKeyMap[name] in this.values;
  19076. },
  19077. getByName: function CFFDict_getByName(name) {
  19078. if (!(name in this.nameToKeyMap)) {
  19079. error('Invalid dictionary name "' + name + '"');
  19080. }
  19081. var key = this.nameToKeyMap[name];
  19082. if (!(key in this.values)) {
  19083. return this.defaults[key];
  19084. }
  19085. return this.values[key];
  19086. },
  19087. removeByName: function CFFDict_removeByName(name) {
  19088. delete this.values[this.nameToKeyMap[name]];
  19089. }
  19090. };
  19091. CFFDict.createTables = function CFFDict_createTables(layout) {
  19092. var tables = {
  19093. keyToNameMap: {},
  19094. nameToKeyMap: {},
  19095. defaults: {},
  19096. types: {},
  19097. opcodes: {},
  19098. order: []
  19099. };
  19100. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19101. var entry = layout[i];
  19102. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19103. tables.keyToNameMap[key] = entry[1];
  19104. tables.nameToKeyMap[entry[1]] = key;
  19105. tables.types[key] = entry[2];
  19106. tables.defaults[key] = entry[3];
  19107. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19108. tables.order.push(key);
  19109. }
  19110. return tables;
  19111. };
  19112. return CFFDict;
  19113. })();
  19114. var CFFTopDict = (function CFFTopDictClosure() {
  19115. var layout = [
  19116. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19117. [[12, 20], 'SyntheticBase', 'num', null],
  19118. [0, 'version', 'sid', null],
  19119. [1, 'Notice', 'sid', null],
  19120. [[12, 0], 'Copyright', 'sid', null],
  19121. [2, 'FullName', 'sid', null],
  19122. [3, 'FamilyName', 'sid', null],
  19123. [4, 'Weight', 'sid', null],
  19124. [[12, 1], 'isFixedPitch', 'num', 0],
  19125. [[12, 2], 'ItalicAngle', 'num', 0],
  19126. [[12, 3], 'UnderlinePosition', 'num', -100],
  19127. [[12, 4], 'UnderlineThickness', 'num', 50],
  19128. [[12, 5], 'PaintType', 'num', 0],
  19129. [[12, 6], 'CharstringType', 'num', 2],
  19130. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19131. [0.001, 0, 0, 0.001, 0, 0]],
  19132. [13, 'UniqueID', 'num', null],
  19133. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19134. [[12, 8], 'StrokeWidth', 'num', 0],
  19135. [14, 'XUID', 'array', null],
  19136. [15, 'charset', 'offset', 0],
  19137. [16, 'Encoding', 'offset', 0],
  19138. [17, 'CharStrings', 'offset', 0],
  19139. [18, 'Private', ['offset', 'offset'], null],
  19140. [[12, 21], 'PostScript', 'sid', null],
  19141. [[12, 22], 'BaseFontName', 'sid', null],
  19142. [[12, 23], 'BaseFontBlend', 'delta', null],
  19143. [[12, 31], 'CIDFontVersion', 'num', 0],
  19144. [[12, 32], 'CIDFontRevision', 'num', 0],
  19145. [[12, 33], 'CIDFontType', 'num', 0],
  19146. [[12, 34], 'CIDCount', 'num', 8720],
  19147. [[12, 35], 'UIDBase', 'num', null],
  19148. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19149. // before FDArray.
  19150. [[12, 37], 'FDSelect', 'offset', null],
  19151. [[12, 36], 'FDArray', 'offset', null],
  19152. [[12, 38], 'FontName', 'sid', null]
  19153. ];
  19154. var tables = null;
  19155. function CFFTopDict(strings) {
  19156. if (tables === null) {
  19157. tables = CFFDict.createTables(layout);
  19158. }
  19159. CFFDict.call(this, tables, strings);
  19160. this.privateDict = null;
  19161. }
  19162. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19163. return CFFTopDict;
  19164. })();
  19165. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19166. var layout = [
  19167. [6, 'BlueValues', 'delta', null],
  19168. [7, 'OtherBlues', 'delta', null],
  19169. [8, 'FamilyBlues', 'delta', null],
  19170. [9, 'FamilyOtherBlues', 'delta', null],
  19171. [[12, 9], 'BlueScale', 'num', 0.039625],
  19172. [[12, 10], 'BlueShift', 'num', 7],
  19173. [[12, 11], 'BlueFuzz', 'num', 1],
  19174. [10, 'StdHW', 'num', null],
  19175. [11, 'StdVW', 'num', null],
  19176. [[12, 12], 'StemSnapH', 'delta', null],
  19177. [[12, 13], 'StemSnapV', 'delta', null],
  19178. [[12, 14], 'ForceBold', 'num', 0],
  19179. [[12, 17], 'LanguageGroup', 'num', 0],
  19180. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19181. [[12, 19], 'initialRandomSeed', 'num', 0],
  19182. [20, 'defaultWidthX', 'num', 0],
  19183. [21, 'nominalWidthX', 'num', 0],
  19184. [19, 'Subrs', 'offset', null]
  19185. ];
  19186. var tables = null;
  19187. function CFFPrivateDict(strings) {
  19188. if (tables === null) {
  19189. tables = CFFDict.createTables(layout);
  19190. }
  19191. CFFDict.call(this, tables, strings);
  19192. this.subrsIndex = null;
  19193. }
  19194. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19195. return CFFPrivateDict;
  19196. })();
  19197. var CFFCharsetPredefinedTypes = {
  19198. ISO_ADOBE: 0,
  19199. EXPERT: 1,
  19200. EXPERT_SUBSET: 2
  19201. };
  19202. var CFFCharset = (function CFFCharsetClosure() {
  19203. function CFFCharset(predefined, format, charset, raw) {
  19204. this.predefined = predefined;
  19205. this.format = format;
  19206. this.charset = charset;
  19207. this.raw = raw;
  19208. }
  19209. return CFFCharset;
  19210. })();
  19211. var CFFEncoding = (function CFFEncodingClosure() {
  19212. function CFFEncoding(predefined, format, encoding, raw) {
  19213. this.predefined = predefined;
  19214. this.format = format;
  19215. this.encoding = encoding;
  19216. this.raw = raw;
  19217. }
  19218. return CFFEncoding;
  19219. })();
  19220. var CFFFDSelect = (function CFFFDSelectClosure() {
  19221. function CFFFDSelect(fdSelect, raw) {
  19222. this.fdSelect = fdSelect;
  19223. this.raw = raw;
  19224. }
  19225. return CFFFDSelect;
  19226. })();
  19227. // Helper class to keep track of where an offset is within the data and helps
  19228. // filling in that offset once it's known.
  19229. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19230. function CFFOffsetTracker() {
  19231. this.offsets = {};
  19232. }
  19233. CFFOffsetTracker.prototype = {
  19234. isTracking: function CFFOffsetTracker_isTracking(key) {
  19235. return key in this.offsets;
  19236. },
  19237. track: function CFFOffsetTracker_track(key, location) {
  19238. if (key in this.offsets) {
  19239. error('Already tracking location of ' + key);
  19240. }
  19241. this.offsets[key] = location;
  19242. },
  19243. offset: function CFFOffsetTracker_offset(value) {
  19244. for (var key in this.offsets) {
  19245. this.offsets[key] += value;
  19246. }
  19247. },
  19248. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19249. values,
  19250. output) {
  19251. if (!(key in this.offsets)) {
  19252. error('Not tracking location of ' + key);
  19253. }
  19254. var data = output.data;
  19255. var dataOffset = this.offsets[key];
  19256. var size = 5;
  19257. for (var i = 0, ii = values.length; i < ii; ++i) {
  19258. var offset0 = i * size + dataOffset;
  19259. var offset1 = offset0 + 1;
  19260. var offset2 = offset0 + 2;
  19261. var offset3 = offset0 + 3;
  19262. var offset4 = offset0 + 4;
  19263. // It's easy to screw up offsets so perform this sanity check.
  19264. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19265. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19266. error('writing to an offset that is not empty');
  19267. }
  19268. var value = values[i];
  19269. data[offset0] = 0x1d;
  19270. data[offset1] = (value >> 24) & 0xFF;
  19271. data[offset2] = (value >> 16) & 0xFF;
  19272. data[offset3] = (value >> 8) & 0xFF;
  19273. data[offset4] = value & 0xFF;
  19274. }
  19275. }
  19276. };
  19277. return CFFOffsetTracker;
  19278. })();
  19279. // Takes a CFF and converts it to the binary representation.
  19280. var CFFCompiler = (function CFFCompilerClosure() {
  19281. function CFFCompiler(cff) {
  19282. this.cff = cff;
  19283. }
  19284. CFFCompiler.prototype = {
  19285. compile: function CFFCompiler_compile() {
  19286. var cff = this.cff;
  19287. var output = {
  19288. data: [],
  19289. length: 0,
  19290. add: function CFFCompiler_add(data) {
  19291. this.data = this.data.concat(data);
  19292. this.length = this.data.length;
  19293. }
  19294. };
  19295. // Compile the five entries that must be in order.
  19296. var header = this.compileHeader(cff.header);
  19297. output.add(header);
  19298. var nameIndex = this.compileNameIndex(cff.names);
  19299. output.add(nameIndex);
  19300. if (cff.isCIDFont) {
  19301. // The spec is unclear on how font matrices should relate to each other
  19302. // when there is one in the main top dict and the sub top dicts.
  19303. // Windows handles this differently than linux and osx so we have to
  19304. // normalize to work on all.
  19305. // Rules based off of some mailing list discussions:
  19306. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19307. // - If no main font matrix and there is a subfont matrix, use the
  19308. // subfont matrix.
  19309. // - If both have matrices, concat together.
  19310. // - If neither have matrices, use default.
  19311. // To make this work on all platforms we move the top matrix into each
  19312. // sub top dict and concat if necessary.
  19313. if (cff.topDict.hasName('FontMatrix')) {
  19314. var base = cff.topDict.getByName('FontMatrix');
  19315. cff.topDict.removeByName('FontMatrix');
  19316. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19317. var subDict = cff.fdArray[i];
  19318. var matrix = base.slice(0);
  19319. if (subDict.hasName('FontMatrix')) {
  19320. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19321. }
  19322. subDict.setByName('FontMatrix', matrix);
  19323. }
  19324. }
  19325. }
  19326. var compiled = this.compileTopDicts([cff.topDict],
  19327. output.length,
  19328. cff.isCIDFont);
  19329. output.add(compiled.output);
  19330. var topDictTracker = compiled.trackers[0];
  19331. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19332. output.add(stringIndex);
  19333. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19334. output.add(globalSubrIndex);
  19335. // Now start on the other entries that have no specfic order.
  19336. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19337. if (cff.encoding.predefined) {
  19338. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19339. output);
  19340. } else {
  19341. var encoding = this.compileEncoding(cff.encoding);
  19342. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19343. output.add(encoding);
  19344. }
  19345. }
  19346. if (cff.charset && cff.topDict.hasName('charset')) {
  19347. if (cff.charset.predefined) {
  19348. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19349. output);
  19350. } else {
  19351. var charset = this.compileCharset(cff.charset);
  19352. topDictTracker.setEntryLocation('charset', [output.length], output);
  19353. output.add(charset);
  19354. }
  19355. }
  19356. var charStrings = this.compileCharStrings(cff.charStrings);
  19357. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19358. output.add(charStrings);
  19359. if (cff.isCIDFont) {
  19360. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19361. // and linux don't seem to care.
  19362. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19363. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19364. output.add(fdSelect);
  19365. // It is unclear if the sub font dictionary can have CID related
  19366. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19367. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19368. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19369. output.add(compiled.output);
  19370. var fontDictTrackers = compiled.trackers;
  19371. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19372. }
  19373. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19374. // If the font data ends with INDEX whose object data is zero-length,
  19375. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19376. output.add([0]);
  19377. return output.data;
  19378. },
  19379. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19380. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19381. return this.encodeInteger(value);
  19382. } else {
  19383. return this.encodeFloat(value);
  19384. }
  19385. },
  19386. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19387. var value = num.toString();
  19388. // rounding inaccurate doubles
  19389. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19390. if (m) {
  19391. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19392. value = (Math.round(num * epsilon) / epsilon).toString();
  19393. }
  19394. var nibbles = '';
  19395. var i, ii;
  19396. for (i = 0, ii = value.length; i < ii; ++i) {
  19397. var a = value[i];
  19398. if (a === 'e') {
  19399. nibbles += value[++i] === '-' ? 'c' : 'b';
  19400. } else if (a === '.') {
  19401. nibbles += 'a';
  19402. } else if (a === '-') {
  19403. nibbles += 'e';
  19404. } else {
  19405. nibbles += a;
  19406. }
  19407. }
  19408. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19409. var out = [30];
  19410. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19411. out.push(parseInt(nibbles.substr(i, 2), 16));
  19412. }
  19413. return out;
  19414. },
  19415. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19416. var code;
  19417. if (value >= -107 && value <= 107) {
  19418. code = [value + 139];
  19419. } else if (value >= 108 && value <= 1131) {
  19420. value = [value - 108];
  19421. code = [(value >> 8) + 247, value & 0xFF];
  19422. } else if (value >= -1131 && value <= -108) {
  19423. value = -value - 108;
  19424. code = [(value >> 8) + 251, value & 0xFF];
  19425. } else if (value >= -32768 && value <= 32767) {
  19426. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19427. } else {
  19428. code = [0x1d,
  19429. (value >> 24) & 0xFF,
  19430. (value >> 16) & 0xFF,
  19431. (value >> 8) & 0xFF,
  19432. value & 0xFF];
  19433. }
  19434. return code;
  19435. },
  19436. compileHeader: function CFFCompiler_compileHeader(header) {
  19437. return [
  19438. header.major,
  19439. header.minor,
  19440. header.hdrSize,
  19441. header.offSize
  19442. ];
  19443. },
  19444. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19445. var nameIndex = new CFFIndex();
  19446. for (var i = 0, ii = names.length; i < ii; ++i) {
  19447. nameIndex.add(stringToBytes(names[i]));
  19448. }
  19449. return this.compileIndex(nameIndex);
  19450. },
  19451. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19452. length,
  19453. removeCidKeys) {
  19454. var fontDictTrackers = [];
  19455. var fdArrayIndex = new CFFIndex();
  19456. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19457. var fontDict = dicts[i];
  19458. if (removeCidKeys) {
  19459. fontDict.removeByName('CIDFontVersion');
  19460. fontDict.removeByName('CIDFontRevision');
  19461. fontDict.removeByName('CIDFontType');
  19462. fontDict.removeByName('CIDCount');
  19463. fontDict.removeByName('UIDBase');
  19464. }
  19465. var fontDictTracker = new CFFOffsetTracker();
  19466. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19467. fontDictTrackers.push(fontDictTracker);
  19468. fdArrayIndex.add(fontDictData);
  19469. fontDictTracker.offset(length);
  19470. }
  19471. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19472. return {
  19473. trackers: fontDictTrackers,
  19474. output: fdArrayIndex
  19475. };
  19476. },
  19477. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19478. trackers,
  19479. output) {
  19480. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19481. var fontDict = dicts[i];
  19482. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19483. 'There must be an private dictionary.');
  19484. var privateDict = fontDict.privateDict;
  19485. var privateDictTracker = new CFFOffsetTracker();
  19486. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19487. var outputLength = output.length;
  19488. privateDictTracker.offset(outputLength);
  19489. if (!privateDictData.length) {
  19490. // The private dictionary was empty, set the output length to zero to
  19491. // ensure the offset length isn't out of bounds in the eyes of the
  19492. // sanitizer.
  19493. outputLength = 0;
  19494. }
  19495. trackers[i].setEntryLocation('Private',
  19496. [privateDictData.length, outputLength],
  19497. output);
  19498. output.add(privateDictData);
  19499. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19500. var subrs = this.compileIndex(privateDict.subrsIndex);
  19501. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19502. output);
  19503. output.add(subrs);
  19504. }
  19505. }
  19506. },
  19507. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19508. var out = [];
  19509. // The dictionary keys must be in a certain order.
  19510. var order = dict.order;
  19511. for (var i = 0; i < order.length; ++i) {
  19512. var key = order[i];
  19513. if (!(key in dict.values)) {
  19514. continue;
  19515. }
  19516. var values = dict.values[key];
  19517. var types = dict.types[key];
  19518. if (!isArray(types)) {
  19519. types = [types];
  19520. }
  19521. if (!isArray(values)) {
  19522. values = [values];
  19523. }
  19524. // Remove any empty dict values.
  19525. if (values.length === 0) {
  19526. continue;
  19527. }
  19528. for (var j = 0, jj = types.length; j < jj; ++j) {
  19529. var type = types[j];
  19530. var value = values[j];
  19531. switch (type) {
  19532. case 'num':
  19533. case 'sid':
  19534. out = out.concat(this.encodeNumber(value));
  19535. break;
  19536. case 'offset':
  19537. // For offsets we just insert a 32bit integer so we don't have to
  19538. // deal with figuring out the length of the offset when it gets
  19539. // replaced later on by the compiler.
  19540. var name = dict.keyToNameMap[key];
  19541. // Some offsets have the offset and the length, so just record the
  19542. // position of the first one.
  19543. if (!offsetTracker.isTracking(name)) {
  19544. offsetTracker.track(name, out.length);
  19545. }
  19546. out = out.concat([0x1d, 0, 0, 0, 0]);
  19547. break;
  19548. case 'array':
  19549. case 'delta':
  19550. out = out.concat(this.encodeNumber(value));
  19551. for (var k = 1, kk = values.length; k < kk; ++k) {
  19552. out = out.concat(this.encodeNumber(values[k]));
  19553. }
  19554. break;
  19555. default:
  19556. error('Unknown data type of ' + type);
  19557. break;
  19558. }
  19559. }
  19560. out = out.concat(dict.opcodes[key]);
  19561. }
  19562. return out;
  19563. },
  19564. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19565. var stringIndex = new CFFIndex();
  19566. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19567. stringIndex.add(stringToBytes(strings[i]));
  19568. }
  19569. return this.compileIndex(stringIndex);
  19570. },
  19571. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19572. var globalSubrIndex = this.cff.globalSubrIndex;
  19573. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19574. },
  19575. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19576. return this.compileIndex(charStrings);
  19577. },
  19578. compileCharset: function CFFCompiler_compileCharset(charset) {
  19579. return this.compileTypedArray(charset.raw);
  19580. },
  19581. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19582. return this.compileTypedArray(encoding.raw);
  19583. },
  19584. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19585. return this.compileTypedArray(fdSelect);
  19586. },
  19587. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19588. var out = [];
  19589. for (var i = 0, ii = data.length; i < ii; ++i) {
  19590. out[i] = data[i];
  19591. }
  19592. return out;
  19593. },
  19594. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19595. trackers = trackers || [];
  19596. var objects = index.objects;
  19597. // First 2 bytes contains the number of objects contained into this index
  19598. var count = objects.length;
  19599. // If there is no object, just create an index. This technically
  19600. // should just be [0, 0] but OTS has an issue with that.
  19601. if (count === 0) {
  19602. return [0, 0, 0];
  19603. }
  19604. var data = [(count >> 8) & 0xFF, count & 0xff];
  19605. var lastOffset = 1, i;
  19606. for (i = 0; i < count; ++i) {
  19607. lastOffset += objects[i].length;
  19608. }
  19609. var offsetSize;
  19610. if (lastOffset < 0x100) {
  19611. offsetSize = 1;
  19612. } else if (lastOffset < 0x10000) {
  19613. offsetSize = 2;
  19614. } else if (lastOffset < 0x1000000) {
  19615. offsetSize = 3;
  19616. } else {
  19617. offsetSize = 4;
  19618. }
  19619. // Next byte contains the offset size use to reference object in the file
  19620. data.push(offsetSize);
  19621. // Add another offset after this one because we need a new offset
  19622. var relativeOffset = 1;
  19623. for (i = 0; i < count + 1; i++) {
  19624. if (offsetSize === 1) {
  19625. data.push(relativeOffset & 0xFF);
  19626. } else if (offsetSize === 2) {
  19627. data.push((relativeOffset >> 8) & 0xFF,
  19628. relativeOffset & 0xFF);
  19629. } else if (offsetSize === 3) {
  19630. data.push((relativeOffset >> 16) & 0xFF,
  19631. (relativeOffset >> 8) & 0xFF,
  19632. relativeOffset & 0xFF);
  19633. } else {
  19634. data.push((relativeOffset >>> 24) & 0xFF,
  19635. (relativeOffset >> 16) & 0xFF,
  19636. (relativeOffset >> 8) & 0xFF,
  19637. relativeOffset & 0xFF);
  19638. }
  19639. if (objects[i]) {
  19640. relativeOffset += objects[i].length;
  19641. }
  19642. }
  19643. for (i = 0; i < count; i++) {
  19644. // Notify the tracker where the object will be offset in the data.
  19645. if (trackers[i]) {
  19646. trackers[i].offset(data.length);
  19647. }
  19648. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19649. data.push(objects[i][j]);
  19650. }
  19651. }
  19652. return data;
  19653. }
  19654. };
  19655. return CFFCompiler;
  19656. })();
  19657. // Workaround for seac on Windows.
  19658. (function checkSeacSupport() {
  19659. if (/Windows/.test(navigator.userAgent)) {
  19660. SEAC_ANALYSIS_ENABLED = true;
  19661. }
  19662. })();
  19663. // Workaround for Private Use Area characters in Chrome on Windows
  19664. // http://code.google.com/p/chromium/issues/detail?id=122465
  19665. // https://github.com/mozilla/pdf.js/issues/1689
  19666. (function checkChromeWindows() {
  19667. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19668. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19669. }
  19670. })();
  19671. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19672. function getLong(data, offset) {
  19673. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19674. (data[offset + 2] << 8) | data[offset + 3];
  19675. }
  19676. function getUshort(data, offset) {
  19677. return (data[offset] << 8) | data[offset + 1];
  19678. }
  19679. function parseCmap(data, start, end) {
  19680. var offset = (getUshort(data, start + 2) === 1 ?
  19681. getLong(data, start + 8) : getLong(data, start + 16));
  19682. var format = getUshort(data, start + offset);
  19683. var length, ranges, p, i;
  19684. if (format === 4) {
  19685. length = getUshort(data, start + offset + 2);
  19686. var segCount = getUshort(data, start + offset + 6) >> 1;
  19687. p = start + offset + 14;
  19688. ranges = [];
  19689. for (i = 0; i < segCount; i++, p += 2) {
  19690. ranges[i] = {end: getUshort(data, p)};
  19691. }
  19692. p += 2;
  19693. for (i = 0; i < segCount; i++, p += 2) {
  19694. ranges[i].start = getUshort(data, p);
  19695. }
  19696. for (i = 0; i < segCount; i++, p += 2) {
  19697. ranges[i].idDelta = getUshort(data, p);
  19698. }
  19699. for (i = 0; i < segCount; i++, p += 2) {
  19700. var idOffset = getUshort(data, p);
  19701. if (idOffset === 0) {
  19702. continue;
  19703. }
  19704. ranges[i].ids = [];
  19705. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19706. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19707. idOffset += 2;
  19708. }
  19709. }
  19710. return ranges;
  19711. } else if (format === 12) {
  19712. length = getLong(data, start + offset + 4);
  19713. var groups = getLong(data, start + offset + 12);
  19714. p = start + offset + 16;
  19715. ranges = [];
  19716. for (i = 0; i < groups; i++) {
  19717. ranges.push({
  19718. start: getLong(data, p),
  19719. end: getLong(data, p + 4),
  19720. idDelta: getLong(data, p + 8) - getLong(data, p)
  19721. });
  19722. p += 12;
  19723. }
  19724. return ranges;
  19725. }
  19726. error('not supported cmap: ' + format);
  19727. }
  19728. function parseCff(data, start, end) {
  19729. var properties = {};
  19730. var parser = new CFFParser(new Stream(data, start, end - start),
  19731. properties);
  19732. var cff = parser.parse();
  19733. return {
  19734. glyphs: cff.charStrings.objects,
  19735. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19736. cff.topDict.privateDict.subrsIndex.objects),
  19737. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19738. };
  19739. }
  19740. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19741. var itemSize, itemDecode;
  19742. if (isGlyphLocationsLong) {
  19743. itemSize = 4;
  19744. itemDecode = function fontItemDecodeLong(data, offset) {
  19745. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19746. (data[offset + 2] << 8) | data[offset + 3];
  19747. };
  19748. } else {
  19749. itemSize = 2;
  19750. itemDecode = function fontItemDecode(data, offset) {
  19751. return (data[offset] << 9) | (data[offset + 1] << 1);
  19752. };
  19753. }
  19754. var glyphs = [];
  19755. var startOffset = itemDecode(loca, 0);
  19756. for (var j = itemSize; j < loca.length; j += itemSize) {
  19757. var endOffset = itemDecode(loca, j);
  19758. glyphs.push(glyf.subarray(startOffset, endOffset));
  19759. startOffset = endOffset;
  19760. }
  19761. return glyphs;
  19762. }
  19763. function lookupCmap(ranges, unicode) {
  19764. var code = unicode.charCodeAt(0);
  19765. var l = 0, r = ranges.length - 1;
  19766. while (l < r) {
  19767. var c = (l + r + 1) >> 1;
  19768. if (code < ranges[c].start) {
  19769. r = c - 1;
  19770. } else {
  19771. l = c;
  19772. }
  19773. }
  19774. if (ranges[l].start <= code && code <= ranges[l].end) {
  19775. return (ranges[l].idDelta + (ranges[l].ids ?
  19776. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19777. }
  19778. return 0;
  19779. }
  19780. function compileGlyf(code, js, font) {
  19781. function moveTo(x, y) {
  19782. js.push('c.moveTo(' + x + ',' + y + ');');
  19783. }
  19784. function lineTo(x, y) {
  19785. js.push('c.lineTo(' + x + ',' + y + ');');
  19786. }
  19787. function quadraticCurveTo(xa, ya, x, y) {
  19788. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19789. x + ',' + y + ');');
  19790. }
  19791. var i = 0;
  19792. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19793. var flags;
  19794. var x = 0, y = 0;
  19795. i += 10;
  19796. if (numberOfContours < 0) {
  19797. // composite glyph
  19798. do {
  19799. flags = (code[i] << 8) | code[i + 1];
  19800. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19801. i += 4;
  19802. var arg1, arg2;
  19803. if ((flags & 0x01)) {
  19804. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19805. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19806. i += 4;
  19807. } else {
  19808. arg1 = code[i++]; arg2 = code[i++];
  19809. }
  19810. if ((flags & 0x02)) {
  19811. x = arg1;
  19812. y = arg2;
  19813. } else {
  19814. x = 0; y = 0; // TODO "they are points" ?
  19815. }
  19816. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19817. if ((flags & 0x08)) {
  19818. scaleX =
  19819. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19820. i += 2;
  19821. } else if ((flags & 0x40)) {
  19822. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19823. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19824. i += 4;
  19825. } else if ((flags & 0x80)) {
  19826. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19827. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19828. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19829. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19830. i += 8;
  19831. }
  19832. var subglyph = font.glyphs[glyphIndex];
  19833. if (subglyph) {
  19834. js.push('c.save();');
  19835. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19836. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19837. compileGlyf(subglyph, js, font);
  19838. js.push('c.restore();');
  19839. }
  19840. } while ((flags & 0x20));
  19841. } else {
  19842. // simple glyph
  19843. var endPtsOfContours = [];
  19844. var j, jj;
  19845. for (j = 0; j < numberOfContours; j++) {
  19846. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19847. i += 2;
  19848. }
  19849. var instructionLength = (code[i] << 8) | code[i + 1];
  19850. i += 2 + instructionLength; // skipping the instructions
  19851. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19852. var points = [];
  19853. while (points.length < numberOfPoints) {
  19854. flags = code[i++];
  19855. var repeat = 1;
  19856. if ((flags & 0x08)) {
  19857. repeat += code[i++];
  19858. }
  19859. while (repeat-- > 0) {
  19860. points.push({flags: flags});
  19861. }
  19862. }
  19863. for (j = 0; j < numberOfPoints; j++) {
  19864. switch (points[j].flags & 0x12) {
  19865. case 0x00:
  19866. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19867. i += 2;
  19868. break;
  19869. case 0x02:
  19870. x -= code[i++];
  19871. break;
  19872. case 0x12:
  19873. x += code[i++];
  19874. break;
  19875. }
  19876. points[j].x = x;
  19877. }
  19878. for (j = 0; j < numberOfPoints; j++) {
  19879. switch (points[j].flags & 0x24) {
  19880. case 0x00:
  19881. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19882. i += 2;
  19883. break;
  19884. case 0x04:
  19885. y -= code[i++];
  19886. break;
  19887. case 0x24:
  19888. y += code[i++];
  19889. break;
  19890. }
  19891. points[j].y = y;
  19892. }
  19893. var startPoint = 0;
  19894. for (i = 0; i < numberOfContours; i++) {
  19895. var endPoint = endPtsOfContours[i];
  19896. // contours might have implicit points, which is located in the middle
  19897. // between two neighboring off-curve points
  19898. var contour = points.slice(startPoint, endPoint + 1);
  19899. if ((contour[0].flags & 1)) {
  19900. contour.push(contour[0]); // using start point at the contour end
  19901. } else if ((contour[contour.length - 1].flags & 1)) {
  19902. // first is off-curve point, trying to use one from the end
  19903. contour.unshift(contour[contour.length - 1]);
  19904. } else {
  19905. // start and end are off-curve points, creating implicit one
  19906. var p = {
  19907. flags: 1,
  19908. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19909. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19910. };
  19911. contour.unshift(p);
  19912. contour.push(p);
  19913. }
  19914. moveTo(contour[0].x, contour[0].y);
  19915. for (j = 1, jj = contour.length; j < jj; j++) {
  19916. if ((contour[j].flags & 1)) {
  19917. lineTo(contour[j].x, contour[j].y);
  19918. } else if ((contour[j + 1].flags & 1)){
  19919. quadraticCurveTo(contour[j].x, contour[j].y,
  19920. contour[j + 1].x, contour[j + 1].y);
  19921. j++;
  19922. } else {
  19923. quadraticCurveTo(contour[j].x, contour[j].y,
  19924. (contour[j].x + contour[j + 1].x) / 2,
  19925. (contour[j].y + contour[j + 1].y) / 2);
  19926. }
  19927. }
  19928. startPoint = endPoint + 1;
  19929. }
  19930. }
  19931. }
  19932. function compileCharString(code, js, font) {
  19933. var stack = [];
  19934. var x = 0, y = 0;
  19935. var stems = 0;
  19936. function moveTo(x, y) {
  19937. js.push('c.moveTo(' + x + ',' + y + ');');
  19938. }
  19939. function lineTo(x, y) {
  19940. js.push('c.lineTo(' + x + ',' + y + ');');
  19941. }
  19942. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19943. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19944. x + ',' + y + ');');
  19945. }
  19946. function parse(code) {
  19947. var i = 0;
  19948. while (i < code.length) {
  19949. var stackClean = false;
  19950. var v = code[i++];
  19951. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19952. switch (v) {
  19953. case 1: // hstem
  19954. stems += stack.length >> 1;
  19955. stackClean = true;
  19956. break;
  19957. case 3: // vstem
  19958. stems += stack.length >> 1;
  19959. stackClean = true;
  19960. break;
  19961. case 4: // vmoveto
  19962. y += stack.pop();
  19963. moveTo(x, y);
  19964. stackClean = true;
  19965. break;
  19966. case 5: // rlineto
  19967. while (stack.length > 0) {
  19968. x += stack.shift();
  19969. y += stack.shift();
  19970. lineTo(x, y);
  19971. }
  19972. break;
  19973. case 6: // hlineto
  19974. while (stack.length > 0) {
  19975. x += stack.shift();
  19976. lineTo(x, y);
  19977. if (stack.length === 0) {
  19978. break;
  19979. }
  19980. y += stack.shift();
  19981. lineTo(x, y);
  19982. }
  19983. break;
  19984. case 7: // vlineto
  19985. while (stack.length > 0) {
  19986. y += stack.shift();
  19987. lineTo(x, y);
  19988. if (stack.length === 0) {
  19989. break;
  19990. }
  19991. x += stack.shift();
  19992. lineTo(x, y);
  19993. }
  19994. break;
  19995. case 8: // rrcurveto
  19996. while (stack.length > 0) {
  19997. xa = x + stack.shift(); ya = y + stack.shift();
  19998. xb = xa + stack.shift(); yb = ya + stack.shift();
  19999. x = xb + stack.shift(); y = yb + stack.shift();
  20000. bezierCurveTo(xa, ya, xb, yb, x, y);
  20001. }
  20002. break;
  20003. case 10: // callsubr
  20004. n = stack.pop() + font.subrsBias;
  20005. subrCode = font.subrs[n];
  20006. if (subrCode) {
  20007. parse(subrCode);
  20008. }
  20009. break;
  20010. case 11: // return
  20011. return;
  20012. case 12:
  20013. v = code[i++];
  20014. switch (v) {
  20015. case 34: // flex
  20016. xa = x + stack.shift();
  20017. xb = xa + stack.shift(); y1 = y + stack.shift();
  20018. x = xb + stack.shift();
  20019. bezierCurveTo(xa, y, xb, y1, x, y1);
  20020. xa = x + stack.shift();
  20021. xb = xa + stack.shift();
  20022. x = xb + stack.shift();
  20023. bezierCurveTo(xa, y1, xb, y, x, y);
  20024. break;
  20025. case 35: // flex
  20026. xa = x + stack.shift(); ya = y + stack.shift();
  20027. xb = xa + stack.shift(); yb = ya + stack.shift();
  20028. x = xb + stack.shift(); y = yb + stack.shift();
  20029. bezierCurveTo(xa, ya, xb, yb, x, y);
  20030. xa = x + stack.shift(); ya = y + stack.shift();
  20031. xb = xa + stack.shift(); yb = ya + stack.shift();
  20032. x = xb + stack.shift(); y = yb + stack.shift();
  20033. bezierCurveTo(xa, ya, xb, yb, x, y);
  20034. stack.pop(); // fd
  20035. break;
  20036. case 36: // hflex1
  20037. xa = x + stack.shift(); y1 = y + stack.shift();
  20038. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20039. x = xb + stack.shift();
  20040. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20041. xa = x + stack.shift();
  20042. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20043. x = xb + stack.shift();
  20044. bezierCurveTo(xa, y2, xb, y3, x, y);
  20045. break;
  20046. case 37: // flex1
  20047. var x0 = x, y0 = y;
  20048. xa = x + stack.shift(); ya = y + stack.shift();
  20049. xb = xa + stack.shift(); yb = ya + stack.shift();
  20050. x = xb + stack.shift(); y = yb + stack.shift();
  20051. bezierCurveTo(xa, ya, xb, yb, x, y);
  20052. xa = x + stack.shift(); ya = y + stack.shift();
  20053. xb = xa + stack.shift(); yb = ya + stack.shift();
  20054. x = xb; y = yb;
  20055. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20056. x += stack.shift();
  20057. } else {
  20058. y += stack.shift();
  20059. }
  20060. bezierCurveTo(xa, ya, xb, yb, x, y);
  20061. break;
  20062. default:
  20063. error('unknown operator: 12 ' + v);
  20064. }
  20065. break;
  20066. case 14: // endchar
  20067. if (stack.length >= 4) {
  20068. var achar = stack.pop();
  20069. var bchar = stack.pop();
  20070. y = stack.pop();
  20071. x = stack.pop();
  20072. js.push('c.save();');
  20073. js.push('c.translate('+ x + ',' + y + ');');
  20074. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20075. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20076. compileCharString(font.glyphs[gid], js, font);
  20077. js.push('c.restore();');
  20078. gid = lookupCmap(font.cmap, String.fromCharCode(
  20079. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20080. compileCharString(font.glyphs[gid], js, font);
  20081. }
  20082. return;
  20083. case 18: // hstemhm
  20084. stems += stack.length >> 1;
  20085. stackClean = true;
  20086. break;
  20087. case 19: // hintmask
  20088. stems += stack.length >> 1;
  20089. i += (stems + 7) >> 3;
  20090. stackClean = true;
  20091. break;
  20092. case 20: // cntrmask
  20093. stems += stack.length >> 1;
  20094. i += (stems + 7) >> 3;
  20095. stackClean = true;
  20096. break;
  20097. case 21: // rmoveto
  20098. y += stack.pop();
  20099. x += stack.pop();
  20100. moveTo(x, y);
  20101. stackClean = true;
  20102. break;
  20103. case 22: // hmoveto
  20104. x += stack.pop();
  20105. moveTo(x, y);
  20106. stackClean = true;
  20107. break;
  20108. case 23: // vstemhm
  20109. stems += stack.length >> 1;
  20110. stackClean = true;
  20111. break;
  20112. case 24: // rcurveline
  20113. while (stack.length > 2) {
  20114. xa = x + stack.shift(); ya = y + stack.shift();
  20115. xb = xa + stack.shift(); yb = ya + stack.shift();
  20116. x = xb + stack.shift(); y = yb + stack.shift();
  20117. bezierCurveTo(xa, ya, xb, yb, x, y);
  20118. }
  20119. x += stack.shift();
  20120. y += stack.shift();
  20121. lineTo(x, y);
  20122. break;
  20123. case 25: // rlinecurve
  20124. while (stack.length > 6) {
  20125. x += stack.shift();
  20126. y += stack.shift();
  20127. lineTo(x, y);
  20128. }
  20129. xa = x + stack.shift(); ya = y + stack.shift();
  20130. xb = xa + stack.shift(); yb = ya + stack.shift();
  20131. x = xb + stack.shift(); y = yb + stack.shift();
  20132. bezierCurveTo(xa, ya, xb, yb, x, y);
  20133. break;
  20134. case 26: // vvcurveto
  20135. if (stack.length % 2) {
  20136. x += stack.shift();
  20137. }
  20138. while (stack.length > 0) {
  20139. xa = x; ya = y + stack.shift();
  20140. xb = xa + stack.shift(); yb = ya + stack.shift();
  20141. x = xb; y = yb + stack.shift();
  20142. bezierCurveTo(xa, ya, xb, yb, x, y);
  20143. }
  20144. break;
  20145. case 27: // hhcurveto
  20146. if (stack.length % 2) {
  20147. y += stack.shift();
  20148. }
  20149. while (stack.length > 0) {
  20150. xa = x + stack.shift(); ya = y;
  20151. xb = xa + stack.shift(); yb = ya + stack.shift();
  20152. x = xb + stack.shift(); y = yb;
  20153. bezierCurveTo(xa, ya, xb, yb, x, y);
  20154. }
  20155. break;
  20156. case 28:
  20157. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20158. i += 2;
  20159. break;
  20160. case 29: // callgsubr
  20161. n = stack.pop() + font.gsubrsBias;
  20162. subrCode = font.gsubrs[n];
  20163. if (subrCode) {
  20164. parse(subrCode);
  20165. }
  20166. break;
  20167. case 30: // vhcurveto
  20168. while (stack.length > 0) {
  20169. xa = x; ya = y + stack.shift();
  20170. xb = xa + stack.shift(); yb = ya + stack.shift();
  20171. x = xb + stack.shift();
  20172. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20173. bezierCurveTo(xa, ya, xb, yb, x, y);
  20174. if (stack.length === 0) {
  20175. break;
  20176. }
  20177. xa = x + stack.shift(); ya = y;
  20178. xb = xa + stack.shift(); yb = ya + stack.shift();
  20179. y = yb + stack.shift();
  20180. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20181. bezierCurveTo(xa, ya, xb, yb, x, y);
  20182. }
  20183. break;
  20184. case 31: // hvcurveto
  20185. while (stack.length > 0) {
  20186. xa = x + stack.shift(); ya = y;
  20187. xb = xa + stack.shift(); yb = ya + stack.shift();
  20188. y = yb + stack.shift();
  20189. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20190. bezierCurveTo(xa, ya, xb, yb, x, y);
  20191. if (stack.length === 0) {
  20192. break;
  20193. }
  20194. xa = x; ya = y + stack.shift();
  20195. xb = xa + stack.shift(); yb = ya + stack.shift();
  20196. x = xb + stack.shift();
  20197. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20198. bezierCurveTo(xa, ya, xb, yb, x, y);
  20199. }
  20200. break;
  20201. default:
  20202. if (v < 32) {
  20203. error('unknown operator: ' + v);
  20204. }
  20205. if (v < 247) {
  20206. stack.push(v - 139);
  20207. } else if (v < 251) {
  20208. stack.push((v - 247) * 256 + code[i++] + 108);
  20209. } else if (v < 255) {
  20210. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20211. } else {
  20212. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20213. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20214. i += 4;
  20215. }
  20216. break;
  20217. }
  20218. if (stackClean) {
  20219. stack.length = 0;
  20220. }
  20221. }
  20222. }
  20223. parse(code);
  20224. }
  20225. var noop = '';
  20226. function CompiledFont(fontMatrix) {
  20227. this.compiledGlyphs = {};
  20228. this.fontMatrix = fontMatrix;
  20229. }
  20230. CompiledFont.prototype = {
  20231. getPathJs: function (unicode) {
  20232. var gid = lookupCmap(this.cmap, unicode);
  20233. var fn = this.compiledGlyphs[gid];
  20234. if (!fn) {
  20235. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20236. }
  20237. return fn;
  20238. },
  20239. compileGlyph: function (code) {
  20240. if (!code || code.length === 0 || code[0] === 14) {
  20241. return noop;
  20242. }
  20243. var js = [];
  20244. js.push('c.save();');
  20245. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20246. js.push('c.scale(size, -size);');
  20247. this.compileGlyphImpl(code, js);
  20248. js.push('c.restore();');
  20249. return js.join('\n');
  20250. },
  20251. compileGlyphImpl: function () {
  20252. error('Children classes should implement this.');
  20253. },
  20254. hasBuiltPath: function (unicode) {
  20255. var gid = lookupCmap(this.cmap, unicode);
  20256. return gid in this.compiledGlyphs;
  20257. }
  20258. };
  20259. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20260. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20261. CompiledFont.call(this, fontMatrix);
  20262. this.glyphs = glyphs;
  20263. this.cmap = cmap;
  20264. this.compiledGlyphs = [];
  20265. }
  20266. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20267. compileGlyphImpl: function (code, js) {
  20268. compileGlyf(code, js, this);
  20269. }
  20270. });
  20271. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20272. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20273. CompiledFont.call(this, fontMatrix);
  20274. this.glyphs = cffInfo.glyphs;
  20275. this.gsubrs = cffInfo.gsubrs || [];
  20276. this.subrs = cffInfo.subrs || [];
  20277. this.cmap = cmap;
  20278. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20279. this.compiledGlyphs = [];
  20280. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20281. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20282. this.subrsBias = (this.subrs.length < 1240 ?
  20283. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20284. }
  20285. Util.inherit(Type2Compiled, CompiledFont, {
  20286. compileGlyphImpl: function (code, js) {
  20287. compileCharString(code, js, this);
  20288. }
  20289. });
  20290. return {
  20291. create: function FontRendererFactory_create(font) {
  20292. var data = new Uint8Array(font.data);
  20293. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20294. var numTables = getUshort(data, 4);
  20295. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20296. var tag = bytesToString(data.subarray(p, p + 4));
  20297. var offset = getLong(data, p + 8);
  20298. var length = getLong(data, p + 12);
  20299. switch (tag) {
  20300. case 'cmap':
  20301. cmap = parseCmap(data, offset, offset + length);
  20302. break;
  20303. case 'glyf':
  20304. glyf = data.subarray(offset, offset + length);
  20305. break;
  20306. case 'loca':
  20307. loca = data.subarray(offset, offset + length);
  20308. break;
  20309. case 'head':
  20310. unitsPerEm = getUshort(data, offset + 18);
  20311. indexToLocFormat = getUshort(data, offset + 50);
  20312. break;
  20313. case 'CFF ':
  20314. cff = parseCff(data, offset, offset + length);
  20315. break;
  20316. }
  20317. }
  20318. if (glyf) {
  20319. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20320. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20321. return new TrueTypeCompiled(
  20322. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20323. } else {
  20324. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20325. }
  20326. }
  20327. };
  20328. })();
  20329. var GlyphsUnicode = {
  20330. A: 0x0041,
  20331. AE: 0x00C6,
  20332. AEacute: 0x01FC,
  20333. AEmacron: 0x01E2,
  20334. AEsmall: 0xF7E6,
  20335. Aacute: 0x00C1,
  20336. Aacutesmall: 0xF7E1,
  20337. Abreve: 0x0102,
  20338. Abreveacute: 0x1EAE,
  20339. Abrevecyrillic: 0x04D0,
  20340. Abrevedotbelow: 0x1EB6,
  20341. Abrevegrave: 0x1EB0,
  20342. Abrevehookabove: 0x1EB2,
  20343. Abrevetilde: 0x1EB4,
  20344. Acaron: 0x01CD,
  20345. Acircle: 0x24B6,
  20346. Acircumflex: 0x00C2,
  20347. Acircumflexacute: 0x1EA4,
  20348. Acircumflexdotbelow: 0x1EAC,
  20349. Acircumflexgrave: 0x1EA6,
  20350. Acircumflexhookabove: 0x1EA8,
  20351. Acircumflexsmall: 0xF7E2,
  20352. Acircumflextilde: 0x1EAA,
  20353. Acute: 0xF6C9,
  20354. Acutesmall: 0xF7B4,
  20355. Acyrillic: 0x0410,
  20356. Adblgrave: 0x0200,
  20357. Adieresis: 0x00C4,
  20358. Adieresiscyrillic: 0x04D2,
  20359. Adieresismacron: 0x01DE,
  20360. Adieresissmall: 0xF7E4,
  20361. Adotbelow: 0x1EA0,
  20362. Adotmacron: 0x01E0,
  20363. Agrave: 0x00C0,
  20364. Agravesmall: 0xF7E0,
  20365. Ahookabove: 0x1EA2,
  20366. Aiecyrillic: 0x04D4,
  20367. Ainvertedbreve: 0x0202,
  20368. Alpha: 0x0391,
  20369. Alphatonos: 0x0386,
  20370. Amacron: 0x0100,
  20371. Amonospace: 0xFF21,
  20372. Aogonek: 0x0104,
  20373. Aring: 0x00C5,
  20374. Aringacute: 0x01FA,
  20375. Aringbelow: 0x1E00,
  20376. Aringsmall: 0xF7E5,
  20377. Asmall: 0xF761,
  20378. Atilde: 0x00C3,
  20379. Atildesmall: 0xF7E3,
  20380. Aybarmenian: 0x0531,
  20381. B: 0x0042,
  20382. Bcircle: 0x24B7,
  20383. Bdotaccent: 0x1E02,
  20384. Bdotbelow: 0x1E04,
  20385. Becyrillic: 0x0411,
  20386. Benarmenian: 0x0532,
  20387. Beta: 0x0392,
  20388. Bhook: 0x0181,
  20389. Blinebelow: 0x1E06,
  20390. Bmonospace: 0xFF22,
  20391. Brevesmall: 0xF6F4,
  20392. Bsmall: 0xF762,
  20393. Btopbar: 0x0182,
  20394. C: 0x0043,
  20395. Caarmenian: 0x053E,
  20396. Cacute: 0x0106,
  20397. Caron: 0xF6CA,
  20398. Caronsmall: 0xF6F5,
  20399. Ccaron: 0x010C,
  20400. Ccedilla: 0x00C7,
  20401. Ccedillaacute: 0x1E08,
  20402. Ccedillasmall: 0xF7E7,
  20403. Ccircle: 0x24B8,
  20404. Ccircumflex: 0x0108,
  20405. Cdot: 0x010A,
  20406. Cdotaccent: 0x010A,
  20407. Cedillasmall: 0xF7B8,
  20408. Chaarmenian: 0x0549,
  20409. Cheabkhasiancyrillic: 0x04BC,
  20410. Checyrillic: 0x0427,
  20411. Chedescenderabkhasiancyrillic: 0x04BE,
  20412. Chedescendercyrillic: 0x04B6,
  20413. Chedieresiscyrillic: 0x04F4,
  20414. Cheharmenian: 0x0543,
  20415. Chekhakassiancyrillic: 0x04CB,
  20416. Cheverticalstrokecyrillic: 0x04B8,
  20417. Chi: 0x03A7,
  20418. Chook: 0x0187,
  20419. Circumflexsmall: 0xF6F6,
  20420. Cmonospace: 0xFF23,
  20421. Coarmenian: 0x0551,
  20422. Csmall: 0xF763,
  20423. D: 0x0044,
  20424. DZ: 0x01F1,
  20425. DZcaron: 0x01C4,
  20426. Daarmenian: 0x0534,
  20427. Dafrican: 0x0189,
  20428. Dcaron: 0x010E,
  20429. Dcedilla: 0x1E10,
  20430. Dcircle: 0x24B9,
  20431. Dcircumflexbelow: 0x1E12,
  20432. Dcroat: 0x0110,
  20433. Ddotaccent: 0x1E0A,
  20434. Ddotbelow: 0x1E0C,
  20435. Decyrillic: 0x0414,
  20436. Deicoptic: 0x03EE,
  20437. Delta: 0x2206,
  20438. Deltagreek: 0x0394,
  20439. Dhook: 0x018A,
  20440. Dieresis: 0xF6CB,
  20441. DieresisAcute: 0xF6CC,
  20442. DieresisGrave: 0xF6CD,
  20443. Dieresissmall: 0xF7A8,
  20444. Digammagreek: 0x03DC,
  20445. Djecyrillic: 0x0402,
  20446. Dlinebelow: 0x1E0E,
  20447. Dmonospace: 0xFF24,
  20448. Dotaccentsmall: 0xF6F7,
  20449. Dslash: 0x0110,
  20450. Dsmall: 0xF764,
  20451. Dtopbar: 0x018B,
  20452. Dz: 0x01F2,
  20453. Dzcaron: 0x01C5,
  20454. Dzeabkhasiancyrillic: 0x04E0,
  20455. Dzecyrillic: 0x0405,
  20456. Dzhecyrillic: 0x040F,
  20457. E: 0x0045,
  20458. Eacute: 0x00C9,
  20459. Eacutesmall: 0xF7E9,
  20460. Ebreve: 0x0114,
  20461. Ecaron: 0x011A,
  20462. Ecedillabreve: 0x1E1C,
  20463. Echarmenian: 0x0535,
  20464. Ecircle: 0x24BA,
  20465. Ecircumflex: 0x00CA,
  20466. Ecircumflexacute: 0x1EBE,
  20467. Ecircumflexbelow: 0x1E18,
  20468. Ecircumflexdotbelow: 0x1EC6,
  20469. Ecircumflexgrave: 0x1EC0,
  20470. Ecircumflexhookabove: 0x1EC2,
  20471. Ecircumflexsmall: 0xF7EA,
  20472. Ecircumflextilde: 0x1EC4,
  20473. Ecyrillic: 0x0404,
  20474. Edblgrave: 0x0204,
  20475. Edieresis: 0x00CB,
  20476. Edieresissmall: 0xF7EB,
  20477. Edot: 0x0116,
  20478. Edotaccent: 0x0116,
  20479. Edotbelow: 0x1EB8,
  20480. Efcyrillic: 0x0424,
  20481. Egrave: 0x00C8,
  20482. Egravesmall: 0xF7E8,
  20483. Eharmenian: 0x0537,
  20484. Ehookabove: 0x1EBA,
  20485. Eightroman: 0x2167,
  20486. Einvertedbreve: 0x0206,
  20487. Eiotifiedcyrillic: 0x0464,
  20488. Elcyrillic: 0x041B,
  20489. Elevenroman: 0x216A,
  20490. Emacron: 0x0112,
  20491. Emacronacute: 0x1E16,
  20492. Emacrongrave: 0x1E14,
  20493. Emcyrillic: 0x041C,
  20494. Emonospace: 0xFF25,
  20495. Encyrillic: 0x041D,
  20496. Endescendercyrillic: 0x04A2,
  20497. Eng: 0x014A,
  20498. Enghecyrillic: 0x04A4,
  20499. Enhookcyrillic: 0x04C7,
  20500. Eogonek: 0x0118,
  20501. Eopen: 0x0190,
  20502. Epsilon: 0x0395,
  20503. Epsilontonos: 0x0388,
  20504. Ercyrillic: 0x0420,
  20505. Ereversed: 0x018E,
  20506. Ereversedcyrillic: 0x042D,
  20507. Escyrillic: 0x0421,
  20508. Esdescendercyrillic: 0x04AA,
  20509. Esh: 0x01A9,
  20510. Esmall: 0xF765,
  20511. Eta: 0x0397,
  20512. Etarmenian: 0x0538,
  20513. Etatonos: 0x0389,
  20514. Eth: 0x00D0,
  20515. Ethsmall: 0xF7F0,
  20516. Etilde: 0x1EBC,
  20517. Etildebelow: 0x1E1A,
  20518. Euro: 0x20AC,
  20519. Ezh: 0x01B7,
  20520. Ezhcaron: 0x01EE,
  20521. Ezhreversed: 0x01B8,
  20522. F: 0x0046,
  20523. Fcircle: 0x24BB,
  20524. Fdotaccent: 0x1E1E,
  20525. Feharmenian: 0x0556,
  20526. Feicoptic: 0x03E4,
  20527. Fhook: 0x0191,
  20528. Fitacyrillic: 0x0472,
  20529. Fiveroman: 0x2164,
  20530. Fmonospace: 0xFF26,
  20531. Fourroman: 0x2163,
  20532. Fsmall: 0xF766,
  20533. G: 0x0047,
  20534. GBsquare: 0x3387,
  20535. Gacute: 0x01F4,
  20536. Gamma: 0x0393,
  20537. Gammaafrican: 0x0194,
  20538. Gangiacoptic: 0x03EA,
  20539. Gbreve: 0x011E,
  20540. Gcaron: 0x01E6,
  20541. Gcedilla: 0x0122,
  20542. Gcircle: 0x24BC,
  20543. Gcircumflex: 0x011C,
  20544. Gcommaaccent: 0x0122,
  20545. Gdot: 0x0120,
  20546. Gdotaccent: 0x0120,
  20547. Gecyrillic: 0x0413,
  20548. Ghadarmenian: 0x0542,
  20549. Ghemiddlehookcyrillic: 0x0494,
  20550. Ghestrokecyrillic: 0x0492,
  20551. Gheupturncyrillic: 0x0490,
  20552. Ghook: 0x0193,
  20553. Gimarmenian: 0x0533,
  20554. Gjecyrillic: 0x0403,
  20555. Gmacron: 0x1E20,
  20556. Gmonospace: 0xFF27,
  20557. Grave: 0xF6CE,
  20558. Gravesmall: 0xF760,
  20559. Gsmall: 0xF767,
  20560. Gsmallhook: 0x029B,
  20561. Gstroke: 0x01E4,
  20562. H: 0x0048,
  20563. H18533: 0x25CF,
  20564. H18543: 0x25AA,
  20565. H18551: 0x25AB,
  20566. H22073: 0x25A1,
  20567. HPsquare: 0x33CB,
  20568. Haabkhasiancyrillic: 0x04A8,
  20569. Hadescendercyrillic: 0x04B2,
  20570. Hardsigncyrillic: 0x042A,
  20571. Hbar: 0x0126,
  20572. Hbrevebelow: 0x1E2A,
  20573. Hcedilla: 0x1E28,
  20574. Hcircle: 0x24BD,
  20575. Hcircumflex: 0x0124,
  20576. Hdieresis: 0x1E26,
  20577. Hdotaccent: 0x1E22,
  20578. Hdotbelow: 0x1E24,
  20579. Hmonospace: 0xFF28,
  20580. Hoarmenian: 0x0540,
  20581. Horicoptic: 0x03E8,
  20582. Hsmall: 0xF768,
  20583. Hungarumlaut: 0xF6CF,
  20584. Hungarumlautsmall: 0xF6F8,
  20585. Hzsquare: 0x3390,
  20586. I: 0x0049,
  20587. IAcyrillic: 0x042F,
  20588. IJ: 0x0132,
  20589. IUcyrillic: 0x042E,
  20590. Iacute: 0x00CD,
  20591. Iacutesmall: 0xF7ED,
  20592. Ibreve: 0x012C,
  20593. Icaron: 0x01CF,
  20594. Icircle: 0x24BE,
  20595. Icircumflex: 0x00CE,
  20596. Icircumflexsmall: 0xF7EE,
  20597. Icyrillic: 0x0406,
  20598. Idblgrave: 0x0208,
  20599. Idieresis: 0x00CF,
  20600. Idieresisacute: 0x1E2E,
  20601. Idieresiscyrillic: 0x04E4,
  20602. Idieresissmall: 0xF7EF,
  20603. Idot: 0x0130,
  20604. Idotaccent: 0x0130,
  20605. Idotbelow: 0x1ECA,
  20606. Iebrevecyrillic: 0x04D6,
  20607. Iecyrillic: 0x0415,
  20608. Ifraktur: 0x2111,
  20609. Igrave: 0x00CC,
  20610. Igravesmall: 0xF7EC,
  20611. Ihookabove: 0x1EC8,
  20612. Iicyrillic: 0x0418,
  20613. Iinvertedbreve: 0x020A,
  20614. Iishortcyrillic: 0x0419,
  20615. Imacron: 0x012A,
  20616. Imacroncyrillic: 0x04E2,
  20617. Imonospace: 0xFF29,
  20618. Iniarmenian: 0x053B,
  20619. Iocyrillic: 0x0401,
  20620. Iogonek: 0x012E,
  20621. Iota: 0x0399,
  20622. Iotaafrican: 0x0196,
  20623. Iotadieresis: 0x03AA,
  20624. Iotatonos: 0x038A,
  20625. Ismall: 0xF769,
  20626. Istroke: 0x0197,
  20627. Itilde: 0x0128,
  20628. Itildebelow: 0x1E2C,
  20629. Izhitsacyrillic: 0x0474,
  20630. Izhitsadblgravecyrillic: 0x0476,
  20631. J: 0x004A,
  20632. Jaarmenian: 0x0541,
  20633. Jcircle: 0x24BF,
  20634. Jcircumflex: 0x0134,
  20635. Jecyrillic: 0x0408,
  20636. Jheharmenian: 0x054B,
  20637. Jmonospace: 0xFF2A,
  20638. Jsmall: 0xF76A,
  20639. K: 0x004B,
  20640. KBsquare: 0x3385,
  20641. KKsquare: 0x33CD,
  20642. Kabashkircyrillic: 0x04A0,
  20643. Kacute: 0x1E30,
  20644. Kacyrillic: 0x041A,
  20645. Kadescendercyrillic: 0x049A,
  20646. Kahookcyrillic: 0x04C3,
  20647. Kappa: 0x039A,
  20648. Kastrokecyrillic: 0x049E,
  20649. Kaverticalstrokecyrillic: 0x049C,
  20650. Kcaron: 0x01E8,
  20651. Kcedilla: 0x0136,
  20652. Kcircle: 0x24C0,
  20653. Kcommaaccent: 0x0136,
  20654. Kdotbelow: 0x1E32,
  20655. Keharmenian: 0x0554,
  20656. Kenarmenian: 0x053F,
  20657. Khacyrillic: 0x0425,
  20658. Kheicoptic: 0x03E6,
  20659. Khook: 0x0198,
  20660. Kjecyrillic: 0x040C,
  20661. Klinebelow: 0x1E34,
  20662. Kmonospace: 0xFF2B,
  20663. Koppacyrillic: 0x0480,
  20664. Koppagreek: 0x03DE,
  20665. Ksicyrillic: 0x046E,
  20666. Ksmall: 0xF76B,
  20667. L: 0x004C,
  20668. LJ: 0x01C7,
  20669. LL: 0xF6BF,
  20670. Lacute: 0x0139,
  20671. Lambda: 0x039B,
  20672. Lcaron: 0x013D,
  20673. Lcedilla: 0x013B,
  20674. Lcircle: 0x24C1,
  20675. Lcircumflexbelow: 0x1E3C,
  20676. Lcommaaccent: 0x013B,
  20677. Ldot: 0x013F,
  20678. Ldotaccent: 0x013F,
  20679. Ldotbelow: 0x1E36,
  20680. Ldotbelowmacron: 0x1E38,
  20681. Liwnarmenian: 0x053C,
  20682. Lj: 0x01C8,
  20683. Ljecyrillic: 0x0409,
  20684. Llinebelow: 0x1E3A,
  20685. Lmonospace: 0xFF2C,
  20686. Lslash: 0x0141,
  20687. Lslashsmall: 0xF6F9,
  20688. Lsmall: 0xF76C,
  20689. M: 0x004D,
  20690. MBsquare: 0x3386,
  20691. Macron: 0xF6D0,
  20692. Macronsmall: 0xF7AF,
  20693. Macute: 0x1E3E,
  20694. Mcircle: 0x24C2,
  20695. Mdotaccent: 0x1E40,
  20696. Mdotbelow: 0x1E42,
  20697. Menarmenian: 0x0544,
  20698. Mmonospace: 0xFF2D,
  20699. Msmall: 0xF76D,
  20700. Mturned: 0x019C,
  20701. Mu: 0x039C,
  20702. N: 0x004E,
  20703. NJ: 0x01CA,
  20704. Nacute: 0x0143,
  20705. Ncaron: 0x0147,
  20706. Ncedilla: 0x0145,
  20707. Ncircle: 0x24C3,
  20708. Ncircumflexbelow: 0x1E4A,
  20709. Ncommaaccent: 0x0145,
  20710. Ndotaccent: 0x1E44,
  20711. Ndotbelow: 0x1E46,
  20712. Nhookleft: 0x019D,
  20713. Nineroman: 0x2168,
  20714. Nj: 0x01CB,
  20715. Njecyrillic: 0x040A,
  20716. Nlinebelow: 0x1E48,
  20717. Nmonospace: 0xFF2E,
  20718. Nowarmenian: 0x0546,
  20719. Nsmall: 0xF76E,
  20720. Ntilde: 0x00D1,
  20721. Ntildesmall: 0xF7F1,
  20722. Nu: 0x039D,
  20723. O: 0x004F,
  20724. OE: 0x0152,
  20725. OEsmall: 0xF6FA,
  20726. Oacute: 0x00D3,
  20727. Oacutesmall: 0xF7F3,
  20728. Obarredcyrillic: 0x04E8,
  20729. Obarreddieresiscyrillic: 0x04EA,
  20730. Obreve: 0x014E,
  20731. Ocaron: 0x01D1,
  20732. Ocenteredtilde: 0x019F,
  20733. Ocircle: 0x24C4,
  20734. Ocircumflex: 0x00D4,
  20735. Ocircumflexacute: 0x1ED0,
  20736. Ocircumflexdotbelow: 0x1ED8,
  20737. Ocircumflexgrave: 0x1ED2,
  20738. Ocircumflexhookabove: 0x1ED4,
  20739. Ocircumflexsmall: 0xF7F4,
  20740. Ocircumflextilde: 0x1ED6,
  20741. Ocyrillic: 0x041E,
  20742. Odblacute: 0x0150,
  20743. Odblgrave: 0x020C,
  20744. Odieresis: 0x00D6,
  20745. Odieresiscyrillic: 0x04E6,
  20746. Odieresissmall: 0xF7F6,
  20747. Odotbelow: 0x1ECC,
  20748. Ogoneksmall: 0xF6FB,
  20749. Ograve: 0x00D2,
  20750. Ogravesmall: 0xF7F2,
  20751. Oharmenian: 0x0555,
  20752. Ohm: 0x2126,
  20753. Ohookabove: 0x1ECE,
  20754. Ohorn: 0x01A0,
  20755. Ohornacute: 0x1EDA,
  20756. Ohorndotbelow: 0x1EE2,
  20757. Ohorngrave: 0x1EDC,
  20758. Ohornhookabove: 0x1EDE,
  20759. Ohorntilde: 0x1EE0,
  20760. Ohungarumlaut: 0x0150,
  20761. Oi: 0x01A2,
  20762. Oinvertedbreve: 0x020E,
  20763. Omacron: 0x014C,
  20764. Omacronacute: 0x1E52,
  20765. Omacrongrave: 0x1E50,
  20766. Omega: 0x2126,
  20767. Omegacyrillic: 0x0460,
  20768. Omegagreek: 0x03A9,
  20769. Omegaroundcyrillic: 0x047A,
  20770. Omegatitlocyrillic: 0x047C,
  20771. Omegatonos: 0x038F,
  20772. Omicron: 0x039F,
  20773. Omicrontonos: 0x038C,
  20774. Omonospace: 0xFF2F,
  20775. Oneroman: 0x2160,
  20776. Oogonek: 0x01EA,
  20777. Oogonekmacron: 0x01EC,
  20778. Oopen: 0x0186,
  20779. Oslash: 0x00D8,
  20780. Oslashacute: 0x01FE,
  20781. Oslashsmall: 0xF7F8,
  20782. Osmall: 0xF76F,
  20783. Ostrokeacute: 0x01FE,
  20784. Otcyrillic: 0x047E,
  20785. Otilde: 0x00D5,
  20786. Otildeacute: 0x1E4C,
  20787. Otildedieresis: 0x1E4E,
  20788. Otildesmall: 0xF7F5,
  20789. P: 0x0050,
  20790. Pacute: 0x1E54,
  20791. Pcircle: 0x24C5,
  20792. Pdotaccent: 0x1E56,
  20793. Pecyrillic: 0x041F,
  20794. Peharmenian: 0x054A,
  20795. Pemiddlehookcyrillic: 0x04A6,
  20796. Phi: 0x03A6,
  20797. Phook: 0x01A4,
  20798. Pi: 0x03A0,
  20799. Piwrarmenian: 0x0553,
  20800. Pmonospace: 0xFF30,
  20801. Psi: 0x03A8,
  20802. Psicyrillic: 0x0470,
  20803. Psmall: 0xF770,
  20804. Q: 0x0051,
  20805. Qcircle: 0x24C6,
  20806. Qmonospace: 0xFF31,
  20807. Qsmall: 0xF771,
  20808. R: 0x0052,
  20809. Raarmenian: 0x054C,
  20810. Racute: 0x0154,
  20811. Rcaron: 0x0158,
  20812. Rcedilla: 0x0156,
  20813. Rcircle: 0x24C7,
  20814. Rcommaaccent: 0x0156,
  20815. Rdblgrave: 0x0210,
  20816. Rdotaccent: 0x1E58,
  20817. Rdotbelow: 0x1E5A,
  20818. Rdotbelowmacron: 0x1E5C,
  20819. Reharmenian: 0x0550,
  20820. Rfraktur: 0x211C,
  20821. Rho: 0x03A1,
  20822. Ringsmall: 0xF6FC,
  20823. Rinvertedbreve: 0x0212,
  20824. Rlinebelow: 0x1E5E,
  20825. Rmonospace: 0xFF32,
  20826. Rsmall: 0xF772,
  20827. Rsmallinverted: 0x0281,
  20828. Rsmallinvertedsuperior: 0x02B6,
  20829. S: 0x0053,
  20830. SF010000: 0x250C,
  20831. SF020000: 0x2514,
  20832. SF030000: 0x2510,
  20833. SF040000: 0x2518,
  20834. SF050000: 0x253C,
  20835. SF060000: 0x252C,
  20836. SF070000: 0x2534,
  20837. SF080000: 0x251C,
  20838. SF090000: 0x2524,
  20839. SF100000: 0x2500,
  20840. SF110000: 0x2502,
  20841. SF190000: 0x2561,
  20842. SF200000: 0x2562,
  20843. SF210000: 0x2556,
  20844. SF220000: 0x2555,
  20845. SF230000: 0x2563,
  20846. SF240000: 0x2551,
  20847. SF250000: 0x2557,
  20848. SF260000: 0x255D,
  20849. SF270000: 0x255C,
  20850. SF280000: 0x255B,
  20851. SF360000: 0x255E,
  20852. SF370000: 0x255F,
  20853. SF380000: 0x255A,
  20854. SF390000: 0x2554,
  20855. SF400000: 0x2569,
  20856. SF410000: 0x2566,
  20857. SF420000: 0x2560,
  20858. SF430000: 0x2550,
  20859. SF440000: 0x256C,
  20860. SF450000: 0x2567,
  20861. SF460000: 0x2568,
  20862. SF470000: 0x2564,
  20863. SF480000: 0x2565,
  20864. SF490000: 0x2559,
  20865. SF500000: 0x2558,
  20866. SF510000: 0x2552,
  20867. SF520000: 0x2553,
  20868. SF530000: 0x256B,
  20869. SF540000: 0x256A,
  20870. Sacute: 0x015A,
  20871. Sacutedotaccent: 0x1E64,
  20872. Sampigreek: 0x03E0,
  20873. Scaron: 0x0160,
  20874. Scarondotaccent: 0x1E66,
  20875. Scaronsmall: 0xF6FD,
  20876. Scedilla: 0x015E,
  20877. Schwa: 0x018F,
  20878. Schwacyrillic: 0x04D8,
  20879. Schwadieresiscyrillic: 0x04DA,
  20880. Scircle: 0x24C8,
  20881. Scircumflex: 0x015C,
  20882. Scommaaccent: 0x0218,
  20883. Sdotaccent: 0x1E60,
  20884. Sdotbelow: 0x1E62,
  20885. Sdotbelowdotaccent: 0x1E68,
  20886. Seharmenian: 0x054D,
  20887. Sevenroman: 0x2166,
  20888. Shaarmenian: 0x0547,
  20889. Shacyrillic: 0x0428,
  20890. Shchacyrillic: 0x0429,
  20891. Sheicoptic: 0x03E2,
  20892. Shhacyrillic: 0x04BA,
  20893. Shimacoptic: 0x03EC,
  20894. Sigma: 0x03A3,
  20895. Sixroman: 0x2165,
  20896. Smonospace: 0xFF33,
  20897. Softsigncyrillic: 0x042C,
  20898. Ssmall: 0xF773,
  20899. Stigmagreek: 0x03DA,
  20900. T: 0x0054,
  20901. Tau: 0x03A4,
  20902. Tbar: 0x0166,
  20903. Tcaron: 0x0164,
  20904. Tcedilla: 0x0162,
  20905. Tcircle: 0x24C9,
  20906. Tcircumflexbelow: 0x1E70,
  20907. Tcommaaccent: 0x0162,
  20908. Tdotaccent: 0x1E6A,
  20909. Tdotbelow: 0x1E6C,
  20910. Tecyrillic: 0x0422,
  20911. Tedescendercyrillic: 0x04AC,
  20912. Tenroman: 0x2169,
  20913. Tetsecyrillic: 0x04B4,
  20914. Theta: 0x0398,
  20915. Thook: 0x01AC,
  20916. Thorn: 0x00DE,
  20917. Thornsmall: 0xF7FE,
  20918. Threeroman: 0x2162,
  20919. Tildesmall: 0xF6FE,
  20920. Tiwnarmenian: 0x054F,
  20921. Tlinebelow: 0x1E6E,
  20922. Tmonospace: 0xFF34,
  20923. Toarmenian: 0x0539,
  20924. Tonefive: 0x01BC,
  20925. Tonesix: 0x0184,
  20926. Tonetwo: 0x01A7,
  20927. Tretroflexhook: 0x01AE,
  20928. Tsecyrillic: 0x0426,
  20929. Tshecyrillic: 0x040B,
  20930. Tsmall: 0xF774,
  20931. Twelveroman: 0x216B,
  20932. Tworoman: 0x2161,
  20933. U: 0x0055,
  20934. Uacute: 0x00DA,
  20935. Uacutesmall: 0xF7FA,
  20936. Ubreve: 0x016C,
  20937. Ucaron: 0x01D3,
  20938. Ucircle: 0x24CA,
  20939. Ucircumflex: 0x00DB,
  20940. Ucircumflexbelow: 0x1E76,
  20941. Ucircumflexsmall: 0xF7FB,
  20942. Ucyrillic: 0x0423,
  20943. Udblacute: 0x0170,
  20944. Udblgrave: 0x0214,
  20945. Udieresis: 0x00DC,
  20946. Udieresisacute: 0x01D7,
  20947. Udieresisbelow: 0x1E72,
  20948. Udieresiscaron: 0x01D9,
  20949. Udieresiscyrillic: 0x04F0,
  20950. Udieresisgrave: 0x01DB,
  20951. Udieresismacron: 0x01D5,
  20952. Udieresissmall: 0xF7FC,
  20953. Udotbelow: 0x1EE4,
  20954. Ugrave: 0x00D9,
  20955. Ugravesmall: 0xF7F9,
  20956. Uhookabove: 0x1EE6,
  20957. Uhorn: 0x01AF,
  20958. Uhornacute: 0x1EE8,
  20959. Uhorndotbelow: 0x1EF0,
  20960. Uhorngrave: 0x1EEA,
  20961. Uhornhookabove: 0x1EEC,
  20962. Uhorntilde: 0x1EEE,
  20963. Uhungarumlaut: 0x0170,
  20964. Uhungarumlautcyrillic: 0x04F2,
  20965. Uinvertedbreve: 0x0216,
  20966. Ukcyrillic: 0x0478,
  20967. Umacron: 0x016A,
  20968. Umacroncyrillic: 0x04EE,
  20969. Umacrondieresis: 0x1E7A,
  20970. Umonospace: 0xFF35,
  20971. Uogonek: 0x0172,
  20972. Upsilon: 0x03A5,
  20973. Upsilon1: 0x03D2,
  20974. Upsilonacutehooksymbolgreek: 0x03D3,
  20975. Upsilonafrican: 0x01B1,
  20976. Upsilondieresis: 0x03AB,
  20977. Upsilondieresishooksymbolgreek: 0x03D4,
  20978. Upsilonhooksymbol: 0x03D2,
  20979. Upsilontonos: 0x038E,
  20980. Uring: 0x016E,
  20981. Ushortcyrillic: 0x040E,
  20982. Usmall: 0xF775,
  20983. Ustraightcyrillic: 0x04AE,
  20984. Ustraightstrokecyrillic: 0x04B0,
  20985. Utilde: 0x0168,
  20986. Utildeacute: 0x1E78,
  20987. Utildebelow: 0x1E74,
  20988. V: 0x0056,
  20989. Vcircle: 0x24CB,
  20990. Vdotbelow: 0x1E7E,
  20991. Vecyrillic: 0x0412,
  20992. Vewarmenian: 0x054E,
  20993. Vhook: 0x01B2,
  20994. Vmonospace: 0xFF36,
  20995. Voarmenian: 0x0548,
  20996. Vsmall: 0xF776,
  20997. Vtilde: 0x1E7C,
  20998. W: 0x0057,
  20999. Wacute: 0x1E82,
  21000. Wcircle: 0x24CC,
  21001. Wcircumflex: 0x0174,
  21002. Wdieresis: 0x1E84,
  21003. Wdotaccent: 0x1E86,
  21004. Wdotbelow: 0x1E88,
  21005. Wgrave: 0x1E80,
  21006. Wmonospace: 0xFF37,
  21007. Wsmall: 0xF777,
  21008. X: 0x0058,
  21009. Xcircle: 0x24CD,
  21010. Xdieresis: 0x1E8C,
  21011. Xdotaccent: 0x1E8A,
  21012. Xeharmenian: 0x053D,
  21013. Xi: 0x039E,
  21014. Xmonospace: 0xFF38,
  21015. Xsmall: 0xF778,
  21016. Y: 0x0059,
  21017. Yacute: 0x00DD,
  21018. Yacutesmall: 0xF7FD,
  21019. Yatcyrillic: 0x0462,
  21020. Ycircle: 0x24CE,
  21021. Ycircumflex: 0x0176,
  21022. Ydieresis: 0x0178,
  21023. Ydieresissmall: 0xF7FF,
  21024. Ydotaccent: 0x1E8E,
  21025. Ydotbelow: 0x1EF4,
  21026. Yericyrillic: 0x042B,
  21027. Yerudieresiscyrillic: 0x04F8,
  21028. Ygrave: 0x1EF2,
  21029. Yhook: 0x01B3,
  21030. Yhookabove: 0x1EF6,
  21031. Yiarmenian: 0x0545,
  21032. Yicyrillic: 0x0407,
  21033. Yiwnarmenian: 0x0552,
  21034. Ymonospace: 0xFF39,
  21035. Ysmall: 0xF779,
  21036. Ytilde: 0x1EF8,
  21037. Yusbigcyrillic: 0x046A,
  21038. Yusbigiotifiedcyrillic: 0x046C,
  21039. Yuslittlecyrillic: 0x0466,
  21040. Yuslittleiotifiedcyrillic: 0x0468,
  21041. Z: 0x005A,
  21042. Zaarmenian: 0x0536,
  21043. Zacute: 0x0179,
  21044. Zcaron: 0x017D,
  21045. Zcaronsmall: 0xF6FF,
  21046. Zcircle: 0x24CF,
  21047. Zcircumflex: 0x1E90,
  21048. Zdot: 0x017B,
  21049. Zdotaccent: 0x017B,
  21050. Zdotbelow: 0x1E92,
  21051. Zecyrillic: 0x0417,
  21052. Zedescendercyrillic: 0x0498,
  21053. Zedieresiscyrillic: 0x04DE,
  21054. Zeta: 0x0396,
  21055. Zhearmenian: 0x053A,
  21056. Zhebrevecyrillic: 0x04C1,
  21057. Zhecyrillic: 0x0416,
  21058. Zhedescendercyrillic: 0x0496,
  21059. Zhedieresiscyrillic: 0x04DC,
  21060. Zlinebelow: 0x1E94,
  21061. Zmonospace: 0xFF3A,
  21062. Zsmall: 0xF77A,
  21063. Zstroke: 0x01B5,
  21064. a: 0x0061,
  21065. aabengali: 0x0986,
  21066. aacute: 0x00E1,
  21067. aadeva: 0x0906,
  21068. aagujarati: 0x0A86,
  21069. aagurmukhi: 0x0A06,
  21070. aamatragurmukhi: 0x0A3E,
  21071. aarusquare: 0x3303,
  21072. aavowelsignbengali: 0x09BE,
  21073. aavowelsigndeva: 0x093E,
  21074. aavowelsigngujarati: 0x0ABE,
  21075. abbreviationmarkarmenian: 0x055F,
  21076. abbreviationsigndeva: 0x0970,
  21077. abengali: 0x0985,
  21078. abopomofo: 0x311A,
  21079. abreve: 0x0103,
  21080. abreveacute: 0x1EAF,
  21081. abrevecyrillic: 0x04D1,
  21082. abrevedotbelow: 0x1EB7,
  21083. abrevegrave: 0x1EB1,
  21084. abrevehookabove: 0x1EB3,
  21085. abrevetilde: 0x1EB5,
  21086. acaron: 0x01CE,
  21087. acircle: 0x24D0,
  21088. acircumflex: 0x00E2,
  21089. acircumflexacute: 0x1EA5,
  21090. acircumflexdotbelow: 0x1EAD,
  21091. acircumflexgrave: 0x1EA7,
  21092. acircumflexhookabove: 0x1EA9,
  21093. acircumflextilde: 0x1EAB,
  21094. acute: 0x00B4,
  21095. acutebelowcmb: 0x0317,
  21096. acutecmb: 0x0301,
  21097. acutecomb: 0x0301,
  21098. acutedeva: 0x0954,
  21099. acutelowmod: 0x02CF,
  21100. acutetonecmb: 0x0341,
  21101. acyrillic: 0x0430,
  21102. adblgrave: 0x0201,
  21103. addakgurmukhi: 0x0A71,
  21104. adeva: 0x0905,
  21105. adieresis: 0x00E4,
  21106. adieresiscyrillic: 0x04D3,
  21107. adieresismacron: 0x01DF,
  21108. adotbelow: 0x1EA1,
  21109. adotmacron: 0x01E1,
  21110. ae: 0x00E6,
  21111. aeacute: 0x01FD,
  21112. aekorean: 0x3150,
  21113. aemacron: 0x01E3,
  21114. afii00208: 0x2015,
  21115. afii08941: 0x20A4,
  21116. afii10017: 0x0410,
  21117. afii10018: 0x0411,
  21118. afii10019: 0x0412,
  21119. afii10020: 0x0413,
  21120. afii10021: 0x0414,
  21121. afii10022: 0x0415,
  21122. afii10023: 0x0401,
  21123. afii10024: 0x0416,
  21124. afii10025: 0x0417,
  21125. afii10026: 0x0418,
  21126. afii10027: 0x0419,
  21127. afii10028: 0x041A,
  21128. afii10029: 0x041B,
  21129. afii10030: 0x041C,
  21130. afii10031: 0x041D,
  21131. afii10032: 0x041E,
  21132. afii10033: 0x041F,
  21133. afii10034: 0x0420,
  21134. afii10035: 0x0421,
  21135. afii10036: 0x0422,
  21136. afii10037: 0x0423,
  21137. afii10038: 0x0424,
  21138. afii10039: 0x0425,
  21139. afii10040: 0x0426,
  21140. afii10041: 0x0427,
  21141. afii10042: 0x0428,
  21142. afii10043: 0x0429,
  21143. afii10044: 0x042A,
  21144. afii10045: 0x042B,
  21145. afii10046: 0x042C,
  21146. afii10047: 0x042D,
  21147. afii10048: 0x042E,
  21148. afii10049: 0x042F,
  21149. afii10050: 0x0490,
  21150. afii10051: 0x0402,
  21151. afii10052: 0x0403,
  21152. afii10053: 0x0404,
  21153. afii10054: 0x0405,
  21154. afii10055: 0x0406,
  21155. afii10056: 0x0407,
  21156. afii10057: 0x0408,
  21157. afii10058: 0x0409,
  21158. afii10059: 0x040A,
  21159. afii10060: 0x040B,
  21160. afii10061: 0x040C,
  21161. afii10062: 0x040E,
  21162. afii10063: 0xF6C4,
  21163. afii10064: 0xF6C5,
  21164. afii10065: 0x0430,
  21165. afii10066: 0x0431,
  21166. afii10067: 0x0432,
  21167. afii10068: 0x0433,
  21168. afii10069: 0x0434,
  21169. afii10070: 0x0435,
  21170. afii10071: 0x0451,
  21171. afii10072: 0x0436,
  21172. afii10073: 0x0437,
  21173. afii10074: 0x0438,
  21174. afii10075: 0x0439,
  21175. afii10076: 0x043A,
  21176. afii10077: 0x043B,
  21177. afii10078: 0x043C,
  21178. afii10079: 0x043D,
  21179. afii10080: 0x043E,
  21180. afii10081: 0x043F,
  21181. afii10082: 0x0440,
  21182. afii10083: 0x0441,
  21183. afii10084: 0x0442,
  21184. afii10085: 0x0443,
  21185. afii10086: 0x0444,
  21186. afii10087: 0x0445,
  21187. afii10088: 0x0446,
  21188. afii10089: 0x0447,
  21189. afii10090: 0x0448,
  21190. afii10091: 0x0449,
  21191. afii10092: 0x044A,
  21192. afii10093: 0x044B,
  21193. afii10094: 0x044C,
  21194. afii10095: 0x044D,
  21195. afii10096: 0x044E,
  21196. afii10097: 0x044F,
  21197. afii10098: 0x0491,
  21198. afii10099: 0x0452,
  21199. afii10100: 0x0453,
  21200. afii10101: 0x0454,
  21201. afii10102: 0x0455,
  21202. afii10103: 0x0456,
  21203. afii10104: 0x0457,
  21204. afii10105: 0x0458,
  21205. afii10106: 0x0459,
  21206. afii10107: 0x045A,
  21207. afii10108: 0x045B,
  21208. afii10109: 0x045C,
  21209. afii10110: 0x045E,
  21210. afii10145: 0x040F,
  21211. afii10146: 0x0462,
  21212. afii10147: 0x0472,
  21213. afii10148: 0x0474,
  21214. afii10192: 0xF6C6,
  21215. afii10193: 0x045F,
  21216. afii10194: 0x0463,
  21217. afii10195: 0x0473,
  21218. afii10196: 0x0475,
  21219. afii10831: 0xF6C7,
  21220. afii10832: 0xF6C8,
  21221. afii10846: 0x04D9,
  21222. afii299: 0x200E,
  21223. afii300: 0x200F,
  21224. afii301: 0x200D,
  21225. afii57381: 0x066A,
  21226. afii57388: 0x060C,
  21227. afii57392: 0x0660,
  21228. afii57393: 0x0661,
  21229. afii57394: 0x0662,
  21230. afii57395: 0x0663,
  21231. afii57396: 0x0664,
  21232. afii57397: 0x0665,
  21233. afii57398: 0x0666,
  21234. afii57399: 0x0667,
  21235. afii57400: 0x0668,
  21236. afii57401: 0x0669,
  21237. afii57403: 0x061B,
  21238. afii57407: 0x061F,
  21239. afii57409: 0x0621,
  21240. afii57410: 0x0622,
  21241. afii57411: 0x0623,
  21242. afii57412: 0x0624,
  21243. afii57413: 0x0625,
  21244. afii57414: 0x0626,
  21245. afii57415: 0x0627,
  21246. afii57416: 0x0628,
  21247. afii57417: 0x0629,
  21248. afii57418: 0x062A,
  21249. afii57419: 0x062B,
  21250. afii57420: 0x062C,
  21251. afii57421: 0x062D,
  21252. afii57422: 0x062E,
  21253. afii57423: 0x062F,
  21254. afii57424: 0x0630,
  21255. afii57425: 0x0631,
  21256. afii57426: 0x0632,
  21257. afii57427: 0x0633,
  21258. afii57428: 0x0634,
  21259. afii57429: 0x0635,
  21260. afii57430: 0x0636,
  21261. afii57431: 0x0637,
  21262. afii57432: 0x0638,
  21263. afii57433: 0x0639,
  21264. afii57434: 0x063A,
  21265. afii57440: 0x0640,
  21266. afii57441: 0x0641,
  21267. afii57442: 0x0642,
  21268. afii57443: 0x0643,
  21269. afii57444: 0x0644,
  21270. afii57445: 0x0645,
  21271. afii57446: 0x0646,
  21272. afii57448: 0x0648,
  21273. afii57449: 0x0649,
  21274. afii57450: 0x064A,
  21275. afii57451: 0x064B,
  21276. afii57452: 0x064C,
  21277. afii57453: 0x064D,
  21278. afii57454: 0x064E,
  21279. afii57455: 0x064F,
  21280. afii57456: 0x0650,
  21281. afii57457: 0x0651,
  21282. afii57458: 0x0652,
  21283. afii57470: 0x0647,
  21284. afii57505: 0x06A4,
  21285. afii57506: 0x067E,
  21286. afii57507: 0x0686,
  21287. afii57508: 0x0698,
  21288. afii57509: 0x06AF,
  21289. afii57511: 0x0679,
  21290. afii57512: 0x0688,
  21291. afii57513: 0x0691,
  21292. afii57514: 0x06BA,
  21293. afii57519: 0x06D2,
  21294. afii57534: 0x06D5,
  21295. afii57636: 0x20AA,
  21296. afii57645: 0x05BE,
  21297. afii57658: 0x05C3,
  21298. afii57664: 0x05D0,
  21299. afii57665: 0x05D1,
  21300. afii57666: 0x05D2,
  21301. afii57667: 0x05D3,
  21302. afii57668: 0x05D4,
  21303. afii57669: 0x05D5,
  21304. afii57670: 0x05D6,
  21305. afii57671: 0x05D7,
  21306. afii57672: 0x05D8,
  21307. afii57673: 0x05D9,
  21308. afii57674: 0x05DA,
  21309. afii57675: 0x05DB,
  21310. afii57676: 0x05DC,
  21311. afii57677: 0x05DD,
  21312. afii57678: 0x05DE,
  21313. afii57679: 0x05DF,
  21314. afii57680: 0x05E0,
  21315. afii57681: 0x05E1,
  21316. afii57682: 0x05E2,
  21317. afii57683: 0x05E3,
  21318. afii57684: 0x05E4,
  21319. afii57685: 0x05E5,
  21320. afii57686: 0x05E6,
  21321. afii57687: 0x05E7,
  21322. afii57688: 0x05E8,
  21323. afii57689: 0x05E9,
  21324. afii57690: 0x05EA,
  21325. afii57694: 0xFB2A,
  21326. afii57695: 0xFB2B,
  21327. afii57700: 0xFB4B,
  21328. afii57705: 0xFB1F,
  21329. afii57716: 0x05F0,
  21330. afii57717: 0x05F1,
  21331. afii57718: 0x05F2,
  21332. afii57723: 0xFB35,
  21333. afii57793: 0x05B4,
  21334. afii57794: 0x05B5,
  21335. afii57795: 0x05B6,
  21336. afii57796: 0x05BB,
  21337. afii57797: 0x05B8,
  21338. afii57798: 0x05B7,
  21339. afii57799: 0x05B0,
  21340. afii57800: 0x05B2,
  21341. afii57801: 0x05B1,
  21342. afii57802: 0x05B3,
  21343. afii57803: 0x05C2,
  21344. afii57804: 0x05C1,
  21345. afii57806: 0x05B9,
  21346. afii57807: 0x05BC,
  21347. afii57839: 0x05BD,
  21348. afii57841: 0x05BF,
  21349. afii57842: 0x05C0,
  21350. afii57929: 0x02BC,
  21351. afii61248: 0x2105,
  21352. afii61289: 0x2113,
  21353. afii61352: 0x2116,
  21354. afii61573: 0x202C,
  21355. afii61574: 0x202D,
  21356. afii61575: 0x202E,
  21357. afii61664: 0x200C,
  21358. afii63167: 0x066D,
  21359. afii64937: 0x02BD,
  21360. agrave: 0x00E0,
  21361. agujarati: 0x0A85,
  21362. agurmukhi: 0x0A05,
  21363. ahiragana: 0x3042,
  21364. ahookabove: 0x1EA3,
  21365. aibengali: 0x0990,
  21366. aibopomofo: 0x311E,
  21367. aideva: 0x0910,
  21368. aiecyrillic: 0x04D5,
  21369. aigujarati: 0x0A90,
  21370. aigurmukhi: 0x0A10,
  21371. aimatragurmukhi: 0x0A48,
  21372. ainarabic: 0x0639,
  21373. ainfinalarabic: 0xFECA,
  21374. aininitialarabic: 0xFECB,
  21375. ainmedialarabic: 0xFECC,
  21376. ainvertedbreve: 0x0203,
  21377. aivowelsignbengali: 0x09C8,
  21378. aivowelsigndeva: 0x0948,
  21379. aivowelsigngujarati: 0x0AC8,
  21380. akatakana: 0x30A2,
  21381. akatakanahalfwidth: 0xFF71,
  21382. akorean: 0x314F,
  21383. alef: 0x05D0,
  21384. alefarabic: 0x0627,
  21385. alefdageshhebrew: 0xFB30,
  21386. aleffinalarabic: 0xFE8E,
  21387. alefhamzaabovearabic: 0x0623,
  21388. alefhamzaabovefinalarabic: 0xFE84,
  21389. alefhamzabelowarabic: 0x0625,
  21390. alefhamzabelowfinalarabic: 0xFE88,
  21391. alefhebrew: 0x05D0,
  21392. aleflamedhebrew: 0xFB4F,
  21393. alefmaddaabovearabic: 0x0622,
  21394. alefmaddaabovefinalarabic: 0xFE82,
  21395. alefmaksuraarabic: 0x0649,
  21396. alefmaksurafinalarabic: 0xFEF0,
  21397. alefmaksurainitialarabic: 0xFEF3,
  21398. alefmaksuramedialarabic: 0xFEF4,
  21399. alefpatahhebrew: 0xFB2E,
  21400. alefqamatshebrew: 0xFB2F,
  21401. aleph: 0x2135,
  21402. allequal: 0x224C,
  21403. alpha: 0x03B1,
  21404. alphatonos: 0x03AC,
  21405. amacron: 0x0101,
  21406. amonospace: 0xFF41,
  21407. ampersand: 0x0026,
  21408. ampersandmonospace: 0xFF06,
  21409. ampersandsmall: 0xF726,
  21410. amsquare: 0x33C2,
  21411. anbopomofo: 0x3122,
  21412. angbopomofo: 0x3124,
  21413. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21414. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21415. angkhankhuthai: 0x0E5A,
  21416. angle: 0x2220,
  21417. anglebracketleft: 0x3008,
  21418. anglebracketleftvertical: 0xFE3F,
  21419. anglebracketright: 0x3009,
  21420. anglebracketrightvertical: 0xFE40,
  21421. angleleft: 0x2329,
  21422. angleright: 0x232A,
  21423. angstrom: 0x212B,
  21424. anoteleia: 0x0387,
  21425. anudattadeva: 0x0952,
  21426. anusvarabengali: 0x0982,
  21427. anusvaradeva: 0x0902,
  21428. anusvaragujarati: 0x0A82,
  21429. aogonek: 0x0105,
  21430. apaatosquare: 0x3300,
  21431. aparen: 0x249C,
  21432. apostrophearmenian: 0x055A,
  21433. apostrophemod: 0x02BC,
  21434. apple: 0xF8FF,
  21435. approaches: 0x2250,
  21436. approxequal: 0x2248,
  21437. approxequalorimage: 0x2252,
  21438. approximatelyequal: 0x2245,
  21439. araeaekorean: 0x318E,
  21440. araeakorean: 0x318D,
  21441. arc: 0x2312,
  21442. arighthalfring: 0x1E9A,
  21443. aring: 0x00E5,
  21444. aringacute: 0x01FB,
  21445. aringbelow: 0x1E01,
  21446. arrowboth: 0x2194,
  21447. arrowdashdown: 0x21E3,
  21448. arrowdashleft: 0x21E0,
  21449. arrowdashright: 0x21E2,
  21450. arrowdashup: 0x21E1,
  21451. arrowdblboth: 0x21D4,
  21452. arrowdbldown: 0x21D3,
  21453. arrowdblleft: 0x21D0,
  21454. arrowdblright: 0x21D2,
  21455. arrowdblup: 0x21D1,
  21456. arrowdown: 0x2193,
  21457. arrowdownleft: 0x2199,
  21458. arrowdownright: 0x2198,
  21459. arrowdownwhite: 0x21E9,
  21460. arrowheaddownmod: 0x02C5,
  21461. arrowheadleftmod: 0x02C2,
  21462. arrowheadrightmod: 0x02C3,
  21463. arrowheadupmod: 0x02C4,
  21464. arrowhorizex: 0xF8E7,
  21465. arrowleft: 0x2190,
  21466. arrowleftdbl: 0x21D0,
  21467. arrowleftdblstroke: 0x21CD,
  21468. arrowleftoverright: 0x21C6,
  21469. arrowleftwhite: 0x21E6,
  21470. arrowright: 0x2192,
  21471. arrowrightdblstroke: 0x21CF,
  21472. arrowrightheavy: 0x279E,
  21473. arrowrightoverleft: 0x21C4,
  21474. arrowrightwhite: 0x21E8,
  21475. arrowtableft: 0x21E4,
  21476. arrowtabright: 0x21E5,
  21477. arrowup: 0x2191,
  21478. arrowupdn: 0x2195,
  21479. arrowupdnbse: 0x21A8,
  21480. arrowupdownbase: 0x21A8,
  21481. arrowupleft: 0x2196,
  21482. arrowupleftofdown: 0x21C5,
  21483. arrowupright: 0x2197,
  21484. arrowupwhite: 0x21E7,
  21485. arrowvertex: 0xF8E6,
  21486. asciicircum: 0x005E,
  21487. asciicircummonospace: 0xFF3E,
  21488. asciitilde: 0x007E,
  21489. asciitildemonospace: 0xFF5E,
  21490. ascript: 0x0251,
  21491. ascriptturned: 0x0252,
  21492. asmallhiragana: 0x3041,
  21493. asmallkatakana: 0x30A1,
  21494. asmallkatakanahalfwidth: 0xFF67,
  21495. asterisk: 0x002A,
  21496. asteriskaltonearabic: 0x066D,
  21497. asteriskarabic: 0x066D,
  21498. asteriskmath: 0x2217,
  21499. asteriskmonospace: 0xFF0A,
  21500. asterisksmall: 0xFE61,
  21501. asterism: 0x2042,
  21502. asuperior: 0xF6E9,
  21503. asymptoticallyequal: 0x2243,
  21504. at: 0x0040,
  21505. atilde: 0x00E3,
  21506. atmonospace: 0xFF20,
  21507. atsmall: 0xFE6B,
  21508. aturned: 0x0250,
  21509. aubengali: 0x0994,
  21510. aubopomofo: 0x3120,
  21511. audeva: 0x0914,
  21512. augujarati: 0x0A94,
  21513. augurmukhi: 0x0A14,
  21514. aulengthmarkbengali: 0x09D7,
  21515. aumatragurmukhi: 0x0A4C,
  21516. auvowelsignbengali: 0x09CC,
  21517. auvowelsigndeva: 0x094C,
  21518. auvowelsigngujarati: 0x0ACC,
  21519. avagrahadeva: 0x093D,
  21520. aybarmenian: 0x0561,
  21521. ayin: 0x05E2,
  21522. ayinaltonehebrew: 0xFB20,
  21523. ayinhebrew: 0x05E2,
  21524. b: 0x0062,
  21525. babengali: 0x09AC,
  21526. backslash: 0x005C,
  21527. backslashmonospace: 0xFF3C,
  21528. badeva: 0x092C,
  21529. bagujarati: 0x0AAC,
  21530. bagurmukhi: 0x0A2C,
  21531. bahiragana: 0x3070,
  21532. bahtthai: 0x0E3F,
  21533. bakatakana: 0x30D0,
  21534. bar: 0x007C,
  21535. barmonospace: 0xFF5C,
  21536. bbopomofo: 0x3105,
  21537. bcircle: 0x24D1,
  21538. bdotaccent: 0x1E03,
  21539. bdotbelow: 0x1E05,
  21540. beamedsixteenthnotes: 0x266C,
  21541. because: 0x2235,
  21542. becyrillic: 0x0431,
  21543. beharabic: 0x0628,
  21544. behfinalarabic: 0xFE90,
  21545. behinitialarabic: 0xFE91,
  21546. behiragana: 0x3079,
  21547. behmedialarabic: 0xFE92,
  21548. behmeeminitialarabic: 0xFC9F,
  21549. behmeemisolatedarabic: 0xFC08,
  21550. behnoonfinalarabic: 0xFC6D,
  21551. bekatakana: 0x30D9,
  21552. benarmenian: 0x0562,
  21553. bet: 0x05D1,
  21554. beta: 0x03B2,
  21555. betasymbolgreek: 0x03D0,
  21556. betdagesh: 0xFB31,
  21557. betdageshhebrew: 0xFB31,
  21558. bethebrew: 0x05D1,
  21559. betrafehebrew: 0xFB4C,
  21560. bhabengali: 0x09AD,
  21561. bhadeva: 0x092D,
  21562. bhagujarati: 0x0AAD,
  21563. bhagurmukhi: 0x0A2D,
  21564. bhook: 0x0253,
  21565. bihiragana: 0x3073,
  21566. bikatakana: 0x30D3,
  21567. bilabialclick: 0x0298,
  21568. bindigurmukhi: 0x0A02,
  21569. birusquare: 0x3331,
  21570. blackcircle: 0x25CF,
  21571. blackdiamond: 0x25C6,
  21572. blackdownpointingtriangle: 0x25BC,
  21573. blackleftpointingpointer: 0x25C4,
  21574. blackleftpointingtriangle: 0x25C0,
  21575. blacklenticularbracketleft: 0x3010,
  21576. blacklenticularbracketleftvertical: 0xFE3B,
  21577. blacklenticularbracketright: 0x3011,
  21578. blacklenticularbracketrightvertical: 0xFE3C,
  21579. blacklowerlefttriangle: 0x25E3,
  21580. blacklowerrighttriangle: 0x25E2,
  21581. blackrectangle: 0x25AC,
  21582. blackrightpointingpointer: 0x25BA,
  21583. blackrightpointingtriangle: 0x25B6,
  21584. blacksmallsquare: 0x25AA,
  21585. blacksmilingface: 0x263B,
  21586. blacksquare: 0x25A0,
  21587. blackstar: 0x2605,
  21588. blackupperlefttriangle: 0x25E4,
  21589. blackupperrighttriangle: 0x25E5,
  21590. blackuppointingsmalltriangle: 0x25B4,
  21591. blackuppointingtriangle: 0x25B2,
  21592. blank: 0x2423,
  21593. blinebelow: 0x1E07,
  21594. block: 0x2588,
  21595. bmonospace: 0xFF42,
  21596. bobaimaithai: 0x0E1A,
  21597. bohiragana: 0x307C,
  21598. bokatakana: 0x30DC,
  21599. bparen: 0x249D,
  21600. bqsquare: 0x33C3,
  21601. braceex: 0xF8F4,
  21602. braceleft: 0x007B,
  21603. braceleftbt: 0xF8F3,
  21604. braceleftmid: 0xF8F2,
  21605. braceleftmonospace: 0xFF5B,
  21606. braceleftsmall: 0xFE5B,
  21607. bracelefttp: 0xF8F1,
  21608. braceleftvertical: 0xFE37,
  21609. braceright: 0x007D,
  21610. bracerightbt: 0xF8FE,
  21611. bracerightmid: 0xF8FD,
  21612. bracerightmonospace: 0xFF5D,
  21613. bracerightsmall: 0xFE5C,
  21614. bracerighttp: 0xF8FC,
  21615. bracerightvertical: 0xFE38,
  21616. bracketleft: 0x005B,
  21617. bracketleftbt: 0xF8F0,
  21618. bracketleftex: 0xF8EF,
  21619. bracketleftmonospace: 0xFF3B,
  21620. bracketlefttp: 0xF8EE,
  21621. bracketright: 0x005D,
  21622. bracketrightbt: 0xF8FB,
  21623. bracketrightex: 0xF8FA,
  21624. bracketrightmonospace: 0xFF3D,
  21625. bracketrighttp: 0xF8F9,
  21626. breve: 0x02D8,
  21627. brevebelowcmb: 0x032E,
  21628. brevecmb: 0x0306,
  21629. breveinvertedbelowcmb: 0x032F,
  21630. breveinvertedcmb: 0x0311,
  21631. breveinverteddoublecmb: 0x0361,
  21632. bridgebelowcmb: 0x032A,
  21633. bridgeinvertedbelowcmb: 0x033A,
  21634. brokenbar: 0x00A6,
  21635. bstroke: 0x0180,
  21636. bsuperior: 0xF6EA,
  21637. btopbar: 0x0183,
  21638. buhiragana: 0x3076,
  21639. bukatakana: 0x30D6,
  21640. bullet: 0x2022,
  21641. bulletinverse: 0x25D8,
  21642. bulletoperator: 0x2219,
  21643. bullseye: 0x25CE,
  21644. c: 0x0063,
  21645. caarmenian: 0x056E,
  21646. cabengali: 0x099A,
  21647. cacute: 0x0107,
  21648. cadeva: 0x091A,
  21649. cagujarati: 0x0A9A,
  21650. cagurmukhi: 0x0A1A,
  21651. calsquare: 0x3388,
  21652. candrabindubengali: 0x0981,
  21653. candrabinducmb: 0x0310,
  21654. candrabindudeva: 0x0901,
  21655. candrabindugujarati: 0x0A81,
  21656. capslock: 0x21EA,
  21657. careof: 0x2105,
  21658. caron: 0x02C7,
  21659. caronbelowcmb: 0x032C,
  21660. caroncmb: 0x030C,
  21661. carriagereturn: 0x21B5,
  21662. cbopomofo: 0x3118,
  21663. ccaron: 0x010D,
  21664. ccedilla: 0x00E7,
  21665. ccedillaacute: 0x1E09,
  21666. ccircle: 0x24D2,
  21667. ccircumflex: 0x0109,
  21668. ccurl: 0x0255,
  21669. cdot: 0x010B,
  21670. cdotaccent: 0x010B,
  21671. cdsquare: 0x33C5,
  21672. cedilla: 0x00B8,
  21673. cedillacmb: 0x0327,
  21674. cent: 0x00A2,
  21675. centigrade: 0x2103,
  21676. centinferior: 0xF6DF,
  21677. centmonospace: 0xFFE0,
  21678. centoldstyle: 0xF7A2,
  21679. centsuperior: 0xF6E0,
  21680. chaarmenian: 0x0579,
  21681. chabengali: 0x099B,
  21682. chadeva: 0x091B,
  21683. chagujarati: 0x0A9B,
  21684. chagurmukhi: 0x0A1B,
  21685. chbopomofo: 0x3114,
  21686. cheabkhasiancyrillic: 0x04BD,
  21687. checkmark: 0x2713,
  21688. checyrillic: 0x0447,
  21689. chedescenderabkhasiancyrillic: 0x04BF,
  21690. chedescendercyrillic: 0x04B7,
  21691. chedieresiscyrillic: 0x04F5,
  21692. cheharmenian: 0x0573,
  21693. chekhakassiancyrillic: 0x04CC,
  21694. cheverticalstrokecyrillic: 0x04B9,
  21695. chi: 0x03C7,
  21696. chieuchacirclekorean: 0x3277,
  21697. chieuchaparenkorean: 0x3217,
  21698. chieuchcirclekorean: 0x3269,
  21699. chieuchkorean: 0x314A,
  21700. chieuchparenkorean: 0x3209,
  21701. chochangthai: 0x0E0A,
  21702. chochanthai: 0x0E08,
  21703. chochingthai: 0x0E09,
  21704. chochoethai: 0x0E0C,
  21705. chook: 0x0188,
  21706. cieucacirclekorean: 0x3276,
  21707. cieucaparenkorean: 0x3216,
  21708. cieuccirclekorean: 0x3268,
  21709. cieuckorean: 0x3148,
  21710. cieucparenkorean: 0x3208,
  21711. cieucuparenkorean: 0x321C,
  21712. circle: 0x25CB,
  21713. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21714. circlemultiply: 0x2297,
  21715. circleot: 0x2299,
  21716. circleplus: 0x2295,
  21717. circlepostalmark: 0x3036,
  21718. circlewithlefthalfblack: 0x25D0,
  21719. circlewithrighthalfblack: 0x25D1,
  21720. circumflex: 0x02C6,
  21721. circumflexbelowcmb: 0x032D,
  21722. circumflexcmb: 0x0302,
  21723. clear: 0x2327,
  21724. clickalveolar: 0x01C2,
  21725. clickdental: 0x01C0,
  21726. clicklateral: 0x01C1,
  21727. clickretroflex: 0x01C3,
  21728. club: 0x2663,
  21729. clubsuitblack: 0x2663,
  21730. clubsuitwhite: 0x2667,
  21731. cmcubedsquare: 0x33A4,
  21732. cmonospace: 0xFF43,
  21733. cmsquaredsquare: 0x33A0,
  21734. coarmenian: 0x0581,
  21735. colon: 0x003A,
  21736. colonmonetary: 0x20A1,
  21737. colonmonospace: 0xFF1A,
  21738. colonsign: 0x20A1,
  21739. colonsmall: 0xFE55,
  21740. colontriangularhalfmod: 0x02D1,
  21741. colontriangularmod: 0x02D0,
  21742. comma: 0x002C,
  21743. commaabovecmb: 0x0313,
  21744. commaaboverightcmb: 0x0315,
  21745. commaaccent: 0xF6C3,
  21746. commaarabic: 0x060C,
  21747. commaarmenian: 0x055D,
  21748. commainferior: 0xF6E1,
  21749. commamonospace: 0xFF0C,
  21750. commareversedabovecmb: 0x0314,
  21751. commareversedmod: 0x02BD,
  21752. commasmall: 0xFE50,
  21753. commasuperior: 0xF6E2,
  21754. commaturnedabovecmb: 0x0312,
  21755. commaturnedmod: 0x02BB,
  21756. compass: 0x263C,
  21757. congruent: 0x2245,
  21758. contourintegral: 0x222E,
  21759. control: 0x2303,
  21760. controlACK: 0x0006,
  21761. controlBEL: 0x0007,
  21762. controlBS: 0x0008,
  21763. controlCAN: 0x0018,
  21764. controlCR: 0x000D,
  21765. controlDC1: 0x0011,
  21766. controlDC2: 0x0012,
  21767. controlDC3: 0x0013,
  21768. controlDC4: 0x0014,
  21769. controlDEL: 0x007F,
  21770. controlDLE: 0x0010,
  21771. controlEM: 0x0019,
  21772. controlENQ: 0x0005,
  21773. controlEOT: 0x0004,
  21774. controlESC: 0x001B,
  21775. controlETB: 0x0017,
  21776. controlETX: 0x0003,
  21777. controlFF: 0x000C,
  21778. controlFS: 0x001C,
  21779. controlGS: 0x001D,
  21780. controlHT: 0x0009,
  21781. controlLF: 0x000A,
  21782. controlNAK: 0x0015,
  21783. controlRS: 0x001E,
  21784. controlSI: 0x000F,
  21785. controlSO: 0x000E,
  21786. controlSOT: 0x0002,
  21787. controlSTX: 0x0001,
  21788. controlSUB: 0x001A,
  21789. controlSYN: 0x0016,
  21790. controlUS: 0x001F,
  21791. controlVT: 0x000B,
  21792. copyright: 0x00A9,
  21793. copyrightsans: 0xF8E9,
  21794. copyrightserif: 0xF6D9,
  21795. cornerbracketleft: 0x300C,
  21796. cornerbracketlefthalfwidth: 0xFF62,
  21797. cornerbracketleftvertical: 0xFE41,
  21798. cornerbracketright: 0x300D,
  21799. cornerbracketrighthalfwidth: 0xFF63,
  21800. cornerbracketrightvertical: 0xFE42,
  21801. corporationsquare: 0x337F,
  21802. cosquare: 0x33C7,
  21803. coverkgsquare: 0x33C6,
  21804. cparen: 0x249E,
  21805. cruzeiro: 0x20A2,
  21806. cstretched: 0x0297,
  21807. curlyand: 0x22CF,
  21808. curlyor: 0x22CE,
  21809. currency: 0x00A4,
  21810. cyrBreve: 0xF6D1,
  21811. cyrFlex: 0xF6D2,
  21812. cyrbreve: 0xF6D4,
  21813. cyrflex: 0xF6D5,
  21814. d: 0x0064,
  21815. daarmenian: 0x0564,
  21816. dabengali: 0x09A6,
  21817. dadarabic: 0x0636,
  21818. dadeva: 0x0926,
  21819. dadfinalarabic: 0xFEBE,
  21820. dadinitialarabic: 0xFEBF,
  21821. dadmedialarabic: 0xFEC0,
  21822. dagesh: 0x05BC,
  21823. dageshhebrew: 0x05BC,
  21824. dagger: 0x2020,
  21825. daggerdbl: 0x2021,
  21826. dagujarati: 0x0AA6,
  21827. dagurmukhi: 0x0A26,
  21828. dahiragana: 0x3060,
  21829. dakatakana: 0x30C0,
  21830. dalarabic: 0x062F,
  21831. dalet: 0x05D3,
  21832. daletdagesh: 0xFB33,
  21833. daletdageshhebrew: 0xFB33,
  21834. dalethebrew: 0x05D3,
  21835. dalfinalarabic: 0xFEAA,
  21836. dammaarabic: 0x064F,
  21837. dammalowarabic: 0x064F,
  21838. dammatanaltonearabic: 0x064C,
  21839. dammatanarabic: 0x064C,
  21840. danda: 0x0964,
  21841. dargahebrew: 0x05A7,
  21842. dargalefthebrew: 0x05A7,
  21843. dasiapneumatacyrilliccmb: 0x0485,
  21844. dblGrave: 0xF6D3,
  21845. dblanglebracketleft: 0x300A,
  21846. dblanglebracketleftvertical: 0xFE3D,
  21847. dblanglebracketright: 0x300B,
  21848. dblanglebracketrightvertical: 0xFE3E,
  21849. dblarchinvertedbelowcmb: 0x032B,
  21850. dblarrowleft: 0x21D4,
  21851. dblarrowright: 0x21D2,
  21852. dbldanda: 0x0965,
  21853. dblgrave: 0xF6D6,
  21854. dblgravecmb: 0x030F,
  21855. dblintegral: 0x222C,
  21856. dbllowline: 0x2017,
  21857. dbllowlinecmb: 0x0333,
  21858. dbloverlinecmb: 0x033F,
  21859. dblprimemod: 0x02BA,
  21860. dblverticalbar: 0x2016,
  21861. dblverticallineabovecmb: 0x030E,
  21862. dbopomofo: 0x3109,
  21863. dbsquare: 0x33C8,
  21864. dcaron: 0x010F,
  21865. dcedilla: 0x1E11,
  21866. dcircle: 0x24D3,
  21867. dcircumflexbelow: 0x1E13,
  21868. dcroat: 0x0111,
  21869. ddabengali: 0x09A1,
  21870. ddadeva: 0x0921,
  21871. ddagujarati: 0x0AA1,
  21872. ddagurmukhi: 0x0A21,
  21873. ddalarabic: 0x0688,
  21874. ddalfinalarabic: 0xFB89,
  21875. dddhadeva: 0x095C,
  21876. ddhabengali: 0x09A2,
  21877. ddhadeva: 0x0922,
  21878. ddhagujarati: 0x0AA2,
  21879. ddhagurmukhi: 0x0A22,
  21880. ddotaccent: 0x1E0B,
  21881. ddotbelow: 0x1E0D,
  21882. decimalseparatorarabic: 0x066B,
  21883. decimalseparatorpersian: 0x066B,
  21884. decyrillic: 0x0434,
  21885. degree: 0x00B0,
  21886. dehihebrew: 0x05AD,
  21887. dehiragana: 0x3067,
  21888. deicoptic: 0x03EF,
  21889. dekatakana: 0x30C7,
  21890. deleteleft: 0x232B,
  21891. deleteright: 0x2326,
  21892. delta: 0x03B4,
  21893. deltaturned: 0x018D,
  21894. denominatorminusonenumeratorbengali: 0x09F8,
  21895. dezh: 0x02A4,
  21896. dhabengali: 0x09A7,
  21897. dhadeva: 0x0927,
  21898. dhagujarati: 0x0AA7,
  21899. dhagurmukhi: 0x0A27,
  21900. dhook: 0x0257,
  21901. dialytikatonos: 0x0385,
  21902. dialytikatonoscmb: 0x0344,
  21903. diamond: 0x2666,
  21904. diamondsuitwhite: 0x2662,
  21905. dieresis: 0x00A8,
  21906. dieresisacute: 0xF6D7,
  21907. dieresisbelowcmb: 0x0324,
  21908. dieresiscmb: 0x0308,
  21909. dieresisgrave: 0xF6D8,
  21910. dieresistonos: 0x0385,
  21911. dihiragana: 0x3062,
  21912. dikatakana: 0x30C2,
  21913. dittomark: 0x3003,
  21914. divide: 0x00F7,
  21915. divides: 0x2223,
  21916. divisionslash: 0x2215,
  21917. djecyrillic: 0x0452,
  21918. dkshade: 0x2593,
  21919. dlinebelow: 0x1E0F,
  21920. dlsquare: 0x3397,
  21921. dmacron: 0x0111,
  21922. dmonospace: 0xFF44,
  21923. dnblock: 0x2584,
  21924. dochadathai: 0x0E0E,
  21925. dodekthai: 0x0E14,
  21926. dohiragana: 0x3069,
  21927. dokatakana: 0x30C9,
  21928. dollar: 0x0024,
  21929. dollarinferior: 0xF6E3,
  21930. dollarmonospace: 0xFF04,
  21931. dollaroldstyle: 0xF724,
  21932. dollarsmall: 0xFE69,
  21933. dollarsuperior: 0xF6E4,
  21934. dong: 0x20AB,
  21935. dorusquare: 0x3326,
  21936. dotaccent: 0x02D9,
  21937. dotaccentcmb: 0x0307,
  21938. dotbelowcmb: 0x0323,
  21939. dotbelowcomb: 0x0323,
  21940. dotkatakana: 0x30FB,
  21941. dotlessi: 0x0131,
  21942. dotlessj: 0xF6BE,
  21943. dotlessjstrokehook: 0x0284,
  21944. dotmath: 0x22C5,
  21945. dottedcircle: 0x25CC,
  21946. doubleyodpatah: 0xFB1F,
  21947. doubleyodpatahhebrew: 0xFB1F,
  21948. downtackbelowcmb: 0x031E,
  21949. downtackmod: 0x02D5,
  21950. dparen: 0x249F,
  21951. dsuperior: 0xF6EB,
  21952. dtail: 0x0256,
  21953. dtopbar: 0x018C,
  21954. duhiragana: 0x3065,
  21955. dukatakana: 0x30C5,
  21956. dz: 0x01F3,
  21957. dzaltone: 0x02A3,
  21958. dzcaron: 0x01C6,
  21959. dzcurl: 0x02A5,
  21960. dzeabkhasiancyrillic: 0x04E1,
  21961. dzecyrillic: 0x0455,
  21962. dzhecyrillic: 0x045F,
  21963. e: 0x0065,
  21964. eacute: 0x00E9,
  21965. earth: 0x2641,
  21966. ebengali: 0x098F,
  21967. ebopomofo: 0x311C,
  21968. ebreve: 0x0115,
  21969. ecandradeva: 0x090D,
  21970. ecandragujarati: 0x0A8D,
  21971. ecandravowelsigndeva: 0x0945,
  21972. ecandravowelsigngujarati: 0x0AC5,
  21973. ecaron: 0x011B,
  21974. ecedillabreve: 0x1E1D,
  21975. echarmenian: 0x0565,
  21976. echyiwnarmenian: 0x0587,
  21977. ecircle: 0x24D4,
  21978. ecircumflex: 0x00EA,
  21979. ecircumflexacute: 0x1EBF,
  21980. ecircumflexbelow: 0x1E19,
  21981. ecircumflexdotbelow: 0x1EC7,
  21982. ecircumflexgrave: 0x1EC1,
  21983. ecircumflexhookabove: 0x1EC3,
  21984. ecircumflextilde: 0x1EC5,
  21985. ecyrillic: 0x0454,
  21986. edblgrave: 0x0205,
  21987. edeva: 0x090F,
  21988. edieresis: 0x00EB,
  21989. edot: 0x0117,
  21990. edotaccent: 0x0117,
  21991. edotbelow: 0x1EB9,
  21992. eegurmukhi: 0x0A0F,
  21993. eematragurmukhi: 0x0A47,
  21994. efcyrillic: 0x0444,
  21995. egrave: 0x00E8,
  21996. egujarati: 0x0A8F,
  21997. eharmenian: 0x0567,
  21998. ehbopomofo: 0x311D,
  21999. ehiragana: 0x3048,
  22000. ehookabove: 0x1EBB,
  22001. eibopomofo: 0x311F,
  22002. eight: 0x0038,
  22003. eightarabic: 0x0668,
  22004. eightbengali: 0x09EE,
  22005. eightcircle: 0x2467,
  22006. eightcircleinversesansserif: 0x2791,
  22007. eightdeva: 0x096E,
  22008. eighteencircle: 0x2471,
  22009. eighteenparen: 0x2485,
  22010. eighteenperiod: 0x2499,
  22011. eightgujarati: 0x0AEE,
  22012. eightgurmukhi: 0x0A6E,
  22013. eighthackarabic: 0x0668,
  22014. eighthangzhou: 0x3028,
  22015. eighthnotebeamed: 0x266B,
  22016. eightideographicparen: 0x3227,
  22017. eightinferior: 0x2088,
  22018. eightmonospace: 0xFF18,
  22019. eightoldstyle: 0xF738,
  22020. eightparen: 0x247B,
  22021. eightperiod: 0x248F,
  22022. eightpersian: 0x06F8,
  22023. eightroman: 0x2177,
  22024. eightsuperior: 0x2078,
  22025. eightthai: 0x0E58,
  22026. einvertedbreve: 0x0207,
  22027. eiotifiedcyrillic: 0x0465,
  22028. ekatakana: 0x30A8,
  22029. ekatakanahalfwidth: 0xFF74,
  22030. ekonkargurmukhi: 0x0A74,
  22031. ekorean: 0x3154,
  22032. elcyrillic: 0x043B,
  22033. element: 0x2208,
  22034. elevencircle: 0x246A,
  22035. elevenparen: 0x247E,
  22036. elevenperiod: 0x2492,
  22037. elevenroman: 0x217A,
  22038. ellipsis: 0x2026,
  22039. ellipsisvertical: 0x22EE,
  22040. emacron: 0x0113,
  22041. emacronacute: 0x1E17,
  22042. emacrongrave: 0x1E15,
  22043. emcyrillic: 0x043C,
  22044. emdash: 0x2014,
  22045. emdashvertical: 0xFE31,
  22046. emonospace: 0xFF45,
  22047. emphasismarkarmenian: 0x055B,
  22048. emptyset: 0x2205,
  22049. enbopomofo: 0x3123,
  22050. encyrillic: 0x043D,
  22051. endash: 0x2013,
  22052. endashvertical: 0xFE32,
  22053. endescendercyrillic: 0x04A3,
  22054. eng: 0x014B,
  22055. engbopomofo: 0x3125,
  22056. enghecyrillic: 0x04A5,
  22057. enhookcyrillic: 0x04C8,
  22058. enspace: 0x2002,
  22059. eogonek: 0x0119,
  22060. eokorean: 0x3153,
  22061. eopen: 0x025B,
  22062. eopenclosed: 0x029A,
  22063. eopenreversed: 0x025C,
  22064. eopenreversedclosed: 0x025E,
  22065. eopenreversedhook: 0x025D,
  22066. eparen: 0x24A0,
  22067. epsilon: 0x03B5,
  22068. epsilontonos: 0x03AD,
  22069. equal: 0x003D,
  22070. equalmonospace: 0xFF1D,
  22071. equalsmall: 0xFE66,
  22072. equalsuperior: 0x207C,
  22073. equivalence: 0x2261,
  22074. erbopomofo: 0x3126,
  22075. ercyrillic: 0x0440,
  22076. ereversed: 0x0258,
  22077. ereversedcyrillic: 0x044D,
  22078. escyrillic: 0x0441,
  22079. esdescendercyrillic: 0x04AB,
  22080. esh: 0x0283,
  22081. eshcurl: 0x0286,
  22082. eshortdeva: 0x090E,
  22083. eshortvowelsigndeva: 0x0946,
  22084. eshreversedloop: 0x01AA,
  22085. eshsquatreversed: 0x0285,
  22086. esmallhiragana: 0x3047,
  22087. esmallkatakana: 0x30A7,
  22088. esmallkatakanahalfwidth: 0xFF6A,
  22089. estimated: 0x212E,
  22090. esuperior: 0xF6EC,
  22091. eta: 0x03B7,
  22092. etarmenian: 0x0568,
  22093. etatonos: 0x03AE,
  22094. eth: 0x00F0,
  22095. etilde: 0x1EBD,
  22096. etildebelow: 0x1E1B,
  22097. etnahtafoukhhebrew: 0x0591,
  22098. etnahtafoukhlefthebrew: 0x0591,
  22099. etnahtahebrew: 0x0591,
  22100. etnahtalefthebrew: 0x0591,
  22101. eturned: 0x01DD,
  22102. eukorean: 0x3161,
  22103. euro: 0x20AC,
  22104. evowelsignbengali: 0x09C7,
  22105. evowelsigndeva: 0x0947,
  22106. evowelsigngujarati: 0x0AC7,
  22107. exclam: 0x0021,
  22108. exclamarmenian: 0x055C,
  22109. exclamdbl: 0x203C,
  22110. exclamdown: 0x00A1,
  22111. exclamdownsmall: 0xF7A1,
  22112. exclammonospace: 0xFF01,
  22113. exclamsmall: 0xF721,
  22114. existential: 0x2203,
  22115. ezh: 0x0292,
  22116. ezhcaron: 0x01EF,
  22117. ezhcurl: 0x0293,
  22118. ezhreversed: 0x01B9,
  22119. ezhtail: 0x01BA,
  22120. f: 0x0066,
  22121. fadeva: 0x095E,
  22122. fagurmukhi: 0x0A5E,
  22123. fahrenheit: 0x2109,
  22124. fathaarabic: 0x064E,
  22125. fathalowarabic: 0x064E,
  22126. fathatanarabic: 0x064B,
  22127. fbopomofo: 0x3108,
  22128. fcircle: 0x24D5,
  22129. fdotaccent: 0x1E1F,
  22130. feharabic: 0x0641,
  22131. feharmenian: 0x0586,
  22132. fehfinalarabic: 0xFED2,
  22133. fehinitialarabic: 0xFED3,
  22134. fehmedialarabic: 0xFED4,
  22135. feicoptic: 0x03E5,
  22136. female: 0x2640,
  22137. ff: 0xFB00,
  22138. ffi: 0xFB03,
  22139. ffl: 0xFB04,
  22140. fi: 0xFB01,
  22141. fifteencircle: 0x246E,
  22142. fifteenparen: 0x2482,
  22143. fifteenperiod: 0x2496,
  22144. figuredash: 0x2012,
  22145. filledbox: 0x25A0,
  22146. filledrect: 0x25AC,
  22147. finalkaf: 0x05DA,
  22148. finalkafdagesh: 0xFB3A,
  22149. finalkafdageshhebrew: 0xFB3A,
  22150. finalkafhebrew: 0x05DA,
  22151. finalmem: 0x05DD,
  22152. finalmemhebrew: 0x05DD,
  22153. finalnun: 0x05DF,
  22154. finalnunhebrew: 0x05DF,
  22155. finalpe: 0x05E3,
  22156. finalpehebrew: 0x05E3,
  22157. finaltsadi: 0x05E5,
  22158. finaltsadihebrew: 0x05E5,
  22159. firsttonechinese: 0x02C9,
  22160. fisheye: 0x25C9,
  22161. fitacyrillic: 0x0473,
  22162. five: 0x0035,
  22163. fivearabic: 0x0665,
  22164. fivebengali: 0x09EB,
  22165. fivecircle: 0x2464,
  22166. fivecircleinversesansserif: 0x278E,
  22167. fivedeva: 0x096B,
  22168. fiveeighths: 0x215D,
  22169. fivegujarati: 0x0AEB,
  22170. fivegurmukhi: 0x0A6B,
  22171. fivehackarabic: 0x0665,
  22172. fivehangzhou: 0x3025,
  22173. fiveideographicparen: 0x3224,
  22174. fiveinferior: 0x2085,
  22175. fivemonospace: 0xFF15,
  22176. fiveoldstyle: 0xF735,
  22177. fiveparen: 0x2478,
  22178. fiveperiod: 0x248C,
  22179. fivepersian: 0x06F5,
  22180. fiveroman: 0x2174,
  22181. fivesuperior: 0x2075,
  22182. fivethai: 0x0E55,
  22183. fl: 0xFB02,
  22184. florin: 0x0192,
  22185. fmonospace: 0xFF46,
  22186. fmsquare: 0x3399,
  22187. fofanthai: 0x0E1F,
  22188. fofathai: 0x0E1D,
  22189. fongmanthai: 0x0E4F,
  22190. forall: 0x2200,
  22191. four: 0x0034,
  22192. fourarabic: 0x0664,
  22193. fourbengali: 0x09EA,
  22194. fourcircle: 0x2463,
  22195. fourcircleinversesansserif: 0x278D,
  22196. fourdeva: 0x096A,
  22197. fourgujarati: 0x0AEA,
  22198. fourgurmukhi: 0x0A6A,
  22199. fourhackarabic: 0x0664,
  22200. fourhangzhou: 0x3024,
  22201. fourideographicparen: 0x3223,
  22202. fourinferior: 0x2084,
  22203. fourmonospace: 0xFF14,
  22204. fournumeratorbengali: 0x09F7,
  22205. fouroldstyle: 0xF734,
  22206. fourparen: 0x2477,
  22207. fourperiod: 0x248B,
  22208. fourpersian: 0x06F4,
  22209. fourroman: 0x2173,
  22210. foursuperior: 0x2074,
  22211. fourteencircle: 0x246D,
  22212. fourteenparen: 0x2481,
  22213. fourteenperiod: 0x2495,
  22214. fourthai: 0x0E54,
  22215. fourthtonechinese: 0x02CB,
  22216. fparen: 0x24A1,
  22217. fraction: 0x2044,
  22218. franc: 0x20A3,
  22219. g: 0x0067,
  22220. gabengali: 0x0997,
  22221. gacute: 0x01F5,
  22222. gadeva: 0x0917,
  22223. gafarabic: 0x06AF,
  22224. gaffinalarabic: 0xFB93,
  22225. gafinitialarabic: 0xFB94,
  22226. gafmedialarabic: 0xFB95,
  22227. gagujarati: 0x0A97,
  22228. gagurmukhi: 0x0A17,
  22229. gahiragana: 0x304C,
  22230. gakatakana: 0x30AC,
  22231. gamma: 0x03B3,
  22232. gammalatinsmall: 0x0263,
  22233. gammasuperior: 0x02E0,
  22234. gangiacoptic: 0x03EB,
  22235. gbopomofo: 0x310D,
  22236. gbreve: 0x011F,
  22237. gcaron: 0x01E7,
  22238. gcedilla: 0x0123,
  22239. gcircle: 0x24D6,
  22240. gcircumflex: 0x011D,
  22241. gcommaaccent: 0x0123,
  22242. gdot: 0x0121,
  22243. gdotaccent: 0x0121,
  22244. gecyrillic: 0x0433,
  22245. gehiragana: 0x3052,
  22246. gekatakana: 0x30B2,
  22247. geometricallyequal: 0x2251,
  22248. gereshaccenthebrew: 0x059C,
  22249. gereshhebrew: 0x05F3,
  22250. gereshmuqdamhebrew: 0x059D,
  22251. germandbls: 0x00DF,
  22252. gershayimaccenthebrew: 0x059E,
  22253. gershayimhebrew: 0x05F4,
  22254. getamark: 0x3013,
  22255. ghabengali: 0x0998,
  22256. ghadarmenian: 0x0572,
  22257. ghadeva: 0x0918,
  22258. ghagujarati: 0x0A98,
  22259. ghagurmukhi: 0x0A18,
  22260. ghainarabic: 0x063A,
  22261. ghainfinalarabic: 0xFECE,
  22262. ghaininitialarabic: 0xFECF,
  22263. ghainmedialarabic: 0xFED0,
  22264. ghemiddlehookcyrillic: 0x0495,
  22265. ghestrokecyrillic: 0x0493,
  22266. gheupturncyrillic: 0x0491,
  22267. ghhadeva: 0x095A,
  22268. ghhagurmukhi: 0x0A5A,
  22269. ghook: 0x0260,
  22270. ghzsquare: 0x3393,
  22271. gihiragana: 0x304E,
  22272. gikatakana: 0x30AE,
  22273. gimarmenian: 0x0563,
  22274. gimel: 0x05D2,
  22275. gimeldagesh: 0xFB32,
  22276. gimeldageshhebrew: 0xFB32,
  22277. gimelhebrew: 0x05D2,
  22278. gjecyrillic: 0x0453,
  22279. glottalinvertedstroke: 0x01BE,
  22280. glottalstop: 0x0294,
  22281. glottalstopinverted: 0x0296,
  22282. glottalstopmod: 0x02C0,
  22283. glottalstopreversed: 0x0295,
  22284. glottalstopreversedmod: 0x02C1,
  22285. glottalstopreversedsuperior: 0x02E4,
  22286. glottalstopstroke: 0x02A1,
  22287. glottalstopstrokereversed: 0x02A2,
  22288. gmacron: 0x1E21,
  22289. gmonospace: 0xFF47,
  22290. gohiragana: 0x3054,
  22291. gokatakana: 0x30B4,
  22292. gparen: 0x24A2,
  22293. gpasquare: 0x33AC,
  22294. gradient: 0x2207,
  22295. grave: 0x0060,
  22296. gravebelowcmb: 0x0316,
  22297. gravecmb: 0x0300,
  22298. gravecomb: 0x0300,
  22299. gravedeva: 0x0953,
  22300. gravelowmod: 0x02CE,
  22301. gravemonospace: 0xFF40,
  22302. gravetonecmb: 0x0340,
  22303. greater: 0x003E,
  22304. greaterequal: 0x2265,
  22305. greaterequalorless: 0x22DB,
  22306. greatermonospace: 0xFF1E,
  22307. greaterorequivalent: 0x2273,
  22308. greaterorless: 0x2277,
  22309. greateroverequal: 0x2267,
  22310. greatersmall: 0xFE65,
  22311. gscript: 0x0261,
  22312. gstroke: 0x01E5,
  22313. guhiragana: 0x3050,
  22314. guillemotleft: 0x00AB,
  22315. guillemotright: 0x00BB,
  22316. guilsinglleft: 0x2039,
  22317. guilsinglright: 0x203A,
  22318. gukatakana: 0x30B0,
  22319. guramusquare: 0x3318,
  22320. gysquare: 0x33C9,
  22321. h: 0x0068,
  22322. haabkhasiancyrillic: 0x04A9,
  22323. haaltonearabic: 0x06C1,
  22324. habengali: 0x09B9,
  22325. hadescendercyrillic: 0x04B3,
  22326. hadeva: 0x0939,
  22327. hagujarati: 0x0AB9,
  22328. hagurmukhi: 0x0A39,
  22329. haharabic: 0x062D,
  22330. hahfinalarabic: 0xFEA2,
  22331. hahinitialarabic: 0xFEA3,
  22332. hahiragana: 0x306F,
  22333. hahmedialarabic: 0xFEA4,
  22334. haitusquare: 0x332A,
  22335. hakatakana: 0x30CF,
  22336. hakatakanahalfwidth: 0xFF8A,
  22337. halantgurmukhi: 0x0A4D,
  22338. hamzaarabic: 0x0621,
  22339. hamzalowarabic: 0x0621,
  22340. hangulfiller: 0x3164,
  22341. hardsigncyrillic: 0x044A,
  22342. harpoonleftbarbup: 0x21BC,
  22343. harpoonrightbarbup: 0x21C0,
  22344. hasquare: 0x33CA,
  22345. hatafpatah: 0x05B2,
  22346. hatafpatah16: 0x05B2,
  22347. hatafpatah23: 0x05B2,
  22348. hatafpatah2f: 0x05B2,
  22349. hatafpatahhebrew: 0x05B2,
  22350. hatafpatahnarrowhebrew: 0x05B2,
  22351. hatafpatahquarterhebrew: 0x05B2,
  22352. hatafpatahwidehebrew: 0x05B2,
  22353. hatafqamats: 0x05B3,
  22354. hatafqamats1b: 0x05B3,
  22355. hatafqamats28: 0x05B3,
  22356. hatafqamats34: 0x05B3,
  22357. hatafqamatshebrew: 0x05B3,
  22358. hatafqamatsnarrowhebrew: 0x05B3,
  22359. hatafqamatsquarterhebrew: 0x05B3,
  22360. hatafqamatswidehebrew: 0x05B3,
  22361. hatafsegol: 0x05B1,
  22362. hatafsegol17: 0x05B1,
  22363. hatafsegol24: 0x05B1,
  22364. hatafsegol30: 0x05B1,
  22365. hatafsegolhebrew: 0x05B1,
  22366. hatafsegolnarrowhebrew: 0x05B1,
  22367. hatafsegolquarterhebrew: 0x05B1,
  22368. hatafsegolwidehebrew: 0x05B1,
  22369. hbar: 0x0127,
  22370. hbopomofo: 0x310F,
  22371. hbrevebelow: 0x1E2B,
  22372. hcedilla: 0x1E29,
  22373. hcircle: 0x24D7,
  22374. hcircumflex: 0x0125,
  22375. hdieresis: 0x1E27,
  22376. hdotaccent: 0x1E23,
  22377. hdotbelow: 0x1E25,
  22378. he: 0x05D4,
  22379. heart: 0x2665,
  22380. heartsuitblack: 0x2665,
  22381. heartsuitwhite: 0x2661,
  22382. hedagesh: 0xFB34,
  22383. hedageshhebrew: 0xFB34,
  22384. hehaltonearabic: 0x06C1,
  22385. heharabic: 0x0647,
  22386. hehebrew: 0x05D4,
  22387. hehfinalaltonearabic: 0xFBA7,
  22388. hehfinalalttwoarabic: 0xFEEA,
  22389. hehfinalarabic: 0xFEEA,
  22390. hehhamzaabovefinalarabic: 0xFBA5,
  22391. hehhamzaaboveisolatedarabic: 0xFBA4,
  22392. hehinitialaltonearabic: 0xFBA8,
  22393. hehinitialarabic: 0xFEEB,
  22394. hehiragana: 0x3078,
  22395. hehmedialaltonearabic: 0xFBA9,
  22396. hehmedialarabic: 0xFEEC,
  22397. heiseierasquare: 0x337B,
  22398. hekatakana: 0x30D8,
  22399. hekatakanahalfwidth: 0xFF8D,
  22400. hekutaarusquare: 0x3336,
  22401. henghook: 0x0267,
  22402. herutusquare: 0x3339,
  22403. het: 0x05D7,
  22404. hethebrew: 0x05D7,
  22405. hhook: 0x0266,
  22406. hhooksuperior: 0x02B1,
  22407. hieuhacirclekorean: 0x327B,
  22408. hieuhaparenkorean: 0x321B,
  22409. hieuhcirclekorean: 0x326D,
  22410. hieuhkorean: 0x314E,
  22411. hieuhparenkorean: 0x320D,
  22412. hihiragana: 0x3072,
  22413. hikatakana: 0x30D2,
  22414. hikatakanahalfwidth: 0xFF8B,
  22415. hiriq: 0x05B4,
  22416. hiriq14: 0x05B4,
  22417. hiriq21: 0x05B4,
  22418. hiriq2d: 0x05B4,
  22419. hiriqhebrew: 0x05B4,
  22420. hiriqnarrowhebrew: 0x05B4,
  22421. hiriqquarterhebrew: 0x05B4,
  22422. hiriqwidehebrew: 0x05B4,
  22423. hlinebelow: 0x1E96,
  22424. hmonospace: 0xFF48,
  22425. hoarmenian: 0x0570,
  22426. hohipthai: 0x0E2B,
  22427. hohiragana: 0x307B,
  22428. hokatakana: 0x30DB,
  22429. hokatakanahalfwidth: 0xFF8E,
  22430. holam: 0x05B9,
  22431. holam19: 0x05B9,
  22432. holam26: 0x05B9,
  22433. holam32: 0x05B9,
  22434. holamhebrew: 0x05B9,
  22435. holamnarrowhebrew: 0x05B9,
  22436. holamquarterhebrew: 0x05B9,
  22437. holamwidehebrew: 0x05B9,
  22438. honokhukthai: 0x0E2E,
  22439. hookabovecomb: 0x0309,
  22440. hookcmb: 0x0309,
  22441. hookpalatalizedbelowcmb: 0x0321,
  22442. hookretroflexbelowcmb: 0x0322,
  22443. hoonsquare: 0x3342,
  22444. horicoptic: 0x03E9,
  22445. horizontalbar: 0x2015,
  22446. horncmb: 0x031B,
  22447. hotsprings: 0x2668,
  22448. house: 0x2302,
  22449. hparen: 0x24A3,
  22450. hsuperior: 0x02B0,
  22451. hturned: 0x0265,
  22452. huhiragana: 0x3075,
  22453. huiitosquare: 0x3333,
  22454. hukatakana: 0x30D5,
  22455. hukatakanahalfwidth: 0xFF8C,
  22456. hungarumlaut: 0x02DD,
  22457. hungarumlautcmb: 0x030B,
  22458. hv: 0x0195,
  22459. hyphen: 0x002D,
  22460. hypheninferior: 0xF6E5,
  22461. hyphenmonospace: 0xFF0D,
  22462. hyphensmall: 0xFE63,
  22463. hyphensuperior: 0xF6E6,
  22464. hyphentwo: 0x2010,
  22465. i: 0x0069,
  22466. iacute: 0x00ED,
  22467. iacyrillic: 0x044F,
  22468. ibengali: 0x0987,
  22469. ibopomofo: 0x3127,
  22470. ibreve: 0x012D,
  22471. icaron: 0x01D0,
  22472. icircle: 0x24D8,
  22473. icircumflex: 0x00EE,
  22474. icyrillic: 0x0456,
  22475. idblgrave: 0x0209,
  22476. ideographearthcircle: 0x328F,
  22477. ideographfirecircle: 0x328B,
  22478. ideographicallianceparen: 0x323F,
  22479. ideographiccallparen: 0x323A,
  22480. ideographiccentrecircle: 0x32A5,
  22481. ideographicclose: 0x3006,
  22482. ideographiccomma: 0x3001,
  22483. ideographiccommaleft: 0xFF64,
  22484. ideographiccongratulationparen: 0x3237,
  22485. ideographiccorrectcircle: 0x32A3,
  22486. ideographicearthparen: 0x322F,
  22487. ideographicenterpriseparen: 0x323D,
  22488. ideographicexcellentcircle: 0x329D,
  22489. ideographicfestivalparen: 0x3240,
  22490. ideographicfinancialcircle: 0x3296,
  22491. ideographicfinancialparen: 0x3236,
  22492. ideographicfireparen: 0x322B,
  22493. ideographichaveparen: 0x3232,
  22494. ideographichighcircle: 0x32A4,
  22495. ideographiciterationmark: 0x3005,
  22496. ideographiclaborcircle: 0x3298,
  22497. ideographiclaborparen: 0x3238,
  22498. ideographicleftcircle: 0x32A7,
  22499. ideographiclowcircle: 0x32A6,
  22500. ideographicmedicinecircle: 0x32A9,
  22501. ideographicmetalparen: 0x322E,
  22502. ideographicmoonparen: 0x322A,
  22503. ideographicnameparen: 0x3234,
  22504. ideographicperiod: 0x3002,
  22505. ideographicprintcircle: 0x329E,
  22506. ideographicreachparen: 0x3243,
  22507. ideographicrepresentparen: 0x3239,
  22508. ideographicresourceparen: 0x323E,
  22509. ideographicrightcircle: 0x32A8,
  22510. ideographicsecretcircle: 0x3299,
  22511. ideographicselfparen: 0x3242,
  22512. ideographicsocietyparen: 0x3233,
  22513. ideographicspace: 0x3000,
  22514. ideographicspecialparen: 0x3235,
  22515. ideographicstockparen: 0x3231,
  22516. ideographicstudyparen: 0x323B,
  22517. ideographicsunparen: 0x3230,
  22518. ideographicsuperviseparen: 0x323C,
  22519. ideographicwaterparen: 0x322C,
  22520. ideographicwoodparen: 0x322D,
  22521. ideographiczero: 0x3007,
  22522. ideographmetalcircle: 0x328E,
  22523. ideographmooncircle: 0x328A,
  22524. ideographnamecircle: 0x3294,
  22525. ideographsuncircle: 0x3290,
  22526. ideographwatercircle: 0x328C,
  22527. ideographwoodcircle: 0x328D,
  22528. ideva: 0x0907,
  22529. idieresis: 0x00EF,
  22530. idieresisacute: 0x1E2F,
  22531. idieresiscyrillic: 0x04E5,
  22532. idotbelow: 0x1ECB,
  22533. iebrevecyrillic: 0x04D7,
  22534. iecyrillic: 0x0435,
  22535. ieungacirclekorean: 0x3275,
  22536. ieungaparenkorean: 0x3215,
  22537. ieungcirclekorean: 0x3267,
  22538. ieungkorean: 0x3147,
  22539. ieungparenkorean: 0x3207,
  22540. igrave: 0x00EC,
  22541. igujarati: 0x0A87,
  22542. igurmukhi: 0x0A07,
  22543. ihiragana: 0x3044,
  22544. ihookabove: 0x1EC9,
  22545. iibengali: 0x0988,
  22546. iicyrillic: 0x0438,
  22547. iideva: 0x0908,
  22548. iigujarati: 0x0A88,
  22549. iigurmukhi: 0x0A08,
  22550. iimatragurmukhi: 0x0A40,
  22551. iinvertedbreve: 0x020B,
  22552. iishortcyrillic: 0x0439,
  22553. iivowelsignbengali: 0x09C0,
  22554. iivowelsigndeva: 0x0940,
  22555. iivowelsigngujarati: 0x0AC0,
  22556. ij: 0x0133,
  22557. ikatakana: 0x30A4,
  22558. ikatakanahalfwidth: 0xFF72,
  22559. ikorean: 0x3163,
  22560. ilde: 0x02DC,
  22561. iluyhebrew: 0x05AC,
  22562. imacron: 0x012B,
  22563. imacroncyrillic: 0x04E3,
  22564. imageorapproximatelyequal: 0x2253,
  22565. imatragurmukhi: 0x0A3F,
  22566. imonospace: 0xFF49,
  22567. increment: 0x2206,
  22568. infinity: 0x221E,
  22569. iniarmenian: 0x056B,
  22570. integral: 0x222B,
  22571. integralbottom: 0x2321,
  22572. integralbt: 0x2321,
  22573. integralex: 0xF8F5,
  22574. integraltop: 0x2320,
  22575. integraltp: 0x2320,
  22576. intersection: 0x2229,
  22577. intisquare: 0x3305,
  22578. invbullet: 0x25D8,
  22579. invcircle: 0x25D9,
  22580. invsmileface: 0x263B,
  22581. iocyrillic: 0x0451,
  22582. iogonek: 0x012F,
  22583. iota: 0x03B9,
  22584. iotadieresis: 0x03CA,
  22585. iotadieresistonos: 0x0390,
  22586. iotalatin: 0x0269,
  22587. iotatonos: 0x03AF,
  22588. iparen: 0x24A4,
  22589. irigurmukhi: 0x0A72,
  22590. ismallhiragana: 0x3043,
  22591. ismallkatakana: 0x30A3,
  22592. ismallkatakanahalfwidth: 0xFF68,
  22593. issharbengali: 0x09FA,
  22594. istroke: 0x0268,
  22595. isuperior: 0xF6ED,
  22596. iterationhiragana: 0x309D,
  22597. iterationkatakana: 0x30FD,
  22598. itilde: 0x0129,
  22599. itildebelow: 0x1E2D,
  22600. iubopomofo: 0x3129,
  22601. iucyrillic: 0x044E,
  22602. ivowelsignbengali: 0x09BF,
  22603. ivowelsigndeva: 0x093F,
  22604. ivowelsigngujarati: 0x0ABF,
  22605. izhitsacyrillic: 0x0475,
  22606. izhitsadblgravecyrillic: 0x0477,
  22607. j: 0x006A,
  22608. jaarmenian: 0x0571,
  22609. jabengali: 0x099C,
  22610. jadeva: 0x091C,
  22611. jagujarati: 0x0A9C,
  22612. jagurmukhi: 0x0A1C,
  22613. jbopomofo: 0x3110,
  22614. jcaron: 0x01F0,
  22615. jcircle: 0x24D9,
  22616. jcircumflex: 0x0135,
  22617. jcrossedtail: 0x029D,
  22618. jdotlessstroke: 0x025F,
  22619. jecyrillic: 0x0458,
  22620. jeemarabic: 0x062C,
  22621. jeemfinalarabic: 0xFE9E,
  22622. jeeminitialarabic: 0xFE9F,
  22623. jeemmedialarabic: 0xFEA0,
  22624. jeharabic: 0x0698,
  22625. jehfinalarabic: 0xFB8B,
  22626. jhabengali: 0x099D,
  22627. jhadeva: 0x091D,
  22628. jhagujarati: 0x0A9D,
  22629. jhagurmukhi: 0x0A1D,
  22630. jheharmenian: 0x057B,
  22631. jis: 0x3004,
  22632. jmonospace: 0xFF4A,
  22633. jparen: 0x24A5,
  22634. jsuperior: 0x02B2,
  22635. k: 0x006B,
  22636. kabashkircyrillic: 0x04A1,
  22637. kabengali: 0x0995,
  22638. kacute: 0x1E31,
  22639. kacyrillic: 0x043A,
  22640. kadescendercyrillic: 0x049B,
  22641. kadeva: 0x0915,
  22642. kaf: 0x05DB,
  22643. kafarabic: 0x0643,
  22644. kafdagesh: 0xFB3B,
  22645. kafdageshhebrew: 0xFB3B,
  22646. kaffinalarabic: 0xFEDA,
  22647. kafhebrew: 0x05DB,
  22648. kafinitialarabic: 0xFEDB,
  22649. kafmedialarabic: 0xFEDC,
  22650. kafrafehebrew: 0xFB4D,
  22651. kagujarati: 0x0A95,
  22652. kagurmukhi: 0x0A15,
  22653. kahiragana: 0x304B,
  22654. kahookcyrillic: 0x04C4,
  22655. kakatakana: 0x30AB,
  22656. kakatakanahalfwidth: 0xFF76,
  22657. kappa: 0x03BA,
  22658. kappasymbolgreek: 0x03F0,
  22659. kapyeounmieumkorean: 0x3171,
  22660. kapyeounphieuphkorean: 0x3184,
  22661. kapyeounpieupkorean: 0x3178,
  22662. kapyeounssangpieupkorean: 0x3179,
  22663. karoriisquare: 0x330D,
  22664. kashidaautoarabic: 0x0640,
  22665. kashidaautonosidebearingarabic: 0x0640,
  22666. kasmallkatakana: 0x30F5,
  22667. kasquare: 0x3384,
  22668. kasraarabic: 0x0650,
  22669. kasratanarabic: 0x064D,
  22670. kastrokecyrillic: 0x049F,
  22671. katahiraprolongmarkhalfwidth: 0xFF70,
  22672. kaverticalstrokecyrillic: 0x049D,
  22673. kbopomofo: 0x310E,
  22674. kcalsquare: 0x3389,
  22675. kcaron: 0x01E9,
  22676. kcedilla: 0x0137,
  22677. kcircle: 0x24DA,
  22678. kcommaaccent: 0x0137,
  22679. kdotbelow: 0x1E33,
  22680. keharmenian: 0x0584,
  22681. kehiragana: 0x3051,
  22682. kekatakana: 0x30B1,
  22683. kekatakanahalfwidth: 0xFF79,
  22684. kenarmenian: 0x056F,
  22685. kesmallkatakana: 0x30F6,
  22686. kgreenlandic: 0x0138,
  22687. khabengali: 0x0996,
  22688. khacyrillic: 0x0445,
  22689. khadeva: 0x0916,
  22690. khagujarati: 0x0A96,
  22691. khagurmukhi: 0x0A16,
  22692. khaharabic: 0x062E,
  22693. khahfinalarabic: 0xFEA6,
  22694. khahinitialarabic: 0xFEA7,
  22695. khahmedialarabic: 0xFEA8,
  22696. kheicoptic: 0x03E7,
  22697. khhadeva: 0x0959,
  22698. khhagurmukhi: 0x0A59,
  22699. khieukhacirclekorean: 0x3278,
  22700. khieukhaparenkorean: 0x3218,
  22701. khieukhcirclekorean: 0x326A,
  22702. khieukhkorean: 0x314B,
  22703. khieukhparenkorean: 0x320A,
  22704. khokhaithai: 0x0E02,
  22705. khokhonthai: 0x0E05,
  22706. khokhuatthai: 0x0E03,
  22707. khokhwaithai: 0x0E04,
  22708. khomutthai: 0x0E5B,
  22709. khook: 0x0199,
  22710. khorakhangthai: 0x0E06,
  22711. khzsquare: 0x3391,
  22712. kihiragana: 0x304D,
  22713. kikatakana: 0x30AD,
  22714. kikatakanahalfwidth: 0xFF77,
  22715. kiroguramusquare: 0x3315,
  22716. kiromeetorusquare: 0x3316,
  22717. kirosquare: 0x3314,
  22718. kiyeokacirclekorean: 0x326E,
  22719. kiyeokaparenkorean: 0x320E,
  22720. kiyeokcirclekorean: 0x3260,
  22721. kiyeokkorean: 0x3131,
  22722. kiyeokparenkorean: 0x3200,
  22723. kiyeoksioskorean: 0x3133,
  22724. kjecyrillic: 0x045C,
  22725. klinebelow: 0x1E35,
  22726. klsquare: 0x3398,
  22727. kmcubedsquare: 0x33A6,
  22728. kmonospace: 0xFF4B,
  22729. kmsquaredsquare: 0x33A2,
  22730. kohiragana: 0x3053,
  22731. kohmsquare: 0x33C0,
  22732. kokaithai: 0x0E01,
  22733. kokatakana: 0x30B3,
  22734. kokatakanahalfwidth: 0xFF7A,
  22735. kooposquare: 0x331E,
  22736. koppacyrillic: 0x0481,
  22737. koreanstandardsymbol: 0x327F,
  22738. koroniscmb: 0x0343,
  22739. kparen: 0x24A6,
  22740. kpasquare: 0x33AA,
  22741. ksicyrillic: 0x046F,
  22742. ktsquare: 0x33CF,
  22743. kturned: 0x029E,
  22744. kuhiragana: 0x304F,
  22745. kukatakana: 0x30AF,
  22746. kukatakanahalfwidth: 0xFF78,
  22747. kvsquare: 0x33B8,
  22748. kwsquare: 0x33BE,
  22749. l: 0x006C,
  22750. labengali: 0x09B2,
  22751. lacute: 0x013A,
  22752. ladeva: 0x0932,
  22753. lagujarati: 0x0AB2,
  22754. lagurmukhi: 0x0A32,
  22755. lakkhangyaothai: 0x0E45,
  22756. lamaleffinalarabic: 0xFEFC,
  22757. lamalefhamzaabovefinalarabic: 0xFEF8,
  22758. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22759. lamalefhamzabelowfinalarabic: 0xFEFA,
  22760. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22761. lamalefisolatedarabic: 0xFEFB,
  22762. lamalefmaddaabovefinalarabic: 0xFEF6,
  22763. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22764. lamarabic: 0x0644,
  22765. lambda: 0x03BB,
  22766. lambdastroke: 0x019B,
  22767. lamed: 0x05DC,
  22768. lameddagesh: 0xFB3C,
  22769. lameddageshhebrew: 0xFB3C,
  22770. lamedhebrew: 0x05DC,
  22771. lamfinalarabic: 0xFEDE,
  22772. lamhahinitialarabic: 0xFCCA,
  22773. laminitialarabic: 0xFEDF,
  22774. lamjeeminitialarabic: 0xFCC9,
  22775. lamkhahinitialarabic: 0xFCCB,
  22776. lamlamhehisolatedarabic: 0xFDF2,
  22777. lammedialarabic: 0xFEE0,
  22778. lammeemhahinitialarabic: 0xFD88,
  22779. lammeeminitialarabic: 0xFCCC,
  22780. largecircle: 0x25EF,
  22781. lbar: 0x019A,
  22782. lbelt: 0x026C,
  22783. lbopomofo: 0x310C,
  22784. lcaron: 0x013E,
  22785. lcedilla: 0x013C,
  22786. lcircle: 0x24DB,
  22787. lcircumflexbelow: 0x1E3D,
  22788. lcommaaccent: 0x013C,
  22789. ldot: 0x0140,
  22790. ldotaccent: 0x0140,
  22791. ldotbelow: 0x1E37,
  22792. ldotbelowmacron: 0x1E39,
  22793. leftangleabovecmb: 0x031A,
  22794. lefttackbelowcmb: 0x0318,
  22795. less: 0x003C,
  22796. lessequal: 0x2264,
  22797. lessequalorgreater: 0x22DA,
  22798. lessmonospace: 0xFF1C,
  22799. lessorequivalent: 0x2272,
  22800. lessorgreater: 0x2276,
  22801. lessoverequal: 0x2266,
  22802. lesssmall: 0xFE64,
  22803. lezh: 0x026E,
  22804. lfblock: 0x258C,
  22805. lhookretroflex: 0x026D,
  22806. lira: 0x20A4,
  22807. liwnarmenian: 0x056C,
  22808. lj: 0x01C9,
  22809. ljecyrillic: 0x0459,
  22810. ll: 0xF6C0,
  22811. lladeva: 0x0933,
  22812. llagujarati: 0x0AB3,
  22813. llinebelow: 0x1E3B,
  22814. llladeva: 0x0934,
  22815. llvocalicbengali: 0x09E1,
  22816. llvocalicdeva: 0x0961,
  22817. llvocalicvowelsignbengali: 0x09E3,
  22818. llvocalicvowelsigndeva: 0x0963,
  22819. lmiddletilde: 0x026B,
  22820. lmonospace: 0xFF4C,
  22821. lmsquare: 0x33D0,
  22822. lochulathai: 0x0E2C,
  22823. logicaland: 0x2227,
  22824. logicalnot: 0x00AC,
  22825. logicalnotreversed: 0x2310,
  22826. logicalor: 0x2228,
  22827. lolingthai: 0x0E25,
  22828. longs: 0x017F,
  22829. lowlinecenterline: 0xFE4E,
  22830. lowlinecmb: 0x0332,
  22831. lowlinedashed: 0xFE4D,
  22832. lozenge: 0x25CA,
  22833. lparen: 0x24A7,
  22834. lslash: 0x0142,
  22835. lsquare: 0x2113,
  22836. lsuperior: 0xF6EE,
  22837. ltshade: 0x2591,
  22838. luthai: 0x0E26,
  22839. lvocalicbengali: 0x098C,
  22840. lvocalicdeva: 0x090C,
  22841. lvocalicvowelsignbengali: 0x09E2,
  22842. lvocalicvowelsigndeva: 0x0962,
  22843. lxsquare: 0x33D3,
  22844. m: 0x006D,
  22845. mabengali: 0x09AE,
  22846. macron: 0x00AF,
  22847. macronbelowcmb: 0x0331,
  22848. macroncmb: 0x0304,
  22849. macronlowmod: 0x02CD,
  22850. macronmonospace: 0xFFE3,
  22851. macute: 0x1E3F,
  22852. madeva: 0x092E,
  22853. magujarati: 0x0AAE,
  22854. magurmukhi: 0x0A2E,
  22855. mahapakhhebrew: 0x05A4,
  22856. mahapakhlefthebrew: 0x05A4,
  22857. mahiragana: 0x307E,
  22858. maichattawalowleftthai: 0xF895,
  22859. maichattawalowrightthai: 0xF894,
  22860. maichattawathai: 0x0E4B,
  22861. maichattawaupperleftthai: 0xF893,
  22862. maieklowleftthai: 0xF88C,
  22863. maieklowrightthai: 0xF88B,
  22864. maiekthai: 0x0E48,
  22865. maiekupperleftthai: 0xF88A,
  22866. maihanakatleftthai: 0xF884,
  22867. maihanakatthai: 0x0E31,
  22868. maitaikhuleftthai: 0xF889,
  22869. maitaikhuthai: 0x0E47,
  22870. maitholowleftthai: 0xF88F,
  22871. maitholowrightthai: 0xF88E,
  22872. maithothai: 0x0E49,
  22873. maithoupperleftthai: 0xF88D,
  22874. maitrilowleftthai: 0xF892,
  22875. maitrilowrightthai: 0xF891,
  22876. maitrithai: 0x0E4A,
  22877. maitriupperleftthai: 0xF890,
  22878. maiyamokthai: 0x0E46,
  22879. makatakana: 0x30DE,
  22880. makatakanahalfwidth: 0xFF8F,
  22881. male: 0x2642,
  22882. mansyonsquare: 0x3347,
  22883. maqafhebrew: 0x05BE,
  22884. mars: 0x2642,
  22885. masoracirclehebrew: 0x05AF,
  22886. masquare: 0x3383,
  22887. mbopomofo: 0x3107,
  22888. mbsquare: 0x33D4,
  22889. mcircle: 0x24DC,
  22890. mcubedsquare: 0x33A5,
  22891. mdotaccent: 0x1E41,
  22892. mdotbelow: 0x1E43,
  22893. meemarabic: 0x0645,
  22894. meemfinalarabic: 0xFEE2,
  22895. meeminitialarabic: 0xFEE3,
  22896. meemmedialarabic: 0xFEE4,
  22897. meemmeeminitialarabic: 0xFCD1,
  22898. meemmeemisolatedarabic: 0xFC48,
  22899. meetorusquare: 0x334D,
  22900. mehiragana: 0x3081,
  22901. meizierasquare: 0x337E,
  22902. mekatakana: 0x30E1,
  22903. mekatakanahalfwidth: 0xFF92,
  22904. mem: 0x05DE,
  22905. memdagesh: 0xFB3E,
  22906. memdageshhebrew: 0xFB3E,
  22907. memhebrew: 0x05DE,
  22908. menarmenian: 0x0574,
  22909. merkhahebrew: 0x05A5,
  22910. merkhakefulahebrew: 0x05A6,
  22911. merkhakefulalefthebrew: 0x05A6,
  22912. merkhalefthebrew: 0x05A5,
  22913. mhook: 0x0271,
  22914. mhzsquare: 0x3392,
  22915. middledotkatakanahalfwidth: 0xFF65,
  22916. middot: 0x00B7,
  22917. mieumacirclekorean: 0x3272,
  22918. mieumaparenkorean: 0x3212,
  22919. mieumcirclekorean: 0x3264,
  22920. mieumkorean: 0x3141,
  22921. mieumpansioskorean: 0x3170,
  22922. mieumparenkorean: 0x3204,
  22923. mieumpieupkorean: 0x316E,
  22924. mieumsioskorean: 0x316F,
  22925. mihiragana: 0x307F,
  22926. mikatakana: 0x30DF,
  22927. mikatakanahalfwidth: 0xFF90,
  22928. minus: 0x2212,
  22929. minusbelowcmb: 0x0320,
  22930. minuscircle: 0x2296,
  22931. minusmod: 0x02D7,
  22932. minusplus: 0x2213,
  22933. minute: 0x2032,
  22934. miribaarusquare: 0x334A,
  22935. mirisquare: 0x3349,
  22936. mlonglegturned: 0x0270,
  22937. mlsquare: 0x3396,
  22938. mmcubedsquare: 0x33A3,
  22939. mmonospace: 0xFF4D,
  22940. mmsquaredsquare: 0x339F,
  22941. mohiragana: 0x3082,
  22942. mohmsquare: 0x33C1,
  22943. mokatakana: 0x30E2,
  22944. mokatakanahalfwidth: 0xFF93,
  22945. molsquare: 0x33D6,
  22946. momathai: 0x0E21,
  22947. moverssquare: 0x33A7,
  22948. moverssquaredsquare: 0x33A8,
  22949. mparen: 0x24A8,
  22950. mpasquare: 0x33AB,
  22951. mssquare: 0x33B3,
  22952. msuperior: 0xF6EF,
  22953. mturned: 0x026F,
  22954. mu: 0x00B5,
  22955. mu1: 0x00B5,
  22956. muasquare: 0x3382,
  22957. muchgreater: 0x226B,
  22958. muchless: 0x226A,
  22959. mufsquare: 0x338C,
  22960. mugreek: 0x03BC,
  22961. mugsquare: 0x338D,
  22962. muhiragana: 0x3080,
  22963. mukatakana: 0x30E0,
  22964. mukatakanahalfwidth: 0xFF91,
  22965. mulsquare: 0x3395,
  22966. multiply: 0x00D7,
  22967. mumsquare: 0x339B,
  22968. munahhebrew: 0x05A3,
  22969. munahlefthebrew: 0x05A3,
  22970. musicalnote: 0x266A,
  22971. musicalnotedbl: 0x266B,
  22972. musicflatsign: 0x266D,
  22973. musicsharpsign: 0x266F,
  22974. mussquare: 0x33B2,
  22975. muvsquare: 0x33B6,
  22976. muwsquare: 0x33BC,
  22977. mvmegasquare: 0x33B9,
  22978. mvsquare: 0x33B7,
  22979. mwmegasquare: 0x33BF,
  22980. mwsquare: 0x33BD,
  22981. n: 0x006E,
  22982. nabengali: 0x09A8,
  22983. nabla: 0x2207,
  22984. nacute: 0x0144,
  22985. nadeva: 0x0928,
  22986. nagujarati: 0x0AA8,
  22987. nagurmukhi: 0x0A28,
  22988. nahiragana: 0x306A,
  22989. nakatakana: 0x30CA,
  22990. nakatakanahalfwidth: 0xFF85,
  22991. napostrophe: 0x0149,
  22992. nasquare: 0x3381,
  22993. nbopomofo: 0x310B,
  22994. nbspace: 0x00A0,
  22995. ncaron: 0x0148,
  22996. ncedilla: 0x0146,
  22997. ncircle: 0x24DD,
  22998. ncircumflexbelow: 0x1E4B,
  22999. ncommaaccent: 0x0146,
  23000. ndotaccent: 0x1E45,
  23001. ndotbelow: 0x1E47,
  23002. nehiragana: 0x306D,
  23003. nekatakana: 0x30CD,
  23004. nekatakanahalfwidth: 0xFF88,
  23005. newsheqelsign: 0x20AA,
  23006. nfsquare: 0x338B,
  23007. ngabengali: 0x0999,
  23008. ngadeva: 0x0919,
  23009. ngagujarati: 0x0A99,
  23010. ngagurmukhi: 0x0A19,
  23011. ngonguthai: 0x0E07,
  23012. nhiragana: 0x3093,
  23013. nhookleft: 0x0272,
  23014. nhookretroflex: 0x0273,
  23015. nieunacirclekorean: 0x326F,
  23016. nieunaparenkorean: 0x320F,
  23017. nieuncieuckorean: 0x3135,
  23018. nieuncirclekorean: 0x3261,
  23019. nieunhieuhkorean: 0x3136,
  23020. nieunkorean: 0x3134,
  23021. nieunpansioskorean: 0x3168,
  23022. nieunparenkorean: 0x3201,
  23023. nieunsioskorean: 0x3167,
  23024. nieuntikeutkorean: 0x3166,
  23025. nihiragana: 0x306B,
  23026. nikatakana: 0x30CB,
  23027. nikatakanahalfwidth: 0xFF86,
  23028. nikhahitleftthai: 0xF899,
  23029. nikhahitthai: 0x0E4D,
  23030. nine: 0x0039,
  23031. ninearabic: 0x0669,
  23032. ninebengali: 0x09EF,
  23033. ninecircle: 0x2468,
  23034. ninecircleinversesansserif: 0x2792,
  23035. ninedeva: 0x096F,
  23036. ninegujarati: 0x0AEF,
  23037. ninegurmukhi: 0x0A6F,
  23038. ninehackarabic: 0x0669,
  23039. ninehangzhou: 0x3029,
  23040. nineideographicparen: 0x3228,
  23041. nineinferior: 0x2089,
  23042. ninemonospace: 0xFF19,
  23043. nineoldstyle: 0xF739,
  23044. nineparen: 0x247C,
  23045. nineperiod: 0x2490,
  23046. ninepersian: 0x06F9,
  23047. nineroman: 0x2178,
  23048. ninesuperior: 0x2079,
  23049. nineteencircle: 0x2472,
  23050. nineteenparen: 0x2486,
  23051. nineteenperiod: 0x249A,
  23052. ninethai: 0x0E59,
  23053. nj: 0x01CC,
  23054. njecyrillic: 0x045A,
  23055. nkatakana: 0x30F3,
  23056. nkatakanahalfwidth: 0xFF9D,
  23057. nlegrightlong: 0x019E,
  23058. nlinebelow: 0x1E49,
  23059. nmonospace: 0xFF4E,
  23060. nmsquare: 0x339A,
  23061. nnabengali: 0x09A3,
  23062. nnadeva: 0x0923,
  23063. nnagujarati: 0x0AA3,
  23064. nnagurmukhi: 0x0A23,
  23065. nnnadeva: 0x0929,
  23066. nohiragana: 0x306E,
  23067. nokatakana: 0x30CE,
  23068. nokatakanahalfwidth: 0xFF89,
  23069. nonbreakingspace: 0x00A0,
  23070. nonenthai: 0x0E13,
  23071. nonuthai: 0x0E19,
  23072. noonarabic: 0x0646,
  23073. noonfinalarabic: 0xFEE6,
  23074. noonghunnaarabic: 0x06BA,
  23075. noonghunnafinalarabic: 0xFB9F,
  23076. nooninitialarabic: 0xFEE7,
  23077. noonjeeminitialarabic: 0xFCD2,
  23078. noonjeemisolatedarabic: 0xFC4B,
  23079. noonmedialarabic: 0xFEE8,
  23080. noonmeeminitialarabic: 0xFCD5,
  23081. noonmeemisolatedarabic: 0xFC4E,
  23082. noonnoonfinalarabic: 0xFC8D,
  23083. notcontains: 0x220C,
  23084. notelement: 0x2209,
  23085. notelementof: 0x2209,
  23086. notequal: 0x2260,
  23087. notgreater: 0x226F,
  23088. notgreaternorequal: 0x2271,
  23089. notgreaternorless: 0x2279,
  23090. notidentical: 0x2262,
  23091. notless: 0x226E,
  23092. notlessnorequal: 0x2270,
  23093. notparallel: 0x2226,
  23094. notprecedes: 0x2280,
  23095. notsubset: 0x2284,
  23096. notsucceeds: 0x2281,
  23097. notsuperset: 0x2285,
  23098. nowarmenian: 0x0576,
  23099. nparen: 0x24A9,
  23100. nssquare: 0x33B1,
  23101. nsuperior: 0x207F,
  23102. ntilde: 0x00F1,
  23103. nu: 0x03BD,
  23104. nuhiragana: 0x306C,
  23105. nukatakana: 0x30CC,
  23106. nukatakanahalfwidth: 0xFF87,
  23107. nuktabengali: 0x09BC,
  23108. nuktadeva: 0x093C,
  23109. nuktagujarati: 0x0ABC,
  23110. nuktagurmukhi: 0x0A3C,
  23111. numbersign: 0x0023,
  23112. numbersignmonospace: 0xFF03,
  23113. numbersignsmall: 0xFE5F,
  23114. numeralsigngreek: 0x0374,
  23115. numeralsignlowergreek: 0x0375,
  23116. numero: 0x2116,
  23117. nun: 0x05E0,
  23118. nundagesh: 0xFB40,
  23119. nundageshhebrew: 0xFB40,
  23120. nunhebrew: 0x05E0,
  23121. nvsquare: 0x33B5,
  23122. nwsquare: 0x33BB,
  23123. nyabengali: 0x099E,
  23124. nyadeva: 0x091E,
  23125. nyagujarati: 0x0A9E,
  23126. nyagurmukhi: 0x0A1E,
  23127. o: 0x006F,
  23128. oacute: 0x00F3,
  23129. oangthai: 0x0E2D,
  23130. obarred: 0x0275,
  23131. obarredcyrillic: 0x04E9,
  23132. obarreddieresiscyrillic: 0x04EB,
  23133. obengali: 0x0993,
  23134. obopomofo: 0x311B,
  23135. obreve: 0x014F,
  23136. ocandradeva: 0x0911,
  23137. ocandragujarati: 0x0A91,
  23138. ocandravowelsigndeva: 0x0949,
  23139. ocandravowelsigngujarati: 0x0AC9,
  23140. ocaron: 0x01D2,
  23141. ocircle: 0x24DE,
  23142. ocircumflex: 0x00F4,
  23143. ocircumflexacute: 0x1ED1,
  23144. ocircumflexdotbelow: 0x1ED9,
  23145. ocircumflexgrave: 0x1ED3,
  23146. ocircumflexhookabove: 0x1ED5,
  23147. ocircumflextilde: 0x1ED7,
  23148. ocyrillic: 0x043E,
  23149. odblacute: 0x0151,
  23150. odblgrave: 0x020D,
  23151. odeva: 0x0913,
  23152. odieresis: 0x00F6,
  23153. odieresiscyrillic: 0x04E7,
  23154. odotbelow: 0x1ECD,
  23155. oe: 0x0153,
  23156. oekorean: 0x315A,
  23157. ogonek: 0x02DB,
  23158. ogonekcmb: 0x0328,
  23159. ograve: 0x00F2,
  23160. ogujarati: 0x0A93,
  23161. oharmenian: 0x0585,
  23162. ohiragana: 0x304A,
  23163. ohookabove: 0x1ECF,
  23164. ohorn: 0x01A1,
  23165. ohornacute: 0x1EDB,
  23166. ohorndotbelow: 0x1EE3,
  23167. ohorngrave: 0x1EDD,
  23168. ohornhookabove: 0x1EDF,
  23169. ohorntilde: 0x1EE1,
  23170. ohungarumlaut: 0x0151,
  23171. oi: 0x01A3,
  23172. oinvertedbreve: 0x020F,
  23173. okatakana: 0x30AA,
  23174. okatakanahalfwidth: 0xFF75,
  23175. okorean: 0x3157,
  23176. olehebrew: 0x05AB,
  23177. omacron: 0x014D,
  23178. omacronacute: 0x1E53,
  23179. omacrongrave: 0x1E51,
  23180. omdeva: 0x0950,
  23181. omega: 0x03C9,
  23182. omega1: 0x03D6,
  23183. omegacyrillic: 0x0461,
  23184. omegalatinclosed: 0x0277,
  23185. omegaroundcyrillic: 0x047B,
  23186. omegatitlocyrillic: 0x047D,
  23187. omegatonos: 0x03CE,
  23188. omgujarati: 0x0AD0,
  23189. omicron: 0x03BF,
  23190. omicrontonos: 0x03CC,
  23191. omonospace: 0xFF4F,
  23192. one: 0x0031,
  23193. onearabic: 0x0661,
  23194. onebengali: 0x09E7,
  23195. onecircle: 0x2460,
  23196. onecircleinversesansserif: 0x278A,
  23197. onedeva: 0x0967,
  23198. onedotenleader: 0x2024,
  23199. oneeighth: 0x215B,
  23200. onefitted: 0xF6DC,
  23201. onegujarati: 0x0AE7,
  23202. onegurmukhi: 0x0A67,
  23203. onehackarabic: 0x0661,
  23204. onehalf: 0x00BD,
  23205. onehangzhou: 0x3021,
  23206. oneideographicparen: 0x3220,
  23207. oneinferior: 0x2081,
  23208. onemonospace: 0xFF11,
  23209. onenumeratorbengali: 0x09F4,
  23210. oneoldstyle: 0xF731,
  23211. oneparen: 0x2474,
  23212. oneperiod: 0x2488,
  23213. onepersian: 0x06F1,
  23214. onequarter: 0x00BC,
  23215. oneroman: 0x2170,
  23216. onesuperior: 0x00B9,
  23217. onethai: 0x0E51,
  23218. onethird: 0x2153,
  23219. oogonek: 0x01EB,
  23220. oogonekmacron: 0x01ED,
  23221. oogurmukhi: 0x0A13,
  23222. oomatragurmukhi: 0x0A4B,
  23223. oopen: 0x0254,
  23224. oparen: 0x24AA,
  23225. openbullet: 0x25E6,
  23226. option: 0x2325,
  23227. ordfeminine: 0x00AA,
  23228. ordmasculine: 0x00BA,
  23229. orthogonal: 0x221F,
  23230. oshortdeva: 0x0912,
  23231. oshortvowelsigndeva: 0x094A,
  23232. oslash: 0x00F8,
  23233. oslashacute: 0x01FF,
  23234. osmallhiragana: 0x3049,
  23235. osmallkatakana: 0x30A9,
  23236. osmallkatakanahalfwidth: 0xFF6B,
  23237. ostrokeacute: 0x01FF,
  23238. osuperior: 0xF6F0,
  23239. otcyrillic: 0x047F,
  23240. otilde: 0x00F5,
  23241. otildeacute: 0x1E4D,
  23242. otildedieresis: 0x1E4F,
  23243. oubopomofo: 0x3121,
  23244. overline: 0x203E,
  23245. overlinecenterline: 0xFE4A,
  23246. overlinecmb: 0x0305,
  23247. overlinedashed: 0xFE49,
  23248. overlinedblwavy: 0xFE4C,
  23249. overlinewavy: 0xFE4B,
  23250. overscore: 0x00AF,
  23251. ovowelsignbengali: 0x09CB,
  23252. ovowelsigndeva: 0x094B,
  23253. ovowelsigngujarati: 0x0ACB,
  23254. p: 0x0070,
  23255. paampssquare: 0x3380,
  23256. paasentosquare: 0x332B,
  23257. pabengali: 0x09AA,
  23258. pacute: 0x1E55,
  23259. padeva: 0x092A,
  23260. pagedown: 0x21DF,
  23261. pageup: 0x21DE,
  23262. pagujarati: 0x0AAA,
  23263. pagurmukhi: 0x0A2A,
  23264. pahiragana: 0x3071,
  23265. paiyannoithai: 0x0E2F,
  23266. pakatakana: 0x30D1,
  23267. palatalizationcyrilliccmb: 0x0484,
  23268. palochkacyrillic: 0x04C0,
  23269. pansioskorean: 0x317F,
  23270. paragraph: 0x00B6,
  23271. parallel: 0x2225,
  23272. parenleft: 0x0028,
  23273. parenleftaltonearabic: 0xFD3E,
  23274. parenleftbt: 0xF8ED,
  23275. parenleftex: 0xF8EC,
  23276. parenleftinferior: 0x208D,
  23277. parenleftmonospace: 0xFF08,
  23278. parenleftsmall: 0xFE59,
  23279. parenleftsuperior: 0x207D,
  23280. parenlefttp: 0xF8EB,
  23281. parenleftvertical: 0xFE35,
  23282. parenright: 0x0029,
  23283. parenrightaltonearabic: 0xFD3F,
  23284. parenrightbt: 0xF8F8,
  23285. parenrightex: 0xF8F7,
  23286. parenrightinferior: 0x208E,
  23287. parenrightmonospace: 0xFF09,
  23288. parenrightsmall: 0xFE5A,
  23289. parenrightsuperior: 0x207E,
  23290. parenrighttp: 0xF8F6,
  23291. parenrightvertical: 0xFE36,
  23292. partialdiff: 0x2202,
  23293. paseqhebrew: 0x05C0,
  23294. pashtahebrew: 0x0599,
  23295. pasquare: 0x33A9,
  23296. patah: 0x05B7,
  23297. patah11: 0x05B7,
  23298. patah1d: 0x05B7,
  23299. patah2a: 0x05B7,
  23300. patahhebrew: 0x05B7,
  23301. patahnarrowhebrew: 0x05B7,
  23302. patahquarterhebrew: 0x05B7,
  23303. patahwidehebrew: 0x05B7,
  23304. pazerhebrew: 0x05A1,
  23305. pbopomofo: 0x3106,
  23306. pcircle: 0x24DF,
  23307. pdotaccent: 0x1E57,
  23308. pe: 0x05E4,
  23309. pecyrillic: 0x043F,
  23310. pedagesh: 0xFB44,
  23311. pedageshhebrew: 0xFB44,
  23312. peezisquare: 0x333B,
  23313. pefinaldageshhebrew: 0xFB43,
  23314. peharabic: 0x067E,
  23315. peharmenian: 0x057A,
  23316. pehebrew: 0x05E4,
  23317. pehfinalarabic: 0xFB57,
  23318. pehinitialarabic: 0xFB58,
  23319. pehiragana: 0x307A,
  23320. pehmedialarabic: 0xFB59,
  23321. pekatakana: 0x30DA,
  23322. pemiddlehookcyrillic: 0x04A7,
  23323. perafehebrew: 0xFB4E,
  23324. percent: 0x0025,
  23325. percentarabic: 0x066A,
  23326. percentmonospace: 0xFF05,
  23327. percentsmall: 0xFE6A,
  23328. period: 0x002E,
  23329. periodarmenian: 0x0589,
  23330. periodcentered: 0x00B7,
  23331. periodhalfwidth: 0xFF61,
  23332. periodinferior: 0xF6E7,
  23333. periodmonospace: 0xFF0E,
  23334. periodsmall: 0xFE52,
  23335. periodsuperior: 0xF6E8,
  23336. perispomenigreekcmb: 0x0342,
  23337. perpendicular: 0x22A5,
  23338. perthousand: 0x2030,
  23339. peseta: 0x20A7,
  23340. pfsquare: 0x338A,
  23341. phabengali: 0x09AB,
  23342. phadeva: 0x092B,
  23343. phagujarati: 0x0AAB,
  23344. phagurmukhi: 0x0A2B,
  23345. phi: 0x03C6,
  23346. phi1: 0x03D5,
  23347. phieuphacirclekorean: 0x327A,
  23348. phieuphaparenkorean: 0x321A,
  23349. phieuphcirclekorean: 0x326C,
  23350. phieuphkorean: 0x314D,
  23351. phieuphparenkorean: 0x320C,
  23352. philatin: 0x0278,
  23353. phinthuthai: 0x0E3A,
  23354. phisymbolgreek: 0x03D5,
  23355. phook: 0x01A5,
  23356. phophanthai: 0x0E1E,
  23357. phophungthai: 0x0E1C,
  23358. phosamphaothai: 0x0E20,
  23359. pi: 0x03C0,
  23360. pieupacirclekorean: 0x3273,
  23361. pieupaparenkorean: 0x3213,
  23362. pieupcieuckorean: 0x3176,
  23363. pieupcirclekorean: 0x3265,
  23364. pieupkiyeokkorean: 0x3172,
  23365. pieupkorean: 0x3142,
  23366. pieupparenkorean: 0x3205,
  23367. pieupsioskiyeokkorean: 0x3174,
  23368. pieupsioskorean: 0x3144,
  23369. pieupsiostikeutkorean: 0x3175,
  23370. pieupthieuthkorean: 0x3177,
  23371. pieuptikeutkorean: 0x3173,
  23372. pihiragana: 0x3074,
  23373. pikatakana: 0x30D4,
  23374. pisymbolgreek: 0x03D6,
  23375. piwrarmenian: 0x0583,
  23376. plus: 0x002B,
  23377. plusbelowcmb: 0x031F,
  23378. pluscircle: 0x2295,
  23379. plusminus: 0x00B1,
  23380. plusmod: 0x02D6,
  23381. plusmonospace: 0xFF0B,
  23382. plussmall: 0xFE62,
  23383. plussuperior: 0x207A,
  23384. pmonospace: 0xFF50,
  23385. pmsquare: 0x33D8,
  23386. pohiragana: 0x307D,
  23387. pointingindexdownwhite: 0x261F,
  23388. pointingindexleftwhite: 0x261C,
  23389. pointingindexrightwhite: 0x261E,
  23390. pointingindexupwhite: 0x261D,
  23391. pokatakana: 0x30DD,
  23392. poplathai: 0x0E1B,
  23393. postalmark: 0x3012,
  23394. postalmarkface: 0x3020,
  23395. pparen: 0x24AB,
  23396. precedes: 0x227A,
  23397. prescription: 0x211E,
  23398. primemod: 0x02B9,
  23399. primereversed: 0x2035,
  23400. product: 0x220F,
  23401. projective: 0x2305,
  23402. prolongedkana: 0x30FC,
  23403. propellor: 0x2318,
  23404. propersubset: 0x2282,
  23405. propersuperset: 0x2283,
  23406. proportion: 0x2237,
  23407. proportional: 0x221D,
  23408. psi: 0x03C8,
  23409. psicyrillic: 0x0471,
  23410. psilipneumatacyrilliccmb: 0x0486,
  23411. pssquare: 0x33B0,
  23412. puhiragana: 0x3077,
  23413. pukatakana: 0x30D7,
  23414. pvsquare: 0x33B4,
  23415. pwsquare: 0x33BA,
  23416. q: 0x0071,
  23417. qadeva: 0x0958,
  23418. qadmahebrew: 0x05A8,
  23419. qafarabic: 0x0642,
  23420. qaffinalarabic: 0xFED6,
  23421. qafinitialarabic: 0xFED7,
  23422. qafmedialarabic: 0xFED8,
  23423. qamats: 0x05B8,
  23424. qamats10: 0x05B8,
  23425. qamats1a: 0x05B8,
  23426. qamats1c: 0x05B8,
  23427. qamats27: 0x05B8,
  23428. qamats29: 0x05B8,
  23429. qamats33: 0x05B8,
  23430. qamatsde: 0x05B8,
  23431. qamatshebrew: 0x05B8,
  23432. qamatsnarrowhebrew: 0x05B8,
  23433. qamatsqatanhebrew: 0x05B8,
  23434. qamatsqatannarrowhebrew: 0x05B8,
  23435. qamatsqatanquarterhebrew: 0x05B8,
  23436. qamatsqatanwidehebrew: 0x05B8,
  23437. qamatsquarterhebrew: 0x05B8,
  23438. qamatswidehebrew: 0x05B8,
  23439. qarneyparahebrew: 0x059F,
  23440. qbopomofo: 0x3111,
  23441. qcircle: 0x24E0,
  23442. qhook: 0x02A0,
  23443. qmonospace: 0xFF51,
  23444. qof: 0x05E7,
  23445. qofdagesh: 0xFB47,
  23446. qofdageshhebrew: 0xFB47,
  23447. qofhebrew: 0x05E7,
  23448. qparen: 0x24AC,
  23449. quarternote: 0x2669,
  23450. qubuts: 0x05BB,
  23451. qubuts18: 0x05BB,
  23452. qubuts25: 0x05BB,
  23453. qubuts31: 0x05BB,
  23454. qubutshebrew: 0x05BB,
  23455. qubutsnarrowhebrew: 0x05BB,
  23456. qubutsquarterhebrew: 0x05BB,
  23457. qubutswidehebrew: 0x05BB,
  23458. question: 0x003F,
  23459. questionarabic: 0x061F,
  23460. questionarmenian: 0x055E,
  23461. questiondown: 0x00BF,
  23462. questiondownsmall: 0xF7BF,
  23463. questiongreek: 0x037E,
  23464. questionmonospace: 0xFF1F,
  23465. questionsmall: 0xF73F,
  23466. quotedbl: 0x0022,
  23467. quotedblbase: 0x201E,
  23468. quotedblleft: 0x201C,
  23469. quotedblmonospace: 0xFF02,
  23470. quotedblprime: 0x301E,
  23471. quotedblprimereversed: 0x301D,
  23472. quotedblright: 0x201D,
  23473. quoteleft: 0x2018,
  23474. quoteleftreversed: 0x201B,
  23475. quotereversed: 0x201B,
  23476. quoteright: 0x2019,
  23477. quoterightn: 0x0149,
  23478. quotesinglbase: 0x201A,
  23479. quotesingle: 0x0027,
  23480. quotesinglemonospace: 0xFF07,
  23481. r: 0x0072,
  23482. raarmenian: 0x057C,
  23483. rabengali: 0x09B0,
  23484. racute: 0x0155,
  23485. radeva: 0x0930,
  23486. radical: 0x221A,
  23487. radicalex: 0xF8E5,
  23488. radoverssquare: 0x33AE,
  23489. radoverssquaredsquare: 0x33AF,
  23490. radsquare: 0x33AD,
  23491. rafe: 0x05BF,
  23492. rafehebrew: 0x05BF,
  23493. ragujarati: 0x0AB0,
  23494. ragurmukhi: 0x0A30,
  23495. rahiragana: 0x3089,
  23496. rakatakana: 0x30E9,
  23497. rakatakanahalfwidth: 0xFF97,
  23498. ralowerdiagonalbengali: 0x09F1,
  23499. ramiddlediagonalbengali: 0x09F0,
  23500. ramshorn: 0x0264,
  23501. ratio: 0x2236,
  23502. rbopomofo: 0x3116,
  23503. rcaron: 0x0159,
  23504. rcedilla: 0x0157,
  23505. rcircle: 0x24E1,
  23506. rcommaaccent: 0x0157,
  23507. rdblgrave: 0x0211,
  23508. rdotaccent: 0x1E59,
  23509. rdotbelow: 0x1E5B,
  23510. rdotbelowmacron: 0x1E5D,
  23511. referencemark: 0x203B,
  23512. reflexsubset: 0x2286,
  23513. reflexsuperset: 0x2287,
  23514. registered: 0x00AE,
  23515. registersans: 0xF8E8,
  23516. registerserif: 0xF6DA,
  23517. reharabic: 0x0631,
  23518. reharmenian: 0x0580,
  23519. rehfinalarabic: 0xFEAE,
  23520. rehiragana: 0x308C,
  23521. rekatakana: 0x30EC,
  23522. rekatakanahalfwidth: 0xFF9A,
  23523. resh: 0x05E8,
  23524. reshdageshhebrew: 0xFB48,
  23525. reshhebrew: 0x05E8,
  23526. reversedtilde: 0x223D,
  23527. reviahebrew: 0x0597,
  23528. reviamugrashhebrew: 0x0597,
  23529. revlogicalnot: 0x2310,
  23530. rfishhook: 0x027E,
  23531. rfishhookreversed: 0x027F,
  23532. rhabengali: 0x09DD,
  23533. rhadeva: 0x095D,
  23534. rho: 0x03C1,
  23535. rhook: 0x027D,
  23536. rhookturned: 0x027B,
  23537. rhookturnedsuperior: 0x02B5,
  23538. rhosymbolgreek: 0x03F1,
  23539. rhotichookmod: 0x02DE,
  23540. rieulacirclekorean: 0x3271,
  23541. rieulaparenkorean: 0x3211,
  23542. rieulcirclekorean: 0x3263,
  23543. rieulhieuhkorean: 0x3140,
  23544. rieulkiyeokkorean: 0x313A,
  23545. rieulkiyeoksioskorean: 0x3169,
  23546. rieulkorean: 0x3139,
  23547. rieulmieumkorean: 0x313B,
  23548. rieulpansioskorean: 0x316C,
  23549. rieulparenkorean: 0x3203,
  23550. rieulphieuphkorean: 0x313F,
  23551. rieulpieupkorean: 0x313C,
  23552. rieulpieupsioskorean: 0x316B,
  23553. rieulsioskorean: 0x313D,
  23554. rieulthieuthkorean: 0x313E,
  23555. rieultikeutkorean: 0x316A,
  23556. rieulyeorinhieuhkorean: 0x316D,
  23557. rightangle: 0x221F,
  23558. righttackbelowcmb: 0x0319,
  23559. righttriangle: 0x22BF,
  23560. rihiragana: 0x308A,
  23561. rikatakana: 0x30EA,
  23562. rikatakanahalfwidth: 0xFF98,
  23563. ring: 0x02DA,
  23564. ringbelowcmb: 0x0325,
  23565. ringcmb: 0x030A,
  23566. ringhalfleft: 0x02BF,
  23567. ringhalfleftarmenian: 0x0559,
  23568. ringhalfleftbelowcmb: 0x031C,
  23569. ringhalfleftcentered: 0x02D3,
  23570. ringhalfright: 0x02BE,
  23571. ringhalfrightbelowcmb: 0x0339,
  23572. ringhalfrightcentered: 0x02D2,
  23573. rinvertedbreve: 0x0213,
  23574. rittorusquare: 0x3351,
  23575. rlinebelow: 0x1E5F,
  23576. rlongleg: 0x027C,
  23577. rlonglegturned: 0x027A,
  23578. rmonospace: 0xFF52,
  23579. rohiragana: 0x308D,
  23580. rokatakana: 0x30ED,
  23581. rokatakanahalfwidth: 0xFF9B,
  23582. roruathai: 0x0E23,
  23583. rparen: 0x24AD,
  23584. rrabengali: 0x09DC,
  23585. rradeva: 0x0931,
  23586. rragurmukhi: 0x0A5C,
  23587. rreharabic: 0x0691,
  23588. rrehfinalarabic: 0xFB8D,
  23589. rrvocalicbengali: 0x09E0,
  23590. rrvocalicdeva: 0x0960,
  23591. rrvocalicgujarati: 0x0AE0,
  23592. rrvocalicvowelsignbengali: 0x09C4,
  23593. rrvocalicvowelsigndeva: 0x0944,
  23594. rrvocalicvowelsigngujarati: 0x0AC4,
  23595. rsuperior: 0xF6F1,
  23596. rtblock: 0x2590,
  23597. rturned: 0x0279,
  23598. rturnedsuperior: 0x02B4,
  23599. ruhiragana: 0x308B,
  23600. rukatakana: 0x30EB,
  23601. rukatakanahalfwidth: 0xFF99,
  23602. rupeemarkbengali: 0x09F2,
  23603. rupeesignbengali: 0x09F3,
  23604. rupiah: 0xF6DD,
  23605. ruthai: 0x0E24,
  23606. rvocalicbengali: 0x098B,
  23607. rvocalicdeva: 0x090B,
  23608. rvocalicgujarati: 0x0A8B,
  23609. rvocalicvowelsignbengali: 0x09C3,
  23610. rvocalicvowelsigndeva: 0x0943,
  23611. rvocalicvowelsigngujarati: 0x0AC3,
  23612. s: 0x0073,
  23613. sabengali: 0x09B8,
  23614. sacute: 0x015B,
  23615. sacutedotaccent: 0x1E65,
  23616. sadarabic: 0x0635,
  23617. sadeva: 0x0938,
  23618. sadfinalarabic: 0xFEBA,
  23619. sadinitialarabic: 0xFEBB,
  23620. sadmedialarabic: 0xFEBC,
  23621. sagujarati: 0x0AB8,
  23622. sagurmukhi: 0x0A38,
  23623. sahiragana: 0x3055,
  23624. sakatakana: 0x30B5,
  23625. sakatakanahalfwidth: 0xFF7B,
  23626. sallallahoualayhewasallamarabic: 0xFDFA,
  23627. samekh: 0x05E1,
  23628. samekhdagesh: 0xFB41,
  23629. samekhdageshhebrew: 0xFB41,
  23630. samekhhebrew: 0x05E1,
  23631. saraaathai: 0x0E32,
  23632. saraaethai: 0x0E41,
  23633. saraaimaimalaithai: 0x0E44,
  23634. saraaimaimuanthai: 0x0E43,
  23635. saraamthai: 0x0E33,
  23636. saraathai: 0x0E30,
  23637. saraethai: 0x0E40,
  23638. saraiileftthai: 0xF886,
  23639. saraiithai: 0x0E35,
  23640. saraileftthai: 0xF885,
  23641. saraithai: 0x0E34,
  23642. saraothai: 0x0E42,
  23643. saraueeleftthai: 0xF888,
  23644. saraueethai: 0x0E37,
  23645. saraueleftthai: 0xF887,
  23646. sarauethai: 0x0E36,
  23647. sarauthai: 0x0E38,
  23648. sarauuthai: 0x0E39,
  23649. sbopomofo: 0x3119,
  23650. scaron: 0x0161,
  23651. scarondotaccent: 0x1E67,
  23652. scedilla: 0x015F,
  23653. schwa: 0x0259,
  23654. schwacyrillic: 0x04D9,
  23655. schwadieresiscyrillic: 0x04DB,
  23656. schwahook: 0x025A,
  23657. scircle: 0x24E2,
  23658. scircumflex: 0x015D,
  23659. scommaaccent: 0x0219,
  23660. sdotaccent: 0x1E61,
  23661. sdotbelow: 0x1E63,
  23662. sdotbelowdotaccent: 0x1E69,
  23663. seagullbelowcmb: 0x033C,
  23664. second: 0x2033,
  23665. secondtonechinese: 0x02CA,
  23666. section: 0x00A7,
  23667. seenarabic: 0x0633,
  23668. seenfinalarabic: 0xFEB2,
  23669. seeninitialarabic: 0xFEB3,
  23670. seenmedialarabic: 0xFEB4,
  23671. segol: 0x05B6,
  23672. segol13: 0x05B6,
  23673. segol1f: 0x05B6,
  23674. segol2c: 0x05B6,
  23675. segolhebrew: 0x05B6,
  23676. segolnarrowhebrew: 0x05B6,
  23677. segolquarterhebrew: 0x05B6,
  23678. segoltahebrew: 0x0592,
  23679. segolwidehebrew: 0x05B6,
  23680. seharmenian: 0x057D,
  23681. sehiragana: 0x305B,
  23682. sekatakana: 0x30BB,
  23683. sekatakanahalfwidth: 0xFF7E,
  23684. semicolon: 0x003B,
  23685. semicolonarabic: 0x061B,
  23686. semicolonmonospace: 0xFF1B,
  23687. semicolonsmall: 0xFE54,
  23688. semivoicedmarkkana: 0x309C,
  23689. semivoicedmarkkanahalfwidth: 0xFF9F,
  23690. sentisquare: 0x3322,
  23691. sentosquare: 0x3323,
  23692. seven: 0x0037,
  23693. sevenarabic: 0x0667,
  23694. sevenbengali: 0x09ED,
  23695. sevencircle: 0x2466,
  23696. sevencircleinversesansserif: 0x2790,
  23697. sevendeva: 0x096D,
  23698. seveneighths: 0x215E,
  23699. sevengujarati: 0x0AED,
  23700. sevengurmukhi: 0x0A6D,
  23701. sevenhackarabic: 0x0667,
  23702. sevenhangzhou: 0x3027,
  23703. sevenideographicparen: 0x3226,
  23704. seveninferior: 0x2087,
  23705. sevenmonospace: 0xFF17,
  23706. sevenoldstyle: 0xF737,
  23707. sevenparen: 0x247A,
  23708. sevenperiod: 0x248E,
  23709. sevenpersian: 0x06F7,
  23710. sevenroman: 0x2176,
  23711. sevensuperior: 0x2077,
  23712. seventeencircle: 0x2470,
  23713. seventeenparen: 0x2484,
  23714. seventeenperiod: 0x2498,
  23715. seventhai: 0x0E57,
  23716. sfthyphen: 0x00AD,
  23717. shaarmenian: 0x0577,
  23718. shabengali: 0x09B6,
  23719. shacyrillic: 0x0448,
  23720. shaddaarabic: 0x0651,
  23721. shaddadammaarabic: 0xFC61,
  23722. shaddadammatanarabic: 0xFC5E,
  23723. shaddafathaarabic: 0xFC60,
  23724. shaddakasraarabic: 0xFC62,
  23725. shaddakasratanarabic: 0xFC5F,
  23726. shade: 0x2592,
  23727. shadedark: 0x2593,
  23728. shadelight: 0x2591,
  23729. shademedium: 0x2592,
  23730. shadeva: 0x0936,
  23731. shagujarati: 0x0AB6,
  23732. shagurmukhi: 0x0A36,
  23733. shalshelethebrew: 0x0593,
  23734. shbopomofo: 0x3115,
  23735. shchacyrillic: 0x0449,
  23736. sheenarabic: 0x0634,
  23737. sheenfinalarabic: 0xFEB6,
  23738. sheeninitialarabic: 0xFEB7,
  23739. sheenmedialarabic: 0xFEB8,
  23740. sheicoptic: 0x03E3,
  23741. sheqel: 0x20AA,
  23742. sheqelhebrew: 0x20AA,
  23743. sheva: 0x05B0,
  23744. sheva115: 0x05B0,
  23745. sheva15: 0x05B0,
  23746. sheva22: 0x05B0,
  23747. sheva2e: 0x05B0,
  23748. shevahebrew: 0x05B0,
  23749. shevanarrowhebrew: 0x05B0,
  23750. shevaquarterhebrew: 0x05B0,
  23751. shevawidehebrew: 0x05B0,
  23752. shhacyrillic: 0x04BB,
  23753. shimacoptic: 0x03ED,
  23754. shin: 0x05E9,
  23755. shindagesh: 0xFB49,
  23756. shindageshhebrew: 0xFB49,
  23757. shindageshshindot: 0xFB2C,
  23758. shindageshshindothebrew: 0xFB2C,
  23759. shindageshsindot: 0xFB2D,
  23760. shindageshsindothebrew: 0xFB2D,
  23761. shindothebrew: 0x05C1,
  23762. shinhebrew: 0x05E9,
  23763. shinshindot: 0xFB2A,
  23764. shinshindothebrew: 0xFB2A,
  23765. shinsindot: 0xFB2B,
  23766. shinsindothebrew: 0xFB2B,
  23767. shook: 0x0282,
  23768. sigma: 0x03C3,
  23769. sigma1: 0x03C2,
  23770. sigmafinal: 0x03C2,
  23771. sigmalunatesymbolgreek: 0x03F2,
  23772. sihiragana: 0x3057,
  23773. sikatakana: 0x30B7,
  23774. sikatakanahalfwidth: 0xFF7C,
  23775. siluqhebrew: 0x05BD,
  23776. siluqlefthebrew: 0x05BD,
  23777. similar: 0x223C,
  23778. sindothebrew: 0x05C2,
  23779. siosacirclekorean: 0x3274,
  23780. siosaparenkorean: 0x3214,
  23781. sioscieuckorean: 0x317E,
  23782. sioscirclekorean: 0x3266,
  23783. sioskiyeokkorean: 0x317A,
  23784. sioskorean: 0x3145,
  23785. siosnieunkorean: 0x317B,
  23786. siosparenkorean: 0x3206,
  23787. siospieupkorean: 0x317D,
  23788. siostikeutkorean: 0x317C,
  23789. six: 0x0036,
  23790. sixarabic: 0x0666,
  23791. sixbengali: 0x09EC,
  23792. sixcircle: 0x2465,
  23793. sixcircleinversesansserif: 0x278F,
  23794. sixdeva: 0x096C,
  23795. sixgujarati: 0x0AEC,
  23796. sixgurmukhi: 0x0A6C,
  23797. sixhackarabic: 0x0666,
  23798. sixhangzhou: 0x3026,
  23799. sixideographicparen: 0x3225,
  23800. sixinferior: 0x2086,
  23801. sixmonospace: 0xFF16,
  23802. sixoldstyle: 0xF736,
  23803. sixparen: 0x2479,
  23804. sixperiod: 0x248D,
  23805. sixpersian: 0x06F6,
  23806. sixroman: 0x2175,
  23807. sixsuperior: 0x2076,
  23808. sixteencircle: 0x246F,
  23809. sixteencurrencydenominatorbengali: 0x09F9,
  23810. sixteenparen: 0x2483,
  23811. sixteenperiod: 0x2497,
  23812. sixthai: 0x0E56,
  23813. slash: 0x002F,
  23814. slashmonospace: 0xFF0F,
  23815. slong: 0x017F,
  23816. slongdotaccent: 0x1E9B,
  23817. smileface: 0x263A,
  23818. smonospace: 0xFF53,
  23819. sofpasuqhebrew: 0x05C3,
  23820. softhyphen: 0x00AD,
  23821. softsigncyrillic: 0x044C,
  23822. sohiragana: 0x305D,
  23823. sokatakana: 0x30BD,
  23824. sokatakanahalfwidth: 0xFF7F,
  23825. soliduslongoverlaycmb: 0x0338,
  23826. solidusshortoverlaycmb: 0x0337,
  23827. sorusithai: 0x0E29,
  23828. sosalathai: 0x0E28,
  23829. sosothai: 0x0E0B,
  23830. sosuathai: 0x0E2A,
  23831. space: 0x0020,
  23832. spacehackarabic: 0x0020,
  23833. spade: 0x2660,
  23834. spadesuitblack: 0x2660,
  23835. spadesuitwhite: 0x2664,
  23836. sparen: 0x24AE,
  23837. squarebelowcmb: 0x033B,
  23838. squarecc: 0x33C4,
  23839. squarecm: 0x339D,
  23840. squarediagonalcrosshatchfill: 0x25A9,
  23841. squarehorizontalfill: 0x25A4,
  23842. squarekg: 0x338F,
  23843. squarekm: 0x339E,
  23844. squarekmcapital: 0x33CE,
  23845. squareln: 0x33D1,
  23846. squarelog: 0x33D2,
  23847. squaremg: 0x338E,
  23848. squaremil: 0x33D5,
  23849. squaremm: 0x339C,
  23850. squaremsquared: 0x33A1,
  23851. squareorthogonalcrosshatchfill: 0x25A6,
  23852. squareupperlefttolowerrightfill: 0x25A7,
  23853. squareupperrighttolowerleftfill: 0x25A8,
  23854. squareverticalfill: 0x25A5,
  23855. squarewhitewithsmallblack: 0x25A3,
  23856. srsquare: 0x33DB,
  23857. ssabengali: 0x09B7,
  23858. ssadeva: 0x0937,
  23859. ssagujarati: 0x0AB7,
  23860. ssangcieuckorean: 0x3149,
  23861. ssanghieuhkorean: 0x3185,
  23862. ssangieungkorean: 0x3180,
  23863. ssangkiyeokkorean: 0x3132,
  23864. ssangnieunkorean: 0x3165,
  23865. ssangpieupkorean: 0x3143,
  23866. ssangsioskorean: 0x3146,
  23867. ssangtikeutkorean: 0x3138,
  23868. ssuperior: 0xF6F2,
  23869. sterling: 0x00A3,
  23870. sterlingmonospace: 0xFFE1,
  23871. strokelongoverlaycmb: 0x0336,
  23872. strokeshortoverlaycmb: 0x0335,
  23873. subset: 0x2282,
  23874. subsetnotequal: 0x228A,
  23875. subsetorequal: 0x2286,
  23876. succeeds: 0x227B,
  23877. suchthat: 0x220B,
  23878. suhiragana: 0x3059,
  23879. sukatakana: 0x30B9,
  23880. sukatakanahalfwidth: 0xFF7D,
  23881. sukunarabic: 0x0652,
  23882. summation: 0x2211,
  23883. sun: 0x263C,
  23884. superset: 0x2283,
  23885. supersetnotequal: 0x228B,
  23886. supersetorequal: 0x2287,
  23887. svsquare: 0x33DC,
  23888. syouwaerasquare: 0x337C,
  23889. t: 0x0074,
  23890. tabengali: 0x09A4,
  23891. tackdown: 0x22A4,
  23892. tackleft: 0x22A3,
  23893. tadeva: 0x0924,
  23894. tagujarati: 0x0AA4,
  23895. tagurmukhi: 0x0A24,
  23896. taharabic: 0x0637,
  23897. tahfinalarabic: 0xFEC2,
  23898. tahinitialarabic: 0xFEC3,
  23899. tahiragana: 0x305F,
  23900. tahmedialarabic: 0xFEC4,
  23901. taisyouerasquare: 0x337D,
  23902. takatakana: 0x30BF,
  23903. takatakanahalfwidth: 0xFF80,
  23904. tatweelarabic: 0x0640,
  23905. tau: 0x03C4,
  23906. tav: 0x05EA,
  23907. tavdages: 0xFB4A,
  23908. tavdagesh: 0xFB4A,
  23909. tavdageshhebrew: 0xFB4A,
  23910. tavhebrew: 0x05EA,
  23911. tbar: 0x0167,
  23912. tbopomofo: 0x310A,
  23913. tcaron: 0x0165,
  23914. tccurl: 0x02A8,
  23915. tcedilla: 0x0163,
  23916. tcheharabic: 0x0686,
  23917. tchehfinalarabic: 0xFB7B,
  23918. tchehinitialarabic: 0xFB7C,
  23919. tchehmedialarabic: 0xFB7D,
  23920. tcircle: 0x24E3,
  23921. tcircumflexbelow: 0x1E71,
  23922. tcommaaccent: 0x0163,
  23923. tdieresis: 0x1E97,
  23924. tdotaccent: 0x1E6B,
  23925. tdotbelow: 0x1E6D,
  23926. tecyrillic: 0x0442,
  23927. tedescendercyrillic: 0x04AD,
  23928. teharabic: 0x062A,
  23929. tehfinalarabic: 0xFE96,
  23930. tehhahinitialarabic: 0xFCA2,
  23931. tehhahisolatedarabic: 0xFC0C,
  23932. tehinitialarabic: 0xFE97,
  23933. tehiragana: 0x3066,
  23934. tehjeeminitialarabic: 0xFCA1,
  23935. tehjeemisolatedarabic: 0xFC0B,
  23936. tehmarbutaarabic: 0x0629,
  23937. tehmarbutafinalarabic: 0xFE94,
  23938. tehmedialarabic: 0xFE98,
  23939. tehmeeminitialarabic: 0xFCA4,
  23940. tehmeemisolatedarabic: 0xFC0E,
  23941. tehnoonfinalarabic: 0xFC73,
  23942. tekatakana: 0x30C6,
  23943. tekatakanahalfwidth: 0xFF83,
  23944. telephone: 0x2121,
  23945. telephoneblack: 0x260E,
  23946. telishagedolahebrew: 0x05A0,
  23947. telishaqetanahebrew: 0x05A9,
  23948. tencircle: 0x2469,
  23949. tenideographicparen: 0x3229,
  23950. tenparen: 0x247D,
  23951. tenperiod: 0x2491,
  23952. tenroman: 0x2179,
  23953. tesh: 0x02A7,
  23954. tet: 0x05D8,
  23955. tetdagesh: 0xFB38,
  23956. tetdageshhebrew: 0xFB38,
  23957. tethebrew: 0x05D8,
  23958. tetsecyrillic: 0x04B5,
  23959. tevirhebrew: 0x059B,
  23960. tevirlefthebrew: 0x059B,
  23961. thabengali: 0x09A5,
  23962. thadeva: 0x0925,
  23963. thagujarati: 0x0AA5,
  23964. thagurmukhi: 0x0A25,
  23965. thalarabic: 0x0630,
  23966. thalfinalarabic: 0xFEAC,
  23967. thanthakhatlowleftthai: 0xF898,
  23968. thanthakhatlowrightthai: 0xF897,
  23969. thanthakhatthai: 0x0E4C,
  23970. thanthakhatupperleftthai: 0xF896,
  23971. theharabic: 0x062B,
  23972. thehfinalarabic: 0xFE9A,
  23973. thehinitialarabic: 0xFE9B,
  23974. thehmedialarabic: 0xFE9C,
  23975. thereexists: 0x2203,
  23976. therefore: 0x2234,
  23977. theta: 0x03B8,
  23978. theta1: 0x03D1,
  23979. thetasymbolgreek: 0x03D1,
  23980. thieuthacirclekorean: 0x3279,
  23981. thieuthaparenkorean: 0x3219,
  23982. thieuthcirclekorean: 0x326B,
  23983. thieuthkorean: 0x314C,
  23984. thieuthparenkorean: 0x320B,
  23985. thirteencircle: 0x246C,
  23986. thirteenparen: 0x2480,
  23987. thirteenperiod: 0x2494,
  23988. thonangmonthothai: 0x0E11,
  23989. thook: 0x01AD,
  23990. thophuthaothai: 0x0E12,
  23991. thorn: 0x00FE,
  23992. thothahanthai: 0x0E17,
  23993. thothanthai: 0x0E10,
  23994. thothongthai: 0x0E18,
  23995. thothungthai: 0x0E16,
  23996. thousandcyrillic: 0x0482,
  23997. thousandsseparatorarabic: 0x066C,
  23998. thousandsseparatorpersian: 0x066C,
  23999. three: 0x0033,
  24000. threearabic: 0x0663,
  24001. threebengali: 0x09E9,
  24002. threecircle: 0x2462,
  24003. threecircleinversesansserif: 0x278C,
  24004. threedeva: 0x0969,
  24005. threeeighths: 0x215C,
  24006. threegujarati: 0x0AE9,
  24007. threegurmukhi: 0x0A69,
  24008. threehackarabic: 0x0663,
  24009. threehangzhou: 0x3023,
  24010. threeideographicparen: 0x3222,
  24011. threeinferior: 0x2083,
  24012. threemonospace: 0xFF13,
  24013. threenumeratorbengali: 0x09F6,
  24014. threeoldstyle: 0xF733,
  24015. threeparen: 0x2476,
  24016. threeperiod: 0x248A,
  24017. threepersian: 0x06F3,
  24018. threequarters: 0x00BE,
  24019. threequartersemdash: 0xF6DE,
  24020. threeroman: 0x2172,
  24021. threesuperior: 0x00B3,
  24022. threethai: 0x0E53,
  24023. thzsquare: 0x3394,
  24024. tihiragana: 0x3061,
  24025. tikatakana: 0x30C1,
  24026. tikatakanahalfwidth: 0xFF81,
  24027. tikeutacirclekorean: 0x3270,
  24028. tikeutaparenkorean: 0x3210,
  24029. tikeutcirclekorean: 0x3262,
  24030. tikeutkorean: 0x3137,
  24031. tikeutparenkorean: 0x3202,
  24032. tilde: 0x02DC,
  24033. tildebelowcmb: 0x0330,
  24034. tildecmb: 0x0303,
  24035. tildecomb: 0x0303,
  24036. tildedoublecmb: 0x0360,
  24037. tildeoperator: 0x223C,
  24038. tildeoverlaycmb: 0x0334,
  24039. tildeverticalcmb: 0x033E,
  24040. timescircle: 0x2297,
  24041. tipehahebrew: 0x0596,
  24042. tipehalefthebrew: 0x0596,
  24043. tippigurmukhi: 0x0A70,
  24044. titlocyrilliccmb: 0x0483,
  24045. tiwnarmenian: 0x057F,
  24046. tlinebelow: 0x1E6F,
  24047. tmonospace: 0xFF54,
  24048. toarmenian: 0x0569,
  24049. tohiragana: 0x3068,
  24050. tokatakana: 0x30C8,
  24051. tokatakanahalfwidth: 0xFF84,
  24052. tonebarextrahighmod: 0x02E5,
  24053. tonebarextralowmod: 0x02E9,
  24054. tonebarhighmod: 0x02E6,
  24055. tonebarlowmod: 0x02E8,
  24056. tonebarmidmod: 0x02E7,
  24057. tonefive: 0x01BD,
  24058. tonesix: 0x0185,
  24059. tonetwo: 0x01A8,
  24060. tonos: 0x0384,
  24061. tonsquare: 0x3327,
  24062. topatakthai: 0x0E0F,
  24063. tortoiseshellbracketleft: 0x3014,
  24064. tortoiseshellbracketleftsmall: 0xFE5D,
  24065. tortoiseshellbracketleftvertical: 0xFE39,
  24066. tortoiseshellbracketright: 0x3015,
  24067. tortoiseshellbracketrightsmall: 0xFE5E,
  24068. tortoiseshellbracketrightvertical: 0xFE3A,
  24069. totaothai: 0x0E15,
  24070. tpalatalhook: 0x01AB,
  24071. tparen: 0x24AF,
  24072. trademark: 0x2122,
  24073. trademarksans: 0xF8EA,
  24074. trademarkserif: 0xF6DB,
  24075. tretroflexhook: 0x0288,
  24076. triagdn: 0x25BC,
  24077. triaglf: 0x25C4,
  24078. triagrt: 0x25BA,
  24079. triagup: 0x25B2,
  24080. ts: 0x02A6,
  24081. tsadi: 0x05E6,
  24082. tsadidagesh: 0xFB46,
  24083. tsadidageshhebrew: 0xFB46,
  24084. tsadihebrew: 0x05E6,
  24085. tsecyrillic: 0x0446,
  24086. tsere: 0x05B5,
  24087. tsere12: 0x05B5,
  24088. tsere1e: 0x05B5,
  24089. tsere2b: 0x05B5,
  24090. tserehebrew: 0x05B5,
  24091. tserenarrowhebrew: 0x05B5,
  24092. tserequarterhebrew: 0x05B5,
  24093. tserewidehebrew: 0x05B5,
  24094. tshecyrillic: 0x045B,
  24095. tsuperior: 0xF6F3,
  24096. ttabengali: 0x099F,
  24097. ttadeva: 0x091F,
  24098. ttagujarati: 0x0A9F,
  24099. ttagurmukhi: 0x0A1F,
  24100. tteharabic: 0x0679,
  24101. ttehfinalarabic: 0xFB67,
  24102. ttehinitialarabic: 0xFB68,
  24103. ttehmedialarabic: 0xFB69,
  24104. tthabengali: 0x09A0,
  24105. tthadeva: 0x0920,
  24106. tthagujarati: 0x0AA0,
  24107. tthagurmukhi: 0x0A20,
  24108. tturned: 0x0287,
  24109. tuhiragana: 0x3064,
  24110. tukatakana: 0x30C4,
  24111. tukatakanahalfwidth: 0xFF82,
  24112. tusmallhiragana: 0x3063,
  24113. tusmallkatakana: 0x30C3,
  24114. tusmallkatakanahalfwidth: 0xFF6F,
  24115. twelvecircle: 0x246B,
  24116. twelveparen: 0x247F,
  24117. twelveperiod: 0x2493,
  24118. twelveroman: 0x217B,
  24119. twentycircle: 0x2473,
  24120. twentyhangzhou: 0x5344,
  24121. twentyparen: 0x2487,
  24122. twentyperiod: 0x249B,
  24123. two: 0x0032,
  24124. twoarabic: 0x0662,
  24125. twobengali: 0x09E8,
  24126. twocircle: 0x2461,
  24127. twocircleinversesansserif: 0x278B,
  24128. twodeva: 0x0968,
  24129. twodotenleader: 0x2025,
  24130. twodotleader: 0x2025,
  24131. twodotleadervertical: 0xFE30,
  24132. twogujarati: 0x0AE8,
  24133. twogurmukhi: 0x0A68,
  24134. twohackarabic: 0x0662,
  24135. twohangzhou: 0x3022,
  24136. twoideographicparen: 0x3221,
  24137. twoinferior: 0x2082,
  24138. twomonospace: 0xFF12,
  24139. twonumeratorbengali: 0x09F5,
  24140. twooldstyle: 0xF732,
  24141. twoparen: 0x2475,
  24142. twoperiod: 0x2489,
  24143. twopersian: 0x06F2,
  24144. tworoman: 0x2171,
  24145. twostroke: 0x01BB,
  24146. twosuperior: 0x00B2,
  24147. twothai: 0x0E52,
  24148. twothirds: 0x2154,
  24149. u: 0x0075,
  24150. uacute: 0x00FA,
  24151. ubar: 0x0289,
  24152. ubengali: 0x0989,
  24153. ubopomofo: 0x3128,
  24154. ubreve: 0x016D,
  24155. ucaron: 0x01D4,
  24156. ucircle: 0x24E4,
  24157. ucircumflex: 0x00FB,
  24158. ucircumflexbelow: 0x1E77,
  24159. ucyrillic: 0x0443,
  24160. udattadeva: 0x0951,
  24161. udblacute: 0x0171,
  24162. udblgrave: 0x0215,
  24163. udeva: 0x0909,
  24164. udieresis: 0x00FC,
  24165. udieresisacute: 0x01D8,
  24166. udieresisbelow: 0x1E73,
  24167. udieresiscaron: 0x01DA,
  24168. udieresiscyrillic: 0x04F1,
  24169. udieresisgrave: 0x01DC,
  24170. udieresismacron: 0x01D6,
  24171. udotbelow: 0x1EE5,
  24172. ugrave: 0x00F9,
  24173. ugujarati: 0x0A89,
  24174. ugurmukhi: 0x0A09,
  24175. uhiragana: 0x3046,
  24176. uhookabove: 0x1EE7,
  24177. uhorn: 0x01B0,
  24178. uhornacute: 0x1EE9,
  24179. uhorndotbelow: 0x1EF1,
  24180. uhorngrave: 0x1EEB,
  24181. uhornhookabove: 0x1EED,
  24182. uhorntilde: 0x1EEF,
  24183. uhungarumlaut: 0x0171,
  24184. uhungarumlautcyrillic: 0x04F3,
  24185. uinvertedbreve: 0x0217,
  24186. ukatakana: 0x30A6,
  24187. ukatakanahalfwidth: 0xFF73,
  24188. ukcyrillic: 0x0479,
  24189. ukorean: 0x315C,
  24190. umacron: 0x016B,
  24191. umacroncyrillic: 0x04EF,
  24192. umacrondieresis: 0x1E7B,
  24193. umatragurmukhi: 0x0A41,
  24194. umonospace: 0xFF55,
  24195. underscore: 0x005F,
  24196. underscoredbl: 0x2017,
  24197. underscoremonospace: 0xFF3F,
  24198. underscorevertical: 0xFE33,
  24199. underscorewavy: 0xFE4F,
  24200. union: 0x222A,
  24201. universal: 0x2200,
  24202. uogonek: 0x0173,
  24203. uparen: 0x24B0,
  24204. upblock: 0x2580,
  24205. upperdothebrew: 0x05C4,
  24206. upsilon: 0x03C5,
  24207. upsilondieresis: 0x03CB,
  24208. upsilondieresistonos: 0x03B0,
  24209. upsilonlatin: 0x028A,
  24210. upsilontonos: 0x03CD,
  24211. uptackbelowcmb: 0x031D,
  24212. uptackmod: 0x02D4,
  24213. uragurmukhi: 0x0A73,
  24214. uring: 0x016F,
  24215. ushortcyrillic: 0x045E,
  24216. usmallhiragana: 0x3045,
  24217. usmallkatakana: 0x30A5,
  24218. usmallkatakanahalfwidth: 0xFF69,
  24219. ustraightcyrillic: 0x04AF,
  24220. ustraightstrokecyrillic: 0x04B1,
  24221. utilde: 0x0169,
  24222. utildeacute: 0x1E79,
  24223. utildebelow: 0x1E75,
  24224. uubengali: 0x098A,
  24225. uudeva: 0x090A,
  24226. uugujarati: 0x0A8A,
  24227. uugurmukhi: 0x0A0A,
  24228. uumatragurmukhi: 0x0A42,
  24229. uuvowelsignbengali: 0x09C2,
  24230. uuvowelsigndeva: 0x0942,
  24231. uuvowelsigngujarati: 0x0AC2,
  24232. uvowelsignbengali: 0x09C1,
  24233. uvowelsigndeva: 0x0941,
  24234. uvowelsigngujarati: 0x0AC1,
  24235. v: 0x0076,
  24236. vadeva: 0x0935,
  24237. vagujarati: 0x0AB5,
  24238. vagurmukhi: 0x0A35,
  24239. vakatakana: 0x30F7,
  24240. vav: 0x05D5,
  24241. vavdagesh: 0xFB35,
  24242. vavdagesh65: 0xFB35,
  24243. vavdageshhebrew: 0xFB35,
  24244. vavhebrew: 0x05D5,
  24245. vavholam: 0xFB4B,
  24246. vavholamhebrew: 0xFB4B,
  24247. vavvavhebrew: 0x05F0,
  24248. vavyodhebrew: 0x05F1,
  24249. vcircle: 0x24E5,
  24250. vdotbelow: 0x1E7F,
  24251. vecyrillic: 0x0432,
  24252. veharabic: 0x06A4,
  24253. vehfinalarabic: 0xFB6B,
  24254. vehinitialarabic: 0xFB6C,
  24255. vehmedialarabic: 0xFB6D,
  24256. vekatakana: 0x30F9,
  24257. venus: 0x2640,
  24258. verticalbar: 0x007C,
  24259. verticallineabovecmb: 0x030D,
  24260. verticallinebelowcmb: 0x0329,
  24261. verticallinelowmod: 0x02CC,
  24262. verticallinemod: 0x02C8,
  24263. vewarmenian: 0x057E,
  24264. vhook: 0x028B,
  24265. vikatakana: 0x30F8,
  24266. viramabengali: 0x09CD,
  24267. viramadeva: 0x094D,
  24268. viramagujarati: 0x0ACD,
  24269. visargabengali: 0x0983,
  24270. visargadeva: 0x0903,
  24271. visargagujarati: 0x0A83,
  24272. vmonospace: 0xFF56,
  24273. voarmenian: 0x0578,
  24274. voicediterationhiragana: 0x309E,
  24275. voicediterationkatakana: 0x30FE,
  24276. voicedmarkkana: 0x309B,
  24277. voicedmarkkanahalfwidth: 0xFF9E,
  24278. vokatakana: 0x30FA,
  24279. vparen: 0x24B1,
  24280. vtilde: 0x1E7D,
  24281. vturned: 0x028C,
  24282. vuhiragana: 0x3094,
  24283. vukatakana: 0x30F4,
  24284. w: 0x0077,
  24285. wacute: 0x1E83,
  24286. waekorean: 0x3159,
  24287. wahiragana: 0x308F,
  24288. wakatakana: 0x30EF,
  24289. wakatakanahalfwidth: 0xFF9C,
  24290. wakorean: 0x3158,
  24291. wasmallhiragana: 0x308E,
  24292. wasmallkatakana: 0x30EE,
  24293. wattosquare: 0x3357,
  24294. wavedash: 0x301C,
  24295. wavyunderscorevertical: 0xFE34,
  24296. wawarabic: 0x0648,
  24297. wawfinalarabic: 0xFEEE,
  24298. wawhamzaabovearabic: 0x0624,
  24299. wawhamzaabovefinalarabic: 0xFE86,
  24300. wbsquare: 0x33DD,
  24301. wcircle: 0x24E6,
  24302. wcircumflex: 0x0175,
  24303. wdieresis: 0x1E85,
  24304. wdotaccent: 0x1E87,
  24305. wdotbelow: 0x1E89,
  24306. wehiragana: 0x3091,
  24307. weierstrass: 0x2118,
  24308. wekatakana: 0x30F1,
  24309. wekorean: 0x315E,
  24310. weokorean: 0x315D,
  24311. wgrave: 0x1E81,
  24312. whitebullet: 0x25E6,
  24313. whitecircle: 0x25CB,
  24314. whitecircleinverse: 0x25D9,
  24315. whitecornerbracketleft: 0x300E,
  24316. whitecornerbracketleftvertical: 0xFE43,
  24317. whitecornerbracketright: 0x300F,
  24318. whitecornerbracketrightvertical: 0xFE44,
  24319. whitediamond: 0x25C7,
  24320. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24321. whitedownpointingsmalltriangle: 0x25BF,
  24322. whitedownpointingtriangle: 0x25BD,
  24323. whiteleftpointingsmalltriangle: 0x25C3,
  24324. whiteleftpointingtriangle: 0x25C1,
  24325. whitelenticularbracketleft: 0x3016,
  24326. whitelenticularbracketright: 0x3017,
  24327. whiterightpointingsmalltriangle: 0x25B9,
  24328. whiterightpointingtriangle: 0x25B7,
  24329. whitesmallsquare: 0x25AB,
  24330. whitesmilingface: 0x263A,
  24331. whitesquare: 0x25A1,
  24332. whitestar: 0x2606,
  24333. whitetelephone: 0x260F,
  24334. whitetortoiseshellbracketleft: 0x3018,
  24335. whitetortoiseshellbracketright: 0x3019,
  24336. whiteuppointingsmalltriangle: 0x25B5,
  24337. whiteuppointingtriangle: 0x25B3,
  24338. wihiragana: 0x3090,
  24339. wikatakana: 0x30F0,
  24340. wikorean: 0x315F,
  24341. wmonospace: 0xFF57,
  24342. wohiragana: 0x3092,
  24343. wokatakana: 0x30F2,
  24344. wokatakanahalfwidth: 0xFF66,
  24345. won: 0x20A9,
  24346. wonmonospace: 0xFFE6,
  24347. wowaenthai: 0x0E27,
  24348. wparen: 0x24B2,
  24349. wring: 0x1E98,
  24350. wsuperior: 0x02B7,
  24351. wturned: 0x028D,
  24352. wynn: 0x01BF,
  24353. x: 0x0078,
  24354. xabovecmb: 0x033D,
  24355. xbopomofo: 0x3112,
  24356. xcircle: 0x24E7,
  24357. xdieresis: 0x1E8D,
  24358. xdotaccent: 0x1E8B,
  24359. xeharmenian: 0x056D,
  24360. xi: 0x03BE,
  24361. xmonospace: 0xFF58,
  24362. xparen: 0x24B3,
  24363. xsuperior: 0x02E3,
  24364. y: 0x0079,
  24365. yaadosquare: 0x334E,
  24366. yabengali: 0x09AF,
  24367. yacute: 0x00FD,
  24368. yadeva: 0x092F,
  24369. yaekorean: 0x3152,
  24370. yagujarati: 0x0AAF,
  24371. yagurmukhi: 0x0A2F,
  24372. yahiragana: 0x3084,
  24373. yakatakana: 0x30E4,
  24374. yakatakanahalfwidth: 0xFF94,
  24375. yakorean: 0x3151,
  24376. yamakkanthai: 0x0E4E,
  24377. yasmallhiragana: 0x3083,
  24378. yasmallkatakana: 0x30E3,
  24379. yasmallkatakanahalfwidth: 0xFF6C,
  24380. yatcyrillic: 0x0463,
  24381. ycircle: 0x24E8,
  24382. ycircumflex: 0x0177,
  24383. ydieresis: 0x00FF,
  24384. ydotaccent: 0x1E8F,
  24385. ydotbelow: 0x1EF5,
  24386. yeharabic: 0x064A,
  24387. yehbarreearabic: 0x06D2,
  24388. yehbarreefinalarabic: 0xFBAF,
  24389. yehfinalarabic: 0xFEF2,
  24390. yehhamzaabovearabic: 0x0626,
  24391. yehhamzaabovefinalarabic: 0xFE8A,
  24392. yehhamzaaboveinitialarabic: 0xFE8B,
  24393. yehhamzaabovemedialarabic: 0xFE8C,
  24394. yehinitialarabic: 0xFEF3,
  24395. yehmedialarabic: 0xFEF4,
  24396. yehmeeminitialarabic: 0xFCDD,
  24397. yehmeemisolatedarabic: 0xFC58,
  24398. yehnoonfinalarabic: 0xFC94,
  24399. yehthreedotsbelowarabic: 0x06D1,
  24400. yekorean: 0x3156,
  24401. yen: 0x00A5,
  24402. yenmonospace: 0xFFE5,
  24403. yeokorean: 0x3155,
  24404. yeorinhieuhkorean: 0x3186,
  24405. yerahbenyomohebrew: 0x05AA,
  24406. yerahbenyomolefthebrew: 0x05AA,
  24407. yericyrillic: 0x044B,
  24408. yerudieresiscyrillic: 0x04F9,
  24409. yesieungkorean: 0x3181,
  24410. yesieungpansioskorean: 0x3183,
  24411. yesieungsioskorean: 0x3182,
  24412. yetivhebrew: 0x059A,
  24413. ygrave: 0x1EF3,
  24414. yhook: 0x01B4,
  24415. yhookabove: 0x1EF7,
  24416. yiarmenian: 0x0575,
  24417. yicyrillic: 0x0457,
  24418. yikorean: 0x3162,
  24419. yinyang: 0x262F,
  24420. yiwnarmenian: 0x0582,
  24421. ymonospace: 0xFF59,
  24422. yod: 0x05D9,
  24423. yoddagesh: 0xFB39,
  24424. yoddageshhebrew: 0xFB39,
  24425. yodhebrew: 0x05D9,
  24426. yodyodhebrew: 0x05F2,
  24427. yodyodpatahhebrew: 0xFB1F,
  24428. yohiragana: 0x3088,
  24429. yoikorean: 0x3189,
  24430. yokatakana: 0x30E8,
  24431. yokatakanahalfwidth: 0xFF96,
  24432. yokorean: 0x315B,
  24433. yosmallhiragana: 0x3087,
  24434. yosmallkatakana: 0x30E7,
  24435. yosmallkatakanahalfwidth: 0xFF6E,
  24436. yotgreek: 0x03F3,
  24437. yoyaekorean: 0x3188,
  24438. yoyakorean: 0x3187,
  24439. yoyakthai: 0x0E22,
  24440. yoyingthai: 0x0E0D,
  24441. yparen: 0x24B4,
  24442. ypogegrammeni: 0x037A,
  24443. ypogegrammenigreekcmb: 0x0345,
  24444. yr: 0x01A6,
  24445. yring: 0x1E99,
  24446. ysuperior: 0x02B8,
  24447. ytilde: 0x1EF9,
  24448. yturned: 0x028E,
  24449. yuhiragana: 0x3086,
  24450. yuikorean: 0x318C,
  24451. yukatakana: 0x30E6,
  24452. yukatakanahalfwidth: 0xFF95,
  24453. yukorean: 0x3160,
  24454. yusbigcyrillic: 0x046B,
  24455. yusbigiotifiedcyrillic: 0x046D,
  24456. yuslittlecyrillic: 0x0467,
  24457. yuslittleiotifiedcyrillic: 0x0469,
  24458. yusmallhiragana: 0x3085,
  24459. yusmallkatakana: 0x30E5,
  24460. yusmallkatakanahalfwidth: 0xFF6D,
  24461. yuyekorean: 0x318B,
  24462. yuyeokorean: 0x318A,
  24463. yyabengali: 0x09DF,
  24464. yyadeva: 0x095F,
  24465. z: 0x007A,
  24466. zaarmenian: 0x0566,
  24467. zacute: 0x017A,
  24468. zadeva: 0x095B,
  24469. zagurmukhi: 0x0A5B,
  24470. zaharabic: 0x0638,
  24471. zahfinalarabic: 0xFEC6,
  24472. zahinitialarabic: 0xFEC7,
  24473. zahiragana: 0x3056,
  24474. zahmedialarabic: 0xFEC8,
  24475. zainarabic: 0x0632,
  24476. zainfinalarabic: 0xFEB0,
  24477. zakatakana: 0x30B6,
  24478. zaqefgadolhebrew: 0x0595,
  24479. zaqefqatanhebrew: 0x0594,
  24480. zarqahebrew: 0x0598,
  24481. zayin: 0x05D6,
  24482. zayindagesh: 0xFB36,
  24483. zayindageshhebrew: 0xFB36,
  24484. zayinhebrew: 0x05D6,
  24485. zbopomofo: 0x3117,
  24486. zcaron: 0x017E,
  24487. zcircle: 0x24E9,
  24488. zcircumflex: 0x1E91,
  24489. zcurl: 0x0291,
  24490. zdot: 0x017C,
  24491. zdotaccent: 0x017C,
  24492. zdotbelow: 0x1E93,
  24493. zecyrillic: 0x0437,
  24494. zedescendercyrillic: 0x0499,
  24495. zedieresiscyrillic: 0x04DF,
  24496. zehiragana: 0x305C,
  24497. zekatakana: 0x30BC,
  24498. zero: 0x0030,
  24499. zeroarabic: 0x0660,
  24500. zerobengali: 0x09E6,
  24501. zerodeva: 0x0966,
  24502. zerogujarati: 0x0AE6,
  24503. zerogurmukhi: 0x0A66,
  24504. zerohackarabic: 0x0660,
  24505. zeroinferior: 0x2080,
  24506. zeromonospace: 0xFF10,
  24507. zerooldstyle: 0xF730,
  24508. zeropersian: 0x06F0,
  24509. zerosuperior: 0x2070,
  24510. zerothai: 0x0E50,
  24511. zerowidthjoiner: 0xFEFF,
  24512. zerowidthnonjoiner: 0x200C,
  24513. zerowidthspace: 0x200B,
  24514. zeta: 0x03B6,
  24515. zhbopomofo: 0x3113,
  24516. zhearmenian: 0x056A,
  24517. zhebrevecyrillic: 0x04C2,
  24518. zhecyrillic: 0x0436,
  24519. zhedescendercyrillic: 0x0497,
  24520. zhedieresiscyrillic: 0x04DD,
  24521. zihiragana: 0x3058,
  24522. zikatakana: 0x30B8,
  24523. zinorhebrew: 0x05AE,
  24524. zlinebelow: 0x1E95,
  24525. zmonospace: 0xFF5A,
  24526. zohiragana: 0x305E,
  24527. zokatakana: 0x30BE,
  24528. zparen: 0x24B5,
  24529. zretroflexhook: 0x0290,
  24530. zstroke: 0x01B6,
  24531. zuhiragana: 0x305A,
  24532. zukatakana: 0x30BA,
  24533. '.notdef': 0x0000
  24534. };
  24535. var DingbatsGlyphsUnicode = {
  24536. space: 0x0020,
  24537. a1: 0x2701,
  24538. a2: 0x2702,
  24539. a202: 0x2703,
  24540. a3: 0x2704,
  24541. a4: 0x260E,
  24542. a5: 0x2706,
  24543. a119: 0x2707,
  24544. a118: 0x2708,
  24545. a117: 0x2709,
  24546. a11: 0x261B,
  24547. a12: 0x261E,
  24548. a13: 0x270C,
  24549. a14: 0x270D,
  24550. a15: 0x270E,
  24551. a16: 0x270F,
  24552. a105: 0x2710,
  24553. a17: 0x2711,
  24554. a18: 0x2712,
  24555. a19: 0x2713,
  24556. a20: 0x2714,
  24557. a21: 0x2715,
  24558. a22: 0x2716,
  24559. a23: 0x2717,
  24560. a24: 0x2718,
  24561. a25: 0x2719,
  24562. a26: 0x271A,
  24563. a27: 0x271B,
  24564. a28: 0x271C,
  24565. a6: 0x271D,
  24566. a7: 0x271E,
  24567. a8: 0x271F,
  24568. a9: 0x2720,
  24569. a10: 0x2721,
  24570. a29: 0x2722,
  24571. a30: 0x2723,
  24572. a31: 0x2724,
  24573. a32: 0x2725,
  24574. a33: 0x2726,
  24575. a34: 0x2727,
  24576. a35: 0x2605,
  24577. a36: 0x2729,
  24578. a37: 0x272A,
  24579. a38: 0x272B,
  24580. a39: 0x272C,
  24581. a40: 0x272D,
  24582. a41: 0x272E,
  24583. a42: 0x272F,
  24584. a43: 0x2730,
  24585. a44: 0x2731,
  24586. a45: 0x2732,
  24587. a46: 0x2733,
  24588. a47: 0x2734,
  24589. a48: 0x2735,
  24590. a49: 0x2736,
  24591. a50: 0x2737,
  24592. a51: 0x2738,
  24593. a52: 0x2739,
  24594. a53: 0x273A,
  24595. a54: 0x273B,
  24596. a55: 0x273C,
  24597. a56: 0x273D,
  24598. a57: 0x273E,
  24599. a58: 0x273F,
  24600. a59: 0x2740,
  24601. a60: 0x2741,
  24602. a61: 0x2742,
  24603. a62: 0x2743,
  24604. a63: 0x2744,
  24605. a64: 0x2745,
  24606. a65: 0x2746,
  24607. a66: 0x2747,
  24608. a67: 0x2748,
  24609. a68: 0x2749,
  24610. a69: 0x274A,
  24611. a70: 0x274B,
  24612. a71: 0x25CF,
  24613. a72: 0x274D,
  24614. a73: 0x25A0,
  24615. a74: 0x274F,
  24616. a203: 0x2750,
  24617. a75: 0x2751,
  24618. a204: 0x2752,
  24619. a76: 0x25B2,
  24620. a77: 0x25BC,
  24621. a78: 0x25C6,
  24622. a79: 0x2756,
  24623. a81: 0x25D7,
  24624. a82: 0x2758,
  24625. a83: 0x2759,
  24626. a84: 0x275A,
  24627. a97: 0x275B,
  24628. a98: 0x275C,
  24629. a99: 0x275D,
  24630. a100: 0x275E,
  24631. a101: 0x2761,
  24632. a102: 0x2762,
  24633. a103: 0x2763,
  24634. a104: 0x2764,
  24635. a106: 0x2765,
  24636. a107: 0x2766,
  24637. a108: 0x2767,
  24638. a112: 0x2663,
  24639. a111: 0x2666,
  24640. a110: 0x2665,
  24641. a109: 0x2660,
  24642. a120: 0x2460,
  24643. a121: 0x2461,
  24644. a122: 0x2462,
  24645. a123: 0x2463,
  24646. a124: 0x2464,
  24647. a125: 0x2465,
  24648. a126: 0x2466,
  24649. a127: 0x2467,
  24650. a128: 0x2468,
  24651. a129: 0x2469,
  24652. a130: 0x2776,
  24653. a131: 0x2777,
  24654. a132: 0x2778,
  24655. a133: 0x2779,
  24656. a134: 0x277A,
  24657. a135: 0x277B,
  24658. a136: 0x277C,
  24659. a137: 0x277D,
  24660. a138: 0x277E,
  24661. a139: 0x277F,
  24662. a140: 0x2780,
  24663. a141: 0x2781,
  24664. a142: 0x2782,
  24665. a143: 0x2783,
  24666. a144: 0x2784,
  24667. a145: 0x2785,
  24668. a146: 0x2786,
  24669. a147: 0x2787,
  24670. a148: 0x2788,
  24671. a149: 0x2789,
  24672. a150: 0x278A,
  24673. a151: 0x278B,
  24674. a152: 0x278C,
  24675. a153: 0x278D,
  24676. a154: 0x278E,
  24677. a155: 0x278F,
  24678. a156: 0x2790,
  24679. a157: 0x2791,
  24680. a158: 0x2792,
  24681. a159: 0x2793,
  24682. a160: 0x2794,
  24683. a161: 0x2192,
  24684. a163: 0x2194,
  24685. a164: 0x2195,
  24686. a196: 0x2798,
  24687. a165: 0x2799,
  24688. a192: 0x279A,
  24689. a166: 0x279B,
  24690. a167: 0x279C,
  24691. a168: 0x279D,
  24692. a169: 0x279E,
  24693. a170: 0x279F,
  24694. a171: 0x27A0,
  24695. a172: 0x27A1,
  24696. a173: 0x27A2,
  24697. a162: 0x27A3,
  24698. a174: 0x27A4,
  24699. a175: 0x27A5,
  24700. a176: 0x27A6,
  24701. a177: 0x27A7,
  24702. a178: 0x27A8,
  24703. a179: 0x27A9,
  24704. a193: 0x27AA,
  24705. a180: 0x27AB,
  24706. a199: 0x27AC,
  24707. a181: 0x27AD,
  24708. a200: 0x27AE,
  24709. a182: 0x27AF,
  24710. a201: 0x27B1,
  24711. a183: 0x27B2,
  24712. a184: 0x27B3,
  24713. a197: 0x27B4,
  24714. a185: 0x27B5,
  24715. a194: 0x27B6,
  24716. a198: 0x27B7,
  24717. a186: 0x27B8,
  24718. a195: 0x27B9,
  24719. a187: 0x27BA,
  24720. a188: 0x27BB,
  24721. a189: 0x27BC,
  24722. a190: 0x27BD,
  24723. a191: 0x27BE,
  24724. a89: 0x2768, // 0xF8D7
  24725. a90: 0x2769, // 0xF8D8
  24726. a93: 0x276A, // 0xF8D9
  24727. a94: 0x276B, // 0xF8DA
  24728. a91: 0x276C, // 0xF8DB
  24729. a92: 0x276D, // 0xF8DC
  24730. a205: 0x276E, // 0xF8DD
  24731. a85: 0x276F, // 0xF8DE
  24732. a206: 0x2770, // 0xF8DF
  24733. a86: 0x2771, // 0xF8E0
  24734. a87: 0x2772, // 0xF8E1
  24735. a88: 0x2773, // 0xF8E2
  24736. a95: 0x2774, // 0xF8E3
  24737. a96: 0x2775, // 0xF8E4
  24738. '.notdef': 0x0000
  24739. };
  24740. var PDFImage = (function PDFImageClosure() {
  24741. /**
  24742. * Decode the image in the main thread if it supported. Resovles the promise
  24743. * when the image data is ready.
  24744. */
  24745. function handleImageData(handler, xref, res, image) {
  24746. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24747. // For natively supported jpegs send them to the main thread for decoding.
  24748. var dict = image.dict;
  24749. var colorSpace = dict.get('ColorSpace', 'CS');
  24750. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24751. var numComps = colorSpace.numComps;
  24752. var decodePromise = handler.sendWithPromise('JpegDecode',
  24753. [image.getIR(), numComps]);
  24754. return decodePromise.then(function (message) {
  24755. var data = message.data;
  24756. return new Stream(data, 0, data.length, image.dict);
  24757. });
  24758. } else {
  24759. return Promise.resolve(image);
  24760. }
  24761. }
  24762. /**
  24763. * Decode and clamp a value. The formula is different from the spec because we
  24764. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24765. */
  24766. function decodeAndClamp(value, addend, coefficient, max) {
  24767. value = addend + value * coefficient;
  24768. // Clamp the value to the range
  24769. return (value < 0 ? 0 : (value > max ? max : value));
  24770. }
  24771. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24772. this.image = image;
  24773. var dict = image.dict;
  24774. if (dict.has('Filter')) {
  24775. var filter = dict.get('Filter').name;
  24776. if (filter === 'JPXDecode') {
  24777. var jpxImage = new JpxImage();
  24778. jpxImage.parseImageProperties(image.stream);
  24779. image.stream.reset();
  24780. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24781. image.numComps = jpxImage.componentsCount;
  24782. } else if (filter === 'JBIG2Decode') {
  24783. image.bitsPerComponent = 1;
  24784. image.numComps = 1;
  24785. }
  24786. }
  24787. // TODO cache rendered images?
  24788. this.width = dict.get('Width', 'W');
  24789. this.height = dict.get('Height', 'H');
  24790. if (this.width < 1 || this.height < 1) {
  24791. error('Invalid image width: ' + this.width + ' or height: ' +
  24792. this.height);
  24793. }
  24794. this.interpolate = dict.get('Interpolate', 'I') || false;
  24795. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24796. this.matte = dict.get('Matte') || false;
  24797. var bitsPerComponent = image.bitsPerComponent;
  24798. if (!bitsPerComponent) {
  24799. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24800. if (!bitsPerComponent) {
  24801. if (this.imageMask) {
  24802. bitsPerComponent = 1;
  24803. } else {
  24804. error('Bits per component missing in image: ' + this.imageMask);
  24805. }
  24806. }
  24807. }
  24808. this.bpc = bitsPerComponent;
  24809. if (!this.imageMask) {
  24810. var colorSpace = dict.get('ColorSpace', 'CS');
  24811. if (!colorSpace) {
  24812. info('JPX images (which do not require color spaces)');
  24813. switch (image.numComps) {
  24814. case 1:
  24815. colorSpace = Name.get('DeviceGray');
  24816. break;
  24817. case 3:
  24818. colorSpace = Name.get('DeviceRGB');
  24819. break;
  24820. case 4:
  24821. colorSpace = Name.get('DeviceCMYK');
  24822. break;
  24823. default:
  24824. error('JPX images with ' + this.numComps +
  24825. ' color components not supported.');
  24826. }
  24827. }
  24828. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24829. this.numComps = this.colorSpace.numComps;
  24830. }
  24831. this.decode = dict.get('Decode', 'D');
  24832. this.needsDecode = false;
  24833. if (this.decode &&
  24834. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24835. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24836. this.needsDecode = true;
  24837. // Do some preprocessing to avoid more math.
  24838. var max = (1 << bitsPerComponent) - 1;
  24839. this.decodeCoefficients = [];
  24840. this.decodeAddends = [];
  24841. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24842. var dmin = this.decode[i];
  24843. var dmax = this.decode[i + 1];
  24844. this.decodeCoefficients[j] = dmax - dmin;
  24845. this.decodeAddends[j] = max * dmin;
  24846. }
  24847. }
  24848. if (smask) {
  24849. this.smask = new PDFImage(xref, res, smask, false);
  24850. } else if (mask) {
  24851. if (isStream(mask)) {
  24852. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24853. } else {
  24854. // Color key mask (just an array).
  24855. this.mask = mask;
  24856. }
  24857. }
  24858. }
  24859. /**
  24860. * Handles processing of image data and returns the Promise that is resolved
  24861. * with a PDFImage when the image is ready to be used.
  24862. */
  24863. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24864. res, image, inline) {
  24865. var imagePromise = handleImageData(handler, xref, res, image);
  24866. var smaskPromise;
  24867. var maskPromise;
  24868. var smask = image.dict.get('SMask');
  24869. var mask = image.dict.get('Mask');
  24870. if (smask) {
  24871. smaskPromise = handleImageData(handler, xref, res, smask);
  24872. maskPromise = Promise.resolve(null);
  24873. } else {
  24874. smaskPromise = Promise.resolve(null);
  24875. if (mask) {
  24876. if (isStream(mask)) {
  24877. maskPromise = handleImageData(handler, xref, res, mask);
  24878. } else if (isArray(mask)) {
  24879. maskPromise = Promise.resolve(mask);
  24880. } else {
  24881. warn('Unsupported mask format.');
  24882. maskPromise = Promise.resolve(null);
  24883. }
  24884. } else {
  24885. maskPromise = Promise.resolve(null);
  24886. }
  24887. }
  24888. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24889. function(results) {
  24890. var imageData = results[0];
  24891. var smaskData = results[1];
  24892. var maskData = results[2];
  24893. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24894. });
  24895. };
  24896. /**
  24897. * Resize an image using the nearest neighbor algorithm. Currently only
  24898. * supports one and three component images.
  24899. * @param {TypedArray} pixels The original image with one component.
  24900. * @param {Number} bpc Number of bits per component.
  24901. * @param {Number} components Number of color components, 1 or 3 is supported.
  24902. * @param {Number} w1 Original width.
  24903. * @param {Number} h1 Original height.
  24904. * @param {Number} w2 New width.
  24905. * @param {Number} h2 New height.
  24906. * @param {TypedArray} dest (Optional) The destination buffer.
  24907. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24908. * @return {TypedArray} Resized image data.
  24909. */
  24910. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24911. w1, h1, w2, h2, dest, alpha01) {
  24912. if (components !== 1 && components !== 3) {
  24913. error('Unsupported component count for resizing.');
  24914. }
  24915. var length = w2 * h2 * components;
  24916. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24917. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24918. var xRatio = w1 / w2;
  24919. var yRatio = h1 / h2;
  24920. var i, j, py, newIndex = 0, oldIndex;
  24921. var xScaled = new Uint16Array(w2);
  24922. var w1Scanline = w1 * components;
  24923. if (alpha01 !== 1) {
  24924. alpha01 = 0;
  24925. }
  24926. for (j = 0; j < w2; j++) {
  24927. xScaled[j] = Math.floor(j * xRatio) * components;
  24928. }
  24929. if (components === 1) {
  24930. for (i = 0; i < h2; i++) {
  24931. py = Math.floor(i * yRatio) * w1Scanline;
  24932. for (j = 0; j < w2; j++) {
  24933. oldIndex = py + xScaled[j];
  24934. temp[newIndex++] = pixels[oldIndex];
  24935. }
  24936. }
  24937. } else if (components === 3) {
  24938. for (i = 0; i < h2; i++) {
  24939. py = Math.floor(i * yRatio) * w1Scanline;
  24940. for (j = 0; j < w2; j++) {
  24941. oldIndex = py + xScaled[j];
  24942. temp[newIndex++] = pixels[oldIndex++];
  24943. temp[newIndex++] = pixels[oldIndex++];
  24944. temp[newIndex++] = pixels[oldIndex++];
  24945. newIndex += alpha01;
  24946. }
  24947. }
  24948. }
  24949. return temp;
  24950. };
  24951. PDFImage.createMask =
  24952. function PDFImage_createMask(imgArray, width, height,
  24953. imageIsFromDecodeStream, inverseDecode) {
  24954. // |imgArray| might not contain full data for every pixel of the mask, so
  24955. // we need to distinguish between |computedLength| and |actualLength|.
  24956. // In particular, if inverseDecode is true, then the array we return must
  24957. // have a length of |computedLength|.
  24958. var computedLength = ((width + 7) >> 3) * height;
  24959. var actualLength = imgArray.byteLength;
  24960. var haveFullData = computedLength === actualLength;
  24961. var data, i;
  24962. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24963. // imgArray came from a DecodeStream and its data is in an appropriate
  24964. // form, so we can just transfer it.
  24965. data = imgArray;
  24966. } else if (!inverseDecode) {
  24967. data = new Uint8Array(actualLength);
  24968. data.set(imgArray);
  24969. } else {
  24970. data = new Uint8Array(computedLength);
  24971. data.set(imgArray);
  24972. for (i = actualLength; i < computedLength; i++) {
  24973. data[i] = 0xff;
  24974. }
  24975. }
  24976. // If necessary, invert the original mask data (but not any extra we might
  24977. // have added above). It's safe to modify the array -- whether it's the
  24978. // original or a copy, we're about to transfer it anyway, so nothing else
  24979. // in this thread can be relying on its contents.
  24980. if (inverseDecode) {
  24981. for (i = 0; i < actualLength; i++) {
  24982. data[i] = ~data[i];
  24983. }
  24984. }
  24985. return {data: data, width: width, height: height};
  24986. };
  24987. PDFImage.prototype = {
  24988. get drawWidth() {
  24989. return Math.max(this.width,
  24990. this.smask && this.smask.width || 0,
  24991. this.mask && this.mask.width || 0);
  24992. },
  24993. get drawHeight() {
  24994. return Math.max(this.height,
  24995. this.smask && this.smask.height || 0,
  24996. this.mask && this.mask.height || 0);
  24997. },
  24998. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24999. var bpc = this.bpc;
  25000. var numComps = this.numComps;
  25001. var decodeAddends = this.decodeAddends;
  25002. var decodeCoefficients = this.decodeCoefficients;
  25003. var max = (1 << bpc) - 1;
  25004. var i, ii;
  25005. if (bpc === 1) {
  25006. // If the buffer needed decode that means it just needs to be inverted.
  25007. for (i = 0, ii = buffer.length; i < ii; i++) {
  25008. buffer[i] = +!(buffer[i]);
  25009. }
  25010. return;
  25011. }
  25012. var index = 0;
  25013. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25014. for (var j = 0; j < numComps; j++) {
  25015. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25016. decodeCoefficients[j], max);
  25017. index++;
  25018. }
  25019. }
  25020. },
  25021. getComponents: function PDFImage_getComponents(buffer) {
  25022. var bpc = this.bpc;
  25023. // This image doesn't require any extra work.
  25024. if (bpc === 8) {
  25025. return buffer;
  25026. }
  25027. var width = this.width;
  25028. var height = this.height;
  25029. var numComps = this.numComps;
  25030. var length = width * height * numComps;
  25031. var bufferPos = 0;
  25032. var output = (bpc <= 8 ? new Uint8Array(length) :
  25033. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25034. var rowComps = width * numComps;
  25035. var max = (1 << bpc) - 1;
  25036. var i = 0, ii, buf;
  25037. if (bpc === 1) {
  25038. // Optimization for reading 1 bpc images.
  25039. var mask, loop1End, loop2End;
  25040. for (var j = 0; j < height; j++) {
  25041. loop1End = i + (rowComps & ~7);
  25042. loop2End = i + rowComps;
  25043. // unroll loop for all full bytes
  25044. while (i < loop1End) {
  25045. buf = buffer[bufferPos++];
  25046. output[i] = (buf >> 7) & 1;
  25047. output[i + 1] = (buf >> 6) & 1;
  25048. output[i + 2] = (buf >> 5) & 1;
  25049. output[i + 3] = (buf >> 4) & 1;
  25050. output[i + 4] = (buf >> 3) & 1;
  25051. output[i + 5] = (buf >> 2) & 1;
  25052. output[i + 6] = (buf >> 1) & 1;
  25053. output[i + 7] = buf & 1;
  25054. i += 8;
  25055. }
  25056. // handle remaing bits
  25057. if (i < loop2End) {
  25058. buf = buffer[bufferPos++];
  25059. mask = 128;
  25060. while (i < loop2End) {
  25061. output[i++] = +!!(buf & mask);
  25062. mask >>= 1;
  25063. }
  25064. }
  25065. }
  25066. } else {
  25067. // The general case that handles all other bpc values.
  25068. var bits = 0;
  25069. buf = 0;
  25070. for (i = 0, ii = length; i < ii; ++i) {
  25071. if (i % rowComps === 0) {
  25072. buf = 0;
  25073. bits = 0;
  25074. }
  25075. while (bits < bpc) {
  25076. buf = (buf << 8) | buffer[bufferPos++];
  25077. bits += 8;
  25078. }
  25079. var remainingBits = bits - bpc;
  25080. var value = buf >> remainingBits;
  25081. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25082. buf = buf & ((1 << remainingBits) - 1);
  25083. bits = remainingBits;
  25084. }
  25085. }
  25086. return output;
  25087. },
  25088. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25089. actualHeight, image) {
  25090. var smask = this.smask;
  25091. var mask = this.mask;
  25092. var alphaBuf, sw, sh, i, ii, j;
  25093. if (smask) {
  25094. sw = smask.width;
  25095. sh = smask.height;
  25096. alphaBuf = new Uint8Array(sw * sh);
  25097. smask.fillGrayBuffer(alphaBuf);
  25098. if (sw !== width || sh !== height) {
  25099. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25100. height);
  25101. }
  25102. } else if (mask) {
  25103. if (mask instanceof PDFImage) {
  25104. sw = mask.width;
  25105. sh = mask.height;
  25106. alphaBuf = new Uint8Array(sw * sh);
  25107. mask.numComps = 1;
  25108. mask.fillGrayBuffer(alphaBuf);
  25109. // Need to invert values in rgbaBuf
  25110. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25111. alphaBuf[i] = 255 - alphaBuf[i];
  25112. }
  25113. if (sw !== width || sh !== height) {
  25114. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25115. height);
  25116. }
  25117. } else if (isArray(mask)) {
  25118. // Color key mask: if any of the compontents are outside the range
  25119. // then they should be painted.
  25120. alphaBuf = new Uint8Array(width * height);
  25121. var numComps = this.numComps;
  25122. for (i = 0, ii = width * height; i < ii; ++i) {
  25123. var opacity = 0;
  25124. var imageOffset = i * numComps;
  25125. for (j = 0; j < numComps; ++j) {
  25126. var color = image[imageOffset + j];
  25127. var maskOffset = j * 2;
  25128. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25129. opacity = 255;
  25130. break;
  25131. }
  25132. }
  25133. alphaBuf[i] = opacity;
  25134. }
  25135. } else {
  25136. error('Unknown mask format.');
  25137. }
  25138. }
  25139. if (alphaBuf) {
  25140. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25141. rgbaBuf[j] = alphaBuf[i];
  25142. }
  25143. } else {
  25144. // No mask.
  25145. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25146. rgbaBuf[j] = 255;
  25147. }
  25148. }
  25149. },
  25150. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25151. var matte = this.smask && this.smask.matte;
  25152. if (!matte) {
  25153. return;
  25154. }
  25155. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25156. var matteR = matteRgb[0];
  25157. var matteG = matteRgb[1];
  25158. var matteB = matteRgb[2];
  25159. var length = width * height * 4;
  25160. var r, g, b;
  25161. for (var i = 0; i < length; i += 4) {
  25162. var alpha = buffer[i + 3];
  25163. if (alpha === 0) {
  25164. // according formula we have to get Infinity in all components
  25165. // making it white (typical paper color) should be okay
  25166. buffer[i] = 255;
  25167. buffer[i + 1] = 255;
  25168. buffer[i + 2] = 255;
  25169. continue;
  25170. }
  25171. var k = 255 / alpha;
  25172. r = (buffer[i] - matteR) * k + matteR;
  25173. g = (buffer[i + 1] - matteG) * k + matteG;
  25174. b = (buffer[i + 2] - matteB) * k + matteB;
  25175. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25176. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25177. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25178. }
  25179. },
  25180. createImageData: function PDFImage_createImageData(forceRGBA) {
  25181. var drawWidth = this.drawWidth;
  25182. var drawHeight = this.drawHeight;
  25183. var imgData = { // other fields are filled in below
  25184. width: drawWidth,
  25185. height: drawHeight
  25186. };
  25187. var numComps = this.numComps;
  25188. var originalWidth = this.width;
  25189. var originalHeight = this.height;
  25190. var bpc = this.bpc;
  25191. // Rows start at byte boundary.
  25192. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25193. var imgArray;
  25194. if (!forceRGBA) {
  25195. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25196. // without any complications, we pass a same-sized copy to the main
  25197. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25198. // of memory for many scanned documents. It's also much faster.
  25199. //
  25200. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25201. // complications, we avoid expanding by 1.333x to RGBA form.
  25202. var kind;
  25203. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25204. kind = ImageKind.GRAYSCALE_1BPP;
  25205. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25206. !this.needsDecode) {
  25207. kind = ImageKind.RGB_24BPP;
  25208. }
  25209. if (kind && !this.smask && !this.mask &&
  25210. drawWidth === originalWidth && drawHeight === originalHeight) {
  25211. imgData.kind = kind;
  25212. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25213. // If imgArray came from a DecodeStream, we're safe to transfer it
  25214. // (and thus neuter it) because it will constitute the entire
  25215. // DecodeStream's data. But if it came from a Stream, we need to
  25216. // copy it because it'll only be a portion of the Stream's data, and
  25217. // the rest will be read later on.
  25218. if (this.image instanceof DecodeStream) {
  25219. imgData.data = imgArray;
  25220. } else {
  25221. var newArray = new Uint8Array(imgArray.length);
  25222. newArray.set(imgArray);
  25223. imgData.data = newArray;
  25224. }
  25225. if (this.needsDecode) {
  25226. // Invert the buffer (which must be grayscale if we reached here).
  25227. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25228. var buffer = imgData.data;
  25229. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25230. buffer[i] ^= 0xff;
  25231. }
  25232. }
  25233. return imgData;
  25234. }
  25235. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25236. imgData.kind = ImageKind.RGB_24BPP;
  25237. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25238. drawWidth, drawHeight, true);
  25239. return imgData;
  25240. }
  25241. }
  25242. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25243. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25244. var actualHeight = 0 | (imgArray.length / rowBytes *
  25245. drawHeight / originalHeight);
  25246. var comps = this.getComponents(imgArray);
  25247. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25248. // more compact RGB_24BPP form if allowable.
  25249. var alpha01, maybeUndoPreblend;
  25250. if (!forceRGBA && !this.smask && !this.mask) {
  25251. imgData.kind = ImageKind.RGB_24BPP;
  25252. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25253. alpha01 = 0;
  25254. maybeUndoPreblend = false;
  25255. } else {
  25256. imgData.kind = ImageKind.RGBA_32BPP;
  25257. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25258. alpha01 = 1;
  25259. maybeUndoPreblend = true;
  25260. // Color key masking (opacity) must be performed before decoding.
  25261. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25262. comps);
  25263. }
  25264. if (this.needsDecode) {
  25265. this.decodeBuffer(comps);
  25266. }
  25267. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25268. drawWidth, drawHeight, actualHeight, bpc, comps,
  25269. alpha01);
  25270. if (maybeUndoPreblend) {
  25271. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25272. }
  25273. return imgData;
  25274. },
  25275. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25276. var numComps = this.numComps;
  25277. if (numComps !== 1) {
  25278. error('Reading gray scale from a color image: ' + numComps);
  25279. }
  25280. var width = this.width;
  25281. var height = this.height;
  25282. var bpc = this.bpc;
  25283. // rows start at byte boundary
  25284. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25285. var imgArray = this.getImageBytes(height * rowBytes);
  25286. var comps = this.getComponents(imgArray);
  25287. var i, length;
  25288. if (bpc === 1) {
  25289. // inline decoding (= inversion) for 1 bpc images
  25290. length = width * height;
  25291. if (this.needsDecode) {
  25292. // invert and scale to {0, 255}
  25293. for (i = 0; i < length; ++i) {
  25294. buffer[i] = (comps[i] - 1) & 255;
  25295. }
  25296. } else {
  25297. // scale to {0, 255}
  25298. for (i = 0; i < length; ++i) {
  25299. buffer[i] = (-comps[i]) & 255;
  25300. }
  25301. }
  25302. return;
  25303. }
  25304. if (this.needsDecode) {
  25305. this.decodeBuffer(comps);
  25306. }
  25307. length = width * height;
  25308. // we aren't using a colorspace so we need to scale the value
  25309. var scale = 255 / ((1 << bpc) - 1);
  25310. for (i = 0; i < length; ++i) {
  25311. buffer[i] = (scale * comps[i]) | 0;
  25312. }
  25313. },
  25314. getImageBytes: function PDFImage_getImageBytes(length,
  25315. drawWidth, drawHeight,
  25316. forceRGB) {
  25317. this.image.reset();
  25318. this.image.drawWidth = drawWidth || this.width;
  25319. this.image.drawHeight = drawHeight || this.height;
  25320. this.image.forceRGB = !!forceRGB;
  25321. return this.image.getBytes(length);
  25322. }
  25323. };
  25324. return PDFImage;
  25325. })();
  25326. // The Metrics object contains glyph widths (in glyph space units).
  25327. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25328. // space unit corresponds to 1/1000th of text space unit.
  25329. var Metrics = {
  25330. 'Courier': 600,
  25331. 'Courier-Bold': 600,
  25332. 'Courier-BoldOblique': 600,
  25333. 'Courier-Oblique': 600,
  25334. 'Helvetica' : {
  25335. 'space': 278,
  25336. 'exclam': 278,
  25337. 'quotedbl': 355,
  25338. 'numbersign': 556,
  25339. 'dollar': 556,
  25340. 'percent': 889,
  25341. 'ampersand': 667,
  25342. 'quoteright': 222,
  25343. 'parenleft': 333,
  25344. 'parenright': 333,
  25345. 'asterisk': 389,
  25346. 'plus': 584,
  25347. 'comma': 278,
  25348. 'hyphen': 333,
  25349. 'period': 278,
  25350. 'slash': 278,
  25351. 'zero': 556,
  25352. 'one': 556,
  25353. 'two': 556,
  25354. 'three': 556,
  25355. 'four': 556,
  25356. 'five': 556,
  25357. 'six': 556,
  25358. 'seven': 556,
  25359. 'eight': 556,
  25360. 'nine': 556,
  25361. 'colon': 278,
  25362. 'semicolon': 278,
  25363. 'less': 584,
  25364. 'equal': 584,
  25365. 'greater': 584,
  25366. 'question': 556,
  25367. 'at': 1015,
  25368. 'A': 667,
  25369. 'B': 667,
  25370. 'C': 722,
  25371. 'D': 722,
  25372. 'E': 667,
  25373. 'F': 611,
  25374. 'G': 778,
  25375. 'H': 722,
  25376. 'I': 278,
  25377. 'J': 500,
  25378. 'K': 667,
  25379. 'L': 556,
  25380. 'M': 833,
  25381. 'N': 722,
  25382. 'O': 778,
  25383. 'P': 667,
  25384. 'Q': 778,
  25385. 'R': 722,
  25386. 'S': 667,
  25387. 'T': 611,
  25388. 'U': 722,
  25389. 'V': 667,
  25390. 'W': 944,
  25391. 'X': 667,
  25392. 'Y': 667,
  25393. 'Z': 611,
  25394. 'bracketleft': 278,
  25395. 'backslash': 278,
  25396. 'bracketright': 278,
  25397. 'asciicircum': 469,
  25398. 'underscore': 556,
  25399. 'quoteleft': 222,
  25400. 'a': 556,
  25401. 'b': 556,
  25402. 'c': 500,
  25403. 'd': 556,
  25404. 'e': 556,
  25405. 'f': 278,
  25406. 'g': 556,
  25407. 'h': 556,
  25408. 'i': 222,
  25409. 'j': 222,
  25410. 'k': 500,
  25411. 'l': 222,
  25412. 'm': 833,
  25413. 'n': 556,
  25414. 'o': 556,
  25415. 'p': 556,
  25416. 'q': 556,
  25417. 'r': 333,
  25418. 's': 500,
  25419. 't': 278,
  25420. 'u': 556,
  25421. 'v': 500,
  25422. 'w': 722,
  25423. 'x': 500,
  25424. 'y': 500,
  25425. 'z': 500,
  25426. 'braceleft': 334,
  25427. 'bar': 260,
  25428. 'braceright': 334,
  25429. 'asciitilde': 584,
  25430. 'exclamdown': 333,
  25431. 'cent': 556,
  25432. 'sterling': 556,
  25433. 'fraction': 167,
  25434. 'yen': 556,
  25435. 'florin': 556,
  25436. 'section': 556,
  25437. 'currency': 556,
  25438. 'quotesingle': 191,
  25439. 'quotedblleft': 333,
  25440. 'guillemotleft': 556,
  25441. 'guilsinglleft': 333,
  25442. 'guilsinglright': 333,
  25443. 'fi': 500,
  25444. 'fl': 500,
  25445. 'endash': 556,
  25446. 'dagger': 556,
  25447. 'daggerdbl': 556,
  25448. 'periodcentered': 278,
  25449. 'paragraph': 537,
  25450. 'bullet': 350,
  25451. 'quotesinglbase': 222,
  25452. 'quotedblbase': 333,
  25453. 'quotedblright': 333,
  25454. 'guillemotright': 556,
  25455. 'ellipsis': 1000,
  25456. 'perthousand': 1000,
  25457. 'questiondown': 611,
  25458. 'grave': 333,
  25459. 'acute': 333,
  25460. 'circumflex': 333,
  25461. 'tilde': 333,
  25462. 'macron': 333,
  25463. 'breve': 333,
  25464. 'dotaccent': 333,
  25465. 'dieresis': 333,
  25466. 'ring': 333,
  25467. 'cedilla': 333,
  25468. 'hungarumlaut': 333,
  25469. 'ogonek': 333,
  25470. 'caron': 333,
  25471. 'emdash': 1000,
  25472. 'AE': 1000,
  25473. 'ordfeminine': 370,
  25474. 'Lslash': 556,
  25475. 'Oslash': 778,
  25476. 'OE': 1000,
  25477. 'ordmasculine': 365,
  25478. 'ae': 889,
  25479. 'dotlessi': 278,
  25480. 'lslash': 222,
  25481. 'oslash': 611,
  25482. 'oe': 944,
  25483. 'germandbls': 611,
  25484. 'Idieresis': 278,
  25485. 'eacute': 556,
  25486. 'abreve': 556,
  25487. 'uhungarumlaut': 556,
  25488. 'ecaron': 556,
  25489. 'Ydieresis': 667,
  25490. 'divide': 584,
  25491. 'Yacute': 667,
  25492. 'Acircumflex': 667,
  25493. 'aacute': 556,
  25494. 'Ucircumflex': 722,
  25495. 'yacute': 500,
  25496. 'scommaaccent': 500,
  25497. 'ecircumflex': 556,
  25498. 'Uring': 722,
  25499. 'Udieresis': 722,
  25500. 'aogonek': 556,
  25501. 'Uacute': 722,
  25502. 'uogonek': 556,
  25503. 'Edieresis': 667,
  25504. 'Dcroat': 722,
  25505. 'commaaccent': 250,
  25506. 'copyright': 737,
  25507. 'Emacron': 667,
  25508. 'ccaron': 500,
  25509. 'aring': 556,
  25510. 'Ncommaaccent': 722,
  25511. 'lacute': 222,
  25512. 'agrave': 556,
  25513. 'Tcommaaccent': 611,
  25514. 'Cacute': 722,
  25515. 'atilde': 556,
  25516. 'Edotaccent': 667,
  25517. 'scaron': 500,
  25518. 'scedilla': 500,
  25519. 'iacute': 278,
  25520. 'lozenge': 471,
  25521. 'Rcaron': 722,
  25522. 'Gcommaaccent': 778,
  25523. 'ucircumflex': 556,
  25524. 'acircumflex': 556,
  25525. 'Amacron': 667,
  25526. 'rcaron': 333,
  25527. 'ccedilla': 500,
  25528. 'Zdotaccent': 611,
  25529. 'Thorn': 667,
  25530. 'Omacron': 778,
  25531. 'Racute': 722,
  25532. 'Sacute': 667,
  25533. 'dcaron': 643,
  25534. 'Umacron': 722,
  25535. 'uring': 556,
  25536. 'threesuperior': 333,
  25537. 'Ograve': 778,
  25538. 'Agrave': 667,
  25539. 'Abreve': 667,
  25540. 'multiply': 584,
  25541. 'uacute': 556,
  25542. 'Tcaron': 611,
  25543. 'partialdiff': 476,
  25544. 'ydieresis': 500,
  25545. 'Nacute': 722,
  25546. 'icircumflex': 278,
  25547. 'Ecircumflex': 667,
  25548. 'adieresis': 556,
  25549. 'edieresis': 556,
  25550. 'cacute': 500,
  25551. 'nacute': 556,
  25552. 'umacron': 556,
  25553. 'Ncaron': 722,
  25554. 'Iacute': 278,
  25555. 'plusminus': 584,
  25556. 'brokenbar': 260,
  25557. 'registered': 737,
  25558. 'Gbreve': 778,
  25559. 'Idotaccent': 278,
  25560. 'summation': 600,
  25561. 'Egrave': 667,
  25562. 'racute': 333,
  25563. 'omacron': 556,
  25564. 'Zacute': 611,
  25565. 'Zcaron': 611,
  25566. 'greaterequal': 549,
  25567. 'Eth': 722,
  25568. 'Ccedilla': 722,
  25569. 'lcommaaccent': 222,
  25570. 'tcaron': 317,
  25571. 'eogonek': 556,
  25572. 'Uogonek': 722,
  25573. 'Aacute': 667,
  25574. 'Adieresis': 667,
  25575. 'egrave': 556,
  25576. 'zacute': 500,
  25577. 'iogonek': 222,
  25578. 'Oacute': 778,
  25579. 'oacute': 556,
  25580. 'amacron': 556,
  25581. 'sacute': 500,
  25582. 'idieresis': 278,
  25583. 'Ocircumflex': 778,
  25584. 'Ugrave': 722,
  25585. 'Delta': 612,
  25586. 'thorn': 556,
  25587. 'twosuperior': 333,
  25588. 'Odieresis': 778,
  25589. 'mu': 556,
  25590. 'igrave': 278,
  25591. 'ohungarumlaut': 556,
  25592. 'Eogonek': 667,
  25593. 'dcroat': 556,
  25594. 'threequarters': 834,
  25595. 'Scedilla': 667,
  25596. 'lcaron': 299,
  25597. 'Kcommaaccent': 667,
  25598. 'Lacute': 556,
  25599. 'trademark': 1000,
  25600. 'edotaccent': 556,
  25601. 'Igrave': 278,
  25602. 'Imacron': 278,
  25603. 'Lcaron': 556,
  25604. 'onehalf': 834,
  25605. 'lessequal': 549,
  25606. 'ocircumflex': 556,
  25607. 'ntilde': 556,
  25608. 'Uhungarumlaut': 722,
  25609. 'Eacute': 667,
  25610. 'emacron': 556,
  25611. 'gbreve': 556,
  25612. 'onequarter': 834,
  25613. 'Scaron': 667,
  25614. 'Scommaaccent': 667,
  25615. 'Ohungarumlaut': 778,
  25616. 'degree': 400,
  25617. 'ograve': 556,
  25618. 'Ccaron': 722,
  25619. 'ugrave': 556,
  25620. 'radical': 453,
  25621. 'Dcaron': 722,
  25622. 'rcommaaccent': 333,
  25623. 'Ntilde': 722,
  25624. 'otilde': 556,
  25625. 'Rcommaaccent': 722,
  25626. 'Lcommaaccent': 556,
  25627. 'Atilde': 667,
  25628. 'Aogonek': 667,
  25629. 'Aring': 667,
  25630. 'Otilde': 778,
  25631. 'zdotaccent': 500,
  25632. 'Ecaron': 667,
  25633. 'Iogonek': 278,
  25634. 'kcommaaccent': 500,
  25635. 'minus': 584,
  25636. 'Icircumflex': 278,
  25637. 'ncaron': 556,
  25638. 'tcommaaccent': 278,
  25639. 'logicalnot': 584,
  25640. 'odieresis': 556,
  25641. 'udieresis': 556,
  25642. 'notequal': 549,
  25643. 'gcommaaccent': 556,
  25644. 'eth': 556,
  25645. 'zcaron': 500,
  25646. 'ncommaaccent': 556,
  25647. 'onesuperior': 333,
  25648. 'imacron': 278,
  25649. 'Euro': 556
  25650. },
  25651. 'Helvetica-Bold': {
  25652. 'space': 278,
  25653. 'exclam': 333,
  25654. 'quotedbl': 474,
  25655. 'numbersign': 556,
  25656. 'dollar': 556,
  25657. 'percent': 889,
  25658. 'ampersand': 722,
  25659. 'quoteright': 278,
  25660. 'parenleft': 333,
  25661. 'parenright': 333,
  25662. 'asterisk': 389,
  25663. 'plus': 584,
  25664. 'comma': 278,
  25665. 'hyphen': 333,
  25666. 'period': 278,
  25667. 'slash': 278,
  25668. 'zero': 556,
  25669. 'one': 556,
  25670. 'two': 556,
  25671. 'three': 556,
  25672. 'four': 556,
  25673. 'five': 556,
  25674. 'six': 556,
  25675. 'seven': 556,
  25676. 'eight': 556,
  25677. 'nine': 556,
  25678. 'colon': 333,
  25679. 'semicolon': 333,
  25680. 'less': 584,
  25681. 'equal': 584,
  25682. 'greater': 584,
  25683. 'question': 611,
  25684. 'at': 975,
  25685. 'A': 722,
  25686. 'B': 722,
  25687. 'C': 722,
  25688. 'D': 722,
  25689. 'E': 667,
  25690. 'F': 611,
  25691. 'G': 778,
  25692. 'H': 722,
  25693. 'I': 278,
  25694. 'J': 556,
  25695. 'K': 722,
  25696. 'L': 611,
  25697. 'M': 833,
  25698. 'N': 722,
  25699. 'O': 778,
  25700. 'P': 667,
  25701. 'Q': 778,
  25702. 'R': 722,
  25703. 'S': 667,
  25704. 'T': 611,
  25705. 'U': 722,
  25706. 'V': 667,
  25707. 'W': 944,
  25708. 'X': 667,
  25709. 'Y': 667,
  25710. 'Z': 611,
  25711. 'bracketleft': 333,
  25712. 'backslash': 278,
  25713. 'bracketright': 333,
  25714. 'asciicircum': 584,
  25715. 'underscore': 556,
  25716. 'quoteleft': 278,
  25717. 'a': 556,
  25718. 'b': 611,
  25719. 'c': 556,
  25720. 'd': 611,
  25721. 'e': 556,
  25722. 'f': 333,
  25723. 'g': 611,
  25724. 'h': 611,
  25725. 'i': 278,
  25726. 'j': 278,
  25727. 'k': 556,
  25728. 'l': 278,
  25729. 'm': 889,
  25730. 'n': 611,
  25731. 'o': 611,
  25732. 'p': 611,
  25733. 'q': 611,
  25734. 'r': 389,
  25735. 's': 556,
  25736. 't': 333,
  25737. 'u': 611,
  25738. 'v': 556,
  25739. 'w': 778,
  25740. 'x': 556,
  25741. 'y': 556,
  25742. 'z': 500,
  25743. 'braceleft': 389,
  25744. 'bar': 280,
  25745. 'braceright': 389,
  25746. 'asciitilde': 584,
  25747. 'exclamdown': 333,
  25748. 'cent': 556,
  25749. 'sterling': 556,
  25750. 'fraction': 167,
  25751. 'yen': 556,
  25752. 'florin': 556,
  25753. 'section': 556,
  25754. 'currency': 556,
  25755. 'quotesingle': 238,
  25756. 'quotedblleft': 500,
  25757. 'guillemotleft': 556,
  25758. 'guilsinglleft': 333,
  25759. 'guilsinglright': 333,
  25760. 'fi': 611,
  25761. 'fl': 611,
  25762. 'endash': 556,
  25763. 'dagger': 556,
  25764. 'daggerdbl': 556,
  25765. 'periodcentered': 278,
  25766. 'paragraph': 556,
  25767. 'bullet': 350,
  25768. 'quotesinglbase': 278,
  25769. 'quotedblbase': 500,
  25770. 'quotedblright': 500,
  25771. 'guillemotright': 556,
  25772. 'ellipsis': 1000,
  25773. 'perthousand': 1000,
  25774. 'questiondown': 611,
  25775. 'grave': 333,
  25776. 'acute': 333,
  25777. 'circumflex': 333,
  25778. 'tilde': 333,
  25779. 'macron': 333,
  25780. 'breve': 333,
  25781. 'dotaccent': 333,
  25782. 'dieresis': 333,
  25783. 'ring': 333,
  25784. 'cedilla': 333,
  25785. 'hungarumlaut': 333,
  25786. 'ogonek': 333,
  25787. 'caron': 333,
  25788. 'emdash': 1000,
  25789. 'AE': 1000,
  25790. 'ordfeminine': 370,
  25791. 'Lslash': 611,
  25792. 'Oslash': 778,
  25793. 'OE': 1000,
  25794. 'ordmasculine': 365,
  25795. 'ae': 889,
  25796. 'dotlessi': 278,
  25797. 'lslash': 278,
  25798. 'oslash': 611,
  25799. 'oe': 944,
  25800. 'germandbls': 611,
  25801. 'Idieresis': 278,
  25802. 'eacute': 556,
  25803. 'abreve': 556,
  25804. 'uhungarumlaut': 611,
  25805. 'ecaron': 556,
  25806. 'Ydieresis': 667,
  25807. 'divide': 584,
  25808. 'Yacute': 667,
  25809. 'Acircumflex': 722,
  25810. 'aacute': 556,
  25811. 'Ucircumflex': 722,
  25812. 'yacute': 556,
  25813. 'scommaaccent': 556,
  25814. 'ecircumflex': 556,
  25815. 'Uring': 722,
  25816. 'Udieresis': 722,
  25817. 'aogonek': 556,
  25818. 'Uacute': 722,
  25819. 'uogonek': 611,
  25820. 'Edieresis': 667,
  25821. 'Dcroat': 722,
  25822. 'commaaccent': 250,
  25823. 'copyright': 737,
  25824. 'Emacron': 667,
  25825. 'ccaron': 556,
  25826. 'aring': 556,
  25827. 'Ncommaaccent': 722,
  25828. 'lacute': 278,
  25829. 'agrave': 556,
  25830. 'Tcommaaccent': 611,
  25831. 'Cacute': 722,
  25832. 'atilde': 556,
  25833. 'Edotaccent': 667,
  25834. 'scaron': 556,
  25835. 'scedilla': 556,
  25836. 'iacute': 278,
  25837. 'lozenge': 494,
  25838. 'Rcaron': 722,
  25839. 'Gcommaaccent': 778,
  25840. 'ucircumflex': 611,
  25841. 'acircumflex': 556,
  25842. 'Amacron': 722,
  25843. 'rcaron': 389,
  25844. 'ccedilla': 556,
  25845. 'Zdotaccent': 611,
  25846. 'Thorn': 667,
  25847. 'Omacron': 778,
  25848. 'Racute': 722,
  25849. 'Sacute': 667,
  25850. 'dcaron': 743,
  25851. 'Umacron': 722,
  25852. 'uring': 611,
  25853. 'threesuperior': 333,
  25854. 'Ograve': 778,
  25855. 'Agrave': 722,
  25856. 'Abreve': 722,
  25857. 'multiply': 584,
  25858. 'uacute': 611,
  25859. 'Tcaron': 611,
  25860. 'partialdiff': 494,
  25861. 'ydieresis': 556,
  25862. 'Nacute': 722,
  25863. 'icircumflex': 278,
  25864. 'Ecircumflex': 667,
  25865. 'adieresis': 556,
  25866. 'edieresis': 556,
  25867. 'cacute': 556,
  25868. 'nacute': 611,
  25869. 'umacron': 611,
  25870. 'Ncaron': 722,
  25871. 'Iacute': 278,
  25872. 'plusminus': 584,
  25873. 'brokenbar': 280,
  25874. 'registered': 737,
  25875. 'Gbreve': 778,
  25876. 'Idotaccent': 278,
  25877. 'summation': 600,
  25878. 'Egrave': 667,
  25879. 'racute': 389,
  25880. 'omacron': 611,
  25881. 'Zacute': 611,
  25882. 'Zcaron': 611,
  25883. 'greaterequal': 549,
  25884. 'Eth': 722,
  25885. 'Ccedilla': 722,
  25886. 'lcommaaccent': 278,
  25887. 'tcaron': 389,
  25888. 'eogonek': 556,
  25889. 'Uogonek': 722,
  25890. 'Aacute': 722,
  25891. 'Adieresis': 722,
  25892. 'egrave': 556,
  25893. 'zacute': 500,
  25894. 'iogonek': 278,
  25895. 'Oacute': 778,
  25896. 'oacute': 611,
  25897. 'amacron': 556,
  25898. 'sacute': 556,
  25899. 'idieresis': 278,
  25900. 'Ocircumflex': 778,
  25901. 'Ugrave': 722,
  25902. 'Delta': 612,
  25903. 'thorn': 611,
  25904. 'twosuperior': 333,
  25905. 'Odieresis': 778,
  25906. 'mu': 611,
  25907. 'igrave': 278,
  25908. 'ohungarumlaut': 611,
  25909. 'Eogonek': 667,
  25910. 'dcroat': 611,
  25911. 'threequarters': 834,
  25912. 'Scedilla': 667,
  25913. 'lcaron': 400,
  25914. 'Kcommaaccent': 722,
  25915. 'Lacute': 611,
  25916. 'trademark': 1000,
  25917. 'edotaccent': 556,
  25918. 'Igrave': 278,
  25919. 'Imacron': 278,
  25920. 'Lcaron': 611,
  25921. 'onehalf': 834,
  25922. 'lessequal': 549,
  25923. 'ocircumflex': 611,
  25924. 'ntilde': 611,
  25925. 'Uhungarumlaut': 722,
  25926. 'Eacute': 667,
  25927. 'emacron': 556,
  25928. 'gbreve': 611,
  25929. 'onequarter': 834,
  25930. 'Scaron': 667,
  25931. 'Scommaaccent': 667,
  25932. 'Ohungarumlaut': 778,
  25933. 'degree': 400,
  25934. 'ograve': 611,
  25935. 'Ccaron': 722,
  25936. 'ugrave': 611,
  25937. 'radical': 549,
  25938. 'Dcaron': 722,
  25939. 'rcommaaccent': 389,
  25940. 'Ntilde': 722,
  25941. 'otilde': 611,
  25942. 'Rcommaaccent': 722,
  25943. 'Lcommaaccent': 611,
  25944. 'Atilde': 722,
  25945. 'Aogonek': 722,
  25946. 'Aring': 722,
  25947. 'Otilde': 778,
  25948. 'zdotaccent': 500,
  25949. 'Ecaron': 667,
  25950. 'Iogonek': 278,
  25951. 'kcommaaccent': 556,
  25952. 'minus': 584,
  25953. 'Icircumflex': 278,
  25954. 'ncaron': 611,
  25955. 'tcommaaccent': 333,
  25956. 'logicalnot': 584,
  25957. 'odieresis': 611,
  25958. 'udieresis': 611,
  25959. 'notequal': 549,
  25960. 'gcommaaccent': 611,
  25961. 'eth': 611,
  25962. 'zcaron': 500,
  25963. 'ncommaaccent': 611,
  25964. 'onesuperior': 333,
  25965. 'imacron': 278,
  25966. 'Euro': 556
  25967. },
  25968. 'Helvetica-BoldOblique': {
  25969. 'space': 278,
  25970. 'exclam': 333,
  25971. 'quotedbl': 474,
  25972. 'numbersign': 556,
  25973. 'dollar': 556,
  25974. 'percent': 889,
  25975. 'ampersand': 722,
  25976. 'quoteright': 278,
  25977. 'parenleft': 333,
  25978. 'parenright': 333,
  25979. 'asterisk': 389,
  25980. 'plus': 584,
  25981. 'comma': 278,
  25982. 'hyphen': 333,
  25983. 'period': 278,
  25984. 'slash': 278,
  25985. 'zero': 556,
  25986. 'one': 556,
  25987. 'two': 556,
  25988. 'three': 556,
  25989. 'four': 556,
  25990. 'five': 556,
  25991. 'six': 556,
  25992. 'seven': 556,
  25993. 'eight': 556,
  25994. 'nine': 556,
  25995. 'colon': 333,
  25996. 'semicolon': 333,
  25997. 'less': 584,
  25998. 'equal': 584,
  25999. 'greater': 584,
  26000. 'question': 611,
  26001. 'at': 975,
  26002. 'A': 722,
  26003. 'B': 722,
  26004. 'C': 722,
  26005. 'D': 722,
  26006. 'E': 667,
  26007. 'F': 611,
  26008. 'G': 778,
  26009. 'H': 722,
  26010. 'I': 278,
  26011. 'J': 556,
  26012. 'K': 722,
  26013. 'L': 611,
  26014. 'M': 833,
  26015. 'N': 722,
  26016. 'O': 778,
  26017. 'P': 667,
  26018. 'Q': 778,
  26019. 'R': 722,
  26020. 'S': 667,
  26021. 'T': 611,
  26022. 'U': 722,
  26023. 'V': 667,
  26024. 'W': 944,
  26025. 'X': 667,
  26026. 'Y': 667,
  26027. 'Z': 611,
  26028. 'bracketleft': 333,
  26029. 'backslash': 278,
  26030. 'bracketright': 333,
  26031. 'asciicircum': 584,
  26032. 'underscore': 556,
  26033. 'quoteleft': 278,
  26034. 'a': 556,
  26035. 'b': 611,
  26036. 'c': 556,
  26037. 'd': 611,
  26038. 'e': 556,
  26039. 'f': 333,
  26040. 'g': 611,
  26041. 'h': 611,
  26042. 'i': 278,
  26043. 'j': 278,
  26044. 'k': 556,
  26045. 'l': 278,
  26046. 'm': 889,
  26047. 'n': 611,
  26048. 'o': 611,
  26049. 'p': 611,
  26050. 'q': 611,
  26051. 'r': 389,
  26052. 's': 556,
  26053. 't': 333,
  26054. 'u': 611,
  26055. 'v': 556,
  26056. 'w': 778,
  26057. 'x': 556,
  26058. 'y': 556,
  26059. 'z': 500,
  26060. 'braceleft': 389,
  26061. 'bar': 280,
  26062. 'braceright': 389,
  26063. 'asciitilde': 584,
  26064. 'exclamdown': 333,
  26065. 'cent': 556,
  26066. 'sterling': 556,
  26067. 'fraction': 167,
  26068. 'yen': 556,
  26069. 'florin': 556,
  26070. 'section': 556,
  26071. 'currency': 556,
  26072. 'quotesingle': 238,
  26073. 'quotedblleft': 500,
  26074. 'guillemotleft': 556,
  26075. 'guilsinglleft': 333,
  26076. 'guilsinglright': 333,
  26077. 'fi': 611,
  26078. 'fl': 611,
  26079. 'endash': 556,
  26080. 'dagger': 556,
  26081. 'daggerdbl': 556,
  26082. 'periodcentered': 278,
  26083. 'paragraph': 556,
  26084. 'bullet': 350,
  26085. 'quotesinglbase': 278,
  26086. 'quotedblbase': 500,
  26087. 'quotedblright': 500,
  26088. 'guillemotright': 556,
  26089. 'ellipsis': 1000,
  26090. 'perthousand': 1000,
  26091. 'questiondown': 611,
  26092. 'grave': 333,
  26093. 'acute': 333,
  26094. 'circumflex': 333,
  26095. 'tilde': 333,
  26096. 'macron': 333,
  26097. 'breve': 333,
  26098. 'dotaccent': 333,
  26099. 'dieresis': 333,
  26100. 'ring': 333,
  26101. 'cedilla': 333,
  26102. 'hungarumlaut': 333,
  26103. 'ogonek': 333,
  26104. 'caron': 333,
  26105. 'emdash': 1000,
  26106. 'AE': 1000,
  26107. 'ordfeminine': 370,
  26108. 'Lslash': 611,
  26109. 'Oslash': 778,
  26110. 'OE': 1000,
  26111. 'ordmasculine': 365,
  26112. 'ae': 889,
  26113. 'dotlessi': 278,
  26114. 'lslash': 278,
  26115. 'oslash': 611,
  26116. 'oe': 944,
  26117. 'germandbls': 611,
  26118. 'Idieresis': 278,
  26119. 'eacute': 556,
  26120. 'abreve': 556,
  26121. 'uhungarumlaut': 611,
  26122. 'ecaron': 556,
  26123. 'Ydieresis': 667,
  26124. 'divide': 584,
  26125. 'Yacute': 667,
  26126. 'Acircumflex': 722,
  26127. 'aacute': 556,
  26128. 'Ucircumflex': 722,
  26129. 'yacute': 556,
  26130. 'scommaaccent': 556,
  26131. 'ecircumflex': 556,
  26132. 'Uring': 722,
  26133. 'Udieresis': 722,
  26134. 'aogonek': 556,
  26135. 'Uacute': 722,
  26136. 'uogonek': 611,
  26137. 'Edieresis': 667,
  26138. 'Dcroat': 722,
  26139. 'commaaccent': 250,
  26140. 'copyright': 737,
  26141. 'Emacron': 667,
  26142. 'ccaron': 556,
  26143. 'aring': 556,
  26144. 'Ncommaaccent': 722,
  26145. 'lacute': 278,
  26146. 'agrave': 556,
  26147. 'Tcommaaccent': 611,
  26148. 'Cacute': 722,
  26149. 'atilde': 556,
  26150. 'Edotaccent': 667,
  26151. 'scaron': 556,
  26152. 'scedilla': 556,
  26153. 'iacute': 278,
  26154. 'lozenge': 494,
  26155. 'Rcaron': 722,
  26156. 'Gcommaaccent': 778,
  26157. 'ucircumflex': 611,
  26158. 'acircumflex': 556,
  26159. 'Amacron': 722,
  26160. 'rcaron': 389,
  26161. 'ccedilla': 556,
  26162. 'Zdotaccent': 611,
  26163. 'Thorn': 667,
  26164. 'Omacron': 778,
  26165. 'Racute': 722,
  26166. 'Sacute': 667,
  26167. 'dcaron': 743,
  26168. 'Umacron': 722,
  26169. 'uring': 611,
  26170. 'threesuperior': 333,
  26171. 'Ograve': 778,
  26172. 'Agrave': 722,
  26173. 'Abreve': 722,
  26174. 'multiply': 584,
  26175. 'uacute': 611,
  26176. 'Tcaron': 611,
  26177. 'partialdiff': 494,
  26178. 'ydieresis': 556,
  26179. 'Nacute': 722,
  26180. 'icircumflex': 278,
  26181. 'Ecircumflex': 667,
  26182. 'adieresis': 556,
  26183. 'edieresis': 556,
  26184. 'cacute': 556,
  26185. 'nacute': 611,
  26186. 'umacron': 611,
  26187. 'Ncaron': 722,
  26188. 'Iacute': 278,
  26189. 'plusminus': 584,
  26190. 'brokenbar': 280,
  26191. 'registered': 737,
  26192. 'Gbreve': 778,
  26193. 'Idotaccent': 278,
  26194. 'summation': 600,
  26195. 'Egrave': 667,
  26196. 'racute': 389,
  26197. 'omacron': 611,
  26198. 'Zacute': 611,
  26199. 'Zcaron': 611,
  26200. 'greaterequal': 549,
  26201. 'Eth': 722,
  26202. 'Ccedilla': 722,
  26203. 'lcommaaccent': 278,
  26204. 'tcaron': 389,
  26205. 'eogonek': 556,
  26206. 'Uogonek': 722,
  26207. 'Aacute': 722,
  26208. 'Adieresis': 722,
  26209. 'egrave': 556,
  26210. 'zacute': 500,
  26211. 'iogonek': 278,
  26212. 'Oacute': 778,
  26213. 'oacute': 611,
  26214. 'amacron': 556,
  26215. 'sacute': 556,
  26216. 'idieresis': 278,
  26217. 'Ocircumflex': 778,
  26218. 'Ugrave': 722,
  26219. 'Delta': 612,
  26220. 'thorn': 611,
  26221. 'twosuperior': 333,
  26222. 'Odieresis': 778,
  26223. 'mu': 611,
  26224. 'igrave': 278,
  26225. 'ohungarumlaut': 611,
  26226. 'Eogonek': 667,
  26227. 'dcroat': 611,
  26228. 'threequarters': 834,
  26229. 'Scedilla': 667,
  26230. 'lcaron': 400,
  26231. 'Kcommaaccent': 722,
  26232. 'Lacute': 611,
  26233. 'trademark': 1000,
  26234. 'edotaccent': 556,
  26235. 'Igrave': 278,
  26236. 'Imacron': 278,
  26237. 'Lcaron': 611,
  26238. 'onehalf': 834,
  26239. 'lessequal': 549,
  26240. 'ocircumflex': 611,
  26241. 'ntilde': 611,
  26242. 'Uhungarumlaut': 722,
  26243. 'Eacute': 667,
  26244. 'emacron': 556,
  26245. 'gbreve': 611,
  26246. 'onequarter': 834,
  26247. 'Scaron': 667,
  26248. 'Scommaaccent': 667,
  26249. 'Ohungarumlaut': 778,
  26250. 'degree': 400,
  26251. 'ograve': 611,
  26252. 'Ccaron': 722,
  26253. 'ugrave': 611,
  26254. 'radical': 549,
  26255. 'Dcaron': 722,
  26256. 'rcommaaccent': 389,
  26257. 'Ntilde': 722,
  26258. 'otilde': 611,
  26259. 'Rcommaaccent': 722,
  26260. 'Lcommaaccent': 611,
  26261. 'Atilde': 722,
  26262. 'Aogonek': 722,
  26263. 'Aring': 722,
  26264. 'Otilde': 778,
  26265. 'zdotaccent': 500,
  26266. 'Ecaron': 667,
  26267. 'Iogonek': 278,
  26268. 'kcommaaccent': 556,
  26269. 'minus': 584,
  26270. 'Icircumflex': 278,
  26271. 'ncaron': 611,
  26272. 'tcommaaccent': 333,
  26273. 'logicalnot': 584,
  26274. 'odieresis': 611,
  26275. 'udieresis': 611,
  26276. 'notequal': 549,
  26277. 'gcommaaccent': 611,
  26278. 'eth': 611,
  26279. 'zcaron': 500,
  26280. 'ncommaaccent': 611,
  26281. 'onesuperior': 333,
  26282. 'imacron': 278,
  26283. 'Euro': 556
  26284. },
  26285. 'Helvetica-Oblique' : {
  26286. 'space': 278,
  26287. 'exclam': 278,
  26288. 'quotedbl': 355,
  26289. 'numbersign': 556,
  26290. 'dollar': 556,
  26291. 'percent': 889,
  26292. 'ampersand': 667,
  26293. 'quoteright': 222,
  26294. 'parenleft': 333,
  26295. 'parenright': 333,
  26296. 'asterisk': 389,
  26297. 'plus': 584,
  26298. 'comma': 278,
  26299. 'hyphen': 333,
  26300. 'period': 278,
  26301. 'slash': 278,
  26302. 'zero': 556,
  26303. 'one': 556,
  26304. 'two': 556,
  26305. 'three': 556,
  26306. 'four': 556,
  26307. 'five': 556,
  26308. 'six': 556,
  26309. 'seven': 556,
  26310. 'eight': 556,
  26311. 'nine': 556,
  26312. 'colon': 278,
  26313. 'semicolon': 278,
  26314. 'less': 584,
  26315. 'equal': 584,
  26316. 'greater': 584,
  26317. 'question': 556,
  26318. 'at': 1015,
  26319. 'A': 667,
  26320. 'B': 667,
  26321. 'C': 722,
  26322. 'D': 722,
  26323. 'E': 667,
  26324. 'F': 611,
  26325. 'G': 778,
  26326. 'H': 722,
  26327. 'I': 278,
  26328. 'J': 500,
  26329. 'K': 667,
  26330. 'L': 556,
  26331. 'M': 833,
  26332. 'N': 722,
  26333. 'O': 778,
  26334. 'P': 667,
  26335. 'Q': 778,
  26336. 'R': 722,
  26337. 'S': 667,
  26338. 'T': 611,
  26339. 'U': 722,
  26340. 'V': 667,
  26341. 'W': 944,
  26342. 'X': 667,
  26343. 'Y': 667,
  26344. 'Z': 611,
  26345. 'bracketleft': 278,
  26346. 'backslash': 278,
  26347. 'bracketright': 278,
  26348. 'asciicircum': 469,
  26349. 'underscore': 556,
  26350. 'quoteleft': 222,
  26351. 'a': 556,
  26352. 'b': 556,
  26353. 'c': 500,
  26354. 'd': 556,
  26355. 'e': 556,
  26356. 'f': 278,
  26357. 'g': 556,
  26358. 'h': 556,
  26359. 'i': 222,
  26360. 'j': 222,
  26361. 'k': 500,
  26362. 'l': 222,
  26363. 'm': 833,
  26364. 'n': 556,
  26365. 'o': 556,
  26366. 'p': 556,
  26367. 'q': 556,
  26368. 'r': 333,
  26369. 's': 500,
  26370. 't': 278,
  26371. 'u': 556,
  26372. 'v': 500,
  26373. 'w': 722,
  26374. 'x': 500,
  26375. 'y': 500,
  26376. 'z': 500,
  26377. 'braceleft': 334,
  26378. 'bar': 260,
  26379. 'braceright': 334,
  26380. 'asciitilde': 584,
  26381. 'exclamdown': 333,
  26382. 'cent': 556,
  26383. 'sterling': 556,
  26384. 'fraction': 167,
  26385. 'yen': 556,
  26386. 'florin': 556,
  26387. 'section': 556,
  26388. 'currency': 556,
  26389. 'quotesingle': 191,
  26390. 'quotedblleft': 333,
  26391. 'guillemotleft': 556,
  26392. 'guilsinglleft': 333,
  26393. 'guilsinglright': 333,
  26394. 'fi': 500,
  26395. 'fl': 500,
  26396. 'endash': 556,
  26397. 'dagger': 556,
  26398. 'daggerdbl': 556,
  26399. 'periodcentered': 278,
  26400. 'paragraph': 537,
  26401. 'bullet': 350,
  26402. 'quotesinglbase': 222,
  26403. 'quotedblbase': 333,
  26404. 'quotedblright': 333,
  26405. 'guillemotright': 556,
  26406. 'ellipsis': 1000,
  26407. 'perthousand': 1000,
  26408. 'questiondown': 611,
  26409. 'grave': 333,
  26410. 'acute': 333,
  26411. 'circumflex': 333,
  26412. 'tilde': 333,
  26413. 'macron': 333,
  26414. 'breve': 333,
  26415. 'dotaccent': 333,
  26416. 'dieresis': 333,
  26417. 'ring': 333,
  26418. 'cedilla': 333,
  26419. 'hungarumlaut': 333,
  26420. 'ogonek': 333,
  26421. 'caron': 333,
  26422. 'emdash': 1000,
  26423. 'AE': 1000,
  26424. 'ordfeminine': 370,
  26425. 'Lslash': 556,
  26426. 'Oslash': 778,
  26427. 'OE': 1000,
  26428. 'ordmasculine': 365,
  26429. 'ae': 889,
  26430. 'dotlessi': 278,
  26431. 'lslash': 222,
  26432. 'oslash': 611,
  26433. 'oe': 944,
  26434. 'germandbls': 611,
  26435. 'Idieresis': 278,
  26436. 'eacute': 556,
  26437. 'abreve': 556,
  26438. 'uhungarumlaut': 556,
  26439. 'ecaron': 556,
  26440. 'Ydieresis': 667,
  26441. 'divide': 584,
  26442. 'Yacute': 667,
  26443. 'Acircumflex': 667,
  26444. 'aacute': 556,
  26445. 'Ucircumflex': 722,
  26446. 'yacute': 500,
  26447. 'scommaaccent': 500,
  26448. 'ecircumflex': 556,
  26449. 'Uring': 722,
  26450. 'Udieresis': 722,
  26451. 'aogonek': 556,
  26452. 'Uacute': 722,
  26453. 'uogonek': 556,
  26454. 'Edieresis': 667,
  26455. 'Dcroat': 722,
  26456. 'commaaccent': 250,
  26457. 'copyright': 737,
  26458. 'Emacron': 667,
  26459. 'ccaron': 500,
  26460. 'aring': 556,
  26461. 'Ncommaaccent': 722,
  26462. 'lacute': 222,
  26463. 'agrave': 556,
  26464. 'Tcommaaccent': 611,
  26465. 'Cacute': 722,
  26466. 'atilde': 556,
  26467. 'Edotaccent': 667,
  26468. 'scaron': 500,
  26469. 'scedilla': 500,
  26470. 'iacute': 278,
  26471. 'lozenge': 471,
  26472. 'Rcaron': 722,
  26473. 'Gcommaaccent': 778,
  26474. 'ucircumflex': 556,
  26475. 'acircumflex': 556,
  26476. 'Amacron': 667,
  26477. 'rcaron': 333,
  26478. 'ccedilla': 500,
  26479. 'Zdotaccent': 611,
  26480. 'Thorn': 667,
  26481. 'Omacron': 778,
  26482. 'Racute': 722,
  26483. 'Sacute': 667,
  26484. 'dcaron': 643,
  26485. 'Umacron': 722,
  26486. 'uring': 556,
  26487. 'threesuperior': 333,
  26488. 'Ograve': 778,
  26489. 'Agrave': 667,
  26490. 'Abreve': 667,
  26491. 'multiply': 584,
  26492. 'uacute': 556,
  26493. 'Tcaron': 611,
  26494. 'partialdiff': 476,
  26495. 'ydieresis': 500,
  26496. 'Nacute': 722,
  26497. 'icircumflex': 278,
  26498. 'Ecircumflex': 667,
  26499. 'adieresis': 556,
  26500. 'edieresis': 556,
  26501. 'cacute': 500,
  26502. 'nacute': 556,
  26503. 'umacron': 556,
  26504. 'Ncaron': 722,
  26505. 'Iacute': 278,
  26506. 'plusminus': 584,
  26507. 'brokenbar': 260,
  26508. 'registered': 737,
  26509. 'Gbreve': 778,
  26510. 'Idotaccent': 278,
  26511. 'summation': 600,
  26512. 'Egrave': 667,
  26513. 'racute': 333,
  26514. 'omacron': 556,
  26515. 'Zacute': 611,
  26516. 'Zcaron': 611,
  26517. 'greaterequal': 549,
  26518. 'Eth': 722,
  26519. 'Ccedilla': 722,
  26520. 'lcommaaccent': 222,
  26521. 'tcaron': 317,
  26522. 'eogonek': 556,
  26523. 'Uogonek': 722,
  26524. 'Aacute': 667,
  26525. 'Adieresis': 667,
  26526. 'egrave': 556,
  26527. 'zacute': 500,
  26528. 'iogonek': 222,
  26529. 'Oacute': 778,
  26530. 'oacute': 556,
  26531. 'amacron': 556,
  26532. 'sacute': 500,
  26533. 'idieresis': 278,
  26534. 'Ocircumflex': 778,
  26535. 'Ugrave': 722,
  26536. 'Delta': 612,
  26537. 'thorn': 556,
  26538. 'twosuperior': 333,
  26539. 'Odieresis': 778,
  26540. 'mu': 556,
  26541. 'igrave': 278,
  26542. 'ohungarumlaut': 556,
  26543. 'Eogonek': 667,
  26544. 'dcroat': 556,
  26545. 'threequarters': 834,
  26546. 'Scedilla': 667,
  26547. 'lcaron': 299,
  26548. 'Kcommaaccent': 667,
  26549. 'Lacute': 556,
  26550. 'trademark': 1000,
  26551. 'edotaccent': 556,
  26552. 'Igrave': 278,
  26553. 'Imacron': 278,
  26554. 'Lcaron': 556,
  26555. 'onehalf': 834,
  26556. 'lessequal': 549,
  26557. 'ocircumflex': 556,
  26558. 'ntilde': 556,
  26559. 'Uhungarumlaut': 722,
  26560. 'Eacute': 667,
  26561. 'emacron': 556,
  26562. 'gbreve': 556,
  26563. 'onequarter': 834,
  26564. 'Scaron': 667,
  26565. 'Scommaaccent': 667,
  26566. 'Ohungarumlaut': 778,
  26567. 'degree': 400,
  26568. 'ograve': 556,
  26569. 'Ccaron': 722,
  26570. 'ugrave': 556,
  26571. 'radical': 453,
  26572. 'Dcaron': 722,
  26573. 'rcommaaccent': 333,
  26574. 'Ntilde': 722,
  26575. 'otilde': 556,
  26576. 'Rcommaaccent': 722,
  26577. 'Lcommaaccent': 556,
  26578. 'Atilde': 667,
  26579. 'Aogonek': 667,
  26580. 'Aring': 667,
  26581. 'Otilde': 778,
  26582. 'zdotaccent': 500,
  26583. 'Ecaron': 667,
  26584. 'Iogonek': 278,
  26585. 'kcommaaccent': 500,
  26586. 'minus': 584,
  26587. 'Icircumflex': 278,
  26588. 'ncaron': 556,
  26589. 'tcommaaccent': 278,
  26590. 'logicalnot': 584,
  26591. 'odieresis': 556,
  26592. 'udieresis': 556,
  26593. 'notequal': 549,
  26594. 'gcommaaccent': 556,
  26595. 'eth': 556,
  26596. 'zcaron': 500,
  26597. 'ncommaaccent': 556,
  26598. 'onesuperior': 333,
  26599. 'imacron': 278,
  26600. 'Euro': 556
  26601. },
  26602. 'Symbol': {
  26603. 'space': 250,
  26604. 'exclam': 333,
  26605. 'universal': 713,
  26606. 'numbersign': 500,
  26607. 'existential': 549,
  26608. 'percent': 833,
  26609. 'ampersand': 778,
  26610. 'suchthat': 439,
  26611. 'parenleft': 333,
  26612. 'parenright': 333,
  26613. 'asteriskmath': 500,
  26614. 'plus': 549,
  26615. 'comma': 250,
  26616. 'minus': 549,
  26617. 'period': 250,
  26618. 'slash': 278,
  26619. 'zero': 500,
  26620. 'one': 500,
  26621. 'two': 500,
  26622. 'three': 500,
  26623. 'four': 500,
  26624. 'five': 500,
  26625. 'six': 500,
  26626. 'seven': 500,
  26627. 'eight': 500,
  26628. 'nine': 500,
  26629. 'colon': 278,
  26630. 'semicolon': 278,
  26631. 'less': 549,
  26632. 'equal': 549,
  26633. 'greater': 549,
  26634. 'question': 444,
  26635. 'congruent': 549,
  26636. 'Alpha': 722,
  26637. 'Beta': 667,
  26638. 'Chi': 722,
  26639. 'Delta': 612,
  26640. 'Epsilon': 611,
  26641. 'Phi': 763,
  26642. 'Gamma': 603,
  26643. 'Eta': 722,
  26644. 'Iota': 333,
  26645. 'theta1': 631,
  26646. 'Kappa': 722,
  26647. 'Lambda': 686,
  26648. 'Mu': 889,
  26649. 'Nu': 722,
  26650. 'Omicron': 722,
  26651. 'Pi': 768,
  26652. 'Theta': 741,
  26653. 'Rho': 556,
  26654. 'Sigma': 592,
  26655. 'Tau': 611,
  26656. 'Upsilon': 690,
  26657. 'sigma1': 439,
  26658. 'Omega': 768,
  26659. 'Xi': 645,
  26660. 'Psi': 795,
  26661. 'Zeta': 611,
  26662. 'bracketleft': 333,
  26663. 'therefore': 863,
  26664. 'bracketright': 333,
  26665. 'perpendicular': 658,
  26666. 'underscore': 500,
  26667. 'radicalex': 500,
  26668. 'alpha': 631,
  26669. 'beta': 549,
  26670. 'chi': 549,
  26671. 'delta': 494,
  26672. 'epsilon': 439,
  26673. 'phi': 521,
  26674. 'gamma': 411,
  26675. 'eta': 603,
  26676. 'iota': 329,
  26677. 'phi1': 603,
  26678. 'kappa': 549,
  26679. 'lambda': 549,
  26680. 'mu': 576,
  26681. 'nu': 521,
  26682. 'omicron': 549,
  26683. 'pi': 549,
  26684. 'theta': 521,
  26685. 'rho': 549,
  26686. 'sigma': 603,
  26687. 'tau': 439,
  26688. 'upsilon': 576,
  26689. 'omega1': 713,
  26690. 'omega': 686,
  26691. 'xi': 493,
  26692. 'psi': 686,
  26693. 'zeta': 494,
  26694. 'braceleft': 480,
  26695. 'bar': 200,
  26696. 'braceright': 480,
  26697. 'similar': 549,
  26698. 'Euro': 750,
  26699. 'Upsilon1': 620,
  26700. 'minute': 247,
  26701. 'lessequal': 549,
  26702. 'fraction': 167,
  26703. 'infinity': 713,
  26704. 'florin': 500,
  26705. 'club': 753,
  26706. 'diamond': 753,
  26707. 'heart': 753,
  26708. 'spade': 753,
  26709. 'arrowboth': 1042,
  26710. 'arrowleft': 987,
  26711. 'arrowup': 603,
  26712. 'arrowright': 987,
  26713. 'arrowdown': 603,
  26714. 'degree': 400,
  26715. 'plusminus': 549,
  26716. 'second': 411,
  26717. 'greaterequal': 549,
  26718. 'multiply': 549,
  26719. 'proportional': 713,
  26720. 'partialdiff': 494,
  26721. 'bullet': 460,
  26722. 'divide': 549,
  26723. 'notequal': 549,
  26724. 'equivalence': 549,
  26725. 'approxequal': 549,
  26726. 'ellipsis': 1000,
  26727. 'arrowvertex': 603,
  26728. 'arrowhorizex': 1000,
  26729. 'carriagereturn': 658,
  26730. 'aleph': 823,
  26731. 'Ifraktur': 686,
  26732. 'Rfraktur': 795,
  26733. 'weierstrass': 987,
  26734. 'circlemultiply': 768,
  26735. 'circleplus': 768,
  26736. 'emptyset': 823,
  26737. 'intersection': 768,
  26738. 'union': 768,
  26739. 'propersuperset': 713,
  26740. 'reflexsuperset': 713,
  26741. 'notsubset': 713,
  26742. 'propersubset': 713,
  26743. 'reflexsubset': 713,
  26744. 'element': 713,
  26745. 'notelement': 713,
  26746. 'angle': 768,
  26747. 'gradient': 713,
  26748. 'registerserif': 790,
  26749. 'copyrightserif': 790,
  26750. 'trademarkserif': 890,
  26751. 'product': 823,
  26752. 'radical': 549,
  26753. 'dotmath': 250,
  26754. 'logicalnot': 713,
  26755. 'logicaland': 603,
  26756. 'logicalor': 603,
  26757. 'arrowdblboth': 1042,
  26758. 'arrowdblleft': 987,
  26759. 'arrowdblup': 603,
  26760. 'arrowdblright': 987,
  26761. 'arrowdbldown': 603,
  26762. 'lozenge': 494,
  26763. 'angleleft': 329,
  26764. 'registersans': 790,
  26765. 'copyrightsans': 790,
  26766. 'trademarksans': 786,
  26767. 'summation': 713,
  26768. 'parenlefttp': 384,
  26769. 'parenleftex': 384,
  26770. 'parenleftbt': 384,
  26771. 'bracketlefttp': 384,
  26772. 'bracketleftex': 384,
  26773. 'bracketleftbt': 384,
  26774. 'bracelefttp': 494,
  26775. 'braceleftmid': 494,
  26776. 'braceleftbt': 494,
  26777. 'braceex': 494,
  26778. 'angleright': 329,
  26779. 'integral': 274,
  26780. 'integraltp': 686,
  26781. 'integralex': 686,
  26782. 'integralbt': 686,
  26783. 'parenrighttp': 384,
  26784. 'parenrightex': 384,
  26785. 'parenrightbt': 384,
  26786. 'bracketrighttp': 384,
  26787. 'bracketrightex': 384,
  26788. 'bracketrightbt': 384,
  26789. 'bracerighttp': 494,
  26790. 'bracerightmid': 494,
  26791. 'bracerightbt': 494,
  26792. 'apple': 790
  26793. },
  26794. 'Times-Roman': {
  26795. 'space': 250,
  26796. 'exclam': 333,
  26797. 'quotedbl': 408,
  26798. 'numbersign': 500,
  26799. 'dollar': 500,
  26800. 'percent': 833,
  26801. 'ampersand': 778,
  26802. 'quoteright': 333,
  26803. 'parenleft': 333,
  26804. 'parenright': 333,
  26805. 'asterisk': 500,
  26806. 'plus': 564,
  26807. 'comma': 250,
  26808. 'hyphen': 333,
  26809. 'period': 250,
  26810. 'slash': 278,
  26811. 'zero': 500,
  26812. 'one': 500,
  26813. 'two': 500,
  26814. 'three': 500,
  26815. 'four': 500,
  26816. 'five': 500,
  26817. 'six': 500,
  26818. 'seven': 500,
  26819. 'eight': 500,
  26820. 'nine': 500,
  26821. 'colon': 278,
  26822. 'semicolon': 278,
  26823. 'less': 564,
  26824. 'equal': 564,
  26825. 'greater': 564,
  26826. 'question': 444,
  26827. 'at': 921,
  26828. 'A': 722,
  26829. 'B': 667,
  26830. 'C': 667,
  26831. 'D': 722,
  26832. 'E': 611,
  26833. 'F': 556,
  26834. 'G': 722,
  26835. 'H': 722,
  26836. 'I': 333,
  26837. 'J': 389,
  26838. 'K': 722,
  26839. 'L': 611,
  26840. 'M': 889,
  26841. 'N': 722,
  26842. 'O': 722,
  26843. 'P': 556,
  26844. 'Q': 722,
  26845. 'R': 667,
  26846. 'S': 556,
  26847. 'T': 611,
  26848. 'U': 722,
  26849. 'V': 722,
  26850. 'W': 944,
  26851. 'X': 722,
  26852. 'Y': 722,
  26853. 'Z': 611,
  26854. 'bracketleft': 333,
  26855. 'backslash': 278,
  26856. 'bracketright': 333,
  26857. 'asciicircum': 469,
  26858. 'underscore': 500,
  26859. 'quoteleft': 333,
  26860. 'a': 444,
  26861. 'b': 500,
  26862. 'c': 444,
  26863. 'd': 500,
  26864. 'e': 444,
  26865. 'f': 333,
  26866. 'g': 500,
  26867. 'h': 500,
  26868. 'i': 278,
  26869. 'j': 278,
  26870. 'k': 500,
  26871. 'l': 278,
  26872. 'm': 778,
  26873. 'n': 500,
  26874. 'o': 500,
  26875. 'p': 500,
  26876. 'q': 500,
  26877. 'r': 333,
  26878. 's': 389,
  26879. 't': 278,
  26880. 'u': 500,
  26881. 'v': 500,
  26882. 'w': 722,
  26883. 'x': 500,
  26884. 'y': 500,
  26885. 'z': 444,
  26886. 'braceleft': 480,
  26887. 'bar': 200,
  26888. 'braceright': 480,
  26889. 'asciitilde': 541,
  26890. 'exclamdown': 333,
  26891. 'cent': 500,
  26892. 'sterling': 500,
  26893. 'fraction': 167,
  26894. 'yen': 500,
  26895. 'florin': 500,
  26896. 'section': 500,
  26897. 'currency': 500,
  26898. 'quotesingle': 180,
  26899. 'quotedblleft': 444,
  26900. 'guillemotleft': 500,
  26901. 'guilsinglleft': 333,
  26902. 'guilsinglright': 333,
  26903. 'fi': 556,
  26904. 'fl': 556,
  26905. 'endash': 500,
  26906. 'dagger': 500,
  26907. 'daggerdbl': 500,
  26908. 'periodcentered': 250,
  26909. 'paragraph': 453,
  26910. 'bullet': 350,
  26911. 'quotesinglbase': 333,
  26912. 'quotedblbase': 444,
  26913. 'quotedblright': 444,
  26914. 'guillemotright': 500,
  26915. 'ellipsis': 1000,
  26916. 'perthousand': 1000,
  26917. 'questiondown': 444,
  26918. 'grave': 333,
  26919. 'acute': 333,
  26920. 'circumflex': 333,
  26921. 'tilde': 333,
  26922. 'macron': 333,
  26923. 'breve': 333,
  26924. 'dotaccent': 333,
  26925. 'dieresis': 333,
  26926. 'ring': 333,
  26927. 'cedilla': 333,
  26928. 'hungarumlaut': 333,
  26929. 'ogonek': 333,
  26930. 'caron': 333,
  26931. 'emdash': 1000,
  26932. 'AE': 889,
  26933. 'ordfeminine': 276,
  26934. 'Lslash': 611,
  26935. 'Oslash': 722,
  26936. 'OE': 889,
  26937. 'ordmasculine': 310,
  26938. 'ae': 667,
  26939. 'dotlessi': 278,
  26940. 'lslash': 278,
  26941. 'oslash': 500,
  26942. 'oe': 722,
  26943. 'germandbls': 500,
  26944. 'Idieresis': 333,
  26945. 'eacute': 444,
  26946. 'abreve': 444,
  26947. 'uhungarumlaut': 500,
  26948. 'ecaron': 444,
  26949. 'Ydieresis': 722,
  26950. 'divide': 564,
  26951. 'Yacute': 722,
  26952. 'Acircumflex': 722,
  26953. 'aacute': 444,
  26954. 'Ucircumflex': 722,
  26955. 'yacute': 500,
  26956. 'scommaaccent': 389,
  26957. 'ecircumflex': 444,
  26958. 'Uring': 722,
  26959. 'Udieresis': 722,
  26960. 'aogonek': 444,
  26961. 'Uacute': 722,
  26962. 'uogonek': 500,
  26963. 'Edieresis': 611,
  26964. 'Dcroat': 722,
  26965. 'commaaccent': 250,
  26966. 'copyright': 760,
  26967. 'Emacron': 611,
  26968. 'ccaron': 444,
  26969. 'aring': 444,
  26970. 'Ncommaaccent': 722,
  26971. 'lacute': 278,
  26972. 'agrave': 444,
  26973. 'Tcommaaccent': 611,
  26974. 'Cacute': 667,
  26975. 'atilde': 444,
  26976. 'Edotaccent': 611,
  26977. 'scaron': 389,
  26978. 'scedilla': 389,
  26979. 'iacute': 278,
  26980. 'lozenge': 471,
  26981. 'Rcaron': 667,
  26982. 'Gcommaaccent': 722,
  26983. 'ucircumflex': 500,
  26984. 'acircumflex': 444,
  26985. 'Amacron': 722,
  26986. 'rcaron': 333,
  26987. 'ccedilla': 444,
  26988. 'Zdotaccent': 611,
  26989. 'Thorn': 556,
  26990. 'Omacron': 722,
  26991. 'Racute': 667,
  26992. 'Sacute': 556,
  26993. 'dcaron': 588,
  26994. 'Umacron': 722,
  26995. 'uring': 500,
  26996. 'threesuperior': 300,
  26997. 'Ograve': 722,
  26998. 'Agrave': 722,
  26999. 'Abreve': 722,
  27000. 'multiply': 564,
  27001. 'uacute': 500,
  27002. 'Tcaron': 611,
  27003. 'partialdiff': 476,
  27004. 'ydieresis': 500,
  27005. 'Nacute': 722,
  27006. 'icircumflex': 278,
  27007. 'Ecircumflex': 611,
  27008. 'adieresis': 444,
  27009. 'edieresis': 444,
  27010. 'cacute': 444,
  27011. 'nacute': 500,
  27012. 'umacron': 500,
  27013. 'Ncaron': 722,
  27014. 'Iacute': 333,
  27015. 'plusminus': 564,
  27016. 'brokenbar': 200,
  27017. 'registered': 760,
  27018. 'Gbreve': 722,
  27019. 'Idotaccent': 333,
  27020. 'summation': 600,
  27021. 'Egrave': 611,
  27022. 'racute': 333,
  27023. 'omacron': 500,
  27024. 'Zacute': 611,
  27025. 'Zcaron': 611,
  27026. 'greaterequal': 549,
  27027. 'Eth': 722,
  27028. 'Ccedilla': 667,
  27029. 'lcommaaccent': 278,
  27030. 'tcaron': 326,
  27031. 'eogonek': 444,
  27032. 'Uogonek': 722,
  27033. 'Aacute': 722,
  27034. 'Adieresis': 722,
  27035. 'egrave': 444,
  27036. 'zacute': 444,
  27037. 'iogonek': 278,
  27038. 'Oacute': 722,
  27039. 'oacute': 500,
  27040. 'amacron': 444,
  27041. 'sacute': 389,
  27042. 'idieresis': 278,
  27043. 'Ocircumflex': 722,
  27044. 'Ugrave': 722,
  27045. 'Delta': 612,
  27046. 'thorn': 500,
  27047. 'twosuperior': 300,
  27048. 'Odieresis': 722,
  27049. 'mu': 500,
  27050. 'igrave': 278,
  27051. 'ohungarumlaut': 500,
  27052. 'Eogonek': 611,
  27053. 'dcroat': 500,
  27054. 'threequarters': 750,
  27055. 'Scedilla': 556,
  27056. 'lcaron': 344,
  27057. 'Kcommaaccent': 722,
  27058. 'Lacute': 611,
  27059. 'trademark': 980,
  27060. 'edotaccent': 444,
  27061. 'Igrave': 333,
  27062. 'Imacron': 333,
  27063. 'Lcaron': 611,
  27064. 'onehalf': 750,
  27065. 'lessequal': 549,
  27066. 'ocircumflex': 500,
  27067. 'ntilde': 500,
  27068. 'Uhungarumlaut': 722,
  27069. 'Eacute': 611,
  27070. 'emacron': 444,
  27071. 'gbreve': 500,
  27072. 'onequarter': 750,
  27073. 'Scaron': 556,
  27074. 'Scommaaccent': 556,
  27075. 'Ohungarumlaut': 722,
  27076. 'degree': 400,
  27077. 'ograve': 500,
  27078. 'Ccaron': 667,
  27079. 'ugrave': 500,
  27080. 'radical': 453,
  27081. 'Dcaron': 722,
  27082. 'rcommaaccent': 333,
  27083. 'Ntilde': 722,
  27084. 'otilde': 500,
  27085. 'Rcommaaccent': 667,
  27086. 'Lcommaaccent': 611,
  27087. 'Atilde': 722,
  27088. 'Aogonek': 722,
  27089. 'Aring': 722,
  27090. 'Otilde': 722,
  27091. 'zdotaccent': 444,
  27092. 'Ecaron': 611,
  27093. 'Iogonek': 333,
  27094. 'kcommaaccent': 500,
  27095. 'minus': 564,
  27096. 'Icircumflex': 333,
  27097. 'ncaron': 500,
  27098. 'tcommaaccent': 278,
  27099. 'logicalnot': 564,
  27100. 'odieresis': 500,
  27101. 'udieresis': 500,
  27102. 'notequal': 549,
  27103. 'gcommaaccent': 500,
  27104. 'eth': 500,
  27105. 'zcaron': 444,
  27106. 'ncommaaccent': 500,
  27107. 'onesuperior': 300,
  27108. 'imacron': 278,
  27109. 'Euro': 500
  27110. },
  27111. 'Times-Bold': {
  27112. 'space': 250,
  27113. 'exclam': 333,
  27114. 'quotedbl': 555,
  27115. 'numbersign': 500,
  27116. 'dollar': 500,
  27117. 'percent': 1000,
  27118. 'ampersand': 833,
  27119. 'quoteright': 333,
  27120. 'parenleft': 333,
  27121. 'parenright': 333,
  27122. 'asterisk': 500,
  27123. 'plus': 570,
  27124. 'comma': 250,
  27125. 'hyphen': 333,
  27126. 'period': 250,
  27127. 'slash': 278,
  27128. 'zero': 500,
  27129. 'one': 500,
  27130. 'two': 500,
  27131. 'three': 500,
  27132. 'four': 500,
  27133. 'five': 500,
  27134. 'six': 500,
  27135. 'seven': 500,
  27136. 'eight': 500,
  27137. 'nine': 500,
  27138. 'colon': 333,
  27139. 'semicolon': 333,
  27140. 'less': 570,
  27141. 'equal': 570,
  27142. 'greater': 570,
  27143. 'question': 500,
  27144. 'at': 930,
  27145. 'A': 722,
  27146. 'B': 667,
  27147. 'C': 722,
  27148. 'D': 722,
  27149. 'E': 667,
  27150. 'F': 611,
  27151. 'G': 778,
  27152. 'H': 778,
  27153. 'I': 389,
  27154. 'J': 500,
  27155. 'K': 778,
  27156. 'L': 667,
  27157. 'M': 944,
  27158. 'N': 722,
  27159. 'O': 778,
  27160. 'P': 611,
  27161. 'Q': 778,
  27162. 'R': 722,
  27163. 'S': 556,
  27164. 'T': 667,
  27165. 'U': 722,
  27166. 'V': 722,
  27167. 'W': 1000,
  27168. 'X': 722,
  27169. 'Y': 722,
  27170. 'Z': 667,
  27171. 'bracketleft': 333,
  27172. 'backslash': 278,
  27173. 'bracketright': 333,
  27174. 'asciicircum': 581,
  27175. 'underscore': 500,
  27176. 'quoteleft': 333,
  27177. 'a': 500,
  27178. 'b': 556,
  27179. 'c': 444,
  27180. 'd': 556,
  27181. 'e': 444,
  27182. 'f': 333,
  27183. 'g': 500,
  27184. 'h': 556,
  27185. 'i': 278,
  27186. 'j': 333,
  27187. 'k': 556,
  27188. 'l': 278,
  27189. 'm': 833,
  27190. 'n': 556,
  27191. 'o': 500,
  27192. 'p': 556,
  27193. 'q': 556,
  27194. 'r': 444,
  27195. 's': 389,
  27196. 't': 333,
  27197. 'u': 556,
  27198. 'v': 500,
  27199. 'w': 722,
  27200. 'x': 500,
  27201. 'y': 500,
  27202. 'z': 444,
  27203. 'braceleft': 394,
  27204. 'bar': 220,
  27205. 'braceright': 394,
  27206. 'asciitilde': 520,
  27207. 'exclamdown': 333,
  27208. 'cent': 500,
  27209. 'sterling': 500,
  27210. 'fraction': 167,
  27211. 'yen': 500,
  27212. 'florin': 500,
  27213. 'section': 500,
  27214. 'currency': 500,
  27215. 'quotesingle': 278,
  27216. 'quotedblleft': 500,
  27217. 'guillemotleft': 500,
  27218. 'guilsinglleft': 333,
  27219. 'guilsinglright': 333,
  27220. 'fi': 556,
  27221. 'fl': 556,
  27222. 'endash': 500,
  27223. 'dagger': 500,
  27224. 'daggerdbl': 500,
  27225. 'periodcentered': 250,
  27226. 'paragraph': 540,
  27227. 'bullet': 350,
  27228. 'quotesinglbase': 333,
  27229. 'quotedblbase': 500,
  27230. 'quotedblright': 500,
  27231. 'guillemotright': 500,
  27232. 'ellipsis': 1000,
  27233. 'perthousand': 1000,
  27234. 'questiondown': 500,
  27235. 'grave': 333,
  27236. 'acute': 333,
  27237. 'circumflex': 333,
  27238. 'tilde': 333,
  27239. 'macron': 333,
  27240. 'breve': 333,
  27241. 'dotaccent': 333,
  27242. 'dieresis': 333,
  27243. 'ring': 333,
  27244. 'cedilla': 333,
  27245. 'hungarumlaut': 333,
  27246. 'ogonek': 333,
  27247. 'caron': 333,
  27248. 'emdash': 1000,
  27249. 'AE': 1000,
  27250. 'ordfeminine': 300,
  27251. 'Lslash': 667,
  27252. 'Oslash': 778,
  27253. 'OE': 1000,
  27254. 'ordmasculine': 330,
  27255. 'ae': 722,
  27256. 'dotlessi': 278,
  27257. 'lslash': 278,
  27258. 'oslash': 500,
  27259. 'oe': 722,
  27260. 'germandbls': 556,
  27261. 'Idieresis': 389,
  27262. 'eacute': 444,
  27263. 'abreve': 500,
  27264. 'uhungarumlaut': 556,
  27265. 'ecaron': 444,
  27266. 'Ydieresis': 722,
  27267. 'divide': 570,
  27268. 'Yacute': 722,
  27269. 'Acircumflex': 722,
  27270. 'aacute': 500,
  27271. 'Ucircumflex': 722,
  27272. 'yacute': 500,
  27273. 'scommaaccent': 389,
  27274. 'ecircumflex': 444,
  27275. 'Uring': 722,
  27276. 'Udieresis': 722,
  27277. 'aogonek': 500,
  27278. 'Uacute': 722,
  27279. 'uogonek': 556,
  27280. 'Edieresis': 667,
  27281. 'Dcroat': 722,
  27282. 'commaaccent': 250,
  27283. 'copyright': 747,
  27284. 'Emacron': 667,
  27285. 'ccaron': 444,
  27286. 'aring': 500,
  27287. 'Ncommaaccent': 722,
  27288. 'lacute': 278,
  27289. 'agrave': 500,
  27290. 'Tcommaaccent': 667,
  27291. 'Cacute': 722,
  27292. 'atilde': 500,
  27293. 'Edotaccent': 667,
  27294. 'scaron': 389,
  27295. 'scedilla': 389,
  27296. 'iacute': 278,
  27297. 'lozenge': 494,
  27298. 'Rcaron': 722,
  27299. 'Gcommaaccent': 778,
  27300. 'ucircumflex': 556,
  27301. 'acircumflex': 500,
  27302. 'Amacron': 722,
  27303. 'rcaron': 444,
  27304. 'ccedilla': 444,
  27305. 'Zdotaccent': 667,
  27306. 'Thorn': 611,
  27307. 'Omacron': 778,
  27308. 'Racute': 722,
  27309. 'Sacute': 556,
  27310. 'dcaron': 672,
  27311. 'Umacron': 722,
  27312. 'uring': 556,
  27313. 'threesuperior': 300,
  27314. 'Ograve': 778,
  27315. 'Agrave': 722,
  27316. 'Abreve': 722,
  27317. 'multiply': 570,
  27318. 'uacute': 556,
  27319. 'Tcaron': 667,
  27320. 'partialdiff': 494,
  27321. 'ydieresis': 500,
  27322. 'Nacute': 722,
  27323. 'icircumflex': 278,
  27324. 'Ecircumflex': 667,
  27325. 'adieresis': 500,
  27326. 'edieresis': 444,
  27327. 'cacute': 444,
  27328. 'nacute': 556,
  27329. 'umacron': 556,
  27330. 'Ncaron': 722,
  27331. 'Iacute': 389,
  27332. 'plusminus': 570,
  27333. 'brokenbar': 220,
  27334. 'registered': 747,
  27335. 'Gbreve': 778,
  27336. 'Idotaccent': 389,
  27337. 'summation': 600,
  27338. 'Egrave': 667,
  27339. 'racute': 444,
  27340. 'omacron': 500,
  27341. 'Zacute': 667,
  27342. 'Zcaron': 667,
  27343. 'greaterequal': 549,
  27344. 'Eth': 722,
  27345. 'Ccedilla': 722,
  27346. 'lcommaaccent': 278,
  27347. 'tcaron': 416,
  27348. 'eogonek': 444,
  27349. 'Uogonek': 722,
  27350. 'Aacute': 722,
  27351. 'Adieresis': 722,
  27352. 'egrave': 444,
  27353. 'zacute': 444,
  27354. 'iogonek': 278,
  27355. 'Oacute': 778,
  27356. 'oacute': 500,
  27357. 'amacron': 500,
  27358. 'sacute': 389,
  27359. 'idieresis': 278,
  27360. 'Ocircumflex': 778,
  27361. 'Ugrave': 722,
  27362. 'Delta': 612,
  27363. 'thorn': 556,
  27364. 'twosuperior': 300,
  27365. 'Odieresis': 778,
  27366. 'mu': 556,
  27367. 'igrave': 278,
  27368. 'ohungarumlaut': 500,
  27369. 'Eogonek': 667,
  27370. 'dcroat': 556,
  27371. 'threequarters': 750,
  27372. 'Scedilla': 556,
  27373. 'lcaron': 394,
  27374. 'Kcommaaccent': 778,
  27375. 'Lacute': 667,
  27376. 'trademark': 1000,
  27377. 'edotaccent': 444,
  27378. 'Igrave': 389,
  27379. 'Imacron': 389,
  27380. 'Lcaron': 667,
  27381. 'onehalf': 750,
  27382. 'lessequal': 549,
  27383. 'ocircumflex': 500,
  27384. 'ntilde': 556,
  27385. 'Uhungarumlaut': 722,
  27386. 'Eacute': 667,
  27387. 'emacron': 444,
  27388. 'gbreve': 500,
  27389. 'onequarter': 750,
  27390. 'Scaron': 556,
  27391. 'Scommaaccent': 556,
  27392. 'Ohungarumlaut': 778,
  27393. 'degree': 400,
  27394. 'ograve': 500,
  27395. 'Ccaron': 722,
  27396. 'ugrave': 556,
  27397. 'radical': 549,
  27398. 'Dcaron': 722,
  27399. 'rcommaaccent': 444,
  27400. 'Ntilde': 722,
  27401. 'otilde': 500,
  27402. 'Rcommaaccent': 722,
  27403. 'Lcommaaccent': 667,
  27404. 'Atilde': 722,
  27405. 'Aogonek': 722,
  27406. 'Aring': 722,
  27407. 'Otilde': 778,
  27408. 'zdotaccent': 444,
  27409. 'Ecaron': 667,
  27410. 'Iogonek': 389,
  27411. 'kcommaaccent': 556,
  27412. 'minus': 570,
  27413. 'Icircumflex': 389,
  27414. 'ncaron': 556,
  27415. 'tcommaaccent': 333,
  27416. 'logicalnot': 570,
  27417. 'odieresis': 500,
  27418. 'udieresis': 556,
  27419. 'notequal': 549,
  27420. 'gcommaaccent': 500,
  27421. 'eth': 500,
  27422. 'zcaron': 444,
  27423. 'ncommaaccent': 556,
  27424. 'onesuperior': 300,
  27425. 'imacron': 278,
  27426. 'Euro': 500
  27427. },
  27428. 'Times-BoldItalic': {
  27429. 'space': 250,
  27430. 'exclam': 389,
  27431. 'quotedbl': 555,
  27432. 'numbersign': 500,
  27433. 'dollar': 500,
  27434. 'percent': 833,
  27435. 'ampersand': 778,
  27436. 'quoteright': 333,
  27437. 'parenleft': 333,
  27438. 'parenright': 333,
  27439. 'asterisk': 500,
  27440. 'plus': 570,
  27441. 'comma': 250,
  27442. 'hyphen': 333,
  27443. 'period': 250,
  27444. 'slash': 278,
  27445. 'zero': 500,
  27446. 'one': 500,
  27447. 'two': 500,
  27448. 'three': 500,
  27449. 'four': 500,
  27450. 'five': 500,
  27451. 'six': 500,
  27452. 'seven': 500,
  27453. 'eight': 500,
  27454. 'nine': 500,
  27455. 'colon': 333,
  27456. 'semicolon': 333,
  27457. 'less': 570,
  27458. 'equal': 570,
  27459. 'greater': 570,
  27460. 'question': 500,
  27461. 'at': 832,
  27462. 'A': 667,
  27463. 'B': 667,
  27464. 'C': 667,
  27465. 'D': 722,
  27466. 'E': 667,
  27467. 'F': 667,
  27468. 'G': 722,
  27469. 'H': 778,
  27470. 'I': 389,
  27471. 'J': 500,
  27472. 'K': 667,
  27473. 'L': 611,
  27474. 'M': 889,
  27475. 'N': 722,
  27476. 'O': 722,
  27477. 'P': 611,
  27478. 'Q': 722,
  27479. 'R': 667,
  27480. 'S': 556,
  27481. 'T': 611,
  27482. 'U': 722,
  27483. 'V': 667,
  27484. 'W': 889,
  27485. 'X': 667,
  27486. 'Y': 611,
  27487. 'Z': 611,
  27488. 'bracketleft': 333,
  27489. 'backslash': 278,
  27490. 'bracketright': 333,
  27491. 'asciicircum': 570,
  27492. 'underscore': 500,
  27493. 'quoteleft': 333,
  27494. 'a': 500,
  27495. 'b': 500,
  27496. 'c': 444,
  27497. 'd': 500,
  27498. 'e': 444,
  27499. 'f': 333,
  27500. 'g': 500,
  27501. 'h': 556,
  27502. 'i': 278,
  27503. 'j': 278,
  27504. 'k': 500,
  27505. 'l': 278,
  27506. 'm': 778,
  27507. 'n': 556,
  27508. 'o': 500,
  27509. 'p': 500,
  27510. 'q': 500,
  27511. 'r': 389,
  27512. 's': 389,
  27513. 't': 278,
  27514. 'u': 556,
  27515. 'v': 444,
  27516. 'w': 667,
  27517. 'x': 500,
  27518. 'y': 444,
  27519. 'z': 389,
  27520. 'braceleft': 348,
  27521. 'bar': 220,
  27522. 'braceright': 348,
  27523. 'asciitilde': 570,
  27524. 'exclamdown': 389,
  27525. 'cent': 500,
  27526. 'sterling': 500,
  27527. 'fraction': 167,
  27528. 'yen': 500,
  27529. 'florin': 500,
  27530. 'section': 500,
  27531. 'currency': 500,
  27532. 'quotesingle': 278,
  27533. 'quotedblleft': 500,
  27534. 'guillemotleft': 500,
  27535. 'guilsinglleft': 333,
  27536. 'guilsinglright': 333,
  27537. 'fi': 556,
  27538. 'fl': 556,
  27539. 'endash': 500,
  27540. 'dagger': 500,
  27541. 'daggerdbl': 500,
  27542. 'periodcentered': 250,
  27543. 'paragraph': 500,
  27544. 'bullet': 350,
  27545. 'quotesinglbase': 333,
  27546. 'quotedblbase': 500,
  27547. 'quotedblright': 500,
  27548. 'guillemotright': 500,
  27549. 'ellipsis': 1000,
  27550. 'perthousand': 1000,
  27551. 'questiondown': 500,
  27552. 'grave': 333,
  27553. 'acute': 333,
  27554. 'circumflex': 333,
  27555. 'tilde': 333,
  27556. 'macron': 333,
  27557. 'breve': 333,
  27558. 'dotaccent': 333,
  27559. 'dieresis': 333,
  27560. 'ring': 333,
  27561. 'cedilla': 333,
  27562. 'hungarumlaut': 333,
  27563. 'ogonek': 333,
  27564. 'caron': 333,
  27565. 'emdash': 1000,
  27566. 'AE': 944,
  27567. 'ordfeminine': 266,
  27568. 'Lslash': 611,
  27569. 'Oslash': 722,
  27570. 'OE': 944,
  27571. 'ordmasculine': 300,
  27572. 'ae': 722,
  27573. 'dotlessi': 278,
  27574. 'lslash': 278,
  27575. 'oslash': 500,
  27576. 'oe': 722,
  27577. 'germandbls': 500,
  27578. 'Idieresis': 389,
  27579. 'eacute': 444,
  27580. 'abreve': 500,
  27581. 'uhungarumlaut': 556,
  27582. 'ecaron': 444,
  27583. 'Ydieresis': 611,
  27584. 'divide': 570,
  27585. 'Yacute': 611,
  27586. 'Acircumflex': 667,
  27587. 'aacute': 500,
  27588. 'Ucircumflex': 722,
  27589. 'yacute': 444,
  27590. 'scommaaccent': 389,
  27591. 'ecircumflex': 444,
  27592. 'Uring': 722,
  27593. 'Udieresis': 722,
  27594. 'aogonek': 500,
  27595. 'Uacute': 722,
  27596. 'uogonek': 556,
  27597. 'Edieresis': 667,
  27598. 'Dcroat': 722,
  27599. 'commaaccent': 250,
  27600. 'copyright': 747,
  27601. 'Emacron': 667,
  27602. 'ccaron': 444,
  27603. 'aring': 500,
  27604. 'Ncommaaccent': 722,
  27605. 'lacute': 278,
  27606. 'agrave': 500,
  27607. 'Tcommaaccent': 611,
  27608. 'Cacute': 667,
  27609. 'atilde': 500,
  27610. 'Edotaccent': 667,
  27611. 'scaron': 389,
  27612. 'scedilla': 389,
  27613. 'iacute': 278,
  27614. 'lozenge': 494,
  27615. 'Rcaron': 667,
  27616. 'Gcommaaccent': 722,
  27617. 'ucircumflex': 556,
  27618. 'acircumflex': 500,
  27619. 'Amacron': 667,
  27620. 'rcaron': 389,
  27621. 'ccedilla': 444,
  27622. 'Zdotaccent': 611,
  27623. 'Thorn': 611,
  27624. 'Omacron': 722,
  27625. 'Racute': 667,
  27626. 'Sacute': 556,
  27627. 'dcaron': 608,
  27628. 'Umacron': 722,
  27629. 'uring': 556,
  27630. 'threesuperior': 300,
  27631. 'Ograve': 722,
  27632. 'Agrave': 667,
  27633. 'Abreve': 667,
  27634. 'multiply': 570,
  27635. 'uacute': 556,
  27636. 'Tcaron': 611,
  27637. 'partialdiff': 494,
  27638. 'ydieresis': 444,
  27639. 'Nacute': 722,
  27640. 'icircumflex': 278,
  27641. 'Ecircumflex': 667,
  27642. 'adieresis': 500,
  27643. 'edieresis': 444,
  27644. 'cacute': 444,
  27645. 'nacute': 556,
  27646. 'umacron': 556,
  27647. 'Ncaron': 722,
  27648. 'Iacute': 389,
  27649. 'plusminus': 570,
  27650. 'brokenbar': 220,
  27651. 'registered': 747,
  27652. 'Gbreve': 722,
  27653. 'Idotaccent': 389,
  27654. 'summation': 600,
  27655. 'Egrave': 667,
  27656. 'racute': 389,
  27657. 'omacron': 500,
  27658. 'Zacute': 611,
  27659. 'Zcaron': 611,
  27660. 'greaterequal': 549,
  27661. 'Eth': 722,
  27662. 'Ccedilla': 667,
  27663. 'lcommaaccent': 278,
  27664. 'tcaron': 366,
  27665. 'eogonek': 444,
  27666. 'Uogonek': 722,
  27667. 'Aacute': 667,
  27668. 'Adieresis': 667,
  27669. 'egrave': 444,
  27670. 'zacute': 389,
  27671. 'iogonek': 278,
  27672. 'Oacute': 722,
  27673. 'oacute': 500,
  27674. 'amacron': 500,
  27675. 'sacute': 389,
  27676. 'idieresis': 278,
  27677. 'Ocircumflex': 722,
  27678. 'Ugrave': 722,
  27679. 'Delta': 612,
  27680. 'thorn': 500,
  27681. 'twosuperior': 300,
  27682. 'Odieresis': 722,
  27683. 'mu': 576,
  27684. 'igrave': 278,
  27685. 'ohungarumlaut': 500,
  27686. 'Eogonek': 667,
  27687. 'dcroat': 500,
  27688. 'threequarters': 750,
  27689. 'Scedilla': 556,
  27690. 'lcaron': 382,
  27691. 'Kcommaaccent': 667,
  27692. 'Lacute': 611,
  27693. 'trademark': 1000,
  27694. 'edotaccent': 444,
  27695. 'Igrave': 389,
  27696. 'Imacron': 389,
  27697. 'Lcaron': 611,
  27698. 'onehalf': 750,
  27699. 'lessequal': 549,
  27700. 'ocircumflex': 500,
  27701. 'ntilde': 556,
  27702. 'Uhungarumlaut': 722,
  27703. 'Eacute': 667,
  27704. 'emacron': 444,
  27705. 'gbreve': 500,
  27706. 'onequarter': 750,
  27707. 'Scaron': 556,
  27708. 'Scommaaccent': 556,
  27709. 'Ohungarumlaut': 722,
  27710. 'degree': 400,
  27711. 'ograve': 500,
  27712. 'Ccaron': 667,
  27713. 'ugrave': 556,
  27714. 'radical': 549,
  27715. 'Dcaron': 722,
  27716. 'rcommaaccent': 389,
  27717. 'Ntilde': 722,
  27718. 'otilde': 500,
  27719. 'Rcommaaccent': 667,
  27720. 'Lcommaaccent': 611,
  27721. 'Atilde': 667,
  27722. 'Aogonek': 667,
  27723. 'Aring': 667,
  27724. 'Otilde': 722,
  27725. 'zdotaccent': 389,
  27726. 'Ecaron': 667,
  27727. 'Iogonek': 389,
  27728. 'kcommaaccent': 500,
  27729. 'minus': 606,
  27730. 'Icircumflex': 389,
  27731. 'ncaron': 556,
  27732. 'tcommaaccent': 278,
  27733. 'logicalnot': 606,
  27734. 'odieresis': 500,
  27735. 'udieresis': 556,
  27736. 'notequal': 549,
  27737. 'gcommaaccent': 500,
  27738. 'eth': 500,
  27739. 'zcaron': 389,
  27740. 'ncommaaccent': 556,
  27741. 'onesuperior': 300,
  27742. 'imacron': 278,
  27743. 'Euro': 500
  27744. },
  27745. 'Times-Italic': {
  27746. 'space': 250,
  27747. 'exclam': 333,
  27748. 'quotedbl': 420,
  27749. 'numbersign': 500,
  27750. 'dollar': 500,
  27751. 'percent': 833,
  27752. 'ampersand': 778,
  27753. 'quoteright': 333,
  27754. 'parenleft': 333,
  27755. 'parenright': 333,
  27756. 'asterisk': 500,
  27757. 'plus': 675,
  27758. 'comma': 250,
  27759. 'hyphen': 333,
  27760. 'period': 250,
  27761. 'slash': 278,
  27762. 'zero': 500,
  27763. 'one': 500,
  27764. 'two': 500,
  27765. 'three': 500,
  27766. 'four': 500,
  27767. 'five': 500,
  27768. 'six': 500,
  27769. 'seven': 500,
  27770. 'eight': 500,
  27771. 'nine': 500,
  27772. 'colon': 333,
  27773. 'semicolon': 333,
  27774. 'less': 675,
  27775. 'equal': 675,
  27776. 'greater': 675,
  27777. 'question': 500,
  27778. 'at': 920,
  27779. 'A': 611,
  27780. 'B': 611,
  27781. 'C': 667,
  27782. 'D': 722,
  27783. 'E': 611,
  27784. 'F': 611,
  27785. 'G': 722,
  27786. 'H': 722,
  27787. 'I': 333,
  27788. 'J': 444,
  27789. 'K': 667,
  27790. 'L': 556,
  27791. 'M': 833,
  27792. 'N': 667,
  27793. 'O': 722,
  27794. 'P': 611,
  27795. 'Q': 722,
  27796. 'R': 611,
  27797. 'S': 500,
  27798. 'T': 556,
  27799. 'U': 722,
  27800. 'V': 611,
  27801. 'W': 833,
  27802. 'X': 611,
  27803. 'Y': 556,
  27804. 'Z': 556,
  27805. 'bracketleft': 389,
  27806. 'backslash': 278,
  27807. 'bracketright': 389,
  27808. 'asciicircum': 422,
  27809. 'underscore': 500,
  27810. 'quoteleft': 333,
  27811. 'a': 500,
  27812. 'b': 500,
  27813. 'c': 444,
  27814. 'd': 500,
  27815. 'e': 444,
  27816. 'f': 278,
  27817. 'g': 500,
  27818. 'h': 500,
  27819. 'i': 278,
  27820. 'j': 278,
  27821. 'k': 444,
  27822. 'l': 278,
  27823. 'm': 722,
  27824. 'n': 500,
  27825. 'o': 500,
  27826. 'p': 500,
  27827. 'q': 500,
  27828. 'r': 389,
  27829. 's': 389,
  27830. 't': 278,
  27831. 'u': 500,
  27832. 'v': 444,
  27833. 'w': 667,
  27834. 'x': 444,
  27835. 'y': 444,
  27836. 'z': 389,
  27837. 'braceleft': 400,
  27838. 'bar': 275,
  27839. 'braceright': 400,
  27840. 'asciitilde': 541,
  27841. 'exclamdown': 389,
  27842. 'cent': 500,
  27843. 'sterling': 500,
  27844. 'fraction': 167,
  27845. 'yen': 500,
  27846. 'florin': 500,
  27847. 'section': 500,
  27848. 'currency': 500,
  27849. 'quotesingle': 214,
  27850. 'quotedblleft': 556,
  27851. 'guillemotleft': 500,
  27852. 'guilsinglleft': 333,
  27853. 'guilsinglright': 333,
  27854. 'fi': 500,
  27855. 'fl': 500,
  27856. 'endash': 500,
  27857. 'dagger': 500,
  27858. 'daggerdbl': 500,
  27859. 'periodcentered': 250,
  27860. 'paragraph': 523,
  27861. 'bullet': 350,
  27862. 'quotesinglbase': 333,
  27863. 'quotedblbase': 556,
  27864. 'quotedblright': 556,
  27865. 'guillemotright': 500,
  27866. 'ellipsis': 889,
  27867. 'perthousand': 1000,
  27868. 'questiondown': 500,
  27869. 'grave': 333,
  27870. 'acute': 333,
  27871. 'circumflex': 333,
  27872. 'tilde': 333,
  27873. 'macron': 333,
  27874. 'breve': 333,
  27875. 'dotaccent': 333,
  27876. 'dieresis': 333,
  27877. 'ring': 333,
  27878. 'cedilla': 333,
  27879. 'hungarumlaut': 333,
  27880. 'ogonek': 333,
  27881. 'caron': 333,
  27882. 'emdash': 889,
  27883. 'AE': 889,
  27884. 'ordfeminine': 276,
  27885. 'Lslash': 556,
  27886. 'Oslash': 722,
  27887. 'OE': 944,
  27888. 'ordmasculine': 310,
  27889. 'ae': 667,
  27890. 'dotlessi': 278,
  27891. 'lslash': 278,
  27892. 'oslash': 500,
  27893. 'oe': 667,
  27894. 'germandbls': 500,
  27895. 'Idieresis': 333,
  27896. 'eacute': 444,
  27897. 'abreve': 500,
  27898. 'uhungarumlaut': 500,
  27899. 'ecaron': 444,
  27900. 'Ydieresis': 556,
  27901. 'divide': 675,
  27902. 'Yacute': 556,
  27903. 'Acircumflex': 611,
  27904. 'aacute': 500,
  27905. 'Ucircumflex': 722,
  27906. 'yacute': 444,
  27907. 'scommaaccent': 389,
  27908. 'ecircumflex': 444,
  27909. 'Uring': 722,
  27910. 'Udieresis': 722,
  27911. 'aogonek': 500,
  27912. 'Uacute': 722,
  27913. 'uogonek': 500,
  27914. 'Edieresis': 611,
  27915. 'Dcroat': 722,
  27916. 'commaaccent': 250,
  27917. 'copyright': 760,
  27918. 'Emacron': 611,
  27919. 'ccaron': 444,
  27920. 'aring': 500,
  27921. 'Ncommaaccent': 667,
  27922. 'lacute': 278,
  27923. 'agrave': 500,
  27924. 'Tcommaaccent': 556,
  27925. 'Cacute': 667,
  27926. 'atilde': 500,
  27927. 'Edotaccent': 611,
  27928. 'scaron': 389,
  27929. 'scedilla': 389,
  27930. 'iacute': 278,
  27931. 'lozenge': 471,
  27932. 'Rcaron': 611,
  27933. 'Gcommaaccent': 722,
  27934. 'ucircumflex': 500,
  27935. 'acircumflex': 500,
  27936. 'Amacron': 611,
  27937. 'rcaron': 389,
  27938. 'ccedilla': 444,
  27939. 'Zdotaccent': 556,
  27940. 'Thorn': 611,
  27941. 'Omacron': 722,
  27942. 'Racute': 611,
  27943. 'Sacute': 500,
  27944. 'dcaron': 544,
  27945. 'Umacron': 722,
  27946. 'uring': 500,
  27947. 'threesuperior': 300,
  27948. 'Ograve': 722,
  27949. 'Agrave': 611,
  27950. 'Abreve': 611,
  27951. 'multiply': 675,
  27952. 'uacute': 500,
  27953. 'Tcaron': 556,
  27954. 'partialdiff': 476,
  27955. 'ydieresis': 444,
  27956. 'Nacute': 667,
  27957. 'icircumflex': 278,
  27958. 'Ecircumflex': 611,
  27959. 'adieresis': 500,
  27960. 'edieresis': 444,
  27961. 'cacute': 444,
  27962. 'nacute': 500,
  27963. 'umacron': 500,
  27964. 'Ncaron': 667,
  27965. 'Iacute': 333,
  27966. 'plusminus': 675,
  27967. 'brokenbar': 275,
  27968. 'registered': 760,
  27969. 'Gbreve': 722,
  27970. 'Idotaccent': 333,
  27971. 'summation': 600,
  27972. 'Egrave': 611,
  27973. 'racute': 389,
  27974. 'omacron': 500,
  27975. 'Zacute': 556,
  27976. 'Zcaron': 556,
  27977. 'greaterequal': 549,
  27978. 'Eth': 722,
  27979. 'Ccedilla': 667,
  27980. 'lcommaaccent': 278,
  27981. 'tcaron': 300,
  27982. 'eogonek': 444,
  27983. 'Uogonek': 722,
  27984. 'Aacute': 611,
  27985. 'Adieresis': 611,
  27986. 'egrave': 444,
  27987. 'zacute': 389,
  27988. 'iogonek': 278,
  27989. 'Oacute': 722,
  27990. 'oacute': 500,
  27991. 'amacron': 500,
  27992. 'sacute': 389,
  27993. 'idieresis': 278,
  27994. 'Ocircumflex': 722,
  27995. 'Ugrave': 722,
  27996. 'Delta': 612,
  27997. 'thorn': 500,
  27998. 'twosuperior': 300,
  27999. 'Odieresis': 722,
  28000. 'mu': 500,
  28001. 'igrave': 278,
  28002. 'ohungarumlaut': 500,
  28003. 'Eogonek': 611,
  28004. 'dcroat': 500,
  28005. 'threequarters': 750,
  28006. 'Scedilla': 500,
  28007. 'lcaron': 300,
  28008. 'Kcommaaccent': 667,
  28009. 'Lacute': 556,
  28010. 'trademark': 980,
  28011. 'edotaccent': 444,
  28012. 'Igrave': 333,
  28013. 'Imacron': 333,
  28014. 'Lcaron': 611,
  28015. 'onehalf': 750,
  28016. 'lessequal': 549,
  28017. 'ocircumflex': 500,
  28018. 'ntilde': 500,
  28019. 'Uhungarumlaut': 722,
  28020. 'Eacute': 611,
  28021. 'emacron': 444,
  28022. 'gbreve': 500,
  28023. 'onequarter': 750,
  28024. 'Scaron': 500,
  28025. 'Scommaaccent': 500,
  28026. 'Ohungarumlaut': 722,
  28027. 'degree': 400,
  28028. 'ograve': 500,
  28029. 'Ccaron': 667,
  28030. 'ugrave': 500,
  28031. 'radical': 453,
  28032. 'Dcaron': 722,
  28033. 'rcommaaccent': 389,
  28034. 'Ntilde': 667,
  28035. 'otilde': 500,
  28036. 'Rcommaaccent': 611,
  28037. 'Lcommaaccent': 556,
  28038. 'Atilde': 611,
  28039. 'Aogonek': 611,
  28040. 'Aring': 611,
  28041. 'Otilde': 722,
  28042. 'zdotaccent': 389,
  28043. 'Ecaron': 611,
  28044. 'Iogonek': 333,
  28045. 'kcommaaccent': 444,
  28046. 'minus': 675,
  28047. 'Icircumflex': 333,
  28048. 'ncaron': 500,
  28049. 'tcommaaccent': 278,
  28050. 'logicalnot': 675,
  28051. 'odieresis': 500,
  28052. 'udieresis': 500,
  28053. 'notequal': 549,
  28054. 'gcommaaccent': 500,
  28055. 'eth': 500,
  28056. 'zcaron': 389,
  28057. 'ncommaaccent': 500,
  28058. 'onesuperior': 300,
  28059. 'imacron': 278,
  28060. 'Euro': 500
  28061. },
  28062. 'ZapfDingbats': {
  28063. 'space': 278,
  28064. 'a1': 974,
  28065. 'a2': 961,
  28066. 'a202': 974,
  28067. 'a3': 980,
  28068. 'a4': 719,
  28069. 'a5': 789,
  28070. 'a119': 790,
  28071. 'a118': 791,
  28072. 'a117': 690,
  28073. 'a11': 960,
  28074. 'a12': 939,
  28075. 'a13': 549,
  28076. 'a14': 855,
  28077. 'a15': 911,
  28078. 'a16': 933,
  28079. 'a105': 911,
  28080. 'a17': 945,
  28081. 'a18': 974,
  28082. 'a19': 755,
  28083. 'a20': 846,
  28084. 'a21': 762,
  28085. 'a22': 761,
  28086. 'a23': 571,
  28087. 'a24': 677,
  28088. 'a25': 763,
  28089. 'a26': 760,
  28090. 'a27': 759,
  28091. 'a28': 754,
  28092. 'a6': 494,
  28093. 'a7': 552,
  28094. 'a8': 537,
  28095. 'a9': 577,
  28096. 'a10': 692,
  28097. 'a29': 786,
  28098. 'a30': 788,
  28099. 'a31': 788,
  28100. 'a32': 790,
  28101. 'a33': 793,
  28102. 'a34': 794,
  28103. 'a35': 816,
  28104. 'a36': 823,
  28105. 'a37': 789,
  28106. 'a38': 841,
  28107. 'a39': 823,
  28108. 'a40': 833,
  28109. 'a41': 816,
  28110. 'a42': 831,
  28111. 'a43': 923,
  28112. 'a44': 744,
  28113. 'a45': 723,
  28114. 'a46': 749,
  28115. 'a47': 790,
  28116. 'a48': 792,
  28117. 'a49': 695,
  28118. 'a50': 776,
  28119. 'a51': 768,
  28120. 'a52': 792,
  28121. 'a53': 759,
  28122. 'a54': 707,
  28123. 'a55': 708,
  28124. 'a56': 682,
  28125. 'a57': 701,
  28126. 'a58': 826,
  28127. 'a59': 815,
  28128. 'a60': 789,
  28129. 'a61': 789,
  28130. 'a62': 707,
  28131. 'a63': 687,
  28132. 'a64': 696,
  28133. 'a65': 689,
  28134. 'a66': 786,
  28135. 'a67': 787,
  28136. 'a68': 713,
  28137. 'a69': 791,
  28138. 'a70': 785,
  28139. 'a71': 791,
  28140. 'a72': 873,
  28141. 'a73': 761,
  28142. 'a74': 762,
  28143. 'a203': 762,
  28144. 'a75': 759,
  28145. 'a204': 759,
  28146. 'a76': 892,
  28147. 'a77': 892,
  28148. 'a78': 788,
  28149. 'a79': 784,
  28150. 'a81': 438,
  28151. 'a82': 138,
  28152. 'a83': 277,
  28153. 'a84': 415,
  28154. 'a97': 392,
  28155. 'a98': 392,
  28156. 'a99': 668,
  28157. 'a100': 668,
  28158. 'a89': 390,
  28159. 'a90': 390,
  28160. 'a93': 317,
  28161. 'a94': 317,
  28162. 'a91': 276,
  28163. 'a92': 276,
  28164. 'a205': 509,
  28165. 'a85': 509,
  28166. 'a206': 410,
  28167. 'a86': 410,
  28168. 'a87': 234,
  28169. 'a88': 234,
  28170. 'a95': 334,
  28171. 'a96': 334,
  28172. 'a101': 732,
  28173. 'a102': 544,
  28174. 'a103': 544,
  28175. 'a104': 910,
  28176. 'a106': 667,
  28177. 'a107': 760,
  28178. 'a108': 760,
  28179. 'a112': 776,
  28180. 'a111': 595,
  28181. 'a110': 694,
  28182. 'a109': 626,
  28183. 'a120': 788,
  28184. 'a121': 788,
  28185. 'a122': 788,
  28186. 'a123': 788,
  28187. 'a124': 788,
  28188. 'a125': 788,
  28189. 'a126': 788,
  28190. 'a127': 788,
  28191. 'a128': 788,
  28192. 'a129': 788,
  28193. 'a130': 788,
  28194. 'a131': 788,
  28195. 'a132': 788,
  28196. 'a133': 788,
  28197. 'a134': 788,
  28198. 'a135': 788,
  28199. 'a136': 788,
  28200. 'a137': 788,
  28201. 'a138': 788,
  28202. 'a139': 788,
  28203. 'a140': 788,
  28204. 'a141': 788,
  28205. 'a142': 788,
  28206. 'a143': 788,
  28207. 'a144': 788,
  28208. 'a145': 788,
  28209. 'a146': 788,
  28210. 'a147': 788,
  28211. 'a148': 788,
  28212. 'a149': 788,
  28213. 'a150': 788,
  28214. 'a151': 788,
  28215. 'a152': 788,
  28216. 'a153': 788,
  28217. 'a154': 788,
  28218. 'a155': 788,
  28219. 'a156': 788,
  28220. 'a157': 788,
  28221. 'a158': 788,
  28222. 'a159': 788,
  28223. 'a160': 894,
  28224. 'a161': 838,
  28225. 'a163': 1016,
  28226. 'a164': 458,
  28227. 'a196': 748,
  28228. 'a165': 924,
  28229. 'a192': 748,
  28230. 'a166': 918,
  28231. 'a167': 927,
  28232. 'a168': 928,
  28233. 'a169': 928,
  28234. 'a170': 834,
  28235. 'a171': 873,
  28236. 'a172': 828,
  28237. 'a173': 924,
  28238. 'a162': 924,
  28239. 'a174': 917,
  28240. 'a175': 930,
  28241. 'a176': 931,
  28242. 'a177': 463,
  28243. 'a178': 883,
  28244. 'a179': 836,
  28245. 'a193': 836,
  28246. 'a180': 867,
  28247. 'a199': 867,
  28248. 'a181': 696,
  28249. 'a200': 696,
  28250. 'a182': 874,
  28251. 'a201': 874,
  28252. 'a183': 760,
  28253. 'a184': 946,
  28254. 'a197': 771,
  28255. 'a185': 865,
  28256. 'a194': 771,
  28257. 'a198': 888,
  28258. 'a186': 967,
  28259. 'a195': 888,
  28260. 'a187': 831,
  28261. 'a188': 873,
  28262. 'a189': 927,
  28263. 'a190': 970,
  28264. 'a191': 918
  28265. }
  28266. };
  28267. var EOF = {};
  28268. function isEOF(v) {
  28269. return (v === EOF);
  28270. }
  28271. var MAX_LENGTH_TO_CACHE = 1000;
  28272. var Parser = (function ParserClosure() {
  28273. function Parser(lexer, allowStreams, xref) {
  28274. this.lexer = lexer;
  28275. this.allowStreams = allowStreams;
  28276. this.xref = xref;
  28277. this.imageCache = {};
  28278. this.refill();
  28279. }
  28280. Parser.prototype = {
  28281. refill: function Parser_refill() {
  28282. this.buf1 = this.lexer.getObj();
  28283. this.buf2 = this.lexer.getObj();
  28284. },
  28285. shift: function Parser_shift() {
  28286. if (isCmd(this.buf2, 'ID')) {
  28287. this.buf1 = this.buf2;
  28288. this.buf2 = null;
  28289. } else {
  28290. this.buf1 = this.buf2;
  28291. this.buf2 = this.lexer.getObj();
  28292. }
  28293. },
  28294. getObj: function Parser_getObj(cipherTransform) {
  28295. var buf1 = this.buf1;
  28296. this.shift();
  28297. if (buf1 instanceof Cmd) {
  28298. switch (buf1.cmd) {
  28299. case 'BI': // inline image
  28300. return this.makeInlineImage(cipherTransform);
  28301. case '[': // array
  28302. var array = [];
  28303. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28304. array.push(this.getObj(cipherTransform));
  28305. }
  28306. if (isEOF(this.buf1)) {
  28307. error('End of file inside array');
  28308. }
  28309. this.shift();
  28310. return array;
  28311. case '<<': // dictionary or stream
  28312. var dict = new Dict(this.xref);
  28313. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28314. if (!isName(this.buf1)) {
  28315. info('Malformed dictionary: key must be a name object');
  28316. this.shift();
  28317. continue;
  28318. }
  28319. var key = this.buf1.name;
  28320. this.shift();
  28321. if (isEOF(this.buf1)) {
  28322. break;
  28323. }
  28324. dict.set(key, this.getObj(cipherTransform));
  28325. }
  28326. if (isEOF(this.buf1)) {
  28327. error('End of file inside dictionary');
  28328. }
  28329. // Stream objects are not allowed inside content streams or
  28330. // object streams.
  28331. if (isCmd(this.buf2, 'stream')) {
  28332. return (this.allowStreams ?
  28333. this.makeStream(dict, cipherTransform) : dict);
  28334. }
  28335. this.shift();
  28336. return dict;
  28337. default: // simple object
  28338. return buf1;
  28339. }
  28340. }
  28341. if (isInt(buf1)) { // indirect reference or integer
  28342. var num = buf1;
  28343. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28344. var ref = new Ref(num, this.buf1);
  28345. this.shift();
  28346. this.shift();
  28347. return ref;
  28348. }
  28349. return num;
  28350. }
  28351. if (isString(buf1)) { // string
  28352. var str = buf1;
  28353. if (cipherTransform) {
  28354. str = cipherTransform.decryptString(str);
  28355. }
  28356. return str;
  28357. }
  28358. // simple object
  28359. return buf1;
  28360. },
  28361. /**
  28362. * Find the end of the stream by searching for the /EI\s/.
  28363. * @returns {number} The inline stream length.
  28364. */
  28365. findDefaultInlineStreamEnd:
  28366. function Parser_findDefaultInlineStreamEnd(stream) {
  28367. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28368. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28369. while ((ch = stream.getByte()) !== -1) {
  28370. if (state === 0) {
  28371. state = (ch === E) ? 1 : 0;
  28372. } else if (state === 1) {
  28373. state = (ch === I) ? 2 : 0;
  28374. } else {
  28375. assert(state === 2);
  28376. if (ch === SPACE || ch === LF || ch === CR) {
  28377. // Let's check the next five bytes are ASCII... just be sure.
  28378. n = 5;
  28379. followingBytes = stream.peekBytes(n);
  28380. for (i = 0; i < n; i++) {
  28381. ch = followingBytes[i];
  28382. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28383. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28384. // it's binary stuff. Resetting the state.
  28385. state = 0;
  28386. break;
  28387. }
  28388. }
  28389. if (state === 2) {
  28390. break; // Finished!
  28391. }
  28392. } else {
  28393. state = 0;
  28394. }
  28395. }
  28396. }
  28397. return ((stream.pos - 4) - startPos);
  28398. },
  28399. /**
  28400. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28401. * @returns {number} The inline stream length.
  28402. */
  28403. findDCTDecodeInlineStreamEnd:
  28404. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28405. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28406. while ((b = stream.getByte()) !== -1) {
  28407. if (b !== 0xFF) { // Not a valid marker.
  28408. continue;
  28409. }
  28410. switch (stream.getByte()) {
  28411. case 0x00: // Byte stuffing.
  28412. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28413. break;
  28414. case 0xFF: // Fill byte.
  28415. // Avoid skipping a valid marker, resetting the stream position.
  28416. stream.skip(-1);
  28417. break;
  28418. case 0xD9: // EOI
  28419. foundEOI = true;
  28420. break;
  28421. case 0xC0: // SOF0
  28422. case 0xC1: // SOF1
  28423. case 0xC2: // SOF2
  28424. case 0xC3: // SOF3
  28425. case 0xC5: // SOF5
  28426. case 0xC6: // SOF6
  28427. case 0xC7: // SOF7
  28428. case 0xC9: // SOF9
  28429. case 0xCA: // SOF10
  28430. case 0xCB: // SOF11
  28431. case 0xCD: // SOF13
  28432. case 0xCE: // SOF14
  28433. case 0xCF: // SOF15
  28434. case 0xC4: // DHT
  28435. case 0xCC: // DAC
  28436. case 0xDA: // SOS
  28437. case 0xDB: // DQT
  28438. case 0xDC: // DNL
  28439. case 0xDD: // DRI
  28440. case 0xDE: // DHP
  28441. case 0xDF: // EXP
  28442. case 0xE0: // APP0
  28443. case 0xE1: // APP1
  28444. case 0xE2: // APP2
  28445. case 0xE3: // APP3
  28446. case 0xE4: // APP4
  28447. case 0xE5: // APP5
  28448. case 0xE6: // APP6
  28449. case 0xE7: // APP7
  28450. case 0xE8: // APP8
  28451. case 0xE9: // APP9
  28452. case 0xEA: // APP10
  28453. case 0xEB: // APP11
  28454. case 0xEC: // APP12
  28455. case 0xED: // APP13
  28456. case 0xEE: // APP14
  28457. case 0xEF: // APP15
  28458. case 0xFE: // COM
  28459. // The marker should be followed by the length of the segment.
  28460. markerLength = stream.getUint16();
  28461. if (markerLength > 2) {
  28462. // |markerLength| contains the byte length of the marker segment,
  28463. // including its own length (2 bytes) and excluding the marker.
  28464. stream.skip(markerLength - 2); // Jump to the next marker.
  28465. } else {
  28466. // The marker length is invalid, resetting the stream position.
  28467. stream.skip(-2);
  28468. }
  28469. break;
  28470. }
  28471. if (foundEOI) {
  28472. break;
  28473. }
  28474. }
  28475. length = stream.pos - startPos;
  28476. if (b === -1) {
  28477. warn('Inline DCTDecode image stream: ' +
  28478. 'EOI marker not found, searching for /EI/ instead.');
  28479. stream.skip(-length); // Reset the stream position.
  28480. return this.findDefaultInlineStreamEnd(stream);
  28481. }
  28482. this.inlineStreamSkipEI(stream);
  28483. return length;
  28484. },
  28485. /**
  28486. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28487. * @returns {number} The inline stream length.
  28488. */
  28489. findASCII85DecodeInlineStreamEnd:
  28490. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28491. var TILDE = 0x7E, GT = 0x3E;
  28492. var startPos = stream.pos, ch, length;
  28493. while ((ch = stream.getByte()) !== -1) {
  28494. if (ch === TILDE && stream.peekByte() === GT) {
  28495. stream.skip();
  28496. break;
  28497. }
  28498. }
  28499. length = stream.pos - startPos;
  28500. if (ch === -1) {
  28501. warn('Inline ASCII85Decode image stream: ' +
  28502. 'EOD marker not found, searching for /EI/ instead.');
  28503. stream.skip(-length); // Reset the stream position.
  28504. return this.findDefaultInlineStreamEnd(stream);
  28505. }
  28506. this.inlineStreamSkipEI(stream);
  28507. return length;
  28508. },
  28509. /**
  28510. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28511. * @returns {number} The inline stream length.
  28512. */
  28513. findASCIIHexDecodeInlineStreamEnd:
  28514. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28515. var GT = 0x3E;
  28516. var startPos = stream.pos, ch, length;
  28517. while ((ch = stream.getByte()) !== -1) {
  28518. if (ch === GT) {
  28519. break;
  28520. }
  28521. }
  28522. length = stream.pos - startPos;
  28523. if (ch === -1) {
  28524. warn('Inline ASCIIHexDecode image stream: ' +
  28525. 'EOD marker not found, searching for /EI/ instead.');
  28526. stream.skip(-length); // Reset the stream position.
  28527. return this.findDefaultInlineStreamEnd(stream);
  28528. }
  28529. this.inlineStreamSkipEI(stream);
  28530. return length;
  28531. },
  28532. /**
  28533. * Skip over the /EI/ for streams where we search for an EOD marker.
  28534. */
  28535. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28536. var E = 0x45, I = 0x49;
  28537. var state = 0, ch;
  28538. while ((ch = stream.getByte()) !== -1) {
  28539. if (state === 0) {
  28540. state = (ch === E) ? 1 : 0;
  28541. } else if (state === 1) {
  28542. state = (ch === I) ? 2 : 0;
  28543. } else if (state === 2) {
  28544. break;
  28545. }
  28546. }
  28547. },
  28548. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28549. var lexer = this.lexer;
  28550. var stream = lexer.stream;
  28551. // Parse dictionary.
  28552. var dict = new Dict(null);
  28553. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28554. if (!isName(this.buf1)) {
  28555. error('Dictionary key must be a name object');
  28556. }
  28557. var key = this.buf1.name;
  28558. this.shift();
  28559. if (isEOF(this.buf1)) {
  28560. break;
  28561. }
  28562. dict.set(key, this.getObj(cipherTransform));
  28563. }
  28564. // Extract the name of the first (i.e. the current) image filter.
  28565. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28566. if (isName(filter)) {
  28567. filterName = filter.name;
  28568. } else if (isArray(filter) && isName(filter[0])) {
  28569. filterName = filter[0].name;
  28570. }
  28571. // Parse image stream.
  28572. var startPos = stream.pos, length, i, ii;
  28573. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  28574. length = this.findDCTDecodeInlineStreamEnd(stream);
  28575. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28576. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28577. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28578. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28579. } else {
  28580. length = this.findDefaultInlineStreamEnd(stream);
  28581. }
  28582. var imageStream = stream.makeSubStream(startPos, length, dict);
  28583. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28584. // adler32 checksum.
  28585. var adler32;
  28586. if (length < MAX_LENGTH_TO_CACHE) {
  28587. var imageBytes = imageStream.getBytes();
  28588. imageStream.reset();
  28589. var a = 1;
  28590. var b = 0;
  28591. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28592. // No modulo required in the loop if imageBytes.length < 5552.
  28593. a += imageBytes[i] & 0xff;
  28594. b += a;
  28595. }
  28596. adler32 = ((b % 65521) << 16) | (a % 65521);
  28597. if (this.imageCache.adler32 === adler32) {
  28598. this.buf2 = Cmd.get('EI');
  28599. this.shift();
  28600. this.imageCache[adler32].reset();
  28601. return this.imageCache[adler32];
  28602. }
  28603. }
  28604. if (cipherTransform) {
  28605. imageStream = cipherTransform.createStream(imageStream, length);
  28606. }
  28607. imageStream = this.filter(imageStream, dict, length);
  28608. imageStream.dict = dict;
  28609. if (adler32 !== undefined) {
  28610. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28611. this.imageCache[adler32] = imageStream;
  28612. }
  28613. this.buf2 = Cmd.get('EI');
  28614. this.shift();
  28615. return imageStream;
  28616. },
  28617. fetchIfRef: function Parser_fetchIfRef(obj) {
  28618. // not relying on the xref.fetchIfRef -- xref might not be set
  28619. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28620. },
  28621. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28622. var lexer = this.lexer;
  28623. var stream = lexer.stream;
  28624. // get stream start position
  28625. lexer.skipToNextLine();
  28626. var pos = stream.pos - 1;
  28627. // get length
  28628. var length = this.fetchIfRef(dict.get('Length'));
  28629. if (!isInt(length)) {
  28630. info('Bad ' + length + ' attribute in stream');
  28631. length = 0;
  28632. }
  28633. // skip over the stream data
  28634. stream.pos = pos + length;
  28635. lexer.nextChar();
  28636. this.shift(); // '>>'
  28637. this.shift(); // 'stream'
  28638. if (!isCmd(this.buf1, 'endstream')) {
  28639. // bad stream length, scanning for endstream
  28640. stream.pos = pos;
  28641. var SCAN_BLOCK_SIZE = 2048;
  28642. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28643. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28644. 0x61, 0x6D];
  28645. var skipped = 0, found = false, i, j;
  28646. while (stream.pos < stream.end) {
  28647. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28648. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28649. if (scanLength <= 0) {
  28650. break;
  28651. }
  28652. found = false;
  28653. for (i = 0, j = 0; i < scanLength; i++) {
  28654. var b = scanBytes[i];
  28655. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28656. i -= j;
  28657. j = 0;
  28658. } else {
  28659. j++;
  28660. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28661. i++;
  28662. found = true;
  28663. break;
  28664. }
  28665. }
  28666. }
  28667. if (found) {
  28668. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28669. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28670. break;
  28671. }
  28672. skipped += scanLength;
  28673. stream.pos += scanLength;
  28674. }
  28675. if (!found) {
  28676. error('Missing endstream');
  28677. }
  28678. length = skipped;
  28679. lexer.nextChar();
  28680. this.shift();
  28681. this.shift();
  28682. }
  28683. this.shift(); // 'endstream'
  28684. stream = stream.makeSubStream(pos, length, dict);
  28685. if (cipherTransform) {
  28686. stream = cipherTransform.createStream(stream, length);
  28687. }
  28688. stream = this.filter(stream, dict, length);
  28689. stream.dict = dict;
  28690. return stream;
  28691. },
  28692. filter: function Parser_filter(stream, dict, length) {
  28693. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28694. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28695. if (isName(filter)) {
  28696. return this.makeFilter(stream, filter.name, length, params);
  28697. }
  28698. var maybeLength = length;
  28699. if (isArray(filter)) {
  28700. var filterArray = filter;
  28701. var paramsArray = params;
  28702. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28703. filter = filterArray[i];
  28704. if (!isName(filter)) {
  28705. error('Bad filter name: ' + filter);
  28706. }
  28707. params = null;
  28708. if (isArray(paramsArray) && (i in paramsArray)) {
  28709. params = paramsArray[i];
  28710. }
  28711. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28712. // after the first stream the length variable is invalid
  28713. maybeLength = null;
  28714. }
  28715. }
  28716. return stream;
  28717. },
  28718. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28719. if (stream.dict.get('Length') === 0) {
  28720. return new NullStream(stream);
  28721. }
  28722. try {
  28723. if (params) {
  28724. params = this.fetchIfRef(params);
  28725. }
  28726. var xrefStreamStats = this.xref.stats.streamTypes;
  28727. if (name === 'FlateDecode' || name === 'Fl') {
  28728. xrefStreamStats[StreamType.FLATE] = true;
  28729. if (params) {
  28730. return new PredictorStream(new FlateStream(stream, maybeLength),
  28731. maybeLength, params);
  28732. }
  28733. return new FlateStream(stream, maybeLength);
  28734. }
  28735. if (name === 'LZWDecode' || name === 'LZW') {
  28736. xrefStreamStats[StreamType.LZW] = true;
  28737. var earlyChange = 1;
  28738. if (params) {
  28739. if (params.has('EarlyChange')) {
  28740. earlyChange = params.get('EarlyChange');
  28741. }
  28742. return new PredictorStream(
  28743. new LZWStream(stream, maybeLength, earlyChange),
  28744. maybeLength, params);
  28745. }
  28746. return new LZWStream(stream, maybeLength, earlyChange);
  28747. }
  28748. if (name === 'DCTDecode' || name === 'DCT') {
  28749. xrefStreamStats[StreamType.DCT] = true;
  28750. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28751. }
  28752. if (name === 'JPXDecode' || name === 'JPX') {
  28753. xrefStreamStats[StreamType.JPX] = true;
  28754. return new JpxStream(stream, maybeLength, stream.dict);
  28755. }
  28756. if (name === 'ASCII85Decode' || name === 'A85') {
  28757. xrefStreamStats[StreamType.A85] = true;
  28758. return new Ascii85Stream(stream, maybeLength);
  28759. }
  28760. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28761. xrefStreamStats[StreamType.AHX] = true;
  28762. return new AsciiHexStream(stream, maybeLength);
  28763. }
  28764. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28765. xrefStreamStats[StreamType.CCF] = true;
  28766. return new CCITTFaxStream(stream, maybeLength, params);
  28767. }
  28768. if (name === 'RunLengthDecode' || name === 'RL') {
  28769. xrefStreamStats[StreamType.RL] = true;
  28770. return new RunLengthStream(stream, maybeLength);
  28771. }
  28772. if (name === 'JBIG2Decode') {
  28773. xrefStreamStats[StreamType.JBIG] = true;
  28774. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28775. }
  28776. warn('filter "' + name + '" not supported yet');
  28777. return stream;
  28778. } catch (ex) {
  28779. if (ex instanceof MissingDataException) {
  28780. throw ex;
  28781. }
  28782. warn('Invalid stream: \"' + ex + '\"');
  28783. return new NullStream(stream);
  28784. }
  28785. }
  28786. };
  28787. return Parser;
  28788. })();
  28789. var Lexer = (function LexerClosure() {
  28790. function Lexer(stream, knownCommands) {
  28791. this.stream = stream;
  28792. this.nextChar();
  28793. // While lexing, we build up many strings one char at a time. Using += for
  28794. // this can result in lots of garbage strings. It's better to build an
  28795. // array of single-char strings and then join() them together at the end.
  28796. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28797. // purpose uses less memory than using a new array for each string.
  28798. this.strBuf = [];
  28799. // The PDFs might have "glued" commands with other commands, operands or
  28800. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28801. // commands and their prefixes. The prefixes are built the following way:
  28802. // if there a command that is a prefix of the other valid command or
  28803. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28804. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28805. // other commands or literals as a prefix. The knowCommands is optional.
  28806. this.knownCommands = knownCommands;
  28807. }
  28808. Lexer.isSpace = function Lexer_isSpace(ch) {
  28809. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28810. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28811. };
  28812. // A '1' in this array means the character is white space. A '1' or
  28813. // '2' means the character ends a name or command.
  28814. var specialChars = [
  28815. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28817. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28831. ];
  28832. function toHexDigit(ch) {
  28833. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28834. return ch & 0x0F;
  28835. }
  28836. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28837. // 'A'-'F', 'a'-'f'
  28838. return (ch & 0x0F) + 9;
  28839. }
  28840. return -1;
  28841. }
  28842. Lexer.prototype = {
  28843. nextChar: function Lexer_nextChar() {
  28844. return (this.currentChar = this.stream.getByte());
  28845. },
  28846. peekChar: function Lexer_peekChar() {
  28847. return this.stream.peekByte();
  28848. },
  28849. getNumber: function Lexer_getNumber() {
  28850. var ch = this.currentChar;
  28851. var eNotation = false;
  28852. var divideBy = 0; // different from 0 if it's a floating point value
  28853. var sign = 1;
  28854. if (ch === 0x2D) { // '-'
  28855. sign = -1;
  28856. ch = this.nextChar();
  28857. } else if (ch === 0x2B) { // '+'
  28858. ch = this.nextChar();
  28859. }
  28860. if (ch === 0x2E) { // '.'
  28861. divideBy = 10;
  28862. ch = this.nextChar();
  28863. }
  28864. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28865. error('Invalid number: ' + String.fromCharCode(ch));
  28866. return 0;
  28867. }
  28868. var baseValue = ch - 0x30; // '0'
  28869. var powerValue = 0;
  28870. var powerValueSign = 1;
  28871. while ((ch = this.nextChar()) >= 0) {
  28872. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28873. var currentDigit = ch - 0x30; // '0'
  28874. if (eNotation) { // We are after an 'e' or 'E'
  28875. powerValue = powerValue * 10 + currentDigit;
  28876. } else {
  28877. if (divideBy !== 0) { // We are after a point
  28878. divideBy *= 10;
  28879. }
  28880. baseValue = baseValue * 10 + currentDigit;
  28881. }
  28882. } else if (ch === 0x2E) { // '.'
  28883. if (divideBy === 0) {
  28884. divideBy = 1;
  28885. } else {
  28886. // A number can have only one '.'
  28887. break;
  28888. }
  28889. } else if (ch === 0x2D) { // '-'
  28890. // ignore minus signs in the middle of numbers to match
  28891. // Adobe's behavior
  28892. warn('Badly formated number');
  28893. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28894. // 'E' can be either a scientific notation or the beginning of a new
  28895. // operator
  28896. ch = this.peekChar();
  28897. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28898. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28899. this.nextChar(); // Consume the sign character
  28900. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28901. // The 'E' must be the beginning of a new operator
  28902. break;
  28903. }
  28904. eNotation = true;
  28905. } else {
  28906. // the last character doesn't belong to us
  28907. break;
  28908. }
  28909. }
  28910. if (divideBy !== 0) {
  28911. baseValue /= divideBy;
  28912. }
  28913. if (eNotation) {
  28914. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28915. }
  28916. return sign * baseValue;
  28917. },
  28918. getString: function Lexer_getString() {
  28919. var numParen = 1;
  28920. var done = false;
  28921. var strBuf = this.strBuf;
  28922. strBuf.length = 0;
  28923. var ch = this.nextChar();
  28924. while (true) {
  28925. var charBuffered = false;
  28926. switch (ch | 0) {
  28927. case -1:
  28928. warn('Unterminated string');
  28929. done = true;
  28930. break;
  28931. case 0x28: // '('
  28932. ++numParen;
  28933. strBuf.push('(');
  28934. break;
  28935. case 0x29: // ')'
  28936. if (--numParen === 0) {
  28937. this.nextChar(); // consume strings ')'
  28938. done = true;
  28939. } else {
  28940. strBuf.push(')');
  28941. }
  28942. break;
  28943. case 0x5C: // '\\'
  28944. ch = this.nextChar();
  28945. switch (ch) {
  28946. case -1:
  28947. warn('Unterminated string');
  28948. done = true;
  28949. break;
  28950. case 0x6E: // 'n'
  28951. strBuf.push('\n');
  28952. break;
  28953. case 0x72: // 'r'
  28954. strBuf.push('\r');
  28955. break;
  28956. case 0x74: // 't'
  28957. strBuf.push('\t');
  28958. break;
  28959. case 0x62: // 'b'
  28960. strBuf.push('\b');
  28961. break;
  28962. case 0x66: // 'f'
  28963. strBuf.push('\f');
  28964. break;
  28965. case 0x5C: // '\'
  28966. case 0x28: // '('
  28967. case 0x29: // ')'
  28968. strBuf.push(String.fromCharCode(ch));
  28969. break;
  28970. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28971. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28972. var x = ch & 0x0F;
  28973. ch = this.nextChar();
  28974. charBuffered = true;
  28975. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28976. x = (x << 3) + (ch & 0x0F);
  28977. ch = this.nextChar();
  28978. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28979. charBuffered = false;
  28980. x = (x << 3) + (ch & 0x0F);
  28981. }
  28982. }
  28983. strBuf.push(String.fromCharCode(x));
  28984. break;
  28985. case 0x0D: // CR
  28986. if (this.peekChar() === 0x0A) { // LF
  28987. this.nextChar();
  28988. }
  28989. break;
  28990. case 0x0A: // LF
  28991. break;
  28992. default:
  28993. strBuf.push(String.fromCharCode(ch));
  28994. break;
  28995. }
  28996. break;
  28997. default:
  28998. strBuf.push(String.fromCharCode(ch));
  28999. break;
  29000. }
  29001. if (done) {
  29002. break;
  29003. }
  29004. if (!charBuffered) {
  29005. ch = this.nextChar();
  29006. }
  29007. }
  29008. return strBuf.join('');
  29009. },
  29010. getName: function Lexer_getName() {
  29011. var ch;
  29012. var strBuf = this.strBuf;
  29013. strBuf.length = 0;
  29014. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29015. if (ch === 0x23) { // '#'
  29016. ch = this.nextChar();
  29017. var x = toHexDigit(ch);
  29018. if (x !== -1) {
  29019. var x2 = toHexDigit(this.nextChar());
  29020. if (x2 === -1) {
  29021. error('Illegal digit in hex char in name: ' + x2);
  29022. }
  29023. strBuf.push(String.fromCharCode((x << 4) | x2));
  29024. } else {
  29025. strBuf.push('#', String.fromCharCode(ch));
  29026. }
  29027. } else {
  29028. strBuf.push(String.fromCharCode(ch));
  29029. }
  29030. }
  29031. if (strBuf.length > 128) {
  29032. error('Warning: name token is longer than allowed by the spec: ' +
  29033. strBuf.length);
  29034. }
  29035. return Name.get(strBuf.join(''));
  29036. },
  29037. getHexString: function Lexer_getHexString() {
  29038. var strBuf = this.strBuf;
  29039. strBuf.length = 0;
  29040. var ch = this.currentChar;
  29041. var isFirstHex = true;
  29042. var firstDigit;
  29043. var secondDigit;
  29044. while (true) {
  29045. if (ch < 0) {
  29046. warn('Unterminated hex string');
  29047. break;
  29048. } else if (ch === 0x3E) { // '>'
  29049. this.nextChar();
  29050. break;
  29051. } else if (specialChars[ch] === 1) {
  29052. ch = this.nextChar();
  29053. continue;
  29054. } else {
  29055. if (isFirstHex) {
  29056. firstDigit = toHexDigit(ch);
  29057. if (firstDigit === -1) {
  29058. warn('Ignoring invalid character "' + ch + '" in hex string');
  29059. ch = this.nextChar();
  29060. continue;
  29061. }
  29062. } else {
  29063. secondDigit = toHexDigit(ch);
  29064. if (secondDigit === -1) {
  29065. warn('Ignoring invalid character "' + ch + '" in hex string');
  29066. ch = this.nextChar();
  29067. continue;
  29068. }
  29069. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29070. }
  29071. isFirstHex = !isFirstHex;
  29072. ch = this.nextChar();
  29073. }
  29074. }
  29075. return strBuf.join('');
  29076. },
  29077. getObj: function Lexer_getObj() {
  29078. // skip whitespace and comments
  29079. var comment = false;
  29080. var ch = this.currentChar;
  29081. while (true) {
  29082. if (ch < 0) {
  29083. return EOF;
  29084. }
  29085. if (comment) {
  29086. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29087. comment = false;
  29088. }
  29089. } else if (ch === 0x25) { // '%'
  29090. comment = true;
  29091. } else if (specialChars[ch] !== 1) {
  29092. break;
  29093. }
  29094. ch = this.nextChar();
  29095. }
  29096. // start reading token
  29097. switch (ch | 0) {
  29098. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29099. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29100. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29101. return this.getNumber();
  29102. case 0x28: // '('
  29103. return this.getString();
  29104. case 0x2F: // '/'
  29105. return this.getName();
  29106. // array punctuation
  29107. case 0x5B: // '['
  29108. this.nextChar();
  29109. return Cmd.get('[');
  29110. case 0x5D: // ']'
  29111. this.nextChar();
  29112. return Cmd.get(']');
  29113. // hex string or dict punctuation
  29114. case 0x3C: // '<'
  29115. ch = this.nextChar();
  29116. if (ch === 0x3C) {
  29117. // dict punctuation
  29118. this.nextChar();
  29119. return Cmd.get('<<');
  29120. }
  29121. return this.getHexString();
  29122. // dict punctuation
  29123. case 0x3E: // '>'
  29124. ch = this.nextChar();
  29125. if (ch === 0x3E) {
  29126. this.nextChar();
  29127. return Cmd.get('>>');
  29128. }
  29129. return Cmd.get('>');
  29130. case 0x7B: // '{'
  29131. this.nextChar();
  29132. return Cmd.get('{');
  29133. case 0x7D: // '}'
  29134. this.nextChar();
  29135. return Cmd.get('}');
  29136. case 0x29: // ')'
  29137. error('Illegal character: ' + ch);
  29138. break;
  29139. }
  29140. // command
  29141. var str = String.fromCharCode(ch);
  29142. var knownCommands = this.knownCommands;
  29143. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29144. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29145. // stop if known command is found and next character does not make
  29146. // the str a command
  29147. var possibleCommand = str + String.fromCharCode(ch);
  29148. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29149. break;
  29150. }
  29151. if (str.length === 128) {
  29152. error('Command token too long: ' + str.length);
  29153. }
  29154. str = possibleCommand;
  29155. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29156. }
  29157. if (str === 'true') {
  29158. return true;
  29159. }
  29160. if (str === 'false') {
  29161. return false;
  29162. }
  29163. if (str === 'null') {
  29164. return null;
  29165. }
  29166. return Cmd.get(str);
  29167. },
  29168. skipToNextLine: function Lexer_skipToNextLine() {
  29169. var ch = this.currentChar;
  29170. while (ch >= 0) {
  29171. if (ch === 0x0D) { // CR
  29172. ch = this.nextChar();
  29173. if (ch === 0x0A) { // LF
  29174. this.nextChar();
  29175. }
  29176. break;
  29177. } else if (ch === 0x0A) { // LF
  29178. this.nextChar();
  29179. break;
  29180. }
  29181. ch = this.nextChar();
  29182. }
  29183. }
  29184. };
  29185. return Lexer;
  29186. })();
  29187. var Linearization = {
  29188. create: function LinearizationCreate(stream) {
  29189. function getInt(name, allowZeroValue) {
  29190. var obj = linDict.get(name);
  29191. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29192. return obj;
  29193. }
  29194. throw new Error('The "' + name + '" parameter in the linearization ' +
  29195. 'dictionary is invalid.');
  29196. }
  29197. function getHints() {
  29198. var hints = linDict.get('H'), hintsLength, item;
  29199. if (isArray(hints) &&
  29200. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29201. for (var index = 0; index < hintsLength; index++) {
  29202. if (!(isInt(item = hints[index]) && item > 0)) {
  29203. throw new Error('Hint (' + index +
  29204. ') in the linearization dictionary is invalid.');
  29205. }
  29206. }
  29207. return hints;
  29208. }
  29209. throw new Error('Hint array in the linearization dictionary is invalid.');
  29210. }
  29211. var parser = new Parser(new Lexer(stream), false, null);
  29212. var obj1 = parser.getObj();
  29213. var obj2 = parser.getObj();
  29214. var obj3 = parser.getObj();
  29215. var linDict = parser.getObj();
  29216. var obj, length;
  29217. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29218. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29219. return null; // No valid linearization dictionary found.
  29220. } else if ((length = getInt('L')) !== stream.length) {
  29221. throw new Error('The "L" parameter in the linearization dictionary ' +
  29222. 'does not equal the stream length.');
  29223. }
  29224. return {
  29225. length: length,
  29226. hints: getHints(),
  29227. objectNumberFirst: getInt('O'),
  29228. endFirst: getInt('E'),
  29229. numPages: getInt('N'),
  29230. mainXRefEntriesOffset: getInt('T'),
  29231. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29232. };
  29233. }
  29234. };
  29235. var PostScriptParser = (function PostScriptParserClosure() {
  29236. function PostScriptParser(lexer) {
  29237. this.lexer = lexer;
  29238. this.operators = [];
  29239. this.token = null;
  29240. this.prev = null;
  29241. }
  29242. PostScriptParser.prototype = {
  29243. nextToken: function PostScriptParser_nextToken() {
  29244. this.prev = this.token;
  29245. this.token = this.lexer.getToken();
  29246. },
  29247. accept: function PostScriptParser_accept(type) {
  29248. if (this.token.type === type) {
  29249. this.nextToken();
  29250. return true;
  29251. }
  29252. return false;
  29253. },
  29254. expect: function PostScriptParser_expect(type) {
  29255. if (this.accept(type)) {
  29256. return true;
  29257. }
  29258. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29259. type + '.');
  29260. },
  29261. parse: function PostScriptParser_parse() {
  29262. this.nextToken();
  29263. this.expect(PostScriptTokenTypes.LBRACE);
  29264. this.parseBlock();
  29265. this.expect(PostScriptTokenTypes.RBRACE);
  29266. return this.operators;
  29267. },
  29268. parseBlock: function PostScriptParser_parseBlock() {
  29269. while (true) {
  29270. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29271. this.operators.push(this.prev.value);
  29272. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29273. this.operators.push(this.prev.value);
  29274. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29275. this.parseCondition();
  29276. } else {
  29277. return;
  29278. }
  29279. }
  29280. },
  29281. parseCondition: function PostScriptParser_parseCondition() {
  29282. // Add two place holders that will be updated later
  29283. var conditionLocation = this.operators.length;
  29284. this.operators.push(null, null);
  29285. this.parseBlock();
  29286. this.expect(PostScriptTokenTypes.RBRACE);
  29287. if (this.accept(PostScriptTokenTypes.IF)) {
  29288. // The true block is right after the 'if' so it just falls through on
  29289. // true else it jumps and skips the true block.
  29290. this.operators[conditionLocation] = this.operators.length;
  29291. this.operators[conditionLocation + 1] = 'jz';
  29292. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29293. var jumpLocation = this.operators.length;
  29294. this.operators.push(null, null);
  29295. var endOfTrue = this.operators.length;
  29296. this.parseBlock();
  29297. this.expect(PostScriptTokenTypes.RBRACE);
  29298. this.expect(PostScriptTokenTypes.IFELSE);
  29299. // The jump is added at the end of the true block to skip the false
  29300. // block.
  29301. this.operators[jumpLocation] = this.operators.length;
  29302. this.operators[jumpLocation + 1] = 'j';
  29303. this.operators[conditionLocation] = endOfTrue;
  29304. this.operators[conditionLocation + 1] = 'jz';
  29305. } else {
  29306. error('PS Function: error parsing conditional.');
  29307. }
  29308. }
  29309. };
  29310. return PostScriptParser;
  29311. })();
  29312. var PostScriptTokenTypes = {
  29313. LBRACE: 0,
  29314. RBRACE: 1,
  29315. NUMBER: 2,
  29316. OPERATOR: 3,
  29317. IF: 4,
  29318. IFELSE: 5
  29319. };
  29320. var PostScriptToken = (function PostScriptTokenClosure() {
  29321. function PostScriptToken(type, value) {
  29322. this.type = type;
  29323. this.value = value;
  29324. }
  29325. var opCache = {};
  29326. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29327. var opValue = opCache[op];
  29328. if (opValue) {
  29329. return opValue;
  29330. }
  29331. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29332. };
  29333. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29334. '{');
  29335. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29336. '}');
  29337. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29338. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29339. 'IFELSE');
  29340. return PostScriptToken;
  29341. })();
  29342. var PostScriptLexer = (function PostScriptLexerClosure() {
  29343. function PostScriptLexer(stream) {
  29344. this.stream = stream;
  29345. this.nextChar();
  29346. this.strBuf = [];
  29347. }
  29348. PostScriptLexer.prototype = {
  29349. nextChar: function PostScriptLexer_nextChar() {
  29350. return (this.currentChar = this.stream.getByte());
  29351. },
  29352. getToken: function PostScriptLexer_getToken() {
  29353. var comment = false;
  29354. var ch = this.currentChar;
  29355. // skip comments
  29356. while (true) {
  29357. if (ch < 0) {
  29358. return EOF;
  29359. }
  29360. if (comment) {
  29361. if (ch === 0x0A || ch === 0x0D) {
  29362. comment = false;
  29363. }
  29364. } else if (ch === 0x25) { // '%'
  29365. comment = true;
  29366. } else if (!Lexer.isSpace(ch)) {
  29367. break;
  29368. }
  29369. ch = this.nextChar();
  29370. }
  29371. switch (ch | 0) {
  29372. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29373. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29374. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29375. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29376. this.getNumber());
  29377. case 0x7B: // '{'
  29378. this.nextChar();
  29379. return PostScriptToken.LBRACE;
  29380. case 0x7D: // '}'
  29381. this.nextChar();
  29382. return PostScriptToken.RBRACE;
  29383. }
  29384. // operator
  29385. var strBuf = this.strBuf;
  29386. strBuf.length = 0;
  29387. strBuf[0] = String.fromCharCode(ch);
  29388. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29389. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29390. strBuf.push(String.fromCharCode(ch));
  29391. }
  29392. var str = strBuf.join('');
  29393. switch (str.toLowerCase()) {
  29394. case 'if':
  29395. return PostScriptToken.IF;
  29396. case 'ifelse':
  29397. return PostScriptToken.IFELSE;
  29398. default:
  29399. return PostScriptToken.getOperator(str);
  29400. }
  29401. },
  29402. getNumber: function PostScriptLexer_getNumber() {
  29403. var ch = this.currentChar;
  29404. var strBuf = this.strBuf;
  29405. strBuf.length = 0;
  29406. strBuf[0] = String.fromCharCode(ch);
  29407. while ((ch = this.nextChar()) >= 0) {
  29408. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29409. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29410. strBuf.push(String.fromCharCode(ch));
  29411. } else {
  29412. break;
  29413. }
  29414. }
  29415. var value = parseFloat(strBuf.join(''));
  29416. if (isNaN(value)) {
  29417. error('Invalid floating point number: ' + value);
  29418. }
  29419. return value;
  29420. }
  29421. };
  29422. return PostScriptLexer;
  29423. })();
  29424. var Stream = (function StreamClosure() {
  29425. function Stream(arrayBuffer, start, length, dict) {
  29426. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29427. arrayBuffer : new Uint8Array(arrayBuffer));
  29428. this.start = start || 0;
  29429. this.pos = this.start;
  29430. this.end = (start + length) || this.bytes.length;
  29431. this.dict = dict;
  29432. }
  29433. // required methods for a stream. if a particular stream does not
  29434. // implement these, an error should be thrown
  29435. Stream.prototype = {
  29436. get length() {
  29437. return this.end - this.start;
  29438. },
  29439. get isEmpty() {
  29440. return this.length === 0;
  29441. },
  29442. getByte: function Stream_getByte() {
  29443. if (this.pos >= this.end) {
  29444. return -1;
  29445. }
  29446. return this.bytes[this.pos++];
  29447. },
  29448. getUint16: function Stream_getUint16() {
  29449. var b0 = this.getByte();
  29450. var b1 = this.getByte();
  29451. if (b0 === -1 || b1 === -1) {
  29452. return -1;
  29453. }
  29454. return (b0 << 8) + b1;
  29455. },
  29456. getInt32: function Stream_getInt32() {
  29457. var b0 = this.getByte();
  29458. var b1 = this.getByte();
  29459. var b2 = this.getByte();
  29460. var b3 = this.getByte();
  29461. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29462. },
  29463. // returns subarray of original buffer
  29464. // should only be read
  29465. getBytes: function Stream_getBytes(length) {
  29466. var bytes = this.bytes;
  29467. var pos = this.pos;
  29468. var strEnd = this.end;
  29469. if (!length) {
  29470. return bytes.subarray(pos, strEnd);
  29471. }
  29472. var end = pos + length;
  29473. if (end > strEnd) {
  29474. end = strEnd;
  29475. }
  29476. this.pos = end;
  29477. return bytes.subarray(pos, end);
  29478. },
  29479. peekByte: function Stream_peekByte() {
  29480. var peekedByte = this.getByte();
  29481. this.pos--;
  29482. return peekedByte;
  29483. },
  29484. peekBytes: function Stream_peekBytes(length) {
  29485. var bytes = this.getBytes(length);
  29486. this.pos -= bytes.length;
  29487. return bytes;
  29488. },
  29489. skip: function Stream_skip(n) {
  29490. if (!n) {
  29491. n = 1;
  29492. }
  29493. this.pos += n;
  29494. },
  29495. reset: function Stream_reset() {
  29496. this.pos = this.start;
  29497. },
  29498. moveStart: function Stream_moveStart() {
  29499. this.start = this.pos;
  29500. },
  29501. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29502. return new Stream(this.bytes.buffer, start, length, dict);
  29503. },
  29504. isStream: true
  29505. };
  29506. return Stream;
  29507. })();
  29508. var StringStream = (function StringStreamClosure() {
  29509. function StringStream(str) {
  29510. var length = str.length;
  29511. var bytes = new Uint8Array(length);
  29512. for (var n = 0; n < length; ++n) {
  29513. bytes[n] = str.charCodeAt(n);
  29514. }
  29515. Stream.call(this, bytes);
  29516. }
  29517. StringStream.prototype = Stream.prototype;
  29518. return StringStream;
  29519. })();
  29520. // super class for the decoding streams
  29521. var DecodeStream = (function DecodeStreamClosure() {
  29522. // Lots of DecodeStreams are created whose buffers are never used. For these
  29523. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29524. // having special cases that would be required if we used |null| for an empty
  29525. // buffer.
  29526. var emptyBuffer = new Uint8Array(0);
  29527. function DecodeStream(maybeMinBufferLength) {
  29528. this.pos = 0;
  29529. this.bufferLength = 0;
  29530. this.eof = false;
  29531. this.buffer = emptyBuffer;
  29532. this.minBufferLength = 512;
  29533. if (maybeMinBufferLength) {
  29534. // Compute the first power of two that is as big as maybeMinBufferLength.
  29535. while (this.minBufferLength < maybeMinBufferLength) {
  29536. this.minBufferLength *= 2;
  29537. }
  29538. }
  29539. }
  29540. DecodeStream.prototype = {
  29541. get isEmpty() {
  29542. while (!this.eof && this.bufferLength === 0) {
  29543. this.readBlock();
  29544. }
  29545. return this.bufferLength === 0;
  29546. },
  29547. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29548. var buffer = this.buffer;
  29549. if (requested <= buffer.byteLength) {
  29550. return buffer;
  29551. }
  29552. var size = this.minBufferLength;
  29553. while (size < requested) {
  29554. size *= 2;
  29555. }
  29556. var buffer2 = new Uint8Array(size);
  29557. buffer2.set(buffer);
  29558. return (this.buffer = buffer2);
  29559. },
  29560. getByte: function DecodeStream_getByte() {
  29561. var pos = this.pos;
  29562. while (this.bufferLength <= pos) {
  29563. if (this.eof) {
  29564. return -1;
  29565. }
  29566. this.readBlock();
  29567. }
  29568. return this.buffer[this.pos++];
  29569. },
  29570. getUint16: function DecodeStream_getUint16() {
  29571. var b0 = this.getByte();
  29572. var b1 = this.getByte();
  29573. if (b0 === -1 || b1 === -1) {
  29574. return -1;
  29575. }
  29576. return (b0 << 8) + b1;
  29577. },
  29578. getInt32: function DecodeStream_getInt32() {
  29579. var b0 = this.getByte();
  29580. var b1 = this.getByte();
  29581. var b2 = this.getByte();
  29582. var b3 = this.getByte();
  29583. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29584. },
  29585. getBytes: function DecodeStream_getBytes(length) {
  29586. var end, pos = this.pos;
  29587. if (length) {
  29588. this.ensureBuffer(pos + length);
  29589. end = pos + length;
  29590. while (!this.eof && this.bufferLength < end) {
  29591. this.readBlock();
  29592. }
  29593. var bufEnd = this.bufferLength;
  29594. if (end > bufEnd) {
  29595. end = bufEnd;
  29596. }
  29597. } else {
  29598. while (!this.eof) {
  29599. this.readBlock();
  29600. }
  29601. end = this.bufferLength;
  29602. }
  29603. this.pos = end;
  29604. return this.buffer.subarray(pos, end);
  29605. },
  29606. peekByte: function DecodeStream_peekByte() {
  29607. var peekedByte = this.getByte();
  29608. this.pos--;
  29609. return peekedByte;
  29610. },
  29611. peekBytes: function DecodeStream_peekBytes(length) {
  29612. var bytes = this.getBytes(length);
  29613. this.pos -= bytes.length;
  29614. return bytes;
  29615. },
  29616. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29617. var end = start + length;
  29618. while (this.bufferLength <= end && !this.eof) {
  29619. this.readBlock();
  29620. }
  29621. return new Stream(this.buffer, start, length, dict);
  29622. },
  29623. skip: function DecodeStream_skip(n) {
  29624. if (!n) {
  29625. n = 1;
  29626. }
  29627. this.pos += n;
  29628. },
  29629. reset: function DecodeStream_reset() {
  29630. this.pos = 0;
  29631. },
  29632. getBaseStreams: function DecodeStream_getBaseStreams() {
  29633. if (this.str && this.str.getBaseStreams) {
  29634. return this.str.getBaseStreams();
  29635. }
  29636. return [];
  29637. }
  29638. };
  29639. return DecodeStream;
  29640. })();
  29641. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29642. function StreamsSequenceStream(streams) {
  29643. this.streams = streams;
  29644. DecodeStream.call(this, /* maybeLength = */ null);
  29645. }
  29646. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29647. StreamsSequenceStream.prototype.readBlock =
  29648. function streamSequenceStreamReadBlock() {
  29649. var streams = this.streams;
  29650. if (streams.length === 0) {
  29651. this.eof = true;
  29652. return;
  29653. }
  29654. var stream = streams.shift();
  29655. var chunk = stream.getBytes();
  29656. var bufferLength = this.bufferLength;
  29657. var newLength = bufferLength + chunk.length;
  29658. var buffer = this.ensureBuffer(newLength);
  29659. buffer.set(chunk, bufferLength);
  29660. this.bufferLength = newLength;
  29661. };
  29662. StreamsSequenceStream.prototype.getBaseStreams =
  29663. function StreamsSequenceStream_getBaseStreams() {
  29664. var baseStreams = [];
  29665. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29666. var stream = this.streams[i];
  29667. if (stream.getBaseStreams) {
  29668. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29669. }
  29670. }
  29671. return baseStreams;
  29672. };
  29673. return StreamsSequenceStream;
  29674. })();
  29675. var FlateStream = (function FlateStreamClosure() {
  29676. var codeLenCodeMap = new Uint32Array([
  29677. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29678. ]);
  29679. var lengthDecode = new Uint32Array([
  29680. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29681. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29682. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29683. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29684. ]);
  29685. var distDecode = new Uint32Array([
  29686. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29687. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29688. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29689. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29690. ]);
  29691. var fixedLitCodeTab = [new Uint32Array([
  29692. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29693. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29694. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29695. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29696. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29697. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29698. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29699. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29700. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29701. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29702. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29703. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29704. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29705. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29706. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29707. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29708. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29709. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29710. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29711. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29712. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29713. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29714. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29715. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29716. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29717. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29718. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29719. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29720. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29721. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29722. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29723. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29724. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29725. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29726. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29727. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29728. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29729. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29730. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29731. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29732. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29733. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29734. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29735. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29736. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29737. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29738. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29739. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29740. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29741. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29742. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29743. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29744. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29745. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29746. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29747. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29748. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29749. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29750. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29751. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29752. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29753. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29754. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29755. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29756. ]), 9];
  29757. var fixedDistCodeTab = [new Uint32Array([
  29758. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29759. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29760. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29761. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29762. ]), 5];
  29763. function FlateStream(str, maybeLength) {
  29764. this.str = str;
  29765. this.dict = str.dict;
  29766. var cmf = str.getByte();
  29767. var flg = str.getByte();
  29768. if (cmf === -1 || flg === -1) {
  29769. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29770. }
  29771. if ((cmf & 0x0f) !== 0x08) {
  29772. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29773. }
  29774. if ((((cmf << 8) + flg) % 31) !== 0) {
  29775. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29776. }
  29777. if (flg & 0x20) {
  29778. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29779. }
  29780. this.codeSize = 0;
  29781. this.codeBuf = 0;
  29782. DecodeStream.call(this, maybeLength);
  29783. }
  29784. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29785. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29786. var str = this.str;
  29787. var codeSize = this.codeSize;
  29788. var codeBuf = this.codeBuf;
  29789. var b;
  29790. while (codeSize < bits) {
  29791. if ((b = str.getByte()) === -1) {
  29792. error('Bad encoding in flate stream');
  29793. }
  29794. codeBuf |= b << codeSize;
  29795. codeSize += 8;
  29796. }
  29797. b = codeBuf & ((1 << bits) - 1);
  29798. this.codeBuf = codeBuf >> bits;
  29799. this.codeSize = codeSize -= bits;
  29800. return b;
  29801. };
  29802. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29803. var str = this.str;
  29804. var codes = table[0];
  29805. var maxLen = table[1];
  29806. var codeSize = this.codeSize;
  29807. var codeBuf = this.codeBuf;
  29808. var b;
  29809. while (codeSize < maxLen) {
  29810. if ((b = str.getByte()) === -1) {
  29811. // premature end of stream. code might however still be valid.
  29812. // codeSize < codeLen check below guards against incomplete codeVal.
  29813. break;
  29814. }
  29815. codeBuf |= (b << codeSize);
  29816. codeSize += 8;
  29817. }
  29818. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29819. var codeLen = code >> 16;
  29820. var codeVal = code & 0xffff;
  29821. if (codeLen < 1 || codeSize < codeLen) {
  29822. error('Bad encoding in flate stream');
  29823. }
  29824. this.codeBuf = (codeBuf >> codeLen);
  29825. this.codeSize = (codeSize - codeLen);
  29826. return codeVal;
  29827. };
  29828. FlateStream.prototype.generateHuffmanTable =
  29829. function flateStreamGenerateHuffmanTable(lengths) {
  29830. var n = lengths.length;
  29831. // find max code length
  29832. var maxLen = 0;
  29833. var i;
  29834. for (i = 0; i < n; ++i) {
  29835. if (lengths[i] > maxLen) {
  29836. maxLen = lengths[i];
  29837. }
  29838. }
  29839. // build the table
  29840. var size = 1 << maxLen;
  29841. var codes = new Uint32Array(size);
  29842. for (var len = 1, code = 0, skip = 2;
  29843. len <= maxLen;
  29844. ++len, code <<= 1, skip <<= 1) {
  29845. for (var val = 0; val < n; ++val) {
  29846. if (lengths[val] === len) {
  29847. // bit-reverse the code
  29848. var code2 = 0;
  29849. var t = code;
  29850. for (i = 0; i < len; ++i) {
  29851. code2 = (code2 << 1) | (t & 1);
  29852. t >>= 1;
  29853. }
  29854. // fill the table entries
  29855. for (i = code2; i < size; i += skip) {
  29856. codes[i] = (len << 16) | val;
  29857. }
  29858. ++code;
  29859. }
  29860. }
  29861. }
  29862. return [codes, maxLen];
  29863. };
  29864. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29865. var buffer, len;
  29866. var str = this.str;
  29867. // read block header
  29868. var hdr = this.getBits(3);
  29869. if (hdr & 1) {
  29870. this.eof = true;
  29871. }
  29872. hdr >>= 1;
  29873. if (hdr === 0) { // uncompressed block
  29874. var b;
  29875. if ((b = str.getByte()) === -1) {
  29876. error('Bad block header in flate stream');
  29877. }
  29878. var blockLen = b;
  29879. if ((b = str.getByte()) === -1) {
  29880. error('Bad block header in flate stream');
  29881. }
  29882. blockLen |= (b << 8);
  29883. if ((b = str.getByte()) === -1) {
  29884. error('Bad block header in flate stream');
  29885. }
  29886. var check = b;
  29887. if ((b = str.getByte()) === -1) {
  29888. error('Bad block header in flate stream');
  29889. }
  29890. check |= (b << 8);
  29891. if (check !== (~blockLen & 0xffff) &&
  29892. (blockLen !== 0 || check !== 0)) {
  29893. // Ignoring error for bad "empty" block (see issue 1277)
  29894. error('Bad uncompressed block length in flate stream');
  29895. }
  29896. this.codeBuf = 0;
  29897. this.codeSize = 0;
  29898. var bufferLength = this.bufferLength;
  29899. buffer = this.ensureBuffer(bufferLength + blockLen);
  29900. var end = bufferLength + blockLen;
  29901. this.bufferLength = end;
  29902. if (blockLen === 0) {
  29903. if (str.peekByte() === -1) {
  29904. this.eof = true;
  29905. }
  29906. } else {
  29907. for (var n = bufferLength; n < end; ++n) {
  29908. if ((b = str.getByte()) === -1) {
  29909. this.eof = true;
  29910. break;
  29911. }
  29912. buffer[n] = b;
  29913. }
  29914. }
  29915. return;
  29916. }
  29917. var litCodeTable;
  29918. var distCodeTable;
  29919. if (hdr === 1) { // compressed block, fixed codes
  29920. litCodeTable = fixedLitCodeTab;
  29921. distCodeTable = fixedDistCodeTab;
  29922. } else if (hdr === 2) { // compressed block, dynamic codes
  29923. var numLitCodes = this.getBits(5) + 257;
  29924. var numDistCodes = this.getBits(5) + 1;
  29925. var numCodeLenCodes = this.getBits(4) + 4;
  29926. // build the code lengths code table
  29927. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29928. var i;
  29929. for (i = 0; i < numCodeLenCodes; ++i) {
  29930. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29931. }
  29932. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29933. // build the literal and distance code tables
  29934. len = 0;
  29935. i = 0;
  29936. var codes = numLitCodes + numDistCodes;
  29937. var codeLengths = new Uint8Array(codes);
  29938. var bitsLength, bitsOffset, what;
  29939. while (i < codes) {
  29940. var code = this.getCode(codeLenCodeTab);
  29941. if (code === 16) {
  29942. bitsLength = 2; bitsOffset = 3; what = len;
  29943. } else if (code === 17) {
  29944. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29945. } else if (code === 18) {
  29946. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29947. } else {
  29948. codeLengths[i++] = len = code;
  29949. continue;
  29950. }
  29951. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29952. while (repeatLength-- > 0) {
  29953. codeLengths[i++] = what;
  29954. }
  29955. }
  29956. litCodeTable =
  29957. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29958. distCodeTable =
  29959. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29960. } else {
  29961. error('Unknown block type in flate stream');
  29962. }
  29963. buffer = this.buffer;
  29964. var limit = buffer ? buffer.length : 0;
  29965. var pos = this.bufferLength;
  29966. while (true) {
  29967. var code1 = this.getCode(litCodeTable);
  29968. if (code1 < 256) {
  29969. if (pos + 1 >= limit) {
  29970. buffer = this.ensureBuffer(pos + 1);
  29971. limit = buffer.length;
  29972. }
  29973. buffer[pos++] = code1;
  29974. continue;
  29975. }
  29976. if (code1 === 256) {
  29977. this.bufferLength = pos;
  29978. return;
  29979. }
  29980. code1 -= 257;
  29981. code1 = lengthDecode[code1];
  29982. var code2 = code1 >> 16;
  29983. if (code2 > 0) {
  29984. code2 = this.getBits(code2);
  29985. }
  29986. len = (code1 & 0xffff) + code2;
  29987. code1 = this.getCode(distCodeTable);
  29988. code1 = distDecode[code1];
  29989. code2 = code1 >> 16;
  29990. if (code2 > 0) {
  29991. code2 = this.getBits(code2);
  29992. }
  29993. var dist = (code1 & 0xffff) + code2;
  29994. if (pos + len >= limit) {
  29995. buffer = this.ensureBuffer(pos + len);
  29996. limit = buffer.length;
  29997. }
  29998. for (var k = 0; k < len; ++k, ++pos) {
  29999. buffer[pos] = buffer[pos - dist];
  30000. }
  30001. }
  30002. };
  30003. return FlateStream;
  30004. })();
  30005. var PredictorStream = (function PredictorStreamClosure() {
  30006. function PredictorStream(str, maybeLength, params) {
  30007. var predictor = this.predictor = params.get('Predictor') || 1;
  30008. if (predictor <= 1) {
  30009. return str; // no prediction
  30010. }
  30011. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30012. error('Unsupported predictor: ' + predictor);
  30013. }
  30014. if (predictor === 2) {
  30015. this.readBlock = this.readBlockTiff;
  30016. } else {
  30017. this.readBlock = this.readBlockPng;
  30018. }
  30019. this.str = str;
  30020. this.dict = str.dict;
  30021. var colors = this.colors = params.get('Colors') || 1;
  30022. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30023. var columns = this.columns = params.get('Columns') || 1;
  30024. this.pixBytes = (colors * bits + 7) >> 3;
  30025. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30026. DecodeStream.call(this, maybeLength);
  30027. return this;
  30028. }
  30029. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30030. PredictorStream.prototype.readBlockTiff =
  30031. function predictorStreamReadBlockTiff() {
  30032. var rowBytes = this.rowBytes;
  30033. var bufferLength = this.bufferLength;
  30034. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30035. var bits = this.bits;
  30036. var colors = this.colors;
  30037. var rawBytes = this.str.getBytes(rowBytes);
  30038. this.eof = !rawBytes.length;
  30039. if (this.eof) {
  30040. return;
  30041. }
  30042. var inbuf = 0, outbuf = 0;
  30043. var inbits = 0, outbits = 0;
  30044. var pos = bufferLength;
  30045. var i;
  30046. if (bits === 1) {
  30047. for (i = 0; i < rowBytes; ++i) {
  30048. var c = rawBytes[i];
  30049. inbuf = (inbuf << 8) | c;
  30050. // bitwise addition is exclusive or
  30051. // first shift inbuf and then add
  30052. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30053. // truncate inbuf (assumes colors < 16)
  30054. inbuf &= 0xFFFF;
  30055. }
  30056. } else if (bits === 8) {
  30057. for (i = 0; i < colors; ++i) {
  30058. buffer[pos++] = rawBytes[i];
  30059. }
  30060. for (; i < rowBytes; ++i) {
  30061. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30062. pos++;
  30063. }
  30064. } else {
  30065. var compArray = new Uint8Array(colors + 1);
  30066. var bitMask = (1 << bits) - 1;
  30067. var j = 0, k = bufferLength;
  30068. var columns = this.columns;
  30069. for (i = 0; i < columns; ++i) {
  30070. for (var kk = 0; kk < colors; ++kk) {
  30071. if (inbits < bits) {
  30072. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30073. inbits += 8;
  30074. }
  30075. compArray[kk] = (compArray[kk] +
  30076. (inbuf >> (inbits - bits))) & bitMask;
  30077. inbits -= bits;
  30078. outbuf = (outbuf << bits) | compArray[kk];
  30079. outbits += bits;
  30080. if (outbits >= 8) {
  30081. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30082. outbits -= 8;
  30083. }
  30084. }
  30085. }
  30086. if (outbits > 0) {
  30087. buffer[k++] = (outbuf << (8 - outbits)) +
  30088. (inbuf & ((1 << (8 - outbits)) - 1));
  30089. }
  30090. }
  30091. this.bufferLength += rowBytes;
  30092. };
  30093. PredictorStream.prototype.readBlockPng =
  30094. function predictorStreamReadBlockPng() {
  30095. var rowBytes = this.rowBytes;
  30096. var pixBytes = this.pixBytes;
  30097. var predictor = this.str.getByte();
  30098. var rawBytes = this.str.getBytes(rowBytes);
  30099. this.eof = !rawBytes.length;
  30100. if (this.eof) {
  30101. return;
  30102. }
  30103. var bufferLength = this.bufferLength;
  30104. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30105. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30106. if (prevRow.length === 0) {
  30107. prevRow = new Uint8Array(rowBytes);
  30108. }
  30109. var i, j = bufferLength, up, c;
  30110. switch (predictor) {
  30111. case 0:
  30112. for (i = 0; i < rowBytes; ++i) {
  30113. buffer[j++] = rawBytes[i];
  30114. }
  30115. break;
  30116. case 1:
  30117. for (i = 0; i < pixBytes; ++i) {
  30118. buffer[j++] = rawBytes[i];
  30119. }
  30120. for (; i < rowBytes; ++i) {
  30121. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30122. j++;
  30123. }
  30124. break;
  30125. case 2:
  30126. for (i = 0; i < rowBytes; ++i) {
  30127. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30128. }
  30129. break;
  30130. case 3:
  30131. for (i = 0; i < pixBytes; ++i) {
  30132. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30133. }
  30134. for (; i < rowBytes; ++i) {
  30135. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30136. rawBytes[i]) & 0xFF;
  30137. j++;
  30138. }
  30139. break;
  30140. case 4:
  30141. // we need to save the up left pixels values. the simplest way
  30142. // is to create a new buffer
  30143. for (i = 0; i < pixBytes; ++i) {
  30144. up = prevRow[i];
  30145. c = rawBytes[i];
  30146. buffer[j++] = up + c;
  30147. }
  30148. for (; i < rowBytes; ++i) {
  30149. up = prevRow[i];
  30150. var upLeft = prevRow[i - pixBytes];
  30151. var left = buffer[j - pixBytes];
  30152. var p = left + up - upLeft;
  30153. var pa = p - left;
  30154. if (pa < 0) {
  30155. pa = -pa;
  30156. }
  30157. var pb = p - up;
  30158. if (pb < 0) {
  30159. pb = -pb;
  30160. }
  30161. var pc = p - upLeft;
  30162. if (pc < 0) {
  30163. pc = -pc;
  30164. }
  30165. c = rawBytes[i];
  30166. if (pa <= pb && pa <= pc) {
  30167. buffer[j++] = left + c;
  30168. } else if (pb <= pc) {
  30169. buffer[j++] = up + c;
  30170. } else {
  30171. buffer[j++] = upLeft + c;
  30172. }
  30173. }
  30174. break;
  30175. default:
  30176. error('Unsupported predictor: ' + predictor);
  30177. }
  30178. this.bufferLength += rowBytes;
  30179. };
  30180. return PredictorStream;
  30181. })();
  30182. /**
  30183. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30184. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30185. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30186. * a library to decode these images and the stream behaves like all the other
  30187. * DecodeStreams.
  30188. */
  30189. var JpegStream = (function JpegStreamClosure() {
  30190. function JpegStream(stream, maybeLength, dict, xref) {
  30191. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30192. // Note: this seems to mainly affect inline images.
  30193. var ch;
  30194. while ((ch = stream.getByte()) !== -1) {
  30195. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30196. stream.skip(-1); // Reset the stream position to the SOI.
  30197. break;
  30198. }
  30199. }
  30200. this.stream = stream;
  30201. this.maybeLength = maybeLength;
  30202. this.dict = dict;
  30203. DecodeStream.call(this, maybeLength);
  30204. }
  30205. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30206. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30207. get: function JpegStream_bytes() {
  30208. // If this.maybeLength is null, we'll get the entire stream.
  30209. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30210. },
  30211. configurable: true
  30212. });
  30213. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30214. if (this.bufferLength) {
  30215. return;
  30216. }
  30217. try {
  30218. var jpegImage = new JpegImage();
  30219. // checking if values needs to be transformed before conversion
  30220. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30221. var decodeArr = this.dict.get('Decode');
  30222. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30223. var decodeArrLength = decodeArr.length;
  30224. var transform = new Int32Array(decodeArrLength);
  30225. var transformNeeded = false;
  30226. var maxValue = (1 << bitsPerComponent) - 1;
  30227. for (var i = 0; i < decodeArrLength; i += 2) {
  30228. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30229. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30230. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30231. transformNeeded = true;
  30232. }
  30233. }
  30234. if (transformNeeded) {
  30235. jpegImage.decodeTransform = transform;
  30236. }
  30237. }
  30238. jpegImage.parse(this.bytes);
  30239. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30240. this.forceRGB);
  30241. this.buffer = data;
  30242. this.bufferLength = data.length;
  30243. this.eof = true;
  30244. } catch (e) {
  30245. error('JPEG error: ' + e);
  30246. }
  30247. };
  30248. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30249. this.ensureBuffer();
  30250. return this.buffer;
  30251. };
  30252. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30253. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30254. };
  30255. /**
  30256. * Checks if the image can be decoded and displayed by the browser without any
  30257. * further processing such as color space conversions.
  30258. */
  30259. JpegStream.prototype.isNativelySupported =
  30260. function JpegStream_isNativelySupported(xref, res) {
  30261. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30262. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30263. };
  30264. /**
  30265. * Checks if the image can be decoded by the browser.
  30266. */
  30267. JpegStream.prototype.isNativelyDecodable =
  30268. function JpegStream_isNativelyDecodable(xref, res) {
  30269. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30270. var numComps = cs.numComps;
  30271. return numComps === 1 || numComps === 3;
  30272. };
  30273. return JpegStream;
  30274. })();
  30275. /**
  30276. * For JPEG 2000's we use a library to decode these images and
  30277. * the stream behaves like all the other DecodeStreams.
  30278. */
  30279. var JpxStream = (function JpxStreamClosure() {
  30280. function JpxStream(stream, maybeLength, dict) {
  30281. this.stream = stream;
  30282. this.maybeLength = maybeLength;
  30283. this.dict = dict;
  30284. DecodeStream.call(this, maybeLength);
  30285. }
  30286. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30287. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30288. get: function JpxStream_bytes() {
  30289. // If this.maybeLength is null, we'll get the entire stream.
  30290. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30291. },
  30292. configurable: true
  30293. });
  30294. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30295. if (this.bufferLength) {
  30296. return;
  30297. }
  30298. var jpxImage = new JpxImage();
  30299. jpxImage.parse(this.bytes);
  30300. var width = jpxImage.width;
  30301. var height = jpxImage.height;
  30302. var componentsCount = jpxImage.componentsCount;
  30303. var tileCount = jpxImage.tiles.length;
  30304. if (tileCount === 1) {
  30305. this.buffer = jpxImage.tiles[0].items;
  30306. } else {
  30307. var data = new Uint8Array(width * height * componentsCount);
  30308. for (var k = 0; k < tileCount; k++) {
  30309. var tileComponents = jpxImage.tiles[k];
  30310. var tileWidth = tileComponents.width;
  30311. var tileHeight = tileComponents.height;
  30312. var tileLeft = tileComponents.left;
  30313. var tileTop = tileComponents.top;
  30314. var src = tileComponents.items;
  30315. var srcPosition = 0;
  30316. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30317. var imgRowSize = width * componentsCount;
  30318. var tileRowSize = tileWidth * componentsCount;
  30319. for (var j = 0; j < tileHeight; j++) {
  30320. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30321. data.set(rowBytes, dataPosition);
  30322. srcPosition += tileRowSize;
  30323. dataPosition += imgRowSize;
  30324. }
  30325. }
  30326. this.buffer = data;
  30327. }
  30328. this.bufferLength = this.buffer.length;
  30329. this.eof = true;
  30330. };
  30331. return JpxStream;
  30332. })();
  30333. /**
  30334. * For JBIG2's we use a library to decode these images and
  30335. * the stream behaves like all the other DecodeStreams.
  30336. */
  30337. var Jbig2Stream = (function Jbig2StreamClosure() {
  30338. function Jbig2Stream(stream, maybeLength, dict) {
  30339. this.stream = stream;
  30340. this.maybeLength = maybeLength;
  30341. this.dict = dict;
  30342. DecodeStream.call(this, maybeLength);
  30343. }
  30344. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30345. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30346. get: function Jbig2Stream_bytes() {
  30347. // If this.maybeLength is null, we'll get the entire stream.
  30348. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30349. },
  30350. configurable: true
  30351. });
  30352. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30353. if (this.bufferLength) {
  30354. return;
  30355. }
  30356. var jbig2Image = new Jbig2Image();
  30357. var chunks = [], xref = this.dict.xref;
  30358. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30359. // According to the PDF specification, DecodeParms can be either
  30360. // a dictionary, or an array whose elements are dictionaries.
  30361. if (isArray(decodeParams)) {
  30362. if (decodeParams.length > 1) {
  30363. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30364. 'not supported.');
  30365. }
  30366. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30367. }
  30368. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30369. var globalsStream = decodeParams.get('JBIG2Globals');
  30370. var globals = globalsStream.getBytes();
  30371. chunks.push({data: globals, start: 0, end: globals.length});
  30372. }
  30373. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30374. var data = jbig2Image.parseChunks(chunks);
  30375. var dataLength = data.length;
  30376. // JBIG2 had black as 1 and white as 0, inverting the colors
  30377. for (var i = 0; i < dataLength; i++) {
  30378. data[i] ^= 0xFF;
  30379. }
  30380. this.buffer = data;
  30381. this.bufferLength = dataLength;
  30382. this.eof = true;
  30383. };
  30384. return Jbig2Stream;
  30385. })();
  30386. var DecryptStream = (function DecryptStreamClosure() {
  30387. function DecryptStream(str, maybeLength, decrypt) {
  30388. this.str = str;
  30389. this.dict = str.dict;
  30390. this.decrypt = decrypt;
  30391. this.nextChunk = null;
  30392. this.initialized = false;
  30393. DecodeStream.call(this, maybeLength);
  30394. }
  30395. var chunkSize = 512;
  30396. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30397. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30398. var chunk;
  30399. if (this.initialized) {
  30400. chunk = this.nextChunk;
  30401. } else {
  30402. chunk = this.str.getBytes(chunkSize);
  30403. this.initialized = true;
  30404. }
  30405. if (!chunk || chunk.length === 0) {
  30406. this.eof = true;
  30407. return;
  30408. }
  30409. this.nextChunk = this.str.getBytes(chunkSize);
  30410. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30411. var decrypt = this.decrypt;
  30412. chunk = decrypt(chunk, !hasMoreData);
  30413. var bufferLength = this.bufferLength;
  30414. var i, n = chunk.length;
  30415. var buffer = this.ensureBuffer(bufferLength + n);
  30416. for (i = 0; i < n; i++) {
  30417. buffer[bufferLength++] = chunk[i];
  30418. }
  30419. this.bufferLength = bufferLength;
  30420. };
  30421. return DecryptStream;
  30422. })();
  30423. var Ascii85Stream = (function Ascii85StreamClosure() {
  30424. function Ascii85Stream(str, maybeLength) {
  30425. this.str = str;
  30426. this.dict = str.dict;
  30427. this.input = new Uint8Array(5);
  30428. // Most streams increase in size when decoded, but Ascii85 streams
  30429. // typically shrink by ~20%.
  30430. if (maybeLength) {
  30431. maybeLength = 0.8 * maybeLength;
  30432. }
  30433. DecodeStream.call(this, maybeLength);
  30434. }
  30435. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30436. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30437. var TILDA_CHAR = 0x7E; // '~'
  30438. var Z_LOWER_CHAR = 0x7A; // 'z'
  30439. var EOF = -1;
  30440. var str = this.str;
  30441. var c = str.getByte();
  30442. while (Lexer.isSpace(c)) {
  30443. c = str.getByte();
  30444. }
  30445. if (c === EOF || c === TILDA_CHAR) {
  30446. this.eof = true;
  30447. return;
  30448. }
  30449. var bufferLength = this.bufferLength, buffer;
  30450. var i;
  30451. // special code for z
  30452. if (c === Z_LOWER_CHAR) {
  30453. buffer = this.ensureBuffer(bufferLength + 4);
  30454. for (i = 0; i < 4; ++i) {
  30455. buffer[bufferLength + i] = 0;
  30456. }
  30457. this.bufferLength += 4;
  30458. } else {
  30459. var input = this.input;
  30460. input[0] = c;
  30461. for (i = 1; i < 5; ++i) {
  30462. c = str.getByte();
  30463. while (Lexer.isSpace(c)) {
  30464. c = str.getByte();
  30465. }
  30466. input[i] = c;
  30467. if (c === EOF || c === TILDA_CHAR) {
  30468. break;
  30469. }
  30470. }
  30471. buffer = this.ensureBuffer(bufferLength + i - 1);
  30472. this.bufferLength += i - 1;
  30473. // partial ending;
  30474. if (i < 5) {
  30475. for (; i < 5; ++i) {
  30476. input[i] = 0x21 + 84;
  30477. }
  30478. this.eof = true;
  30479. }
  30480. var t = 0;
  30481. for (i = 0; i < 5; ++i) {
  30482. t = t * 85 + (input[i] - 0x21);
  30483. }
  30484. for (i = 3; i >= 0; --i) {
  30485. buffer[bufferLength + i] = t & 0xFF;
  30486. t >>= 8;
  30487. }
  30488. }
  30489. };
  30490. return Ascii85Stream;
  30491. })();
  30492. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30493. function AsciiHexStream(str, maybeLength) {
  30494. this.str = str;
  30495. this.dict = str.dict;
  30496. this.firstDigit = -1;
  30497. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30498. // by 50%.
  30499. if (maybeLength) {
  30500. maybeLength = 0.5 * maybeLength;
  30501. }
  30502. DecodeStream.call(this, maybeLength);
  30503. }
  30504. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30505. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30506. var UPSTREAM_BLOCK_SIZE = 8000;
  30507. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30508. if (!bytes.length) {
  30509. this.eof = true;
  30510. return;
  30511. }
  30512. var maxDecodeLength = (bytes.length + 1) >> 1;
  30513. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30514. var bufferLength = this.bufferLength;
  30515. var firstDigit = this.firstDigit;
  30516. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30517. var ch = bytes[i], digit;
  30518. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30519. digit = ch & 0x0F;
  30520. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30521. // 'A'-'Z', 'a'-'z'
  30522. digit = (ch & 0x0F) + 9;
  30523. } else if (ch === 0x3E) { // '>'
  30524. this.eof = true;
  30525. break;
  30526. } else { // probably whitespace
  30527. continue; // ignoring
  30528. }
  30529. if (firstDigit < 0) {
  30530. firstDigit = digit;
  30531. } else {
  30532. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30533. firstDigit = -1;
  30534. }
  30535. }
  30536. if (firstDigit >= 0 && this.eof) {
  30537. // incomplete byte
  30538. buffer[bufferLength++] = (firstDigit << 4);
  30539. firstDigit = -1;
  30540. }
  30541. this.firstDigit = firstDigit;
  30542. this.bufferLength = bufferLength;
  30543. };
  30544. return AsciiHexStream;
  30545. })();
  30546. var RunLengthStream = (function RunLengthStreamClosure() {
  30547. function RunLengthStream(str, maybeLength) {
  30548. this.str = str;
  30549. this.dict = str.dict;
  30550. DecodeStream.call(this, maybeLength);
  30551. }
  30552. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30553. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30554. // The repeatHeader has following format. The first byte defines type of run
  30555. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30556. // (in addition to the second byte from the header), n = 129 through 255 -
  30557. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30558. var repeatHeader = this.str.getBytes(2);
  30559. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30560. this.eof = true;
  30561. return;
  30562. }
  30563. var buffer;
  30564. var bufferLength = this.bufferLength;
  30565. var n = repeatHeader[0];
  30566. if (n < 128) {
  30567. // copy n bytes
  30568. buffer = this.ensureBuffer(bufferLength + n + 1);
  30569. buffer[bufferLength++] = repeatHeader[1];
  30570. if (n > 0) {
  30571. var source = this.str.getBytes(n);
  30572. buffer.set(source, bufferLength);
  30573. bufferLength += n;
  30574. }
  30575. } else {
  30576. n = 257 - n;
  30577. var b = repeatHeader[1];
  30578. buffer = this.ensureBuffer(bufferLength + n + 1);
  30579. for (var i = 0; i < n; i++) {
  30580. buffer[bufferLength++] = b;
  30581. }
  30582. }
  30583. this.bufferLength = bufferLength;
  30584. };
  30585. return RunLengthStream;
  30586. })();
  30587. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30588. var ccittEOL = -2;
  30589. var twoDimPass = 0;
  30590. var twoDimHoriz = 1;
  30591. var twoDimVert0 = 2;
  30592. var twoDimVertR1 = 3;
  30593. var twoDimVertL1 = 4;
  30594. var twoDimVertR2 = 5;
  30595. var twoDimVertL2 = 6;
  30596. var twoDimVertR3 = 7;
  30597. var twoDimVertL3 = 8;
  30598. var twoDimTable = [
  30599. [-1, -1], [-1, -1], // 000000x
  30600. [7, twoDimVertL3], // 0000010
  30601. [7, twoDimVertR3], // 0000011
  30602. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30603. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30604. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30605. [4, twoDimPass], [4, twoDimPass],
  30606. [4, twoDimPass], [4, twoDimPass],
  30607. [4, twoDimPass], [4, twoDimPass],
  30608. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30609. [3, twoDimHoriz], [3, twoDimHoriz],
  30610. [3, twoDimHoriz], [3, twoDimHoriz],
  30611. [3, twoDimHoriz], [3, twoDimHoriz],
  30612. [3, twoDimHoriz], [3, twoDimHoriz],
  30613. [3, twoDimHoriz], [3, twoDimHoriz],
  30614. [3, twoDimHoriz], [3, twoDimHoriz],
  30615. [3, twoDimHoriz], [3, twoDimHoriz],
  30616. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30617. [3, twoDimVertL1], [3, twoDimVertL1],
  30618. [3, twoDimVertL1], [3, twoDimVertL1],
  30619. [3, twoDimVertL1], [3, twoDimVertL1],
  30620. [3, twoDimVertL1], [3, twoDimVertL1],
  30621. [3, twoDimVertL1], [3, twoDimVertL1],
  30622. [3, twoDimVertL1], [3, twoDimVertL1],
  30623. [3, twoDimVertL1], [3, twoDimVertL1],
  30624. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30625. [3, twoDimVertR1], [3, twoDimVertR1],
  30626. [3, twoDimVertR1], [3, twoDimVertR1],
  30627. [3, twoDimVertR1], [3, twoDimVertR1],
  30628. [3, twoDimVertR1], [3, twoDimVertR1],
  30629. [3, twoDimVertR1], [3, twoDimVertR1],
  30630. [3, twoDimVertR1], [3, twoDimVertR1],
  30631. [3, twoDimVertR1], [3, twoDimVertR1],
  30632. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30633. [1, twoDimVert0], [1, twoDimVert0],
  30634. [1, twoDimVert0], [1, twoDimVert0],
  30635. [1, twoDimVert0], [1, twoDimVert0],
  30636. [1, twoDimVert0], [1, twoDimVert0],
  30637. [1, twoDimVert0], [1, twoDimVert0],
  30638. [1, twoDimVert0], [1, twoDimVert0],
  30639. [1, twoDimVert0], [1, twoDimVert0],
  30640. [1, twoDimVert0], [1, twoDimVert0],
  30641. [1, twoDimVert0], [1, twoDimVert0],
  30642. [1, twoDimVert0], [1, twoDimVert0],
  30643. [1, twoDimVert0], [1, twoDimVert0],
  30644. [1, twoDimVert0], [1, twoDimVert0],
  30645. [1, twoDimVert0], [1, twoDimVert0],
  30646. [1, twoDimVert0], [1, twoDimVert0],
  30647. [1, twoDimVert0], [1, twoDimVert0],
  30648. [1, twoDimVert0], [1, twoDimVert0],
  30649. [1, twoDimVert0], [1, twoDimVert0],
  30650. [1, twoDimVert0], [1, twoDimVert0],
  30651. [1, twoDimVert0], [1, twoDimVert0],
  30652. [1, twoDimVert0], [1, twoDimVert0],
  30653. [1, twoDimVert0], [1, twoDimVert0],
  30654. [1, twoDimVert0], [1, twoDimVert0],
  30655. [1, twoDimVert0], [1, twoDimVert0],
  30656. [1, twoDimVert0], [1, twoDimVert0],
  30657. [1, twoDimVert0], [1, twoDimVert0],
  30658. [1, twoDimVert0], [1, twoDimVert0],
  30659. [1, twoDimVert0], [1, twoDimVert0],
  30660. [1, twoDimVert0], [1, twoDimVert0],
  30661. [1, twoDimVert0], [1, twoDimVert0],
  30662. [1, twoDimVert0], [1, twoDimVert0],
  30663. [1, twoDimVert0], [1, twoDimVert0]
  30664. ];
  30665. var whiteTable1 = [
  30666. [-1, -1], // 00000
  30667. [12, ccittEOL], // 00001
  30668. [-1, -1], [-1, -1], // 0001x
  30669. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30670. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30671. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30672. [11, 1792], [11, 1792], // 1000x
  30673. [12, 1984], // 10010
  30674. [12, 2048], // 10011
  30675. [12, 2112], // 10100
  30676. [12, 2176], // 10101
  30677. [12, 2240], // 10110
  30678. [12, 2304], // 10111
  30679. [11, 1856], [11, 1856], // 1100x
  30680. [11, 1920], [11, 1920], // 1101x
  30681. [12, 2368], // 11100
  30682. [12, 2432], // 11101
  30683. [12, 2496], // 11110
  30684. [12, 2560] // 11111
  30685. ];
  30686. var whiteTable2 = [
  30687. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30688. [8, 29], [8, 29], // 00000010x
  30689. [8, 30], [8, 30], // 00000011x
  30690. [8, 45], [8, 45], // 00000100x
  30691. [8, 46], [8, 46], // 00000101x
  30692. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30693. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30694. [8, 47], [8, 47], // 00001010x
  30695. [8, 48], [8, 48], // 00001011x
  30696. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30697. [6, 13], [6, 13], [6, 13], [6, 13],
  30698. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30699. [8, 33], [8, 33], // 00010010x
  30700. [8, 34], [8, 34], // 00010011x
  30701. [8, 35], [8, 35], // 00010100x
  30702. [8, 36], [8, 36], // 00010101x
  30703. [8, 37], [8, 37], // 00010110x
  30704. [8, 38], [8, 38], // 00010111x
  30705. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30706. [8, 31], [8, 31], // 00011010x
  30707. [8, 32], [8, 32], // 00011011x
  30708. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30709. [6, 1], [6, 1], [6, 1], [6, 1],
  30710. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30711. [6, 12], [6, 12], [6, 12], [6, 12],
  30712. [8, 53], [8, 53], // 00100100x
  30713. [8, 54], [8, 54], // 00100101x
  30714. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30715. [8, 39], [8, 39], // 00101000x
  30716. [8, 40], [8, 40], // 00101001x
  30717. [8, 41], [8, 41], // 00101010x
  30718. [8, 42], [8, 42], // 00101011x
  30719. [8, 43], [8, 43], // 00101100x
  30720. [8, 44], [8, 44], // 00101101x
  30721. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30722. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30723. [8, 61], [8, 61], // 00110010x
  30724. [8, 62], [8, 62], // 00110011x
  30725. [8, 63], [8, 63], // 00110100x
  30726. [8, 0], [8, 0], // 00110101x
  30727. [8, 320], [8, 320], // 00110110x
  30728. [8, 384], [8, 384], // 00110111x
  30729. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30730. [5, 10], [5, 10], [5, 10], [5, 10],
  30731. [5, 10], [5, 10], [5, 10], [5, 10],
  30732. [5, 10], [5, 10], [5, 10], [5, 10],
  30733. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30734. [5, 11], [5, 11], [5, 11], [5, 11],
  30735. [5, 11], [5, 11], [5, 11], [5, 11],
  30736. [5, 11], [5, 11], [5, 11], [5, 11],
  30737. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30738. [8, 59], [8, 59], // 01001010x
  30739. [8, 60], [8, 60], // 01001011x
  30740. [9, 1472], // 010011000
  30741. [9, 1536], // 010011001
  30742. [9, 1600], // 010011010
  30743. [9, 1728], // 010011011
  30744. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30745. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30746. [8, 49], [8, 49], // 01010010x
  30747. [8, 50], [8, 50], // 01010011x
  30748. [8, 51], [8, 51], // 01010100x
  30749. [8, 52], [8, 52], // 01010101x
  30750. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30751. [8, 55], [8, 55], // 01011000x
  30752. [8, 56], [8, 56], // 01011001x
  30753. [8, 57], [8, 57], // 01011010x
  30754. [8, 58], [8, 58], // 01011011x
  30755. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30756. [6, 192], [6, 192], [6, 192], [6, 192],
  30757. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30758. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30759. [8, 448], [8, 448], // 01100100x
  30760. [8, 512], [8, 512], // 01100101x
  30761. [9, 704], // 011001100
  30762. [9, 768], // 011001101
  30763. [8, 640], [8, 640], // 01100111x
  30764. [8, 576], [8, 576], // 01101000x
  30765. [9, 832], // 011010010
  30766. [9, 896], // 011010011
  30767. [9, 960], // 011010100
  30768. [9, 1024], // 011010101
  30769. [9, 1088], // 011010110
  30770. [9, 1152], // 011010111
  30771. [9, 1216], // 011011000
  30772. [9, 1280], // 011011001
  30773. [9, 1344], // 011011010
  30774. [9, 1408], // 011011011
  30775. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30776. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30777. [4, 2], [4, 2], [4, 2], [4, 2],
  30778. [4, 2], [4, 2], [4, 2], [4, 2],
  30779. [4, 2], [4, 2], [4, 2], [4, 2],
  30780. [4, 2], [4, 2], [4, 2], [4, 2],
  30781. [4, 2], [4, 2], [4, 2], [4, 2],
  30782. [4, 2], [4, 2], [4, 2], [4, 2],
  30783. [4, 2], [4, 2], [4, 2], [4, 2],
  30784. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30785. [4, 3], [4, 3], [4, 3], [4, 3],
  30786. [4, 3], [4, 3], [4, 3], [4, 3],
  30787. [4, 3], [4, 3], [4, 3], [4, 3],
  30788. [4, 3], [4, 3], [4, 3], [4, 3],
  30789. [4, 3], [4, 3], [4, 3], [4, 3],
  30790. [4, 3], [4, 3], [4, 3], [4, 3],
  30791. [4, 3], [4, 3], [4, 3], [4, 3],
  30792. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30793. [5, 128], [5, 128], [5, 128], [5, 128],
  30794. [5, 128], [5, 128], [5, 128], [5, 128],
  30795. [5, 128], [5, 128], [5, 128], [5, 128],
  30796. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30797. [5, 8], [5, 8], [5, 8], [5, 8],
  30798. [5, 8], [5, 8], [5, 8], [5, 8],
  30799. [5, 8], [5, 8], [5, 8], [5, 8],
  30800. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30801. [5, 9], [5, 9], [5, 9], [5, 9],
  30802. [5, 9], [5, 9], [5, 9], [5, 9],
  30803. [5, 9], [5, 9], [5, 9], [5, 9],
  30804. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30805. [6, 16], [6, 16], [6, 16], [6, 16],
  30806. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30807. [6, 17], [6, 17], [6, 17], [6, 17],
  30808. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30809. [4, 4], [4, 4], [4, 4], [4, 4],
  30810. [4, 4], [4, 4], [4, 4], [4, 4],
  30811. [4, 4], [4, 4], [4, 4], [4, 4],
  30812. [4, 4], [4, 4], [4, 4], [4, 4],
  30813. [4, 4], [4, 4], [4, 4], [4, 4],
  30814. [4, 4], [4, 4], [4, 4], [4, 4],
  30815. [4, 4], [4, 4], [4, 4], [4, 4],
  30816. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30817. [4, 5], [4, 5], [4, 5], [4, 5],
  30818. [4, 5], [4, 5], [4, 5], [4, 5],
  30819. [4, 5], [4, 5], [4, 5], [4, 5],
  30820. [4, 5], [4, 5], [4, 5], [4, 5],
  30821. [4, 5], [4, 5], [4, 5], [4, 5],
  30822. [4, 5], [4, 5], [4, 5], [4, 5],
  30823. [4, 5], [4, 5], [4, 5], [4, 5],
  30824. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30825. [6, 14], [6, 14], [6, 14], [6, 14],
  30826. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30827. [6, 15], [6, 15], [6, 15], [6, 15],
  30828. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30829. [5, 64], [5, 64], [5, 64], [5, 64],
  30830. [5, 64], [5, 64], [5, 64], [5, 64],
  30831. [5, 64], [5, 64], [5, 64], [5, 64],
  30832. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30833. [4, 6], [4, 6], [4, 6], [4, 6],
  30834. [4, 6], [4, 6], [4, 6], [4, 6],
  30835. [4, 6], [4, 6], [4, 6], [4, 6],
  30836. [4, 6], [4, 6], [4, 6], [4, 6],
  30837. [4, 6], [4, 6], [4, 6], [4, 6],
  30838. [4, 6], [4, 6], [4, 6], [4, 6],
  30839. [4, 6], [4, 6], [4, 6], [4, 6],
  30840. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30841. [4, 7], [4, 7], [4, 7], [4, 7],
  30842. [4, 7], [4, 7], [4, 7], [4, 7],
  30843. [4, 7], [4, 7], [4, 7], [4, 7],
  30844. [4, 7], [4, 7], [4, 7], [4, 7],
  30845. [4, 7], [4, 7], [4, 7], [4, 7],
  30846. [4, 7], [4, 7], [4, 7], [4, 7],
  30847. [4, 7], [4, 7], [4, 7], [4, 7]
  30848. ];
  30849. var blackTable1 = [
  30850. [-1, -1], [-1, -1], // 000000000000x
  30851. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30852. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30853. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30854. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30855. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30856. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30857. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30858. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30859. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30860. [12, 1984], [12, 1984], // 000000010010x
  30861. [12, 2048], [12, 2048], // 000000010011x
  30862. [12, 2112], [12, 2112], // 000000010100x
  30863. [12, 2176], [12, 2176], // 000000010101x
  30864. [12, 2240], [12, 2240], // 000000010110x
  30865. [12, 2304], [12, 2304], // 000000010111x
  30866. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30867. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30868. [12, 2368], [12, 2368], // 000000011100x
  30869. [12, 2432], [12, 2432], // 000000011101x
  30870. [12, 2496], [12, 2496], // 000000011110x
  30871. [12, 2560], [12, 2560], // 000000011111x
  30872. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30873. [10, 18], [10, 18], [10, 18], [10, 18],
  30874. [12, 52], [12, 52], // 000000100100x
  30875. [13, 640], // 0000001001010
  30876. [13, 704], // 0000001001011
  30877. [13, 768], // 0000001001100
  30878. [13, 832], // 0000001001101
  30879. [12, 55], [12, 55], // 000000100111x
  30880. [12, 56], [12, 56], // 000000101000x
  30881. [13, 1280], // 0000001010010
  30882. [13, 1344], // 0000001010011
  30883. [13, 1408], // 0000001010100
  30884. [13, 1472], // 0000001010101
  30885. [12, 59], [12, 59], // 000000101011x
  30886. [12, 60], [12, 60], // 000000101100x
  30887. [13, 1536], // 0000001011010
  30888. [13, 1600], // 0000001011011
  30889. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30890. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30891. [13, 1664], // 0000001100100
  30892. [13, 1728], // 0000001100101
  30893. [12, 320], [12, 320], // 000000110011x
  30894. [12, 384], [12, 384], // 000000110100x
  30895. [12, 448], [12, 448], // 000000110101x
  30896. [13, 512], // 0000001101100
  30897. [13, 576], // 0000001101101
  30898. [12, 53], [12, 53], // 000000110111x
  30899. [12, 54], [12, 54], // 000000111000x
  30900. [13, 896], // 0000001110010
  30901. [13, 960], // 0000001110011
  30902. [13, 1024], // 0000001110100
  30903. [13, 1088], // 0000001110101
  30904. [13, 1152], // 0000001110110
  30905. [13, 1216], // 0000001110111
  30906. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30907. [10, 64], [10, 64], [10, 64], [10, 64]
  30908. ];
  30909. var blackTable2 = [
  30910. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30911. [8, 13], [8, 13], [8, 13], [8, 13],
  30912. [8, 13], [8, 13], [8, 13], [8, 13],
  30913. [8, 13], [8, 13], [8, 13], [8, 13],
  30914. [11, 23], [11, 23], // 00000101000x
  30915. [12, 50], // 000001010010
  30916. [12, 51], // 000001010011
  30917. [12, 44], // 000001010100
  30918. [12, 45], // 000001010101
  30919. [12, 46], // 000001010110
  30920. [12, 47], // 000001010111
  30921. [12, 57], // 000001011000
  30922. [12, 58], // 000001011001
  30923. [12, 61], // 000001011010
  30924. [12, 256], // 000001011011
  30925. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30926. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30927. [12, 48], // 000001100100
  30928. [12, 49], // 000001100101
  30929. [12, 62], // 000001100110
  30930. [12, 63], // 000001100111
  30931. [12, 30], // 000001101000
  30932. [12, 31], // 000001101001
  30933. [12, 32], // 000001101010
  30934. [12, 33], // 000001101011
  30935. [12, 40], // 000001101100
  30936. [12, 41], // 000001101101
  30937. [11, 22], [11, 22], // 00000110111x
  30938. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30939. [8, 14], [8, 14], [8, 14], [8, 14],
  30940. [8, 14], [8, 14], [8, 14], [8, 14],
  30941. [8, 14], [8, 14], [8, 14], [8, 14],
  30942. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30943. [7, 10], [7, 10], [7, 10], [7, 10],
  30944. [7, 10], [7, 10], [7, 10], [7, 10],
  30945. [7, 10], [7, 10], [7, 10], [7, 10],
  30946. [7, 10], [7, 10], [7, 10], [7, 10],
  30947. [7, 10], [7, 10], [7, 10], [7, 10],
  30948. [7, 10], [7, 10], [7, 10], [7, 10],
  30949. [7, 10], [7, 10], [7, 10], [7, 10],
  30950. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30951. [7, 11], [7, 11], [7, 11], [7, 11],
  30952. [7, 11], [7, 11], [7, 11], [7, 11],
  30953. [7, 11], [7, 11], [7, 11], [7, 11],
  30954. [7, 11], [7, 11], [7, 11], [7, 11],
  30955. [7, 11], [7, 11], [7, 11], [7, 11],
  30956. [7, 11], [7, 11], [7, 11], [7, 11],
  30957. [7, 11], [7, 11], [7, 11], [7, 11],
  30958. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30959. [9, 15], [9, 15], [9, 15], [9, 15],
  30960. [12, 128], // 000011001000
  30961. [12, 192], // 000011001001
  30962. [12, 26], // 000011001010
  30963. [12, 27], // 000011001011
  30964. [12, 28], // 000011001100
  30965. [12, 29], // 000011001101
  30966. [11, 19], [11, 19], // 00001100111x
  30967. [11, 20], [11, 20], // 00001101000x
  30968. [12, 34], // 000011010010
  30969. [12, 35], // 000011010011
  30970. [12, 36], // 000011010100
  30971. [12, 37], // 000011010101
  30972. [12, 38], // 000011010110
  30973. [12, 39], // 000011010111
  30974. [11, 21], [11, 21], // 00001101100x
  30975. [12, 42], // 000011011010
  30976. [12, 43], // 000011011011
  30977. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30978. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30979. [7, 12], [7, 12], [7, 12], [7, 12],
  30980. [7, 12], [7, 12], [7, 12], [7, 12],
  30981. [7, 12], [7, 12], [7, 12], [7, 12],
  30982. [7, 12], [7, 12], [7, 12], [7, 12],
  30983. [7, 12], [7, 12], [7, 12], [7, 12],
  30984. [7, 12], [7, 12], [7, 12], [7, 12],
  30985. [7, 12], [7, 12], [7, 12], [7, 12]
  30986. ];
  30987. var blackTable3 = [
  30988. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30989. [6, 9], // 000100
  30990. [6, 8], // 000101
  30991. [5, 7], [5, 7], // 00011x
  30992. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30993. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30994. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30995. [3, 1], [3, 1], [3, 1], [3, 1],
  30996. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30997. [3, 4], [3, 4], [3, 4], [3, 4],
  30998. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30999. [2, 3], [2, 3], [2, 3], [2, 3],
  31000. [2, 3], [2, 3], [2, 3], [2, 3],
  31001. [2, 3], [2, 3], [2, 3], [2, 3],
  31002. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31003. [2, 2], [2, 2], [2, 2], [2, 2],
  31004. [2, 2], [2, 2], [2, 2], [2, 2],
  31005. [2, 2], [2, 2], [2, 2], [2, 2]
  31006. ];
  31007. function CCITTFaxStream(str, maybeLength, params) {
  31008. this.str = str;
  31009. this.dict = str.dict;
  31010. params = params || Dict.empty;
  31011. this.encoding = params.get('K') || 0;
  31012. this.eoline = params.get('EndOfLine') || false;
  31013. this.byteAlign = params.get('EncodedByteAlign') || false;
  31014. this.columns = params.get('Columns') || 1728;
  31015. this.rows = params.get('Rows') || 0;
  31016. var eoblock = params.get('EndOfBlock');
  31017. if (eoblock === null || eoblock === undefined) {
  31018. eoblock = true;
  31019. }
  31020. this.eoblock = eoblock;
  31021. this.black = params.get('BlackIs1') || false;
  31022. this.codingLine = new Uint32Array(this.columns + 1);
  31023. this.refLine = new Uint32Array(this.columns + 2);
  31024. this.codingLine[0] = this.columns;
  31025. this.codingPos = 0;
  31026. this.row = 0;
  31027. this.nextLine2D = this.encoding < 0;
  31028. this.inputBits = 0;
  31029. this.inputBuf = 0;
  31030. this.outputBits = 0;
  31031. var code1;
  31032. while ((code1 = this.lookBits(12)) === 0) {
  31033. this.eatBits(1);
  31034. }
  31035. if (code1 === 1) {
  31036. this.eatBits(12);
  31037. }
  31038. if (this.encoding > 0) {
  31039. this.nextLine2D = !this.lookBits(1);
  31040. this.eatBits(1);
  31041. }
  31042. DecodeStream.call(this, maybeLength);
  31043. }
  31044. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31045. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31046. while (!this.eof) {
  31047. var c = this.lookChar();
  31048. this.ensureBuffer(this.bufferLength + 1);
  31049. this.buffer[this.bufferLength++] = c;
  31050. }
  31051. };
  31052. CCITTFaxStream.prototype.addPixels =
  31053. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31054. var codingLine = this.codingLine;
  31055. var codingPos = this.codingPos;
  31056. if (a1 > codingLine[codingPos]) {
  31057. if (a1 > this.columns) {
  31058. info('row is wrong length');
  31059. this.err = true;
  31060. a1 = this.columns;
  31061. }
  31062. if ((codingPos & 1) ^ blackPixels) {
  31063. ++codingPos;
  31064. }
  31065. codingLine[codingPos] = a1;
  31066. }
  31067. this.codingPos = codingPos;
  31068. };
  31069. CCITTFaxStream.prototype.addPixelsNeg =
  31070. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31071. var codingLine = this.codingLine;
  31072. var codingPos = this.codingPos;
  31073. if (a1 > codingLine[codingPos]) {
  31074. if (a1 > this.columns) {
  31075. info('row is wrong length');
  31076. this.err = true;
  31077. a1 = this.columns;
  31078. }
  31079. if ((codingPos & 1) ^ blackPixels) {
  31080. ++codingPos;
  31081. }
  31082. codingLine[codingPos] = a1;
  31083. } else if (a1 < codingLine[codingPos]) {
  31084. if (a1 < 0) {
  31085. info('invalid code');
  31086. this.err = true;
  31087. a1 = 0;
  31088. }
  31089. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31090. --codingPos;
  31091. }
  31092. codingLine[codingPos] = a1;
  31093. }
  31094. this.codingPos = codingPos;
  31095. };
  31096. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31097. var refLine = this.refLine;
  31098. var codingLine = this.codingLine;
  31099. var columns = this.columns;
  31100. var refPos, blackPixels, bits, i;
  31101. if (this.outputBits === 0) {
  31102. if (this.eof) {
  31103. return null;
  31104. }
  31105. this.err = false;
  31106. var code1, code2, code3;
  31107. if (this.nextLine2D) {
  31108. for (i = 0; codingLine[i] < columns; ++i) {
  31109. refLine[i] = codingLine[i];
  31110. }
  31111. refLine[i++] = columns;
  31112. refLine[i] = columns;
  31113. codingLine[0] = 0;
  31114. this.codingPos = 0;
  31115. refPos = 0;
  31116. blackPixels = 0;
  31117. while (codingLine[this.codingPos] < columns) {
  31118. code1 = this.getTwoDimCode();
  31119. switch (code1) {
  31120. case twoDimPass:
  31121. this.addPixels(refLine[refPos + 1], blackPixels);
  31122. if (refLine[refPos + 1] < columns) {
  31123. refPos += 2;
  31124. }
  31125. break;
  31126. case twoDimHoriz:
  31127. code1 = code2 = 0;
  31128. if (blackPixels) {
  31129. do {
  31130. code1 += (code3 = this.getBlackCode());
  31131. } while (code3 >= 64);
  31132. do {
  31133. code2 += (code3 = this.getWhiteCode());
  31134. } while (code3 >= 64);
  31135. } else {
  31136. do {
  31137. code1 += (code3 = this.getWhiteCode());
  31138. } while (code3 >= 64);
  31139. do {
  31140. code2 += (code3 = this.getBlackCode());
  31141. } while (code3 >= 64);
  31142. }
  31143. this.addPixels(codingLine[this.codingPos] +
  31144. code1, blackPixels);
  31145. if (codingLine[this.codingPos] < columns) {
  31146. this.addPixels(codingLine[this.codingPos] + code2,
  31147. blackPixels ^ 1);
  31148. }
  31149. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31150. refLine[refPos] < columns) {
  31151. refPos += 2;
  31152. }
  31153. break;
  31154. case twoDimVertR3:
  31155. this.addPixels(refLine[refPos] + 3, blackPixels);
  31156. blackPixels ^= 1;
  31157. if (codingLine[this.codingPos] < columns) {
  31158. ++refPos;
  31159. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31160. refLine[refPos] < columns) {
  31161. refPos += 2;
  31162. }
  31163. }
  31164. break;
  31165. case twoDimVertR2:
  31166. this.addPixels(refLine[refPos] + 2, blackPixels);
  31167. blackPixels ^= 1;
  31168. if (codingLine[this.codingPos] < columns) {
  31169. ++refPos;
  31170. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31171. refLine[refPos] < columns) {
  31172. refPos += 2;
  31173. }
  31174. }
  31175. break;
  31176. case twoDimVertR1:
  31177. this.addPixels(refLine[refPos] + 1, blackPixels);
  31178. blackPixels ^= 1;
  31179. if (codingLine[this.codingPos] < columns) {
  31180. ++refPos;
  31181. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31182. refLine[refPos] < columns) {
  31183. refPos += 2;
  31184. }
  31185. }
  31186. break;
  31187. case twoDimVert0:
  31188. this.addPixels(refLine[refPos], blackPixels);
  31189. blackPixels ^= 1;
  31190. if (codingLine[this.codingPos] < columns) {
  31191. ++refPos;
  31192. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31193. refLine[refPos] < columns) {
  31194. refPos += 2;
  31195. }
  31196. }
  31197. break;
  31198. case twoDimVertL3:
  31199. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31200. blackPixels ^= 1;
  31201. if (codingLine[this.codingPos] < columns) {
  31202. if (refPos > 0) {
  31203. --refPos;
  31204. } else {
  31205. ++refPos;
  31206. }
  31207. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31208. refLine[refPos] < columns) {
  31209. refPos += 2;
  31210. }
  31211. }
  31212. break;
  31213. case twoDimVertL2:
  31214. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31215. blackPixels ^= 1;
  31216. if (codingLine[this.codingPos] < columns) {
  31217. if (refPos > 0) {
  31218. --refPos;
  31219. } else {
  31220. ++refPos;
  31221. }
  31222. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31223. refLine[refPos] < columns) {
  31224. refPos += 2;
  31225. }
  31226. }
  31227. break;
  31228. case twoDimVertL1:
  31229. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31230. blackPixels ^= 1;
  31231. if (codingLine[this.codingPos] < columns) {
  31232. if (refPos > 0) {
  31233. --refPos;
  31234. } else {
  31235. ++refPos;
  31236. }
  31237. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31238. refLine[refPos] < columns) {
  31239. refPos += 2;
  31240. }
  31241. }
  31242. break;
  31243. case EOF:
  31244. this.addPixels(columns, 0);
  31245. this.eof = true;
  31246. break;
  31247. default:
  31248. info('bad 2d code');
  31249. this.addPixels(columns, 0);
  31250. this.err = true;
  31251. }
  31252. }
  31253. } else {
  31254. codingLine[0] = 0;
  31255. this.codingPos = 0;
  31256. blackPixels = 0;
  31257. while (codingLine[this.codingPos] < columns) {
  31258. code1 = 0;
  31259. if (blackPixels) {
  31260. do {
  31261. code1 += (code3 = this.getBlackCode());
  31262. } while (code3 >= 64);
  31263. } else {
  31264. do {
  31265. code1 += (code3 = this.getWhiteCode());
  31266. } while (code3 >= 64);
  31267. }
  31268. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31269. blackPixels ^= 1;
  31270. }
  31271. }
  31272. var gotEOL = false;
  31273. if (this.byteAlign) {
  31274. this.inputBits &= ~7;
  31275. }
  31276. if (!this.eoblock && this.row === this.rows - 1) {
  31277. this.eof = true;
  31278. } else {
  31279. code1 = this.lookBits(12);
  31280. if (this.eoline) {
  31281. while (code1 !== EOF && code1 !== 1) {
  31282. this.eatBits(1);
  31283. code1 = this.lookBits(12);
  31284. }
  31285. } else {
  31286. while (code1 === 0) {
  31287. this.eatBits(1);
  31288. code1 = this.lookBits(12);
  31289. }
  31290. }
  31291. if (code1 === 1) {
  31292. this.eatBits(12);
  31293. gotEOL = true;
  31294. } else if (code1 === EOF) {
  31295. this.eof = true;
  31296. }
  31297. }
  31298. if (!this.eof && this.encoding > 0) {
  31299. this.nextLine2D = !this.lookBits(1);
  31300. this.eatBits(1);
  31301. }
  31302. if (this.eoblock && gotEOL && this.byteAlign) {
  31303. code1 = this.lookBits(12);
  31304. if (code1 === 1) {
  31305. this.eatBits(12);
  31306. if (this.encoding > 0) {
  31307. this.lookBits(1);
  31308. this.eatBits(1);
  31309. }
  31310. if (this.encoding >= 0) {
  31311. for (i = 0; i < 4; ++i) {
  31312. code1 = this.lookBits(12);
  31313. if (code1 !== 1) {
  31314. info('bad rtc code: ' + code1);
  31315. }
  31316. this.eatBits(12);
  31317. if (this.encoding > 0) {
  31318. this.lookBits(1);
  31319. this.eatBits(1);
  31320. }
  31321. }
  31322. }
  31323. this.eof = true;
  31324. }
  31325. } else if (this.err && this.eoline) {
  31326. while (true) {
  31327. code1 = this.lookBits(13);
  31328. if (code1 === EOF) {
  31329. this.eof = true;
  31330. return null;
  31331. }
  31332. if ((code1 >> 1) === 1) {
  31333. break;
  31334. }
  31335. this.eatBits(1);
  31336. }
  31337. this.eatBits(12);
  31338. if (this.encoding > 0) {
  31339. this.eatBits(1);
  31340. this.nextLine2D = !(code1 & 1);
  31341. }
  31342. }
  31343. if (codingLine[0] > 0) {
  31344. this.outputBits = codingLine[this.codingPos = 0];
  31345. } else {
  31346. this.outputBits = codingLine[this.codingPos = 1];
  31347. }
  31348. this.row++;
  31349. }
  31350. var c;
  31351. if (this.outputBits >= 8) {
  31352. c = (this.codingPos & 1) ? 0 : 0xFF;
  31353. this.outputBits -= 8;
  31354. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31355. this.codingPos++;
  31356. this.outputBits = (codingLine[this.codingPos] -
  31357. codingLine[this.codingPos - 1]);
  31358. }
  31359. } else {
  31360. bits = 8;
  31361. c = 0;
  31362. do {
  31363. if (this.outputBits > bits) {
  31364. c <<= bits;
  31365. if (!(this.codingPos & 1)) {
  31366. c |= 0xFF >> (8 - bits);
  31367. }
  31368. this.outputBits -= bits;
  31369. bits = 0;
  31370. } else {
  31371. c <<= this.outputBits;
  31372. if (!(this.codingPos & 1)) {
  31373. c |= 0xFF >> (8 - this.outputBits);
  31374. }
  31375. bits -= this.outputBits;
  31376. this.outputBits = 0;
  31377. if (codingLine[this.codingPos] < columns) {
  31378. this.codingPos++;
  31379. this.outputBits = (codingLine[this.codingPos] -
  31380. codingLine[this.codingPos - 1]);
  31381. } else if (bits > 0) {
  31382. c <<= bits;
  31383. bits = 0;
  31384. }
  31385. }
  31386. } while (bits);
  31387. }
  31388. if (this.black) {
  31389. c ^= 0xFF;
  31390. }
  31391. return c;
  31392. };
  31393. // This functions returns the code found from the table.
  31394. // The start and end parameters set the boundaries for searching the table.
  31395. // The limit parameter is optional. Function returns an array with three
  31396. // values. The first array element indicates whether a valid code is being
  31397. // returned. The second array element is the actual code. The third array
  31398. // element indicates whether EOF was reached.
  31399. CCITTFaxStream.prototype.findTableCode =
  31400. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31401. var limitValue = limit || 0;
  31402. for (var i = start; i <= end; ++i) {
  31403. var code = this.lookBits(i);
  31404. if (code === EOF) {
  31405. return [true, 1, false];
  31406. }
  31407. if (i < end) {
  31408. code <<= end - i;
  31409. }
  31410. if (!limitValue || code >= limitValue) {
  31411. var p = table[code - limitValue];
  31412. if (p[0] === i) {
  31413. this.eatBits(i);
  31414. return [true, p[1], true];
  31415. }
  31416. }
  31417. }
  31418. return [false, 0, false];
  31419. };
  31420. CCITTFaxStream.prototype.getTwoDimCode =
  31421. function ccittFaxStreamGetTwoDimCode() {
  31422. var code = 0;
  31423. var p;
  31424. if (this.eoblock) {
  31425. code = this.lookBits(7);
  31426. p = twoDimTable[code];
  31427. if (p && p[0] > 0) {
  31428. this.eatBits(p[0]);
  31429. return p[1];
  31430. }
  31431. } else {
  31432. var result = this.findTableCode(1, 7, twoDimTable);
  31433. if (result[0] && result[2]) {
  31434. return result[1];
  31435. }
  31436. }
  31437. info('Bad two dim code');
  31438. return EOF;
  31439. };
  31440. CCITTFaxStream.prototype.getWhiteCode =
  31441. function ccittFaxStreamGetWhiteCode() {
  31442. var code = 0;
  31443. var p;
  31444. if (this.eoblock) {
  31445. code = this.lookBits(12);
  31446. if (code === EOF) {
  31447. return 1;
  31448. }
  31449. if ((code >> 5) === 0) {
  31450. p = whiteTable1[code];
  31451. } else {
  31452. p = whiteTable2[code >> 3];
  31453. }
  31454. if (p[0] > 0) {
  31455. this.eatBits(p[0]);
  31456. return p[1];
  31457. }
  31458. } else {
  31459. var result = this.findTableCode(1, 9, whiteTable2);
  31460. if (result[0]) {
  31461. return result[1];
  31462. }
  31463. result = this.findTableCode(11, 12, whiteTable1);
  31464. if (result[0]) {
  31465. return result[1];
  31466. }
  31467. }
  31468. info('bad white code');
  31469. this.eatBits(1);
  31470. return 1;
  31471. };
  31472. CCITTFaxStream.prototype.getBlackCode =
  31473. function ccittFaxStreamGetBlackCode() {
  31474. var code, p;
  31475. if (this.eoblock) {
  31476. code = this.lookBits(13);
  31477. if (code === EOF) {
  31478. return 1;
  31479. }
  31480. if ((code >> 7) === 0) {
  31481. p = blackTable1[code];
  31482. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31483. p = blackTable2[(code >> 1) - 64];
  31484. } else {
  31485. p = blackTable3[code >> 7];
  31486. }
  31487. if (p[0] > 0) {
  31488. this.eatBits(p[0]);
  31489. return p[1];
  31490. }
  31491. } else {
  31492. var result = this.findTableCode(2, 6, blackTable3);
  31493. if (result[0]) {
  31494. return result[1];
  31495. }
  31496. result = this.findTableCode(7, 12, blackTable2, 64);
  31497. if (result[0]) {
  31498. return result[1];
  31499. }
  31500. result = this.findTableCode(10, 13, blackTable1);
  31501. if (result[0]) {
  31502. return result[1];
  31503. }
  31504. }
  31505. info('bad black code');
  31506. this.eatBits(1);
  31507. return 1;
  31508. };
  31509. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31510. var c;
  31511. while (this.inputBits < n) {
  31512. if ((c = this.str.getByte()) === -1) {
  31513. if (this.inputBits === 0) {
  31514. return EOF;
  31515. }
  31516. return ((this.inputBuf << (n - this.inputBits)) &
  31517. (0xFFFF >> (16 - n)));
  31518. }
  31519. this.inputBuf = (this.inputBuf << 8) + c;
  31520. this.inputBits += 8;
  31521. }
  31522. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31523. };
  31524. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31525. if ((this.inputBits -= n) < 0) {
  31526. this.inputBits = 0;
  31527. }
  31528. };
  31529. return CCITTFaxStream;
  31530. })();
  31531. var LZWStream = (function LZWStreamClosure() {
  31532. function LZWStream(str, maybeLength, earlyChange) {
  31533. this.str = str;
  31534. this.dict = str.dict;
  31535. this.cachedData = 0;
  31536. this.bitsCached = 0;
  31537. var maxLzwDictionarySize = 4096;
  31538. var lzwState = {
  31539. earlyChange: earlyChange,
  31540. codeLength: 9,
  31541. nextCode: 258,
  31542. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31543. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31544. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31545. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31546. currentSequenceLength: 0
  31547. };
  31548. for (var i = 0; i < 256; ++i) {
  31549. lzwState.dictionaryValues[i] = i;
  31550. lzwState.dictionaryLengths[i] = 1;
  31551. }
  31552. this.lzwState = lzwState;
  31553. DecodeStream.call(this, maybeLength);
  31554. }
  31555. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31556. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31557. var bitsCached = this.bitsCached;
  31558. var cachedData = this.cachedData;
  31559. while (bitsCached < n) {
  31560. var c = this.str.getByte();
  31561. if (c === -1) {
  31562. this.eof = true;
  31563. return null;
  31564. }
  31565. cachedData = (cachedData << 8) | c;
  31566. bitsCached += 8;
  31567. }
  31568. this.bitsCached = (bitsCached -= n);
  31569. this.cachedData = cachedData;
  31570. this.lastCode = null;
  31571. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31572. };
  31573. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31574. var blockSize = 512;
  31575. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31576. var i, j, q;
  31577. var lzwState = this.lzwState;
  31578. if (!lzwState) {
  31579. return; // eof was found
  31580. }
  31581. var earlyChange = lzwState.earlyChange;
  31582. var nextCode = lzwState.nextCode;
  31583. var dictionaryValues = lzwState.dictionaryValues;
  31584. var dictionaryLengths = lzwState.dictionaryLengths;
  31585. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31586. var codeLength = lzwState.codeLength;
  31587. var prevCode = lzwState.prevCode;
  31588. var currentSequence = lzwState.currentSequence;
  31589. var currentSequenceLength = lzwState.currentSequenceLength;
  31590. var decodedLength = 0;
  31591. var currentBufferLength = this.bufferLength;
  31592. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31593. for (i = 0; i < blockSize; i++) {
  31594. var code = this.readBits(codeLength);
  31595. var hasPrev = currentSequenceLength > 0;
  31596. if (code < 256) {
  31597. currentSequence[0] = code;
  31598. currentSequenceLength = 1;
  31599. } else if (code >= 258) {
  31600. if (code < nextCode) {
  31601. currentSequenceLength = dictionaryLengths[code];
  31602. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31603. currentSequence[j] = dictionaryValues[q];
  31604. q = dictionaryPrevCodes[q];
  31605. }
  31606. } else {
  31607. currentSequence[currentSequenceLength++] = currentSequence[0];
  31608. }
  31609. } else if (code === 256) {
  31610. codeLength = 9;
  31611. nextCode = 258;
  31612. currentSequenceLength = 0;
  31613. continue;
  31614. } else {
  31615. this.eof = true;
  31616. delete this.lzwState;
  31617. break;
  31618. }
  31619. if (hasPrev) {
  31620. dictionaryPrevCodes[nextCode] = prevCode;
  31621. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31622. dictionaryValues[nextCode] = currentSequence[0];
  31623. nextCode++;
  31624. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31625. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31626. 0.6931471805599453 + 1, 12) | 0;
  31627. }
  31628. prevCode = code;
  31629. decodedLength += currentSequenceLength;
  31630. if (estimatedDecodedSize < decodedLength) {
  31631. do {
  31632. estimatedDecodedSize += decodedSizeDelta;
  31633. } while (estimatedDecodedSize < decodedLength);
  31634. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31635. }
  31636. for (j = 0; j < currentSequenceLength; j++) {
  31637. buffer[currentBufferLength++] = currentSequence[j];
  31638. }
  31639. }
  31640. lzwState.nextCode = nextCode;
  31641. lzwState.codeLength = codeLength;
  31642. lzwState.prevCode = prevCode;
  31643. lzwState.currentSequenceLength = currentSequenceLength;
  31644. this.bufferLength = currentBufferLength;
  31645. };
  31646. return LZWStream;
  31647. })();
  31648. var NullStream = (function NullStreamClosure() {
  31649. function NullStream() {
  31650. Stream.call(this, new Uint8Array(0));
  31651. }
  31652. NullStream.prototype = Stream.prototype;
  31653. return NullStream;
  31654. })();
  31655. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31656. setup: function wphSetup(handler) {
  31657. var pdfManager;
  31658. function loadDocument(recoveryMode) {
  31659. var loadDocumentCapability = createPromiseCapability();
  31660. var parseSuccess = function parseSuccess() {
  31661. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31662. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31663. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31664. Promise.all([numPagesPromise, fingerprintPromise,
  31665. encryptedPromise]).then(function onDocReady(results) {
  31666. var doc = {
  31667. numPages: results[0],
  31668. fingerprint: results[1],
  31669. encrypted: !!results[2],
  31670. };
  31671. loadDocumentCapability.resolve(doc);
  31672. },
  31673. parseFailure);
  31674. };
  31675. var parseFailure = function parseFailure(e) {
  31676. loadDocumentCapability.reject(e);
  31677. };
  31678. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31679. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31680. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31681. parseSuccess, parseFailure);
  31682. }, parseFailure);
  31683. }, parseFailure);
  31684. return loadDocumentCapability.promise;
  31685. }
  31686. function getPdfManager(data) {
  31687. var pdfManagerCapability = createPromiseCapability();
  31688. var source = data.source;
  31689. var disableRange = data.disableRange;
  31690. if (source.data) {
  31691. try {
  31692. pdfManager = new LocalPdfManager(source.data, source.password);
  31693. pdfManagerCapability.resolve();
  31694. } catch (ex) {
  31695. pdfManagerCapability.reject(ex);
  31696. }
  31697. return pdfManagerCapability.promise;
  31698. } else if (source.chunkedViewerLoading) {
  31699. try {
  31700. pdfManager = new NetworkPdfManager(source, handler);
  31701. pdfManagerCapability.resolve();
  31702. } catch (ex) {
  31703. pdfManagerCapability.reject(ex);
  31704. }
  31705. return pdfManagerCapability.promise;
  31706. }
  31707. var networkManager = new NetworkManager(source.url, {
  31708. httpHeaders: source.httpHeaders,
  31709. withCredentials: source.withCredentials
  31710. });
  31711. var cachedChunks = [];
  31712. var fullRequestXhrId = networkManager.requestFull({
  31713. onHeadersReceived: function onHeadersReceived() {
  31714. if (disableRange) {
  31715. return;
  31716. }
  31717. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31718. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31719. return;
  31720. }
  31721. var contentEncoding =
  31722. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31723. if (contentEncoding !== 'identity') {
  31724. return;
  31725. }
  31726. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31727. length = parseInt(length, 10);
  31728. if (fullRequestXhr.status === 206) {
  31729. // Since Chrome 39, there exists a bug where cached responses are
  31730. // served with status code 206 for non-range requests.
  31731. // Content-Length does not specify the total size of the resource
  31732. // when the status code is 206 (see RFC 2616, section 14.16).
  31733. // In this case, extract the file size from the Content-Range
  31734. // header, which is defined to be "bytes start-end/length" for
  31735. // byte range requests.
  31736. // See https://github.com/mozilla/pdf.js/issues/5512 and
  31737. // https://code.google.com/p/chromium/issues/detail?id=442318
  31738. length = fullRequestXhr.getResponseHeader('Content-Range');
  31739. length = length && /bytes \d+-\d+\/(\d+)/.exec(length);
  31740. length = length && parseInt(length[1], 10);
  31741. }
  31742. if (!isInt(length)) {
  31743. return;
  31744. }
  31745. source.length = length;
  31746. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31747. // The file size is smaller than the size of two chunks, so it does
  31748. // not make any sense to abort the request and retry with a range
  31749. // request.
  31750. return;
  31751. }
  31752. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31753. // We can continue fetching when progressive loading is enabled,
  31754. // and we don't need the autoFetch feature.
  31755. source.disableAutoFetch = true;
  31756. } else {
  31757. // NOTE: by cancelling the full request, and then issuing range
  31758. // requests, there will be an issue for sites where you can only
  31759. // request the pdf once. However, if this is the case, then the
  31760. // server should not be returning that it can support range
  31761. // requests.
  31762. networkManager.abortRequest(fullRequestXhrId);
  31763. }
  31764. try {
  31765. pdfManager = new NetworkPdfManager(source, handler);
  31766. pdfManagerCapability.resolve(pdfManager);
  31767. } catch (ex) {
  31768. pdfManagerCapability.reject(ex);
  31769. }
  31770. },
  31771. onProgressiveData: source.disableStream ? null :
  31772. function onProgressiveData(chunk) {
  31773. if (!pdfManager) {
  31774. cachedChunks.push(chunk);
  31775. return;
  31776. }
  31777. pdfManager.sendProgressiveData(chunk);
  31778. },
  31779. onDone: function onDone(args) {
  31780. if (pdfManager) {
  31781. return; // already processed
  31782. }
  31783. var pdfFile;
  31784. if (args === null) {
  31785. // TODO add some streaming manager, e.g. for unknown length files.
  31786. // The data was returned in the onProgressiveData, combining...
  31787. var pdfFileLength = 0, pos = 0;
  31788. cachedChunks.forEach(function (chunk) {
  31789. pdfFileLength += chunk.byteLength;
  31790. });
  31791. if (source.length && pdfFileLength !== source.length) {
  31792. warn('reported HTTP length is different from actual');
  31793. }
  31794. var pdfFileArray = new Uint8Array(pdfFileLength);
  31795. cachedChunks.forEach(function (chunk) {
  31796. pdfFileArray.set(new Uint8Array(chunk), pos);
  31797. pos += chunk.byteLength;
  31798. });
  31799. pdfFile = pdfFileArray.buffer;
  31800. } else {
  31801. pdfFile = args.chunk;
  31802. }
  31803. // the data is array, instantiating directly from it
  31804. try {
  31805. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31806. pdfManagerCapability.resolve();
  31807. } catch (ex) {
  31808. pdfManagerCapability.reject(ex);
  31809. }
  31810. },
  31811. onError: function onError(status) {
  31812. var exception;
  31813. if (status === 404) {
  31814. exception = new MissingPDFException('Missing PDF "' +
  31815. source.url + '".');
  31816. handler.send('MissingPDF', exception);
  31817. } else {
  31818. exception = new UnexpectedResponseException(
  31819. 'Unexpected server response (' + status +
  31820. ') while retrieving PDF "' + source.url + '".', status);
  31821. handler.send('UnexpectedResponse', exception);
  31822. }
  31823. },
  31824. onProgress: function onProgress(evt) {
  31825. handler.send('DocProgress', {
  31826. loaded: evt.loaded,
  31827. total: evt.lengthComputable ? evt.total : source.length
  31828. });
  31829. }
  31830. });
  31831. return pdfManagerCapability.promise;
  31832. }
  31833. handler.on('test', function wphSetupTest(data) {
  31834. // check if Uint8Array can be sent to worker
  31835. if (!(data instanceof Uint8Array)) {
  31836. handler.send('test', false);
  31837. return;
  31838. }
  31839. // making sure postMessage transfers are working
  31840. var supportTransfers = data[0] === 255;
  31841. handler.postMessageTransfers = supportTransfers;
  31842. // check if the response property is supported by xhr
  31843. var xhr = new XMLHttpRequest();
  31844. var responseExists = 'response' in xhr;
  31845. // check if the property is actually implemented
  31846. try {
  31847. var dummy = xhr.responseType;
  31848. } catch (e) {
  31849. responseExists = false;
  31850. }
  31851. if (!responseExists) {
  31852. handler.send('test', false);
  31853. return;
  31854. }
  31855. handler.send('test', {
  31856. supportTypedArray: true,
  31857. supportTransfers: supportTransfers
  31858. });
  31859. });
  31860. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31861. var onSuccess = function(doc) {
  31862. handler.send('GetDoc', { pdfInfo: doc });
  31863. };
  31864. var onFailure = function(e) {
  31865. if (e instanceof PasswordException) {
  31866. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31867. handler.send('NeedPassword', e);
  31868. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31869. handler.send('IncorrectPassword', e);
  31870. }
  31871. } else if (e instanceof InvalidPDFException) {
  31872. handler.send('InvalidPDF', e);
  31873. } else if (e instanceof MissingPDFException) {
  31874. handler.send('MissingPDF', e);
  31875. } else if (e instanceof UnexpectedResponseException) {
  31876. handler.send('UnexpectedResponse', e);
  31877. } else {
  31878. handler.send('UnknownError',
  31879. new UnknownErrorException(e.message, e.toString()));
  31880. }
  31881. };
  31882. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31883. -1 : data.maxImageSize;
  31884. PDFJS.disableFontFace = data.disableFontFace;
  31885. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31886. PDFJS.verbosity = data.verbosity;
  31887. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31888. null : data.cMapUrl;
  31889. PDFJS.cMapPacked = data.cMapPacked === true;
  31890. getPdfManager(data).then(function () {
  31891. handler.send('PDFManagerReady', null);
  31892. pdfManager.onLoadedStream().then(function(stream) {
  31893. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31894. });
  31895. }).then(function pdfManagerReady() {
  31896. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31897. // Try again with recoveryMode == true
  31898. if (!(ex instanceof XRefParseException)) {
  31899. if (ex instanceof PasswordException) {
  31900. // after password exception prepare to receive a new password
  31901. // to repeat loading
  31902. pdfManager.passwordChanged().then(pdfManagerReady);
  31903. }
  31904. onFailure(ex);
  31905. return;
  31906. }
  31907. pdfManager.requestLoadedStream();
  31908. pdfManager.onLoadedStream().then(function() {
  31909. loadDocument(true).then(onSuccess, onFailure);
  31910. });
  31911. }, onFailure);
  31912. }, onFailure);
  31913. });
  31914. handler.on('GetPage', function wphSetupGetPage(data) {
  31915. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31916. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31917. var refPromise = pdfManager.ensure(page, 'ref');
  31918. var viewPromise = pdfManager.ensure(page, 'view');
  31919. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31920. function(results) {
  31921. return {
  31922. rotate: results[0],
  31923. ref: results[1],
  31924. view: results[2]
  31925. };
  31926. });
  31927. });
  31928. });
  31929. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31930. var ref = new Ref(data.ref.num, data.ref.gen);
  31931. var catalog = pdfManager.pdfDocument.catalog;
  31932. return catalog.getPageIndex(ref);
  31933. });
  31934. handler.on('GetDestinations',
  31935. function wphSetupGetDestinations(data) {
  31936. return pdfManager.ensureCatalog('destinations');
  31937. }
  31938. );
  31939. handler.on('GetDestination',
  31940. function wphSetupGetDestination(data) {
  31941. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  31942. }
  31943. );
  31944. handler.on('GetAttachments',
  31945. function wphSetupGetAttachments(data) {
  31946. return pdfManager.ensureCatalog('attachments');
  31947. }
  31948. );
  31949. handler.on('GetJavaScript',
  31950. function wphSetupGetJavaScript(data) {
  31951. return pdfManager.ensureCatalog('javaScript');
  31952. }
  31953. );
  31954. handler.on('GetOutline',
  31955. function wphSetupGetOutline(data) {
  31956. return pdfManager.ensureCatalog('documentOutline');
  31957. }
  31958. );
  31959. handler.on('GetMetadata',
  31960. function wphSetupGetMetadata(data) {
  31961. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31962. pdfManager.ensureCatalog('metadata')]);
  31963. }
  31964. );
  31965. handler.on('GetData', function wphSetupGetData(data) {
  31966. pdfManager.requestLoadedStream();
  31967. return pdfManager.onLoadedStream().then(function(stream) {
  31968. return stream.bytes;
  31969. });
  31970. });
  31971. handler.on('GetStats',
  31972. function wphSetupGetStats(data) {
  31973. return pdfManager.pdfDocument.xref.stats;
  31974. }
  31975. );
  31976. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31977. pdfManager.updatePassword(data);
  31978. });
  31979. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31980. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31981. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31982. });
  31983. });
  31984. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31985. pdfManager.getPage(data.pageIndex).then(function(page) {
  31986. var pageNum = data.pageIndex + 1;
  31987. var start = Date.now();
  31988. // Pre compile the pdf page and fetch the fonts/images.
  31989. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31990. info('page=' + pageNum + ' - getOperatorList: time=' +
  31991. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31992. }, function(e) {
  31993. var minimumStackMessage =
  31994. 'worker.js: while trying to getPage() and getOperatorList()';
  31995. var wrappedException;
  31996. // Turn the error into an obj that can be serialized
  31997. if (typeof e === 'string') {
  31998. wrappedException = {
  31999. message: e,
  32000. stack: minimumStackMessage
  32001. };
  32002. } else if (typeof e === 'object') {
  32003. wrappedException = {
  32004. message: e.message || e.toString(),
  32005. stack: e.stack || minimumStackMessage
  32006. };
  32007. } else {
  32008. wrappedException = {
  32009. message: 'Unknown exception type: ' + (typeof e),
  32010. stack: minimumStackMessage
  32011. };
  32012. }
  32013. handler.send('PageError', {
  32014. pageNum: pageNum,
  32015. error: wrappedException,
  32016. intent: data.intent
  32017. });
  32018. });
  32019. });
  32020. }, this);
  32021. handler.on('GetTextContent', function wphExtractText(data) {
  32022. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32023. var pageNum = data.pageIndex + 1;
  32024. var start = Date.now();
  32025. return page.extractTextContent().then(function(textContent) {
  32026. info('text indexing: page=' + pageNum + ' - time=' +
  32027. (Date.now() - start) + 'ms');
  32028. return textContent;
  32029. });
  32030. });
  32031. });
  32032. handler.on('Cleanup', function wphCleanup(data) {
  32033. return pdfManager.cleanup();
  32034. });
  32035. handler.on('Terminate', function wphTerminate(data) {
  32036. pdfManager.terminate();
  32037. });
  32038. }
  32039. };
  32040. var consoleTimer = {};
  32041. var workerConsole = {
  32042. log: function log() {
  32043. var args = Array.prototype.slice.call(arguments);
  32044. globalScope.postMessage({
  32045. action: 'console_log',
  32046. data: args
  32047. });
  32048. },
  32049. error: function error() {
  32050. var args = Array.prototype.slice.call(arguments);
  32051. globalScope.postMessage({
  32052. action: 'console_error',
  32053. data: args
  32054. });
  32055. throw 'pdf.js execution error';
  32056. },
  32057. time: function time(name) {
  32058. consoleTimer[name] = Date.now();
  32059. },
  32060. timeEnd: function timeEnd(name) {
  32061. var time = consoleTimer[name];
  32062. if (!time) {
  32063. error('Unknown timer name ' + name);
  32064. }
  32065. this.log('Timer:', name, Date.now() - time);
  32066. }
  32067. };
  32068. // Worker thread?
  32069. if (typeof window === 'undefined') {
  32070. if (!('console' in globalScope)) {
  32071. globalScope.console = workerConsole;
  32072. }
  32073. // Listen for unsupported features so we can pass them on to the main thread.
  32074. PDFJS.UnsupportedManager.listen(function (msg) {
  32075. globalScope.postMessage({
  32076. action: '_unsupported_feature',
  32077. data: msg
  32078. });
  32079. });
  32080. var handler = new MessageHandler('worker_processor', this);
  32081. WorkerMessageHandler.setup(handler);
  32082. }
  32083. /* This class implements the QM Coder decoding as defined in
  32084. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32085. * Annex C.3 Arithmetic decoding procedure
  32086. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32087. *
  32088. * The arithmetic decoder is used in conjunction with context models to decode
  32089. * JPEG2000 and JBIG2 streams.
  32090. */
  32091. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32092. // Table C-2
  32093. var QeTable = [
  32094. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32095. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32096. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32097. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32098. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32099. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32100. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32101. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32102. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32103. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32104. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32105. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32106. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32107. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32108. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32109. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32110. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32111. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32112. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32113. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32114. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32115. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32116. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32117. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32118. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32119. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32120. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32121. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32122. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32123. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32124. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32125. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32126. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32127. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32128. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32129. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32130. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32131. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32132. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32133. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32134. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32135. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32136. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32137. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32138. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32139. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32140. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32141. ];
  32142. // C.3.5 Initialisation of the decoder (INITDEC)
  32143. function ArithmeticDecoder(data, start, end) {
  32144. this.data = data;
  32145. this.bp = start;
  32146. this.dataEnd = end;
  32147. this.chigh = data[start];
  32148. this.clow = 0;
  32149. this.byteIn();
  32150. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32151. this.clow = (this.clow << 7) & 0xFFFF;
  32152. this.ct -= 7;
  32153. this.a = 0x8000;
  32154. }
  32155. ArithmeticDecoder.prototype = {
  32156. // C.3.4 Compressed data input (BYTEIN)
  32157. byteIn: function ArithmeticDecoder_byteIn() {
  32158. var data = this.data;
  32159. var bp = this.bp;
  32160. if (data[bp] === 0xFF) {
  32161. var b1 = data[bp + 1];
  32162. if (b1 > 0x8F) {
  32163. this.clow += 0xFF00;
  32164. this.ct = 8;
  32165. } else {
  32166. bp++;
  32167. this.clow += (data[bp] << 9);
  32168. this.ct = 7;
  32169. this.bp = bp;
  32170. }
  32171. } else {
  32172. bp++;
  32173. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32174. this.ct = 8;
  32175. this.bp = bp;
  32176. }
  32177. if (this.clow > 0xFFFF) {
  32178. this.chigh += (this.clow >> 16);
  32179. this.clow &= 0xFFFF;
  32180. }
  32181. },
  32182. // C.3.2 Decoding a decision (DECODE)
  32183. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32184. // contexts are packed into 1 byte:
  32185. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32186. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32187. var qeTableIcx = QeTable[cx_index];
  32188. var qeIcx = qeTableIcx.qe;
  32189. var d;
  32190. var a = this.a - qeIcx;
  32191. if (this.chigh < qeIcx) {
  32192. // exchangeLps
  32193. if (a < qeIcx) {
  32194. a = qeIcx;
  32195. d = cx_mps;
  32196. cx_index = qeTableIcx.nmps;
  32197. } else {
  32198. a = qeIcx;
  32199. d = 1 ^ cx_mps;
  32200. if (qeTableIcx.switchFlag === 1) {
  32201. cx_mps = d;
  32202. }
  32203. cx_index = qeTableIcx.nlps;
  32204. }
  32205. } else {
  32206. this.chigh -= qeIcx;
  32207. if ((a & 0x8000) !== 0) {
  32208. this.a = a;
  32209. return cx_mps;
  32210. }
  32211. // exchangeMps
  32212. if (a < qeIcx) {
  32213. d = 1 ^ cx_mps;
  32214. if (qeTableIcx.switchFlag === 1) {
  32215. cx_mps = d;
  32216. }
  32217. cx_index = qeTableIcx.nlps;
  32218. } else {
  32219. d = cx_mps;
  32220. cx_index = qeTableIcx.nmps;
  32221. }
  32222. }
  32223. // C.3.3 renormD;
  32224. do {
  32225. if (this.ct === 0) {
  32226. this.byteIn();
  32227. }
  32228. a <<= 1;
  32229. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32230. this.clow = (this.clow << 1) & 0xFFFF;
  32231. this.ct--;
  32232. } while ((a & 0x8000) === 0);
  32233. this.a = a;
  32234. contexts[pos] = cx_index << 1 | cx_mps;
  32235. return d;
  32236. }
  32237. };
  32238. return ArithmeticDecoder;
  32239. })();
  32240. var JpegImage = (function jpegImage() {
  32241. var dctZigZag = new Uint8Array([
  32242. 0,
  32243. 1, 8,
  32244. 16, 9, 2,
  32245. 3, 10, 17, 24,
  32246. 32, 25, 18, 11, 4,
  32247. 5, 12, 19, 26, 33, 40,
  32248. 48, 41, 34, 27, 20, 13, 6,
  32249. 7, 14, 21, 28, 35, 42, 49, 56,
  32250. 57, 50, 43, 36, 29, 22, 15,
  32251. 23, 30, 37, 44, 51, 58,
  32252. 59, 52, 45, 38, 31,
  32253. 39, 46, 53, 60,
  32254. 61, 54, 47,
  32255. 55, 62,
  32256. 63
  32257. ]);
  32258. var dctCos1 = 4017; // cos(pi/16)
  32259. var dctSin1 = 799; // sin(pi/16)
  32260. var dctCos3 = 3406; // cos(3*pi/16)
  32261. var dctSin3 = 2276; // sin(3*pi/16)
  32262. var dctCos6 = 1567; // cos(6*pi/16)
  32263. var dctSin6 = 3784; // sin(6*pi/16)
  32264. var dctSqrt2 = 5793; // sqrt(2)
  32265. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32266. function constructor() {
  32267. }
  32268. function buildHuffmanTable(codeLengths, values) {
  32269. var k = 0, code = [], i, j, length = 16;
  32270. while (length > 0 && !codeLengths[length - 1]) {
  32271. length--;
  32272. }
  32273. code.push({children: [], index: 0});
  32274. var p = code[0], q;
  32275. for (i = 0; i < length; i++) {
  32276. for (j = 0; j < codeLengths[i]; j++) {
  32277. p = code.pop();
  32278. p.children[p.index] = values[k];
  32279. while (p.index > 0) {
  32280. p = code.pop();
  32281. }
  32282. p.index++;
  32283. code.push(p);
  32284. while (code.length <= i) {
  32285. code.push(q = {children: [], index: 0});
  32286. p.children[p.index] = q.children;
  32287. p = q;
  32288. }
  32289. k++;
  32290. }
  32291. if (i + 1 < length) {
  32292. // p here points to last code
  32293. code.push(q = {children: [], index: 0});
  32294. p.children[p.index] = q.children;
  32295. p = q;
  32296. }
  32297. }
  32298. return code[0].children;
  32299. }
  32300. function getBlockBufferOffset(component, row, col) {
  32301. return 64 * ((component.blocksPerLine + 1) * row + col);
  32302. }
  32303. function decodeScan(data, offset, frame, components, resetInterval,
  32304. spectralStart, spectralEnd, successivePrev, successive) {
  32305. var precision = frame.precision;
  32306. var samplesPerLine = frame.samplesPerLine;
  32307. var scanLines = frame.scanLines;
  32308. var mcusPerLine = frame.mcusPerLine;
  32309. var progressive = frame.progressive;
  32310. var maxH = frame.maxH, maxV = frame.maxV;
  32311. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32312. function readBit() {
  32313. if (bitsCount > 0) {
  32314. bitsCount--;
  32315. return (bitsData >> bitsCount) & 1;
  32316. }
  32317. bitsData = data[offset++];
  32318. if (bitsData === 0xFF) {
  32319. var nextByte = data[offset++];
  32320. if (nextByte) {
  32321. throw 'unexpected marker: ' +
  32322. ((bitsData << 8) | nextByte).toString(16);
  32323. }
  32324. // unstuff 0
  32325. }
  32326. bitsCount = 7;
  32327. return bitsData >>> 7;
  32328. }
  32329. function decodeHuffman(tree) {
  32330. var node = tree;
  32331. while (true) {
  32332. node = node[readBit()];
  32333. if (typeof node === 'number') {
  32334. return node;
  32335. }
  32336. if (typeof node !== 'object') {
  32337. throw 'invalid huffman sequence';
  32338. }
  32339. }
  32340. }
  32341. function receive(length) {
  32342. var n = 0;
  32343. while (length > 0) {
  32344. n = (n << 1) | readBit();
  32345. length--;
  32346. }
  32347. return n;
  32348. }
  32349. function receiveAndExtend(length) {
  32350. if (length === 1) {
  32351. return readBit() === 1 ? 1 : -1;
  32352. }
  32353. var n = receive(length);
  32354. if (n >= 1 << (length - 1)) {
  32355. return n;
  32356. }
  32357. return n + (-1 << length) + 1;
  32358. }
  32359. function decodeBaseline(component, offset) {
  32360. var t = decodeHuffman(component.huffmanTableDC);
  32361. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32362. component.blockData[offset] = (component.pred += diff);
  32363. var k = 1;
  32364. while (k < 64) {
  32365. var rs = decodeHuffman(component.huffmanTableAC);
  32366. var s = rs & 15, r = rs >> 4;
  32367. if (s === 0) {
  32368. if (r < 15) {
  32369. break;
  32370. }
  32371. k += 16;
  32372. continue;
  32373. }
  32374. k += r;
  32375. var z = dctZigZag[k];
  32376. component.blockData[offset + z] = receiveAndExtend(s);
  32377. k++;
  32378. }
  32379. }
  32380. function decodeDCFirst(component, offset) {
  32381. var t = decodeHuffman(component.huffmanTableDC);
  32382. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32383. component.blockData[offset] = (component.pred += diff);
  32384. }
  32385. function decodeDCSuccessive(component, offset) {
  32386. component.blockData[offset] |= readBit() << successive;
  32387. }
  32388. var eobrun = 0;
  32389. function decodeACFirst(component, offset) {
  32390. if (eobrun > 0) {
  32391. eobrun--;
  32392. return;
  32393. }
  32394. var k = spectralStart, e = spectralEnd;
  32395. while (k <= e) {
  32396. var rs = decodeHuffman(component.huffmanTableAC);
  32397. var s = rs & 15, r = rs >> 4;
  32398. if (s === 0) {
  32399. if (r < 15) {
  32400. eobrun = receive(r) + (1 << r) - 1;
  32401. break;
  32402. }
  32403. k += 16;
  32404. continue;
  32405. }
  32406. k += r;
  32407. var z = dctZigZag[k];
  32408. component.blockData[offset + z] =
  32409. receiveAndExtend(s) * (1 << successive);
  32410. k++;
  32411. }
  32412. }
  32413. var successiveACState = 0, successiveACNextValue;
  32414. function decodeACSuccessive(component, offset) {
  32415. var k = spectralStart;
  32416. var e = spectralEnd;
  32417. var r = 0;
  32418. var s;
  32419. var rs;
  32420. while (k <= e) {
  32421. var z = dctZigZag[k];
  32422. switch (successiveACState) {
  32423. case 0: // initial state
  32424. rs = decodeHuffman(component.huffmanTableAC);
  32425. s = rs & 15;
  32426. r = rs >> 4;
  32427. if (s === 0) {
  32428. if (r < 15) {
  32429. eobrun = receive(r) + (1 << r);
  32430. successiveACState = 4;
  32431. } else {
  32432. r = 16;
  32433. successiveACState = 1;
  32434. }
  32435. } else {
  32436. if (s !== 1) {
  32437. throw 'invalid ACn encoding';
  32438. }
  32439. successiveACNextValue = receiveAndExtend(s);
  32440. successiveACState = r ? 2 : 3;
  32441. }
  32442. continue;
  32443. case 1: // skipping r zero items
  32444. case 2:
  32445. if (component.blockData[offset + z]) {
  32446. component.blockData[offset + z] += (readBit() << successive);
  32447. } else {
  32448. r--;
  32449. if (r === 0) {
  32450. successiveACState = successiveACState === 2 ? 3 : 0;
  32451. }
  32452. }
  32453. break;
  32454. case 3: // set value for a zero item
  32455. if (component.blockData[offset + z]) {
  32456. component.blockData[offset + z] += (readBit() << successive);
  32457. } else {
  32458. component.blockData[offset + z] =
  32459. successiveACNextValue << successive;
  32460. successiveACState = 0;
  32461. }
  32462. break;
  32463. case 4: // eob
  32464. if (component.blockData[offset + z]) {
  32465. component.blockData[offset + z] += (readBit() << successive);
  32466. }
  32467. break;
  32468. }
  32469. k++;
  32470. }
  32471. if (successiveACState === 4) {
  32472. eobrun--;
  32473. if (eobrun === 0) {
  32474. successiveACState = 0;
  32475. }
  32476. }
  32477. }
  32478. function decodeMcu(component, decode, mcu, row, col) {
  32479. var mcuRow = (mcu / mcusPerLine) | 0;
  32480. var mcuCol = mcu % mcusPerLine;
  32481. var blockRow = mcuRow * component.v + row;
  32482. var blockCol = mcuCol * component.h + col;
  32483. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32484. decode(component, offset);
  32485. }
  32486. function decodeBlock(component, decode, mcu) {
  32487. var blockRow = (mcu / component.blocksPerLine) | 0;
  32488. var blockCol = mcu % component.blocksPerLine;
  32489. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32490. decode(component, offset);
  32491. }
  32492. var componentsLength = components.length;
  32493. var component, i, j, k, n;
  32494. var decodeFn;
  32495. if (progressive) {
  32496. if (spectralStart === 0) {
  32497. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32498. } else {
  32499. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32500. }
  32501. } else {
  32502. decodeFn = decodeBaseline;
  32503. }
  32504. var mcu = 0, marker;
  32505. var mcuExpected;
  32506. if (componentsLength === 1) {
  32507. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32508. } else {
  32509. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32510. }
  32511. if (!resetInterval) {
  32512. resetInterval = mcuExpected;
  32513. }
  32514. var h, v;
  32515. while (mcu < mcuExpected) {
  32516. // reset interval stuff
  32517. for (i = 0; i < componentsLength; i++) {
  32518. components[i].pred = 0;
  32519. }
  32520. eobrun = 0;
  32521. if (componentsLength === 1) {
  32522. component = components[0];
  32523. for (n = 0; n < resetInterval; n++) {
  32524. decodeBlock(component, decodeFn, mcu);
  32525. mcu++;
  32526. }
  32527. } else {
  32528. for (n = 0; n < resetInterval; n++) {
  32529. for (i = 0; i < componentsLength; i++) {
  32530. component = components[i];
  32531. h = component.h;
  32532. v = component.v;
  32533. for (j = 0; j < v; j++) {
  32534. for (k = 0; k < h; k++) {
  32535. decodeMcu(component, decodeFn, mcu, j, k);
  32536. }
  32537. }
  32538. }
  32539. mcu++;
  32540. }
  32541. }
  32542. // find marker
  32543. bitsCount = 0;
  32544. marker = (data[offset] << 8) | data[offset + 1];
  32545. if (marker <= 0xFF00) {
  32546. throw 'marker was not found';
  32547. }
  32548. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32549. offset += 2;
  32550. } else {
  32551. break;
  32552. }
  32553. }
  32554. return offset - startOffset;
  32555. }
  32556. // A port of poppler's IDCT method which in turn is taken from:
  32557. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32558. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32559. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32560. // 988-991.
  32561. function quantizeAndInverse(component, blockBufferOffset, p) {
  32562. var qt = component.quantizationTable, blockData = component.blockData;
  32563. var v0, v1, v2, v3, v4, v5, v6, v7;
  32564. var p0, p1, p2, p3, p4, p5, p6, p7;
  32565. var t;
  32566. // inverse DCT on rows
  32567. for (var row = 0; row < 64; row += 8) {
  32568. // gather block data
  32569. p0 = blockData[blockBufferOffset + row];
  32570. p1 = blockData[blockBufferOffset + row + 1];
  32571. p2 = blockData[blockBufferOffset + row + 2];
  32572. p3 = blockData[blockBufferOffset + row + 3];
  32573. p4 = blockData[blockBufferOffset + row + 4];
  32574. p5 = blockData[blockBufferOffset + row + 5];
  32575. p6 = blockData[blockBufferOffset + row + 6];
  32576. p7 = blockData[blockBufferOffset + row + 7];
  32577. // dequant p0
  32578. p0 *= qt[row];
  32579. // check for all-zero AC coefficients
  32580. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32581. t = (dctSqrt2 * p0 + 512) >> 10;
  32582. p[row] = t;
  32583. p[row + 1] = t;
  32584. p[row + 2] = t;
  32585. p[row + 3] = t;
  32586. p[row + 4] = t;
  32587. p[row + 5] = t;
  32588. p[row + 6] = t;
  32589. p[row + 7] = t;
  32590. continue;
  32591. }
  32592. // dequant p1 ... p7
  32593. p1 *= qt[row + 1];
  32594. p2 *= qt[row + 2];
  32595. p3 *= qt[row + 3];
  32596. p4 *= qt[row + 4];
  32597. p5 *= qt[row + 5];
  32598. p6 *= qt[row + 6];
  32599. p7 *= qt[row + 7];
  32600. // stage 4
  32601. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32602. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32603. v2 = p2;
  32604. v3 = p6;
  32605. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32606. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32607. v5 = p3 << 4;
  32608. v6 = p5 << 4;
  32609. // stage 3
  32610. v0 = (v0 + v1 + 1) >> 1;
  32611. v1 = v0 - v1;
  32612. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32613. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32614. v3 = t;
  32615. v4 = (v4 + v6 + 1) >> 1;
  32616. v6 = v4 - v6;
  32617. v7 = (v7 + v5 + 1) >> 1;
  32618. v5 = v7 - v5;
  32619. // stage 2
  32620. v0 = (v0 + v3 + 1) >> 1;
  32621. v3 = v0 - v3;
  32622. v1 = (v1 + v2 + 1) >> 1;
  32623. v2 = v1 - v2;
  32624. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32625. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32626. v7 = t;
  32627. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32628. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32629. v6 = t;
  32630. // stage 1
  32631. p[row] = v0 + v7;
  32632. p[row + 7] = v0 - v7;
  32633. p[row + 1] = v1 + v6;
  32634. p[row + 6] = v1 - v6;
  32635. p[row + 2] = v2 + v5;
  32636. p[row + 5] = v2 - v5;
  32637. p[row + 3] = v3 + v4;
  32638. p[row + 4] = v3 - v4;
  32639. }
  32640. // inverse DCT on columns
  32641. for (var col = 0; col < 8; ++col) {
  32642. p0 = p[col];
  32643. p1 = p[col + 8];
  32644. p2 = p[col + 16];
  32645. p3 = p[col + 24];
  32646. p4 = p[col + 32];
  32647. p5 = p[col + 40];
  32648. p6 = p[col + 48];
  32649. p7 = p[col + 56];
  32650. // check for all-zero AC coefficients
  32651. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32652. t = (dctSqrt2 * p0 + 8192) >> 14;
  32653. // convert to 8 bit
  32654. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32655. blockData[blockBufferOffset + col] = t;
  32656. blockData[blockBufferOffset + col + 8] = t;
  32657. blockData[blockBufferOffset + col + 16] = t;
  32658. blockData[blockBufferOffset + col + 24] = t;
  32659. blockData[blockBufferOffset + col + 32] = t;
  32660. blockData[blockBufferOffset + col + 40] = t;
  32661. blockData[blockBufferOffset + col + 48] = t;
  32662. blockData[blockBufferOffset + col + 56] = t;
  32663. continue;
  32664. }
  32665. // stage 4
  32666. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32667. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32668. v2 = p2;
  32669. v3 = p6;
  32670. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32671. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32672. v5 = p3;
  32673. v6 = p5;
  32674. // stage 3
  32675. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32676. // converting to UInt8 range later.
  32677. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32678. v1 = v0 - v1;
  32679. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32680. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32681. v3 = t;
  32682. v4 = (v4 + v6 + 1) >> 1;
  32683. v6 = v4 - v6;
  32684. v7 = (v7 + v5 + 1) >> 1;
  32685. v5 = v7 - v5;
  32686. // stage 2
  32687. v0 = (v0 + v3 + 1) >> 1;
  32688. v3 = v0 - v3;
  32689. v1 = (v1 + v2 + 1) >> 1;
  32690. v2 = v1 - v2;
  32691. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32692. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32693. v7 = t;
  32694. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32695. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32696. v6 = t;
  32697. // stage 1
  32698. p0 = v0 + v7;
  32699. p7 = v0 - v7;
  32700. p1 = v1 + v6;
  32701. p6 = v1 - v6;
  32702. p2 = v2 + v5;
  32703. p5 = v2 - v5;
  32704. p3 = v3 + v4;
  32705. p4 = v3 - v4;
  32706. // convert to 8-bit integers
  32707. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32708. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32709. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32710. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32711. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32712. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32713. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32714. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32715. // store block data
  32716. blockData[blockBufferOffset + col] = p0;
  32717. blockData[blockBufferOffset + col + 8] = p1;
  32718. blockData[blockBufferOffset + col + 16] = p2;
  32719. blockData[blockBufferOffset + col + 24] = p3;
  32720. blockData[blockBufferOffset + col + 32] = p4;
  32721. blockData[blockBufferOffset + col + 40] = p5;
  32722. blockData[blockBufferOffset + col + 48] = p6;
  32723. blockData[blockBufferOffset + col + 56] = p7;
  32724. }
  32725. }
  32726. function buildComponentData(frame, component) {
  32727. var blocksPerLine = component.blocksPerLine;
  32728. var blocksPerColumn = component.blocksPerColumn;
  32729. var computationBuffer = new Int16Array(64);
  32730. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32731. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32732. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32733. quantizeAndInverse(component, offset, computationBuffer);
  32734. }
  32735. }
  32736. return component.blockData;
  32737. }
  32738. function clamp0to255(a) {
  32739. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32740. }
  32741. constructor.prototype = {
  32742. parse: function parse(data) {
  32743. function readUint16() {
  32744. var value = (data[offset] << 8) | data[offset + 1];
  32745. offset += 2;
  32746. return value;
  32747. }
  32748. function readDataBlock() {
  32749. var length = readUint16();
  32750. var array = data.subarray(offset, offset + length - 2);
  32751. offset += array.length;
  32752. return array;
  32753. }
  32754. function prepareComponents(frame) {
  32755. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32756. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32757. for (var i = 0; i < frame.components.length; i++) {
  32758. component = frame.components[i];
  32759. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32760. component.h / frame.maxH);
  32761. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32762. component.v / frame.maxV);
  32763. var blocksPerLineForMcu = mcusPerLine * component.h;
  32764. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32765. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32766. (blocksPerLineForMcu + 1);
  32767. component.blockData = new Int16Array(blocksBufferSize);
  32768. component.blocksPerLine = blocksPerLine;
  32769. component.blocksPerColumn = blocksPerColumn;
  32770. }
  32771. frame.mcusPerLine = mcusPerLine;
  32772. frame.mcusPerColumn = mcusPerColumn;
  32773. }
  32774. var offset = 0, length = data.length;
  32775. var jfif = null;
  32776. var adobe = null;
  32777. var pixels = null;
  32778. var frame, resetInterval;
  32779. var quantizationTables = [];
  32780. var huffmanTablesAC = [], huffmanTablesDC = [];
  32781. var fileMarker = readUint16();
  32782. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32783. throw 'SOI not found';
  32784. }
  32785. fileMarker = readUint16();
  32786. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32787. var i, j, l;
  32788. switch(fileMarker) {
  32789. case 0xFFE0: // APP0 (Application Specific)
  32790. case 0xFFE1: // APP1
  32791. case 0xFFE2: // APP2
  32792. case 0xFFE3: // APP3
  32793. case 0xFFE4: // APP4
  32794. case 0xFFE5: // APP5
  32795. case 0xFFE6: // APP6
  32796. case 0xFFE7: // APP7
  32797. case 0xFFE8: // APP8
  32798. case 0xFFE9: // APP9
  32799. case 0xFFEA: // APP10
  32800. case 0xFFEB: // APP11
  32801. case 0xFFEC: // APP12
  32802. case 0xFFED: // APP13
  32803. case 0xFFEE: // APP14
  32804. case 0xFFEF: // APP15
  32805. case 0xFFFE: // COM (Comment)
  32806. var appData = readDataBlock();
  32807. if (fileMarker === 0xFFE0) {
  32808. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32809. appData[2] === 0x49 && appData[3] === 0x46 &&
  32810. appData[4] === 0) { // 'JFIF\x00'
  32811. jfif = {
  32812. version: { major: appData[5], minor: appData[6] },
  32813. densityUnits: appData[7],
  32814. xDensity: (appData[8] << 8) | appData[9],
  32815. yDensity: (appData[10] << 8) | appData[11],
  32816. thumbWidth: appData[12],
  32817. thumbHeight: appData[13],
  32818. thumbData: appData.subarray(14, 14 +
  32819. 3 * appData[12] * appData[13])
  32820. };
  32821. }
  32822. }
  32823. // TODO APP1 - Exif
  32824. if (fileMarker === 0xFFEE) {
  32825. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32826. appData[2] === 0x6F && appData[3] === 0x62 &&
  32827. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32828. adobe = {
  32829. version: appData[6],
  32830. flags0: (appData[7] << 8) | appData[8],
  32831. flags1: (appData[9] << 8) | appData[10],
  32832. transformCode: appData[11]
  32833. };
  32834. }
  32835. }
  32836. break;
  32837. case 0xFFDB: // DQT (Define Quantization Tables)
  32838. var quantizationTablesLength = readUint16();
  32839. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32840. var z;
  32841. while (offset < quantizationTablesEnd) {
  32842. var quantizationTableSpec = data[offset++];
  32843. var tableData = new Uint16Array(64);
  32844. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32845. for (j = 0; j < 64; j++) {
  32846. z = dctZigZag[j];
  32847. tableData[z] = data[offset++];
  32848. }
  32849. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32850. for (j = 0; j < 64; j++) {
  32851. z = dctZigZag[j];
  32852. tableData[z] = readUint16();
  32853. }
  32854. } else {
  32855. throw 'DQT: invalid table spec';
  32856. }
  32857. quantizationTables[quantizationTableSpec & 15] = tableData;
  32858. }
  32859. break;
  32860. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32861. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32862. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32863. if (frame) {
  32864. throw 'Only single frame JPEGs supported';
  32865. }
  32866. readUint16(); // skip data length
  32867. frame = {};
  32868. frame.extended = (fileMarker === 0xFFC1);
  32869. frame.progressive = (fileMarker === 0xFFC2);
  32870. frame.precision = data[offset++];
  32871. frame.scanLines = readUint16();
  32872. frame.samplesPerLine = readUint16();
  32873. frame.components = [];
  32874. frame.componentIds = {};
  32875. var componentsCount = data[offset++], componentId;
  32876. var maxH = 0, maxV = 0;
  32877. for (i = 0; i < componentsCount; i++) {
  32878. componentId = data[offset];
  32879. var h = data[offset + 1] >> 4;
  32880. var v = data[offset + 1] & 15;
  32881. if (maxH < h) {
  32882. maxH = h;
  32883. }
  32884. if (maxV < v) {
  32885. maxV = v;
  32886. }
  32887. var qId = data[offset + 2];
  32888. l = frame.components.push({
  32889. h: h,
  32890. v: v,
  32891. quantizationTable: quantizationTables[qId]
  32892. });
  32893. frame.componentIds[componentId] = l - 1;
  32894. offset += 3;
  32895. }
  32896. frame.maxH = maxH;
  32897. frame.maxV = maxV;
  32898. prepareComponents(frame);
  32899. break;
  32900. case 0xFFC4: // DHT (Define Huffman Tables)
  32901. var huffmanLength = readUint16();
  32902. for (i = 2; i < huffmanLength;) {
  32903. var huffmanTableSpec = data[offset++];
  32904. var codeLengths = new Uint8Array(16);
  32905. var codeLengthSum = 0;
  32906. for (j = 0; j < 16; j++, offset++) {
  32907. codeLengthSum += (codeLengths[j] = data[offset]);
  32908. }
  32909. var huffmanValues = new Uint8Array(codeLengthSum);
  32910. for (j = 0; j < codeLengthSum; j++, offset++) {
  32911. huffmanValues[j] = data[offset];
  32912. }
  32913. i += 17 + codeLengthSum;
  32914. ((huffmanTableSpec >> 4) === 0 ?
  32915. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32916. buildHuffmanTable(codeLengths, huffmanValues);
  32917. }
  32918. break;
  32919. case 0xFFDD: // DRI (Define Restart Interval)
  32920. readUint16(); // skip data length
  32921. resetInterval = readUint16();
  32922. break;
  32923. case 0xFFDA: // SOS (Start of Scan)
  32924. var scanLength = readUint16();
  32925. var selectorsCount = data[offset++];
  32926. var components = [], component;
  32927. for (i = 0; i < selectorsCount; i++) {
  32928. var componentIndex = frame.componentIds[data[offset++]];
  32929. component = frame.components[componentIndex];
  32930. var tableSpec = data[offset++];
  32931. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32932. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32933. components.push(component);
  32934. }
  32935. var spectralStart = data[offset++];
  32936. var spectralEnd = data[offset++];
  32937. var successiveApproximation = data[offset++];
  32938. var processed = decodeScan(data, offset,
  32939. frame, components, resetInterval,
  32940. spectralStart, spectralEnd,
  32941. successiveApproximation >> 4, successiveApproximation & 15);
  32942. offset += processed;
  32943. break;
  32944. default:
  32945. if (data[offset - 3] === 0xFF &&
  32946. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32947. // could be incorrect encoding -- last 0xFF byte of the previous
  32948. // block was eaten by the encoder
  32949. offset -= 3;
  32950. break;
  32951. }
  32952. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32953. }
  32954. fileMarker = readUint16();
  32955. }
  32956. this.width = frame.samplesPerLine;
  32957. this.height = frame.scanLines;
  32958. this.jfif = jfif;
  32959. this.adobe = adobe;
  32960. this.components = [];
  32961. for (i = 0; i < frame.components.length; i++) {
  32962. component = frame.components[i];
  32963. this.components.push({
  32964. output: buildComponentData(frame, component),
  32965. scaleX: component.h / frame.maxH,
  32966. scaleY: component.v / frame.maxV,
  32967. blocksPerLine: component.blocksPerLine,
  32968. blocksPerColumn: component.blocksPerColumn
  32969. });
  32970. }
  32971. this.numComponents = this.components.length;
  32972. },
  32973. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32974. var scaleX = this.width / width, scaleY = this.height / height;
  32975. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32976. var x, y, i, j, k;
  32977. var index;
  32978. var offset = 0;
  32979. var output;
  32980. var numComponents = this.components.length;
  32981. var dataLength = width * height * numComponents;
  32982. var data = new Uint8Array(dataLength);
  32983. var xScaleBlockOffset = new Uint32Array(width);
  32984. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32985. for (i = 0; i < numComponents; i++) {
  32986. component = this.components[i];
  32987. componentScaleX = component.scaleX * scaleX;
  32988. componentScaleY = component.scaleY * scaleY;
  32989. offset = i;
  32990. output = component.output;
  32991. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32992. // precalculate the xScaleBlockOffset
  32993. for (x = 0; x < width; x++) {
  32994. j = 0 | (x * componentScaleX);
  32995. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32996. }
  32997. // linearize the blocks of the component
  32998. for (y = 0; y < height; y++) {
  32999. j = 0 | (y * componentScaleY);
  33000. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33001. for (x = 0; x < width; x++) {
  33002. data[offset] = output[index + xScaleBlockOffset[x]];
  33003. offset += numComponents;
  33004. }
  33005. }
  33006. }
  33007. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33008. var transform = this.decodeTransform;
  33009. if (transform) {
  33010. for (i = 0; i < dataLength;) {
  33011. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33012. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33013. }
  33014. }
  33015. }
  33016. return data;
  33017. },
  33018. _isColorConversionNeeded: function isColorConversionNeeded() {
  33019. if (this.adobe && this.adobe.transformCode) {
  33020. // The adobe transform marker overrides any previous setting
  33021. return true;
  33022. } else if (this.numComponents === 3) {
  33023. return true;
  33024. } else {
  33025. return false;
  33026. }
  33027. },
  33028. _convertYccToRgb: function convertYccToRgb(data) {
  33029. var Y, Cb, Cr;
  33030. for (var i = 0, length = data.length; i < length; i += 3) {
  33031. Y = data[i ];
  33032. Cb = data[i + 1];
  33033. Cr = data[i + 2];
  33034. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33035. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33036. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33037. }
  33038. return data;
  33039. },
  33040. _convertYcckToRgb: function convertYcckToRgb(data) {
  33041. var Y, Cb, Cr, k;
  33042. var offset = 0;
  33043. for (var i = 0, length = data.length; i < length; i += 4) {
  33044. Y = data[i];
  33045. Cb = data[i + 1];
  33046. Cr = data[i + 2];
  33047. k = data[i + 3];
  33048. var r = -122.67195406894 +
  33049. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33050. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33051. 0.154362151871126) +
  33052. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33053. 0.00477271405408747 * k + 1.53380253221734) +
  33054. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33055. 0.48357088451265) +
  33056. k * (-0.000336197177618394 * k + 0.484791561490776);
  33057. var g = 107.268039397724 +
  33058. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33059. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33060. 0.176491792462875) +
  33061. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33062. 0.000770482631801132 * k - 0.151051492775562) +
  33063. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33064. 0.25802910206845) +
  33065. k * (-0.000318913117588328 * k - 0.213742400323665);
  33066. var b = -20.810012546947 +
  33067. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33068. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33069. 0.814272968359295) +
  33070. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33071. 0.000560833691242812 * k - 0.195152027534049) +
  33072. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33073. 0.116935020465145) +
  33074. k * (-0.000343531996510555 * k + 0.24165260232407);
  33075. data[offset++] = clamp0to255(r);
  33076. data[offset++] = clamp0to255(g);
  33077. data[offset++] = clamp0to255(b);
  33078. }
  33079. return data;
  33080. },
  33081. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33082. var Y, Cb, Cr;
  33083. for (var i = 0, length = data.length; i < length; i += 4) {
  33084. Y = data[i];
  33085. Cb = data[i + 1];
  33086. Cr = data[i + 2];
  33087. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33088. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33089. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33090. // K in data[i + 3] is unchanged
  33091. }
  33092. return data;
  33093. },
  33094. _convertCmykToRgb: function convertCmykToRgb(data) {
  33095. var c, m, y, k;
  33096. var offset = 0;
  33097. var min = -255 * 255 * 255;
  33098. var scale = 1 / 255 / 255;
  33099. for (var i = 0, length = data.length; i < length; i += 4) {
  33100. c = data[i];
  33101. m = data[i + 1];
  33102. y = data[i + 2];
  33103. k = data[i + 3];
  33104. var r =
  33105. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33106. 18.82290502165302 * y + 212.25662451639585 * k -
  33107. 72734.4411664936) +
  33108. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33109. 17.873870861415444 * k - 1401.7366389350734) +
  33110. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33111. 4465.541406466231) -
  33112. k * (21.86122147463605 * k + 48317.86113160301);
  33113. var g =
  33114. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33115. 6.871425592049007 * y + 31.159100130055922 * k -
  33116. 20220.756542821975) +
  33117. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33118. 131.35250912493976 * k - 48691.05921601825) +
  33119. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33120. 6341.191035517494) -
  33121. k * (20.737325471181034 * k + 47890.15695978492);
  33122. var b =
  33123. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33124. 30.89978309703729 * y - 0.23883238689178934 * k -
  33125. 3616.812083916688) +
  33126. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33127. 50.606957656360734 * k - 28620.90484698408) +
  33128. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33129. 49363.43385999684) -
  33130. k * (22.33816807309886 * k + 45932.16563550634);
  33131. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33132. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33133. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33134. }
  33135. return data;
  33136. },
  33137. getData: function getData(width, height, forceRGBoutput) {
  33138. if (this.numComponents > 4) {
  33139. throw 'Unsupported color mode';
  33140. }
  33141. // type of data: Uint8Array(width * height * numComponents)
  33142. var data = this._getLinearizedBlockData(width, height);
  33143. if (this.numComponents === 3) {
  33144. return this._convertYccToRgb(data);
  33145. } else if (this.numComponents === 4) {
  33146. if (this._isColorConversionNeeded()) {
  33147. if (forceRGBoutput) {
  33148. return this._convertYcckToRgb(data);
  33149. } else {
  33150. return this._convertYcckToCmyk(data);
  33151. }
  33152. } else if (forceRGBoutput) {
  33153. return this._convertCmykToRgb(data);
  33154. }
  33155. }
  33156. return data;
  33157. }
  33158. };
  33159. return constructor;
  33160. })();
  33161. var JpxImage = (function JpxImageClosure() {
  33162. // Table E.1
  33163. var SubbandsGainLog2 = {
  33164. 'LL': 0,
  33165. 'LH': 1,
  33166. 'HL': 1,
  33167. 'HH': 2
  33168. };
  33169. function JpxImage() {
  33170. this.failOnCorruptedImage = false;
  33171. }
  33172. JpxImage.prototype = {
  33173. parse: function JpxImage_parse(data) {
  33174. var head = readUint16(data, 0);
  33175. // No box header, immediate start of codestream (SOC)
  33176. if (head === 0xFF4F) {
  33177. this.parseCodestream(data, 0, data.length);
  33178. return;
  33179. }
  33180. var position = 0, length = data.length;
  33181. while (position < length) {
  33182. var headerSize = 8;
  33183. var lbox = readUint32(data, position);
  33184. var tbox = readUint32(data, position + 4);
  33185. position += headerSize;
  33186. if (lbox === 1) {
  33187. // XLBox: read UInt64 according to spec.
  33188. // JavaScript's int precision of 53 bit should be sufficient here.
  33189. lbox = readUint32(data, position) * 4294967296 +
  33190. readUint32(data, position + 4);
  33191. position += 8;
  33192. headerSize += 8;
  33193. }
  33194. if (lbox === 0) {
  33195. lbox = length - position + headerSize;
  33196. }
  33197. if (lbox < headerSize) {
  33198. throw new Error('JPX Error: Invalid box field size');
  33199. }
  33200. var dataLength = lbox - headerSize;
  33201. var jumpDataLength = true;
  33202. switch (tbox) {
  33203. case 0x6A703268: // 'jp2h'
  33204. jumpDataLength = false; // parsing child boxes
  33205. break;
  33206. case 0x636F6C72: // 'colr'
  33207. // Colorspaces are not used, the CS from the PDF is used.
  33208. var method = data[position];
  33209. var precedence = data[position + 1];
  33210. var approximation = data[position + 2];
  33211. if (method === 1) {
  33212. // enumerated colorspace
  33213. var colorspace = readUint32(data, position + 3);
  33214. switch (colorspace) {
  33215. case 16: // this indicates a sRGB colorspace
  33216. case 17: // this indicates a grayscale colorspace
  33217. case 18: // this indicates a YUV colorspace
  33218. break;
  33219. default:
  33220. warn('Unknown colorspace ' + colorspace);
  33221. break;
  33222. }
  33223. } else if (method === 2) {
  33224. info('ICC profile not supported');
  33225. }
  33226. break;
  33227. case 0x6A703263: // 'jp2c'
  33228. this.parseCodestream(data, position, position + dataLength);
  33229. break;
  33230. case 0x6A502020: // 'jP\024\024'
  33231. if (0x0d0a870a !== readUint32(data, position)) {
  33232. warn('Invalid JP2 signature');
  33233. }
  33234. break;
  33235. // The following header types are valid but currently not used:
  33236. case 0x6A501A1A: // 'jP\032\032'
  33237. case 0x66747970: // 'ftyp'
  33238. case 0x72726571: // 'rreq'
  33239. case 0x72657320: // 'res '
  33240. case 0x69686472: // 'ihdr'
  33241. break;
  33242. default:
  33243. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33244. (tbox >> 16) & 0xFF,
  33245. (tbox >> 8) & 0xFF,
  33246. tbox & 0xFF);
  33247. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33248. break;
  33249. }
  33250. if (jumpDataLength) {
  33251. position += dataLength;
  33252. }
  33253. }
  33254. },
  33255. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33256. var newByte = stream.getByte();
  33257. while (newByte >= 0) {
  33258. var oldByte = newByte;
  33259. newByte = stream.getByte();
  33260. var code = (oldByte << 8) | newByte;
  33261. // Image and tile size (SIZ)
  33262. if (code === 0xFF51) {
  33263. stream.skip(4);
  33264. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33265. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33266. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33267. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33268. stream.skip(16);
  33269. var Csiz = stream.getUint16(); // Byte 36
  33270. this.width = Xsiz - XOsiz;
  33271. this.height = Ysiz - YOsiz;
  33272. this.componentsCount = Csiz;
  33273. // Results are always returned as Uint8Arrays
  33274. this.bitsPerComponent = 8;
  33275. return;
  33276. }
  33277. }
  33278. throw new Error('JPX Error: No size marker found in JPX stream');
  33279. },
  33280. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33281. var context = {};
  33282. try {
  33283. var doNotRecover = false;
  33284. var position = start;
  33285. while (position + 1 < end) {
  33286. var code = readUint16(data, position);
  33287. position += 2;
  33288. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33289. switch (code) {
  33290. case 0xFF4F: // Start of codestream (SOC)
  33291. context.mainHeader = true;
  33292. break;
  33293. case 0xFFD9: // End of codestream (EOC)
  33294. break;
  33295. case 0xFF51: // Image and tile size (SIZ)
  33296. length = readUint16(data, position);
  33297. var siz = {};
  33298. siz.Xsiz = readUint32(data, position + 4);
  33299. siz.Ysiz = readUint32(data, position + 8);
  33300. siz.XOsiz = readUint32(data, position + 12);
  33301. siz.YOsiz = readUint32(data, position + 16);
  33302. siz.XTsiz = readUint32(data, position + 20);
  33303. siz.YTsiz = readUint32(data, position + 24);
  33304. siz.XTOsiz = readUint32(data, position + 28);
  33305. siz.YTOsiz = readUint32(data, position + 32);
  33306. var componentsCount = readUint16(data, position + 36);
  33307. siz.Csiz = componentsCount;
  33308. var components = [];
  33309. j = position + 38;
  33310. for (var i = 0; i < componentsCount; i++) {
  33311. var component = {
  33312. precision: (data[j] & 0x7F) + 1,
  33313. isSigned: !!(data[j] & 0x80),
  33314. XRsiz: data[j + 1],
  33315. YRsiz: data[j + 1]
  33316. };
  33317. calculateComponentDimensions(component, siz);
  33318. components.push(component);
  33319. }
  33320. context.SIZ = siz;
  33321. context.components = components;
  33322. calculateTileGrids(context, components);
  33323. context.QCC = [];
  33324. context.COC = [];
  33325. break;
  33326. case 0xFF5C: // Quantization default (QCD)
  33327. length = readUint16(data, position);
  33328. var qcd = {};
  33329. j = position + 2;
  33330. sqcd = data[j++];
  33331. switch (sqcd & 0x1F) {
  33332. case 0:
  33333. spqcdSize = 8;
  33334. scalarExpounded = true;
  33335. break;
  33336. case 1:
  33337. spqcdSize = 16;
  33338. scalarExpounded = false;
  33339. break;
  33340. case 2:
  33341. spqcdSize = 16;
  33342. scalarExpounded = true;
  33343. break;
  33344. default:
  33345. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33346. }
  33347. qcd.noQuantization = (spqcdSize === 8);
  33348. qcd.scalarExpounded = scalarExpounded;
  33349. qcd.guardBits = sqcd >> 5;
  33350. spqcds = [];
  33351. while (j < length + position) {
  33352. var spqcd = {};
  33353. if (spqcdSize === 8) {
  33354. spqcd.epsilon = data[j++] >> 3;
  33355. spqcd.mu = 0;
  33356. } else {
  33357. spqcd.epsilon = data[j] >> 3;
  33358. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33359. j += 2;
  33360. }
  33361. spqcds.push(spqcd);
  33362. }
  33363. qcd.SPqcds = spqcds;
  33364. if (context.mainHeader) {
  33365. context.QCD = qcd;
  33366. } else {
  33367. context.currentTile.QCD = qcd;
  33368. context.currentTile.QCC = [];
  33369. }
  33370. break;
  33371. case 0xFF5D: // Quantization component (QCC)
  33372. length = readUint16(data, position);
  33373. var qcc = {};
  33374. j = position + 2;
  33375. var cqcc;
  33376. if (context.SIZ.Csiz < 257) {
  33377. cqcc = data[j++];
  33378. } else {
  33379. cqcc = readUint16(data, j);
  33380. j += 2;
  33381. }
  33382. sqcd = data[j++];
  33383. switch (sqcd & 0x1F) {
  33384. case 0:
  33385. spqcdSize = 8;
  33386. scalarExpounded = true;
  33387. break;
  33388. case 1:
  33389. spqcdSize = 16;
  33390. scalarExpounded = false;
  33391. break;
  33392. case 2:
  33393. spqcdSize = 16;
  33394. scalarExpounded = true;
  33395. break;
  33396. default:
  33397. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33398. }
  33399. qcc.noQuantization = (spqcdSize === 8);
  33400. qcc.scalarExpounded = scalarExpounded;
  33401. qcc.guardBits = sqcd >> 5;
  33402. spqcds = [];
  33403. while (j < (length + position)) {
  33404. spqcd = {};
  33405. if (spqcdSize === 8) {
  33406. spqcd.epsilon = data[j++] >> 3;
  33407. spqcd.mu = 0;
  33408. } else {
  33409. spqcd.epsilon = data[j] >> 3;
  33410. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33411. j += 2;
  33412. }
  33413. spqcds.push(spqcd);
  33414. }
  33415. qcc.SPqcds = spqcds;
  33416. if (context.mainHeader) {
  33417. context.QCC[cqcc] = qcc;
  33418. } else {
  33419. context.currentTile.QCC[cqcc] = qcc;
  33420. }
  33421. break;
  33422. case 0xFF52: // Coding style default (COD)
  33423. length = readUint16(data, position);
  33424. var cod = {};
  33425. j = position + 2;
  33426. var scod = data[j++];
  33427. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33428. cod.sopMarkerUsed = !!(scod & 2);
  33429. cod.ephMarkerUsed = !!(scod & 4);
  33430. cod.progressionOrder = data[j++];
  33431. cod.layersCount = readUint16(data, j);
  33432. j += 2;
  33433. cod.multipleComponentTransform = data[j++];
  33434. cod.decompositionLevelsCount = data[j++];
  33435. cod.xcb = (data[j++] & 0xF) + 2;
  33436. cod.ycb = (data[j++] & 0xF) + 2;
  33437. var blockStyle = data[j++];
  33438. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33439. cod.resetContextProbabilities = !!(blockStyle & 2);
  33440. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33441. cod.verticalyStripe = !!(blockStyle & 8);
  33442. cod.predictableTermination = !!(blockStyle & 16);
  33443. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33444. cod.reversibleTransformation = data[j++];
  33445. if (cod.entropyCoderWithCustomPrecincts) {
  33446. var precinctsSizes = [];
  33447. while (j < length + position) {
  33448. var precinctsSize = data[j++];
  33449. precinctsSizes.push({
  33450. PPx: precinctsSize & 0xF,
  33451. PPy: precinctsSize >> 4
  33452. });
  33453. }
  33454. cod.precinctsSizes = precinctsSizes;
  33455. }
  33456. var unsupported = [];
  33457. if (cod.selectiveArithmeticCodingBypass) {
  33458. unsupported.push('selectiveArithmeticCodingBypass');
  33459. }
  33460. if (cod.resetContextProbabilities) {
  33461. unsupported.push('resetContextProbabilities');
  33462. }
  33463. if (cod.terminationOnEachCodingPass) {
  33464. unsupported.push('terminationOnEachCodingPass');
  33465. }
  33466. if (cod.verticalyStripe) {
  33467. unsupported.push('verticalyStripe');
  33468. }
  33469. if (cod.predictableTermination) {
  33470. unsupported.push('predictableTermination');
  33471. }
  33472. if (unsupported.length > 0) {
  33473. doNotRecover = true;
  33474. throw new Error('JPX Error: Unsupported COD options (' +
  33475. unsupported.join(', ') + ')');
  33476. }
  33477. if (context.mainHeader) {
  33478. context.COD = cod;
  33479. } else {
  33480. context.currentTile.COD = cod;
  33481. context.currentTile.COC = [];
  33482. }
  33483. break;
  33484. case 0xFF90: // Start of tile-part (SOT)
  33485. length = readUint16(data, position);
  33486. tile = {};
  33487. tile.index = readUint16(data, position + 2);
  33488. tile.length = readUint32(data, position + 4);
  33489. tile.dataEnd = tile.length + position - 2;
  33490. tile.partIndex = data[position + 8];
  33491. tile.partsCount = data[position + 9];
  33492. context.mainHeader = false;
  33493. if (tile.partIndex === 0) {
  33494. // reset component specific settings
  33495. tile.COD = context.COD;
  33496. tile.COC = context.COC.slice(0); // clone of the global COC
  33497. tile.QCD = context.QCD;
  33498. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33499. }
  33500. context.currentTile = tile;
  33501. break;
  33502. case 0xFF93: // Start of data (SOD)
  33503. tile = context.currentTile;
  33504. if (tile.partIndex === 0) {
  33505. initializeTile(context, tile.index);
  33506. buildPackets(context);
  33507. }
  33508. // moving to the end of the data
  33509. length = tile.dataEnd - position;
  33510. parseTilePackets(context, data, position, length);
  33511. break;
  33512. case 0xFF55: // Tile-part lengths, main header (TLM)
  33513. case 0xFF57: // Packet length, main header (PLM)
  33514. case 0xFF58: // Packet length, tile-part header (PLT)
  33515. case 0xFF64: // Comment (COM)
  33516. length = readUint16(data, position);
  33517. // skipping content
  33518. break;
  33519. case 0xFF53: // Coding style component (COC)
  33520. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33521. 'not implemented');
  33522. default:
  33523. throw new Error('JPX Error: Unknown codestream code: ' +
  33524. code.toString(16));
  33525. }
  33526. position += length;
  33527. }
  33528. } catch (e) {
  33529. if (doNotRecover || this.failOnCorruptedImage) {
  33530. throw e;
  33531. } else {
  33532. warn('Trying to recover from ' + e.message);
  33533. }
  33534. }
  33535. this.tiles = transformComponents(context);
  33536. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33537. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33538. this.componentsCount = context.SIZ.Csiz;
  33539. }
  33540. };
  33541. function calculateComponentDimensions(component, siz) {
  33542. // Section B.2 Component mapping
  33543. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33544. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33545. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33546. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33547. component.width = component.x1 - component.x0;
  33548. component.height = component.y1 - component.y0;
  33549. }
  33550. function calculateTileGrids(context, components) {
  33551. var siz = context.SIZ;
  33552. // Section B.3 Division into tile and tile-components
  33553. var tile, tiles = [];
  33554. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33555. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33556. for (var q = 0; q < numYtiles; q++) {
  33557. for (var p = 0; p < numXtiles; p++) {
  33558. tile = {};
  33559. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33560. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33561. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33562. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33563. tile.width = tile.tx1 - tile.tx0;
  33564. tile.height = tile.ty1 - tile.ty0;
  33565. tile.components = [];
  33566. tiles.push(tile);
  33567. }
  33568. }
  33569. context.tiles = tiles;
  33570. var componentsCount = siz.Csiz;
  33571. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33572. var component = components[i];
  33573. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33574. var tileComponent = {};
  33575. tile = tiles[j];
  33576. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33577. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33578. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33579. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33580. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33581. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33582. tile.components[i] = tileComponent;
  33583. }
  33584. }
  33585. }
  33586. function getBlocksDimensions(context, component, r) {
  33587. var codOrCoc = component.codingStyleParameters;
  33588. var result = {};
  33589. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33590. result.PPx = 15;
  33591. result.PPy = 15;
  33592. } else {
  33593. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33594. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33595. }
  33596. // calculate codeblock size as described in section B.7
  33597. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33598. Math.min(codOrCoc.xcb, result.PPx));
  33599. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33600. Math.min(codOrCoc.ycb, result.PPy));
  33601. return result;
  33602. }
  33603. function buildPrecincts(context, resolution, dimensions) {
  33604. // Section B.6 Division resolution to precincts
  33605. var precinctWidth = 1 << dimensions.PPx;
  33606. var precinctHeight = 1 << dimensions.PPy;
  33607. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33608. // to precincts. Precinct partition divides a resolution according to width
  33609. // and height parameters. The subband that belongs to the resolution level
  33610. // has a different size than the level, unless it is the zero resolution.
  33611. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33612. // The precinct partitioning for a particular subband is derived from a
  33613. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33614. // resolution level)... The LL band associated with each resolution level is
  33615. // divided into precincts... Each of the resulting precinct regions is then
  33616. // mapped into its child subbands (if any) at the next lower resolution
  33617. // level. This is accomplished by using the coordinate transformation
  33618. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33619. // coordinates of a point in the LL band and child subband, respectively.
  33620. var isZeroRes = resolution.resLevel === 0;
  33621. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33622. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33623. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33624. Math.ceil(resolution.trx1 / precinctWidth) -
  33625. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33626. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33627. Math.ceil(resolution.try1 / precinctHeight) -
  33628. Math.floor(resolution.try0 / precinctHeight) : 0);
  33629. var numprecincts = numprecinctswide * numprecinctshigh;
  33630. resolution.precinctParameters = {
  33631. precinctWidth: precinctWidth,
  33632. precinctHeight: precinctHeight,
  33633. numprecinctswide: numprecinctswide,
  33634. numprecinctshigh: numprecinctshigh,
  33635. numprecincts: numprecincts,
  33636. precinctWidthInSubband: precinctWidthInSubband,
  33637. precinctHeightInSubband: precinctHeightInSubband
  33638. };
  33639. }
  33640. function buildCodeblocks(context, subband, dimensions) {
  33641. // Section B.7 Division sub-band into code-blocks
  33642. var xcb_ = dimensions.xcb_;
  33643. var ycb_ = dimensions.ycb_;
  33644. var codeblockWidth = 1 << xcb_;
  33645. var codeblockHeight = 1 << ycb_;
  33646. var cbx0 = subband.tbx0 >> xcb_;
  33647. var cby0 = subband.tby0 >> ycb_;
  33648. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33649. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33650. var precinctParameters = subband.resolution.precinctParameters;
  33651. var codeblocks = [];
  33652. var precincts = [];
  33653. var i, j, codeblock, precinctNumber;
  33654. for (j = cby0; j < cby1; j++) {
  33655. for (i = cbx0; i < cbx1; i++) {
  33656. codeblock = {
  33657. cbx: i,
  33658. cby: j,
  33659. tbx0: codeblockWidth * i,
  33660. tby0: codeblockHeight * j,
  33661. tbx1: codeblockWidth * (i + 1),
  33662. tby1: codeblockHeight * (j + 1)
  33663. };
  33664. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33665. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33666. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33667. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33668. // Calculate precinct number for this codeblock, codeblock position
  33669. // should be relative to its subband, use actual dimension and position
  33670. // See comment about codeblock group width and height
  33671. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33672. precinctParameters.precinctWidthInSubband);
  33673. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33674. precinctParameters.precinctHeightInSubband);
  33675. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33676. codeblock.precinctNumber = precinctNumber;
  33677. codeblock.subbandType = subband.type;
  33678. codeblock.Lblock = 3;
  33679. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  33680. codeblock.tby1_ <= codeblock.tby0_) {
  33681. continue;
  33682. }
  33683. codeblocks.push(codeblock);
  33684. // building precinct for the sub-band
  33685. var precinct = precincts[precinctNumber];
  33686. if (precinct !== undefined) {
  33687. if (i < precinct.cbxMin) {
  33688. precinct.cbxMin = i;
  33689. } else if (i > precinct.cbxMax) {
  33690. precinct.cbxMax = i;
  33691. }
  33692. if (j < precinct.cbyMin) {
  33693. precinct.cbxMin = j;
  33694. } else if (j > precinct.cbyMax) {
  33695. precinct.cbyMax = j;
  33696. }
  33697. } else {
  33698. precincts[precinctNumber] = precinct = {
  33699. cbxMin: i,
  33700. cbyMin: j,
  33701. cbxMax: i,
  33702. cbyMax: j
  33703. };
  33704. }
  33705. codeblock.precinct = precinct;
  33706. }
  33707. }
  33708. subband.codeblockParameters = {
  33709. codeblockWidth: xcb_,
  33710. codeblockHeight: ycb_,
  33711. numcodeblockwide: cbx1 - cbx0 + 1,
  33712. numcodeblockhigh: cby1 - cby0 + 1
  33713. };
  33714. subband.codeblocks = codeblocks;
  33715. subband.precincts = precincts;
  33716. }
  33717. function createPacket(resolution, precinctNumber, layerNumber) {
  33718. var precinctCodeblocks = [];
  33719. // Section B.10.8 Order of info in packet
  33720. var subbands = resolution.subbands;
  33721. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33722. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33723. var subband = subbands[i];
  33724. var codeblocks = subband.codeblocks;
  33725. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33726. var codeblock = codeblocks[j];
  33727. if (codeblock.precinctNumber !== precinctNumber) {
  33728. continue;
  33729. }
  33730. precinctCodeblocks.push(codeblock);
  33731. }
  33732. }
  33733. return {
  33734. layerNumber: layerNumber,
  33735. codeblocks: precinctCodeblocks
  33736. };
  33737. }
  33738. function LayerResolutionComponentPositionIterator(context) {
  33739. var siz = context.SIZ;
  33740. var tileIndex = context.currentTile.index;
  33741. var tile = context.tiles[tileIndex];
  33742. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33743. var componentsCount = siz.Csiz;
  33744. var maxDecompositionLevelsCount = 0;
  33745. for (var q = 0; q < componentsCount; q++) {
  33746. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33747. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33748. }
  33749. var l = 0, r = 0, i = 0, k = 0;
  33750. this.nextPacket = function JpxImage_nextPacket() {
  33751. // Section B.12.1.1 Layer-resolution-component-position
  33752. for (; l < layersCount; l++) {
  33753. for (; r <= maxDecompositionLevelsCount; r++) {
  33754. for (; i < componentsCount; i++) {
  33755. var component = tile.components[i];
  33756. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33757. continue;
  33758. }
  33759. var resolution = component.resolutions[r];
  33760. var numprecincts = resolution.precinctParameters.numprecincts;
  33761. for (; k < numprecincts;) {
  33762. var packet = createPacket(resolution, k, l);
  33763. k++;
  33764. return packet;
  33765. }
  33766. k = 0;
  33767. }
  33768. i = 0;
  33769. }
  33770. r = 0;
  33771. }
  33772. throw new Error('JPX Error: Out of packets');
  33773. };
  33774. }
  33775. function ResolutionLayerComponentPositionIterator(context) {
  33776. var siz = context.SIZ;
  33777. var tileIndex = context.currentTile.index;
  33778. var tile = context.tiles[tileIndex];
  33779. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33780. var componentsCount = siz.Csiz;
  33781. var maxDecompositionLevelsCount = 0;
  33782. for (var q = 0; q < componentsCount; q++) {
  33783. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33784. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33785. }
  33786. var r = 0, l = 0, i = 0, k = 0;
  33787. this.nextPacket = function JpxImage_nextPacket() {
  33788. // Section B.12.1.2 Resolution-layer-component-position
  33789. for (; r <= maxDecompositionLevelsCount; r++) {
  33790. for (; l < layersCount; l++) {
  33791. for (; i < componentsCount; i++) {
  33792. var component = tile.components[i];
  33793. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33794. continue;
  33795. }
  33796. var resolution = component.resolutions[r];
  33797. var numprecincts = resolution.precinctParameters.numprecincts;
  33798. for (; k < numprecincts;) {
  33799. var packet = createPacket(resolution, k, l);
  33800. k++;
  33801. return packet;
  33802. }
  33803. k = 0;
  33804. }
  33805. i = 0;
  33806. }
  33807. l = 0;
  33808. }
  33809. throw new Error('JPX Error: Out of packets');
  33810. };
  33811. }
  33812. function ResolutionPositionComponentLayerIterator(context) {
  33813. var siz = context.SIZ;
  33814. var tileIndex = context.currentTile.index;
  33815. var tile = context.tiles[tileIndex];
  33816. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33817. var componentsCount = siz.Csiz;
  33818. var l, r, c, p;
  33819. var maxDecompositionLevelsCount = 0;
  33820. for (c = 0; c < componentsCount; c++) {
  33821. var component = tile.components[c];
  33822. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33823. component.codingStyleParameters.decompositionLevelsCount);
  33824. }
  33825. var maxNumPrecinctsInLevel = new Int32Array(
  33826. maxDecompositionLevelsCount + 1);
  33827. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  33828. var maxNumPrecincts = 0;
  33829. for (c = 0; c < componentsCount; ++c) {
  33830. var resolutions = tile.components[c].resolutions;
  33831. if (r < resolutions.length) {
  33832. maxNumPrecincts = Math.max(maxNumPrecincts,
  33833. resolutions[r].precinctParameters.numprecincts);
  33834. }
  33835. }
  33836. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  33837. }
  33838. l = 0;
  33839. r = 0;
  33840. c = 0;
  33841. p = 0;
  33842. this.nextPacket = function JpxImage_nextPacket() {
  33843. // Section B.12.1.3 Resolution-position-component-layer
  33844. for (; r <= maxDecompositionLevelsCount; r++) {
  33845. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  33846. for (; c < componentsCount; c++) {
  33847. var component = tile.components[c];
  33848. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33849. continue;
  33850. }
  33851. var resolution = component.resolutions[r];
  33852. var numprecincts = resolution.precinctParameters.numprecincts;
  33853. if (p >= numprecincts) {
  33854. continue;
  33855. }
  33856. for (; l < layersCount;) {
  33857. var packet = createPacket(resolution, p, l);
  33858. l++;
  33859. return packet;
  33860. }
  33861. l = 0;
  33862. }
  33863. c = 0;
  33864. }
  33865. p = 0;
  33866. }
  33867. throw new Error('JPX Error: Out of packets');
  33868. };
  33869. }
  33870. function PositionComponentResolutionLayerIterator(context) {
  33871. var siz = context.SIZ;
  33872. var tileIndex = context.currentTile.index;
  33873. var tile = context.tiles[tileIndex];
  33874. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33875. var componentsCount = siz.Csiz;
  33876. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33877. var precinctsIterationSizes = precinctsSizes;
  33878. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33879. this.nextPacket = function JpxImage_nextPacket() {
  33880. // Section B.12.1.4 Position-component-resolution-layer
  33881. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33882. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33883. for (; c < componentsCount; c++) {
  33884. var component = tile.components[c];
  33885. var decompositionLevelsCount =
  33886. component.codingStyleParameters.decompositionLevelsCount;
  33887. for (; r <= decompositionLevelsCount; r++) {
  33888. var resolution = component.resolutions[r];
  33889. var sizeInImageScale =
  33890. precinctsSizes.components[c].resolutions[r];
  33891. var k = getPrecinctIndexIfExist(
  33892. px,
  33893. py,
  33894. sizeInImageScale,
  33895. precinctsIterationSizes,
  33896. resolution);
  33897. if (k === null) {
  33898. continue;
  33899. }
  33900. for (; l < layersCount;) {
  33901. var packet = createPacket(resolution, k, l);
  33902. l++;
  33903. return packet;
  33904. }
  33905. l = 0;
  33906. }
  33907. r = 0;
  33908. }
  33909. c = 0;
  33910. }
  33911. px = 0;
  33912. }
  33913. throw new Error('JPX Error: Out of packets');
  33914. };
  33915. }
  33916. function ComponentPositionResolutionLayerIterator(context) {
  33917. var siz = context.SIZ;
  33918. var tileIndex = context.currentTile.index;
  33919. var tile = context.tiles[tileIndex];
  33920. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33921. var componentsCount = siz.Csiz;
  33922. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33923. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33924. this.nextPacket = function JpxImage_nextPacket() {
  33925. // Section B.12.1.5 Component-position-resolution-layer
  33926. for (; c < componentsCount; ++c) {
  33927. var component = tile.components[c];
  33928. var precinctsIterationSizes = precinctsSizes.components[c];
  33929. var decompositionLevelsCount =
  33930. component.codingStyleParameters.decompositionLevelsCount;
  33931. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33932. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33933. for (; r <= decompositionLevelsCount; r++) {
  33934. var resolution = component.resolutions[r];
  33935. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  33936. var k = getPrecinctIndexIfExist(
  33937. px,
  33938. py,
  33939. sizeInImageScale,
  33940. precinctsIterationSizes,
  33941. resolution);
  33942. if (k === null) {
  33943. continue;
  33944. }
  33945. for (; l < layersCount;) {
  33946. var packet = createPacket(resolution, k, l);
  33947. l++;
  33948. return packet;
  33949. }
  33950. l = 0;
  33951. }
  33952. r = 0;
  33953. }
  33954. px = 0;
  33955. }
  33956. py = 0;
  33957. }
  33958. throw new Error('JPX Error: Out of packets');
  33959. };
  33960. }
  33961. function getPrecinctIndexIfExist(
  33962. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  33963. var posX = pxIndex * precinctIterationSizes.minWidth;
  33964. var posY = pyIndex * precinctIterationSizes.minHeight;
  33965. if (posX % sizeInImageScale.width !== 0 ||
  33966. posY % sizeInImageScale.height !== 0) {
  33967. return null;
  33968. }
  33969. var startPrecinctRowIndex =
  33970. (posY / sizeInImageScale.width) *
  33971. resolution.precinctParameters.numprecinctswide;
  33972. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  33973. }
  33974. function getPrecinctSizesInImageScale(tile) {
  33975. var componentsCount = tile.components.length;
  33976. var minWidth = Number.MAX_VALUE;
  33977. var minHeight = Number.MAX_VALUE;
  33978. var maxNumWide = 0;
  33979. var maxNumHigh = 0;
  33980. var sizePerComponent = new Array(componentsCount);
  33981. for (var c = 0; c < componentsCount; c++) {
  33982. var component = tile.components[c];
  33983. var decompositionLevelsCount =
  33984. component.codingStyleParameters.decompositionLevelsCount;
  33985. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  33986. var minWidthCurrentComponent = Number.MAX_VALUE;
  33987. var minHeightCurrentComponent = Number.MAX_VALUE;
  33988. var maxNumWideCurrentComponent = 0;
  33989. var maxNumHighCurrentComponent = 0;
  33990. var scale = 1;
  33991. for (var r = decompositionLevelsCount; r >= 0; --r) {
  33992. var resolution = component.resolutions[r];
  33993. var widthCurrentResolution =
  33994. scale * resolution.precinctParameters.precinctWidth;
  33995. var heightCurrentResolution =
  33996. scale * resolution.precinctParameters.precinctHeight;
  33997. minWidthCurrentComponent = Math.min(
  33998. minWidthCurrentComponent,
  33999. widthCurrentResolution);
  34000. minHeightCurrentComponent = Math.min(
  34001. minHeightCurrentComponent,
  34002. heightCurrentResolution);
  34003. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34004. resolution.precinctParameters.numprecinctswide);
  34005. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34006. resolution.precinctParameters.numprecinctshigh);
  34007. sizePerResolution[r] = {
  34008. width: widthCurrentResolution,
  34009. height: heightCurrentResolution
  34010. };
  34011. scale <<= 1;
  34012. }
  34013. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34014. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34015. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34016. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34017. sizePerComponent[c] = {
  34018. resolutions: sizePerResolution,
  34019. minWidth: minWidthCurrentComponent,
  34020. minHeight: minHeightCurrentComponent,
  34021. maxNumWide: maxNumWideCurrentComponent,
  34022. maxNumHigh: maxNumHighCurrentComponent
  34023. };
  34024. }
  34025. return {
  34026. components: sizePerComponent,
  34027. minWidth: minWidth,
  34028. minHeight: minHeight,
  34029. maxNumWide: maxNumWide,
  34030. maxNumHigh: maxNumHigh
  34031. };
  34032. }
  34033. function buildPackets(context) {
  34034. var siz = context.SIZ;
  34035. var tileIndex = context.currentTile.index;
  34036. var tile = context.tiles[tileIndex];
  34037. var componentsCount = siz.Csiz;
  34038. // Creating resolutions and sub-bands for each component
  34039. for (var c = 0; c < componentsCount; c++) {
  34040. var component = tile.components[c];
  34041. var decompositionLevelsCount =
  34042. component.codingStyleParameters.decompositionLevelsCount;
  34043. // Section B.5 Resolution levels and sub-bands
  34044. var resolutions = [];
  34045. var subbands = [];
  34046. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34047. var blocksDimensions = getBlocksDimensions(context, component, r);
  34048. var resolution = {};
  34049. var scale = 1 << (decompositionLevelsCount - r);
  34050. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34051. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34052. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34053. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34054. resolution.resLevel = r;
  34055. buildPrecincts(context, resolution, blocksDimensions);
  34056. resolutions.push(resolution);
  34057. var subband;
  34058. if (r === 0) {
  34059. // one sub-band (LL) with last decomposition
  34060. subband = {};
  34061. subband.type = 'LL';
  34062. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34063. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34064. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34065. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34066. subband.resolution = resolution;
  34067. buildCodeblocks(context, subband, blocksDimensions);
  34068. subbands.push(subband);
  34069. resolution.subbands = [subband];
  34070. } else {
  34071. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34072. var resolutionSubbands = [];
  34073. // three sub-bands (HL, LH and HH) with rest of decompositions
  34074. subband = {};
  34075. subband.type = 'HL';
  34076. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34077. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34078. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34079. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34080. subband.resolution = resolution;
  34081. buildCodeblocks(context, subband, blocksDimensions);
  34082. subbands.push(subband);
  34083. resolutionSubbands.push(subband);
  34084. subband = {};
  34085. subband.type = 'LH';
  34086. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34087. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34088. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34089. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34090. subband.resolution = resolution;
  34091. buildCodeblocks(context, subband, blocksDimensions);
  34092. subbands.push(subband);
  34093. resolutionSubbands.push(subband);
  34094. subband = {};
  34095. subband.type = 'HH';
  34096. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34097. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34098. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34099. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34100. subband.resolution = resolution;
  34101. buildCodeblocks(context, subband, blocksDimensions);
  34102. subbands.push(subband);
  34103. resolutionSubbands.push(subband);
  34104. resolution.subbands = resolutionSubbands;
  34105. }
  34106. }
  34107. component.resolutions = resolutions;
  34108. component.subbands = subbands;
  34109. }
  34110. // Generate the packets sequence
  34111. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34112. switch (progressionOrder) {
  34113. case 0:
  34114. tile.packetsIterator =
  34115. new LayerResolutionComponentPositionIterator(context);
  34116. break;
  34117. case 1:
  34118. tile.packetsIterator =
  34119. new ResolutionLayerComponentPositionIterator(context);
  34120. break;
  34121. case 2:
  34122. tile.packetsIterator =
  34123. new ResolutionPositionComponentLayerIterator(context);
  34124. break;
  34125. case 3:
  34126. tile.packetsIterator =
  34127. new PositionComponentResolutionLayerIterator(context);
  34128. break;
  34129. case 4:
  34130. tile.packetsIterator =
  34131. new ComponentPositionResolutionLayerIterator(context);
  34132. break;
  34133. default:
  34134. throw new Error('JPX Error: Unsupported progression order ' +
  34135. progressionOrder);
  34136. }
  34137. }
  34138. function parseTilePackets(context, data, offset, dataLength) {
  34139. var position = 0;
  34140. var buffer, bufferSize = 0, skipNextBit = false;
  34141. function readBits(count) {
  34142. while (bufferSize < count) {
  34143. var b = data[offset + position];
  34144. position++;
  34145. if (skipNextBit) {
  34146. buffer = (buffer << 7) | b;
  34147. bufferSize += 7;
  34148. skipNextBit = false;
  34149. } else {
  34150. buffer = (buffer << 8) | b;
  34151. bufferSize += 8;
  34152. }
  34153. if (b === 0xFF) {
  34154. skipNextBit = true;
  34155. }
  34156. }
  34157. bufferSize -= count;
  34158. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34159. }
  34160. function skipMarkerIfEqual(value) {
  34161. if (data[offset + position - 1] === 0xFF &&
  34162. data[offset + position] === value) {
  34163. skipBytes(1);
  34164. return true;
  34165. } else if (data[offset + position] === 0xFF &&
  34166. data[offset + position + 1] === value) {
  34167. skipBytes(2);
  34168. return true;
  34169. }
  34170. return false;
  34171. }
  34172. function skipBytes(count) {
  34173. position += count;
  34174. }
  34175. function alignToByte() {
  34176. bufferSize = 0;
  34177. if (skipNextBit) {
  34178. position++;
  34179. skipNextBit = false;
  34180. }
  34181. }
  34182. function readCodingpasses() {
  34183. if (readBits(1) === 0) {
  34184. return 1;
  34185. }
  34186. if (readBits(1) === 0) {
  34187. return 2;
  34188. }
  34189. var value = readBits(2);
  34190. if (value < 3) {
  34191. return value + 3;
  34192. }
  34193. value = readBits(5);
  34194. if (value < 31) {
  34195. return value + 6;
  34196. }
  34197. value = readBits(7);
  34198. return value + 37;
  34199. }
  34200. var tileIndex = context.currentTile.index;
  34201. var tile = context.tiles[tileIndex];
  34202. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34203. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34204. var packetsIterator = tile.packetsIterator;
  34205. while (position < dataLength) {
  34206. alignToByte();
  34207. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34208. // Skip also marker segment length and packet sequence ID
  34209. skipBytes(4);
  34210. }
  34211. var packet = packetsIterator.nextPacket();
  34212. if (!readBits(1)) {
  34213. continue;
  34214. }
  34215. var layerNumber = packet.layerNumber;
  34216. var queue = [], codeblock;
  34217. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34218. codeblock = packet.codeblocks[i];
  34219. var precinct = codeblock.precinct;
  34220. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34221. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34222. var codeblockIncluded = false;
  34223. var firstTimeInclusion = false;
  34224. var valueReady;
  34225. if (codeblock['included'] !== undefined) {
  34226. codeblockIncluded = !!readBits(1);
  34227. } else {
  34228. // reading inclusion tree
  34229. precinct = codeblock.precinct;
  34230. var inclusionTree, zeroBitPlanesTree;
  34231. if (precinct['inclusionTree'] !== undefined) {
  34232. inclusionTree = precinct.inclusionTree;
  34233. } else {
  34234. // building inclusion and zero bit-planes trees
  34235. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34236. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34237. inclusionTree = new InclusionTree(width, height, layerNumber);
  34238. zeroBitPlanesTree = new TagTree(width, height);
  34239. precinct.inclusionTree = inclusionTree;
  34240. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34241. }
  34242. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34243. while (true) {
  34244. if (readBits(1)) {
  34245. valueReady = !inclusionTree.nextLevel();
  34246. if (valueReady) {
  34247. codeblock.included = true;
  34248. codeblockIncluded = firstTimeInclusion = true;
  34249. break;
  34250. }
  34251. } else {
  34252. inclusionTree.incrementValue(layerNumber);
  34253. break;
  34254. }
  34255. }
  34256. }
  34257. }
  34258. if (!codeblockIncluded) {
  34259. continue;
  34260. }
  34261. if (firstTimeInclusion) {
  34262. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34263. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34264. while (true) {
  34265. if (readBits(1)) {
  34266. valueReady = !zeroBitPlanesTree.nextLevel();
  34267. if (valueReady) {
  34268. break;
  34269. }
  34270. } else {
  34271. zeroBitPlanesTree.incrementValue();
  34272. }
  34273. }
  34274. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34275. }
  34276. var codingpasses = readCodingpasses();
  34277. while (readBits(1)) {
  34278. codeblock.Lblock++;
  34279. }
  34280. var codingpassesLog2 = log2(codingpasses);
  34281. // rounding down log2
  34282. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34283. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34284. var codedDataLength = readBits(bits);
  34285. queue.push({
  34286. codeblock: codeblock,
  34287. codingpasses: codingpasses,
  34288. dataLength: codedDataLength
  34289. });
  34290. }
  34291. alignToByte();
  34292. if (ephMarkerUsed) {
  34293. skipMarkerIfEqual(0x92);
  34294. }
  34295. while (queue.length > 0) {
  34296. var packetItem = queue.shift();
  34297. codeblock = packetItem.codeblock;
  34298. if (codeblock['data'] === undefined) {
  34299. codeblock.data = [];
  34300. }
  34301. codeblock.data.push({
  34302. data: data,
  34303. start: offset + position,
  34304. end: offset + position + packetItem.dataLength,
  34305. codingpasses: packetItem.codingpasses
  34306. });
  34307. position += packetItem.dataLength;
  34308. }
  34309. }
  34310. return position;
  34311. }
  34312. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34313. delta, mb, reversible, segmentationSymbolUsed) {
  34314. var x0 = subband.tbx0;
  34315. var y0 = subband.tby0;
  34316. var width = subband.tbx1 - subband.tbx0;
  34317. var codeblocks = subband.codeblocks;
  34318. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34319. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34320. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34321. var codeblock = codeblocks[i];
  34322. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34323. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34324. if (blockWidth === 0 || blockHeight === 0) {
  34325. continue;
  34326. }
  34327. if (codeblock['data'] === undefined) {
  34328. continue;
  34329. }
  34330. var bitModel, currentCodingpassType;
  34331. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34332. codeblock.zeroBitPlanes, mb);
  34333. currentCodingpassType = 2; // first bit plane starts from cleanup
  34334. // collect data
  34335. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34336. var j, jj, dataItem;
  34337. for (j = 0, jj = data.length; j < jj; j++) {
  34338. dataItem = data[j];
  34339. totalLength += dataItem.end - dataItem.start;
  34340. codingpasses += dataItem.codingpasses;
  34341. }
  34342. var encodedData = new Uint8Array(totalLength);
  34343. var position = 0;
  34344. for (j = 0, jj = data.length; j < jj; j++) {
  34345. dataItem = data[j];
  34346. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34347. encodedData.set(chunk, position);
  34348. position += chunk.length;
  34349. }
  34350. // decoding the item
  34351. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34352. bitModel.setDecoder(decoder);
  34353. for (j = 0; j < codingpasses; j++) {
  34354. switch (currentCodingpassType) {
  34355. case 0:
  34356. bitModel.runSignificancePropogationPass();
  34357. break;
  34358. case 1:
  34359. bitModel.runMagnitudeRefinementPass();
  34360. break;
  34361. case 2:
  34362. bitModel.runCleanupPass();
  34363. if (segmentationSymbolUsed) {
  34364. bitModel.checkSegmentationSymbol();
  34365. }
  34366. break;
  34367. }
  34368. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34369. }
  34370. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34371. var sign = bitModel.coefficentsSign;
  34372. var magnitude = bitModel.coefficentsMagnitude;
  34373. var bitsDecoded = bitModel.bitsDecoded;
  34374. var magnitudeCorrection = reversible ? 0 : 0.5;
  34375. var k, n, nb;
  34376. position = 0;
  34377. // Do the interleaving of Section F.3.3 here, so we do not need
  34378. // to copy later. LL level is not interleaved, just copied.
  34379. var interleave = (subband.type !== 'LL');
  34380. for (j = 0; j < blockHeight; j++) {
  34381. var row = (offset / width) | 0; // row in the non-interleaved subband
  34382. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34383. for (k = 0; k < blockWidth; k++) {
  34384. n = magnitude[position];
  34385. if (n !== 0) {
  34386. n = (n + magnitudeCorrection) * delta;
  34387. if (sign[position] !== 0) {
  34388. n = -n;
  34389. }
  34390. nb = bitsDecoded[position];
  34391. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34392. if (reversible && (nb >= mb)) {
  34393. coefficients[pos] = n;
  34394. } else {
  34395. coefficients[pos] = n * (1 << (mb - nb));
  34396. }
  34397. }
  34398. offset++;
  34399. position++;
  34400. }
  34401. offset += width - blockWidth;
  34402. }
  34403. }
  34404. }
  34405. function transformTile(context, tile, c) {
  34406. var component = tile.components[c];
  34407. var codingStyleParameters = component.codingStyleParameters;
  34408. var quantizationParameters = component.quantizationParameters;
  34409. var decompositionLevelsCount =
  34410. codingStyleParameters.decompositionLevelsCount;
  34411. var spqcds = quantizationParameters.SPqcds;
  34412. var scalarExpounded = quantizationParameters.scalarExpounded;
  34413. var guardBits = quantizationParameters.guardBits;
  34414. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34415. var precision = context.components[c].precision;
  34416. var reversible = codingStyleParameters.reversibleTransformation;
  34417. var transform = (reversible ? new ReversibleTransform() :
  34418. new IrreversibleTransform());
  34419. var subbandCoefficients = [];
  34420. var b = 0;
  34421. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34422. var resolution = component.resolutions[i];
  34423. var width = resolution.trx1 - resolution.trx0;
  34424. var height = resolution.try1 - resolution.try0;
  34425. // Allocate space for the whole sublevel.
  34426. var coefficients = new Float32Array(width * height);
  34427. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34428. var mu, epsilon;
  34429. if (!scalarExpounded) {
  34430. // formula E-5
  34431. mu = spqcds[0].mu;
  34432. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34433. } else {
  34434. mu = spqcds[b].mu;
  34435. epsilon = spqcds[b].epsilon;
  34436. b++;
  34437. }
  34438. var subband = resolution.subbands[j];
  34439. var gainLog2 = SubbandsGainLog2[subband.type];
  34440. // calulate quantization coefficient (Section E.1.1.1)
  34441. var delta = (reversible ? 1 :
  34442. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34443. var mb = (guardBits + epsilon - 1);
  34444. // In the first resolution level, copyCoefficients will fill the
  34445. // whole array with coefficients. In the succeding passes,
  34446. // copyCoefficients will consecutively fill in the values that belong
  34447. // to the interleaved positions of the HL, LH, and HH coefficients.
  34448. // The LL coefficients will then be interleaved in Transform.iterate().
  34449. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34450. reversible, segmentationSymbolUsed);
  34451. }
  34452. subbandCoefficients.push({
  34453. width: width,
  34454. height: height,
  34455. items: coefficients
  34456. });
  34457. }
  34458. var result = transform.calculate(subbandCoefficients,
  34459. component.tcx0, component.tcy0);
  34460. return {
  34461. left: component.tcx0,
  34462. top: component.tcy0,
  34463. width: result.width,
  34464. height: result.height,
  34465. items: result.items
  34466. };
  34467. }
  34468. function transformComponents(context) {
  34469. var siz = context.SIZ;
  34470. var components = context.components;
  34471. var componentsCount = siz.Csiz;
  34472. var resultImages = [];
  34473. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34474. var tile = context.tiles[i];
  34475. var transformedTiles = [];
  34476. var c;
  34477. for (c = 0; c < componentsCount; c++) {
  34478. transformedTiles[c] = transformTile(context, tile, c);
  34479. }
  34480. var tile0 = transformedTiles[0];
  34481. var out = new Uint8Array(tile0.items.length * componentsCount);
  34482. var result = {
  34483. left: tile0.left,
  34484. top: tile0.top,
  34485. width: tile0.width,
  34486. height: tile0.height,
  34487. items: out
  34488. };
  34489. // Section G.2.2 Inverse multi component transform
  34490. var shift, offset, max, min, maxK;
  34491. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34492. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34493. var fourComponents = componentsCount === 4;
  34494. var y0items = transformedTiles[0].items;
  34495. var y1items = transformedTiles[1].items;
  34496. var y2items = transformedTiles[2].items;
  34497. var y3items = fourComponents ? transformedTiles[3].items : null;
  34498. // HACK: The multiple component transform formulas below assume that
  34499. // all components have the same precision. With this in mind, we
  34500. // compute shift and offset only once.
  34501. shift = components[0].precision - 8;
  34502. offset = (128 << shift) + 0.5;
  34503. max = 255 * (1 << shift);
  34504. maxK = max * 0.5;
  34505. min = -maxK;
  34506. var component0 = tile.components[0];
  34507. var alpha01 = componentsCount - 3;
  34508. jj = y0items.length;
  34509. if (!component0.codingStyleParameters.reversibleTransformation) {
  34510. // inverse irreversible multiple component transform
  34511. for (j = 0; j < jj; j++, pos += alpha01) {
  34512. y0 = y0items[j] + offset;
  34513. y1 = y1items[j];
  34514. y2 = y2items[j];
  34515. r = y0 + 1.402 * y2;
  34516. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34517. b = y0 + 1.772 * y1;
  34518. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34519. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34520. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34521. }
  34522. } else {
  34523. // inverse reversible multiple component transform
  34524. for (j = 0; j < jj; j++, pos += alpha01) {
  34525. y0 = y0items[j] + offset;
  34526. y1 = y1items[j];
  34527. y2 = y2items[j];
  34528. g = y0 - ((y2 + y1) >> 2);
  34529. r = g + y2;
  34530. b = g + y1;
  34531. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34532. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34533. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34534. }
  34535. }
  34536. if (fourComponents) {
  34537. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34538. k = y3items[j];
  34539. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34540. }
  34541. }
  34542. } else { // no multi-component transform
  34543. for (c = 0; c < componentsCount; c++) {
  34544. var items = transformedTiles[c].items;
  34545. shift = components[c].precision - 8;
  34546. offset = (128 << shift) + 0.5;
  34547. max = (127.5 * (1 << shift));
  34548. min = -max;
  34549. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34550. val = items[j];
  34551. out[pos] = val <= min ? 0 :
  34552. val >= max ? 255 : (val + offset) >> shift;
  34553. pos += componentsCount;
  34554. }
  34555. }
  34556. }
  34557. resultImages.push(result);
  34558. }
  34559. return resultImages;
  34560. }
  34561. function initializeTile(context, tileIndex) {
  34562. var siz = context.SIZ;
  34563. var componentsCount = siz.Csiz;
  34564. var tile = context.tiles[tileIndex];
  34565. for (var c = 0; c < componentsCount; c++) {
  34566. var component = tile.components[c];
  34567. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34568. context.currentTile.QCC[c] : context.currentTile.QCD);
  34569. component.quantizationParameters = qcdOrQcc;
  34570. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34571. context.currentTile.COC[c] : context.currentTile.COD);
  34572. component.codingStyleParameters = codOrCoc;
  34573. }
  34574. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34575. }
  34576. // Section B.10.2 Tag trees
  34577. var TagTree = (function TagTreeClosure() {
  34578. function TagTree(width, height) {
  34579. var levelsLength = log2(Math.max(width, height)) + 1;
  34580. this.levels = [];
  34581. for (var i = 0; i < levelsLength; i++) {
  34582. var level = {
  34583. width: width,
  34584. height: height,
  34585. items: []
  34586. };
  34587. this.levels.push(level);
  34588. width = Math.ceil(width / 2);
  34589. height = Math.ceil(height / 2);
  34590. }
  34591. }
  34592. TagTree.prototype = {
  34593. reset: function TagTree_reset(i, j) {
  34594. var currentLevel = 0, value = 0, level;
  34595. while (currentLevel < this.levels.length) {
  34596. level = this.levels[currentLevel];
  34597. var index = i + j * level.width;
  34598. if (level.items[index] !== undefined) {
  34599. value = level.items[index];
  34600. break;
  34601. }
  34602. level.index = index;
  34603. i >>= 1;
  34604. j >>= 1;
  34605. currentLevel++;
  34606. }
  34607. currentLevel--;
  34608. level = this.levels[currentLevel];
  34609. level.items[level.index] = value;
  34610. this.currentLevel = currentLevel;
  34611. delete this.value;
  34612. },
  34613. incrementValue: function TagTree_incrementValue() {
  34614. var level = this.levels[this.currentLevel];
  34615. level.items[level.index]++;
  34616. },
  34617. nextLevel: function TagTree_nextLevel() {
  34618. var currentLevel = this.currentLevel;
  34619. var level = this.levels[currentLevel];
  34620. var value = level.items[level.index];
  34621. currentLevel--;
  34622. if (currentLevel < 0) {
  34623. this.value = value;
  34624. return false;
  34625. }
  34626. this.currentLevel = currentLevel;
  34627. level = this.levels[currentLevel];
  34628. level.items[level.index] = value;
  34629. return true;
  34630. }
  34631. };
  34632. return TagTree;
  34633. })();
  34634. var InclusionTree = (function InclusionTreeClosure() {
  34635. function InclusionTree(width, height, defaultValue) {
  34636. var levelsLength = log2(Math.max(width, height)) + 1;
  34637. this.levels = [];
  34638. for (var i = 0; i < levelsLength; i++) {
  34639. var items = new Uint8Array(width * height);
  34640. for (var j = 0, jj = items.length; j < jj; j++) {
  34641. items[j] = defaultValue;
  34642. }
  34643. var level = {
  34644. width: width,
  34645. height: height,
  34646. items: items
  34647. };
  34648. this.levels.push(level);
  34649. width = Math.ceil(width / 2);
  34650. height = Math.ceil(height / 2);
  34651. }
  34652. }
  34653. InclusionTree.prototype = {
  34654. reset: function InclusionTree_reset(i, j, stopValue) {
  34655. var currentLevel = 0;
  34656. while (currentLevel < this.levels.length) {
  34657. var level = this.levels[currentLevel];
  34658. var index = i + j * level.width;
  34659. level.index = index;
  34660. var value = level.items[index];
  34661. if (value === 0xFF) {
  34662. break;
  34663. }
  34664. if (value > stopValue) {
  34665. this.currentLevel = currentLevel;
  34666. // already know about this one, propagating the value to top levels
  34667. this.propagateValues();
  34668. return false;
  34669. }
  34670. i >>= 1;
  34671. j >>= 1;
  34672. currentLevel++;
  34673. }
  34674. this.currentLevel = currentLevel - 1;
  34675. return true;
  34676. },
  34677. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34678. var level = this.levels[this.currentLevel];
  34679. level.items[level.index] = stopValue + 1;
  34680. this.propagateValues();
  34681. },
  34682. propagateValues: function InclusionTree_propagateValues() {
  34683. var levelIndex = this.currentLevel;
  34684. var level = this.levels[levelIndex];
  34685. var currentValue = level.items[level.index];
  34686. while (--levelIndex >= 0) {
  34687. level = this.levels[levelIndex];
  34688. level.items[level.index] = currentValue;
  34689. }
  34690. },
  34691. nextLevel: function InclusionTree_nextLevel() {
  34692. var currentLevel = this.currentLevel;
  34693. var level = this.levels[currentLevel];
  34694. var value = level.items[level.index];
  34695. level.items[level.index] = 0xFF;
  34696. currentLevel--;
  34697. if (currentLevel < 0) {
  34698. return false;
  34699. }
  34700. this.currentLevel = currentLevel;
  34701. level = this.levels[currentLevel];
  34702. level.items[level.index] = value;
  34703. return true;
  34704. }
  34705. };
  34706. return InclusionTree;
  34707. })();
  34708. // Section D. Coefficient bit modeling
  34709. var BitModel = (function BitModelClosure() {
  34710. var UNIFORM_CONTEXT = 17;
  34711. var RUNLENGTH_CONTEXT = 18;
  34712. // Table D-1
  34713. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34714. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34715. var LLAndLHContextsLabel = new Uint8Array([
  34716. 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,
  34717. 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,
  34718. 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
  34719. ]);
  34720. var HLContextLabel = new Uint8Array([
  34721. 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,
  34722. 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,
  34723. 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
  34724. ]);
  34725. var HHContextLabel = new Uint8Array([
  34726. 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,
  34727. 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,
  34728. 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
  34729. ]);
  34730. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34731. this.width = width;
  34732. this.height = height;
  34733. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34734. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34735. var coefficientCount = width * height;
  34736. // coefficients outside the encoding region treated as insignificant
  34737. // add border state cells for significanceState
  34738. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34739. this.coefficentsSign = new Uint8Array(coefficientCount);
  34740. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34741. mb > 6 ? new Uint16Array(coefficientCount) :
  34742. new Uint8Array(coefficientCount);
  34743. this.processingFlags = new Uint8Array(coefficientCount);
  34744. var bitsDecoded = new Uint8Array(coefficientCount);
  34745. if (zeroBitPlanes !== 0) {
  34746. for (var i = 0; i < coefficientCount; i++) {
  34747. bitsDecoded[i] = zeroBitPlanes;
  34748. }
  34749. }
  34750. this.bitsDecoded = bitsDecoded;
  34751. this.reset();
  34752. }
  34753. BitModel.prototype = {
  34754. setDecoder: function BitModel_setDecoder(decoder) {
  34755. this.decoder = decoder;
  34756. },
  34757. reset: function BitModel_reset() {
  34758. // We have 17 contexts that are accessed via context labels,
  34759. // plus the uniform and runlength context.
  34760. this.contexts = new Int8Array(19);
  34761. // Contexts are packed into 1 byte:
  34762. // highest 7 bits carry the index, lowest bit carries mps
  34763. this.contexts[0] = (4 << 1) | 0;
  34764. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34765. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34766. },
  34767. setNeighborsSignificance:
  34768. function BitModel_setNeighborsSignificance(row, column, index) {
  34769. var neighborsSignificance = this.neighborsSignificance;
  34770. var width = this.width, height = this.height;
  34771. var left = (column > 0);
  34772. var right = (column + 1 < width);
  34773. var i;
  34774. if (row > 0) {
  34775. i = index - width;
  34776. if (left) {
  34777. neighborsSignificance[i - 1] += 0x10;
  34778. }
  34779. if (right) {
  34780. neighborsSignificance[i + 1] += 0x10;
  34781. }
  34782. neighborsSignificance[i] += 0x04;
  34783. }
  34784. if (row + 1 < height) {
  34785. i = index + width;
  34786. if (left) {
  34787. neighborsSignificance[i - 1] += 0x10;
  34788. }
  34789. if (right) {
  34790. neighborsSignificance[i + 1] += 0x10;
  34791. }
  34792. neighborsSignificance[i] += 0x04;
  34793. }
  34794. if (left) {
  34795. neighborsSignificance[index - 1] += 0x01;
  34796. }
  34797. if (right) {
  34798. neighborsSignificance[index + 1] += 0x01;
  34799. }
  34800. neighborsSignificance[index] |= 0x80;
  34801. },
  34802. runSignificancePropogationPass:
  34803. function BitModel_runSignificancePropogationPass() {
  34804. var decoder = this.decoder;
  34805. var width = this.width, height = this.height;
  34806. var coefficentsMagnitude = this.coefficentsMagnitude;
  34807. var coefficentsSign = this.coefficentsSign;
  34808. var neighborsSignificance = this.neighborsSignificance;
  34809. var processingFlags = this.processingFlags;
  34810. var contexts = this.contexts;
  34811. var labels = this.contextLabelTable;
  34812. var bitsDecoded = this.bitsDecoded;
  34813. var processedInverseMask = ~1;
  34814. var processedMask = 1;
  34815. var firstMagnitudeBitMask = 2;
  34816. for (var i0 = 0; i0 < height; i0 += 4) {
  34817. for (var j = 0; j < width; j++) {
  34818. var index = i0 * width + j;
  34819. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34820. var i = i0 + i1;
  34821. if (i >= height) {
  34822. break;
  34823. }
  34824. // clear processed flag first
  34825. processingFlags[index] &= processedInverseMask;
  34826. if (coefficentsMagnitude[index] ||
  34827. !neighborsSignificance[index]) {
  34828. continue;
  34829. }
  34830. var contextLabel = labels[neighborsSignificance[index]];
  34831. var decision = decoder.readBit(contexts, contextLabel);
  34832. if (decision) {
  34833. var sign = this.decodeSignBit(i, j, index);
  34834. coefficentsSign[index] = sign;
  34835. coefficentsMagnitude[index] = 1;
  34836. this.setNeighborsSignificance(i, j, index);
  34837. processingFlags[index] |= firstMagnitudeBitMask;
  34838. }
  34839. bitsDecoded[index]++;
  34840. processingFlags[index] |= processedMask;
  34841. }
  34842. }
  34843. }
  34844. },
  34845. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34846. var width = this.width, height = this.height;
  34847. var coefficentsMagnitude = this.coefficentsMagnitude;
  34848. var coefficentsSign = this.coefficentsSign;
  34849. var contribution, sign0, sign1, significance1;
  34850. var contextLabel, decoded;
  34851. // calculate horizontal contribution
  34852. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34853. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34854. sign1 = coefficentsSign[index + 1];
  34855. if (significance1) {
  34856. sign0 = coefficentsSign[index - 1];
  34857. contribution = 1 - sign1 - sign0;
  34858. } else {
  34859. contribution = 1 - sign1 - sign1;
  34860. }
  34861. } else if (significance1) {
  34862. sign0 = coefficentsSign[index - 1];
  34863. contribution = 1 - sign0 - sign0;
  34864. } else {
  34865. contribution = 0;
  34866. }
  34867. var horizontalContribution = 3 * contribution;
  34868. // calculate vertical contribution and combine with the horizontal
  34869. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34870. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34871. sign1 = coefficentsSign[index + width];
  34872. if (significance1) {
  34873. sign0 = coefficentsSign[index - width];
  34874. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34875. } else {
  34876. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34877. }
  34878. } else if (significance1) {
  34879. sign0 = coefficentsSign[index - width];
  34880. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34881. } else {
  34882. contribution = horizontalContribution;
  34883. }
  34884. if (contribution >= 0) {
  34885. contextLabel = 9 + contribution;
  34886. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34887. } else {
  34888. contextLabel = 9 - contribution;
  34889. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34890. }
  34891. return decoded;
  34892. },
  34893. runMagnitudeRefinementPass:
  34894. function BitModel_runMagnitudeRefinementPass() {
  34895. var decoder = this.decoder;
  34896. var width = this.width, height = this.height;
  34897. var coefficentsMagnitude = this.coefficentsMagnitude;
  34898. var neighborsSignificance = this.neighborsSignificance;
  34899. var contexts = this.contexts;
  34900. var bitsDecoded = this.bitsDecoded;
  34901. var processingFlags = this.processingFlags;
  34902. var processedMask = 1;
  34903. var firstMagnitudeBitMask = 2;
  34904. var length = width * height;
  34905. var width4 = width * 4;
  34906. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  34907. indexNext = Math.min(length, index0 + width4);
  34908. for (var j = 0; j < width; j++) {
  34909. for (var index = index0 + j; index < indexNext; index += width) {
  34910. // significant but not those that have just become
  34911. if (!coefficentsMagnitude[index] ||
  34912. (processingFlags[index] & processedMask) !== 0) {
  34913. continue;
  34914. }
  34915. var contextLabel = 16;
  34916. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  34917. processingFlags[index] ^= firstMagnitudeBitMask;
  34918. // first refinement
  34919. var significance = neighborsSignificance[index] & 127;
  34920. contextLabel = significance === 0 ? 15 : 14;
  34921. }
  34922. var bit = decoder.readBit(contexts, contextLabel);
  34923. coefficentsMagnitude[index] =
  34924. (coefficentsMagnitude[index] << 1) | bit;
  34925. bitsDecoded[index]++;
  34926. processingFlags[index] |= processedMask;
  34927. }
  34928. }
  34929. }
  34930. },
  34931. runCleanupPass: function BitModel_runCleanupPass() {
  34932. var decoder = this.decoder;
  34933. var width = this.width, height = this.height;
  34934. var neighborsSignificance = this.neighborsSignificance;
  34935. var coefficentsMagnitude = this.coefficentsMagnitude;
  34936. var coefficentsSign = this.coefficentsSign;
  34937. var contexts = this.contexts;
  34938. var labels = this.contextLabelTable;
  34939. var bitsDecoded = this.bitsDecoded;
  34940. var processingFlags = this.processingFlags;
  34941. var processedMask = 1;
  34942. var firstMagnitudeBitMask = 2;
  34943. var oneRowDown = width;
  34944. var twoRowsDown = width * 2;
  34945. var threeRowsDown = width * 3;
  34946. var iNext;
  34947. for (var i0 = 0; i0 < height; i0 = iNext) {
  34948. iNext = Math.min(i0 + 4, height);
  34949. var indexBase = i0 * width;
  34950. var checkAllEmpty = i0 + 3 < height;
  34951. for (var j = 0; j < width; j++) {
  34952. var index0 = indexBase + j;
  34953. // using the property: labels[neighborsSignificance[index]] === 0
  34954. // when neighborsSignificance[index] === 0
  34955. var allEmpty = (checkAllEmpty &&
  34956. processingFlags[index0] === 0 &&
  34957. processingFlags[index0 + oneRowDown] === 0 &&
  34958. processingFlags[index0 + twoRowsDown] === 0 &&
  34959. processingFlags[index0 + threeRowsDown] === 0 &&
  34960. neighborsSignificance[index0] === 0 &&
  34961. neighborsSignificance[index0 + oneRowDown] === 0 &&
  34962. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  34963. neighborsSignificance[index0 + threeRowsDown] === 0);
  34964. var i1 = 0, index = index0;
  34965. var i = i0, sign;
  34966. if (allEmpty) {
  34967. var hasSignificantCoefficent =
  34968. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  34969. if (!hasSignificantCoefficent) {
  34970. bitsDecoded[index0]++;
  34971. bitsDecoded[index0 + oneRowDown]++;
  34972. bitsDecoded[index0 + twoRowsDown]++;
  34973. bitsDecoded[index0 + threeRowsDown]++;
  34974. continue; // next column
  34975. }
  34976. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34977. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34978. if (i1 !== 0) {
  34979. i = i0 + i1;
  34980. index += i1 * width;
  34981. }
  34982. sign = this.decodeSignBit(i, j, index);
  34983. coefficentsSign[index] = sign;
  34984. coefficentsMagnitude[index] = 1;
  34985. this.setNeighborsSignificance(i, j, index);
  34986. processingFlags[index] |= firstMagnitudeBitMask;
  34987. index = index0;
  34988. for (var i2 = i0; i2 <= i; i2++, index += width) {
  34989. bitsDecoded[index]++;
  34990. }
  34991. i1++;
  34992. }
  34993. for (i = i0 + i1; i < iNext; i++, index += width) {
  34994. if (coefficentsMagnitude[index] ||
  34995. (processingFlags[index] & processedMask) !== 0) {
  34996. continue;
  34997. }
  34998. var contextLabel = labels[neighborsSignificance[index]];
  34999. var decision = decoder.readBit(contexts, contextLabel);
  35000. if (decision === 1) {
  35001. sign = this.decodeSignBit(i, j, index);
  35002. coefficentsSign[index] = sign;
  35003. coefficentsMagnitude[index] = 1;
  35004. this.setNeighborsSignificance(i, j, index);
  35005. processingFlags[index] |= firstMagnitudeBitMask;
  35006. }
  35007. bitsDecoded[index]++;
  35008. }
  35009. }
  35010. }
  35011. },
  35012. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35013. var decoder = this.decoder;
  35014. var contexts = this.contexts;
  35015. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35016. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35017. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35018. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35019. if (symbol !== 0xA) {
  35020. throw new Error('JPX Error: Invalid segmentation symbol');
  35021. }
  35022. }
  35023. };
  35024. return BitModel;
  35025. })();
  35026. // Section F, Discrete wavelet transformation
  35027. var Transform = (function TransformClosure() {
  35028. function Transform() {}
  35029. Transform.prototype.calculate =
  35030. function transformCalculate(subbands, u0, v0) {
  35031. var ll = subbands[0];
  35032. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35033. ll = this.iterate(ll, subbands[i], u0, v0);
  35034. }
  35035. return ll;
  35036. };
  35037. Transform.prototype.extend = function extend(buffer, offset, size) {
  35038. // Section F.3.7 extending... using max extension of 4
  35039. var i1 = offset - 1, j1 = offset + 1;
  35040. var i2 = offset + size - 2, j2 = offset + size;
  35041. buffer[i1--] = buffer[j1++];
  35042. buffer[j2++] = buffer[i2--];
  35043. buffer[i1--] = buffer[j1++];
  35044. buffer[j2++] = buffer[i2--];
  35045. buffer[i1--] = buffer[j1++];
  35046. buffer[j2++] = buffer[i2--];
  35047. buffer[i1] = buffer[j1];
  35048. buffer[j2] = buffer[i2];
  35049. };
  35050. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35051. u0, v0) {
  35052. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35053. var width = hl_lh_hh.width;
  35054. var height = hl_lh_hh.height;
  35055. var items = hl_lh_hh.items;
  35056. var i, j, k, l, u, v;
  35057. // Interleave LL according to Section F.3.3
  35058. for (k = 0, i = 0; i < llHeight; i++) {
  35059. l = i * 2 * width;
  35060. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35061. items[l] = llItems[k];
  35062. }
  35063. }
  35064. // The LL band is not needed anymore.
  35065. llItems = ll.items = null;
  35066. var bufferPadding = 4;
  35067. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35068. // Section F.3.4 HOR_SR
  35069. if (width === 1) {
  35070. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35071. if ((u0 & 1) !== 0) {
  35072. for (v = 0, k = 0; v < height; v++, k += width) {
  35073. items[k] *= 0.5;
  35074. }
  35075. }
  35076. } else {
  35077. for (v = 0, k = 0; v < height; v++, k += width) {
  35078. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35079. this.extend(rowBuffer, bufferPadding, width);
  35080. this.filter(rowBuffer, bufferPadding, width);
  35081. items.set(
  35082. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35083. k);
  35084. }
  35085. }
  35086. // Accesses to the items array can take long, because it may not fit into
  35087. // CPU cache and has to be fetched from main memory. Since subsequent
  35088. // accesses to the items array are not local when reading columns, we
  35089. // have a cache miss every time. To reduce cache misses, get up to
  35090. // 'numBuffers' items at a time and store them into the individual
  35091. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35092. var numBuffers = 16;
  35093. var colBuffers = [];
  35094. for (i = 0; i < numBuffers; i++) {
  35095. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35096. }
  35097. var b, currentBuffer = 0;
  35098. ll = bufferPadding + height;
  35099. // Section F.3.5 VER_SR
  35100. if (height === 1) {
  35101. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35102. if ((v0 & 1) !== 0) {
  35103. for (u = 0; u < width; u++) {
  35104. items[u] *= 0.5;
  35105. }
  35106. }
  35107. } else {
  35108. for (u = 0; u < width; u++) {
  35109. // if we ran out of buffers, copy several image columns at once
  35110. if (currentBuffer === 0) {
  35111. numBuffers = Math.min(width - u, numBuffers);
  35112. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35113. for (b = 0; b < numBuffers; b++) {
  35114. colBuffers[b][l] = items[k + b];
  35115. }
  35116. }
  35117. currentBuffer = numBuffers;
  35118. }
  35119. currentBuffer--;
  35120. var buffer = colBuffers[currentBuffer];
  35121. this.extend(buffer, bufferPadding, height);
  35122. this.filter(buffer, bufferPadding, height);
  35123. // If this is last buffer in this group of buffers, flush all buffers.
  35124. if (currentBuffer === 0) {
  35125. k = u - numBuffers + 1;
  35126. for (l = bufferPadding; l < ll; k += width, l++) {
  35127. for (b = 0; b < numBuffers; b++) {
  35128. items[k + b] = colBuffers[b][l];
  35129. }
  35130. }
  35131. }
  35132. }
  35133. }
  35134. return {
  35135. width: width,
  35136. height: height,
  35137. items: items
  35138. };
  35139. };
  35140. return Transform;
  35141. })();
  35142. // Section 3.8.2 Irreversible 9-7 filter
  35143. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35144. function IrreversibleTransform() {
  35145. Transform.call(this);
  35146. }
  35147. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35148. IrreversibleTransform.prototype.filter =
  35149. function irreversibleTransformFilter(x, offset, length) {
  35150. var len = length >> 1;
  35151. offset = offset | 0;
  35152. var j, n, current, next;
  35153. var alpha = -1.586134342059924;
  35154. var beta = -0.052980118572961;
  35155. var gamma = 0.882911075530934;
  35156. var delta = 0.443506852043971;
  35157. var K = 1.230174104914001;
  35158. var K_ = 1 / K;
  35159. // step 1 is combined with step 3
  35160. // step 2
  35161. j = offset - 3;
  35162. for (n = len + 4; n--; j += 2) {
  35163. x[j] *= K_;
  35164. }
  35165. // step 1 & 3
  35166. j = offset - 2;
  35167. current = delta * x[j -1];
  35168. for (n = len + 3; n--; j += 2) {
  35169. next = delta * x[j + 1];
  35170. x[j] = K * x[j] - current - next;
  35171. if (n--) {
  35172. j += 2;
  35173. current = delta * x[j + 1];
  35174. x[j] = K * x[j] - current - next;
  35175. } else {
  35176. break;
  35177. }
  35178. }
  35179. // step 4
  35180. j = offset - 1;
  35181. current = gamma * x[j - 1];
  35182. for (n = len + 2; n--; j += 2) {
  35183. next = gamma * x[j + 1];
  35184. x[j] -= current + next;
  35185. if (n--) {
  35186. j += 2;
  35187. current = gamma * x[j + 1];
  35188. x[j] -= current + next;
  35189. } else {
  35190. break;
  35191. }
  35192. }
  35193. // step 5
  35194. j = offset;
  35195. current = beta * x[j - 1];
  35196. for (n = len + 1; n--; j += 2) {
  35197. next = beta * x[j + 1];
  35198. x[j] -= current + next;
  35199. if (n--) {
  35200. j += 2;
  35201. current = beta * x[j + 1];
  35202. x[j] -= current + next;
  35203. } else {
  35204. break;
  35205. }
  35206. }
  35207. // step 6
  35208. if (len !== 0) {
  35209. j = offset + 1;
  35210. current = alpha * x[j - 1];
  35211. for (n = len; n--; j += 2) {
  35212. next = alpha * x[j + 1];
  35213. x[j] -= current + next;
  35214. if (n--) {
  35215. j += 2;
  35216. current = alpha * x[j + 1];
  35217. x[j] -= current + next;
  35218. } else {
  35219. break;
  35220. }
  35221. }
  35222. }
  35223. };
  35224. return IrreversibleTransform;
  35225. })();
  35226. // Section 3.8.1 Reversible 5-3 filter
  35227. var ReversibleTransform = (function ReversibleTransformClosure() {
  35228. function ReversibleTransform() {
  35229. Transform.call(this);
  35230. }
  35231. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35232. ReversibleTransform.prototype.filter =
  35233. function reversibleTransformFilter(x, offset, length) {
  35234. var len = length >> 1;
  35235. offset = offset | 0;
  35236. var j, n;
  35237. for (j = offset, n = len + 1; n--; j += 2) {
  35238. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35239. }
  35240. for (j = offset + 1, n = len; n--; j += 2) {
  35241. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35242. }
  35243. };
  35244. return ReversibleTransform;
  35245. })();
  35246. return JpxImage;
  35247. })();
  35248. var Jbig2Image = (function Jbig2ImageClosure() {
  35249. // Utility data structures
  35250. function ContextCache() {}
  35251. ContextCache.prototype = {
  35252. getContexts: function(id) {
  35253. if (id in this) {
  35254. return this[id];
  35255. }
  35256. return (this[id] = new Int8Array(1 << 16));
  35257. }
  35258. };
  35259. function DecodingContext(data, start, end) {
  35260. this.data = data;
  35261. this.start = start;
  35262. this.end = end;
  35263. }
  35264. DecodingContext.prototype = {
  35265. get decoder() {
  35266. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35267. return shadow(this, 'decoder', decoder);
  35268. },
  35269. get contextCache() {
  35270. var cache = new ContextCache();
  35271. return shadow(this, 'contextCache', cache);
  35272. }
  35273. };
  35274. // Annex A. Arithmetic Integer Decoding Procedure
  35275. // A.2 Procedure for decoding values
  35276. function decodeInteger(contextCache, procedure, decoder) {
  35277. var contexts = contextCache.getContexts(procedure);
  35278. var prev = 1;
  35279. function readBits(length) {
  35280. var v = 0;
  35281. for (var i = 0; i < length; i++) {
  35282. var bit = decoder.readBit(contexts, prev);
  35283. prev = (prev < 256 ? (prev << 1) | bit :
  35284. (((prev << 1) | bit) & 511) | 256);
  35285. v = (v << 1) | bit;
  35286. }
  35287. return v >>> 0;
  35288. }
  35289. var sign = readBits(1);
  35290. var value = readBits(1) ?
  35291. (readBits(1) ?
  35292. (readBits(1) ?
  35293. (readBits(1) ?
  35294. (readBits(1) ?
  35295. (readBits(32) + 4436) :
  35296. readBits(12) + 340) :
  35297. readBits(8) + 84) :
  35298. readBits(6) + 20) :
  35299. readBits(4) + 4) :
  35300. readBits(2);
  35301. return (sign === 0 ? value : (value > 0 ? -value : null));
  35302. }
  35303. // A.3 The IAID decoding procedure
  35304. function decodeIAID(contextCache, decoder, codeLength) {
  35305. var contexts = contextCache.getContexts('IAID');
  35306. var prev = 1;
  35307. for (var i = 0; i < codeLength; i++) {
  35308. var bit = decoder.readBit(contexts, prev);
  35309. prev = (prev << 1) | bit;
  35310. }
  35311. if (codeLength < 31) {
  35312. return prev & ((1 << codeLength) - 1);
  35313. }
  35314. return prev & 0x7FFFFFFF;
  35315. }
  35316. // 7.3 Segment types
  35317. var SegmentTypes = [
  35318. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35319. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35320. null, null, null, null, null, 'patternDictionary', null, null, null,
  35321. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35322. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35323. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35324. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35325. 'IntermediateGenericRefinementRegion', null,
  35326. 'ImmediateGenericRefinementRegion',
  35327. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35328. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35329. 'Tables', null, null, null, null, null, null, null, null,
  35330. 'Extension'
  35331. ];
  35332. var CodingTemplates = [
  35333. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35334. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35335. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35336. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35337. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35338. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35339. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35340. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35341. {x: -1, y: 0}],
  35342. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35343. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35344. ];
  35345. var RefinementTemplates = [
  35346. {
  35347. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35348. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35349. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35350. },
  35351. {
  35352. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35353. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35354. {x: 0, y: 1}, {x: 1, y: 1}]
  35355. }
  35356. ];
  35357. // See 6.2.5.7 Decoding the bitmap.
  35358. var ReusedContexts = [
  35359. 0x9B25, // 10011 0110010 0101
  35360. 0x0795, // 0011 110010 101
  35361. 0x00E5, // 001 11001 01
  35362. 0x0195 // 011001 0101
  35363. ];
  35364. var RefinementReusedContexts = [
  35365. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35366. 0x0008 // '0000' + '001000'
  35367. ];
  35368. function decodeBitmapTemplate0(width, height, decodingContext) {
  35369. var decoder = decodingContext.decoder;
  35370. var contexts = decodingContext.contextCache.getContexts('GB');
  35371. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35372. // ...ooooo....
  35373. // ..ooooooo... Context template for current pixel (X)
  35374. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35375. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35376. for (i = 0; i < height; i++) {
  35377. row = bitmap[i] = new Uint8Array(width);
  35378. row1 = (i < 1) ? row : bitmap[i - 1];
  35379. row2 = (i < 2) ? row : bitmap[i - 2];
  35380. // At the beginning of each row:
  35381. // Fill contextLabel with pixels that are above/right of (X)
  35382. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35383. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35384. (row1[3] << 4);
  35385. for (j = 0; j < width; j++) {
  35386. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35387. // At each pixel: Clear contextLabel pixels that are shifted
  35388. // out of the context, then add new ones.
  35389. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35390. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  35391. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  35392. }
  35393. }
  35394. return bitmap;
  35395. }
  35396. // 6.2 Generic Region Decoding Procedure
  35397. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35398. decodingContext) {
  35399. if (mmr) {
  35400. error('JBIG2 error: MMR encoding is not supported');
  35401. }
  35402. // Use optimized version for the most common case
  35403. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35404. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35405. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35406. return decodeBitmapTemplate0(width, height, decodingContext);
  35407. }
  35408. var useskip = !!skip;
  35409. var template = CodingTemplates[templateIndex].concat(at);
  35410. // Sorting is non-standard, and it is not required. But sorting increases
  35411. // the number of template bits that can be reused from the previous
  35412. // contextLabel in the main loop.
  35413. template.sort(function (a, b) {
  35414. return (a.y - b.y) || (a.x - b.x);
  35415. });
  35416. var templateLength = template.length;
  35417. var templateX = new Int8Array(templateLength);
  35418. var templateY = new Int8Array(templateLength);
  35419. var changingTemplateEntries = [];
  35420. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35421. var c, k;
  35422. for (k = 0; k < templateLength; k++) {
  35423. templateX[k] = template[k].x;
  35424. templateY[k] = template[k].y;
  35425. minX = Math.min(minX, template[k].x);
  35426. maxX = Math.max(maxX, template[k].x);
  35427. minY = Math.min(minY, template[k].y);
  35428. // Check if the template pixel appears in two consecutive context labels,
  35429. // so it can be reused. Otherwise, we add it to the list of changing
  35430. // template entries.
  35431. if (k < templateLength - 1 &&
  35432. template[k].y === template[k + 1].y &&
  35433. template[k].x === template[k + 1].x - 1) {
  35434. reuseMask |= 1 << (templateLength - 1 - k);
  35435. } else {
  35436. changingTemplateEntries.push(k);
  35437. }
  35438. }
  35439. var changingEntriesLength = changingTemplateEntries.length;
  35440. var changingTemplateX = new Int8Array(changingEntriesLength);
  35441. var changingTemplateY = new Int8Array(changingEntriesLength);
  35442. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35443. for (c = 0; c < changingEntriesLength; c++) {
  35444. k = changingTemplateEntries[c];
  35445. changingTemplateX[c] = template[k].x;
  35446. changingTemplateY[c] = template[k].y;
  35447. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35448. }
  35449. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35450. var sbb_left = -minX;
  35451. var sbb_top = -minY;
  35452. var sbb_right = width - maxX;
  35453. var pseudoPixelContext = ReusedContexts[templateIndex];
  35454. var row = new Uint8Array(width);
  35455. var bitmap = [];
  35456. var decoder = decodingContext.decoder;
  35457. var contexts = decodingContext.contextCache.getContexts('GB');
  35458. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35459. for (var i = 0; i < height; i++) {
  35460. if (prediction) {
  35461. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35462. ltp ^= sltp;
  35463. if (ltp) {
  35464. bitmap.push(row); // duplicate previous row
  35465. continue;
  35466. }
  35467. }
  35468. row = new Uint8Array(row);
  35469. bitmap.push(row);
  35470. for (j = 0; j < width; j++) {
  35471. if (useskip && skip[i][j]) {
  35472. row[j] = 0;
  35473. continue;
  35474. }
  35475. // Are we in the middle of a scanline, so we can reuse contextLabel
  35476. // bits?
  35477. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35478. // If yes, we can just shift the bits that are reusable and only
  35479. // fetch the remaining ones.
  35480. contextLabel = (contextLabel << 1) & reuseMask;
  35481. for (k = 0; k < changingEntriesLength; k++) {
  35482. i0 = i + changingTemplateY[k];
  35483. j0 = j + changingTemplateX[k];
  35484. bit = bitmap[i0][j0];
  35485. if (bit) {
  35486. bit = changingTemplateBit[k];
  35487. contextLabel |= bit;
  35488. }
  35489. }
  35490. } else {
  35491. // compute the contextLabel from scratch
  35492. contextLabel = 0;
  35493. shift = templateLength - 1;
  35494. for (k = 0; k < templateLength; k++, shift--) {
  35495. j0 = j + templateX[k];
  35496. if (j0 >= 0 && j0 < width) {
  35497. i0 = i + templateY[k];
  35498. if (i0 >= 0) {
  35499. bit = bitmap[i0][j0];
  35500. if (bit) {
  35501. contextLabel |= bit << shift;
  35502. }
  35503. }
  35504. }
  35505. }
  35506. }
  35507. var pixel = decoder.readBit(contexts, contextLabel);
  35508. row[j] = pixel;
  35509. }
  35510. }
  35511. return bitmap;
  35512. }
  35513. // 6.3.2 Generic Refinement Region Decoding Procedure
  35514. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35515. offsetX, offsetY, prediction, at,
  35516. decodingContext) {
  35517. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35518. if (templateIndex === 0) {
  35519. codingTemplate = codingTemplate.concat([at[0]]);
  35520. }
  35521. var codingTemplateLength = codingTemplate.length;
  35522. var codingTemplateX = new Int32Array(codingTemplateLength);
  35523. var codingTemplateY = new Int32Array(codingTemplateLength);
  35524. var k;
  35525. for (k = 0; k < codingTemplateLength; k++) {
  35526. codingTemplateX[k] = codingTemplate[k].x;
  35527. codingTemplateY[k] = codingTemplate[k].y;
  35528. }
  35529. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35530. if (templateIndex === 0) {
  35531. referenceTemplate = referenceTemplate.concat([at[1]]);
  35532. }
  35533. var referenceTemplateLength = referenceTemplate.length;
  35534. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35535. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35536. for (k = 0; k < referenceTemplateLength; k++) {
  35537. referenceTemplateX[k] = referenceTemplate[k].x;
  35538. referenceTemplateY[k] = referenceTemplate[k].y;
  35539. }
  35540. var referenceWidth = referenceBitmap[0].length;
  35541. var referenceHeight = referenceBitmap.length;
  35542. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35543. var bitmap = [];
  35544. var decoder = decodingContext.decoder;
  35545. var contexts = decodingContext.contextCache.getContexts('GR');
  35546. var ltp = 0;
  35547. for (var i = 0; i < height; i++) {
  35548. if (prediction) {
  35549. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35550. ltp ^= sltp;
  35551. if (ltp) {
  35552. error('JBIG2 error: prediction is not supported');
  35553. }
  35554. }
  35555. var row = new Uint8Array(width);
  35556. bitmap.push(row);
  35557. for (var j = 0; j < width; j++) {
  35558. var i0, j0;
  35559. var contextLabel = 0;
  35560. for (k = 0; k < codingTemplateLength; k++) {
  35561. i0 = i + codingTemplateY[k];
  35562. j0 = j + codingTemplateX[k];
  35563. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35564. contextLabel <<= 1; // out of bound pixel
  35565. } else {
  35566. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35567. }
  35568. }
  35569. for (k = 0; k < referenceTemplateLength; k++) {
  35570. i0 = i + referenceTemplateY[k] + offsetY;
  35571. j0 = j + referenceTemplateX[k] + offsetX;
  35572. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35573. j0 >= referenceWidth) {
  35574. contextLabel <<= 1; // out of bound pixel
  35575. } else {
  35576. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35577. }
  35578. }
  35579. var pixel = decoder.readBit(contexts, contextLabel);
  35580. row[j] = pixel;
  35581. }
  35582. }
  35583. return bitmap;
  35584. }
  35585. // 6.5.5 Decoding the symbol dictionary
  35586. function decodeSymbolDictionary(huffman, refinement, symbols,
  35587. numberOfNewSymbols, numberOfExportedSymbols,
  35588. huffmanTables, templateIndex, at,
  35589. refinementTemplateIndex, refinementAt,
  35590. decodingContext) {
  35591. if (huffman) {
  35592. error('JBIG2 error: huffman is not supported');
  35593. }
  35594. var newSymbols = [];
  35595. var currentHeight = 0;
  35596. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35597. var decoder = decodingContext.decoder;
  35598. var contextCache = decodingContext.contextCache;
  35599. while (newSymbols.length < numberOfNewSymbols) {
  35600. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35601. currentHeight += deltaHeight;
  35602. var currentWidth = 0;
  35603. var totalWidth = 0;
  35604. while (true) {
  35605. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35606. if (deltaWidth === null) {
  35607. break; // OOB
  35608. }
  35609. currentWidth += deltaWidth;
  35610. totalWidth += currentWidth;
  35611. var bitmap;
  35612. if (refinement) {
  35613. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35614. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35615. if (numberOfInstances > 1) {
  35616. bitmap = decodeTextRegion(huffman, refinement,
  35617. currentWidth, currentHeight, 0,
  35618. numberOfInstances, 1, //strip size
  35619. symbols.concat(newSymbols),
  35620. symbolCodeLength,
  35621. 0, //transposed
  35622. 0, //ds offset
  35623. 1, //top left 7.4.3.1.1
  35624. 0, //OR operator
  35625. huffmanTables,
  35626. refinementTemplateIndex, refinementAt,
  35627. decodingContext);
  35628. } else {
  35629. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35630. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35631. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35632. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35633. newSymbols[symbolId - symbols.length]);
  35634. bitmap = decodeRefinement(currentWidth, currentHeight,
  35635. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35636. decodingContext);
  35637. }
  35638. } else {
  35639. // 6.5.8.1 Direct-coded symbol bitmap
  35640. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35641. templateIndex, false, null, at, decodingContext);
  35642. }
  35643. newSymbols.push(bitmap);
  35644. }
  35645. }
  35646. // 6.5.10 Exported symbols
  35647. var exportedSymbols = [];
  35648. var flags = [], currentFlag = false;
  35649. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35650. while (flags.length < totalSymbolsLength) {
  35651. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35652. while (runLength--) {
  35653. flags.push(currentFlag);
  35654. }
  35655. currentFlag = !currentFlag;
  35656. }
  35657. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35658. if (flags[i]) {
  35659. exportedSymbols.push(symbols[i]);
  35660. }
  35661. }
  35662. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35663. if (flags[i]) {
  35664. exportedSymbols.push(newSymbols[j]);
  35665. }
  35666. }
  35667. return exportedSymbols;
  35668. }
  35669. function decodeTextRegion(huffman, refinement, width, height,
  35670. defaultPixelValue, numberOfSymbolInstances,
  35671. stripSize, inputSymbols, symbolCodeLength,
  35672. transposed, dsOffset, referenceCorner,
  35673. combinationOperator, huffmanTables,
  35674. refinementTemplateIndex, refinementAt,
  35675. decodingContext) {
  35676. if (huffman) {
  35677. error('JBIG2 error: huffman is not supported');
  35678. }
  35679. // Prepare bitmap
  35680. var bitmap = [];
  35681. var i, row;
  35682. for (i = 0; i < height; i++) {
  35683. row = new Uint8Array(width);
  35684. if (defaultPixelValue) {
  35685. for (var j = 0; j < width; j++) {
  35686. row[j] = defaultPixelValue;
  35687. }
  35688. }
  35689. bitmap.push(row);
  35690. }
  35691. var decoder = decodingContext.decoder;
  35692. var contextCache = decodingContext.contextCache;
  35693. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35694. var firstS = 0;
  35695. i = 0;
  35696. while (i < numberOfSymbolInstances) {
  35697. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35698. stripT += deltaT;
  35699. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35700. firstS += deltaFirstS;
  35701. var currentS = firstS;
  35702. do {
  35703. var currentT = (stripSize === 1 ? 0 :
  35704. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35705. var t = stripSize * stripT + currentT;
  35706. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35707. var applyRefinement = (refinement &&
  35708. decodeInteger(contextCache, 'IARI', decoder));
  35709. var symbolBitmap = inputSymbols[symbolId];
  35710. var symbolWidth = symbolBitmap[0].length;
  35711. var symbolHeight = symbolBitmap.length;
  35712. if (applyRefinement) {
  35713. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35714. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35715. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35716. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35717. symbolWidth += rdw;
  35718. symbolHeight += rdh;
  35719. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35720. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35721. (rdh >> 1) + rdy, false, refinementAt,
  35722. decodingContext);
  35723. }
  35724. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35725. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35726. var s2, t2, symbolRow;
  35727. if (transposed) {
  35728. // Place Symbol Bitmap from T1,S1
  35729. for (s2 = 0; s2 < symbolHeight; s2++) {
  35730. row = bitmap[offsetS + s2];
  35731. if (!row) {
  35732. continue;
  35733. }
  35734. symbolRow = symbolBitmap[s2];
  35735. // To ignore Parts of Symbol bitmap which goes
  35736. // outside bitmap region
  35737. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35738. switch (combinationOperator) {
  35739. case 0: // OR
  35740. for (t2 = 0; t2 < maxWidth; t2++) {
  35741. row[offsetT + t2] |= symbolRow[t2];
  35742. }
  35743. break;
  35744. case 2: // XOR
  35745. for (t2 = 0; t2 < maxWidth; t2++) {
  35746. row[offsetT + t2] ^= symbolRow[t2];
  35747. }
  35748. break;
  35749. default:
  35750. error('JBIG2 error: operator ' + combinationOperator +
  35751. ' is not supported');
  35752. }
  35753. }
  35754. currentS += symbolHeight - 1;
  35755. } else {
  35756. for (t2 = 0; t2 < symbolHeight; t2++) {
  35757. row = bitmap[offsetT + t2];
  35758. if (!row) {
  35759. continue;
  35760. }
  35761. symbolRow = symbolBitmap[t2];
  35762. switch (combinationOperator) {
  35763. case 0: // OR
  35764. for (s2 = 0; s2 < symbolWidth; s2++) {
  35765. row[offsetS + s2] |= symbolRow[s2];
  35766. }
  35767. break;
  35768. case 2: // XOR
  35769. for (s2 = 0; s2 < symbolWidth; s2++) {
  35770. row[offsetS + s2] ^= symbolRow[s2];
  35771. }
  35772. break;
  35773. default:
  35774. error('JBIG2 error: operator ' + combinationOperator +
  35775. ' is not supported');
  35776. }
  35777. }
  35778. currentS += symbolWidth - 1;
  35779. }
  35780. i++;
  35781. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35782. if (deltaS === null) {
  35783. break; // OOB
  35784. }
  35785. currentS += deltaS + dsOffset;
  35786. } while (true);
  35787. }
  35788. return bitmap;
  35789. }
  35790. function readSegmentHeader(data, start) {
  35791. var segmentHeader = {};
  35792. segmentHeader.number = readUint32(data, start);
  35793. var flags = data[start + 4];
  35794. var segmentType = flags & 0x3F;
  35795. if (!SegmentTypes[segmentType]) {
  35796. error('JBIG2 error: invalid segment type: ' + segmentType);
  35797. }
  35798. segmentHeader.type = segmentType;
  35799. segmentHeader.typeName = SegmentTypes[segmentType];
  35800. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35801. var pageAssociationFieldSize = !!(flags & 0x40);
  35802. var referredFlags = data[start + 5];
  35803. var referredToCount = (referredFlags >> 5) & 7;
  35804. var retainBits = [referredFlags & 31];
  35805. var position = start + 6;
  35806. if (referredFlags === 7) {
  35807. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35808. position += 3;
  35809. var bytes = (referredToCount + 7) >> 3;
  35810. retainBits[0] = data[position++];
  35811. while (--bytes > 0) {
  35812. retainBits.push(data[position++]);
  35813. }
  35814. } else if (referredFlags === 5 || referredFlags === 6) {
  35815. error('JBIG2 error: invalid referred-to flags');
  35816. }
  35817. segmentHeader.retainBits = retainBits;
  35818. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35819. (segmentHeader.number <= 65536 ? 2 : 4));
  35820. var referredTo = [];
  35821. var i, ii;
  35822. for (i = 0; i < referredToCount; i++) {
  35823. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35824. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35825. readUint32(data, position)));
  35826. referredTo.push(number);
  35827. position += referredToSegmentNumberSize;
  35828. }
  35829. segmentHeader.referredTo = referredTo;
  35830. if (!pageAssociationFieldSize) {
  35831. segmentHeader.pageAssociation = data[position++];
  35832. } else {
  35833. segmentHeader.pageAssociation = readUint32(data, position);
  35834. position += 4;
  35835. }
  35836. segmentHeader.length = readUint32(data, position);
  35837. position += 4;
  35838. if (segmentHeader.length === 0xFFFFFFFF) {
  35839. // 7.2.7 Segment data length, unknown segment length
  35840. if (segmentType === 38) { // ImmediateGenericRegion
  35841. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35842. var genericRegionSegmentFlags = data[position +
  35843. RegionSegmentInformationFieldLength];
  35844. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35845. // searching for the segment end
  35846. var searchPatternLength = 6;
  35847. var searchPattern = new Uint8Array(searchPatternLength);
  35848. if (!genericRegionMmr) {
  35849. searchPattern[0] = 0xFF;
  35850. searchPattern[1] = 0xAC;
  35851. }
  35852. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35853. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35854. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35855. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35856. for (i = position, ii = data.length; i < ii; i++) {
  35857. var j = 0;
  35858. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35859. j++;
  35860. }
  35861. if (j === searchPatternLength) {
  35862. segmentHeader.length = i + searchPatternLength;
  35863. break;
  35864. }
  35865. }
  35866. if (segmentHeader.length === 0xFFFFFFFF) {
  35867. error('JBIG2 error: segment end was not found');
  35868. }
  35869. } else {
  35870. error('JBIG2 error: invalid unknown segment length');
  35871. }
  35872. }
  35873. segmentHeader.headerEnd = position;
  35874. return segmentHeader;
  35875. }
  35876. function readSegments(header, data, start, end) {
  35877. var segments = [];
  35878. var position = start;
  35879. while (position < end) {
  35880. var segmentHeader = readSegmentHeader(data, position);
  35881. position = segmentHeader.headerEnd;
  35882. var segment = {
  35883. header: segmentHeader,
  35884. data: data
  35885. };
  35886. if (!header.randomAccess) {
  35887. segment.start = position;
  35888. position += segmentHeader.length;
  35889. segment.end = position;
  35890. }
  35891. segments.push(segment);
  35892. if (segmentHeader.type === 51) {
  35893. break; // end of file is found
  35894. }
  35895. }
  35896. if (header.randomAccess) {
  35897. for (var i = 0, ii = segments.length; i < ii; i++) {
  35898. segments[i].start = position;
  35899. position += segments[i].header.length;
  35900. segments[i].end = position;
  35901. }
  35902. }
  35903. return segments;
  35904. }
  35905. // 7.4.1 Region segment information field
  35906. function readRegionSegmentInformation(data, start) {
  35907. return {
  35908. width: readUint32(data, start),
  35909. height: readUint32(data, start + 4),
  35910. x: readUint32(data, start + 8),
  35911. y: readUint32(data, start + 12),
  35912. combinationOperator: data[start + 16] & 7
  35913. };
  35914. }
  35915. var RegionSegmentInformationFieldLength = 17;
  35916. function processSegment(segment, visitor) {
  35917. var header = segment.header;
  35918. var data = segment.data, position = segment.start, end = segment.end;
  35919. var args, at, i, atLength;
  35920. switch (header.type) {
  35921. case 0: // SymbolDictionary
  35922. // 7.4.2 Symbol dictionary segment syntax
  35923. var dictionary = {};
  35924. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  35925. dictionary.huffman = !!(dictionaryFlags & 1);
  35926. dictionary.refinement = !!(dictionaryFlags & 2);
  35927. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  35928. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  35929. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  35930. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  35931. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  35932. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  35933. dictionary.template = (dictionaryFlags >> 10) & 3;
  35934. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  35935. position += 2;
  35936. if (!dictionary.huffman) {
  35937. atLength = dictionary.template === 0 ? 4 : 1;
  35938. at = [];
  35939. for (i = 0; i < atLength; i++) {
  35940. at.push({
  35941. x: readInt8(data, position),
  35942. y: readInt8(data, position + 1)
  35943. });
  35944. position += 2;
  35945. }
  35946. dictionary.at = at;
  35947. }
  35948. if (dictionary.refinement && !dictionary.refinementTemplate) {
  35949. at = [];
  35950. for (i = 0; i < 2; i++) {
  35951. at.push({
  35952. x: readInt8(data, position),
  35953. y: readInt8(data, position + 1)
  35954. });
  35955. position += 2;
  35956. }
  35957. dictionary.refinementAt = at;
  35958. }
  35959. dictionary.numberOfExportedSymbols = readUint32(data, position);
  35960. position += 4;
  35961. dictionary.numberOfNewSymbols = readUint32(data, position);
  35962. position += 4;
  35963. args = [dictionary, header.number, header.referredTo,
  35964. data, position, end];
  35965. break;
  35966. case 6: // ImmediateTextRegion
  35967. case 7: // ImmediateLosslessTextRegion
  35968. var textRegion = {};
  35969. textRegion.info = readRegionSegmentInformation(data, position);
  35970. position += RegionSegmentInformationFieldLength;
  35971. var textRegionSegmentFlags = readUint16(data, position);
  35972. position += 2;
  35973. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  35974. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  35975. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  35976. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  35977. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  35978. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  35979. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  35980. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  35981. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  35982. if (textRegion.huffman) {
  35983. var textRegionHuffmanFlags = readUint16(data, position);
  35984. position += 2;
  35985. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  35986. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  35987. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  35988. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  35989. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  35990. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  35991. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  35992. textRegion.huffmanRefinementSizeSelector =
  35993. !!(textRegionHuffmanFlags & 14);
  35994. }
  35995. if (textRegion.refinement && !textRegion.refinementTemplate) {
  35996. at = [];
  35997. for (i = 0; i < 2; i++) {
  35998. at.push({
  35999. x: readInt8(data, position),
  36000. y: readInt8(data, position + 1)
  36001. });
  36002. position += 2;
  36003. }
  36004. textRegion.refinementAt = at;
  36005. }
  36006. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36007. position += 4;
  36008. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36009. if (textRegion.huffman) {
  36010. error('JBIG2 error: huffman is not supported');
  36011. }
  36012. args = [textRegion, header.referredTo, data, position, end];
  36013. break;
  36014. case 38: // ImmediateGenericRegion
  36015. case 39: // ImmediateLosslessGenericRegion
  36016. var genericRegion = {};
  36017. genericRegion.info = readRegionSegmentInformation(data, position);
  36018. position += RegionSegmentInformationFieldLength;
  36019. var genericRegionSegmentFlags = data[position++];
  36020. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36021. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36022. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36023. if (!genericRegion.mmr) {
  36024. atLength = genericRegion.template === 0 ? 4 : 1;
  36025. at = [];
  36026. for (i = 0; i < atLength; i++) {
  36027. at.push({
  36028. x: readInt8(data, position),
  36029. y: readInt8(data, position + 1)
  36030. });
  36031. position += 2;
  36032. }
  36033. genericRegion.at = at;
  36034. }
  36035. args = [genericRegion, data, position, end];
  36036. break;
  36037. case 48: // PageInformation
  36038. var pageInfo = {
  36039. width: readUint32(data, position),
  36040. height: readUint32(data, position + 4),
  36041. resolutionX: readUint32(data, position + 8),
  36042. resolutionY: readUint32(data, position + 12)
  36043. };
  36044. if (pageInfo.height === 0xFFFFFFFF) {
  36045. delete pageInfo.height;
  36046. }
  36047. var pageSegmentFlags = data[position + 16];
  36048. var pageStripingInformatiom = readUint16(data, position + 17);
  36049. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36050. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36051. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36052. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36053. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36054. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36055. args = [pageInfo];
  36056. break;
  36057. case 49: // EndOfPage
  36058. break;
  36059. case 50: // EndOfStripe
  36060. break;
  36061. case 51: // EndOfFile
  36062. break;
  36063. case 62: // 7.4.15 defines 2 extension types which
  36064. // are comments and can be ignored.
  36065. break;
  36066. default:
  36067. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36068. header.type + ') is not implemented');
  36069. }
  36070. var callbackName = 'on' + header.typeName;
  36071. if (callbackName in visitor) {
  36072. visitor[callbackName].apply(visitor, args);
  36073. }
  36074. }
  36075. function processSegments(segments, visitor) {
  36076. for (var i = 0, ii = segments.length; i < ii; i++) {
  36077. processSegment(segments[i], visitor);
  36078. }
  36079. }
  36080. function parseJbig2(data, start, end) {
  36081. var position = start;
  36082. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36083. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36084. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36085. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36086. error('JBIG2 error: invalid header');
  36087. }
  36088. var header = {};
  36089. position += 8;
  36090. var flags = data[position++];
  36091. header.randomAccess = !(flags & 1);
  36092. if (!(flags & 2)) {
  36093. header.numberOfPages = readUint32(data, position);
  36094. position += 4;
  36095. }
  36096. var segments = readSegments(header, data, position, end);
  36097. error('Not implemented');
  36098. // processSegments(segments, new SimpleSegmentVisitor());
  36099. }
  36100. function parseJbig2Chunks(chunks) {
  36101. var visitor = new SimpleSegmentVisitor();
  36102. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36103. var chunk = chunks[i];
  36104. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36105. processSegments(segments, visitor);
  36106. }
  36107. return visitor.buffer;
  36108. }
  36109. function SimpleSegmentVisitor() {}
  36110. SimpleSegmentVisitor.prototype = {
  36111. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36112. this.currentPageInfo = info;
  36113. var rowSize = (info.width + 7) >> 3;
  36114. var buffer = new Uint8Array(rowSize * info.height);
  36115. // The contents of ArrayBuffers are initialized to 0.
  36116. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36117. if (info.defaultPixelValue) {
  36118. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36119. buffer[i] = 0xFF;
  36120. }
  36121. }
  36122. this.buffer = buffer;
  36123. },
  36124. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36125. var pageInfo = this.currentPageInfo;
  36126. var width = regionInfo.width, height = regionInfo.height;
  36127. var rowSize = (pageInfo.width + 7) >> 3;
  36128. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36129. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36130. var buffer = this.buffer;
  36131. var mask0 = 128 >> (regionInfo.x & 7);
  36132. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36133. var i, j, mask, offset;
  36134. switch (combinationOperator) {
  36135. case 0: // OR
  36136. for (i = 0; i < height; i++) {
  36137. mask = mask0;
  36138. offset = offset0;
  36139. for (j = 0; j < width; j++) {
  36140. if (bitmap[i][j]) {
  36141. buffer[offset] |= mask;
  36142. }
  36143. mask >>= 1;
  36144. if (!mask) {
  36145. mask = 128;
  36146. offset++;
  36147. }
  36148. }
  36149. offset0 += rowSize;
  36150. }
  36151. break;
  36152. case 2: // XOR
  36153. for (i = 0; i < height; i++) {
  36154. mask = mask0;
  36155. offset = offset0;
  36156. for (j = 0; j < width; j++) {
  36157. if (bitmap[i][j]) {
  36158. buffer[offset] ^= mask;
  36159. }
  36160. mask >>= 1;
  36161. if (!mask) {
  36162. mask = 128;
  36163. offset++;
  36164. }
  36165. }
  36166. offset0 += rowSize;
  36167. }
  36168. break;
  36169. default:
  36170. error('JBIG2 error: operator ' + combinationOperator +
  36171. ' is not supported');
  36172. }
  36173. },
  36174. onImmediateGenericRegion:
  36175. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36176. start, end) {
  36177. var regionInfo = region.info;
  36178. var decodingContext = new DecodingContext(data, start, end);
  36179. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36180. region.template, region.prediction, null,
  36181. region.at, decodingContext);
  36182. this.drawBitmap(regionInfo, bitmap);
  36183. },
  36184. onImmediateLosslessGenericRegion:
  36185. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36186. this.onImmediateGenericRegion.apply(this, arguments);
  36187. },
  36188. onSymbolDictionary:
  36189. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36190. currentSegment,
  36191. referredSegments,
  36192. data, start, end) {
  36193. var huffmanTables;
  36194. if (dictionary.huffman) {
  36195. error('JBIG2 error: huffman is not supported');
  36196. }
  36197. // Combines exported symbols from all referred segments
  36198. var symbols = this.symbols;
  36199. if (!symbols) {
  36200. this.symbols = symbols = {};
  36201. }
  36202. var inputSymbols = [];
  36203. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36204. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36205. }
  36206. var decodingContext = new DecodingContext(data, start, end);
  36207. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36208. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36209. dictionary.numberOfExportedSymbols, huffmanTables,
  36210. dictionary.template, dictionary.at,
  36211. dictionary.refinementTemplate, dictionary.refinementAt,
  36212. decodingContext);
  36213. },
  36214. onImmediateTextRegion:
  36215. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36216. referredSegments,
  36217. data, start, end) {
  36218. var regionInfo = region.info;
  36219. var huffmanTables;
  36220. // Combines exported symbols from all referred segments
  36221. var symbols = this.symbols;
  36222. var inputSymbols = [];
  36223. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36224. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36225. }
  36226. var symbolCodeLength = log2(inputSymbols.length);
  36227. var decodingContext = new DecodingContext(data, start, end);
  36228. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36229. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36230. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36231. symbolCodeLength, region.transposed, region.dsOffset,
  36232. region.referenceCorner, region.combinationOperator, huffmanTables,
  36233. region.refinementTemplate, region.refinementAt, decodingContext);
  36234. this.drawBitmap(regionInfo, bitmap);
  36235. },
  36236. onImmediateLosslessTextRegion:
  36237. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36238. this.onImmediateTextRegion.apply(this, arguments);
  36239. }
  36240. };
  36241. function Jbig2Image() {}
  36242. Jbig2Image.prototype = {
  36243. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36244. return parseJbig2Chunks(chunks);
  36245. }
  36246. };
  36247. return Jbig2Image;
  36248. })();
  36249. var bidi = PDFJS.bidi = (function bidiClosure() {
  36250. // Character types for symbols from 0000 to 00FF.
  36251. var baseTypes = [
  36252. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36253. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36254. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36255. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36256. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36257. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36258. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36259. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36260. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36261. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36262. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36263. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36264. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36265. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36266. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36267. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36268. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36269. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36270. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36271. ];
  36272. // Character types for symbols from 0600 to 06FF
  36273. var arabicTypes = [
  36274. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36275. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36276. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36277. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36278. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36279. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36280. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36281. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36282. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36283. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36284. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36285. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36286. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36287. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36288. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36289. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36290. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36291. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36292. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36293. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36294. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36295. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36296. ];
  36297. function isOdd(i) {
  36298. return (i & 1) !== 0;
  36299. }
  36300. function isEven(i) {
  36301. return (i & 1) === 0;
  36302. }
  36303. function findUnequal(arr, start, value) {
  36304. for (var j = start, jj = arr.length; j < jj; ++j) {
  36305. if (arr[j] !== value) {
  36306. return j;
  36307. }
  36308. }
  36309. return j;
  36310. }
  36311. function setValues(arr, start, end, value) {
  36312. for (var j = start; j < end; ++j) {
  36313. arr[j] = value;
  36314. }
  36315. }
  36316. function reverseValues(arr, start, end) {
  36317. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36318. var temp = arr[i];
  36319. arr[i] = arr[j];
  36320. arr[j] = temp;
  36321. }
  36322. }
  36323. function createBidiText(str, isLTR, vertical) {
  36324. return {
  36325. str: str,
  36326. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36327. };
  36328. }
  36329. // These are used in bidi(), which is called frequently. We re-use them on
  36330. // each call to avoid unnecessary allocations.
  36331. var chars = [];
  36332. var types = [];
  36333. function bidi(str, startLevel, vertical) {
  36334. var isLTR = true;
  36335. var strLength = str.length;
  36336. if (strLength === 0 || vertical) {
  36337. return createBidiText(str, isLTR, vertical);
  36338. }
  36339. // Get types and fill arrays
  36340. chars.length = strLength;
  36341. types.length = strLength;
  36342. var numBidi = 0;
  36343. var i, ii;
  36344. for (i = 0; i < strLength; ++i) {
  36345. chars[i] = str.charAt(i);
  36346. var charCode = str.charCodeAt(i);
  36347. var charType = 'L';
  36348. if (charCode <= 0x00ff) {
  36349. charType = baseTypes[charCode];
  36350. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36351. charType = 'R';
  36352. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36353. charType = arabicTypes[charCode & 0xff];
  36354. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36355. charType = 'AL';
  36356. }
  36357. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36358. numBidi++;
  36359. }
  36360. types[i] = charType;
  36361. }
  36362. // Detect the bidi method
  36363. // - If there are no rtl characters then no bidi needed
  36364. // - If less than 30% chars are rtl then string is primarily ltr
  36365. // - If more than 30% chars are rtl then string is primarily rtl
  36366. if (numBidi === 0) {
  36367. isLTR = true;
  36368. return createBidiText(str, isLTR);
  36369. }
  36370. if (startLevel === -1) {
  36371. if ((strLength / numBidi) < 0.3) {
  36372. isLTR = true;
  36373. startLevel = 0;
  36374. } else {
  36375. isLTR = false;
  36376. startLevel = 1;
  36377. }
  36378. }
  36379. var levels = [];
  36380. for (i = 0; i < strLength; ++i) {
  36381. levels[i] = startLevel;
  36382. }
  36383. /*
  36384. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36385. */
  36386. var e = (isOdd(startLevel) ? 'R' : 'L');
  36387. var sor = e;
  36388. var eor = sor;
  36389. /*
  36390. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36391. type of the NSM to the type of the previous character. If the NSM is at the
  36392. start of the level run, it will get the type of sor.
  36393. */
  36394. var lastType = sor;
  36395. for (i = 0; i < strLength; ++i) {
  36396. if (types[i] === 'NSM') {
  36397. types[i] = lastType;
  36398. } else {
  36399. lastType = types[i];
  36400. }
  36401. }
  36402. /*
  36403. W2. Search backwards from each instance of a European number until the
  36404. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36405. the type of the European number to Arabic number.
  36406. */
  36407. lastType = sor;
  36408. var t;
  36409. for (i = 0; i < strLength; ++i) {
  36410. t = types[i];
  36411. if (t === 'EN') {
  36412. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36413. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36414. lastType = t;
  36415. }
  36416. }
  36417. /*
  36418. W3. Change all ALs to R.
  36419. */
  36420. for (i = 0; i < strLength; ++i) {
  36421. t = types[i];
  36422. if (t === 'AL') {
  36423. types[i] = 'R';
  36424. }
  36425. }
  36426. /*
  36427. W4. A single European separator between two European numbers changes to a
  36428. European number. A single common separator between two numbers of the same
  36429. type changes to that type:
  36430. */
  36431. for (i = 1; i < strLength - 1; ++i) {
  36432. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36433. types[i] = 'EN';
  36434. }
  36435. if (types[i] === 'CS' &&
  36436. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36437. types[i + 1] === types[i - 1]) {
  36438. types[i] = types[i - 1];
  36439. }
  36440. }
  36441. /*
  36442. W5. A sequence of European terminators adjacent to European numbers changes
  36443. to all European numbers:
  36444. */
  36445. for (i = 0; i < strLength; ++i) {
  36446. if (types[i] === 'EN') {
  36447. // do before
  36448. var j;
  36449. for (j = i - 1; j >= 0; --j) {
  36450. if (types[j] !== 'ET') {
  36451. break;
  36452. }
  36453. types[j] = 'EN';
  36454. }
  36455. // do after
  36456. for (j = i + 1; j < strLength; --j) {
  36457. if (types[j] !== 'ET') {
  36458. break;
  36459. }
  36460. types[j] = 'EN';
  36461. }
  36462. }
  36463. }
  36464. /*
  36465. W6. Otherwise, separators and terminators change to Other Neutral:
  36466. */
  36467. for (i = 0; i < strLength; ++i) {
  36468. t = types[i];
  36469. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36470. types[i] = 'ON';
  36471. }
  36472. }
  36473. /*
  36474. W7. Search backwards from each instance of a European number until the
  36475. first strong type (R, L, or sor) is found. If an L is found, then change
  36476. the type of the European number to L.
  36477. */
  36478. lastType = sor;
  36479. for (i = 0; i < strLength; ++i) {
  36480. t = types[i];
  36481. if (t === 'EN') {
  36482. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36483. } else if (t === 'R' || t === 'L') {
  36484. lastType = t;
  36485. }
  36486. }
  36487. /*
  36488. N1. A sequence of neutrals takes the direction of the surrounding strong
  36489. text if the text on both sides has the same direction. European and Arabic
  36490. numbers are treated as though they were R. Start-of-level-run (sor) and
  36491. end-of-level-run (eor) are used at level run boundaries.
  36492. */
  36493. for (i = 0; i < strLength; ++i) {
  36494. if (types[i] === 'ON') {
  36495. var end = findUnequal(types, i + 1, 'ON');
  36496. var before = sor;
  36497. if (i > 0) {
  36498. before = types[i - 1];
  36499. }
  36500. var after = eor;
  36501. if (end + 1 < strLength) {
  36502. after = types[end + 1];
  36503. }
  36504. if (before !== 'L') {
  36505. before = 'R';
  36506. }
  36507. if (after !== 'L') {
  36508. after = 'R';
  36509. }
  36510. if (before === after) {
  36511. setValues(types, i, end, before);
  36512. }
  36513. i = end - 1; // reset to end (-1 so next iteration is ok)
  36514. }
  36515. }
  36516. /*
  36517. N2. Any remaining neutrals take the embedding direction.
  36518. */
  36519. for (i = 0; i < strLength; ++i) {
  36520. if (types[i] === 'ON') {
  36521. types[i] = e;
  36522. }
  36523. }
  36524. /*
  36525. I1. For all characters with an even (left-to-right) embedding direction,
  36526. those of type R go up one level and those of type AN or EN go up two
  36527. levels.
  36528. I2. For all characters with an odd (right-to-left) embedding direction,
  36529. those of type L, EN or AN go up one level.
  36530. */
  36531. for (i = 0; i < strLength; ++i) {
  36532. t = types[i];
  36533. if (isEven(levels[i])) {
  36534. if (t === 'R') {
  36535. levels[i] += 1;
  36536. } else if (t === 'AN' || t === 'EN') {
  36537. levels[i] += 2;
  36538. }
  36539. } else { // isOdd
  36540. if (t === 'L' || t === 'AN' || t === 'EN') {
  36541. levels[i] += 1;
  36542. }
  36543. }
  36544. }
  36545. /*
  36546. L1. On each line, reset the embedding level of the following characters to
  36547. the paragraph embedding level:
  36548. segment separators,
  36549. paragraph separators,
  36550. any sequence of whitespace characters preceding a segment separator or
  36551. paragraph separator, and any sequence of white space characters at the end
  36552. of the line.
  36553. */
  36554. // don't bother as text is only single line
  36555. /*
  36556. L2. From the highest level found in the text to the lowest odd level on
  36557. each line, reverse any contiguous sequence of characters that are at that
  36558. level or higher.
  36559. */
  36560. // find highest level & lowest odd level
  36561. var highestLevel = -1;
  36562. var lowestOddLevel = 99;
  36563. var level;
  36564. for (i = 0, ii = levels.length; i < ii; ++i) {
  36565. level = levels[i];
  36566. if (highestLevel < level) {
  36567. highestLevel = level;
  36568. }
  36569. if (lowestOddLevel > level && isOdd(level)) {
  36570. lowestOddLevel = level;
  36571. }
  36572. }
  36573. // now reverse between those limits
  36574. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36575. // find segments to reverse
  36576. var start = -1;
  36577. for (i = 0, ii = levels.length; i < ii; ++i) {
  36578. if (levels[i] < level) {
  36579. if (start >= 0) {
  36580. reverseValues(chars, start, i);
  36581. start = -1;
  36582. }
  36583. } else if (start < 0) {
  36584. start = i;
  36585. }
  36586. }
  36587. if (start >= 0) {
  36588. reverseValues(chars, start, levels.length);
  36589. }
  36590. }
  36591. /*
  36592. L3. Combining marks applied to a right-to-left base character will at this
  36593. point precede their base character. If the rendering engine expects them to
  36594. follow the base characters in the final display process, then the ordering
  36595. of the marks and the base character must be reversed.
  36596. */
  36597. // don't bother for now
  36598. /*
  36599. L4. A character that possesses the mirrored property as specified by
  36600. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36601. directionality of that character is R.
  36602. */
  36603. // don't mirror as characters are already mirrored in the pdf
  36604. // Finally, return string
  36605. var result = '';
  36606. for (i = 0, ii = chars.length; i < ii; ++i) {
  36607. var ch = chars[i];
  36608. if (ch !== '<' && ch !== '>') {
  36609. result += ch;
  36610. }
  36611. }
  36612. return createBidiText(result, isLTR);
  36613. }
  36614. return bidi;
  36615. })();
  36616. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36617. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36618. /* Copyright 2014 Opera Software ASA
  36619. *
  36620. * Licensed under the Apache License, Version 2.0 (the "License");
  36621. * you may not use this file except in compliance with the License.
  36622. * You may obtain a copy of the License at
  36623. *
  36624. * http://www.apache.org/licenses/LICENSE-2.0
  36625. *
  36626. * Unless required by applicable law or agreed to in writing, software
  36627. * distributed under the License is distributed on an "AS IS" BASIS,
  36628. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36629. * See the License for the specific language governing permissions and
  36630. * limitations under the License.
  36631. *
  36632. *
  36633. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36634. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36635. */
  36636. /* globals Uint32ArrayView */
  36637. 'use strict';
  36638. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36639. // Workaround for missing math precison in JS.
  36640. var MASK_HIGH = 0xffff0000;
  36641. var MASK_LOW = 0xffff;
  36642. function MurmurHash3_64 (seed) {
  36643. var SEED = 0xc3d2e1f0;
  36644. this.h1 = seed ? seed & 0xffffffff : SEED;
  36645. this.h2 = seed ? seed & 0xffffffff : SEED;
  36646. }
  36647. var alwaysUseUint32ArrayView = false;
  36648. // old webkits have issues with non-aligned arrays
  36649. try {
  36650. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36651. } catch (e) {
  36652. alwaysUseUint32ArrayView = true;
  36653. }
  36654. MurmurHash3_64.prototype = {
  36655. update: function MurmurHash3_64_update(input) {
  36656. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36657. var i;
  36658. if (typeof input === 'string') {
  36659. var data = new Uint8Array(input.length * 2);
  36660. var length = 0;
  36661. for (i = 0; i < input.length; i++) {
  36662. var code = input.charCodeAt(i);
  36663. if (code <= 0xff) {
  36664. data[length++] = code;
  36665. }
  36666. else {
  36667. data[length++] = code >>> 8;
  36668. data[length++] = code & 0xff;
  36669. }
  36670. }
  36671. } else if (input instanceof Uint8Array) {
  36672. data = input;
  36673. length = data.length;
  36674. } else if (typeof input === 'object' && ('length' in input)) {
  36675. // processing regular arrays as well, e.g. for IE9
  36676. data = input;
  36677. length = data.length;
  36678. useUint32ArrayView = true;
  36679. } else {
  36680. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36681. 'Input must be a string or array.');
  36682. }
  36683. var blockCounts = length >> 2;
  36684. var tailLength = length - blockCounts * 4;
  36685. // we don't care about endianness here
  36686. var dataUint32 = useUint32ArrayView ?
  36687. new Uint32ArrayView(data, blockCounts) :
  36688. new Uint32Array(data.buffer, 0, blockCounts);
  36689. var k1 = 0;
  36690. var k2 = 0;
  36691. var h1 = this.h1;
  36692. var h2 = this.h2;
  36693. var C1 = 0xcc9e2d51;
  36694. var C2 = 0x1b873593;
  36695. var C1_LOW = C1 & MASK_LOW;
  36696. var C2_LOW = C2 & MASK_LOW;
  36697. for (i = 0; i < blockCounts; i++) {
  36698. if (i & 1) {
  36699. k1 = dataUint32[i];
  36700. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36701. k1 = k1 << 15 | k1 >>> 17;
  36702. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36703. h1 ^= k1;
  36704. h1 = h1 << 13 | h1 >>> 19;
  36705. h1 = h1 * 5 + 0xe6546b64;
  36706. } else {
  36707. k2 = dataUint32[i];
  36708. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36709. k2 = k2 << 15 | k2 >>> 17;
  36710. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36711. h2 ^= k2;
  36712. h2 = h2 << 13 | h2 >>> 19;
  36713. h2 = h2 * 5 + 0xe6546b64;
  36714. }
  36715. }
  36716. k1 = 0;
  36717. switch (tailLength) {
  36718. case 3:
  36719. k1 ^= data[blockCounts * 4 + 2] << 16;
  36720. /* falls through */
  36721. case 2:
  36722. k1 ^= data[blockCounts * 4 + 1] << 8;
  36723. /* falls through */
  36724. case 1:
  36725. k1 ^= data[blockCounts * 4];
  36726. /* falls through */
  36727. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36728. k1 = k1 << 15 | k1 >>> 17;
  36729. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36730. if (blockCounts & 1) {
  36731. h1 ^= k1;
  36732. } else {
  36733. h2 ^= k1;
  36734. }
  36735. }
  36736. this.h1 = h1;
  36737. this.h2 = h2;
  36738. return this;
  36739. },
  36740. hexdigest: function MurmurHash3_64_hexdigest () {
  36741. var h1 = this.h1;
  36742. var h2 = this.h2;
  36743. h1 ^= h2 >>> 1;
  36744. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36745. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36746. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36747. h1 ^= h2 >>> 1;
  36748. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36749. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36750. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36751. h1 ^= h2 >>> 1;
  36752. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36753. var hex = (arr[i] >>> 0).toString(16);
  36754. while (hex.length < 8) {
  36755. hex = '0' + hex;
  36756. }
  36757. str += hex;
  36758. }
  36759. return str;
  36760. }
  36761. };
  36762. return MurmurHash3_64;
  36763. })();
  36764. }).call((typeof window === 'undefined') ? this : window);
  36765. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36766. // workerSrc is not set -- using last script url to define default location
  36767. PDFJS.workerSrc = (function () {
  36768. 'use strict';
  36769. var scriptTagContainer = document.body ||
  36770. document.getElementsByTagName('head')[0];
  36771. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36772. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36773. })();
  36774. }