pdf.worker.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097
  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.1059';
  24. PDFJS.build = '34bed63';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. PDFJS.PasswordException = PasswordException;
  346. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  347. function UnknownErrorException(msg, details) {
  348. this.name = 'UnknownErrorException';
  349. this.message = msg;
  350. this.details = details;
  351. }
  352. UnknownErrorException.prototype = new Error();
  353. UnknownErrorException.constructor = UnknownErrorException;
  354. return UnknownErrorException;
  355. })();
  356. PDFJS.UnknownErrorException = UnknownErrorException;
  357. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  358. function InvalidPDFException(msg) {
  359. this.name = 'InvalidPDFException';
  360. this.message = msg;
  361. }
  362. InvalidPDFException.prototype = new Error();
  363. InvalidPDFException.constructor = InvalidPDFException;
  364. return InvalidPDFException;
  365. })();
  366. PDFJS.InvalidPDFException = InvalidPDFException;
  367. var MissingPDFException = (function MissingPDFExceptionClosure() {
  368. function MissingPDFException(msg) {
  369. this.name = 'MissingPDFException';
  370. this.message = msg;
  371. }
  372. MissingPDFException.prototype = new Error();
  373. MissingPDFException.constructor = MissingPDFException;
  374. return MissingPDFException;
  375. })();
  376. PDFJS.MissingPDFException = MissingPDFException;
  377. var UnexpectedResponseException =
  378. (function UnexpectedResponseExceptionClosure() {
  379. function UnexpectedResponseException(msg, status) {
  380. this.name = 'UnexpectedResponseException';
  381. this.message = msg;
  382. this.status = status;
  383. }
  384. UnexpectedResponseException.prototype = new Error();
  385. UnexpectedResponseException.constructor = UnexpectedResponseException;
  386. return UnexpectedResponseException;
  387. })();
  388. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  389. var NotImplementedException = (function NotImplementedExceptionClosure() {
  390. function NotImplementedException(msg) {
  391. this.message = msg;
  392. }
  393. NotImplementedException.prototype = new Error();
  394. NotImplementedException.prototype.name = 'NotImplementedException';
  395. NotImplementedException.constructor = NotImplementedException;
  396. return NotImplementedException;
  397. })();
  398. var MissingDataException = (function MissingDataExceptionClosure() {
  399. function MissingDataException(begin, end) {
  400. this.begin = begin;
  401. this.end = end;
  402. this.message = 'Missing data [' + begin + ', ' + end + ')';
  403. }
  404. MissingDataException.prototype = new Error();
  405. MissingDataException.prototype.name = 'MissingDataException';
  406. MissingDataException.constructor = MissingDataException;
  407. return MissingDataException;
  408. })();
  409. var XRefParseException = (function XRefParseExceptionClosure() {
  410. function XRefParseException(msg) {
  411. this.message = msg;
  412. }
  413. XRefParseException.prototype = new Error();
  414. XRefParseException.prototype.name = 'XRefParseException';
  415. XRefParseException.constructor = XRefParseException;
  416. return XRefParseException;
  417. })();
  418. function bytesToString(bytes) {
  419. assert(bytes !== null && typeof bytes === 'object' &&
  420. bytes.length !== undefined, 'Invalid argument for bytesToString');
  421. var length = bytes.length;
  422. var MAX_ARGUMENT_COUNT = 8192;
  423. if (length < MAX_ARGUMENT_COUNT) {
  424. return String.fromCharCode.apply(null, bytes);
  425. }
  426. var strBuf = [];
  427. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  428. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  429. var chunk = bytes.subarray(i, chunkEnd);
  430. strBuf.push(String.fromCharCode.apply(null, chunk));
  431. }
  432. return strBuf.join('');
  433. }
  434. function stringToBytes(str) {
  435. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  436. var length = str.length;
  437. var bytes = new Uint8Array(length);
  438. for (var i = 0; i < length; ++i) {
  439. bytes[i] = str.charCodeAt(i) & 0xFF;
  440. }
  441. return bytes;
  442. }
  443. function string32(value) {
  444. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  445. (value >> 8) & 0xff, value & 0xff);
  446. }
  447. function log2(x) {
  448. var n = 1, i = 0;
  449. while (x > n) {
  450. n <<= 1;
  451. i++;
  452. }
  453. return i;
  454. }
  455. function readInt8(data, start) {
  456. return (data[start] << 24) >> 24;
  457. }
  458. function readUint16(data, offset) {
  459. return (data[offset] << 8) | data[offset + 1];
  460. }
  461. function readUint32(data, offset) {
  462. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  463. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  464. }
  465. // Lazy test the endianness of the platform
  466. // NOTE: This will be 'true' for simulated TypedArrays
  467. function isLittleEndian() {
  468. var buffer8 = new Uint8Array(2);
  469. buffer8[0] = 1;
  470. var buffer16 = new Uint16Array(buffer8.buffer);
  471. return (buffer16[0] === 1);
  472. }
  473. Object.defineProperty(PDFJS, 'isLittleEndian', {
  474. configurable: true,
  475. get: function PDFJS_isLittleEndian() {
  476. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  477. }
  478. });
  479. // Lazy test if the userAgant support CanvasTypedArrays
  480. function hasCanvasTypedArrays() {
  481. var canvas = document.createElement('canvas');
  482. canvas.width = canvas.height = 1;
  483. var ctx = canvas.getContext('2d');
  484. var imageData = ctx.createImageData(1, 1);
  485. return (typeof imageData.data.buffer !== 'undefined');
  486. }
  487. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  488. configurable: true,
  489. get: function PDFJS_hasCanvasTypedArrays() {
  490. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  491. }
  492. });
  493. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  494. function Uint32ArrayView(buffer, length) {
  495. this.buffer = buffer;
  496. this.byteLength = buffer.length;
  497. this.length = length === undefined ? (this.byteLength >> 2) : length;
  498. ensureUint32ArrayViewProps(this.length);
  499. }
  500. Uint32ArrayView.prototype = Object.create(null);
  501. var uint32ArrayViewSetters = 0;
  502. function createUint32ArrayProp(index) {
  503. return {
  504. get: function () {
  505. var buffer = this.buffer, offset = index << 2;
  506. return (buffer[offset] | (buffer[offset + 1] << 8) |
  507. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  508. },
  509. set: function (value) {
  510. var buffer = this.buffer, offset = index << 2;
  511. buffer[offset] = value & 255;
  512. buffer[offset + 1] = (value >> 8) & 255;
  513. buffer[offset + 2] = (value >> 16) & 255;
  514. buffer[offset + 3] = (value >>> 24) & 255;
  515. }
  516. };
  517. }
  518. function ensureUint32ArrayViewProps(length) {
  519. while (uint32ArrayViewSetters < length) {
  520. Object.defineProperty(Uint32ArrayView.prototype,
  521. uint32ArrayViewSetters,
  522. createUint32ArrayProp(uint32ArrayViewSetters));
  523. uint32ArrayViewSetters++;
  524. }
  525. }
  526. return Uint32ArrayView;
  527. })();
  528. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  529. var Util = PDFJS.Util = (function UtilClosure() {
  530. function Util() {}
  531. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  532. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  533. // creating many intermediate strings.
  534. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  535. rgbBuf[1] = r;
  536. rgbBuf[3] = g;
  537. rgbBuf[5] = b;
  538. return rgbBuf.join('');
  539. };
  540. // Concatenates two transformation matrices together and returns the result.
  541. Util.transform = function Util_transform(m1, m2) {
  542. return [
  543. m1[0] * m2[0] + m1[2] * m2[1],
  544. m1[1] * m2[0] + m1[3] * m2[1],
  545. m1[0] * m2[2] + m1[2] * m2[3],
  546. m1[1] * m2[2] + m1[3] * m2[3],
  547. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  548. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  549. ];
  550. };
  551. // For 2d affine transforms
  552. Util.applyTransform = function Util_applyTransform(p, m) {
  553. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  554. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  555. return [xt, yt];
  556. };
  557. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  558. var d = m[0] * m[3] - m[1] * m[2];
  559. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  560. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  561. return [xt, yt];
  562. };
  563. // Applies the transform to the rectangle and finds the minimum axially
  564. // aligned bounding box.
  565. Util.getAxialAlignedBoundingBox =
  566. function Util_getAxialAlignedBoundingBox(r, m) {
  567. var p1 = Util.applyTransform(r, m);
  568. var p2 = Util.applyTransform(r.slice(2, 4), m);
  569. var p3 = Util.applyTransform([r[0], r[3]], m);
  570. var p4 = Util.applyTransform([r[2], r[1]], m);
  571. return [
  572. Math.min(p1[0], p2[0], p3[0], p4[0]),
  573. Math.min(p1[1], p2[1], p3[1], p4[1]),
  574. Math.max(p1[0], p2[0], p3[0], p4[0]),
  575. Math.max(p1[1], p2[1], p3[1], p4[1])
  576. ];
  577. };
  578. Util.inverseTransform = function Util_inverseTransform(m) {
  579. var d = m[0] * m[3] - m[1] * m[2];
  580. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  581. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  582. };
  583. // Apply a generic 3d matrix M on a 3-vector v:
  584. // | a b c | | X |
  585. // | d e f | x | Y |
  586. // | g h i | | Z |
  587. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  588. // with v as [X,Y,Z]
  589. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  590. return [
  591. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  592. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  593. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  594. ];
  595. };
  596. // This calculation uses Singular Value Decomposition.
  597. // The SVD can be represented with formula A = USV. We are interested in the
  598. // matrix S here because it represents the scale values.
  599. Util.singularValueDecompose2dScale =
  600. function Util_singularValueDecompose2dScale(m) {
  601. var transpose = [m[0], m[2], m[1], m[3]];
  602. // Multiply matrix m with its transpose.
  603. var a = m[0] * transpose[0] + m[1] * transpose[2];
  604. var b = m[0] * transpose[1] + m[1] * transpose[3];
  605. var c = m[2] * transpose[0] + m[3] * transpose[2];
  606. var d = m[2] * transpose[1] + m[3] * transpose[3];
  607. // Solve the second degree polynomial to get roots.
  608. var first = (a + d) / 2;
  609. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  610. var sx = first + second || 1;
  611. var sy = first - second || 1;
  612. // Scale values are the square roots of the eigenvalues.
  613. return [Math.sqrt(sx), Math.sqrt(sy)];
  614. };
  615. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  616. // For coordinate systems whose origin lies in the bottom-left, this
  617. // means normalization to (BL,TR) ordering. For systems with origin in the
  618. // top-left, this means (TL,BR) ordering.
  619. Util.normalizeRect = function Util_normalizeRect(rect) {
  620. var r = rect.slice(0); // clone rect
  621. if (rect[0] > rect[2]) {
  622. r[0] = rect[2];
  623. r[2] = rect[0];
  624. }
  625. if (rect[1] > rect[3]) {
  626. r[1] = rect[3];
  627. r[3] = rect[1];
  628. }
  629. return r;
  630. };
  631. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  632. // intersection of rect1 and rect2. If no intersection, returns 'false'
  633. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  634. Util.intersect = function Util_intersect(rect1, rect2) {
  635. function compare(a, b) {
  636. return a - b;
  637. }
  638. // Order points along the axes
  639. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  640. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  641. result = [];
  642. rect1 = Util.normalizeRect(rect1);
  643. rect2 = Util.normalizeRect(rect2);
  644. // X: first and second points belong to different rectangles?
  645. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  646. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  647. // Intersection must be between second and third points
  648. result[0] = orderedX[1];
  649. result[2] = orderedX[2];
  650. } else {
  651. return false;
  652. }
  653. // Y: first and second points belong to different rectangles?
  654. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  655. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  656. // Intersection must be between second and third points
  657. result[1] = orderedY[1];
  658. result[3] = orderedY[2];
  659. } else {
  660. return false;
  661. }
  662. return result;
  663. };
  664. Util.sign = function Util_sign(num) {
  665. return num < 0 ? -1 : 1;
  666. };
  667. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  668. Array.prototype.push.apply(arr1, arr2);
  669. };
  670. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  671. Array.prototype.unshift.apply(arr1, arr2);
  672. };
  673. Util.extendObj = function extendObj(obj1, obj2) {
  674. for (var key in obj2) {
  675. obj1[key] = obj2[key];
  676. }
  677. };
  678. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  679. name) {
  680. while (dict && !dict.has(name)) {
  681. dict = dict.get('Parent');
  682. }
  683. if (!dict) {
  684. return null;
  685. }
  686. return dict.get(name);
  687. };
  688. Util.inherit = function Util_inherit(sub, base, prototype) {
  689. sub.prototype = Object.create(base.prototype);
  690. sub.prototype.constructor = sub;
  691. for (var prop in prototype) {
  692. sub.prototype[prop] = prototype[prop];
  693. }
  694. };
  695. Util.loadScript = function Util_loadScript(src, callback) {
  696. var script = document.createElement('script');
  697. var loaded = false;
  698. script.setAttribute('src', src);
  699. if (callback) {
  700. script.onload = function() {
  701. if (!loaded) {
  702. callback();
  703. }
  704. loaded = true;
  705. };
  706. }
  707. document.getElementsByTagName('head')[0].appendChild(script);
  708. };
  709. return Util;
  710. })();
  711. /**
  712. * PDF page viewport created based on scale, rotation and offset.
  713. * @class
  714. * @alias PDFJS.PageViewport
  715. */
  716. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  717. /**
  718. * @constructor
  719. * @private
  720. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  721. * @param scale {number} scale of the viewport.
  722. * @param rotation {number} rotations of the viewport in degrees.
  723. * @param offsetX {number} offset X
  724. * @param offsetY {number} offset Y
  725. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  726. */
  727. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  728. this.viewBox = viewBox;
  729. this.scale = scale;
  730. this.rotation = rotation;
  731. this.offsetX = offsetX;
  732. this.offsetY = offsetY;
  733. // creating transform to convert pdf coordinate system to the normal
  734. // canvas like coordinates taking in account scale and rotation
  735. var centerX = (viewBox[2] + viewBox[0]) / 2;
  736. var centerY = (viewBox[3] + viewBox[1]) / 2;
  737. var rotateA, rotateB, rotateC, rotateD;
  738. rotation = rotation % 360;
  739. rotation = rotation < 0 ? rotation + 360 : rotation;
  740. switch (rotation) {
  741. case 180:
  742. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  743. break;
  744. case 90:
  745. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  746. break;
  747. case 270:
  748. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  749. break;
  750. //case 0:
  751. default:
  752. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  753. break;
  754. }
  755. if (dontFlip) {
  756. rotateC = -rotateC; rotateD = -rotateD;
  757. }
  758. var offsetCanvasX, offsetCanvasY;
  759. var width, height;
  760. if (rotateA === 0) {
  761. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  762. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  763. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  764. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  765. } else {
  766. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  767. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  768. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  769. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  770. }
  771. // creating transform for the following operations:
  772. // translate(-centerX, -centerY), rotate and flip vertically,
  773. // scale, and translate(offsetCanvasX, offsetCanvasY)
  774. this.transform = [
  775. rotateA * scale,
  776. rotateB * scale,
  777. rotateC * scale,
  778. rotateD * scale,
  779. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  780. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  781. ];
  782. this.width = width;
  783. this.height = height;
  784. this.fontScale = scale;
  785. }
  786. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  787. /**
  788. * Clones viewport with additional properties.
  789. * @param args {Object} (optional) If specified, may contain the 'scale' or
  790. * 'rotation' properties to override the corresponding properties in
  791. * the cloned viewport.
  792. * @returns {PDFJS.PageViewport} Cloned viewport.
  793. */
  794. clone: function PageViewPort_clone(args) {
  795. args = args || {};
  796. var scale = 'scale' in args ? args.scale : this.scale;
  797. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  798. return new PageViewport(this.viewBox.slice(), scale, rotation,
  799. this.offsetX, this.offsetY, args.dontFlip);
  800. },
  801. /**
  802. * Converts PDF point to the viewport coordinates. For examples, useful for
  803. * converting PDF location into canvas pixel coordinates.
  804. * @param x {number} X coordinate.
  805. * @param y {number} Y coordinate.
  806. * @returns {Object} Object that contains 'x' and 'y' properties of the
  807. * point in the viewport coordinate space.
  808. * @see {@link convertToPdfPoint}
  809. * @see {@link convertToViewportRectangle}
  810. */
  811. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  812. return Util.applyTransform([x, y], this.transform);
  813. },
  814. /**
  815. * Converts PDF rectangle to the viewport coordinates.
  816. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  817. * @returns {Array} Contains corresponding coordinates of the rectangle
  818. * in the viewport coordinate space.
  819. * @see {@link convertToViewportPoint}
  820. */
  821. convertToViewportRectangle:
  822. function PageViewport_convertToViewportRectangle(rect) {
  823. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  824. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  825. return [tl[0], tl[1], br[0], br[1]];
  826. },
  827. /**
  828. * Converts viewport coordinates to the PDF location. For examples, useful
  829. * for converting canvas pixel location into PDF one.
  830. * @param x {number} X coordinate.
  831. * @param y {number} Y coordinate.
  832. * @returns {Object} Object that contains 'x' and 'y' properties of the
  833. * point in the PDF coordinate space.
  834. * @see {@link convertToViewportPoint}
  835. */
  836. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  837. return Util.applyInverseTransform([x, y], this.transform);
  838. }
  839. };
  840. return PageViewport;
  841. })();
  842. var PDFStringTranslateTable = [
  843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  844. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0,
  846. 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,
  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, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  849. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  850. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  851. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  852. ];
  853. function stringToPDFString(str) {
  854. var i, n = str.length, strBuf = [];
  855. if (str[0] === '\xFE' && str[1] === '\xFF') {
  856. // UTF16BE BOM
  857. for (i = 2; i < n; i += 2) {
  858. strBuf.push(String.fromCharCode(
  859. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  860. }
  861. } else {
  862. for (i = 0; i < n; ++i) {
  863. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  864. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  865. }
  866. }
  867. return strBuf.join('');
  868. }
  869. function stringToUTF8String(str) {
  870. return decodeURIComponent(escape(str));
  871. }
  872. function isEmptyObj(obj) {
  873. for (var key in obj) {
  874. return false;
  875. }
  876. return true;
  877. }
  878. function isBool(v) {
  879. return typeof v === 'boolean';
  880. }
  881. function isInt(v) {
  882. return typeof v === 'number' && ((v | 0) === v);
  883. }
  884. function isNum(v) {
  885. return typeof v === 'number';
  886. }
  887. function isString(v) {
  888. return typeof v === 'string';
  889. }
  890. function isNull(v) {
  891. return v === null;
  892. }
  893. function isName(v) {
  894. return v instanceof Name;
  895. }
  896. function isCmd(v, cmd) {
  897. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  898. }
  899. function isDict(v, type) {
  900. if (!(v instanceof Dict)) {
  901. return false;
  902. }
  903. if (!type) {
  904. return true;
  905. }
  906. var dictType = v.get('Type');
  907. return isName(dictType) && dictType.name === type;
  908. }
  909. function isArray(v) {
  910. return v instanceof Array;
  911. }
  912. function isStream(v) {
  913. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  914. }
  915. function isArrayBuffer(v) {
  916. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  917. }
  918. function isRef(v) {
  919. return v instanceof Ref;
  920. }
  921. /**
  922. * Promise Capability object.
  923. *
  924. * @typedef {Object} PromiseCapability
  925. * @property {Promise} promise - A promise object.
  926. * @property {function} resolve - Fullfills the promise.
  927. * @property {function} reject - Rejects the promise.
  928. */
  929. /**
  930. * Creates a promise capability object.
  931. * @alias PDFJS.createPromiseCapability
  932. *
  933. * @return {PromiseCapability} A capability object contains:
  934. * - a Promise, resolve and reject methods.
  935. */
  936. function createPromiseCapability() {
  937. var capability = {};
  938. capability.promise = new Promise(function (resolve, reject) {
  939. capability.resolve = resolve;
  940. capability.reject = reject;
  941. });
  942. return capability;
  943. }
  944. PDFJS.createPromiseCapability = createPromiseCapability;
  945. /**
  946. * Polyfill for Promises:
  947. * The following promise implementation tries to generally implement the
  948. * Promise/A+ spec. Some notable differences from other promise libaries are:
  949. * - There currently isn't a seperate deferred and promise object.
  950. * - Unhandled rejections eventually show an error if they aren't handled.
  951. *
  952. * Based off of the work in:
  953. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  954. */
  955. (function PromiseClosure() {
  956. if (globalScope.Promise) {
  957. // Promises existing in the DOM/Worker, checking presence of all/resolve
  958. if (typeof globalScope.Promise.all !== 'function') {
  959. globalScope.Promise.all = function (iterable) {
  960. var count = 0, results = [], resolve, reject;
  961. var promise = new globalScope.Promise(function (resolve_, reject_) {
  962. resolve = resolve_;
  963. reject = reject_;
  964. });
  965. iterable.forEach(function (p, i) {
  966. count++;
  967. p.then(function (result) {
  968. results[i] = result;
  969. count--;
  970. if (count === 0) {
  971. resolve(results);
  972. }
  973. }, reject);
  974. });
  975. if (count === 0) {
  976. resolve(results);
  977. }
  978. return promise;
  979. };
  980. }
  981. if (typeof globalScope.Promise.resolve !== 'function') {
  982. globalScope.Promise.resolve = function (value) {
  983. return new globalScope.Promise(function (resolve) { resolve(value); });
  984. };
  985. }
  986. if (typeof globalScope.Promise.reject !== 'function') {
  987. globalScope.Promise.reject = function (reason) {
  988. return new globalScope.Promise(function (resolve, reject) {
  989. reject(reason);
  990. });
  991. };
  992. }
  993. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  994. globalScope.Promise.prototype.catch = function (onReject) {
  995. return globalScope.Promise.prototype.then(undefined, onReject);
  996. };
  997. }
  998. return;
  999. }
  1000. var STATUS_PENDING = 0;
  1001. var STATUS_RESOLVED = 1;
  1002. var STATUS_REJECTED = 2;
  1003. // In an attempt to avoid silent exceptions, unhandled rejections are
  1004. // tracked and if they aren't handled in a certain amount of time an
  1005. // error is logged.
  1006. var REJECTION_TIMEOUT = 500;
  1007. var HandlerManager = {
  1008. handlers: [],
  1009. running: false,
  1010. unhandledRejections: [],
  1011. pendingRejectionCheck: false,
  1012. scheduleHandlers: function scheduleHandlers(promise) {
  1013. if (promise._status === STATUS_PENDING) {
  1014. return;
  1015. }
  1016. this.handlers = this.handlers.concat(promise._handlers);
  1017. promise._handlers = [];
  1018. if (this.running) {
  1019. return;
  1020. }
  1021. this.running = true;
  1022. setTimeout(this.runHandlers.bind(this), 0);
  1023. },
  1024. runHandlers: function runHandlers() {
  1025. var RUN_TIMEOUT = 1; // ms
  1026. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1027. while (this.handlers.length > 0) {
  1028. var handler = this.handlers.shift();
  1029. var nextStatus = handler.thisPromise._status;
  1030. var nextValue = handler.thisPromise._value;
  1031. try {
  1032. if (nextStatus === STATUS_RESOLVED) {
  1033. if (typeof handler.onResolve === 'function') {
  1034. nextValue = handler.onResolve(nextValue);
  1035. }
  1036. } else if (typeof handler.onReject === 'function') {
  1037. nextValue = handler.onReject(nextValue);
  1038. nextStatus = STATUS_RESOLVED;
  1039. if (handler.thisPromise._unhandledRejection) {
  1040. this.removeUnhandeledRejection(handler.thisPromise);
  1041. }
  1042. }
  1043. } catch (ex) {
  1044. nextStatus = STATUS_REJECTED;
  1045. nextValue = ex;
  1046. }
  1047. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1048. if (Date.now() >= timeoutAt) {
  1049. break;
  1050. }
  1051. }
  1052. if (this.handlers.length > 0) {
  1053. setTimeout(this.runHandlers.bind(this), 0);
  1054. return;
  1055. }
  1056. this.running = false;
  1057. },
  1058. addUnhandledRejection: function addUnhandledRejection(promise) {
  1059. this.unhandledRejections.push({
  1060. promise: promise,
  1061. time: Date.now()
  1062. });
  1063. this.scheduleRejectionCheck();
  1064. },
  1065. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1066. promise._unhandledRejection = false;
  1067. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1068. if (this.unhandledRejections[i].promise === promise) {
  1069. this.unhandledRejections.splice(i);
  1070. i--;
  1071. }
  1072. }
  1073. },
  1074. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1075. if (this.pendingRejectionCheck) {
  1076. return;
  1077. }
  1078. this.pendingRejectionCheck = true;
  1079. setTimeout(function rejectionCheck() {
  1080. this.pendingRejectionCheck = false;
  1081. var now = Date.now();
  1082. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1083. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1084. var unhandled = this.unhandledRejections[i].promise._value;
  1085. var msg = 'Unhandled rejection: ' + unhandled;
  1086. if (unhandled.stack) {
  1087. msg += '\n' + unhandled.stack;
  1088. }
  1089. warn(msg);
  1090. this.unhandledRejections.splice(i);
  1091. i--;
  1092. }
  1093. }
  1094. if (this.unhandledRejections.length) {
  1095. this.scheduleRejectionCheck();
  1096. }
  1097. }.bind(this), REJECTION_TIMEOUT);
  1098. }
  1099. };
  1100. function Promise(resolver) {
  1101. this._status = STATUS_PENDING;
  1102. this._handlers = [];
  1103. try {
  1104. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1105. } catch (e) {
  1106. this._reject(e);
  1107. }
  1108. }
  1109. /**
  1110. * Builds a promise that is resolved when all the passed in promises are
  1111. * resolved.
  1112. * @param {array} array of data and/or promises to wait for.
  1113. * @return {Promise} New dependant promise.
  1114. */
  1115. Promise.all = function Promise_all(promises) {
  1116. var resolveAll, rejectAll;
  1117. var deferred = new Promise(function (resolve, reject) {
  1118. resolveAll = resolve;
  1119. rejectAll = reject;
  1120. });
  1121. var unresolved = promises.length;
  1122. var results = [];
  1123. if (unresolved === 0) {
  1124. resolveAll(results);
  1125. return deferred;
  1126. }
  1127. function reject(reason) {
  1128. if (deferred._status === STATUS_REJECTED) {
  1129. return;
  1130. }
  1131. results = [];
  1132. rejectAll(reason);
  1133. }
  1134. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1135. var promise = promises[i];
  1136. var resolve = (function(i) {
  1137. return function(value) {
  1138. if (deferred._status === STATUS_REJECTED) {
  1139. return;
  1140. }
  1141. results[i] = value;
  1142. unresolved--;
  1143. if (unresolved === 0) {
  1144. resolveAll(results);
  1145. }
  1146. };
  1147. })(i);
  1148. if (Promise.isPromise(promise)) {
  1149. promise.then(resolve, reject);
  1150. } else {
  1151. resolve(promise);
  1152. }
  1153. }
  1154. return deferred;
  1155. };
  1156. /**
  1157. * Checks if the value is likely a promise (has a 'then' function).
  1158. * @return {boolean} true if value is thenable
  1159. */
  1160. Promise.isPromise = function Promise_isPromise(value) {
  1161. return value && typeof value.then === 'function';
  1162. };
  1163. /**
  1164. * Creates resolved promise
  1165. * @param value resolve value
  1166. * @returns {Promise}
  1167. */
  1168. Promise.resolve = function Promise_resolve(value) {
  1169. return new Promise(function (resolve) { resolve(value); });
  1170. };
  1171. /**
  1172. * Creates rejected promise
  1173. * @param reason rejection value
  1174. * @returns {Promise}
  1175. */
  1176. Promise.reject = function Promise_reject(reason) {
  1177. return new Promise(function (resolve, reject) { reject(reason); });
  1178. };
  1179. Promise.prototype = {
  1180. _status: null,
  1181. _value: null,
  1182. _handlers: null,
  1183. _unhandledRejection: null,
  1184. _updateStatus: function Promise__updateStatus(status, value) {
  1185. if (this._status === STATUS_RESOLVED ||
  1186. this._status === STATUS_REJECTED) {
  1187. return;
  1188. }
  1189. if (status === STATUS_RESOLVED &&
  1190. Promise.isPromise(value)) {
  1191. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1192. this._updateStatus.bind(this, STATUS_REJECTED));
  1193. return;
  1194. }
  1195. this._status = status;
  1196. this._value = value;
  1197. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1198. this._unhandledRejection = true;
  1199. HandlerManager.addUnhandledRejection(this);
  1200. }
  1201. HandlerManager.scheduleHandlers(this);
  1202. },
  1203. _resolve: function Promise_resolve(value) {
  1204. this._updateStatus(STATUS_RESOLVED, value);
  1205. },
  1206. _reject: function Promise_reject(reason) {
  1207. this._updateStatus(STATUS_REJECTED, reason);
  1208. },
  1209. then: function Promise_then(onResolve, onReject) {
  1210. var nextPromise = new Promise(function (resolve, reject) {
  1211. this.resolve = resolve;
  1212. this.reject = reject;
  1213. });
  1214. this._handlers.push({
  1215. thisPromise: this,
  1216. onResolve: onResolve,
  1217. onReject: onReject,
  1218. nextPromise: nextPromise
  1219. });
  1220. HandlerManager.scheduleHandlers(this);
  1221. return nextPromise;
  1222. },
  1223. catch: function Promise_catch(onReject) {
  1224. return this.then(undefined, onReject);
  1225. }
  1226. };
  1227. globalScope.Promise = Promise;
  1228. })();
  1229. var StatTimer = (function StatTimerClosure() {
  1230. function rpad(str, pad, length) {
  1231. while (str.length < length) {
  1232. str += pad;
  1233. }
  1234. return str;
  1235. }
  1236. function StatTimer() {
  1237. this.started = {};
  1238. this.times = [];
  1239. this.enabled = true;
  1240. }
  1241. StatTimer.prototype = {
  1242. time: function StatTimer_time(name) {
  1243. if (!this.enabled) {
  1244. return;
  1245. }
  1246. if (name in this.started) {
  1247. warn('Timer is already running for ' + name);
  1248. }
  1249. this.started[name] = Date.now();
  1250. },
  1251. timeEnd: function StatTimer_timeEnd(name) {
  1252. if (!this.enabled) {
  1253. return;
  1254. }
  1255. if (!(name in this.started)) {
  1256. warn('Timer has not been started for ' + name);
  1257. }
  1258. this.times.push({
  1259. 'name': name,
  1260. 'start': this.started[name],
  1261. 'end': Date.now()
  1262. });
  1263. // Remove timer from started so it can be called again.
  1264. delete this.started[name];
  1265. },
  1266. toString: function StatTimer_toString() {
  1267. var i, ii;
  1268. var times = this.times;
  1269. var out = '';
  1270. // Find the longest name for padding purposes.
  1271. var longest = 0;
  1272. for (i = 0, ii = times.length; i < ii; ++i) {
  1273. var name = times[i]['name'];
  1274. if (name.length > longest) {
  1275. longest = name.length;
  1276. }
  1277. }
  1278. for (i = 0, ii = times.length; i < ii; ++i) {
  1279. var span = times[i];
  1280. var duration = span.end - span.start;
  1281. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1282. }
  1283. return out;
  1284. }
  1285. };
  1286. return StatTimer;
  1287. })();
  1288. PDFJS.createBlob = function createBlob(data, contentType) {
  1289. if (typeof Blob !== 'undefined') {
  1290. return new Blob([data], { type: contentType });
  1291. }
  1292. // Blob builder is deprecated in FF14 and removed in FF18.
  1293. var bb = new MozBlobBuilder();
  1294. bb.append(data);
  1295. return bb.getBlob(contentType);
  1296. };
  1297. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1298. // Blob/createObjectURL is not available, falling back to data schema.
  1299. var digits =
  1300. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1301. return function createObjectURL(data, contentType) {
  1302. if (!PDFJS.disableCreateObjectURL &&
  1303. typeof URL !== 'undefined' && URL.createObjectURL) {
  1304. var blob = PDFJS.createBlob(data, contentType);
  1305. return URL.createObjectURL(blob);
  1306. }
  1307. var buffer = 'data:' + contentType + ';base64,';
  1308. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1309. var b1 = data[i] & 0xFF;
  1310. var b2 = data[i + 1] & 0xFF;
  1311. var b3 = data[i + 2] & 0xFF;
  1312. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1313. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1314. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1315. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1316. }
  1317. return buffer;
  1318. };
  1319. })();
  1320. function MessageHandler(name, comObj) {
  1321. this.name = name;
  1322. this.comObj = comObj;
  1323. this.callbackIndex = 1;
  1324. this.postMessageTransfers = true;
  1325. var callbacksCapabilities = this.callbacksCapabilities = {};
  1326. var ah = this.actionHandler = {};
  1327. ah['console_log'] = [function ahConsoleLog(data) {
  1328. console.log.apply(console, data);
  1329. }];
  1330. ah['console_error'] = [function ahConsoleError(data) {
  1331. console.error.apply(console, data);
  1332. }];
  1333. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1334. UnsupportedManager.notify(data);
  1335. }];
  1336. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1337. var data = event.data;
  1338. if (data.isReply) {
  1339. var callbackId = data.callbackId;
  1340. if (data.callbackId in callbacksCapabilities) {
  1341. var callback = callbacksCapabilities[callbackId];
  1342. delete callbacksCapabilities[callbackId];
  1343. if ('error' in data) {
  1344. callback.reject(data.error);
  1345. } else {
  1346. callback.resolve(data.data);
  1347. }
  1348. } else {
  1349. error('Cannot resolve callback ' + callbackId);
  1350. }
  1351. } else if (data.action in ah) {
  1352. var action = ah[data.action];
  1353. if (data.callbackId) {
  1354. Promise.resolve().then(function () {
  1355. return action[0].call(action[1], data.data);
  1356. }).then(function (result) {
  1357. comObj.postMessage({
  1358. isReply: true,
  1359. callbackId: data.callbackId,
  1360. data: result
  1361. });
  1362. }, function (reason) {
  1363. comObj.postMessage({
  1364. isReply: true,
  1365. callbackId: data.callbackId,
  1366. error: reason
  1367. });
  1368. });
  1369. } else {
  1370. action[0].call(action[1], data.data);
  1371. }
  1372. } else {
  1373. error('Unknown action from worker: ' + data.action);
  1374. }
  1375. };
  1376. }
  1377. MessageHandler.prototype = {
  1378. on: function messageHandlerOn(actionName, handler, scope) {
  1379. var ah = this.actionHandler;
  1380. if (ah[actionName]) {
  1381. error('There is already an actionName called "' + actionName + '"');
  1382. }
  1383. ah[actionName] = [handler, scope];
  1384. },
  1385. /**
  1386. * Sends a message to the comObj to invoke the action with the supplied data.
  1387. * @param {String} actionName Action to call.
  1388. * @param {JSON} data JSON data to send.
  1389. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1390. */
  1391. send: function messageHandlerSend(actionName, data, transfers) {
  1392. var message = {
  1393. action: actionName,
  1394. data: data
  1395. };
  1396. this.postMessage(message, transfers);
  1397. },
  1398. /**
  1399. * Sends a message to the comObj to invoke the action with the supplied data.
  1400. * Expects that other side will callback with the response.
  1401. * @param {String} actionName Action to call.
  1402. * @param {JSON} data JSON data to send.
  1403. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1404. * @returns {Promise} Promise to be resolved with response data.
  1405. */
  1406. sendWithPromise:
  1407. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1408. var callbackId = this.callbackIndex++;
  1409. var message = {
  1410. action: actionName,
  1411. data: data,
  1412. callbackId: callbackId
  1413. };
  1414. var capability = createPromiseCapability();
  1415. this.callbacksCapabilities[callbackId] = capability;
  1416. try {
  1417. this.postMessage(message, transfers);
  1418. } catch (e) {
  1419. capability.reject(e);
  1420. }
  1421. return capability.promise;
  1422. },
  1423. /**
  1424. * Sends raw message to the comObj.
  1425. * @private
  1426. * @param message {Object} Raw message.
  1427. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1428. */
  1429. postMessage: function (message, transfers) {
  1430. if (transfers && this.postMessageTransfers) {
  1431. this.comObj.postMessage(message, transfers);
  1432. } else {
  1433. this.comObj.postMessage(message);
  1434. }
  1435. }
  1436. };
  1437. function loadJpegStream(id, imageUrl, objs) {
  1438. var img = new Image();
  1439. img.onload = (function loadJpegStream_onloadClosure() {
  1440. objs.resolve(id, img);
  1441. });
  1442. img.onerror = (function loadJpegStream_onerrorClosure() {
  1443. objs.resolve(id, null);
  1444. warn('Error during JPEG image loading');
  1445. });
  1446. img.src = imageUrl;
  1447. }
  1448. var NetworkManager = (function NetworkManagerClosure() {
  1449. var OK_RESPONSE = 200;
  1450. var PARTIAL_CONTENT_RESPONSE = 206;
  1451. function NetworkManager(url, args) {
  1452. this.url = url;
  1453. args = args || {};
  1454. this.isHttp = /^https?:/i.test(url);
  1455. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1456. this.withCredentials = args.withCredentials || false;
  1457. this.getXhr = args.getXhr ||
  1458. function NetworkManager_getXhr() {
  1459. return new XMLHttpRequest();
  1460. };
  1461. this.currXhrId = 0;
  1462. this.pendingRequests = {};
  1463. this.loadedRequests = {};
  1464. }
  1465. function getArrayBuffer(xhr) {
  1466. var data = xhr.response;
  1467. if (typeof data !== 'string') {
  1468. return data;
  1469. }
  1470. var length = data.length;
  1471. var array = new Uint8Array(length);
  1472. for (var i = 0; i < length; i++) {
  1473. array[i] = data.charCodeAt(i) & 0xFF;
  1474. }
  1475. return array.buffer;
  1476. }
  1477. NetworkManager.prototype = {
  1478. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1479. var args = {
  1480. begin: begin,
  1481. end: end
  1482. };
  1483. for (var prop in listeners) {
  1484. args[prop] = listeners[prop];
  1485. }
  1486. return this.request(args);
  1487. },
  1488. requestFull: function NetworkManager_requestFull(listeners) {
  1489. return this.request(listeners);
  1490. },
  1491. request: function NetworkManager_request(args) {
  1492. var xhr = this.getXhr();
  1493. var xhrId = this.currXhrId++;
  1494. var pendingRequest = this.pendingRequests[xhrId] = {
  1495. xhr: xhr
  1496. };
  1497. xhr.open('GET', this.url);
  1498. xhr.withCredentials = this.withCredentials;
  1499. for (var property in this.httpHeaders) {
  1500. var value = this.httpHeaders[property];
  1501. if (typeof value === 'undefined') {
  1502. continue;
  1503. }
  1504. xhr.setRequestHeader(property, value);
  1505. }
  1506. if (this.isHttp && 'begin' in args && 'end' in args) {
  1507. var rangeStr = args.begin + '-' + (args.end - 1);
  1508. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1509. pendingRequest.expectedStatus = 206;
  1510. } else {
  1511. pendingRequest.expectedStatus = 200;
  1512. }
  1513. if (args.onProgressiveData) {
  1514. // Some legacy browsers might throw an exception.
  1515. try {
  1516. xhr.responseType = 'moz-chunked-arraybuffer';
  1517. } catch(e) {}
  1518. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1519. pendingRequest.onProgressiveData = args.onProgressiveData;
  1520. pendingRequest.mozChunked = true;
  1521. } else {
  1522. xhr.responseType = 'arraybuffer';
  1523. }
  1524. } else {
  1525. xhr.responseType = 'arraybuffer';
  1526. }
  1527. if (args.onError) {
  1528. xhr.onerror = function(evt) {
  1529. args.onError(xhr.status);
  1530. };
  1531. }
  1532. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1533. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1534. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1535. pendingRequest.onDone = args.onDone;
  1536. pendingRequest.onError = args.onError;
  1537. pendingRequest.onProgress = args.onProgress;
  1538. xhr.send(null);
  1539. return xhrId;
  1540. },
  1541. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1542. var pendingRequest = this.pendingRequests[xhrId];
  1543. if (!pendingRequest) {
  1544. // Maybe abortRequest was called...
  1545. return;
  1546. }
  1547. if (pendingRequest.mozChunked) {
  1548. var chunk = getArrayBuffer(pendingRequest.xhr);
  1549. pendingRequest.onProgressiveData(chunk);
  1550. }
  1551. var onProgress = pendingRequest.onProgress;
  1552. if (onProgress) {
  1553. onProgress(evt);
  1554. }
  1555. },
  1556. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1557. var pendingRequest = this.pendingRequests[xhrId];
  1558. if (!pendingRequest) {
  1559. // Maybe abortRequest was called...
  1560. return;
  1561. }
  1562. var xhr = pendingRequest.xhr;
  1563. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1564. pendingRequest.onHeadersReceived();
  1565. delete pendingRequest.onHeadersReceived;
  1566. }
  1567. if (xhr.readyState !== 4) {
  1568. return;
  1569. }
  1570. if (!(xhrId in this.pendingRequests)) {
  1571. // The XHR request might have been aborted in onHeadersReceived()
  1572. // callback, in which case we should abort request
  1573. return;
  1574. }
  1575. delete this.pendingRequests[xhrId];
  1576. // success status == 0 can be on ftp, file and other protocols
  1577. if (xhr.status === 0 && this.isHttp) {
  1578. if (pendingRequest.onError) {
  1579. pendingRequest.onError(xhr.status);
  1580. }
  1581. return;
  1582. }
  1583. var xhrStatus = xhr.status || OK_RESPONSE;
  1584. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1585. // "A server MAY ignore the Range header". This means it's possible to
  1586. // get a 200 rather than a 206 response from a range request.
  1587. var ok_response_on_range_request =
  1588. xhrStatus === OK_RESPONSE &&
  1589. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1590. if (!ok_response_on_range_request &&
  1591. xhrStatus !== pendingRequest.expectedStatus) {
  1592. if (pendingRequest.onError) {
  1593. pendingRequest.onError(xhr.status);
  1594. }
  1595. return;
  1596. }
  1597. this.loadedRequests[xhrId] = true;
  1598. var chunk = getArrayBuffer(xhr);
  1599. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1600. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1601. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1602. var begin = parseInt(matches[1], 10);
  1603. pendingRequest.onDone({
  1604. begin: begin,
  1605. chunk: chunk
  1606. });
  1607. } else if (pendingRequest.onProgressiveData) {
  1608. pendingRequest.onDone(null);
  1609. } else {
  1610. pendingRequest.onDone({
  1611. begin: 0,
  1612. chunk: chunk
  1613. });
  1614. }
  1615. },
  1616. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1617. for (var xhrId in this.pendingRequests) {
  1618. return true;
  1619. }
  1620. return false;
  1621. },
  1622. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1623. return this.pendingRequests[xhrId].xhr;
  1624. },
  1625. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1626. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1627. },
  1628. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1629. return xhrId in this.pendingRequests;
  1630. },
  1631. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1632. return xhrId in this.loadedRequests;
  1633. },
  1634. abortAllRequests: function NetworkManager_abortAllRequests() {
  1635. for (var xhrId in this.pendingRequests) {
  1636. this.abortRequest(xhrId | 0);
  1637. }
  1638. },
  1639. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1640. var xhr = this.pendingRequests[xhrId].xhr;
  1641. delete this.pendingRequests[xhrId];
  1642. xhr.abort();
  1643. }
  1644. };
  1645. return NetworkManager;
  1646. })();
  1647. var ChunkedStream = (function ChunkedStreamClosure() {
  1648. function ChunkedStream(length, chunkSize, manager) {
  1649. this.bytes = new Uint8Array(length);
  1650. this.start = 0;
  1651. this.pos = 0;
  1652. this.end = length;
  1653. this.chunkSize = chunkSize;
  1654. this.loadedChunks = [];
  1655. this.numChunksLoaded = 0;
  1656. this.numChunks = Math.ceil(length / chunkSize);
  1657. this.manager = manager;
  1658. this.progressiveDataLength = 0;
  1659. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1660. }
  1661. // required methods for a stream. if a particular stream does not
  1662. // implement these, an error should be thrown
  1663. ChunkedStream.prototype = {
  1664. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1665. var chunks = [];
  1666. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1667. if (!this.loadedChunks[chunk]) {
  1668. chunks.push(chunk);
  1669. }
  1670. }
  1671. return chunks;
  1672. },
  1673. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1674. return [this];
  1675. },
  1676. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1677. return this.numChunksLoaded === this.numChunks;
  1678. },
  1679. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1680. var end = begin + chunk.byteLength;
  1681. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1682. // Using this.length is inaccurate here since this.start can be moved
  1683. // See ChunkedStream.moveStart()
  1684. var length = this.bytes.length;
  1685. assert(end % this.chunkSize === 0 || end === length,
  1686. 'Bad end offset: ' + end);
  1687. this.bytes.set(new Uint8Array(chunk), begin);
  1688. var chunkSize = this.chunkSize;
  1689. var beginChunk = Math.floor(begin / chunkSize);
  1690. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1691. var curChunk;
  1692. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1693. if (!this.loadedChunks[curChunk]) {
  1694. this.loadedChunks[curChunk] = true;
  1695. ++this.numChunksLoaded;
  1696. }
  1697. }
  1698. },
  1699. onReceiveProgressiveData:
  1700. function ChunkedStream_onReceiveProgressiveData(data) {
  1701. var position = this.progressiveDataLength;
  1702. var beginChunk = Math.floor(position / this.chunkSize);
  1703. this.bytes.set(new Uint8Array(data), position);
  1704. position += data.byteLength;
  1705. this.progressiveDataLength = position;
  1706. var endChunk = position >= this.end ? this.numChunks :
  1707. Math.floor(position / this.chunkSize);
  1708. var curChunk;
  1709. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1710. if (!this.loadedChunks[curChunk]) {
  1711. this.loadedChunks[curChunk] = true;
  1712. ++this.numChunksLoaded;
  1713. }
  1714. }
  1715. },
  1716. ensureByte: function ChunkedStream_ensureByte(pos) {
  1717. var chunk = Math.floor(pos / this.chunkSize);
  1718. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1719. return;
  1720. }
  1721. if (!this.loadedChunks[chunk]) {
  1722. throw new MissingDataException(pos, pos + 1);
  1723. }
  1724. this.lastSuccessfulEnsureByteChunk = chunk;
  1725. },
  1726. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1727. if (begin >= end) {
  1728. return;
  1729. }
  1730. if (end <= this.progressiveDataLength) {
  1731. return;
  1732. }
  1733. var chunkSize = this.chunkSize;
  1734. var beginChunk = Math.floor(begin / chunkSize);
  1735. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1736. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1737. if (!this.loadedChunks[chunk]) {
  1738. throw new MissingDataException(begin, end);
  1739. }
  1740. }
  1741. },
  1742. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1743. var chunk, n;
  1744. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1745. if (!this.loadedChunks[chunk]) {
  1746. return chunk;
  1747. }
  1748. }
  1749. // Wrap around to beginning
  1750. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1751. if (!this.loadedChunks[chunk]) {
  1752. return chunk;
  1753. }
  1754. }
  1755. return null;
  1756. },
  1757. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1758. return !!this.loadedChunks[chunk];
  1759. },
  1760. get length() {
  1761. return this.end - this.start;
  1762. },
  1763. get isEmpty() {
  1764. return this.length === 0;
  1765. },
  1766. getByte: function ChunkedStream_getByte() {
  1767. var pos = this.pos;
  1768. if (pos >= this.end) {
  1769. return -1;
  1770. }
  1771. this.ensureByte(pos);
  1772. return this.bytes[this.pos++];
  1773. },
  1774. getUint16: function ChunkedStream_getUint16() {
  1775. var b0 = this.getByte();
  1776. var b1 = this.getByte();
  1777. return (b0 << 8) + b1;
  1778. },
  1779. getInt32: function ChunkedStream_getInt32() {
  1780. var b0 = this.getByte();
  1781. var b1 = this.getByte();
  1782. var b2 = this.getByte();
  1783. var b3 = this.getByte();
  1784. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1785. },
  1786. // returns subarray of original buffer
  1787. // should only be read
  1788. getBytes: function ChunkedStream_getBytes(length) {
  1789. var bytes = this.bytes;
  1790. var pos = this.pos;
  1791. var strEnd = this.end;
  1792. if (!length) {
  1793. this.ensureRange(pos, strEnd);
  1794. return bytes.subarray(pos, strEnd);
  1795. }
  1796. var end = pos + length;
  1797. if (end > strEnd) {
  1798. end = strEnd;
  1799. }
  1800. this.ensureRange(pos, end);
  1801. this.pos = end;
  1802. return bytes.subarray(pos, end);
  1803. },
  1804. peekByte: function ChunkedStream_peekByte() {
  1805. var peekedByte = this.getByte();
  1806. this.pos--;
  1807. return peekedByte;
  1808. },
  1809. peekBytes: function ChunkedStream_peekBytes(length) {
  1810. var bytes = this.getBytes(length);
  1811. this.pos -= bytes.length;
  1812. return bytes;
  1813. },
  1814. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1815. this.ensureRange(begin, end);
  1816. return this.bytes.subarray(begin, end);
  1817. },
  1818. skip: function ChunkedStream_skip(n) {
  1819. if (!n) {
  1820. n = 1;
  1821. }
  1822. this.pos += n;
  1823. },
  1824. reset: function ChunkedStream_reset() {
  1825. this.pos = this.start;
  1826. },
  1827. moveStart: function ChunkedStream_moveStart() {
  1828. this.start = this.pos;
  1829. },
  1830. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1831. this.ensureRange(start, start + length);
  1832. function ChunkedStreamSubstream() {}
  1833. ChunkedStreamSubstream.prototype = Object.create(this);
  1834. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1835. var chunkSize = this.chunkSize;
  1836. var beginChunk = Math.floor(this.start / chunkSize);
  1837. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1838. var missingChunks = [];
  1839. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1840. if (!this.loadedChunks[chunk]) {
  1841. missingChunks.push(chunk);
  1842. }
  1843. }
  1844. return missingChunks;
  1845. };
  1846. var subStream = new ChunkedStreamSubstream();
  1847. subStream.pos = subStream.start = start;
  1848. subStream.end = start + length || this.end;
  1849. subStream.dict = dict;
  1850. return subStream;
  1851. },
  1852. isStream: true
  1853. };
  1854. return ChunkedStream;
  1855. })();
  1856. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1857. function ChunkedStreamManager(length, chunkSize, url, args) {
  1858. this.stream = new ChunkedStream(length, chunkSize, this);
  1859. this.length = length;
  1860. this.chunkSize = chunkSize;
  1861. this.url = url;
  1862. this.disableAutoFetch = args.disableAutoFetch;
  1863. var msgHandler = this.msgHandler = args.msgHandler;
  1864. if (args.chunkedViewerLoading) {
  1865. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1866. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1867. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1868. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1869. };
  1870. } else {
  1871. var getXhr = function getXhr() {
  1872. return new XMLHttpRequest();
  1873. };
  1874. this.networkManager = new NetworkManager(this.url, {
  1875. getXhr: getXhr,
  1876. httpHeaders: args.httpHeaders,
  1877. withCredentials: args.withCredentials
  1878. });
  1879. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1880. this.networkManager.requestRange(begin, end, {
  1881. onDone: this.onReceiveData.bind(this),
  1882. onProgress: this.onProgress.bind(this)
  1883. });
  1884. };
  1885. }
  1886. this.currRequestId = 0;
  1887. this.chunksNeededByRequest = {};
  1888. this.requestsByChunk = {};
  1889. this.callbacksByRequest = {};
  1890. this.progressiveDataLength = 0;
  1891. this._loadedStreamCapability = createPromiseCapability();
  1892. if (args.initialData) {
  1893. this.onReceiveData({chunk: args.initialData});
  1894. }
  1895. }
  1896. ChunkedStreamManager.prototype = {
  1897. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1898. return this._loadedStreamCapability.promise;
  1899. },
  1900. // Get all the chunks that are not yet loaded and groups them into
  1901. // contiguous ranges to load in as few requests as possible
  1902. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1903. var missingChunks = this.stream.getMissingChunks();
  1904. this.requestChunks(missingChunks);
  1905. return this._loadedStreamCapability.promise;
  1906. },
  1907. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1908. callback) {
  1909. var requestId = this.currRequestId++;
  1910. var chunksNeeded;
  1911. var i, ii;
  1912. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1913. for (i = 0, ii = chunks.length; i < ii; i++) {
  1914. if (!this.stream.hasChunk(chunks[i])) {
  1915. chunksNeeded[chunks[i]] = true;
  1916. }
  1917. }
  1918. if (isEmptyObj(chunksNeeded)) {
  1919. if (callback) {
  1920. callback();
  1921. }
  1922. return;
  1923. }
  1924. this.callbacksByRequest[requestId] = callback;
  1925. var chunksToRequest = [];
  1926. for (var chunk in chunksNeeded) {
  1927. chunk = chunk | 0;
  1928. if (!(chunk in this.requestsByChunk)) {
  1929. this.requestsByChunk[chunk] = [];
  1930. chunksToRequest.push(chunk);
  1931. }
  1932. this.requestsByChunk[chunk].push(requestId);
  1933. }
  1934. if (!chunksToRequest.length) {
  1935. return;
  1936. }
  1937. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1938. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1939. var groupedChunk = groupedChunksToRequest[i];
  1940. var begin = groupedChunk.beginChunk * this.chunkSize;
  1941. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1942. this.sendRequest(begin, end);
  1943. }
  1944. },
  1945. getStream: function ChunkedStreamManager_getStream() {
  1946. return this.stream;
  1947. },
  1948. // Loads any chunks in the requested range that are not yet loaded
  1949. requestRange: function ChunkedStreamManager_requestRange(
  1950. begin, end, callback) {
  1951. end = Math.min(end, this.length);
  1952. var beginChunk = this.getBeginChunk(begin);
  1953. var endChunk = this.getEndChunk(end);
  1954. var chunks = [];
  1955. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1956. chunks.push(chunk);
  1957. }
  1958. this.requestChunks(chunks, callback);
  1959. },
  1960. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1961. callback) {
  1962. ranges = ranges || [];
  1963. var chunksToRequest = [];
  1964. for (var i = 0; i < ranges.length; i++) {
  1965. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1966. var endChunk = this.getEndChunk(ranges[i].end);
  1967. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1968. if (chunksToRequest.indexOf(chunk) < 0) {
  1969. chunksToRequest.push(chunk);
  1970. }
  1971. }
  1972. }
  1973. chunksToRequest.sort(function(a, b) { return a - b; });
  1974. this.requestChunks(chunksToRequest, callback);
  1975. },
  1976. // Groups a sorted array of chunks into as few continguous larger
  1977. // chunks as possible
  1978. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1979. var groupedChunks = [];
  1980. var beginChunk = -1;
  1981. var prevChunk = -1;
  1982. for (var i = 0; i < chunks.length; ++i) {
  1983. var chunk = chunks[i];
  1984. if (beginChunk < 0) {
  1985. beginChunk = chunk;
  1986. }
  1987. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1988. groupedChunks.push({ beginChunk: beginChunk,
  1989. endChunk: prevChunk + 1 });
  1990. beginChunk = chunk;
  1991. }
  1992. if (i + 1 === chunks.length) {
  1993. groupedChunks.push({ beginChunk: beginChunk,
  1994. endChunk: chunk + 1 });
  1995. }
  1996. prevChunk = chunk;
  1997. }
  1998. return groupedChunks;
  1999. },
  2000. onProgress: function ChunkedStreamManager_onProgress(args) {
  2001. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2002. args.loaded);
  2003. this.msgHandler.send('DocProgress', {
  2004. loaded: bytesLoaded,
  2005. total: this.length
  2006. });
  2007. },
  2008. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2009. var chunk = args.chunk;
  2010. var isProgressive = args.begin === undefined;
  2011. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2012. var end = begin + chunk.byteLength;
  2013. var beginChunk = Math.floor(begin / this.chunkSize);
  2014. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2015. Math.ceil(end / this.chunkSize);
  2016. if (isProgressive) {
  2017. this.stream.onReceiveProgressiveData(chunk);
  2018. this.progressiveDataLength = end;
  2019. } else {
  2020. this.stream.onReceiveData(begin, chunk);
  2021. }
  2022. if (this.stream.allChunksLoaded()) {
  2023. this._loadedStreamCapability.resolve(this.stream);
  2024. }
  2025. var loadedRequests = [];
  2026. var i, requestId;
  2027. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2028. // The server might return more chunks than requested
  2029. var requestIds = this.requestsByChunk[chunk] || [];
  2030. delete this.requestsByChunk[chunk];
  2031. for (i = 0; i < requestIds.length; ++i) {
  2032. requestId = requestIds[i];
  2033. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2034. if (chunk in chunksNeeded) {
  2035. delete chunksNeeded[chunk];
  2036. }
  2037. if (!isEmptyObj(chunksNeeded)) {
  2038. continue;
  2039. }
  2040. loadedRequests.push(requestId);
  2041. }
  2042. }
  2043. // If there are no pending requests, automatically fetch the next
  2044. // unfetched chunk of the PDF
  2045. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2046. var nextEmptyChunk;
  2047. if (this.stream.numChunksLoaded === 1) {
  2048. // This is a special optimization so that after fetching the first
  2049. // chunk, rather than fetching the second chunk, we fetch the last
  2050. // chunk.
  2051. var lastChunk = this.stream.numChunks - 1;
  2052. if (!this.stream.hasChunk(lastChunk)) {
  2053. nextEmptyChunk = lastChunk;
  2054. }
  2055. } else {
  2056. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2057. }
  2058. if (isInt(nextEmptyChunk)) {
  2059. this.requestChunks([nextEmptyChunk]);
  2060. }
  2061. }
  2062. for (i = 0; i < loadedRequests.length; ++i) {
  2063. requestId = loadedRequests[i];
  2064. var callback = this.callbacksByRequest[requestId];
  2065. delete this.callbacksByRequest[requestId];
  2066. if (callback) {
  2067. callback();
  2068. }
  2069. }
  2070. this.msgHandler.send('DocProgress', {
  2071. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2072. total: this.length
  2073. });
  2074. },
  2075. onError: function ChunkedStreamManager_onError(err) {
  2076. this._loadedStreamCapability.reject(err);
  2077. },
  2078. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2079. var chunk = Math.floor(begin / this.chunkSize);
  2080. return chunk;
  2081. },
  2082. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2083. if (end % this.chunkSize === 0) {
  2084. return end / this.chunkSize;
  2085. }
  2086. // 0 -> 0
  2087. // 1 -> 1
  2088. // 99 -> 1
  2089. // 100 -> 1
  2090. // 101 -> 2
  2091. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2092. return chunk;
  2093. }
  2094. };
  2095. return ChunkedStreamManager;
  2096. })();
  2097. // The maximum number of bytes fetched per range request
  2098. var RANGE_CHUNK_SIZE = 65536;
  2099. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2100. var BasePdfManager = (function BasePdfManagerClosure() {
  2101. function BasePdfManager() {
  2102. throw new Error('Cannot initialize BaseManagerManager');
  2103. }
  2104. BasePdfManager.prototype = {
  2105. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2106. throw new NotImplementedException();
  2107. },
  2108. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2109. return this.ensure(this.pdfDocument, prop, args);
  2110. },
  2111. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2112. return this.ensure(this.pdfDocument.xref, prop, args);
  2113. },
  2114. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2115. return this.ensure(this.pdfDocument.catalog, prop, args);
  2116. },
  2117. getPage: function BasePdfManager_pagePage(pageIndex) {
  2118. return this.pdfDocument.getPage(pageIndex);
  2119. },
  2120. cleanup: function BasePdfManager_cleanup() {
  2121. return this.pdfDocument.cleanup();
  2122. },
  2123. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2124. return new NotImplementedException();
  2125. },
  2126. requestRange: function BasePdfManager_ensure(begin, end) {
  2127. return new NotImplementedException();
  2128. },
  2129. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2130. return new NotImplementedException();
  2131. },
  2132. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2133. return new NotImplementedException();
  2134. },
  2135. updatePassword: function BasePdfManager_updatePassword(password) {
  2136. this.pdfDocument.xref.password = this.password = password;
  2137. if (this._passwordChangedCapability) {
  2138. this._passwordChangedCapability.resolve();
  2139. }
  2140. },
  2141. passwordChanged: function BasePdfManager_passwordChanged() {
  2142. this._passwordChangedCapability = createPromiseCapability();
  2143. return this._passwordChangedCapability.promise;
  2144. },
  2145. terminate: function BasePdfManager_terminate() {
  2146. return new NotImplementedException();
  2147. }
  2148. };
  2149. return BasePdfManager;
  2150. })();
  2151. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2152. function LocalPdfManager(data, password) {
  2153. var stream = new Stream(data);
  2154. this.pdfDocument = new PDFDocument(this, stream, password);
  2155. this._loadedStreamCapability = createPromiseCapability();
  2156. this._loadedStreamCapability.resolve(stream);
  2157. }
  2158. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2159. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2160. LocalPdfManager.prototype.ensure =
  2161. function LocalPdfManager_ensure(obj, prop, args) {
  2162. return new Promise(function (resolve, reject) {
  2163. try {
  2164. var value = obj[prop];
  2165. var result;
  2166. if (typeof value === 'function') {
  2167. result = value.apply(obj, args);
  2168. } else {
  2169. result = value;
  2170. }
  2171. resolve(result);
  2172. } catch (e) {
  2173. reject(e);
  2174. }
  2175. });
  2176. };
  2177. LocalPdfManager.prototype.requestRange =
  2178. function LocalPdfManager_requestRange(begin, end) {
  2179. return Promise.resolve();
  2180. };
  2181. LocalPdfManager.prototype.requestLoadedStream =
  2182. function LocalPdfManager_requestLoadedStream() {
  2183. };
  2184. LocalPdfManager.prototype.onLoadedStream =
  2185. function LocalPdfManager_getLoadedStream() {
  2186. return this._loadedStreamCapability.promise;
  2187. };
  2188. LocalPdfManager.prototype.terminate =
  2189. function LocalPdfManager_terminate() {
  2190. return;
  2191. };
  2192. return LocalPdfManager;
  2193. })();
  2194. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2195. function NetworkPdfManager(args, msgHandler) {
  2196. this.msgHandler = msgHandler;
  2197. var params = {
  2198. msgHandler: msgHandler,
  2199. httpHeaders: args.httpHeaders,
  2200. withCredentials: args.withCredentials,
  2201. chunkedViewerLoading: args.chunkedViewerLoading,
  2202. disableAutoFetch: args.disableAutoFetch,
  2203. initialData: args.initialData
  2204. };
  2205. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2206. args.url, params);
  2207. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2208. args.password);
  2209. }
  2210. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2211. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2212. NetworkPdfManager.prototype.ensure =
  2213. function NetworkPdfManager_ensure(obj, prop, args) {
  2214. var pdfManager = this;
  2215. return new Promise(function (resolve, reject) {
  2216. function ensureHelper() {
  2217. try {
  2218. var result;
  2219. var value = obj[prop];
  2220. if (typeof value === 'function') {
  2221. result = value.apply(obj, args);
  2222. } else {
  2223. result = value;
  2224. }
  2225. resolve(result);
  2226. } catch(e) {
  2227. if (!(e instanceof MissingDataException)) {
  2228. reject(e);
  2229. return;
  2230. }
  2231. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2232. }
  2233. }
  2234. ensureHelper();
  2235. });
  2236. };
  2237. NetworkPdfManager.prototype.requestRange =
  2238. function NetworkPdfManager_requestRange(begin, end) {
  2239. return new Promise(function (resolve) {
  2240. this.streamManager.requestRange(begin, end, function() {
  2241. resolve();
  2242. });
  2243. }.bind(this));
  2244. };
  2245. NetworkPdfManager.prototype.requestLoadedStream =
  2246. function NetworkPdfManager_requestLoadedStream() {
  2247. this.streamManager.requestAllChunks();
  2248. };
  2249. NetworkPdfManager.prototype.sendProgressiveData =
  2250. function NetworkPdfManager_sendProgressiveData(chunk) {
  2251. this.streamManager.onReceiveData({ chunk: chunk });
  2252. };
  2253. NetworkPdfManager.prototype.onLoadedStream =
  2254. function NetworkPdfManager_getLoadedStream() {
  2255. return this.streamManager.onLoadedStream();
  2256. };
  2257. NetworkPdfManager.prototype.terminate =
  2258. function NetworkPdfManager_terminate() {
  2259. this.streamManager.networkManager.abortAllRequests();
  2260. };
  2261. return NetworkPdfManager;
  2262. })();
  2263. var Page = (function PageClosure() {
  2264. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2265. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2266. this.pdfManager = pdfManager;
  2267. this.pageIndex = pageIndex;
  2268. this.pageDict = pageDict;
  2269. this.xref = xref;
  2270. this.ref = ref;
  2271. this.fontCache = fontCache;
  2272. this.idCounters = {
  2273. obj: 0
  2274. };
  2275. this.resourcesPromise = null;
  2276. }
  2277. Page.prototype = {
  2278. getPageProp: function Page_getPageProp(key) {
  2279. return this.pageDict.get(key);
  2280. },
  2281. getInheritedPageProp: function Page_inheritPageProp(key) {
  2282. var dict = this.pageDict;
  2283. var value = dict.get(key);
  2284. while (value === undefined) {
  2285. dict = dict.get('Parent');
  2286. if (!dict) {
  2287. break;
  2288. }
  2289. value = dict.get(key);
  2290. }
  2291. return value;
  2292. },
  2293. get content() {
  2294. return this.getPageProp('Contents');
  2295. },
  2296. get resources() {
  2297. var value = this.getInheritedPageProp('Resources');
  2298. // For robustness: The spec states that a \Resources entry has to be
  2299. // present, but can be empty. Some document omit it still. In this case
  2300. // return an empty dictionary:
  2301. if (value === undefined) {
  2302. value = Dict.empty;
  2303. }
  2304. return shadow(this, 'resources', value);
  2305. },
  2306. get mediaBox() {
  2307. var obj = this.getInheritedPageProp('MediaBox');
  2308. // Reset invalid media box to letter size.
  2309. if (!isArray(obj) || obj.length !== 4) {
  2310. obj = LETTER_SIZE_MEDIABOX;
  2311. }
  2312. return shadow(this, 'mediaBox', obj);
  2313. },
  2314. get view() {
  2315. var mediaBox = this.mediaBox;
  2316. var cropBox = this.getInheritedPageProp('CropBox');
  2317. if (!isArray(cropBox) || cropBox.length !== 4) {
  2318. return shadow(this, 'view', mediaBox);
  2319. }
  2320. // From the spec, 6th ed., p.963:
  2321. // "The crop, bleed, trim, and art boxes should not ordinarily
  2322. // extend beyond the boundaries of the media box. If they do, they are
  2323. // effectively reduced to their intersection with the media box."
  2324. cropBox = Util.intersect(cropBox, mediaBox);
  2325. if (!cropBox) {
  2326. return shadow(this, 'view', mediaBox);
  2327. }
  2328. return shadow(this, 'view', cropBox);
  2329. },
  2330. get annotationRefs() {
  2331. return shadow(this, 'annotationRefs',
  2332. this.getInheritedPageProp('Annots'));
  2333. },
  2334. get rotate() {
  2335. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2336. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2337. if (rotate % 90 !== 0) {
  2338. rotate = 0;
  2339. } else if (rotate >= 360) {
  2340. rotate = rotate % 360;
  2341. } else if (rotate < 0) {
  2342. // The spec doesn't cover negatives, assume its counterclockwise
  2343. // rotation. The following is the other implementation of modulo.
  2344. rotate = ((rotate % 360) + 360) % 360;
  2345. }
  2346. return shadow(this, 'rotate', rotate);
  2347. },
  2348. getContentStream: function Page_getContentStream() {
  2349. var content = this.content;
  2350. var stream;
  2351. if (isArray(content)) {
  2352. // fetching items
  2353. var xref = this.xref;
  2354. var i, n = content.length;
  2355. var streams = [];
  2356. for (i = 0; i < n; ++i) {
  2357. streams.push(xref.fetchIfRef(content[i]));
  2358. }
  2359. stream = new StreamsSequenceStream(streams);
  2360. } else if (isStream(content)) {
  2361. stream = content;
  2362. } else {
  2363. // replacing non-existent page content with empty one
  2364. stream = new NullStream();
  2365. }
  2366. return stream;
  2367. },
  2368. loadResources: function Page_loadResources(keys) {
  2369. if (!this.resourcesPromise) {
  2370. // TODO: add async getInheritedPageProp and remove this.
  2371. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2372. }
  2373. return this.resourcesPromise.then(function resourceSuccess() {
  2374. var objectLoader = new ObjectLoader(this.resources.map,
  2375. keys,
  2376. this.xref);
  2377. return objectLoader.load();
  2378. }.bind(this));
  2379. },
  2380. getOperatorList: function Page_getOperatorList(handler, intent) {
  2381. var self = this;
  2382. var pdfManager = this.pdfManager;
  2383. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2384. []);
  2385. var resourcesPromise = this.loadResources([
  2386. 'ExtGState',
  2387. 'ColorSpace',
  2388. 'Pattern',
  2389. 'Shading',
  2390. 'XObject',
  2391. 'Font'
  2392. // ProcSet
  2393. // Properties
  2394. ]);
  2395. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2396. handler, this.pageIndex,
  2397. 'p' + this.pageIndex + '_',
  2398. this.idCounters,
  2399. this.fontCache);
  2400. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2401. var pageListPromise = dataPromises.then(function(data) {
  2402. var contentStream = data[0];
  2403. var opList = new OperatorList(intent, handler, self.pageIndex);
  2404. handler.send('StartRenderPage', {
  2405. transparency: partialEvaluator.hasBlendModes(self.resources),
  2406. pageIndex: self.pageIndex,
  2407. intent: intent
  2408. });
  2409. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2410. opList).then(function () {
  2411. return opList;
  2412. });
  2413. });
  2414. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2415. return Promise.all([pageListPromise, annotationsPromise]).then(
  2416. function(datas) {
  2417. var pageOpList = datas[0];
  2418. var annotations = datas[1];
  2419. if (annotations.length === 0) {
  2420. pageOpList.flush(true);
  2421. return pageOpList;
  2422. }
  2423. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2424. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2425. return annotationsReadyPromise.then(function () {
  2426. pageOpList.flush(true);
  2427. return pageOpList;
  2428. });
  2429. });
  2430. },
  2431. extractTextContent: function Page_extractTextContent() {
  2432. var handler = {
  2433. on: function nullHandlerOn() {},
  2434. send: function nullHandlerSend() {}
  2435. };
  2436. var self = this;
  2437. var pdfManager = this.pdfManager;
  2438. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2439. []);
  2440. var resourcesPromise = this.loadResources([
  2441. 'ExtGState',
  2442. 'XObject',
  2443. 'Font'
  2444. ]);
  2445. var dataPromises = Promise.all([contentStreamPromise,
  2446. resourcesPromise]);
  2447. return dataPromises.then(function(data) {
  2448. var contentStream = data[0];
  2449. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2450. handler, self.pageIndex,
  2451. 'p' + self.pageIndex + '_',
  2452. self.idCounters,
  2453. self.fontCache);
  2454. return partialEvaluator.getTextContent(contentStream,
  2455. self.resources);
  2456. });
  2457. },
  2458. getAnnotationsData: function Page_getAnnotationsData() {
  2459. var annotations = this.annotations;
  2460. var annotationsData = [];
  2461. for (var i = 0, n = annotations.length; i < n; ++i) {
  2462. annotationsData.push(annotations[i].getData());
  2463. }
  2464. return annotationsData;
  2465. },
  2466. get annotations() {
  2467. var annotations = [];
  2468. var annotationRefs = (this.annotationRefs || []);
  2469. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2470. var annotationRef = annotationRefs[i];
  2471. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2472. if (annotation) {
  2473. annotations.push(annotation);
  2474. }
  2475. }
  2476. return shadow(this, 'annotations', annotations);
  2477. }
  2478. };
  2479. return Page;
  2480. })();
  2481. /**
  2482. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2483. * `PDFDoc`, this one doesn't have any job management code.
  2484. * Right now there exists one PDFDocument on the main thread + one object
  2485. * for each worker. If there is no worker support enabled, there are two
  2486. * `PDFDocument` objects on the main thread created.
  2487. */
  2488. var PDFDocument = (function PDFDocumentClosure() {
  2489. var FINGERPRINT_FIRST_BYTES = 1024;
  2490. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2491. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2492. function PDFDocument(pdfManager, arg, password) {
  2493. if (isStream(arg)) {
  2494. init.call(this, pdfManager, arg, password);
  2495. } else if (isArrayBuffer(arg)) {
  2496. init.call(this, pdfManager, new Stream(arg), password);
  2497. } else {
  2498. error('PDFDocument: Unknown argument type');
  2499. }
  2500. }
  2501. function init(pdfManager, stream, password) {
  2502. assert(stream.length > 0, 'stream must have data');
  2503. this.pdfManager = pdfManager;
  2504. this.stream = stream;
  2505. var xref = new XRef(this.stream, password, pdfManager);
  2506. this.xref = xref;
  2507. }
  2508. function find(stream, needle, limit, backwards) {
  2509. var pos = stream.pos;
  2510. var end = stream.end;
  2511. var strBuf = [];
  2512. if (pos + limit > end) {
  2513. limit = end - pos;
  2514. }
  2515. for (var n = 0; n < limit; ++n) {
  2516. strBuf.push(String.fromCharCode(stream.getByte()));
  2517. }
  2518. var str = strBuf.join('');
  2519. stream.pos = pos;
  2520. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2521. if (index === -1) {
  2522. return false; /* not found */
  2523. }
  2524. stream.pos += index;
  2525. return true; /* found */
  2526. }
  2527. var DocumentInfoValidators = {
  2528. get entries() {
  2529. // Lazily build this since all the validation functions below are not
  2530. // defined until after this file loads.
  2531. return shadow(this, 'entries', {
  2532. Title: isString,
  2533. Author: isString,
  2534. Subject: isString,
  2535. Keywords: isString,
  2536. Creator: isString,
  2537. Producer: isString,
  2538. CreationDate: isString,
  2539. ModDate: isString,
  2540. Trapped: isName
  2541. });
  2542. }
  2543. };
  2544. PDFDocument.prototype = {
  2545. parse: function PDFDocument_parse(recoveryMode) {
  2546. this.setup(recoveryMode);
  2547. try {
  2548. // checking if AcroForm is present
  2549. this.acroForm = this.catalog.catDict.get('AcroForm');
  2550. if (this.acroForm) {
  2551. this.xfa = this.acroForm.get('XFA');
  2552. var fields = this.acroForm.get('Fields');
  2553. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2554. !this.xfa) {
  2555. // no fields and no XFA -- not a form (?)
  2556. this.acroForm = null;
  2557. }
  2558. }
  2559. } catch (ex) {
  2560. info('Something wrong with AcroForm entry');
  2561. this.acroForm = null;
  2562. }
  2563. },
  2564. get linearization() {
  2565. var linearization = null;
  2566. if (this.stream.length) {
  2567. try {
  2568. linearization = Linearization.create(this.stream);
  2569. } catch (err) {
  2570. if (err instanceof MissingDataException) {
  2571. throw err;
  2572. }
  2573. info(err);
  2574. }
  2575. }
  2576. // shadow the prototype getter with a data property
  2577. return shadow(this, 'linearization', linearization);
  2578. },
  2579. get startXRef() {
  2580. var stream = this.stream;
  2581. var startXRef = 0;
  2582. var linearization = this.linearization;
  2583. if (linearization) {
  2584. // Find end of first obj.
  2585. stream.reset();
  2586. if (find(stream, 'endobj', 1024)) {
  2587. startXRef = stream.pos + 6;
  2588. }
  2589. } else {
  2590. // Find startxref by jumping backward from the end of the file.
  2591. var step = 1024;
  2592. var found = false, pos = stream.end;
  2593. while (!found && pos > 0) {
  2594. pos -= step - 'startxref'.length;
  2595. if (pos < 0) {
  2596. pos = 0;
  2597. }
  2598. stream.pos = pos;
  2599. found = find(stream, 'startxref', step, true);
  2600. }
  2601. if (found) {
  2602. stream.skip(9);
  2603. var ch;
  2604. do {
  2605. ch = stream.getByte();
  2606. } while (Lexer.isSpace(ch));
  2607. var str = '';
  2608. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2609. str += String.fromCharCode(ch);
  2610. ch = stream.getByte();
  2611. }
  2612. startXRef = parseInt(str, 10);
  2613. if (isNaN(startXRef)) {
  2614. startXRef = 0;
  2615. }
  2616. }
  2617. }
  2618. // shadow the prototype getter with a data property
  2619. return shadow(this, 'startXRef', startXRef);
  2620. },
  2621. get mainXRefEntriesOffset() {
  2622. var mainXRefEntriesOffset = 0;
  2623. var linearization = this.linearization;
  2624. if (linearization) {
  2625. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2626. }
  2627. // shadow the prototype getter with a data property
  2628. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2629. },
  2630. // Find the header, remove leading garbage and setup the stream
  2631. // starting from the header.
  2632. checkHeader: function PDFDocument_checkHeader() {
  2633. var stream = this.stream;
  2634. stream.reset();
  2635. if (find(stream, '%PDF-', 1024)) {
  2636. // Found the header, trim off any garbage before it.
  2637. stream.moveStart();
  2638. // Reading file format version
  2639. var MAX_VERSION_LENGTH = 12;
  2640. var version = '', ch;
  2641. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2642. if (version.length >= MAX_VERSION_LENGTH) {
  2643. break;
  2644. }
  2645. version += String.fromCharCode(ch);
  2646. }
  2647. // removing "%PDF-"-prefix
  2648. this.pdfFormatVersion = version.substring(5);
  2649. return;
  2650. }
  2651. // May not be a PDF file, continue anyway.
  2652. },
  2653. parseStartXRef: function PDFDocument_parseStartXRef() {
  2654. var startXRef = this.startXRef;
  2655. this.xref.setStartXRef(startXRef);
  2656. },
  2657. setup: function PDFDocument_setup(recoveryMode) {
  2658. this.xref.parse(recoveryMode);
  2659. this.catalog = new Catalog(this.pdfManager, this.xref);
  2660. },
  2661. get numPages() {
  2662. var linearization = this.linearization;
  2663. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2664. // shadow the prototype getter
  2665. return shadow(this, 'numPages', num);
  2666. },
  2667. get documentInfo() {
  2668. var docInfo = {
  2669. PDFFormatVersion: this.pdfFormatVersion,
  2670. IsAcroFormPresent: !!this.acroForm,
  2671. IsXFAPresent: !!this.xfa
  2672. };
  2673. var infoDict;
  2674. try {
  2675. infoDict = this.xref.trailer.get('Info');
  2676. } catch (err) {
  2677. info('The document information dictionary is invalid.');
  2678. }
  2679. if (infoDict) {
  2680. var validEntries = DocumentInfoValidators.entries;
  2681. // Only fill the document info with valid entries from the spec.
  2682. for (var key in validEntries) {
  2683. if (infoDict.has(key)) {
  2684. var value = infoDict.get(key);
  2685. // Make sure the value conforms to the spec.
  2686. if (validEntries[key](value)) {
  2687. docInfo[key] = (typeof value !== 'string' ?
  2688. value : stringToPDFString(value));
  2689. } else {
  2690. info('Bad value in document info for "' + key + '"');
  2691. }
  2692. }
  2693. }
  2694. }
  2695. return shadow(this, 'documentInfo', docInfo);
  2696. },
  2697. get fingerprint() {
  2698. var xref = this.xref, idArray, hash, fileID = '';
  2699. if (xref.trailer.has('ID')) {
  2700. idArray = xref.trailer.get('ID');
  2701. }
  2702. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2703. hash = stringToBytes(idArray[0]);
  2704. } else {
  2705. if (this.stream.ensureRange) {
  2706. this.stream.ensureRange(0,
  2707. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2708. }
  2709. hash = calculateMD5(this.stream.bytes.subarray(0,
  2710. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2711. }
  2712. for (var i = 0, n = hash.length; i < n; i++) {
  2713. var hex = hash[i].toString(16);
  2714. fileID += hex.length === 1 ? '0' + hex : hex;
  2715. }
  2716. return shadow(this, 'fingerprint', fileID);
  2717. },
  2718. getPage: function PDFDocument_getPage(pageIndex) {
  2719. return this.catalog.getPage(pageIndex);
  2720. },
  2721. cleanup: function PDFDocument_cleanup() {
  2722. return this.catalog.cleanup();
  2723. }
  2724. };
  2725. return PDFDocument;
  2726. })();
  2727. var Name = (function NameClosure() {
  2728. function Name(name) {
  2729. this.name = name;
  2730. }
  2731. Name.prototype = {};
  2732. var nameCache = {};
  2733. Name.get = function Name_get(name) {
  2734. var nameValue = nameCache[name];
  2735. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2736. };
  2737. return Name;
  2738. })();
  2739. var Cmd = (function CmdClosure() {
  2740. function Cmd(cmd) {
  2741. this.cmd = cmd;
  2742. }
  2743. Cmd.prototype = {};
  2744. var cmdCache = {};
  2745. Cmd.get = function Cmd_get(cmd) {
  2746. var cmdValue = cmdCache[cmd];
  2747. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2748. };
  2749. return Cmd;
  2750. })();
  2751. var Dict = (function DictClosure() {
  2752. var nonSerializable = function nonSerializableClosure() {
  2753. return nonSerializable; // creating closure on some variable
  2754. };
  2755. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2756. 'Background': true,
  2757. 'ExtGState': true,
  2758. 'Halftone': true,
  2759. 'Layout': true,
  2760. 'Mask': true,
  2761. 'Pagination': true,
  2762. 'Printing': true
  2763. };
  2764. function isRecursionAllowedFor(dict) {
  2765. if (!isName(dict.Type)) {
  2766. return true;
  2767. }
  2768. var dictType = dict.Type.name;
  2769. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2770. }
  2771. // xref is optional
  2772. function Dict(xref) {
  2773. // Map should only be used internally, use functions below to access.
  2774. this.map = Object.create(null);
  2775. this.xref = xref;
  2776. this.objId = null;
  2777. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2778. }
  2779. Dict.prototype = {
  2780. assignXref: function Dict_assignXref(newXref) {
  2781. this.xref = newXref;
  2782. },
  2783. // automatically dereferences Ref objects
  2784. get: function Dict_get(key1, key2, key3) {
  2785. var value;
  2786. var xref = this.xref;
  2787. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2788. typeof key2 === 'undefined') {
  2789. return xref ? xref.fetchIfRef(value) : value;
  2790. }
  2791. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2792. typeof key3 === 'undefined') {
  2793. return xref ? xref.fetchIfRef(value) : value;
  2794. }
  2795. value = this.map[key3] || null;
  2796. return xref ? xref.fetchIfRef(value) : value;
  2797. },
  2798. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2799. getAsync: function Dict_getAsync(key1, key2, key3) {
  2800. var value;
  2801. var xref = this.xref;
  2802. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2803. typeof key2 === 'undefined') {
  2804. if (xref) {
  2805. return xref.fetchIfRefAsync(value);
  2806. }
  2807. return Promise.resolve(value);
  2808. }
  2809. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2810. typeof key3 === 'undefined') {
  2811. if (xref) {
  2812. return xref.fetchIfRefAsync(value);
  2813. }
  2814. return Promise.resolve(value);
  2815. }
  2816. value = this.map[key3] || null;
  2817. if (xref) {
  2818. return xref.fetchIfRefAsync(value);
  2819. }
  2820. return Promise.resolve(value);
  2821. },
  2822. // no dereferencing
  2823. getRaw: function Dict_getRaw(key) {
  2824. return this.map[key];
  2825. },
  2826. // creates new map and dereferences all Refs
  2827. getAll: function Dict_getAll() {
  2828. var all = Object.create(null);
  2829. var queue = null;
  2830. var key, obj;
  2831. for (key in this.map) {
  2832. obj = this.get(key);
  2833. if (obj instanceof Dict) {
  2834. if (isRecursionAllowedFor(obj)) {
  2835. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2836. } else {
  2837. all[key] = this.getRaw(key);
  2838. }
  2839. } else {
  2840. all[key] = obj;
  2841. }
  2842. }
  2843. if (!queue) {
  2844. return all;
  2845. }
  2846. // trying to take cyclic references into the account
  2847. var processed = Object.create(null);
  2848. while (queue.length > 0) {
  2849. var item = queue.shift();
  2850. var itemObj = item.obj;
  2851. var objId = itemObj.objId;
  2852. if (objId && objId in processed) {
  2853. item.target[item.key] = processed[objId];
  2854. continue;
  2855. }
  2856. var dereferenced = Object.create(null);
  2857. for (key in itemObj.map) {
  2858. obj = itemObj.get(key);
  2859. if (obj instanceof Dict) {
  2860. if (isRecursionAllowedFor(obj)) {
  2861. queue.push({target: dereferenced, key: key, obj: obj});
  2862. } else {
  2863. dereferenced[key] = itemObj.getRaw(key);
  2864. }
  2865. } else {
  2866. dereferenced[key] = obj;
  2867. }
  2868. }
  2869. if (objId) {
  2870. processed[objId] = dereferenced;
  2871. }
  2872. item.target[item.key] = dereferenced;
  2873. }
  2874. return all;
  2875. },
  2876. set: function Dict_set(key, value) {
  2877. this.map[key] = value;
  2878. },
  2879. has: function Dict_has(key) {
  2880. return key in this.map;
  2881. },
  2882. forEach: function Dict_forEach(callback) {
  2883. for (var key in this.map) {
  2884. callback(key, this.get(key));
  2885. }
  2886. }
  2887. };
  2888. Dict.empty = new Dict(null);
  2889. return Dict;
  2890. })();
  2891. var Ref = (function RefClosure() {
  2892. function Ref(num, gen) {
  2893. this.num = num;
  2894. this.gen = gen;
  2895. }
  2896. Ref.prototype = {
  2897. toString: function Ref_toString() {
  2898. // This function is hot, so we make the string as compact as possible.
  2899. // |this.gen| is almost always zero, so we treat that case specially.
  2900. var str = this.num + 'R';
  2901. if (this.gen !== 0) {
  2902. str += this.gen;
  2903. }
  2904. return str;
  2905. }
  2906. };
  2907. return Ref;
  2908. })();
  2909. // The reference is identified by number and generation.
  2910. // This structure stores only one instance of the reference.
  2911. var RefSet = (function RefSetClosure() {
  2912. function RefSet() {
  2913. this.dict = {};
  2914. }
  2915. RefSet.prototype = {
  2916. has: function RefSet_has(ref) {
  2917. return ref.toString() in this.dict;
  2918. },
  2919. put: function RefSet_put(ref) {
  2920. this.dict[ref.toString()] = true;
  2921. },
  2922. remove: function RefSet_remove(ref) {
  2923. delete this.dict[ref.toString()];
  2924. }
  2925. };
  2926. return RefSet;
  2927. })();
  2928. var RefSetCache = (function RefSetCacheClosure() {
  2929. function RefSetCache() {
  2930. this.dict = Object.create(null);
  2931. }
  2932. RefSetCache.prototype = {
  2933. get: function RefSetCache_get(ref) {
  2934. return this.dict[ref.toString()];
  2935. },
  2936. has: function RefSetCache_has(ref) {
  2937. return ref.toString() in this.dict;
  2938. },
  2939. put: function RefSetCache_put(ref, obj) {
  2940. this.dict[ref.toString()] = obj;
  2941. },
  2942. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2943. this.dict[ref.toString()] = this.get(aliasRef);
  2944. },
  2945. forEach: function RefSetCache_forEach(fn, thisArg) {
  2946. for (var i in this.dict) {
  2947. fn.call(thisArg, this.dict[i]);
  2948. }
  2949. },
  2950. clear: function RefSetCache_clear() {
  2951. this.dict = Object.create(null);
  2952. }
  2953. };
  2954. return RefSetCache;
  2955. })();
  2956. var Catalog = (function CatalogClosure() {
  2957. function Catalog(pdfManager, xref) {
  2958. this.pdfManager = pdfManager;
  2959. this.xref = xref;
  2960. this.catDict = xref.getCatalogObj();
  2961. this.fontCache = new RefSetCache();
  2962. assert(isDict(this.catDict),
  2963. 'catalog object is not a dictionary');
  2964. this.pagePromises = [];
  2965. }
  2966. Catalog.prototype = {
  2967. get metadata() {
  2968. var streamRef = this.catDict.getRaw('Metadata');
  2969. if (!isRef(streamRef)) {
  2970. return shadow(this, 'metadata', null);
  2971. }
  2972. var encryptMetadata = (!this.xref.encrypt ? false :
  2973. this.xref.encrypt.encryptMetadata);
  2974. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2975. var metadata;
  2976. if (stream && isDict(stream.dict)) {
  2977. var type = stream.dict.get('Type');
  2978. var subtype = stream.dict.get('Subtype');
  2979. if (isName(type) && isName(subtype) &&
  2980. type.name === 'Metadata' && subtype.name === 'XML') {
  2981. // XXX: This should examine the charset the XML document defines,
  2982. // however since there are currently no real means to decode
  2983. // arbitrary charsets, let's just hope that the author of the PDF
  2984. // was reasonable enough to stick with the XML default charset,
  2985. // which is UTF-8.
  2986. try {
  2987. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2988. } catch (e) {
  2989. info('Skipping invalid metadata.');
  2990. }
  2991. }
  2992. }
  2993. return shadow(this, 'metadata', metadata);
  2994. },
  2995. get toplevelPagesDict() {
  2996. var pagesObj = this.catDict.get('Pages');
  2997. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2998. // shadow the prototype getter
  2999. return shadow(this, 'toplevelPagesDict', pagesObj);
  3000. },
  3001. get documentOutline() {
  3002. var obj = null;
  3003. try {
  3004. obj = this.readDocumentOutline();
  3005. } catch (ex) {
  3006. if (ex instanceof MissingDataException) {
  3007. throw ex;
  3008. }
  3009. warn('Unable to read document outline');
  3010. }
  3011. return shadow(this, 'documentOutline', obj);
  3012. },
  3013. readDocumentOutline: function Catalog_readDocumentOutline() {
  3014. var xref = this.xref;
  3015. var obj = this.catDict.get('Outlines');
  3016. var root = { items: [] };
  3017. if (isDict(obj)) {
  3018. obj = obj.getRaw('First');
  3019. var processed = new RefSet();
  3020. if (isRef(obj)) {
  3021. var queue = [{obj: obj, parent: root}];
  3022. // to avoid recursion keeping track of the items
  3023. // in the processed dictionary
  3024. processed.put(obj);
  3025. while (queue.length > 0) {
  3026. var i = queue.shift();
  3027. var outlineDict = xref.fetchIfRef(i.obj);
  3028. if (outlineDict === null) {
  3029. continue;
  3030. }
  3031. if (!outlineDict.has('Title')) {
  3032. error('Invalid outline item');
  3033. }
  3034. var dest = outlineDict.get('A');
  3035. if (dest) {
  3036. dest = dest.get('D');
  3037. } else if (outlineDict.has('Dest')) {
  3038. dest = outlineDict.getRaw('Dest');
  3039. if (isName(dest)) {
  3040. dest = dest.name;
  3041. }
  3042. }
  3043. var title = outlineDict.get('Title');
  3044. var outlineItem = {
  3045. dest: dest,
  3046. title: stringToPDFString(title),
  3047. color: outlineDict.get('C') || [0, 0, 0],
  3048. count: outlineDict.get('Count'),
  3049. bold: !!(outlineDict.get('F') & 2),
  3050. italic: !!(outlineDict.get('F') & 1),
  3051. items: []
  3052. };
  3053. i.parent.items.push(outlineItem);
  3054. obj = outlineDict.getRaw('First');
  3055. if (isRef(obj) && !processed.has(obj)) {
  3056. queue.push({obj: obj, parent: outlineItem});
  3057. processed.put(obj);
  3058. }
  3059. obj = outlineDict.getRaw('Next');
  3060. if (isRef(obj) && !processed.has(obj)) {
  3061. queue.push({obj: obj, parent: i.parent});
  3062. processed.put(obj);
  3063. }
  3064. }
  3065. }
  3066. }
  3067. return (root.items.length > 0 ? root.items : null);
  3068. },
  3069. get numPages() {
  3070. var obj = this.toplevelPagesDict.get('Count');
  3071. assert(
  3072. isInt(obj),
  3073. 'page count in top level pages object is not an integer'
  3074. );
  3075. // shadow the prototype getter
  3076. return shadow(this, 'num', obj);
  3077. },
  3078. get destinations() {
  3079. function fetchDestination(dest) {
  3080. return isDict(dest) ? dest.get('D') : dest;
  3081. }
  3082. var xref = this.xref;
  3083. var dests = {}, nameTreeRef, nameDictionaryRef;
  3084. var obj = this.catDict.get('Names');
  3085. if (obj && obj.has('Dests')) {
  3086. nameTreeRef = obj.getRaw('Dests');
  3087. } else if (this.catDict.has('Dests')) {
  3088. nameDictionaryRef = this.catDict.get('Dests');
  3089. }
  3090. if (nameDictionaryRef) {
  3091. // reading simple destination dictionary
  3092. obj = nameDictionaryRef;
  3093. obj.forEach(function catalogForEach(key, value) {
  3094. if (!value) {
  3095. return;
  3096. }
  3097. dests[key] = fetchDestination(value);
  3098. });
  3099. }
  3100. if (nameTreeRef) {
  3101. var nameTree = new NameTree(nameTreeRef, xref);
  3102. var names = nameTree.getAll();
  3103. for (var name in names) {
  3104. if (!names.hasOwnProperty(name)) {
  3105. continue;
  3106. }
  3107. dests[name] = fetchDestination(names[name]);
  3108. }
  3109. }
  3110. return shadow(this, 'destinations', dests);
  3111. },
  3112. getDestination: function Catalog_getDestination(destinationId) {
  3113. function fetchDestination(dest) {
  3114. return isDict(dest) ? dest.get('D') : dest;
  3115. }
  3116. var xref = this.xref;
  3117. var dest, nameTreeRef, nameDictionaryRef;
  3118. var obj = this.catDict.get('Names');
  3119. if (obj && obj.has('Dests')) {
  3120. nameTreeRef = obj.getRaw('Dests');
  3121. } else if (this.catDict.has('Dests')) {
  3122. nameDictionaryRef = this.catDict.get('Dests');
  3123. }
  3124. if (nameDictionaryRef) {
  3125. // reading simple destination dictionary
  3126. obj = nameDictionaryRef;
  3127. obj.forEach(function catalogForEach(key, value) {
  3128. if (!value) {
  3129. return;
  3130. }
  3131. if (key === destinationId) {
  3132. dest = fetchDestination(value);
  3133. }
  3134. });
  3135. }
  3136. if (nameTreeRef) {
  3137. var nameTree = new NameTree(nameTreeRef, xref);
  3138. dest = fetchDestination(nameTree.get(destinationId));
  3139. }
  3140. return dest;
  3141. },
  3142. get attachments() {
  3143. var xref = this.xref;
  3144. var attachments = null, nameTreeRef;
  3145. var obj = this.catDict.get('Names');
  3146. if (obj) {
  3147. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3148. }
  3149. if (nameTreeRef) {
  3150. var nameTree = new NameTree(nameTreeRef, xref);
  3151. var names = nameTree.getAll();
  3152. for (var name in names) {
  3153. if (!names.hasOwnProperty(name)) {
  3154. continue;
  3155. }
  3156. var fs = new FileSpec(names[name], xref);
  3157. if (!attachments) {
  3158. attachments = {};
  3159. }
  3160. attachments[stringToPDFString(name)] = fs.serializable;
  3161. }
  3162. }
  3163. return shadow(this, 'attachments', attachments);
  3164. },
  3165. get javaScript() {
  3166. var xref = this.xref;
  3167. var obj = this.catDict.get('Names');
  3168. var javaScript = [];
  3169. if (obj && obj.has('JavaScript')) {
  3170. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3171. var names = nameTree.getAll();
  3172. for (var name in names) {
  3173. if (!names.hasOwnProperty(name)) {
  3174. continue;
  3175. }
  3176. // We don't really use the JavaScript right now. This code is
  3177. // defensive so we don't cause errors on document load.
  3178. var jsDict = names[name];
  3179. if (!isDict(jsDict)) {
  3180. continue;
  3181. }
  3182. var type = jsDict.get('S');
  3183. if (!isName(type) || type.name !== 'JavaScript') {
  3184. continue;
  3185. }
  3186. var js = jsDict.get('JS');
  3187. if (!isString(js) && !isStream(js)) {
  3188. continue;
  3189. }
  3190. if (isStream(js)) {
  3191. js = bytesToString(js.getBytes());
  3192. }
  3193. javaScript.push(stringToPDFString(js));
  3194. }
  3195. }
  3196. // Append OpenAction actions to javaScript array
  3197. var openactionDict = this.catDict.get('OpenAction');
  3198. if (isDict(openactionDict)) {
  3199. var objType = openactionDict.get('Type');
  3200. var actionType = openactionDict.get('S');
  3201. var action = openactionDict.get('N');
  3202. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3203. isName(actionType) && actionType.name === 'Named' &&
  3204. isName(action) && action.name === 'Print');
  3205. if (isPrintAction) {
  3206. javaScript.push('print(true);');
  3207. }
  3208. }
  3209. return shadow(this, 'javaScript', javaScript);
  3210. },
  3211. cleanup: function Catalog_cleanup() {
  3212. var promises = [];
  3213. this.fontCache.forEach(function (promise) {
  3214. promises.push(promise);
  3215. });
  3216. return Promise.all(promises).then(function (translatedFonts) {
  3217. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3218. var font = translatedFonts[i].dict;
  3219. delete font.translated;
  3220. }
  3221. this.fontCache.clear();
  3222. }.bind(this));
  3223. },
  3224. getPage: function Catalog_getPage(pageIndex) {
  3225. if (!(pageIndex in this.pagePromises)) {
  3226. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3227. function (a) {
  3228. var dict = a[0];
  3229. var ref = a[1];
  3230. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3231. this.fontCache);
  3232. }.bind(this)
  3233. );
  3234. }
  3235. return this.pagePromises[pageIndex];
  3236. },
  3237. getPageDict: function Catalog_getPageDict(pageIndex) {
  3238. var capability = createPromiseCapability();
  3239. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3240. var currentPageIndex = 0;
  3241. var xref = this.xref;
  3242. function next() {
  3243. while (nodesToVisit.length) {
  3244. var currentNode = nodesToVisit.pop();
  3245. if (isRef(currentNode)) {
  3246. xref.fetchAsync(currentNode).then(function (obj) {
  3247. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3248. if (pageIndex === currentPageIndex) {
  3249. capability.resolve([obj, currentNode]);
  3250. } else {
  3251. currentPageIndex++;
  3252. next();
  3253. }
  3254. return;
  3255. }
  3256. nodesToVisit.push(obj);
  3257. next();
  3258. }, capability.reject);
  3259. return;
  3260. }
  3261. // must be a child page dictionary
  3262. assert(
  3263. isDict(currentNode),
  3264. 'page dictionary kid reference points to wrong type of object'
  3265. );
  3266. var count = currentNode.get('Count');
  3267. // Skip nodes where the page can't be.
  3268. if (currentPageIndex + count <= pageIndex) {
  3269. currentPageIndex += count;
  3270. continue;
  3271. }
  3272. var kids = currentNode.get('Kids');
  3273. assert(isArray(kids), 'page dictionary kids object is not an array');
  3274. if (count === kids.length) {
  3275. // Nodes that don't have the page have been skipped and this is the
  3276. // bottom of the tree which means the page requested must be a
  3277. // descendant of this pages node. Ideally we would just resolve the
  3278. // promise with the page ref here, but there is the case where more
  3279. // pages nodes could link to single a page (see issue 3666 pdf). To
  3280. // handle this push it back on the queue so if it is a pages node it
  3281. // will be descended into.
  3282. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3283. currentPageIndex = pageIndex;
  3284. continue;
  3285. } else {
  3286. for (var last = kids.length - 1; last >= 0; last--) {
  3287. nodesToVisit.push(kids[last]);
  3288. }
  3289. }
  3290. }
  3291. capability.reject('Page index ' + pageIndex + ' not found.');
  3292. }
  3293. next();
  3294. return capability.promise;
  3295. },
  3296. getPageIndex: function Catalog_getPageIndex(ref) {
  3297. // The page tree nodes have the count of all the leaves below them. To get
  3298. // how many pages are before we just have to walk up the tree and keep
  3299. // adding the count of siblings to the left of the node.
  3300. var xref = this.xref;
  3301. function pagesBeforeRef(kidRef) {
  3302. var total = 0;
  3303. var parentRef;
  3304. return xref.fetchAsync(kidRef).then(function (node) {
  3305. if (!node) {
  3306. return null;
  3307. }
  3308. parentRef = node.getRaw('Parent');
  3309. return node.getAsync('Parent');
  3310. }).then(function (parent) {
  3311. if (!parent) {
  3312. return null;
  3313. }
  3314. return parent.getAsync('Kids');
  3315. }).then(function (kids) {
  3316. if (!kids) {
  3317. return null;
  3318. }
  3319. var kidPromises = [];
  3320. var found = false;
  3321. for (var i = 0; i < kids.length; i++) {
  3322. var kid = kids[i];
  3323. assert(isRef(kid), 'kids must be a ref');
  3324. if (kid.num === kidRef.num) {
  3325. found = true;
  3326. break;
  3327. }
  3328. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3329. if (kid.has('Count')) {
  3330. var count = kid.get('Count');
  3331. total += count;
  3332. } else { // page leaf node
  3333. total++;
  3334. }
  3335. }));
  3336. }
  3337. if (!found) {
  3338. error('kid ref not found in parents kids');
  3339. }
  3340. return Promise.all(kidPromises).then(function () {
  3341. return [total, parentRef];
  3342. });
  3343. });
  3344. }
  3345. var total = 0;
  3346. function next(ref) {
  3347. return pagesBeforeRef(ref).then(function (args) {
  3348. if (!args) {
  3349. return total;
  3350. }
  3351. var count = args[0];
  3352. var parentRef = args[1];
  3353. total += count;
  3354. return next(parentRef);
  3355. });
  3356. }
  3357. return next(ref);
  3358. }
  3359. };
  3360. return Catalog;
  3361. })();
  3362. var XRef = (function XRefClosure() {
  3363. function XRef(stream, password) {
  3364. this.stream = stream;
  3365. this.entries = [];
  3366. this.xrefstms = {};
  3367. // prepare the XRef cache
  3368. this.cache = [];
  3369. this.password = password;
  3370. this.stats = {
  3371. streamTypes: [],
  3372. fontTypes: []
  3373. };
  3374. }
  3375. XRef.prototype = {
  3376. setStartXRef: function XRef_setStartXRef(startXRef) {
  3377. // Store the starting positions of xref tables as we process them
  3378. // so we can recover from missing data errors
  3379. this.startXRefQueue = [startXRef];
  3380. },
  3381. parse: function XRef_parse(recoveryMode) {
  3382. var trailerDict;
  3383. if (!recoveryMode) {
  3384. trailerDict = this.readXRef();
  3385. } else {
  3386. warn('Indexing all PDF objects');
  3387. trailerDict = this.indexObjects();
  3388. }
  3389. trailerDict.assignXref(this);
  3390. this.trailer = trailerDict;
  3391. var encrypt = trailerDict.get('Encrypt');
  3392. if (encrypt) {
  3393. var ids = trailerDict.get('ID');
  3394. var fileId = (ids && ids.length) ? ids[0] : '';
  3395. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3396. this.password);
  3397. }
  3398. // get the root dictionary (catalog) object
  3399. if (!(this.root = trailerDict.get('Root'))) {
  3400. error('Invalid root reference');
  3401. }
  3402. },
  3403. processXRefTable: function XRef_processXRefTable(parser) {
  3404. if (!('tableState' in this)) {
  3405. // Stores state of the table as we process it so we can resume
  3406. // from middle of table in case of missing data error
  3407. this.tableState = {
  3408. entryNum: 0,
  3409. streamPos: parser.lexer.stream.pos,
  3410. parserBuf1: parser.buf1,
  3411. parserBuf2: parser.buf2
  3412. };
  3413. }
  3414. var obj = this.readXRefTable(parser);
  3415. // Sanity check
  3416. if (!isCmd(obj, 'trailer')) {
  3417. error('Invalid XRef table: could not find trailer dictionary');
  3418. }
  3419. // Read trailer dictionary, e.g.
  3420. // trailer
  3421. // << /Size 22
  3422. // /Root 20R
  3423. // /Info 10R
  3424. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3425. // >>
  3426. // The parser goes through the entire stream << ... >> and provides
  3427. // a getter interface for the key-value table
  3428. var dict = parser.getObj();
  3429. // The pdflib PDF generator can generate a nested trailer dictionary
  3430. if (!isDict(dict) && dict.dict) {
  3431. dict = dict.dict;
  3432. }
  3433. if (!isDict(dict)) {
  3434. error('Invalid XRef table: could not parse trailer dictionary');
  3435. }
  3436. delete this.tableState;
  3437. return dict;
  3438. },
  3439. readXRefTable: function XRef_readXRefTable(parser) {
  3440. // Example of cross-reference table:
  3441. // xref
  3442. // 0 1 <-- subsection header (first obj #, obj count)
  3443. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3444. // 23 2 <-- subsection header ... and so on ...
  3445. // 0000025518 00002 n
  3446. // 0000025635 00000 n
  3447. // trailer
  3448. // ...
  3449. var stream = parser.lexer.stream;
  3450. var tableState = this.tableState;
  3451. stream.pos = tableState.streamPos;
  3452. parser.buf1 = tableState.parserBuf1;
  3453. parser.buf2 = tableState.parserBuf2;
  3454. // Outer loop is over subsection headers
  3455. var obj;
  3456. while (true) {
  3457. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3458. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3459. break;
  3460. }
  3461. tableState.firstEntryNum = obj;
  3462. tableState.entryCount = parser.getObj();
  3463. }
  3464. var first = tableState.firstEntryNum;
  3465. var count = tableState.entryCount;
  3466. if (!isInt(first) || !isInt(count)) {
  3467. error('Invalid XRef table: wrong types in subsection header');
  3468. }
  3469. // Inner loop is over objects themselves
  3470. for (var i = tableState.entryNum; i < count; i++) {
  3471. tableState.streamPos = stream.pos;
  3472. tableState.entryNum = i;
  3473. tableState.parserBuf1 = parser.buf1;
  3474. tableState.parserBuf2 = parser.buf2;
  3475. var entry = {};
  3476. entry.offset = parser.getObj();
  3477. entry.gen = parser.getObj();
  3478. var type = parser.getObj();
  3479. if (isCmd(type, 'f')) {
  3480. entry.free = true;
  3481. } else if (isCmd(type, 'n')) {
  3482. entry.uncompressed = true;
  3483. }
  3484. // Validate entry obj
  3485. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3486. !(entry.free || entry.uncompressed)) {
  3487. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3488. }
  3489. if (!this.entries[i + first]) {
  3490. this.entries[i + first] = entry;
  3491. }
  3492. }
  3493. tableState.entryNum = 0;
  3494. tableState.streamPos = stream.pos;
  3495. tableState.parserBuf1 = parser.buf1;
  3496. tableState.parserBuf2 = parser.buf2;
  3497. delete tableState.firstEntryNum;
  3498. delete tableState.entryCount;
  3499. }
  3500. // Per issue 3248: hp scanners generate bad XRef
  3501. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3502. // shifting the entries
  3503. this.entries.shift();
  3504. }
  3505. // Sanity check: as per spec, first object must be free
  3506. if (this.entries[0] && !this.entries[0].free) {
  3507. error('Invalid XRef table: unexpected first object');
  3508. }
  3509. return obj;
  3510. },
  3511. processXRefStream: function XRef_processXRefStream(stream) {
  3512. if (!('streamState' in this)) {
  3513. // Stores state of the stream as we process it so we can resume
  3514. // from middle of stream in case of missing data error
  3515. var streamParameters = stream.dict;
  3516. var byteWidths = streamParameters.get('W');
  3517. var range = streamParameters.get('Index');
  3518. if (!range) {
  3519. range = [0, streamParameters.get('Size')];
  3520. }
  3521. this.streamState = {
  3522. entryRanges: range,
  3523. byteWidths: byteWidths,
  3524. entryNum: 0,
  3525. streamPos: stream.pos
  3526. };
  3527. }
  3528. this.readXRefStream(stream);
  3529. delete this.streamState;
  3530. return stream.dict;
  3531. },
  3532. readXRefStream: function XRef_readXRefStream(stream) {
  3533. var i, j;
  3534. var streamState = this.streamState;
  3535. stream.pos = streamState.streamPos;
  3536. var byteWidths = streamState.byteWidths;
  3537. var typeFieldWidth = byteWidths[0];
  3538. var offsetFieldWidth = byteWidths[1];
  3539. var generationFieldWidth = byteWidths[2];
  3540. var entryRanges = streamState.entryRanges;
  3541. while (entryRanges.length > 0) {
  3542. var first = entryRanges[0];
  3543. var n = entryRanges[1];
  3544. if (!isInt(first) || !isInt(n)) {
  3545. error('Invalid XRef range fields: ' + first + ', ' + n);
  3546. }
  3547. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3548. !isInt(generationFieldWidth)) {
  3549. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3550. }
  3551. for (i = streamState.entryNum; i < n; ++i) {
  3552. streamState.entryNum = i;
  3553. streamState.streamPos = stream.pos;
  3554. var type = 0, offset = 0, generation = 0;
  3555. for (j = 0; j < typeFieldWidth; ++j) {
  3556. type = (type << 8) | stream.getByte();
  3557. }
  3558. // if type field is absent, its default value is 1
  3559. if (typeFieldWidth === 0) {
  3560. type = 1;
  3561. }
  3562. for (j = 0; j < offsetFieldWidth; ++j) {
  3563. offset = (offset << 8) | stream.getByte();
  3564. }
  3565. for (j = 0; j < generationFieldWidth; ++j) {
  3566. generation = (generation << 8) | stream.getByte();
  3567. }
  3568. var entry = {};
  3569. entry.offset = offset;
  3570. entry.gen = generation;
  3571. switch (type) {
  3572. case 0:
  3573. entry.free = true;
  3574. break;
  3575. case 1:
  3576. entry.uncompressed = true;
  3577. break;
  3578. case 2:
  3579. break;
  3580. default:
  3581. error('Invalid XRef entry type: ' + type);
  3582. }
  3583. if (!this.entries[first + i]) {
  3584. this.entries[first + i] = entry;
  3585. }
  3586. }
  3587. streamState.entryNum = 0;
  3588. streamState.streamPos = stream.pos;
  3589. entryRanges.splice(0, 2);
  3590. }
  3591. },
  3592. indexObjects: function XRef_indexObjects() {
  3593. // Simple scan through the PDF content to find objects,
  3594. // trailers and XRef streams.
  3595. function readToken(data, offset) {
  3596. var token = '', ch = data[offset];
  3597. while (ch !== 13 && ch !== 10) {
  3598. if (++offset >= data.length) {
  3599. break;
  3600. }
  3601. token += String.fromCharCode(ch);
  3602. ch = data[offset];
  3603. }
  3604. return token;
  3605. }
  3606. function skipUntil(data, offset, what) {
  3607. var length = what.length, dataLength = data.length;
  3608. var skipped = 0;
  3609. // finding byte sequence
  3610. while (offset < dataLength) {
  3611. var i = 0;
  3612. while (i < length && data[offset + i] === what[i]) {
  3613. ++i;
  3614. }
  3615. if (i >= length) {
  3616. break; // sequence found
  3617. }
  3618. offset++;
  3619. skipped++;
  3620. }
  3621. return skipped;
  3622. }
  3623. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3624. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3625. 101, 102]);
  3626. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3627. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3628. var stream = this.stream;
  3629. stream.pos = 0;
  3630. var buffer = stream.getBytes();
  3631. var position = stream.start, length = buffer.length;
  3632. var trailers = [], xrefStms = [];
  3633. while (position < length) {
  3634. var ch = buffer[position];
  3635. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3636. ++position;
  3637. continue;
  3638. }
  3639. if (ch === 37) { // %-comment
  3640. do {
  3641. ++position;
  3642. if (position >= length) {
  3643. break;
  3644. }
  3645. ch = buffer[position];
  3646. } while (ch !== 13 && ch !== 10);
  3647. continue;
  3648. }
  3649. var token = readToken(buffer, position);
  3650. var m;
  3651. if (token === 'xref') {
  3652. position += skipUntil(buffer, position, trailerBytes);
  3653. trailers.push(position);
  3654. position += skipUntil(buffer, position, startxrefBytes);
  3655. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3656. this.entries[m[1]] = {
  3657. offset: position,
  3658. gen: m[2] | 0,
  3659. uncompressed: true
  3660. };
  3661. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3662. var content = buffer.subarray(position, position + contentLength);
  3663. // checking XRef stream suspect
  3664. // (it shall have '/XRef' and next char is not a letter)
  3665. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3666. if (xrefTagOffset < contentLength &&
  3667. content[xrefTagOffset + 5] < 64) {
  3668. xrefStms.push(position);
  3669. this.xrefstms[position] = 1; // don't read it recursively
  3670. }
  3671. position += contentLength;
  3672. } else {
  3673. position += token.length + 1;
  3674. }
  3675. }
  3676. // reading XRef streams
  3677. var i, ii;
  3678. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3679. this.startXRefQueue.push(xrefStms[i]);
  3680. this.readXRef(/* recoveryMode */ true);
  3681. }
  3682. // finding main trailer
  3683. var dict;
  3684. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3685. stream.pos = trailers[i];
  3686. var parser = new Parser(new Lexer(stream), true, this);
  3687. var obj = parser.getObj();
  3688. if (!isCmd(obj, 'trailer')) {
  3689. continue;
  3690. }
  3691. // read the trailer dictionary
  3692. if (!isDict(dict = parser.getObj())) {
  3693. continue;
  3694. }
  3695. // taking the first one with 'ID'
  3696. if (dict.has('ID')) {
  3697. return dict;
  3698. }
  3699. }
  3700. // no tailer with 'ID', taking last one (if exists)
  3701. if (dict) {
  3702. return dict;
  3703. }
  3704. // nothing helps
  3705. // calling error() would reject worker with an UnknownErrorException.
  3706. throw new InvalidPDFException('Invalid PDF structure');
  3707. },
  3708. readXRef: function XRef_readXRef(recoveryMode) {
  3709. var stream = this.stream;
  3710. try {
  3711. while (this.startXRefQueue.length) {
  3712. var startXRef = this.startXRefQueue[0];
  3713. stream.pos = startXRef + stream.start;
  3714. var parser = new Parser(new Lexer(stream), true, this);
  3715. var obj = parser.getObj();
  3716. var dict;
  3717. // Get dictionary
  3718. if (isCmd(obj, 'xref')) {
  3719. // Parse end-of-file XRef
  3720. dict = this.processXRefTable(parser);
  3721. if (!this.topDict) {
  3722. this.topDict = dict;
  3723. }
  3724. // Recursively get other XRefs 'XRefStm', if any
  3725. obj = dict.get('XRefStm');
  3726. if (isInt(obj)) {
  3727. var pos = obj;
  3728. // ignore previously loaded xref streams
  3729. // (possible infinite recursion)
  3730. if (!(pos in this.xrefstms)) {
  3731. this.xrefstms[pos] = 1;
  3732. this.startXRefQueue.push(pos);
  3733. }
  3734. }
  3735. } else if (isInt(obj)) {
  3736. // Parse in-stream XRef
  3737. if (!isInt(parser.getObj()) ||
  3738. !isCmd(parser.getObj(), 'obj') ||
  3739. !isStream(obj = parser.getObj())) {
  3740. error('Invalid XRef stream');
  3741. }
  3742. dict = this.processXRefStream(obj);
  3743. if (!this.topDict) {
  3744. this.topDict = dict;
  3745. }
  3746. if (!dict) {
  3747. error('Failed to read XRef stream');
  3748. }
  3749. } else {
  3750. error('Invalid XRef stream header');
  3751. }
  3752. // Recursively get previous dictionary, if any
  3753. obj = dict.get('Prev');
  3754. if (isInt(obj)) {
  3755. this.startXRefQueue.push(obj);
  3756. } else if (isRef(obj)) {
  3757. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3758. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3759. this.startXRefQueue.push(obj.num);
  3760. }
  3761. this.startXRefQueue.shift();
  3762. }
  3763. return this.topDict;
  3764. } catch (e) {
  3765. if (e instanceof MissingDataException) {
  3766. throw e;
  3767. }
  3768. info('(while reading XRef): ' + e);
  3769. }
  3770. if (recoveryMode) {
  3771. return;
  3772. }
  3773. throw new XRefParseException();
  3774. },
  3775. getEntry: function XRef_getEntry(i) {
  3776. var xrefEntry = this.entries[i];
  3777. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3778. return xrefEntry;
  3779. }
  3780. return null;
  3781. },
  3782. fetchIfRef: function XRef_fetchIfRef(obj) {
  3783. if (!isRef(obj)) {
  3784. return obj;
  3785. }
  3786. return this.fetch(obj);
  3787. },
  3788. fetch: function XRef_fetch(ref, suppressEncryption) {
  3789. assert(isRef(ref), 'ref object is not a reference');
  3790. var num = ref.num;
  3791. if (num in this.cache) {
  3792. var cacheEntry = this.cache[num];
  3793. return cacheEntry;
  3794. }
  3795. var xrefEntry = this.getEntry(num);
  3796. // the referenced entry can be free
  3797. if (xrefEntry === null) {
  3798. return (this.cache[num] = null);
  3799. }
  3800. if (xrefEntry.uncompressed) {
  3801. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3802. } else {
  3803. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3804. }
  3805. if (isDict(xrefEntry)){
  3806. xrefEntry.objId = ref.toString();
  3807. } else if (isStream(xrefEntry)) {
  3808. xrefEntry.dict.objId = ref.toString();
  3809. }
  3810. return xrefEntry;
  3811. },
  3812. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3813. suppressEncryption) {
  3814. var gen = ref.gen;
  3815. var num = ref.num;
  3816. if (xrefEntry.gen !== gen) {
  3817. error('inconsistent generation in XRef');
  3818. }
  3819. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3820. this.stream.start);
  3821. var parser = new Parser(new Lexer(stream), true, this);
  3822. var obj1 = parser.getObj();
  3823. var obj2 = parser.getObj();
  3824. var obj3 = parser.getObj();
  3825. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3826. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3827. !isCmd(obj3)) {
  3828. error('bad XRef entry');
  3829. }
  3830. if (!isCmd(obj3, 'obj')) {
  3831. // some bad PDFs use "obj1234" and really mean 1234
  3832. if (obj3.cmd.indexOf('obj') === 0) {
  3833. num = parseInt(obj3.cmd.substring(3), 10);
  3834. if (!isNaN(num)) {
  3835. return num;
  3836. }
  3837. }
  3838. error('bad XRef entry');
  3839. }
  3840. if (this.encrypt && !suppressEncryption) {
  3841. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3842. } else {
  3843. xrefEntry = parser.getObj();
  3844. }
  3845. if (!isStream(xrefEntry)) {
  3846. this.cache[num] = xrefEntry;
  3847. }
  3848. return xrefEntry;
  3849. },
  3850. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3851. suppressEncryption) {
  3852. var tableOffset = xrefEntry.offset;
  3853. var stream = this.fetch(new Ref(tableOffset, 0));
  3854. if (!isStream(stream)) {
  3855. error('bad ObjStm stream');
  3856. }
  3857. var first = stream.dict.get('First');
  3858. var n = stream.dict.get('N');
  3859. if (!isInt(first) || !isInt(n)) {
  3860. error('invalid first and n parameters for ObjStm stream');
  3861. }
  3862. var parser = new Parser(new Lexer(stream), false, this);
  3863. parser.allowStreams = true;
  3864. var i, entries = [], num, nums = [];
  3865. // read the object numbers to populate cache
  3866. for (i = 0; i < n; ++i) {
  3867. num = parser.getObj();
  3868. if (!isInt(num)) {
  3869. error('invalid object number in the ObjStm stream: ' + num);
  3870. }
  3871. nums.push(num);
  3872. var offset = parser.getObj();
  3873. if (!isInt(offset)) {
  3874. error('invalid object offset in the ObjStm stream: ' + offset);
  3875. }
  3876. }
  3877. // read stream objects for cache
  3878. for (i = 0; i < n; ++i) {
  3879. entries.push(parser.getObj());
  3880. num = nums[i];
  3881. var entry = this.entries[num];
  3882. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3883. this.cache[num] = entries[i];
  3884. }
  3885. }
  3886. xrefEntry = entries[xrefEntry.gen];
  3887. if (xrefEntry === undefined) {
  3888. error('bad XRef entry for compressed object');
  3889. }
  3890. return xrefEntry;
  3891. },
  3892. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3893. if (!isRef(obj)) {
  3894. return Promise.resolve(obj);
  3895. }
  3896. return this.fetchAsync(obj);
  3897. },
  3898. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3899. var streamManager = this.stream.manager;
  3900. var xref = this;
  3901. return new Promise(function tryFetch(resolve, reject) {
  3902. try {
  3903. resolve(xref.fetch(ref, suppressEncryption));
  3904. } catch (e) {
  3905. if (e instanceof MissingDataException) {
  3906. streamManager.requestRange(e.begin, e.end, function () {
  3907. tryFetch(resolve, reject);
  3908. });
  3909. return;
  3910. }
  3911. reject(e);
  3912. }
  3913. });
  3914. },
  3915. getCatalogObj: function XRef_getCatalogObj() {
  3916. return this.root;
  3917. }
  3918. };
  3919. return XRef;
  3920. })();
  3921. /**
  3922. * A NameTree is like a Dict but has some advantageous properties, see the
  3923. * spec (7.9.6) for more details.
  3924. * TODO: implement all the Dict functions and make this more efficent.
  3925. */
  3926. var NameTree = (function NameTreeClosure() {
  3927. function NameTree(root, xref) {
  3928. this.root = root;
  3929. this.xref = xref;
  3930. }
  3931. NameTree.prototype = {
  3932. getAll: function NameTree_getAll() {
  3933. var dict = {};
  3934. if (!this.root) {
  3935. return dict;
  3936. }
  3937. var xref = this.xref;
  3938. // reading name tree
  3939. var processed = new RefSet();
  3940. processed.put(this.root);
  3941. var queue = [this.root];
  3942. while (queue.length > 0) {
  3943. var i, n;
  3944. var obj = xref.fetchIfRef(queue.shift());
  3945. if (!isDict(obj)) {
  3946. continue;
  3947. }
  3948. if (obj.has('Kids')) {
  3949. var kids = obj.get('Kids');
  3950. for (i = 0, n = kids.length; i < n; i++) {
  3951. var kid = kids[i];
  3952. if (processed.has(kid)) {
  3953. error('invalid destinations');
  3954. }
  3955. queue.push(kid);
  3956. processed.put(kid);
  3957. }
  3958. continue;
  3959. }
  3960. var names = obj.get('Names');
  3961. if (names) {
  3962. for (i = 0, n = names.length; i < n; i += 2) {
  3963. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3964. }
  3965. }
  3966. }
  3967. return dict;
  3968. },
  3969. get: function NameTree_get(destinationId) {
  3970. if (!this.root) {
  3971. return null;
  3972. }
  3973. var xref = this.xref;
  3974. var kidsOrNames = xref.fetchIfRef(this.root);
  3975. var loopCount = 0;
  3976. var MAX_NAMES_LEVELS = 10;
  3977. var l, r, m;
  3978. // Perform a binary search to quickly find the entry that
  3979. // contains the named destination we are looking for.
  3980. while (kidsOrNames.has('Kids')) {
  3981. loopCount++;
  3982. if (loopCount > MAX_NAMES_LEVELS) {
  3983. warn('Search depth limit for named destionations has been reached.');
  3984. return null;
  3985. }
  3986. var kids = kidsOrNames.get('Kids');
  3987. if (!isArray(kids)) {
  3988. return null;
  3989. }
  3990. l = 0;
  3991. r = kids.length - 1;
  3992. while (l <= r) {
  3993. m = (l + r) >> 1;
  3994. var kid = xref.fetchIfRef(kids[m]);
  3995. var limits = kid.get('Limits');
  3996. if (destinationId < limits[0]) {
  3997. r = m - 1;
  3998. } else if (destinationId > limits[1]) {
  3999. l = m + 1;
  4000. } else {
  4001. kidsOrNames = xref.fetchIfRef(kids[m]);
  4002. break;
  4003. }
  4004. }
  4005. if (l > r) {
  4006. return null;
  4007. }
  4008. }
  4009. // If we get here, then we have found the right entry. Now
  4010. // go through the named destinations in the Named dictionary
  4011. // until we find the exact destination we're looking for.
  4012. var names = kidsOrNames.get('Names');
  4013. if (isArray(names)) {
  4014. // Perform a binary search to reduce the lookup time.
  4015. l = 0;
  4016. r = names.length - 2;
  4017. while (l <= r) {
  4018. // Check only even indices (0, 2, 4, ...) because the
  4019. // odd indices contain the actual D array.
  4020. m = (l + r) & ~1;
  4021. if (destinationId < names[m]) {
  4022. r = m - 2;
  4023. } else if (destinationId > names[m]) {
  4024. l = m + 2;
  4025. } else {
  4026. return xref.fetchIfRef(names[m + 1]);
  4027. }
  4028. }
  4029. }
  4030. return null;
  4031. }
  4032. };
  4033. return NameTree;
  4034. })();
  4035. /**
  4036. * "A PDF file can refer to the contents of another file by using a File
  4037. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4038. * NOTE: Only embedded files are supported (as part of the attachments support)
  4039. * TODO: support the 'URL' file system (with caching if !/V), portable
  4040. * collections attributes and related files (/RF)
  4041. */
  4042. var FileSpec = (function FileSpecClosure() {
  4043. function FileSpec(root, xref) {
  4044. if (!root || !isDict(root)) {
  4045. return;
  4046. }
  4047. this.xref = xref;
  4048. this.root = root;
  4049. if (root.has('FS')) {
  4050. this.fs = root.get('FS');
  4051. }
  4052. this.description = root.has('Desc') ?
  4053. stringToPDFString(root.get('Desc')) :
  4054. '';
  4055. if (root.has('RF')) {
  4056. warn('Related file specifications are not supported');
  4057. }
  4058. this.contentAvailable = true;
  4059. if (!root.has('EF')) {
  4060. this.contentAvailable = false;
  4061. warn('Non-embedded file specifications are not supported');
  4062. }
  4063. }
  4064. function pickPlatformItem(dict) {
  4065. // Look for the filename in this order:
  4066. // UF, F, Unix, Mac, DOS
  4067. if (dict.has('UF')) {
  4068. return dict.get('UF');
  4069. } else if (dict.has('F')) {
  4070. return dict.get('F');
  4071. } else if (dict.has('Unix')) {
  4072. return dict.get('Unix');
  4073. } else if (dict.has('Mac')) {
  4074. return dict.get('Mac');
  4075. } else if (dict.has('DOS')) {
  4076. return dict.get('DOS');
  4077. } else {
  4078. return null;
  4079. }
  4080. }
  4081. FileSpec.prototype = {
  4082. get filename() {
  4083. if (!this._filename && this.root) {
  4084. var filename = pickPlatformItem(this.root) || 'unnamed';
  4085. this._filename = stringToPDFString(filename).
  4086. replace(/\\\\/g, '\\').
  4087. replace(/\\\//g, '/').
  4088. replace(/\\/g, '/');
  4089. }
  4090. return this._filename;
  4091. },
  4092. get content() {
  4093. if (!this.contentAvailable) {
  4094. return null;
  4095. }
  4096. if (!this.contentRef && this.root) {
  4097. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4098. }
  4099. var content = null;
  4100. if (this.contentRef) {
  4101. var xref = this.xref;
  4102. var fileObj = xref.fetchIfRef(this.contentRef);
  4103. if (fileObj && isStream(fileObj)) {
  4104. content = fileObj.getBytes();
  4105. } else {
  4106. warn('Embedded file specification points to non-existing/invalid ' +
  4107. 'content');
  4108. }
  4109. } else {
  4110. warn('Embedded file specification does not have a content');
  4111. }
  4112. return content;
  4113. },
  4114. get serializable() {
  4115. return {
  4116. filename: this.filename,
  4117. content: this.content
  4118. };
  4119. }
  4120. };
  4121. return FileSpec;
  4122. })();
  4123. /**
  4124. * A helper for loading missing data in object graphs. It traverses the graph
  4125. * depth first and queues up any objects that have missing data. Once it has
  4126. * has traversed as many objects that are available it attempts to bundle the
  4127. * missing data requests and then resume from the nodes that weren't ready.
  4128. *
  4129. * NOTE: It provides protection from circular references by keeping track of
  4130. * of loaded references. However, you must be careful not to load any graphs
  4131. * that have references to the catalog or other pages since that will cause the
  4132. * entire PDF document object graph to be traversed.
  4133. */
  4134. var ObjectLoader = (function() {
  4135. function mayHaveChildren(value) {
  4136. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4137. }
  4138. function addChildren(node, nodesToVisit) {
  4139. var value;
  4140. if (isDict(node) || isStream(node)) {
  4141. var map;
  4142. if (isDict(node)) {
  4143. map = node.map;
  4144. } else {
  4145. map = node.dict.map;
  4146. }
  4147. for (var key in map) {
  4148. value = map[key];
  4149. if (mayHaveChildren(value)) {
  4150. nodesToVisit.push(value);
  4151. }
  4152. }
  4153. } else if (isArray(node)) {
  4154. for (var i = 0, ii = node.length; i < ii; i++) {
  4155. value = node[i];
  4156. if (mayHaveChildren(value)) {
  4157. nodesToVisit.push(value);
  4158. }
  4159. }
  4160. }
  4161. }
  4162. function ObjectLoader(obj, keys, xref) {
  4163. this.obj = obj;
  4164. this.keys = keys;
  4165. this.xref = xref;
  4166. this.refSet = null;
  4167. }
  4168. ObjectLoader.prototype = {
  4169. load: function ObjectLoader_load() {
  4170. var keys = this.keys;
  4171. this.capability = createPromiseCapability();
  4172. // Don't walk the graph if all the data is already loaded.
  4173. if (!(this.xref.stream instanceof ChunkedStream) ||
  4174. this.xref.stream.getMissingChunks().length === 0) {
  4175. this.capability.resolve();
  4176. return this.capability.promise;
  4177. }
  4178. this.refSet = new RefSet();
  4179. // Setup the initial nodes to visit.
  4180. var nodesToVisit = [];
  4181. for (var i = 0; i < keys.length; i++) {
  4182. nodesToVisit.push(this.obj[keys[i]]);
  4183. }
  4184. this.walk(nodesToVisit);
  4185. return this.capability.promise;
  4186. },
  4187. walk: function ObjectLoader_walk(nodesToVisit) {
  4188. var nodesToRevisit = [];
  4189. var pendingRequests = [];
  4190. // DFS walk of the object graph.
  4191. while (nodesToVisit.length) {
  4192. var currentNode = nodesToVisit.pop();
  4193. // Only references or chunked streams can cause missing data exceptions.
  4194. if (isRef(currentNode)) {
  4195. // Skip nodes that have already been visited.
  4196. if (this.refSet.has(currentNode)) {
  4197. continue;
  4198. }
  4199. try {
  4200. var ref = currentNode;
  4201. this.refSet.put(ref);
  4202. currentNode = this.xref.fetch(currentNode);
  4203. } catch (e) {
  4204. if (!(e instanceof MissingDataException)) {
  4205. throw e;
  4206. }
  4207. nodesToRevisit.push(currentNode);
  4208. pendingRequests.push({ begin: e.begin, end: e.end });
  4209. }
  4210. }
  4211. if (currentNode && currentNode.getBaseStreams) {
  4212. var baseStreams = currentNode.getBaseStreams();
  4213. var foundMissingData = false;
  4214. for (var i = 0; i < baseStreams.length; i++) {
  4215. var stream = baseStreams[i];
  4216. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4217. foundMissingData = true;
  4218. pendingRequests.push({
  4219. begin: stream.start,
  4220. end: stream.end
  4221. });
  4222. }
  4223. }
  4224. if (foundMissingData) {
  4225. nodesToRevisit.push(currentNode);
  4226. }
  4227. }
  4228. addChildren(currentNode, nodesToVisit);
  4229. }
  4230. if (pendingRequests.length) {
  4231. this.xref.stream.manager.requestRanges(pendingRequests,
  4232. function pendingRequestCallback() {
  4233. nodesToVisit = nodesToRevisit;
  4234. for (var i = 0; i < nodesToRevisit.length; i++) {
  4235. var node = nodesToRevisit[i];
  4236. // Remove any reference nodes from the currrent refset so they
  4237. // aren't skipped when we revist them.
  4238. if (isRef(node)) {
  4239. this.refSet.remove(node);
  4240. }
  4241. }
  4242. this.walk(nodesToVisit);
  4243. }.bind(this));
  4244. return;
  4245. }
  4246. // Everything is loaded.
  4247. this.refSet = null;
  4248. this.capability.resolve();
  4249. }
  4250. };
  4251. return ObjectLoader;
  4252. })();
  4253. var ISOAdobeCharset = [
  4254. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4255. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4256. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4257. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4258. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4259. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4260. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4261. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4262. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4263. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4264. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4265. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4266. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4267. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4268. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4269. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4270. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4271. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4272. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4273. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4274. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4275. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4276. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4277. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4278. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4279. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4280. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4281. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4282. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4283. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4284. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4285. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4286. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4287. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4288. ];
  4289. var ExpertCharset = [
  4290. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4291. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4292. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4293. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4294. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4295. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4296. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4297. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4298. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4299. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4300. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4301. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4302. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4303. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4304. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4305. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4306. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4307. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4308. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4309. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4310. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4311. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4312. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4313. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4314. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4315. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4316. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4317. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4318. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4319. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4320. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4321. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4322. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4323. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4324. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4325. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4326. 'Ydieresissmall'
  4327. ];
  4328. var ExpertSubsetCharset = [
  4329. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4330. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4331. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4332. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4333. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4334. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4335. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4336. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4337. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4338. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4339. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4340. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4341. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4342. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4343. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4344. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4345. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4346. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4347. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4348. 'periodinferior', 'commainferior'
  4349. ];
  4350. var DEFAULT_ICON_SIZE = 22; // px
  4351. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4352. var Annotation = (function AnnotationClosure() {
  4353. // 12.5.5: Algorithm: Appearance streams
  4354. function getTransformMatrix(rect, bbox, matrix) {
  4355. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4356. var minX = bounds[0];
  4357. var minY = bounds[1];
  4358. var maxX = bounds[2];
  4359. var maxY = bounds[3];
  4360. if (minX === maxX || minY === maxY) {
  4361. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4362. // just apply the transform for rect
  4363. return [1, 0, 0, 1, rect[0], rect[1]];
  4364. }
  4365. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4366. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4367. return [
  4368. xRatio,
  4369. 0,
  4370. 0,
  4371. yRatio,
  4372. rect[0] - minX * xRatio,
  4373. rect[1] - minY * yRatio
  4374. ];
  4375. }
  4376. function getDefaultAppearance(dict) {
  4377. var appearanceState = dict.get('AP');
  4378. if (!isDict(appearanceState)) {
  4379. return;
  4380. }
  4381. var appearance;
  4382. var appearances = appearanceState.get('N');
  4383. if (isDict(appearances)) {
  4384. var as = dict.get('AS');
  4385. if (as && appearances.has(as.name)) {
  4386. appearance = appearances.get(as.name);
  4387. }
  4388. } else {
  4389. appearance = appearances;
  4390. }
  4391. return appearance;
  4392. }
  4393. function Annotation(params) {
  4394. var dict = params.dict;
  4395. var data = this.data = {};
  4396. data.subtype = dict.get('Subtype').name;
  4397. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4398. data.rect = Util.normalizeRect(rect);
  4399. data.annotationFlags = dict.get('F');
  4400. var color = dict.get('C');
  4401. if (!color) {
  4402. // The PDF spec does not mention how a missing color array is interpreted.
  4403. // Adobe Reader seems to default to black in this case.
  4404. data.color = [0, 0, 0];
  4405. } else if (isArray(color)) {
  4406. switch (color.length) {
  4407. case 0:
  4408. // Empty array denotes transparent border.
  4409. data.color = null;
  4410. break;
  4411. case 1:
  4412. // TODO: implement DeviceGray
  4413. break;
  4414. case 3:
  4415. data.color = color;
  4416. break;
  4417. case 4:
  4418. // TODO: implement DeviceCMYK
  4419. break;
  4420. }
  4421. }
  4422. // Some types of annotations have border style dict which has more
  4423. // info than the border array
  4424. if (dict.has('BS')) {
  4425. var borderStyle = dict.get('BS');
  4426. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4427. } else {
  4428. var borderArray = dict.get('Border') || [0, 0, 1];
  4429. data.borderWidth = borderArray[2] || 0;
  4430. // TODO: implement proper support for annotations with line dash patterns.
  4431. var dashArray = borderArray[3];
  4432. if (data.borderWidth > 0 && dashArray) {
  4433. if (!isArray(dashArray)) {
  4434. // Ignore the border if dashArray is not actually an array,
  4435. // this is consistent with the behaviour in Adobe Reader.
  4436. data.borderWidth = 0;
  4437. } else {
  4438. var dashArrayLength = dashArray.length;
  4439. if (dashArrayLength > 0) {
  4440. // According to the PDF specification: the elements in a dashArray
  4441. // shall be numbers that are nonnegative and not all equal to zero.
  4442. var isInvalid = false;
  4443. var numPositive = 0;
  4444. for (var i = 0; i < dashArrayLength; i++) {
  4445. var validNumber = (+dashArray[i] >= 0);
  4446. if (!validNumber) {
  4447. isInvalid = true;
  4448. break;
  4449. } else if (dashArray[i] > 0) {
  4450. numPositive++;
  4451. }
  4452. }
  4453. if (isInvalid || numPositive === 0) {
  4454. data.borderWidth = 0;
  4455. }
  4456. }
  4457. }
  4458. }
  4459. }
  4460. this.appearance = getDefaultAppearance(dict);
  4461. data.hasAppearance = !!this.appearance;
  4462. data.id = params.ref.num;
  4463. }
  4464. Annotation.prototype = {
  4465. getData: function Annotation_getData() {
  4466. return this.data;
  4467. },
  4468. isInvisible: function Annotation_isInvisible() {
  4469. var data = this.data;
  4470. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4471. return false;
  4472. } else {
  4473. return !!(data &&
  4474. data.annotationFlags && // Default: not invisible
  4475. data.annotationFlags & 0x1); // Invisible
  4476. }
  4477. },
  4478. isViewable: function Annotation_isViewable() {
  4479. var data = this.data;
  4480. return !!(!this.isInvisible() &&
  4481. data &&
  4482. (!data.annotationFlags ||
  4483. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4484. data.rect); // rectangle is necessary
  4485. },
  4486. isPrintable: function Annotation_isPrintable() {
  4487. var data = this.data;
  4488. return !!(!this.isInvisible() &&
  4489. data &&
  4490. data.annotationFlags && // Default: not printable
  4491. data.annotationFlags & 0x4 && // Print
  4492. !(data.annotationFlags & 0x2) && // Hidden
  4493. data.rect); // rectangle is necessary
  4494. },
  4495. loadResources: function Annotation_loadResources(keys) {
  4496. return new Promise(function (resolve, reject) {
  4497. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4498. if (!resources) {
  4499. resolve();
  4500. return;
  4501. }
  4502. var objectLoader = new ObjectLoader(resources.map,
  4503. keys,
  4504. resources.xref);
  4505. objectLoader.load().then(function() {
  4506. resolve(resources);
  4507. }, reject);
  4508. }, reject);
  4509. }.bind(this));
  4510. },
  4511. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4512. if (!this.appearance) {
  4513. return Promise.resolve(new OperatorList());
  4514. }
  4515. var data = this.data;
  4516. var appearanceDict = this.appearance.dict;
  4517. var resourcesPromise = this.loadResources([
  4518. 'ExtGState',
  4519. 'ColorSpace',
  4520. 'Pattern',
  4521. 'Shading',
  4522. 'XObject',
  4523. 'Font'
  4524. // ProcSet
  4525. // Properties
  4526. ]);
  4527. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4528. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4529. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4530. var self = this;
  4531. return resourcesPromise.then(function(resources) {
  4532. var opList = new OperatorList();
  4533. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4534. return evaluator.getOperatorList(self.appearance, resources, opList).
  4535. then(function () {
  4536. opList.addOp(OPS.endAnnotation, []);
  4537. self.appearance.reset();
  4538. return opList;
  4539. });
  4540. });
  4541. }
  4542. };
  4543. Annotation.getConstructor =
  4544. function Annotation_getConstructor(subtype, fieldType) {
  4545. if (!subtype) {
  4546. return;
  4547. }
  4548. // TODO(mack): Implement FreeText annotations
  4549. if (subtype === 'Link') {
  4550. return LinkAnnotation;
  4551. } else if (subtype === 'Text') {
  4552. return TextAnnotation;
  4553. } else if (subtype === 'Widget') {
  4554. if (!fieldType) {
  4555. return;
  4556. }
  4557. if (fieldType === 'Tx') {
  4558. return TextWidgetAnnotation;
  4559. } else {
  4560. return WidgetAnnotation;
  4561. }
  4562. } else {
  4563. return Annotation;
  4564. }
  4565. };
  4566. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4567. var dict = xref.fetchIfRef(ref);
  4568. if (!isDict(dict)) {
  4569. return;
  4570. }
  4571. var subtype = dict.get('Subtype');
  4572. subtype = isName(subtype) ? subtype.name : '';
  4573. if (!subtype) {
  4574. return;
  4575. }
  4576. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4577. fieldType = isName(fieldType) ? fieldType.name : '';
  4578. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4579. if (!Constructor) {
  4580. return;
  4581. }
  4582. var params = {
  4583. dict: dict,
  4584. ref: ref,
  4585. };
  4586. var annotation = new Constructor(params);
  4587. if (annotation.isViewable() || annotation.isPrintable()) {
  4588. return annotation;
  4589. } else {
  4590. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4591. warn('unimplemented annotation type: ' + subtype);
  4592. }
  4593. }
  4594. };
  4595. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4596. annotations, opList, pdfManager, partialEvaluator, intent) {
  4597. function reject(e) {
  4598. annotationsReadyCapability.reject(e);
  4599. }
  4600. var annotationsReadyCapability = createPromiseCapability();
  4601. var annotationPromises = [];
  4602. for (var i = 0, n = annotations.length; i < n; ++i) {
  4603. if (intent === 'display' && annotations[i].isViewable() ||
  4604. intent === 'print' && annotations[i].isPrintable()) {
  4605. annotationPromises.push(
  4606. annotations[i].getOperatorList(partialEvaluator));
  4607. }
  4608. }
  4609. Promise.all(annotationPromises).then(function(datas) {
  4610. opList.addOp(OPS.beginAnnotations, []);
  4611. for (var i = 0, n = datas.length; i < n; ++i) {
  4612. var annotOpList = datas[i];
  4613. opList.addOpList(annotOpList);
  4614. }
  4615. opList.addOp(OPS.endAnnotations, []);
  4616. annotationsReadyCapability.resolve();
  4617. }, reject);
  4618. return annotationsReadyCapability.promise;
  4619. };
  4620. return Annotation;
  4621. })();
  4622. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4623. function WidgetAnnotation(params) {
  4624. Annotation.call(this, params);
  4625. var dict = params.dict;
  4626. var data = this.data;
  4627. data.fieldValue = stringToPDFString(
  4628. Util.getInheritableProperty(dict, 'V') || '');
  4629. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4630. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4631. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4632. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4633. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4634. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4635. // Building the full field name by collecting the field and
  4636. // its ancestors 'T' data and joining them using '.'.
  4637. var fieldName = [];
  4638. var namedItem = dict;
  4639. var ref = params.ref;
  4640. while (namedItem) {
  4641. var parent = namedItem.get('Parent');
  4642. var parentRef = namedItem.getRaw('Parent');
  4643. var name = namedItem.get('T');
  4644. if (name) {
  4645. fieldName.unshift(stringToPDFString(name));
  4646. } else if (parent && ref) {
  4647. // The field name is absent, that means more than one field
  4648. // with the same name may exist. Replacing the empty name
  4649. // with the '`' plus index in the parent's 'Kids' array.
  4650. // This is not in the PDF spec but necessary to id the
  4651. // the input controls.
  4652. var kids = parent.get('Kids');
  4653. var j, jj;
  4654. for (j = 0, jj = kids.length; j < jj; j++) {
  4655. var kidRef = kids[j];
  4656. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4657. break;
  4658. }
  4659. }
  4660. fieldName.unshift('`' + j);
  4661. }
  4662. namedItem = parent;
  4663. ref = parentRef;
  4664. }
  4665. data.fullName = fieldName.join('.');
  4666. }
  4667. var parent = Annotation.prototype;
  4668. Util.inherit(WidgetAnnotation, Annotation, {
  4669. isViewable: function WidgetAnnotation_isViewable() {
  4670. if (this.data.fieldType === 'Sig') {
  4671. warn('unimplemented annotation type: Widget signature');
  4672. return false;
  4673. }
  4674. return parent.isViewable.call(this);
  4675. }
  4676. });
  4677. return WidgetAnnotation;
  4678. })();
  4679. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4680. function TextWidgetAnnotation(params) {
  4681. WidgetAnnotation.call(this, params);
  4682. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4683. this.data.annotationType = AnnotationType.WIDGET;
  4684. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4685. }
  4686. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4687. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4688. if (this.appearance) {
  4689. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4690. }
  4691. var opList = new OperatorList();
  4692. var data = this.data;
  4693. // Even if there is an appearance stream, ignore it. This is the
  4694. // behaviour used by Adobe Reader.
  4695. if (!data.defaultAppearance) {
  4696. return Promise.resolve(opList);
  4697. }
  4698. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4699. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4700. then(function () {
  4701. return opList;
  4702. });
  4703. }
  4704. });
  4705. return TextWidgetAnnotation;
  4706. })();
  4707. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4708. function InteractiveAnnotation(params) {
  4709. Annotation.call(this, params);
  4710. this.data.hasHtml = true;
  4711. }
  4712. Util.inherit(InteractiveAnnotation, Annotation, { });
  4713. return InteractiveAnnotation;
  4714. })();
  4715. var TextAnnotation = (function TextAnnotationClosure() {
  4716. function TextAnnotation(params) {
  4717. InteractiveAnnotation.call(this, params);
  4718. var dict = params.dict;
  4719. var data = this.data;
  4720. var content = dict.get('Contents');
  4721. var title = dict.get('T');
  4722. data.annotationType = AnnotationType.TEXT;
  4723. data.content = stringToPDFString(content || '');
  4724. data.title = stringToPDFString(title || '');
  4725. if (data.hasAppearance) {
  4726. data.name = 'NoIcon';
  4727. } else {
  4728. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4729. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4730. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4731. }
  4732. if (dict.has('C')) {
  4733. data.hasBgColor = true;
  4734. }
  4735. }
  4736. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4737. return TextAnnotation;
  4738. })();
  4739. var LinkAnnotation = (function LinkAnnotationClosure() {
  4740. function LinkAnnotation(params) {
  4741. InteractiveAnnotation.call(this, params);
  4742. var dict = params.dict;
  4743. var data = this.data;
  4744. data.annotationType = AnnotationType.LINK;
  4745. var action = dict.get('A');
  4746. if (action) {
  4747. var linkType = action.get('S').name;
  4748. if (linkType === 'URI') {
  4749. var url = action.get('URI');
  4750. if (isName(url)) {
  4751. // Some bad PDFs do not put parentheses around relative URLs.
  4752. url = '/' + url.name;
  4753. } else if (url) {
  4754. url = addDefaultProtocolToUrl(url);
  4755. }
  4756. // TODO: pdf spec mentions urls can be relative to a Base
  4757. // entry in the dictionary.
  4758. if (!isValidUrl(url, false)) {
  4759. url = '';
  4760. }
  4761. data.url = url;
  4762. } else if (linkType === 'GoTo') {
  4763. data.dest = action.get('D');
  4764. } else if (linkType === 'GoToR') {
  4765. var urlDict = action.get('F');
  4766. if (isDict(urlDict)) {
  4767. // We assume that the 'url' is a Filspec dictionary
  4768. // and fetch the url without checking any further
  4769. url = urlDict.get('F') || '';
  4770. }
  4771. // TODO: pdf reference says that GoToR
  4772. // can also have 'NewWindow' attribute
  4773. if (!isValidUrl(url, false)) {
  4774. url = '';
  4775. }
  4776. data.url = url;
  4777. data.dest = action.get('D');
  4778. } else if (linkType === 'Named') {
  4779. data.action = action.get('N').name;
  4780. } else {
  4781. warn('unrecognized link type: ' + linkType);
  4782. }
  4783. } else if (dict.has('Dest')) {
  4784. // simple destination link
  4785. var dest = dict.get('Dest');
  4786. data.dest = isName(dest) ? dest.name : dest;
  4787. }
  4788. }
  4789. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4790. function addDefaultProtocolToUrl(url) {
  4791. if (url && url.indexOf('www.') === 0) {
  4792. return ('http://' + url);
  4793. }
  4794. return url;
  4795. }
  4796. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4797. return LinkAnnotation;
  4798. })();
  4799. var PDFFunction = (function PDFFunctionClosure() {
  4800. var CONSTRUCT_SAMPLED = 0;
  4801. var CONSTRUCT_INTERPOLATED = 2;
  4802. var CONSTRUCT_STICHED = 3;
  4803. var CONSTRUCT_POSTSCRIPT = 4;
  4804. return {
  4805. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4806. str) {
  4807. var i, ii;
  4808. var length = 1;
  4809. for (i = 0, ii = size.length; i < ii; i++) {
  4810. length *= size[i];
  4811. }
  4812. length *= outputSize;
  4813. var array = new Array(length);
  4814. var codeSize = 0;
  4815. var codeBuf = 0;
  4816. // 32 is a valid bps so shifting won't work
  4817. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4818. var strBytes = str.getBytes((length * bps + 7) / 8);
  4819. var strIdx = 0;
  4820. for (i = 0; i < length; i++) {
  4821. while (codeSize < bps) {
  4822. codeBuf <<= 8;
  4823. codeBuf |= strBytes[strIdx++];
  4824. codeSize += 8;
  4825. }
  4826. codeSize -= bps;
  4827. array[i] = (codeBuf >> codeSize) * sampleMul;
  4828. codeBuf &= (1 << codeSize) - 1;
  4829. }
  4830. return array;
  4831. },
  4832. getIR: function PDFFunction_getIR(xref, fn) {
  4833. var dict = fn.dict;
  4834. if (!dict) {
  4835. dict = fn;
  4836. }
  4837. var types = [this.constructSampled,
  4838. null,
  4839. this.constructInterpolated,
  4840. this.constructStiched,
  4841. this.constructPostScript];
  4842. var typeNum = dict.get('FunctionType');
  4843. var typeFn = types[typeNum];
  4844. if (!typeFn) {
  4845. error('Unknown type of function');
  4846. }
  4847. return typeFn.call(this, fn, dict, xref);
  4848. },
  4849. fromIR: function PDFFunction_fromIR(IR) {
  4850. var type = IR[0];
  4851. switch (type) {
  4852. case CONSTRUCT_SAMPLED:
  4853. return this.constructSampledFromIR(IR);
  4854. case CONSTRUCT_INTERPOLATED:
  4855. return this.constructInterpolatedFromIR(IR);
  4856. case CONSTRUCT_STICHED:
  4857. return this.constructStichedFromIR(IR);
  4858. //case CONSTRUCT_POSTSCRIPT:
  4859. default:
  4860. return this.constructPostScriptFromIR(IR);
  4861. }
  4862. },
  4863. parse: function PDFFunction_parse(xref, fn) {
  4864. var IR = this.getIR(xref, fn);
  4865. return this.fromIR(IR);
  4866. },
  4867. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4868. if (!isArray(fnObj)) {
  4869. // not an array -- parsing as regular function
  4870. return this.parse(xref, fnObj);
  4871. }
  4872. var fnArray = [];
  4873. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4874. var obj = xref.fetchIfRef(fnObj[j]);
  4875. fnArray.push(PDFFunction.parse(xref, obj));
  4876. }
  4877. return function (src, srcOffset, dest, destOffset) {
  4878. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4879. fnArray[i](src, srcOffset, dest, destOffset + i);
  4880. }
  4881. };
  4882. },
  4883. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4884. function toMultiArray(arr) {
  4885. var inputLength = arr.length;
  4886. var out = [];
  4887. var index = 0;
  4888. for (var i = 0; i < inputLength; i += 2) {
  4889. out[index] = [arr[i], arr[i + 1]];
  4890. ++index;
  4891. }
  4892. return out;
  4893. }
  4894. var domain = dict.get('Domain');
  4895. var range = dict.get('Range');
  4896. if (!domain || !range) {
  4897. error('No domain or range');
  4898. }
  4899. var inputSize = domain.length / 2;
  4900. var outputSize = range.length / 2;
  4901. domain = toMultiArray(domain);
  4902. range = toMultiArray(range);
  4903. var size = dict.get('Size');
  4904. var bps = dict.get('BitsPerSample');
  4905. var order = dict.get('Order') || 1;
  4906. if (order !== 1) {
  4907. // No description how cubic spline interpolation works in PDF32000:2008
  4908. // As in poppler, ignoring order, linear interpolation may work as good
  4909. info('No support for cubic spline interpolation: ' + order);
  4910. }
  4911. var encode = dict.get('Encode');
  4912. if (!encode) {
  4913. encode = [];
  4914. for (var i = 0; i < inputSize; ++i) {
  4915. encode.push(0);
  4916. encode.push(size[i] - 1);
  4917. }
  4918. }
  4919. encode = toMultiArray(encode);
  4920. var decode = dict.get('Decode');
  4921. if (!decode) {
  4922. decode = range;
  4923. } else {
  4924. decode = toMultiArray(decode);
  4925. }
  4926. var samples = this.getSampleArray(size, outputSize, bps, str);
  4927. return [
  4928. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4929. outputSize, Math.pow(2, bps) - 1, range
  4930. ];
  4931. },
  4932. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4933. // See chapter 3, page 109 of the PDF reference
  4934. function interpolate(x, xmin, xmax, ymin, ymax) {
  4935. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4936. }
  4937. return function constructSampledFromIRResult(src, srcOffset,
  4938. dest, destOffset) {
  4939. // See chapter 3, page 110 of the PDF reference.
  4940. var m = IR[1];
  4941. var domain = IR[2];
  4942. var encode = IR[3];
  4943. var decode = IR[4];
  4944. var samples = IR[5];
  4945. var size = IR[6];
  4946. var n = IR[7];
  4947. //var mask = IR[8];
  4948. var range = IR[9];
  4949. // Building the cube vertices: its part and sample index
  4950. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4951. var cubeVertices = 1 << m;
  4952. var cubeN = new Float64Array(cubeVertices);
  4953. var cubeVertex = new Uint32Array(cubeVertices);
  4954. var i, j;
  4955. for (j = 0; j < cubeVertices; j++) {
  4956. cubeN[j] = 1;
  4957. }
  4958. var k = n, pos = 1;
  4959. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4960. for (i = 0; i < m; ++i) {
  4961. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4962. var domain_2i = domain[i][0];
  4963. var domain_2i_1 = domain[i][1];
  4964. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4965. domain_2i_1);
  4966. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4967. // Encode_2i, Encode_2i+1)
  4968. var e = interpolate(xi, domain_2i, domain_2i_1,
  4969. encode[i][0], encode[i][1]);
  4970. // e_i' = min(max(e_i, 0), Size_i - 1)
  4971. var size_i = size[i];
  4972. e = Math.min(Math.max(e, 0), size_i - 1);
  4973. // Adjusting the cube: N and vertex sample index
  4974. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4975. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4976. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4977. var offset0 = e0 * k;
  4978. var offset1 = offset0 + k; // e1 * k
  4979. for (j = 0; j < cubeVertices; j++) {
  4980. if (j & pos) {
  4981. cubeN[j] *= n1;
  4982. cubeVertex[j] += offset1;
  4983. } else {
  4984. cubeN[j] *= n0;
  4985. cubeVertex[j] += offset0;
  4986. }
  4987. }
  4988. k *= size_i;
  4989. pos <<= 1;
  4990. }
  4991. for (j = 0; j < n; ++j) {
  4992. // Sum all cube vertices' samples portions
  4993. var rj = 0;
  4994. for (i = 0; i < cubeVertices; i++) {
  4995. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4996. }
  4997. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4998. // Decode_2j, Decode_2j+1)
  4999. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5000. // y_j = min(max(r_j, range_2j), range_2j+1)
  5001. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5002. range[j][1]);
  5003. }
  5004. };
  5005. },
  5006. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5007. dict) {
  5008. var c0 = dict.get('C0') || [0];
  5009. var c1 = dict.get('C1') || [1];
  5010. var n = dict.get('N');
  5011. if (!isArray(c0) || !isArray(c1)) {
  5012. error('Illegal dictionary for interpolated function');
  5013. }
  5014. var length = c0.length;
  5015. var diff = [];
  5016. for (var i = 0; i < length; ++i) {
  5017. diff.push(c1[i] - c0[i]);
  5018. }
  5019. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5020. },
  5021. constructInterpolatedFromIR:
  5022. function PDFFunction_constructInterpolatedFromIR(IR) {
  5023. var c0 = IR[1];
  5024. var diff = IR[2];
  5025. var n = IR[3];
  5026. var length = diff.length;
  5027. return function constructInterpolatedFromIRResult(src, srcOffset,
  5028. dest, destOffset) {
  5029. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5030. for (var j = 0; j < length; ++j) {
  5031. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5032. }
  5033. };
  5034. },
  5035. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5036. var domain = dict.get('Domain');
  5037. if (!domain) {
  5038. error('No domain');
  5039. }
  5040. var inputSize = domain.length / 2;
  5041. if (inputSize !== 1) {
  5042. error('Bad domain for stiched function');
  5043. }
  5044. var fnRefs = dict.get('Functions');
  5045. var fns = [];
  5046. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5047. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5048. }
  5049. var bounds = dict.get('Bounds');
  5050. var encode = dict.get('Encode');
  5051. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5052. },
  5053. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5054. var domain = IR[1];
  5055. var bounds = IR[2];
  5056. var encode = IR[3];
  5057. var fnsIR = IR[4];
  5058. var fns = [];
  5059. var tmpBuf = new Float32Array(1);
  5060. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5061. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5062. }
  5063. return function constructStichedFromIRResult(src, srcOffset,
  5064. dest, destOffset) {
  5065. var clip = function constructStichedFromIRClip(v, min, max) {
  5066. if (v > max) {
  5067. v = max;
  5068. } else if (v < min) {
  5069. v = min;
  5070. }
  5071. return v;
  5072. };
  5073. // clip to domain
  5074. var v = clip(src[srcOffset], domain[0], domain[1]);
  5075. // calulate which bound the value is in
  5076. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5077. if (v < bounds[i]) {
  5078. break;
  5079. }
  5080. }
  5081. // encode value into domain of function
  5082. var dmin = domain[0];
  5083. if (i > 0) {
  5084. dmin = bounds[i - 1];
  5085. }
  5086. var dmax = domain[1];
  5087. if (i < bounds.length) {
  5088. dmax = bounds[i];
  5089. }
  5090. var rmin = encode[2 * i];
  5091. var rmax = encode[2 * i + 1];
  5092. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5093. // call the appropriate function
  5094. fns[i](tmpBuf, 0, dest, destOffset);
  5095. };
  5096. },
  5097. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5098. xref) {
  5099. var domain = dict.get('Domain');
  5100. var range = dict.get('Range');
  5101. if (!domain) {
  5102. error('No domain.');
  5103. }
  5104. if (!range) {
  5105. error('No range.');
  5106. }
  5107. var lexer = new PostScriptLexer(fn);
  5108. var parser = new PostScriptParser(lexer);
  5109. var code = parser.parse();
  5110. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5111. },
  5112. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5113. IR) {
  5114. var domain = IR[1];
  5115. var range = IR[2];
  5116. var code = IR[3];
  5117. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5118. if (compiled) {
  5119. // Compiled function consists of simple expressions such as addition,
  5120. // subtraction, Math.max, and also contains 'var' and 'return'
  5121. // statements. See the generation in the PostScriptCompiler below.
  5122. /*jshint -W054 */
  5123. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5124. }
  5125. info('Unable to compile PS function');
  5126. var numOutputs = range.length >> 1;
  5127. var numInputs = domain.length >> 1;
  5128. var evaluator = new PostScriptEvaluator(code);
  5129. // Cache the values for a big speed up, the cache size is limited though
  5130. // since the number of possible values can be huge from a PS function.
  5131. var cache = {};
  5132. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5133. // seen in our tests.
  5134. var MAX_CACHE_SIZE = 2048 * 4;
  5135. var cache_available = MAX_CACHE_SIZE;
  5136. var tmpBuf = new Float32Array(numInputs);
  5137. return function constructPostScriptFromIRResult(src, srcOffset,
  5138. dest, destOffset) {
  5139. var i, value;
  5140. var key = '';
  5141. var input = tmpBuf;
  5142. for (i = 0; i < numInputs; i++) {
  5143. value = src[srcOffset + i];
  5144. input[i] = value;
  5145. key += value + '_';
  5146. }
  5147. var cachedValue = cache[key];
  5148. if (cachedValue !== undefined) {
  5149. dest.set(cachedValue, destOffset);
  5150. return;
  5151. }
  5152. var output = new Float32Array(numOutputs);
  5153. var stack = evaluator.execute(input);
  5154. var stackIndex = stack.length - numOutputs;
  5155. for (i = 0; i < numOutputs; i++) {
  5156. value = stack[stackIndex + i];
  5157. var bound = range[i * 2];
  5158. if (value < bound) {
  5159. value = bound;
  5160. } else {
  5161. bound = range[i * 2 +1];
  5162. if (value > bound) {
  5163. value = bound;
  5164. }
  5165. }
  5166. output[i] = value;
  5167. }
  5168. if (cache_available > 0) {
  5169. cache_available--;
  5170. cache[key] = output;
  5171. }
  5172. dest.set(output, destOffset);
  5173. };
  5174. }
  5175. };
  5176. })();
  5177. function isPDFFunction(v) {
  5178. var fnDict;
  5179. if (typeof v !== 'object') {
  5180. return false;
  5181. } else if (isDict(v)) {
  5182. fnDict = v;
  5183. } else if (isStream(v)) {
  5184. fnDict = v.dict;
  5185. } else {
  5186. return false;
  5187. }
  5188. return fnDict.has('FunctionType');
  5189. }
  5190. var PostScriptStack = (function PostScriptStackClosure() {
  5191. var MAX_STACK_SIZE = 100;
  5192. function PostScriptStack(initialStack) {
  5193. this.stack = !initialStack ? [] :
  5194. Array.prototype.slice.call(initialStack, 0);
  5195. }
  5196. PostScriptStack.prototype = {
  5197. push: function PostScriptStack_push(value) {
  5198. if (this.stack.length >= MAX_STACK_SIZE) {
  5199. error('PostScript function stack overflow.');
  5200. }
  5201. this.stack.push(value);
  5202. },
  5203. pop: function PostScriptStack_pop() {
  5204. if (this.stack.length <= 0) {
  5205. error('PostScript function stack underflow.');
  5206. }
  5207. return this.stack.pop();
  5208. },
  5209. copy: function PostScriptStack_copy(n) {
  5210. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5211. error('PostScript function stack overflow.');
  5212. }
  5213. var stack = this.stack;
  5214. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5215. stack.push(stack[i]);
  5216. }
  5217. },
  5218. index: function PostScriptStack_index(n) {
  5219. this.push(this.stack[this.stack.length - n - 1]);
  5220. },
  5221. // rotate the last n stack elements p times
  5222. roll: function PostScriptStack_roll(n, p) {
  5223. var stack = this.stack;
  5224. var l = stack.length - n;
  5225. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5226. for (i = l, j = r; i < j; i++, j--) {
  5227. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5228. }
  5229. for (i = l, j = c - 1; i < j; i++, j--) {
  5230. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5231. }
  5232. for (i = c, j = r; i < j; i++, j--) {
  5233. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5234. }
  5235. }
  5236. };
  5237. return PostScriptStack;
  5238. })();
  5239. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5240. function PostScriptEvaluator(operators) {
  5241. this.operators = operators;
  5242. }
  5243. PostScriptEvaluator.prototype = {
  5244. execute: function PostScriptEvaluator_execute(initialStack) {
  5245. var stack = new PostScriptStack(initialStack);
  5246. var counter = 0;
  5247. var operators = this.operators;
  5248. var length = operators.length;
  5249. var operator, a, b;
  5250. while (counter < length) {
  5251. operator = operators[counter++];
  5252. if (typeof operator === 'number') {
  5253. // Operator is really an operand and should be pushed to the stack.
  5254. stack.push(operator);
  5255. continue;
  5256. }
  5257. switch (operator) {
  5258. // non standard ps operators
  5259. case 'jz': // jump if false
  5260. b = stack.pop();
  5261. a = stack.pop();
  5262. if (!a) {
  5263. counter = b;
  5264. }
  5265. break;
  5266. case 'j': // jump
  5267. a = stack.pop();
  5268. counter = a;
  5269. break;
  5270. // all ps operators in alphabetical order (excluding if/ifelse)
  5271. case 'abs':
  5272. a = stack.pop();
  5273. stack.push(Math.abs(a));
  5274. break;
  5275. case 'add':
  5276. b = stack.pop();
  5277. a = stack.pop();
  5278. stack.push(a + b);
  5279. break;
  5280. case 'and':
  5281. b = stack.pop();
  5282. a = stack.pop();
  5283. if (isBool(a) && isBool(b)) {
  5284. stack.push(a && b);
  5285. } else {
  5286. stack.push(a & b);
  5287. }
  5288. break;
  5289. case 'atan':
  5290. a = stack.pop();
  5291. stack.push(Math.atan(a));
  5292. break;
  5293. case 'bitshift':
  5294. b = stack.pop();
  5295. a = stack.pop();
  5296. if (a > 0) {
  5297. stack.push(a << b);
  5298. } else {
  5299. stack.push(a >> b);
  5300. }
  5301. break;
  5302. case 'ceiling':
  5303. a = stack.pop();
  5304. stack.push(Math.ceil(a));
  5305. break;
  5306. case 'copy':
  5307. a = stack.pop();
  5308. stack.copy(a);
  5309. break;
  5310. case 'cos':
  5311. a = stack.pop();
  5312. stack.push(Math.cos(a));
  5313. break;
  5314. case 'cvi':
  5315. a = stack.pop() | 0;
  5316. stack.push(a);
  5317. break;
  5318. case 'cvr':
  5319. // noop
  5320. break;
  5321. case 'div':
  5322. b = stack.pop();
  5323. a = stack.pop();
  5324. stack.push(a / b);
  5325. break;
  5326. case 'dup':
  5327. stack.copy(1);
  5328. break;
  5329. case 'eq':
  5330. b = stack.pop();
  5331. a = stack.pop();
  5332. stack.push(a === b);
  5333. break;
  5334. case 'exch':
  5335. stack.roll(2, 1);
  5336. break;
  5337. case 'exp':
  5338. b = stack.pop();
  5339. a = stack.pop();
  5340. stack.push(Math.pow(a, b));
  5341. break;
  5342. case 'false':
  5343. stack.push(false);
  5344. break;
  5345. case 'floor':
  5346. a = stack.pop();
  5347. stack.push(Math.floor(a));
  5348. break;
  5349. case 'ge':
  5350. b = stack.pop();
  5351. a = stack.pop();
  5352. stack.push(a >= b);
  5353. break;
  5354. case 'gt':
  5355. b = stack.pop();
  5356. a = stack.pop();
  5357. stack.push(a > b);
  5358. break;
  5359. case 'idiv':
  5360. b = stack.pop();
  5361. a = stack.pop();
  5362. stack.push((a / b) | 0);
  5363. break;
  5364. case 'index':
  5365. a = stack.pop();
  5366. stack.index(a);
  5367. break;
  5368. case 'le':
  5369. b = stack.pop();
  5370. a = stack.pop();
  5371. stack.push(a <= b);
  5372. break;
  5373. case 'ln':
  5374. a = stack.pop();
  5375. stack.push(Math.log(a));
  5376. break;
  5377. case 'log':
  5378. a = stack.pop();
  5379. stack.push(Math.log(a) / Math.LN10);
  5380. break;
  5381. case 'lt':
  5382. b = stack.pop();
  5383. a = stack.pop();
  5384. stack.push(a < b);
  5385. break;
  5386. case 'mod':
  5387. b = stack.pop();
  5388. a = stack.pop();
  5389. stack.push(a % b);
  5390. break;
  5391. case 'mul':
  5392. b = stack.pop();
  5393. a = stack.pop();
  5394. stack.push(a * b);
  5395. break;
  5396. case 'ne':
  5397. b = stack.pop();
  5398. a = stack.pop();
  5399. stack.push(a !== b);
  5400. break;
  5401. case 'neg':
  5402. a = stack.pop();
  5403. stack.push(-a);
  5404. break;
  5405. case 'not':
  5406. a = stack.pop();
  5407. if (isBool(a)) {
  5408. stack.push(!a);
  5409. } else {
  5410. stack.push(~a);
  5411. }
  5412. break;
  5413. case 'or':
  5414. b = stack.pop();
  5415. a = stack.pop();
  5416. if (isBool(a) && isBool(b)) {
  5417. stack.push(a || b);
  5418. } else {
  5419. stack.push(a | b);
  5420. }
  5421. break;
  5422. case 'pop':
  5423. stack.pop();
  5424. break;
  5425. case 'roll':
  5426. b = stack.pop();
  5427. a = stack.pop();
  5428. stack.roll(a, b);
  5429. break;
  5430. case 'round':
  5431. a = stack.pop();
  5432. stack.push(Math.round(a));
  5433. break;
  5434. case 'sin':
  5435. a = stack.pop();
  5436. stack.push(Math.sin(a));
  5437. break;
  5438. case 'sqrt':
  5439. a = stack.pop();
  5440. stack.push(Math.sqrt(a));
  5441. break;
  5442. case 'sub':
  5443. b = stack.pop();
  5444. a = stack.pop();
  5445. stack.push(a - b);
  5446. break;
  5447. case 'true':
  5448. stack.push(true);
  5449. break;
  5450. case 'truncate':
  5451. a = stack.pop();
  5452. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5453. stack.push(a);
  5454. break;
  5455. case 'xor':
  5456. b = stack.pop();
  5457. a = stack.pop();
  5458. if (isBool(a) && isBool(b)) {
  5459. stack.push(a !== b);
  5460. } else {
  5461. stack.push(a ^ b);
  5462. }
  5463. break;
  5464. default:
  5465. error('Unknown operator ' + operator);
  5466. break;
  5467. }
  5468. }
  5469. return stack.stack;
  5470. }
  5471. };
  5472. return PostScriptEvaluator;
  5473. })();
  5474. // Most of the PDFs functions consist of simple operations such as:
  5475. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5476. //
  5477. // We can compile most of such programs, and at the same moment, we can
  5478. // optimize some expressions using basic math properties. Keeping track of
  5479. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5480. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5481. function AstNode(type) {
  5482. this.type = type;
  5483. }
  5484. AstNode.prototype.visit = function (visitor) {
  5485. throw new Error('abstract method');
  5486. };
  5487. function AstArgument(index, min, max) {
  5488. AstNode.call(this, 'args');
  5489. this.index = index;
  5490. this.min = min;
  5491. this.max = max;
  5492. }
  5493. AstArgument.prototype = Object.create(AstNode.prototype);
  5494. AstArgument.prototype.visit = function (visitor) {
  5495. visitor.visitArgument(this);
  5496. };
  5497. function AstLiteral(number) {
  5498. AstNode.call(this, 'literal');
  5499. this.number = number;
  5500. this.min = number;
  5501. this.max = number;
  5502. }
  5503. AstLiteral.prototype = Object.create(AstNode.prototype);
  5504. AstLiteral.prototype.visit = function (visitor) {
  5505. visitor.visitLiteral(this);
  5506. };
  5507. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5508. AstNode.call(this, 'binary');
  5509. this.op = op;
  5510. this.arg1 = arg1;
  5511. this.arg2 = arg2;
  5512. this.min = min;
  5513. this.max = max;
  5514. }
  5515. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5516. AstBinaryOperation.prototype.visit = function (visitor) {
  5517. visitor.visitBinaryOperation(this);
  5518. };
  5519. function AstMin(arg, max) {
  5520. AstNode.call(this, 'max');
  5521. this.arg = arg;
  5522. this.min = arg.min;
  5523. this.max = max;
  5524. }
  5525. AstMin.prototype = Object.create(AstNode.prototype);
  5526. AstMin.prototype.visit = function (visitor) {
  5527. visitor.visitMin(this);
  5528. };
  5529. function AstVariable(index, min, max) {
  5530. AstNode.call(this, 'var');
  5531. this.index = index;
  5532. this.min = min;
  5533. this.max = max;
  5534. }
  5535. AstVariable.prototype = Object.create(AstNode.prototype);
  5536. AstVariable.prototype.visit = function (visitor) {
  5537. visitor.visitVariable(this);
  5538. };
  5539. function AstVariableDefinition(variable, arg) {
  5540. AstNode.call(this, 'definition');
  5541. this.variable = variable;
  5542. this.arg = arg;
  5543. }
  5544. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5545. AstVariableDefinition.prototype.visit = function (visitor) {
  5546. visitor.visitVariableDefinition(this);
  5547. };
  5548. function ExpressionBuilderVisitor() {
  5549. this.parts = [];
  5550. }
  5551. ExpressionBuilderVisitor.prototype = {
  5552. visitArgument: function (arg) {
  5553. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5554. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5555. },
  5556. visitVariable: function (variable) {
  5557. this.parts.push('v', variable.index);
  5558. },
  5559. visitLiteral: function (literal) {
  5560. this.parts.push(literal.number);
  5561. },
  5562. visitBinaryOperation: function (operation) {
  5563. this.parts.push('(');
  5564. operation.arg1.visit(this);
  5565. this.parts.push(' ', operation.op, ' ');
  5566. operation.arg2.visit(this);
  5567. this.parts.push(')');
  5568. },
  5569. visitVariableDefinition: function (definition) {
  5570. this.parts.push('var ');
  5571. definition.variable.visit(this);
  5572. this.parts.push(' = ');
  5573. definition.arg.visit(this);
  5574. this.parts.push(';');
  5575. },
  5576. visitMin: function (max) {
  5577. this.parts.push('Math.min(');
  5578. max.arg.visit(this);
  5579. this.parts.push(', ', max.max, ')');
  5580. },
  5581. toString: function () {
  5582. return this.parts.join('');
  5583. }
  5584. };
  5585. function buildAddOperation(num1, num2) {
  5586. if (num2.type === 'literal' && num2.number === 0) {
  5587. // optimization: second operand is 0
  5588. return num1;
  5589. }
  5590. if (num1.type === 'literal' && num1.number === 0) {
  5591. // optimization: first operand is 0
  5592. return num2;
  5593. }
  5594. if (num2.type === 'literal' && num1.type === 'literal') {
  5595. // optimization: operands operand are literals
  5596. return new AstLiteral(num1.number + num2.number);
  5597. }
  5598. return new AstBinaryOperation('+', num1, num2,
  5599. num1.min + num2.min, num1.max + num2.max);
  5600. }
  5601. function buildMulOperation(num1, num2) {
  5602. if (num2.type === 'literal') {
  5603. // optimization: second operands is a literal...
  5604. if (num2.number === 0) {
  5605. return new AstLiteral(0); // and it's 0
  5606. } else if (num2.number === 1) {
  5607. return num1; // and it's 1
  5608. } else if (num1.type === 'literal') {
  5609. // ... and first operands is a literal too
  5610. return new AstLiteral(num1.number * num2.number);
  5611. }
  5612. }
  5613. if (num1.type === 'literal') {
  5614. // optimization: first operands is a literal...
  5615. if (num1.number === 0) {
  5616. return new AstLiteral(0); // and it's 0
  5617. } else if (num1.number === 1) {
  5618. return num2; // and it's 1
  5619. }
  5620. }
  5621. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5622. num1.max * num2.min, num1.max * num2.max);
  5623. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5624. num1.max * num2.min, num1.max * num2.max);
  5625. return new AstBinaryOperation('*', num1, num2, min, max);
  5626. }
  5627. function buildSubOperation(num1, num2) {
  5628. if (num2.type === 'literal') {
  5629. // optimization: second operands is a literal...
  5630. if (num2.number === 0) {
  5631. return num1; // ... and it's 0
  5632. } else if (num1.type === 'literal') {
  5633. // ... and first operands is a literal too
  5634. return new AstLiteral(num1.number - num2.number);
  5635. }
  5636. }
  5637. if (num2.type === 'binary' && num2.op === '-' &&
  5638. num1.type === 'literal' && num1.number === 1 &&
  5639. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5640. // optimization for case: 1 - (1 - x)
  5641. return num2.arg2;
  5642. }
  5643. return new AstBinaryOperation('-', num1, num2,
  5644. num1.min - num2.max, num1.max - num2.min);
  5645. }
  5646. function buildMinOperation(num1, max) {
  5647. if (num1.min >= max) {
  5648. // optimization: num1 min value is not less than required max
  5649. return new AstLiteral(max); // just returning max
  5650. } else if (num1.max <= max) {
  5651. // optimization: num1 max value is not greater than required max
  5652. return num1; // just returning an argument
  5653. }
  5654. return new AstMin(num1, max);
  5655. }
  5656. function PostScriptCompiler() {}
  5657. PostScriptCompiler.prototype = {
  5658. compile: function PostScriptCompiler_compile(code, domain, range) {
  5659. var stack = [];
  5660. var i, ii;
  5661. var instructions = [];
  5662. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5663. var lastRegister = 0;
  5664. var n, j, min, max;
  5665. var num1, num2, ast1, ast2, tmpVar, item;
  5666. for (i = 0; i < inputSize; i++) {
  5667. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5668. }
  5669. for (i = 0, ii = code.length; i < ii; i++) {
  5670. item = code[i];
  5671. if (typeof item === 'number') {
  5672. stack.push(new AstLiteral(item));
  5673. continue;
  5674. }
  5675. switch (item) {
  5676. case 'add':
  5677. if (stack.length < 2) {
  5678. return null;
  5679. }
  5680. num2 = stack.pop();
  5681. num1 = stack.pop();
  5682. stack.push(buildAddOperation(num1, num2));
  5683. break;
  5684. case 'cvr':
  5685. if (stack.length < 1) {
  5686. return null;
  5687. }
  5688. break;
  5689. case 'mul':
  5690. if (stack.length < 2) {
  5691. return null;
  5692. }
  5693. num2 = stack.pop();
  5694. num1 = stack.pop();
  5695. stack.push(buildMulOperation(num1, num2));
  5696. break;
  5697. case 'sub':
  5698. if (stack.length < 2) {
  5699. return null;
  5700. }
  5701. num2 = stack.pop();
  5702. num1 = stack.pop();
  5703. stack.push(buildSubOperation(num1, num2));
  5704. break;
  5705. case 'exch':
  5706. if (stack.length < 2) {
  5707. return null;
  5708. }
  5709. ast1 = stack.pop(); ast2 = stack.pop();
  5710. stack.push(ast1, ast2);
  5711. break;
  5712. case 'pop':
  5713. if (stack.length < 1) {
  5714. return null;
  5715. }
  5716. stack.pop();
  5717. break;
  5718. case 'index':
  5719. if (stack.length < 1) {
  5720. return null;
  5721. }
  5722. num1 = stack.pop();
  5723. if (num1.type !== 'literal') {
  5724. return null;
  5725. }
  5726. n = num1.number;
  5727. if (n < 0 || (n|0) !== n || stack.length < n) {
  5728. return null;
  5729. }
  5730. ast1 = stack[stack.length - n - 1];
  5731. if (ast1.type === 'literal' || ast1.type === 'var') {
  5732. stack.push(ast1);
  5733. break;
  5734. }
  5735. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5736. stack[stack.length - n - 1] = tmpVar;
  5737. stack.push(tmpVar);
  5738. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5739. break;
  5740. case 'dup':
  5741. if (stack.length < 1) {
  5742. return null;
  5743. }
  5744. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5745. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5746. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5747. // special case of the commands sequence for the min operation
  5748. num1 = stack.pop();
  5749. stack.push(buildMinOperation(num1, code[i + 1]));
  5750. i += 6;
  5751. break;
  5752. }
  5753. ast1 = stack[stack.length - 1];
  5754. if (ast1.type === 'literal' || ast1.type === 'var') {
  5755. // we don't have to save into intermediate variable a literal or
  5756. // variable.
  5757. stack.push(ast1);
  5758. break;
  5759. }
  5760. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5761. stack[stack.length - 1] = tmpVar;
  5762. stack.push(tmpVar);
  5763. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5764. break;
  5765. case 'roll':
  5766. if (stack.length < 2) {
  5767. return null;
  5768. }
  5769. num2 = stack.pop();
  5770. num1 = stack.pop();
  5771. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5772. // both roll operands must be numbers
  5773. return null;
  5774. }
  5775. j = num2.number;
  5776. n = num1.number;
  5777. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5778. // ... and integers
  5779. return null;
  5780. }
  5781. j = ((j % n) + n) % n;
  5782. if (j === 0) {
  5783. break; // just skipping -- there are nothing to rotate
  5784. }
  5785. Array.prototype.push.apply(stack,
  5786. stack.splice(stack.length - n, n - j));
  5787. break;
  5788. default:
  5789. return null; // unsupported operator
  5790. }
  5791. }
  5792. if (stack.length !== outputSize) {
  5793. return null;
  5794. }
  5795. var result = [];
  5796. instructions.forEach(function (instruction) {
  5797. var statementBuilder = new ExpressionBuilderVisitor();
  5798. instruction.visit(statementBuilder);
  5799. result.push(statementBuilder.toString());
  5800. });
  5801. stack.forEach(function (expr, i) {
  5802. var statementBuilder = new ExpressionBuilderVisitor();
  5803. expr.visit(statementBuilder);
  5804. var min = range[i * 2], max = range[i * 2 + 1];
  5805. var out = [statementBuilder.toString()];
  5806. if (min > expr.min) {
  5807. out.unshift('Math.max(', min, ', ');
  5808. out.push(')');
  5809. }
  5810. if (max < expr.max) {
  5811. out.unshift('Math.min(', max, ', ');
  5812. out.push(')');
  5813. }
  5814. out.unshift('dest[destOffset + ', i, '] = ');
  5815. out.push(';');
  5816. result.push(out.join(''));
  5817. });
  5818. return result.join('\n');
  5819. }
  5820. };
  5821. return PostScriptCompiler;
  5822. })();
  5823. var ColorSpace = (function ColorSpaceClosure() {
  5824. // Constructor should define this.numComps, this.defaultColor, this.name
  5825. function ColorSpace() {
  5826. error('should not call ColorSpace constructor');
  5827. }
  5828. ColorSpace.prototype = {
  5829. /**
  5830. * Converts the color value to the RGB color. The color components are
  5831. * located in the src array starting from the srcOffset. Returns the array
  5832. * of the rgb components, each value ranging from [0,255].
  5833. */
  5834. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5835. var rgb = new Uint8Array(3);
  5836. this.getRgbItem(src, srcOffset, rgb, 0);
  5837. return rgb;
  5838. },
  5839. /**
  5840. * Converts the color value to the RGB color, similar to the getRgb method.
  5841. * The result placed into the dest array starting from the destOffset.
  5842. */
  5843. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5844. dest, destOffset) {
  5845. error('Should not call ColorSpace.getRgbItem');
  5846. },
  5847. /**
  5848. * Converts the specified number of the color values to the RGB colors.
  5849. * The colors are located in the src array starting from the srcOffset.
  5850. * The result is placed into the dest array starting from the destOffset.
  5851. * The src array items shall be in [0,2^bits) range, the dest array items
  5852. * will be in [0,255] range. alpha01 indicates how many alpha components
  5853. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5854. * array).
  5855. */
  5856. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5857. dest, destOffset, bits,
  5858. alpha01) {
  5859. error('Should not call ColorSpace.getRgbBuffer');
  5860. },
  5861. /**
  5862. * Determines the number of bytes required to store the result of the
  5863. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5864. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5865. */
  5866. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5867. alpha01) {
  5868. error('Should not call ColorSpace.getOutputLength');
  5869. },
  5870. /**
  5871. * Returns true if source data will be equal the result/output data.
  5872. */
  5873. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5874. return false;
  5875. },
  5876. /**
  5877. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5878. * how many alpha components there are in the dest array; it will be either
  5879. * 0 (RGB array) or 1 (RGBA array).
  5880. */
  5881. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5882. originalHeight, width, height,
  5883. actualHeight, bpc, comps, alpha01) {
  5884. var count = originalWidth * originalHeight;
  5885. var rgbBuf = null;
  5886. var numComponentColors = 1 << bpc;
  5887. var needsResizing = originalHeight !== height || originalWidth !== width;
  5888. var i, ii;
  5889. if (this.isPassthrough(bpc)) {
  5890. rgbBuf = comps;
  5891. } else if (this.numComps === 1 && count > numComponentColors &&
  5892. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5893. // Optimization: create a color map when there is just one component and
  5894. // we are converting more colors than the size of the color map. We
  5895. // don't build the map if the colorspace is gray or rgb since those
  5896. // methods are faster than building a map. This mainly offers big speed
  5897. // ups for indexed and alternate colorspaces.
  5898. //
  5899. // TODO it may be worth while to cache the color map. While running
  5900. // testing I never hit a cache so I will leave that out for now (perhaps
  5901. // we are reparsing colorspaces too much?).
  5902. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5903. new Uint16Array(numComponentColors);
  5904. var key;
  5905. for (i = 0; i < numComponentColors; i++) {
  5906. allColors[i] = i;
  5907. }
  5908. var colorMap = new Uint8Array(numComponentColors * 3);
  5909. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5910. /* alpha01 = */ 0);
  5911. var destPos, rgbPos;
  5912. if (!needsResizing) {
  5913. // Fill in the RGB values directly into |dest|.
  5914. destPos = 0;
  5915. for (i = 0; i < count; ++i) {
  5916. key = comps[i] * 3;
  5917. dest[destPos++] = colorMap[key];
  5918. dest[destPos++] = colorMap[key + 1];
  5919. dest[destPos++] = colorMap[key + 2];
  5920. destPos += alpha01;
  5921. }
  5922. } else {
  5923. rgbBuf = new Uint8Array(count * 3);
  5924. rgbPos = 0;
  5925. for (i = 0; i < count; ++i) {
  5926. key = comps[i] * 3;
  5927. rgbBuf[rgbPos++] = colorMap[key];
  5928. rgbBuf[rgbPos++] = colorMap[key + 1];
  5929. rgbBuf[rgbPos++] = colorMap[key + 2];
  5930. }
  5931. }
  5932. } else {
  5933. if (!needsResizing) {
  5934. // Fill in the RGB values directly into |dest|.
  5935. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5936. alpha01);
  5937. } else {
  5938. rgbBuf = new Uint8Array(count * 3);
  5939. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5940. /* alpha01 = */ 0);
  5941. }
  5942. }
  5943. if (rgbBuf) {
  5944. if (needsResizing) {
  5945. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5946. height, dest, alpha01);
  5947. } else {
  5948. rgbPos = 0;
  5949. destPos = 0;
  5950. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5951. dest[destPos++] = rgbBuf[rgbPos++];
  5952. dest[destPos++] = rgbBuf[rgbPos++];
  5953. dest[destPos++] = rgbBuf[rgbPos++];
  5954. destPos += alpha01;
  5955. }
  5956. }
  5957. }
  5958. },
  5959. /**
  5960. * True if the colorspace has components in the default range of [0, 1].
  5961. * This should be true for all colorspaces except for lab color spaces
  5962. * which are [0,100], [-128, 127], [-128, 127].
  5963. */
  5964. usesZeroToOneRange: true
  5965. };
  5966. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5967. var IR = ColorSpace.parseToIR(cs, xref, res);
  5968. if (IR instanceof AlternateCS) {
  5969. return IR;
  5970. }
  5971. return ColorSpace.fromIR(IR);
  5972. };
  5973. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5974. var name = isArray(IR) ? IR[0] : IR;
  5975. var whitePoint, blackPoint, gamma;
  5976. switch (name) {
  5977. case 'DeviceGrayCS':
  5978. return this.singletons.gray;
  5979. case 'DeviceRgbCS':
  5980. return this.singletons.rgb;
  5981. case 'DeviceCmykCS':
  5982. return this.singletons.cmyk;
  5983. case 'CalGrayCS':
  5984. whitePoint = IR[1].WhitePoint;
  5985. blackPoint = IR[1].BlackPoint;
  5986. gamma = IR[1].Gamma;
  5987. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5988. case 'CalRGBCS':
  5989. whitePoint = IR[1].WhitePoint;
  5990. blackPoint = IR[1].BlackPoint;
  5991. gamma = IR[1].Gamma;
  5992. var matrix = IR[1].Matrix;
  5993. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5994. case 'PatternCS':
  5995. var basePatternCS = IR[1];
  5996. if (basePatternCS) {
  5997. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5998. }
  5999. return new PatternCS(basePatternCS);
  6000. case 'IndexedCS':
  6001. var baseIndexedCS = IR[1];
  6002. var hiVal = IR[2];
  6003. var lookup = IR[3];
  6004. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6005. case 'AlternateCS':
  6006. var numComps = IR[1];
  6007. var alt = IR[2];
  6008. var tintFnIR = IR[3];
  6009. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6010. PDFFunction.fromIR(tintFnIR));
  6011. case 'LabCS':
  6012. whitePoint = IR[1].WhitePoint;
  6013. blackPoint = IR[1].BlackPoint;
  6014. var range = IR[1].Range;
  6015. return new LabCS(whitePoint, blackPoint, range);
  6016. default:
  6017. error('Unknown name ' + name);
  6018. }
  6019. return null;
  6020. };
  6021. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6022. if (isName(cs)) {
  6023. var colorSpaces = res.get('ColorSpace');
  6024. if (isDict(colorSpaces)) {
  6025. var refcs = colorSpaces.get(cs.name);
  6026. if (refcs) {
  6027. cs = refcs;
  6028. }
  6029. }
  6030. }
  6031. cs = xref.fetchIfRef(cs);
  6032. var mode;
  6033. if (isName(cs)) {
  6034. mode = cs.name;
  6035. this.mode = mode;
  6036. switch (mode) {
  6037. case 'DeviceGray':
  6038. case 'G':
  6039. return 'DeviceGrayCS';
  6040. case 'DeviceRGB':
  6041. case 'RGB':
  6042. return 'DeviceRgbCS';
  6043. case 'DeviceCMYK':
  6044. case 'CMYK':
  6045. return 'DeviceCmykCS';
  6046. case 'Pattern':
  6047. return ['PatternCS', null];
  6048. default:
  6049. error('unrecognized colorspace ' + mode);
  6050. }
  6051. } else if (isArray(cs)) {
  6052. mode = cs[0].name;
  6053. this.mode = mode;
  6054. var numComps, params;
  6055. switch (mode) {
  6056. case 'DeviceGray':
  6057. case 'G':
  6058. return 'DeviceGrayCS';
  6059. case 'DeviceRGB':
  6060. case 'RGB':
  6061. return 'DeviceRgbCS';
  6062. case 'DeviceCMYK':
  6063. case 'CMYK':
  6064. return 'DeviceCmykCS';
  6065. case 'CalGray':
  6066. params = cs[1].getAll();
  6067. return ['CalGrayCS', params];
  6068. case 'CalRGB':
  6069. params = cs[1].getAll();
  6070. return ['CalRGBCS', params];
  6071. case 'ICCBased':
  6072. var stream = xref.fetchIfRef(cs[1]);
  6073. var dict = stream.dict;
  6074. numComps = dict.get('N');
  6075. if (numComps === 1) {
  6076. return 'DeviceGrayCS';
  6077. } else if (numComps === 3) {
  6078. return 'DeviceRgbCS';
  6079. } else if (numComps === 4) {
  6080. return 'DeviceCmykCS';
  6081. }
  6082. break;
  6083. case 'Pattern':
  6084. var basePatternCS = cs[1];
  6085. if (basePatternCS) {
  6086. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6087. }
  6088. return ['PatternCS', basePatternCS];
  6089. case 'Indexed':
  6090. case 'I':
  6091. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6092. var hiVal = cs[2] + 1;
  6093. var lookup = xref.fetchIfRef(cs[3]);
  6094. if (isStream(lookup)) {
  6095. lookup = lookup.getBytes();
  6096. }
  6097. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6098. case 'Separation':
  6099. case 'DeviceN':
  6100. var name = cs[1];
  6101. numComps = 1;
  6102. if (isName(name)) {
  6103. numComps = 1;
  6104. } else if (isArray(name)) {
  6105. numComps = name.length;
  6106. }
  6107. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  6108. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6109. return ['AlternateCS', numComps, alt, tintFnIR];
  6110. case 'Lab':
  6111. params = cs[1].getAll();
  6112. return ['LabCS', params];
  6113. default:
  6114. error('unimplemented color space object "' + mode + '"');
  6115. }
  6116. } else {
  6117. error('unrecognized color space object: "' + cs + '"');
  6118. }
  6119. return null;
  6120. };
  6121. /**
  6122. * Checks if a decode map matches the default decode map for a color space.
  6123. * This handles the general decode maps where there are two values per
  6124. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6125. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6126. * slightly different.
  6127. * @param {Array} decode Decode map (usually from an image).
  6128. * @param {Number} n Number of components the color space has.
  6129. */
  6130. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6131. if (!decode) {
  6132. return true;
  6133. }
  6134. if (n * 2 !== decode.length) {
  6135. warn('The decode map is not the correct length');
  6136. return true;
  6137. }
  6138. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6139. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6140. return false;
  6141. }
  6142. }
  6143. return true;
  6144. };
  6145. ColorSpace.singletons = {
  6146. get gray() {
  6147. return shadow(this, 'gray', new DeviceGrayCS());
  6148. },
  6149. get rgb() {
  6150. return shadow(this, 'rgb', new DeviceRgbCS());
  6151. },
  6152. get cmyk() {
  6153. return shadow(this, 'cmyk', new DeviceCmykCS());
  6154. }
  6155. };
  6156. return ColorSpace;
  6157. })();
  6158. /**
  6159. * Alternate color space handles both Separation and DeviceN color spaces. A
  6160. * Separation color space is actually just a DeviceN with one color component.
  6161. * Both color spaces use a tinting function to convert colors to a base color
  6162. * space.
  6163. */
  6164. var AlternateCS = (function AlternateCSClosure() {
  6165. function AlternateCS(numComps, base, tintFn) {
  6166. this.name = 'Alternate';
  6167. this.numComps = numComps;
  6168. this.defaultColor = new Float32Array(numComps);
  6169. for (var i = 0; i < numComps; ++i) {
  6170. this.defaultColor[i] = 1;
  6171. }
  6172. this.base = base;
  6173. this.tintFn = tintFn;
  6174. this.tmpBuf = new Float32Array(base.numComps);
  6175. }
  6176. AlternateCS.prototype = {
  6177. getRgb: ColorSpace.prototype.getRgb,
  6178. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6179. dest, destOffset) {
  6180. var tmpBuf = this.tmpBuf;
  6181. this.tintFn(src, srcOffset, tmpBuf, 0);
  6182. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6183. },
  6184. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6185. dest, destOffset, bits,
  6186. alpha01) {
  6187. var tintFn = this.tintFn;
  6188. var base = this.base;
  6189. var scale = 1 / ((1 << bits) - 1);
  6190. var baseNumComps = base.numComps;
  6191. var usesZeroToOneRange = base.usesZeroToOneRange;
  6192. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6193. alpha01 === 0;
  6194. var pos = isPassthrough ? destOffset : 0;
  6195. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6196. var numComps = this.numComps;
  6197. var scaled = new Float32Array(numComps);
  6198. var tinted = new Float32Array(baseNumComps);
  6199. var i, j;
  6200. if (usesZeroToOneRange) {
  6201. for (i = 0; i < count; i++) {
  6202. for (j = 0; j < numComps; j++) {
  6203. scaled[j] = src[srcOffset++] * scale;
  6204. }
  6205. tintFn(scaled, 0, tinted, 0);
  6206. for (j = 0; j < baseNumComps; j++) {
  6207. baseBuf[pos++] = tinted[j] * 255;
  6208. }
  6209. }
  6210. } else {
  6211. for (i = 0; i < count; i++) {
  6212. for (j = 0; j < numComps; j++) {
  6213. scaled[j] = src[srcOffset++] * scale;
  6214. }
  6215. tintFn(scaled, 0, tinted, 0);
  6216. base.getRgbItem(tinted, 0, baseBuf, pos);
  6217. pos += baseNumComps;
  6218. }
  6219. }
  6220. if (!isPassthrough) {
  6221. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6222. }
  6223. },
  6224. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6225. alpha01) {
  6226. return this.base.getOutputLength(inputLength *
  6227. this.base.numComps / this.numComps,
  6228. alpha01);
  6229. },
  6230. isPassthrough: ColorSpace.prototype.isPassthrough,
  6231. fillRgb: ColorSpace.prototype.fillRgb,
  6232. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6233. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6234. },
  6235. usesZeroToOneRange: true
  6236. };
  6237. return AlternateCS;
  6238. })();
  6239. var PatternCS = (function PatternCSClosure() {
  6240. function PatternCS(baseCS) {
  6241. this.name = 'Pattern';
  6242. this.base = baseCS;
  6243. }
  6244. PatternCS.prototype = {};
  6245. return PatternCS;
  6246. })();
  6247. var IndexedCS = (function IndexedCSClosure() {
  6248. function IndexedCS(base, highVal, lookup) {
  6249. this.name = 'Indexed';
  6250. this.numComps = 1;
  6251. this.defaultColor = new Uint8Array([0]);
  6252. this.base = base;
  6253. this.highVal = highVal;
  6254. var baseNumComps = base.numComps;
  6255. var length = baseNumComps * highVal;
  6256. var lookupArray;
  6257. if (isStream(lookup)) {
  6258. lookupArray = new Uint8Array(length);
  6259. var bytes = lookup.getBytes(length);
  6260. lookupArray.set(bytes);
  6261. } else if (isString(lookup)) {
  6262. lookupArray = new Uint8Array(length);
  6263. for (var i = 0; i < length; ++i) {
  6264. lookupArray[i] = lookup.charCodeAt(i);
  6265. }
  6266. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6267. lookupArray = lookup;
  6268. } else {
  6269. error('Unrecognized lookup table: ' + lookup);
  6270. }
  6271. this.lookup = lookupArray;
  6272. }
  6273. IndexedCS.prototype = {
  6274. getRgb: ColorSpace.prototype.getRgb,
  6275. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6276. dest, destOffset) {
  6277. var numComps = this.base.numComps;
  6278. var start = src[srcOffset] * numComps;
  6279. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6280. },
  6281. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6282. dest, destOffset, bits,
  6283. alpha01) {
  6284. var base = this.base;
  6285. var numComps = base.numComps;
  6286. var outputDelta = base.getOutputLength(numComps, alpha01);
  6287. var lookup = this.lookup;
  6288. for (var i = 0; i < count; ++i) {
  6289. var lookupPos = src[srcOffset++] * numComps;
  6290. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6291. destOffset += outputDelta;
  6292. }
  6293. },
  6294. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6295. return this.base.getOutputLength(inputLength * this.base.numComps,
  6296. alpha01);
  6297. },
  6298. isPassthrough: ColorSpace.prototype.isPassthrough,
  6299. fillRgb: ColorSpace.prototype.fillRgb,
  6300. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6301. // indexed color maps shouldn't be changed
  6302. return true;
  6303. },
  6304. usesZeroToOneRange: true
  6305. };
  6306. return IndexedCS;
  6307. })();
  6308. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6309. function DeviceGrayCS() {
  6310. this.name = 'DeviceGray';
  6311. this.numComps = 1;
  6312. this.defaultColor = new Float32Array([0]);
  6313. }
  6314. DeviceGrayCS.prototype = {
  6315. getRgb: ColorSpace.prototype.getRgb,
  6316. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6317. dest, destOffset) {
  6318. var c = (src[srcOffset] * 255) | 0;
  6319. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6320. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6321. },
  6322. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6323. dest, destOffset, bits,
  6324. alpha01) {
  6325. var scale = 255 / ((1 << bits) - 1);
  6326. var j = srcOffset, q = destOffset;
  6327. for (var i = 0; i < count; ++i) {
  6328. var c = (scale * src[j++]) | 0;
  6329. dest[q++] = c;
  6330. dest[q++] = c;
  6331. dest[q++] = c;
  6332. q += alpha01;
  6333. }
  6334. },
  6335. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6336. alpha01) {
  6337. return inputLength * (3 + alpha01);
  6338. },
  6339. isPassthrough: ColorSpace.prototype.isPassthrough,
  6340. fillRgb: ColorSpace.prototype.fillRgb,
  6341. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6342. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6343. },
  6344. usesZeroToOneRange: true
  6345. };
  6346. return DeviceGrayCS;
  6347. })();
  6348. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6349. function DeviceRgbCS() {
  6350. this.name = 'DeviceRGB';
  6351. this.numComps = 3;
  6352. this.defaultColor = new Float32Array([0, 0, 0]);
  6353. }
  6354. DeviceRgbCS.prototype = {
  6355. getRgb: ColorSpace.prototype.getRgb,
  6356. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6357. dest, destOffset) {
  6358. var r = (src[srcOffset] * 255) | 0;
  6359. var g = (src[srcOffset + 1] * 255) | 0;
  6360. var b = (src[srcOffset + 2] * 255) | 0;
  6361. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6362. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6363. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6364. },
  6365. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6366. dest, destOffset, bits,
  6367. alpha01) {
  6368. if (bits === 8 && alpha01 === 0) {
  6369. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6370. return;
  6371. }
  6372. var scale = 255 / ((1 << bits) - 1);
  6373. var j = srcOffset, q = destOffset;
  6374. for (var i = 0; i < count; ++i) {
  6375. dest[q++] = (scale * src[j++]) | 0;
  6376. dest[q++] = (scale * src[j++]) | 0;
  6377. dest[q++] = (scale * src[j++]) | 0;
  6378. q += alpha01;
  6379. }
  6380. },
  6381. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6382. alpha01) {
  6383. return (inputLength * (3 + alpha01) / 3) | 0;
  6384. },
  6385. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6386. return bits === 8;
  6387. },
  6388. fillRgb: ColorSpace.prototype.fillRgb,
  6389. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6390. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6391. },
  6392. usesZeroToOneRange: true
  6393. };
  6394. return DeviceRgbCS;
  6395. })();
  6396. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6397. // The coefficients below was found using numerical analysis: the method of
  6398. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6399. // where color_value is the tabular value from the table of sampled RGB colors
  6400. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6401. // CMYK color conversion using the estimation below:
  6402. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6403. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6404. var c = src[srcOffset + 0] * srcScale;
  6405. var m = src[srcOffset + 1] * srcScale;
  6406. var y = src[srcOffset + 2] * srcScale;
  6407. var k = src[srcOffset + 3] * srcScale;
  6408. var r =
  6409. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6410. 18.82290502165302 * y + 212.25662451639585 * k +
  6411. -285.2331026137004) +
  6412. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6413. -17.873870861415444 * k - 5.497006427196366) +
  6414. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6415. 17.5119270841813) +
  6416. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6417. var g =
  6418. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6419. 6.871425592049007 * y + 31.159100130055922 * k +
  6420. -79.2970844816548) +
  6421. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6422. 131.35250912493976 * k - 190.9453302588951) +
  6423. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6424. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6425. var b =
  6426. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6427. 30.89978309703729 * y - 0.23883238689178934 * k +
  6428. -14.183576799673286) +
  6429. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6430. 50.606957656360734 * k - 112.23884253719248) +
  6431. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6432. -193.58209356861505) +
  6433. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6434. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6435. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6436. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6437. }
  6438. function DeviceCmykCS() {
  6439. this.name = 'DeviceCMYK';
  6440. this.numComps = 4;
  6441. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6442. }
  6443. DeviceCmykCS.prototype = {
  6444. getRgb: ColorSpace.prototype.getRgb,
  6445. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6446. dest, destOffset) {
  6447. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6448. },
  6449. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6450. dest, destOffset, bits,
  6451. alpha01) {
  6452. var scale = 1 / ((1 << bits) - 1);
  6453. for (var i = 0; i < count; i++) {
  6454. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6455. srcOffset += 4;
  6456. destOffset += 3 + alpha01;
  6457. }
  6458. },
  6459. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6460. alpha01) {
  6461. return (inputLength / 4 * (3 + alpha01)) | 0;
  6462. },
  6463. isPassthrough: ColorSpace.prototype.isPassthrough,
  6464. fillRgb: ColorSpace.prototype.fillRgb,
  6465. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6466. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6467. },
  6468. usesZeroToOneRange: true
  6469. };
  6470. return DeviceCmykCS;
  6471. })();
  6472. //
  6473. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6474. //
  6475. var CalGrayCS = (function CalGrayCSClosure() {
  6476. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6477. this.name = 'CalGray';
  6478. this.numComps = 1;
  6479. this.defaultColor = new Float32Array([0]);
  6480. if (!whitePoint) {
  6481. error('WhitePoint missing - required for color space CalGray');
  6482. }
  6483. blackPoint = blackPoint || [0, 0, 0];
  6484. gamma = gamma || 1;
  6485. // Translate arguments to spec variables.
  6486. this.XW = whitePoint[0];
  6487. this.YW = whitePoint[1];
  6488. this.ZW = whitePoint[2];
  6489. this.XB = blackPoint[0];
  6490. this.YB = blackPoint[1];
  6491. this.ZB = blackPoint[2];
  6492. this.G = gamma;
  6493. // Validate variables as per spec.
  6494. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6495. error('Invalid WhitePoint components for ' + this.name +
  6496. ', no fallback available');
  6497. }
  6498. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6499. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6500. this.XB = this.YB = this.ZB = 0;
  6501. }
  6502. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6503. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6504. ', ZB: ' + this.ZB + ', only default values are supported.');
  6505. }
  6506. if (this.G < 1) {
  6507. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6508. ', falling back to default');
  6509. this.G = 1;
  6510. }
  6511. }
  6512. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6513. // A represents a gray component of a calibrated gray space.
  6514. // A <---> AG in the spec
  6515. var A = src[srcOffset] * scale;
  6516. var AG = Math.pow(A, cs.G);
  6517. // Computes L as per spec. ( = cs.YW * AG )
  6518. // Except if other than default BlackPoint values are used.
  6519. var L = cs.YW * AG;
  6520. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6521. // Convert values to rgb range [0, 255].
  6522. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6523. dest[destOffset] = val;
  6524. dest[destOffset + 1] = val;
  6525. dest[destOffset + 2] = val;
  6526. }
  6527. CalGrayCS.prototype = {
  6528. getRgb: ColorSpace.prototype.getRgb,
  6529. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6530. dest, destOffset) {
  6531. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6532. },
  6533. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6534. dest, destOffset, bits,
  6535. alpha01) {
  6536. var scale = 1 / ((1 << bits) - 1);
  6537. for (var i = 0; i < count; ++i) {
  6538. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6539. srcOffset += 1;
  6540. destOffset += 3 + alpha01;
  6541. }
  6542. },
  6543. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6544. return inputLength * (3 + alpha01);
  6545. },
  6546. isPassthrough: ColorSpace.prototype.isPassthrough,
  6547. fillRgb: ColorSpace.prototype.fillRgb,
  6548. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6549. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6550. },
  6551. usesZeroToOneRange: true
  6552. };
  6553. return CalGrayCS;
  6554. })();
  6555. //
  6556. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6557. //
  6558. var CalRGBCS = (function CalRGBCSClosure() {
  6559. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6560. // matrices.
  6561. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6562. 0.8951, 0.2664, -0.1614,
  6563. -0.7502, 1.7135, 0.0367,
  6564. 0.0389, -0.0685, 1.0296]);
  6565. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6566. 0.9869929, -0.1470543, 0.1599627,
  6567. 0.4323053, 0.5183603, 0.0492912,
  6568. -0.0085287, 0.0400428, 0.9684867]);
  6569. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6570. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6571. 3.2404542, -1.5371385, -0.4985314,
  6572. -0.9692660, 1.8760108, 0.0415560,
  6573. 0.0556434, -0.2040259, 1.0572252]);
  6574. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6575. var tempNormalizeMatrix = new Float32Array(3);
  6576. var tempConvertMatrix1 = new Float32Array(3);
  6577. var tempConvertMatrix2 = new Float32Array(3);
  6578. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6579. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6580. this.name = 'CalRGB';
  6581. this.numComps = 3;
  6582. this.defaultColor = new Float32Array(3);
  6583. if (!whitePoint) {
  6584. error('WhitePoint missing - required for color space CalRGB');
  6585. }
  6586. blackPoint = blackPoint || new Float32Array(3);
  6587. gamma = gamma || new Float32Array([1, 1, 1]);
  6588. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6589. // Translate arguments to spec variables.
  6590. var XW = whitePoint[0];
  6591. var YW = whitePoint[1];
  6592. var ZW = whitePoint[2];
  6593. this.whitePoint = whitePoint;
  6594. var XB = blackPoint[0];
  6595. var YB = blackPoint[1];
  6596. var ZB = blackPoint[2];
  6597. this.blackPoint = blackPoint;
  6598. this.GR = gamma[0];
  6599. this.GG = gamma[1];
  6600. this.GB = gamma[2];
  6601. this.MXA = matrix[0];
  6602. this.MYA = matrix[1];
  6603. this.MZA = matrix[2];
  6604. this.MXB = matrix[3];
  6605. this.MYB = matrix[4];
  6606. this.MZB = matrix[5];
  6607. this.MXC = matrix[6];
  6608. this.MYC = matrix[7];
  6609. this.MZC = matrix[8];
  6610. // Validate variables as per spec.
  6611. if (XW < 0 || ZW < 0 || YW !== 1) {
  6612. error('Invalid WhitePoint components for ' + this.name +
  6613. ', no fallback available');
  6614. }
  6615. if (XB < 0 || YB < 0 || ZB < 0) {
  6616. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6617. ', ' + ZB + '], falling back to default');
  6618. this.blackPoint = new Float32Array(3);
  6619. }
  6620. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6621. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6622. '] for ' + this.name + ', falling back to default');
  6623. this.GR = this.GG = this.GB = 1;
  6624. }
  6625. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6626. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6627. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6628. info('Invalid Matrix for ' + this.name + ' [' +
  6629. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6630. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6631. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6632. '], falling back to default');
  6633. this.MXA = this.MYB = this.MZC = 1;
  6634. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6635. }
  6636. }
  6637. function matrixProduct(a, b, result) {
  6638. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6639. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6640. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6641. }
  6642. function convertToFlat(sourceWhitePoint, LMS, result) {
  6643. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6644. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6645. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6646. }
  6647. function convertToD65(sourceWhitePoint, LMS, result) {
  6648. var D65X = 0.95047;
  6649. var D65Y = 1;
  6650. var D65Z = 1.08883;
  6651. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6652. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6653. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6654. }
  6655. function sRGBTransferFunction(color) {
  6656. // See http://en.wikipedia.org/wiki/SRGB.
  6657. if (color <= 0.0031308){
  6658. return adjustToRange(0, 1, 12.92 * color);
  6659. }
  6660. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6661. }
  6662. function adjustToRange(min, max, value) {
  6663. return Math.max(min, Math.min(max, value));
  6664. }
  6665. function decodeL(L) {
  6666. if (L < 0) {
  6667. return -decodeL(-L);
  6668. }
  6669. if (L > 8.0) {
  6670. return Math.pow(((L + 16) / 116), 3);
  6671. }
  6672. return L * DECODE_L_CONSTANT;
  6673. }
  6674. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6675. // In case the blackPoint is already the default blackPoint then there is
  6676. // no need to do compensation.
  6677. if (sourceBlackPoint[0] === 0 &&
  6678. sourceBlackPoint[1] === 0 &&
  6679. sourceBlackPoint[2] === 0) {
  6680. result[0] = XYZ_Flat[0];
  6681. result[1] = XYZ_Flat[1];
  6682. result[2] = XYZ_Flat[2];
  6683. return;
  6684. }
  6685. // For the blackPoint calculation details, please see
  6686. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6687. // AdobeBPC.pdf.
  6688. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6689. var zeroDecodeL = decodeL(0);
  6690. var X_DST = zeroDecodeL;
  6691. var X_SRC = decodeL(sourceBlackPoint[0]);
  6692. var Y_DST = zeroDecodeL;
  6693. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6694. var Z_DST = zeroDecodeL;
  6695. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6696. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6697. var X_Offset = 1 - X_Scale;
  6698. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6699. var Y_Offset = 1 - Y_Scale;
  6700. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6701. var Z_Offset = 1 - Z_Scale;
  6702. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6703. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6704. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6705. }
  6706. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6707. // In case the whitePoint is already flat then there is no need to do
  6708. // normalization.
  6709. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6710. result[0] = XYZ_In[0];
  6711. result[1] = XYZ_In[1];
  6712. result[2] = XYZ_In[2];
  6713. return;
  6714. }
  6715. var LMS = result;
  6716. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6717. var LMS_Flat = tempNormalizeMatrix;
  6718. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6719. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6720. }
  6721. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6722. var LMS = result;
  6723. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6724. var LMS_D65 = tempNormalizeMatrix;
  6725. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6726. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6727. }
  6728. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6729. // A, B and C represent a red, green and blue components of a calibrated
  6730. // rgb space.
  6731. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6732. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6733. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6734. // A <---> AGR in the spec
  6735. // B <---> BGG in the spec
  6736. // C <---> CGB in the spec
  6737. var AGR = Math.pow(A, cs.GR);
  6738. var BGG = Math.pow(B, cs.GG);
  6739. var CGB = Math.pow(C, cs.GB);
  6740. // Computes intermediate variables L, M, N as per spec.
  6741. // To decode X, Y, Z values map L, M, N directly to them.
  6742. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6743. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6744. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6745. // The following calculations are based on this document:
  6746. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6747. // AdobeBPC.pdf.
  6748. var XYZ = tempConvertMatrix1;
  6749. XYZ[0] = X;
  6750. XYZ[1] = Y;
  6751. XYZ[2] = Z;
  6752. var XYZ_Flat = tempConvertMatrix2;
  6753. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6754. var XYZ_Black = tempConvertMatrix1;
  6755. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6756. var XYZ_D65 = tempConvertMatrix2;
  6757. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6758. var SRGB = tempConvertMatrix1;
  6759. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6760. var sR = sRGBTransferFunction(SRGB[0]);
  6761. var sG = sRGBTransferFunction(SRGB[1]);
  6762. var sB = sRGBTransferFunction(SRGB[2]);
  6763. // Convert the values to rgb range [0, 255].
  6764. dest[destOffset] = Math.round(sR * 255);
  6765. dest[destOffset + 1] = Math.round(sG * 255);
  6766. dest[destOffset + 2] = Math.round(sB * 255);
  6767. }
  6768. CalRGBCS.prototype = {
  6769. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6770. var rgb = new Uint8Array(3);
  6771. this.getRgbItem(src, srcOffset, rgb, 0);
  6772. return rgb;
  6773. },
  6774. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6775. dest, destOffset) {
  6776. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6777. },
  6778. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6779. dest, destOffset, bits,
  6780. alpha01) {
  6781. var scale = 1 / ((1 << bits) - 1);
  6782. for (var i = 0; i < count; ++i) {
  6783. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6784. srcOffset += 3;
  6785. destOffset += 3 + alpha01;
  6786. }
  6787. },
  6788. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6789. return (inputLength * (3 + alpha01) / 3) | 0;
  6790. },
  6791. isPassthrough: ColorSpace.prototype.isPassthrough,
  6792. fillRgb: ColorSpace.prototype.fillRgb,
  6793. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6794. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6795. },
  6796. usesZeroToOneRange: true
  6797. };
  6798. return CalRGBCS;
  6799. })();
  6800. //
  6801. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6802. //
  6803. var LabCS = (function LabCSClosure() {
  6804. function LabCS(whitePoint, blackPoint, range) {
  6805. this.name = 'Lab';
  6806. this.numComps = 3;
  6807. this.defaultColor = new Float32Array([0, 0, 0]);
  6808. if (!whitePoint) {
  6809. error('WhitePoint missing - required for color space Lab');
  6810. }
  6811. blackPoint = blackPoint || [0, 0, 0];
  6812. range = range || [-100, 100, -100, 100];
  6813. // Translate args to spec variables
  6814. this.XW = whitePoint[0];
  6815. this.YW = whitePoint[1];
  6816. this.ZW = whitePoint[2];
  6817. this.amin = range[0];
  6818. this.amax = range[1];
  6819. this.bmin = range[2];
  6820. this.bmax = range[3];
  6821. // These are here just for completeness - the spec doesn't offer any
  6822. // formulas that use BlackPoint in Lab
  6823. this.XB = blackPoint[0];
  6824. this.YB = blackPoint[1];
  6825. this.ZB = blackPoint[2];
  6826. // Validate vars as per spec
  6827. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6828. error('Invalid WhitePoint components, no fallback available');
  6829. }
  6830. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6831. info('Invalid BlackPoint, falling back to default');
  6832. this.XB = this.YB = this.ZB = 0;
  6833. }
  6834. if (this.amin > this.amax || this.bmin > this.bmax) {
  6835. info('Invalid Range, falling back to defaults');
  6836. this.amin = -100;
  6837. this.amax = 100;
  6838. this.bmin = -100;
  6839. this.bmax = 100;
  6840. }
  6841. }
  6842. // Function g(x) from spec
  6843. function fn_g(x) {
  6844. if (x >= 6 / 29) {
  6845. return x * x * x;
  6846. } else {
  6847. return (108 / 841) * (x - 4 / 29);
  6848. }
  6849. }
  6850. function decode(value, high1, low2, high2) {
  6851. return low2 + (value) * (high2 - low2) / (high1);
  6852. }
  6853. // If decoding is needed maxVal should be 2^bits per component - 1.
  6854. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6855. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6856. // not the usual [0, 1]. If a command like setFillColor is used the src
  6857. // values will already be within the correct range. However, if we are
  6858. // converting an image we have to map the values to the correct range given
  6859. // above.
  6860. // Ls,as,bs <---> L*,a*,b* in the spec
  6861. var Ls = src[srcOffset];
  6862. var as = src[srcOffset + 1];
  6863. var bs = src[srcOffset + 2];
  6864. if (maxVal !== false) {
  6865. Ls = decode(Ls, maxVal, 0, 100);
  6866. as = decode(as, maxVal, cs.amin, cs.amax);
  6867. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6868. }
  6869. // Adjust limits of 'as' and 'bs'
  6870. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6871. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6872. // Computes intermediate variables X,Y,Z as per spec
  6873. var M = (Ls + 16) / 116;
  6874. var L = M + (as / 500);
  6875. var N = M - (bs / 200);
  6876. var X = cs.XW * fn_g(L);
  6877. var Y = cs.YW * fn_g(M);
  6878. var Z = cs.ZW * fn_g(N);
  6879. var r, g, b;
  6880. // Using different conversions for D50 and D65 white points,
  6881. // per http://www.color.org/srgb.pdf
  6882. if (cs.ZW < 1) {
  6883. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6884. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6885. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6886. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6887. } else {
  6888. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6889. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6890. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6891. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6892. }
  6893. // clamp color values to [0,1] range then convert to [0,255] range.
  6894. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6895. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6896. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6897. }
  6898. LabCS.prototype = {
  6899. getRgb: ColorSpace.prototype.getRgb,
  6900. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6901. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6902. },
  6903. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6904. dest, destOffset, bits,
  6905. alpha01) {
  6906. var maxVal = (1 << bits) - 1;
  6907. for (var i = 0; i < count; i++) {
  6908. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6909. srcOffset += 3;
  6910. destOffset += 3 + alpha01;
  6911. }
  6912. },
  6913. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6914. return (inputLength * (3 + alpha01) / 3) | 0;
  6915. },
  6916. isPassthrough: ColorSpace.prototype.isPassthrough,
  6917. fillRgb: ColorSpace.prototype.fillRgb,
  6918. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6919. // XXX: Decoding is handled with the lab conversion because of the strange
  6920. // ranges that are used.
  6921. return true;
  6922. },
  6923. usesZeroToOneRange: false
  6924. };
  6925. return LabCS;
  6926. })();
  6927. var ARCFourCipher = (function ARCFourCipherClosure() {
  6928. function ARCFourCipher(key) {
  6929. this.a = 0;
  6930. this.b = 0;
  6931. var s = new Uint8Array(256);
  6932. var i, j = 0, tmp, keyLength = key.length;
  6933. for (i = 0; i < 256; ++i) {
  6934. s[i] = i;
  6935. }
  6936. for (i = 0; i < 256; ++i) {
  6937. tmp = s[i];
  6938. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6939. s[i] = s[j];
  6940. s[j] = tmp;
  6941. }
  6942. this.s = s;
  6943. }
  6944. ARCFourCipher.prototype = {
  6945. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6946. var i, n = data.length, tmp, tmp2;
  6947. var a = this.a, b = this.b, s = this.s;
  6948. var output = new Uint8Array(n);
  6949. for (i = 0; i < n; ++i) {
  6950. a = (a + 1) & 0xFF;
  6951. tmp = s[a];
  6952. b = (b + tmp) & 0xFF;
  6953. tmp2 = s[b];
  6954. s[a] = tmp2;
  6955. s[b] = tmp;
  6956. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6957. }
  6958. this.a = a;
  6959. this.b = b;
  6960. return output;
  6961. }
  6962. };
  6963. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6964. return ARCFourCipher;
  6965. })();
  6966. var calculateMD5 = (function calculateMD5Closure() {
  6967. var r = new Uint8Array([
  6968. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6969. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6970. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6971. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6972. var k = new Int32Array([
  6973. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6974. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6975. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6976. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6977. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6978. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6979. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6980. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6981. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6982. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6983. -145523070, -1120210379, 718787259, -343485551]);
  6984. function hash(data, offset, length) {
  6985. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6986. // pre-processing
  6987. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6988. var padded = new Uint8Array(paddedLength);
  6989. var i, j, n;
  6990. for (i = 0; i < length; ++i) {
  6991. padded[i] = data[offset++];
  6992. }
  6993. padded[i++] = 0x80;
  6994. n = paddedLength - 8;
  6995. while (i < n) {
  6996. padded[i++] = 0;
  6997. }
  6998. padded[i++] = (length << 3) & 0xFF;
  6999. padded[i++] = (length >> 5) & 0xFF;
  7000. padded[i++] = (length >> 13) & 0xFF;
  7001. padded[i++] = (length >> 21) & 0xFF;
  7002. padded[i++] = (length >>> 29) & 0xFF;
  7003. padded[i++] = 0;
  7004. padded[i++] = 0;
  7005. padded[i++] = 0;
  7006. var w = new Int32Array(16);
  7007. for (i = 0; i < paddedLength;) {
  7008. for (j = 0; j < 16; ++j, i += 4) {
  7009. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7010. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7011. }
  7012. var a = h0, b = h1, c = h2, d = h3, f, g;
  7013. for (j = 0; j < 64; ++j) {
  7014. if (j < 16) {
  7015. f = (b & c) | ((~b) & d);
  7016. g = j;
  7017. } else if (j < 32) {
  7018. f = (d & b) | ((~d) & c);
  7019. g = (5 * j + 1) & 15;
  7020. } else if (j < 48) {
  7021. f = b ^ c ^ d;
  7022. g = (3 * j + 5) & 15;
  7023. } else {
  7024. f = c ^ (b | (~d));
  7025. g = (7 * j) & 15;
  7026. }
  7027. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7028. d = c;
  7029. c = b;
  7030. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7031. a = tmp;
  7032. }
  7033. h0 = (h0 + a) | 0;
  7034. h1 = (h1 + b) | 0;
  7035. h2 = (h2 + c) | 0;
  7036. h3 = (h3 + d) | 0;
  7037. }
  7038. return new Uint8Array([
  7039. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7040. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7041. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7042. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7043. ]);
  7044. }
  7045. return hash;
  7046. })();
  7047. var Word64 = (function Word64Closure() {
  7048. function Word64(highInteger, lowInteger) {
  7049. this.high = highInteger | 0;
  7050. this.low = lowInteger | 0;
  7051. }
  7052. Word64.prototype = {
  7053. and: function Word64_and(word) {
  7054. this.high &= word.high;
  7055. this.low &= word.low;
  7056. },
  7057. xor: function Word64_xor(word) {
  7058. this.high ^= word.high;
  7059. this.low ^= word.low;
  7060. },
  7061. or: function Word64_or(word) {
  7062. this.high |= word.high;
  7063. this.low |= word.low;
  7064. },
  7065. shiftRight: function Word64_shiftRight(places) {
  7066. if (places >= 32) {
  7067. this.low = (this.high >>> (places - 32)) | 0;
  7068. this.high = 0;
  7069. } else {
  7070. this.low = (this.low >>> places) | (this.high << (32 - places));
  7071. this.high = (this.high >>> places) | 0;
  7072. }
  7073. },
  7074. shiftLeft: function Word64_shiftLeft(places) {
  7075. if (places >= 32) {
  7076. this.high = this.low << (places - 32);
  7077. this.low = 0;
  7078. } else {
  7079. this.high = (this.high << places) | (this.low >>> (32 - places));
  7080. this.low = this.low << places;
  7081. }
  7082. },
  7083. rotateRight: function Word64_rotateRight(places) {
  7084. var low, high;
  7085. if (places & 32) {
  7086. high = this.low;
  7087. low = this.high;
  7088. } else {
  7089. low = this.low;
  7090. high = this.high;
  7091. }
  7092. places &= 31;
  7093. this.low = (low >>> places) | (high << (32 - places));
  7094. this.high = (high >>> places) | (low << (32 - places));
  7095. },
  7096. not: function Word64_not() {
  7097. this.high = ~this.high;
  7098. this.low = ~this.low;
  7099. },
  7100. add: function Word64_add(word) {
  7101. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7102. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7103. if (lowAdd > 0xFFFFFFFF) {
  7104. highAdd += 1;
  7105. }
  7106. this.low = lowAdd | 0;
  7107. this.high = highAdd | 0;
  7108. },
  7109. copyTo: function Word64_copyTo(bytes, offset) {
  7110. bytes[offset] = (this.high >>> 24) & 0xFF;
  7111. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7112. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7113. bytes[offset + 3] = this.high & 0xFF;
  7114. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7115. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7116. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7117. bytes[offset + 7] = this.low & 0xFF;
  7118. },
  7119. assign: function Word64_assign(word) {
  7120. this.high = word.high;
  7121. this.low = word.low;
  7122. }
  7123. };
  7124. return Word64;
  7125. })();
  7126. var calculateSHA256 = (function calculateSHA256Closure() {
  7127. function rotr(x, n) {
  7128. return (x >>> n) | (x << 32 - n);
  7129. }
  7130. function ch(x, y, z) {
  7131. return (x & y) ^ (~x & z);
  7132. }
  7133. function maj(x, y, z) {
  7134. return (x & y) ^ (x & z) ^ (y & z);
  7135. }
  7136. function sigma(x) {
  7137. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7138. }
  7139. function sigmaPrime(x) {
  7140. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7141. }
  7142. function littleSigma(x) {
  7143. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7144. }
  7145. function littleSigmaPrime(x) {
  7146. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7147. }
  7148. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7149. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7150. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7151. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7152. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7153. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7154. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7155. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7156. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7157. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7158. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7159. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7160. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7161. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7162. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7163. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7164. function hash(data, offset, length) {
  7165. // initial hash values
  7166. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7167. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7168. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7169. // pre-processing
  7170. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7171. var padded = new Uint8Array(paddedLength);
  7172. var i, j, n;
  7173. for (i = 0; i < length; ++i) {
  7174. padded[i] = data[offset++];
  7175. }
  7176. padded[i++] = 0x80;
  7177. n = paddedLength - 8;
  7178. while (i < n) {
  7179. padded[i++] = 0;
  7180. }
  7181. padded[i++] = 0;
  7182. padded[i++] = 0;
  7183. padded[i++] = 0;
  7184. padded[i++] = (length >>> 29) & 0xFF;
  7185. padded[i++] = (length >> 21) & 0xFF;
  7186. padded[i++] = (length >> 13) & 0xFF;
  7187. padded[i++] = (length >> 5) & 0xFF;
  7188. padded[i++] = (length << 3) & 0xFF;
  7189. var w = new Uint32Array(64);
  7190. // for each 512 bit block
  7191. for (i = 0; i < paddedLength;) {
  7192. for (j = 0; j < 16; ++j) {
  7193. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7194. (padded[i + 2] << 8) | (padded[i + 3]));
  7195. i += 4;
  7196. }
  7197. for (j = 16; j < 64; ++j) {
  7198. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7199. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7200. }
  7201. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7202. f = h5, g = h6, h = h7, t1, t2;
  7203. for (j = 0; j < 64; ++j) {
  7204. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7205. t2 = sigma(a) + maj(a, b, c);
  7206. h = g;
  7207. g = f;
  7208. f = e;
  7209. e = (d + t1) | 0;
  7210. d = c;
  7211. c = b;
  7212. b = a;
  7213. a = (t1 + t2) | 0;
  7214. }
  7215. h0 = (h0 + a) | 0;
  7216. h1 = (h1 + b) | 0;
  7217. h2 = (h2 + c) | 0;
  7218. h3 = (h3 + d) | 0;
  7219. h4 = (h4 + e) | 0;
  7220. h5 = (h5 + f) | 0;
  7221. h6 = (h6 + g) | 0;
  7222. h7 = (h7 + h) | 0;
  7223. }
  7224. return new Uint8Array([
  7225. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7226. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7227. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7228. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7229. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7230. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7231. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7232. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7233. ]);
  7234. }
  7235. return hash;
  7236. })();
  7237. var calculateSHA512 = (function calculateSHA512Closure() {
  7238. function ch(result, x, y, z, tmp) {
  7239. result.assign(x);
  7240. result.and(y);
  7241. tmp.assign(x);
  7242. tmp.not();
  7243. tmp.and(z);
  7244. result.xor(tmp);
  7245. }
  7246. function maj(result, x, y, z, tmp) {
  7247. result.assign(x);
  7248. result.and(y);
  7249. tmp.assign(x);
  7250. tmp.and(z);
  7251. result.xor(tmp);
  7252. tmp.assign(y);
  7253. tmp.and(z);
  7254. result.xor(tmp);
  7255. }
  7256. function sigma(result, x, tmp) {
  7257. result.assign(x);
  7258. result.rotateRight(28);
  7259. tmp.assign(x);
  7260. tmp.rotateRight(34);
  7261. result.xor(tmp);
  7262. tmp.assign(x);
  7263. tmp.rotateRight(39);
  7264. result.xor(tmp);
  7265. }
  7266. function sigmaPrime(result, x, tmp) {
  7267. result.assign(x);
  7268. result.rotateRight(14);
  7269. tmp.assign(x);
  7270. tmp.rotateRight(18);
  7271. result.xor(tmp);
  7272. tmp.assign(x);
  7273. tmp.rotateRight(41);
  7274. result.xor(tmp);
  7275. }
  7276. function littleSigma(result, x, tmp) {
  7277. result.assign(x);
  7278. result.rotateRight(1);
  7279. tmp.assign(x);
  7280. tmp.rotateRight(8);
  7281. result.xor(tmp);
  7282. tmp.assign(x);
  7283. tmp.shiftRight(7);
  7284. result.xor(tmp);
  7285. }
  7286. function littleSigmaPrime(result, x, tmp) {
  7287. result.assign(x);
  7288. result.rotateRight(19);
  7289. tmp.assign(x);
  7290. tmp.rotateRight(61);
  7291. result.xor(tmp);
  7292. tmp.assign(x);
  7293. tmp.shiftRight(6);
  7294. result.xor(tmp);
  7295. }
  7296. var k = [
  7297. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7298. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7299. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7300. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7301. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7302. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7303. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7304. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7305. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7306. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7307. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7308. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7309. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7310. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7311. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7312. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7313. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7314. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7315. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7316. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7317. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7318. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7319. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7320. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7321. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7322. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7323. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7324. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7325. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7326. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7327. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7328. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7329. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7330. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7331. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7332. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7333. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7334. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7335. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7336. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7337. function hash(data, offset, length, mode384) {
  7338. mode384 = !!mode384;
  7339. // initial hash values
  7340. var h0, h1, h2, h3, h4, h5, h6, h7;
  7341. if (!mode384) {
  7342. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7343. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7344. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7345. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7346. h4 = new Word64(0x510e527f, 0xade682d1);
  7347. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7348. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7349. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7350. }
  7351. else {
  7352. // SHA384 is exactly the same
  7353. // except with different starting values and a trimmed result
  7354. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7355. h1 = new Word64(0x629a292a, 0x367cd507);
  7356. h2 = new Word64(0x9159015a, 0x3070dd17);
  7357. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7358. h4 = new Word64(0x67332667, 0xffc00b31);
  7359. h5 = new Word64(0x8eb44a87, 0x68581511);
  7360. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7361. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7362. }
  7363. // pre-processing
  7364. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7365. var padded = new Uint8Array(paddedLength);
  7366. var i, j, n;
  7367. for (i = 0; i < length; ++i) {
  7368. padded[i] = data[offset++];
  7369. }
  7370. padded[i++] = 0x80;
  7371. n = paddedLength - 16;
  7372. while (i < n) {
  7373. padded[i++] = 0;
  7374. }
  7375. padded[i++] = 0;
  7376. padded[i++] = 0;
  7377. padded[i++] = 0;
  7378. padded[i++] = 0;
  7379. padded[i++] = 0;
  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++] = (length >>> 29) & 0xFF;
  7387. padded[i++] = (length >> 21) & 0xFF;
  7388. padded[i++] = (length >> 13) & 0xFF;
  7389. padded[i++] = (length >> 5) & 0xFF;
  7390. padded[i++] = (length << 3) & 0xFF;
  7391. var w = new Array(80);
  7392. for (i = 0; i < 80; i++) {
  7393. w[i] = new Word64(0, 0);
  7394. }
  7395. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7396. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7397. var g = new Word64(0, 0), h = new Word64(0, 0);
  7398. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7399. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7400. // for each 1024 bit block
  7401. for (i = 0; i < paddedLength;) {
  7402. for (j = 0; j < 16; ++j) {
  7403. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7404. (padded[i + 2] << 8) | (padded[i + 3]);
  7405. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7406. (padded[i + 6]) << 8 | (padded[i + 7]);
  7407. i += 8;
  7408. }
  7409. for (j = 16; j < 80; ++j) {
  7410. tmp3 = w[j];
  7411. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7412. tmp3.add(w[j - 7]);
  7413. littleSigma(tmp1, w[j - 15], tmp2);
  7414. tmp3.add(tmp1);
  7415. tmp3.add(w[j - 16]);
  7416. }
  7417. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7418. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7419. for (j = 0; j < 80; ++j) {
  7420. t1.assign(h);
  7421. sigmaPrime(tmp1, e, tmp2);
  7422. t1.add(tmp1);
  7423. ch(tmp1, e, f, g, tmp2);
  7424. t1.add(tmp1);
  7425. t1.add(k[j]);
  7426. t1.add(w[j]);
  7427. sigma(t2, a, tmp2);
  7428. maj(tmp1, a, b, c, tmp2);
  7429. t2.add(tmp1);
  7430. tmp3 = h;
  7431. h = g;
  7432. g = f;
  7433. f = e;
  7434. d.add(t1);
  7435. e = d;
  7436. d = c;
  7437. c = b;
  7438. b = a;
  7439. tmp3.assign(t1);
  7440. tmp3.add(t2);
  7441. a = tmp3;
  7442. }
  7443. h0.add(a);
  7444. h1.add(b);
  7445. h2.add(c);
  7446. h3.add(d);
  7447. h4.add(e);
  7448. h5.add(f);
  7449. h6.add(g);
  7450. h7.add(h);
  7451. }
  7452. var result;
  7453. if (!mode384) {
  7454. result = new Uint8Array(64);
  7455. h0.copyTo(result,0);
  7456. h1.copyTo(result,8);
  7457. h2.copyTo(result,16);
  7458. h3.copyTo(result,24);
  7459. h4.copyTo(result,32);
  7460. h5.copyTo(result,40);
  7461. h6.copyTo(result,48);
  7462. h7.copyTo(result,56);
  7463. }
  7464. else {
  7465. result = new Uint8Array(48);
  7466. h0.copyTo(result,0);
  7467. h1.copyTo(result,8);
  7468. h2.copyTo(result,16);
  7469. h3.copyTo(result,24);
  7470. h4.copyTo(result,32);
  7471. h5.copyTo(result,40);
  7472. }
  7473. return result;
  7474. }
  7475. return hash;
  7476. })();
  7477. var calculateSHA384 = (function calculateSHA384Closure() {
  7478. function hash(data, offset, length) {
  7479. return calculateSHA512(data, offset, length, true);
  7480. }
  7481. return hash;
  7482. })();
  7483. var NullCipher = (function NullCipherClosure() {
  7484. function NullCipher() {
  7485. }
  7486. NullCipher.prototype = {
  7487. decryptBlock: function NullCipher_decryptBlock(data) {
  7488. return data;
  7489. }
  7490. };
  7491. return NullCipher;
  7492. })();
  7493. var AES128Cipher = (function AES128CipherClosure() {
  7494. var rcon = new Uint8Array([
  7495. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7496. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7497. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7498. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7499. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7500. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7501. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7502. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7503. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7504. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7505. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7506. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7507. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7508. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7509. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7510. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7511. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7512. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7513. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7514. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7515. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7516. 0x74, 0xe8, 0xcb, 0x8d]);
  7517. var s = new Uint8Array([
  7518. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7519. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7520. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7521. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7522. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7523. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7524. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7525. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7526. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7527. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7528. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7529. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7530. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7531. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7532. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7533. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7534. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7535. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7536. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7537. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7538. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7539. 0xb0, 0x54, 0xbb, 0x16]);
  7540. var inv_s = new Uint8Array([
  7541. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7542. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7543. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7544. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7545. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7546. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7547. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7548. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7549. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7550. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7551. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7552. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7553. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7554. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7555. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7556. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7557. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7558. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7559. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7560. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7561. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7562. 0x55, 0x21, 0x0c, 0x7d]);
  7563. var mixCol = new Uint8Array(256);
  7564. for (var i = 0; i < 256; i++) {
  7565. if (i < 128) {
  7566. mixCol[i] = i << 1;
  7567. } else {
  7568. mixCol[i] = (i << 1) ^ 0x1b;
  7569. }
  7570. }
  7571. var mix = new Uint32Array([
  7572. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7573. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7574. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7575. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7576. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7577. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7578. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7579. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7580. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7581. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7582. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7583. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7584. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7585. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7586. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7587. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7588. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7589. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7590. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7591. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7592. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7593. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7594. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7595. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7596. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7597. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7598. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7599. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7600. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7601. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7602. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7603. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7604. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7605. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7606. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7607. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7608. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7609. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7610. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7611. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7612. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7613. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7614. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7615. function expandKey128(cipherKey) {
  7616. var b = 176, result = new Uint8Array(b);
  7617. result.set(cipherKey);
  7618. for (var j = 16, i = 1; j < b; ++i) {
  7619. // RotWord
  7620. var t1 = result[j - 3], t2 = result[j - 2],
  7621. t3 = result[j - 1], t4 = result[j - 4];
  7622. // SubWord
  7623. t1 = s[t1];
  7624. t2 = s[t2];
  7625. t3 = s[t3];
  7626. t4 = s[t4];
  7627. // Rcon
  7628. t1 = t1 ^ rcon[i];
  7629. for (var n = 0; n < 4; ++n) {
  7630. result[j] = (t1 ^= result[j - 16]);
  7631. j++;
  7632. result[j] = (t2 ^= result[j - 16]);
  7633. j++;
  7634. result[j] = (t3 ^= result[j - 16]);
  7635. j++;
  7636. result[j] = (t4 ^= result[j - 16]);
  7637. j++;
  7638. }
  7639. }
  7640. return result;
  7641. }
  7642. function decrypt128(input, key) {
  7643. var state = new Uint8Array(16);
  7644. state.set(input);
  7645. var i, j, k;
  7646. var t, u, v;
  7647. // AddRoundKey
  7648. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7649. state[j] ^= key[k];
  7650. }
  7651. for (i = 9; i >= 1; --i) {
  7652. // InvShiftRows
  7653. t = state[13];
  7654. state[13] = state[9];
  7655. state[9] = state[5];
  7656. state[5] = state[1];
  7657. state[1] = t;
  7658. t = state[14];
  7659. u = state[10];
  7660. state[14] = state[6];
  7661. state[10] = state[2];
  7662. state[6] = t;
  7663. state[2] = u;
  7664. t = state[15];
  7665. u = state[11];
  7666. v = state[7];
  7667. state[15] = state[3];
  7668. state[11] = t;
  7669. state[7] = u;
  7670. state[3] = v;
  7671. // InvSubBytes
  7672. for (j = 0; j < 16; ++j) {
  7673. state[j] = inv_s[state[j]];
  7674. }
  7675. // AddRoundKey
  7676. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7677. state[j] ^= key[k];
  7678. }
  7679. // InvMixColumns
  7680. for (j = 0; j < 16; j += 4) {
  7681. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7682. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7683. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7684. (s3 >>> 24) ^ (s3 << 8));
  7685. state[j] = (t >>> 24) & 0xFF;
  7686. state[j + 1] = (t >> 16) & 0xFF;
  7687. state[j + 2] = (t >> 8) & 0xFF;
  7688. state[j + 3] = t & 0xFF;
  7689. }
  7690. }
  7691. // InvShiftRows
  7692. t = state[13];
  7693. state[13] = state[9];
  7694. state[9] = state[5];
  7695. state[5] = state[1];
  7696. state[1] = t;
  7697. t = state[14];
  7698. u = state[10];
  7699. state[14] = state[6];
  7700. state[10] = state[2];
  7701. state[6] = t;
  7702. state[2] = u;
  7703. t = state[15];
  7704. u = state[11];
  7705. v = state[7];
  7706. state[15] = state[3];
  7707. state[11] = t;
  7708. state[7] = u;
  7709. state[3] = v;
  7710. for (j = 0; j < 16; ++j) {
  7711. // InvSubBytes
  7712. state[j] = inv_s[state[j]];
  7713. // AddRoundKey
  7714. state[j] ^= key[j];
  7715. }
  7716. return state;
  7717. }
  7718. function encrypt128(input, key) {
  7719. var t, u, v, k;
  7720. var state = new Uint8Array(16);
  7721. state.set(input);
  7722. for (j = 0; j < 16; ++j) {
  7723. // AddRoundKey
  7724. state[j] ^= key[j];
  7725. }
  7726. for (i = 1; i < 10; i++) {
  7727. //SubBytes
  7728. for (j = 0; j < 16; ++j) {
  7729. state[j] = s[state[j]];
  7730. }
  7731. //ShiftRows
  7732. v = state[1];
  7733. state[1] = state[5];
  7734. state[5] = state[9];
  7735. state[9] = state[13];
  7736. state[13] = v;
  7737. v = state[2];
  7738. u = state[6];
  7739. state[2] = state[10];
  7740. state[6] = state[14];
  7741. state[10] = v;
  7742. state[14] = u;
  7743. v = state[3];
  7744. u = state[7];
  7745. t = state[11];
  7746. state[3] = state[15];
  7747. state[7] = v;
  7748. state[11] = u;
  7749. state[15] = t;
  7750. //MixColumns
  7751. for (var j = 0; j < 16; j += 4) {
  7752. var s0 = state[j + 0], s1 = state[j + 1];
  7753. var s2 = state[j + 2], s3 = state[j + 3];
  7754. t = s0 ^ s1 ^ s2 ^ s3;
  7755. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7756. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7757. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7758. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7759. }
  7760. //AddRoundKey
  7761. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7762. state[j] ^= key[k];
  7763. }
  7764. }
  7765. //SubBytes
  7766. for (j = 0; j < 16; ++j) {
  7767. state[j] = s[state[j]];
  7768. }
  7769. //ShiftRows
  7770. v = state[1];
  7771. state[1] = state[5];
  7772. state[5] = state[9];
  7773. state[9] = state[13];
  7774. state[13] = v;
  7775. v = state[2];
  7776. u = state[6];
  7777. state[2] = state[10];
  7778. state[6] = state[14];
  7779. state[10] = v;
  7780. state[14] = u;
  7781. v = state[3];
  7782. u = state[7];
  7783. t = state[11];
  7784. state[3] = state[15];
  7785. state[7] = v;
  7786. state[11] = u;
  7787. state[15] = t;
  7788. //AddRoundKey
  7789. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7790. state[j] ^= key[k];
  7791. }
  7792. return state;
  7793. }
  7794. function AES128Cipher(key) {
  7795. this.key = expandKey128(key);
  7796. this.buffer = new Uint8Array(16);
  7797. this.bufferPosition = 0;
  7798. }
  7799. function decryptBlock2(data, finalize) {
  7800. var i, j, ii, sourceLength = data.length,
  7801. buffer = this.buffer, bufferLength = this.bufferPosition,
  7802. result = [], iv = this.iv;
  7803. for (i = 0; i < sourceLength; ++i) {
  7804. buffer[bufferLength] = data[i];
  7805. ++bufferLength;
  7806. if (bufferLength < 16) {
  7807. continue;
  7808. }
  7809. // buffer is full, decrypting
  7810. var plain = decrypt128(buffer, this.key);
  7811. // xor-ing the IV vector to get plain text
  7812. for (j = 0; j < 16; ++j) {
  7813. plain[j] ^= iv[j];
  7814. }
  7815. iv = buffer;
  7816. result.push(plain);
  7817. buffer = new Uint8Array(16);
  7818. bufferLength = 0;
  7819. }
  7820. // saving incomplete buffer
  7821. this.buffer = buffer;
  7822. this.bufferLength = bufferLength;
  7823. this.iv = iv;
  7824. if (result.length === 0) {
  7825. return new Uint8Array([]);
  7826. }
  7827. // combining plain text blocks into one
  7828. var outputLength = 16 * result.length;
  7829. if (finalize) {
  7830. // undo a padding that is described in RFC 2898
  7831. var lastBlock = result[result.length - 1];
  7832. var psLen = lastBlock[15];
  7833. if (psLen <= 16) {
  7834. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7835. if (lastBlock[i] !== psLen) {
  7836. // Invalid padding, assume that the block has no padding.
  7837. psLen = 0;
  7838. break;
  7839. }
  7840. }
  7841. outputLength -= psLen;
  7842. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7843. }
  7844. }
  7845. var output = new Uint8Array(outputLength);
  7846. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7847. output.set(result[i], j);
  7848. }
  7849. return output;
  7850. }
  7851. AES128Cipher.prototype = {
  7852. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7853. var i, sourceLength = data.length;
  7854. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7855. // waiting for IV values -- they are at the start of the stream
  7856. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7857. buffer[bufferLength] = data[i];
  7858. }
  7859. if (bufferLength < 16) {
  7860. // need more data
  7861. this.bufferLength = bufferLength;
  7862. return new Uint8Array([]);
  7863. }
  7864. this.iv = buffer;
  7865. this.buffer = new Uint8Array(16);
  7866. this.bufferLength = 0;
  7867. // starting decryption
  7868. this.decryptBlock = decryptBlock2;
  7869. return this.decryptBlock(data.subarray(16), finalize);
  7870. },
  7871. encrypt: function AES128Cipher_encrypt(data, iv) {
  7872. var i, j, ii, sourceLength = data.length,
  7873. buffer = this.buffer, bufferLength = this.bufferPosition,
  7874. result = [];
  7875. if (!iv) {
  7876. iv = new Uint8Array(16);
  7877. }
  7878. for (i = 0; i < sourceLength; ++i) {
  7879. buffer[bufferLength] = data[i];
  7880. ++bufferLength;
  7881. if (bufferLength < 16) {
  7882. continue;
  7883. }
  7884. for (j = 0; j < 16; ++j) {
  7885. buffer[j] ^= iv[j];
  7886. }
  7887. // buffer is full, encrypting
  7888. var cipher = encrypt128(buffer, this.key);
  7889. iv = cipher;
  7890. result.push(cipher);
  7891. buffer = new Uint8Array(16);
  7892. bufferLength = 0;
  7893. }
  7894. // saving incomplete buffer
  7895. this.buffer = buffer;
  7896. this.bufferLength = bufferLength;
  7897. this.iv = iv;
  7898. if (result.length === 0) {
  7899. return new Uint8Array([]);
  7900. }
  7901. // combining plain text blocks into one
  7902. var outputLength = 16 * result.length;
  7903. var output = new Uint8Array(outputLength);
  7904. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7905. output.set(result[i], j);
  7906. }
  7907. return output;
  7908. }
  7909. };
  7910. return AES128Cipher;
  7911. })();
  7912. var AES256Cipher = (function AES256CipherClosure() {
  7913. var rcon = new Uint8Array([
  7914. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7915. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7916. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7917. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7918. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7919. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7920. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7921. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7922. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7923. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7924. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7925. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7926. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7927. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7928. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7929. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7930. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7931. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7932. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7933. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7934. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7935. 0x74, 0xe8, 0xcb, 0x8d]);
  7936. var s = new Uint8Array([
  7937. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7938. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7939. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7940. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7941. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7942. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7943. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7944. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7945. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7946. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7947. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7948. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7949. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7950. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7951. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7952. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7953. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7954. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7955. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7956. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7957. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7958. 0xb0, 0x54, 0xbb, 0x16]);
  7959. var inv_s = new Uint8Array([
  7960. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7961. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7962. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7963. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7964. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7965. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7966. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7967. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7968. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7969. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7970. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7971. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7972. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7973. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7974. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7975. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7976. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7977. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7978. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7979. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7980. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7981. 0x55, 0x21, 0x0c, 0x7d]);
  7982. var mixCol = new Uint8Array(256);
  7983. for (var i = 0; i < 256; i++) {
  7984. if (i < 128) {
  7985. mixCol[i] = i << 1;
  7986. } else {
  7987. mixCol[i] = (i << 1) ^ 0x1b;
  7988. }
  7989. }
  7990. var mix = new Uint32Array([
  7991. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7992. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7993. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7994. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7995. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7996. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7997. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7998. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7999. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8000. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8001. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8002. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8003. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8004. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8005. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8006. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8007. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8008. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8009. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8010. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8011. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8012. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8013. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8014. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8015. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8016. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8017. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8018. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8019. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8020. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8021. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8022. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8023. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8024. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8025. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8026. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8027. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8028. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8029. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8030. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8031. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8032. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8033. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8034. function expandKey256(cipherKey) {
  8035. var b = 240, result = new Uint8Array(b);
  8036. var r = 1;
  8037. result.set(cipherKey);
  8038. for (var j = 32, i = 1; j < b; ++i) {
  8039. if (j % 32 === 16) {
  8040. t1 = s[t1];
  8041. t2 = s[t2];
  8042. t3 = s[t3];
  8043. t4 = s[t4];
  8044. } else if (j % 32 === 0) {
  8045. // RotWord
  8046. var t1 = result[j - 3], t2 = result[j - 2],
  8047. t3 = result[j - 1], t4 = result[j - 4];
  8048. // SubWord
  8049. t1 = s[t1];
  8050. t2 = s[t2];
  8051. t3 = s[t3];
  8052. t4 = s[t4];
  8053. // Rcon
  8054. t1 = t1 ^ r;
  8055. if ((r <<= 1) >= 256) {
  8056. r = (r ^ 0x1b) & 0xFF;
  8057. }
  8058. }
  8059. for (var n = 0; n < 4; ++n) {
  8060. result[j] = (t1 ^= result[j - 32]);
  8061. j++;
  8062. result[j] = (t2 ^= result[j - 32]);
  8063. j++;
  8064. result[j] = (t3 ^= result[j - 32]);
  8065. j++;
  8066. result[j] = (t4 ^= result[j - 32]);
  8067. j++;
  8068. }
  8069. }
  8070. return result;
  8071. }
  8072. function decrypt256(input, key) {
  8073. var state = new Uint8Array(16);
  8074. state.set(input);
  8075. var i, j, k;
  8076. var t, u, v;
  8077. // AddRoundKey
  8078. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8079. state[j] ^= key[k];
  8080. }
  8081. for (i = 13; i >= 1; --i) {
  8082. // InvShiftRows
  8083. t = state[13];
  8084. state[13] = state[9];
  8085. state[9] = state[5];
  8086. state[5] = state[1];
  8087. state[1] = t;
  8088. t = state[14];
  8089. u = state[10];
  8090. state[14] = state[6];
  8091. state[10] = state[2];
  8092. state[6] = t;
  8093. state[2] = u;
  8094. t = state[15];
  8095. u = state[11];
  8096. v = state[7];
  8097. state[15] = state[3];
  8098. state[11] = t;
  8099. state[7] = u;
  8100. state[3] = v;
  8101. // InvSubBytes
  8102. for (j = 0; j < 16; ++j) {
  8103. state[j] = inv_s[state[j]];
  8104. }
  8105. // AddRoundKey
  8106. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8107. state[j] ^= key[k];
  8108. }
  8109. // InvMixColumns
  8110. for (j = 0; j < 16; j += 4) {
  8111. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8112. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8113. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8114. (s3 >>> 24) ^ (s3 << 8));
  8115. state[j] = (t >>> 24) & 0xFF;
  8116. state[j + 1] = (t >> 16) & 0xFF;
  8117. state[j + 2] = (t >> 8) & 0xFF;
  8118. state[j + 3] = t & 0xFF;
  8119. }
  8120. }
  8121. // InvShiftRows
  8122. t = state[13];
  8123. state[13] = state[9];
  8124. state[9] = state[5];
  8125. state[5] = state[1];
  8126. state[1] = t;
  8127. t = state[14];
  8128. u = state[10];
  8129. state[14] = state[6];
  8130. state[10] = state[2];
  8131. state[6] = t;
  8132. state[2] = u;
  8133. t = state[15];
  8134. u = state[11];
  8135. v = state[7];
  8136. state[15] = state[3];
  8137. state[11] = t;
  8138. state[7] = u;
  8139. state[3] = v;
  8140. for (j = 0; j < 16; ++j) {
  8141. // InvSubBytes
  8142. state[j] = inv_s[state[j]];
  8143. // AddRoundKey
  8144. state[j] ^= key[j];
  8145. }
  8146. return state;
  8147. }
  8148. function encrypt256(input, key) {
  8149. var t, u, v, k;
  8150. var state = new Uint8Array(16);
  8151. state.set(input);
  8152. for (j = 0; j < 16; ++j) {
  8153. // AddRoundKey
  8154. state[j] ^= key[j];
  8155. }
  8156. for (i = 1; i < 14; i++) {
  8157. //SubBytes
  8158. for (j = 0; j < 16; ++j) {
  8159. state[j] = s[state[j]];
  8160. }
  8161. //ShiftRows
  8162. v = state[1];
  8163. state[1] = state[5];
  8164. state[5] = state[9];
  8165. state[9] = state[13];
  8166. state[13] = v;
  8167. v = state[2];
  8168. u = state[6];
  8169. state[2] = state[10];
  8170. state[6] = state[14];
  8171. state[10] = v;
  8172. state[14] = u;
  8173. v = state[3];
  8174. u = state[7];
  8175. t = state[11];
  8176. state[3] = state[15];
  8177. state[7] = v;
  8178. state[11] = u;
  8179. state[15] = t;
  8180. //MixColumns
  8181. for (var j = 0; j < 16; j += 4) {
  8182. var s0 = state[j + 0], s1 = state[j + 1];
  8183. var s2 = state[j + 2], s3 = state[j + 3];
  8184. t = s0 ^ s1 ^ s2 ^ s3;
  8185. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8186. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8187. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8188. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8189. }
  8190. //AddRoundKey
  8191. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8192. state[j] ^= key[k];
  8193. }
  8194. }
  8195. //SubBytes
  8196. for (j = 0; j < 16; ++j) {
  8197. state[j] = s[state[j]];
  8198. }
  8199. //ShiftRows
  8200. v = state[1];
  8201. state[1] = state[5];
  8202. state[5] = state[9];
  8203. state[9] = state[13];
  8204. state[13] = v;
  8205. v = state[2];
  8206. u = state[6];
  8207. state[2] = state[10];
  8208. state[6] = state[14];
  8209. state[10] = v;
  8210. state[14] = u;
  8211. v = state[3];
  8212. u = state[7];
  8213. t = state[11];
  8214. state[3] = state[15];
  8215. state[7] = v;
  8216. state[11] = u;
  8217. state[15] = t;
  8218. //AddRoundKey
  8219. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8220. state[j] ^= key[k];
  8221. }
  8222. return state;
  8223. }
  8224. function AES256Cipher(key) {
  8225. this.key = expandKey256(key);
  8226. this.buffer = new Uint8Array(16);
  8227. this.bufferPosition = 0;
  8228. }
  8229. function decryptBlock2(data, finalize) {
  8230. var i, j, ii, sourceLength = data.length,
  8231. buffer = this.buffer, bufferLength = this.bufferPosition,
  8232. result = [], iv = this.iv;
  8233. for (i = 0; i < sourceLength; ++i) {
  8234. buffer[bufferLength] = data[i];
  8235. ++bufferLength;
  8236. if (bufferLength < 16) {
  8237. continue;
  8238. }
  8239. // buffer is full, decrypting
  8240. var plain = decrypt256(buffer, this.key);
  8241. // xor-ing the IV vector to get plain text
  8242. for (j = 0; j < 16; ++j) {
  8243. plain[j] ^= iv[j];
  8244. }
  8245. iv = buffer;
  8246. result.push(plain);
  8247. buffer = new Uint8Array(16);
  8248. bufferLength = 0;
  8249. }
  8250. // saving incomplete buffer
  8251. this.buffer = buffer;
  8252. this.bufferLength = bufferLength;
  8253. this.iv = iv;
  8254. if (result.length === 0) {
  8255. return new Uint8Array([]);
  8256. }
  8257. // combining plain text blocks into one
  8258. var outputLength = 16 * result.length;
  8259. if (finalize) {
  8260. // undo a padding that is described in RFC 2898
  8261. var lastBlock = result[result.length - 1];
  8262. var psLen = lastBlock[15];
  8263. if (psLen <= 16) {
  8264. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8265. if (lastBlock[i] !== psLen) {
  8266. // Invalid padding, assume that the block has no padding.
  8267. psLen = 0;
  8268. break;
  8269. }
  8270. }
  8271. outputLength -= psLen;
  8272. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8273. }
  8274. }
  8275. var output = new Uint8Array(outputLength);
  8276. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8277. output.set(result[i], j);
  8278. }
  8279. return output;
  8280. }
  8281. AES256Cipher.prototype = {
  8282. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8283. var i, sourceLength = data.length;
  8284. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8285. // if not supplied an IV wait for IV values
  8286. // they are at the start of the stream
  8287. if (iv) {
  8288. this.iv = iv;
  8289. } else {
  8290. for (i = 0; bufferLength < 16 &&
  8291. i < sourceLength; ++i, ++bufferLength) {
  8292. buffer[bufferLength] = data[i];
  8293. }
  8294. if (bufferLength < 16) {
  8295. //need more data
  8296. this.bufferLength = bufferLength;
  8297. return new Uint8Array([]);
  8298. }
  8299. this.iv = buffer;
  8300. data = data.subarray(16);
  8301. }
  8302. this.buffer = new Uint8Array(16);
  8303. this.bufferLength = 0;
  8304. // starting decryption
  8305. this.decryptBlock = decryptBlock2;
  8306. return this.decryptBlock(data, finalize);
  8307. },
  8308. encrypt: function AES256Cipher_encrypt(data, iv) {
  8309. var i, j, ii, sourceLength = data.length,
  8310. buffer = this.buffer, bufferLength = this.bufferPosition,
  8311. result = [];
  8312. if (!iv) {
  8313. iv = new Uint8Array(16);
  8314. }
  8315. for (i = 0; i < sourceLength; ++i) {
  8316. buffer[bufferLength] = data[i];
  8317. ++bufferLength;
  8318. if (bufferLength < 16) {
  8319. continue;
  8320. }
  8321. for (j = 0; j < 16; ++j) {
  8322. buffer[j] ^= iv[j];
  8323. }
  8324. // buffer is full, encrypting
  8325. var cipher = encrypt256(buffer, this.key);
  8326. this.iv = cipher;
  8327. result.push(cipher);
  8328. buffer = new Uint8Array(16);
  8329. bufferLength = 0;
  8330. }
  8331. // saving incomplete buffer
  8332. this.buffer = buffer;
  8333. this.bufferLength = bufferLength;
  8334. this.iv = iv;
  8335. if (result.length === 0) {
  8336. return new Uint8Array([]);
  8337. }
  8338. // combining plain text blocks into one
  8339. var outputLength = 16 * result.length;
  8340. var output = new Uint8Array(outputLength);
  8341. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8342. output.set(result[i], j);
  8343. }
  8344. return output;
  8345. }
  8346. };
  8347. return AES256Cipher;
  8348. })();
  8349. var PDF17 = (function PDF17Closure() {
  8350. function compareByteArrays(array1, array2) {
  8351. if (array1.length !== array2.length) {
  8352. return false;
  8353. }
  8354. for (var i = 0; i < array1.length; i++) {
  8355. if (array1[i] !== array2[i]) {
  8356. return false;
  8357. }
  8358. }
  8359. return true;
  8360. }
  8361. function PDF17() {
  8362. }
  8363. PDF17.prototype = {
  8364. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8365. ownerValidationSalt,
  8366. userBytes,
  8367. ownerPassword) {
  8368. var hashData = new Uint8Array(password.length + 56);
  8369. hashData.set(password, 0);
  8370. hashData.set(ownerValidationSalt, password.length);
  8371. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8372. var result = calculateSHA256(hashData, 0, hashData.length);
  8373. return compareByteArrays(result, ownerPassword);
  8374. },
  8375. checkUserPassword: function PDF17_checkUserPassword(password,
  8376. userValidationSalt,
  8377. userPassword) {
  8378. var hashData = new Uint8Array(password.length + 8);
  8379. hashData.set(password, 0);
  8380. hashData.set(userValidationSalt, password.length);
  8381. var result = calculateSHA256(hashData, 0, hashData.length);
  8382. return compareByteArrays(result, userPassword);
  8383. },
  8384. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8385. ownerEncryption) {
  8386. var hashData = new Uint8Array(password.length + 56);
  8387. hashData.set(password, 0);
  8388. hashData.set(ownerKeySalt, password.length);
  8389. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8390. var key = calculateSHA256(hashData, 0, hashData.length);
  8391. var cipher = new AES256Cipher(key);
  8392. return cipher.decryptBlock(ownerEncryption,
  8393. false,
  8394. new Uint8Array(16));
  8395. },
  8396. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8397. userEncryption) {
  8398. var hashData = new Uint8Array(password.length + 8);
  8399. hashData.set(password, 0);
  8400. hashData.set(userKeySalt, password.length);
  8401. //key is the decryption key for the UE string
  8402. var key = calculateSHA256(hashData, 0, hashData.length);
  8403. var cipher = new AES256Cipher(key);
  8404. return cipher.decryptBlock(userEncryption,
  8405. false,
  8406. new Uint8Array(16));
  8407. }
  8408. };
  8409. return PDF17;
  8410. })();
  8411. var PDF20 = (function PDF20Closure() {
  8412. function concatArrays(array1, array2) {
  8413. var t = new Uint8Array(array1.length + array2.length);
  8414. t.set(array1, 0);
  8415. t.set(array2, array1.length);
  8416. return t;
  8417. }
  8418. function calculatePDF20Hash(password, input, userBytes) {
  8419. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8420. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8421. var e = [0];
  8422. var i = 0;
  8423. while (i < 64 || e[e.length - 1] > i - 32) {
  8424. var arrayLength = password.length + k.length + userBytes.length;
  8425. var k1 = new Uint8Array(arrayLength * 64);
  8426. var array = concatArrays(password, k);
  8427. array = concatArrays(array, userBytes);
  8428. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8429. k1.set(array, pos);
  8430. }
  8431. //AES128 CBC NO PADDING with
  8432. //first 16 bytes of k as the key and the second 16 as the iv.
  8433. var cipher = new AES128Cipher(k.subarray(0, 16));
  8434. e = cipher.encrypt(k1, k.subarray(16, 32));
  8435. //Now we have to take the first 16 bytes of an unsigned
  8436. //big endian integer... and compute the remainder
  8437. //modulo 3.... That is a fairly large number and
  8438. //JavaScript isn't going to handle that well...
  8439. //So we're using a trick that allows us to perform
  8440. //modulo math byte by byte
  8441. var remainder = 0;
  8442. for (var z = 0; z < 16; z++) {
  8443. remainder *= (256 % 3);
  8444. remainder %= 3;
  8445. remainder += ((e[z] >>> 0) % 3);
  8446. remainder %= 3;
  8447. }
  8448. if (remainder === 0) {
  8449. k = calculateSHA256(e, 0, e.length);
  8450. }
  8451. else if (remainder === 1) {
  8452. k = calculateSHA384(e, 0, e.length);
  8453. }
  8454. else if (remainder === 2) {
  8455. k = calculateSHA512(e, 0, e.length);
  8456. }
  8457. i++;
  8458. }
  8459. return k.subarray(0, 32);
  8460. }
  8461. function PDF20() {
  8462. }
  8463. function compareByteArrays(array1, array2) {
  8464. if (array1.length !== array2.length) {
  8465. return false;
  8466. }
  8467. for (var i = 0; i < array1.length; i++) {
  8468. if (array1[i] !== array2[i]) {
  8469. return false;
  8470. }
  8471. }
  8472. return true;
  8473. }
  8474. PDF20.prototype = {
  8475. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8476. return calculatePDF20Hash(password, concatBytes, userBytes);
  8477. },
  8478. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8479. ownerValidationSalt,
  8480. userBytes,
  8481. ownerPassword) {
  8482. var hashData = new Uint8Array(password.length + 56);
  8483. hashData.set(password, 0);
  8484. hashData.set(ownerValidationSalt, password.length);
  8485. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8486. var result = calculatePDF20Hash(password, hashData, userBytes);
  8487. return compareByteArrays(result, ownerPassword);
  8488. },
  8489. checkUserPassword: function PDF20_checkUserPassword(password,
  8490. userValidationSalt,
  8491. userPassword) {
  8492. var hashData = new Uint8Array(password.length + 8);
  8493. hashData.set(password, 0);
  8494. hashData.set(userValidationSalt, password.length);
  8495. var result = calculatePDF20Hash(password, hashData, []);
  8496. return compareByteArrays(result, userPassword);
  8497. },
  8498. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8499. ownerEncryption) {
  8500. var hashData = new Uint8Array(password.length + 56);
  8501. hashData.set(password, 0);
  8502. hashData.set(ownerKeySalt, password.length);
  8503. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8504. var key = calculatePDF20Hash(password, hashData, userBytes);
  8505. var cipher = new AES256Cipher(key);
  8506. return cipher.decryptBlock(ownerEncryption,
  8507. false,
  8508. new Uint8Array(16));
  8509. },
  8510. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8511. userEncryption) {
  8512. var hashData = new Uint8Array(password.length + 8);
  8513. hashData.set(password, 0);
  8514. hashData.set(userKeySalt, password.length);
  8515. //key is the decryption key for the UE string
  8516. var key = calculatePDF20Hash(password, hashData, []);
  8517. var cipher = new AES256Cipher(key);
  8518. return cipher.decryptBlock(userEncryption,
  8519. false,
  8520. new Uint8Array(16));
  8521. }
  8522. };
  8523. return PDF20;
  8524. })();
  8525. var CipherTransform = (function CipherTransformClosure() {
  8526. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8527. this.stringCipherConstructor = stringCipherConstructor;
  8528. this.streamCipherConstructor = streamCipherConstructor;
  8529. }
  8530. CipherTransform.prototype = {
  8531. createStream: function CipherTransform_createStream(stream, length) {
  8532. var cipher = new this.streamCipherConstructor();
  8533. return new DecryptStream(stream, length,
  8534. function cipherTransformDecryptStream(data, finalize) {
  8535. return cipher.decryptBlock(data, finalize);
  8536. }
  8537. );
  8538. },
  8539. decryptString: function CipherTransform_decryptString(s) {
  8540. var cipher = new this.stringCipherConstructor();
  8541. var data = stringToBytes(s);
  8542. data = cipher.decryptBlock(data, true);
  8543. return bytesToString(data);
  8544. }
  8545. };
  8546. return CipherTransform;
  8547. })();
  8548. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8549. var defaultPasswordBytes = new Uint8Array([
  8550. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8551. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8552. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8553. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8554. function createEncryptionKey20(revision, password, ownerPassword,
  8555. ownerValidationSalt, ownerKeySalt, uBytes,
  8556. userPassword, userValidationSalt, userKeySalt,
  8557. ownerEncryption, userEncryption, perms) {
  8558. if (password) {
  8559. var passwordLength = Math.min(127, password.length);
  8560. password = password.subarray(0, passwordLength);
  8561. } else {
  8562. password = [];
  8563. }
  8564. var pdfAlgorithm;
  8565. if (revision === 6) {
  8566. pdfAlgorithm = new PDF20();
  8567. } else {
  8568. pdfAlgorithm = new PDF17();
  8569. }
  8570. if (pdfAlgorithm) {
  8571. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8572. userPassword)) {
  8573. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8574. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8575. uBytes,
  8576. ownerPassword)) {
  8577. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8578. ownerEncryption);
  8579. }
  8580. }
  8581. return null;
  8582. }
  8583. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8584. flags, revision, keyLength, encryptMetadata) {
  8585. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8586. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8587. if (password) {
  8588. n = Math.min(32, password.length);
  8589. for (; i < n; ++i) {
  8590. hashData[i] = password[i];
  8591. }
  8592. }
  8593. j = 0;
  8594. while (i < 32) {
  8595. hashData[i++] = defaultPasswordBytes[j++];
  8596. }
  8597. // as now the padded password in the hashData[0..i]
  8598. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8599. hashData[i++] = ownerPassword[j];
  8600. }
  8601. hashData[i++] = flags & 0xFF;
  8602. hashData[i++] = (flags >> 8) & 0xFF;
  8603. hashData[i++] = (flags >> 16) & 0xFF;
  8604. hashData[i++] = (flags >>> 24) & 0xFF;
  8605. for (j = 0, n = fileId.length; j < n; ++j) {
  8606. hashData[i++] = fileId[j];
  8607. }
  8608. if (revision >= 4 && !encryptMetadata) {
  8609. hashData[i++] = 0xFF;
  8610. hashData[i++] = 0xFF;
  8611. hashData[i++] = 0xFF;
  8612. hashData[i++] = 0xFF;
  8613. }
  8614. var hash = calculateMD5(hashData, 0, i);
  8615. var keyLengthInBytes = keyLength >> 3;
  8616. if (revision >= 3) {
  8617. for (j = 0; j < 50; ++j) {
  8618. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8619. }
  8620. }
  8621. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8622. var cipher, checkData;
  8623. if (revision >= 3) {
  8624. for (i = 0; i < 32; ++i) {
  8625. hashData[i] = defaultPasswordBytes[i];
  8626. }
  8627. for (j = 0, n = fileId.length; j < n; ++j) {
  8628. hashData[i++] = fileId[j];
  8629. }
  8630. cipher = new ARCFourCipher(encryptionKey);
  8631. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8632. n = encryptionKey.length;
  8633. var derivedKey = new Uint8Array(n), k;
  8634. for (j = 1; j <= 19; ++j) {
  8635. for (k = 0; k < n; ++k) {
  8636. derivedKey[k] = encryptionKey[k] ^ j;
  8637. }
  8638. cipher = new ARCFourCipher(derivedKey);
  8639. checkData = cipher.encryptBlock(checkData);
  8640. }
  8641. for (j = 0, n = checkData.length; j < n; ++j) {
  8642. if (userPassword[j] !== checkData[j]) {
  8643. return null;
  8644. }
  8645. }
  8646. } else {
  8647. cipher = new ARCFourCipher(encryptionKey);
  8648. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8649. for (j = 0, n = checkData.length; j < n; ++j) {
  8650. if (userPassword[j] !== checkData[j]) {
  8651. return null;
  8652. }
  8653. }
  8654. }
  8655. return encryptionKey;
  8656. }
  8657. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8658. var hashData = new Uint8Array(32), i = 0, j, n;
  8659. n = Math.min(32, password.length);
  8660. for (; i < n; ++i) {
  8661. hashData[i] = password[i];
  8662. }
  8663. j = 0;
  8664. while (i < 32) {
  8665. hashData[i++] = defaultPasswordBytes[j++];
  8666. }
  8667. var hash = calculateMD5(hashData, 0, i);
  8668. var keyLengthInBytes = keyLength >> 3;
  8669. if (revision >= 3) {
  8670. for (j = 0; j < 50; ++j) {
  8671. hash = calculateMD5(hash, 0, hash.length);
  8672. }
  8673. }
  8674. var cipher, userPassword;
  8675. if (revision >= 3) {
  8676. userPassword = ownerPassword;
  8677. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8678. for (j = 19; j >= 0; j--) {
  8679. for (k = 0; k < keyLengthInBytes; ++k) {
  8680. derivedKey[k] = hash[k] ^ j;
  8681. }
  8682. cipher = new ARCFourCipher(derivedKey);
  8683. userPassword = cipher.encryptBlock(userPassword);
  8684. }
  8685. } else {
  8686. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8687. userPassword = cipher.encryptBlock(ownerPassword);
  8688. }
  8689. return userPassword;
  8690. }
  8691. var identityName = Name.get('Identity');
  8692. function CipherTransformFactory(dict, fileId, password) {
  8693. var filter = dict.get('Filter');
  8694. if (!isName(filter) || filter.name !== 'Standard') {
  8695. error('unknown encryption method');
  8696. }
  8697. this.dict = dict;
  8698. var algorithm = dict.get('V');
  8699. if (!isInt(algorithm) ||
  8700. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8701. algorithm !== 5)) {
  8702. error('unsupported encryption algorithm');
  8703. }
  8704. this.algorithm = algorithm;
  8705. var keyLength = dict.get('Length') || 40;
  8706. if (!isInt(keyLength) ||
  8707. keyLength < 40 || (keyLength % 8) !== 0) {
  8708. error('invalid key length');
  8709. }
  8710. // prepare keys
  8711. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8712. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8713. var flags = dict.get('P');
  8714. var revision = dict.get('R');
  8715. // meaningful when V is 4 or 5
  8716. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8717. dict.get('EncryptMetadata') !== false);
  8718. this.encryptMetadata = encryptMetadata;
  8719. var fileIdBytes = stringToBytes(fileId);
  8720. var passwordBytes;
  8721. if (password) {
  8722. passwordBytes = stringToBytes(password);
  8723. }
  8724. var encryptionKey;
  8725. if (algorithm !== 5) {
  8726. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8727. ownerPassword, userPassword, flags,
  8728. revision, keyLength, encryptMetadata);
  8729. }
  8730. else {
  8731. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8732. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8733. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8734. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8735. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8736. var ownerEncryption = stringToBytes(dict.get('OE'));
  8737. var userEncryption = stringToBytes(dict.get('UE'));
  8738. var perms = stringToBytes(dict.get('Perms'));
  8739. encryptionKey =
  8740. createEncryptionKey20(revision, passwordBytes,
  8741. ownerPassword, ownerValidationSalt,
  8742. ownerKeySalt, uBytes,
  8743. userPassword, userValidationSalt,
  8744. userKeySalt, ownerEncryption,
  8745. userEncryption, perms);
  8746. }
  8747. if (!encryptionKey && !password) {
  8748. throw new PasswordException('No password given',
  8749. PasswordResponses.NEED_PASSWORD);
  8750. } else if (!encryptionKey && password) {
  8751. // Attempting use the password as an owner password
  8752. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8753. revision, keyLength);
  8754. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8755. ownerPassword, userPassword, flags,
  8756. revision, keyLength, encryptMetadata);
  8757. }
  8758. if (!encryptionKey) {
  8759. throw new PasswordException('Incorrect Password',
  8760. PasswordResponses.INCORRECT_PASSWORD);
  8761. }
  8762. this.encryptionKey = encryptionKey;
  8763. if (algorithm >= 4) {
  8764. this.cf = dict.get('CF');
  8765. this.stmf = dict.get('StmF') || identityName;
  8766. this.strf = dict.get('StrF') || identityName;
  8767. this.eff = dict.get('EFF') || this.strf;
  8768. }
  8769. }
  8770. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8771. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8772. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8773. key[i] = encryptionKey[i];
  8774. }
  8775. key[i++] = num & 0xFF;
  8776. key[i++] = (num >> 8) & 0xFF;
  8777. key[i++] = (num >> 16) & 0xFF;
  8778. key[i++] = gen & 0xFF;
  8779. key[i++] = (gen >> 8) & 0xFF;
  8780. if (isAes) {
  8781. key[i++] = 0x73;
  8782. key[i++] = 0x41;
  8783. key[i++] = 0x6C;
  8784. key[i++] = 0x54;
  8785. }
  8786. var hash = calculateMD5(key, 0, i);
  8787. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8788. }
  8789. function buildCipherConstructor(cf, name, num, gen, key) {
  8790. var cryptFilter = cf.get(name.name);
  8791. var cfm;
  8792. if (cryptFilter !== null && cryptFilter !== undefined) {
  8793. cfm = cryptFilter.get('CFM');
  8794. }
  8795. if (!cfm || cfm.name === 'None') {
  8796. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8797. return new NullCipher();
  8798. };
  8799. }
  8800. if ('V2' === cfm.name) {
  8801. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8802. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8803. };
  8804. }
  8805. if ('AESV2' === cfm.name) {
  8806. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8807. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8808. };
  8809. }
  8810. if ('AESV3' === cfm.name) {
  8811. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8812. return new AES256Cipher(key);
  8813. };
  8814. }
  8815. error('Unknown crypto method');
  8816. }
  8817. CipherTransformFactory.prototype = {
  8818. createCipherTransform:
  8819. function CipherTransformFactory_createCipherTransform(num, gen) {
  8820. if (this.algorithm === 4 || this.algorithm === 5) {
  8821. return new CipherTransform(
  8822. buildCipherConstructor(this.cf, this.stmf,
  8823. num, gen, this.encryptionKey),
  8824. buildCipherConstructor(this.cf, this.strf,
  8825. num, gen, this.encryptionKey));
  8826. }
  8827. // algorithms 1 and 2
  8828. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8829. var cipherConstructor = function buildCipherCipherConstructor() {
  8830. return new ARCFourCipher(key);
  8831. };
  8832. return new CipherTransform(cipherConstructor, cipherConstructor);
  8833. }
  8834. };
  8835. return CipherTransformFactory;
  8836. })();
  8837. var PatternType = {
  8838. FUNCTION_BASED: 1,
  8839. AXIAL: 2,
  8840. RADIAL: 3,
  8841. FREE_FORM_MESH: 4,
  8842. LATTICE_FORM_MESH: 5,
  8843. COONS_PATCH_MESH: 6,
  8844. TENSOR_PATCH_MESH: 7
  8845. };
  8846. var Pattern = (function PatternClosure() {
  8847. // Constructor should define this.getPattern
  8848. function Pattern() {
  8849. error('should not call Pattern constructor');
  8850. }
  8851. Pattern.prototype = {
  8852. // Input: current Canvas context
  8853. // Output: the appropriate fillStyle or strokeStyle
  8854. getPattern: function Pattern_getPattern(ctx) {
  8855. error('Should not call Pattern.getStyle: ' + ctx);
  8856. }
  8857. };
  8858. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8859. res) {
  8860. var dict = isStream(shading) ? shading.dict : shading;
  8861. var type = dict.get('ShadingType');
  8862. try {
  8863. switch (type) {
  8864. case PatternType.AXIAL:
  8865. case PatternType.RADIAL:
  8866. // Both radial and axial shadings are handled by RadialAxial shading.
  8867. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8868. case PatternType.FREE_FORM_MESH:
  8869. case PatternType.LATTICE_FORM_MESH:
  8870. case PatternType.COONS_PATCH_MESH:
  8871. case PatternType.TENSOR_PATCH_MESH:
  8872. return new Shadings.Mesh(shading, matrix, xref, res);
  8873. default:
  8874. throw new Error('Unknown PatternType: ' + type);
  8875. }
  8876. } catch (ex) {
  8877. if (ex instanceof MissingDataException) {
  8878. throw ex;
  8879. }
  8880. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8881. warn(ex);
  8882. return new Shadings.Dummy();
  8883. }
  8884. };
  8885. return Pattern;
  8886. })();
  8887. var Shadings = {};
  8888. // A small number to offset the first/last color stops so we can insert ones to
  8889. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8890. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8891. // internally so we have to go bigger.
  8892. Shadings.SMALL_NUMBER = 1e-2;
  8893. // Radial and axial shading have very similar implementations
  8894. // If needed, the implementations can be broken into two classes
  8895. Shadings.RadialAxial = (function RadialAxialClosure() {
  8896. function RadialAxial(dict, matrix, xref, res) {
  8897. this.matrix = matrix;
  8898. this.coordsArr = dict.get('Coords');
  8899. this.shadingType = dict.get('ShadingType');
  8900. this.type = 'Pattern';
  8901. var cs = dict.get('ColorSpace', 'CS');
  8902. cs = ColorSpace.parse(cs, xref, res);
  8903. this.cs = cs;
  8904. var t0 = 0.0, t1 = 1.0;
  8905. if (dict.has('Domain')) {
  8906. var domainArr = dict.get('Domain');
  8907. t0 = domainArr[0];
  8908. t1 = domainArr[1];
  8909. }
  8910. var extendStart = false, extendEnd = false;
  8911. if (dict.has('Extend')) {
  8912. var extendArr = dict.get('Extend');
  8913. extendStart = extendArr[0];
  8914. extendEnd = extendArr[1];
  8915. }
  8916. if (this.shadingType === PatternType.RADIAL &&
  8917. (!extendStart || !extendEnd)) {
  8918. // Radial gradient only currently works if either circle is fully within
  8919. // the other circle.
  8920. var x1 = this.coordsArr[0];
  8921. var y1 = this.coordsArr[1];
  8922. var r1 = this.coordsArr[2];
  8923. var x2 = this.coordsArr[3];
  8924. var y2 = this.coordsArr[4];
  8925. var r2 = this.coordsArr[5];
  8926. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8927. if (r1 <= r2 + distance &&
  8928. r2 <= r1 + distance) {
  8929. warn('Unsupported radial gradient.');
  8930. }
  8931. }
  8932. this.extendStart = extendStart;
  8933. this.extendEnd = extendEnd;
  8934. var fnObj = dict.get('Function');
  8935. var fn = PDFFunction.parseArray(xref, fnObj);
  8936. // 10 samples seems good enough for now, but probably won't work
  8937. // if there are sharp color changes. Ideally, we would implement
  8938. // the spec faithfully and add lossless optimizations.
  8939. var diff = t1 - t0;
  8940. var step = diff / 10;
  8941. var colorStops = this.colorStops = [];
  8942. // Protect against bad domains so we don't end up in an infinte loop below.
  8943. if (t0 >= t1 || step <= 0) {
  8944. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8945. // now.
  8946. info('Bad shading domain.');
  8947. return;
  8948. }
  8949. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8950. var rgbColor;
  8951. for (var i = t0; i <= t1; i += step) {
  8952. ratio[0] = i;
  8953. fn(ratio, 0, color, 0);
  8954. rgbColor = cs.getRgb(color, 0);
  8955. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8956. colorStops.push([(i - t0) / diff, cssColor]);
  8957. }
  8958. var background = 'transparent';
  8959. if (dict.has('Background')) {
  8960. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8961. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8962. }
  8963. if (!extendStart) {
  8964. // Insert a color stop at the front and offset the first real color stop
  8965. // so it doesn't conflict with the one we insert.
  8966. colorStops.unshift([0, background]);
  8967. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8968. }
  8969. if (!extendEnd) {
  8970. // Same idea as above in extendStart but for the end.
  8971. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8972. colorStops.push([1, background]);
  8973. }
  8974. this.colorStops = colorStops;
  8975. }
  8976. RadialAxial.prototype = {
  8977. getIR: function RadialAxial_getIR() {
  8978. var coordsArr = this.coordsArr;
  8979. var shadingType = this.shadingType;
  8980. var type, p0, p1, r0, r1;
  8981. if (shadingType === PatternType.AXIAL) {
  8982. p0 = [coordsArr[0], coordsArr[1]];
  8983. p1 = [coordsArr[2], coordsArr[3]];
  8984. r0 = null;
  8985. r1 = null;
  8986. type = 'axial';
  8987. } else if (shadingType === PatternType.RADIAL) {
  8988. p0 = [coordsArr[0], coordsArr[1]];
  8989. p1 = [coordsArr[3], coordsArr[4]];
  8990. r0 = coordsArr[2];
  8991. r1 = coordsArr[5];
  8992. type = 'radial';
  8993. } else {
  8994. error('getPattern type unknown: ' + shadingType);
  8995. }
  8996. var matrix = this.matrix;
  8997. if (matrix) {
  8998. p0 = Util.applyTransform(p0, matrix);
  8999. p1 = Util.applyTransform(p1, matrix);
  9000. }
  9001. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9002. }
  9003. };
  9004. return RadialAxial;
  9005. })();
  9006. // All mesh shading. For now, they will be presented as set of the triangles
  9007. // to be drawn on the canvas and rgb color for each vertex.
  9008. Shadings.Mesh = (function MeshClosure() {
  9009. function MeshStreamReader(stream, context) {
  9010. this.stream = stream;
  9011. this.context = context;
  9012. this.buffer = 0;
  9013. this.bufferLength = 0;
  9014. var numComps = context.numComps;
  9015. this.tmpCompsBuf = new Float32Array(numComps);
  9016. var csNumComps = context.colorSpace;
  9017. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9018. this.tmpCompsBuf;
  9019. }
  9020. MeshStreamReader.prototype = {
  9021. get hasData() {
  9022. if (this.stream.end) {
  9023. return this.stream.pos < this.stream.end;
  9024. }
  9025. if (this.bufferLength > 0) {
  9026. return true;
  9027. }
  9028. var nextByte = this.stream.getByte();
  9029. if (nextByte < 0) {
  9030. return false;
  9031. }
  9032. this.buffer = nextByte;
  9033. this.bufferLength = 8;
  9034. return true;
  9035. },
  9036. readBits: function MeshStreamReader_readBits(n) {
  9037. var buffer = this.buffer;
  9038. var bufferLength = this.bufferLength;
  9039. if (n === 32) {
  9040. if (bufferLength === 0) {
  9041. return ((this.stream.getByte() << 24) |
  9042. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9043. this.stream.getByte()) >>> 0;
  9044. }
  9045. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9046. (this.stream.getByte() << 8) | this.stream.getByte();
  9047. var nextByte = this.stream.getByte();
  9048. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9049. return ((buffer << (8 - bufferLength)) |
  9050. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9051. }
  9052. if (n === 8 && bufferLength === 0) {
  9053. return this.stream.getByte();
  9054. }
  9055. while (bufferLength < n) {
  9056. buffer = (buffer << 8) | this.stream.getByte();
  9057. bufferLength += 8;
  9058. }
  9059. bufferLength -= n;
  9060. this.bufferLength = bufferLength;
  9061. this.buffer = buffer & ((1 << bufferLength) - 1);
  9062. return buffer >> bufferLength;
  9063. },
  9064. align: function MeshStreamReader_align() {
  9065. this.buffer = 0;
  9066. this.bufferLength = 0;
  9067. },
  9068. readFlag: function MeshStreamReader_readFlag() {
  9069. return this.readBits(this.context.bitsPerFlag);
  9070. },
  9071. readCoordinate: function MeshStreamReader_readCoordinate() {
  9072. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9073. var xi = this.readBits(bitsPerCoordinate);
  9074. var yi = this.readBits(bitsPerCoordinate);
  9075. var decode = this.context.decode;
  9076. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9077. 2.3283064365386963e-10; // 2 ^ -32
  9078. return [
  9079. xi * scale * (decode[1] - decode[0]) + decode[0],
  9080. yi * scale * (decode[3] - decode[2]) + decode[2]
  9081. ];
  9082. },
  9083. readComponents: function MeshStreamReader_readComponents() {
  9084. var numComps = this.context.numComps;
  9085. var bitsPerComponent = this.context.bitsPerComponent;
  9086. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9087. 2.3283064365386963e-10; // 2 ^ -32
  9088. var decode = this.context.decode;
  9089. var components = this.tmpCompsBuf;
  9090. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9091. var ci = this.readBits(bitsPerComponent);
  9092. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9093. }
  9094. var color = this.tmpCsCompsBuf;
  9095. if (this.context.colorFn) {
  9096. this.context.colorFn(components, 0, color, 0);
  9097. }
  9098. return this.context.colorSpace.getRgb(color, 0);
  9099. }
  9100. };
  9101. function decodeType4Shading(mesh, reader) {
  9102. var coords = mesh.coords;
  9103. var colors = mesh.colors;
  9104. var operators = [];
  9105. var ps = []; // not maintaining cs since that will match ps
  9106. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9107. while (reader.hasData) {
  9108. var f = reader.readFlag();
  9109. var coord = reader.readCoordinate();
  9110. var color = reader.readComponents();
  9111. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9112. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9113. switch (f) {
  9114. case 0:
  9115. verticesLeft = 3;
  9116. break;
  9117. case 1:
  9118. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9119. verticesLeft = 1;
  9120. break;
  9121. case 2:
  9122. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9123. verticesLeft = 1;
  9124. break;
  9125. }
  9126. operators.push(f);
  9127. }
  9128. ps.push(coords.length);
  9129. coords.push(coord);
  9130. colors.push(color);
  9131. verticesLeft--;
  9132. reader.align();
  9133. }
  9134. var psPacked = new Int32Array(ps);
  9135. mesh.figures.push({
  9136. type: 'triangles',
  9137. coords: psPacked,
  9138. colors: psPacked
  9139. });
  9140. }
  9141. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9142. var coords = mesh.coords;
  9143. var colors = mesh.colors;
  9144. var ps = []; // not maintaining cs since that will match ps
  9145. while (reader.hasData) {
  9146. var coord = reader.readCoordinate();
  9147. var color = reader.readComponents();
  9148. ps.push(coords.length);
  9149. coords.push(coord);
  9150. colors.push(color);
  9151. }
  9152. var psPacked = new Int32Array(ps);
  9153. mesh.figures.push({
  9154. type: 'lattice',
  9155. coords: psPacked,
  9156. colors: psPacked,
  9157. verticesPerRow: verticesPerRow
  9158. });
  9159. }
  9160. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9161. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9162. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9163. var getB = (function getBClosure() {
  9164. function buildB(count) {
  9165. var lut = [];
  9166. for (var i = 0; i <= count; i++) {
  9167. var t = i / count, t_ = 1 - t;
  9168. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9169. 3 * t * t * t_, t * t * t]));
  9170. }
  9171. return lut;
  9172. }
  9173. var cache = [];
  9174. return function getB(count) {
  9175. if (!cache[count]) {
  9176. cache[count] = buildB(count);
  9177. }
  9178. return cache[count];
  9179. };
  9180. })();
  9181. function buildFigureFromPatch(mesh, index) {
  9182. var figure = mesh.figures[index];
  9183. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9184. var coords = mesh.coords, colors = mesh.colors;
  9185. var pi = figure.coords;
  9186. var ci = figure.colors;
  9187. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9188. coords[pi[12]][0], coords[pi[15]][0]);
  9189. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9190. coords[pi[12]][1], coords[pi[15]][1]);
  9191. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9192. coords[pi[12]][0], coords[pi[15]][0]);
  9193. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9194. coords[pi[12]][1], coords[pi[15]][1]);
  9195. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9196. (mesh.bounds[2] - mesh.bounds[0]));
  9197. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9198. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9199. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9200. (mesh.bounds[3] - mesh.bounds[1]));
  9201. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9202. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9203. var verticesPerRow = splitXBy + 1;
  9204. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9205. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9206. var k = 0;
  9207. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9208. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9209. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9210. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9211. for (var row = 0; row <= splitYBy; row++) {
  9212. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9213. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9214. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9215. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9216. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9217. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9218. for (var col = 0; col <= splitXBy; col++, k++) {
  9219. if ((row === 0 || row === splitYBy) &&
  9220. (col === 0 || col === splitXBy)) {
  9221. continue;
  9222. }
  9223. var x = 0, y = 0;
  9224. var q = 0;
  9225. for (var i = 0; i <= 3; i++) {
  9226. for (var j = 0; j <= 3; j++, q++) {
  9227. var m = bRow[row][i] * bCol[col][j];
  9228. x += coords[pi[q]][0] * m;
  9229. y += coords[pi[q]][1] * m;
  9230. }
  9231. }
  9232. figureCoords[k] = coords.length;
  9233. coords.push([x, y]);
  9234. figureColors[k] = colors.length;
  9235. var newColor = new Uint8Array(3);
  9236. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9237. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9238. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9239. colors.push(newColor);
  9240. }
  9241. }
  9242. figureCoords[0] = pi[0];
  9243. figureColors[0] = ci[0];
  9244. figureCoords[splitXBy] = pi[3];
  9245. figureColors[splitXBy] = ci[1];
  9246. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9247. figureColors[verticesPerRow * splitYBy] = ci[2];
  9248. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9249. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9250. mesh.figures[index] = {
  9251. type: 'lattice',
  9252. coords: figureCoords,
  9253. colors: figureColors,
  9254. verticesPerRow: verticesPerRow
  9255. };
  9256. }
  9257. function decodeType6Shading(mesh, reader) {
  9258. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9259. var coords = mesh.coords;
  9260. var colors = mesh.colors;
  9261. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9262. var cs = new Int32Array(4); // c00, c30, c03, c33
  9263. while (reader.hasData) {
  9264. var f = reader.readFlag();
  9265. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9266. var i, ii;
  9267. var pi = coords.length;
  9268. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9269. coords.push(reader.readCoordinate());
  9270. }
  9271. var ci = colors.length;
  9272. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9273. colors.push(reader.readComponents());
  9274. }
  9275. var tmp1, tmp2, tmp3, tmp4;
  9276. switch (f) {
  9277. case 0:
  9278. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9279. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9280. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9281. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9282. cs[2] = ci + 1; cs[3] = ci + 2;
  9283. cs[0] = ci; cs[1] = ci + 3;
  9284. break;
  9285. case 1:
  9286. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9287. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9288. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9289. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9290. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9291. tmp1 = cs[2]; tmp2 = cs[3];
  9292. cs[2] = ci + 1; cs[3] = ci;
  9293. cs[0] = tmp1; cs[1] = tmp2;
  9294. break;
  9295. case 2:
  9296. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9297. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9298. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9299. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9300. cs[2] = cs[3]; cs[3] = ci + 1;
  9301. cs[0] = cs[1]; cs[1] = ci;
  9302. break;
  9303. case 3:
  9304. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9305. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9306. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9307. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9308. cs[2] = cs[0]; cs[3] = cs[1];
  9309. cs[0] = ci; cs[1] = ci + 1;
  9310. break;
  9311. }
  9312. // set p11, p12, p21, p22
  9313. ps[5] = coords.length;
  9314. coords.push([
  9315. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9316. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9317. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9318. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9319. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9320. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9321. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9322. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9323. ]);
  9324. ps[6] = coords.length;
  9325. coords.push([
  9326. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9327. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9328. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9329. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9330. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9331. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9332. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9333. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9334. ]);
  9335. ps[9] = coords.length;
  9336. coords.push([
  9337. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9338. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9339. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9340. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9341. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9342. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9343. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9344. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9345. ]);
  9346. ps[10] = coords.length;
  9347. coords.push([
  9348. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9349. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9350. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9351. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9352. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9353. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9354. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9355. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9356. ]);
  9357. mesh.figures.push({
  9358. type: 'patch',
  9359. coords: new Int32Array(ps), // making copies of ps and cs
  9360. colors: new Int32Array(cs)
  9361. });
  9362. }
  9363. }
  9364. function decodeType7Shading(mesh, reader) {
  9365. var coords = mesh.coords;
  9366. var colors = mesh.colors;
  9367. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9368. var cs = new Int32Array(4); // c00, c30, c03, c33
  9369. while (reader.hasData) {
  9370. var f = reader.readFlag();
  9371. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9372. var i, ii;
  9373. var pi = coords.length;
  9374. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9375. coords.push(reader.readCoordinate());
  9376. }
  9377. var ci = colors.length;
  9378. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9379. colors.push(reader.readComponents());
  9380. }
  9381. var tmp1, tmp2, tmp3, tmp4;
  9382. switch (f) {
  9383. case 0:
  9384. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9385. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9386. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9387. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9388. cs[2] = ci + 1; cs[3] = ci + 2;
  9389. cs[0] = ci; cs[1] = ci + 3;
  9390. break;
  9391. case 1:
  9392. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9393. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9394. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9395. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9396. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9397. tmp1 = cs[2]; tmp2 = cs[3];
  9398. cs[2] = ci + 1; cs[3] = ci;
  9399. cs[0] = tmp1; cs[1] = tmp2;
  9400. break;
  9401. case 2:
  9402. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9403. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9404. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9405. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9406. cs[2] = cs[3]; cs[3] = ci + 1;
  9407. cs[0] = cs[1]; cs[1] = ci;
  9408. break;
  9409. case 3:
  9410. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9411. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9412. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9413. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9414. cs[2] = cs[0]; cs[3] = cs[1];
  9415. cs[0] = ci; cs[1] = ci + 1;
  9416. break;
  9417. }
  9418. mesh.figures.push({
  9419. type: 'patch',
  9420. coords: new Int32Array(ps), // making copies of ps and cs
  9421. colors: new Int32Array(cs)
  9422. });
  9423. }
  9424. }
  9425. function updateBounds(mesh) {
  9426. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9427. maxX = minX, maxY = minY;
  9428. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9429. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9430. minX = minX > x ? x : minX;
  9431. minY = minY > y ? y : minY;
  9432. maxX = maxX < x ? x : maxX;
  9433. maxY = maxY < y ? y : maxY;
  9434. }
  9435. mesh.bounds = [minX, minY, maxX, maxY];
  9436. }
  9437. function packData(mesh) {
  9438. var i, ii, j, jj;
  9439. var coords = mesh.coords;
  9440. var coordsPacked = new Float32Array(coords.length * 2);
  9441. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9442. var xy = coords[i];
  9443. coordsPacked[j++] = xy[0];
  9444. coordsPacked[j++] = xy[1];
  9445. }
  9446. mesh.coords = coordsPacked;
  9447. var colors = mesh.colors;
  9448. var colorsPacked = new Uint8Array(colors.length * 3);
  9449. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9450. var c = colors[i];
  9451. colorsPacked[j++] = c[0];
  9452. colorsPacked[j++] = c[1];
  9453. colorsPacked[j++] = c[2];
  9454. }
  9455. mesh.colors = colorsPacked;
  9456. var figures = mesh.figures;
  9457. for (i = 0, ii = figures.length; i < ii; i++) {
  9458. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9459. for (j = 0, jj = ps.length; j < jj; j++) {
  9460. ps[j] *= 2;
  9461. cs[j] *= 3;
  9462. }
  9463. }
  9464. }
  9465. function Mesh(stream, matrix, xref, res) {
  9466. assert(isStream(stream), 'Mesh data is not a stream');
  9467. var dict = stream.dict;
  9468. this.matrix = matrix;
  9469. this.shadingType = dict.get('ShadingType');
  9470. this.type = 'Pattern';
  9471. this.bbox = dict.get('BBox');
  9472. var cs = dict.get('ColorSpace', 'CS');
  9473. cs = ColorSpace.parse(cs, xref, res);
  9474. this.cs = cs;
  9475. this.background = dict.has('Background') ?
  9476. cs.getRgb(dict.get('Background'), 0) : null;
  9477. var fnObj = dict.get('Function');
  9478. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9479. this.coords = [];
  9480. this.colors = [];
  9481. this.figures = [];
  9482. var decodeContext = {
  9483. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9484. bitsPerComponent: dict.get('BitsPerComponent'),
  9485. bitsPerFlag: dict.get('BitsPerFlag'),
  9486. decode: dict.get('Decode'),
  9487. colorFn: fn,
  9488. colorSpace: cs,
  9489. numComps: fn ? 1 : cs.numComps
  9490. };
  9491. var reader = new MeshStreamReader(stream, decodeContext);
  9492. var patchMesh = false;
  9493. switch (this.shadingType) {
  9494. case PatternType.FREE_FORM_MESH:
  9495. decodeType4Shading(this, reader);
  9496. break;
  9497. case PatternType.LATTICE_FORM_MESH:
  9498. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9499. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9500. decodeType5Shading(this, reader, verticesPerRow);
  9501. break;
  9502. case PatternType.COONS_PATCH_MESH:
  9503. decodeType6Shading(this, reader);
  9504. patchMesh = true;
  9505. break;
  9506. case PatternType.TENSOR_PATCH_MESH:
  9507. decodeType7Shading(this, reader);
  9508. patchMesh = true;
  9509. break;
  9510. default:
  9511. error('Unsupported mesh type.');
  9512. break;
  9513. }
  9514. if (patchMesh) {
  9515. // dirty bounds calculation for determining, how dense shall be triangles
  9516. updateBounds(this);
  9517. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9518. buildFigureFromPatch(this, i);
  9519. }
  9520. }
  9521. // calculate bounds
  9522. updateBounds(this);
  9523. packData(this);
  9524. }
  9525. Mesh.prototype = {
  9526. getIR: function Mesh_getIR() {
  9527. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9528. this.bounds, this.matrix, this.bbox, this.background];
  9529. }
  9530. };
  9531. return Mesh;
  9532. })();
  9533. Shadings.Dummy = (function DummyClosure() {
  9534. function Dummy() {
  9535. this.type = 'Pattern';
  9536. }
  9537. Dummy.prototype = {
  9538. getIR: function Dummy_getIR() {
  9539. return ['Dummy'];
  9540. }
  9541. };
  9542. return Dummy;
  9543. })();
  9544. function getTilingPatternIR(operatorList, dict, args) {
  9545. var matrix = dict.get('Matrix');
  9546. var bbox = dict.get('BBox');
  9547. var xstep = dict.get('XStep');
  9548. var ystep = dict.get('YStep');
  9549. var paintType = dict.get('PaintType');
  9550. var tilingType = dict.get('TilingType');
  9551. return [
  9552. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9553. paintType, tilingType
  9554. ];
  9555. }
  9556. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9557. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9558. uniquePrefix, idCounters, fontCache) {
  9559. this.pdfManager = pdfManager;
  9560. this.xref = xref;
  9561. this.handler = handler;
  9562. this.pageIndex = pageIndex;
  9563. this.uniquePrefix = uniquePrefix;
  9564. this.idCounters = idCounters;
  9565. this.fontCache = fontCache;
  9566. }
  9567. // Trying to minimize Date.now() usage and check every 100 time
  9568. var TIME_SLOT_DURATION_MS = 20;
  9569. var CHECK_TIME_EVERY = 100;
  9570. function TimeSlotManager() {
  9571. this.reset();
  9572. }
  9573. TimeSlotManager.prototype = {
  9574. check: function TimeSlotManager_check() {
  9575. if (++this.checked < CHECK_TIME_EVERY) {
  9576. return false;
  9577. }
  9578. this.checked = 0;
  9579. return this.endTime <= Date.now();
  9580. },
  9581. reset: function TimeSlotManager_reset() {
  9582. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9583. this.checked = 0;
  9584. }
  9585. };
  9586. var deferred = Promise.resolve();
  9587. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9588. PartialEvaluator.prototype = {
  9589. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9590. if (!isDict(resources)) {
  9591. return false;
  9592. }
  9593. var processed = Object.create(null);
  9594. if (resources.objId) {
  9595. processed[resources.objId] = true;
  9596. }
  9597. var nodes = [resources];
  9598. while (nodes.length) {
  9599. var key;
  9600. var node = nodes.shift();
  9601. // First check the current resources for blend modes.
  9602. var graphicStates = node.get('ExtGState');
  9603. if (isDict(graphicStates)) {
  9604. graphicStates = graphicStates.getAll();
  9605. for (key in graphicStates) {
  9606. var graphicState = graphicStates[key];
  9607. var bm = graphicState['BM'];
  9608. if (isName(bm) && bm.name !== 'Normal') {
  9609. return true;
  9610. }
  9611. }
  9612. }
  9613. // Descend into the XObjects to look for more resources and blend modes.
  9614. var xObjects = node.get('XObject');
  9615. if (!isDict(xObjects)) {
  9616. continue;
  9617. }
  9618. xObjects = xObjects.getAll();
  9619. for (key in xObjects) {
  9620. var xObject = xObjects[key];
  9621. if (!isStream(xObject)) {
  9622. continue;
  9623. }
  9624. if (xObject.dict.objId) {
  9625. if (processed[xObject.dict.objId]) {
  9626. // stream has objId and is processed already
  9627. continue;
  9628. }
  9629. processed[xObject.dict.objId] = true;
  9630. }
  9631. var xResources = xObject.dict.get('Resources');
  9632. // Checking objId to detect an infinite loop.
  9633. if (isDict(xResources) &&
  9634. (!xResources.objId || !processed[xResources.objId])) {
  9635. nodes.push(xResources);
  9636. if (xResources.objId) {
  9637. processed[xResources.objId] = true;
  9638. }
  9639. }
  9640. }
  9641. }
  9642. return false;
  9643. },
  9644. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9645. xobj, smask,
  9646. operatorList,
  9647. initialState) {
  9648. var matrix = xobj.dict.get('Matrix');
  9649. var bbox = xobj.dict.get('BBox');
  9650. var group = xobj.dict.get('Group');
  9651. if (group) {
  9652. var groupOptions = {
  9653. matrix: matrix,
  9654. bbox: bbox,
  9655. smask: smask,
  9656. isolated: false,
  9657. knockout: false
  9658. };
  9659. var groupSubtype = group.get('S');
  9660. var colorSpace;
  9661. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9662. groupOptions.isolated = (group.get('I') || false);
  9663. groupOptions.knockout = (group.get('K') || false);
  9664. colorSpace = (group.has('CS') ?
  9665. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9666. }
  9667. if (smask && smask.backdrop) {
  9668. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9669. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9670. }
  9671. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9672. }
  9673. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9674. return this.getOperatorList(xobj,
  9675. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9676. then(function () {
  9677. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9678. if (group) {
  9679. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9680. }
  9681. });
  9682. },
  9683. buildPaintImageXObject:
  9684. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9685. inline, operatorList,
  9686. cacheKey, imageCache) {
  9687. var self = this;
  9688. var dict = image.dict;
  9689. var w = dict.get('Width', 'W');
  9690. var h = dict.get('Height', 'H');
  9691. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9692. warn('Image dimensions are missing, or not numbers.');
  9693. return;
  9694. }
  9695. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9696. warn('Image exceeded maximum allowed size and was removed.');
  9697. return;
  9698. }
  9699. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9700. var imgData, args;
  9701. if (imageMask) {
  9702. // This depends on a tmpCanvas being filled with the
  9703. // current fillStyle, such that processing the pixel
  9704. // data can't be done here. Instead of creating a
  9705. // complete PDFImage, only read the information needed
  9706. // for later.
  9707. var width = dict.get('Width', 'W');
  9708. var height = dict.get('Height', 'H');
  9709. var bitStrideLength = (width + 7) >> 3;
  9710. var imgArray = image.getBytes(bitStrideLength * height);
  9711. var decode = dict.get('Decode', 'D');
  9712. var inverseDecode = (!!decode && decode[0] > 0);
  9713. imgData = PDFImage.createMask(imgArray, width, height,
  9714. image instanceof DecodeStream,
  9715. inverseDecode);
  9716. imgData.cached = true;
  9717. args = [imgData];
  9718. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9719. if (cacheKey) {
  9720. imageCache[cacheKey] = {
  9721. fn: OPS.paintImageMaskXObject,
  9722. args: args
  9723. };
  9724. }
  9725. return;
  9726. }
  9727. var softMask = (dict.get('SMask', 'SM') || false);
  9728. var mask = (dict.get('Mask') || false);
  9729. var SMALL_IMAGE_DIMENSIONS = 200;
  9730. // Inlining small images into the queue as RGB data
  9731. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9732. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9733. var imageObj = new PDFImage(this.xref, resources, image,
  9734. inline, null, null);
  9735. // We force the use of RGBA_32BPP images here, because we can't handle
  9736. // any other kind.
  9737. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9738. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9739. return;
  9740. }
  9741. // If there is no imageMask, create the PDFImage and a lot
  9742. // of image processing can be done here.
  9743. var uniquePrefix = (this.uniquePrefix || '');
  9744. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9745. operatorList.addDependency(objId);
  9746. args = [objId, w, h];
  9747. if (!softMask && !mask && image instanceof JpegStream &&
  9748. image.isNativelySupported(this.xref, resources)) {
  9749. // These JPEGs don't need any more processing so we can just send it.
  9750. operatorList.addOp(OPS.paintJpegXObject, args);
  9751. this.handler.send('obj',
  9752. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9753. return;
  9754. }
  9755. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9756. then(function(imageObj) {
  9757. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9758. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9759. [imgData.data.buffer]);
  9760. }).then(undefined, function (reason) {
  9761. warn('Unable to decode image: ' + reason);
  9762. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9763. });
  9764. operatorList.addOp(OPS.paintImageXObject, args);
  9765. if (cacheKey) {
  9766. imageCache[cacheKey] = {
  9767. fn: OPS.paintImageXObject,
  9768. args: args
  9769. };
  9770. }
  9771. },
  9772. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9773. operatorList,
  9774. stateManager) {
  9775. var smaskContent = smask.get('G');
  9776. var smaskOptions = {
  9777. subtype: smask.get('S').name,
  9778. backdrop: smask.get('BC')
  9779. };
  9780. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9781. operatorList, stateManager.state.clone());
  9782. },
  9783. handleTilingType:
  9784. function PartialEvaluator_handleTilingType(fn, args, resources,
  9785. pattern, patternDict,
  9786. operatorList) {
  9787. // Create an IR of the pattern code.
  9788. var tilingOpList = new OperatorList();
  9789. return this.getOperatorList(pattern,
  9790. (patternDict.get('Resources') || resources), tilingOpList).
  9791. then(function () {
  9792. // Add the dependencies to the parent operator list so they are
  9793. // resolved before sub operator list is executed synchronously.
  9794. operatorList.addDependencies(tilingOpList.dependencies);
  9795. operatorList.addOp(fn, getTilingPatternIR({
  9796. fnArray: tilingOpList.fnArray,
  9797. argsArray: tilingOpList.argsArray
  9798. }, patternDict, args));
  9799. });
  9800. },
  9801. handleSetFont:
  9802. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9803. operatorList, state) {
  9804. // TODO(mack): Not needed?
  9805. var fontName;
  9806. if (fontArgs) {
  9807. fontArgs = fontArgs.slice();
  9808. fontName = fontArgs[0].name;
  9809. }
  9810. var self = this;
  9811. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9812. function (translated) {
  9813. if (!translated.font.isType3Font) {
  9814. return translated;
  9815. }
  9816. return translated.loadType3Data(self, resources, operatorList).then(
  9817. function () {
  9818. return translated;
  9819. });
  9820. }).then(function (translated) {
  9821. state.font = translated.font;
  9822. translated.send(self.handler);
  9823. return translated.loadedName;
  9824. });
  9825. },
  9826. handleText: function PartialEvaluator_handleText(chars, state) {
  9827. var font = state.font;
  9828. var glyphs = font.charsToGlyphs(chars);
  9829. var isAddToPathSet = !!(state.textRenderingMode &
  9830. TextRenderingMode.ADD_TO_PATH_FLAG);
  9831. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9832. var buildPath = function (fontChar) {
  9833. if (!font.renderer.hasBuiltPath(fontChar)) {
  9834. var path = font.renderer.getPathJs(fontChar);
  9835. this.handler.send('commonobj', [
  9836. font.loadedName + '_path_' + fontChar,
  9837. 'FontPath',
  9838. path
  9839. ]);
  9840. }
  9841. }.bind(this);
  9842. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9843. var glyph = glyphs[i];
  9844. if (glyph === null) {
  9845. continue;
  9846. }
  9847. buildPath(glyph.fontChar);
  9848. // If the glyph has an accent we need to build a path for its
  9849. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9850. var accent = glyph.accent;
  9851. if (accent && accent.fontChar) {
  9852. buildPath(accent.fontChar);
  9853. }
  9854. }
  9855. }
  9856. return glyphs;
  9857. },
  9858. setGState: function PartialEvaluator_setGState(resources, gState,
  9859. operatorList, xref,
  9860. stateManager) {
  9861. // This array holds the converted/processed state data.
  9862. var gStateObj = [];
  9863. var gStateMap = gState.map;
  9864. var self = this;
  9865. var promise = Promise.resolve();
  9866. for (var key in gStateMap) {
  9867. var value = gStateMap[key];
  9868. switch (key) {
  9869. case 'Type':
  9870. break;
  9871. case 'LW':
  9872. case 'LC':
  9873. case 'LJ':
  9874. case 'ML':
  9875. case 'D':
  9876. case 'RI':
  9877. case 'FL':
  9878. case 'CA':
  9879. case 'ca':
  9880. gStateObj.push([key, value]);
  9881. break;
  9882. case 'Font':
  9883. promise = promise.then(function () {
  9884. return self.handleSetFont(resources, null, value[0],
  9885. operatorList, stateManager.state).
  9886. then(function (loadedName) {
  9887. operatorList.addDependency(loadedName);
  9888. gStateObj.push([key, [loadedName, value[1]]]);
  9889. });
  9890. });
  9891. break;
  9892. case 'BM':
  9893. gStateObj.push([key, value]);
  9894. break;
  9895. case 'SMask':
  9896. if (isName(value) && value.name === 'None') {
  9897. gStateObj.push([key, false]);
  9898. break;
  9899. }
  9900. var dict = xref.fetchIfRef(value);
  9901. if (isDict(dict)) {
  9902. promise = promise.then(function () {
  9903. return self.handleSMask(dict, resources, operatorList,
  9904. stateManager);
  9905. });
  9906. gStateObj.push([key, true]);
  9907. } else {
  9908. warn('Unsupported SMask type');
  9909. }
  9910. break;
  9911. // Only generate info log messages for the following since
  9912. // they are unlikely to have a big impact on the rendering.
  9913. case 'OP':
  9914. case 'op':
  9915. case 'OPM':
  9916. case 'BG':
  9917. case 'BG2':
  9918. case 'UCR':
  9919. case 'UCR2':
  9920. case 'TR':
  9921. case 'TR2':
  9922. case 'HT':
  9923. case 'SM':
  9924. case 'SA':
  9925. case 'AIS':
  9926. case 'TK':
  9927. // TODO implement these operators.
  9928. info('graphic state operator ' + key);
  9929. break;
  9930. default:
  9931. info('Unknown graphic state operator ' + key);
  9932. break;
  9933. }
  9934. }
  9935. return promise.then(function () {
  9936. if (gStateObj.length >= 0) {
  9937. operatorList.addOp(OPS.setGState, [gStateObj]);
  9938. }
  9939. });
  9940. },
  9941. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9942. resources) {
  9943. function errorFont() {
  9944. return Promise.resolve(new TranslatedFont('g_font_error',
  9945. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9946. }
  9947. var fontRef;
  9948. if (font) { // Loading by ref.
  9949. assert(isRef(font));
  9950. fontRef = font;
  9951. } else { // Loading by name.
  9952. var fontRes = resources.get('Font');
  9953. if (fontRes) {
  9954. fontRef = fontRes.getRaw(fontName);
  9955. } else {
  9956. warn('fontRes not available');
  9957. return errorFont();
  9958. }
  9959. }
  9960. if (!fontRef) {
  9961. warn('fontRef not available');
  9962. return errorFont();
  9963. }
  9964. if (this.fontCache.has(fontRef)) {
  9965. return this.fontCache.get(fontRef);
  9966. }
  9967. font = xref.fetchIfRef(fontRef);
  9968. if (!isDict(font)) {
  9969. return errorFont();
  9970. }
  9971. // We are holding font.translated references just for fontRef that are not
  9972. // dictionaries (Dict). See explanation below.
  9973. if (font.translated) {
  9974. return font.translated;
  9975. }
  9976. var fontCapability = createPromiseCapability();
  9977. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9978. var descriptor = preEvaluatedFont.descriptor;
  9979. var fontID = fontRef.num + '_' + fontRef.gen;
  9980. if (isDict(descriptor)) {
  9981. if (!descriptor.fontAliases) {
  9982. descriptor.fontAliases = Object.create(null);
  9983. }
  9984. var fontAliases = descriptor.fontAliases;
  9985. var hash = preEvaluatedFont.hash;
  9986. if (fontAliases[hash]) {
  9987. var aliasFontRef = fontAliases[hash].aliasRef;
  9988. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9989. this.fontCache.putAlias(fontRef, aliasFontRef);
  9990. return this.fontCache.get(fontRef);
  9991. }
  9992. }
  9993. if (!fontAliases[hash]) {
  9994. fontAliases[hash] = {
  9995. fontID: Font.getFontID()
  9996. };
  9997. }
  9998. fontAliases[hash].aliasRef = fontRef;
  9999. fontID = fontAliases[hash].fontID;
  10000. }
  10001. // Workaround for bad PDF generators that don't reference fonts
  10002. // properly, i.e. by not using an object identifier.
  10003. // Check if the fontRef is a Dict (as opposed to a standard object),
  10004. // in which case we don't cache the font and instead reference it by
  10005. // fontName in font.loadedName below.
  10006. var fontRefIsDict = isDict(fontRef);
  10007. if (!fontRefIsDict) {
  10008. this.fontCache.put(fontRef, fontCapability.promise);
  10009. }
  10010. // Keep track of each font we translated so the caller can
  10011. // load them asynchronously before calling display on a page.
  10012. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10013. fontName.replace(/\W/g, '') : fontID);
  10014. font.translated = fontCapability.promise;
  10015. // TODO move promises into translate font
  10016. var translatedPromise;
  10017. try {
  10018. translatedPromise = Promise.resolve(
  10019. this.translateFont(preEvaluatedFont, xref));
  10020. } catch (e) {
  10021. translatedPromise = Promise.reject(e);
  10022. }
  10023. translatedPromise.then(function (translatedFont) {
  10024. if (translatedFont.fontType !== undefined) {
  10025. var xrefFontStats = xref.stats.fontTypes;
  10026. xrefFontStats[translatedFont.fontType] = true;
  10027. }
  10028. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10029. translatedFont, font));
  10030. }, function (reason) {
  10031. // TODO fontCapability.reject?
  10032. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10033. try {
  10034. // error, but it's still nice to have font type reported
  10035. var descriptor = preEvaluatedFont.descriptor;
  10036. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10037. var subtype = fontFile3 && fontFile3.get('Subtype');
  10038. var fontType = getFontType(preEvaluatedFont.type,
  10039. subtype && subtype.name);
  10040. var xrefFontStats = xref.stats.fontTypes;
  10041. xrefFontStats[fontType] = true;
  10042. } catch (ex) { }
  10043. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10044. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10045. font));
  10046. });
  10047. return fontCapability.promise;
  10048. },
  10049. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10050. var lastIndex = operatorList.length - 1;
  10051. if (!args) {
  10052. args = [];
  10053. }
  10054. if (lastIndex < 0 ||
  10055. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10056. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10057. } else {
  10058. var opArgs = operatorList.argsArray[lastIndex];
  10059. opArgs[0].push(fn);
  10060. Array.prototype.push.apply(opArgs[1], args);
  10061. }
  10062. },
  10063. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10064. cs, patterns, resources, xref) {
  10065. // compile tiling patterns
  10066. var patternName = args[args.length - 1];
  10067. // SCN/scn applies patterns along with normal colors
  10068. var pattern;
  10069. if (isName(patternName) &&
  10070. (pattern = patterns.get(patternName.name))) {
  10071. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10072. var typeNum = dict.get('PatternType');
  10073. if (typeNum === TILING_PATTERN) {
  10074. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10075. return this.handleTilingType(fn, color, resources, pattern,
  10076. dict, operatorList);
  10077. } else if (typeNum === SHADING_PATTERN) {
  10078. var shading = dict.get('Shading');
  10079. var matrix = dict.get('Matrix');
  10080. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10081. operatorList.addOp(fn, pattern.getIR());
  10082. return Promise.resolve();
  10083. } else {
  10084. return Promise.reject('Unknown PatternType: ' + typeNum);
  10085. }
  10086. }
  10087. // TODO shall we fail here?
  10088. operatorList.addOp(fn, args);
  10089. return Promise.resolve();
  10090. },
  10091. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10092. resources,
  10093. operatorList,
  10094. initialState) {
  10095. var self = this;
  10096. var xref = this.xref;
  10097. var imageCache = {};
  10098. assert(operatorList);
  10099. resources = (resources || Dict.empty);
  10100. var xobjs = (resources.get('XObject') || Dict.empty);
  10101. var patterns = (resources.get('Pattern') || Dict.empty);
  10102. var stateManager = new StateManager(initialState || new EvalState());
  10103. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10104. var timeSlotManager = new TimeSlotManager();
  10105. return new Promise(function next(resolve, reject) {
  10106. timeSlotManager.reset();
  10107. var stop, operation = {}, i, ii, cs;
  10108. while (!(stop = timeSlotManager.check())) {
  10109. // The arguments parsed by read() are used beyond this loop, so we
  10110. // cannot reuse the same array on each iteration. Therefore we pass
  10111. // in |null| as the initial value (see the comment on
  10112. // EvaluatorPreprocessor_read() for why).
  10113. operation.args = null;
  10114. if (!(preprocessor.read(operation))) {
  10115. break;
  10116. }
  10117. var args = operation.args;
  10118. var fn = operation.fn;
  10119. switch (fn | 0) {
  10120. case OPS.paintXObject:
  10121. if (args[0].code) {
  10122. break;
  10123. }
  10124. // eagerly compile XForm objects
  10125. var name = args[0].name;
  10126. if (imageCache[name] !== undefined) {
  10127. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10128. args = null;
  10129. continue;
  10130. }
  10131. var xobj = xobjs.get(name);
  10132. if (xobj) {
  10133. assert(isStream(xobj), 'XObject should be a stream');
  10134. var type = xobj.dict.get('Subtype');
  10135. assert(isName(type),
  10136. 'XObject should have a Name subtype');
  10137. if (type.name === 'Form') {
  10138. stateManager.save();
  10139. return self.buildFormXObject(resources, xobj, null,
  10140. operatorList,
  10141. stateManager.state.clone()).
  10142. then(function () {
  10143. stateManager.restore();
  10144. next(resolve, reject);
  10145. }, reject);
  10146. } else if (type.name === 'Image') {
  10147. self.buildPaintImageXObject(resources, xobj, false,
  10148. operatorList, name, imageCache);
  10149. args = null;
  10150. continue;
  10151. } else if (type.name === 'PS') {
  10152. // PostScript XObjects are unused when viewing documents.
  10153. // See section 4.7.1 of Adobe's PDF reference.
  10154. info('Ignored XObject subtype PS');
  10155. continue;
  10156. } else {
  10157. error('Unhandled XObject subtype ' + type.name);
  10158. }
  10159. }
  10160. break;
  10161. case OPS.setFont:
  10162. var fontSize = args[1];
  10163. // eagerly collect all fonts
  10164. return self.handleSetFont(resources, args, null,
  10165. operatorList, stateManager.state).
  10166. then(function (loadedName) {
  10167. operatorList.addDependency(loadedName);
  10168. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10169. next(resolve, reject);
  10170. }, reject);
  10171. case OPS.endInlineImage:
  10172. var cacheKey = args[0].cacheKey;
  10173. if (cacheKey) {
  10174. var cacheEntry = imageCache[cacheKey];
  10175. if (cacheEntry !== undefined) {
  10176. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10177. args = null;
  10178. continue;
  10179. }
  10180. }
  10181. self.buildPaintImageXObject(resources, args[0], true,
  10182. operatorList, cacheKey, imageCache);
  10183. args = null;
  10184. continue;
  10185. case OPS.showText:
  10186. args[0] = self.handleText(args[0], stateManager.state);
  10187. break;
  10188. case OPS.showSpacedText:
  10189. var arr = args[0];
  10190. var combinedGlyphs = [];
  10191. var arrLength = arr.length;
  10192. for (i = 0; i < arrLength; ++i) {
  10193. var arrItem = arr[i];
  10194. if (isString(arrItem)) {
  10195. Array.prototype.push.apply(combinedGlyphs,
  10196. self.handleText(arrItem, stateManager.state));
  10197. } else if (isNum(arrItem)) {
  10198. combinedGlyphs.push(arrItem);
  10199. }
  10200. }
  10201. args[0] = combinedGlyphs;
  10202. fn = OPS.showText;
  10203. break;
  10204. case OPS.nextLineShowText:
  10205. operatorList.addOp(OPS.nextLine);
  10206. args[0] = self.handleText(args[0], stateManager.state);
  10207. fn = OPS.showText;
  10208. break;
  10209. case OPS.nextLineSetSpacingShowText:
  10210. operatorList.addOp(OPS.nextLine);
  10211. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10212. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10213. args[0] = self.handleText(args[0], stateManager.state);
  10214. fn = OPS.showText;
  10215. break;
  10216. case OPS.setTextRenderingMode:
  10217. stateManager.state.textRenderingMode = args[0];
  10218. break;
  10219. case OPS.setFillColorSpace:
  10220. stateManager.state.fillColorSpace =
  10221. ColorSpace.parse(args[0], xref, resources);
  10222. continue;
  10223. case OPS.setStrokeColorSpace:
  10224. stateManager.state.strokeColorSpace =
  10225. ColorSpace.parse(args[0], xref, resources);
  10226. continue;
  10227. case OPS.setFillColor:
  10228. cs = stateManager.state.fillColorSpace;
  10229. args = cs.getRgb(args, 0);
  10230. fn = OPS.setFillRGBColor;
  10231. break;
  10232. case OPS.setStrokeColor:
  10233. cs = stateManager.state.strokeColorSpace;
  10234. args = cs.getRgb(args, 0);
  10235. fn = OPS.setStrokeRGBColor;
  10236. break;
  10237. case OPS.setFillGray:
  10238. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10239. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10240. fn = OPS.setFillRGBColor;
  10241. break;
  10242. case OPS.setStrokeGray:
  10243. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10244. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10245. fn = OPS.setStrokeRGBColor;
  10246. break;
  10247. case OPS.setFillCMYKColor:
  10248. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10249. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10250. fn = OPS.setFillRGBColor;
  10251. break;
  10252. case OPS.setStrokeCMYKColor:
  10253. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10254. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10255. fn = OPS.setStrokeRGBColor;
  10256. break;
  10257. case OPS.setFillRGBColor:
  10258. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10259. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10260. break;
  10261. case OPS.setStrokeRGBColor:
  10262. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10263. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10264. break;
  10265. case OPS.setFillColorN:
  10266. cs = stateManager.state.fillColorSpace;
  10267. if (cs.name === 'Pattern') {
  10268. return self.handleColorN(operatorList, OPS.setFillColorN,
  10269. args, cs, patterns, resources, xref).then(function() {
  10270. next(resolve, reject);
  10271. }, reject);
  10272. }
  10273. args = cs.getRgb(args, 0);
  10274. fn = OPS.setFillRGBColor;
  10275. break;
  10276. case OPS.setStrokeColorN:
  10277. cs = stateManager.state.strokeColorSpace;
  10278. if (cs.name === 'Pattern') {
  10279. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10280. args, cs, patterns, resources, xref).then(function() {
  10281. next(resolve, reject);
  10282. }, reject);
  10283. }
  10284. args = cs.getRgb(args, 0);
  10285. fn = OPS.setStrokeRGBColor;
  10286. break;
  10287. case OPS.shadingFill:
  10288. var shadingRes = resources.get('Shading');
  10289. if (!shadingRes) {
  10290. error('No shading resource found');
  10291. }
  10292. var shading = shadingRes.get(args[0].name);
  10293. if (!shading) {
  10294. error('No shading object found');
  10295. }
  10296. var shadingFill = Pattern.parseShading(shading, null, xref,
  10297. resources);
  10298. var patternIR = shadingFill.getIR();
  10299. args = [patternIR];
  10300. fn = OPS.shadingFill;
  10301. break;
  10302. case OPS.setGState:
  10303. var dictName = args[0];
  10304. var extGState = resources.get('ExtGState');
  10305. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10306. break;
  10307. }
  10308. var gState = extGState.get(dictName.name);
  10309. return self.setGState(resources, gState, operatorList, xref,
  10310. stateManager).then(function() {
  10311. next(resolve, reject);
  10312. }, reject);
  10313. case OPS.moveTo:
  10314. case OPS.lineTo:
  10315. case OPS.curveTo:
  10316. case OPS.curveTo2:
  10317. case OPS.curveTo3:
  10318. case OPS.closePath:
  10319. self.buildPath(operatorList, fn, args);
  10320. continue;
  10321. case OPS.rectangle:
  10322. self.buildPath(operatorList, fn, args);
  10323. continue;
  10324. }
  10325. operatorList.addOp(fn, args);
  10326. }
  10327. if (stop) {
  10328. deferred.then(function () {
  10329. next(resolve, reject);
  10330. });
  10331. return;
  10332. }
  10333. // Some PDFs don't close all restores inside object/form.
  10334. // Closing those for them.
  10335. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10336. operatorList.addOp(OPS.restore, []);
  10337. }
  10338. resolve();
  10339. });
  10340. },
  10341. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10342. stateManager) {
  10343. stateManager = (stateManager || new StateManager(new TextState()));
  10344. var textContent = {
  10345. items: [],
  10346. styles: Object.create(null)
  10347. };
  10348. var bidiTexts = textContent.items;
  10349. var SPACE_FACTOR = 0.35;
  10350. var MULTI_SPACE_FACTOR = 1.5;
  10351. var self = this;
  10352. var xref = this.xref;
  10353. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10354. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10355. var xobjs = null;
  10356. var xobjsCache = {};
  10357. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10358. var textState;
  10359. function newTextChunk() {
  10360. var font = textState.font;
  10361. if (!(font.loadedName in textContent.styles)) {
  10362. textContent.styles[font.loadedName] = {
  10363. fontFamily: font.fallbackName,
  10364. ascent: font.ascent,
  10365. descent: font.descent,
  10366. vertical: font.vertical
  10367. };
  10368. }
  10369. return {
  10370. // |str| is initially an array which we push individual chars to, and
  10371. // then runBidi() overwrites it with the final string.
  10372. str: [],
  10373. dir: null,
  10374. width: 0,
  10375. height: 0,
  10376. transform: null,
  10377. fontName: font.loadedName
  10378. };
  10379. }
  10380. function runBidi(textChunk) {
  10381. var str = textChunk.str.join('');
  10382. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10383. textChunk.str = bidiResult.str;
  10384. textChunk.dir = bidiResult.dir;
  10385. return textChunk;
  10386. }
  10387. function handleSetFont(fontName, fontRef) {
  10388. return self.loadFont(fontName, fontRef, xref, resources).
  10389. then(function (translated) {
  10390. textState.font = translated.font;
  10391. textState.fontMatrix = translated.font.fontMatrix ||
  10392. FONT_IDENTITY_MATRIX;
  10393. });
  10394. }
  10395. function buildTextGeometry(chars, textChunk) {
  10396. var font = textState.font;
  10397. textChunk = textChunk || newTextChunk();
  10398. if (!textChunk.transform) {
  10399. // 9.4.4 Text Space Details
  10400. var tsm = [textState.fontSize * textState.textHScale, 0,
  10401. 0, textState.fontSize,
  10402. 0, textState.textRise];
  10403. var trm = textChunk.transform = Util.transform(textState.ctm,
  10404. Util.transform(textState.textMatrix, tsm));
  10405. if (!font.vertical) {
  10406. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10407. } else {
  10408. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10409. }
  10410. }
  10411. var width = 0;
  10412. var height = 0;
  10413. var glyphs = font.charsToGlyphs(chars);
  10414. var defaultVMetrics = font.defaultVMetrics;
  10415. for (var i = 0; i < glyphs.length; i++) {
  10416. var glyph = glyphs[i];
  10417. if (!glyph) { // Previous glyph was a space.
  10418. width += textState.wordSpacing * textState.textHScale;
  10419. continue;
  10420. }
  10421. var vMetricX = null;
  10422. var vMetricY = null;
  10423. var glyphWidth = null;
  10424. if (font.vertical) {
  10425. if (glyph.vmetric) {
  10426. glyphWidth = glyph.vmetric[0];
  10427. vMetricX = glyph.vmetric[1];
  10428. vMetricY = glyph.vmetric[2];
  10429. } else {
  10430. glyphWidth = glyph.width;
  10431. vMetricX = glyph.width * 0.5;
  10432. vMetricY = defaultVMetrics[2];
  10433. }
  10434. } else {
  10435. glyphWidth = glyph.width;
  10436. }
  10437. var glyphUnicode = glyph.unicode;
  10438. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10439. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10440. }
  10441. glyphUnicode = reverseIfRtl(glyphUnicode);
  10442. // The following will calculate the x and y of the individual glyphs.
  10443. // if (font.vertical) {
  10444. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10445. // textState.fontMatrix[0];
  10446. // tsm[5] -= vMetricY * textState.fontSize *
  10447. // textState.fontMatrix[0];
  10448. // }
  10449. // var trm = Util.transform(textState.textMatrix, tsm);
  10450. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10451. // var x = pt[0];
  10452. // var y = pt[1];
  10453. var tx = 0;
  10454. var ty = 0;
  10455. if (!font.vertical) {
  10456. var w0 = glyphWidth * textState.fontMatrix[0];
  10457. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10458. textState.textHScale;
  10459. width += tx;
  10460. } else {
  10461. var w1 = glyphWidth * textState.fontMatrix[0];
  10462. ty = w1 * textState.fontSize + textState.charSpacing;
  10463. height += ty;
  10464. }
  10465. textState.translateTextMatrix(tx, ty);
  10466. textChunk.str.push(glyphUnicode);
  10467. }
  10468. var a = textState.textLineMatrix[0];
  10469. var b = textState.textLineMatrix[1];
  10470. var scaleLineX = Math.sqrt(a * a + b * b);
  10471. a = textState.ctm[0];
  10472. b = textState.ctm[1];
  10473. var scaleCtmX = Math.sqrt(a * a + b * b);
  10474. if (!font.vertical) {
  10475. textChunk.width += width * scaleCtmX * scaleLineX;
  10476. } else {
  10477. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10478. }
  10479. return textChunk;
  10480. }
  10481. var timeSlotManager = new TimeSlotManager();
  10482. return new Promise(function next(resolve, reject) {
  10483. timeSlotManager.reset();
  10484. var stop, operation = {}, args = [];
  10485. while (!(stop = timeSlotManager.check())) {
  10486. // The arguments parsed by read() are not used beyond this loop, so
  10487. // we can reuse the same array on every iteration, thus avoiding
  10488. // unnecessary allocations.
  10489. args.length = 0;
  10490. operation.args = args;
  10491. if (!(preprocessor.read(operation))) {
  10492. break;
  10493. }
  10494. textState = stateManager.state;
  10495. var fn = operation.fn;
  10496. args = operation.args;
  10497. switch (fn | 0) {
  10498. case OPS.setFont:
  10499. textState.fontSize = args[1];
  10500. return handleSetFont(args[0].name).then(function() {
  10501. next(resolve, reject);
  10502. }, reject);
  10503. case OPS.setTextRise:
  10504. textState.textRise = args[0];
  10505. break;
  10506. case OPS.setHScale:
  10507. textState.textHScale = args[0] / 100;
  10508. break;
  10509. case OPS.setLeading:
  10510. textState.leading = args[0];
  10511. break;
  10512. case OPS.moveText:
  10513. textState.translateTextLineMatrix(args[0], args[1]);
  10514. textState.textMatrix = textState.textLineMatrix.slice();
  10515. break;
  10516. case OPS.setLeadingMoveText:
  10517. textState.leading = -args[1];
  10518. textState.translateTextLineMatrix(args[0], args[1]);
  10519. textState.textMatrix = textState.textLineMatrix.slice();
  10520. break;
  10521. case OPS.nextLine:
  10522. textState.carriageReturn();
  10523. break;
  10524. case OPS.setTextMatrix:
  10525. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10526. args[4], args[5]);
  10527. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10528. args[4], args[5]);
  10529. break;
  10530. case OPS.setCharSpacing:
  10531. textState.charSpacing = args[0];
  10532. break;
  10533. case OPS.setWordSpacing:
  10534. textState.wordSpacing = args[0];
  10535. break;
  10536. case OPS.beginText:
  10537. textState.textMatrix = IDENTITY_MATRIX.slice();
  10538. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10539. break;
  10540. case OPS.showSpacedText:
  10541. var items = args[0];
  10542. var textChunk = newTextChunk();
  10543. var offset;
  10544. for (var j = 0, jj = items.length; j < jj; j++) {
  10545. if (typeof items[j] === 'string') {
  10546. buildTextGeometry(items[j], textChunk);
  10547. } else {
  10548. var val = items[j] / 1000;
  10549. if (!textState.font.vertical) {
  10550. offset = -val * textState.fontSize * textState.textHScale *
  10551. textState.textMatrix[0];
  10552. textState.translateTextMatrix(offset, 0);
  10553. textChunk.width += offset;
  10554. } else {
  10555. offset = -val * textState.fontSize *
  10556. textState.textMatrix[3];
  10557. textState.translateTextMatrix(0, offset);
  10558. textChunk.height += offset;
  10559. }
  10560. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10561. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10562. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10563. fakeSpaces = Math.round(fakeSpaces);
  10564. while (fakeSpaces--) {
  10565. textChunk.str.push(' ');
  10566. }
  10567. } else if (fakeSpaces > SPACE_FACTOR) {
  10568. textChunk.str.push(' ');
  10569. }
  10570. }
  10571. }
  10572. }
  10573. bidiTexts.push(runBidi(textChunk));
  10574. break;
  10575. case OPS.showText:
  10576. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10577. break;
  10578. case OPS.nextLineShowText:
  10579. textState.carriageReturn();
  10580. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10581. break;
  10582. case OPS.nextLineSetSpacingShowText:
  10583. textState.wordSpacing = args[0];
  10584. textState.charSpacing = args[1];
  10585. textState.carriageReturn();
  10586. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10587. break;
  10588. case OPS.paintXObject:
  10589. if (args[0].code) {
  10590. break;
  10591. }
  10592. if (!xobjs) {
  10593. xobjs = (resources.get('XObject') || Dict.empty);
  10594. }
  10595. var name = args[0].name;
  10596. if (xobjsCache.key === name) {
  10597. if (xobjsCache.texts) {
  10598. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10599. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10600. }
  10601. break;
  10602. }
  10603. var xobj = xobjs.get(name);
  10604. if (!xobj) {
  10605. break;
  10606. }
  10607. assert(isStream(xobj), 'XObject should be a stream');
  10608. var type = xobj.dict.get('Subtype');
  10609. assert(isName(type),
  10610. 'XObject should have a Name subtype');
  10611. if ('Form' !== type.name) {
  10612. xobjsCache.key = name;
  10613. xobjsCache.texts = null;
  10614. break;
  10615. }
  10616. stateManager.save();
  10617. var matrix = xobj.dict.get('Matrix');
  10618. if (isArray(matrix) && matrix.length === 6) {
  10619. stateManager.transform(matrix);
  10620. }
  10621. return self.getTextContent(xobj,
  10622. xobj.dict.get('Resources') || resources, stateManager).
  10623. then(function (formTextContent) {
  10624. Util.appendToArray(bidiTexts, formTextContent.items);
  10625. Util.extendObj(textContent.styles, formTextContent.styles);
  10626. stateManager.restore();
  10627. xobjsCache.key = name;
  10628. xobjsCache.texts = formTextContent;
  10629. next(resolve, reject);
  10630. }, reject);
  10631. case OPS.setGState:
  10632. var dictName = args[0];
  10633. var extGState = resources.get('ExtGState');
  10634. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10635. break;
  10636. }
  10637. var gsStateMap = extGState.get(dictName.name);
  10638. var gsStateFont = null;
  10639. for (var key in gsStateMap) {
  10640. if (key === 'Font') {
  10641. assert(!gsStateFont);
  10642. gsStateFont = gsStateMap[key];
  10643. }
  10644. }
  10645. if (gsStateFont) {
  10646. textState.fontSize = gsStateFont[1];
  10647. return handleSetFont(gsStateFont[0]).then(function() {
  10648. next(resolve, reject);
  10649. }, reject);
  10650. }
  10651. break;
  10652. } // switch
  10653. } // while
  10654. if (stop) {
  10655. deferred.then(function () {
  10656. next(resolve, reject);
  10657. });
  10658. return;
  10659. }
  10660. resolve(textContent);
  10661. });
  10662. },
  10663. extractDataStructures: function
  10664. partialEvaluatorExtractDataStructures(dict, baseDict,
  10665. xref, properties) {
  10666. // 9.10.2
  10667. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10668. if (toUnicode) {
  10669. properties.toUnicode = this.readToUnicode(toUnicode);
  10670. }
  10671. if (properties.composite) {
  10672. // CIDSystemInfo helps to match CID to glyphs
  10673. var cidSystemInfo = dict.get('CIDSystemInfo');
  10674. if (isDict(cidSystemInfo)) {
  10675. properties.cidSystemInfo = {
  10676. registry: cidSystemInfo.get('Registry'),
  10677. ordering: cidSystemInfo.get('Ordering'),
  10678. supplement: cidSystemInfo.get('Supplement')
  10679. };
  10680. }
  10681. var cidToGidMap = dict.get('CIDToGIDMap');
  10682. if (isStream(cidToGidMap)) {
  10683. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10684. }
  10685. }
  10686. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10687. // and depends on the font type. The base encoding and differences are
  10688. // read here, but the encoding that is actually used is chosen during
  10689. // glyph mapping in the font.
  10690. // TODO: Loading the built in encoding in the font would allow the
  10691. // differences to be merged in here not require us to hold on to it.
  10692. var differences = [];
  10693. var baseEncodingName = null;
  10694. var encoding;
  10695. if (dict.has('Encoding')) {
  10696. encoding = dict.get('Encoding');
  10697. if (isDict(encoding)) {
  10698. baseEncodingName = encoding.get('BaseEncoding');
  10699. baseEncodingName = (isName(baseEncodingName) ?
  10700. baseEncodingName.name : null);
  10701. // Load the differences between the base and original
  10702. if (encoding.has('Differences')) {
  10703. var diffEncoding = encoding.get('Differences');
  10704. var index = 0;
  10705. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10706. var data = diffEncoding[j];
  10707. if (isNum(data)) {
  10708. index = data;
  10709. } else {
  10710. differences[index++] = data.name;
  10711. }
  10712. }
  10713. }
  10714. } else if (isName(encoding)) {
  10715. baseEncodingName = encoding.name;
  10716. } else {
  10717. error('Encoding is not a Name nor a Dict');
  10718. }
  10719. // According to table 114 if the encoding is a named encoding it must be
  10720. // one of these predefined encodings.
  10721. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10722. baseEncodingName !== 'MacExpertEncoding' &&
  10723. baseEncodingName !== 'WinAnsiEncoding')) {
  10724. baseEncodingName = null;
  10725. }
  10726. }
  10727. if (baseEncodingName) {
  10728. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10729. } else {
  10730. encoding = (properties.type === 'TrueType' ?
  10731. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10732. // The Symbolic attribute can be misused for regular fonts
  10733. // Heuristic: we have to check if the font is a standard one also
  10734. if (!!(properties.flags & FontFlags.Symbolic)) {
  10735. encoding = Encodings.MacRomanEncoding;
  10736. if (!properties.file) {
  10737. if (/Symbol/i.test(properties.name)) {
  10738. encoding = Encodings.SymbolSetEncoding;
  10739. } else if (/Dingbats/i.test(properties.name)) {
  10740. encoding = Encodings.ZapfDingbatsEncoding;
  10741. }
  10742. }
  10743. }
  10744. properties.defaultEncoding = encoding;
  10745. }
  10746. properties.differences = differences;
  10747. properties.baseEncodingName = baseEncodingName;
  10748. properties.dict = dict;
  10749. },
  10750. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10751. var cmap, cmapObj = toUnicode;
  10752. if (isName(cmapObj)) {
  10753. cmap = CMapFactory.create(cmapObj,
  10754. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10755. return new ToUnicodeMap(cmap);
  10756. } else if (isStream(cmapObj)) {
  10757. cmap = CMapFactory.create(cmapObj,
  10758. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10759. // Convert UTF-16BE
  10760. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10761. // to iterate over all keys.
  10762. cmap.forEach(function(token, i) {
  10763. var str = [];
  10764. for (var k = 0; k < token.length; k += 2) {
  10765. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10766. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10767. str.push(w1);
  10768. continue;
  10769. }
  10770. k += 2;
  10771. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10772. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10773. }
  10774. cmap[i] = String.fromCharCode.apply(String, str);
  10775. });
  10776. return new ToUnicodeMap(cmap);
  10777. }
  10778. return null;
  10779. },
  10780. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10781. // Extract the encoding from the CIDToGIDMap
  10782. var glyphsData = cidToGidStream.getBytes();
  10783. // Set encoding 0 to later verify the font has an encoding
  10784. var result = [];
  10785. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10786. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10787. if (glyphID === 0) {
  10788. continue;
  10789. }
  10790. var code = j >> 1;
  10791. result[code] = glyphID;
  10792. }
  10793. return result;
  10794. },
  10795. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10796. descriptor,
  10797. properties) {
  10798. var glyphsWidths = [];
  10799. var defaultWidth = 0;
  10800. var glyphsVMetrics = [];
  10801. var defaultVMetrics;
  10802. var i, ii, j, jj, start, code, widths;
  10803. if (properties.composite) {
  10804. defaultWidth = dict.get('DW') || 1000;
  10805. widths = dict.get('W');
  10806. if (widths) {
  10807. for (i = 0, ii = widths.length; i < ii; i++) {
  10808. start = widths[i++];
  10809. code = xref.fetchIfRef(widths[i]);
  10810. if (isArray(code)) {
  10811. for (j = 0, jj = code.length; j < jj; j++) {
  10812. glyphsWidths[start++] = code[j];
  10813. }
  10814. } else {
  10815. var width = widths[++i];
  10816. for (j = start; j <= code; j++) {
  10817. glyphsWidths[j] = width;
  10818. }
  10819. }
  10820. }
  10821. }
  10822. if (properties.vertical) {
  10823. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10824. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10825. vmetrics = dict.get('W2');
  10826. if (vmetrics) {
  10827. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10828. start = vmetrics[i++];
  10829. code = xref.fetchIfRef(vmetrics[i]);
  10830. if (isArray(code)) {
  10831. for (j = 0, jj = code.length; j < jj; j++) {
  10832. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10833. }
  10834. } else {
  10835. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10836. for (j = start; j <= code; j++) {
  10837. glyphsVMetrics[j] = vmetric;
  10838. }
  10839. }
  10840. }
  10841. }
  10842. }
  10843. } else {
  10844. var firstChar = properties.firstChar;
  10845. widths = dict.get('Widths');
  10846. if (widths) {
  10847. j = firstChar;
  10848. for (i = 0, ii = widths.length; i < ii; i++) {
  10849. glyphsWidths[j++] = widths[i];
  10850. }
  10851. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10852. } else {
  10853. // Trying get the BaseFont metrics (see comment above).
  10854. var baseFontName = dict.get('BaseFont');
  10855. if (isName(baseFontName)) {
  10856. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10857. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10858. properties);
  10859. defaultWidth = metrics.defaultWidth;
  10860. }
  10861. }
  10862. }
  10863. // Heuristic: detection of monospace font by checking all non-zero widths
  10864. var isMonospace = true;
  10865. var firstWidth = defaultWidth;
  10866. for (var glyph in glyphsWidths) {
  10867. var glyphWidth = glyphsWidths[glyph];
  10868. if (!glyphWidth) {
  10869. continue;
  10870. }
  10871. if (!firstWidth) {
  10872. firstWidth = glyphWidth;
  10873. continue;
  10874. }
  10875. if (firstWidth !== glyphWidth) {
  10876. isMonospace = false;
  10877. break;
  10878. }
  10879. }
  10880. if (isMonospace) {
  10881. properties.flags |= FontFlags.FixedPitch;
  10882. }
  10883. properties.defaultWidth = defaultWidth;
  10884. properties.widths = glyphsWidths;
  10885. properties.defaultVMetrics = defaultVMetrics;
  10886. properties.vmetrics = glyphsVMetrics;
  10887. },
  10888. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10889. // Simulating descriptor flags attribute
  10890. var fontNameWoStyle = baseFontName.split('-')[0];
  10891. return (fontNameWoStyle in serifFonts) ||
  10892. (fontNameWoStyle.search(/serif/gi) !== -1);
  10893. },
  10894. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10895. var defaultWidth = 0;
  10896. var widths = [];
  10897. var monospace = false;
  10898. var lookupName = (stdFontMap[name] || name);
  10899. if (!(lookupName in Metrics)) {
  10900. // Use default fonts for looking up font metrics if the passed
  10901. // font is not a base font
  10902. if (this.isSerifFont(name)) {
  10903. lookupName = 'Times-Roman';
  10904. } else {
  10905. lookupName = 'Helvetica';
  10906. }
  10907. }
  10908. var glyphWidths = Metrics[lookupName];
  10909. if (isNum(glyphWidths)) {
  10910. defaultWidth = glyphWidths;
  10911. monospace = true;
  10912. } else {
  10913. widths = glyphWidths;
  10914. }
  10915. return {
  10916. defaultWidth: defaultWidth,
  10917. monospace: monospace,
  10918. widths: widths
  10919. };
  10920. },
  10921. buildCharCodeToWidth:
  10922. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10923. properties) {
  10924. var widths = Object.create(null);
  10925. var differences = properties.differences;
  10926. var encoding = properties.defaultEncoding;
  10927. for (var charCode = 0; charCode < 256; charCode++) {
  10928. if (charCode in differences &&
  10929. widthsByGlyphName[differences[charCode]]) {
  10930. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10931. continue;
  10932. }
  10933. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10934. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10935. continue;
  10936. }
  10937. }
  10938. return widths;
  10939. },
  10940. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10941. var baseDict = dict;
  10942. var type = dict.get('Subtype');
  10943. assert(isName(type), 'invalid font Subtype');
  10944. var composite = false;
  10945. var uint8array;
  10946. if (type.name === 'Type0') {
  10947. // If font is a composite
  10948. // - get the descendant font
  10949. // - set the type according to the descendant font
  10950. // - get the FontDescriptor from the descendant font
  10951. var df = dict.get('DescendantFonts');
  10952. if (!df) {
  10953. error('Descendant fonts are not specified');
  10954. }
  10955. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10956. type = dict.get('Subtype');
  10957. assert(isName(type), 'invalid font Subtype');
  10958. composite = true;
  10959. }
  10960. var descriptor = dict.get('FontDescriptor');
  10961. if (descriptor) {
  10962. var hash = new MurmurHash3_64();
  10963. var encoding = baseDict.getRaw('Encoding');
  10964. if (isName(encoding)) {
  10965. hash.update(encoding.name);
  10966. } else if (isRef(encoding)) {
  10967. hash.update(encoding.num + '_' + encoding.gen);
  10968. }
  10969. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10970. if (isStream(toUnicode)) {
  10971. var stream = toUnicode.str || toUnicode;
  10972. uint8array = stream.buffer ?
  10973. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10974. new Uint8Array(stream.bytes.buffer,
  10975. stream.start, stream.end - stream.start);
  10976. hash.update(uint8array);
  10977. } else if (isName(toUnicode)) {
  10978. hash.update(toUnicode.name);
  10979. }
  10980. var widths = dict.get('Widths') || baseDict.get('Widths');
  10981. if (widths) {
  10982. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10983. hash.update(uint8array);
  10984. }
  10985. }
  10986. return {
  10987. descriptor: descriptor,
  10988. dict: dict,
  10989. baseDict: baseDict,
  10990. composite: composite,
  10991. type: type.name,
  10992. hash: hash ? hash.hexdigest() : ''
  10993. };
  10994. },
  10995. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10996. xref) {
  10997. var baseDict = preEvaluatedFont.baseDict;
  10998. var dict = preEvaluatedFont.dict;
  10999. var composite = preEvaluatedFont.composite;
  11000. var descriptor = preEvaluatedFont.descriptor;
  11001. var type = preEvaluatedFont.type;
  11002. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11003. var properties;
  11004. if (!descriptor) {
  11005. if (type === 'Type3') {
  11006. // FontDescriptor is only required for Type3 fonts when the document
  11007. // is a tagged pdf. Create a barbebones one to get by.
  11008. descriptor = new Dict(null);
  11009. descriptor.set('FontName', Name.get(type));
  11010. } else {
  11011. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11012. // FontDescriptor was not required.
  11013. // This case is here for compatibility.
  11014. var baseFontName = dict.get('BaseFont');
  11015. if (!isName(baseFontName)) {
  11016. error('Base font is not specified');
  11017. }
  11018. // Using base font name as a font name.
  11019. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11020. var metrics = this.getBaseFontMetrics(baseFontName);
  11021. // Simulating descriptor flags attribute
  11022. var fontNameWoStyle = baseFontName.split('-')[0];
  11023. var flags =
  11024. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11025. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11026. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11027. FontFlags.Nonsymbolic);
  11028. properties = {
  11029. type: type,
  11030. name: baseFontName,
  11031. widths: metrics.widths,
  11032. defaultWidth: metrics.defaultWidth,
  11033. flags: flags,
  11034. firstChar: 0,
  11035. lastChar: maxCharIndex
  11036. };
  11037. this.extractDataStructures(dict, dict, xref, properties);
  11038. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11039. properties);
  11040. return new Font(baseFontName, null, properties);
  11041. }
  11042. }
  11043. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11044. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11045. // to ignore this rule when a variant of a standart font is used.
  11046. // TODO Fill the width array depending on which of the base font this is
  11047. // a variant.
  11048. var firstChar = (dict.get('FirstChar') || 0);
  11049. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11050. var fontName = descriptor.get('FontName');
  11051. var baseFont = dict.get('BaseFont');
  11052. // Some bad PDFs have a string as the font name.
  11053. if (isString(fontName)) {
  11054. fontName = Name.get(fontName);
  11055. }
  11056. if (isString(baseFont)) {
  11057. baseFont = Name.get(baseFont);
  11058. }
  11059. if (type !== 'Type3') {
  11060. var fontNameStr = fontName && fontName.name;
  11061. var baseFontStr = baseFont && baseFont.name;
  11062. if (fontNameStr !== baseFontStr) {
  11063. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11064. '" but should be the same as the Font\'s BaseFont "' +
  11065. baseFontStr + '"');
  11066. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11067. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11068. if (fontNameStr && baseFontStr &&
  11069. baseFontStr.indexOf(fontNameStr) === 0) {
  11070. fontName = baseFont;
  11071. }
  11072. }
  11073. }
  11074. fontName = (fontName || baseFont);
  11075. assert(isName(fontName), 'invalid font name');
  11076. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11077. if (fontFile) {
  11078. if (fontFile.dict) {
  11079. var subtype = fontFile.dict.get('Subtype');
  11080. if (subtype) {
  11081. subtype = subtype.name;
  11082. }
  11083. var length1 = fontFile.dict.get('Length1');
  11084. var length2 = fontFile.dict.get('Length2');
  11085. }
  11086. }
  11087. properties = {
  11088. type: type,
  11089. name: fontName.name,
  11090. subtype: subtype,
  11091. file: fontFile,
  11092. length1: length1,
  11093. length2: length2,
  11094. loadedName: baseDict.loadedName,
  11095. composite: composite,
  11096. wideChars: composite,
  11097. fixedPitch: false,
  11098. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11099. firstChar: firstChar || 0,
  11100. lastChar: (lastChar || maxCharIndex),
  11101. bbox: descriptor.get('FontBBox'),
  11102. ascent: descriptor.get('Ascent'),
  11103. descent: descriptor.get('Descent'),
  11104. xHeight: descriptor.get('XHeight'),
  11105. capHeight: descriptor.get('CapHeight'),
  11106. flags: descriptor.get('Flags'),
  11107. italicAngle: descriptor.get('ItalicAngle'),
  11108. coded: false
  11109. };
  11110. if (composite) {
  11111. var cidEncoding = baseDict.get('Encoding');
  11112. if (isName(cidEncoding)) {
  11113. properties.cidEncoding = cidEncoding.name;
  11114. }
  11115. properties.cMap = CMapFactory.create(cidEncoding,
  11116. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11117. properties.vertical = properties.cMap.vertical;
  11118. }
  11119. this.extractDataStructures(dict, baseDict, xref, properties);
  11120. this.extractWidths(dict, xref, descriptor, properties);
  11121. if (type === 'Type3') {
  11122. properties.isType3Font = true;
  11123. }
  11124. return new Font(fontName.name, fontFile, properties);
  11125. }
  11126. };
  11127. return PartialEvaluator;
  11128. })();
  11129. var TranslatedFont = (function TranslatedFontClosure() {
  11130. function TranslatedFont(loadedName, font, dict) {
  11131. this.loadedName = loadedName;
  11132. this.font = font;
  11133. this.dict = dict;
  11134. this.type3Loaded = null;
  11135. this.sent = false;
  11136. }
  11137. TranslatedFont.prototype = {
  11138. send: function (handler) {
  11139. if (this.sent) {
  11140. return;
  11141. }
  11142. var fontData = this.font.exportData();
  11143. handler.send('commonobj', [
  11144. this.loadedName,
  11145. 'Font',
  11146. fontData
  11147. ]);
  11148. this.sent = true;
  11149. },
  11150. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11151. assert(this.font.isType3Font);
  11152. if (this.type3Loaded) {
  11153. return this.type3Loaded;
  11154. }
  11155. var translatedFont = this.font;
  11156. var loadCharProcsPromise = Promise.resolve();
  11157. var charProcs = this.dict.get('CharProcs').getAll();
  11158. var fontResources = this.dict.get('Resources') || resources;
  11159. var charProcKeys = Object.keys(charProcs);
  11160. var charProcOperatorList = {};
  11161. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11162. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11163. var glyphStream = charProcs[key];
  11164. var operatorList = new OperatorList();
  11165. return evaluator.getOperatorList(glyphStream, fontResources,
  11166. operatorList).then(function () {
  11167. charProcOperatorList[key] = operatorList.getIR();
  11168. // Add the dependencies to the parent operator list so they are
  11169. // resolved before sub operator list is executed synchronously.
  11170. parentOperatorList.addDependencies(operatorList.dependencies);
  11171. }, function (reason) {
  11172. warn('Type3 font resource \"' + key + '\" is not available');
  11173. var operatorList = new OperatorList();
  11174. charProcOperatorList[key] = operatorList.getIR();
  11175. });
  11176. }.bind(this, charProcKeys[i]));
  11177. }
  11178. this.type3Loaded = loadCharProcsPromise.then(function () {
  11179. translatedFont.charProcOperatorList = charProcOperatorList;
  11180. });
  11181. return this.type3Loaded;
  11182. }
  11183. };
  11184. return TranslatedFont;
  11185. })();
  11186. var OperatorList = (function OperatorListClosure() {
  11187. var CHUNK_SIZE = 1000;
  11188. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11189. function getTransfers(queue) {
  11190. var transfers = [];
  11191. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11192. for (var i = 0, ii = queue.length; i < ii; i++) {
  11193. switch (fnArray[i]) {
  11194. case OPS.paintInlineImageXObject:
  11195. case OPS.paintInlineImageXObjectGroup:
  11196. case OPS.paintImageMaskXObject:
  11197. var arg = argsArray[i][0]; // first param in imgData
  11198. if (!arg.cached) {
  11199. transfers.push(arg.data.buffer);
  11200. }
  11201. break;
  11202. }
  11203. }
  11204. return transfers;
  11205. }
  11206. function OperatorList(intent, messageHandler, pageIndex) {
  11207. this.messageHandler = messageHandler;
  11208. this.fnArray = [];
  11209. this.argsArray = [];
  11210. this.dependencies = {};
  11211. this.pageIndex = pageIndex;
  11212. this.intent = intent;
  11213. }
  11214. OperatorList.prototype = {
  11215. get length() {
  11216. return this.argsArray.length;
  11217. },
  11218. addOp: function(fn, args) {
  11219. this.fnArray.push(fn);
  11220. this.argsArray.push(args);
  11221. if (this.messageHandler) {
  11222. if (this.fnArray.length >= CHUNK_SIZE) {
  11223. this.flush();
  11224. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11225. (fn === OPS.restore || fn === OPS.endText)) {
  11226. // heuristic to flush on boundary of restore or endText
  11227. this.flush();
  11228. }
  11229. }
  11230. },
  11231. addDependency: function(dependency) {
  11232. if (dependency in this.dependencies) {
  11233. return;
  11234. }
  11235. this.dependencies[dependency] = true;
  11236. this.addOp(OPS.dependency, [dependency]);
  11237. },
  11238. addDependencies: function(dependencies) {
  11239. for (var key in dependencies) {
  11240. this.addDependency(key);
  11241. }
  11242. },
  11243. addOpList: function(opList) {
  11244. Util.extendObj(this.dependencies, opList.dependencies);
  11245. for (var i = 0, ii = opList.length; i < ii; i++) {
  11246. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11247. }
  11248. },
  11249. getIR: function() {
  11250. return {
  11251. fnArray: this.fnArray,
  11252. argsArray: this.argsArray,
  11253. length: this.length
  11254. };
  11255. },
  11256. flush: function(lastChunk) {
  11257. if (this.intent !== 'oplist') {
  11258. new QueueOptimizer().optimize(this);
  11259. }
  11260. var transfers = getTransfers(this);
  11261. this.messageHandler.send('RenderPageChunk', {
  11262. operatorList: {
  11263. fnArray: this.fnArray,
  11264. argsArray: this.argsArray,
  11265. lastChunk: lastChunk,
  11266. length: this.length
  11267. },
  11268. pageIndex: this.pageIndex,
  11269. intent: this.intent
  11270. }, transfers);
  11271. this.dependencies = {};
  11272. this.fnArray.length = 0;
  11273. this.argsArray.length = 0;
  11274. }
  11275. };
  11276. return OperatorList;
  11277. })();
  11278. var StateManager = (function StateManagerClosure() {
  11279. function StateManager(initialState) {
  11280. this.state = initialState;
  11281. this.stateStack = [];
  11282. }
  11283. StateManager.prototype = {
  11284. save: function () {
  11285. var old = this.state;
  11286. this.stateStack.push(this.state);
  11287. this.state = old.clone();
  11288. },
  11289. restore: function () {
  11290. var prev = this.stateStack.pop();
  11291. if (prev) {
  11292. this.state = prev;
  11293. }
  11294. },
  11295. transform: function (args) {
  11296. this.state.ctm = Util.transform(this.state.ctm, args);
  11297. }
  11298. };
  11299. return StateManager;
  11300. })();
  11301. var TextState = (function TextStateClosure() {
  11302. function TextState() {
  11303. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11304. this.fontSize = 0;
  11305. this.font = null;
  11306. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11307. this.textMatrix = IDENTITY_MATRIX.slice();
  11308. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11309. this.charSpacing = 0;
  11310. this.wordSpacing = 0;
  11311. this.leading = 0;
  11312. this.textHScale = 1;
  11313. this.textRise = 0;
  11314. }
  11315. TextState.prototype = {
  11316. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11317. var m = this.textMatrix;
  11318. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11319. },
  11320. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11321. var m = this.textLineMatrix;
  11322. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11323. },
  11324. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11325. var m = this.textMatrix;
  11326. m[4] = m[0] * x + m[2] * y + m[4];
  11327. m[5] = m[1] * x + m[3] * y + m[5];
  11328. },
  11329. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11330. var m = this.textLineMatrix;
  11331. m[4] = m[0] * x + m[2] * y + m[4];
  11332. m[5] = m[1] * x + m[3] * y + m[5];
  11333. },
  11334. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11335. // 9.4.4 Text Space Details
  11336. var tsm = [this.fontSize * this.textHScale, 0,
  11337. 0, this.fontSize,
  11338. 0, this.textRise];
  11339. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11340. },
  11341. carriageReturn: function TextState_carriageReturn() {
  11342. this.translateTextLineMatrix(0, -this.leading);
  11343. this.textMatrix = this.textLineMatrix.slice();
  11344. },
  11345. clone: function TextState_clone() {
  11346. var clone = Object.create(this);
  11347. clone.textMatrix = this.textMatrix.slice();
  11348. clone.textLineMatrix = this.textLineMatrix.slice();
  11349. clone.fontMatrix = this.fontMatrix.slice();
  11350. return clone;
  11351. }
  11352. };
  11353. return TextState;
  11354. })();
  11355. var EvalState = (function EvalStateClosure() {
  11356. function EvalState() {
  11357. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11358. this.font = null;
  11359. this.textRenderingMode = TextRenderingMode.FILL;
  11360. this.fillColorSpace = ColorSpace.singletons.gray;
  11361. this.strokeColorSpace = ColorSpace.singletons.gray;
  11362. }
  11363. EvalState.prototype = {
  11364. clone: function CanvasExtraState_clone() {
  11365. return Object.create(this);
  11366. },
  11367. };
  11368. return EvalState;
  11369. })();
  11370. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11371. // Specifies properties for each command
  11372. //
  11373. // If variableArgs === true: [0, `numArgs`] expected
  11374. // If variableArgs === false: exactly `numArgs` expected
  11375. var OP_MAP = {
  11376. // Graphic state
  11377. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11378. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11379. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11380. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11381. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11382. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11383. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11384. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11385. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11386. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11387. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11388. // Path
  11389. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11390. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11391. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11392. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11393. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11394. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11395. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11396. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11397. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11398. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11399. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11400. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11401. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11402. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11403. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11404. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11405. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11406. // Clipping
  11407. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11408. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11409. // Text
  11410. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11411. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11412. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11413. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11414. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11415. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11416. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11417. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11418. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11419. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11420. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11421. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11422. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11423. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11424. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11425. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11426. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11427. variableArgs: false },
  11428. // Type3 fonts
  11429. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11430. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11431. // Color
  11432. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11433. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11434. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11435. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11436. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11437. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11438. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11439. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11440. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11441. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11442. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11443. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11444. // Shading
  11445. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11446. // Images
  11447. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11448. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11449. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11450. // XObjects
  11451. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11452. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11453. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11454. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11455. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11456. variableArgs: false },
  11457. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11458. // Compatibility
  11459. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11460. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11461. // (reserved partial commands for the lexer)
  11462. BM: null,
  11463. BD: null,
  11464. 'true': null,
  11465. fa: null,
  11466. fal: null,
  11467. fals: null,
  11468. 'false': null,
  11469. nu: null,
  11470. nul: null,
  11471. 'null': null
  11472. };
  11473. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11474. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11475. // dictionary
  11476. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11477. this.stateManager = stateManager;
  11478. this.nonProcessedArgs = [];
  11479. }
  11480. EvaluatorPreprocessor.prototype = {
  11481. get savedStatesDepth() {
  11482. return this.stateManager.stateStack.length;
  11483. },
  11484. // |operation| is an object with two fields:
  11485. //
  11486. // - |fn| is an out param.
  11487. //
  11488. // - |args| is an inout param. On entry, it should have one of two values.
  11489. //
  11490. // - An empty array. This indicates that the caller is providing the
  11491. // array in which the args will be stored in. The caller should use
  11492. // this value if it can reuse a single array for each call to read().
  11493. //
  11494. // - |null|. This indicates that the caller needs this function to create
  11495. // the array in which any args are stored in. If there are zero args,
  11496. // this function will leave |operation.args| as |null| (thus avoiding
  11497. // allocations that would occur if we used an empty array to represent
  11498. // zero arguments). Otherwise, it will replace |null| with a new array
  11499. // containing the arguments. The caller should use this value if it
  11500. // cannot reuse an array for each call to read().
  11501. //
  11502. // These two modes are present because this function is very hot and so
  11503. // avoiding allocations where possible is worthwhile.
  11504. //
  11505. read: function EvaluatorPreprocessor_read(operation) {
  11506. var args = operation.args;
  11507. while (true) {
  11508. var obj = this.parser.getObj();
  11509. if (isCmd(obj)) {
  11510. var cmd = obj.cmd;
  11511. // Check that the command is valid
  11512. var opSpec = OP_MAP[cmd];
  11513. if (!opSpec) {
  11514. warn('Unknown command "' + cmd + '"');
  11515. continue;
  11516. }
  11517. var fn = opSpec.id;
  11518. var numArgs = opSpec.numArgs;
  11519. var argsLength = args !== null ? args.length : 0;
  11520. if (!opSpec.variableArgs) {
  11521. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11522. if (argsLength !== numArgs) {
  11523. var nonProcessedArgs = this.nonProcessedArgs;
  11524. while (argsLength > numArgs) {
  11525. nonProcessedArgs.push(args.shift());
  11526. argsLength--;
  11527. }
  11528. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11529. if (!args) {
  11530. args = [];
  11531. }
  11532. args.unshift(nonProcessedArgs.pop());
  11533. argsLength++;
  11534. }
  11535. }
  11536. if (argsLength < numArgs) {
  11537. // If we receive too few args, it's not possible to possible
  11538. // to execute the command, so skip the command
  11539. info('Command ' + fn + ': because expected ' +
  11540. numArgs + ' args, but received ' + argsLength +
  11541. ' args; skipping');
  11542. args = null;
  11543. continue;
  11544. }
  11545. } else if (argsLength > numArgs) {
  11546. info('Command ' + fn + ': expected [0,' + numArgs +
  11547. '] args, but received ' + argsLength + ' args');
  11548. }
  11549. // TODO figure out how to type-check vararg functions
  11550. this.preprocessCommand(fn, args);
  11551. operation.fn = fn;
  11552. operation.args = args;
  11553. return true;
  11554. } else {
  11555. if (isEOF(obj)) {
  11556. return false; // no more commands
  11557. }
  11558. // argument
  11559. if (obj !== null) {
  11560. if (!args) {
  11561. args = [];
  11562. }
  11563. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11564. assert(args.length <= 33, 'Too many arguments');
  11565. }
  11566. }
  11567. }
  11568. },
  11569. preprocessCommand:
  11570. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11571. switch (fn | 0) {
  11572. case OPS.save:
  11573. this.stateManager.save();
  11574. break;
  11575. case OPS.restore:
  11576. this.stateManager.restore();
  11577. break;
  11578. case OPS.transform:
  11579. this.stateManager.transform(args);
  11580. break;
  11581. }
  11582. }
  11583. };
  11584. return EvaluatorPreprocessor;
  11585. })();
  11586. var QueueOptimizer = (function QueueOptimizerClosure() {
  11587. function addState(parentState, pattern, fn) {
  11588. var state = parentState;
  11589. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11590. var item = pattern[i];
  11591. state = (state[item] || (state[item] = []));
  11592. }
  11593. state[pattern[pattern.length - 1]] = fn;
  11594. }
  11595. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11596. argsArray) {
  11597. // Handles special case of mainly LaTeX documents which use image masks to
  11598. // draw lines with the current fill style.
  11599. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11600. // have been found at iFirstSave.
  11601. var iFirstPIMXO = iFirstSave + 2;
  11602. for (var i = 0; i < count; i++) {
  11603. var arg = argsArray[iFirstPIMXO + 4 * i];
  11604. var imageMask = arg.length === 1 && arg[0];
  11605. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11606. (!imageMask.data.length ||
  11607. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11608. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11609. continue;
  11610. }
  11611. break;
  11612. }
  11613. return count - i;
  11614. }
  11615. var InitialState = [];
  11616. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11617. // sequences with one |paintInlineImageXObjectGroup| operation.
  11618. addState(InitialState,
  11619. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11620. function foundInlineImageGroup(context) {
  11621. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11622. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11623. var MAX_WIDTH = 1000;
  11624. var IMAGE_PADDING = 1;
  11625. var fnArray = context.fnArray, argsArray = context.argsArray;
  11626. var curr = context.iCurr;
  11627. var iFirstSave = curr - 3;
  11628. var iFirstTransform = curr - 2;
  11629. var iFirstPIIXO = curr - 1;
  11630. // Look for the quartets.
  11631. var i = iFirstSave + 4;
  11632. var ii = fnArray.length;
  11633. while (i + 3 < ii) {
  11634. if (fnArray[i] !== OPS.save ||
  11635. fnArray[i + 1] !== OPS.transform ||
  11636. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11637. fnArray[i + 3] !== OPS.restore) {
  11638. break; // ops don't match
  11639. }
  11640. i += 4;
  11641. }
  11642. // At this point, i is the index of the first op past the last valid
  11643. // quartet.
  11644. var count = Math.min((i - iFirstSave) / 4,
  11645. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11646. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11647. return i;
  11648. }
  11649. // assuming that heights of those image is too small (~1 pixel)
  11650. // packing as much as possible by lines
  11651. var maxX = 0;
  11652. var map = [], maxLineHeight = 0;
  11653. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11654. var q;
  11655. for (q = 0; q < count; q++) {
  11656. var transform = argsArray[iFirstTransform + (q << 2)];
  11657. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11658. if (currentX + img.width > MAX_WIDTH) {
  11659. // starting new line
  11660. maxX = Math.max(maxX, currentX);
  11661. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11662. currentX = 0;
  11663. maxLineHeight = 0;
  11664. }
  11665. map.push({
  11666. transform: transform,
  11667. x: currentX, y: currentY,
  11668. w: img.width, h: img.height
  11669. });
  11670. currentX += img.width + 2 * IMAGE_PADDING;
  11671. maxLineHeight = Math.max(maxLineHeight, img.height);
  11672. }
  11673. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11674. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11675. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11676. var imgRowSize = imgWidth << 2;
  11677. for (q = 0; q < count; q++) {
  11678. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11679. // Copy image by lines and extends pixels into padding.
  11680. var rowSize = map[q].w << 2;
  11681. var dataOffset = 0;
  11682. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11683. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11684. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11685. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11686. dataOffset += rowSize;
  11687. offset += imgRowSize;
  11688. }
  11689. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11690. while (offset >= 0) {
  11691. data[offset - 4] = data[offset];
  11692. data[offset - 3] = data[offset + 1];
  11693. data[offset - 2] = data[offset + 2];
  11694. data[offset - 1] = data[offset + 3];
  11695. data[offset + rowSize] = data[offset + rowSize - 4];
  11696. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11697. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11698. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11699. offset -= imgRowSize;
  11700. }
  11701. }
  11702. // Replace queue items.
  11703. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11704. argsArray.splice(iFirstSave, count * 4,
  11705. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11706. data: imgData }, map]);
  11707. return iFirstSave + 1;
  11708. });
  11709. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11710. // sequences with one |paintImageMaskXObjectGroup| or one
  11711. // |paintImageMaskXObjectRepeat| operation.
  11712. addState(InitialState,
  11713. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11714. function foundImageMaskGroup(context) {
  11715. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11716. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11717. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11718. var fnArray = context.fnArray, argsArray = context.argsArray;
  11719. var curr = context.iCurr;
  11720. var iFirstSave = curr - 3;
  11721. var iFirstTransform = curr - 2;
  11722. var iFirstPIMXO = curr - 1;
  11723. // Look for the quartets.
  11724. var i = iFirstSave + 4;
  11725. var ii = fnArray.length;
  11726. while (i + 3 < ii) {
  11727. if (fnArray[i] !== OPS.save ||
  11728. fnArray[i + 1] !== OPS.transform ||
  11729. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11730. fnArray[i + 3] !== OPS.restore) {
  11731. break; // ops don't match
  11732. }
  11733. i += 4;
  11734. }
  11735. // At this point, i is the index of the first op past the last valid
  11736. // quartet.
  11737. var count = (i - iFirstSave) / 4;
  11738. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11739. argsArray);
  11740. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11741. return i;
  11742. }
  11743. var q;
  11744. var isSameImage = false;
  11745. var iTransform, transformArgs;
  11746. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11747. if (argsArray[iFirstTransform][1] === 0 &&
  11748. argsArray[iFirstTransform][2] === 0) {
  11749. isSameImage = true;
  11750. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11751. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11752. iTransform = iFirstTransform + 4;
  11753. var iPIMXO = iFirstPIMXO + 4;
  11754. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11755. transformArgs = argsArray[iTransform];
  11756. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11757. transformArgs[0] !== firstTransformArg0 ||
  11758. transformArgs[1] !== 0 ||
  11759. transformArgs[2] !== 0 ||
  11760. transformArgs[3] !== firstTransformArg3) {
  11761. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11762. isSameImage = false;
  11763. } else {
  11764. count = q;
  11765. }
  11766. break; // different image or transform
  11767. }
  11768. }
  11769. }
  11770. if (isSameImage) {
  11771. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11772. var positions = new Float32Array(count * 2);
  11773. iTransform = iFirstTransform;
  11774. for (q = 0; q < count; q++, iTransform += 4) {
  11775. transformArgs = argsArray[iTransform];
  11776. positions[(q << 1)] = transformArgs[4];
  11777. positions[(q << 1) + 1] = transformArgs[5];
  11778. }
  11779. // Replace queue items.
  11780. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11781. argsArray.splice(iFirstSave, count * 4,
  11782. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11783. } else {
  11784. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11785. var images = [];
  11786. for (q = 0; q < count; q++) {
  11787. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11788. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11789. images.push({ data: maskParams.data, width: maskParams.width,
  11790. height: maskParams.height,
  11791. transform: transformArgs });
  11792. }
  11793. // Replace queue items.
  11794. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11795. argsArray.splice(iFirstSave, count * 4, [images]);
  11796. }
  11797. return iFirstSave + 1;
  11798. });
  11799. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11800. // with one paintImageXObjectRepeat operation, if the |transform| and
  11801. // |paintImageXObjectRepeat| ops are appropriate.
  11802. addState(InitialState,
  11803. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11804. function (context) {
  11805. var MIN_IMAGES_IN_BLOCK = 3;
  11806. var MAX_IMAGES_IN_BLOCK = 1000;
  11807. var fnArray = context.fnArray, argsArray = context.argsArray;
  11808. var curr = context.iCurr;
  11809. var iFirstSave = curr - 3;
  11810. var iFirstTransform = curr - 2;
  11811. var iFirstPIXO = curr - 1;
  11812. var iFirstRestore = curr;
  11813. if (argsArray[iFirstTransform][1] !== 0 ||
  11814. argsArray[iFirstTransform][2] !== 0) {
  11815. return iFirstRestore + 1; // transform has the wrong form
  11816. }
  11817. // Look for the quartets.
  11818. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11819. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11820. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11821. var i = iFirstSave + 4;
  11822. var ii = fnArray.length;
  11823. while (i + 3 < ii) {
  11824. if (fnArray[i] !== OPS.save ||
  11825. fnArray[i + 1] !== OPS.transform ||
  11826. fnArray[i + 2] !== OPS.paintImageXObject ||
  11827. fnArray[i + 3] !== OPS.restore) {
  11828. break; // ops don't match
  11829. }
  11830. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11831. argsArray[i + 1][1] !== 0 ||
  11832. argsArray[i + 1][2] !== 0 ||
  11833. argsArray[i + 1][3] !== firstTransformArg3) {
  11834. break; // transforms don't match
  11835. }
  11836. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11837. break; // images don't match
  11838. }
  11839. i += 4;
  11840. }
  11841. // At this point, i is the index of the first op past the last valid
  11842. // quartet.
  11843. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11844. if (count < MIN_IMAGES_IN_BLOCK) {
  11845. return i;
  11846. }
  11847. // Extract the (x,y) positions from all of the matching transforms.
  11848. var positions = new Float32Array(count * 2);
  11849. var iTransform = iFirstTransform;
  11850. for (var q = 0; q < count; q++, iTransform += 4) {
  11851. var transformArgs = argsArray[iTransform];
  11852. positions[(q << 1)] = transformArgs[4];
  11853. positions[(q << 1) + 1] = transformArgs[5];
  11854. }
  11855. // Replace queue items.
  11856. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11857. positions];
  11858. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11859. argsArray.splice(iFirstSave, count * 4, args);
  11860. return iFirstSave + 1;
  11861. });
  11862. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11863. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11864. // sequences, if the font for each one is the same.
  11865. addState(InitialState,
  11866. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11867. function (context) {
  11868. var MIN_CHARS_IN_BLOCK = 3;
  11869. var MAX_CHARS_IN_BLOCK = 1000;
  11870. var fnArray = context.fnArray, argsArray = context.argsArray;
  11871. var curr = context.iCurr;
  11872. var iFirstBeginText = curr - 4;
  11873. var iFirstSetFont = curr - 3;
  11874. var iFirstSetTextMatrix = curr - 2;
  11875. var iFirstShowText = curr - 1;
  11876. var iFirstEndText = curr;
  11877. // Look for the quintets.
  11878. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11879. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11880. var i = iFirstBeginText + 5;
  11881. var ii = fnArray.length;
  11882. while (i + 4 < ii) {
  11883. if (fnArray[i] !== OPS.beginText ||
  11884. fnArray[i + 1] !== OPS.setFont ||
  11885. fnArray[i + 2] !== OPS.setTextMatrix ||
  11886. fnArray[i + 3] !== OPS.showText ||
  11887. fnArray[i + 4] !== OPS.endText) {
  11888. break; // ops don't match
  11889. }
  11890. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11891. argsArray[i + 1][1] !== firstSetFontArg1) {
  11892. break; // fonts don't match
  11893. }
  11894. i += 5;
  11895. }
  11896. // At this point, i is the index of the first op past the last valid
  11897. // quintet.
  11898. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11899. if (count < MIN_CHARS_IN_BLOCK) {
  11900. return i;
  11901. }
  11902. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11903. // showText, endText), include that as well. (E.g. <something> might be
  11904. // |dependency|.)
  11905. var iFirst = iFirstBeginText;
  11906. if (iFirstBeginText >= 4 &&
  11907. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11908. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11909. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11910. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11911. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11912. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11913. count++;
  11914. iFirst -= 5;
  11915. }
  11916. // Remove (endText, beginText, setFont) trios.
  11917. var iEndText = iFirst + 4;
  11918. for (var q = 1; q < count; q++) {
  11919. fnArray.splice(iEndText, 3);
  11920. argsArray.splice(iEndText, 3);
  11921. iEndText += 2;
  11922. }
  11923. return iEndText + 1;
  11924. });
  11925. function QueueOptimizer() {}
  11926. QueueOptimizer.prototype = {
  11927. optimize: function QueueOptimizer_optimize(queue) {
  11928. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11929. var context = {
  11930. iCurr: 0,
  11931. fnArray: fnArray,
  11932. argsArray: argsArray
  11933. };
  11934. var state;
  11935. var i = 0, ii = fnArray.length;
  11936. while (i < ii) {
  11937. state = (state || InitialState)[fnArray[i]];
  11938. if (typeof state === 'function') { // we found some handler
  11939. context.iCurr = i;
  11940. // state() returns the index of the first non-matching op (if we
  11941. // didn't match) or the first op past the modified ops (if we did
  11942. // match and replace).
  11943. i = state(context);
  11944. state = undefined; // reset the state machine
  11945. ii = context.fnArray.length;
  11946. } else {
  11947. i++;
  11948. }
  11949. }
  11950. }
  11951. };
  11952. return QueueOptimizer;
  11953. })();
  11954. var BUILT_IN_CMAPS = [
  11955. // << Start unicode maps.
  11956. 'Adobe-GB1-UCS2',
  11957. 'Adobe-CNS1-UCS2',
  11958. 'Adobe-Japan1-UCS2',
  11959. 'Adobe-Korea1-UCS2',
  11960. // >> End unicode maps.
  11961. '78-EUC-H',
  11962. '78-EUC-V',
  11963. '78-H',
  11964. '78-RKSJ-H',
  11965. '78-RKSJ-V',
  11966. '78-V',
  11967. '78ms-RKSJ-H',
  11968. '78ms-RKSJ-V',
  11969. '83pv-RKSJ-H',
  11970. '90ms-RKSJ-H',
  11971. '90ms-RKSJ-V',
  11972. '90msp-RKSJ-H',
  11973. '90msp-RKSJ-V',
  11974. '90pv-RKSJ-H',
  11975. '90pv-RKSJ-V',
  11976. 'Add-H',
  11977. 'Add-RKSJ-H',
  11978. 'Add-RKSJ-V',
  11979. 'Add-V',
  11980. 'Adobe-CNS1-0',
  11981. 'Adobe-CNS1-1',
  11982. 'Adobe-CNS1-2',
  11983. 'Adobe-CNS1-3',
  11984. 'Adobe-CNS1-4',
  11985. 'Adobe-CNS1-5',
  11986. 'Adobe-CNS1-6',
  11987. 'Adobe-GB1-0',
  11988. 'Adobe-GB1-1',
  11989. 'Adobe-GB1-2',
  11990. 'Adobe-GB1-3',
  11991. 'Adobe-GB1-4',
  11992. 'Adobe-GB1-5',
  11993. 'Adobe-Japan1-0',
  11994. 'Adobe-Japan1-1',
  11995. 'Adobe-Japan1-2',
  11996. 'Adobe-Japan1-3',
  11997. 'Adobe-Japan1-4',
  11998. 'Adobe-Japan1-5',
  11999. 'Adobe-Japan1-6',
  12000. 'Adobe-Korea1-0',
  12001. 'Adobe-Korea1-1',
  12002. 'Adobe-Korea1-2',
  12003. 'B5-H',
  12004. 'B5-V',
  12005. 'B5pc-H',
  12006. 'B5pc-V',
  12007. 'CNS-EUC-H',
  12008. 'CNS-EUC-V',
  12009. 'CNS1-H',
  12010. 'CNS1-V',
  12011. 'CNS2-H',
  12012. 'CNS2-V',
  12013. 'ETHK-B5-H',
  12014. 'ETHK-B5-V',
  12015. 'ETen-B5-H',
  12016. 'ETen-B5-V',
  12017. 'ETenms-B5-H',
  12018. 'ETenms-B5-V',
  12019. 'EUC-H',
  12020. 'EUC-V',
  12021. 'Ext-H',
  12022. 'Ext-RKSJ-H',
  12023. 'Ext-RKSJ-V',
  12024. 'Ext-V',
  12025. 'GB-EUC-H',
  12026. 'GB-EUC-V',
  12027. 'GB-H',
  12028. 'GB-V',
  12029. 'GBK-EUC-H',
  12030. 'GBK-EUC-V',
  12031. 'GBK2K-H',
  12032. 'GBK2K-V',
  12033. 'GBKp-EUC-H',
  12034. 'GBKp-EUC-V',
  12035. 'GBT-EUC-H',
  12036. 'GBT-EUC-V',
  12037. 'GBT-H',
  12038. 'GBT-V',
  12039. 'GBTpc-EUC-H',
  12040. 'GBTpc-EUC-V',
  12041. 'GBpc-EUC-H',
  12042. 'GBpc-EUC-V',
  12043. 'H',
  12044. 'HKdla-B5-H',
  12045. 'HKdla-B5-V',
  12046. 'HKdlb-B5-H',
  12047. 'HKdlb-B5-V',
  12048. 'HKgccs-B5-H',
  12049. 'HKgccs-B5-V',
  12050. 'HKm314-B5-H',
  12051. 'HKm314-B5-V',
  12052. 'HKm471-B5-H',
  12053. 'HKm471-B5-V',
  12054. 'HKscs-B5-H',
  12055. 'HKscs-B5-V',
  12056. 'Hankaku',
  12057. 'Hiragana',
  12058. 'KSC-EUC-H',
  12059. 'KSC-EUC-V',
  12060. 'KSC-H',
  12061. 'KSC-Johab-H',
  12062. 'KSC-Johab-V',
  12063. 'KSC-V',
  12064. 'KSCms-UHC-H',
  12065. 'KSCms-UHC-HW-H',
  12066. 'KSCms-UHC-HW-V',
  12067. 'KSCms-UHC-V',
  12068. 'KSCpc-EUC-H',
  12069. 'KSCpc-EUC-V',
  12070. 'Katakana',
  12071. 'NWP-H',
  12072. 'NWP-V',
  12073. 'RKSJ-H',
  12074. 'RKSJ-V',
  12075. 'Roman',
  12076. 'UniCNS-UCS2-H',
  12077. 'UniCNS-UCS2-V',
  12078. 'UniCNS-UTF16-H',
  12079. 'UniCNS-UTF16-V',
  12080. 'UniCNS-UTF32-H',
  12081. 'UniCNS-UTF32-V',
  12082. 'UniCNS-UTF8-H',
  12083. 'UniCNS-UTF8-V',
  12084. 'UniGB-UCS2-H',
  12085. 'UniGB-UCS2-V',
  12086. 'UniGB-UTF16-H',
  12087. 'UniGB-UTF16-V',
  12088. 'UniGB-UTF32-H',
  12089. 'UniGB-UTF32-V',
  12090. 'UniGB-UTF8-H',
  12091. 'UniGB-UTF8-V',
  12092. 'UniJIS-UCS2-H',
  12093. 'UniJIS-UCS2-HW-H',
  12094. 'UniJIS-UCS2-HW-V',
  12095. 'UniJIS-UCS2-V',
  12096. 'UniJIS-UTF16-H',
  12097. 'UniJIS-UTF16-V',
  12098. 'UniJIS-UTF32-H',
  12099. 'UniJIS-UTF32-V',
  12100. 'UniJIS-UTF8-H',
  12101. 'UniJIS-UTF8-V',
  12102. 'UniJIS2004-UTF16-H',
  12103. 'UniJIS2004-UTF16-V',
  12104. 'UniJIS2004-UTF32-H',
  12105. 'UniJIS2004-UTF32-V',
  12106. 'UniJIS2004-UTF8-H',
  12107. 'UniJIS2004-UTF8-V',
  12108. 'UniJISPro-UCS2-HW-V',
  12109. 'UniJISPro-UCS2-V',
  12110. 'UniJISPro-UTF8-V',
  12111. 'UniJISX0213-UTF32-H',
  12112. 'UniJISX0213-UTF32-V',
  12113. 'UniJISX02132004-UTF32-H',
  12114. 'UniJISX02132004-UTF32-V',
  12115. 'UniKS-UCS2-H',
  12116. 'UniKS-UCS2-V',
  12117. 'UniKS-UTF16-H',
  12118. 'UniKS-UTF16-V',
  12119. 'UniKS-UTF32-H',
  12120. 'UniKS-UTF32-V',
  12121. 'UniKS-UTF8-H',
  12122. 'UniKS-UTF8-V',
  12123. 'V',
  12124. 'WP-Symbol'];
  12125. // CMap, not to be confused with TrueType's cmap.
  12126. var CMap = (function CMapClosure() {
  12127. function CMap(builtInCMap) {
  12128. // Codespace ranges are stored as follows:
  12129. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12130. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12131. this.codespaceRanges = [[], [], [], []];
  12132. this.numCodespaceRanges = 0;
  12133. // Map entries have one of two forms.
  12134. // - cid chars are 16-bit unsigned integers, stored as integers.
  12135. // - bf chars are variable-length byte sequences, stored as strings, with
  12136. // one byte per character.
  12137. this._map = [];
  12138. this.vertical = false;
  12139. this.useCMap = null;
  12140. this.builtInCMap = builtInCMap;
  12141. }
  12142. CMap.prototype = {
  12143. addCodespaceRange: function(n, low, high) {
  12144. this.codespaceRanges[n - 1].push(low, high);
  12145. this.numCodespaceRanges++;
  12146. },
  12147. mapCidRange: function(low, high, dstLow) {
  12148. while (low <= high) {
  12149. this._map[low++] = dstLow++;
  12150. }
  12151. },
  12152. mapBfRange: function(low, high, dstLow) {
  12153. var lastByte = dstLow.length - 1;
  12154. while (low <= high) {
  12155. this._map[low++] = dstLow;
  12156. // Only the last byte has to be incremented.
  12157. dstLow = dstLow.substr(0, lastByte) +
  12158. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12159. }
  12160. },
  12161. mapBfRangeToArray: function(low, high, array) {
  12162. var i = 0, ii = array.length;
  12163. while (low <= high && i < ii) {
  12164. this._map[low] = array[i++];
  12165. ++low;
  12166. }
  12167. },
  12168. // This is used for both bf and cid chars.
  12169. mapOne: function(src, dst) {
  12170. this._map[src] = dst;
  12171. },
  12172. lookup: function(code) {
  12173. return this._map[code];
  12174. },
  12175. contains: function(code) {
  12176. return this._map[code] !== undefined;
  12177. },
  12178. forEach: function(callback) {
  12179. // Most maps have fewer than 65536 entries, and for those we use normal
  12180. // array iteration. But really sparse tables are possible -- e.g. with
  12181. // indices in the *billions*. For such tables we use for..in, which isn't
  12182. // ideal because it stringifies the indices for all present elements, but
  12183. // it does avoid iterating over every undefined entry.
  12184. var map = this._map;
  12185. var length = map.length;
  12186. var i;
  12187. if (length <= 0x10000) {
  12188. for (i = 0; i < length; i++) {
  12189. if (map[i] !== undefined) {
  12190. callback(i, map[i]);
  12191. }
  12192. }
  12193. } else {
  12194. for (i in this._map) {
  12195. callback(i, map[i]);
  12196. }
  12197. }
  12198. },
  12199. charCodeOf: function(value) {
  12200. return this._map.indexOf(value);
  12201. },
  12202. getMap: function() {
  12203. return this._map;
  12204. },
  12205. readCharCode: function(str, offset, out) {
  12206. var c = 0;
  12207. var codespaceRanges = this.codespaceRanges;
  12208. var codespaceRangesLen = this.codespaceRanges.length;
  12209. // 9.7.6.2 CMap Mapping
  12210. // The code length is at most 4.
  12211. for (var n = 0; n < codespaceRangesLen; n++) {
  12212. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12213. // Check each codespace range to see if it falls within.
  12214. var codespaceRange = codespaceRanges[n];
  12215. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12216. var low = codespaceRange[k++];
  12217. var high = codespaceRange[k++];
  12218. if (c >= low && c <= high) {
  12219. out.charcode = c;
  12220. out.length = n + 1;
  12221. return;
  12222. }
  12223. }
  12224. }
  12225. out.charcode = 0;
  12226. out.length = 1;
  12227. }
  12228. };
  12229. return CMap;
  12230. })();
  12231. // A special case of CMap, where the _map array implicitly has a length of
  12232. // 65535 and each element is equal to its index.
  12233. var IdentityCMap = (function IdentityCMapClosure() {
  12234. function IdentityCMap(vertical, n) {
  12235. CMap.call(this);
  12236. this.vertical = vertical;
  12237. this.addCodespaceRange(n, 0, 0xffff);
  12238. }
  12239. Util.inherit(IdentityCMap, CMap, {});
  12240. IdentityCMap.prototype = {
  12241. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12242. mapCidRange: function(low, high, dstLow) {
  12243. error('should not call mapCidRange');
  12244. },
  12245. mapBfRange: function(low, high, dstLow) {
  12246. error('should not call mapBfRange');
  12247. },
  12248. mapBfRangeToArray: function(low, high, array) {
  12249. error('should not call mapBfRangeToArray');
  12250. },
  12251. mapOne: function(src, dst) {
  12252. error('should not call mapCidOne');
  12253. },
  12254. lookup: function(code) {
  12255. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12256. },
  12257. contains: function(code) {
  12258. return isInt(code) && code <= 0xffff;
  12259. },
  12260. forEach: function(callback) {
  12261. for (var i = 0; i <= 0xffff; i++) {
  12262. callback(i, i);
  12263. }
  12264. },
  12265. charCodeOf: function(value) {
  12266. return (isInt(value) && value <= 0xffff) ? value : -1;
  12267. },
  12268. getMap: function() {
  12269. // Sometimes identity maps must be instantiated, but it's rare.
  12270. var map = new Array(0x10000);
  12271. for (var i = 0; i <= 0xffff; i++) {
  12272. map[i] = i;
  12273. }
  12274. return map;
  12275. },
  12276. readCharCode: CMap.prototype.readCharCode
  12277. };
  12278. return IdentityCMap;
  12279. })();
  12280. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12281. function fetchBinaryData(url) {
  12282. var nonBinaryRequest = PDFJS.disableWorker;
  12283. var request = new XMLHttpRequest();
  12284. request.open('GET', url, false);
  12285. if (!nonBinaryRequest) {
  12286. try {
  12287. request.responseType = 'arraybuffer';
  12288. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12289. } catch (e) {
  12290. nonBinaryRequest = true;
  12291. }
  12292. }
  12293. if (nonBinaryRequest && request.overrideMimeType) {
  12294. request.overrideMimeType('text/plain; charset=x-user-defined');
  12295. }
  12296. request.send(null);
  12297. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12298. error('Unable to get binary cMap at: ' + url);
  12299. }
  12300. if (nonBinaryRequest) {
  12301. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12302. return ch.charCodeAt(0) & 255;
  12303. });
  12304. return new Uint8Array(data);
  12305. }
  12306. return new Uint8Array(request.response);
  12307. }
  12308. function hexToInt(a, size) {
  12309. var n = 0;
  12310. for (var i = 0; i <= size; i++) {
  12311. n = (n << 8) | a[i];
  12312. }
  12313. return n >>> 0;
  12314. }
  12315. function hexToStr(a, size) {
  12316. // This code is hot. Special-case some common values to avoid creating an
  12317. // object with subarray().
  12318. if (size === 1) {
  12319. return String.fromCharCode(a[0], a[1]);
  12320. }
  12321. if (size === 3) {
  12322. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12323. }
  12324. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12325. }
  12326. function addHex(a, b, size) {
  12327. var c = 0;
  12328. for (var i = size; i >= 0; i--) {
  12329. c += a[i] + b[i];
  12330. a[i] = c & 255;
  12331. c >>= 8;
  12332. }
  12333. }
  12334. function incHex(a, size) {
  12335. var c = 1;
  12336. for (var i = size; i >= 0 && c > 0; i--) {
  12337. c += a[i];
  12338. a[i] = c & 255;
  12339. c >>= 8;
  12340. }
  12341. }
  12342. var MAX_NUM_SIZE = 16;
  12343. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12344. function BinaryCMapStream(data) {
  12345. this.buffer = data;
  12346. this.pos = 0;
  12347. this.end = data.length;
  12348. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12349. }
  12350. BinaryCMapStream.prototype = {
  12351. readByte: function () {
  12352. if (this.pos >= this.end) {
  12353. return -1;
  12354. }
  12355. return this.buffer[this.pos++];
  12356. },
  12357. readNumber: function () {
  12358. var n = 0;
  12359. var last;
  12360. do {
  12361. var b = this.readByte();
  12362. if (b < 0) {
  12363. error('unexpected EOF in bcmap');
  12364. }
  12365. last = !(b & 0x80);
  12366. n = (n << 7) | (b & 0x7F);
  12367. } while (!last);
  12368. return n;
  12369. },
  12370. readSigned: function () {
  12371. var n = this.readNumber();
  12372. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12373. },
  12374. readHex: function (num, size) {
  12375. num.set(this.buffer.subarray(this.pos,
  12376. this.pos + size + 1));
  12377. this.pos += size + 1;
  12378. },
  12379. readHexNumber: function (num, size) {
  12380. var last;
  12381. var stack = this.tmpBuf, sp = 0;
  12382. do {
  12383. var b = this.readByte();
  12384. if (b < 0) {
  12385. error('unexpected EOF in bcmap');
  12386. }
  12387. last = !(b & 0x80);
  12388. stack[sp++] = b & 0x7F;
  12389. } while (!last);
  12390. var i = size, buffer = 0, bufferSize = 0;
  12391. while (i >= 0) {
  12392. while (bufferSize < 8 && stack.length > 0) {
  12393. buffer = (stack[--sp] << bufferSize) | buffer;
  12394. bufferSize += 7;
  12395. }
  12396. num[i] = buffer & 255;
  12397. i--;
  12398. buffer >>= 8;
  12399. bufferSize -= 8;
  12400. }
  12401. },
  12402. readHexSigned: function (num, size) {
  12403. this.readHexNumber(num, size);
  12404. var sign = num[size] & 1 ? 255 : 0;
  12405. var c = 0;
  12406. for (var i = 0; i <= size; i++) {
  12407. c = ((c & 1) << 8) | num[i];
  12408. num[i] = (c >> 1) ^ sign;
  12409. }
  12410. },
  12411. readString: function () {
  12412. var len = this.readNumber();
  12413. var s = '';
  12414. for (var i = 0; i < len; i++) {
  12415. s += String.fromCharCode(this.readNumber());
  12416. }
  12417. return s;
  12418. }
  12419. };
  12420. function processBinaryCMap(url, cMap, extend) {
  12421. var data = fetchBinaryData(url);
  12422. var stream = new BinaryCMapStream(data);
  12423. var header = stream.readByte();
  12424. cMap.vertical = !!(header & 1);
  12425. var useCMap = null;
  12426. var start = new Uint8Array(MAX_NUM_SIZE);
  12427. var end = new Uint8Array(MAX_NUM_SIZE);
  12428. var char = new Uint8Array(MAX_NUM_SIZE);
  12429. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12430. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12431. var code;
  12432. var b;
  12433. while ((b = stream.readByte()) >= 0) {
  12434. var type = b >> 5;
  12435. if (type === 7) { // metadata, e.g. comment or usecmap
  12436. switch (b & 0x1F) {
  12437. case 0:
  12438. stream.readString(); // skipping comment
  12439. break;
  12440. case 1:
  12441. useCMap = stream.readString();
  12442. break;
  12443. }
  12444. continue;
  12445. }
  12446. var sequence = !!(b & 0x10);
  12447. var dataSize = b & 15;
  12448. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12449. var ucs2DataSize = 1;
  12450. var subitemsCount = stream.readNumber();
  12451. var i;
  12452. switch (type) {
  12453. case 0: // codespacerange
  12454. stream.readHex(start, dataSize);
  12455. stream.readHexNumber(end, dataSize);
  12456. addHex(end, start, dataSize);
  12457. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12458. hexToInt(end, dataSize));
  12459. for (i = 1; i < subitemsCount; i++) {
  12460. incHex(end, dataSize);
  12461. stream.readHexNumber(start, dataSize);
  12462. addHex(start, end, dataSize);
  12463. stream.readHexNumber(end, dataSize);
  12464. addHex(end, start, dataSize);
  12465. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12466. hexToInt(end, dataSize));
  12467. }
  12468. break;
  12469. case 1: // notdefrange
  12470. stream.readHex(start, dataSize);
  12471. stream.readHexNumber(end, dataSize);
  12472. addHex(end, start, dataSize);
  12473. code = stream.readNumber();
  12474. // undefined range, skipping
  12475. for (i = 1; i < subitemsCount; i++) {
  12476. incHex(end, dataSize);
  12477. stream.readHexNumber(start, dataSize);
  12478. addHex(start, end, dataSize);
  12479. stream.readHexNumber(end, dataSize);
  12480. addHex(end, start, dataSize);
  12481. code = stream.readNumber();
  12482. // nop
  12483. }
  12484. break;
  12485. case 2: // cidchar
  12486. stream.readHex(char, dataSize);
  12487. code = stream.readNumber();
  12488. cMap.mapOne(hexToInt(char, dataSize), code);
  12489. for (i = 1; i < subitemsCount; i++) {
  12490. incHex(char, dataSize);
  12491. if (!sequence) {
  12492. stream.readHexNumber(tmp, dataSize);
  12493. addHex(char, tmp, dataSize);
  12494. }
  12495. code = stream.readSigned() + (code + 1);
  12496. cMap.mapOne(hexToInt(char, dataSize), code);
  12497. }
  12498. break;
  12499. case 3: // cidrange
  12500. stream.readHex(start, dataSize);
  12501. stream.readHexNumber(end, dataSize);
  12502. addHex(end, start, dataSize);
  12503. code = stream.readNumber();
  12504. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12505. code);
  12506. for (i = 1; i < subitemsCount; i++) {
  12507. incHex(end, dataSize);
  12508. if (!sequence) {
  12509. stream.readHexNumber(start, dataSize);
  12510. addHex(start, end, dataSize);
  12511. } else {
  12512. start.set(end);
  12513. }
  12514. stream.readHexNumber(end, dataSize);
  12515. addHex(end, start, dataSize);
  12516. code = stream.readNumber();
  12517. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12518. code);
  12519. }
  12520. break;
  12521. case 4: // bfchar
  12522. stream.readHex(char, ucs2DataSize);
  12523. stream.readHex(charCode, dataSize);
  12524. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12525. hexToStr(charCode, dataSize));
  12526. for (i = 1; i < subitemsCount; i++) {
  12527. incHex(char, ucs2DataSize);
  12528. if (!sequence) {
  12529. stream.readHexNumber(tmp, ucs2DataSize);
  12530. addHex(char, tmp, ucs2DataSize);
  12531. }
  12532. incHex(charCode, dataSize);
  12533. stream.readHexSigned(tmp, dataSize);
  12534. addHex(charCode, tmp, dataSize);
  12535. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12536. hexToStr(charCode, dataSize));
  12537. }
  12538. break;
  12539. case 5: // bfrange
  12540. stream.readHex(start, ucs2DataSize);
  12541. stream.readHexNumber(end, ucs2DataSize);
  12542. addHex(end, start, ucs2DataSize);
  12543. stream.readHex(charCode, dataSize);
  12544. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12545. hexToInt(end, ucs2DataSize),
  12546. hexToStr(charCode, dataSize));
  12547. for (i = 1; i < subitemsCount; i++) {
  12548. incHex(end, ucs2DataSize);
  12549. if (!sequence) {
  12550. stream.readHexNumber(start, ucs2DataSize);
  12551. addHex(start, end, ucs2DataSize);
  12552. } else {
  12553. start.set(end);
  12554. }
  12555. stream.readHexNumber(end, ucs2DataSize);
  12556. addHex(end, start, ucs2DataSize);
  12557. stream.readHex(charCode, dataSize);
  12558. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12559. hexToInt(end, ucs2DataSize),
  12560. hexToStr(charCode, dataSize));
  12561. }
  12562. break;
  12563. default:
  12564. error('Unknown type: ' + type);
  12565. break;
  12566. }
  12567. }
  12568. if (useCMap) {
  12569. extend(useCMap);
  12570. }
  12571. return cMap;
  12572. }
  12573. function BinaryCMapReader() {}
  12574. BinaryCMapReader.prototype = {
  12575. read: processBinaryCMap
  12576. };
  12577. return BinaryCMapReader;
  12578. })();
  12579. var CMapFactory = (function CMapFactoryClosure() {
  12580. function strToInt(str) {
  12581. var a = 0;
  12582. for (var i = 0; i < str.length; i++) {
  12583. a = (a << 8) | str.charCodeAt(i);
  12584. }
  12585. return a >>> 0;
  12586. }
  12587. function expectString(obj) {
  12588. if (!isString(obj)) {
  12589. error('Malformed CMap: expected string.');
  12590. }
  12591. }
  12592. function expectInt(obj) {
  12593. if (!isInt(obj)) {
  12594. error('Malformed CMap: expected int.');
  12595. }
  12596. }
  12597. function parseBfChar(cMap, lexer) {
  12598. while (true) {
  12599. var obj = lexer.getObj();
  12600. if (isEOF(obj)) {
  12601. break;
  12602. }
  12603. if (isCmd(obj, 'endbfchar')) {
  12604. return;
  12605. }
  12606. expectString(obj);
  12607. var src = strToInt(obj);
  12608. obj = lexer.getObj();
  12609. // TODO are /dstName used?
  12610. expectString(obj);
  12611. var dst = obj;
  12612. cMap.mapOne(src, dst);
  12613. }
  12614. }
  12615. function parseBfRange(cMap, lexer) {
  12616. while (true) {
  12617. var obj = lexer.getObj();
  12618. if (isEOF(obj)) {
  12619. break;
  12620. }
  12621. if (isCmd(obj, 'endbfrange')) {
  12622. return;
  12623. }
  12624. expectString(obj);
  12625. var low = strToInt(obj);
  12626. obj = lexer.getObj();
  12627. expectString(obj);
  12628. var high = strToInt(obj);
  12629. obj = lexer.getObj();
  12630. if (isInt(obj) || isString(obj)) {
  12631. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12632. cMap.mapBfRange(low, high, dstLow);
  12633. } else if (isCmd(obj, '[')) {
  12634. obj = lexer.getObj();
  12635. var array = [];
  12636. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12637. array.push(obj);
  12638. obj = lexer.getObj();
  12639. }
  12640. cMap.mapBfRangeToArray(low, high, array);
  12641. } else {
  12642. break;
  12643. }
  12644. }
  12645. error('Invalid bf range.');
  12646. }
  12647. function parseCidChar(cMap, lexer) {
  12648. while (true) {
  12649. var obj = lexer.getObj();
  12650. if (isEOF(obj)) {
  12651. break;
  12652. }
  12653. if (isCmd(obj, 'endcidchar')) {
  12654. return;
  12655. }
  12656. expectString(obj);
  12657. var src = strToInt(obj);
  12658. obj = lexer.getObj();
  12659. expectInt(obj);
  12660. var dst = obj;
  12661. cMap.mapOne(src, dst);
  12662. }
  12663. }
  12664. function parseCidRange(cMap, lexer) {
  12665. while (true) {
  12666. var obj = lexer.getObj();
  12667. if (isEOF(obj)) {
  12668. break;
  12669. }
  12670. if (isCmd(obj, 'endcidrange')) {
  12671. return;
  12672. }
  12673. expectString(obj);
  12674. var low = strToInt(obj);
  12675. obj = lexer.getObj();
  12676. expectString(obj);
  12677. var high = strToInt(obj);
  12678. obj = lexer.getObj();
  12679. expectInt(obj);
  12680. var dstLow = obj;
  12681. cMap.mapCidRange(low, high, dstLow);
  12682. }
  12683. }
  12684. function parseCodespaceRange(cMap, lexer) {
  12685. while (true) {
  12686. var obj = lexer.getObj();
  12687. if (isEOF(obj)) {
  12688. break;
  12689. }
  12690. if (isCmd(obj, 'endcodespacerange')) {
  12691. return;
  12692. }
  12693. if (!isString(obj)) {
  12694. break;
  12695. }
  12696. var low = strToInt(obj);
  12697. obj = lexer.getObj();
  12698. if (!isString(obj)) {
  12699. break;
  12700. }
  12701. var high = strToInt(obj);
  12702. cMap.addCodespaceRange(obj.length, low, high);
  12703. }
  12704. error('Invalid codespace range.');
  12705. }
  12706. function parseWMode(cMap, lexer) {
  12707. var obj = lexer.getObj();
  12708. if (isInt(obj)) {
  12709. cMap.vertical = !!obj;
  12710. }
  12711. }
  12712. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12713. var previous;
  12714. var embededUseCMap;
  12715. objLoop: while (true) {
  12716. var obj = lexer.getObj();
  12717. if (isEOF(obj)) {
  12718. break;
  12719. } else if (isName(obj)) {
  12720. if (obj.name === 'WMode') {
  12721. parseWMode(cMap, lexer);
  12722. }
  12723. previous = obj;
  12724. } else if (isCmd(obj)) {
  12725. switch (obj.cmd) {
  12726. case 'endcmap':
  12727. break objLoop;
  12728. case 'usecmap':
  12729. if (isName(previous)) {
  12730. embededUseCMap = previous.name;
  12731. }
  12732. break;
  12733. case 'begincodespacerange':
  12734. parseCodespaceRange(cMap, lexer);
  12735. break;
  12736. case 'beginbfchar':
  12737. parseBfChar(cMap, lexer);
  12738. break;
  12739. case 'begincidchar':
  12740. parseCidChar(cMap, lexer);
  12741. break;
  12742. case 'beginbfrange':
  12743. parseBfRange(cMap, lexer);
  12744. break;
  12745. case 'begincidrange':
  12746. parseCidRange(cMap, lexer);
  12747. break;
  12748. }
  12749. }
  12750. }
  12751. if (!useCMap && embededUseCMap) {
  12752. // Load the usecmap definition from the file only if there wasn't one
  12753. // specified.
  12754. useCMap = embededUseCMap;
  12755. }
  12756. if (useCMap) {
  12757. extendCMap(cMap, builtInCMapParams, useCMap);
  12758. }
  12759. }
  12760. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12761. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12762. // If there aren't any code space ranges defined clone all the parent ones
  12763. // into this cMap.
  12764. if (cMap.numCodespaceRanges === 0) {
  12765. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12766. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12767. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12768. }
  12769. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12770. }
  12771. // Merge the map into the current one, making sure not to override
  12772. // any previously defined entries.
  12773. cMap.useCMap.forEach(function(key, value) {
  12774. if (!cMap.contains(key)) {
  12775. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12776. }
  12777. });
  12778. }
  12779. function parseBinaryCMap(name, builtInCMapParams) {
  12780. var url = builtInCMapParams.url + name + '.bcmap';
  12781. var cMap = new CMap(true);
  12782. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12783. extendCMap(cMap, builtInCMapParams, useCMap);
  12784. });
  12785. return cMap;
  12786. }
  12787. function createBuiltInCMap(name, builtInCMapParams) {
  12788. if (name === 'Identity-H') {
  12789. return new IdentityCMap(false, 2);
  12790. } else if (name === 'Identity-V') {
  12791. return new IdentityCMap(true, 2);
  12792. }
  12793. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12794. error('Unknown cMap name: ' + name);
  12795. }
  12796. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12797. if (builtInCMapParams.packed) {
  12798. return parseBinaryCMap(name, builtInCMapParams);
  12799. }
  12800. var request = new XMLHttpRequest();
  12801. var url = builtInCMapParams.url + name;
  12802. request.open('GET', url, false);
  12803. request.send(null);
  12804. if (!request.responseText) {
  12805. error('Unable to get cMap at: ' + url);
  12806. }
  12807. var cMap = new CMap(true);
  12808. var lexer = new Lexer(new StringStream(request.responseText));
  12809. parseCMap(cMap, lexer, builtInCMapParams, null);
  12810. return cMap;
  12811. }
  12812. return {
  12813. create: function (encoding, builtInCMapParams, useCMap) {
  12814. if (isName(encoding)) {
  12815. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12816. } else if (isStream(encoding)) {
  12817. var cMap = new CMap();
  12818. var lexer = new Lexer(encoding);
  12819. try {
  12820. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12821. } catch (e) {
  12822. warn('Invalid CMap data. ' + e);
  12823. }
  12824. return cMap;
  12825. }
  12826. error('Encoding required.');
  12827. }
  12828. };
  12829. })();
  12830. // Unicode Private Use Area
  12831. var PRIVATE_USE_OFFSET_START = 0xE000;
  12832. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12833. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12834. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12835. // except for Type 3 fonts
  12836. var PDF_GLYPH_SPACE_UNITS = 1000;
  12837. // Hinting is currently disabled due to unknown problems on windows
  12838. // in tracemonkey and various other pdfs with type1 fonts.
  12839. var HINTING_ENABLED = false;
  12840. // Accented charactars are not displayed properly on windows, using this flag
  12841. // to control analysis of seac charstrings.
  12842. var SEAC_ANALYSIS_ENABLED = false;
  12843. var FontFlags = {
  12844. FixedPitch: 1,
  12845. Serif: 2,
  12846. Symbolic: 4,
  12847. Script: 8,
  12848. Nonsymbolic: 32,
  12849. Italic: 64,
  12850. AllCap: 65536,
  12851. SmallCap: 131072,
  12852. ForceBold: 262144
  12853. };
  12854. var Encodings = {
  12855. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12856. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12857. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12858. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12859. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12860. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12861. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12862. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12863. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12864. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12865. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12866. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12867. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12868. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12869. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12870. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12871. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12872. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12873. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12874. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12875. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12876. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12877. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12878. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12879. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12880. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12881. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12882. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12883. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12884. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12885. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12886. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12887. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12888. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12889. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12890. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12891. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12892. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12893. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12894. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12895. 'Ydieresissmall'],
  12896. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12897. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12898. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12899. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12900. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12901. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12902. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12903. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12904. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12905. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12906. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12907. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12908. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12909. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12910. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12911. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12912. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12913. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12914. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12915. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12916. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12917. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12918. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12919. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12920. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12921. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12922. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12923. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12924. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12925. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12926. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12927. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12928. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12929. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12930. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12931. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12932. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12933. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12934. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12935. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12936. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12937. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12938. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12939. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12940. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12941. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12942. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12943. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12944. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12945. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12946. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12947. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12948. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12949. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12950. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12951. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12952. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12953. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12954. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12955. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12956. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12957. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12958. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12959. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12960. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12961. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12962. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12963. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12964. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12965. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12966. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12967. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12968. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12969. 'ogonek', 'caron'],
  12970. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12971. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12972. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12973. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12974. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12975. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12976. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12977. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12978. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12979. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12980. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12981. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12982. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12983. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12984. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12985. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12986. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12987. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12988. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12989. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12990. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12991. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12992. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12993. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12994. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12995. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12996. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12997. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12998. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12999. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13000. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13001. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13002. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13003. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13004. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13005. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13006. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13007. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13008. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13009. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13010. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13011. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13012. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13013. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13014. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13015. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13016. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13017. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13018. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13019. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13020. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13021. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13022. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13023. 'germandbls', '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', 'divide', 'oslash',
  13027. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13028. 'ydieresis'],
  13029. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13030. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13031. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13032. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13033. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13034. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13035. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13036. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13037. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13038. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13039. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13040. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13041. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13042. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13043. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13044. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13045. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13046. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13047. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13048. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13049. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13050. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13051. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13052. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13053. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13054. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13055. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13056. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13057. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13058. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13059. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13060. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13061. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13062. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13063. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13064. 'bracerightbt'],
  13065. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13066. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13067. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13068. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13069. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13070. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13071. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13072. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13073. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13074. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13075. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13076. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13077. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13078. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13079. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13080. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13081. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13082. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13083. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13084. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13085. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13086. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13087. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13088. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13089. };
  13090. /**
  13091. * Hold a map of decoded fonts and of the standard fourteen Type1
  13092. * fonts and their acronyms.
  13093. */
  13094. var stdFontMap = {
  13095. 'ArialNarrow': 'Helvetica',
  13096. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13097. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13098. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13099. 'ArialBlack': 'Helvetica',
  13100. 'ArialBlack-Bold': 'Helvetica-Bold',
  13101. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13102. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13103. 'Arial': 'Helvetica',
  13104. 'Arial-Bold': 'Helvetica-Bold',
  13105. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13106. 'Arial-Italic': 'Helvetica-Oblique',
  13107. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13108. 'Arial-BoldMT': 'Helvetica-Bold',
  13109. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13110. 'ArialMT': 'Helvetica',
  13111. 'Courier-Bold': 'Courier-Bold',
  13112. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13113. 'Courier-Italic': 'Courier-Oblique',
  13114. 'CourierNew': 'Courier',
  13115. 'CourierNew-Bold': 'Courier-Bold',
  13116. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13117. 'CourierNew-Italic': 'Courier-Oblique',
  13118. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13119. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13120. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13121. 'CourierNewPSMT': 'Courier',
  13122. 'Helvetica': 'Helvetica',
  13123. 'Helvetica-Bold': 'Helvetica-Bold',
  13124. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13125. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13126. 'Helvetica-Italic': 'Helvetica-Oblique',
  13127. 'Helvetica-Oblique':'Helvetica-Oblique',
  13128. 'Symbol-Bold': 'Symbol',
  13129. 'Symbol-BoldItalic': 'Symbol',
  13130. 'Symbol-Italic': 'Symbol',
  13131. 'TimesNewRoman': 'Times-Roman',
  13132. 'TimesNewRoman-Bold': 'Times-Bold',
  13133. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13134. 'TimesNewRoman-Italic': 'Times-Italic',
  13135. 'TimesNewRomanPS': 'Times-Roman',
  13136. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13137. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13138. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13139. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13140. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13141. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13142. 'TimesNewRomanPSMT': 'Times-Roman',
  13143. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13144. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13145. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13146. };
  13147. /**
  13148. * Holds the map of the non-standard fonts that might be included as a standard
  13149. * fonts without glyph data.
  13150. */
  13151. var nonStdFontMap = {
  13152. 'CenturyGothic': 'Helvetica',
  13153. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13154. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13155. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13156. 'ComicSansMS': 'Comic Sans MS',
  13157. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13158. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13159. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13160. 'LucidaConsole': 'Courier',
  13161. 'LucidaConsole-Bold': 'Courier-Bold',
  13162. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13163. 'LucidaConsole-Italic': 'Courier-Oblique',
  13164. 'MS-Gothic': 'MS Gothic',
  13165. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13166. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13167. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13168. 'MS-Mincho': 'MS Mincho',
  13169. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13170. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13171. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13172. 'MS-PGothic': 'MS PGothic',
  13173. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13174. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13175. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13176. 'MS-PMincho': 'MS PMincho',
  13177. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13178. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13179. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13180. 'Wingdings': 'ZapfDingbats'
  13181. };
  13182. var serifFonts = {
  13183. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13184. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13185. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13186. 'Arno': true, 'Aster': true, 'Aurora': true,
  13187. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13188. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13189. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13190. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13191. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13192. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13193. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13194. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13195. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13196. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13197. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13198. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13199. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13200. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13201. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13202. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13203. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13204. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13205. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13206. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13207. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13208. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13209. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13210. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13211. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13212. 'Miller': true, 'Minion': true, 'Modern': true,
  13213. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13214. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13215. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13216. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13217. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13218. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13219. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13220. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13221. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13222. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13223. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13224. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13225. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13226. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13227. };
  13228. var symbolsFonts = {
  13229. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13230. };
  13231. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13232. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13233. // glyphs, but common for some set of the standard fonts.
  13234. var GlyphMapForStandardFonts = {
  13235. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13236. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13237. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13238. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13239. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13240. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13241. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13242. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13243. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13244. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13245. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13246. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13247. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13248. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13249. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13250. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13251. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13252. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13253. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13254. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13255. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13256. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13257. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13258. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13259. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13260. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13261. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13262. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13263. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13264. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13265. '298': 380, '305': 963,
  13266. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13267. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13268. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13269. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13270. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13271. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13272. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13273. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13274. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13275. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13276. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13277. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13278. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13279. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13280. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13281. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13282. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13283. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13284. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13285. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13286. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13287. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13288. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13289. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13290. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13291. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13292. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13293. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13294. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13295. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13296. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13297. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13298. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13299. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13300. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13301. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13302. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13303. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13304. };
  13305. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13306. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13307. // to the similar equivalents in the normal characters range.
  13308. var SpecialPUASymbols = {
  13309. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13310. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13311. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13312. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13313. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13314. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13315. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13316. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13317. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13318. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13319. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13320. '63742': 0x23AD, // bracerightmid (0xF8FE)
  13321. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13322. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13323. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13324. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13325. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13326. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13327. '63723': 0x239B, // parenlefttp (0xF8EB)
  13328. '63724': 0x239C, // parenleftex (0xF8EC)
  13329. '63725': 0x239D, // parenleftbt (0xF8ED)
  13330. '63734': 0x239E, // parenrighttp (0xF8F6)
  13331. '63735': 0x239F, // parenrightex (0xF8F7)
  13332. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13333. };
  13334. function mapSpecialUnicodeValues(code) {
  13335. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13336. return 0;
  13337. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13338. return (SpecialPUASymbols[code] || code);
  13339. }
  13340. return code;
  13341. }
  13342. var UnicodeRanges = [
  13343. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13344. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13345. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13346. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13347. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13348. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13349. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13350. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13351. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13352. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13353. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13354. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13355. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13356. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13357. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13358. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13359. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13360. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13361. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13362. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13363. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13364. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13365. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13366. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13367. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13368. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13369. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13370. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13371. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13372. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13373. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13374. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13375. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13376. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13377. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13378. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13379. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13380. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13381. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13382. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13383. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13384. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13385. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13386. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13387. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13388. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13389. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13390. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13391. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13392. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13393. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13394. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13395. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13396. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13397. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13398. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13399. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13400. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13401. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13402. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13403. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13404. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13405. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13406. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13407. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13408. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13409. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13410. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13411. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13412. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13413. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13414. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13415. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13416. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13417. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13418. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13419. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13420. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13421. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13422. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13423. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13424. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13425. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13426. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13427. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13428. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13429. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13430. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13431. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13432. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13433. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13434. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13435. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13436. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13437. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13438. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13439. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13440. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13441. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13442. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13443. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13444. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13445. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13446. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13447. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13448. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13449. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13450. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13451. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13452. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13453. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13454. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13455. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13456. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13457. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13458. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13459. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13460. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13461. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13462. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13463. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13464. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13465. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13466. ];
  13467. var MacStandardGlyphOrdering = [
  13468. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13469. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13470. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13471. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13472. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13473. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13474. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13475. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13476. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13477. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13478. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13479. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13480. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13481. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13482. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13483. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13484. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13485. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13486. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13487. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13488. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13489. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13490. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13491. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13492. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13493. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13494. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13495. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13496. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13497. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13498. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13499. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13500. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13501. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13502. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13503. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13504. function getUnicodeRangeFor(value) {
  13505. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13506. var range = UnicodeRanges[i];
  13507. if (value >= range.begin && value < range.end) {
  13508. return i;
  13509. }
  13510. }
  13511. return -1;
  13512. }
  13513. function isRTLRangeFor(value) {
  13514. var range = UnicodeRanges[13];
  13515. if (value >= range.begin && value < range.end) {
  13516. return true;
  13517. }
  13518. range = UnicodeRanges[11];
  13519. if (value >= range.begin && value < range.end) {
  13520. return true;
  13521. }
  13522. return false;
  13523. }
  13524. // The normalization table is obtained by filtering the Unicode characters
  13525. // database with <compat> entries.
  13526. var NormalizedUnicodes = {
  13527. '\u00A8': '\u0020\u0308',
  13528. '\u00AF': '\u0020\u0304',
  13529. '\u00B4': '\u0020\u0301',
  13530. '\u00B5': '\u03BC',
  13531. '\u00B8': '\u0020\u0327',
  13532. '\u0132': '\u0049\u004A',
  13533. '\u0133': '\u0069\u006A',
  13534. '\u013F': '\u004C\u00B7',
  13535. '\u0140': '\u006C\u00B7',
  13536. '\u0149': '\u02BC\u006E',
  13537. '\u017F': '\u0073',
  13538. '\u01C4': '\u0044\u017D',
  13539. '\u01C5': '\u0044\u017E',
  13540. '\u01C6': '\u0064\u017E',
  13541. '\u01C7': '\u004C\u004A',
  13542. '\u01C8': '\u004C\u006A',
  13543. '\u01C9': '\u006C\u006A',
  13544. '\u01CA': '\u004E\u004A',
  13545. '\u01CB': '\u004E\u006A',
  13546. '\u01CC': '\u006E\u006A',
  13547. '\u01F1': '\u0044\u005A',
  13548. '\u01F2': '\u0044\u007A',
  13549. '\u01F3': '\u0064\u007A',
  13550. '\u02D8': '\u0020\u0306',
  13551. '\u02D9': '\u0020\u0307',
  13552. '\u02DA': '\u0020\u030A',
  13553. '\u02DB': '\u0020\u0328',
  13554. '\u02DC': '\u0020\u0303',
  13555. '\u02DD': '\u0020\u030B',
  13556. '\u037A': '\u0020\u0345',
  13557. '\u0384': '\u0020\u0301',
  13558. '\u03D0': '\u03B2',
  13559. '\u03D1': '\u03B8',
  13560. '\u03D2': '\u03A5',
  13561. '\u03D5': '\u03C6',
  13562. '\u03D6': '\u03C0',
  13563. '\u03F0': '\u03BA',
  13564. '\u03F1': '\u03C1',
  13565. '\u03F2': '\u03C2',
  13566. '\u03F4': '\u0398',
  13567. '\u03F5': '\u03B5',
  13568. '\u03F9': '\u03A3',
  13569. '\u0587': '\u0565\u0582',
  13570. '\u0675': '\u0627\u0674',
  13571. '\u0676': '\u0648\u0674',
  13572. '\u0677': '\u06C7\u0674',
  13573. '\u0678': '\u064A\u0674',
  13574. '\u0E33': '\u0E4D\u0E32',
  13575. '\u0EB3': '\u0ECD\u0EB2',
  13576. '\u0EDC': '\u0EAB\u0E99',
  13577. '\u0EDD': '\u0EAB\u0EA1',
  13578. '\u0F77': '\u0FB2\u0F81',
  13579. '\u0F79': '\u0FB3\u0F81',
  13580. '\u1E9A': '\u0061\u02BE',
  13581. '\u1FBD': '\u0020\u0313',
  13582. '\u1FBF': '\u0020\u0313',
  13583. '\u1FC0': '\u0020\u0342',
  13584. '\u1FFE': '\u0020\u0314',
  13585. '\u2002': '\u0020',
  13586. '\u2003': '\u0020',
  13587. '\u2004': '\u0020',
  13588. '\u2005': '\u0020',
  13589. '\u2006': '\u0020',
  13590. '\u2008': '\u0020',
  13591. '\u2009': '\u0020',
  13592. '\u200A': '\u0020',
  13593. '\u2017': '\u0020\u0333',
  13594. '\u2024': '\u002E',
  13595. '\u2025': '\u002E\u002E',
  13596. '\u2026': '\u002E\u002E\u002E',
  13597. '\u2033': '\u2032\u2032',
  13598. '\u2034': '\u2032\u2032\u2032',
  13599. '\u2036': '\u2035\u2035',
  13600. '\u2037': '\u2035\u2035\u2035',
  13601. '\u203C': '\u0021\u0021',
  13602. '\u203E': '\u0020\u0305',
  13603. '\u2047': '\u003F\u003F',
  13604. '\u2048': '\u003F\u0021',
  13605. '\u2049': '\u0021\u003F',
  13606. '\u2057': '\u2032\u2032\u2032\u2032',
  13607. '\u205F': '\u0020',
  13608. '\u20A8': '\u0052\u0073',
  13609. '\u2100': '\u0061\u002F\u0063',
  13610. '\u2101': '\u0061\u002F\u0073',
  13611. '\u2103': '\u00B0\u0043',
  13612. '\u2105': '\u0063\u002F\u006F',
  13613. '\u2106': '\u0063\u002F\u0075',
  13614. '\u2107': '\u0190',
  13615. '\u2109': '\u00B0\u0046',
  13616. '\u2116': '\u004E\u006F',
  13617. '\u2121': '\u0054\u0045\u004C',
  13618. '\u2135': '\u05D0',
  13619. '\u2136': '\u05D1',
  13620. '\u2137': '\u05D2',
  13621. '\u2138': '\u05D3',
  13622. '\u213B': '\u0046\u0041\u0058',
  13623. '\u2160': '\u0049',
  13624. '\u2161': '\u0049\u0049',
  13625. '\u2162': '\u0049\u0049\u0049',
  13626. '\u2163': '\u0049\u0056',
  13627. '\u2164': '\u0056',
  13628. '\u2165': '\u0056\u0049',
  13629. '\u2166': '\u0056\u0049\u0049',
  13630. '\u2167': '\u0056\u0049\u0049\u0049',
  13631. '\u2168': '\u0049\u0058',
  13632. '\u2169': '\u0058',
  13633. '\u216A': '\u0058\u0049',
  13634. '\u216B': '\u0058\u0049\u0049',
  13635. '\u216C': '\u004C',
  13636. '\u216D': '\u0043',
  13637. '\u216E': '\u0044',
  13638. '\u216F': '\u004D',
  13639. '\u2170': '\u0069',
  13640. '\u2171': '\u0069\u0069',
  13641. '\u2172': '\u0069\u0069\u0069',
  13642. '\u2173': '\u0069\u0076',
  13643. '\u2174': '\u0076',
  13644. '\u2175': '\u0076\u0069',
  13645. '\u2176': '\u0076\u0069\u0069',
  13646. '\u2177': '\u0076\u0069\u0069\u0069',
  13647. '\u2178': '\u0069\u0078',
  13648. '\u2179': '\u0078',
  13649. '\u217A': '\u0078\u0069',
  13650. '\u217B': '\u0078\u0069\u0069',
  13651. '\u217C': '\u006C',
  13652. '\u217D': '\u0063',
  13653. '\u217E': '\u0064',
  13654. '\u217F': '\u006D',
  13655. '\u222C': '\u222B\u222B',
  13656. '\u222D': '\u222B\u222B\u222B',
  13657. '\u222F': '\u222E\u222E',
  13658. '\u2230': '\u222E\u222E\u222E',
  13659. '\u2474': '\u0028\u0031\u0029',
  13660. '\u2475': '\u0028\u0032\u0029',
  13661. '\u2476': '\u0028\u0033\u0029',
  13662. '\u2477': '\u0028\u0034\u0029',
  13663. '\u2478': '\u0028\u0035\u0029',
  13664. '\u2479': '\u0028\u0036\u0029',
  13665. '\u247A': '\u0028\u0037\u0029',
  13666. '\u247B': '\u0028\u0038\u0029',
  13667. '\u247C': '\u0028\u0039\u0029',
  13668. '\u247D': '\u0028\u0031\u0030\u0029',
  13669. '\u247E': '\u0028\u0031\u0031\u0029',
  13670. '\u247F': '\u0028\u0031\u0032\u0029',
  13671. '\u2480': '\u0028\u0031\u0033\u0029',
  13672. '\u2481': '\u0028\u0031\u0034\u0029',
  13673. '\u2482': '\u0028\u0031\u0035\u0029',
  13674. '\u2483': '\u0028\u0031\u0036\u0029',
  13675. '\u2484': '\u0028\u0031\u0037\u0029',
  13676. '\u2485': '\u0028\u0031\u0038\u0029',
  13677. '\u2486': '\u0028\u0031\u0039\u0029',
  13678. '\u2487': '\u0028\u0032\u0030\u0029',
  13679. '\u2488': '\u0031\u002E',
  13680. '\u2489': '\u0032\u002E',
  13681. '\u248A': '\u0033\u002E',
  13682. '\u248B': '\u0034\u002E',
  13683. '\u248C': '\u0035\u002E',
  13684. '\u248D': '\u0036\u002E',
  13685. '\u248E': '\u0037\u002E',
  13686. '\u248F': '\u0038\u002E',
  13687. '\u2490': '\u0039\u002E',
  13688. '\u2491': '\u0031\u0030\u002E',
  13689. '\u2492': '\u0031\u0031\u002E',
  13690. '\u2493': '\u0031\u0032\u002E',
  13691. '\u2494': '\u0031\u0033\u002E',
  13692. '\u2495': '\u0031\u0034\u002E',
  13693. '\u2496': '\u0031\u0035\u002E',
  13694. '\u2497': '\u0031\u0036\u002E',
  13695. '\u2498': '\u0031\u0037\u002E',
  13696. '\u2499': '\u0031\u0038\u002E',
  13697. '\u249A': '\u0031\u0039\u002E',
  13698. '\u249B': '\u0032\u0030\u002E',
  13699. '\u249C': '\u0028\u0061\u0029',
  13700. '\u249D': '\u0028\u0062\u0029',
  13701. '\u249E': '\u0028\u0063\u0029',
  13702. '\u249F': '\u0028\u0064\u0029',
  13703. '\u24A0': '\u0028\u0065\u0029',
  13704. '\u24A1': '\u0028\u0066\u0029',
  13705. '\u24A2': '\u0028\u0067\u0029',
  13706. '\u24A3': '\u0028\u0068\u0029',
  13707. '\u24A4': '\u0028\u0069\u0029',
  13708. '\u24A5': '\u0028\u006A\u0029',
  13709. '\u24A6': '\u0028\u006B\u0029',
  13710. '\u24A7': '\u0028\u006C\u0029',
  13711. '\u24A8': '\u0028\u006D\u0029',
  13712. '\u24A9': '\u0028\u006E\u0029',
  13713. '\u24AA': '\u0028\u006F\u0029',
  13714. '\u24AB': '\u0028\u0070\u0029',
  13715. '\u24AC': '\u0028\u0071\u0029',
  13716. '\u24AD': '\u0028\u0072\u0029',
  13717. '\u24AE': '\u0028\u0073\u0029',
  13718. '\u24AF': '\u0028\u0074\u0029',
  13719. '\u24B0': '\u0028\u0075\u0029',
  13720. '\u24B1': '\u0028\u0076\u0029',
  13721. '\u24B2': '\u0028\u0077\u0029',
  13722. '\u24B3': '\u0028\u0078\u0029',
  13723. '\u24B4': '\u0028\u0079\u0029',
  13724. '\u24B5': '\u0028\u007A\u0029',
  13725. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13726. '\u2A74': '\u003A\u003A\u003D',
  13727. '\u2A75': '\u003D\u003D',
  13728. '\u2A76': '\u003D\u003D\u003D',
  13729. '\u2E9F': '\u6BCD',
  13730. '\u2EF3': '\u9F9F',
  13731. '\u2F00': '\u4E00',
  13732. '\u2F01': '\u4E28',
  13733. '\u2F02': '\u4E36',
  13734. '\u2F03': '\u4E3F',
  13735. '\u2F04': '\u4E59',
  13736. '\u2F05': '\u4E85',
  13737. '\u2F06': '\u4E8C',
  13738. '\u2F07': '\u4EA0',
  13739. '\u2F08': '\u4EBA',
  13740. '\u2F09': '\u513F',
  13741. '\u2F0A': '\u5165',
  13742. '\u2F0B': '\u516B',
  13743. '\u2F0C': '\u5182',
  13744. '\u2F0D': '\u5196',
  13745. '\u2F0E': '\u51AB',
  13746. '\u2F0F': '\u51E0',
  13747. '\u2F10': '\u51F5',
  13748. '\u2F11': '\u5200',
  13749. '\u2F12': '\u529B',
  13750. '\u2F13': '\u52F9',
  13751. '\u2F14': '\u5315',
  13752. '\u2F15': '\u531A',
  13753. '\u2F16': '\u5338',
  13754. '\u2F17': '\u5341',
  13755. '\u2F18': '\u535C',
  13756. '\u2F19': '\u5369',
  13757. '\u2F1A': '\u5382',
  13758. '\u2F1B': '\u53B6',
  13759. '\u2F1C': '\u53C8',
  13760. '\u2F1D': '\u53E3',
  13761. '\u2F1E': '\u56D7',
  13762. '\u2F1F': '\u571F',
  13763. '\u2F20': '\u58EB',
  13764. '\u2F21': '\u5902',
  13765. '\u2F22': '\u590A',
  13766. '\u2F23': '\u5915',
  13767. '\u2F24': '\u5927',
  13768. '\u2F25': '\u5973',
  13769. '\u2F26': '\u5B50',
  13770. '\u2F27': '\u5B80',
  13771. '\u2F28': '\u5BF8',
  13772. '\u2F29': '\u5C0F',
  13773. '\u2F2A': '\u5C22',
  13774. '\u2F2B': '\u5C38',
  13775. '\u2F2C': '\u5C6E',
  13776. '\u2F2D': '\u5C71',
  13777. '\u2F2E': '\u5DDB',
  13778. '\u2F2F': '\u5DE5',
  13779. '\u2F30': '\u5DF1',
  13780. '\u2F31': '\u5DFE',
  13781. '\u2F32': '\u5E72',
  13782. '\u2F33': '\u5E7A',
  13783. '\u2F34': '\u5E7F',
  13784. '\u2F35': '\u5EF4',
  13785. '\u2F36': '\u5EFE',
  13786. '\u2F37': '\u5F0B',
  13787. '\u2F38': '\u5F13',
  13788. '\u2F39': '\u5F50',
  13789. '\u2F3A': '\u5F61',
  13790. '\u2F3B': '\u5F73',
  13791. '\u2F3C': '\u5FC3',
  13792. '\u2F3D': '\u6208',
  13793. '\u2F3E': '\u6236',
  13794. '\u2F3F': '\u624B',
  13795. '\u2F40': '\u652F',
  13796. '\u2F41': '\u6534',
  13797. '\u2F42': '\u6587',
  13798. '\u2F43': '\u6597',
  13799. '\u2F44': '\u65A4',
  13800. '\u2F45': '\u65B9',
  13801. '\u2F46': '\u65E0',
  13802. '\u2F47': '\u65E5',
  13803. '\u2F48': '\u66F0',
  13804. '\u2F49': '\u6708',
  13805. '\u2F4A': '\u6728',
  13806. '\u2F4B': '\u6B20',
  13807. '\u2F4C': '\u6B62',
  13808. '\u2F4D': '\u6B79',
  13809. '\u2F4E': '\u6BB3',
  13810. '\u2F4F': '\u6BCB',
  13811. '\u2F50': '\u6BD4',
  13812. '\u2F51': '\u6BDB',
  13813. '\u2F52': '\u6C0F',
  13814. '\u2F53': '\u6C14',
  13815. '\u2F54': '\u6C34',
  13816. '\u2F55': '\u706B',
  13817. '\u2F56': '\u722A',
  13818. '\u2F57': '\u7236',
  13819. '\u2F58': '\u723B',
  13820. '\u2F59': '\u723F',
  13821. '\u2F5A': '\u7247',
  13822. '\u2F5B': '\u7259',
  13823. '\u2F5C': '\u725B',
  13824. '\u2F5D': '\u72AC',
  13825. '\u2F5E': '\u7384',
  13826. '\u2F5F': '\u7389',
  13827. '\u2F60': '\u74DC',
  13828. '\u2F61': '\u74E6',
  13829. '\u2F62': '\u7518',
  13830. '\u2F63': '\u751F',
  13831. '\u2F64': '\u7528',
  13832. '\u2F65': '\u7530',
  13833. '\u2F66': '\u758B',
  13834. '\u2F67': '\u7592',
  13835. '\u2F68': '\u7676',
  13836. '\u2F69': '\u767D',
  13837. '\u2F6A': '\u76AE',
  13838. '\u2F6B': '\u76BF',
  13839. '\u2F6C': '\u76EE',
  13840. '\u2F6D': '\u77DB',
  13841. '\u2F6E': '\u77E2',
  13842. '\u2F6F': '\u77F3',
  13843. '\u2F70': '\u793A',
  13844. '\u2F71': '\u79B8',
  13845. '\u2F72': '\u79BE',
  13846. '\u2F73': '\u7A74',
  13847. '\u2F74': '\u7ACB',
  13848. '\u2F75': '\u7AF9',
  13849. '\u2F76': '\u7C73',
  13850. '\u2F77': '\u7CF8',
  13851. '\u2F78': '\u7F36',
  13852. '\u2F79': '\u7F51',
  13853. '\u2F7A': '\u7F8A',
  13854. '\u2F7B': '\u7FBD',
  13855. '\u2F7C': '\u8001',
  13856. '\u2F7D': '\u800C',
  13857. '\u2F7E': '\u8012',
  13858. '\u2F7F': '\u8033',
  13859. '\u2F80': '\u807F',
  13860. '\u2F81': '\u8089',
  13861. '\u2F82': '\u81E3',
  13862. '\u2F83': '\u81EA',
  13863. '\u2F84': '\u81F3',
  13864. '\u2F85': '\u81FC',
  13865. '\u2F86': '\u820C',
  13866. '\u2F87': '\u821B',
  13867. '\u2F88': '\u821F',
  13868. '\u2F89': '\u826E',
  13869. '\u2F8A': '\u8272',
  13870. '\u2F8B': '\u8278',
  13871. '\u2F8C': '\u864D',
  13872. '\u2F8D': '\u866B',
  13873. '\u2F8E': '\u8840',
  13874. '\u2F8F': '\u884C',
  13875. '\u2F90': '\u8863',
  13876. '\u2F91': '\u897E',
  13877. '\u2F92': '\u898B',
  13878. '\u2F93': '\u89D2',
  13879. '\u2F94': '\u8A00',
  13880. '\u2F95': '\u8C37',
  13881. '\u2F96': '\u8C46',
  13882. '\u2F97': '\u8C55',
  13883. '\u2F98': '\u8C78',
  13884. '\u2F99': '\u8C9D',
  13885. '\u2F9A': '\u8D64',
  13886. '\u2F9B': '\u8D70',
  13887. '\u2F9C': '\u8DB3',
  13888. '\u2F9D': '\u8EAB',
  13889. '\u2F9E': '\u8ECA',
  13890. '\u2F9F': '\u8F9B',
  13891. '\u2FA0': '\u8FB0',
  13892. '\u2FA1': '\u8FB5',
  13893. '\u2FA2': '\u9091',
  13894. '\u2FA3': '\u9149',
  13895. '\u2FA4': '\u91C6',
  13896. '\u2FA5': '\u91CC',
  13897. '\u2FA6': '\u91D1',
  13898. '\u2FA7': '\u9577',
  13899. '\u2FA8': '\u9580',
  13900. '\u2FA9': '\u961C',
  13901. '\u2FAA': '\u96B6',
  13902. '\u2FAB': '\u96B9',
  13903. '\u2FAC': '\u96E8',
  13904. '\u2FAD': '\u9751',
  13905. '\u2FAE': '\u975E',
  13906. '\u2FAF': '\u9762',
  13907. '\u2FB0': '\u9769',
  13908. '\u2FB1': '\u97CB',
  13909. '\u2FB2': '\u97ED',
  13910. '\u2FB3': '\u97F3',
  13911. '\u2FB4': '\u9801',
  13912. '\u2FB5': '\u98A8',
  13913. '\u2FB6': '\u98DB',
  13914. '\u2FB7': '\u98DF',
  13915. '\u2FB8': '\u9996',
  13916. '\u2FB9': '\u9999',
  13917. '\u2FBA': '\u99AC',
  13918. '\u2FBB': '\u9AA8',
  13919. '\u2FBC': '\u9AD8',
  13920. '\u2FBD': '\u9ADF',
  13921. '\u2FBE': '\u9B25',
  13922. '\u2FBF': '\u9B2F',
  13923. '\u2FC0': '\u9B32',
  13924. '\u2FC1': '\u9B3C',
  13925. '\u2FC2': '\u9B5A',
  13926. '\u2FC3': '\u9CE5',
  13927. '\u2FC4': '\u9E75',
  13928. '\u2FC5': '\u9E7F',
  13929. '\u2FC6': '\u9EA5',
  13930. '\u2FC7': '\u9EBB',
  13931. '\u2FC8': '\u9EC3',
  13932. '\u2FC9': '\u9ECD',
  13933. '\u2FCA': '\u9ED1',
  13934. '\u2FCB': '\u9EF9',
  13935. '\u2FCC': '\u9EFD',
  13936. '\u2FCD': '\u9F0E',
  13937. '\u2FCE': '\u9F13',
  13938. '\u2FCF': '\u9F20',
  13939. '\u2FD0': '\u9F3B',
  13940. '\u2FD1': '\u9F4A',
  13941. '\u2FD2': '\u9F52',
  13942. '\u2FD3': '\u9F8D',
  13943. '\u2FD4': '\u9F9C',
  13944. '\u2FD5': '\u9FA0',
  13945. '\u3036': '\u3012',
  13946. '\u3038': '\u5341',
  13947. '\u3039': '\u5344',
  13948. '\u303A': '\u5345',
  13949. '\u309B': '\u0020\u3099',
  13950. '\u309C': '\u0020\u309A',
  13951. '\u3131': '\u1100',
  13952. '\u3132': '\u1101',
  13953. '\u3133': '\u11AA',
  13954. '\u3134': '\u1102',
  13955. '\u3135': '\u11AC',
  13956. '\u3136': '\u11AD',
  13957. '\u3137': '\u1103',
  13958. '\u3138': '\u1104',
  13959. '\u3139': '\u1105',
  13960. '\u313A': '\u11B0',
  13961. '\u313B': '\u11B1',
  13962. '\u313C': '\u11B2',
  13963. '\u313D': '\u11B3',
  13964. '\u313E': '\u11B4',
  13965. '\u313F': '\u11B5',
  13966. '\u3140': '\u111A',
  13967. '\u3141': '\u1106',
  13968. '\u3142': '\u1107',
  13969. '\u3143': '\u1108',
  13970. '\u3144': '\u1121',
  13971. '\u3145': '\u1109',
  13972. '\u3146': '\u110A',
  13973. '\u3147': '\u110B',
  13974. '\u3148': '\u110C',
  13975. '\u3149': '\u110D',
  13976. '\u314A': '\u110E',
  13977. '\u314B': '\u110F',
  13978. '\u314C': '\u1110',
  13979. '\u314D': '\u1111',
  13980. '\u314E': '\u1112',
  13981. '\u314F': '\u1161',
  13982. '\u3150': '\u1162',
  13983. '\u3151': '\u1163',
  13984. '\u3152': '\u1164',
  13985. '\u3153': '\u1165',
  13986. '\u3154': '\u1166',
  13987. '\u3155': '\u1167',
  13988. '\u3156': '\u1168',
  13989. '\u3157': '\u1169',
  13990. '\u3158': '\u116A',
  13991. '\u3159': '\u116B',
  13992. '\u315A': '\u116C',
  13993. '\u315B': '\u116D',
  13994. '\u315C': '\u116E',
  13995. '\u315D': '\u116F',
  13996. '\u315E': '\u1170',
  13997. '\u315F': '\u1171',
  13998. '\u3160': '\u1172',
  13999. '\u3161': '\u1173',
  14000. '\u3162': '\u1174',
  14001. '\u3163': '\u1175',
  14002. '\u3164': '\u1160',
  14003. '\u3165': '\u1114',
  14004. '\u3166': '\u1115',
  14005. '\u3167': '\u11C7',
  14006. '\u3168': '\u11C8',
  14007. '\u3169': '\u11CC',
  14008. '\u316A': '\u11CE',
  14009. '\u316B': '\u11D3',
  14010. '\u316C': '\u11D7',
  14011. '\u316D': '\u11D9',
  14012. '\u316E': '\u111C',
  14013. '\u316F': '\u11DD',
  14014. '\u3170': '\u11DF',
  14015. '\u3171': '\u111D',
  14016. '\u3172': '\u111E',
  14017. '\u3173': '\u1120',
  14018. '\u3174': '\u1122',
  14019. '\u3175': '\u1123',
  14020. '\u3176': '\u1127',
  14021. '\u3177': '\u1129',
  14022. '\u3178': '\u112B',
  14023. '\u3179': '\u112C',
  14024. '\u317A': '\u112D',
  14025. '\u317B': '\u112E',
  14026. '\u317C': '\u112F',
  14027. '\u317D': '\u1132',
  14028. '\u317E': '\u1136',
  14029. '\u317F': '\u1140',
  14030. '\u3180': '\u1147',
  14031. '\u3181': '\u114C',
  14032. '\u3182': '\u11F1',
  14033. '\u3183': '\u11F2',
  14034. '\u3184': '\u1157',
  14035. '\u3185': '\u1158',
  14036. '\u3186': '\u1159',
  14037. '\u3187': '\u1184',
  14038. '\u3188': '\u1185',
  14039. '\u3189': '\u1188',
  14040. '\u318A': '\u1191',
  14041. '\u318B': '\u1192',
  14042. '\u318C': '\u1194',
  14043. '\u318D': '\u119E',
  14044. '\u318E': '\u11A1',
  14045. '\u3200': '\u0028\u1100\u0029',
  14046. '\u3201': '\u0028\u1102\u0029',
  14047. '\u3202': '\u0028\u1103\u0029',
  14048. '\u3203': '\u0028\u1105\u0029',
  14049. '\u3204': '\u0028\u1106\u0029',
  14050. '\u3205': '\u0028\u1107\u0029',
  14051. '\u3206': '\u0028\u1109\u0029',
  14052. '\u3207': '\u0028\u110B\u0029',
  14053. '\u3208': '\u0028\u110C\u0029',
  14054. '\u3209': '\u0028\u110E\u0029',
  14055. '\u320A': '\u0028\u110F\u0029',
  14056. '\u320B': '\u0028\u1110\u0029',
  14057. '\u320C': '\u0028\u1111\u0029',
  14058. '\u320D': '\u0028\u1112\u0029',
  14059. '\u320E': '\u0028\u1100\u1161\u0029',
  14060. '\u320F': '\u0028\u1102\u1161\u0029',
  14061. '\u3210': '\u0028\u1103\u1161\u0029',
  14062. '\u3211': '\u0028\u1105\u1161\u0029',
  14063. '\u3212': '\u0028\u1106\u1161\u0029',
  14064. '\u3213': '\u0028\u1107\u1161\u0029',
  14065. '\u3214': '\u0028\u1109\u1161\u0029',
  14066. '\u3215': '\u0028\u110B\u1161\u0029',
  14067. '\u3216': '\u0028\u110C\u1161\u0029',
  14068. '\u3217': '\u0028\u110E\u1161\u0029',
  14069. '\u3218': '\u0028\u110F\u1161\u0029',
  14070. '\u3219': '\u0028\u1110\u1161\u0029',
  14071. '\u321A': '\u0028\u1111\u1161\u0029',
  14072. '\u321B': '\u0028\u1112\u1161\u0029',
  14073. '\u321C': '\u0028\u110C\u116E\u0029',
  14074. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14075. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14076. '\u3220': '\u0028\u4E00\u0029',
  14077. '\u3221': '\u0028\u4E8C\u0029',
  14078. '\u3222': '\u0028\u4E09\u0029',
  14079. '\u3223': '\u0028\u56DB\u0029',
  14080. '\u3224': '\u0028\u4E94\u0029',
  14081. '\u3225': '\u0028\u516D\u0029',
  14082. '\u3226': '\u0028\u4E03\u0029',
  14083. '\u3227': '\u0028\u516B\u0029',
  14084. '\u3228': '\u0028\u4E5D\u0029',
  14085. '\u3229': '\u0028\u5341\u0029',
  14086. '\u322A': '\u0028\u6708\u0029',
  14087. '\u322B': '\u0028\u706B\u0029',
  14088. '\u322C': '\u0028\u6C34\u0029',
  14089. '\u322D': '\u0028\u6728\u0029',
  14090. '\u322E': '\u0028\u91D1\u0029',
  14091. '\u322F': '\u0028\u571F\u0029',
  14092. '\u3230': '\u0028\u65E5\u0029',
  14093. '\u3231': '\u0028\u682A\u0029',
  14094. '\u3232': '\u0028\u6709\u0029',
  14095. '\u3233': '\u0028\u793E\u0029',
  14096. '\u3234': '\u0028\u540D\u0029',
  14097. '\u3235': '\u0028\u7279\u0029',
  14098. '\u3236': '\u0028\u8CA1\u0029',
  14099. '\u3237': '\u0028\u795D\u0029',
  14100. '\u3238': '\u0028\u52B4\u0029',
  14101. '\u3239': '\u0028\u4EE3\u0029',
  14102. '\u323A': '\u0028\u547C\u0029',
  14103. '\u323B': '\u0028\u5B66\u0029',
  14104. '\u323C': '\u0028\u76E3\u0029',
  14105. '\u323D': '\u0028\u4F01\u0029',
  14106. '\u323E': '\u0028\u8CC7\u0029',
  14107. '\u323F': '\u0028\u5354\u0029',
  14108. '\u3240': '\u0028\u796D\u0029',
  14109. '\u3241': '\u0028\u4F11\u0029',
  14110. '\u3242': '\u0028\u81EA\u0029',
  14111. '\u3243': '\u0028\u81F3\u0029',
  14112. '\u32C0': '\u0031\u6708',
  14113. '\u32C1': '\u0032\u6708',
  14114. '\u32C2': '\u0033\u6708',
  14115. '\u32C3': '\u0034\u6708',
  14116. '\u32C4': '\u0035\u6708',
  14117. '\u32C5': '\u0036\u6708',
  14118. '\u32C6': '\u0037\u6708',
  14119. '\u32C7': '\u0038\u6708',
  14120. '\u32C8': '\u0039\u6708',
  14121. '\u32C9': '\u0031\u0030\u6708',
  14122. '\u32CA': '\u0031\u0031\u6708',
  14123. '\u32CB': '\u0031\u0032\u6708',
  14124. '\u3358': '\u0030\u70B9',
  14125. '\u3359': '\u0031\u70B9',
  14126. '\u335A': '\u0032\u70B9',
  14127. '\u335B': '\u0033\u70B9',
  14128. '\u335C': '\u0034\u70B9',
  14129. '\u335D': '\u0035\u70B9',
  14130. '\u335E': '\u0036\u70B9',
  14131. '\u335F': '\u0037\u70B9',
  14132. '\u3360': '\u0038\u70B9',
  14133. '\u3361': '\u0039\u70B9',
  14134. '\u3362': '\u0031\u0030\u70B9',
  14135. '\u3363': '\u0031\u0031\u70B9',
  14136. '\u3364': '\u0031\u0032\u70B9',
  14137. '\u3365': '\u0031\u0033\u70B9',
  14138. '\u3366': '\u0031\u0034\u70B9',
  14139. '\u3367': '\u0031\u0035\u70B9',
  14140. '\u3368': '\u0031\u0036\u70B9',
  14141. '\u3369': '\u0031\u0037\u70B9',
  14142. '\u336A': '\u0031\u0038\u70B9',
  14143. '\u336B': '\u0031\u0039\u70B9',
  14144. '\u336C': '\u0032\u0030\u70B9',
  14145. '\u336D': '\u0032\u0031\u70B9',
  14146. '\u336E': '\u0032\u0032\u70B9',
  14147. '\u336F': '\u0032\u0033\u70B9',
  14148. '\u3370': '\u0032\u0034\u70B9',
  14149. '\u33E0': '\u0031\u65E5',
  14150. '\u33E1': '\u0032\u65E5',
  14151. '\u33E2': '\u0033\u65E5',
  14152. '\u33E3': '\u0034\u65E5',
  14153. '\u33E4': '\u0035\u65E5',
  14154. '\u33E5': '\u0036\u65E5',
  14155. '\u33E6': '\u0037\u65E5',
  14156. '\u33E7': '\u0038\u65E5',
  14157. '\u33E8': '\u0039\u65E5',
  14158. '\u33E9': '\u0031\u0030\u65E5',
  14159. '\u33EA': '\u0031\u0031\u65E5',
  14160. '\u33EB': '\u0031\u0032\u65E5',
  14161. '\u33EC': '\u0031\u0033\u65E5',
  14162. '\u33ED': '\u0031\u0034\u65E5',
  14163. '\u33EE': '\u0031\u0035\u65E5',
  14164. '\u33EF': '\u0031\u0036\u65E5',
  14165. '\u33F0': '\u0031\u0037\u65E5',
  14166. '\u33F1': '\u0031\u0038\u65E5',
  14167. '\u33F2': '\u0031\u0039\u65E5',
  14168. '\u33F3': '\u0032\u0030\u65E5',
  14169. '\u33F4': '\u0032\u0031\u65E5',
  14170. '\u33F5': '\u0032\u0032\u65E5',
  14171. '\u33F6': '\u0032\u0033\u65E5',
  14172. '\u33F7': '\u0032\u0034\u65E5',
  14173. '\u33F8': '\u0032\u0035\u65E5',
  14174. '\u33F9': '\u0032\u0036\u65E5',
  14175. '\u33FA': '\u0032\u0037\u65E5',
  14176. '\u33FB': '\u0032\u0038\u65E5',
  14177. '\u33FC': '\u0032\u0039\u65E5',
  14178. '\u33FD': '\u0033\u0030\u65E5',
  14179. '\u33FE': '\u0033\u0031\u65E5',
  14180. '\uFB00': '\u0066\u0066',
  14181. '\uFB01': '\u0066\u0069',
  14182. '\uFB02': '\u0066\u006C',
  14183. '\uFB03': '\u0066\u0066\u0069',
  14184. '\uFB04': '\u0066\u0066\u006C',
  14185. '\uFB05': '\u017F\u0074',
  14186. '\uFB06': '\u0073\u0074',
  14187. '\uFB13': '\u0574\u0576',
  14188. '\uFB14': '\u0574\u0565',
  14189. '\uFB15': '\u0574\u056B',
  14190. '\uFB16': '\u057E\u0576',
  14191. '\uFB17': '\u0574\u056D',
  14192. '\uFB4F': '\u05D0\u05DC',
  14193. '\uFB50': '\u0671',
  14194. '\uFB51': '\u0671',
  14195. '\uFB52': '\u067B',
  14196. '\uFB53': '\u067B',
  14197. '\uFB54': '\u067B',
  14198. '\uFB55': '\u067B',
  14199. '\uFB56': '\u067E',
  14200. '\uFB57': '\u067E',
  14201. '\uFB58': '\u067E',
  14202. '\uFB59': '\u067E',
  14203. '\uFB5A': '\u0680',
  14204. '\uFB5B': '\u0680',
  14205. '\uFB5C': '\u0680',
  14206. '\uFB5D': '\u0680',
  14207. '\uFB5E': '\u067A',
  14208. '\uFB5F': '\u067A',
  14209. '\uFB60': '\u067A',
  14210. '\uFB61': '\u067A',
  14211. '\uFB62': '\u067F',
  14212. '\uFB63': '\u067F',
  14213. '\uFB64': '\u067F',
  14214. '\uFB65': '\u067F',
  14215. '\uFB66': '\u0679',
  14216. '\uFB67': '\u0679',
  14217. '\uFB68': '\u0679',
  14218. '\uFB69': '\u0679',
  14219. '\uFB6A': '\u06A4',
  14220. '\uFB6B': '\u06A4',
  14221. '\uFB6C': '\u06A4',
  14222. '\uFB6D': '\u06A4',
  14223. '\uFB6E': '\u06A6',
  14224. '\uFB6F': '\u06A6',
  14225. '\uFB70': '\u06A6',
  14226. '\uFB71': '\u06A6',
  14227. '\uFB72': '\u0684',
  14228. '\uFB73': '\u0684',
  14229. '\uFB74': '\u0684',
  14230. '\uFB75': '\u0684',
  14231. '\uFB76': '\u0683',
  14232. '\uFB77': '\u0683',
  14233. '\uFB78': '\u0683',
  14234. '\uFB79': '\u0683',
  14235. '\uFB7A': '\u0686',
  14236. '\uFB7B': '\u0686',
  14237. '\uFB7C': '\u0686',
  14238. '\uFB7D': '\u0686',
  14239. '\uFB7E': '\u0687',
  14240. '\uFB7F': '\u0687',
  14241. '\uFB80': '\u0687',
  14242. '\uFB81': '\u0687',
  14243. '\uFB82': '\u068D',
  14244. '\uFB83': '\u068D',
  14245. '\uFB84': '\u068C',
  14246. '\uFB85': '\u068C',
  14247. '\uFB86': '\u068E',
  14248. '\uFB87': '\u068E',
  14249. '\uFB88': '\u0688',
  14250. '\uFB89': '\u0688',
  14251. '\uFB8A': '\u0698',
  14252. '\uFB8B': '\u0698',
  14253. '\uFB8C': '\u0691',
  14254. '\uFB8D': '\u0691',
  14255. '\uFB8E': '\u06A9',
  14256. '\uFB8F': '\u06A9',
  14257. '\uFB90': '\u06A9',
  14258. '\uFB91': '\u06A9',
  14259. '\uFB92': '\u06AF',
  14260. '\uFB93': '\u06AF',
  14261. '\uFB94': '\u06AF',
  14262. '\uFB95': '\u06AF',
  14263. '\uFB96': '\u06B3',
  14264. '\uFB97': '\u06B3',
  14265. '\uFB98': '\u06B3',
  14266. '\uFB99': '\u06B3',
  14267. '\uFB9A': '\u06B1',
  14268. '\uFB9B': '\u06B1',
  14269. '\uFB9C': '\u06B1',
  14270. '\uFB9D': '\u06B1',
  14271. '\uFB9E': '\u06BA',
  14272. '\uFB9F': '\u06BA',
  14273. '\uFBA0': '\u06BB',
  14274. '\uFBA1': '\u06BB',
  14275. '\uFBA2': '\u06BB',
  14276. '\uFBA3': '\u06BB',
  14277. '\uFBA4': '\u06C0',
  14278. '\uFBA5': '\u06C0',
  14279. '\uFBA6': '\u06C1',
  14280. '\uFBA7': '\u06C1',
  14281. '\uFBA8': '\u06C1',
  14282. '\uFBA9': '\u06C1',
  14283. '\uFBAA': '\u06BE',
  14284. '\uFBAB': '\u06BE',
  14285. '\uFBAC': '\u06BE',
  14286. '\uFBAD': '\u06BE',
  14287. '\uFBAE': '\u06D2',
  14288. '\uFBAF': '\u06D2',
  14289. '\uFBB0': '\u06D3',
  14290. '\uFBB1': '\u06D3',
  14291. '\uFBD3': '\u06AD',
  14292. '\uFBD4': '\u06AD',
  14293. '\uFBD5': '\u06AD',
  14294. '\uFBD6': '\u06AD',
  14295. '\uFBD7': '\u06C7',
  14296. '\uFBD8': '\u06C7',
  14297. '\uFBD9': '\u06C6',
  14298. '\uFBDA': '\u06C6',
  14299. '\uFBDB': '\u06C8',
  14300. '\uFBDC': '\u06C8',
  14301. '\uFBDD': '\u0677',
  14302. '\uFBDE': '\u06CB',
  14303. '\uFBDF': '\u06CB',
  14304. '\uFBE0': '\u06C5',
  14305. '\uFBE1': '\u06C5',
  14306. '\uFBE2': '\u06C9',
  14307. '\uFBE3': '\u06C9',
  14308. '\uFBE4': '\u06D0',
  14309. '\uFBE5': '\u06D0',
  14310. '\uFBE6': '\u06D0',
  14311. '\uFBE7': '\u06D0',
  14312. '\uFBE8': '\u0649',
  14313. '\uFBE9': '\u0649',
  14314. '\uFBEA': '\u0626\u0627',
  14315. '\uFBEB': '\u0626\u0627',
  14316. '\uFBEC': '\u0626\u06D5',
  14317. '\uFBED': '\u0626\u06D5',
  14318. '\uFBEE': '\u0626\u0648',
  14319. '\uFBEF': '\u0626\u0648',
  14320. '\uFBF0': '\u0626\u06C7',
  14321. '\uFBF1': '\u0626\u06C7',
  14322. '\uFBF2': '\u0626\u06C6',
  14323. '\uFBF3': '\u0626\u06C6',
  14324. '\uFBF4': '\u0626\u06C8',
  14325. '\uFBF5': '\u0626\u06C8',
  14326. '\uFBF6': '\u0626\u06D0',
  14327. '\uFBF7': '\u0626\u06D0',
  14328. '\uFBF8': '\u0626\u06D0',
  14329. '\uFBF9': '\u0626\u0649',
  14330. '\uFBFA': '\u0626\u0649',
  14331. '\uFBFB': '\u0626\u0649',
  14332. '\uFBFC': '\u06CC',
  14333. '\uFBFD': '\u06CC',
  14334. '\uFBFE': '\u06CC',
  14335. '\uFBFF': '\u06CC',
  14336. '\uFC00': '\u0626\u062C',
  14337. '\uFC01': '\u0626\u062D',
  14338. '\uFC02': '\u0626\u0645',
  14339. '\uFC03': '\u0626\u0649',
  14340. '\uFC04': '\u0626\u064A',
  14341. '\uFC05': '\u0628\u062C',
  14342. '\uFC06': '\u0628\u062D',
  14343. '\uFC07': '\u0628\u062E',
  14344. '\uFC08': '\u0628\u0645',
  14345. '\uFC09': '\u0628\u0649',
  14346. '\uFC0A': '\u0628\u064A',
  14347. '\uFC0B': '\u062A\u062C',
  14348. '\uFC0C': '\u062A\u062D',
  14349. '\uFC0D': '\u062A\u062E',
  14350. '\uFC0E': '\u062A\u0645',
  14351. '\uFC0F': '\u062A\u0649',
  14352. '\uFC10': '\u062A\u064A',
  14353. '\uFC11': '\u062B\u062C',
  14354. '\uFC12': '\u062B\u0645',
  14355. '\uFC13': '\u062B\u0649',
  14356. '\uFC14': '\u062B\u064A',
  14357. '\uFC15': '\u062C\u062D',
  14358. '\uFC16': '\u062C\u0645',
  14359. '\uFC17': '\u062D\u062C',
  14360. '\uFC18': '\u062D\u0645',
  14361. '\uFC19': '\u062E\u062C',
  14362. '\uFC1A': '\u062E\u062D',
  14363. '\uFC1B': '\u062E\u0645',
  14364. '\uFC1C': '\u0633\u062C',
  14365. '\uFC1D': '\u0633\u062D',
  14366. '\uFC1E': '\u0633\u062E',
  14367. '\uFC1F': '\u0633\u0645',
  14368. '\uFC20': '\u0635\u062D',
  14369. '\uFC21': '\u0635\u0645',
  14370. '\uFC22': '\u0636\u062C',
  14371. '\uFC23': '\u0636\u062D',
  14372. '\uFC24': '\u0636\u062E',
  14373. '\uFC25': '\u0636\u0645',
  14374. '\uFC26': '\u0637\u062D',
  14375. '\uFC27': '\u0637\u0645',
  14376. '\uFC28': '\u0638\u0645',
  14377. '\uFC29': '\u0639\u062C',
  14378. '\uFC2A': '\u0639\u0645',
  14379. '\uFC2B': '\u063A\u062C',
  14380. '\uFC2C': '\u063A\u0645',
  14381. '\uFC2D': '\u0641\u062C',
  14382. '\uFC2E': '\u0641\u062D',
  14383. '\uFC2F': '\u0641\u062E',
  14384. '\uFC30': '\u0641\u0645',
  14385. '\uFC31': '\u0641\u0649',
  14386. '\uFC32': '\u0641\u064A',
  14387. '\uFC33': '\u0642\u062D',
  14388. '\uFC34': '\u0642\u0645',
  14389. '\uFC35': '\u0642\u0649',
  14390. '\uFC36': '\u0642\u064A',
  14391. '\uFC37': '\u0643\u0627',
  14392. '\uFC38': '\u0643\u062C',
  14393. '\uFC39': '\u0643\u062D',
  14394. '\uFC3A': '\u0643\u062E',
  14395. '\uFC3B': '\u0643\u0644',
  14396. '\uFC3C': '\u0643\u0645',
  14397. '\uFC3D': '\u0643\u0649',
  14398. '\uFC3E': '\u0643\u064A',
  14399. '\uFC3F': '\u0644\u062C',
  14400. '\uFC40': '\u0644\u062D',
  14401. '\uFC41': '\u0644\u062E',
  14402. '\uFC42': '\u0644\u0645',
  14403. '\uFC43': '\u0644\u0649',
  14404. '\uFC44': '\u0644\u064A',
  14405. '\uFC45': '\u0645\u062C',
  14406. '\uFC46': '\u0645\u062D',
  14407. '\uFC47': '\u0645\u062E',
  14408. '\uFC48': '\u0645\u0645',
  14409. '\uFC49': '\u0645\u0649',
  14410. '\uFC4A': '\u0645\u064A',
  14411. '\uFC4B': '\u0646\u062C',
  14412. '\uFC4C': '\u0646\u062D',
  14413. '\uFC4D': '\u0646\u062E',
  14414. '\uFC4E': '\u0646\u0645',
  14415. '\uFC4F': '\u0646\u0649',
  14416. '\uFC50': '\u0646\u064A',
  14417. '\uFC51': '\u0647\u062C',
  14418. '\uFC52': '\u0647\u0645',
  14419. '\uFC53': '\u0647\u0649',
  14420. '\uFC54': '\u0647\u064A',
  14421. '\uFC55': '\u064A\u062C',
  14422. '\uFC56': '\u064A\u062D',
  14423. '\uFC57': '\u064A\u062E',
  14424. '\uFC58': '\u064A\u0645',
  14425. '\uFC59': '\u064A\u0649',
  14426. '\uFC5A': '\u064A\u064A',
  14427. '\uFC5B': '\u0630\u0670',
  14428. '\uFC5C': '\u0631\u0670',
  14429. '\uFC5D': '\u0649\u0670',
  14430. '\uFC5E': '\u0020\u064C\u0651',
  14431. '\uFC5F': '\u0020\u064D\u0651',
  14432. '\uFC60': '\u0020\u064E\u0651',
  14433. '\uFC61': '\u0020\u064F\u0651',
  14434. '\uFC62': '\u0020\u0650\u0651',
  14435. '\uFC63': '\u0020\u0651\u0670',
  14436. '\uFC64': '\u0626\u0631',
  14437. '\uFC65': '\u0626\u0632',
  14438. '\uFC66': '\u0626\u0645',
  14439. '\uFC67': '\u0626\u0646',
  14440. '\uFC68': '\u0626\u0649',
  14441. '\uFC69': '\u0626\u064A',
  14442. '\uFC6A': '\u0628\u0631',
  14443. '\uFC6B': '\u0628\u0632',
  14444. '\uFC6C': '\u0628\u0645',
  14445. '\uFC6D': '\u0628\u0646',
  14446. '\uFC6E': '\u0628\u0649',
  14447. '\uFC6F': '\u0628\u064A',
  14448. '\uFC70': '\u062A\u0631',
  14449. '\uFC71': '\u062A\u0632',
  14450. '\uFC72': '\u062A\u0645',
  14451. '\uFC73': '\u062A\u0646',
  14452. '\uFC74': '\u062A\u0649',
  14453. '\uFC75': '\u062A\u064A',
  14454. '\uFC76': '\u062B\u0631',
  14455. '\uFC77': '\u062B\u0632',
  14456. '\uFC78': '\u062B\u0645',
  14457. '\uFC79': '\u062B\u0646',
  14458. '\uFC7A': '\u062B\u0649',
  14459. '\uFC7B': '\u062B\u064A',
  14460. '\uFC7C': '\u0641\u0649',
  14461. '\uFC7D': '\u0641\u064A',
  14462. '\uFC7E': '\u0642\u0649',
  14463. '\uFC7F': '\u0642\u064A',
  14464. '\uFC80': '\u0643\u0627',
  14465. '\uFC81': '\u0643\u0644',
  14466. '\uFC82': '\u0643\u0645',
  14467. '\uFC83': '\u0643\u0649',
  14468. '\uFC84': '\u0643\u064A',
  14469. '\uFC85': '\u0644\u0645',
  14470. '\uFC86': '\u0644\u0649',
  14471. '\uFC87': '\u0644\u064A',
  14472. '\uFC88': '\u0645\u0627',
  14473. '\uFC89': '\u0645\u0645',
  14474. '\uFC8A': '\u0646\u0631',
  14475. '\uFC8B': '\u0646\u0632',
  14476. '\uFC8C': '\u0646\u0645',
  14477. '\uFC8D': '\u0646\u0646',
  14478. '\uFC8E': '\u0646\u0649',
  14479. '\uFC8F': '\u0646\u064A',
  14480. '\uFC90': '\u0649\u0670',
  14481. '\uFC91': '\u064A\u0631',
  14482. '\uFC92': '\u064A\u0632',
  14483. '\uFC93': '\u064A\u0645',
  14484. '\uFC94': '\u064A\u0646',
  14485. '\uFC95': '\u064A\u0649',
  14486. '\uFC96': '\u064A\u064A',
  14487. '\uFC97': '\u0626\u062C',
  14488. '\uFC98': '\u0626\u062D',
  14489. '\uFC99': '\u0626\u062E',
  14490. '\uFC9A': '\u0626\u0645',
  14491. '\uFC9B': '\u0626\u0647',
  14492. '\uFC9C': '\u0628\u062C',
  14493. '\uFC9D': '\u0628\u062D',
  14494. '\uFC9E': '\u0628\u062E',
  14495. '\uFC9F': '\u0628\u0645',
  14496. '\uFCA0': '\u0628\u0647',
  14497. '\uFCA1': '\u062A\u062C',
  14498. '\uFCA2': '\u062A\u062D',
  14499. '\uFCA3': '\u062A\u062E',
  14500. '\uFCA4': '\u062A\u0645',
  14501. '\uFCA5': '\u062A\u0647',
  14502. '\uFCA6': '\u062B\u0645',
  14503. '\uFCA7': '\u062C\u062D',
  14504. '\uFCA8': '\u062C\u0645',
  14505. '\uFCA9': '\u062D\u062C',
  14506. '\uFCAA': '\u062D\u0645',
  14507. '\uFCAB': '\u062E\u062C',
  14508. '\uFCAC': '\u062E\u0645',
  14509. '\uFCAD': '\u0633\u062C',
  14510. '\uFCAE': '\u0633\u062D',
  14511. '\uFCAF': '\u0633\u062E',
  14512. '\uFCB0': '\u0633\u0645',
  14513. '\uFCB1': '\u0635\u062D',
  14514. '\uFCB2': '\u0635\u062E',
  14515. '\uFCB3': '\u0635\u0645',
  14516. '\uFCB4': '\u0636\u062C',
  14517. '\uFCB5': '\u0636\u062D',
  14518. '\uFCB6': '\u0636\u062E',
  14519. '\uFCB7': '\u0636\u0645',
  14520. '\uFCB8': '\u0637\u062D',
  14521. '\uFCB9': '\u0638\u0645',
  14522. '\uFCBA': '\u0639\u062C',
  14523. '\uFCBB': '\u0639\u0645',
  14524. '\uFCBC': '\u063A\u062C',
  14525. '\uFCBD': '\u063A\u0645',
  14526. '\uFCBE': '\u0641\u062C',
  14527. '\uFCBF': '\u0641\u062D',
  14528. '\uFCC0': '\u0641\u062E',
  14529. '\uFCC1': '\u0641\u0645',
  14530. '\uFCC2': '\u0642\u062D',
  14531. '\uFCC3': '\u0642\u0645',
  14532. '\uFCC4': '\u0643\u062C',
  14533. '\uFCC5': '\u0643\u062D',
  14534. '\uFCC6': '\u0643\u062E',
  14535. '\uFCC7': '\u0643\u0644',
  14536. '\uFCC8': '\u0643\u0645',
  14537. '\uFCC9': '\u0644\u062C',
  14538. '\uFCCA': '\u0644\u062D',
  14539. '\uFCCB': '\u0644\u062E',
  14540. '\uFCCC': '\u0644\u0645',
  14541. '\uFCCD': '\u0644\u0647',
  14542. '\uFCCE': '\u0645\u062C',
  14543. '\uFCCF': '\u0645\u062D',
  14544. '\uFCD0': '\u0645\u062E',
  14545. '\uFCD1': '\u0645\u0645',
  14546. '\uFCD2': '\u0646\u062C',
  14547. '\uFCD3': '\u0646\u062D',
  14548. '\uFCD4': '\u0646\u062E',
  14549. '\uFCD5': '\u0646\u0645',
  14550. '\uFCD6': '\u0646\u0647',
  14551. '\uFCD7': '\u0647\u062C',
  14552. '\uFCD8': '\u0647\u0645',
  14553. '\uFCD9': '\u0647\u0670',
  14554. '\uFCDA': '\u064A\u062C',
  14555. '\uFCDB': '\u064A\u062D',
  14556. '\uFCDC': '\u064A\u062E',
  14557. '\uFCDD': '\u064A\u0645',
  14558. '\uFCDE': '\u064A\u0647',
  14559. '\uFCDF': '\u0626\u0645',
  14560. '\uFCE0': '\u0626\u0647',
  14561. '\uFCE1': '\u0628\u0645',
  14562. '\uFCE2': '\u0628\u0647',
  14563. '\uFCE3': '\u062A\u0645',
  14564. '\uFCE4': '\u062A\u0647',
  14565. '\uFCE5': '\u062B\u0645',
  14566. '\uFCE6': '\u062B\u0647',
  14567. '\uFCE7': '\u0633\u0645',
  14568. '\uFCE8': '\u0633\u0647',
  14569. '\uFCE9': '\u0634\u0645',
  14570. '\uFCEA': '\u0634\u0647',
  14571. '\uFCEB': '\u0643\u0644',
  14572. '\uFCEC': '\u0643\u0645',
  14573. '\uFCED': '\u0644\u0645',
  14574. '\uFCEE': '\u0646\u0645',
  14575. '\uFCEF': '\u0646\u0647',
  14576. '\uFCF0': '\u064A\u0645',
  14577. '\uFCF1': '\u064A\u0647',
  14578. '\uFCF2': '\u0640\u064E\u0651',
  14579. '\uFCF3': '\u0640\u064F\u0651',
  14580. '\uFCF4': '\u0640\u0650\u0651',
  14581. '\uFCF5': '\u0637\u0649',
  14582. '\uFCF6': '\u0637\u064A',
  14583. '\uFCF7': '\u0639\u0649',
  14584. '\uFCF8': '\u0639\u064A',
  14585. '\uFCF9': '\u063A\u0649',
  14586. '\uFCFA': '\u063A\u064A',
  14587. '\uFCFB': '\u0633\u0649',
  14588. '\uFCFC': '\u0633\u064A',
  14589. '\uFCFD': '\u0634\u0649',
  14590. '\uFCFE': '\u0634\u064A',
  14591. '\uFCFF': '\u062D\u0649',
  14592. '\uFD00': '\u062D\u064A',
  14593. '\uFD01': '\u062C\u0649',
  14594. '\uFD02': '\u062C\u064A',
  14595. '\uFD03': '\u062E\u0649',
  14596. '\uFD04': '\u062E\u064A',
  14597. '\uFD05': '\u0635\u0649',
  14598. '\uFD06': '\u0635\u064A',
  14599. '\uFD07': '\u0636\u0649',
  14600. '\uFD08': '\u0636\u064A',
  14601. '\uFD09': '\u0634\u062C',
  14602. '\uFD0A': '\u0634\u062D',
  14603. '\uFD0B': '\u0634\u062E',
  14604. '\uFD0C': '\u0634\u0645',
  14605. '\uFD0D': '\u0634\u0631',
  14606. '\uFD0E': '\u0633\u0631',
  14607. '\uFD0F': '\u0635\u0631',
  14608. '\uFD10': '\u0636\u0631',
  14609. '\uFD11': '\u0637\u0649',
  14610. '\uFD12': '\u0637\u064A',
  14611. '\uFD13': '\u0639\u0649',
  14612. '\uFD14': '\u0639\u064A',
  14613. '\uFD15': '\u063A\u0649',
  14614. '\uFD16': '\u063A\u064A',
  14615. '\uFD17': '\u0633\u0649',
  14616. '\uFD18': '\u0633\u064A',
  14617. '\uFD19': '\u0634\u0649',
  14618. '\uFD1A': '\u0634\u064A',
  14619. '\uFD1B': '\u062D\u0649',
  14620. '\uFD1C': '\u062D\u064A',
  14621. '\uFD1D': '\u062C\u0649',
  14622. '\uFD1E': '\u062C\u064A',
  14623. '\uFD1F': '\u062E\u0649',
  14624. '\uFD20': '\u062E\u064A',
  14625. '\uFD21': '\u0635\u0649',
  14626. '\uFD22': '\u0635\u064A',
  14627. '\uFD23': '\u0636\u0649',
  14628. '\uFD24': '\u0636\u064A',
  14629. '\uFD25': '\u0634\u062C',
  14630. '\uFD26': '\u0634\u062D',
  14631. '\uFD27': '\u0634\u062E',
  14632. '\uFD28': '\u0634\u0645',
  14633. '\uFD29': '\u0634\u0631',
  14634. '\uFD2A': '\u0633\u0631',
  14635. '\uFD2B': '\u0635\u0631',
  14636. '\uFD2C': '\u0636\u0631',
  14637. '\uFD2D': '\u0634\u062C',
  14638. '\uFD2E': '\u0634\u062D',
  14639. '\uFD2F': '\u0634\u062E',
  14640. '\uFD30': '\u0634\u0645',
  14641. '\uFD31': '\u0633\u0647',
  14642. '\uFD32': '\u0634\u0647',
  14643. '\uFD33': '\u0637\u0645',
  14644. '\uFD34': '\u0633\u062C',
  14645. '\uFD35': '\u0633\u062D',
  14646. '\uFD36': '\u0633\u062E',
  14647. '\uFD37': '\u0634\u062C',
  14648. '\uFD38': '\u0634\u062D',
  14649. '\uFD39': '\u0634\u062E',
  14650. '\uFD3A': '\u0637\u0645',
  14651. '\uFD3B': '\u0638\u0645',
  14652. '\uFD3C': '\u0627\u064B',
  14653. '\uFD3D': '\u0627\u064B',
  14654. '\uFD50': '\u062A\u062C\u0645',
  14655. '\uFD51': '\u062A\u062D\u062C',
  14656. '\uFD52': '\u062A\u062D\u062C',
  14657. '\uFD53': '\u062A\u062D\u0645',
  14658. '\uFD54': '\u062A\u062E\u0645',
  14659. '\uFD55': '\u062A\u0645\u062C',
  14660. '\uFD56': '\u062A\u0645\u062D',
  14661. '\uFD57': '\u062A\u0645\u062E',
  14662. '\uFD58': '\u062C\u0645\u062D',
  14663. '\uFD59': '\u062C\u0645\u062D',
  14664. '\uFD5A': '\u062D\u0645\u064A',
  14665. '\uFD5B': '\u062D\u0645\u0649',
  14666. '\uFD5C': '\u0633\u062D\u062C',
  14667. '\uFD5D': '\u0633\u062C\u062D',
  14668. '\uFD5E': '\u0633\u062C\u0649',
  14669. '\uFD5F': '\u0633\u0645\u062D',
  14670. '\uFD60': '\u0633\u0645\u062D',
  14671. '\uFD61': '\u0633\u0645\u062C',
  14672. '\uFD62': '\u0633\u0645\u0645',
  14673. '\uFD63': '\u0633\u0645\u0645',
  14674. '\uFD64': '\u0635\u062D\u062D',
  14675. '\uFD65': '\u0635\u062D\u062D',
  14676. '\uFD66': '\u0635\u0645\u0645',
  14677. '\uFD67': '\u0634\u062D\u0645',
  14678. '\uFD68': '\u0634\u062D\u0645',
  14679. '\uFD69': '\u0634\u062C\u064A',
  14680. '\uFD6A': '\u0634\u0645\u062E',
  14681. '\uFD6B': '\u0634\u0645\u062E',
  14682. '\uFD6C': '\u0634\u0645\u0645',
  14683. '\uFD6D': '\u0634\u0645\u0645',
  14684. '\uFD6E': '\u0636\u062D\u0649',
  14685. '\uFD6F': '\u0636\u062E\u0645',
  14686. '\uFD70': '\u0636\u062E\u0645',
  14687. '\uFD71': '\u0637\u0645\u062D',
  14688. '\uFD72': '\u0637\u0645\u062D',
  14689. '\uFD73': '\u0637\u0645\u0645',
  14690. '\uFD74': '\u0637\u0645\u064A',
  14691. '\uFD75': '\u0639\u062C\u0645',
  14692. '\uFD76': '\u0639\u0645\u0645',
  14693. '\uFD77': '\u0639\u0645\u0645',
  14694. '\uFD78': '\u0639\u0645\u0649',
  14695. '\uFD79': '\u063A\u0645\u0645',
  14696. '\uFD7A': '\u063A\u0645\u064A',
  14697. '\uFD7B': '\u063A\u0645\u0649',
  14698. '\uFD7C': '\u0641\u062E\u0645',
  14699. '\uFD7D': '\u0641\u062E\u0645',
  14700. '\uFD7E': '\u0642\u0645\u062D',
  14701. '\uFD7F': '\u0642\u0645\u0645',
  14702. '\uFD80': '\u0644\u062D\u0645',
  14703. '\uFD81': '\u0644\u062D\u064A',
  14704. '\uFD82': '\u0644\u062D\u0649',
  14705. '\uFD83': '\u0644\u062C\u062C',
  14706. '\uFD84': '\u0644\u062C\u062C',
  14707. '\uFD85': '\u0644\u062E\u0645',
  14708. '\uFD86': '\u0644\u062E\u0645',
  14709. '\uFD87': '\u0644\u0645\u062D',
  14710. '\uFD88': '\u0644\u0645\u062D',
  14711. '\uFD89': '\u0645\u062D\u062C',
  14712. '\uFD8A': '\u0645\u062D\u0645',
  14713. '\uFD8B': '\u0645\u062D\u064A',
  14714. '\uFD8C': '\u0645\u062C\u062D',
  14715. '\uFD8D': '\u0645\u062C\u0645',
  14716. '\uFD8E': '\u0645\u062E\u062C',
  14717. '\uFD8F': '\u0645\u062E\u0645',
  14718. '\uFD92': '\u0645\u062C\u062E',
  14719. '\uFD93': '\u0647\u0645\u062C',
  14720. '\uFD94': '\u0647\u0645\u0645',
  14721. '\uFD95': '\u0646\u062D\u0645',
  14722. '\uFD96': '\u0646\u062D\u0649',
  14723. '\uFD97': '\u0646\u062C\u0645',
  14724. '\uFD98': '\u0646\u062C\u0645',
  14725. '\uFD99': '\u0646\u062C\u0649',
  14726. '\uFD9A': '\u0646\u0645\u064A',
  14727. '\uFD9B': '\u0646\u0645\u0649',
  14728. '\uFD9C': '\u064A\u0645\u0645',
  14729. '\uFD9D': '\u064A\u0645\u0645',
  14730. '\uFD9E': '\u0628\u062E\u064A',
  14731. '\uFD9F': '\u062A\u062C\u064A',
  14732. '\uFDA0': '\u062A\u062C\u0649',
  14733. '\uFDA1': '\u062A\u062E\u064A',
  14734. '\uFDA2': '\u062A\u062E\u0649',
  14735. '\uFDA3': '\u062A\u0645\u064A',
  14736. '\uFDA4': '\u062A\u0645\u0649',
  14737. '\uFDA5': '\u062C\u0645\u064A',
  14738. '\uFDA6': '\u062C\u062D\u0649',
  14739. '\uFDA7': '\u062C\u0645\u0649',
  14740. '\uFDA8': '\u0633\u062E\u0649',
  14741. '\uFDA9': '\u0635\u062D\u064A',
  14742. '\uFDAA': '\u0634\u062D\u064A',
  14743. '\uFDAB': '\u0636\u062D\u064A',
  14744. '\uFDAC': '\u0644\u062C\u064A',
  14745. '\uFDAD': '\u0644\u0645\u064A',
  14746. '\uFDAE': '\u064A\u062D\u064A',
  14747. '\uFDAF': '\u064A\u062C\u064A',
  14748. '\uFDB0': '\u064A\u0645\u064A',
  14749. '\uFDB1': '\u0645\u0645\u064A',
  14750. '\uFDB2': '\u0642\u0645\u064A',
  14751. '\uFDB3': '\u0646\u062D\u064A',
  14752. '\uFDB4': '\u0642\u0645\u062D',
  14753. '\uFDB5': '\u0644\u062D\u0645',
  14754. '\uFDB6': '\u0639\u0645\u064A',
  14755. '\uFDB7': '\u0643\u0645\u064A',
  14756. '\uFDB8': '\u0646\u062C\u062D',
  14757. '\uFDB9': '\u0645\u062E\u064A',
  14758. '\uFDBA': '\u0644\u062C\u0645',
  14759. '\uFDBB': '\u0643\u0645\u0645',
  14760. '\uFDBC': '\u0644\u062C\u0645',
  14761. '\uFDBD': '\u0646\u062C\u062D',
  14762. '\uFDBE': '\u062C\u062D\u064A',
  14763. '\uFDBF': '\u062D\u062C\u064A',
  14764. '\uFDC0': '\u0645\u062C\u064A',
  14765. '\uFDC1': '\u0641\u0645\u064A',
  14766. '\uFDC2': '\u0628\u062D\u064A',
  14767. '\uFDC3': '\u0643\u0645\u0645',
  14768. '\uFDC4': '\u0639\u062C\u0645',
  14769. '\uFDC5': '\u0635\u0645\u0645',
  14770. '\uFDC6': '\u0633\u062E\u064A',
  14771. '\uFDC7': '\u0646\u062C\u064A',
  14772. '\uFE49': '\u203E',
  14773. '\uFE4A': '\u203E',
  14774. '\uFE4B': '\u203E',
  14775. '\uFE4C': '\u203E',
  14776. '\uFE4D': '\u005F',
  14777. '\uFE4E': '\u005F',
  14778. '\uFE4F': '\u005F',
  14779. '\uFE80': '\u0621',
  14780. '\uFE81': '\u0622',
  14781. '\uFE82': '\u0622',
  14782. '\uFE83': '\u0623',
  14783. '\uFE84': '\u0623',
  14784. '\uFE85': '\u0624',
  14785. '\uFE86': '\u0624',
  14786. '\uFE87': '\u0625',
  14787. '\uFE88': '\u0625',
  14788. '\uFE89': '\u0626',
  14789. '\uFE8A': '\u0626',
  14790. '\uFE8B': '\u0626',
  14791. '\uFE8C': '\u0626',
  14792. '\uFE8D': '\u0627',
  14793. '\uFE8E': '\u0627',
  14794. '\uFE8F': '\u0628',
  14795. '\uFE90': '\u0628',
  14796. '\uFE91': '\u0628',
  14797. '\uFE92': '\u0628',
  14798. '\uFE93': '\u0629',
  14799. '\uFE94': '\u0629',
  14800. '\uFE95': '\u062A',
  14801. '\uFE96': '\u062A',
  14802. '\uFE97': '\u062A',
  14803. '\uFE98': '\u062A',
  14804. '\uFE99': '\u062B',
  14805. '\uFE9A': '\u062B',
  14806. '\uFE9B': '\u062B',
  14807. '\uFE9C': '\u062B',
  14808. '\uFE9D': '\u062C',
  14809. '\uFE9E': '\u062C',
  14810. '\uFE9F': '\u062C',
  14811. '\uFEA0': '\u062C',
  14812. '\uFEA1': '\u062D',
  14813. '\uFEA2': '\u062D',
  14814. '\uFEA3': '\u062D',
  14815. '\uFEA4': '\u062D',
  14816. '\uFEA5': '\u062E',
  14817. '\uFEA6': '\u062E',
  14818. '\uFEA7': '\u062E',
  14819. '\uFEA8': '\u062E',
  14820. '\uFEA9': '\u062F',
  14821. '\uFEAA': '\u062F',
  14822. '\uFEAB': '\u0630',
  14823. '\uFEAC': '\u0630',
  14824. '\uFEAD': '\u0631',
  14825. '\uFEAE': '\u0631',
  14826. '\uFEAF': '\u0632',
  14827. '\uFEB0': '\u0632',
  14828. '\uFEB1': '\u0633',
  14829. '\uFEB2': '\u0633',
  14830. '\uFEB3': '\u0633',
  14831. '\uFEB4': '\u0633',
  14832. '\uFEB5': '\u0634',
  14833. '\uFEB6': '\u0634',
  14834. '\uFEB7': '\u0634',
  14835. '\uFEB8': '\u0634',
  14836. '\uFEB9': '\u0635',
  14837. '\uFEBA': '\u0635',
  14838. '\uFEBB': '\u0635',
  14839. '\uFEBC': '\u0635',
  14840. '\uFEBD': '\u0636',
  14841. '\uFEBE': '\u0636',
  14842. '\uFEBF': '\u0636',
  14843. '\uFEC0': '\u0636',
  14844. '\uFEC1': '\u0637',
  14845. '\uFEC2': '\u0637',
  14846. '\uFEC3': '\u0637',
  14847. '\uFEC4': '\u0637',
  14848. '\uFEC5': '\u0638',
  14849. '\uFEC6': '\u0638',
  14850. '\uFEC7': '\u0638',
  14851. '\uFEC8': '\u0638',
  14852. '\uFEC9': '\u0639',
  14853. '\uFECA': '\u0639',
  14854. '\uFECB': '\u0639',
  14855. '\uFECC': '\u0639',
  14856. '\uFECD': '\u063A',
  14857. '\uFECE': '\u063A',
  14858. '\uFECF': '\u063A',
  14859. '\uFED0': '\u063A',
  14860. '\uFED1': '\u0641',
  14861. '\uFED2': '\u0641',
  14862. '\uFED3': '\u0641',
  14863. '\uFED4': '\u0641',
  14864. '\uFED5': '\u0642',
  14865. '\uFED6': '\u0642',
  14866. '\uFED7': '\u0642',
  14867. '\uFED8': '\u0642',
  14868. '\uFED9': '\u0643',
  14869. '\uFEDA': '\u0643',
  14870. '\uFEDB': '\u0643',
  14871. '\uFEDC': '\u0643',
  14872. '\uFEDD': '\u0644',
  14873. '\uFEDE': '\u0644',
  14874. '\uFEDF': '\u0644',
  14875. '\uFEE0': '\u0644',
  14876. '\uFEE1': '\u0645',
  14877. '\uFEE2': '\u0645',
  14878. '\uFEE3': '\u0645',
  14879. '\uFEE4': '\u0645',
  14880. '\uFEE5': '\u0646',
  14881. '\uFEE6': '\u0646',
  14882. '\uFEE7': '\u0646',
  14883. '\uFEE8': '\u0646',
  14884. '\uFEE9': '\u0647',
  14885. '\uFEEA': '\u0647',
  14886. '\uFEEB': '\u0647',
  14887. '\uFEEC': '\u0647',
  14888. '\uFEED': '\u0648',
  14889. '\uFEEE': '\u0648',
  14890. '\uFEEF': '\u0649',
  14891. '\uFEF0': '\u0649',
  14892. '\uFEF1': '\u064A',
  14893. '\uFEF2': '\u064A',
  14894. '\uFEF3': '\u064A',
  14895. '\uFEF4': '\u064A',
  14896. '\uFEF5': '\u0644\u0622',
  14897. '\uFEF6': '\u0644\u0622',
  14898. '\uFEF7': '\u0644\u0623',
  14899. '\uFEF8': '\u0644\u0623',
  14900. '\uFEF9': '\u0644\u0625',
  14901. '\uFEFA': '\u0644\u0625',
  14902. '\uFEFB': '\u0644\u0627',
  14903. '\uFEFC': '\u0644\u0627'
  14904. };
  14905. function reverseIfRtl(chars) {
  14906. var charsLength = chars.length;
  14907. //reverse an arabic ligature
  14908. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14909. return chars;
  14910. }
  14911. var s = '';
  14912. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14913. s += chars[ii];
  14914. }
  14915. return s;
  14916. }
  14917. function adjustWidths(properties) {
  14918. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14919. return;
  14920. }
  14921. // adjusting width to fontMatrix scale
  14922. var scale = 0.001 / properties.fontMatrix[0];
  14923. var glyphsWidths = properties.widths;
  14924. for (var glyph in glyphsWidths) {
  14925. glyphsWidths[glyph] *= scale;
  14926. }
  14927. properties.defaultWidth *= scale;
  14928. }
  14929. function getFontType(type, subtype) {
  14930. switch (type) {
  14931. case 'Type1':
  14932. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14933. case 'CIDFontType0':
  14934. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14935. FontType.CIDFONTTYPE0;
  14936. case 'OpenType':
  14937. return FontType.OPENTYPE;
  14938. case 'TrueType':
  14939. return FontType.TRUETYPE;
  14940. case 'CIDFontType2':
  14941. return FontType.CIDFONTTYPE2;
  14942. case 'MMType1':
  14943. return FontType.MMTYPE1;
  14944. case 'Type0':
  14945. return FontType.TYPE0;
  14946. default:
  14947. return FontType.UNKNOWN;
  14948. }
  14949. }
  14950. var Glyph = (function GlyphClosure() {
  14951. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14952. this.fontChar = fontChar;
  14953. this.unicode = unicode;
  14954. this.accent = accent;
  14955. this.width = width;
  14956. this.vmetric = vmetric;
  14957. this.operatorListId = operatorListId;
  14958. }
  14959. Glyph.prototype.matchesForCache =
  14960. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14961. return this.fontChar === fontChar &&
  14962. this.unicode === unicode &&
  14963. this.accent === accent &&
  14964. this.width === width &&
  14965. this.vmetric === vmetric &&
  14966. this.operatorListId === operatorListId;
  14967. };
  14968. return Glyph;
  14969. })();
  14970. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14971. function ToUnicodeMap(cmap) {
  14972. // The elements of this._map can be integers or strings, depending on how
  14973. // |cmap| was created.
  14974. this._map = cmap;
  14975. }
  14976. ToUnicodeMap.prototype = {
  14977. get length() {
  14978. return this._map.length;
  14979. },
  14980. forEach: function(callback) {
  14981. for (var charCode in this._map) {
  14982. callback(charCode, this._map[charCode].charCodeAt(0));
  14983. }
  14984. },
  14985. get: function(i) {
  14986. return this._map[i];
  14987. },
  14988. charCodeOf: function(v) {
  14989. return this._map.indexOf(v);
  14990. }
  14991. };
  14992. return ToUnicodeMap;
  14993. })();
  14994. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14995. function IdentityToUnicodeMap(firstChar, lastChar) {
  14996. this.firstChar = firstChar;
  14997. this.lastChar = lastChar;
  14998. }
  14999. IdentityToUnicodeMap.prototype = {
  15000. get length() {
  15001. error('should not access .length');
  15002. },
  15003. forEach: function (callback) {
  15004. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15005. callback(i, i);
  15006. }
  15007. },
  15008. get: function (i) {
  15009. if (this.firstChar <= i && i <= this.lastChar) {
  15010. return String.fromCharCode(i);
  15011. }
  15012. return undefined;
  15013. },
  15014. charCodeOf: function (v) {
  15015. error('should not call .charCodeOf');
  15016. }
  15017. };
  15018. return IdentityToUnicodeMap;
  15019. })();
  15020. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15021. function writeInt16(dest, offset, num) {
  15022. dest[offset] = (num >> 8) & 0xFF;
  15023. dest[offset + 1] = num & 0xFF;
  15024. }
  15025. function writeInt32(dest, offset, num) {
  15026. dest[offset] = (num >> 24) & 0xFF;
  15027. dest[offset + 1] = (num >> 16) & 0xFF;
  15028. dest[offset + 2] = (num >> 8) & 0xFF;
  15029. dest[offset + 3] = num & 0xFF;
  15030. }
  15031. function writeData(dest, offset, data) {
  15032. var i, ii;
  15033. if (data instanceof Uint8Array) {
  15034. dest.set(data, offset);
  15035. } else if (typeof data === 'string') {
  15036. for (i = 0, ii = data.length; i < ii; i++) {
  15037. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15038. }
  15039. } else {
  15040. // treating everything else as array
  15041. for (i = 0, ii = data.length; i < ii; i++) {
  15042. dest[offset++] = data[i] & 0xFF;
  15043. }
  15044. }
  15045. }
  15046. function OpenTypeFileBuilder(sfnt) {
  15047. this.sfnt = sfnt;
  15048. this.tables = Object.create(null);
  15049. }
  15050. OpenTypeFileBuilder.getSearchParams =
  15051. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15052. var maxPower2 = 1, log2 = 0;
  15053. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15054. maxPower2 <<= 1;
  15055. log2++;
  15056. }
  15057. var searchRange = maxPower2 * entrySize;
  15058. return {
  15059. range: searchRange,
  15060. entry: log2,
  15061. rangeShift: entrySize * entriesCount - searchRange
  15062. };
  15063. };
  15064. var OTF_HEADER_SIZE = 12;
  15065. var OTF_TABLE_ENTRY_SIZE = 16;
  15066. OpenTypeFileBuilder.prototype = {
  15067. toArray: function OpenTypeFileBuilder_toArray() {
  15068. var sfnt = this.sfnt;
  15069. // Tables needs to be written by ascendant alphabetic order
  15070. var tables = this.tables;
  15071. var tablesNames = Object.keys(tables);
  15072. tablesNames.sort();
  15073. var numTables = tablesNames.length;
  15074. var i, j, jj, table, tableName;
  15075. // layout the tables data
  15076. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15077. var tableOffsets = [offset];
  15078. for (i = 0; i < numTables; i++) {
  15079. table = tables[tablesNames[i]];
  15080. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15081. offset += paddedLength;
  15082. tableOffsets.push(offset);
  15083. }
  15084. var file = new Uint8Array(offset);
  15085. // write the table data first (mostly for checksum)
  15086. for (i = 0; i < numTables; i++) {
  15087. table = tables[tablesNames[i]];
  15088. writeData(file, tableOffsets[i], table);
  15089. }
  15090. // sfnt version (4 bytes)
  15091. if (sfnt === 'true') {
  15092. // Windows hates the Mac TrueType sfnt version number
  15093. sfnt = string32(0x00010000);
  15094. }
  15095. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15096. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15097. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15098. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15099. // numTables (2 bytes)
  15100. writeInt16(file, 4, numTables);
  15101. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15102. // searchRange (2 bytes)
  15103. writeInt16(file, 6, searchParams.range);
  15104. // entrySelector (2 bytes)
  15105. writeInt16(file, 8, searchParams.entry);
  15106. // rangeShift (2 bytes)
  15107. writeInt16(file, 10, searchParams.rangeShift);
  15108. offset = OTF_HEADER_SIZE;
  15109. // writing table entries
  15110. for (i = 0; i < numTables; i++) {
  15111. tableName = tablesNames[i];
  15112. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15113. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15114. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15115. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15116. // checksum
  15117. var checksum = 0;
  15118. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15119. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15120. (file[j + 2] << 8) + file[j + 3];
  15121. checksum = (checksum + quad) | 0;
  15122. }
  15123. writeInt32(file, offset + 4, checksum);
  15124. // offset
  15125. writeInt32(file, offset + 8, tableOffsets[i]);
  15126. // length
  15127. writeInt32(file, offset + 12, tables[tableName].length);
  15128. offset += OTF_TABLE_ENTRY_SIZE;
  15129. }
  15130. return file;
  15131. },
  15132. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15133. if (tag in this.tables) {
  15134. throw new Error('Table ' + tag + ' already exists');
  15135. }
  15136. this.tables[tag] = data;
  15137. }
  15138. };
  15139. return OpenTypeFileBuilder;
  15140. })();
  15141. /**
  15142. * 'Font' is the class the outside world should use, it encapsulate all the font
  15143. * decoding logics whatever type it is (assuming the font type is supported).
  15144. *
  15145. * For example to read a Type1 font and to attach it to the document:
  15146. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15147. * type1Font.bind();
  15148. */
  15149. var Font = (function FontClosure() {
  15150. function Font(name, file, properties) {
  15151. var charCode, glyphName, fontChar;
  15152. this.name = name;
  15153. this.loadedName = properties.loadedName;
  15154. this.isType3Font = properties.isType3Font;
  15155. this.sizes = [];
  15156. this.glyphCache = {};
  15157. var names = name.split('+');
  15158. names = names.length > 1 ? names[1] : names[0];
  15159. names = names.split(/[-,_]/g)[0];
  15160. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15161. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15162. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15163. var type = properties.type;
  15164. var subtype = properties.subtype;
  15165. this.type = type;
  15166. this.fallbackName = (this.isMonospace ? 'monospace' :
  15167. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15168. this.differences = properties.differences;
  15169. this.widths = properties.widths;
  15170. this.defaultWidth = properties.defaultWidth;
  15171. this.composite = properties.composite;
  15172. this.wideChars = properties.wideChars;
  15173. this.cMap = properties.cMap;
  15174. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15175. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15176. this.fontMatrix = properties.fontMatrix;
  15177. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15178. this.toFontChar = [];
  15179. if (properties.type === 'Type3') {
  15180. for (charCode = 0; charCode < 256; charCode++) {
  15181. this.toFontChar[charCode] = (this.differences[charCode] ||
  15182. properties.defaultEncoding[charCode]);
  15183. }
  15184. this.fontType = FontType.TYPE3;
  15185. return;
  15186. }
  15187. this.cidEncoding = properties.cidEncoding;
  15188. this.vertical = properties.vertical;
  15189. if (this.vertical) {
  15190. this.vmetrics = properties.vmetrics;
  15191. this.defaultVMetrics = properties.defaultVMetrics;
  15192. }
  15193. if (!file || file.isEmpty) {
  15194. if (file) {
  15195. // Some bad PDF generators will include empty font files,
  15196. // attempting to recover by assuming that no file exists.
  15197. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15198. }
  15199. this.missingFile = true;
  15200. // The file data is not specified. Trying to fix the font name
  15201. // to be used with the canvas.font.
  15202. var fontName = name.replace(/[,_]/g, '-');
  15203. var isStandardFont = !!stdFontMap[fontName] ||
  15204. (nonStdFontMap[fontName] && !!stdFontMap[nonStdFontMap[fontName]]);
  15205. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15206. this.bold = (fontName.search(/bold/gi) !== -1);
  15207. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15208. (fontName.search(/italic/gi) !== -1));
  15209. // Use 'name' instead of 'fontName' here because the original
  15210. // name ArialBlack for example will be replaced by Helvetica.
  15211. this.black = (name.search(/Black/g) !== -1);
  15212. // if at least one width is present, remeasure all chars when exists
  15213. this.remeasure = Object.keys(this.widths).length > 0;
  15214. if (isStandardFont && type === 'CIDFontType2' &&
  15215. properties.cidEncoding.indexOf('Identity-') === 0) {
  15216. // Standard fonts might be embedded as CID font without glyph mapping.
  15217. // Building one based on GlyphMapForStandardFonts.
  15218. var map = [];
  15219. for (var code in GlyphMapForStandardFonts) {
  15220. map[+code] = GlyphMapForStandardFonts[code];
  15221. }
  15222. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15223. if (!isIdentityUnicode) {
  15224. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15225. map[+charCode] = unicodeCharCode;
  15226. });
  15227. }
  15228. this.toFontChar = map;
  15229. this.toUnicode = new ToUnicodeMap(map);
  15230. } else if (/Symbol/i.test(fontName)) {
  15231. var symbols = Encodings.SymbolSetEncoding;
  15232. for (charCode in symbols) {
  15233. fontChar = GlyphsUnicode[symbols[charCode]];
  15234. if (!fontChar) {
  15235. continue;
  15236. }
  15237. this.toFontChar[charCode] = fontChar;
  15238. }
  15239. for (charCode in properties.differences) {
  15240. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15241. if (!fontChar) {
  15242. continue;
  15243. }
  15244. this.toFontChar[charCode] = fontChar;
  15245. }
  15246. } else if (/Dingbats/i.test(fontName)) {
  15247. if (/Wingdings/i.test(name)) {
  15248. warn('Wingdings font without embedded font file, ' +
  15249. 'falling back to the ZapfDingbats encoding.');
  15250. }
  15251. var dingbats = Encodings.ZapfDingbatsEncoding;
  15252. for (charCode in dingbats) {
  15253. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15254. if (!fontChar) {
  15255. continue;
  15256. }
  15257. this.toFontChar[charCode] = fontChar;
  15258. }
  15259. for (charCode in properties.differences) {
  15260. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15261. if (!fontChar) {
  15262. continue;
  15263. }
  15264. this.toFontChar[charCode] = fontChar;
  15265. }
  15266. } else if (isStandardFont) {
  15267. this.toFontChar = [];
  15268. for (charCode in properties.defaultEncoding) {
  15269. glyphName = (properties.differences[charCode] ||
  15270. properties.defaultEncoding[charCode]);
  15271. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15272. }
  15273. } else {
  15274. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15275. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15276. if (notCidFont) {
  15277. glyphName = (properties.differences[charCode] ||
  15278. properties.defaultEncoding[charCode]);
  15279. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15280. }
  15281. this.toFontChar[charCode] = unicodeCharCode;
  15282. }.bind(this));
  15283. }
  15284. this.loadedName = fontName.split('-')[0];
  15285. this.loading = false;
  15286. this.fontType = getFontType(type, subtype);
  15287. return;
  15288. }
  15289. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15290. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15291. // Some TrueType fonts by mistake claim Type1C
  15292. if (isTrueTypeFile(file)) {
  15293. subtype = 'TrueType';
  15294. } else {
  15295. type = 'Type1';
  15296. }
  15297. }
  15298. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15299. type = 'CIDFontType0';
  15300. }
  15301. // XXX: Temporarily change the type for open type so we trigger a warning.
  15302. // This should be removed when we add support for open type.
  15303. if (subtype === 'OpenType') {
  15304. type = 'OpenType';
  15305. }
  15306. var data;
  15307. switch (type) {
  15308. case 'MMType1':
  15309. info('MMType1 font (' + name + '), falling back to Type1.');
  15310. /* falls through */
  15311. case 'Type1':
  15312. case 'CIDFontType0':
  15313. this.mimetype = 'font/opentype';
  15314. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15315. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15316. adjustWidths(properties);
  15317. // Wrap the CFF data inside an OTF font file
  15318. data = this.convert(name, cff, properties);
  15319. break;
  15320. case 'OpenType':
  15321. case 'TrueType':
  15322. case 'CIDFontType2':
  15323. this.mimetype = 'font/opentype';
  15324. // Repair the TrueType file. It is can be damaged in the point of
  15325. // view of the sanitizer
  15326. data = this.checkAndRepair(name, file, properties);
  15327. if (this.isOpenType) {
  15328. type = 'OpenType';
  15329. }
  15330. break;
  15331. default:
  15332. error('Font ' + type + ' is not supported');
  15333. break;
  15334. }
  15335. this.data = data;
  15336. this.fontType = getFontType(type, subtype);
  15337. // Transfer some properties again that could change during font conversion
  15338. this.fontMatrix = properties.fontMatrix;
  15339. this.widths = properties.widths;
  15340. this.defaultWidth = properties.defaultWidth;
  15341. this.encoding = properties.baseEncoding;
  15342. this.seacMap = properties.seacMap;
  15343. this.loading = true;
  15344. }
  15345. Font.getFontID = (function () {
  15346. var ID = 1;
  15347. return function Font_getFontID() {
  15348. return String(ID++);
  15349. };
  15350. })();
  15351. function int16(b0, b1) {
  15352. return (b0 << 8) + b1;
  15353. }
  15354. function int32(b0, b1, b2, b3) {
  15355. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15356. }
  15357. function string16(value) {
  15358. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15359. }
  15360. function safeString16(value) {
  15361. // clamp value to the 16-bit int range
  15362. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15363. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15364. }
  15365. function isTrueTypeFile(file) {
  15366. var header = file.peekBytes(4);
  15367. return readUint32(header, 0) === 0x00010000;
  15368. }
  15369. /**
  15370. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15371. * with their unicode value. It also moves char codes that are in known
  15372. * problematic locations.
  15373. * @return {Object} Two properties:
  15374. * 'toFontChar' - maps original char codes(the value that will be read
  15375. * from commands such as show text) to the char codes that will be used in the
  15376. * font that we build
  15377. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15378. */
  15379. function adjustMapping(charCodeToGlyphId, properties) {
  15380. var toUnicode = properties.toUnicode;
  15381. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15382. var isIdentityUnicode =
  15383. properties.toUnicode instanceof IdentityToUnicodeMap;
  15384. var isCidFontType2 = (properties.type === 'CIDFontType2');
  15385. var newMap = Object.create(null);
  15386. var toFontChar = [];
  15387. var usedFontCharCodes = [];
  15388. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15389. for (var originalCharCode in charCodeToGlyphId) {
  15390. originalCharCode |= 0;
  15391. var glyphId = charCodeToGlyphId[originalCharCode];
  15392. var fontCharCode = originalCharCode;
  15393. // First try to map the value to a unicode position if a non identity map
  15394. // was created.
  15395. if (!isIdentityUnicode) {
  15396. if (toUnicode.get(originalCharCode) !== undefined) {
  15397. var unicode = toUnicode.get(fontCharCode);
  15398. // TODO: Try to map ligatures to the correct spot.
  15399. if (unicode.length === 1) {
  15400. fontCharCode = unicode.charCodeAt(0);
  15401. }
  15402. } else if (isCidFontType2) {
  15403. // For CIDFontType2, move characters not present in toUnicode
  15404. // to the private use area (fixes bug 1028735 and issue 4881).
  15405. fontCharCode = nextAvailableFontCharCode;
  15406. }
  15407. }
  15408. // Try to move control characters, special characters and already mapped
  15409. // characters to the private use area since they will not be drawn by
  15410. // canvas if left in their current position. Also, move characters if the
  15411. // font was symbolic and there is only an identity unicode map since the
  15412. // characters probably aren't in the correct position (fixes an issue
  15413. // with firefox and thuluthfont).
  15414. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15415. fontCharCode <= 0x1f || // Control chars
  15416. fontCharCode === 0x7F || // Control char
  15417. fontCharCode === 0xAD || // Soft hyphen
  15418. fontCharCode === 0xA0 || // Non breaking space
  15419. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15420. // Prevent drawing characters in the specials unicode block.
  15421. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15422. (isSymbolic && isIdentityUnicode)) &&
  15423. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15424. // Loop to try and find a free spot in the private use area.
  15425. do {
  15426. fontCharCode = nextAvailableFontCharCode++;
  15427. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15428. fontCharCode = 0xF020;
  15429. nextAvailableFontCharCode = fontCharCode + 1;
  15430. }
  15431. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15432. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15433. }
  15434. newMap[fontCharCode] = glyphId;
  15435. toFontChar[originalCharCode] = fontCharCode;
  15436. usedFontCharCodes[fontCharCode] = true;
  15437. }
  15438. return {
  15439. toFontChar: toFontChar,
  15440. charCodeToGlyphId: newMap,
  15441. nextAvailableFontCharCode: nextAvailableFontCharCode
  15442. };
  15443. }
  15444. function getRanges(glyphs) {
  15445. // Array.sort() sorts by characters, not numerically, so convert to an
  15446. // array of characters.
  15447. var codes = [];
  15448. for (var charCode in glyphs) {
  15449. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15450. }
  15451. codes.sort(function fontGetRangesSort(a, b) {
  15452. return a.fontCharCode - b.fontCharCode;
  15453. });
  15454. // Split the sorted codes into ranges.
  15455. var ranges = [];
  15456. var length = codes.length;
  15457. for (var n = 0; n < length; ) {
  15458. var start = codes[n].fontCharCode;
  15459. var codeIndices = [codes[n].glyphId];
  15460. ++n;
  15461. var end = start;
  15462. while (n < length && end + 1 === codes[n].fontCharCode) {
  15463. codeIndices.push(codes[n].glyphId);
  15464. ++end;
  15465. ++n;
  15466. if (end === 0xFFFF) {
  15467. break;
  15468. }
  15469. }
  15470. ranges.push([start, end, codeIndices]);
  15471. }
  15472. return ranges;
  15473. }
  15474. function createCmapTable(glyphs) {
  15475. var ranges = getRanges(glyphs);
  15476. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15477. var cmap = '\x00\x00' + // version
  15478. string16(numTables) + // numTables
  15479. '\x00\x03' + // platformID
  15480. '\x00\x01' + // encodingID
  15481. string32(4 + numTables * 8); // start of the table record
  15482. var i, ii, j, jj;
  15483. for (i = ranges.length - 1; i >= 0; --i) {
  15484. if (ranges[i][0] <= 0xFFFF) { break; }
  15485. }
  15486. var bmpLength = i + 1;
  15487. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15488. ranges[i][1] = 0xFFFE;
  15489. }
  15490. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15491. var segCount = bmpLength + trailingRangesCount;
  15492. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15493. // Fill up the 4 parallel arrays describing the segments.
  15494. var startCount = '';
  15495. var endCount = '';
  15496. var idDeltas = '';
  15497. var idRangeOffsets = '';
  15498. var glyphsIds = '';
  15499. var bias = 0;
  15500. var range, start, end, codes;
  15501. for (i = 0, ii = bmpLength; i < ii; i++) {
  15502. range = ranges[i];
  15503. start = range[0];
  15504. end = range[1];
  15505. startCount += string16(start);
  15506. endCount += string16(end);
  15507. codes = range[2];
  15508. var contiguous = true;
  15509. for (j = 1, jj = codes.length; j < jj; ++j) {
  15510. if (codes[j] !== codes[j - 1] + 1) {
  15511. contiguous = false;
  15512. break;
  15513. }
  15514. }
  15515. if (!contiguous) {
  15516. var offset = (segCount - i) * 2 + bias * 2;
  15517. bias += (end - start + 1);
  15518. idDeltas += string16(0);
  15519. idRangeOffsets += string16(offset);
  15520. for (j = 0, jj = codes.length; j < jj; ++j) {
  15521. glyphsIds += string16(codes[j]);
  15522. }
  15523. } else {
  15524. var startCode = codes[0];
  15525. idDeltas += string16((startCode - start) & 0xFFFF);
  15526. idRangeOffsets += string16(0);
  15527. }
  15528. }
  15529. if (trailingRangesCount > 0) {
  15530. endCount += '\xFF\xFF';
  15531. startCount += '\xFF\xFF';
  15532. idDeltas += '\x00\x01';
  15533. idRangeOffsets += '\x00\x00';
  15534. }
  15535. var format314 = '\x00\x00' + // language
  15536. string16(2 * segCount) +
  15537. string16(searchParams.range) +
  15538. string16(searchParams.entry) +
  15539. string16(searchParams.rangeShift) +
  15540. endCount + '\x00\x00' + startCount +
  15541. idDeltas + idRangeOffsets + glyphsIds;
  15542. var format31012 = '';
  15543. var header31012 = '';
  15544. if (numTables > 1) {
  15545. cmap += '\x00\x03' + // platformID
  15546. '\x00\x0A' + // encodingID
  15547. string32(4 + numTables * 8 +
  15548. 4 + format314.length); // start of the table record
  15549. format31012 = '';
  15550. for (i = 0, ii = ranges.length; i < ii; i++) {
  15551. range = ranges[i];
  15552. start = range[0];
  15553. codes = range[2];
  15554. var code = codes[0];
  15555. for (j = 1, jj = codes.length; j < jj; ++j) {
  15556. if (codes[j] !== codes[j - 1] + 1) {
  15557. end = range[0] + j - 1;
  15558. format31012 += string32(start) + // startCharCode
  15559. string32(end) + // endCharCode
  15560. string32(code); // startGlyphID
  15561. start = end + 1;
  15562. code = codes[j];
  15563. }
  15564. }
  15565. format31012 += string32(start) + // startCharCode
  15566. string32(range[1]) + // endCharCode
  15567. string32(code); // startGlyphID
  15568. }
  15569. header31012 = '\x00\x0C' + // format
  15570. '\x00\x00' + // reserved
  15571. string32(format31012.length + 16) + // length
  15572. '\x00\x00\x00\x00' + // language
  15573. string32(format31012.length / 12); // nGroups
  15574. }
  15575. return cmap + '\x00\x04' + // format
  15576. string16(format314.length + 4) + // length
  15577. format314 + header31012 + format31012;
  15578. }
  15579. function validateOS2Table(os2) {
  15580. var stream = new Stream(os2.data);
  15581. var version = stream.getUint16();
  15582. // TODO verify all OS/2 tables fields, but currently we validate only those
  15583. // that give us issues
  15584. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15585. var selection = stream.getUint16();
  15586. if (version < 4 && (selection & 0x0300)) {
  15587. return false;
  15588. }
  15589. var firstChar = stream.getUint16();
  15590. var lastChar = stream.getUint16();
  15591. if (firstChar > lastChar) {
  15592. return false;
  15593. }
  15594. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15595. var usWinAscent = stream.getUint16();
  15596. if (usWinAscent === 0) { // makes font unreadable by windows
  15597. return false;
  15598. }
  15599. // OS/2 appears to be valid, resetting some fields
  15600. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15601. return true;
  15602. }
  15603. function createOS2Table(properties, charstrings, override) {
  15604. override = override || {
  15605. unitsPerEm: 0,
  15606. yMax: 0,
  15607. yMin: 0,
  15608. ascent: 0,
  15609. descent: 0
  15610. };
  15611. var ulUnicodeRange1 = 0;
  15612. var ulUnicodeRange2 = 0;
  15613. var ulUnicodeRange3 = 0;
  15614. var ulUnicodeRange4 = 0;
  15615. var firstCharIndex = null;
  15616. var lastCharIndex = 0;
  15617. if (charstrings) {
  15618. for (var code in charstrings) {
  15619. code |= 0;
  15620. if (firstCharIndex > code || !firstCharIndex) {
  15621. firstCharIndex = code;
  15622. }
  15623. if (lastCharIndex < code) {
  15624. lastCharIndex = code;
  15625. }
  15626. var position = getUnicodeRangeFor(code);
  15627. if (position < 32) {
  15628. ulUnicodeRange1 |= 1 << position;
  15629. } else if (position < 64) {
  15630. ulUnicodeRange2 |= 1 << position - 32;
  15631. } else if (position < 96) {
  15632. ulUnicodeRange3 |= 1 << position - 64;
  15633. } else if (position < 123) {
  15634. ulUnicodeRange4 |= 1 << position - 96;
  15635. } else {
  15636. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15637. }
  15638. }
  15639. } else {
  15640. // TODO
  15641. firstCharIndex = 0;
  15642. lastCharIndex = 255;
  15643. }
  15644. var bbox = properties.bbox || [0, 0, 0, 0];
  15645. var unitsPerEm = (override.unitsPerEm ||
  15646. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15647. // if the font units differ to the PDF glyph space units
  15648. // then scale up the values
  15649. var scale = (properties.ascentScaled ? 1.0 :
  15650. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15651. var typoAscent = (override.ascent ||
  15652. Math.round(scale * (properties.ascent || bbox[3])));
  15653. var typoDescent = (override.descent ||
  15654. Math.round(scale * (properties.descent || bbox[1])));
  15655. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15656. typoDescent = -typoDescent; // fixing incorrect descent
  15657. }
  15658. var winAscent = override.yMax || typoAscent;
  15659. var winDescent = -override.yMin || -typoDescent;
  15660. return '\x00\x03' + // version
  15661. '\x02\x24' + // xAvgCharWidth
  15662. '\x01\xF4' + // usWeightClass
  15663. '\x00\x05' + // usWidthClass
  15664. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15665. '\x02\x8A' + // ySubscriptXSize
  15666. '\x02\xBB' + // ySubscriptYSize
  15667. '\x00\x00' + // ySubscriptXOffset
  15668. '\x00\x8C' + // ySubscriptYOffset
  15669. '\x02\x8A' + // ySuperScriptXSize
  15670. '\x02\xBB' + // ySuperScriptYSize
  15671. '\x00\x00' + // ySuperScriptXOffset
  15672. '\x01\xDF' + // ySuperScriptYOffset
  15673. '\x00\x31' + // yStrikeOutSize
  15674. '\x01\x02' + // yStrikeOutPosition
  15675. '\x00\x00' + // sFamilyClass
  15676. '\x00\x00\x06' +
  15677. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15678. '\x00\x00\x00\x00\x00\x00' + // Panose
  15679. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15680. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15681. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15682. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15683. '\x2A\x32\x31\x2A' + // achVendID
  15684. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15685. string16(firstCharIndex ||
  15686. properties.firstChar) + // usFirstCharIndex
  15687. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15688. string16(typoAscent) + // sTypoAscender
  15689. string16(typoDescent) + // sTypoDescender
  15690. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15691. string16(winAscent) + // usWinAscent
  15692. string16(winDescent) + // usWinDescent
  15693. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15694. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15695. string16(properties.xHeight) + // sxHeight
  15696. string16(properties.capHeight) + // sCapHeight
  15697. string16(0) + // usDefaultChar
  15698. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15699. '\x00\x03'; // usMaxContext
  15700. }
  15701. function createPostTable(properties) {
  15702. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15703. return ('\x00\x03\x00\x00' + // Version number
  15704. string32(angle) + // italicAngle
  15705. '\x00\x00' + // underlinePosition
  15706. '\x00\x00' + // underlineThickness
  15707. string32(properties.fixedPitch) + // isFixedPitch
  15708. '\x00\x00\x00\x00' + // minMemType42
  15709. '\x00\x00\x00\x00' + // maxMemType42
  15710. '\x00\x00\x00\x00' + // minMemType1
  15711. '\x00\x00\x00\x00'); // maxMemType1
  15712. }
  15713. function createNameTable(name, proto) {
  15714. if (!proto) {
  15715. proto = [[], []]; // no strings and unicode strings
  15716. }
  15717. var strings = [
  15718. proto[0][0] || 'Original licence', // 0.Copyright
  15719. proto[0][1] || name, // 1.Font family
  15720. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15721. proto[0][3] || 'uniqueID', // 3.Unique ID
  15722. proto[0][4] || name, // 4.Full font name
  15723. proto[0][5] || 'Version 0.11', // 5.Version
  15724. proto[0][6] || '', // 6.Postscript name
  15725. proto[0][7] || 'Unknown', // 7.Trademark
  15726. proto[0][8] || 'Unknown', // 8.Manufacturer
  15727. proto[0][9] || 'Unknown' // 9.Designer
  15728. ];
  15729. // Mac want 1-byte per character strings while Windows want
  15730. // 2-bytes per character, so duplicate the names table
  15731. var stringsUnicode = [];
  15732. var i, ii, j, jj, str;
  15733. for (i = 0, ii = strings.length; i < ii; i++) {
  15734. str = proto[1][i] || strings[i];
  15735. var strBufUnicode = [];
  15736. for (j = 0, jj = str.length; j < jj; j++) {
  15737. strBufUnicode.push(string16(str.charCodeAt(j)));
  15738. }
  15739. stringsUnicode.push(strBufUnicode.join(''));
  15740. }
  15741. var names = [strings, stringsUnicode];
  15742. var platforms = ['\x00\x01', '\x00\x03'];
  15743. var encodings = ['\x00\x00', '\x00\x01'];
  15744. var languages = ['\x00\x00', '\x04\x09'];
  15745. var namesRecordCount = strings.length * platforms.length;
  15746. var nameTable =
  15747. '\x00\x00' + // format
  15748. string16(namesRecordCount) + // Number of names Record
  15749. string16(namesRecordCount * 12 + 6); // Storage
  15750. // Build the name records field
  15751. var strOffset = 0;
  15752. for (i = 0, ii = platforms.length; i < ii; i++) {
  15753. var strs = names[i];
  15754. for (j = 0, jj = strs.length; j < jj; j++) {
  15755. str = strs[j];
  15756. var nameRecord =
  15757. platforms[i] + // platform ID
  15758. encodings[i] + // encoding ID
  15759. languages[i] + // language ID
  15760. string16(j) + // name ID
  15761. string16(str.length) +
  15762. string16(strOffset);
  15763. nameTable += nameRecord;
  15764. strOffset += str.length;
  15765. }
  15766. }
  15767. nameTable += strings.join('') + stringsUnicode.join('');
  15768. return nameTable;
  15769. }
  15770. Font.prototype = {
  15771. name: null,
  15772. font: null,
  15773. mimetype: null,
  15774. encoding: null,
  15775. get renderer() {
  15776. var renderer = FontRendererFactory.create(this);
  15777. return shadow(this, 'renderer', renderer);
  15778. },
  15779. exportData: function Font_exportData() {
  15780. var data = {};
  15781. for (var i in this) {
  15782. if (this.hasOwnProperty(i)) {
  15783. data[i] = this[i];
  15784. }
  15785. }
  15786. return data;
  15787. },
  15788. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15789. function readTableEntry(file) {
  15790. var tag = bytesToString(file.getBytes(4));
  15791. var checksum = file.getInt32();
  15792. var offset = file.getInt32() >>> 0;
  15793. var length = file.getInt32() >>> 0;
  15794. // Read the table associated data
  15795. var previousPosition = file.pos;
  15796. file.pos = file.start ? file.start : 0;
  15797. file.skip(offset);
  15798. var data = file.getBytes(length);
  15799. file.pos = previousPosition;
  15800. if (tag === 'head') {
  15801. // clearing checksum adjustment
  15802. data[8] = data[9] = data[10] = data[11] = 0;
  15803. data[17] |= 0x20; //Set font optimized for cleartype flag
  15804. }
  15805. return {
  15806. tag: tag,
  15807. checksum: checksum,
  15808. length: length,
  15809. offset: offset,
  15810. data: data
  15811. };
  15812. }
  15813. function readOpenTypeHeader(ttf) {
  15814. return {
  15815. version: bytesToString(ttf.getBytes(4)),
  15816. numTables: ttf.getUint16(),
  15817. searchRange: ttf.getUint16(),
  15818. entrySelector: ttf.getUint16(),
  15819. rangeShift: ttf.getUint16()
  15820. };
  15821. }
  15822. /**
  15823. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15824. * PDF spec
  15825. */
  15826. function readCmapTable(cmap, font, isSymbolicFont) {
  15827. var segment;
  15828. var start = (font.start ? font.start : 0) + cmap.offset;
  15829. font.pos = start;
  15830. var version = font.getUint16();
  15831. var numTables = font.getUint16();
  15832. var potentialTable;
  15833. var canBreak = false;
  15834. // There's an order of preference in terms of which cmap subtable to
  15835. // use:
  15836. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15837. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15838. // The following takes advantage of the fact that the tables are sorted
  15839. // to work.
  15840. for (var i = 0; i < numTables; i++) {
  15841. var platformId = font.getUint16();
  15842. var encodingId = font.getUint16();
  15843. var offset = font.getInt32() >>> 0;
  15844. var useTable = false;
  15845. if (platformId === 1 && encodingId === 0) {
  15846. useTable = true;
  15847. // Continue the loop since there still may be a higher priority
  15848. // table.
  15849. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15850. useTable = true;
  15851. canBreak = true;
  15852. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15853. useTable = true;
  15854. canBreak = true;
  15855. }
  15856. if (useTable) {
  15857. potentialTable = {
  15858. platformId: platformId,
  15859. encodingId: encodingId,
  15860. offset: offset
  15861. };
  15862. }
  15863. if (canBreak) {
  15864. break;
  15865. }
  15866. }
  15867. if (!potentialTable) {
  15868. warn('Could not find a preferred cmap table.');
  15869. return {
  15870. platformId: -1,
  15871. encodingId: -1,
  15872. mappings: [],
  15873. hasShortCmap: false
  15874. };
  15875. }
  15876. font.pos = start + potentialTable.offset;
  15877. var format = font.getUint16();
  15878. var length = font.getUint16();
  15879. var language = font.getUint16();
  15880. var hasShortCmap = false;
  15881. var mappings = [];
  15882. var j, glyphId;
  15883. // TODO(mack): refactor this cmap subtable reading logic out
  15884. if (format === 0) {
  15885. for (j = 0; j < 256; j++) {
  15886. var index = font.getByte();
  15887. if (!index) {
  15888. continue;
  15889. }
  15890. mappings.push({
  15891. charCode: j,
  15892. glyphId: index
  15893. });
  15894. }
  15895. hasShortCmap = true;
  15896. } else if (format === 4) {
  15897. // re-creating the table in format 4 since the encoding
  15898. // might be changed
  15899. var segCount = (font.getUint16() >> 1);
  15900. font.getBytes(6); // skipping range fields
  15901. var segIndex, segments = [];
  15902. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15903. segments.push({ end: font.getUint16() });
  15904. }
  15905. font.getUint16();
  15906. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15907. segments[segIndex].start = font.getUint16();
  15908. }
  15909. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15910. segments[segIndex].delta = font.getUint16();
  15911. }
  15912. var offsetsCount = 0;
  15913. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15914. segment = segments[segIndex];
  15915. var rangeOffset = font.getUint16();
  15916. if (!rangeOffset) {
  15917. segment.offsetIndex = -1;
  15918. continue;
  15919. }
  15920. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15921. segment.offsetIndex = offsetIndex;
  15922. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15923. segment.end - segment.start + 1);
  15924. }
  15925. var offsets = [];
  15926. for (j = 0; j < offsetsCount; j++) {
  15927. offsets.push(font.getUint16());
  15928. }
  15929. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15930. segment = segments[segIndex];
  15931. start = segment.start;
  15932. var end = segment.end;
  15933. var delta = segment.delta;
  15934. offsetIndex = segment.offsetIndex;
  15935. for (j = start; j <= end; j++) {
  15936. if (j === 0xFFFF) {
  15937. continue;
  15938. }
  15939. glyphId = (offsetIndex < 0 ?
  15940. j : offsets[offsetIndex + j - start]);
  15941. glyphId = (glyphId + delta) & 0xFFFF;
  15942. if (glyphId === 0) {
  15943. continue;
  15944. }
  15945. mappings.push({
  15946. charCode: j,
  15947. glyphId: glyphId
  15948. });
  15949. }
  15950. }
  15951. } else if (format === 6) {
  15952. // Format 6 is a 2-bytes dense mapping, which means the font data
  15953. // lives glue together even if they are pretty far in the unicode
  15954. // table. (This looks weird, so I can have missed something), this
  15955. // works on Linux but seems to fails on Mac so let's rewrite the
  15956. // cmap table to a 3-1-4 style
  15957. var firstCode = font.getUint16();
  15958. var entryCount = font.getUint16();
  15959. for (j = 0; j < entryCount; j++) {
  15960. glyphId = font.getUint16();
  15961. var charCode = firstCode + j;
  15962. mappings.push({
  15963. charCode: charCode,
  15964. glyphId: glyphId
  15965. });
  15966. }
  15967. } else {
  15968. error('cmap table has unsupported format: ' + format);
  15969. }
  15970. // removing duplicate entries
  15971. mappings.sort(function (a, b) {
  15972. return a.charCode - b.charCode;
  15973. });
  15974. for (i = 1; i < mappings.length; i++) {
  15975. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15976. mappings.splice(i, 1);
  15977. i--;
  15978. }
  15979. }
  15980. return {
  15981. platformId: potentialTable.platformId,
  15982. encodingId: potentialTable.encodingId,
  15983. mappings: mappings,
  15984. hasShortCmap: hasShortCmap
  15985. };
  15986. }
  15987. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15988. if (!header) {
  15989. if (metrics) {
  15990. metrics.data = null;
  15991. }
  15992. return;
  15993. }
  15994. font.pos = (font.start ? font.start : 0) + header.offset;
  15995. font.pos += header.length - 2;
  15996. var numOfMetrics = font.getUint16();
  15997. if (numOfMetrics > numGlyphs) {
  15998. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  15999. 'greater than the numGlyphs (' + numGlyphs + ')');
  16000. // Reduce numOfMetrics if it is greater than numGlyphs
  16001. numOfMetrics = numGlyphs;
  16002. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16003. header.data[35] = numOfMetrics & 0x00ff;
  16004. }
  16005. var numOfSidebearings = numGlyphs - numOfMetrics;
  16006. var numMissing = numOfSidebearings -
  16007. ((metrics.length - numOfMetrics * 4) >> 1);
  16008. if (numMissing > 0) {
  16009. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16010. // Since we need to add two properties for each glyph, this explains
  16011. // the use of |numMissing * 2| when initializing the typed array.
  16012. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16013. entries.set(metrics.data);
  16014. metrics.data = entries;
  16015. }
  16016. }
  16017. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16018. hintsValid) {
  16019. if (sourceEnd - sourceStart <= 12) {
  16020. // glyph with data less than 12 is invalid one
  16021. return 0;
  16022. }
  16023. var glyf = source.subarray(sourceStart, sourceEnd);
  16024. var contoursCount = (glyf[0] << 8) | glyf[1];
  16025. if (contoursCount & 0x8000) {
  16026. // complex glyph, writing as is
  16027. dest.set(glyf, destStart);
  16028. return glyf.length;
  16029. }
  16030. var i, j = 10, flagsCount = 0;
  16031. for (i = 0; i < contoursCount; i++) {
  16032. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16033. flagsCount = endPoint + 1;
  16034. j += 2;
  16035. }
  16036. // skipping instructions
  16037. var instructionsStart = j;
  16038. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16039. j += 2 + instructionsLength;
  16040. var instructionsEnd = j;
  16041. // validating flags
  16042. var coordinatesLength = 0;
  16043. for (i = 0; i < flagsCount; i++) {
  16044. var flag = glyf[j++];
  16045. if (flag & 0xC0) {
  16046. // reserved flags must be zero, cleaning up
  16047. glyf[j - 1] = flag & 0x3F;
  16048. }
  16049. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16050. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16051. coordinatesLength += xyLength;
  16052. if (flag & 8) {
  16053. var repeat = glyf[j++];
  16054. i += repeat;
  16055. coordinatesLength += repeat * xyLength;
  16056. }
  16057. }
  16058. // glyph without coordinates will be rejected
  16059. if (coordinatesLength === 0) {
  16060. return 0;
  16061. }
  16062. var glyphDataLength = j + coordinatesLength;
  16063. if (glyphDataLength > glyf.length) {
  16064. // not enough data for coordinates
  16065. return 0;
  16066. }
  16067. if (!hintsValid && instructionsLength > 0) {
  16068. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16069. dest.set([0, 0], destStart + instructionsStart);
  16070. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16071. destStart + instructionsStart + 2);
  16072. glyphDataLength -= instructionsLength;
  16073. if (glyf.length - glyphDataLength > 3) {
  16074. glyphDataLength = (glyphDataLength + 3) & ~3;
  16075. }
  16076. return glyphDataLength;
  16077. }
  16078. if (glyf.length - glyphDataLength > 3) {
  16079. // truncating and aligning to 4 bytes the long glyph data
  16080. glyphDataLength = (glyphDataLength + 3) & ~3;
  16081. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16082. return glyphDataLength;
  16083. }
  16084. // glyph data is fine
  16085. dest.set(glyf, destStart);
  16086. return glyf.length;
  16087. }
  16088. function sanitizeHead(head, numGlyphs, locaLength) {
  16089. var data = head.data;
  16090. // Validate version:
  16091. // Should always be 0x00010000
  16092. var version = int32(data[0], data[1], data[2], data[3]);
  16093. if (version >> 16 !== 1) {
  16094. info('Attempting to fix invalid version in head table: ' + version);
  16095. data[0] = 0;
  16096. data[1] = 1;
  16097. data[2] = 0;
  16098. data[3] = 0;
  16099. }
  16100. var indexToLocFormat = int16(data[50], data[51]);
  16101. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16102. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16103. indexToLocFormat);
  16104. // The value of indexToLocFormat should be 0 if the loca table
  16105. // consists of short offsets, and should be 1 if the loca table
  16106. // consists of long offsets.
  16107. //
  16108. // The number of entries in the loca table should be numGlyphs + 1.
  16109. //
  16110. // Using this information, we can work backwards to deduce if the
  16111. // size of each offset in the loca table, and thus figure out the
  16112. // appropriate value for indexToLocFormat.
  16113. var numGlyphsPlusOne = numGlyphs + 1;
  16114. if (locaLength === numGlyphsPlusOne << 1) {
  16115. // 0x0000 indicates the loca table consists of short offsets
  16116. data[50] = 0;
  16117. data[51] = 0;
  16118. } else if (locaLength === numGlyphsPlusOne << 2) {
  16119. // 0x0001 indicates the loca table consists of long offsets
  16120. data[50] = 0;
  16121. data[51] = 1;
  16122. } else {
  16123. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16124. }
  16125. }
  16126. }
  16127. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16128. isGlyphLocationsLong, hintsValid,
  16129. dupFirstEntry) {
  16130. var itemSize, itemDecode, itemEncode;
  16131. if (isGlyphLocationsLong) {
  16132. itemSize = 4;
  16133. itemDecode = function fontItemDecodeLong(data, offset) {
  16134. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16135. (data[offset + 2] << 8) | data[offset + 3];
  16136. };
  16137. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16138. data[offset] = (value >>> 24) & 0xFF;
  16139. data[offset + 1] = (value >> 16) & 0xFF;
  16140. data[offset + 2] = (value >> 8) & 0xFF;
  16141. data[offset + 3] = value & 0xFF;
  16142. };
  16143. } else {
  16144. itemSize = 2;
  16145. itemDecode = function fontItemDecode(data, offset) {
  16146. return (data[offset] << 9) | (data[offset + 1] << 1);
  16147. };
  16148. itemEncode = function fontItemEncode(data, offset, value) {
  16149. data[offset] = (value >> 9) & 0xFF;
  16150. data[offset + 1] = (value >> 1) & 0xFF;
  16151. };
  16152. }
  16153. var locaData = loca.data;
  16154. var locaDataSize = itemSize * (1 + numGlyphs);
  16155. // is loca.data too short or long?
  16156. if (locaData.length !== locaDataSize) {
  16157. locaData = new Uint8Array(locaDataSize);
  16158. locaData.set(loca.data.subarray(0, locaDataSize));
  16159. loca.data = locaData;
  16160. }
  16161. // removing the invalid glyphs
  16162. var oldGlyfData = glyf.data;
  16163. var oldGlyfDataLength = oldGlyfData.length;
  16164. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16165. var startOffset = itemDecode(locaData, 0);
  16166. var writeOffset = 0;
  16167. itemEncode(locaData, 0, writeOffset);
  16168. var i, j;
  16169. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16170. var endOffset = itemDecode(locaData, j);
  16171. if (endOffset > oldGlyfDataLength &&
  16172. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16173. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16174. // the glyf table size, which makes last glyph out of range.
  16175. endOffset = oldGlyfDataLength;
  16176. }
  16177. if (endOffset > oldGlyfDataLength) {
  16178. // glyph end offset points outside glyf data, rejecting the glyph
  16179. itemEncode(locaData, j, writeOffset);
  16180. startOffset = endOffset;
  16181. continue;
  16182. }
  16183. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16184. newGlyfData, writeOffset, hintsValid);
  16185. writeOffset += newLength;
  16186. itemEncode(locaData, j, writeOffset);
  16187. startOffset = endOffset;
  16188. }
  16189. if (writeOffset === 0) {
  16190. // glyf table cannot be empty -- redoing the glyf and loca tables
  16191. // to have single glyph with one point
  16192. var simpleGlyph = new Uint8Array(
  16193. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16194. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16195. itemEncode(locaData, j, simpleGlyph.length);
  16196. }
  16197. glyf.data = simpleGlyph;
  16198. return;
  16199. }
  16200. if (dupFirstEntry) {
  16201. var firstEntryLength = itemDecode(locaData, itemSize);
  16202. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16203. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16204. } else {
  16205. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16206. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16207. }
  16208. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16209. itemEncode(loca.data, locaData.length - itemSize,
  16210. writeOffset + firstEntryLength);
  16211. } else {
  16212. glyf.data = newGlyfData.subarray(0, writeOffset);
  16213. }
  16214. }
  16215. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16216. var start = (font.start ? font.start : 0) + post.offset;
  16217. font.pos = start;
  16218. var length = post.length, end = start + length;
  16219. var version = font.getInt32();
  16220. // skip rest to the tables
  16221. font.getBytes(28);
  16222. var glyphNames;
  16223. var valid = true;
  16224. var i;
  16225. switch (version) {
  16226. case 0x00010000:
  16227. glyphNames = MacStandardGlyphOrdering;
  16228. break;
  16229. case 0x00020000:
  16230. var numGlyphs = font.getUint16();
  16231. if (numGlyphs !== maxpNumGlyphs) {
  16232. valid = false;
  16233. break;
  16234. }
  16235. var glyphNameIndexes = [];
  16236. for (i = 0; i < numGlyphs; ++i) {
  16237. var index = font.getUint16();
  16238. if (index >= 32768) {
  16239. valid = false;
  16240. break;
  16241. }
  16242. glyphNameIndexes.push(index);
  16243. }
  16244. if (!valid) {
  16245. break;
  16246. }
  16247. var customNames = [];
  16248. var strBuf = [];
  16249. while (font.pos < end) {
  16250. var stringLength = font.getByte();
  16251. strBuf.length = stringLength;
  16252. for (i = 0; i < stringLength; ++i) {
  16253. strBuf[i] = String.fromCharCode(font.getByte());
  16254. }
  16255. customNames.push(strBuf.join(''));
  16256. }
  16257. glyphNames = [];
  16258. for (i = 0; i < numGlyphs; ++i) {
  16259. var j = glyphNameIndexes[i];
  16260. if (j < 258) {
  16261. glyphNames.push(MacStandardGlyphOrdering[j]);
  16262. continue;
  16263. }
  16264. glyphNames.push(customNames[j - 258]);
  16265. }
  16266. break;
  16267. case 0x00030000:
  16268. break;
  16269. default:
  16270. warn('Unknown/unsupported post table version ' + version);
  16271. valid = false;
  16272. break;
  16273. }
  16274. properties.glyphNames = glyphNames;
  16275. return valid;
  16276. }
  16277. function readNameTable(nameTable) {
  16278. var start = (font.start ? font.start : 0) + nameTable.offset;
  16279. font.pos = start;
  16280. var names = [[], []];
  16281. var length = nameTable.length, end = start + length;
  16282. var format = font.getUint16();
  16283. var FORMAT_0_HEADER_LENGTH = 6;
  16284. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16285. // unsupported name table format or table "too" small
  16286. return names;
  16287. }
  16288. var numRecords = font.getUint16();
  16289. var stringsStart = font.getUint16();
  16290. var records = [];
  16291. var NAME_RECORD_LENGTH = 12;
  16292. var i, ii;
  16293. for (i = 0; i < numRecords &&
  16294. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16295. var r = {
  16296. platform: font.getUint16(),
  16297. encoding: font.getUint16(),
  16298. language: font.getUint16(),
  16299. name: font.getUint16(),
  16300. length: font.getUint16(),
  16301. offset: font.getUint16()
  16302. };
  16303. // using only Macintosh and Windows platform/encoding names
  16304. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16305. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16306. records.push(r);
  16307. }
  16308. }
  16309. for (i = 0, ii = records.length; i < ii; i++) {
  16310. var record = records[i];
  16311. var pos = start + stringsStart + record.offset;
  16312. if (pos + record.length > end) {
  16313. continue; // outside of name table, ignoring
  16314. }
  16315. font.pos = pos;
  16316. var nameIndex = record.name;
  16317. if (record.encoding) {
  16318. // unicode
  16319. var str = '';
  16320. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16321. str += String.fromCharCode(font.getUint16());
  16322. }
  16323. names[1][nameIndex] = str;
  16324. } else {
  16325. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16326. }
  16327. }
  16328. return names;
  16329. }
  16330. var TTOpsStackDeltas = [
  16331. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16332. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16333. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16334. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16335. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16336. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16337. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16338. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16339. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16340. // 0xC0-DF == -1 and 0xE0-FF == -2
  16341. function sanitizeTTProgram(table, ttContext) {
  16342. var data = table.data;
  16343. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16344. var stack = [];
  16345. var callstack = [];
  16346. var functionsCalled = [];
  16347. var tooComplexToFollowFunctions =
  16348. ttContext.tooComplexToFollowFunctions;
  16349. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16350. for (var ii = data.length; i < ii;) {
  16351. var op = data[i++];
  16352. // The TrueType instruction set docs can be found at
  16353. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16354. if (op === 0x40) { // NPUSHB - pushes n bytes
  16355. n = data[i++];
  16356. if (inFDEF || inELSE) {
  16357. i += n;
  16358. } else {
  16359. for (j = 0; j < n; j++) {
  16360. stack.push(data[i++]);
  16361. }
  16362. }
  16363. } else if (op === 0x41) { // NPUSHW - pushes n words
  16364. n = data[i++];
  16365. if (inFDEF || inELSE) {
  16366. i += n * 2;
  16367. } else {
  16368. for (j = 0; j < n; j++) {
  16369. b = data[i++];
  16370. stack.push((b << 8) | data[i++]);
  16371. }
  16372. }
  16373. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16374. n = op - 0xB0 + 1;
  16375. if (inFDEF || inELSE) {
  16376. i += n;
  16377. } else {
  16378. for (j = 0; j < n; j++) {
  16379. stack.push(data[i++]);
  16380. }
  16381. }
  16382. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16383. n = op - 0xB8 + 1;
  16384. if (inFDEF || inELSE) {
  16385. i += n * 2;
  16386. } else {
  16387. for (j = 0; j < n; j++) {
  16388. b = data[i++];
  16389. stack.push((b << 8) | data[i++]);
  16390. }
  16391. }
  16392. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16393. if (!inFDEF && !inELSE) {
  16394. // collecting inforamtion about which functions are used
  16395. funcId = stack[stack.length - 1];
  16396. ttContext.functionsUsed[funcId] = true;
  16397. if (funcId in ttContext.functionsStackDeltas) {
  16398. stack.length += ttContext.functionsStackDeltas[funcId];
  16399. } else if (funcId in ttContext.functionsDefined &&
  16400. functionsCalled.indexOf(funcId) < 0) {
  16401. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16402. functionsCalled.push(funcId);
  16403. pc = ttContext.functionsDefined[funcId];
  16404. if (!pc) {
  16405. warn('TT: CALL non-existent function');
  16406. ttContext.hintsValid = false;
  16407. return;
  16408. }
  16409. data = pc.data;
  16410. i = pc.i;
  16411. }
  16412. }
  16413. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16414. if (inFDEF || inELSE) {
  16415. warn('TT: nested FDEFs not allowed');
  16416. tooComplexToFollowFunctions = true;
  16417. }
  16418. inFDEF = true;
  16419. // collecting inforamtion about which functions are defined
  16420. lastDeff = i;
  16421. funcId = stack.pop();
  16422. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16423. } else if (op === 0x2D) { // ENDF - end of function
  16424. if (inFDEF) {
  16425. inFDEF = false;
  16426. lastEndf = i;
  16427. } else {
  16428. pc = callstack.pop();
  16429. if (!pc) {
  16430. warn('TT: ENDF bad stack');
  16431. ttContext.hintsValid = false;
  16432. return;
  16433. }
  16434. funcId = functionsCalled.pop();
  16435. data = pc.data;
  16436. i = pc.i;
  16437. ttContext.functionsStackDeltas[funcId] =
  16438. stack.length - pc.stackTop;
  16439. }
  16440. } else if (op === 0x89) { // IDEF - instruction definition
  16441. if (inFDEF || inELSE) {
  16442. warn('TT: nested IDEFs not allowed');
  16443. tooComplexToFollowFunctions = true;
  16444. }
  16445. inFDEF = true;
  16446. // recording it as a function to track ENDF
  16447. lastDeff = i;
  16448. } else if (op === 0x58) { // IF
  16449. ++ifLevel;
  16450. } else if (op === 0x1B) { // ELSE
  16451. inELSE = ifLevel;
  16452. } else if (op === 0x59) { // EIF
  16453. if (inELSE === ifLevel) {
  16454. inELSE = 0;
  16455. }
  16456. --ifLevel;
  16457. } else if (op === 0x1C) { // JMPR
  16458. if (!inFDEF && !inELSE) {
  16459. var offset = stack[stack.length - 1];
  16460. // only jumping forward to prevent infinite loop
  16461. if (offset > 0) {
  16462. i += offset - 1;
  16463. }
  16464. }
  16465. }
  16466. // Adjusting stack not extactly, but just enough to get function id
  16467. if (!inFDEF && !inELSE) {
  16468. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16469. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16470. if (op >= 0x71 && op <= 0x75) {
  16471. n = stack.pop();
  16472. if (n === n) {
  16473. stackDelta = -n * 2;
  16474. }
  16475. }
  16476. while (stackDelta < 0 && stack.length > 0) {
  16477. stack.pop();
  16478. stackDelta++;
  16479. }
  16480. while (stackDelta > 0) {
  16481. stack.push(NaN); // pushing any number into stack
  16482. stackDelta--;
  16483. }
  16484. }
  16485. }
  16486. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16487. var content = [data];
  16488. if (i > data.length) {
  16489. content.push(new Uint8Array(i - data.length));
  16490. }
  16491. if (lastDeff > lastEndf) {
  16492. warn('TT: complementing a missing function tail');
  16493. // new function definition started, but not finished
  16494. // complete function by [CLEAR, ENDF]
  16495. content.push(new Uint8Array([0x22, 0x2D]));
  16496. }
  16497. foldTTTable(table, content);
  16498. }
  16499. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16500. if (ttContext.tooComplexToFollowFunctions) {
  16501. return;
  16502. }
  16503. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16504. warn('TT: more functions defined than expected');
  16505. ttContext.hintsValid = false;
  16506. return;
  16507. }
  16508. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16509. if (j > maxFunctionDefs) {
  16510. warn('TT: invalid function id: ' + j);
  16511. ttContext.hintsValid = false;
  16512. return;
  16513. }
  16514. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16515. warn('TT: undefined function: ' + j);
  16516. ttContext.hintsValid = false;
  16517. return;
  16518. }
  16519. }
  16520. }
  16521. function foldTTTable(table, content) {
  16522. if (content.length > 1) {
  16523. // concatenating the content items
  16524. var newLength = 0;
  16525. var j, jj;
  16526. for (j = 0, jj = content.length; j < jj; j++) {
  16527. newLength += content[j].length;
  16528. }
  16529. newLength = (newLength + 3) & ~3;
  16530. var result = new Uint8Array(newLength);
  16531. var pos = 0;
  16532. for (j = 0, jj = content.length; j < jj; j++) {
  16533. result.set(content[j], pos);
  16534. pos += content[j].length;
  16535. }
  16536. table.data = result;
  16537. table.length = newLength;
  16538. }
  16539. }
  16540. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16541. var ttContext = {
  16542. functionsDefined: [],
  16543. functionsUsed: [],
  16544. functionsStackDeltas: [],
  16545. tooComplexToFollowFunctions: false,
  16546. hintsValid: true
  16547. };
  16548. if (fpgm) {
  16549. sanitizeTTProgram(fpgm, ttContext);
  16550. }
  16551. if (prep) {
  16552. sanitizeTTProgram(prep, ttContext);
  16553. }
  16554. if (fpgm) {
  16555. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16556. }
  16557. if (cvt && (cvt.length & 1)) {
  16558. var cvtData = new Uint8Array(cvt.length + 1);
  16559. cvtData.set(cvt.data);
  16560. cvt.data = cvtData;
  16561. }
  16562. return ttContext.hintsValid;
  16563. }
  16564. // The following steps modify the original font data, making copy
  16565. font = new Stream(new Uint8Array(font.getBytes()));
  16566. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16567. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16568. var header = readOpenTypeHeader(font);
  16569. var numTables = header.numTables;
  16570. var cff, cffFile;
  16571. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16572. hmtx: null, maxp: null, name: null, post: null };
  16573. var table;
  16574. for (var i = 0; i < numTables; i++) {
  16575. table = readTableEntry(font);
  16576. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16577. continue; // skipping table if it's not a required or optional table
  16578. }
  16579. if (table.length === 0) {
  16580. continue; // skipping empty tables
  16581. }
  16582. tables[table.tag] = table;
  16583. }
  16584. var isTrueType = !tables['CFF '];
  16585. if (!isTrueType) {
  16586. // OpenType font
  16587. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16588. // no major tables: throwing everything at CFFFont
  16589. cffFile = new Stream(tables['CFF '].data);
  16590. cff = new CFFFont(cffFile, properties);
  16591. return this.convert(name, cff, properties);
  16592. }
  16593. delete tables.glyf;
  16594. delete tables.loca;
  16595. delete tables.fpgm;
  16596. delete tables.prep;
  16597. delete tables['cvt '];
  16598. this.isOpenType = true;
  16599. } else {
  16600. if (!tables.glyf || !tables.loca) {
  16601. error('Required "glyf" or "loca" tables are not found');
  16602. }
  16603. this.isOpenType = false;
  16604. }
  16605. if (!tables.maxp) {
  16606. error('Required "maxp" table is not found');
  16607. }
  16608. font.pos = (font.start || 0) + tables.maxp.offset;
  16609. var version = font.getInt32();
  16610. var numGlyphs = font.getUint16();
  16611. var maxFunctionDefs = 0;
  16612. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16613. // maxZones can be invalid
  16614. font.pos += 8;
  16615. var maxZones = font.getUint16();
  16616. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16617. tables.maxp.data[14] = 0;
  16618. tables.maxp.data[15] = 2;
  16619. }
  16620. font.pos += 4;
  16621. maxFunctionDefs = font.getUint16();
  16622. }
  16623. var dupFirstEntry = false;
  16624. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16625. properties.toUnicode.get(0) > '\u0000') {
  16626. // oracle's defect (see 3427), duplicating first entry
  16627. dupFirstEntry = true;
  16628. numGlyphs++;
  16629. tables.maxp.data[4] = numGlyphs >> 8;
  16630. tables.maxp.data[5] = numGlyphs & 255;
  16631. }
  16632. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16633. tables['cvt '], maxFunctionDefs);
  16634. if (!hintsValid) {
  16635. delete tables.fpgm;
  16636. delete tables.prep;
  16637. delete tables['cvt '];
  16638. }
  16639. // Ensure the hmtx table contains the advance width and
  16640. // sidebearings information for numGlyphs in the maxp table
  16641. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16642. if (!tables.head) {
  16643. error('Required "head" table is not found');
  16644. }
  16645. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16646. if (isTrueType) {
  16647. var isGlyphLocationsLong = int16(tables.head.data[50],
  16648. tables.head.data[51]);
  16649. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16650. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16651. }
  16652. if (!tables.hhea) {
  16653. error('Required "hhea" table is not found');
  16654. }
  16655. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16656. // Sometimes it's 0. That needs to be fixed
  16657. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16658. tables.hhea.data[10] = 0xFF;
  16659. tables.hhea.data[11] = 0xFF;
  16660. }
  16661. // The 'post' table has glyphs names.
  16662. if (tables.post) {
  16663. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16664. if (!valid) {
  16665. tables.post = null;
  16666. }
  16667. }
  16668. var charCodeToGlyphId = [], charCode;
  16669. if (properties.type === 'CIDFontType2') {
  16670. var cidToGidMap = properties.cidToGidMap || [];
  16671. var cidToGidMapLength = cidToGidMap.length;
  16672. properties.cMap.forEach(function(charCode, cid) {
  16673. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16674. var glyphId = -1;
  16675. if (cidToGidMapLength === 0) {
  16676. glyphId = charCode;
  16677. } else if (cidToGidMap[cid] !== undefined) {
  16678. glyphId = cidToGidMap[cid];
  16679. }
  16680. if (glyphId >= 0 && glyphId < numGlyphs) {
  16681. charCodeToGlyphId[charCode] = glyphId;
  16682. }
  16683. });
  16684. if (dupFirstEntry) {
  16685. charCodeToGlyphId[0] = numGlyphs - 1;
  16686. }
  16687. } else {
  16688. // Most of the following logic in this code branch is based on the
  16689. // 9.6.6.4 of the PDF spec.
  16690. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16691. var cmapPlatformId = cmapTable.platformId;
  16692. var cmapEncodingId = cmapTable.encodingId;
  16693. var cmapMappings = cmapTable.mappings;
  16694. var cmapMappingsLength = cmapMappings.length;
  16695. var hasEncoding = properties.differences.length ||
  16696. !!properties.baseEncodingName;
  16697. // The spec seems to imply that if the font is symbolic the encoding
  16698. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16699. // where the the font is symbolic and it has an encoding.
  16700. if (hasEncoding &&
  16701. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16702. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16703. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16704. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16705. // When no preferred cmap table was found and |baseEncodingName| is
  16706. // one of the predefined encodings, we seem to obtain a better
  16707. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16708. // TODO: Note that this is a hack which should be removed as soon as
  16709. // we have proper support for more exotic cmap tables.
  16710. var baseEncoding = [];
  16711. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16712. properties.baseEncodingName === 'WinAnsiEncoding') {
  16713. baseEncoding = Encodings[properties.baseEncodingName];
  16714. }
  16715. for (charCode = 0; charCode < 256; charCode++) {
  16716. var glyphName;
  16717. if (this.differences && charCode in this.differences) {
  16718. glyphName = this.differences[charCode];
  16719. } else if (charCode in baseEncoding &&
  16720. baseEncoding[charCode] !== '') {
  16721. glyphName = baseEncoding[charCode];
  16722. } else {
  16723. glyphName = Encodings.StandardEncoding[charCode];
  16724. }
  16725. if (!glyphName) {
  16726. continue;
  16727. }
  16728. var unicodeOrCharCode;
  16729. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16730. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16731. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16732. // TODO: the encoding needs to be updated with mac os table.
  16733. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16734. }
  16735. var found = false;
  16736. for (i = 0; i < cmapMappingsLength; ++i) {
  16737. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16738. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16739. found = true;
  16740. break;
  16741. }
  16742. }
  16743. if (!found && properties.glyphNames) {
  16744. // Try to map using the post table. There are currently no known
  16745. // pdfs that this fixes.
  16746. var glyphId = properties.glyphNames.indexOf(glyphName);
  16747. if (glyphId > 0) {
  16748. charCodeToGlyphId[charCode] = glyphId;
  16749. }
  16750. }
  16751. }
  16752. } else {
  16753. // For (3, 0) cmap tables:
  16754. // The charcode key being stored in charCodeToGlyphId is the lower
  16755. // byte of the two-byte charcodes of the cmap table since according to
  16756. // the spec: 'each byte from the string shall be prepended with the
  16757. // high byte of the range [of charcodes in the cmap table], to form
  16758. // a two-byte character, which shall be used to select the
  16759. // associated glyph description from the subtable'.
  16760. //
  16761. // For (1, 0) cmap tables:
  16762. // 'single bytes from the string shall be used to look up the
  16763. // associated glyph descriptions from the subtable'. This means
  16764. // charcodes in the cmap will be single bytes, so no-op since
  16765. // glyph.charCode & 0xFF === glyph.charCode
  16766. for (i = 0; i < cmapMappingsLength; ++i) {
  16767. charCode = cmapMappings[i].charCode & 0xFF;
  16768. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16769. }
  16770. }
  16771. }
  16772. if (charCodeToGlyphId.length === 0) {
  16773. // defines at least one glyph
  16774. charCodeToGlyphId[0] = 0;
  16775. }
  16776. // Converting glyphs and ids into font's cmap table
  16777. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16778. this.toFontChar = newMapping.toFontChar;
  16779. tables.cmap = {
  16780. tag: 'cmap',
  16781. data: createCmapTable(newMapping.charCodeToGlyphId)
  16782. };
  16783. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16784. // extract some more font properties from the OpenType head and
  16785. // hhea tables; yMin and descent value are always negative
  16786. var override = {
  16787. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16788. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16789. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16790. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16791. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16792. };
  16793. tables['OS/2'] = {
  16794. tag: 'OS/2',
  16795. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16796. override)
  16797. };
  16798. }
  16799. // Rewrite the 'post' table if needed
  16800. if (!tables.post) {
  16801. tables.post = {
  16802. tag: 'post',
  16803. data: createPostTable(properties)
  16804. };
  16805. }
  16806. if (!isTrueType) {
  16807. try {
  16808. // Trying to repair CFF file
  16809. cffFile = new Stream(tables['CFF '].data);
  16810. var parser = new CFFParser(cffFile, properties);
  16811. cff = parser.parse();
  16812. var compiler = new CFFCompiler(cff);
  16813. tables['CFF '].data = compiler.compile();
  16814. } catch (e) {
  16815. warn('Failed to compile font ' + properties.loadedName);
  16816. }
  16817. }
  16818. // Re-creating 'name' table
  16819. if (!tables.name) {
  16820. tables.name = {
  16821. tag: 'name',
  16822. data: createNameTable(this.name)
  16823. };
  16824. } else {
  16825. // ... using existing 'name' table as prototype
  16826. var namePrototype = readNameTable(tables.name);
  16827. tables.name.data = createNameTable(name, namePrototype);
  16828. }
  16829. var builder = new OpenTypeFileBuilder(header.version);
  16830. for (var tableTag in tables) {
  16831. builder.addTable(tableTag, tables[tableTag].data);
  16832. }
  16833. return builder.toArray();
  16834. },
  16835. convert: function Font_convert(fontName, font, properties) {
  16836. // TODO: Check the charstring widths to determine this.
  16837. properties.fixedPitch = false;
  16838. var mapping = font.getGlyphMapping(properties);
  16839. var newMapping = adjustMapping(mapping, properties);
  16840. this.toFontChar = newMapping.toFontChar;
  16841. var numGlyphs = font.numGlyphs;
  16842. function getCharCodes(charCodeToGlyphId, glyphId) {
  16843. var charCodes = null;
  16844. for (var charCode in charCodeToGlyphId) {
  16845. if (glyphId === charCodeToGlyphId[charCode]) {
  16846. if (!charCodes) {
  16847. charCodes = [];
  16848. }
  16849. charCodes.push(charCode | 0);
  16850. }
  16851. }
  16852. return charCodes;
  16853. }
  16854. function createCharCode(charCodeToGlyphId, glyphId) {
  16855. for (var charCode in charCodeToGlyphId) {
  16856. if (glyphId === charCodeToGlyphId[charCode]) {
  16857. return charCode | 0;
  16858. }
  16859. }
  16860. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16861. glyphId;
  16862. return newMapping.nextAvailableFontCharCode++;
  16863. }
  16864. var seacs = font.seacs;
  16865. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16866. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16867. var charset = font.getCharset();
  16868. var seacMap = Object.create(null);
  16869. for (var glyphId in seacs) {
  16870. glyphId |= 0;
  16871. var seac = seacs[glyphId];
  16872. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16873. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16874. var baseGlyphId = charset.indexOf(baseGlyphName);
  16875. var accentGlyphId = charset.indexOf(accentGlyphName);
  16876. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16877. continue;
  16878. }
  16879. var accentOffset = {
  16880. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16881. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16882. };
  16883. var charCodes = getCharCodes(mapping, glyphId);
  16884. if (!charCodes) {
  16885. // There's no point in mapping it if the char code was never mapped
  16886. // to begin with.
  16887. continue;
  16888. }
  16889. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16890. var charCode = charCodes[i];
  16891. // Find a fontCharCode that maps to the base and accent glyphs.
  16892. // If one doesn't exists, create it.
  16893. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16894. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16895. baseGlyphId);
  16896. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16897. accentGlyphId);
  16898. seacMap[charCode] = {
  16899. baseFontCharCode: baseFontCharCode,
  16900. accentFontCharCode: accentFontCharCode,
  16901. accentOffset: accentOffset
  16902. };
  16903. }
  16904. }
  16905. properties.seacMap = seacMap;
  16906. }
  16907. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16908. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16909. // PostScript Font Program
  16910. builder.addTable('CFF ', font.data);
  16911. // OS/2 and Windows Specific metrics
  16912. builder.addTable('OS/2', createOS2Table(properties,
  16913. newMapping.charCodeToGlyphId));
  16914. // Character to glyphs mapping
  16915. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16916. // Font header
  16917. builder.addTable('head',
  16918. '\x00\x01\x00\x00' + // Version number
  16919. '\x00\x00\x10\x00' + // fontRevision
  16920. '\x00\x00\x00\x00' + // checksumAdjustement
  16921. '\x5F\x0F\x3C\xF5' + // magicNumber
  16922. '\x00\x00' + // Flags
  16923. safeString16(unitsPerEm) + // unitsPerEM
  16924. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16925. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16926. '\x00\x00' + // xMin
  16927. safeString16(properties.descent) + // yMin
  16928. '\x0F\xFF' + // xMax
  16929. safeString16(properties.ascent) + // yMax
  16930. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16931. '\x00\x11' + // lowestRecPPEM
  16932. '\x00\x00' + // fontDirectionHint
  16933. '\x00\x00' + // indexToLocFormat
  16934. '\x00\x00'); // glyphDataFormat
  16935. // Horizontal header
  16936. builder.addTable('hhea',
  16937. '\x00\x01\x00\x00' + // Version number
  16938. safeString16(properties.ascent) + // Typographic Ascent
  16939. safeString16(properties.descent) + // Typographic Descent
  16940. '\x00\x00' + // Line Gap
  16941. '\xFF\xFF' + // advanceWidthMax
  16942. '\x00\x00' + // minLeftSidebearing
  16943. '\x00\x00' + // minRightSidebearing
  16944. '\x00\x00' + // xMaxExtent
  16945. safeString16(properties.capHeight) + // caretSlopeRise
  16946. safeString16(Math.tan(properties.italicAngle) *
  16947. properties.xHeight) + // caretSlopeRun
  16948. '\x00\x00' + // caretOffset
  16949. '\x00\x00' + // -reserved-
  16950. '\x00\x00' + // -reserved-
  16951. '\x00\x00' + // -reserved-
  16952. '\x00\x00' + // -reserved-
  16953. '\x00\x00' + // metricDataFormat
  16954. string16(numGlyphs)); // Number of HMetrics
  16955. // Horizontal metrics
  16956. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16957. var charstrings = font.charstrings;
  16958. var cffWidths = font.cff ? font.cff.widths : null;
  16959. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16960. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16961. var width = 0;
  16962. if (charstrings) {
  16963. var charstring = charstrings[i - 1];
  16964. width = 'width' in charstring ? charstring.width : 0;
  16965. } else if (cffWidths) {
  16966. width = Math.ceil(cffWidths[i] || 0);
  16967. }
  16968. hmtx += string16(width) + string16(0);
  16969. }
  16970. return hmtx;
  16971. })());
  16972. // Maximum profile
  16973. builder.addTable('maxp',
  16974. '\x00\x00\x50\x00' + // Version number
  16975. string16(numGlyphs)); // Num of glyphs
  16976. // Naming tables
  16977. builder.addTable('name', createNameTable(fontName));
  16978. // PostScript informations
  16979. builder.addTable('post', createPostTable(properties));
  16980. return builder.toArray();
  16981. },
  16982. /**
  16983. * Builds a char code to unicode map based on section 9.10 of the spec.
  16984. * @param {Object} properties Font properties object.
  16985. * @return {Object} A ToUnicodeMap object.
  16986. */
  16987. buildToUnicode: function Font_buildToUnicode(properties) {
  16988. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16989. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16990. return properties.toUnicode;
  16991. }
  16992. // According to the spec if the font is a simple font we should only map
  16993. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16994. // the differences array only contains adobe standard or symbol set names,
  16995. // in pratice it seems better to always try to create a toUnicode
  16996. // map based of the default encoding.
  16997. var toUnicode, charcode;
  16998. if (!properties.composite /* is simple font */) {
  16999. toUnicode = [];
  17000. var encoding = properties.defaultEncoding.slice();
  17001. var baseEncodingName = properties.baseEncodingName;
  17002. // Merge in the differences array.
  17003. var differences = properties.differences;
  17004. for (charcode in differences) {
  17005. encoding[charcode] = differences[charcode];
  17006. }
  17007. for (charcode in encoding) {
  17008. // a) Map the character code to a character name.
  17009. var glyphName = encoding[charcode];
  17010. // b) Look up the character name in the Adobe Glyph List (see the
  17011. // Bibliography) to obtain the corresponding Unicode value.
  17012. if (glyphName === '') {
  17013. continue;
  17014. } else if (GlyphsUnicode[glyphName] === undefined) {
  17015. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17016. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17017. var code = 0;
  17018. switch (glyphName[0]) {
  17019. case 'G': // Gxx glyph
  17020. if (glyphName.length === 3) {
  17021. code = parseInt(glyphName.substr(1), 16);
  17022. }
  17023. break;
  17024. case 'g': // g00xx glyph
  17025. if (glyphName.length === 5) {
  17026. code = parseInt(glyphName.substr(1), 16);
  17027. }
  17028. break;
  17029. case 'C': // Cddd glyph
  17030. case 'c': // cddd glyph
  17031. if (glyphName.length >= 3) {
  17032. code = +glyphName.substr(1);
  17033. }
  17034. break;
  17035. }
  17036. if (code) {
  17037. // If |baseEncodingName| is one the predefined encodings,
  17038. // and |code| equals |charcode|, using the glyph defined in the
  17039. // baseEncoding seems to yield a better |toUnicode| mapping
  17040. // (fixes issue 5070).
  17041. if (baseEncodingName && code === +charcode) {
  17042. var baseEncoding = Encodings[baseEncodingName];
  17043. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17044. toUnicode[charcode] =
  17045. String.fromCharCode(GlyphsUnicode[glyphName]);
  17046. continue;
  17047. }
  17048. }
  17049. toUnicode[charcode] = String.fromCharCode(code);
  17050. }
  17051. continue;
  17052. }
  17053. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17054. }
  17055. return new ToUnicodeMap(toUnicode);
  17056. }
  17057. // If the font is a composite font that uses one of the predefined CMaps
  17058. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17059. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17060. // Adobe-Korea1 character collection:
  17061. if (properties.composite && (
  17062. (properties.cMap.builtInCMap &&
  17063. !(properties.cMap instanceof IdentityCMap)) ||
  17064. (properties.cidSystemInfo.registry === 'Adobe' &&
  17065. (properties.cidSystemInfo.ordering === 'GB1' ||
  17066. properties.cidSystemInfo.ordering === 'CNS1' ||
  17067. properties.cidSystemInfo.ordering === 'Japan1' ||
  17068. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17069. // Then:
  17070. // a) Map the character code to a character identifier (CID) according
  17071. // to the font’s CMap.
  17072. // b) Obtain the registry and ordering of the character collection used
  17073. // by the font’s CMap (for example, Adobe and Japan1) from its
  17074. // CIDSystemInfo dictionary.
  17075. var registry = properties.cidSystemInfo.registry;
  17076. var ordering = properties.cidSystemInfo.ordering;
  17077. // c) Construct a second CMap name by concatenating the registry and
  17078. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17079. // (for example, Adobe–Japan1–UCS2).
  17080. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17081. // d) Obtain the CMap with the name constructed in step (c) (available
  17082. // from the ASN Web site; see the Bibliography).
  17083. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17084. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17085. var cMap = properties.cMap;
  17086. toUnicode = [];
  17087. cMap.forEach(function(charcode, cid) {
  17088. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17089. // e) Map the CID obtained in step (a) according to the CMap obtained
  17090. // in step (d), producing a Unicode value.
  17091. var ucs2 = ucs2CMap.lookup(cid);
  17092. if (ucs2) {
  17093. toUnicode[charcode] =
  17094. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17095. ucs2.charCodeAt(1));
  17096. }
  17097. });
  17098. return new ToUnicodeMap(toUnicode);
  17099. }
  17100. // The viewer's choice, just use an identity map.
  17101. return new IdentityToUnicodeMap(properties.firstChar,
  17102. properties.lastChar);
  17103. },
  17104. get spaceWidth() {
  17105. if ('_shadowWidth' in this) {
  17106. return this._shadowWidth;
  17107. }
  17108. // trying to estimate space character width
  17109. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17110. var width;
  17111. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17112. var glyphName = possibleSpaceReplacements[i];
  17113. // if possible, getting width by glyph name
  17114. if (glyphName in this.widths) {
  17115. width = this.widths[glyphName];
  17116. break;
  17117. }
  17118. var glyphUnicode = GlyphsUnicode[glyphName];
  17119. // finding the charcode via unicodeToCID map
  17120. var charcode = 0;
  17121. if (this.composite) {
  17122. if (this.cMap.contains(glyphUnicode)) {
  17123. charcode = this.cMap.lookup(glyphUnicode);
  17124. }
  17125. }
  17126. // ... via toUnicode map
  17127. if (!charcode && 'toUnicode' in this) {
  17128. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17129. }
  17130. // setting it to unicode if negative or undefined
  17131. if (charcode <= 0) {
  17132. charcode = glyphUnicode;
  17133. }
  17134. // trying to get width via charcode
  17135. width = this.widths[charcode];
  17136. if (width) {
  17137. break; // the non-zero width found
  17138. }
  17139. }
  17140. width = width || this.defaultWidth;
  17141. // Do not shadow the property here. See discussion:
  17142. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17143. this._shadowWidth = width;
  17144. return width;
  17145. },
  17146. charToGlyph: function Font_charToGlyph(charcode) {
  17147. var fontCharCode, width, operatorListId;
  17148. var widthCode = charcode;
  17149. if (this.cMap && this.cMap.contains(charcode)) {
  17150. widthCode = this.cMap.lookup(charcode);
  17151. }
  17152. width = this.widths[widthCode];
  17153. width = isNum(width) ? width : this.defaultWidth;
  17154. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17155. var unicode = this.toUnicode.get(charcode) || charcode;
  17156. if (typeof unicode === 'number') {
  17157. unicode = String.fromCharCode(unicode);
  17158. }
  17159. // First try the toFontChar map, if it's not there then try falling
  17160. // back to the char code.
  17161. fontCharCode = this.toFontChar[charcode] || charcode;
  17162. if (this.missingFile) {
  17163. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17164. }
  17165. if (this.isType3Font) {
  17166. // Font char code in this case is actually a glyph name.
  17167. operatorListId = fontCharCode;
  17168. }
  17169. var accent = null;
  17170. if (this.seacMap && this.seacMap[charcode]) {
  17171. var seac = this.seacMap[charcode];
  17172. fontCharCode = seac.baseFontCharCode;
  17173. accent = {
  17174. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17175. offset: seac.accentOffset
  17176. };
  17177. }
  17178. var fontChar = String.fromCharCode(fontCharCode);
  17179. var glyph = this.glyphCache[charcode];
  17180. if (!glyph ||
  17181. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17182. operatorListId)) {
  17183. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17184. operatorListId);
  17185. this.glyphCache[charcode] = glyph;
  17186. }
  17187. return glyph;
  17188. },
  17189. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17190. var charsCache = this.charsCache;
  17191. var glyphs, glyph, charcode;
  17192. // if we translated this string before, just grab it from the cache
  17193. if (charsCache) {
  17194. glyphs = charsCache[chars];
  17195. if (glyphs) {
  17196. return glyphs;
  17197. }
  17198. }
  17199. // lazily create the translation cache
  17200. if (!charsCache) {
  17201. charsCache = this.charsCache = Object.create(null);
  17202. }
  17203. glyphs = [];
  17204. var charsCacheKey = chars;
  17205. var i = 0, ii;
  17206. if (this.cMap) {
  17207. // composite fonts have multi-byte strings convert the string from
  17208. // single-byte to multi-byte
  17209. var c = {};
  17210. while (i < chars.length) {
  17211. this.cMap.readCharCode(chars, i, c);
  17212. charcode = c.charcode;
  17213. var length = c.length;
  17214. i += length;
  17215. glyph = this.charToGlyph(charcode);
  17216. glyphs.push(glyph);
  17217. // placing null after each word break charcode (ASCII SPACE)
  17218. // Ignore occurences of 0x20 in multiple-byte codes.
  17219. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17220. glyphs.push(null);
  17221. }
  17222. }
  17223. } else {
  17224. for (i = 0, ii = chars.length; i < ii; ++i) {
  17225. charcode = chars.charCodeAt(i);
  17226. glyph = this.charToGlyph(charcode);
  17227. glyphs.push(glyph);
  17228. if (charcode === 0x20) {
  17229. glyphs.push(null);
  17230. }
  17231. }
  17232. }
  17233. // Enter the translated string into the cache
  17234. return (charsCache[charsCacheKey] = glyphs);
  17235. }
  17236. };
  17237. return Font;
  17238. })();
  17239. var ErrorFont = (function ErrorFontClosure() {
  17240. function ErrorFont(error) {
  17241. this.error = error;
  17242. this.loadedName = 'g_font_error';
  17243. this.loading = false;
  17244. }
  17245. ErrorFont.prototype = {
  17246. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17247. return [];
  17248. },
  17249. exportData: function ErrorFont_exportData() {
  17250. return {error: this.error};
  17251. }
  17252. };
  17253. return ErrorFont;
  17254. })();
  17255. /**
  17256. * Shared logic for building a char code to glyph id mapping for Type1 and
  17257. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17258. * @param {Object} properties Font properties object.
  17259. * @param {Object} builtInEncoding The encoding contained within the actual font
  17260. * data.
  17261. * @param {Array} Array of glyph names where the index is the glyph ID.
  17262. * @returns {Object} A char code to glyph ID map.
  17263. */
  17264. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17265. var charCodeToGlyphId = Object.create(null);
  17266. var glyphId, charCode, baseEncoding;
  17267. if (properties.baseEncodingName) {
  17268. // If a valid base encoding name was used, the mapping is initialized with
  17269. // that.
  17270. baseEncoding = Encodings[properties.baseEncodingName];
  17271. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17272. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17273. if (glyphId >= 0) {
  17274. charCodeToGlyphId[charCode] = glyphId;
  17275. } else {
  17276. charCodeToGlyphId[charCode] = 0; // notdef
  17277. }
  17278. }
  17279. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17280. // For a symbolic font the encoding should be the fonts built-in
  17281. // encoding.
  17282. for (charCode in builtInEncoding) {
  17283. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17284. }
  17285. } else {
  17286. // For non-symbolic fonts that don't have a base encoding the standard
  17287. // encoding should be used.
  17288. baseEncoding = Encodings.StandardEncoding;
  17289. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17290. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17291. if (glyphId >= 0) {
  17292. charCodeToGlyphId[charCode] = glyphId;
  17293. } else {
  17294. charCodeToGlyphId[charCode] = 0; // notdef
  17295. }
  17296. }
  17297. }
  17298. // Lastly, merge in the differences.
  17299. var differences = properties.differences;
  17300. if (differences) {
  17301. for (charCode in differences) {
  17302. var glyphName = differences[charCode];
  17303. glyphId = glyphNames.indexOf(glyphName);
  17304. if (glyphId >= 0) {
  17305. charCodeToGlyphId[charCode] = glyphId;
  17306. } else {
  17307. charCodeToGlyphId[charCode] = 0; // notdef
  17308. }
  17309. }
  17310. }
  17311. return charCodeToGlyphId;
  17312. }
  17313. /*
  17314. * CharStrings are encoded following the the CharString Encoding sequence
  17315. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17316. * The value in a byte indicates a command, a number, or subsequent bytes
  17317. * that are to be interpreted in a special way.
  17318. *
  17319. * CharString Number Encoding:
  17320. * A CharString byte containing the values from 32 through 255 inclusive
  17321. * indicate an integer. These values are decoded in four ranges.
  17322. *
  17323. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17324. * indicate the integer v - 139. Thus, the integer values from -107 through
  17325. * 107 inclusive may be encoded in single byte.
  17326. *
  17327. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17328. * indicates an integer involving the next byte, w, according to the formula:
  17329. * [(v - 247) x 256] + w + 108
  17330. *
  17331. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17332. * indicates an integer involving the next byte, w, according to the formula:
  17333. * -[(v - 251) * 256] - w - 108
  17334. *
  17335. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17336. * are a two complement signed integer. The first of these bytes contains the
  17337. * highest order bits, the second byte contains the next higher order bits
  17338. * and the fourth byte contain the lowest order bits.
  17339. *
  17340. *
  17341. * CharString Command Encoding:
  17342. * CharStrings commands are encoded in 1 or 2 bytes.
  17343. *
  17344. * Single byte commands are encoded in 1 byte that contains a value between
  17345. * 0 and 31 inclusive.
  17346. * If a command byte contains the value 12, then the value in the next byte
  17347. * indicates a command. This "escape" mechanism allows many extra commands
  17348. * to be encoded and this encoding technique helps to minimize the length of
  17349. * the charStrings.
  17350. */
  17351. var Type1CharString = (function Type1CharStringClosure() {
  17352. var COMMAND_MAP = {
  17353. 'hstem': [1],
  17354. 'vstem': [3],
  17355. 'vmoveto': [4],
  17356. 'rlineto': [5],
  17357. 'hlineto': [6],
  17358. 'vlineto': [7],
  17359. 'rrcurveto': [8],
  17360. 'callsubr': [10],
  17361. 'flex': [12, 35],
  17362. 'drop' : [12, 18],
  17363. 'endchar': [14],
  17364. 'rmoveto': [21],
  17365. 'hmoveto': [22],
  17366. 'vhcurveto': [30],
  17367. 'hvcurveto': [31]
  17368. };
  17369. function Type1CharString() {
  17370. this.width = 0;
  17371. this.lsb = 0;
  17372. this.flexing = false;
  17373. this.output = [];
  17374. this.stack = [];
  17375. }
  17376. Type1CharString.prototype = {
  17377. convert: function Type1CharString_convert(encoded, subrs) {
  17378. var count = encoded.length;
  17379. var error = false;
  17380. var wx, sbx, subrNumber;
  17381. for (var i = 0; i < count; i++) {
  17382. var value = encoded[i];
  17383. if (value < 32) {
  17384. if (value === 12) {
  17385. value = (value << 8) + encoded[++i];
  17386. }
  17387. switch (value) {
  17388. case 1: // hstem
  17389. if (!HINTING_ENABLED) {
  17390. this.stack = [];
  17391. break;
  17392. }
  17393. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17394. break;
  17395. case 3: // vstem
  17396. if (!HINTING_ENABLED) {
  17397. this.stack = [];
  17398. break;
  17399. }
  17400. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17401. break;
  17402. case 4: // vmoveto
  17403. if (this.flexing) {
  17404. if (this.stack.length < 1) {
  17405. error = true;
  17406. break;
  17407. }
  17408. // Add the dx for flex and but also swap the values so they are
  17409. // the right order.
  17410. var dy = this.stack.pop();
  17411. this.stack.push(0, dy);
  17412. break;
  17413. }
  17414. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17415. break;
  17416. case 5: // rlineto
  17417. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17418. break;
  17419. case 6: // hlineto
  17420. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17421. break;
  17422. case 7: // vlineto
  17423. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17424. break;
  17425. case 8: // rrcurveto
  17426. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17427. break;
  17428. case 9: // closepath
  17429. // closepath is a Type1 command that does not take argument and is
  17430. // useless in Type2 and it can simply be ignored.
  17431. this.stack = [];
  17432. break;
  17433. case 10: // callsubr
  17434. if (this.stack.length < 1) {
  17435. error = true;
  17436. break;
  17437. }
  17438. subrNumber = this.stack.pop();
  17439. error = this.convert(subrs[subrNumber], subrs);
  17440. break;
  17441. case 11: // return
  17442. return error;
  17443. case 13: // hsbw
  17444. if (this.stack.length < 2) {
  17445. error = true;
  17446. break;
  17447. }
  17448. // To convert to type2 we have to move the width value to the
  17449. // first part of the charstring and then use hmoveto with lsb.
  17450. wx = this.stack.pop();
  17451. sbx = this.stack.pop();
  17452. this.lsb = sbx;
  17453. this.width = wx;
  17454. this.stack.push(wx, sbx);
  17455. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17456. break;
  17457. case 14: // endchar
  17458. this.output.push(COMMAND_MAP.endchar[0]);
  17459. break;
  17460. case 21: // rmoveto
  17461. if (this.flexing) {
  17462. break;
  17463. }
  17464. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17465. break;
  17466. case 22: // hmoveto
  17467. if (this.flexing) {
  17468. // Add the dy for flex.
  17469. this.stack.push(0);
  17470. break;
  17471. }
  17472. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17473. break;
  17474. case 30: // vhcurveto
  17475. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17476. break;
  17477. case 31: // hvcurveto
  17478. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17479. break;
  17480. case (12 << 8) + 0: // dotsection
  17481. // dotsection is a Type1 command to specify some hinting feature
  17482. // for dots that do not take a parameter and it can safely be
  17483. // ignored for Type2.
  17484. this.stack = [];
  17485. break;
  17486. case (12 << 8) + 1: // vstem3
  17487. if (!HINTING_ENABLED) {
  17488. this.stack = [];
  17489. break;
  17490. }
  17491. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17492. // multiple parameters, so instead of returning [vh]stem3 take a
  17493. // shortcut and return [vhstem] instead.
  17494. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17495. break;
  17496. case (12 << 8) + 2: // hstem3
  17497. if (!HINTING_ENABLED) {
  17498. this.stack = [];
  17499. break;
  17500. }
  17501. // See vstem3.
  17502. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17503. break;
  17504. case (12 << 8) + 6: // seac
  17505. // seac is like type 2's special endchar but it doesn't use the
  17506. // first argument asb, so remove it.
  17507. if (SEAC_ANALYSIS_ENABLED) {
  17508. this.seac = this.stack.splice(-4, 4);
  17509. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17510. } else {
  17511. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17512. }
  17513. break;
  17514. case (12 << 8) + 7: // sbw
  17515. if (this.stack.length < 4) {
  17516. error = true;
  17517. break;
  17518. }
  17519. // To convert to type2 we have to move the width value to the
  17520. // first part of the charstring and then use rmoveto with
  17521. // (dx, dy). The height argument will not be used for vmtx and
  17522. // vhea tables reconstruction -- ignoring it.
  17523. var wy = this.stack.pop();
  17524. wx = this.stack.pop();
  17525. var sby = this.stack.pop();
  17526. sbx = this.stack.pop();
  17527. this.lsb = sbx;
  17528. this.width = wx;
  17529. this.stack.push(wx, sbx, sby);
  17530. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17531. break;
  17532. case (12 << 8) + 12: // div
  17533. if (this.stack.length < 2) {
  17534. error = true;
  17535. break;
  17536. }
  17537. var num2 = this.stack.pop();
  17538. var num1 = this.stack.pop();
  17539. this.stack.push(num1 / num2);
  17540. break;
  17541. case (12 << 8) + 16: // callothersubr
  17542. if (this.stack.length < 2) {
  17543. error = true;
  17544. break;
  17545. }
  17546. subrNumber = this.stack.pop();
  17547. var numArgs = this.stack.pop();
  17548. if (subrNumber === 0 && numArgs === 3) {
  17549. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17550. this.stack.push(
  17551. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17552. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17553. flexArgs[4], // bcp2x
  17554. flexArgs[5], // bcp2y
  17555. flexArgs[6], // p2x
  17556. flexArgs[7], // p2y
  17557. flexArgs[8], // bcp3x
  17558. flexArgs[9], // bcp3y
  17559. flexArgs[10], // bcp4x
  17560. flexArgs[11], // bcp4y
  17561. flexArgs[12], // p3x
  17562. flexArgs[13], // p3y
  17563. flexArgs[14] // flexDepth
  17564. // 15 = finalx unused by flex
  17565. // 16 = finaly unused by flex
  17566. );
  17567. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17568. this.flexing = false;
  17569. this.stack.push(flexArgs[15], flexArgs[16]);
  17570. } else if (subrNumber === 1 && numArgs === 0) {
  17571. this.flexing = true;
  17572. }
  17573. break;
  17574. case (12 << 8) + 17: // pop
  17575. // Ignore this since it is only used with othersubr.
  17576. break;
  17577. case (12 << 8) + 33: // setcurrentpoint
  17578. // Ignore for now.
  17579. this.stack = [];
  17580. break;
  17581. default:
  17582. warn('Unknown type 1 charstring command of "' + value + '"');
  17583. break;
  17584. }
  17585. if (error) {
  17586. break;
  17587. }
  17588. continue;
  17589. } else if (value <= 246) {
  17590. value = value - 139;
  17591. } else if (value <= 250) {
  17592. value = ((value - 247) * 256) + encoded[++i] + 108;
  17593. } else if (value <= 254) {
  17594. value = -((value - 251) * 256) - encoded[++i] - 108;
  17595. } else {
  17596. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17597. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17598. }
  17599. this.stack.push(value);
  17600. }
  17601. return error;
  17602. },
  17603. executeCommand: function(howManyArgs, command, keepStack) {
  17604. var stackLength = this.stack.length;
  17605. if (howManyArgs > stackLength) {
  17606. return true;
  17607. }
  17608. var start = stackLength - howManyArgs;
  17609. for (var i = start; i < stackLength; i++) {
  17610. var value = this.stack[i];
  17611. if (value === (value | 0)) { // int
  17612. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17613. } else { // fixed point
  17614. value = (65536 * value) | 0;
  17615. this.output.push(255,
  17616. (value >> 24) & 0xFF,
  17617. (value >> 16) & 0xFF,
  17618. (value >> 8) & 0xFF,
  17619. value & 0xFF);
  17620. }
  17621. }
  17622. this.output.push.apply(this.output, command);
  17623. if (keepStack) {
  17624. this.stack.splice(start, howManyArgs);
  17625. } else {
  17626. this.stack.length = 0;
  17627. }
  17628. return false;
  17629. }
  17630. };
  17631. return Type1CharString;
  17632. })();
  17633. /*
  17634. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17635. * program. Some of its logic depends on the Type2 charstrings
  17636. * structure.
  17637. * Note: this doesn't really parse the font since that would require evaluation
  17638. * of PostScript, but it is possible in most cases to extract what we need
  17639. * without a full parse.
  17640. */
  17641. var Type1Parser = (function Type1ParserClosure() {
  17642. /*
  17643. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17644. * of Plaintext Bytes. The function took a key as a parameter which can be
  17645. * for decrypting the eexec block of for decoding charStrings.
  17646. */
  17647. var EEXEC_ENCRYPT_KEY = 55665;
  17648. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17649. function isHexDigit(code) {
  17650. return code >= 48 && code <= 57 || // '0'-'9'
  17651. code >= 65 && code <= 70 || // 'A'-'F'
  17652. code >= 97 && code <= 102; // 'a'-'f'
  17653. }
  17654. function decrypt(data, key, discardNumber) {
  17655. var r = key | 0, c1 = 52845, c2 = 22719;
  17656. var count = data.length;
  17657. var decrypted = new Uint8Array(count);
  17658. for (var i = 0; i < count; i++) {
  17659. var value = data[i];
  17660. decrypted[i] = value ^ (r >> 8);
  17661. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17662. }
  17663. return Array.prototype.slice.call(decrypted, discardNumber);
  17664. }
  17665. function decryptAscii(data, key, discardNumber) {
  17666. var r = key | 0, c1 = 52845, c2 = 22719;
  17667. var count = data.length, maybeLength = count >>> 1;
  17668. var decrypted = new Uint8Array(maybeLength);
  17669. var i, j;
  17670. for (i = 0, j = 0; i < count; i++) {
  17671. var digit1 = data[i];
  17672. if (!isHexDigit(digit1)) {
  17673. continue;
  17674. }
  17675. i++;
  17676. var digit2;
  17677. while (i < count && !isHexDigit(digit2 = data[i])) {
  17678. i++;
  17679. }
  17680. if (i < count) {
  17681. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17682. decrypted[j++] = value ^ (r >> 8);
  17683. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17684. }
  17685. }
  17686. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17687. }
  17688. function isSpecial(c) {
  17689. return c === 0x2F || // '/'
  17690. c === 0x5B || c === 0x5D || // '[', ']'
  17691. c === 0x7B || c === 0x7D || // '{', '}'
  17692. c === 0x28 || c === 0x29; // '(', ')'
  17693. }
  17694. function Type1Parser(stream, encrypted) {
  17695. if (encrypted) {
  17696. var data = stream.getBytes();
  17697. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17698. isHexDigit(data[2]) && isHexDigit(data[3]));
  17699. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17700. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17701. }
  17702. this.stream = stream;
  17703. this.nextChar();
  17704. }
  17705. Type1Parser.prototype = {
  17706. readNumberArray: function Type1Parser_readNumberArray() {
  17707. this.getToken(); // read '[' or '{' (arrays can start with either)
  17708. var array = [];
  17709. while (true) {
  17710. var token = this.getToken();
  17711. if (token === null || token === ']' || token === '}') {
  17712. break;
  17713. }
  17714. array.push(parseFloat(token || 0));
  17715. }
  17716. return array;
  17717. },
  17718. readNumber: function Type1Parser_readNumber() {
  17719. var token = this.getToken();
  17720. return parseFloat(token || 0);
  17721. },
  17722. readInt: function Type1Parser_readInt() {
  17723. // Use '| 0' to prevent setting a double into length such as the double
  17724. // does not flow into the loop variable.
  17725. var token = this.getToken();
  17726. return parseInt(token || 0, 10) | 0;
  17727. },
  17728. readBoolean: function Type1Parser_readBoolean() {
  17729. var token = this.getToken();
  17730. // Use 1 and 0 since that's what type2 charstrings use.
  17731. return token === 'true' ? 1 : 0;
  17732. },
  17733. nextChar : function Type1_nextChar() {
  17734. return (this.currentChar = this.stream.getByte());
  17735. },
  17736. getToken: function Type1Parser_getToken() {
  17737. // Eat whitespace and comments.
  17738. var comment = false;
  17739. var ch = this.currentChar;
  17740. while (true) {
  17741. if (ch === -1) {
  17742. return null;
  17743. }
  17744. if (comment) {
  17745. if (ch === 0x0A || ch === 0x0D) {
  17746. comment = false;
  17747. }
  17748. } else if (ch === 0x25) { // '%'
  17749. comment = true;
  17750. } else if (!Lexer.isSpace(ch)) {
  17751. break;
  17752. }
  17753. ch = this.nextChar();
  17754. }
  17755. if (isSpecial(ch)) {
  17756. this.nextChar();
  17757. return String.fromCharCode(ch);
  17758. }
  17759. var token = '';
  17760. do {
  17761. token += String.fromCharCode(ch);
  17762. ch = this.nextChar();
  17763. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17764. return token;
  17765. },
  17766. /*
  17767. * Returns an object containing a Subrs array and a CharStrings
  17768. * array extracted from and eexec encrypted block of data
  17769. */
  17770. extractFontProgram: function Type1Parser_extractFontProgram() {
  17771. var stream = this.stream;
  17772. var subrs = [], charstrings = [];
  17773. var program = {
  17774. subrs: [],
  17775. charstrings: [],
  17776. properties: {
  17777. 'privateData': {
  17778. 'lenIV': 4
  17779. }
  17780. }
  17781. };
  17782. var token, length, data, lenIV, encoded;
  17783. while ((token = this.getToken()) !== null) {
  17784. if (token !== '/') {
  17785. continue;
  17786. }
  17787. token = this.getToken();
  17788. switch (token) {
  17789. case 'CharStrings':
  17790. // The number immediately following CharStrings must be greater or
  17791. // equal to the number of CharStrings.
  17792. this.getToken();
  17793. this.getToken(); // read in 'dict'
  17794. this.getToken(); // read in 'dup'
  17795. this.getToken(); // read in 'begin'
  17796. while(true) {
  17797. token = this.getToken();
  17798. if (token === null || token === 'end') {
  17799. break;
  17800. }
  17801. if (token !== '/') {
  17802. continue;
  17803. }
  17804. var glyph = this.getToken();
  17805. length = this.readInt();
  17806. this.getToken(); // read in 'RD' or '-|'
  17807. data = stream.makeSubStream(stream.pos, length);
  17808. lenIV = program.properties.privateData['lenIV'];
  17809. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17810. // Skip past the required space and binary data.
  17811. stream.skip(length);
  17812. this.nextChar();
  17813. token = this.getToken(); // read in 'ND' or '|-'
  17814. if (token === 'noaccess') {
  17815. this.getToken(); // read in 'def'
  17816. }
  17817. charstrings.push({
  17818. glyph: glyph,
  17819. encoded: encoded
  17820. });
  17821. }
  17822. break;
  17823. case 'Subrs':
  17824. var num = this.readInt();
  17825. this.getToken(); // read in 'array'
  17826. while ((token = this.getToken()) === 'dup') {
  17827. var index = this.readInt();
  17828. length = this.readInt();
  17829. this.getToken(); // read in 'RD' or '-|'
  17830. data = stream.makeSubStream(stream.pos, length);
  17831. lenIV = program.properties.privateData['lenIV'];
  17832. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17833. // Skip past the required space and binary data.
  17834. stream.skip(length);
  17835. this.nextChar();
  17836. token = this.getToken(); // read in 'NP' or '|'
  17837. if (token === 'noaccess') {
  17838. this.getToken(); // read in 'put'
  17839. }
  17840. subrs[index] = encoded;
  17841. }
  17842. break;
  17843. case 'BlueValues':
  17844. case 'OtherBlues':
  17845. case 'FamilyBlues':
  17846. case 'FamilyOtherBlues':
  17847. var blueArray = this.readNumberArray();
  17848. // *Blue* values may contain invalid data: disables reading of
  17849. // those values when hinting is disabled.
  17850. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17851. HINTING_ENABLED) {
  17852. program.properties.privateData[token] = blueArray;
  17853. }
  17854. break;
  17855. case 'StemSnapH':
  17856. case 'StemSnapV':
  17857. program.properties.privateData[token] = this.readNumberArray();
  17858. break;
  17859. case 'StdHW':
  17860. case 'StdVW':
  17861. program.properties.privateData[token] =
  17862. this.readNumberArray()[0];
  17863. break;
  17864. case 'BlueShift':
  17865. case 'lenIV':
  17866. case 'BlueFuzz':
  17867. case 'BlueScale':
  17868. case 'LanguageGroup':
  17869. case 'ExpansionFactor':
  17870. program.properties.privateData[token] = this.readNumber();
  17871. break;
  17872. case 'ForceBold':
  17873. program.properties.privateData[token] = this.readBoolean();
  17874. break;
  17875. }
  17876. }
  17877. for (var i = 0; i < charstrings.length; i++) {
  17878. glyph = charstrings[i].glyph;
  17879. encoded = charstrings[i].encoded;
  17880. var charString = new Type1CharString();
  17881. var error = charString.convert(encoded, subrs);
  17882. var output = charString.output;
  17883. if (error) {
  17884. // It seems when FreeType encounters an error while evaluating a glyph
  17885. // that it completely ignores the glyph so we'll mimic that behaviour
  17886. // here and put an endchar to make the validator happy.
  17887. output = [14];
  17888. }
  17889. program.charstrings.push({
  17890. glyphName: glyph,
  17891. charstring: output,
  17892. width: charString.width,
  17893. lsb: charString.lsb,
  17894. seac: charString.seac
  17895. });
  17896. }
  17897. return program;
  17898. },
  17899. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17900. var token;
  17901. while ((token = this.getToken()) !== null) {
  17902. if (token !== '/') {
  17903. continue;
  17904. }
  17905. token = this.getToken();
  17906. switch (token) {
  17907. case 'FontMatrix':
  17908. var matrix = this.readNumberArray();
  17909. properties.fontMatrix = matrix;
  17910. break;
  17911. case 'Encoding':
  17912. var encodingArg = this.getToken();
  17913. var encoding;
  17914. if (!/^\d+$/.test(encodingArg)) {
  17915. // encoding name is specified
  17916. encoding = Encodings[encodingArg];
  17917. } else {
  17918. encoding = [];
  17919. var size = parseInt(encodingArg, 10) | 0;
  17920. this.getToken(); // read in 'array'
  17921. for (var j = 0; j < size; j++) {
  17922. token = this.getToken();
  17923. // skipping till first dup or def (e.g. ignoring for statement)
  17924. while (token !== 'dup' && token !== 'def') {
  17925. token = this.getToken();
  17926. if (token === null) {
  17927. return; // invalid header
  17928. }
  17929. }
  17930. if (token === 'def') {
  17931. break; // read all array data
  17932. }
  17933. var index = this.readInt();
  17934. this.getToken(); // read in '/'
  17935. var glyph = this.getToken();
  17936. encoding[index] = glyph;
  17937. this.getToken(); // read the in 'put'
  17938. }
  17939. }
  17940. properties.builtInEncoding = encoding;
  17941. break;
  17942. case 'FontBBox':
  17943. var fontBBox = this.readNumberArray();
  17944. // adjusting ascent/descent
  17945. properties.ascent = fontBBox[3];
  17946. properties.descent = fontBBox[1];
  17947. properties.ascentScaled = true;
  17948. break;
  17949. }
  17950. }
  17951. }
  17952. };
  17953. return Type1Parser;
  17954. })();
  17955. /**
  17956. * The CFF class takes a Type1 file and wrap it into a
  17957. * 'Compact Font Format' which itself embed Type2 charstrings.
  17958. */
  17959. var CFFStandardStrings = [
  17960. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17961. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17962. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17963. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17964. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17965. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17966. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17967. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17968. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17969. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17970. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17971. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17972. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17973. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17974. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17975. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17976. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17977. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17978. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17979. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17980. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17981. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17982. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17983. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17984. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17985. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17986. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17987. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17988. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17989. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17990. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17991. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17992. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17993. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17994. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17995. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  17996. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  17997. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  17998. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  17999. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18000. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18001. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18002. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18003. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18004. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18005. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18006. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18007. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18008. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18009. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18010. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18011. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18012. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18013. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18014. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18015. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18016. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18017. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18018. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18019. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18020. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18021. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18022. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18023. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18024. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18025. ];
  18026. // Type1Font is also a CIDFontType0.
  18027. var Type1Font = function Type1Font(name, file, properties) {
  18028. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18029. // Also, length1 and length2 might be off by 6 bytes as well.
  18030. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18031. var PFB_HEADER_SIZE = 6;
  18032. var headerBlockLength = properties.length1;
  18033. var eexecBlockLength = properties.length2;
  18034. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18035. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18036. if (pfbHeaderPresent) {
  18037. file.skip(PFB_HEADER_SIZE);
  18038. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18039. (pfbHeader[3] << 8) | pfbHeader[2];
  18040. }
  18041. // Get the data block containing glyphs and subrs informations
  18042. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18043. var headerBlockParser = new Type1Parser(headerBlock);
  18044. headerBlockParser.extractFontHeader(properties);
  18045. if (pfbHeaderPresent) {
  18046. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18047. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18048. (pfbHeader[3] << 8) | pfbHeader[2];
  18049. }
  18050. // Decrypt the data blocks and retrieve it's content
  18051. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18052. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18053. var data = eexecBlockParser.extractFontProgram();
  18054. for (var info in data.properties) {
  18055. properties[info] = data.properties[info];
  18056. }
  18057. var charstrings = data.charstrings;
  18058. var type2Charstrings = this.getType2Charstrings(charstrings);
  18059. var subrs = this.getType2Subrs(data.subrs);
  18060. this.charstrings = charstrings;
  18061. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18062. subrs, properties);
  18063. this.seacs = this.getSeacs(data.charstrings);
  18064. };
  18065. Type1Font.prototype = {
  18066. get numGlyphs() {
  18067. return this.charstrings.length + 1;
  18068. },
  18069. getCharset: function Type1Font_getCharset() {
  18070. var charset = ['.notdef'];
  18071. var charstrings = this.charstrings;
  18072. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18073. charset.push(charstrings[glyphId].glyphName);
  18074. }
  18075. return charset;
  18076. },
  18077. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18078. var charstrings = this.charstrings;
  18079. var glyphNames = ['.notdef'], glyphId;
  18080. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18081. glyphNames.push(charstrings[glyphId].glyphName);
  18082. }
  18083. var encoding = properties.builtInEncoding;
  18084. if (encoding) {
  18085. var builtInEncoding = {};
  18086. for (var charCode in encoding) {
  18087. glyphId = glyphNames.indexOf(encoding[charCode]);
  18088. if (glyphId >= 0) {
  18089. builtInEncoding[charCode] = glyphId;
  18090. }
  18091. }
  18092. }
  18093. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18094. },
  18095. getSeacs: function Type1Font_getSeacs(charstrings) {
  18096. var i, ii;
  18097. var seacMap = [];
  18098. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18099. var charstring = charstrings[i];
  18100. if (charstring.seac) {
  18101. // Offset by 1 for .notdef
  18102. seacMap[i + 1] = charstring.seac;
  18103. }
  18104. }
  18105. return seacMap;
  18106. },
  18107. getType2Charstrings: function Type1Font_getType2Charstrings(
  18108. type1Charstrings) {
  18109. var type2Charstrings = [];
  18110. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18111. type2Charstrings.push(type1Charstrings[i].charstring);
  18112. }
  18113. return type2Charstrings;
  18114. },
  18115. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18116. var bias = 0;
  18117. var count = type1Subrs.length;
  18118. if (count < 1133) {
  18119. bias = 107;
  18120. } else if (count < 33769) {
  18121. bias = 1131;
  18122. } else {
  18123. bias = 32768;
  18124. }
  18125. // Add a bunch of empty subrs to deal with the Type2 bias
  18126. var type2Subrs = [];
  18127. var i;
  18128. for (i = 0; i < bias; i++) {
  18129. type2Subrs.push([0x0B]);
  18130. }
  18131. for (i = 0; i < count; i++) {
  18132. type2Subrs.push(type1Subrs[i]);
  18133. }
  18134. return type2Subrs;
  18135. },
  18136. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18137. var cff = new CFF();
  18138. cff.header = new CFFHeader(1, 0, 4, 4);
  18139. cff.names = [name];
  18140. var topDict = new CFFTopDict();
  18141. // CFF strings IDs 0...390 are predefined names, so refering
  18142. // to entries in our own String INDEX starts at SID 391.
  18143. topDict.setByName('version', 391);
  18144. topDict.setByName('Notice', 392);
  18145. topDict.setByName('FullName', 393);
  18146. topDict.setByName('FamilyName', 394);
  18147. topDict.setByName('Weight', 395);
  18148. topDict.setByName('Encoding', null); // placeholder
  18149. topDict.setByName('FontMatrix', properties.fontMatrix);
  18150. topDict.setByName('FontBBox', properties.bbox);
  18151. topDict.setByName('charset', null); // placeholder
  18152. topDict.setByName('CharStrings', null); // placeholder
  18153. topDict.setByName('Private', null); // placeholder
  18154. cff.topDict = topDict;
  18155. var strings = new CFFStrings();
  18156. strings.add('Version 0.11'); // Version
  18157. strings.add('See original notice'); // Notice
  18158. strings.add(name); // FullName
  18159. strings.add(name); // FamilyName
  18160. strings.add('Medium'); // Weight
  18161. cff.strings = strings;
  18162. cff.globalSubrIndex = new CFFIndex();
  18163. var count = glyphs.length;
  18164. var charsetArray = [0];
  18165. var i, ii;
  18166. for (i = 0; i < count; i++) {
  18167. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18168. // TODO: Insert the string and correctly map it. Previously it was
  18169. // thought mapping names that aren't in the standard strings to .notdef
  18170. // was fine, however in issue818 when mapping them all to .notdef the
  18171. // adieresis glyph no longer worked.
  18172. if (index === -1) {
  18173. index = 0;
  18174. }
  18175. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18176. }
  18177. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18178. var charStringsIndex = new CFFIndex();
  18179. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18180. for (i = 0; i < count; i++) {
  18181. charStringsIndex.add(glyphs[i]);
  18182. }
  18183. cff.charStrings = charStringsIndex;
  18184. var privateDict = new CFFPrivateDict();
  18185. privateDict.setByName('Subrs', null); // placeholder
  18186. var fields = [
  18187. 'BlueValues',
  18188. 'OtherBlues',
  18189. 'FamilyBlues',
  18190. 'FamilyOtherBlues',
  18191. 'StemSnapH',
  18192. 'StemSnapV',
  18193. 'BlueShift',
  18194. 'BlueFuzz',
  18195. 'BlueScale',
  18196. 'LanguageGroup',
  18197. 'ExpansionFactor',
  18198. 'ForceBold',
  18199. 'StdHW',
  18200. 'StdVW'
  18201. ];
  18202. for (i = 0, ii = fields.length; i < ii; i++) {
  18203. var field = fields[i];
  18204. if (!properties.privateData.hasOwnProperty(field)) {
  18205. continue;
  18206. }
  18207. var value = properties.privateData[field];
  18208. if (isArray(value)) {
  18209. // All of the private dictionary array data in CFF must be stored as
  18210. // "delta-encoded" numbers.
  18211. for (var j = value.length - 1; j > 0; j--) {
  18212. value[j] -= value[j - 1]; // ... difference from previous value
  18213. }
  18214. }
  18215. privateDict.setByName(field, value);
  18216. }
  18217. cff.topDict.privateDict = privateDict;
  18218. var subrIndex = new CFFIndex();
  18219. for (i = 0, ii = subrs.length; i < ii; i++) {
  18220. subrIndex.add(subrs[i]);
  18221. }
  18222. privateDict.subrsIndex = subrIndex;
  18223. var compiler = new CFFCompiler(cff);
  18224. return compiler.compile();
  18225. }
  18226. };
  18227. var CFFFont = (function CFFFontClosure() {
  18228. function CFFFont(file, properties) {
  18229. this.properties = properties;
  18230. var parser = new CFFParser(file, properties);
  18231. this.cff = parser.parse();
  18232. var compiler = new CFFCompiler(this.cff);
  18233. this.seacs = this.cff.seacs;
  18234. try {
  18235. this.data = compiler.compile();
  18236. } catch (e) {
  18237. warn('Failed to compile font ' + properties.loadedName);
  18238. // There may have just been an issue with the compiler, set the data
  18239. // anyway and hope the font loaded.
  18240. this.data = file;
  18241. }
  18242. }
  18243. CFFFont.prototype = {
  18244. get numGlyphs() {
  18245. return this.cff.charStrings.count;
  18246. },
  18247. getCharset: function CFFFont_getCharset() {
  18248. return this.cff.charset.charset;
  18249. },
  18250. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18251. var cff = this.cff;
  18252. var properties = this.properties;
  18253. var charsets = cff.charset.charset;
  18254. var charCodeToGlyphId;
  18255. var glyphId;
  18256. if (properties.composite) {
  18257. charCodeToGlyphId = Object.create(null);
  18258. if (cff.isCIDFont) {
  18259. // If the font is actually a CID font then we should use the charset
  18260. // to map CIDs to GIDs.
  18261. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18262. var cid = charsets[glyphId];
  18263. var charCode = properties.cMap.charCodeOf(cid);
  18264. charCodeToGlyphId[charCode] = glyphId;
  18265. }
  18266. } else {
  18267. // If it is NOT actually a CID font then CIDs should be mapped
  18268. // directly to GIDs.
  18269. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18270. charCodeToGlyphId[glyphId] = glyphId;
  18271. }
  18272. }
  18273. return charCodeToGlyphId;
  18274. }
  18275. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18276. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18277. return charCodeToGlyphId;
  18278. }
  18279. };
  18280. return CFFFont;
  18281. })();
  18282. var CFFParser = (function CFFParserClosure() {
  18283. var CharstringValidationData = [
  18284. null,
  18285. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18286. null,
  18287. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18288. { id: 'vmoveto', min: 1, stackClearing: true },
  18289. { id: 'rlineto', min: 2, resetStack: true },
  18290. { id: 'hlineto', min: 1, resetStack: true },
  18291. { id: 'vlineto', min: 1, resetStack: true },
  18292. { id: 'rrcurveto', min: 6, resetStack: true },
  18293. null,
  18294. { id: 'callsubr', min: 1, undefStack: true },
  18295. { id: 'return', min: 0, undefStack: true },
  18296. null, // 12
  18297. null,
  18298. { id: 'endchar', min: 0, stackClearing: true },
  18299. null,
  18300. null,
  18301. null,
  18302. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18303. { id: 'hintmask', min: 0, stackClearing: true },
  18304. { id: 'cntrmask', min: 0, stackClearing: true },
  18305. { id: 'rmoveto', min: 2, stackClearing: true },
  18306. { id: 'hmoveto', min: 1, stackClearing: true },
  18307. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18308. { id: 'rcurveline', min: 8, resetStack: true },
  18309. { id: 'rlinecurve', min: 8, resetStack: true },
  18310. { id: 'vvcurveto', min: 4, resetStack: true },
  18311. { id: 'hhcurveto', min: 4, resetStack: true },
  18312. null, // shortint
  18313. { id: 'callgsubr', min: 1, undefStack: true },
  18314. { id: 'vhcurveto', min: 4, resetStack: true },
  18315. { id: 'hvcurveto', min: 4, resetStack: true }
  18316. ];
  18317. var CharstringValidationData12 = [
  18318. null,
  18319. null,
  18320. null,
  18321. { id: 'and', min: 2, stackDelta: -1 },
  18322. { id: 'or', min: 2, stackDelta: -1 },
  18323. { id: 'not', min: 1, stackDelta: 0 },
  18324. null,
  18325. null,
  18326. null,
  18327. { id: 'abs', min: 1, stackDelta: 0 },
  18328. { id: 'add', min: 2, stackDelta: -1,
  18329. stackFn: function stack_div(stack, index) {
  18330. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18331. }
  18332. },
  18333. { id: 'sub', min: 2, stackDelta: -1,
  18334. stackFn: function stack_div(stack, index) {
  18335. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18336. }
  18337. },
  18338. { id: 'div', min: 2, stackDelta: -1,
  18339. stackFn: function stack_div(stack, index) {
  18340. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18341. }
  18342. },
  18343. null,
  18344. { id: 'neg', min: 1, stackDelta: 0,
  18345. stackFn: function stack_div(stack, index) {
  18346. stack[index - 1] = -stack[index - 1];
  18347. }
  18348. },
  18349. { id: 'eq', min: 2, stackDelta: -1 },
  18350. null,
  18351. null,
  18352. { id: 'drop', min: 1, stackDelta: -1 },
  18353. null,
  18354. { id: 'put', min: 2, stackDelta: -2 },
  18355. { id: 'get', min: 1, stackDelta: 0 },
  18356. { id: 'ifelse', min: 4, stackDelta: -3 },
  18357. { id: 'random', min: 0, stackDelta: 1 },
  18358. { id: 'mul', min: 2, stackDelta: -1,
  18359. stackFn: function stack_div(stack, index) {
  18360. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18361. }
  18362. },
  18363. null,
  18364. { id: 'sqrt', min: 1, stackDelta: 0 },
  18365. { id: 'dup', min: 1, stackDelta: 1 },
  18366. { id: 'exch', min: 2, stackDelta: 0 },
  18367. { id: 'index', min: 2, stackDelta: 0 },
  18368. { id: 'roll', min: 3, stackDelta: -2 },
  18369. null,
  18370. null,
  18371. null,
  18372. { id: 'hflex', min: 7, resetStack: true },
  18373. { id: 'flex', min: 13, resetStack: true },
  18374. { id: 'hflex1', min: 9, resetStack: true },
  18375. { id: 'flex1', min: 11, resetStack: true }
  18376. ];
  18377. function CFFParser(file, properties) {
  18378. this.bytes = file.getBytes();
  18379. this.properties = properties;
  18380. }
  18381. CFFParser.prototype = {
  18382. parse: function CFFParser_parse() {
  18383. var properties = this.properties;
  18384. var cff = new CFF();
  18385. this.cff = cff;
  18386. // The first five sections must be in order, all the others are reached
  18387. // via offsets contained in one of the below.
  18388. var header = this.parseHeader();
  18389. var nameIndex = this.parseIndex(header.endPos);
  18390. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18391. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18392. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18393. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18394. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18395. cff.header = header.obj;
  18396. cff.names = this.parseNameIndex(nameIndex.obj);
  18397. cff.strings = this.parseStringIndex(stringIndex.obj);
  18398. cff.topDict = topDict;
  18399. cff.globalSubrIndex = globalSubrIndex.obj;
  18400. this.parsePrivateDict(cff.topDict);
  18401. cff.isCIDFont = topDict.hasName('ROS');
  18402. var charStringOffset = topDict.getByName('CharStrings');
  18403. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18404. cff.charStrings = charStringsAndSeacs.charStrings;
  18405. cff.seacs = charStringsAndSeacs.seacs;
  18406. cff.widths = charStringsAndSeacs.widths;
  18407. var fontMatrix = topDict.getByName('FontMatrix');
  18408. if (fontMatrix) {
  18409. properties.fontMatrix = fontMatrix;
  18410. }
  18411. var fontBBox = topDict.getByName('FontBBox');
  18412. if (fontBBox) {
  18413. // adjusting ascent/descent
  18414. properties.ascent = fontBBox[3];
  18415. properties.descent = fontBBox[1];
  18416. properties.ascentScaled = true;
  18417. }
  18418. var charset, encoding;
  18419. if (cff.isCIDFont) {
  18420. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18421. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18422. var dictRaw = fdArrayIndex.get(i);
  18423. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18424. cff.strings);
  18425. this.parsePrivateDict(fontDict);
  18426. cff.fdArray.push(fontDict);
  18427. }
  18428. // cid fonts don't have an encoding
  18429. encoding = null;
  18430. charset = this.parseCharsets(topDict.getByName('charset'),
  18431. cff.charStrings.count, cff.strings, true);
  18432. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18433. cff.charStrings.count);
  18434. } else {
  18435. charset = this.parseCharsets(topDict.getByName('charset'),
  18436. cff.charStrings.count, cff.strings, false);
  18437. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18438. properties,
  18439. cff.strings, charset.charset);
  18440. }
  18441. cff.charset = charset;
  18442. cff.encoding = encoding;
  18443. return cff;
  18444. },
  18445. parseHeader: function CFFParser_parseHeader() {
  18446. var bytes = this.bytes;
  18447. var bytesLength = bytes.length;
  18448. var offset = 0;
  18449. // Prevent an infinite loop, by checking that the offset is within the
  18450. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18451. while (offset < bytesLength && bytes[offset] !== 1) {
  18452. ++offset;
  18453. }
  18454. if (offset >= bytesLength) {
  18455. error('Invalid CFF header');
  18456. } else if (offset !== 0) {
  18457. info('cff data is shifted');
  18458. bytes = bytes.subarray(offset);
  18459. this.bytes = bytes;
  18460. }
  18461. var major = bytes[0];
  18462. var minor = bytes[1];
  18463. var hdrSize = bytes[2];
  18464. var offSize = bytes[3];
  18465. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18466. return { obj: header, endPos: hdrSize };
  18467. },
  18468. parseDict: function CFFParser_parseDict(dict) {
  18469. var pos = 0;
  18470. function parseOperand() {
  18471. var value = dict[pos++];
  18472. if (value === 30) {
  18473. return parseFloatOperand(pos);
  18474. } else if (value === 28) {
  18475. value = dict[pos++];
  18476. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18477. return value;
  18478. } else if (value === 29) {
  18479. value = dict[pos++];
  18480. value = (value << 8) | dict[pos++];
  18481. value = (value << 8) | dict[pos++];
  18482. value = (value << 8) | dict[pos++];
  18483. return value;
  18484. } else if (value >= 32 && value <= 246) {
  18485. return value - 139;
  18486. } else if (value >= 247 && value <= 250) {
  18487. return ((value - 247) * 256) + dict[pos++] + 108;
  18488. } else if (value >= 251 && value <= 254) {
  18489. return -((value - 251) * 256) - dict[pos++] - 108;
  18490. } else {
  18491. error('255 is not a valid DICT command');
  18492. }
  18493. return -1;
  18494. }
  18495. function parseFloatOperand() {
  18496. var str = '';
  18497. var eof = 15;
  18498. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18499. '9', '.', 'E', 'E-', null, '-'];
  18500. var length = dict.length;
  18501. while (pos < length) {
  18502. var b = dict[pos++];
  18503. var b1 = b >> 4;
  18504. var b2 = b & 15;
  18505. if (b1 === eof) {
  18506. break;
  18507. }
  18508. str += lookup[b1];
  18509. if (b2 === eof) {
  18510. break;
  18511. }
  18512. str += lookup[b2];
  18513. }
  18514. return parseFloat(str);
  18515. }
  18516. var operands = [];
  18517. var entries = [];
  18518. pos = 0;
  18519. var end = dict.length;
  18520. while (pos < end) {
  18521. var b = dict[pos];
  18522. if (b <= 21) {
  18523. if (b === 12) {
  18524. b = (b << 8) | dict[++pos];
  18525. }
  18526. entries.push([b, operands]);
  18527. operands = [];
  18528. ++pos;
  18529. } else {
  18530. operands.push(parseOperand());
  18531. }
  18532. }
  18533. return entries;
  18534. },
  18535. parseIndex: function CFFParser_parseIndex(pos) {
  18536. var cffIndex = new CFFIndex();
  18537. var bytes = this.bytes;
  18538. var count = (bytes[pos++] << 8) | bytes[pos++];
  18539. var offsets = [];
  18540. var end = pos;
  18541. var i, ii;
  18542. if (count !== 0) {
  18543. var offsetSize = bytes[pos++];
  18544. // add 1 for offset to determine size of last object
  18545. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18546. for (i = 0, ii = count + 1; i < ii; ++i) {
  18547. var offset = 0;
  18548. for (var j = 0; j < offsetSize; ++j) {
  18549. offset <<= 8;
  18550. offset += bytes[pos++];
  18551. }
  18552. offsets.push(startPos + offset);
  18553. }
  18554. end = offsets[count];
  18555. }
  18556. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18557. var offsetStart = offsets[i];
  18558. var offsetEnd = offsets[i + 1];
  18559. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18560. }
  18561. return {obj: cffIndex, endPos: end};
  18562. },
  18563. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18564. var names = [];
  18565. for (var i = 0, ii = index.count; i < ii; ++i) {
  18566. var name = index.get(i);
  18567. // OTS doesn't allow names to be over 127 characters.
  18568. var length = Math.min(name.length, 127);
  18569. var data = [];
  18570. // OTS also only permits certain characters in the name.
  18571. for (var j = 0; j < length; ++j) {
  18572. var c = name[j];
  18573. if (j === 0 && c === 0) {
  18574. data[j] = c;
  18575. continue;
  18576. }
  18577. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18578. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18579. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18580. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18581. data[j] = 95;
  18582. continue;
  18583. }
  18584. data[j] = c;
  18585. }
  18586. names.push(bytesToString(data));
  18587. }
  18588. return names;
  18589. },
  18590. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18591. var strings = new CFFStrings();
  18592. for (var i = 0, ii = index.count; i < ii; ++i) {
  18593. var data = index.get(i);
  18594. strings.add(bytesToString(data));
  18595. }
  18596. return strings;
  18597. },
  18598. createDict: function CFFParser_createDict(Type, dict, strings) {
  18599. var cffDict = new Type(strings);
  18600. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18601. var pair = dict[i];
  18602. var key = pair[0];
  18603. var value = pair[1];
  18604. cffDict.setByKey(key, value);
  18605. }
  18606. return cffDict;
  18607. },
  18608. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18609. var charStrings = this.parseIndex(charStringOffset).obj;
  18610. var seacs = [];
  18611. var widths = [];
  18612. var count = charStrings.count;
  18613. for (var i = 0; i < count; i++) {
  18614. var charstring = charStrings.get(i);
  18615. var stackSize = 0;
  18616. var stack = [];
  18617. var undefStack = true;
  18618. var hints = 0;
  18619. var valid = true;
  18620. var data = charstring;
  18621. var length = data.length;
  18622. var firstStackClearing = true;
  18623. for (var j = 0; j < length;) {
  18624. var value = data[j++];
  18625. var validationCommand = null;
  18626. if (value === 12) {
  18627. var q = data[j++];
  18628. if (q === 0) {
  18629. // The CFF specification state that the 'dotsection' command
  18630. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18631. // charstrings processors should support them. Unfortunately
  18632. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18633. // is replaced by a useless (0, hmoveto).
  18634. data[j - 2] = 139;
  18635. data[j - 1] = 22;
  18636. stackSize = 0;
  18637. } else {
  18638. validationCommand = CharstringValidationData12[q];
  18639. }
  18640. } else if (value === 28) { // number (16 bit)
  18641. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18642. j += 2;
  18643. stackSize++;
  18644. } else if (value === 14) {
  18645. if (stackSize >= 4) {
  18646. stackSize -= 4;
  18647. if (SEAC_ANALYSIS_ENABLED) {
  18648. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18649. valid = false;
  18650. }
  18651. }
  18652. validationCommand = CharstringValidationData[value];
  18653. } else if (value >= 32 && value <= 246) { // number
  18654. stack[stackSize] = value - 139;
  18655. stackSize++;
  18656. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18657. stack[stackSize] = (value < 251 ?
  18658. ((value - 247) << 8) + data[j] + 108 :
  18659. -((value - 251) << 8) - data[j] - 108);
  18660. j++;
  18661. stackSize++;
  18662. } else if (value === 255) { // number (32 bit)
  18663. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18664. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18665. j += 4;
  18666. stackSize++;
  18667. } else if (value === 19 || value === 20) {
  18668. hints += stackSize >> 1;
  18669. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18670. stackSize %= 2;
  18671. validationCommand = CharstringValidationData[value];
  18672. } else {
  18673. validationCommand = CharstringValidationData[value];
  18674. }
  18675. if (validationCommand) {
  18676. if (validationCommand.stem) {
  18677. hints += stackSize >> 1;
  18678. }
  18679. if ('min' in validationCommand) {
  18680. if (!undefStack && stackSize < validationCommand.min) {
  18681. warn('Not enough parameters for ' + validationCommand.id +
  18682. '; actual: ' + stackSize +
  18683. ', expected: ' + validationCommand.min);
  18684. valid = false;
  18685. break;
  18686. }
  18687. }
  18688. if (firstStackClearing && validationCommand.stackClearing) {
  18689. firstStackClearing = false;
  18690. // the optional character width can be found before the first
  18691. // stack-clearing command arguments
  18692. stackSize -= validationCommand.min;
  18693. if (stackSize >= 2 && validationCommand.stem) {
  18694. // there are even amount of arguments for stem commands
  18695. stackSize %= 2;
  18696. } else if (stackSize > 1) {
  18697. warn('Found too many parameters for stack-clearing command');
  18698. }
  18699. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18700. widths[i] = stack[stackSize - 1];
  18701. }
  18702. }
  18703. if ('stackDelta' in validationCommand) {
  18704. if ('stackFn' in validationCommand) {
  18705. validationCommand.stackFn(stack, stackSize);
  18706. }
  18707. stackSize += validationCommand.stackDelta;
  18708. } else if (validationCommand.stackClearing) {
  18709. stackSize = 0;
  18710. } else if (validationCommand.resetStack) {
  18711. stackSize = 0;
  18712. undefStack = false;
  18713. } else if (validationCommand.undefStack) {
  18714. stackSize = 0;
  18715. undefStack = true;
  18716. firstStackClearing = false;
  18717. }
  18718. }
  18719. }
  18720. if (!valid) {
  18721. // resetting invalid charstring to single 'endchar'
  18722. charStrings.set(i, new Uint8Array([14]));
  18723. }
  18724. }
  18725. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18726. },
  18727. emptyPrivateDictionary:
  18728. function CFFParser_emptyPrivateDictionary(parentDict) {
  18729. var privateDict = this.createDict(CFFPrivateDict, [],
  18730. parentDict.strings);
  18731. parentDict.setByKey(18, [0, 0]);
  18732. parentDict.privateDict = privateDict;
  18733. },
  18734. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18735. // no private dict, do nothing
  18736. if (!parentDict.hasName('Private')) {
  18737. this.emptyPrivateDictionary(parentDict);
  18738. return;
  18739. }
  18740. var privateOffset = parentDict.getByName('Private');
  18741. // make sure the params are formatted correctly
  18742. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18743. parentDict.removeByName('Private');
  18744. return;
  18745. }
  18746. var size = privateOffset[0];
  18747. var offset = privateOffset[1];
  18748. // remove empty dicts or ones that refer to invalid location
  18749. if (size === 0 || offset >= this.bytes.length) {
  18750. this.emptyPrivateDictionary(parentDict);
  18751. return;
  18752. }
  18753. var privateDictEnd = offset + size;
  18754. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18755. var dict = this.parseDict(dictData);
  18756. var privateDict = this.createDict(CFFPrivateDict, dict,
  18757. parentDict.strings);
  18758. parentDict.privateDict = privateDict;
  18759. // Parse the Subrs index also since it's relative to the private dict.
  18760. if (!privateDict.getByName('Subrs')) {
  18761. return;
  18762. }
  18763. var subrsOffset = privateDict.getByName('Subrs');
  18764. var relativeOffset = offset + subrsOffset;
  18765. // Validate the offset.
  18766. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18767. this.emptyPrivateDictionary(parentDict);
  18768. return;
  18769. }
  18770. var subrsIndex = this.parseIndex(relativeOffset);
  18771. privateDict.subrsIndex = subrsIndex.obj;
  18772. },
  18773. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18774. if (pos === 0) {
  18775. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18776. ISOAdobeCharset);
  18777. } else if (pos === 1) {
  18778. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18779. ExpertCharset);
  18780. } else if (pos === 2) {
  18781. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18782. ExpertSubsetCharset);
  18783. }
  18784. var bytes = this.bytes;
  18785. var start = pos;
  18786. var format = bytes[pos++];
  18787. var charset = ['.notdef'];
  18788. var id, count, i;
  18789. // subtract 1 for the .notdef glyph
  18790. length -= 1;
  18791. switch (format) {
  18792. case 0:
  18793. for (i = 0; i < length; i++) {
  18794. id = (bytes[pos++] << 8) | bytes[pos++];
  18795. charset.push(cid ? id : strings.get(id));
  18796. }
  18797. break;
  18798. case 1:
  18799. while (charset.length <= length) {
  18800. id = (bytes[pos++] << 8) | bytes[pos++];
  18801. count = bytes[pos++];
  18802. for (i = 0; i <= count; i++) {
  18803. charset.push(cid ? id++ : strings.get(id++));
  18804. }
  18805. }
  18806. break;
  18807. case 2:
  18808. while (charset.length <= length) {
  18809. id = (bytes[pos++] << 8) | bytes[pos++];
  18810. count = (bytes[pos++] << 8) | bytes[pos++];
  18811. for (i = 0; i <= count; i++) {
  18812. charset.push(cid ? id++ : strings.get(id++));
  18813. }
  18814. }
  18815. break;
  18816. default:
  18817. error('Unknown charset format');
  18818. }
  18819. // Raw won't be needed if we actually compile the charset.
  18820. var end = pos;
  18821. var raw = bytes.subarray(start, end);
  18822. return new CFFCharset(false, format, charset, raw);
  18823. },
  18824. parseEncoding: function CFFParser_parseEncoding(pos,
  18825. properties,
  18826. strings,
  18827. charset) {
  18828. var encoding = {};
  18829. var bytes = this.bytes;
  18830. var predefined = false;
  18831. var hasSupplement = false;
  18832. var format, i, ii;
  18833. var raw = null;
  18834. function readSupplement() {
  18835. var supplementsCount = bytes[pos++];
  18836. for (i = 0; i < supplementsCount; i++) {
  18837. var code = bytes[pos++];
  18838. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18839. encoding[code] = charset.indexOf(strings.get(sid));
  18840. }
  18841. }
  18842. if (pos === 0 || pos === 1) {
  18843. predefined = true;
  18844. format = pos;
  18845. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18846. Encodings.StandardEncoding;
  18847. for (i = 0, ii = charset.length; i < ii; i++) {
  18848. var index = baseEncoding.indexOf(charset[i]);
  18849. if (index !== -1) {
  18850. encoding[index] = i;
  18851. }
  18852. }
  18853. } else {
  18854. var dataStart = pos;
  18855. format = bytes[pos++];
  18856. switch (format & 0x7f) {
  18857. case 0:
  18858. var glyphsCount = bytes[pos++];
  18859. for (i = 1; i <= glyphsCount; i++) {
  18860. encoding[bytes[pos++]] = i;
  18861. }
  18862. break;
  18863. case 1:
  18864. var rangesCount = bytes[pos++];
  18865. var gid = 1;
  18866. for (i = 0; i < rangesCount; i++) {
  18867. var start = bytes[pos++];
  18868. var left = bytes[pos++];
  18869. for (var j = start; j <= start + left; j++) {
  18870. encoding[j] = gid++;
  18871. }
  18872. }
  18873. break;
  18874. default:
  18875. error('Unknow encoding format: ' + format + ' in CFF');
  18876. break;
  18877. }
  18878. var dataEnd = pos;
  18879. if (format & 0x80) {
  18880. // The font sanitizer does not support CFF encoding with a
  18881. // supplement, since the encoding is not really used to map
  18882. // between gid to glyph, let's overwrite what is declared in
  18883. // the top dictionary to let the sanitizer think the font use
  18884. // StandardEncoding, that's a lie but that's ok.
  18885. bytes[dataStart] &= 0x7f;
  18886. readSupplement();
  18887. hasSupplement = true;
  18888. }
  18889. raw = bytes.subarray(dataStart, dataEnd);
  18890. }
  18891. format = format & 0x7f;
  18892. return new CFFEncoding(predefined, format, encoding, raw);
  18893. },
  18894. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18895. var start = pos;
  18896. var bytes = this.bytes;
  18897. var format = bytes[pos++];
  18898. var fdSelect = [];
  18899. var i;
  18900. switch (format) {
  18901. case 0:
  18902. for (i = 0; i < length; ++i) {
  18903. var id = bytes[pos++];
  18904. fdSelect.push(id);
  18905. }
  18906. break;
  18907. case 3:
  18908. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18909. for (i = 0; i < rangesCount; ++i) {
  18910. var first = (bytes[pos++] << 8) | bytes[pos++];
  18911. var fdIndex = bytes[pos++];
  18912. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18913. for (var j = first; j < next; ++j) {
  18914. fdSelect.push(fdIndex);
  18915. }
  18916. }
  18917. // Advance past the sentinel(next).
  18918. pos += 2;
  18919. break;
  18920. default:
  18921. error('Unknown fdselect format ' + format);
  18922. break;
  18923. }
  18924. var end = pos;
  18925. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18926. }
  18927. };
  18928. return CFFParser;
  18929. })();
  18930. // Compact Font Format
  18931. var CFF = (function CFFClosure() {
  18932. function CFF() {
  18933. this.header = null;
  18934. this.names = [];
  18935. this.topDict = null;
  18936. this.strings = new CFFStrings();
  18937. this.globalSubrIndex = null;
  18938. // The following could really be per font, but since we only have one font
  18939. // store them here.
  18940. this.encoding = null;
  18941. this.charset = null;
  18942. this.charStrings = null;
  18943. this.fdArray = [];
  18944. this.fdSelect = null;
  18945. this.isCIDFont = false;
  18946. }
  18947. return CFF;
  18948. })();
  18949. var CFFHeader = (function CFFHeaderClosure() {
  18950. function CFFHeader(major, minor, hdrSize, offSize) {
  18951. this.major = major;
  18952. this.minor = minor;
  18953. this.hdrSize = hdrSize;
  18954. this.offSize = offSize;
  18955. }
  18956. return CFFHeader;
  18957. })();
  18958. var CFFStrings = (function CFFStringsClosure() {
  18959. function CFFStrings() {
  18960. this.strings = [];
  18961. }
  18962. CFFStrings.prototype = {
  18963. get: function CFFStrings_get(index) {
  18964. if (index >= 0 && index <= 390) {
  18965. return CFFStandardStrings[index];
  18966. }
  18967. if (index - 391 <= this.strings.length) {
  18968. return this.strings[index - 391];
  18969. }
  18970. return CFFStandardStrings[0];
  18971. },
  18972. add: function CFFStrings_add(value) {
  18973. this.strings.push(value);
  18974. },
  18975. get count() {
  18976. return this.strings.length;
  18977. }
  18978. };
  18979. return CFFStrings;
  18980. })();
  18981. var CFFIndex = (function CFFIndexClosure() {
  18982. function CFFIndex() {
  18983. this.objects = [];
  18984. this.length = 0;
  18985. }
  18986. CFFIndex.prototype = {
  18987. add: function CFFIndex_add(data) {
  18988. this.length += data.length;
  18989. this.objects.push(data);
  18990. },
  18991. set: function CFFIndex_set(index, data) {
  18992. this.length += data.length - this.objects[index].length;
  18993. this.objects[index] = data;
  18994. },
  18995. get: function CFFIndex_get(index) {
  18996. return this.objects[index];
  18997. },
  18998. get count() {
  18999. return this.objects.length;
  19000. }
  19001. };
  19002. return CFFIndex;
  19003. })();
  19004. var CFFDict = (function CFFDictClosure() {
  19005. function CFFDict(tables, strings) {
  19006. this.keyToNameMap = tables.keyToNameMap;
  19007. this.nameToKeyMap = tables.nameToKeyMap;
  19008. this.defaults = tables.defaults;
  19009. this.types = tables.types;
  19010. this.opcodes = tables.opcodes;
  19011. this.order = tables.order;
  19012. this.strings = strings;
  19013. this.values = {};
  19014. }
  19015. CFFDict.prototype = {
  19016. // value should always be an array
  19017. setByKey: function CFFDict_setByKey(key, value) {
  19018. if (!(key in this.keyToNameMap)) {
  19019. return false;
  19020. }
  19021. // ignore empty values
  19022. if (value.length === 0) {
  19023. return true;
  19024. }
  19025. var type = this.types[key];
  19026. // remove the array wrapping these types of values
  19027. if (type === 'num' || type === 'sid' || type === 'offset') {
  19028. value = value[0];
  19029. }
  19030. this.values[key] = value;
  19031. return true;
  19032. },
  19033. setByName: function CFFDict_setByName(name, value) {
  19034. if (!(name in this.nameToKeyMap)) {
  19035. error('Invalid dictionary name "' + name + '"');
  19036. }
  19037. this.values[this.nameToKeyMap[name]] = value;
  19038. },
  19039. hasName: function CFFDict_hasName(name) {
  19040. return this.nameToKeyMap[name] in this.values;
  19041. },
  19042. getByName: function CFFDict_getByName(name) {
  19043. if (!(name in this.nameToKeyMap)) {
  19044. error('Invalid dictionary name "' + name + '"');
  19045. }
  19046. var key = this.nameToKeyMap[name];
  19047. if (!(key in this.values)) {
  19048. return this.defaults[key];
  19049. }
  19050. return this.values[key];
  19051. },
  19052. removeByName: function CFFDict_removeByName(name) {
  19053. delete this.values[this.nameToKeyMap[name]];
  19054. }
  19055. };
  19056. CFFDict.createTables = function CFFDict_createTables(layout) {
  19057. var tables = {
  19058. keyToNameMap: {},
  19059. nameToKeyMap: {},
  19060. defaults: {},
  19061. types: {},
  19062. opcodes: {},
  19063. order: []
  19064. };
  19065. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19066. var entry = layout[i];
  19067. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19068. tables.keyToNameMap[key] = entry[1];
  19069. tables.nameToKeyMap[entry[1]] = key;
  19070. tables.types[key] = entry[2];
  19071. tables.defaults[key] = entry[3];
  19072. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19073. tables.order.push(key);
  19074. }
  19075. return tables;
  19076. };
  19077. return CFFDict;
  19078. })();
  19079. var CFFTopDict = (function CFFTopDictClosure() {
  19080. var layout = [
  19081. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19082. [[12, 20], 'SyntheticBase', 'num', null],
  19083. [0, 'version', 'sid', null],
  19084. [1, 'Notice', 'sid', null],
  19085. [[12, 0], 'Copyright', 'sid', null],
  19086. [2, 'FullName', 'sid', null],
  19087. [3, 'FamilyName', 'sid', null],
  19088. [4, 'Weight', 'sid', null],
  19089. [[12, 1], 'isFixedPitch', 'num', 0],
  19090. [[12, 2], 'ItalicAngle', 'num', 0],
  19091. [[12, 3], 'UnderlinePosition', 'num', -100],
  19092. [[12, 4], 'UnderlineThickness', 'num', 50],
  19093. [[12, 5], 'PaintType', 'num', 0],
  19094. [[12, 6], 'CharstringType', 'num', 2],
  19095. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19096. [0.001, 0, 0, 0.001, 0, 0]],
  19097. [13, 'UniqueID', 'num', null],
  19098. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19099. [[12, 8], 'StrokeWidth', 'num', 0],
  19100. [14, 'XUID', 'array', null],
  19101. [15, 'charset', 'offset', 0],
  19102. [16, 'Encoding', 'offset', 0],
  19103. [17, 'CharStrings', 'offset', 0],
  19104. [18, 'Private', ['offset', 'offset'], null],
  19105. [[12, 21], 'PostScript', 'sid', null],
  19106. [[12, 22], 'BaseFontName', 'sid', null],
  19107. [[12, 23], 'BaseFontBlend', 'delta', null],
  19108. [[12, 31], 'CIDFontVersion', 'num', 0],
  19109. [[12, 32], 'CIDFontRevision', 'num', 0],
  19110. [[12, 33], 'CIDFontType', 'num', 0],
  19111. [[12, 34], 'CIDCount', 'num', 8720],
  19112. [[12, 35], 'UIDBase', 'num', null],
  19113. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19114. // before FDArray.
  19115. [[12, 37], 'FDSelect', 'offset', null],
  19116. [[12, 36], 'FDArray', 'offset', null],
  19117. [[12, 38], 'FontName', 'sid', null]
  19118. ];
  19119. var tables = null;
  19120. function CFFTopDict(strings) {
  19121. if (tables === null) {
  19122. tables = CFFDict.createTables(layout);
  19123. }
  19124. CFFDict.call(this, tables, strings);
  19125. this.privateDict = null;
  19126. }
  19127. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19128. return CFFTopDict;
  19129. })();
  19130. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19131. var layout = [
  19132. [6, 'BlueValues', 'delta', null],
  19133. [7, 'OtherBlues', 'delta', null],
  19134. [8, 'FamilyBlues', 'delta', null],
  19135. [9, 'FamilyOtherBlues', 'delta', null],
  19136. [[12, 9], 'BlueScale', 'num', 0.039625],
  19137. [[12, 10], 'BlueShift', 'num', 7],
  19138. [[12, 11], 'BlueFuzz', 'num', 1],
  19139. [10, 'StdHW', 'num', null],
  19140. [11, 'StdVW', 'num', null],
  19141. [[12, 12], 'StemSnapH', 'delta', null],
  19142. [[12, 13], 'StemSnapV', 'delta', null],
  19143. [[12, 14], 'ForceBold', 'num', 0],
  19144. [[12, 17], 'LanguageGroup', 'num', 0],
  19145. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19146. [[12, 19], 'initialRandomSeed', 'num', 0],
  19147. [20, 'defaultWidthX', 'num', 0],
  19148. [21, 'nominalWidthX', 'num', 0],
  19149. [19, 'Subrs', 'offset', null]
  19150. ];
  19151. var tables = null;
  19152. function CFFPrivateDict(strings) {
  19153. if (tables === null) {
  19154. tables = CFFDict.createTables(layout);
  19155. }
  19156. CFFDict.call(this, tables, strings);
  19157. this.subrsIndex = null;
  19158. }
  19159. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19160. return CFFPrivateDict;
  19161. })();
  19162. var CFFCharsetPredefinedTypes = {
  19163. ISO_ADOBE: 0,
  19164. EXPERT: 1,
  19165. EXPERT_SUBSET: 2
  19166. };
  19167. var CFFCharset = (function CFFCharsetClosure() {
  19168. function CFFCharset(predefined, format, charset, raw) {
  19169. this.predefined = predefined;
  19170. this.format = format;
  19171. this.charset = charset;
  19172. this.raw = raw;
  19173. }
  19174. return CFFCharset;
  19175. })();
  19176. var CFFEncoding = (function CFFEncodingClosure() {
  19177. function CFFEncoding(predefined, format, encoding, raw) {
  19178. this.predefined = predefined;
  19179. this.format = format;
  19180. this.encoding = encoding;
  19181. this.raw = raw;
  19182. }
  19183. return CFFEncoding;
  19184. })();
  19185. var CFFFDSelect = (function CFFFDSelectClosure() {
  19186. function CFFFDSelect(fdSelect, raw) {
  19187. this.fdSelect = fdSelect;
  19188. this.raw = raw;
  19189. }
  19190. return CFFFDSelect;
  19191. })();
  19192. // Helper class to keep track of where an offset is within the data and helps
  19193. // filling in that offset once it's known.
  19194. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19195. function CFFOffsetTracker() {
  19196. this.offsets = {};
  19197. }
  19198. CFFOffsetTracker.prototype = {
  19199. isTracking: function CFFOffsetTracker_isTracking(key) {
  19200. return key in this.offsets;
  19201. },
  19202. track: function CFFOffsetTracker_track(key, location) {
  19203. if (key in this.offsets) {
  19204. error('Already tracking location of ' + key);
  19205. }
  19206. this.offsets[key] = location;
  19207. },
  19208. offset: function CFFOffsetTracker_offset(value) {
  19209. for (var key in this.offsets) {
  19210. this.offsets[key] += value;
  19211. }
  19212. },
  19213. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19214. values,
  19215. output) {
  19216. if (!(key in this.offsets)) {
  19217. error('Not tracking location of ' + key);
  19218. }
  19219. var data = output.data;
  19220. var dataOffset = this.offsets[key];
  19221. var size = 5;
  19222. for (var i = 0, ii = values.length; i < ii; ++i) {
  19223. var offset0 = i * size + dataOffset;
  19224. var offset1 = offset0 + 1;
  19225. var offset2 = offset0 + 2;
  19226. var offset3 = offset0 + 3;
  19227. var offset4 = offset0 + 4;
  19228. // It's easy to screw up offsets so perform this sanity check.
  19229. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19230. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19231. error('writing to an offset that is not empty');
  19232. }
  19233. var value = values[i];
  19234. data[offset0] = 0x1d;
  19235. data[offset1] = (value >> 24) & 0xFF;
  19236. data[offset2] = (value >> 16) & 0xFF;
  19237. data[offset3] = (value >> 8) & 0xFF;
  19238. data[offset4] = value & 0xFF;
  19239. }
  19240. }
  19241. };
  19242. return CFFOffsetTracker;
  19243. })();
  19244. // Takes a CFF and converts it to the binary representation.
  19245. var CFFCompiler = (function CFFCompilerClosure() {
  19246. function CFFCompiler(cff) {
  19247. this.cff = cff;
  19248. }
  19249. CFFCompiler.prototype = {
  19250. compile: function CFFCompiler_compile() {
  19251. var cff = this.cff;
  19252. var output = {
  19253. data: [],
  19254. length: 0,
  19255. add: function CFFCompiler_add(data) {
  19256. this.data = this.data.concat(data);
  19257. this.length = this.data.length;
  19258. }
  19259. };
  19260. // Compile the five entries that must be in order.
  19261. var header = this.compileHeader(cff.header);
  19262. output.add(header);
  19263. var nameIndex = this.compileNameIndex(cff.names);
  19264. output.add(nameIndex);
  19265. if (cff.isCIDFont) {
  19266. // The spec is unclear on how font matrices should relate to each other
  19267. // when there is one in the main top dict and the sub top dicts.
  19268. // Windows handles this differently than linux and osx so we have to
  19269. // normalize to work on all.
  19270. // Rules based off of some mailing list discussions:
  19271. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19272. // - If no main font matrix and there is a subfont matrix, use the
  19273. // subfont matrix.
  19274. // - If both have matrices, concat together.
  19275. // - If neither have matrices, use default.
  19276. // To make this work on all platforms we move the top matrix into each
  19277. // sub top dict and concat if necessary.
  19278. if (cff.topDict.hasName('FontMatrix')) {
  19279. var base = cff.topDict.getByName('FontMatrix');
  19280. cff.topDict.removeByName('FontMatrix');
  19281. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19282. var subDict = cff.fdArray[i];
  19283. var matrix = base.slice(0);
  19284. if (subDict.hasName('FontMatrix')) {
  19285. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19286. }
  19287. subDict.setByName('FontMatrix', matrix);
  19288. }
  19289. }
  19290. }
  19291. var compiled = this.compileTopDicts([cff.topDict],
  19292. output.length,
  19293. cff.isCIDFont);
  19294. output.add(compiled.output);
  19295. var topDictTracker = compiled.trackers[0];
  19296. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19297. output.add(stringIndex);
  19298. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19299. output.add(globalSubrIndex);
  19300. // Now start on the other entries that have no specfic order.
  19301. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19302. if (cff.encoding.predefined) {
  19303. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19304. output);
  19305. } else {
  19306. var encoding = this.compileEncoding(cff.encoding);
  19307. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19308. output.add(encoding);
  19309. }
  19310. }
  19311. if (cff.charset && cff.topDict.hasName('charset')) {
  19312. if (cff.charset.predefined) {
  19313. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19314. output);
  19315. } else {
  19316. var charset = this.compileCharset(cff.charset);
  19317. topDictTracker.setEntryLocation('charset', [output.length], output);
  19318. output.add(charset);
  19319. }
  19320. }
  19321. var charStrings = this.compileCharStrings(cff.charStrings);
  19322. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19323. output.add(charStrings);
  19324. if (cff.isCIDFont) {
  19325. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19326. // and linux don't seem to care.
  19327. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19328. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19329. output.add(fdSelect);
  19330. // It is unclear if the sub font dictionary can have CID related
  19331. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19332. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19333. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19334. output.add(compiled.output);
  19335. var fontDictTrackers = compiled.trackers;
  19336. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19337. }
  19338. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19339. // If the font data ends with INDEX whose object data is zero-length,
  19340. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19341. output.add([0]);
  19342. return output.data;
  19343. },
  19344. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19345. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19346. return this.encodeInteger(value);
  19347. } else {
  19348. return this.encodeFloat(value);
  19349. }
  19350. },
  19351. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19352. var value = num.toString();
  19353. // rounding inaccurate doubles
  19354. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19355. if (m) {
  19356. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19357. value = (Math.round(num * epsilon) / epsilon).toString();
  19358. }
  19359. var nibbles = '';
  19360. var i, ii;
  19361. for (i = 0, ii = value.length; i < ii; ++i) {
  19362. var a = value[i];
  19363. if (a === 'e') {
  19364. nibbles += value[++i] === '-' ? 'c' : 'b';
  19365. } else if (a === '.') {
  19366. nibbles += 'a';
  19367. } else if (a === '-') {
  19368. nibbles += 'e';
  19369. } else {
  19370. nibbles += a;
  19371. }
  19372. }
  19373. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19374. var out = [30];
  19375. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19376. out.push(parseInt(nibbles.substr(i, 2), 16));
  19377. }
  19378. return out;
  19379. },
  19380. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19381. var code;
  19382. if (value >= -107 && value <= 107) {
  19383. code = [value + 139];
  19384. } else if (value >= 108 && value <= 1131) {
  19385. value = [value - 108];
  19386. code = [(value >> 8) + 247, value & 0xFF];
  19387. } else if (value >= -1131 && value <= -108) {
  19388. value = -value - 108;
  19389. code = [(value >> 8) + 251, value & 0xFF];
  19390. } else if (value >= -32768 && value <= 32767) {
  19391. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19392. } else {
  19393. code = [0x1d,
  19394. (value >> 24) & 0xFF,
  19395. (value >> 16) & 0xFF,
  19396. (value >> 8) & 0xFF,
  19397. value & 0xFF];
  19398. }
  19399. return code;
  19400. },
  19401. compileHeader: function CFFCompiler_compileHeader(header) {
  19402. return [
  19403. header.major,
  19404. header.minor,
  19405. header.hdrSize,
  19406. header.offSize
  19407. ];
  19408. },
  19409. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19410. var nameIndex = new CFFIndex();
  19411. for (var i = 0, ii = names.length; i < ii; ++i) {
  19412. nameIndex.add(stringToBytes(names[i]));
  19413. }
  19414. return this.compileIndex(nameIndex);
  19415. },
  19416. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19417. length,
  19418. removeCidKeys) {
  19419. var fontDictTrackers = [];
  19420. var fdArrayIndex = new CFFIndex();
  19421. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19422. var fontDict = dicts[i];
  19423. if (removeCidKeys) {
  19424. fontDict.removeByName('CIDFontVersion');
  19425. fontDict.removeByName('CIDFontRevision');
  19426. fontDict.removeByName('CIDFontType');
  19427. fontDict.removeByName('CIDCount');
  19428. fontDict.removeByName('UIDBase');
  19429. }
  19430. var fontDictTracker = new CFFOffsetTracker();
  19431. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19432. fontDictTrackers.push(fontDictTracker);
  19433. fdArrayIndex.add(fontDictData);
  19434. fontDictTracker.offset(length);
  19435. }
  19436. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19437. return {
  19438. trackers: fontDictTrackers,
  19439. output: fdArrayIndex
  19440. };
  19441. },
  19442. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19443. trackers,
  19444. output) {
  19445. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19446. var fontDict = dicts[i];
  19447. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19448. 'There must be an private dictionary.');
  19449. var privateDict = fontDict.privateDict;
  19450. var privateDictTracker = new CFFOffsetTracker();
  19451. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19452. var outputLength = output.length;
  19453. privateDictTracker.offset(outputLength);
  19454. if (!privateDictData.length) {
  19455. // The private dictionary was empty, set the output length to zero to
  19456. // ensure the offset length isn't out of bounds in the eyes of the
  19457. // sanitizer.
  19458. outputLength = 0;
  19459. }
  19460. trackers[i].setEntryLocation('Private',
  19461. [privateDictData.length, outputLength],
  19462. output);
  19463. output.add(privateDictData);
  19464. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19465. var subrs = this.compileIndex(privateDict.subrsIndex);
  19466. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19467. output);
  19468. output.add(subrs);
  19469. }
  19470. }
  19471. },
  19472. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19473. var out = [];
  19474. // The dictionary keys must be in a certain order.
  19475. var order = dict.order;
  19476. for (var i = 0; i < order.length; ++i) {
  19477. var key = order[i];
  19478. if (!(key in dict.values)) {
  19479. continue;
  19480. }
  19481. var values = dict.values[key];
  19482. var types = dict.types[key];
  19483. if (!isArray(types)) {
  19484. types = [types];
  19485. }
  19486. if (!isArray(values)) {
  19487. values = [values];
  19488. }
  19489. // Remove any empty dict values.
  19490. if (values.length === 0) {
  19491. continue;
  19492. }
  19493. for (var j = 0, jj = types.length; j < jj; ++j) {
  19494. var type = types[j];
  19495. var value = values[j];
  19496. switch (type) {
  19497. case 'num':
  19498. case 'sid':
  19499. out = out.concat(this.encodeNumber(value));
  19500. break;
  19501. case 'offset':
  19502. // For offsets we just insert a 32bit integer so we don't have to
  19503. // deal with figuring out the length of the offset when it gets
  19504. // replaced later on by the compiler.
  19505. var name = dict.keyToNameMap[key];
  19506. // Some offsets have the offset and the length, so just record the
  19507. // position of the first one.
  19508. if (!offsetTracker.isTracking(name)) {
  19509. offsetTracker.track(name, out.length);
  19510. }
  19511. out = out.concat([0x1d, 0, 0, 0, 0]);
  19512. break;
  19513. case 'array':
  19514. case 'delta':
  19515. out = out.concat(this.encodeNumber(value));
  19516. for (var k = 1, kk = values.length; k < kk; ++k) {
  19517. out = out.concat(this.encodeNumber(values[k]));
  19518. }
  19519. break;
  19520. default:
  19521. error('Unknown data type of ' + type);
  19522. break;
  19523. }
  19524. }
  19525. out = out.concat(dict.opcodes[key]);
  19526. }
  19527. return out;
  19528. },
  19529. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19530. var stringIndex = new CFFIndex();
  19531. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19532. stringIndex.add(stringToBytes(strings[i]));
  19533. }
  19534. return this.compileIndex(stringIndex);
  19535. },
  19536. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19537. var globalSubrIndex = this.cff.globalSubrIndex;
  19538. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19539. },
  19540. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19541. return this.compileIndex(charStrings);
  19542. },
  19543. compileCharset: function CFFCompiler_compileCharset(charset) {
  19544. return this.compileTypedArray(charset.raw);
  19545. },
  19546. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19547. return this.compileTypedArray(encoding.raw);
  19548. },
  19549. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19550. return this.compileTypedArray(fdSelect);
  19551. },
  19552. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19553. var out = [];
  19554. for (var i = 0, ii = data.length; i < ii; ++i) {
  19555. out[i] = data[i];
  19556. }
  19557. return out;
  19558. },
  19559. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19560. trackers = trackers || [];
  19561. var objects = index.objects;
  19562. // First 2 bytes contains the number of objects contained into this index
  19563. var count = objects.length;
  19564. // If there is no object, just create an index. This technically
  19565. // should just be [0, 0] but OTS has an issue with that.
  19566. if (count === 0) {
  19567. return [0, 0, 0];
  19568. }
  19569. var data = [(count >> 8) & 0xFF, count & 0xff];
  19570. var lastOffset = 1, i;
  19571. for (i = 0; i < count; ++i) {
  19572. lastOffset += objects[i].length;
  19573. }
  19574. var offsetSize;
  19575. if (lastOffset < 0x100) {
  19576. offsetSize = 1;
  19577. } else if (lastOffset < 0x10000) {
  19578. offsetSize = 2;
  19579. } else if (lastOffset < 0x1000000) {
  19580. offsetSize = 3;
  19581. } else {
  19582. offsetSize = 4;
  19583. }
  19584. // Next byte contains the offset size use to reference object in the file
  19585. data.push(offsetSize);
  19586. // Add another offset after this one because we need a new offset
  19587. var relativeOffset = 1;
  19588. for (i = 0; i < count + 1; i++) {
  19589. if (offsetSize === 1) {
  19590. data.push(relativeOffset & 0xFF);
  19591. } else if (offsetSize === 2) {
  19592. data.push((relativeOffset >> 8) & 0xFF,
  19593. relativeOffset & 0xFF);
  19594. } else if (offsetSize === 3) {
  19595. data.push((relativeOffset >> 16) & 0xFF,
  19596. (relativeOffset >> 8) & 0xFF,
  19597. relativeOffset & 0xFF);
  19598. } else {
  19599. data.push((relativeOffset >>> 24) & 0xFF,
  19600. (relativeOffset >> 16) & 0xFF,
  19601. (relativeOffset >> 8) & 0xFF,
  19602. relativeOffset & 0xFF);
  19603. }
  19604. if (objects[i]) {
  19605. relativeOffset += objects[i].length;
  19606. }
  19607. }
  19608. for (i = 0; i < count; i++) {
  19609. // Notify the tracker where the object will be offset in the data.
  19610. if (trackers[i]) {
  19611. trackers[i].offset(data.length);
  19612. }
  19613. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19614. data.push(objects[i][j]);
  19615. }
  19616. }
  19617. return data;
  19618. }
  19619. };
  19620. return CFFCompiler;
  19621. })();
  19622. // Workaround for seac on Windows.
  19623. (function checkSeacSupport() {
  19624. if (/Windows/.test(navigator.userAgent)) {
  19625. SEAC_ANALYSIS_ENABLED = true;
  19626. }
  19627. })();
  19628. // Workaround for Private Use Area characters in Chrome on Windows
  19629. // http://code.google.com/p/chromium/issues/detail?id=122465
  19630. // https://github.com/mozilla/pdf.js/issues/1689
  19631. (function checkChromeWindows() {
  19632. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19633. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19634. }
  19635. })();
  19636. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19637. function getLong(data, offset) {
  19638. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19639. (data[offset + 2] << 8) | data[offset + 3];
  19640. }
  19641. function getUshort(data, offset) {
  19642. return (data[offset] << 8) | data[offset + 1];
  19643. }
  19644. function parseCmap(data, start, end) {
  19645. var offset = (getUshort(data, start + 2) === 1 ?
  19646. getLong(data, start + 8) : getLong(data, start + 16));
  19647. var format = getUshort(data, start + offset);
  19648. var length, ranges, p, i;
  19649. if (format === 4) {
  19650. length = getUshort(data, start + offset + 2);
  19651. var segCount = getUshort(data, start + offset + 6) >> 1;
  19652. p = start + offset + 14;
  19653. ranges = [];
  19654. for (i = 0; i < segCount; i++, p += 2) {
  19655. ranges[i] = {end: getUshort(data, p)};
  19656. }
  19657. p += 2;
  19658. for (i = 0; i < segCount; i++, p += 2) {
  19659. ranges[i].start = getUshort(data, p);
  19660. }
  19661. for (i = 0; i < segCount; i++, p += 2) {
  19662. ranges[i].idDelta = getUshort(data, p);
  19663. }
  19664. for (i = 0; i < segCount; i++, p += 2) {
  19665. var idOffset = getUshort(data, p);
  19666. if (idOffset === 0) {
  19667. continue;
  19668. }
  19669. ranges[i].ids = [];
  19670. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19671. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19672. idOffset += 2;
  19673. }
  19674. }
  19675. return ranges;
  19676. } else if (format === 12) {
  19677. length = getLong(data, start + offset + 4);
  19678. var groups = getLong(data, start + offset + 12);
  19679. p = start + offset + 16;
  19680. ranges = [];
  19681. for (i = 0; i < groups; i++) {
  19682. ranges.push({
  19683. start: getLong(data, p),
  19684. end: getLong(data, p + 4),
  19685. idDelta: getLong(data, p + 8) - getLong(data, p)
  19686. });
  19687. p += 12;
  19688. }
  19689. return ranges;
  19690. }
  19691. error('not supported cmap: ' + format);
  19692. }
  19693. function parseCff(data, start, end) {
  19694. var properties = {};
  19695. var parser = new CFFParser(new Stream(data, start, end - start),
  19696. properties);
  19697. var cff = parser.parse();
  19698. return {
  19699. glyphs: cff.charStrings.objects,
  19700. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19701. cff.topDict.privateDict.subrsIndex.objects),
  19702. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19703. };
  19704. }
  19705. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19706. var itemSize, itemDecode;
  19707. if (isGlyphLocationsLong) {
  19708. itemSize = 4;
  19709. itemDecode = function fontItemDecodeLong(data, offset) {
  19710. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19711. (data[offset + 2] << 8) | data[offset + 3];
  19712. };
  19713. } else {
  19714. itemSize = 2;
  19715. itemDecode = function fontItemDecode(data, offset) {
  19716. return (data[offset] << 9) | (data[offset + 1] << 1);
  19717. };
  19718. }
  19719. var glyphs = [];
  19720. var startOffset = itemDecode(loca, 0);
  19721. for (var j = itemSize; j < loca.length; j += itemSize) {
  19722. var endOffset = itemDecode(loca, j);
  19723. glyphs.push(glyf.subarray(startOffset, endOffset));
  19724. startOffset = endOffset;
  19725. }
  19726. return glyphs;
  19727. }
  19728. function lookupCmap(ranges, unicode) {
  19729. var code = unicode.charCodeAt(0);
  19730. var l = 0, r = ranges.length - 1;
  19731. while (l < r) {
  19732. var c = (l + r + 1) >> 1;
  19733. if (code < ranges[c].start) {
  19734. r = c - 1;
  19735. } else {
  19736. l = c;
  19737. }
  19738. }
  19739. if (ranges[l].start <= code && code <= ranges[l].end) {
  19740. return (ranges[l].idDelta + (ranges[l].ids ?
  19741. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19742. }
  19743. return 0;
  19744. }
  19745. function compileGlyf(code, js, font) {
  19746. function moveTo(x, y) {
  19747. js.push('c.moveTo(' + x + ',' + y + ');');
  19748. }
  19749. function lineTo(x, y) {
  19750. js.push('c.lineTo(' + x + ',' + y + ');');
  19751. }
  19752. function quadraticCurveTo(xa, ya, x, y) {
  19753. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19754. x + ',' + y + ');');
  19755. }
  19756. var i = 0;
  19757. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19758. var flags;
  19759. var x = 0, y = 0;
  19760. i += 10;
  19761. if (numberOfContours < 0) {
  19762. // composite glyph
  19763. do {
  19764. flags = (code[i] << 8) | code[i + 1];
  19765. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19766. i += 4;
  19767. var arg1, arg2;
  19768. if ((flags & 0x01)) {
  19769. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19770. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19771. i += 4;
  19772. } else {
  19773. arg1 = code[i++]; arg2 = code[i++];
  19774. }
  19775. if ((flags & 0x02)) {
  19776. x = arg1;
  19777. y = arg2;
  19778. } else {
  19779. x = 0; y = 0; // TODO "they are points" ?
  19780. }
  19781. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19782. if ((flags & 0x08)) {
  19783. scaleX =
  19784. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19785. i += 2;
  19786. } else if ((flags & 0x40)) {
  19787. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19788. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19789. i += 4;
  19790. } else if ((flags & 0x80)) {
  19791. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19792. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19793. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19794. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19795. i += 8;
  19796. }
  19797. var subglyph = font.glyphs[glyphIndex];
  19798. if (subglyph) {
  19799. js.push('c.save();');
  19800. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19801. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19802. compileGlyf(subglyph, js, font);
  19803. js.push('c.restore();');
  19804. }
  19805. } while ((flags & 0x20));
  19806. } else {
  19807. // simple glyph
  19808. var endPtsOfContours = [];
  19809. var j, jj;
  19810. for (j = 0; j < numberOfContours; j++) {
  19811. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19812. i += 2;
  19813. }
  19814. var instructionLength = (code[i] << 8) | code[i + 1];
  19815. i += 2 + instructionLength; // skipping the instructions
  19816. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19817. var points = [];
  19818. while (points.length < numberOfPoints) {
  19819. flags = code[i++];
  19820. var repeat = 1;
  19821. if ((flags & 0x08)) {
  19822. repeat += code[i++];
  19823. }
  19824. while (repeat-- > 0) {
  19825. points.push({flags: flags});
  19826. }
  19827. }
  19828. for (j = 0; j < numberOfPoints; j++) {
  19829. switch (points[j].flags & 0x12) {
  19830. case 0x00:
  19831. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19832. i += 2;
  19833. break;
  19834. case 0x02:
  19835. x -= code[i++];
  19836. break;
  19837. case 0x12:
  19838. x += code[i++];
  19839. break;
  19840. }
  19841. points[j].x = x;
  19842. }
  19843. for (j = 0; j < numberOfPoints; j++) {
  19844. switch (points[j].flags & 0x24) {
  19845. case 0x00:
  19846. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19847. i += 2;
  19848. break;
  19849. case 0x04:
  19850. y -= code[i++];
  19851. break;
  19852. case 0x24:
  19853. y += code[i++];
  19854. break;
  19855. }
  19856. points[j].y = y;
  19857. }
  19858. var startPoint = 0;
  19859. for (i = 0; i < numberOfContours; i++) {
  19860. var endPoint = endPtsOfContours[i];
  19861. // contours might have implicit points, which is located in the middle
  19862. // between two neighboring off-curve points
  19863. var contour = points.slice(startPoint, endPoint + 1);
  19864. if ((contour[0].flags & 1)) {
  19865. contour.push(contour[0]); // using start point at the contour end
  19866. } else if ((contour[contour.length - 1].flags & 1)) {
  19867. // first is off-curve point, trying to use one from the end
  19868. contour.unshift(contour[contour.length - 1]);
  19869. } else {
  19870. // start and end are off-curve points, creating implicit one
  19871. var p = {
  19872. flags: 1,
  19873. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19874. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19875. };
  19876. contour.unshift(p);
  19877. contour.push(p);
  19878. }
  19879. moveTo(contour[0].x, contour[0].y);
  19880. for (j = 1, jj = contour.length; j < jj; j++) {
  19881. if ((contour[j].flags & 1)) {
  19882. lineTo(contour[j].x, contour[j].y);
  19883. } else if ((contour[j + 1].flags & 1)){
  19884. quadraticCurveTo(contour[j].x, contour[j].y,
  19885. contour[j + 1].x, contour[j + 1].y);
  19886. j++;
  19887. } else {
  19888. quadraticCurveTo(contour[j].x, contour[j].y,
  19889. (contour[j].x + contour[j + 1].x) / 2,
  19890. (contour[j].y + contour[j + 1].y) / 2);
  19891. }
  19892. }
  19893. startPoint = endPoint + 1;
  19894. }
  19895. }
  19896. }
  19897. function compileCharString(code, js, font) {
  19898. var stack = [];
  19899. var x = 0, y = 0;
  19900. var stems = 0;
  19901. function moveTo(x, y) {
  19902. js.push('c.moveTo(' + x + ',' + y + ');');
  19903. }
  19904. function lineTo(x, y) {
  19905. js.push('c.lineTo(' + x + ',' + y + ');');
  19906. }
  19907. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19908. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19909. x + ',' + y + ');');
  19910. }
  19911. function parse(code) {
  19912. var i = 0;
  19913. while (i < code.length) {
  19914. var stackClean = false;
  19915. var v = code[i++];
  19916. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19917. switch (v) {
  19918. case 1: // hstem
  19919. stems += stack.length >> 1;
  19920. stackClean = true;
  19921. break;
  19922. case 3: // vstem
  19923. stems += stack.length >> 1;
  19924. stackClean = true;
  19925. break;
  19926. case 4: // vmoveto
  19927. y += stack.pop();
  19928. moveTo(x, y);
  19929. stackClean = true;
  19930. break;
  19931. case 5: // rlineto
  19932. while (stack.length > 0) {
  19933. x += stack.shift();
  19934. y += stack.shift();
  19935. lineTo(x, y);
  19936. }
  19937. break;
  19938. case 6: // hlineto
  19939. while (stack.length > 0) {
  19940. x += stack.shift();
  19941. lineTo(x, y);
  19942. if (stack.length === 0) {
  19943. break;
  19944. }
  19945. y += stack.shift();
  19946. lineTo(x, y);
  19947. }
  19948. break;
  19949. case 7: // vlineto
  19950. while (stack.length > 0) {
  19951. y += stack.shift();
  19952. lineTo(x, y);
  19953. if (stack.length === 0) {
  19954. break;
  19955. }
  19956. x += stack.shift();
  19957. lineTo(x, y);
  19958. }
  19959. break;
  19960. case 8: // rrcurveto
  19961. while (stack.length > 0) {
  19962. xa = x + stack.shift(); ya = y + stack.shift();
  19963. xb = xa + stack.shift(); yb = ya + stack.shift();
  19964. x = xb + stack.shift(); y = yb + stack.shift();
  19965. bezierCurveTo(xa, ya, xb, yb, x, y);
  19966. }
  19967. break;
  19968. case 10: // callsubr
  19969. n = stack.pop() + font.subrsBias;
  19970. subrCode = font.subrs[n];
  19971. if (subrCode) {
  19972. parse(subrCode);
  19973. }
  19974. break;
  19975. case 11: // return
  19976. return;
  19977. case 12:
  19978. v = code[i++];
  19979. switch (v) {
  19980. case 34: // flex
  19981. xa = x + stack.shift();
  19982. xb = xa + stack.shift(); y1 = y + stack.shift();
  19983. x = xb + stack.shift();
  19984. bezierCurveTo(xa, y, xb, y1, x, y1);
  19985. xa = x + stack.shift();
  19986. xb = xa + stack.shift();
  19987. x = xb + stack.shift();
  19988. bezierCurveTo(xa, y1, xb, y, x, y);
  19989. break;
  19990. case 35: // flex
  19991. xa = x + stack.shift(); ya = y + stack.shift();
  19992. xb = xa + stack.shift(); yb = ya + stack.shift();
  19993. x = xb + stack.shift(); y = yb + stack.shift();
  19994. bezierCurveTo(xa, ya, xb, yb, x, y);
  19995. xa = x + stack.shift(); ya = y + stack.shift();
  19996. xb = xa + stack.shift(); yb = ya + stack.shift();
  19997. x = xb + stack.shift(); y = yb + stack.shift();
  19998. bezierCurveTo(xa, ya, xb, yb, x, y);
  19999. stack.pop(); // fd
  20000. break;
  20001. case 36: // hflex1
  20002. xa = x + stack.shift(); y1 = y + stack.shift();
  20003. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20004. x = xb + stack.shift();
  20005. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20006. xa = x + stack.shift();
  20007. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20008. x = xb + stack.shift();
  20009. bezierCurveTo(xa, y2, xb, y3, x, y);
  20010. break;
  20011. case 37: // flex1
  20012. var x0 = x, y0 = y;
  20013. xa = x + stack.shift(); ya = y + stack.shift();
  20014. xb = xa + stack.shift(); yb = ya + stack.shift();
  20015. x = xb + stack.shift(); y = yb + stack.shift();
  20016. bezierCurveTo(xa, ya, xb, yb, x, y);
  20017. xa = x + stack.shift(); ya = y + stack.shift();
  20018. xb = xa + stack.shift(); yb = ya + stack.shift();
  20019. x = xb; y = yb;
  20020. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20021. x += stack.shift();
  20022. } else {
  20023. y += stack.shift();
  20024. }
  20025. bezierCurveTo(xa, ya, xb, yb, x, y);
  20026. break;
  20027. default:
  20028. error('unknown operator: 12 ' + v);
  20029. }
  20030. break;
  20031. case 14: // endchar
  20032. if (stack.length >= 4) {
  20033. var achar = stack.pop();
  20034. var bchar = stack.pop();
  20035. y = stack.pop();
  20036. x = stack.pop();
  20037. js.push('c.save();');
  20038. js.push('c.translate('+ x + ',' + y + ');');
  20039. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20040. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20041. compileCharString(font.glyphs[gid], js, font);
  20042. js.push('c.restore();');
  20043. gid = lookupCmap(font.cmap, String.fromCharCode(
  20044. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20045. compileCharString(font.glyphs[gid], js, font);
  20046. }
  20047. return;
  20048. case 18: // hstemhm
  20049. stems += stack.length >> 1;
  20050. stackClean = true;
  20051. break;
  20052. case 19: // hintmask
  20053. stems += stack.length >> 1;
  20054. i += (stems + 7) >> 3;
  20055. stackClean = true;
  20056. break;
  20057. case 20: // cntrmask
  20058. stems += stack.length >> 1;
  20059. i += (stems + 7) >> 3;
  20060. stackClean = true;
  20061. break;
  20062. case 21: // rmoveto
  20063. y += stack.pop();
  20064. x += stack.pop();
  20065. moveTo(x, y);
  20066. stackClean = true;
  20067. break;
  20068. case 22: // hmoveto
  20069. x += stack.pop();
  20070. moveTo(x, y);
  20071. stackClean = true;
  20072. break;
  20073. case 23: // vstemhm
  20074. stems += stack.length >> 1;
  20075. stackClean = true;
  20076. break;
  20077. case 24: // rcurveline
  20078. while (stack.length > 2) {
  20079. xa = x + stack.shift(); ya = y + stack.shift();
  20080. xb = xa + stack.shift(); yb = ya + stack.shift();
  20081. x = xb + stack.shift(); y = yb + stack.shift();
  20082. bezierCurveTo(xa, ya, xb, yb, x, y);
  20083. }
  20084. x += stack.shift();
  20085. y += stack.shift();
  20086. lineTo(x, y);
  20087. break;
  20088. case 25: // rlinecurve
  20089. while (stack.length > 6) {
  20090. x += stack.shift();
  20091. y += stack.shift();
  20092. lineTo(x, y);
  20093. }
  20094. xa = x + stack.shift(); ya = y + stack.shift();
  20095. xb = xa + stack.shift(); yb = ya + stack.shift();
  20096. x = xb + stack.shift(); y = yb + stack.shift();
  20097. bezierCurveTo(xa, ya, xb, yb, x, y);
  20098. break;
  20099. case 26: // vvcurveto
  20100. if (stack.length % 2) {
  20101. x += stack.shift();
  20102. }
  20103. while (stack.length > 0) {
  20104. xa = x; ya = y + stack.shift();
  20105. xb = xa + stack.shift(); yb = ya + stack.shift();
  20106. x = xb; y = yb + stack.shift();
  20107. bezierCurveTo(xa, ya, xb, yb, x, y);
  20108. }
  20109. break;
  20110. case 27: // hhcurveto
  20111. if (stack.length % 2) {
  20112. y += stack.shift();
  20113. }
  20114. while (stack.length > 0) {
  20115. xa = x + stack.shift(); ya = y;
  20116. xb = xa + stack.shift(); yb = ya + stack.shift();
  20117. x = xb + stack.shift(); y = yb;
  20118. bezierCurveTo(xa, ya, xb, yb, x, y);
  20119. }
  20120. break;
  20121. case 28:
  20122. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20123. i += 2;
  20124. break;
  20125. case 29: // callgsubr
  20126. n = stack.pop() + font.gsubrsBias;
  20127. subrCode = font.gsubrs[n];
  20128. if (subrCode) {
  20129. parse(subrCode);
  20130. }
  20131. break;
  20132. case 30: // vhcurveto
  20133. while (stack.length > 0) {
  20134. xa = x; ya = y + stack.shift();
  20135. xb = xa + stack.shift(); yb = ya + stack.shift();
  20136. x = xb + stack.shift();
  20137. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20138. bezierCurveTo(xa, ya, xb, yb, x, y);
  20139. if (stack.length === 0) {
  20140. break;
  20141. }
  20142. xa = x + stack.shift(); ya = y;
  20143. xb = xa + stack.shift(); yb = ya + stack.shift();
  20144. y = yb + stack.shift();
  20145. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20146. bezierCurveTo(xa, ya, xb, yb, x, y);
  20147. }
  20148. break;
  20149. case 31: // hvcurveto
  20150. while (stack.length > 0) {
  20151. xa = x + stack.shift(); ya = y;
  20152. xb = xa + stack.shift(); yb = ya + stack.shift();
  20153. y = yb + stack.shift();
  20154. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20155. bezierCurveTo(xa, ya, xb, yb, x, y);
  20156. if (stack.length === 0) {
  20157. break;
  20158. }
  20159. xa = x; ya = y + stack.shift();
  20160. xb = xa + stack.shift(); yb = ya + stack.shift();
  20161. x = xb + stack.shift();
  20162. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20163. bezierCurveTo(xa, ya, xb, yb, x, y);
  20164. }
  20165. break;
  20166. default:
  20167. if (v < 32) {
  20168. error('unknown operator: ' + v);
  20169. }
  20170. if (v < 247) {
  20171. stack.push(v - 139);
  20172. } else if (v < 251) {
  20173. stack.push((v - 247) * 256 + code[i++] + 108);
  20174. } else if (v < 255) {
  20175. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20176. } else {
  20177. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20178. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20179. i += 4;
  20180. }
  20181. break;
  20182. }
  20183. if (stackClean) {
  20184. stack.length = 0;
  20185. }
  20186. }
  20187. }
  20188. parse(code);
  20189. }
  20190. var noop = '';
  20191. function CompiledFont(fontMatrix) {
  20192. this.compiledGlyphs = {};
  20193. this.fontMatrix = fontMatrix;
  20194. }
  20195. CompiledFont.prototype = {
  20196. getPathJs: function (unicode) {
  20197. var gid = lookupCmap(this.cmap, unicode);
  20198. var fn = this.compiledGlyphs[gid];
  20199. if (!fn) {
  20200. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20201. }
  20202. return fn;
  20203. },
  20204. compileGlyph: function (code) {
  20205. if (!code || code.length === 0 || code[0] === 14) {
  20206. return noop;
  20207. }
  20208. var js = [];
  20209. js.push('c.save();');
  20210. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20211. js.push('c.scale(size, -size);');
  20212. this.compileGlyphImpl(code, js);
  20213. js.push('c.restore();');
  20214. return js.join('\n');
  20215. },
  20216. compileGlyphImpl: function () {
  20217. error('Children classes should implement this.');
  20218. },
  20219. hasBuiltPath: function (unicode) {
  20220. var gid = lookupCmap(this.cmap, unicode);
  20221. return gid in this.compiledGlyphs;
  20222. }
  20223. };
  20224. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20225. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20226. CompiledFont.call(this, fontMatrix);
  20227. this.glyphs = glyphs;
  20228. this.cmap = cmap;
  20229. this.compiledGlyphs = [];
  20230. }
  20231. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20232. compileGlyphImpl: function (code, js) {
  20233. compileGlyf(code, js, this);
  20234. }
  20235. });
  20236. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20237. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20238. CompiledFont.call(this, fontMatrix);
  20239. this.glyphs = cffInfo.glyphs;
  20240. this.gsubrs = cffInfo.gsubrs || [];
  20241. this.subrs = cffInfo.subrs || [];
  20242. this.cmap = cmap;
  20243. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20244. this.compiledGlyphs = [];
  20245. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20246. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20247. this.subrsBias = (this.subrs.length < 1240 ?
  20248. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20249. }
  20250. Util.inherit(Type2Compiled, CompiledFont, {
  20251. compileGlyphImpl: function (code, js) {
  20252. compileCharString(code, js, this);
  20253. }
  20254. });
  20255. return {
  20256. create: function FontRendererFactory_create(font) {
  20257. var data = new Uint8Array(font.data);
  20258. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20259. var numTables = getUshort(data, 4);
  20260. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20261. var tag = bytesToString(data.subarray(p, p + 4));
  20262. var offset = getLong(data, p + 8);
  20263. var length = getLong(data, p + 12);
  20264. switch (tag) {
  20265. case 'cmap':
  20266. cmap = parseCmap(data, offset, offset + length);
  20267. break;
  20268. case 'glyf':
  20269. glyf = data.subarray(offset, offset + length);
  20270. break;
  20271. case 'loca':
  20272. loca = data.subarray(offset, offset + length);
  20273. break;
  20274. case 'head':
  20275. unitsPerEm = getUshort(data, offset + 18);
  20276. indexToLocFormat = getUshort(data, offset + 50);
  20277. break;
  20278. case 'CFF ':
  20279. cff = parseCff(data, offset, offset + length);
  20280. break;
  20281. }
  20282. }
  20283. if (glyf) {
  20284. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20285. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20286. return new TrueTypeCompiled(
  20287. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20288. } else {
  20289. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20290. }
  20291. }
  20292. };
  20293. })();
  20294. var GlyphsUnicode = {
  20295. A: 0x0041,
  20296. AE: 0x00C6,
  20297. AEacute: 0x01FC,
  20298. AEmacron: 0x01E2,
  20299. AEsmall: 0xF7E6,
  20300. Aacute: 0x00C1,
  20301. Aacutesmall: 0xF7E1,
  20302. Abreve: 0x0102,
  20303. Abreveacute: 0x1EAE,
  20304. Abrevecyrillic: 0x04D0,
  20305. Abrevedotbelow: 0x1EB6,
  20306. Abrevegrave: 0x1EB0,
  20307. Abrevehookabove: 0x1EB2,
  20308. Abrevetilde: 0x1EB4,
  20309. Acaron: 0x01CD,
  20310. Acircle: 0x24B6,
  20311. Acircumflex: 0x00C2,
  20312. Acircumflexacute: 0x1EA4,
  20313. Acircumflexdotbelow: 0x1EAC,
  20314. Acircumflexgrave: 0x1EA6,
  20315. Acircumflexhookabove: 0x1EA8,
  20316. Acircumflexsmall: 0xF7E2,
  20317. Acircumflextilde: 0x1EAA,
  20318. Acute: 0xF6C9,
  20319. Acutesmall: 0xF7B4,
  20320. Acyrillic: 0x0410,
  20321. Adblgrave: 0x0200,
  20322. Adieresis: 0x00C4,
  20323. Adieresiscyrillic: 0x04D2,
  20324. Adieresismacron: 0x01DE,
  20325. Adieresissmall: 0xF7E4,
  20326. Adotbelow: 0x1EA0,
  20327. Adotmacron: 0x01E0,
  20328. Agrave: 0x00C0,
  20329. Agravesmall: 0xF7E0,
  20330. Ahookabove: 0x1EA2,
  20331. Aiecyrillic: 0x04D4,
  20332. Ainvertedbreve: 0x0202,
  20333. Alpha: 0x0391,
  20334. Alphatonos: 0x0386,
  20335. Amacron: 0x0100,
  20336. Amonospace: 0xFF21,
  20337. Aogonek: 0x0104,
  20338. Aring: 0x00C5,
  20339. Aringacute: 0x01FA,
  20340. Aringbelow: 0x1E00,
  20341. Aringsmall: 0xF7E5,
  20342. Asmall: 0xF761,
  20343. Atilde: 0x00C3,
  20344. Atildesmall: 0xF7E3,
  20345. Aybarmenian: 0x0531,
  20346. B: 0x0042,
  20347. Bcircle: 0x24B7,
  20348. Bdotaccent: 0x1E02,
  20349. Bdotbelow: 0x1E04,
  20350. Becyrillic: 0x0411,
  20351. Benarmenian: 0x0532,
  20352. Beta: 0x0392,
  20353. Bhook: 0x0181,
  20354. Blinebelow: 0x1E06,
  20355. Bmonospace: 0xFF22,
  20356. Brevesmall: 0xF6F4,
  20357. Bsmall: 0xF762,
  20358. Btopbar: 0x0182,
  20359. C: 0x0043,
  20360. Caarmenian: 0x053E,
  20361. Cacute: 0x0106,
  20362. Caron: 0xF6CA,
  20363. Caronsmall: 0xF6F5,
  20364. Ccaron: 0x010C,
  20365. Ccedilla: 0x00C7,
  20366. Ccedillaacute: 0x1E08,
  20367. Ccedillasmall: 0xF7E7,
  20368. Ccircle: 0x24B8,
  20369. Ccircumflex: 0x0108,
  20370. Cdot: 0x010A,
  20371. Cdotaccent: 0x010A,
  20372. Cedillasmall: 0xF7B8,
  20373. Chaarmenian: 0x0549,
  20374. Cheabkhasiancyrillic: 0x04BC,
  20375. Checyrillic: 0x0427,
  20376. Chedescenderabkhasiancyrillic: 0x04BE,
  20377. Chedescendercyrillic: 0x04B6,
  20378. Chedieresiscyrillic: 0x04F4,
  20379. Cheharmenian: 0x0543,
  20380. Chekhakassiancyrillic: 0x04CB,
  20381. Cheverticalstrokecyrillic: 0x04B8,
  20382. Chi: 0x03A7,
  20383. Chook: 0x0187,
  20384. Circumflexsmall: 0xF6F6,
  20385. Cmonospace: 0xFF23,
  20386. Coarmenian: 0x0551,
  20387. Csmall: 0xF763,
  20388. D: 0x0044,
  20389. DZ: 0x01F1,
  20390. DZcaron: 0x01C4,
  20391. Daarmenian: 0x0534,
  20392. Dafrican: 0x0189,
  20393. Dcaron: 0x010E,
  20394. Dcedilla: 0x1E10,
  20395. Dcircle: 0x24B9,
  20396. Dcircumflexbelow: 0x1E12,
  20397. Dcroat: 0x0110,
  20398. Ddotaccent: 0x1E0A,
  20399. Ddotbelow: 0x1E0C,
  20400. Decyrillic: 0x0414,
  20401. Deicoptic: 0x03EE,
  20402. Delta: 0x2206,
  20403. Deltagreek: 0x0394,
  20404. Dhook: 0x018A,
  20405. Dieresis: 0xF6CB,
  20406. DieresisAcute: 0xF6CC,
  20407. DieresisGrave: 0xF6CD,
  20408. Dieresissmall: 0xF7A8,
  20409. Digammagreek: 0x03DC,
  20410. Djecyrillic: 0x0402,
  20411. Dlinebelow: 0x1E0E,
  20412. Dmonospace: 0xFF24,
  20413. Dotaccentsmall: 0xF6F7,
  20414. Dslash: 0x0110,
  20415. Dsmall: 0xF764,
  20416. Dtopbar: 0x018B,
  20417. Dz: 0x01F2,
  20418. Dzcaron: 0x01C5,
  20419. Dzeabkhasiancyrillic: 0x04E0,
  20420. Dzecyrillic: 0x0405,
  20421. Dzhecyrillic: 0x040F,
  20422. E: 0x0045,
  20423. Eacute: 0x00C9,
  20424. Eacutesmall: 0xF7E9,
  20425. Ebreve: 0x0114,
  20426. Ecaron: 0x011A,
  20427. Ecedillabreve: 0x1E1C,
  20428. Echarmenian: 0x0535,
  20429. Ecircle: 0x24BA,
  20430. Ecircumflex: 0x00CA,
  20431. Ecircumflexacute: 0x1EBE,
  20432. Ecircumflexbelow: 0x1E18,
  20433. Ecircumflexdotbelow: 0x1EC6,
  20434. Ecircumflexgrave: 0x1EC0,
  20435. Ecircumflexhookabove: 0x1EC2,
  20436. Ecircumflexsmall: 0xF7EA,
  20437. Ecircumflextilde: 0x1EC4,
  20438. Ecyrillic: 0x0404,
  20439. Edblgrave: 0x0204,
  20440. Edieresis: 0x00CB,
  20441. Edieresissmall: 0xF7EB,
  20442. Edot: 0x0116,
  20443. Edotaccent: 0x0116,
  20444. Edotbelow: 0x1EB8,
  20445. Efcyrillic: 0x0424,
  20446. Egrave: 0x00C8,
  20447. Egravesmall: 0xF7E8,
  20448. Eharmenian: 0x0537,
  20449. Ehookabove: 0x1EBA,
  20450. Eightroman: 0x2167,
  20451. Einvertedbreve: 0x0206,
  20452. Eiotifiedcyrillic: 0x0464,
  20453. Elcyrillic: 0x041B,
  20454. Elevenroman: 0x216A,
  20455. Emacron: 0x0112,
  20456. Emacronacute: 0x1E16,
  20457. Emacrongrave: 0x1E14,
  20458. Emcyrillic: 0x041C,
  20459. Emonospace: 0xFF25,
  20460. Encyrillic: 0x041D,
  20461. Endescendercyrillic: 0x04A2,
  20462. Eng: 0x014A,
  20463. Enghecyrillic: 0x04A4,
  20464. Enhookcyrillic: 0x04C7,
  20465. Eogonek: 0x0118,
  20466. Eopen: 0x0190,
  20467. Epsilon: 0x0395,
  20468. Epsilontonos: 0x0388,
  20469. Ercyrillic: 0x0420,
  20470. Ereversed: 0x018E,
  20471. Ereversedcyrillic: 0x042D,
  20472. Escyrillic: 0x0421,
  20473. Esdescendercyrillic: 0x04AA,
  20474. Esh: 0x01A9,
  20475. Esmall: 0xF765,
  20476. Eta: 0x0397,
  20477. Etarmenian: 0x0538,
  20478. Etatonos: 0x0389,
  20479. Eth: 0x00D0,
  20480. Ethsmall: 0xF7F0,
  20481. Etilde: 0x1EBC,
  20482. Etildebelow: 0x1E1A,
  20483. Euro: 0x20AC,
  20484. Ezh: 0x01B7,
  20485. Ezhcaron: 0x01EE,
  20486. Ezhreversed: 0x01B8,
  20487. F: 0x0046,
  20488. Fcircle: 0x24BB,
  20489. Fdotaccent: 0x1E1E,
  20490. Feharmenian: 0x0556,
  20491. Feicoptic: 0x03E4,
  20492. Fhook: 0x0191,
  20493. Fitacyrillic: 0x0472,
  20494. Fiveroman: 0x2164,
  20495. Fmonospace: 0xFF26,
  20496. Fourroman: 0x2163,
  20497. Fsmall: 0xF766,
  20498. G: 0x0047,
  20499. GBsquare: 0x3387,
  20500. Gacute: 0x01F4,
  20501. Gamma: 0x0393,
  20502. Gammaafrican: 0x0194,
  20503. Gangiacoptic: 0x03EA,
  20504. Gbreve: 0x011E,
  20505. Gcaron: 0x01E6,
  20506. Gcedilla: 0x0122,
  20507. Gcircle: 0x24BC,
  20508. Gcircumflex: 0x011C,
  20509. Gcommaaccent: 0x0122,
  20510. Gdot: 0x0120,
  20511. Gdotaccent: 0x0120,
  20512. Gecyrillic: 0x0413,
  20513. Ghadarmenian: 0x0542,
  20514. Ghemiddlehookcyrillic: 0x0494,
  20515. Ghestrokecyrillic: 0x0492,
  20516. Gheupturncyrillic: 0x0490,
  20517. Ghook: 0x0193,
  20518. Gimarmenian: 0x0533,
  20519. Gjecyrillic: 0x0403,
  20520. Gmacron: 0x1E20,
  20521. Gmonospace: 0xFF27,
  20522. Grave: 0xF6CE,
  20523. Gravesmall: 0xF760,
  20524. Gsmall: 0xF767,
  20525. Gsmallhook: 0x029B,
  20526. Gstroke: 0x01E4,
  20527. H: 0x0048,
  20528. H18533: 0x25CF,
  20529. H18543: 0x25AA,
  20530. H18551: 0x25AB,
  20531. H22073: 0x25A1,
  20532. HPsquare: 0x33CB,
  20533. Haabkhasiancyrillic: 0x04A8,
  20534. Hadescendercyrillic: 0x04B2,
  20535. Hardsigncyrillic: 0x042A,
  20536. Hbar: 0x0126,
  20537. Hbrevebelow: 0x1E2A,
  20538. Hcedilla: 0x1E28,
  20539. Hcircle: 0x24BD,
  20540. Hcircumflex: 0x0124,
  20541. Hdieresis: 0x1E26,
  20542. Hdotaccent: 0x1E22,
  20543. Hdotbelow: 0x1E24,
  20544. Hmonospace: 0xFF28,
  20545. Hoarmenian: 0x0540,
  20546. Horicoptic: 0x03E8,
  20547. Hsmall: 0xF768,
  20548. Hungarumlaut: 0xF6CF,
  20549. Hungarumlautsmall: 0xF6F8,
  20550. Hzsquare: 0x3390,
  20551. I: 0x0049,
  20552. IAcyrillic: 0x042F,
  20553. IJ: 0x0132,
  20554. IUcyrillic: 0x042E,
  20555. Iacute: 0x00CD,
  20556. Iacutesmall: 0xF7ED,
  20557. Ibreve: 0x012C,
  20558. Icaron: 0x01CF,
  20559. Icircle: 0x24BE,
  20560. Icircumflex: 0x00CE,
  20561. Icircumflexsmall: 0xF7EE,
  20562. Icyrillic: 0x0406,
  20563. Idblgrave: 0x0208,
  20564. Idieresis: 0x00CF,
  20565. Idieresisacute: 0x1E2E,
  20566. Idieresiscyrillic: 0x04E4,
  20567. Idieresissmall: 0xF7EF,
  20568. Idot: 0x0130,
  20569. Idotaccent: 0x0130,
  20570. Idotbelow: 0x1ECA,
  20571. Iebrevecyrillic: 0x04D6,
  20572. Iecyrillic: 0x0415,
  20573. Ifraktur: 0x2111,
  20574. Igrave: 0x00CC,
  20575. Igravesmall: 0xF7EC,
  20576. Ihookabove: 0x1EC8,
  20577. Iicyrillic: 0x0418,
  20578. Iinvertedbreve: 0x020A,
  20579. Iishortcyrillic: 0x0419,
  20580. Imacron: 0x012A,
  20581. Imacroncyrillic: 0x04E2,
  20582. Imonospace: 0xFF29,
  20583. Iniarmenian: 0x053B,
  20584. Iocyrillic: 0x0401,
  20585. Iogonek: 0x012E,
  20586. Iota: 0x0399,
  20587. Iotaafrican: 0x0196,
  20588. Iotadieresis: 0x03AA,
  20589. Iotatonos: 0x038A,
  20590. Ismall: 0xF769,
  20591. Istroke: 0x0197,
  20592. Itilde: 0x0128,
  20593. Itildebelow: 0x1E2C,
  20594. Izhitsacyrillic: 0x0474,
  20595. Izhitsadblgravecyrillic: 0x0476,
  20596. J: 0x004A,
  20597. Jaarmenian: 0x0541,
  20598. Jcircle: 0x24BF,
  20599. Jcircumflex: 0x0134,
  20600. Jecyrillic: 0x0408,
  20601. Jheharmenian: 0x054B,
  20602. Jmonospace: 0xFF2A,
  20603. Jsmall: 0xF76A,
  20604. K: 0x004B,
  20605. KBsquare: 0x3385,
  20606. KKsquare: 0x33CD,
  20607. Kabashkircyrillic: 0x04A0,
  20608. Kacute: 0x1E30,
  20609. Kacyrillic: 0x041A,
  20610. Kadescendercyrillic: 0x049A,
  20611. Kahookcyrillic: 0x04C3,
  20612. Kappa: 0x039A,
  20613. Kastrokecyrillic: 0x049E,
  20614. Kaverticalstrokecyrillic: 0x049C,
  20615. Kcaron: 0x01E8,
  20616. Kcedilla: 0x0136,
  20617. Kcircle: 0x24C0,
  20618. Kcommaaccent: 0x0136,
  20619. Kdotbelow: 0x1E32,
  20620. Keharmenian: 0x0554,
  20621. Kenarmenian: 0x053F,
  20622. Khacyrillic: 0x0425,
  20623. Kheicoptic: 0x03E6,
  20624. Khook: 0x0198,
  20625. Kjecyrillic: 0x040C,
  20626. Klinebelow: 0x1E34,
  20627. Kmonospace: 0xFF2B,
  20628. Koppacyrillic: 0x0480,
  20629. Koppagreek: 0x03DE,
  20630. Ksicyrillic: 0x046E,
  20631. Ksmall: 0xF76B,
  20632. L: 0x004C,
  20633. LJ: 0x01C7,
  20634. LL: 0xF6BF,
  20635. Lacute: 0x0139,
  20636. Lambda: 0x039B,
  20637. Lcaron: 0x013D,
  20638. Lcedilla: 0x013B,
  20639. Lcircle: 0x24C1,
  20640. Lcircumflexbelow: 0x1E3C,
  20641. Lcommaaccent: 0x013B,
  20642. Ldot: 0x013F,
  20643. Ldotaccent: 0x013F,
  20644. Ldotbelow: 0x1E36,
  20645. Ldotbelowmacron: 0x1E38,
  20646. Liwnarmenian: 0x053C,
  20647. Lj: 0x01C8,
  20648. Ljecyrillic: 0x0409,
  20649. Llinebelow: 0x1E3A,
  20650. Lmonospace: 0xFF2C,
  20651. Lslash: 0x0141,
  20652. Lslashsmall: 0xF6F9,
  20653. Lsmall: 0xF76C,
  20654. M: 0x004D,
  20655. MBsquare: 0x3386,
  20656. Macron: 0xF6D0,
  20657. Macronsmall: 0xF7AF,
  20658. Macute: 0x1E3E,
  20659. Mcircle: 0x24C2,
  20660. Mdotaccent: 0x1E40,
  20661. Mdotbelow: 0x1E42,
  20662. Menarmenian: 0x0544,
  20663. Mmonospace: 0xFF2D,
  20664. Msmall: 0xF76D,
  20665. Mturned: 0x019C,
  20666. Mu: 0x039C,
  20667. N: 0x004E,
  20668. NJ: 0x01CA,
  20669. Nacute: 0x0143,
  20670. Ncaron: 0x0147,
  20671. Ncedilla: 0x0145,
  20672. Ncircle: 0x24C3,
  20673. Ncircumflexbelow: 0x1E4A,
  20674. Ncommaaccent: 0x0145,
  20675. Ndotaccent: 0x1E44,
  20676. Ndotbelow: 0x1E46,
  20677. Nhookleft: 0x019D,
  20678. Nineroman: 0x2168,
  20679. Nj: 0x01CB,
  20680. Njecyrillic: 0x040A,
  20681. Nlinebelow: 0x1E48,
  20682. Nmonospace: 0xFF2E,
  20683. Nowarmenian: 0x0546,
  20684. Nsmall: 0xF76E,
  20685. Ntilde: 0x00D1,
  20686. Ntildesmall: 0xF7F1,
  20687. Nu: 0x039D,
  20688. O: 0x004F,
  20689. OE: 0x0152,
  20690. OEsmall: 0xF6FA,
  20691. Oacute: 0x00D3,
  20692. Oacutesmall: 0xF7F3,
  20693. Obarredcyrillic: 0x04E8,
  20694. Obarreddieresiscyrillic: 0x04EA,
  20695. Obreve: 0x014E,
  20696. Ocaron: 0x01D1,
  20697. Ocenteredtilde: 0x019F,
  20698. Ocircle: 0x24C4,
  20699. Ocircumflex: 0x00D4,
  20700. Ocircumflexacute: 0x1ED0,
  20701. Ocircumflexdotbelow: 0x1ED8,
  20702. Ocircumflexgrave: 0x1ED2,
  20703. Ocircumflexhookabove: 0x1ED4,
  20704. Ocircumflexsmall: 0xF7F4,
  20705. Ocircumflextilde: 0x1ED6,
  20706. Ocyrillic: 0x041E,
  20707. Odblacute: 0x0150,
  20708. Odblgrave: 0x020C,
  20709. Odieresis: 0x00D6,
  20710. Odieresiscyrillic: 0x04E6,
  20711. Odieresissmall: 0xF7F6,
  20712. Odotbelow: 0x1ECC,
  20713. Ogoneksmall: 0xF6FB,
  20714. Ograve: 0x00D2,
  20715. Ogravesmall: 0xF7F2,
  20716. Oharmenian: 0x0555,
  20717. Ohm: 0x2126,
  20718. Ohookabove: 0x1ECE,
  20719. Ohorn: 0x01A0,
  20720. Ohornacute: 0x1EDA,
  20721. Ohorndotbelow: 0x1EE2,
  20722. Ohorngrave: 0x1EDC,
  20723. Ohornhookabove: 0x1EDE,
  20724. Ohorntilde: 0x1EE0,
  20725. Ohungarumlaut: 0x0150,
  20726. Oi: 0x01A2,
  20727. Oinvertedbreve: 0x020E,
  20728. Omacron: 0x014C,
  20729. Omacronacute: 0x1E52,
  20730. Omacrongrave: 0x1E50,
  20731. Omega: 0x2126,
  20732. Omegacyrillic: 0x0460,
  20733. Omegagreek: 0x03A9,
  20734. Omegaroundcyrillic: 0x047A,
  20735. Omegatitlocyrillic: 0x047C,
  20736. Omegatonos: 0x038F,
  20737. Omicron: 0x039F,
  20738. Omicrontonos: 0x038C,
  20739. Omonospace: 0xFF2F,
  20740. Oneroman: 0x2160,
  20741. Oogonek: 0x01EA,
  20742. Oogonekmacron: 0x01EC,
  20743. Oopen: 0x0186,
  20744. Oslash: 0x00D8,
  20745. Oslashacute: 0x01FE,
  20746. Oslashsmall: 0xF7F8,
  20747. Osmall: 0xF76F,
  20748. Ostrokeacute: 0x01FE,
  20749. Otcyrillic: 0x047E,
  20750. Otilde: 0x00D5,
  20751. Otildeacute: 0x1E4C,
  20752. Otildedieresis: 0x1E4E,
  20753. Otildesmall: 0xF7F5,
  20754. P: 0x0050,
  20755. Pacute: 0x1E54,
  20756. Pcircle: 0x24C5,
  20757. Pdotaccent: 0x1E56,
  20758. Pecyrillic: 0x041F,
  20759. Peharmenian: 0x054A,
  20760. Pemiddlehookcyrillic: 0x04A6,
  20761. Phi: 0x03A6,
  20762. Phook: 0x01A4,
  20763. Pi: 0x03A0,
  20764. Piwrarmenian: 0x0553,
  20765. Pmonospace: 0xFF30,
  20766. Psi: 0x03A8,
  20767. Psicyrillic: 0x0470,
  20768. Psmall: 0xF770,
  20769. Q: 0x0051,
  20770. Qcircle: 0x24C6,
  20771. Qmonospace: 0xFF31,
  20772. Qsmall: 0xF771,
  20773. R: 0x0052,
  20774. Raarmenian: 0x054C,
  20775. Racute: 0x0154,
  20776. Rcaron: 0x0158,
  20777. Rcedilla: 0x0156,
  20778. Rcircle: 0x24C7,
  20779. Rcommaaccent: 0x0156,
  20780. Rdblgrave: 0x0210,
  20781. Rdotaccent: 0x1E58,
  20782. Rdotbelow: 0x1E5A,
  20783. Rdotbelowmacron: 0x1E5C,
  20784. Reharmenian: 0x0550,
  20785. Rfraktur: 0x211C,
  20786. Rho: 0x03A1,
  20787. Ringsmall: 0xF6FC,
  20788. Rinvertedbreve: 0x0212,
  20789. Rlinebelow: 0x1E5E,
  20790. Rmonospace: 0xFF32,
  20791. Rsmall: 0xF772,
  20792. Rsmallinverted: 0x0281,
  20793. Rsmallinvertedsuperior: 0x02B6,
  20794. S: 0x0053,
  20795. SF010000: 0x250C,
  20796. SF020000: 0x2514,
  20797. SF030000: 0x2510,
  20798. SF040000: 0x2518,
  20799. SF050000: 0x253C,
  20800. SF060000: 0x252C,
  20801. SF070000: 0x2534,
  20802. SF080000: 0x251C,
  20803. SF090000: 0x2524,
  20804. SF100000: 0x2500,
  20805. SF110000: 0x2502,
  20806. SF190000: 0x2561,
  20807. SF200000: 0x2562,
  20808. SF210000: 0x2556,
  20809. SF220000: 0x2555,
  20810. SF230000: 0x2563,
  20811. SF240000: 0x2551,
  20812. SF250000: 0x2557,
  20813. SF260000: 0x255D,
  20814. SF270000: 0x255C,
  20815. SF280000: 0x255B,
  20816. SF360000: 0x255E,
  20817. SF370000: 0x255F,
  20818. SF380000: 0x255A,
  20819. SF390000: 0x2554,
  20820. SF400000: 0x2569,
  20821. SF410000: 0x2566,
  20822. SF420000: 0x2560,
  20823. SF430000: 0x2550,
  20824. SF440000: 0x256C,
  20825. SF450000: 0x2567,
  20826. SF460000: 0x2568,
  20827. SF470000: 0x2564,
  20828. SF480000: 0x2565,
  20829. SF490000: 0x2559,
  20830. SF500000: 0x2558,
  20831. SF510000: 0x2552,
  20832. SF520000: 0x2553,
  20833. SF530000: 0x256B,
  20834. SF540000: 0x256A,
  20835. Sacute: 0x015A,
  20836. Sacutedotaccent: 0x1E64,
  20837. Sampigreek: 0x03E0,
  20838. Scaron: 0x0160,
  20839. Scarondotaccent: 0x1E66,
  20840. Scaronsmall: 0xF6FD,
  20841. Scedilla: 0x015E,
  20842. Schwa: 0x018F,
  20843. Schwacyrillic: 0x04D8,
  20844. Schwadieresiscyrillic: 0x04DA,
  20845. Scircle: 0x24C8,
  20846. Scircumflex: 0x015C,
  20847. Scommaaccent: 0x0218,
  20848. Sdotaccent: 0x1E60,
  20849. Sdotbelow: 0x1E62,
  20850. Sdotbelowdotaccent: 0x1E68,
  20851. Seharmenian: 0x054D,
  20852. Sevenroman: 0x2166,
  20853. Shaarmenian: 0x0547,
  20854. Shacyrillic: 0x0428,
  20855. Shchacyrillic: 0x0429,
  20856. Sheicoptic: 0x03E2,
  20857. Shhacyrillic: 0x04BA,
  20858. Shimacoptic: 0x03EC,
  20859. Sigma: 0x03A3,
  20860. Sixroman: 0x2165,
  20861. Smonospace: 0xFF33,
  20862. Softsigncyrillic: 0x042C,
  20863. Ssmall: 0xF773,
  20864. Stigmagreek: 0x03DA,
  20865. T: 0x0054,
  20866. Tau: 0x03A4,
  20867. Tbar: 0x0166,
  20868. Tcaron: 0x0164,
  20869. Tcedilla: 0x0162,
  20870. Tcircle: 0x24C9,
  20871. Tcircumflexbelow: 0x1E70,
  20872. Tcommaaccent: 0x0162,
  20873. Tdotaccent: 0x1E6A,
  20874. Tdotbelow: 0x1E6C,
  20875. Tecyrillic: 0x0422,
  20876. Tedescendercyrillic: 0x04AC,
  20877. Tenroman: 0x2169,
  20878. Tetsecyrillic: 0x04B4,
  20879. Theta: 0x0398,
  20880. Thook: 0x01AC,
  20881. Thorn: 0x00DE,
  20882. Thornsmall: 0xF7FE,
  20883. Threeroman: 0x2162,
  20884. Tildesmall: 0xF6FE,
  20885. Tiwnarmenian: 0x054F,
  20886. Tlinebelow: 0x1E6E,
  20887. Tmonospace: 0xFF34,
  20888. Toarmenian: 0x0539,
  20889. Tonefive: 0x01BC,
  20890. Tonesix: 0x0184,
  20891. Tonetwo: 0x01A7,
  20892. Tretroflexhook: 0x01AE,
  20893. Tsecyrillic: 0x0426,
  20894. Tshecyrillic: 0x040B,
  20895. Tsmall: 0xF774,
  20896. Twelveroman: 0x216B,
  20897. Tworoman: 0x2161,
  20898. U: 0x0055,
  20899. Uacute: 0x00DA,
  20900. Uacutesmall: 0xF7FA,
  20901. Ubreve: 0x016C,
  20902. Ucaron: 0x01D3,
  20903. Ucircle: 0x24CA,
  20904. Ucircumflex: 0x00DB,
  20905. Ucircumflexbelow: 0x1E76,
  20906. Ucircumflexsmall: 0xF7FB,
  20907. Ucyrillic: 0x0423,
  20908. Udblacute: 0x0170,
  20909. Udblgrave: 0x0214,
  20910. Udieresis: 0x00DC,
  20911. Udieresisacute: 0x01D7,
  20912. Udieresisbelow: 0x1E72,
  20913. Udieresiscaron: 0x01D9,
  20914. Udieresiscyrillic: 0x04F0,
  20915. Udieresisgrave: 0x01DB,
  20916. Udieresismacron: 0x01D5,
  20917. Udieresissmall: 0xF7FC,
  20918. Udotbelow: 0x1EE4,
  20919. Ugrave: 0x00D9,
  20920. Ugravesmall: 0xF7F9,
  20921. Uhookabove: 0x1EE6,
  20922. Uhorn: 0x01AF,
  20923. Uhornacute: 0x1EE8,
  20924. Uhorndotbelow: 0x1EF0,
  20925. Uhorngrave: 0x1EEA,
  20926. Uhornhookabove: 0x1EEC,
  20927. Uhorntilde: 0x1EEE,
  20928. Uhungarumlaut: 0x0170,
  20929. Uhungarumlautcyrillic: 0x04F2,
  20930. Uinvertedbreve: 0x0216,
  20931. Ukcyrillic: 0x0478,
  20932. Umacron: 0x016A,
  20933. Umacroncyrillic: 0x04EE,
  20934. Umacrondieresis: 0x1E7A,
  20935. Umonospace: 0xFF35,
  20936. Uogonek: 0x0172,
  20937. Upsilon: 0x03A5,
  20938. Upsilon1: 0x03D2,
  20939. Upsilonacutehooksymbolgreek: 0x03D3,
  20940. Upsilonafrican: 0x01B1,
  20941. Upsilondieresis: 0x03AB,
  20942. Upsilondieresishooksymbolgreek: 0x03D4,
  20943. Upsilonhooksymbol: 0x03D2,
  20944. Upsilontonos: 0x038E,
  20945. Uring: 0x016E,
  20946. Ushortcyrillic: 0x040E,
  20947. Usmall: 0xF775,
  20948. Ustraightcyrillic: 0x04AE,
  20949. Ustraightstrokecyrillic: 0x04B0,
  20950. Utilde: 0x0168,
  20951. Utildeacute: 0x1E78,
  20952. Utildebelow: 0x1E74,
  20953. V: 0x0056,
  20954. Vcircle: 0x24CB,
  20955. Vdotbelow: 0x1E7E,
  20956. Vecyrillic: 0x0412,
  20957. Vewarmenian: 0x054E,
  20958. Vhook: 0x01B2,
  20959. Vmonospace: 0xFF36,
  20960. Voarmenian: 0x0548,
  20961. Vsmall: 0xF776,
  20962. Vtilde: 0x1E7C,
  20963. W: 0x0057,
  20964. Wacute: 0x1E82,
  20965. Wcircle: 0x24CC,
  20966. Wcircumflex: 0x0174,
  20967. Wdieresis: 0x1E84,
  20968. Wdotaccent: 0x1E86,
  20969. Wdotbelow: 0x1E88,
  20970. Wgrave: 0x1E80,
  20971. Wmonospace: 0xFF37,
  20972. Wsmall: 0xF777,
  20973. X: 0x0058,
  20974. Xcircle: 0x24CD,
  20975. Xdieresis: 0x1E8C,
  20976. Xdotaccent: 0x1E8A,
  20977. Xeharmenian: 0x053D,
  20978. Xi: 0x039E,
  20979. Xmonospace: 0xFF38,
  20980. Xsmall: 0xF778,
  20981. Y: 0x0059,
  20982. Yacute: 0x00DD,
  20983. Yacutesmall: 0xF7FD,
  20984. Yatcyrillic: 0x0462,
  20985. Ycircle: 0x24CE,
  20986. Ycircumflex: 0x0176,
  20987. Ydieresis: 0x0178,
  20988. Ydieresissmall: 0xF7FF,
  20989. Ydotaccent: 0x1E8E,
  20990. Ydotbelow: 0x1EF4,
  20991. Yericyrillic: 0x042B,
  20992. Yerudieresiscyrillic: 0x04F8,
  20993. Ygrave: 0x1EF2,
  20994. Yhook: 0x01B3,
  20995. Yhookabove: 0x1EF6,
  20996. Yiarmenian: 0x0545,
  20997. Yicyrillic: 0x0407,
  20998. Yiwnarmenian: 0x0552,
  20999. Ymonospace: 0xFF39,
  21000. Ysmall: 0xF779,
  21001. Ytilde: 0x1EF8,
  21002. Yusbigcyrillic: 0x046A,
  21003. Yusbigiotifiedcyrillic: 0x046C,
  21004. Yuslittlecyrillic: 0x0466,
  21005. Yuslittleiotifiedcyrillic: 0x0468,
  21006. Z: 0x005A,
  21007. Zaarmenian: 0x0536,
  21008. Zacute: 0x0179,
  21009. Zcaron: 0x017D,
  21010. Zcaronsmall: 0xF6FF,
  21011. Zcircle: 0x24CF,
  21012. Zcircumflex: 0x1E90,
  21013. Zdot: 0x017B,
  21014. Zdotaccent: 0x017B,
  21015. Zdotbelow: 0x1E92,
  21016. Zecyrillic: 0x0417,
  21017. Zedescendercyrillic: 0x0498,
  21018. Zedieresiscyrillic: 0x04DE,
  21019. Zeta: 0x0396,
  21020. Zhearmenian: 0x053A,
  21021. Zhebrevecyrillic: 0x04C1,
  21022. Zhecyrillic: 0x0416,
  21023. Zhedescendercyrillic: 0x0496,
  21024. Zhedieresiscyrillic: 0x04DC,
  21025. Zlinebelow: 0x1E94,
  21026. Zmonospace: 0xFF3A,
  21027. Zsmall: 0xF77A,
  21028. Zstroke: 0x01B5,
  21029. a: 0x0061,
  21030. aabengali: 0x0986,
  21031. aacute: 0x00E1,
  21032. aadeva: 0x0906,
  21033. aagujarati: 0x0A86,
  21034. aagurmukhi: 0x0A06,
  21035. aamatragurmukhi: 0x0A3E,
  21036. aarusquare: 0x3303,
  21037. aavowelsignbengali: 0x09BE,
  21038. aavowelsigndeva: 0x093E,
  21039. aavowelsigngujarati: 0x0ABE,
  21040. abbreviationmarkarmenian: 0x055F,
  21041. abbreviationsigndeva: 0x0970,
  21042. abengali: 0x0985,
  21043. abopomofo: 0x311A,
  21044. abreve: 0x0103,
  21045. abreveacute: 0x1EAF,
  21046. abrevecyrillic: 0x04D1,
  21047. abrevedotbelow: 0x1EB7,
  21048. abrevegrave: 0x1EB1,
  21049. abrevehookabove: 0x1EB3,
  21050. abrevetilde: 0x1EB5,
  21051. acaron: 0x01CE,
  21052. acircle: 0x24D0,
  21053. acircumflex: 0x00E2,
  21054. acircumflexacute: 0x1EA5,
  21055. acircumflexdotbelow: 0x1EAD,
  21056. acircumflexgrave: 0x1EA7,
  21057. acircumflexhookabove: 0x1EA9,
  21058. acircumflextilde: 0x1EAB,
  21059. acute: 0x00B4,
  21060. acutebelowcmb: 0x0317,
  21061. acutecmb: 0x0301,
  21062. acutecomb: 0x0301,
  21063. acutedeva: 0x0954,
  21064. acutelowmod: 0x02CF,
  21065. acutetonecmb: 0x0341,
  21066. acyrillic: 0x0430,
  21067. adblgrave: 0x0201,
  21068. addakgurmukhi: 0x0A71,
  21069. adeva: 0x0905,
  21070. adieresis: 0x00E4,
  21071. adieresiscyrillic: 0x04D3,
  21072. adieresismacron: 0x01DF,
  21073. adotbelow: 0x1EA1,
  21074. adotmacron: 0x01E1,
  21075. ae: 0x00E6,
  21076. aeacute: 0x01FD,
  21077. aekorean: 0x3150,
  21078. aemacron: 0x01E3,
  21079. afii00208: 0x2015,
  21080. afii08941: 0x20A4,
  21081. afii10017: 0x0410,
  21082. afii10018: 0x0411,
  21083. afii10019: 0x0412,
  21084. afii10020: 0x0413,
  21085. afii10021: 0x0414,
  21086. afii10022: 0x0415,
  21087. afii10023: 0x0401,
  21088. afii10024: 0x0416,
  21089. afii10025: 0x0417,
  21090. afii10026: 0x0418,
  21091. afii10027: 0x0419,
  21092. afii10028: 0x041A,
  21093. afii10029: 0x041B,
  21094. afii10030: 0x041C,
  21095. afii10031: 0x041D,
  21096. afii10032: 0x041E,
  21097. afii10033: 0x041F,
  21098. afii10034: 0x0420,
  21099. afii10035: 0x0421,
  21100. afii10036: 0x0422,
  21101. afii10037: 0x0423,
  21102. afii10038: 0x0424,
  21103. afii10039: 0x0425,
  21104. afii10040: 0x0426,
  21105. afii10041: 0x0427,
  21106. afii10042: 0x0428,
  21107. afii10043: 0x0429,
  21108. afii10044: 0x042A,
  21109. afii10045: 0x042B,
  21110. afii10046: 0x042C,
  21111. afii10047: 0x042D,
  21112. afii10048: 0x042E,
  21113. afii10049: 0x042F,
  21114. afii10050: 0x0490,
  21115. afii10051: 0x0402,
  21116. afii10052: 0x0403,
  21117. afii10053: 0x0404,
  21118. afii10054: 0x0405,
  21119. afii10055: 0x0406,
  21120. afii10056: 0x0407,
  21121. afii10057: 0x0408,
  21122. afii10058: 0x0409,
  21123. afii10059: 0x040A,
  21124. afii10060: 0x040B,
  21125. afii10061: 0x040C,
  21126. afii10062: 0x040E,
  21127. afii10063: 0xF6C4,
  21128. afii10064: 0xF6C5,
  21129. afii10065: 0x0430,
  21130. afii10066: 0x0431,
  21131. afii10067: 0x0432,
  21132. afii10068: 0x0433,
  21133. afii10069: 0x0434,
  21134. afii10070: 0x0435,
  21135. afii10071: 0x0451,
  21136. afii10072: 0x0436,
  21137. afii10073: 0x0437,
  21138. afii10074: 0x0438,
  21139. afii10075: 0x0439,
  21140. afii10076: 0x043A,
  21141. afii10077: 0x043B,
  21142. afii10078: 0x043C,
  21143. afii10079: 0x043D,
  21144. afii10080: 0x043E,
  21145. afii10081: 0x043F,
  21146. afii10082: 0x0440,
  21147. afii10083: 0x0441,
  21148. afii10084: 0x0442,
  21149. afii10085: 0x0443,
  21150. afii10086: 0x0444,
  21151. afii10087: 0x0445,
  21152. afii10088: 0x0446,
  21153. afii10089: 0x0447,
  21154. afii10090: 0x0448,
  21155. afii10091: 0x0449,
  21156. afii10092: 0x044A,
  21157. afii10093: 0x044B,
  21158. afii10094: 0x044C,
  21159. afii10095: 0x044D,
  21160. afii10096: 0x044E,
  21161. afii10097: 0x044F,
  21162. afii10098: 0x0491,
  21163. afii10099: 0x0452,
  21164. afii10100: 0x0453,
  21165. afii10101: 0x0454,
  21166. afii10102: 0x0455,
  21167. afii10103: 0x0456,
  21168. afii10104: 0x0457,
  21169. afii10105: 0x0458,
  21170. afii10106: 0x0459,
  21171. afii10107: 0x045A,
  21172. afii10108: 0x045B,
  21173. afii10109: 0x045C,
  21174. afii10110: 0x045E,
  21175. afii10145: 0x040F,
  21176. afii10146: 0x0462,
  21177. afii10147: 0x0472,
  21178. afii10148: 0x0474,
  21179. afii10192: 0xF6C6,
  21180. afii10193: 0x045F,
  21181. afii10194: 0x0463,
  21182. afii10195: 0x0473,
  21183. afii10196: 0x0475,
  21184. afii10831: 0xF6C7,
  21185. afii10832: 0xF6C8,
  21186. afii10846: 0x04D9,
  21187. afii299: 0x200E,
  21188. afii300: 0x200F,
  21189. afii301: 0x200D,
  21190. afii57381: 0x066A,
  21191. afii57388: 0x060C,
  21192. afii57392: 0x0660,
  21193. afii57393: 0x0661,
  21194. afii57394: 0x0662,
  21195. afii57395: 0x0663,
  21196. afii57396: 0x0664,
  21197. afii57397: 0x0665,
  21198. afii57398: 0x0666,
  21199. afii57399: 0x0667,
  21200. afii57400: 0x0668,
  21201. afii57401: 0x0669,
  21202. afii57403: 0x061B,
  21203. afii57407: 0x061F,
  21204. afii57409: 0x0621,
  21205. afii57410: 0x0622,
  21206. afii57411: 0x0623,
  21207. afii57412: 0x0624,
  21208. afii57413: 0x0625,
  21209. afii57414: 0x0626,
  21210. afii57415: 0x0627,
  21211. afii57416: 0x0628,
  21212. afii57417: 0x0629,
  21213. afii57418: 0x062A,
  21214. afii57419: 0x062B,
  21215. afii57420: 0x062C,
  21216. afii57421: 0x062D,
  21217. afii57422: 0x062E,
  21218. afii57423: 0x062F,
  21219. afii57424: 0x0630,
  21220. afii57425: 0x0631,
  21221. afii57426: 0x0632,
  21222. afii57427: 0x0633,
  21223. afii57428: 0x0634,
  21224. afii57429: 0x0635,
  21225. afii57430: 0x0636,
  21226. afii57431: 0x0637,
  21227. afii57432: 0x0638,
  21228. afii57433: 0x0639,
  21229. afii57434: 0x063A,
  21230. afii57440: 0x0640,
  21231. afii57441: 0x0641,
  21232. afii57442: 0x0642,
  21233. afii57443: 0x0643,
  21234. afii57444: 0x0644,
  21235. afii57445: 0x0645,
  21236. afii57446: 0x0646,
  21237. afii57448: 0x0648,
  21238. afii57449: 0x0649,
  21239. afii57450: 0x064A,
  21240. afii57451: 0x064B,
  21241. afii57452: 0x064C,
  21242. afii57453: 0x064D,
  21243. afii57454: 0x064E,
  21244. afii57455: 0x064F,
  21245. afii57456: 0x0650,
  21246. afii57457: 0x0651,
  21247. afii57458: 0x0652,
  21248. afii57470: 0x0647,
  21249. afii57505: 0x06A4,
  21250. afii57506: 0x067E,
  21251. afii57507: 0x0686,
  21252. afii57508: 0x0698,
  21253. afii57509: 0x06AF,
  21254. afii57511: 0x0679,
  21255. afii57512: 0x0688,
  21256. afii57513: 0x0691,
  21257. afii57514: 0x06BA,
  21258. afii57519: 0x06D2,
  21259. afii57534: 0x06D5,
  21260. afii57636: 0x20AA,
  21261. afii57645: 0x05BE,
  21262. afii57658: 0x05C3,
  21263. afii57664: 0x05D0,
  21264. afii57665: 0x05D1,
  21265. afii57666: 0x05D2,
  21266. afii57667: 0x05D3,
  21267. afii57668: 0x05D4,
  21268. afii57669: 0x05D5,
  21269. afii57670: 0x05D6,
  21270. afii57671: 0x05D7,
  21271. afii57672: 0x05D8,
  21272. afii57673: 0x05D9,
  21273. afii57674: 0x05DA,
  21274. afii57675: 0x05DB,
  21275. afii57676: 0x05DC,
  21276. afii57677: 0x05DD,
  21277. afii57678: 0x05DE,
  21278. afii57679: 0x05DF,
  21279. afii57680: 0x05E0,
  21280. afii57681: 0x05E1,
  21281. afii57682: 0x05E2,
  21282. afii57683: 0x05E3,
  21283. afii57684: 0x05E4,
  21284. afii57685: 0x05E5,
  21285. afii57686: 0x05E6,
  21286. afii57687: 0x05E7,
  21287. afii57688: 0x05E8,
  21288. afii57689: 0x05E9,
  21289. afii57690: 0x05EA,
  21290. afii57694: 0xFB2A,
  21291. afii57695: 0xFB2B,
  21292. afii57700: 0xFB4B,
  21293. afii57705: 0xFB1F,
  21294. afii57716: 0x05F0,
  21295. afii57717: 0x05F1,
  21296. afii57718: 0x05F2,
  21297. afii57723: 0xFB35,
  21298. afii57793: 0x05B4,
  21299. afii57794: 0x05B5,
  21300. afii57795: 0x05B6,
  21301. afii57796: 0x05BB,
  21302. afii57797: 0x05B8,
  21303. afii57798: 0x05B7,
  21304. afii57799: 0x05B0,
  21305. afii57800: 0x05B2,
  21306. afii57801: 0x05B1,
  21307. afii57802: 0x05B3,
  21308. afii57803: 0x05C2,
  21309. afii57804: 0x05C1,
  21310. afii57806: 0x05B9,
  21311. afii57807: 0x05BC,
  21312. afii57839: 0x05BD,
  21313. afii57841: 0x05BF,
  21314. afii57842: 0x05C0,
  21315. afii57929: 0x02BC,
  21316. afii61248: 0x2105,
  21317. afii61289: 0x2113,
  21318. afii61352: 0x2116,
  21319. afii61573: 0x202C,
  21320. afii61574: 0x202D,
  21321. afii61575: 0x202E,
  21322. afii61664: 0x200C,
  21323. afii63167: 0x066D,
  21324. afii64937: 0x02BD,
  21325. agrave: 0x00E0,
  21326. agujarati: 0x0A85,
  21327. agurmukhi: 0x0A05,
  21328. ahiragana: 0x3042,
  21329. ahookabove: 0x1EA3,
  21330. aibengali: 0x0990,
  21331. aibopomofo: 0x311E,
  21332. aideva: 0x0910,
  21333. aiecyrillic: 0x04D5,
  21334. aigujarati: 0x0A90,
  21335. aigurmukhi: 0x0A10,
  21336. aimatragurmukhi: 0x0A48,
  21337. ainarabic: 0x0639,
  21338. ainfinalarabic: 0xFECA,
  21339. aininitialarabic: 0xFECB,
  21340. ainmedialarabic: 0xFECC,
  21341. ainvertedbreve: 0x0203,
  21342. aivowelsignbengali: 0x09C8,
  21343. aivowelsigndeva: 0x0948,
  21344. aivowelsigngujarati: 0x0AC8,
  21345. akatakana: 0x30A2,
  21346. akatakanahalfwidth: 0xFF71,
  21347. akorean: 0x314F,
  21348. alef: 0x05D0,
  21349. alefarabic: 0x0627,
  21350. alefdageshhebrew: 0xFB30,
  21351. aleffinalarabic: 0xFE8E,
  21352. alefhamzaabovearabic: 0x0623,
  21353. alefhamzaabovefinalarabic: 0xFE84,
  21354. alefhamzabelowarabic: 0x0625,
  21355. alefhamzabelowfinalarabic: 0xFE88,
  21356. alefhebrew: 0x05D0,
  21357. aleflamedhebrew: 0xFB4F,
  21358. alefmaddaabovearabic: 0x0622,
  21359. alefmaddaabovefinalarabic: 0xFE82,
  21360. alefmaksuraarabic: 0x0649,
  21361. alefmaksurafinalarabic: 0xFEF0,
  21362. alefmaksurainitialarabic: 0xFEF3,
  21363. alefmaksuramedialarabic: 0xFEF4,
  21364. alefpatahhebrew: 0xFB2E,
  21365. alefqamatshebrew: 0xFB2F,
  21366. aleph: 0x2135,
  21367. allequal: 0x224C,
  21368. alpha: 0x03B1,
  21369. alphatonos: 0x03AC,
  21370. amacron: 0x0101,
  21371. amonospace: 0xFF41,
  21372. ampersand: 0x0026,
  21373. ampersandmonospace: 0xFF06,
  21374. ampersandsmall: 0xF726,
  21375. amsquare: 0x33C2,
  21376. anbopomofo: 0x3122,
  21377. angbopomofo: 0x3124,
  21378. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21379. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21380. angkhankhuthai: 0x0E5A,
  21381. angle: 0x2220,
  21382. anglebracketleft: 0x3008,
  21383. anglebracketleftvertical: 0xFE3F,
  21384. anglebracketright: 0x3009,
  21385. anglebracketrightvertical: 0xFE40,
  21386. angleleft: 0x2329,
  21387. angleright: 0x232A,
  21388. angstrom: 0x212B,
  21389. anoteleia: 0x0387,
  21390. anudattadeva: 0x0952,
  21391. anusvarabengali: 0x0982,
  21392. anusvaradeva: 0x0902,
  21393. anusvaragujarati: 0x0A82,
  21394. aogonek: 0x0105,
  21395. apaatosquare: 0x3300,
  21396. aparen: 0x249C,
  21397. apostrophearmenian: 0x055A,
  21398. apostrophemod: 0x02BC,
  21399. apple: 0xF8FF,
  21400. approaches: 0x2250,
  21401. approxequal: 0x2248,
  21402. approxequalorimage: 0x2252,
  21403. approximatelyequal: 0x2245,
  21404. araeaekorean: 0x318E,
  21405. araeakorean: 0x318D,
  21406. arc: 0x2312,
  21407. arighthalfring: 0x1E9A,
  21408. aring: 0x00E5,
  21409. aringacute: 0x01FB,
  21410. aringbelow: 0x1E01,
  21411. arrowboth: 0x2194,
  21412. arrowdashdown: 0x21E3,
  21413. arrowdashleft: 0x21E0,
  21414. arrowdashright: 0x21E2,
  21415. arrowdashup: 0x21E1,
  21416. arrowdblboth: 0x21D4,
  21417. arrowdbldown: 0x21D3,
  21418. arrowdblleft: 0x21D0,
  21419. arrowdblright: 0x21D2,
  21420. arrowdblup: 0x21D1,
  21421. arrowdown: 0x2193,
  21422. arrowdownleft: 0x2199,
  21423. arrowdownright: 0x2198,
  21424. arrowdownwhite: 0x21E9,
  21425. arrowheaddownmod: 0x02C5,
  21426. arrowheadleftmod: 0x02C2,
  21427. arrowheadrightmod: 0x02C3,
  21428. arrowheadupmod: 0x02C4,
  21429. arrowhorizex: 0xF8E7,
  21430. arrowleft: 0x2190,
  21431. arrowleftdbl: 0x21D0,
  21432. arrowleftdblstroke: 0x21CD,
  21433. arrowleftoverright: 0x21C6,
  21434. arrowleftwhite: 0x21E6,
  21435. arrowright: 0x2192,
  21436. arrowrightdblstroke: 0x21CF,
  21437. arrowrightheavy: 0x279E,
  21438. arrowrightoverleft: 0x21C4,
  21439. arrowrightwhite: 0x21E8,
  21440. arrowtableft: 0x21E4,
  21441. arrowtabright: 0x21E5,
  21442. arrowup: 0x2191,
  21443. arrowupdn: 0x2195,
  21444. arrowupdnbse: 0x21A8,
  21445. arrowupdownbase: 0x21A8,
  21446. arrowupleft: 0x2196,
  21447. arrowupleftofdown: 0x21C5,
  21448. arrowupright: 0x2197,
  21449. arrowupwhite: 0x21E7,
  21450. arrowvertex: 0xF8E6,
  21451. asciicircum: 0x005E,
  21452. asciicircummonospace: 0xFF3E,
  21453. asciitilde: 0x007E,
  21454. asciitildemonospace: 0xFF5E,
  21455. ascript: 0x0251,
  21456. ascriptturned: 0x0252,
  21457. asmallhiragana: 0x3041,
  21458. asmallkatakana: 0x30A1,
  21459. asmallkatakanahalfwidth: 0xFF67,
  21460. asterisk: 0x002A,
  21461. asteriskaltonearabic: 0x066D,
  21462. asteriskarabic: 0x066D,
  21463. asteriskmath: 0x2217,
  21464. asteriskmonospace: 0xFF0A,
  21465. asterisksmall: 0xFE61,
  21466. asterism: 0x2042,
  21467. asuperior: 0xF6E9,
  21468. asymptoticallyequal: 0x2243,
  21469. at: 0x0040,
  21470. atilde: 0x00E3,
  21471. atmonospace: 0xFF20,
  21472. atsmall: 0xFE6B,
  21473. aturned: 0x0250,
  21474. aubengali: 0x0994,
  21475. aubopomofo: 0x3120,
  21476. audeva: 0x0914,
  21477. augujarati: 0x0A94,
  21478. augurmukhi: 0x0A14,
  21479. aulengthmarkbengali: 0x09D7,
  21480. aumatragurmukhi: 0x0A4C,
  21481. auvowelsignbengali: 0x09CC,
  21482. auvowelsigndeva: 0x094C,
  21483. auvowelsigngujarati: 0x0ACC,
  21484. avagrahadeva: 0x093D,
  21485. aybarmenian: 0x0561,
  21486. ayin: 0x05E2,
  21487. ayinaltonehebrew: 0xFB20,
  21488. ayinhebrew: 0x05E2,
  21489. b: 0x0062,
  21490. babengali: 0x09AC,
  21491. backslash: 0x005C,
  21492. backslashmonospace: 0xFF3C,
  21493. badeva: 0x092C,
  21494. bagujarati: 0x0AAC,
  21495. bagurmukhi: 0x0A2C,
  21496. bahiragana: 0x3070,
  21497. bahtthai: 0x0E3F,
  21498. bakatakana: 0x30D0,
  21499. bar: 0x007C,
  21500. barmonospace: 0xFF5C,
  21501. bbopomofo: 0x3105,
  21502. bcircle: 0x24D1,
  21503. bdotaccent: 0x1E03,
  21504. bdotbelow: 0x1E05,
  21505. beamedsixteenthnotes: 0x266C,
  21506. because: 0x2235,
  21507. becyrillic: 0x0431,
  21508. beharabic: 0x0628,
  21509. behfinalarabic: 0xFE90,
  21510. behinitialarabic: 0xFE91,
  21511. behiragana: 0x3079,
  21512. behmedialarabic: 0xFE92,
  21513. behmeeminitialarabic: 0xFC9F,
  21514. behmeemisolatedarabic: 0xFC08,
  21515. behnoonfinalarabic: 0xFC6D,
  21516. bekatakana: 0x30D9,
  21517. benarmenian: 0x0562,
  21518. bet: 0x05D1,
  21519. beta: 0x03B2,
  21520. betasymbolgreek: 0x03D0,
  21521. betdagesh: 0xFB31,
  21522. betdageshhebrew: 0xFB31,
  21523. bethebrew: 0x05D1,
  21524. betrafehebrew: 0xFB4C,
  21525. bhabengali: 0x09AD,
  21526. bhadeva: 0x092D,
  21527. bhagujarati: 0x0AAD,
  21528. bhagurmukhi: 0x0A2D,
  21529. bhook: 0x0253,
  21530. bihiragana: 0x3073,
  21531. bikatakana: 0x30D3,
  21532. bilabialclick: 0x0298,
  21533. bindigurmukhi: 0x0A02,
  21534. birusquare: 0x3331,
  21535. blackcircle: 0x25CF,
  21536. blackdiamond: 0x25C6,
  21537. blackdownpointingtriangle: 0x25BC,
  21538. blackleftpointingpointer: 0x25C4,
  21539. blackleftpointingtriangle: 0x25C0,
  21540. blacklenticularbracketleft: 0x3010,
  21541. blacklenticularbracketleftvertical: 0xFE3B,
  21542. blacklenticularbracketright: 0x3011,
  21543. blacklenticularbracketrightvertical: 0xFE3C,
  21544. blacklowerlefttriangle: 0x25E3,
  21545. blacklowerrighttriangle: 0x25E2,
  21546. blackrectangle: 0x25AC,
  21547. blackrightpointingpointer: 0x25BA,
  21548. blackrightpointingtriangle: 0x25B6,
  21549. blacksmallsquare: 0x25AA,
  21550. blacksmilingface: 0x263B,
  21551. blacksquare: 0x25A0,
  21552. blackstar: 0x2605,
  21553. blackupperlefttriangle: 0x25E4,
  21554. blackupperrighttriangle: 0x25E5,
  21555. blackuppointingsmalltriangle: 0x25B4,
  21556. blackuppointingtriangle: 0x25B2,
  21557. blank: 0x2423,
  21558. blinebelow: 0x1E07,
  21559. block: 0x2588,
  21560. bmonospace: 0xFF42,
  21561. bobaimaithai: 0x0E1A,
  21562. bohiragana: 0x307C,
  21563. bokatakana: 0x30DC,
  21564. bparen: 0x249D,
  21565. bqsquare: 0x33C3,
  21566. braceex: 0xF8F4,
  21567. braceleft: 0x007B,
  21568. braceleftbt: 0xF8F3,
  21569. braceleftmid: 0xF8F2,
  21570. braceleftmonospace: 0xFF5B,
  21571. braceleftsmall: 0xFE5B,
  21572. bracelefttp: 0xF8F1,
  21573. braceleftvertical: 0xFE37,
  21574. braceright: 0x007D,
  21575. bracerightbt: 0xF8FE,
  21576. bracerightmid: 0xF8FD,
  21577. bracerightmonospace: 0xFF5D,
  21578. bracerightsmall: 0xFE5C,
  21579. bracerighttp: 0xF8FC,
  21580. bracerightvertical: 0xFE38,
  21581. bracketleft: 0x005B,
  21582. bracketleftbt: 0xF8F0,
  21583. bracketleftex: 0xF8EF,
  21584. bracketleftmonospace: 0xFF3B,
  21585. bracketlefttp: 0xF8EE,
  21586. bracketright: 0x005D,
  21587. bracketrightbt: 0xF8FB,
  21588. bracketrightex: 0xF8FA,
  21589. bracketrightmonospace: 0xFF3D,
  21590. bracketrighttp: 0xF8F9,
  21591. breve: 0x02D8,
  21592. brevebelowcmb: 0x032E,
  21593. brevecmb: 0x0306,
  21594. breveinvertedbelowcmb: 0x032F,
  21595. breveinvertedcmb: 0x0311,
  21596. breveinverteddoublecmb: 0x0361,
  21597. bridgebelowcmb: 0x032A,
  21598. bridgeinvertedbelowcmb: 0x033A,
  21599. brokenbar: 0x00A6,
  21600. bstroke: 0x0180,
  21601. bsuperior: 0xF6EA,
  21602. btopbar: 0x0183,
  21603. buhiragana: 0x3076,
  21604. bukatakana: 0x30D6,
  21605. bullet: 0x2022,
  21606. bulletinverse: 0x25D8,
  21607. bulletoperator: 0x2219,
  21608. bullseye: 0x25CE,
  21609. c: 0x0063,
  21610. caarmenian: 0x056E,
  21611. cabengali: 0x099A,
  21612. cacute: 0x0107,
  21613. cadeva: 0x091A,
  21614. cagujarati: 0x0A9A,
  21615. cagurmukhi: 0x0A1A,
  21616. calsquare: 0x3388,
  21617. candrabindubengali: 0x0981,
  21618. candrabinducmb: 0x0310,
  21619. candrabindudeva: 0x0901,
  21620. candrabindugujarati: 0x0A81,
  21621. capslock: 0x21EA,
  21622. careof: 0x2105,
  21623. caron: 0x02C7,
  21624. caronbelowcmb: 0x032C,
  21625. caroncmb: 0x030C,
  21626. carriagereturn: 0x21B5,
  21627. cbopomofo: 0x3118,
  21628. ccaron: 0x010D,
  21629. ccedilla: 0x00E7,
  21630. ccedillaacute: 0x1E09,
  21631. ccircle: 0x24D2,
  21632. ccircumflex: 0x0109,
  21633. ccurl: 0x0255,
  21634. cdot: 0x010B,
  21635. cdotaccent: 0x010B,
  21636. cdsquare: 0x33C5,
  21637. cedilla: 0x00B8,
  21638. cedillacmb: 0x0327,
  21639. cent: 0x00A2,
  21640. centigrade: 0x2103,
  21641. centinferior: 0xF6DF,
  21642. centmonospace: 0xFFE0,
  21643. centoldstyle: 0xF7A2,
  21644. centsuperior: 0xF6E0,
  21645. chaarmenian: 0x0579,
  21646. chabengali: 0x099B,
  21647. chadeva: 0x091B,
  21648. chagujarati: 0x0A9B,
  21649. chagurmukhi: 0x0A1B,
  21650. chbopomofo: 0x3114,
  21651. cheabkhasiancyrillic: 0x04BD,
  21652. checkmark: 0x2713,
  21653. checyrillic: 0x0447,
  21654. chedescenderabkhasiancyrillic: 0x04BF,
  21655. chedescendercyrillic: 0x04B7,
  21656. chedieresiscyrillic: 0x04F5,
  21657. cheharmenian: 0x0573,
  21658. chekhakassiancyrillic: 0x04CC,
  21659. cheverticalstrokecyrillic: 0x04B9,
  21660. chi: 0x03C7,
  21661. chieuchacirclekorean: 0x3277,
  21662. chieuchaparenkorean: 0x3217,
  21663. chieuchcirclekorean: 0x3269,
  21664. chieuchkorean: 0x314A,
  21665. chieuchparenkorean: 0x3209,
  21666. chochangthai: 0x0E0A,
  21667. chochanthai: 0x0E08,
  21668. chochingthai: 0x0E09,
  21669. chochoethai: 0x0E0C,
  21670. chook: 0x0188,
  21671. cieucacirclekorean: 0x3276,
  21672. cieucaparenkorean: 0x3216,
  21673. cieuccirclekorean: 0x3268,
  21674. cieuckorean: 0x3148,
  21675. cieucparenkorean: 0x3208,
  21676. cieucuparenkorean: 0x321C,
  21677. circle: 0x25CB,
  21678. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21679. circlemultiply: 0x2297,
  21680. circleot: 0x2299,
  21681. circleplus: 0x2295,
  21682. circlepostalmark: 0x3036,
  21683. circlewithlefthalfblack: 0x25D0,
  21684. circlewithrighthalfblack: 0x25D1,
  21685. circumflex: 0x02C6,
  21686. circumflexbelowcmb: 0x032D,
  21687. circumflexcmb: 0x0302,
  21688. clear: 0x2327,
  21689. clickalveolar: 0x01C2,
  21690. clickdental: 0x01C0,
  21691. clicklateral: 0x01C1,
  21692. clickretroflex: 0x01C3,
  21693. club: 0x2663,
  21694. clubsuitblack: 0x2663,
  21695. clubsuitwhite: 0x2667,
  21696. cmcubedsquare: 0x33A4,
  21697. cmonospace: 0xFF43,
  21698. cmsquaredsquare: 0x33A0,
  21699. coarmenian: 0x0581,
  21700. colon: 0x003A,
  21701. colonmonetary: 0x20A1,
  21702. colonmonospace: 0xFF1A,
  21703. colonsign: 0x20A1,
  21704. colonsmall: 0xFE55,
  21705. colontriangularhalfmod: 0x02D1,
  21706. colontriangularmod: 0x02D0,
  21707. comma: 0x002C,
  21708. commaabovecmb: 0x0313,
  21709. commaaboverightcmb: 0x0315,
  21710. commaaccent: 0xF6C3,
  21711. commaarabic: 0x060C,
  21712. commaarmenian: 0x055D,
  21713. commainferior: 0xF6E1,
  21714. commamonospace: 0xFF0C,
  21715. commareversedabovecmb: 0x0314,
  21716. commareversedmod: 0x02BD,
  21717. commasmall: 0xFE50,
  21718. commasuperior: 0xF6E2,
  21719. commaturnedabovecmb: 0x0312,
  21720. commaturnedmod: 0x02BB,
  21721. compass: 0x263C,
  21722. congruent: 0x2245,
  21723. contourintegral: 0x222E,
  21724. control: 0x2303,
  21725. controlACK: 0x0006,
  21726. controlBEL: 0x0007,
  21727. controlBS: 0x0008,
  21728. controlCAN: 0x0018,
  21729. controlCR: 0x000D,
  21730. controlDC1: 0x0011,
  21731. controlDC2: 0x0012,
  21732. controlDC3: 0x0013,
  21733. controlDC4: 0x0014,
  21734. controlDEL: 0x007F,
  21735. controlDLE: 0x0010,
  21736. controlEM: 0x0019,
  21737. controlENQ: 0x0005,
  21738. controlEOT: 0x0004,
  21739. controlESC: 0x001B,
  21740. controlETB: 0x0017,
  21741. controlETX: 0x0003,
  21742. controlFF: 0x000C,
  21743. controlFS: 0x001C,
  21744. controlGS: 0x001D,
  21745. controlHT: 0x0009,
  21746. controlLF: 0x000A,
  21747. controlNAK: 0x0015,
  21748. controlRS: 0x001E,
  21749. controlSI: 0x000F,
  21750. controlSO: 0x000E,
  21751. controlSOT: 0x0002,
  21752. controlSTX: 0x0001,
  21753. controlSUB: 0x001A,
  21754. controlSYN: 0x0016,
  21755. controlUS: 0x001F,
  21756. controlVT: 0x000B,
  21757. copyright: 0x00A9,
  21758. copyrightsans: 0xF8E9,
  21759. copyrightserif: 0xF6D9,
  21760. cornerbracketleft: 0x300C,
  21761. cornerbracketlefthalfwidth: 0xFF62,
  21762. cornerbracketleftvertical: 0xFE41,
  21763. cornerbracketright: 0x300D,
  21764. cornerbracketrighthalfwidth: 0xFF63,
  21765. cornerbracketrightvertical: 0xFE42,
  21766. corporationsquare: 0x337F,
  21767. cosquare: 0x33C7,
  21768. coverkgsquare: 0x33C6,
  21769. cparen: 0x249E,
  21770. cruzeiro: 0x20A2,
  21771. cstretched: 0x0297,
  21772. curlyand: 0x22CF,
  21773. curlyor: 0x22CE,
  21774. currency: 0x00A4,
  21775. cyrBreve: 0xF6D1,
  21776. cyrFlex: 0xF6D2,
  21777. cyrbreve: 0xF6D4,
  21778. cyrflex: 0xF6D5,
  21779. d: 0x0064,
  21780. daarmenian: 0x0564,
  21781. dabengali: 0x09A6,
  21782. dadarabic: 0x0636,
  21783. dadeva: 0x0926,
  21784. dadfinalarabic: 0xFEBE,
  21785. dadinitialarabic: 0xFEBF,
  21786. dadmedialarabic: 0xFEC0,
  21787. dagesh: 0x05BC,
  21788. dageshhebrew: 0x05BC,
  21789. dagger: 0x2020,
  21790. daggerdbl: 0x2021,
  21791. dagujarati: 0x0AA6,
  21792. dagurmukhi: 0x0A26,
  21793. dahiragana: 0x3060,
  21794. dakatakana: 0x30C0,
  21795. dalarabic: 0x062F,
  21796. dalet: 0x05D3,
  21797. daletdagesh: 0xFB33,
  21798. daletdageshhebrew: 0xFB33,
  21799. dalethebrew: 0x05D3,
  21800. dalfinalarabic: 0xFEAA,
  21801. dammaarabic: 0x064F,
  21802. dammalowarabic: 0x064F,
  21803. dammatanaltonearabic: 0x064C,
  21804. dammatanarabic: 0x064C,
  21805. danda: 0x0964,
  21806. dargahebrew: 0x05A7,
  21807. dargalefthebrew: 0x05A7,
  21808. dasiapneumatacyrilliccmb: 0x0485,
  21809. dblGrave: 0xF6D3,
  21810. dblanglebracketleft: 0x300A,
  21811. dblanglebracketleftvertical: 0xFE3D,
  21812. dblanglebracketright: 0x300B,
  21813. dblanglebracketrightvertical: 0xFE3E,
  21814. dblarchinvertedbelowcmb: 0x032B,
  21815. dblarrowleft: 0x21D4,
  21816. dblarrowright: 0x21D2,
  21817. dbldanda: 0x0965,
  21818. dblgrave: 0xF6D6,
  21819. dblgravecmb: 0x030F,
  21820. dblintegral: 0x222C,
  21821. dbllowline: 0x2017,
  21822. dbllowlinecmb: 0x0333,
  21823. dbloverlinecmb: 0x033F,
  21824. dblprimemod: 0x02BA,
  21825. dblverticalbar: 0x2016,
  21826. dblverticallineabovecmb: 0x030E,
  21827. dbopomofo: 0x3109,
  21828. dbsquare: 0x33C8,
  21829. dcaron: 0x010F,
  21830. dcedilla: 0x1E11,
  21831. dcircle: 0x24D3,
  21832. dcircumflexbelow: 0x1E13,
  21833. dcroat: 0x0111,
  21834. ddabengali: 0x09A1,
  21835. ddadeva: 0x0921,
  21836. ddagujarati: 0x0AA1,
  21837. ddagurmukhi: 0x0A21,
  21838. ddalarabic: 0x0688,
  21839. ddalfinalarabic: 0xFB89,
  21840. dddhadeva: 0x095C,
  21841. ddhabengali: 0x09A2,
  21842. ddhadeva: 0x0922,
  21843. ddhagujarati: 0x0AA2,
  21844. ddhagurmukhi: 0x0A22,
  21845. ddotaccent: 0x1E0B,
  21846. ddotbelow: 0x1E0D,
  21847. decimalseparatorarabic: 0x066B,
  21848. decimalseparatorpersian: 0x066B,
  21849. decyrillic: 0x0434,
  21850. degree: 0x00B0,
  21851. dehihebrew: 0x05AD,
  21852. dehiragana: 0x3067,
  21853. deicoptic: 0x03EF,
  21854. dekatakana: 0x30C7,
  21855. deleteleft: 0x232B,
  21856. deleteright: 0x2326,
  21857. delta: 0x03B4,
  21858. deltaturned: 0x018D,
  21859. denominatorminusonenumeratorbengali: 0x09F8,
  21860. dezh: 0x02A4,
  21861. dhabengali: 0x09A7,
  21862. dhadeva: 0x0927,
  21863. dhagujarati: 0x0AA7,
  21864. dhagurmukhi: 0x0A27,
  21865. dhook: 0x0257,
  21866. dialytikatonos: 0x0385,
  21867. dialytikatonoscmb: 0x0344,
  21868. diamond: 0x2666,
  21869. diamondsuitwhite: 0x2662,
  21870. dieresis: 0x00A8,
  21871. dieresisacute: 0xF6D7,
  21872. dieresisbelowcmb: 0x0324,
  21873. dieresiscmb: 0x0308,
  21874. dieresisgrave: 0xF6D8,
  21875. dieresistonos: 0x0385,
  21876. dihiragana: 0x3062,
  21877. dikatakana: 0x30C2,
  21878. dittomark: 0x3003,
  21879. divide: 0x00F7,
  21880. divides: 0x2223,
  21881. divisionslash: 0x2215,
  21882. djecyrillic: 0x0452,
  21883. dkshade: 0x2593,
  21884. dlinebelow: 0x1E0F,
  21885. dlsquare: 0x3397,
  21886. dmacron: 0x0111,
  21887. dmonospace: 0xFF44,
  21888. dnblock: 0x2584,
  21889. dochadathai: 0x0E0E,
  21890. dodekthai: 0x0E14,
  21891. dohiragana: 0x3069,
  21892. dokatakana: 0x30C9,
  21893. dollar: 0x0024,
  21894. dollarinferior: 0xF6E3,
  21895. dollarmonospace: 0xFF04,
  21896. dollaroldstyle: 0xF724,
  21897. dollarsmall: 0xFE69,
  21898. dollarsuperior: 0xF6E4,
  21899. dong: 0x20AB,
  21900. dorusquare: 0x3326,
  21901. dotaccent: 0x02D9,
  21902. dotaccentcmb: 0x0307,
  21903. dotbelowcmb: 0x0323,
  21904. dotbelowcomb: 0x0323,
  21905. dotkatakana: 0x30FB,
  21906. dotlessi: 0x0131,
  21907. dotlessj: 0xF6BE,
  21908. dotlessjstrokehook: 0x0284,
  21909. dotmath: 0x22C5,
  21910. dottedcircle: 0x25CC,
  21911. doubleyodpatah: 0xFB1F,
  21912. doubleyodpatahhebrew: 0xFB1F,
  21913. downtackbelowcmb: 0x031E,
  21914. downtackmod: 0x02D5,
  21915. dparen: 0x249F,
  21916. dsuperior: 0xF6EB,
  21917. dtail: 0x0256,
  21918. dtopbar: 0x018C,
  21919. duhiragana: 0x3065,
  21920. dukatakana: 0x30C5,
  21921. dz: 0x01F3,
  21922. dzaltone: 0x02A3,
  21923. dzcaron: 0x01C6,
  21924. dzcurl: 0x02A5,
  21925. dzeabkhasiancyrillic: 0x04E1,
  21926. dzecyrillic: 0x0455,
  21927. dzhecyrillic: 0x045F,
  21928. e: 0x0065,
  21929. eacute: 0x00E9,
  21930. earth: 0x2641,
  21931. ebengali: 0x098F,
  21932. ebopomofo: 0x311C,
  21933. ebreve: 0x0115,
  21934. ecandradeva: 0x090D,
  21935. ecandragujarati: 0x0A8D,
  21936. ecandravowelsigndeva: 0x0945,
  21937. ecandravowelsigngujarati: 0x0AC5,
  21938. ecaron: 0x011B,
  21939. ecedillabreve: 0x1E1D,
  21940. echarmenian: 0x0565,
  21941. echyiwnarmenian: 0x0587,
  21942. ecircle: 0x24D4,
  21943. ecircumflex: 0x00EA,
  21944. ecircumflexacute: 0x1EBF,
  21945. ecircumflexbelow: 0x1E19,
  21946. ecircumflexdotbelow: 0x1EC7,
  21947. ecircumflexgrave: 0x1EC1,
  21948. ecircumflexhookabove: 0x1EC3,
  21949. ecircumflextilde: 0x1EC5,
  21950. ecyrillic: 0x0454,
  21951. edblgrave: 0x0205,
  21952. edeva: 0x090F,
  21953. edieresis: 0x00EB,
  21954. edot: 0x0117,
  21955. edotaccent: 0x0117,
  21956. edotbelow: 0x1EB9,
  21957. eegurmukhi: 0x0A0F,
  21958. eematragurmukhi: 0x0A47,
  21959. efcyrillic: 0x0444,
  21960. egrave: 0x00E8,
  21961. egujarati: 0x0A8F,
  21962. eharmenian: 0x0567,
  21963. ehbopomofo: 0x311D,
  21964. ehiragana: 0x3048,
  21965. ehookabove: 0x1EBB,
  21966. eibopomofo: 0x311F,
  21967. eight: 0x0038,
  21968. eightarabic: 0x0668,
  21969. eightbengali: 0x09EE,
  21970. eightcircle: 0x2467,
  21971. eightcircleinversesansserif: 0x2791,
  21972. eightdeva: 0x096E,
  21973. eighteencircle: 0x2471,
  21974. eighteenparen: 0x2485,
  21975. eighteenperiod: 0x2499,
  21976. eightgujarati: 0x0AEE,
  21977. eightgurmukhi: 0x0A6E,
  21978. eighthackarabic: 0x0668,
  21979. eighthangzhou: 0x3028,
  21980. eighthnotebeamed: 0x266B,
  21981. eightideographicparen: 0x3227,
  21982. eightinferior: 0x2088,
  21983. eightmonospace: 0xFF18,
  21984. eightoldstyle: 0xF738,
  21985. eightparen: 0x247B,
  21986. eightperiod: 0x248F,
  21987. eightpersian: 0x06F8,
  21988. eightroman: 0x2177,
  21989. eightsuperior: 0x2078,
  21990. eightthai: 0x0E58,
  21991. einvertedbreve: 0x0207,
  21992. eiotifiedcyrillic: 0x0465,
  21993. ekatakana: 0x30A8,
  21994. ekatakanahalfwidth: 0xFF74,
  21995. ekonkargurmukhi: 0x0A74,
  21996. ekorean: 0x3154,
  21997. elcyrillic: 0x043B,
  21998. element: 0x2208,
  21999. elevencircle: 0x246A,
  22000. elevenparen: 0x247E,
  22001. elevenperiod: 0x2492,
  22002. elevenroman: 0x217A,
  22003. ellipsis: 0x2026,
  22004. ellipsisvertical: 0x22EE,
  22005. emacron: 0x0113,
  22006. emacronacute: 0x1E17,
  22007. emacrongrave: 0x1E15,
  22008. emcyrillic: 0x043C,
  22009. emdash: 0x2014,
  22010. emdashvertical: 0xFE31,
  22011. emonospace: 0xFF45,
  22012. emphasismarkarmenian: 0x055B,
  22013. emptyset: 0x2205,
  22014. enbopomofo: 0x3123,
  22015. encyrillic: 0x043D,
  22016. endash: 0x2013,
  22017. endashvertical: 0xFE32,
  22018. endescendercyrillic: 0x04A3,
  22019. eng: 0x014B,
  22020. engbopomofo: 0x3125,
  22021. enghecyrillic: 0x04A5,
  22022. enhookcyrillic: 0x04C8,
  22023. enspace: 0x2002,
  22024. eogonek: 0x0119,
  22025. eokorean: 0x3153,
  22026. eopen: 0x025B,
  22027. eopenclosed: 0x029A,
  22028. eopenreversed: 0x025C,
  22029. eopenreversedclosed: 0x025E,
  22030. eopenreversedhook: 0x025D,
  22031. eparen: 0x24A0,
  22032. epsilon: 0x03B5,
  22033. epsilontonos: 0x03AD,
  22034. equal: 0x003D,
  22035. equalmonospace: 0xFF1D,
  22036. equalsmall: 0xFE66,
  22037. equalsuperior: 0x207C,
  22038. equivalence: 0x2261,
  22039. erbopomofo: 0x3126,
  22040. ercyrillic: 0x0440,
  22041. ereversed: 0x0258,
  22042. ereversedcyrillic: 0x044D,
  22043. escyrillic: 0x0441,
  22044. esdescendercyrillic: 0x04AB,
  22045. esh: 0x0283,
  22046. eshcurl: 0x0286,
  22047. eshortdeva: 0x090E,
  22048. eshortvowelsigndeva: 0x0946,
  22049. eshreversedloop: 0x01AA,
  22050. eshsquatreversed: 0x0285,
  22051. esmallhiragana: 0x3047,
  22052. esmallkatakana: 0x30A7,
  22053. esmallkatakanahalfwidth: 0xFF6A,
  22054. estimated: 0x212E,
  22055. esuperior: 0xF6EC,
  22056. eta: 0x03B7,
  22057. etarmenian: 0x0568,
  22058. etatonos: 0x03AE,
  22059. eth: 0x00F0,
  22060. etilde: 0x1EBD,
  22061. etildebelow: 0x1E1B,
  22062. etnahtafoukhhebrew: 0x0591,
  22063. etnahtafoukhlefthebrew: 0x0591,
  22064. etnahtahebrew: 0x0591,
  22065. etnahtalefthebrew: 0x0591,
  22066. eturned: 0x01DD,
  22067. eukorean: 0x3161,
  22068. euro: 0x20AC,
  22069. evowelsignbengali: 0x09C7,
  22070. evowelsigndeva: 0x0947,
  22071. evowelsigngujarati: 0x0AC7,
  22072. exclam: 0x0021,
  22073. exclamarmenian: 0x055C,
  22074. exclamdbl: 0x203C,
  22075. exclamdown: 0x00A1,
  22076. exclamdownsmall: 0xF7A1,
  22077. exclammonospace: 0xFF01,
  22078. exclamsmall: 0xF721,
  22079. existential: 0x2203,
  22080. ezh: 0x0292,
  22081. ezhcaron: 0x01EF,
  22082. ezhcurl: 0x0293,
  22083. ezhreversed: 0x01B9,
  22084. ezhtail: 0x01BA,
  22085. f: 0x0066,
  22086. fadeva: 0x095E,
  22087. fagurmukhi: 0x0A5E,
  22088. fahrenheit: 0x2109,
  22089. fathaarabic: 0x064E,
  22090. fathalowarabic: 0x064E,
  22091. fathatanarabic: 0x064B,
  22092. fbopomofo: 0x3108,
  22093. fcircle: 0x24D5,
  22094. fdotaccent: 0x1E1F,
  22095. feharabic: 0x0641,
  22096. feharmenian: 0x0586,
  22097. fehfinalarabic: 0xFED2,
  22098. fehinitialarabic: 0xFED3,
  22099. fehmedialarabic: 0xFED4,
  22100. feicoptic: 0x03E5,
  22101. female: 0x2640,
  22102. ff: 0xFB00,
  22103. ffi: 0xFB03,
  22104. ffl: 0xFB04,
  22105. fi: 0xFB01,
  22106. fifteencircle: 0x246E,
  22107. fifteenparen: 0x2482,
  22108. fifteenperiod: 0x2496,
  22109. figuredash: 0x2012,
  22110. filledbox: 0x25A0,
  22111. filledrect: 0x25AC,
  22112. finalkaf: 0x05DA,
  22113. finalkafdagesh: 0xFB3A,
  22114. finalkafdageshhebrew: 0xFB3A,
  22115. finalkafhebrew: 0x05DA,
  22116. finalmem: 0x05DD,
  22117. finalmemhebrew: 0x05DD,
  22118. finalnun: 0x05DF,
  22119. finalnunhebrew: 0x05DF,
  22120. finalpe: 0x05E3,
  22121. finalpehebrew: 0x05E3,
  22122. finaltsadi: 0x05E5,
  22123. finaltsadihebrew: 0x05E5,
  22124. firsttonechinese: 0x02C9,
  22125. fisheye: 0x25C9,
  22126. fitacyrillic: 0x0473,
  22127. five: 0x0035,
  22128. fivearabic: 0x0665,
  22129. fivebengali: 0x09EB,
  22130. fivecircle: 0x2464,
  22131. fivecircleinversesansserif: 0x278E,
  22132. fivedeva: 0x096B,
  22133. fiveeighths: 0x215D,
  22134. fivegujarati: 0x0AEB,
  22135. fivegurmukhi: 0x0A6B,
  22136. fivehackarabic: 0x0665,
  22137. fivehangzhou: 0x3025,
  22138. fiveideographicparen: 0x3224,
  22139. fiveinferior: 0x2085,
  22140. fivemonospace: 0xFF15,
  22141. fiveoldstyle: 0xF735,
  22142. fiveparen: 0x2478,
  22143. fiveperiod: 0x248C,
  22144. fivepersian: 0x06F5,
  22145. fiveroman: 0x2174,
  22146. fivesuperior: 0x2075,
  22147. fivethai: 0x0E55,
  22148. fl: 0xFB02,
  22149. florin: 0x0192,
  22150. fmonospace: 0xFF46,
  22151. fmsquare: 0x3399,
  22152. fofanthai: 0x0E1F,
  22153. fofathai: 0x0E1D,
  22154. fongmanthai: 0x0E4F,
  22155. forall: 0x2200,
  22156. four: 0x0034,
  22157. fourarabic: 0x0664,
  22158. fourbengali: 0x09EA,
  22159. fourcircle: 0x2463,
  22160. fourcircleinversesansserif: 0x278D,
  22161. fourdeva: 0x096A,
  22162. fourgujarati: 0x0AEA,
  22163. fourgurmukhi: 0x0A6A,
  22164. fourhackarabic: 0x0664,
  22165. fourhangzhou: 0x3024,
  22166. fourideographicparen: 0x3223,
  22167. fourinferior: 0x2084,
  22168. fourmonospace: 0xFF14,
  22169. fournumeratorbengali: 0x09F7,
  22170. fouroldstyle: 0xF734,
  22171. fourparen: 0x2477,
  22172. fourperiod: 0x248B,
  22173. fourpersian: 0x06F4,
  22174. fourroman: 0x2173,
  22175. foursuperior: 0x2074,
  22176. fourteencircle: 0x246D,
  22177. fourteenparen: 0x2481,
  22178. fourteenperiod: 0x2495,
  22179. fourthai: 0x0E54,
  22180. fourthtonechinese: 0x02CB,
  22181. fparen: 0x24A1,
  22182. fraction: 0x2044,
  22183. franc: 0x20A3,
  22184. g: 0x0067,
  22185. gabengali: 0x0997,
  22186. gacute: 0x01F5,
  22187. gadeva: 0x0917,
  22188. gafarabic: 0x06AF,
  22189. gaffinalarabic: 0xFB93,
  22190. gafinitialarabic: 0xFB94,
  22191. gafmedialarabic: 0xFB95,
  22192. gagujarati: 0x0A97,
  22193. gagurmukhi: 0x0A17,
  22194. gahiragana: 0x304C,
  22195. gakatakana: 0x30AC,
  22196. gamma: 0x03B3,
  22197. gammalatinsmall: 0x0263,
  22198. gammasuperior: 0x02E0,
  22199. gangiacoptic: 0x03EB,
  22200. gbopomofo: 0x310D,
  22201. gbreve: 0x011F,
  22202. gcaron: 0x01E7,
  22203. gcedilla: 0x0123,
  22204. gcircle: 0x24D6,
  22205. gcircumflex: 0x011D,
  22206. gcommaaccent: 0x0123,
  22207. gdot: 0x0121,
  22208. gdotaccent: 0x0121,
  22209. gecyrillic: 0x0433,
  22210. gehiragana: 0x3052,
  22211. gekatakana: 0x30B2,
  22212. geometricallyequal: 0x2251,
  22213. gereshaccenthebrew: 0x059C,
  22214. gereshhebrew: 0x05F3,
  22215. gereshmuqdamhebrew: 0x059D,
  22216. germandbls: 0x00DF,
  22217. gershayimaccenthebrew: 0x059E,
  22218. gershayimhebrew: 0x05F4,
  22219. getamark: 0x3013,
  22220. ghabengali: 0x0998,
  22221. ghadarmenian: 0x0572,
  22222. ghadeva: 0x0918,
  22223. ghagujarati: 0x0A98,
  22224. ghagurmukhi: 0x0A18,
  22225. ghainarabic: 0x063A,
  22226. ghainfinalarabic: 0xFECE,
  22227. ghaininitialarabic: 0xFECF,
  22228. ghainmedialarabic: 0xFED0,
  22229. ghemiddlehookcyrillic: 0x0495,
  22230. ghestrokecyrillic: 0x0493,
  22231. gheupturncyrillic: 0x0491,
  22232. ghhadeva: 0x095A,
  22233. ghhagurmukhi: 0x0A5A,
  22234. ghook: 0x0260,
  22235. ghzsquare: 0x3393,
  22236. gihiragana: 0x304E,
  22237. gikatakana: 0x30AE,
  22238. gimarmenian: 0x0563,
  22239. gimel: 0x05D2,
  22240. gimeldagesh: 0xFB32,
  22241. gimeldageshhebrew: 0xFB32,
  22242. gimelhebrew: 0x05D2,
  22243. gjecyrillic: 0x0453,
  22244. glottalinvertedstroke: 0x01BE,
  22245. glottalstop: 0x0294,
  22246. glottalstopinverted: 0x0296,
  22247. glottalstopmod: 0x02C0,
  22248. glottalstopreversed: 0x0295,
  22249. glottalstopreversedmod: 0x02C1,
  22250. glottalstopreversedsuperior: 0x02E4,
  22251. glottalstopstroke: 0x02A1,
  22252. glottalstopstrokereversed: 0x02A2,
  22253. gmacron: 0x1E21,
  22254. gmonospace: 0xFF47,
  22255. gohiragana: 0x3054,
  22256. gokatakana: 0x30B4,
  22257. gparen: 0x24A2,
  22258. gpasquare: 0x33AC,
  22259. gradient: 0x2207,
  22260. grave: 0x0060,
  22261. gravebelowcmb: 0x0316,
  22262. gravecmb: 0x0300,
  22263. gravecomb: 0x0300,
  22264. gravedeva: 0x0953,
  22265. gravelowmod: 0x02CE,
  22266. gravemonospace: 0xFF40,
  22267. gravetonecmb: 0x0340,
  22268. greater: 0x003E,
  22269. greaterequal: 0x2265,
  22270. greaterequalorless: 0x22DB,
  22271. greatermonospace: 0xFF1E,
  22272. greaterorequivalent: 0x2273,
  22273. greaterorless: 0x2277,
  22274. greateroverequal: 0x2267,
  22275. greatersmall: 0xFE65,
  22276. gscript: 0x0261,
  22277. gstroke: 0x01E5,
  22278. guhiragana: 0x3050,
  22279. guillemotleft: 0x00AB,
  22280. guillemotright: 0x00BB,
  22281. guilsinglleft: 0x2039,
  22282. guilsinglright: 0x203A,
  22283. gukatakana: 0x30B0,
  22284. guramusquare: 0x3318,
  22285. gysquare: 0x33C9,
  22286. h: 0x0068,
  22287. haabkhasiancyrillic: 0x04A9,
  22288. haaltonearabic: 0x06C1,
  22289. habengali: 0x09B9,
  22290. hadescendercyrillic: 0x04B3,
  22291. hadeva: 0x0939,
  22292. hagujarati: 0x0AB9,
  22293. hagurmukhi: 0x0A39,
  22294. haharabic: 0x062D,
  22295. hahfinalarabic: 0xFEA2,
  22296. hahinitialarabic: 0xFEA3,
  22297. hahiragana: 0x306F,
  22298. hahmedialarabic: 0xFEA4,
  22299. haitusquare: 0x332A,
  22300. hakatakana: 0x30CF,
  22301. hakatakanahalfwidth: 0xFF8A,
  22302. halantgurmukhi: 0x0A4D,
  22303. hamzaarabic: 0x0621,
  22304. hamzalowarabic: 0x0621,
  22305. hangulfiller: 0x3164,
  22306. hardsigncyrillic: 0x044A,
  22307. harpoonleftbarbup: 0x21BC,
  22308. harpoonrightbarbup: 0x21C0,
  22309. hasquare: 0x33CA,
  22310. hatafpatah: 0x05B2,
  22311. hatafpatah16: 0x05B2,
  22312. hatafpatah23: 0x05B2,
  22313. hatafpatah2f: 0x05B2,
  22314. hatafpatahhebrew: 0x05B2,
  22315. hatafpatahnarrowhebrew: 0x05B2,
  22316. hatafpatahquarterhebrew: 0x05B2,
  22317. hatafpatahwidehebrew: 0x05B2,
  22318. hatafqamats: 0x05B3,
  22319. hatafqamats1b: 0x05B3,
  22320. hatafqamats28: 0x05B3,
  22321. hatafqamats34: 0x05B3,
  22322. hatafqamatshebrew: 0x05B3,
  22323. hatafqamatsnarrowhebrew: 0x05B3,
  22324. hatafqamatsquarterhebrew: 0x05B3,
  22325. hatafqamatswidehebrew: 0x05B3,
  22326. hatafsegol: 0x05B1,
  22327. hatafsegol17: 0x05B1,
  22328. hatafsegol24: 0x05B1,
  22329. hatafsegol30: 0x05B1,
  22330. hatafsegolhebrew: 0x05B1,
  22331. hatafsegolnarrowhebrew: 0x05B1,
  22332. hatafsegolquarterhebrew: 0x05B1,
  22333. hatafsegolwidehebrew: 0x05B1,
  22334. hbar: 0x0127,
  22335. hbopomofo: 0x310F,
  22336. hbrevebelow: 0x1E2B,
  22337. hcedilla: 0x1E29,
  22338. hcircle: 0x24D7,
  22339. hcircumflex: 0x0125,
  22340. hdieresis: 0x1E27,
  22341. hdotaccent: 0x1E23,
  22342. hdotbelow: 0x1E25,
  22343. he: 0x05D4,
  22344. heart: 0x2665,
  22345. heartsuitblack: 0x2665,
  22346. heartsuitwhite: 0x2661,
  22347. hedagesh: 0xFB34,
  22348. hedageshhebrew: 0xFB34,
  22349. hehaltonearabic: 0x06C1,
  22350. heharabic: 0x0647,
  22351. hehebrew: 0x05D4,
  22352. hehfinalaltonearabic: 0xFBA7,
  22353. hehfinalalttwoarabic: 0xFEEA,
  22354. hehfinalarabic: 0xFEEA,
  22355. hehhamzaabovefinalarabic: 0xFBA5,
  22356. hehhamzaaboveisolatedarabic: 0xFBA4,
  22357. hehinitialaltonearabic: 0xFBA8,
  22358. hehinitialarabic: 0xFEEB,
  22359. hehiragana: 0x3078,
  22360. hehmedialaltonearabic: 0xFBA9,
  22361. hehmedialarabic: 0xFEEC,
  22362. heiseierasquare: 0x337B,
  22363. hekatakana: 0x30D8,
  22364. hekatakanahalfwidth: 0xFF8D,
  22365. hekutaarusquare: 0x3336,
  22366. henghook: 0x0267,
  22367. herutusquare: 0x3339,
  22368. het: 0x05D7,
  22369. hethebrew: 0x05D7,
  22370. hhook: 0x0266,
  22371. hhooksuperior: 0x02B1,
  22372. hieuhacirclekorean: 0x327B,
  22373. hieuhaparenkorean: 0x321B,
  22374. hieuhcirclekorean: 0x326D,
  22375. hieuhkorean: 0x314E,
  22376. hieuhparenkorean: 0x320D,
  22377. hihiragana: 0x3072,
  22378. hikatakana: 0x30D2,
  22379. hikatakanahalfwidth: 0xFF8B,
  22380. hiriq: 0x05B4,
  22381. hiriq14: 0x05B4,
  22382. hiriq21: 0x05B4,
  22383. hiriq2d: 0x05B4,
  22384. hiriqhebrew: 0x05B4,
  22385. hiriqnarrowhebrew: 0x05B4,
  22386. hiriqquarterhebrew: 0x05B4,
  22387. hiriqwidehebrew: 0x05B4,
  22388. hlinebelow: 0x1E96,
  22389. hmonospace: 0xFF48,
  22390. hoarmenian: 0x0570,
  22391. hohipthai: 0x0E2B,
  22392. hohiragana: 0x307B,
  22393. hokatakana: 0x30DB,
  22394. hokatakanahalfwidth: 0xFF8E,
  22395. holam: 0x05B9,
  22396. holam19: 0x05B9,
  22397. holam26: 0x05B9,
  22398. holam32: 0x05B9,
  22399. holamhebrew: 0x05B9,
  22400. holamnarrowhebrew: 0x05B9,
  22401. holamquarterhebrew: 0x05B9,
  22402. holamwidehebrew: 0x05B9,
  22403. honokhukthai: 0x0E2E,
  22404. hookabovecomb: 0x0309,
  22405. hookcmb: 0x0309,
  22406. hookpalatalizedbelowcmb: 0x0321,
  22407. hookretroflexbelowcmb: 0x0322,
  22408. hoonsquare: 0x3342,
  22409. horicoptic: 0x03E9,
  22410. horizontalbar: 0x2015,
  22411. horncmb: 0x031B,
  22412. hotsprings: 0x2668,
  22413. house: 0x2302,
  22414. hparen: 0x24A3,
  22415. hsuperior: 0x02B0,
  22416. hturned: 0x0265,
  22417. huhiragana: 0x3075,
  22418. huiitosquare: 0x3333,
  22419. hukatakana: 0x30D5,
  22420. hukatakanahalfwidth: 0xFF8C,
  22421. hungarumlaut: 0x02DD,
  22422. hungarumlautcmb: 0x030B,
  22423. hv: 0x0195,
  22424. hyphen: 0x002D,
  22425. hypheninferior: 0xF6E5,
  22426. hyphenmonospace: 0xFF0D,
  22427. hyphensmall: 0xFE63,
  22428. hyphensuperior: 0xF6E6,
  22429. hyphentwo: 0x2010,
  22430. i: 0x0069,
  22431. iacute: 0x00ED,
  22432. iacyrillic: 0x044F,
  22433. ibengali: 0x0987,
  22434. ibopomofo: 0x3127,
  22435. ibreve: 0x012D,
  22436. icaron: 0x01D0,
  22437. icircle: 0x24D8,
  22438. icircumflex: 0x00EE,
  22439. icyrillic: 0x0456,
  22440. idblgrave: 0x0209,
  22441. ideographearthcircle: 0x328F,
  22442. ideographfirecircle: 0x328B,
  22443. ideographicallianceparen: 0x323F,
  22444. ideographiccallparen: 0x323A,
  22445. ideographiccentrecircle: 0x32A5,
  22446. ideographicclose: 0x3006,
  22447. ideographiccomma: 0x3001,
  22448. ideographiccommaleft: 0xFF64,
  22449. ideographiccongratulationparen: 0x3237,
  22450. ideographiccorrectcircle: 0x32A3,
  22451. ideographicearthparen: 0x322F,
  22452. ideographicenterpriseparen: 0x323D,
  22453. ideographicexcellentcircle: 0x329D,
  22454. ideographicfestivalparen: 0x3240,
  22455. ideographicfinancialcircle: 0x3296,
  22456. ideographicfinancialparen: 0x3236,
  22457. ideographicfireparen: 0x322B,
  22458. ideographichaveparen: 0x3232,
  22459. ideographichighcircle: 0x32A4,
  22460. ideographiciterationmark: 0x3005,
  22461. ideographiclaborcircle: 0x3298,
  22462. ideographiclaborparen: 0x3238,
  22463. ideographicleftcircle: 0x32A7,
  22464. ideographiclowcircle: 0x32A6,
  22465. ideographicmedicinecircle: 0x32A9,
  22466. ideographicmetalparen: 0x322E,
  22467. ideographicmoonparen: 0x322A,
  22468. ideographicnameparen: 0x3234,
  22469. ideographicperiod: 0x3002,
  22470. ideographicprintcircle: 0x329E,
  22471. ideographicreachparen: 0x3243,
  22472. ideographicrepresentparen: 0x3239,
  22473. ideographicresourceparen: 0x323E,
  22474. ideographicrightcircle: 0x32A8,
  22475. ideographicsecretcircle: 0x3299,
  22476. ideographicselfparen: 0x3242,
  22477. ideographicsocietyparen: 0x3233,
  22478. ideographicspace: 0x3000,
  22479. ideographicspecialparen: 0x3235,
  22480. ideographicstockparen: 0x3231,
  22481. ideographicstudyparen: 0x323B,
  22482. ideographicsunparen: 0x3230,
  22483. ideographicsuperviseparen: 0x323C,
  22484. ideographicwaterparen: 0x322C,
  22485. ideographicwoodparen: 0x322D,
  22486. ideographiczero: 0x3007,
  22487. ideographmetalcircle: 0x328E,
  22488. ideographmooncircle: 0x328A,
  22489. ideographnamecircle: 0x3294,
  22490. ideographsuncircle: 0x3290,
  22491. ideographwatercircle: 0x328C,
  22492. ideographwoodcircle: 0x328D,
  22493. ideva: 0x0907,
  22494. idieresis: 0x00EF,
  22495. idieresisacute: 0x1E2F,
  22496. idieresiscyrillic: 0x04E5,
  22497. idotbelow: 0x1ECB,
  22498. iebrevecyrillic: 0x04D7,
  22499. iecyrillic: 0x0435,
  22500. ieungacirclekorean: 0x3275,
  22501. ieungaparenkorean: 0x3215,
  22502. ieungcirclekorean: 0x3267,
  22503. ieungkorean: 0x3147,
  22504. ieungparenkorean: 0x3207,
  22505. igrave: 0x00EC,
  22506. igujarati: 0x0A87,
  22507. igurmukhi: 0x0A07,
  22508. ihiragana: 0x3044,
  22509. ihookabove: 0x1EC9,
  22510. iibengali: 0x0988,
  22511. iicyrillic: 0x0438,
  22512. iideva: 0x0908,
  22513. iigujarati: 0x0A88,
  22514. iigurmukhi: 0x0A08,
  22515. iimatragurmukhi: 0x0A40,
  22516. iinvertedbreve: 0x020B,
  22517. iishortcyrillic: 0x0439,
  22518. iivowelsignbengali: 0x09C0,
  22519. iivowelsigndeva: 0x0940,
  22520. iivowelsigngujarati: 0x0AC0,
  22521. ij: 0x0133,
  22522. ikatakana: 0x30A4,
  22523. ikatakanahalfwidth: 0xFF72,
  22524. ikorean: 0x3163,
  22525. ilde: 0x02DC,
  22526. iluyhebrew: 0x05AC,
  22527. imacron: 0x012B,
  22528. imacroncyrillic: 0x04E3,
  22529. imageorapproximatelyequal: 0x2253,
  22530. imatragurmukhi: 0x0A3F,
  22531. imonospace: 0xFF49,
  22532. increment: 0x2206,
  22533. infinity: 0x221E,
  22534. iniarmenian: 0x056B,
  22535. integral: 0x222B,
  22536. integralbottom: 0x2321,
  22537. integralbt: 0x2321,
  22538. integralex: 0xF8F5,
  22539. integraltop: 0x2320,
  22540. integraltp: 0x2320,
  22541. intersection: 0x2229,
  22542. intisquare: 0x3305,
  22543. invbullet: 0x25D8,
  22544. invcircle: 0x25D9,
  22545. invsmileface: 0x263B,
  22546. iocyrillic: 0x0451,
  22547. iogonek: 0x012F,
  22548. iota: 0x03B9,
  22549. iotadieresis: 0x03CA,
  22550. iotadieresistonos: 0x0390,
  22551. iotalatin: 0x0269,
  22552. iotatonos: 0x03AF,
  22553. iparen: 0x24A4,
  22554. irigurmukhi: 0x0A72,
  22555. ismallhiragana: 0x3043,
  22556. ismallkatakana: 0x30A3,
  22557. ismallkatakanahalfwidth: 0xFF68,
  22558. issharbengali: 0x09FA,
  22559. istroke: 0x0268,
  22560. isuperior: 0xF6ED,
  22561. iterationhiragana: 0x309D,
  22562. iterationkatakana: 0x30FD,
  22563. itilde: 0x0129,
  22564. itildebelow: 0x1E2D,
  22565. iubopomofo: 0x3129,
  22566. iucyrillic: 0x044E,
  22567. ivowelsignbengali: 0x09BF,
  22568. ivowelsigndeva: 0x093F,
  22569. ivowelsigngujarati: 0x0ABF,
  22570. izhitsacyrillic: 0x0475,
  22571. izhitsadblgravecyrillic: 0x0477,
  22572. j: 0x006A,
  22573. jaarmenian: 0x0571,
  22574. jabengali: 0x099C,
  22575. jadeva: 0x091C,
  22576. jagujarati: 0x0A9C,
  22577. jagurmukhi: 0x0A1C,
  22578. jbopomofo: 0x3110,
  22579. jcaron: 0x01F0,
  22580. jcircle: 0x24D9,
  22581. jcircumflex: 0x0135,
  22582. jcrossedtail: 0x029D,
  22583. jdotlessstroke: 0x025F,
  22584. jecyrillic: 0x0458,
  22585. jeemarabic: 0x062C,
  22586. jeemfinalarabic: 0xFE9E,
  22587. jeeminitialarabic: 0xFE9F,
  22588. jeemmedialarabic: 0xFEA0,
  22589. jeharabic: 0x0698,
  22590. jehfinalarabic: 0xFB8B,
  22591. jhabengali: 0x099D,
  22592. jhadeva: 0x091D,
  22593. jhagujarati: 0x0A9D,
  22594. jhagurmukhi: 0x0A1D,
  22595. jheharmenian: 0x057B,
  22596. jis: 0x3004,
  22597. jmonospace: 0xFF4A,
  22598. jparen: 0x24A5,
  22599. jsuperior: 0x02B2,
  22600. k: 0x006B,
  22601. kabashkircyrillic: 0x04A1,
  22602. kabengali: 0x0995,
  22603. kacute: 0x1E31,
  22604. kacyrillic: 0x043A,
  22605. kadescendercyrillic: 0x049B,
  22606. kadeva: 0x0915,
  22607. kaf: 0x05DB,
  22608. kafarabic: 0x0643,
  22609. kafdagesh: 0xFB3B,
  22610. kafdageshhebrew: 0xFB3B,
  22611. kaffinalarabic: 0xFEDA,
  22612. kafhebrew: 0x05DB,
  22613. kafinitialarabic: 0xFEDB,
  22614. kafmedialarabic: 0xFEDC,
  22615. kafrafehebrew: 0xFB4D,
  22616. kagujarati: 0x0A95,
  22617. kagurmukhi: 0x0A15,
  22618. kahiragana: 0x304B,
  22619. kahookcyrillic: 0x04C4,
  22620. kakatakana: 0x30AB,
  22621. kakatakanahalfwidth: 0xFF76,
  22622. kappa: 0x03BA,
  22623. kappasymbolgreek: 0x03F0,
  22624. kapyeounmieumkorean: 0x3171,
  22625. kapyeounphieuphkorean: 0x3184,
  22626. kapyeounpieupkorean: 0x3178,
  22627. kapyeounssangpieupkorean: 0x3179,
  22628. karoriisquare: 0x330D,
  22629. kashidaautoarabic: 0x0640,
  22630. kashidaautonosidebearingarabic: 0x0640,
  22631. kasmallkatakana: 0x30F5,
  22632. kasquare: 0x3384,
  22633. kasraarabic: 0x0650,
  22634. kasratanarabic: 0x064D,
  22635. kastrokecyrillic: 0x049F,
  22636. katahiraprolongmarkhalfwidth: 0xFF70,
  22637. kaverticalstrokecyrillic: 0x049D,
  22638. kbopomofo: 0x310E,
  22639. kcalsquare: 0x3389,
  22640. kcaron: 0x01E9,
  22641. kcedilla: 0x0137,
  22642. kcircle: 0x24DA,
  22643. kcommaaccent: 0x0137,
  22644. kdotbelow: 0x1E33,
  22645. keharmenian: 0x0584,
  22646. kehiragana: 0x3051,
  22647. kekatakana: 0x30B1,
  22648. kekatakanahalfwidth: 0xFF79,
  22649. kenarmenian: 0x056F,
  22650. kesmallkatakana: 0x30F6,
  22651. kgreenlandic: 0x0138,
  22652. khabengali: 0x0996,
  22653. khacyrillic: 0x0445,
  22654. khadeva: 0x0916,
  22655. khagujarati: 0x0A96,
  22656. khagurmukhi: 0x0A16,
  22657. khaharabic: 0x062E,
  22658. khahfinalarabic: 0xFEA6,
  22659. khahinitialarabic: 0xFEA7,
  22660. khahmedialarabic: 0xFEA8,
  22661. kheicoptic: 0x03E7,
  22662. khhadeva: 0x0959,
  22663. khhagurmukhi: 0x0A59,
  22664. khieukhacirclekorean: 0x3278,
  22665. khieukhaparenkorean: 0x3218,
  22666. khieukhcirclekorean: 0x326A,
  22667. khieukhkorean: 0x314B,
  22668. khieukhparenkorean: 0x320A,
  22669. khokhaithai: 0x0E02,
  22670. khokhonthai: 0x0E05,
  22671. khokhuatthai: 0x0E03,
  22672. khokhwaithai: 0x0E04,
  22673. khomutthai: 0x0E5B,
  22674. khook: 0x0199,
  22675. khorakhangthai: 0x0E06,
  22676. khzsquare: 0x3391,
  22677. kihiragana: 0x304D,
  22678. kikatakana: 0x30AD,
  22679. kikatakanahalfwidth: 0xFF77,
  22680. kiroguramusquare: 0x3315,
  22681. kiromeetorusquare: 0x3316,
  22682. kirosquare: 0x3314,
  22683. kiyeokacirclekorean: 0x326E,
  22684. kiyeokaparenkorean: 0x320E,
  22685. kiyeokcirclekorean: 0x3260,
  22686. kiyeokkorean: 0x3131,
  22687. kiyeokparenkorean: 0x3200,
  22688. kiyeoksioskorean: 0x3133,
  22689. kjecyrillic: 0x045C,
  22690. klinebelow: 0x1E35,
  22691. klsquare: 0x3398,
  22692. kmcubedsquare: 0x33A6,
  22693. kmonospace: 0xFF4B,
  22694. kmsquaredsquare: 0x33A2,
  22695. kohiragana: 0x3053,
  22696. kohmsquare: 0x33C0,
  22697. kokaithai: 0x0E01,
  22698. kokatakana: 0x30B3,
  22699. kokatakanahalfwidth: 0xFF7A,
  22700. kooposquare: 0x331E,
  22701. koppacyrillic: 0x0481,
  22702. koreanstandardsymbol: 0x327F,
  22703. koroniscmb: 0x0343,
  22704. kparen: 0x24A6,
  22705. kpasquare: 0x33AA,
  22706. ksicyrillic: 0x046F,
  22707. ktsquare: 0x33CF,
  22708. kturned: 0x029E,
  22709. kuhiragana: 0x304F,
  22710. kukatakana: 0x30AF,
  22711. kukatakanahalfwidth: 0xFF78,
  22712. kvsquare: 0x33B8,
  22713. kwsquare: 0x33BE,
  22714. l: 0x006C,
  22715. labengali: 0x09B2,
  22716. lacute: 0x013A,
  22717. ladeva: 0x0932,
  22718. lagujarati: 0x0AB2,
  22719. lagurmukhi: 0x0A32,
  22720. lakkhangyaothai: 0x0E45,
  22721. lamaleffinalarabic: 0xFEFC,
  22722. lamalefhamzaabovefinalarabic: 0xFEF8,
  22723. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22724. lamalefhamzabelowfinalarabic: 0xFEFA,
  22725. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22726. lamalefisolatedarabic: 0xFEFB,
  22727. lamalefmaddaabovefinalarabic: 0xFEF6,
  22728. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22729. lamarabic: 0x0644,
  22730. lambda: 0x03BB,
  22731. lambdastroke: 0x019B,
  22732. lamed: 0x05DC,
  22733. lameddagesh: 0xFB3C,
  22734. lameddageshhebrew: 0xFB3C,
  22735. lamedhebrew: 0x05DC,
  22736. lamfinalarabic: 0xFEDE,
  22737. lamhahinitialarabic: 0xFCCA,
  22738. laminitialarabic: 0xFEDF,
  22739. lamjeeminitialarabic: 0xFCC9,
  22740. lamkhahinitialarabic: 0xFCCB,
  22741. lamlamhehisolatedarabic: 0xFDF2,
  22742. lammedialarabic: 0xFEE0,
  22743. lammeemhahinitialarabic: 0xFD88,
  22744. lammeeminitialarabic: 0xFCCC,
  22745. largecircle: 0x25EF,
  22746. lbar: 0x019A,
  22747. lbelt: 0x026C,
  22748. lbopomofo: 0x310C,
  22749. lcaron: 0x013E,
  22750. lcedilla: 0x013C,
  22751. lcircle: 0x24DB,
  22752. lcircumflexbelow: 0x1E3D,
  22753. lcommaaccent: 0x013C,
  22754. ldot: 0x0140,
  22755. ldotaccent: 0x0140,
  22756. ldotbelow: 0x1E37,
  22757. ldotbelowmacron: 0x1E39,
  22758. leftangleabovecmb: 0x031A,
  22759. lefttackbelowcmb: 0x0318,
  22760. less: 0x003C,
  22761. lessequal: 0x2264,
  22762. lessequalorgreater: 0x22DA,
  22763. lessmonospace: 0xFF1C,
  22764. lessorequivalent: 0x2272,
  22765. lessorgreater: 0x2276,
  22766. lessoverequal: 0x2266,
  22767. lesssmall: 0xFE64,
  22768. lezh: 0x026E,
  22769. lfblock: 0x258C,
  22770. lhookretroflex: 0x026D,
  22771. lira: 0x20A4,
  22772. liwnarmenian: 0x056C,
  22773. lj: 0x01C9,
  22774. ljecyrillic: 0x0459,
  22775. ll: 0xF6C0,
  22776. lladeva: 0x0933,
  22777. llagujarati: 0x0AB3,
  22778. llinebelow: 0x1E3B,
  22779. llladeva: 0x0934,
  22780. llvocalicbengali: 0x09E1,
  22781. llvocalicdeva: 0x0961,
  22782. llvocalicvowelsignbengali: 0x09E3,
  22783. llvocalicvowelsigndeva: 0x0963,
  22784. lmiddletilde: 0x026B,
  22785. lmonospace: 0xFF4C,
  22786. lmsquare: 0x33D0,
  22787. lochulathai: 0x0E2C,
  22788. logicaland: 0x2227,
  22789. logicalnot: 0x00AC,
  22790. logicalnotreversed: 0x2310,
  22791. logicalor: 0x2228,
  22792. lolingthai: 0x0E25,
  22793. longs: 0x017F,
  22794. lowlinecenterline: 0xFE4E,
  22795. lowlinecmb: 0x0332,
  22796. lowlinedashed: 0xFE4D,
  22797. lozenge: 0x25CA,
  22798. lparen: 0x24A7,
  22799. lslash: 0x0142,
  22800. lsquare: 0x2113,
  22801. lsuperior: 0xF6EE,
  22802. ltshade: 0x2591,
  22803. luthai: 0x0E26,
  22804. lvocalicbengali: 0x098C,
  22805. lvocalicdeva: 0x090C,
  22806. lvocalicvowelsignbengali: 0x09E2,
  22807. lvocalicvowelsigndeva: 0x0962,
  22808. lxsquare: 0x33D3,
  22809. m: 0x006D,
  22810. mabengali: 0x09AE,
  22811. macron: 0x00AF,
  22812. macronbelowcmb: 0x0331,
  22813. macroncmb: 0x0304,
  22814. macronlowmod: 0x02CD,
  22815. macronmonospace: 0xFFE3,
  22816. macute: 0x1E3F,
  22817. madeva: 0x092E,
  22818. magujarati: 0x0AAE,
  22819. magurmukhi: 0x0A2E,
  22820. mahapakhhebrew: 0x05A4,
  22821. mahapakhlefthebrew: 0x05A4,
  22822. mahiragana: 0x307E,
  22823. maichattawalowleftthai: 0xF895,
  22824. maichattawalowrightthai: 0xF894,
  22825. maichattawathai: 0x0E4B,
  22826. maichattawaupperleftthai: 0xF893,
  22827. maieklowleftthai: 0xF88C,
  22828. maieklowrightthai: 0xF88B,
  22829. maiekthai: 0x0E48,
  22830. maiekupperleftthai: 0xF88A,
  22831. maihanakatleftthai: 0xF884,
  22832. maihanakatthai: 0x0E31,
  22833. maitaikhuleftthai: 0xF889,
  22834. maitaikhuthai: 0x0E47,
  22835. maitholowleftthai: 0xF88F,
  22836. maitholowrightthai: 0xF88E,
  22837. maithothai: 0x0E49,
  22838. maithoupperleftthai: 0xF88D,
  22839. maitrilowleftthai: 0xF892,
  22840. maitrilowrightthai: 0xF891,
  22841. maitrithai: 0x0E4A,
  22842. maitriupperleftthai: 0xF890,
  22843. maiyamokthai: 0x0E46,
  22844. makatakana: 0x30DE,
  22845. makatakanahalfwidth: 0xFF8F,
  22846. male: 0x2642,
  22847. mansyonsquare: 0x3347,
  22848. maqafhebrew: 0x05BE,
  22849. mars: 0x2642,
  22850. masoracirclehebrew: 0x05AF,
  22851. masquare: 0x3383,
  22852. mbopomofo: 0x3107,
  22853. mbsquare: 0x33D4,
  22854. mcircle: 0x24DC,
  22855. mcubedsquare: 0x33A5,
  22856. mdotaccent: 0x1E41,
  22857. mdotbelow: 0x1E43,
  22858. meemarabic: 0x0645,
  22859. meemfinalarabic: 0xFEE2,
  22860. meeminitialarabic: 0xFEE3,
  22861. meemmedialarabic: 0xFEE4,
  22862. meemmeeminitialarabic: 0xFCD1,
  22863. meemmeemisolatedarabic: 0xFC48,
  22864. meetorusquare: 0x334D,
  22865. mehiragana: 0x3081,
  22866. meizierasquare: 0x337E,
  22867. mekatakana: 0x30E1,
  22868. mekatakanahalfwidth: 0xFF92,
  22869. mem: 0x05DE,
  22870. memdagesh: 0xFB3E,
  22871. memdageshhebrew: 0xFB3E,
  22872. memhebrew: 0x05DE,
  22873. menarmenian: 0x0574,
  22874. merkhahebrew: 0x05A5,
  22875. merkhakefulahebrew: 0x05A6,
  22876. merkhakefulalefthebrew: 0x05A6,
  22877. merkhalefthebrew: 0x05A5,
  22878. mhook: 0x0271,
  22879. mhzsquare: 0x3392,
  22880. middledotkatakanahalfwidth: 0xFF65,
  22881. middot: 0x00B7,
  22882. mieumacirclekorean: 0x3272,
  22883. mieumaparenkorean: 0x3212,
  22884. mieumcirclekorean: 0x3264,
  22885. mieumkorean: 0x3141,
  22886. mieumpansioskorean: 0x3170,
  22887. mieumparenkorean: 0x3204,
  22888. mieumpieupkorean: 0x316E,
  22889. mieumsioskorean: 0x316F,
  22890. mihiragana: 0x307F,
  22891. mikatakana: 0x30DF,
  22892. mikatakanahalfwidth: 0xFF90,
  22893. minus: 0x2212,
  22894. minusbelowcmb: 0x0320,
  22895. minuscircle: 0x2296,
  22896. minusmod: 0x02D7,
  22897. minusplus: 0x2213,
  22898. minute: 0x2032,
  22899. miribaarusquare: 0x334A,
  22900. mirisquare: 0x3349,
  22901. mlonglegturned: 0x0270,
  22902. mlsquare: 0x3396,
  22903. mmcubedsquare: 0x33A3,
  22904. mmonospace: 0xFF4D,
  22905. mmsquaredsquare: 0x339F,
  22906. mohiragana: 0x3082,
  22907. mohmsquare: 0x33C1,
  22908. mokatakana: 0x30E2,
  22909. mokatakanahalfwidth: 0xFF93,
  22910. molsquare: 0x33D6,
  22911. momathai: 0x0E21,
  22912. moverssquare: 0x33A7,
  22913. moverssquaredsquare: 0x33A8,
  22914. mparen: 0x24A8,
  22915. mpasquare: 0x33AB,
  22916. mssquare: 0x33B3,
  22917. msuperior: 0xF6EF,
  22918. mturned: 0x026F,
  22919. mu: 0x00B5,
  22920. mu1: 0x00B5,
  22921. muasquare: 0x3382,
  22922. muchgreater: 0x226B,
  22923. muchless: 0x226A,
  22924. mufsquare: 0x338C,
  22925. mugreek: 0x03BC,
  22926. mugsquare: 0x338D,
  22927. muhiragana: 0x3080,
  22928. mukatakana: 0x30E0,
  22929. mukatakanahalfwidth: 0xFF91,
  22930. mulsquare: 0x3395,
  22931. multiply: 0x00D7,
  22932. mumsquare: 0x339B,
  22933. munahhebrew: 0x05A3,
  22934. munahlefthebrew: 0x05A3,
  22935. musicalnote: 0x266A,
  22936. musicalnotedbl: 0x266B,
  22937. musicflatsign: 0x266D,
  22938. musicsharpsign: 0x266F,
  22939. mussquare: 0x33B2,
  22940. muvsquare: 0x33B6,
  22941. muwsquare: 0x33BC,
  22942. mvmegasquare: 0x33B9,
  22943. mvsquare: 0x33B7,
  22944. mwmegasquare: 0x33BF,
  22945. mwsquare: 0x33BD,
  22946. n: 0x006E,
  22947. nabengali: 0x09A8,
  22948. nabla: 0x2207,
  22949. nacute: 0x0144,
  22950. nadeva: 0x0928,
  22951. nagujarati: 0x0AA8,
  22952. nagurmukhi: 0x0A28,
  22953. nahiragana: 0x306A,
  22954. nakatakana: 0x30CA,
  22955. nakatakanahalfwidth: 0xFF85,
  22956. napostrophe: 0x0149,
  22957. nasquare: 0x3381,
  22958. nbopomofo: 0x310B,
  22959. nbspace: 0x00A0,
  22960. ncaron: 0x0148,
  22961. ncedilla: 0x0146,
  22962. ncircle: 0x24DD,
  22963. ncircumflexbelow: 0x1E4B,
  22964. ncommaaccent: 0x0146,
  22965. ndotaccent: 0x1E45,
  22966. ndotbelow: 0x1E47,
  22967. nehiragana: 0x306D,
  22968. nekatakana: 0x30CD,
  22969. nekatakanahalfwidth: 0xFF88,
  22970. newsheqelsign: 0x20AA,
  22971. nfsquare: 0x338B,
  22972. ngabengali: 0x0999,
  22973. ngadeva: 0x0919,
  22974. ngagujarati: 0x0A99,
  22975. ngagurmukhi: 0x0A19,
  22976. ngonguthai: 0x0E07,
  22977. nhiragana: 0x3093,
  22978. nhookleft: 0x0272,
  22979. nhookretroflex: 0x0273,
  22980. nieunacirclekorean: 0x326F,
  22981. nieunaparenkorean: 0x320F,
  22982. nieuncieuckorean: 0x3135,
  22983. nieuncirclekorean: 0x3261,
  22984. nieunhieuhkorean: 0x3136,
  22985. nieunkorean: 0x3134,
  22986. nieunpansioskorean: 0x3168,
  22987. nieunparenkorean: 0x3201,
  22988. nieunsioskorean: 0x3167,
  22989. nieuntikeutkorean: 0x3166,
  22990. nihiragana: 0x306B,
  22991. nikatakana: 0x30CB,
  22992. nikatakanahalfwidth: 0xFF86,
  22993. nikhahitleftthai: 0xF899,
  22994. nikhahitthai: 0x0E4D,
  22995. nine: 0x0039,
  22996. ninearabic: 0x0669,
  22997. ninebengali: 0x09EF,
  22998. ninecircle: 0x2468,
  22999. ninecircleinversesansserif: 0x2792,
  23000. ninedeva: 0x096F,
  23001. ninegujarati: 0x0AEF,
  23002. ninegurmukhi: 0x0A6F,
  23003. ninehackarabic: 0x0669,
  23004. ninehangzhou: 0x3029,
  23005. nineideographicparen: 0x3228,
  23006. nineinferior: 0x2089,
  23007. ninemonospace: 0xFF19,
  23008. nineoldstyle: 0xF739,
  23009. nineparen: 0x247C,
  23010. nineperiod: 0x2490,
  23011. ninepersian: 0x06F9,
  23012. nineroman: 0x2178,
  23013. ninesuperior: 0x2079,
  23014. nineteencircle: 0x2472,
  23015. nineteenparen: 0x2486,
  23016. nineteenperiod: 0x249A,
  23017. ninethai: 0x0E59,
  23018. nj: 0x01CC,
  23019. njecyrillic: 0x045A,
  23020. nkatakana: 0x30F3,
  23021. nkatakanahalfwidth: 0xFF9D,
  23022. nlegrightlong: 0x019E,
  23023. nlinebelow: 0x1E49,
  23024. nmonospace: 0xFF4E,
  23025. nmsquare: 0x339A,
  23026. nnabengali: 0x09A3,
  23027. nnadeva: 0x0923,
  23028. nnagujarati: 0x0AA3,
  23029. nnagurmukhi: 0x0A23,
  23030. nnnadeva: 0x0929,
  23031. nohiragana: 0x306E,
  23032. nokatakana: 0x30CE,
  23033. nokatakanahalfwidth: 0xFF89,
  23034. nonbreakingspace: 0x00A0,
  23035. nonenthai: 0x0E13,
  23036. nonuthai: 0x0E19,
  23037. noonarabic: 0x0646,
  23038. noonfinalarabic: 0xFEE6,
  23039. noonghunnaarabic: 0x06BA,
  23040. noonghunnafinalarabic: 0xFB9F,
  23041. nooninitialarabic: 0xFEE7,
  23042. noonjeeminitialarabic: 0xFCD2,
  23043. noonjeemisolatedarabic: 0xFC4B,
  23044. noonmedialarabic: 0xFEE8,
  23045. noonmeeminitialarabic: 0xFCD5,
  23046. noonmeemisolatedarabic: 0xFC4E,
  23047. noonnoonfinalarabic: 0xFC8D,
  23048. notcontains: 0x220C,
  23049. notelement: 0x2209,
  23050. notelementof: 0x2209,
  23051. notequal: 0x2260,
  23052. notgreater: 0x226F,
  23053. notgreaternorequal: 0x2271,
  23054. notgreaternorless: 0x2279,
  23055. notidentical: 0x2262,
  23056. notless: 0x226E,
  23057. notlessnorequal: 0x2270,
  23058. notparallel: 0x2226,
  23059. notprecedes: 0x2280,
  23060. notsubset: 0x2284,
  23061. notsucceeds: 0x2281,
  23062. notsuperset: 0x2285,
  23063. nowarmenian: 0x0576,
  23064. nparen: 0x24A9,
  23065. nssquare: 0x33B1,
  23066. nsuperior: 0x207F,
  23067. ntilde: 0x00F1,
  23068. nu: 0x03BD,
  23069. nuhiragana: 0x306C,
  23070. nukatakana: 0x30CC,
  23071. nukatakanahalfwidth: 0xFF87,
  23072. nuktabengali: 0x09BC,
  23073. nuktadeva: 0x093C,
  23074. nuktagujarati: 0x0ABC,
  23075. nuktagurmukhi: 0x0A3C,
  23076. numbersign: 0x0023,
  23077. numbersignmonospace: 0xFF03,
  23078. numbersignsmall: 0xFE5F,
  23079. numeralsigngreek: 0x0374,
  23080. numeralsignlowergreek: 0x0375,
  23081. numero: 0x2116,
  23082. nun: 0x05E0,
  23083. nundagesh: 0xFB40,
  23084. nundageshhebrew: 0xFB40,
  23085. nunhebrew: 0x05E0,
  23086. nvsquare: 0x33B5,
  23087. nwsquare: 0x33BB,
  23088. nyabengali: 0x099E,
  23089. nyadeva: 0x091E,
  23090. nyagujarati: 0x0A9E,
  23091. nyagurmukhi: 0x0A1E,
  23092. o: 0x006F,
  23093. oacute: 0x00F3,
  23094. oangthai: 0x0E2D,
  23095. obarred: 0x0275,
  23096. obarredcyrillic: 0x04E9,
  23097. obarreddieresiscyrillic: 0x04EB,
  23098. obengali: 0x0993,
  23099. obopomofo: 0x311B,
  23100. obreve: 0x014F,
  23101. ocandradeva: 0x0911,
  23102. ocandragujarati: 0x0A91,
  23103. ocandravowelsigndeva: 0x0949,
  23104. ocandravowelsigngujarati: 0x0AC9,
  23105. ocaron: 0x01D2,
  23106. ocircle: 0x24DE,
  23107. ocircumflex: 0x00F4,
  23108. ocircumflexacute: 0x1ED1,
  23109. ocircumflexdotbelow: 0x1ED9,
  23110. ocircumflexgrave: 0x1ED3,
  23111. ocircumflexhookabove: 0x1ED5,
  23112. ocircumflextilde: 0x1ED7,
  23113. ocyrillic: 0x043E,
  23114. odblacute: 0x0151,
  23115. odblgrave: 0x020D,
  23116. odeva: 0x0913,
  23117. odieresis: 0x00F6,
  23118. odieresiscyrillic: 0x04E7,
  23119. odotbelow: 0x1ECD,
  23120. oe: 0x0153,
  23121. oekorean: 0x315A,
  23122. ogonek: 0x02DB,
  23123. ogonekcmb: 0x0328,
  23124. ograve: 0x00F2,
  23125. ogujarati: 0x0A93,
  23126. oharmenian: 0x0585,
  23127. ohiragana: 0x304A,
  23128. ohookabove: 0x1ECF,
  23129. ohorn: 0x01A1,
  23130. ohornacute: 0x1EDB,
  23131. ohorndotbelow: 0x1EE3,
  23132. ohorngrave: 0x1EDD,
  23133. ohornhookabove: 0x1EDF,
  23134. ohorntilde: 0x1EE1,
  23135. ohungarumlaut: 0x0151,
  23136. oi: 0x01A3,
  23137. oinvertedbreve: 0x020F,
  23138. okatakana: 0x30AA,
  23139. okatakanahalfwidth: 0xFF75,
  23140. okorean: 0x3157,
  23141. olehebrew: 0x05AB,
  23142. omacron: 0x014D,
  23143. omacronacute: 0x1E53,
  23144. omacrongrave: 0x1E51,
  23145. omdeva: 0x0950,
  23146. omega: 0x03C9,
  23147. omega1: 0x03D6,
  23148. omegacyrillic: 0x0461,
  23149. omegalatinclosed: 0x0277,
  23150. omegaroundcyrillic: 0x047B,
  23151. omegatitlocyrillic: 0x047D,
  23152. omegatonos: 0x03CE,
  23153. omgujarati: 0x0AD0,
  23154. omicron: 0x03BF,
  23155. omicrontonos: 0x03CC,
  23156. omonospace: 0xFF4F,
  23157. one: 0x0031,
  23158. onearabic: 0x0661,
  23159. onebengali: 0x09E7,
  23160. onecircle: 0x2460,
  23161. onecircleinversesansserif: 0x278A,
  23162. onedeva: 0x0967,
  23163. onedotenleader: 0x2024,
  23164. oneeighth: 0x215B,
  23165. onefitted: 0xF6DC,
  23166. onegujarati: 0x0AE7,
  23167. onegurmukhi: 0x0A67,
  23168. onehackarabic: 0x0661,
  23169. onehalf: 0x00BD,
  23170. onehangzhou: 0x3021,
  23171. oneideographicparen: 0x3220,
  23172. oneinferior: 0x2081,
  23173. onemonospace: 0xFF11,
  23174. onenumeratorbengali: 0x09F4,
  23175. oneoldstyle: 0xF731,
  23176. oneparen: 0x2474,
  23177. oneperiod: 0x2488,
  23178. onepersian: 0x06F1,
  23179. onequarter: 0x00BC,
  23180. oneroman: 0x2170,
  23181. onesuperior: 0x00B9,
  23182. onethai: 0x0E51,
  23183. onethird: 0x2153,
  23184. oogonek: 0x01EB,
  23185. oogonekmacron: 0x01ED,
  23186. oogurmukhi: 0x0A13,
  23187. oomatragurmukhi: 0x0A4B,
  23188. oopen: 0x0254,
  23189. oparen: 0x24AA,
  23190. openbullet: 0x25E6,
  23191. option: 0x2325,
  23192. ordfeminine: 0x00AA,
  23193. ordmasculine: 0x00BA,
  23194. orthogonal: 0x221F,
  23195. oshortdeva: 0x0912,
  23196. oshortvowelsigndeva: 0x094A,
  23197. oslash: 0x00F8,
  23198. oslashacute: 0x01FF,
  23199. osmallhiragana: 0x3049,
  23200. osmallkatakana: 0x30A9,
  23201. osmallkatakanahalfwidth: 0xFF6B,
  23202. ostrokeacute: 0x01FF,
  23203. osuperior: 0xF6F0,
  23204. otcyrillic: 0x047F,
  23205. otilde: 0x00F5,
  23206. otildeacute: 0x1E4D,
  23207. otildedieresis: 0x1E4F,
  23208. oubopomofo: 0x3121,
  23209. overline: 0x203E,
  23210. overlinecenterline: 0xFE4A,
  23211. overlinecmb: 0x0305,
  23212. overlinedashed: 0xFE49,
  23213. overlinedblwavy: 0xFE4C,
  23214. overlinewavy: 0xFE4B,
  23215. overscore: 0x00AF,
  23216. ovowelsignbengali: 0x09CB,
  23217. ovowelsigndeva: 0x094B,
  23218. ovowelsigngujarati: 0x0ACB,
  23219. p: 0x0070,
  23220. paampssquare: 0x3380,
  23221. paasentosquare: 0x332B,
  23222. pabengali: 0x09AA,
  23223. pacute: 0x1E55,
  23224. padeva: 0x092A,
  23225. pagedown: 0x21DF,
  23226. pageup: 0x21DE,
  23227. pagujarati: 0x0AAA,
  23228. pagurmukhi: 0x0A2A,
  23229. pahiragana: 0x3071,
  23230. paiyannoithai: 0x0E2F,
  23231. pakatakana: 0x30D1,
  23232. palatalizationcyrilliccmb: 0x0484,
  23233. palochkacyrillic: 0x04C0,
  23234. pansioskorean: 0x317F,
  23235. paragraph: 0x00B6,
  23236. parallel: 0x2225,
  23237. parenleft: 0x0028,
  23238. parenleftaltonearabic: 0xFD3E,
  23239. parenleftbt: 0xF8ED,
  23240. parenleftex: 0xF8EC,
  23241. parenleftinferior: 0x208D,
  23242. parenleftmonospace: 0xFF08,
  23243. parenleftsmall: 0xFE59,
  23244. parenleftsuperior: 0x207D,
  23245. parenlefttp: 0xF8EB,
  23246. parenleftvertical: 0xFE35,
  23247. parenright: 0x0029,
  23248. parenrightaltonearabic: 0xFD3F,
  23249. parenrightbt: 0xF8F8,
  23250. parenrightex: 0xF8F7,
  23251. parenrightinferior: 0x208E,
  23252. parenrightmonospace: 0xFF09,
  23253. parenrightsmall: 0xFE5A,
  23254. parenrightsuperior: 0x207E,
  23255. parenrighttp: 0xF8F6,
  23256. parenrightvertical: 0xFE36,
  23257. partialdiff: 0x2202,
  23258. paseqhebrew: 0x05C0,
  23259. pashtahebrew: 0x0599,
  23260. pasquare: 0x33A9,
  23261. patah: 0x05B7,
  23262. patah11: 0x05B7,
  23263. patah1d: 0x05B7,
  23264. patah2a: 0x05B7,
  23265. patahhebrew: 0x05B7,
  23266. patahnarrowhebrew: 0x05B7,
  23267. patahquarterhebrew: 0x05B7,
  23268. patahwidehebrew: 0x05B7,
  23269. pazerhebrew: 0x05A1,
  23270. pbopomofo: 0x3106,
  23271. pcircle: 0x24DF,
  23272. pdotaccent: 0x1E57,
  23273. pe: 0x05E4,
  23274. pecyrillic: 0x043F,
  23275. pedagesh: 0xFB44,
  23276. pedageshhebrew: 0xFB44,
  23277. peezisquare: 0x333B,
  23278. pefinaldageshhebrew: 0xFB43,
  23279. peharabic: 0x067E,
  23280. peharmenian: 0x057A,
  23281. pehebrew: 0x05E4,
  23282. pehfinalarabic: 0xFB57,
  23283. pehinitialarabic: 0xFB58,
  23284. pehiragana: 0x307A,
  23285. pehmedialarabic: 0xFB59,
  23286. pekatakana: 0x30DA,
  23287. pemiddlehookcyrillic: 0x04A7,
  23288. perafehebrew: 0xFB4E,
  23289. percent: 0x0025,
  23290. percentarabic: 0x066A,
  23291. percentmonospace: 0xFF05,
  23292. percentsmall: 0xFE6A,
  23293. period: 0x002E,
  23294. periodarmenian: 0x0589,
  23295. periodcentered: 0x00B7,
  23296. periodhalfwidth: 0xFF61,
  23297. periodinferior: 0xF6E7,
  23298. periodmonospace: 0xFF0E,
  23299. periodsmall: 0xFE52,
  23300. periodsuperior: 0xF6E8,
  23301. perispomenigreekcmb: 0x0342,
  23302. perpendicular: 0x22A5,
  23303. perthousand: 0x2030,
  23304. peseta: 0x20A7,
  23305. pfsquare: 0x338A,
  23306. phabengali: 0x09AB,
  23307. phadeva: 0x092B,
  23308. phagujarati: 0x0AAB,
  23309. phagurmukhi: 0x0A2B,
  23310. phi: 0x03C6,
  23311. phi1: 0x03D5,
  23312. phieuphacirclekorean: 0x327A,
  23313. phieuphaparenkorean: 0x321A,
  23314. phieuphcirclekorean: 0x326C,
  23315. phieuphkorean: 0x314D,
  23316. phieuphparenkorean: 0x320C,
  23317. philatin: 0x0278,
  23318. phinthuthai: 0x0E3A,
  23319. phisymbolgreek: 0x03D5,
  23320. phook: 0x01A5,
  23321. phophanthai: 0x0E1E,
  23322. phophungthai: 0x0E1C,
  23323. phosamphaothai: 0x0E20,
  23324. pi: 0x03C0,
  23325. pieupacirclekorean: 0x3273,
  23326. pieupaparenkorean: 0x3213,
  23327. pieupcieuckorean: 0x3176,
  23328. pieupcirclekorean: 0x3265,
  23329. pieupkiyeokkorean: 0x3172,
  23330. pieupkorean: 0x3142,
  23331. pieupparenkorean: 0x3205,
  23332. pieupsioskiyeokkorean: 0x3174,
  23333. pieupsioskorean: 0x3144,
  23334. pieupsiostikeutkorean: 0x3175,
  23335. pieupthieuthkorean: 0x3177,
  23336. pieuptikeutkorean: 0x3173,
  23337. pihiragana: 0x3074,
  23338. pikatakana: 0x30D4,
  23339. pisymbolgreek: 0x03D6,
  23340. piwrarmenian: 0x0583,
  23341. plus: 0x002B,
  23342. plusbelowcmb: 0x031F,
  23343. pluscircle: 0x2295,
  23344. plusminus: 0x00B1,
  23345. plusmod: 0x02D6,
  23346. plusmonospace: 0xFF0B,
  23347. plussmall: 0xFE62,
  23348. plussuperior: 0x207A,
  23349. pmonospace: 0xFF50,
  23350. pmsquare: 0x33D8,
  23351. pohiragana: 0x307D,
  23352. pointingindexdownwhite: 0x261F,
  23353. pointingindexleftwhite: 0x261C,
  23354. pointingindexrightwhite: 0x261E,
  23355. pointingindexupwhite: 0x261D,
  23356. pokatakana: 0x30DD,
  23357. poplathai: 0x0E1B,
  23358. postalmark: 0x3012,
  23359. postalmarkface: 0x3020,
  23360. pparen: 0x24AB,
  23361. precedes: 0x227A,
  23362. prescription: 0x211E,
  23363. primemod: 0x02B9,
  23364. primereversed: 0x2035,
  23365. product: 0x220F,
  23366. projective: 0x2305,
  23367. prolongedkana: 0x30FC,
  23368. propellor: 0x2318,
  23369. propersubset: 0x2282,
  23370. propersuperset: 0x2283,
  23371. proportion: 0x2237,
  23372. proportional: 0x221D,
  23373. psi: 0x03C8,
  23374. psicyrillic: 0x0471,
  23375. psilipneumatacyrilliccmb: 0x0486,
  23376. pssquare: 0x33B0,
  23377. puhiragana: 0x3077,
  23378. pukatakana: 0x30D7,
  23379. pvsquare: 0x33B4,
  23380. pwsquare: 0x33BA,
  23381. q: 0x0071,
  23382. qadeva: 0x0958,
  23383. qadmahebrew: 0x05A8,
  23384. qafarabic: 0x0642,
  23385. qaffinalarabic: 0xFED6,
  23386. qafinitialarabic: 0xFED7,
  23387. qafmedialarabic: 0xFED8,
  23388. qamats: 0x05B8,
  23389. qamats10: 0x05B8,
  23390. qamats1a: 0x05B8,
  23391. qamats1c: 0x05B8,
  23392. qamats27: 0x05B8,
  23393. qamats29: 0x05B8,
  23394. qamats33: 0x05B8,
  23395. qamatsde: 0x05B8,
  23396. qamatshebrew: 0x05B8,
  23397. qamatsnarrowhebrew: 0x05B8,
  23398. qamatsqatanhebrew: 0x05B8,
  23399. qamatsqatannarrowhebrew: 0x05B8,
  23400. qamatsqatanquarterhebrew: 0x05B8,
  23401. qamatsqatanwidehebrew: 0x05B8,
  23402. qamatsquarterhebrew: 0x05B8,
  23403. qamatswidehebrew: 0x05B8,
  23404. qarneyparahebrew: 0x059F,
  23405. qbopomofo: 0x3111,
  23406. qcircle: 0x24E0,
  23407. qhook: 0x02A0,
  23408. qmonospace: 0xFF51,
  23409. qof: 0x05E7,
  23410. qofdagesh: 0xFB47,
  23411. qofdageshhebrew: 0xFB47,
  23412. qofhebrew: 0x05E7,
  23413. qparen: 0x24AC,
  23414. quarternote: 0x2669,
  23415. qubuts: 0x05BB,
  23416. qubuts18: 0x05BB,
  23417. qubuts25: 0x05BB,
  23418. qubuts31: 0x05BB,
  23419. qubutshebrew: 0x05BB,
  23420. qubutsnarrowhebrew: 0x05BB,
  23421. qubutsquarterhebrew: 0x05BB,
  23422. qubutswidehebrew: 0x05BB,
  23423. question: 0x003F,
  23424. questionarabic: 0x061F,
  23425. questionarmenian: 0x055E,
  23426. questiondown: 0x00BF,
  23427. questiondownsmall: 0xF7BF,
  23428. questiongreek: 0x037E,
  23429. questionmonospace: 0xFF1F,
  23430. questionsmall: 0xF73F,
  23431. quotedbl: 0x0022,
  23432. quotedblbase: 0x201E,
  23433. quotedblleft: 0x201C,
  23434. quotedblmonospace: 0xFF02,
  23435. quotedblprime: 0x301E,
  23436. quotedblprimereversed: 0x301D,
  23437. quotedblright: 0x201D,
  23438. quoteleft: 0x2018,
  23439. quoteleftreversed: 0x201B,
  23440. quotereversed: 0x201B,
  23441. quoteright: 0x2019,
  23442. quoterightn: 0x0149,
  23443. quotesinglbase: 0x201A,
  23444. quotesingle: 0x0027,
  23445. quotesinglemonospace: 0xFF07,
  23446. r: 0x0072,
  23447. raarmenian: 0x057C,
  23448. rabengali: 0x09B0,
  23449. racute: 0x0155,
  23450. radeva: 0x0930,
  23451. radical: 0x221A,
  23452. radicalex: 0xF8E5,
  23453. radoverssquare: 0x33AE,
  23454. radoverssquaredsquare: 0x33AF,
  23455. radsquare: 0x33AD,
  23456. rafe: 0x05BF,
  23457. rafehebrew: 0x05BF,
  23458. ragujarati: 0x0AB0,
  23459. ragurmukhi: 0x0A30,
  23460. rahiragana: 0x3089,
  23461. rakatakana: 0x30E9,
  23462. rakatakanahalfwidth: 0xFF97,
  23463. ralowerdiagonalbengali: 0x09F1,
  23464. ramiddlediagonalbengali: 0x09F0,
  23465. ramshorn: 0x0264,
  23466. ratio: 0x2236,
  23467. rbopomofo: 0x3116,
  23468. rcaron: 0x0159,
  23469. rcedilla: 0x0157,
  23470. rcircle: 0x24E1,
  23471. rcommaaccent: 0x0157,
  23472. rdblgrave: 0x0211,
  23473. rdotaccent: 0x1E59,
  23474. rdotbelow: 0x1E5B,
  23475. rdotbelowmacron: 0x1E5D,
  23476. referencemark: 0x203B,
  23477. reflexsubset: 0x2286,
  23478. reflexsuperset: 0x2287,
  23479. registered: 0x00AE,
  23480. registersans: 0xF8E8,
  23481. registerserif: 0xF6DA,
  23482. reharabic: 0x0631,
  23483. reharmenian: 0x0580,
  23484. rehfinalarabic: 0xFEAE,
  23485. rehiragana: 0x308C,
  23486. rekatakana: 0x30EC,
  23487. rekatakanahalfwidth: 0xFF9A,
  23488. resh: 0x05E8,
  23489. reshdageshhebrew: 0xFB48,
  23490. reshhebrew: 0x05E8,
  23491. reversedtilde: 0x223D,
  23492. reviahebrew: 0x0597,
  23493. reviamugrashhebrew: 0x0597,
  23494. revlogicalnot: 0x2310,
  23495. rfishhook: 0x027E,
  23496. rfishhookreversed: 0x027F,
  23497. rhabengali: 0x09DD,
  23498. rhadeva: 0x095D,
  23499. rho: 0x03C1,
  23500. rhook: 0x027D,
  23501. rhookturned: 0x027B,
  23502. rhookturnedsuperior: 0x02B5,
  23503. rhosymbolgreek: 0x03F1,
  23504. rhotichookmod: 0x02DE,
  23505. rieulacirclekorean: 0x3271,
  23506. rieulaparenkorean: 0x3211,
  23507. rieulcirclekorean: 0x3263,
  23508. rieulhieuhkorean: 0x3140,
  23509. rieulkiyeokkorean: 0x313A,
  23510. rieulkiyeoksioskorean: 0x3169,
  23511. rieulkorean: 0x3139,
  23512. rieulmieumkorean: 0x313B,
  23513. rieulpansioskorean: 0x316C,
  23514. rieulparenkorean: 0x3203,
  23515. rieulphieuphkorean: 0x313F,
  23516. rieulpieupkorean: 0x313C,
  23517. rieulpieupsioskorean: 0x316B,
  23518. rieulsioskorean: 0x313D,
  23519. rieulthieuthkorean: 0x313E,
  23520. rieultikeutkorean: 0x316A,
  23521. rieulyeorinhieuhkorean: 0x316D,
  23522. rightangle: 0x221F,
  23523. righttackbelowcmb: 0x0319,
  23524. righttriangle: 0x22BF,
  23525. rihiragana: 0x308A,
  23526. rikatakana: 0x30EA,
  23527. rikatakanahalfwidth: 0xFF98,
  23528. ring: 0x02DA,
  23529. ringbelowcmb: 0x0325,
  23530. ringcmb: 0x030A,
  23531. ringhalfleft: 0x02BF,
  23532. ringhalfleftarmenian: 0x0559,
  23533. ringhalfleftbelowcmb: 0x031C,
  23534. ringhalfleftcentered: 0x02D3,
  23535. ringhalfright: 0x02BE,
  23536. ringhalfrightbelowcmb: 0x0339,
  23537. ringhalfrightcentered: 0x02D2,
  23538. rinvertedbreve: 0x0213,
  23539. rittorusquare: 0x3351,
  23540. rlinebelow: 0x1E5F,
  23541. rlongleg: 0x027C,
  23542. rlonglegturned: 0x027A,
  23543. rmonospace: 0xFF52,
  23544. rohiragana: 0x308D,
  23545. rokatakana: 0x30ED,
  23546. rokatakanahalfwidth: 0xFF9B,
  23547. roruathai: 0x0E23,
  23548. rparen: 0x24AD,
  23549. rrabengali: 0x09DC,
  23550. rradeva: 0x0931,
  23551. rragurmukhi: 0x0A5C,
  23552. rreharabic: 0x0691,
  23553. rrehfinalarabic: 0xFB8D,
  23554. rrvocalicbengali: 0x09E0,
  23555. rrvocalicdeva: 0x0960,
  23556. rrvocalicgujarati: 0x0AE0,
  23557. rrvocalicvowelsignbengali: 0x09C4,
  23558. rrvocalicvowelsigndeva: 0x0944,
  23559. rrvocalicvowelsigngujarati: 0x0AC4,
  23560. rsuperior: 0xF6F1,
  23561. rtblock: 0x2590,
  23562. rturned: 0x0279,
  23563. rturnedsuperior: 0x02B4,
  23564. ruhiragana: 0x308B,
  23565. rukatakana: 0x30EB,
  23566. rukatakanahalfwidth: 0xFF99,
  23567. rupeemarkbengali: 0x09F2,
  23568. rupeesignbengali: 0x09F3,
  23569. rupiah: 0xF6DD,
  23570. ruthai: 0x0E24,
  23571. rvocalicbengali: 0x098B,
  23572. rvocalicdeva: 0x090B,
  23573. rvocalicgujarati: 0x0A8B,
  23574. rvocalicvowelsignbengali: 0x09C3,
  23575. rvocalicvowelsigndeva: 0x0943,
  23576. rvocalicvowelsigngujarati: 0x0AC3,
  23577. s: 0x0073,
  23578. sabengali: 0x09B8,
  23579. sacute: 0x015B,
  23580. sacutedotaccent: 0x1E65,
  23581. sadarabic: 0x0635,
  23582. sadeva: 0x0938,
  23583. sadfinalarabic: 0xFEBA,
  23584. sadinitialarabic: 0xFEBB,
  23585. sadmedialarabic: 0xFEBC,
  23586. sagujarati: 0x0AB8,
  23587. sagurmukhi: 0x0A38,
  23588. sahiragana: 0x3055,
  23589. sakatakana: 0x30B5,
  23590. sakatakanahalfwidth: 0xFF7B,
  23591. sallallahoualayhewasallamarabic: 0xFDFA,
  23592. samekh: 0x05E1,
  23593. samekhdagesh: 0xFB41,
  23594. samekhdageshhebrew: 0xFB41,
  23595. samekhhebrew: 0x05E1,
  23596. saraaathai: 0x0E32,
  23597. saraaethai: 0x0E41,
  23598. saraaimaimalaithai: 0x0E44,
  23599. saraaimaimuanthai: 0x0E43,
  23600. saraamthai: 0x0E33,
  23601. saraathai: 0x0E30,
  23602. saraethai: 0x0E40,
  23603. saraiileftthai: 0xF886,
  23604. saraiithai: 0x0E35,
  23605. saraileftthai: 0xF885,
  23606. saraithai: 0x0E34,
  23607. saraothai: 0x0E42,
  23608. saraueeleftthai: 0xF888,
  23609. saraueethai: 0x0E37,
  23610. saraueleftthai: 0xF887,
  23611. sarauethai: 0x0E36,
  23612. sarauthai: 0x0E38,
  23613. sarauuthai: 0x0E39,
  23614. sbopomofo: 0x3119,
  23615. scaron: 0x0161,
  23616. scarondotaccent: 0x1E67,
  23617. scedilla: 0x015F,
  23618. schwa: 0x0259,
  23619. schwacyrillic: 0x04D9,
  23620. schwadieresiscyrillic: 0x04DB,
  23621. schwahook: 0x025A,
  23622. scircle: 0x24E2,
  23623. scircumflex: 0x015D,
  23624. scommaaccent: 0x0219,
  23625. sdotaccent: 0x1E61,
  23626. sdotbelow: 0x1E63,
  23627. sdotbelowdotaccent: 0x1E69,
  23628. seagullbelowcmb: 0x033C,
  23629. second: 0x2033,
  23630. secondtonechinese: 0x02CA,
  23631. section: 0x00A7,
  23632. seenarabic: 0x0633,
  23633. seenfinalarabic: 0xFEB2,
  23634. seeninitialarabic: 0xFEB3,
  23635. seenmedialarabic: 0xFEB4,
  23636. segol: 0x05B6,
  23637. segol13: 0x05B6,
  23638. segol1f: 0x05B6,
  23639. segol2c: 0x05B6,
  23640. segolhebrew: 0x05B6,
  23641. segolnarrowhebrew: 0x05B6,
  23642. segolquarterhebrew: 0x05B6,
  23643. segoltahebrew: 0x0592,
  23644. segolwidehebrew: 0x05B6,
  23645. seharmenian: 0x057D,
  23646. sehiragana: 0x305B,
  23647. sekatakana: 0x30BB,
  23648. sekatakanahalfwidth: 0xFF7E,
  23649. semicolon: 0x003B,
  23650. semicolonarabic: 0x061B,
  23651. semicolonmonospace: 0xFF1B,
  23652. semicolonsmall: 0xFE54,
  23653. semivoicedmarkkana: 0x309C,
  23654. semivoicedmarkkanahalfwidth: 0xFF9F,
  23655. sentisquare: 0x3322,
  23656. sentosquare: 0x3323,
  23657. seven: 0x0037,
  23658. sevenarabic: 0x0667,
  23659. sevenbengali: 0x09ED,
  23660. sevencircle: 0x2466,
  23661. sevencircleinversesansserif: 0x2790,
  23662. sevendeva: 0x096D,
  23663. seveneighths: 0x215E,
  23664. sevengujarati: 0x0AED,
  23665. sevengurmukhi: 0x0A6D,
  23666. sevenhackarabic: 0x0667,
  23667. sevenhangzhou: 0x3027,
  23668. sevenideographicparen: 0x3226,
  23669. seveninferior: 0x2087,
  23670. sevenmonospace: 0xFF17,
  23671. sevenoldstyle: 0xF737,
  23672. sevenparen: 0x247A,
  23673. sevenperiod: 0x248E,
  23674. sevenpersian: 0x06F7,
  23675. sevenroman: 0x2176,
  23676. sevensuperior: 0x2077,
  23677. seventeencircle: 0x2470,
  23678. seventeenparen: 0x2484,
  23679. seventeenperiod: 0x2498,
  23680. seventhai: 0x0E57,
  23681. sfthyphen: 0x00AD,
  23682. shaarmenian: 0x0577,
  23683. shabengali: 0x09B6,
  23684. shacyrillic: 0x0448,
  23685. shaddaarabic: 0x0651,
  23686. shaddadammaarabic: 0xFC61,
  23687. shaddadammatanarabic: 0xFC5E,
  23688. shaddafathaarabic: 0xFC60,
  23689. shaddakasraarabic: 0xFC62,
  23690. shaddakasratanarabic: 0xFC5F,
  23691. shade: 0x2592,
  23692. shadedark: 0x2593,
  23693. shadelight: 0x2591,
  23694. shademedium: 0x2592,
  23695. shadeva: 0x0936,
  23696. shagujarati: 0x0AB6,
  23697. shagurmukhi: 0x0A36,
  23698. shalshelethebrew: 0x0593,
  23699. shbopomofo: 0x3115,
  23700. shchacyrillic: 0x0449,
  23701. sheenarabic: 0x0634,
  23702. sheenfinalarabic: 0xFEB6,
  23703. sheeninitialarabic: 0xFEB7,
  23704. sheenmedialarabic: 0xFEB8,
  23705. sheicoptic: 0x03E3,
  23706. sheqel: 0x20AA,
  23707. sheqelhebrew: 0x20AA,
  23708. sheva: 0x05B0,
  23709. sheva115: 0x05B0,
  23710. sheva15: 0x05B0,
  23711. sheva22: 0x05B0,
  23712. sheva2e: 0x05B0,
  23713. shevahebrew: 0x05B0,
  23714. shevanarrowhebrew: 0x05B0,
  23715. shevaquarterhebrew: 0x05B0,
  23716. shevawidehebrew: 0x05B0,
  23717. shhacyrillic: 0x04BB,
  23718. shimacoptic: 0x03ED,
  23719. shin: 0x05E9,
  23720. shindagesh: 0xFB49,
  23721. shindageshhebrew: 0xFB49,
  23722. shindageshshindot: 0xFB2C,
  23723. shindageshshindothebrew: 0xFB2C,
  23724. shindageshsindot: 0xFB2D,
  23725. shindageshsindothebrew: 0xFB2D,
  23726. shindothebrew: 0x05C1,
  23727. shinhebrew: 0x05E9,
  23728. shinshindot: 0xFB2A,
  23729. shinshindothebrew: 0xFB2A,
  23730. shinsindot: 0xFB2B,
  23731. shinsindothebrew: 0xFB2B,
  23732. shook: 0x0282,
  23733. sigma: 0x03C3,
  23734. sigma1: 0x03C2,
  23735. sigmafinal: 0x03C2,
  23736. sigmalunatesymbolgreek: 0x03F2,
  23737. sihiragana: 0x3057,
  23738. sikatakana: 0x30B7,
  23739. sikatakanahalfwidth: 0xFF7C,
  23740. siluqhebrew: 0x05BD,
  23741. siluqlefthebrew: 0x05BD,
  23742. similar: 0x223C,
  23743. sindothebrew: 0x05C2,
  23744. siosacirclekorean: 0x3274,
  23745. siosaparenkorean: 0x3214,
  23746. sioscieuckorean: 0x317E,
  23747. sioscirclekorean: 0x3266,
  23748. sioskiyeokkorean: 0x317A,
  23749. sioskorean: 0x3145,
  23750. siosnieunkorean: 0x317B,
  23751. siosparenkorean: 0x3206,
  23752. siospieupkorean: 0x317D,
  23753. siostikeutkorean: 0x317C,
  23754. six: 0x0036,
  23755. sixarabic: 0x0666,
  23756. sixbengali: 0x09EC,
  23757. sixcircle: 0x2465,
  23758. sixcircleinversesansserif: 0x278F,
  23759. sixdeva: 0x096C,
  23760. sixgujarati: 0x0AEC,
  23761. sixgurmukhi: 0x0A6C,
  23762. sixhackarabic: 0x0666,
  23763. sixhangzhou: 0x3026,
  23764. sixideographicparen: 0x3225,
  23765. sixinferior: 0x2086,
  23766. sixmonospace: 0xFF16,
  23767. sixoldstyle: 0xF736,
  23768. sixparen: 0x2479,
  23769. sixperiod: 0x248D,
  23770. sixpersian: 0x06F6,
  23771. sixroman: 0x2175,
  23772. sixsuperior: 0x2076,
  23773. sixteencircle: 0x246F,
  23774. sixteencurrencydenominatorbengali: 0x09F9,
  23775. sixteenparen: 0x2483,
  23776. sixteenperiod: 0x2497,
  23777. sixthai: 0x0E56,
  23778. slash: 0x002F,
  23779. slashmonospace: 0xFF0F,
  23780. slong: 0x017F,
  23781. slongdotaccent: 0x1E9B,
  23782. smileface: 0x263A,
  23783. smonospace: 0xFF53,
  23784. sofpasuqhebrew: 0x05C3,
  23785. softhyphen: 0x00AD,
  23786. softsigncyrillic: 0x044C,
  23787. sohiragana: 0x305D,
  23788. sokatakana: 0x30BD,
  23789. sokatakanahalfwidth: 0xFF7F,
  23790. soliduslongoverlaycmb: 0x0338,
  23791. solidusshortoverlaycmb: 0x0337,
  23792. sorusithai: 0x0E29,
  23793. sosalathai: 0x0E28,
  23794. sosothai: 0x0E0B,
  23795. sosuathai: 0x0E2A,
  23796. space: 0x0020,
  23797. spacehackarabic: 0x0020,
  23798. spade: 0x2660,
  23799. spadesuitblack: 0x2660,
  23800. spadesuitwhite: 0x2664,
  23801. sparen: 0x24AE,
  23802. squarebelowcmb: 0x033B,
  23803. squarecc: 0x33C4,
  23804. squarecm: 0x339D,
  23805. squarediagonalcrosshatchfill: 0x25A9,
  23806. squarehorizontalfill: 0x25A4,
  23807. squarekg: 0x338F,
  23808. squarekm: 0x339E,
  23809. squarekmcapital: 0x33CE,
  23810. squareln: 0x33D1,
  23811. squarelog: 0x33D2,
  23812. squaremg: 0x338E,
  23813. squaremil: 0x33D5,
  23814. squaremm: 0x339C,
  23815. squaremsquared: 0x33A1,
  23816. squareorthogonalcrosshatchfill: 0x25A6,
  23817. squareupperlefttolowerrightfill: 0x25A7,
  23818. squareupperrighttolowerleftfill: 0x25A8,
  23819. squareverticalfill: 0x25A5,
  23820. squarewhitewithsmallblack: 0x25A3,
  23821. srsquare: 0x33DB,
  23822. ssabengali: 0x09B7,
  23823. ssadeva: 0x0937,
  23824. ssagujarati: 0x0AB7,
  23825. ssangcieuckorean: 0x3149,
  23826. ssanghieuhkorean: 0x3185,
  23827. ssangieungkorean: 0x3180,
  23828. ssangkiyeokkorean: 0x3132,
  23829. ssangnieunkorean: 0x3165,
  23830. ssangpieupkorean: 0x3143,
  23831. ssangsioskorean: 0x3146,
  23832. ssangtikeutkorean: 0x3138,
  23833. ssuperior: 0xF6F2,
  23834. sterling: 0x00A3,
  23835. sterlingmonospace: 0xFFE1,
  23836. strokelongoverlaycmb: 0x0336,
  23837. strokeshortoverlaycmb: 0x0335,
  23838. subset: 0x2282,
  23839. subsetnotequal: 0x228A,
  23840. subsetorequal: 0x2286,
  23841. succeeds: 0x227B,
  23842. suchthat: 0x220B,
  23843. suhiragana: 0x3059,
  23844. sukatakana: 0x30B9,
  23845. sukatakanahalfwidth: 0xFF7D,
  23846. sukunarabic: 0x0652,
  23847. summation: 0x2211,
  23848. sun: 0x263C,
  23849. superset: 0x2283,
  23850. supersetnotequal: 0x228B,
  23851. supersetorequal: 0x2287,
  23852. svsquare: 0x33DC,
  23853. syouwaerasquare: 0x337C,
  23854. t: 0x0074,
  23855. tabengali: 0x09A4,
  23856. tackdown: 0x22A4,
  23857. tackleft: 0x22A3,
  23858. tadeva: 0x0924,
  23859. tagujarati: 0x0AA4,
  23860. tagurmukhi: 0x0A24,
  23861. taharabic: 0x0637,
  23862. tahfinalarabic: 0xFEC2,
  23863. tahinitialarabic: 0xFEC3,
  23864. tahiragana: 0x305F,
  23865. tahmedialarabic: 0xFEC4,
  23866. taisyouerasquare: 0x337D,
  23867. takatakana: 0x30BF,
  23868. takatakanahalfwidth: 0xFF80,
  23869. tatweelarabic: 0x0640,
  23870. tau: 0x03C4,
  23871. tav: 0x05EA,
  23872. tavdages: 0xFB4A,
  23873. tavdagesh: 0xFB4A,
  23874. tavdageshhebrew: 0xFB4A,
  23875. tavhebrew: 0x05EA,
  23876. tbar: 0x0167,
  23877. tbopomofo: 0x310A,
  23878. tcaron: 0x0165,
  23879. tccurl: 0x02A8,
  23880. tcedilla: 0x0163,
  23881. tcheharabic: 0x0686,
  23882. tchehfinalarabic: 0xFB7B,
  23883. tchehinitialarabic: 0xFB7C,
  23884. tchehmedialarabic: 0xFB7D,
  23885. tcircle: 0x24E3,
  23886. tcircumflexbelow: 0x1E71,
  23887. tcommaaccent: 0x0163,
  23888. tdieresis: 0x1E97,
  23889. tdotaccent: 0x1E6B,
  23890. tdotbelow: 0x1E6D,
  23891. tecyrillic: 0x0442,
  23892. tedescendercyrillic: 0x04AD,
  23893. teharabic: 0x062A,
  23894. tehfinalarabic: 0xFE96,
  23895. tehhahinitialarabic: 0xFCA2,
  23896. tehhahisolatedarabic: 0xFC0C,
  23897. tehinitialarabic: 0xFE97,
  23898. tehiragana: 0x3066,
  23899. tehjeeminitialarabic: 0xFCA1,
  23900. tehjeemisolatedarabic: 0xFC0B,
  23901. tehmarbutaarabic: 0x0629,
  23902. tehmarbutafinalarabic: 0xFE94,
  23903. tehmedialarabic: 0xFE98,
  23904. tehmeeminitialarabic: 0xFCA4,
  23905. tehmeemisolatedarabic: 0xFC0E,
  23906. tehnoonfinalarabic: 0xFC73,
  23907. tekatakana: 0x30C6,
  23908. tekatakanahalfwidth: 0xFF83,
  23909. telephone: 0x2121,
  23910. telephoneblack: 0x260E,
  23911. telishagedolahebrew: 0x05A0,
  23912. telishaqetanahebrew: 0x05A9,
  23913. tencircle: 0x2469,
  23914. tenideographicparen: 0x3229,
  23915. tenparen: 0x247D,
  23916. tenperiod: 0x2491,
  23917. tenroman: 0x2179,
  23918. tesh: 0x02A7,
  23919. tet: 0x05D8,
  23920. tetdagesh: 0xFB38,
  23921. tetdageshhebrew: 0xFB38,
  23922. tethebrew: 0x05D8,
  23923. tetsecyrillic: 0x04B5,
  23924. tevirhebrew: 0x059B,
  23925. tevirlefthebrew: 0x059B,
  23926. thabengali: 0x09A5,
  23927. thadeva: 0x0925,
  23928. thagujarati: 0x0AA5,
  23929. thagurmukhi: 0x0A25,
  23930. thalarabic: 0x0630,
  23931. thalfinalarabic: 0xFEAC,
  23932. thanthakhatlowleftthai: 0xF898,
  23933. thanthakhatlowrightthai: 0xF897,
  23934. thanthakhatthai: 0x0E4C,
  23935. thanthakhatupperleftthai: 0xF896,
  23936. theharabic: 0x062B,
  23937. thehfinalarabic: 0xFE9A,
  23938. thehinitialarabic: 0xFE9B,
  23939. thehmedialarabic: 0xFE9C,
  23940. thereexists: 0x2203,
  23941. therefore: 0x2234,
  23942. theta: 0x03B8,
  23943. theta1: 0x03D1,
  23944. thetasymbolgreek: 0x03D1,
  23945. thieuthacirclekorean: 0x3279,
  23946. thieuthaparenkorean: 0x3219,
  23947. thieuthcirclekorean: 0x326B,
  23948. thieuthkorean: 0x314C,
  23949. thieuthparenkorean: 0x320B,
  23950. thirteencircle: 0x246C,
  23951. thirteenparen: 0x2480,
  23952. thirteenperiod: 0x2494,
  23953. thonangmonthothai: 0x0E11,
  23954. thook: 0x01AD,
  23955. thophuthaothai: 0x0E12,
  23956. thorn: 0x00FE,
  23957. thothahanthai: 0x0E17,
  23958. thothanthai: 0x0E10,
  23959. thothongthai: 0x0E18,
  23960. thothungthai: 0x0E16,
  23961. thousandcyrillic: 0x0482,
  23962. thousandsseparatorarabic: 0x066C,
  23963. thousandsseparatorpersian: 0x066C,
  23964. three: 0x0033,
  23965. threearabic: 0x0663,
  23966. threebengali: 0x09E9,
  23967. threecircle: 0x2462,
  23968. threecircleinversesansserif: 0x278C,
  23969. threedeva: 0x0969,
  23970. threeeighths: 0x215C,
  23971. threegujarati: 0x0AE9,
  23972. threegurmukhi: 0x0A69,
  23973. threehackarabic: 0x0663,
  23974. threehangzhou: 0x3023,
  23975. threeideographicparen: 0x3222,
  23976. threeinferior: 0x2083,
  23977. threemonospace: 0xFF13,
  23978. threenumeratorbengali: 0x09F6,
  23979. threeoldstyle: 0xF733,
  23980. threeparen: 0x2476,
  23981. threeperiod: 0x248A,
  23982. threepersian: 0x06F3,
  23983. threequarters: 0x00BE,
  23984. threequartersemdash: 0xF6DE,
  23985. threeroman: 0x2172,
  23986. threesuperior: 0x00B3,
  23987. threethai: 0x0E53,
  23988. thzsquare: 0x3394,
  23989. tihiragana: 0x3061,
  23990. tikatakana: 0x30C1,
  23991. tikatakanahalfwidth: 0xFF81,
  23992. tikeutacirclekorean: 0x3270,
  23993. tikeutaparenkorean: 0x3210,
  23994. tikeutcirclekorean: 0x3262,
  23995. tikeutkorean: 0x3137,
  23996. tikeutparenkorean: 0x3202,
  23997. tilde: 0x02DC,
  23998. tildebelowcmb: 0x0330,
  23999. tildecmb: 0x0303,
  24000. tildecomb: 0x0303,
  24001. tildedoublecmb: 0x0360,
  24002. tildeoperator: 0x223C,
  24003. tildeoverlaycmb: 0x0334,
  24004. tildeverticalcmb: 0x033E,
  24005. timescircle: 0x2297,
  24006. tipehahebrew: 0x0596,
  24007. tipehalefthebrew: 0x0596,
  24008. tippigurmukhi: 0x0A70,
  24009. titlocyrilliccmb: 0x0483,
  24010. tiwnarmenian: 0x057F,
  24011. tlinebelow: 0x1E6F,
  24012. tmonospace: 0xFF54,
  24013. toarmenian: 0x0569,
  24014. tohiragana: 0x3068,
  24015. tokatakana: 0x30C8,
  24016. tokatakanahalfwidth: 0xFF84,
  24017. tonebarextrahighmod: 0x02E5,
  24018. tonebarextralowmod: 0x02E9,
  24019. tonebarhighmod: 0x02E6,
  24020. tonebarlowmod: 0x02E8,
  24021. tonebarmidmod: 0x02E7,
  24022. tonefive: 0x01BD,
  24023. tonesix: 0x0185,
  24024. tonetwo: 0x01A8,
  24025. tonos: 0x0384,
  24026. tonsquare: 0x3327,
  24027. topatakthai: 0x0E0F,
  24028. tortoiseshellbracketleft: 0x3014,
  24029. tortoiseshellbracketleftsmall: 0xFE5D,
  24030. tortoiseshellbracketleftvertical: 0xFE39,
  24031. tortoiseshellbracketright: 0x3015,
  24032. tortoiseshellbracketrightsmall: 0xFE5E,
  24033. tortoiseshellbracketrightvertical: 0xFE3A,
  24034. totaothai: 0x0E15,
  24035. tpalatalhook: 0x01AB,
  24036. tparen: 0x24AF,
  24037. trademark: 0x2122,
  24038. trademarksans: 0xF8EA,
  24039. trademarkserif: 0xF6DB,
  24040. tretroflexhook: 0x0288,
  24041. triagdn: 0x25BC,
  24042. triaglf: 0x25C4,
  24043. triagrt: 0x25BA,
  24044. triagup: 0x25B2,
  24045. ts: 0x02A6,
  24046. tsadi: 0x05E6,
  24047. tsadidagesh: 0xFB46,
  24048. tsadidageshhebrew: 0xFB46,
  24049. tsadihebrew: 0x05E6,
  24050. tsecyrillic: 0x0446,
  24051. tsere: 0x05B5,
  24052. tsere12: 0x05B5,
  24053. tsere1e: 0x05B5,
  24054. tsere2b: 0x05B5,
  24055. tserehebrew: 0x05B5,
  24056. tserenarrowhebrew: 0x05B5,
  24057. tserequarterhebrew: 0x05B5,
  24058. tserewidehebrew: 0x05B5,
  24059. tshecyrillic: 0x045B,
  24060. tsuperior: 0xF6F3,
  24061. ttabengali: 0x099F,
  24062. ttadeva: 0x091F,
  24063. ttagujarati: 0x0A9F,
  24064. ttagurmukhi: 0x0A1F,
  24065. tteharabic: 0x0679,
  24066. ttehfinalarabic: 0xFB67,
  24067. ttehinitialarabic: 0xFB68,
  24068. ttehmedialarabic: 0xFB69,
  24069. tthabengali: 0x09A0,
  24070. tthadeva: 0x0920,
  24071. tthagujarati: 0x0AA0,
  24072. tthagurmukhi: 0x0A20,
  24073. tturned: 0x0287,
  24074. tuhiragana: 0x3064,
  24075. tukatakana: 0x30C4,
  24076. tukatakanahalfwidth: 0xFF82,
  24077. tusmallhiragana: 0x3063,
  24078. tusmallkatakana: 0x30C3,
  24079. tusmallkatakanahalfwidth: 0xFF6F,
  24080. twelvecircle: 0x246B,
  24081. twelveparen: 0x247F,
  24082. twelveperiod: 0x2493,
  24083. twelveroman: 0x217B,
  24084. twentycircle: 0x2473,
  24085. twentyhangzhou: 0x5344,
  24086. twentyparen: 0x2487,
  24087. twentyperiod: 0x249B,
  24088. two: 0x0032,
  24089. twoarabic: 0x0662,
  24090. twobengali: 0x09E8,
  24091. twocircle: 0x2461,
  24092. twocircleinversesansserif: 0x278B,
  24093. twodeva: 0x0968,
  24094. twodotenleader: 0x2025,
  24095. twodotleader: 0x2025,
  24096. twodotleadervertical: 0xFE30,
  24097. twogujarati: 0x0AE8,
  24098. twogurmukhi: 0x0A68,
  24099. twohackarabic: 0x0662,
  24100. twohangzhou: 0x3022,
  24101. twoideographicparen: 0x3221,
  24102. twoinferior: 0x2082,
  24103. twomonospace: 0xFF12,
  24104. twonumeratorbengali: 0x09F5,
  24105. twooldstyle: 0xF732,
  24106. twoparen: 0x2475,
  24107. twoperiod: 0x2489,
  24108. twopersian: 0x06F2,
  24109. tworoman: 0x2171,
  24110. twostroke: 0x01BB,
  24111. twosuperior: 0x00B2,
  24112. twothai: 0x0E52,
  24113. twothirds: 0x2154,
  24114. u: 0x0075,
  24115. uacute: 0x00FA,
  24116. ubar: 0x0289,
  24117. ubengali: 0x0989,
  24118. ubopomofo: 0x3128,
  24119. ubreve: 0x016D,
  24120. ucaron: 0x01D4,
  24121. ucircle: 0x24E4,
  24122. ucircumflex: 0x00FB,
  24123. ucircumflexbelow: 0x1E77,
  24124. ucyrillic: 0x0443,
  24125. udattadeva: 0x0951,
  24126. udblacute: 0x0171,
  24127. udblgrave: 0x0215,
  24128. udeva: 0x0909,
  24129. udieresis: 0x00FC,
  24130. udieresisacute: 0x01D8,
  24131. udieresisbelow: 0x1E73,
  24132. udieresiscaron: 0x01DA,
  24133. udieresiscyrillic: 0x04F1,
  24134. udieresisgrave: 0x01DC,
  24135. udieresismacron: 0x01D6,
  24136. udotbelow: 0x1EE5,
  24137. ugrave: 0x00F9,
  24138. ugujarati: 0x0A89,
  24139. ugurmukhi: 0x0A09,
  24140. uhiragana: 0x3046,
  24141. uhookabove: 0x1EE7,
  24142. uhorn: 0x01B0,
  24143. uhornacute: 0x1EE9,
  24144. uhorndotbelow: 0x1EF1,
  24145. uhorngrave: 0x1EEB,
  24146. uhornhookabove: 0x1EED,
  24147. uhorntilde: 0x1EEF,
  24148. uhungarumlaut: 0x0171,
  24149. uhungarumlautcyrillic: 0x04F3,
  24150. uinvertedbreve: 0x0217,
  24151. ukatakana: 0x30A6,
  24152. ukatakanahalfwidth: 0xFF73,
  24153. ukcyrillic: 0x0479,
  24154. ukorean: 0x315C,
  24155. umacron: 0x016B,
  24156. umacroncyrillic: 0x04EF,
  24157. umacrondieresis: 0x1E7B,
  24158. umatragurmukhi: 0x0A41,
  24159. umonospace: 0xFF55,
  24160. underscore: 0x005F,
  24161. underscoredbl: 0x2017,
  24162. underscoremonospace: 0xFF3F,
  24163. underscorevertical: 0xFE33,
  24164. underscorewavy: 0xFE4F,
  24165. union: 0x222A,
  24166. universal: 0x2200,
  24167. uogonek: 0x0173,
  24168. uparen: 0x24B0,
  24169. upblock: 0x2580,
  24170. upperdothebrew: 0x05C4,
  24171. upsilon: 0x03C5,
  24172. upsilondieresis: 0x03CB,
  24173. upsilondieresistonos: 0x03B0,
  24174. upsilonlatin: 0x028A,
  24175. upsilontonos: 0x03CD,
  24176. uptackbelowcmb: 0x031D,
  24177. uptackmod: 0x02D4,
  24178. uragurmukhi: 0x0A73,
  24179. uring: 0x016F,
  24180. ushortcyrillic: 0x045E,
  24181. usmallhiragana: 0x3045,
  24182. usmallkatakana: 0x30A5,
  24183. usmallkatakanahalfwidth: 0xFF69,
  24184. ustraightcyrillic: 0x04AF,
  24185. ustraightstrokecyrillic: 0x04B1,
  24186. utilde: 0x0169,
  24187. utildeacute: 0x1E79,
  24188. utildebelow: 0x1E75,
  24189. uubengali: 0x098A,
  24190. uudeva: 0x090A,
  24191. uugujarati: 0x0A8A,
  24192. uugurmukhi: 0x0A0A,
  24193. uumatragurmukhi: 0x0A42,
  24194. uuvowelsignbengali: 0x09C2,
  24195. uuvowelsigndeva: 0x0942,
  24196. uuvowelsigngujarati: 0x0AC2,
  24197. uvowelsignbengali: 0x09C1,
  24198. uvowelsigndeva: 0x0941,
  24199. uvowelsigngujarati: 0x0AC1,
  24200. v: 0x0076,
  24201. vadeva: 0x0935,
  24202. vagujarati: 0x0AB5,
  24203. vagurmukhi: 0x0A35,
  24204. vakatakana: 0x30F7,
  24205. vav: 0x05D5,
  24206. vavdagesh: 0xFB35,
  24207. vavdagesh65: 0xFB35,
  24208. vavdageshhebrew: 0xFB35,
  24209. vavhebrew: 0x05D5,
  24210. vavholam: 0xFB4B,
  24211. vavholamhebrew: 0xFB4B,
  24212. vavvavhebrew: 0x05F0,
  24213. vavyodhebrew: 0x05F1,
  24214. vcircle: 0x24E5,
  24215. vdotbelow: 0x1E7F,
  24216. vecyrillic: 0x0432,
  24217. veharabic: 0x06A4,
  24218. vehfinalarabic: 0xFB6B,
  24219. vehinitialarabic: 0xFB6C,
  24220. vehmedialarabic: 0xFB6D,
  24221. vekatakana: 0x30F9,
  24222. venus: 0x2640,
  24223. verticalbar: 0x007C,
  24224. verticallineabovecmb: 0x030D,
  24225. verticallinebelowcmb: 0x0329,
  24226. verticallinelowmod: 0x02CC,
  24227. verticallinemod: 0x02C8,
  24228. vewarmenian: 0x057E,
  24229. vhook: 0x028B,
  24230. vikatakana: 0x30F8,
  24231. viramabengali: 0x09CD,
  24232. viramadeva: 0x094D,
  24233. viramagujarati: 0x0ACD,
  24234. visargabengali: 0x0983,
  24235. visargadeva: 0x0903,
  24236. visargagujarati: 0x0A83,
  24237. vmonospace: 0xFF56,
  24238. voarmenian: 0x0578,
  24239. voicediterationhiragana: 0x309E,
  24240. voicediterationkatakana: 0x30FE,
  24241. voicedmarkkana: 0x309B,
  24242. voicedmarkkanahalfwidth: 0xFF9E,
  24243. vokatakana: 0x30FA,
  24244. vparen: 0x24B1,
  24245. vtilde: 0x1E7D,
  24246. vturned: 0x028C,
  24247. vuhiragana: 0x3094,
  24248. vukatakana: 0x30F4,
  24249. w: 0x0077,
  24250. wacute: 0x1E83,
  24251. waekorean: 0x3159,
  24252. wahiragana: 0x308F,
  24253. wakatakana: 0x30EF,
  24254. wakatakanahalfwidth: 0xFF9C,
  24255. wakorean: 0x3158,
  24256. wasmallhiragana: 0x308E,
  24257. wasmallkatakana: 0x30EE,
  24258. wattosquare: 0x3357,
  24259. wavedash: 0x301C,
  24260. wavyunderscorevertical: 0xFE34,
  24261. wawarabic: 0x0648,
  24262. wawfinalarabic: 0xFEEE,
  24263. wawhamzaabovearabic: 0x0624,
  24264. wawhamzaabovefinalarabic: 0xFE86,
  24265. wbsquare: 0x33DD,
  24266. wcircle: 0x24E6,
  24267. wcircumflex: 0x0175,
  24268. wdieresis: 0x1E85,
  24269. wdotaccent: 0x1E87,
  24270. wdotbelow: 0x1E89,
  24271. wehiragana: 0x3091,
  24272. weierstrass: 0x2118,
  24273. wekatakana: 0x30F1,
  24274. wekorean: 0x315E,
  24275. weokorean: 0x315D,
  24276. wgrave: 0x1E81,
  24277. whitebullet: 0x25E6,
  24278. whitecircle: 0x25CB,
  24279. whitecircleinverse: 0x25D9,
  24280. whitecornerbracketleft: 0x300E,
  24281. whitecornerbracketleftvertical: 0xFE43,
  24282. whitecornerbracketright: 0x300F,
  24283. whitecornerbracketrightvertical: 0xFE44,
  24284. whitediamond: 0x25C7,
  24285. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24286. whitedownpointingsmalltriangle: 0x25BF,
  24287. whitedownpointingtriangle: 0x25BD,
  24288. whiteleftpointingsmalltriangle: 0x25C3,
  24289. whiteleftpointingtriangle: 0x25C1,
  24290. whitelenticularbracketleft: 0x3016,
  24291. whitelenticularbracketright: 0x3017,
  24292. whiterightpointingsmalltriangle: 0x25B9,
  24293. whiterightpointingtriangle: 0x25B7,
  24294. whitesmallsquare: 0x25AB,
  24295. whitesmilingface: 0x263A,
  24296. whitesquare: 0x25A1,
  24297. whitestar: 0x2606,
  24298. whitetelephone: 0x260F,
  24299. whitetortoiseshellbracketleft: 0x3018,
  24300. whitetortoiseshellbracketright: 0x3019,
  24301. whiteuppointingsmalltriangle: 0x25B5,
  24302. whiteuppointingtriangle: 0x25B3,
  24303. wihiragana: 0x3090,
  24304. wikatakana: 0x30F0,
  24305. wikorean: 0x315F,
  24306. wmonospace: 0xFF57,
  24307. wohiragana: 0x3092,
  24308. wokatakana: 0x30F2,
  24309. wokatakanahalfwidth: 0xFF66,
  24310. won: 0x20A9,
  24311. wonmonospace: 0xFFE6,
  24312. wowaenthai: 0x0E27,
  24313. wparen: 0x24B2,
  24314. wring: 0x1E98,
  24315. wsuperior: 0x02B7,
  24316. wturned: 0x028D,
  24317. wynn: 0x01BF,
  24318. x: 0x0078,
  24319. xabovecmb: 0x033D,
  24320. xbopomofo: 0x3112,
  24321. xcircle: 0x24E7,
  24322. xdieresis: 0x1E8D,
  24323. xdotaccent: 0x1E8B,
  24324. xeharmenian: 0x056D,
  24325. xi: 0x03BE,
  24326. xmonospace: 0xFF58,
  24327. xparen: 0x24B3,
  24328. xsuperior: 0x02E3,
  24329. y: 0x0079,
  24330. yaadosquare: 0x334E,
  24331. yabengali: 0x09AF,
  24332. yacute: 0x00FD,
  24333. yadeva: 0x092F,
  24334. yaekorean: 0x3152,
  24335. yagujarati: 0x0AAF,
  24336. yagurmukhi: 0x0A2F,
  24337. yahiragana: 0x3084,
  24338. yakatakana: 0x30E4,
  24339. yakatakanahalfwidth: 0xFF94,
  24340. yakorean: 0x3151,
  24341. yamakkanthai: 0x0E4E,
  24342. yasmallhiragana: 0x3083,
  24343. yasmallkatakana: 0x30E3,
  24344. yasmallkatakanahalfwidth: 0xFF6C,
  24345. yatcyrillic: 0x0463,
  24346. ycircle: 0x24E8,
  24347. ycircumflex: 0x0177,
  24348. ydieresis: 0x00FF,
  24349. ydotaccent: 0x1E8F,
  24350. ydotbelow: 0x1EF5,
  24351. yeharabic: 0x064A,
  24352. yehbarreearabic: 0x06D2,
  24353. yehbarreefinalarabic: 0xFBAF,
  24354. yehfinalarabic: 0xFEF2,
  24355. yehhamzaabovearabic: 0x0626,
  24356. yehhamzaabovefinalarabic: 0xFE8A,
  24357. yehhamzaaboveinitialarabic: 0xFE8B,
  24358. yehhamzaabovemedialarabic: 0xFE8C,
  24359. yehinitialarabic: 0xFEF3,
  24360. yehmedialarabic: 0xFEF4,
  24361. yehmeeminitialarabic: 0xFCDD,
  24362. yehmeemisolatedarabic: 0xFC58,
  24363. yehnoonfinalarabic: 0xFC94,
  24364. yehthreedotsbelowarabic: 0x06D1,
  24365. yekorean: 0x3156,
  24366. yen: 0x00A5,
  24367. yenmonospace: 0xFFE5,
  24368. yeokorean: 0x3155,
  24369. yeorinhieuhkorean: 0x3186,
  24370. yerahbenyomohebrew: 0x05AA,
  24371. yerahbenyomolefthebrew: 0x05AA,
  24372. yericyrillic: 0x044B,
  24373. yerudieresiscyrillic: 0x04F9,
  24374. yesieungkorean: 0x3181,
  24375. yesieungpansioskorean: 0x3183,
  24376. yesieungsioskorean: 0x3182,
  24377. yetivhebrew: 0x059A,
  24378. ygrave: 0x1EF3,
  24379. yhook: 0x01B4,
  24380. yhookabove: 0x1EF7,
  24381. yiarmenian: 0x0575,
  24382. yicyrillic: 0x0457,
  24383. yikorean: 0x3162,
  24384. yinyang: 0x262F,
  24385. yiwnarmenian: 0x0582,
  24386. ymonospace: 0xFF59,
  24387. yod: 0x05D9,
  24388. yoddagesh: 0xFB39,
  24389. yoddageshhebrew: 0xFB39,
  24390. yodhebrew: 0x05D9,
  24391. yodyodhebrew: 0x05F2,
  24392. yodyodpatahhebrew: 0xFB1F,
  24393. yohiragana: 0x3088,
  24394. yoikorean: 0x3189,
  24395. yokatakana: 0x30E8,
  24396. yokatakanahalfwidth: 0xFF96,
  24397. yokorean: 0x315B,
  24398. yosmallhiragana: 0x3087,
  24399. yosmallkatakana: 0x30E7,
  24400. yosmallkatakanahalfwidth: 0xFF6E,
  24401. yotgreek: 0x03F3,
  24402. yoyaekorean: 0x3188,
  24403. yoyakorean: 0x3187,
  24404. yoyakthai: 0x0E22,
  24405. yoyingthai: 0x0E0D,
  24406. yparen: 0x24B4,
  24407. ypogegrammeni: 0x037A,
  24408. ypogegrammenigreekcmb: 0x0345,
  24409. yr: 0x01A6,
  24410. yring: 0x1E99,
  24411. ysuperior: 0x02B8,
  24412. ytilde: 0x1EF9,
  24413. yturned: 0x028E,
  24414. yuhiragana: 0x3086,
  24415. yuikorean: 0x318C,
  24416. yukatakana: 0x30E6,
  24417. yukatakanahalfwidth: 0xFF95,
  24418. yukorean: 0x3160,
  24419. yusbigcyrillic: 0x046B,
  24420. yusbigiotifiedcyrillic: 0x046D,
  24421. yuslittlecyrillic: 0x0467,
  24422. yuslittleiotifiedcyrillic: 0x0469,
  24423. yusmallhiragana: 0x3085,
  24424. yusmallkatakana: 0x30E5,
  24425. yusmallkatakanahalfwidth: 0xFF6D,
  24426. yuyekorean: 0x318B,
  24427. yuyeokorean: 0x318A,
  24428. yyabengali: 0x09DF,
  24429. yyadeva: 0x095F,
  24430. z: 0x007A,
  24431. zaarmenian: 0x0566,
  24432. zacute: 0x017A,
  24433. zadeva: 0x095B,
  24434. zagurmukhi: 0x0A5B,
  24435. zaharabic: 0x0638,
  24436. zahfinalarabic: 0xFEC6,
  24437. zahinitialarabic: 0xFEC7,
  24438. zahiragana: 0x3056,
  24439. zahmedialarabic: 0xFEC8,
  24440. zainarabic: 0x0632,
  24441. zainfinalarabic: 0xFEB0,
  24442. zakatakana: 0x30B6,
  24443. zaqefgadolhebrew: 0x0595,
  24444. zaqefqatanhebrew: 0x0594,
  24445. zarqahebrew: 0x0598,
  24446. zayin: 0x05D6,
  24447. zayindagesh: 0xFB36,
  24448. zayindageshhebrew: 0xFB36,
  24449. zayinhebrew: 0x05D6,
  24450. zbopomofo: 0x3117,
  24451. zcaron: 0x017E,
  24452. zcircle: 0x24E9,
  24453. zcircumflex: 0x1E91,
  24454. zcurl: 0x0291,
  24455. zdot: 0x017C,
  24456. zdotaccent: 0x017C,
  24457. zdotbelow: 0x1E93,
  24458. zecyrillic: 0x0437,
  24459. zedescendercyrillic: 0x0499,
  24460. zedieresiscyrillic: 0x04DF,
  24461. zehiragana: 0x305C,
  24462. zekatakana: 0x30BC,
  24463. zero: 0x0030,
  24464. zeroarabic: 0x0660,
  24465. zerobengali: 0x09E6,
  24466. zerodeva: 0x0966,
  24467. zerogujarati: 0x0AE6,
  24468. zerogurmukhi: 0x0A66,
  24469. zerohackarabic: 0x0660,
  24470. zeroinferior: 0x2080,
  24471. zeromonospace: 0xFF10,
  24472. zerooldstyle: 0xF730,
  24473. zeropersian: 0x06F0,
  24474. zerosuperior: 0x2070,
  24475. zerothai: 0x0E50,
  24476. zerowidthjoiner: 0xFEFF,
  24477. zerowidthnonjoiner: 0x200C,
  24478. zerowidthspace: 0x200B,
  24479. zeta: 0x03B6,
  24480. zhbopomofo: 0x3113,
  24481. zhearmenian: 0x056A,
  24482. zhebrevecyrillic: 0x04C2,
  24483. zhecyrillic: 0x0436,
  24484. zhedescendercyrillic: 0x0497,
  24485. zhedieresiscyrillic: 0x04DD,
  24486. zihiragana: 0x3058,
  24487. zikatakana: 0x30B8,
  24488. zinorhebrew: 0x05AE,
  24489. zlinebelow: 0x1E95,
  24490. zmonospace: 0xFF5A,
  24491. zohiragana: 0x305E,
  24492. zokatakana: 0x30BE,
  24493. zparen: 0x24B5,
  24494. zretroflexhook: 0x0290,
  24495. zstroke: 0x01B6,
  24496. zuhiragana: 0x305A,
  24497. zukatakana: 0x30BA,
  24498. '.notdef': 0x0000
  24499. };
  24500. var DingbatsGlyphsUnicode = {
  24501. space: 0x0020,
  24502. a1: 0x2701,
  24503. a2: 0x2702,
  24504. a202: 0x2703,
  24505. a3: 0x2704,
  24506. a4: 0x260E,
  24507. a5: 0x2706,
  24508. a119: 0x2707,
  24509. a118: 0x2708,
  24510. a117: 0x2709,
  24511. a11: 0x261B,
  24512. a12: 0x261E,
  24513. a13: 0x270C,
  24514. a14: 0x270D,
  24515. a15: 0x270E,
  24516. a16: 0x270F,
  24517. a105: 0x2710,
  24518. a17: 0x2711,
  24519. a18: 0x2712,
  24520. a19: 0x2713,
  24521. a20: 0x2714,
  24522. a21: 0x2715,
  24523. a22: 0x2716,
  24524. a23: 0x2717,
  24525. a24: 0x2718,
  24526. a25: 0x2719,
  24527. a26: 0x271A,
  24528. a27: 0x271B,
  24529. a28: 0x271C,
  24530. a6: 0x271D,
  24531. a7: 0x271E,
  24532. a8: 0x271F,
  24533. a9: 0x2720,
  24534. a10: 0x2721,
  24535. a29: 0x2722,
  24536. a30: 0x2723,
  24537. a31: 0x2724,
  24538. a32: 0x2725,
  24539. a33: 0x2726,
  24540. a34: 0x2727,
  24541. a35: 0x2605,
  24542. a36: 0x2729,
  24543. a37: 0x272A,
  24544. a38: 0x272B,
  24545. a39: 0x272C,
  24546. a40: 0x272D,
  24547. a41: 0x272E,
  24548. a42: 0x272F,
  24549. a43: 0x2730,
  24550. a44: 0x2731,
  24551. a45: 0x2732,
  24552. a46: 0x2733,
  24553. a47: 0x2734,
  24554. a48: 0x2735,
  24555. a49: 0x2736,
  24556. a50: 0x2737,
  24557. a51: 0x2738,
  24558. a52: 0x2739,
  24559. a53: 0x273A,
  24560. a54: 0x273B,
  24561. a55: 0x273C,
  24562. a56: 0x273D,
  24563. a57: 0x273E,
  24564. a58: 0x273F,
  24565. a59: 0x2740,
  24566. a60: 0x2741,
  24567. a61: 0x2742,
  24568. a62: 0x2743,
  24569. a63: 0x2744,
  24570. a64: 0x2745,
  24571. a65: 0x2746,
  24572. a66: 0x2747,
  24573. a67: 0x2748,
  24574. a68: 0x2749,
  24575. a69: 0x274A,
  24576. a70: 0x274B,
  24577. a71: 0x25CF,
  24578. a72: 0x274D,
  24579. a73: 0x25A0,
  24580. a74: 0x274F,
  24581. a203: 0x2750,
  24582. a75: 0x2751,
  24583. a204: 0x2752,
  24584. a76: 0x25B2,
  24585. a77: 0x25BC,
  24586. a78: 0x25C6,
  24587. a79: 0x2756,
  24588. a81: 0x25D7,
  24589. a82: 0x2758,
  24590. a83: 0x2759,
  24591. a84: 0x275A,
  24592. a97: 0x275B,
  24593. a98: 0x275C,
  24594. a99: 0x275D,
  24595. a100: 0x275E,
  24596. a101: 0x2761,
  24597. a102: 0x2762,
  24598. a103: 0x2763,
  24599. a104: 0x2764,
  24600. a106: 0x2765,
  24601. a107: 0x2766,
  24602. a108: 0x2767,
  24603. a112: 0x2663,
  24604. a111: 0x2666,
  24605. a110: 0x2665,
  24606. a109: 0x2660,
  24607. a120: 0x2460,
  24608. a121: 0x2461,
  24609. a122: 0x2462,
  24610. a123: 0x2463,
  24611. a124: 0x2464,
  24612. a125: 0x2465,
  24613. a126: 0x2466,
  24614. a127: 0x2467,
  24615. a128: 0x2468,
  24616. a129: 0x2469,
  24617. a130: 0x2776,
  24618. a131: 0x2777,
  24619. a132: 0x2778,
  24620. a133: 0x2779,
  24621. a134: 0x277A,
  24622. a135: 0x277B,
  24623. a136: 0x277C,
  24624. a137: 0x277D,
  24625. a138: 0x277E,
  24626. a139: 0x277F,
  24627. a140: 0x2780,
  24628. a141: 0x2781,
  24629. a142: 0x2782,
  24630. a143: 0x2783,
  24631. a144: 0x2784,
  24632. a145: 0x2785,
  24633. a146: 0x2786,
  24634. a147: 0x2787,
  24635. a148: 0x2788,
  24636. a149: 0x2789,
  24637. a150: 0x278A,
  24638. a151: 0x278B,
  24639. a152: 0x278C,
  24640. a153: 0x278D,
  24641. a154: 0x278E,
  24642. a155: 0x278F,
  24643. a156: 0x2790,
  24644. a157: 0x2791,
  24645. a158: 0x2792,
  24646. a159: 0x2793,
  24647. a160: 0x2794,
  24648. a161: 0x2192,
  24649. a163: 0x2194,
  24650. a164: 0x2195,
  24651. a196: 0x2798,
  24652. a165: 0x2799,
  24653. a192: 0x279A,
  24654. a166: 0x279B,
  24655. a167: 0x279C,
  24656. a168: 0x279D,
  24657. a169: 0x279E,
  24658. a170: 0x279F,
  24659. a171: 0x27A0,
  24660. a172: 0x27A1,
  24661. a173: 0x27A2,
  24662. a162: 0x27A3,
  24663. a174: 0x27A4,
  24664. a175: 0x27A5,
  24665. a176: 0x27A6,
  24666. a177: 0x27A7,
  24667. a178: 0x27A8,
  24668. a179: 0x27A9,
  24669. a193: 0x27AA,
  24670. a180: 0x27AB,
  24671. a199: 0x27AC,
  24672. a181: 0x27AD,
  24673. a200: 0x27AE,
  24674. a182: 0x27AF,
  24675. a201: 0x27B1,
  24676. a183: 0x27B2,
  24677. a184: 0x27B3,
  24678. a197: 0x27B4,
  24679. a185: 0x27B5,
  24680. a194: 0x27B6,
  24681. a198: 0x27B7,
  24682. a186: 0x27B8,
  24683. a195: 0x27B9,
  24684. a187: 0x27BA,
  24685. a188: 0x27BB,
  24686. a189: 0x27BC,
  24687. a190: 0x27BD,
  24688. a191: 0x27BE,
  24689. a89: 0x2768, // 0xF8D7
  24690. a90: 0x2769, // 0xF8D8
  24691. a93: 0x276A, // 0xF8D9
  24692. a94: 0x276B, // 0xF8DA
  24693. a91: 0x276C, // 0xF8DB
  24694. a92: 0x276D, // 0xF8DC
  24695. a205: 0x276E, // 0xF8DD
  24696. a85: 0x276F, // 0xF8DE
  24697. a206: 0x2770, // 0xF8DF
  24698. a86: 0x2771, // 0xF8E0
  24699. a87: 0x2772, // 0xF8E1
  24700. a88: 0x2773, // 0xF8E2
  24701. a95: 0x2774, // 0xF8E3
  24702. a96: 0x2775, // 0xF8E4
  24703. '.notdef': 0x0000
  24704. };
  24705. var PDFImage = (function PDFImageClosure() {
  24706. /**
  24707. * Decode the image in the main thread if it supported. Resovles the promise
  24708. * when the image data is ready.
  24709. */
  24710. function handleImageData(handler, xref, res, image) {
  24711. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24712. // For natively supported jpegs send them to the main thread for decoding.
  24713. var dict = image.dict;
  24714. var colorSpace = dict.get('ColorSpace', 'CS');
  24715. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24716. var numComps = colorSpace.numComps;
  24717. var decodePromise = handler.sendWithPromise('JpegDecode',
  24718. [image.getIR(), numComps]);
  24719. return decodePromise.then(function (message) {
  24720. var data = message.data;
  24721. return new Stream(data, 0, data.length, image.dict);
  24722. });
  24723. } else {
  24724. return Promise.resolve(image);
  24725. }
  24726. }
  24727. /**
  24728. * Decode and clamp a value. The formula is different from the spec because we
  24729. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24730. */
  24731. function decodeAndClamp(value, addend, coefficient, max) {
  24732. value = addend + value * coefficient;
  24733. // Clamp the value to the range
  24734. return (value < 0 ? 0 : (value > max ? max : value));
  24735. }
  24736. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24737. this.image = image;
  24738. var dict = image.dict;
  24739. if (dict.has('Filter')) {
  24740. var filter = dict.get('Filter').name;
  24741. if (filter === 'JPXDecode') {
  24742. var jpxImage = new JpxImage();
  24743. jpxImage.parseImageProperties(image.stream);
  24744. image.stream.reset();
  24745. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24746. image.numComps = jpxImage.componentsCount;
  24747. } else if (filter === 'JBIG2Decode') {
  24748. image.bitsPerComponent = 1;
  24749. image.numComps = 1;
  24750. }
  24751. }
  24752. // TODO cache rendered images?
  24753. this.width = dict.get('Width', 'W');
  24754. this.height = dict.get('Height', 'H');
  24755. if (this.width < 1 || this.height < 1) {
  24756. error('Invalid image width: ' + this.width + ' or height: ' +
  24757. this.height);
  24758. }
  24759. this.interpolate = dict.get('Interpolate', 'I') || false;
  24760. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24761. this.matte = dict.get('Matte') || false;
  24762. var bitsPerComponent = image.bitsPerComponent;
  24763. if (!bitsPerComponent) {
  24764. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24765. if (!bitsPerComponent) {
  24766. if (this.imageMask) {
  24767. bitsPerComponent = 1;
  24768. } else {
  24769. error('Bits per component missing in image: ' + this.imageMask);
  24770. }
  24771. }
  24772. }
  24773. this.bpc = bitsPerComponent;
  24774. if (!this.imageMask) {
  24775. var colorSpace = dict.get('ColorSpace', 'CS');
  24776. if (!colorSpace) {
  24777. info('JPX images (which do not require color spaces)');
  24778. switch (image.numComps) {
  24779. case 1:
  24780. colorSpace = Name.get('DeviceGray');
  24781. break;
  24782. case 3:
  24783. colorSpace = Name.get('DeviceRGB');
  24784. break;
  24785. case 4:
  24786. colorSpace = Name.get('DeviceCMYK');
  24787. break;
  24788. default:
  24789. error('JPX images with ' + this.numComps +
  24790. ' color components not supported.');
  24791. }
  24792. }
  24793. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24794. this.numComps = this.colorSpace.numComps;
  24795. }
  24796. this.decode = dict.get('Decode', 'D');
  24797. this.needsDecode = false;
  24798. if (this.decode &&
  24799. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24800. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24801. this.needsDecode = true;
  24802. // Do some preprocessing to avoid more math.
  24803. var max = (1 << bitsPerComponent) - 1;
  24804. this.decodeCoefficients = [];
  24805. this.decodeAddends = [];
  24806. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24807. var dmin = this.decode[i];
  24808. var dmax = this.decode[i + 1];
  24809. this.decodeCoefficients[j] = dmax - dmin;
  24810. this.decodeAddends[j] = max * dmin;
  24811. }
  24812. }
  24813. if (smask) {
  24814. this.smask = new PDFImage(xref, res, smask, false);
  24815. } else if (mask) {
  24816. if (isStream(mask)) {
  24817. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24818. } else {
  24819. // Color key mask (just an array).
  24820. this.mask = mask;
  24821. }
  24822. }
  24823. }
  24824. /**
  24825. * Handles processing of image data and returns the Promise that is resolved
  24826. * with a PDFImage when the image is ready to be used.
  24827. */
  24828. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24829. res, image, inline) {
  24830. var imagePromise = handleImageData(handler, xref, res, image);
  24831. var smaskPromise;
  24832. var maskPromise;
  24833. var smask = image.dict.get('SMask');
  24834. var mask = image.dict.get('Mask');
  24835. if (smask) {
  24836. smaskPromise = handleImageData(handler, xref, res, smask);
  24837. maskPromise = Promise.resolve(null);
  24838. } else {
  24839. smaskPromise = Promise.resolve(null);
  24840. if (mask) {
  24841. if (isStream(mask)) {
  24842. maskPromise = handleImageData(handler, xref, res, mask);
  24843. } else if (isArray(mask)) {
  24844. maskPromise = Promise.resolve(mask);
  24845. } else {
  24846. warn('Unsupported mask format.');
  24847. maskPromise = Promise.resolve(null);
  24848. }
  24849. } else {
  24850. maskPromise = Promise.resolve(null);
  24851. }
  24852. }
  24853. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24854. function(results) {
  24855. var imageData = results[0];
  24856. var smaskData = results[1];
  24857. var maskData = results[2];
  24858. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24859. });
  24860. };
  24861. /**
  24862. * Resize an image using the nearest neighbor algorithm. Currently only
  24863. * supports one and three component images.
  24864. * @param {TypedArray} pixels The original image with one component.
  24865. * @param {Number} bpc Number of bits per component.
  24866. * @param {Number} components Number of color components, 1 or 3 is supported.
  24867. * @param {Number} w1 Original width.
  24868. * @param {Number} h1 Original height.
  24869. * @param {Number} w2 New width.
  24870. * @param {Number} h2 New height.
  24871. * @param {TypedArray} dest (Optional) The destination buffer.
  24872. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24873. * @return {TypedArray} Resized image data.
  24874. */
  24875. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24876. w1, h1, w2, h2, dest, alpha01) {
  24877. if (components !== 1 && components !== 3) {
  24878. error('Unsupported component count for resizing.');
  24879. }
  24880. var length = w2 * h2 * components;
  24881. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24882. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24883. var xRatio = w1 / w2;
  24884. var yRatio = h1 / h2;
  24885. var i, j, py, newIndex = 0, oldIndex;
  24886. var xScaled = new Uint16Array(w2);
  24887. var w1Scanline = w1 * components;
  24888. if (alpha01 !== 1) {
  24889. alpha01 = 0;
  24890. }
  24891. for (j = 0; j < w2; j++) {
  24892. xScaled[j] = Math.floor(j * xRatio) * components;
  24893. }
  24894. if (components === 1) {
  24895. for (i = 0; i < h2; i++) {
  24896. py = Math.floor(i * yRatio) * w1Scanline;
  24897. for (j = 0; j < w2; j++) {
  24898. oldIndex = py + xScaled[j];
  24899. temp[newIndex++] = pixels[oldIndex];
  24900. }
  24901. }
  24902. } else if (components === 3) {
  24903. for (i = 0; i < h2; i++) {
  24904. py = Math.floor(i * yRatio) * w1Scanline;
  24905. for (j = 0; j < w2; j++) {
  24906. oldIndex = py + xScaled[j];
  24907. temp[newIndex++] = pixels[oldIndex++];
  24908. temp[newIndex++] = pixels[oldIndex++];
  24909. temp[newIndex++] = pixels[oldIndex++];
  24910. newIndex += alpha01;
  24911. }
  24912. }
  24913. }
  24914. return temp;
  24915. };
  24916. PDFImage.createMask =
  24917. function PDFImage_createMask(imgArray, width, height,
  24918. imageIsFromDecodeStream, inverseDecode) {
  24919. // |imgArray| might not contain full data for every pixel of the mask, so
  24920. // we need to distinguish between |computedLength| and |actualLength|.
  24921. // In particular, if inverseDecode is true, then the array we return must
  24922. // have a length of |computedLength|.
  24923. var computedLength = ((width + 7) >> 3) * height;
  24924. var actualLength = imgArray.byteLength;
  24925. var haveFullData = computedLength === actualLength;
  24926. var data, i;
  24927. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24928. // imgArray came from a DecodeStream and its data is in an appropriate
  24929. // form, so we can just transfer it.
  24930. data = imgArray;
  24931. } else if (!inverseDecode) {
  24932. data = new Uint8Array(actualLength);
  24933. data.set(imgArray);
  24934. } else {
  24935. data = new Uint8Array(computedLength);
  24936. data.set(imgArray);
  24937. for (i = actualLength; i < computedLength; i++) {
  24938. data[i] = 0xff;
  24939. }
  24940. }
  24941. // If necessary, invert the original mask data (but not any extra we might
  24942. // have added above). It's safe to modify the array -- whether it's the
  24943. // original or a copy, we're about to transfer it anyway, so nothing else
  24944. // in this thread can be relying on its contents.
  24945. if (inverseDecode) {
  24946. for (i = 0; i < actualLength; i++) {
  24947. data[i] = ~data[i];
  24948. }
  24949. }
  24950. return {data: data, width: width, height: height};
  24951. };
  24952. PDFImage.prototype = {
  24953. get drawWidth() {
  24954. return Math.max(this.width,
  24955. this.smask && this.smask.width || 0,
  24956. this.mask && this.mask.width || 0);
  24957. },
  24958. get drawHeight() {
  24959. return Math.max(this.height,
  24960. this.smask && this.smask.height || 0,
  24961. this.mask && this.mask.height || 0);
  24962. },
  24963. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24964. var bpc = this.bpc;
  24965. var numComps = this.numComps;
  24966. var decodeAddends = this.decodeAddends;
  24967. var decodeCoefficients = this.decodeCoefficients;
  24968. var max = (1 << bpc) - 1;
  24969. var i, ii;
  24970. if (bpc === 1) {
  24971. // If the buffer needed decode that means it just needs to be inverted.
  24972. for (i = 0, ii = buffer.length; i < ii; i++) {
  24973. buffer[i] = +!(buffer[i]);
  24974. }
  24975. return;
  24976. }
  24977. var index = 0;
  24978. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24979. for (var j = 0; j < numComps; j++) {
  24980. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24981. decodeCoefficients[j], max);
  24982. index++;
  24983. }
  24984. }
  24985. },
  24986. getComponents: function PDFImage_getComponents(buffer) {
  24987. var bpc = this.bpc;
  24988. // This image doesn't require any extra work.
  24989. if (bpc === 8) {
  24990. return buffer;
  24991. }
  24992. var width = this.width;
  24993. var height = this.height;
  24994. var numComps = this.numComps;
  24995. var length = width * height * numComps;
  24996. var bufferPos = 0;
  24997. var output = (bpc <= 8 ? new Uint8Array(length) :
  24998. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24999. var rowComps = width * numComps;
  25000. var max = (1 << bpc) - 1;
  25001. var i = 0, ii, buf;
  25002. if (bpc === 1) {
  25003. // Optimization for reading 1 bpc images.
  25004. var mask, loop1End, loop2End;
  25005. for (var j = 0; j < height; j++) {
  25006. loop1End = i + (rowComps & ~7);
  25007. loop2End = i + rowComps;
  25008. // unroll loop for all full bytes
  25009. while (i < loop1End) {
  25010. buf = buffer[bufferPos++];
  25011. output[i] = (buf >> 7) & 1;
  25012. output[i + 1] = (buf >> 6) & 1;
  25013. output[i + 2] = (buf >> 5) & 1;
  25014. output[i + 3] = (buf >> 4) & 1;
  25015. output[i + 4] = (buf >> 3) & 1;
  25016. output[i + 5] = (buf >> 2) & 1;
  25017. output[i + 6] = (buf >> 1) & 1;
  25018. output[i + 7] = buf & 1;
  25019. i += 8;
  25020. }
  25021. // handle remaing bits
  25022. if (i < loop2End) {
  25023. buf = buffer[bufferPos++];
  25024. mask = 128;
  25025. while (i < loop2End) {
  25026. output[i++] = +!!(buf & mask);
  25027. mask >>= 1;
  25028. }
  25029. }
  25030. }
  25031. } else {
  25032. // The general case that handles all other bpc values.
  25033. var bits = 0;
  25034. buf = 0;
  25035. for (i = 0, ii = length; i < ii; ++i) {
  25036. if (i % rowComps === 0) {
  25037. buf = 0;
  25038. bits = 0;
  25039. }
  25040. while (bits < bpc) {
  25041. buf = (buf << 8) | buffer[bufferPos++];
  25042. bits += 8;
  25043. }
  25044. var remainingBits = bits - bpc;
  25045. var value = buf >> remainingBits;
  25046. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25047. buf = buf & ((1 << remainingBits) - 1);
  25048. bits = remainingBits;
  25049. }
  25050. }
  25051. return output;
  25052. },
  25053. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25054. actualHeight, image) {
  25055. var smask = this.smask;
  25056. var mask = this.mask;
  25057. var alphaBuf, sw, sh, i, ii, j;
  25058. if (smask) {
  25059. sw = smask.width;
  25060. sh = smask.height;
  25061. alphaBuf = new Uint8Array(sw * sh);
  25062. smask.fillGrayBuffer(alphaBuf);
  25063. if (sw !== width || sh !== height) {
  25064. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25065. height);
  25066. }
  25067. } else if (mask) {
  25068. if (mask instanceof PDFImage) {
  25069. sw = mask.width;
  25070. sh = mask.height;
  25071. alphaBuf = new Uint8Array(sw * sh);
  25072. mask.numComps = 1;
  25073. mask.fillGrayBuffer(alphaBuf);
  25074. // Need to invert values in rgbaBuf
  25075. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25076. alphaBuf[i] = 255 - alphaBuf[i];
  25077. }
  25078. if (sw !== width || sh !== height) {
  25079. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25080. height);
  25081. }
  25082. } else if (isArray(mask)) {
  25083. // Color key mask: if any of the compontents are outside the range
  25084. // then they should be painted.
  25085. alphaBuf = new Uint8Array(width * height);
  25086. var numComps = this.numComps;
  25087. for (i = 0, ii = width * height; i < ii; ++i) {
  25088. var opacity = 0;
  25089. var imageOffset = i * numComps;
  25090. for (j = 0; j < numComps; ++j) {
  25091. var color = image[imageOffset + j];
  25092. var maskOffset = j * 2;
  25093. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25094. opacity = 255;
  25095. break;
  25096. }
  25097. }
  25098. alphaBuf[i] = opacity;
  25099. }
  25100. } else {
  25101. error('Unknown mask format.');
  25102. }
  25103. }
  25104. if (alphaBuf) {
  25105. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25106. rgbaBuf[j] = alphaBuf[i];
  25107. }
  25108. } else {
  25109. // No mask.
  25110. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25111. rgbaBuf[j] = 255;
  25112. }
  25113. }
  25114. },
  25115. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25116. var matte = this.smask && this.smask.matte;
  25117. if (!matte) {
  25118. return;
  25119. }
  25120. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25121. var matteR = matteRgb[0];
  25122. var matteG = matteRgb[1];
  25123. var matteB = matteRgb[2];
  25124. var length = width * height * 4;
  25125. var r, g, b;
  25126. for (var i = 0; i < length; i += 4) {
  25127. var alpha = buffer[i + 3];
  25128. if (alpha === 0) {
  25129. // according formula we have to get Infinity in all components
  25130. // making it white (typical paper color) should be okay
  25131. buffer[i] = 255;
  25132. buffer[i + 1] = 255;
  25133. buffer[i + 2] = 255;
  25134. continue;
  25135. }
  25136. var k = 255 / alpha;
  25137. r = (buffer[i] - matteR) * k + matteR;
  25138. g = (buffer[i + 1] - matteG) * k + matteG;
  25139. b = (buffer[i + 2] - matteB) * k + matteB;
  25140. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25141. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25142. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25143. }
  25144. },
  25145. createImageData: function PDFImage_createImageData(forceRGBA) {
  25146. var drawWidth = this.drawWidth;
  25147. var drawHeight = this.drawHeight;
  25148. var imgData = { // other fields are filled in below
  25149. width: drawWidth,
  25150. height: drawHeight
  25151. };
  25152. var numComps = this.numComps;
  25153. var originalWidth = this.width;
  25154. var originalHeight = this.height;
  25155. var bpc = this.bpc;
  25156. // Rows start at byte boundary.
  25157. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25158. var imgArray;
  25159. if (!forceRGBA) {
  25160. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25161. // without any complications, we pass a same-sized copy to the main
  25162. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25163. // of memory for many scanned documents. It's also much faster.
  25164. //
  25165. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25166. // complications, we avoid expanding by 1.333x to RGBA form.
  25167. var kind;
  25168. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25169. kind = ImageKind.GRAYSCALE_1BPP;
  25170. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25171. !this.needsDecode) {
  25172. kind = ImageKind.RGB_24BPP;
  25173. }
  25174. if (kind && !this.smask && !this.mask &&
  25175. drawWidth === originalWidth && drawHeight === originalHeight) {
  25176. imgData.kind = kind;
  25177. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25178. // If imgArray came from a DecodeStream, we're safe to transfer it
  25179. // (and thus neuter it) because it will constitute the entire
  25180. // DecodeStream's data. But if it came from a Stream, we need to
  25181. // copy it because it'll only be a portion of the Stream's data, and
  25182. // the rest will be read later on.
  25183. if (this.image instanceof DecodeStream) {
  25184. imgData.data = imgArray;
  25185. } else {
  25186. var newArray = new Uint8Array(imgArray.length);
  25187. newArray.set(imgArray);
  25188. imgData.data = newArray;
  25189. }
  25190. if (this.needsDecode) {
  25191. // Invert the buffer (which must be grayscale if we reached here).
  25192. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25193. var buffer = imgData.data;
  25194. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25195. buffer[i] ^= 0xff;
  25196. }
  25197. }
  25198. return imgData;
  25199. }
  25200. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25201. imgData.kind = ImageKind.RGB_24BPP;
  25202. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25203. drawWidth, drawHeight, true);
  25204. return imgData;
  25205. }
  25206. }
  25207. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25208. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25209. var actualHeight = 0 | (imgArray.length / rowBytes *
  25210. drawHeight / originalHeight);
  25211. var comps = this.getComponents(imgArray);
  25212. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25213. // more compact RGB_24BPP form if allowable.
  25214. var alpha01, maybeUndoPreblend;
  25215. if (!forceRGBA && !this.smask && !this.mask) {
  25216. imgData.kind = ImageKind.RGB_24BPP;
  25217. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25218. alpha01 = 0;
  25219. maybeUndoPreblend = false;
  25220. } else {
  25221. imgData.kind = ImageKind.RGBA_32BPP;
  25222. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25223. alpha01 = 1;
  25224. maybeUndoPreblend = true;
  25225. // Color key masking (opacity) must be performed before decoding.
  25226. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25227. comps);
  25228. }
  25229. if (this.needsDecode) {
  25230. this.decodeBuffer(comps);
  25231. }
  25232. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25233. drawWidth, drawHeight, actualHeight, bpc, comps,
  25234. alpha01);
  25235. if (maybeUndoPreblend) {
  25236. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25237. }
  25238. return imgData;
  25239. },
  25240. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25241. var numComps = this.numComps;
  25242. if (numComps !== 1) {
  25243. error('Reading gray scale from a color image: ' + numComps);
  25244. }
  25245. var width = this.width;
  25246. var height = this.height;
  25247. var bpc = this.bpc;
  25248. // rows start at byte boundary
  25249. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25250. var imgArray = this.getImageBytes(height * rowBytes);
  25251. var comps = this.getComponents(imgArray);
  25252. var i, length;
  25253. if (bpc === 1) {
  25254. // inline decoding (= inversion) for 1 bpc images
  25255. length = width * height;
  25256. if (this.needsDecode) {
  25257. // invert and scale to {0, 255}
  25258. for (i = 0; i < length; ++i) {
  25259. buffer[i] = (comps[i] - 1) & 255;
  25260. }
  25261. } else {
  25262. // scale to {0, 255}
  25263. for (i = 0; i < length; ++i) {
  25264. buffer[i] = (-comps[i]) & 255;
  25265. }
  25266. }
  25267. return;
  25268. }
  25269. if (this.needsDecode) {
  25270. this.decodeBuffer(comps);
  25271. }
  25272. length = width * height;
  25273. // we aren't using a colorspace so we need to scale the value
  25274. var scale = 255 / ((1 << bpc) - 1);
  25275. for (i = 0; i < length; ++i) {
  25276. buffer[i] = (scale * comps[i]) | 0;
  25277. }
  25278. },
  25279. getImageBytes: function PDFImage_getImageBytes(length,
  25280. drawWidth, drawHeight,
  25281. forceRGB) {
  25282. this.image.reset();
  25283. this.image.drawWidth = drawWidth || this.width;
  25284. this.image.drawHeight = drawHeight || this.height;
  25285. this.image.forceRGB = !!forceRGB;
  25286. return this.image.getBytes(length);
  25287. }
  25288. };
  25289. return PDFImage;
  25290. })();
  25291. // The Metrics object contains glyph widths (in glyph space units).
  25292. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25293. // space unit corresponds to 1/1000th of text space unit.
  25294. var Metrics = {
  25295. 'Courier': 600,
  25296. 'Courier-Bold': 600,
  25297. 'Courier-BoldOblique': 600,
  25298. 'Courier-Oblique': 600,
  25299. 'Helvetica' : {
  25300. 'space': 278,
  25301. 'exclam': 278,
  25302. 'quotedbl': 355,
  25303. 'numbersign': 556,
  25304. 'dollar': 556,
  25305. 'percent': 889,
  25306. 'ampersand': 667,
  25307. 'quoteright': 222,
  25308. 'parenleft': 333,
  25309. 'parenright': 333,
  25310. 'asterisk': 389,
  25311. 'plus': 584,
  25312. 'comma': 278,
  25313. 'hyphen': 333,
  25314. 'period': 278,
  25315. 'slash': 278,
  25316. 'zero': 556,
  25317. 'one': 556,
  25318. 'two': 556,
  25319. 'three': 556,
  25320. 'four': 556,
  25321. 'five': 556,
  25322. 'six': 556,
  25323. 'seven': 556,
  25324. 'eight': 556,
  25325. 'nine': 556,
  25326. 'colon': 278,
  25327. 'semicolon': 278,
  25328. 'less': 584,
  25329. 'equal': 584,
  25330. 'greater': 584,
  25331. 'question': 556,
  25332. 'at': 1015,
  25333. 'A': 667,
  25334. 'B': 667,
  25335. 'C': 722,
  25336. 'D': 722,
  25337. 'E': 667,
  25338. 'F': 611,
  25339. 'G': 778,
  25340. 'H': 722,
  25341. 'I': 278,
  25342. 'J': 500,
  25343. 'K': 667,
  25344. 'L': 556,
  25345. 'M': 833,
  25346. 'N': 722,
  25347. 'O': 778,
  25348. 'P': 667,
  25349. 'Q': 778,
  25350. 'R': 722,
  25351. 'S': 667,
  25352. 'T': 611,
  25353. 'U': 722,
  25354. 'V': 667,
  25355. 'W': 944,
  25356. 'X': 667,
  25357. 'Y': 667,
  25358. 'Z': 611,
  25359. 'bracketleft': 278,
  25360. 'backslash': 278,
  25361. 'bracketright': 278,
  25362. 'asciicircum': 469,
  25363. 'underscore': 556,
  25364. 'quoteleft': 222,
  25365. 'a': 556,
  25366. 'b': 556,
  25367. 'c': 500,
  25368. 'd': 556,
  25369. 'e': 556,
  25370. 'f': 278,
  25371. 'g': 556,
  25372. 'h': 556,
  25373. 'i': 222,
  25374. 'j': 222,
  25375. 'k': 500,
  25376. 'l': 222,
  25377. 'm': 833,
  25378. 'n': 556,
  25379. 'o': 556,
  25380. 'p': 556,
  25381. 'q': 556,
  25382. 'r': 333,
  25383. 's': 500,
  25384. 't': 278,
  25385. 'u': 556,
  25386. 'v': 500,
  25387. 'w': 722,
  25388. 'x': 500,
  25389. 'y': 500,
  25390. 'z': 500,
  25391. 'braceleft': 334,
  25392. 'bar': 260,
  25393. 'braceright': 334,
  25394. 'asciitilde': 584,
  25395. 'exclamdown': 333,
  25396. 'cent': 556,
  25397. 'sterling': 556,
  25398. 'fraction': 167,
  25399. 'yen': 556,
  25400. 'florin': 556,
  25401. 'section': 556,
  25402. 'currency': 556,
  25403. 'quotesingle': 191,
  25404. 'quotedblleft': 333,
  25405. 'guillemotleft': 556,
  25406. 'guilsinglleft': 333,
  25407. 'guilsinglright': 333,
  25408. 'fi': 500,
  25409. 'fl': 500,
  25410. 'endash': 556,
  25411. 'dagger': 556,
  25412. 'daggerdbl': 556,
  25413. 'periodcentered': 278,
  25414. 'paragraph': 537,
  25415. 'bullet': 350,
  25416. 'quotesinglbase': 222,
  25417. 'quotedblbase': 333,
  25418. 'quotedblright': 333,
  25419. 'guillemotright': 556,
  25420. 'ellipsis': 1000,
  25421. 'perthousand': 1000,
  25422. 'questiondown': 611,
  25423. 'grave': 333,
  25424. 'acute': 333,
  25425. 'circumflex': 333,
  25426. 'tilde': 333,
  25427. 'macron': 333,
  25428. 'breve': 333,
  25429. 'dotaccent': 333,
  25430. 'dieresis': 333,
  25431. 'ring': 333,
  25432. 'cedilla': 333,
  25433. 'hungarumlaut': 333,
  25434. 'ogonek': 333,
  25435. 'caron': 333,
  25436. 'emdash': 1000,
  25437. 'AE': 1000,
  25438. 'ordfeminine': 370,
  25439. 'Lslash': 556,
  25440. 'Oslash': 778,
  25441. 'OE': 1000,
  25442. 'ordmasculine': 365,
  25443. 'ae': 889,
  25444. 'dotlessi': 278,
  25445. 'lslash': 222,
  25446. 'oslash': 611,
  25447. 'oe': 944,
  25448. 'germandbls': 611,
  25449. 'Idieresis': 278,
  25450. 'eacute': 556,
  25451. 'abreve': 556,
  25452. 'uhungarumlaut': 556,
  25453. 'ecaron': 556,
  25454. 'Ydieresis': 667,
  25455. 'divide': 584,
  25456. 'Yacute': 667,
  25457. 'Acircumflex': 667,
  25458. 'aacute': 556,
  25459. 'Ucircumflex': 722,
  25460. 'yacute': 500,
  25461. 'scommaaccent': 500,
  25462. 'ecircumflex': 556,
  25463. 'Uring': 722,
  25464. 'Udieresis': 722,
  25465. 'aogonek': 556,
  25466. 'Uacute': 722,
  25467. 'uogonek': 556,
  25468. 'Edieresis': 667,
  25469. 'Dcroat': 722,
  25470. 'commaaccent': 250,
  25471. 'copyright': 737,
  25472. 'Emacron': 667,
  25473. 'ccaron': 500,
  25474. 'aring': 556,
  25475. 'Ncommaaccent': 722,
  25476. 'lacute': 222,
  25477. 'agrave': 556,
  25478. 'Tcommaaccent': 611,
  25479. 'Cacute': 722,
  25480. 'atilde': 556,
  25481. 'Edotaccent': 667,
  25482. 'scaron': 500,
  25483. 'scedilla': 500,
  25484. 'iacute': 278,
  25485. 'lozenge': 471,
  25486. 'Rcaron': 722,
  25487. 'Gcommaaccent': 778,
  25488. 'ucircumflex': 556,
  25489. 'acircumflex': 556,
  25490. 'Amacron': 667,
  25491. 'rcaron': 333,
  25492. 'ccedilla': 500,
  25493. 'Zdotaccent': 611,
  25494. 'Thorn': 667,
  25495. 'Omacron': 778,
  25496. 'Racute': 722,
  25497. 'Sacute': 667,
  25498. 'dcaron': 643,
  25499. 'Umacron': 722,
  25500. 'uring': 556,
  25501. 'threesuperior': 333,
  25502. 'Ograve': 778,
  25503. 'Agrave': 667,
  25504. 'Abreve': 667,
  25505. 'multiply': 584,
  25506. 'uacute': 556,
  25507. 'Tcaron': 611,
  25508. 'partialdiff': 476,
  25509. 'ydieresis': 500,
  25510. 'Nacute': 722,
  25511. 'icircumflex': 278,
  25512. 'Ecircumflex': 667,
  25513. 'adieresis': 556,
  25514. 'edieresis': 556,
  25515. 'cacute': 500,
  25516. 'nacute': 556,
  25517. 'umacron': 556,
  25518. 'Ncaron': 722,
  25519. 'Iacute': 278,
  25520. 'plusminus': 584,
  25521. 'brokenbar': 260,
  25522. 'registered': 737,
  25523. 'Gbreve': 778,
  25524. 'Idotaccent': 278,
  25525. 'summation': 600,
  25526. 'Egrave': 667,
  25527. 'racute': 333,
  25528. 'omacron': 556,
  25529. 'Zacute': 611,
  25530. 'Zcaron': 611,
  25531. 'greaterequal': 549,
  25532. 'Eth': 722,
  25533. 'Ccedilla': 722,
  25534. 'lcommaaccent': 222,
  25535. 'tcaron': 317,
  25536. 'eogonek': 556,
  25537. 'Uogonek': 722,
  25538. 'Aacute': 667,
  25539. 'Adieresis': 667,
  25540. 'egrave': 556,
  25541. 'zacute': 500,
  25542. 'iogonek': 222,
  25543. 'Oacute': 778,
  25544. 'oacute': 556,
  25545. 'amacron': 556,
  25546. 'sacute': 500,
  25547. 'idieresis': 278,
  25548. 'Ocircumflex': 778,
  25549. 'Ugrave': 722,
  25550. 'Delta': 612,
  25551. 'thorn': 556,
  25552. 'twosuperior': 333,
  25553. 'Odieresis': 778,
  25554. 'mu': 556,
  25555. 'igrave': 278,
  25556. 'ohungarumlaut': 556,
  25557. 'Eogonek': 667,
  25558. 'dcroat': 556,
  25559. 'threequarters': 834,
  25560. 'Scedilla': 667,
  25561. 'lcaron': 299,
  25562. 'Kcommaaccent': 667,
  25563. 'Lacute': 556,
  25564. 'trademark': 1000,
  25565. 'edotaccent': 556,
  25566. 'Igrave': 278,
  25567. 'Imacron': 278,
  25568. 'Lcaron': 556,
  25569. 'onehalf': 834,
  25570. 'lessequal': 549,
  25571. 'ocircumflex': 556,
  25572. 'ntilde': 556,
  25573. 'Uhungarumlaut': 722,
  25574. 'Eacute': 667,
  25575. 'emacron': 556,
  25576. 'gbreve': 556,
  25577. 'onequarter': 834,
  25578. 'Scaron': 667,
  25579. 'Scommaaccent': 667,
  25580. 'Ohungarumlaut': 778,
  25581. 'degree': 400,
  25582. 'ograve': 556,
  25583. 'Ccaron': 722,
  25584. 'ugrave': 556,
  25585. 'radical': 453,
  25586. 'Dcaron': 722,
  25587. 'rcommaaccent': 333,
  25588. 'Ntilde': 722,
  25589. 'otilde': 556,
  25590. 'Rcommaaccent': 722,
  25591. 'Lcommaaccent': 556,
  25592. 'Atilde': 667,
  25593. 'Aogonek': 667,
  25594. 'Aring': 667,
  25595. 'Otilde': 778,
  25596. 'zdotaccent': 500,
  25597. 'Ecaron': 667,
  25598. 'Iogonek': 278,
  25599. 'kcommaaccent': 500,
  25600. 'minus': 584,
  25601. 'Icircumflex': 278,
  25602. 'ncaron': 556,
  25603. 'tcommaaccent': 278,
  25604. 'logicalnot': 584,
  25605. 'odieresis': 556,
  25606. 'udieresis': 556,
  25607. 'notequal': 549,
  25608. 'gcommaaccent': 556,
  25609. 'eth': 556,
  25610. 'zcaron': 500,
  25611. 'ncommaaccent': 556,
  25612. 'onesuperior': 333,
  25613. 'imacron': 278,
  25614. 'Euro': 556
  25615. },
  25616. 'Helvetica-Bold': {
  25617. 'space': 278,
  25618. 'exclam': 333,
  25619. 'quotedbl': 474,
  25620. 'numbersign': 556,
  25621. 'dollar': 556,
  25622. 'percent': 889,
  25623. 'ampersand': 722,
  25624. 'quoteright': 278,
  25625. 'parenleft': 333,
  25626. 'parenright': 333,
  25627. 'asterisk': 389,
  25628. 'plus': 584,
  25629. 'comma': 278,
  25630. 'hyphen': 333,
  25631. 'period': 278,
  25632. 'slash': 278,
  25633. 'zero': 556,
  25634. 'one': 556,
  25635. 'two': 556,
  25636. 'three': 556,
  25637. 'four': 556,
  25638. 'five': 556,
  25639. 'six': 556,
  25640. 'seven': 556,
  25641. 'eight': 556,
  25642. 'nine': 556,
  25643. 'colon': 333,
  25644. 'semicolon': 333,
  25645. 'less': 584,
  25646. 'equal': 584,
  25647. 'greater': 584,
  25648. 'question': 611,
  25649. 'at': 975,
  25650. 'A': 722,
  25651. 'B': 722,
  25652. 'C': 722,
  25653. 'D': 722,
  25654. 'E': 667,
  25655. 'F': 611,
  25656. 'G': 778,
  25657. 'H': 722,
  25658. 'I': 278,
  25659. 'J': 556,
  25660. 'K': 722,
  25661. 'L': 611,
  25662. 'M': 833,
  25663. 'N': 722,
  25664. 'O': 778,
  25665. 'P': 667,
  25666. 'Q': 778,
  25667. 'R': 722,
  25668. 'S': 667,
  25669. 'T': 611,
  25670. 'U': 722,
  25671. 'V': 667,
  25672. 'W': 944,
  25673. 'X': 667,
  25674. 'Y': 667,
  25675. 'Z': 611,
  25676. 'bracketleft': 333,
  25677. 'backslash': 278,
  25678. 'bracketright': 333,
  25679. 'asciicircum': 584,
  25680. 'underscore': 556,
  25681. 'quoteleft': 278,
  25682. 'a': 556,
  25683. 'b': 611,
  25684. 'c': 556,
  25685. 'd': 611,
  25686. 'e': 556,
  25687. 'f': 333,
  25688. 'g': 611,
  25689. 'h': 611,
  25690. 'i': 278,
  25691. 'j': 278,
  25692. 'k': 556,
  25693. 'l': 278,
  25694. 'm': 889,
  25695. 'n': 611,
  25696. 'o': 611,
  25697. 'p': 611,
  25698. 'q': 611,
  25699. 'r': 389,
  25700. 's': 556,
  25701. 't': 333,
  25702. 'u': 611,
  25703. 'v': 556,
  25704. 'w': 778,
  25705. 'x': 556,
  25706. 'y': 556,
  25707. 'z': 500,
  25708. 'braceleft': 389,
  25709. 'bar': 280,
  25710. 'braceright': 389,
  25711. 'asciitilde': 584,
  25712. 'exclamdown': 333,
  25713. 'cent': 556,
  25714. 'sterling': 556,
  25715. 'fraction': 167,
  25716. 'yen': 556,
  25717. 'florin': 556,
  25718. 'section': 556,
  25719. 'currency': 556,
  25720. 'quotesingle': 238,
  25721. 'quotedblleft': 500,
  25722. 'guillemotleft': 556,
  25723. 'guilsinglleft': 333,
  25724. 'guilsinglright': 333,
  25725. 'fi': 611,
  25726. 'fl': 611,
  25727. 'endash': 556,
  25728. 'dagger': 556,
  25729. 'daggerdbl': 556,
  25730. 'periodcentered': 278,
  25731. 'paragraph': 556,
  25732. 'bullet': 350,
  25733. 'quotesinglbase': 278,
  25734. 'quotedblbase': 500,
  25735. 'quotedblright': 500,
  25736. 'guillemotright': 556,
  25737. 'ellipsis': 1000,
  25738. 'perthousand': 1000,
  25739. 'questiondown': 611,
  25740. 'grave': 333,
  25741. 'acute': 333,
  25742. 'circumflex': 333,
  25743. 'tilde': 333,
  25744. 'macron': 333,
  25745. 'breve': 333,
  25746. 'dotaccent': 333,
  25747. 'dieresis': 333,
  25748. 'ring': 333,
  25749. 'cedilla': 333,
  25750. 'hungarumlaut': 333,
  25751. 'ogonek': 333,
  25752. 'caron': 333,
  25753. 'emdash': 1000,
  25754. 'AE': 1000,
  25755. 'ordfeminine': 370,
  25756. 'Lslash': 611,
  25757. 'Oslash': 778,
  25758. 'OE': 1000,
  25759. 'ordmasculine': 365,
  25760. 'ae': 889,
  25761. 'dotlessi': 278,
  25762. 'lslash': 278,
  25763. 'oslash': 611,
  25764. 'oe': 944,
  25765. 'germandbls': 611,
  25766. 'Idieresis': 278,
  25767. 'eacute': 556,
  25768. 'abreve': 556,
  25769. 'uhungarumlaut': 611,
  25770. 'ecaron': 556,
  25771. 'Ydieresis': 667,
  25772. 'divide': 584,
  25773. 'Yacute': 667,
  25774. 'Acircumflex': 722,
  25775. 'aacute': 556,
  25776. 'Ucircumflex': 722,
  25777. 'yacute': 556,
  25778. 'scommaaccent': 556,
  25779. 'ecircumflex': 556,
  25780. 'Uring': 722,
  25781. 'Udieresis': 722,
  25782. 'aogonek': 556,
  25783. 'Uacute': 722,
  25784. 'uogonek': 611,
  25785. 'Edieresis': 667,
  25786. 'Dcroat': 722,
  25787. 'commaaccent': 250,
  25788. 'copyright': 737,
  25789. 'Emacron': 667,
  25790. 'ccaron': 556,
  25791. 'aring': 556,
  25792. 'Ncommaaccent': 722,
  25793. 'lacute': 278,
  25794. 'agrave': 556,
  25795. 'Tcommaaccent': 611,
  25796. 'Cacute': 722,
  25797. 'atilde': 556,
  25798. 'Edotaccent': 667,
  25799. 'scaron': 556,
  25800. 'scedilla': 556,
  25801. 'iacute': 278,
  25802. 'lozenge': 494,
  25803. 'Rcaron': 722,
  25804. 'Gcommaaccent': 778,
  25805. 'ucircumflex': 611,
  25806. 'acircumflex': 556,
  25807. 'Amacron': 722,
  25808. 'rcaron': 389,
  25809. 'ccedilla': 556,
  25810. 'Zdotaccent': 611,
  25811. 'Thorn': 667,
  25812. 'Omacron': 778,
  25813. 'Racute': 722,
  25814. 'Sacute': 667,
  25815. 'dcaron': 743,
  25816. 'Umacron': 722,
  25817. 'uring': 611,
  25818. 'threesuperior': 333,
  25819. 'Ograve': 778,
  25820. 'Agrave': 722,
  25821. 'Abreve': 722,
  25822. 'multiply': 584,
  25823. 'uacute': 611,
  25824. 'Tcaron': 611,
  25825. 'partialdiff': 494,
  25826. 'ydieresis': 556,
  25827. 'Nacute': 722,
  25828. 'icircumflex': 278,
  25829. 'Ecircumflex': 667,
  25830. 'adieresis': 556,
  25831. 'edieresis': 556,
  25832. 'cacute': 556,
  25833. 'nacute': 611,
  25834. 'umacron': 611,
  25835. 'Ncaron': 722,
  25836. 'Iacute': 278,
  25837. 'plusminus': 584,
  25838. 'brokenbar': 280,
  25839. 'registered': 737,
  25840. 'Gbreve': 778,
  25841. 'Idotaccent': 278,
  25842. 'summation': 600,
  25843. 'Egrave': 667,
  25844. 'racute': 389,
  25845. 'omacron': 611,
  25846. 'Zacute': 611,
  25847. 'Zcaron': 611,
  25848. 'greaterequal': 549,
  25849. 'Eth': 722,
  25850. 'Ccedilla': 722,
  25851. 'lcommaaccent': 278,
  25852. 'tcaron': 389,
  25853. 'eogonek': 556,
  25854. 'Uogonek': 722,
  25855. 'Aacute': 722,
  25856. 'Adieresis': 722,
  25857. 'egrave': 556,
  25858. 'zacute': 500,
  25859. 'iogonek': 278,
  25860. 'Oacute': 778,
  25861. 'oacute': 611,
  25862. 'amacron': 556,
  25863. 'sacute': 556,
  25864. 'idieresis': 278,
  25865. 'Ocircumflex': 778,
  25866. 'Ugrave': 722,
  25867. 'Delta': 612,
  25868. 'thorn': 611,
  25869. 'twosuperior': 333,
  25870. 'Odieresis': 778,
  25871. 'mu': 611,
  25872. 'igrave': 278,
  25873. 'ohungarumlaut': 611,
  25874. 'Eogonek': 667,
  25875. 'dcroat': 611,
  25876. 'threequarters': 834,
  25877. 'Scedilla': 667,
  25878. 'lcaron': 400,
  25879. 'Kcommaaccent': 722,
  25880. 'Lacute': 611,
  25881. 'trademark': 1000,
  25882. 'edotaccent': 556,
  25883. 'Igrave': 278,
  25884. 'Imacron': 278,
  25885. 'Lcaron': 611,
  25886. 'onehalf': 834,
  25887. 'lessequal': 549,
  25888. 'ocircumflex': 611,
  25889. 'ntilde': 611,
  25890. 'Uhungarumlaut': 722,
  25891. 'Eacute': 667,
  25892. 'emacron': 556,
  25893. 'gbreve': 611,
  25894. 'onequarter': 834,
  25895. 'Scaron': 667,
  25896. 'Scommaaccent': 667,
  25897. 'Ohungarumlaut': 778,
  25898. 'degree': 400,
  25899. 'ograve': 611,
  25900. 'Ccaron': 722,
  25901. 'ugrave': 611,
  25902. 'radical': 549,
  25903. 'Dcaron': 722,
  25904. 'rcommaaccent': 389,
  25905. 'Ntilde': 722,
  25906. 'otilde': 611,
  25907. 'Rcommaaccent': 722,
  25908. 'Lcommaaccent': 611,
  25909. 'Atilde': 722,
  25910. 'Aogonek': 722,
  25911. 'Aring': 722,
  25912. 'Otilde': 778,
  25913. 'zdotaccent': 500,
  25914. 'Ecaron': 667,
  25915. 'Iogonek': 278,
  25916. 'kcommaaccent': 556,
  25917. 'minus': 584,
  25918. 'Icircumflex': 278,
  25919. 'ncaron': 611,
  25920. 'tcommaaccent': 333,
  25921. 'logicalnot': 584,
  25922. 'odieresis': 611,
  25923. 'udieresis': 611,
  25924. 'notequal': 549,
  25925. 'gcommaaccent': 611,
  25926. 'eth': 611,
  25927. 'zcaron': 500,
  25928. 'ncommaaccent': 611,
  25929. 'onesuperior': 333,
  25930. 'imacron': 278,
  25931. 'Euro': 556
  25932. },
  25933. 'Helvetica-BoldOblique': {
  25934. 'space': 278,
  25935. 'exclam': 333,
  25936. 'quotedbl': 474,
  25937. 'numbersign': 556,
  25938. 'dollar': 556,
  25939. 'percent': 889,
  25940. 'ampersand': 722,
  25941. 'quoteright': 278,
  25942. 'parenleft': 333,
  25943. 'parenright': 333,
  25944. 'asterisk': 389,
  25945. 'plus': 584,
  25946. 'comma': 278,
  25947. 'hyphen': 333,
  25948. 'period': 278,
  25949. 'slash': 278,
  25950. 'zero': 556,
  25951. 'one': 556,
  25952. 'two': 556,
  25953. 'three': 556,
  25954. 'four': 556,
  25955. 'five': 556,
  25956. 'six': 556,
  25957. 'seven': 556,
  25958. 'eight': 556,
  25959. 'nine': 556,
  25960. 'colon': 333,
  25961. 'semicolon': 333,
  25962. 'less': 584,
  25963. 'equal': 584,
  25964. 'greater': 584,
  25965. 'question': 611,
  25966. 'at': 975,
  25967. 'A': 722,
  25968. 'B': 722,
  25969. 'C': 722,
  25970. 'D': 722,
  25971. 'E': 667,
  25972. 'F': 611,
  25973. 'G': 778,
  25974. 'H': 722,
  25975. 'I': 278,
  25976. 'J': 556,
  25977. 'K': 722,
  25978. 'L': 611,
  25979. 'M': 833,
  25980. 'N': 722,
  25981. 'O': 778,
  25982. 'P': 667,
  25983. 'Q': 778,
  25984. 'R': 722,
  25985. 'S': 667,
  25986. 'T': 611,
  25987. 'U': 722,
  25988. 'V': 667,
  25989. 'W': 944,
  25990. 'X': 667,
  25991. 'Y': 667,
  25992. 'Z': 611,
  25993. 'bracketleft': 333,
  25994. 'backslash': 278,
  25995. 'bracketright': 333,
  25996. 'asciicircum': 584,
  25997. 'underscore': 556,
  25998. 'quoteleft': 278,
  25999. 'a': 556,
  26000. 'b': 611,
  26001. 'c': 556,
  26002. 'd': 611,
  26003. 'e': 556,
  26004. 'f': 333,
  26005. 'g': 611,
  26006. 'h': 611,
  26007. 'i': 278,
  26008. 'j': 278,
  26009. 'k': 556,
  26010. 'l': 278,
  26011. 'm': 889,
  26012. 'n': 611,
  26013. 'o': 611,
  26014. 'p': 611,
  26015. 'q': 611,
  26016. 'r': 389,
  26017. 's': 556,
  26018. 't': 333,
  26019. 'u': 611,
  26020. 'v': 556,
  26021. 'w': 778,
  26022. 'x': 556,
  26023. 'y': 556,
  26024. 'z': 500,
  26025. 'braceleft': 389,
  26026. 'bar': 280,
  26027. 'braceright': 389,
  26028. 'asciitilde': 584,
  26029. 'exclamdown': 333,
  26030. 'cent': 556,
  26031. 'sterling': 556,
  26032. 'fraction': 167,
  26033. 'yen': 556,
  26034. 'florin': 556,
  26035. 'section': 556,
  26036. 'currency': 556,
  26037. 'quotesingle': 238,
  26038. 'quotedblleft': 500,
  26039. 'guillemotleft': 556,
  26040. 'guilsinglleft': 333,
  26041. 'guilsinglright': 333,
  26042. 'fi': 611,
  26043. 'fl': 611,
  26044. 'endash': 556,
  26045. 'dagger': 556,
  26046. 'daggerdbl': 556,
  26047. 'periodcentered': 278,
  26048. 'paragraph': 556,
  26049. 'bullet': 350,
  26050. 'quotesinglbase': 278,
  26051. 'quotedblbase': 500,
  26052. 'quotedblright': 500,
  26053. 'guillemotright': 556,
  26054. 'ellipsis': 1000,
  26055. 'perthousand': 1000,
  26056. 'questiondown': 611,
  26057. 'grave': 333,
  26058. 'acute': 333,
  26059. 'circumflex': 333,
  26060. 'tilde': 333,
  26061. 'macron': 333,
  26062. 'breve': 333,
  26063. 'dotaccent': 333,
  26064. 'dieresis': 333,
  26065. 'ring': 333,
  26066. 'cedilla': 333,
  26067. 'hungarumlaut': 333,
  26068. 'ogonek': 333,
  26069. 'caron': 333,
  26070. 'emdash': 1000,
  26071. 'AE': 1000,
  26072. 'ordfeminine': 370,
  26073. 'Lslash': 611,
  26074. 'Oslash': 778,
  26075. 'OE': 1000,
  26076. 'ordmasculine': 365,
  26077. 'ae': 889,
  26078. 'dotlessi': 278,
  26079. 'lslash': 278,
  26080. 'oslash': 611,
  26081. 'oe': 944,
  26082. 'germandbls': 611,
  26083. 'Idieresis': 278,
  26084. 'eacute': 556,
  26085. 'abreve': 556,
  26086. 'uhungarumlaut': 611,
  26087. 'ecaron': 556,
  26088. 'Ydieresis': 667,
  26089. 'divide': 584,
  26090. 'Yacute': 667,
  26091. 'Acircumflex': 722,
  26092. 'aacute': 556,
  26093. 'Ucircumflex': 722,
  26094. 'yacute': 556,
  26095. 'scommaaccent': 556,
  26096. 'ecircumflex': 556,
  26097. 'Uring': 722,
  26098. 'Udieresis': 722,
  26099. 'aogonek': 556,
  26100. 'Uacute': 722,
  26101. 'uogonek': 611,
  26102. 'Edieresis': 667,
  26103. 'Dcroat': 722,
  26104. 'commaaccent': 250,
  26105. 'copyright': 737,
  26106. 'Emacron': 667,
  26107. 'ccaron': 556,
  26108. 'aring': 556,
  26109. 'Ncommaaccent': 722,
  26110. 'lacute': 278,
  26111. 'agrave': 556,
  26112. 'Tcommaaccent': 611,
  26113. 'Cacute': 722,
  26114. 'atilde': 556,
  26115. 'Edotaccent': 667,
  26116. 'scaron': 556,
  26117. 'scedilla': 556,
  26118. 'iacute': 278,
  26119. 'lozenge': 494,
  26120. 'Rcaron': 722,
  26121. 'Gcommaaccent': 778,
  26122. 'ucircumflex': 611,
  26123. 'acircumflex': 556,
  26124. 'Amacron': 722,
  26125. 'rcaron': 389,
  26126. 'ccedilla': 556,
  26127. 'Zdotaccent': 611,
  26128. 'Thorn': 667,
  26129. 'Omacron': 778,
  26130. 'Racute': 722,
  26131. 'Sacute': 667,
  26132. 'dcaron': 743,
  26133. 'Umacron': 722,
  26134. 'uring': 611,
  26135. 'threesuperior': 333,
  26136. 'Ograve': 778,
  26137. 'Agrave': 722,
  26138. 'Abreve': 722,
  26139. 'multiply': 584,
  26140. 'uacute': 611,
  26141. 'Tcaron': 611,
  26142. 'partialdiff': 494,
  26143. 'ydieresis': 556,
  26144. 'Nacute': 722,
  26145. 'icircumflex': 278,
  26146. 'Ecircumflex': 667,
  26147. 'adieresis': 556,
  26148. 'edieresis': 556,
  26149. 'cacute': 556,
  26150. 'nacute': 611,
  26151. 'umacron': 611,
  26152. 'Ncaron': 722,
  26153. 'Iacute': 278,
  26154. 'plusminus': 584,
  26155. 'brokenbar': 280,
  26156. 'registered': 737,
  26157. 'Gbreve': 778,
  26158. 'Idotaccent': 278,
  26159. 'summation': 600,
  26160. 'Egrave': 667,
  26161. 'racute': 389,
  26162. 'omacron': 611,
  26163. 'Zacute': 611,
  26164. 'Zcaron': 611,
  26165. 'greaterequal': 549,
  26166. 'Eth': 722,
  26167. 'Ccedilla': 722,
  26168. 'lcommaaccent': 278,
  26169. 'tcaron': 389,
  26170. 'eogonek': 556,
  26171. 'Uogonek': 722,
  26172. 'Aacute': 722,
  26173. 'Adieresis': 722,
  26174. 'egrave': 556,
  26175. 'zacute': 500,
  26176. 'iogonek': 278,
  26177. 'Oacute': 778,
  26178. 'oacute': 611,
  26179. 'amacron': 556,
  26180. 'sacute': 556,
  26181. 'idieresis': 278,
  26182. 'Ocircumflex': 778,
  26183. 'Ugrave': 722,
  26184. 'Delta': 612,
  26185. 'thorn': 611,
  26186. 'twosuperior': 333,
  26187. 'Odieresis': 778,
  26188. 'mu': 611,
  26189. 'igrave': 278,
  26190. 'ohungarumlaut': 611,
  26191. 'Eogonek': 667,
  26192. 'dcroat': 611,
  26193. 'threequarters': 834,
  26194. 'Scedilla': 667,
  26195. 'lcaron': 400,
  26196. 'Kcommaaccent': 722,
  26197. 'Lacute': 611,
  26198. 'trademark': 1000,
  26199. 'edotaccent': 556,
  26200. 'Igrave': 278,
  26201. 'Imacron': 278,
  26202. 'Lcaron': 611,
  26203. 'onehalf': 834,
  26204. 'lessequal': 549,
  26205. 'ocircumflex': 611,
  26206. 'ntilde': 611,
  26207. 'Uhungarumlaut': 722,
  26208. 'Eacute': 667,
  26209. 'emacron': 556,
  26210. 'gbreve': 611,
  26211. 'onequarter': 834,
  26212. 'Scaron': 667,
  26213. 'Scommaaccent': 667,
  26214. 'Ohungarumlaut': 778,
  26215. 'degree': 400,
  26216. 'ograve': 611,
  26217. 'Ccaron': 722,
  26218. 'ugrave': 611,
  26219. 'radical': 549,
  26220. 'Dcaron': 722,
  26221. 'rcommaaccent': 389,
  26222. 'Ntilde': 722,
  26223. 'otilde': 611,
  26224. 'Rcommaaccent': 722,
  26225. 'Lcommaaccent': 611,
  26226. 'Atilde': 722,
  26227. 'Aogonek': 722,
  26228. 'Aring': 722,
  26229. 'Otilde': 778,
  26230. 'zdotaccent': 500,
  26231. 'Ecaron': 667,
  26232. 'Iogonek': 278,
  26233. 'kcommaaccent': 556,
  26234. 'minus': 584,
  26235. 'Icircumflex': 278,
  26236. 'ncaron': 611,
  26237. 'tcommaaccent': 333,
  26238. 'logicalnot': 584,
  26239. 'odieresis': 611,
  26240. 'udieresis': 611,
  26241. 'notequal': 549,
  26242. 'gcommaaccent': 611,
  26243. 'eth': 611,
  26244. 'zcaron': 500,
  26245. 'ncommaaccent': 611,
  26246. 'onesuperior': 333,
  26247. 'imacron': 278,
  26248. 'Euro': 556
  26249. },
  26250. 'Helvetica-Oblique' : {
  26251. 'space': 278,
  26252. 'exclam': 278,
  26253. 'quotedbl': 355,
  26254. 'numbersign': 556,
  26255. 'dollar': 556,
  26256. 'percent': 889,
  26257. 'ampersand': 667,
  26258. 'quoteright': 222,
  26259. 'parenleft': 333,
  26260. 'parenright': 333,
  26261. 'asterisk': 389,
  26262. 'plus': 584,
  26263. 'comma': 278,
  26264. 'hyphen': 333,
  26265. 'period': 278,
  26266. 'slash': 278,
  26267. 'zero': 556,
  26268. 'one': 556,
  26269. 'two': 556,
  26270. 'three': 556,
  26271. 'four': 556,
  26272. 'five': 556,
  26273. 'six': 556,
  26274. 'seven': 556,
  26275. 'eight': 556,
  26276. 'nine': 556,
  26277. 'colon': 278,
  26278. 'semicolon': 278,
  26279. 'less': 584,
  26280. 'equal': 584,
  26281. 'greater': 584,
  26282. 'question': 556,
  26283. 'at': 1015,
  26284. 'A': 667,
  26285. 'B': 667,
  26286. 'C': 722,
  26287. 'D': 722,
  26288. 'E': 667,
  26289. 'F': 611,
  26290. 'G': 778,
  26291. 'H': 722,
  26292. 'I': 278,
  26293. 'J': 500,
  26294. 'K': 667,
  26295. 'L': 556,
  26296. 'M': 833,
  26297. 'N': 722,
  26298. 'O': 778,
  26299. 'P': 667,
  26300. 'Q': 778,
  26301. 'R': 722,
  26302. 'S': 667,
  26303. 'T': 611,
  26304. 'U': 722,
  26305. 'V': 667,
  26306. 'W': 944,
  26307. 'X': 667,
  26308. 'Y': 667,
  26309. 'Z': 611,
  26310. 'bracketleft': 278,
  26311. 'backslash': 278,
  26312. 'bracketright': 278,
  26313. 'asciicircum': 469,
  26314. 'underscore': 556,
  26315. 'quoteleft': 222,
  26316. 'a': 556,
  26317. 'b': 556,
  26318. 'c': 500,
  26319. 'd': 556,
  26320. 'e': 556,
  26321. 'f': 278,
  26322. 'g': 556,
  26323. 'h': 556,
  26324. 'i': 222,
  26325. 'j': 222,
  26326. 'k': 500,
  26327. 'l': 222,
  26328. 'm': 833,
  26329. 'n': 556,
  26330. 'o': 556,
  26331. 'p': 556,
  26332. 'q': 556,
  26333. 'r': 333,
  26334. 's': 500,
  26335. 't': 278,
  26336. 'u': 556,
  26337. 'v': 500,
  26338. 'w': 722,
  26339. 'x': 500,
  26340. 'y': 500,
  26341. 'z': 500,
  26342. 'braceleft': 334,
  26343. 'bar': 260,
  26344. 'braceright': 334,
  26345. 'asciitilde': 584,
  26346. 'exclamdown': 333,
  26347. 'cent': 556,
  26348. 'sterling': 556,
  26349. 'fraction': 167,
  26350. 'yen': 556,
  26351. 'florin': 556,
  26352. 'section': 556,
  26353. 'currency': 556,
  26354. 'quotesingle': 191,
  26355. 'quotedblleft': 333,
  26356. 'guillemotleft': 556,
  26357. 'guilsinglleft': 333,
  26358. 'guilsinglright': 333,
  26359. 'fi': 500,
  26360. 'fl': 500,
  26361. 'endash': 556,
  26362. 'dagger': 556,
  26363. 'daggerdbl': 556,
  26364. 'periodcentered': 278,
  26365. 'paragraph': 537,
  26366. 'bullet': 350,
  26367. 'quotesinglbase': 222,
  26368. 'quotedblbase': 333,
  26369. 'quotedblright': 333,
  26370. 'guillemotright': 556,
  26371. 'ellipsis': 1000,
  26372. 'perthousand': 1000,
  26373. 'questiondown': 611,
  26374. 'grave': 333,
  26375. 'acute': 333,
  26376. 'circumflex': 333,
  26377. 'tilde': 333,
  26378. 'macron': 333,
  26379. 'breve': 333,
  26380. 'dotaccent': 333,
  26381. 'dieresis': 333,
  26382. 'ring': 333,
  26383. 'cedilla': 333,
  26384. 'hungarumlaut': 333,
  26385. 'ogonek': 333,
  26386. 'caron': 333,
  26387. 'emdash': 1000,
  26388. 'AE': 1000,
  26389. 'ordfeminine': 370,
  26390. 'Lslash': 556,
  26391. 'Oslash': 778,
  26392. 'OE': 1000,
  26393. 'ordmasculine': 365,
  26394. 'ae': 889,
  26395. 'dotlessi': 278,
  26396. 'lslash': 222,
  26397. 'oslash': 611,
  26398. 'oe': 944,
  26399. 'germandbls': 611,
  26400. 'Idieresis': 278,
  26401. 'eacute': 556,
  26402. 'abreve': 556,
  26403. 'uhungarumlaut': 556,
  26404. 'ecaron': 556,
  26405. 'Ydieresis': 667,
  26406. 'divide': 584,
  26407. 'Yacute': 667,
  26408. 'Acircumflex': 667,
  26409. 'aacute': 556,
  26410. 'Ucircumflex': 722,
  26411. 'yacute': 500,
  26412. 'scommaaccent': 500,
  26413. 'ecircumflex': 556,
  26414. 'Uring': 722,
  26415. 'Udieresis': 722,
  26416. 'aogonek': 556,
  26417. 'Uacute': 722,
  26418. 'uogonek': 556,
  26419. 'Edieresis': 667,
  26420. 'Dcroat': 722,
  26421. 'commaaccent': 250,
  26422. 'copyright': 737,
  26423. 'Emacron': 667,
  26424. 'ccaron': 500,
  26425. 'aring': 556,
  26426. 'Ncommaaccent': 722,
  26427. 'lacute': 222,
  26428. 'agrave': 556,
  26429. 'Tcommaaccent': 611,
  26430. 'Cacute': 722,
  26431. 'atilde': 556,
  26432. 'Edotaccent': 667,
  26433. 'scaron': 500,
  26434. 'scedilla': 500,
  26435. 'iacute': 278,
  26436. 'lozenge': 471,
  26437. 'Rcaron': 722,
  26438. 'Gcommaaccent': 778,
  26439. 'ucircumflex': 556,
  26440. 'acircumflex': 556,
  26441. 'Amacron': 667,
  26442. 'rcaron': 333,
  26443. 'ccedilla': 500,
  26444. 'Zdotaccent': 611,
  26445. 'Thorn': 667,
  26446. 'Omacron': 778,
  26447. 'Racute': 722,
  26448. 'Sacute': 667,
  26449. 'dcaron': 643,
  26450. 'Umacron': 722,
  26451. 'uring': 556,
  26452. 'threesuperior': 333,
  26453. 'Ograve': 778,
  26454. 'Agrave': 667,
  26455. 'Abreve': 667,
  26456. 'multiply': 584,
  26457. 'uacute': 556,
  26458. 'Tcaron': 611,
  26459. 'partialdiff': 476,
  26460. 'ydieresis': 500,
  26461. 'Nacute': 722,
  26462. 'icircumflex': 278,
  26463. 'Ecircumflex': 667,
  26464. 'adieresis': 556,
  26465. 'edieresis': 556,
  26466. 'cacute': 500,
  26467. 'nacute': 556,
  26468. 'umacron': 556,
  26469. 'Ncaron': 722,
  26470. 'Iacute': 278,
  26471. 'plusminus': 584,
  26472. 'brokenbar': 260,
  26473. 'registered': 737,
  26474. 'Gbreve': 778,
  26475. 'Idotaccent': 278,
  26476. 'summation': 600,
  26477. 'Egrave': 667,
  26478. 'racute': 333,
  26479. 'omacron': 556,
  26480. 'Zacute': 611,
  26481. 'Zcaron': 611,
  26482. 'greaterequal': 549,
  26483. 'Eth': 722,
  26484. 'Ccedilla': 722,
  26485. 'lcommaaccent': 222,
  26486. 'tcaron': 317,
  26487. 'eogonek': 556,
  26488. 'Uogonek': 722,
  26489. 'Aacute': 667,
  26490. 'Adieresis': 667,
  26491. 'egrave': 556,
  26492. 'zacute': 500,
  26493. 'iogonek': 222,
  26494. 'Oacute': 778,
  26495. 'oacute': 556,
  26496. 'amacron': 556,
  26497. 'sacute': 500,
  26498. 'idieresis': 278,
  26499. 'Ocircumflex': 778,
  26500. 'Ugrave': 722,
  26501. 'Delta': 612,
  26502. 'thorn': 556,
  26503. 'twosuperior': 333,
  26504. 'Odieresis': 778,
  26505. 'mu': 556,
  26506. 'igrave': 278,
  26507. 'ohungarumlaut': 556,
  26508. 'Eogonek': 667,
  26509. 'dcroat': 556,
  26510. 'threequarters': 834,
  26511. 'Scedilla': 667,
  26512. 'lcaron': 299,
  26513. 'Kcommaaccent': 667,
  26514. 'Lacute': 556,
  26515. 'trademark': 1000,
  26516. 'edotaccent': 556,
  26517. 'Igrave': 278,
  26518. 'Imacron': 278,
  26519. 'Lcaron': 556,
  26520. 'onehalf': 834,
  26521. 'lessequal': 549,
  26522. 'ocircumflex': 556,
  26523. 'ntilde': 556,
  26524. 'Uhungarumlaut': 722,
  26525. 'Eacute': 667,
  26526. 'emacron': 556,
  26527. 'gbreve': 556,
  26528. 'onequarter': 834,
  26529. 'Scaron': 667,
  26530. 'Scommaaccent': 667,
  26531. 'Ohungarumlaut': 778,
  26532. 'degree': 400,
  26533. 'ograve': 556,
  26534. 'Ccaron': 722,
  26535. 'ugrave': 556,
  26536. 'radical': 453,
  26537. 'Dcaron': 722,
  26538. 'rcommaaccent': 333,
  26539. 'Ntilde': 722,
  26540. 'otilde': 556,
  26541. 'Rcommaaccent': 722,
  26542. 'Lcommaaccent': 556,
  26543. 'Atilde': 667,
  26544. 'Aogonek': 667,
  26545. 'Aring': 667,
  26546. 'Otilde': 778,
  26547. 'zdotaccent': 500,
  26548. 'Ecaron': 667,
  26549. 'Iogonek': 278,
  26550. 'kcommaaccent': 500,
  26551. 'minus': 584,
  26552. 'Icircumflex': 278,
  26553. 'ncaron': 556,
  26554. 'tcommaaccent': 278,
  26555. 'logicalnot': 584,
  26556. 'odieresis': 556,
  26557. 'udieresis': 556,
  26558. 'notequal': 549,
  26559. 'gcommaaccent': 556,
  26560. 'eth': 556,
  26561. 'zcaron': 500,
  26562. 'ncommaaccent': 556,
  26563. 'onesuperior': 333,
  26564. 'imacron': 278,
  26565. 'Euro': 556
  26566. },
  26567. 'Symbol': {
  26568. 'space': 250,
  26569. 'exclam': 333,
  26570. 'universal': 713,
  26571. 'numbersign': 500,
  26572. 'existential': 549,
  26573. 'percent': 833,
  26574. 'ampersand': 778,
  26575. 'suchthat': 439,
  26576. 'parenleft': 333,
  26577. 'parenright': 333,
  26578. 'asteriskmath': 500,
  26579. 'plus': 549,
  26580. 'comma': 250,
  26581. 'minus': 549,
  26582. 'period': 250,
  26583. 'slash': 278,
  26584. 'zero': 500,
  26585. 'one': 500,
  26586. 'two': 500,
  26587. 'three': 500,
  26588. 'four': 500,
  26589. 'five': 500,
  26590. 'six': 500,
  26591. 'seven': 500,
  26592. 'eight': 500,
  26593. 'nine': 500,
  26594. 'colon': 278,
  26595. 'semicolon': 278,
  26596. 'less': 549,
  26597. 'equal': 549,
  26598. 'greater': 549,
  26599. 'question': 444,
  26600. 'congruent': 549,
  26601. 'Alpha': 722,
  26602. 'Beta': 667,
  26603. 'Chi': 722,
  26604. 'Delta': 612,
  26605. 'Epsilon': 611,
  26606. 'Phi': 763,
  26607. 'Gamma': 603,
  26608. 'Eta': 722,
  26609. 'Iota': 333,
  26610. 'theta1': 631,
  26611. 'Kappa': 722,
  26612. 'Lambda': 686,
  26613. 'Mu': 889,
  26614. 'Nu': 722,
  26615. 'Omicron': 722,
  26616. 'Pi': 768,
  26617. 'Theta': 741,
  26618. 'Rho': 556,
  26619. 'Sigma': 592,
  26620. 'Tau': 611,
  26621. 'Upsilon': 690,
  26622. 'sigma1': 439,
  26623. 'Omega': 768,
  26624. 'Xi': 645,
  26625. 'Psi': 795,
  26626. 'Zeta': 611,
  26627. 'bracketleft': 333,
  26628. 'therefore': 863,
  26629. 'bracketright': 333,
  26630. 'perpendicular': 658,
  26631. 'underscore': 500,
  26632. 'radicalex': 500,
  26633. 'alpha': 631,
  26634. 'beta': 549,
  26635. 'chi': 549,
  26636. 'delta': 494,
  26637. 'epsilon': 439,
  26638. 'phi': 521,
  26639. 'gamma': 411,
  26640. 'eta': 603,
  26641. 'iota': 329,
  26642. 'phi1': 603,
  26643. 'kappa': 549,
  26644. 'lambda': 549,
  26645. 'mu': 576,
  26646. 'nu': 521,
  26647. 'omicron': 549,
  26648. 'pi': 549,
  26649. 'theta': 521,
  26650. 'rho': 549,
  26651. 'sigma': 603,
  26652. 'tau': 439,
  26653. 'upsilon': 576,
  26654. 'omega1': 713,
  26655. 'omega': 686,
  26656. 'xi': 493,
  26657. 'psi': 686,
  26658. 'zeta': 494,
  26659. 'braceleft': 480,
  26660. 'bar': 200,
  26661. 'braceright': 480,
  26662. 'similar': 549,
  26663. 'Euro': 750,
  26664. 'Upsilon1': 620,
  26665. 'minute': 247,
  26666. 'lessequal': 549,
  26667. 'fraction': 167,
  26668. 'infinity': 713,
  26669. 'florin': 500,
  26670. 'club': 753,
  26671. 'diamond': 753,
  26672. 'heart': 753,
  26673. 'spade': 753,
  26674. 'arrowboth': 1042,
  26675. 'arrowleft': 987,
  26676. 'arrowup': 603,
  26677. 'arrowright': 987,
  26678. 'arrowdown': 603,
  26679. 'degree': 400,
  26680. 'plusminus': 549,
  26681. 'second': 411,
  26682. 'greaterequal': 549,
  26683. 'multiply': 549,
  26684. 'proportional': 713,
  26685. 'partialdiff': 494,
  26686. 'bullet': 460,
  26687. 'divide': 549,
  26688. 'notequal': 549,
  26689. 'equivalence': 549,
  26690. 'approxequal': 549,
  26691. 'ellipsis': 1000,
  26692. 'arrowvertex': 603,
  26693. 'arrowhorizex': 1000,
  26694. 'carriagereturn': 658,
  26695. 'aleph': 823,
  26696. 'Ifraktur': 686,
  26697. 'Rfraktur': 795,
  26698. 'weierstrass': 987,
  26699. 'circlemultiply': 768,
  26700. 'circleplus': 768,
  26701. 'emptyset': 823,
  26702. 'intersection': 768,
  26703. 'union': 768,
  26704. 'propersuperset': 713,
  26705. 'reflexsuperset': 713,
  26706. 'notsubset': 713,
  26707. 'propersubset': 713,
  26708. 'reflexsubset': 713,
  26709. 'element': 713,
  26710. 'notelement': 713,
  26711. 'angle': 768,
  26712. 'gradient': 713,
  26713. 'registerserif': 790,
  26714. 'copyrightserif': 790,
  26715. 'trademarkserif': 890,
  26716. 'product': 823,
  26717. 'radical': 549,
  26718. 'dotmath': 250,
  26719. 'logicalnot': 713,
  26720. 'logicaland': 603,
  26721. 'logicalor': 603,
  26722. 'arrowdblboth': 1042,
  26723. 'arrowdblleft': 987,
  26724. 'arrowdblup': 603,
  26725. 'arrowdblright': 987,
  26726. 'arrowdbldown': 603,
  26727. 'lozenge': 494,
  26728. 'angleleft': 329,
  26729. 'registersans': 790,
  26730. 'copyrightsans': 790,
  26731. 'trademarksans': 786,
  26732. 'summation': 713,
  26733. 'parenlefttp': 384,
  26734. 'parenleftex': 384,
  26735. 'parenleftbt': 384,
  26736. 'bracketlefttp': 384,
  26737. 'bracketleftex': 384,
  26738. 'bracketleftbt': 384,
  26739. 'bracelefttp': 494,
  26740. 'braceleftmid': 494,
  26741. 'braceleftbt': 494,
  26742. 'braceex': 494,
  26743. 'angleright': 329,
  26744. 'integral': 274,
  26745. 'integraltp': 686,
  26746. 'integralex': 686,
  26747. 'integralbt': 686,
  26748. 'parenrighttp': 384,
  26749. 'parenrightex': 384,
  26750. 'parenrightbt': 384,
  26751. 'bracketrighttp': 384,
  26752. 'bracketrightex': 384,
  26753. 'bracketrightbt': 384,
  26754. 'bracerighttp': 494,
  26755. 'bracerightmid': 494,
  26756. 'bracerightbt': 494,
  26757. 'apple': 790
  26758. },
  26759. 'Times-Roman': {
  26760. 'space': 250,
  26761. 'exclam': 333,
  26762. 'quotedbl': 408,
  26763. 'numbersign': 500,
  26764. 'dollar': 500,
  26765. 'percent': 833,
  26766. 'ampersand': 778,
  26767. 'quoteright': 333,
  26768. 'parenleft': 333,
  26769. 'parenright': 333,
  26770. 'asterisk': 500,
  26771. 'plus': 564,
  26772. 'comma': 250,
  26773. 'hyphen': 333,
  26774. 'period': 250,
  26775. 'slash': 278,
  26776. 'zero': 500,
  26777. 'one': 500,
  26778. 'two': 500,
  26779. 'three': 500,
  26780. 'four': 500,
  26781. 'five': 500,
  26782. 'six': 500,
  26783. 'seven': 500,
  26784. 'eight': 500,
  26785. 'nine': 500,
  26786. 'colon': 278,
  26787. 'semicolon': 278,
  26788. 'less': 564,
  26789. 'equal': 564,
  26790. 'greater': 564,
  26791. 'question': 444,
  26792. 'at': 921,
  26793. 'A': 722,
  26794. 'B': 667,
  26795. 'C': 667,
  26796. 'D': 722,
  26797. 'E': 611,
  26798. 'F': 556,
  26799. 'G': 722,
  26800. 'H': 722,
  26801. 'I': 333,
  26802. 'J': 389,
  26803. 'K': 722,
  26804. 'L': 611,
  26805. 'M': 889,
  26806. 'N': 722,
  26807. 'O': 722,
  26808. 'P': 556,
  26809. 'Q': 722,
  26810. 'R': 667,
  26811. 'S': 556,
  26812. 'T': 611,
  26813. 'U': 722,
  26814. 'V': 722,
  26815. 'W': 944,
  26816. 'X': 722,
  26817. 'Y': 722,
  26818. 'Z': 611,
  26819. 'bracketleft': 333,
  26820. 'backslash': 278,
  26821. 'bracketright': 333,
  26822. 'asciicircum': 469,
  26823. 'underscore': 500,
  26824. 'quoteleft': 333,
  26825. 'a': 444,
  26826. 'b': 500,
  26827. 'c': 444,
  26828. 'd': 500,
  26829. 'e': 444,
  26830. 'f': 333,
  26831. 'g': 500,
  26832. 'h': 500,
  26833. 'i': 278,
  26834. 'j': 278,
  26835. 'k': 500,
  26836. 'l': 278,
  26837. 'm': 778,
  26838. 'n': 500,
  26839. 'o': 500,
  26840. 'p': 500,
  26841. 'q': 500,
  26842. 'r': 333,
  26843. 's': 389,
  26844. 't': 278,
  26845. 'u': 500,
  26846. 'v': 500,
  26847. 'w': 722,
  26848. 'x': 500,
  26849. 'y': 500,
  26850. 'z': 444,
  26851. 'braceleft': 480,
  26852. 'bar': 200,
  26853. 'braceright': 480,
  26854. 'asciitilde': 541,
  26855. 'exclamdown': 333,
  26856. 'cent': 500,
  26857. 'sterling': 500,
  26858. 'fraction': 167,
  26859. 'yen': 500,
  26860. 'florin': 500,
  26861. 'section': 500,
  26862. 'currency': 500,
  26863. 'quotesingle': 180,
  26864. 'quotedblleft': 444,
  26865. 'guillemotleft': 500,
  26866. 'guilsinglleft': 333,
  26867. 'guilsinglright': 333,
  26868. 'fi': 556,
  26869. 'fl': 556,
  26870. 'endash': 500,
  26871. 'dagger': 500,
  26872. 'daggerdbl': 500,
  26873. 'periodcentered': 250,
  26874. 'paragraph': 453,
  26875. 'bullet': 350,
  26876. 'quotesinglbase': 333,
  26877. 'quotedblbase': 444,
  26878. 'quotedblright': 444,
  26879. 'guillemotright': 500,
  26880. 'ellipsis': 1000,
  26881. 'perthousand': 1000,
  26882. 'questiondown': 444,
  26883. 'grave': 333,
  26884. 'acute': 333,
  26885. 'circumflex': 333,
  26886. 'tilde': 333,
  26887. 'macron': 333,
  26888. 'breve': 333,
  26889. 'dotaccent': 333,
  26890. 'dieresis': 333,
  26891. 'ring': 333,
  26892. 'cedilla': 333,
  26893. 'hungarumlaut': 333,
  26894. 'ogonek': 333,
  26895. 'caron': 333,
  26896. 'emdash': 1000,
  26897. 'AE': 889,
  26898. 'ordfeminine': 276,
  26899. 'Lslash': 611,
  26900. 'Oslash': 722,
  26901. 'OE': 889,
  26902. 'ordmasculine': 310,
  26903. 'ae': 667,
  26904. 'dotlessi': 278,
  26905. 'lslash': 278,
  26906. 'oslash': 500,
  26907. 'oe': 722,
  26908. 'germandbls': 500,
  26909. 'Idieresis': 333,
  26910. 'eacute': 444,
  26911. 'abreve': 444,
  26912. 'uhungarumlaut': 500,
  26913. 'ecaron': 444,
  26914. 'Ydieresis': 722,
  26915. 'divide': 564,
  26916. 'Yacute': 722,
  26917. 'Acircumflex': 722,
  26918. 'aacute': 444,
  26919. 'Ucircumflex': 722,
  26920. 'yacute': 500,
  26921. 'scommaaccent': 389,
  26922. 'ecircumflex': 444,
  26923. 'Uring': 722,
  26924. 'Udieresis': 722,
  26925. 'aogonek': 444,
  26926. 'Uacute': 722,
  26927. 'uogonek': 500,
  26928. 'Edieresis': 611,
  26929. 'Dcroat': 722,
  26930. 'commaaccent': 250,
  26931. 'copyright': 760,
  26932. 'Emacron': 611,
  26933. 'ccaron': 444,
  26934. 'aring': 444,
  26935. 'Ncommaaccent': 722,
  26936. 'lacute': 278,
  26937. 'agrave': 444,
  26938. 'Tcommaaccent': 611,
  26939. 'Cacute': 667,
  26940. 'atilde': 444,
  26941. 'Edotaccent': 611,
  26942. 'scaron': 389,
  26943. 'scedilla': 389,
  26944. 'iacute': 278,
  26945. 'lozenge': 471,
  26946. 'Rcaron': 667,
  26947. 'Gcommaaccent': 722,
  26948. 'ucircumflex': 500,
  26949. 'acircumflex': 444,
  26950. 'Amacron': 722,
  26951. 'rcaron': 333,
  26952. 'ccedilla': 444,
  26953. 'Zdotaccent': 611,
  26954. 'Thorn': 556,
  26955. 'Omacron': 722,
  26956. 'Racute': 667,
  26957. 'Sacute': 556,
  26958. 'dcaron': 588,
  26959. 'Umacron': 722,
  26960. 'uring': 500,
  26961. 'threesuperior': 300,
  26962. 'Ograve': 722,
  26963. 'Agrave': 722,
  26964. 'Abreve': 722,
  26965. 'multiply': 564,
  26966. 'uacute': 500,
  26967. 'Tcaron': 611,
  26968. 'partialdiff': 476,
  26969. 'ydieresis': 500,
  26970. 'Nacute': 722,
  26971. 'icircumflex': 278,
  26972. 'Ecircumflex': 611,
  26973. 'adieresis': 444,
  26974. 'edieresis': 444,
  26975. 'cacute': 444,
  26976. 'nacute': 500,
  26977. 'umacron': 500,
  26978. 'Ncaron': 722,
  26979. 'Iacute': 333,
  26980. 'plusminus': 564,
  26981. 'brokenbar': 200,
  26982. 'registered': 760,
  26983. 'Gbreve': 722,
  26984. 'Idotaccent': 333,
  26985. 'summation': 600,
  26986. 'Egrave': 611,
  26987. 'racute': 333,
  26988. 'omacron': 500,
  26989. 'Zacute': 611,
  26990. 'Zcaron': 611,
  26991. 'greaterequal': 549,
  26992. 'Eth': 722,
  26993. 'Ccedilla': 667,
  26994. 'lcommaaccent': 278,
  26995. 'tcaron': 326,
  26996. 'eogonek': 444,
  26997. 'Uogonek': 722,
  26998. 'Aacute': 722,
  26999. 'Adieresis': 722,
  27000. 'egrave': 444,
  27001. 'zacute': 444,
  27002. 'iogonek': 278,
  27003. 'Oacute': 722,
  27004. 'oacute': 500,
  27005. 'amacron': 444,
  27006. 'sacute': 389,
  27007. 'idieresis': 278,
  27008. 'Ocircumflex': 722,
  27009. 'Ugrave': 722,
  27010. 'Delta': 612,
  27011. 'thorn': 500,
  27012. 'twosuperior': 300,
  27013. 'Odieresis': 722,
  27014. 'mu': 500,
  27015. 'igrave': 278,
  27016. 'ohungarumlaut': 500,
  27017. 'Eogonek': 611,
  27018. 'dcroat': 500,
  27019. 'threequarters': 750,
  27020. 'Scedilla': 556,
  27021. 'lcaron': 344,
  27022. 'Kcommaaccent': 722,
  27023. 'Lacute': 611,
  27024. 'trademark': 980,
  27025. 'edotaccent': 444,
  27026. 'Igrave': 333,
  27027. 'Imacron': 333,
  27028. 'Lcaron': 611,
  27029. 'onehalf': 750,
  27030. 'lessequal': 549,
  27031. 'ocircumflex': 500,
  27032. 'ntilde': 500,
  27033. 'Uhungarumlaut': 722,
  27034. 'Eacute': 611,
  27035. 'emacron': 444,
  27036. 'gbreve': 500,
  27037. 'onequarter': 750,
  27038. 'Scaron': 556,
  27039. 'Scommaaccent': 556,
  27040. 'Ohungarumlaut': 722,
  27041. 'degree': 400,
  27042. 'ograve': 500,
  27043. 'Ccaron': 667,
  27044. 'ugrave': 500,
  27045. 'radical': 453,
  27046. 'Dcaron': 722,
  27047. 'rcommaaccent': 333,
  27048. 'Ntilde': 722,
  27049. 'otilde': 500,
  27050. 'Rcommaaccent': 667,
  27051. 'Lcommaaccent': 611,
  27052. 'Atilde': 722,
  27053. 'Aogonek': 722,
  27054. 'Aring': 722,
  27055. 'Otilde': 722,
  27056. 'zdotaccent': 444,
  27057. 'Ecaron': 611,
  27058. 'Iogonek': 333,
  27059. 'kcommaaccent': 500,
  27060. 'minus': 564,
  27061. 'Icircumflex': 333,
  27062. 'ncaron': 500,
  27063. 'tcommaaccent': 278,
  27064. 'logicalnot': 564,
  27065. 'odieresis': 500,
  27066. 'udieresis': 500,
  27067. 'notequal': 549,
  27068. 'gcommaaccent': 500,
  27069. 'eth': 500,
  27070. 'zcaron': 444,
  27071. 'ncommaaccent': 500,
  27072. 'onesuperior': 300,
  27073. 'imacron': 278,
  27074. 'Euro': 500
  27075. },
  27076. 'Times-Bold': {
  27077. 'space': 250,
  27078. 'exclam': 333,
  27079. 'quotedbl': 555,
  27080. 'numbersign': 500,
  27081. 'dollar': 500,
  27082. 'percent': 1000,
  27083. 'ampersand': 833,
  27084. 'quoteright': 333,
  27085. 'parenleft': 333,
  27086. 'parenright': 333,
  27087. 'asterisk': 500,
  27088. 'plus': 570,
  27089. 'comma': 250,
  27090. 'hyphen': 333,
  27091. 'period': 250,
  27092. 'slash': 278,
  27093. 'zero': 500,
  27094. 'one': 500,
  27095. 'two': 500,
  27096. 'three': 500,
  27097. 'four': 500,
  27098. 'five': 500,
  27099. 'six': 500,
  27100. 'seven': 500,
  27101. 'eight': 500,
  27102. 'nine': 500,
  27103. 'colon': 333,
  27104. 'semicolon': 333,
  27105. 'less': 570,
  27106. 'equal': 570,
  27107. 'greater': 570,
  27108. 'question': 500,
  27109. 'at': 930,
  27110. 'A': 722,
  27111. 'B': 667,
  27112. 'C': 722,
  27113. 'D': 722,
  27114. 'E': 667,
  27115. 'F': 611,
  27116. 'G': 778,
  27117. 'H': 778,
  27118. 'I': 389,
  27119. 'J': 500,
  27120. 'K': 778,
  27121. 'L': 667,
  27122. 'M': 944,
  27123. 'N': 722,
  27124. 'O': 778,
  27125. 'P': 611,
  27126. 'Q': 778,
  27127. 'R': 722,
  27128. 'S': 556,
  27129. 'T': 667,
  27130. 'U': 722,
  27131. 'V': 722,
  27132. 'W': 1000,
  27133. 'X': 722,
  27134. 'Y': 722,
  27135. 'Z': 667,
  27136. 'bracketleft': 333,
  27137. 'backslash': 278,
  27138. 'bracketright': 333,
  27139. 'asciicircum': 581,
  27140. 'underscore': 500,
  27141. 'quoteleft': 333,
  27142. 'a': 500,
  27143. 'b': 556,
  27144. 'c': 444,
  27145. 'd': 556,
  27146. 'e': 444,
  27147. 'f': 333,
  27148. 'g': 500,
  27149. 'h': 556,
  27150. 'i': 278,
  27151. 'j': 333,
  27152. 'k': 556,
  27153. 'l': 278,
  27154. 'm': 833,
  27155. 'n': 556,
  27156. 'o': 500,
  27157. 'p': 556,
  27158. 'q': 556,
  27159. 'r': 444,
  27160. 's': 389,
  27161. 't': 333,
  27162. 'u': 556,
  27163. 'v': 500,
  27164. 'w': 722,
  27165. 'x': 500,
  27166. 'y': 500,
  27167. 'z': 444,
  27168. 'braceleft': 394,
  27169. 'bar': 220,
  27170. 'braceright': 394,
  27171. 'asciitilde': 520,
  27172. 'exclamdown': 333,
  27173. 'cent': 500,
  27174. 'sterling': 500,
  27175. 'fraction': 167,
  27176. 'yen': 500,
  27177. 'florin': 500,
  27178. 'section': 500,
  27179. 'currency': 500,
  27180. 'quotesingle': 278,
  27181. 'quotedblleft': 500,
  27182. 'guillemotleft': 500,
  27183. 'guilsinglleft': 333,
  27184. 'guilsinglright': 333,
  27185. 'fi': 556,
  27186. 'fl': 556,
  27187. 'endash': 500,
  27188. 'dagger': 500,
  27189. 'daggerdbl': 500,
  27190. 'periodcentered': 250,
  27191. 'paragraph': 540,
  27192. 'bullet': 350,
  27193. 'quotesinglbase': 333,
  27194. 'quotedblbase': 500,
  27195. 'quotedblright': 500,
  27196. 'guillemotright': 500,
  27197. 'ellipsis': 1000,
  27198. 'perthousand': 1000,
  27199. 'questiondown': 500,
  27200. 'grave': 333,
  27201. 'acute': 333,
  27202. 'circumflex': 333,
  27203. 'tilde': 333,
  27204. 'macron': 333,
  27205. 'breve': 333,
  27206. 'dotaccent': 333,
  27207. 'dieresis': 333,
  27208. 'ring': 333,
  27209. 'cedilla': 333,
  27210. 'hungarumlaut': 333,
  27211. 'ogonek': 333,
  27212. 'caron': 333,
  27213. 'emdash': 1000,
  27214. 'AE': 1000,
  27215. 'ordfeminine': 300,
  27216. 'Lslash': 667,
  27217. 'Oslash': 778,
  27218. 'OE': 1000,
  27219. 'ordmasculine': 330,
  27220. 'ae': 722,
  27221. 'dotlessi': 278,
  27222. 'lslash': 278,
  27223. 'oslash': 500,
  27224. 'oe': 722,
  27225. 'germandbls': 556,
  27226. 'Idieresis': 389,
  27227. 'eacute': 444,
  27228. 'abreve': 500,
  27229. 'uhungarumlaut': 556,
  27230. 'ecaron': 444,
  27231. 'Ydieresis': 722,
  27232. 'divide': 570,
  27233. 'Yacute': 722,
  27234. 'Acircumflex': 722,
  27235. 'aacute': 500,
  27236. 'Ucircumflex': 722,
  27237. 'yacute': 500,
  27238. 'scommaaccent': 389,
  27239. 'ecircumflex': 444,
  27240. 'Uring': 722,
  27241. 'Udieresis': 722,
  27242. 'aogonek': 500,
  27243. 'Uacute': 722,
  27244. 'uogonek': 556,
  27245. 'Edieresis': 667,
  27246. 'Dcroat': 722,
  27247. 'commaaccent': 250,
  27248. 'copyright': 747,
  27249. 'Emacron': 667,
  27250. 'ccaron': 444,
  27251. 'aring': 500,
  27252. 'Ncommaaccent': 722,
  27253. 'lacute': 278,
  27254. 'agrave': 500,
  27255. 'Tcommaaccent': 667,
  27256. 'Cacute': 722,
  27257. 'atilde': 500,
  27258. 'Edotaccent': 667,
  27259. 'scaron': 389,
  27260. 'scedilla': 389,
  27261. 'iacute': 278,
  27262. 'lozenge': 494,
  27263. 'Rcaron': 722,
  27264. 'Gcommaaccent': 778,
  27265. 'ucircumflex': 556,
  27266. 'acircumflex': 500,
  27267. 'Amacron': 722,
  27268. 'rcaron': 444,
  27269. 'ccedilla': 444,
  27270. 'Zdotaccent': 667,
  27271. 'Thorn': 611,
  27272. 'Omacron': 778,
  27273. 'Racute': 722,
  27274. 'Sacute': 556,
  27275. 'dcaron': 672,
  27276. 'Umacron': 722,
  27277. 'uring': 556,
  27278. 'threesuperior': 300,
  27279. 'Ograve': 778,
  27280. 'Agrave': 722,
  27281. 'Abreve': 722,
  27282. 'multiply': 570,
  27283. 'uacute': 556,
  27284. 'Tcaron': 667,
  27285. 'partialdiff': 494,
  27286. 'ydieresis': 500,
  27287. 'Nacute': 722,
  27288. 'icircumflex': 278,
  27289. 'Ecircumflex': 667,
  27290. 'adieresis': 500,
  27291. 'edieresis': 444,
  27292. 'cacute': 444,
  27293. 'nacute': 556,
  27294. 'umacron': 556,
  27295. 'Ncaron': 722,
  27296. 'Iacute': 389,
  27297. 'plusminus': 570,
  27298. 'brokenbar': 220,
  27299. 'registered': 747,
  27300. 'Gbreve': 778,
  27301. 'Idotaccent': 389,
  27302. 'summation': 600,
  27303. 'Egrave': 667,
  27304. 'racute': 444,
  27305. 'omacron': 500,
  27306. 'Zacute': 667,
  27307. 'Zcaron': 667,
  27308. 'greaterequal': 549,
  27309. 'Eth': 722,
  27310. 'Ccedilla': 722,
  27311. 'lcommaaccent': 278,
  27312. 'tcaron': 416,
  27313. 'eogonek': 444,
  27314. 'Uogonek': 722,
  27315. 'Aacute': 722,
  27316. 'Adieresis': 722,
  27317. 'egrave': 444,
  27318. 'zacute': 444,
  27319. 'iogonek': 278,
  27320. 'Oacute': 778,
  27321. 'oacute': 500,
  27322. 'amacron': 500,
  27323. 'sacute': 389,
  27324. 'idieresis': 278,
  27325. 'Ocircumflex': 778,
  27326. 'Ugrave': 722,
  27327. 'Delta': 612,
  27328. 'thorn': 556,
  27329. 'twosuperior': 300,
  27330. 'Odieresis': 778,
  27331. 'mu': 556,
  27332. 'igrave': 278,
  27333. 'ohungarumlaut': 500,
  27334. 'Eogonek': 667,
  27335. 'dcroat': 556,
  27336. 'threequarters': 750,
  27337. 'Scedilla': 556,
  27338. 'lcaron': 394,
  27339. 'Kcommaaccent': 778,
  27340. 'Lacute': 667,
  27341. 'trademark': 1000,
  27342. 'edotaccent': 444,
  27343. 'Igrave': 389,
  27344. 'Imacron': 389,
  27345. 'Lcaron': 667,
  27346. 'onehalf': 750,
  27347. 'lessequal': 549,
  27348. 'ocircumflex': 500,
  27349. 'ntilde': 556,
  27350. 'Uhungarumlaut': 722,
  27351. 'Eacute': 667,
  27352. 'emacron': 444,
  27353. 'gbreve': 500,
  27354. 'onequarter': 750,
  27355. 'Scaron': 556,
  27356. 'Scommaaccent': 556,
  27357. 'Ohungarumlaut': 778,
  27358. 'degree': 400,
  27359. 'ograve': 500,
  27360. 'Ccaron': 722,
  27361. 'ugrave': 556,
  27362. 'radical': 549,
  27363. 'Dcaron': 722,
  27364. 'rcommaaccent': 444,
  27365. 'Ntilde': 722,
  27366. 'otilde': 500,
  27367. 'Rcommaaccent': 722,
  27368. 'Lcommaaccent': 667,
  27369. 'Atilde': 722,
  27370. 'Aogonek': 722,
  27371. 'Aring': 722,
  27372. 'Otilde': 778,
  27373. 'zdotaccent': 444,
  27374. 'Ecaron': 667,
  27375. 'Iogonek': 389,
  27376. 'kcommaaccent': 556,
  27377. 'minus': 570,
  27378. 'Icircumflex': 389,
  27379. 'ncaron': 556,
  27380. 'tcommaaccent': 333,
  27381. 'logicalnot': 570,
  27382. 'odieresis': 500,
  27383. 'udieresis': 556,
  27384. 'notequal': 549,
  27385. 'gcommaaccent': 500,
  27386. 'eth': 500,
  27387. 'zcaron': 444,
  27388. 'ncommaaccent': 556,
  27389. 'onesuperior': 300,
  27390. 'imacron': 278,
  27391. 'Euro': 500
  27392. },
  27393. 'Times-BoldItalic': {
  27394. 'space': 250,
  27395. 'exclam': 389,
  27396. 'quotedbl': 555,
  27397. 'numbersign': 500,
  27398. 'dollar': 500,
  27399. 'percent': 833,
  27400. 'ampersand': 778,
  27401. 'quoteright': 333,
  27402. 'parenleft': 333,
  27403. 'parenright': 333,
  27404. 'asterisk': 500,
  27405. 'plus': 570,
  27406. 'comma': 250,
  27407. 'hyphen': 333,
  27408. 'period': 250,
  27409. 'slash': 278,
  27410. 'zero': 500,
  27411. 'one': 500,
  27412. 'two': 500,
  27413. 'three': 500,
  27414. 'four': 500,
  27415. 'five': 500,
  27416. 'six': 500,
  27417. 'seven': 500,
  27418. 'eight': 500,
  27419. 'nine': 500,
  27420. 'colon': 333,
  27421. 'semicolon': 333,
  27422. 'less': 570,
  27423. 'equal': 570,
  27424. 'greater': 570,
  27425. 'question': 500,
  27426. 'at': 832,
  27427. 'A': 667,
  27428. 'B': 667,
  27429. 'C': 667,
  27430. 'D': 722,
  27431. 'E': 667,
  27432. 'F': 667,
  27433. 'G': 722,
  27434. 'H': 778,
  27435. 'I': 389,
  27436. 'J': 500,
  27437. 'K': 667,
  27438. 'L': 611,
  27439. 'M': 889,
  27440. 'N': 722,
  27441. 'O': 722,
  27442. 'P': 611,
  27443. 'Q': 722,
  27444. 'R': 667,
  27445. 'S': 556,
  27446. 'T': 611,
  27447. 'U': 722,
  27448. 'V': 667,
  27449. 'W': 889,
  27450. 'X': 667,
  27451. 'Y': 611,
  27452. 'Z': 611,
  27453. 'bracketleft': 333,
  27454. 'backslash': 278,
  27455. 'bracketright': 333,
  27456. 'asciicircum': 570,
  27457. 'underscore': 500,
  27458. 'quoteleft': 333,
  27459. 'a': 500,
  27460. 'b': 500,
  27461. 'c': 444,
  27462. 'd': 500,
  27463. 'e': 444,
  27464. 'f': 333,
  27465. 'g': 500,
  27466. 'h': 556,
  27467. 'i': 278,
  27468. 'j': 278,
  27469. 'k': 500,
  27470. 'l': 278,
  27471. 'm': 778,
  27472. 'n': 556,
  27473. 'o': 500,
  27474. 'p': 500,
  27475. 'q': 500,
  27476. 'r': 389,
  27477. 's': 389,
  27478. 't': 278,
  27479. 'u': 556,
  27480. 'v': 444,
  27481. 'w': 667,
  27482. 'x': 500,
  27483. 'y': 444,
  27484. 'z': 389,
  27485. 'braceleft': 348,
  27486. 'bar': 220,
  27487. 'braceright': 348,
  27488. 'asciitilde': 570,
  27489. 'exclamdown': 389,
  27490. 'cent': 500,
  27491. 'sterling': 500,
  27492. 'fraction': 167,
  27493. 'yen': 500,
  27494. 'florin': 500,
  27495. 'section': 500,
  27496. 'currency': 500,
  27497. 'quotesingle': 278,
  27498. 'quotedblleft': 500,
  27499. 'guillemotleft': 500,
  27500. 'guilsinglleft': 333,
  27501. 'guilsinglright': 333,
  27502. 'fi': 556,
  27503. 'fl': 556,
  27504. 'endash': 500,
  27505. 'dagger': 500,
  27506. 'daggerdbl': 500,
  27507. 'periodcentered': 250,
  27508. 'paragraph': 500,
  27509. 'bullet': 350,
  27510. 'quotesinglbase': 333,
  27511. 'quotedblbase': 500,
  27512. 'quotedblright': 500,
  27513. 'guillemotright': 500,
  27514. 'ellipsis': 1000,
  27515. 'perthousand': 1000,
  27516. 'questiondown': 500,
  27517. 'grave': 333,
  27518. 'acute': 333,
  27519. 'circumflex': 333,
  27520. 'tilde': 333,
  27521. 'macron': 333,
  27522. 'breve': 333,
  27523. 'dotaccent': 333,
  27524. 'dieresis': 333,
  27525. 'ring': 333,
  27526. 'cedilla': 333,
  27527. 'hungarumlaut': 333,
  27528. 'ogonek': 333,
  27529. 'caron': 333,
  27530. 'emdash': 1000,
  27531. 'AE': 944,
  27532. 'ordfeminine': 266,
  27533. 'Lslash': 611,
  27534. 'Oslash': 722,
  27535. 'OE': 944,
  27536. 'ordmasculine': 300,
  27537. 'ae': 722,
  27538. 'dotlessi': 278,
  27539. 'lslash': 278,
  27540. 'oslash': 500,
  27541. 'oe': 722,
  27542. 'germandbls': 500,
  27543. 'Idieresis': 389,
  27544. 'eacute': 444,
  27545. 'abreve': 500,
  27546. 'uhungarumlaut': 556,
  27547. 'ecaron': 444,
  27548. 'Ydieresis': 611,
  27549. 'divide': 570,
  27550. 'Yacute': 611,
  27551. 'Acircumflex': 667,
  27552. 'aacute': 500,
  27553. 'Ucircumflex': 722,
  27554. 'yacute': 444,
  27555. 'scommaaccent': 389,
  27556. 'ecircumflex': 444,
  27557. 'Uring': 722,
  27558. 'Udieresis': 722,
  27559. 'aogonek': 500,
  27560. 'Uacute': 722,
  27561. 'uogonek': 556,
  27562. 'Edieresis': 667,
  27563. 'Dcroat': 722,
  27564. 'commaaccent': 250,
  27565. 'copyright': 747,
  27566. 'Emacron': 667,
  27567. 'ccaron': 444,
  27568. 'aring': 500,
  27569. 'Ncommaaccent': 722,
  27570. 'lacute': 278,
  27571. 'agrave': 500,
  27572. 'Tcommaaccent': 611,
  27573. 'Cacute': 667,
  27574. 'atilde': 500,
  27575. 'Edotaccent': 667,
  27576. 'scaron': 389,
  27577. 'scedilla': 389,
  27578. 'iacute': 278,
  27579. 'lozenge': 494,
  27580. 'Rcaron': 667,
  27581. 'Gcommaaccent': 722,
  27582. 'ucircumflex': 556,
  27583. 'acircumflex': 500,
  27584. 'Amacron': 667,
  27585. 'rcaron': 389,
  27586. 'ccedilla': 444,
  27587. 'Zdotaccent': 611,
  27588. 'Thorn': 611,
  27589. 'Omacron': 722,
  27590. 'Racute': 667,
  27591. 'Sacute': 556,
  27592. 'dcaron': 608,
  27593. 'Umacron': 722,
  27594. 'uring': 556,
  27595. 'threesuperior': 300,
  27596. 'Ograve': 722,
  27597. 'Agrave': 667,
  27598. 'Abreve': 667,
  27599. 'multiply': 570,
  27600. 'uacute': 556,
  27601. 'Tcaron': 611,
  27602. 'partialdiff': 494,
  27603. 'ydieresis': 444,
  27604. 'Nacute': 722,
  27605. 'icircumflex': 278,
  27606. 'Ecircumflex': 667,
  27607. 'adieresis': 500,
  27608. 'edieresis': 444,
  27609. 'cacute': 444,
  27610. 'nacute': 556,
  27611. 'umacron': 556,
  27612. 'Ncaron': 722,
  27613. 'Iacute': 389,
  27614. 'plusminus': 570,
  27615. 'brokenbar': 220,
  27616. 'registered': 747,
  27617. 'Gbreve': 722,
  27618. 'Idotaccent': 389,
  27619. 'summation': 600,
  27620. 'Egrave': 667,
  27621. 'racute': 389,
  27622. 'omacron': 500,
  27623. 'Zacute': 611,
  27624. 'Zcaron': 611,
  27625. 'greaterequal': 549,
  27626. 'Eth': 722,
  27627. 'Ccedilla': 667,
  27628. 'lcommaaccent': 278,
  27629. 'tcaron': 366,
  27630. 'eogonek': 444,
  27631. 'Uogonek': 722,
  27632. 'Aacute': 667,
  27633. 'Adieresis': 667,
  27634. 'egrave': 444,
  27635. 'zacute': 389,
  27636. 'iogonek': 278,
  27637. 'Oacute': 722,
  27638. 'oacute': 500,
  27639. 'amacron': 500,
  27640. 'sacute': 389,
  27641. 'idieresis': 278,
  27642. 'Ocircumflex': 722,
  27643. 'Ugrave': 722,
  27644. 'Delta': 612,
  27645. 'thorn': 500,
  27646. 'twosuperior': 300,
  27647. 'Odieresis': 722,
  27648. 'mu': 576,
  27649. 'igrave': 278,
  27650. 'ohungarumlaut': 500,
  27651. 'Eogonek': 667,
  27652. 'dcroat': 500,
  27653. 'threequarters': 750,
  27654. 'Scedilla': 556,
  27655. 'lcaron': 382,
  27656. 'Kcommaaccent': 667,
  27657. 'Lacute': 611,
  27658. 'trademark': 1000,
  27659. 'edotaccent': 444,
  27660. 'Igrave': 389,
  27661. 'Imacron': 389,
  27662. 'Lcaron': 611,
  27663. 'onehalf': 750,
  27664. 'lessequal': 549,
  27665. 'ocircumflex': 500,
  27666. 'ntilde': 556,
  27667. 'Uhungarumlaut': 722,
  27668. 'Eacute': 667,
  27669. 'emacron': 444,
  27670. 'gbreve': 500,
  27671. 'onequarter': 750,
  27672. 'Scaron': 556,
  27673. 'Scommaaccent': 556,
  27674. 'Ohungarumlaut': 722,
  27675. 'degree': 400,
  27676. 'ograve': 500,
  27677. 'Ccaron': 667,
  27678. 'ugrave': 556,
  27679. 'radical': 549,
  27680. 'Dcaron': 722,
  27681. 'rcommaaccent': 389,
  27682. 'Ntilde': 722,
  27683. 'otilde': 500,
  27684. 'Rcommaaccent': 667,
  27685. 'Lcommaaccent': 611,
  27686. 'Atilde': 667,
  27687. 'Aogonek': 667,
  27688. 'Aring': 667,
  27689. 'Otilde': 722,
  27690. 'zdotaccent': 389,
  27691. 'Ecaron': 667,
  27692. 'Iogonek': 389,
  27693. 'kcommaaccent': 500,
  27694. 'minus': 606,
  27695. 'Icircumflex': 389,
  27696. 'ncaron': 556,
  27697. 'tcommaaccent': 278,
  27698. 'logicalnot': 606,
  27699. 'odieresis': 500,
  27700. 'udieresis': 556,
  27701. 'notequal': 549,
  27702. 'gcommaaccent': 500,
  27703. 'eth': 500,
  27704. 'zcaron': 389,
  27705. 'ncommaaccent': 556,
  27706. 'onesuperior': 300,
  27707. 'imacron': 278,
  27708. 'Euro': 500
  27709. },
  27710. 'Times-Italic': {
  27711. 'space': 250,
  27712. 'exclam': 333,
  27713. 'quotedbl': 420,
  27714. 'numbersign': 500,
  27715. 'dollar': 500,
  27716. 'percent': 833,
  27717. 'ampersand': 778,
  27718. 'quoteright': 333,
  27719. 'parenleft': 333,
  27720. 'parenright': 333,
  27721. 'asterisk': 500,
  27722. 'plus': 675,
  27723. 'comma': 250,
  27724. 'hyphen': 333,
  27725. 'period': 250,
  27726. 'slash': 278,
  27727. 'zero': 500,
  27728. 'one': 500,
  27729. 'two': 500,
  27730. 'three': 500,
  27731. 'four': 500,
  27732. 'five': 500,
  27733. 'six': 500,
  27734. 'seven': 500,
  27735. 'eight': 500,
  27736. 'nine': 500,
  27737. 'colon': 333,
  27738. 'semicolon': 333,
  27739. 'less': 675,
  27740. 'equal': 675,
  27741. 'greater': 675,
  27742. 'question': 500,
  27743. 'at': 920,
  27744. 'A': 611,
  27745. 'B': 611,
  27746. 'C': 667,
  27747. 'D': 722,
  27748. 'E': 611,
  27749. 'F': 611,
  27750. 'G': 722,
  27751. 'H': 722,
  27752. 'I': 333,
  27753. 'J': 444,
  27754. 'K': 667,
  27755. 'L': 556,
  27756. 'M': 833,
  27757. 'N': 667,
  27758. 'O': 722,
  27759. 'P': 611,
  27760. 'Q': 722,
  27761. 'R': 611,
  27762. 'S': 500,
  27763. 'T': 556,
  27764. 'U': 722,
  27765. 'V': 611,
  27766. 'W': 833,
  27767. 'X': 611,
  27768. 'Y': 556,
  27769. 'Z': 556,
  27770. 'bracketleft': 389,
  27771. 'backslash': 278,
  27772. 'bracketright': 389,
  27773. 'asciicircum': 422,
  27774. 'underscore': 500,
  27775. 'quoteleft': 333,
  27776. 'a': 500,
  27777. 'b': 500,
  27778. 'c': 444,
  27779. 'd': 500,
  27780. 'e': 444,
  27781. 'f': 278,
  27782. 'g': 500,
  27783. 'h': 500,
  27784. 'i': 278,
  27785. 'j': 278,
  27786. 'k': 444,
  27787. 'l': 278,
  27788. 'm': 722,
  27789. 'n': 500,
  27790. 'o': 500,
  27791. 'p': 500,
  27792. 'q': 500,
  27793. 'r': 389,
  27794. 's': 389,
  27795. 't': 278,
  27796. 'u': 500,
  27797. 'v': 444,
  27798. 'w': 667,
  27799. 'x': 444,
  27800. 'y': 444,
  27801. 'z': 389,
  27802. 'braceleft': 400,
  27803. 'bar': 275,
  27804. 'braceright': 400,
  27805. 'asciitilde': 541,
  27806. 'exclamdown': 389,
  27807. 'cent': 500,
  27808. 'sterling': 500,
  27809. 'fraction': 167,
  27810. 'yen': 500,
  27811. 'florin': 500,
  27812. 'section': 500,
  27813. 'currency': 500,
  27814. 'quotesingle': 214,
  27815. 'quotedblleft': 556,
  27816. 'guillemotleft': 500,
  27817. 'guilsinglleft': 333,
  27818. 'guilsinglright': 333,
  27819. 'fi': 500,
  27820. 'fl': 500,
  27821. 'endash': 500,
  27822. 'dagger': 500,
  27823. 'daggerdbl': 500,
  27824. 'periodcentered': 250,
  27825. 'paragraph': 523,
  27826. 'bullet': 350,
  27827. 'quotesinglbase': 333,
  27828. 'quotedblbase': 556,
  27829. 'quotedblright': 556,
  27830. 'guillemotright': 500,
  27831. 'ellipsis': 889,
  27832. 'perthousand': 1000,
  27833. 'questiondown': 500,
  27834. 'grave': 333,
  27835. 'acute': 333,
  27836. 'circumflex': 333,
  27837. 'tilde': 333,
  27838. 'macron': 333,
  27839. 'breve': 333,
  27840. 'dotaccent': 333,
  27841. 'dieresis': 333,
  27842. 'ring': 333,
  27843. 'cedilla': 333,
  27844. 'hungarumlaut': 333,
  27845. 'ogonek': 333,
  27846. 'caron': 333,
  27847. 'emdash': 889,
  27848. 'AE': 889,
  27849. 'ordfeminine': 276,
  27850. 'Lslash': 556,
  27851. 'Oslash': 722,
  27852. 'OE': 944,
  27853. 'ordmasculine': 310,
  27854. 'ae': 667,
  27855. 'dotlessi': 278,
  27856. 'lslash': 278,
  27857. 'oslash': 500,
  27858. 'oe': 667,
  27859. 'germandbls': 500,
  27860. 'Idieresis': 333,
  27861. 'eacute': 444,
  27862. 'abreve': 500,
  27863. 'uhungarumlaut': 500,
  27864. 'ecaron': 444,
  27865. 'Ydieresis': 556,
  27866. 'divide': 675,
  27867. 'Yacute': 556,
  27868. 'Acircumflex': 611,
  27869. 'aacute': 500,
  27870. 'Ucircumflex': 722,
  27871. 'yacute': 444,
  27872. 'scommaaccent': 389,
  27873. 'ecircumflex': 444,
  27874. 'Uring': 722,
  27875. 'Udieresis': 722,
  27876. 'aogonek': 500,
  27877. 'Uacute': 722,
  27878. 'uogonek': 500,
  27879. 'Edieresis': 611,
  27880. 'Dcroat': 722,
  27881. 'commaaccent': 250,
  27882. 'copyright': 760,
  27883. 'Emacron': 611,
  27884. 'ccaron': 444,
  27885. 'aring': 500,
  27886. 'Ncommaaccent': 667,
  27887. 'lacute': 278,
  27888. 'agrave': 500,
  27889. 'Tcommaaccent': 556,
  27890. 'Cacute': 667,
  27891. 'atilde': 500,
  27892. 'Edotaccent': 611,
  27893. 'scaron': 389,
  27894. 'scedilla': 389,
  27895. 'iacute': 278,
  27896. 'lozenge': 471,
  27897. 'Rcaron': 611,
  27898. 'Gcommaaccent': 722,
  27899. 'ucircumflex': 500,
  27900. 'acircumflex': 500,
  27901. 'Amacron': 611,
  27902. 'rcaron': 389,
  27903. 'ccedilla': 444,
  27904. 'Zdotaccent': 556,
  27905. 'Thorn': 611,
  27906. 'Omacron': 722,
  27907. 'Racute': 611,
  27908. 'Sacute': 500,
  27909. 'dcaron': 544,
  27910. 'Umacron': 722,
  27911. 'uring': 500,
  27912. 'threesuperior': 300,
  27913. 'Ograve': 722,
  27914. 'Agrave': 611,
  27915. 'Abreve': 611,
  27916. 'multiply': 675,
  27917. 'uacute': 500,
  27918. 'Tcaron': 556,
  27919. 'partialdiff': 476,
  27920. 'ydieresis': 444,
  27921. 'Nacute': 667,
  27922. 'icircumflex': 278,
  27923. 'Ecircumflex': 611,
  27924. 'adieresis': 500,
  27925. 'edieresis': 444,
  27926. 'cacute': 444,
  27927. 'nacute': 500,
  27928. 'umacron': 500,
  27929. 'Ncaron': 667,
  27930. 'Iacute': 333,
  27931. 'plusminus': 675,
  27932. 'brokenbar': 275,
  27933. 'registered': 760,
  27934. 'Gbreve': 722,
  27935. 'Idotaccent': 333,
  27936. 'summation': 600,
  27937. 'Egrave': 611,
  27938. 'racute': 389,
  27939. 'omacron': 500,
  27940. 'Zacute': 556,
  27941. 'Zcaron': 556,
  27942. 'greaterequal': 549,
  27943. 'Eth': 722,
  27944. 'Ccedilla': 667,
  27945. 'lcommaaccent': 278,
  27946. 'tcaron': 300,
  27947. 'eogonek': 444,
  27948. 'Uogonek': 722,
  27949. 'Aacute': 611,
  27950. 'Adieresis': 611,
  27951. 'egrave': 444,
  27952. 'zacute': 389,
  27953. 'iogonek': 278,
  27954. 'Oacute': 722,
  27955. 'oacute': 500,
  27956. 'amacron': 500,
  27957. 'sacute': 389,
  27958. 'idieresis': 278,
  27959. 'Ocircumflex': 722,
  27960. 'Ugrave': 722,
  27961. 'Delta': 612,
  27962. 'thorn': 500,
  27963. 'twosuperior': 300,
  27964. 'Odieresis': 722,
  27965. 'mu': 500,
  27966. 'igrave': 278,
  27967. 'ohungarumlaut': 500,
  27968. 'Eogonek': 611,
  27969. 'dcroat': 500,
  27970. 'threequarters': 750,
  27971. 'Scedilla': 500,
  27972. 'lcaron': 300,
  27973. 'Kcommaaccent': 667,
  27974. 'Lacute': 556,
  27975. 'trademark': 980,
  27976. 'edotaccent': 444,
  27977. 'Igrave': 333,
  27978. 'Imacron': 333,
  27979. 'Lcaron': 611,
  27980. 'onehalf': 750,
  27981. 'lessequal': 549,
  27982. 'ocircumflex': 500,
  27983. 'ntilde': 500,
  27984. 'Uhungarumlaut': 722,
  27985. 'Eacute': 611,
  27986. 'emacron': 444,
  27987. 'gbreve': 500,
  27988. 'onequarter': 750,
  27989. 'Scaron': 500,
  27990. 'Scommaaccent': 500,
  27991. 'Ohungarumlaut': 722,
  27992. 'degree': 400,
  27993. 'ograve': 500,
  27994. 'Ccaron': 667,
  27995. 'ugrave': 500,
  27996. 'radical': 453,
  27997. 'Dcaron': 722,
  27998. 'rcommaaccent': 389,
  27999. 'Ntilde': 667,
  28000. 'otilde': 500,
  28001. 'Rcommaaccent': 611,
  28002. 'Lcommaaccent': 556,
  28003. 'Atilde': 611,
  28004. 'Aogonek': 611,
  28005. 'Aring': 611,
  28006. 'Otilde': 722,
  28007. 'zdotaccent': 389,
  28008. 'Ecaron': 611,
  28009. 'Iogonek': 333,
  28010. 'kcommaaccent': 444,
  28011. 'minus': 675,
  28012. 'Icircumflex': 333,
  28013. 'ncaron': 500,
  28014. 'tcommaaccent': 278,
  28015. 'logicalnot': 675,
  28016. 'odieresis': 500,
  28017. 'udieresis': 500,
  28018. 'notequal': 549,
  28019. 'gcommaaccent': 500,
  28020. 'eth': 500,
  28021. 'zcaron': 389,
  28022. 'ncommaaccent': 500,
  28023. 'onesuperior': 300,
  28024. 'imacron': 278,
  28025. 'Euro': 500
  28026. },
  28027. 'ZapfDingbats': {
  28028. 'space': 278,
  28029. 'a1': 974,
  28030. 'a2': 961,
  28031. 'a202': 974,
  28032. 'a3': 980,
  28033. 'a4': 719,
  28034. 'a5': 789,
  28035. 'a119': 790,
  28036. 'a118': 791,
  28037. 'a117': 690,
  28038. 'a11': 960,
  28039. 'a12': 939,
  28040. 'a13': 549,
  28041. 'a14': 855,
  28042. 'a15': 911,
  28043. 'a16': 933,
  28044. 'a105': 911,
  28045. 'a17': 945,
  28046. 'a18': 974,
  28047. 'a19': 755,
  28048. 'a20': 846,
  28049. 'a21': 762,
  28050. 'a22': 761,
  28051. 'a23': 571,
  28052. 'a24': 677,
  28053. 'a25': 763,
  28054. 'a26': 760,
  28055. 'a27': 759,
  28056. 'a28': 754,
  28057. 'a6': 494,
  28058. 'a7': 552,
  28059. 'a8': 537,
  28060. 'a9': 577,
  28061. 'a10': 692,
  28062. 'a29': 786,
  28063. 'a30': 788,
  28064. 'a31': 788,
  28065. 'a32': 790,
  28066. 'a33': 793,
  28067. 'a34': 794,
  28068. 'a35': 816,
  28069. 'a36': 823,
  28070. 'a37': 789,
  28071. 'a38': 841,
  28072. 'a39': 823,
  28073. 'a40': 833,
  28074. 'a41': 816,
  28075. 'a42': 831,
  28076. 'a43': 923,
  28077. 'a44': 744,
  28078. 'a45': 723,
  28079. 'a46': 749,
  28080. 'a47': 790,
  28081. 'a48': 792,
  28082. 'a49': 695,
  28083. 'a50': 776,
  28084. 'a51': 768,
  28085. 'a52': 792,
  28086. 'a53': 759,
  28087. 'a54': 707,
  28088. 'a55': 708,
  28089. 'a56': 682,
  28090. 'a57': 701,
  28091. 'a58': 826,
  28092. 'a59': 815,
  28093. 'a60': 789,
  28094. 'a61': 789,
  28095. 'a62': 707,
  28096. 'a63': 687,
  28097. 'a64': 696,
  28098. 'a65': 689,
  28099. 'a66': 786,
  28100. 'a67': 787,
  28101. 'a68': 713,
  28102. 'a69': 791,
  28103. 'a70': 785,
  28104. 'a71': 791,
  28105. 'a72': 873,
  28106. 'a73': 761,
  28107. 'a74': 762,
  28108. 'a203': 762,
  28109. 'a75': 759,
  28110. 'a204': 759,
  28111. 'a76': 892,
  28112. 'a77': 892,
  28113. 'a78': 788,
  28114. 'a79': 784,
  28115. 'a81': 438,
  28116. 'a82': 138,
  28117. 'a83': 277,
  28118. 'a84': 415,
  28119. 'a97': 392,
  28120. 'a98': 392,
  28121. 'a99': 668,
  28122. 'a100': 668,
  28123. 'a89': 390,
  28124. 'a90': 390,
  28125. 'a93': 317,
  28126. 'a94': 317,
  28127. 'a91': 276,
  28128. 'a92': 276,
  28129. 'a205': 509,
  28130. 'a85': 509,
  28131. 'a206': 410,
  28132. 'a86': 410,
  28133. 'a87': 234,
  28134. 'a88': 234,
  28135. 'a95': 334,
  28136. 'a96': 334,
  28137. 'a101': 732,
  28138. 'a102': 544,
  28139. 'a103': 544,
  28140. 'a104': 910,
  28141. 'a106': 667,
  28142. 'a107': 760,
  28143. 'a108': 760,
  28144. 'a112': 776,
  28145. 'a111': 595,
  28146. 'a110': 694,
  28147. 'a109': 626,
  28148. 'a120': 788,
  28149. 'a121': 788,
  28150. 'a122': 788,
  28151. 'a123': 788,
  28152. 'a124': 788,
  28153. 'a125': 788,
  28154. 'a126': 788,
  28155. 'a127': 788,
  28156. 'a128': 788,
  28157. 'a129': 788,
  28158. 'a130': 788,
  28159. 'a131': 788,
  28160. 'a132': 788,
  28161. 'a133': 788,
  28162. 'a134': 788,
  28163. 'a135': 788,
  28164. 'a136': 788,
  28165. 'a137': 788,
  28166. 'a138': 788,
  28167. 'a139': 788,
  28168. 'a140': 788,
  28169. 'a141': 788,
  28170. 'a142': 788,
  28171. 'a143': 788,
  28172. 'a144': 788,
  28173. 'a145': 788,
  28174. 'a146': 788,
  28175. 'a147': 788,
  28176. 'a148': 788,
  28177. 'a149': 788,
  28178. 'a150': 788,
  28179. 'a151': 788,
  28180. 'a152': 788,
  28181. 'a153': 788,
  28182. 'a154': 788,
  28183. 'a155': 788,
  28184. 'a156': 788,
  28185. 'a157': 788,
  28186. 'a158': 788,
  28187. 'a159': 788,
  28188. 'a160': 894,
  28189. 'a161': 838,
  28190. 'a163': 1016,
  28191. 'a164': 458,
  28192. 'a196': 748,
  28193. 'a165': 924,
  28194. 'a192': 748,
  28195. 'a166': 918,
  28196. 'a167': 927,
  28197. 'a168': 928,
  28198. 'a169': 928,
  28199. 'a170': 834,
  28200. 'a171': 873,
  28201. 'a172': 828,
  28202. 'a173': 924,
  28203. 'a162': 924,
  28204. 'a174': 917,
  28205. 'a175': 930,
  28206. 'a176': 931,
  28207. 'a177': 463,
  28208. 'a178': 883,
  28209. 'a179': 836,
  28210. 'a193': 836,
  28211. 'a180': 867,
  28212. 'a199': 867,
  28213. 'a181': 696,
  28214. 'a200': 696,
  28215. 'a182': 874,
  28216. 'a201': 874,
  28217. 'a183': 760,
  28218. 'a184': 946,
  28219. 'a197': 771,
  28220. 'a185': 865,
  28221. 'a194': 771,
  28222. 'a198': 888,
  28223. 'a186': 967,
  28224. 'a195': 888,
  28225. 'a187': 831,
  28226. 'a188': 873,
  28227. 'a189': 927,
  28228. 'a190': 970,
  28229. 'a191': 918
  28230. }
  28231. };
  28232. var EOF = {};
  28233. function isEOF(v) {
  28234. return (v === EOF);
  28235. }
  28236. var MAX_LENGTH_TO_CACHE = 1000;
  28237. var Parser = (function ParserClosure() {
  28238. function Parser(lexer, allowStreams, xref) {
  28239. this.lexer = lexer;
  28240. this.allowStreams = allowStreams;
  28241. this.xref = xref;
  28242. this.imageCache = {};
  28243. this.refill();
  28244. }
  28245. Parser.prototype = {
  28246. refill: function Parser_refill() {
  28247. this.buf1 = this.lexer.getObj();
  28248. this.buf2 = this.lexer.getObj();
  28249. },
  28250. shift: function Parser_shift() {
  28251. if (isCmd(this.buf2, 'ID')) {
  28252. this.buf1 = this.buf2;
  28253. this.buf2 = null;
  28254. } else {
  28255. this.buf1 = this.buf2;
  28256. this.buf2 = this.lexer.getObj();
  28257. }
  28258. },
  28259. getObj: function Parser_getObj(cipherTransform) {
  28260. var buf1 = this.buf1;
  28261. this.shift();
  28262. if (buf1 instanceof Cmd) {
  28263. switch (buf1.cmd) {
  28264. case 'BI': // inline image
  28265. return this.makeInlineImage(cipherTransform);
  28266. case '[': // array
  28267. var array = [];
  28268. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28269. array.push(this.getObj(cipherTransform));
  28270. }
  28271. if (isEOF(this.buf1)) {
  28272. error('End of file inside array');
  28273. }
  28274. this.shift();
  28275. return array;
  28276. case '<<': // dictionary or stream
  28277. var dict = new Dict(this.xref);
  28278. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28279. if (!isName(this.buf1)) {
  28280. info('Malformed dictionary: key must be a name object');
  28281. this.shift();
  28282. continue;
  28283. }
  28284. var key = this.buf1.name;
  28285. this.shift();
  28286. if (isEOF(this.buf1)) {
  28287. break;
  28288. }
  28289. dict.set(key, this.getObj(cipherTransform));
  28290. }
  28291. if (isEOF(this.buf1)) {
  28292. error('End of file inside dictionary');
  28293. }
  28294. // Stream objects are not allowed inside content streams or
  28295. // object streams.
  28296. if (isCmd(this.buf2, 'stream')) {
  28297. return (this.allowStreams ?
  28298. this.makeStream(dict, cipherTransform) : dict);
  28299. }
  28300. this.shift();
  28301. return dict;
  28302. default: // simple object
  28303. return buf1;
  28304. }
  28305. }
  28306. if (isInt(buf1)) { // indirect reference or integer
  28307. var num = buf1;
  28308. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28309. var ref = new Ref(num, this.buf1);
  28310. this.shift();
  28311. this.shift();
  28312. return ref;
  28313. }
  28314. return num;
  28315. }
  28316. if (isString(buf1)) { // string
  28317. var str = buf1;
  28318. if (cipherTransform) {
  28319. str = cipherTransform.decryptString(str);
  28320. }
  28321. return str;
  28322. }
  28323. // simple object
  28324. return buf1;
  28325. },
  28326. /**
  28327. * Find the end of the stream by searching for the /EI\s/.
  28328. * @returns {number} The inline stream length.
  28329. */
  28330. findDefaultInlineStreamEnd:
  28331. function Parser_findDefaultInlineStreamEnd(stream) {
  28332. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28333. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28334. while ((ch = stream.getByte()) !== -1) {
  28335. if (state === 0) {
  28336. state = (ch === E) ? 1 : 0;
  28337. } else if (state === 1) {
  28338. state = (ch === I) ? 2 : 0;
  28339. } else {
  28340. assert(state === 2);
  28341. if (ch === SPACE || ch === LF || ch === CR) {
  28342. // Let's check the next five bytes are ASCII... just be sure.
  28343. n = 5;
  28344. followingBytes = stream.peekBytes(n);
  28345. for (i = 0; i < n; i++) {
  28346. ch = followingBytes[i];
  28347. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28348. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28349. // it's binary stuff. Resetting the state.
  28350. state = 0;
  28351. break;
  28352. }
  28353. }
  28354. if (state === 2) {
  28355. break; // Finished!
  28356. }
  28357. } else {
  28358. state = 0;
  28359. }
  28360. }
  28361. }
  28362. return ((stream.pos - 4) - startPos);
  28363. },
  28364. /**
  28365. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28366. * @returns {number} The inline stream length.
  28367. */
  28368. findASCII85DecodeInlineStreamEnd:
  28369. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28370. var TILDE = 0x7E, GT = 0x3E;
  28371. var startPos = stream.pos, ch, length;
  28372. while ((ch = stream.getByte()) !== -1) {
  28373. if (ch === TILDE && stream.peekByte() === GT) {
  28374. stream.skip();
  28375. break;
  28376. }
  28377. }
  28378. length = stream.pos - startPos;
  28379. if (ch === -1) {
  28380. warn('Inline ASCII85Decode image stream: ' +
  28381. 'EOD marker not found, searching for /EI/ instead.');
  28382. stream.skip(-length); // Reset the stream position.
  28383. return this.findDefaultInlineStreamEnd(stream);
  28384. }
  28385. this.inlineStreamSkipEI(stream);
  28386. return length;
  28387. },
  28388. /**
  28389. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28390. * @returns {number} The inline stream length.
  28391. */
  28392. findASCIIHexDecodeInlineStreamEnd:
  28393. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28394. var GT = 0x3E;
  28395. var startPos = stream.pos, ch, length;
  28396. while ((ch = stream.getByte()) !== -1) {
  28397. if (ch === GT) {
  28398. break;
  28399. }
  28400. }
  28401. length = stream.pos - startPos;
  28402. if (ch === -1) {
  28403. warn('Inline ASCIIHexDecode image stream: ' +
  28404. 'EOD marker not found, searching for /EI/ instead.');
  28405. stream.skip(-length); // Reset the stream position.
  28406. return this.findDefaultInlineStreamEnd(stream);
  28407. }
  28408. this.inlineStreamSkipEI(stream);
  28409. return length;
  28410. },
  28411. /**
  28412. * Skip over the /EI/ for streams where we search for an EOD marker.
  28413. */
  28414. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28415. var E = 0x45, I = 0x49;
  28416. var state = 0, ch;
  28417. while ((ch = stream.getByte()) !== -1) {
  28418. if (state === 0) {
  28419. state = (ch === E) ? 1 : 0;
  28420. } else if (state === 1) {
  28421. state = (ch === I) ? 2 : 0;
  28422. } else if (state === 2) {
  28423. break;
  28424. }
  28425. }
  28426. },
  28427. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28428. var lexer = this.lexer;
  28429. var stream = lexer.stream;
  28430. // Parse dictionary.
  28431. var dict = new Dict(null);
  28432. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28433. if (!isName(this.buf1)) {
  28434. error('Dictionary key must be a name object');
  28435. }
  28436. var key = this.buf1.name;
  28437. this.shift();
  28438. if (isEOF(this.buf1)) {
  28439. break;
  28440. }
  28441. dict.set(key, this.getObj(cipherTransform));
  28442. }
  28443. // Extract the name of the first (i.e. the current) image filter.
  28444. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28445. if (isName(filter)) {
  28446. filterName = filter.name;
  28447. } else if (isArray(filter) && isName(filter[0])) {
  28448. filterName = filter[0].name;
  28449. }
  28450. // Parse image stream.
  28451. var startPos = stream.pos, length, i, ii;
  28452. if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28453. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28454. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28455. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28456. } else {
  28457. length = this.findDefaultInlineStreamEnd(stream);
  28458. }
  28459. var imageStream = stream.makeSubStream(startPos, length, dict);
  28460. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28461. // adler32 checksum.
  28462. var adler32;
  28463. if (length < MAX_LENGTH_TO_CACHE) {
  28464. var imageBytes = imageStream.getBytes();
  28465. imageStream.reset();
  28466. var a = 1;
  28467. var b = 0;
  28468. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28469. // No modulo required in the loop if imageBytes.length < 5552.
  28470. a += imageBytes[i] & 0xff;
  28471. b += a;
  28472. }
  28473. adler32 = ((b % 65521) << 16) | (a % 65521);
  28474. if (this.imageCache.adler32 === adler32) {
  28475. this.buf2 = Cmd.get('EI');
  28476. this.shift();
  28477. this.imageCache[adler32].reset();
  28478. return this.imageCache[adler32];
  28479. }
  28480. }
  28481. if (cipherTransform) {
  28482. imageStream = cipherTransform.createStream(imageStream, length);
  28483. }
  28484. imageStream = this.filter(imageStream, dict, length);
  28485. imageStream.dict = dict;
  28486. if (adler32 !== undefined) {
  28487. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28488. this.imageCache[adler32] = imageStream;
  28489. }
  28490. this.buf2 = Cmd.get('EI');
  28491. this.shift();
  28492. return imageStream;
  28493. },
  28494. fetchIfRef: function Parser_fetchIfRef(obj) {
  28495. // not relying on the xref.fetchIfRef -- xref might not be set
  28496. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28497. },
  28498. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28499. var lexer = this.lexer;
  28500. var stream = lexer.stream;
  28501. // get stream start position
  28502. lexer.skipToNextLine();
  28503. var pos = stream.pos - 1;
  28504. // get length
  28505. var length = this.fetchIfRef(dict.get('Length'));
  28506. if (!isInt(length)) {
  28507. info('Bad ' + length + ' attribute in stream');
  28508. length = 0;
  28509. }
  28510. // skip over the stream data
  28511. stream.pos = pos + length;
  28512. lexer.nextChar();
  28513. this.shift(); // '>>'
  28514. this.shift(); // 'stream'
  28515. if (!isCmd(this.buf1, 'endstream')) {
  28516. // bad stream length, scanning for endstream
  28517. stream.pos = pos;
  28518. var SCAN_BLOCK_SIZE = 2048;
  28519. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28520. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28521. 0x61, 0x6D];
  28522. var skipped = 0, found = false, i, j;
  28523. while (stream.pos < stream.end) {
  28524. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28525. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28526. if (scanLength <= 0) {
  28527. break;
  28528. }
  28529. found = false;
  28530. for (i = 0, j = 0; i < scanLength; i++) {
  28531. var b = scanBytes[i];
  28532. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28533. i -= j;
  28534. j = 0;
  28535. } else {
  28536. j++;
  28537. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28538. i++;
  28539. found = true;
  28540. break;
  28541. }
  28542. }
  28543. }
  28544. if (found) {
  28545. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28546. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28547. break;
  28548. }
  28549. skipped += scanLength;
  28550. stream.pos += scanLength;
  28551. }
  28552. if (!found) {
  28553. error('Missing endstream');
  28554. }
  28555. length = skipped;
  28556. lexer.nextChar();
  28557. this.shift();
  28558. this.shift();
  28559. }
  28560. this.shift(); // 'endstream'
  28561. stream = stream.makeSubStream(pos, length, dict);
  28562. if (cipherTransform) {
  28563. stream = cipherTransform.createStream(stream, length);
  28564. }
  28565. stream = this.filter(stream, dict, length);
  28566. stream.dict = dict;
  28567. return stream;
  28568. },
  28569. filter: function Parser_filter(stream, dict, length) {
  28570. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28571. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28572. if (isName(filter)) {
  28573. return this.makeFilter(stream, filter.name, length, params);
  28574. }
  28575. var maybeLength = length;
  28576. if (isArray(filter)) {
  28577. var filterArray = filter;
  28578. var paramsArray = params;
  28579. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28580. filter = filterArray[i];
  28581. if (!isName(filter)) {
  28582. error('Bad filter name: ' + filter);
  28583. }
  28584. params = null;
  28585. if (isArray(paramsArray) && (i in paramsArray)) {
  28586. params = paramsArray[i];
  28587. }
  28588. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28589. // after the first stream the length variable is invalid
  28590. maybeLength = null;
  28591. }
  28592. }
  28593. return stream;
  28594. },
  28595. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28596. if (stream.dict.get('Length') === 0) {
  28597. return new NullStream(stream);
  28598. }
  28599. try {
  28600. if (params) {
  28601. params = this.fetchIfRef(params);
  28602. }
  28603. var xrefStreamStats = this.xref.stats.streamTypes;
  28604. if (name === 'FlateDecode' || name === 'Fl') {
  28605. xrefStreamStats[StreamType.FLATE] = true;
  28606. if (params) {
  28607. return new PredictorStream(new FlateStream(stream, maybeLength),
  28608. maybeLength, params);
  28609. }
  28610. return new FlateStream(stream, maybeLength);
  28611. }
  28612. if (name === 'LZWDecode' || name === 'LZW') {
  28613. xrefStreamStats[StreamType.LZW] = true;
  28614. var earlyChange = 1;
  28615. if (params) {
  28616. if (params.has('EarlyChange')) {
  28617. earlyChange = params.get('EarlyChange');
  28618. }
  28619. return new PredictorStream(
  28620. new LZWStream(stream, maybeLength, earlyChange),
  28621. maybeLength, params);
  28622. }
  28623. return new LZWStream(stream, maybeLength, earlyChange);
  28624. }
  28625. if (name === 'DCTDecode' || name === 'DCT') {
  28626. xrefStreamStats[StreamType.DCT] = true;
  28627. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28628. }
  28629. if (name === 'JPXDecode' || name === 'JPX') {
  28630. xrefStreamStats[StreamType.JPX] = true;
  28631. return new JpxStream(stream, maybeLength, stream.dict);
  28632. }
  28633. if (name === 'ASCII85Decode' || name === 'A85') {
  28634. xrefStreamStats[StreamType.A85] = true;
  28635. return new Ascii85Stream(stream, maybeLength);
  28636. }
  28637. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28638. xrefStreamStats[StreamType.AHX] = true;
  28639. return new AsciiHexStream(stream, maybeLength);
  28640. }
  28641. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28642. xrefStreamStats[StreamType.CCF] = true;
  28643. return new CCITTFaxStream(stream, maybeLength, params);
  28644. }
  28645. if (name === 'RunLengthDecode' || name === 'RL') {
  28646. xrefStreamStats[StreamType.RL] = true;
  28647. return new RunLengthStream(stream, maybeLength);
  28648. }
  28649. if (name === 'JBIG2Decode') {
  28650. xrefStreamStats[StreamType.JBIG] = true;
  28651. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28652. }
  28653. warn('filter "' + name + '" not supported yet');
  28654. return stream;
  28655. } catch (ex) {
  28656. if (ex instanceof MissingDataException) {
  28657. throw ex;
  28658. }
  28659. warn('Invalid stream: \"' + ex + '\"');
  28660. return new NullStream(stream);
  28661. }
  28662. }
  28663. };
  28664. return Parser;
  28665. })();
  28666. var Lexer = (function LexerClosure() {
  28667. function Lexer(stream, knownCommands) {
  28668. this.stream = stream;
  28669. this.nextChar();
  28670. // While lexing, we build up many strings one char at a time. Using += for
  28671. // this can result in lots of garbage strings. It's better to build an
  28672. // array of single-char strings and then join() them together at the end.
  28673. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28674. // purpose uses less memory than using a new array for each string.
  28675. this.strBuf = [];
  28676. // The PDFs might have "glued" commands with other commands, operands or
  28677. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28678. // commands and their prefixes. The prefixes are built the following way:
  28679. // if there a command that is a prefix of the other valid command or
  28680. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28681. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28682. // other commands or literals as a prefix. The knowCommands is optional.
  28683. this.knownCommands = knownCommands;
  28684. }
  28685. Lexer.isSpace = function Lexer_isSpace(ch) {
  28686. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28687. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28688. };
  28689. // A '1' in this array means the character is white space. A '1' or
  28690. // '2' means the character ends a name or command.
  28691. var specialChars = [
  28692. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28694. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28708. ];
  28709. function toHexDigit(ch) {
  28710. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28711. return ch & 0x0F;
  28712. }
  28713. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28714. // 'A'-'F', 'a'-'f'
  28715. return (ch & 0x0F) + 9;
  28716. }
  28717. return -1;
  28718. }
  28719. Lexer.prototype = {
  28720. nextChar: function Lexer_nextChar() {
  28721. return (this.currentChar = this.stream.getByte());
  28722. },
  28723. peekChar: function Lexer_peekChar() {
  28724. return this.stream.peekByte();
  28725. },
  28726. getNumber: function Lexer_getNumber() {
  28727. var ch = this.currentChar;
  28728. var eNotation = false;
  28729. var divideBy = 0; // different from 0 if it's a floating point value
  28730. var sign = 1;
  28731. if (ch === 0x2D) { // '-'
  28732. sign = -1;
  28733. ch = this.nextChar();
  28734. } else if (ch === 0x2B) { // '+'
  28735. ch = this.nextChar();
  28736. }
  28737. if (ch === 0x2E) { // '.'
  28738. divideBy = 10;
  28739. ch = this.nextChar();
  28740. }
  28741. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28742. error('Invalid number: ' + String.fromCharCode(ch));
  28743. return 0;
  28744. }
  28745. var baseValue = ch - 0x30; // '0'
  28746. var powerValue = 0;
  28747. var powerValueSign = 1;
  28748. while ((ch = this.nextChar()) >= 0) {
  28749. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28750. var currentDigit = ch - 0x30; // '0'
  28751. if (eNotation) { // We are after an 'e' or 'E'
  28752. powerValue = powerValue * 10 + currentDigit;
  28753. } else {
  28754. if (divideBy !== 0) { // We are after a point
  28755. divideBy *= 10;
  28756. }
  28757. baseValue = baseValue * 10 + currentDigit;
  28758. }
  28759. } else if (ch === 0x2E) { // '.'
  28760. if (divideBy === 0) {
  28761. divideBy = 1;
  28762. } else {
  28763. // A number can have only one '.'
  28764. break;
  28765. }
  28766. } else if (ch === 0x2D) { // '-'
  28767. // ignore minus signs in the middle of numbers to match
  28768. // Adobe's behavior
  28769. warn('Badly formated number');
  28770. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28771. // 'E' can be either a scientific notation or the beginning of a new
  28772. // operator
  28773. ch = this.peekChar();
  28774. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28775. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28776. this.nextChar(); // Consume the sign character
  28777. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28778. // The 'E' must be the beginning of a new operator
  28779. break;
  28780. }
  28781. eNotation = true;
  28782. } else {
  28783. // the last character doesn't belong to us
  28784. break;
  28785. }
  28786. }
  28787. if (divideBy !== 0) {
  28788. baseValue /= divideBy;
  28789. }
  28790. if (eNotation) {
  28791. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28792. }
  28793. return sign * baseValue;
  28794. },
  28795. getString: function Lexer_getString() {
  28796. var numParen = 1;
  28797. var done = false;
  28798. var strBuf = this.strBuf;
  28799. strBuf.length = 0;
  28800. var ch = this.nextChar();
  28801. while (true) {
  28802. var charBuffered = false;
  28803. switch (ch | 0) {
  28804. case -1:
  28805. warn('Unterminated string');
  28806. done = true;
  28807. break;
  28808. case 0x28: // '('
  28809. ++numParen;
  28810. strBuf.push('(');
  28811. break;
  28812. case 0x29: // ')'
  28813. if (--numParen === 0) {
  28814. this.nextChar(); // consume strings ')'
  28815. done = true;
  28816. } else {
  28817. strBuf.push(')');
  28818. }
  28819. break;
  28820. case 0x5C: // '\\'
  28821. ch = this.nextChar();
  28822. switch (ch) {
  28823. case -1:
  28824. warn('Unterminated string');
  28825. done = true;
  28826. break;
  28827. case 0x6E: // 'n'
  28828. strBuf.push('\n');
  28829. break;
  28830. case 0x72: // 'r'
  28831. strBuf.push('\r');
  28832. break;
  28833. case 0x74: // 't'
  28834. strBuf.push('\t');
  28835. break;
  28836. case 0x62: // 'b'
  28837. strBuf.push('\b');
  28838. break;
  28839. case 0x66: // 'f'
  28840. strBuf.push('\f');
  28841. break;
  28842. case 0x5C: // '\'
  28843. case 0x28: // '('
  28844. case 0x29: // ')'
  28845. strBuf.push(String.fromCharCode(ch));
  28846. break;
  28847. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28848. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28849. var x = ch & 0x0F;
  28850. ch = this.nextChar();
  28851. charBuffered = true;
  28852. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28853. x = (x << 3) + (ch & 0x0F);
  28854. ch = this.nextChar();
  28855. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28856. charBuffered = false;
  28857. x = (x << 3) + (ch & 0x0F);
  28858. }
  28859. }
  28860. strBuf.push(String.fromCharCode(x));
  28861. break;
  28862. case 0x0D: // CR
  28863. if (this.peekChar() === 0x0A) { // LF
  28864. this.nextChar();
  28865. }
  28866. break;
  28867. case 0x0A: // LF
  28868. break;
  28869. default:
  28870. strBuf.push(String.fromCharCode(ch));
  28871. break;
  28872. }
  28873. break;
  28874. default:
  28875. strBuf.push(String.fromCharCode(ch));
  28876. break;
  28877. }
  28878. if (done) {
  28879. break;
  28880. }
  28881. if (!charBuffered) {
  28882. ch = this.nextChar();
  28883. }
  28884. }
  28885. return strBuf.join('');
  28886. },
  28887. getName: function Lexer_getName() {
  28888. var ch;
  28889. var strBuf = this.strBuf;
  28890. strBuf.length = 0;
  28891. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28892. if (ch === 0x23) { // '#'
  28893. ch = this.nextChar();
  28894. var x = toHexDigit(ch);
  28895. if (x !== -1) {
  28896. var x2 = toHexDigit(this.nextChar());
  28897. if (x2 === -1) {
  28898. error('Illegal digit in hex char in name: ' + x2);
  28899. }
  28900. strBuf.push(String.fromCharCode((x << 4) | x2));
  28901. } else {
  28902. strBuf.push('#', String.fromCharCode(ch));
  28903. }
  28904. } else {
  28905. strBuf.push(String.fromCharCode(ch));
  28906. }
  28907. }
  28908. if (strBuf.length > 128) {
  28909. error('Warning: name token is longer than allowed by the spec: ' +
  28910. strBuf.length);
  28911. }
  28912. return Name.get(strBuf.join(''));
  28913. },
  28914. getHexString: function Lexer_getHexString() {
  28915. var strBuf = this.strBuf;
  28916. strBuf.length = 0;
  28917. var ch = this.currentChar;
  28918. var isFirstHex = true;
  28919. var firstDigit;
  28920. var secondDigit;
  28921. while (true) {
  28922. if (ch < 0) {
  28923. warn('Unterminated hex string');
  28924. break;
  28925. } else if (ch === 0x3E) { // '>'
  28926. this.nextChar();
  28927. break;
  28928. } else if (specialChars[ch] === 1) {
  28929. ch = this.nextChar();
  28930. continue;
  28931. } else {
  28932. if (isFirstHex) {
  28933. firstDigit = toHexDigit(ch);
  28934. if (firstDigit === -1) {
  28935. warn('Ignoring invalid character "' + ch + '" in hex string');
  28936. ch = this.nextChar();
  28937. continue;
  28938. }
  28939. } else {
  28940. secondDigit = toHexDigit(ch);
  28941. if (secondDigit === -1) {
  28942. warn('Ignoring invalid character "' + ch + '" in hex string');
  28943. ch = this.nextChar();
  28944. continue;
  28945. }
  28946. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28947. }
  28948. isFirstHex = !isFirstHex;
  28949. ch = this.nextChar();
  28950. }
  28951. }
  28952. return strBuf.join('');
  28953. },
  28954. getObj: function Lexer_getObj() {
  28955. // skip whitespace and comments
  28956. var comment = false;
  28957. var ch = this.currentChar;
  28958. while (true) {
  28959. if (ch < 0) {
  28960. return EOF;
  28961. }
  28962. if (comment) {
  28963. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28964. comment = false;
  28965. }
  28966. } else if (ch === 0x25) { // '%'
  28967. comment = true;
  28968. } else if (specialChars[ch] !== 1) {
  28969. break;
  28970. }
  28971. ch = this.nextChar();
  28972. }
  28973. // start reading token
  28974. switch (ch | 0) {
  28975. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28976. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28977. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28978. return this.getNumber();
  28979. case 0x28: // '('
  28980. return this.getString();
  28981. case 0x2F: // '/'
  28982. return this.getName();
  28983. // array punctuation
  28984. case 0x5B: // '['
  28985. this.nextChar();
  28986. return Cmd.get('[');
  28987. case 0x5D: // ']'
  28988. this.nextChar();
  28989. return Cmd.get(']');
  28990. // hex string or dict punctuation
  28991. case 0x3C: // '<'
  28992. ch = this.nextChar();
  28993. if (ch === 0x3C) {
  28994. // dict punctuation
  28995. this.nextChar();
  28996. return Cmd.get('<<');
  28997. }
  28998. return this.getHexString();
  28999. // dict punctuation
  29000. case 0x3E: // '>'
  29001. ch = this.nextChar();
  29002. if (ch === 0x3E) {
  29003. this.nextChar();
  29004. return Cmd.get('>>');
  29005. }
  29006. return Cmd.get('>');
  29007. case 0x7B: // '{'
  29008. this.nextChar();
  29009. return Cmd.get('{');
  29010. case 0x7D: // '}'
  29011. this.nextChar();
  29012. return Cmd.get('}');
  29013. case 0x29: // ')'
  29014. error('Illegal character: ' + ch);
  29015. break;
  29016. }
  29017. // command
  29018. var str = String.fromCharCode(ch);
  29019. var knownCommands = this.knownCommands;
  29020. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29021. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29022. // stop if known command is found and next character does not make
  29023. // the str a command
  29024. var possibleCommand = str + String.fromCharCode(ch);
  29025. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29026. break;
  29027. }
  29028. if (str.length === 128) {
  29029. error('Command token too long: ' + str.length);
  29030. }
  29031. str = possibleCommand;
  29032. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29033. }
  29034. if (str === 'true') {
  29035. return true;
  29036. }
  29037. if (str === 'false') {
  29038. return false;
  29039. }
  29040. if (str === 'null') {
  29041. return null;
  29042. }
  29043. return Cmd.get(str);
  29044. },
  29045. skipToNextLine: function Lexer_skipToNextLine() {
  29046. var ch = this.currentChar;
  29047. while (ch >= 0) {
  29048. if (ch === 0x0D) { // CR
  29049. ch = this.nextChar();
  29050. if (ch === 0x0A) { // LF
  29051. this.nextChar();
  29052. }
  29053. break;
  29054. } else if (ch === 0x0A) { // LF
  29055. this.nextChar();
  29056. break;
  29057. }
  29058. ch = this.nextChar();
  29059. }
  29060. }
  29061. };
  29062. return Lexer;
  29063. })();
  29064. var Linearization = {
  29065. create: function LinearizationCreate(stream) {
  29066. function getInt(name, allowZeroValue) {
  29067. var obj = linDict.get(name);
  29068. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29069. return obj;
  29070. }
  29071. throw new Error('The "' + name + '" parameter in the linearization ' +
  29072. 'dictionary is invalid.');
  29073. }
  29074. function getHints() {
  29075. var hints = linDict.get('H'), hintsLength, item;
  29076. if (isArray(hints) &&
  29077. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29078. for (var index = 0; index < hintsLength; index++) {
  29079. if (!(isInt(item = hints[index]) && item > 0)) {
  29080. throw new Error('Hint (' + index +
  29081. ') in the linearization dictionary is invalid.');
  29082. }
  29083. }
  29084. return hints;
  29085. }
  29086. throw new Error('Hint array in the linearization dictionary is invalid.');
  29087. }
  29088. var parser = new Parser(new Lexer(stream), false, null);
  29089. var obj1 = parser.getObj();
  29090. var obj2 = parser.getObj();
  29091. var obj3 = parser.getObj();
  29092. var linDict = parser.getObj();
  29093. var obj, length;
  29094. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29095. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29096. return null; // No valid linearization dictionary found.
  29097. } else if ((length = getInt('L')) !== stream.length) {
  29098. throw new Error('The "L" parameter in the linearization dictionary ' +
  29099. 'does not equal the stream length.');
  29100. }
  29101. return {
  29102. length: length,
  29103. hints: getHints(),
  29104. objectNumberFirst: getInt('O'),
  29105. endFirst: getInt('E'),
  29106. numPages: getInt('N'),
  29107. mainXRefEntriesOffset: getInt('T'),
  29108. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29109. };
  29110. }
  29111. };
  29112. var PostScriptParser = (function PostScriptParserClosure() {
  29113. function PostScriptParser(lexer) {
  29114. this.lexer = lexer;
  29115. this.operators = [];
  29116. this.token = null;
  29117. this.prev = null;
  29118. }
  29119. PostScriptParser.prototype = {
  29120. nextToken: function PostScriptParser_nextToken() {
  29121. this.prev = this.token;
  29122. this.token = this.lexer.getToken();
  29123. },
  29124. accept: function PostScriptParser_accept(type) {
  29125. if (this.token.type === type) {
  29126. this.nextToken();
  29127. return true;
  29128. }
  29129. return false;
  29130. },
  29131. expect: function PostScriptParser_expect(type) {
  29132. if (this.accept(type)) {
  29133. return true;
  29134. }
  29135. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29136. type + '.');
  29137. },
  29138. parse: function PostScriptParser_parse() {
  29139. this.nextToken();
  29140. this.expect(PostScriptTokenTypes.LBRACE);
  29141. this.parseBlock();
  29142. this.expect(PostScriptTokenTypes.RBRACE);
  29143. return this.operators;
  29144. },
  29145. parseBlock: function PostScriptParser_parseBlock() {
  29146. while (true) {
  29147. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29148. this.operators.push(this.prev.value);
  29149. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29150. this.operators.push(this.prev.value);
  29151. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29152. this.parseCondition();
  29153. } else {
  29154. return;
  29155. }
  29156. }
  29157. },
  29158. parseCondition: function PostScriptParser_parseCondition() {
  29159. // Add two place holders that will be updated later
  29160. var conditionLocation = this.operators.length;
  29161. this.operators.push(null, null);
  29162. this.parseBlock();
  29163. this.expect(PostScriptTokenTypes.RBRACE);
  29164. if (this.accept(PostScriptTokenTypes.IF)) {
  29165. // The true block is right after the 'if' so it just falls through on
  29166. // true else it jumps and skips the true block.
  29167. this.operators[conditionLocation] = this.operators.length;
  29168. this.operators[conditionLocation + 1] = 'jz';
  29169. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29170. var jumpLocation = this.operators.length;
  29171. this.operators.push(null, null);
  29172. var endOfTrue = this.operators.length;
  29173. this.parseBlock();
  29174. this.expect(PostScriptTokenTypes.RBRACE);
  29175. this.expect(PostScriptTokenTypes.IFELSE);
  29176. // The jump is added at the end of the true block to skip the false
  29177. // block.
  29178. this.operators[jumpLocation] = this.operators.length;
  29179. this.operators[jumpLocation + 1] = 'j';
  29180. this.operators[conditionLocation] = endOfTrue;
  29181. this.operators[conditionLocation + 1] = 'jz';
  29182. } else {
  29183. error('PS Function: error parsing conditional.');
  29184. }
  29185. }
  29186. };
  29187. return PostScriptParser;
  29188. })();
  29189. var PostScriptTokenTypes = {
  29190. LBRACE: 0,
  29191. RBRACE: 1,
  29192. NUMBER: 2,
  29193. OPERATOR: 3,
  29194. IF: 4,
  29195. IFELSE: 5
  29196. };
  29197. var PostScriptToken = (function PostScriptTokenClosure() {
  29198. function PostScriptToken(type, value) {
  29199. this.type = type;
  29200. this.value = value;
  29201. }
  29202. var opCache = {};
  29203. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29204. var opValue = opCache[op];
  29205. if (opValue) {
  29206. return opValue;
  29207. }
  29208. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29209. };
  29210. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29211. '{');
  29212. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29213. '}');
  29214. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29215. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29216. 'IFELSE');
  29217. return PostScriptToken;
  29218. })();
  29219. var PostScriptLexer = (function PostScriptLexerClosure() {
  29220. function PostScriptLexer(stream) {
  29221. this.stream = stream;
  29222. this.nextChar();
  29223. this.strBuf = [];
  29224. }
  29225. PostScriptLexer.prototype = {
  29226. nextChar: function PostScriptLexer_nextChar() {
  29227. return (this.currentChar = this.stream.getByte());
  29228. },
  29229. getToken: function PostScriptLexer_getToken() {
  29230. var comment = false;
  29231. var ch = this.currentChar;
  29232. // skip comments
  29233. while (true) {
  29234. if (ch < 0) {
  29235. return EOF;
  29236. }
  29237. if (comment) {
  29238. if (ch === 0x0A || ch === 0x0D) {
  29239. comment = false;
  29240. }
  29241. } else if (ch === 0x25) { // '%'
  29242. comment = true;
  29243. } else if (!Lexer.isSpace(ch)) {
  29244. break;
  29245. }
  29246. ch = this.nextChar();
  29247. }
  29248. switch (ch | 0) {
  29249. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29250. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29251. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29252. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29253. this.getNumber());
  29254. case 0x7B: // '{'
  29255. this.nextChar();
  29256. return PostScriptToken.LBRACE;
  29257. case 0x7D: // '}'
  29258. this.nextChar();
  29259. return PostScriptToken.RBRACE;
  29260. }
  29261. // operator
  29262. var strBuf = this.strBuf;
  29263. strBuf.length = 0;
  29264. strBuf[0] = String.fromCharCode(ch);
  29265. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29266. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29267. strBuf.push(String.fromCharCode(ch));
  29268. }
  29269. var str = strBuf.join('');
  29270. switch (str.toLowerCase()) {
  29271. case 'if':
  29272. return PostScriptToken.IF;
  29273. case 'ifelse':
  29274. return PostScriptToken.IFELSE;
  29275. default:
  29276. return PostScriptToken.getOperator(str);
  29277. }
  29278. },
  29279. getNumber: function PostScriptLexer_getNumber() {
  29280. var ch = this.currentChar;
  29281. var strBuf = this.strBuf;
  29282. strBuf.length = 0;
  29283. strBuf[0] = String.fromCharCode(ch);
  29284. while ((ch = this.nextChar()) >= 0) {
  29285. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29286. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29287. strBuf.push(String.fromCharCode(ch));
  29288. } else {
  29289. break;
  29290. }
  29291. }
  29292. var value = parseFloat(strBuf.join(''));
  29293. if (isNaN(value)) {
  29294. error('Invalid floating point number: ' + value);
  29295. }
  29296. return value;
  29297. }
  29298. };
  29299. return PostScriptLexer;
  29300. })();
  29301. var Stream = (function StreamClosure() {
  29302. function Stream(arrayBuffer, start, length, dict) {
  29303. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29304. arrayBuffer : new Uint8Array(arrayBuffer));
  29305. this.start = start || 0;
  29306. this.pos = this.start;
  29307. this.end = (start + length) || this.bytes.length;
  29308. this.dict = dict;
  29309. }
  29310. // required methods for a stream. if a particular stream does not
  29311. // implement these, an error should be thrown
  29312. Stream.prototype = {
  29313. get length() {
  29314. return this.end - this.start;
  29315. },
  29316. get isEmpty() {
  29317. return this.length === 0;
  29318. },
  29319. getByte: function Stream_getByte() {
  29320. if (this.pos >= this.end) {
  29321. return -1;
  29322. }
  29323. return this.bytes[this.pos++];
  29324. },
  29325. getUint16: function Stream_getUint16() {
  29326. var b0 = this.getByte();
  29327. var b1 = this.getByte();
  29328. return (b0 << 8) + b1;
  29329. },
  29330. getInt32: function Stream_getInt32() {
  29331. var b0 = this.getByte();
  29332. var b1 = this.getByte();
  29333. var b2 = this.getByte();
  29334. var b3 = this.getByte();
  29335. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29336. },
  29337. // returns subarray of original buffer
  29338. // should only be read
  29339. getBytes: function Stream_getBytes(length) {
  29340. var bytes = this.bytes;
  29341. var pos = this.pos;
  29342. var strEnd = this.end;
  29343. if (!length) {
  29344. return bytes.subarray(pos, strEnd);
  29345. }
  29346. var end = pos + length;
  29347. if (end > strEnd) {
  29348. end = strEnd;
  29349. }
  29350. this.pos = end;
  29351. return bytes.subarray(pos, end);
  29352. },
  29353. peekByte: function Stream_peekByte() {
  29354. var peekedByte = this.getByte();
  29355. this.pos--;
  29356. return peekedByte;
  29357. },
  29358. peekBytes: function Stream_peekBytes(length) {
  29359. var bytes = this.getBytes(length);
  29360. this.pos -= bytes.length;
  29361. return bytes;
  29362. },
  29363. skip: function Stream_skip(n) {
  29364. if (!n) {
  29365. n = 1;
  29366. }
  29367. this.pos += n;
  29368. },
  29369. reset: function Stream_reset() {
  29370. this.pos = this.start;
  29371. },
  29372. moveStart: function Stream_moveStart() {
  29373. this.start = this.pos;
  29374. },
  29375. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29376. return new Stream(this.bytes.buffer, start, length, dict);
  29377. },
  29378. isStream: true
  29379. };
  29380. return Stream;
  29381. })();
  29382. var StringStream = (function StringStreamClosure() {
  29383. function StringStream(str) {
  29384. var length = str.length;
  29385. var bytes = new Uint8Array(length);
  29386. for (var n = 0; n < length; ++n) {
  29387. bytes[n] = str.charCodeAt(n);
  29388. }
  29389. Stream.call(this, bytes);
  29390. }
  29391. StringStream.prototype = Stream.prototype;
  29392. return StringStream;
  29393. })();
  29394. // super class for the decoding streams
  29395. var DecodeStream = (function DecodeStreamClosure() {
  29396. // Lots of DecodeStreams are created whose buffers are never used. For these
  29397. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29398. // having special cases that would be required if we used |null| for an empty
  29399. // buffer.
  29400. var emptyBuffer = new Uint8Array(0);
  29401. function DecodeStream(maybeMinBufferLength) {
  29402. this.pos = 0;
  29403. this.bufferLength = 0;
  29404. this.eof = false;
  29405. this.buffer = emptyBuffer;
  29406. this.minBufferLength = 512;
  29407. if (maybeMinBufferLength) {
  29408. // Compute the first power of two that is as big as maybeMinBufferLength.
  29409. while (this.minBufferLength < maybeMinBufferLength) {
  29410. this.minBufferLength *= 2;
  29411. }
  29412. }
  29413. }
  29414. DecodeStream.prototype = {
  29415. get isEmpty() {
  29416. while (!this.eof && this.bufferLength === 0) {
  29417. this.readBlock();
  29418. }
  29419. return this.bufferLength === 0;
  29420. },
  29421. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29422. var buffer = this.buffer;
  29423. if (requested <= buffer.byteLength) {
  29424. return buffer;
  29425. }
  29426. var size = this.minBufferLength;
  29427. while (size < requested) {
  29428. size *= 2;
  29429. }
  29430. var buffer2 = new Uint8Array(size);
  29431. buffer2.set(buffer);
  29432. return (this.buffer = buffer2);
  29433. },
  29434. getByte: function DecodeStream_getByte() {
  29435. var pos = this.pos;
  29436. while (this.bufferLength <= pos) {
  29437. if (this.eof) {
  29438. return -1;
  29439. }
  29440. this.readBlock();
  29441. }
  29442. return this.buffer[this.pos++];
  29443. },
  29444. getUint16: function DecodeStream_getUint16() {
  29445. var b0 = this.getByte();
  29446. var b1 = this.getByte();
  29447. return (b0 << 8) + b1;
  29448. },
  29449. getInt32: function DecodeStream_getInt32() {
  29450. var b0 = this.getByte();
  29451. var b1 = this.getByte();
  29452. var b2 = this.getByte();
  29453. var b3 = this.getByte();
  29454. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29455. },
  29456. getBytes: function DecodeStream_getBytes(length) {
  29457. var end, pos = this.pos;
  29458. if (length) {
  29459. this.ensureBuffer(pos + length);
  29460. end = pos + length;
  29461. while (!this.eof && this.bufferLength < end) {
  29462. this.readBlock();
  29463. }
  29464. var bufEnd = this.bufferLength;
  29465. if (end > bufEnd) {
  29466. end = bufEnd;
  29467. }
  29468. } else {
  29469. while (!this.eof) {
  29470. this.readBlock();
  29471. }
  29472. end = this.bufferLength;
  29473. }
  29474. this.pos = end;
  29475. return this.buffer.subarray(pos, end);
  29476. },
  29477. peekByte: function DecodeStream_peekByte() {
  29478. var peekedByte = this.getByte();
  29479. this.pos--;
  29480. return peekedByte;
  29481. },
  29482. peekBytes: function DecodeStream_peekBytes(length) {
  29483. var bytes = this.getBytes(length);
  29484. this.pos -= bytes.length;
  29485. return bytes;
  29486. },
  29487. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29488. var end = start + length;
  29489. while (this.bufferLength <= end && !this.eof) {
  29490. this.readBlock();
  29491. }
  29492. return new Stream(this.buffer, start, length, dict);
  29493. },
  29494. skip: function DecodeStream_skip(n) {
  29495. if (!n) {
  29496. n = 1;
  29497. }
  29498. this.pos += n;
  29499. },
  29500. reset: function DecodeStream_reset() {
  29501. this.pos = 0;
  29502. },
  29503. getBaseStreams: function DecodeStream_getBaseStreams() {
  29504. if (this.str && this.str.getBaseStreams) {
  29505. return this.str.getBaseStreams();
  29506. }
  29507. return [];
  29508. }
  29509. };
  29510. return DecodeStream;
  29511. })();
  29512. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29513. function StreamsSequenceStream(streams) {
  29514. this.streams = streams;
  29515. DecodeStream.call(this, /* maybeLength = */ null);
  29516. }
  29517. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29518. StreamsSequenceStream.prototype.readBlock =
  29519. function streamSequenceStreamReadBlock() {
  29520. var streams = this.streams;
  29521. if (streams.length === 0) {
  29522. this.eof = true;
  29523. return;
  29524. }
  29525. var stream = streams.shift();
  29526. var chunk = stream.getBytes();
  29527. var bufferLength = this.bufferLength;
  29528. var newLength = bufferLength + chunk.length;
  29529. var buffer = this.ensureBuffer(newLength);
  29530. buffer.set(chunk, bufferLength);
  29531. this.bufferLength = newLength;
  29532. };
  29533. StreamsSequenceStream.prototype.getBaseStreams =
  29534. function StreamsSequenceStream_getBaseStreams() {
  29535. var baseStreams = [];
  29536. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29537. var stream = this.streams[i];
  29538. if (stream.getBaseStreams) {
  29539. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29540. }
  29541. }
  29542. return baseStreams;
  29543. };
  29544. return StreamsSequenceStream;
  29545. })();
  29546. var FlateStream = (function FlateStreamClosure() {
  29547. var codeLenCodeMap = new Uint32Array([
  29548. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29549. ]);
  29550. var lengthDecode = new Uint32Array([
  29551. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29552. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29553. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29554. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29555. ]);
  29556. var distDecode = new Uint32Array([
  29557. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29558. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29559. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29560. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29561. ]);
  29562. var fixedLitCodeTab = [new Uint32Array([
  29563. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29564. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29565. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29566. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29567. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29568. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29569. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29570. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29571. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29572. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29573. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29574. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29575. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29576. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29577. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29578. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29579. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29580. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29581. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29582. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29583. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29584. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29585. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29586. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29587. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29588. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29589. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29590. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29591. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29592. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29593. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29594. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29595. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29596. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29597. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29598. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29599. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29600. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29601. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29602. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29603. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29604. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29605. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29606. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29607. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29608. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29609. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29610. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29611. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29612. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29613. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29614. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29615. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29616. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29617. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29618. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29619. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29620. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29621. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29622. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29623. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29624. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29625. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29626. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29627. ]), 9];
  29628. var fixedDistCodeTab = [new Uint32Array([
  29629. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29630. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29631. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29632. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29633. ]), 5];
  29634. function FlateStream(str, maybeLength) {
  29635. this.str = str;
  29636. this.dict = str.dict;
  29637. var cmf = str.getByte();
  29638. var flg = str.getByte();
  29639. if (cmf === -1 || flg === -1) {
  29640. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29641. }
  29642. if ((cmf & 0x0f) !== 0x08) {
  29643. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29644. }
  29645. if ((((cmf << 8) + flg) % 31) !== 0) {
  29646. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29647. }
  29648. if (flg & 0x20) {
  29649. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29650. }
  29651. this.codeSize = 0;
  29652. this.codeBuf = 0;
  29653. DecodeStream.call(this, maybeLength);
  29654. }
  29655. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29656. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29657. var str = this.str;
  29658. var codeSize = this.codeSize;
  29659. var codeBuf = this.codeBuf;
  29660. var b;
  29661. while (codeSize < bits) {
  29662. if ((b = str.getByte()) === -1) {
  29663. error('Bad encoding in flate stream');
  29664. }
  29665. codeBuf |= b << codeSize;
  29666. codeSize += 8;
  29667. }
  29668. b = codeBuf & ((1 << bits) - 1);
  29669. this.codeBuf = codeBuf >> bits;
  29670. this.codeSize = codeSize -= bits;
  29671. return b;
  29672. };
  29673. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29674. var str = this.str;
  29675. var codes = table[0];
  29676. var maxLen = table[1];
  29677. var codeSize = this.codeSize;
  29678. var codeBuf = this.codeBuf;
  29679. var b;
  29680. while (codeSize < maxLen) {
  29681. if ((b = str.getByte()) === -1) {
  29682. // premature end of stream. code might however still be valid.
  29683. // codeSize < codeLen check below guards against incomplete codeVal.
  29684. break;
  29685. }
  29686. codeBuf |= (b << codeSize);
  29687. codeSize += 8;
  29688. }
  29689. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29690. var codeLen = code >> 16;
  29691. var codeVal = code & 0xffff;
  29692. if (codeLen < 1 || codeSize < codeLen) {
  29693. error('Bad encoding in flate stream');
  29694. }
  29695. this.codeBuf = (codeBuf >> codeLen);
  29696. this.codeSize = (codeSize - codeLen);
  29697. return codeVal;
  29698. };
  29699. FlateStream.prototype.generateHuffmanTable =
  29700. function flateStreamGenerateHuffmanTable(lengths) {
  29701. var n = lengths.length;
  29702. // find max code length
  29703. var maxLen = 0;
  29704. var i;
  29705. for (i = 0; i < n; ++i) {
  29706. if (lengths[i] > maxLen) {
  29707. maxLen = lengths[i];
  29708. }
  29709. }
  29710. // build the table
  29711. var size = 1 << maxLen;
  29712. var codes = new Uint32Array(size);
  29713. for (var len = 1, code = 0, skip = 2;
  29714. len <= maxLen;
  29715. ++len, code <<= 1, skip <<= 1) {
  29716. for (var val = 0; val < n; ++val) {
  29717. if (lengths[val] === len) {
  29718. // bit-reverse the code
  29719. var code2 = 0;
  29720. var t = code;
  29721. for (i = 0; i < len; ++i) {
  29722. code2 = (code2 << 1) | (t & 1);
  29723. t >>= 1;
  29724. }
  29725. // fill the table entries
  29726. for (i = code2; i < size; i += skip) {
  29727. codes[i] = (len << 16) | val;
  29728. }
  29729. ++code;
  29730. }
  29731. }
  29732. }
  29733. return [codes, maxLen];
  29734. };
  29735. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29736. var buffer, len;
  29737. var str = this.str;
  29738. // read block header
  29739. var hdr = this.getBits(3);
  29740. if (hdr & 1) {
  29741. this.eof = true;
  29742. }
  29743. hdr >>= 1;
  29744. if (hdr === 0) { // uncompressed block
  29745. var b;
  29746. if ((b = str.getByte()) === -1) {
  29747. error('Bad block header in flate stream');
  29748. }
  29749. var blockLen = b;
  29750. if ((b = str.getByte()) === -1) {
  29751. error('Bad block header in flate stream');
  29752. }
  29753. blockLen |= (b << 8);
  29754. if ((b = str.getByte()) === -1) {
  29755. error('Bad block header in flate stream');
  29756. }
  29757. var check = b;
  29758. if ((b = str.getByte()) === -1) {
  29759. error('Bad block header in flate stream');
  29760. }
  29761. check |= (b << 8);
  29762. if (check !== (~blockLen & 0xffff) &&
  29763. (blockLen !== 0 || check !== 0)) {
  29764. // Ignoring error for bad "empty" block (see issue 1277)
  29765. error('Bad uncompressed block length in flate stream');
  29766. }
  29767. this.codeBuf = 0;
  29768. this.codeSize = 0;
  29769. var bufferLength = this.bufferLength;
  29770. buffer = this.ensureBuffer(bufferLength + blockLen);
  29771. var end = bufferLength + blockLen;
  29772. this.bufferLength = end;
  29773. if (blockLen === 0) {
  29774. if (str.peekByte() === -1) {
  29775. this.eof = true;
  29776. }
  29777. } else {
  29778. for (var n = bufferLength; n < end; ++n) {
  29779. if ((b = str.getByte()) === -1) {
  29780. this.eof = true;
  29781. break;
  29782. }
  29783. buffer[n] = b;
  29784. }
  29785. }
  29786. return;
  29787. }
  29788. var litCodeTable;
  29789. var distCodeTable;
  29790. if (hdr === 1) { // compressed block, fixed codes
  29791. litCodeTable = fixedLitCodeTab;
  29792. distCodeTable = fixedDistCodeTab;
  29793. } else if (hdr === 2) { // compressed block, dynamic codes
  29794. var numLitCodes = this.getBits(5) + 257;
  29795. var numDistCodes = this.getBits(5) + 1;
  29796. var numCodeLenCodes = this.getBits(4) + 4;
  29797. // build the code lengths code table
  29798. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29799. var i;
  29800. for (i = 0; i < numCodeLenCodes; ++i) {
  29801. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29802. }
  29803. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29804. // build the literal and distance code tables
  29805. len = 0;
  29806. i = 0;
  29807. var codes = numLitCodes + numDistCodes;
  29808. var codeLengths = new Uint8Array(codes);
  29809. var bitsLength, bitsOffset, what;
  29810. while (i < codes) {
  29811. var code = this.getCode(codeLenCodeTab);
  29812. if (code === 16) {
  29813. bitsLength = 2; bitsOffset = 3; what = len;
  29814. } else if (code === 17) {
  29815. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29816. } else if (code === 18) {
  29817. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29818. } else {
  29819. codeLengths[i++] = len = code;
  29820. continue;
  29821. }
  29822. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29823. while (repeatLength-- > 0) {
  29824. codeLengths[i++] = what;
  29825. }
  29826. }
  29827. litCodeTable =
  29828. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29829. distCodeTable =
  29830. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29831. } else {
  29832. error('Unknown block type in flate stream');
  29833. }
  29834. buffer = this.buffer;
  29835. var limit = buffer ? buffer.length : 0;
  29836. var pos = this.bufferLength;
  29837. while (true) {
  29838. var code1 = this.getCode(litCodeTable);
  29839. if (code1 < 256) {
  29840. if (pos + 1 >= limit) {
  29841. buffer = this.ensureBuffer(pos + 1);
  29842. limit = buffer.length;
  29843. }
  29844. buffer[pos++] = code1;
  29845. continue;
  29846. }
  29847. if (code1 === 256) {
  29848. this.bufferLength = pos;
  29849. return;
  29850. }
  29851. code1 -= 257;
  29852. code1 = lengthDecode[code1];
  29853. var code2 = code1 >> 16;
  29854. if (code2 > 0) {
  29855. code2 = this.getBits(code2);
  29856. }
  29857. len = (code1 & 0xffff) + code2;
  29858. code1 = this.getCode(distCodeTable);
  29859. code1 = distDecode[code1];
  29860. code2 = code1 >> 16;
  29861. if (code2 > 0) {
  29862. code2 = this.getBits(code2);
  29863. }
  29864. var dist = (code1 & 0xffff) + code2;
  29865. if (pos + len >= limit) {
  29866. buffer = this.ensureBuffer(pos + len);
  29867. limit = buffer.length;
  29868. }
  29869. for (var k = 0; k < len; ++k, ++pos) {
  29870. buffer[pos] = buffer[pos - dist];
  29871. }
  29872. }
  29873. };
  29874. return FlateStream;
  29875. })();
  29876. var PredictorStream = (function PredictorStreamClosure() {
  29877. function PredictorStream(str, maybeLength, params) {
  29878. var predictor = this.predictor = params.get('Predictor') || 1;
  29879. if (predictor <= 1) {
  29880. return str; // no prediction
  29881. }
  29882. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  29883. error('Unsupported predictor: ' + predictor);
  29884. }
  29885. if (predictor === 2) {
  29886. this.readBlock = this.readBlockTiff;
  29887. } else {
  29888. this.readBlock = this.readBlockPng;
  29889. }
  29890. this.str = str;
  29891. this.dict = str.dict;
  29892. var colors = this.colors = params.get('Colors') || 1;
  29893. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29894. var columns = this.columns = params.get('Columns') || 1;
  29895. this.pixBytes = (colors * bits + 7) >> 3;
  29896. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29897. DecodeStream.call(this, maybeLength);
  29898. return this;
  29899. }
  29900. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29901. PredictorStream.prototype.readBlockTiff =
  29902. function predictorStreamReadBlockTiff() {
  29903. var rowBytes = this.rowBytes;
  29904. var bufferLength = this.bufferLength;
  29905. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29906. var bits = this.bits;
  29907. var colors = this.colors;
  29908. var rawBytes = this.str.getBytes(rowBytes);
  29909. this.eof = !rawBytes.length;
  29910. if (this.eof) {
  29911. return;
  29912. }
  29913. var inbuf = 0, outbuf = 0;
  29914. var inbits = 0, outbits = 0;
  29915. var pos = bufferLength;
  29916. var i;
  29917. if (bits === 1) {
  29918. for (i = 0; i < rowBytes; ++i) {
  29919. var c = rawBytes[i];
  29920. inbuf = (inbuf << 8) | c;
  29921. // bitwise addition is exclusive or
  29922. // first shift inbuf and then add
  29923. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  29924. // truncate inbuf (assumes colors < 16)
  29925. inbuf &= 0xFFFF;
  29926. }
  29927. } else if (bits === 8) {
  29928. for (i = 0; i < colors; ++i) {
  29929. buffer[pos++] = rawBytes[i];
  29930. }
  29931. for (; i < rowBytes; ++i) {
  29932. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  29933. pos++;
  29934. }
  29935. } else {
  29936. var compArray = new Uint8Array(colors + 1);
  29937. var bitMask = (1 << bits) - 1;
  29938. var j = 0, k = bufferLength;
  29939. var columns = this.columns;
  29940. for (i = 0; i < columns; ++i) {
  29941. for (var kk = 0; kk < colors; ++kk) {
  29942. if (inbits < bits) {
  29943. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  29944. inbits += 8;
  29945. }
  29946. compArray[kk] = (compArray[kk] +
  29947. (inbuf >> (inbits - bits))) & bitMask;
  29948. inbits -= bits;
  29949. outbuf = (outbuf << bits) | compArray[kk];
  29950. outbits += bits;
  29951. if (outbits >= 8) {
  29952. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  29953. outbits -= 8;
  29954. }
  29955. }
  29956. }
  29957. if (outbits > 0) {
  29958. buffer[k++] = (outbuf << (8 - outbits)) +
  29959. (inbuf & ((1 << (8 - outbits)) - 1));
  29960. }
  29961. }
  29962. this.bufferLength += rowBytes;
  29963. };
  29964. PredictorStream.prototype.readBlockPng =
  29965. function predictorStreamReadBlockPng() {
  29966. var rowBytes = this.rowBytes;
  29967. var pixBytes = this.pixBytes;
  29968. var predictor = this.str.getByte();
  29969. var rawBytes = this.str.getBytes(rowBytes);
  29970. this.eof = !rawBytes.length;
  29971. if (this.eof) {
  29972. return;
  29973. }
  29974. var bufferLength = this.bufferLength;
  29975. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29976. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  29977. if (prevRow.length === 0) {
  29978. prevRow = new Uint8Array(rowBytes);
  29979. }
  29980. var i, j = bufferLength, up, c;
  29981. switch (predictor) {
  29982. case 0:
  29983. for (i = 0; i < rowBytes; ++i) {
  29984. buffer[j++] = rawBytes[i];
  29985. }
  29986. break;
  29987. case 1:
  29988. for (i = 0; i < pixBytes; ++i) {
  29989. buffer[j++] = rawBytes[i];
  29990. }
  29991. for (; i < rowBytes; ++i) {
  29992. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  29993. j++;
  29994. }
  29995. break;
  29996. case 2:
  29997. for (i = 0; i < rowBytes; ++i) {
  29998. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  29999. }
  30000. break;
  30001. case 3:
  30002. for (i = 0; i < pixBytes; ++i) {
  30003. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30004. }
  30005. for (; i < rowBytes; ++i) {
  30006. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30007. rawBytes[i]) & 0xFF;
  30008. j++;
  30009. }
  30010. break;
  30011. case 4:
  30012. // we need to save the up left pixels values. the simplest way
  30013. // is to create a new buffer
  30014. for (i = 0; i < pixBytes; ++i) {
  30015. up = prevRow[i];
  30016. c = rawBytes[i];
  30017. buffer[j++] = up + c;
  30018. }
  30019. for (; i < rowBytes; ++i) {
  30020. up = prevRow[i];
  30021. var upLeft = prevRow[i - pixBytes];
  30022. var left = buffer[j - pixBytes];
  30023. var p = left + up - upLeft;
  30024. var pa = p - left;
  30025. if (pa < 0) {
  30026. pa = -pa;
  30027. }
  30028. var pb = p - up;
  30029. if (pb < 0) {
  30030. pb = -pb;
  30031. }
  30032. var pc = p - upLeft;
  30033. if (pc < 0) {
  30034. pc = -pc;
  30035. }
  30036. c = rawBytes[i];
  30037. if (pa <= pb && pa <= pc) {
  30038. buffer[j++] = left + c;
  30039. } else if (pb <= pc) {
  30040. buffer[j++] = up + c;
  30041. } else {
  30042. buffer[j++] = upLeft + c;
  30043. }
  30044. }
  30045. break;
  30046. default:
  30047. error('Unsupported predictor: ' + predictor);
  30048. }
  30049. this.bufferLength += rowBytes;
  30050. };
  30051. return PredictorStream;
  30052. })();
  30053. /**
  30054. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30055. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30056. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30057. * a library to decode these images and the stream behaves like all the other
  30058. * DecodeStreams.
  30059. */
  30060. var JpegStream = (function JpegStreamClosure() {
  30061. function JpegStream(stream, maybeLength, dict, xref) {
  30062. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30063. // Note: this seems to mainly affect inline images.
  30064. var ch;
  30065. while ((ch = stream.getByte()) !== -1) {
  30066. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30067. stream.skip(-1); // Reset the stream position to the SOI.
  30068. break;
  30069. }
  30070. }
  30071. this.stream = stream;
  30072. this.maybeLength = maybeLength;
  30073. this.dict = dict;
  30074. DecodeStream.call(this, maybeLength);
  30075. }
  30076. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30077. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30078. get: function JpegStream_bytes() {
  30079. // If this.maybeLength is null, we'll get the entire stream.
  30080. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30081. },
  30082. configurable: true
  30083. });
  30084. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30085. if (this.bufferLength) {
  30086. return;
  30087. }
  30088. try {
  30089. var jpegImage = new JpegImage();
  30090. // checking if values needs to be transformed before conversion
  30091. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30092. var decodeArr = this.dict.get('Decode');
  30093. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30094. var decodeArrLength = decodeArr.length;
  30095. var transform = new Int32Array(decodeArrLength);
  30096. var transformNeeded = false;
  30097. var maxValue = (1 << bitsPerComponent) - 1;
  30098. for (var i = 0; i < decodeArrLength; i += 2) {
  30099. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30100. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30101. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30102. transformNeeded = true;
  30103. }
  30104. }
  30105. if (transformNeeded) {
  30106. jpegImage.decodeTransform = transform;
  30107. }
  30108. }
  30109. jpegImage.parse(this.bytes);
  30110. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30111. this.forceRGB);
  30112. this.buffer = data;
  30113. this.bufferLength = data.length;
  30114. this.eof = true;
  30115. } catch (e) {
  30116. error('JPEG error: ' + e);
  30117. }
  30118. };
  30119. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30120. this.ensureBuffer();
  30121. return this.buffer;
  30122. };
  30123. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30124. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30125. };
  30126. /**
  30127. * Checks if the image can be decoded and displayed by the browser without any
  30128. * further processing such as color space conversions.
  30129. */
  30130. JpegStream.prototype.isNativelySupported =
  30131. function JpegStream_isNativelySupported(xref, res) {
  30132. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30133. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30134. };
  30135. /**
  30136. * Checks if the image can be decoded by the browser.
  30137. */
  30138. JpegStream.prototype.isNativelyDecodable =
  30139. function JpegStream_isNativelyDecodable(xref, res) {
  30140. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30141. var numComps = cs.numComps;
  30142. return numComps === 1 || numComps === 3;
  30143. };
  30144. return JpegStream;
  30145. })();
  30146. /**
  30147. * For JPEG 2000's we use a library to decode these images and
  30148. * the stream behaves like all the other DecodeStreams.
  30149. */
  30150. var JpxStream = (function JpxStreamClosure() {
  30151. function JpxStream(stream, maybeLength, dict) {
  30152. this.stream = stream;
  30153. this.maybeLength = maybeLength;
  30154. this.dict = dict;
  30155. DecodeStream.call(this, maybeLength);
  30156. }
  30157. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30158. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30159. get: function JpxStream_bytes() {
  30160. // If this.maybeLength is null, we'll get the entire stream.
  30161. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30162. },
  30163. configurable: true
  30164. });
  30165. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30166. if (this.bufferLength) {
  30167. return;
  30168. }
  30169. var jpxImage = new JpxImage();
  30170. jpxImage.parse(this.bytes);
  30171. var width = jpxImage.width;
  30172. var height = jpxImage.height;
  30173. var componentsCount = jpxImage.componentsCount;
  30174. var tileCount = jpxImage.tiles.length;
  30175. if (tileCount === 1) {
  30176. this.buffer = jpxImage.tiles[0].items;
  30177. } else {
  30178. var data = new Uint8Array(width * height * componentsCount);
  30179. for (var k = 0; k < tileCount; k++) {
  30180. var tileComponents = jpxImage.tiles[k];
  30181. var tileWidth = tileComponents.width;
  30182. var tileHeight = tileComponents.height;
  30183. var tileLeft = tileComponents.left;
  30184. var tileTop = tileComponents.top;
  30185. var src = tileComponents.items;
  30186. var srcPosition = 0;
  30187. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30188. var imgRowSize = width * componentsCount;
  30189. var tileRowSize = tileWidth * componentsCount;
  30190. for (var j = 0; j < tileHeight; j++) {
  30191. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30192. data.set(rowBytes, dataPosition);
  30193. srcPosition += tileRowSize;
  30194. dataPosition += imgRowSize;
  30195. }
  30196. }
  30197. this.buffer = data;
  30198. }
  30199. this.bufferLength = this.buffer.length;
  30200. this.eof = true;
  30201. };
  30202. return JpxStream;
  30203. })();
  30204. /**
  30205. * For JBIG2's we use a library to decode these images and
  30206. * the stream behaves like all the other DecodeStreams.
  30207. */
  30208. var Jbig2Stream = (function Jbig2StreamClosure() {
  30209. function Jbig2Stream(stream, maybeLength, dict) {
  30210. this.stream = stream;
  30211. this.maybeLength = maybeLength;
  30212. this.dict = dict;
  30213. DecodeStream.call(this, maybeLength);
  30214. }
  30215. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30216. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30217. get: function Jbig2Stream_bytes() {
  30218. // If this.maybeLength is null, we'll get the entire stream.
  30219. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30220. },
  30221. configurable: true
  30222. });
  30223. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30224. if (this.bufferLength) {
  30225. return;
  30226. }
  30227. var jbig2Image = new Jbig2Image();
  30228. var chunks = [], xref = this.dict.xref;
  30229. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30230. // According to the PDF specification, DecodeParms can be either
  30231. // a dictionary, or an array whose elements are dictionaries.
  30232. if (isArray(decodeParams)) {
  30233. if (decodeParams.length > 1) {
  30234. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30235. 'not supported.');
  30236. }
  30237. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30238. }
  30239. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30240. var globalsStream = decodeParams.get('JBIG2Globals');
  30241. var globals = globalsStream.getBytes();
  30242. chunks.push({data: globals, start: 0, end: globals.length});
  30243. }
  30244. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30245. var data = jbig2Image.parseChunks(chunks);
  30246. var dataLength = data.length;
  30247. // JBIG2 had black as 1 and white as 0, inverting the colors
  30248. for (var i = 0; i < dataLength; i++) {
  30249. data[i] ^= 0xFF;
  30250. }
  30251. this.buffer = data;
  30252. this.bufferLength = dataLength;
  30253. this.eof = true;
  30254. };
  30255. return Jbig2Stream;
  30256. })();
  30257. var DecryptStream = (function DecryptStreamClosure() {
  30258. function DecryptStream(str, maybeLength, decrypt) {
  30259. this.str = str;
  30260. this.dict = str.dict;
  30261. this.decrypt = decrypt;
  30262. this.nextChunk = null;
  30263. this.initialized = false;
  30264. DecodeStream.call(this, maybeLength);
  30265. }
  30266. var chunkSize = 512;
  30267. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30268. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30269. var chunk;
  30270. if (this.initialized) {
  30271. chunk = this.nextChunk;
  30272. } else {
  30273. chunk = this.str.getBytes(chunkSize);
  30274. this.initialized = true;
  30275. }
  30276. if (!chunk || chunk.length === 0) {
  30277. this.eof = true;
  30278. return;
  30279. }
  30280. this.nextChunk = this.str.getBytes(chunkSize);
  30281. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30282. var decrypt = this.decrypt;
  30283. chunk = decrypt(chunk, !hasMoreData);
  30284. var bufferLength = this.bufferLength;
  30285. var i, n = chunk.length;
  30286. var buffer = this.ensureBuffer(bufferLength + n);
  30287. for (i = 0; i < n; i++) {
  30288. buffer[bufferLength++] = chunk[i];
  30289. }
  30290. this.bufferLength = bufferLength;
  30291. };
  30292. return DecryptStream;
  30293. })();
  30294. var Ascii85Stream = (function Ascii85StreamClosure() {
  30295. function Ascii85Stream(str, maybeLength) {
  30296. this.str = str;
  30297. this.dict = str.dict;
  30298. this.input = new Uint8Array(5);
  30299. // Most streams increase in size when decoded, but Ascii85 streams
  30300. // typically shrink by ~20%.
  30301. if (maybeLength) {
  30302. maybeLength = 0.8 * maybeLength;
  30303. }
  30304. DecodeStream.call(this, maybeLength);
  30305. }
  30306. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30307. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30308. var TILDA_CHAR = 0x7E; // '~'
  30309. var Z_LOWER_CHAR = 0x7A; // 'z'
  30310. var EOF = -1;
  30311. var str = this.str;
  30312. var c = str.getByte();
  30313. while (Lexer.isSpace(c)) {
  30314. c = str.getByte();
  30315. }
  30316. if (c === EOF || c === TILDA_CHAR) {
  30317. this.eof = true;
  30318. return;
  30319. }
  30320. var bufferLength = this.bufferLength, buffer;
  30321. var i;
  30322. // special code for z
  30323. if (c === Z_LOWER_CHAR) {
  30324. buffer = this.ensureBuffer(bufferLength + 4);
  30325. for (i = 0; i < 4; ++i) {
  30326. buffer[bufferLength + i] = 0;
  30327. }
  30328. this.bufferLength += 4;
  30329. } else {
  30330. var input = this.input;
  30331. input[0] = c;
  30332. for (i = 1; i < 5; ++i) {
  30333. c = str.getByte();
  30334. while (Lexer.isSpace(c)) {
  30335. c = str.getByte();
  30336. }
  30337. input[i] = c;
  30338. if (c === EOF || c === TILDA_CHAR) {
  30339. break;
  30340. }
  30341. }
  30342. buffer = this.ensureBuffer(bufferLength + i - 1);
  30343. this.bufferLength += i - 1;
  30344. // partial ending;
  30345. if (i < 5) {
  30346. for (; i < 5; ++i) {
  30347. input[i] = 0x21 + 84;
  30348. }
  30349. this.eof = true;
  30350. }
  30351. var t = 0;
  30352. for (i = 0; i < 5; ++i) {
  30353. t = t * 85 + (input[i] - 0x21);
  30354. }
  30355. for (i = 3; i >= 0; --i) {
  30356. buffer[bufferLength + i] = t & 0xFF;
  30357. t >>= 8;
  30358. }
  30359. }
  30360. };
  30361. return Ascii85Stream;
  30362. })();
  30363. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30364. function AsciiHexStream(str, maybeLength) {
  30365. this.str = str;
  30366. this.dict = str.dict;
  30367. this.firstDigit = -1;
  30368. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30369. // by 50%.
  30370. if (maybeLength) {
  30371. maybeLength = 0.5 * maybeLength;
  30372. }
  30373. DecodeStream.call(this, maybeLength);
  30374. }
  30375. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30376. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30377. var UPSTREAM_BLOCK_SIZE = 8000;
  30378. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30379. if (!bytes.length) {
  30380. this.eof = true;
  30381. return;
  30382. }
  30383. var maxDecodeLength = (bytes.length + 1) >> 1;
  30384. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30385. var bufferLength = this.bufferLength;
  30386. var firstDigit = this.firstDigit;
  30387. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30388. var ch = bytes[i], digit;
  30389. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30390. digit = ch & 0x0F;
  30391. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30392. // 'A'-'Z', 'a'-'z'
  30393. digit = (ch & 0x0F) + 9;
  30394. } else if (ch === 0x3E) { // '>'
  30395. this.eof = true;
  30396. break;
  30397. } else { // probably whitespace
  30398. continue; // ignoring
  30399. }
  30400. if (firstDigit < 0) {
  30401. firstDigit = digit;
  30402. } else {
  30403. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30404. firstDigit = -1;
  30405. }
  30406. }
  30407. if (firstDigit >= 0 && this.eof) {
  30408. // incomplete byte
  30409. buffer[bufferLength++] = (firstDigit << 4);
  30410. firstDigit = -1;
  30411. }
  30412. this.firstDigit = firstDigit;
  30413. this.bufferLength = bufferLength;
  30414. };
  30415. return AsciiHexStream;
  30416. })();
  30417. var RunLengthStream = (function RunLengthStreamClosure() {
  30418. function RunLengthStream(str, maybeLength) {
  30419. this.str = str;
  30420. this.dict = str.dict;
  30421. DecodeStream.call(this, maybeLength);
  30422. }
  30423. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30424. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30425. // The repeatHeader has following format. The first byte defines type of run
  30426. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30427. // (in addition to the second byte from the header), n = 129 through 255 -
  30428. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30429. var repeatHeader = this.str.getBytes(2);
  30430. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30431. this.eof = true;
  30432. return;
  30433. }
  30434. var buffer;
  30435. var bufferLength = this.bufferLength;
  30436. var n = repeatHeader[0];
  30437. if (n < 128) {
  30438. // copy n bytes
  30439. buffer = this.ensureBuffer(bufferLength + n + 1);
  30440. buffer[bufferLength++] = repeatHeader[1];
  30441. if (n > 0) {
  30442. var source = this.str.getBytes(n);
  30443. buffer.set(source, bufferLength);
  30444. bufferLength += n;
  30445. }
  30446. } else {
  30447. n = 257 - n;
  30448. var b = repeatHeader[1];
  30449. buffer = this.ensureBuffer(bufferLength + n + 1);
  30450. for (var i = 0; i < n; i++) {
  30451. buffer[bufferLength++] = b;
  30452. }
  30453. }
  30454. this.bufferLength = bufferLength;
  30455. };
  30456. return RunLengthStream;
  30457. })();
  30458. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30459. var ccittEOL = -2;
  30460. var twoDimPass = 0;
  30461. var twoDimHoriz = 1;
  30462. var twoDimVert0 = 2;
  30463. var twoDimVertR1 = 3;
  30464. var twoDimVertL1 = 4;
  30465. var twoDimVertR2 = 5;
  30466. var twoDimVertL2 = 6;
  30467. var twoDimVertR3 = 7;
  30468. var twoDimVertL3 = 8;
  30469. var twoDimTable = [
  30470. [-1, -1], [-1, -1], // 000000x
  30471. [7, twoDimVertL3], // 0000010
  30472. [7, twoDimVertR3], // 0000011
  30473. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30474. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30475. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30476. [4, twoDimPass], [4, twoDimPass],
  30477. [4, twoDimPass], [4, twoDimPass],
  30478. [4, twoDimPass], [4, twoDimPass],
  30479. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30480. [3, twoDimHoriz], [3, twoDimHoriz],
  30481. [3, twoDimHoriz], [3, twoDimHoriz],
  30482. [3, twoDimHoriz], [3, twoDimHoriz],
  30483. [3, twoDimHoriz], [3, twoDimHoriz],
  30484. [3, twoDimHoriz], [3, twoDimHoriz],
  30485. [3, twoDimHoriz], [3, twoDimHoriz],
  30486. [3, twoDimHoriz], [3, twoDimHoriz],
  30487. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30488. [3, twoDimVertL1], [3, twoDimVertL1],
  30489. [3, twoDimVertL1], [3, twoDimVertL1],
  30490. [3, twoDimVertL1], [3, twoDimVertL1],
  30491. [3, twoDimVertL1], [3, twoDimVertL1],
  30492. [3, twoDimVertL1], [3, twoDimVertL1],
  30493. [3, twoDimVertL1], [3, twoDimVertL1],
  30494. [3, twoDimVertL1], [3, twoDimVertL1],
  30495. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30496. [3, twoDimVertR1], [3, twoDimVertR1],
  30497. [3, twoDimVertR1], [3, twoDimVertR1],
  30498. [3, twoDimVertR1], [3, twoDimVertR1],
  30499. [3, twoDimVertR1], [3, twoDimVertR1],
  30500. [3, twoDimVertR1], [3, twoDimVertR1],
  30501. [3, twoDimVertR1], [3, twoDimVertR1],
  30502. [3, twoDimVertR1], [3, twoDimVertR1],
  30503. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30504. [1, twoDimVert0], [1, twoDimVert0],
  30505. [1, twoDimVert0], [1, twoDimVert0],
  30506. [1, twoDimVert0], [1, twoDimVert0],
  30507. [1, twoDimVert0], [1, twoDimVert0],
  30508. [1, twoDimVert0], [1, twoDimVert0],
  30509. [1, twoDimVert0], [1, twoDimVert0],
  30510. [1, twoDimVert0], [1, twoDimVert0],
  30511. [1, twoDimVert0], [1, twoDimVert0],
  30512. [1, twoDimVert0], [1, twoDimVert0],
  30513. [1, twoDimVert0], [1, twoDimVert0],
  30514. [1, twoDimVert0], [1, twoDimVert0],
  30515. [1, twoDimVert0], [1, twoDimVert0],
  30516. [1, twoDimVert0], [1, twoDimVert0],
  30517. [1, twoDimVert0], [1, twoDimVert0],
  30518. [1, twoDimVert0], [1, twoDimVert0],
  30519. [1, twoDimVert0], [1, twoDimVert0],
  30520. [1, twoDimVert0], [1, twoDimVert0],
  30521. [1, twoDimVert0], [1, twoDimVert0],
  30522. [1, twoDimVert0], [1, twoDimVert0],
  30523. [1, twoDimVert0], [1, twoDimVert0],
  30524. [1, twoDimVert0], [1, twoDimVert0],
  30525. [1, twoDimVert0], [1, twoDimVert0],
  30526. [1, twoDimVert0], [1, twoDimVert0],
  30527. [1, twoDimVert0], [1, twoDimVert0],
  30528. [1, twoDimVert0], [1, twoDimVert0],
  30529. [1, twoDimVert0], [1, twoDimVert0],
  30530. [1, twoDimVert0], [1, twoDimVert0],
  30531. [1, twoDimVert0], [1, twoDimVert0],
  30532. [1, twoDimVert0], [1, twoDimVert0],
  30533. [1, twoDimVert0], [1, twoDimVert0],
  30534. [1, twoDimVert0], [1, twoDimVert0]
  30535. ];
  30536. var whiteTable1 = [
  30537. [-1, -1], // 00000
  30538. [12, ccittEOL], // 00001
  30539. [-1, -1], [-1, -1], // 0001x
  30540. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30541. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30542. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30543. [11, 1792], [11, 1792], // 1000x
  30544. [12, 1984], // 10010
  30545. [12, 2048], // 10011
  30546. [12, 2112], // 10100
  30547. [12, 2176], // 10101
  30548. [12, 2240], // 10110
  30549. [12, 2304], // 10111
  30550. [11, 1856], [11, 1856], // 1100x
  30551. [11, 1920], [11, 1920], // 1101x
  30552. [12, 2368], // 11100
  30553. [12, 2432], // 11101
  30554. [12, 2496], // 11110
  30555. [12, 2560] // 11111
  30556. ];
  30557. var whiteTable2 = [
  30558. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30559. [8, 29], [8, 29], // 00000010x
  30560. [8, 30], [8, 30], // 00000011x
  30561. [8, 45], [8, 45], // 00000100x
  30562. [8, 46], [8, 46], // 00000101x
  30563. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30564. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30565. [8, 47], [8, 47], // 00001010x
  30566. [8, 48], [8, 48], // 00001011x
  30567. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30568. [6, 13], [6, 13], [6, 13], [6, 13],
  30569. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30570. [8, 33], [8, 33], // 00010010x
  30571. [8, 34], [8, 34], // 00010011x
  30572. [8, 35], [8, 35], // 00010100x
  30573. [8, 36], [8, 36], // 00010101x
  30574. [8, 37], [8, 37], // 00010110x
  30575. [8, 38], [8, 38], // 00010111x
  30576. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30577. [8, 31], [8, 31], // 00011010x
  30578. [8, 32], [8, 32], // 00011011x
  30579. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30580. [6, 1], [6, 1], [6, 1], [6, 1],
  30581. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30582. [6, 12], [6, 12], [6, 12], [6, 12],
  30583. [8, 53], [8, 53], // 00100100x
  30584. [8, 54], [8, 54], // 00100101x
  30585. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30586. [8, 39], [8, 39], // 00101000x
  30587. [8, 40], [8, 40], // 00101001x
  30588. [8, 41], [8, 41], // 00101010x
  30589. [8, 42], [8, 42], // 00101011x
  30590. [8, 43], [8, 43], // 00101100x
  30591. [8, 44], [8, 44], // 00101101x
  30592. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30593. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30594. [8, 61], [8, 61], // 00110010x
  30595. [8, 62], [8, 62], // 00110011x
  30596. [8, 63], [8, 63], // 00110100x
  30597. [8, 0], [8, 0], // 00110101x
  30598. [8, 320], [8, 320], // 00110110x
  30599. [8, 384], [8, 384], // 00110111x
  30600. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30601. [5, 10], [5, 10], [5, 10], [5, 10],
  30602. [5, 10], [5, 10], [5, 10], [5, 10],
  30603. [5, 10], [5, 10], [5, 10], [5, 10],
  30604. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30605. [5, 11], [5, 11], [5, 11], [5, 11],
  30606. [5, 11], [5, 11], [5, 11], [5, 11],
  30607. [5, 11], [5, 11], [5, 11], [5, 11],
  30608. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30609. [8, 59], [8, 59], // 01001010x
  30610. [8, 60], [8, 60], // 01001011x
  30611. [9, 1472], // 010011000
  30612. [9, 1536], // 010011001
  30613. [9, 1600], // 010011010
  30614. [9, 1728], // 010011011
  30615. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30616. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30617. [8, 49], [8, 49], // 01010010x
  30618. [8, 50], [8, 50], // 01010011x
  30619. [8, 51], [8, 51], // 01010100x
  30620. [8, 52], [8, 52], // 01010101x
  30621. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30622. [8, 55], [8, 55], // 01011000x
  30623. [8, 56], [8, 56], // 01011001x
  30624. [8, 57], [8, 57], // 01011010x
  30625. [8, 58], [8, 58], // 01011011x
  30626. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30627. [6, 192], [6, 192], [6, 192], [6, 192],
  30628. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30629. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30630. [8, 448], [8, 448], // 01100100x
  30631. [8, 512], [8, 512], // 01100101x
  30632. [9, 704], // 011001100
  30633. [9, 768], // 011001101
  30634. [8, 640], [8, 640], // 01100111x
  30635. [8, 576], [8, 576], // 01101000x
  30636. [9, 832], // 011010010
  30637. [9, 896], // 011010011
  30638. [9, 960], // 011010100
  30639. [9, 1024], // 011010101
  30640. [9, 1088], // 011010110
  30641. [9, 1152], // 011010111
  30642. [9, 1216], // 011011000
  30643. [9, 1280], // 011011001
  30644. [9, 1344], // 011011010
  30645. [9, 1408], // 011011011
  30646. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30647. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30648. [4, 2], [4, 2], [4, 2], [4, 2],
  30649. [4, 2], [4, 2], [4, 2], [4, 2],
  30650. [4, 2], [4, 2], [4, 2], [4, 2],
  30651. [4, 2], [4, 2], [4, 2], [4, 2],
  30652. [4, 2], [4, 2], [4, 2], [4, 2],
  30653. [4, 2], [4, 2], [4, 2], [4, 2],
  30654. [4, 2], [4, 2], [4, 2], [4, 2],
  30655. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30656. [4, 3], [4, 3], [4, 3], [4, 3],
  30657. [4, 3], [4, 3], [4, 3], [4, 3],
  30658. [4, 3], [4, 3], [4, 3], [4, 3],
  30659. [4, 3], [4, 3], [4, 3], [4, 3],
  30660. [4, 3], [4, 3], [4, 3], [4, 3],
  30661. [4, 3], [4, 3], [4, 3], [4, 3],
  30662. [4, 3], [4, 3], [4, 3], [4, 3],
  30663. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30664. [5, 128], [5, 128], [5, 128], [5, 128],
  30665. [5, 128], [5, 128], [5, 128], [5, 128],
  30666. [5, 128], [5, 128], [5, 128], [5, 128],
  30667. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30668. [5, 8], [5, 8], [5, 8], [5, 8],
  30669. [5, 8], [5, 8], [5, 8], [5, 8],
  30670. [5, 8], [5, 8], [5, 8], [5, 8],
  30671. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30672. [5, 9], [5, 9], [5, 9], [5, 9],
  30673. [5, 9], [5, 9], [5, 9], [5, 9],
  30674. [5, 9], [5, 9], [5, 9], [5, 9],
  30675. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30676. [6, 16], [6, 16], [6, 16], [6, 16],
  30677. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30678. [6, 17], [6, 17], [6, 17], [6, 17],
  30679. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30680. [4, 4], [4, 4], [4, 4], [4, 4],
  30681. [4, 4], [4, 4], [4, 4], [4, 4],
  30682. [4, 4], [4, 4], [4, 4], [4, 4],
  30683. [4, 4], [4, 4], [4, 4], [4, 4],
  30684. [4, 4], [4, 4], [4, 4], [4, 4],
  30685. [4, 4], [4, 4], [4, 4], [4, 4],
  30686. [4, 4], [4, 4], [4, 4], [4, 4],
  30687. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30688. [4, 5], [4, 5], [4, 5], [4, 5],
  30689. [4, 5], [4, 5], [4, 5], [4, 5],
  30690. [4, 5], [4, 5], [4, 5], [4, 5],
  30691. [4, 5], [4, 5], [4, 5], [4, 5],
  30692. [4, 5], [4, 5], [4, 5], [4, 5],
  30693. [4, 5], [4, 5], [4, 5], [4, 5],
  30694. [4, 5], [4, 5], [4, 5], [4, 5],
  30695. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30696. [6, 14], [6, 14], [6, 14], [6, 14],
  30697. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30698. [6, 15], [6, 15], [6, 15], [6, 15],
  30699. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30700. [5, 64], [5, 64], [5, 64], [5, 64],
  30701. [5, 64], [5, 64], [5, 64], [5, 64],
  30702. [5, 64], [5, 64], [5, 64], [5, 64],
  30703. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30704. [4, 6], [4, 6], [4, 6], [4, 6],
  30705. [4, 6], [4, 6], [4, 6], [4, 6],
  30706. [4, 6], [4, 6], [4, 6], [4, 6],
  30707. [4, 6], [4, 6], [4, 6], [4, 6],
  30708. [4, 6], [4, 6], [4, 6], [4, 6],
  30709. [4, 6], [4, 6], [4, 6], [4, 6],
  30710. [4, 6], [4, 6], [4, 6], [4, 6],
  30711. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30712. [4, 7], [4, 7], [4, 7], [4, 7],
  30713. [4, 7], [4, 7], [4, 7], [4, 7],
  30714. [4, 7], [4, 7], [4, 7], [4, 7],
  30715. [4, 7], [4, 7], [4, 7], [4, 7],
  30716. [4, 7], [4, 7], [4, 7], [4, 7],
  30717. [4, 7], [4, 7], [4, 7], [4, 7],
  30718. [4, 7], [4, 7], [4, 7], [4, 7]
  30719. ];
  30720. var blackTable1 = [
  30721. [-1, -1], [-1, -1], // 000000000000x
  30722. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30723. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30724. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30725. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30726. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30727. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30728. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30729. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30730. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30731. [12, 1984], [12, 1984], // 000000010010x
  30732. [12, 2048], [12, 2048], // 000000010011x
  30733. [12, 2112], [12, 2112], // 000000010100x
  30734. [12, 2176], [12, 2176], // 000000010101x
  30735. [12, 2240], [12, 2240], // 000000010110x
  30736. [12, 2304], [12, 2304], // 000000010111x
  30737. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30738. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30739. [12, 2368], [12, 2368], // 000000011100x
  30740. [12, 2432], [12, 2432], // 000000011101x
  30741. [12, 2496], [12, 2496], // 000000011110x
  30742. [12, 2560], [12, 2560], // 000000011111x
  30743. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30744. [10, 18], [10, 18], [10, 18], [10, 18],
  30745. [12, 52], [12, 52], // 000000100100x
  30746. [13, 640], // 0000001001010
  30747. [13, 704], // 0000001001011
  30748. [13, 768], // 0000001001100
  30749. [13, 832], // 0000001001101
  30750. [12, 55], [12, 55], // 000000100111x
  30751. [12, 56], [12, 56], // 000000101000x
  30752. [13, 1280], // 0000001010010
  30753. [13, 1344], // 0000001010011
  30754. [13, 1408], // 0000001010100
  30755. [13, 1472], // 0000001010101
  30756. [12, 59], [12, 59], // 000000101011x
  30757. [12, 60], [12, 60], // 000000101100x
  30758. [13, 1536], // 0000001011010
  30759. [13, 1600], // 0000001011011
  30760. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30761. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30762. [13, 1664], // 0000001100100
  30763. [13, 1728], // 0000001100101
  30764. [12, 320], [12, 320], // 000000110011x
  30765. [12, 384], [12, 384], // 000000110100x
  30766. [12, 448], [12, 448], // 000000110101x
  30767. [13, 512], // 0000001101100
  30768. [13, 576], // 0000001101101
  30769. [12, 53], [12, 53], // 000000110111x
  30770. [12, 54], [12, 54], // 000000111000x
  30771. [13, 896], // 0000001110010
  30772. [13, 960], // 0000001110011
  30773. [13, 1024], // 0000001110100
  30774. [13, 1088], // 0000001110101
  30775. [13, 1152], // 0000001110110
  30776. [13, 1216], // 0000001110111
  30777. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30778. [10, 64], [10, 64], [10, 64], [10, 64]
  30779. ];
  30780. var blackTable2 = [
  30781. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30782. [8, 13], [8, 13], [8, 13], [8, 13],
  30783. [8, 13], [8, 13], [8, 13], [8, 13],
  30784. [8, 13], [8, 13], [8, 13], [8, 13],
  30785. [11, 23], [11, 23], // 00000101000x
  30786. [12, 50], // 000001010010
  30787. [12, 51], // 000001010011
  30788. [12, 44], // 000001010100
  30789. [12, 45], // 000001010101
  30790. [12, 46], // 000001010110
  30791. [12, 47], // 000001010111
  30792. [12, 57], // 000001011000
  30793. [12, 58], // 000001011001
  30794. [12, 61], // 000001011010
  30795. [12, 256], // 000001011011
  30796. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30797. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30798. [12, 48], // 000001100100
  30799. [12, 49], // 000001100101
  30800. [12, 62], // 000001100110
  30801. [12, 63], // 000001100111
  30802. [12, 30], // 000001101000
  30803. [12, 31], // 000001101001
  30804. [12, 32], // 000001101010
  30805. [12, 33], // 000001101011
  30806. [12, 40], // 000001101100
  30807. [12, 41], // 000001101101
  30808. [11, 22], [11, 22], // 00000110111x
  30809. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30810. [8, 14], [8, 14], [8, 14], [8, 14],
  30811. [8, 14], [8, 14], [8, 14], [8, 14],
  30812. [8, 14], [8, 14], [8, 14], [8, 14],
  30813. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30814. [7, 10], [7, 10], [7, 10], [7, 10],
  30815. [7, 10], [7, 10], [7, 10], [7, 10],
  30816. [7, 10], [7, 10], [7, 10], [7, 10],
  30817. [7, 10], [7, 10], [7, 10], [7, 10],
  30818. [7, 10], [7, 10], [7, 10], [7, 10],
  30819. [7, 10], [7, 10], [7, 10], [7, 10],
  30820. [7, 10], [7, 10], [7, 10], [7, 10],
  30821. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30822. [7, 11], [7, 11], [7, 11], [7, 11],
  30823. [7, 11], [7, 11], [7, 11], [7, 11],
  30824. [7, 11], [7, 11], [7, 11], [7, 11],
  30825. [7, 11], [7, 11], [7, 11], [7, 11],
  30826. [7, 11], [7, 11], [7, 11], [7, 11],
  30827. [7, 11], [7, 11], [7, 11], [7, 11],
  30828. [7, 11], [7, 11], [7, 11], [7, 11],
  30829. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30830. [9, 15], [9, 15], [9, 15], [9, 15],
  30831. [12, 128], // 000011001000
  30832. [12, 192], // 000011001001
  30833. [12, 26], // 000011001010
  30834. [12, 27], // 000011001011
  30835. [12, 28], // 000011001100
  30836. [12, 29], // 000011001101
  30837. [11, 19], [11, 19], // 00001100111x
  30838. [11, 20], [11, 20], // 00001101000x
  30839. [12, 34], // 000011010010
  30840. [12, 35], // 000011010011
  30841. [12, 36], // 000011010100
  30842. [12, 37], // 000011010101
  30843. [12, 38], // 000011010110
  30844. [12, 39], // 000011010111
  30845. [11, 21], [11, 21], // 00001101100x
  30846. [12, 42], // 000011011010
  30847. [12, 43], // 000011011011
  30848. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30849. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30850. [7, 12], [7, 12], [7, 12], [7, 12],
  30851. [7, 12], [7, 12], [7, 12], [7, 12],
  30852. [7, 12], [7, 12], [7, 12], [7, 12],
  30853. [7, 12], [7, 12], [7, 12], [7, 12],
  30854. [7, 12], [7, 12], [7, 12], [7, 12],
  30855. [7, 12], [7, 12], [7, 12], [7, 12],
  30856. [7, 12], [7, 12], [7, 12], [7, 12]
  30857. ];
  30858. var blackTable3 = [
  30859. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30860. [6, 9], // 000100
  30861. [6, 8], // 000101
  30862. [5, 7], [5, 7], // 00011x
  30863. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30864. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30865. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30866. [3, 1], [3, 1], [3, 1], [3, 1],
  30867. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30868. [3, 4], [3, 4], [3, 4], [3, 4],
  30869. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30870. [2, 3], [2, 3], [2, 3], [2, 3],
  30871. [2, 3], [2, 3], [2, 3], [2, 3],
  30872. [2, 3], [2, 3], [2, 3], [2, 3],
  30873. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  30874. [2, 2], [2, 2], [2, 2], [2, 2],
  30875. [2, 2], [2, 2], [2, 2], [2, 2],
  30876. [2, 2], [2, 2], [2, 2], [2, 2]
  30877. ];
  30878. function CCITTFaxStream(str, maybeLength, params) {
  30879. this.str = str;
  30880. this.dict = str.dict;
  30881. params = params || Dict.empty;
  30882. this.encoding = params.get('K') || 0;
  30883. this.eoline = params.get('EndOfLine') || false;
  30884. this.byteAlign = params.get('EncodedByteAlign') || false;
  30885. this.columns = params.get('Columns') || 1728;
  30886. this.rows = params.get('Rows') || 0;
  30887. var eoblock = params.get('EndOfBlock');
  30888. if (eoblock === null || eoblock === undefined) {
  30889. eoblock = true;
  30890. }
  30891. this.eoblock = eoblock;
  30892. this.black = params.get('BlackIs1') || false;
  30893. this.codingLine = new Uint32Array(this.columns + 1);
  30894. this.refLine = new Uint32Array(this.columns + 2);
  30895. this.codingLine[0] = this.columns;
  30896. this.codingPos = 0;
  30897. this.row = 0;
  30898. this.nextLine2D = this.encoding < 0;
  30899. this.inputBits = 0;
  30900. this.inputBuf = 0;
  30901. this.outputBits = 0;
  30902. var code1;
  30903. while ((code1 = this.lookBits(12)) === 0) {
  30904. this.eatBits(1);
  30905. }
  30906. if (code1 === 1) {
  30907. this.eatBits(12);
  30908. }
  30909. if (this.encoding > 0) {
  30910. this.nextLine2D = !this.lookBits(1);
  30911. this.eatBits(1);
  30912. }
  30913. DecodeStream.call(this, maybeLength);
  30914. }
  30915. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30916. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30917. while (!this.eof) {
  30918. var c = this.lookChar();
  30919. this.ensureBuffer(this.bufferLength + 1);
  30920. this.buffer[this.bufferLength++] = c;
  30921. }
  30922. };
  30923. CCITTFaxStream.prototype.addPixels =
  30924. function ccittFaxStreamAddPixels(a1, blackPixels) {
  30925. var codingLine = this.codingLine;
  30926. var codingPos = this.codingPos;
  30927. if (a1 > codingLine[codingPos]) {
  30928. if (a1 > this.columns) {
  30929. info('row is wrong length');
  30930. this.err = true;
  30931. a1 = this.columns;
  30932. }
  30933. if ((codingPos & 1) ^ blackPixels) {
  30934. ++codingPos;
  30935. }
  30936. codingLine[codingPos] = a1;
  30937. }
  30938. this.codingPos = codingPos;
  30939. };
  30940. CCITTFaxStream.prototype.addPixelsNeg =
  30941. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30942. var codingLine = this.codingLine;
  30943. var codingPos = this.codingPos;
  30944. if (a1 > codingLine[codingPos]) {
  30945. if (a1 > this.columns) {
  30946. info('row is wrong length');
  30947. this.err = true;
  30948. a1 = this.columns;
  30949. }
  30950. if ((codingPos & 1) ^ blackPixels) {
  30951. ++codingPos;
  30952. }
  30953. codingLine[codingPos] = a1;
  30954. } else if (a1 < codingLine[codingPos]) {
  30955. if (a1 < 0) {
  30956. info('invalid code');
  30957. this.err = true;
  30958. a1 = 0;
  30959. }
  30960. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30961. --codingPos;
  30962. }
  30963. codingLine[codingPos] = a1;
  30964. }
  30965. this.codingPos = codingPos;
  30966. };
  30967. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30968. var refLine = this.refLine;
  30969. var codingLine = this.codingLine;
  30970. var columns = this.columns;
  30971. var refPos, blackPixels, bits, i;
  30972. if (this.outputBits === 0) {
  30973. if (this.eof) {
  30974. return null;
  30975. }
  30976. this.err = false;
  30977. var code1, code2, code3;
  30978. if (this.nextLine2D) {
  30979. for (i = 0; codingLine[i] < columns; ++i) {
  30980. refLine[i] = codingLine[i];
  30981. }
  30982. refLine[i++] = columns;
  30983. refLine[i] = columns;
  30984. codingLine[0] = 0;
  30985. this.codingPos = 0;
  30986. refPos = 0;
  30987. blackPixels = 0;
  30988. while (codingLine[this.codingPos] < columns) {
  30989. code1 = this.getTwoDimCode();
  30990. switch (code1) {
  30991. case twoDimPass:
  30992. this.addPixels(refLine[refPos + 1], blackPixels);
  30993. if (refLine[refPos + 1] < columns) {
  30994. refPos += 2;
  30995. }
  30996. break;
  30997. case twoDimHoriz:
  30998. code1 = code2 = 0;
  30999. if (blackPixels) {
  31000. do {
  31001. code1 += (code3 = this.getBlackCode());
  31002. } while (code3 >= 64);
  31003. do {
  31004. code2 += (code3 = this.getWhiteCode());
  31005. } while (code3 >= 64);
  31006. } else {
  31007. do {
  31008. code1 += (code3 = this.getWhiteCode());
  31009. } while (code3 >= 64);
  31010. do {
  31011. code2 += (code3 = this.getBlackCode());
  31012. } while (code3 >= 64);
  31013. }
  31014. this.addPixels(codingLine[this.codingPos] +
  31015. code1, blackPixels);
  31016. if (codingLine[this.codingPos] < columns) {
  31017. this.addPixels(codingLine[this.codingPos] + code2,
  31018. blackPixels ^ 1);
  31019. }
  31020. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31021. refLine[refPos] < columns) {
  31022. refPos += 2;
  31023. }
  31024. break;
  31025. case twoDimVertR3:
  31026. this.addPixels(refLine[refPos] + 3, blackPixels);
  31027. blackPixels ^= 1;
  31028. if (codingLine[this.codingPos] < columns) {
  31029. ++refPos;
  31030. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31031. refLine[refPos] < columns) {
  31032. refPos += 2;
  31033. }
  31034. }
  31035. break;
  31036. case twoDimVertR2:
  31037. this.addPixels(refLine[refPos] + 2, blackPixels);
  31038. blackPixels ^= 1;
  31039. if (codingLine[this.codingPos] < columns) {
  31040. ++refPos;
  31041. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31042. refLine[refPos] < columns) {
  31043. refPos += 2;
  31044. }
  31045. }
  31046. break;
  31047. case twoDimVertR1:
  31048. this.addPixels(refLine[refPos] + 1, blackPixels);
  31049. blackPixels ^= 1;
  31050. if (codingLine[this.codingPos] < columns) {
  31051. ++refPos;
  31052. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31053. refLine[refPos] < columns) {
  31054. refPos += 2;
  31055. }
  31056. }
  31057. break;
  31058. case twoDimVert0:
  31059. this.addPixels(refLine[refPos], blackPixels);
  31060. blackPixels ^= 1;
  31061. if (codingLine[this.codingPos] < columns) {
  31062. ++refPos;
  31063. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31064. refLine[refPos] < columns) {
  31065. refPos += 2;
  31066. }
  31067. }
  31068. break;
  31069. case twoDimVertL3:
  31070. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31071. blackPixels ^= 1;
  31072. if (codingLine[this.codingPos] < columns) {
  31073. if (refPos > 0) {
  31074. --refPos;
  31075. } else {
  31076. ++refPos;
  31077. }
  31078. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31079. refLine[refPos] < columns) {
  31080. refPos += 2;
  31081. }
  31082. }
  31083. break;
  31084. case twoDimVertL2:
  31085. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31086. blackPixels ^= 1;
  31087. if (codingLine[this.codingPos] < columns) {
  31088. if (refPos > 0) {
  31089. --refPos;
  31090. } else {
  31091. ++refPos;
  31092. }
  31093. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31094. refLine[refPos] < columns) {
  31095. refPos += 2;
  31096. }
  31097. }
  31098. break;
  31099. case twoDimVertL1:
  31100. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31101. blackPixels ^= 1;
  31102. if (codingLine[this.codingPos] < columns) {
  31103. if (refPos > 0) {
  31104. --refPos;
  31105. } else {
  31106. ++refPos;
  31107. }
  31108. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31109. refLine[refPos] < columns) {
  31110. refPos += 2;
  31111. }
  31112. }
  31113. break;
  31114. case EOF:
  31115. this.addPixels(columns, 0);
  31116. this.eof = true;
  31117. break;
  31118. default:
  31119. info('bad 2d code');
  31120. this.addPixels(columns, 0);
  31121. this.err = true;
  31122. }
  31123. }
  31124. } else {
  31125. codingLine[0] = 0;
  31126. this.codingPos = 0;
  31127. blackPixels = 0;
  31128. while (codingLine[this.codingPos] < columns) {
  31129. code1 = 0;
  31130. if (blackPixels) {
  31131. do {
  31132. code1 += (code3 = this.getBlackCode());
  31133. } while (code3 >= 64);
  31134. } else {
  31135. do {
  31136. code1 += (code3 = this.getWhiteCode());
  31137. } while (code3 >= 64);
  31138. }
  31139. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31140. blackPixels ^= 1;
  31141. }
  31142. }
  31143. var gotEOL = false;
  31144. if (!this.eoblock && this.row === this.rows - 1) {
  31145. this.eof = true;
  31146. } else {
  31147. code1 = this.lookBits(12);
  31148. if (this.eoline) {
  31149. while (code1 !== EOF && code1 !== 1) {
  31150. this.eatBits(1);
  31151. code1 = this.lookBits(12);
  31152. }
  31153. } else {
  31154. while (code1 === 0) {
  31155. this.eatBits(1);
  31156. code1 = this.lookBits(12);
  31157. }
  31158. }
  31159. if (code1 === 1) {
  31160. this.eatBits(12);
  31161. gotEOL = true;
  31162. } else if (code1 === EOF) {
  31163. this.eof = true;
  31164. }
  31165. }
  31166. if (this.byteAlign && !gotEOL) {
  31167. this.inputBits &= ~7;
  31168. }
  31169. if (!this.eof && this.encoding > 0) {
  31170. this.nextLine2D = !this.lookBits(1);
  31171. this.eatBits(1);
  31172. }
  31173. if (this.eoblock && gotEOL && this.byteAlign) {
  31174. code1 = this.lookBits(12);
  31175. if (code1 === 1) {
  31176. this.eatBits(12);
  31177. if (this.encoding > 0) {
  31178. this.lookBits(1);
  31179. this.eatBits(1);
  31180. }
  31181. if (this.encoding >= 0) {
  31182. for (i = 0; i < 4; ++i) {
  31183. code1 = this.lookBits(12);
  31184. if (code1 !== 1) {
  31185. info('bad rtc code: ' + code1);
  31186. }
  31187. this.eatBits(12);
  31188. if (this.encoding > 0) {
  31189. this.lookBits(1);
  31190. this.eatBits(1);
  31191. }
  31192. }
  31193. }
  31194. this.eof = true;
  31195. }
  31196. } else if (this.err && this.eoline) {
  31197. while (true) {
  31198. code1 = this.lookBits(13);
  31199. if (code1 === EOF) {
  31200. this.eof = true;
  31201. return null;
  31202. }
  31203. if ((code1 >> 1) === 1) {
  31204. break;
  31205. }
  31206. this.eatBits(1);
  31207. }
  31208. this.eatBits(12);
  31209. if (this.encoding > 0) {
  31210. this.eatBits(1);
  31211. this.nextLine2D = !(code1 & 1);
  31212. }
  31213. }
  31214. if (codingLine[0] > 0) {
  31215. this.outputBits = codingLine[this.codingPos = 0];
  31216. } else {
  31217. this.outputBits = codingLine[this.codingPos = 1];
  31218. }
  31219. this.row++;
  31220. }
  31221. var c;
  31222. if (this.outputBits >= 8) {
  31223. c = (this.codingPos & 1) ? 0 : 0xFF;
  31224. this.outputBits -= 8;
  31225. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31226. this.codingPos++;
  31227. this.outputBits = (codingLine[this.codingPos] -
  31228. codingLine[this.codingPos - 1]);
  31229. }
  31230. } else {
  31231. bits = 8;
  31232. c = 0;
  31233. do {
  31234. if (this.outputBits > bits) {
  31235. c <<= bits;
  31236. if (!(this.codingPos & 1)) {
  31237. c |= 0xFF >> (8 - bits);
  31238. }
  31239. this.outputBits -= bits;
  31240. bits = 0;
  31241. } else {
  31242. c <<= this.outputBits;
  31243. if (!(this.codingPos & 1)) {
  31244. c |= 0xFF >> (8 - this.outputBits);
  31245. }
  31246. bits -= this.outputBits;
  31247. this.outputBits = 0;
  31248. if (codingLine[this.codingPos] < columns) {
  31249. this.codingPos++;
  31250. this.outputBits = (codingLine[this.codingPos] -
  31251. codingLine[this.codingPos - 1]);
  31252. } else if (bits > 0) {
  31253. c <<= bits;
  31254. bits = 0;
  31255. }
  31256. }
  31257. } while (bits);
  31258. }
  31259. if (this.black) {
  31260. c ^= 0xFF;
  31261. }
  31262. return c;
  31263. };
  31264. // This functions returns the code found from the table.
  31265. // The start and end parameters set the boundaries for searching the table.
  31266. // The limit parameter is optional. Function returns an array with three
  31267. // values. The first array element indicates whether a valid code is being
  31268. // returned. The second array element is the actual code. The third array
  31269. // element indicates whether EOF was reached.
  31270. CCITTFaxStream.prototype.findTableCode =
  31271. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31272. var limitValue = limit || 0;
  31273. for (var i = start; i <= end; ++i) {
  31274. var code = this.lookBits(i);
  31275. if (code === EOF) {
  31276. return [true, 1, false];
  31277. }
  31278. if (i < end) {
  31279. code <<= end - i;
  31280. }
  31281. if (!limitValue || code >= limitValue) {
  31282. var p = table[code - limitValue];
  31283. if (p[0] === i) {
  31284. this.eatBits(i);
  31285. return [true, p[1], true];
  31286. }
  31287. }
  31288. }
  31289. return [false, 0, false];
  31290. };
  31291. CCITTFaxStream.prototype.getTwoDimCode =
  31292. function ccittFaxStreamGetTwoDimCode() {
  31293. var code = 0;
  31294. var p;
  31295. if (this.eoblock) {
  31296. code = this.lookBits(7);
  31297. p = twoDimTable[code];
  31298. if (p && p[0] > 0) {
  31299. this.eatBits(p[0]);
  31300. return p[1];
  31301. }
  31302. } else {
  31303. var result = this.findTableCode(1, 7, twoDimTable);
  31304. if (result[0] && result[2]) {
  31305. return result[1];
  31306. }
  31307. }
  31308. info('Bad two dim code');
  31309. return EOF;
  31310. };
  31311. CCITTFaxStream.prototype.getWhiteCode =
  31312. function ccittFaxStreamGetWhiteCode() {
  31313. var code = 0;
  31314. var p;
  31315. if (this.eoblock) {
  31316. code = this.lookBits(12);
  31317. if (code === EOF) {
  31318. return 1;
  31319. }
  31320. if ((code >> 5) === 0) {
  31321. p = whiteTable1[code];
  31322. } else {
  31323. p = whiteTable2[code >> 3];
  31324. }
  31325. if (p[0] > 0) {
  31326. this.eatBits(p[0]);
  31327. return p[1];
  31328. }
  31329. } else {
  31330. var result = this.findTableCode(1, 9, whiteTable2);
  31331. if (result[0]) {
  31332. return result[1];
  31333. }
  31334. result = this.findTableCode(11, 12, whiteTable1);
  31335. if (result[0]) {
  31336. return result[1];
  31337. }
  31338. }
  31339. info('bad white code');
  31340. this.eatBits(1);
  31341. return 1;
  31342. };
  31343. CCITTFaxStream.prototype.getBlackCode =
  31344. function ccittFaxStreamGetBlackCode() {
  31345. var code, p;
  31346. if (this.eoblock) {
  31347. code = this.lookBits(13);
  31348. if (code === EOF) {
  31349. return 1;
  31350. }
  31351. if ((code >> 7) === 0) {
  31352. p = blackTable1[code];
  31353. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31354. p = blackTable2[(code >> 1) - 64];
  31355. } else {
  31356. p = blackTable3[code >> 7];
  31357. }
  31358. if (p[0] > 0) {
  31359. this.eatBits(p[0]);
  31360. return p[1];
  31361. }
  31362. } else {
  31363. var result = this.findTableCode(2, 6, blackTable3);
  31364. if (result[0]) {
  31365. return result[1];
  31366. }
  31367. result = this.findTableCode(7, 12, blackTable2, 64);
  31368. if (result[0]) {
  31369. return result[1];
  31370. }
  31371. result = this.findTableCode(10, 13, blackTable1);
  31372. if (result[0]) {
  31373. return result[1];
  31374. }
  31375. }
  31376. info('bad black code');
  31377. this.eatBits(1);
  31378. return 1;
  31379. };
  31380. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31381. var c;
  31382. while (this.inputBits < n) {
  31383. if ((c = this.str.getByte()) === -1) {
  31384. if (this.inputBits === 0) {
  31385. return EOF;
  31386. }
  31387. return ((this.inputBuf << (n - this.inputBits)) &
  31388. (0xFFFF >> (16 - n)));
  31389. }
  31390. this.inputBuf = (this.inputBuf << 8) + c;
  31391. this.inputBits += 8;
  31392. }
  31393. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31394. };
  31395. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31396. if ((this.inputBits -= n) < 0) {
  31397. this.inputBits = 0;
  31398. }
  31399. };
  31400. return CCITTFaxStream;
  31401. })();
  31402. var LZWStream = (function LZWStreamClosure() {
  31403. function LZWStream(str, maybeLength, earlyChange) {
  31404. this.str = str;
  31405. this.dict = str.dict;
  31406. this.cachedData = 0;
  31407. this.bitsCached = 0;
  31408. var maxLzwDictionarySize = 4096;
  31409. var lzwState = {
  31410. earlyChange: earlyChange,
  31411. codeLength: 9,
  31412. nextCode: 258,
  31413. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31414. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31415. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31416. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31417. currentSequenceLength: 0
  31418. };
  31419. for (var i = 0; i < 256; ++i) {
  31420. lzwState.dictionaryValues[i] = i;
  31421. lzwState.dictionaryLengths[i] = 1;
  31422. }
  31423. this.lzwState = lzwState;
  31424. DecodeStream.call(this, maybeLength);
  31425. }
  31426. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31427. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31428. var bitsCached = this.bitsCached;
  31429. var cachedData = this.cachedData;
  31430. while (bitsCached < n) {
  31431. var c = this.str.getByte();
  31432. if (c === -1) {
  31433. this.eof = true;
  31434. return null;
  31435. }
  31436. cachedData = (cachedData << 8) | c;
  31437. bitsCached += 8;
  31438. }
  31439. this.bitsCached = (bitsCached -= n);
  31440. this.cachedData = cachedData;
  31441. this.lastCode = null;
  31442. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31443. };
  31444. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31445. var blockSize = 512;
  31446. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31447. var i, j, q;
  31448. var lzwState = this.lzwState;
  31449. if (!lzwState) {
  31450. return; // eof was found
  31451. }
  31452. var earlyChange = lzwState.earlyChange;
  31453. var nextCode = lzwState.nextCode;
  31454. var dictionaryValues = lzwState.dictionaryValues;
  31455. var dictionaryLengths = lzwState.dictionaryLengths;
  31456. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31457. var codeLength = lzwState.codeLength;
  31458. var prevCode = lzwState.prevCode;
  31459. var currentSequence = lzwState.currentSequence;
  31460. var currentSequenceLength = lzwState.currentSequenceLength;
  31461. var decodedLength = 0;
  31462. var currentBufferLength = this.bufferLength;
  31463. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31464. for (i = 0; i < blockSize; i++) {
  31465. var code = this.readBits(codeLength);
  31466. var hasPrev = currentSequenceLength > 0;
  31467. if (code < 256) {
  31468. currentSequence[0] = code;
  31469. currentSequenceLength = 1;
  31470. } else if (code >= 258) {
  31471. if (code < nextCode) {
  31472. currentSequenceLength = dictionaryLengths[code];
  31473. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31474. currentSequence[j] = dictionaryValues[q];
  31475. q = dictionaryPrevCodes[q];
  31476. }
  31477. } else {
  31478. currentSequence[currentSequenceLength++] = currentSequence[0];
  31479. }
  31480. } else if (code === 256) {
  31481. codeLength = 9;
  31482. nextCode = 258;
  31483. currentSequenceLength = 0;
  31484. continue;
  31485. } else {
  31486. this.eof = true;
  31487. delete this.lzwState;
  31488. break;
  31489. }
  31490. if (hasPrev) {
  31491. dictionaryPrevCodes[nextCode] = prevCode;
  31492. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31493. dictionaryValues[nextCode] = currentSequence[0];
  31494. nextCode++;
  31495. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31496. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31497. 0.6931471805599453 + 1, 12) | 0;
  31498. }
  31499. prevCode = code;
  31500. decodedLength += currentSequenceLength;
  31501. if (estimatedDecodedSize < decodedLength) {
  31502. do {
  31503. estimatedDecodedSize += decodedSizeDelta;
  31504. } while (estimatedDecodedSize < decodedLength);
  31505. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31506. }
  31507. for (j = 0; j < currentSequenceLength; j++) {
  31508. buffer[currentBufferLength++] = currentSequence[j];
  31509. }
  31510. }
  31511. lzwState.nextCode = nextCode;
  31512. lzwState.codeLength = codeLength;
  31513. lzwState.prevCode = prevCode;
  31514. lzwState.currentSequenceLength = currentSequenceLength;
  31515. this.bufferLength = currentBufferLength;
  31516. };
  31517. return LZWStream;
  31518. })();
  31519. var NullStream = (function NullStreamClosure() {
  31520. function NullStream() {
  31521. Stream.call(this, new Uint8Array(0));
  31522. }
  31523. NullStream.prototype = Stream.prototype;
  31524. return NullStream;
  31525. })();
  31526. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31527. setup: function wphSetup(handler) {
  31528. var pdfManager;
  31529. function loadDocument(recoveryMode) {
  31530. var loadDocumentCapability = createPromiseCapability();
  31531. var parseSuccess = function parseSuccess() {
  31532. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31533. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31534. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31535. Promise.all([numPagesPromise, fingerprintPromise,
  31536. encryptedPromise]).then(function onDocReady(results) {
  31537. var doc = {
  31538. numPages: results[0],
  31539. fingerprint: results[1],
  31540. encrypted: !!results[2],
  31541. };
  31542. loadDocumentCapability.resolve(doc);
  31543. },
  31544. parseFailure);
  31545. };
  31546. var parseFailure = function parseFailure(e) {
  31547. loadDocumentCapability.reject(e);
  31548. };
  31549. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31550. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31551. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31552. parseSuccess, parseFailure);
  31553. }, parseFailure);
  31554. }, parseFailure);
  31555. return loadDocumentCapability.promise;
  31556. }
  31557. function getPdfManager(data) {
  31558. var pdfManagerCapability = createPromiseCapability();
  31559. var source = data.source;
  31560. var disableRange = data.disableRange;
  31561. if (source.data) {
  31562. try {
  31563. pdfManager = new LocalPdfManager(source.data, source.password);
  31564. pdfManagerCapability.resolve();
  31565. } catch (ex) {
  31566. pdfManagerCapability.reject(ex);
  31567. }
  31568. return pdfManagerCapability.promise;
  31569. } else if (source.chunkedViewerLoading) {
  31570. try {
  31571. pdfManager = new NetworkPdfManager(source, handler);
  31572. pdfManagerCapability.resolve();
  31573. } catch (ex) {
  31574. pdfManagerCapability.reject(ex);
  31575. }
  31576. return pdfManagerCapability.promise;
  31577. }
  31578. var networkManager = new NetworkManager(source.url, {
  31579. httpHeaders: source.httpHeaders,
  31580. withCredentials: source.withCredentials
  31581. });
  31582. var cachedChunks = [];
  31583. var fullRequestXhrId = networkManager.requestFull({
  31584. onHeadersReceived: function onHeadersReceived() {
  31585. if (disableRange) {
  31586. return;
  31587. }
  31588. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31589. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31590. return;
  31591. }
  31592. var contentEncoding =
  31593. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31594. if (contentEncoding !== 'identity') {
  31595. return;
  31596. }
  31597. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31598. length = parseInt(length, 10);
  31599. if (fullRequestXhr.status === 206) {
  31600. // Since Chrome 39, there exists a bug where cached responses are
  31601. // served with status code 206 for non-range requests.
  31602. // Content-Length does not specify the total size of the resource
  31603. // when the status code is 206 (see RFC 2616, section 14.16).
  31604. // In this case, extract the file size from the Content-Range
  31605. // header, which is defined to be "bytes start-end/length" for
  31606. // byte range requests.
  31607. // See https://github.com/mozilla/pdf.js/issues/5512 and
  31608. // https://code.google.com/p/chromium/issues/detail?id=442318
  31609. length = fullRequestXhr.getResponseHeader('Content-Range');
  31610. length = length && /bytes \d+-\d+\/(\d+)/.exec(length);
  31611. length = length && parseInt(length[1], 10);
  31612. }
  31613. if (!isInt(length)) {
  31614. return;
  31615. }
  31616. source.length = length;
  31617. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31618. // The file size is smaller than the size of two chunks, so it does
  31619. // not make any sense to abort the request and retry with a range
  31620. // request.
  31621. return;
  31622. }
  31623. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31624. // We can continue fetching when progressive loading is enabled,
  31625. // and we don't need the autoFetch feature.
  31626. source.disableAutoFetch = true;
  31627. } else {
  31628. // NOTE: by cancelling the full request, and then issuing range
  31629. // requests, there will be an issue for sites where you can only
  31630. // request the pdf once. However, if this is the case, then the
  31631. // server should not be returning that it can support range
  31632. // requests.
  31633. networkManager.abortRequest(fullRequestXhrId);
  31634. }
  31635. try {
  31636. pdfManager = new NetworkPdfManager(source, handler);
  31637. pdfManagerCapability.resolve(pdfManager);
  31638. } catch (ex) {
  31639. pdfManagerCapability.reject(ex);
  31640. }
  31641. },
  31642. onProgressiveData: source.disableStream ? null :
  31643. function onProgressiveData(chunk) {
  31644. if (!pdfManager) {
  31645. cachedChunks.push(chunk);
  31646. return;
  31647. }
  31648. pdfManager.sendProgressiveData(chunk);
  31649. },
  31650. onDone: function onDone(args) {
  31651. if (pdfManager) {
  31652. return; // already processed
  31653. }
  31654. var pdfFile;
  31655. if (args === null) {
  31656. // TODO add some streaming manager, e.g. for unknown length files.
  31657. // The data was returned in the onProgressiveData, combining...
  31658. var pdfFileLength = 0, pos = 0;
  31659. cachedChunks.forEach(function (chunk) {
  31660. pdfFileLength += chunk.byteLength;
  31661. });
  31662. if (source.length && pdfFileLength !== source.length) {
  31663. warn('reported HTTP length is different from actual');
  31664. }
  31665. var pdfFileArray = new Uint8Array(pdfFileLength);
  31666. cachedChunks.forEach(function (chunk) {
  31667. pdfFileArray.set(new Uint8Array(chunk), pos);
  31668. pos += chunk.byteLength;
  31669. });
  31670. pdfFile = pdfFileArray.buffer;
  31671. } else {
  31672. pdfFile = args.chunk;
  31673. }
  31674. // the data is array, instantiating directly from it
  31675. try {
  31676. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31677. pdfManagerCapability.resolve();
  31678. } catch (ex) {
  31679. pdfManagerCapability.reject(ex);
  31680. }
  31681. },
  31682. onError: function onError(status) {
  31683. var exception;
  31684. if (status === 404) {
  31685. exception = new MissingPDFException('Missing PDF "' +
  31686. source.url + '".');
  31687. handler.send('MissingPDF', exception);
  31688. } else {
  31689. exception = new UnexpectedResponseException(
  31690. 'Unexpected server response (' + status +
  31691. ') while retrieving PDF "' + source.url + '".', status);
  31692. handler.send('UnexpectedResponse', exception);
  31693. }
  31694. },
  31695. onProgress: function onProgress(evt) {
  31696. handler.send('DocProgress', {
  31697. loaded: evt.loaded,
  31698. total: evt.lengthComputable ? evt.total : source.length
  31699. });
  31700. }
  31701. });
  31702. return pdfManagerCapability.promise;
  31703. }
  31704. handler.on('test', function wphSetupTest(data) {
  31705. // check if Uint8Array can be sent to worker
  31706. if (!(data instanceof Uint8Array)) {
  31707. handler.send('test', false);
  31708. return;
  31709. }
  31710. // making sure postMessage transfers are working
  31711. var supportTransfers = data[0] === 255;
  31712. handler.postMessageTransfers = supportTransfers;
  31713. // check if the response property is supported by xhr
  31714. var xhr = new XMLHttpRequest();
  31715. var responseExists = 'response' in xhr;
  31716. // check if the property is actually implemented
  31717. try {
  31718. var dummy = xhr.responseType;
  31719. } catch (e) {
  31720. responseExists = false;
  31721. }
  31722. if (!responseExists) {
  31723. handler.send('test', false);
  31724. return;
  31725. }
  31726. handler.send('test', {
  31727. supportTypedArray: true,
  31728. supportTransfers: supportTransfers
  31729. });
  31730. });
  31731. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31732. var onSuccess = function(doc) {
  31733. handler.send('GetDoc', { pdfInfo: doc });
  31734. };
  31735. var onFailure = function(e) {
  31736. if (e instanceof PasswordException) {
  31737. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31738. handler.send('NeedPassword', e);
  31739. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31740. handler.send('IncorrectPassword', e);
  31741. }
  31742. } else if (e instanceof InvalidPDFException) {
  31743. handler.send('InvalidPDF', e);
  31744. } else if (e instanceof MissingPDFException) {
  31745. handler.send('MissingPDF', e);
  31746. } else if (e instanceof UnexpectedResponseException) {
  31747. handler.send('UnexpectedResponse', e);
  31748. } else {
  31749. handler.send('UnknownError',
  31750. new UnknownErrorException(e.message, e.toString()));
  31751. }
  31752. };
  31753. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31754. -1 : data.maxImageSize;
  31755. PDFJS.disableFontFace = data.disableFontFace;
  31756. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31757. PDFJS.verbosity = data.verbosity;
  31758. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31759. null : data.cMapUrl;
  31760. PDFJS.cMapPacked = data.cMapPacked === true;
  31761. getPdfManager(data).then(function () {
  31762. handler.send('PDFManagerReady', null);
  31763. pdfManager.onLoadedStream().then(function(stream) {
  31764. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31765. });
  31766. }).then(function pdfManagerReady() {
  31767. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31768. // Try again with recoveryMode == true
  31769. if (!(ex instanceof XRefParseException)) {
  31770. if (ex instanceof PasswordException) {
  31771. // after password exception prepare to receive a new password
  31772. // to repeat loading
  31773. pdfManager.passwordChanged().then(pdfManagerReady);
  31774. }
  31775. onFailure(ex);
  31776. return;
  31777. }
  31778. pdfManager.requestLoadedStream();
  31779. pdfManager.onLoadedStream().then(function() {
  31780. loadDocument(true).then(onSuccess, onFailure);
  31781. });
  31782. }, onFailure);
  31783. }, onFailure);
  31784. });
  31785. handler.on('GetPage', function wphSetupGetPage(data) {
  31786. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31787. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31788. var refPromise = pdfManager.ensure(page, 'ref');
  31789. var viewPromise = pdfManager.ensure(page, 'view');
  31790. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31791. function(results) {
  31792. return {
  31793. rotate: results[0],
  31794. ref: results[1],
  31795. view: results[2]
  31796. };
  31797. });
  31798. });
  31799. });
  31800. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31801. var ref = new Ref(data.ref.num, data.ref.gen);
  31802. var catalog = pdfManager.pdfDocument.catalog;
  31803. return catalog.getPageIndex(ref);
  31804. });
  31805. handler.on('GetDestinations',
  31806. function wphSetupGetDestinations(data) {
  31807. return pdfManager.ensureCatalog('destinations');
  31808. }
  31809. );
  31810. handler.on('GetDestination',
  31811. function wphSetupGetDestination(data) {
  31812. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  31813. }
  31814. );
  31815. handler.on('GetAttachments',
  31816. function wphSetupGetAttachments(data) {
  31817. return pdfManager.ensureCatalog('attachments');
  31818. }
  31819. );
  31820. handler.on('GetJavaScript',
  31821. function wphSetupGetJavaScript(data) {
  31822. return pdfManager.ensureCatalog('javaScript');
  31823. }
  31824. );
  31825. handler.on('GetOutline',
  31826. function wphSetupGetOutline(data) {
  31827. return pdfManager.ensureCatalog('documentOutline');
  31828. }
  31829. );
  31830. handler.on('GetMetadata',
  31831. function wphSetupGetMetadata(data) {
  31832. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31833. pdfManager.ensureCatalog('metadata')]);
  31834. }
  31835. );
  31836. handler.on('GetData', function wphSetupGetData(data) {
  31837. pdfManager.requestLoadedStream();
  31838. return pdfManager.onLoadedStream().then(function(stream) {
  31839. return stream.bytes;
  31840. });
  31841. });
  31842. handler.on('GetStats',
  31843. function wphSetupGetStats(data) {
  31844. return pdfManager.pdfDocument.xref.stats;
  31845. }
  31846. );
  31847. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31848. pdfManager.updatePassword(data);
  31849. });
  31850. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31851. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31852. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31853. });
  31854. });
  31855. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31856. pdfManager.getPage(data.pageIndex).then(function(page) {
  31857. var pageNum = data.pageIndex + 1;
  31858. var start = Date.now();
  31859. // Pre compile the pdf page and fetch the fonts/images.
  31860. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31861. info('page=' + pageNum + ' - getOperatorList: time=' +
  31862. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31863. }, function(e) {
  31864. var minimumStackMessage =
  31865. 'worker.js: while trying to getPage() and getOperatorList()';
  31866. var wrappedException;
  31867. // Turn the error into an obj that can be serialized
  31868. if (typeof e === 'string') {
  31869. wrappedException = {
  31870. message: e,
  31871. stack: minimumStackMessage
  31872. };
  31873. } else if (typeof e === 'object') {
  31874. wrappedException = {
  31875. message: e.message || e.toString(),
  31876. stack: e.stack || minimumStackMessage
  31877. };
  31878. } else {
  31879. wrappedException = {
  31880. message: 'Unknown exception type: ' + (typeof e),
  31881. stack: minimumStackMessage
  31882. };
  31883. }
  31884. handler.send('PageError', {
  31885. pageNum: pageNum,
  31886. error: wrappedException,
  31887. intent: data.intent
  31888. });
  31889. });
  31890. });
  31891. }, this);
  31892. handler.on('GetTextContent', function wphExtractText(data) {
  31893. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31894. var pageNum = data.pageIndex + 1;
  31895. var start = Date.now();
  31896. return page.extractTextContent().then(function(textContent) {
  31897. info('text indexing: page=' + pageNum + ' - time=' +
  31898. (Date.now() - start) + 'ms');
  31899. return textContent;
  31900. });
  31901. });
  31902. });
  31903. handler.on('Cleanup', function wphCleanup(data) {
  31904. return pdfManager.cleanup();
  31905. });
  31906. handler.on('Terminate', function wphTerminate(data) {
  31907. pdfManager.terminate();
  31908. });
  31909. }
  31910. };
  31911. var consoleTimer = {};
  31912. var workerConsole = {
  31913. log: function log() {
  31914. var args = Array.prototype.slice.call(arguments);
  31915. globalScope.postMessage({
  31916. action: 'console_log',
  31917. data: args
  31918. });
  31919. },
  31920. error: function error() {
  31921. var args = Array.prototype.slice.call(arguments);
  31922. globalScope.postMessage({
  31923. action: 'console_error',
  31924. data: args
  31925. });
  31926. throw 'pdf.js execution error';
  31927. },
  31928. time: function time(name) {
  31929. consoleTimer[name] = Date.now();
  31930. },
  31931. timeEnd: function timeEnd(name) {
  31932. var time = consoleTimer[name];
  31933. if (!time) {
  31934. error('Unknown timer name ' + name);
  31935. }
  31936. this.log('Timer:', name, Date.now() - time);
  31937. }
  31938. };
  31939. // Worker thread?
  31940. if (typeof window === 'undefined') {
  31941. if (!('console' in globalScope)) {
  31942. globalScope.console = workerConsole;
  31943. }
  31944. // Listen for unsupported features so we can pass them on to the main thread.
  31945. PDFJS.UnsupportedManager.listen(function (msg) {
  31946. globalScope.postMessage({
  31947. action: '_unsupported_feature',
  31948. data: msg
  31949. });
  31950. });
  31951. var handler = new MessageHandler('worker_processor', this);
  31952. WorkerMessageHandler.setup(handler);
  31953. }
  31954. /* This class implements the QM Coder decoding as defined in
  31955. * JPEG 2000 Part I Final Committee Draft Version 1.0
  31956. * Annex C.3 Arithmetic decoding procedure
  31957. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  31958. *
  31959. * The arithmetic decoder is used in conjunction with context models to decode
  31960. * JPEG2000 and JBIG2 streams.
  31961. */
  31962. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  31963. // Table C-2
  31964. var QeTable = [
  31965. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  31966. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  31967. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  31968. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  31969. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  31970. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  31971. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  31972. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  31973. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  31974. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  31975. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  31976. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  31977. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  31978. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  31979. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  31980. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  31981. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  31982. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  31983. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  31984. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  31985. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  31986. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  31987. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  31988. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  31989. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  31990. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  31991. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  31992. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  31993. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  31994. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  31995. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  31996. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  31997. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  31998. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  31999. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32000. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32001. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32002. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32003. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32004. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32005. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32006. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32007. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32008. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32009. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32010. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32011. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32012. ];
  32013. // C.3.5 Initialisation of the decoder (INITDEC)
  32014. function ArithmeticDecoder(data, start, end) {
  32015. this.data = data;
  32016. this.bp = start;
  32017. this.dataEnd = end;
  32018. this.chigh = data[start];
  32019. this.clow = 0;
  32020. this.byteIn();
  32021. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32022. this.clow = (this.clow << 7) & 0xFFFF;
  32023. this.ct -= 7;
  32024. this.a = 0x8000;
  32025. }
  32026. ArithmeticDecoder.prototype = {
  32027. // C.3.4 Compressed data input (BYTEIN)
  32028. byteIn: function ArithmeticDecoder_byteIn() {
  32029. var data = this.data;
  32030. var bp = this.bp;
  32031. if (data[bp] === 0xFF) {
  32032. var b1 = data[bp + 1];
  32033. if (b1 > 0x8F) {
  32034. this.clow += 0xFF00;
  32035. this.ct = 8;
  32036. } else {
  32037. bp++;
  32038. this.clow += (data[bp] << 9);
  32039. this.ct = 7;
  32040. this.bp = bp;
  32041. }
  32042. } else {
  32043. bp++;
  32044. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32045. this.ct = 8;
  32046. this.bp = bp;
  32047. }
  32048. if (this.clow > 0xFFFF) {
  32049. this.chigh += (this.clow >> 16);
  32050. this.clow &= 0xFFFF;
  32051. }
  32052. },
  32053. // C.3.2 Decoding a decision (DECODE)
  32054. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32055. // contexts are packed into 1 byte:
  32056. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32057. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32058. var qeTableIcx = QeTable[cx_index];
  32059. var qeIcx = qeTableIcx.qe;
  32060. var d;
  32061. var a = this.a - qeIcx;
  32062. if (this.chigh < qeIcx) {
  32063. // exchangeLps
  32064. if (a < qeIcx) {
  32065. a = qeIcx;
  32066. d = cx_mps;
  32067. cx_index = qeTableIcx.nmps;
  32068. } else {
  32069. a = qeIcx;
  32070. d = 1 ^ cx_mps;
  32071. if (qeTableIcx.switchFlag === 1) {
  32072. cx_mps = d;
  32073. }
  32074. cx_index = qeTableIcx.nlps;
  32075. }
  32076. } else {
  32077. this.chigh -= qeIcx;
  32078. if ((a & 0x8000) !== 0) {
  32079. this.a = a;
  32080. return cx_mps;
  32081. }
  32082. // exchangeMps
  32083. if (a < qeIcx) {
  32084. d = 1 ^ cx_mps;
  32085. if (qeTableIcx.switchFlag === 1) {
  32086. cx_mps = d;
  32087. }
  32088. cx_index = qeTableIcx.nlps;
  32089. } else {
  32090. d = cx_mps;
  32091. cx_index = qeTableIcx.nmps;
  32092. }
  32093. }
  32094. // C.3.3 renormD;
  32095. do {
  32096. if (this.ct === 0) {
  32097. this.byteIn();
  32098. }
  32099. a <<= 1;
  32100. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32101. this.clow = (this.clow << 1) & 0xFFFF;
  32102. this.ct--;
  32103. } while ((a & 0x8000) === 0);
  32104. this.a = a;
  32105. contexts[pos] = cx_index << 1 | cx_mps;
  32106. return d;
  32107. }
  32108. };
  32109. return ArithmeticDecoder;
  32110. })();
  32111. var JpegImage = (function jpegImage() {
  32112. var dctZigZag = new Uint8Array([
  32113. 0,
  32114. 1, 8,
  32115. 16, 9, 2,
  32116. 3, 10, 17, 24,
  32117. 32, 25, 18, 11, 4,
  32118. 5, 12, 19, 26, 33, 40,
  32119. 48, 41, 34, 27, 20, 13, 6,
  32120. 7, 14, 21, 28, 35, 42, 49, 56,
  32121. 57, 50, 43, 36, 29, 22, 15,
  32122. 23, 30, 37, 44, 51, 58,
  32123. 59, 52, 45, 38, 31,
  32124. 39, 46, 53, 60,
  32125. 61, 54, 47,
  32126. 55, 62,
  32127. 63
  32128. ]);
  32129. var dctCos1 = 4017; // cos(pi/16)
  32130. var dctSin1 = 799; // sin(pi/16)
  32131. var dctCos3 = 3406; // cos(3*pi/16)
  32132. var dctSin3 = 2276; // sin(3*pi/16)
  32133. var dctCos6 = 1567; // cos(6*pi/16)
  32134. var dctSin6 = 3784; // sin(6*pi/16)
  32135. var dctSqrt2 = 5793; // sqrt(2)
  32136. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32137. function constructor() {
  32138. }
  32139. function buildHuffmanTable(codeLengths, values) {
  32140. var k = 0, code = [], i, j, length = 16;
  32141. while (length > 0 && !codeLengths[length - 1]) {
  32142. length--;
  32143. }
  32144. code.push({children: [], index: 0});
  32145. var p = code[0], q;
  32146. for (i = 0; i < length; i++) {
  32147. for (j = 0; j < codeLengths[i]; j++) {
  32148. p = code.pop();
  32149. p.children[p.index] = values[k];
  32150. while (p.index > 0) {
  32151. p = code.pop();
  32152. }
  32153. p.index++;
  32154. code.push(p);
  32155. while (code.length <= i) {
  32156. code.push(q = {children: [], index: 0});
  32157. p.children[p.index] = q.children;
  32158. p = q;
  32159. }
  32160. k++;
  32161. }
  32162. if (i + 1 < length) {
  32163. // p here points to last code
  32164. code.push(q = {children: [], index: 0});
  32165. p.children[p.index] = q.children;
  32166. p = q;
  32167. }
  32168. }
  32169. return code[0].children;
  32170. }
  32171. function getBlockBufferOffset(component, row, col) {
  32172. return 64 * ((component.blocksPerLine + 1) * row + col);
  32173. }
  32174. function decodeScan(data, offset, frame, components, resetInterval,
  32175. spectralStart, spectralEnd, successivePrev, successive) {
  32176. var precision = frame.precision;
  32177. var samplesPerLine = frame.samplesPerLine;
  32178. var scanLines = frame.scanLines;
  32179. var mcusPerLine = frame.mcusPerLine;
  32180. var progressive = frame.progressive;
  32181. var maxH = frame.maxH, maxV = frame.maxV;
  32182. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32183. function readBit() {
  32184. if (bitsCount > 0) {
  32185. bitsCount--;
  32186. return (bitsData >> bitsCount) & 1;
  32187. }
  32188. bitsData = data[offset++];
  32189. if (bitsData === 0xFF) {
  32190. var nextByte = data[offset++];
  32191. if (nextByte) {
  32192. throw 'unexpected marker: ' +
  32193. ((bitsData << 8) | nextByte).toString(16);
  32194. }
  32195. // unstuff 0
  32196. }
  32197. bitsCount = 7;
  32198. return bitsData >>> 7;
  32199. }
  32200. function decodeHuffman(tree) {
  32201. var node = tree;
  32202. while (true) {
  32203. node = node[readBit()];
  32204. if (typeof node === 'number') {
  32205. return node;
  32206. }
  32207. if (typeof node !== 'object') {
  32208. throw 'invalid huffman sequence';
  32209. }
  32210. }
  32211. }
  32212. function receive(length) {
  32213. var n = 0;
  32214. while (length > 0) {
  32215. n = (n << 1) | readBit();
  32216. length--;
  32217. }
  32218. return n;
  32219. }
  32220. function receiveAndExtend(length) {
  32221. if (length === 1) {
  32222. return readBit() === 1 ? 1 : -1;
  32223. }
  32224. var n = receive(length);
  32225. if (n >= 1 << (length - 1)) {
  32226. return n;
  32227. }
  32228. return n + (-1 << length) + 1;
  32229. }
  32230. function decodeBaseline(component, offset) {
  32231. var t = decodeHuffman(component.huffmanTableDC);
  32232. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32233. component.blockData[offset] = (component.pred += diff);
  32234. var k = 1;
  32235. while (k < 64) {
  32236. var rs = decodeHuffman(component.huffmanTableAC);
  32237. var s = rs & 15, r = rs >> 4;
  32238. if (s === 0) {
  32239. if (r < 15) {
  32240. break;
  32241. }
  32242. k += 16;
  32243. continue;
  32244. }
  32245. k += r;
  32246. var z = dctZigZag[k];
  32247. component.blockData[offset + z] = receiveAndExtend(s);
  32248. k++;
  32249. }
  32250. }
  32251. function decodeDCFirst(component, offset) {
  32252. var t = decodeHuffman(component.huffmanTableDC);
  32253. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32254. component.blockData[offset] = (component.pred += diff);
  32255. }
  32256. function decodeDCSuccessive(component, offset) {
  32257. component.blockData[offset] |= readBit() << successive;
  32258. }
  32259. var eobrun = 0;
  32260. function decodeACFirst(component, offset) {
  32261. if (eobrun > 0) {
  32262. eobrun--;
  32263. return;
  32264. }
  32265. var k = spectralStart, e = spectralEnd;
  32266. while (k <= e) {
  32267. var rs = decodeHuffman(component.huffmanTableAC);
  32268. var s = rs & 15, r = rs >> 4;
  32269. if (s === 0) {
  32270. if (r < 15) {
  32271. eobrun = receive(r) + (1 << r) - 1;
  32272. break;
  32273. }
  32274. k += 16;
  32275. continue;
  32276. }
  32277. k += r;
  32278. var z = dctZigZag[k];
  32279. component.blockData[offset + z] =
  32280. receiveAndExtend(s) * (1 << successive);
  32281. k++;
  32282. }
  32283. }
  32284. var successiveACState = 0, successiveACNextValue;
  32285. function decodeACSuccessive(component, offset) {
  32286. var k = spectralStart;
  32287. var e = spectralEnd;
  32288. var r = 0;
  32289. var s;
  32290. var rs;
  32291. while (k <= e) {
  32292. var z = dctZigZag[k];
  32293. switch (successiveACState) {
  32294. case 0: // initial state
  32295. rs = decodeHuffman(component.huffmanTableAC);
  32296. s = rs & 15;
  32297. r = rs >> 4;
  32298. if (s === 0) {
  32299. if (r < 15) {
  32300. eobrun = receive(r) + (1 << r);
  32301. successiveACState = 4;
  32302. } else {
  32303. r = 16;
  32304. successiveACState = 1;
  32305. }
  32306. } else {
  32307. if (s !== 1) {
  32308. throw 'invalid ACn encoding';
  32309. }
  32310. successiveACNextValue = receiveAndExtend(s);
  32311. successiveACState = r ? 2 : 3;
  32312. }
  32313. continue;
  32314. case 1: // skipping r zero items
  32315. case 2:
  32316. if (component.blockData[offset + z]) {
  32317. component.blockData[offset + z] += (readBit() << successive);
  32318. } else {
  32319. r--;
  32320. if (r === 0) {
  32321. successiveACState = successiveACState === 2 ? 3 : 0;
  32322. }
  32323. }
  32324. break;
  32325. case 3: // set value for a zero item
  32326. if (component.blockData[offset + z]) {
  32327. component.blockData[offset + z] += (readBit() << successive);
  32328. } else {
  32329. component.blockData[offset + z] =
  32330. successiveACNextValue << successive;
  32331. successiveACState = 0;
  32332. }
  32333. break;
  32334. case 4: // eob
  32335. if (component.blockData[offset + z]) {
  32336. component.blockData[offset + z] += (readBit() << successive);
  32337. }
  32338. break;
  32339. }
  32340. k++;
  32341. }
  32342. if (successiveACState === 4) {
  32343. eobrun--;
  32344. if (eobrun === 0) {
  32345. successiveACState = 0;
  32346. }
  32347. }
  32348. }
  32349. function decodeMcu(component, decode, mcu, row, col) {
  32350. var mcuRow = (mcu / mcusPerLine) | 0;
  32351. var mcuCol = mcu % mcusPerLine;
  32352. var blockRow = mcuRow * component.v + row;
  32353. var blockCol = mcuCol * component.h + col;
  32354. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32355. decode(component, offset);
  32356. }
  32357. function decodeBlock(component, decode, mcu) {
  32358. var blockRow = (mcu / component.blocksPerLine) | 0;
  32359. var blockCol = mcu % component.blocksPerLine;
  32360. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32361. decode(component, offset);
  32362. }
  32363. var componentsLength = components.length;
  32364. var component, i, j, k, n;
  32365. var decodeFn;
  32366. if (progressive) {
  32367. if (spectralStart === 0) {
  32368. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32369. } else {
  32370. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32371. }
  32372. } else {
  32373. decodeFn = decodeBaseline;
  32374. }
  32375. var mcu = 0, marker;
  32376. var mcuExpected;
  32377. if (componentsLength === 1) {
  32378. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32379. } else {
  32380. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32381. }
  32382. if (!resetInterval) {
  32383. resetInterval = mcuExpected;
  32384. }
  32385. var h, v;
  32386. while (mcu < mcuExpected) {
  32387. // reset interval stuff
  32388. for (i = 0; i < componentsLength; i++) {
  32389. components[i].pred = 0;
  32390. }
  32391. eobrun = 0;
  32392. if (componentsLength === 1) {
  32393. component = components[0];
  32394. for (n = 0; n < resetInterval; n++) {
  32395. decodeBlock(component, decodeFn, mcu);
  32396. mcu++;
  32397. }
  32398. } else {
  32399. for (n = 0; n < resetInterval; n++) {
  32400. for (i = 0; i < componentsLength; i++) {
  32401. component = components[i];
  32402. h = component.h;
  32403. v = component.v;
  32404. for (j = 0; j < v; j++) {
  32405. for (k = 0; k < h; k++) {
  32406. decodeMcu(component, decodeFn, mcu, j, k);
  32407. }
  32408. }
  32409. }
  32410. mcu++;
  32411. }
  32412. }
  32413. // find marker
  32414. bitsCount = 0;
  32415. marker = (data[offset] << 8) | data[offset + 1];
  32416. if (marker <= 0xFF00) {
  32417. throw 'marker was not found';
  32418. }
  32419. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32420. offset += 2;
  32421. } else {
  32422. break;
  32423. }
  32424. }
  32425. return offset - startOffset;
  32426. }
  32427. // A port of poppler's IDCT method which in turn is taken from:
  32428. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32429. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32430. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32431. // 988-991.
  32432. function quantizeAndInverse(component, blockBufferOffset, p) {
  32433. var qt = component.quantizationTable, blockData = component.blockData;
  32434. var v0, v1, v2, v3, v4, v5, v6, v7;
  32435. var p0, p1, p2, p3, p4, p5, p6, p7;
  32436. var t;
  32437. // inverse DCT on rows
  32438. for (var row = 0; row < 64; row += 8) {
  32439. // gather block data
  32440. p0 = blockData[blockBufferOffset + row];
  32441. p1 = blockData[blockBufferOffset + row + 1];
  32442. p2 = blockData[blockBufferOffset + row + 2];
  32443. p3 = blockData[blockBufferOffset + row + 3];
  32444. p4 = blockData[blockBufferOffset + row + 4];
  32445. p5 = blockData[blockBufferOffset + row + 5];
  32446. p6 = blockData[blockBufferOffset + row + 6];
  32447. p7 = blockData[blockBufferOffset + row + 7];
  32448. // dequant p0
  32449. p0 *= qt[row];
  32450. // check for all-zero AC coefficients
  32451. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32452. t = (dctSqrt2 * p0 + 512) >> 10;
  32453. p[row] = t;
  32454. p[row + 1] = t;
  32455. p[row + 2] = t;
  32456. p[row + 3] = t;
  32457. p[row + 4] = t;
  32458. p[row + 5] = t;
  32459. p[row + 6] = t;
  32460. p[row + 7] = t;
  32461. continue;
  32462. }
  32463. // dequant p1 ... p7
  32464. p1 *= qt[row + 1];
  32465. p2 *= qt[row + 2];
  32466. p3 *= qt[row + 3];
  32467. p4 *= qt[row + 4];
  32468. p5 *= qt[row + 5];
  32469. p6 *= qt[row + 6];
  32470. p7 *= qt[row + 7];
  32471. // stage 4
  32472. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32473. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32474. v2 = p2;
  32475. v3 = p6;
  32476. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32477. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32478. v5 = p3 << 4;
  32479. v6 = p5 << 4;
  32480. // stage 3
  32481. v0 = (v0 + v1 + 1) >> 1;
  32482. v1 = v0 - v1;
  32483. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32484. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32485. v3 = t;
  32486. v4 = (v4 + v6 + 1) >> 1;
  32487. v6 = v4 - v6;
  32488. v7 = (v7 + v5 + 1) >> 1;
  32489. v5 = v7 - v5;
  32490. // stage 2
  32491. v0 = (v0 + v3 + 1) >> 1;
  32492. v3 = v0 - v3;
  32493. v1 = (v1 + v2 + 1) >> 1;
  32494. v2 = v1 - v2;
  32495. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32496. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32497. v7 = t;
  32498. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32499. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32500. v6 = t;
  32501. // stage 1
  32502. p[row] = v0 + v7;
  32503. p[row + 7] = v0 - v7;
  32504. p[row + 1] = v1 + v6;
  32505. p[row + 6] = v1 - v6;
  32506. p[row + 2] = v2 + v5;
  32507. p[row + 5] = v2 - v5;
  32508. p[row + 3] = v3 + v4;
  32509. p[row + 4] = v3 - v4;
  32510. }
  32511. // inverse DCT on columns
  32512. for (var col = 0; col < 8; ++col) {
  32513. p0 = p[col];
  32514. p1 = p[col + 8];
  32515. p2 = p[col + 16];
  32516. p3 = p[col + 24];
  32517. p4 = p[col + 32];
  32518. p5 = p[col + 40];
  32519. p6 = p[col + 48];
  32520. p7 = p[col + 56];
  32521. // check for all-zero AC coefficients
  32522. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32523. t = (dctSqrt2 * p0 + 8192) >> 14;
  32524. // convert to 8 bit
  32525. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32526. blockData[blockBufferOffset + col] = t;
  32527. blockData[blockBufferOffset + col + 8] = t;
  32528. blockData[blockBufferOffset + col + 16] = t;
  32529. blockData[blockBufferOffset + col + 24] = t;
  32530. blockData[blockBufferOffset + col + 32] = t;
  32531. blockData[blockBufferOffset + col + 40] = t;
  32532. blockData[blockBufferOffset + col + 48] = t;
  32533. blockData[blockBufferOffset + col + 56] = t;
  32534. continue;
  32535. }
  32536. // stage 4
  32537. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32538. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32539. v2 = p2;
  32540. v3 = p6;
  32541. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32542. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32543. v5 = p3;
  32544. v6 = p5;
  32545. // stage 3
  32546. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32547. // converting to UInt8 range later.
  32548. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32549. v1 = v0 - v1;
  32550. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32551. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32552. v3 = t;
  32553. v4 = (v4 + v6 + 1) >> 1;
  32554. v6 = v4 - v6;
  32555. v7 = (v7 + v5 + 1) >> 1;
  32556. v5 = v7 - v5;
  32557. // stage 2
  32558. v0 = (v0 + v3 + 1) >> 1;
  32559. v3 = v0 - v3;
  32560. v1 = (v1 + v2 + 1) >> 1;
  32561. v2 = v1 - v2;
  32562. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32563. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32564. v7 = t;
  32565. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32566. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32567. v6 = t;
  32568. // stage 1
  32569. p0 = v0 + v7;
  32570. p7 = v0 - v7;
  32571. p1 = v1 + v6;
  32572. p6 = v1 - v6;
  32573. p2 = v2 + v5;
  32574. p5 = v2 - v5;
  32575. p3 = v3 + v4;
  32576. p4 = v3 - v4;
  32577. // convert to 8-bit integers
  32578. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32579. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32580. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32581. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32582. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32583. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32584. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32585. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32586. // store block data
  32587. blockData[blockBufferOffset + col] = p0;
  32588. blockData[blockBufferOffset + col + 8] = p1;
  32589. blockData[blockBufferOffset + col + 16] = p2;
  32590. blockData[blockBufferOffset + col + 24] = p3;
  32591. blockData[blockBufferOffset + col + 32] = p4;
  32592. blockData[blockBufferOffset + col + 40] = p5;
  32593. blockData[blockBufferOffset + col + 48] = p6;
  32594. blockData[blockBufferOffset + col + 56] = p7;
  32595. }
  32596. }
  32597. function buildComponentData(frame, component) {
  32598. var blocksPerLine = component.blocksPerLine;
  32599. var blocksPerColumn = component.blocksPerColumn;
  32600. var computationBuffer = new Int16Array(64);
  32601. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32602. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32603. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32604. quantizeAndInverse(component, offset, computationBuffer);
  32605. }
  32606. }
  32607. return component.blockData;
  32608. }
  32609. function clamp0to255(a) {
  32610. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32611. }
  32612. constructor.prototype = {
  32613. parse: function parse(data) {
  32614. function readUint16() {
  32615. var value = (data[offset] << 8) | data[offset + 1];
  32616. offset += 2;
  32617. return value;
  32618. }
  32619. function readDataBlock() {
  32620. var length = readUint16();
  32621. var array = data.subarray(offset, offset + length - 2);
  32622. offset += array.length;
  32623. return array;
  32624. }
  32625. function prepareComponents(frame) {
  32626. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32627. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32628. for (var i = 0; i < frame.components.length; i++) {
  32629. component = frame.components[i];
  32630. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32631. component.h / frame.maxH);
  32632. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32633. component.v / frame.maxV);
  32634. var blocksPerLineForMcu = mcusPerLine * component.h;
  32635. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32636. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32637. (blocksPerLineForMcu + 1);
  32638. component.blockData = new Int16Array(blocksBufferSize);
  32639. component.blocksPerLine = blocksPerLine;
  32640. component.blocksPerColumn = blocksPerColumn;
  32641. }
  32642. frame.mcusPerLine = mcusPerLine;
  32643. frame.mcusPerColumn = mcusPerColumn;
  32644. }
  32645. var offset = 0, length = data.length;
  32646. var jfif = null;
  32647. var adobe = null;
  32648. var pixels = null;
  32649. var frame, resetInterval;
  32650. var quantizationTables = [];
  32651. var huffmanTablesAC = [], huffmanTablesDC = [];
  32652. var fileMarker = readUint16();
  32653. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32654. throw 'SOI not found';
  32655. }
  32656. fileMarker = readUint16();
  32657. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32658. var i, j, l;
  32659. switch(fileMarker) {
  32660. case 0xFFE0: // APP0 (Application Specific)
  32661. case 0xFFE1: // APP1
  32662. case 0xFFE2: // APP2
  32663. case 0xFFE3: // APP3
  32664. case 0xFFE4: // APP4
  32665. case 0xFFE5: // APP5
  32666. case 0xFFE6: // APP6
  32667. case 0xFFE7: // APP7
  32668. case 0xFFE8: // APP8
  32669. case 0xFFE9: // APP9
  32670. case 0xFFEA: // APP10
  32671. case 0xFFEB: // APP11
  32672. case 0xFFEC: // APP12
  32673. case 0xFFED: // APP13
  32674. case 0xFFEE: // APP14
  32675. case 0xFFEF: // APP15
  32676. case 0xFFFE: // COM (Comment)
  32677. var appData = readDataBlock();
  32678. if (fileMarker === 0xFFE0) {
  32679. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32680. appData[2] === 0x49 && appData[3] === 0x46 &&
  32681. appData[4] === 0) { // 'JFIF\x00'
  32682. jfif = {
  32683. version: { major: appData[5], minor: appData[6] },
  32684. densityUnits: appData[7],
  32685. xDensity: (appData[8] << 8) | appData[9],
  32686. yDensity: (appData[10] << 8) | appData[11],
  32687. thumbWidth: appData[12],
  32688. thumbHeight: appData[13],
  32689. thumbData: appData.subarray(14, 14 +
  32690. 3 * appData[12] * appData[13])
  32691. };
  32692. }
  32693. }
  32694. // TODO APP1 - Exif
  32695. if (fileMarker === 0xFFEE) {
  32696. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32697. appData[2] === 0x6F && appData[3] === 0x62 &&
  32698. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32699. adobe = {
  32700. version: appData[6],
  32701. flags0: (appData[7] << 8) | appData[8],
  32702. flags1: (appData[9] << 8) | appData[10],
  32703. transformCode: appData[11]
  32704. };
  32705. }
  32706. }
  32707. break;
  32708. case 0xFFDB: // DQT (Define Quantization Tables)
  32709. var quantizationTablesLength = readUint16();
  32710. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32711. var z;
  32712. while (offset < quantizationTablesEnd) {
  32713. var quantizationTableSpec = data[offset++];
  32714. var tableData = new Uint16Array(64);
  32715. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32716. for (j = 0; j < 64; j++) {
  32717. z = dctZigZag[j];
  32718. tableData[z] = data[offset++];
  32719. }
  32720. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32721. for (j = 0; j < 64; j++) {
  32722. z = dctZigZag[j];
  32723. tableData[z] = readUint16();
  32724. }
  32725. } else {
  32726. throw 'DQT: invalid table spec';
  32727. }
  32728. quantizationTables[quantizationTableSpec & 15] = tableData;
  32729. }
  32730. break;
  32731. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32732. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32733. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32734. if (frame) {
  32735. throw 'Only single frame JPEGs supported';
  32736. }
  32737. readUint16(); // skip data length
  32738. frame = {};
  32739. frame.extended = (fileMarker === 0xFFC1);
  32740. frame.progressive = (fileMarker === 0xFFC2);
  32741. frame.precision = data[offset++];
  32742. frame.scanLines = readUint16();
  32743. frame.samplesPerLine = readUint16();
  32744. frame.components = [];
  32745. frame.componentIds = {};
  32746. var componentsCount = data[offset++], componentId;
  32747. var maxH = 0, maxV = 0;
  32748. for (i = 0; i < componentsCount; i++) {
  32749. componentId = data[offset];
  32750. var h = data[offset + 1] >> 4;
  32751. var v = data[offset + 1] & 15;
  32752. if (maxH < h) {
  32753. maxH = h;
  32754. }
  32755. if (maxV < v) {
  32756. maxV = v;
  32757. }
  32758. var qId = data[offset + 2];
  32759. l = frame.components.push({
  32760. h: h,
  32761. v: v,
  32762. quantizationTable: quantizationTables[qId]
  32763. });
  32764. frame.componentIds[componentId] = l - 1;
  32765. offset += 3;
  32766. }
  32767. frame.maxH = maxH;
  32768. frame.maxV = maxV;
  32769. prepareComponents(frame);
  32770. break;
  32771. case 0xFFC4: // DHT (Define Huffman Tables)
  32772. var huffmanLength = readUint16();
  32773. for (i = 2; i < huffmanLength;) {
  32774. var huffmanTableSpec = data[offset++];
  32775. var codeLengths = new Uint8Array(16);
  32776. var codeLengthSum = 0;
  32777. for (j = 0; j < 16; j++, offset++) {
  32778. codeLengthSum += (codeLengths[j] = data[offset]);
  32779. }
  32780. var huffmanValues = new Uint8Array(codeLengthSum);
  32781. for (j = 0; j < codeLengthSum; j++, offset++) {
  32782. huffmanValues[j] = data[offset];
  32783. }
  32784. i += 17 + codeLengthSum;
  32785. ((huffmanTableSpec >> 4) === 0 ?
  32786. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32787. buildHuffmanTable(codeLengths, huffmanValues);
  32788. }
  32789. break;
  32790. case 0xFFDD: // DRI (Define Restart Interval)
  32791. readUint16(); // skip data length
  32792. resetInterval = readUint16();
  32793. break;
  32794. case 0xFFDA: // SOS (Start of Scan)
  32795. var scanLength = readUint16();
  32796. var selectorsCount = data[offset++];
  32797. var components = [], component;
  32798. for (i = 0; i < selectorsCount; i++) {
  32799. var componentIndex = frame.componentIds[data[offset++]];
  32800. component = frame.components[componentIndex];
  32801. var tableSpec = data[offset++];
  32802. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32803. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32804. components.push(component);
  32805. }
  32806. var spectralStart = data[offset++];
  32807. var spectralEnd = data[offset++];
  32808. var successiveApproximation = data[offset++];
  32809. var processed = decodeScan(data, offset,
  32810. frame, components, resetInterval,
  32811. spectralStart, spectralEnd,
  32812. successiveApproximation >> 4, successiveApproximation & 15);
  32813. offset += processed;
  32814. break;
  32815. default:
  32816. if (data[offset - 3] === 0xFF &&
  32817. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32818. // could be incorrect encoding -- last 0xFF byte of the previous
  32819. // block was eaten by the encoder
  32820. offset -= 3;
  32821. break;
  32822. }
  32823. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32824. }
  32825. fileMarker = readUint16();
  32826. }
  32827. this.width = frame.samplesPerLine;
  32828. this.height = frame.scanLines;
  32829. this.jfif = jfif;
  32830. this.adobe = adobe;
  32831. this.components = [];
  32832. for (i = 0; i < frame.components.length; i++) {
  32833. component = frame.components[i];
  32834. this.components.push({
  32835. output: buildComponentData(frame, component),
  32836. scaleX: component.h / frame.maxH,
  32837. scaleY: component.v / frame.maxV,
  32838. blocksPerLine: component.blocksPerLine,
  32839. blocksPerColumn: component.blocksPerColumn
  32840. });
  32841. }
  32842. this.numComponents = this.components.length;
  32843. },
  32844. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32845. var scaleX = this.width / width, scaleY = this.height / height;
  32846. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32847. var x, y, i, j, k;
  32848. var index;
  32849. var offset = 0;
  32850. var output;
  32851. var numComponents = this.components.length;
  32852. var dataLength = width * height * numComponents;
  32853. var data = new Uint8Array(dataLength);
  32854. var xScaleBlockOffset = new Uint32Array(width);
  32855. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32856. for (i = 0; i < numComponents; i++) {
  32857. component = this.components[i];
  32858. componentScaleX = component.scaleX * scaleX;
  32859. componentScaleY = component.scaleY * scaleY;
  32860. offset = i;
  32861. output = component.output;
  32862. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32863. // precalculate the xScaleBlockOffset
  32864. for (x = 0; x < width; x++) {
  32865. j = 0 | (x * componentScaleX);
  32866. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32867. }
  32868. // linearize the blocks of the component
  32869. for (y = 0; y < height; y++) {
  32870. j = 0 | (y * componentScaleY);
  32871. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  32872. for (x = 0; x < width; x++) {
  32873. data[offset] = output[index + xScaleBlockOffset[x]];
  32874. offset += numComponents;
  32875. }
  32876. }
  32877. }
  32878. // decodeTransform contains pairs of multiplier (-256..256) and additive
  32879. var transform = this.decodeTransform;
  32880. if (transform) {
  32881. for (i = 0; i < dataLength;) {
  32882. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  32883. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  32884. }
  32885. }
  32886. }
  32887. return data;
  32888. },
  32889. _isColorConversionNeeded: function isColorConversionNeeded() {
  32890. if (this.adobe && this.adobe.transformCode) {
  32891. // The adobe transform marker overrides any previous setting
  32892. return true;
  32893. } else if (this.numComponents === 3) {
  32894. return true;
  32895. } else {
  32896. return false;
  32897. }
  32898. },
  32899. _convertYccToRgb: function convertYccToRgb(data) {
  32900. var Y, Cb, Cr;
  32901. for (var i = 0, length = data.length; i < length; i += 3) {
  32902. Y = data[i ];
  32903. Cb = data[i + 1];
  32904. Cr = data[i + 2];
  32905. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  32906. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  32907. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  32908. }
  32909. return data;
  32910. },
  32911. _convertYcckToRgb: function convertYcckToRgb(data) {
  32912. var Y, Cb, Cr, k;
  32913. var offset = 0;
  32914. for (var i = 0, length = data.length; i < length; i += 4) {
  32915. Y = data[i];
  32916. Cb = data[i + 1];
  32917. Cr = data[i + 2];
  32918. k = data[i + 3];
  32919. var r = -122.67195406894 +
  32920. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  32921. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  32922. 0.154362151871126) +
  32923. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  32924. 0.00477271405408747 * k + 1.53380253221734) +
  32925. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  32926. 0.48357088451265) +
  32927. k * (-0.000336197177618394 * k + 0.484791561490776);
  32928. var g = 107.268039397724 +
  32929. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  32930. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  32931. 0.176491792462875) +
  32932. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  32933. 0.000770482631801132 * k - 0.151051492775562) +
  32934. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  32935. 0.25802910206845) +
  32936. k * (-0.000318913117588328 * k - 0.213742400323665);
  32937. var b = -20.810012546947 +
  32938. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  32939. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  32940. 0.814272968359295) +
  32941. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  32942. 0.000560833691242812 * k - 0.195152027534049) +
  32943. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  32944. 0.116935020465145) +
  32945. k * (-0.000343531996510555 * k + 0.24165260232407);
  32946. data[offset++] = clamp0to255(r);
  32947. data[offset++] = clamp0to255(g);
  32948. data[offset++] = clamp0to255(b);
  32949. }
  32950. return data;
  32951. },
  32952. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  32953. var Y, Cb, Cr;
  32954. for (var i = 0, length = data.length; i < length; i += 4) {
  32955. Y = data[i];
  32956. Cb = data[i + 1];
  32957. Cr = data[i + 2];
  32958. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  32959. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  32960. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  32961. // K in data[i + 3] is unchanged
  32962. }
  32963. return data;
  32964. },
  32965. _convertCmykToRgb: function convertCmykToRgb(data) {
  32966. var c, m, y, k;
  32967. var offset = 0;
  32968. var min = -255 * 255 * 255;
  32969. var scale = 1 / 255 / 255;
  32970. for (var i = 0, length = data.length; i < length; i += 4) {
  32971. c = data[i];
  32972. m = data[i + 1];
  32973. y = data[i + 2];
  32974. k = data[i + 3];
  32975. var r =
  32976. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32977. 18.82290502165302 * y + 212.25662451639585 * k -
  32978. 72734.4411664936) +
  32979. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  32980. 17.873870861415444 * k - 1401.7366389350734) +
  32981. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32982. 4465.541406466231) -
  32983. k * (21.86122147463605 * k + 48317.86113160301);
  32984. var g =
  32985. c * (8.841041422036149 * c + 60.118027045597366 * m +
  32986. 6.871425592049007 * y + 31.159100130055922 * k -
  32987. 20220.756542821975) +
  32988. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32989. 131.35250912493976 * k - 48691.05921601825) +
  32990. y * (4.444339102852739 * y + 9.8632861493405 * k -
  32991. 6341.191035517494) -
  32992. k * (20.737325471181034 * k + 47890.15695978492);
  32993. var b =
  32994. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32995. 30.89978309703729 * y - 0.23883238689178934 * k -
  32996. 3616.812083916688) +
  32997. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32998. 50.606957656360734 * k - 28620.90484698408) +
  32999. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33000. 49363.43385999684) -
  33001. k * (22.33816807309886 * k + 45932.16563550634);
  33002. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33003. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33004. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33005. }
  33006. return data;
  33007. },
  33008. getData: function getData(width, height, forceRGBoutput) {
  33009. if (this.numComponents > 4) {
  33010. throw 'Unsupported color mode';
  33011. }
  33012. // type of data: Uint8Array(width * height * numComponents)
  33013. var data = this._getLinearizedBlockData(width, height);
  33014. if (this.numComponents === 3) {
  33015. return this._convertYccToRgb(data);
  33016. } else if (this.numComponents === 4) {
  33017. if (this._isColorConversionNeeded()) {
  33018. if (forceRGBoutput) {
  33019. return this._convertYcckToRgb(data);
  33020. } else {
  33021. return this._convertYcckToCmyk(data);
  33022. }
  33023. } else if (forceRGBoutput) {
  33024. return this._convertCmykToRgb(data);
  33025. }
  33026. }
  33027. return data;
  33028. }
  33029. };
  33030. return constructor;
  33031. })();
  33032. var JpxImage = (function JpxImageClosure() {
  33033. // Table E.1
  33034. var SubbandsGainLog2 = {
  33035. 'LL': 0,
  33036. 'LH': 1,
  33037. 'HL': 1,
  33038. 'HH': 2
  33039. };
  33040. function JpxImage() {
  33041. this.failOnCorruptedImage = false;
  33042. }
  33043. JpxImage.prototype = {
  33044. parse: function JpxImage_parse(data) {
  33045. var head = readUint16(data, 0);
  33046. // No box header, immediate start of codestream (SOC)
  33047. if (head === 0xFF4F) {
  33048. this.parseCodestream(data, 0, data.length);
  33049. return;
  33050. }
  33051. var position = 0, length = data.length;
  33052. while (position < length) {
  33053. var headerSize = 8;
  33054. var lbox = readUint32(data, position);
  33055. var tbox = readUint32(data, position + 4);
  33056. position += headerSize;
  33057. if (lbox === 1) {
  33058. // XLBox: read UInt64 according to spec.
  33059. // JavaScript's int precision of 53 bit should be sufficient here.
  33060. lbox = readUint32(data, position) * 4294967296 +
  33061. readUint32(data, position + 4);
  33062. position += 8;
  33063. headerSize += 8;
  33064. }
  33065. if (lbox === 0) {
  33066. lbox = length - position + headerSize;
  33067. }
  33068. if (lbox < headerSize) {
  33069. throw new Error('JPX Error: Invalid box field size');
  33070. }
  33071. var dataLength = lbox - headerSize;
  33072. var jumpDataLength = true;
  33073. switch (tbox) {
  33074. case 0x6A703268: // 'jp2h'
  33075. jumpDataLength = false; // parsing child boxes
  33076. break;
  33077. case 0x636F6C72: // 'colr'
  33078. // Colorspaces are not used, the CS from the PDF is used.
  33079. var method = data[position];
  33080. var precedence = data[position + 1];
  33081. var approximation = data[position + 2];
  33082. if (method === 1) {
  33083. // enumerated colorspace
  33084. var colorspace = readUint32(data, position + 3);
  33085. switch (colorspace) {
  33086. case 16: // this indicates a sRGB colorspace
  33087. case 17: // this indicates a grayscale colorspace
  33088. case 18: // this indicates a YUV colorspace
  33089. break;
  33090. default:
  33091. warn('Unknown colorspace ' + colorspace);
  33092. break;
  33093. }
  33094. } else if (method === 2) {
  33095. info('ICC profile not supported');
  33096. }
  33097. break;
  33098. case 0x6A703263: // 'jp2c'
  33099. this.parseCodestream(data, position, position + dataLength);
  33100. break;
  33101. case 0x6A502020: // 'jP\024\024'
  33102. if (0x0d0a870a !== readUint32(data, position)) {
  33103. warn('Invalid JP2 signature');
  33104. }
  33105. break;
  33106. // The following header types are valid but currently not used:
  33107. case 0x6A501A1A: // 'jP\032\032'
  33108. case 0x66747970: // 'ftyp'
  33109. case 0x72726571: // 'rreq'
  33110. case 0x72657320: // 'res '
  33111. case 0x69686472: // 'ihdr'
  33112. break;
  33113. default:
  33114. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33115. (tbox >> 16) & 0xFF,
  33116. (tbox >> 8) & 0xFF,
  33117. tbox & 0xFF);
  33118. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33119. break;
  33120. }
  33121. if (jumpDataLength) {
  33122. position += dataLength;
  33123. }
  33124. }
  33125. },
  33126. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33127. var newByte = stream.getByte();
  33128. while (newByte >= 0) {
  33129. var oldByte = newByte;
  33130. newByte = stream.getByte();
  33131. var code = (oldByte << 8) | newByte;
  33132. // Image and tile size (SIZ)
  33133. if (code === 0xFF51) {
  33134. stream.skip(4);
  33135. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33136. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33137. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33138. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33139. stream.skip(16);
  33140. var Csiz = stream.getUint16(); // Byte 36
  33141. this.width = Xsiz - XOsiz;
  33142. this.height = Ysiz - YOsiz;
  33143. this.componentsCount = Csiz;
  33144. // Results are always returned as Uint8Arrays
  33145. this.bitsPerComponent = 8;
  33146. return;
  33147. }
  33148. }
  33149. throw new Error('JPX Error: No size marker found in JPX stream');
  33150. },
  33151. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33152. var context = {};
  33153. try {
  33154. var doNotRecover = false;
  33155. var position = start;
  33156. while (position + 1 < end) {
  33157. var code = readUint16(data, position);
  33158. position += 2;
  33159. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33160. switch (code) {
  33161. case 0xFF4F: // Start of codestream (SOC)
  33162. context.mainHeader = true;
  33163. break;
  33164. case 0xFFD9: // End of codestream (EOC)
  33165. break;
  33166. case 0xFF51: // Image and tile size (SIZ)
  33167. length = readUint16(data, position);
  33168. var siz = {};
  33169. siz.Xsiz = readUint32(data, position + 4);
  33170. siz.Ysiz = readUint32(data, position + 8);
  33171. siz.XOsiz = readUint32(data, position + 12);
  33172. siz.YOsiz = readUint32(data, position + 16);
  33173. siz.XTsiz = readUint32(data, position + 20);
  33174. siz.YTsiz = readUint32(data, position + 24);
  33175. siz.XTOsiz = readUint32(data, position + 28);
  33176. siz.YTOsiz = readUint32(data, position + 32);
  33177. var componentsCount = readUint16(data, position + 36);
  33178. siz.Csiz = componentsCount;
  33179. var components = [];
  33180. j = position + 38;
  33181. for (var i = 0; i < componentsCount; i++) {
  33182. var component = {
  33183. precision: (data[j] & 0x7F) + 1,
  33184. isSigned: !!(data[j] & 0x80),
  33185. XRsiz: data[j + 1],
  33186. YRsiz: data[j + 1]
  33187. };
  33188. calculateComponentDimensions(component, siz);
  33189. components.push(component);
  33190. }
  33191. context.SIZ = siz;
  33192. context.components = components;
  33193. calculateTileGrids(context, components);
  33194. context.QCC = [];
  33195. context.COC = [];
  33196. break;
  33197. case 0xFF55: // Tile-part lengths, main header (TLM)
  33198. var Ltlm = readUint16(data, position); // Marker segment length
  33199. // Skip tile length markers
  33200. position += Ltlm;
  33201. break;
  33202. case 0xFF5C: // Quantization default (QCD)
  33203. length = readUint16(data, position);
  33204. var qcd = {};
  33205. j = position + 2;
  33206. sqcd = data[j++];
  33207. switch (sqcd & 0x1F) {
  33208. case 0:
  33209. spqcdSize = 8;
  33210. scalarExpounded = true;
  33211. break;
  33212. case 1:
  33213. spqcdSize = 16;
  33214. scalarExpounded = false;
  33215. break;
  33216. case 2:
  33217. spqcdSize = 16;
  33218. scalarExpounded = true;
  33219. break;
  33220. default:
  33221. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33222. }
  33223. qcd.noQuantization = (spqcdSize === 8);
  33224. qcd.scalarExpounded = scalarExpounded;
  33225. qcd.guardBits = sqcd >> 5;
  33226. spqcds = [];
  33227. while (j < length + position) {
  33228. var spqcd = {};
  33229. if (spqcdSize === 8) {
  33230. spqcd.epsilon = data[j++] >> 3;
  33231. spqcd.mu = 0;
  33232. } else {
  33233. spqcd.epsilon = data[j] >> 3;
  33234. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33235. j += 2;
  33236. }
  33237. spqcds.push(spqcd);
  33238. }
  33239. qcd.SPqcds = spqcds;
  33240. if (context.mainHeader) {
  33241. context.QCD = qcd;
  33242. } else {
  33243. context.currentTile.QCD = qcd;
  33244. context.currentTile.QCC = [];
  33245. }
  33246. break;
  33247. case 0xFF5D: // Quantization component (QCC)
  33248. length = readUint16(data, position);
  33249. var qcc = {};
  33250. j = position + 2;
  33251. var cqcc;
  33252. if (context.SIZ.Csiz < 257) {
  33253. cqcc = data[j++];
  33254. } else {
  33255. cqcc = readUint16(data, j);
  33256. j += 2;
  33257. }
  33258. sqcd = data[j++];
  33259. switch (sqcd & 0x1F) {
  33260. case 0:
  33261. spqcdSize = 8;
  33262. scalarExpounded = true;
  33263. break;
  33264. case 1:
  33265. spqcdSize = 16;
  33266. scalarExpounded = false;
  33267. break;
  33268. case 2:
  33269. spqcdSize = 16;
  33270. scalarExpounded = true;
  33271. break;
  33272. default:
  33273. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33274. }
  33275. qcc.noQuantization = (spqcdSize === 8);
  33276. qcc.scalarExpounded = scalarExpounded;
  33277. qcc.guardBits = sqcd >> 5;
  33278. spqcds = [];
  33279. while (j < (length + position)) {
  33280. spqcd = {};
  33281. if (spqcdSize === 8) {
  33282. spqcd.epsilon = data[j++] >> 3;
  33283. spqcd.mu = 0;
  33284. } else {
  33285. spqcd.epsilon = data[j] >> 3;
  33286. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33287. j += 2;
  33288. }
  33289. spqcds.push(spqcd);
  33290. }
  33291. qcc.SPqcds = spqcds;
  33292. if (context.mainHeader) {
  33293. context.QCC[cqcc] = qcc;
  33294. } else {
  33295. context.currentTile.QCC[cqcc] = qcc;
  33296. }
  33297. break;
  33298. case 0xFF52: // Coding style default (COD)
  33299. length = readUint16(data, position);
  33300. var cod = {};
  33301. j = position + 2;
  33302. var scod = data[j++];
  33303. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33304. cod.sopMarkerUsed = !!(scod & 2);
  33305. cod.ephMarkerUsed = !!(scod & 4);
  33306. cod.progressionOrder = data[j++];
  33307. cod.layersCount = readUint16(data, j);
  33308. j += 2;
  33309. cod.multipleComponentTransform = data[j++];
  33310. cod.decompositionLevelsCount = data[j++];
  33311. cod.xcb = (data[j++] & 0xF) + 2;
  33312. cod.ycb = (data[j++] & 0xF) + 2;
  33313. var blockStyle = data[j++];
  33314. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33315. cod.resetContextProbabilities = !!(blockStyle & 2);
  33316. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33317. cod.verticalyStripe = !!(blockStyle & 8);
  33318. cod.predictableTermination = !!(blockStyle & 16);
  33319. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33320. cod.reversibleTransformation = data[j++];
  33321. if (cod.entropyCoderWithCustomPrecincts) {
  33322. var precinctsSizes = [];
  33323. while (j < length + position) {
  33324. var precinctsSize = data[j++];
  33325. precinctsSizes.push({
  33326. PPx: precinctsSize & 0xF,
  33327. PPy: precinctsSize >> 4
  33328. });
  33329. }
  33330. cod.precinctsSizes = precinctsSizes;
  33331. }
  33332. var unsupported = [];
  33333. if (cod.selectiveArithmeticCodingBypass) {
  33334. unsupported.push('selectiveArithmeticCodingBypass');
  33335. }
  33336. if (cod.resetContextProbabilities) {
  33337. unsupported.push('resetContextProbabilities');
  33338. }
  33339. if (cod.terminationOnEachCodingPass) {
  33340. unsupported.push('terminationOnEachCodingPass');
  33341. }
  33342. if (cod.verticalyStripe) {
  33343. unsupported.push('verticalyStripe');
  33344. }
  33345. if (cod.predictableTermination) {
  33346. unsupported.push('predictableTermination');
  33347. }
  33348. if (unsupported.length > 0) {
  33349. doNotRecover = true;
  33350. throw new Error('JPX Error: Unsupported COD options (' +
  33351. unsupported.join(', ') + ')');
  33352. }
  33353. if (context.mainHeader) {
  33354. context.COD = cod;
  33355. } else {
  33356. context.currentTile.COD = cod;
  33357. context.currentTile.COC = [];
  33358. }
  33359. break;
  33360. case 0xFF90: // Start of tile-part (SOT)
  33361. length = readUint16(data, position);
  33362. tile = {};
  33363. tile.index = readUint16(data, position + 2);
  33364. tile.length = readUint32(data, position + 4);
  33365. tile.dataEnd = tile.length + position - 2;
  33366. tile.partIndex = data[position + 8];
  33367. tile.partsCount = data[position + 9];
  33368. context.mainHeader = false;
  33369. if (tile.partIndex === 0) {
  33370. // reset component specific settings
  33371. tile.COD = context.COD;
  33372. tile.COC = context.COC.slice(0); // clone of the global COC
  33373. tile.QCD = context.QCD;
  33374. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33375. }
  33376. context.currentTile = tile;
  33377. break;
  33378. case 0xFF93: // Start of data (SOD)
  33379. tile = context.currentTile;
  33380. if (tile.partIndex === 0) {
  33381. initializeTile(context, tile.index);
  33382. buildPackets(context);
  33383. }
  33384. // moving to the end of the data
  33385. length = tile.dataEnd - position;
  33386. parseTilePackets(context, data, position, length);
  33387. break;
  33388. case 0xFF64: // Comment (COM)
  33389. length = readUint16(data, position);
  33390. // skipping content
  33391. break;
  33392. case 0xFF53: // Coding style component (COC)
  33393. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33394. 'not implemented');
  33395. default:
  33396. throw new Error('JPX Error: Unknown codestream code: ' +
  33397. code.toString(16));
  33398. }
  33399. position += length;
  33400. }
  33401. } catch (e) {
  33402. if (doNotRecover || this.failOnCorruptedImage) {
  33403. throw e;
  33404. } else {
  33405. warn('Trying to recover from ' + e.message);
  33406. }
  33407. }
  33408. this.tiles = transformComponents(context);
  33409. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33410. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33411. this.componentsCount = context.SIZ.Csiz;
  33412. }
  33413. };
  33414. function calculateComponentDimensions(component, siz) {
  33415. // Section B.2 Component mapping
  33416. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33417. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33418. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33419. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33420. component.width = component.x1 - component.x0;
  33421. component.height = component.y1 - component.y0;
  33422. }
  33423. function calculateTileGrids(context, components) {
  33424. var siz = context.SIZ;
  33425. // Section B.3 Division into tile and tile-components
  33426. var tile, tiles = [];
  33427. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33428. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33429. for (var q = 0; q < numYtiles; q++) {
  33430. for (var p = 0; p < numXtiles; p++) {
  33431. tile = {};
  33432. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33433. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33434. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33435. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33436. tile.width = tile.tx1 - tile.tx0;
  33437. tile.height = tile.ty1 - tile.ty0;
  33438. tile.components = [];
  33439. tiles.push(tile);
  33440. }
  33441. }
  33442. context.tiles = tiles;
  33443. var componentsCount = siz.Csiz;
  33444. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33445. var component = components[i];
  33446. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33447. var tileComponent = {};
  33448. tile = tiles[j];
  33449. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33450. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33451. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33452. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33453. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33454. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33455. tile.components[i] = tileComponent;
  33456. }
  33457. }
  33458. }
  33459. function getBlocksDimensions(context, component, r) {
  33460. var codOrCoc = component.codingStyleParameters;
  33461. var result = {};
  33462. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33463. result.PPx = 15;
  33464. result.PPy = 15;
  33465. } else {
  33466. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33467. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33468. }
  33469. // calculate codeblock size as described in section B.7
  33470. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33471. Math.min(codOrCoc.xcb, result.PPx));
  33472. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33473. Math.min(codOrCoc.ycb, result.PPy));
  33474. return result;
  33475. }
  33476. function buildPrecincts(context, resolution, dimensions) {
  33477. // Section B.6 Division resolution to precincts
  33478. var precinctWidth = 1 << dimensions.PPx;
  33479. var precinctHeight = 1 << dimensions.PPy;
  33480. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33481. // to precincts. Precinct partition divides a resolution according to width
  33482. // and height parameters. The subband that belongs to the resolution level
  33483. // has a different size than the level, unless it is the zero resolution.
  33484. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33485. // The precinct partitioning for a particular subband is derived from a
  33486. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33487. // resolution level)... The LL band associated with each resolution level is
  33488. // divided into precincts... Each of the resulting precinct regions is then
  33489. // mapped into its child subbands (if any) at the next lower resolution
  33490. // level. This is accomplished by using the coordinate transformation
  33491. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33492. // coordinates of a point in the LL band and child subband, respectively.
  33493. var isZeroRes = resolution.resLevel === 0;
  33494. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33495. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33496. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33497. Math.ceil(resolution.trx1 / precinctWidth) -
  33498. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33499. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33500. Math.ceil(resolution.try1 / precinctHeight) -
  33501. Math.floor(resolution.try0 / precinctHeight) : 0);
  33502. var numprecincts = numprecinctswide * numprecinctshigh;
  33503. resolution.precinctParameters = {
  33504. precinctWidth: precinctWidth,
  33505. precinctHeight: precinctHeight,
  33506. numprecinctswide: numprecinctswide,
  33507. numprecinctshigh: numprecinctshigh,
  33508. numprecincts: numprecincts,
  33509. precinctWidthInSubband: precinctWidthInSubband,
  33510. precinctHeightInSubband: precinctHeightInSubband
  33511. };
  33512. }
  33513. function buildCodeblocks(context, subband, dimensions) {
  33514. // Section B.7 Division sub-band into code-blocks
  33515. var xcb_ = dimensions.xcb_;
  33516. var ycb_ = dimensions.ycb_;
  33517. var codeblockWidth = 1 << xcb_;
  33518. var codeblockHeight = 1 << ycb_;
  33519. var cbx0 = subband.tbx0 >> xcb_;
  33520. var cby0 = subband.tby0 >> ycb_;
  33521. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33522. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33523. var precinctParameters = subband.resolution.precinctParameters;
  33524. var codeblocks = [];
  33525. var precincts = [];
  33526. var i, j, codeblock, precinctNumber;
  33527. for (j = cby0; j < cby1; j++) {
  33528. for (i = cbx0; i < cbx1; i++) {
  33529. codeblock = {
  33530. cbx: i,
  33531. cby: j,
  33532. tbx0: codeblockWidth * i,
  33533. tby0: codeblockHeight * j,
  33534. tbx1: codeblockWidth * (i + 1),
  33535. tby1: codeblockHeight * (j + 1)
  33536. };
  33537. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33538. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33539. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33540. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33541. // Calculate precinct number for this codeblock, codeblock position
  33542. // should be relative to its subband, use actual dimension and position
  33543. // See comment about codeblock group width and height
  33544. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33545. precinctParameters.precinctWidthInSubband);
  33546. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33547. precinctParameters.precinctHeightInSubband);
  33548. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33549. codeblock.precinctNumber = precinctNumber;
  33550. codeblock.subbandType = subband.type;
  33551. codeblock.Lblock = 3;
  33552. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  33553. codeblock.tby1_ <= codeblock.tby0_) {
  33554. continue;
  33555. }
  33556. codeblocks.push(codeblock);
  33557. // building precinct for the sub-band
  33558. var precinct = precincts[precinctNumber];
  33559. if (precinct !== undefined) {
  33560. if (i < precinct.cbxMin) {
  33561. precinct.cbxMin = i;
  33562. } else if (i > precinct.cbxMax) {
  33563. precinct.cbxMax = i;
  33564. }
  33565. if (j < precinct.cbyMin) {
  33566. precinct.cbxMin = j;
  33567. } else if (j > precinct.cbyMax) {
  33568. precinct.cbyMax = j;
  33569. }
  33570. } else {
  33571. precincts[precinctNumber] = precinct = {
  33572. cbxMin: i,
  33573. cbyMin: j,
  33574. cbxMax: i,
  33575. cbyMax: j
  33576. };
  33577. }
  33578. codeblock.precinct = precinct;
  33579. }
  33580. }
  33581. subband.codeblockParameters = {
  33582. codeblockWidth: xcb_,
  33583. codeblockHeight: ycb_,
  33584. numcodeblockwide: cbx1 - cbx0 + 1,
  33585. numcodeblockhigh: cby1 - cby0 + 1
  33586. };
  33587. subband.codeblocks = codeblocks;
  33588. subband.precincts = precincts;
  33589. }
  33590. function createPacket(resolution, precinctNumber, layerNumber) {
  33591. var precinctCodeblocks = [];
  33592. // Section B.10.8 Order of info in packet
  33593. var subbands = resolution.subbands;
  33594. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33595. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33596. var subband = subbands[i];
  33597. var codeblocks = subband.codeblocks;
  33598. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33599. var codeblock = codeblocks[j];
  33600. if (codeblock.precinctNumber !== precinctNumber) {
  33601. continue;
  33602. }
  33603. precinctCodeblocks.push(codeblock);
  33604. }
  33605. }
  33606. return {
  33607. layerNumber: layerNumber,
  33608. codeblocks: precinctCodeblocks
  33609. };
  33610. }
  33611. function LayerResolutionComponentPositionIterator(context) {
  33612. var siz = context.SIZ;
  33613. var tileIndex = context.currentTile.index;
  33614. var tile = context.tiles[tileIndex];
  33615. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33616. var componentsCount = siz.Csiz;
  33617. var maxDecompositionLevelsCount = 0;
  33618. for (var q = 0; q < componentsCount; q++) {
  33619. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33620. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33621. }
  33622. var l = 0, r = 0, i = 0, k = 0;
  33623. this.nextPacket = function JpxImage_nextPacket() {
  33624. // Section B.12.1.1 Layer-resolution-component-position
  33625. for (; l < layersCount; l++) {
  33626. for (; r <= maxDecompositionLevelsCount; r++) {
  33627. for (; i < componentsCount; i++) {
  33628. var component = tile.components[i];
  33629. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33630. continue;
  33631. }
  33632. var resolution = component.resolutions[r];
  33633. var numprecincts = resolution.precinctParameters.numprecincts;
  33634. for (; k < numprecincts;) {
  33635. var packet = createPacket(resolution, k, l);
  33636. k++;
  33637. return packet;
  33638. }
  33639. k = 0;
  33640. }
  33641. i = 0;
  33642. }
  33643. r = 0;
  33644. }
  33645. throw new Error('JPX Error: Out of packets');
  33646. };
  33647. }
  33648. function ResolutionLayerComponentPositionIterator(context) {
  33649. var siz = context.SIZ;
  33650. var tileIndex = context.currentTile.index;
  33651. var tile = context.tiles[tileIndex];
  33652. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33653. var componentsCount = siz.Csiz;
  33654. var maxDecompositionLevelsCount = 0;
  33655. for (var q = 0; q < componentsCount; q++) {
  33656. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33657. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33658. }
  33659. var r = 0, l = 0, i = 0, k = 0;
  33660. this.nextPacket = function JpxImage_nextPacket() {
  33661. // Section B.12.1.2 Resolution-layer-component-position
  33662. for (; r <= maxDecompositionLevelsCount; r++) {
  33663. for (; l < layersCount; l++) {
  33664. for (; i < componentsCount; i++) {
  33665. var component = tile.components[i];
  33666. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33667. continue;
  33668. }
  33669. var resolution = component.resolutions[r];
  33670. var numprecincts = resolution.precinctParameters.numprecincts;
  33671. for (; k < numprecincts;) {
  33672. var packet = createPacket(resolution, k, l);
  33673. k++;
  33674. return packet;
  33675. }
  33676. k = 0;
  33677. }
  33678. i = 0;
  33679. }
  33680. l = 0;
  33681. }
  33682. throw new Error('JPX Error: Out of packets');
  33683. };
  33684. }
  33685. function ResolutionPositionComponentLayerIterator(context) {
  33686. var siz = context.SIZ;
  33687. var tileIndex = context.currentTile.index;
  33688. var tile = context.tiles[tileIndex];
  33689. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33690. var componentsCount = siz.Csiz;
  33691. var l, r, c, p;
  33692. var maxDecompositionLevelsCount = 0;
  33693. for (c = 0; c < componentsCount; c++) {
  33694. var component = tile.components[c];
  33695. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33696. component.codingStyleParameters.decompositionLevelsCount);
  33697. }
  33698. var maxNumPrecinctsInLevel = new Int32Array(
  33699. maxDecompositionLevelsCount + 1);
  33700. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  33701. var maxNumPrecincts = 0;
  33702. for (c = 0; c < componentsCount; ++c) {
  33703. var resolutions = tile.components[c].resolutions;
  33704. if (r < resolutions.length) {
  33705. maxNumPrecincts = Math.max(maxNumPrecincts,
  33706. resolutions[r].precinctParameters.numprecincts);
  33707. }
  33708. }
  33709. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  33710. }
  33711. l = 0;
  33712. r = 0;
  33713. c = 0;
  33714. p = 0;
  33715. this.nextPacket = function JpxImage_nextPacket() {
  33716. // Section B.12.1.3 Resolution-position-component-layer
  33717. for (; r <= maxDecompositionLevelsCount; r++) {
  33718. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  33719. for (; c < componentsCount; c++) {
  33720. var component = tile.components[c];
  33721. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33722. continue;
  33723. }
  33724. var resolution = component.resolutions[r];
  33725. var numprecincts = resolution.precinctParameters.numprecincts;
  33726. if (p >= numprecincts) {
  33727. continue;
  33728. }
  33729. for (; l < layersCount;) {
  33730. var packet = createPacket(resolution, p, l);
  33731. l++;
  33732. return packet;
  33733. }
  33734. l = 0;
  33735. }
  33736. c = 0;
  33737. }
  33738. p = 0;
  33739. }
  33740. throw new Error('JPX Error: Out of packets');
  33741. };
  33742. }
  33743. function PositionComponentResolutionLayerIterator(context) {
  33744. var siz = context.SIZ;
  33745. var tileIndex = context.currentTile.index;
  33746. var tile = context.tiles[tileIndex];
  33747. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33748. var componentsCount = siz.Csiz;
  33749. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33750. var precinctsIterationSizes = precinctsSizes;
  33751. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33752. this.nextPacket = function JpxImage_nextPacket() {
  33753. // Section B.12.1.4 Position-component-resolution-layer
  33754. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33755. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33756. for (; c < componentsCount; c++) {
  33757. var component = tile.components[c];
  33758. var decompositionLevelsCount =
  33759. component.codingStyleParameters.decompositionLevelsCount;
  33760. for (; r <= decompositionLevelsCount; r++) {
  33761. var resolution = component.resolutions[r];
  33762. var sizeInImageScale =
  33763. precinctsSizes.components[c].resolutions[r];
  33764. var k = getPrecinctIndexIfExist(
  33765. px,
  33766. py,
  33767. sizeInImageScale,
  33768. precinctsIterationSizes,
  33769. resolution);
  33770. if (k === null) {
  33771. continue;
  33772. }
  33773. for (; l < layersCount;) {
  33774. var packet = createPacket(resolution, k, l);
  33775. l++;
  33776. return packet;
  33777. }
  33778. l = 0;
  33779. }
  33780. r = 0;
  33781. }
  33782. c = 0;
  33783. }
  33784. px = 0;
  33785. }
  33786. throw new Error('JPX Error: Out of packets');
  33787. };
  33788. }
  33789. function ComponentPositionResolutionLayerIterator(context) {
  33790. var siz = context.SIZ;
  33791. var tileIndex = context.currentTile.index;
  33792. var tile = context.tiles[tileIndex];
  33793. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33794. var componentsCount = siz.Csiz;
  33795. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33796. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33797. this.nextPacket = function JpxImage_nextPacket() {
  33798. // Section B.12.1.5 Component-position-resolution-layer
  33799. for (; c < componentsCount; ++c) {
  33800. var component = tile.components[c];
  33801. var precinctsIterationSizes = precinctsSizes.components[c];
  33802. var decompositionLevelsCount =
  33803. component.codingStyleParameters.decompositionLevelsCount;
  33804. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33805. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33806. for (; r <= decompositionLevelsCount; r++) {
  33807. var resolution = component.resolutions[r];
  33808. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  33809. var k = getPrecinctIndexIfExist(
  33810. px,
  33811. py,
  33812. sizeInImageScale,
  33813. precinctsIterationSizes,
  33814. resolution);
  33815. if (k === null) {
  33816. continue;
  33817. }
  33818. for (; l < layersCount;) {
  33819. var packet = createPacket(resolution, k, l);
  33820. l++;
  33821. return packet;
  33822. }
  33823. l = 0;
  33824. }
  33825. r = 0;
  33826. }
  33827. px = 0;
  33828. }
  33829. py = 0;
  33830. }
  33831. throw new Error('JPX Error: Out of packets');
  33832. };
  33833. }
  33834. function getPrecinctIndexIfExist(
  33835. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  33836. var posX = pxIndex * precinctIterationSizes.minWidth;
  33837. var posY = pyIndex * precinctIterationSizes.minHeight;
  33838. if (posX % sizeInImageScale.width !== 0 ||
  33839. posY % sizeInImageScale.height !== 0) {
  33840. return null;
  33841. }
  33842. var startPrecinctRowIndex =
  33843. (posY / sizeInImageScale.width) *
  33844. resolution.precinctParameters.numprecinctswide;
  33845. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  33846. }
  33847. function getPrecinctSizesInImageScale(tile) {
  33848. var componentsCount = tile.components.length;
  33849. var minWidth = Number.MAX_VALUE;
  33850. var minHeight = Number.MAX_VALUE;
  33851. var maxNumWide = 0;
  33852. var maxNumHigh = 0;
  33853. var sizePerComponent = new Array(componentsCount);
  33854. for (var c = 0; c < componentsCount; c++) {
  33855. var component = tile.components[c];
  33856. var decompositionLevelsCount =
  33857. component.codingStyleParameters.decompositionLevelsCount;
  33858. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  33859. var minWidthCurrentComponent = Number.MAX_VALUE;
  33860. var minHeightCurrentComponent = Number.MAX_VALUE;
  33861. var maxNumWideCurrentComponent = 0;
  33862. var maxNumHighCurrentComponent = 0;
  33863. var scale = 1;
  33864. for (var r = decompositionLevelsCount; r >= 0; --r) {
  33865. var resolution = component.resolutions[r];
  33866. var widthCurrentResolution =
  33867. scale * resolution.precinctParameters.precinctWidth;
  33868. var heightCurrentResolution =
  33869. scale * resolution.precinctParameters.precinctHeight;
  33870. minWidthCurrentComponent = Math.min(
  33871. minWidthCurrentComponent,
  33872. widthCurrentResolution);
  33873. minHeightCurrentComponent = Math.min(
  33874. minHeightCurrentComponent,
  33875. heightCurrentResolution);
  33876. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  33877. resolution.precinctParameters.numprecinctswide);
  33878. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  33879. resolution.precinctParameters.numprecinctshigh);
  33880. sizePerResolution[r] = {
  33881. width: widthCurrentResolution,
  33882. height: heightCurrentResolution
  33883. };
  33884. scale <<= 1;
  33885. }
  33886. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  33887. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  33888. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  33889. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  33890. sizePerComponent[c] = {
  33891. resolutions: sizePerResolution,
  33892. minWidth: minWidthCurrentComponent,
  33893. minHeight: minHeightCurrentComponent,
  33894. maxNumWide: maxNumWideCurrentComponent,
  33895. maxNumHigh: maxNumHighCurrentComponent
  33896. };
  33897. }
  33898. return {
  33899. components: sizePerComponent,
  33900. minWidth: minWidth,
  33901. minHeight: minHeight,
  33902. maxNumWide: maxNumWide,
  33903. maxNumHigh: maxNumHigh
  33904. };
  33905. }
  33906. function buildPackets(context) {
  33907. var siz = context.SIZ;
  33908. var tileIndex = context.currentTile.index;
  33909. var tile = context.tiles[tileIndex];
  33910. var componentsCount = siz.Csiz;
  33911. // Creating resolutions and sub-bands for each component
  33912. for (var c = 0; c < componentsCount; c++) {
  33913. var component = tile.components[c];
  33914. var decompositionLevelsCount =
  33915. component.codingStyleParameters.decompositionLevelsCount;
  33916. // Section B.5 Resolution levels and sub-bands
  33917. var resolutions = [];
  33918. var subbands = [];
  33919. for (var r = 0; r <= decompositionLevelsCount; r++) {
  33920. var blocksDimensions = getBlocksDimensions(context, component, r);
  33921. var resolution = {};
  33922. var scale = 1 << (decompositionLevelsCount - r);
  33923. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  33924. resolution.try0 = Math.ceil(component.tcy0 / scale);
  33925. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  33926. resolution.try1 = Math.ceil(component.tcy1 / scale);
  33927. resolution.resLevel = r;
  33928. buildPrecincts(context, resolution, blocksDimensions);
  33929. resolutions.push(resolution);
  33930. var subband;
  33931. if (r === 0) {
  33932. // one sub-band (LL) with last decomposition
  33933. subband = {};
  33934. subband.type = 'LL';
  33935. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  33936. subband.tby0 = Math.ceil(component.tcy0 / scale);
  33937. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  33938. subband.tby1 = Math.ceil(component.tcy1 / scale);
  33939. subband.resolution = resolution;
  33940. buildCodeblocks(context, subband, blocksDimensions);
  33941. subbands.push(subband);
  33942. resolution.subbands = [subband];
  33943. } else {
  33944. var bscale = 1 << (decompositionLevelsCount - r + 1);
  33945. var resolutionSubbands = [];
  33946. // three sub-bands (HL, LH and HH) with rest of decompositions
  33947. subband = {};
  33948. subband.type = 'HL';
  33949. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33950. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  33951. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33952. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  33953. subband.resolution = resolution;
  33954. buildCodeblocks(context, subband, blocksDimensions);
  33955. subbands.push(subband);
  33956. resolutionSubbands.push(subband);
  33957. subband = {};
  33958. subband.type = 'LH';
  33959. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  33960. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33961. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  33962. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33963. subband.resolution = resolution;
  33964. buildCodeblocks(context, subband, blocksDimensions);
  33965. subbands.push(subband);
  33966. resolutionSubbands.push(subband);
  33967. subband = {};
  33968. subband.type = 'HH';
  33969. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33970. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33971. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33972. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33973. subband.resolution = resolution;
  33974. buildCodeblocks(context, subband, blocksDimensions);
  33975. subbands.push(subband);
  33976. resolutionSubbands.push(subband);
  33977. resolution.subbands = resolutionSubbands;
  33978. }
  33979. }
  33980. component.resolutions = resolutions;
  33981. component.subbands = subbands;
  33982. }
  33983. // Generate the packets sequence
  33984. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  33985. switch (progressionOrder) {
  33986. case 0:
  33987. tile.packetsIterator =
  33988. new LayerResolutionComponentPositionIterator(context);
  33989. break;
  33990. case 1:
  33991. tile.packetsIterator =
  33992. new ResolutionLayerComponentPositionIterator(context);
  33993. break;
  33994. case 2:
  33995. tile.packetsIterator =
  33996. new ResolutionPositionComponentLayerIterator(context);
  33997. break;
  33998. case 3:
  33999. tile.packetsIterator =
  34000. new PositionComponentResolutionLayerIterator(context);
  34001. break;
  34002. case 4:
  34003. tile.packetsIterator =
  34004. new ComponentPositionResolutionLayerIterator(context);
  34005. break;
  34006. default:
  34007. throw new Error('JPX Error: Unsupported progression order ' +
  34008. progressionOrder);
  34009. }
  34010. }
  34011. function parseTilePackets(context, data, offset, dataLength) {
  34012. var position = 0;
  34013. var buffer, bufferSize = 0, skipNextBit = false;
  34014. function readBits(count) {
  34015. while (bufferSize < count) {
  34016. var b = data[offset + position];
  34017. position++;
  34018. if (skipNextBit) {
  34019. buffer = (buffer << 7) | b;
  34020. bufferSize += 7;
  34021. skipNextBit = false;
  34022. } else {
  34023. buffer = (buffer << 8) | b;
  34024. bufferSize += 8;
  34025. }
  34026. if (b === 0xFF) {
  34027. skipNextBit = true;
  34028. }
  34029. }
  34030. bufferSize -= count;
  34031. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34032. }
  34033. function skipMarkerIfEqual(value) {
  34034. if (data[offset + position - 1] === 0xFF &&
  34035. data[offset + position] === value) {
  34036. skipBytes(1);
  34037. return true;
  34038. } else if (data[offset + position] === 0xFF &&
  34039. data[offset + position + 1] === value) {
  34040. skipBytes(2);
  34041. return true;
  34042. }
  34043. return false;
  34044. }
  34045. function skipBytes(count) {
  34046. position += count;
  34047. }
  34048. function alignToByte() {
  34049. bufferSize = 0;
  34050. if (skipNextBit) {
  34051. position++;
  34052. skipNextBit = false;
  34053. }
  34054. }
  34055. function readCodingpasses() {
  34056. if (readBits(1) === 0) {
  34057. return 1;
  34058. }
  34059. if (readBits(1) === 0) {
  34060. return 2;
  34061. }
  34062. var value = readBits(2);
  34063. if (value < 3) {
  34064. return value + 3;
  34065. }
  34066. value = readBits(5);
  34067. if (value < 31) {
  34068. return value + 6;
  34069. }
  34070. value = readBits(7);
  34071. return value + 37;
  34072. }
  34073. var tileIndex = context.currentTile.index;
  34074. var tile = context.tiles[tileIndex];
  34075. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34076. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34077. var packetsIterator = tile.packetsIterator;
  34078. while (position < dataLength) {
  34079. alignToByte();
  34080. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34081. // Skip also marker segment length and packet sequence ID
  34082. skipBytes(4);
  34083. }
  34084. var packet = packetsIterator.nextPacket();
  34085. if (!readBits(1)) {
  34086. continue;
  34087. }
  34088. var layerNumber = packet.layerNumber;
  34089. var queue = [], codeblock;
  34090. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34091. codeblock = packet.codeblocks[i];
  34092. var precinct = codeblock.precinct;
  34093. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34094. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34095. var codeblockIncluded = false;
  34096. var firstTimeInclusion = false;
  34097. var valueReady;
  34098. if (codeblock['included'] !== undefined) {
  34099. codeblockIncluded = !!readBits(1);
  34100. } else {
  34101. // reading inclusion tree
  34102. precinct = codeblock.precinct;
  34103. var inclusionTree, zeroBitPlanesTree;
  34104. if (precinct['inclusionTree'] !== undefined) {
  34105. inclusionTree = precinct.inclusionTree;
  34106. } else {
  34107. // building inclusion and zero bit-planes trees
  34108. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34109. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34110. inclusionTree = new InclusionTree(width, height, layerNumber);
  34111. zeroBitPlanesTree = new TagTree(width, height);
  34112. precinct.inclusionTree = inclusionTree;
  34113. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34114. }
  34115. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34116. while (true) {
  34117. if (readBits(1)) {
  34118. valueReady = !inclusionTree.nextLevel();
  34119. if (valueReady) {
  34120. codeblock.included = true;
  34121. codeblockIncluded = firstTimeInclusion = true;
  34122. break;
  34123. }
  34124. } else {
  34125. inclusionTree.incrementValue(layerNumber);
  34126. break;
  34127. }
  34128. }
  34129. }
  34130. }
  34131. if (!codeblockIncluded) {
  34132. continue;
  34133. }
  34134. if (firstTimeInclusion) {
  34135. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34136. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34137. while (true) {
  34138. if (readBits(1)) {
  34139. valueReady = !zeroBitPlanesTree.nextLevel();
  34140. if (valueReady) {
  34141. break;
  34142. }
  34143. } else {
  34144. zeroBitPlanesTree.incrementValue();
  34145. }
  34146. }
  34147. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34148. }
  34149. var codingpasses = readCodingpasses();
  34150. while (readBits(1)) {
  34151. codeblock.Lblock++;
  34152. }
  34153. var codingpassesLog2 = log2(codingpasses);
  34154. // rounding down log2
  34155. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34156. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34157. var codedDataLength = readBits(bits);
  34158. queue.push({
  34159. codeblock: codeblock,
  34160. codingpasses: codingpasses,
  34161. dataLength: codedDataLength
  34162. });
  34163. }
  34164. alignToByte();
  34165. if (ephMarkerUsed) {
  34166. skipMarkerIfEqual(0x92);
  34167. }
  34168. while (queue.length > 0) {
  34169. var packetItem = queue.shift();
  34170. codeblock = packetItem.codeblock;
  34171. if (codeblock['data'] === undefined) {
  34172. codeblock.data = [];
  34173. }
  34174. codeblock.data.push({
  34175. data: data,
  34176. start: offset + position,
  34177. end: offset + position + packetItem.dataLength,
  34178. codingpasses: packetItem.codingpasses
  34179. });
  34180. position += packetItem.dataLength;
  34181. }
  34182. }
  34183. return position;
  34184. }
  34185. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34186. delta, mb, reversible, segmentationSymbolUsed) {
  34187. var x0 = subband.tbx0;
  34188. var y0 = subband.tby0;
  34189. var width = subband.tbx1 - subband.tbx0;
  34190. var codeblocks = subband.codeblocks;
  34191. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34192. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34193. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34194. var codeblock = codeblocks[i];
  34195. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34196. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34197. if (blockWidth === 0 || blockHeight === 0) {
  34198. continue;
  34199. }
  34200. if (codeblock['data'] === undefined) {
  34201. continue;
  34202. }
  34203. var bitModel, currentCodingpassType;
  34204. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34205. codeblock.zeroBitPlanes, mb);
  34206. currentCodingpassType = 2; // first bit plane starts from cleanup
  34207. // collect data
  34208. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34209. var j, jj, dataItem;
  34210. for (j = 0, jj = data.length; j < jj; j++) {
  34211. dataItem = data[j];
  34212. totalLength += dataItem.end - dataItem.start;
  34213. codingpasses += dataItem.codingpasses;
  34214. }
  34215. var encodedData = new Uint8Array(totalLength);
  34216. var position = 0;
  34217. for (j = 0, jj = data.length; j < jj; j++) {
  34218. dataItem = data[j];
  34219. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34220. encodedData.set(chunk, position);
  34221. position += chunk.length;
  34222. }
  34223. // decoding the item
  34224. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34225. bitModel.setDecoder(decoder);
  34226. for (j = 0; j < codingpasses; j++) {
  34227. switch (currentCodingpassType) {
  34228. case 0:
  34229. bitModel.runSignificancePropogationPass();
  34230. break;
  34231. case 1:
  34232. bitModel.runMagnitudeRefinementPass();
  34233. break;
  34234. case 2:
  34235. bitModel.runCleanupPass();
  34236. if (segmentationSymbolUsed) {
  34237. bitModel.checkSegmentationSymbol();
  34238. }
  34239. break;
  34240. }
  34241. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34242. }
  34243. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34244. var sign = bitModel.coefficentsSign;
  34245. var magnitude = bitModel.coefficentsMagnitude;
  34246. var bitsDecoded = bitModel.bitsDecoded;
  34247. var magnitudeCorrection = reversible ? 0 : 0.5;
  34248. var k, n, nb;
  34249. position = 0;
  34250. // Do the interleaving of Section F.3.3 here, so we do not need
  34251. // to copy later. LL level is not interleaved, just copied.
  34252. var interleave = (subband.type !== 'LL');
  34253. for (j = 0; j < blockHeight; j++) {
  34254. var row = (offset / width) | 0; // row in the non-interleaved subband
  34255. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34256. for (k = 0; k < blockWidth; k++) {
  34257. n = magnitude[position];
  34258. if (n !== 0) {
  34259. n = (n + magnitudeCorrection) * delta;
  34260. if (sign[position] !== 0) {
  34261. n = -n;
  34262. }
  34263. nb = bitsDecoded[position];
  34264. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34265. if (reversible && (nb >= mb)) {
  34266. coefficients[pos] = n;
  34267. } else {
  34268. coefficients[pos] = n * (1 << (mb - nb));
  34269. }
  34270. }
  34271. offset++;
  34272. position++;
  34273. }
  34274. offset += width - blockWidth;
  34275. }
  34276. }
  34277. }
  34278. function transformTile(context, tile, c) {
  34279. var component = tile.components[c];
  34280. var codingStyleParameters = component.codingStyleParameters;
  34281. var quantizationParameters = component.quantizationParameters;
  34282. var decompositionLevelsCount =
  34283. codingStyleParameters.decompositionLevelsCount;
  34284. var spqcds = quantizationParameters.SPqcds;
  34285. var scalarExpounded = quantizationParameters.scalarExpounded;
  34286. var guardBits = quantizationParameters.guardBits;
  34287. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34288. var precision = context.components[c].precision;
  34289. var reversible = codingStyleParameters.reversibleTransformation;
  34290. var transform = (reversible ? new ReversibleTransform() :
  34291. new IrreversibleTransform());
  34292. var subbandCoefficients = [];
  34293. var b = 0;
  34294. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34295. var resolution = component.resolutions[i];
  34296. var width = resolution.trx1 - resolution.trx0;
  34297. var height = resolution.try1 - resolution.try0;
  34298. // Allocate space for the whole sublevel.
  34299. var coefficients = new Float32Array(width * height);
  34300. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34301. var mu, epsilon;
  34302. if (!scalarExpounded) {
  34303. // formula E-5
  34304. mu = spqcds[0].mu;
  34305. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34306. } else {
  34307. mu = spqcds[b].mu;
  34308. epsilon = spqcds[b].epsilon;
  34309. b++;
  34310. }
  34311. var subband = resolution.subbands[j];
  34312. var gainLog2 = SubbandsGainLog2[subband.type];
  34313. // calulate quantization coefficient (Section E.1.1.1)
  34314. var delta = (reversible ? 1 :
  34315. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34316. var mb = (guardBits + epsilon - 1);
  34317. // In the first resolution level, copyCoefficients will fill the
  34318. // whole array with coefficients. In the succeding passes,
  34319. // copyCoefficients will consecutively fill in the values that belong
  34320. // to the interleaved positions of the HL, LH, and HH coefficients.
  34321. // The LL coefficients will then be interleaved in Transform.iterate().
  34322. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34323. reversible, segmentationSymbolUsed);
  34324. }
  34325. subbandCoefficients.push({
  34326. width: width,
  34327. height: height,
  34328. items: coefficients
  34329. });
  34330. }
  34331. var result = transform.calculate(subbandCoefficients,
  34332. component.tcx0, component.tcy0);
  34333. return {
  34334. left: component.tcx0,
  34335. top: component.tcy0,
  34336. width: result.width,
  34337. height: result.height,
  34338. items: result.items
  34339. };
  34340. }
  34341. function transformComponents(context) {
  34342. var siz = context.SIZ;
  34343. var components = context.components;
  34344. var componentsCount = siz.Csiz;
  34345. var resultImages = [];
  34346. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34347. var tile = context.tiles[i];
  34348. var transformedTiles = [];
  34349. var c;
  34350. for (c = 0; c < componentsCount; c++) {
  34351. transformedTiles[c] = transformTile(context, tile, c);
  34352. }
  34353. var tile0 = transformedTiles[0];
  34354. var out = new Uint8Array(tile0.items.length * componentsCount);
  34355. var result = {
  34356. left: tile0.left,
  34357. top: tile0.top,
  34358. width: tile0.width,
  34359. height: tile0.height,
  34360. items: out
  34361. };
  34362. // Section G.2.2 Inverse multi component transform
  34363. var shift, offset, max, min, maxK;
  34364. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34365. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34366. var fourComponents = componentsCount === 4;
  34367. var y0items = transformedTiles[0].items;
  34368. var y1items = transformedTiles[1].items;
  34369. var y2items = transformedTiles[2].items;
  34370. var y3items = fourComponents ? transformedTiles[3].items : null;
  34371. // HACK: The multiple component transform formulas below assume that
  34372. // all components have the same precision. With this in mind, we
  34373. // compute shift and offset only once.
  34374. shift = components[0].precision - 8;
  34375. offset = (128 << shift) + 0.5;
  34376. max = 255 * (1 << shift);
  34377. maxK = max * 0.5;
  34378. min = -maxK;
  34379. var component0 = tile.components[0];
  34380. var alpha01 = componentsCount - 3;
  34381. jj = y0items.length;
  34382. if (!component0.codingStyleParameters.reversibleTransformation) {
  34383. // inverse irreversible multiple component transform
  34384. for (j = 0; j < jj; j++, pos += alpha01) {
  34385. y0 = y0items[j] + offset;
  34386. y1 = y1items[j];
  34387. y2 = y2items[j];
  34388. r = y0 + 1.402 * y2;
  34389. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34390. b = y0 + 1.772 * y1;
  34391. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34392. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34393. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34394. }
  34395. } else {
  34396. // inverse reversible multiple component transform
  34397. for (j = 0; j < jj; j++, pos += alpha01) {
  34398. y0 = y0items[j] + offset;
  34399. y1 = y1items[j];
  34400. y2 = y2items[j];
  34401. g = y0 - ((y2 + y1) >> 2);
  34402. r = g + y2;
  34403. b = g + y1;
  34404. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34405. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34406. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34407. }
  34408. }
  34409. if (fourComponents) {
  34410. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34411. k = y3items[j];
  34412. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34413. }
  34414. }
  34415. } else { // no multi-component transform
  34416. for (c = 0; c < componentsCount; c++) {
  34417. var items = transformedTiles[c].items;
  34418. shift = components[c].precision - 8;
  34419. offset = (128 << shift) + 0.5;
  34420. max = (127.5 * (1 << shift));
  34421. min = -max;
  34422. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34423. val = items[j];
  34424. out[pos] = val <= min ? 0 :
  34425. val >= max ? 255 : (val + offset) >> shift;
  34426. pos += componentsCount;
  34427. }
  34428. }
  34429. }
  34430. resultImages.push(result);
  34431. }
  34432. return resultImages;
  34433. }
  34434. function initializeTile(context, tileIndex) {
  34435. var siz = context.SIZ;
  34436. var componentsCount = siz.Csiz;
  34437. var tile = context.tiles[tileIndex];
  34438. for (var c = 0; c < componentsCount; c++) {
  34439. var component = tile.components[c];
  34440. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34441. context.currentTile.QCC[c] : context.currentTile.QCD);
  34442. component.quantizationParameters = qcdOrQcc;
  34443. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34444. context.currentTile.COC[c] : context.currentTile.COD);
  34445. component.codingStyleParameters = codOrCoc;
  34446. }
  34447. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34448. }
  34449. // Section B.10.2 Tag trees
  34450. var TagTree = (function TagTreeClosure() {
  34451. function TagTree(width, height) {
  34452. var levelsLength = log2(Math.max(width, height)) + 1;
  34453. this.levels = [];
  34454. for (var i = 0; i < levelsLength; i++) {
  34455. var level = {
  34456. width: width,
  34457. height: height,
  34458. items: []
  34459. };
  34460. this.levels.push(level);
  34461. width = Math.ceil(width / 2);
  34462. height = Math.ceil(height / 2);
  34463. }
  34464. }
  34465. TagTree.prototype = {
  34466. reset: function TagTree_reset(i, j) {
  34467. var currentLevel = 0, value = 0, level;
  34468. while (currentLevel < this.levels.length) {
  34469. level = this.levels[currentLevel];
  34470. var index = i + j * level.width;
  34471. if (level.items[index] !== undefined) {
  34472. value = level.items[index];
  34473. break;
  34474. }
  34475. level.index = index;
  34476. i >>= 1;
  34477. j >>= 1;
  34478. currentLevel++;
  34479. }
  34480. currentLevel--;
  34481. level = this.levels[currentLevel];
  34482. level.items[level.index] = value;
  34483. this.currentLevel = currentLevel;
  34484. delete this.value;
  34485. },
  34486. incrementValue: function TagTree_incrementValue() {
  34487. var level = this.levels[this.currentLevel];
  34488. level.items[level.index]++;
  34489. },
  34490. nextLevel: function TagTree_nextLevel() {
  34491. var currentLevel = this.currentLevel;
  34492. var level = this.levels[currentLevel];
  34493. var value = level.items[level.index];
  34494. currentLevel--;
  34495. if (currentLevel < 0) {
  34496. this.value = value;
  34497. return false;
  34498. }
  34499. this.currentLevel = currentLevel;
  34500. level = this.levels[currentLevel];
  34501. level.items[level.index] = value;
  34502. return true;
  34503. }
  34504. };
  34505. return TagTree;
  34506. })();
  34507. var InclusionTree = (function InclusionTreeClosure() {
  34508. function InclusionTree(width, height, defaultValue) {
  34509. var levelsLength = log2(Math.max(width, height)) + 1;
  34510. this.levels = [];
  34511. for (var i = 0; i < levelsLength; i++) {
  34512. var items = new Uint8Array(width * height);
  34513. for (var j = 0, jj = items.length; j < jj; j++) {
  34514. items[j] = defaultValue;
  34515. }
  34516. var level = {
  34517. width: width,
  34518. height: height,
  34519. items: items
  34520. };
  34521. this.levels.push(level);
  34522. width = Math.ceil(width / 2);
  34523. height = Math.ceil(height / 2);
  34524. }
  34525. }
  34526. InclusionTree.prototype = {
  34527. reset: function InclusionTree_reset(i, j, stopValue) {
  34528. var currentLevel = 0;
  34529. while (currentLevel < this.levels.length) {
  34530. var level = this.levels[currentLevel];
  34531. var index = i + j * level.width;
  34532. level.index = index;
  34533. var value = level.items[index];
  34534. if (value === 0xFF) {
  34535. break;
  34536. }
  34537. if (value > stopValue) {
  34538. this.currentLevel = currentLevel;
  34539. // already know about this one, propagating the value to top levels
  34540. this.propagateValues();
  34541. return false;
  34542. }
  34543. i >>= 1;
  34544. j >>= 1;
  34545. currentLevel++;
  34546. }
  34547. this.currentLevel = currentLevel - 1;
  34548. return true;
  34549. },
  34550. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34551. var level = this.levels[this.currentLevel];
  34552. level.items[level.index] = stopValue + 1;
  34553. this.propagateValues();
  34554. },
  34555. propagateValues: function InclusionTree_propagateValues() {
  34556. var levelIndex = this.currentLevel;
  34557. var level = this.levels[levelIndex];
  34558. var currentValue = level.items[level.index];
  34559. while (--levelIndex >= 0) {
  34560. level = this.levels[levelIndex];
  34561. level.items[level.index] = currentValue;
  34562. }
  34563. },
  34564. nextLevel: function InclusionTree_nextLevel() {
  34565. var currentLevel = this.currentLevel;
  34566. var level = this.levels[currentLevel];
  34567. var value = level.items[level.index];
  34568. level.items[level.index] = 0xFF;
  34569. currentLevel--;
  34570. if (currentLevel < 0) {
  34571. return false;
  34572. }
  34573. this.currentLevel = currentLevel;
  34574. level = this.levels[currentLevel];
  34575. level.items[level.index] = value;
  34576. return true;
  34577. }
  34578. };
  34579. return InclusionTree;
  34580. })();
  34581. // Section D. Coefficient bit modeling
  34582. var BitModel = (function BitModelClosure() {
  34583. var UNIFORM_CONTEXT = 17;
  34584. var RUNLENGTH_CONTEXT = 18;
  34585. // Table D-1
  34586. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34587. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34588. var LLAndLHContextsLabel = new Uint8Array([
  34589. 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,
  34590. 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,
  34591. 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
  34592. ]);
  34593. var HLContextLabel = new Uint8Array([
  34594. 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,
  34595. 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,
  34596. 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
  34597. ]);
  34598. var HHContextLabel = new Uint8Array([
  34599. 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,
  34600. 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,
  34601. 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
  34602. ]);
  34603. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34604. this.width = width;
  34605. this.height = height;
  34606. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34607. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34608. var coefficientCount = width * height;
  34609. // coefficients outside the encoding region treated as insignificant
  34610. // add border state cells for significanceState
  34611. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34612. this.coefficentsSign = new Uint8Array(coefficientCount);
  34613. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34614. mb > 6 ? new Uint16Array(coefficientCount) :
  34615. new Uint8Array(coefficientCount);
  34616. this.processingFlags = new Uint8Array(coefficientCount);
  34617. var bitsDecoded = new Uint8Array(coefficientCount);
  34618. if (zeroBitPlanes !== 0) {
  34619. for (var i = 0; i < coefficientCount; i++) {
  34620. bitsDecoded[i] = zeroBitPlanes;
  34621. }
  34622. }
  34623. this.bitsDecoded = bitsDecoded;
  34624. this.reset();
  34625. }
  34626. BitModel.prototype = {
  34627. setDecoder: function BitModel_setDecoder(decoder) {
  34628. this.decoder = decoder;
  34629. },
  34630. reset: function BitModel_reset() {
  34631. // We have 17 contexts that are accessed via context labels,
  34632. // plus the uniform and runlength context.
  34633. this.contexts = new Int8Array(19);
  34634. // Contexts are packed into 1 byte:
  34635. // highest 7 bits carry the index, lowest bit carries mps
  34636. this.contexts[0] = (4 << 1) | 0;
  34637. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34638. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34639. },
  34640. setNeighborsSignificance:
  34641. function BitModel_setNeighborsSignificance(row, column, index) {
  34642. var neighborsSignificance = this.neighborsSignificance;
  34643. var width = this.width, height = this.height;
  34644. var left = (column > 0);
  34645. var right = (column + 1 < width);
  34646. var i;
  34647. if (row > 0) {
  34648. i = index - width;
  34649. if (left) {
  34650. neighborsSignificance[i - 1] += 0x10;
  34651. }
  34652. if (right) {
  34653. neighborsSignificance[i + 1] += 0x10;
  34654. }
  34655. neighborsSignificance[i] += 0x04;
  34656. }
  34657. if (row + 1 < height) {
  34658. i = index + width;
  34659. if (left) {
  34660. neighborsSignificance[i - 1] += 0x10;
  34661. }
  34662. if (right) {
  34663. neighborsSignificance[i + 1] += 0x10;
  34664. }
  34665. neighborsSignificance[i] += 0x04;
  34666. }
  34667. if (left) {
  34668. neighborsSignificance[index - 1] += 0x01;
  34669. }
  34670. if (right) {
  34671. neighborsSignificance[index + 1] += 0x01;
  34672. }
  34673. neighborsSignificance[index] |= 0x80;
  34674. },
  34675. runSignificancePropogationPass:
  34676. function BitModel_runSignificancePropogationPass() {
  34677. var decoder = this.decoder;
  34678. var width = this.width, height = this.height;
  34679. var coefficentsMagnitude = this.coefficentsMagnitude;
  34680. var coefficentsSign = this.coefficentsSign;
  34681. var neighborsSignificance = this.neighborsSignificance;
  34682. var processingFlags = this.processingFlags;
  34683. var contexts = this.contexts;
  34684. var labels = this.contextLabelTable;
  34685. var bitsDecoded = this.bitsDecoded;
  34686. var processedInverseMask = ~1;
  34687. var processedMask = 1;
  34688. var firstMagnitudeBitMask = 2;
  34689. for (var i0 = 0; i0 < height; i0 += 4) {
  34690. for (var j = 0; j < width; j++) {
  34691. var index = i0 * width + j;
  34692. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34693. var i = i0 + i1;
  34694. if (i >= height) {
  34695. break;
  34696. }
  34697. // clear processed flag first
  34698. processingFlags[index] &= processedInverseMask;
  34699. if (coefficentsMagnitude[index] ||
  34700. !neighborsSignificance[index]) {
  34701. continue;
  34702. }
  34703. var contextLabel = labels[neighborsSignificance[index]];
  34704. var decision = decoder.readBit(contexts, contextLabel);
  34705. if (decision) {
  34706. var sign = this.decodeSignBit(i, j, index);
  34707. coefficentsSign[index] = sign;
  34708. coefficentsMagnitude[index] = 1;
  34709. this.setNeighborsSignificance(i, j, index);
  34710. processingFlags[index] |= firstMagnitudeBitMask;
  34711. }
  34712. bitsDecoded[index]++;
  34713. processingFlags[index] |= processedMask;
  34714. }
  34715. }
  34716. }
  34717. },
  34718. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34719. var width = this.width, height = this.height;
  34720. var coefficentsMagnitude = this.coefficentsMagnitude;
  34721. var coefficentsSign = this.coefficentsSign;
  34722. var contribution, sign0, sign1, significance1;
  34723. var contextLabel, decoded;
  34724. // calculate horizontal contribution
  34725. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34726. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34727. sign1 = coefficentsSign[index + 1];
  34728. if (significance1) {
  34729. sign0 = coefficentsSign[index - 1];
  34730. contribution = 1 - sign1 - sign0;
  34731. } else {
  34732. contribution = 1 - sign1 - sign1;
  34733. }
  34734. } else if (significance1) {
  34735. sign0 = coefficentsSign[index - 1];
  34736. contribution = 1 - sign0 - sign0;
  34737. } else {
  34738. contribution = 0;
  34739. }
  34740. var horizontalContribution = 3 * contribution;
  34741. // calculate vertical contribution and combine with the horizontal
  34742. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34743. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34744. sign1 = coefficentsSign[index + width];
  34745. if (significance1) {
  34746. sign0 = coefficentsSign[index - width];
  34747. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34748. } else {
  34749. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34750. }
  34751. } else if (significance1) {
  34752. sign0 = coefficentsSign[index - width];
  34753. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34754. } else {
  34755. contribution = horizontalContribution;
  34756. }
  34757. if (contribution >= 0) {
  34758. contextLabel = 9 + contribution;
  34759. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34760. } else {
  34761. contextLabel = 9 - contribution;
  34762. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34763. }
  34764. return decoded;
  34765. },
  34766. runMagnitudeRefinementPass:
  34767. function BitModel_runMagnitudeRefinementPass() {
  34768. var decoder = this.decoder;
  34769. var width = this.width, height = this.height;
  34770. var coefficentsMagnitude = this.coefficentsMagnitude;
  34771. var neighborsSignificance = this.neighborsSignificance;
  34772. var contexts = this.contexts;
  34773. var bitsDecoded = this.bitsDecoded;
  34774. var processingFlags = this.processingFlags;
  34775. var processedMask = 1;
  34776. var firstMagnitudeBitMask = 2;
  34777. var length = width * height;
  34778. var width4 = width * 4;
  34779. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  34780. indexNext = Math.min(length, index0 + width4);
  34781. for (var j = 0; j < width; j++) {
  34782. for (var index = index0 + j; index < indexNext; index += width) {
  34783. // significant but not those that have just become
  34784. if (!coefficentsMagnitude[index] ||
  34785. (processingFlags[index] & processedMask) !== 0) {
  34786. continue;
  34787. }
  34788. var contextLabel = 16;
  34789. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  34790. processingFlags[index] ^= firstMagnitudeBitMask;
  34791. // first refinement
  34792. var significance = neighborsSignificance[index] & 127;
  34793. contextLabel = significance === 0 ? 15 : 14;
  34794. }
  34795. var bit = decoder.readBit(contexts, contextLabel);
  34796. coefficentsMagnitude[index] =
  34797. (coefficentsMagnitude[index] << 1) | bit;
  34798. bitsDecoded[index]++;
  34799. processingFlags[index] |= processedMask;
  34800. }
  34801. }
  34802. }
  34803. },
  34804. runCleanupPass: function BitModel_runCleanupPass() {
  34805. var decoder = this.decoder;
  34806. var width = this.width, height = this.height;
  34807. var neighborsSignificance = this.neighborsSignificance;
  34808. var coefficentsMagnitude = this.coefficentsMagnitude;
  34809. var coefficentsSign = this.coefficentsSign;
  34810. var contexts = this.contexts;
  34811. var labels = this.contextLabelTable;
  34812. var bitsDecoded = this.bitsDecoded;
  34813. var processingFlags = this.processingFlags;
  34814. var processedMask = 1;
  34815. var firstMagnitudeBitMask = 2;
  34816. var oneRowDown = width;
  34817. var twoRowsDown = width * 2;
  34818. var threeRowsDown = width * 3;
  34819. var iNext;
  34820. for (var i0 = 0; i0 < height; i0 = iNext) {
  34821. iNext = Math.min(i0 + 4, height);
  34822. var indexBase = i0 * width;
  34823. var checkAllEmpty = i0 + 3 < height;
  34824. for (var j = 0; j < width; j++) {
  34825. var index0 = indexBase + j;
  34826. // using the property: labels[neighborsSignificance[index]] === 0
  34827. // when neighborsSignificance[index] === 0
  34828. var allEmpty = (checkAllEmpty &&
  34829. processingFlags[index0] === 0 &&
  34830. processingFlags[index0 + oneRowDown] === 0 &&
  34831. processingFlags[index0 + twoRowsDown] === 0 &&
  34832. processingFlags[index0 + threeRowsDown] === 0 &&
  34833. neighborsSignificance[index0] === 0 &&
  34834. neighborsSignificance[index0 + oneRowDown] === 0 &&
  34835. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  34836. neighborsSignificance[index0 + threeRowsDown] === 0);
  34837. var i1 = 0, index = index0;
  34838. var i = i0, sign;
  34839. if (allEmpty) {
  34840. var hasSignificantCoefficent =
  34841. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  34842. if (!hasSignificantCoefficent) {
  34843. bitsDecoded[index0]++;
  34844. bitsDecoded[index0 + oneRowDown]++;
  34845. bitsDecoded[index0 + twoRowsDown]++;
  34846. bitsDecoded[index0 + threeRowsDown]++;
  34847. continue; // next column
  34848. }
  34849. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34850. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34851. if (i1 !== 0) {
  34852. i = i0 + i1;
  34853. index += i1 * width;
  34854. }
  34855. sign = this.decodeSignBit(i, j, index);
  34856. coefficentsSign[index] = sign;
  34857. coefficentsMagnitude[index] = 1;
  34858. this.setNeighborsSignificance(i, j, index);
  34859. processingFlags[index] |= firstMagnitudeBitMask;
  34860. index = index0;
  34861. for (var i2 = i0; i2 <= i; i2++, index += width) {
  34862. bitsDecoded[index]++;
  34863. }
  34864. i1++;
  34865. }
  34866. for (i = i0 + i1; i < iNext; i++, index += width) {
  34867. if (coefficentsMagnitude[index] ||
  34868. (processingFlags[index] & processedMask) !== 0) {
  34869. continue;
  34870. }
  34871. var contextLabel = labels[neighborsSignificance[index]];
  34872. var decision = decoder.readBit(contexts, contextLabel);
  34873. if (decision === 1) {
  34874. sign = this.decodeSignBit(i, j, index);
  34875. coefficentsSign[index] = sign;
  34876. coefficentsMagnitude[index] = 1;
  34877. this.setNeighborsSignificance(i, j, index);
  34878. processingFlags[index] |= firstMagnitudeBitMask;
  34879. }
  34880. bitsDecoded[index]++;
  34881. }
  34882. }
  34883. }
  34884. },
  34885. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  34886. var decoder = this.decoder;
  34887. var contexts = this.contexts;
  34888. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  34889. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  34890. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34891. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34892. if (symbol !== 0xA) {
  34893. throw new Error('JPX Error: Invalid segmentation symbol');
  34894. }
  34895. }
  34896. };
  34897. return BitModel;
  34898. })();
  34899. // Section F, Discrete wavelet transformation
  34900. var Transform = (function TransformClosure() {
  34901. function Transform() {}
  34902. Transform.prototype.calculate =
  34903. function transformCalculate(subbands, u0, v0) {
  34904. var ll = subbands[0];
  34905. for (var i = 1, ii = subbands.length; i < ii; i++) {
  34906. ll = this.iterate(ll, subbands[i], u0, v0);
  34907. }
  34908. return ll;
  34909. };
  34910. Transform.prototype.extend = function extend(buffer, offset, size) {
  34911. // Section F.3.7 extending... using max extension of 4
  34912. var i1 = offset - 1, j1 = offset + 1;
  34913. var i2 = offset + size - 2, j2 = offset + size;
  34914. buffer[i1--] = buffer[j1++];
  34915. buffer[j2++] = buffer[i2--];
  34916. buffer[i1--] = buffer[j1++];
  34917. buffer[j2++] = buffer[i2--];
  34918. buffer[i1--] = buffer[j1++];
  34919. buffer[j2++] = buffer[i2--];
  34920. buffer[i1] = buffer[j1];
  34921. buffer[j2] = buffer[i2];
  34922. };
  34923. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  34924. u0, v0) {
  34925. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  34926. var width = hl_lh_hh.width;
  34927. var height = hl_lh_hh.height;
  34928. var items = hl_lh_hh.items;
  34929. var i, j, k, l, u, v;
  34930. // Interleave LL according to Section F.3.3
  34931. for (k = 0, i = 0; i < llHeight; i++) {
  34932. l = i * 2 * width;
  34933. for (j = 0; j < llWidth; j++, k++, l += 2) {
  34934. items[l] = llItems[k];
  34935. }
  34936. }
  34937. // The LL band is not needed anymore.
  34938. llItems = ll.items = null;
  34939. var bufferPadding = 4;
  34940. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  34941. // Section F.3.4 HOR_SR
  34942. if (width === 1) {
  34943. // if width = 1, when u0 even keep items as is, when odd divide by 2
  34944. if ((u0 & 1) !== 0) {
  34945. for (v = 0, k = 0; v < height; v++, k += width) {
  34946. items[k] *= 0.5;
  34947. }
  34948. }
  34949. } else {
  34950. for (v = 0, k = 0; v < height; v++, k += width) {
  34951. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  34952. this.extend(rowBuffer, bufferPadding, width);
  34953. this.filter(rowBuffer, bufferPadding, width);
  34954. items.set(
  34955. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  34956. k);
  34957. }
  34958. }
  34959. // Accesses to the items array can take long, because it may not fit into
  34960. // CPU cache and has to be fetched from main memory. Since subsequent
  34961. // accesses to the items array are not local when reading columns, we
  34962. // have a cache miss every time. To reduce cache misses, get up to
  34963. // 'numBuffers' items at a time and store them into the individual
  34964. // buffers. The colBuffers should be small enough to fit into CPU cache.
  34965. var numBuffers = 16;
  34966. var colBuffers = [];
  34967. for (i = 0; i < numBuffers; i++) {
  34968. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  34969. }
  34970. var b, currentBuffer = 0;
  34971. ll = bufferPadding + height;
  34972. // Section F.3.5 VER_SR
  34973. if (height === 1) {
  34974. // if height = 1, when v0 even keep items as is, when odd divide by 2
  34975. if ((v0 & 1) !== 0) {
  34976. for (u = 0; u < width; u++) {
  34977. items[u] *= 0.5;
  34978. }
  34979. }
  34980. } else {
  34981. for (u = 0; u < width; u++) {
  34982. // if we ran out of buffers, copy several image columns at once
  34983. if (currentBuffer === 0) {
  34984. numBuffers = Math.min(width - u, numBuffers);
  34985. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  34986. for (b = 0; b < numBuffers; b++) {
  34987. colBuffers[b][l] = items[k + b];
  34988. }
  34989. }
  34990. currentBuffer = numBuffers;
  34991. }
  34992. currentBuffer--;
  34993. var buffer = colBuffers[currentBuffer];
  34994. this.extend(buffer, bufferPadding, height);
  34995. this.filter(buffer, bufferPadding, height);
  34996. // If this is last buffer in this group of buffers, flush all buffers.
  34997. if (currentBuffer === 0) {
  34998. k = u - numBuffers + 1;
  34999. for (l = bufferPadding; l < ll; k += width, l++) {
  35000. for (b = 0; b < numBuffers; b++) {
  35001. items[k + b] = colBuffers[b][l];
  35002. }
  35003. }
  35004. }
  35005. }
  35006. }
  35007. return {
  35008. width: width,
  35009. height: height,
  35010. items: items
  35011. };
  35012. };
  35013. return Transform;
  35014. })();
  35015. // Section 3.8.2 Irreversible 9-7 filter
  35016. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35017. function IrreversibleTransform() {
  35018. Transform.call(this);
  35019. }
  35020. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35021. IrreversibleTransform.prototype.filter =
  35022. function irreversibleTransformFilter(x, offset, length) {
  35023. var len = length >> 1;
  35024. offset = offset | 0;
  35025. var j, n, current, next;
  35026. var alpha = -1.586134342059924;
  35027. var beta = -0.052980118572961;
  35028. var gamma = 0.882911075530934;
  35029. var delta = 0.443506852043971;
  35030. var K = 1.230174104914001;
  35031. var K_ = 1 / K;
  35032. // step 1 is combined with step 3
  35033. // step 2
  35034. j = offset - 3;
  35035. for (n = len + 4; n--; j += 2) {
  35036. x[j] *= K_;
  35037. }
  35038. // step 1 & 3
  35039. j = offset - 2;
  35040. current = delta * x[j -1];
  35041. for (n = len + 3; n--; j += 2) {
  35042. next = delta * x[j + 1];
  35043. x[j] = K * x[j] - current - next;
  35044. if (n--) {
  35045. j += 2;
  35046. current = delta * x[j + 1];
  35047. x[j] = K * x[j] - current - next;
  35048. } else {
  35049. break;
  35050. }
  35051. }
  35052. // step 4
  35053. j = offset - 1;
  35054. current = gamma * x[j - 1];
  35055. for (n = len + 2; n--; j += 2) {
  35056. next = gamma * x[j + 1];
  35057. x[j] -= current + next;
  35058. if (n--) {
  35059. j += 2;
  35060. current = gamma * x[j + 1];
  35061. x[j] -= current + next;
  35062. } else {
  35063. break;
  35064. }
  35065. }
  35066. // step 5
  35067. j = offset;
  35068. current = beta * x[j - 1];
  35069. for (n = len + 1; n--; j += 2) {
  35070. next = beta * x[j + 1];
  35071. x[j] -= current + next;
  35072. if (n--) {
  35073. j += 2;
  35074. current = beta * x[j + 1];
  35075. x[j] -= current + next;
  35076. } else {
  35077. break;
  35078. }
  35079. }
  35080. // step 6
  35081. if (len !== 0) {
  35082. j = offset + 1;
  35083. current = alpha * x[j - 1];
  35084. for (n = len; n--; j += 2) {
  35085. next = alpha * x[j + 1];
  35086. x[j] -= current + next;
  35087. if (n--) {
  35088. j += 2;
  35089. current = alpha * x[j + 1];
  35090. x[j] -= current + next;
  35091. } else {
  35092. break;
  35093. }
  35094. }
  35095. }
  35096. };
  35097. return IrreversibleTransform;
  35098. })();
  35099. // Section 3.8.1 Reversible 5-3 filter
  35100. var ReversibleTransform = (function ReversibleTransformClosure() {
  35101. function ReversibleTransform() {
  35102. Transform.call(this);
  35103. }
  35104. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35105. ReversibleTransform.prototype.filter =
  35106. function reversibleTransformFilter(x, offset, length) {
  35107. var len = length >> 1;
  35108. offset = offset | 0;
  35109. var j, n;
  35110. for (j = offset, n = len + 1; n--; j += 2) {
  35111. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35112. }
  35113. for (j = offset + 1, n = len; n--; j += 2) {
  35114. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35115. }
  35116. };
  35117. return ReversibleTransform;
  35118. })();
  35119. return JpxImage;
  35120. })();
  35121. var Jbig2Image = (function Jbig2ImageClosure() {
  35122. // Utility data structures
  35123. function ContextCache() {}
  35124. ContextCache.prototype = {
  35125. getContexts: function(id) {
  35126. if (id in this) {
  35127. return this[id];
  35128. }
  35129. return (this[id] = new Int8Array(1 << 16));
  35130. }
  35131. };
  35132. function DecodingContext(data, start, end) {
  35133. this.data = data;
  35134. this.start = start;
  35135. this.end = end;
  35136. }
  35137. DecodingContext.prototype = {
  35138. get decoder() {
  35139. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35140. return shadow(this, 'decoder', decoder);
  35141. },
  35142. get contextCache() {
  35143. var cache = new ContextCache();
  35144. return shadow(this, 'contextCache', cache);
  35145. }
  35146. };
  35147. // Annex A. Arithmetic Integer Decoding Procedure
  35148. // A.2 Procedure for decoding values
  35149. function decodeInteger(contextCache, procedure, decoder) {
  35150. var contexts = contextCache.getContexts(procedure);
  35151. var prev = 1;
  35152. function readBits(length) {
  35153. var v = 0;
  35154. for (var i = 0; i < length; i++) {
  35155. var bit = decoder.readBit(contexts, prev);
  35156. prev = (prev < 256 ? (prev << 1) | bit :
  35157. (((prev << 1) | bit) & 511) | 256);
  35158. v = (v << 1) | bit;
  35159. }
  35160. return v >>> 0;
  35161. }
  35162. var sign = readBits(1);
  35163. var value = readBits(1) ?
  35164. (readBits(1) ?
  35165. (readBits(1) ?
  35166. (readBits(1) ?
  35167. (readBits(1) ?
  35168. (readBits(32) + 4436) :
  35169. readBits(12) + 340) :
  35170. readBits(8) + 84) :
  35171. readBits(6) + 20) :
  35172. readBits(4) + 4) :
  35173. readBits(2);
  35174. return (sign === 0 ? value : (value > 0 ? -value : null));
  35175. }
  35176. // A.3 The IAID decoding procedure
  35177. function decodeIAID(contextCache, decoder, codeLength) {
  35178. var contexts = contextCache.getContexts('IAID');
  35179. var prev = 1;
  35180. for (var i = 0; i < codeLength; i++) {
  35181. var bit = decoder.readBit(contexts, prev);
  35182. prev = (prev << 1) | bit;
  35183. }
  35184. if (codeLength < 31) {
  35185. return prev & ((1 << codeLength) - 1);
  35186. }
  35187. return prev & 0x7FFFFFFF;
  35188. }
  35189. // 7.3 Segment types
  35190. var SegmentTypes = [
  35191. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35192. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35193. null, null, null, null, null, 'patternDictionary', null, null, null,
  35194. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35195. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35196. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35197. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35198. 'IntermediateGenericRefinementRegion', null,
  35199. 'ImmediateGenericRefinementRegion',
  35200. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35201. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35202. 'Tables', null, null, null, null, null, null, null, null,
  35203. 'Extension'
  35204. ];
  35205. var CodingTemplates = [
  35206. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35207. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35208. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35209. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35210. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35211. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35212. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35213. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35214. {x: -1, y: 0}],
  35215. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35216. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35217. ];
  35218. var RefinementTemplates = [
  35219. {
  35220. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35221. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35222. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35223. },
  35224. {
  35225. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35226. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35227. {x: 0, y: 1}, {x: 1, y: 1}]
  35228. }
  35229. ];
  35230. // See 6.2.5.7 Decoding the bitmap.
  35231. var ReusedContexts = [
  35232. 0x9B25, // 10011 0110010 0101
  35233. 0x0795, // 0011 110010 101
  35234. 0x00E5, // 001 11001 01
  35235. 0x0195 // 011001 0101
  35236. ];
  35237. var RefinementReusedContexts = [
  35238. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35239. 0x0008 // '0000' + '001000'
  35240. ];
  35241. function decodeBitmapTemplate0(width, height, decodingContext) {
  35242. var decoder = decodingContext.decoder;
  35243. var contexts = decodingContext.contextCache.getContexts('GB');
  35244. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35245. // ...ooooo....
  35246. // ..ooooooo... Context template for current pixel (X)
  35247. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35248. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35249. for (i = 0; i < height; i++) {
  35250. row = bitmap[i] = new Uint8Array(width);
  35251. row1 = (i < 1) ? row : bitmap[i - 1];
  35252. row2 = (i < 2) ? row : bitmap[i - 2];
  35253. // At the beginning of each row:
  35254. // Fill contextLabel with pixels that are above/right of (X)
  35255. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35256. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35257. (row1[3] << 4);
  35258. for (j = 0; j < width; j++) {
  35259. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35260. // At each pixel: Clear contextLabel pixels that are shifted
  35261. // out of the context, then add new ones.
  35262. // If j + n is out of range at the right image border, then
  35263. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  35264. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35265. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  35266. }
  35267. }
  35268. return bitmap;
  35269. }
  35270. // 6.2 Generic Region Decoding Procedure
  35271. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35272. decodingContext) {
  35273. if (mmr) {
  35274. error('JBIG2 error: MMR encoding is not supported');
  35275. }
  35276. // Use optimized version for the most common case
  35277. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35278. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35279. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35280. return decodeBitmapTemplate0(width, height, decodingContext);
  35281. }
  35282. var useskip = !!skip;
  35283. var template = CodingTemplates[templateIndex].concat(at);
  35284. // Sorting is non-standard, and it is not required. But sorting increases
  35285. // the number of template bits that can be reused from the previous
  35286. // contextLabel in the main loop.
  35287. template.sort(function (a, b) {
  35288. return (a.y - b.y) || (a.x - b.x);
  35289. });
  35290. var templateLength = template.length;
  35291. var templateX = new Int8Array(templateLength);
  35292. var templateY = new Int8Array(templateLength);
  35293. var changingTemplateEntries = [];
  35294. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35295. var c, k;
  35296. for (k = 0; k < templateLength; k++) {
  35297. templateX[k] = template[k].x;
  35298. templateY[k] = template[k].y;
  35299. minX = Math.min(minX, template[k].x);
  35300. maxX = Math.max(maxX, template[k].x);
  35301. minY = Math.min(minY, template[k].y);
  35302. // Check if the template pixel appears in two consecutive context labels,
  35303. // so it can be reused. Otherwise, we add it to the list of changing
  35304. // template entries.
  35305. if (k < templateLength - 1 &&
  35306. template[k].y === template[k + 1].y &&
  35307. template[k].x === template[k + 1].x - 1) {
  35308. reuseMask |= 1 << (templateLength - 1 - k);
  35309. } else {
  35310. changingTemplateEntries.push(k);
  35311. }
  35312. }
  35313. var changingEntriesLength = changingTemplateEntries.length;
  35314. var changingTemplateX = new Int8Array(changingEntriesLength);
  35315. var changingTemplateY = new Int8Array(changingEntriesLength);
  35316. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35317. for (c = 0; c < changingEntriesLength; c++) {
  35318. k = changingTemplateEntries[c];
  35319. changingTemplateX[c] = template[k].x;
  35320. changingTemplateY[c] = template[k].y;
  35321. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35322. }
  35323. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35324. var sbb_left = -minX;
  35325. var sbb_top = -minY;
  35326. var sbb_right = width - maxX;
  35327. var pseudoPixelContext = ReusedContexts[templateIndex];
  35328. var row = new Uint8Array(width);
  35329. var bitmap = [];
  35330. var decoder = decodingContext.decoder;
  35331. var contexts = decodingContext.contextCache.getContexts('GB');
  35332. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35333. for (var i = 0; i < height; i++) {
  35334. if (prediction) {
  35335. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35336. ltp ^= sltp;
  35337. if (ltp) {
  35338. bitmap.push(row); // duplicate previous row
  35339. continue;
  35340. }
  35341. }
  35342. row = new Uint8Array(row);
  35343. bitmap.push(row);
  35344. for (j = 0; j < width; j++) {
  35345. if (useskip && skip[i][j]) {
  35346. row[j] = 0;
  35347. continue;
  35348. }
  35349. // Are we in the middle of a scanline, so we can reuse contextLabel
  35350. // bits?
  35351. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35352. // If yes, we can just shift the bits that are reusable and only
  35353. // fetch the remaining ones.
  35354. contextLabel = (contextLabel << 1) & reuseMask;
  35355. for (k = 0; k < changingEntriesLength; k++) {
  35356. i0 = i + changingTemplateY[k];
  35357. j0 = j + changingTemplateX[k];
  35358. bit = bitmap[i0][j0];
  35359. if (bit) {
  35360. bit = changingTemplateBit[k];
  35361. contextLabel |= bit;
  35362. }
  35363. }
  35364. } else {
  35365. // compute the contextLabel from scratch
  35366. contextLabel = 0;
  35367. shift = templateLength - 1;
  35368. for (k = 0; k < templateLength; k++, shift--) {
  35369. j0 = j + templateX[k];
  35370. if (j0 >= 0 && j0 < width) {
  35371. i0 = i + templateY[k];
  35372. if (i0 >= 0) {
  35373. bit = bitmap[i0][j0];
  35374. if (bit) {
  35375. contextLabel |= bit << shift;
  35376. }
  35377. }
  35378. }
  35379. }
  35380. }
  35381. var pixel = decoder.readBit(contexts, contextLabel);
  35382. row[j] = pixel;
  35383. }
  35384. }
  35385. return bitmap;
  35386. }
  35387. // 6.3.2 Generic Refinement Region Decoding Procedure
  35388. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35389. offsetX, offsetY, prediction, at,
  35390. decodingContext) {
  35391. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35392. if (templateIndex === 0) {
  35393. codingTemplate = codingTemplate.concat([at[0]]);
  35394. }
  35395. var codingTemplateLength = codingTemplate.length;
  35396. var codingTemplateX = new Int32Array(codingTemplateLength);
  35397. var codingTemplateY = new Int32Array(codingTemplateLength);
  35398. var k;
  35399. for (k = 0; k < codingTemplateLength; k++) {
  35400. codingTemplateX[k] = codingTemplate[k].x;
  35401. codingTemplateY[k] = codingTemplate[k].y;
  35402. }
  35403. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35404. if (templateIndex === 0) {
  35405. referenceTemplate = referenceTemplate.concat([at[1]]);
  35406. }
  35407. var referenceTemplateLength = referenceTemplate.length;
  35408. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35409. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35410. for (k = 0; k < referenceTemplateLength; k++) {
  35411. referenceTemplateX[k] = referenceTemplate[k].x;
  35412. referenceTemplateY[k] = referenceTemplate[k].y;
  35413. }
  35414. var referenceWidth = referenceBitmap[0].length;
  35415. var referenceHeight = referenceBitmap.length;
  35416. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35417. var bitmap = [];
  35418. var decoder = decodingContext.decoder;
  35419. var contexts = decodingContext.contextCache.getContexts('GR');
  35420. var ltp = 0;
  35421. for (var i = 0; i < height; i++) {
  35422. if (prediction) {
  35423. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35424. ltp ^= sltp;
  35425. if (ltp) {
  35426. error('JBIG2 error: prediction is not supported');
  35427. }
  35428. }
  35429. var row = new Uint8Array(width);
  35430. bitmap.push(row);
  35431. for (var j = 0; j < width; j++) {
  35432. var i0, j0;
  35433. var contextLabel = 0;
  35434. for (k = 0; k < codingTemplateLength; k++) {
  35435. i0 = i + codingTemplateY[k];
  35436. j0 = j + codingTemplateX[k];
  35437. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35438. contextLabel <<= 1; // out of bound pixel
  35439. } else {
  35440. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35441. }
  35442. }
  35443. for (k = 0; k < referenceTemplateLength; k++) {
  35444. i0 = i + referenceTemplateY[k] + offsetY;
  35445. j0 = j + referenceTemplateX[k] + offsetX;
  35446. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35447. j0 >= referenceWidth) {
  35448. contextLabel <<= 1; // out of bound pixel
  35449. } else {
  35450. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35451. }
  35452. }
  35453. var pixel = decoder.readBit(contexts, contextLabel);
  35454. row[j] = pixel;
  35455. }
  35456. }
  35457. return bitmap;
  35458. }
  35459. // 6.5.5 Decoding the symbol dictionary
  35460. function decodeSymbolDictionary(huffman, refinement, symbols,
  35461. numberOfNewSymbols, numberOfExportedSymbols,
  35462. huffmanTables, templateIndex, at,
  35463. refinementTemplateIndex, refinementAt,
  35464. decodingContext) {
  35465. if (huffman) {
  35466. error('JBIG2 error: huffman is not supported');
  35467. }
  35468. var newSymbols = [];
  35469. var currentHeight = 0;
  35470. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35471. var decoder = decodingContext.decoder;
  35472. var contextCache = decodingContext.contextCache;
  35473. while (newSymbols.length < numberOfNewSymbols) {
  35474. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35475. currentHeight += deltaHeight;
  35476. var currentWidth = 0;
  35477. var totalWidth = 0;
  35478. while (true) {
  35479. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35480. if (deltaWidth === null) {
  35481. break; // OOB
  35482. }
  35483. currentWidth += deltaWidth;
  35484. totalWidth += currentWidth;
  35485. var bitmap;
  35486. if (refinement) {
  35487. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35488. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35489. if (numberOfInstances > 1) {
  35490. bitmap = decodeTextRegion(huffman, refinement,
  35491. currentWidth, currentHeight, 0,
  35492. numberOfInstances, 1, //strip size
  35493. symbols.concat(newSymbols),
  35494. symbolCodeLength,
  35495. 0, //transposed
  35496. 0, //ds offset
  35497. 1, //top left 7.4.3.1.1
  35498. 0, //OR operator
  35499. huffmanTables,
  35500. refinementTemplateIndex, refinementAt,
  35501. decodingContext);
  35502. } else {
  35503. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35504. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35505. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35506. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35507. newSymbols[symbolId - symbols.length]);
  35508. bitmap = decodeRefinement(currentWidth, currentHeight,
  35509. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35510. decodingContext);
  35511. }
  35512. } else {
  35513. // 6.5.8.1 Direct-coded symbol bitmap
  35514. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35515. templateIndex, false, null, at, decodingContext);
  35516. }
  35517. newSymbols.push(bitmap);
  35518. }
  35519. }
  35520. // 6.5.10 Exported symbols
  35521. var exportedSymbols = [];
  35522. var flags = [], currentFlag = false;
  35523. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35524. while (flags.length < totalSymbolsLength) {
  35525. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35526. while (runLength--) {
  35527. flags.push(currentFlag);
  35528. }
  35529. currentFlag = !currentFlag;
  35530. }
  35531. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35532. if (flags[i]) {
  35533. exportedSymbols.push(symbols[i]);
  35534. }
  35535. }
  35536. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35537. if (flags[i]) {
  35538. exportedSymbols.push(newSymbols[j]);
  35539. }
  35540. }
  35541. return exportedSymbols;
  35542. }
  35543. function decodeTextRegion(huffman, refinement, width, height,
  35544. defaultPixelValue, numberOfSymbolInstances,
  35545. stripSize, inputSymbols, symbolCodeLength,
  35546. transposed, dsOffset, referenceCorner,
  35547. combinationOperator, huffmanTables,
  35548. refinementTemplateIndex, refinementAt,
  35549. decodingContext) {
  35550. if (huffman) {
  35551. error('JBIG2 error: huffman is not supported');
  35552. }
  35553. // Prepare bitmap
  35554. var bitmap = [];
  35555. var i, row;
  35556. for (i = 0; i < height; i++) {
  35557. row = new Uint8Array(width);
  35558. if (defaultPixelValue) {
  35559. for (var j = 0; j < width; j++) {
  35560. row[j] = defaultPixelValue;
  35561. }
  35562. }
  35563. bitmap.push(row);
  35564. }
  35565. var decoder = decodingContext.decoder;
  35566. var contextCache = decodingContext.contextCache;
  35567. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35568. var firstS = 0;
  35569. i = 0;
  35570. while (i < numberOfSymbolInstances) {
  35571. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35572. stripT += deltaT;
  35573. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35574. firstS += deltaFirstS;
  35575. var currentS = firstS;
  35576. do {
  35577. var currentT = (stripSize === 1 ? 0 :
  35578. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35579. var t = stripSize * stripT + currentT;
  35580. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35581. var applyRefinement = (refinement &&
  35582. decodeInteger(contextCache, 'IARI', decoder));
  35583. var symbolBitmap = inputSymbols[symbolId];
  35584. var symbolWidth = symbolBitmap[0].length;
  35585. var symbolHeight = symbolBitmap.length;
  35586. if (applyRefinement) {
  35587. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35588. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35589. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35590. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35591. symbolWidth += rdw;
  35592. symbolHeight += rdh;
  35593. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35594. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35595. (rdh >> 1) + rdy, false, refinementAt,
  35596. decodingContext);
  35597. }
  35598. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35599. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35600. var s2, t2, symbolRow;
  35601. if (transposed) {
  35602. // Place Symbol Bitmap from T1,S1
  35603. for (s2 = 0; s2 < symbolHeight; s2++) {
  35604. row = bitmap[offsetS + s2];
  35605. if (!row) {
  35606. continue;
  35607. }
  35608. symbolRow = symbolBitmap[s2];
  35609. // To ignore Parts of Symbol bitmap which goes
  35610. // outside bitmap region
  35611. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35612. switch (combinationOperator) {
  35613. case 0: // OR
  35614. for (t2 = 0; t2 < maxWidth; t2++) {
  35615. row[offsetT + t2] |= symbolRow[t2];
  35616. }
  35617. break;
  35618. case 2: // XOR
  35619. for (t2 = 0; t2 < maxWidth; t2++) {
  35620. row[offsetT + t2] ^= symbolRow[t2];
  35621. }
  35622. break;
  35623. default:
  35624. error('JBIG2 error: operator ' + combinationOperator +
  35625. ' is not supported');
  35626. }
  35627. }
  35628. currentS += symbolHeight - 1;
  35629. } else {
  35630. for (t2 = 0; t2 < symbolHeight; t2++) {
  35631. row = bitmap[offsetT + t2];
  35632. if (!row) {
  35633. continue;
  35634. }
  35635. symbolRow = symbolBitmap[t2];
  35636. switch (combinationOperator) {
  35637. case 0: // OR
  35638. for (s2 = 0; s2 < symbolWidth; s2++) {
  35639. row[offsetS + s2] |= symbolRow[s2];
  35640. }
  35641. break;
  35642. case 2: // XOR
  35643. for (s2 = 0; s2 < symbolWidth; s2++) {
  35644. row[offsetS + s2] ^= symbolRow[s2];
  35645. }
  35646. break;
  35647. default:
  35648. error('JBIG2 error: operator ' + combinationOperator +
  35649. ' is not supported');
  35650. }
  35651. }
  35652. currentS += symbolWidth - 1;
  35653. }
  35654. i++;
  35655. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35656. if (deltaS === null) {
  35657. break; // OOB
  35658. }
  35659. currentS += deltaS + dsOffset;
  35660. } while (true);
  35661. }
  35662. return bitmap;
  35663. }
  35664. function readSegmentHeader(data, start) {
  35665. var segmentHeader = {};
  35666. segmentHeader.number = readUint32(data, start);
  35667. var flags = data[start + 4];
  35668. var segmentType = flags & 0x3F;
  35669. if (!SegmentTypes[segmentType]) {
  35670. error('JBIG2 error: invalid segment type: ' + segmentType);
  35671. }
  35672. segmentHeader.type = segmentType;
  35673. segmentHeader.typeName = SegmentTypes[segmentType];
  35674. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35675. var pageAssociationFieldSize = !!(flags & 0x40);
  35676. var referredFlags = data[start + 5];
  35677. var referredToCount = (referredFlags >> 5) & 7;
  35678. var retainBits = [referredFlags & 31];
  35679. var position = start + 6;
  35680. if (referredFlags === 7) {
  35681. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35682. position += 3;
  35683. var bytes = (referredToCount + 7) >> 3;
  35684. retainBits[0] = data[position++];
  35685. while (--bytes > 0) {
  35686. retainBits.push(data[position++]);
  35687. }
  35688. } else if (referredFlags === 5 || referredFlags === 6) {
  35689. error('JBIG2 error: invalid referred-to flags');
  35690. }
  35691. segmentHeader.retainBits = retainBits;
  35692. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35693. (segmentHeader.number <= 65536 ? 2 : 4));
  35694. var referredTo = [];
  35695. var i, ii;
  35696. for (i = 0; i < referredToCount; i++) {
  35697. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35698. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35699. readUint32(data, position)));
  35700. referredTo.push(number);
  35701. position += referredToSegmentNumberSize;
  35702. }
  35703. segmentHeader.referredTo = referredTo;
  35704. if (!pageAssociationFieldSize) {
  35705. segmentHeader.pageAssociation = data[position++];
  35706. } else {
  35707. segmentHeader.pageAssociation = readUint32(data, position);
  35708. position += 4;
  35709. }
  35710. segmentHeader.length = readUint32(data, position);
  35711. position += 4;
  35712. if (segmentHeader.length === 0xFFFFFFFF) {
  35713. // 7.2.7 Segment data length, unknown segment length
  35714. if (segmentType === 38) { // ImmediateGenericRegion
  35715. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35716. var genericRegionSegmentFlags = data[position +
  35717. RegionSegmentInformationFieldLength];
  35718. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35719. // searching for the segment end
  35720. var searchPatternLength = 6;
  35721. var searchPattern = new Uint8Array(searchPatternLength);
  35722. if (!genericRegionMmr) {
  35723. searchPattern[0] = 0xFF;
  35724. searchPattern[1] = 0xAC;
  35725. }
  35726. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35727. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35728. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35729. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35730. for (i = position, ii = data.length; i < ii; i++) {
  35731. var j = 0;
  35732. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35733. j++;
  35734. }
  35735. if (j === searchPatternLength) {
  35736. segmentHeader.length = i + searchPatternLength;
  35737. break;
  35738. }
  35739. }
  35740. if (segmentHeader.length === 0xFFFFFFFF) {
  35741. error('JBIG2 error: segment end was not found');
  35742. }
  35743. } else {
  35744. error('JBIG2 error: invalid unknown segment length');
  35745. }
  35746. }
  35747. segmentHeader.headerEnd = position;
  35748. return segmentHeader;
  35749. }
  35750. function readSegments(header, data, start, end) {
  35751. var segments = [];
  35752. var position = start;
  35753. while (position < end) {
  35754. var segmentHeader = readSegmentHeader(data, position);
  35755. position = segmentHeader.headerEnd;
  35756. var segment = {
  35757. header: segmentHeader,
  35758. data: data
  35759. };
  35760. if (!header.randomAccess) {
  35761. segment.start = position;
  35762. position += segmentHeader.length;
  35763. segment.end = position;
  35764. }
  35765. segments.push(segment);
  35766. if (segmentHeader.type === 51) {
  35767. break; // end of file is found
  35768. }
  35769. }
  35770. if (header.randomAccess) {
  35771. for (var i = 0, ii = segments.length; i < ii; i++) {
  35772. segments[i].start = position;
  35773. position += segments[i].header.length;
  35774. segments[i].end = position;
  35775. }
  35776. }
  35777. return segments;
  35778. }
  35779. // 7.4.1 Region segment information field
  35780. function readRegionSegmentInformation(data, start) {
  35781. return {
  35782. width: readUint32(data, start),
  35783. height: readUint32(data, start + 4),
  35784. x: readUint32(data, start + 8),
  35785. y: readUint32(data, start + 12),
  35786. combinationOperator: data[start + 16] & 7
  35787. };
  35788. }
  35789. var RegionSegmentInformationFieldLength = 17;
  35790. function processSegment(segment, visitor) {
  35791. var header = segment.header;
  35792. var data = segment.data, position = segment.start, end = segment.end;
  35793. var args, at, i, atLength;
  35794. switch (header.type) {
  35795. case 0: // SymbolDictionary
  35796. // 7.4.2 Symbol dictionary segment syntax
  35797. var dictionary = {};
  35798. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  35799. dictionary.huffman = !!(dictionaryFlags & 1);
  35800. dictionary.refinement = !!(dictionaryFlags & 2);
  35801. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  35802. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  35803. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  35804. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  35805. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  35806. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  35807. dictionary.template = (dictionaryFlags >> 10) & 3;
  35808. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  35809. position += 2;
  35810. if (!dictionary.huffman) {
  35811. atLength = dictionary.template === 0 ? 4 : 1;
  35812. at = [];
  35813. for (i = 0; i < atLength; i++) {
  35814. at.push({
  35815. x: readInt8(data, position),
  35816. y: readInt8(data, position + 1)
  35817. });
  35818. position += 2;
  35819. }
  35820. dictionary.at = at;
  35821. }
  35822. if (dictionary.refinement && !dictionary.refinementTemplate) {
  35823. at = [];
  35824. for (i = 0; i < 2; i++) {
  35825. at.push({
  35826. x: readInt8(data, position),
  35827. y: readInt8(data, position + 1)
  35828. });
  35829. position += 2;
  35830. }
  35831. dictionary.refinementAt = at;
  35832. }
  35833. dictionary.numberOfExportedSymbols = readUint32(data, position);
  35834. position += 4;
  35835. dictionary.numberOfNewSymbols = readUint32(data, position);
  35836. position += 4;
  35837. args = [dictionary, header.number, header.referredTo,
  35838. data, position, end];
  35839. break;
  35840. case 6: // ImmediateTextRegion
  35841. case 7: // ImmediateLosslessTextRegion
  35842. var textRegion = {};
  35843. textRegion.info = readRegionSegmentInformation(data, position);
  35844. position += RegionSegmentInformationFieldLength;
  35845. var textRegionSegmentFlags = readUint16(data, position);
  35846. position += 2;
  35847. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  35848. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  35849. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  35850. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  35851. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  35852. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  35853. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  35854. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  35855. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  35856. if (textRegion.huffman) {
  35857. var textRegionHuffmanFlags = readUint16(data, position);
  35858. position += 2;
  35859. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  35860. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  35861. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  35862. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  35863. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  35864. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  35865. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  35866. textRegion.huffmanRefinementSizeSelector =
  35867. !!(textRegionHuffmanFlags & 14);
  35868. }
  35869. if (textRegion.refinement && !textRegion.refinementTemplate) {
  35870. at = [];
  35871. for (i = 0; i < 2; i++) {
  35872. at.push({
  35873. x: readInt8(data, position),
  35874. y: readInt8(data, position + 1)
  35875. });
  35876. position += 2;
  35877. }
  35878. textRegion.refinementAt = at;
  35879. }
  35880. textRegion.numberOfSymbolInstances = readUint32(data, position);
  35881. position += 4;
  35882. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  35883. if (textRegion.huffman) {
  35884. error('JBIG2 error: huffman is not supported');
  35885. }
  35886. args = [textRegion, header.referredTo, data, position, end];
  35887. break;
  35888. case 38: // ImmediateGenericRegion
  35889. case 39: // ImmediateLosslessGenericRegion
  35890. var genericRegion = {};
  35891. genericRegion.info = readRegionSegmentInformation(data, position);
  35892. position += RegionSegmentInformationFieldLength;
  35893. var genericRegionSegmentFlags = data[position++];
  35894. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  35895. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  35896. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  35897. if (!genericRegion.mmr) {
  35898. atLength = genericRegion.template === 0 ? 4 : 1;
  35899. at = [];
  35900. for (i = 0; i < atLength; i++) {
  35901. at.push({
  35902. x: readInt8(data, position),
  35903. y: readInt8(data, position + 1)
  35904. });
  35905. position += 2;
  35906. }
  35907. genericRegion.at = at;
  35908. }
  35909. args = [genericRegion, data, position, end];
  35910. break;
  35911. case 48: // PageInformation
  35912. var pageInfo = {
  35913. width: readUint32(data, position),
  35914. height: readUint32(data, position + 4),
  35915. resolutionX: readUint32(data, position + 8),
  35916. resolutionY: readUint32(data, position + 12)
  35917. };
  35918. if (pageInfo.height === 0xFFFFFFFF) {
  35919. delete pageInfo.height;
  35920. }
  35921. var pageSegmentFlags = data[position + 16];
  35922. var pageStripingInformatiom = readUint16(data, position + 17);
  35923. pageInfo.lossless = !!(pageSegmentFlags & 1);
  35924. pageInfo.refinement = !!(pageSegmentFlags & 2);
  35925. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  35926. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  35927. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  35928. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  35929. args = [pageInfo];
  35930. break;
  35931. case 49: // EndOfPage
  35932. break;
  35933. case 50: // EndOfStripe
  35934. break;
  35935. case 51: // EndOfFile
  35936. break;
  35937. case 62: // 7.4.15 defines 2 extension types which
  35938. // are comments and can be ignored.
  35939. break;
  35940. default:
  35941. error('JBIG2 error: segment type ' + header.typeName + '(' +
  35942. header.type + ') is not implemented');
  35943. }
  35944. var callbackName = 'on' + header.typeName;
  35945. if (callbackName in visitor) {
  35946. visitor[callbackName].apply(visitor, args);
  35947. }
  35948. }
  35949. function processSegments(segments, visitor) {
  35950. for (var i = 0, ii = segments.length; i < ii; i++) {
  35951. processSegment(segments[i], visitor);
  35952. }
  35953. }
  35954. function parseJbig2(data, start, end) {
  35955. var position = start;
  35956. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  35957. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  35958. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  35959. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  35960. error('JBIG2 error: invalid header');
  35961. }
  35962. var header = {};
  35963. position += 8;
  35964. var flags = data[position++];
  35965. header.randomAccess = !(flags & 1);
  35966. if (!(flags & 2)) {
  35967. header.numberOfPages = readUint32(data, position);
  35968. position += 4;
  35969. }
  35970. var segments = readSegments(header, data, position, end);
  35971. error('Not implemented');
  35972. // processSegments(segments, new SimpleSegmentVisitor());
  35973. }
  35974. function parseJbig2Chunks(chunks) {
  35975. var visitor = new SimpleSegmentVisitor();
  35976. for (var i = 0, ii = chunks.length; i < ii; i++) {
  35977. var chunk = chunks[i];
  35978. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  35979. processSegments(segments, visitor);
  35980. }
  35981. return visitor.buffer;
  35982. }
  35983. function SimpleSegmentVisitor() {}
  35984. SimpleSegmentVisitor.prototype = {
  35985. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  35986. this.currentPageInfo = info;
  35987. var rowSize = (info.width + 7) >> 3;
  35988. var buffer = new Uint8Array(rowSize * info.height);
  35989. // The contents of ArrayBuffers are initialized to 0.
  35990. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  35991. if (info.defaultPixelValue) {
  35992. for (var i = 0, ii = buffer.length; i < ii; i++) {
  35993. buffer[i] = 0xFF;
  35994. }
  35995. }
  35996. this.buffer = buffer;
  35997. },
  35998. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  35999. var pageInfo = this.currentPageInfo;
  36000. var width = regionInfo.width, height = regionInfo.height;
  36001. var rowSize = (pageInfo.width + 7) >> 3;
  36002. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36003. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36004. var buffer = this.buffer;
  36005. var mask0 = 128 >> (regionInfo.x & 7);
  36006. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36007. var i, j, mask, offset;
  36008. switch (combinationOperator) {
  36009. case 0: // OR
  36010. for (i = 0; i < height; i++) {
  36011. mask = mask0;
  36012. offset = offset0;
  36013. for (j = 0; j < width; j++) {
  36014. if (bitmap[i][j]) {
  36015. buffer[offset] |= mask;
  36016. }
  36017. mask >>= 1;
  36018. if (!mask) {
  36019. mask = 128;
  36020. offset++;
  36021. }
  36022. }
  36023. offset0 += rowSize;
  36024. }
  36025. break;
  36026. case 2: // XOR
  36027. for (i = 0; i < height; i++) {
  36028. mask = mask0;
  36029. offset = offset0;
  36030. for (j = 0; j < width; j++) {
  36031. if (bitmap[i][j]) {
  36032. buffer[offset] ^= mask;
  36033. }
  36034. mask >>= 1;
  36035. if (!mask) {
  36036. mask = 128;
  36037. offset++;
  36038. }
  36039. }
  36040. offset0 += rowSize;
  36041. }
  36042. break;
  36043. default:
  36044. error('JBIG2 error: operator ' + combinationOperator +
  36045. ' is not supported');
  36046. }
  36047. },
  36048. onImmediateGenericRegion:
  36049. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36050. start, end) {
  36051. var regionInfo = region.info;
  36052. var decodingContext = new DecodingContext(data, start, end);
  36053. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36054. region.template, region.prediction, null,
  36055. region.at, decodingContext);
  36056. this.drawBitmap(regionInfo, bitmap);
  36057. },
  36058. onImmediateLosslessGenericRegion:
  36059. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36060. this.onImmediateGenericRegion.apply(this, arguments);
  36061. },
  36062. onSymbolDictionary:
  36063. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36064. currentSegment,
  36065. referredSegments,
  36066. data, start, end) {
  36067. var huffmanTables;
  36068. if (dictionary.huffman) {
  36069. error('JBIG2 error: huffman is not supported');
  36070. }
  36071. // Combines exported symbols from all referred segments
  36072. var symbols = this.symbols;
  36073. if (!symbols) {
  36074. this.symbols = symbols = {};
  36075. }
  36076. var inputSymbols = [];
  36077. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36078. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36079. }
  36080. var decodingContext = new DecodingContext(data, start, end);
  36081. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36082. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36083. dictionary.numberOfExportedSymbols, huffmanTables,
  36084. dictionary.template, dictionary.at,
  36085. dictionary.refinementTemplate, dictionary.refinementAt,
  36086. decodingContext);
  36087. },
  36088. onImmediateTextRegion:
  36089. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36090. referredSegments,
  36091. data, start, end) {
  36092. var regionInfo = region.info;
  36093. var huffmanTables;
  36094. // Combines exported symbols from all referred segments
  36095. var symbols = this.symbols;
  36096. var inputSymbols = [];
  36097. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36098. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36099. }
  36100. var symbolCodeLength = log2(inputSymbols.length);
  36101. var decodingContext = new DecodingContext(data, start, end);
  36102. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36103. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36104. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36105. symbolCodeLength, region.transposed, region.dsOffset,
  36106. region.referenceCorner, region.combinationOperator, huffmanTables,
  36107. region.refinementTemplate, region.refinementAt, decodingContext);
  36108. this.drawBitmap(regionInfo, bitmap);
  36109. },
  36110. onImmediateLosslessTextRegion:
  36111. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36112. this.onImmediateTextRegion.apply(this, arguments);
  36113. }
  36114. };
  36115. function Jbig2Image() {}
  36116. Jbig2Image.prototype = {
  36117. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36118. return parseJbig2Chunks(chunks);
  36119. }
  36120. };
  36121. return Jbig2Image;
  36122. })();
  36123. var bidi = PDFJS.bidi = (function bidiClosure() {
  36124. // Character types for symbols from 0000 to 00FF.
  36125. var baseTypes = [
  36126. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36127. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36128. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36129. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36130. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36131. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36132. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36133. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36134. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36135. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36136. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36137. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36138. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36139. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36140. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36141. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36142. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36143. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36144. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36145. ];
  36146. // Character types for symbols from 0600 to 06FF
  36147. var arabicTypes = [
  36148. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36149. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36150. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36151. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36152. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36153. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36154. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36155. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36156. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36157. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36158. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36159. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36160. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36161. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36162. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36163. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36164. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36165. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36166. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36167. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36168. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36169. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36170. ];
  36171. function isOdd(i) {
  36172. return (i & 1) !== 0;
  36173. }
  36174. function isEven(i) {
  36175. return (i & 1) === 0;
  36176. }
  36177. function findUnequal(arr, start, value) {
  36178. for (var j = start, jj = arr.length; j < jj; ++j) {
  36179. if (arr[j] !== value) {
  36180. return j;
  36181. }
  36182. }
  36183. return j;
  36184. }
  36185. function setValues(arr, start, end, value) {
  36186. for (var j = start; j < end; ++j) {
  36187. arr[j] = value;
  36188. }
  36189. }
  36190. function reverseValues(arr, start, end) {
  36191. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36192. var temp = arr[i];
  36193. arr[i] = arr[j];
  36194. arr[j] = temp;
  36195. }
  36196. }
  36197. function createBidiText(str, isLTR, vertical) {
  36198. return {
  36199. str: str,
  36200. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36201. };
  36202. }
  36203. // These are used in bidi(), which is called frequently. We re-use them on
  36204. // each call to avoid unnecessary allocations.
  36205. var chars = [];
  36206. var types = [];
  36207. function bidi(str, startLevel, vertical) {
  36208. var isLTR = true;
  36209. var strLength = str.length;
  36210. if (strLength === 0 || vertical) {
  36211. return createBidiText(str, isLTR, vertical);
  36212. }
  36213. // Get types and fill arrays
  36214. chars.length = strLength;
  36215. types.length = strLength;
  36216. var numBidi = 0;
  36217. var i, ii;
  36218. for (i = 0; i < strLength; ++i) {
  36219. chars[i] = str.charAt(i);
  36220. var charCode = str.charCodeAt(i);
  36221. var charType = 'L';
  36222. if (charCode <= 0x00ff) {
  36223. charType = baseTypes[charCode];
  36224. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36225. charType = 'R';
  36226. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36227. charType = arabicTypes[charCode & 0xff];
  36228. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36229. charType = 'AL';
  36230. }
  36231. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36232. numBidi++;
  36233. }
  36234. types[i] = charType;
  36235. }
  36236. // Detect the bidi method
  36237. // - If there are no rtl characters then no bidi needed
  36238. // - If less than 30% chars are rtl then string is primarily ltr
  36239. // - If more than 30% chars are rtl then string is primarily rtl
  36240. if (numBidi === 0) {
  36241. isLTR = true;
  36242. return createBidiText(str, isLTR);
  36243. }
  36244. if (startLevel === -1) {
  36245. if ((strLength / numBidi) < 0.3) {
  36246. isLTR = true;
  36247. startLevel = 0;
  36248. } else {
  36249. isLTR = false;
  36250. startLevel = 1;
  36251. }
  36252. }
  36253. var levels = [];
  36254. for (i = 0; i < strLength; ++i) {
  36255. levels[i] = startLevel;
  36256. }
  36257. /*
  36258. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36259. */
  36260. var e = (isOdd(startLevel) ? 'R' : 'L');
  36261. var sor = e;
  36262. var eor = sor;
  36263. /*
  36264. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36265. type of the NSM to the type of the previous character. If the NSM is at the
  36266. start of the level run, it will get the type of sor.
  36267. */
  36268. var lastType = sor;
  36269. for (i = 0; i < strLength; ++i) {
  36270. if (types[i] === 'NSM') {
  36271. types[i] = lastType;
  36272. } else {
  36273. lastType = types[i];
  36274. }
  36275. }
  36276. /*
  36277. W2. Search backwards from each instance of a European number until the
  36278. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36279. the type of the European number to Arabic number.
  36280. */
  36281. lastType = sor;
  36282. var t;
  36283. for (i = 0; i < strLength; ++i) {
  36284. t = types[i];
  36285. if (t === 'EN') {
  36286. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36287. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36288. lastType = t;
  36289. }
  36290. }
  36291. /*
  36292. W3. Change all ALs to R.
  36293. */
  36294. for (i = 0; i < strLength; ++i) {
  36295. t = types[i];
  36296. if (t === 'AL') {
  36297. types[i] = 'R';
  36298. }
  36299. }
  36300. /*
  36301. W4. A single European separator between two European numbers changes to a
  36302. European number. A single common separator between two numbers of the same
  36303. type changes to that type:
  36304. */
  36305. for (i = 1; i < strLength - 1; ++i) {
  36306. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36307. types[i] = 'EN';
  36308. }
  36309. if (types[i] === 'CS' &&
  36310. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36311. types[i + 1] === types[i - 1]) {
  36312. types[i] = types[i - 1];
  36313. }
  36314. }
  36315. /*
  36316. W5. A sequence of European terminators adjacent to European numbers changes
  36317. to all European numbers:
  36318. */
  36319. for (i = 0; i < strLength; ++i) {
  36320. if (types[i] === 'EN') {
  36321. // do before
  36322. var j;
  36323. for (j = i - 1; j >= 0; --j) {
  36324. if (types[j] !== 'ET') {
  36325. break;
  36326. }
  36327. types[j] = 'EN';
  36328. }
  36329. // do after
  36330. for (j = i + 1; j < strLength; --j) {
  36331. if (types[j] !== 'ET') {
  36332. break;
  36333. }
  36334. types[j] = 'EN';
  36335. }
  36336. }
  36337. }
  36338. /*
  36339. W6. Otherwise, separators and terminators change to Other Neutral:
  36340. */
  36341. for (i = 0; i < strLength; ++i) {
  36342. t = types[i];
  36343. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36344. types[i] = 'ON';
  36345. }
  36346. }
  36347. /*
  36348. W7. Search backwards from each instance of a European number until the
  36349. first strong type (R, L, or sor) is found. If an L is found, then change
  36350. the type of the European number to L.
  36351. */
  36352. lastType = sor;
  36353. for (i = 0; i < strLength; ++i) {
  36354. t = types[i];
  36355. if (t === 'EN') {
  36356. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36357. } else if (t === 'R' || t === 'L') {
  36358. lastType = t;
  36359. }
  36360. }
  36361. /*
  36362. N1. A sequence of neutrals takes the direction of the surrounding strong
  36363. text if the text on both sides has the same direction. European and Arabic
  36364. numbers are treated as though they were R. Start-of-level-run (sor) and
  36365. end-of-level-run (eor) are used at level run boundaries.
  36366. */
  36367. for (i = 0; i < strLength; ++i) {
  36368. if (types[i] === 'ON') {
  36369. var end = findUnequal(types, i + 1, 'ON');
  36370. var before = sor;
  36371. if (i > 0) {
  36372. before = types[i - 1];
  36373. }
  36374. var after = eor;
  36375. if (end + 1 < strLength) {
  36376. after = types[end + 1];
  36377. }
  36378. if (before !== 'L') {
  36379. before = 'R';
  36380. }
  36381. if (after !== 'L') {
  36382. after = 'R';
  36383. }
  36384. if (before === after) {
  36385. setValues(types, i, end, before);
  36386. }
  36387. i = end - 1; // reset to end (-1 so next iteration is ok)
  36388. }
  36389. }
  36390. /*
  36391. N2. Any remaining neutrals take the embedding direction.
  36392. */
  36393. for (i = 0; i < strLength; ++i) {
  36394. if (types[i] === 'ON') {
  36395. types[i] = e;
  36396. }
  36397. }
  36398. /*
  36399. I1. For all characters with an even (left-to-right) embedding direction,
  36400. those of type R go up one level and those of type AN or EN go up two
  36401. levels.
  36402. I2. For all characters with an odd (right-to-left) embedding direction,
  36403. those of type L, EN or AN go up one level.
  36404. */
  36405. for (i = 0; i < strLength; ++i) {
  36406. t = types[i];
  36407. if (isEven(levels[i])) {
  36408. if (t === 'R') {
  36409. levels[i] += 1;
  36410. } else if (t === 'AN' || t === 'EN') {
  36411. levels[i] += 2;
  36412. }
  36413. } else { // isOdd
  36414. if (t === 'L' || t === 'AN' || t === 'EN') {
  36415. levels[i] += 1;
  36416. }
  36417. }
  36418. }
  36419. /*
  36420. L1. On each line, reset the embedding level of the following characters to
  36421. the paragraph embedding level:
  36422. segment separators,
  36423. paragraph separators,
  36424. any sequence of whitespace characters preceding a segment separator or
  36425. paragraph separator, and any sequence of white space characters at the end
  36426. of the line.
  36427. */
  36428. // don't bother as text is only single line
  36429. /*
  36430. L2. From the highest level found in the text to the lowest odd level on
  36431. each line, reverse any contiguous sequence of characters that are at that
  36432. level or higher.
  36433. */
  36434. // find highest level & lowest odd level
  36435. var highestLevel = -1;
  36436. var lowestOddLevel = 99;
  36437. var level;
  36438. for (i = 0, ii = levels.length; i < ii; ++i) {
  36439. level = levels[i];
  36440. if (highestLevel < level) {
  36441. highestLevel = level;
  36442. }
  36443. if (lowestOddLevel > level && isOdd(level)) {
  36444. lowestOddLevel = level;
  36445. }
  36446. }
  36447. // now reverse between those limits
  36448. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36449. // find segments to reverse
  36450. var start = -1;
  36451. for (i = 0, ii = levels.length; i < ii; ++i) {
  36452. if (levels[i] < level) {
  36453. if (start >= 0) {
  36454. reverseValues(chars, start, i);
  36455. start = -1;
  36456. }
  36457. } else if (start < 0) {
  36458. start = i;
  36459. }
  36460. }
  36461. if (start >= 0) {
  36462. reverseValues(chars, start, levels.length);
  36463. }
  36464. }
  36465. /*
  36466. L3. Combining marks applied to a right-to-left base character will at this
  36467. point precede their base character. If the rendering engine expects them to
  36468. follow the base characters in the final display process, then the ordering
  36469. of the marks and the base character must be reversed.
  36470. */
  36471. // don't bother for now
  36472. /*
  36473. L4. A character that possesses the mirrored property as specified by
  36474. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36475. directionality of that character is R.
  36476. */
  36477. // don't mirror as characters are already mirrored in the pdf
  36478. // Finally, return string
  36479. var result = '';
  36480. for (i = 0, ii = chars.length; i < ii; ++i) {
  36481. var ch = chars[i];
  36482. if (ch !== '<' && ch !== '>') {
  36483. result += ch;
  36484. }
  36485. }
  36486. return createBidiText(result, isLTR);
  36487. }
  36488. return bidi;
  36489. })();
  36490. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36491. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36492. /* Copyright 2014 Opera Software ASA
  36493. *
  36494. * Licensed under the Apache License, Version 2.0 (the "License");
  36495. * you may not use this file except in compliance with the License.
  36496. * You may obtain a copy of the License at
  36497. *
  36498. * http://www.apache.org/licenses/LICENSE-2.0
  36499. *
  36500. * Unless required by applicable law or agreed to in writing, software
  36501. * distributed under the License is distributed on an "AS IS" BASIS,
  36502. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36503. * See the License for the specific language governing permissions and
  36504. * limitations under the License.
  36505. *
  36506. *
  36507. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36508. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36509. */
  36510. /* globals Uint32ArrayView */
  36511. 'use strict';
  36512. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36513. // Workaround for missing math precison in JS.
  36514. var MASK_HIGH = 0xffff0000;
  36515. var MASK_LOW = 0xffff;
  36516. function MurmurHash3_64 (seed) {
  36517. var SEED = 0xc3d2e1f0;
  36518. this.h1 = seed ? seed & 0xffffffff : SEED;
  36519. this.h2 = seed ? seed & 0xffffffff : SEED;
  36520. }
  36521. var alwaysUseUint32ArrayView = false;
  36522. // old webkits have issues with non-aligned arrays
  36523. try {
  36524. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36525. } catch (e) {
  36526. alwaysUseUint32ArrayView = true;
  36527. }
  36528. MurmurHash3_64.prototype = {
  36529. update: function MurmurHash3_64_update(input) {
  36530. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36531. var i;
  36532. if (typeof input === 'string') {
  36533. var data = new Uint8Array(input.length * 2);
  36534. var length = 0;
  36535. for (i = 0; i < input.length; i++) {
  36536. var code = input.charCodeAt(i);
  36537. if (code <= 0xff) {
  36538. data[length++] = code;
  36539. }
  36540. else {
  36541. data[length++] = code >>> 8;
  36542. data[length++] = code & 0xff;
  36543. }
  36544. }
  36545. } else if (input instanceof Uint8Array) {
  36546. data = input;
  36547. length = data.length;
  36548. } else if (typeof input === 'object' && ('length' in input)) {
  36549. // processing regular arrays as well, e.g. for IE9
  36550. data = input;
  36551. length = data.length;
  36552. useUint32ArrayView = true;
  36553. } else {
  36554. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36555. 'Input must be a string or array.');
  36556. }
  36557. var blockCounts = length >> 2;
  36558. var tailLength = length - blockCounts * 4;
  36559. // we don't care about endianness here
  36560. var dataUint32 = useUint32ArrayView ?
  36561. new Uint32ArrayView(data, blockCounts) :
  36562. new Uint32Array(data.buffer, 0, blockCounts);
  36563. var k1 = 0;
  36564. var k2 = 0;
  36565. var h1 = this.h1;
  36566. var h2 = this.h2;
  36567. var C1 = 0xcc9e2d51;
  36568. var C2 = 0x1b873593;
  36569. var C1_LOW = C1 & MASK_LOW;
  36570. var C2_LOW = C2 & MASK_LOW;
  36571. for (i = 0; i < blockCounts; i++) {
  36572. if (i & 1) {
  36573. k1 = dataUint32[i];
  36574. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36575. k1 = k1 << 15 | k1 >>> 17;
  36576. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36577. h1 ^= k1;
  36578. h1 = h1 << 13 | h1 >>> 19;
  36579. h1 = h1 * 5 + 0xe6546b64;
  36580. } else {
  36581. k2 = dataUint32[i];
  36582. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36583. k2 = k2 << 15 | k2 >>> 17;
  36584. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36585. h2 ^= k2;
  36586. h2 = h2 << 13 | h2 >>> 19;
  36587. h2 = h2 * 5 + 0xe6546b64;
  36588. }
  36589. }
  36590. k1 = 0;
  36591. switch (tailLength) {
  36592. case 3:
  36593. k1 ^= data[blockCounts * 4 + 2] << 16;
  36594. /* falls through */
  36595. case 2:
  36596. k1 ^= data[blockCounts * 4 + 1] << 8;
  36597. /* falls through */
  36598. case 1:
  36599. k1 ^= data[blockCounts * 4];
  36600. /* falls through */
  36601. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36602. k1 = k1 << 15 | k1 >>> 17;
  36603. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36604. if (blockCounts & 1) {
  36605. h1 ^= k1;
  36606. } else {
  36607. h2 ^= k1;
  36608. }
  36609. }
  36610. this.h1 = h1;
  36611. this.h2 = h2;
  36612. return this;
  36613. },
  36614. hexdigest: function MurmurHash3_64_hexdigest () {
  36615. var h1 = this.h1;
  36616. var h2 = this.h2;
  36617. h1 ^= h2 >>> 1;
  36618. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36619. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36620. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36621. h1 ^= h2 >>> 1;
  36622. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36623. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36624. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36625. h1 ^= h2 >>> 1;
  36626. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36627. var hex = (arr[i] >>> 0).toString(16);
  36628. while (hex.length < 8) {
  36629. hex = '0' + hex;
  36630. }
  36631. str += hex;
  36632. }
  36633. return str;
  36634. }
  36635. };
  36636. return MurmurHash3_64;
  36637. })();
  36638. }).call((typeof window === 'undefined') ? this : window);
  36639. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36640. // workerSrc is not set -- using last script url to define default location
  36641. PDFJS.workerSrc = (function () {
  36642. 'use strict';
  36643. var scriptTagContainer = document.body ||
  36644. document.getElementsByTagName('head')[0];
  36645. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36646. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36647. })();
  36648. }