pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448
  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.811';
  24. PDFJS.build = 'a4cb67b';
  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. var length = bytes.length;
  420. var MAX_ARGUMENT_COUNT = 8192;
  421. if (length < MAX_ARGUMENT_COUNT) {
  422. return String.fromCharCode.apply(null, bytes);
  423. }
  424. var strBuf = [];
  425. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  426. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  427. var chunk = bytes.subarray(i, chunkEnd);
  428. strBuf.push(String.fromCharCode.apply(null, chunk));
  429. }
  430. return strBuf.join('');
  431. }
  432. function stringToBytes(str) {
  433. var length = str.length;
  434. var bytes = new Uint8Array(length);
  435. for (var i = 0; i < length; ++i) {
  436. bytes[i] = str.charCodeAt(i) & 0xFF;
  437. }
  438. return bytes;
  439. }
  440. function string32(value) {
  441. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  442. (value >> 8) & 0xff, value & 0xff);
  443. }
  444. function log2(x) {
  445. var n = 1, i = 0;
  446. while (x > n) {
  447. n <<= 1;
  448. i++;
  449. }
  450. return i;
  451. }
  452. function readInt8(data, start) {
  453. return (data[start] << 24) >> 24;
  454. }
  455. function readUint16(data, offset) {
  456. return (data[offset] << 8) | data[offset + 1];
  457. }
  458. function readUint32(data, offset) {
  459. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  460. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  461. }
  462. // Lazy test the endianness of the platform
  463. // NOTE: This will be 'true' for simulated TypedArrays
  464. function isLittleEndian() {
  465. var buffer8 = new Uint8Array(2);
  466. buffer8[0] = 1;
  467. var buffer16 = new Uint16Array(buffer8.buffer);
  468. return (buffer16[0] === 1);
  469. }
  470. Object.defineProperty(PDFJS, 'isLittleEndian', {
  471. configurable: true,
  472. get: function PDFJS_isLittleEndian() {
  473. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  474. }
  475. });
  476. // Lazy test if the userAgant support CanvasTypedArrays
  477. function hasCanvasTypedArrays() {
  478. var canvas = document.createElement('canvas');
  479. canvas.width = canvas.height = 1;
  480. var ctx = canvas.getContext('2d');
  481. var imageData = ctx.createImageData(1, 1);
  482. return (typeof imageData.data.buffer !== 'undefined');
  483. }
  484. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  485. configurable: true,
  486. get: function PDFJS_hasCanvasTypedArrays() {
  487. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  488. }
  489. });
  490. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  491. function Uint32ArrayView(buffer, length) {
  492. this.buffer = buffer;
  493. this.byteLength = buffer.length;
  494. this.length = length === undefined ? (this.byteLength >> 2) : length;
  495. ensureUint32ArrayViewProps(this.length);
  496. }
  497. Uint32ArrayView.prototype = Object.create(null);
  498. var uint32ArrayViewSetters = 0;
  499. function createUint32ArrayProp(index) {
  500. return {
  501. get: function () {
  502. var buffer = this.buffer, offset = index << 2;
  503. return (buffer[offset] | (buffer[offset + 1] << 8) |
  504. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  505. },
  506. set: function (value) {
  507. var buffer = this.buffer, offset = index << 2;
  508. buffer[offset] = value & 255;
  509. buffer[offset + 1] = (value >> 8) & 255;
  510. buffer[offset + 2] = (value >> 16) & 255;
  511. buffer[offset + 3] = (value >>> 24) & 255;
  512. }
  513. };
  514. }
  515. function ensureUint32ArrayViewProps(length) {
  516. while (uint32ArrayViewSetters < length) {
  517. Object.defineProperty(Uint32ArrayView.prototype,
  518. uint32ArrayViewSetters,
  519. createUint32ArrayProp(uint32ArrayViewSetters));
  520. uint32ArrayViewSetters++;
  521. }
  522. }
  523. return Uint32ArrayView;
  524. })();
  525. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  526. var Util = PDFJS.Util = (function UtilClosure() {
  527. function Util() {}
  528. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  529. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  530. // creating many intermediate strings.
  531. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  532. rgbBuf[1] = rgb[0];
  533. rgbBuf[3] = rgb[1];
  534. rgbBuf[5] = rgb[2];
  535. return rgbBuf.join('');
  536. };
  537. // Concatenates two transformation matrices together and returns the result.
  538. Util.transform = function Util_transform(m1, m2) {
  539. return [
  540. m1[0] * m2[0] + m1[2] * m2[1],
  541. m1[1] * m2[0] + m1[3] * m2[1],
  542. m1[0] * m2[2] + m1[2] * m2[3],
  543. m1[1] * m2[2] + m1[3] * m2[3],
  544. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  545. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  546. ];
  547. };
  548. // For 2d affine transforms
  549. Util.applyTransform = function Util_applyTransform(p, m) {
  550. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  551. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  552. return [xt, yt];
  553. };
  554. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  555. var d = m[0] * m[3] - m[1] * m[2];
  556. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  557. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  558. return [xt, yt];
  559. };
  560. // Applies the transform to the rectangle and finds the minimum axially
  561. // aligned bounding box.
  562. Util.getAxialAlignedBoundingBox =
  563. function Util_getAxialAlignedBoundingBox(r, m) {
  564. var p1 = Util.applyTransform(r, m);
  565. var p2 = Util.applyTransform(r.slice(2, 4), m);
  566. var p3 = Util.applyTransform([r[0], r[3]], m);
  567. var p4 = Util.applyTransform([r[2], r[1]], m);
  568. return [
  569. Math.min(p1[0], p2[0], p3[0], p4[0]),
  570. Math.min(p1[1], p2[1], p3[1], p4[1]),
  571. Math.max(p1[0], p2[0], p3[0], p4[0]),
  572. Math.max(p1[1], p2[1], p3[1], p4[1])
  573. ];
  574. };
  575. Util.inverseTransform = function Util_inverseTransform(m) {
  576. var d = m[0] * m[3] - m[1] * m[2];
  577. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  578. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  579. };
  580. // Apply a generic 3d matrix M on a 3-vector v:
  581. // | a b c | | X |
  582. // | d e f | x | Y |
  583. // | g h i | | Z |
  584. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  585. // with v as [X,Y,Z]
  586. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  587. return [
  588. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  589. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  590. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  591. ];
  592. };
  593. // This calculation uses Singular Value Decomposition.
  594. // The SVD can be represented with formula A = USV. We are interested in the
  595. // matrix S here because it represents the scale values.
  596. Util.singularValueDecompose2dScale =
  597. function Util_singularValueDecompose2dScale(m) {
  598. var transpose = [m[0], m[2], m[1], m[3]];
  599. // Multiply matrix m with its transpose.
  600. var a = m[0] * transpose[0] + m[1] * transpose[2];
  601. var b = m[0] * transpose[1] + m[1] * transpose[3];
  602. var c = m[2] * transpose[0] + m[3] * transpose[2];
  603. var d = m[2] * transpose[1] + m[3] * transpose[3];
  604. // Solve the second degree polynomial to get roots.
  605. var first = (a + d) / 2;
  606. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  607. var sx = first + second || 1;
  608. var sy = first - second || 1;
  609. // Scale values are the square roots of the eigenvalues.
  610. return [Math.sqrt(sx), Math.sqrt(sy)];
  611. };
  612. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  613. // For coordinate systems whose origin lies in the bottom-left, this
  614. // means normalization to (BL,TR) ordering. For systems with origin in the
  615. // top-left, this means (TL,BR) ordering.
  616. Util.normalizeRect = function Util_normalizeRect(rect) {
  617. var r = rect.slice(0); // clone rect
  618. if (rect[0] > rect[2]) {
  619. r[0] = rect[2];
  620. r[2] = rect[0];
  621. }
  622. if (rect[1] > rect[3]) {
  623. r[1] = rect[3];
  624. r[3] = rect[1];
  625. }
  626. return r;
  627. };
  628. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  629. // intersection of rect1 and rect2. If no intersection, returns 'false'
  630. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  631. Util.intersect = function Util_intersect(rect1, rect2) {
  632. function compare(a, b) {
  633. return a - b;
  634. }
  635. // Order points along the axes
  636. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  637. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  638. result = [];
  639. rect1 = Util.normalizeRect(rect1);
  640. rect2 = Util.normalizeRect(rect2);
  641. // X: first and second points belong to different rectangles?
  642. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  643. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  644. // Intersection must be between second and third points
  645. result[0] = orderedX[1];
  646. result[2] = orderedX[2];
  647. } else {
  648. return false;
  649. }
  650. // Y: first and second points belong to different rectangles?
  651. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  652. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  653. // Intersection must be between second and third points
  654. result[1] = orderedY[1];
  655. result[3] = orderedY[2];
  656. } else {
  657. return false;
  658. }
  659. return result;
  660. };
  661. Util.sign = function Util_sign(num) {
  662. return num < 0 ? -1 : 1;
  663. };
  664. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  665. Array.prototype.push.apply(arr1, arr2);
  666. };
  667. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  668. Array.prototype.unshift.apply(arr1, arr2);
  669. };
  670. Util.extendObj = function extendObj(obj1, obj2) {
  671. for (var key in obj2) {
  672. obj1[key] = obj2[key];
  673. }
  674. };
  675. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  676. name) {
  677. while (dict && !dict.has(name)) {
  678. dict = dict.get('Parent');
  679. }
  680. if (!dict) {
  681. return null;
  682. }
  683. return dict.get(name);
  684. };
  685. Util.inherit = function Util_inherit(sub, base, prototype) {
  686. sub.prototype = Object.create(base.prototype);
  687. sub.prototype.constructor = sub;
  688. for (var prop in prototype) {
  689. sub.prototype[prop] = prototype[prop];
  690. }
  691. };
  692. Util.loadScript = function Util_loadScript(src, callback) {
  693. var script = document.createElement('script');
  694. var loaded = false;
  695. script.setAttribute('src', src);
  696. if (callback) {
  697. script.onload = function() {
  698. if (!loaded) {
  699. callback();
  700. }
  701. loaded = true;
  702. };
  703. }
  704. document.getElementsByTagName('head')[0].appendChild(script);
  705. };
  706. return Util;
  707. })();
  708. /**
  709. * PDF page viewport created based on scale, rotation and offset.
  710. * @class
  711. * @alias PDFJS.PageViewport
  712. */
  713. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  714. /**
  715. * @constructor
  716. * @private
  717. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  718. * @param scale {number} scale of the viewport.
  719. * @param rotation {number} rotations of the viewport in degrees.
  720. * @param offsetX {number} offset X
  721. * @param offsetY {number} offset Y
  722. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  723. */
  724. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  725. this.viewBox = viewBox;
  726. this.scale = scale;
  727. this.rotation = rotation;
  728. this.offsetX = offsetX;
  729. this.offsetY = offsetY;
  730. // creating transform to convert pdf coordinate system to the normal
  731. // canvas like coordinates taking in account scale and rotation
  732. var centerX = (viewBox[2] + viewBox[0]) / 2;
  733. var centerY = (viewBox[3] + viewBox[1]) / 2;
  734. var rotateA, rotateB, rotateC, rotateD;
  735. rotation = rotation % 360;
  736. rotation = rotation < 0 ? rotation + 360 : rotation;
  737. switch (rotation) {
  738. case 180:
  739. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  740. break;
  741. case 90:
  742. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  743. break;
  744. case 270:
  745. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  746. break;
  747. //case 0:
  748. default:
  749. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  750. break;
  751. }
  752. if (dontFlip) {
  753. rotateC = -rotateC; rotateD = -rotateD;
  754. }
  755. var offsetCanvasX, offsetCanvasY;
  756. var width, height;
  757. if (rotateA === 0) {
  758. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  759. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  760. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  761. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  762. } else {
  763. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  765. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  766. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  767. }
  768. // creating transform for the following operations:
  769. // translate(-centerX, -centerY), rotate and flip vertically,
  770. // scale, and translate(offsetCanvasX, offsetCanvasY)
  771. this.transform = [
  772. rotateA * scale,
  773. rotateB * scale,
  774. rotateC * scale,
  775. rotateD * scale,
  776. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  777. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  778. ];
  779. this.width = width;
  780. this.height = height;
  781. this.fontScale = scale;
  782. }
  783. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  784. /**
  785. * Clones viewport with additional properties.
  786. * @param args {Object} (optional) If specified, may contain the 'scale' or
  787. * 'rotation' properties to override the corresponding properties in
  788. * the cloned viewport.
  789. * @returns {PDFJS.PageViewport} Cloned viewport.
  790. */
  791. clone: function PageViewPort_clone(args) {
  792. args = args || {};
  793. var scale = 'scale' in args ? args.scale : this.scale;
  794. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  795. return new PageViewport(this.viewBox.slice(), scale, rotation,
  796. this.offsetX, this.offsetY, args.dontFlip);
  797. },
  798. /**
  799. * Converts PDF point to the viewport coordinates. For examples, useful for
  800. * converting PDF location into canvas pixel coordinates.
  801. * @param x {number} X coordinate.
  802. * @param y {number} Y coordinate.
  803. * @returns {Object} Object that contains 'x' and 'y' properties of the
  804. * point in the viewport coordinate space.
  805. * @see {@link convertToPdfPoint}
  806. * @see {@link convertToViewportRectangle}
  807. */
  808. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  809. return Util.applyTransform([x, y], this.transform);
  810. },
  811. /**
  812. * Converts PDF rectangle to the viewport coordinates.
  813. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  814. * @returns {Array} Contains corresponding coordinates of the rectangle
  815. * in the viewport coordinate space.
  816. * @see {@link convertToViewportPoint}
  817. */
  818. convertToViewportRectangle:
  819. function PageViewport_convertToViewportRectangle(rect) {
  820. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  821. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  822. return [tl[0], tl[1], br[0], br[1]];
  823. },
  824. /**
  825. * Converts viewport coordinates to the PDF location. For examples, useful
  826. * for converting canvas pixel location into PDF one.
  827. * @param x {number} X coordinate.
  828. * @param y {number} Y coordinate.
  829. * @returns {Object} Object that contains 'x' and 'y' properties of the
  830. * point in the PDF coordinate space.
  831. * @see {@link convertToViewportPoint}
  832. */
  833. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  834. return Util.applyInverseTransform([x, y], this.transform);
  835. }
  836. };
  837. return PageViewport;
  838. })();
  839. var PDFStringTranslateTable = [
  840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  841. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  844. 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,
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  846. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  847. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  848. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  849. ];
  850. function stringToPDFString(str) {
  851. var i, n = str.length, strBuf = [];
  852. if (str[0] === '\xFE' && str[1] === '\xFF') {
  853. // UTF16BE BOM
  854. for (i = 2; i < n; i += 2) {
  855. strBuf.push(String.fromCharCode(
  856. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  857. }
  858. } else {
  859. for (i = 0; i < n; ++i) {
  860. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  861. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  862. }
  863. }
  864. return strBuf.join('');
  865. }
  866. function stringToUTF8String(str) {
  867. return decodeURIComponent(escape(str));
  868. }
  869. function isEmptyObj(obj) {
  870. for (var key in obj) {
  871. return false;
  872. }
  873. return true;
  874. }
  875. function isBool(v) {
  876. return typeof v === 'boolean';
  877. }
  878. function isInt(v) {
  879. return typeof v === 'number' && ((v | 0) === v);
  880. }
  881. function isNum(v) {
  882. return typeof v === 'number';
  883. }
  884. function isString(v) {
  885. return typeof v === 'string';
  886. }
  887. function isNull(v) {
  888. return v === null;
  889. }
  890. function isName(v) {
  891. return v instanceof Name;
  892. }
  893. function isCmd(v, cmd) {
  894. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  895. }
  896. function isDict(v, type) {
  897. if (!(v instanceof Dict)) {
  898. return false;
  899. }
  900. if (!type) {
  901. return true;
  902. }
  903. var dictType = v.get('Type');
  904. return isName(dictType) && dictType.name === type;
  905. }
  906. function isArray(v) {
  907. return v instanceof Array;
  908. }
  909. function isStream(v) {
  910. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  911. }
  912. function isArrayBuffer(v) {
  913. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  914. }
  915. function isRef(v) {
  916. return v instanceof Ref;
  917. }
  918. /**
  919. * Promise Capability object.
  920. *
  921. * @typedef {Object} PromiseCapability
  922. * @property {Promise} promise - A promise object.
  923. * @property {function} resolve - Fullfills the promise.
  924. * @property {function} reject - Rejects the promise.
  925. */
  926. /**
  927. * Creates a promise capability object.
  928. * @alias PDFJS.createPromiseCapability
  929. *
  930. * @return {PromiseCapability} A capability object contains:
  931. * - a Promise, resolve and reject methods.
  932. */
  933. function createPromiseCapability() {
  934. var capability = {};
  935. capability.promise = new Promise(function (resolve, reject) {
  936. capability.resolve = resolve;
  937. capability.reject = reject;
  938. });
  939. return capability;
  940. }
  941. PDFJS.createPromiseCapability = createPromiseCapability;
  942. /**
  943. * Polyfill for Promises:
  944. * The following promise implementation tries to generally implement the
  945. * Promise/A+ spec. Some notable differences from other promise libaries are:
  946. * - There currently isn't a seperate deferred and promise object.
  947. * - Unhandled rejections eventually show an error if they aren't handled.
  948. *
  949. * Based off of the work in:
  950. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  951. */
  952. (function PromiseClosure() {
  953. if (globalScope.Promise) {
  954. // Promises existing in the DOM/Worker, checking presence of all/resolve
  955. if (typeof globalScope.Promise.all !== 'function') {
  956. globalScope.Promise.all = function (iterable) {
  957. var count = 0, results = [], resolve, reject;
  958. var promise = new globalScope.Promise(function (resolve_, reject_) {
  959. resolve = resolve_;
  960. reject = reject_;
  961. });
  962. iterable.forEach(function (p, i) {
  963. count++;
  964. p.then(function (result) {
  965. results[i] = result;
  966. count--;
  967. if (count === 0) {
  968. resolve(results);
  969. }
  970. }, reject);
  971. });
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. return promise;
  976. };
  977. }
  978. if (typeof globalScope.Promise.resolve !== 'function') {
  979. globalScope.Promise.resolve = function (value) {
  980. return new globalScope.Promise(function (resolve) { resolve(value); });
  981. };
  982. }
  983. if (typeof globalScope.Promise.reject !== 'function') {
  984. globalScope.Promise.reject = function (reason) {
  985. return new globalScope.Promise(function (resolve, reject) {
  986. reject(reason);
  987. });
  988. };
  989. }
  990. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  991. globalScope.Promise.prototype.catch = function (onReject) {
  992. return globalScope.Promise.prototype.then(undefined, onReject);
  993. };
  994. }
  995. return;
  996. }
  997. var STATUS_PENDING = 0;
  998. var STATUS_RESOLVED = 1;
  999. var STATUS_REJECTED = 2;
  1000. // In an attempt to avoid silent exceptions, unhandled rejections are
  1001. // tracked and if they aren't handled in a certain amount of time an
  1002. // error is logged.
  1003. var REJECTION_TIMEOUT = 500;
  1004. var HandlerManager = {
  1005. handlers: [],
  1006. running: false,
  1007. unhandledRejections: [],
  1008. pendingRejectionCheck: false,
  1009. scheduleHandlers: function scheduleHandlers(promise) {
  1010. if (promise._status === STATUS_PENDING) {
  1011. return;
  1012. }
  1013. this.handlers = this.handlers.concat(promise._handlers);
  1014. promise._handlers = [];
  1015. if (this.running) {
  1016. return;
  1017. }
  1018. this.running = true;
  1019. setTimeout(this.runHandlers.bind(this), 0);
  1020. },
  1021. runHandlers: function runHandlers() {
  1022. var RUN_TIMEOUT = 1; // ms
  1023. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1024. while (this.handlers.length > 0) {
  1025. var handler = this.handlers.shift();
  1026. var nextStatus = handler.thisPromise._status;
  1027. var nextValue = handler.thisPromise._value;
  1028. try {
  1029. if (nextStatus === STATUS_RESOLVED) {
  1030. if (typeof handler.onResolve === 'function') {
  1031. nextValue = handler.onResolve(nextValue);
  1032. }
  1033. } else if (typeof handler.onReject === 'function') {
  1034. nextValue = handler.onReject(nextValue);
  1035. nextStatus = STATUS_RESOLVED;
  1036. if (handler.thisPromise._unhandledRejection) {
  1037. this.removeUnhandeledRejection(handler.thisPromise);
  1038. }
  1039. }
  1040. } catch (ex) {
  1041. nextStatus = STATUS_REJECTED;
  1042. nextValue = ex;
  1043. }
  1044. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1045. if (Date.now() >= timeoutAt) {
  1046. break;
  1047. }
  1048. }
  1049. if (this.handlers.length > 0) {
  1050. setTimeout(this.runHandlers.bind(this), 0);
  1051. return;
  1052. }
  1053. this.running = false;
  1054. },
  1055. addUnhandledRejection: function addUnhandledRejection(promise) {
  1056. this.unhandledRejections.push({
  1057. promise: promise,
  1058. time: Date.now()
  1059. });
  1060. this.scheduleRejectionCheck();
  1061. },
  1062. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1063. promise._unhandledRejection = false;
  1064. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1065. if (this.unhandledRejections[i].promise === promise) {
  1066. this.unhandledRejections.splice(i);
  1067. i--;
  1068. }
  1069. }
  1070. },
  1071. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1072. if (this.pendingRejectionCheck) {
  1073. return;
  1074. }
  1075. this.pendingRejectionCheck = true;
  1076. setTimeout(function rejectionCheck() {
  1077. this.pendingRejectionCheck = false;
  1078. var now = Date.now();
  1079. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1080. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1081. var unhandled = this.unhandledRejections[i].promise._value;
  1082. var msg = 'Unhandled rejection: ' + unhandled;
  1083. if (unhandled.stack) {
  1084. msg += '\n' + unhandled.stack;
  1085. }
  1086. warn(msg);
  1087. this.unhandledRejections.splice(i);
  1088. i--;
  1089. }
  1090. }
  1091. if (this.unhandledRejections.length) {
  1092. this.scheduleRejectionCheck();
  1093. }
  1094. }.bind(this), REJECTION_TIMEOUT);
  1095. }
  1096. };
  1097. function Promise(resolver) {
  1098. this._status = STATUS_PENDING;
  1099. this._handlers = [];
  1100. try {
  1101. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1102. } catch (e) {
  1103. this._reject(e);
  1104. }
  1105. }
  1106. /**
  1107. * Builds a promise that is resolved when all the passed in promises are
  1108. * resolved.
  1109. * @param {array} array of data and/or promises to wait for.
  1110. * @return {Promise} New dependant promise.
  1111. */
  1112. Promise.all = function Promise_all(promises) {
  1113. var resolveAll, rejectAll;
  1114. var deferred = new Promise(function (resolve, reject) {
  1115. resolveAll = resolve;
  1116. rejectAll = reject;
  1117. });
  1118. var unresolved = promises.length;
  1119. var results = [];
  1120. if (unresolved === 0) {
  1121. resolveAll(results);
  1122. return deferred;
  1123. }
  1124. function reject(reason) {
  1125. if (deferred._status === STATUS_REJECTED) {
  1126. return;
  1127. }
  1128. results = [];
  1129. rejectAll(reason);
  1130. }
  1131. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1132. var promise = promises[i];
  1133. var resolve = (function(i) {
  1134. return function(value) {
  1135. if (deferred._status === STATUS_REJECTED) {
  1136. return;
  1137. }
  1138. results[i] = value;
  1139. unresolved--;
  1140. if (unresolved === 0) {
  1141. resolveAll(results);
  1142. }
  1143. };
  1144. })(i);
  1145. if (Promise.isPromise(promise)) {
  1146. promise.then(resolve, reject);
  1147. } else {
  1148. resolve(promise);
  1149. }
  1150. }
  1151. return deferred;
  1152. };
  1153. /**
  1154. * Checks if the value is likely a promise (has a 'then' function).
  1155. * @return {boolean} true if value is thenable
  1156. */
  1157. Promise.isPromise = function Promise_isPromise(value) {
  1158. return value && typeof value.then === 'function';
  1159. };
  1160. /**
  1161. * Creates resolved promise
  1162. * @param value resolve value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.resolve = function Promise_resolve(value) {
  1166. return new Promise(function (resolve) { resolve(value); });
  1167. };
  1168. /**
  1169. * Creates rejected promise
  1170. * @param reason rejection value
  1171. * @returns {Promise}
  1172. */
  1173. Promise.reject = function Promise_reject(reason) {
  1174. return new Promise(function (resolve, reject) { reject(reason); });
  1175. };
  1176. Promise.prototype = {
  1177. _status: null,
  1178. _value: null,
  1179. _handlers: null,
  1180. _unhandledRejection: null,
  1181. _updateStatus: function Promise__updateStatus(status, value) {
  1182. if (this._status === STATUS_RESOLVED ||
  1183. this._status === STATUS_REJECTED) {
  1184. return;
  1185. }
  1186. if (status === STATUS_RESOLVED &&
  1187. Promise.isPromise(value)) {
  1188. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1189. this._updateStatus.bind(this, STATUS_REJECTED));
  1190. return;
  1191. }
  1192. this._status = status;
  1193. this._value = value;
  1194. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1195. this._unhandledRejection = true;
  1196. HandlerManager.addUnhandledRejection(this);
  1197. }
  1198. HandlerManager.scheduleHandlers(this);
  1199. },
  1200. _resolve: function Promise_resolve(value) {
  1201. this._updateStatus(STATUS_RESOLVED, value);
  1202. },
  1203. _reject: function Promise_reject(reason) {
  1204. this._updateStatus(STATUS_REJECTED, reason);
  1205. },
  1206. then: function Promise_then(onResolve, onReject) {
  1207. var nextPromise = new Promise(function (resolve, reject) {
  1208. this.resolve = resolve;
  1209. this.reject = reject;
  1210. });
  1211. this._handlers.push({
  1212. thisPromise: this,
  1213. onResolve: onResolve,
  1214. onReject: onReject,
  1215. nextPromise: nextPromise
  1216. });
  1217. HandlerManager.scheduleHandlers(this);
  1218. return nextPromise;
  1219. },
  1220. catch: function Promise_catch(onReject) {
  1221. return this.then(undefined, onReject);
  1222. }
  1223. };
  1224. globalScope.Promise = Promise;
  1225. })();
  1226. var StatTimer = (function StatTimerClosure() {
  1227. function rpad(str, pad, length) {
  1228. while (str.length < length) {
  1229. str += pad;
  1230. }
  1231. return str;
  1232. }
  1233. function StatTimer() {
  1234. this.started = {};
  1235. this.times = [];
  1236. this.enabled = true;
  1237. }
  1238. StatTimer.prototype = {
  1239. time: function StatTimer_time(name) {
  1240. if (!this.enabled) {
  1241. return;
  1242. }
  1243. if (name in this.started) {
  1244. warn('Timer is already running for ' + name);
  1245. }
  1246. this.started[name] = Date.now();
  1247. },
  1248. timeEnd: function StatTimer_timeEnd(name) {
  1249. if (!this.enabled) {
  1250. return;
  1251. }
  1252. if (!(name in this.started)) {
  1253. warn('Timer has not been started for ' + name);
  1254. }
  1255. this.times.push({
  1256. 'name': name,
  1257. 'start': this.started[name],
  1258. 'end': Date.now()
  1259. });
  1260. // Remove timer from started so it can be called again.
  1261. delete this.started[name];
  1262. },
  1263. toString: function StatTimer_toString() {
  1264. var i, ii;
  1265. var times = this.times;
  1266. var out = '';
  1267. // Find the longest name for padding purposes.
  1268. var longest = 0;
  1269. for (i = 0, ii = times.length; i < ii; ++i) {
  1270. var name = times[i]['name'];
  1271. if (name.length > longest) {
  1272. longest = name.length;
  1273. }
  1274. }
  1275. for (i = 0, ii = times.length; i < ii; ++i) {
  1276. var span = times[i];
  1277. var duration = span.end - span.start;
  1278. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1279. }
  1280. return out;
  1281. }
  1282. };
  1283. return StatTimer;
  1284. })();
  1285. PDFJS.createBlob = function createBlob(data, contentType) {
  1286. if (typeof Blob !== 'undefined') {
  1287. return new Blob([data], { type: contentType });
  1288. }
  1289. // Blob builder is deprecated in FF14 and removed in FF18.
  1290. var bb = new MozBlobBuilder();
  1291. bb.append(data);
  1292. return bb.getBlob(contentType);
  1293. };
  1294. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1295. // Blob/createObjectURL is not available, falling back to data schema.
  1296. var digits =
  1297. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1298. return function createObjectURL(data, contentType) {
  1299. if (!PDFJS.disableCreateObjectURL &&
  1300. typeof URL !== 'undefined' && URL.createObjectURL) {
  1301. var blob = PDFJS.createBlob(data, contentType);
  1302. return URL.createObjectURL(blob);
  1303. }
  1304. var buffer = 'data:' + contentType + ';base64,';
  1305. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1306. var b1 = data[i] & 0xFF;
  1307. var b2 = data[i + 1] & 0xFF;
  1308. var b3 = data[i + 2] & 0xFF;
  1309. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1310. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1311. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1312. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1313. }
  1314. return buffer;
  1315. };
  1316. })();
  1317. function MessageHandler(name, comObj) {
  1318. this.name = name;
  1319. this.comObj = comObj;
  1320. this.callbackIndex = 1;
  1321. this.postMessageTransfers = true;
  1322. var callbacksCapabilities = this.callbacksCapabilities = {};
  1323. var ah = this.actionHandler = {};
  1324. ah['console_log'] = [function ahConsoleLog(data) {
  1325. console.log.apply(console, data);
  1326. }];
  1327. ah['console_error'] = [function ahConsoleError(data) {
  1328. console.error.apply(console, data);
  1329. }];
  1330. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1331. UnsupportedManager.notify(data);
  1332. }];
  1333. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1334. var data = event.data;
  1335. if (data.isReply) {
  1336. var callbackId = data.callbackId;
  1337. if (data.callbackId in callbacksCapabilities) {
  1338. var callback = callbacksCapabilities[callbackId];
  1339. delete callbacksCapabilities[callbackId];
  1340. if ('error' in data) {
  1341. callback.reject(data.error);
  1342. } else {
  1343. callback.resolve(data.data);
  1344. }
  1345. } else {
  1346. error('Cannot resolve callback ' + callbackId);
  1347. }
  1348. } else if (data.action in ah) {
  1349. var action = ah[data.action];
  1350. if (data.callbackId) {
  1351. Promise.resolve().then(function () {
  1352. return action[0].call(action[1], data.data);
  1353. }).then(function (result) {
  1354. comObj.postMessage({
  1355. isReply: true,
  1356. callbackId: data.callbackId,
  1357. data: result
  1358. });
  1359. }, function (reason) {
  1360. comObj.postMessage({
  1361. isReply: true,
  1362. callbackId: data.callbackId,
  1363. error: reason
  1364. });
  1365. });
  1366. } else {
  1367. action[0].call(action[1], data.data);
  1368. }
  1369. } else {
  1370. error('Unknown action from worker: ' + data.action);
  1371. }
  1372. };
  1373. }
  1374. MessageHandler.prototype = {
  1375. on: function messageHandlerOn(actionName, handler, scope) {
  1376. var ah = this.actionHandler;
  1377. if (ah[actionName]) {
  1378. error('There is already an actionName called "' + actionName + '"');
  1379. }
  1380. ah[actionName] = [handler, scope];
  1381. },
  1382. /**
  1383. * Sends a message to the comObj to invoke the action with the supplied data.
  1384. * @param {String} actionName Action to call.
  1385. * @param {JSON} data JSON data to send.
  1386. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1387. */
  1388. send: function messageHandlerSend(actionName, data, transfers) {
  1389. var message = {
  1390. action: actionName,
  1391. data: data
  1392. };
  1393. this.postMessage(message, transfers);
  1394. },
  1395. /**
  1396. * Sends a message to the comObj to invoke the action with the supplied data.
  1397. * Expects that other side will callback with the response.
  1398. * @param {String} actionName Action to call.
  1399. * @param {JSON} data JSON data to send.
  1400. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1401. * @returns {Promise} Promise to be resolved with response data.
  1402. */
  1403. sendWithPromise:
  1404. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1405. var callbackId = this.callbackIndex++;
  1406. var message = {
  1407. action: actionName,
  1408. data: data,
  1409. callbackId: callbackId
  1410. };
  1411. var capability = createPromiseCapability();
  1412. this.callbacksCapabilities[callbackId] = capability;
  1413. try {
  1414. this.postMessage(message, transfers);
  1415. } catch (e) {
  1416. capability.reject(e);
  1417. }
  1418. return capability.promise;
  1419. },
  1420. /**
  1421. * Sends raw message to the comObj.
  1422. * @private
  1423. * @param message {Object} Raw message.
  1424. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1425. */
  1426. postMessage: function (message, transfers) {
  1427. if (transfers && this.postMessageTransfers) {
  1428. this.comObj.postMessage(message, transfers);
  1429. } else {
  1430. this.comObj.postMessage(message);
  1431. }
  1432. }
  1433. };
  1434. function loadJpegStream(id, imageUrl, objs) {
  1435. var img = new Image();
  1436. img.onload = (function loadJpegStream_onloadClosure() {
  1437. objs.resolve(id, img);
  1438. });
  1439. img.onerror = (function loadJpegStream_onerrorClosure() {
  1440. objs.resolve(id, null);
  1441. warn('Error during JPEG image loading');
  1442. });
  1443. img.src = imageUrl;
  1444. }
  1445. var NetworkManager = (function NetworkManagerClosure() {
  1446. var OK_RESPONSE = 200;
  1447. var PARTIAL_CONTENT_RESPONSE = 206;
  1448. function NetworkManager(url, args) {
  1449. this.url = url;
  1450. args = args || {};
  1451. this.isHttp = /^https?:/i.test(url);
  1452. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1453. this.withCredentials = args.withCredentials || false;
  1454. this.getXhr = args.getXhr ||
  1455. function NetworkManager_getXhr() {
  1456. return new XMLHttpRequest();
  1457. };
  1458. this.currXhrId = 0;
  1459. this.pendingRequests = {};
  1460. this.loadedRequests = {};
  1461. }
  1462. function getArrayBuffer(xhr) {
  1463. var data = xhr.response;
  1464. if (typeof data !== 'string') {
  1465. return data;
  1466. }
  1467. var length = data.length;
  1468. var buffer = new Uint8Array(length);
  1469. for (var i = 0; i < length; i++) {
  1470. buffer[i] = data.charCodeAt(i) & 0xFF;
  1471. }
  1472. return buffer;
  1473. }
  1474. NetworkManager.prototype = {
  1475. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1476. var args = {
  1477. begin: begin,
  1478. end: end
  1479. };
  1480. for (var prop in listeners) {
  1481. args[prop] = listeners[prop];
  1482. }
  1483. return this.request(args);
  1484. },
  1485. requestFull: function NetworkManager_requestRange(listeners) {
  1486. return this.request(listeners);
  1487. },
  1488. request: function NetworkManager_requestRange(args) {
  1489. var xhr = this.getXhr();
  1490. var xhrId = this.currXhrId++;
  1491. var pendingRequest = this.pendingRequests[xhrId] = {
  1492. xhr: xhr
  1493. };
  1494. xhr.open('GET', this.url);
  1495. xhr.withCredentials = this.withCredentials;
  1496. for (var property in this.httpHeaders) {
  1497. var value = this.httpHeaders[property];
  1498. if (typeof value === 'undefined') {
  1499. continue;
  1500. }
  1501. xhr.setRequestHeader(property, value);
  1502. }
  1503. if (this.isHttp && 'begin' in args && 'end' in args) {
  1504. var rangeStr = args.begin + '-' + (args.end - 1);
  1505. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1506. pendingRequest.expectedStatus = 206;
  1507. } else {
  1508. pendingRequest.expectedStatus = 200;
  1509. }
  1510. xhr.responseType = 'arraybuffer';
  1511. if (args.onProgress) {
  1512. xhr.onprogress = args.onProgress;
  1513. }
  1514. if (args.onError) {
  1515. xhr.onerror = function(evt) {
  1516. args.onError(xhr.status);
  1517. };
  1518. }
  1519. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1520. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1521. pendingRequest.onDone = args.onDone;
  1522. pendingRequest.onError = args.onError;
  1523. xhr.send(null);
  1524. return xhrId;
  1525. },
  1526. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1527. var pendingRequest = this.pendingRequests[xhrId];
  1528. if (!pendingRequest) {
  1529. // Maybe abortRequest was called...
  1530. return;
  1531. }
  1532. var xhr = pendingRequest.xhr;
  1533. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1534. pendingRequest.onHeadersReceived();
  1535. delete pendingRequest.onHeadersReceived;
  1536. }
  1537. if (xhr.readyState !== 4) {
  1538. return;
  1539. }
  1540. if (!(xhrId in this.pendingRequests)) {
  1541. // The XHR request might have been aborted in onHeadersReceived()
  1542. // callback, in which case we should abort request
  1543. return;
  1544. }
  1545. delete this.pendingRequests[xhrId];
  1546. // success status == 0 can be on ftp, file and other protocols
  1547. if (xhr.status === 0 && this.isHttp) {
  1548. if (pendingRequest.onError) {
  1549. pendingRequest.onError(xhr.status);
  1550. }
  1551. return;
  1552. }
  1553. var xhrStatus = xhr.status || OK_RESPONSE;
  1554. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1555. // "A server MAY ignore the Range header". This means it's possible to
  1556. // get a 200 rather than a 206 response from a range request.
  1557. var ok_response_on_range_request =
  1558. xhrStatus === OK_RESPONSE &&
  1559. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1560. if (!ok_response_on_range_request &&
  1561. xhrStatus !== pendingRequest.expectedStatus) {
  1562. if (pendingRequest.onError) {
  1563. pendingRequest.onError(xhr.status);
  1564. }
  1565. return;
  1566. }
  1567. this.loadedRequests[xhrId] = true;
  1568. var chunk = getArrayBuffer(xhr);
  1569. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1570. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1571. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1572. var begin = parseInt(matches[1], 10);
  1573. pendingRequest.onDone({
  1574. begin: begin,
  1575. chunk: chunk
  1576. });
  1577. } else {
  1578. pendingRequest.onDone({
  1579. begin: 0,
  1580. chunk: chunk
  1581. });
  1582. }
  1583. },
  1584. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1585. for (var xhrId in this.pendingRequests) {
  1586. return true;
  1587. }
  1588. return false;
  1589. },
  1590. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1591. return this.pendingRequests[xhrId].xhr;
  1592. },
  1593. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1594. return xhrId in this.pendingRequests;
  1595. },
  1596. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1597. return xhrId in this.loadedRequests;
  1598. },
  1599. abortAllRequests: function NetworkManager_abortAllRequests() {
  1600. for (var xhrId in this.pendingRequests) {
  1601. this.abortRequest(xhrId | 0);
  1602. }
  1603. },
  1604. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1605. var xhr = this.pendingRequests[xhrId].xhr;
  1606. delete this.pendingRequests[xhrId];
  1607. xhr.abort();
  1608. }
  1609. };
  1610. return NetworkManager;
  1611. })();
  1612. var ChunkedStream = (function ChunkedStreamClosure() {
  1613. function ChunkedStream(length, chunkSize, manager) {
  1614. this.bytes = new Uint8Array(length);
  1615. this.start = 0;
  1616. this.pos = 0;
  1617. this.end = length;
  1618. this.chunkSize = chunkSize;
  1619. this.loadedChunks = [];
  1620. this.numChunksLoaded = 0;
  1621. this.numChunks = Math.ceil(length / chunkSize);
  1622. this.manager = manager;
  1623. this.initialDataLength = 0;
  1624. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1625. }
  1626. // required methods for a stream. if a particular stream does not
  1627. // implement these, an error should be thrown
  1628. ChunkedStream.prototype = {
  1629. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1630. var chunks = [];
  1631. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1632. if (!(chunk in this.loadedChunks)) {
  1633. chunks.push(chunk);
  1634. }
  1635. }
  1636. return chunks;
  1637. },
  1638. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1639. return [this];
  1640. },
  1641. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1642. return this.numChunksLoaded === this.numChunks;
  1643. },
  1644. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1645. var end = begin + chunk.byteLength;
  1646. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1647. // Using this.length is inaccurate here since this.start can be moved
  1648. // See ChunkedStream.moveStart()
  1649. var length = this.bytes.length;
  1650. assert(end % this.chunkSize === 0 || end === length,
  1651. 'Bad end offset: ' + end);
  1652. this.bytes.set(new Uint8Array(chunk), begin);
  1653. var chunkSize = this.chunkSize;
  1654. var beginChunk = Math.floor(begin / chunkSize);
  1655. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1656. var curChunk;
  1657. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1658. if (!(curChunk in this.loadedChunks)) {
  1659. this.loadedChunks[curChunk] = true;
  1660. ++this.numChunksLoaded;
  1661. }
  1662. }
  1663. },
  1664. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  1665. this.bytes.set(data);
  1666. this.initialDataLength = data.length;
  1667. var endChunk = (this.end === data.length ?
  1668. this.numChunks : Math.floor(data.length / this.chunkSize));
  1669. for (var i = 0; i < endChunk; i++) {
  1670. this.loadedChunks[i] = true;
  1671. ++this.numChunksLoaded;
  1672. }
  1673. },
  1674. ensureByte: function ChunkedStream_ensureByte(pos) {
  1675. var chunk = Math.floor(pos / this.chunkSize);
  1676. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1677. return;
  1678. }
  1679. if (!(chunk in this.loadedChunks)) {
  1680. throw new MissingDataException(pos, pos + 1);
  1681. }
  1682. this.lastSuccessfulEnsureByteChunk = chunk;
  1683. },
  1684. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1685. if (begin >= end) {
  1686. return;
  1687. }
  1688. if (end <= this.initialDataLength) {
  1689. return;
  1690. }
  1691. var chunkSize = this.chunkSize;
  1692. var beginChunk = Math.floor(begin / chunkSize);
  1693. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1694. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1695. if (!(chunk in this.loadedChunks)) {
  1696. throw new MissingDataException(begin, end);
  1697. }
  1698. }
  1699. },
  1700. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1701. var chunk, n;
  1702. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1703. if (!(chunk in this.loadedChunks)) {
  1704. return chunk;
  1705. }
  1706. }
  1707. // Wrap around to beginning
  1708. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1709. if (!(chunk in this.loadedChunks)) {
  1710. return chunk;
  1711. }
  1712. }
  1713. return null;
  1714. },
  1715. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1716. return chunk in this.loadedChunks;
  1717. },
  1718. get length() {
  1719. return this.end - this.start;
  1720. },
  1721. get isEmpty() {
  1722. return this.length === 0;
  1723. },
  1724. getByte: function ChunkedStream_getByte() {
  1725. var pos = this.pos;
  1726. if (pos >= this.end) {
  1727. return -1;
  1728. }
  1729. this.ensureByte(pos);
  1730. return this.bytes[this.pos++];
  1731. },
  1732. getUint16: function ChunkedStream_getUint16() {
  1733. var b0 = this.getByte();
  1734. var b1 = this.getByte();
  1735. return (b0 << 8) + b1;
  1736. },
  1737. getInt32: function ChunkedStream_getInt32() {
  1738. var b0 = this.getByte();
  1739. var b1 = this.getByte();
  1740. var b2 = this.getByte();
  1741. var b3 = this.getByte();
  1742. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1743. },
  1744. // returns subarray of original buffer
  1745. // should only be read
  1746. getBytes: function ChunkedStream_getBytes(length) {
  1747. var bytes = this.bytes;
  1748. var pos = this.pos;
  1749. var strEnd = this.end;
  1750. if (!length) {
  1751. this.ensureRange(pos, strEnd);
  1752. return bytes.subarray(pos, strEnd);
  1753. }
  1754. var end = pos + length;
  1755. if (end > strEnd) {
  1756. end = strEnd;
  1757. }
  1758. this.ensureRange(pos, end);
  1759. this.pos = end;
  1760. return bytes.subarray(pos, end);
  1761. },
  1762. peekByte: function ChunkedStream_peekByte() {
  1763. var peekedByte = this.getByte();
  1764. this.pos--;
  1765. return peekedByte;
  1766. },
  1767. peekBytes: function ChunkedStream_peekBytes(length) {
  1768. var bytes = this.getBytes(length);
  1769. this.pos -= bytes.length;
  1770. return bytes;
  1771. },
  1772. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1773. this.ensureRange(begin, end);
  1774. return this.bytes.subarray(begin, end);
  1775. },
  1776. skip: function ChunkedStream_skip(n) {
  1777. if (!n) {
  1778. n = 1;
  1779. }
  1780. this.pos += n;
  1781. },
  1782. reset: function ChunkedStream_reset() {
  1783. this.pos = this.start;
  1784. },
  1785. moveStart: function ChunkedStream_moveStart() {
  1786. this.start = this.pos;
  1787. },
  1788. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1789. this.ensureRange(start, start + length);
  1790. function ChunkedStreamSubstream() {}
  1791. ChunkedStreamSubstream.prototype = Object.create(this);
  1792. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1793. var chunkSize = this.chunkSize;
  1794. var beginChunk = Math.floor(this.start / chunkSize);
  1795. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1796. var missingChunks = [];
  1797. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1798. if (!(chunk in this.loadedChunks)) {
  1799. missingChunks.push(chunk);
  1800. }
  1801. }
  1802. return missingChunks;
  1803. };
  1804. var subStream = new ChunkedStreamSubstream();
  1805. subStream.pos = subStream.start = start;
  1806. subStream.end = start + length || this.end;
  1807. subStream.dict = dict;
  1808. return subStream;
  1809. },
  1810. isStream: true
  1811. };
  1812. return ChunkedStream;
  1813. })();
  1814. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1815. function ChunkedStreamManager(length, chunkSize, url, args) {
  1816. this.stream = new ChunkedStream(length, chunkSize, this);
  1817. this.length = length;
  1818. this.chunkSize = chunkSize;
  1819. this.url = url;
  1820. this.disableAutoFetch = args.disableAutoFetch;
  1821. var msgHandler = this.msgHandler = args.msgHandler;
  1822. if (args.chunkedViewerLoading) {
  1823. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1824. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1825. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1826. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1827. };
  1828. } else {
  1829. var getXhr = function getXhr() {
  1830. return new XMLHttpRequest();
  1831. };
  1832. this.networkManager = new NetworkManager(this.url, {
  1833. getXhr: getXhr,
  1834. httpHeaders: args.httpHeaders,
  1835. withCredentials: args.withCredentials
  1836. });
  1837. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1838. this.networkManager.requestRange(begin, end, {
  1839. onDone: this.onReceiveData.bind(this),
  1840. onProgress: this.onProgress.bind(this)
  1841. });
  1842. };
  1843. }
  1844. this.currRequestId = 0;
  1845. this.chunksNeededByRequest = {};
  1846. this.requestsByChunk = {};
  1847. this.callbacksByRequest = {};
  1848. this._loadedStreamCapability = createPromiseCapability();
  1849. if (args.initialData) {
  1850. this.setInitialData(args.initialData);
  1851. }
  1852. }
  1853. ChunkedStreamManager.prototype = {
  1854. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  1855. this.stream.onReceiveInitialData(data);
  1856. if (this.stream.allChunksLoaded()) {
  1857. this._loadedStreamCapability.resolve(this.stream);
  1858. } else if (this.msgHandler) {
  1859. this.msgHandler.send('DocProgress', {
  1860. loaded: data.length,
  1861. total: this.length
  1862. });
  1863. }
  1864. },
  1865. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1866. return this._loadedStreamCapability.promise;
  1867. },
  1868. // Get all the chunks that are not yet loaded and groups them into
  1869. // contiguous ranges to load in as few requests as possible
  1870. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1871. var missingChunks = this.stream.getMissingChunks();
  1872. this.requestChunks(missingChunks);
  1873. return this._loadedStreamCapability.promise;
  1874. },
  1875. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1876. callback) {
  1877. var requestId = this.currRequestId++;
  1878. var chunksNeeded;
  1879. var i, ii;
  1880. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1881. for (i = 0, ii = chunks.length; i < ii; i++) {
  1882. if (!this.stream.hasChunk(chunks[i])) {
  1883. chunksNeeded[chunks[i]] = true;
  1884. }
  1885. }
  1886. if (isEmptyObj(chunksNeeded)) {
  1887. if (callback) {
  1888. callback();
  1889. }
  1890. return;
  1891. }
  1892. this.callbacksByRequest[requestId] = callback;
  1893. var chunksToRequest = [];
  1894. for (var chunk in chunksNeeded) {
  1895. chunk = chunk | 0;
  1896. if (!(chunk in this.requestsByChunk)) {
  1897. this.requestsByChunk[chunk] = [];
  1898. chunksToRequest.push(chunk);
  1899. }
  1900. this.requestsByChunk[chunk].push(requestId);
  1901. }
  1902. if (!chunksToRequest.length) {
  1903. return;
  1904. }
  1905. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1906. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1907. var groupedChunk = groupedChunksToRequest[i];
  1908. var begin = groupedChunk.beginChunk * this.chunkSize;
  1909. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1910. this.sendRequest(begin, end);
  1911. }
  1912. },
  1913. getStream: function ChunkedStreamManager_getStream() {
  1914. return this.stream;
  1915. },
  1916. // Loads any chunks in the requested range that are not yet loaded
  1917. requestRange: function ChunkedStreamManager_requestRange(
  1918. begin, end, callback) {
  1919. end = Math.min(end, this.length);
  1920. var beginChunk = this.getBeginChunk(begin);
  1921. var endChunk = this.getEndChunk(end);
  1922. var chunks = [];
  1923. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1924. chunks.push(chunk);
  1925. }
  1926. this.requestChunks(chunks, callback);
  1927. },
  1928. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1929. callback) {
  1930. ranges = ranges || [];
  1931. var chunksToRequest = [];
  1932. for (var i = 0; i < ranges.length; i++) {
  1933. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1934. var endChunk = this.getEndChunk(ranges[i].end);
  1935. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1936. if (chunksToRequest.indexOf(chunk) < 0) {
  1937. chunksToRequest.push(chunk);
  1938. }
  1939. }
  1940. }
  1941. chunksToRequest.sort(function(a, b) { return a - b; });
  1942. this.requestChunks(chunksToRequest, callback);
  1943. },
  1944. // Groups a sorted array of chunks into as few continguous larger
  1945. // chunks as possible
  1946. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1947. var groupedChunks = [];
  1948. var beginChunk = -1;
  1949. var prevChunk = -1;
  1950. for (var i = 0; i < chunks.length; ++i) {
  1951. var chunk = chunks[i];
  1952. if (beginChunk < 0) {
  1953. beginChunk = chunk;
  1954. }
  1955. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1956. groupedChunks.push({ beginChunk: beginChunk,
  1957. endChunk: prevChunk + 1 });
  1958. beginChunk = chunk;
  1959. }
  1960. if (i + 1 === chunks.length) {
  1961. groupedChunks.push({ beginChunk: beginChunk,
  1962. endChunk: chunk + 1 });
  1963. }
  1964. prevChunk = chunk;
  1965. }
  1966. return groupedChunks;
  1967. },
  1968. onProgress: function ChunkedStreamManager_onProgress(args) {
  1969. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1970. args.loaded);
  1971. this.msgHandler.send('DocProgress', {
  1972. loaded: bytesLoaded,
  1973. total: this.length
  1974. });
  1975. },
  1976. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  1977. var chunk = args.chunk;
  1978. var begin = args.begin;
  1979. var end = begin + chunk.byteLength;
  1980. var beginChunk = this.getBeginChunk(begin);
  1981. var endChunk = this.getEndChunk(end);
  1982. this.stream.onReceiveData(begin, chunk);
  1983. if (this.stream.allChunksLoaded()) {
  1984. this._loadedStreamCapability.resolve(this.stream);
  1985. }
  1986. var loadedRequests = [];
  1987. var i, requestId;
  1988. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  1989. // The server might return more chunks than requested
  1990. var requestIds = this.requestsByChunk[chunk] || [];
  1991. delete this.requestsByChunk[chunk];
  1992. for (i = 0; i < requestIds.length; ++i) {
  1993. requestId = requestIds[i];
  1994. var chunksNeeded = this.chunksNeededByRequest[requestId];
  1995. if (chunk in chunksNeeded) {
  1996. delete chunksNeeded[chunk];
  1997. }
  1998. if (!isEmptyObj(chunksNeeded)) {
  1999. continue;
  2000. }
  2001. loadedRequests.push(requestId);
  2002. }
  2003. }
  2004. // If there are no pending requests, automatically fetch the next
  2005. // unfetched chunk of the PDF
  2006. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2007. var nextEmptyChunk;
  2008. if (this.stream.numChunksLoaded === 1) {
  2009. // This is a special optimization so that after fetching the first
  2010. // chunk, rather than fetching the second chunk, we fetch the last
  2011. // chunk.
  2012. var lastChunk = this.stream.numChunks - 1;
  2013. if (!this.stream.hasChunk(lastChunk)) {
  2014. nextEmptyChunk = lastChunk;
  2015. }
  2016. } else {
  2017. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2018. }
  2019. if (isInt(nextEmptyChunk)) {
  2020. this.requestChunks([nextEmptyChunk]);
  2021. }
  2022. }
  2023. for (i = 0; i < loadedRequests.length; ++i) {
  2024. requestId = loadedRequests[i];
  2025. var callback = this.callbacksByRequest[requestId];
  2026. delete this.callbacksByRequest[requestId];
  2027. if (callback) {
  2028. callback();
  2029. }
  2030. }
  2031. this.msgHandler.send('DocProgress', {
  2032. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2033. total: this.length
  2034. });
  2035. },
  2036. onError: function ChunkedStreamManager_onError(err) {
  2037. this._loadedStreamCapability.reject(err);
  2038. },
  2039. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2040. var chunk = Math.floor(begin / this.chunkSize);
  2041. return chunk;
  2042. },
  2043. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2044. if (end % this.chunkSize === 0) {
  2045. return end / this.chunkSize;
  2046. }
  2047. // 0 -> 0
  2048. // 1 -> 1
  2049. // 99 -> 1
  2050. // 100 -> 1
  2051. // 101 -> 2
  2052. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2053. return chunk;
  2054. }
  2055. };
  2056. return ChunkedStreamManager;
  2057. })();
  2058. // The maximum number of bytes fetched per range request
  2059. var RANGE_CHUNK_SIZE = 65536;
  2060. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2061. var BasePdfManager = (function BasePdfManagerClosure() {
  2062. function BasePdfManager() {
  2063. throw new Error('Cannot initialize BaseManagerManager');
  2064. }
  2065. BasePdfManager.prototype = {
  2066. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2067. throw new NotImplementedException();
  2068. },
  2069. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2070. return this.ensure(this.pdfDocument, prop, args);
  2071. },
  2072. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2073. return this.ensure(this.pdfDocument.xref, prop, args);
  2074. },
  2075. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2076. return this.ensure(this.pdfDocument.catalog, prop, args);
  2077. },
  2078. getPage: function BasePdfManager_pagePage(pageIndex) {
  2079. return this.pdfDocument.getPage(pageIndex);
  2080. },
  2081. cleanup: function BasePdfManager_cleanup() {
  2082. return this.pdfDocument.cleanup();
  2083. },
  2084. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2085. return new NotImplementedException();
  2086. },
  2087. requestRange: function BasePdfManager_ensure(begin, end) {
  2088. return new NotImplementedException();
  2089. },
  2090. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2091. return new NotImplementedException();
  2092. },
  2093. updatePassword: function BasePdfManager_updatePassword(password) {
  2094. this.pdfDocument.xref.password = this.password = password;
  2095. if (this._passwordChangedCapability) {
  2096. this._passwordChangedCapability.resolve();
  2097. }
  2098. },
  2099. passwordChanged: function BasePdfManager_passwordChanged() {
  2100. this._passwordChangedCapability = createPromiseCapability();
  2101. return this._passwordChangedCapability.promise;
  2102. },
  2103. terminate: function BasePdfManager_terminate() {
  2104. return new NotImplementedException();
  2105. }
  2106. };
  2107. return BasePdfManager;
  2108. })();
  2109. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2110. function LocalPdfManager(data, password) {
  2111. var stream = new Stream(data);
  2112. this.pdfDocument = new PDFDocument(this, stream, password);
  2113. this._loadedStreamCapability = createPromiseCapability();
  2114. this._loadedStreamCapability.resolve(stream);
  2115. }
  2116. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2117. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2118. LocalPdfManager.prototype.ensure =
  2119. function LocalPdfManager_ensure(obj, prop, args) {
  2120. return new Promise(function (resolve, reject) {
  2121. try {
  2122. var value = obj[prop];
  2123. var result;
  2124. if (typeof value === 'function') {
  2125. result = value.apply(obj, args);
  2126. } else {
  2127. result = value;
  2128. }
  2129. resolve(result);
  2130. } catch (e) {
  2131. reject(e);
  2132. }
  2133. });
  2134. };
  2135. LocalPdfManager.prototype.requestRange =
  2136. function LocalPdfManager_requestRange(begin, end) {
  2137. return Promise.resolve();
  2138. };
  2139. LocalPdfManager.prototype.requestLoadedStream =
  2140. function LocalPdfManager_requestLoadedStream() {
  2141. };
  2142. LocalPdfManager.prototype.onLoadedStream =
  2143. function LocalPdfManager_getLoadedStream() {
  2144. return this._loadedStreamCapability.promise;
  2145. };
  2146. LocalPdfManager.prototype.terminate =
  2147. function LocalPdfManager_terminate() {
  2148. return;
  2149. };
  2150. return LocalPdfManager;
  2151. })();
  2152. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2153. function NetworkPdfManager(args, msgHandler) {
  2154. this.msgHandler = msgHandler;
  2155. var params = {
  2156. msgHandler: msgHandler,
  2157. httpHeaders: args.httpHeaders,
  2158. withCredentials: args.withCredentials,
  2159. chunkedViewerLoading: args.chunkedViewerLoading,
  2160. disableAutoFetch: args.disableAutoFetch,
  2161. initialData: args.initialData
  2162. };
  2163. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2164. args.url, params);
  2165. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2166. args.password);
  2167. }
  2168. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2169. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2170. NetworkPdfManager.prototype.ensure =
  2171. function NetworkPdfManager_ensure(obj, prop, args) {
  2172. var pdfManager = this;
  2173. return new Promise(function (resolve, reject) {
  2174. function ensureHelper() {
  2175. try {
  2176. var result;
  2177. var value = obj[prop];
  2178. if (typeof value === 'function') {
  2179. result = value.apply(obj, args);
  2180. } else {
  2181. result = value;
  2182. }
  2183. resolve(result);
  2184. } catch(e) {
  2185. if (!(e instanceof MissingDataException)) {
  2186. reject(e);
  2187. return;
  2188. }
  2189. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2190. }
  2191. }
  2192. ensureHelper();
  2193. });
  2194. };
  2195. NetworkPdfManager.prototype.requestRange =
  2196. function NetworkPdfManager_requestRange(begin, end) {
  2197. return new Promise(function (resolve) {
  2198. this.streamManager.requestRange(begin, end, function() {
  2199. resolve();
  2200. });
  2201. }.bind(this));
  2202. };
  2203. NetworkPdfManager.prototype.requestLoadedStream =
  2204. function NetworkPdfManager_requestLoadedStream() {
  2205. this.streamManager.requestAllChunks();
  2206. };
  2207. NetworkPdfManager.prototype.onLoadedStream =
  2208. function NetworkPdfManager_getLoadedStream() {
  2209. return this.streamManager.onLoadedStream();
  2210. };
  2211. NetworkPdfManager.prototype.terminate =
  2212. function NetworkPdfManager_terminate() {
  2213. this.streamManager.networkManager.abortAllRequests();
  2214. };
  2215. return NetworkPdfManager;
  2216. })();
  2217. var Page = (function PageClosure() {
  2218. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2219. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2220. this.pdfManager = pdfManager;
  2221. this.pageIndex = pageIndex;
  2222. this.pageDict = pageDict;
  2223. this.xref = xref;
  2224. this.ref = ref;
  2225. this.fontCache = fontCache;
  2226. this.idCounters = {
  2227. obj: 0
  2228. };
  2229. this.resourcesPromise = null;
  2230. }
  2231. Page.prototype = {
  2232. getPageProp: function Page_getPageProp(key) {
  2233. return this.pageDict.get(key);
  2234. },
  2235. getInheritedPageProp: function Page_inheritPageProp(key) {
  2236. var dict = this.pageDict;
  2237. var value = dict.get(key);
  2238. while (value === undefined) {
  2239. dict = dict.get('Parent');
  2240. if (!dict) {
  2241. break;
  2242. }
  2243. value = dict.get(key);
  2244. }
  2245. return value;
  2246. },
  2247. get content() {
  2248. return this.getPageProp('Contents');
  2249. },
  2250. get resources() {
  2251. var value = this.getInheritedPageProp('Resources');
  2252. // For robustness: The spec states that a \Resources entry has to be
  2253. // present, but can be empty. Some document omit it still. In this case
  2254. // return an empty dictionary:
  2255. if (value === undefined) {
  2256. value = Dict.empty;
  2257. }
  2258. return shadow(this, 'resources', value);
  2259. },
  2260. get mediaBox() {
  2261. var obj = this.getInheritedPageProp('MediaBox');
  2262. // Reset invalid media box to letter size.
  2263. if (!isArray(obj) || obj.length !== 4) {
  2264. obj = LETTER_SIZE_MEDIABOX;
  2265. }
  2266. return shadow(this, 'mediaBox', obj);
  2267. },
  2268. get view() {
  2269. var mediaBox = this.mediaBox;
  2270. var cropBox = this.getInheritedPageProp('CropBox');
  2271. if (!isArray(cropBox) || cropBox.length !== 4) {
  2272. return shadow(this, 'view', mediaBox);
  2273. }
  2274. // From the spec, 6th ed., p.963:
  2275. // "The crop, bleed, trim, and art boxes should not ordinarily
  2276. // extend beyond the boundaries of the media box. If they do, they are
  2277. // effectively reduced to their intersection with the media box."
  2278. cropBox = Util.intersect(cropBox, mediaBox);
  2279. if (!cropBox) {
  2280. return shadow(this, 'view', mediaBox);
  2281. }
  2282. return shadow(this, 'view', cropBox);
  2283. },
  2284. get annotationRefs() {
  2285. return shadow(this, 'annotationRefs',
  2286. this.getInheritedPageProp('Annots'));
  2287. },
  2288. get rotate() {
  2289. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2290. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2291. if (rotate % 90 !== 0) {
  2292. rotate = 0;
  2293. } else if (rotate >= 360) {
  2294. rotate = rotate % 360;
  2295. } else if (rotate < 0) {
  2296. // The spec doesn't cover negatives, assume its counterclockwise
  2297. // rotation. The following is the other implementation of modulo.
  2298. rotate = ((rotate % 360) + 360) % 360;
  2299. }
  2300. return shadow(this, 'rotate', rotate);
  2301. },
  2302. getContentStream: function Page_getContentStream() {
  2303. var content = this.content;
  2304. var stream;
  2305. if (isArray(content)) {
  2306. // fetching items
  2307. var xref = this.xref;
  2308. var i, n = content.length;
  2309. var streams = [];
  2310. for (i = 0; i < n; ++i) {
  2311. streams.push(xref.fetchIfRef(content[i]));
  2312. }
  2313. stream = new StreamsSequenceStream(streams);
  2314. } else if (isStream(content)) {
  2315. stream = content;
  2316. } else {
  2317. // replacing non-existent page content with empty one
  2318. stream = new NullStream();
  2319. }
  2320. return stream;
  2321. },
  2322. loadResources: function Page_loadResources(keys) {
  2323. if (!this.resourcesPromise) {
  2324. // TODO: add async getInheritedPageProp and remove this.
  2325. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2326. }
  2327. return this.resourcesPromise.then(function resourceSuccess() {
  2328. var objectLoader = new ObjectLoader(this.resources.map,
  2329. keys,
  2330. this.xref);
  2331. return objectLoader.load();
  2332. }.bind(this));
  2333. },
  2334. getOperatorList: function Page_getOperatorList(handler, intent) {
  2335. var self = this;
  2336. var pdfManager = this.pdfManager;
  2337. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2338. []);
  2339. var resourcesPromise = this.loadResources([
  2340. 'ExtGState',
  2341. 'ColorSpace',
  2342. 'Pattern',
  2343. 'Shading',
  2344. 'XObject',
  2345. 'Font'
  2346. // ProcSet
  2347. // Properties
  2348. ]);
  2349. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2350. handler, this.pageIndex,
  2351. 'p' + this.pageIndex + '_',
  2352. this.idCounters,
  2353. this.fontCache);
  2354. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2355. var pageListPromise = dataPromises.then(function(data) {
  2356. var contentStream = data[0];
  2357. var opList = new OperatorList(intent, handler, self.pageIndex);
  2358. handler.send('StartRenderPage', {
  2359. transparency: partialEvaluator.hasBlendModes(self.resources),
  2360. pageIndex: self.pageIndex,
  2361. intent: intent
  2362. });
  2363. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2364. opList).then(function () {
  2365. return opList;
  2366. });
  2367. });
  2368. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2369. return Promise.all([pageListPromise, annotationsPromise]).then(
  2370. function(datas) {
  2371. var pageOpList = datas[0];
  2372. var annotations = datas[1];
  2373. if (annotations.length === 0) {
  2374. pageOpList.flush(true);
  2375. return pageOpList;
  2376. }
  2377. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2378. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2379. return annotationsReadyPromise.then(function () {
  2380. pageOpList.flush(true);
  2381. return pageOpList;
  2382. });
  2383. });
  2384. },
  2385. extractTextContent: function Page_extractTextContent() {
  2386. var handler = {
  2387. on: function nullHandlerOn() {},
  2388. send: function nullHandlerSend() {}
  2389. };
  2390. var self = this;
  2391. var pdfManager = this.pdfManager;
  2392. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2393. []);
  2394. var resourcesPromise = this.loadResources([
  2395. 'ExtGState',
  2396. 'XObject',
  2397. 'Font'
  2398. ]);
  2399. var dataPromises = Promise.all([contentStreamPromise,
  2400. resourcesPromise]);
  2401. return dataPromises.then(function(data) {
  2402. var contentStream = data[0];
  2403. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2404. handler, self.pageIndex,
  2405. 'p' + self.pageIndex + '_',
  2406. self.idCounters,
  2407. self.fontCache);
  2408. return partialEvaluator.getTextContent(contentStream,
  2409. self.resources);
  2410. });
  2411. },
  2412. getAnnotationsData: function Page_getAnnotationsData() {
  2413. var annotations = this.annotations;
  2414. var annotationsData = [];
  2415. for (var i = 0, n = annotations.length; i < n; ++i) {
  2416. annotationsData.push(annotations[i].getData());
  2417. }
  2418. return annotationsData;
  2419. },
  2420. get annotations() {
  2421. var annotations = [];
  2422. var annotationRefs = (this.annotationRefs || []);
  2423. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2424. var annotationRef = annotationRefs[i];
  2425. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2426. if (annotation) {
  2427. annotations.push(annotation);
  2428. }
  2429. }
  2430. return shadow(this, 'annotations', annotations);
  2431. }
  2432. };
  2433. return Page;
  2434. })();
  2435. /**
  2436. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2437. * `PDFDoc`, this one doesn't have any job management code.
  2438. * Right now there exists one PDFDocument on the main thread + one object
  2439. * for each worker. If there is no worker support enabled, there are two
  2440. * `PDFDocument` objects on the main thread created.
  2441. */
  2442. var PDFDocument = (function PDFDocumentClosure() {
  2443. function PDFDocument(pdfManager, arg, password) {
  2444. if (isStream(arg)) {
  2445. init.call(this, pdfManager, arg, password);
  2446. } else if (isArrayBuffer(arg)) {
  2447. init.call(this, pdfManager, new Stream(arg), password);
  2448. } else {
  2449. error('PDFDocument: Unknown argument type');
  2450. }
  2451. }
  2452. function init(pdfManager, stream, password) {
  2453. assert(stream.length > 0, 'stream must have data');
  2454. this.pdfManager = pdfManager;
  2455. this.stream = stream;
  2456. var xref = new XRef(this.stream, password, pdfManager);
  2457. this.xref = xref;
  2458. }
  2459. function find(stream, needle, limit, backwards) {
  2460. var pos = stream.pos;
  2461. var end = stream.end;
  2462. var strBuf = [];
  2463. if (pos + limit > end) {
  2464. limit = end - pos;
  2465. }
  2466. for (var n = 0; n < limit; ++n) {
  2467. strBuf.push(String.fromCharCode(stream.getByte()));
  2468. }
  2469. var str = strBuf.join('');
  2470. stream.pos = pos;
  2471. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2472. if (index === -1) {
  2473. return false; /* not found */
  2474. }
  2475. stream.pos += index;
  2476. return true; /* found */
  2477. }
  2478. var DocumentInfoValidators = {
  2479. get entries() {
  2480. // Lazily build this since all the validation functions below are not
  2481. // defined until after this file loads.
  2482. return shadow(this, 'entries', {
  2483. Title: isString,
  2484. Author: isString,
  2485. Subject: isString,
  2486. Keywords: isString,
  2487. Creator: isString,
  2488. Producer: isString,
  2489. CreationDate: isString,
  2490. ModDate: isString,
  2491. Trapped: isName
  2492. });
  2493. }
  2494. };
  2495. PDFDocument.prototype = {
  2496. parse: function PDFDocument_parse(recoveryMode) {
  2497. this.setup(recoveryMode);
  2498. try {
  2499. // checking if AcroForm is present
  2500. this.acroForm = this.catalog.catDict.get('AcroForm');
  2501. if (this.acroForm) {
  2502. this.xfa = this.acroForm.get('XFA');
  2503. var fields = this.acroForm.get('Fields');
  2504. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2505. !this.xfa) {
  2506. // no fields and no XFA -- not a form (?)
  2507. this.acroForm = null;
  2508. }
  2509. }
  2510. } catch (ex) {
  2511. info('Something wrong with AcroForm entry');
  2512. this.acroForm = null;
  2513. }
  2514. },
  2515. get linearization() {
  2516. var linearization = null;
  2517. if (this.stream.length) {
  2518. try {
  2519. linearization = Linearization.create(this.stream);
  2520. } catch (err) {
  2521. if (err instanceof MissingDataException) {
  2522. throw err;
  2523. }
  2524. info(err);
  2525. }
  2526. }
  2527. // shadow the prototype getter with a data property
  2528. return shadow(this, 'linearization', linearization);
  2529. },
  2530. get startXRef() {
  2531. var stream = this.stream;
  2532. var startXRef = 0;
  2533. var linearization = this.linearization;
  2534. if (linearization) {
  2535. // Find end of first obj.
  2536. stream.reset();
  2537. if (find(stream, 'endobj', 1024)) {
  2538. startXRef = stream.pos + 6;
  2539. }
  2540. } else {
  2541. // Find startxref by jumping backward from the end of the file.
  2542. var step = 1024;
  2543. var found = false, pos = stream.end;
  2544. while (!found && pos > 0) {
  2545. pos -= step - 'startxref'.length;
  2546. if (pos < 0) {
  2547. pos = 0;
  2548. }
  2549. stream.pos = pos;
  2550. found = find(stream, 'startxref', step, true);
  2551. }
  2552. if (found) {
  2553. stream.skip(9);
  2554. var ch;
  2555. do {
  2556. ch = stream.getByte();
  2557. } while (Lexer.isSpace(ch));
  2558. var str = '';
  2559. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2560. str += String.fromCharCode(ch);
  2561. ch = stream.getByte();
  2562. }
  2563. startXRef = parseInt(str, 10);
  2564. if (isNaN(startXRef)) {
  2565. startXRef = 0;
  2566. }
  2567. }
  2568. }
  2569. // shadow the prototype getter with a data property
  2570. return shadow(this, 'startXRef', startXRef);
  2571. },
  2572. get mainXRefEntriesOffset() {
  2573. var mainXRefEntriesOffset = 0;
  2574. var linearization = this.linearization;
  2575. if (linearization) {
  2576. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2577. }
  2578. // shadow the prototype getter with a data property
  2579. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2580. },
  2581. // Find the header, remove leading garbage and setup the stream
  2582. // starting from the header.
  2583. checkHeader: function PDFDocument_checkHeader() {
  2584. var stream = this.stream;
  2585. stream.reset();
  2586. if (find(stream, '%PDF-', 1024)) {
  2587. // Found the header, trim off any garbage before it.
  2588. stream.moveStart();
  2589. // Reading file format version
  2590. var MAX_VERSION_LENGTH = 12;
  2591. var version = '', ch;
  2592. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2593. if (version.length >= MAX_VERSION_LENGTH) {
  2594. break;
  2595. }
  2596. version += String.fromCharCode(ch);
  2597. }
  2598. // removing "%PDF-"-prefix
  2599. this.pdfFormatVersion = version.substring(5);
  2600. return;
  2601. }
  2602. // May not be a PDF file, continue anyway.
  2603. },
  2604. parseStartXRef: function PDFDocument_parseStartXRef() {
  2605. var startXRef = this.startXRef;
  2606. this.xref.setStartXRef(startXRef);
  2607. },
  2608. setup: function PDFDocument_setup(recoveryMode) {
  2609. this.xref.parse(recoveryMode);
  2610. this.catalog = new Catalog(this.pdfManager, this.xref);
  2611. },
  2612. get numPages() {
  2613. var linearization = this.linearization;
  2614. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2615. // shadow the prototype getter
  2616. return shadow(this, 'numPages', num);
  2617. },
  2618. get documentInfo() {
  2619. var docInfo = {
  2620. PDFFormatVersion: this.pdfFormatVersion,
  2621. IsAcroFormPresent: !!this.acroForm,
  2622. IsXFAPresent: !!this.xfa
  2623. };
  2624. var infoDict;
  2625. try {
  2626. infoDict = this.xref.trailer.get('Info');
  2627. } catch (err) {
  2628. info('The document information dictionary is invalid.');
  2629. }
  2630. if (infoDict) {
  2631. var validEntries = DocumentInfoValidators.entries;
  2632. // Only fill the document info with valid entries from the spec.
  2633. for (var key in validEntries) {
  2634. if (infoDict.has(key)) {
  2635. var value = infoDict.get(key);
  2636. // Make sure the value conforms to the spec.
  2637. if (validEntries[key](value)) {
  2638. docInfo[key] = (typeof value !== 'string' ?
  2639. value : stringToPDFString(value));
  2640. } else {
  2641. info('Bad value in document info for "' + key + '"');
  2642. }
  2643. }
  2644. }
  2645. }
  2646. return shadow(this, 'documentInfo', docInfo);
  2647. },
  2648. get fingerprint() {
  2649. var xref = this.xref, hash, fileID = '';
  2650. if (xref.trailer.has('ID')) {
  2651. hash = stringToBytes(xref.trailer.get('ID')[0]);
  2652. } else {
  2653. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  2654. }
  2655. for (var i = 0, n = hash.length; i < n; i++) {
  2656. fileID += hash[i].toString(16);
  2657. }
  2658. return shadow(this, 'fingerprint', fileID);
  2659. },
  2660. getPage: function PDFDocument_getPage(pageIndex) {
  2661. return this.catalog.getPage(pageIndex);
  2662. },
  2663. cleanup: function PDFDocument_cleanup() {
  2664. return this.catalog.cleanup();
  2665. }
  2666. };
  2667. return PDFDocument;
  2668. })();
  2669. var Name = (function NameClosure() {
  2670. function Name(name) {
  2671. this.name = name;
  2672. }
  2673. Name.prototype = {};
  2674. var nameCache = {};
  2675. Name.get = function Name_get(name) {
  2676. var nameValue = nameCache[name];
  2677. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2678. };
  2679. return Name;
  2680. })();
  2681. var Cmd = (function CmdClosure() {
  2682. function Cmd(cmd) {
  2683. this.cmd = cmd;
  2684. }
  2685. Cmd.prototype = {};
  2686. var cmdCache = {};
  2687. Cmd.get = function Cmd_get(cmd) {
  2688. var cmdValue = cmdCache[cmd];
  2689. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2690. };
  2691. return Cmd;
  2692. })();
  2693. var Dict = (function DictClosure() {
  2694. var nonSerializable = function nonSerializableClosure() {
  2695. return nonSerializable; // creating closure on some variable
  2696. };
  2697. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2698. 'Background': true,
  2699. 'ExtGState': true,
  2700. 'Halftone': true,
  2701. 'Layout': true,
  2702. 'Mask': true,
  2703. 'Pagination': true,
  2704. 'Printing': true
  2705. };
  2706. function isRecursionAllowedFor(dict) {
  2707. if (!isName(dict.Type)) {
  2708. return true;
  2709. }
  2710. var dictType = dict.Type.name;
  2711. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2712. }
  2713. // xref is optional
  2714. function Dict(xref) {
  2715. // Map should only be used internally, use functions below to access.
  2716. this.map = Object.create(null);
  2717. this.xref = xref;
  2718. this.objId = null;
  2719. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2720. }
  2721. Dict.prototype = {
  2722. assignXref: function Dict_assignXref(newXref) {
  2723. this.xref = newXref;
  2724. },
  2725. // automatically dereferences Ref objects
  2726. get: function Dict_get(key1, key2, key3) {
  2727. var value;
  2728. var xref = this.xref;
  2729. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2730. typeof key2 === 'undefined') {
  2731. return xref ? xref.fetchIfRef(value) : value;
  2732. }
  2733. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2734. typeof key3 === 'undefined') {
  2735. return xref ? xref.fetchIfRef(value) : value;
  2736. }
  2737. value = this.map[key3] || null;
  2738. return xref ? xref.fetchIfRef(value) : value;
  2739. },
  2740. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2741. getAsync: function Dict_getAsync(key1, key2, key3) {
  2742. var value;
  2743. var xref = this.xref;
  2744. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2745. typeof key2 === 'undefined') {
  2746. if (xref) {
  2747. return xref.fetchIfRefAsync(value);
  2748. }
  2749. return Promise.resolve(value);
  2750. }
  2751. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2752. typeof key3 === 'undefined') {
  2753. if (xref) {
  2754. return xref.fetchIfRefAsync(value);
  2755. }
  2756. return Promise.resolve(value);
  2757. }
  2758. value = this.map[key3] || null;
  2759. if (xref) {
  2760. return xref.fetchIfRefAsync(value);
  2761. }
  2762. return Promise.resolve(value);
  2763. },
  2764. // no dereferencing
  2765. getRaw: function Dict_getRaw(key) {
  2766. return this.map[key];
  2767. },
  2768. // creates new map and dereferences all Refs
  2769. getAll: function Dict_getAll() {
  2770. var all = Object.create(null);
  2771. var queue = null;
  2772. var key, obj;
  2773. for (key in this.map) {
  2774. obj = this.get(key);
  2775. if (obj instanceof Dict) {
  2776. if (isRecursionAllowedFor(obj)) {
  2777. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2778. } else {
  2779. all[key] = this.getRaw(key);
  2780. }
  2781. } else {
  2782. all[key] = obj;
  2783. }
  2784. }
  2785. if (!queue) {
  2786. return all;
  2787. }
  2788. // trying to take cyclic references into the account
  2789. var processed = Object.create(null);
  2790. while (queue.length > 0) {
  2791. var item = queue.shift();
  2792. var itemObj = item.obj;
  2793. var objId = itemObj.objId;
  2794. if (objId && objId in processed) {
  2795. item.target[item.key] = processed[objId];
  2796. continue;
  2797. }
  2798. var dereferenced = Object.create(null);
  2799. for (key in itemObj.map) {
  2800. obj = itemObj.get(key);
  2801. if (obj instanceof Dict) {
  2802. if (isRecursionAllowedFor(obj)) {
  2803. queue.push({target: dereferenced, key: key, obj: obj});
  2804. } else {
  2805. dereferenced[key] = itemObj.getRaw(key);
  2806. }
  2807. } else {
  2808. dereferenced[key] = obj;
  2809. }
  2810. }
  2811. if (objId) {
  2812. processed[objId] = dereferenced;
  2813. }
  2814. item.target[item.key] = dereferenced;
  2815. }
  2816. return all;
  2817. },
  2818. set: function Dict_set(key, value) {
  2819. this.map[key] = value;
  2820. },
  2821. has: function Dict_has(key) {
  2822. return key in this.map;
  2823. },
  2824. forEach: function Dict_forEach(callback) {
  2825. for (var key in this.map) {
  2826. callback(key, this.get(key));
  2827. }
  2828. }
  2829. };
  2830. Dict.empty = new Dict(null);
  2831. return Dict;
  2832. })();
  2833. var Ref = (function RefClosure() {
  2834. function Ref(num, gen) {
  2835. this.num = num;
  2836. this.gen = gen;
  2837. }
  2838. Ref.prototype = {
  2839. toString: function Ref_toString() {
  2840. // This function is hot, so we make the string as compact as possible.
  2841. // |this.gen| is almost always zero, so we treat that case specially.
  2842. var str = this.num + 'R';
  2843. if (this.gen !== 0) {
  2844. str += this.gen;
  2845. }
  2846. return str;
  2847. }
  2848. };
  2849. return Ref;
  2850. })();
  2851. // The reference is identified by number and generation.
  2852. // This structure stores only one instance of the reference.
  2853. var RefSet = (function RefSetClosure() {
  2854. function RefSet() {
  2855. this.dict = {};
  2856. }
  2857. RefSet.prototype = {
  2858. has: function RefSet_has(ref) {
  2859. return ref.toString() in this.dict;
  2860. },
  2861. put: function RefSet_put(ref) {
  2862. this.dict[ref.toString()] = true;
  2863. },
  2864. remove: function RefSet_remove(ref) {
  2865. delete this.dict[ref.toString()];
  2866. }
  2867. };
  2868. return RefSet;
  2869. })();
  2870. var RefSetCache = (function RefSetCacheClosure() {
  2871. function RefSetCache() {
  2872. this.dict = Object.create(null);
  2873. }
  2874. RefSetCache.prototype = {
  2875. get: function RefSetCache_get(ref) {
  2876. return this.dict[ref.toString()];
  2877. },
  2878. has: function RefSetCache_has(ref) {
  2879. return ref.toString() in this.dict;
  2880. },
  2881. put: function RefSetCache_put(ref, obj) {
  2882. this.dict[ref.toString()] = obj;
  2883. },
  2884. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2885. this.dict[ref.toString()] = this.get(aliasRef);
  2886. },
  2887. forEach: function RefSetCache_forEach(fn, thisArg) {
  2888. for (var i in this.dict) {
  2889. fn.call(thisArg, this.dict[i]);
  2890. }
  2891. },
  2892. clear: function RefSetCache_clear() {
  2893. this.dict = Object.create(null);
  2894. }
  2895. };
  2896. return RefSetCache;
  2897. })();
  2898. var Catalog = (function CatalogClosure() {
  2899. function Catalog(pdfManager, xref) {
  2900. this.pdfManager = pdfManager;
  2901. this.xref = xref;
  2902. this.catDict = xref.getCatalogObj();
  2903. this.fontCache = new RefSetCache();
  2904. assert(isDict(this.catDict),
  2905. 'catalog object is not a dictionary');
  2906. this.pagePromises = [];
  2907. }
  2908. Catalog.prototype = {
  2909. get metadata() {
  2910. var streamRef = this.catDict.getRaw('Metadata');
  2911. if (!isRef(streamRef)) {
  2912. return shadow(this, 'metadata', null);
  2913. }
  2914. var encryptMetadata = (!this.xref.encrypt ? false :
  2915. this.xref.encrypt.encryptMetadata);
  2916. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2917. var metadata;
  2918. if (stream && isDict(stream.dict)) {
  2919. var type = stream.dict.get('Type');
  2920. var subtype = stream.dict.get('Subtype');
  2921. if (isName(type) && isName(subtype) &&
  2922. type.name === 'Metadata' && subtype.name === 'XML') {
  2923. // XXX: This should examine the charset the XML document defines,
  2924. // however since there are currently no real means to decode
  2925. // arbitrary charsets, let's just hope that the author of the PDF
  2926. // was reasonable enough to stick with the XML default charset,
  2927. // which is UTF-8.
  2928. try {
  2929. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2930. } catch (e) {
  2931. info('Skipping invalid metadata.');
  2932. }
  2933. }
  2934. }
  2935. return shadow(this, 'metadata', metadata);
  2936. },
  2937. get toplevelPagesDict() {
  2938. var pagesObj = this.catDict.get('Pages');
  2939. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2940. // shadow the prototype getter
  2941. return shadow(this, 'toplevelPagesDict', pagesObj);
  2942. },
  2943. get documentOutline() {
  2944. var obj = null;
  2945. try {
  2946. obj = this.readDocumentOutline();
  2947. } catch (ex) {
  2948. if (ex instanceof MissingDataException) {
  2949. throw ex;
  2950. }
  2951. warn('Unable to read document outline');
  2952. }
  2953. return shadow(this, 'documentOutline', obj);
  2954. },
  2955. readDocumentOutline: function Catalog_readDocumentOutline() {
  2956. var xref = this.xref;
  2957. var obj = this.catDict.get('Outlines');
  2958. var root = { items: [] };
  2959. if (isDict(obj)) {
  2960. obj = obj.getRaw('First');
  2961. var processed = new RefSet();
  2962. if (isRef(obj)) {
  2963. var queue = [{obj: obj, parent: root}];
  2964. // to avoid recursion keeping track of the items
  2965. // in the processed dictionary
  2966. processed.put(obj);
  2967. while (queue.length > 0) {
  2968. var i = queue.shift();
  2969. var outlineDict = xref.fetchIfRef(i.obj);
  2970. if (outlineDict === null) {
  2971. continue;
  2972. }
  2973. if (!outlineDict.has('Title')) {
  2974. error('Invalid outline item');
  2975. }
  2976. var dest = outlineDict.get('A');
  2977. if (dest) {
  2978. dest = dest.get('D');
  2979. } else if (outlineDict.has('Dest')) {
  2980. dest = outlineDict.getRaw('Dest');
  2981. if (isName(dest)) {
  2982. dest = dest.name;
  2983. }
  2984. }
  2985. var title = outlineDict.get('Title');
  2986. var outlineItem = {
  2987. dest: dest,
  2988. title: stringToPDFString(title),
  2989. color: outlineDict.get('C') || [0, 0, 0],
  2990. count: outlineDict.get('Count'),
  2991. bold: !!(outlineDict.get('F') & 2),
  2992. italic: !!(outlineDict.get('F') & 1),
  2993. items: []
  2994. };
  2995. i.parent.items.push(outlineItem);
  2996. obj = outlineDict.getRaw('First');
  2997. if (isRef(obj) && !processed.has(obj)) {
  2998. queue.push({obj: obj, parent: outlineItem});
  2999. processed.put(obj);
  3000. }
  3001. obj = outlineDict.getRaw('Next');
  3002. if (isRef(obj) && !processed.has(obj)) {
  3003. queue.push({obj: obj, parent: i.parent});
  3004. processed.put(obj);
  3005. }
  3006. }
  3007. }
  3008. }
  3009. return (root.items.length > 0 ? root.items : null);
  3010. },
  3011. get numPages() {
  3012. var obj = this.toplevelPagesDict.get('Count');
  3013. assert(
  3014. isInt(obj),
  3015. 'page count in top level pages object is not an integer'
  3016. );
  3017. // shadow the prototype getter
  3018. return shadow(this, 'num', obj);
  3019. },
  3020. get destinations() {
  3021. function fetchDestination(dest) {
  3022. return isDict(dest) ? dest.get('D') : dest;
  3023. }
  3024. var xref = this.xref;
  3025. var dests = {}, nameTreeRef, nameDictionaryRef;
  3026. var obj = this.catDict.get('Names');
  3027. if (obj && obj.has('Dests')) {
  3028. nameTreeRef = obj.getRaw('Dests');
  3029. } else if (this.catDict.has('Dests')) {
  3030. nameDictionaryRef = this.catDict.get('Dests');
  3031. }
  3032. if (nameDictionaryRef) {
  3033. // reading simple destination dictionary
  3034. obj = nameDictionaryRef;
  3035. obj.forEach(function catalogForEach(key, value) {
  3036. if (!value) {
  3037. return;
  3038. }
  3039. dests[key] = fetchDestination(value);
  3040. });
  3041. }
  3042. if (nameTreeRef) {
  3043. var nameTree = new NameTree(nameTreeRef, xref);
  3044. var names = nameTree.getAll();
  3045. for (var name in names) {
  3046. if (!names.hasOwnProperty(name)) {
  3047. continue;
  3048. }
  3049. dests[name] = fetchDestination(names[name]);
  3050. }
  3051. }
  3052. return shadow(this, 'destinations', dests);
  3053. },
  3054. get attachments() {
  3055. var xref = this.xref;
  3056. var attachments = null, nameTreeRef;
  3057. var obj = this.catDict.get('Names');
  3058. if (obj) {
  3059. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3060. }
  3061. if (nameTreeRef) {
  3062. var nameTree = new NameTree(nameTreeRef, xref);
  3063. var names = nameTree.getAll();
  3064. for (var name in names) {
  3065. if (!names.hasOwnProperty(name)) {
  3066. continue;
  3067. }
  3068. var fs = new FileSpec(names[name], xref);
  3069. if (!attachments) {
  3070. attachments = {};
  3071. }
  3072. attachments[stringToPDFString(name)] = fs.serializable;
  3073. }
  3074. }
  3075. return shadow(this, 'attachments', attachments);
  3076. },
  3077. get javaScript() {
  3078. var xref = this.xref;
  3079. var obj = this.catDict.get('Names');
  3080. var javaScript = [];
  3081. if (obj && obj.has('JavaScript')) {
  3082. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3083. var names = nameTree.getAll();
  3084. for (var name in names) {
  3085. if (!names.hasOwnProperty(name)) {
  3086. continue;
  3087. }
  3088. // We don't really use the JavaScript right now. This code is
  3089. // defensive so we don't cause errors on document load.
  3090. var jsDict = names[name];
  3091. if (!isDict(jsDict)) {
  3092. continue;
  3093. }
  3094. var type = jsDict.get('S');
  3095. if (!isName(type) || type.name !== 'JavaScript') {
  3096. continue;
  3097. }
  3098. var js = jsDict.get('JS');
  3099. if (!isString(js) && !isStream(js)) {
  3100. continue;
  3101. }
  3102. if (isStream(js)) {
  3103. js = bytesToString(js.getBytes());
  3104. }
  3105. javaScript.push(stringToPDFString(js));
  3106. }
  3107. }
  3108. // Append OpenAction actions to javaScript array
  3109. var openactionDict = this.catDict.get('OpenAction');
  3110. if (isDict(openactionDict)) {
  3111. var objType = openactionDict.get('Type');
  3112. var actionType = openactionDict.get('S');
  3113. var action = openactionDict.get('N');
  3114. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3115. isName(actionType) && actionType.name === 'Named' &&
  3116. isName(action) && action.name === 'Print');
  3117. if (isPrintAction) {
  3118. javaScript.push('print(true);');
  3119. }
  3120. }
  3121. return shadow(this, 'javaScript', javaScript);
  3122. },
  3123. cleanup: function Catalog_cleanup() {
  3124. var promises = [];
  3125. this.fontCache.forEach(function (promise) {
  3126. promises.push(promise);
  3127. });
  3128. return Promise.all(promises).then(function (translatedFonts) {
  3129. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3130. var font = translatedFonts[i].dict;
  3131. delete font.translated;
  3132. }
  3133. this.fontCache.clear();
  3134. }.bind(this));
  3135. },
  3136. getPage: function Catalog_getPage(pageIndex) {
  3137. if (!(pageIndex in this.pagePromises)) {
  3138. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3139. function (a) {
  3140. var dict = a[0];
  3141. var ref = a[1];
  3142. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3143. this.fontCache);
  3144. }.bind(this)
  3145. );
  3146. }
  3147. return this.pagePromises[pageIndex];
  3148. },
  3149. getPageDict: function Catalog_getPageDict(pageIndex) {
  3150. var capability = createPromiseCapability();
  3151. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3152. var currentPageIndex = 0;
  3153. var xref = this.xref;
  3154. function next() {
  3155. while (nodesToVisit.length) {
  3156. var currentNode = nodesToVisit.pop();
  3157. if (isRef(currentNode)) {
  3158. xref.fetchAsync(currentNode).then(function (obj) {
  3159. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3160. if (pageIndex === currentPageIndex) {
  3161. capability.resolve([obj, currentNode]);
  3162. } else {
  3163. currentPageIndex++;
  3164. next();
  3165. }
  3166. return;
  3167. }
  3168. nodesToVisit.push(obj);
  3169. next();
  3170. }, capability.reject);
  3171. return;
  3172. }
  3173. // must be a child page dictionary
  3174. assert(
  3175. isDict(currentNode),
  3176. 'page dictionary kid reference points to wrong type of object'
  3177. );
  3178. var count = currentNode.get('Count');
  3179. // Skip nodes where the page can't be.
  3180. if (currentPageIndex + count <= pageIndex) {
  3181. currentPageIndex += count;
  3182. continue;
  3183. }
  3184. var kids = currentNode.get('Kids');
  3185. assert(isArray(kids), 'page dictionary kids object is not an array');
  3186. if (count === kids.length) {
  3187. // Nodes that don't have the page have been skipped and this is the
  3188. // bottom of the tree which means the page requested must be a
  3189. // descendant of this pages node. Ideally we would just resolve the
  3190. // promise with the page ref here, but there is the case where more
  3191. // pages nodes could link to single a page (see issue 3666 pdf). To
  3192. // handle this push it back on the queue so if it is a pages node it
  3193. // will be descended into.
  3194. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3195. currentPageIndex = pageIndex;
  3196. continue;
  3197. } else {
  3198. for (var last = kids.length - 1; last >= 0; last--) {
  3199. nodesToVisit.push(kids[last]);
  3200. }
  3201. }
  3202. }
  3203. capability.reject('Page index ' + pageIndex + ' not found.');
  3204. }
  3205. next();
  3206. return capability.promise;
  3207. },
  3208. getPageIndex: function Catalog_getPageIndex(ref) {
  3209. // The page tree nodes have the count of all the leaves below them. To get
  3210. // how many pages are before we just have to walk up the tree and keep
  3211. // adding the count of siblings to the left of the node.
  3212. var xref = this.xref;
  3213. function pagesBeforeRef(kidRef) {
  3214. var total = 0;
  3215. var parentRef;
  3216. return xref.fetchAsync(kidRef).then(function (node) {
  3217. if (!node) {
  3218. return null;
  3219. }
  3220. parentRef = node.getRaw('Parent');
  3221. return node.getAsync('Parent');
  3222. }).then(function (parent) {
  3223. if (!parent) {
  3224. return null;
  3225. }
  3226. return parent.getAsync('Kids');
  3227. }).then(function (kids) {
  3228. if (!kids) {
  3229. return null;
  3230. }
  3231. var kidPromises = [];
  3232. var found = false;
  3233. for (var i = 0; i < kids.length; i++) {
  3234. var kid = kids[i];
  3235. assert(isRef(kid), 'kids must be a ref');
  3236. if (kid.num === kidRef.num) {
  3237. found = true;
  3238. break;
  3239. }
  3240. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3241. if (kid.has('Count')) {
  3242. var count = kid.get('Count');
  3243. total += count;
  3244. } else { // page leaf node
  3245. total++;
  3246. }
  3247. }));
  3248. }
  3249. if (!found) {
  3250. error('kid ref not found in parents kids');
  3251. }
  3252. return Promise.all(kidPromises).then(function () {
  3253. return [total, parentRef];
  3254. });
  3255. });
  3256. }
  3257. var total = 0;
  3258. function next(ref) {
  3259. return pagesBeforeRef(ref).then(function (args) {
  3260. if (!args) {
  3261. return total;
  3262. }
  3263. var count = args[0];
  3264. var parentRef = args[1];
  3265. total += count;
  3266. return next(parentRef);
  3267. });
  3268. }
  3269. return next(ref);
  3270. }
  3271. };
  3272. return Catalog;
  3273. })();
  3274. var XRef = (function XRefClosure() {
  3275. function XRef(stream, password) {
  3276. this.stream = stream;
  3277. this.entries = [];
  3278. this.xrefstms = {};
  3279. // prepare the XRef cache
  3280. this.cache = [];
  3281. this.password = password;
  3282. this.stats = {
  3283. streamTypes: [],
  3284. fontTypes: []
  3285. };
  3286. }
  3287. XRef.prototype = {
  3288. setStartXRef: function XRef_setStartXRef(startXRef) {
  3289. // Store the starting positions of xref tables as we process them
  3290. // so we can recover from missing data errors
  3291. this.startXRefQueue = [startXRef];
  3292. },
  3293. parse: function XRef_parse(recoveryMode) {
  3294. var trailerDict;
  3295. if (!recoveryMode) {
  3296. trailerDict = this.readXRef();
  3297. } else {
  3298. warn('Indexing all PDF objects');
  3299. trailerDict = this.indexObjects();
  3300. }
  3301. trailerDict.assignXref(this);
  3302. this.trailer = trailerDict;
  3303. var encrypt = trailerDict.get('Encrypt');
  3304. if (encrypt) {
  3305. var ids = trailerDict.get('ID');
  3306. var fileId = (ids && ids.length) ? ids[0] : '';
  3307. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3308. this.password);
  3309. }
  3310. // get the root dictionary (catalog) object
  3311. if (!(this.root = trailerDict.get('Root'))) {
  3312. error('Invalid root reference');
  3313. }
  3314. },
  3315. processXRefTable: function XRef_processXRefTable(parser) {
  3316. if (!('tableState' in this)) {
  3317. // Stores state of the table as we process it so we can resume
  3318. // from middle of table in case of missing data error
  3319. this.tableState = {
  3320. entryNum: 0,
  3321. streamPos: parser.lexer.stream.pos,
  3322. parserBuf1: parser.buf1,
  3323. parserBuf2: parser.buf2
  3324. };
  3325. }
  3326. var obj = this.readXRefTable(parser);
  3327. // Sanity check
  3328. if (!isCmd(obj, 'trailer')) {
  3329. error('Invalid XRef table: could not find trailer dictionary');
  3330. }
  3331. // Read trailer dictionary, e.g.
  3332. // trailer
  3333. // << /Size 22
  3334. // /Root 20R
  3335. // /Info 10R
  3336. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3337. // >>
  3338. // The parser goes through the entire stream << ... >> and provides
  3339. // a getter interface for the key-value table
  3340. var dict = parser.getObj();
  3341. // The pdflib PDF generator can generate a nested trailer dictionary
  3342. if (!isDict(dict) && dict.dict) {
  3343. dict = dict.dict;
  3344. }
  3345. if (!isDict(dict)) {
  3346. error('Invalid XRef table: could not parse trailer dictionary');
  3347. }
  3348. delete this.tableState;
  3349. return dict;
  3350. },
  3351. readXRefTable: function XRef_readXRefTable(parser) {
  3352. // Example of cross-reference table:
  3353. // xref
  3354. // 0 1 <-- subsection header (first obj #, obj count)
  3355. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3356. // 23 2 <-- subsection header ... and so on ...
  3357. // 0000025518 00002 n
  3358. // 0000025635 00000 n
  3359. // trailer
  3360. // ...
  3361. var stream = parser.lexer.stream;
  3362. var tableState = this.tableState;
  3363. stream.pos = tableState.streamPos;
  3364. parser.buf1 = tableState.parserBuf1;
  3365. parser.buf2 = tableState.parserBuf2;
  3366. // Outer loop is over subsection headers
  3367. var obj;
  3368. while (true) {
  3369. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3370. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3371. break;
  3372. }
  3373. tableState.firstEntryNum = obj;
  3374. tableState.entryCount = parser.getObj();
  3375. }
  3376. var first = tableState.firstEntryNum;
  3377. var count = tableState.entryCount;
  3378. if (!isInt(first) || !isInt(count)) {
  3379. error('Invalid XRef table: wrong types in subsection header');
  3380. }
  3381. // Inner loop is over objects themselves
  3382. for (var i = tableState.entryNum; i < count; i++) {
  3383. tableState.streamPos = stream.pos;
  3384. tableState.entryNum = i;
  3385. tableState.parserBuf1 = parser.buf1;
  3386. tableState.parserBuf2 = parser.buf2;
  3387. var entry = {};
  3388. entry.offset = parser.getObj();
  3389. entry.gen = parser.getObj();
  3390. var type = parser.getObj();
  3391. if (isCmd(type, 'f')) {
  3392. entry.free = true;
  3393. } else if (isCmd(type, 'n')) {
  3394. entry.uncompressed = true;
  3395. }
  3396. // Validate entry obj
  3397. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3398. !(entry.free || entry.uncompressed)) {
  3399. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3400. }
  3401. if (!this.entries[i + first]) {
  3402. this.entries[i + first] = entry;
  3403. }
  3404. }
  3405. tableState.entryNum = 0;
  3406. tableState.streamPos = stream.pos;
  3407. tableState.parserBuf1 = parser.buf1;
  3408. tableState.parserBuf2 = parser.buf2;
  3409. delete tableState.firstEntryNum;
  3410. delete tableState.entryCount;
  3411. }
  3412. // Per issue 3248: hp scanners generate bad XRef
  3413. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3414. // shifting the entries
  3415. this.entries.shift();
  3416. }
  3417. // Sanity check: as per spec, first object must be free
  3418. if (this.entries[0] && !this.entries[0].free) {
  3419. error('Invalid XRef table: unexpected first object');
  3420. }
  3421. return obj;
  3422. },
  3423. processXRefStream: function XRef_processXRefStream(stream) {
  3424. if (!('streamState' in this)) {
  3425. // Stores state of the stream as we process it so we can resume
  3426. // from middle of stream in case of missing data error
  3427. var streamParameters = stream.dict;
  3428. var byteWidths = streamParameters.get('W');
  3429. var range = streamParameters.get('Index');
  3430. if (!range) {
  3431. range = [0, streamParameters.get('Size')];
  3432. }
  3433. this.streamState = {
  3434. entryRanges: range,
  3435. byteWidths: byteWidths,
  3436. entryNum: 0,
  3437. streamPos: stream.pos
  3438. };
  3439. }
  3440. this.readXRefStream(stream);
  3441. delete this.streamState;
  3442. return stream.dict;
  3443. },
  3444. readXRefStream: function XRef_readXRefStream(stream) {
  3445. var i, j;
  3446. var streamState = this.streamState;
  3447. stream.pos = streamState.streamPos;
  3448. var byteWidths = streamState.byteWidths;
  3449. var typeFieldWidth = byteWidths[0];
  3450. var offsetFieldWidth = byteWidths[1];
  3451. var generationFieldWidth = byteWidths[2];
  3452. var entryRanges = streamState.entryRanges;
  3453. while (entryRanges.length > 0) {
  3454. var first = entryRanges[0];
  3455. var n = entryRanges[1];
  3456. if (!isInt(first) || !isInt(n)) {
  3457. error('Invalid XRef range fields: ' + first + ', ' + n);
  3458. }
  3459. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3460. !isInt(generationFieldWidth)) {
  3461. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3462. }
  3463. for (i = streamState.entryNum; i < n; ++i) {
  3464. streamState.entryNum = i;
  3465. streamState.streamPos = stream.pos;
  3466. var type = 0, offset = 0, generation = 0;
  3467. for (j = 0; j < typeFieldWidth; ++j) {
  3468. type = (type << 8) | stream.getByte();
  3469. }
  3470. // if type field is absent, its default value is 1
  3471. if (typeFieldWidth === 0) {
  3472. type = 1;
  3473. }
  3474. for (j = 0; j < offsetFieldWidth; ++j) {
  3475. offset = (offset << 8) | stream.getByte();
  3476. }
  3477. for (j = 0; j < generationFieldWidth; ++j) {
  3478. generation = (generation << 8) | stream.getByte();
  3479. }
  3480. var entry = {};
  3481. entry.offset = offset;
  3482. entry.gen = generation;
  3483. switch (type) {
  3484. case 0:
  3485. entry.free = true;
  3486. break;
  3487. case 1:
  3488. entry.uncompressed = true;
  3489. break;
  3490. case 2:
  3491. break;
  3492. default:
  3493. error('Invalid XRef entry type: ' + type);
  3494. }
  3495. if (!this.entries[first + i]) {
  3496. this.entries[first + i] = entry;
  3497. }
  3498. }
  3499. streamState.entryNum = 0;
  3500. streamState.streamPos = stream.pos;
  3501. entryRanges.splice(0, 2);
  3502. }
  3503. },
  3504. indexObjects: function XRef_indexObjects() {
  3505. // Simple scan through the PDF content to find objects,
  3506. // trailers and XRef streams.
  3507. function readToken(data, offset) {
  3508. var token = '', ch = data[offset];
  3509. while (ch !== 13 && ch !== 10) {
  3510. if (++offset >= data.length) {
  3511. break;
  3512. }
  3513. token += String.fromCharCode(ch);
  3514. ch = data[offset];
  3515. }
  3516. return token;
  3517. }
  3518. function skipUntil(data, offset, what) {
  3519. var length = what.length, dataLength = data.length;
  3520. var skipped = 0;
  3521. // finding byte sequence
  3522. while (offset < dataLength) {
  3523. var i = 0;
  3524. while (i < length && data[offset + i] === what[i]) {
  3525. ++i;
  3526. }
  3527. if (i >= length) {
  3528. break; // sequence found
  3529. }
  3530. offset++;
  3531. skipped++;
  3532. }
  3533. return skipped;
  3534. }
  3535. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3536. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3537. 101, 102]);
  3538. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3539. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3540. var stream = this.stream;
  3541. stream.pos = 0;
  3542. var buffer = stream.getBytes();
  3543. var position = stream.start, length = buffer.length;
  3544. var trailers = [], xrefStms = [];
  3545. while (position < length) {
  3546. var ch = buffer[position];
  3547. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3548. ++position;
  3549. continue;
  3550. }
  3551. if (ch === 37) { // %-comment
  3552. do {
  3553. ++position;
  3554. if (position >= length) {
  3555. break;
  3556. }
  3557. ch = buffer[position];
  3558. } while (ch !== 13 && ch !== 10);
  3559. continue;
  3560. }
  3561. var token = readToken(buffer, position);
  3562. var m;
  3563. if (token === 'xref') {
  3564. position += skipUntil(buffer, position, trailerBytes);
  3565. trailers.push(position);
  3566. position += skipUntil(buffer, position, startxrefBytes);
  3567. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3568. this.entries[m[1]] = {
  3569. offset: position,
  3570. gen: m[2] | 0,
  3571. uncompressed: true
  3572. };
  3573. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3574. var content = buffer.subarray(position, position + contentLength);
  3575. // checking XRef stream suspect
  3576. // (it shall have '/XRef' and next char is not a letter)
  3577. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3578. if (xrefTagOffset < contentLength &&
  3579. content[xrefTagOffset + 5] < 64) {
  3580. xrefStms.push(position);
  3581. this.xrefstms[position] = 1; // don't read it recursively
  3582. }
  3583. position += contentLength;
  3584. } else {
  3585. position += token.length + 1;
  3586. }
  3587. }
  3588. // reading XRef streams
  3589. var i, ii;
  3590. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3591. this.startXRefQueue.push(xrefStms[i]);
  3592. this.readXRef(/* recoveryMode */ true);
  3593. }
  3594. // finding main trailer
  3595. var dict;
  3596. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3597. stream.pos = trailers[i];
  3598. var parser = new Parser(new Lexer(stream), true, this);
  3599. var obj = parser.getObj();
  3600. if (!isCmd(obj, 'trailer')) {
  3601. continue;
  3602. }
  3603. // read the trailer dictionary
  3604. if (!isDict(dict = parser.getObj())) {
  3605. continue;
  3606. }
  3607. // taking the first one with 'ID'
  3608. if (dict.has('ID')) {
  3609. return dict;
  3610. }
  3611. }
  3612. // no tailer with 'ID', taking last one (if exists)
  3613. if (dict) {
  3614. return dict;
  3615. }
  3616. // nothing helps
  3617. // calling error() would reject worker with an UnknownErrorException.
  3618. throw new InvalidPDFException('Invalid PDF structure');
  3619. },
  3620. readXRef: function XRef_readXRef(recoveryMode) {
  3621. var stream = this.stream;
  3622. try {
  3623. while (this.startXRefQueue.length) {
  3624. var startXRef = this.startXRefQueue[0];
  3625. stream.pos = startXRef + stream.start;
  3626. var parser = new Parser(new Lexer(stream), true, this);
  3627. var obj = parser.getObj();
  3628. var dict;
  3629. // Get dictionary
  3630. if (isCmd(obj, 'xref')) {
  3631. // Parse end-of-file XRef
  3632. dict = this.processXRefTable(parser);
  3633. if (!this.topDict) {
  3634. this.topDict = dict;
  3635. }
  3636. // Recursively get other XRefs 'XRefStm', if any
  3637. obj = dict.get('XRefStm');
  3638. if (isInt(obj)) {
  3639. var pos = obj;
  3640. // ignore previously loaded xref streams
  3641. // (possible infinite recursion)
  3642. if (!(pos in this.xrefstms)) {
  3643. this.xrefstms[pos] = 1;
  3644. this.startXRefQueue.push(pos);
  3645. }
  3646. }
  3647. } else if (isInt(obj)) {
  3648. // Parse in-stream XRef
  3649. if (!isInt(parser.getObj()) ||
  3650. !isCmd(parser.getObj(), 'obj') ||
  3651. !isStream(obj = parser.getObj())) {
  3652. error('Invalid XRef stream');
  3653. }
  3654. dict = this.processXRefStream(obj);
  3655. if (!this.topDict) {
  3656. this.topDict = dict;
  3657. }
  3658. if (!dict) {
  3659. error('Failed to read XRef stream');
  3660. }
  3661. } else {
  3662. error('Invalid XRef stream header');
  3663. }
  3664. // Recursively get previous dictionary, if any
  3665. obj = dict.get('Prev');
  3666. if (isInt(obj)) {
  3667. this.startXRefQueue.push(obj);
  3668. } else if (isRef(obj)) {
  3669. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3670. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3671. this.startXRefQueue.push(obj.num);
  3672. }
  3673. this.startXRefQueue.shift();
  3674. }
  3675. return this.topDict;
  3676. } catch (e) {
  3677. if (e instanceof MissingDataException) {
  3678. throw e;
  3679. }
  3680. info('(while reading XRef): ' + e);
  3681. }
  3682. if (recoveryMode) {
  3683. return;
  3684. }
  3685. throw new XRefParseException();
  3686. },
  3687. getEntry: function XRef_getEntry(i) {
  3688. var xrefEntry = this.entries[i];
  3689. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3690. return xrefEntry;
  3691. }
  3692. return null;
  3693. },
  3694. fetchIfRef: function XRef_fetchIfRef(obj) {
  3695. if (!isRef(obj)) {
  3696. return obj;
  3697. }
  3698. return this.fetch(obj);
  3699. },
  3700. fetch: function XRef_fetch(ref, suppressEncryption) {
  3701. assert(isRef(ref), 'ref object is not a reference');
  3702. var num = ref.num;
  3703. if (num in this.cache) {
  3704. var cacheEntry = this.cache[num];
  3705. return cacheEntry;
  3706. }
  3707. var xrefEntry = this.getEntry(num);
  3708. // the referenced entry can be free
  3709. if (xrefEntry === null) {
  3710. return (this.cache[num] = null);
  3711. }
  3712. if (xrefEntry.uncompressed) {
  3713. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3714. } else {
  3715. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3716. }
  3717. if (isDict(xrefEntry)){
  3718. xrefEntry.objId = ref.toString();
  3719. } else if (isStream(xrefEntry)) {
  3720. xrefEntry.dict.objId = ref.toString();
  3721. }
  3722. return xrefEntry;
  3723. },
  3724. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3725. suppressEncryption) {
  3726. var gen = ref.gen;
  3727. var num = ref.num;
  3728. if (xrefEntry.gen !== gen) {
  3729. error('inconsistent generation in XRef');
  3730. }
  3731. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3732. this.stream.start);
  3733. var parser = new Parser(new Lexer(stream), true, this);
  3734. var obj1 = parser.getObj();
  3735. var obj2 = parser.getObj();
  3736. var obj3 = parser.getObj();
  3737. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3738. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3739. !isCmd(obj3)) {
  3740. error('bad XRef entry');
  3741. }
  3742. if (!isCmd(obj3, 'obj')) {
  3743. // some bad PDFs use "obj1234" and really mean 1234
  3744. if (obj3.cmd.indexOf('obj') === 0) {
  3745. num = parseInt(obj3.cmd.substring(3), 10);
  3746. if (!isNaN(num)) {
  3747. return num;
  3748. }
  3749. }
  3750. error('bad XRef entry');
  3751. }
  3752. if (this.encrypt && !suppressEncryption) {
  3753. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3754. } else {
  3755. xrefEntry = parser.getObj();
  3756. }
  3757. if (!isStream(xrefEntry)) {
  3758. this.cache[num] = xrefEntry;
  3759. }
  3760. return xrefEntry;
  3761. },
  3762. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3763. suppressEncryption) {
  3764. var tableOffset = xrefEntry.offset;
  3765. var stream = this.fetch(new Ref(tableOffset, 0));
  3766. if (!isStream(stream)) {
  3767. error('bad ObjStm stream');
  3768. }
  3769. var first = stream.dict.get('First');
  3770. var n = stream.dict.get('N');
  3771. if (!isInt(first) || !isInt(n)) {
  3772. error('invalid first and n parameters for ObjStm stream');
  3773. }
  3774. var parser = new Parser(new Lexer(stream), false, this);
  3775. parser.allowStreams = true;
  3776. var i, entries = [], num, nums = [];
  3777. // read the object numbers to populate cache
  3778. for (i = 0; i < n; ++i) {
  3779. num = parser.getObj();
  3780. if (!isInt(num)) {
  3781. error('invalid object number in the ObjStm stream: ' + num);
  3782. }
  3783. nums.push(num);
  3784. var offset = parser.getObj();
  3785. if (!isInt(offset)) {
  3786. error('invalid object offset in the ObjStm stream: ' + offset);
  3787. }
  3788. }
  3789. // read stream objects for cache
  3790. for (i = 0; i < n; ++i) {
  3791. entries.push(parser.getObj());
  3792. num = nums[i];
  3793. var entry = this.entries[num];
  3794. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3795. this.cache[num] = entries[i];
  3796. }
  3797. }
  3798. xrefEntry = entries[xrefEntry.gen];
  3799. if (xrefEntry === undefined) {
  3800. error('bad XRef entry for compressed object');
  3801. }
  3802. return xrefEntry;
  3803. },
  3804. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3805. if (!isRef(obj)) {
  3806. return Promise.resolve(obj);
  3807. }
  3808. return this.fetchAsync(obj);
  3809. },
  3810. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3811. var streamManager = this.stream.manager;
  3812. var xref = this;
  3813. return new Promise(function tryFetch(resolve, reject) {
  3814. try {
  3815. resolve(xref.fetch(ref, suppressEncryption));
  3816. } catch (e) {
  3817. if (e instanceof MissingDataException) {
  3818. streamManager.requestRange(e.begin, e.end, function () {
  3819. tryFetch(resolve, reject);
  3820. });
  3821. return;
  3822. }
  3823. reject(e);
  3824. }
  3825. });
  3826. },
  3827. getCatalogObj: function XRef_getCatalogObj() {
  3828. return this.root;
  3829. }
  3830. };
  3831. return XRef;
  3832. })();
  3833. /**
  3834. * A NameTree is like a Dict but has some advantageous properties, see the
  3835. * spec (7.9.6) for more details.
  3836. * TODO: implement all the Dict functions and make this more efficent.
  3837. */
  3838. var NameTree = (function NameTreeClosure() {
  3839. function NameTree(root, xref) {
  3840. this.root = root;
  3841. this.xref = xref;
  3842. }
  3843. NameTree.prototype = {
  3844. getAll: function NameTree_getAll() {
  3845. var dict = {};
  3846. if (!this.root) {
  3847. return dict;
  3848. }
  3849. var xref = this.xref;
  3850. // reading name tree
  3851. var processed = new RefSet();
  3852. processed.put(this.root);
  3853. var queue = [this.root];
  3854. while (queue.length > 0) {
  3855. var i, n;
  3856. var obj = xref.fetchIfRef(queue.shift());
  3857. if (!isDict(obj)) {
  3858. continue;
  3859. }
  3860. if (obj.has('Kids')) {
  3861. var kids = obj.get('Kids');
  3862. for (i = 0, n = kids.length; i < n; i++) {
  3863. var kid = kids[i];
  3864. if (processed.has(kid)) {
  3865. error('invalid destinations');
  3866. }
  3867. queue.push(kid);
  3868. processed.put(kid);
  3869. }
  3870. continue;
  3871. }
  3872. var names = obj.get('Names');
  3873. if (names) {
  3874. for (i = 0, n = names.length; i < n; i += 2) {
  3875. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3876. }
  3877. }
  3878. }
  3879. return dict;
  3880. }
  3881. };
  3882. return NameTree;
  3883. })();
  3884. /**
  3885. * "A PDF file can refer to the contents of another file by using a File
  3886. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  3887. * NOTE: Only embedded files are supported (as part of the attachments support)
  3888. * TODO: support the 'URL' file system (with caching if !/V), portable
  3889. * collections attributes and related files (/RF)
  3890. */
  3891. var FileSpec = (function FileSpecClosure() {
  3892. function FileSpec(root, xref) {
  3893. if (!root || !isDict(root)) {
  3894. return;
  3895. }
  3896. this.xref = xref;
  3897. this.root = root;
  3898. if (root.has('FS')) {
  3899. this.fs = root.get('FS');
  3900. }
  3901. this.description = root.has('Desc') ?
  3902. stringToPDFString(root.get('Desc')) :
  3903. '';
  3904. if (root.has('RF')) {
  3905. warn('Related file specifications are not supported');
  3906. }
  3907. this.contentAvailable = true;
  3908. if (!root.has('EF')) {
  3909. this.contentAvailable = false;
  3910. warn('Non-embedded file specifications are not supported');
  3911. }
  3912. }
  3913. function pickPlatformItem(dict) {
  3914. // Look for the filename in this order:
  3915. // UF, F, Unix, Mac, DOS
  3916. if (dict.has('UF')) {
  3917. return dict.get('UF');
  3918. } else if (dict.has('F')) {
  3919. return dict.get('F');
  3920. } else if (dict.has('Unix')) {
  3921. return dict.get('Unix');
  3922. } else if (dict.has('Mac')) {
  3923. return dict.get('Mac');
  3924. } else if (dict.has('DOS')) {
  3925. return dict.get('DOS');
  3926. } else {
  3927. return null;
  3928. }
  3929. }
  3930. FileSpec.prototype = {
  3931. get filename() {
  3932. if (!this._filename && this.root) {
  3933. var filename = pickPlatformItem(this.root) || 'unnamed';
  3934. this._filename = stringToPDFString(filename).
  3935. replace(/\\\\/g, '\\').
  3936. replace(/\\\//g, '/').
  3937. replace(/\\/g, '/');
  3938. }
  3939. return this._filename;
  3940. },
  3941. get content() {
  3942. if (!this.contentAvailable) {
  3943. return null;
  3944. }
  3945. if (!this.contentRef && this.root) {
  3946. this.contentRef = pickPlatformItem(this.root.get('EF'));
  3947. }
  3948. var content = null;
  3949. if (this.contentRef) {
  3950. var xref = this.xref;
  3951. var fileObj = xref.fetchIfRef(this.contentRef);
  3952. if (fileObj && isStream(fileObj)) {
  3953. content = fileObj.getBytes();
  3954. } else {
  3955. warn('Embedded file specification points to non-existing/invalid ' +
  3956. 'content');
  3957. }
  3958. } else {
  3959. warn('Embedded file specification does not have a content');
  3960. }
  3961. return content;
  3962. },
  3963. get serializable() {
  3964. return {
  3965. filename: this.filename,
  3966. content: this.content
  3967. };
  3968. }
  3969. };
  3970. return FileSpec;
  3971. })();
  3972. /**
  3973. * A helper for loading missing data in object graphs. It traverses the graph
  3974. * depth first and queues up any objects that have missing data. Once it has
  3975. * has traversed as many objects that are available it attempts to bundle the
  3976. * missing data requests and then resume from the nodes that weren't ready.
  3977. *
  3978. * NOTE: It provides protection from circular references by keeping track of
  3979. * of loaded references. However, you must be careful not to load any graphs
  3980. * that have references to the catalog or other pages since that will cause the
  3981. * entire PDF document object graph to be traversed.
  3982. */
  3983. var ObjectLoader = (function() {
  3984. function mayHaveChildren(value) {
  3985. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  3986. }
  3987. function addChildren(node, nodesToVisit) {
  3988. var value;
  3989. if (isDict(node) || isStream(node)) {
  3990. var map;
  3991. if (isDict(node)) {
  3992. map = node.map;
  3993. } else {
  3994. map = node.dict.map;
  3995. }
  3996. for (var key in map) {
  3997. value = map[key];
  3998. if (mayHaveChildren(value)) {
  3999. nodesToVisit.push(value);
  4000. }
  4001. }
  4002. } else if (isArray(node)) {
  4003. for (var i = 0, ii = node.length; i < ii; i++) {
  4004. value = node[i];
  4005. if (mayHaveChildren(value)) {
  4006. nodesToVisit.push(value);
  4007. }
  4008. }
  4009. }
  4010. }
  4011. function ObjectLoader(obj, keys, xref) {
  4012. this.obj = obj;
  4013. this.keys = keys;
  4014. this.xref = xref;
  4015. this.refSet = null;
  4016. }
  4017. ObjectLoader.prototype = {
  4018. load: function ObjectLoader_load() {
  4019. var keys = this.keys;
  4020. this.capability = createPromiseCapability();
  4021. // Don't walk the graph if all the data is already loaded.
  4022. if (!(this.xref.stream instanceof ChunkedStream) ||
  4023. this.xref.stream.getMissingChunks().length === 0) {
  4024. this.capability.resolve();
  4025. return this.capability.promise;
  4026. }
  4027. this.refSet = new RefSet();
  4028. // Setup the initial nodes to visit.
  4029. var nodesToVisit = [];
  4030. for (var i = 0; i < keys.length; i++) {
  4031. nodesToVisit.push(this.obj[keys[i]]);
  4032. }
  4033. this.walk(nodesToVisit);
  4034. return this.capability.promise;
  4035. },
  4036. walk: function ObjectLoader_walk(nodesToVisit) {
  4037. var nodesToRevisit = [];
  4038. var pendingRequests = [];
  4039. // DFS walk of the object graph.
  4040. while (nodesToVisit.length) {
  4041. var currentNode = nodesToVisit.pop();
  4042. // Only references or chunked streams can cause missing data exceptions.
  4043. if (isRef(currentNode)) {
  4044. // Skip nodes that have already been visited.
  4045. if (this.refSet.has(currentNode)) {
  4046. continue;
  4047. }
  4048. try {
  4049. var ref = currentNode;
  4050. this.refSet.put(ref);
  4051. currentNode = this.xref.fetch(currentNode);
  4052. } catch (e) {
  4053. if (!(e instanceof MissingDataException)) {
  4054. throw e;
  4055. }
  4056. nodesToRevisit.push(currentNode);
  4057. pendingRequests.push({ begin: e.begin, end: e.end });
  4058. }
  4059. }
  4060. if (currentNode && currentNode.getBaseStreams) {
  4061. var baseStreams = currentNode.getBaseStreams();
  4062. var foundMissingData = false;
  4063. for (var i = 0; i < baseStreams.length; i++) {
  4064. var stream = baseStreams[i];
  4065. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4066. foundMissingData = true;
  4067. pendingRequests.push({
  4068. begin: stream.start,
  4069. end: stream.end
  4070. });
  4071. }
  4072. }
  4073. if (foundMissingData) {
  4074. nodesToRevisit.push(currentNode);
  4075. }
  4076. }
  4077. addChildren(currentNode, nodesToVisit);
  4078. }
  4079. if (pendingRequests.length) {
  4080. this.xref.stream.manager.requestRanges(pendingRequests,
  4081. function pendingRequestCallback() {
  4082. nodesToVisit = nodesToRevisit;
  4083. for (var i = 0; i < nodesToRevisit.length; i++) {
  4084. var node = nodesToRevisit[i];
  4085. // Remove any reference nodes from the currrent refset so they
  4086. // aren't skipped when we revist them.
  4087. if (isRef(node)) {
  4088. this.refSet.remove(node);
  4089. }
  4090. }
  4091. this.walk(nodesToVisit);
  4092. }.bind(this));
  4093. return;
  4094. }
  4095. // Everything is loaded.
  4096. this.refSet = null;
  4097. this.capability.resolve();
  4098. }
  4099. };
  4100. return ObjectLoader;
  4101. })();
  4102. var ISOAdobeCharset = [
  4103. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4104. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4105. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4106. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4107. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4108. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4109. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4110. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4111. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4112. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4113. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4114. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4115. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4116. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4117. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4118. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4119. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4120. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4121. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4122. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4123. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4124. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4125. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4126. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4127. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4128. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4129. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4130. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4131. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4132. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4133. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4134. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4135. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4136. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4137. ];
  4138. var ExpertCharset = [
  4139. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4140. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4141. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4142. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4143. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4144. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4145. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4146. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4147. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4148. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4149. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4150. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4151. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4152. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4153. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4154. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4155. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4156. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4157. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4158. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4159. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4160. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4161. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4162. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4163. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4164. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4165. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4166. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4167. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4168. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4169. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4170. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4171. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4172. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4173. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4174. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4175. 'Ydieresissmall'
  4176. ];
  4177. var ExpertSubsetCharset = [
  4178. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4179. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4180. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4181. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4182. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4183. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4184. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4185. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4186. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4187. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4188. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4189. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4190. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4191. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4192. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4193. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4194. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4195. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4196. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4197. 'periodinferior', 'commainferior'
  4198. ];
  4199. var DEFAULT_ICON_SIZE = 22; // px
  4200. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4201. var Annotation = (function AnnotationClosure() {
  4202. // 12.5.5: Algorithm: Appearance streams
  4203. function getTransformMatrix(rect, bbox, matrix) {
  4204. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4205. var minX = bounds[0];
  4206. var minY = bounds[1];
  4207. var maxX = bounds[2];
  4208. var maxY = bounds[3];
  4209. if (minX === maxX || minY === maxY) {
  4210. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4211. // just apply the transform for rect
  4212. return [1, 0, 0, 1, rect[0], rect[1]];
  4213. }
  4214. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4215. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4216. return [
  4217. xRatio,
  4218. 0,
  4219. 0,
  4220. yRatio,
  4221. rect[0] - minX * xRatio,
  4222. rect[1] - minY * yRatio
  4223. ];
  4224. }
  4225. function getDefaultAppearance(dict) {
  4226. var appearanceState = dict.get('AP');
  4227. if (!isDict(appearanceState)) {
  4228. return;
  4229. }
  4230. var appearance;
  4231. var appearances = appearanceState.get('N');
  4232. if (isDict(appearances)) {
  4233. var as = dict.get('AS');
  4234. if (as && appearances.has(as.name)) {
  4235. appearance = appearances.get(as.name);
  4236. }
  4237. } else {
  4238. appearance = appearances;
  4239. }
  4240. return appearance;
  4241. }
  4242. function Annotation(params) {
  4243. var dict = params.dict;
  4244. var data = this.data = {};
  4245. data.subtype = dict.get('Subtype').name;
  4246. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4247. data.rect = Util.normalizeRect(rect);
  4248. data.annotationFlags = dict.get('F');
  4249. var color = dict.get('C');
  4250. if (isArray(color) && color.length === 3) {
  4251. // TODO(mack): currently only supporting rgb; need support different
  4252. // colorspaces
  4253. data.color = color;
  4254. } else {
  4255. data.color = [0, 0, 0];
  4256. }
  4257. // Some types of annotations have border style dict which has more
  4258. // info than the border array
  4259. if (dict.has('BS')) {
  4260. var borderStyle = dict.get('BS');
  4261. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4262. } else {
  4263. var borderArray = dict.get('Border') || [0, 0, 1];
  4264. data.borderWidth = borderArray[2] || 0;
  4265. // TODO: implement proper support for annotations with line dash patterns.
  4266. var dashArray = borderArray[3];
  4267. if (data.borderWidth > 0 && dashArray) {
  4268. if (!isArray(dashArray)) {
  4269. // Ignore the border if dashArray is not actually an array,
  4270. // this is consistent with the behaviour in Adobe Reader.
  4271. data.borderWidth = 0;
  4272. } else {
  4273. var dashArrayLength = dashArray.length;
  4274. if (dashArrayLength > 0) {
  4275. // According to the PDF specification: the elements in a dashArray
  4276. // shall be numbers that are nonnegative and not all equal to zero.
  4277. var isInvalid = false;
  4278. var numPositive = 0;
  4279. for (var i = 0; i < dashArrayLength; i++) {
  4280. var validNumber = (+dashArray[i] >= 0);
  4281. if (!validNumber) {
  4282. isInvalid = true;
  4283. break;
  4284. } else if (dashArray[i] > 0) {
  4285. numPositive++;
  4286. }
  4287. }
  4288. if (isInvalid || numPositive === 0) {
  4289. data.borderWidth = 0;
  4290. }
  4291. }
  4292. }
  4293. }
  4294. }
  4295. this.appearance = getDefaultAppearance(dict);
  4296. data.hasAppearance = !!this.appearance;
  4297. data.id = params.ref.num;
  4298. }
  4299. Annotation.prototype = {
  4300. getData: function Annotation_getData() {
  4301. return this.data;
  4302. },
  4303. isInvisible: function Annotation_isInvisible() {
  4304. var data = this.data;
  4305. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4306. return false;
  4307. } else {
  4308. return !!(data &&
  4309. data.annotationFlags && // Default: not invisible
  4310. data.annotationFlags & 0x1); // Invisible
  4311. }
  4312. },
  4313. isViewable: function Annotation_isViewable() {
  4314. var data = this.data;
  4315. return !!(!this.isInvisible() &&
  4316. data &&
  4317. (!data.annotationFlags ||
  4318. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4319. data.rect); // rectangle is necessary
  4320. },
  4321. isPrintable: function Annotation_isPrintable() {
  4322. var data = this.data;
  4323. return !!(!this.isInvisible() &&
  4324. data &&
  4325. data.annotationFlags && // Default: not printable
  4326. data.annotationFlags & 0x4 && // Print
  4327. !(data.annotationFlags & 0x2) && // Hidden
  4328. data.rect); // rectangle is necessary
  4329. },
  4330. loadResources: function Annotation_loadResources(keys) {
  4331. return new Promise(function (resolve, reject) {
  4332. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4333. if (!resources) {
  4334. resolve();
  4335. return;
  4336. }
  4337. var objectLoader = new ObjectLoader(resources.map,
  4338. keys,
  4339. resources.xref);
  4340. objectLoader.load().then(function() {
  4341. resolve(resources);
  4342. }, reject);
  4343. }, reject);
  4344. }.bind(this));
  4345. },
  4346. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4347. if (!this.appearance) {
  4348. return Promise.resolve(new OperatorList());
  4349. }
  4350. var data = this.data;
  4351. var appearanceDict = this.appearance.dict;
  4352. var resourcesPromise = this.loadResources([
  4353. 'ExtGState',
  4354. 'ColorSpace',
  4355. 'Pattern',
  4356. 'Shading',
  4357. 'XObject',
  4358. 'Font'
  4359. // ProcSet
  4360. // Properties
  4361. ]);
  4362. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4363. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4364. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4365. var self = this;
  4366. return resourcesPromise.then(function(resources) {
  4367. var opList = new OperatorList();
  4368. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4369. return evaluator.getOperatorList(self.appearance, resources, opList).
  4370. then(function () {
  4371. opList.addOp(OPS.endAnnotation, []);
  4372. self.appearance.reset();
  4373. return opList;
  4374. });
  4375. });
  4376. }
  4377. };
  4378. Annotation.getConstructor =
  4379. function Annotation_getConstructor(subtype, fieldType) {
  4380. if (!subtype) {
  4381. return;
  4382. }
  4383. // TODO(mack): Implement FreeText annotations
  4384. if (subtype === 'Link') {
  4385. return LinkAnnotation;
  4386. } else if (subtype === 'Text') {
  4387. return TextAnnotation;
  4388. } else if (subtype === 'Widget') {
  4389. if (!fieldType) {
  4390. return;
  4391. }
  4392. if (fieldType === 'Tx') {
  4393. return TextWidgetAnnotation;
  4394. } else {
  4395. return WidgetAnnotation;
  4396. }
  4397. } else {
  4398. return Annotation;
  4399. }
  4400. };
  4401. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4402. var dict = xref.fetchIfRef(ref);
  4403. if (!isDict(dict)) {
  4404. return;
  4405. }
  4406. var subtype = dict.get('Subtype');
  4407. subtype = isName(subtype) ? subtype.name : '';
  4408. if (!subtype) {
  4409. return;
  4410. }
  4411. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4412. fieldType = isName(fieldType) ? fieldType.name : '';
  4413. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4414. if (!Constructor) {
  4415. return;
  4416. }
  4417. var params = {
  4418. dict: dict,
  4419. ref: ref,
  4420. };
  4421. var annotation = new Constructor(params);
  4422. if (annotation.isViewable() || annotation.isPrintable()) {
  4423. return annotation;
  4424. } else {
  4425. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4426. warn('unimplemented annotation type: ' + subtype);
  4427. }
  4428. }
  4429. };
  4430. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4431. annotations, opList, pdfManager, partialEvaluator, intent) {
  4432. function reject(e) {
  4433. annotationsReadyCapability.reject(e);
  4434. }
  4435. var annotationsReadyCapability = createPromiseCapability();
  4436. var annotationPromises = [];
  4437. for (var i = 0, n = annotations.length; i < n; ++i) {
  4438. if (intent === 'display' && annotations[i].isViewable() ||
  4439. intent === 'print' && annotations[i].isPrintable()) {
  4440. annotationPromises.push(
  4441. annotations[i].getOperatorList(partialEvaluator));
  4442. }
  4443. }
  4444. Promise.all(annotationPromises).then(function(datas) {
  4445. opList.addOp(OPS.beginAnnotations, []);
  4446. for (var i = 0, n = datas.length; i < n; ++i) {
  4447. var annotOpList = datas[i];
  4448. opList.addOpList(annotOpList);
  4449. }
  4450. opList.addOp(OPS.endAnnotations, []);
  4451. annotationsReadyCapability.resolve();
  4452. }, reject);
  4453. return annotationsReadyCapability.promise;
  4454. };
  4455. return Annotation;
  4456. })();
  4457. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4458. function WidgetAnnotation(params) {
  4459. Annotation.call(this, params);
  4460. var dict = params.dict;
  4461. var data = this.data;
  4462. data.fieldValue = stringToPDFString(
  4463. Util.getInheritableProperty(dict, 'V') || '');
  4464. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4465. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4466. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4467. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4468. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4469. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4470. // Building the full field name by collecting the field and
  4471. // its ancestors 'T' data and joining them using '.'.
  4472. var fieldName = [];
  4473. var namedItem = dict;
  4474. var ref = params.ref;
  4475. while (namedItem) {
  4476. var parent = namedItem.get('Parent');
  4477. var parentRef = namedItem.getRaw('Parent');
  4478. var name = namedItem.get('T');
  4479. if (name) {
  4480. fieldName.unshift(stringToPDFString(name));
  4481. } else {
  4482. // The field name is absent, that means more than one field
  4483. // with the same name may exist. Replacing the empty name
  4484. // with the '`' plus index in the parent's 'Kids' array.
  4485. // This is not in the PDF spec but necessary to id the
  4486. // the input controls.
  4487. var kids = parent.get('Kids');
  4488. var j, jj;
  4489. for (j = 0, jj = kids.length; j < jj; j++) {
  4490. var kidRef = kids[j];
  4491. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4492. break;
  4493. }
  4494. }
  4495. fieldName.unshift('`' + j);
  4496. }
  4497. namedItem = parent;
  4498. ref = parentRef;
  4499. }
  4500. data.fullName = fieldName.join('.');
  4501. }
  4502. var parent = Annotation.prototype;
  4503. Util.inherit(WidgetAnnotation, Annotation, {
  4504. isViewable: function WidgetAnnotation_isViewable() {
  4505. if (this.data.fieldType === 'Sig') {
  4506. warn('unimplemented annotation type: Widget signature');
  4507. return false;
  4508. }
  4509. return parent.isViewable.call(this);
  4510. }
  4511. });
  4512. return WidgetAnnotation;
  4513. })();
  4514. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4515. function TextWidgetAnnotation(params) {
  4516. WidgetAnnotation.call(this, params);
  4517. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4518. this.data.annotationType = AnnotationType.WIDGET;
  4519. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4520. }
  4521. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4522. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4523. if (this.appearance) {
  4524. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4525. }
  4526. var opList = new OperatorList();
  4527. var data = this.data;
  4528. // Even if there is an appearance stream, ignore it. This is the
  4529. // behaviour used by Adobe Reader.
  4530. if (!data.defaultAppearance) {
  4531. return Promise.resolve(opList);
  4532. }
  4533. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4534. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4535. then(function () {
  4536. return opList;
  4537. });
  4538. }
  4539. });
  4540. return TextWidgetAnnotation;
  4541. })();
  4542. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4543. function InteractiveAnnotation(params) {
  4544. Annotation.call(this, params);
  4545. this.data.hasHtml = true;
  4546. }
  4547. Util.inherit(InteractiveAnnotation, Annotation, { });
  4548. return InteractiveAnnotation;
  4549. })();
  4550. var TextAnnotation = (function TextAnnotationClosure() {
  4551. function TextAnnotation(params) {
  4552. InteractiveAnnotation.call(this, params);
  4553. var dict = params.dict;
  4554. var data = this.data;
  4555. var content = dict.get('Contents');
  4556. var title = dict.get('T');
  4557. data.annotationType = AnnotationType.TEXT;
  4558. data.content = stringToPDFString(content || '');
  4559. data.title = stringToPDFString(title || '');
  4560. if (data.hasAppearance) {
  4561. data.name = 'NoIcon';
  4562. } else {
  4563. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4564. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4565. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4566. }
  4567. if (dict.has('C')) {
  4568. data.hasBgColor = true;
  4569. }
  4570. }
  4571. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4572. return TextAnnotation;
  4573. })();
  4574. var LinkAnnotation = (function LinkAnnotationClosure() {
  4575. function LinkAnnotation(params) {
  4576. InteractiveAnnotation.call(this, params);
  4577. var dict = params.dict;
  4578. var data = this.data;
  4579. data.annotationType = AnnotationType.LINK;
  4580. var action = dict.get('A');
  4581. if (action) {
  4582. var linkType = action.get('S').name;
  4583. if (linkType === 'URI') {
  4584. var url = action.get('URI');
  4585. if (isName(url)) {
  4586. // Some bad PDFs do not put parentheses around relative URLs.
  4587. url = '/' + url.name;
  4588. } else if (url) {
  4589. url = addDefaultProtocolToUrl(url);
  4590. }
  4591. // TODO: pdf spec mentions urls can be relative to a Base
  4592. // entry in the dictionary.
  4593. if (!isValidUrl(url, false)) {
  4594. url = '';
  4595. }
  4596. data.url = url;
  4597. } else if (linkType === 'GoTo') {
  4598. data.dest = action.get('D');
  4599. } else if (linkType === 'GoToR') {
  4600. var urlDict = action.get('F');
  4601. if (isDict(urlDict)) {
  4602. // We assume that the 'url' is a Filspec dictionary
  4603. // and fetch the url without checking any further
  4604. url = urlDict.get('F') || '';
  4605. }
  4606. // TODO: pdf reference says that GoToR
  4607. // can also have 'NewWindow' attribute
  4608. if (!isValidUrl(url, false)) {
  4609. url = '';
  4610. }
  4611. data.url = url;
  4612. data.dest = action.get('D');
  4613. } else if (linkType === 'Named') {
  4614. data.action = action.get('N').name;
  4615. } else {
  4616. warn('unrecognized link type: ' + linkType);
  4617. }
  4618. } else if (dict.has('Dest')) {
  4619. // simple destination link
  4620. var dest = dict.get('Dest');
  4621. data.dest = isName(dest) ? dest.name : dest;
  4622. }
  4623. }
  4624. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4625. function addDefaultProtocolToUrl(url) {
  4626. if (url && url.indexOf('www.') === 0) {
  4627. return ('http://' + url);
  4628. }
  4629. return url;
  4630. }
  4631. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  4632. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  4633. return false;
  4634. }
  4635. });
  4636. return LinkAnnotation;
  4637. })();
  4638. var PDFFunction = (function PDFFunctionClosure() {
  4639. var CONSTRUCT_SAMPLED = 0;
  4640. var CONSTRUCT_INTERPOLATED = 2;
  4641. var CONSTRUCT_STICHED = 3;
  4642. var CONSTRUCT_POSTSCRIPT = 4;
  4643. return {
  4644. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4645. str) {
  4646. var i, ii;
  4647. var length = 1;
  4648. for (i = 0, ii = size.length; i < ii; i++) {
  4649. length *= size[i];
  4650. }
  4651. length *= outputSize;
  4652. var array = new Array(length);
  4653. var codeSize = 0;
  4654. var codeBuf = 0;
  4655. // 32 is a valid bps so shifting won't work
  4656. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4657. var strBytes = str.getBytes((length * bps + 7) / 8);
  4658. var strIdx = 0;
  4659. for (i = 0; i < length; i++) {
  4660. while (codeSize < bps) {
  4661. codeBuf <<= 8;
  4662. codeBuf |= strBytes[strIdx++];
  4663. codeSize += 8;
  4664. }
  4665. codeSize -= bps;
  4666. array[i] = (codeBuf >> codeSize) * sampleMul;
  4667. codeBuf &= (1 << codeSize) - 1;
  4668. }
  4669. return array;
  4670. },
  4671. getIR: function PDFFunction_getIR(xref, fn) {
  4672. var dict = fn.dict;
  4673. if (!dict) {
  4674. dict = fn;
  4675. }
  4676. var types = [this.constructSampled,
  4677. null,
  4678. this.constructInterpolated,
  4679. this.constructStiched,
  4680. this.constructPostScript];
  4681. var typeNum = dict.get('FunctionType');
  4682. var typeFn = types[typeNum];
  4683. if (!typeFn) {
  4684. error('Unknown type of function');
  4685. }
  4686. return typeFn.call(this, fn, dict, xref);
  4687. },
  4688. fromIR: function PDFFunction_fromIR(IR) {
  4689. var type = IR[0];
  4690. switch (type) {
  4691. case CONSTRUCT_SAMPLED:
  4692. return this.constructSampledFromIR(IR);
  4693. case CONSTRUCT_INTERPOLATED:
  4694. return this.constructInterpolatedFromIR(IR);
  4695. case CONSTRUCT_STICHED:
  4696. return this.constructStichedFromIR(IR);
  4697. //case CONSTRUCT_POSTSCRIPT:
  4698. default:
  4699. return this.constructPostScriptFromIR(IR);
  4700. }
  4701. },
  4702. parse: function PDFFunction_parse(xref, fn) {
  4703. var IR = this.getIR(xref, fn);
  4704. return this.fromIR(IR);
  4705. },
  4706. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4707. if (!isArray(fnObj)) {
  4708. // not an array -- parsing as regular function
  4709. return this.parse(xref, fnObj);
  4710. }
  4711. var fnArray = [];
  4712. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4713. var obj = xref.fetchIfRef(fnObj[j]);
  4714. fnArray.push(PDFFunction.parse(xref, obj));
  4715. }
  4716. return function (src, srcOffset, dest, destOffset) {
  4717. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4718. fnArray[i](src, srcOffset, dest, destOffset + i);
  4719. }
  4720. };
  4721. },
  4722. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4723. function toMultiArray(arr) {
  4724. var inputLength = arr.length;
  4725. var out = [];
  4726. var index = 0;
  4727. for (var i = 0; i < inputLength; i += 2) {
  4728. out[index] = [arr[i], arr[i + 1]];
  4729. ++index;
  4730. }
  4731. return out;
  4732. }
  4733. var domain = dict.get('Domain');
  4734. var range = dict.get('Range');
  4735. if (!domain || !range) {
  4736. error('No domain or range');
  4737. }
  4738. var inputSize = domain.length / 2;
  4739. var outputSize = range.length / 2;
  4740. domain = toMultiArray(domain);
  4741. range = toMultiArray(range);
  4742. var size = dict.get('Size');
  4743. var bps = dict.get('BitsPerSample');
  4744. var order = dict.get('Order') || 1;
  4745. if (order !== 1) {
  4746. // No description how cubic spline interpolation works in PDF32000:2008
  4747. // As in poppler, ignoring order, linear interpolation may work as good
  4748. info('No support for cubic spline interpolation: ' + order);
  4749. }
  4750. var encode = dict.get('Encode');
  4751. if (!encode) {
  4752. encode = [];
  4753. for (var i = 0; i < inputSize; ++i) {
  4754. encode.push(0);
  4755. encode.push(size[i] - 1);
  4756. }
  4757. }
  4758. encode = toMultiArray(encode);
  4759. var decode = dict.get('Decode');
  4760. if (!decode) {
  4761. decode = range;
  4762. } else {
  4763. decode = toMultiArray(decode);
  4764. }
  4765. var samples = this.getSampleArray(size, outputSize, bps, str);
  4766. return [
  4767. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4768. outputSize, Math.pow(2, bps) - 1, range
  4769. ];
  4770. },
  4771. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4772. // See chapter 3, page 109 of the PDF reference
  4773. function interpolate(x, xmin, xmax, ymin, ymax) {
  4774. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4775. }
  4776. return function constructSampledFromIRResult(src, srcOffset,
  4777. dest, destOffset) {
  4778. // See chapter 3, page 110 of the PDF reference.
  4779. var m = IR[1];
  4780. var domain = IR[2];
  4781. var encode = IR[3];
  4782. var decode = IR[4];
  4783. var samples = IR[5];
  4784. var size = IR[6];
  4785. var n = IR[7];
  4786. //var mask = IR[8];
  4787. var range = IR[9];
  4788. // Building the cube vertices: its part and sample index
  4789. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4790. var cubeVertices = 1 << m;
  4791. var cubeN = new Float64Array(cubeVertices);
  4792. var cubeVertex = new Uint32Array(cubeVertices);
  4793. var i, j;
  4794. for (j = 0; j < cubeVertices; j++) {
  4795. cubeN[j] = 1;
  4796. }
  4797. var k = n, pos = 1;
  4798. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4799. for (i = 0; i < m; ++i) {
  4800. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4801. var domain_2i = domain[i][0];
  4802. var domain_2i_1 = domain[i][1];
  4803. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4804. domain_2i_1);
  4805. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4806. // Encode_2i, Encode_2i+1)
  4807. var e = interpolate(xi, domain_2i, domain_2i_1,
  4808. encode[i][0], encode[i][1]);
  4809. // e_i' = min(max(e_i, 0), Size_i - 1)
  4810. var size_i = size[i];
  4811. e = Math.min(Math.max(e, 0), size_i - 1);
  4812. // Adjusting the cube: N and vertex sample index
  4813. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4814. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4815. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4816. var offset0 = e0 * k;
  4817. var offset1 = offset0 + k; // e1 * k
  4818. for (j = 0; j < cubeVertices; j++) {
  4819. if (j & pos) {
  4820. cubeN[j] *= n1;
  4821. cubeVertex[j] += offset1;
  4822. } else {
  4823. cubeN[j] *= n0;
  4824. cubeVertex[j] += offset0;
  4825. }
  4826. }
  4827. k *= size_i;
  4828. pos <<= 1;
  4829. }
  4830. for (j = 0; j < n; ++j) {
  4831. // Sum all cube vertices' samples portions
  4832. var rj = 0;
  4833. for (i = 0; i < cubeVertices; i++) {
  4834. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4835. }
  4836. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4837. // Decode_2j, Decode_2j+1)
  4838. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  4839. // y_j = min(max(r_j, range_2j), range_2j+1)
  4840. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  4841. range[j][1]);
  4842. }
  4843. };
  4844. },
  4845. constructInterpolated: function PDFFunction_constructInterpolated(str,
  4846. dict) {
  4847. var c0 = dict.get('C0') || [0];
  4848. var c1 = dict.get('C1') || [1];
  4849. var n = dict.get('N');
  4850. if (!isArray(c0) || !isArray(c1)) {
  4851. error('Illegal dictionary for interpolated function');
  4852. }
  4853. var length = c0.length;
  4854. var diff = [];
  4855. for (var i = 0; i < length; ++i) {
  4856. diff.push(c1[i] - c0[i]);
  4857. }
  4858. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  4859. },
  4860. constructInterpolatedFromIR:
  4861. function PDFFunction_constructInterpolatedFromIR(IR) {
  4862. var c0 = IR[1];
  4863. var diff = IR[2];
  4864. var n = IR[3];
  4865. var length = diff.length;
  4866. return function constructInterpolatedFromIRResult(src, srcOffset,
  4867. dest, destOffset) {
  4868. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  4869. for (var j = 0; j < length; ++j) {
  4870. dest[destOffset + j] = c0[j] + (x * diff[j]);
  4871. }
  4872. };
  4873. },
  4874. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  4875. var domain = dict.get('Domain');
  4876. if (!domain) {
  4877. error('No domain');
  4878. }
  4879. var inputSize = domain.length / 2;
  4880. if (inputSize !== 1) {
  4881. error('Bad domain for stiched function');
  4882. }
  4883. var fnRefs = dict.get('Functions');
  4884. var fns = [];
  4885. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  4886. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  4887. }
  4888. var bounds = dict.get('Bounds');
  4889. var encode = dict.get('Encode');
  4890. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  4891. },
  4892. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  4893. var domain = IR[1];
  4894. var bounds = IR[2];
  4895. var encode = IR[3];
  4896. var fnsIR = IR[4];
  4897. var fns = [];
  4898. var tmpBuf = new Float32Array(1);
  4899. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  4900. fns.push(PDFFunction.fromIR(fnsIR[i]));
  4901. }
  4902. return function constructStichedFromIRResult(src, srcOffset,
  4903. dest, destOffset) {
  4904. var clip = function constructStichedFromIRClip(v, min, max) {
  4905. if (v > max) {
  4906. v = max;
  4907. } else if (v < min) {
  4908. v = min;
  4909. }
  4910. return v;
  4911. };
  4912. // clip to domain
  4913. var v = clip(src[srcOffset], domain[0], domain[1]);
  4914. // calulate which bound the value is in
  4915. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  4916. if (v < bounds[i]) {
  4917. break;
  4918. }
  4919. }
  4920. // encode value into domain of function
  4921. var dmin = domain[0];
  4922. if (i > 0) {
  4923. dmin = bounds[i - 1];
  4924. }
  4925. var dmax = domain[1];
  4926. if (i < bounds.length) {
  4927. dmax = bounds[i];
  4928. }
  4929. var rmin = encode[2 * i];
  4930. var rmax = encode[2 * i + 1];
  4931. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  4932. // call the appropriate function
  4933. fns[i](tmpBuf, 0, dest, destOffset);
  4934. };
  4935. },
  4936. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  4937. xref) {
  4938. var domain = dict.get('Domain');
  4939. var range = dict.get('Range');
  4940. if (!domain) {
  4941. error('No domain.');
  4942. }
  4943. if (!range) {
  4944. error('No range.');
  4945. }
  4946. var lexer = new PostScriptLexer(fn);
  4947. var parser = new PostScriptParser(lexer);
  4948. var code = parser.parse();
  4949. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  4950. },
  4951. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  4952. IR) {
  4953. var domain = IR[1];
  4954. var range = IR[2];
  4955. var code = IR[3];
  4956. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  4957. if (compiled) {
  4958. // Compiled function consists of simple expressions such as addition,
  4959. // subtraction, Math.max, and also contains 'var' and 'return'
  4960. // statements. See the generation in the PostScriptCompiler below.
  4961. /*jshint -W054 */
  4962. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  4963. }
  4964. info('Unable to compile PS function');
  4965. var numOutputs = range.length >> 1;
  4966. var numInputs = domain.length >> 1;
  4967. var evaluator = new PostScriptEvaluator(code);
  4968. // Cache the values for a big speed up, the cache size is limited though
  4969. // since the number of possible values can be huge from a PS function.
  4970. var cache = {};
  4971. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  4972. // seen in our tests.
  4973. var MAX_CACHE_SIZE = 2048 * 4;
  4974. var cache_available = MAX_CACHE_SIZE;
  4975. var tmpBuf = new Float32Array(numInputs);
  4976. return function constructPostScriptFromIRResult(src, srcOffset,
  4977. dest, destOffset) {
  4978. var i, value;
  4979. var key = '';
  4980. var input = tmpBuf;
  4981. for (i = 0; i < numInputs; i++) {
  4982. value = src[srcOffset + i];
  4983. input[i] = value;
  4984. key += value + '_';
  4985. }
  4986. var cachedValue = cache[key];
  4987. if (cachedValue !== undefined) {
  4988. cachedValue.set(dest, destOffset);
  4989. return;
  4990. }
  4991. var output = new Float32Array(numOutputs);
  4992. var stack = evaluator.execute(input);
  4993. var stackIndex = stack.length - numOutputs;
  4994. for (i = 0; i < numOutputs; i++) {
  4995. value = stack[stackIndex + i];
  4996. var bound = range[i * 2];
  4997. if (value < bound) {
  4998. value = bound;
  4999. } else {
  5000. bound = range[i * 2 +1];
  5001. if (value > bound) {
  5002. value = bound;
  5003. }
  5004. }
  5005. output[i] = value;
  5006. }
  5007. if (cache_available > 0) {
  5008. cache_available--;
  5009. cache[key] = output;
  5010. }
  5011. output.set(dest, destOffset);
  5012. };
  5013. }
  5014. };
  5015. })();
  5016. function isPDFFunction(v) {
  5017. var fnDict;
  5018. if (typeof v !== 'object') {
  5019. return false;
  5020. } else if (isDict(v)) {
  5021. fnDict = v;
  5022. } else if (isStream(v)) {
  5023. fnDict = v.dict;
  5024. } else {
  5025. return false;
  5026. }
  5027. return fnDict.has('FunctionType');
  5028. }
  5029. var PostScriptStack = (function PostScriptStackClosure() {
  5030. var MAX_STACK_SIZE = 100;
  5031. function PostScriptStack(initialStack) {
  5032. this.stack = !initialStack ? [] :
  5033. Array.prototype.slice.call(initialStack, 0);
  5034. }
  5035. PostScriptStack.prototype = {
  5036. push: function PostScriptStack_push(value) {
  5037. if (this.stack.length >= MAX_STACK_SIZE) {
  5038. error('PostScript function stack overflow.');
  5039. }
  5040. this.stack.push(value);
  5041. },
  5042. pop: function PostScriptStack_pop() {
  5043. if (this.stack.length <= 0) {
  5044. error('PostScript function stack underflow.');
  5045. }
  5046. return this.stack.pop();
  5047. },
  5048. copy: function PostScriptStack_copy(n) {
  5049. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5050. error('PostScript function stack overflow.');
  5051. }
  5052. var stack = this.stack;
  5053. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5054. stack.push(stack[i]);
  5055. }
  5056. },
  5057. index: function PostScriptStack_index(n) {
  5058. this.push(this.stack[this.stack.length - n - 1]);
  5059. },
  5060. // rotate the last n stack elements p times
  5061. roll: function PostScriptStack_roll(n, p) {
  5062. var stack = this.stack;
  5063. var l = stack.length - n;
  5064. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5065. for (i = l, j = r; i < j; i++, j--) {
  5066. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5067. }
  5068. for (i = l, j = c - 1; i < j; i++, j--) {
  5069. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5070. }
  5071. for (i = c, j = r; i < j; i++, j--) {
  5072. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5073. }
  5074. }
  5075. };
  5076. return PostScriptStack;
  5077. })();
  5078. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5079. function PostScriptEvaluator(operators) {
  5080. this.operators = operators;
  5081. }
  5082. PostScriptEvaluator.prototype = {
  5083. execute: function PostScriptEvaluator_execute(initialStack) {
  5084. var stack = new PostScriptStack(initialStack);
  5085. var counter = 0;
  5086. var operators = this.operators;
  5087. var length = operators.length;
  5088. var operator, a, b;
  5089. while (counter < length) {
  5090. operator = operators[counter++];
  5091. if (typeof operator === 'number') {
  5092. // Operator is really an operand and should be pushed to the stack.
  5093. stack.push(operator);
  5094. continue;
  5095. }
  5096. switch (operator) {
  5097. // non standard ps operators
  5098. case 'jz': // jump if false
  5099. b = stack.pop();
  5100. a = stack.pop();
  5101. if (!a) {
  5102. counter = b;
  5103. }
  5104. break;
  5105. case 'j': // jump
  5106. a = stack.pop();
  5107. counter = a;
  5108. break;
  5109. // all ps operators in alphabetical order (excluding if/ifelse)
  5110. case 'abs':
  5111. a = stack.pop();
  5112. stack.push(Math.abs(a));
  5113. break;
  5114. case 'add':
  5115. b = stack.pop();
  5116. a = stack.pop();
  5117. stack.push(a + b);
  5118. break;
  5119. case 'and':
  5120. b = stack.pop();
  5121. a = stack.pop();
  5122. if (isBool(a) && isBool(b)) {
  5123. stack.push(a && b);
  5124. } else {
  5125. stack.push(a & b);
  5126. }
  5127. break;
  5128. case 'atan':
  5129. a = stack.pop();
  5130. stack.push(Math.atan(a));
  5131. break;
  5132. case 'bitshift':
  5133. b = stack.pop();
  5134. a = stack.pop();
  5135. if (a > 0) {
  5136. stack.push(a << b);
  5137. } else {
  5138. stack.push(a >> b);
  5139. }
  5140. break;
  5141. case 'ceiling':
  5142. a = stack.pop();
  5143. stack.push(Math.ceil(a));
  5144. break;
  5145. case 'copy':
  5146. a = stack.pop();
  5147. stack.copy(a);
  5148. break;
  5149. case 'cos':
  5150. a = stack.pop();
  5151. stack.push(Math.cos(a));
  5152. break;
  5153. case 'cvi':
  5154. a = stack.pop() | 0;
  5155. stack.push(a);
  5156. break;
  5157. case 'cvr':
  5158. // noop
  5159. break;
  5160. case 'div':
  5161. b = stack.pop();
  5162. a = stack.pop();
  5163. stack.push(a / b);
  5164. break;
  5165. case 'dup':
  5166. stack.copy(1);
  5167. break;
  5168. case 'eq':
  5169. b = stack.pop();
  5170. a = stack.pop();
  5171. stack.push(a === b);
  5172. break;
  5173. case 'exch':
  5174. stack.roll(2, 1);
  5175. break;
  5176. case 'exp':
  5177. b = stack.pop();
  5178. a = stack.pop();
  5179. stack.push(Math.pow(a, b));
  5180. break;
  5181. case 'false':
  5182. stack.push(false);
  5183. break;
  5184. case 'floor':
  5185. a = stack.pop();
  5186. stack.push(Math.floor(a));
  5187. break;
  5188. case 'ge':
  5189. b = stack.pop();
  5190. a = stack.pop();
  5191. stack.push(a >= b);
  5192. break;
  5193. case 'gt':
  5194. b = stack.pop();
  5195. a = stack.pop();
  5196. stack.push(a > b);
  5197. break;
  5198. case 'idiv':
  5199. b = stack.pop();
  5200. a = stack.pop();
  5201. stack.push((a / b) | 0);
  5202. break;
  5203. case 'index':
  5204. a = stack.pop();
  5205. stack.index(a);
  5206. break;
  5207. case 'le':
  5208. b = stack.pop();
  5209. a = stack.pop();
  5210. stack.push(a <= b);
  5211. break;
  5212. case 'ln':
  5213. a = stack.pop();
  5214. stack.push(Math.log(a));
  5215. break;
  5216. case 'log':
  5217. a = stack.pop();
  5218. stack.push(Math.log(a) / Math.LN10);
  5219. break;
  5220. case 'lt':
  5221. b = stack.pop();
  5222. a = stack.pop();
  5223. stack.push(a < b);
  5224. break;
  5225. case 'mod':
  5226. b = stack.pop();
  5227. a = stack.pop();
  5228. stack.push(a % b);
  5229. break;
  5230. case 'mul':
  5231. b = stack.pop();
  5232. a = stack.pop();
  5233. stack.push(a * b);
  5234. break;
  5235. case 'ne':
  5236. b = stack.pop();
  5237. a = stack.pop();
  5238. stack.push(a !== b);
  5239. break;
  5240. case 'neg':
  5241. a = stack.pop();
  5242. stack.push(-a);
  5243. break;
  5244. case 'not':
  5245. a = stack.pop();
  5246. if (isBool(a)) {
  5247. stack.push(!a);
  5248. } else {
  5249. stack.push(~a);
  5250. }
  5251. break;
  5252. case 'or':
  5253. b = stack.pop();
  5254. a = stack.pop();
  5255. if (isBool(a) && isBool(b)) {
  5256. stack.push(a || b);
  5257. } else {
  5258. stack.push(a | b);
  5259. }
  5260. break;
  5261. case 'pop':
  5262. stack.pop();
  5263. break;
  5264. case 'roll':
  5265. b = stack.pop();
  5266. a = stack.pop();
  5267. stack.roll(a, b);
  5268. break;
  5269. case 'round':
  5270. a = stack.pop();
  5271. stack.push(Math.round(a));
  5272. break;
  5273. case 'sin':
  5274. a = stack.pop();
  5275. stack.push(Math.sin(a));
  5276. break;
  5277. case 'sqrt':
  5278. a = stack.pop();
  5279. stack.push(Math.sqrt(a));
  5280. break;
  5281. case 'sub':
  5282. b = stack.pop();
  5283. a = stack.pop();
  5284. stack.push(a - b);
  5285. break;
  5286. case 'true':
  5287. stack.push(true);
  5288. break;
  5289. case 'truncate':
  5290. a = stack.pop();
  5291. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5292. stack.push(a);
  5293. break;
  5294. case 'xor':
  5295. b = stack.pop();
  5296. a = stack.pop();
  5297. if (isBool(a) && isBool(b)) {
  5298. stack.push(a !== b);
  5299. } else {
  5300. stack.push(a ^ b);
  5301. }
  5302. break;
  5303. default:
  5304. error('Unknown operator ' + operator);
  5305. break;
  5306. }
  5307. }
  5308. return stack.stack;
  5309. }
  5310. };
  5311. return PostScriptEvaluator;
  5312. })();
  5313. // Most of the PDFs functions consist of simple operations such as:
  5314. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5315. //
  5316. // We can compile most of such programs, and at the same moment, we can
  5317. // optimize some expressions using basic math properties. Keeping track of
  5318. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5319. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5320. function AstNode(type) {
  5321. this.type = type;
  5322. }
  5323. AstNode.prototype.visit = function (visitor) {
  5324. throw new Error('abstract method');
  5325. };
  5326. function AstArgument(index, min, max) {
  5327. AstNode.call(this, 'args');
  5328. this.index = index;
  5329. this.min = min;
  5330. this.max = max;
  5331. }
  5332. AstArgument.prototype = Object.create(AstNode.prototype);
  5333. AstArgument.prototype.visit = function (visitor) {
  5334. visitor.visitArgument(this);
  5335. };
  5336. function AstLiteral(number) {
  5337. AstNode.call(this, 'literal');
  5338. this.number = number;
  5339. this.min = number;
  5340. this.max = number;
  5341. }
  5342. AstLiteral.prototype = Object.create(AstNode.prototype);
  5343. AstLiteral.prototype.visit = function (visitor) {
  5344. visitor.visitLiteral(this);
  5345. };
  5346. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5347. AstNode.call(this, 'binary');
  5348. this.op = op;
  5349. this.arg1 = arg1;
  5350. this.arg2 = arg2;
  5351. this.min = min;
  5352. this.max = max;
  5353. }
  5354. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5355. AstBinaryOperation.prototype.visit = function (visitor) {
  5356. visitor.visitBinaryOperation(this);
  5357. };
  5358. function AstMin(arg, max) {
  5359. AstNode.call(this, 'max');
  5360. this.arg = arg;
  5361. this.min = arg.min;
  5362. this.max = max;
  5363. }
  5364. AstMin.prototype = Object.create(AstNode.prototype);
  5365. AstMin.prototype.visit = function (visitor) {
  5366. visitor.visitMin(this);
  5367. };
  5368. function AstVariable(index, min, max) {
  5369. AstNode.call(this, 'var');
  5370. this.index = index;
  5371. this.min = min;
  5372. this.max = max;
  5373. }
  5374. AstVariable.prototype = Object.create(AstNode.prototype);
  5375. AstVariable.prototype.visit = function (visitor) {
  5376. visitor.visitVariable(this);
  5377. };
  5378. function AstVariableDefinition(variable, arg) {
  5379. AstNode.call(this, 'definition');
  5380. this.variable = variable;
  5381. this.arg = arg;
  5382. }
  5383. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5384. AstVariableDefinition.prototype.visit = function (visitor) {
  5385. visitor.visitVariableDefinition(this);
  5386. };
  5387. function ExpressionBuilderVisitor() {
  5388. this.parts = [];
  5389. }
  5390. ExpressionBuilderVisitor.prototype = {
  5391. visitArgument: function (arg) {
  5392. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5393. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5394. },
  5395. visitVariable: function (variable) {
  5396. this.parts.push('v', variable.index);
  5397. },
  5398. visitLiteral: function (literal) {
  5399. this.parts.push(literal.number);
  5400. },
  5401. visitBinaryOperation: function (operation) {
  5402. this.parts.push('(');
  5403. operation.arg1.visit(this);
  5404. this.parts.push(' ', operation.op, ' ');
  5405. operation.arg2.visit(this);
  5406. this.parts.push(')');
  5407. },
  5408. visitVariableDefinition: function (definition) {
  5409. this.parts.push('var ');
  5410. definition.variable.visit(this);
  5411. this.parts.push(' = ');
  5412. definition.arg.visit(this);
  5413. this.parts.push(';');
  5414. },
  5415. visitMin: function (max) {
  5416. this.parts.push('Math.min(');
  5417. max.arg.visit(this);
  5418. this.parts.push(', ', max.max, ')');
  5419. },
  5420. toString: function () {
  5421. return this.parts.join('');
  5422. }
  5423. };
  5424. function buildAddOperation(num1, num2) {
  5425. if (num2.type === 'literal' && num2.number === 0) {
  5426. // optimization: second operand is 0
  5427. return num1;
  5428. }
  5429. if (num1.type === 'literal' && num1.number === 0) {
  5430. // optimization: first operand is 0
  5431. return num2;
  5432. }
  5433. if (num2.type === 'literal' && num1.type === 'literal') {
  5434. // optimization: operands operand are literals
  5435. return new AstLiteral(num1.number + num2.number);
  5436. }
  5437. return new AstBinaryOperation('+', num1, num2,
  5438. num1.min + num2.min, num1.max + num2.max);
  5439. }
  5440. function buildMulOperation(num1, num2) {
  5441. if (num2.type === 'literal') {
  5442. // optimization: second operands is a literal...
  5443. if (num2.number === 0) {
  5444. return new AstLiteral(0); // and it's 0
  5445. } else if (num2.number === 1) {
  5446. return num1; // and it's 1
  5447. } else if (num1.type === 'literal') {
  5448. // ... and first operands is a literal too
  5449. return new AstLiteral(num1.number * num2.number);
  5450. }
  5451. }
  5452. if (num1.type === 'literal') {
  5453. // optimization: first operands is a literal...
  5454. if (num1.number === 0) {
  5455. return new AstLiteral(0); // and it's 0
  5456. } else if (num1.number === 1) {
  5457. return num2; // and it's 1
  5458. }
  5459. }
  5460. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5461. num1.max * num2.min, num1.max * num2.max);
  5462. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5463. num1.max * num2.min, num1.max * num2.max);
  5464. return new AstBinaryOperation('*', num1, num2, min, max);
  5465. }
  5466. function buildSubOperation(num1, num2) {
  5467. if (num2.type === 'literal') {
  5468. // optimization: second operands is a literal...
  5469. if (num2.number === 0) {
  5470. return num1; // ... and it's 0
  5471. } else if (num1.type === 'literal') {
  5472. // ... and first operands is a literal too
  5473. return new AstLiteral(num1.number - num2.number);
  5474. }
  5475. }
  5476. if (num2.type === 'binary' && num2.op === '-' &&
  5477. num1.type === 'literal' && num1.number === 1 &&
  5478. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5479. // optimization for case: 1 - (1 - x)
  5480. return num2.arg2;
  5481. }
  5482. return new AstBinaryOperation('-', num1, num2,
  5483. num1.min - num2.max, num1.max - num2.min);
  5484. }
  5485. function buildMinOperation(num1, max) {
  5486. if (num1.min >= max) {
  5487. // optimization: num1 min value is not less than required max
  5488. return new AstLiteral(max); // just returning max
  5489. } else if (num1.max <= max) {
  5490. // optimization: num1 max value is not greater than required max
  5491. return num1; // just returning an argument
  5492. }
  5493. return new AstMin(num1, max);
  5494. }
  5495. function PostScriptCompiler() {}
  5496. PostScriptCompiler.prototype = {
  5497. compile: function PostScriptCompiler_compile(code, domain, range) {
  5498. var stack = [];
  5499. var i, ii;
  5500. var instructions = [];
  5501. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5502. var lastRegister = 0;
  5503. var n, j, min, max;
  5504. var num1, num2, ast1, ast2, tmpVar, item;
  5505. for (i = 0; i < inputSize; i++) {
  5506. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5507. }
  5508. for (i = 0, ii = code.length; i < ii; i++) {
  5509. item = code[i];
  5510. if (typeof item === 'number') {
  5511. stack.push(new AstLiteral(item));
  5512. continue;
  5513. }
  5514. switch (item) {
  5515. case 'add':
  5516. if (stack.length < 2) {
  5517. return null;
  5518. }
  5519. num2 = stack.pop();
  5520. num1 = stack.pop();
  5521. stack.push(buildAddOperation(num1, num2));
  5522. break;
  5523. case 'cvr':
  5524. if (stack.length < 1) {
  5525. return null;
  5526. }
  5527. break;
  5528. case 'mul':
  5529. if (stack.length < 2) {
  5530. return null;
  5531. }
  5532. num2 = stack.pop();
  5533. num1 = stack.pop();
  5534. stack.push(buildMulOperation(num1, num2));
  5535. break;
  5536. case 'sub':
  5537. if (stack.length < 2) {
  5538. return null;
  5539. }
  5540. num2 = stack.pop();
  5541. num1 = stack.pop();
  5542. stack.push(buildSubOperation(num1, num2));
  5543. break;
  5544. case 'exch':
  5545. if (stack.length < 2) {
  5546. return null;
  5547. }
  5548. ast1 = stack.pop(); ast2 = stack.pop();
  5549. stack.push(ast1, ast2);
  5550. break;
  5551. case 'pop':
  5552. if (stack.length < 1) {
  5553. return null;
  5554. }
  5555. stack.pop();
  5556. break;
  5557. case 'index':
  5558. if (stack.length < 1) {
  5559. return null;
  5560. }
  5561. num1 = stack.pop();
  5562. if (num1.type !== 'literal') {
  5563. return null;
  5564. }
  5565. n = num1.number;
  5566. if (n < 0 || (n|0) !== n || stack.length < n) {
  5567. return null;
  5568. }
  5569. ast1 = stack[stack.length - n - 1];
  5570. if (ast1.type === 'literal' || ast1.type === 'var') {
  5571. stack.push(ast1);
  5572. break;
  5573. }
  5574. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5575. stack[stack.length - n - 1] = tmpVar;
  5576. stack.push(tmpVar);
  5577. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5578. break;
  5579. case 'dup':
  5580. if (stack.length < 1) {
  5581. return null;
  5582. }
  5583. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5584. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5585. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5586. // special case of the commands sequence for the min operation
  5587. num1 = stack.pop();
  5588. stack.push(buildMinOperation(num1, code[i + 1]));
  5589. i += 6;
  5590. break;
  5591. }
  5592. ast1 = stack[stack.length - 1];
  5593. if (ast1.type === 'literal' || ast1.type === 'var') {
  5594. // we don't have to save into intermediate variable a literal or
  5595. // variable.
  5596. stack.push(ast1);
  5597. break;
  5598. }
  5599. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5600. stack[stack.length - 1] = tmpVar;
  5601. stack.push(tmpVar);
  5602. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5603. break;
  5604. case 'roll':
  5605. if (stack.length < 2) {
  5606. return null;
  5607. }
  5608. num2 = stack.pop();
  5609. num1 = stack.pop();
  5610. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5611. // both roll operands must be numbers
  5612. return null;
  5613. }
  5614. j = num2.number;
  5615. n = num1.number;
  5616. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5617. // ... and integers
  5618. return null;
  5619. }
  5620. j = ((j % n) + n) % n;
  5621. if (j === 0) {
  5622. break; // just skipping -- there are nothing to rotate
  5623. }
  5624. Array.prototype.push.apply(stack,
  5625. stack.splice(stack.length - n, n - j));
  5626. break;
  5627. default:
  5628. return null; // unsupported operator
  5629. }
  5630. }
  5631. if (stack.length !== outputSize) {
  5632. return null;
  5633. }
  5634. var result = [];
  5635. instructions.forEach(function (instruction) {
  5636. var statementBuilder = new ExpressionBuilderVisitor();
  5637. instruction.visit(statementBuilder);
  5638. result.push(statementBuilder.toString());
  5639. });
  5640. stack.forEach(function (expr, i) {
  5641. var statementBuilder = new ExpressionBuilderVisitor();
  5642. expr.visit(statementBuilder);
  5643. var min = range[i * 2], max = range[i * 2 + 1];
  5644. var out = [statementBuilder.toString()];
  5645. if (min > expr.min) {
  5646. out.unshift('Math.max(', min, ', ');
  5647. out.push(')');
  5648. }
  5649. if (max < expr.max) {
  5650. out.unshift('Math.min(', max, ', ');
  5651. out.push(')');
  5652. }
  5653. out.unshift('dest[destOffset + ', i, '] = ');
  5654. out.push(';');
  5655. result.push(out.join(''));
  5656. });
  5657. return result.join('\n');
  5658. }
  5659. };
  5660. return PostScriptCompiler;
  5661. })();
  5662. var ColorSpace = (function ColorSpaceClosure() {
  5663. // Constructor should define this.numComps, this.defaultColor, this.name
  5664. function ColorSpace() {
  5665. error('should not call ColorSpace constructor');
  5666. }
  5667. ColorSpace.prototype = {
  5668. /**
  5669. * Converts the color value to the RGB color. The color components are
  5670. * located in the src array starting from the srcOffset. Returns the array
  5671. * of the rgb components, each value ranging from [0,255].
  5672. */
  5673. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5674. var rgb = new Uint8Array(3);
  5675. this.getRgbItem(src, srcOffset, rgb, 0);
  5676. return rgb;
  5677. },
  5678. /**
  5679. * Converts the color value to the RGB color, similar to the getRgb method.
  5680. * The result placed into the dest array starting from the destOffset.
  5681. */
  5682. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5683. dest, destOffset) {
  5684. error('Should not call ColorSpace.getRgbItem');
  5685. },
  5686. /**
  5687. * Converts the specified number of the color values to the RGB colors.
  5688. * The colors are located in the src array starting from the srcOffset.
  5689. * The result is placed into the dest array starting from the destOffset.
  5690. * The src array items shall be in [0,2^bits) range, the dest array items
  5691. * will be in [0,255] range. alpha01 indicates how many alpha components
  5692. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5693. * array).
  5694. */
  5695. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5696. dest, destOffset, bits,
  5697. alpha01) {
  5698. error('Should not call ColorSpace.getRgbBuffer');
  5699. },
  5700. /**
  5701. * Determines the number of bytes required to store the result of the
  5702. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5703. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5704. */
  5705. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5706. alpha01) {
  5707. error('Should not call ColorSpace.getOutputLength');
  5708. },
  5709. /**
  5710. * Returns true if source data will be equal the result/output data.
  5711. */
  5712. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5713. return false;
  5714. },
  5715. /**
  5716. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5717. * how many alpha components there are in the dest array; it will be either
  5718. * 0 (RGB array) or 1 (RGBA array).
  5719. */
  5720. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5721. originalHeight, width, height,
  5722. actualHeight, bpc, comps, alpha01) {
  5723. var count = originalWidth * originalHeight;
  5724. var rgbBuf = null;
  5725. var numComponentColors = 1 << bpc;
  5726. var needsResizing = originalHeight !== height || originalWidth !== width;
  5727. var i, ii;
  5728. if (this.isPassthrough(bpc)) {
  5729. rgbBuf = comps;
  5730. } else if (this.numComps === 1 && count > numComponentColors &&
  5731. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5732. // Optimization: create a color map when there is just one component and
  5733. // we are converting more colors than the size of the color map. We
  5734. // don't build the map if the colorspace is gray or rgb since those
  5735. // methods are faster than building a map. This mainly offers big speed
  5736. // ups for indexed and alternate colorspaces.
  5737. //
  5738. // TODO it may be worth while to cache the color map. While running
  5739. // testing I never hit a cache so I will leave that out for now (perhaps
  5740. // we are reparsing colorspaces too much?).
  5741. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5742. new Uint16Array(numComponentColors);
  5743. var key;
  5744. for (i = 0; i < numComponentColors; i++) {
  5745. allColors[i] = i;
  5746. }
  5747. var colorMap = new Uint8Array(numComponentColors * 3);
  5748. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5749. /* alpha01 = */ 0);
  5750. var destPos, rgbPos;
  5751. if (!needsResizing) {
  5752. // Fill in the RGB values directly into |dest|.
  5753. destPos = 0;
  5754. for (i = 0; i < count; ++i) {
  5755. key = comps[i] * 3;
  5756. dest[destPos++] = colorMap[key];
  5757. dest[destPos++] = colorMap[key + 1];
  5758. dest[destPos++] = colorMap[key + 2];
  5759. destPos += alpha01;
  5760. }
  5761. } else {
  5762. rgbBuf = new Uint8Array(count * 3);
  5763. rgbPos = 0;
  5764. for (i = 0; i < count; ++i) {
  5765. key = comps[i] * 3;
  5766. rgbBuf[rgbPos++] = colorMap[key];
  5767. rgbBuf[rgbPos++] = colorMap[key + 1];
  5768. rgbBuf[rgbPos++] = colorMap[key + 2];
  5769. }
  5770. }
  5771. } else {
  5772. if (!needsResizing) {
  5773. // Fill in the RGB values directly into |dest|.
  5774. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5775. alpha01);
  5776. } else {
  5777. rgbBuf = new Uint8Array(count * 3);
  5778. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5779. /* alpha01 = */ 0);
  5780. }
  5781. }
  5782. if (rgbBuf) {
  5783. if (needsResizing) {
  5784. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5785. height, dest, alpha01);
  5786. } else {
  5787. rgbPos = 0;
  5788. destPos = 0;
  5789. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5790. dest[destPos++] = rgbBuf[rgbPos++];
  5791. dest[destPos++] = rgbBuf[rgbPos++];
  5792. dest[destPos++] = rgbBuf[rgbPos++];
  5793. destPos += alpha01;
  5794. }
  5795. }
  5796. }
  5797. },
  5798. /**
  5799. * True if the colorspace has components in the default range of [0, 1].
  5800. * This should be true for all colorspaces except for lab color spaces
  5801. * which are [0,100], [-128, 127], [-128, 127].
  5802. */
  5803. usesZeroToOneRange: true
  5804. };
  5805. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5806. var IR = ColorSpace.parseToIR(cs, xref, res);
  5807. if (IR instanceof AlternateCS) {
  5808. return IR;
  5809. }
  5810. return ColorSpace.fromIR(IR);
  5811. };
  5812. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5813. var name = isArray(IR) ? IR[0] : IR;
  5814. var whitePoint, blackPoint, gamma;
  5815. switch (name) {
  5816. case 'DeviceGrayCS':
  5817. return this.singletons.gray;
  5818. case 'DeviceRgbCS':
  5819. return this.singletons.rgb;
  5820. case 'DeviceCmykCS':
  5821. return this.singletons.cmyk;
  5822. case 'CalGrayCS':
  5823. whitePoint = IR[1].WhitePoint;
  5824. blackPoint = IR[1].BlackPoint;
  5825. gamma = IR[1].Gamma;
  5826. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5827. case 'CalRGBCS':
  5828. whitePoint = IR[1].WhitePoint;
  5829. blackPoint = IR[1].BlackPoint;
  5830. gamma = IR[1].Gamma;
  5831. var matrix = IR[1].Matrix;
  5832. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5833. case 'PatternCS':
  5834. var basePatternCS = IR[1];
  5835. if (basePatternCS) {
  5836. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5837. }
  5838. return new PatternCS(basePatternCS);
  5839. case 'IndexedCS':
  5840. var baseIndexedCS = IR[1];
  5841. var hiVal = IR[2];
  5842. var lookup = IR[3];
  5843. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  5844. case 'AlternateCS':
  5845. var numComps = IR[1];
  5846. var alt = IR[2];
  5847. var tintFnIR = IR[3];
  5848. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  5849. PDFFunction.fromIR(tintFnIR));
  5850. case 'LabCS':
  5851. whitePoint = IR[1].WhitePoint;
  5852. blackPoint = IR[1].BlackPoint;
  5853. var range = IR[1].Range;
  5854. return new LabCS(whitePoint, blackPoint, range);
  5855. default:
  5856. error('Unknown name ' + name);
  5857. }
  5858. return null;
  5859. };
  5860. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  5861. if (isName(cs)) {
  5862. var colorSpaces = res.get('ColorSpace');
  5863. if (isDict(colorSpaces)) {
  5864. var refcs = colorSpaces.get(cs.name);
  5865. if (refcs) {
  5866. cs = refcs;
  5867. }
  5868. }
  5869. }
  5870. cs = xref.fetchIfRef(cs);
  5871. var mode;
  5872. if (isName(cs)) {
  5873. mode = cs.name;
  5874. this.mode = mode;
  5875. switch (mode) {
  5876. case 'DeviceGray':
  5877. case 'G':
  5878. return 'DeviceGrayCS';
  5879. case 'DeviceRGB':
  5880. case 'RGB':
  5881. return 'DeviceRgbCS';
  5882. case 'DeviceCMYK':
  5883. case 'CMYK':
  5884. return 'DeviceCmykCS';
  5885. case 'Pattern':
  5886. return ['PatternCS', null];
  5887. default:
  5888. error('unrecognized colorspace ' + mode);
  5889. }
  5890. } else if (isArray(cs)) {
  5891. mode = cs[0].name;
  5892. this.mode = mode;
  5893. var numComps, params;
  5894. switch (mode) {
  5895. case 'DeviceGray':
  5896. case 'G':
  5897. return 'DeviceGrayCS';
  5898. case 'DeviceRGB':
  5899. case 'RGB':
  5900. return 'DeviceRgbCS';
  5901. case 'DeviceCMYK':
  5902. case 'CMYK':
  5903. return 'DeviceCmykCS';
  5904. case 'CalGray':
  5905. params = cs[1].getAll();
  5906. return ['CalGrayCS', params];
  5907. case 'CalRGB':
  5908. params = cs[1].getAll();
  5909. return ['CalRGBCS', params];
  5910. case 'ICCBased':
  5911. var stream = xref.fetchIfRef(cs[1]);
  5912. var dict = stream.dict;
  5913. numComps = dict.get('N');
  5914. if (numComps === 1) {
  5915. return 'DeviceGrayCS';
  5916. } else if (numComps === 3) {
  5917. return 'DeviceRgbCS';
  5918. } else if (numComps === 4) {
  5919. return 'DeviceCmykCS';
  5920. }
  5921. break;
  5922. case 'Pattern':
  5923. var basePatternCS = cs[1];
  5924. if (basePatternCS) {
  5925. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  5926. }
  5927. return ['PatternCS', basePatternCS];
  5928. case 'Indexed':
  5929. case 'I':
  5930. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  5931. var hiVal = cs[2] + 1;
  5932. var lookup = xref.fetchIfRef(cs[3]);
  5933. if (isStream(lookup)) {
  5934. lookup = lookup.getBytes();
  5935. }
  5936. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  5937. case 'Separation':
  5938. case 'DeviceN':
  5939. var name = cs[1];
  5940. numComps = 1;
  5941. if (isName(name)) {
  5942. numComps = 1;
  5943. } else if (isArray(name)) {
  5944. numComps = name.length;
  5945. }
  5946. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  5947. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  5948. return ['AlternateCS', numComps, alt, tintFnIR];
  5949. case 'Lab':
  5950. params = cs[1].getAll();
  5951. return ['LabCS', params];
  5952. default:
  5953. error('unimplemented color space object "' + mode + '"');
  5954. }
  5955. } else {
  5956. error('unrecognized color space object: "' + cs + '"');
  5957. }
  5958. return null;
  5959. };
  5960. /**
  5961. * Checks if a decode map matches the default decode map for a color space.
  5962. * This handles the general decode maps where there are two values per
  5963. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  5964. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  5965. * slightly different.
  5966. * @param {Array} decode Decode map (usually from an image).
  5967. * @param {Number} n Number of components the color space has.
  5968. */
  5969. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  5970. if (!decode) {
  5971. return true;
  5972. }
  5973. if (n * 2 !== decode.length) {
  5974. warn('The decode map is not the correct length');
  5975. return true;
  5976. }
  5977. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  5978. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  5979. return false;
  5980. }
  5981. }
  5982. return true;
  5983. };
  5984. ColorSpace.singletons = {
  5985. get gray() {
  5986. return shadow(this, 'gray', new DeviceGrayCS());
  5987. },
  5988. get rgb() {
  5989. return shadow(this, 'rgb', new DeviceRgbCS());
  5990. },
  5991. get cmyk() {
  5992. return shadow(this, 'cmyk', new DeviceCmykCS());
  5993. }
  5994. };
  5995. return ColorSpace;
  5996. })();
  5997. /**
  5998. * Alternate color space handles both Separation and DeviceN color spaces. A
  5999. * Separation color space is actually just a DeviceN with one color component.
  6000. * Both color spaces use a tinting function to convert colors to a base color
  6001. * space.
  6002. */
  6003. var AlternateCS = (function AlternateCSClosure() {
  6004. function AlternateCS(numComps, base, tintFn) {
  6005. this.name = 'Alternate';
  6006. this.numComps = numComps;
  6007. this.defaultColor = new Float32Array(numComps);
  6008. for (var i = 0; i < numComps; ++i) {
  6009. this.defaultColor[i] = 1;
  6010. }
  6011. this.base = base;
  6012. this.tintFn = tintFn;
  6013. this.tmpBuf = new Float32Array(base.numComps);
  6014. }
  6015. AlternateCS.prototype = {
  6016. getRgb: ColorSpace.prototype.getRgb,
  6017. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6018. dest, destOffset) {
  6019. var tmpBuf = this.tmpBuf;
  6020. this.tintFn(src, srcOffset, tmpBuf, 0);
  6021. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6022. },
  6023. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6024. dest, destOffset, bits,
  6025. alpha01) {
  6026. var tintFn = this.tintFn;
  6027. var base = this.base;
  6028. var scale = 1 / ((1 << bits) - 1);
  6029. var baseNumComps = base.numComps;
  6030. var usesZeroToOneRange = base.usesZeroToOneRange;
  6031. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6032. alpha01 === 0;
  6033. var pos = isPassthrough ? destOffset : 0;
  6034. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6035. var numComps = this.numComps;
  6036. var scaled = new Float32Array(numComps);
  6037. var tinted = new Float32Array(baseNumComps);
  6038. var i, j;
  6039. if (usesZeroToOneRange) {
  6040. for (i = 0; i < count; i++) {
  6041. for (j = 0; j < numComps; j++) {
  6042. scaled[j] = src[srcOffset++] * scale;
  6043. }
  6044. tintFn(scaled, 0, tinted, 0);
  6045. for (j = 0; j < baseNumComps; j++) {
  6046. baseBuf[pos++] = tinted[j] * 255;
  6047. }
  6048. }
  6049. } else {
  6050. for (i = 0; i < count; i++) {
  6051. for (j = 0; j < numComps; j++) {
  6052. scaled[j] = src[srcOffset++] * scale;
  6053. }
  6054. tintFn(scaled, 0, tinted, 0);
  6055. base.getRgbItem(tinted, 0, baseBuf, pos);
  6056. pos += baseNumComps;
  6057. }
  6058. }
  6059. if (!isPassthrough) {
  6060. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6061. }
  6062. },
  6063. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6064. alpha01) {
  6065. return this.base.getOutputLength(inputLength *
  6066. this.base.numComps / this.numComps,
  6067. alpha01);
  6068. },
  6069. isPassthrough: ColorSpace.prototype.isPassthrough,
  6070. fillRgb: ColorSpace.prototype.fillRgb,
  6071. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6072. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6073. },
  6074. usesZeroToOneRange: true
  6075. };
  6076. return AlternateCS;
  6077. })();
  6078. var PatternCS = (function PatternCSClosure() {
  6079. function PatternCS(baseCS) {
  6080. this.name = 'Pattern';
  6081. this.base = baseCS;
  6082. }
  6083. PatternCS.prototype = {};
  6084. return PatternCS;
  6085. })();
  6086. var IndexedCS = (function IndexedCSClosure() {
  6087. function IndexedCS(base, highVal, lookup) {
  6088. this.name = 'Indexed';
  6089. this.numComps = 1;
  6090. this.defaultColor = new Uint8Array([0]);
  6091. this.base = base;
  6092. this.highVal = highVal;
  6093. var baseNumComps = base.numComps;
  6094. var length = baseNumComps * highVal;
  6095. var lookupArray;
  6096. if (isStream(lookup)) {
  6097. lookupArray = new Uint8Array(length);
  6098. var bytes = lookup.getBytes(length);
  6099. lookupArray.set(bytes);
  6100. } else if (isString(lookup)) {
  6101. lookupArray = new Uint8Array(length);
  6102. for (var i = 0; i < length; ++i) {
  6103. lookupArray[i] = lookup.charCodeAt(i);
  6104. }
  6105. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6106. lookupArray = lookup;
  6107. } else {
  6108. error('Unrecognized lookup table: ' + lookup);
  6109. }
  6110. this.lookup = lookupArray;
  6111. }
  6112. IndexedCS.prototype = {
  6113. getRgb: ColorSpace.prototype.getRgb,
  6114. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6115. dest, destOffset) {
  6116. var numComps = this.base.numComps;
  6117. var start = src[srcOffset] * numComps;
  6118. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6119. },
  6120. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6121. dest, destOffset, bits,
  6122. alpha01) {
  6123. var base = this.base;
  6124. var numComps = base.numComps;
  6125. var outputDelta = base.getOutputLength(numComps, alpha01);
  6126. var lookup = this.lookup;
  6127. for (var i = 0; i < count; ++i) {
  6128. var lookupPos = src[srcOffset++] * numComps;
  6129. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6130. destOffset += outputDelta;
  6131. }
  6132. },
  6133. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6134. return this.base.getOutputLength(inputLength * this.base.numComps,
  6135. alpha01);
  6136. },
  6137. isPassthrough: ColorSpace.prototype.isPassthrough,
  6138. fillRgb: ColorSpace.prototype.fillRgb,
  6139. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6140. // indexed color maps shouldn't be changed
  6141. return true;
  6142. },
  6143. usesZeroToOneRange: true
  6144. };
  6145. return IndexedCS;
  6146. })();
  6147. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6148. function DeviceGrayCS() {
  6149. this.name = 'DeviceGray';
  6150. this.numComps = 1;
  6151. this.defaultColor = new Float32Array([0]);
  6152. }
  6153. DeviceGrayCS.prototype = {
  6154. getRgb: ColorSpace.prototype.getRgb,
  6155. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6156. dest, destOffset) {
  6157. var c = (src[srcOffset] * 255) | 0;
  6158. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6159. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6160. },
  6161. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6162. dest, destOffset, bits,
  6163. alpha01) {
  6164. var scale = 255 / ((1 << bits) - 1);
  6165. var j = srcOffset, q = destOffset;
  6166. for (var i = 0; i < count; ++i) {
  6167. var c = (scale * src[j++]) | 0;
  6168. dest[q++] = c;
  6169. dest[q++] = c;
  6170. dest[q++] = c;
  6171. q += alpha01;
  6172. }
  6173. },
  6174. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6175. alpha01) {
  6176. return inputLength * (3 + alpha01);
  6177. },
  6178. isPassthrough: ColorSpace.prototype.isPassthrough,
  6179. fillRgb: ColorSpace.prototype.fillRgb,
  6180. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6181. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6182. },
  6183. usesZeroToOneRange: true
  6184. };
  6185. return DeviceGrayCS;
  6186. })();
  6187. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6188. function DeviceRgbCS() {
  6189. this.name = 'DeviceRGB';
  6190. this.numComps = 3;
  6191. this.defaultColor = new Float32Array([0, 0, 0]);
  6192. }
  6193. DeviceRgbCS.prototype = {
  6194. getRgb: ColorSpace.prototype.getRgb,
  6195. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6196. dest, destOffset) {
  6197. var r = (src[srcOffset] * 255) | 0;
  6198. var g = (src[srcOffset + 1] * 255) | 0;
  6199. var b = (src[srcOffset + 2] * 255) | 0;
  6200. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6201. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6202. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6203. },
  6204. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6205. dest, destOffset, bits,
  6206. alpha01) {
  6207. if (bits === 8 && alpha01 === 0) {
  6208. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6209. return;
  6210. }
  6211. var scale = 255 / ((1 << bits) - 1);
  6212. var j = srcOffset, q = destOffset;
  6213. for (var i = 0; i < count; ++i) {
  6214. dest[q++] = (scale * src[j++]) | 0;
  6215. dest[q++] = (scale * src[j++]) | 0;
  6216. dest[q++] = (scale * src[j++]) | 0;
  6217. q += alpha01;
  6218. }
  6219. },
  6220. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6221. alpha01) {
  6222. return (inputLength * (3 + alpha01) / 3) | 0;
  6223. },
  6224. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6225. return bits === 8;
  6226. },
  6227. fillRgb: ColorSpace.prototype.fillRgb,
  6228. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6229. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6230. },
  6231. usesZeroToOneRange: true
  6232. };
  6233. return DeviceRgbCS;
  6234. })();
  6235. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6236. // The coefficients below was found using numerical analysis: the method of
  6237. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6238. // where color_value is the tabular value from the table of sampled RGB colors
  6239. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6240. // CMYK color conversion using the estimation below:
  6241. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6242. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6243. var c = src[srcOffset + 0] * srcScale;
  6244. var m = src[srcOffset + 1] * srcScale;
  6245. var y = src[srcOffset + 2] * srcScale;
  6246. var k = src[srcOffset + 3] * srcScale;
  6247. var r =
  6248. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6249. 18.82290502165302 * y + 212.25662451639585 * k +
  6250. -285.2331026137004) +
  6251. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6252. -17.873870861415444 * k - 5.497006427196366) +
  6253. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6254. 17.5119270841813) +
  6255. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6256. var g =
  6257. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6258. 6.871425592049007 * y + 31.159100130055922 * k +
  6259. -79.2970844816548) +
  6260. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6261. 131.35250912493976 * k - 190.9453302588951) +
  6262. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6263. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6264. var b =
  6265. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6266. 30.89978309703729 * y - 0.23883238689178934 * k +
  6267. -14.183576799673286) +
  6268. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6269. 50.606957656360734 * k - 112.23884253719248) +
  6270. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6271. -193.58209356861505) +
  6272. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6273. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6274. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6275. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6276. }
  6277. function DeviceCmykCS() {
  6278. this.name = 'DeviceCMYK';
  6279. this.numComps = 4;
  6280. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6281. }
  6282. DeviceCmykCS.prototype = {
  6283. getRgb: ColorSpace.prototype.getRgb,
  6284. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6285. dest, destOffset) {
  6286. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6287. },
  6288. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6289. dest, destOffset, bits,
  6290. alpha01) {
  6291. var scale = 1 / ((1 << bits) - 1);
  6292. for (var i = 0; i < count; i++) {
  6293. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6294. srcOffset += 4;
  6295. destOffset += 3 + alpha01;
  6296. }
  6297. },
  6298. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6299. alpha01) {
  6300. return (inputLength / 4 * (3 + alpha01)) | 0;
  6301. },
  6302. isPassthrough: ColorSpace.prototype.isPassthrough,
  6303. fillRgb: ColorSpace.prototype.fillRgb,
  6304. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6305. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6306. },
  6307. usesZeroToOneRange: true
  6308. };
  6309. return DeviceCmykCS;
  6310. })();
  6311. //
  6312. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6313. //
  6314. var CalGrayCS = (function CalGrayCSClosure() {
  6315. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6316. this.name = 'CalGray';
  6317. this.numComps = 1;
  6318. this.defaultColor = new Float32Array([0]);
  6319. if (!whitePoint) {
  6320. error('WhitePoint missing - required for color space CalGray');
  6321. }
  6322. blackPoint = blackPoint || [0, 0, 0];
  6323. gamma = gamma || 1;
  6324. // Translate arguments to spec variables.
  6325. this.XW = whitePoint[0];
  6326. this.YW = whitePoint[1];
  6327. this.ZW = whitePoint[2];
  6328. this.XB = blackPoint[0];
  6329. this.YB = blackPoint[1];
  6330. this.ZB = blackPoint[2];
  6331. this.G = gamma;
  6332. // Validate variables as per spec.
  6333. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6334. error('Invalid WhitePoint components for ' + this.name +
  6335. ', no fallback available');
  6336. }
  6337. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6338. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6339. this.XB = this.YB = this.ZB = 0;
  6340. }
  6341. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6342. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6343. ', ZB: ' + this.ZB + ', only default values are supported.');
  6344. }
  6345. if (this.G < 1) {
  6346. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6347. ', falling back to default');
  6348. this.G = 1;
  6349. }
  6350. }
  6351. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6352. // A represents a gray component of a calibrated gray space.
  6353. // A <---> AG in the spec
  6354. var A = src[srcOffset] * scale;
  6355. var AG = Math.pow(A, cs.G);
  6356. // Computes L as per spec. ( = cs.YW * AG )
  6357. // Except if other than default BlackPoint values are used.
  6358. var L = cs.YW * AG;
  6359. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6360. // Convert values to rgb range [0, 255].
  6361. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6362. dest[destOffset] = val;
  6363. dest[destOffset + 1] = val;
  6364. dest[destOffset + 2] = val;
  6365. }
  6366. CalGrayCS.prototype = {
  6367. getRgb: ColorSpace.prototype.getRgb,
  6368. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6369. dest, destOffset) {
  6370. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6371. },
  6372. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6373. dest, destOffset, bits,
  6374. alpha01) {
  6375. var scale = 1 / ((1 << bits) - 1);
  6376. for (var i = 0; i < count; ++i) {
  6377. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6378. srcOffset += 1;
  6379. destOffset += 3 + alpha01;
  6380. }
  6381. },
  6382. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6383. return inputLength * (3 + alpha01);
  6384. },
  6385. isPassthrough: ColorSpace.prototype.isPassthrough,
  6386. fillRgb: ColorSpace.prototype.fillRgb,
  6387. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6388. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6389. },
  6390. usesZeroToOneRange: true
  6391. };
  6392. return CalGrayCS;
  6393. })();
  6394. //
  6395. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6396. //
  6397. var CalRGBCS = (function CalRGBCSClosure() {
  6398. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6399. // matrices.
  6400. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6401. 0.8951, 0.2664, -0.1614,
  6402. -0.7502, 1.7135, 0.0367,
  6403. 0.0389, -0.0685, 1.0296]);
  6404. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6405. 0.9869929, -0.1470543, 0.1599627,
  6406. 0.4323053, 0.5183603, 0.0492912,
  6407. -0.0085287, 0.0400428, 0.9684867]);
  6408. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6409. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6410. 3.2404542, -1.5371385, -0.4985314,
  6411. -0.9692660, 1.8760108, 0.0415560,
  6412. 0.0556434, -0.2040259, 1.0572252]);
  6413. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6414. var tempNormalizeMatrix = new Float32Array(3);
  6415. var tempConvertMatrix1 = new Float32Array(3);
  6416. var tempConvertMatrix2 = new Float32Array(3);
  6417. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6418. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6419. this.name = 'CalRGB';
  6420. this.numComps = 3;
  6421. this.defaultColor = new Float32Array(3);
  6422. if (!whitePoint) {
  6423. error('WhitePoint missing - required for color space CalRGB');
  6424. }
  6425. blackPoint = blackPoint || new Float32Array(3);
  6426. gamma = gamma || new Float32Array([1, 1, 1]);
  6427. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6428. // Translate arguments to spec variables.
  6429. var XW = whitePoint[0];
  6430. var YW = whitePoint[1];
  6431. var ZW = whitePoint[2];
  6432. this.whitePoint = whitePoint;
  6433. var XB = blackPoint[0];
  6434. var YB = blackPoint[1];
  6435. var ZB = blackPoint[2];
  6436. this.blackPoint = blackPoint;
  6437. this.GR = gamma[0];
  6438. this.GG = gamma[1];
  6439. this.GB = gamma[2];
  6440. this.MXA = matrix[0];
  6441. this.MYA = matrix[1];
  6442. this.MZA = matrix[2];
  6443. this.MXB = matrix[3];
  6444. this.MYB = matrix[4];
  6445. this.MZB = matrix[5];
  6446. this.MXC = matrix[6];
  6447. this.MYC = matrix[7];
  6448. this.MZC = matrix[8];
  6449. // Validate variables as per spec.
  6450. if (XW < 0 || ZW < 0 || YW !== 1) {
  6451. error('Invalid WhitePoint components for ' + this.name +
  6452. ', no fallback available');
  6453. }
  6454. if (XB < 0 || YB < 0 || ZB < 0) {
  6455. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6456. ', ' + ZB + '], falling back to default');
  6457. this.blackPoint = new Float32Array(3);
  6458. }
  6459. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6460. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6461. '] for ' + this.name + ', falling back to default');
  6462. this.GR = this.GG = this.GB = 1;
  6463. }
  6464. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6465. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6466. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6467. info('Invalid Matrix for ' + this.name + ' [' +
  6468. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6469. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6470. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6471. '], falling back to default');
  6472. this.MXA = this.MYB = this.MZC = 1;
  6473. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6474. }
  6475. }
  6476. function matrixProduct(a, b, result) {
  6477. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6478. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6479. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6480. }
  6481. function convertToFlat(sourceWhitePoint, LMS, result) {
  6482. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6483. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6484. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6485. }
  6486. function convertToD65(sourceWhitePoint, LMS, result) {
  6487. var D65X = 0.95047;
  6488. var D65Y = 1;
  6489. var D65Z = 1.08883;
  6490. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6491. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6492. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6493. }
  6494. function sRGBTransferFunction(color) {
  6495. // See http://en.wikipedia.org/wiki/SRGB.
  6496. if (color <= 0.0031308){
  6497. return adjustToRange(0, 1, 12.92 * color);
  6498. }
  6499. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6500. }
  6501. function adjustToRange(min, max, value) {
  6502. return Math.max(min, Math.min(max, value));
  6503. }
  6504. function decodeL(L) {
  6505. if (L < 0) {
  6506. return -decodeL(-L);
  6507. }
  6508. if (L > 8.0) {
  6509. return Math.pow(((L + 16) / 116), 3);
  6510. }
  6511. return L * DECODE_L_CONSTANT;
  6512. }
  6513. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6514. // In case the blackPoint is already the default blackPoint then there is
  6515. // no need to do compensation.
  6516. if (sourceBlackPoint[0] === 0 &&
  6517. sourceBlackPoint[1] === 0 &&
  6518. sourceBlackPoint[2] === 0) {
  6519. result[0] = XYZ_Flat[0];
  6520. result[1] = XYZ_Flat[1];
  6521. result[2] = XYZ_Flat[2];
  6522. return;
  6523. }
  6524. // For the blackPoint calculation details, please see
  6525. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6526. // AdobeBPC.pdf.
  6527. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6528. var zeroDecodeL = decodeL(0);
  6529. var X_DST = zeroDecodeL;
  6530. var X_SRC = decodeL(sourceBlackPoint[0]);
  6531. var Y_DST = zeroDecodeL;
  6532. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6533. var Z_DST = zeroDecodeL;
  6534. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6535. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6536. var X_Offset = 1 - X_Scale;
  6537. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6538. var Y_Offset = 1 - Y_Scale;
  6539. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6540. var Z_Offset = 1 - Z_Scale;
  6541. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6542. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6543. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6544. }
  6545. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6546. // In case the whitePoint is already flat then there is no need to do
  6547. // normalization.
  6548. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6549. result[0] = XYZ_In[0];
  6550. result[1] = XYZ_In[1];
  6551. result[2] = XYZ_In[2];
  6552. return;
  6553. }
  6554. var LMS = result;
  6555. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6556. var LMS_Flat = tempNormalizeMatrix;
  6557. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6558. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6559. }
  6560. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6561. var LMS = result;
  6562. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6563. var LMS_D65 = tempNormalizeMatrix;
  6564. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6565. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6566. }
  6567. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6568. // A, B and C represent a red, green and blue components of a calibrated
  6569. // rgb space.
  6570. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6571. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6572. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6573. // A <---> AGR in the spec
  6574. // B <---> BGG in the spec
  6575. // C <---> CGB in the spec
  6576. var AGR = Math.pow(A, cs.GR);
  6577. var BGG = Math.pow(B, cs.GG);
  6578. var CGB = Math.pow(C, cs.GB);
  6579. // Computes intermediate variables L, M, N as per spec.
  6580. // To decode X, Y, Z values map L, M, N directly to them.
  6581. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6582. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6583. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6584. // The following calculations are based on this document:
  6585. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6586. // AdobeBPC.pdf.
  6587. var XYZ = tempConvertMatrix1;
  6588. XYZ[0] = X;
  6589. XYZ[1] = Y;
  6590. XYZ[2] = Z;
  6591. var XYZ_Flat = tempConvertMatrix2;
  6592. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6593. var XYZ_Black = tempConvertMatrix1;
  6594. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6595. var XYZ_D65 = tempConvertMatrix2;
  6596. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6597. var SRGB = tempConvertMatrix1;
  6598. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6599. var sR = sRGBTransferFunction(SRGB[0]);
  6600. var sG = sRGBTransferFunction(SRGB[1]);
  6601. var sB = sRGBTransferFunction(SRGB[2]);
  6602. // Convert the values to rgb range [0, 255].
  6603. dest[destOffset] = Math.round(sR * 255);
  6604. dest[destOffset + 1] = Math.round(sG * 255);
  6605. dest[destOffset + 2] = Math.round(sB * 255);
  6606. }
  6607. CalRGBCS.prototype = {
  6608. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6609. var rgb = new Uint8Array(3);
  6610. this.getRgbItem(src, srcOffset, rgb, 0);
  6611. return rgb;
  6612. },
  6613. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6614. dest, destOffset) {
  6615. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6616. },
  6617. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6618. dest, destOffset, bits,
  6619. alpha01) {
  6620. var scale = 1 / ((1 << bits) - 1);
  6621. for (var i = 0; i < count; ++i) {
  6622. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6623. srcOffset += 3;
  6624. destOffset += 3 + alpha01;
  6625. }
  6626. },
  6627. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6628. return (inputLength * (3 + alpha01) / 3) | 0;
  6629. },
  6630. isPassthrough: ColorSpace.prototype.isPassthrough,
  6631. fillRgb: ColorSpace.prototype.fillRgb,
  6632. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6633. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6634. },
  6635. usesZeroToOneRange: true
  6636. };
  6637. return CalRGBCS;
  6638. })();
  6639. //
  6640. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6641. //
  6642. var LabCS = (function LabCSClosure() {
  6643. function LabCS(whitePoint, blackPoint, range) {
  6644. this.name = 'Lab';
  6645. this.numComps = 3;
  6646. this.defaultColor = new Float32Array([0, 0, 0]);
  6647. if (!whitePoint) {
  6648. error('WhitePoint missing - required for color space Lab');
  6649. }
  6650. blackPoint = blackPoint || [0, 0, 0];
  6651. range = range || [-100, 100, -100, 100];
  6652. // Translate args to spec variables
  6653. this.XW = whitePoint[0];
  6654. this.YW = whitePoint[1];
  6655. this.ZW = whitePoint[2];
  6656. this.amin = range[0];
  6657. this.amax = range[1];
  6658. this.bmin = range[2];
  6659. this.bmax = range[3];
  6660. // These are here just for completeness - the spec doesn't offer any
  6661. // formulas that use BlackPoint in Lab
  6662. this.XB = blackPoint[0];
  6663. this.YB = blackPoint[1];
  6664. this.ZB = blackPoint[2];
  6665. // Validate vars as per spec
  6666. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6667. error('Invalid WhitePoint components, no fallback available');
  6668. }
  6669. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6670. info('Invalid BlackPoint, falling back to default');
  6671. this.XB = this.YB = this.ZB = 0;
  6672. }
  6673. if (this.amin > this.amax || this.bmin > this.bmax) {
  6674. info('Invalid Range, falling back to defaults');
  6675. this.amin = -100;
  6676. this.amax = 100;
  6677. this.bmin = -100;
  6678. this.bmax = 100;
  6679. }
  6680. }
  6681. // Function g(x) from spec
  6682. function fn_g(x) {
  6683. if (x >= 6 / 29) {
  6684. return x * x * x;
  6685. } else {
  6686. return (108 / 841) * (x - 4 / 29);
  6687. }
  6688. }
  6689. function decode(value, high1, low2, high2) {
  6690. return low2 + (value) * (high2 - low2) / (high1);
  6691. }
  6692. // If decoding is needed maxVal should be 2^bits per component - 1.
  6693. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6694. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6695. // not the usual [0, 1]. If a command like setFillColor is used the src
  6696. // values will already be within the correct range. However, if we are
  6697. // converting an image we have to map the values to the correct range given
  6698. // above.
  6699. // Ls,as,bs <---> L*,a*,b* in the spec
  6700. var Ls = src[srcOffset];
  6701. var as = src[srcOffset + 1];
  6702. var bs = src[srcOffset + 2];
  6703. if (maxVal !== false) {
  6704. Ls = decode(Ls, maxVal, 0, 100);
  6705. as = decode(as, maxVal, cs.amin, cs.amax);
  6706. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6707. }
  6708. // Adjust limits of 'as' and 'bs'
  6709. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6710. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6711. // Computes intermediate variables X,Y,Z as per spec
  6712. var M = (Ls + 16) / 116;
  6713. var L = M + (as / 500);
  6714. var N = M - (bs / 200);
  6715. var X = cs.XW * fn_g(L);
  6716. var Y = cs.YW * fn_g(M);
  6717. var Z = cs.ZW * fn_g(N);
  6718. var r, g, b;
  6719. // Using different conversions for D50 and D65 white points,
  6720. // per http://www.color.org/srgb.pdf
  6721. if (cs.ZW < 1) {
  6722. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6723. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6724. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6725. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6726. } else {
  6727. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6728. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6729. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6730. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6731. }
  6732. // clamp color values to [0,1] range then convert to [0,255] range.
  6733. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6734. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6735. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6736. }
  6737. LabCS.prototype = {
  6738. getRgb: ColorSpace.prototype.getRgb,
  6739. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6740. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6741. },
  6742. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6743. dest, destOffset, bits,
  6744. alpha01) {
  6745. var maxVal = (1 << bits) - 1;
  6746. for (var i = 0; i < count; i++) {
  6747. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6748. srcOffset += 3;
  6749. destOffset += 3 + alpha01;
  6750. }
  6751. },
  6752. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6753. return (inputLength * (3 + alpha01) / 3) | 0;
  6754. },
  6755. isPassthrough: ColorSpace.prototype.isPassthrough,
  6756. fillRgb: ColorSpace.prototype.fillRgb,
  6757. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6758. // XXX: Decoding is handled with the lab conversion because of the strange
  6759. // ranges that are used.
  6760. return true;
  6761. },
  6762. usesZeroToOneRange: false
  6763. };
  6764. return LabCS;
  6765. })();
  6766. var ARCFourCipher = (function ARCFourCipherClosure() {
  6767. function ARCFourCipher(key) {
  6768. this.a = 0;
  6769. this.b = 0;
  6770. var s = new Uint8Array(256);
  6771. var i, j = 0, tmp, keyLength = key.length;
  6772. for (i = 0; i < 256; ++i) {
  6773. s[i] = i;
  6774. }
  6775. for (i = 0; i < 256; ++i) {
  6776. tmp = s[i];
  6777. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6778. s[i] = s[j];
  6779. s[j] = tmp;
  6780. }
  6781. this.s = s;
  6782. }
  6783. ARCFourCipher.prototype = {
  6784. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6785. var i, n = data.length, tmp, tmp2;
  6786. var a = this.a, b = this.b, s = this.s;
  6787. var output = new Uint8Array(n);
  6788. for (i = 0; i < n; ++i) {
  6789. a = (a + 1) & 0xFF;
  6790. tmp = s[a];
  6791. b = (b + tmp) & 0xFF;
  6792. tmp2 = s[b];
  6793. s[a] = tmp2;
  6794. s[b] = tmp;
  6795. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6796. }
  6797. this.a = a;
  6798. this.b = b;
  6799. return output;
  6800. }
  6801. };
  6802. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6803. return ARCFourCipher;
  6804. })();
  6805. var calculateMD5 = (function calculateMD5Closure() {
  6806. var r = new Uint8Array([
  6807. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6808. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6809. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6810. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6811. var k = new Int32Array([
  6812. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6813. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6814. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6815. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6816. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6817. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6818. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6819. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6820. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6821. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6822. -145523070, -1120210379, 718787259, -343485551]);
  6823. function hash(data, offset, length) {
  6824. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6825. // pre-processing
  6826. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6827. var padded = new Uint8Array(paddedLength);
  6828. var i, j, n;
  6829. for (i = 0; i < length; ++i) {
  6830. padded[i] = data[offset++];
  6831. }
  6832. padded[i++] = 0x80;
  6833. n = paddedLength - 8;
  6834. while (i < n) {
  6835. padded[i++] = 0;
  6836. }
  6837. padded[i++] = (length << 3) & 0xFF;
  6838. padded[i++] = (length >> 5) & 0xFF;
  6839. padded[i++] = (length >> 13) & 0xFF;
  6840. padded[i++] = (length >> 21) & 0xFF;
  6841. padded[i++] = (length >>> 29) & 0xFF;
  6842. padded[i++] = 0;
  6843. padded[i++] = 0;
  6844. padded[i++] = 0;
  6845. var w = new Int32Array(16);
  6846. for (i = 0; i < paddedLength;) {
  6847. for (j = 0; j < 16; ++j, i += 4) {
  6848. w[j] = (padded[i] | (padded[i + 1] << 8) |
  6849. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  6850. }
  6851. var a = h0, b = h1, c = h2, d = h3, f, g;
  6852. for (j = 0; j < 64; ++j) {
  6853. if (j < 16) {
  6854. f = (b & c) | ((~b) & d);
  6855. g = j;
  6856. } else if (j < 32) {
  6857. f = (d & b) | ((~d) & c);
  6858. g = (5 * j + 1) & 15;
  6859. } else if (j < 48) {
  6860. f = b ^ c ^ d;
  6861. g = (3 * j + 5) & 15;
  6862. } else {
  6863. f = c ^ (b | (~d));
  6864. g = (7 * j) & 15;
  6865. }
  6866. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  6867. d = c;
  6868. c = b;
  6869. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  6870. a = tmp;
  6871. }
  6872. h0 = (h0 + a) | 0;
  6873. h1 = (h1 + b) | 0;
  6874. h2 = (h2 + c) | 0;
  6875. h3 = (h3 + d) | 0;
  6876. }
  6877. return new Uint8Array([
  6878. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  6879. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  6880. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  6881. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  6882. ]);
  6883. }
  6884. return hash;
  6885. })();
  6886. var Word64 = (function Word64Closure() {
  6887. function Word64(highInteger, lowInteger) {
  6888. this.high = highInteger | 0;
  6889. this.low = lowInteger | 0;
  6890. }
  6891. Word64.prototype = {
  6892. and: function Word64_and(word) {
  6893. this.high &= word.high;
  6894. this.low &= word.low;
  6895. },
  6896. xor: function Word64_xor(word) {
  6897. this.high ^= word.high;
  6898. this.low ^= word.low;
  6899. },
  6900. or: function Word64_or(word) {
  6901. this.high |= word.high;
  6902. this.low |= word.low;
  6903. },
  6904. shiftRight: function Word64_shiftRight(places) {
  6905. if (places >= 32) {
  6906. this.low = (this.high >>> (places - 32)) | 0;
  6907. this.high = 0;
  6908. } else {
  6909. this.low = (this.low >>> places) | (this.high << (32 - places));
  6910. this.high = (this.high >>> places) | 0;
  6911. }
  6912. },
  6913. shiftLeft: function Word64_shiftLeft(places) {
  6914. if (places >= 32) {
  6915. this.high = this.low << (places - 32);
  6916. this.low = 0;
  6917. } else {
  6918. this.high = (this.high << places) | (this.low >>> (32 - places));
  6919. this.low = this.low << places;
  6920. }
  6921. },
  6922. rotateRight: function Word64_rotateRight(places) {
  6923. var low, high;
  6924. if (places & 32) {
  6925. high = this.low;
  6926. low = this.high;
  6927. } else {
  6928. low = this.low;
  6929. high = this.high;
  6930. }
  6931. places &= 31;
  6932. this.low = (low >>> places) | (high << (32 - places));
  6933. this.high = (high >>> places) | (low << (32 - places));
  6934. },
  6935. not: function Word64_not() {
  6936. this.high = ~this.high;
  6937. this.low = ~this.low;
  6938. },
  6939. add: function Word64_add(word) {
  6940. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  6941. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  6942. if (lowAdd > 0xFFFFFFFF) {
  6943. highAdd += 1;
  6944. }
  6945. this.low = lowAdd | 0;
  6946. this.high = highAdd | 0;
  6947. },
  6948. copyTo: function Word64_copyTo(bytes, offset) {
  6949. bytes[offset] = (this.high >>> 24) & 0xFF;
  6950. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  6951. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  6952. bytes[offset + 3] = this.high & 0xFF;
  6953. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  6954. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  6955. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  6956. bytes[offset + 7] = this.low & 0xFF;
  6957. },
  6958. assign: function Word64_assign(word) {
  6959. this.high = word.high;
  6960. this.low = word.low;
  6961. }
  6962. };
  6963. return Word64;
  6964. })();
  6965. var calculateSHA256 = (function calculateSHA256Closure() {
  6966. function rotr(x, n) {
  6967. return (x >>> n) | (x << 32 - n);
  6968. }
  6969. function ch(x, y, z) {
  6970. return (x & y) ^ (~x & z);
  6971. }
  6972. function maj(x, y, z) {
  6973. return (x & y) ^ (x & z) ^ (y & z);
  6974. }
  6975. function sigma(x) {
  6976. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  6977. }
  6978. function sigmaPrime(x) {
  6979. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  6980. }
  6981. function littleSigma(x) {
  6982. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  6983. }
  6984. function littleSigmaPrime(x) {
  6985. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  6986. }
  6987. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  6988. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  6989. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  6990. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  6991. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  6992. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  6993. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  6994. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  6995. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  6996. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  6997. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  6998. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  6999. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7000. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7001. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7002. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7003. function hash(data, offset, length) {
  7004. // initial hash values
  7005. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7006. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7007. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7008. // pre-processing
  7009. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7010. var padded = new Uint8Array(paddedLength);
  7011. var i, j, n;
  7012. for (i = 0; i < length; ++i) {
  7013. padded[i] = data[offset++];
  7014. }
  7015. padded[i++] = 0x80;
  7016. n = paddedLength - 8;
  7017. while (i < n) {
  7018. padded[i++] = 0;
  7019. }
  7020. padded[i++] = 0;
  7021. padded[i++] = 0;
  7022. padded[i++] = 0;
  7023. padded[i++] = (length >>> 29) & 0xFF;
  7024. padded[i++] = (length >> 21) & 0xFF;
  7025. padded[i++] = (length >> 13) & 0xFF;
  7026. padded[i++] = (length >> 5) & 0xFF;
  7027. padded[i++] = (length << 3) & 0xFF;
  7028. var w = new Uint32Array(64);
  7029. // for each 512 bit block
  7030. for (i = 0; i < paddedLength;) {
  7031. for (j = 0; j < 16; ++j) {
  7032. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7033. (padded[i + 2] << 8) | (padded[i + 3]));
  7034. i += 4;
  7035. }
  7036. for (j = 16; j < 64; ++j) {
  7037. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7038. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7039. }
  7040. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7041. f = h5, g = h6, h = h7, t1, t2;
  7042. for (j = 0; j < 64; ++j) {
  7043. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7044. t2 = sigma(a) + maj(a, b, c);
  7045. h = g;
  7046. g = f;
  7047. f = e;
  7048. e = (d + t1) | 0;
  7049. d = c;
  7050. c = b;
  7051. b = a;
  7052. a = (t1 + t2) | 0;
  7053. }
  7054. h0 = (h0 + a) | 0;
  7055. h1 = (h1 + b) | 0;
  7056. h2 = (h2 + c) | 0;
  7057. h3 = (h3 + d) | 0;
  7058. h4 = (h4 + e) | 0;
  7059. h5 = (h5 + f) | 0;
  7060. h6 = (h6 + g) | 0;
  7061. h7 = (h7 + h) | 0;
  7062. }
  7063. return new Uint8Array([
  7064. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7065. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7066. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7067. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7068. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7069. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7070. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7071. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7072. ]);
  7073. }
  7074. return hash;
  7075. })();
  7076. var calculateSHA512 = (function calculateSHA512Closure() {
  7077. function ch(result, x, y, z, tmp) {
  7078. result.assign(x);
  7079. result.and(y);
  7080. tmp.assign(x);
  7081. tmp.not();
  7082. tmp.and(z);
  7083. result.xor(tmp);
  7084. }
  7085. function maj(result, x, y, z, tmp) {
  7086. result.assign(x);
  7087. result.and(y);
  7088. tmp.assign(x);
  7089. tmp.and(z);
  7090. result.xor(tmp);
  7091. tmp.assign(y);
  7092. tmp.and(z);
  7093. result.xor(tmp);
  7094. }
  7095. function sigma(result, x, tmp) {
  7096. result.assign(x);
  7097. result.rotateRight(28);
  7098. tmp.assign(x);
  7099. tmp.rotateRight(34);
  7100. result.xor(tmp);
  7101. tmp.assign(x);
  7102. tmp.rotateRight(39);
  7103. result.xor(tmp);
  7104. }
  7105. function sigmaPrime(result, x, tmp) {
  7106. result.assign(x);
  7107. result.rotateRight(14);
  7108. tmp.assign(x);
  7109. tmp.rotateRight(18);
  7110. result.xor(tmp);
  7111. tmp.assign(x);
  7112. tmp.rotateRight(41);
  7113. result.xor(tmp);
  7114. }
  7115. function littleSigma(result, x, tmp) {
  7116. result.assign(x);
  7117. result.rotateRight(1);
  7118. tmp.assign(x);
  7119. tmp.rotateRight(8);
  7120. result.xor(tmp);
  7121. tmp.assign(x);
  7122. tmp.shiftRight(7);
  7123. result.xor(tmp);
  7124. }
  7125. function littleSigmaPrime(result, x, tmp) {
  7126. result.assign(x);
  7127. result.rotateRight(19);
  7128. tmp.assign(x);
  7129. tmp.rotateRight(61);
  7130. result.xor(tmp);
  7131. tmp.assign(x);
  7132. tmp.shiftRight(6);
  7133. result.xor(tmp);
  7134. }
  7135. var k = [
  7136. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7137. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7138. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7139. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7140. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7141. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7142. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7143. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7144. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7145. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7146. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7147. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7148. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7149. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7150. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7151. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7152. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7153. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7154. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7155. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7156. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7157. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7158. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7159. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7160. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7161. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7162. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7163. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7164. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7165. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7166. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7167. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7168. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7169. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7170. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7171. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7172. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7173. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7174. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7175. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7176. function hash(data, offset, length, mode384) {
  7177. mode384 = !!mode384;
  7178. // initial hash values
  7179. var h0, h1, h2, h3, h4, h5, h6, h7;
  7180. if (!mode384) {
  7181. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7182. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7183. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7184. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7185. h4 = new Word64(0x510e527f, 0xade682d1);
  7186. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7187. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7188. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7189. }
  7190. else {
  7191. // SHA384 is exactly the same
  7192. // except with different starting values and a trimmed result
  7193. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7194. h1 = new Word64(0x629a292a, 0x367cd507);
  7195. h2 = new Word64(0x9159015a, 0x3070dd17);
  7196. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7197. h4 = new Word64(0x67332667, 0xffc00b31);
  7198. h5 = new Word64(0x8eb44a87, 0x68581511);
  7199. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7200. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7201. }
  7202. // pre-processing
  7203. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7204. var padded = new Uint8Array(paddedLength);
  7205. var i, j, n;
  7206. for (i = 0; i < length; ++i) {
  7207. padded[i] = data[offset++];
  7208. }
  7209. padded[i++] = 0x80;
  7210. n = paddedLength - 16;
  7211. while (i < n) {
  7212. padded[i++] = 0;
  7213. }
  7214. padded[i++] = 0;
  7215. padded[i++] = 0;
  7216. padded[i++] = 0;
  7217. padded[i++] = 0;
  7218. padded[i++] = 0;
  7219. padded[i++] = 0;
  7220. padded[i++] = 0;
  7221. padded[i++] = 0;
  7222. padded[i++] = 0;
  7223. padded[i++] = 0;
  7224. padded[i++] = 0;
  7225. padded[i++] = (length >>> 29) & 0xFF;
  7226. padded[i++] = (length >> 21) & 0xFF;
  7227. padded[i++] = (length >> 13) & 0xFF;
  7228. padded[i++] = (length >> 5) & 0xFF;
  7229. padded[i++] = (length << 3) & 0xFF;
  7230. var w = new Array(80);
  7231. for (i = 0; i < 80; i++) {
  7232. w[i] = new Word64(0, 0);
  7233. }
  7234. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7235. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7236. var g = new Word64(0, 0), h = new Word64(0, 0);
  7237. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7238. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7239. // for each 1024 bit block
  7240. for (i = 0; i < paddedLength;) {
  7241. for (j = 0; j < 16; ++j) {
  7242. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7243. (padded[i + 2] << 8) | (padded[i + 3]);
  7244. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7245. (padded[i + 6]) << 8 | (padded[i + 7]);
  7246. i += 8;
  7247. }
  7248. for (j = 16; j < 80; ++j) {
  7249. tmp3 = w[j];
  7250. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7251. tmp3.add(w[j - 7]);
  7252. littleSigma(tmp1, w[j - 15], tmp2);
  7253. tmp3.add(tmp1);
  7254. tmp3.add(w[j - 16]);
  7255. }
  7256. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7257. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7258. for (j = 0; j < 80; ++j) {
  7259. t1.assign(h);
  7260. sigmaPrime(tmp1, e, tmp2);
  7261. t1.add(tmp1);
  7262. ch(tmp1, e, f, g, tmp2);
  7263. t1.add(tmp1);
  7264. t1.add(k[j]);
  7265. t1.add(w[j]);
  7266. sigma(t2, a, tmp2);
  7267. maj(tmp1, a, b, c, tmp2);
  7268. t2.add(tmp1);
  7269. tmp3 = h;
  7270. h = g;
  7271. g = f;
  7272. f = e;
  7273. d.add(t1);
  7274. e = d;
  7275. d = c;
  7276. c = b;
  7277. b = a;
  7278. tmp3.assign(t1);
  7279. tmp3.add(t2);
  7280. a = tmp3;
  7281. }
  7282. h0.add(a);
  7283. h1.add(b);
  7284. h2.add(c);
  7285. h3.add(d);
  7286. h4.add(e);
  7287. h5.add(f);
  7288. h6.add(g);
  7289. h7.add(h);
  7290. }
  7291. var result;
  7292. if (!mode384) {
  7293. result = new Uint8Array(64);
  7294. h0.copyTo(result,0);
  7295. h1.copyTo(result,8);
  7296. h2.copyTo(result,16);
  7297. h3.copyTo(result,24);
  7298. h4.copyTo(result,32);
  7299. h5.copyTo(result,40);
  7300. h6.copyTo(result,48);
  7301. h7.copyTo(result,56);
  7302. }
  7303. else {
  7304. result = new Uint8Array(48);
  7305. h0.copyTo(result,0);
  7306. h1.copyTo(result,8);
  7307. h2.copyTo(result,16);
  7308. h3.copyTo(result,24);
  7309. h4.copyTo(result,32);
  7310. h5.copyTo(result,40);
  7311. }
  7312. return result;
  7313. }
  7314. return hash;
  7315. })();
  7316. var calculateSHA384 = (function calculateSHA384Closure() {
  7317. function hash(data, offset, length) {
  7318. return calculateSHA512(data, offset, length, true);
  7319. }
  7320. return hash;
  7321. })();
  7322. var NullCipher = (function NullCipherClosure() {
  7323. function NullCipher() {
  7324. }
  7325. NullCipher.prototype = {
  7326. decryptBlock: function NullCipher_decryptBlock(data) {
  7327. return data;
  7328. }
  7329. };
  7330. return NullCipher;
  7331. })();
  7332. var AES128Cipher = (function AES128CipherClosure() {
  7333. var rcon = new Uint8Array([
  7334. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7335. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7336. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7337. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7338. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7339. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7340. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7341. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7342. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7343. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7344. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7345. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7346. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7347. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7348. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7349. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7350. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7351. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7352. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7353. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7354. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7355. 0x74, 0xe8, 0xcb, 0x8d]);
  7356. var s = new Uint8Array([
  7357. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7358. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7359. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7360. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7361. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7362. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7363. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7364. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7365. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7366. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7367. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7368. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7369. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7370. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7371. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7372. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7373. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7374. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7375. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7376. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7377. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7378. 0xb0, 0x54, 0xbb, 0x16]);
  7379. var inv_s = new Uint8Array([
  7380. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7381. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7382. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7383. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7384. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7385. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7386. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7387. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7388. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7389. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7390. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7391. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7392. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7393. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7394. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7395. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7396. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7397. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7398. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7399. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7400. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7401. 0x55, 0x21, 0x0c, 0x7d]);
  7402. var mixCol = new Uint8Array(256);
  7403. for (var i = 0; i < 256; i++) {
  7404. if (i < 128) {
  7405. mixCol[i] = i << 1;
  7406. } else {
  7407. mixCol[i] = (i << 1) ^ 0x1b;
  7408. }
  7409. }
  7410. var mix = new Uint32Array([
  7411. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7412. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7413. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7414. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7415. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7416. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7417. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7418. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7419. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7420. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7421. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7422. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7423. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7424. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7425. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7426. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7427. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7428. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7429. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7430. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7431. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7432. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7433. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7434. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7435. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7436. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7437. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7438. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7439. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7440. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7441. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7442. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7443. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7444. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7445. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7446. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7447. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7448. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7449. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7450. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7451. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7452. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7453. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7454. function expandKey128(cipherKey) {
  7455. var b = 176, result = new Uint8Array(b);
  7456. result.set(cipherKey);
  7457. for (var j = 16, i = 1; j < b; ++i) {
  7458. // RotWord
  7459. var t1 = result[j - 3], t2 = result[j - 2],
  7460. t3 = result[j - 1], t4 = result[j - 4];
  7461. // SubWord
  7462. t1 = s[t1];
  7463. t2 = s[t2];
  7464. t3 = s[t3];
  7465. t4 = s[t4];
  7466. // Rcon
  7467. t1 = t1 ^ rcon[i];
  7468. for (var n = 0; n < 4; ++n) {
  7469. result[j] = (t1 ^= result[j - 16]);
  7470. j++;
  7471. result[j] = (t2 ^= result[j - 16]);
  7472. j++;
  7473. result[j] = (t3 ^= result[j - 16]);
  7474. j++;
  7475. result[j] = (t4 ^= result[j - 16]);
  7476. j++;
  7477. }
  7478. }
  7479. return result;
  7480. }
  7481. function decrypt128(input, key) {
  7482. var state = new Uint8Array(16);
  7483. state.set(input);
  7484. var i, j, k;
  7485. var t, u, v;
  7486. // AddRoundKey
  7487. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7488. state[j] ^= key[k];
  7489. }
  7490. for (i = 9; i >= 1; --i) {
  7491. // InvShiftRows
  7492. t = state[13];
  7493. state[13] = state[9];
  7494. state[9] = state[5];
  7495. state[5] = state[1];
  7496. state[1] = t;
  7497. t = state[14];
  7498. u = state[10];
  7499. state[14] = state[6];
  7500. state[10] = state[2];
  7501. state[6] = t;
  7502. state[2] = u;
  7503. t = state[15];
  7504. u = state[11];
  7505. v = state[7];
  7506. state[15] = state[3];
  7507. state[11] = t;
  7508. state[7] = u;
  7509. state[3] = v;
  7510. // InvSubBytes
  7511. for (j = 0; j < 16; ++j) {
  7512. state[j] = inv_s[state[j]];
  7513. }
  7514. // AddRoundKey
  7515. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7516. state[j] ^= key[k];
  7517. }
  7518. // InvMixColumns
  7519. for (j = 0; j < 16; j += 4) {
  7520. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7521. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7522. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7523. (s3 >>> 24) ^ (s3 << 8));
  7524. state[j] = (t >>> 24) & 0xFF;
  7525. state[j + 1] = (t >> 16) & 0xFF;
  7526. state[j + 2] = (t >> 8) & 0xFF;
  7527. state[j + 3] = t & 0xFF;
  7528. }
  7529. }
  7530. // InvShiftRows
  7531. t = state[13];
  7532. state[13] = state[9];
  7533. state[9] = state[5];
  7534. state[5] = state[1];
  7535. state[1] = t;
  7536. t = state[14];
  7537. u = state[10];
  7538. state[14] = state[6];
  7539. state[10] = state[2];
  7540. state[6] = t;
  7541. state[2] = u;
  7542. t = state[15];
  7543. u = state[11];
  7544. v = state[7];
  7545. state[15] = state[3];
  7546. state[11] = t;
  7547. state[7] = u;
  7548. state[3] = v;
  7549. for (j = 0; j < 16; ++j) {
  7550. // InvSubBytes
  7551. state[j] = inv_s[state[j]];
  7552. // AddRoundKey
  7553. state[j] ^= key[j];
  7554. }
  7555. return state;
  7556. }
  7557. function encrypt128(input, key) {
  7558. var t, u, v, k;
  7559. var state = new Uint8Array(16);
  7560. state.set(input);
  7561. for (j = 0; j < 16; ++j) {
  7562. // AddRoundKey
  7563. state[j] ^= key[j];
  7564. }
  7565. for (i = 1; i < 10; i++) {
  7566. //SubBytes
  7567. for (j = 0; j < 16; ++j) {
  7568. state[j] = s[state[j]];
  7569. }
  7570. //ShiftRows
  7571. v = state[1];
  7572. state[1] = state[5];
  7573. state[5] = state[9];
  7574. state[9] = state[13];
  7575. state[13] = v;
  7576. v = state[2];
  7577. u = state[6];
  7578. state[2] = state[10];
  7579. state[6] = state[14];
  7580. state[10] = v;
  7581. state[14] = u;
  7582. v = state[3];
  7583. u = state[7];
  7584. t = state[11];
  7585. state[3] = state[15];
  7586. state[7] = v;
  7587. state[11] = u;
  7588. state[15] = t;
  7589. //MixColumns
  7590. for (var j = 0; j < 16; j += 4) {
  7591. var s0 = state[j + 0], s1 = state[j + 1];
  7592. var s2 = state[j + 2], s3 = state[j + 3];
  7593. t = s0 ^ s1 ^ s2 ^ s3;
  7594. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7595. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7596. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7597. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7598. }
  7599. //AddRoundKey
  7600. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7601. state[j] ^= key[k];
  7602. }
  7603. }
  7604. //SubBytes
  7605. for (j = 0; j < 16; ++j) {
  7606. state[j] = s[state[j]];
  7607. }
  7608. //ShiftRows
  7609. v = state[1];
  7610. state[1] = state[5];
  7611. state[5] = state[9];
  7612. state[9] = state[13];
  7613. state[13] = v;
  7614. v = state[2];
  7615. u = state[6];
  7616. state[2] = state[10];
  7617. state[6] = state[14];
  7618. state[10] = v;
  7619. state[14] = u;
  7620. v = state[3];
  7621. u = state[7];
  7622. t = state[11];
  7623. state[3] = state[15];
  7624. state[7] = v;
  7625. state[11] = u;
  7626. state[15] = t;
  7627. //AddRoundKey
  7628. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7629. state[j] ^= key[k];
  7630. }
  7631. return state;
  7632. }
  7633. function AES128Cipher(key) {
  7634. this.key = expandKey128(key);
  7635. this.buffer = new Uint8Array(16);
  7636. this.bufferPosition = 0;
  7637. }
  7638. function decryptBlock2(data, finalize) {
  7639. var i, j, ii, sourceLength = data.length,
  7640. buffer = this.buffer, bufferLength = this.bufferPosition,
  7641. result = [], iv = this.iv;
  7642. for (i = 0; i < sourceLength; ++i) {
  7643. buffer[bufferLength] = data[i];
  7644. ++bufferLength;
  7645. if (bufferLength < 16) {
  7646. continue;
  7647. }
  7648. // buffer is full, decrypting
  7649. var plain = decrypt128(buffer, this.key);
  7650. // xor-ing the IV vector to get plain text
  7651. for (j = 0; j < 16; ++j) {
  7652. plain[j] ^= iv[j];
  7653. }
  7654. iv = buffer;
  7655. result.push(plain);
  7656. buffer = new Uint8Array(16);
  7657. bufferLength = 0;
  7658. }
  7659. // saving incomplete buffer
  7660. this.buffer = buffer;
  7661. this.bufferLength = bufferLength;
  7662. this.iv = iv;
  7663. if (result.length === 0) {
  7664. return new Uint8Array([]);
  7665. }
  7666. // combining plain text blocks into one
  7667. var outputLength = 16 * result.length;
  7668. if (finalize) {
  7669. // undo a padding that is described in RFC 2898
  7670. var lastBlock = result[result.length - 1];
  7671. var psLen = lastBlock[15];
  7672. if (psLen <= 16) {
  7673. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7674. if (lastBlock[i] !== psLen) {
  7675. // Invalid padding, assume that the block has no padding.
  7676. psLen = 0;
  7677. break;
  7678. }
  7679. }
  7680. outputLength -= psLen;
  7681. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7682. }
  7683. }
  7684. var output = new Uint8Array(outputLength);
  7685. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7686. output.set(result[i], j);
  7687. }
  7688. return output;
  7689. }
  7690. AES128Cipher.prototype = {
  7691. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7692. var i, sourceLength = data.length;
  7693. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7694. // waiting for IV values -- they are at the start of the stream
  7695. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7696. buffer[bufferLength] = data[i];
  7697. }
  7698. if (bufferLength < 16) {
  7699. // need more data
  7700. this.bufferLength = bufferLength;
  7701. return new Uint8Array([]);
  7702. }
  7703. this.iv = buffer;
  7704. this.buffer = new Uint8Array(16);
  7705. this.bufferLength = 0;
  7706. // starting decryption
  7707. this.decryptBlock = decryptBlock2;
  7708. return this.decryptBlock(data.subarray(16), finalize);
  7709. },
  7710. encrypt: function AES128Cipher_encrypt(data, iv) {
  7711. var i, j, ii, sourceLength = data.length,
  7712. buffer = this.buffer, bufferLength = this.bufferPosition,
  7713. result = [];
  7714. if (!iv) {
  7715. iv = new Uint8Array(16);
  7716. }
  7717. for (i = 0; i < sourceLength; ++i) {
  7718. buffer[bufferLength] = data[i];
  7719. ++bufferLength;
  7720. if (bufferLength < 16) {
  7721. continue;
  7722. }
  7723. for (j = 0; j < 16; ++j) {
  7724. buffer[j] ^= iv[j];
  7725. }
  7726. // buffer is full, encrypting
  7727. var cipher = encrypt128(buffer, this.key);
  7728. iv = cipher;
  7729. result.push(cipher);
  7730. buffer = new Uint8Array(16);
  7731. bufferLength = 0;
  7732. }
  7733. // saving incomplete buffer
  7734. this.buffer = buffer;
  7735. this.bufferLength = bufferLength;
  7736. this.iv = iv;
  7737. if (result.length === 0) {
  7738. return new Uint8Array([]);
  7739. }
  7740. // combining plain text blocks into one
  7741. var outputLength = 16 * result.length;
  7742. var output = new Uint8Array(outputLength);
  7743. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7744. output.set(result[i], j);
  7745. }
  7746. return output;
  7747. }
  7748. };
  7749. return AES128Cipher;
  7750. })();
  7751. var AES256Cipher = (function AES256CipherClosure() {
  7752. var rcon = new Uint8Array([
  7753. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7754. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7755. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7756. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7757. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7758. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7759. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7760. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7761. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7762. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7763. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7764. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7765. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7766. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7767. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7768. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7769. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7770. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7771. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7772. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7773. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7774. 0x74, 0xe8, 0xcb, 0x8d]);
  7775. var s = new Uint8Array([
  7776. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7777. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7778. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7779. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7780. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7781. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7782. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7783. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7784. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7785. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7786. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7787. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7788. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7789. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7790. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7791. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7792. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7793. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7794. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7795. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7796. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7797. 0xb0, 0x54, 0xbb, 0x16]);
  7798. var inv_s = new Uint8Array([
  7799. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7800. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7801. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7802. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7803. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7804. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7805. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7806. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7807. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7808. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7809. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7810. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7811. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7812. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7813. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7814. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7815. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7816. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7817. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7818. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7819. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7820. 0x55, 0x21, 0x0c, 0x7d]);
  7821. var mixCol = new Uint8Array(256);
  7822. for (var i = 0; i < 256; i++) {
  7823. if (i < 128) {
  7824. mixCol[i] = i << 1;
  7825. } else {
  7826. mixCol[i] = (i << 1) ^ 0x1b;
  7827. }
  7828. }
  7829. var mix = new Uint32Array([
  7830. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7831. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7832. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7833. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7834. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7835. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7836. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7837. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7838. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7839. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7840. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7841. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7842. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7843. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7844. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7845. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7846. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7847. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7848. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7849. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7850. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7851. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7852. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7853. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7854. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7855. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7856. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7857. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7858. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7859. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7860. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7861. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7862. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7863. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7864. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7865. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7866. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7867. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7868. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7869. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7870. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7871. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7872. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7873. function expandKey256(cipherKey) {
  7874. var b = 240, result = new Uint8Array(b);
  7875. var r = 1;
  7876. result.set(cipherKey);
  7877. for (var j = 32, i = 1; j < b; ++i) {
  7878. if (j % 32 === 16) {
  7879. t1 = s[t1];
  7880. t2 = s[t2];
  7881. t3 = s[t3];
  7882. t4 = s[t4];
  7883. } else if (j % 32 === 0) {
  7884. // RotWord
  7885. var t1 = result[j - 3], t2 = result[j - 2],
  7886. t3 = result[j - 1], t4 = result[j - 4];
  7887. // SubWord
  7888. t1 = s[t1];
  7889. t2 = s[t2];
  7890. t3 = s[t3];
  7891. t4 = s[t4];
  7892. // Rcon
  7893. t1 = t1 ^ r;
  7894. if ((r <<= 1) >= 256) {
  7895. r = (r ^ 0x1b) & 0xFF;
  7896. }
  7897. }
  7898. for (var n = 0; n < 4; ++n) {
  7899. result[j] = (t1 ^= result[j - 32]);
  7900. j++;
  7901. result[j] = (t2 ^= result[j - 32]);
  7902. j++;
  7903. result[j] = (t3 ^= result[j - 32]);
  7904. j++;
  7905. result[j] = (t4 ^= result[j - 32]);
  7906. j++;
  7907. }
  7908. }
  7909. return result;
  7910. }
  7911. function decrypt256(input, key) {
  7912. var state = new Uint8Array(16);
  7913. state.set(input);
  7914. var i, j, k;
  7915. var t, u, v;
  7916. // AddRoundKey
  7917. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7918. state[j] ^= key[k];
  7919. }
  7920. for (i = 13; i >= 1; --i) {
  7921. // InvShiftRows
  7922. t = state[13];
  7923. state[13] = state[9];
  7924. state[9] = state[5];
  7925. state[5] = state[1];
  7926. state[1] = t;
  7927. t = state[14];
  7928. u = state[10];
  7929. state[14] = state[6];
  7930. state[10] = state[2];
  7931. state[6] = t;
  7932. state[2] = u;
  7933. t = state[15];
  7934. u = state[11];
  7935. v = state[7];
  7936. state[15] = state[3];
  7937. state[11] = t;
  7938. state[7] = u;
  7939. state[3] = v;
  7940. // InvSubBytes
  7941. for (j = 0; j < 16; ++j) {
  7942. state[j] = inv_s[state[j]];
  7943. }
  7944. // AddRoundKey
  7945. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7946. state[j] ^= key[k];
  7947. }
  7948. // InvMixColumns
  7949. for (j = 0; j < 16; j += 4) {
  7950. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7951. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7952. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7953. (s3 >>> 24) ^ (s3 << 8));
  7954. state[j] = (t >>> 24) & 0xFF;
  7955. state[j + 1] = (t >> 16) & 0xFF;
  7956. state[j + 2] = (t >> 8) & 0xFF;
  7957. state[j + 3] = t & 0xFF;
  7958. }
  7959. }
  7960. // InvShiftRows
  7961. t = state[13];
  7962. state[13] = state[9];
  7963. state[9] = state[5];
  7964. state[5] = state[1];
  7965. state[1] = t;
  7966. t = state[14];
  7967. u = state[10];
  7968. state[14] = state[6];
  7969. state[10] = state[2];
  7970. state[6] = t;
  7971. state[2] = u;
  7972. t = state[15];
  7973. u = state[11];
  7974. v = state[7];
  7975. state[15] = state[3];
  7976. state[11] = t;
  7977. state[7] = u;
  7978. state[3] = v;
  7979. for (j = 0; j < 16; ++j) {
  7980. // InvSubBytes
  7981. state[j] = inv_s[state[j]];
  7982. // AddRoundKey
  7983. state[j] ^= key[j];
  7984. }
  7985. return state;
  7986. }
  7987. function encrypt256(input, key) {
  7988. var t, u, v, k;
  7989. var state = new Uint8Array(16);
  7990. state.set(input);
  7991. for (j = 0; j < 16; ++j) {
  7992. // AddRoundKey
  7993. state[j] ^= key[j];
  7994. }
  7995. for (i = 1; i < 14; i++) {
  7996. //SubBytes
  7997. for (j = 0; j < 16; ++j) {
  7998. state[j] = s[state[j]];
  7999. }
  8000. //ShiftRows
  8001. v = state[1];
  8002. state[1] = state[5];
  8003. state[5] = state[9];
  8004. state[9] = state[13];
  8005. state[13] = v;
  8006. v = state[2];
  8007. u = state[6];
  8008. state[2] = state[10];
  8009. state[6] = state[14];
  8010. state[10] = v;
  8011. state[14] = u;
  8012. v = state[3];
  8013. u = state[7];
  8014. t = state[11];
  8015. state[3] = state[15];
  8016. state[7] = v;
  8017. state[11] = u;
  8018. state[15] = t;
  8019. //MixColumns
  8020. for (var j = 0; j < 16; j += 4) {
  8021. var s0 = state[j + 0], s1 = state[j + 1];
  8022. var s2 = state[j + 2], s3 = state[j + 3];
  8023. t = s0 ^ s1 ^ s2 ^ s3;
  8024. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8025. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8026. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8027. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8028. }
  8029. //AddRoundKey
  8030. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8031. state[j] ^= key[k];
  8032. }
  8033. }
  8034. //SubBytes
  8035. for (j = 0; j < 16; ++j) {
  8036. state[j] = s[state[j]];
  8037. }
  8038. //ShiftRows
  8039. v = state[1];
  8040. state[1] = state[5];
  8041. state[5] = state[9];
  8042. state[9] = state[13];
  8043. state[13] = v;
  8044. v = state[2];
  8045. u = state[6];
  8046. state[2] = state[10];
  8047. state[6] = state[14];
  8048. state[10] = v;
  8049. state[14] = u;
  8050. v = state[3];
  8051. u = state[7];
  8052. t = state[11];
  8053. state[3] = state[15];
  8054. state[7] = v;
  8055. state[11] = u;
  8056. state[15] = t;
  8057. //AddRoundKey
  8058. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8059. state[j] ^= key[k];
  8060. }
  8061. return state;
  8062. }
  8063. function AES256Cipher(key) {
  8064. this.key = expandKey256(key);
  8065. this.buffer = new Uint8Array(16);
  8066. this.bufferPosition = 0;
  8067. }
  8068. function decryptBlock2(data, finalize) {
  8069. var i, j, ii, sourceLength = data.length,
  8070. buffer = this.buffer, bufferLength = this.bufferPosition,
  8071. result = [], iv = this.iv;
  8072. for (i = 0; i < sourceLength; ++i) {
  8073. buffer[bufferLength] = data[i];
  8074. ++bufferLength;
  8075. if (bufferLength < 16) {
  8076. continue;
  8077. }
  8078. // buffer is full, decrypting
  8079. var plain = decrypt256(buffer, this.key);
  8080. // xor-ing the IV vector to get plain text
  8081. for (j = 0; j < 16; ++j) {
  8082. plain[j] ^= iv[j];
  8083. }
  8084. iv = buffer;
  8085. result.push(plain);
  8086. buffer = new Uint8Array(16);
  8087. bufferLength = 0;
  8088. }
  8089. // saving incomplete buffer
  8090. this.buffer = buffer;
  8091. this.bufferLength = bufferLength;
  8092. this.iv = iv;
  8093. if (result.length === 0) {
  8094. return new Uint8Array([]);
  8095. }
  8096. // combining plain text blocks into one
  8097. var outputLength = 16 * result.length;
  8098. if (finalize) {
  8099. // undo a padding that is described in RFC 2898
  8100. var lastBlock = result[result.length - 1];
  8101. var psLen = lastBlock[15];
  8102. if (psLen <= 16) {
  8103. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8104. if (lastBlock[i] !== psLen) {
  8105. // Invalid padding, assume that the block has no padding.
  8106. psLen = 0;
  8107. break;
  8108. }
  8109. }
  8110. outputLength -= psLen;
  8111. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8112. }
  8113. }
  8114. var output = new Uint8Array(outputLength);
  8115. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8116. output.set(result[i], j);
  8117. }
  8118. return output;
  8119. }
  8120. AES256Cipher.prototype = {
  8121. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8122. var i, sourceLength = data.length;
  8123. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8124. // if not supplied an IV wait for IV values
  8125. // they are at the start of the stream
  8126. if (iv) {
  8127. this.iv = iv;
  8128. } else {
  8129. for (i = 0; bufferLength < 16 &&
  8130. i < sourceLength; ++i, ++bufferLength) {
  8131. buffer[bufferLength] = data[i];
  8132. }
  8133. if (bufferLength < 16) {
  8134. //need more data
  8135. this.bufferLength = bufferLength;
  8136. return new Uint8Array([]);
  8137. }
  8138. this.iv = buffer;
  8139. data = data.subarray(16);
  8140. }
  8141. this.buffer = new Uint8Array(16);
  8142. this.bufferLength = 0;
  8143. // starting decryption
  8144. this.decryptBlock = decryptBlock2;
  8145. return this.decryptBlock(data, finalize);
  8146. },
  8147. encrypt: function AES256Cipher_encrypt(data, iv) {
  8148. var i, j, ii, sourceLength = data.length,
  8149. buffer = this.buffer, bufferLength = this.bufferPosition,
  8150. result = [];
  8151. if (!iv) {
  8152. iv = new Uint8Array(16);
  8153. }
  8154. for (i = 0; i < sourceLength; ++i) {
  8155. buffer[bufferLength] = data[i];
  8156. ++bufferLength;
  8157. if (bufferLength < 16) {
  8158. continue;
  8159. }
  8160. for (j = 0; j < 16; ++j) {
  8161. buffer[j] ^= iv[j];
  8162. }
  8163. // buffer is full, encrypting
  8164. var cipher = encrypt256(buffer, this.key);
  8165. this.iv = cipher;
  8166. result.push(cipher);
  8167. buffer = new Uint8Array(16);
  8168. bufferLength = 0;
  8169. }
  8170. // saving incomplete buffer
  8171. this.buffer = buffer;
  8172. this.bufferLength = bufferLength;
  8173. this.iv = iv;
  8174. if (result.length === 0) {
  8175. return new Uint8Array([]);
  8176. }
  8177. // combining plain text blocks into one
  8178. var outputLength = 16 * result.length;
  8179. var output = new Uint8Array(outputLength);
  8180. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8181. output.set(result[i], j);
  8182. }
  8183. return output;
  8184. }
  8185. };
  8186. return AES256Cipher;
  8187. })();
  8188. var PDF17 = (function PDF17Closure() {
  8189. function compareByteArrays(array1, array2) {
  8190. if (array1.length !== array2.length) {
  8191. return false;
  8192. }
  8193. for (var i = 0; i < array1.length; i++) {
  8194. if (array1[i] !== array2[i]) {
  8195. return false;
  8196. }
  8197. }
  8198. return true;
  8199. }
  8200. function PDF17() {
  8201. }
  8202. PDF17.prototype = {
  8203. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8204. ownerValidationSalt,
  8205. userBytes,
  8206. ownerPassword) {
  8207. var hashData = new Uint8Array(password.length + 56);
  8208. hashData.set(password, 0);
  8209. hashData.set(ownerValidationSalt, password.length);
  8210. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8211. var result = calculateSHA256(hashData, 0, hashData.length);
  8212. return compareByteArrays(result, ownerPassword);
  8213. },
  8214. checkUserPassword: function PDF17_checkUserPassword(password,
  8215. userValidationSalt,
  8216. userPassword) {
  8217. var hashData = new Uint8Array(password.length + 8);
  8218. hashData.set(password, 0);
  8219. hashData.set(userValidationSalt, password.length);
  8220. var result = calculateSHA256(hashData, 0, hashData.length);
  8221. return compareByteArrays(result, userPassword);
  8222. },
  8223. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8224. ownerEncryption) {
  8225. var hashData = new Uint8Array(password.length + 56);
  8226. hashData.set(password, 0);
  8227. hashData.set(ownerKeySalt, password.length);
  8228. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8229. var key = calculateSHA256(hashData, 0, hashData.length);
  8230. var cipher = new AES256Cipher(key);
  8231. return cipher.decryptBlock(ownerEncryption,
  8232. false,
  8233. new Uint8Array(16));
  8234. },
  8235. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8236. userEncryption) {
  8237. var hashData = new Uint8Array(password.length + 8);
  8238. hashData.set(password, 0);
  8239. hashData.set(userKeySalt, password.length);
  8240. //key is the decryption key for the UE string
  8241. var key = calculateSHA256(hashData, 0, hashData.length);
  8242. var cipher = new AES256Cipher(key);
  8243. return cipher.decryptBlock(userEncryption,
  8244. false,
  8245. new Uint8Array(16));
  8246. }
  8247. };
  8248. return PDF17;
  8249. })();
  8250. var PDF20 = (function PDF20Closure() {
  8251. function concatArrays(array1, array2) {
  8252. var t = new Uint8Array(array1.length + array2.length);
  8253. t.set(array1, 0);
  8254. t.set(array2, array1.length);
  8255. return t;
  8256. }
  8257. function calculatePDF20Hash(password, input, userBytes) {
  8258. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8259. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8260. var e = [0];
  8261. var i = 0;
  8262. while (i < 64 || e[e.length - 1] > i - 32) {
  8263. var arrayLength = password.length + k.length + userBytes.length;
  8264. var k1 = new Uint8Array(arrayLength * 64);
  8265. var array = concatArrays(password, k);
  8266. array = concatArrays(array, userBytes);
  8267. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8268. k1.set(array, pos);
  8269. }
  8270. //AES128 CBC NO PADDING with
  8271. //first 16 bytes of k as the key and the second 16 as the iv.
  8272. var cipher = new AES128Cipher(k.subarray(0, 16));
  8273. e = cipher.encrypt(k1, k.subarray(16, 32));
  8274. //Now we have to take the first 16 bytes of an unsigned
  8275. //big endian integer... and compute the remainder
  8276. //modulo 3.... That is a fairly large number and
  8277. //JavaScript isn't going to handle that well...
  8278. //So we're using a trick that allows us to perform
  8279. //modulo math byte by byte
  8280. var remainder = 0;
  8281. for (var z = 0; z < 16; z++) {
  8282. remainder *= (256 % 3);
  8283. remainder %= 3;
  8284. remainder += ((e[z] >>> 0) % 3);
  8285. remainder %= 3;
  8286. }
  8287. if (remainder === 0) {
  8288. k = calculateSHA256(e, 0, e.length);
  8289. }
  8290. else if (remainder === 1) {
  8291. k = calculateSHA384(e, 0, e.length);
  8292. }
  8293. else if (remainder === 2) {
  8294. k = calculateSHA512(e, 0, e.length);
  8295. }
  8296. i++;
  8297. }
  8298. return k.subarray(0, 32);
  8299. }
  8300. function PDF20() {
  8301. }
  8302. function compareByteArrays(array1, array2) {
  8303. if (array1.length !== array2.length) {
  8304. return false;
  8305. }
  8306. for (var i = 0; i < array1.length; i++) {
  8307. if (array1[i] !== array2[i]) {
  8308. return false;
  8309. }
  8310. }
  8311. return true;
  8312. }
  8313. PDF20.prototype = {
  8314. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8315. return calculatePDF20Hash(password, concatBytes, userBytes);
  8316. },
  8317. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8318. ownerValidationSalt,
  8319. userBytes,
  8320. ownerPassword) {
  8321. var hashData = new Uint8Array(password.length + 56);
  8322. hashData.set(password, 0);
  8323. hashData.set(ownerValidationSalt, password.length);
  8324. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8325. var result = calculatePDF20Hash(password, hashData, userBytes);
  8326. return compareByteArrays(result, ownerPassword);
  8327. },
  8328. checkUserPassword: function PDF20_checkUserPassword(password,
  8329. userValidationSalt,
  8330. userPassword) {
  8331. var hashData = new Uint8Array(password.length + 8);
  8332. hashData.set(password, 0);
  8333. hashData.set(userValidationSalt, password.length);
  8334. var result = calculatePDF20Hash(password, hashData, []);
  8335. return compareByteArrays(result, userPassword);
  8336. },
  8337. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8338. ownerEncryption) {
  8339. var hashData = new Uint8Array(password.length + 56);
  8340. hashData.set(password, 0);
  8341. hashData.set(ownerKeySalt, password.length);
  8342. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8343. var key = calculatePDF20Hash(password, hashData, userBytes);
  8344. var cipher = new AES256Cipher(key);
  8345. return cipher.decryptBlock(ownerEncryption,
  8346. false,
  8347. new Uint8Array(16));
  8348. },
  8349. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8350. userEncryption) {
  8351. var hashData = new Uint8Array(password.length + 8);
  8352. hashData.set(password, 0);
  8353. hashData.set(userKeySalt, password.length);
  8354. //key is the decryption key for the UE string
  8355. var key = calculatePDF20Hash(password, hashData, []);
  8356. var cipher = new AES256Cipher(key);
  8357. return cipher.decryptBlock(userEncryption,
  8358. false,
  8359. new Uint8Array(16));
  8360. }
  8361. };
  8362. return PDF20;
  8363. })();
  8364. var CipherTransform = (function CipherTransformClosure() {
  8365. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8366. this.stringCipherConstructor = stringCipherConstructor;
  8367. this.streamCipherConstructor = streamCipherConstructor;
  8368. }
  8369. CipherTransform.prototype = {
  8370. createStream: function CipherTransform_createStream(stream, length) {
  8371. var cipher = new this.streamCipherConstructor();
  8372. return new DecryptStream(stream, length,
  8373. function cipherTransformDecryptStream(data, finalize) {
  8374. return cipher.decryptBlock(data, finalize);
  8375. }
  8376. );
  8377. },
  8378. decryptString: function CipherTransform_decryptString(s) {
  8379. var cipher = new this.stringCipherConstructor();
  8380. var data = stringToBytes(s);
  8381. data = cipher.decryptBlock(data, true);
  8382. return bytesToString(data);
  8383. }
  8384. };
  8385. return CipherTransform;
  8386. })();
  8387. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8388. var defaultPasswordBytes = new Uint8Array([
  8389. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8390. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8391. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8392. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8393. function createEncryptionKey20(revision, password, ownerPassword,
  8394. ownerValidationSalt, ownerKeySalt, uBytes,
  8395. userPassword, userValidationSalt, userKeySalt,
  8396. ownerEncryption, userEncryption, perms) {
  8397. if (password) {
  8398. var passwordLength = Math.min(127, password.length);
  8399. password = password.subarray(0, passwordLength);
  8400. } else {
  8401. password = [];
  8402. }
  8403. var pdfAlgorithm;
  8404. if (revision === 6) {
  8405. pdfAlgorithm = new PDF20();
  8406. } else {
  8407. pdfAlgorithm = new PDF17();
  8408. }
  8409. if (pdfAlgorithm) {
  8410. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8411. userPassword)) {
  8412. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8413. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8414. uBytes,
  8415. ownerPassword)) {
  8416. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8417. ownerEncryption);
  8418. }
  8419. }
  8420. return null;
  8421. }
  8422. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8423. flags, revision, keyLength, encryptMetadata) {
  8424. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8425. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8426. if (password) {
  8427. n = Math.min(32, password.length);
  8428. for (; i < n; ++i) {
  8429. hashData[i] = password[i];
  8430. }
  8431. }
  8432. j = 0;
  8433. while (i < 32) {
  8434. hashData[i++] = defaultPasswordBytes[j++];
  8435. }
  8436. // as now the padded password in the hashData[0..i]
  8437. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8438. hashData[i++] = ownerPassword[j];
  8439. }
  8440. hashData[i++] = flags & 0xFF;
  8441. hashData[i++] = (flags >> 8) & 0xFF;
  8442. hashData[i++] = (flags >> 16) & 0xFF;
  8443. hashData[i++] = (flags >>> 24) & 0xFF;
  8444. for (j = 0, n = fileId.length; j < n; ++j) {
  8445. hashData[i++] = fileId[j];
  8446. }
  8447. if (revision >= 4 && !encryptMetadata) {
  8448. hashData[i++] = 0xFF;
  8449. hashData[i++] = 0xFF;
  8450. hashData[i++] = 0xFF;
  8451. hashData[i++] = 0xFF;
  8452. }
  8453. var hash = calculateMD5(hashData, 0, i);
  8454. var keyLengthInBytes = keyLength >> 3;
  8455. if (revision >= 3) {
  8456. for (j = 0; j < 50; ++j) {
  8457. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8458. }
  8459. }
  8460. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8461. var cipher, checkData;
  8462. if (revision >= 3) {
  8463. for (i = 0; i < 32; ++i) {
  8464. hashData[i] = defaultPasswordBytes[i];
  8465. }
  8466. for (j = 0, n = fileId.length; j < n; ++j) {
  8467. hashData[i++] = fileId[j];
  8468. }
  8469. cipher = new ARCFourCipher(encryptionKey);
  8470. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8471. n = encryptionKey.length;
  8472. var derivedKey = new Uint8Array(n), k;
  8473. for (j = 1; j <= 19; ++j) {
  8474. for (k = 0; k < n; ++k) {
  8475. derivedKey[k] = encryptionKey[k] ^ j;
  8476. }
  8477. cipher = new ARCFourCipher(derivedKey);
  8478. checkData = cipher.encryptBlock(checkData);
  8479. }
  8480. for (j = 0, n = checkData.length; j < n; ++j) {
  8481. if (userPassword[j] !== checkData[j]) {
  8482. return null;
  8483. }
  8484. }
  8485. } else {
  8486. cipher = new ARCFourCipher(encryptionKey);
  8487. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8488. for (j = 0, n = checkData.length; j < n; ++j) {
  8489. if (userPassword[j] !== checkData[j]) {
  8490. return null;
  8491. }
  8492. }
  8493. }
  8494. return encryptionKey;
  8495. }
  8496. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8497. var hashData = new Uint8Array(32), i = 0, j, n;
  8498. n = Math.min(32, password.length);
  8499. for (; i < n; ++i) {
  8500. hashData[i] = password[i];
  8501. }
  8502. j = 0;
  8503. while (i < 32) {
  8504. hashData[i++] = defaultPasswordBytes[j++];
  8505. }
  8506. var hash = calculateMD5(hashData, 0, i);
  8507. var keyLengthInBytes = keyLength >> 3;
  8508. if (revision >= 3) {
  8509. for (j = 0; j < 50; ++j) {
  8510. hash = calculateMD5(hash, 0, hash.length);
  8511. }
  8512. }
  8513. var cipher, userPassword;
  8514. if (revision >= 3) {
  8515. userPassword = ownerPassword;
  8516. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8517. for (j = 19; j >= 0; j--) {
  8518. for (k = 0; k < keyLengthInBytes; ++k) {
  8519. derivedKey[k] = hash[k] ^ j;
  8520. }
  8521. cipher = new ARCFourCipher(derivedKey);
  8522. userPassword = cipher.encryptBlock(userPassword);
  8523. }
  8524. } else {
  8525. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8526. userPassword = cipher.encryptBlock(ownerPassword);
  8527. }
  8528. return userPassword;
  8529. }
  8530. var identityName = Name.get('Identity');
  8531. function CipherTransformFactory(dict, fileId, password) {
  8532. var filter = dict.get('Filter');
  8533. if (!isName(filter) || filter.name !== 'Standard') {
  8534. error('unknown encryption method');
  8535. }
  8536. this.dict = dict;
  8537. var algorithm = dict.get('V');
  8538. if (!isInt(algorithm) ||
  8539. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8540. algorithm !== 5)) {
  8541. error('unsupported encryption algorithm');
  8542. }
  8543. this.algorithm = algorithm;
  8544. var keyLength = dict.get('Length') || 40;
  8545. if (!isInt(keyLength) ||
  8546. keyLength < 40 || (keyLength % 8) !== 0) {
  8547. error('invalid key length');
  8548. }
  8549. // prepare keys
  8550. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8551. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8552. var flags = dict.get('P');
  8553. var revision = dict.get('R');
  8554. // meaningful when V is 4 or 5
  8555. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8556. dict.get('EncryptMetadata') !== false);
  8557. this.encryptMetadata = encryptMetadata;
  8558. var fileIdBytes = stringToBytes(fileId);
  8559. var passwordBytes;
  8560. if (password) {
  8561. passwordBytes = stringToBytes(password);
  8562. }
  8563. var encryptionKey;
  8564. if (algorithm !== 5) {
  8565. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8566. ownerPassword, userPassword, flags,
  8567. revision, keyLength, encryptMetadata);
  8568. }
  8569. else {
  8570. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8571. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8572. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8573. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8574. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8575. var ownerEncryption = stringToBytes(dict.get('OE'));
  8576. var userEncryption = stringToBytes(dict.get('UE'));
  8577. var perms = stringToBytes(dict.get('Perms'));
  8578. encryptionKey =
  8579. createEncryptionKey20(revision, passwordBytes,
  8580. ownerPassword, ownerValidationSalt,
  8581. ownerKeySalt, uBytes,
  8582. userPassword, userValidationSalt,
  8583. userKeySalt, ownerEncryption,
  8584. userEncryption, perms);
  8585. }
  8586. if (!encryptionKey && !password) {
  8587. throw new PasswordException('No password given',
  8588. PasswordResponses.NEED_PASSWORD);
  8589. } else if (!encryptionKey && password) {
  8590. // Attempting use the password as an owner password
  8591. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8592. revision, keyLength);
  8593. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8594. ownerPassword, userPassword, flags,
  8595. revision, keyLength, encryptMetadata);
  8596. }
  8597. if (!encryptionKey) {
  8598. throw new PasswordException('Incorrect Password',
  8599. PasswordResponses.INCORRECT_PASSWORD);
  8600. }
  8601. this.encryptionKey = encryptionKey;
  8602. if (algorithm >= 4) {
  8603. this.cf = dict.get('CF');
  8604. this.stmf = dict.get('StmF') || identityName;
  8605. this.strf = dict.get('StrF') || identityName;
  8606. this.eff = dict.get('EFF') || this.strf;
  8607. }
  8608. }
  8609. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8610. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8611. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8612. key[i] = encryptionKey[i];
  8613. }
  8614. key[i++] = num & 0xFF;
  8615. key[i++] = (num >> 8) & 0xFF;
  8616. key[i++] = (num >> 16) & 0xFF;
  8617. key[i++] = gen & 0xFF;
  8618. key[i++] = (gen >> 8) & 0xFF;
  8619. if (isAes) {
  8620. key[i++] = 0x73;
  8621. key[i++] = 0x41;
  8622. key[i++] = 0x6C;
  8623. key[i++] = 0x54;
  8624. }
  8625. var hash = calculateMD5(key, 0, i);
  8626. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8627. }
  8628. function buildCipherConstructor(cf, name, num, gen, key) {
  8629. var cryptFilter = cf.get(name.name);
  8630. var cfm;
  8631. if (cryptFilter !== null && cryptFilter !== undefined) {
  8632. cfm = cryptFilter.get('CFM');
  8633. }
  8634. if (!cfm || cfm.name === 'None') {
  8635. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8636. return new NullCipher();
  8637. };
  8638. }
  8639. if ('V2' === cfm.name) {
  8640. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8641. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8642. };
  8643. }
  8644. if ('AESV2' === cfm.name) {
  8645. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8646. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8647. };
  8648. }
  8649. if ('AESV3' === cfm.name) {
  8650. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8651. return new AES256Cipher(key);
  8652. };
  8653. }
  8654. error('Unknown crypto method');
  8655. }
  8656. CipherTransformFactory.prototype = {
  8657. createCipherTransform:
  8658. function CipherTransformFactory_createCipherTransform(num, gen) {
  8659. if (this.algorithm === 4 || this.algorithm === 5) {
  8660. return new CipherTransform(
  8661. buildCipherConstructor(this.cf, this.stmf,
  8662. num, gen, this.encryptionKey),
  8663. buildCipherConstructor(this.cf, this.strf,
  8664. num, gen, this.encryptionKey));
  8665. }
  8666. // algorithms 1 and 2
  8667. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8668. var cipherConstructor = function buildCipherCipherConstructor() {
  8669. return new ARCFourCipher(key);
  8670. };
  8671. return new CipherTransform(cipherConstructor, cipherConstructor);
  8672. }
  8673. };
  8674. return CipherTransformFactory;
  8675. })();
  8676. var PatternType = {
  8677. FUNCTION_BASED: 1,
  8678. AXIAL: 2,
  8679. RADIAL: 3,
  8680. FREE_FORM_MESH: 4,
  8681. LATTICE_FORM_MESH: 5,
  8682. COONS_PATCH_MESH: 6,
  8683. TENSOR_PATCH_MESH: 7
  8684. };
  8685. var Pattern = (function PatternClosure() {
  8686. // Constructor should define this.getPattern
  8687. function Pattern() {
  8688. error('should not call Pattern constructor');
  8689. }
  8690. Pattern.prototype = {
  8691. // Input: current Canvas context
  8692. // Output: the appropriate fillStyle or strokeStyle
  8693. getPattern: function Pattern_getPattern(ctx) {
  8694. error('Should not call Pattern.getStyle: ' + ctx);
  8695. }
  8696. };
  8697. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8698. res) {
  8699. var dict = isStream(shading) ? shading.dict : shading;
  8700. var type = dict.get('ShadingType');
  8701. switch (type) {
  8702. case PatternType.AXIAL:
  8703. case PatternType.RADIAL:
  8704. // Both radial and axial shadings are handled by RadialAxial shading.
  8705. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8706. case PatternType.FREE_FORM_MESH:
  8707. case PatternType.LATTICE_FORM_MESH:
  8708. case PatternType.COONS_PATCH_MESH:
  8709. case PatternType.TENSOR_PATCH_MESH:
  8710. return new Shadings.Mesh(shading, matrix, xref, res);
  8711. default:
  8712. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8713. return new Shadings.Dummy();
  8714. }
  8715. };
  8716. return Pattern;
  8717. })();
  8718. var Shadings = {};
  8719. // A small number to offset the first/last color stops so we can insert ones to
  8720. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8721. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8722. // internally so we have to go bigger.
  8723. Shadings.SMALL_NUMBER = 1e-2;
  8724. // Radial and axial shading have very similar implementations
  8725. // If needed, the implementations can be broken into two classes
  8726. Shadings.RadialAxial = (function RadialAxialClosure() {
  8727. function RadialAxial(dict, matrix, xref, res) {
  8728. this.matrix = matrix;
  8729. this.coordsArr = dict.get('Coords');
  8730. this.shadingType = dict.get('ShadingType');
  8731. this.type = 'Pattern';
  8732. var cs = dict.get('ColorSpace', 'CS');
  8733. cs = ColorSpace.parse(cs, xref, res);
  8734. this.cs = cs;
  8735. var t0 = 0.0, t1 = 1.0;
  8736. if (dict.has('Domain')) {
  8737. var domainArr = dict.get('Domain');
  8738. t0 = domainArr[0];
  8739. t1 = domainArr[1];
  8740. }
  8741. var extendStart = false, extendEnd = false;
  8742. if (dict.has('Extend')) {
  8743. var extendArr = dict.get('Extend');
  8744. extendStart = extendArr[0];
  8745. extendEnd = extendArr[1];
  8746. }
  8747. if (this.shadingType === PatternType.RADIAL &&
  8748. (!extendStart || !extendEnd)) {
  8749. // Radial gradient only currently works if either circle is fully within
  8750. // the other circle.
  8751. var x1 = this.coordsArr[0];
  8752. var y1 = this.coordsArr[1];
  8753. var r1 = this.coordsArr[2];
  8754. var x2 = this.coordsArr[3];
  8755. var y2 = this.coordsArr[4];
  8756. var r2 = this.coordsArr[5];
  8757. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8758. if (r1 <= r2 + distance &&
  8759. r2 <= r1 + distance) {
  8760. warn('Unsupported radial gradient.');
  8761. }
  8762. }
  8763. this.extendStart = extendStart;
  8764. this.extendEnd = extendEnd;
  8765. var fnObj = dict.get('Function');
  8766. var fn = PDFFunction.parseArray(xref, fnObj);
  8767. // 10 samples seems good enough for now, but probably won't work
  8768. // if there are sharp color changes. Ideally, we would implement
  8769. // the spec faithfully and add lossless optimizations.
  8770. var diff = t1 - t0;
  8771. var step = diff / 10;
  8772. var colorStops = this.colorStops = [];
  8773. // Protect against bad domains so we don't end up in an infinte loop below.
  8774. if (t0 >= t1 || step <= 0) {
  8775. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8776. // now.
  8777. info('Bad shading domain.');
  8778. return;
  8779. }
  8780. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8781. var rgbColor;
  8782. for (var i = t0; i <= t1; i += step) {
  8783. ratio[0] = i;
  8784. fn(ratio, 0, color, 0);
  8785. rgbColor = cs.getRgb(color, 0);
  8786. var cssColor = Util.makeCssRgb(rgbColor);
  8787. colorStops.push([(i - t0) / diff, cssColor]);
  8788. }
  8789. var background = 'transparent';
  8790. if (dict.has('Background')) {
  8791. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8792. background = Util.makeCssRgb(rgbColor);
  8793. }
  8794. if (!extendStart) {
  8795. // Insert a color stop at the front and offset the first real color stop
  8796. // so it doesn't conflict with the one we insert.
  8797. colorStops.unshift([0, background]);
  8798. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8799. }
  8800. if (!extendEnd) {
  8801. // Same idea as above in extendStart but for the end.
  8802. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8803. colorStops.push([1, background]);
  8804. }
  8805. this.colorStops = colorStops;
  8806. }
  8807. RadialAxial.prototype = {
  8808. getIR: function RadialAxial_getIR() {
  8809. var coordsArr = this.coordsArr;
  8810. var shadingType = this.shadingType;
  8811. var type, p0, p1, r0, r1;
  8812. if (shadingType === PatternType.AXIAL) {
  8813. p0 = [coordsArr[0], coordsArr[1]];
  8814. p1 = [coordsArr[2], coordsArr[3]];
  8815. r0 = null;
  8816. r1 = null;
  8817. type = 'axial';
  8818. } else if (shadingType === PatternType.RADIAL) {
  8819. p0 = [coordsArr[0], coordsArr[1]];
  8820. p1 = [coordsArr[3], coordsArr[4]];
  8821. r0 = coordsArr[2];
  8822. r1 = coordsArr[5];
  8823. type = 'radial';
  8824. } else {
  8825. error('getPattern type unknown: ' + shadingType);
  8826. }
  8827. var matrix = this.matrix;
  8828. if (matrix) {
  8829. p0 = Util.applyTransform(p0, matrix);
  8830. p1 = Util.applyTransform(p1, matrix);
  8831. }
  8832. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  8833. }
  8834. };
  8835. return RadialAxial;
  8836. })();
  8837. // All mesh shading. For now, they will be presented as set of the triangles
  8838. // to be drawn on the canvas and rgb color for each vertex.
  8839. Shadings.Mesh = (function MeshClosure() {
  8840. function MeshStreamReader(stream, context) {
  8841. this.stream = stream;
  8842. this.context = context;
  8843. this.buffer = 0;
  8844. this.bufferLength = 0;
  8845. var numComps = context.numComps;
  8846. this.tmpCompsBuf = new Float32Array(numComps);
  8847. var csNumComps = context.colorSpace;
  8848. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  8849. this.tmpCompsBuf;
  8850. }
  8851. MeshStreamReader.prototype = {
  8852. get hasData() {
  8853. if (this.stream.end) {
  8854. return this.stream.pos < this.stream.end;
  8855. }
  8856. if (this.bufferLength > 0) {
  8857. return true;
  8858. }
  8859. var nextByte = this.stream.getByte();
  8860. if (nextByte < 0) {
  8861. return false;
  8862. }
  8863. this.buffer = nextByte;
  8864. this.bufferLength = 8;
  8865. return true;
  8866. },
  8867. readBits: function MeshStreamReader_readBits(n) {
  8868. var buffer = this.buffer;
  8869. var bufferLength = this.bufferLength;
  8870. if (n === 32) {
  8871. if (bufferLength === 0) {
  8872. return ((this.stream.getByte() << 24) |
  8873. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  8874. this.stream.getByte()) >>> 0;
  8875. }
  8876. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  8877. (this.stream.getByte() << 8) | this.stream.getByte();
  8878. var nextByte = this.stream.getByte();
  8879. this.buffer = nextByte & ((1 << bufferLength) - 1);
  8880. return ((buffer << (8 - bufferLength)) |
  8881. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  8882. }
  8883. if (n === 8 && bufferLength === 0) {
  8884. return this.stream.getByte();
  8885. }
  8886. while (bufferLength < n) {
  8887. buffer = (buffer << 8) | this.stream.getByte();
  8888. bufferLength += 8;
  8889. }
  8890. bufferLength -= n;
  8891. this.bufferLength = bufferLength;
  8892. this.buffer = buffer & ((1 << bufferLength) - 1);
  8893. return buffer >> bufferLength;
  8894. },
  8895. align: function MeshStreamReader_align() {
  8896. this.buffer = 0;
  8897. this.bufferLength = 0;
  8898. },
  8899. readFlag: function MeshStreamReader_readFlag() {
  8900. return this.readBits(this.context.bitsPerFlag);
  8901. },
  8902. readCoordinate: function MeshStreamReader_readCoordinate() {
  8903. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  8904. var xi = this.readBits(bitsPerCoordinate);
  8905. var yi = this.readBits(bitsPerCoordinate);
  8906. var decode = this.context.decode;
  8907. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  8908. 2.3283064365386963e-10; // 2 ^ -32
  8909. return [
  8910. xi * scale * (decode[1] - decode[0]) + decode[0],
  8911. yi * scale * (decode[3] - decode[2]) + decode[2]
  8912. ];
  8913. },
  8914. readComponents: function MeshStreamReader_readComponents() {
  8915. var numComps = this.context.numComps;
  8916. var bitsPerComponent = this.context.bitsPerComponent;
  8917. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  8918. 2.3283064365386963e-10; // 2 ^ -32
  8919. var decode = this.context.decode;
  8920. var components = this.tmpCompsBuf;
  8921. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  8922. var ci = this.readBits(bitsPerComponent);
  8923. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  8924. }
  8925. var color = this.tmpCsCompsBuf;
  8926. if (this.context.colorFn) {
  8927. this.context.colorFn(components, 0, color, 0);
  8928. }
  8929. return this.context.colorSpace.getRgb(color, 0);
  8930. }
  8931. };
  8932. function decodeType4Shading(mesh, reader) {
  8933. var coords = mesh.coords;
  8934. var colors = mesh.colors;
  8935. var operators = [];
  8936. var ps = []; // not maintaining cs since that will match ps
  8937. var verticesLeft = 0; // assuming we have all data to start a new triangle
  8938. while (reader.hasData) {
  8939. var f = reader.readFlag();
  8940. var coord = reader.readCoordinate();
  8941. var color = reader.readComponents();
  8942. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  8943. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  8944. switch (f) {
  8945. case 0:
  8946. verticesLeft = 3;
  8947. break;
  8948. case 1:
  8949. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  8950. verticesLeft = 1;
  8951. break;
  8952. case 2:
  8953. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  8954. verticesLeft = 1;
  8955. break;
  8956. }
  8957. operators.push(f);
  8958. }
  8959. ps.push(coords.length);
  8960. coords.push(coord);
  8961. colors.push(color);
  8962. verticesLeft--;
  8963. reader.align();
  8964. }
  8965. var psPacked = new Int32Array(ps);
  8966. mesh.figures.push({
  8967. type: 'triangles',
  8968. coords: psPacked,
  8969. colors: psPacked
  8970. });
  8971. }
  8972. function decodeType5Shading(mesh, reader, verticesPerRow) {
  8973. var coords = mesh.coords;
  8974. var colors = mesh.colors;
  8975. var ps = []; // not maintaining cs since that will match ps
  8976. while (reader.hasData) {
  8977. var coord = reader.readCoordinate();
  8978. var color = reader.readComponents();
  8979. ps.push(coords.length);
  8980. coords.push(coord);
  8981. colors.push(color);
  8982. }
  8983. var psPacked = new Int32Array(ps);
  8984. mesh.figures.push({
  8985. type: 'lattice',
  8986. coords: psPacked,
  8987. colors: psPacked,
  8988. verticesPerRow: verticesPerRow
  8989. });
  8990. }
  8991. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  8992. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  8993. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  8994. var getB = (function getBClosure() {
  8995. function buildB(count) {
  8996. var lut = [];
  8997. for (var i = 0; i <= count; i++) {
  8998. var t = i / count, t_ = 1 - t;
  8999. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9000. 3 * t * t * t_, t * t * t]));
  9001. }
  9002. return lut;
  9003. }
  9004. var cache = [];
  9005. return function getB(count) {
  9006. if (!cache[count]) {
  9007. cache[count] = buildB(count);
  9008. }
  9009. return cache[count];
  9010. };
  9011. })();
  9012. function buildFigureFromPatch(mesh, index) {
  9013. var figure = mesh.figures[index];
  9014. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9015. var coords = mesh.coords, colors = mesh.colors;
  9016. var pi = figure.coords;
  9017. var ci = figure.colors;
  9018. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9019. coords[pi[12]][0], coords[pi[15]][0]);
  9020. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9021. coords[pi[12]][1], coords[pi[15]][1]);
  9022. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9023. coords[pi[12]][0], coords[pi[15]][0]);
  9024. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9025. coords[pi[12]][1], coords[pi[15]][1]);
  9026. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9027. (mesh.bounds[2] - mesh.bounds[0]));
  9028. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9029. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9030. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9031. (mesh.bounds[3] - mesh.bounds[1]));
  9032. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9033. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9034. var verticesPerRow = splitXBy + 1;
  9035. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9036. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9037. var k = 0;
  9038. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9039. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9040. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9041. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9042. for (var row = 0; row <= splitYBy; row++) {
  9043. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9044. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9045. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9046. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9047. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9048. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9049. for (var col = 0; col <= splitXBy; col++, k++) {
  9050. if ((row === 0 || row === splitYBy) &&
  9051. (col === 0 || col === splitXBy)) {
  9052. continue;
  9053. }
  9054. var x = 0, y = 0;
  9055. var q = 0;
  9056. for (var i = 0; i <= 3; i++) {
  9057. for (var j = 0; j <= 3; j++, q++) {
  9058. var m = bRow[row][i] * bCol[col][j];
  9059. x += coords[pi[q]][0] * m;
  9060. y += coords[pi[q]][1] * m;
  9061. }
  9062. }
  9063. figureCoords[k] = coords.length;
  9064. coords.push([x, y]);
  9065. figureColors[k] = colors.length;
  9066. var newColor = new Uint8Array(3);
  9067. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9068. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9069. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9070. colors.push(newColor);
  9071. }
  9072. }
  9073. figureCoords[0] = pi[0];
  9074. figureColors[0] = ci[0];
  9075. figureCoords[splitXBy] = pi[3];
  9076. figureColors[splitXBy] = ci[1];
  9077. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9078. figureColors[verticesPerRow * splitYBy] = ci[2];
  9079. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9080. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9081. mesh.figures[index] = {
  9082. type: 'lattice',
  9083. coords: figureCoords,
  9084. colors: figureColors,
  9085. verticesPerRow: verticesPerRow
  9086. };
  9087. }
  9088. function decodeType6Shading(mesh, reader) {
  9089. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9090. var coords = mesh.coords;
  9091. var colors = mesh.colors;
  9092. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9093. var cs = new Int32Array(4); // c00, c30, c03, c33
  9094. while (reader.hasData) {
  9095. var f = reader.readFlag();
  9096. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9097. var i, ii;
  9098. var pi = coords.length;
  9099. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9100. coords.push(reader.readCoordinate());
  9101. }
  9102. var ci = colors.length;
  9103. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9104. colors.push(reader.readComponents());
  9105. }
  9106. var tmp1, tmp2, tmp3, tmp4;
  9107. switch (f) {
  9108. case 0:
  9109. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9110. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9111. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9112. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9113. cs[2] = ci + 1; cs[3] = ci + 2;
  9114. cs[0] = ci; cs[1] = ci + 3;
  9115. break;
  9116. case 1:
  9117. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9118. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9119. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9120. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9121. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9122. tmp1 = cs[2]; tmp2 = cs[3];
  9123. cs[2] = ci + 1; cs[3] = ci;
  9124. cs[0] = tmp1; cs[1] = tmp2;
  9125. break;
  9126. case 2:
  9127. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9128. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9129. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9130. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9131. cs[2] = cs[3]; cs[3] = ci + 1;
  9132. cs[0] = cs[1]; cs[1] = ci;
  9133. break;
  9134. case 3:
  9135. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9136. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9137. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9138. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9139. cs[2] = cs[0]; cs[3] = cs[1];
  9140. cs[0] = ci; cs[1] = ci + 1;
  9141. break;
  9142. }
  9143. // set p11, p12, p21, p22
  9144. ps[5] = coords.length;
  9145. coords.push([
  9146. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9147. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9148. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9149. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9150. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9151. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9152. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9153. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9154. ]);
  9155. ps[6] = coords.length;
  9156. coords.push([
  9157. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9158. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9159. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9160. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9161. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9162. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9163. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9164. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9165. ]);
  9166. ps[9] = coords.length;
  9167. coords.push([
  9168. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9169. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9170. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9171. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9172. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9173. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9174. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9175. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9176. ]);
  9177. ps[10] = coords.length;
  9178. coords.push([
  9179. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9180. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9181. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9182. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9183. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9184. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9185. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9186. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9187. ]);
  9188. mesh.figures.push({
  9189. type: 'patch',
  9190. coords: new Int32Array(ps), // making copies of ps and cs
  9191. colors: new Int32Array(cs)
  9192. });
  9193. }
  9194. }
  9195. function decodeType7Shading(mesh, reader) {
  9196. var coords = mesh.coords;
  9197. var colors = mesh.colors;
  9198. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9199. var cs = new Int32Array(4); // c00, c30, c03, c33
  9200. while (reader.hasData) {
  9201. var f = reader.readFlag();
  9202. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9203. var i, ii;
  9204. var pi = coords.length;
  9205. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9206. coords.push(reader.readCoordinate());
  9207. }
  9208. var ci = colors.length;
  9209. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9210. colors.push(reader.readComponents());
  9211. }
  9212. var tmp1, tmp2, tmp3, tmp4;
  9213. switch (f) {
  9214. case 0:
  9215. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9216. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9217. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9218. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9219. cs[2] = ci + 1; cs[3] = ci + 2;
  9220. cs[0] = ci; cs[1] = ci + 3;
  9221. break;
  9222. case 1:
  9223. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9224. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9225. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9226. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9227. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9228. tmp1 = cs[2]; tmp2 = cs[3];
  9229. cs[2] = ci + 1; cs[3] = ci;
  9230. cs[0] = tmp1; cs[1] = tmp2;
  9231. break;
  9232. case 2:
  9233. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9234. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9235. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9236. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9237. cs[2] = cs[3]; cs[3] = ci + 1;
  9238. cs[0] = cs[1]; cs[1] = ci;
  9239. break;
  9240. case 3:
  9241. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9242. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9243. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9244. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9245. cs[2] = cs[0]; cs[3] = cs[1];
  9246. cs[0] = ci; cs[1] = ci + 1;
  9247. break;
  9248. }
  9249. mesh.figures.push({
  9250. type: 'patch',
  9251. coords: new Int32Array(ps), // making copies of ps and cs
  9252. colors: new Int32Array(cs)
  9253. });
  9254. }
  9255. }
  9256. function updateBounds(mesh) {
  9257. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9258. maxX = minX, maxY = minY;
  9259. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9260. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9261. minX = minX > x ? x : minX;
  9262. minY = minY > y ? y : minY;
  9263. maxX = maxX < x ? x : maxX;
  9264. maxY = maxY < y ? y : maxY;
  9265. }
  9266. mesh.bounds = [minX, minY, maxX, maxY];
  9267. }
  9268. function packData(mesh) {
  9269. var i, ii, j, jj;
  9270. var coords = mesh.coords;
  9271. var coordsPacked = new Float32Array(coords.length * 2);
  9272. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9273. var xy = coords[i];
  9274. coordsPacked[j++] = xy[0];
  9275. coordsPacked[j++] = xy[1];
  9276. }
  9277. mesh.coords = coordsPacked;
  9278. var colors = mesh.colors;
  9279. var colorsPacked = new Uint8Array(colors.length * 3);
  9280. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9281. var c = colors[i];
  9282. colorsPacked[j++] = c[0];
  9283. colorsPacked[j++] = c[1];
  9284. colorsPacked[j++] = c[2];
  9285. }
  9286. mesh.colors = colorsPacked;
  9287. var figures = mesh.figures;
  9288. for (i = 0, ii = figures.length; i < ii; i++) {
  9289. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9290. for (j = 0, jj = ps.length; j < jj; j++) {
  9291. ps[j] *= 2;
  9292. cs[j] *= 3;
  9293. }
  9294. }
  9295. }
  9296. function Mesh(stream, matrix, xref, res) {
  9297. assert(isStream(stream), 'Mesh data is not a stream');
  9298. var dict = stream.dict;
  9299. this.matrix = matrix;
  9300. this.shadingType = dict.get('ShadingType');
  9301. this.type = 'Pattern';
  9302. this.bbox = dict.get('BBox');
  9303. var cs = dict.get('ColorSpace', 'CS');
  9304. cs = ColorSpace.parse(cs, xref, res);
  9305. this.cs = cs;
  9306. this.background = dict.has('Background') ?
  9307. cs.getRgb(dict.get('Background'), 0) : null;
  9308. var fnObj = dict.get('Function');
  9309. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9310. this.coords = [];
  9311. this.colors = [];
  9312. this.figures = [];
  9313. var decodeContext = {
  9314. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9315. bitsPerComponent: dict.get('BitsPerComponent'),
  9316. bitsPerFlag: dict.get('BitsPerFlag'),
  9317. decode: dict.get('Decode'),
  9318. colorFn: fn,
  9319. colorSpace: cs,
  9320. numComps: fn ? 1 : cs.numComps
  9321. };
  9322. var reader = new MeshStreamReader(stream, decodeContext);
  9323. var patchMesh = false;
  9324. switch (this.shadingType) {
  9325. case PatternType.FREE_FORM_MESH:
  9326. decodeType4Shading(this, reader);
  9327. break;
  9328. case PatternType.LATTICE_FORM_MESH:
  9329. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9330. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9331. decodeType5Shading(this, reader, verticesPerRow);
  9332. break;
  9333. case PatternType.COONS_PATCH_MESH:
  9334. decodeType6Shading(this, reader);
  9335. patchMesh = true;
  9336. break;
  9337. case PatternType.TENSOR_PATCH_MESH:
  9338. decodeType7Shading(this, reader);
  9339. patchMesh = true;
  9340. break;
  9341. default:
  9342. error('Unsupported mesh type.');
  9343. break;
  9344. }
  9345. if (patchMesh) {
  9346. // dirty bounds calculation for determining, how dense shall be triangles
  9347. updateBounds(this);
  9348. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9349. buildFigureFromPatch(this, i);
  9350. }
  9351. }
  9352. // calculate bounds
  9353. updateBounds(this);
  9354. packData(this);
  9355. }
  9356. Mesh.prototype = {
  9357. getIR: function Mesh_getIR() {
  9358. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9359. this.bounds, this.matrix, this.bbox, this.background];
  9360. }
  9361. };
  9362. return Mesh;
  9363. })();
  9364. Shadings.Dummy = (function DummyClosure() {
  9365. function Dummy() {
  9366. this.type = 'Pattern';
  9367. }
  9368. Dummy.prototype = {
  9369. getIR: function Dummy_getIR() {
  9370. return ['Dummy'];
  9371. }
  9372. };
  9373. return Dummy;
  9374. })();
  9375. function getTilingPatternIR(operatorList, dict, args) {
  9376. var matrix = dict.get('Matrix');
  9377. var bbox = dict.get('BBox');
  9378. var xstep = dict.get('XStep');
  9379. var ystep = dict.get('YStep');
  9380. var paintType = dict.get('PaintType');
  9381. var tilingType = dict.get('TilingType');
  9382. return [
  9383. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9384. paintType, tilingType
  9385. ];
  9386. }
  9387. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9388. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9389. uniquePrefix, idCounters, fontCache) {
  9390. this.pdfManager = pdfManager;
  9391. this.xref = xref;
  9392. this.handler = handler;
  9393. this.pageIndex = pageIndex;
  9394. this.uniquePrefix = uniquePrefix;
  9395. this.idCounters = idCounters;
  9396. this.fontCache = fontCache;
  9397. }
  9398. // Trying to minimize Date.now() usage and check every 100 time
  9399. var TIME_SLOT_DURATION_MS = 20;
  9400. var CHECK_TIME_EVERY = 100;
  9401. function TimeSlotManager() {
  9402. this.reset();
  9403. }
  9404. TimeSlotManager.prototype = {
  9405. check: function TimeSlotManager_check() {
  9406. if (++this.checked < CHECK_TIME_EVERY) {
  9407. return false;
  9408. }
  9409. this.checked = 0;
  9410. return this.endTime <= Date.now();
  9411. },
  9412. reset: function TimeSlotManager_reset() {
  9413. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9414. this.checked = 0;
  9415. }
  9416. };
  9417. var deferred = Promise.resolve();
  9418. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9419. PartialEvaluator.prototype = {
  9420. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9421. if (!isDict(resources)) {
  9422. return false;
  9423. }
  9424. var processed = Object.create(null);
  9425. if (resources.objId) {
  9426. processed[resources.objId] = true;
  9427. }
  9428. var nodes = [resources];
  9429. while (nodes.length) {
  9430. var key;
  9431. var node = nodes.shift();
  9432. // First check the current resources for blend modes.
  9433. var graphicStates = node.get('ExtGState');
  9434. if (isDict(graphicStates)) {
  9435. graphicStates = graphicStates.getAll();
  9436. for (key in graphicStates) {
  9437. var graphicState = graphicStates[key];
  9438. var bm = graphicState['BM'];
  9439. if (isName(bm) && bm.name !== 'Normal') {
  9440. return true;
  9441. }
  9442. }
  9443. }
  9444. // Descend into the XObjects to look for more resources and blend modes.
  9445. var xObjects = node.get('XObject');
  9446. if (!isDict(xObjects)) {
  9447. continue;
  9448. }
  9449. xObjects = xObjects.getAll();
  9450. for (key in xObjects) {
  9451. var xObject = xObjects[key];
  9452. if (!isStream(xObject)) {
  9453. continue;
  9454. }
  9455. if (xObject.dict.objId) {
  9456. if (processed[xObject.dict.objId]) {
  9457. // stream has objId and is processed already
  9458. continue;
  9459. }
  9460. processed[xObject.dict.objId] = true;
  9461. }
  9462. var xResources = xObject.dict.get('Resources');
  9463. // Checking objId to detect an infinite loop.
  9464. if (isDict(xResources) &&
  9465. (!xResources.objId || !processed[xResources.objId])) {
  9466. nodes.push(xResources);
  9467. if (xResources.objId) {
  9468. processed[xResources.objId] = true;
  9469. }
  9470. }
  9471. }
  9472. }
  9473. return false;
  9474. },
  9475. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9476. xobj, smask,
  9477. operatorList,
  9478. initialState) {
  9479. var matrix = xobj.dict.get('Matrix');
  9480. var bbox = xobj.dict.get('BBox');
  9481. var group = xobj.dict.get('Group');
  9482. if (group) {
  9483. var groupOptions = {
  9484. matrix: matrix,
  9485. bbox: bbox,
  9486. smask: smask,
  9487. isolated: false,
  9488. knockout: false
  9489. };
  9490. var groupSubtype = group.get('S');
  9491. var colorSpace;
  9492. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9493. groupOptions.isolated = (group.get('I') || false);
  9494. groupOptions.knockout = (group.get('K') || false);
  9495. colorSpace = (group.has('CS') ?
  9496. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9497. }
  9498. if (smask && smask.backdrop) {
  9499. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9500. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9501. }
  9502. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9503. }
  9504. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9505. return this.getOperatorList(xobj,
  9506. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9507. then(function () {
  9508. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9509. if (group) {
  9510. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9511. }
  9512. });
  9513. },
  9514. buildPaintImageXObject:
  9515. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9516. inline, operatorList,
  9517. cacheKey, cache) {
  9518. var self = this;
  9519. var dict = image.dict;
  9520. var w = dict.get('Width', 'W');
  9521. var h = dict.get('Height', 'H');
  9522. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9523. warn('Image dimensions are missing, or not numbers.');
  9524. return;
  9525. }
  9526. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9527. warn('Image exceeded maximum allowed size and was removed.');
  9528. return;
  9529. }
  9530. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9531. var imgData, args;
  9532. if (imageMask) {
  9533. // This depends on a tmpCanvas being filled with the
  9534. // current fillStyle, such that processing the pixel
  9535. // data can't be done here. Instead of creating a
  9536. // complete PDFImage, only read the information needed
  9537. // for later.
  9538. var width = dict.get('Width', 'W');
  9539. var height = dict.get('Height', 'H');
  9540. var bitStrideLength = (width + 7) >> 3;
  9541. var imgArray = image.getBytes(bitStrideLength * height);
  9542. var decode = dict.get('Decode', 'D');
  9543. var inverseDecode = (!!decode && decode[0] > 0);
  9544. imgData = PDFImage.createMask(imgArray, width, height,
  9545. image instanceof DecodeStream,
  9546. inverseDecode);
  9547. imgData.cached = true;
  9548. args = [imgData];
  9549. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9550. if (cacheKey) {
  9551. cache.key = cacheKey;
  9552. cache.fn = OPS.paintImageMaskXObject;
  9553. cache.args = args;
  9554. }
  9555. return;
  9556. }
  9557. var softMask = (dict.get('SMask', 'SM') || false);
  9558. var mask = (dict.get('Mask') || false);
  9559. var SMALL_IMAGE_DIMENSIONS = 200;
  9560. // Inlining small images into the queue as RGB data
  9561. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9562. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9563. var imageObj = new PDFImage(this.xref, resources, image,
  9564. inline, null, null);
  9565. // We force the use of RGBA_32BPP images here, because we can't handle
  9566. // any other kind.
  9567. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9568. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9569. return;
  9570. }
  9571. // If there is no imageMask, create the PDFImage and a lot
  9572. // of image processing can be done here.
  9573. var uniquePrefix = (this.uniquePrefix || '');
  9574. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9575. operatorList.addDependency(objId);
  9576. args = [objId, w, h];
  9577. if (!softMask && !mask && image instanceof JpegStream &&
  9578. image.isNativelySupported(this.xref, resources)) {
  9579. // These JPEGs don't need any more processing so we can just send it.
  9580. operatorList.addOp(OPS.paintJpegXObject, args);
  9581. this.handler.send('obj',
  9582. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9583. return;
  9584. }
  9585. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9586. then(function(imageObj) {
  9587. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9588. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9589. [imgData.data.buffer]);
  9590. }).then(null, function (reason) {
  9591. warn('Unable to decode image: ' + reason);
  9592. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9593. });
  9594. operatorList.addOp(OPS.paintImageXObject, args);
  9595. if (cacheKey) {
  9596. cache.key = cacheKey;
  9597. cache.fn = OPS.paintImageXObject;
  9598. cache.args = args;
  9599. }
  9600. },
  9601. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9602. operatorList,
  9603. stateManager) {
  9604. var smaskContent = smask.get('G');
  9605. var smaskOptions = {
  9606. subtype: smask.get('S').name,
  9607. backdrop: smask.get('BC')
  9608. };
  9609. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9610. operatorList, stateManager.state.clone());
  9611. },
  9612. handleTilingType:
  9613. function PartialEvaluator_handleTilingType(fn, args, resources,
  9614. pattern, patternDict,
  9615. operatorList) {
  9616. // Create an IR of the pattern code.
  9617. var tilingOpList = new OperatorList();
  9618. return this.getOperatorList(pattern,
  9619. (patternDict.get('Resources') || resources), tilingOpList).
  9620. then(function () {
  9621. // Add the dependencies to the parent operator list so they are
  9622. // resolved before sub operator list is executed synchronously.
  9623. operatorList.addDependencies(tilingOpList.dependencies);
  9624. operatorList.addOp(fn, getTilingPatternIR({
  9625. fnArray: tilingOpList.fnArray,
  9626. argsArray: tilingOpList.argsArray
  9627. }, patternDict, args));
  9628. });
  9629. },
  9630. handleSetFont:
  9631. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9632. operatorList, state) {
  9633. // TODO(mack): Not needed?
  9634. var fontName;
  9635. if (fontArgs) {
  9636. fontArgs = fontArgs.slice();
  9637. fontName = fontArgs[0].name;
  9638. }
  9639. var self = this;
  9640. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9641. function (translated) {
  9642. if (!translated.font.isType3Font) {
  9643. return translated;
  9644. }
  9645. return translated.loadType3Data(self, resources, operatorList).then(
  9646. function () {
  9647. return translated;
  9648. });
  9649. }).then(function (translated) {
  9650. state.font = translated.font;
  9651. translated.send(self.handler);
  9652. return translated.loadedName;
  9653. });
  9654. },
  9655. handleText: function PartialEvaluator_handleText(chars, state) {
  9656. var font = state.font;
  9657. var glyphs = font.charsToGlyphs(chars);
  9658. var isAddToPathSet = !!(state.textRenderingMode &
  9659. TextRenderingMode.ADD_TO_PATH_FLAG);
  9660. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9661. var buildPath = function (fontChar) {
  9662. if (!font.renderer.hasBuiltPath(fontChar)) {
  9663. var path = font.renderer.getPathJs(fontChar);
  9664. this.handler.send('commonobj', [
  9665. font.loadedName + '_path_' + fontChar,
  9666. 'FontPath',
  9667. path
  9668. ]);
  9669. }
  9670. }.bind(this);
  9671. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9672. var glyph = glyphs[i];
  9673. if (glyph === null) {
  9674. continue;
  9675. }
  9676. buildPath(glyph.fontChar);
  9677. // If the glyph has an accent we need to build a path for its
  9678. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9679. var accent = glyph.accent;
  9680. if (accent && accent.fontChar) {
  9681. buildPath(accent.fontChar);
  9682. }
  9683. }
  9684. }
  9685. return glyphs;
  9686. },
  9687. setGState: function PartialEvaluator_setGState(resources, gState,
  9688. operatorList, xref,
  9689. stateManager) {
  9690. // This array holds the converted/processed state data.
  9691. var gStateObj = [];
  9692. var gStateMap = gState.map;
  9693. var self = this;
  9694. var promise = Promise.resolve();
  9695. for (var key in gStateMap) {
  9696. var value = gStateMap[key];
  9697. switch (key) {
  9698. case 'Type':
  9699. break;
  9700. case 'LW':
  9701. case 'LC':
  9702. case 'LJ':
  9703. case 'ML':
  9704. case 'D':
  9705. case 'RI':
  9706. case 'FL':
  9707. case 'CA':
  9708. case 'ca':
  9709. gStateObj.push([key, value]);
  9710. break;
  9711. case 'Font':
  9712. promise = promise.then(function () {
  9713. return self.handleSetFont(resources, null, value[0],
  9714. operatorList, stateManager.state).
  9715. then(function (loadedName) {
  9716. operatorList.addDependency(loadedName);
  9717. gStateObj.push([key, [loadedName, value[1]]]);
  9718. });
  9719. });
  9720. break;
  9721. case 'BM':
  9722. gStateObj.push([key, value]);
  9723. break;
  9724. case 'SMask':
  9725. if (isName(value) && value.name === 'None') {
  9726. gStateObj.push([key, false]);
  9727. break;
  9728. }
  9729. var dict = xref.fetchIfRef(value);
  9730. if (isDict(dict)) {
  9731. promise = promise.then(function () {
  9732. return self.handleSMask(dict, resources, operatorList,
  9733. stateManager);
  9734. });
  9735. gStateObj.push([key, true]);
  9736. } else {
  9737. warn('Unsupported SMask type');
  9738. }
  9739. break;
  9740. // Only generate info log messages for the following since
  9741. // they are unlikely to have a big impact on the rendering.
  9742. case 'OP':
  9743. case 'op':
  9744. case 'OPM':
  9745. case 'BG':
  9746. case 'BG2':
  9747. case 'UCR':
  9748. case 'UCR2':
  9749. case 'TR':
  9750. case 'TR2':
  9751. case 'HT':
  9752. case 'SM':
  9753. case 'SA':
  9754. case 'AIS':
  9755. case 'TK':
  9756. // TODO implement these operators.
  9757. info('graphic state operator ' + key);
  9758. break;
  9759. default:
  9760. info('Unknown graphic state operator ' + key);
  9761. break;
  9762. }
  9763. }
  9764. return promise.then(function () {
  9765. if (gStateObj.length >= 0) {
  9766. operatorList.addOp(OPS.setGState, [gStateObj]);
  9767. }
  9768. });
  9769. },
  9770. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9771. resources) {
  9772. function errorFont() {
  9773. return Promise.resolve(new TranslatedFont('g_font_error',
  9774. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9775. }
  9776. var fontRef;
  9777. if (font) { // Loading by ref.
  9778. assert(isRef(font));
  9779. fontRef = font;
  9780. } else { // Loading by name.
  9781. var fontRes = resources.get('Font');
  9782. if (fontRes) {
  9783. fontRef = fontRes.getRaw(fontName);
  9784. } else {
  9785. warn('fontRes not available');
  9786. return errorFont();
  9787. }
  9788. }
  9789. if (!fontRef) {
  9790. warn('fontRef not available');
  9791. return errorFont();
  9792. }
  9793. if (this.fontCache.has(fontRef)) {
  9794. return this.fontCache.get(fontRef);
  9795. }
  9796. font = xref.fetchIfRef(fontRef);
  9797. if (!isDict(font)) {
  9798. return errorFont();
  9799. }
  9800. // We are holding font.translated references just for fontRef that are not
  9801. // dictionaries (Dict). See explanation below.
  9802. if (font.translated) {
  9803. return font.translated;
  9804. }
  9805. var fontCapability = createPromiseCapability();
  9806. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9807. var descriptor = preEvaluatedFont.descriptor;
  9808. var fontID = fontRef.num + '_' + fontRef.gen;
  9809. if (isDict(descriptor)) {
  9810. if (!descriptor.fontAliases) {
  9811. descriptor.fontAliases = Object.create(null);
  9812. }
  9813. var fontAliases = descriptor.fontAliases;
  9814. var hash = preEvaluatedFont.hash;
  9815. if (fontAliases[hash]) {
  9816. var aliasFontRef = fontAliases[hash].aliasRef;
  9817. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9818. this.fontCache.putAlias(fontRef, aliasFontRef);
  9819. return this.fontCache.get(fontRef);
  9820. }
  9821. }
  9822. if (!fontAliases[hash]) {
  9823. fontAliases[hash] = {
  9824. fontID: Font.getFontID()
  9825. };
  9826. }
  9827. fontAliases[hash].aliasRef = fontRef;
  9828. fontID = fontAliases[hash].fontID;
  9829. }
  9830. // Workaround for bad PDF generators that don't reference fonts
  9831. // properly, i.e. by not using an object identifier.
  9832. // Check if the fontRef is a Dict (as opposed to a standard object),
  9833. // in which case we don't cache the font and instead reference it by
  9834. // fontName in font.loadedName below.
  9835. var fontRefIsDict = isDict(fontRef);
  9836. if (!fontRefIsDict) {
  9837. this.fontCache.put(fontRef, fontCapability.promise);
  9838. }
  9839. // Keep track of each font we translated so the caller can
  9840. // load them asynchronously before calling display on a page.
  9841. font.loadedName = 'g_font_' + (fontRefIsDict ?
  9842. fontName.replace(/\W/g, '') : fontID);
  9843. font.translated = fontCapability.promise;
  9844. // TODO move promises into translate font
  9845. var translatedPromise;
  9846. try {
  9847. translatedPromise = Promise.resolve(
  9848. this.translateFont(preEvaluatedFont, xref));
  9849. } catch (e) {
  9850. translatedPromise = Promise.reject(e);
  9851. }
  9852. translatedPromise.then(function (translatedFont) {
  9853. if (translatedFont.fontType !== undefined) {
  9854. var xrefFontStats = xref.stats.fontTypes;
  9855. xrefFontStats[translatedFont.fontType] = true;
  9856. }
  9857. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9858. translatedFont, font));
  9859. }, function (reason) {
  9860. // TODO fontCapability.reject?
  9861. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  9862. try {
  9863. // error, but it's still nice to have font type reported
  9864. var descriptor = preEvaluatedFont.descriptor;
  9865. var fontFile3 = descriptor && descriptor.get('FontFile3');
  9866. var subtype = fontFile3 && fontFile3.get('Subtype');
  9867. var fontType = getFontType(preEvaluatedFont.type,
  9868. subtype && subtype.name);
  9869. var xrefFontStats = xref.stats.fontTypes;
  9870. xrefFontStats[fontType] = true;
  9871. } catch (ex) { }
  9872. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9873. new ErrorFont(reason instanceof Error ? reason.message : reason),
  9874. font));
  9875. });
  9876. return fontCapability.promise;
  9877. },
  9878. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  9879. var lastIndex = operatorList.length - 1;
  9880. if (!args) {
  9881. args = [];
  9882. }
  9883. if (lastIndex < 0 ||
  9884. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  9885. operatorList.addOp(OPS.constructPath, [[fn], args]);
  9886. } else {
  9887. var opArgs = operatorList.argsArray[lastIndex];
  9888. opArgs[0].push(fn);
  9889. Array.prototype.push.apply(opArgs[1], args);
  9890. }
  9891. },
  9892. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  9893. cs, patterns, resources, xref) {
  9894. // compile tiling patterns
  9895. var patternName = args[args.length - 1];
  9896. // SCN/scn applies patterns along with normal colors
  9897. var pattern;
  9898. if (isName(patternName) &&
  9899. (pattern = patterns.get(patternName.name))) {
  9900. var dict = (isStream(pattern) ? pattern.dict : pattern);
  9901. var typeNum = dict.get('PatternType');
  9902. if (typeNum === TILING_PATTERN) {
  9903. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  9904. return this.handleTilingType(fn, color, resources, pattern,
  9905. dict, operatorList);
  9906. } else if (typeNum === SHADING_PATTERN) {
  9907. var shading = dict.get('Shading');
  9908. var matrix = dict.get('Matrix');
  9909. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  9910. operatorList.addOp(fn, pattern.getIR());
  9911. return Promise.resolve();
  9912. } else {
  9913. return Promise.reject('Unknown PatternType: ' + typeNum);
  9914. }
  9915. }
  9916. // TODO shall we fail here?
  9917. operatorList.addOp(fn, args);
  9918. return Promise.resolve();
  9919. },
  9920. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  9921. resources,
  9922. operatorList,
  9923. initialState) {
  9924. var self = this;
  9925. var xref = this.xref;
  9926. var imageCache = {};
  9927. assert(operatorList);
  9928. resources = (resources || Dict.empty);
  9929. var xobjs = (resources.get('XObject') || Dict.empty);
  9930. var patterns = (resources.get('Pattern') || Dict.empty);
  9931. var stateManager = new StateManager(initialState || new EvalState());
  9932. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9933. var timeSlotManager = new TimeSlotManager();
  9934. return new Promise(function next(resolve, reject) {
  9935. timeSlotManager.reset();
  9936. var stop, operation = {}, i, ii, cs;
  9937. while (!(stop = timeSlotManager.check())) {
  9938. // The arguments parsed by read() are used beyond this loop, so we
  9939. // cannot reuse the same array on each iteration. Therefore we pass
  9940. // in |null| as the initial value (see the comment on
  9941. // EvaluatorPreprocessor_read() for why).
  9942. operation.args = null;
  9943. if (!(preprocessor.read(operation))) {
  9944. break;
  9945. }
  9946. var args = operation.args;
  9947. var fn = operation.fn;
  9948. switch (fn | 0) {
  9949. case OPS.paintXObject:
  9950. if (args[0].code) {
  9951. break;
  9952. }
  9953. // eagerly compile XForm objects
  9954. var name = args[0].name;
  9955. if (imageCache.key === name) {
  9956. operatorList.addOp(imageCache.fn, imageCache.args);
  9957. args = null;
  9958. continue;
  9959. }
  9960. var xobj = xobjs.get(name);
  9961. if (xobj) {
  9962. assert(isStream(xobj), 'XObject should be a stream');
  9963. var type = xobj.dict.get('Subtype');
  9964. assert(isName(type),
  9965. 'XObject should have a Name subtype');
  9966. if (type.name === 'Form') {
  9967. stateManager.save();
  9968. return self.buildFormXObject(resources, xobj, null,
  9969. operatorList,
  9970. stateManager.state.clone()).
  9971. then(function () {
  9972. stateManager.restore();
  9973. next(resolve, reject);
  9974. }, reject);
  9975. } else if (type.name === 'Image') {
  9976. self.buildPaintImageXObject(resources, xobj, false,
  9977. operatorList, name, imageCache);
  9978. args = null;
  9979. continue;
  9980. } else if (type.name === 'PS') {
  9981. // PostScript XObjects are unused when viewing documents.
  9982. // See section 4.7.1 of Adobe's PDF reference.
  9983. info('Ignored XObject subtype PS');
  9984. continue;
  9985. } else {
  9986. error('Unhandled XObject subtype ' + type.name);
  9987. }
  9988. }
  9989. break;
  9990. case OPS.setFont:
  9991. var fontSize = args[1];
  9992. // eagerly collect all fonts
  9993. return self.handleSetFont(resources, args, null,
  9994. operatorList, stateManager.state).
  9995. then(function (loadedName) {
  9996. operatorList.addDependency(loadedName);
  9997. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  9998. next(resolve, reject);
  9999. }, reject);
  10000. case OPS.endInlineImage:
  10001. var cacheKey = args[0].cacheKey;
  10002. if (cacheKey && imageCache.key === cacheKey) {
  10003. operatorList.addOp(imageCache.fn, imageCache.args);
  10004. args = null;
  10005. continue;
  10006. }
  10007. self.buildPaintImageXObject(resources, args[0], true,
  10008. operatorList, cacheKey, imageCache);
  10009. args = null;
  10010. continue;
  10011. case OPS.showText:
  10012. args[0] = self.handleText(args[0], stateManager.state);
  10013. break;
  10014. case OPS.showSpacedText:
  10015. var arr = args[0];
  10016. var combinedGlyphs = [];
  10017. var arrLength = arr.length;
  10018. for (i = 0; i < arrLength; ++i) {
  10019. var arrItem = arr[i];
  10020. if (isString(arrItem)) {
  10021. Array.prototype.push.apply(combinedGlyphs,
  10022. self.handleText(arrItem, stateManager.state));
  10023. } else if (isNum(arrItem)) {
  10024. combinedGlyphs.push(arrItem);
  10025. }
  10026. }
  10027. args[0] = combinedGlyphs;
  10028. fn = OPS.showText;
  10029. break;
  10030. case OPS.nextLineShowText:
  10031. operatorList.addOp(OPS.nextLine);
  10032. args[0] = self.handleText(args[0], stateManager.state);
  10033. fn = OPS.showText;
  10034. break;
  10035. case OPS.nextLineSetSpacingShowText:
  10036. operatorList.addOp(OPS.nextLine);
  10037. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10038. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10039. args[0] = self.handleText(args[0], stateManager.state);
  10040. fn = OPS.showText;
  10041. break;
  10042. case OPS.setTextRenderingMode:
  10043. stateManager.state.textRenderingMode = args[0];
  10044. break;
  10045. case OPS.setFillColorSpace:
  10046. stateManager.state.fillColorSpace =
  10047. ColorSpace.parse(args[0], xref, resources);
  10048. continue;
  10049. case OPS.setStrokeColorSpace:
  10050. stateManager.state.strokeColorSpace =
  10051. ColorSpace.parse(args[0], xref, resources);
  10052. continue;
  10053. case OPS.setFillColor:
  10054. cs = stateManager.state.fillColorSpace;
  10055. args = cs.getRgb(args, 0);
  10056. fn = OPS.setFillRGBColor;
  10057. break;
  10058. case OPS.setStrokeColor:
  10059. cs = stateManager.state.strokeColorSpace;
  10060. args = cs.getRgb(args, 0);
  10061. fn = OPS.setStrokeRGBColor;
  10062. break;
  10063. case OPS.setFillGray:
  10064. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10065. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10066. fn = OPS.setFillRGBColor;
  10067. break;
  10068. case OPS.setStrokeGray:
  10069. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10070. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10071. fn = OPS.setStrokeRGBColor;
  10072. break;
  10073. case OPS.setFillCMYKColor:
  10074. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10075. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10076. fn = OPS.setFillRGBColor;
  10077. break;
  10078. case OPS.setStrokeCMYKColor:
  10079. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10080. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10081. fn = OPS.setStrokeRGBColor;
  10082. break;
  10083. case OPS.setFillRGBColor:
  10084. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10085. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10086. break;
  10087. case OPS.setStrokeRGBColor:
  10088. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10089. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10090. break;
  10091. case OPS.setFillColorN:
  10092. cs = stateManager.state.fillColorSpace;
  10093. if (cs.name === 'Pattern') {
  10094. return self.handleColorN(operatorList, OPS.setFillColorN,
  10095. args, cs, patterns, resources, xref).then(function() {
  10096. next(resolve, reject);
  10097. }, reject);
  10098. }
  10099. args = cs.getRgb(args, 0);
  10100. fn = OPS.setFillRGBColor;
  10101. break;
  10102. case OPS.setStrokeColorN:
  10103. cs = stateManager.state.strokeColorSpace;
  10104. if (cs.name === 'Pattern') {
  10105. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10106. args, cs, patterns, resources, xref).then(function() {
  10107. next(resolve, reject);
  10108. }, reject);
  10109. }
  10110. args = cs.getRgb(args, 0);
  10111. fn = OPS.setStrokeRGBColor;
  10112. break;
  10113. case OPS.shadingFill:
  10114. var shadingRes = resources.get('Shading');
  10115. if (!shadingRes) {
  10116. error('No shading resource found');
  10117. }
  10118. var shading = shadingRes.get(args[0].name);
  10119. if (!shading) {
  10120. error('No shading object found');
  10121. }
  10122. var shadingFill = Pattern.parseShading(shading, null, xref,
  10123. resources);
  10124. var patternIR = shadingFill.getIR();
  10125. args = [patternIR];
  10126. fn = OPS.shadingFill;
  10127. break;
  10128. case OPS.setGState:
  10129. var dictName = args[0];
  10130. var extGState = resources.get('ExtGState');
  10131. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10132. break;
  10133. }
  10134. var gState = extGState.get(dictName.name);
  10135. return self.setGState(resources, gState, operatorList, xref,
  10136. stateManager).then(function() {
  10137. next(resolve, reject);
  10138. }, reject);
  10139. case OPS.moveTo:
  10140. case OPS.lineTo:
  10141. case OPS.curveTo:
  10142. case OPS.curveTo2:
  10143. case OPS.curveTo3:
  10144. case OPS.closePath:
  10145. self.buildPath(operatorList, fn, args);
  10146. continue;
  10147. case OPS.rectangle:
  10148. self.buildPath(operatorList, fn, args);
  10149. continue;
  10150. }
  10151. operatorList.addOp(fn, args);
  10152. }
  10153. if (stop) {
  10154. deferred.then(function () {
  10155. next(resolve, reject);
  10156. });
  10157. return;
  10158. }
  10159. // Some PDFs don't close all restores inside object/form.
  10160. // Closing those for them.
  10161. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10162. operatorList.addOp(OPS.restore, []);
  10163. }
  10164. resolve();
  10165. });
  10166. },
  10167. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10168. stateManager) {
  10169. stateManager = (stateManager || new StateManager(new TextState()));
  10170. var textContent = {
  10171. items: [],
  10172. styles: Object.create(null)
  10173. };
  10174. var bidiTexts = textContent.items;
  10175. var SPACE_FACTOR = 0.35;
  10176. var MULTI_SPACE_FACTOR = 1.5;
  10177. var self = this;
  10178. var xref = this.xref;
  10179. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10180. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10181. var xobjs = null;
  10182. var xobjsCache = {};
  10183. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10184. var textState;
  10185. function newTextChunk() {
  10186. var font = textState.font;
  10187. if (!(font.loadedName in textContent.styles)) {
  10188. textContent.styles[font.loadedName] = {
  10189. fontFamily: font.fallbackName,
  10190. ascent: font.ascent,
  10191. descent: font.descent,
  10192. vertical: font.vertical
  10193. };
  10194. }
  10195. return {
  10196. // |str| is initially an array which we push individual chars to, and
  10197. // then runBidi() overwrites it with the final string.
  10198. str: [],
  10199. dir: null,
  10200. width: 0,
  10201. height: 0,
  10202. transform: null,
  10203. fontName: font.loadedName
  10204. };
  10205. }
  10206. function runBidi(textChunk) {
  10207. var str = textChunk.str.join('');
  10208. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10209. textChunk.str = bidiResult.str;
  10210. textChunk.dir = bidiResult.dir;
  10211. return textChunk;
  10212. }
  10213. function handleSetFont(fontName, fontRef) {
  10214. return self.loadFont(fontName, fontRef, xref, resources).
  10215. then(function (translated) {
  10216. textState.font = translated.font;
  10217. textState.fontMatrix = translated.font.fontMatrix ||
  10218. FONT_IDENTITY_MATRIX;
  10219. });
  10220. }
  10221. function buildTextGeometry(chars, textChunk) {
  10222. var font = textState.font;
  10223. textChunk = textChunk || newTextChunk();
  10224. if (!textChunk.transform) {
  10225. // 9.4.4 Text Space Details
  10226. var tsm = [textState.fontSize * textState.textHScale, 0,
  10227. 0, textState.fontSize,
  10228. 0, textState.textRise];
  10229. var trm = textChunk.transform = Util.transform(textState.ctm,
  10230. Util.transform(textState.textMatrix, tsm));
  10231. if (!font.vertical) {
  10232. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10233. } else {
  10234. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10235. }
  10236. }
  10237. var width = 0;
  10238. var height = 0;
  10239. var glyphs = font.charsToGlyphs(chars);
  10240. var defaultVMetrics = font.defaultVMetrics;
  10241. for (var i = 0; i < glyphs.length; i++) {
  10242. var glyph = glyphs[i];
  10243. if (!glyph) { // Previous glyph was a space.
  10244. width += textState.wordSpacing * textState.textHScale;
  10245. continue;
  10246. }
  10247. var vMetricX = null;
  10248. var vMetricY = null;
  10249. var glyphWidth = null;
  10250. if (font.vertical) {
  10251. if (glyph.vmetric) {
  10252. glyphWidth = glyph.vmetric[0];
  10253. vMetricX = glyph.vmetric[1];
  10254. vMetricY = glyph.vmetric[2];
  10255. } else {
  10256. glyphWidth = glyph.width;
  10257. vMetricX = glyph.width * 0.5;
  10258. vMetricY = defaultVMetrics[2];
  10259. }
  10260. } else {
  10261. glyphWidth = glyph.width;
  10262. }
  10263. var glyphUnicode = glyph.unicode;
  10264. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10265. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10266. }
  10267. glyphUnicode = reverseIfRtl(glyphUnicode);
  10268. // The following will calculate the x and y of the individual glyphs.
  10269. // if (font.vertical) {
  10270. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10271. // textState.fontMatrix[0];
  10272. // tsm[5] -= vMetricY * textState.fontSize *
  10273. // textState.fontMatrix[0];
  10274. // }
  10275. // var trm = Util.transform(textState.textMatrix, tsm);
  10276. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10277. // var x = pt[0];
  10278. // var y = pt[1];
  10279. var tx = 0;
  10280. var ty = 0;
  10281. if (!font.vertical) {
  10282. var w0 = glyphWidth * textState.fontMatrix[0];
  10283. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10284. textState.textHScale;
  10285. width += tx;
  10286. } else {
  10287. var w1 = glyphWidth * textState.fontMatrix[0];
  10288. ty = w1 * textState.fontSize + textState.charSpacing;
  10289. height += ty;
  10290. }
  10291. textState.translateTextMatrix(tx, ty);
  10292. textChunk.str.push(glyphUnicode);
  10293. }
  10294. var a = textState.textLineMatrix[0];
  10295. var b = textState.textLineMatrix[1];
  10296. var scaleLineX = Math.sqrt(a * a + b * b);
  10297. a = textState.ctm[0];
  10298. b = textState.ctm[1];
  10299. var scaleCtmX = Math.sqrt(a * a + b * b);
  10300. if (!font.vertical) {
  10301. textChunk.width += width * scaleCtmX * scaleLineX;
  10302. } else {
  10303. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10304. }
  10305. return textChunk;
  10306. }
  10307. var timeSlotManager = new TimeSlotManager();
  10308. return new Promise(function next(resolve, reject) {
  10309. timeSlotManager.reset();
  10310. var stop, operation = {}, args = [];
  10311. while (!(stop = timeSlotManager.check())) {
  10312. // The arguments parsed by read() are not used beyond this loop, so
  10313. // we can reuse the same array on every iteration, thus avoiding
  10314. // unnecessary allocations.
  10315. args.length = 0;
  10316. operation.args = args;
  10317. if (!(preprocessor.read(operation))) {
  10318. break;
  10319. }
  10320. textState = stateManager.state;
  10321. var fn = operation.fn;
  10322. args = operation.args;
  10323. switch (fn | 0) {
  10324. case OPS.setFont:
  10325. textState.fontSize = args[1];
  10326. return handleSetFont(args[0].name).then(function() {
  10327. next(resolve, reject);
  10328. }, reject);
  10329. case OPS.setTextRise:
  10330. textState.textRise = args[0];
  10331. break;
  10332. case OPS.setHScale:
  10333. textState.textHScale = args[0] / 100;
  10334. break;
  10335. case OPS.setLeading:
  10336. textState.leading = args[0];
  10337. break;
  10338. case OPS.moveText:
  10339. textState.translateTextLineMatrix(args[0], args[1]);
  10340. textState.textMatrix = textState.textLineMatrix.slice();
  10341. break;
  10342. case OPS.setLeadingMoveText:
  10343. textState.leading = -args[1];
  10344. textState.translateTextLineMatrix(args[0], args[1]);
  10345. textState.textMatrix = textState.textLineMatrix.slice();
  10346. break;
  10347. case OPS.nextLine:
  10348. textState.carriageReturn();
  10349. break;
  10350. case OPS.setTextMatrix:
  10351. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10352. args[4], args[5]);
  10353. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10354. args[4], args[5]);
  10355. break;
  10356. case OPS.setCharSpacing:
  10357. textState.charSpacing = args[0];
  10358. break;
  10359. case OPS.setWordSpacing:
  10360. textState.wordSpacing = args[0];
  10361. break;
  10362. case OPS.beginText:
  10363. textState.textMatrix = IDENTITY_MATRIX.slice();
  10364. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10365. break;
  10366. case OPS.showSpacedText:
  10367. var items = args[0];
  10368. var textChunk = newTextChunk();
  10369. var offset;
  10370. for (var j = 0, jj = items.length; j < jj; j++) {
  10371. if (typeof items[j] === 'string') {
  10372. buildTextGeometry(items[j], textChunk);
  10373. } else {
  10374. var val = items[j] / 1000;
  10375. if (!textState.font.vertical) {
  10376. offset = -val * textState.fontSize * textState.textHScale *
  10377. textState.textMatrix[0];
  10378. textState.translateTextMatrix(offset, 0);
  10379. textChunk.width += offset;
  10380. } else {
  10381. offset = -val * textState.fontSize *
  10382. textState.textMatrix[3];
  10383. textState.translateTextMatrix(0, offset);
  10384. textChunk.height += offset;
  10385. }
  10386. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10387. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10388. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10389. fakeSpaces = Math.round(fakeSpaces);
  10390. while (fakeSpaces--) {
  10391. textChunk.str.push(' ');
  10392. }
  10393. } else if (fakeSpaces > SPACE_FACTOR) {
  10394. textChunk.str.push(' ');
  10395. }
  10396. }
  10397. }
  10398. }
  10399. bidiTexts.push(runBidi(textChunk));
  10400. break;
  10401. case OPS.showText:
  10402. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10403. break;
  10404. case OPS.nextLineShowText:
  10405. textState.carriageReturn();
  10406. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10407. break;
  10408. case OPS.nextLineSetSpacingShowText:
  10409. textState.wordSpacing = args[0];
  10410. textState.charSpacing = args[1];
  10411. textState.carriageReturn();
  10412. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10413. break;
  10414. case OPS.paintXObject:
  10415. if (args[0].code) {
  10416. break;
  10417. }
  10418. if (!xobjs) {
  10419. xobjs = (resources.get('XObject') || Dict.empty);
  10420. }
  10421. var name = args[0].name;
  10422. if (xobjsCache.key === name) {
  10423. if (xobjsCache.texts) {
  10424. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10425. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10426. }
  10427. break;
  10428. }
  10429. var xobj = xobjs.get(name);
  10430. if (!xobj) {
  10431. break;
  10432. }
  10433. assert(isStream(xobj), 'XObject should be a stream');
  10434. var type = xobj.dict.get('Subtype');
  10435. assert(isName(type),
  10436. 'XObject should have a Name subtype');
  10437. if ('Form' !== type.name) {
  10438. xobjsCache.key = name;
  10439. xobjsCache.texts = null;
  10440. break;
  10441. }
  10442. stateManager.save();
  10443. var matrix = xobj.dict.get('Matrix');
  10444. if (isArray(matrix) && matrix.length === 6) {
  10445. stateManager.transform(matrix);
  10446. }
  10447. return self.getTextContent(xobj,
  10448. xobj.dict.get('Resources') || resources, stateManager).
  10449. then(function (formTextContent) {
  10450. Util.appendToArray(bidiTexts, formTextContent.items);
  10451. Util.extendObj(textContent.styles, formTextContent.styles);
  10452. stateManager.restore();
  10453. xobjsCache.key = name;
  10454. xobjsCache.texts = formTextContent;
  10455. next(resolve, reject);
  10456. }, reject);
  10457. case OPS.setGState:
  10458. var dictName = args[0];
  10459. var extGState = resources.get('ExtGState');
  10460. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10461. break;
  10462. }
  10463. var gsStateMap = extGState.get(dictName.name);
  10464. var gsStateFont = null;
  10465. for (var key in gsStateMap) {
  10466. if (key === 'Font') {
  10467. assert(!gsStateFont);
  10468. gsStateFont = gsStateMap[key];
  10469. }
  10470. }
  10471. if (gsStateFont) {
  10472. textState.fontSize = gsStateFont[1];
  10473. return handleSetFont(gsStateFont[0]).then(function() {
  10474. next(resolve, reject);
  10475. }, reject);
  10476. }
  10477. break;
  10478. } // switch
  10479. } // while
  10480. if (stop) {
  10481. deferred.then(function () {
  10482. next(resolve, reject);
  10483. });
  10484. return;
  10485. }
  10486. resolve(textContent);
  10487. });
  10488. },
  10489. extractDataStructures: function
  10490. partialEvaluatorExtractDataStructures(dict, baseDict,
  10491. xref, properties) {
  10492. // 9.10.2
  10493. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10494. if (toUnicode) {
  10495. properties.toUnicode = this.readToUnicode(toUnicode);
  10496. }
  10497. if (properties.composite) {
  10498. // CIDSystemInfo helps to match CID to glyphs
  10499. var cidSystemInfo = dict.get('CIDSystemInfo');
  10500. if (isDict(cidSystemInfo)) {
  10501. properties.cidSystemInfo = {
  10502. registry: cidSystemInfo.get('Registry'),
  10503. ordering: cidSystemInfo.get('Ordering'),
  10504. supplement: cidSystemInfo.get('Supplement')
  10505. };
  10506. }
  10507. var cidToGidMap = dict.get('CIDToGIDMap');
  10508. if (isStream(cidToGidMap)) {
  10509. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10510. }
  10511. }
  10512. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10513. // and depends on the font type. The base encoding and differences are
  10514. // read here, but the encoding that is actually used is chosen during
  10515. // glyph mapping in the font.
  10516. // TODO: Loading the built in encoding in the font would allow the
  10517. // differences to be merged in here not require us to hold on to it.
  10518. var differences = [];
  10519. var baseEncodingName = null;
  10520. var encoding;
  10521. if (dict.has('Encoding')) {
  10522. encoding = dict.get('Encoding');
  10523. if (isDict(encoding)) {
  10524. baseEncodingName = encoding.get('BaseEncoding');
  10525. baseEncodingName = (isName(baseEncodingName) ?
  10526. baseEncodingName.name : null);
  10527. // Load the differences between the base and original
  10528. if (encoding.has('Differences')) {
  10529. var diffEncoding = encoding.get('Differences');
  10530. var index = 0;
  10531. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10532. var data = diffEncoding[j];
  10533. if (isNum(data)) {
  10534. index = data;
  10535. } else {
  10536. differences[index++] = data.name;
  10537. }
  10538. }
  10539. }
  10540. } else if (isName(encoding)) {
  10541. baseEncodingName = encoding.name;
  10542. } else {
  10543. error('Encoding is not a Name nor a Dict');
  10544. }
  10545. // According to table 114 if the encoding is a named encoding it must be
  10546. // one of these predefined encodings.
  10547. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10548. baseEncodingName !== 'MacExpertEncoding' &&
  10549. baseEncodingName !== 'WinAnsiEncoding')) {
  10550. baseEncodingName = null;
  10551. }
  10552. }
  10553. if (baseEncodingName) {
  10554. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10555. } else {
  10556. encoding = (properties.type === 'TrueType' ?
  10557. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10558. // The Symbolic attribute can be misused for regular fonts
  10559. // Heuristic: we have to check if the font is a standard one also
  10560. if (!!(properties.flags & FontFlags.Symbolic)) {
  10561. encoding = Encodings.MacRomanEncoding;
  10562. if (!properties.file) {
  10563. if (/Symbol/i.test(properties.name)) {
  10564. encoding = Encodings.SymbolSetEncoding;
  10565. } else if (/Dingbats/i.test(properties.name)) {
  10566. encoding = Encodings.ZapfDingbatsEncoding;
  10567. }
  10568. }
  10569. }
  10570. properties.defaultEncoding = encoding;
  10571. }
  10572. properties.differences = differences;
  10573. properties.baseEncodingName = baseEncodingName;
  10574. properties.dict = dict;
  10575. },
  10576. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10577. var cmap, cmapObj = toUnicode;
  10578. if (isName(cmapObj)) {
  10579. cmap = CMapFactory.create(cmapObj,
  10580. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10581. return new ToUnicodeMap(cmap);
  10582. } else if (isStream(cmapObj)) {
  10583. cmap = CMapFactory.create(cmapObj,
  10584. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10585. // Convert UTF-16BE
  10586. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10587. // to iterate over all keys.
  10588. cmap.forEach(function(token, i) {
  10589. var str = [];
  10590. for (var k = 0; k < token.length; k += 2) {
  10591. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10592. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10593. str.push(w1);
  10594. continue;
  10595. }
  10596. k += 2;
  10597. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10598. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10599. }
  10600. cmap[i] = String.fromCharCode.apply(String, str);
  10601. });
  10602. return new ToUnicodeMap(cmap);
  10603. }
  10604. return null;
  10605. },
  10606. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10607. // Extract the encoding from the CIDToGIDMap
  10608. var glyphsData = cidToGidStream.getBytes();
  10609. // Set encoding 0 to later verify the font has an encoding
  10610. var result = [];
  10611. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10612. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10613. if (glyphID === 0) {
  10614. continue;
  10615. }
  10616. var code = j >> 1;
  10617. result[code] = glyphID;
  10618. }
  10619. return result;
  10620. },
  10621. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10622. descriptor,
  10623. properties) {
  10624. var glyphsWidths = [];
  10625. var defaultWidth = 0;
  10626. var glyphsVMetrics = [];
  10627. var defaultVMetrics;
  10628. var i, ii, j, jj, start, code, widths;
  10629. if (properties.composite) {
  10630. defaultWidth = dict.get('DW') || 1000;
  10631. widths = dict.get('W');
  10632. if (widths) {
  10633. for (i = 0, ii = widths.length; i < ii; i++) {
  10634. start = widths[i++];
  10635. code = xref.fetchIfRef(widths[i]);
  10636. if (isArray(code)) {
  10637. for (j = 0, jj = code.length; j < jj; j++) {
  10638. glyphsWidths[start++] = code[j];
  10639. }
  10640. } else {
  10641. var width = widths[++i];
  10642. for (j = start; j <= code; j++) {
  10643. glyphsWidths[j] = width;
  10644. }
  10645. }
  10646. }
  10647. }
  10648. if (properties.vertical) {
  10649. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10650. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10651. vmetrics = dict.get('W2');
  10652. if (vmetrics) {
  10653. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10654. start = vmetrics[i++];
  10655. code = xref.fetchIfRef(vmetrics[i]);
  10656. if (isArray(code)) {
  10657. for (j = 0, jj = code.length; j < jj; j++) {
  10658. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10659. }
  10660. } else {
  10661. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10662. for (j = start; j <= code; j++) {
  10663. glyphsVMetrics[j] = vmetric;
  10664. }
  10665. }
  10666. }
  10667. }
  10668. }
  10669. } else {
  10670. var firstChar = properties.firstChar;
  10671. widths = dict.get('Widths');
  10672. if (widths) {
  10673. j = firstChar;
  10674. for (i = 0, ii = widths.length; i < ii; i++) {
  10675. glyphsWidths[j++] = widths[i];
  10676. }
  10677. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10678. } else {
  10679. // Trying get the BaseFont metrics (see comment above).
  10680. var baseFontName = dict.get('BaseFont');
  10681. if (isName(baseFontName)) {
  10682. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10683. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10684. properties);
  10685. defaultWidth = metrics.defaultWidth;
  10686. }
  10687. }
  10688. }
  10689. // Heuristic: detection of monospace font by checking all non-zero widths
  10690. var isMonospace = true;
  10691. var firstWidth = defaultWidth;
  10692. for (var glyph in glyphsWidths) {
  10693. var glyphWidth = glyphsWidths[glyph];
  10694. if (!glyphWidth) {
  10695. continue;
  10696. }
  10697. if (!firstWidth) {
  10698. firstWidth = glyphWidth;
  10699. continue;
  10700. }
  10701. if (firstWidth !== glyphWidth) {
  10702. isMonospace = false;
  10703. break;
  10704. }
  10705. }
  10706. if (isMonospace) {
  10707. properties.flags |= FontFlags.FixedPitch;
  10708. }
  10709. properties.defaultWidth = defaultWidth;
  10710. properties.widths = glyphsWidths;
  10711. properties.defaultVMetrics = defaultVMetrics;
  10712. properties.vmetrics = glyphsVMetrics;
  10713. },
  10714. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10715. // Simulating descriptor flags attribute
  10716. var fontNameWoStyle = baseFontName.split('-')[0];
  10717. return (fontNameWoStyle in serifFonts) ||
  10718. (fontNameWoStyle.search(/serif/gi) !== -1);
  10719. },
  10720. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10721. var defaultWidth = 0;
  10722. var widths = [];
  10723. var monospace = false;
  10724. var lookupName = (stdFontMap[name] || name);
  10725. if (!(lookupName in Metrics)) {
  10726. // Use default fonts for looking up font metrics if the passed
  10727. // font is not a base font
  10728. if (this.isSerifFont(name)) {
  10729. lookupName = 'Times-Roman';
  10730. } else {
  10731. lookupName = 'Helvetica';
  10732. }
  10733. }
  10734. var glyphWidths = Metrics[lookupName];
  10735. if (isNum(glyphWidths)) {
  10736. defaultWidth = glyphWidths;
  10737. monospace = true;
  10738. } else {
  10739. widths = glyphWidths;
  10740. }
  10741. return {
  10742. defaultWidth: defaultWidth,
  10743. monospace: monospace,
  10744. widths: widths
  10745. };
  10746. },
  10747. buildCharCodeToWidth:
  10748. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10749. properties) {
  10750. var widths = Object.create(null);
  10751. var differences = properties.differences;
  10752. var encoding = properties.defaultEncoding;
  10753. for (var charCode = 0; charCode < 256; charCode++) {
  10754. if (charCode in differences &&
  10755. widthsByGlyphName[differences[charCode]]) {
  10756. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10757. continue;
  10758. }
  10759. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10760. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10761. continue;
  10762. }
  10763. }
  10764. return widths;
  10765. },
  10766. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10767. var baseDict = dict;
  10768. var type = dict.get('Subtype');
  10769. assert(isName(type), 'invalid font Subtype');
  10770. var composite = false;
  10771. var uint8array;
  10772. if (type.name === 'Type0') {
  10773. // If font is a composite
  10774. // - get the descendant font
  10775. // - set the type according to the descendant font
  10776. // - get the FontDescriptor from the descendant font
  10777. var df = dict.get('DescendantFonts');
  10778. if (!df) {
  10779. error('Descendant fonts are not specified');
  10780. }
  10781. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10782. type = dict.get('Subtype');
  10783. assert(isName(type), 'invalid font Subtype');
  10784. composite = true;
  10785. }
  10786. var descriptor = dict.get('FontDescriptor');
  10787. if (descriptor) {
  10788. var hash = new MurmurHash3_64();
  10789. var encoding = baseDict.getRaw('Encoding');
  10790. if (isName(encoding)) {
  10791. hash.update(encoding.name);
  10792. } else if (isRef(encoding)) {
  10793. hash.update(encoding.num + '_' + encoding.gen);
  10794. }
  10795. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10796. if (isStream(toUnicode)) {
  10797. var stream = toUnicode.str || toUnicode;
  10798. uint8array = stream.buffer ?
  10799. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10800. new Uint8Array(stream.bytes.buffer,
  10801. stream.start, stream.end - stream.start);
  10802. hash.update(uint8array);
  10803. } else if (isName(toUnicode)) {
  10804. hash.update(toUnicode.name);
  10805. }
  10806. var widths = dict.get('Widths') || baseDict.get('Widths');
  10807. if (widths) {
  10808. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10809. hash.update(uint8array);
  10810. }
  10811. }
  10812. return {
  10813. descriptor: descriptor,
  10814. dict: dict,
  10815. baseDict: baseDict,
  10816. composite: composite,
  10817. type: type.name,
  10818. hash: hash ? hash.hexdigest() : ''
  10819. };
  10820. },
  10821. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10822. xref) {
  10823. var baseDict = preEvaluatedFont.baseDict;
  10824. var dict = preEvaluatedFont.dict;
  10825. var composite = preEvaluatedFont.composite;
  10826. var descriptor = preEvaluatedFont.descriptor;
  10827. var type = preEvaluatedFont.type;
  10828. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  10829. var properties;
  10830. if (!descriptor) {
  10831. if (type === 'Type3') {
  10832. // FontDescriptor is only required for Type3 fonts when the document
  10833. // is a tagged pdf. Create a barbebones one to get by.
  10834. descriptor = new Dict(null);
  10835. descriptor.set('FontName', Name.get(type));
  10836. } else {
  10837. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  10838. // FontDescriptor was not required.
  10839. // This case is here for compatibility.
  10840. var baseFontName = dict.get('BaseFont');
  10841. if (!isName(baseFontName)) {
  10842. error('Base font is not specified');
  10843. }
  10844. // Using base font name as a font name.
  10845. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  10846. var metrics = this.getBaseFontMetrics(baseFontName);
  10847. // Simulating descriptor flags attribute
  10848. var fontNameWoStyle = baseFontName.split('-')[0];
  10849. var flags =
  10850. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  10851. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  10852. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  10853. FontFlags.Nonsymbolic);
  10854. properties = {
  10855. type: type,
  10856. name: baseFontName,
  10857. widths: metrics.widths,
  10858. defaultWidth: metrics.defaultWidth,
  10859. flags: flags,
  10860. firstChar: 0,
  10861. lastChar: maxCharIndex
  10862. };
  10863. this.extractDataStructures(dict, dict, xref, properties);
  10864. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  10865. properties);
  10866. return new Font(baseFontName, null, properties);
  10867. }
  10868. }
  10869. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  10870. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  10871. // to ignore this rule when a variant of a standart font is used.
  10872. // TODO Fill the width array depending on which of the base font this is
  10873. // a variant.
  10874. var firstChar = (dict.get('FirstChar') || 0);
  10875. var lastChar = (dict.get('LastChar') || maxCharIndex);
  10876. var fontName = descriptor.get('FontName');
  10877. var baseFont = dict.get('BaseFont');
  10878. // Some bad PDFs have a string as the font name.
  10879. if (isString(fontName)) {
  10880. fontName = Name.get(fontName);
  10881. }
  10882. if (isString(baseFont)) {
  10883. baseFont = Name.get(baseFont);
  10884. }
  10885. if (type !== 'Type3') {
  10886. var fontNameStr = fontName && fontName.name;
  10887. var baseFontStr = baseFont && baseFont.name;
  10888. if (fontNameStr !== baseFontStr) {
  10889. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  10890. '" but should be the same as the Font\'s BaseFont "' +
  10891. baseFontStr + '"');
  10892. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  10893. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  10894. if (fontNameStr && baseFontStr &&
  10895. baseFontStr.indexOf(fontNameStr) === 0) {
  10896. fontName = baseFont;
  10897. }
  10898. }
  10899. }
  10900. fontName = (fontName || baseFont);
  10901. assert(isName(fontName), 'invalid font name');
  10902. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  10903. if (fontFile) {
  10904. if (fontFile.dict) {
  10905. var subtype = fontFile.dict.get('Subtype');
  10906. if (subtype) {
  10907. subtype = subtype.name;
  10908. }
  10909. var length1 = fontFile.dict.get('Length1');
  10910. var length2 = fontFile.dict.get('Length2');
  10911. }
  10912. }
  10913. properties = {
  10914. type: type,
  10915. name: fontName.name,
  10916. subtype: subtype,
  10917. file: fontFile,
  10918. length1: length1,
  10919. length2: length2,
  10920. loadedName: baseDict.loadedName,
  10921. composite: composite,
  10922. wideChars: composite,
  10923. fixedPitch: false,
  10924. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  10925. firstChar: firstChar || 0,
  10926. lastChar: (lastChar || maxCharIndex),
  10927. bbox: descriptor.get('FontBBox'),
  10928. ascent: descriptor.get('Ascent'),
  10929. descent: descriptor.get('Descent'),
  10930. xHeight: descriptor.get('XHeight'),
  10931. capHeight: descriptor.get('CapHeight'),
  10932. flags: descriptor.get('Flags'),
  10933. italicAngle: descriptor.get('ItalicAngle'),
  10934. coded: false
  10935. };
  10936. if (composite) {
  10937. var cidEncoding = baseDict.get('Encoding');
  10938. if (isName(cidEncoding)) {
  10939. properties.cidEncoding = cidEncoding.name;
  10940. }
  10941. properties.cMap = CMapFactory.create(cidEncoding,
  10942. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10943. properties.vertical = properties.cMap.vertical;
  10944. }
  10945. this.extractDataStructures(dict, baseDict, xref, properties);
  10946. this.extractWidths(dict, xref, descriptor, properties);
  10947. if (type === 'Type3') {
  10948. properties.isType3Font = true;
  10949. }
  10950. return new Font(fontName.name, fontFile, properties);
  10951. }
  10952. };
  10953. return PartialEvaluator;
  10954. })();
  10955. var TranslatedFont = (function TranslatedFontClosure() {
  10956. function TranslatedFont(loadedName, font, dict) {
  10957. this.loadedName = loadedName;
  10958. this.font = font;
  10959. this.dict = dict;
  10960. this.type3Loaded = null;
  10961. this.sent = false;
  10962. }
  10963. TranslatedFont.prototype = {
  10964. send: function (handler) {
  10965. if (this.sent) {
  10966. return;
  10967. }
  10968. var fontData = this.font.exportData();
  10969. handler.send('commonobj', [
  10970. this.loadedName,
  10971. 'Font',
  10972. fontData
  10973. ]);
  10974. this.sent = true;
  10975. },
  10976. loadType3Data: function (evaluator, resources, parentOperatorList) {
  10977. assert(this.font.isType3Font);
  10978. if (this.type3Loaded) {
  10979. return this.type3Loaded;
  10980. }
  10981. var translatedFont = this.font;
  10982. var loadCharProcsPromise = Promise.resolve();
  10983. var charProcs = this.dict.get('CharProcs').getAll();
  10984. var fontResources = this.dict.get('Resources') || resources;
  10985. var charProcKeys = Object.keys(charProcs);
  10986. var charProcOperatorList = {};
  10987. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  10988. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  10989. var glyphStream = charProcs[key];
  10990. var operatorList = new OperatorList();
  10991. return evaluator.getOperatorList(glyphStream, fontResources,
  10992. operatorList).then(function () {
  10993. charProcOperatorList[key] = operatorList.getIR();
  10994. // Add the dependencies to the parent operator list so they are
  10995. // resolved before sub operator list is executed synchronously.
  10996. parentOperatorList.addDependencies(operatorList.dependencies);
  10997. }, function (reason) {
  10998. warn('Type3 font resource \"' + key + '\" is not available');
  10999. var operatorList = new OperatorList();
  11000. charProcOperatorList[key] = operatorList.getIR();
  11001. });
  11002. }.bind(this, charProcKeys[i]));
  11003. }
  11004. this.type3Loaded = loadCharProcsPromise.then(function () {
  11005. translatedFont.charProcOperatorList = charProcOperatorList;
  11006. });
  11007. return this.type3Loaded;
  11008. }
  11009. };
  11010. return TranslatedFont;
  11011. })();
  11012. var OperatorList = (function OperatorListClosure() {
  11013. var CHUNK_SIZE = 1000;
  11014. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11015. function getTransfers(queue) {
  11016. var transfers = [];
  11017. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11018. for (var i = 0, ii = queue.length; i < ii; i++) {
  11019. switch (fnArray[i]) {
  11020. case OPS.paintInlineImageXObject:
  11021. case OPS.paintInlineImageXObjectGroup:
  11022. case OPS.paintImageMaskXObject:
  11023. var arg = argsArray[i][0]; // first param in imgData
  11024. if (!arg.cached) {
  11025. transfers.push(arg.data.buffer);
  11026. }
  11027. break;
  11028. }
  11029. }
  11030. return transfers;
  11031. }
  11032. function OperatorList(intent, messageHandler, pageIndex) {
  11033. this.messageHandler = messageHandler;
  11034. this.fnArray = [];
  11035. this.argsArray = [];
  11036. this.dependencies = {};
  11037. this.pageIndex = pageIndex;
  11038. this.intent = intent;
  11039. }
  11040. OperatorList.prototype = {
  11041. get length() {
  11042. return this.argsArray.length;
  11043. },
  11044. addOp: function(fn, args) {
  11045. this.fnArray.push(fn);
  11046. this.argsArray.push(args);
  11047. if (this.messageHandler) {
  11048. if (this.fnArray.length >= CHUNK_SIZE) {
  11049. this.flush();
  11050. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11051. (fn === OPS.restore || fn === OPS.endText)) {
  11052. // heuristic to flush on boundary of restore or endText
  11053. this.flush();
  11054. }
  11055. }
  11056. },
  11057. addDependency: function(dependency) {
  11058. if (dependency in this.dependencies) {
  11059. return;
  11060. }
  11061. this.dependencies[dependency] = true;
  11062. this.addOp(OPS.dependency, [dependency]);
  11063. },
  11064. addDependencies: function(dependencies) {
  11065. for (var key in dependencies) {
  11066. this.addDependency(key);
  11067. }
  11068. },
  11069. addOpList: function(opList) {
  11070. Util.extendObj(this.dependencies, opList.dependencies);
  11071. for (var i = 0, ii = opList.length; i < ii; i++) {
  11072. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11073. }
  11074. },
  11075. getIR: function() {
  11076. return {
  11077. fnArray: this.fnArray,
  11078. argsArray: this.argsArray,
  11079. length: this.length
  11080. };
  11081. },
  11082. flush: function(lastChunk) {
  11083. if (this.intent !== 'oplist') {
  11084. new QueueOptimizer().optimize(this);
  11085. }
  11086. var transfers = getTransfers(this);
  11087. this.messageHandler.send('RenderPageChunk', {
  11088. operatorList: {
  11089. fnArray: this.fnArray,
  11090. argsArray: this.argsArray,
  11091. lastChunk: lastChunk,
  11092. length: this.length
  11093. },
  11094. pageIndex: this.pageIndex,
  11095. intent: this.intent
  11096. }, transfers);
  11097. this.dependencies = {};
  11098. this.fnArray.length = 0;
  11099. this.argsArray.length = 0;
  11100. }
  11101. };
  11102. return OperatorList;
  11103. })();
  11104. var StateManager = (function StateManagerClosure() {
  11105. function StateManager(initialState) {
  11106. this.state = initialState;
  11107. this.stateStack = [];
  11108. }
  11109. StateManager.prototype = {
  11110. save: function () {
  11111. var old = this.state;
  11112. this.stateStack.push(this.state);
  11113. this.state = old.clone();
  11114. },
  11115. restore: function () {
  11116. var prev = this.stateStack.pop();
  11117. if (prev) {
  11118. this.state = prev;
  11119. }
  11120. },
  11121. transform: function (args) {
  11122. this.state.ctm = Util.transform(this.state.ctm, args);
  11123. }
  11124. };
  11125. return StateManager;
  11126. })();
  11127. var TextState = (function TextStateClosure() {
  11128. function TextState() {
  11129. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11130. this.fontSize = 0;
  11131. this.font = null;
  11132. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11133. this.textMatrix = IDENTITY_MATRIX.slice();
  11134. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11135. this.charSpacing = 0;
  11136. this.wordSpacing = 0;
  11137. this.leading = 0;
  11138. this.textHScale = 1;
  11139. this.textRise = 0;
  11140. }
  11141. TextState.prototype = {
  11142. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11143. var m = this.textMatrix;
  11144. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11145. },
  11146. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11147. var m = this.textLineMatrix;
  11148. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11149. },
  11150. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11151. var m = this.textMatrix;
  11152. m[4] = m[0] * x + m[2] * y + m[4];
  11153. m[5] = m[1] * x + m[3] * y + m[5];
  11154. },
  11155. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11156. var m = this.textLineMatrix;
  11157. m[4] = m[0] * x + m[2] * y + m[4];
  11158. m[5] = m[1] * x + m[3] * y + m[5];
  11159. },
  11160. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11161. // 9.4.4 Text Space Details
  11162. var tsm = [this.fontSize * this.textHScale, 0,
  11163. 0, this.fontSize,
  11164. 0, this.textRise];
  11165. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11166. },
  11167. carriageReturn: function TextState_carriageReturn() {
  11168. this.translateTextLineMatrix(0, -this.leading);
  11169. this.textMatrix = this.textLineMatrix.slice();
  11170. },
  11171. clone: function TextState_clone() {
  11172. var clone = Object.create(this);
  11173. clone.textMatrix = this.textMatrix.slice();
  11174. clone.textLineMatrix = this.textLineMatrix.slice();
  11175. clone.fontMatrix = this.fontMatrix.slice();
  11176. return clone;
  11177. }
  11178. };
  11179. return TextState;
  11180. })();
  11181. var EvalState = (function EvalStateClosure() {
  11182. function EvalState() {
  11183. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11184. this.font = null;
  11185. this.textRenderingMode = TextRenderingMode.FILL;
  11186. this.fillColorSpace = ColorSpace.singletons.gray;
  11187. this.strokeColorSpace = ColorSpace.singletons.gray;
  11188. }
  11189. EvalState.prototype = {
  11190. clone: function CanvasExtraState_clone() {
  11191. return Object.create(this);
  11192. },
  11193. };
  11194. return EvalState;
  11195. })();
  11196. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11197. // Specifies properties for each command
  11198. //
  11199. // If variableArgs === true: [0, `numArgs`] expected
  11200. // If variableArgs === false: exactly `numArgs` expected
  11201. var OP_MAP = {
  11202. // Graphic state
  11203. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11204. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11205. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11206. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11207. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11208. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11209. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11210. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11211. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11212. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11213. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11214. // Path
  11215. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11216. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11217. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11218. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11219. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11220. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11221. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11222. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11223. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11224. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11225. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11226. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11227. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11228. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11229. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11230. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11231. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11232. // Clipping
  11233. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11234. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11235. // Text
  11236. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11237. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11238. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11239. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11240. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11241. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11242. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11243. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11244. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11245. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11246. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11247. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11248. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11249. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11250. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11251. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11252. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11253. variableArgs: false },
  11254. // Type3 fonts
  11255. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11256. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11257. // Color
  11258. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11259. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11260. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11261. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11262. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11263. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11264. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11265. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11266. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11267. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11268. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11269. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11270. // Shading
  11271. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11272. // Images
  11273. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11274. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11275. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11276. // XObjects
  11277. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11278. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11279. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11280. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11281. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11282. variableArgs: false },
  11283. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11284. // Compatibility
  11285. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11286. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11287. // (reserved partial commands for the lexer)
  11288. BM: null,
  11289. BD: null,
  11290. 'true': null,
  11291. fa: null,
  11292. fal: null,
  11293. fals: null,
  11294. 'false': null,
  11295. nu: null,
  11296. nul: null,
  11297. 'null': null
  11298. };
  11299. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11300. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11301. // dictionary
  11302. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11303. this.stateManager = stateManager;
  11304. this.nonProcessedArgs = [];
  11305. }
  11306. EvaluatorPreprocessor.prototype = {
  11307. get savedStatesDepth() {
  11308. return this.stateManager.stateStack.length;
  11309. },
  11310. // |operation| is an object with two fields:
  11311. //
  11312. // - |fn| is an out param.
  11313. //
  11314. // - |args| is an inout param. On entry, it should have one of two values.
  11315. //
  11316. // - An empty array. This indicates that the caller is providing the
  11317. // array in which the args will be stored in. The caller should use
  11318. // this value if it can reuse a single array for each call to read().
  11319. //
  11320. // - |null|. This indicates that the caller needs this function to create
  11321. // the array in which any args are stored in. If there are zero args,
  11322. // this function will leave |operation.args| as |null| (thus avoiding
  11323. // allocations that would occur if we used an empty array to represent
  11324. // zero arguments). Otherwise, it will replace |null| with a new array
  11325. // containing the arguments. The caller should use this value if it
  11326. // cannot reuse an array for each call to read().
  11327. //
  11328. // These two modes are present because this function is very hot and so
  11329. // avoiding allocations where possible is worthwhile.
  11330. //
  11331. read: function EvaluatorPreprocessor_read(operation) {
  11332. var args = operation.args;
  11333. while (true) {
  11334. var obj = this.parser.getObj();
  11335. if (isCmd(obj)) {
  11336. var cmd = obj.cmd;
  11337. // Check that the command is valid
  11338. var opSpec = OP_MAP[cmd];
  11339. if (!opSpec) {
  11340. warn('Unknown command "' + cmd + '"');
  11341. continue;
  11342. }
  11343. var fn = opSpec.id;
  11344. var numArgs = opSpec.numArgs;
  11345. var argsLength = args !== null ? args.length : 0;
  11346. if (!opSpec.variableArgs) {
  11347. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11348. if (argsLength !== numArgs) {
  11349. var nonProcessedArgs = this.nonProcessedArgs;
  11350. while (argsLength > numArgs) {
  11351. nonProcessedArgs.push(args.shift());
  11352. argsLength--;
  11353. }
  11354. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11355. if (!args) {
  11356. args = [];
  11357. }
  11358. args.unshift(nonProcessedArgs.pop());
  11359. argsLength++;
  11360. }
  11361. }
  11362. if (argsLength < numArgs) {
  11363. // If we receive too few args, it's not possible to possible
  11364. // to execute the command, so skip the command
  11365. info('Command ' + fn + ': because expected ' +
  11366. numArgs + ' args, but received ' + argsLength +
  11367. ' args; skipping');
  11368. args = null;
  11369. continue;
  11370. }
  11371. } else if (argsLength > numArgs) {
  11372. info('Command ' + fn + ': expected [0,' + numArgs +
  11373. '] args, but received ' + argsLength + ' args');
  11374. }
  11375. // TODO figure out how to type-check vararg functions
  11376. this.preprocessCommand(fn, args);
  11377. operation.fn = fn;
  11378. operation.args = args;
  11379. return true;
  11380. } else {
  11381. if (isEOF(obj)) {
  11382. return false; // no more commands
  11383. }
  11384. // argument
  11385. if (obj !== null) {
  11386. if (!args) {
  11387. args = [];
  11388. }
  11389. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11390. assert(args.length <= 33, 'Too many arguments');
  11391. }
  11392. }
  11393. }
  11394. },
  11395. preprocessCommand:
  11396. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11397. switch (fn | 0) {
  11398. case OPS.save:
  11399. this.stateManager.save();
  11400. break;
  11401. case OPS.restore:
  11402. this.stateManager.restore();
  11403. break;
  11404. case OPS.transform:
  11405. this.stateManager.transform(args);
  11406. break;
  11407. }
  11408. }
  11409. };
  11410. return EvaluatorPreprocessor;
  11411. })();
  11412. var QueueOptimizer = (function QueueOptimizerClosure() {
  11413. function addState(parentState, pattern, fn) {
  11414. var state = parentState;
  11415. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11416. var item = pattern[i];
  11417. state = (state[item] || (state[item] = []));
  11418. }
  11419. state[pattern[pattern.length - 1]] = fn;
  11420. }
  11421. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11422. argsArray) {
  11423. // Handles special case of mainly LaTeX documents which use image masks to
  11424. // draw lines with the current fill style.
  11425. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11426. // have been found at iFirstSave.
  11427. var iFirstPIMXO = iFirstSave + 2;
  11428. for (var i = 0; i < count; i++) {
  11429. var arg = argsArray[iFirstPIMXO + 4 * i];
  11430. var imageMask = arg.length === 1 && arg[0];
  11431. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11432. (!imageMask.data.length ||
  11433. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11434. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11435. continue;
  11436. }
  11437. break;
  11438. }
  11439. return count - i;
  11440. }
  11441. var InitialState = [];
  11442. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11443. // sequences with one |paintInlineImageXObjectGroup| operation.
  11444. addState(InitialState,
  11445. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11446. function foundInlineImageGroup(context) {
  11447. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11448. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11449. var MAX_WIDTH = 1000;
  11450. var IMAGE_PADDING = 1;
  11451. var fnArray = context.fnArray, argsArray = context.argsArray;
  11452. var curr = context.iCurr;
  11453. var iFirstSave = curr - 3;
  11454. var iFirstTransform = curr - 2;
  11455. var iFirstPIIXO = curr - 1;
  11456. // Look for the quartets.
  11457. var i = iFirstSave + 4;
  11458. var ii = fnArray.length;
  11459. while (i + 3 < ii) {
  11460. if (fnArray[i] !== OPS.save ||
  11461. fnArray[i + 1] !== OPS.transform ||
  11462. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11463. fnArray[i + 3] !== OPS.restore) {
  11464. break; // ops don't match
  11465. }
  11466. i += 4;
  11467. }
  11468. // At this point, i is the index of the first op past the last valid
  11469. // quartet.
  11470. var count = Math.min((i - iFirstSave) / 4,
  11471. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11472. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11473. return i;
  11474. }
  11475. // assuming that heights of those image is too small (~1 pixel)
  11476. // packing as much as possible by lines
  11477. var maxX = 0;
  11478. var map = [], maxLineHeight = 0;
  11479. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11480. var q;
  11481. for (q = 0; q < count; q++) {
  11482. var transform = argsArray[iFirstTransform + (q << 2)];
  11483. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11484. if (currentX + img.width > MAX_WIDTH) {
  11485. // starting new line
  11486. maxX = Math.max(maxX, currentX);
  11487. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11488. currentX = 0;
  11489. maxLineHeight = 0;
  11490. }
  11491. map.push({
  11492. transform: transform,
  11493. x: currentX, y: currentY,
  11494. w: img.width, h: img.height
  11495. });
  11496. currentX += img.width + 2 * IMAGE_PADDING;
  11497. maxLineHeight = Math.max(maxLineHeight, img.height);
  11498. }
  11499. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11500. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11501. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11502. var imgRowSize = imgWidth << 2;
  11503. for (q = 0; q < count; q++) {
  11504. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11505. // Copy image by lines and extends pixels into padding.
  11506. var rowSize = map[q].w << 2;
  11507. var dataOffset = 0;
  11508. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11509. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11510. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11511. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11512. dataOffset += rowSize;
  11513. offset += imgRowSize;
  11514. }
  11515. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11516. while (offset >= 0) {
  11517. data[offset - 4] = data[offset];
  11518. data[offset - 3] = data[offset + 1];
  11519. data[offset - 2] = data[offset + 2];
  11520. data[offset - 1] = data[offset + 3];
  11521. data[offset + rowSize] = data[offset + rowSize - 4];
  11522. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11523. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11524. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11525. offset -= imgRowSize;
  11526. }
  11527. }
  11528. // Replace queue items.
  11529. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11530. argsArray.splice(iFirstSave, count * 4,
  11531. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11532. data: imgData }, map]);
  11533. return iFirstSave + 1;
  11534. });
  11535. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11536. // sequences with one |paintImageMaskXObjectGroup| or one
  11537. // |paintImageMaskXObjectRepeat| operation.
  11538. addState(InitialState,
  11539. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11540. function foundImageMaskGroup(context) {
  11541. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11542. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11543. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11544. var fnArray = context.fnArray, argsArray = context.argsArray;
  11545. var curr = context.iCurr;
  11546. var iFirstSave = curr - 3;
  11547. var iFirstTransform = curr - 2;
  11548. var iFirstPIMXO = curr - 1;
  11549. // Look for the quartets.
  11550. var i = iFirstSave + 4;
  11551. var ii = fnArray.length;
  11552. while (i + 3 < ii) {
  11553. if (fnArray[i] !== OPS.save ||
  11554. fnArray[i + 1] !== OPS.transform ||
  11555. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11556. fnArray[i + 3] !== OPS.restore) {
  11557. break; // ops don't match
  11558. }
  11559. i += 4;
  11560. }
  11561. // At this point, i is the index of the first op past the last valid
  11562. // quartet.
  11563. var count = (i - iFirstSave) / 4;
  11564. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11565. argsArray);
  11566. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11567. return i;
  11568. }
  11569. var q;
  11570. var isSameImage = false;
  11571. var iTransform, transformArgs;
  11572. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11573. if (argsArray[iFirstTransform][1] === 0 &&
  11574. argsArray[iFirstTransform][2] === 0) {
  11575. isSameImage = true;
  11576. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11577. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11578. iTransform = iFirstTransform + 4;
  11579. var iPIMXO = iFirstPIMXO + 4;
  11580. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11581. transformArgs = argsArray[iTransform];
  11582. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11583. transformArgs[0] !== firstTransformArg0 ||
  11584. transformArgs[1] !== 0 ||
  11585. transformArgs[2] !== 0 ||
  11586. transformArgs[3] !== firstTransformArg3) {
  11587. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11588. isSameImage = false;
  11589. } else {
  11590. count = q;
  11591. }
  11592. break; // different image or transform
  11593. }
  11594. }
  11595. }
  11596. if (isSameImage) {
  11597. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11598. var positions = new Float32Array(count * 2);
  11599. iTransform = iFirstTransform;
  11600. for (q = 0; q < count; q++, iTransform += 4) {
  11601. transformArgs = argsArray[iTransform];
  11602. positions[(q << 1)] = transformArgs[4];
  11603. positions[(q << 1) + 1] = transformArgs[5];
  11604. }
  11605. // Replace queue items.
  11606. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11607. argsArray.splice(iFirstSave, count * 4,
  11608. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11609. } else {
  11610. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11611. var images = [];
  11612. for (q = 0; q < count; q++) {
  11613. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11614. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11615. images.push({ data: maskParams.data, width: maskParams.width,
  11616. height: maskParams.height,
  11617. transform: transformArgs });
  11618. }
  11619. // Replace queue items.
  11620. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11621. argsArray.splice(iFirstSave, count * 4, [images]);
  11622. }
  11623. return iFirstSave + 1;
  11624. });
  11625. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11626. // with one paintImageXObjectRepeat operation, if the |transform| and
  11627. // |paintImageXObjectRepeat| ops are appropriate.
  11628. addState(InitialState,
  11629. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11630. function (context) {
  11631. var MIN_IMAGES_IN_BLOCK = 3;
  11632. var MAX_IMAGES_IN_BLOCK = 1000;
  11633. var fnArray = context.fnArray, argsArray = context.argsArray;
  11634. var curr = context.iCurr;
  11635. var iFirstSave = curr - 3;
  11636. var iFirstTransform = curr - 2;
  11637. var iFirstPIXO = curr - 1;
  11638. var iFirstRestore = curr;
  11639. if (argsArray[iFirstTransform][1] !== 0 ||
  11640. argsArray[iFirstTransform][2] !== 0) {
  11641. return iFirstRestore + 1; // transform has the wrong form
  11642. }
  11643. // Look for the quartets.
  11644. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11645. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11646. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11647. var i = iFirstSave + 4;
  11648. var ii = fnArray.length;
  11649. while (i + 3 < ii) {
  11650. if (fnArray[i] !== OPS.save ||
  11651. fnArray[i + 1] !== OPS.transform ||
  11652. fnArray[i + 2] !== OPS.paintImageXObject ||
  11653. fnArray[i + 3] !== OPS.restore) {
  11654. break; // ops don't match
  11655. }
  11656. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11657. argsArray[i + 1][1] !== 0 ||
  11658. argsArray[i + 1][2] !== 0 ||
  11659. argsArray[i + 1][3] !== firstTransformArg3) {
  11660. break; // transforms don't match
  11661. }
  11662. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11663. break; // images don't match
  11664. }
  11665. i += 4;
  11666. }
  11667. // At this point, i is the index of the first op past the last valid
  11668. // quartet.
  11669. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11670. if (count < MIN_IMAGES_IN_BLOCK) {
  11671. return i;
  11672. }
  11673. // Extract the (x,y) positions from all of the matching transforms.
  11674. var positions = new Float32Array(count * 2);
  11675. var iTransform = iFirstTransform;
  11676. for (var q = 0; q < count; q++, iTransform += 4) {
  11677. var transformArgs = argsArray[iTransform];
  11678. positions[(q << 1)] = transformArgs[4];
  11679. positions[(q << 1) + 1] = transformArgs[5];
  11680. }
  11681. // Replace queue items.
  11682. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11683. positions];
  11684. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11685. argsArray.splice(iFirstSave, count * 4, args);
  11686. return iFirstSave + 1;
  11687. });
  11688. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11689. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11690. // sequences, if the font for each one is the same.
  11691. addState(InitialState,
  11692. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11693. function (context) {
  11694. var MIN_CHARS_IN_BLOCK = 3;
  11695. var MAX_CHARS_IN_BLOCK = 1000;
  11696. var fnArray = context.fnArray, argsArray = context.argsArray;
  11697. var curr = context.iCurr;
  11698. var iFirstBeginText = curr - 4;
  11699. var iFirstSetFont = curr - 3;
  11700. var iFirstSetTextMatrix = curr - 2;
  11701. var iFirstShowText = curr - 1;
  11702. var iFirstEndText = curr;
  11703. // Look for the quintets.
  11704. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11705. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11706. var i = iFirstBeginText + 5;
  11707. var ii = fnArray.length;
  11708. while (i + 4 < ii) {
  11709. if (fnArray[i] !== OPS.beginText ||
  11710. fnArray[i + 1] !== OPS.setFont ||
  11711. fnArray[i + 2] !== OPS.setTextMatrix ||
  11712. fnArray[i + 3] !== OPS.showText ||
  11713. fnArray[i + 4] !== OPS.endText) {
  11714. break; // ops don't match
  11715. }
  11716. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11717. argsArray[i + 1][1] !== firstSetFontArg1) {
  11718. break; // fonts don't match
  11719. }
  11720. i += 5;
  11721. }
  11722. // At this point, i is the index of the first op past the last valid
  11723. // quintet.
  11724. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11725. if (count < MIN_CHARS_IN_BLOCK) {
  11726. return i;
  11727. }
  11728. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11729. // showText, endText), include that as well. (E.g. <something> might be
  11730. // |dependency|.)
  11731. var iFirst = iFirstBeginText;
  11732. if (iFirstBeginText >= 4 &&
  11733. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11734. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11735. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11736. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11737. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11738. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11739. count++;
  11740. iFirst -= 5;
  11741. }
  11742. // Remove (endText, beginText, setFont) trios.
  11743. var iEndText = iFirst + 4;
  11744. for (var q = 1; q < count; q++) {
  11745. fnArray.splice(iEndText, 3);
  11746. argsArray.splice(iEndText, 3);
  11747. iEndText += 2;
  11748. }
  11749. return iEndText + 1;
  11750. });
  11751. function QueueOptimizer() {}
  11752. QueueOptimizer.prototype = {
  11753. optimize: function QueueOptimizer_optimize(queue) {
  11754. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11755. var context = {
  11756. iCurr: 0,
  11757. fnArray: fnArray,
  11758. argsArray: argsArray
  11759. };
  11760. var state;
  11761. var i = 0, ii = fnArray.length;
  11762. while (i < ii) {
  11763. state = (state || InitialState)[fnArray[i]];
  11764. if (typeof state === 'function') { // we found some handler
  11765. context.iCurr = i;
  11766. // state() returns the index of the first non-matching op (if we
  11767. // didn't match) or the first op past the modified ops (if we did
  11768. // match and replace).
  11769. i = state(context);
  11770. state = undefined; // reset the state machine
  11771. ii = context.fnArray.length;
  11772. } else {
  11773. i++;
  11774. }
  11775. }
  11776. }
  11777. };
  11778. return QueueOptimizer;
  11779. })();
  11780. var BUILT_IN_CMAPS = [
  11781. // << Start unicode maps.
  11782. 'Adobe-GB1-UCS2',
  11783. 'Adobe-CNS1-UCS2',
  11784. 'Adobe-Japan1-UCS2',
  11785. 'Adobe-Korea1-UCS2',
  11786. // >> End unicode maps.
  11787. '78-EUC-H',
  11788. '78-EUC-V',
  11789. '78-H',
  11790. '78-RKSJ-H',
  11791. '78-RKSJ-V',
  11792. '78-V',
  11793. '78ms-RKSJ-H',
  11794. '78ms-RKSJ-V',
  11795. '83pv-RKSJ-H',
  11796. '90ms-RKSJ-H',
  11797. '90ms-RKSJ-V',
  11798. '90msp-RKSJ-H',
  11799. '90msp-RKSJ-V',
  11800. '90pv-RKSJ-H',
  11801. '90pv-RKSJ-V',
  11802. 'Add-H',
  11803. 'Add-RKSJ-H',
  11804. 'Add-RKSJ-V',
  11805. 'Add-V',
  11806. 'Adobe-CNS1-0',
  11807. 'Adobe-CNS1-1',
  11808. 'Adobe-CNS1-2',
  11809. 'Adobe-CNS1-3',
  11810. 'Adobe-CNS1-4',
  11811. 'Adobe-CNS1-5',
  11812. 'Adobe-CNS1-6',
  11813. 'Adobe-GB1-0',
  11814. 'Adobe-GB1-1',
  11815. 'Adobe-GB1-2',
  11816. 'Adobe-GB1-3',
  11817. 'Adobe-GB1-4',
  11818. 'Adobe-GB1-5',
  11819. 'Adobe-Japan1-0',
  11820. 'Adobe-Japan1-1',
  11821. 'Adobe-Japan1-2',
  11822. 'Adobe-Japan1-3',
  11823. 'Adobe-Japan1-4',
  11824. 'Adobe-Japan1-5',
  11825. 'Adobe-Japan1-6',
  11826. 'Adobe-Korea1-0',
  11827. 'Adobe-Korea1-1',
  11828. 'Adobe-Korea1-2',
  11829. 'B5-H',
  11830. 'B5-V',
  11831. 'B5pc-H',
  11832. 'B5pc-V',
  11833. 'CNS-EUC-H',
  11834. 'CNS-EUC-V',
  11835. 'CNS1-H',
  11836. 'CNS1-V',
  11837. 'CNS2-H',
  11838. 'CNS2-V',
  11839. 'ETHK-B5-H',
  11840. 'ETHK-B5-V',
  11841. 'ETen-B5-H',
  11842. 'ETen-B5-V',
  11843. 'ETenms-B5-H',
  11844. 'ETenms-B5-V',
  11845. 'EUC-H',
  11846. 'EUC-V',
  11847. 'Ext-H',
  11848. 'Ext-RKSJ-H',
  11849. 'Ext-RKSJ-V',
  11850. 'Ext-V',
  11851. 'GB-EUC-H',
  11852. 'GB-EUC-V',
  11853. 'GB-H',
  11854. 'GB-V',
  11855. 'GBK-EUC-H',
  11856. 'GBK-EUC-V',
  11857. 'GBK2K-H',
  11858. 'GBK2K-V',
  11859. 'GBKp-EUC-H',
  11860. 'GBKp-EUC-V',
  11861. 'GBT-EUC-H',
  11862. 'GBT-EUC-V',
  11863. 'GBT-H',
  11864. 'GBT-V',
  11865. 'GBTpc-EUC-H',
  11866. 'GBTpc-EUC-V',
  11867. 'GBpc-EUC-H',
  11868. 'GBpc-EUC-V',
  11869. 'H',
  11870. 'HKdla-B5-H',
  11871. 'HKdla-B5-V',
  11872. 'HKdlb-B5-H',
  11873. 'HKdlb-B5-V',
  11874. 'HKgccs-B5-H',
  11875. 'HKgccs-B5-V',
  11876. 'HKm314-B5-H',
  11877. 'HKm314-B5-V',
  11878. 'HKm471-B5-H',
  11879. 'HKm471-B5-V',
  11880. 'HKscs-B5-H',
  11881. 'HKscs-B5-V',
  11882. 'Hankaku',
  11883. 'Hiragana',
  11884. 'KSC-EUC-H',
  11885. 'KSC-EUC-V',
  11886. 'KSC-H',
  11887. 'KSC-Johab-H',
  11888. 'KSC-Johab-V',
  11889. 'KSC-V',
  11890. 'KSCms-UHC-H',
  11891. 'KSCms-UHC-HW-H',
  11892. 'KSCms-UHC-HW-V',
  11893. 'KSCms-UHC-V',
  11894. 'KSCpc-EUC-H',
  11895. 'KSCpc-EUC-V',
  11896. 'Katakana',
  11897. 'NWP-H',
  11898. 'NWP-V',
  11899. 'RKSJ-H',
  11900. 'RKSJ-V',
  11901. 'Roman',
  11902. 'UniCNS-UCS2-H',
  11903. 'UniCNS-UCS2-V',
  11904. 'UniCNS-UTF16-H',
  11905. 'UniCNS-UTF16-V',
  11906. 'UniCNS-UTF32-H',
  11907. 'UniCNS-UTF32-V',
  11908. 'UniCNS-UTF8-H',
  11909. 'UniCNS-UTF8-V',
  11910. 'UniGB-UCS2-H',
  11911. 'UniGB-UCS2-V',
  11912. 'UniGB-UTF16-H',
  11913. 'UniGB-UTF16-V',
  11914. 'UniGB-UTF32-H',
  11915. 'UniGB-UTF32-V',
  11916. 'UniGB-UTF8-H',
  11917. 'UniGB-UTF8-V',
  11918. 'UniJIS-UCS2-H',
  11919. 'UniJIS-UCS2-HW-H',
  11920. 'UniJIS-UCS2-HW-V',
  11921. 'UniJIS-UCS2-V',
  11922. 'UniJIS-UTF16-H',
  11923. 'UniJIS-UTF16-V',
  11924. 'UniJIS-UTF32-H',
  11925. 'UniJIS-UTF32-V',
  11926. 'UniJIS-UTF8-H',
  11927. 'UniJIS-UTF8-V',
  11928. 'UniJIS2004-UTF16-H',
  11929. 'UniJIS2004-UTF16-V',
  11930. 'UniJIS2004-UTF32-H',
  11931. 'UniJIS2004-UTF32-V',
  11932. 'UniJIS2004-UTF8-H',
  11933. 'UniJIS2004-UTF8-V',
  11934. 'UniJISPro-UCS2-HW-V',
  11935. 'UniJISPro-UCS2-V',
  11936. 'UniJISPro-UTF8-V',
  11937. 'UniJISX0213-UTF32-H',
  11938. 'UniJISX0213-UTF32-V',
  11939. 'UniJISX02132004-UTF32-H',
  11940. 'UniJISX02132004-UTF32-V',
  11941. 'UniKS-UCS2-H',
  11942. 'UniKS-UCS2-V',
  11943. 'UniKS-UTF16-H',
  11944. 'UniKS-UTF16-V',
  11945. 'UniKS-UTF32-H',
  11946. 'UniKS-UTF32-V',
  11947. 'UniKS-UTF8-H',
  11948. 'UniKS-UTF8-V',
  11949. 'V',
  11950. 'WP-Symbol'];
  11951. // CMap, not to be confused with TrueType's cmap.
  11952. var CMap = (function CMapClosure() {
  11953. function CMap(builtInCMap) {
  11954. // Codespace ranges are stored as follows:
  11955. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  11956. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  11957. this.codespaceRanges = [[], [], [], []];
  11958. this.numCodespaceRanges = 0;
  11959. // Map entries have one of two forms.
  11960. // - cid chars are 16-bit unsigned integers, stored as integers.
  11961. // - bf chars are variable-length byte sequences, stored as strings, with
  11962. // one byte per character.
  11963. this._map = [];
  11964. this.vertical = false;
  11965. this.useCMap = null;
  11966. this.builtInCMap = builtInCMap;
  11967. }
  11968. CMap.prototype = {
  11969. addCodespaceRange: function(n, low, high) {
  11970. this.codespaceRanges[n - 1].push(low, high);
  11971. this.numCodespaceRanges++;
  11972. },
  11973. mapCidRange: function(low, high, dstLow) {
  11974. while (low <= high) {
  11975. this._map[low++] = dstLow++;
  11976. }
  11977. },
  11978. mapBfRange: function(low, high, dstLow) {
  11979. var lastByte = dstLow.length - 1;
  11980. while (low <= high) {
  11981. this._map[low++] = dstLow;
  11982. // Only the last byte has to be incremented.
  11983. dstLow = dstLow.substr(0, lastByte) +
  11984. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  11985. }
  11986. },
  11987. mapBfRangeToArray: function(low, high, array) {
  11988. var i = 0, ii = array.length;
  11989. while (low <= high && i < ii) {
  11990. this._map[low] = array[i++];
  11991. ++low;
  11992. }
  11993. },
  11994. // This is used for both bf and cid chars.
  11995. mapOne: function(src, dst) {
  11996. this._map[src] = dst;
  11997. },
  11998. lookup: function(code) {
  11999. return this._map[code];
  12000. },
  12001. contains: function(code) {
  12002. return this._map[code] !== undefined;
  12003. },
  12004. forEach: function(callback) {
  12005. // Most maps have fewer than 65536 entries, and for those we use normal
  12006. // array iteration. But really sparse tables are possible -- e.g. with
  12007. // indices in the *billions*. For such tables we use for..in, which isn't
  12008. // ideal because it stringifies the indices for all present elements, but
  12009. // it does avoid iterating over every undefined entry.
  12010. var map = this._map;
  12011. var length = map.length;
  12012. var i;
  12013. if (length <= 0x10000) {
  12014. for (i = 0; i < length; i++) {
  12015. if (map[i] !== undefined) {
  12016. callback(i, map[i]);
  12017. }
  12018. }
  12019. } else {
  12020. for (i in this._map) {
  12021. callback(i, map[i]);
  12022. }
  12023. }
  12024. },
  12025. charCodeOf: function(value) {
  12026. return this._map.indexOf(value);
  12027. },
  12028. getMap: function() {
  12029. return this._map;
  12030. },
  12031. readCharCode: function(str, offset, out) {
  12032. var c = 0;
  12033. var codespaceRanges = this.codespaceRanges;
  12034. var codespaceRangesLen = this.codespaceRanges.length;
  12035. // 9.7.6.2 CMap Mapping
  12036. // The code length is at most 4.
  12037. for (var n = 0; n < codespaceRangesLen; n++) {
  12038. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12039. // Check each codespace range to see if it falls within.
  12040. var codespaceRange = codespaceRanges[n];
  12041. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12042. var low = codespaceRange[k++];
  12043. var high = codespaceRange[k++];
  12044. if (c >= low && c <= high) {
  12045. out.charcode = c;
  12046. out.length = n + 1;
  12047. return;
  12048. }
  12049. }
  12050. }
  12051. out.charcode = 0;
  12052. out.length = 1;
  12053. }
  12054. };
  12055. return CMap;
  12056. })();
  12057. // A special case of CMap, where the _map array implicitly has a length of
  12058. // 65535 and each element is equal to its index.
  12059. var IdentityCMap = (function IdentityCMapClosure() {
  12060. function IdentityCMap(vertical, n) {
  12061. CMap.call(this);
  12062. this.vertical = vertical;
  12063. this.addCodespaceRange(n, 0, 0xffff);
  12064. }
  12065. Util.inherit(IdentityCMap, CMap, {});
  12066. IdentityCMap.prototype = {
  12067. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12068. mapCidRange: function(low, high, dstLow) {
  12069. error('should not call mapCidRange');
  12070. },
  12071. mapBfRange: function(low, high, dstLow) {
  12072. error('should not call mapBfRange');
  12073. },
  12074. mapBfRangeToArray: function(low, high, array) {
  12075. error('should not call mapBfRangeToArray');
  12076. },
  12077. mapOne: function(src, dst) {
  12078. error('should not call mapCidOne');
  12079. },
  12080. lookup: function(code) {
  12081. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12082. },
  12083. contains: function(code) {
  12084. return isInt(code) && code <= 0xffff;
  12085. },
  12086. forEach: function(callback) {
  12087. for (var i = 0; i <= 0xffff; i++) {
  12088. callback(i, i);
  12089. }
  12090. },
  12091. charCodeOf: function(value) {
  12092. return (isInt(value) && value <= 0xffff) ? value : -1;
  12093. },
  12094. getMap: function() {
  12095. // Sometimes identity maps must be instantiated, but it's rare.
  12096. var map = new Array(0x10000);
  12097. for (var i = 0; i <= 0xffff; i++) {
  12098. map[i] = i;
  12099. }
  12100. return map;
  12101. },
  12102. readCharCode: CMap.prototype.readCharCode
  12103. };
  12104. return IdentityCMap;
  12105. })();
  12106. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12107. function fetchBinaryData(url) {
  12108. var nonBinaryRequest = PDFJS.disableWorker;
  12109. var request = new XMLHttpRequest();
  12110. request.open('GET', url, false);
  12111. if (!nonBinaryRequest) {
  12112. try {
  12113. request.responseType = 'arraybuffer';
  12114. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12115. } catch (e) {
  12116. nonBinaryRequest = true;
  12117. }
  12118. }
  12119. if (nonBinaryRequest && request.overrideMimeType) {
  12120. request.overrideMimeType('text/plain; charset=x-user-defined');
  12121. }
  12122. request.send(null);
  12123. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12124. error('Unable to get binary cMap at: ' + url);
  12125. }
  12126. if (nonBinaryRequest) {
  12127. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12128. return ch.charCodeAt(0) & 255;
  12129. });
  12130. return new Uint8Array(data);
  12131. }
  12132. return new Uint8Array(request.response);
  12133. }
  12134. function hexToInt(a, size) {
  12135. var n = 0;
  12136. for (var i = 0; i <= size; i++) {
  12137. n = (n << 8) | a[i];
  12138. }
  12139. return n >>> 0;
  12140. }
  12141. function hexToStr(a, size) {
  12142. // This code is hot. Special-case some common values to avoid creating an
  12143. // object with subarray().
  12144. if (size === 1) {
  12145. return String.fromCharCode(a[0], a[1]);
  12146. }
  12147. if (size === 3) {
  12148. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12149. }
  12150. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12151. }
  12152. function addHex(a, b, size) {
  12153. var c = 0;
  12154. for (var i = size; i >= 0; i--) {
  12155. c += a[i] + b[i];
  12156. a[i] = c & 255;
  12157. c >>= 8;
  12158. }
  12159. }
  12160. function incHex(a, size) {
  12161. var c = 1;
  12162. for (var i = size; i >= 0 && c > 0; i--) {
  12163. c += a[i];
  12164. a[i] = c & 255;
  12165. c >>= 8;
  12166. }
  12167. }
  12168. var MAX_NUM_SIZE = 16;
  12169. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12170. function BinaryCMapStream(data) {
  12171. this.buffer = data;
  12172. this.pos = 0;
  12173. this.end = data.length;
  12174. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12175. }
  12176. BinaryCMapStream.prototype = {
  12177. readByte: function () {
  12178. if (this.pos >= this.end) {
  12179. return -1;
  12180. }
  12181. return this.buffer[this.pos++];
  12182. },
  12183. readNumber: function () {
  12184. var n = 0;
  12185. var last;
  12186. do {
  12187. var b = this.readByte();
  12188. if (b < 0) {
  12189. error('unexpected EOF in bcmap');
  12190. }
  12191. last = !(b & 0x80);
  12192. n = (n << 7) | (b & 0x7F);
  12193. } while (!last);
  12194. return n;
  12195. },
  12196. readSigned: function () {
  12197. var n = this.readNumber();
  12198. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12199. },
  12200. readHex: function (num, size) {
  12201. num.set(this.buffer.subarray(this.pos,
  12202. this.pos + size + 1));
  12203. this.pos += size + 1;
  12204. },
  12205. readHexNumber: function (num, size) {
  12206. var last;
  12207. var stack = this.tmpBuf, sp = 0;
  12208. do {
  12209. var b = this.readByte();
  12210. if (b < 0) {
  12211. error('unexpected EOF in bcmap');
  12212. }
  12213. last = !(b & 0x80);
  12214. stack[sp++] = b & 0x7F;
  12215. } while (!last);
  12216. var i = size, buffer = 0, bufferSize = 0;
  12217. while (i >= 0) {
  12218. while (bufferSize < 8 && stack.length > 0) {
  12219. buffer = (stack[--sp] << bufferSize) | buffer;
  12220. bufferSize += 7;
  12221. }
  12222. num[i] = buffer & 255;
  12223. i--;
  12224. buffer >>= 8;
  12225. bufferSize -= 8;
  12226. }
  12227. },
  12228. readHexSigned: function (num, size) {
  12229. this.readHexNumber(num, size);
  12230. var sign = num[size] & 1 ? 255 : 0;
  12231. var c = 0;
  12232. for (var i = 0; i <= size; i++) {
  12233. c = ((c & 1) << 8) | num[i];
  12234. num[i] = (c >> 1) ^ sign;
  12235. }
  12236. },
  12237. readString: function () {
  12238. var len = this.readNumber();
  12239. var s = '';
  12240. for (var i = 0; i < len; i++) {
  12241. s += String.fromCharCode(this.readNumber());
  12242. }
  12243. return s;
  12244. }
  12245. };
  12246. function processBinaryCMap(url, cMap, extend) {
  12247. var data = fetchBinaryData(url);
  12248. var stream = new BinaryCMapStream(data);
  12249. var header = stream.readByte();
  12250. cMap.vertical = !!(header & 1);
  12251. var useCMap = null;
  12252. var start = new Uint8Array(MAX_NUM_SIZE);
  12253. var end = new Uint8Array(MAX_NUM_SIZE);
  12254. var char = new Uint8Array(MAX_NUM_SIZE);
  12255. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12256. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12257. var code;
  12258. var b;
  12259. while ((b = stream.readByte()) >= 0) {
  12260. var type = b >> 5;
  12261. if (type === 7) { // metadata, e.g. comment or usecmap
  12262. switch (b & 0x1F) {
  12263. case 0:
  12264. stream.readString(); // skipping comment
  12265. break;
  12266. case 1:
  12267. useCMap = stream.readString();
  12268. break;
  12269. }
  12270. continue;
  12271. }
  12272. var sequence = !!(b & 0x10);
  12273. var dataSize = b & 15;
  12274. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12275. var ucs2DataSize = 1;
  12276. var subitemsCount = stream.readNumber();
  12277. var i;
  12278. switch (type) {
  12279. case 0: // codespacerange
  12280. stream.readHex(start, dataSize);
  12281. stream.readHexNumber(end, dataSize);
  12282. addHex(end, start, dataSize);
  12283. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12284. hexToInt(end, dataSize));
  12285. for (i = 1; i < subitemsCount; i++) {
  12286. incHex(end, dataSize);
  12287. stream.readHexNumber(start, dataSize);
  12288. addHex(start, end, dataSize);
  12289. stream.readHexNumber(end, dataSize);
  12290. addHex(end, start, dataSize);
  12291. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12292. hexToInt(end, dataSize));
  12293. }
  12294. break;
  12295. case 1: // notdefrange
  12296. stream.readHex(start, dataSize);
  12297. stream.readHexNumber(end, dataSize);
  12298. addHex(end, start, dataSize);
  12299. code = stream.readNumber();
  12300. // undefined range, skipping
  12301. for (i = 1; i < subitemsCount; i++) {
  12302. incHex(end, dataSize);
  12303. stream.readHexNumber(start, dataSize);
  12304. addHex(start, end, dataSize);
  12305. stream.readHexNumber(end, dataSize);
  12306. addHex(end, start, dataSize);
  12307. code = stream.readNumber();
  12308. // nop
  12309. }
  12310. break;
  12311. case 2: // cidchar
  12312. stream.readHex(char, dataSize);
  12313. code = stream.readNumber();
  12314. cMap.mapOne(hexToInt(char, dataSize), code);
  12315. for (i = 1; i < subitemsCount; i++) {
  12316. incHex(char, dataSize);
  12317. if (!sequence) {
  12318. stream.readHexNumber(tmp, dataSize);
  12319. addHex(char, tmp, dataSize);
  12320. }
  12321. code = stream.readSigned() + (code + 1);
  12322. cMap.mapOne(hexToInt(char, dataSize), code);
  12323. }
  12324. break;
  12325. case 3: // cidrange
  12326. stream.readHex(start, dataSize);
  12327. stream.readHexNumber(end, dataSize);
  12328. addHex(end, start, dataSize);
  12329. code = stream.readNumber();
  12330. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12331. code);
  12332. for (i = 1; i < subitemsCount; i++) {
  12333. incHex(end, dataSize);
  12334. if (!sequence) {
  12335. stream.readHexNumber(start, dataSize);
  12336. addHex(start, end, dataSize);
  12337. } else {
  12338. start.set(end);
  12339. }
  12340. stream.readHexNumber(end, dataSize);
  12341. addHex(end, start, dataSize);
  12342. code = stream.readNumber();
  12343. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12344. code);
  12345. }
  12346. break;
  12347. case 4: // bfchar
  12348. stream.readHex(char, ucs2DataSize);
  12349. stream.readHex(charCode, dataSize);
  12350. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12351. hexToStr(charCode, dataSize));
  12352. for (i = 1; i < subitemsCount; i++) {
  12353. incHex(char, ucs2DataSize);
  12354. if (!sequence) {
  12355. stream.readHexNumber(tmp, ucs2DataSize);
  12356. addHex(char, tmp, ucs2DataSize);
  12357. }
  12358. incHex(charCode, dataSize);
  12359. stream.readHexSigned(tmp, dataSize);
  12360. addHex(charCode, tmp, dataSize);
  12361. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12362. hexToStr(charCode, dataSize));
  12363. }
  12364. break;
  12365. case 5: // bfrange
  12366. stream.readHex(start, ucs2DataSize);
  12367. stream.readHexNumber(end, ucs2DataSize);
  12368. addHex(end, start, ucs2DataSize);
  12369. stream.readHex(charCode, dataSize);
  12370. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12371. hexToInt(end, ucs2DataSize),
  12372. hexToStr(charCode, dataSize));
  12373. for (i = 1; i < subitemsCount; i++) {
  12374. incHex(end, ucs2DataSize);
  12375. if (!sequence) {
  12376. stream.readHexNumber(start, ucs2DataSize);
  12377. addHex(start, end, ucs2DataSize);
  12378. } else {
  12379. start.set(end);
  12380. }
  12381. stream.readHexNumber(end, ucs2DataSize);
  12382. addHex(end, start, ucs2DataSize);
  12383. stream.readHex(charCode, dataSize);
  12384. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12385. hexToInt(end, ucs2DataSize),
  12386. hexToStr(charCode, dataSize));
  12387. }
  12388. break;
  12389. default:
  12390. error('Unknown type: ' + type);
  12391. break;
  12392. }
  12393. }
  12394. if (useCMap) {
  12395. extend(useCMap);
  12396. }
  12397. return cMap;
  12398. }
  12399. function BinaryCMapReader() {}
  12400. BinaryCMapReader.prototype = {
  12401. read: processBinaryCMap
  12402. };
  12403. return BinaryCMapReader;
  12404. })();
  12405. var CMapFactory = (function CMapFactoryClosure() {
  12406. function strToInt(str) {
  12407. var a = 0;
  12408. for (var i = 0; i < str.length; i++) {
  12409. a = (a << 8) | str.charCodeAt(i);
  12410. }
  12411. return a >>> 0;
  12412. }
  12413. function expectString(obj) {
  12414. if (!isString(obj)) {
  12415. error('Malformed CMap: expected string.');
  12416. }
  12417. }
  12418. function expectInt(obj) {
  12419. if (!isInt(obj)) {
  12420. error('Malformed CMap: expected int.');
  12421. }
  12422. }
  12423. function parseBfChar(cMap, lexer) {
  12424. while (true) {
  12425. var obj = lexer.getObj();
  12426. if (isEOF(obj)) {
  12427. break;
  12428. }
  12429. if (isCmd(obj, 'endbfchar')) {
  12430. return;
  12431. }
  12432. expectString(obj);
  12433. var src = strToInt(obj);
  12434. obj = lexer.getObj();
  12435. // TODO are /dstName used?
  12436. expectString(obj);
  12437. var dst = obj;
  12438. cMap.mapOne(src, dst);
  12439. }
  12440. }
  12441. function parseBfRange(cMap, lexer) {
  12442. while (true) {
  12443. var obj = lexer.getObj();
  12444. if (isEOF(obj)) {
  12445. break;
  12446. }
  12447. if (isCmd(obj, 'endbfrange')) {
  12448. return;
  12449. }
  12450. expectString(obj);
  12451. var low = strToInt(obj);
  12452. obj = lexer.getObj();
  12453. expectString(obj);
  12454. var high = strToInt(obj);
  12455. obj = lexer.getObj();
  12456. if (isInt(obj) || isString(obj)) {
  12457. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12458. cMap.mapBfRange(low, high, dstLow);
  12459. } else if (isCmd(obj, '[')) {
  12460. obj = lexer.getObj();
  12461. var array = [];
  12462. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12463. array.push(obj);
  12464. obj = lexer.getObj();
  12465. }
  12466. cMap.mapBfRangeToArray(low, high, array);
  12467. } else {
  12468. break;
  12469. }
  12470. }
  12471. error('Invalid bf range.');
  12472. }
  12473. function parseCidChar(cMap, lexer) {
  12474. while (true) {
  12475. var obj = lexer.getObj();
  12476. if (isEOF(obj)) {
  12477. break;
  12478. }
  12479. if (isCmd(obj, 'endcidchar')) {
  12480. return;
  12481. }
  12482. expectString(obj);
  12483. var src = strToInt(obj);
  12484. obj = lexer.getObj();
  12485. expectInt(obj);
  12486. var dst = obj;
  12487. cMap.mapOne(src, dst);
  12488. }
  12489. }
  12490. function parseCidRange(cMap, lexer) {
  12491. while (true) {
  12492. var obj = lexer.getObj();
  12493. if (isEOF(obj)) {
  12494. break;
  12495. }
  12496. if (isCmd(obj, 'endcidrange')) {
  12497. return;
  12498. }
  12499. expectString(obj);
  12500. var low = strToInt(obj);
  12501. obj = lexer.getObj();
  12502. expectString(obj);
  12503. var high = strToInt(obj);
  12504. obj = lexer.getObj();
  12505. expectInt(obj);
  12506. var dstLow = obj;
  12507. cMap.mapCidRange(low, high, dstLow);
  12508. }
  12509. }
  12510. function parseCodespaceRange(cMap, lexer) {
  12511. while (true) {
  12512. var obj = lexer.getObj();
  12513. if (isEOF(obj)) {
  12514. break;
  12515. }
  12516. if (isCmd(obj, 'endcodespacerange')) {
  12517. return;
  12518. }
  12519. if (!isString(obj)) {
  12520. break;
  12521. }
  12522. var low = strToInt(obj);
  12523. obj = lexer.getObj();
  12524. if (!isString(obj)) {
  12525. break;
  12526. }
  12527. var high = strToInt(obj);
  12528. cMap.addCodespaceRange(obj.length, low, high);
  12529. }
  12530. error('Invalid codespace range.');
  12531. }
  12532. function parseWMode(cMap, lexer) {
  12533. var obj = lexer.getObj();
  12534. if (isInt(obj)) {
  12535. cMap.vertical = !!obj;
  12536. }
  12537. }
  12538. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12539. var previous;
  12540. var embededUseCMap;
  12541. objLoop: while (true) {
  12542. var obj = lexer.getObj();
  12543. if (isEOF(obj)) {
  12544. break;
  12545. } else if (isName(obj)) {
  12546. if (obj.name === 'WMode') {
  12547. parseWMode(cMap, lexer);
  12548. }
  12549. previous = obj;
  12550. } else if (isCmd(obj)) {
  12551. switch (obj.cmd) {
  12552. case 'endcmap':
  12553. break objLoop;
  12554. case 'usecmap':
  12555. if (isName(previous)) {
  12556. embededUseCMap = previous.name;
  12557. }
  12558. break;
  12559. case 'begincodespacerange':
  12560. parseCodespaceRange(cMap, lexer);
  12561. break;
  12562. case 'beginbfchar':
  12563. parseBfChar(cMap, lexer);
  12564. break;
  12565. case 'begincidchar':
  12566. parseCidChar(cMap, lexer);
  12567. break;
  12568. case 'beginbfrange':
  12569. parseBfRange(cMap, lexer);
  12570. break;
  12571. case 'begincidrange':
  12572. parseCidRange(cMap, lexer);
  12573. break;
  12574. }
  12575. }
  12576. }
  12577. if (!useCMap && embededUseCMap) {
  12578. // Load the usecmap definition from the file only if there wasn't one
  12579. // specified.
  12580. useCMap = embededUseCMap;
  12581. }
  12582. if (useCMap) {
  12583. extendCMap(cMap, builtInCMapParams, useCMap);
  12584. }
  12585. }
  12586. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12587. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12588. // If there aren't any code space ranges defined clone all the parent ones
  12589. // into this cMap.
  12590. if (cMap.numCodespaceRanges === 0) {
  12591. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12592. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12593. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12594. }
  12595. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12596. }
  12597. // Merge the map into the current one, making sure not to override
  12598. // any previously defined entries.
  12599. cMap.useCMap.forEach(function(key, value) {
  12600. if (!cMap.contains(key)) {
  12601. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12602. }
  12603. });
  12604. }
  12605. function parseBinaryCMap(name, builtInCMapParams) {
  12606. var url = builtInCMapParams.url + name + '.bcmap';
  12607. var cMap = new CMap(true);
  12608. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12609. extendCMap(cMap, builtInCMapParams, useCMap);
  12610. });
  12611. return cMap;
  12612. }
  12613. function createBuiltInCMap(name, builtInCMapParams) {
  12614. if (name === 'Identity-H') {
  12615. return new IdentityCMap(false, 2);
  12616. } else if (name === 'Identity-V') {
  12617. return new IdentityCMap(true, 2);
  12618. }
  12619. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12620. error('Unknown cMap name: ' + name);
  12621. }
  12622. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12623. if (builtInCMapParams.packed) {
  12624. return parseBinaryCMap(name, builtInCMapParams);
  12625. }
  12626. var request = new XMLHttpRequest();
  12627. var url = builtInCMapParams.url + name;
  12628. request.open('GET', url, false);
  12629. request.send(null);
  12630. if (!request.responseText) {
  12631. error('Unable to get cMap at: ' + url);
  12632. }
  12633. var cMap = new CMap(true);
  12634. var lexer = new Lexer(new StringStream(request.responseText));
  12635. parseCMap(cMap, lexer, builtInCMapParams, null);
  12636. return cMap;
  12637. }
  12638. return {
  12639. create: function (encoding, builtInCMapParams, useCMap) {
  12640. if (isName(encoding)) {
  12641. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12642. } else if (isStream(encoding)) {
  12643. var cMap = new CMap();
  12644. var lexer = new Lexer(encoding);
  12645. try {
  12646. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12647. } catch (e) {
  12648. warn('Invalid CMap data. ' + e);
  12649. }
  12650. return cMap;
  12651. }
  12652. error('Encoding required.');
  12653. }
  12654. };
  12655. })();
  12656. // Unicode Private Use Area
  12657. var PRIVATE_USE_OFFSET_START = 0xE000;
  12658. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12659. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12660. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12661. // except for Type 3 fonts
  12662. var PDF_GLYPH_SPACE_UNITS = 1000;
  12663. // Hinting is currently disabled due to unknown problems on windows
  12664. // in tracemonkey and various other pdfs with type1 fonts.
  12665. var HINTING_ENABLED = false;
  12666. // Accented charactars are not displayed properly on windows, using this flag
  12667. // to control analysis of seac charstrings.
  12668. var SEAC_ANALYSIS_ENABLED = false;
  12669. var FontFlags = {
  12670. FixedPitch: 1,
  12671. Serif: 2,
  12672. Symbolic: 4,
  12673. Script: 8,
  12674. Nonsymbolic: 32,
  12675. Italic: 64,
  12676. AllCap: 65536,
  12677. SmallCap: 131072,
  12678. ForceBold: 262144
  12679. };
  12680. var Encodings = {
  12681. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12682. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12683. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12684. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12685. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12686. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12687. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12688. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12689. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12690. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12691. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12692. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12693. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12694. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12695. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12696. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12697. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12698. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12699. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12700. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12701. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12702. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12703. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12704. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12705. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12706. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12707. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12708. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12709. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12710. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12711. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12712. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12713. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12714. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12715. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12716. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12717. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12718. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12719. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12720. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12721. 'Ydieresissmall'],
  12722. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12723. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12724. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12725. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12726. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12727. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12728. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12729. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12730. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12731. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12732. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12733. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12734. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12735. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12736. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12737. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12738. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12739. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12740. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12741. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12742. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12743. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12744. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12745. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12746. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12747. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12748. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12749. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12750. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12751. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12752. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12753. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12754. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12755. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12756. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12757. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12758. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12759. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12760. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12761. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12762. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12763. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12764. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12765. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12766. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12767. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12768. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12769. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12770. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12771. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12772. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12773. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12774. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12775. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12776. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12777. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12778. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12779. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12780. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12781. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12782. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12783. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12784. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12785. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12786. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12787. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12788. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12789. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12790. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12791. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12792. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12793. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12794. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12795. 'ogonek', 'caron'],
  12796. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12797. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12798. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12799. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12800. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12801. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12802. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12803. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12804. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12805. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12806. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12807. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12808. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12809. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12810. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12811. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12812. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12813. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12814. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12815. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12816. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12817. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12818. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12819. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12820. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12821. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12822. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12823. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12824. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12825. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12826. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12827. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12828. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12829. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12830. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12831. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12832. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12833. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  12834. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  12835. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  12836. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  12837. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  12838. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  12839. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  12840. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  12841. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  12842. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  12843. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  12844. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  12845. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  12846. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  12847. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  12848. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  12849. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  12850. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  12851. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  12852. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  12853. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  12854. 'ydieresis'],
  12855. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12856. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12857. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  12858. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  12859. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  12860. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  12861. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  12862. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  12863. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  12864. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  12865. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  12866. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  12867. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  12868. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  12869. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  12870. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12871. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  12872. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  12873. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  12874. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  12875. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  12876. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  12877. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  12878. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  12879. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  12880. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  12881. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  12882. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  12883. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  12884. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  12885. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  12886. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  12887. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  12888. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  12889. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  12890. 'bracerightbt'],
  12891. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12892. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12893. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  12894. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  12895. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  12896. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  12897. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  12898. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  12899. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  12900. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  12901. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  12902. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  12903. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  12904. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  12905. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  12906. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  12907. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  12908. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  12909. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  12910. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  12911. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  12912. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  12913. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  12914. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  12915. };
  12916. /**
  12917. * Hold a map of decoded fonts and of the standard fourteen Type1
  12918. * fonts and their acronyms.
  12919. */
  12920. var stdFontMap = {
  12921. 'ArialNarrow': 'Helvetica',
  12922. 'ArialNarrow-Bold': 'Helvetica-Bold',
  12923. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  12924. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  12925. 'ArialBlack': 'Helvetica',
  12926. 'ArialBlack-Bold': 'Helvetica-Bold',
  12927. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  12928. 'ArialBlack-Italic': 'Helvetica-Oblique',
  12929. 'Arial': 'Helvetica',
  12930. 'Arial-Bold': 'Helvetica-Bold',
  12931. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  12932. 'Arial-Italic': 'Helvetica-Oblique',
  12933. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  12934. 'Arial-BoldMT': 'Helvetica-Bold',
  12935. 'Arial-ItalicMT': 'Helvetica-Oblique',
  12936. 'ArialMT': 'Helvetica',
  12937. 'Courier-Bold': 'Courier-Bold',
  12938. 'Courier-BoldItalic': 'Courier-BoldOblique',
  12939. 'Courier-Italic': 'Courier-Oblique',
  12940. 'CourierNew': 'Courier',
  12941. 'CourierNew-Bold': 'Courier-Bold',
  12942. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  12943. 'CourierNew-Italic': 'Courier-Oblique',
  12944. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  12945. 'CourierNewPS-BoldMT': 'Courier-Bold',
  12946. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  12947. 'CourierNewPSMT': 'Courier',
  12948. 'Helvetica-Bold': 'Helvetica-Bold',
  12949. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  12950. 'Helvetica-Italic': 'Helvetica-Oblique',
  12951. 'Symbol-Bold': 'Symbol',
  12952. 'Symbol-BoldItalic': 'Symbol',
  12953. 'Symbol-Italic': 'Symbol',
  12954. 'TimesNewRoman': 'Times-Roman',
  12955. 'TimesNewRoman-Bold': 'Times-Bold',
  12956. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  12957. 'TimesNewRoman-Italic': 'Times-Italic',
  12958. 'TimesNewRomanPS': 'Times-Roman',
  12959. 'TimesNewRomanPS-Bold': 'Times-Bold',
  12960. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  12961. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  12962. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  12963. 'TimesNewRomanPS-Italic': 'Times-Italic',
  12964. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  12965. 'TimesNewRomanPSMT': 'Times-Roman',
  12966. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  12967. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  12968. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  12969. };
  12970. /**
  12971. * Holds the map of the non-standard fonts that might be included as a standard
  12972. * fonts without glyph data.
  12973. */
  12974. var nonStdFontMap = {
  12975. 'ComicSansMS': 'Comic Sans MS',
  12976. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  12977. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  12978. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  12979. 'LucidaConsole': 'Courier',
  12980. 'LucidaConsole-Bold': 'Courier-Bold',
  12981. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  12982. 'LucidaConsole-Italic': 'Courier-Oblique',
  12983. 'MS-Gothic': 'MS Gothic',
  12984. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  12985. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  12986. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  12987. 'MS-Mincho': 'MS Mincho',
  12988. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  12989. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  12990. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  12991. 'MS-PGothic': 'MS PGothic',
  12992. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  12993. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  12994. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  12995. 'MS-PMincho': 'MS PMincho',
  12996. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  12997. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  12998. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  12999. };
  13000. var serifFonts = {
  13001. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13002. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13003. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13004. 'Arno': true, 'Aster': true, 'Aurora': true,
  13005. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13006. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13007. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13008. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13009. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13010. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13011. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13012. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13013. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13014. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13015. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13016. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13017. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13018. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13019. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13020. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13021. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13022. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13023. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13024. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13025. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13026. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13027. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13028. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13029. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13030. 'Miller': true, 'Minion': true, 'Modern': true,
  13031. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13032. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13033. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13034. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13035. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13036. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13037. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13038. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13039. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13040. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13041. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13042. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13043. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13044. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13045. };
  13046. var symbolsFonts = {
  13047. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13048. };
  13049. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13050. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13051. // glyphs, but common for some set of the standard fonts.
  13052. var GlyphMapForStandardFonts = {
  13053. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13054. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13055. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13056. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13057. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13058. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13059. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13060. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13061. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13062. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13063. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13064. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13065. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13066. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13067. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13068. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13069. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13070. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13071. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13072. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13073. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13074. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13075. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13076. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13077. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13078. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13079. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13080. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13081. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13082. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13083. '298': 380, '305': 963,
  13084. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13085. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13086. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13087. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13088. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13089. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13090. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13091. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13092. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13093. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13094. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13095. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13096. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13097. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13098. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13099. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13100. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13101. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13102. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13103. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13104. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13105. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13106. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13107. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13108. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13109. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13110. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13111. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13112. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13113. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13114. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13115. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13116. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13117. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13118. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13119. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13120. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13121. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13122. };
  13123. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13124. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13125. // to the similar equivalents in the normal characters range.
  13126. var SpecialPUASymbols = {
  13127. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13128. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13129. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13130. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13131. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13132. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13133. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13134. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13135. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13136. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13137. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13138. '63742': 0x23AD, // bracerightmid (0xF8FE)
  13139. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13140. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13141. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13142. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13143. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13144. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13145. '63723': 0x239B, // parenlefttp (0xF8EB)
  13146. '63724': 0x239C, // parenleftex (0xF8EC)
  13147. '63725': 0x239D, // parenleftbt (0xF8ED)
  13148. '63734': 0x239E, // parenrighttp (0xF8F6)
  13149. '63735': 0x239F, // parenrightex (0xF8F7)
  13150. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13151. };
  13152. function mapSpecialUnicodeValues(code) {
  13153. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13154. return 0;
  13155. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13156. return (SpecialPUASymbols[code] || code);
  13157. }
  13158. return code;
  13159. }
  13160. var UnicodeRanges = [
  13161. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13162. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13163. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13164. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13165. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13166. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13167. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13168. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13169. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13170. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13171. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13172. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13173. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13174. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13175. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13176. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13177. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13178. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13179. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13180. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13181. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13182. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13183. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13184. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13185. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13186. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13187. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13188. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13189. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13190. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13191. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13192. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13193. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13194. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13195. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13196. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13197. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13198. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13199. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13200. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13201. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13202. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13203. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13204. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13205. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13206. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13207. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13208. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13209. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13210. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13211. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13212. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13213. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13214. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13215. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13216. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13217. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13218. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13219. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13220. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13221. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13222. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13223. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13224. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13225. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13226. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13227. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13228. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13229. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13230. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13231. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13232. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13233. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13234. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13235. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13236. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13237. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13238. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13239. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13240. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13241. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13242. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13243. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13244. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13245. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13246. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13247. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13248. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13249. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13250. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13251. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13252. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13253. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13254. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13255. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13256. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13257. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13258. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13259. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13260. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13261. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13262. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13263. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13264. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13265. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13266. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13267. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13268. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13269. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13270. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13271. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13272. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13273. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13274. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13275. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13276. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13277. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13278. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13279. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13280. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13281. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13282. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13283. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13284. ];
  13285. var MacStandardGlyphOrdering = [
  13286. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13287. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13288. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13289. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13290. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13291. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13292. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13293. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13294. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13295. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13296. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13297. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13298. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13299. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13300. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13301. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13302. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13303. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13304. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13305. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13306. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13307. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13308. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13309. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13310. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13311. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13312. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13313. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13314. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13315. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13316. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13317. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13318. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13319. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13320. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13321. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13322. function getUnicodeRangeFor(value) {
  13323. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13324. var range = UnicodeRanges[i];
  13325. if (value >= range.begin && value < range.end) {
  13326. return i;
  13327. }
  13328. }
  13329. return -1;
  13330. }
  13331. function isRTLRangeFor(value) {
  13332. var range = UnicodeRanges[13];
  13333. if (value >= range.begin && value < range.end) {
  13334. return true;
  13335. }
  13336. range = UnicodeRanges[11];
  13337. if (value >= range.begin && value < range.end) {
  13338. return true;
  13339. }
  13340. return false;
  13341. }
  13342. // The normalization table is obtained by filtering the Unicode characters
  13343. // database with <compat> entries.
  13344. var NormalizedUnicodes = {
  13345. '\u00A8': '\u0020\u0308',
  13346. '\u00AF': '\u0020\u0304',
  13347. '\u00B4': '\u0020\u0301',
  13348. '\u00B5': '\u03BC',
  13349. '\u00B8': '\u0020\u0327',
  13350. '\u0132': '\u0049\u004A',
  13351. '\u0133': '\u0069\u006A',
  13352. '\u013F': '\u004C\u00B7',
  13353. '\u0140': '\u006C\u00B7',
  13354. '\u0149': '\u02BC\u006E',
  13355. '\u017F': '\u0073',
  13356. '\u01C4': '\u0044\u017D',
  13357. '\u01C5': '\u0044\u017E',
  13358. '\u01C6': '\u0064\u017E',
  13359. '\u01C7': '\u004C\u004A',
  13360. '\u01C8': '\u004C\u006A',
  13361. '\u01C9': '\u006C\u006A',
  13362. '\u01CA': '\u004E\u004A',
  13363. '\u01CB': '\u004E\u006A',
  13364. '\u01CC': '\u006E\u006A',
  13365. '\u01F1': '\u0044\u005A',
  13366. '\u01F2': '\u0044\u007A',
  13367. '\u01F3': '\u0064\u007A',
  13368. '\u02D8': '\u0020\u0306',
  13369. '\u02D9': '\u0020\u0307',
  13370. '\u02DA': '\u0020\u030A',
  13371. '\u02DB': '\u0020\u0328',
  13372. '\u02DC': '\u0020\u0303',
  13373. '\u02DD': '\u0020\u030B',
  13374. '\u037A': '\u0020\u0345',
  13375. '\u0384': '\u0020\u0301',
  13376. '\u03D0': '\u03B2',
  13377. '\u03D1': '\u03B8',
  13378. '\u03D2': '\u03A5',
  13379. '\u03D5': '\u03C6',
  13380. '\u03D6': '\u03C0',
  13381. '\u03F0': '\u03BA',
  13382. '\u03F1': '\u03C1',
  13383. '\u03F2': '\u03C2',
  13384. '\u03F4': '\u0398',
  13385. '\u03F5': '\u03B5',
  13386. '\u03F9': '\u03A3',
  13387. '\u0587': '\u0565\u0582',
  13388. '\u0675': '\u0627\u0674',
  13389. '\u0676': '\u0648\u0674',
  13390. '\u0677': '\u06C7\u0674',
  13391. '\u0678': '\u064A\u0674',
  13392. '\u0E33': '\u0E4D\u0E32',
  13393. '\u0EB3': '\u0ECD\u0EB2',
  13394. '\u0EDC': '\u0EAB\u0E99',
  13395. '\u0EDD': '\u0EAB\u0EA1',
  13396. '\u0F77': '\u0FB2\u0F81',
  13397. '\u0F79': '\u0FB3\u0F81',
  13398. '\u1E9A': '\u0061\u02BE',
  13399. '\u1FBD': '\u0020\u0313',
  13400. '\u1FBF': '\u0020\u0313',
  13401. '\u1FC0': '\u0020\u0342',
  13402. '\u1FFE': '\u0020\u0314',
  13403. '\u2002': '\u0020',
  13404. '\u2003': '\u0020',
  13405. '\u2004': '\u0020',
  13406. '\u2005': '\u0020',
  13407. '\u2006': '\u0020',
  13408. '\u2008': '\u0020',
  13409. '\u2009': '\u0020',
  13410. '\u200A': '\u0020',
  13411. '\u2017': '\u0020\u0333',
  13412. '\u2024': '\u002E',
  13413. '\u2025': '\u002E\u002E',
  13414. '\u2026': '\u002E\u002E\u002E',
  13415. '\u2033': '\u2032\u2032',
  13416. '\u2034': '\u2032\u2032\u2032',
  13417. '\u2036': '\u2035\u2035',
  13418. '\u2037': '\u2035\u2035\u2035',
  13419. '\u203C': '\u0021\u0021',
  13420. '\u203E': '\u0020\u0305',
  13421. '\u2047': '\u003F\u003F',
  13422. '\u2048': '\u003F\u0021',
  13423. '\u2049': '\u0021\u003F',
  13424. '\u2057': '\u2032\u2032\u2032\u2032',
  13425. '\u205F': '\u0020',
  13426. '\u20A8': '\u0052\u0073',
  13427. '\u2100': '\u0061\u002F\u0063',
  13428. '\u2101': '\u0061\u002F\u0073',
  13429. '\u2103': '\u00B0\u0043',
  13430. '\u2105': '\u0063\u002F\u006F',
  13431. '\u2106': '\u0063\u002F\u0075',
  13432. '\u2107': '\u0190',
  13433. '\u2109': '\u00B0\u0046',
  13434. '\u2116': '\u004E\u006F',
  13435. '\u2121': '\u0054\u0045\u004C',
  13436. '\u2135': '\u05D0',
  13437. '\u2136': '\u05D1',
  13438. '\u2137': '\u05D2',
  13439. '\u2138': '\u05D3',
  13440. '\u213B': '\u0046\u0041\u0058',
  13441. '\u2160': '\u0049',
  13442. '\u2161': '\u0049\u0049',
  13443. '\u2162': '\u0049\u0049\u0049',
  13444. '\u2163': '\u0049\u0056',
  13445. '\u2164': '\u0056',
  13446. '\u2165': '\u0056\u0049',
  13447. '\u2166': '\u0056\u0049\u0049',
  13448. '\u2167': '\u0056\u0049\u0049\u0049',
  13449. '\u2168': '\u0049\u0058',
  13450. '\u2169': '\u0058',
  13451. '\u216A': '\u0058\u0049',
  13452. '\u216B': '\u0058\u0049\u0049',
  13453. '\u216C': '\u004C',
  13454. '\u216D': '\u0043',
  13455. '\u216E': '\u0044',
  13456. '\u216F': '\u004D',
  13457. '\u2170': '\u0069',
  13458. '\u2171': '\u0069\u0069',
  13459. '\u2172': '\u0069\u0069\u0069',
  13460. '\u2173': '\u0069\u0076',
  13461. '\u2174': '\u0076',
  13462. '\u2175': '\u0076\u0069',
  13463. '\u2176': '\u0076\u0069\u0069',
  13464. '\u2177': '\u0076\u0069\u0069\u0069',
  13465. '\u2178': '\u0069\u0078',
  13466. '\u2179': '\u0078',
  13467. '\u217A': '\u0078\u0069',
  13468. '\u217B': '\u0078\u0069\u0069',
  13469. '\u217C': '\u006C',
  13470. '\u217D': '\u0063',
  13471. '\u217E': '\u0064',
  13472. '\u217F': '\u006D',
  13473. '\u222C': '\u222B\u222B',
  13474. '\u222D': '\u222B\u222B\u222B',
  13475. '\u222F': '\u222E\u222E',
  13476. '\u2230': '\u222E\u222E\u222E',
  13477. '\u2474': '\u0028\u0031\u0029',
  13478. '\u2475': '\u0028\u0032\u0029',
  13479. '\u2476': '\u0028\u0033\u0029',
  13480. '\u2477': '\u0028\u0034\u0029',
  13481. '\u2478': '\u0028\u0035\u0029',
  13482. '\u2479': '\u0028\u0036\u0029',
  13483. '\u247A': '\u0028\u0037\u0029',
  13484. '\u247B': '\u0028\u0038\u0029',
  13485. '\u247C': '\u0028\u0039\u0029',
  13486. '\u247D': '\u0028\u0031\u0030\u0029',
  13487. '\u247E': '\u0028\u0031\u0031\u0029',
  13488. '\u247F': '\u0028\u0031\u0032\u0029',
  13489. '\u2480': '\u0028\u0031\u0033\u0029',
  13490. '\u2481': '\u0028\u0031\u0034\u0029',
  13491. '\u2482': '\u0028\u0031\u0035\u0029',
  13492. '\u2483': '\u0028\u0031\u0036\u0029',
  13493. '\u2484': '\u0028\u0031\u0037\u0029',
  13494. '\u2485': '\u0028\u0031\u0038\u0029',
  13495. '\u2486': '\u0028\u0031\u0039\u0029',
  13496. '\u2487': '\u0028\u0032\u0030\u0029',
  13497. '\u2488': '\u0031\u002E',
  13498. '\u2489': '\u0032\u002E',
  13499. '\u248A': '\u0033\u002E',
  13500. '\u248B': '\u0034\u002E',
  13501. '\u248C': '\u0035\u002E',
  13502. '\u248D': '\u0036\u002E',
  13503. '\u248E': '\u0037\u002E',
  13504. '\u248F': '\u0038\u002E',
  13505. '\u2490': '\u0039\u002E',
  13506. '\u2491': '\u0031\u0030\u002E',
  13507. '\u2492': '\u0031\u0031\u002E',
  13508. '\u2493': '\u0031\u0032\u002E',
  13509. '\u2494': '\u0031\u0033\u002E',
  13510. '\u2495': '\u0031\u0034\u002E',
  13511. '\u2496': '\u0031\u0035\u002E',
  13512. '\u2497': '\u0031\u0036\u002E',
  13513. '\u2498': '\u0031\u0037\u002E',
  13514. '\u2499': '\u0031\u0038\u002E',
  13515. '\u249A': '\u0031\u0039\u002E',
  13516. '\u249B': '\u0032\u0030\u002E',
  13517. '\u249C': '\u0028\u0061\u0029',
  13518. '\u249D': '\u0028\u0062\u0029',
  13519. '\u249E': '\u0028\u0063\u0029',
  13520. '\u249F': '\u0028\u0064\u0029',
  13521. '\u24A0': '\u0028\u0065\u0029',
  13522. '\u24A1': '\u0028\u0066\u0029',
  13523. '\u24A2': '\u0028\u0067\u0029',
  13524. '\u24A3': '\u0028\u0068\u0029',
  13525. '\u24A4': '\u0028\u0069\u0029',
  13526. '\u24A5': '\u0028\u006A\u0029',
  13527. '\u24A6': '\u0028\u006B\u0029',
  13528. '\u24A7': '\u0028\u006C\u0029',
  13529. '\u24A8': '\u0028\u006D\u0029',
  13530. '\u24A9': '\u0028\u006E\u0029',
  13531. '\u24AA': '\u0028\u006F\u0029',
  13532. '\u24AB': '\u0028\u0070\u0029',
  13533. '\u24AC': '\u0028\u0071\u0029',
  13534. '\u24AD': '\u0028\u0072\u0029',
  13535. '\u24AE': '\u0028\u0073\u0029',
  13536. '\u24AF': '\u0028\u0074\u0029',
  13537. '\u24B0': '\u0028\u0075\u0029',
  13538. '\u24B1': '\u0028\u0076\u0029',
  13539. '\u24B2': '\u0028\u0077\u0029',
  13540. '\u24B3': '\u0028\u0078\u0029',
  13541. '\u24B4': '\u0028\u0079\u0029',
  13542. '\u24B5': '\u0028\u007A\u0029',
  13543. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13544. '\u2A74': '\u003A\u003A\u003D',
  13545. '\u2A75': '\u003D\u003D',
  13546. '\u2A76': '\u003D\u003D\u003D',
  13547. '\u2E9F': '\u6BCD',
  13548. '\u2EF3': '\u9F9F',
  13549. '\u2F00': '\u4E00',
  13550. '\u2F01': '\u4E28',
  13551. '\u2F02': '\u4E36',
  13552. '\u2F03': '\u4E3F',
  13553. '\u2F04': '\u4E59',
  13554. '\u2F05': '\u4E85',
  13555. '\u2F06': '\u4E8C',
  13556. '\u2F07': '\u4EA0',
  13557. '\u2F08': '\u4EBA',
  13558. '\u2F09': '\u513F',
  13559. '\u2F0A': '\u5165',
  13560. '\u2F0B': '\u516B',
  13561. '\u2F0C': '\u5182',
  13562. '\u2F0D': '\u5196',
  13563. '\u2F0E': '\u51AB',
  13564. '\u2F0F': '\u51E0',
  13565. '\u2F10': '\u51F5',
  13566. '\u2F11': '\u5200',
  13567. '\u2F12': '\u529B',
  13568. '\u2F13': '\u52F9',
  13569. '\u2F14': '\u5315',
  13570. '\u2F15': '\u531A',
  13571. '\u2F16': '\u5338',
  13572. '\u2F17': '\u5341',
  13573. '\u2F18': '\u535C',
  13574. '\u2F19': '\u5369',
  13575. '\u2F1A': '\u5382',
  13576. '\u2F1B': '\u53B6',
  13577. '\u2F1C': '\u53C8',
  13578. '\u2F1D': '\u53E3',
  13579. '\u2F1E': '\u56D7',
  13580. '\u2F1F': '\u571F',
  13581. '\u2F20': '\u58EB',
  13582. '\u2F21': '\u5902',
  13583. '\u2F22': '\u590A',
  13584. '\u2F23': '\u5915',
  13585. '\u2F24': '\u5927',
  13586. '\u2F25': '\u5973',
  13587. '\u2F26': '\u5B50',
  13588. '\u2F27': '\u5B80',
  13589. '\u2F28': '\u5BF8',
  13590. '\u2F29': '\u5C0F',
  13591. '\u2F2A': '\u5C22',
  13592. '\u2F2B': '\u5C38',
  13593. '\u2F2C': '\u5C6E',
  13594. '\u2F2D': '\u5C71',
  13595. '\u2F2E': '\u5DDB',
  13596. '\u2F2F': '\u5DE5',
  13597. '\u2F30': '\u5DF1',
  13598. '\u2F31': '\u5DFE',
  13599. '\u2F32': '\u5E72',
  13600. '\u2F33': '\u5E7A',
  13601. '\u2F34': '\u5E7F',
  13602. '\u2F35': '\u5EF4',
  13603. '\u2F36': '\u5EFE',
  13604. '\u2F37': '\u5F0B',
  13605. '\u2F38': '\u5F13',
  13606. '\u2F39': '\u5F50',
  13607. '\u2F3A': '\u5F61',
  13608. '\u2F3B': '\u5F73',
  13609. '\u2F3C': '\u5FC3',
  13610. '\u2F3D': '\u6208',
  13611. '\u2F3E': '\u6236',
  13612. '\u2F3F': '\u624B',
  13613. '\u2F40': '\u652F',
  13614. '\u2F41': '\u6534',
  13615. '\u2F42': '\u6587',
  13616. '\u2F43': '\u6597',
  13617. '\u2F44': '\u65A4',
  13618. '\u2F45': '\u65B9',
  13619. '\u2F46': '\u65E0',
  13620. '\u2F47': '\u65E5',
  13621. '\u2F48': '\u66F0',
  13622. '\u2F49': '\u6708',
  13623. '\u2F4A': '\u6728',
  13624. '\u2F4B': '\u6B20',
  13625. '\u2F4C': '\u6B62',
  13626. '\u2F4D': '\u6B79',
  13627. '\u2F4E': '\u6BB3',
  13628. '\u2F4F': '\u6BCB',
  13629. '\u2F50': '\u6BD4',
  13630. '\u2F51': '\u6BDB',
  13631. '\u2F52': '\u6C0F',
  13632. '\u2F53': '\u6C14',
  13633. '\u2F54': '\u6C34',
  13634. '\u2F55': '\u706B',
  13635. '\u2F56': '\u722A',
  13636. '\u2F57': '\u7236',
  13637. '\u2F58': '\u723B',
  13638. '\u2F59': '\u723F',
  13639. '\u2F5A': '\u7247',
  13640. '\u2F5B': '\u7259',
  13641. '\u2F5C': '\u725B',
  13642. '\u2F5D': '\u72AC',
  13643. '\u2F5E': '\u7384',
  13644. '\u2F5F': '\u7389',
  13645. '\u2F60': '\u74DC',
  13646. '\u2F61': '\u74E6',
  13647. '\u2F62': '\u7518',
  13648. '\u2F63': '\u751F',
  13649. '\u2F64': '\u7528',
  13650. '\u2F65': '\u7530',
  13651. '\u2F66': '\u758B',
  13652. '\u2F67': '\u7592',
  13653. '\u2F68': '\u7676',
  13654. '\u2F69': '\u767D',
  13655. '\u2F6A': '\u76AE',
  13656. '\u2F6B': '\u76BF',
  13657. '\u2F6C': '\u76EE',
  13658. '\u2F6D': '\u77DB',
  13659. '\u2F6E': '\u77E2',
  13660. '\u2F6F': '\u77F3',
  13661. '\u2F70': '\u793A',
  13662. '\u2F71': '\u79B8',
  13663. '\u2F72': '\u79BE',
  13664. '\u2F73': '\u7A74',
  13665. '\u2F74': '\u7ACB',
  13666. '\u2F75': '\u7AF9',
  13667. '\u2F76': '\u7C73',
  13668. '\u2F77': '\u7CF8',
  13669. '\u2F78': '\u7F36',
  13670. '\u2F79': '\u7F51',
  13671. '\u2F7A': '\u7F8A',
  13672. '\u2F7B': '\u7FBD',
  13673. '\u2F7C': '\u8001',
  13674. '\u2F7D': '\u800C',
  13675. '\u2F7E': '\u8012',
  13676. '\u2F7F': '\u8033',
  13677. '\u2F80': '\u807F',
  13678. '\u2F81': '\u8089',
  13679. '\u2F82': '\u81E3',
  13680. '\u2F83': '\u81EA',
  13681. '\u2F84': '\u81F3',
  13682. '\u2F85': '\u81FC',
  13683. '\u2F86': '\u820C',
  13684. '\u2F87': '\u821B',
  13685. '\u2F88': '\u821F',
  13686. '\u2F89': '\u826E',
  13687. '\u2F8A': '\u8272',
  13688. '\u2F8B': '\u8278',
  13689. '\u2F8C': '\u864D',
  13690. '\u2F8D': '\u866B',
  13691. '\u2F8E': '\u8840',
  13692. '\u2F8F': '\u884C',
  13693. '\u2F90': '\u8863',
  13694. '\u2F91': '\u897E',
  13695. '\u2F92': '\u898B',
  13696. '\u2F93': '\u89D2',
  13697. '\u2F94': '\u8A00',
  13698. '\u2F95': '\u8C37',
  13699. '\u2F96': '\u8C46',
  13700. '\u2F97': '\u8C55',
  13701. '\u2F98': '\u8C78',
  13702. '\u2F99': '\u8C9D',
  13703. '\u2F9A': '\u8D64',
  13704. '\u2F9B': '\u8D70',
  13705. '\u2F9C': '\u8DB3',
  13706. '\u2F9D': '\u8EAB',
  13707. '\u2F9E': '\u8ECA',
  13708. '\u2F9F': '\u8F9B',
  13709. '\u2FA0': '\u8FB0',
  13710. '\u2FA1': '\u8FB5',
  13711. '\u2FA2': '\u9091',
  13712. '\u2FA3': '\u9149',
  13713. '\u2FA4': '\u91C6',
  13714. '\u2FA5': '\u91CC',
  13715. '\u2FA6': '\u91D1',
  13716. '\u2FA7': '\u9577',
  13717. '\u2FA8': '\u9580',
  13718. '\u2FA9': '\u961C',
  13719. '\u2FAA': '\u96B6',
  13720. '\u2FAB': '\u96B9',
  13721. '\u2FAC': '\u96E8',
  13722. '\u2FAD': '\u9751',
  13723. '\u2FAE': '\u975E',
  13724. '\u2FAF': '\u9762',
  13725. '\u2FB0': '\u9769',
  13726. '\u2FB1': '\u97CB',
  13727. '\u2FB2': '\u97ED',
  13728. '\u2FB3': '\u97F3',
  13729. '\u2FB4': '\u9801',
  13730. '\u2FB5': '\u98A8',
  13731. '\u2FB6': '\u98DB',
  13732. '\u2FB7': '\u98DF',
  13733. '\u2FB8': '\u9996',
  13734. '\u2FB9': '\u9999',
  13735. '\u2FBA': '\u99AC',
  13736. '\u2FBB': '\u9AA8',
  13737. '\u2FBC': '\u9AD8',
  13738. '\u2FBD': '\u9ADF',
  13739. '\u2FBE': '\u9B25',
  13740. '\u2FBF': '\u9B2F',
  13741. '\u2FC0': '\u9B32',
  13742. '\u2FC1': '\u9B3C',
  13743. '\u2FC2': '\u9B5A',
  13744. '\u2FC3': '\u9CE5',
  13745. '\u2FC4': '\u9E75',
  13746. '\u2FC5': '\u9E7F',
  13747. '\u2FC6': '\u9EA5',
  13748. '\u2FC7': '\u9EBB',
  13749. '\u2FC8': '\u9EC3',
  13750. '\u2FC9': '\u9ECD',
  13751. '\u2FCA': '\u9ED1',
  13752. '\u2FCB': '\u9EF9',
  13753. '\u2FCC': '\u9EFD',
  13754. '\u2FCD': '\u9F0E',
  13755. '\u2FCE': '\u9F13',
  13756. '\u2FCF': '\u9F20',
  13757. '\u2FD0': '\u9F3B',
  13758. '\u2FD1': '\u9F4A',
  13759. '\u2FD2': '\u9F52',
  13760. '\u2FD3': '\u9F8D',
  13761. '\u2FD4': '\u9F9C',
  13762. '\u2FD5': '\u9FA0',
  13763. '\u3036': '\u3012',
  13764. '\u3038': '\u5341',
  13765. '\u3039': '\u5344',
  13766. '\u303A': '\u5345',
  13767. '\u309B': '\u0020\u3099',
  13768. '\u309C': '\u0020\u309A',
  13769. '\u3131': '\u1100',
  13770. '\u3132': '\u1101',
  13771. '\u3133': '\u11AA',
  13772. '\u3134': '\u1102',
  13773. '\u3135': '\u11AC',
  13774. '\u3136': '\u11AD',
  13775. '\u3137': '\u1103',
  13776. '\u3138': '\u1104',
  13777. '\u3139': '\u1105',
  13778. '\u313A': '\u11B0',
  13779. '\u313B': '\u11B1',
  13780. '\u313C': '\u11B2',
  13781. '\u313D': '\u11B3',
  13782. '\u313E': '\u11B4',
  13783. '\u313F': '\u11B5',
  13784. '\u3140': '\u111A',
  13785. '\u3141': '\u1106',
  13786. '\u3142': '\u1107',
  13787. '\u3143': '\u1108',
  13788. '\u3144': '\u1121',
  13789. '\u3145': '\u1109',
  13790. '\u3146': '\u110A',
  13791. '\u3147': '\u110B',
  13792. '\u3148': '\u110C',
  13793. '\u3149': '\u110D',
  13794. '\u314A': '\u110E',
  13795. '\u314B': '\u110F',
  13796. '\u314C': '\u1110',
  13797. '\u314D': '\u1111',
  13798. '\u314E': '\u1112',
  13799. '\u314F': '\u1161',
  13800. '\u3150': '\u1162',
  13801. '\u3151': '\u1163',
  13802. '\u3152': '\u1164',
  13803. '\u3153': '\u1165',
  13804. '\u3154': '\u1166',
  13805. '\u3155': '\u1167',
  13806. '\u3156': '\u1168',
  13807. '\u3157': '\u1169',
  13808. '\u3158': '\u116A',
  13809. '\u3159': '\u116B',
  13810. '\u315A': '\u116C',
  13811. '\u315B': '\u116D',
  13812. '\u315C': '\u116E',
  13813. '\u315D': '\u116F',
  13814. '\u315E': '\u1170',
  13815. '\u315F': '\u1171',
  13816. '\u3160': '\u1172',
  13817. '\u3161': '\u1173',
  13818. '\u3162': '\u1174',
  13819. '\u3163': '\u1175',
  13820. '\u3164': '\u1160',
  13821. '\u3165': '\u1114',
  13822. '\u3166': '\u1115',
  13823. '\u3167': '\u11C7',
  13824. '\u3168': '\u11C8',
  13825. '\u3169': '\u11CC',
  13826. '\u316A': '\u11CE',
  13827. '\u316B': '\u11D3',
  13828. '\u316C': '\u11D7',
  13829. '\u316D': '\u11D9',
  13830. '\u316E': '\u111C',
  13831. '\u316F': '\u11DD',
  13832. '\u3170': '\u11DF',
  13833. '\u3171': '\u111D',
  13834. '\u3172': '\u111E',
  13835. '\u3173': '\u1120',
  13836. '\u3174': '\u1122',
  13837. '\u3175': '\u1123',
  13838. '\u3176': '\u1127',
  13839. '\u3177': '\u1129',
  13840. '\u3178': '\u112B',
  13841. '\u3179': '\u112C',
  13842. '\u317A': '\u112D',
  13843. '\u317B': '\u112E',
  13844. '\u317C': '\u112F',
  13845. '\u317D': '\u1132',
  13846. '\u317E': '\u1136',
  13847. '\u317F': '\u1140',
  13848. '\u3180': '\u1147',
  13849. '\u3181': '\u114C',
  13850. '\u3182': '\u11F1',
  13851. '\u3183': '\u11F2',
  13852. '\u3184': '\u1157',
  13853. '\u3185': '\u1158',
  13854. '\u3186': '\u1159',
  13855. '\u3187': '\u1184',
  13856. '\u3188': '\u1185',
  13857. '\u3189': '\u1188',
  13858. '\u318A': '\u1191',
  13859. '\u318B': '\u1192',
  13860. '\u318C': '\u1194',
  13861. '\u318D': '\u119E',
  13862. '\u318E': '\u11A1',
  13863. '\u3200': '\u0028\u1100\u0029',
  13864. '\u3201': '\u0028\u1102\u0029',
  13865. '\u3202': '\u0028\u1103\u0029',
  13866. '\u3203': '\u0028\u1105\u0029',
  13867. '\u3204': '\u0028\u1106\u0029',
  13868. '\u3205': '\u0028\u1107\u0029',
  13869. '\u3206': '\u0028\u1109\u0029',
  13870. '\u3207': '\u0028\u110B\u0029',
  13871. '\u3208': '\u0028\u110C\u0029',
  13872. '\u3209': '\u0028\u110E\u0029',
  13873. '\u320A': '\u0028\u110F\u0029',
  13874. '\u320B': '\u0028\u1110\u0029',
  13875. '\u320C': '\u0028\u1111\u0029',
  13876. '\u320D': '\u0028\u1112\u0029',
  13877. '\u320E': '\u0028\u1100\u1161\u0029',
  13878. '\u320F': '\u0028\u1102\u1161\u0029',
  13879. '\u3210': '\u0028\u1103\u1161\u0029',
  13880. '\u3211': '\u0028\u1105\u1161\u0029',
  13881. '\u3212': '\u0028\u1106\u1161\u0029',
  13882. '\u3213': '\u0028\u1107\u1161\u0029',
  13883. '\u3214': '\u0028\u1109\u1161\u0029',
  13884. '\u3215': '\u0028\u110B\u1161\u0029',
  13885. '\u3216': '\u0028\u110C\u1161\u0029',
  13886. '\u3217': '\u0028\u110E\u1161\u0029',
  13887. '\u3218': '\u0028\u110F\u1161\u0029',
  13888. '\u3219': '\u0028\u1110\u1161\u0029',
  13889. '\u321A': '\u0028\u1111\u1161\u0029',
  13890. '\u321B': '\u0028\u1112\u1161\u0029',
  13891. '\u321C': '\u0028\u110C\u116E\u0029',
  13892. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  13893. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  13894. '\u3220': '\u0028\u4E00\u0029',
  13895. '\u3221': '\u0028\u4E8C\u0029',
  13896. '\u3222': '\u0028\u4E09\u0029',
  13897. '\u3223': '\u0028\u56DB\u0029',
  13898. '\u3224': '\u0028\u4E94\u0029',
  13899. '\u3225': '\u0028\u516D\u0029',
  13900. '\u3226': '\u0028\u4E03\u0029',
  13901. '\u3227': '\u0028\u516B\u0029',
  13902. '\u3228': '\u0028\u4E5D\u0029',
  13903. '\u3229': '\u0028\u5341\u0029',
  13904. '\u322A': '\u0028\u6708\u0029',
  13905. '\u322B': '\u0028\u706B\u0029',
  13906. '\u322C': '\u0028\u6C34\u0029',
  13907. '\u322D': '\u0028\u6728\u0029',
  13908. '\u322E': '\u0028\u91D1\u0029',
  13909. '\u322F': '\u0028\u571F\u0029',
  13910. '\u3230': '\u0028\u65E5\u0029',
  13911. '\u3231': '\u0028\u682A\u0029',
  13912. '\u3232': '\u0028\u6709\u0029',
  13913. '\u3233': '\u0028\u793E\u0029',
  13914. '\u3234': '\u0028\u540D\u0029',
  13915. '\u3235': '\u0028\u7279\u0029',
  13916. '\u3236': '\u0028\u8CA1\u0029',
  13917. '\u3237': '\u0028\u795D\u0029',
  13918. '\u3238': '\u0028\u52B4\u0029',
  13919. '\u3239': '\u0028\u4EE3\u0029',
  13920. '\u323A': '\u0028\u547C\u0029',
  13921. '\u323B': '\u0028\u5B66\u0029',
  13922. '\u323C': '\u0028\u76E3\u0029',
  13923. '\u323D': '\u0028\u4F01\u0029',
  13924. '\u323E': '\u0028\u8CC7\u0029',
  13925. '\u323F': '\u0028\u5354\u0029',
  13926. '\u3240': '\u0028\u796D\u0029',
  13927. '\u3241': '\u0028\u4F11\u0029',
  13928. '\u3242': '\u0028\u81EA\u0029',
  13929. '\u3243': '\u0028\u81F3\u0029',
  13930. '\u32C0': '\u0031\u6708',
  13931. '\u32C1': '\u0032\u6708',
  13932. '\u32C2': '\u0033\u6708',
  13933. '\u32C3': '\u0034\u6708',
  13934. '\u32C4': '\u0035\u6708',
  13935. '\u32C5': '\u0036\u6708',
  13936. '\u32C6': '\u0037\u6708',
  13937. '\u32C7': '\u0038\u6708',
  13938. '\u32C8': '\u0039\u6708',
  13939. '\u32C9': '\u0031\u0030\u6708',
  13940. '\u32CA': '\u0031\u0031\u6708',
  13941. '\u32CB': '\u0031\u0032\u6708',
  13942. '\u3358': '\u0030\u70B9',
  13943. '\u3359': '\u0031\u70B9',
  13944. '\u335A': '\u0032\u70B9',
  13945. '\u335B': '\u0033\u70B9',
  13946. '\u335C': '\u0034\u70B9',
  13947. '\u335D': '\u0035\u70B9',
  13948. '\u335E': '\u0036\u70B9',
  13949. '\u335F': '\u0037\u70B9',
  13950. '\u3360': '\u0038\u70B9',
  13951. '\u3361': '\u0039\u70B9',
  13952. '\u3362': '\u0031\u0030\u70B9',
  13953. '\u3363': '\u0031\u0031\u70B9',
  13954. '\u3364': '\u0031\u0032\u70B9',
  13955. '\u3365': '\u0031\u0033\u70B9',
  13956. '\u3366': '\u0031\u0034\u70B9',
  13957. '\u3367': '\u0031\u0035\u70B9',
  13958. '\u3368': '\u0031\u0036\u70B9',
  13959. '\u3369': '\u0031\u0037\u70B9',
  13960. '\u336A': '\u0031\u0038\u70B9',
  13961. '\u336B': '\u0031\u0039\u70B9',
  13962. '\u336C': '\u0032\u0030\u70B9',
  13963. '\u336D': '\u0032\u0031\u70B9',
  13964. '\u336E': '\u0032\u0032\u70B9',
  13965. '\u336F': '\u0032\u0033\u70B9',
  13966. '\u3370': '\u0032\u0034\u70B9',
  13967. '\u33E0': '\u0031\u65E5',
  13968. '\u33E1': '\u0032\u65E5',
  13969. '\u33E2': '\u0033\u65E5',
  13970. '\u33E3': '\u0034\u65E5',
  13971. '\u33E4': '\u0035\u65E5',
  13972. '\u33E5': '\u0036\u65E5',
  13973. '\u33E6': '\u0037\u65E5',
  13974. '\u33E7': '\u0038\u65E5',
  13975. '\u33E8': '\u0039\u65E5',
  13976. '\u33E9': '\u0031\u0030\u65E5',
  13977. '\u33EA': '\u0031\u0031\u65E5',
  13978. '\u33EB': '\u0031\u0032\u65E5',
  13979. '\u33EC': '\u0031\u0033\u65E5',
  13980. '\u33ED': '\u0031\u0034\u65E5',
  13981. '\u33EE': '\u0031\u0035\u65E5',
  13982. '\u33EF': '\u0031\u0036\u65E5',
  13983. '\u33F0': '\u0031\u0037\u65E5',
  13984. '\u33F1': '\u0031\u0038\u65E5',
  13985. '\u33F2': '\u0031\u0039\u65E5',
  13986. '\u33F3': '\u0032\u0030\u65E5',
  13987. '\u33F4': '\u0032\u0031\u65E5',
  13988. '\u33F5': '\u0032\u0032\u65E5',
  13989. '\u33F6': '\u0032\u0033\u65E5',
  13990. '\u33F7': '\u0032\u0034\u65E5',
  13991. '\u33F8': '\u0032\u0035\u65E5',
  13992. '\u33F9': '\u0032\u0036\u65E5',
  13993. '\u33FA': '\u0032\u0037\u65E5',
  13994. '\u33FB': '\u0032\u0038\u65E5',
  13995. '\u33FC': '\u0032\u0039\u65E5',
  13996. '\u33FD': '\u0033\u0030\u65E5',
  13997. '\u33FE': '\u0033\u0031\u65E5',
  13998. '\uFB00': '\u0066\u0066',
  13999. '\uFB01': '\u0066\u0069',
  14000. '\uFB02': '\u0066\u006C',
  14001. '\uFB03': '\u0066\u0066\u0069',
  14002. '\uFB04': '\u0066\u0066\u006C',
  14003. '\uFB05': '\u017F\u0074',
  14004. '\uFB06': '\u0073\u0074',
  14005. '\uFB13': '\u0574\u0576',
  14006. '\uFB14': '\u0574\u0565',
  14007. '\uFB15': '\u0574\u056B',
  14008. '\uFB16': '\u057E\u0576',
  14009. '\uFB17': '\u0574\u056D',
  14010. '\uFB4F': '\u05D0\u05DC',
  14011. '\uFB50': '\u0671',
  14012. '\uFB51': '\u0671',
  14013. '\uFB52': '\u067B',
  14014. '\uFB53': '\u067B',
  14015. '\uFB54': '\u067B',
  14016. '\uFB55': '\u067B',
  14017. '\uFB56': '\u067E',
  14018. '\uFB57': '\u067E',
  14019. '\uFB58': '\u067E',
  14020. '\uFB59': '\u067E',
  14021. '\uFB5A': '\u0680',
  14022. '\uFB5B': '\u0680',
  14023. '\uFB5C': '\u0680',
  14024. '\uFB5D': '\u0680',
  14025. '\uFB5E': '\u067A',
  14026. '\uFB5F': '\u067A',
  14027. '\uFB60': '\u067A',
  14028. '\uFB61': '\u067A',
  14029. '\uFB62': '\u067F',
  14030. '\uFB63': '\u067F',
  14031. '\uFB64': '\u067F',
  14032. '\uFB65': '\u067F',
  14033. '\uFB66': '\u0679',
  14034. '\uFB67': '\u0679',
  14035. '\uFB68': '\u0679',
  14036. '\uFB69': '\u0679',
  14037. '\uFB6A': '\u06A4',
  14038. '\uFB6B': '\u06A4',
  14039. '\uFB6C': '\u06A4',
  14040. '\uFB6D': '\u06A4',
  14041. '\uFB6E': '\u06A6',
  14042. '\uFB6F': '\u06A6',
  14043. '\uFB70': '\u06A6',
  14044. '\uFB71': '\u06A6',
  14045. '\uFB72': '\u0684',
  14046. '\uFB73': '\u0684',
  14047. '\uFB74': '\u0684',
  14048. '\uFB75': '\u0684',
  14049. '\uFB76': '\u0683',
  14050. '\uFB77': '\u0683',
  14051. '\uFB78': '\u0683',
  14052. '\uFB79': '\u0683',
  14053. '\uFB7A': '\u0686',
  14054. '\uFB7B': '\u0686',
  14055. '\uFB7C': '\u0686',
  14056. '\uFB7D': '\u0686',
  14057. '\uFB7E': '\u0687',
  14058. '\uFB7F': '\u0687',
  14059. '\uFB80': '\u0687',
  14060. '\uFB81': '\u0687',
  14061. '\uFB82': '\u068D',
  14062. '\uFB83': '\u068D',
  14063. '\uFB84': '\u068C',
  14064. '\uFB85': '\u068C',
  14065. '\uFB86': '\u068E',
  14066. '\uFB87': '\u068E',
  14067. '\uFB88': '\u0688',
  14068. '\uFB89': '\u0688',
  14069. '\uFB8A': '\u0698',
  14070. '\uFB8B': '\u0698',
  14071. '\uFB8C': '\u0691',
  14072. '\uFB8D': '\u0691',
  14073. '\uFB8E': '\u06A9',
  14074. '\uFB8F': '\u06A9',
  14075. '\uFB90': '\u06A9',
  14076. '\uFB91': '\u06A9',
  14077. '\uFB92': '\u06AF',
  14078. '\uFB93': '\u06AF',
  14079. '\uFB94': '\u06AF',
  14080. '\uFB95': '\u06AF',
  14081. '\uFB96': '\u06B3',
  14082. '\uFB97': '\u06B3',
  14083. '\uFB98': '\u06B3',
  14084. '\uFB99': '\u06B3',
  14085. '\uFB9A': '\u06B1',
  14086. '\uFB9B': '\u06B1',
  14087. '\uFB9C': '\u06B1',
  14088. '\uFB9D': '\u06B1',
  14089. '\uFB9E': '\u06BA',
  14090. '\uFB9F': '\u06BA',
  14091. '\uFBA0': '\u06BB',
  14092. '\uFBA1': '\u06BB',
  14093. '\uFBA2': '\u06BB',
  14094. '\uFBA3': '\u06BB',
  14095. '\uFBA4': '\u06C0',
  14096. '\uFBA5': '\u06C0',
  14097. '\uFBA6': '\u06C1',
  14098. '\uFBA7': '\u06C1',
  14099. '\uFBA8': '\u06C1',
  14100. '\uFBA9': '\u06C1',
  14101. '\uFBAA': '\u06BE',
  14102. '\uFBAB': '\u06BE',
  14103. '\uFBAC': '\u06BE',
  14104. '\uFBAD': '\u06BE',
  14105. '\uFBAE': '\u06D2',
  14106. '\uFBAF': '\u06D2',
  14107. '\uFBB0': '\u06D3',
  14108. '\uFBB1': '\u06D3',
  14109. '\uFBD3': '\u06AD',
  14110. '\uFBD4': '\u06AD',
  14111. '\uFBD5': '\u06AD',
  14112. '\uFBD6': '\u06AD',
  14113. '\uFBD7': '\u06C7',
  14114. '\uFBD8': '\u06C7',
  14115. '\uFBD9': '\u06C6',
  14116. '\uFBDA': '\u06C6',
  14117. '\uFBDB': '\u06C8',
  14118. '\uFBDC': '\u06C8',
  14119. '\uFBDD': '\u0677',
  14120. '\uFBDE': '\u06CB',
  14121. '\uFBDF': '\u06CB',
  14122. '\uFBE0': '\u06C5',
  14123. '\uFBE1': '\u06C5',
  14124. '\uFBE2': '\u06C9',
  14125. '\uFBE3': '\u06C9',
  14126. '\uFBE4': '\u06D0',
  14127. '\uFBE5': '\u06D0',
  14128. '\uFBE6': '\u06D0',
  14129. '\uFBE7': '\u06D0',
  14130. '\uFBE8': '\u0649',
  14131. '\uFBE9': '\u0649',
  14132. '\uFBEA': '\u0626\u0627',
  14133. '\uFBEB': '\u0626\u0627',
  14134. '\uFBEC': '\u0626\u06D5',
  14135. '\uFBED': '\u0626\u06D5',
  14136. '\uFBEE': '\u0626\u0648',
  14137. '\uFBEF': '\u0626\u0648',
  14138. '\uFBF0': '\u0626\u06C7',
  14139. '\uFBF1': '\u0626\u06C7',
  14140. '\uFBF2': '\u0626\u06C6',
  14141. '\uFBF3': '\u0626\u06C6',
  14142. '\uFBF4': '\u0626\u06C8',
  14143. '\uFBF5': '\u0626\u06C8',
  14144. '\uFBF6': '\u0626\u06D0',
  14145. '\uFBF7': '\u0626\u06D0',
  14146. '\uFBF8': '\u0626\u06D0',
  14147. '\uFBF9': '\u0626\u0649',
  14148. '\uFBFA': '\u0626\u0649',
  14149. '\uFBFB': '\u0626\u0649',
  14150. '\uFBFC': '\u06CC',
  14151. '\uFBFD': '\u06CC',
  14152. '\uFBFE': '\u06CC',
  14153. '\uFBFF': '\u06CC',
  14154. '\uFC00': '\u0626\u062C',
  14155. '\uFC01': '\u0626\u062D',
  14156. '\uFC02': '\u0626\u0645',
  14157. '\uFC03': '\u0626\u0649',
  14158. '\uFC04': '\u0626\u064A',
  14159. '\uFC05': '\u0628\u062C',
  14160. '\uFC06': '\u0628\u062D',
  14161. '\uFC07': '\u0628\u062E',
  14162. '\uFC08': '\u0628\u0645',
  14163. '\uFC09': '\u0628\u0649',
  14164. '\uFC0A': '\u0628\u064A',
  14165. '\uFC0B': '\u062A\u062C',
  14166. '\uFC0C': '\u062A\u062D',
  14167. '\uFC0D': '\u062A\u062E',
  14168. '\uFC0E': '\u062A\u0645',
  14169. '\uFC0F': '\u062A\u0649',
  14170. '\uFC10': '\u062A\u064A',
  14171. '\uFC11': '\u062B\u062C',
  14172. '\uFC12': '\u062B\u0645',
  14173. '\uFC13': '\u062B\u0649',
  14174. '\uFC14': '\u062B\u064A',
  14175. '\uFC15': '\u062C\u062D',
  14176. '\uFC16': '\u062C\u0645',
  14177. '\uFC17': '\u062D\u062C',
  14178. '\uFC18': '\u062D\u0645',
  14179. '\uFC19': '\u062E\u062C',
  14180. '\uFC1A': '\u062E\u062D',
  14181. '\uFC1B': '\u062E\u0645',
  14182. '\uFC1C': '\u0633\u062C',
  14183. '\uFC1D': '\u0633\u062D',
  14184. '\uFC1E': '\u0633\u062E',
  14185. '\uFC1F': '\u0633\u0645',
  14186. '\uFC20': '\u0635\u062D',
  14187. '\uFC21': '\u0635\u0645',
  14188. '\uFC22': '\u0636\u062C',
  14189. '\uFC23': '\u0636\u062D',
  14190. '\uFC24': '\u0636\u062E',
  14191. '\uFC25': '\u0636\u0645',
  14192. '\uFC26': '\u0637\u062D',
  14193. '\uFC27': '\u0637\u0645',
  14194. '\uFC28': '\u0638\u0645',
  14195. '\uFC29': '\u0639\u062C',
  14196. '\uFC2A': '\u0639\u0645',
  14197. '\uFC2B': '\u063A\u062C',
  14198. '\uFC2C': '\u063A\u0645',
  14199. '\uFC2D': '\u0641\u062C',
  14200. '\uFC2E': '\u0641\u062D',
  14201. '\uFC2F': '\u0641\u062E',
  14202. '\uFC30': '\u0641\u0645',
  14203. '\uFC31': '\u0641\u0649',
  14204. '\uFC32': '\u0641\u064A',
  14205. '\uFC33': '\u0642\u062D',
  14206. '\uFC34': '\u0642\u0645',
  14207. '\uFC35': '\u0642\u0649',
  14208. '\uFC36': '\u0642\u064A',
  14209. '\uFC37': '\u0643\u0627',
  14210. '\uFC38': '\u0643\u062C',
  14211. '\uFC39': '\u0643\u062D',
  14212. '\uFC3A': '\u0643\u062E',
  14213. '\uFC3B': '\u0643\u0644',
  14214. '\uFC3C': '\u0643\u0645',
  14215. '\uFC3D': '\u0643\u0649',
  14216. '\uFC3E': '\u0643\u064A',
  14217. '\uFC3F': '\u0644\u062C',
  14218. '\uFC40': '\u0644\u062D',
  14219. '\uFC41': '\u0644\u062E',
  14220. '\uFC42': '\u0644\u0645',
  14221. '\uFC43': '\u0644\u0649',
  14222. '\uFC44': '\u0644\u064A',
  14223. '\uFC45': '\u0645\u062C',
  14224. '\uFC46': '\u0645\u062D',
  14225. '\uFC47': '\u0645\u062E',
  14226. '\uFC48': '\u0645\u0645',
  14227. '\uFC49': '\u0645\u0649',
  14228. '\uFC4A': '\u0645\u064A',
  14229. '\uFC4B': '\u0646\u062C',
  14230. '\uFC4C': '\u0646\u062D',
  14231. '\uFC4D': '\u0646\u062E',
  14232. '\uFC4E': '\u0646\u0645',
  14233. '\uFC4F': '\u0646\u0649',
  14234. '\uFC50': '\u0646\u064A',
  14235. '\uFC51': '\u0647\u062C',
  14236. '\uFC52': '\u0647\u0645',
  14237. '\uFC53': '\u0647\u0649',
  14238. '\uFC54': '\u0647\u064A',
  14239. '\uFC55': '\u064A\u062C',
  14240. '\uFC56': '\u064A\u062D',
  14241. '\uFC57': '\u064A\u062E',
  14242. '\uFC58': '\u064A\u0645',
  14243. '\uFC59': '\u064A\u0649',
  14244. '\uFC5A': '\u064A\u064A',
  14245. '\uFC5B': '\u0630\u0670',
  14246. '\uFC5C': '\u0631\u0670',
  14247. '\uFC5D': '\u0649\u0670',
  14248. '\uFC5E': '\u0020\u064C\u0651',
  14249. '\uFC5F': '\u0020\u064D\u0651',
  14250. '\uFC60': '\u0020\u064E\u0651',
  14251. '\uFC61': '\u0020\u064F\u0651',
  14252. '\uFC62': '\u0020\u0650\u0651',
  14253. '\uFC63': '\u0020\u0651\u0670',
  14254. '\uFC64': '\u0626\u0631',
  14255. '\uFC65': '\u0626\u0632',
  14256. '\uFC66': '\u0626\u0645',
  14257. '\uFC67': '\u0626\u0646',
  14258. '\uFC68': '\u0626\u0649',
  14259. '\uFC69': '\u0626\u064A',
  14260. '\uFC6A': '\u0628\u0631',
  14261. '\uFC6B': '\u0628\u0632',
  14262. '\uFC6C': '\u0628\u0645',
  14263. '\uFC6D': '\u0628\u0646',
  14264. '\uFC6E': '\u0628\u0649',
  14265. '\uFC6F': '\u0628\u064A',
  14266. '\uFC70': '\u062A\u0631',
  14267. '\uFC71': '\u062A\u0632',
  14268. '\uFC72': '\u062A\u0645',
  14269. '\uFC73': '\u062A\u0646',
  14270. '\uFC74': '\u062A\u0649',
  14271. '\uFC75': '\u062A\u064A',
  14272. '\uFC76': '\u062B\u0631',
  14273. '\uFC77': '\u062B\u0632',
  14274. '\uFC78': '\u062B\u0645',
  14275. '\uFC79': '\u062B\u0646',
  14276. '\uFC7A': '\u062B\u0649',
  14277. '\uFC7B': '\u062B\u064A',
  14278. '\uFC7C': '\u0641\u0649',
  14279. '\uFC7D': '\u0641\u064A',
  14280. '\uFC7E': '\u0642\u0649',
  14281. '\uFC7F': '\u0642\u064A',
  14282. '\uFC80': '\u0643\u0627',
  14283. '\uFC81': '\u0643\u0644',
  14284. '\uFC82': '\u0643\u0645',
  14285. '\uFC83': '\u0643\u0649',
  14286. '\uFC84': '\u0643\u064A',
  14287. '\uFC85': '\u0644\u0645',
  14288. '\uFC86': '\u0644\u0649',
  14289. '\uFC87': '\u0644\u064A',
  14290. '\uFC88': '\u0645\u0627',
  14291. '\uFC89': '\u0645\u0645',
  14292. '\uFC8A': '\u0646\u0631',
  14293. '\uFC8B': '\u0646\u0632',
  14294. '\uFC8C': '\u0646\u0645',
  14295. '\uFC8D': '\u0646\u0646',
  14296. '\uFC8E': '\u0646\u0649',
  14297. '\uFC8F': '\u0646\u064A',
  14298. '\uFC90': '\u0649\u0670',
  14299. '\uFC91': '\u064A\u0631',
  14300. '\uFC92': '\u064A\u0632',
  14301. '\uFC93': '\u064A\u0645',
  14302. '\uFC94': '\u064A\u0646',
  14303. '\uFC95': '\u064A\u0649',
  14304. '\uFC96': '\u064A\u064A',
  14305. '\uFC97': '\u0626\u062C',
  14306. '\uFC98': '\u0626\u062D',
  14307. '\uFC99': '\u0626\u062E',
  14308. '\uFC9A': '\u0626\u0645',
  14309. '\uFC9B': '\u0626\u0647',
  14310. '\uFC9C': '\u0628\u062C',
  14311. '\uFC9D': '\u0628\u062D',
  14312. '\uFC9E': '\u0628\u062E',
  14313. '\uFC9F': '\u0628\u0645',
  14314. '\uFCA0': '\u0628\u0647',
  14315. '\uFCA1': '\u062A\u062C',
  14316. '\uFCA2': '\u062A\u062D',
  14317. '\uFCA3': '\u062A\u062E',
  14318. '\uFCA4': '\u062A\u0645',
  14319. '\uFCA5': '\u062A\u0647',
  14320. '\uFCA6': '\u062B\u0645',
  14321. '\uFCA7': '\u062C\u062D',
  14322. '\uFCA8': '\u062C\u0645',
  14323. '\uFCA9': '\u062D\u062C',
  14324. '\uFCAA': '\u062D\u0645',
  14325. '\uFCAB': '\u062E\u062C',
  14326. '\uFCAC': '\u062E\u0645',
  14327. '\uFCAD': '\u0633\u062C',
  14328. '\uFCAE': '\u0633\u062D',
  14329. '\uFCAF': '\u0633\u062E',
  14330. '\uFCB0': '\u0633\u0645',
  14331. '\uFCB1': '\u0635\u062D',
  14332. '\uFCB2': '\u0635\u062E',
  14333. '\uFCB3': '\u0635\u0645',
  14334. '\uFCB4': '\u0636\u062C',
  14335. '\uFCB5': '\u0636\u062D',
  14336. '\uFCB6': '\u0636\u062E',
  14337. '\uFCB7': '\u0636\u0645',
  14338. '\uFCB8': '\u0637\u062D',
  14339. '\uFCB9': '\u0638\u0645',
  14340. '\uFCBA': '\u0639\u062C',
  14341. '\uFCBB': '\u0639\u0645',
  14342. '\uFCBC': '\u063A\u062C',
  14343. '\uFCBD': '\u063A\u0645',
  14344. '\uFCBE': '\u0641\u062C',
  14345. '\uFCBF': '\u0641\u062D',
  14346. '\uFCC0': '\u0641\u062E',
  14347. '\uFCC1': '\u0641\u0645',
  14348. '\uFCC2': '\u0642\u062D',
  14349. '\uFCC3': '\u0642\u0645',
  14350. '\uFCC4': '\u0643\u062C',
  14351. '\uFCC5': '\u0643\u062D',
  14352. '\uFCC6': '\u0643\u062E',
  14353. '\uFCC7': '\u0643\u0644',
  14354. '\uFCC8': '\u0643\u0645',
  14355. '\uFCC9': '\u0644\u062C',
  14356. '\uFCCA': '\u0644\u062D',
  14357. '\uFCCB': '\u0644\u062E',
  14358. '\uFCCC': '\u0644\u0645',
  14359. '\uFCCD': '\u0644\u0647',
  14360. '\uFCCE': '\u0645\u062C',
  14361. '\uFCCF': '\u0645\u062D',
  14362. '\uFCD0': '\u0645\u062E',
  14363. '\uFCD1': '\u0645\u0645',
  14364. '\uFCD2': '\u0646\u062C',
  14365. '\uFCD3': '\u0646\u062D',
  14366. '\uFCD4': '\u0646\u062E',
  14367. '\uFCD5': '\u0646\u0645',
  14368. '\uFCD6': '\u0646\u0647',
  14369. '\uFCD7': '\u0647\u062C',
  14370. '\uFCD8': '\u0647\u0645',
  14371. '\uFCD9': '\u0647\u0670',
  14372. '\uFCDA': '\u064A\u062C',
  14373. '\uFCDB': '\u064A\u062D',
  14374. '\uFCDC': '\u064A\u062E',
  14375. '\uFCDD': '\u064A\u0645',
  14376. '\uFCDE': '\u064A\u0647',
  14377. '\uFCDF': '\u0626\u0645',
  14378. '\uFCE0': '\u0626\u0647',
  14379. '\uFCE1': '\u0628\u0645',
  14380. '\uFCE2': '\u0628\u0647',
  14381. '\uFCE3': '\u062A\u0645',
  14382. '\uFCE4': '\u062A\u0647',
  14383. '\uFCE5': '\u062B\u0645',
  14384. '\uFCE6': '\u062B\u0647',
  14385. '\uFCE7': '\u0633\u0645',
  14386. '\uFCE8': '\u0633\u0647',
  14387. '\uFCE9': '\u0634\u0645',
  14388. '\uFCEA': '\u0634\u0647',
  14389. '\uFCEB': '\u0643\u0644',
  14390. '\uFCEC': '\u0643\u0645',
  14391. '\uFCED': '\u0644\u0645',
  14392. '\uFCEE': '\u0646\u0645',
  14393. '\uFCEF': '\u0646\u0647',
  14394. '\uFCF0': '\u064A\u0645',
  14395. '\uFCF1': '\u064A\u0647',
  14396. '\uFCF2': '\u0640\u064E\u0651',
  14397. '\uFCF3': '\u0640\u064F\u0651',
  14398. '\uFCF4': '\u0640\u0650\u0651',
  14399. '\uFCF5': '\u0637\u0649',
  14400. '\uFCF6': '\u0637\u064A',
  14401. '\uFCF7': '\u0639\u0649',
  14402. '\uFCF8': '\u0639\u064A',
  14403. '\uFCF9': '\u063A\u0649',
  14404. '\uFCFA': '\u063A\u064A',
  14405. '\uFCFB': '\u0633\u0649',
  14406. '\uFCFC': '\u0633\u064A',
  14407. '\uFCFD': '\u0634\u0649',
  14408. '\uFCFE': '\u0634\u064A',
  14409. '\uFCFF': '\u062D\u0649',
  14410. '\uFD00': '\u062D\u064A',
  14411. '\uFD01': '\u062C\u0649',
  14412. '\uFD02': '\u062C\u064A',
  14413. '\uFD03': '\u062E\u0649',
  14414. '\uFD04': '\u062E\u064A',
  14415. '\uFD05': '\u0635\u0649',
  14416. '\uFD06': '\u0635\u064A',
  14417. '\uFD07': '\u0636\u0649',
  14418. '\uFD08': '\u0636\u064A',
  14419. '\uFD09': '\u0634\u062C',
  14420. '\uFD0A': '\u0634\u062D',
  14421. '\uFD0B': '\u0634\u062E',
  14422. '\uFD0C': '\u0634\u0645',
  14423. '\uFD0D': '\u0634\u0631',
  14424. '\uFD0E': '\u0633\u0631',
  14425. '\uFD0F': '\u0635\u0631',
  14426. '\uFD10': '\u0636\u0631',
  14427. '\uFD11': '\u0637\u0649',
  14428. '\uFD12': '\u0637\u064A',
  14429. '\uFD13': '\u0639\u0649',
  14430. '\uFD14': '\u0639\u064A',
  14431. '\uFD15': '\u063A\u0649',
  14432. '\uFD16': '\u063A\u064A',
  14433. '\uFD17': '\u0633\u0649',
  14434. '\uFD18': '\u0633\u064A',
  14435. '\uFD19': '\u0634\u0649',
  14436. '\uFD1A': '\u0634\u064A',
  14437. '\uFD1B': '\u062D\u0649',
  14438. '\uFD1C': '\u062D\u064A',
  14439. '\uFD1D': '\u062C\u0649',
  14440. '\uFD1E': '\u062C\u064A',
  14441. '\uFD1F': '\u062E\u0649',
  14442. '\uFD20': '\u062E\u064A',
  14443. '\uFD21': '\u0635\u0649',
  14444. '\uFD22': '\u0635\u064A',
  14445. '\uFD23': '\u0636\u0649',
  14446. '\uFD24': '\u0636\u064A',
  14447. '\uFD25': '\u0634\u062C',
  14448. '\uFD26': '\u0634\u062D',
  14449. '\uFD27': '\u0634\u062E',
  14450. '\uFD28': '\u0634\u0645',
  14451. '\uFD29': '\u0634\u0631',
  14452. '\uFD2A': '\u0633\u0631',
  14453. '\uFD2B': '\u0635\u0631',
  14454. '\uFD2C': '\u0636\u0631',
  14455. '\uFD2D': '\u0634\u062C',
  14456. '\uFD2E': '\u0634\u062D',
  14457. '\uFD2F': '\u0634\u062E',
  14458. '\uFD30': '\u0634\u0645',
  14459. '\uFD31': '\u0633\u0647',
  14460. '\uFD32': '\u0634\u0647',
  14461. '\uFD33': '\u0637\u0645',
  14462. '\uFD34': '\u0633\u062C',
  14463. '\uFD35': '\u0633\u062D',
  14464. '\uFD36': '\u0633\u062E',
  14465. '\uFD37': '\u0634\u062C',
  14466. '\uFD38': '\u0634\u062D',
  14467. '\uFD39': '\u0634\u062E',
  14468. '\uFD3A': '\u0637\u0645',
  14469. '\uFD3B': '\u0638\u0645',
  14470. '\uFD3C': '\u0627\u064B',
  14471. '\uFD3D': '\u0627\u064B',
  14472. '\uFD50': '\u062A\u062C\u0645',
  14473. '\uFD51': '\u062A\u062D\u062C',
  14474. '\uFD52': '\u062A\u062D\u062C',
  14475. '\uFD53': '\u062A\u062D\u0645',
  14476. '\uFD54': '\u062A\u062E\u0645',
  14477. '\uFD55': '\u062A\u0645\u062C',
  14478. '\uFD56': '\u062A\u0645\u062D',
  14479. '\uFD57': '\u062A\u0645\u062E',
  14480. '\uFD58': '\u062C\u0645\u062D',
  14481. '\uFD59': '\u062C\u0645\u062D',
  14482. '\uFD5A': '\u062D\u0645\u064A',
  14483. '\uFD5B': '\u062D\u0645\u0649',
  14484. '\uFD5C': '\u0633\u062D\u062C',
  14485. '\uFD5D': '\u0633\u062C\u062D',
  14486. '\uFD5E': '\u0633\u062C\u0649',
  14487. '\uFD5F': '\u0633\u0645\u062D',
  14488. '\uFD60': '\u0633\u0645\u062D',
  14489. '\uFD61': '\u0633\u0645\u062C',
  14490. '\uFD62': '\u0633\u0645\u0645',
  14491. '\uFD63': '\u0633\u0645\u0645',
  14492. '\uFD64': '\u0635\u062D\u062D',
  14493. '\uFD65': '\u0635\u062D\u062D',
  14494. '\uFD66': '\u0635\u0645\u0645',
  14495. '\uFD67': '\u0634\u062D\u0645',
  14496. '\uFD68': '\u0634\u062D\u0645',
  14497. '\uFD69': '\u0634\u062C\u064A',
  14498. '\uFD6A': '\u0634\u0645\u062E',
  14499. '\uFD6B': '\u0634\u0645\u062E',
  14500. '\uFD6C': '\u0634\u0645\u0645',
  14501. '\uFD6D': '\u0634\u0645\u0645',
  14502. '\uFD6E': '\u0636\u062D\u0649',
  14503. '\uFD6F': '\u0636\u062E\u0645',
  14504. '\uFD70': '\u0636\u062E\u0645',
  14505. '\uFD71': '\u0637\u0645\u062D',
  14506. '\uFD72': '\u0637\u0645\u062D',
  14507. '\uFD73': '\u0637\u0645\u0645',
  14508. '\uFD74': '\u0637\u0645\u064A',
  14509. '\uFD75': '\u0639\u062C\u0645',
  14510. '\uFD76': '\u0639\u0645\u0645',
  14511. '\uFD77': '\u0639\u0645\u0645',
  14512. '\uFD78': '\u0639\u0645\u0649',
  14513. '\uFD79': '\u063A\u0645\u0645',
  14514. '\uFD7A': '\u063A\u0645\u064A',
  14515. '\uFD7B': '\u063A\u0645\u0649',
  14516. '\uFD7C': '\u0641\u062E\u0645',
  14517. '\uFD7D': '\u0641\u062E\u0645',
  14518. '\uFD7E': '\u0642\u0645\u062D',
  14519. '\uFD7F': '\u0642\u0645\u0645',
  14520. '\uFD80': '\u0644\u062D\u0645',
  14521. '\uFD81': '\u0644\u062D\u064A',
  14522. '\uFD82': '\u0644\u062D\u0649',
  14523. '\uFD83': '\u0644\u062C\u062C',
  14524. '\uFD84': '\u0644\u062C\u062C',
  14525. '\uFD85': '\u0644\u062E\u0645',
  14526. '\uFD86': '\u0644\u062E\u0645',
  14527. '\uFD87': '\u0644\u0645\u062D',
  14528. '\uFD88': '\u0644\u0645\u062D',
  14529. '\uFD89': '\u0645\u062D\u062C',
  14530. '\uFD8A': '\u0645\u062D\u0645',
  14531. '\uFD8B': '\u0645\u062D\u064A',
  14532. '\uFD8C': '\u0645\u062C\u062D',
  14533. '\uFD8D': '\u0645\u062C\u0645',
  14534. '\uFD8E': '\u0645\u062E\u062C',
  14535. '\uFD8F': '\u0645\u062E\u0645',
  14536. '\uFD92': '\u0645\u062C\u062E',
  14537. '\uFD93': '\u0647\u0645\u062C',
  14538. '\uFD94': '\u0647\u0645\u0645',
  14539. '\uFD95': '\u0646\u062D\u0645',
  14540. '\uFD96': '\u0646\u062D\u0649',
  14541. '\uFD97': '\u0646\u062C\u0645',
  14542. '\uFD98': '\u0646\u062C\u0645',
  14543. '\uFD99': '\u0646\u062C\u0649',
  14544. '\uFD9A': '\u0646\u0645\u064A',
  14545. '\uFD9B': '\u0646\u0645\u0649',
  14546. '\uFD9C': '\u064A\u0645\u0645',
  14547. '\uFD9D': '\u064A\u0645\u0645',
  14548. '\uFD9E': '\u0628\u062E\u064A',
  14549. '\uFD9F': '\u062A\u062C\u064A',
  14550. '\uFDA0': '\u062A\u062C\u0649',
  14551. '\uFDA1': '\u062A\u062E\u064A',
  14552. '\uFDA2': '\u062A\u062E\u0649',
  14553. '\uFDA3': '\u062A\u0645\u064A',
  14554. '\uFDA4': '\u062A\u0645\u0649',
  14555. '\uFDA5': '\u062C\u0645\u064A',
  14556. '\uFDA6': '\u062C\u062D\u0649',
  14557. '\uFDA7': '\u062C\u0645\u0649',
  14558. '\uFDA8': '\u0633\u062E\u0649',
  14559. '\uFDA9': '\u0635\u062D\u064A',
  14560. '\uFDAA': '\u0634\u062D\u064A',
  14561. '\uFDAB': '\u0636\u062D\u064A',
  14562. '\uFDAC': '\u0644\u062C\u064A',
  14563. '\uFDAD': '\u0644\u0645\u064A',
  14564. '\uFDAE': '\u064A\u062D\u064A',
  14565. '\uFDAF': '\u064A\u062C\u064A',
  14566. '\uFDB0': '\u064A\u0645\u064A',
  14567. '\uFDB1': '\u0645\u0645\u064A',
  14568. '\uFDB2': '\u0642\u0645\u064A',
  14569. '\uFDB3': '\u0646\u062D\u064A',
  14570. '\uFDB4': '\u0642\u0645\u062D',
  14571. '\uFDB5': '\u0644\u062D\u0645',
  14572. '\uFDB6': '\u0639\u0645\u064A',
  14573. '\uFDB7': '\u0643\u0645\u064A',
  14574. '\uFDB8': '\u0646\u062C\u062D',
  14575. '\uFDB9': '\u0645\u062E\u064A',
  14576. '\uFDBA': '\u0644\u062C\u0645',
  14577. '\uFDBB': '\u0643\u0645\u0645',
  14578. '\uFDBC': '\u0644\u062C\u0645',
  14579. '\uFDBD': '\u0646\u062C\u062D',
  14580. '\uFDBE': '\u062C\u062D\u064A',
  14581. '\uFDBF': '\u062D\u062C\u064A',
  14582. '\uFDC0': '\u0645\u062C\u064A',
  14583. '\uFDC1': '\u0641\u0645\u064A',
  14584. '\uFDC2': '\u0628\u062D\u064A',
  14585. '\uFDC3': '\u0643\u0645\u0645',
  14586. '\uFDC4': '\u0639\u062C\u0645',
  14587. '\uFDC5': '\u0635\u0645\u0645',
  14588. '\uFDC6': '\u0633\u062E\u064A',
  14589. '\uFDC7': '\u0646\u062C\u064A',
  14590. '\uFE49': '\u203E',
  14591. '\uFE4A': '\u203E',
  14592. '\uFE4B': '\u203E',
  14593. '\uFE4C': '\u203E',
  14594. '\uFE4D': '\u005F',
  14595. '\uFE4E': '\u005F',
  14596. '\uFE4F': '\u005F',
  14597. '\uFE80': '\u0621',
  14598. '\uFE81': '\u0622',
  14599. '\uFE82': '\u0622',
  14600. '\uFE83': '\u0623',
  14601. '\uFE84': '\u0623',
  14602. '\uFE85': '\u0624',
  14603. '\uFE86': '\u0624',
  14604. '\uFE87': '\u0625',
  14605. '\uFE88': '\u0625',
  14606. '\uFE89': '\u0626',
  14607. '\uFE8A': '\u0626',
  14608. '\uFE8B': '\u0626',
  14609. '\uFE8C': '\u0626',
  14610. '\uFE8D': '\u0627',
  14611. '\uFE8E': '\u0627',
  14612. '\uFE8F': '\u0628',
  14613. '\uFE90': '\u0628',
  14614. '\uFE91': '\u0628',
  14615. '\uFE92': '\u0628',
  14616. '\uFE93': '\u0629',
  14617. '\uFE94': '\u0629',
  14618. '\uFE95': '\u062A',
  14619. '\uFE96': '\u062A',
  14620. '\uFE97': '\u062A',
  14621. '\uFE98': '\u062A',
  14622. '\uFE99': '\u062B',
  14623. '\uFE9A': '\u062B',
  14624. '\uFE9B': '\u062B',
  14625. '\uFE9C': '\u062B',
  14626. '\uFE9D': '\u062C',
  14627. '\uFE9E': '\u062C',
  14628. '\uFE9F': '\u062C',
  14629. '\uFEA0': '\u062C',
  14630. '\uFEA1': '\u062D',
  14631. '\uFEA2': '\u062D',
  14632. '\uFEA3': '\u062D',
  14633. '\uFEA4': '\u062D',
  14634. '\uFEA5': '\u062E',
  14635. '\uFEA6': '\u062E',
  14636. '\uFEA7': '\u062E',
  14637. '\uFEA8': '\u062E',
  14638. '\uFEA9': '\u062F',
  14639. '\uFEAA': '\u062F',
  14640. '\uFEAB': '\u0630',
  14641. '\uFEAC': '\u0630',
  14642. '\uFEAD': '\u0631',
  14643. '\uFEAE': '\u0631',
  14644. '\uFEAF': '\u0632',
  14645. '\uFEB0': '\u0632',
  14646. '\uFEB1': '\u0633',
  14647. '\uFEB2': '\u0633',
  14648. '\uFEB3': '\u0633',
  14649. '\uFEB4': '\u0633',
  14650. '\uFEB5': '\u0634',
  14651. '\uFEB6': '\u0634',
  14652. '\uFEB7': '\u0634',
  14653. '\uFEB8': '\u0634',
  14654. '\uFEB9': '\u0635',
  14655. '\uFEBA': '\u0635',
  14656. '\uFEBB': '\u0635',
  14657. '\uFEBC': '\u0635',
  14658. '\uFEBD': '\u0636',
  14659. '\uFEBE': '\u0636',
  14660. '\uFEBF': '\u0636',
  14661. '\uFEC0': '\u0636',
  14662. '\uFEC1': '\u0637',
  14663. '\uFEC2': '\u0637',
  14664. '\uFEC3': '\u0637',
  14665. '\uFEC4': '\u0637',
  14666. '\uFEC5': '\u0638',
  14667. '\uFEC6': '\u0638',
  14668. '\uFEC7': '\u0638',
  14669. '\uFEC8': '\u0638',
  14670. '\uFEC9': '\u0639',
  14671. '\uFECA': '\u0639',
  14672. '\uFECB': '\u0639',
  14673. '\uFECC': '\u0639',
  14674. '\uFECD': '\u063A',
  14675. '\uFECE': '\u063A',
  14676. '\uFECF': '\u063A',
  14677. '\uFED0': '\u063A',
  14678. '\uFED1': '\u0641',
  14679. '\uFED2': '\u0641',
  14680. '\uFED3': '\u0641',
  14681. '\uFED4': '\u0641',
  14682. '\uFED5': '\u0642',
  14683. '\uFED6': '\u0642',
  14684. '\uFED7': '\u0642',
  14685. '\uFED8': '\u0642',
  14686. '\uFED9': '\u0643',
  14687. '\uFEDA': '\u0643',
  14688. '\uFEDB': '\u0643',
  14689. '\uFEDC': '\u0643',
  14690. '\uFEDD': '\u0644',
  14691. '\uFEDE': '\u0644',
  14692. '\uFEDF': '\u0644',
  14693. '\uFEE0': '\u0644',
  14694. '\uFEE1': '\u0645',
  14695. '\uFEE2': '\u0645',
  14696. '\uFEE3': '\u0645',
  14697. '\uFEE4': '\u0645',
  14698. '\uFEE5': '\u0646',
  14699. '\uFEE6': '\u0646',
  14700. '\uFEE7': '\u0646',
  14701. '\uFEE8': '\u0646',
  14702. '\uFEE9': '\u0647',
  14703. '\uFEEA': '\u0647',
  14704. '\uFEEB': '\u0647',
  14705. '\uFEEC': '\u0647',
  14706. '\uFEED': '\u0648',
  14707. '\uFEEE': '\u0648',
  14708. '\uFEEF': '\u0649',
  14709. '\uFEF0': '\u0649',
  14710. '\uFEF1': '\u064A',
  14711. '\uFEF2': '\u064A',
  14712. '\uFEF3': '\u064A',
  14713. '\uFEF4': '\u064A',
  14714. '\uFEF5': '\u0644\u0622',
  14715. '\uFEF6': '\u0644\u0622',
  14716. '\uFEF7': '\u0644\u0623',
  14717. '\uFEF8': '\u0644\u0623',
  14718. '\uFEF9': '\u0644\u0625',
  14719. '\uFEFA': '\u0644\u0625',
  14720. '\uFEFB': '\u0644\u0627',
  14721. '\uFEFC': '\u0644\u0627'
  14722. };
  14723. function reverseIfRtl(chars) {
  14724. var charsLength = chars.length;
  14725. //reverse an arabic ligature
  14726. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14727. return chars;
  14728. }
  14729. var s = '';
  14730. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14731. s += chars[ii];
  14732. }
  14733. return s;
  14734. }
  14735. function adjustWidths(properties) {
  14736. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14737. return;
  14738. }
  14739. // adjusting width to fontMatrix scale
  14740. var scale = 0.001 / properties.fontMatrix[0];
  14741. var glyphsWidths = properties.widths;
  14742. for (var glyph in glyphsWidths) {
  14743. glyphsWidths[glyph] *= scale;
  14744. }
  14745. properties.defaultWidth *= scale;
  14746. }
  14747. function getFontType(type, subtype) {
  14748. switch (type) {
  14749. case 'Type1':
  14750. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14751. case 'CIDFontType0':
  14752. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14753. FontType.CIDFONTTYPE0;
  14754. case 'OpenType':
  14755. return FontType.OPENTYPE;
  14756. case 'TrueType':
  14757. return FontType.TRUETYPE;
  14758. case 'CIDFontType2':
  14759. return FontType.CIDFONTTYPE2;
  14760. case 'MMType1':
  14761. return FontType.MMTYPE1;
  14762. case 'Type0':
  14763. return FontType.TYPE0;
  14764. default:
  14765. return FontType.UNKNOWN;
  14766. }
  14767. }
  14768. var Glyph = (function GlyphClosure() {
  14769. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14770. this.fontChar = fontChar;
  14771. this.unicode = unicode;
  14772. this.accent = accent;
  14773. this.width = width;
  14774. this.vmetric = vmetric;
  14775. this.operatorListId = operatorListId;
  14776. }
  14777. Glyph.prototype.matchesForCache =
  14778. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14779. return this.fontChar === fontChar &&
  14780. this.unicode === unicode &&
  14781. this.accent === accent &&
  14782. this.width === width &&
  14783. this.vmetric === vmetric &&
  14784. this.operatorListId === operatorListId;
  14785. };
  14786. return Glyph;
  14787. })();
  14788. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14789. function ToUnicodeMap(cmap) {
  14790. // The elements of this._map can be integers or strings, depending on how
  14791. // |cmap| was created.
  14792. this._map = cmap;
  14793. }
  14794. ToUnicodeMap.prototype = {
  14795. get length() {
  14796. return this._map.length;
  14797. },
  14798. forEach: function(callback) {
  14799. for (var charCode in this._map) {
  14800. callback(charCode, this._map[charCode].charCodeAt(0));
  14801. }
  14802. },
  14803. get: function(i) {
  14804. return this._map[i];
  14805. },
  14806. charCodeOf: function(v) {
  14807. return this._map.indexOf(v);
  14808. }
  14809. };
  14810. return ToUnicodeMap;
  14811. })();
  14812. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14813. function IdentityToUnicodeMap(firstChar, lastChar) {
  14814. this.firstChar = firstChar;
  14815. this.lastChar = lastChar;
  14816. }
  14817. IdentityToUnicodeMap.prototype = {
  14818. get length() {
  14819. error('should not access .length');
  14820. },
  14821. forEach: function (callback) {
  14822. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  14823. callback(i, i);
  14824. }
  14825. },
  14826. get: function (i) {
  14827. if (this.firstChar <= i && i <= this.lastChar) {
  14828. return String.fromCharCode(i);
  14829. }
  14830. return undefined;
  14831. },
  14832. charCodeOf: function (v) {
  14833. error('should not call .charCodeOf');
  14834. }
  14835. };
  14836. return IdentityToUnicodeMap;
  14837. })();
  14838. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  14839. function writeInt16(dest, offset, num) {
  14840. dest[offset] = (num >> 8) & 0xFF;
  14841. dest[offset + 1] = num & 0xFF;
  14842. }
  14843. function writeInt32(dest, offset, num) {
  14844. dest[offset] = (num >> 24) & 0xFF;
  14845. dest[offset + 1] = (num >> 16) & 0xFF;
  14846. dest[offset + 2] = (num >> 8) & 0xFF;
  14847. dest[offset + 3] = num & 0xFF;
  14848. }
  14849. function writeData(dest, offset, data) {
  14850. var i, ii;
  14851. if (data instanceof Uint8Array) {
  14852. dest.set(data, offset);
  14853. } else if (typeof data === 'string') {
  14854. for (i = 0, ii = data.length; i < ii; i++) {
  14855. dest[offset++] = data.charCodeAt(i) & 0xFF;
  14856. }
  14857. } else {
  14858. // treating everything else as array
  14859. for (i = 0, ii = data.length; i < ii; i++) {
  14860. dest[offset++] = data[i] & 0xFF;
  14861. }
  14862. }
  14863. }
  14864. function OpenTypeFileBuilder(sfnt) {
  14865. this.sfnt = sfnt;
  14866. this.tables = Object.create(null);
  14867. }
  14868. OpenTypeFileBuilder.getSearchParams =
  14869. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  14870. var maxPower2 = 1, log2 = 0;
  14871. while ((maxPower2 ^ entriesCount) > maxPower2) {
  14872. maxPower2 <<= 1;
  14873. log2++;
  14874. }
  14875. var searchRange = maxPower2 * entrySize;
  14876. return {
  14877. range: searchRange,
  14878. entry: log2,
  14879. rangeShift: entrySize * entriesCount - searchRange
  14880. };
  14881. };
  14882. var OTF_HEADER_SIZE = 12;
  14883. var OTF_TABLE_ENTRY_SIZE = 16;
  14884. OpenTypeFileBuilder.prototype = {
  14885. toArray: function OpenTypeFileBuilder_toArray() {
  14886. var sfnt = this.sfnt;
  14887. // Tables needs to be written by ascendant alphabetic order
  14888. var tables = this.tables;
  14889. var tablesNames = Object.keys(tables);
  14890. tablesNames.sort();
  14891. var numTables = tablesNames.length;
  14892. var i, j, jj, table, tableName;
  14893. // layout the tables data
  14894. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  14895. var tableOffsets = [offset];
  14896. for (i = 0; i < numTables; i++) {
  14897. table = tables[tablesNames[i]];
  14898. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  14899. offset += paddedLength;
  14900. tableOffsets.push(offset);
  14901. }
  14902. var file = new Uint8Array(offset);
  14903. // write the table data first (mostly for checksum)
  14904. for (i = 0; i < numTables; i++) {
  14905. table = tables[tablesNames[i]];
  14906. writeData(file, tableOffsets[i], table);
  14907. }
  14908. // sfnt version (4 bytes)
  14909. if (sfnt === 'true') {
  14910. // Windows hates the Mac TrueType sfnt version number
  14911. sfnt = string32(0x00010000);
  14912. }
  14913. file[0] = sfnt.charCodeAt(0) & 0xFF;
  14914. file[1] = sfnt.charCodeAt(1) & 0xFF;
  14915. file[2] = sfnt.charCodeAt(2) & 0xFF;
  14916. file[3] = sfnt.charCodeAt(3) & 0xFF;
  14917. // numTables (2 bytes)
  14918. writeInt16(file, 4, numTables);
  14919. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  14920. // searchRange (2 bytes)
  14921. writeInt16(file, 6, searchParams.range);
  14922. // entrySelector (2 bytes)
  14923. writeInt16(file, 8, searchParams.entry);
  14924. // rangeShift (2 bytes)
  14925. writeInt16(file, 10, searchParams.rangeShift);
  14926. offset = OTF_HEADER_SIZE;
  14927. // writing table entries
  14928. for (i = 0; i < numTables; i++) {
  14929. tableName = tablesNames[i];
  14930. file[offset] = tableName.charCodeAt(0) & 0xFF;
  14931. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  14932. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  14933. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  14934. // checksum
  14935. var checksum = 0;
  14936. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  14937. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  14938. (file[j + 2] << 8) + file[j + 3];
  14939. checksum = (checksum + quad) | 0;
  14940. }
  14941. writeInt32(file, offset + 4, checksum);
  14942. // offset
  14943. writeInt32(file, offset + 8, tableOffsets[i]);
  14944. // length
  14945. writeInt32(file, offset + 12, tables[tableName].length);
  14946. offset += OTF_TABLE_ENTRY_SIZE;
  14947. }
  14948. return file;
  14949. },
  14950. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  14951. if (tag in this.tables) {
  14952. throw new Error('Table ' + tag + ' already exists');
  14953. }
  14954. this.tables[tag] = data;
  14955. }
  14956. };
  14957. return OpenTypeFileBuilder;
  14958. })();
  14959. /**
  14960. * 'Font' is the class the outside world should use, it encapsulate all the font
  14961. * decoding logics whatever type it is (assuming the font type is supported).
  14962. *
  14963. * For example to read a Type1 font and to attach it to the document:
  14964. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  14965. * type1Font.bind();
  14966. */
  14967. var Font = (function FontClosure() {
  14968. function Font(name, file, properties) {
  14969. var charCode, glyphName, fontChar;
  14970. this.name = name;
  14971. this.loadedName = properties.loadedName;
  14972. this.isType3Font = properties.isType3Font;
  14973. this.sizes = [];
  14974. this.glyphCache = {};
  14975. var names = name.split('+');
  14976. names = names.length > 1 ? names[1] : names[0];
  14977. names = names.split(/[-,_]/g)[0];
  14978. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  14979. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  14980. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  14981. var type = properties.type;
  14982. var subtype = properties.subtype;
  14983. this.type = type;
  14984. this.fallbackName = (this.isMonospace ? 'monospace' :
  14985. (this.isSerifFont ? 'serif' : 'sans-serif'));
  14986. this.differences = properties.differences;
  14987. this.widths = properties.widths;
  14988. this.defaultWidth = properties.defaultWidth;
  14989. this.composite = properties.composite;
  14990. this.wideChars = properties.wideChars;
  14991. this.cMap = properties.cMap;
  14992. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  14993. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  14994. this.fontMatrix = properties.fontMatrix;
  14995. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  14996. this.toFontChar = [];
  14997. if (properties.type === 'Type3') {
  14998. for (charCode = 0; charCode < 256; charCode++) {
  14999. this.toFontChar[charCode] = (this.differences[charCode] ||
  15000. properties.defaultEncoding[charCode]);
  15001. }
  15002. this.fontType = FontType.TYPE3;
  15003. return;
  15004. }
  15005. this.cidEncoding = properties.cidEncoding;
  15006. this.vertical = properties.vertical;
  15007. if (this.vertical) {
  15008. this.vmetrics = properties.vmetrics;
  15009. this.defaultVMetrics = properties.defaultVMetrics;
  15010. }
  15011. if (!file || file.isEmpty) {
  15012. if (file) {
  15013. // Some bad PDF generators will include empty font files,
  15014. // attempting to recover by assuming that no file exists.
  15015. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15016. }
  15017. this.missingFile = true;
  15018. // The file data is not specified. Trying to fix the font name
  15019. // to be used with the canvas.font.
  15020. var fontName = name.replace(/[,_]/g, '-');
  15021. var isStandardFont = fontName in stdFontMap;
  15022. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15023. this.bold = (fontName.search(/bold/gi) !== -1);
  15024. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15025. (fontName.search(/italic/gi) !== -1));
  15026. // Use 'name' instead of 'fontName' here because the original
  15027. // name ArialBlack for example will be replaced by Helvetica.
  15028. this.black = (name.search(/Black/g) !== -1);
  15029. // if at least one width is present, remeasure all chars when exists
  15030. this.remeasure = Object.keys(this.widths).length > 0;
  15031. if (isStandardFont && type === 'CIDFontType2' &&
  15032. properties.cidEncoding.indexOf('Identity-') === 0) {
  15033. // Standard fonts might be embedded as CID font without glyph mapping.
  15034. // Building one based on GlyphMapForStandardFonts.
  15035. var map = [];
  15036. for (var code in GlyphMapForStandardFonts) {
  15037. map[+code] = GlyphMapForStandardFonts[code];
  15038. }
  15039. this.toFontChar = map;
  15040. this.toUnicode = new ToUnicodeMap(map);
  15041. } else if (/Symbol/i.test(fontName)) {
  15042. var symbols = Encodings.SymbolSetEncoding;
  15043. for (charCode in symbols) {
  15044. fontChar = GlyphsUnicode[symbols[charCode]];
  15045. if (!fontChar) {
  15046. continue;
  15047. }
  15048. this.toFontChar[charCode] = fontChar;
  15049. }
  15050. } else if (/Dingbats/i.test(fontName)) {
  15051. var dingbats = Encodings.ZapfDingbatsEncoding;
  15052. for (charCode in dingbats) {
  15053. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15054. if (!fontChar) {
  15055. continue;
  15056. }
  15057. this.toFontChar[charCode] = fontChar;
  15058. }
  15059. for (charCode in properties.differences) {
  15060. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15061. if (!fontChar) {
  15062. continue;
  15063. }
  15064. this.toFontChar[charCode] = fontChar;
  15065. }
  15066. } else if (isStandardFont) {
  15067. this.toFontChar = [];
  15068. for (charCode in properties.defaultEncoding) {
  15069. glyphName = (properties.differences[charCode] ||
  15070. properties.defaultEncoding[charCode]);
  15071. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15072. }
  15073. } else {
  15074. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15075. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15076. if (notCidFont) {
  15077. glyphName = (properties.differences[charCode] ||
  15078. properties.defaultEncoding[charCode]);
  15079. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15080. }
  15081. this.toFontChar[charCode] = unicodeCharCode;
  15082. }.bind(this));
  15083. }
  15084. this.loadedName = fontName.split('-')[0];
  15085. this.loading = false;
  15086. this.fontType = getFontType(type, subtype);
  15087. return;
  15088. }
  15089. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15090. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15091. // Some TrueType fonts by mistake claim Type1C
  15092. if (isTrueTypeFile(file)) {
  15093. subtype = 'TrueType';
  15094. } else {
  15095. type = 'Type1';
  15096. }
  15097. }
  15098. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15099. type = 'CIDFontType0';
  15100. }
  15101. // XXX: Temporarily change the type for open type so we trigger a warning.
  15102. // This should be removed when we add support for open type.
  15103. if (subtype === 'OpenType') {
  15104. type = 'OpenType';
  15105. }
  15106. var data;
  15107. switch (type) {
  15108. case 'Type1':
  15109. case 'CIDFontType0':
  15110. this.mimetype = 'font/opentype';
  15111. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15112. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15113. adjustWidths(properties);
  15114. // Wrap the CFF data inside an OTF font file
  15115. data = this.convert(name, cff, properties);
  15116. break;
  15117. case 'OpenType':
  15118. case 'TrueType':
  15119. case 'CIDFontType2':
  15120. this.mimetype = 'font/opentype';
  15121. // Repair the TrueType file. It is can be damaged in the point of
  15122. // view of the sanitizer
  15123. data = this.checkAndRepair(name, file, properties);
  15124. if (this.isOpenType) {
  15125. type = 'OpenType';
  15126. }
  15127. break;
  15128. default:
  15129. error('Font ' + type + ' is not supported');
  15130. break;
  15131. }
  15132. this.data = data;
  15133. this.fontType = getFontType(type, subtype);
  15134. // Transfer some properties again that could change during font conversion
  15135. this.fontMatrix = properties.fontMatrix;
  15136. this.widths = properties.widths;
  15137. this.defaultWidth = properties.defaultWidth;
  15138. this.encoding = properties.baseEncoding;
  15139. this.seacMap = properties.seacMap;
  15140. this.loading = true;
  15141. }
  15142. Font.getFontID = (function () {
  15143. var ID = 1;
  15144. return function Font_getFontID() {
  15145. return String(ID++);
  15146. };
  15147. })();
  15148. function int16(b0, b1) {
  15149. return (b0 << 8) + b1;
  15150. }
  15151. function int32(b0, b1, b2, b3) {
  15152. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15153. }
  15154. function string16(value) {
  15155. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15156. }
  15157. function safeString16(value) {
  15158. // clamp value to the 16-bit int range
  15159. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15160. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15161. }
  15162. function isTrueTypeFile(file) {
  15163. var header = file.peekBytes(4);
  15164. return readUint32(header, 0) === 0x00010000;
  15165. }
  15166. /**
  15167. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15168. * with their unicode value. It also moves char codes that are in known
  15169. * problematic locations.
  15170. * @return {Object} Two properties:
  15171. * 'toFontChar' - maps original char codes(the value that will be read
  15172. * from commands such as show text) to the char codes that will be used in the
  15173. * font that we build
  15174. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15175. */
  15176. function adjustMapping(charCodeToGlyphId, properties) {
  15177. var toUnicode = properties.toUnicode;
  15178. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15179. var isIdentityUnicode =
  15180. properties.toUnicode instanceof IdentityToUnicodeMap;
  15181. var isCidFontType2 = (properties.type === 'CIDFontType2');
  15182. var newMap = Object.create(null);
  15183. var toFontChar = [];
  15184. var usedFontCharCodes = [];
  15185. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15186. for (var originalCharCode in charCodeToGlyphId) {
  15187. originalCharCode |= 0;
  15188. var glyphId = charCodeToGlyphId[originalCharCode];
  15189. var fontCharCode = originalCharCode;
  15190. // First try to map the value to a unicode position if a non identity map
  15191. // was created.
  15192. if (!isIdentityUnicode) {
  15193. if (toUnicode.get(originalCharCode) !== undefined) {
  15194. var unicode = toUnicode.get(fontCharCode);
  15195. // TODO: Try to map ligatures to the correct spot.
  15196. if (unicode.length === 1) {
  15197. fontCharCode = unicode.charCodeAt(0);
  15198. }
  15199. } else if (isCidFontType2) {
  15200. // For CIDFontType2, move characters not present in toUnicode
  15201. // to the private use area (fixes bug 1028735 and issue 4881).
  15202. fontCharCode = nextAvailableFontCharCode;
  15203. }
  15204. }
  15205. // Try to move control characters, special characters and already mapped
  15206. // characters to the private use area since they will not be drawn by
  15207. // canvas if left in their current position. Also, move characters if the
  15208. // font was symbolic and there is only an identity unicode map since the
  15209. // characters probably aren't in the correct position (fixes an issue
  15210. // with firefox and thuluthfont).
  15211. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15212. fontCharCode <= 0x1f || // Control chars
  15213. fontCharCode === 0x7F || // Control char
  15214. fontCharCode === 0xAD || // Soft hyphen
  15215. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15216. // Prevent drawing characters in the specials unicode block.
  15217. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15218. (isSymbolic && isIdentityUnicode)) &&
  15219. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15220. // Loop to try and find a free spot in the private use area.
  15221. do {
  15222. fontCharCode = nextAvailableFontCharCode++;
  15223. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15224. fontCharCode = 0xF020;
  15225. nextAvailableFontCharCode = fontCharCode + 1;
  15226. }
  15227. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15228. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15229. }
  15230. newMap[fontCharCode] = glyphId;
  15231. toFontChar[originalCharCode] = fontCharCode;
  15232. usedFontCharCodes[fontCharCode] = true;
  15233. }
  15234. return {
  15235. toFontChar: toFontChar,
  15236. charCodeToGlyphId: newMap,
  15237. nextAvailableFontCharCode: nextAvailableFontCharCode
  15238. };
  15239. }
  15240. function getRanges(glyphs) {
  15241. // Array.sort() sorts by characters, not numerically, so convert to an
  15242. // array of characters.
  15243. var codes = [];
  15244. for (var charCode in glyphs) {
  15245. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15246. }
  15247. codes.sort(function fontGetRangesSort(a, b) {
  15248. return a.fontCharCode - b.fontCharCode;
  15249. });
  15250. // Split the sorted codes into ranges.
  15251. var ranges = [];
  15252. var length = codes.length;
  15253. for (var n = 0; n < length; ) {
  15254. var start = codes[n].fontCharCode;
  15255. var codeIndices = [codes[n].glyphId];
  15256. ++n;
  15257. var end = start;
  15258. while (n < length && end + 1 === codes[n].fontCharCode) {
  15259. codeIndices.push(codes[n].glyphId);
  15260. ++end;
  15261. ++n;
  15262. if (end === 0xFFFF) {
  15263. break;
  15264. }
  15265. }
  15266. ranges.push([start, end, codeIndices]);
  15267. }
  15268. return ranges;
  15269. }
  15270. function createCmapTable(glyphs) {
  15271. var ranges = getRanges(glyphs);
  15272. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15273. var cmap = '\x00\x00' + // version
  15274. string16(numTables) + // numTables
  15275. '\x00\x03' + // platformID
  15276. '\x00\x01' + // encodingID
  15277. string32(4 + numTables * 8); // start of the table record
  15278. var i, ii, j, jj;
  15279. for (i = ranges.length - 1; i >= 0; --i) {
  15280. if (ranges[i][0] <= 0xFFFF) { break; }
  15281. }
  15282. var bmpLength = i + 1;
  15283. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15284. ranges[i][1] = 0xFFFE;
  15285. }
  15286. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15287. var segCount = bmpLength + trailingRangesCount;
  15288. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15289. // Fill up the 4 parallel arrays describing the segments.
  15290. var startCount = '';
  15291. var endCount = '';
  15292. var idDeltas = '';
  15293. var idRangeOffsets = '';
  15294. var glyphsIds = '';
  15295. var bias = 0;
  15296. var range, start, end, codes;
  15297. for (i = 0, ii = bmpLength; i < ii; i++) {
  15298. range = ranges[i];
  15299. start = range[0];
  15300. end = range[1];
  15301. startCount += string16(start);
  15302. endCount += string16(end);
  15303. codes = range[2];
  15304. var contiguous = true;
  15305. for (j = 1, jj = codes.length; j < jj; ++j) {
  15306. if (codes[j] !== codes[j - 1] + 1) {
  15307. contiguous = false;
  15308. break;
  15309. }
  15310. }
  15311. if (!contiguous) {
  15312. var offset = (segCount - i) * 2 + bias * 2;
  15313. bias += (end - start + 1);
  15314. idDeltas += string16(0);
  15315. idRangeOffsets += string16(offset);
  15316. for (j = 0, jj = codes.length; j < jj; ++j) {
  15317. glyphsIds += string16(codes[j]);
  15318. }
  15319. } else {
  15320. var startCode = codes[0];
  15321. idDeltas += string16((startCode - start) & 0xFFFF);
  15322. idRangeOffsets += string16(0);
  15323. }
  15324. }
  15325. if (trailingRangesCount > 0) {
  15326. endCount += '\xFF\xFF';
  15327. startCount += '\xFF\xFF';
  15328. idDeltas += '\x00\x01';
  15329. idRangeOffsets += '\x00\x00';
  15330. }
  15331. var format314 = '\x00\x00' + // language
  15332. string16(2 * segCount) +
  15333. string16(searchParams.range) +
  15334. string16(searchParams.entry) +
  15335. string16(searchParams.rangeShift) +
  15336. endCount + '\x00\x00' + startCount +
  15337. idDeltas + idRangeOffsets + glyphsIds;
  15338. var format31012 = '';
  15339. var header31012 = '';
  15340. if (numTables > 1) {
  15341. cmap += '\x00\x03' + // platformID
  15342. '\x00\x0A' + // encodingID
  15343. string32(4 + numTables * 8 +
  15344. 4 + format314.length); // start of the table record
  15345. format31012 = '';
  15346. for (i = 0, ii = ranges.length; i < ii; i++) {
  15347. range = ranges[i];
  15348. start = range[0];
  15349. codes = range[2];
  15350. var code = codes[0];
  15351. for (j = 1, jj = codes.length; j < jj; ++j) {
  15352. if (codes[j] !== codes[j - 1] + 1) {
  15353. end = range[0] + j - 1;
  15354. format31012 += string32(start) + // startCharCode
  15355. string32(end) + // endCharCode
  15356. string32(code); // startGlyphID
  15357. start = end + 1;
  15358. code = codes[j];
  15359. }
  15360. }
  15361. format31012 += string32(start) + // startCharCode
  15362. string32(range[1]) + // endCharCode
  15363. string32(code); // startGlyphID
  15364. }
  15365. header31012 = '\x00\x0C' + // format
  15366. '\x00\x00' + // reserved
  15367. string32(format31012.length + 16) + // length
  15368. '\x00\x00\x00\x00' + // language
  15369. string32(format31012.length / 12); // nGroups
  15370. }
  15371. return cmap + '\x00\x04' + // format
  15372. string16(format314.length + 4) + // length
  15373. format314 + header31012 + format31012;
  15374. }
  15375. function validateOS2Table(os2) {
  15376. var stream = new Stream(os2.data);
  15377. var version = stream.getUint16();
  15378. // TODO verify all OS/2 tables fields, but currently we validate only those
  15379. // that give us issues
  15380. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15381. var selection = stream.getUint16();
  15382. if (version < 4 && (selection & 0x0300)) {
  15383. return false;
  15384. }
  15385. var firstChar = stream.getUint16();
  15386. var lastChar = stream.getUint16();
  15387. if (firstChar > lastChar) {
  15388. return false;
  15389. }
  15390. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15391. var usWinAscent = stream.getUint16();
  15392. if (usWinAscent === 0) { // makes font unreadable by windows
  15393. return false;
  15394. }
  15395. // OS/2 appears to be valid, resetting some fields
  15396. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15397. return true;
  15398. }
  15399. function createOS2Table(properties, charstrings, override) {
  15400. override = override || {
  15401. unitsPerEm: 0,
  15402. yMax: 0,
  15403. yMin: 0,
  15404. ascent: 0,
  15405. descent: 0
  15406. };
  15407. var ulUnicodeRange1 = 0;
  15408. var ulUnicodeRange2 = 0;
  15409. var ulUnicodeRange3 = 0;
  15410. var ulUnicodeRange4 = 0;
  15411. var firstCharIndex = null;
  15412. var lastCharIndex = 0;
  15413. if (charstrings) {
  15414. for (var code in charstrings) {
  15415. code |= 0;
  15416. if (firstCharIndex > code || !firstCharIndex) {
  15417. firstCharIndex = code;
  15418. }
  15419. if (lastCharIndex < code) {
  15420. lastCharIndex = code;
  15421. }
  15422. var position = getUnicodeRangeFor(code);
  15423. if (position < 32) {
  15424. ulUnicodeRange1 |= 1 << position;
  15425. } else if (position < 64) {
  15426. ulUnicodeRange2 |= 1 << position - 32;
  15427. } else if (position < 96) {
  15428. ulUnicodeRange3 |= 1 << position - 64;
  15429. } else if (position < 123) {
  15430. ulUnicodeRange4 |= 1 << position - 96;
  15431. } else {
  15432. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15433. }
  15434. }
  15435. } else {
  15436. // TODO
  15437. firstCharIndex = 0;
  15438. lastCharIndex = 255;
  15439. }
  15440. var bbox = properties.bbox || [0, 0, 0, 0];
  15441. var unitsPerEm = (override.unitsPerEm ||
  15442. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15443. // if the font units differ to the PDF glyph space units
  15444. // then scale up the values
  15445. var scale = (properties.ascentScaled ? 1.0 :
  15446. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15447. var typoAscent = (override.ascent ||
  15448. Math.round(scale * (properties.ascent || bbox[3])));
  15449. var typoDescent = (override.descent ||
  15450. Math.round(scale * (properties.descent || bbox[1])));
  15451. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15452. typoDescent = -typoDescent; // fixing incorrect descent
  15453. }
  15454. var winAscent = override.yMax || typoAscent;
  15455. var winDescent = -override.yMin || -typoDescent;
  15456. return '\x00\x03' + // version
  15457. '\x02\x24' + // xAvgCharWidth
  15458. '\x01\xF4' + // usWeightClass
  15459. '\x00\x05' + // usWidthClass
  15460. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15461. '\x02\x8A' + // ySubscriptXSize
  15462. '\x02\xBB' + // ySubscriptYSize
  15463. '\x00\x00' + // ySubscriptXOffset
  15464. '\x00\x8C' + // ySubscriptYOffset
  15465. '\x02\x8A' + // ySuperScriptXSize
  15466. '\x02\xBB' + // ySuperScriptYSize
  15467. '\x00\x00' + // ySuperScriptXOffset
  15468. '\x01\xDF' + // ySuperScriptYOffset
  15469. '\x00\x31' + // yStrikeOutSize
  15470. '\x01\x02' + // yStrikeOutPosition
  15471. '\x00\x00' + // sFamilyClass
  15472. '\x00\x00\x06' +
  15473. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15474. '\x00\x00\x00\x00\x00\x00' + // Panose
  15475. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15476. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15477. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15478. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15479. '\x2A\x32\x31\x2A' + // achVendID
  15480. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15481. string16(firstCharIndex ||
  15482. properties.firstChar) + // usFirstCharIndex
  15483. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15484. string16(typoAscent) + // sTypoAscender
  15485. string16(typoDescent) + // sTypoDescender
  15486. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15487. string16(winAscent) + // usWinAscent
  15488. string16(winDescent) + // usWinDescent
  15489. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15490. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15491. string16(properties.xHeight) + // sxHeight
  15492. string16(properties.capHeight) + // sCapHeight
  15493. string16(0) + // usDefaultChar
  15494. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15495. '\x00\x03'; // usMaxContext
  15496. }
  15497. function createPostTable(properties) {
  15498. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15499. return ('\x00\x03\x00\x00' + // Version number
  15500. string32(angle) + // italicAngle
  15501. '\x00\x00' + // underlinePosition
  15502. '\x00\x00' + // underlineThickness
  15503. string32(properties.fixedPitch) + // isFixedPitch
  15504. '\x00\x00\x00\x00' + // minMemType42
  15505. '\x00\x00\x00\x00' + // maxMemType42
  15506. '\x00\x00\x00\x00' + // minMemType1
  15507. '\x00\x00\x00\x00'); // maxMemType1
  15508. }
  15509. function createNameTable(name, proto) {
  15510. if (!proto) {
  15511. proto = [[], []]; // no strings and unicode strings
  15512. }
  15513. var strings = [
  15514. proto[0][0] || 'Original licence', // 0.Copyright
  15515. proto[0][1] || name, // 1.Font family
  15516. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15517. proto[0][3] || 'uniqueID', // 3.Unique ID
  15518. proto[0][4] || name, // 4.Full font name
  15519. proto[0][5] || 'Version 0.11', // 5.Version
  15520. proto[0][6] || '', // 6.Postscript name
  15521. proto[0][7] || 'Unknown', // 7.Trademark
  15522. proto[0][8] || 'Unknown', // 8.Manufacturer
  15523. proto[0][9] || 'Unknown' // 9.Designer
  15524. ];
  15525. // Mac want 1-byte per character strings while Windows want
  15526. // 2-bytes per character, so duplicate the names table
  15527. var stringsUnicode = [];
  15528. var i, ii, j, jj, str;
  15529. for (i = 0, ii = strings.length; i < ii; i++) {
  15530. str = proto[1][i] || strings[i];
  15531. var strBufUnicode = [];
  15532. for (j = 0, jj = str.length; j < jj; j++) {
  15533. strBufUnicode.push(string16(str.charCodeAt(j)));
  15534. }
  15535. stringsUnicode.push(strBufUnicode.join(''));
  15536. }
  15537. var names = [strings, stringsUnicode];
  15538. var platforms = ['\x00\x01', '\x00\x03'];
  15539. var encodings = ['\x00\x00', '\x00\x01'];
  15540. var languages = ['\x00\x00', '\x04\x09'];
  15541. var namesRecordCount = strings.length * platforms.length;
  15542. var nameTable =
  15543. '\x00\x00' + // format
  15544. string16(namesRecordCount) + // Number of names Record
  15545. string16(namesRecordCount * 12 + 6); // Storage
  15546. // Build the name records field
  15547. var strOffset = 0;
  15548. for (i = 0, ii = platforms.length; i < ii; i++) {
  15549. var strs = names[i];
  15550. for (j = 0, jj = strs.length; j < jj; j++) {
  15551. str = strs[j];
  15552. var nameRecord =
  15553. platforms[i] + // platform ID
  15554. encodings[i] + // encoding ID
  15555. languages[i] + // language ID
  15556. string16(j) + // name ID
  15557. string16(str.length) +
  15558. string16(strOffset);
  15559. nameTable += nameRecord;
  15560. strOffset += str.length;
  15561. }
  15562. }
  15563. nameTable += strings.join('') + stringsUnicode.join('');
  15564. return nameTable;
  15565. }
  15566. Font.prototype = {
  15567. name: null,
  15568. font: null,
  15569. mimetype: null,
  15570. encoding: null,
  15571. get renderer() {
  15572. var renderer = FontRendererFactory.create(this);
  15573. return shadow(this, 'renderer', renderer);
  15574. },
  15575. exportData: function Font_exportData() {
  15576. var data = {};
  15577. for (var i in this) {
  15578. if (this.hasOwnProperty(i)) {
  15579. data[i] = this[i];
  15580. }
  15581. }
  15582. return data;
  15583. },
  15584. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15585. function readTableEntry(file) {
  15586. var tag = bytesToString(file.getBytes(4));
  15587. var checksum = file.getInt32();
  15588. var offset = file.getInt32() >>> 0;
  15589. var length = file.getInt32() >>> 0;
  15590. // Read the table associated data
  15591. var previousPosition = file.pos;
  15592. file.pos = file.start ? file.start : 0;
  15593. file.skip(offset);
  15594. var data = file.getBytes(length);
  15595. file.pos = previousPosition;
  15596. if (tag === 'head') {
  15597. // clearing checksum adjustment
  15598. data[8] = data[9] = data[10] = data[11] = 0;
  15599. data[17] |= 0x20; //Set font optimized for cleartype flag
  15600. }
  15601. return {
  15602. tag: tag,
  15603. checksum: checksum,
  15604. length: length,
  15605. offset: offset,
  15606. data: data
  15607. };
  15608. }
  15609. function readOpenTypeHeader(ttf) {
  15610. return {
  15611. version: bytesToString(ttf.getBytes(4)),
  15612. numTables: ttf.getUint16(),
  15613. searchRange: ttf.getUint16(),
  15614. entrySelector: ttf.getUint16(),
  15615. rangeShift: ttf.getUint16()
  15616. };
  15617. }
  15618. /**
  15619. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15620. * PDF spec
  15621. */
  15622. function readCmapTable(cmap, font, isSymbolicFont) {
  15623. var segment;
  15624. var start = (font.start ? font.start : 0) + cmap.offset;
  15625. font.pos = start;
  15626. var version = font.getUint16();
  15627. var numTables = font.getUint16();
  15628. var potentialTable;
  15629. var canBreak = false;
  15630. // There's an order of preference in terms of which cmap subtable to
  15631. // use:
  15632. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15633. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15634. // The following takes advantage of the fact that the tables are sorted
  15635. // to work.
  15636. for (var i = 0; i < numTables; i++) {
  15637. var platformId = font.getUint16();
  15638. var encodingId = font.getUint16();
  15639. var offset = font.getInt32() >>> 0;
  15640. var useTable = false;
  15641. if (platformId === 1 && encodingId === 0) {
  15642. useTable = true;
  15643. // Continue the loop since there still may be a higher priority
  15644. // table.
  15645. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15646. useTable = true;
  15647. canBreak = true;
  15648. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15649. useTable = true;
  15650. canBreak = true;
  15651. }
  15652. if (useTable) {
  15653. potentialTable = {
  15654. platformId: platformId,
  15655. encodingId: encodingId,
  15656. offset: offset
  15657. };
  15658. }
  15659. if (canBreak) {
  15660. break;
  15661. }
  15662. }
  15663. if (!potentialTable) {
  15664. warn('Could not find a preferred cmap table.');
  15665. return {
  15666. platformId: -1,
  15667. encodingId: -1,
  15668. mappings: [],
  15669. hasShortCmap: false
  15670. };
  15671. }
  15672. font.pos = start + potentialTable.offset;
  15673. var format = font.getUint16();
  15674. var length = font.getUint16();
  15675. var language = font.getUint16();
  15676. var hasShortCmap = false;
  15677. var mappings = [];
  15678. var j, glyphId;
  15679. // TODO(mack): refactor this cmap subtable reading logic out
  15680. if (format === 0) {
  15681. for (j = 0; j < 256; j++) {
  15682. var index = font.getByte();
  15683. if (!index) {
  15684. continue;
  15685. }
  15686. mappings.push({
  15687. charCode: j,
  15688. glyphId: index
  15689. });
  15690. }
  15691. hasShortCmap = true;
  15692. } else if (format === 4) {
  15693. // re-creating the table in format 4 since the encoding
  15694. // might be changed
  15695. var segCount = (font.getUint16() >> 1);
  15696. font.getBytes(6); // skipping range fields
  15697. var segIndex, segments = [];
  15698. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15699. segments.push({ end: font.getUint16() });
  15700. }
  15701. font.getUint16();
  15702. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15703. segments[segIndex].start = font.getUint16();
  15704. }
  15705. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15706. segments[segIndex].delta = font.getUint16();
  15707. }
  15708. var offsetsCount = 0;
  15709. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15710. segment = segments[segIndex];
  15711. var rangeOffset = font.getUint16();
  15712. if (!rangeOffset) {
  15713. segment.offsetIndex = -1;
  15714. continue;
  15715. }
  15716. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15717. segment.offsetIndex = offsetIndex;
  15718. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15719. segment.end - segment.start + 1);
  15720. }
  15721. var offsets = [];
  15722. for (j = 0; j < offsetsCount; j++) {
  15723. offsets.push(font.getUint16());
  15724. }
  15725. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15726. segment = segments[segIndex];
  15727. start = segment.start;
  15728. var end = segment.end;
  15729. var delta = segment.delta;
  15730. offsetIndex = segment.offsetIndex;
  15731. for (j = start; j <= end; j++) {
  15732. if (j === 0xFFFF) {
  15733. continue;
  15734. }
  15735. glyphId = (offsetIndex < 0 ?
  15736. j : offsets[offsetIndex + j - start]);
  15737. glyphId = (glyphId + delta) & 0xFFFF;
  15738. if (glyphId === 0) {
  15739. continue;
  15740. }
  15741. mappings.push({
  15742. charCode: j,
  15743. glyphId: glyphId
  15744. });
  15745. }
  15746. }
  15747. } else if (format === 6) {
  15748. // Format 6 is a 2-bytes dense mapping, which means the font data
  15749. // lives glue together even if they are pretty far in the unicode
  15750. // table. (This looks weird, so I can have missed something), this
  15751. // works on Linux but seems to fails on Mac so let's rewrite the
  15752. // cmap table to a 3-1-4 style
  15753. var firstCode = font.getUint16();
  15754. var entryCount = font.getUint16();
  15755. for (j = 0; j < entryCount; j++) {
  15756. glyphId = font.getUint16();
  15757. var charCode = firstCode + j;
  15758. mappings.push({
  15759. charCode: charCode,
  15760. glyphId: glyphId
  15761. });
  15762. }
  15763. } else {
  15764. error('cmap table has unsupported format: ' + format);
  15765. }
  15766. // removing duplicate entries
  15767. mappings.sort(function (a, b) {
  15768. return a.charCode - b.charCode;
  15769. });
  15770. for (i = 1; i < mappings.length; i++) {
  15771. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15772. mappings.splice(i, 1);
  15773. i--;
  15774. }
  15775. }
  15776. return {
  15777. platformId: potentialTable.platformId,
  15778. encodingId: potentialTable.encodingId,
  15779. mappings: mappings,
  15780. hasShortCmap: hasShortCmap
  15781. };
  15782. }
  15783. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15784. if (!header) {
  15785. if (metrics) {
  15786. metrics.data = null;
  15787. }
  15788. return;
  15789. }
  15790. font.pos = (font.start ? font.start : 0) + header.offset;
  15791. font.pos += header.length - 2;
  15792. var numOfMetrics = font.getUint16();
  15793. if (numOfMetrics > numGlyphs) {
  15794. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  15795. 'greater than the numGlyphs (' + numGlyphs + ')');
  15796. // Reduce numOfMetrics if it is greater than numGlyphs
  15797. numOfMetrics = numGlyphs;
  15798. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  15799. header.data[35] = numOfMetrics & 0x00ff;
  15800. }
  15801. var numOfSidebearings = numGlyphs - numOfMetrics;
  15802. var numMissing = numOfSidebearings -
  15803. ((metrics.length - numOfMetrics * 4) >> 1);
  15804. if (numMissing > 0) {
  15805. // For each missing glyph, we set both the width and lsb to 0 (zero).
  15806. // Since we need to add two properties for each glyph, this explains
  15807. // the use of |numMissing * 2| when initializing the typed array.
  15808. var entries = new Uint8Array(metrics.length + numMissing * 2);
  15809. entries.set(metrics.data);
  15810. metrics.data = entries;
  15811. }
  15812. }
  15813. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  15814. hintsValid) {
  15815. if (sourceEnd - sourceStart <= 12) {
  15816. // glyph with data less than 12 is invalid one
  15817. return 0;
  15818. }
  15819. var glyf = source.subarray(sourceStart, sourceEnd);
  15820. var contoursCount = (glyf[0] << 8) | glyf[1];
  15821. if (contoursCount & 0x8000) {
  15822. // complex glyph, writing as is
  15823. dest.set(glyf, destStart);
  15824. return glyf.length;
  15825. }
  15826. var i, j = 10, flagsCount = 0;
  15827. for (i = 0; i < contoursCount; i++) {
  15828. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  15829. flagsCount = endPoint + 1;
  15830. j += 2;
  15831. }
  15832. // skipping instructions
  15833. var instructionsStart = j;
  15834. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  15835. j += 2 + instructionsLength;
  15836. var instructionsEnd = j;
  15837. // validating flags
  15838. var coordinatesLength = 0;
  15839. for (i = 0; i < flagsCount; i++) {
  15840. var flag = glyf[j++];
  15841. if (flag & 0xC0) {
  15842. // reserved flags must be zero, cleaning up
  15843. glyf[j - 1] = flag & 0x3F;
  15844. }
  15845. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  15846. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  15847. coordinatesLength += xyLength;
  15848. if (flag & 8) {
  15849. var repeat = glyf[j++];
  15850. i += repeat;
  15851. coordinatesLength += repeat * xyLength;
  15852. }
  15853. }
  15854. // glyph without coordinates will be rejected
  15855. if (coordinatesLength === 0) {
  15856. return 0;
  15857. }
  15858. var glyphDataLength = j + coordinatesLength;
  15859. if (glyphDataLength > glyf.length) {
  15860. // not enough data for coordinates
  15861. return 0;
  15862. }
  15863. if (!hintsValid && instructionsLength > 0) {
  15864. dest.set(glyf.subarray(0, instructionsStart), destStart);
  15865. dest.set([0, 0], destStart + instructionsStart);
  15866. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  15867. destStart + instructionsStart + 2);
  15868. glyphDataLength -= instructionsLength;
  15869. if (glyf.length - glyphDataLength > 3) {
  15870. glyphDataLength = (glyphDataLength + 3) & ~3;
  15871. }
  15872. return glyphDataLength;
  15873. }
  15874. if (glyf.length - glyphDataLength > 3) {
  15875. // truncating and aligning to 4 bytes the long glyph data
  15876. glyphDataLength = (glyphDataLength + 3) & ~3;
  15877. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  15878. return glyphDataLength;
  15879. }
  15880. // glyph data is fine
  15881. dest.set(glyf, destStart);
  15882. return glyf.length;
  15883. }
  15884. function sanitizeHead(head, numGlyphs, locaLength) {
  15885. var data = head.data;
  15886. // Validate version:
  15887. // Should always be 0x00010000
  15888. var version = int32(data[0], data[1], data[2], data[3]);
  15889. if (version >> 16 !== 1) {
  15890. info('Attempting to fix invalid version in head table: ' + version);
  15891. data[0] = 0;
  15892. data[1] = 1;
  15893. data[2] = 0;
  15894. data[3] = 0;
  15895. }
  15896. var indexToLocFormat = int16(data[50], data[51]);
  15897. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  15898. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  15899. indexToLocFormat);
  15900. // The value of indexToLocFormat should be 0 if the loca table
  15901. // consists of short offsets, and should be 1 if the loca table
  15902. // consists of long offsets.
  15903. //
  15904. // The number of entries in the loca table should be numGlyphs + 1.
  15905. //
  15906. // Using this information, we can work backwards to deduce if the
  15907. // size of each offset in the loca table, and thus figure out the
  15908. // appropriate value for indexToLocFormat.
  15909. var numGlyphsPlusOne = numGlyphs + 1;
  15910. if (locaLength === numGlyphsPlusOne << 1) {
  15911. // 0x0000 indicates the loca table consists of short offsets
  15912. data[50] = 0;
  15913. data[51] = 0;
  15914. } else if (locaLength === numGlyphsPlusOne << 2) {
  15915. // 0x0001 indicates the loca table consists of long offsets
  15916. data[50] = 0;
  15917. data[51] = 1;
  15918. } else {
  15919. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  15920. }
  15921. }
  15922. }
  15923. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  15924. isGlyphLocationsLong, hintsValid,
  15925. dupFirstEntry) {
  15926. var itemSize, itemDecode, itemEncode;
  15927. if (isGlyphLocationsLong) {
  15928. itemSize = 4;
  15929. itemDecode = function fontItemDecodeLong(data, offset) {
  15930. return (data[offset] << 24) | (data[offset + 1] << 16) |
  15931. (data[offset + 2] << 8) | data[offset + 3];
  15932. };
  15933. itemEncode = function fontItemEncodeLong(data, offset, value) {
  15934. data[offset] = (value >>> 24) & 0xFF;
  15935. data[offset + 1] = (value >> 16) & 0xFF;
  15936. data[offset + 2] = (value >> 8) & 0xFF;
  15937. data[offset + 3] = value & 0xFF;
  15938. };
  15939. } else {
  15940. itemSize = 2;
  15941. itemDecode = function fontItemDecode(data, offset) {
  15942. return (data[offset] << 9) | (data[offset + 1] << 1);
  15943. };
  15944. itemEncode = function fontItemEncode(data, offset, value) {
  15945. data[offset] = (value >> 9) & 0xFF;
  15946. data[offset + 1] = (value >> 1) & 0xFF;
  15947. };
  15948. }
  15949. var locaData = loca.data;
  15950. var locaDataSize = itemSize * (1 + numGlyphs);
  15951. // is loca.data too short or long?
  15952. if (locaData.length !== locaDataSize) {
  15953. locaData = new Uint8Array(locaDataSize);
  15954. locaData.set(loca.data.subarray(0, locaDataSize));
  15955. loca.data = locaData;
  15956. }
  15957. // removing the invalid glyphs
  15958. var oldGlyfData = glyf.data;
  15959. var oldGlyfDataLength = oldGlyfData.length;
  15960. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  15961. var startOffset = itemDecode(locaData, 0);
  15962. var writeOffset = 0;
  15963. itemEncode(locaData, 0, writeOffset);
  15964. var i, j;
  15965. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15966. var endOffset = itemDecode(locaData, j);
  15967. if (endOffset > oldGlyfDataLength &&
  15968. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  15969. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  15970. // the glyf table size, which makes last glyph out of range.
  15971. endOffset = oldGlyfDataLength;
  15972. }
  15973. if (endOffset > oldGlyfDataLength) {
  15974. // glyph end offset points outside glyf data, rejecting the glyph
  15975. itemEncode(locaData, j, writeOffset);
  15976. startOffset = endOffset;
  15977. continue;
  15978. }
  15979. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  15980. newGlyfData, writeOffset, hintsValid);
  15981. writeOffset += newLength;
  15982. itemEncode(locaData, j, writeOffset);
  15983. startOffset = endOffset;
  15984. }
  15985. if (writeOffset === 0) {
  15986. // glyf table cannot be empty -- redoing the glyf and loca tables
  15987. // to have single glyph with one point
  15988. var simpleGlyph = new Uint8Array(
  15989. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  15990. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15991. itemEncode(locaData, j, simpleGlyph.length);
  15992. }
  15993. glyf.data = simpleGlyph;
  15994. return;
  15995. }
  15996. if (dupFirstEntry) {
  15997. var firstEntryLength = itemDecode(locaData, itemSize);
  15998. if (newGlyfData.length > firstEntryLength + writeOffset) {
  15999. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16000. } else {
  16001. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16002. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16003. }
  16004. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16005. itemEncode(loca.data, locaData.length - itemSize,
  16006. writeOffset + firstEntryLength);
  16007. } else {
  16008. glyf.data = newGlyfData.subarray(0, writeOffset);
  16009. }
  16010. }
  16011. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16012. var start = (font.start ? font.start : 0) + post.offset;
  16013. font.pos = start;
  16014. var length = post.length, end = start + length;
  16015. var version = font.getInt32();
  16016. // skip rest to the tables
  16017. font.getBytes(28);
  16018. var glyphNames;
  16019. var valid = true;
  16020. var i;
  16021. switch (version) {
  16022. case 0x00010000:
  16023. glyphNames = MacStandardGlyphOrdering;
  16024. break;
  16025. case 0x00020000:
  16026. var numGlyphs = font.getUint16();
  16027. if (numGlyphs !== maxpNumGlyphs) {
  16028. valid = false;
  16029. break;
  16030. }
  16031. var glyphNameIndexes = [];
  16032. for (i = 0; i < numGlyphs; ++i) {
  16033. var index = font.getUint16();
  16034. if (index >= 32768) {
  16035. valid = false;
  16036. break;
  16037. }
  16038. glyphNameIndexes.push(index);
  16039. }
  16040. if (!valid) {
  16041. break;
  16042. }
  16043. var customNames = [];
  16044. var strBuf = [];
  16045. while (font.pos < end) {
  16046. var stringLength = font.getByte();
  16047. strBuf.length = stringLength;
  16048. for (i = 0; i < stringLength; ++i) {
  16049. strBuf[i] = String.fromCharCode(font.getByte());
  16050. }
  16051. customNames.push(strBuf.join(''));
  16052. }
  16053. glyphNames = [];
  16054. for (i = 0; i < numGlyphs; ++i) {
  16055. var j = glyphNameIndexes[i];
  16056. if (j < 258) {
  16057. glyphNames.push(MacStandardGlyphOrdering[j]);
  16058. continue;
  16059. }
  16060. glyphNames.push(customNames[j - 258]);
  16061. }
  16062. break;
  16063. case 0x00030000:
  16064. break;
  16065. default:
  16066. warn('Unknown/unsupported post table version ' + version);
  16067. valid = false;
  16068. break;
  16069. }
  16070. properties.glyphNames = glyphNames;
  16071. return valid;
  16072. }
  16073. function readNameTable(nameTable) {
  16074. var start = (font.start ? font.start : 0) + nameTable.offset;
  16075. font.pos = start;
  16076. var names = [[], []];
  16077. var length = nameTable.length, end = start + length;
  16078. var format = font.getUint16();
  16079. var FORMAT_0_HEADER_LENGTH = 6;
  16080. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16081. // unsupported name table format or table "too" small
  16082. return names;
  16083. }
  16084. var numRecords = font.getUint16();
  16085. var stringsStart = font.getUint16();
  16086. var records = [];
  16087. var NAME_RECORD_LENGTH = 12;
  16088. var i, ii;
  16089. for (i = 0; i < numRecords &&
  16090. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16091. var r = {
  16092. platform: font.getUint16(),
  16093. encoding: font.getUint16(),
  16094. language: font.getUint16(),
  16095. name: font.getUint16(),
  16096. length: font.getUint16(),
  16097. offset: font.getUint16()
  16098. };
  16099. // using only Macintosh and Windows platform/encoding names
  16100. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16101. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16102. records.push(r);
  16103. }
  16104. }
  16105. for (i = 0, ii = records.length; i < ii; i++) {
  16106. var record = records[i];
  16107. var pos = start + stringsStart + record.offset;
  16108. if (pos + record.length > end) {
  16109. continue; // outside of name table, ignoring
  16110. }
  16111. font.pos = pos;
  16112. var nameIndex = record.name;
  16113. if (record.encoding) {
  16114. // unicode
  16115. var str = '';
  16116. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16117. str += String.fromCharCode(font.getUint16());
  16118. }
  16119. names[1][nameIndex] = str;
  16120. } else {
  16121. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16122. }
  16123. }
  16124. return names;
  16125. }
  16126. var TTOpsStackDeltas = [
  16127. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16128. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16129. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16130. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16131. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16132. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16133. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16134. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16135. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16136. // 0xC0-DF == -1 and 0xE0-FF == -2
  16137. function sanitizeTTProgram(table, ttContext) {
  16138. var data = table.data;
  16139. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16140. var stack = [];
  16141. var callstack = [];
  16142. var functionsCalled = [];
  16143. var tooComplexToFollowFunctions =
  16144. ttContext.tooComplexToFollowFunctions;
  16145. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16146. for (var ii = data.length; i < ii;) {
  16147. var op = data[i++];
  16148. // The TrueType instruction set docs can be found at
  16149. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16150. if (op === 0x40) { // NPUSHB - pushes n bytes
  16151. n = data[i++];
  16152. if (inFDEF || inELSE) {
  16153. i += n;
  16154. } else {
  16155. for (j = 0; j < n; j++) {
  16156. stack.push(data[i++]);
  16157. }
  16158. }
  16159. } else if (op === 0x41) { // NPUSHW - pushes n words
  16160. n = data[i++];
  16161. if (inFDEF || inELSE) {
  16162. i += n * 2;
  16163. } else {
  16164. for (j = 0; j < n; j++) {
  16165. b = data[i++];
  16166. stack.push((b << 8) | data[i++]);
  16167. }
  16168. }
  16169. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16170. n = op - 0xB0 + 1;
  16171. if (inFDEF || inELSE) {
  16172. i += n;
  16173. } else {
  16174. for (j = 0; j < n; j++) {
  16175. stack.push(data[i++]);
  16176. }
  16177. }
  16178. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16179. n = op - 0xB8 + 1;
  16180. if (inFDEF || inELSE) {
  16181. i += n * 2;
  16182. } else {
  16183. for (j = 0; j < n; j++) {
  16184. b = data[i++];
  16185. stack.push((b << 8) | data[i++]);
  16186. }
  16187. }
  16188. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16189. if (!inFDEF && !inELSE) {
  16190. // collecting inforamtion about which functions are used
  16191. funcId = stack[stack.length - 1];
  16192. ttContext.functionsUsed[funcId] = true;
  16193. if (funcId in ttContext.functionsStackDeltas) {
  16194. stack.length += ttContext.functionsStackDeltas[funcId];
  16195. } else if (funcId in ttContext.functionsDefined &&
  16196. functionsCalled.indexOf(funcId) < 0) {
  16197. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16198. functionsCalled.push(funcId);
  16199. pc = ttContext.functionsDefined[funcId];
  16200. if (!pc) {
  16201. warn('TT: CALL non-existent function');
  16202. ttContext.hintsValid = false;
  16203. return;
  16204. }
  16205. data = pc.data;
  16206. i = pc.i;
  16207. }
  16208. }
  16209. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16210. if (inFDEF || inELSE) {
  16211. warn('TT: nested FDEFs not allowed');
  16212. tooComplexToFollowFunctions = true;
  16213. }
  16214. inFDEF = true;
  16215. // collecting inforamtion about which functions are defined
  16216. lastDeff = i;
  16217. funcId = stack.pop();
  16218. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16219. } else if (op === 0x2D) { // ENDF - end of function
  16220. if (inFDEF) {
  16221. inFDEF = false;
  16222. lastEndf = i;
  16223. } else {
  16224. pc = callstack.pop();
  16225. if (!pc) {
  16226. warn('TT: ENDF bad stack');
  16227. ttContext.hintsValid = false;
  16228. return;
  16229. }
  16230. funcId = functionsCalled.pop();
  16231. data = pc.data;
  16232. i = pc.i;
  16233. ttContext.functionsStackDeltas[funcId] =
  16234. stack.length - pc.stackTop;
  16235. }
  16236. } else if (op === 0x89) { // IDEF - instruction definition
  16237. if (inFDEF || inELSE) {
  16238. warn('TT: nested IDEFs not allowed');
  16239. tooComplexToFollowFunctions = true;
  16240. }
  16241. inFDEF = true;
  16242. // recording it as a function to track ENDF
  16243. lastDeff = i;
  16244. } else if (op === 0x58) { // IF
  16245. ++ifLevel;
  16246. } else if (op === 0x1B) { // ELSE
  16247. inELSE = ifLevel;
  16248. } else if (op === 0x59) { // EIF
  16249. if (inELSE === ifLevel) {
  16250. inELSE = 0;
  16251. }
  16252. --ifLevel;
  16253. } else if (op === 0x1C) { // JMPR
  16254. if (!inFDEF && !inELSE) {
  16255. var offset = stack[stack.length - 1];
  16256. // only jumping forward to prevent infinite loop
  16257. if (offset > 0) {
  16258. i += offset - 1;
  16259. }
  16260. }
  16261. }
  16262. // Adjusting stack not extactly, but just enough to get function id
  16263. if (!inFDEF && !inELSE) {
  16264. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16265. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16266. if (op >= 0x71 && op <= 0x75) {
  16267. n = stack.pop();
  16268. if (n === n) {
  16269. stackDelta = -n * 2;
  16270. }
  16271. }
  16272. while (stackDelta < 0 && stack.length > 0) {
  16273. stack.pop();
  16274. stackDelta++;
  16275. }
  16276. while (stackDelta > 0) {
  16277. stack.push(NaN); // pushing any number into stack
  16278. stackDelta--;
  16279. }
  16280. }
  16281. }
  16282. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16283. var content = [data];
  16284. if (i > data.length) {
  16285. content.push(new Uint8Array(i - data.length));
  16286. }
  16287. if (lastDeff > lastEndf) {
  16288. warn('TT: complementing a missing function tail');
  16289. // new function definition started, but not finished
  16290. // complete function by [CLEAR, ENDF]
  16291. content.push(new Uint8Array([0x22, 0x2D]));
  16292. }
  16293. foldTTTable(table, content);
  16294. }
  16295. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16296. if (ttContext.tooComplexToFollowFunctions) {
  16297. return;
  16298. }
  16299. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16300. warn('TT: more functions defined than expected');
  16301. ttContext.hintsValid = false;
  16302. return;
  16303. }
  16304. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16305. if (j > maxFunctionDefs) {
  16306. warn('TT: invalid function id: ' + j);
  16307. ttContext.hintsValid = false;
  16308. return;
  16309. }
  16310. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16311. warn('TT: undefined function: ' + j);
  16312. ttContext.hintsValid = false;
  16313. return;
  16314. }
  16315. }
  16316. }
  16317. function foldTTTable(table, content) {
  16318. if (content.length > 1) {
  16319. // concatenating the content items
  16320. var newLength = 0;
  16321. var j, jj;
  16322. for (j = 0, jj = content.length; j < jj; j++) {
  16323. newLength += content[j].length;
  16324. }
  16325. newLength = (newLength + 3) & ~3;
  16326. var result = new Uint8Array(newLength);
  16327. var pos = 0;
  16328. for (j = 0, jj = content.length; j < jj; j++) {
  16329. result.set(content[j], pos);
  16330. pos += content[j].length;
  16331. }
  16332. table.data = result;
  16333. table.length = newLength;
  16334. }
  16335. }
  16336. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16337. var ttContext = {
  16338. functionsDefined: [],
  16339. functionsUsed: [],
  16340. functionsStackDeltas: [],
  16341. tooComplexToFollowFunctions: false,
  16342. hintsValid: true
  16343. };
  16344. if (fpgm) {
  16345. sanitizeTTProgram(fpgm, ttContext);
  16346. }
  16347. if (prep) {
  16348. sanitizeTTProgram(prep, ttContext);
  16349. }
  16350. if (fpgm) {
  16351. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16352. }
  16353. if (cvt && (cvt.length & 1)) {
  16354. var cvtData = new Uint8Array(cvt.length + 1);
  16355. cvtData.set(cvt.data);
  16356. cvt.data = cvtData;
  16357. }
  16358. return ttContext.hintsValid;
  16359. }
  16360. // The following steps modify the original font data, making copy
  16361. font = new Stream(new Uint8Array(font.getBytes()));
  16362. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16363. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16364. var header = readOpenTypeHeader(font);
  16365. var numTables = header.numTables;
  16366. var cff, cffFile;
  16367. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16368. hmtx: null, maxp: null, name: null, post: null };
  16369. var table;
  16370. for (var i = 0; i < numTables; i++) {
  16371. table = readTableEntry(font);
  16372. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16373. continue; // skipping table if it's not a required or optional table
  16374. }
  16375. if (table.length === 0) {
  16376. continue; // skipping empty tables
  16377. }
  16378. tables[table.tag] = table;
  16379. }
  16380. var isTrueType = !tables['CFF '];
  16381. if (!isTrueType) {
  16382. // OpenType font
  16383. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16384. // no major tables: throwing everything at CFFFont
  16385. cffFile = new Stream(tables['CFF '].data);
  16386. cff = new CFFFont(cffFile, properties);
  16387. return this.convert(name, cff, properties);
  16388. }
  16389. delete tables.glyf;
  16390. delete tables.loca;
  16391. delete tables.fpgm;
  16392. delete tables.prep;
  16393. delete tables['cvt '];
  16394. this.isOpenType = true;
  16395. } else {
  16396. if (!tables.glyf || !tables.loca) {
  16397. error('Required "glyf" or "loca" tables are not found');
  16398. }
  16399. this.isOpenType = false;
  16400. }
  16401. if (!tables.maxp) {
  16402. error('Required "maxp" table is not found');
  16403. }
  16404. font.pos = (font.start || 0) + tables.maxp.offset;
  16405. var version = font.getInt32();
  16406. var numGlyphs = font.getUint16();
  16407. var maxFunctionDefs = 0;
  16408. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16409. // maxZones can be invalid
  16410. font.pos += 8;
  16411. var maxZones = font.getUint16();
  16412. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16413. tables.maxp.data[14] = 0;
  16414. tables.maxp.data[15] = 2;
  16415. }
  16416. font.pos += 4;
  16417. maxFunctionDefs = font.getUint16();
  16418. }
  16419. var dupFirstEntry = false;
  16420. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16421. properties.toUnicode.get(0) > '\u0000') {
  16422. // oracle's defect (see 3427), duplicating first entry
  16423. dupFirstEntry = true;
  16424. numGlyphs++;
  16425. tables.maxp.data[4] = numGlyphs >> 8;
  16426. tables.maxp.data[5] = numGlyphs & 255;
  16427. }
  16428. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16429. tables['cvt '], maxFunctionDefs);
  16430. if (!hintsValid) {
  16431. delete tables.fpgm;
  16432. delete tables.prep;
  16433. delete tables['cvt '];
  16434. }
  16435. // Ensure the hmtx table contains the advance width and
  16436. // sidebearings information for numGlyphs in the maxp table
  16437. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16438. if (!tables.head) {
  16439. error('Required "head" table is not found');
  16440. }
  16441. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16442. if (isTrueType) {
  16443. var isGlyphLocationsLong = int16(tables.head.data[50],
  16444. tables.head.data[51]);
  16445. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16446. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16447. }
  16448. if (!tables.hhea) {
  16449. error('Required "hhea" table is not found');
  16450. }
  16451. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16452. // Sometimes it's 0. That needs to be fixed
  16453. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16454. tables.hhea.data[10] = 0xFF;
  16455. tables.hhea.data[11] = 0xFF;
  16456. }
  16457. // The 'post' table has glyphs names.
  16458. if (tables.post) {
  16459. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16460. if (!valid) {
  16461. tables.post = null;
  16462. }
  16463. }
  16464. var charCodeToGlyphId = [], charCode;
  16465. if (properties.type === 'CIDFontType2') {
  16466. var cidToGidMap = properties.cidToGidMap || [];
  16467. var cidToGidMapLength = cidToGidMap.length;
  16468. properties.cMap.forEach(function(charCode, cid) {
  16469. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16470. var glyphId = -1;
  16471. if (cidToGidMapLength === 0) {
  16472. glyphId = charCode;
  16473. } else if (cidToGidMap[cid] !== undefined) {
  16474. glyphId = cidToGidMap[cid];
  16475. }
  16476. if (glyphId >= 0 && glyphId < numGlyphs) {
  16477. charCodeToGlyphId[charCode] = glyphId;
  16478. }
  16479. });
  16480. if (dupFirstEntry) {
  16481. charCodeToGlyphId[0] = numGlyphs - 1;
  16482. }
  16483. } else {
  16484. // Most of the following logic in this code branch is based on the
  16485. // 9.6.6.4 of the PDF spec.
  16486. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16487. var cmapPlatformId = cmapTable.platformId;
  16488. var cmapEncodingId = cmapTable.encodingId;
  16489. var cmapMappings = cmapTable.mappings;
  16490. var cmapMappingsLength = cmapMappings.length;
  16491. var hasEncoding = properties.differences.length ||
  16492. !!properties.baseEncodingName;
  16493. // The spec seems to imply that if the font is symbolic the encoding
  16494. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16495. // where the the font is symbolic and it has an encoding.
  16496. if (hasEncoding &&
  16497. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16498. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16499. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16500. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16501. // When no preferred cmap table was found and |baseEncodingName| is
  16502. // one of the predefined encodings, we seem to obtain a better
  16503. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16504. // TODO: Note that this is a hack which should be removed as soon as
  16505. // we have proper support for more exotic cmap tables.
  16506. var baseEncoding = [];
  16507. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16508. properties.baseEncodingName === 'WinAnsiEncoding') {
  16509. baseEncoding = Encodings[properties.baseEncodingName];
  16510. }
  16511. for (charCode = 0; charCode < 256; charCode++) {
  16512. var glyphName;
  16513. if (this.differences && charCode in this.differences) {
  16514. glyphName = this.differences[charCode];
  16515. } else if (charCode in baseEncoding &&
  16516. baseEncoding[charCode] !== '') {
  16517. glyphName = baseEncoding[charCode];
  16518. } else {
  16519. glyphName = Encodings.StandardEncoding[charCode];
  16520. }
  16521. if (!glyphName) {
  16522. continue;
  16523. }
  16524. var unicodeOrCharCode;
  16525. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16526. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16527. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16528. // TODO: the encoding needs to be updated with mac os table.
  16529. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16530. }
  16531. var found = false;
  16532. for (i = 0; i < cmapMappingsLength; ++i) {
  16533. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16534. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16535. found = true;
  16536. break;
  16537. }
  16538. }
  16539. if (!found && properties.glyphNames) {
  16540. // Try to map using the post table. There are currently no known
  16541. // pdfs that this fixes.
  16542. var glyphId = properties.glyphNames.indexOf(glyphName);
  16543. if (glyphId > 0) {
  16544. charCodeToGlyphId[charCode] = glyphId;
  16545. }
  16546. }
  16547. }
  16548. } else {
  16549. // For (3, 0) cmap tables:
  16550. // The charcode key being stored in charCodeToGlyphId is the lower
  16551. // byte of the two-byte charcodes of the cmap table since according to
  16552. // the spec: 'each byte from the string shall be prepended with the
  16553. // high byte of the range [of charcodes in the cmap table], to form
  16554. // a two-byte character, which shall be used to select the
  16555. // associated glyph description from the subtable'.
  16556. //
  16557. // For (1, 0) cmap tables:
  16558. // 'single bytes from the string shall be used to look up the
  16559. // associated glyph descriptions from the subtable'. This means
  16560. // charcodes in the cmap will be single bytes, so no-op since
  16561. // glyph.charCode & 0xFF === glyph.charCode
  16562. for (i = 0; i < cmapMappingsLength; ++i) {
  16563. charCode = cmapMappings[i].charCode & 0xFF;
  16564. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16565. }
  16566. }
  16567. }
  16568. if (charCodeToGlyphId.length === 0) {
  16569. // defines at least one glyph
  16570. charCodeToGlyphId[0] = 0;
  16571. }
  16572. // Converting glyphs and ids into font's cmap table
  16573. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16574. this.toFontChar = newMapping.toFontChar;
  16575. tables.cmap = {
  16576. tag: 'cmap',
  16577. data: createCmapTable(newMapping.charCodeToGlyphId)
  16578. };
  16579. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16580. // extract some more font properties from the OpenType head and
  16581. // hhea tables; yMin and descent value are always negative
  16582. var override = {
  16583. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16584. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16585. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16586. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16587. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16588. };
  16589. tables['OS/2'] = {
  16590. tag: 'OS/2',
  16591. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16592. override)
  16593. };
  16594. }
  16595. // Rewrite the 'post' table if needed
  16596. if (!tables.post) {
  16597. tables.post = {
  16598. tag: 'post',
  16599. data: createPostTable(properties)
  16600. };
  16601. }
  16602. if (!isTrueType) {
  16603. try {
  16604. // Trying to repair CFF file
  16605. cffFile = new Stream(tables['CFF '].data);
  16606. var parser = new CFFParser(cffFile, properties);
  16607. cff = parser.parse();
  16608. var compiler = new CFFCompiler(cff);
  16609. tables['CFF '].data = compiler.compile();
  16610. } catch (e) {
  16611. warn('Failed to compile font ' + properties.loadedName);
  16612. }
  16613. }
  16614. // Re-creating 'name' table
  16615. if (!tables.name) {
  16616. tables.name = {
  16617. tag: 'name',
  16618. data: createNameTable(this.name)
  16619. };
  16620. } else {
  16621. // ... using existing 'name' table as prototype
  16622. var namePrototype = readNameTable(tables.name);
  16623. tables.name.data = createNameTable(name, namePrototype);
  16624. }
  16625. var builder = new OpenTypeFileBuilder(header.version);
  16626. for (var tableTag in tables) {
  16627. builder.addTable(tableTag, tables[tableTag].data);
  16628. }
  16629. return builder.toArray();
  16630. },
  16631. convert: function Font_convert(fontName, font, properties) {
  16632. // TODO: Check the charstring widths to determine this.
  16633. properties.fixedPitch = false;
  16634. var mapping = font.getGlyphMapping(properties);
  16635. var newMapping = adjustMapping(mapping, properties);
  16636. this.toFontChar = newMapping.toFontChar;
  16637. var numGlyphs = font.numGlyphs;
  16638. function getCharCodes(charCodeToGlyphId, glyphId) {
  16639. var charCodes = null;
  16640. for (var charCode in charCodeToGlyphId) {
  16641. if (glyphId === charCodeToGlyphId[charCode]) {
  16642. if (!charCodes) {
  16643. charCodes = [];
  16644. }
  16645. charCodes.push(charCode | 0);
  16646. }
  16647. }
  16648. return charCodes;
  16649. }
  16650. function createCharCode(charCodeToGlyphId, glyphId) {
  16651. for (var charCode in charCodeToGlyphId) {
  16652. if (glyphId === charCodeToGlyphId[charCode]) {
  16653. return charCode | 0;
  16654. }
  16655. }
  16656. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16657. glyphId;
  16658. return newMapping.nextAvailableFontCharCode++;
  16659. }
  16660. var seacs = font.seacs;
  16661. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16662. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16663. var charset = font.getCharset();
  16664. var seacMap = Object.create(null);
  16665. for (var glyphId in seacs) {
  16666. glyphId |= 0;
  16667. var seac = seacs[glyphId];
  16668. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16669. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16670. var baseGlyphId = charset.indexOf(baseGlyphName);
  16671. var accentGlyphId = charset.indexOf(accentGlyphName);
  16672. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16673. continue;
  16674. }
  16675. var accentOffset = {
  16676. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16677. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16678. };
  16679. var charCodes = getCharCodes(mapping, glyphId);
  16680. if (!charCodes) {
  16681. // There's no point in mapping it if the char code was never mapped
  16682. // to begin with.
  16683. continue;
  16684. }
  16685. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16686. var charCode = charCodes[i];
  16687. // Find a fontCharCode that maps to the base and accent glyphs.
  16688. // If one doesn't exists, create it.
  16689. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16690. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16691. baseGlyphId);
  16692. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16693. accentGlyphId);
  16694. seacMap[charCode] = {
  16695. baseFontCharCode: baseFontCharCode,
  16696. accentFontCharCode: accentFontCharCode,
  16697. accentOffset: accentOffset
  16698. };
  16699. }
  16700. }
  16701. properties.seacMap = seacMap;
  16702. }
  16703. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16704. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16705. // PostScript Font Program
  16706. builder.addTable('CFF ', font.data);
  16707. // OS/2 and Windows Specific metrics
  16708. builder.addTable('OS/2', createOS2Table(properties,
  16709. newMapping.charCodeToGlyphId));
  16710. // Character to glyphs mapping
  16711. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16712. // Font header
  16713. builder.addTable('head',
  16714. '\x00\x01\x00\x00' + // Version number
  16715. '\x00\x00\x10\x00' + // fontRevision
  16716. '\x00\x00\x00\x00' + // checksumAdjustement
  16717. '\x5F\x0F\x3C\xF5' + // magicNumber
  16718. '\x00\x00' + // Flags
  16719. safeString16(unitsPerEm) + // unitsPerEM
  16720. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16721. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16722. '\x00\x00' + // xMin
  16723. safeString16(properties.descent) + // yMin
  16724. '\x0F\xFF' + // xMax
  16725. safeString16(properties.ascent) + // yMax
  16726. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16727. '\x00\x11' + // lowestRecPPEM
  16728. '\x00\x00' + // fontDirectionHint
  16729. '\x00\x00' + // indexToLocFormat
  16730. '\x00\x00'); // glyphDataFormat
  16731. // Horizontal header
  16732. builder.addTable('hhea',
  16733. '\x00\x01\x00\x00' + // Version number
  16734. safeString16(properties.ascent) + // Typographic Ascent
  16735. safeString16(properties.descent) + // Typographic Descent
  16736. '\x00\x00' + // Line Gap
  16737. '\xFF\xFF' + // advanceWidthMax
  16738. '\x00\x00' + // minLeftSidebearing
  16739. '\x00\x00' + // minRightSidebearing
  16740. '\x00\x00' + // xMaxExtent
  16741. safeString16(properties.capHeight) + // caretSlopeRise
  16742. safeString16(Math.tan(properties.italicAngle) *
  16743. properties.xHeight) + // caretSlopeRun
  16744. '\x00\x00' + // caretOffset
  16745. '\x00\x00' + // -reserved-
  16746. '\x00\x00' + // -reserved-
  16747. '\x00\x00' + // -reserved-
  16748. '\x00\x00' + // -reserved-
  16749. '\x00\x00' + // metricDataFormat
  16750. string16(numGlyphs)); // Number of HMetrics
  16751. // Horizontal metrics
  16752. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16753. var charstrings = font.charstrings;
  16754. var cffWidths = font.cff ? font.cff.widths : null;
  16755. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16756. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16757. var width = 0;
  16758. if (charstrings) {
  16759. var charstring = charstrings[i - 1];
  16760. width = 'width' in charstring ? charstring.width : 0;
  16761. } else if (cffWidths) {
  16762. width = Math.ceil(cffWidths[i] || 0);
  16763. }
  16764. hmtx += string16(width) + string16(0);
  16765. }
  16766. return hmtx;
  16767. })());
  16768. // Maximum profile
  16769. builder.addTable('maxp',
  16770. '\x00\x00\x50\x00' + // Version number
  16771. string16(numGlyphs)); // Num of glyphs
  16772. // Naming tables
  16773. builder.addTable('name', createNameTable(fontName));
  16774. // PostScript informations
  16775. builder.addTable('post', createPostTable(properties));
  16776. return builder.toArray();
  16777. },
  16778. /**
  16779. * Builds a char code to unicode map based on section 9.10 of the spec.
  16780. * @param {Object} properties Font properties object.
  16781. * @return {Object} A ToUnicodeMap object.
  16782. */
  16783. buildToUnicode: function Font_buildToUnicode(properties) {
  16784. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16785. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16786. return properties.toUnicode;
  16787. }
  16788. // According to the spec if the font is a simple font we should only map
  16789. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16790. // the differences array only contains adobe standard or symbol set names,
  16791. // in pratice it seems better to always try to create a toUnicode
  16792. // map based of the default encoding.
  16793. var toUnicode, charcode;
  16794. if (!properties.composite /* is simple font */) {
  16795. toUnicode = [];
  16796. var encoding = properties.defaultEncoding.slice();
  16797. var baseEncodingName = properties.baseEncodingName;
  16798. // Merge in the differences array.
  16799. var differences = properties.differences;
  16800. for (charcode in differences) {
  16801. encoding[charcode] = differences[charcode];
  16802. }
  16803. for (charcode in encoding) {
  16804. // a) Map the character code to a character name.
  16805. var glyphName = encoding[charcode];
  16806. // b) Look up the character name in the Adobe Glyph List (see the
  16807. // Bibliography) to obtain the corresponding Unicode value.
  16808. if (glyphName === '') {
  16809. continue;
  16810. } else if (GlyphsUnicode[glyphName] === undefined) {
  16811. // (undocumented) c) Few heuristics to recognize unknown glyphs
  16812. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  16813. var code = 0;
  16814. switch (glyphName[0]) {
  16815. case 'G': // Gxx glyph
  16816. if (glyphName.length === 3) {
  16817. code = parseInt(glyphName.substr(1), 16);
  16818. }
  16819. break;
  16820. case 'g': // g00xx glyph
  16821. if (glyphName.length === 5) {
  16822. code = parseInt(glyphName.substr(1), 16);
  16823. }
  16824. break;
  16825. case 'C': // Cddd glyph
  16826. case 'c': // cddd glyph
  16827. if (glyphName.length >= 3) {
  16828. code = +glyphName.substr(1);
  16829. }
  16830. break;
  16831. }
  16832. if (code) {
  16833. // If |baseEncodingName| is one the predefined encodings,
  16834. // and |code| equals |charcode|, using the glyph defined in the
  16835. // baseEncoding seems to yield a better |toUnicode| mapping
  16836. // (fixes issue 5070).
  16837. if (baseEncodingName && code === +charcode) {
  16838. var baseEncoding = Encodings[baseEncodingName];
  16839. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  16840. toUnicode[charcode] =
  16841. String.fromCharCode(GlyphsUnicode[glyphName]);
  16842. continue;
  16843. }
  16844. }
  16845. toUnicode[charcode] = String.fromCharCode(code);
  16846. }
  16847. continue;
  16848. }
  16849. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  16850. }
  16851. return new ToUnicodeMap(toUnicode);
  16852. }
  16853. // If the font is a composite font that uses one of the predefined CMaps
  16854. // listed in Table 118 (except Identity–H and Identity–V) or whose
  16855. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  16856. // Adobe-Korea1 character collection:
  16857. if (properties.composite && (
  16858. (properties.cMap.builtInCMap &&
  16859. !(properties.cMap instanceof IdentityCMap)) ||
  16860. (properties.cidSystemInfo.registry === 'Adobe' &&
  16861. (properties.cidSystemInfo.ordering === 'GB1' ||
  16862. properties.cidSystemInfo.ordering === 'CNS1' ||
  16863. properties.cidSystemInfo.ordering === 'Japan1' ||
  16864. properties.cidSystemInfo.ordering === 'Korea1')))) {
  16865. // Then:
  16866. // a) Map the character code to a character identifier (CID) according
  16867. // to the font’s CMap.
  16868. // b) Obtain the registry and ordering of the character collection used
  16869. // by the font’s CMap (for example, Adobe and Japan1) from its
  16870. // CIDSystemInfo dictionary.
  16871. var registry = properties.cidSystemInfo.registry;
  16872. var ordering = properties.cidSystemInfo.ordering;
  16873. // c) Construct a second CMap name by concatenating the registry and
  16874. // ordering obtained in step (b) in the format registry–ordering–UCS2
  16875. // (for example, Adobe–Japan1–UCS2).
  16876. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  16877. // d) Obtain the CMap with the name constructed in step (c) (available
  16878. // from the ASN Web site; see the Bibliography).
  16879. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  16880. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16881. var cMap = properties.cMap;
  16882. toUnicode = [];
  16883. cMap.forEach(function(charcode, cid) {
  16884. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16885. // e) Map the CID obtained in step (a) according to the CMap obtained
  16886. // in step (d), producing a Unicode value.
  16887. var ucs2 = ucs2CMap.lookup(cid);
  16888. if (ucs2) {
  16889. toUnicode[charcode] =
  16890. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  16891. ucs2.charCodeAt(1));
  16892. }
  16893. });
  16894. return new ToUnicodeMap(toUnicode);
  16895. }
  16896. // The viewer's choice, just use an identity map.
  16897. return new IdentityToUnicodeMap(properties.firstChar,
  16898. properties.lastChar);
  16899. },
  16900. get spaceWidth() {
  16901. if ('_shadowWidth' in this) {
  16902. return this._shadowWidth;
  16903. }
  16904. // trying to estimate space character width
  16905. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  16906. var width;
  16907. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  16908. var glyphName = possibleSpaceReplacements[i];
  16909. // if possible, getting width by glyph name
  16910. if (glyphName in this.widths) {
  16911. width = this.widths[glyphName];
  16912. break;
  16913. }
  16914. var glyphUnicode = GlyphsUnicode[glyphName];
  16915. // finding the charcode via unicodeToCID map
  16916. var charcode = 0;
  16917. if (this.composite) {
  16918. if (this.cMap.contains(glyphUnicode)) {
  16919. charcode = this.cMap.lookup(glyphUnicode);
  16920. }
  16921. }
  16922. // ... via toUnicode map
  16923. if (!charcode && 'toUnicode' in this) {
  16924. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  16925. }
  16926. // setting it to unicode if negative or undefined
  16927. if (charcode <= 0) {
  16928. charcode = glyphUnicode;
  16929. }
  16930. // trying to get width via charcode
  16931. width = this.widths[charcode];
  16932. if (width) {
  16933. break; // the non-zero width found
  16934. }
  16935. }
  16936. width = width || this.defaultWidth;
  16937. // Do not shadow the property here. See discussion:
  16938. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  16939. this._shadowWidth = width;
  16940. return width;
  16941. },
  16942. charToGlyph: function Font_charToGlyph(charcode) {
  16943. var fontCharCode, width, operatorListId;
  16944. var widthCode = charcode;
  16945. if (this.cMap && this.cMap.contains(charcode)) {
  16946. widthCode = this.cMap.lookup(charcode);
  16947. }
  16948. width = this.widths[widthCode];
  16949. width = isNum(width) ? width : this.defaultWidth;
  16950. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  16951. var unicode = this.toUnicode.get(charcode) || charcode;
  16952. if (typeof unicode === 'number') {
  16953. unicode = String.fromCharCode(unicode);
  16954. }
  16955. // First try the toFontChar map, if it's not there then try falling
  16956. // back to the char code.
  16957. fontCharCode = this.toFontChar[charcode] || charcode;
  16958. if (this.missingFile) {
  16959. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  16960. }
  16961. if (this.isType3Font) {
  16962. // Font char code in this case is actually a glyph name.
  16963. operatorListId = fontCharCode;
  16964. }
  16965. var accent = null;
  16966. if (this.seacMap && this.seacMap[charcode]) {
  16967. var seac = this.seacMap[charcode];
  16968. fontCharCode = seac.baseFontCharCode;
  16969. accent = {
  16970. fontChar: String.fromCharCode(seac.accentFontCharCode),
  16971. offset: seac.accentOffset
  16972. };
  16973. }
  16974. var fontChar = String.fromCharCode(fontCharCode);
  16975. var glyph = this.glyphCache[charcode];
  16976. if (!glyph ||
  16977. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  16978. operatorListId)) {
  16979. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  16980. operatorListId);
  16981. this.glyphCache[charcode] = glyph;
  16982. }
  16983. return glyph;
  16984. },
  16985. charsToGlyphs: function Font_charsToGlyphs(chars) {
  16986. var charsCache = this.charsCache;
  16987. var glyphs, glyph, charcode;
  16988. // if we translated this string before, just grab it from the cache
  16989. if (charsCache) {
  16990. glyphs = charsCache[chars];
  16991. if (glyphs) {
  16992. return glyphs;
  16993. }
  16994. }
  16995. // lazily create the translation cache
  16996. if (!charsCache) {
  16997. charsCache = this.charsCache = Object.create(null);
  16998. }
  16999. glyphs = [];
  17000. var charsCacheKey = chars;
  17001. var i = 0, ii;
  17002. if (this.cMap) {
  17003. // composite fonts have multi-byte strings convert the string from
  17004. // single-byte to multi-byte
  17005. var c = {};
  17006. while (i < chars.length) {
  17007. this.cMap.readCharCode(chars, i, c);
  17008. charcode = c.charcode;
  17009. var length = c.length;
  17010. i += length;
  17011. glyph = this.charToGlyph(charcode);
  17012. glyphs.push(glyph);
  17013. // placing null after each word break charcode (ASCII SPACE)
  17014. // Ignore occurences of 0x20 in multiple-byte codes.
  17015. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17016. glyphs.push(null);
  17017. }
  17018. }
  17019. } else {
  17020. for (i = 0, ii = chars.length; i < ii; ++i) {
  17021. charcode = chars.charCodeAt(i);
  17022. glyph = this.charToGlyph(charcode);
  17023. glyphs.push(glyph);
  17024. if (charcode === 0x20) {
  17025. glyphs.push(null);
  17026. }
  17027. }
  17028. }
  17029. // Enter the translated string into the cache
  17030. return (charsCache[charsCacheKey] = glyphs);
  17031. }
  17032. };
  17033. return Font;
  17034. })();
  17035. var ErrorFont = (function ErrorFontClosure() {
  17036. function ErrorFont(error) {
  17037. this.error = error;
  17038. this.loadedName = 'g_font_error';
  17039. this.loading = false;
  17040. }
  17041. ErrorFont.prototype = {
  17042. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17043. return [];
  17044. },
  17045. exportData: function ErrorFont_exportData() {
  17046. return {error: this.error};
  17047. }
  17048. };
  17049. return ErrorFont;
  17050. })();
  17051. /**
  17052. * Shared logic for building a char code to glyph id mapping for Type1 and
  17053. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17054. * @param {Object} properties Font properties object.
  17055. * @param {Object} builtInEncoding The encoding contained within the actual font
  17056. * data.
  17057. * @param {Array} Array of glyph names where the index is the glyph ID.
  17058. * @returns {Object} A char code to glyph ID map.
  17059. */
  17060. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17061. var charCodeToGlyphId = Object.create(null);
  17062. var glyphId, charCode, baseEncoding;
  17063. if (properties.baseEncodingName) {
  17064. // If a valid base encoding name was used, the mapping is initialized with
  17065. // that.
  17066. baseEncoding = Encodings[properties.baseEncodingName];
  17067. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17068. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17069. if (glyphId >= 0) {
  17070. charCodeToGlyphId[charCode] = glyphId;
  17071. }
  17072. }
  17073. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17074. // For a symbolic font the encoding should be the fonts built-in
  17075. // encoding.
  17076. for (charCode in builtInEncoding) {
  17077. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17078. }
  17079. } else {
  17080. // For non-symbolic fonts that don't have a base encoding the standard
  17081. // encoding should be used.
  17082. baseEncoding = Encodings.StandardEncoding;
  17083. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17084. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17085. if (glyphId >= 0) {
  17086. charCodeToGlyphId[charCode] = glyphId;
  17087. }
  17088. }
  17089. }
  17090. // Lastly, merge in the differences.
  17091. var differences = properties.differences;
  17092. if (differences) {
  17093. for (charCode in differences) {
  17094. var glyphName = differences[charCode];
  17095. glyphId = glyphNames.indexOf(glyphName);
  17096. if (glyphId >= 0) {
  17097. charCodeToGlyphId[charCode] = glyphId;
  17098. }
  17099. }
  17100. }
  17101. return charCodeToGlyphId;
  17102. }
  17103. /*
  17104. * CharStrings are encoded following the the CharString Encoding sequence
  17105. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17106. * The value in a byte indicates a command, a number, or subsequent bytes
  17107. * that are to be interpreted in a special way.
  17108. *
  17109. * CharString Number Encoding:
  17110. * A CharString byte containing the values from 32 through 255 inclusive
  17111. * indicate an integer. These values are decoded in four ranges.
  17112. *
  17113. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17114. * indicate the integer v - 139. Thus, the integer values from -107 through
  17115. * 107 inclusive may be encoded in single byte.
  17116. *
  17117. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17118. * indicates an integer involving the next byte, w, according to the formula:
  17119. * [(v - 247) x 256] + w + 108
  17120. *
  17121. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17122. * indicates an integer involving the next byte, w, according to the formula:
  17123. * -[(v - 251) * 256] - w - 108
  17124. *
  17125. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17126. * are a two complement signed integer. The first of these bytes contains the
  17127. * highest order bits, the second byte contains the next higher order bits
  17128. * and the fourth byte contain the lowest order bits.
  17129. *
  17130. *
  17131. * CharString Command Encoding:
  17132. * CharStrings commands are encoded in 1 or 2 bytes.
  17133. *
  17134. * Single byte commands are encoded in 1 byte that contains a value between
  17135. * 0 and 31 inclusive.
  17136. * If a command byte contains the value 12, then the value in the next byte
  17137. * indicates a command. This "escape" mechanism allows many extra commands
  17138. * to be encoded and this encoding technique helps to minimize the length of
  17139. * the charStrings.
  17140. */
  17141. var Type1CharString = (function Type1CharStringClosure() {
  17142. var COMMAND_MAP = {
  17143. 'hstem': [1],
  17144. 'vstem': [3],
  17145. 'vmoveto': [4],
  17146. 'rlineto': [5],
  17147. 'hlineto': [6],
  17148. 'vlineto': [7],
  17149. 'rrcurveto': [8],
  17150. 'callsubr': [10],
  17151. 'flex': [12, 35],
  17152. 'drop' : [12, 18],
  17153. 'endchar': [14],
  17154. 'rmoveto': [21],
  17155. 'hmoveto': [22],
  17156. 'vhcurveto': [30],
  17157. 'hvcurveto': [31]
  17158. };
  17159. function Type1CharString() {
  17160. this.width = 0;
  17161. this.lsb = 0;
  17162. this.flexing = false;
  17163. this.output = [];
  17164. this.stack = [];
  17165. }
  17166. Type1CharString.prototype = {
  17167. convert: function Type1CharString_convert(encoded, subrs) {
  17168. var count = encoded.length;
  17169. var error = false;
  17170. var wx, sbx, subrNumber;
  17171. for (var i = 0; i < count; i++) {
  17172. var value = encoded[i];
  17173. if (value < 32) {
  17174. if (value === 12) {
  17175. value = (value << 8) + encoded[++i];
  17176. }
  17177. switch (value) {
  17178. case 1: // hstem
  17179. if (!HINTING_ENABLED) {
  17180. this.stack = [];
  17181. break;
  17182. }
  17183. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17184. break;
  17185. case 3: // vstem
  17186. if (!HINTING_ENABLED) {
  17187. this.stack = [];
  17188. break;
  17189. }
  17190. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17191. break;
  17192. case 4: // vmoveto
  17193. if (this.flexing) {
  17194. if (this.stack.length < 1) {
  17195. error = true;
  17196. break;
  17197. }
  17198. // Add the dx for flex and but also swap the values so they are
  17199. // the right order.
  17200. var dy = this.stack.pop();
  17201. this.stack.push(0, dy);
  17202. break;
  17203. }
  17204. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17205. break;
  17206. case 5: // rlineto
  17207. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17208. break;
  17209. case 6: // hlineto
  17210. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17211. break;
  17212. case 7: // vlineto
  17213. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17214. break;
  17215. case 8: // rrcurveto
  17216. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17217. break;
  17218. case 9: // closepath
  17219. // closepath is a Type1 command that does not take argument and is
  17220. // useless in Type2 and it can simply be ignored.
  17221. this.stack = [];
  17222. break;
  17223. case 10: // callsubr
  17224. if (this.stack.length < 1) {
  17225. error = true;
  17226. break;
  17227. }
  17228. subrNumber = this.stack.pop();
  17229. error = this.convert(subrs[subrNumber], subrs);
  17230. break;
  17231. case 11: // return
  17232. return error;
  17233. case 13: // hsbw
  17234. if (this.stack.length < 2) {
  17235. error = true;
  17236. break;
  17237. }
  17238. // To convert to type2 we have to move the width value to the
  17239. // first part of the charstring and then use hmoveto with lsb.
  17240. wx = this.stack.pop();
  17241. sbx = this.stack.pop();
  17242. this.lsb = sbx;
  17243. this.width = wx;
  17244. this.stack.push(wx, sbx);
  17245. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17246. break;
  17247. case 14: // endchar
  17248. this.output.push(COMMAND_MAP.endchar[0]);
  17249. break;
  17250. case 21: // rmoveto
  17251. if (this.flexing) {
  17252. break;
  17253. }
  17254. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17255. break;
  17256. case 22: // hmoveto
  17257. if (this.flexing) {
  17258. // Add the dy for flex.
  17259. this.stack.push(0);
  17260. break;
  17261. }
  17262. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17263. break;
  17264. case 30: // vhcurveto
  17265. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17266. break;
  17267. case 31: // hvcurveto
  17268. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17269. break;
  17270. case (12 << 8) + 0: // dotsection
  17271. // dotsection is a Type1 command to specify some hinting feature
  17272. // for dots that do not take a parameter and it can safely be
  17273. // ignored for Type2.
  17274. this.stack = [];
  17275. break;
  17276. case (12 << 8) + 1: // vstem3
  17277. if (!HINTING_ENABLED) {
  17278. this.stack = [];
  17279. break;
  17280. }
  17281. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17282. // multiple parameters, so instead of returning [vh]stem3 take a
  17283. // shortcut and return [vhstem] instead.
  17284. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17285. break;
  17286. case (12 << 8) + 2: // hstem3
  17287. if (!HINTING_ENABLED) {
  17288. this.stack = [];
  17289. break;
  17290. }
  17291. // See vstem3.
  17292. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17293. break;
  17294. case (12 << 8) + 6: // seac
  17295. // seac is like type 2's special endchar but it doesn't use the
  17296. // first argument asb, so remove it.
  17297. if (SEAC_ANALYSIS_ENABLED) {
  17298. this.seac = this.stack.splice(-4, 4);
  17299. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17300. } else {
  17301. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17302. }
  17303. break;
  17304. case (12 << 8) + 7: // sbw
  17305. if (this.stack.length < 4) {
  17306. error = true;
  17307. break;
  17308. }
  17309. // To convert to type2 we have to move the width value to the
  17310. // first part of the charstring and then use rmoveto with
  17311. // (dx, dy). The height argument will not be used for vmtx and
  17312. // vhea tables reconstruction -- ignoring it.
  17313. var wy = this.stack.pop();
  17314. wx = this.stack.pop();
  17315. var sby = this.stack.pop();
  17316. sbx = this.stack.pop();
  17317. this.lsb = sbx;
  17318. this.width = wx;
  17319. this.stack.push(wx, sbx, sby);
  17320. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17321. break;
  17322. case (12 << 8) + 12: // div
  17323. if (this.stack.length < 2) {
  17324. error = true;
  17325. break;
  17326. }
  17327. var num2 = this.stack.pop();
  17328. var num1 = this.stack.pop();
  17329. this.stack.push(num1 / num2);
  17330. break;
  17331. case (12 << 8) + 16: // callothersubr
  17332. if (this.stack.length < 2) {
  17333. error = true;
  17334. break;
  17335. }
  17336. subrNumber = this.stack.pop();
  17337. var numArgs = this.stack.pop();
  17338. if (subrNumber === 0 && numArgs === 3) {
  17339. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17340. this.stack.push(
  17341. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17342. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17343. flexArgs[4], // bcp2x
  17344. flexArgs[5], // bcp2y
  17345. flexArgs[6], // p2x
  17346. flexArgs[7], // p2y
  17347. flexArgs[8], // bcp3x
  17348. flexArgs[9], // bcp3y
  17349. flexArgs[10], // bcp4x
  17350. flexArgs[11], // bcp4y
  17351. flexArgs[12], // p3x
  17352. flexArgs[13], // p3y
  17353. flexArgs[14] // flexDepth
  17354. // 15 = finalx unused by flex
  17355. // 16 = finaly unused by flex
  17356. );
  17357. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17358. this.flexing = false;
  17359. this.stack.push(flexArgs[15], flexArgs[16]);
  17360. } else if (subrNumber === 1 && numArgs === 0) {
  17361. this.flexing = true;
  17362. }
  17363. break;
  17364. case (12 << 8) + 17: // pop
  17365. // Ignore this since it is only used with othersubr.
  17366. break;
  17367. case (12 << 8) + 33: // setcurrentpoint
  17368. // Ignore for now.
  17369. this.stack = [];
  17370. break;
  17371. default:
  17372. warn('Unknown type 1 charstring command of "' + value + '"');
  17373. break;
  17374. }
  17375. if (error) {
  17376. break;
  17377. }
  17378. continue;
  17379. } else if (value <= 246) {
  17380. value = value - 139;
  17381. } else if (value <= 250) {
  17382. value = ((value - 247) * 256) + encoded[++i] + 108;
  17383. } else if (value <= 254) {
  17384. value = -((value - 251) * 256) - encoded[++i] - 108;
  17385. } else {
  17386. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17387. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17388. }
  17389. this.stack.push(value);
  17390. }
  17391. return error;
  17392. },
  17393. executeCommand: function(howManyArgs, command, keepStack) {
  17394. var stackLength = this.stack.length;
  17395. if (howManyArgs > stackLength) {
  17396. return true;
  17397. }
  17398. var start = stackLength - howManyArgs;
  17399. for (var i = start; i < stackLength; i++) {
  17400. var value = this.stack[i];
  17401. if (value === (value | 0)) { // int
  17402. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17403. } else { // fixed point
  17404. value = (65536 * value) | 0;
  17405. this.output.push(255,
  17406. (value >> 24) & 0xFF,
  17407. (value >> 16) & 0xFF,
  17408. (value >> 8) & 0xFF,
  17409. value & 0xFF);
  17410. }
  17411. }
  17412. this.output.push.apply(this.output, command);
  17413. if (keepStack) {
  17414. this.stack.splice(start, howManyArgs);
  17415. } else {
  17416. this.stack.length = 0;
  17417. }
  17418. return false;
  17419. }
  17420. };
  17421. return Type1CharString;
  17422. })();
  17423. /*
  17424. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17425. * program. Some of its logic depends on the Type2 charstrings
  17426. * structure.
  17427. * Note: this doesn't really parse the font since that would require evaluation
  17428. * of PostScript, but it is possible in most cases to extract what we need
  17429. * without a full parse.
  17430. */
  17431. var Type1Parser = (function Type1ParserClosure() {
  17432. /*
  17433. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17434. * of Plaintext Bytes. The function took a key as a parameter which can be
  17435. * for decrypting the eexec block of for decoding charStrings.
  17436. */
  17437. var EEXEC_ENCRYPT_KEY = 55665;
  17438. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17439. function isHexDigit(code) {
  17440. return code >= 48 && code <= 57 || // '0'-'9'
  17441. code >= 65 && code <= 70 || // 'A'-'F'
  17442. code >= 97 && code <= 102; // 'a'-'f'
  17443. }
  17444. function decrypt(data, key, discardNumber) {
  17445. var r = key | 0, c1 = 52845, c2 = 22719;
  17446. var count = data.length;
  17447. var decrypted = new Uint8Array(count);
  17448. for (var i = 0; i < count; i++) {
  17449. var value = data[i];
  17450. decrypted[i] = value ^ (r >> 8);
  17451. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17452. }
  17453. return Array.prototype.slice.call(decrypted, discardNumber);
  17454. }
  17455. function decryptAscii(data, key, discardNumber) {
  17456. var r = key | 0, c1 = 52845, c2 = 22719;
  17457. var count = data.length, maybeLength = count >>> 1;
  17458. var decrypted = new Uint8Array(maybeLength);
  17459. var i, j;
  17460. for (i = 0, j = 0; i < count; i++) {
  17461. var digit1 = data[i];
  17462. if (!isHexDigit(digit1)) {
  17463. continue;
  17464. }
  17465. i++;
  17466. var digit2;
  17467. while (i < count && !isHexDigit(digit2 = data[i])) {
  17468. i++;
  17469. }
  17470. if (i < count) {
  17471. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17472. decrypted[j++] = value ^ (r >> 8);
  17473. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17474. }
  17475. }
  17476. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17477. }
  17478. function isSpecial(c) {
  17479. return c === 0x2F || // '/'
  17480. c === 0x5B || c === 0x5D || // '[', ']'
  17481. c === 0x7B || c === 0x7D || // '{', '}'
  17482. c === 0x28 || c === 0x29; // '(', ')'
  17483. }
  17484. function Type1Parser(stream, encrypted) {
  17485. if (encrypted) {
  17486. var data = stream.getBytes();
  17487. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17488. isHexDigit(data[2]) && isHexDigit(data[3]));
  17489. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17490. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17491. }
  17492. this.stream = stream;
  17493. this.nextChar();
  17494. }
  17495. Type1Parser.prototype = {
  17496. readNumberArray: function Type1Parser_readNumberArray() {
  17497. this.getToken(); // read '[' or '{' (arrays can start with either)
  17498. var array = [];
  17499. while (true) {
  17500. var token = this.getToken();
  17501. if (token === null || token === ']' || token === '}') {
  17502. break;
  17503. }
  17504. array.push(parseFloat(token || 0));
  17505. }
  17506. return array;
  17507. },
  17508. readNumber: function Type1Parser_readNumber() {
  17509. var token = this.getToken();
  17510. return parseFloat(token || 0);
  17511. },
  17512. readInt: function Type1Parser_readInt() {
  17513. // Use '| 0' to prevent setting a double into length such as the double
  17514. // does not flow into the loop variable.
  17515. var token = this.getToken();
  17516. return parseInt(token || 0, 10) | 0;
  17517. },
  17518. readBoolean: function Type1Parser_readBoolean() {
  17519. var token = this.getToken();
  17520. // Use 1 and 0 since that's what type2 charstrings use.
  17521. return token === 'true' ? 1 : 0;
  17522. },
  17523. nextChar : function Type1_nextChar() {
  17524. return (this.currentChar = this.stream.getByte());
  17525. },
  17526. getToken: function Type1Parser_getToken() {
  17527. // Eat whitespace and comments.
  17528. var comment = false;
  17529. var ch = this.currentChar;
  17530. while (true) {
  17531. if (ch === -1) {
  17532. return null;
  17533. }
  17534. if (comment) {
  17535. if (ch === 0x0A || ch === 0x0D) {
  17536. comment = false;
  17537. }
  17538. } else if (ch === 0x25) { // '%'
  17539. comment = true;
  17540. } else if (!Lexer.isSpace(ch)) {
  17541. break;
  17542. }
  17543. ch = this.nextChar();
  17544. }
  17545. if (isSpecial(ch)) {
  17546. this.nextChar();
  17547. return String.fromCharCode(ch);
  17548. }
  17549. var token = '';
  17550. do {
  17551. token += String.fromCharCode(ch);
  17552. ch = this.nextChar();
  17553. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17554. return token;
  17555. },
  17556. /*
  17557. * Returns an object containing a Subrs array and a CharStrings
  17558. * array extracted from and eexec encrypted block of data
  17559. */
  17560. extractFontProgram: function Type1Parser_extractFontProgram() {
  17561. var stream = this.stream;
  17562. var subrs = [], charstrings = [];
  17563. var program = {
  17564. subrs: [],
  17565. charstrings: [],
  17566. properties: {
  17567. 'privateData': {
  17568. 'lenIV': 4
  17569. }
  17570. }
  17571. };
  17572. var token, length, data, lenIV, encoded;
  17573. while ((token = this.getToken()) !== null) {
  17574. if (token !== '/') {
  17575. continue;
  17576. }
  17577. token = this.getToken();
  17578. switch (token) {
  17579. case 'CharStrings':
  17580. // The number immediately following CharStrings must be greater or
  17581. // equal to the number of CharStrings.
  17582. this.getToken();
  17583. this.getToken(); // read in 'dict'
  17584. this.getToken(); // read in 'dup'
  17585. this.getToken(); // read in 'begin'
  17586. while(true) {
  17587. token = this.getToken();
  17588. if (token === null || token === 'end') {
  17589. break;
  17590. }
  17591. if (token !== '/') {
  17592. continue;
  17593. }
  17594. var glyph = this.getToken();
  17595. length = this.readInt();
  17596. this.getToken(); // read in 'RD' or '-|'
  17597. data = stream.makeSubStream(stream.pos, length);
  17598. lenIV = program.properties.privateData['lenIV'];
  17599. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17600. // Skip past the required space and binary data.
  17601. stream.skip(length);
  17602. this.nextChar();
  17603. token = this.getToken(); // read in 'ND' or '|-'
  17604. if (token === 'noaccess') {
  17605. this.getToken(); // read in 'def'
  17606. }
  17607. charstrings.push({
  17608. glyph: glyph,
  17609. encoded: encoded
  17610. });
  17611. }
  17612. break;
  17613. case 'Subrs':
  17614. var num = this.readInt();
  17615. this.getToken(); // read in 'array'
  17616. while ((token = this.getToken()) === 'dup') {
  17617. var index = this.readInt();
  17618. length = this.readInt();
  17619. this.getToken(); // read in 'RD' or '-|'
  17620. data = stream.makeSubStream(stream.pos, length);
  17621. lenIV = program.properties.privateData['lenIV'];
  17622. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17623. // Skip past the required space and binary data.
  17624. stream.skip(length);
  17625. this.nextChar();
  17626. token = this.getToken(); // read in 'NP' or '|'
  17627. if (token === 'noaccess') {
  17628. this.getToken(); // read in 'put'
  17629. }
  17630. subrs[index] = encoded;
  17631. }
  17632. break;
  17633. case 'BlueValues':
  17634. case 'OtherBlues':
  17635. case 'FamilyBlues':
  17636. case 'FamilyOtherBlues':
  17637. var blueArray = this.readNumberArray();
  17638. // *Blue* values may contain invalid data: disables reading of
  17639. // those values when hinting is disabled.
  17640. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17641. HINTING_ENABLED) {
  17642. program.properties.privateData[token] = blueArray;
  17643. }
  17644. break;
  17645. case 'StemSnapH':
  17646. case 'StemSnapV':
  17647. program.properties.privateData[token] = this.readNumberArray();
  17648. break;
  17649. case 'StdHW':
  17650. case 'StdVW':
  17651. program.properties.privateData[token] =
  17652. this.readNumberArray()[0];
  17653. break;
  17654. case 'BlueShift':
  17655. case 'lenIV':
  17656. case 'BlueFuzz':
  17657. case 'BlueScale':
  17658. case 'LanguageGroup':
  17659. case 'ExpansionFactor':
  17660. program.properties.privateData[token] = this.readNumber();
  17661. break;
  17662. case 'ForceBold':
  17663. program.properties.privateData[token] = this.readBoolean();
  17664. break;
  17665. }
  17666. }
  17667. for (var i = 0; i < charstrings.length; i++) {
  17668. glyph = charstrings[i].glyph;
  17669. encoded = charstrings[i].encoded;
  17670. var charString = new Type1CharString();
  17671. var error = charString.convert(encoded, subrs);
  17672. var output = charString.output;
  17673. if (error) {
  17674. // It seems when FreeType encounters an error while evaluating a glyph
  17675. // that it completely ignores the glyph so we'll mimic that behaviour
  17676. // here and put an endchar to make the validator happy.
  17677. output = [14];
  17678. }
  17679. program.charstrings.push({
  17680. glyphName: glyph,
  17681. charstring: output,
  17682. width: charString.width,
  17683. lsb: charString.lsb,
  17684. seac: charString.seac
  17685. });
  17686. }
  17687. return program;
  17688. },
  17689. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17690. var token;
  17691. while ((token = this.getToken()) !== null) {
  17692. if (token !== '/') {
  17693. continue;
  17694. }
  17695. token = this.getToken();
  17696. switch (token) {
  17697. case 'FontMatrix':
  17698. var matrix = this.readNumberArray();
  17699. properties.fontMatrix = matrix;
  17700. break;
  17701. case 'Encoding':
  17702. var encodingArg = this.getToken();
  17703. var encoding;
  17704. if (!/^\d+$/.test(encodingArg)) {
  17705. // encoding name is specified
  17706. encoding = Encodings[encodingArg];
  17707. } else {
  17708. encoding = [];
  17709. var size = parseInt(encodingArg, 10) | 0;
  17710. this.getToken(); // read in 'array'
  17711. for (var j = 0; j < size; j++) {
  17712. token = this.getToken();
  17713. // skipping till first dup or def (e.g. ignoring for statement)
  17714. while (token !== 'dup' && token !== 'def') {
  17715. token = this.getToken();
  17716. if (token === null) {
  17717. return; // invalid header
  17718. }
  17719. }
  17720. if (token === 'def') {
  17721. break; // read all array data
  17722. }
  17723. var index = this.readInt();
  17724. this.getToken(); // read in '/'
  17725. var glyph = this.getToken();
  17726. encoding[index] = glyph;
  17727. this.getToken(); // read the in 'put'
  17728. }
  17729. }
  17730. properties.builtInEncoding = encoding;
  17731. break;
  17732. case 'FontBBox':
  17733. var fontBBox = this.readNumberArray();
  17734. // adjusting ascent/descent
  17735. properties.ascent = fontBBox[3];
  17736. properties.descent = fontBBox[1];
  17737. properties.ascentScaled = true;
  17738. break;
  17739. }
  17740. }
  17741. }
  17742. };
  17743. return Type1Parser;
  17744. })();
  17745. /**
  17746. * The CFF class takes a Type1 file and wrap it into a
  17747. * 'Compact Font Format' which itself embed Type2 charstrings.
  17748. */
  17749. var CFFStandardStrings = [
  17750. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17751. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17752. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17753. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17754. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17755. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17756. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17757. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17758. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17759. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17760. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17761. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17762. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17763. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17764. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17765. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17766. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17767. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17768. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17769. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17770. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17771. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17772. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17773. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17774. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17775. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17776. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17777. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17778. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17779. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17780. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17781. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17782. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17783. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17784. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17785. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  17786. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  17787. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  17788. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  17789. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  17790. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  17791. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  17792. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  17793. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  17794. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  17795. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  17796. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  17797. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  17798. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  17799. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  17800. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  17801. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  17802. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  17803. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  17804. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  17805. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  17806. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  17807. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  17808. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  17809. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  17810. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  17811. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  17812. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  17813. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  17814. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  17815. ];
  17816. // Type1Font is also a CIDFontType0.
  17817. var Type1Font = function Type1Font(name, file, properties) {
  17818. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  17819. // Also, length1 and length2 might be off by 6 bytes as well.
  17820. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  17821. var PFB_HEADER_SIZE = 6;
  17822. var headerBlockLength = properties.length1;
  17823. var eexecBlockLength = properties.length2;
  17824. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  17825. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  17826. if (pfbHeaderPresent) {
  17827. file.skip(PFB_HEADER_SIZE);
  17828. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17829. (pfbHeader[3] << 8) | pfbHeader[2];
  17830. }
  17831. // Get the data block containing glyphs and subrs informations
  17832. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  17833. var headerBlockParser = new Type1Parser(headerBlock);
  17834. headerBlockParser.extractFontHeader(properties);
  17835. if (pfbHeaderPresent) {
  17836. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  17837. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17838. (pfbHeader[3] << 8) | pfbHeader[2];
  17839. }
  17840. // Decrypt the data blocks and retrieve it's content
  17841. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  17842. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  17843. var data = eexecBlockParser.extractFontProgram();
  17844. for (var info in data.properties) {
  17845. properties[info] = data.properties[info];
  17846. }
  17847. var charstrings = data.charstrings;
  17848. var type2Charstrings = this.getType2Charstrings(charstrings);
  17849. var subrs = this.getType2Subrs(data.subrs);
  17850. this.charstrings = charstrings;
  17851. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  17852. subrs, properties);
  17853. this.seacs = this.getSeacs(data.charstrings);
  17854. };
  17855. Type1Font.prototype = {
  17856. get numGlyphs() {
  17857. return this.charstrings.length + 1;
  17858. },
  17859. getCharset: function Type1Font_getCharset() {
  17860. var charset = ['.notdef'];
  17861. var charstrings = this.charstrings;
  17862. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17863. charset.push(charstrings[glyphId].glyphName);
  17864. }
  17865. return charset;
  17866. },
  17867. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  17868. var charstrings = this.charstrings;
  17869. var glyphNames = ['.notdef'], glyphId;
  17870. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17871. glyphNames.push(charstrings[glyphId].glyphName);
  17872. }
  17873. var encoding = properties.builtInEncoding;
  17874. if (encoding) {
  17875. var builtInEncoding = {};
  17876. for (var charCode in encoding) {
  17877. glyphId = glyphNames.indexOf(encoding[charCode]);
  17878. if (glyphId >= 0) {
  17879. builtInEncoding[charCode] = glyphId;
  17880. }
  17881. }
  17882. }
  17883. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  17884. },
  17885. getSeacs: function Type1Font_getSeacs(charstrings) {
  17886. var i, ii;
  17887. var seacMap = [];
  17888. for (i = 0, ii = charstrings.length; i < ii; i++) {
  17889. var charstring = charstrings[i];
  17890. if (charstring.seac) {
  17891. // Offset by 1 for .notdef
  17892. seacMap[i + 1] = charstring.seac;
  17893. }
  17894. }
  17895. return seacMap;
  17896. },
  17897. getType2Charstrings: function Type1Font_getType2Charstrings(
  17898. type1Charstrings) {
  17899. var type2Charstrings = [];
  17900. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  17901. type2Charstrings.push(type1Charstrings[i].charstring);
  17902. }
  17903. return type2Charstrings;
  17904. },
  17905. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  17906. var bias = 0;
  17907. var count = type1Subrs.length;
  17908. if (count < 1133) {
  17909. bias = 107;
  17910. } else if (count < 33769) {
  17911. bias = 1131;
  17912. } else {
  17913. bias = 32768;
  17914. }
  17915. // Add a bunch of empty subrs to deal with the Type2 bias
  17916. var type2Subrs = [];
  17917. var i;
  17918. for (i = 0; i < bias; i++) {
  17919. type2Subrs.push([0x0B]);
  17920. }
  17921. for (i = 0; i < count; i++) {
  17922. type2Subrs.push(type1Subrs[i]);
  17923. }
  17924. return type2Subrs;
  17925. },
  17926. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  17927. var cff = new CFF();
  17928. cff.header = new CFFHeader(1, 0, 4, 4);
  17929. cff.names = [name];
  17930. var topDict = new CFFTopDict();
  17931. // CFF strings IDs 0...390 are predefined names, so refering
  17932. // to entries in our own String INDEX starts at SID 391.
  17933. topDict.setByName('version', 391);
  17934. topDict.setByName('Notice', 392);
  17935. topDict.setByName('FullName', 393);
  17936. topDict.setByName('FamilyName', 394);
  17937. topDict.setByName('Weight', 395);
  17938. topDict.setByName('Encoding', null); // placeholder
  17939. topDict.setByName('FontMatrix', properties.fontMatrix);
  17940. topDict.setByName('FontBBox', properties.bbox);
  17941. topDict.setByName('charset', null); // placeholder
  17942. topDict.setByName('CharStrings', null); // placeholder
  17943. topDict.setByName('Private', null); // placeholder
  17944. cff.topDict = topDict;
  17945. var strings = new CFFStrings();
  17946. strings.add('Version 0.11'); // Version
  17947. strings.add('See original notice'); // Notice
  17948. strings.add(name); // FullName
  17949. strings.add(name); // FamilyName
  17950. strings.add('Medium'); // Weight
  17951. cff.strings = strings;
  17952. cff.globalSubrIndex = new CFFIndex();
  17953. var count = glyphs.length;
  17954. var charsetArray = [0];
  17955. var i, ii;
  17956. for (i = 0; i < count; i++) {
  17957. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  17958. // TODO: Insert the string and correctly map it. Previously it was
  17959. // thought mapping names that aren't in the standard strings to .notdef
  17960. // was fine, however in issue818 when mapping them all to .notdef the
  17961. // adieresis glyph no longer worked.
  17962. if (index === -1) {
  17963. index = 0;
  17964. }
  17965. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  17966. }
  17967. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  17968. var charStringsIndex = new CFFIndex();
  17969. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  17970. for (i = 0; i < count; i++) {
  17971. charStringsIndex.add(glyphs[i]);
  17972. }
  17973. cff.charStrings = charStringsIndex;
  17974. var privateDict = new CFFPrivateDict();
  17975. privateDict.setByName('Subrs', null); // placeholder
  17976. var fields = [
  17977. 'BlueValues',
  17978. 'OtherBlues',
  17979. 'FamilyBlues',
  17980. 'FamilyOtherBlues',
  17981. 'StemSnapH',
  17982. 'StemSnapV',
  17983. 'BlueShift',
  17984. 'BlueFuzz',
  17985. 'BlueScale',
  17986. 'LanguageGroup',
  17987. 'ExpansionFactor',
  17988. 'ForceBold',
  17989. 'StdHW',
  17990. 'StdVW'
  17991. ];
  17992. for (i = 0, ii = fields.length; i < ii; i++) {
  17993. var field = fields[i];
  17994. if (!properties.privateData.hasOwnProperty(field)) {
  17995. continue;
  17996. }
  17997. var value = properties.privateData[field];
  17998. if (isArray(value)) {
  17999. // All of the private dictionary array data in CFF must be stored as
  18000. // "delta-encoded" numbers.
  18001. for (var j = value.length - 1; j > 0; j--) {
  18002. value[j] -= value[j - 1]; // ... difference from previous value
  18003. }
  18004. }
  18005. privateDict.setByName(field, value);
  18006. }
  18007. cff.topDict.privateDict = privateDict;
  18008. var subrIndex = new CFFIndex();
  18009. for (i = 0, ii = subrs.length; i < ii; i++) {
  18010. subrIndex.add(subrs[i]);
  18011. }
  18012. privateDict.subrsIndex = subrIndex;
  18013. var compiler = new CFFCompiler(cff);
  18014. return compiler.compile();
  18015. }
  18016. };
  18017. var CFFFont = (function CFFFontClosure() {
  18018. function CFFFont(file, properties) {
  18019. this.properties = properties;
  18020. var parser = new CFFParser(file, properties);
  18021. this.cff = parser.parse();
  18022. var compiler = new CFFCompiler(this.cff);
  18023. this.seacs = this.cff.seacs;
  18024. try {
  18025. this.data = compiler.compile();
  18026. } catch (e) {
  18027. warn('Failed to compile font ' + properties.loadedName);
  18028. // There may have just been an issue with the compiler, set the data
  18029. // anyway and hope the font loaded.
  18030. this.data = file;
  18031. }
  18032. }
  18033. CFFFont.prototype = {
  18034. get numGlyphs() {
  18035. return this.cff.charStrings.count;
  18036. },
  18037. getCharset: function CFFFont_getCharset() {
  18038. return this.cff.charset.charset;
  18039. },
  18040. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18041. var cff = this.cff;
  18042. var properties = this.properties;
  18043. var charsets = cff.charset.charset;
  18044. var charCodeToGlyphId;
  18045. var glyphId;
  18046. if (properties.composite) {
  18047. charCodeToGlyphId = Object.create(null);
  18048. if (cff.isCIDFont) {
  18049. // If the font is actually a CID font then we should use the charset
  18050. // to map CIDs to GIDs.
  18051. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18052. var cid = charsets[glyphId];
  18053. var charCode = properties.cMap.charCodeOf(cid);
  18054. charCodeToGlyphId[charCode] = glyphId;
  18055. }
  18056. } else {
  18057. // If it is NOT actually a CID font then CIDs should be mapped
  18058. // directly to GIDs.
  18059. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18060. charCodeToGlyphId[glyphId] = glyphId;
  18061. }
  18062. }
  18063. return charCodeToGlyphId;
  18064. }
  18065. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18066. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18067. return charCodeToGlyphId;
  18068. }
  18069. };
  18070. return CFFFont;
  18071. })();
  18072. var CFFParser = (function CFFParserClosure() {
  18073. var CharstringValidationData = [
  18074. null,
  18075. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18076. null,
  18077. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18078. { id: 'vmoveto', min: 1, stackClearing: true },
  18079. { id: 'rlineto', min: 2, resetStack: true },
  18080. { id: 'hlineto', min: 1, resetStack: true },
  18081. { id: 'vlineto', min: 1, resetStack: true },
  18082. { id: 'rrcurveto', min: 6, resetStack: true },
  18083. null,
  18084. { id: 'callsubr', min: 1, undefStack: true },
  18085. { id: 'return', min: 0, undefStack: true },
  18086. null, // 12
  18087. null,
  18088. { id: 'endchar', min: 0, stackClearing: true },
  18089. null,
  18090. null,
  18091. null,
  18092. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18093. { id: 'hintmask', min: 0, stackClearing: true },
  18094. { id: 'cntrmask', min: 0, stackClearing: true },
  18095. { id: 'rmoveto', min: 2, stackClearing: true },
  18096. { id: 'hmoveto', min: 1, stackClearing: true },
  18097. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18098. { id: 'rcurveline', min: 8, resetStack: true },
  18099. { id: 'rlinecurve', min: 8, resetStack: true },
  18100. { id: 'vvcurveto', min: 4, resetStack: true },
  18101. { id: 'hhcurveto', min: 4, resetStack: true },
  18102. null, // shortint
  18103. { id: 'callgsubr', min: 1, undefStack: true },
  18104. { id: 'vhcurveto', min: 4, resetStack: true },
  18105. { id: 'hvcurveto', min: 4, resetStack: true }
  18106. ];
  18107. var CharstringValidationData12 = [
  18108. null,
  18109. null,
  18110. null,
  18111. { id: 'and', min: 2, stackDelta: -1 },
  18112. { id: 'or', min: 2, stackDelta: -1 },
  18113. { id: 'not', min: 1, stackDelta: 0 },
  18114. null,
  18115. null,
  18116. null,
  18117. { id: 'abs', min: 1, stackDelta: 0 },
  18118. { id: 'add', min: 2, stackDelta: -1,
  18119. stackFn: function stack_div(stack, index) {
  18120. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18121. }
  18122. },
  18123. { id: 'sub', min: 2, stackDelta: -1,
  18124. stackFn: function stack_div(stack, index) {
  18125. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18126. }
  18127. },
  18128. { id: 'div', min: 2, stackDelta: -1,
  18129. stackFn: function stack_div(stack, index) {
  18130. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18131. }
  18132. },
  18133. null,
  18134. { id: 'neg', min: 1, stackDelta: 0,
  18135. stackFn: function stack_div(stack, index) {
  18136. stack[index - 1] = -stack[index - 1];
  18137. }
  18138. },
  18139. { id: 'eq', min: 2, stackDelta: -1 },
  18140. null,
  18141. null,
  18142. { id: 'drop', min: 1, stackDelta: -1 },
  18143. null,
  18144. { id: 'put', min: 2, stackDelta: -2 },
  18145. { id: 'get', min: 1, stackDelta: 0 },
  18146. { id: 'ifelse', min: 4, stackDelta: -3 },
  18147. { id: 'random', min: 0, stackDelta: 1 },
  18148. { id: 'mul', min: 2, stackDelta: -1,
  18149. stackFn: function stack_div(stack, index) {
  18150. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18151. }
  18152. },
  18153. null,
  18154. { id: 'sqrt', min: 1, stackDelta: 0 },
  18155. { id: 'dup', min: 1, stackDelta: 1 },
  18156. { id: 'exch', min: 2, stackDelta: 0 },
  18157. { id: 'index', min: 2, stackDelta: 0 },
  18158. { id: 'roll', min: 3, stackDelta: -2 },
  18159. null,
  18160. null,
  18161. null,
  18162. { id: 'hflex', min: 7, resetStack: true },
  18163. { id: 'flex', min: 13, resetStack: true },
  18164. { id: 'hflex1', min: 9, resetStack: true },
  18165. { id: 'flex1', min: 11, resetStack: true }
  18166. ];
  18167. function CFFParser(file, properties) {
  18168. this.bytes = file.getBytes();
  18169. this.properties = properties;
  18170. }
  18171. CFFParser.prototype = {
  18172. parse: function CFFParser_parse() {
  18173. var properties = this.properties;
  18174. var cff = new CFF();
  18175. this.cff = cff;
  18176. // The first five sections must be in order, all the others are reached
  18177. // via offsets contained in one of the below.
  18178. var header = this.parseHeader();
  18179. var nameIndex = this.parseIndex(header.endPos);
  18180. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18181. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18182. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18183. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18184. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18185. cff.header = header.obj;
  18186. cff.names = this.parseNameIndex(nameIndex.obj);
  18187. cff.strings = this.parseStringIndex(stringIndex.obj);
  18188. cff.topDict = topDict;
  18189. cff.globalSubrIndex = globalSubrIndex.obj;
  18190. this.parsePrivateDict(cff.topDict);
  18191. cff.isCIDFont = topDict.hasName('ROS');
  18192. var charStringOffset = topDict.getByName('CharStrings');
  18193. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18194. cff.charStrings = charStringsAndSeacs.charStrings;
  18195. cff.seacs = charStringsAndSeacs.seacs;
  18196. cff.widths = charStringsAndSeacs.widths;
  18197. var fontMatrix = topDict.getByName('FontMatrix');
  18198. if (fontMatrix) {
  18199. properties.fontMatrix = fontMatrix;
  18200. }
  18201. var fontBBox = topDict.getByName('FontBBox');
  18202. if (fontBBox) {
  18203. // adjusting ascent/descent
  18204. properties.ascent = fontBBox[3];
  18205. properties.descent = fontBBox[1];
  18206. properties.ascentScaled = true;
  18207. }
  18208. var charset, encoding;
  18209. if (cff.isCIDFont) {
  18210. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18211. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18212. var dictRaw = fdArrayIndex.get(i);
  18213. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18214. cff.strings);
  18215. this.parsePrivateDict(fontDict);
  18216. cff.fdArray.push(fontDict);
  18217. }
  18218. // cid fonts don't have an encoding
  18219. encoding = null;
  18220. charset = this.parseCharsets(topDict.getByName('charset'),
  18221. cff.charStrings.count, cff.strings, true);
  18222. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18223. cff.charStrings.count);
  18224. } else {
  18225. charset = this.parseCharsets(topDict.getByName('charset'),
  18226. cff.charStrings.count, cff.strings, false);
  18227. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18228. properties,
  18229. cff.strings, charset.charset);
  18230. }
  18231. cff.charset = charset;
  18232. cff.encoding = encoding;
  18233. return cff;
  18234. },
  18235. parseHeader: function CFFParser_parseHeader() {
  18236. var bytes = this.bytes;
  18237. var bytesLength = bytes.length;
  18238. var offset = 0;
  18239. // Prevent an infinite loop, by checking that the offset is within the
  18240. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18241. while (offset < bytesLength && bytes[offset] !== 1) {
  18242. ++offset;
  18243. }
  18244. if (offset >= bytesLength) {
  18245. error('Invalid CFF header');
  18246. } else if (offset !== 0) {
  18247. info('cff data is shifted');
  18248. bytes = bytes.subarray(offset);
  18249. this.bytes = bytes;
  18250. }
  18251. var major = bytes[0];
  18252. var minor = bytes[1];
  18253. var hdrSize = bytes[2];
  18254. var offSize = bytes[3];
  18255. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18256. return { obj: header, endPos: hdrSize };
  18257. },
  18258. parseDict: function CFFParser_parseDict(dict) {
  18259. var pos = 0;
  18260. function parseOperand() {
  18261. var value = dict[pos++];
  18262. if (value === 30) {
  18263. return parseFloatOperand(pos);
  18264. } else if (value === 28) {
  18265. value = dict[pos++];
  18266. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18267. return value;
  18268. } else if (value === 29) {
  18269. value = dict[pos++];
  18270. value = (value << 8) | dict[pos++];
  18271. value = (value << 8) | dict[pos++];
  18272. value = (value << 8) | dict[pos++];
  18273. return value;
  18274. } else if (value >= 32 && value <= 246) {
  18275. return value - 139;
  18276. } else if (value >= 247 && value <= 250) {
  18277. return ((value - 247) * 256) + dict[pos++] + 108;
  18278. } else if (value >= 251 && value <= 254) {
  18279. return -((value - 251) * 256) - dict[pos++] - 108;
  18280. } else {
  18281. error('255 is not a valid DICT command');
  18282. }
  18283. return -1;
  18284. }
  18285. function parseFloatOperand() {
  18286. var str = '';
  18287. var eof = 15;
  18288. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18289. '9', '.', 'E', 'E-', null, '-'];
  18290. var length = dict.length;
  18291. while (pos < length) {
  18292. var b = dict[pos++];
  18293. var b1 = b >> 4;
  18294. var b2 = b & 15;
  18295. if (b1 === eof) {
  18296. break;
  18297. }
  18298. str += lookup[b1];
  18299. if (b2 === eof) {
  18300. break;
  18301. }
  18302. str += lookup[b2];
  18303. }
  18304. return parseFloat(str);
  18305. }
  18306. var operands = [];
  18307. var entries = [];
  18308. pos = 0;
  18309. var end = dict.length;
  18310. while (pos < end) {
  18311. var b = dict[pos];
  18312. if (b <= 21) {
  18313. if (b === 12) {
  18314. b = (b << 8) | dict[++pos];
  18315. }
  18316. entries.push([b, operands]);
  18317. operands = [];
  18318. ++pos;
  18319. } else {
  18320. operands.push(parseOperand());
  18321. }
  18322. }
  18323. return entries;
  18324. },
  18325. parseIndex: function CFFParser_parseIndex(pos) {
  18326. var cffIndex = new CFFIndex();
  18327. var bytes = this.bytes;
  18328. var count = (bytes[pos++] << 8) | bytes[pos++];
  18329. var offsets = [];
  18330. var end = pos;
  18331. var i, ii;
  18332. if (count !== 0) {
  18333. var offsetSize = bytes[pos++];
  18334. // add 1 for offset to determine size of last object
  18335. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18336. for (i = 0, ii = count + 1; i < ii; ++i) {
  18337. var offset = 0;
  18338. for (var j = 0; j < offsetSize; ++j) {
  18339. offset <<= 8;
  18340. offset += bytes[pos++];
  18341. }
  18342. offsets.push(startPos + offset);
  18343. }
  18344. end = offsets[count];
  18345. }
  18346. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18347. var offsetStart = offsets[i];
  18348. var offsetEnd = offsets[i + 1];
  18349. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18350. }
  18351. return {obj: cffIndex, endPos: end};
  18352. },
  18353. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18354. var names = [];
  18355. for (var i = 0, ii = index.count; i < ii; ++i) {
  18356. var name = index.get(i);
  18357. // OTS doesn't allow names to be over 127 characters.
  18358. var length = Math.min(name.length, 127);
  18359. var data = [];
  18360. // OTS also only permits certain characters in the name.
  18361. for (var j = 0; j < length; ++j) {
  18362. var c = name[j];
  18363. if (j === 0 && c === 0) {
  18364. data[j] = c;
  18365. continue;
  18366. }
  18367. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18368. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18369. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18370. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18371. data[j] = 95;
  18372. continue;
  18373. }
  18374. data[j] = c;
  18375. }
  18376. names.push(bytesToString(data));
  18377. }
  18378. return names;
  18379. },
  18380. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18381. var strings = new CFFStrings();
  18382. for (var i = 0, ii = index.count; i < ii; ++i) {
  18383. var data = index.get(i);
  18384. strings.add(bytesToString(data));
  18385. }
  18386. return strings;
  18387. },
  18388. createDict: function CFFParser_createDict(Type, dict, strings) {
  18389. var cffDict = new Type(strings);
  18390. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18391. var pair = dict[i];
  18392. var key = pair[0];
  18393. var value = pair[1];
  18394. cffDict.setByKey(key, value);
  18395. }
  18396. return cffDict;
  18397. },
  18398. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18399. var charStrings = this.parseIndex(charStringOffset).obj;
  18400. var seacs = [];
  18401. var widths = [];
  18402. var count = charStrings.count;
  18403. for (var i = 0; i < count; i++) {
  18404. var charstring = charStrings.get(i);
  18405. var stackSize = 0;
  18406. var stack = [];
  18407. var undefStack = true;
  18408. var hints = 0;
  18409. var valid = true;
  18410. var data = charstring;
  18411. var length = data.length;
  18412. var firstStackClearing = true;
  18413. for (var j = 0; j < length;) {
  18414. var value = data[j++];
  18415. var validationCommand = null;
  18416. if (value === 12) {
  18417. var q = data[j++];
  18418. if (q === 0) {
  18419. // The CFF specification state that the 'dotsection' command
  18420. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18421. // charstrings processors should support them. Unfortunately
  18422. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18423. // is replaced by a useless (0, hmoveto).
  18424. data[j - 2] = 139;
  18425. data[j - 1] = 22;
  18426. stackSize = 0;
  18427. } else {
  18428. validationCommand = CharstringValidationData12[q];
  18429. }
  18430. } else if (value === 28) { // number (16 bit)
  18431. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18432. j += 2;
  18433. stackSize++;
  18434. } else if (value === 14) {
  18435. if (stackSize >= 4) {
  18436. stackSize -= 4;
  18437. if (SEAC_ANALYSIS_ENABLED) {
  18438. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18439. valid = false;
  18440. }
  18441. }
  18442. validationCommand = CharstringValidationData[value];
  18443. } else if (value >= 32 && value <= 246) { // number
  18444. stack[stackSize] = value - 139;
  18445. stackSize++;
  18446. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18447. stack[stackSize] = (value < 251 ?
  18448. ((value - 247) << 8) + data[j] + 108 :
  18449. -((value - 251) << 8) - data[j] - 108);
  18450. j++;
  18451. stackSize++;
  18452. } else if (value === 255) { // number (32 bit)
  18453. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18454. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18455. j += 4;
  18456. stackSize++;
  18457. } else if (value === 19 || value === 20) {
  18458. hints += stackSize >> 1;
  18459. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18460. stackSize %= 2;
  18461. validationCommand = CharstringValidationData[value];
  18462. } else {
  18463. validationCommand = CharstringValidationData[value];
  18464. }
  18465. if (validationCommand) {
  18466. if (validationCommand.stem) {
  18467. hints += stackSize >> 1;
  18468. }
  18469. if ('min' in validationCommand) {
  18470. if (!undefStack && stackSize < validationCommand.min) {
  18471. warn('Not enough parameters for ' + validationCommand.id +
  18472. '; actual: ' + stackSize +
  18473. ', expected: ' + validationCommand.min);
  18474. valid = false;
  18475. break;
  18476. }
  18477. }
  18478. if (firstStackClearing && validationCommand.stackClearing) {
  18479. firstStackClearing = false;
  18480. // the optional character width can be found before the first
  18481. // stack-clearing command arguments
  18482. stackSize -= validationCommand.min;
  18483. if (stackSize >= 2 && validationCommand.stem) {
  18484. // there are even amount of arguments for stem commands
  18485. stackSize %= 2;
  18486. } else if (stackSize > 1) {
  18487. warn('Found too many parameters for stack-clearing command');
  18488. }
  18489. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18490. widths[i] = stack[stackSize - 1];
  18491. }
  18492. }
  18493. if ('stackDelta' in validationCommand) {
  18494. if ('stackFn' in validationCommand) {
  18495. validationCommand.stackFn(stack, stackSize);
  18496. }
  18497. stackSize += validationCommand.stackDelta;
  18498. } else if (validationCommand.stackClearing) {
  18499. stackSize = 0;
  18500. } else if (validationCommand.resetStack) {
  18501. stackSize = 0;
  18502. undefStack = false;
  18503. } else if (validationCommand.undefStack) {
  18504. stackSize = 0;
  18505. undefStack = true;
  18506. firstStackClearing = false;
  18507. }
  18508. }
  18509. }
  18510. if (!valid) {
  18511. // resetting invalid charstring to single 'endchar'
  18512. charStrings.set(i, new Uint8Array([14]));
  18513. }
  18514. }
  18515. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18516. },
  18517. emptyPrivateDictionary:
  18518. function CFFParser_emptyPrivateDictionary(parentDict) {
  18519. var privateDict = this.createDict(CFFPrivateDict, [],
  18520. parentDict.strings);
  18521. parentDict.setByKey(18, [0, 0]);
  18522. parentDict.privateDict = privateDict;
  18523. },
  18524. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18525. // no private dict, do nothing
  18526. if (!parentDict.hasName('Private')) {
  18527. this.emptyPrivateDictionary(parentDict);
  18528. return;
  18529. }
  18530. var privateOffset = parentDict.getByName('Private');
  18531. // make sure the params are formatted correctly
  18532. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18533. parentDict.removeByName('Private');
  18534. return;
  18535. }
  18536. var size = privateOffset[0];
  18537. var offset = privateOffset[1];
  18538. // remove empty dicts or ones that refer to invalid location
  18539. if (size === 0 || offset >= this.bytes.length) {
  18540. this.emptyPrivateDictionary(parentDict);
  18541. return;
  18542. }
  18543. var privateDictEnd = offset + size;
  18544. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18545. var dict = this.parseDict(dictData);
  18546. var privateDict = this.createDict(CFFPrivateDict, dict,
  18547. parentDict.strings);
  18548. parentDict.privateDict = privateDict;
  18549. // Parse the Subrs index also since it's relative to the private dict.
  18550. if (!privateDict.getByName('Subrs')) {
  18551. return;
  18552. }
  18553. var subrsOffset = privateDict.getByName('Subrs');
  18554. var relativeOffset = offset + subrsOffset;
  18555. // Validate the offset.
  18556. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18557. this.emptyPrivateDictionary(parentDict);
  18558. return;
  18559. }
  18560. var subrsIndex = this.parseIndex(relativeOffset);
  18561. privateDict.subrsIndex = subrsIndex.obj;
  18562. },
  18563. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18564. if (pos === 0) {
  18565. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18566. ISOAdobeCharset);
  18567. } else if (pos === 1) {
  18568. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18569. ExpertCharset);
  18570. } else if (pos === 2) {
  18571. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18572. ExpertSubsetCharset);
  18573. }
  18574. var bytes = this.bytes;
  18575. var start = pos;
  18576. var format = bytes[pos++];
  18577. var charset = ['.notdef'];
  18578. var id, count, i;
  18579. // subtract 1 for the .notdef glyph
  18580. length -= 1;
  18581. switch (format) {
  18582. case 0:
  18583. for (i = 0; i < length; i++) {
  18584. id = (bytes[pos++] << 8) | bytes[pos++];
  18585. charset.push(cid ? id : strings.get(id));
  18586. }
  18587. break;
  18588. case 1:
  18589. while (charset.length <= length) {
  18590. id = (bytes[pos++] << 8) | bytes[pos++];
  18591. count = bytes[pos++];
  18592. for (i = 0; i <= count; i++) {
  18593. charset.push(cid ? id++ : strings.get(id++));
  18594. }
  18595. }
  18596. break;
  18597. case 2:
  18598. while (charset.length <= length) {
  18599. id = (bytes[pos++] << 8) | bytes[pos++];
  18600. count = (bytes[pos++] << 8) | bytes[pos++];
  18601. for (i = 0; i <= count; i++) {
  18602. charset.push(cid ? id++ : strings.get(id++));
  18603. }
  18604. }
  18605. break;
  18606. default:
  18607. error('Unknown charset format');
  18608. }
  18609. // Raw won't be needed if we actually compile the charset.
  18610. var end = pos;
  18611. var raw = bytes.subarray(start, end);
  18612. return new CFFCharset(false, format, charset, raw);
  18613. },
  18614. parseEncoding: function CFFParser_parseEncoding(pos,
  18615. properties,
  18616. strings,
  18617. charset) {
  18618. var encoding = {};
  18619. var bytes = this.bytes;
  18620. var predefined = false;
  18621. var hasSupplement = false;
  18622. var format, i, ii;
  18623. var raw = null;
  18624. function readSupplement() {
  18625. var supplementsCount = bytes[pos++];
  18626. for (i = 0; i < supplementsCount; i++) {
  18627. var code = bytes[pos++];
  18628. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18629. encoding[code] = charset.indexOf(strings.get(sid));
  18630. }
  18631. }
  18632. if (pos === 0 || pos === 1) {
  18633. predefined = true;
  18634. format = pos;
  18635. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18636. Encodings.StandardEncoding;
  18637. for (i = 0, ii = charset.length; i < ii; i++) {
  18638. var index = baseEncoding.indexOf(charset[i]);
  18639. if (index !== -1) {
  18640. encoding[index] = i;
  18641. }
  18642. }
  18643. } else {
  18644. var dataStart = pos;
  18645. format = bytes[pos++];
  18646. switch (format & 0x7f) {
  18647. case 0:
  18648. var glyphsCount = bytes[pos++];
  18649. for (i = 1; i <= glyphsCount; i++) {
  18650. encoding[bytes[pos++]] = i;
  18651. }
  18652. break;
  18653. case 1:
  18654. var rangesCount = bytes[pos++];
  18655. var gid = 1;
  18656. for (i = 0; i < rangesCount; i++) {
  18657. var start = bytes[pos++];
  18658. var left = bytes[pos++];
  18659. for (var j = start; j <= start + left; j++) {
  18660. encoding[j] = gid++;
  18661. }
  18662. }
  18663. break;
  18664. default:
  18665. error('Unknow encoding format: ' + format + ' in CFF');
  18666. break;
  18667. }
  18668. var dataEnd = pos;
  18669. if (format & 0x80) {
  18670. // The font sanitizer does not support CFF encoding with a
  18671. // supplement, since the encoding is not really used to map
  18672. // between gid to glyph, let's overwrite what is declared in
  18673. // the top dictionary to let the sanitizer think the font use
  18674. // StandardEncoding, that's a lie but that's ok.
  18675. bytes[dataStart] &= 0x7f;
  18676. readSupplement();
  18677. hasSupplement = true;
  18678. }
  18679. raw = bytes.subarray(dataStart, dataEnd);
  18680. }
  18681. format = format & 0x7f;
  18682. return new CFFEncoding(predefined, format, encoding, raw);
  18683. },
  18684. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18685. var start = pos;
  18686. var bytes = this.bytes;
  18687. var format = bytes[pos++];
  18688. var fdSelect = [];
  18689. var i;
  18690. switch (format) {
  18691. case 0:
  18692. for (i = 0; i < length; ++i) {
  18693. var id = bytes[pos++];
  18694. fdSelect.push(id);
  18695. }
  18696. break;
  18697. case 3:
  18698. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18699. for (i = 0; i < rangesCount; ++i) {
  18700. var first = (bytes[pos++] << 8) | bytes[pos++];
  18701. var fdIndex = bytes[pos++];
  18702. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18703. for (var j = first; j < next; ++j) {
  18704. fdSelect.push(fdIndex);
  18705. }
  18706. }
  18707. // Advance past the sentinel(next).
  18708. pos += 2;
  18709. break;
  18710. default:
  18711. error('Unknown fdselect format ' + format);
  18712. break;
  18713. }
  18714. var end = pos;
  18715. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18716. }
  18717. };
  18718. return CFFParser;
  18719. })();
  18720. // Compact Font Format
  18721. var CFF = (function CFFClosure() {
  18722. function CFF() {
  18723. this.header = null;
  18724. this.names = [];
  18725. this.topDict = null;
  18726. this.strings = new CFFStrings();
  18727. this.globalSubrIndex = null;
  18728. // The following could really be per font, but since we only have one font
  18729. // store them here.
  18730. this.encoding = null;
  18731. this.charset = null;
  18732. this.charStrings = null;
  18733. this.fdArray = [];
  18734. this.fdSelect = null;
  18735. this.isCIDFont = false;
  18736. }
  18737. return CFF;
  18738. })();
  18739. var CFFHeader = (function CFFHeaderClosure() {
  18740. function CFFHeader(major, minor, hdrSize, offSize) {
  18741. this.major = major;
  18742. this.minor = minor;
  18743. this.hdrSize = hdrSize;
  18744. this.offSize = offSize;
  18745. }
  18746. return CFFHeader;
  18747. })();
  18748. var CFFStrings = (function CFFStringsClosure() {
  18749. function CFFStrings() {
  18750. this.strings = [];
  18751. }
  18752. CFFStrings.prototype = {
  18753. get: function CFFStrings_get(index) {
  18754. if (index >= 0 && index <= 390) {
  18755. return CFFStandardStrings[index];
  18756. }
  18757. if (index - 391 <= this.strings.length) {
  18758. return this.strings[index - 391];
  18759. }
  18760. return CFFStandardStrings[0];
  18761. },
  18762. add: function CFFStrings_add(value) {
  18763. this.strings.push(value);
  18764. },
  18765. get count() {
  18766. return this.strings.length;
  18767. }
  18768. };
  18769. return CFFStrings;
  18770. })();
  18771. var CFFIndex = (function CFFIndexClosure() {
  18772. function CFFIndex() {
  18773. this.objects = [];
  18774. this.length = 0;
  18775. }
  18776. CFFIndex.prototype = {
  18777. add: function CFFIndex_add(data) {
  18778. this.length += data.length;
  18779. this.objects.push(data);
  18780. },
  18781. set: function CFFIndex_set(index, data) {
  18782. this.length += data.length - this.objects[index].length;
  18783. this.objects[index] = data;
  18784. },
  18785. get: function CFFIndex_get(index) {
  18786. return this.objects[index];
  18787. },
  18788. get count() {
  18789. return this.objects.length;
  18790. }
  18791. };
  18792. return CFFIndex;
  18793. })();
  18794. var CFFDict = (function CFFDictClosure() {
  18795. function CFFDict(tables, strings) {
  18796. this.keyToNameMap = tables.keyToNameMap;
  18797. this.nameToKeyMap = tables.nameToKeyMap;
  18798. this.defaults = tables.defaults;
  18799. this.types = tables.types;
  18800. this.opcodes = tables.opcodes;
  18801. this.order = tables.order;
  18802. this.strings = strings;
  18803. this.values = {};
  18804. }
  18805. CFFDict.prototype = {
  18806. // value should always be an array
  18807. setByKey: function CFFDict_setByKey(key, value) {
  18808. if (!(key in this.keyToNameMap)) {
  18809. return false;
  18810. }
  18811. // ignore empty values
  18812. if (value.length === 0) {
  18813. return true;
  18814. }
  18815. var type = this.types[key];
  18816. // remove the array wrapping these types of values
  18817. if (type === 'num' || type === 'sid' || type === 'offset') {
  18818. value = value[0];
  18819. }
  18820. this.values[key] = value;
  18821. return true;
  18822. },
  18823. setByName: function CFFDict_setByName(name, value) {
  18824. if (!(name in this.nameToKeyMap)) {
  18825. error('Invalid dictionary name "' + name + '"');
  18826. }
  18827. this.values[this.nameToKeyMap[name]] = value;
  18828. },
  18829. hasName: function CFFDict_hasName(name) {
  18830. return this.nameToKeyMap[name] in this.values;
  18831. },
  18832. getByName: function CFFDict_getByName(name) {
  18833. if (!(name in this.nameToKeyMap)) {
  18834. error('Invalid dictionary name "' + name + '"');
  18835. }
  18836. var key = this.nameToKeyMap[name];
  18837. if (!(key in this.values)) {
  18838. return this.defaults[key];
  18839. }
  18840. return this.values[key];
  18841. },
  18842. removeByName: function CFFDict_removeByName(name) {
  18843. delete this.values[this.nameToKeyMap[name]];
  18844. }
  18845. };
  18846. CFFDict.createTables = function CFFDict_createTables(layout) {
  18847. var tables = {
  18848. keyToNameMap: {},
  18849. nameToKeyMap: {},
  18850. defaults: {},
  18851. types: {},
  18852. opcodes: {},
  18853. order: []
  18854. };
  18855. for (var i = 0, ii = layout.length; i < ii; ++i) {
  18856. var entry = layout[i];
  18857. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  18858. tables.keyToNameMap[key] = entry[1];
  18859. tables.nameToKeyMap[entry[1]] = key;
  18860. tables.types[key] = entry[2];
  18861. tables.defaults[key] = entry[3];
  18862. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  18863. tables.order.push(key);
  18864. }
  18865. return tables;
  18866. };
  18867. return CFFDict;
  18868. })();
  18869. var CFFTopDict = (function CFFTopDictClosure() {
  18870. var layout = [
  18871. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  18872. [[12, 20], 'SyntheticBase', 'num', null],
  18873. [0, 'version', 'sid', null],
  18874. [1, 'Notice', 'sid', null],
  18875. [[12, 0], 'Copyright', 'sid', null],
  18876. [2, 'FullName', 'sid', null],
  18877. [3, 'FamilyName', 'sid', null],
  18878. [4, 'Weight', 'sid', null],
  18879. [[12, 1], 'isFixedPitch', 'num', 0],
  18880. [[12, 2], 'ItalicAngle', 'num', 0],
  18881. [[12, 3], 'UnderlinePosition', 'num', -100],
  18882. [[12, 4], 'UnderlineThickness', 'num', 50],
  18883. [[12, 5], 'PaintType', 'num', 0],
  18884. [[12, 6], 'CharstringType', 'num', 2],
  18885. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  18886. [0.001, 0, 0, 0.001, 0, 0]],
  18887. [13, 'UniqueID', 'num', null],
  18888. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  18889. [[12, 8], 'StrokeWidth', 'num', 0],
  18890. [14, 'XUID', 'array', null],
  18891. [15, 'charset', 'offset', 0],
  18892. [16, 'Encoding', 'offset', 0],
  18893. [17, 'CharStrings', 'offset', 0],
  18894. [18, 'Private', ['offset', 'offset'], null],
  18895. [[12, 21], 'PostScript', 'sid', null],
  18896. [[12, 22], 'BaseFontName', 'sid', null],
  18897. [[12, 23], 'BaseFontBlend', 'delta', null],
  18898. [[12, 31], 'CIDFontVersion', 'num', 0],
  18899. [[12, 32], 'CIDFontRevision', 'num', 0],
  18900. [[12, 33], 'CIDFontType', 'num', 0],
  18901. [[12, 34], 'CIDCount', 'num', 8720],
  18902. [[12, 35], 'UIDBase', 'num', null],
  18903. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  18904. // before FDArray.
  18905. [[12, 37], 'FDSelect', 'offset', null],
  18906. [[12, 36], 'FDArray', 'offset', null],
  18907. [[12, 38], 'FontName', 'sid', null]
  18908. ];
  18909. var tables = null;
  18910. function CFFTopDict(strings) {
  18911. if (tables === null) {
  18912. tables = CFFDict.createTables(layout);
  18913. }
  18914. CFFDict.call(this, tables, strings);
  18915. this.privateDict = null;
  18916. }
  18917. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  18918. return CFFTopDict;
  18919. })();
  18920. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  18921. var layout = [
  18922. [6, 'BlueValues', 'delta', null],
  18923. [7, 'OtherBlues', 'delta', null],
  18924. [8, 'FamilyBlues', 'delta', null],
  18925. [9, 'FamilyOtherBlues', 'delta', null],
  18926. [[12, 9], 'BlueScale', 'num', 0.039625],
  18927. [[12, 10], 'BlueShift', 'num', 7],
  18928. [[12, 11], 'BlueFuzz', 'num', 1],
  18929. [10, 'StdHW', 'num', null],
  18930. [11, 'StdVW', 'num', null],
  18931. [[12, 12], 'StemSnapH', 'delta', null],
  18932. [[12, 13], 'StemSnapV', 'delta', null],
  18933. [[12, 14], 'ForceBold', 'num', 0],
  18934. [[12, 17], 'LanguageGroup', 'num', 0],
  18935. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  18936. [[12, 19], 'initialRandomSeed', 'num', 0],
  18937. [20, 'defaultWidthX', 'num', 0],
  18938. [21, 'nominalWidthX', 'num', 0],
  18939. [19, 'Subrs', 'offset', null]
  18940. ];
  18941. var tables = null;
  18942. function CFFPrivateDict(strings) {
  18943. if (tables === null) {
  18944. tables = CFFDict.createTables(layout);
  18945. }
  18946. CFFDict.call(this, tables, strings);
  18947. this.subrsIndex = null;
  18948. }
  18949. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  18950. return CFFPrivateDict;
  18951. })();
  18952. var CFFCharsetPredefinedTypes = {
  18953. ISO_ADOBE: 0,
  18954. EXPERT: 1,
  18955. EXPERT_SUBSET: 2
  18956. };
  18957. var CFFCharset = (function CFFCharsetClosure() {
  18958. function CFFCharset(predefined, format, charset, raw) {
  18959. this.predefined = predefined;
  18960. this.format = format;
  18961. this.charset = charset;
  18962. this.raw = raw;
  18963. }
  18964. return CFFCharset;
  18965. })();
  18966. var CFFEncoding = (function CFFEncodingClosure() {
  18967. function CFFEncoding(predefined, format, encoding, raw) {
  18968. this.predefined = predefined;
  18969. this.format = format;
  18970. this.encoding = encoding;
  18971. this.raw = raw;
  18972. }
  18973. return CFFEncoding;
  18974. })();
  18975. var CFFFDSelect = (function CFFFDSelectClosure() {
  18976. function CFFFDSelect(fdSelect, raw) {
  18977. this.fdSelect = fdSelect;
  18978. this.raw = raw;
  18979. }
  18980. return CFFFDSelect;
  18981. })();
  18982. // Helper class to keep track of where an offset is within the data and helps
  18983. // filling in that offset once it's known.
  18984. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  18985. function CFFOffsetTracker() {
  18986. this.offsets = {};
  18987. }
  18988. CFFOffsetTracker.prototype = {
  18989. isTracking: function CFFOffsetTracker_isTracking(key) {
  18990. return key in this.offsets;
  18991. },
  18992. track: function CFFOffsetTracker_track(key, location) {
  18993. if (key in this.offsets) {
  18994. error('Already tracking location of ' + key);
  18995. }
  18996. this.offsets[key] = location;
  18997. },
  18998. offset: function CFFOffsetTracker_offset(value) {
  18999. for (var key in this.offsets) {
  19000. this.offsets[key] += value;
  19001. }
  19002. },
  19003. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19004. values,
  19005. output) {
  19006. if (!(key in this.offsets)) {
  19007. error('Not tracking location of ' + key);
  19008. }
  19009. var data = output.data;
  19010. var dataOffset = this.offsets[key];
  19011. var size = 5;
  19012. for (var i = 0, ii = values.length; i < ii; ++i) {
  19013. var offset0 = i * size + dataOffset;
  19014. var offset1 = offset0 + 1;
  19015. var offset2 = offset0 + 2;
  19016. var offset3 = offset0 + 3;
  19017. var offset4 = offset0 + 4;
  19018. // It's easy to screw up offsets so perform this sanity check.
  19019. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19020. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19021. error('writing to an offset that is not empty');
  19022. }
  19023. var value = values[i];
  19024. data[offset0] = 0x1d;
  19025. data[offset1] = (value >> 24) & 0xFF;
  19026. data[offset2] = (value >> 16) & 0xFF;
  19027. data[offset3] = (value >> 8) & 0xFF;
  19028. data[offset4] = value & 0xFF;
  19029. }
  19030. }
  19031. };
  19032. return CFFOffsetTracker;
  19033. })();
  19034. // Takes a CFF and converts it to the binary representation.
  19035. var CFFCompiler = (function CFFCompilerClosure() {
  19036. function CFFCompiler(cff) {
  19037. this.cff = cff;
  19038. }
  19039. CFFCompiler.prototype = {
  19040. compile: function CFFCompiler_compile() {
  19041. var cff = this.cff;
  19042. var output = {
  19043. data: [],
  19044. length: 0,
  19045. add: function CFFCompiler_add(data) {
  19046. this.data = this.data.concat(data);
  19047. this.length = this.data.length;
  19048. }
  19049. };
  19050. // Compile the five entries that must be in order.
  19051. var header = this.compileHeader(cff.header);
  19052. output.add(header);
  19053. var nameIndex = this.compileNameIndex(cff.names);
  19054. output.add(nameIndex);
  19055. if (cff.isCIDFont) {
  19056. // The spec is unclear on how font matrices should relate to each other
  19057. // when there is one in the main top dict and the sub top dicts.
  19058. // Windows handles this differently than linux and osx so we have to
  19059. // normalize to work on all.
  19060. // Rules based off of some mailing list discussions:
  19061. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19062. // - If no main font matrix and there is a subfont matrix, use the
  19063. // subfont matrix.
  19064. // - If both have matrices, concat together.
  19065. // - If neither have matrices, use default.
  19066. // To make this work on all platforms we move the top matrix into each
  19067. // sub top dict and concat if necessary.
  19068. if (cff.topDict.hasName('FontMatrix')) {
  19069. var base = cff.topDict.getByName('FontMatrix');
  19070. cff.topDict.removeByName('FontMatrix');
  19071. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19072. var subDict = cff.fdArray[i];
  19073. var matrix = base.slice(0);
  19074. if (subDict.hasName('FontMatrix')) {
  19075. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19076. }
  19077. subDict.setByName('FontMatrix', matrix);
  19078. }
  19079. }
  19080. }
  19081. var compiled = this.compileTopDicts([cff.topDict],
  19082. output.length,
  19083. cff.isCIDFont);
  19084. output.add(compiled.output);
  19085. var topDictTracker = compiled.trackers[0];
  19086. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19087. output.add(stringIndex);
  19088. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19089. output.add(globalSubrIndex);
  19090. // Now start on the other entries that have no specfic order.
  19091. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19092. if (cff.encoding.predefined) {
  19093. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19094. output);
  19095. } else {
  19096. var encoding = this.compileEncoding(cff.encoding);
  19097. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19098. output.add(encoding);
  19099. }
  19100. }
  19101. if (cff.charset && cff.topDict.hasName('charset')) {
  19102. if (cff.charset.predefined) {
  19103. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19104. output);
  19105. } else {
  19106. var charset = this.compileCharset(cff.charset);
  19107. topDictTracker.setEntryLocation('charset', [output.length], output);
  19108. output.add(charset);
  19109. }
  19110. }
  19111. var charStrings = this.compileCharStrings(cff.charStrings);
  19112. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19113. output.add(charStrings);
  19114. if (cff.isCIDFont) {
  19115. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19116. // and linux don't seem to care.
  19117. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19118. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19119. output.add(fdSelect);
  19120. // It is unclear if the sub font dictionary can have CID related
  19121. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19122. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19123. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19124. output.add(compiled.output);
  19125. var fontDictTrackers = compiled.trackers;
  19126. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19127. }
  19128. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19129. // If the font data ends with INDEX whose object data is zero-length,
  19130. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19131. output.add([0]);
  19132. return output.data;
  19133. },
  19134. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19135. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19136. return this.encodeInteger(value);
  19137. } else {
  19138. return this.encodeFloat(value);
  19139. }
  19140. },
  19141. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19142. var value = num.toString();
  19143. // rounding inaccurate doubles
  19144. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19145. if (m) {
  19146. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19147. value = (Math.round(num * epsilon) / epsilon).toString();
  19148. }
  19149. var nibbles = '';
  19150. var i, ii;
  19151. for (i = 0, ii = value.length; i < ii; ++i) {
  19152. var a = value[i];
  19153. if (a === 'e') {
  19154. nibbles += value[++i] === '-' ? 'c' : 'b';
  19155. } else if (a === '.') {
  19156. nibbles += 'a';
  19157. } else if (a === '-') {
  19158. nibbles += 'e';
  19159. } else {
  19160. nibbles += a;
  19161. }
  19162. }
  19163. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19164. var out = [30];
  19165. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19166. out.push(parseInt(nibbles.substr(i, 2), 16));
  19167. }
  19168. return out;
  19169. },
  19170. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19171. var code;
  19172. if (value >= -107 && value <= 107) {
  19173. code = [value + 139];
  19174. } else if (value >= 108 && value <= 1131) {
  19175. value = [value - 108];
  19176. code = [(value >> 8) + 247, value & 0xFF];
  19177. } else if (value >= -1131 && value <= -108) {
  19178. value = -value - 108;
  19179. code = [(value >> 8) + 251, value & 0xFF];
  19180. } else if (value >= -32768 && value <= 32767) {
  19181. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19182. } else {
  19183. code = [0x1d,
  19184. (value >> 24) & 0xFF,
  19185. (value >> 16) & 0xFF,
  19186. (value >> 8) & 0xFF,
  19187. value & 0xFF];
  19188. }
  19189. return code;
  19190. },
  19191. compileHeader: function CFFCompiler_compileHeader(header) {
  19192. return [
  19193. header.major,
  19194. header.minor,
  19195. header.hdrSize,
  19196. header.offSize
  19197. ];
  19198. },
  19199. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19200. var nameIndex = new CFFIndex();
  19201. for (var i = 0, ii = names.length; i < ii; ++i) {
  19202. nameIndex.add(stringToBytes(names[i]));
  19203. }
  19204. return this.compileIndex(nameIndex);
  19205. },
  19206. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19207. length,
  19208. removeCidKeys) {
  19209. var fontDictTrackers = [];
  19210. var fdArrayIndex = new CFFIndex();
  19211. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19212. var fontDict = dicts[i];
  19213. if (removeCidKeys) {
  19214. fontDict.removeByName('CIDFontVersion');
  19215. fontDict.removeByName('CIDFontRevision');
  19216. fontDict.removeByName('CIDFontType');
  19217. fontDict.removeByName('CIDCount');
  19218. fontDict.removeByName('UIDBase');
  19219. }
  19220. var fontDictTracker = new CFFOffsetTracker();
  19221. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19222. fontDictTrackers.push(fontDictTracker);
  19223. fdArrayIndex.add(fontDictData);
  19224. fontDictTracker.offset(length);
  19225. }
  19226. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19227. return {
  19228. trackers: fontDictTrackers,
  19229. output: fdArrayIndex
  19230. };
  19231. },
  19232. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19233. trackers,
  19234. output) {
  19235. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19236. var fontDict = dicts[i];
  19237. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19238. 'There must be an private dictionary.');
  19239. var privateDict = fontDict.privateDict;
  19240. var privateDictTracker = new CFFOffsetTracker();
  19241. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19242. var outputLength = output.length;
  19243. privateDictTracker.offset(outputLength);
  19244. if (!privateDictData.length) {
  19245. // The private dictionary was empty, set the output length to zero to
  19246. // ensure the offset length isn't out of bounds in the eyes of the
  19247. // sanitizer.
  19248. outputLength = 0;
  19249. }
  19250. trackers[i].setEntryLocation('Private',
  19251. [privateDictData.length, outputLength],
  19252. output);
  19253. output.add(privateDictData);
  19254. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19255. var subrs = this.compileIndex(privateDict.subrsIndex);
  19256. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19257. output);
  19258. output.add(subrs);
  19259. }
  19260. }
  19261. },
  19262. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19263. var out = [];
  19264. // The dictionary keys must be in a certain order.
  19265. var order = dict.order;
  19266. for (var i = 0; i < order.length; ++i) {
  19267. var key = order[i];
  19268. if (!(key in dict.values)) {
  19269. continue;
  19270. }
  19271. var values = dict.values[key];
  19272. var types = dict.types[key];
  19273. if (!isArray(types)) {
  19274. types = [types];
  19275. }
  19276. if (!isArray(values)) {
  19277. values = [values];
  19278. }
  19279. // Remove any empty dict values.
  19280. if (values.length === 0) {
  19281. continue;
  19282. }
  19283. for (var j = 0, jj = types.length; j < jj; ++j) {
  19284. var type = types[j];
  19285. var value = values[j];
  19286. switch (type) {
  19287. case 'num':
  19288. case 'sid':
  19289. out = out.concat(this.encodeNumber(value));
  19290. break;
  19291. case 'offset':
  19292. // For offsets we just insert a 32bit integer so we don't have to
  19293. // deal with figuring out the length of the offset when it gets
  19294. // replaced later on by the compiler.
  19295. var name = dict.keyToNameMap[key];
  19296. // Some offsets have the offset and the length, so just record the
  19297. // position of the first one.
  19298. if (!offsetTracker.isTracking(name)) {
  19299. offsetTracker.track(name, out.length);
  19300. }
  19301. out = out.concat([0x1d, 0, 0, 0, 0]);
  19302. break;
  19303. case 'array':
  19304. case 'delta':
  19305. out = out.concat(this.encodeNumber(value));
  19306. for (var k = 1, kk = values.length; k < kk; ++k) {
  19307. out = out.concat(this.encodeNumber(values[k]));
  19308. }
  19309. break;
  19310. default:
  19311. error('Unknown data type of ' + type);
  19312. break;
  19313. }
  19314. }
  19315. out = out.concat(dict.opcodes[key]);
  19316. }
  19317. return out;
  19318. },
  19319. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19320. var stringIndex = new CFFIndex();
  19321. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19322. stringIndex.add(stringToBytes(strings[i]));
  19323. }
  19324. return this.compileIndex(stringIndex);
  19325. },
  19326. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19327. var globalSubrIndex = this.cff.globalSubrIndex;
  19328. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19329. },
  19330. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19331. return this.compileIndex(charStrings);
  19332. },
  19333. compileCharset: function CFFCompiler_compileCharset(charset) {
  19334. return this.compileTypedArray(charset.raw);
  19335. },
  19336. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19337. return this.compileTypedArray(encoding.raw);
  19338. },
  19339. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19340. return this.compileTypedArray(fdSelect);
  19341. },
  19342. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19343. var out = [];
  19344. for (var i = 0, ii = data.length; i < ii; ++i) {
  19345. out[i] = data[i];
  19346. }
  19347. return out;
  19348. },
  19349. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19350. trackers = trackers || [];
  19351. var objects = index.objects;
  19352. // First 2 bytes contains the number of objects contained into this index
  19353. var count = objects.length;
  19354. // If there is no object, just create an index. This technically
  19355. // should just be [0, 0] but OTS has an issue with that.
  19356. if (count === 0) {
  19357. return [0, 0, 0];
  19358. }
  19359. var data = [(count >> 8) & 0xFF, count & 0xff];
  19360. var lastOffset = 1, i;
  19361. for (i = 0; i < count; ++i) {
  19362. lastOffset += objects[i].length;
  19363. }
  19364. var offsetSize;
  19365. if (lastOffset < 0x100) {
  19366. offsetSize = 1;
  19367. } else if (lastOffset < 0x10000) {
  19368. offsetSize = 2;
  19369. } else if (lastOffset < 0x1000000) {
  19370. offsetSize = 3;
  19371. } else {
  19372. offsetSize = 4;
  19373. }
  19374. // Next byte contains the offset size use to reference object in the file
  19375. data.push(offsetSize);
  19376. // Add another offset after this one because we need a new offset
  19377. var relativeOffset = 1;
  19378. for (i = 0; i < count + 1; i++) {
  19379. if (offsetSize === 1) {
  19380. data.push(relativeOffset & 0xFF);
  19381. } else if (offsetSize === 2) {
  19382. data.push((relativeOffset >> 8) & 0xFF,
  19383. relativeOffset & 0xFF);
  19384. } else if (offsetSize === 3) {
  19385. data.push((relativeOffset >> 16) & 0xFF,
  19386. (relativeOffset >> 8) & 0xFF,
  19387. relativeOffset & 0xFF);
  19388. } else {
  19389. data.push((relativeOffset >>> 24) & 0xFF,
  19390. (relativeOffset >> 16) & 0xFF,
  19391. (relativeOffset >> 8) & 0xFF,
  19392. relativeOffset & 0xFF);
  19393. }
  19394. if (objects[i]) {
  19395. relativeOffset += objects[i].length;
  19396. }
  19397. }
  19398. for (i = 0; i < count; i++) {
  19399. // Notify the tracker where the object will be offset in the data.
  19400. if (trackers[i]) {
  19401. trackers[i].offset(data.length);
  19402. }
  19403. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19404. data.push(objects[i][j]);
  19405. }
  19406. }
  19407. return data;
  19408. }
  19409. };
  19410. return CFFCompiler;
  19411. })();
  19412. // Workaround for seac on Windows.
  19413. (function checkSeacSupport() {
  19414. if (/Windows/.test(navigator.userAgent)) {
  19415. SEAC_ANALYSIS_ENABLED = true;
  19416. }
  19417. })();
  19418. // Workaround for Private Use Area characters in Chrome on Windows
  19419. // http://code.google.com/p/chromium/issues/detail?id=122465
  19420. // https://github.com/mozilla/pdf.js/issues/1689
  19421. (function checkChromeWindows() {
  19422. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19423. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19424. }
  19425. })();
  19426. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19427. function getLong(data, offset) {
  19428. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19429. (data[offset + 2] << 8) | data[offset + 3];
  19430. }
  19431. function getUshort(data, offset) {
  19432. return (data[offset] << 8) | data[offset + 1];
  19433. }
  19434. function parseCmap(data, start, end) {
  19435. var offset = (getUshort(data, start + 2) === 1 ?
  19436. getLong(data, start + 8) : getLong(data, start + 16));
  19437. var format = getUshort(data, start + offset);
  19438. var length, ranges, p, i;
  19439. if (format === 4) {
  19440. length = getUshort(data, start + offset + 2);
  19441. var segCount = getUshort(data, start + offset + 6) >> 1;
  19442. p = start + offset + 14;
  19443. ranges = [];
  19444. for (i = 0; i < segCount; i++, p += 2) {
  19445. ranges[i] = {end: getUshort(data, p)};
  19446. }
  19447. p += 2;
  19448. for (i = 0; i < segCount; i++, p += 2) {
  19449. ranges[i].start = getUshort(data, p);
  19450. }
  19451. for (i = 0; i < segCount; i++, p += 2) {
  19452. ranges[i].idDelta = getUshort(data, p);
  19453. }
  19454. for (i = 0; i < segCount; i++, p += 2) {
  19455. var idOffset = getUshort(data, p);
  19456. if (idOffset === 0) {
  19457. continue;
  19458. }
  19459. ranges[i].ids = [];
  19460. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19461. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19462. idOffset += 2;
  19463. }
  19464. }
  19465. return ranges;
  19466. } else if (format === 12) {
  19467. length = getLong(data, start + offset + 4);
  19468. var groups = getLong(data, start + offset + 12);
  19469. p = start + offset + 16;
  19470. ranges = [];
  19471. for (i = 0; i < groups; i++) {
  19472. ranges.push({
  19473. start: getLong(data, p),
  19474. end: getLong(data, p + 4),
  19475. idDelta: getLong(data, p + 8) - getLong(data, p)
  19476. });
  19477. p += 12;
  19478. }
  19479. return ranges;
  19480. }
  19481. error('not supported cmap: ' + format);
  19482. }
  19483. function parseCff(data, start, end) {
  19484. var properties = {};
  19485. var parser = new CFFParser(new Stream(data, start, end - start),
  19486. properties);
  19487. var cff = parser.parse();
  19488. return {
  19489. glyphs: cff.charStrings.objects,
  19490. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19491. cff.topDict.privateDict.subrsIndex.objects),
  19492. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19493. };
  19494. }
  19495. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19496. var itemSize, itemDecode;
  19497. if (isGlyphLocationsLong) {
  19498. itemSize = 4;
  19499. itemDecode = function fontItemDecodeLong(data, offset) {
  19500. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19501. (data[offset + 2] << 8) | data[offset + 3];
  19502. };
  19503. } else {
  19504. itemSize = 2;
  19505. itemDecode = function fontItemDecode(data, offset) {
  19506. return (data[offset] << 9) | (data[offset + 1] << 1);
  19507. };
  19508. }
  19509. var glyphs = [];
  19510. var startOffset = itemDecode(loca, 0);
  19511. for (var j = itemSize; j < loca.length; j += itemSize) {
  19512. var endOffset = itemDecode(loca, j);
  19513. glyphs.push(glyf.subarray(startOffset, endOffset));
  19514. startOffset = endOffset;
  19515. }
  19516. return glyphs;
  19517. }
  19518. function lookupCmap(ranges, unicode) {
  19519. var code = unicode.charCodeAt(0);
  19520. var l = 0, r = ranges.length - 1;
  19521. while (l < r) {
  19522. var c = (l + r + 1) >> 1;
  19523. if (code < ranges[c].start) {
  19524. r = c - 1;
  19525. } else {
  19526. l = c;
  19527. }
  19528. }
  19529. if (ranges[l].start <= code && code <= ranges[l].end) {
  19530. return (ranges[l].idDelta + (ranges[l].ids ?
  19531. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19532. }
  19533. return 0;
  19534. }
  19535. function compileGlyf(code, js, font) {
  19536. function moveTo(x, y) {
  19537. js.push('c.moveTo(' + x + ',' + y + ');');
  19538. }
  19539. function lineTo(x, y) {
  19540. js.push('c.lineTo(' + x + ',' + y + ');');
  19541. }
  19542. function quadraticCurveTo(xa, ya, x, y) {
  19543. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19544. x + ',' + y + ');');
  19545. }
  19546. var i = 0;
  19547. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19548. var flags;
  19549. var x = 0, y = 0;
  19550. i += 10;
  19551. if (numberOfContours < 0) {
  19552. // composite glyph
  19553. do {
  19554. flags = (code[i] << 8) | code[i + 1];
  19555. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19556. i += 4;
  19557. var arg1, arg2;
  19558. if ((flags & 0x01)) {
  19559. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19560. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19561. i += 4;
  19562. } else {
  19563. arg1 = code[i++]; arg2 = code[i++];
  19564. }
  19565. if ((flags & 0x02)) {
  19566. x = arg1;
  19567. y = arg2;
  19568. } else {
  19569. x = 0; y = 0; // TODO "they are points" ?
  19570. }
  19571. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19572. if ((flags & 0x08)) {
  19573. scaleX =
  19574. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19575. i += 2;
  19576. } else if ((flags & 0x40)) {
  19577. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19578. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19579. i += 4;
  19580. } else if ((flags & 0x80)) {
  19581. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19582. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19583. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19584. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19585. i += 8;
  19586. }
  19587. var subglyph = font.glyphs[glyphIndex];
  19588. if (subglyph) {
  19589. js.push('c.save();');
  19590. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19591. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19592. compileGlyf(subglyph, js, font);
  19593. js.push('c.restore();');
  19594. }
  19595. } while ((flags & 0x20));
  19596. } else {
  19597. // simple glyph
  19598. var endPtsOfContours = [];
  19599. var j, jj;
  19600. for (j = 0; j < numberOfContours; j++) {
  19601. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19602. i += 2;
  19603. }
  19604. var instructionLength = (code[i] << 8) | code[i + 1];
  19605. i += 2 + instructionLength; // skipping the instructions
  19606. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19607. var points = [];
  19608. while (points.length < numberOfPoints) {
  19609. flags = code[i++];
  19610. var repeat = 1;
  19611. if ((flags & 0x08)) {
  19612. repeat += code[i++];
  19613. }
  19614. while (repeat-- > 0) {
  19615. points.push({flags: flags});
  19616. }
  19617. }
  19618. for (j = 0; j < numberOfPoints; j++) {
  19619. switch (points[j].flags & 0x12) {
  19620. case 0x00:
  19621. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19622. i += 2;
  19623. break;
  19624. case 0x02:
  19625. x -= code[i++];
  19626. break;
  19627. case 0x12:
  19628. x += code[i++];
  19629. break;
  19630. }
  19631. points[j].x = x;
  19632. }
  19633. for (j = 0; j < numberOfPoints; j++) {
  19634. switch (points[j].flags & 0x24) {
  19635. case 0x00:
  19636. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19637. i += 2;
  19638. break;
  19639. case 0x04:
  19640. y -= code[i++];
  19641. break;
  19642. case 0x24:
  19643. y += code[i++];
  19644. break;
  19645. }
  19646. points[j].y = y;
  19647. }
  19648. var startPoint = 0;
  19649. for (i = 0; i < numberOfContours; i++) {
  19650. var endPoint = endPtsOfContours[i];
  19651. // contours might have implicit points, which is located in the middle
  19652. // between two neighboring off-curve points
  19653. var contour = points.slice(startPoint, endPoint + 1);
  19654. if ((contour[0].flags & 1)) {
  19655. contour.push(contour[0]); // using start point at the contour end
  19656. } else if ((contour[contour.length - 1].flags & 1)) {
  19657. // first is off-curve point, trying to use one from the end
  19658. contour.unshift(contour[contour.length - 1]);
  19659. } else {
  19660. // start and end are off-curve points, creating implicit one
  19661. var p = {
  19662. flags: 1,
  19663. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19664. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19665. };
  19666. contour.unshift(p);
  19667. contour.push(p);
  19668. }
  19669. moveTo(contour[0].x, contour[0].y);
  19670. for (j = 1, jj = contour.length; j < jj; j++) {
  19671. if ((contour[j].flags & 1)) {
  19672. lineTo(contour[j].x, contour[j].y);
  19673. } else if ((contour[j + 1].flags & 1)){
  19674. quadraticCurveTo(contour[j].x, contour[j].y,
  19675. contour[j + 1].x, contour[j + 1].y);
  19676. j++;
  19677. } else {
  19678. quadraticCurveTo(contour[j].x, contour[j].y,
  19679. (contour[j].x + contour[j + 1].x) / 2,
  19680. (contour[j].y + contour[j + 1].y) / 2);
  19681. }
  19682. }
  19683. startPoint = endPoint + 1;
  19684. }
  19685. }
  19686. }
  19687. function compileCharString(code, js, font) {
  19688. var stack = [];
  19689. var x = 0, y = 0;
  19690. var stems = 0;
  19691. function moveTo(x, y) {
  19692. js.push('c.moveTo(' + x + ',' + y + ');');
  19693. }
  19694. function lineTo(x, y) {
  19695. js.push('c.lineTo(' + x + ',' + y + ');');
  19696. }
  19697. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19698. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19699. x + ',' + y + ');');
  19700. }
  19701. function parse(code) {
  19702. var i = 0;
  19703. while (i < code.length) {
  19704. var stackClean = false;
  19705. var v = code[i++];
  19706. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19707. switch (v) {
  19708. case 1: // hstem
  19709. stems += stack.length >> 1;
  19710. stackClean = true;
  19711. break;
  19712. case 3: // vstem
  19713. stems += stack.length >> 1;
  19714. stackClean = true;
  19715. break;
  19716. case 4: // vmoveto
  19717. y += stack.pop();
  19718. moveTo(x, y);
  19719. stackClean = true;
  19720. break;
  19721. case 5: // rlineto
  19722. while (stack.length > 0) {
  19723. x += stack.shift();
  19724. y += stack.shift();
  19725. lineTo(x, y);
  19726. }
  19727. break;
  19728. case 6: // hlineto
  19729. while (stack.length > 0) {
  19730. x += stack.shift();
  19731. lineTo(x, y);
  19732. if (stack.length === 0) {
  19733. break;
  19734. }
  19735. y += stack.shift();
  19736. lineTo(x, y);
  19737. }
  19738. break;
  19739. case 7: // vlineto
  19740. while (stack.length > 0) {
  19741. y += stack.shift();
  19742. lineTo(x, y);
  19743. if (stack.length === 0) {
  19744. break;
  19745. }
  19746. x += stack.shift();
  19747. lineTo(x, y);
  19748. }
  19749. break;
  19750. case 8: // rrcurveto
  19751. while (stack.length > 0) {
  19752. xa = x + stack.shift(); ya = y + stack.shift();
  19753. xb = xa + stack.shift(); yb = ya + stack.shift();
  19754. x = xb + stack.shift(); y = yb + stack.shift();
  19755. bezierCurveTo(xa, ya, xb, yb, x, y);
  19756. }
  19757. break;
  19758. case 10: // callsubr
  19759. n = stack.pop() + font.subrsBias;
  19760. subrCode = font.subrs[n];
  19761. if (subrCode) {
  19762. parse(subrCode);
  19763. }
  19764. break;
  19765. case 11: // return
  19766. return;
  19767. case 12:
  19768. v = code[i++];
  19769. switch (v) {
  19770. case 34: // flex
  19771. xa = x + stack.shift();
  19772. xb = xa + stack.shift(); y1 = y + stack.shift();
  19773. x = xb + stack.shift();
  19774. bezierCurveTo(xa, y, xb, y1, x, y1);
  19775. xa = x + stack.shift();
  19776. xb = xa + stack.shift();
  19777. x = xb + stack.shift();
  19778. bezierCurveTo(xa, y1, xb, y, x, y);
  19779. break;
  19780. case 35: // flex
  19781. xa = x + stack.shift(); ya = y + stack.shift();
  19782. xb = xa + stack.shift(); yb = ya + stack.shift();
  19783. x = xb + stack.shift(); y = yb + stack.shift();
  19784. bezierCurveTo(xa, ya, xb, yb, x, y);
  19785. xa = x + stack.shift(); ya = y + stack.shift();
  19786. xb = xa + stack.shift(); yb = ya + stack.shift();
  19787. x = xb + stack.shift(); y = yb + stack.shift();
  19788. bezierCurveTo(xa, ya, xb, yb, x, y);
  19789. stack.pop(); // fd
  19790. break;
  19791. case 36: // hflex1
  19792. xa = x + stack.shift(); y1 = y + stack.shift();
  19793. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19794. x = xb + stack.shift();
  19795. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19796. xa = x + stack.shift();
  19797. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19798. x = xb + stack.shift();
  19799. bezierCurveTo(xa, y2, xb, y3, x, y);
  19800. break;
  19801. case 37: // flex1
  19802. var x0 = x, y0 = y;
  19803. xa = x + stack.shift(); ya = y + stack.shift();
  19804. xb = xa + stack.shift(); yb = ya + stack.shift();
  19805. x = xb + stack.shift(); y = yb + stack.shift();
  19806. bezierCurveTo(xa, ya, xb, yb, x, y);
  19807. xa = x + stack.shift(); ya = y + stack.shift();
  19808. xb = xa + stack.shift(); yb = ya + stack.shift();
  19809. x = xb; y = yb;
  19810. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19811. x += stack.shift();
  19812. } else {
  19813. y += stack.shift();
  19814. }
  19815. bezierCurveTo(xa, ya, xb, yb, x, y);
  19816. break;
  19817. default:
  19818. error('unknown operator: 12 ' + v);
  19819. }
  19820. break;
  19821. case 14: // endchar
  19822. if (stack.length >= 4) {
  19823. var achar = stack.pop();
  19824. var bchar = stack.pop();
  19825. y = stack.pop();
  19826. x = stack.pop();
  19827. js.push('c.save();');
  19828. js.push('c.translate('+ x + ',' + y + ');');
  19829. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19830. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19831. compileCharString(font.glyphs[gid], js, font);
  19832. js.push('c.restore();');
  19833. gid = lookupCmap(font.cmap, String.fromCharCode(
  19834. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19835. compileCharString(font.glyphs[gid], js, font);
  19836. }
  19837. return;
  19838. case 18: // hstemhm
  19839. stems += stack.length >> 1;
  19840. stackClean = true;
  19841. break;
  19842. case 19: // hintmask
  19843. stems += stack.length >> 1;
  19844. i += (stems + 7) >> 3;
  19845. stackClean = true;
  19846. break;
  19847. case 20: // cntrmask
  19848. stems += stack.length >> 1;
  19849. i += (stems + 7) >> 3;
  19850. stackClean = true;
  19851. break;
  19852. case 21: // rmoveto
  19853. y += stack.pop();
  19854. x += stack.pop();
  19855. moveTo(x, y);
  19856. stackClean = true;
  19857. break;
  19858. case 22: // hmoveto
  19859. x += stack.pop();
  19860. moveTo(x, y);
  19861. stackClean = true;
  19862. break;
  19863. case 23: // vstemhm
  19864. stems += stack.length >> 1;
  19865. stackClean = true;
  19866. break;
  19867. case 24: // rcurveline
  19868. while (stack.length > 2) {
  19869. xa = x + stack.shift(); ya = y + stack.shift();
  19870. xb = xa + stack.shift(); yb = ya + stack.shift();
  19871. x = xb + stack.shift(); y = yb + stack.shift();
  19872. bezierCurveTo(xa, ya, xb, yb, x, y);
  19873. }
  19874. x += stack.shift();
  19875. y += stack.shift();
  19876. lineTo(x, y);
  19877. break;
  19878. case 25: // rlinecurve
  19879. while (stack.length > 6) {
  19880. x += stack.shift();
  19881. y += stack.shift();
  19882. lineTo(x, y);
  19883. }
  19884. xa = x + stack.shift(); ya = y + stack.shift();
  19885. xb = xa + stack.shift(); yb = ya + stack.shift();
  19886. x = xb + stack.shift(); y = yb + stack.shift();
  19887. bezierCurveTo(xa, ya, xb, yb, x, y);
  19888. break;
  19889. case 26: // vvcurveto
  19890. if (stack.length % 2) {
  19891. x += stack.shift();
  19892. }
  19893. while (stack.length > 0) {
  19894. xa = x; ya = y + stack.shift();
  19895. xb = xa + stack.shift(); yb = ya + stack.shift();
  19896. x = xb; y = yb + stack.shift();
  19897. bezierCurveTo(xa, ya, xb, yb, x, y);
  19898. }
  19899. break;
  19900. case 27: // hhcurveto
  19901. if (stack.length % 2) {
  19902. y += stack.shift();
  19903. }
  19904. while (stack.length > 0) {
  19905. xa = x + stack.shift(); ya = y;
  19906. xb = xa + stack.shift(); yb = ya + stack.shift();
  19907. x = xb + stack.shift(); y = yb;
  19908. bezierCurveTo(xa, ya, xb, yb, x, y);
  19909. }
  19910. break;
  19911. case 28:
  19912. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19913. i += 2;
  19914. break;
  19915. case 29: // callgsubr
  19916. n = stack.pop() + font.gsubrsBias;
  19917. subrCode = font.gsubrs[n];
  19918. if (subrCode) {
  19919. parse(subrCode);
  19920. }
  19921. break;
  19922. case 30: // vhcurveto
  19923. while (stack.length > 0) {
  19924. xa = x; ya = y + stack.shift();
  19925. xb = xa + stack.shift(); yb = ya + stack.shift();
  19926. x = xb + stack.shift();
  19927. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19928. bezierCurveTo(xa, ya, xb, yb, x, y);
  19929. if (stack.length === 0) {
  19930. break;
  19931. }
  19932. xa = x + stack.shift(); ya = y;
  19933. xb = xa + stack.shift(); yb = ya + stack.shift();
  19934. y = yb + stack.shift();
  19935. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19936. bezierCurveTo(xa, ya, xb, yb, x, y);
  19937. }
  19938. break;
  19939. case 31: // hvcurveto
  19940. while (stack.length > 0) {
  19941. xa = x + stack.shift(); ya = y;
  19942. xb = xa + stack.shift(); yb = ya + stack.shift();
  19943. y = yb + stack.shift();
  19944. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19945. bezierCurveTo(xa, ya, xb, yb, x, y);
  19946. if (stack.length === 0) {
  19947. break;
  19948. }
  19949. xa = x; ya = y + stack.shift();
  19950. xb = xa + stack.shift(); yb = ya + stack.shift();
  19951. x = xb + stack.shift();
  19952. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19953. bezierCurveTo(xa, ya, xb, yb, x, y);
  19954. }
  19955. break;
  19956. default:
  19957. if (v < 32) {
  19958. error('unknown operator: ' + v);
  19959. }
  19960. if (v < 247) {
  19961. stack.push(v - 139);
  19962. } else if (v < 251) {
  19963. stack.push((v - 247) * 256 + code[i++] + 108);
  19964. } else if (v < 255) {
  19965. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19966. } else {
  19967. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19968. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19969. i += 4;
  19970. }
  19971. break;
  19972. }
  19973. if (stackClean) {
  19974. stack.length = 0;
  19975. }
  19976. }
  19977. }
  19978. parse(code);
  19979. }
  19980. var noop = '';
  19981. function CompiledFont(fontMatrix) {
  19982. this.compiledGlyphs = {};
  19983. this.fontMatrix = fontMatrix;
  19984. }
  19985. CompiledFont.prototype = {
  19986. getPathJs: function (unicode) {
  19987. var gid = lookupCmap(this.cmap, unicode);
  19988. var fn = this.compiledGlyphs[gid];
  19989. if (!fn) {
  19990. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19991. }
  19992. return fn;
  19993. },
  19994. compileGlyph: function (code) {
  19995. if (!code || code.length === 0 || code[0] === 14) {
  19996. return noop;
  19997. }
  19998. var js = [];
  19999. js.push('c.save();');
  20000. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20001. js.push('c.scale(size, -size);');
  20002. this.compileGlyphImpl(code, js);
  20003. js.push('c.restore();');
  20004. return js.join('\n');
  20005. },
  20006. compileGlyphImpl: function () {
  20007. error('Children classes should implement this.');
  20008. },
  20009. hasBuiltPath: function (unicode) {
  20010. var gid = lookupCmap(this.cmap, unicode);
  20011. return gid in this.compiledGlyphs;
  20012. }
  20013. };
  20014. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20015. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20016. CompiledFont.call(this, fontMatrix);
  20017. this.glyphs = glyphs;
  20018. this.cmap = cmap;
  20019. this.compiledGlyphs = [];
  20020. }
  20021. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20022. compileGlyphImpl: function (code, js) {
  20023. compileGlyf(code, js, this);
  20024. }
  20025. });
  20026. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20027. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20028. CompiledFont.call(this, fontMatrix);
  20029. this.glyphs = cffInfo.glyphs;
  20030. this.gsubrs = cffInfo.gsubrs || [];
  20031. this.subrs = cffInfo.subrs || [];
  20032. this.cmap = cmap;
  20033. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20034. this.compiledGlyphs = [];
  20035. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20036. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20037. this.subrsBias = (this.subrs.length < 1240 ?
  20038. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20039. }
  20040. Util.inherit(Type2Compiled, CompiledFont, {
  20041. compileGlyphImpl: function (code, js) {
  20042. compileCharString(code, js, this);
  20043. }
  20044. });
  20045. return {
  20046. create: function FontRendererFactory_create(font) {
  20047. var data = new Uint8Array(font.data);
  20048. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20049. var numTables = getUshort(data, 4);
  20050. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20051. var tag = bytesToString(data.subarray(p, p + 4));
  20052. var offset = getLong(data, p + 8);
  20053. var length = getLong(data, p + 12);
  20054. switch (tag) {
  20055. case 'cmap':
  20056. cmap = parseCmap(data, offset, offset + length);
  20057. break;
  20058. case 'glyf':
  20059. glyf = data.subarray(offset, offset + length);
  20060. break;
  20061. case 'loca':
  20062. loca = data.subarray(offset, offset + length);
  20063. break;
  20064. case 'head':
  20065. unitsPerEm = getUshort(data, offset + 18);
  20066. indexToLocFormat = getUshort(data, offset + 50);
  20067. break;
  20068. case 'CFF ':
  20069. cff = parseCff(data, offset, offset + length);
  20070. break;
  20071. }
  20072. }
  20073. if (glyf) {
  20074. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20075. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20076. return new TrueTypeCompiled(
  20077. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20078. } else {
  20079. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20080. }
  20081. }
  20082. };
  20083. })();
  20084. var GlyphsUnicode = {
  20085. A: 0x0041,
  20086. AE: 0x00C6,
  20087. AEacute: 0x01FC,
  20088. AEmacron: 0x01E2,
  20089. AEsmall: 0xF7E6,
  20090. Aacute: 0x00C1,
  20091. Aacutesmall: 0xF7E1,
  20092. Abreve: 0x0102,
  20093. Abreveacute: 0x1EAE,
  20094. Abrevecyrillic: 0x04D0,
  20095. Abrevedotbelow: 0x1EB6,
  20096. Abrevegrave: 0x1EB0,
  20097. Abrevehookabove: 0x1EB2,
  20098. Abrevetilde: 0x1EB4,
  20099. Acaron: 0x01CD,
  20100. Acircle: 0x24B6,
  20101. Acircumflex: 0x00C2,
  20102. Acircumflexacute: 0x1EA4,
  20103. Acircumflexdotbelow: 0x1EAC,
  20104. Acircumflexgrave: 0x1EA6,
  20105. Acircumflexhookabove: 0x1EA8,
  20106. Acircumflexsmall: 0xF7E2,
  20107. Acircumflextilde: 0x1EAA,
  20108. Acute: 0xF6C9,
  20109. Acutesmall: 0xF7B4,
  20110. Acyrillic: 0x0410,
  20111. Adblgrave: 0x0200,
  20112. Adieresis: 0x00C4,
  20113. Adieresiscyrillic: 0x04D2,
  20114. Adieresismacron: 0x01DE,
  20115. Adieresissmall: 0xF7E4,
  20116. Adotbelow: 0x1EA0,
  20117. Adotmacron: 0x01E0,
  20118. Agrave: 0x00C0,
  20119. Agravesmall: 0xF7E0,
  20120. Ahookabove: 0x1EA2,
  20121. Aiecyrillic: 0x04D4,
  20122. Ainvertedbreve: 0x0202,
  20123. Alpha: 0x0391,
  20124. Alphatonos: 0x0386,
  20125. Amacron: 0x0100,
  20126. Amonospace: 0xFF21,
  20127. Aogonek: 0x0104,
  20128. Aring: 0x00C5,
  20129. Aringacute: 0x01FA,
  20130. Aringbelow: 0x1E00,
  20131. Aringsmall: 0xF7E5,
  20132. Asmall: 0xF761,
  20133. Atilde: 0x00C3,
  20134. Atildesmall: 0xF7E3,
  20135. Aybarmenian: 0x0531,
  20136. B: 0x0042,
  20137. Bcircle: 0x24B7,
  20138. Bdotaccent: 0x1E02,
  20139. Bdotbelow: 0x1E04,
  20140. Becyrillic: 0x0411,
  20141. Benarmenian: 0x0532,
  20142. Beta: 0x0392,
  20143. Bhook: 0x0181,
  20144. Blinebelow: 0x1E06,
  20145. Bmonospace: 0xFF22,
  20146. Brevesmall: 0xF6F4,
  20147. Bsmall: 0xF762,
  20148. Btopbar: 0x0182,
  20149. C: 0x0043,
  20150. Caarmenian: 0x053E,
  20151. Cacute: 0x0106,
  20152. Caron: 0xF6CA,
  20153. Caronsmall: 0xF6F5,
  20154. Ccaron: 0x010C,
  20155. Ccedilla: 0x00C7,
  20156. Ccedillaacute: 0x1E08,
  20157. Ccedillasmall: 0xF7E7,
  20158. Ccircle: 0x24B8,
  20159. Ccircumflex: 0x0108,
  20160. Cdot: 0x010A,
  20161. Cdotaccent: 0x010A,
  20162. Cedillasmall: 0xF7B8,
  20163. Chaarmenian: 0x0549,
  20164. Cheabkhasiancyrillic: 0x04BC,
  20165. Checyrillic: 0x0427,
  20166. Chedescenderabkhasiancyrillic: 0x04BE,
  20167. Chedescendercyrillic: 0x04B6,
  20168. Chedieresiscyrillic: 0x04F4,
  20169. Cheharmenian: 0x0543,
  20170. Chekhakassiancyrillic: 0x04CB,
  20171. Cheverticalstrokecyrillic: 0x04B8,
  20172. Chi: 0x03A7,
  20173. Chook: 0x0187,
  20174. Circumflexsmall: 0xF6F6,
  20175. Cmonospace: 0xFF23,
  20176. Coarmenian: 0x0551,
  20177. Csmall: 0xF763,
  20178. D: 0x0044,
  20179. DZ: 0x01F1,
  20180. DZcaron: 0x01C4,
  20181. Daarmenian: 0x0534,
  20182. Dafrican: 0x0189,
  20183. Dcaron: 0x010E,
  20184. Dcedilla: 0x1E10,
  20185. Dcircle: 0x24B9,
  20186. Dcircumflexbelow: 0x1E12,
  20187. Dcroat: 0x0110,
  20188. Ddotaccent: 0x1E0A,
  20189. Ddotbelow: 0x1E0C,
  20190. Decyrillic: 0x0414,
  20191. Deicoptic: 0x03EE,
  20192. Delta: 0x2206,
  20193. Deltagreek: 0x0394,
  20194. Dhook: 0x018A,
  20195. Dieresis: 0xF6CB,
  20196. DieresisAcute: 0xF6CC,
  20197. DieresisGrave: 0xF6CD,
  20198. Dieresissmall: 0xF7A8,
  20199. Digammagreek: 0x03DC,
  20200. Djecyrillic: 0x0402,
  20201. Dlinebelow: 0x1E0E,
  20202. Dmonospace: 0xFF24,
  20203. Dotaccentsmall: 0xF6F7,
  20204. Dslash: 0x0110,
  20205. Dsmall: 0xF764,
  20206. Dtopbar: 0x018B,
  20207. Dz: 0x01F2,
  20208. Dzcaron: 0x01C5,
  20209. Dzeabkhasiancyrillic: 0x04E0,
  20210. Dzecyrillic: 0x0405,
  20211. Dzhecyrillic: 0x040F,
  20212. E: 0x0045,
  20213. Eacute: 0x00C9,
  20214. Eacutesmall: 0xF7E9,
  20215. Ebreve: 0x0114,
  20216. Ecaron: 0x011A,
  20217. Ecedillabreve: 0x1E1C,
  20218. Echarmenian: 0x0535,
  20219. Ecircle: 0x24BA,
  20220. Ecircumflex: 0x00CA,
  20221. Ecircumflexacute: 0x1EBE,
  20222. Ecircumflexbelow: 0x1E18,
  20223. Ecircumflexdotbelow: 0x1EC6,
  20224. Ecircumflexgrave: 0x1EC0,
  20225. Ecircumflexhookabove: 0x1EC2,
  20226. Ecircumflexsmall: 0xF7EA,
  20227. Ecircumflextilde: 0x1EC4,
  20228. Ecyrillic: 0x0404,
  20229. Edblgrave: 0x0204,
  20230. Edieresis: 0x00CB,
  20231. Edieresissmall: 0xF7EB,
  20232. Edot: 0x0116,
  20233. Edotaccent: 0x0116,
  20234. Edotbelow: 0x1EB8,
  20235. Efcyrillic: 0x0424,
  20236. Egrave: 0x00C8,
  20237. Egravesmall: 0xF7E8,
  20238. Eharmenian: 0x0537,
  20239. Ehookabove: 0x1EBA,
  20240. Eightroman: 0x2167,
  20241. Einvertedbreve: 0x0206,
  20242. Eiotifiedcyrillic: 0x0464,
  20243. Elcyrillic: 0x041B,
  20244. Elevenroman: 0x216A,
  20245. Emacron: 0x0112,
  20246. Emacronacute: 0x1E16,
  20247. Emacrongrave: 0x1E14,
  20248. Emcyrillic: 0x041C,
  20249. Emonospace: 0xFF25,
  20250. Encyrillic: 0x041D,
  20251. Endescendercyrillic: 0x04A2,
  20252. Eng: 0x014A,
  20253. Enghecyrillic: 0x04A4,
  20254. Enhookcyrillic: 0x04C7,
  20255. Eogonek: 0x0118,
  20256. Eopen: 0x0190,
  20257. Epsilon: 0x0395,
  20258. Epsilontonos: 0x0388,
  20259. Ercyrillic: 0x0420,
  20260. Ereversed: 0x018E,
  20261. Ereversedcyrillic: 0x042D,
  20262. Escyrillic: 0x0421,
  20263. Esdescendercyrillic: 0x04AA,
  20264. Esh: 0x01A9,
  20265. Esmall: 0xF765,
  20266. Eta: 0x0397,
  20267. Etarmenian: 0x0538,
  20268. Etatonos: 0x0389,
  20269. Eth: 0x00D0,
  20270. Ethsmall: 0xF7F0,
  20271. Etilde: 0x1EBC,
  20272. Etildebelow: 0x1E1A,
  20273. Euro: 0x20AC,
  20274. Ezh: 0x01B7,
  20275. Ezhcaron: 0x01EE,
  20276. Ezhreversed: 0x01B8,
  20277. F: 0x0046,
  20278. Fcircle: 0x24BB,
  20279. Fdotaccent: 0x1E1E,
  20280. Feharmenian: 0x0556,
  20281. Feicoptic: 0x03E4,
  20282. Fhook: 0x0191,
  20283. Fitacyrillic: 0x0472,
  20284. Fiveroman: 0x2164,
  20285. Fmonospace: 0xFF26,
  20286. Fourroman: 0x2163,
  20287. Fsmall: 0xF766,
  20288. G: 0x0047,
  20289. GBsquare: 0x3387,
  20290. Gacute: 0x01F4,
  20291. Gamma: 0x0393,
  20292. Gammaafrican: 0x0194,
  20293. Gangiacoptic: 0x03EA,
  20294. Gbreve: 0x011E,
  20295. Gcaron: 0x01E6,
  20296. Gcedilla: 0x0122,
  20297. Gcircle: 0x24BC,
  20298. Gcircumflex: 0x011C,
  20299. Gcommaaccent: 0x0122,
  20300. Gdot: 0x0120,
  20301. Gdotaccent: 0x0120,
  20302. Gecyrillic: 0x0413,
  20303. Ghadarmenian: 0x0542,
  20304. Ghemiddlehookcyrillic: 0x0494,
  20305. Ghestrokecyrillic: 0x0492,
  20306. Gheupturncyrillic: 0x0490,
  20307. Ghook: 0x0193,
  20308. Gimarmenian: 0x0533,
  20309. Gjecyrillic: 0x0403,
  20310. Gmacron: 0x1E20,
  20311. Gmonospace: 0xFF27,
  20312. Grave: 0xF6CE,
  20313. Gravesmall: 0xF760,
  20314. Gsmall: 0xF767,
  20315. Gsmallhook: 0x029B,
  20316. Gstroke: 0x01E4,
  20317. H: 0x0048,
  20318. H18533: 0x25CF,
  20319. H18543: 0x25AA,
  20320. H18551: 0x25AB,
  20321. H22073: 0x25A1,
  20322. HPsquare: 0x33CB,
  20323. Haabkhasiancyrillic: 0x04A8,
  20324. Hadescendercyrillic: 0x04B2,
  20325. Hardsigncyrillic: 0x042A,
  20326. Hbar: 0x0126,
  20327. Hbrevebelow: 0x1E2A,
  20328. Hcedilla: 0x1E28,
  20329. Hcircle: 0x24BD,
  20330. Hcircumflex: 0x0124,
  20331. Hdieresis: 0x1E26,
  20332. Hdotaccent: 0x1E22,
  20333. Hdotbelow: 0x1E24,
  20334. Hmonospace: 0xFF28,
  20335. Hoarmenian: 0x0540,
  20336. Horicoptic: 0x03E8,
  20337. Hsmall: 0xF768,
  20338. Hungarumlaut: 0xF6CF,
  20339. Hungarumlautsmall: 0xF6F8,
  20340. Hzsquare: 0x3390,
  20341. I: 0x0049,
  20342. IAcyrillic: 0x042F,
  20343. IJ: 0x0132,
  20344. IUcyrillic: 0x042E,
  20345. Iacute: 0x00CD,
  20346. Iacutesmall: 0xF7ED,
  20347. Ibreve: 0x012C,
  20348. Icaron: 0x01CF,
  20349. Icircle: 0x24BE,
  20350. Icircumflex: 0x00CE,
  20351. Icircumflexsmall: 0xF7EE,
  20352. Icyrillic: 0x0406,
  20353. Idblgrave: 0x0208,
  20354. Idieresis: 0x00CF,
  20355. Idieresisacute: 0x1E2E,
  20356. Idieresiscyrillic: 0x04E4,
  20357. Idieresissmall: 0xF7EF,
  20358. Idot: 0x0130,
  20359. Idotaccent: 0x0130,
  20360. Idotbelow: 0x1ECA,
  20361. Iebrevecyrillic: 0x04D6,
  20362. Iecyrillic: 0x0415,
  20363. Ifraktur: 0x2111,
  20364. Igrave: 0x00CC,
  20365. Igravesmall: 0xF7EC,
  20366. Ihookabove: 0x1EC8,
  20367. Iicyrillic: 0x0418,
  20368. Iinvertedbreve: 0x020A,
  20369. Iishortcyrillic: 0x0419,
  20370. Imacron: 0x012A,
  20371. Imacroncyrillic: 0x04E2,
  20372. Imonospace: 0xFF29,
  20373. Iniarmenian: 0x053B,
  20374. Iocyrillic: 0x0401,
  20375. Iogonek: 0x012E,
  20376. Iota: 0x0399,
  20377. Iotaafrican: 0x0196,
  20378. Iotadieresis: 0x03AA,
  20379. Iotatonos: 0x038A,
  20380. Ismall: 0xF769,
  20381. Istroke: 0x0197,
  20382. Itilde: 0x0128,
  20383. Itildebelow: 0x1E2C,
  20384. Izhitsacyrillic: 0x0474,
  20385. Izhitsadblgravecyrillic: 0x0476,
  20386. J: 0x004A,
  20387. Jaarmenian: 0x0541,
  20388. Jcircle: 0x24BF,
  20389. Jcircumflex: 0x0134,
  20390. Jecyrillic: 0x0408,
  20391. Jheharmenian: 0x054B,
  20392. Jmonospace: 0xFF2A,
  20393. Jsmall: 0xF76A,
  20394. K: 0x004B,
  20395. KBsquare: 0x3385,
  20396. KKsquare: 0x33CD,
  20397. Kabashkircyrillic: 0x04A0,
  20398. Kacute: 0x1E30,
  20399. Kacyrillic: 0x041A,
  20400. Kadescendercyrillic: 0x049A,
  20401. Kahookcyrillic: 0x04C3,
  20402. Kappa: 0x039A,
  20403. Kastrokecyrillic: 0x049E,
  20404. Kaverticalstrokecyrillic: 0x049C,
  20405. Kcaron: 0x01E8,
  20406. Kcedilla: 0x0136,
  20407. Kcircle: 0x24C0,
  20408. Kcommaaccent: 0x0136,
  20409. Kdotbelow: 0x1E32,
  20410. Keharmenian: 0x0554,
  20411. Kenarmenian: 0x053F,
  20412. Khacyrillic: 0x0425,
  20413. Kheicoptic: 0x03E6,
  20414. Khook: 0x0198,
  20415. Kjecyrillic: 0x040C,
  20416. Klinebelow: 0x1E34,
  20417. Kmonospace: 0xFF2B,
  20418. Koppacyrillic: 0x0480,
  20419. Koppagreek: 0x03DE,
  20420. Ksicyrillic: 0x046E,
  20421. Ksmall: 0xF76B,
  20422. L: 0x004C,
  20423. LJ: 0x01C7,
  20424. LL: 0xF6BF,
  20425. Lacute: 0x0139,
  20426. Lambda: 0x039B,
  20427. Lcaron: 0x013D,
  20428. Lcedilla: 0x013B,
  20429. Lcircle: 0x24C1,
  20430. Lcircumflexbelow: 0x1E3C,
  20431. Lcommaaccent: 0x013B,
  20432. Ldot: 0x013F,
  20433. Ldotaccent: 0x013F,
  20434. Ldotbelow: 0x1E36,
  20435. Ldotbelowmacron: 0x1E38,
  20436. Liwnarmenian: 0x053C,
  20437. Lj: 0x01C8,
  20438. Ljecyrillic: 0x0409,
  20439. Llinebelow: 0x1E3A,
  20440. Lmonospace: 0xFF2C,
  20441. Lslash: 0x0141,
  20442. Lslashsmall: 0xF6F9,
  20443. Lsmall: 0xF76C,
  20444. M: 0x004D,
  20445. MBsquare: 0x3386,
  20446. Macron: 0xF6D0,
  20447. Macronsmall: 0xF7AF,
  20448. Macute: 0x1E3E,
  20449. Mcircle: 0x24C2,
  20450. Mdotaccent: 0x1E40,
  20451. Mdotbelow: 0x1E42,
  20452. Menarmenian: 0x0544,
  20453. Mmonospace: 0xFF2D,
  20454. Msmall: 0xF76D,
  20455. Mturned: 0x019C,
  20456. Mu: 0x039C,
  20457. N: 0x004E,
  20458. NJ: 0x01CA,
  20459. Nacute: 0x0143,
  20460. Ncaron: 0x0147,
  20461. Ncedilla: 0x0145,
  20462. Ncircle: 0x24C3,
  20463. Ncircumflexbelow: 0x1E4A,
  20464. Ncommaaccent: 0x0145,
  20465. Ndotaccent: 0x1E44,
  20466. Ndotbelow: 0x1E46,
  20467. Nhookleft: 0x019D,
  20468. Nineroman: 0x2168,
  20469. Nj: 0x01CB,
  20470. Njecyrillic: 0x040A,
  20471. Nlinebelow: 0x1E48,
  20472. Nmonospace: 0xFF2E,
  20473. Nowarmenian: 0x0546,
  20474. Nsmall: 0xF76E,
  20475. Ntilde: 0x00D1,
  20476. Ntildesmall: 0xF7F1,
  20477. Nu: 0x039D,
  20478. O: 0x004F,
  20479. OE: 0x0152,
  20480. OEsmall: 0xF6FA,
  20481. Oacute: 0x00D3,
  20482. Oacutesmall: 0xF7F3,
  20483. Obarredcyrillic: 0x04E8,
  20484. Obarreddieresiscyrillic: 0x04EA,
  20485. Obreve: 0x014E,
  20486. Ocaron: 0x01D1,
  20487. Ocenteredtilde: 0x019F,
  20488. Ocircle: 0x24C4,
  20489. Ocircumflex: 0x00D4,
  20490. Ocircumflexacute: 0x1ED0,
  20491. Ocircumflexdotbelow: 0x1ED8,
  20492. Ocircumflexgrave: 0x1ED2,
  20493. Ocircumflexhookabove: 0x1ED4,
  20494. Ocircumflexsmall: 0xF7F4,
  20495. Ocircumflextilde: 0x1ED6,
  20496. Ocyrillic: 0x041E,
  20497. Odblacute: 0x0150,
  20498. Odblgrave: 0x020C,
  20499. Odieresis: 0x00D6,
  20500. Odieresiscyrillic: 0x04E6,
  20501. Odieresissmall: 0xF7F6,
  20502. Odotbelow: 0x1ECC,
  20503. Ogoneksmall: 0xF6FB,
  20504. Ograve: 0x00D2,
  20505. Ogravesmall: 0xF7F2,
  20506. Oharmenian: 0x0555,
  20507. Ohm: 0x2126,
  20508. Ohookabove: 0x1ECE,
  20509. Ohorn: 0x01A0,
  20510. Ohornacute: 0x1EDA,
  20511. Ohorndotbelow: 0x1EE2,
  20512. Ohorngrave: 0x1EDC,
  20513. Ohornhookabove: 0x1EDE,
  20514. Ohorntilde: 0x1EE0,
  20515. Ohungarumlaut: 0x0150,
  20516. Oi: 0x01A2,
  20517. Oinvertedbreve: 0x020E,
  20518. Omacron: 0x014C,
  20519. Omacronacute: 0x1E52,
  20520. Omacrongrave: 0x1E50,
  20521. Omega: 0x2126,
  20522. Omegacyrillic: 0x0460,
  20523. Omegagreek: 0x03A9,
  20524. Omegaroundcyrillic: 0x047A,
  20525. Omegatitlocyrillic: 0x047C,
  20526. Omegatonos: 0x038F,
  20527. Omicron: 0x039F,
  20528. Omicrontonos: 0x038C,
  20529. Omonospace: 0xFF2F,
  20530. Oneroman: 0x2160,
  20531. Oogonek: 0x01EA,
  20532. Oogonekmacron: 0x01EC,
  20533. Oopen: 0x0186,
  20534. Oslash: 0x00D8,
  20535. Oslashacute: 0x01FE,
  20536. Oslashsmall: 0xF7F8,
  20537. Osmall: 0xF76F,
  20538. Ostrokeacute: 0x01FE,
  20539. Otcyrillic: 0x047E,
  20540. Otilde: 0x00D5,
  20541. Otildeacute: 0x1E4C,
  20542. Otildedieresis: 0x1E4E,
  20543. Otildesmall: 0xF7F5,
  20544. P: 0x0050,
  20545. Pacute: 0x1E54,
  20546. Pcircle: 0x24C5,
  20547. Pdotaccent: 0x1E56,
  20548. Pecyrillic: 0x041F,
  20549. Peharmenian: 0x054A,
  20550. Pemiddlehookcyrillic: 0x04A6,
  20551. Phi: 0x03A6,
  20552. Phook: 0x01A4,
  20553. Pi: 0x03A0,
  20554. Piwrarmenian: 0x0553,
  20555. Pmonospace: 0xFF30,
  20556. Psi: 0x03A8,
  20557. Psicyrillic: 0x0470,
  20558. Psmall: 0xF770,
  20559. Q: 0x0051,
  20560. Qcircle: 0x24C6,
  20561. Qmonospace: 0xFF31,
  20562. Qsmall: 0xF771,
  20563. R: 0x0052,
  20564. Raarmenian: 0x054C,
  20565. Racute: 0x0154,
  20566. Rcaron: 0x0158,
  20567. Rcedilla: 0x0156,
  20568. Rcircle: 0x24C7,
  20569. Rcommaaccent: 0x0156,
  20570. Rdblgrave: 0x0210,
  20571. Rdotaccent: 0x1E58,
  20572. Rdotbelow: 0x1E5A,
  20573. Rdotbelowmacron: 0x1E5C,
  20574. Reharmenian: 0x0550,
  20575. Rfraktur: 0x211C,
  20576. Rho: 0x03A1,
  20577. Ringsmall: 0xF6FC,
  20578. Rinvertedbreve: 0x0212,
  20579. Rlinebelow: 0x1E5E,
  20580. Rmonospace: 0xFF32,
  20581. Rsmall: 0xF772,
  20582. Rsmallinverted: 0x0281,
  20583. Rsmallinvertedsuperior: 0x02B6,
  20584. S: 0x0053,
  20585. SF010000: 0x250C,
  20586. SF020000: 0x2514,
  20587. SF030000: 0x2510,
  20588. SF040000: 0x2518,
  20589. SF050000: 0x253C,
  20590. SF060000: 0x252C,
  20591. SF070000: 0x2534,
  20592. SF080000: 0x251C,
  20593. SF090000: 0x2524,
  20594. SF100000: 0x2500,
  20595. SF110000: 0x2502,
  20596. SF190000: 0x2561,
  20597. SF200000: 0x2562,
  20598. SF210000: 0x2556,
  20599. SF220000: 0x2555,
  20600. SF230000: 0x2563,
  20601. SF240000: 0x2551,
  20602. SF250000: 0x2557,
  20603. SF260000: 0x255D,
  20604. SF270000: 0x255C,
  20605. SF280000: 0x255B,
  20606. SF360000: 0x255E,
  20607. SF370000: 0x255F,
  20608. SF380000: 0x255A,
  20609. SF390000: 0x2554,
  20610. SF400000: 0x2569,
  20611. SF410000: 0x2566,
  20612. SF420000: 0x2560,
  20613. SF430000: 0x2550,
  20614. SF440000: 0x256C,
  20615. SF450000: 0x2567,
  20616. SF460000: 0x2568,
  20617. SF470000: 0x2564,
  20618. SF480000: 0x2565,
  20619. SF490000: 0x2559,
  20620. SF500000: 0x2558,
  20621. SF510000: 0x2552,
  20622. SF520000: 0x2553,
  20623. SF530000: 0x256B,
  20624. SF540000: 0x256A,
  20625. Sacute: 0x015A,
  20626. Sacutedotaccent: 0x1E64,
  20627. Sampigreek: 0x03E0,
  20628. Scaron: 0x0160,
  20629. Scarondotaccent: 0x1E66,
  20630. Scaronsmall: 0xF6FD,
  20631. Scedilla: 0x015E,
  20632. Schwa: 0x018F,
  20633. Schwacyrillic: 0x04D8,
  20634. Schwadieresiscyrillic: 0x04DA,
  20635. Scircle: 0x24C8,
  20636. Scircumflex: 0x015C,
  20637. Scommaaccent: 0x0218,
  20638. Sdotaccent: 0x1E60,
  20639. Sdotbelow: 0x1E62,
  20640. Sdotbelowdotaccent: 0x1E68,
  20641. Seharmenian: 0x054D,
  20642. Sevenroman: 0x2166,
  20643. Shaarmenian: 0x0547,
  20644. Shacyrillic: 0x0428,
  20645. Shchacyrillic: 0x0429,
  20646. Sheicoptic: 0x03E2,
  20647. Shhacyrillic: 0x04BA,
  20648. Shimacoptic: 0x03EC,
  20649. Sigma: 0x03A3,
  20650. Sixroman: 0x2165,
  20651. Smonospace: 0xFF33,
  20652. Softsigncyrillic: 0x042C,
  20653. Ssmall: 0xF773,
  20654. Stigmagreek: 0x03DA,
  20655. T: 0x0054,
  20656. Tau: 0x03A4,
  20657. Tbar: 0x0166,
  20658. Tcaron: 0x0164,
  20659. Tcedilla: 0x0162,
  20660. Tcircle: 0x24C9,
  20661. Tcircumflexbelow: 0x1E70,
  20662. Tcommaaccent: 0x0162,
  20663. Tdotaccent: 0x1E6A,
  20664. Tdotbelow: 0x1E6C,
  20665. Tecyrillic: 0x0422,
  20666. Tedescendercyrillic: 0x04AC,
  20667. Tenroman: 0x2169,
  20668. Tetsecyrillic: 0x04B4,
  20669. Theta: 0x0398,
  20670. Thook: 0x01AC,
  20671. Thorn: 0x00DE,
  20672. Thornsmall: 0xF7FE,
  20673. Threeroman: 0x2162,
  20674. Tildesmall: 0xF6FE,
  20675. Tiwnarmenian: 0x054F,
  20676. Tlinebelow: 0x1E6E,
  20677. Tmonospace: 0xFF34,
  20678. Toarmenian: 0x0539,
  20679. Tonefive: 0x01BC,
  20680. Tonesix: 0x0184,
  20681. Tonetwo: 0x01A7,
  20682. Tretroflexhook: 0x01AE,
  20683. Tsecyrillic: 0x0426,
  20684. Tshecyrillic: 0x040B,
  20685. Tsmall: 0xF774,
  20686. Twelveroman: 0x216B,
  20687. Tworoman: 0x2161,
  20688. U: 0x0055,
  20689. Uacute: 0x00DA,
  20690. Uacutesmall: 0xF7FA,
  20691. Ubreve: 0x016C,
  20692. Ucaron: 0x01D3,
  20693. Ucircle: 0x24CA,
  20694. Ucircumflex: 0x00DB,
  20695. Ucircumflexbelow: 0x1E76,
  20696. Ucircumflexsmall: 0xF7FB,
  20697. Ucyrillic: 0x0423,
  20698. Udblacute: 0x0170,
  20699. Udblgrave: 0x0214,
  20700. Udieresis: 0x00DC,
  20701. Udieresisacute: 0x01D7,
  20702. Udieresisbelow: 0x1E72,
  20703. Udieresiscaron: 0x01D9,
  20704. Udieresiscyrillic: 0x04F0,
  20705. Udieresisgrave: 0x01DB,
  20706. Udieresismacron: 0x01D5,
  20707. Udieresissmall: 0xF7FC,
  20708. Udotbelow: 0x1EE4,
  20709. Ugrave: 0x00D9,
  20710. Ugravesmall: 0xF7F9,
  20711. Uhookabove: 0x1EE6,
  20712. Uhorn: 0x01AF,
  20713. Uhornacute: 0x1EE8,
  20714. Uhorndotbelow: 0x1EF0,
  20715. Uhorngrave: 0x1EEA,
  20716. Uhornhookabove: 0x1EEC,
  20717. Uhorntilde: 0x1EEE,
  20718. Uhungarumlaut: 0x0170,
  20719. Uhungarumlautcyrillic: 0x04F2,
  20720. Uinvertedbreve: 0x0216,
  20721. Ukcyrillic: 0x0478,
  20722. Umacron: 0x016A,
  20723. Umacroncyrillic: 0x04EE,
  20724. Umacrondieresis: 0x1E7A,
  20725. Umonospace: 0xFF35,
  20726. Uogonek: 0x0172,
  20727. Upsilon: 0x03A5,
  20728. Upsilon1: 0x03D2,
  20729. Upsilonacutehooksymbolgreek: 0x03D3,
  20730. Upsilonafrican: 0x01B1,
  20731. Upsilondieresis: 0x03AB,
  20732. Upsilondieresishooksymbolgreek: 0x03D4,
  20733. Upsilonhooksymbol: 0x03D2,
  20734. Upsilontonos: 0x038E,
  20735. Uring: 0x016E,
  20736. Ushortcyrillic: 0x040E,
  20737. Usmall: 0xF775,
  20738. Ustraightcyrillic: 0x04AE,
  20739. Ustraightstrokecyrillic: 0x04B0,
  20740. Utilde: 0x0168,
  20741. Utildeacute: 0x1E78,
  20742. Utildebelow: 0x1E74,
  20743. V: 0x0056,
  20744. Vcircle: 0x24CB,
  20745. Vdotbelow: 0x1E7E,
  20746. Vecyrillic: 0x0412,
  20747. Vewarmenian: 0x054E,
  20748. Vhook: 0x01B2,
  20749. Vmonospace: 0xFF36,
  20750. Voarmenian: 0x0548,
  20751. Vsmall: 0xF776,
  20752. Vtilde: 0x1E7C,
  20753. W: 0x0057,
  20754. Wacute: 0x1E82,
  20755. Wcircle: 0x24CC,
  20756. Wcircumflex: 0x0174,
  20757. Wdieresis: 0x1E84,
  20758. Wdotaccent: 0x1E86,
  20759. Wdotbelow: 0x1E88,
  20760. Wgrave: 0x1E80,
  20761. Wmonospace: 0xFF37,
  20762. Wsmall: 0xF777,
  20763. X: 0x0058,
  20764. Xcircle: 0x24CD,
  20765. Xdieresis: 0x1E8C,
  20766. Xdotaccent: 0x1E8A,
  20767. Xeharmenian: 0x053D,
  20768. Xi: 0x039E,
  20769. Xmonospace: 0xFF38,
  20770. Xsmall: 0xF778,
  20771. Y: 0x0059,
  20772. Yacute: 0x00DD,
  20773. Yacutesmall: 0xF7FD,
  20774. Yatcyrillic: 0x0462,
  20775. Ycircle: 0x24CE,
  20776. Ycircumflex: 0x0176,
  20777. Ydieresis: 0x0178,
  20778. Ydieresissmall: 0xF7FF,
  20779. Ydotaccent: 0x1E8E,
  20780. Ydotbelow: 0x1EF4,
  20781. Yericyrillic: 0x042B,
  20782. Yerudieresiscyrillic: 0x04F8,
  20783. Ygrave: 0x1EF2,
  20784. Yhook: 0x01B3,
  20785. Yhookabove: 0x1EF6,
  20786. Yiarmenian: 0x0545,
  20787. Yicyrillic: 0x0407,
  20788. Yiwnarmenian: 0x0552,
  20789. Ymonospace: 0xFF39,
  20790. Ysmall: 0xF779,
  20791. Ytilde: 0x1EF8,
  20792. Yusbigcyrillic: 0x046A,
  20793. Yusbigiotifiedcyrillic: 0x046C,
  20794. Yuslittlecyrillic: 0x0466,
  20795. Yuslittleiotifiedcyrillic: 0x0468,
  20796. Z: 0x005A,
  20797. Zaarmenian: 0x0536,
  20798. Zacute: 0x0179,
  20799. Zcaron: 0x017D,
  20800. Zcaronsmall: 0xF6FF,
  20801. Zcircle: 0x24CF,
  20802. Zcircumflex: 0x1E90,
  20803. Zdot: 0x017B,
  20804. Zdotaccent: 0x017B,
  20805. Zdotbelow: 0x1E92,
  20806. Zecyrillic: 0x0417,
  20807. Zedescendercyrillic: 0x0498,
  20808. Zedieresiscyrillic: 0x04DE,
  20809. Zeta: 0x0396,
  20810. Zhearmenian: 0x053A,
  20811. Zhebrevecyrillic: 0x04C1,
  20812. Zhecyrillic: 0x0416,
  20813. Zhedescendercyrillic: 0x0496,
  20814. Zhedieresiscyrillic: 0x04DC,
  20815. Zlinebelow: 0x1E94,
  20816. Zmonospace: 0xFF3A,
  20817. Zsmall: 0xF77A,
  20818. Zstroke: 0x01B5,
  20819. a: 0x0061,
  20820. aabengali: 0x0986,
  20821. aacute: 0x00E1,
  20822. aadeva: 0x0906,
  20823. aagujarati: 0x0A86,
  20824. aagurmukhi: 0x0A06,
  20825. aamatragurmukhi: 0x0A3E,
  20826. aarusquare: 0x3303,
  20827. aavowelsignbengali: 0x09BE,
  20828. aavowelsigndeva: 0x093E,
  20829. aavowelsigngujarati: 0x0ABE,
  20830. abbreviationmarkarmenian: 0x055F,
  20831. abbreviationsigndeva: 0x0970,
  20832. abengali: 0x0985,
  20833. abopomofo: 0x311A,
  20834. abreve: 0x0103,
  20835. abreveacute: 0x1EAF,
  20836. abrevecyrillic: 0x04D1,
  20837. abrevedotbelow: 0x1EB7,
  20838. abrevegrave: 0x1EB1,
  20839. abrevehookabove: 0x1EB3,
  20840. abrevetilde: 0x1EB5,
  20841. acaron: 0x01CE,
  20842. acircle: 0x24D0,
  20843. acircumflex: 0x00E2,
  20844. acircumflexacute: 0x1EA5,
  20845. acircumflexdotbelow: 0x1EAD,
  20846. acircumflexgrave: 0x1EA7,
  20847. acircumflexhookabove: 0x1EA9,
  20848. acircumflextilde: 0x1EAB,
  20849. acute: 0x00B4,
  20850. acutebelowcmb: 0x0317,
  20851. acutecmb: 0x0301,
  20852. acutecomb: 0x0301,
  20853. acutedeva: 0x0954,
  20854. acutelowmod: 0x02CF,
  20855. acutetonecmb: 0x0341,
  20856. acyrillic: 0x0430,
  20857. adblgrave: 0x0201,
  20858. addakgurmukhi: 0x0A71,
  20859. adeva: 0x0905,
  20860. adieresis: 0x00E4,
  20861. adieresiscyrillic: 0x04D3,
  20862. adieresismacron: 0x01DF,
  20863. adotbelow: 0x1EA1,
  20864. adotmacron: 0x01E1,
  20865. ae: 0x00E6,
  20866. aeacute: 0x01FD,
  20867. aekorean: 0x3150,
  20868. aemacron: 0x01E3,
  20869. afii00208: 0x2015,
  20870. afii08941: 0x20A4,
  20871. afii10017: 0x0410,
  20872. afii10018: 0x0411,
  20873. afii10019: 0x0412,
  20874. afii10020: 0x0413,
  20875. afii10021: 0x0414,
  20876. afii10022: 0x0415,
  20877. afii10023: 0x0401,
  20878. afii10024: 0x0416,
  20879. afii10025: 0x0417,
  20880. afii10026: 0x0418,
  20881. afii10027: 0x0419,
  20882. afii10028: 0x041A,
  20883. afii10029: 0x041B,
  20884. afii10030: 0x041C,
  20885. afii10031: 0x041D,
  20886. afii10032: 0x041E,
  20887. afii10033: 0x041F,
  20888. afii10034: 0x0420,
  20889. afii10035: 0x0421,
  20890. afii10036: 0x0422,
  20891. afii10037: 0x0423,
  20892. afii10038: 0x0424,
  20893. afii10039: 0x0425,
  20894. afii10040: 0x0426,
  20895. afii10041: 0x0427,
  20896. afii10042: 0x0428,
  20897. afii10043: 0x0429,
  20898. afii10044: 0x042A,
  20899. afii10045: 0x042B,
  20900. afii10046: 0x042C,
  20901. afii10047: 0x042D,
  20902. afii10048: 0x042E,
  20903. afii10049: 0x042F,
  20904. afii10050: 0x0490,
  20905. afii10051: 0x0402,
  20906. afii10052: 0x0403,
  20907. afii10053: 0x0404,
  20908. afii10054: 0x0405,
  20909. afii10055: 0x0406,
  20910. afii10056: 0x0407,
  20911. afii10057: 0x0408,
  20912. afii10058: 0x0409,
  20913. afii10059: 0x040A,
  20914. afii10060: 0x040B,
  20915. afii10061: 0x040C,
  20916. afii10062: 0x040E,
  20917. afii10063: 0xF6C4,
  20918. afii10064: 0xF6C5,
  20919. afii10065: 0x0430,
  20920. afii10066: 0x0431,
  20921. afii10067: 0x0432,
  20922. afii10068: 0x0433,
  20923. afii10069: 0x0434,
  20924. afii10070: 0x0435,
  20925. afii10071: 0x0451,
  20926. afii10072: 0x0436,
  20927. afii10073: 0x0437,
  20928. afii10074: 0x0438,
  20929. afii10075: 0x0439,
  20930. afii10076: 0x043A,
  20931. afii10077: 0x043B,
  20932. afii10078: 0x043C,
  20933. afii10079: 0x043D,
  20934. afii10080: 0x043E,
  20935. afii10081: 0x043F,
  20936. afii10082: 0x0440,
  20937. afii10083: 0x0441,
  20938. afii10084: 0x0442,
  20939. afii10085: 0x0443,
  20940. afii10086: 0x0444,
  20941. afii10087: 0x0445,
  20942. afii10088: 0x0446,
  20943. afii10089: 0x0447,
  20944. afii10090: 0x0448,
  20945. afii10091: 0x0449,
  20946. afii10092: 0x044A,
  20947. afii10093: 0x044B,
  20948. afii10094: 0x044C,
  20949. afii10095: 0x044D,
  20950. afii10096: 0x044E,
  20951. afii10097: 0x044F,
  20952. afii10098: 0x0491,
  20953. afii10099: 0x0452,
  20954. afii10100: 0x0453,
  20955. afii10101: 0x0454,
  20956. afii10102: 0x0455,
  20957. afii10103: 0x0456,
  20958. afii10104: 0x0457,
  20959. afii10105: 0x0458,
  20960. afii10106: 0x0459,
  20961. afii10107: 0x045A,
  20962. afii10108: 0x045B,
  20963. afii10109: 0x045C,
  20964. afii10110: 0x045E,
  20965. afii10145: 0x040F,
  20966. afii10146: 0x0462,
  20967. afii10147: 0x0472,
  20968. afii10148: 0x0474,
  20969. afii10192: 0xF6C6,
  20970. afii10193: 0x045F,
  20971. afii10194: 0x0463,
  20972. afii10195: 0x0473,
  20973. afii10196: 0x0475,
  20974. afii10831: 0xF6C7,
  20975. afii10832: 0xF6C8,
  20976. afii10846: 0x04D9,
  20977. afii299: 0x200E,
  20978. afii300: 0x200F,
  20979. afii301: 0x200D,
  20980. afii57381: 0x066A,
  20981. afii57388: 0x060C,
  20982. afii57392: 0x0660,
  20983. afii57393: 0x0661,
  20984. afii57394: 0x0662,
  20985. afii57395: 0x0663,
  20986. afii57396: 0x0664,
  20987. afii57397: 0x0665,
  20988. afii57398: 0x0666,
  20989. afii57399: 0x0667,
  20990. afii57400: 0x0668,
  20991. afii57401: 0x0669,
  20992. afii57403: 0x061B,
  20993. afii57407: 0x061F,
  20994. afii57409: 0x0621,
  20995. afii57410: 0x0622,
  20996. afii57411: 0x0623,
  20997. afii57412: 0x0624,
  20998. afii57413: 0x0625,
  20999. afii57414: 0x0626,
  21000. afii57415: 0x0627,
  21001. afii57416: 0x0628,
  21002. afii57417: 0x0629,
  21003. afii57418: 0x062A,
  21004. afii57419: 0x062B,
  21005. afii57420: 0x062C,
  21006. afii57421: 0x062D,
  21007. afii57422: 0x062E,
  21008. afii57423: 0x062F,
  21009. afii57424: 0x0630,
  21010. afii57425: 0x0631,
  21011. afii57426: 0x0632,
  21012. afii57427: 0x0633,
  21013. afii57428: 0x0634,
  21014. afii57429: 0x0635,
  21015. afii57430: 0x0636,
  21016. afii57431: 0x0637,
  21017. afii57432: 0x0638,
  21018. afii57433: 0x0639,
  21019. afii57434: 0x063A,
  21020. afii57440: 0x0640,
  21021. afii57441: 0x0641,
  21022. afii57442: 0x0642,
  21023. afii57443: 0x0643,
  21024. afii57444: 0x0644,
  21025. afii57445: 0x0645,
  21026. afii57446: 0x0646,
  21027. afii57448: 0x0648,
  21028. afii57449: 0x0649,
  21029. afii57450: 0x064A,
  21030. afii57451: 0x064B,
  21031. afii57452: 0x064C,
  21032. afii57453: 0x064D,
  21033. afii57454: 0x064E,
  21034. afii57455: 0x064F,
  21035. afii57456: 0x0650,
  21036. afii57457: 0x0651,
  21037. afii57458: 0x0652,
  21038. afii57470: 0x0647,
  21039. afii57505: 0x06A4,
  21040. afii57506: 0x067E,
  21041. afii57507: 0x0686,
  21042. afii57508: 0x0698,
  21043. afii57509: 0x06AF,
  21044. afii57511: 0x0679,
  21045. afii57512: 0x0688,
  21046. afii57513: 0x0691,
  21047. afii57514: 0x06BA,
  21048. afii57519: 0x06D2,
  21049. afii57534: 0x06D5,
  21050. afii57636: 0x20AA,
  21051. afii57645: 0x05BE,
  21052. afii57658: 0x05C3,
  21053. afii57664: 0x05D0,
  21054. afii57665: 0x05D1,
  21055. afii57666: 0x05D2,
  21056. afii57667: 0x05D3,
  21057. afii57668: 0x05D4,
  21058. afii57669: 0x05D5,
  21059. afii57670: 0x05D6,
  21060. afii57671: 0x05D7,
  21061. afii57672: 0x05D8,
  21062. afii57673: 0x05D9,
  21063. afii57674: 0x05DA,
  21064. afii57675: 0x05DB,
  21065. afii57676: 0x05DC,
  21066. afii57677: 0x05DD,
  21067. afii57678: 0x05DE,
  21068. afii57679: 0x05DF,
  21069. afii57680: 0x05E0,
  21070. afii57681: 0x05E1,
  21071. afii57682: 0x05E2,
  21072. afii57683: 0x05E3,
  21073. afii57684: 0x05E4,
  21074. afii57685: 0x05E5,
  21075. afii57686: 0x05E6,
  21076. afii57687: 0x05E7,
  21077. afii57688: 0x05E8,
  21078. afii57689: 0x05E9,
  21079. afii57690: 0x05EA,
  21080. afii57694: 0xFB2A,
  21081. afii57695: 0xFB2B,
  21082. afii57700: 0xFB4B,
  21083. afii57705: 0xFB1F,
  21084. afii57716: 0x05F0,
  21085. afii57717: 0x05F1,
  21086. afii57718: 0x05F2,
  21087. afii57723: 0xFB35,
  21088. afii57793: 0x05B4,
  21089. afii57794: 0x05B5,
  21090. afii57795: 0x05B6,
  21091. afii57796: 0x05BB,
  21092. afii57797: 0x05B8,
  21093. afii57798: 0x05B7,
  21094. afii57799: 0x05B0,
  21095. afii57800: 0x05B2,
  21096. afii57801: 0x05B1,
  21097. afii57802: 0x05B3,
  21098. afii57803: 0x05C2,
  21099. afii57804: 0x05C1,
  21100. afii57806: 0x05B9,
  21101. afii57807: 0x05BC,
  21102. afii57839: 0x05BD,
  21103. afii57841: 0x05BF,
  21104. afii57842: 0x05C0,
  21105. afii57929: 0x02BC,
  21106. afii61248: 0x2105,
  21107. afii61289: 0x2113,
  21108. afii61352: 0x2116,
  21109. afii61573: 0x202C,
  21110. afii61574: 0x202D,
  21111. afii61575: 0x202E,
  21112. afii61664: 0x200C,
  21113. afii63167: 0x066D,
  21114. afii64937: 0x02BD,
  21115. agrave: 0x00E0,
  21116. agujarati: 0x0A85,
  21117. agurmukhi: 0x0A05,
  21118. ahiragana: 0x3042,
  21119. ahookabove: 0x1EA3,
  21120. aibengali: 0x0990,
  21121. aibopomofo: 0x311E,
  21122. aideva: 0x0910,
  21123. aiecyrillic: 0x04D5,
  21124. aigujarati: 0x0A90,
  21125. aigurmukhi: 0x0A10,
  21126. aimatragurmukhi: 0x0A48,
  21127. ainarabic: 0x0639,
  21128. ainfinalarabic: 0xFECA,
  21129. aininitialarabic: 0xFECB,
  21130. ainmedialarabic: 0xFECC,
  21131. ainvertedbreve: 0x0203,
  21132. aivowelsignbengali: 0x09C8,
  21133. aivowelsigndeva: 0x0948,
  21134. aivowelsigngujarati: 0x0AC8,
  21135. akatakana: 0x30A2,
  21136. akatakanahalfwidth: 0xFF71,
  21137. akorean: 0x314F,
  21138. alef: 0x05D0,
  21139. alefarabic: 0x0627,
  21140. alefdageshhebrew: 0xFB30,
  21141. aleffinalarabic: 0xFE8E,
  21142. alefhamzaabovearabic: 0x0623,
  21143. alefhamzaabovefinalarabic: 0xFE84,
  21144. alefhamzabelowarabic: 0x0625,
  21145. alefhamzabelowfinalarabic: 0xFE88,
  21146. alefhebrew: 0x05D0,
  21147. aleflamedhebrew: 0xFB4F,
  21148. alefmaddaabovearabic: 0x0622,
  21149. alefmaddaabovefinalarabic: 0xFE82,
  21150. alefmaksuraarabic: 0x0649,
  21151. alefmaksurafinalarabic: 0xFEF0,
  21152. alefmaksurainitialarabic: 0xFEF3,
  21153. alefmaksuramedialarabic: 0xFEF4,
  21154. alefpatahhebrew: 0xFB2E,
  21155. alefqamatshebrew: 0xFB2F,
  21156. aleph: 0x2135,
  21157. allequal: 0x224C,
  21158. alpha: 0x03B1,
  21159. alphatonos: 0x03AC,
  21160. amacron: 0x0101,
  21161. amonospace: 0xFF41,
  21162. ampersand: 0x0026,
  21163. ampersandmonospace: 0xFF06,
  21164. ampersandsmall: 0xF726,
  21165. amsquare: 0x33C2,
  21166. anbopomofo: 0x3122,
  21167. angbopomofo: 0x3124,
  21168. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21169. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21170. angkhankhuthai: 0x0E5A,
  21171. angle: 0x2220,
  21172. anglebracketleft: 0x3008,
  21173. anglebracketleftvertical: 0xFE3F,
  21174. anglebracketright: 0x3009,
  21175. anglebracketrightvertical: 0xFE40,
  21176. angleleft: 0x2329,
  21177. angleright: 0x232A,
  21178. angstrom: 0x212B,
  21179. anoteleia: 0x0387,
  21180. anudattadeva: 0x0952,
  21181. anusvarabengali: 0x0982,
  21182. anusvaradeva: 0x0902,
  21183. anusvaragujarati: 0x0A82,
  21184. aogonek: 0x0105,
  21185. apaatosquare: 0x3300,
  21186. aparen: 0x249C,
  21187. apostrophearmenian: 0x055A,
  21188. apostrophemod: 0x02BC,
  21189. apple: 0xF8FF,
  21190. approaches: 0x2250,
  21191. approxequal: 0x2248,
  21192. approxequalorimage: 0x2252,
  21193. approximatelyequal: 0x2245,
  21194. araeaekorean: 0x318E,
  21195. araeakorean: 0x318D,
  21196. arc: 0x2312,
  21197. arighthalfring: 0x1E9A,
  21198. aring: 0x00E5,
  21199. aringacute: 0x01FB,
  21200. aringbelow: 0x1E01,
  21201. arrowboth: 0x2194,
  21202. arrowdashdown: 0x21E3,
  21203. arrowdashleft: 0x21E0,
  21204. arrowdashright: 0x21E2,
  21205. arrowdashup: 0x21E1,
  21206. arrowdblboth: 0x21D4,
  21207. arrowdbldown: 0x21D3,
  21208. arrowdblleft: 0x21D0,
  21209. arrowdblright: 0x21D2,
  21210. arrowdblup: 0x21D1,
  21211. arrowdown: 0x2193,
  21212. arrowdownleft: 0x2199,
  21213. arrowdownright: 0x2198,
  21214. arrowdownwhite: 0x21E9,
  21215. arrowheaddownmod: 0x02C5,
  21216. arrowheadleftmod: 0x02C2,
  21217. arrowheadrightmod: 0x02C3,
  21218. arrowheadupmod: 0x02C4,
  21219. arrowhorizex: 0xF8E7,
  21220. arrowleft: 0x2190,
  21221. arrowleftdbl: 0x21D0,
  21222. arrowleftdblstroke: 0x21CD,
  21223. arrowleftoverright: 0x21C6,
  21224. arrowleftwhite: 0x21E6,
  21225. arrowright: 0x2192,
  21226. arrowrightdblstroke: 0x21CF,
  21227. arrowrightheavy: 0x279E,
  21228. arrowrightoverleft: 0x21C4,
  21229. arrowrightwhite: 0x21E8,
  21230. arrowtableft: 0x21E4,
  21231. arrowtabright: 0x21E5,
  21232. arrowup: 0x2191,
  21233. arrowupdn: 0x2195,
  21234. arrowupdnbse: 0x21A8,
  21235. arrowupdownbase: 0x21A8,
  21236. arrowupleft: 0x2196,
  21237. arrowupleftofdown: 0x21C5,
  21238. arrowupright: 0x2197,
  21239. arrowupwhite: 0x21E7,
  21240. arrowvertex: 0xF8E6,
  21241. asciicircum: 0x005E,
  21242. asciicircummonospace: 0xFF3E,
  21243. asciitilde: 0x007E,
  21244. asciitildemonospace: 0xFF5E,
  21245. ascript: 0x0251,
  21246. ascriptturned: 0x0252,
  21247. asmallhiragana: 0x3041,
  21248. asmallkatakana: 0x30A1,
  21249. asmallkatakanahalfwidth: 0xFF67,
  21250. asterisk: 0x002A,
  21251. asteriskaltonearabic: 0x066D,
  21252. asteriskarabic: 0x066D,
  21253. asteriskmath: 0x2217,
  21254. asteriskmonospace: 0xFF0A,
  21255. asterisksmall: 0xFE61,
  21256. asterism: 0x2042,
  21257. asuperior: 0xF6E9,
  21258. asymptoticallyequal: 0x2243,
  21259. at: 0x0040,
  21260. atilde: 0x00E3,
  21261. atmonospace: 0xFF20,
  21262. atsmall: 0xFE6B,
  21263. aturned: 0x0250,
  21264. aubengali: 0x0994,
  21265. aubopomofo: 0x3120,
  21266. audeva: 0x0914,
  21267. augujarati: 0x0A94,
  21268. augurmukhi: 0x0A14,
  21269. aulengthmarkbengali: 0x09D7,
  21270. aumatragurmukhi: 0x0A4C,
  21271. auvowelsignbengali: 0x09CC,
  21272. auvowelsigndeva: 0x094C,
  21273. auvowelsigngujarati: 0x0ACC,
  21274. avagrahadeva: 0x093D,
  21275. aybarmenian: 0x0561,
  21276. ayin: 0x05E2,
  21277. ayinaltonehebrew: 0xFB20,
  21278. ayinhebrew: 0x05E2,
  21279. b: 0x0062,
  21280. babengali: 0x09AC,
  21281. backslash: 0x005C,
  21282. backslashmonospace: 0xFF3C,
  21283. badeva: 0x092C,
  21284. bagujarati: 0x0AAC,
  21285. bagurmukhi: 0x0A2C,
  21286. bahiragana: 0x3070,
  21287. bahtthai: 0x0E3F,
  21288. bakatakana: 0x30D0,
  21289. bar: 0x007C,
  21290. barmonospace: 0xFF5C,
  21291. bbopomofo: 0x3105,
  21292. bcircle: 0x24D1,
  21293. bdotaccent: 0x1E03,
  21294. bdotbelow: 0x1E05,
  21295. beamedsixteenthnotes: 0x266C,
  21296. because: 0x2235,
  21297. becyrillic: 0x0431,
  21298. beharabic: 0x0628,
  21299. behfinalarabic: 0xFE90,
  21300. behinitialarabic: 0xFE91,
  21301. behiragana: 0x3079,
  21302. behmedialarabic: 0xFE92,
  21303. behmeeminitialarabic: 0xFC9F,
  21304. behmeemisolatedarabic: 0xFC08,
  21305. behnoonfinalarabic: 0xFC6D,
  21306. bekatakana: 0x30D9,
  21307. benarmenian: 0x0562,
  21308. bet: 0x05D1,
  21309. beta: 0x03B2,
  21310. betasymbolgreek: 0x03D0,
  21311. betdagesh: 0xFB31,
  21312. betdageshhebrew: 0xFB31,
  21313. bethebrew: 0x05D1,
  21314. betrafehebrew: 0xFB4C,
  21315. bhabengali: 0x09AD,
  21316. bhadeva: 0x092D,
  21317. bhagujarati: 0x0AAD,
  21318. bhagurmukhi: 0x0A2D,
  21319. bhook: 0x0253,
  21320. bihiragana: 0x3073,
  21321. bikatakana: 0x30D3,
  21322. bilabialclick: 0x0298,
  21323. bindigurmukhi: 0x0A02,
  21324. birusquare: 0x3331,
  21325. blackcircle: 0x25CF,
  21326. blackdiamond: 0x25C6,
  21327. blackdownpointingtriangle: 0x25BC,
  21328. blackleftpointingpointer: 0x25C4,
  21329. blackleftpointingtriangle: 0x25C0,
  21330. blacklenticularbracketleft: 0x3010,
  21331. blacklenticularbracketleftvertical: 0xFE3B,
  21332. blacklenticularbracketright: 0x3011,
  21333. blacklenticularbracketrightvertical: 0xFE3C,
  21334. blacklowerlefttriangle: 0x25E3,
  21335. blacklowerrighttriangle: 0x25E2,
  21336. blackrectangle: 0x25AC,
  21337. blackrightpointingpointer: 0x25BA,
  21338. blackrightpointingtriangle: 0x25B6,
  21339. blacksmallsquare: 0x25AA,
  21340. blacksmilingface: 0x263B,
  21341. blacksquare: 0x25A0,
  21342. blackstar: 0x2605,
  21343. blackupperlefttriangle: 0x25E4,
  21344. blackupperrighttriangle: 0x25E5,
  21345. blackuppointingsmalltriangle: 0x25B4,
  21346. blackuppointingtriangle: 0x25B2,
  21347. blank: 0x2423,
  21348. blinebelow: 0x1E07,
  21349. block: 0x2588,
  21350. bmonospace: 0xFF42,
  21351. bobaimaithai: 0x0E1A,
  21352. bohiragana: 0x307C,
  21353. bokatakana: 0x30DC,
  21354. bparen: 0x249D,
  21355. bqsquare: 0x33C3,
  21356. braceex: 0xF8F4,
  21357. braceleft: 0x007B,
  21358. braceleftbt: 0xF8F3,
  21359. braceleftmid: 0xF8F2,
  21360. braceleftmonospace: 0xFF5B,
  21361. braceleftsmall: 0xFE5B,
  21362. bracelefttp: 0xF8F1,
  21363. braceleftvertical: 0xFE37,
  21364. braceright: 0x007D,
  21365. bracerightbt: 0xF8FE,
  21366. bracerightmid: 0xF8FD,
  21367. bracerightmonospace: 0xFF5D,
  21368. bracerightsmall: 0xFE5C,
  21369. bracerighttp: 0xF8FC,
  21370. bracerightvertical: 0xFE38,
  21371. bracketleft: 0x005B,
  21372. bracketleftbt: 0xF8F0,
  21373. bracketleftex: 0xF8EF,
  21374. bracketleftmonospace: 0xFF3B,
  21375. bracketlefttp: 0xF8EE,
  21376. bracketright: 0x005D,
  21377. bracketrightbt: 0xF8FB,
  21378. bracketrightex: 0xF8FA,
  21379. bracketrightmonospace: 0xFF3D,
  21380. bracketrighttp: 0xF8F9,
  21381. breve: 0x02D8,
  21382. brevebelowcmb: 0x032E,
  21383. brevecmb: 0x0306,
  21384. breveinvertedbelowcmb: 0x032F,
  21385. breveinvertedcmb: 0x0311,
  21386. breveinverteddoublecmb: 0x0361,
  21387. bridgebelowcmb: 0x032A,
  21388. bridgeinvertedbelowcmb: 0x033A,
  21389. brokenbar: 0x00A6,
  21390. bstroke: 0x0180,
  21391. bsuperior: 0xF6EA,
  21392. btopbar: 0x0183,
  21393. buhiragana: 0x3076,
  21394. bukatakana: 0x30D6,
  21395. bullet: 0x2022,
  21396. bulletinverse: 0x25D8,
  21397. bulletoperator: 0x2219,
  21398. bullseye: 0x25CE,
  21399. c: 0x0063,
  21400. caarmenian: 0x056E,
  21401. cabengali: 0x099A,
  21402. cacute: 0x0107,
  21403. cadeva: 0x091A,
  21404. cagujarati: 0x0A9A,
  21405. cagurmukhi: 0x0A1A,
  21406. calsquare: 0x3388,
  21407. candrabindubengali: 0x0981,
  21408. candrabinducmb: 0x0310,
  21409. candrabindudeva: 0x0901,
  21410. candrabindugujarati: 0x0A81,
  21411. capslock: 0x21EA,
  21412. careof: 0x2105,
  21413. caron: 0x02C7,
  21414. caronbelowcmb: 0x032C,
  21415. caroncmb: 0x030C,
  21416. carriagereturn: 0x21B5,
  21417. cbopomofo: 0x3118,
  21418. ccaron: 0x010D,
  21419. ccedilla: 0x00E7,
  21420. ccedillaacute: 0x1E09,
  21421. ccircle: 0x24D2,
  21422. ccircumflex: 0x0109,
  21423. ccurl: 0x0255,
  21424. cdot: 0x010B,
  21425. cdotaccent: 0x010B,
  21426. cdsquare: 0x33C5,
  21427. cedilla: 0x00B8,
  21428. cedillacmb: 0x0327,
  21429. cent: 0x00A2,
  21430. centigrade: 0x2103,
  21431. centinferior: 0xF6DF,
  21432. centmonospace: 0xFFE0,
  21433. centoldstyle: 0xF7A2,
  21434. centsuperior: 0xF6E0,
  21435. chaarmenian: 0x0579,
  21436. chabengali: 0x099B,
  21437. chadeva: 0x091B,
  21438. chagujarati: 0x0A9B,
  21439. chagurmukhi: 0x0A1B,
  21440. chbopomofo: 0x3114,
  21441. cheabkhasiancyrillic: 0x04BD,
  21442. checkmark: 0x2713,
  21443. checyrillic: 0x0447,
  21444. chedescenderabkhasiancyrillic: 0x04BF,
  21445. chedescendercyrillic: 0x04B7,
  21446. chedieresiscyrillic: 0x04F5,
  21447. cheharmenian: 0x0573,
  21448. chekhakassiancyrillic: 0x04CC,
  21449. cheverticalstrokecyrillic: 0x04B9,
  21450. chi: 0x03C7,
  21451. chieuchacirclekorean: 0x3277,
  21452. chieuchaparenkorean: 0x3217,
  21453. chieuchcirclekorean: 0x3269,
  21454. chieuchkorean: 0x314A,
  21455. chieuchparenkorean: 0x3209,
  21456. chochangthai: 0x0E0A,
  21457. chochanthai: 0x0E08,
  21458. chochingthai: 0x0E09,
  21459. chochoethai: 0x0E0C,
  21460. chook: 0x0188,
  21461. cieucacirclekorean: 0x3276,
  21462. cieucaparenkorean: 0x3216,
  21463. cieuccirclekorean: 0x3268,
  21464. cieuckorean: 0x3148,
  21465. cieucparenkorean: 0x3208,
  21466. cieucuparenkorean: 0x321C,
  21467. circle: 0x25CB,
  21468. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21469. circlemultiply: 0x2297,
  21470. circleot: 0x2299,
  21471. circleplus: 0x2295,
  21472. circlepostalmark: 0x3036,
  21473. circlewithlefthalfblack: 0x25D0,
  21474. circlewithrighthalfblack: 0x25D1,
  21475. circumflex: 0x02C6,
  21476. circumflexbelowcmb: 0x032D,
  21477. circumflexcmb: 0x0302,
  21478. clear: 0x2327,
  21479. clickalveolar: 0x01C2,
  21480. clickdental: 0x01C0,
  21481. clicklateral: 0x01C1,
  21482. clickretroflex: 0x01C3,
  21483. club: 0x2663,
  21484. clubsuitblack: 0x2663,
  21485. clubsuitwhite: 0x2667,
  21486. cmcubedsquare: 0x33A4,
  21487. cmonospace: 0xFF43,
  21488. cmsquaredsquare: 0x33A0,
  21489. coarmenian: 0x0581,
  21490. colon: 0x003A,
  21491. colonmonetary: 0x20A1,
  21492. colonmonospace: 0xFF1A,
  21493. colonsign: 0x20A1,
  21494. colonsmall: 0xFE55,
  21495. colontriangularhalfmod: 0x02D1,
  21496. colontriangularmod: 0x02D0,
  21497. comma: 0x002C,
  21498. commaabovecmb: 0x0313,
  21499. commaaboverightcmb: 0x0315,
  21500. commaaccent: 0xF6C3,
  21501. commaarabic: 0x060C,
  21502. commaarmenian: 0x055D,
  21503. commainferior: 0xF6E1,
  21504. commamonospace: 0xFF0C,
  21505. commareversedabovecmb: 0x0314,
  21506. commareversedmod: 0x02BD,
  21507. commasmall: 0xFE50,
  21508. commasuperior: 0xF6E2,
  21509. commaturnedabovecmb: 0x0312,
  21510. commaturnedmod: 0x02BB,
  21511. compass: 0x263C,
  21512. congruent: 0x2245,
  21513. contourintegral: 0x222E,
  21514. control: 0x2303,
  21515. controlACK: 0x0006,
  21516. controlBEL: 0x0007,
  21517. controlBS: 0x0008,
  21518. controlCAN: 0x0018,
  21519. controlCR: 0x000D,
  21520. controlDC1: 0x0011,
  21521. controlDC2: 0x0012,
  21522. controlDC3: 0x0013,
  21523. controlDC4: 0x0014,
  21524. controlDEL: 0x007F,
  21525. controlDLE: 0x0010,
  21526. controlEM: 0x0019,
  21527. controlENQ: 0x0005,
  21528. controlEOT: 0x0004,
  21529. controlESC: 0x001B,
  21530. controlETB: 0x0017,
  21531. controlETX: 0x0003,
  21532. controlFF: 0x000C,
  21533. controlFS: 0x001C,
  21534. controlGS: 0x001D,
  21535. controlHT: 0x0009,
  21536. controlLF: 0x000A,
  21537. controlNAK: 0x0015,
  21538. controlRS: 0x001E,
  21539. controlSI: 0x000F,
  21540. controlSO: 0x000E,
  21541. controlSOT: 0x0002,
  21542. controlSTX: 0x0001,
  21543. controlSUB: 0x001A,
  21544. controlSYN: 0x0016,
  21545. controlUS: 0x001F,
  21546. controlVT: 0x000B,
  21547. copyright: 0x00A9,
  21548. copyrightsans: 0xF8E9,
  21549. copyrightserif: 0xF6D9,
  21550. cornerbracketleft: 0x300C,
  21551. cornerbracketlefthalfwidth: 0xFF62,
  21552. cornerbracketleftvertical: 0xFE41,
  21553. cornerbracketright: 0x300D,
  21554. cornerbracketrighthalfwidth: 0xFF63,
  21555. cornerbracketrightvertical: 0xFE42,
  21556. corporationsquare: 0x337F,
  21557. cosquare: 0x33C7,
  21558. coverkgsquare: 0x33C6,
  21559. cparen: 0x249E,
  21560. cruzeiro: 0x20A2,
  21561. cstretched: 0x0297,
  21562. curlyand: 0x22CF,
  21563. curlyor: 0x22CE,
  21564. currency: 0x00A4,
  21565. cyrBreve: 0xF6D1,
  21566. cyrFlex: 0xF6D2,
  21567. cyrbreve: 0xF6D4,
  21568. cyrflex: 0xF6D5,
  21569. d: 0x0064,
  21570. daarmenian: 0x0564,
  21571. dabengali: 0x09A6,
  21572. dadarabic: 0x0636,
  21573. dadeva: 0x0926,
  21574. dadfinalarabic: 0xFEBE,
  21575. dadinitialarabic: 0xFEBF,
  21576. dadmedialarabic: 0xFEC0,
  21577. dagesh: 0x05BC,
  21578. dageshhebrew: 0x05BC,
  21579. dagger: 0x2020,
  21580. daggerdbl: 0x2021,
  21581. dagujarati: 0x0AA6,
  21582. dagurmukhi: 0x0A26,
  21583. dahiragana: 0x3060,
  21584. dakatakana: 0x30C0,
  21585. dalarabic: 0x062F,
  21586. dalet: 0x05D3,
  21587. daletdagesh: 0xFB33,
  21588. daletdageshhebrew: 0xFB33,
  21589. dalethebrew: 0x05D3,
  21590. dalfinalarabic: 0xFEAA,
  21591. dammaarabic: 0x064F,
  21592. dammalowarabic: 0x064F,
  21593. dammatanaltonearabic: 0x064C,
  21594. dammatanarabic: 0x064C,
  21595. danda: 0x0964,
  21596. dargahebrew: 0x05A7,
  21597. dargalefthebrew: 0x05A7,
  21598. dasiapneumatacyrilliccmb: 0x0485,
  21599. dblGrave: 0xF6D3,
  21600. dblanglebracketleft: 0x300A,
  21601. dblanglebracketleftvertical: 0xFE3D,
  21602. dblanglebracketright: 0x300B,
  21603. dblanglebracketrightvertical: 0xFE3E,
  21604. dblarchinvertedbelowcmb: 0x032B,
  21605. dblarrowleft: 0x21D4,
  21606. dblarrowright: 0x21D2,
  21607. dbldanda: 0x0965,
  21608. dblgrave: 0xF6D6,
  21609. dblgravecmb: 0x030F,
  21610. dblintegral: 0x222C,
  21611. dbllowline: 0x2017,
  21612. dbllowlinecmb: 0x0333,
  21613. dbloverlinecmb: 0x033F,
  21614. dblprimemod: 0x02BA,
  21615. dblverticalbar: 0x2016,
  21616. dblverticallineabovecmb: 0x030E,
  21617. dbopomofo: 0x3109,
  21618. dbsquare: 0x33C8,
  21619. dcaron: 0x010F,
  21620. dcedilla: 0x1E11,
  21621. dcircle: 0x24D3,
  21622. dcircumflexbelow: 0x1E13,
  21623. dcroat: 0x0111,
  21624. ddabengali: 0x09A1,
  21625. ddadeva: 0x0921,
  21626. ddagujarati: 0x0AA1,
  21627. ddagurmukhi: 0x0A21,
  21628. ddalarabic: 0x0688,
  21629. ddalfinalarabic: 0xFB89,
  21630. dddhadeva: 0x095C,
  21631. ddhabengali: 0x09A2,
  21632. ddhadeva: 0x0922,
  21633. ddhagujarati: 0x0AA2,
  21634. ddhagurmukhi: 0x0A22,
  21635. ddotaccent: 0x1E0B,
  21636. ddotbelow: 0x1E0D,
  21637. decimalseparatorarabic: 0x066B,
  21638. decimalseparatorpersian: 0x066B,
  21639. decyrillic: 0x0434,
  21640. degree: 0x00B0,
  21641. dehihebrew: 0x05AD,
  21642. dehiragana: 0x3067,
  21643. deicoptic: 0x03EF,
  21644. dekatakana: 0x30C7,
  21645. deleteleft: 0x232B,
  21646. deleteright: 0x2326,
  21647. delta: 0x03B4,
  21648. deltaturned: 0x018D,
  21649. denominatorminusonenumeratorbengali: 0x09F8,
  21650. dezh: 0x02A4,
  21651. dhabengali: 0x09A7,
  21652. dhadeva: 0x0927,
  21653. dhagujarati: 0x0AA7,
  21654. dhagurmukhi: 0x0A27,
  21655. dhook: 0x0257,
  21656. dialytikatonos: 0x0385,
  21657. dialytikatonoscmb: 0x0344,
  21658. diamond: 0x2666,
  21659. diamondsuitwhite: 0x2662,
  21660. dieresis: 0x00A8,
  21661. dieresisacute: 0xF6D7,
  21662. dieresisbelowcmb: 0x0324,
  21663. dieresiscmb: 0x0308,
  21664. dieresisgrave: 0xF6D8,
  21665. dieresistonos: 0x0385,
  21666. dihiragana: 0x3062,
  21667. dikatakana: 0x30C2,
  21668. dittomark: 0x3003,
  21669. divide: 0x00F7,
  21670. divides: 0x2223,
  21671. divisionslash: 0x2215,
  21672. djecyrillic: 0x0452,
  21673. dkshade: 0x2593,
  21674. dlinebelow: 0x1E0F,
  21675. dlsquare: 0x3397,
  21676. dmacron: 0x0111,
  21677. dmonospace: 0xFF44,
  21678. dnblock: 0x2584,
  21679. dochadathai: 0x0E0E,
  21680. dodekthai: 0x0E14,
  21681. dohiragana: 0x3069,
  21682. dokatakana: 0x30C9,
  21683. dollar: 0x0024,
  21684. dollarinferior: 0xF6E3,
  21685. dollarmonospace: 0xFF04,
  21686. dollaroldstyle: 0xF724,
  21687. dollarsmall: 0xFE69,
  21688. dollarsuperior: 0xF6E4,
  21689. dong: 0x20AB,
  21690. dorusquare: 0x3326,
  21691. dotaccent: 0x02D9,
  21692. dotaccentcmb: 0x0307,
  21693. dotbelowcmb: 0x0323,
  21694. dotbelowcomb: 0x0323,
  21695. dotkatakana: 0x30FB,
  21696. dotlessi: 0x0131,
  21697. dotlessj: 0xF6BE,
  21698. dotlessjstrokehook: 0x0284,
  21699. dotmath: 0x22C5,
  21700. dottedcircle: 0x25CC,
  21701. doubleyodpatah: 0xFB1F,
  21702. doubleyodpatahhebrew: 0xFB1F,
  21703. downtackbelowcmb: 0x031E,
  21704. downtackmod: 0x02D5,
  21705. dparen: 0x249F,
  21706. dsuperior: 0xF6EB,
  21707. dtail: 0x0256,
  21708. dtopbar: 0x018C,
  21709. duhiragana: 0x3065,
  21710. dukatakana: 0x30C5,
  21711. dz: 0x01F3,
  21712. dzaltone: 0x02A3,
  21713. dzcaron: 0x01C6,
  21714. dzcurl: 0x02A5,
  21715. dzeabkhasiancyrillic: 0x04E1,
  21716. dzecyrillic: 0x0455,
  21717. dzhecyrillic: 0x045F,
  21718. e: 0x0065,
  21719. eacute: 0x00E9,
  21720. earth: 0x2641,
  21721. ebengali: 0x098F,
  21722. ebopomofo: 0x311C,
  21723. ebreve: 0x0115,
  21724. ecandradeva: 0x090D,
  21725. ecandragujarati: 0x0A8D,
  21726. ecandravowelsigndeva: 0x0945,
  21727. ecandravowelsigngujarati: 0x0AC5,
  21728. ecaron: 0x011B,
  21729. ecedillabreve: 0x1E1D,
  21730. echarmenian: 0x0565,
  21731. echyiwnarmenian: 0x0587,
  21732. ecircle: 0x24D4,
  21733. ecircumflex: 0x00EA,
  21734. ecircumflexacute: 0x1EBF,
  21735. ecircumflexbelow: 0x1E19,
  21736. ecircumflexdotbelow: 0x1EC7,
  21737. ecircumflexgrave: 0x1EC1,
  21738. ecircumflexhookabove: 0x1EC3,
  21739. ecircumflextilde: 0x1EC5,
  21740. ecyrillic: 0x0454,
  21741. edblgrave: 0x0205,
  21742. edeva: 0x090F,
  21743. edieresis: 0x00EB,
  21744. edot: 0x0117,
  21745. edotaccent: 0x0117,
  21746. edotbelow: 0x1EB9,
  21747. eegurmukhi: 0x0A0F,
  21748. eematragurmukhi: 0x0A47,
  21749. efcyrillic: 0x0444,
  21750. egrave: 0x00E8,
  21751. egujarati: 0x0A8F,
  21752. eharmenian: 0x0567,
  21753. ehbopomofo: 0x311D,
  21754. ehiragana: 0x3048,
  21755. ehookabove: 0x1EBB,
  21756. eibopomofo: 0x311F,
  21757. eight: 0x0038,
  21758. eightarabic: 0x0668,
  21759. eightbengali: 0x09EE,
  21760. eightcircle: 0x2467,
  21761. eightcircleinversesansserif: 0x2791,
  21762. eightdeva: 0x096E,
  21763. eighteencircle: 0x2471,
  21764. eighteenparen: 0x2485,
  21765. eighteenperiod: 0x2499,
  21766. eightgujarati: 0x0AEE,
  21767. eightgurmukhi: 0x0A6E,
  21768. eighthackarabic: 0x0668,
  21769. eighthangzhou: 0x3028,
  21770. eighthnotebeamed: 0x266B,
  21771. eightideographicparen: 0x3227,
  21772. eightinferior: 0x2088,
  21773. eightmonospace: 0xFF18,
  21774. eightoldstyle: 0xF738,
  21775. eightparen: 0x247B,
  21776. eightperiod: 0x248F,
  21777. eightpersian: 0x06F8,
  21778. eightroman: 0x2177,
  21779. eightsuperior: 0x2078,
  21780. eightthai: 0x0E58,
  21781. einvertedbreve: 0x0207,
  21782. eiotifiedcyrillic: 0x0465,
  21783. ekatakana: 0x30A8,
  21784. ekatakanahalfwidth: 0xFF74,
  21785. ekonkargurmukhi: 0x0A74,
  21786. ekorean: 0x3154,
  21787. elcyrillic: 0x043B,
  21788. element: 0x2208,
  21789. elevencircle: 0x246A,
  21790. elevenparen: 0x247E,
  21791. elevenperiod: 0x2492,
  21792. elevenroman: 0x217A,
  21793. ellipsis: 0x2026,
  21794. ellipsisvertical: 0x22EE,
  21795. emacron: 0x0113,
  21796. emacronacute: 0x1E17,
  21797. emacrongrave: 0x1E15,
  21798. emcyrillic: 0x043C,
  21799. emdash: 0x2014,
  21800. emdashvertical: 0xFE31,
  21801. emonospace: 0xFF45,
  21802. emphasismarkarmenian: 0x055B,
  21803. emptyset: 0x2205,
  21804. enbopomofo: 0x3123,
  21805. encyrillic: 0x043D,
  21806. endash: 0x2013,
  21807. endashvertical: 0xFE32,
  21808. endescendercyrillic: 0x04A3,
  21809. eng: 0x014B,
  21810. engbopomofo: 0x3125,
  21811. enghecyrillic: 0x04A5,
  21812. enhookcyrillic: 0x04C8,
  21813. enspace: 0x2002,
  21814. eogonek: 0x0119,
  21815. eokorean: 0x3153,
  21816. eopen: 0x025B,
  21817. eopenclosed: 0x029A,
  21818. eopenreversed: 0x025C,
  21819. eopenreversedclosed: 0x025E,
  21820. eopenreversedhook: 0x025D,
  21821. eparen: 0x24A0,
  21822. epsilon: 0x03B5,
  21823. epsilontonos: 0x03AD,
  21824. equal: 0x003D,
  21825. equalmonospace: 0xFF1D,
  21826. equalsmall: 0xFE66,
  21827. equalsuperior: 0x207C,
  21828. equivalence: 0x2261,
  21829. erbopomofo: 0x3126,
  21830. ercyrillic: 0x0440,
  21831. ereversed: 0x0258,
  21832. ereversedcyrillic: 0x044D,
  21833. escyrillic: 0x0441,
  21834. esdescendercyrillic: 0x04AB,
  21835. esh: 0x0283,
  21836. eshcurl: 0x0286,
  21837. eshortdeva: 0x090E,
  21838. eshortvowelsigndeva: 0x0946,
  21839. eshreversedloop: 0x01AA,
  21840. eshsquatreversed: 0x0285,
  21841. esmallhiragana: 0x3047,
  21842. esmallkatakana: 0x30A7,
  21843. esmallkatakanahalfwidth: 0xFF6A,
  21844. estimated: 0x212E,
  21845. esuperior: 0xF6EC,
  21846. eta: 0x03B7,
  21847. etarmenian: 0x0568,
  21848. etatonos: 0x03AE,
  21849. eth: 0x00F0,
  21850. etilde: 0x1EBD,
  21851. etildebelow: 0x1E1B,
  21852. etnahtafoukhhebrew: 0x0591,
  21853. etnahtafoukhlefthebrew: 0x0591,
  21854. etnahtahebrew: 0x0591,
  21855. etnahtalefthebrew: 0x0591,
  21856. eturned: 0x01DD,
  21857. eukorean: 0x3161,
  21858. euro: 0x20AC,
  21859. evowelsignbengali: 0x09C7,
  21860. evowelsigndeva: 0x0947,
  21861. evowelsigngujarati: 0x0AC7,
  21862. exclam: 0x0021,
  21863. exclamarmenian: 0x055C,
  21864. exclamdbl: 0x203C,
  21865. exclamdown: 0x00A1,
  21866. exclamdownsmall: 0xF7A1,
  21867. exclammonospace: 0xFF01,
  21868. exclamsmall: 0xF721,
  21869. existential: 0x2203,
  21870. ezh: 0x0292,
  21871. ezhcaron: 0x01EF,
  21872. ezhcurl: 0x0293,
  21873. ezhreversed: 0x01B9,
  21874. ezhtail: 0x01BA,
  21875. f: 0x0066,
  21876. fadeva: 0x095E,
  21877. fagurmukhi: 0x0A5E,
  21878. fahrenheit: 0x2109,
  21879. fathaarabic: 0x064E,
  21880. fathalowarabic: 0x064E,
  21881. fathatanarabic: 0x064B,
  21882. fbopomofo: 0x3108,
  21883. fcircle: 0x24D5,
  21884. fdotaccent: 0x1E1F,
  21885. feharabic: 0x0641,
  21886. feharmenian: 0x0586,
  21887. fehfinalarabic: 0xFED2,
  21888. fehinitialarabic: 0xFED3,
  21889. fehmedialarabic: 0xFED4,
  21890. feicoptic: 0x03E5,
  21891. female: 0x2640,
  21892. ff: 0xFB00,
  21893. ffi: 0xFB03,
  21894. ffl: 0xFB04,
  21895. fi: 0xFB01,
  21896. fifteencircle: 0x246E,
  21897. fifteenparen: 0x2482,
  21898. fifteenperiod: 0x2496,
  21899. figuredash: 0x2012,
  21900. filledbox: 0x25A0,
  21901. filledrect: 0x25AC,
  21902. finalkaf: 0x05DA,
  21903. finalkafdagesh: 0xFB3A,
  21904. finalkafdageshhebrew: 0xFB3A,
  21905. finalkafhebrew: 0x05DA,
  21906. finalmem: 0x05DD,
  21907. finalmemhebrew: 0x05DD,
  21908. finalnun: 0x05DF,
  21909. finalnunhebrew: 0x05DF,
  21910. finalpe: 0x05E3,
  21911. finalpehebrew: 0x05E3,
  21912. finaltsadi: 0x05E5,
  21913. finaltsadihebrew: 0x05E5,
  21914. firsttonechinese: 0x02C9,
  21915. fisheye: 0x25C9,
  21916. fitacyrillic: 0x0473,
  21917. five: 0x0035,
  21918. fivearabic: 0x0665,
  21919. fivebengali: 0x09EB,
  21920. fivecircle: 0x2464,
  21921. fivecircleinversesansserif: 0x278E,
  21922. fivedeva: 0x096B,
  21923. fiveeighths: 0x215D,
  21924. fivegujarati: 0x0AEB,
  21925. fivegurmukhi: 0x0A6B,
  21926. fivehackarabic: 0x0665,
  21927. fivehangzhou: 0x3025,
  21928. fiveideographicparen: 0x3224,
  21929. fiveinferior: 0x2085,
  21930. fivemonospace: 0xFF15,
  21931. fiveoldstyle: 0xF735,
  21932. fiveparen: 0x2478,
  21933. fiveperiod: 0x248C,
  21934. fivepersian: 0x06F5,
  21935. fiveroman: 0x2174,
  21936. fivesuperior: 0x2075,
  21937. fivethai: 0x0E55,
  21938. fl: 0xFB02,
  21939. florin: 0x0192,
  21940. fmonospace: 0xFF46,
  21941. fmsquare: 0x3399,
  21942. fofanthai: 0x0E1F,
  21943. fofathai: 0x0E1D,
  21944. fongmanthai: 0x0E4F,
  21945. forall: 0x2200,
  21946. four: 0x0034,
  21947. fourarabic: 0x0664,
  21948. fourbengali: 0x09EA,
  21949. fourcircle: 0x2463,
  21950. fourcircleinversesansserif: 0x278D,
  21951. fourdeva: 0x096A,
  21952. fourgujarati: 0x0AEA,
  21953. fourgurmukhi: 0x0A6A,
  21954. fourhackarabic: 0x0664,
  21955. fourhangzhou: 0x3024,
  21956. fourideographicparen: 0x3223,
  21957. fourinferior: 0x2084,
  21958. fourmonospace: 0xFF14,
  21959. fournumeratorbengali: 0x09F7,
  21960. fouroldstyle: 0xF734,
  21961. fourparen: 0x2477,
  21962. fourperiod: 0x248B,
  21963. fourpersian: 0x06F4,
  21964. fourroman: 0x2173,
  21965. foursuperior: 0x2074,
  21966. fourteencircle: 0x246D,
  21967. fourteenparen: 0x2481,
  21968. fourteenperiod: 0x2495,
  21969. fourthai: 0x0E54,
  21970. fourthtonechinese: 0x02CB,
  21971. fparen: 0x24A1,
  21972. fraction: 0x2044,
  21973. franc: 0x20A3,
  21974. g: 0x0067,
  21975. gabengali: 0x0997,
  21976. gacute: 0x01F5,
  21977. gadeva: 0x0917,
  21978. gafarabic: 0x06AF,
  21979. gaffinalarabic: 0xFB93,
  21980. gafinitialarabic: 0xFB94,
  21981. gafmedialarabic: 0xFB95,
  21982. gagujarati: 0x0A97,
  21983. gagurmukhi: 0x0A17,
  21984. gahiragana: 0x304C,
  21985. gakatakana: 0x30AC,
  21986. gamma: 0x03B3,
  21987. gammalatinsmall: 0x0263,
  21988. gammasuperior: 0x02E0,
  21989. gangiacoptic: 0x03EB,
  21990. gbopomofo: 0x310D,
  21991. gbreve: 0x011F,
  21992. gcaron: 0x01E7,
  21993. gcedilla: 0x0123,
  21994. gcircle: 0x24D6,
  21995. gcircumflex: 0x011D,
  21996. gcommaaccent: 0x0123,
  21997. gdot: 0x0121,
  21998. gdotaccent: 0x0121,
  21999. gecyrillic: 0x0433,
  22000. gehiragana: 0x3052,
  22001. gekatakana: 0x30B2,
  22002. geometricallyequal: 0x2251,
  22003. gereshaccenthebrew: 0x059C,
  22004. gereshhebrew: 0x05F3,
  22005. gereshmuqdamhebrew: 0x059D,
  22006. germandbls: 0x00DF,
  22007. gershayimaccenthebrew: 0x059E,
  22008. gershayimhebrew: 0x05F4,
  22009. getamark: 0x3013,
  22010. ghabengali: 0x0998,
  22011. ghadarmenian: 0x0572,
  22012. ghadeva: 0x0918,
  22013. ghagujarati: 0x0A98,
  22014. ghagurmukhi: 0x0A18,
  22015. ghainarabic: 0x063A,
  22016. ghainfinalarabic: 0xFECE,
  22017. ghaininitialarabic: 0xFECF,
  22018. ghainmedialarabic: 0xFED0,
  22019. ghemiddlehookcyrillic: 0x0495,
  22020. ghestrokecyrillic: 0x0493,
  22021. gheupturncyrillic: 0x0491,
  22022. ghhadeva: 0x095A,
  22023. ghhagurmukhi: 0x0A5A,
  22024. ghook: 0x0260,
  22025. ghzsquare: 0x3393,
  22026. gihiragana: 0x304E,
  22027. gikatakana: 0x30AE,
  22028. gimarmenian: 0x0563,
  22029. gimel: 0x05D2,
  22030. gimeldagesh: 0xFB32,
  22031. gimeldageshhebrew: 0xFB32,
  22032. gimelhebrew: 0x05D2,
  22033. gjecyrillic: 0x0453,
  22034. glottalinvertedstroke: 0x01BE,
  22035. glottalstop: 0x0294,
  22036. glottalstopinverted: 0x0296,
  22037. glottalstopmod: 0x02C0,
  22038. glottalstopreversed: 0x0295,
  22039. glottalstopreversedmod: 0x02C1,
  22040. glottalstopreversedsuperior: 0x02E4,
  22041. glottalstopstroke: 0x02A1,
  22042. glottalstopstrokereversed: 0x02A2,
  22043. gmacron: 0x1E21,
  22044. gmonospace: 0xFF47,
  22045. gohiragana: 0x3054,
  22046. gokatakana: 0x30B4,
  22047. gparen: 0x24A2,
  22048. gpasquare: 0x33AC,
  22049. gradient: 0x2207,
  22050. grave: 0x0060,
  22051. gravebelowcmb: 0x0316,
  22052. gravecmb: 0x0300,
  22053. gravecomb: 0x0300,
  22054. gravedeva: 0x0953,
  22055. gravelowmod: 0x02CE,
  22056. gravemonospace: 0xFF40,
  22057. gravetonecmb: 0x0340,
  22058. greater: 0x003E,
  22059. greaterequal: 0x2265,
  22060. greaterequalorless: 0x22DB,
  22061. greatermonospace: 0xFF1E,
  22062. greaterorequivalent: 0x2273,
  22063. greaterorless: 0x2277,
  22064. greateroverequal: 0x2267,
  22065. greatersmall: 0xFE65,
  22066. gscript: 0x0261,
  22067. gstroke: 0x01E5,
  22068. guhiragana: 0x3050,
  22069. guillemotleft: 0x00AB,
  22070. guillemotright: 0x00BB,
  22071. guilsinglleft: 0x2039,
  22072. guilsinglright: 0x203A,
  22073. gukatakana: 0x30B0,
  22074. guramusquare: 0x3318,
  22075. gysquare: 0x33C9,
  22076. h: 0x0068,
  22077. haabkhasiancyrillic: 0x04A9,
  22078. haaltonearabic: 0x06C1,
  22079. habengali: 0x09B9,
  22080. hadescendercyrillic: 0x04B3,
  22081. hadeva: 0x0939,
  22082. hagujarati: 0x0AB9,
  22083. hagurmukhi: 0x0A39,
  22084. haharabic: 0x062D,
  22085. hahfinalarabic: 0xFEA2,
  22086. hahinitialarabic: 0xFEA3,
  22087. hahiragana: 0x306F,
  22088. hahmedialarabic: 0xFEA4,
  22089. haitusquare: 0x332A,
  22090. hakatakana: 0x30CF,
  22091. hakatakanahalfwidth: 0xFF8A,
  22092. halantgurmukhi: 0x0A4D,
  22093. hamzaarabic: 0x0621,
  22094. hamzalowarabic: 0x0621,
  22095. hangulfiller: 0x3164,
  22096. hardsigncyrillic: 0x044A,
  22097. harpoonleftbarbup: 0x21BC,
  22098. harpoonrightbarbup: 0x21C0,
  22099. hasquare: 0x33CA,
  22100. hatafpatah: 0x05B2,
  22101. hatafpatah16: 0x05B2,
  22102. hatafpatah23: 0x05B2,
  22103. hatafpatah2f: 0x05B2,
  22104. hatafpatahhebrew: 0x05B2,
  22105. hatafpatahnarrowhebrew: 0x05B2,
  22106. hatafpatahquarterhebrew: 0x05B2,
  22107. hatafpatahwidehebrew: 0x05B2,
  22108. hatafqamats: 0x05B3,
  22109. hatafqamats1b: 0x05B3,
  22110. hatafqamats28: 0x05B3,
  22111. hatafqamats34: 0x05B3,
  22112. hatafqamatshebrew: 0x05B3,
  22113. hatafqamatsnarrowhebrew: 0x05B3,
  22114. hatafqamatsquarterhebrew: 0x05B3,
  22115. hatafqamatswidehebrew: 0x05B3,
  22116. hatafsegol: 0x05B1,
  22117. hatafsegol17: 0x05B1,
  22118. hatafsegol24: 0x05B1,
  22119. hatafsegol30: 0x05B1,
  22120. hatafsegolhebrew: 0x05B1,
  22121. hatafsegolnarrowhebrew: 0x05B1,
  22122. hatafsegolquarterhebrew: 0x05B1,
  22123. hatafsegolwidehebrew: 0x05B1,
  22124. hbar: 0x0127,
  22125. hbopomofo: 0x310F,
  22126. hbrevebelow: 0x1E2B,
  22127. hcedilla: 0x1E29,
  22128. hcircle: 0x24D7,
  22129. hcircumflex: 0x0125,
  22130. hdieresis: 0x1E27,
  22131. hdotaccent: 0x1E23,
  22132. hdotbelow: 0x1E25,
  22133. he: 0x05D4,
  22134. heart: 0x2665,
  22135. heartsuitblack: 0x2665,
  22136. heartsuitwhite: 0x2661,
  22137. hedagesh: 0xFB34,
  22138. hedageshhebrew: 0xFB34,
  22139. hehaltonearabic: 0x06C1,
  22140. heharabic: 0x0647,
  22141. hehebrew: 0x05D4,
  22142. hehfinalaltonearabic: 0xFBA7,
  22143. hehfinalalttwoarabic: 0xFEEA,
  22144. hehfinalarabic: 0xFEEA,
  22145. hehhamzaabovefinalarabic: 0xFBA5,
  22146. hehhamzaaboveisolatedarabic: 0xFBA4,
  22147. hehinitialaltonearabic: 0xFBA8,
  22148. hehinitialarabic: 0xFEEB,
  22149. hehiragana: 0x3078,
  22150. hehmedialaltonearabic: 0xFBA9,
  22151. hehmedialarabic: 0xFEEC,
  22152. heiseierasquare: 0x337B,
  22153. hekatakana: 0x30D8,
  22154. hekatakanahalfwidth: 0xFF8D,
  22155. hekutaarusquare: 0x3336,
  22156. henghook: 0x0267,
  22157. herutusquare: 0x3339,
  22158. het: 0x05D7,
  22159. hethebrew: 0x05D7,
  22160. hhook: 0x0266,
  22161. hhooksuperior: 0x02B1,
  22162. hieuhacirclekorean: 0x327B,
  22163. hieuhaparenkorean: 0x321B,
  22164. hieuhcirclekorean: 0x326D,
  22165. hieuhkorean: 0x314E,
  22166. hieuhparenkorean: 0x320D,
  22167. hihiragana: 0x3072,
  22168. hikatakana: 0x30D2,
  22169. hikatakanahalfwidth: 0xFF8B,
  22170. hiriq: 0x05B4,
  22171. hiriq14: 0x05B4,
  22172. hiriq21: 0x05B4,
  22173. hiriq2d: 0x05B4,
  22174. hiriqhebrew: 0x05B4,
  22175. hiriqnarrowhebrew: 0x05B4,
  22176. hiriqquarterhebrew: 0x05B4,
  22177. hiriqwidehebrew: 0x05B4,
  22178. hlinebelow: 0x1E96,
  22179. hmonospace: 0xFF48,
  22180. hoarmenian: 0x0570,
  22181. hohipthai: 0x0E2B,
  22182. hohiragana: 0x307B,
  22183. hokatakana: 0x30DB,
  22184. hokatakanahalfwidth: 0xFF8E,
  22185. holam: 0x05B9,
  22186. holam19: 0x05B9,
  22187. holam26: 0x05B9,
  22188. holam32: 0x05B9,
  22189. holamhebrew: 0x05B9,
  22190. holamnarrowhebrew: 0x05B9,
  22191. holamquarterhebrew: 0x05B9,
  22192. holamwidehebrew: 0x05B9,
  22193. honokhukthai: 0x0E2E,
  22194. hookabovecomb: 0x0309,
  22195. hookcmb: 0x0309,
  22196. hookpalatalizedbelowcmb: 0x0321,
  22197. hookretroflexbelowcmb: 0x0322,
  22198. hoonsquare: 0x3342,
  22199. horicoptic: 0x03E9,
  22200. horizontalbar: 0x2015,
  22201. horncmb: 0x031B,
  22202. hotsprings: 0x2668,
  22203. house: 0x2302,
  22204. hparen: 0x24A3,
  22205. hsuperior: 0x02B0,
  22206. hturned: 0x0265,
  22207. huhiragana: 0x3075,
  22208. huiitosquare: 0x3333,
  22209. hukatakana: 0x30D5,
  22210. hukatakanahalfwidth: 0xFF8C,
  22211. hungarumlaut: 0x02DD,
  22212. hungarumlautcmb: 0x030B,
  22213. hv: 0x0195,
  22214. hyphen: 0x002D,
  22215. hypheninferior: 0xF6E5,
  22216. hyphenmonospace: 0xFF0D,
  22217. hyphensmall: 0xFE63,
  22218. hyphensuperior: 0xF6E6,
  22219. hyphentwo: 0x2010,
  22220. i: 0x0069,
  22221. iacute: 0x00ED,
  22222. iacyrillic: 0x044F,
  22223. ibengali: 0x0987,
  22224. ibopomofo: 0x3127,
  22225. ibreve: 0x012D,
  22226. icaron: 0x01D0,
  22227. icircle: 0x24D8,
  22228. icircumflex: 0x00EE,
  22229. icyrillic: 0x0456,
  22230. idblgrave: 0x0209,
  22231. ideographearthcircle: 0x328F,
  22232. ideographfirecircle: 0x328B,
  22233. ideographicallianceparen: 0x323F,
  22234. ideographiccallparen: 0x323A,
  22235. ideographiccentrecircle: 0x32A5,
  22236. ideographicclose: 0x3006,
  22237. ideographiccomma: 0x3001,
  22238. ideographiccommaleft: 0xFF64,
  22239. ideographiccongratulationparen: 0x3237,
  22240. ideographiccorrectcircle: 0x32A3,
  22241. ideographicearthparen: 0x322F,
  22242. ideographicenterpriseparen: 0x323D,
  22243. ideographicexcellentcircle: 0x329D,
  22244. ideographicfestivalparen: 0x3240,
  22245. ideographicfinancialcircle: 0x3296,
  22246. ideographicfinancialparen: 0x3236,
  22247. ideographicfireparen: 0x322B,
  22248. ideographichaveparen: 0x3232,
  22249. ideographichighcircle: 0x32A4,
  22250. ideographiciterationmark: 0x3005,
  22251. ideographiclaborcircle: 0x3298,
  22252. ideographiclaborparen: 0x3238,
  22253. ideographicleftcircle: 0x32A7,
  22254. ideographiclowcircle: 0x32A6,
  22255. ideographicmedicinecircle: 0x32A9,
  22256. ideographicmetalparen: 0x322E,
  22257. ideographicmoonparen: 0x322A,
  22258. ideographicnameparen: 0x3234,
  22259. ideographicperiod: 0x3002,
  22260. ideographicprintcircle: 0x329E,
  22261. ideographicreachparen: 0x3243,
  22262. ideographicrepresentparen: 0x3239,
  22263. ideographicresourceparen: 0x323E,
  22264. ideographicrightcircle: 0x32A8,
  22265. ideographicsecretcircle: 0x3299,
  22266. ideographicselfparen: 0x3242,
  22267. ideographicsocietyparen: 0x3233,
  22268. ideographicspace: 0x3000,
  22269. ideographicspecialparen: 0x3235,
  22270. ideographicstockparen: 0x3231,
  22271. ideographicstudyparen: 0x323B,
  22272. ideographicsunparen: 0x3230,
  22273. ideographicsuperviseparen: 0x323C,
  22274. ideographicwaterparen: 0x322C,
  22275. ideographicwoodparen: 0x322D,
  22276. ideographiczero: 0x3007,
  22277. ideographmetalcircle: 0x328E,
  22278. ideographmooncircle: 0x328A,
  22279. ideographnamecircle: 0x3294,
  22280. ideographsuncircle: 0x3290,
  22281. ideographwatercircle: 0x328C,
  22282. ideographwoodcircle: 0x328D,
  22283. ideva: 0x0907,
  22284. idieresis: 0x00EF,
  22285. idieresisacute: 0x1E2F,
  22286. idieresiscyrillic: 0x04E5,
  22287. idotbelow: 0x1ECB,
  22288. iebrevecyrillic: 0x04D7,
  22289. iecyrillic: 0x0435,
  22290. ieungacirclekorean: 0x3275,
  22291. ieungaparenkorean: 0x3215,
  22292. ieungcirclekorean: 0x3267,
  22293. ieungkorean: 0x3147,
  22294. ieungparenkorean: 0x3207,
  22295. igrave: 0x00EC,
  22296. igujarati: 0x0A87,
  22297. igurmukhi: 0x0A07,
  22298. ihiragana: 0x3044,
  22299. ihookabove: 0x1EC9,
  22300. iibengali: 0x0988,
  22301. iicyrillic: 0x0438,
  22302. iideva: 0x0908,
  22303. iigujarati: 0x0A88,
  22304. iigurmukhi: 0x0A08,
  22305. iimatragurmukhi: 0x0A40,
  22306. iinvertedbreve: 0x020B,
  22307. iishortcyrillic: 0x0439,
  22308. iivowelsignbengali: 0x09C0,
  22309. iivowelsigndeva: 0x0940,
  22310. iivowelsigngujarati: 0x0AC0,
  22311. ij: 0x0133,
  22312. ikatakana: 0x30A4,
  22313. ikatakanahalfwidth: 0xFF72,
  22314. ikorean: 0x3163,
  22315. ilde: 0x02DC,
  22316. iluyhebrew: 0x05AC,
  22317. imacron: 0x012B,
  22318. imacroncyrillic: 0x04E3,
  22319. imageorapproximatelyequal: 0x2253,
  22320. imatragurmukhi: 0x0A3F,
  22321. imonospace: 0xFF49,
  22322. increment: 0x2206,
  22323. infinity: 0x221E,
  22324. iniarmenian: 0x056B,
  22325. integral: 0x222B,
  22326. integralbottom: 0x2321,
  22327. integralbt: 0x2321,
  22328. integralex: 0xF8F5,
  22329. integraltop: 0x2320,
  22330. integraltp: 0x2320,
  22331. intersection: 0x2229,
  22332. intisquare: 0x3305,
  22333. invbullet: 0x25D8,
  22334. invcircle: 0x25D9,
  22335. invsmileface: 0x263B,
  22336. iocyrillic: 0x0451,
  22337. iogonek: 0x012F,
  22338. iota: 0x03B9,
  22339. iotadieresis: 0x03CA,
  22340. iotadieresistonos: 0x0390,
  22341. iotalatin: 0x0269,
  22342. iotatonos: 0x03AF,
  22343. iparen: 0x24A4,
  22344. irigurmukhi: 0x0A72,
  22345. ismallhiragana: 0x3043,
  22346. ismallkatakana: 0x30A3,
  22347. ismallkatakanahalfwidth: 0xFF68,
  22348. issharbengali: 0x09FA,
  22349. istroke: 0x0268,
  22350. isuperior: 0xF6ED,
  22351. iterationhiragana: 0x309D,
  22352. iterationkatakana: 0x30FD,
  22353. itilde: 0x0129,
  22354. itildebelow: 0x1E2D,
  22355. iubopomofo: 0x3129,
  22356. iucyrillic: 0x044E,
  22357. ivowelsignbengali: 0x09BF,
  22358. ivowelsigndeva: 0x093F,
  22359. ivowelsigngujarati: 0x0ABF,
  22360. izhitsacyrillic: 0x0475,
  22361. izhitsadblgravecyrillic: 0x0477,
  22362. j: 0x006A,
  22363. jaarmenian: 0x0571,
  22364. jabengali: 0x099C,
  22365. jadeva: 0x091C,
  22366. jagujarati: 0x0A9C,
  22367. jagurmukhi: 0x0A1C,
  22368. jbopomofo: 0x3110,
  22369. jcaron: 0x01F0,
  22370. jcircle: 0x24D9,
  22371. jcircumflex: 0x0135,
  22372. jcrossedtail: 0x029D,
  22373. jdotlessstroke: 0x025F,
  22374. jecyrillic: 0x0458,
  22375. jeemarabic: 0x062C,
  22376. jeemfinalarabic: 0xFE9E,
  22377. jeeminitialarabic: 0xFE9F,
  22378. jeemmedialarabic: 0xFEA0,
  22379. jeharabic: 0x0698,
  22380. jehfinalarabic: 0xFB8B,
  22381. jhabengali: 0x099D,
  22382. jhadeva: 0x091D,
  22383. jhagujarati: 0x0A9D,
  22384. jhagurmukhi: 0x0A1D,
  22385. jheharmenian: 0x057B,
  22386. jis: 0x3004,
  22387. jmonospace: 0xFF4A,
  22388. jparen: 0x24A5,
  22389. jsuperior: 0x02B2,
  22390. k: 0x006B,
  22391. kabashkircyrillic: 0x04A1,
  22392. kabengali: 0x0995,
  22393. kacute: 0x1E31,
  22394. kacyrillic: 0x043A,
  22395. kadescendercyrillic: 0x049B,
  22396. kadeva: 0x0915,
  22397. kaf: 0x05DB,
  22398. kafarabic: 0x0643,
  22399. kafdagesh: 0xFB3B,
  22400. kafdageshhebrew: 0xFB3B,
  22401. kaffinalarabic: 0xFEDA,
  22402. kafhebrew: 0x05DB,
  22403. kafinitialarabic: 0xFEDB,
  22404. kafmedialarabic: 0xFEDC,
  22405. kafrafehebrew: 0xFB4D,
  22406. kagujarati: 0x0A95,
  22407. kagurmukhi: 0x0A15,
  22408. kahiragana: 0x304B,
  22409. kahookcyrillic: 0x04C4,
  22410. kakatakana: 0x30AB,
  22411. kakatakanahalfwidth: 0xFF76,
  22412. kappa: 0x03BA,
  22413. kappasymbolgreek: 0x03F0,
  22414. kapyeounmieumkorean: 0x3171,
  22415. kapyeounphieuphkorean: 0x3184,
  22416. kapyeounpieupkorean: 0x3178,
  22417. kapyeounssangpieupkorean: 0x3179,
  22418. karoriisquare: 0x330D,
  22419. kashidaautoarabic: 0x0640,
  22420. kashidaautonosidebearingarabic: 0x0640,
  22421. kasmallkatakana: 0x30F5,
  22422. kasquare: 0x3384,
  22423. kasraarabic: 0x0650,
  22424. kasratanarabic: 0x064D,
  22425. kastrokecyrillic: 0x049F,
  22426. katahiraprolongmarkhalfwidth: 0xFF70,
  22427. kaverticalstrokecyrillic: 0x049D,
  22428. kbopomofo: 0x310E,
  22429. kcalsquare: 0x3389,
  22430. kcaron: 0x01E9,
  22431. kcedilla: 0x0137,
  22432. kcircle: 0x24DA,
  22433. kcommaaccent: 0x0137,
  22434. kdotbelow: 0x1E33,
  22435. keharmenian: 0x0584,
  22436. kehiragana: 0x3051,
  22437. kekatakana: 0x30B1,
  22438. kekatakanahalfwidth: 0xFF79,
  22439. kenarmenian: 0x056F,
  22440. kesmallkatakana: 0x30F6,
  22441. kgreenlandic: 0x0138,
  22442. khabengali: 0x0996,
  22443. khacyrillic: 0x0445,
  22444. khadeva: 0x0916,
  22445. khagujarati: 0x0A96,
  22446. khagurmukhi: 0x0A16,
  22447. khaharabic: 0x062E,
  22448. khahfinalarabic: 0xFEA6,
  22449. khahinitialarabic: 0xFEA7,
  22450. khahmedialarabic: 0xFEA8,
  22451. kheicoptic: 0x03E7,
  22452. khhadeva: 0x0959,
  22453. khhagurmukhi: 0x0A59,
  22454. khieukhacirclekorean: 0x3278,
  22455. khieukhaparenkorean: 0x3218,
  22456. khieukhcirclekorean: 0x326A,
  22457. khieukhkorean: 0x314B,
  22458. khieukhparenkorean: 0x320A,
  22459. khokhaithai: 0x0E02,
  22460. khokhonthai: 0x0E05,
  22461. khokhuatthai: 0x0E03,
  22462. khokhwaithai: 0x0E04,
  22463. khomutthai: 0x0E5B,
  22464. khook: 0x0199,
  22465. khorakhangthai: 0x0E06,
  22466. khzsquare: 0x3391,
  22467. kihiragana: 0x304D,
  22468. kikatakana: 0x30AD,
  22469. kikatakanahalfwidth: 0xFF77,
  22470. kiroguramusquare: 0x3315,
  22471. kiromeetorusquare: 0x3316,
  22472. kirosquare: 0x3314,
  22473. kiyeokacirclekorean: 0x326E,
  22474. kiyeokaparenkorean: 0x320E,
  22475. kiyeokcirclekorean: 0x3260,
  22476. kiyeokkorean: 0x3131,
  22477. kiyeokparenkorean: 0x3200,
  22478. kiyeoksioskorean: 0x3133,
  22479. kjecyrillic: 0x045C,
  22480. klinebelow: 0x1E35,
  22481. klsquare: 0x3398,
  22482. kmcubedsquare: 0x33A6,
  22483. kmonospace: 0xFF4B,
  22484. kmsquaredsquare: 0x33A2,
  22485. kohiragana: 0x3053,
  22486. kohmsquare: 0x33C0,
  22487. kokaithai: 0x0E01,
  22488. kokatakana: 0x30B3,
  22489. kokatakanahalfwidth: 0xFF7A,
  22490. kooposquare: 0x331E,
  22491. koppacyrillic: 0x0481,
  22492. koreanstandardsymbol: 0x327F,
  22493. koroniscmb: 0x0343,
  22494. kparen: 0x24A6,
  22495. kpasquare: 0x33AA,
  22496. ksicyrillic: 0x046F,
  22497. ktsquare: 0x33CF,
  22498. kturned: 0x029E,
  22499. kuhiragana: 0x304F,
  22500. kukatakana: 0x30AF,
  22501. kukatakanahalfwidth: 0xFF78,
  22502. kvsquare: 0x33B8,
  22503. kwsquare: 0x33BE,
  22504. l: 0x006C,
  22505. labengali: 0x09B2,
  22506. lacute: 0x013A,
  22507. ladeva: 0x0932,
  22508. lagujarati: 0x0AB2,
  22509. lagurmukhi: 0x0A32,
  22510. lakkhangyaothai: 0x0E45,
  22511. lamaleffinalarabic: 0xFEFC,
  22512. lamalefhamzaabovefinalarabic: 0xFEF8,
  22513. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22514. lamalefhamzabelowfinalarabic: 0xFEFA,
  22515. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22516. lamalefisolatedarabic: 0xFEFB,
  22517. lamalefmaddaabovefinalarabic: 0xFEF6,
  22518. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22519. lamarabic: 0x0644,
  22520. lambda: 0x03BB,
  22521. lambdastroke: 0x019B,
  22522. lamed: 0x05DC,
  22523. lameddagesh: 0xFB3C,
  22524. lameddageshhebrew: 0xFB3C,
  22525. lamedhebrew: 0x05DC,
  22526. lamfinalarabic: 0xFEDE,
  22527. lamhahinitialarabic: 0xFCCA,
  22528. laminitialarabic: 0xFEDF,
  22529. lamjeeminitialarabic: 0xFCC9,
  22530. lamkhahinitialarabic: 0xFCCB,
  22531. lamlamhehisolatedarabic: 0xFDF2,
  22532. lammedialarabic: 0xFEE0,
  22533. lammeemhahinitialarabic: 0xFD88,
  22534. lammeeminitialarabic: 0xFCCC,
  22535. largecircle: 0x25EF,
  22536. lbar: 0x019A,
  22537. lbelt: 0x026C,
  22538. lbopomofo: 0x310C,
  22539. lcaron: 0x013E,
  22540. lcedilla: 0x013C,
  22541. lcircle: 0x24DB,
  22542. lcircumflexbelow: 0x1E3D,
  22543. lcommaaccent: 0x013C,
  22544. ldot: 0x0140,
  22545. ldotaccent: 0x0140,
  22546. ldotbelow: 0x1E37,
  22547. ldotbelowmacron: 0x1E39,
  22548. leftangleabovecmb: 0x031A,
  22549. lefttackbelowcmb: 0x0318,
  22550. less: 0x003C,
  22551. lessequal: 0x2264,
  22552. lessequalorgreater: 0x22DA,
  22553. lessmonospace: 0xFF1C,
  22554. lessorequivalent: 0x2272,
  22555. lessorgreater: 0x2276,
  22556. lessoverequal: 0x2266,
  22557. lesssmall: 0xFE64,
  22558. lezh: 0x026E,
  22559. lfblock: 0x258C,
  22560. lhookretroflex: 0x026D,
  22561. lira: 0x20A4,
  22562. liwnarmenian: 0x056C,
  22563. lj: 0x01C9,
  22564. ljecyrillic: 0x0459,
  22565. ll: 0xF6C0,
  22566. lladeva: 0x0933,
  22567. llagujarati: 0x0AB3,
  22568. llinebelow: 0x1E3B,
  22569. llladeva: 0x0934,
  22570. llvocalicbengali: 0x09E1,
  22571. llvocalicdeva: 0x0961,
  22572. llvocalicvowelsignbengali: 0x09E3,
  22573. llvocalicvowelsigndeva: 0x0963,
  22574. lmiddletilde: 0x026B,
  22575. lmonospace: 0xFF4C,
  22576. lmsquare: 0x33D0,
  22577. lochulathai: 0x0E2C,
  22578. logicaland: 0x2227,
  22579. logicalnot: 0x00AC,
  22580. logicalnotreversed: 0x2310,
  22581. logicalor: 0x2228,
  22582. lolingthai: 0x0E25,
  22583. longs: 0x017F,
  22584. lowlinecenterline: 0xFE4E,
  22585. lowlinecmb: 0x0332,
  22586. lowlinedashed: 0xFE4D,
  22587. lozenge: 0x25CA,
  22588. lparen: 0x24A7,
  22589. lslash: 0x0142,
  22590. lsquare: 0x2113,
  22591. lsuperior: 0xF6EE,
  22592. ltshade: 0x2591,
  22593. luthai: 0x0E26,
  22594. lvocalicbengali: 0x098C,
  22595. lvocalicdeva: 0x090C,
  22596. lvocalicvowelsignbengali: 0x09E2,
  22597. lvocalicvowelsigndeva: 0x0962,
  22598. lxsquare: 0x33D3,
  22599. m: 0x006D,
  22600. mabengali: 0x09AE,
  22601. macron: 0x00AF,
  22602. macronbelowcmb: 0x0331,
  22603. macroncmb: 0x0304,
  22604. macronlowmod: 0x02CD,
  22605. macronmonospace: 0xFFE3,
  22606. macute: 0x1E3F,
  22607. madeva: 0x092E,
  22608. magujarati: 0x0AAE,
  22609. magurmukhi: 0x0A2E,
  22610. mahapakhhebrew: 0x05A4,
  22611. mahapakhlefthebrew: 0x05A4,
  22612. mahiragana: 0x307E,
  22613. maichattawalowleftthai: 0xF895,
  22614. maichattawalowrightthai: 0xF894,
  22615. maichattawathai: 0x0E4B,
  22616. maichattawaupperleftthai: 0xF893,
  22617. maieklowleftthai: 0xF88C,
  22618. maieklowrightthai: 0xF88B,
  22619. maiekthai: 0x0E48,
  22620. maiekupperleftthai: 0xF88A,
  22621. maihanakatleftthai: 0xF884,
  22622. maihanakatthai: 0x0E31,
  22623. maitaikhuleftthai: 0xF889,
  22624. maitaikhuthai: 0x0E47,
  22625. maitholowleftthai: 0xF88F,
  22626. maitholowrightthai: 0xF88E,
  22627. maithothai: 0x0E49,
  22628. maithoupperleftthai: 0xF88D,
  22629. maitrilowleftthai: 0xF892,
  22630. maitrilowrightthai: 0xF891,
  22631. maitrithai: 0x0E4A,
  22632. maitriupperleftthai: 0xF890,
  22633. maiyamokthai: 0x0E46,
  22634. makatakana: 0x30DE,
  22635. makatakanahalfwidth: 0xFF8F,
  22636. male: 0x2642,
  22637. mansyonsquare: 0x3347,
  22638. maqafhebrew: 0x05BE,
  22639. mars: 0x2642,
  22640. masoracirclehebrew: 0x05AF,
  22641. masquare: 0x3383,
  22642. mbopomofo: 0x3107,
  22643. mbsquare: 0x33D4,
  22644. mcircle: 0x24DC,
  22645. mcubedsquare: 0x33A5,
  22646. mdotaccent: 0x1E41,
  22647. mdotbelow: 0x1E43,
  22648. meemarabic: 0x0645,
  22649. meemfinalarabic: 0xFEE2,
  22650. meeminitialarabic: 0xFEE3,
  22651. meemmedialarabic: 0xFEE4,
  22652. meemmeeminitialarabic: 0xFCD1,
  22653. meemmeemisolatedarabic: 0xFC48,
  22654. meetorusquare: 0x334D,
  22655. mehiragana: 0x3081,
  22656. meizierasquare: 0x337E,
  22657. mekatakana: 0x30E1,
  22658. mekatakanahalfwidth: 0xFF92,
  22659. mem: 0x05DE,
  22660. memdagesh: 0xFB3E,
  22661. memdageshhebrew: 0xFB3E,
  22662. memhebrew: 0x05DE,
  22663. menarmenian: 0x0574,
  22664. merkhahebrew: 0x05A5,
  22665. merkhakefulahebrew: 0x05A6,
  22666. merkhakefulalefthebrew: 0x05A6,
  22667. merkhalefthebrew: 0x05A5,
  22668. mhook: 0x0271,
  22669. mhzsquare: 0x3392,
  22670. middledotkatakanahalfwidth: 0xFF65,
  22671. middot: 0x00B7,
  22672. mieumacirclekorean: 0x3272,
  22673. mieumaparenkorean: 0x3212,
  22674. mieumcirclekorean: 0x3264,
  22675. mieumkorean: 0x3141,
  22676. mieumpansioskorean: 0x3170,
  22677. mieumparenkorean: 0x3204,
  22678. mieumpieupkorean: 0x316E,
  22679. mieumsioskorean: 0x316F,
  22680. mihiragana: 0x307F,
  22681. mikatakana: 0x30DF,
  22682. mikatakanahalfwidth: 0xFF90,
  22683. minus: 0x2212,
  22684. minusbelowcmb: 0x0320,
  22685. minuscircle: 0x2296,
  22686. minusmod: 0x02D7,
  22687. minusplus: 0x2213,
  22688. minute: 0x2032,
  22689. miribaarusquare: 0x334A,
  22690. mirisquare: 0x3349,
  22691. mlonglegturned: 0x0270,
  22692. mlsquare: 0x3396,
  22693. mmcubedsquare: 0x33A3,
  22694. mmonospace: 0xFF4D,
  22695. mmsquaredsquare: 0x339F,
  22696. mohiragana: 0x3082,
  22697. mohmsquare: 0x33C1,
  22698. mokatakana: 0x30E2,
  22699. mokatakanahalfwidth: 0xFF93,
  22700. molsquare: 0x33D6,
  22701. momathai: 0x0E21,
  22702. moverssquare: 0x33A7,
  22703. moverssquaredsquare: 0x33A8,
  22704. mparen: 0x24A8,
  22705. mpasquare: 0x33AB,
  22706. mssquare: 0x33B3,
  22707. msuperior: 0xF6EF,
  22708. mturned: 0x026F,
  22709. mu: 0x00B5,
  22710. mu1: 0x00B5,
  22711. muasquare: 0x3382,
  22712. muchgreater: 0x226B,
  22713. muchless: 0x226A,
  22714. mufsquare: 0x338C,
  22715. mugreek: 0x03BC,
  22716. mugsquare: 0x338D,
  22717. muhiragana: 0x3080,
  22718. mukatakana: 0x30E0,
  22719. mukatakanahalfwidth: 0xFF91,
  22720. mulsquare: 0x3395,
  22721. multiply: 0x00D7,
  22722. mumsquare: 0x339B,
  22723. munahhebrew: 0x05A3,
  22724. munahlefthebrew: 0x05A3,
  22725. musicalnote: 0x266A,
  22726. musicalnotedbl: 0x266B,
  22727. musicflatsign: 0x266D,
  22728. musicsharpsign: 0x266F,
  22729. mussquare: 0x33B2,
  22730. muvsquare: 0x33B6,
  22731. muwsquare: 0x33BC,
  22732. mvmegasquare: 0x33B9,
  22733. mvsquare: 0x33B7,
  22734. mwmegasquare: 0x33BF,
  22735. mwsquare: 0x33BD,
  22736. n: 0x006E,
  22737. nabengali: 0x09A8,
  22738. nabla: 0x2207,
  22739. nacute: 0x0144,
  22740. nadeva: 0x0928,
  22741. nagujarati: 0x0AA8,
  22742. nagurmukhi: 0x0A28,
  22743. nahiragana: 0x306A,
  22744. nakatakana: 0x30CA,
  22745. nakatakanahalfwidth: 0xFF85,
  22746. napostrophe: 0x0149,
  22747. nasquare: 0x3381,
  22748. nbopomofo: 0x310B,
  22749. nbspace: 0x00A0,
  22750. ncaron: 0x0148,
  22751. ncedilla: 0x0146,
  22752. ncircle: 0x24DD,
  22753. ncircumflexbelow: 0x1E4B,
  22754. ncommaaccent: 0x0146,
  22755. ndotaccent: 0x1E45,
  22756. ndotbelow: 0x1E47,
  22757. nehiragana: 0x306D,
  22758. nekatakana: 0x30CD,
  22759. nekatakanahalfwidth: 0xFF88,
  22760. newsheqelsign: 0x20AA,
  22761. nfsquare: 0x338B,
  22762. ngabengali: 0x0999,
  22763. ngadeva: 0x0919,
  22764. ngagujarati: 0x0A99,
  22765. ngagurmukhi: 0x0A19,
  22766. ngonguthai: 0x0E07,
  22767. nhiragana: 0x3093,
  22768. nhookleft: 0x0272,
  22769. nhookretroflex: 0x0273,
  22770. nieunacirclekorean: 0x326F,
  22771. nieunaparenkorean: 0x320F,
  22772. nieuncieuckorean: 0x3135,
  22773. nieuncirclekorean: 0x3261,
  22774. nieunhieuhkorean: 0x3136,
  22775. nieunkorean: 0x3134,
  22776. nieunpansioskorean: 0x3168,
  22777. nieunparenkorean: 0x3201,
  22778. nieunsioskorean: 0x3167,
  22779. nieuntikeutkorean: 0x3166,
  22780. nihiragana: 0x306B,
  22781. nikatakana: 0x30CB,
  22782. nikatakanahalfwidth: 0xFF86,
  22783. nikhahitleftthai: 0xF899,
  22784. nikhahitthai: 0x0E4D,
  22785. nine: 0x0039,
  22786. ninearabic: 0x0669,
  22787. ninebengali: 0x09EF,
  22788. ninecircle: 0x2468,
  22789. ninecircleinversesansserif: 0x2792,
  22790. ninedeva: 0x096F,
  22791. ninegujarati: 0x0AEF,
  22792. ninegurmukhi: 0x0A6F,
  22793. ninehackarabic: 0x0669,
  22794. ninehangzhou: 0x3029,
  22795. nineideographicparen: 0x3228,
  22796. nineinferior: 0x2089,
  22797. ninemonospace: 0xFF19,
  22798. nineoldstyle: 0xF739,
  22799. nineparen: 0x247C,
  22800. nineperiod: 0x2490,
  22801. ninepersian: 0x06F9,
  22802. nineroman: 0x2178,
  22803. ninesuperior: 0x2079,
  22804. nineteencircle: 0x2472,
  22805. nineteenparen: 0x2486,
  22806. nineteenperiod: 0x249A,
  22807. ninethai: 0x0E59,
  22808. nj: 0x01CC,
  22809. njecyrillic: 0x045A,
  22810. nkatakana: 0x30F3,
  22811. nkatakanahalfwidth: 0xFF9D,
  22812. nlegrightlong: 0x019E,
  22813. nlinebelow: 0x1E49,
  22814. nmonospace: 0xFF4E,
  22815. nmsquare: 0x339A,
  22816. nnabengali: 0x09A3,
  22817. nnadeva: 0x0923,
  22818. nnagujarati: 0x0AA3,
  22819. nnagurmukhi: 0x0A23,
  22820. nnnadeva: 0x0929,
  22821. nohiragana: 0x306E,
  22822. nokatakana: 0x30CE,
  22823. nokatakanahalfwidth: 0xFF89,
  22824. nonbreakingspace: 0x00A0,
  22825. nonenthai: 0x0E13,
  22826. nonuthai: 0x0E19,
  22827. noonarabic: 0x0646,
  22828. noonfinalarabic: 0xFEE6,
  22829. noonghunnaarabic: 0x06BA,
  22830. noonghunnafinalarabic: 0xFB9F,
  22831. nooninitialarabic: 0xFEE7,
  22832. noonjeeminitialarabic: 0xFCD2,
  22833. noonjeemisolatedarabic: 0xFC4B,
  22834. noonmedialarabic: 0xFEE8,
  22835. noonmeeminitialarabic: 0xFCD5,
  22836. noonmeemisolatedarabic: 0xFC4E,
  22837. noonnoonfinalarabic: 0xFC8D,
  22838. notcontains: 0x220C,
  22839. notelement: 0x2209,
  22840. notelementof: 0x2209,
  22841. notequal: 0x2260,
  22842. notgreater: 0x226F,
  22843. notgreaternorequal: 0x2271,
  22844. notgreaternorless: 0x2279,
  22845. notidentical: 0x2262,
  22846. notless: 0x226E,
  22847. notlessnorequal: 0x2270,
  22848. notparallel: 0x2226,
  22849. notprecedes: 0x2280,
  22850. notsubset: 0x2284,
  22851. notsucceeds: 0x2281,
  22852. notsuperset: 0x2285,
  22853. nowarmenian: 0x0576,
  22854. nparen: 0x24A9,
  22855. nssquare: 0x33B1,
  22856. nsuperior: 0x207F,
  22857. ntilde: 0x00F1,
  22858. nu: 0x03BD,
  22859. nuhiragana: 0x306C,
  22860. nukatakana: 0x30CC,
  22861. nukatakanahalfwidth: 0xFF87,
  22862. nuktabengali: 0x09BC,
  22863. nuktadeva: 0x093C,
  22864. nuktagujarati: 0x0ABC,
  22865. nuktagurmukhi: 0x0A3C,
  22866. numbersign: 0x0023,
  22867. numbersignmonospace: 0xFF03,
  22868. numbersignsmall: 0xFE5F,
  22869. numeralsigngreek: 0x0374,
  22870. numeralsignlowergreek: 0x0375,
  22871. numero: 0x2116,
  22872. nun: 0x05E0,
  22873. nundagesh: 0xFB40,
  22874. nundageshhebrew: 0xFB40,
  22875. nunhebrew: 0x05E0,
  22876. nvsquare: 0x33B5,
  22877. nwsquare: 0x33BB,
  22878. nyabengali: 0x099E,
  22879. nyadeva: 0x091E,
  22880. nyagujarati: 0x0A9E,
  22881. nyagurmukhi: 0x0A1E,
  22882. o: 0x006F,
  22883. oacute: 0x00F3,
  22884. oangthai: 0x0E2D,
  22885. obarred: 0x0275,
  22886. obarredcyrillic: 0x04E9,
  22887. obarreddieresiscyrillic: 0x04EB,
  22888. obengali: 0x0993,
  22889. obopomofo: 0x311B,
  22890. obreve: 0x014F,
  22891. ocandradeva: 0x0911,
  22892. ocandragujarati: 0x0A91,
  22893. ocandravowelsigndeva: 0x0949,
  22894. ocandravowelsigngujarati: 0x0AC9,
  22895. ocaron: 0x01D2,
  22896. ocircle: 0x24DE,
  22897. ocircumflex: 0x00F4,
  22898. ocircumflexacute: 0x1ED1,
  22899. ocircumflexdotbelow: 0x1ED9,
  22900. ocircumflexgrave: 0x1ED3,
  22901. ocircumflexhookabove: 0x1ED5,
  22902. ocircumflextilde: 0x1ED7,
  22903. ocyrillic: 0x043E,
  22904. odblacute: 0x0151,
  22905. odblgrave: 0x020D,
  22906. odeva: 0x0913,
  22907. odieresis: 0x00F6,
  22908. odieresiscyrillic: 0x04E7,
  22909. odotbelow: 0x1ECD,
  22910. oe: 0x0153,
  22911. oekorean: 0x315A,
  22912. ogonek: 0x02DB,
  22913. ogonekcmb: 0x0328,
  22914. ograve: 0x00F2,
  22915. ogujarati: 0x0A93,
  22916. oharmenian: 0x0585,
  22917. ohiragana: 0x304A,
  22918. ohookabove: 0x1ECF,
  22919. ohorn: 0x01A1,
  22920. ohornacute: 0x1EDB,
  22921. ohorndotbelow: 0x1EE3,
  22922. ohorngrave: 0x1EDD,
  22923. ohornhookabove: 0x1EDF,
  22924. ohorntilde: 0x1EE1,
  22925. ohungarumlaut: 0x0151,
  22926. oi: 0x01A3,
  22927. oinvertedbreve: 0x020F,
  22928. okatakana: 0x30AA,
  22929. okatakanahalfwidth: 0xFF75,
  22930. okorean: 0x3157,
  22931. olehebrew: 0x05AB,
  22932. omacron: 0x014D,
  22933. omacronacute: 0x1E53,
  22934. omacrongrave: 0x1E51,
  22935. omdeva: 0x0950,
  22936. omega: 0x03C9,
  22937. omega1: 0x03D6,
  22938. omegacyrillic: 0x0461,
  22939. omegalatinclosed: 0x0277,
  22940. omegaroundcyrillic: 0x047B,
  22941. omegatitlocyrillic: 0x047D,
  22942. omegatonos: 0x03CE,
  22943. omgujarati: 0x0AD0,
  22944. omicron: 0x03BF,
  22945. omicrontonos: 0x03CC,
  22946. omonospace: 0xFF4F,
  22947. one: 0x0031,
  22948. onearabic: 0x0661,
  22949. onebengali: 0x09E7,
  22950. onecircle: 0x2460,
  22951. onecircleinversesansserif: 0x278A,
  22952. onedeva: 0x0967,
  22953. onedotenleader: 0x2024,
  22954. oneeighth: 0x215B,
  22955. onefitted: 0xF6DC,
  22956. onegujarati: 0x0AE7,
  22957. onegurmukhi: 0x0A67,
  22958. onehackarabic: 0x0661,
  22959. onehalf: 0x00BD,
  22960. onehangzhou: 0x3021,
  22961. oneideographicparen: 0x3220,
  22962. oneinferior: 0x2081,
  22963. onemonospace: 0xFF11,
  22964. onenumeratorbengali: 0x09F4,
  22965. oneoldstyle: 0xF731,
  22966. oneparen: 0x2474,
  22967. oneperiod: 0x2488,
  22968. onepersian: 0x06F1,
  22969. onequarter: 0x00BC,
  22970. oneroman: 0x2170,
  22971. onesuperior: 0x00B9,
  22972. onethai: 0x0E51,
  22973. onethird: 0x2153,
  22974. oogonek: 0x01EB,
  22975. oogonekmacron: 0x01ED,
  22976. oogurmukhi: 0x0A13,
  22977. oomatragurmukhi: 0x0A4B,
  22978. oopen: 0x0254,
  22979. oparen: 0x24AA,
  22980. openbullet: 0x25E6,
  22981. option: 0x2325,
  22982. ordfeminine: 0x00AA,
  22983. ordmasculine: 0x00BA,
  22984. orthogonal: 0x221F,
  22985. oshortdeva: 0x0912,
  22986. oshortvowelsigndeva: 0x094A,
  22987. oslash: 0x00F8,
  22988. oslashacute: 0x01FF,
  22989. osmallhiragana: 0x3049,
  22990. osmallkatakana: 0x30A9,
  22991. osmallkatakanahalfwidth: 0xFF6B,
  22992. ostrokeacute: 0x01FF,
  22993. osuperior: 0xF6F0,
  22994. otcyrillic: 0x047F,
  22995. otilde: 0x00F5,
  22996. otildeacute: 0x1E4D,
  22997. otildedieresis: 0x1E4F,
  22998. oubopomofo: 0x3121,
  22999. overline: 0x203E,
  23000. overlinecenterline: 0xFE4A,
  23001. overlinecmb: 0x0305,
  23002. overlinedashed: 0xFE49,
  23003. overlinedblwavy: 0xFE4C,
  23004. overlinewavy: 0xFE4B,
  23005. overscore: 0x00AF,
  23006. ovowelsignbengali: 0x09CB,
  23007. ovowelsigndeva: 0x094B,
  23008. ovowelsigngujarati: 0x0ACB,
  23009. p: 0x0070,
  23010. paampssquare: 0x3380,
  23011. paasentosquare: 0x332B,
  23012. pabengali: 0x09AA,
  23013. pacute: 0x1E55,
  23014. padeva: 0x092A,
  23015. pagedown: 0x21DF,
  23016. pageup: 0x21DE,
  23017. pagujarati: 0x0AAA,
  23018. pagurmukhi: 0x0A2A,
  23019. pahiragana: 0x3071,
  23020. paiyannoithai: 0x0E2F,
  23021. pakatakana: 0x30D1,
  23022. palatalizationcyrilliccmb: 0x0484,
  23023. palochkacyrillic: 0x04C0,
  23024. pansioskorean: 0x317F,
  23025. paragraph: 0x00B6,
  23026. parallel: 0x2225,
  23027. parenleft: 0x0028,
  23028. parenleftaltonearabic: 0xFD3E,
  23029. parenleftbt: 0xF8ED,
  23030. parenleftex: 0xF8EC,
  23031. parenleftinferior: 0x208D,
  23032. parenleftmonospace: 0xFF08,
  23033. parenleftsmall: 0xFE59,
  23034. parenleftsuperior: 0x207D,
  23035. parenlefttp: 0xF8EB,
  23036. parenleftvertical: 0xFE35,
  23037. parenright: 0x0029,
  23038. parenrightaltonearabic: 0xFD3F,
  23039. parenrightbt: 0xF8F8,
  23040. parenrightex: 0xF8F7,
  23041. parenrightinferior: 0x208E,
  23042. parenrightmonospace: 0xFF09,
  23043. parenrightsmall: 0xFE5A,
  23044. parenrightsuperior: 0x207E,
  23045. parenrighttp: 0xF8F6,
  23046. parenrightvertical: 0xFE36,
  23047. partialdiff: 0x2202,
  23048. paseqhebrew: 0x05C0,
  23049. pashtahebrew: 0x0599,
  23050. pasquare: 0x33A9,
  23051. patah: 0x05B7,
  23052. patah11: 0x05B7,
  23053. patah1d: 0x05B7,
  23054. patah2a: 0x05B7,
  23055. patahhebrew: 0x05B7,
  23056. patahnarrowhebrew: 0x05B7,
  23057. patahquarterhebrew: 0x05B7,
  23058. patahwidehebrew: 0x05B7,
  23059. pazerhebrew: 0x05A1,
  23060. pbopomofo: 0x3106,
  23061. pcircle: 0x24DF,
  23062. pdotaccent: 0x1E57,
  23063. pe: 0x05E4,
  23064. pecyrillic: 0x043F,
  23065. pedagesh: 0xFB44,
  23066. pedageshhebrew: 0xFB44,
  23067. peezisquare: 0x333B,
  23068. pefinaldageshhebrew: 0xFB43,
  23069. peharabic: 0x067E,
  23070. peharmenian: 0x057A,
  23071. pehebrew: 0x05E4,
  23072. pehfinalarabic: 0xFB57,
  23073. pehinitialarabic: 0xFB58,
  23074. pehiragana: 0x307A,
  23075. pehmedialarabic: 0xFB59,
  23076. pekatakana: 0x30DA,
  23077. pemiddlehookcyrillic: 0x04A7,
  23078. perafehebrew: 0xFB4E,
  23079. percent: 0x0025,
  23080. percentarabic: 0x066A,
  23081. percentmonospace: 0xFF05,
  23082. percentsmall: 0xFE6A,
  23083. period: 0x002E,
  23084. periodarmenian: 0x0589,
  23085. periodcentered: 0x00B7,
  23086. periodhalfwidth: 0xFF61,
  23087. periodinferior: 0xF6E7,
  23088. periodmonospace: 0xFF0E,
  23089. periodsmall: 0xFE52,
  23090. periodsuperior: 0xF6E8,
  23091. perispomenigreekcmb: 0x0342,
  23092. perpendicular: 0x22A5,
  23093. perthousand: 0x2030,
  23094. peseta: 0x20A7,
  23095. pfsquare: 0x338A,
  23096. phabengali: 0x09AB,
  23097. phadeva: 0x092B,
  23098. phagujarati: 0x0AAB,
  23099. phagurmukhi: 0x0A2B,
  23100. phi: 0x03C6,
  23101. phi1: 0x03D5,
  23102. phieuphacirclekorean: 0x327A,
  23103. phieuphaparenkorean: 0x321A,
  23104. phieuphcirclekorean: 0x326C,
  23105. phieuphkorean: 0x314D,
  23106. phieuphparenkorean: 0x320C,
  23107. philatin: 0x0278,
  23108. phinthuthai: 0x0E3A,
  23109. phisymbolgreek: 0x03D5,
  23110. phook: 0x01A5,
  23111. phophanthai: 0x0E1E,
  23112. phophungthai: 0x0E1C,
  23113. phosamphaothai: 0x0E20,
  23114. pi: 0x03C0,
  23115. pieupacirclekorean: 0x3273,
  23116. pieupaparenkorean: 0x3213,
  23117. pieupcieuckorean: 0x3176,
  23118. pieupcirclekorean: 0x3265,
  23119. pieupkiyeokkorean: 0x3172,
  23120. pieupkorean: 0x3142,
  23121. pieupparenkorean: 0x3205,
  23122. pieupsioskiyeokkorean: 0x3174,
  23123. pieupsioskorean: 0x3144,
  23124. pieupsiostikeutkorean: 0x3175,
  23125. pieupthieuthkorean: 0x3177,
  23126. pieuptikeutkorean: 0x3173,
  23127. pihiragana: 0x3074,
  23128. pikatakana: 0x30D4,
  23129. pisymbolgreek: 0x03D6,
  23130. piwrarmenian: 0x0583,
  23131. plus: 0x002B,
  23132. plusbelowcmb: 0x031F,
  23133. pluscircle: 0x2295,
  23134. plusminus: 0x00B1,
  23135. plusmod: 0x02D6,
  23136. plusmonospace: 0xFF0B,
  23137. plussmall: 0xFE62,
  23138. plussuperior: 0x207A,
  23139. pmonospace: 0xFF50,
  23140. pmsquare: 0x33D8,
  23141. pohiragana: 0x307D,
  23142. pointingindexdownwhite: 0x261F,
  23143. pointingindexleftwhite: 0x261C,
  23144. pointingindexrightwhite: 0x261E,
  23145. pointingindexupwhite: 0x261D,
  23146. pokatakana: 0x30DD,
  23147. poplathai: 0x0E1B,
  23148. postalmark: 0x3012,
  23149. postalmarkface: 0x3020,
  23150. pparen: 0x24AB,
  23151. precedes: 0x227A,
  23152. prescription: 0x211E,
  23153. primemod: 0x02B9,
  23154. primereversed: 0x2035,
  23155. product: 0x220F,
  23156. projective: 0x2305,
  23157. prolongedkana: 0x30FC,
  23158. propellor: 0x2318,
  23159. propersubset: 0x2282,
  23160. propersuperset: 0x2283,
  23161. proportion: 0x2237,
  23162. proportional: 0x221D,
  23163. psi: 0x03C8,
  23164. psicyrillic: 0x0471,
  23165. psilipneumatacyrilliccmb: 0x0486,
  23166. pssquare: 0x33B0,
  23167. puhiragana: 0x3077,
  23168. pukatakana: 0x30D7,
  23169. pvsquare: 0x33B4,
  23170. pwsquare: 0x33BA,
  23171. q: 0x0071,
  23172. qadeva: 0x0958,
  23173. qadmahebrew: 0x05A8,
  23174. qafarabic: 0x0642,
  23175. qaffinalarabic: 0xFED6,
  23176. qafinitialarabic: 0xFED7,
  23177. qafmedialarabic: 0xFED8,
  23178. qamats: 0x05B8,
  23179. qamats10: 0x05B8,
  23180. qamats1a: 0x05B8,
  23181. qamats1c: 0x05B8,
  23182. qamats27: 0x05B8,
  23183. qamats29: 0x05B8,
  23184. qamats33: 0x05B8,
  23185. qamatsde: 0x05B8,
  23186. qamatshebrew: 0x05B8,
  23187. qamatsnarrowhebrew: 0x05B8,
  23188. qamatsqatanhebrew: 0x05B8,
  23189. qamatsqatannarrowhebrew: 0x05B8,
  23190. qamatsqatanquarterhebrew: 0x05B8,
  23191. qamatsqatanwidehebrew: 0x05B8,
  23192. qamatsquarterhebrew: 0x05B8,
  23193. qamatswidehebrew: 0x05B8,
  23194. qarneyparahebrew: 0x059F,
  23195. qbopomofo: 0x3111,
  23196. qcircle: 0x24E0,
  23197. qhook: 0x02A0,
  23198. qmonospace: 0xFF51,
  23199. qof: 0x05E7,
  23200. qofdagesh: 0xFB47,
  23201. qofdageshhebrew: 0xFB47,
  23202. qofhebrew: 0x05E7,
  23203. qparen: 0x24AC,
  23204. quarternote: 0x2669,
  23205. qubuts: 0x05BB,
  23206. qubuts18: 0x05BB,
  23207. qubuts25: 0x05BB,
  23208. qubuts31: 0x05BB,
  23209. qubutshebrew: 0x05BB,
  23210. qubutsnarrowhebrew: 0x05BB,
  23211. qubutsquarterhebrew: 0x05BB,
  23212. qubutswidehebrew: 0x05BB,
  23213. question: 0x003F,
  23214. questionarabic: 0x061F,
  23215. questionarmenian: 0x055E,
  23216. questiondown: 0x00BF,
  23217. questiondownsmall: 0xF7BF,
  23218. questiongreek: 0x037E,
  23219. questionmonospace: 0xFF1F,
  23220. questionsmall: 0xF73F,
  23221. quotedbl: 0x0022,
  23222. quotedblbase: 0x201E,
  23223. quotedblleft: 0x201C,
  23224. quotedblmonospace: 0xFF02,
  23225. quotedblprime: 0x301E,
  23226. quotedblprimereversed: 0x301D,
  23227. quotedblright: 0x201D,
  23228. quoteleft: 0x2018,
  23229. quoteleftreversed: 0x201B,
  23230. quotereversed: 0x201B,
  23231. quoteright: 0x2019,
  23232. quoterightn: 0x0149,
  23233. quotesinglbase: 0x201A,
  23234. quotesingle: 0x0027,
  23235. quotesinglemonospace: 0xFF07,
  23236. r: 0x0072,
  23237. raarmenian: 0x057C,
  23238. rabengali: 0x09B0,
  23239. racute: 0x0155,
  23240. radeva: 0x0930,
  23241. radical: 0x221A,
  23242. radicalex: 0xF8E5,
  23243. radoverssquare: 0x33AE,
  23244. radoverssquaredsquare: 0x33AF,
  23245. radsquare: 0x33AD,
  23246. rafe: 0x05BF,
  23247. rafehebrew: 0x05BF,
  23248. ragujarati: 0x0AB0,
  23249. ragurmukhi: 0x0A30,
  23250. rahiragana: 0x3089,
  23251. rakatakana: 0x30E9,
  23252. rakatakanahalfwidth: 0xFF97,
  23253. ralowerdiagonalbengali: 0x09F1,
  23254. ramiddlediagonalbengali: 0x09F0,
  23255. ramshorn: 0x0264,
  23256. ratio: 0x2236,
  23257. rbopomofo: 0x3116,
  23258. rcaron: 0x0159,
  23259. rcedilla: 0x0157,
  23260. rcircle: 0x24E1,
  23261. rcommaaccent: 0x0157,
  23262. rdblgrave: 0x0211,
  23263. rdotaccent: 0x1E59,
  23264. rdotbelow: 0x1E5B,
  23265. rdotbelowmacron: 0x1E5D,
  23266. referencemark: 0x203B,
  23267. reflexsubset: 0x2286,
  23268. reflexsuperset: 0x2287,
  23269. registered: 0x00AE,
  23270. registersans: 0xF8E8,
  23271. registerserif: 0xF6DA,
  23272. reharabic: 0x0631,
  23273. reharmenian: 0x0580,
  23274. rehfinalarabic: 0xFEAE,
  23275. rehiragana: 0x308C,
  23276. rekatakana: 0x30EC,
  23277. rekatakanahalfwidth: 0xFF9A,
  23278. resh: 0x05E8,
  23279. reshdageshhebrew: 0xFB48,
  23280. reshhebrew: 0x05E8,
  23281. reversedtilde: 0x223D,
  23282. reviahebrew: 0x0597,
  23283. reviamugrashhebrew: 0x0597,
  23284. revlogicalnot: 0x2310,
  23285. rfishhook: 0x027E,
  23286. rfishhookreversed: 0x027F,
  23287. rhabengali: 0x09DD,
  23288. rhadeva: 0x095D,
  23289. rho: 0x03C1,
  23290. rhook: 0x027D,
  23291. rhookturned: 0x027B,
  23292. rhookturnedsuperior: 0x02B5,
  23293. rhosymbolgreek: 0x03F1,
  23294. rhotichookmod: 0x02DE,
  23295. rieulacirclekorean: 0x3271,
  23296. rieulaparenkorean: 0x3211,
  23297. rieulcirclekorean: 0x3263,
  23298. rieulhieuhkorean: 0x3140,
  23299. rieulkiyeokkorean: 0x313A,
  23300. rieulkiyeoksioskorean: 0x3169,
  23301. rieulkorean: 0x3139,
  23302. rieulmieumkorean: 0x313B,
  23303. rieulpansioskorean: 0x316C,
  23304. rieulparenkorean: 0x3203,
  23305. rieulphieuphkorean: 0x313F,
  23306. rieulpieupkorean: 0x313C,
  23307. rieulpieupsioskorean: 0x316B,
  23308. rieulsioskorean: 0x313D,
  23309. rieulthieuthkorean: 0x313E,
  23310. rieultikeutkorean: 0x316A,
  23311. rieulyeorinhieuhkorean: 0x316D,
  23312. rightangle: 0x221F,
  23313. righttackbelowcmb: 0x0319,
  23314. righttriangle: 0x22BF,
  23315. rihiragana: 0x308A,
  23316. rikatakana: 0x30EA,
  23317. rikatakanahalfwidth: 0xFF98,
  23318. ring: 0x02DA,
  23319. ringbelowcmb: 0x0325,
  23320. ringcmb: 0x030A,
  23321. ringhalfleft: 0x02BF,
  23322. ringhalfleftarmenian: 0x0559,
  23323. ringhalfleftbelowcmb: 0x031C,
  23324. ringhalfleftcentered: 0x02D3,
  23325. ringhalfright: 0x02BE,
  23326. ringhalfrightbelowcmb: 0x0339,
  23327. ringhalfrightcentered: 0x02D2,
  23328. rinvertedbreve: 0x0213,
  23329. rittorusquare: 0x3351,
  23330. rlinebelow: 0x1E5F,
  23331. rlongleg: 0x027C,
  23332. rlonglegturned: 0x027A,
  23333. rmonospace: 0xFF52,
  23334. rohiragana: 0x308D,
  23335. rokatakana: 0x30ED,
  23336. rokatakanahalfwidth: 0xFF9B,
  23337. roruathai: 0x0E23,
  23338. rparen: 0x24AD,
  23339. rrabengali: 0x09DC,
  23340. rradeva: 0x0931,
  23341. rragurmukhi: 0x0A5C,
  23342. rreharabic: 0x0691,
  23343. rrehfinalarabic: 0xFB8D,
  23344. rrvocalicbengali: 0x09E0,
  23345. rrvocalicdeva: 0x0960,
  23346. rrvocalicgujarati: 0x0AE0,
  23347. rrvocalicvowelsignbengali: 0x09C4,
  23348. rrvocalicvowelsigndeva: 0x0944,
  23349. rrvocalicvowelsigngujarati: 0x0AC4,
  23350. rsuperior: 0xF6F1,
  23351. rtblock: 0x2590,
  23352. rturned: 0x0279,
  23353. rturnedsuperior: 0x02B4,
  23354. ruhiragana: 0x308B,
  23355. rukatakana: 0x30EB,
  23356. rukatakanahalfwidth: 0xFF99,
  23357. rupeemarkbengali: 0x09F2,
  23358. rupeesignbengali: 0x09F3,
  23359. rupiah: 0xF6DD,
  23360. ruthai: 0x0E24,
  23361. rvocalicbengali: 0x098B,
  23362. rvocalicdeva: 0x090B,
  23363. rvocalicgujarati: 0x0A8B,
  23364. rvocalicvowelsignbengali: 0x09C3,
  23365. rvocalicvowelsigndeva: 0x0943,
  23366. rvocalicvowelsigngujarati: 0x0AC3,
  23367. s: 0x0073,
  23368. sabengali: 0x09B8,
  23369. sacute: 0x015B,
  23370. sacutedotaccent: 0x1E65,
  23371. sadarabic: 0x0635,
  23372. sadeva: 0x0938,
  23373. sadfinalarabic: 0xFEBA,
  23374. sadinitialarabic: 0xFEBB,
  23375. sadmedialarabic: 0xFEBC,
  23376. sagujarati: 0x0AB8,
  23377. sagurmukhi: 0x0A38,
  23378. sahiragana: 0x3055,
  23379. sakatakana: 0x30B5,
  23380. sakatakanahalfwidth: 0xFF7B,
  23381. sallallahoualayhewasallamarabic: 0xFDFA,
  23382. samekh: 0x05E1,
  23383. samekhdagesh: 0xFB41,
  23384. samekhdageshhebrew: 0xFB41,
  23385. samekhhebrew: 0x05E1,
  23386. saraaathai: 0x0E32,
  23387. saraaethai: 0x0E41,
  23388. saraaimaimalaithai: 0x0E44,
  23389. saraaimaimuanthai: 0x0E43,
  23390. saraamthai: 0x0E33,
  23391. saraathai: 0x0E30,
  23392. saraethai: 0x0E40,
  23393. saraiileftthai: 0xF886,
  23394. saraiithai: 0x0E35,
  23395. saraileftthai: 0xF885,
  23396. saraithai: 0x0E34,
  23397. saraothai: 0x0E42,
  23398. saraueeleftthai: 0xF888,
  23399. saraueethai: 0x0E37,
  23400. saraueleftthai: 0xF887,
  23401. sarauethai: 0x0E36,
  23402. sarauthai: 0x0E38,
  23403. sarauuthai: 0x0E39,
  23404. sbopomofo: 0x3119,
  23405. scaron: 0x0161,
  23406. scarondotaccent: 0x1E67,
  23407. scedilla: 0x015F,
  23408. schwa: 0x0259,
  23409. schwacyrillic: 0x04D9,
  23410. schwadieresiscyrillic: 0x04DB,
  23411. schwahook: 0x025A,
  23412. scircle: 0x24E2,
  23413. scircumflex: 0x015D,
  23414. scommaaccent: 0x0219,
  23415. sdotaccent: 0x1E61,
  23416. sdotbelow: 0x1E63,
  23417. sdotbelowdotaccent: 0x1E69,
  23418. seagullbelowcmb: 0x033C,
  23419. second: 0x2033,
  23420. secondtonechinese: 0x02CA,
  23421. section: 0x00A7,
  23422. seenarabic: 0x0633,
  23423. seenfinalarabic: 0xFEB2,
  23424. seeninitialarabic: 0xFEB3,
  23425. seenmedialarabic: 0xFEB4,
  23426. segol: 0x05B6,
  23427. segol13: 0x05B6,
  23428. segol1f: 0x05B6,
  23429. segol2c: 0x05B6,
  23430. segolhebrew: 0x05B6,
  23431. segolnarrowhebrew: 0x05B6,
  23432. segolquarterhebrew: 0x05B6,
  23433. segoltahebrew: 0x0592,
  23434. segolwidehebrew: 0x05B6,
  23435. seharmenian: 0x057D,
  23436. sehiragana: 0x305B,
  23437. sekatakana: 0x30BB,
  23438. sekatakanahalfwidth: 0xFF7E,
  23439. semicolon: 0x003B,
  23440. semicolonarabic: 0x061B,
  23441. semicolonmonospace: 0xFF1B,
  23442. semicolonsmall: 0xFE54,
  23443. semivoicedmarkkana: 0x309C,
  23444. semivoicedmarkkanahalfwidth: 0xFF9F,
  23445. sentisquare: 0x3322,
  23446. sentosquare: 0x3323,
  23447. seven: 0x0037,
  23448. sevenarabic: 0x0667,
  23449. sevenbengali: 0x09ED,
  23450. sevencircle: 0x2466,
  23451. sevencircleinversesansserif: 0x2790,
  23452. sevendeva: 0x096D,
  23453. seveneighths: 0x215E,
  23454. sevengujarati: 0x0AED,
  23455. sevengurmukhi: 0x0A6D,
  23456. sevenhackarabic: 0x0667,
  23457. sevenhangzhou: 0x3027,
  23458. sevenideographicparen: 0x3226,
  23459. seveninferior: 0x2087,
  23460. sevenmonospace: 0xFF17,
  23461. sevenoldstyle: 0xF737,
  23462. sevenparen: 0x247A,
  23463. sevenperiod: 0x248E,
  23464. sevenpersian: 0x06F7,
  23465. sevenroman: 0x2176,
  23466. sevensuperior: 0x2077,
  23467. seventeencircle: 0x2470,
  23468. seventeenparen: 0x2484,
  23469. seventeenperiod: 0x2498,
  23470. seventhai: 0x0E57,
  23471. sfthyphen: 0x00AD,
  23472. shaarmenian: 0x0577,
  23473. shabengali: 0x09B6,
  23474. shacyrillic: 0x0448,
  23475. shaddaarabic: 0x0651,
  23476. shaddadammaarabic: 0xFC61,
  23477. shaddadammatanarabic: 0xFC5E,
  23478. shaddafathaarabic: 0xFC60,
  23479. shaddakasraarabic: 0xFC62,
  23480. shaddakasratanarabic: 0xFC5F,
  23481. shade: 0x2592,
  23482. shadedark: 0x2593,
  23483. shadelight: 0x2591,
  23484. shademedium: 0x2592,
  23485. shadeva: 0x0936,
  23486. shagujarati: 0x0AB6,
  23487. shagurmukhi: 0x0A36,
  23488. shalshelethebrew: 0x0593,
  23489. shbopomofo: 0x3115,
  23490. shchacyrillic: 0x0449,
  23491. sheenarabic: 0x0634,
  23492. sheenfinalarabic: 0xFEB6,
  23493. sheeninitialarabic: 0xFEB7,
  23494. sheenmedialarabic: 0xFEB8,
  23495. sheicoptic: 0x03E3,
  23496. sheqel: 0x20AA,
  23497. sheqelhebrew: 0x20AA,
  23498. sheva: 0x05B0,
  23499. sheva115: 0x05B0,
  23500. sheva15: 0x05B0,
  23501. sheva22: 0x05B0,
  23502. sheva2e: 0x05B0,
  23503. shevahebrew: 0x05B0,
  23504. shevanarrowhebrew: 0x05B0,
  23505. shevaquarterhebrew: 0x05B0,
  23506. shevawidehebrew: 0x05B0,
  23507. shhacyrillic: 0x04BB,
  23508. shimacoptic: 0x03ED,
  23509. shin: 0x05E9,
  23510. shindagesh: 0xFB49,
  23511. shindageshhebrew: 0xFB49,
  23512. shindageshshindot: 0xFB2C,
  23513. shindageshshindothebrew: 0xFB2C,
  23514. shindageshsindot: 0xFB2D,
  23515. shindageshsindothebrew: 0xFB2D,
  23516. shindothebrew: 0x05C1,
  23517. shinhebrew: 0x05E9,
  23518. shinshindot: 0xFB2A,
  23519. shinshindothebrew: 0xFB2A,
  23520. shinsindot: 0xFB2B,
  23521. shinsindothebrew: 0xFB2B,
  23522. shook: 0x0282,
  23523. sigma: 0x03C3,
  23524. sigma1: 0x03C2,
  23525. sigmafinal: 0x03C2,
  23526. sigmalunatesymbolgreek: 0x03F2,
  23527. sihiragana: 0x3057,
  23528. sikatakana: 0x30B7,
  23529. sikatakanahalfwidth: 0xFF7C,
  23530. siluqhebrew: 0x05BD,
  23531. siluqlefthebrew: 0x05BD,
  23532. similar: 0x223C,
  23533. sindothebrew: 0x05C2,
  23534. siosacirclekorean: 0x3274,
  23535. siosaparenkorean: 0x3214,
  23536. sioscieuckorean: 0x317E,
  23537. sioscirclekorean: 0x3266,
  23538. sioskiyeokkorean: 0x317A,
  23539. sioskorean: 0x3145,
  23540. siosnieunkorean: 0x317B,
  23541. siosparenkorean: 0x3206,
  23542. siospieupkorean: 0x317D,
  23543. siostikeutkorean: 0x317C,
  23544. six: 0x0036,
  23545. sixarabic: 0x0666,
  23546. sixbengali: 0x09EC,
  23547. sixcircle: 0x2465,
  23548. sixcircleinversesansserif: 0x278F,
  23549. sixdeva: 0x096C,
  23550. sixgujarati: 0x0AEC,
  23551. sixgurmukhi: 0x0A6C,
  23552. sixhackarabic: 0x0666,
  23553. sixhangzhou: 0x3026,
  23554. sixideographicparen: 0x3225,
  23555. sixinferior: 0x2086,
  23556. sixmonospace: 0xFF16,
  23557. sixoldstyle: 0xF736,
  23558. sixparen: 0x2479,
  23559. sixperiod: 0x248D,
  23560. sixpersian: 0x06F6,
  23561. sixroman: 0x2175,
  23562. sixsuperior: 0x2076,
  23563. sixteencircle: 0x246F,
  23564. sixteencurrencydenominatorbengali: 0x09F9,
  23565. sixteenparen: 0x2483,
  23566. sixteenperiod: 0x2497,
  23567. sixthai: 0x0E56,
  23568. slash: 0x002F,
  23569. slashmonospace: 0xFF0F,
  23570. slong: 0x017F,
  23571. slongdotaccent: 0x1E9B,
  23572. smileface: 0x263A,
  23573. smonospace: 0xFF53,
  23574. sofpasuqhebrew: 0x05C3,
  23575. softhyphen: 0x00AD,
  23576. softsigncyrillic: 0x044C,
  23577. sohiragana: 0x305D,
  23578. sokatakana: 0x30BD,
  23579. sokatakanahalfwidth: 0xFF7F,
  23580. soliduslongoverlaycmb: 0x0338,
  23581. solidusshortoverlaycmb: 0x0337,
  23582. sorusithai: 0x0E29,
  23583. sosalathai: 0x0E28,
  23584. sosothai: 0x0E0B,
  23585. sosuathai: 0x0E2A,
  23586. space: 0x0020,
  23587. spacehackarabic: 0x0020,
  23588. spade: 0x2660,
  23589. spadesuitblack: 0x2660,
  23590. spadesuitwhite: 0x2664,
  23591. sparen: 0x24AE,
  23592. squarebelowcmb: 0x033B,
  23593. squarecc: 0x33C4,
  23594. squarecm: 0x339D,
  23595. squarediagonalcrosshatchfill: 0x25A9,
  23596. squarehorizontalfill: 0x25A4,
  23597. squarekg: 0x338F,
  23598. squarekm: 0x339E,
  23599. squarekmcapital: 0x33CE,
  23600. squareln: 0x33D1,
  23601. squarelog: 0x33D2,
  23602. squaremg: 0x338E,
  23603. squaremil: 0x33D5,
  23604. squaremm: 0x339C,
  23605. squaremsquared: 0x33A1,
  23606. squareorthogonalcrosshatchfill: 0x25A6,
  23607. squareupperlefttolowerrightfill: 0x25A7,
  23608. squareupperrighttolowerleftfill: 0x25A8,
  23609. squareverticalfill: 0x25A5,
  23610. squarewhitewithsmallblack: 0x25A3,
  23611. srsquare: 0x33DB,
  23612. ssabengali: 0x09B7,
  23613. ssadeva: 0x0937,
  23614. ssagujarati: 0x0AB7,
  23615. ssangcieuckorean: 0x3149,
  23616. ssanghieuhkorean: 0x3185,
  23617. ssangieungkorean: 0x3180,
  23618. ssangkiyeokkorean: 0x3132,
  23619. ssangnieunkorean: 0x3165,
  23620. ssangpieupkorean: 0x3143,
  23621. ssangsioskorean: 0x3146,
  23622. ssangtikeutkorean: 0x3138,
  23623. ssuperior: 0xF6F2,
  23624. sterling: 0x00A3,
  23625. sterlingmonospace: 0xFFE1,
  23626. strokelongoverlaycmb: 0x0336,
  23627. strokeshortoverlaycmb: 0x0335,
  23628. subset: 0x2282,
  23629. subsetnotequal: 0x228A,
  23630. subsetorequal: 0x2286,
  23631. succeeds: 0x227B,
  23632. suchthat: 0x220B,
  23633. suhiragana: 0x3059,
  23634. sukatakana: 0x30B9,
  23635. sukatakanahalfwidth: 0xFF7D,
  23636. sukunarabic: 0x0652,
  23637. summation: 0x2211,
  23638. sun: 0x263C,
  23639. superset: 0x2283,
  23640. supersetnotequal: 0x228B,
  23641. supersetorequal: 0x2287,
  23642. svsquare: 0x33DC,
  23643. syouwaerasquare: 0x337C,
  23644. t: 0x0074,
  23645. tabengali: 0x09A4,
  23646. tackdown: 0x22A4,
  23647. tackleft: 0x22A3,
  23648. tadeva: 0x0924,
  23649. tagujarati: 0x0AA4,
  23650. tagurmukhi: 0x0A24,
  23651. taharabic: 0x0637,
  23652. tahfinalarabic: 0xFEC2,
  23653. tahinitialarabic: 0xFEC3,
  23654. tahiragana: 0x305F,
  23655. tahmedialarabic: 0xFEC4,
  23656. taisyouerasquare: 0x337D,
  23657. takatakana: 0x30BF,
  23658. takatakanahalfwidth: 0xFF80,
  23659. tatweelarabic: 0x0640,
  23660. tau: 0x03C4,
  23661. tav: 0x05EA,
  23662. tavdages: 0xFB4A,
  23663. tavdagesh: 0xFB4A,
  23664. tavdageshhebrew: 0xFB4A,
  23665. tavhebrew: 0x05EA,
  23666. tbar: 0x0167,
  23667. tbopomofo: 0x310A,
  23668. tcaron: 0x0165,
  23669. tccurl: 0x02A8,
  23670. tcedilla: 0x0163,
  23671. tcheharabic: 0x0686,
  23672. tchehfinalarabic: 0xFB7B,
  23673. tchehinitialarabic: 0xFB7C,
  23674. tchehmedialarabic: 0xFB7D,
  23675. tcircle: 0x24E3,
  23676. tcircumflexbelow: 0x1E71,
  23677. tcommaaccent: 0x0163,
  23678. tdieresis: 0x1E97,
  23679. tdotaccent: 0x1E6B,
  23680. tdotbelow: 0x1E6D,
  23681. tecyrillic: 0x0442,
  23682. tedescendercyrillic: 0x04AD,
  23683. teharabic: 0x062A,
  23684. tehfinalarabic: 0xFE96,
  23685. tehhahinitialarabic: 0xFCA2,
  23686. tehhahisolatedarabic: 0xFC0C,
  23687. tehinitialarabic: 0xFE97,
  23688. tehiragana: 0x3066,
  23689. tehjeeminitialarabic: 0xFCA1,
  23690. tehjeemisolatedarabic: 0xFC0B,
  23691. tehmarbutaarabic: 0x0629,
  23692. tehmarbutafinalarabic: 0xFE94,
  23693. tehmedialarabic: 0xFE98,
  23694. tehmeeminitialarabic: 0xFCA4,
  23695. tehmeemisolatedarabic: 0xFC0E,
  23696. tehnoonfinalarabic: 0xFC73,
  23697. tekatakana: 0x30C6,
  23698. tekatakanahalfwidth: 0xFF83,
  23699. telephone: 0x2121,
  23700. telephoneblack: 0x260E,
  23701. telishagedolahebrew: 0x05A0,
  23702. telishaqetanahebrew: 0x05A9,
  23703. tencircle: 0x2469,
  23704. tenideographicparen: 0x3229,
  23705. tenparen: 0x247D,
  23706. tenperiod: 0x2491,
  23707. tenroman: 0x2179,
  23708. tesh: 0x02A7,
  23709. tet: 0x05D8,
  23710. tetdagesh: 0xFB38,
  23711. tetdageshhebrew: 0xFB38,
  23712. tethebrew: 0x05D8,
  23713. tetsecyrillic: 0x04B5,
  23714. tevirhebrew: 0x059B,
  23715. tevirlefthebrew: 0x059B,
  23716. thabengali: 0x09A5,
  23717. thadeva: 0x0925,
  23718. thagujarati: 0x0AA5,
  23719. thagurmukhi: 0x0A25,
  23720. thalarabic: 0x0630,
  23721. thalfinalarabic: 0xFEAC,
  23722. thanthakhatlowleftthai: 0xF898,
  23723. thanthakhatlowrightthai: 0xF897,
  23724. thanthakhatthai: 0x0E4C,
  23725. thanthakhatupperleftthai: 0xF896,
  23726. theharabic: 0x062B,
  23727. thehfinalarabic: 0xFE9A,
  23728. thehinitialarabic: 0xFE9B,
  23729. thehmedialarabic: 0xFE9C,
  23730. thereexists: 0x2203,
  23731. therefore: 0x2234,
  23732. theta: 0x03B8,
  23733. theta1: 0x03D1,
  23734. thetasymbolgreek: 0x03D1,
  23735. thieuthacirclekorean: 0x3279,
  23736. thieuthaparenkorean: 0x3219,
  23737. thieuthcirclekorean: 0x326B,
  23738. thieuthkorean: 0x314C,
  23739. thieuthparenkorean: 0x320B,
  23740. thirteencircle: 0x246C,
  23741. thirteenparen: 0x2480,
  23742. thirteenperiod: 0x2494,
  23743. thonangmonthothai: 0x0E11,
  23744. thook: 0x01AD,
  23745. thophuthaothai: 0x0E12,
  23746. thorn: 0x00FE,
  23747. thothahanthai: 0x0E17,
  23748. thothanthai: 0x0E10,
  23749. thothongthai: 0x0E18,
  23750. thothungthai: 0x0E16,
  23751. thousandcyrillic: 0x0482,
  23752. thousandsseparatorarabic: 0x066C,
  23753. thousandsseparatorpersian: 0x066C,
  23754. three: 0x0033,
  23755. threearabic: 0x0663,
  23756. threebengali: 0x09E9,
  23757. threecircle: 0x2462,
  23758. threecircleinversesansserif: 0x278C,
  23759. threedeva: 0x0969,
  23760. threeeighths: 0x215C,
  23761. threegujarati: 0x0AE9,
  23762. threegurmukhi: 0x0A69,
  23763. threehackarabic: 0x0663,
  23764. threehangzhou: 0x3023,
  23765. threeideographicparen: 0x3222,
  23766. threeinferior: 0x2083,
  23767. threemonospace: 0xFF13,
  23768. threenumeratorbengali: 0x09F6,
  23769. threeoldstyle: 0xF733,
  23770. threeparen: 0x2476,
  23771. threeperiod: 0x248A,
  23772. threepersian: 0x06F3,
  23773. threequarters: 0x00BE,
  23774. threequartersemdash: 0xF6DE,
  23775. threeroman: 0x2172,
  23776. threesuperior: 0x00B3,
  23777. threethai: 0x0E53,
  23778. thzsquare: 0x3394,
  23779. tihiragana: 0x3061,
  23780. tikatakana: 0x30C1,
  23781. tikatakanahalfwidth: 0xFF81,
  23782. tikeutacirclekorean: 0x3270,
  23783. tikeutaparenkorean: 0x3210,
  23784. tikeutcirclekorean: 0x3262,
  23785. tikeutkorean: 0x3137,
  23786. tikeutparenkorean: 0x3202,
  23787. tilde: 0x02DC,
  23788. tildebelowcmb: 0x0330,
  23789. tildecmb: 0x0303,
  23790. tildecomb: 0x0303,
  23791. tildedoublecmb: 0x0360,
  23792. tildeoperator: 0x223C,
  23793. tildeoverlaycmb: 0x0334,
  23794. tildeverticalcmb: 0x033E,
  23795. timescircle: 0x2297,
  23796. tipehahebrew: 0x0596,
  23797. tipehalefthebrew: 0x0596,
  23798. tippigurmukhi: 0x0A70,
  23799. titlocyrilliccmb: 0x0483,
  23800. tiwnarmenian: 0x057F,
  23801. tlinebelow: 0x1E6F,
  23802. tmonospace: 0xFF54,
  23803. toarmenian: 0x0569,
  23804. tohiragana: 0x3068,
  23805. tokatakana: 0x30C8,
  23806. tokatakanahalfwidth: 0xFF84,
  23807. tonebarextrahighmod: 0x02E5,
  23808. tonebarextralowmod: 0x02E9,
  23809. tonebarhighmod: 0x02E6,
  23810. tonebarlowmod: 0x02E8,
  23811. tonebarmidmod: 0x02E7,
  23812. tonefive: 0x01BD,
  23813. tonesix: 0x0185,
  23814. tonetwo: 0x01A8,
  23815. tonos: 0x0384,
  23816. tonsquare: 0x3327,
  23817. topatakthai: 0x0E0F,
  23818. tortoiseshellbracketleft: 0x3014,
  23819. tortoiseshellbracketleftsmall: 0xFE5D,
  23820. tortoiseshellbracketleftvertical: 0xFE39,
  23821. tortoiseshellbracketright: 0x3015,
  23822. tortoiseshellbracketrightsmall: 0xFE5E,
  23823. tortoiseshellbracketrightvertical: 0xFE3A,
  23824. totaothai: 0x0E15,
  23825. tpalatalhook: 0x01AB,
  23826. tparen: 0x24AF,
  23827. trademark: 0x2122,
  23828. trademarksans: 0xF8EA,
  23829. trademarkserif: 0xF6DB,
  23830. tretroflexhook: 0x0288,
  23831. triagdn: 0x25BC,
  23832. triaglf: 0x25C4,
  23833. triagrt: 0x25BA,
  23834. triagup: 0x25B2,
  23835. ts: 0x02A6,
  23836. tsadi: 0x05E6,
  23837. tsadidagesh: 0xFB46,
  23838. tsadidageshhebrew: 0xFB46,
  23839. tsadihebrew: 0x05E6,
  23840. tsecyrillic: 0x0446,
  23841. tsere: 0x05B5,
  23842. tsere12: 0x05B5,
  23843. tsere1e: 0x05B5,
  23844. tsere2b: 0x05B5,
  23845. tserehebrew: 0x05B5,
  23846. tserenarrowhebrew: 0x05B5,
  23847. tserequarterhebrew: 0x05B5,
  23848. tserewidehebrew: 0x05B5,
  23849. tshecyrillic: 0x045B,
  23850. tsuperior: 0xF6F3,
  23851. ttabengali: 0x099F,
  23852. ttadeva: 0x091F,
  23853. ttagujarati: 0x0A9F,
  23854. ttagurmukhi: 0x0A1F,
  23855. tteharabic: 0x0679,
  23856. ttehfinalarabic: 0xFB67,
  23857. ttehinitialarabic: 0xFB68,
  23858. ttehmedialarabic: 0xFB69,
  23859. tthabengali: 0x09A0,
  23860. tthadeva: 0x0920,
  23861. tthagujarati: 0x0AA0,
  23862. tthagurmukhi: 0x0A20,
  23863. tturned: 0x0287,
  23864. tuhiragana: 0x3064,
  23865. tukatakana: 0x30C4,
  23866. tukatakanahalfwidth: 0xFF82,
  23867. tusmallhiragana: 0x3063,
  23868. tusmallkatakana: 0x30C3,
  23869. tusmallkatakanahalfwidth: 0xFF6F,
  23870. twelvecircle: 0x246B,
  23871. twelveparen: 0x247F,
  23872. twelveperiod: 0x2493,
  23873. twelveroman: 0x217B,
  23874. twentycircle: 0x2473,
  23875. twentyhangzhou: 0x5344,
  23876. twentyparen: 0x2487,
  23877. twentyperiod: 0x249B,
  23878. two: 0x0032,
  23879. twoarabic: 0x0662,
  23880. twobengali: 0x09E8,
  23881. twocircle: 0x2461,
  23882. twocircleinversesansserif: 0x278B,
  23883. twodeva: 0x0968,
  23884. twodotenleader: 0x2025,
  23885. twodotleader: 0x2025,
  23886. twodotleadervertical: 0xFE30,
  23887. twogujarati: 0x0AE8,
  23888. twogurmukhi: 0x0A68,
  23889. twohackarabic: 0x0662,
  23890. twohangzhou: 0x3022,
  23891. twoideographicparen: 0x3221,
  23892. twoinferior: 0x2082,
  23893. twomonospace: 0xFF12,
  23894. twonumeratorbengali: 0x09F5,
  23895. twooldstyle: 0xF732,
  23896. twoparen: 0x2475,
  23897. twoperiod: 0x2489,
  23898. twopersian: 0x06F2,
  23899. tworoman: 0x2171,
  23900. twostroke: 0x01BB,
  23901. twosuperior: 0x00B2,
  23902. twothai: 0x0E52,
  23903. twothirds: 0x2154,
  23904. u: 0x0075,
  23905. uacute: 0x00FA,
  23906. ubar: 0x0289,
  23907. ubengali: 0x0989,
  23908. ubopomofo: 0x3128,
  23909. ubreve: 0x016D,
  23910. ucaron: 0x01D4,
  23911. ucircle: 0x24E4,
  23912. ucircumflex: 0x00FB,
  23913. ucircumflexbelow: 0x1E77,
  23914. ucyrillic: 0x0443,
  23915. udattadeva: 0x0951,
  23916. udblacute: 0x0171,
  23917. udblgrave: 0x0215,
  23918. udeva: 0x0909,
  23919. udieresis: 0x00FC,
  23920. udieresisacute: 0x01D8,
  23921. udieresisbelow: 0x1E73,
  23922. udieresiscaron: 0x01DA,
  23923. udieresiscyrillic: 0x04F1,
  23924. udieresisgrave: 0x01DC,
  23925. udieresismacron: 0x01D6,
  23926. udotbelow: 0x1EE5,
  23927. ugrave: 0x00F9,
  23928. ugujarati: 0x0A89,
  23929. ugurmukhi: 0x0A09,
  23930. uhiragana: 0x3046,
  23931. uhookabove: 0x1EE7,
  23932. uhorn: 0x01B0,
  23933. uhornacute: 0x1EE9,
  23934. uhorndotbelow: 0x1EF1,
  23935. uhorngrave: 0x1EEB,
  23936. uhornhookabove: 0x1EED,
  23937. uhorntilde: 0x1EEF,
  23938. uhungarumlaut: 0x0171,
  23939. uhungarumlautcyrillic: 0x04F3,
  23940. uinvertedbreve: 0x0217,
  23941. ukatakana: 0x30A6,
  23942. ukatakanahalfwidth: 0xFF73,
  23943. ukcyrillic: 0x0479,
  23944. ukorean: 0x315C,
  23945. umacron: 0x016B,
  23946. umacroncyrillic: 0x04EF,
  23947. umacrondieresis: 0x1E7B,
  23948. umatragurmukhi: 0x0A41,
  23949. umonospace: 0xFF55,
  23950. underscore: 0x005F,
  23951. underscoredbl: 0x2017,
  23952. underscoremonospace: 0xFF3F,
  23953. underscorevertical: 0xFE33,
  23954. underscorewavy: 0xFE4F,
  23955. union: 0x222A,
  23956. universal: 0x2200,
  23957. uogonek: 0x0173,
  23958. uparen: 0x24B0,
  23959. upblock: 0x2580,
  23960. upperdothebrew: 0x05C4,
  23961. upsilon: 0x03C5,
  23962. upsilondieresis: 0x03CB,
  23963. upsilondieresistonos: 0x03B0,
  23964. upsilonlatin: 0x028A,
  23965. upsilontonos: 0x03CD,
  23966. uptackbelowcmb: 0x031D,
  23967. uptackmod: 0x02D4,
  23968. uragurmukhi: 0x0A73,
  23969. uring: 0x016F,
  23970. ushortcyrillic: 0x045E,
  23971. usmallhiragana: 0x3045,
  23972. usmallkatakana: 0x30A5,
  23973. usmallkatakanahalfwidth: 0xFF69,
  23974. ustraightcyrillic: 0x04AF,
  23975. ustraightstrokecyrillic: 0x04B1,
  23976. utilde: 0x0169,
  23977. utildeacute: 0x1E79,
  23978. utildebelow: 0x1E75,
  23979. uubengali: 0x098A,
  23980. uudeva: 0x090A,
  23981. uugujarati: 0x0A8A,
  23982. uugurmukhi: 0x0A0A,
  23983. uumatragurmukhi: 0x0A42,
  23984. uuvowelsignbengali: 0x09C2,
  23985. uuvowelsigndeva: 0x0942,
  23986. uuvowelsigngujarati: 0x0AC2,
  23987. uvowelsignbengali: 0x09C1,
  23988. uvowelsigndeva: 0x0941,
  23989. uvowelsigngujarati: 0x0AC1,
  23990. v: 0x0076,
  23991. vadeva: 0x0935,
  23992. vagujarati: 0x0AB5,
  23993. vagurmukhi: 0x0A35,
  23994. vakatakana: 0x30F7,
  23995. vav: 0x05D5,
  23996. vavdagesh: 0xFB35,
  23997. vavdagesh65: 0xFB35,
  23998. vavdageshhebrew: 0xFB35,
  23999. vavhebrew: 0x05D5,
  24000. vavholam: 0xFB4B,
  24001. vavholamhebrew: 0xFB4B,
  24002. vavvavhebrew: 0x05F0,
  24003. vavyodhebrew: 0x05F1,
  24004. vcircle: 0x24E5,
  24005. vdotbelow: 0x1E7F,
  24006. vecyrillic: 0x0432,
  24007. veharabic: 0x06A4,
  24008. vehfinalarabic: 0xFB6B,
  24009. vehinitialarabic: 0xFB6C,
  24010. vehmedialarabic: 0xFB6D,
  24011. vekatakana: 0x30F9,
  24012. venus: 0x2640,
  24013. verticalbar: 0x007C,
  24014. verticallineabovecmb: 0x030D,
  24015. verticallinebelowcmb: 0x0329,
  24016. verticallinelowmod: 0x02CC,
  24017. verticallinemod: 0x02C8,
  24018. vewarmenian: 0x057E,
  24019. vhook: 0x028B,
  24020. vikatakana: 0x30F8,
  24021. viramabengali: 0x09CD,
  24022. viramadeva: 0x094D,
  24023. viramagujarati: 0x0ACD,
  24024. visargabengali: 0x0983,
  24025. visargadeva: 0x0903,
  24026. visargagujarati: 0x0A83,
  24027. vmonospace: 0xFF56,
  24028. voarmenian: 0x0578,
  24029. voicediterationhiragana: 0x309E,
  24030. voicediterationkatakana: 0x30FE,
  24031. voicedmarkkana: 0x309B,
  24032. voicedmarkkanahalfwidth: 0xFF9E,
  24033. vokatakana: 0x30FA,
  24034. vparen: 0x24B1,
  24035. vtilde: 0x1E7D,
  24036. vturned: 0x028C,
  24037. vuhiragana: 0x3094,
  24038. vukatakana: 0x30F4,
  24039. w: 0x0077,
  24040. wacute: 0x1E83,
  24041. waekorean: 0x3159,
  24042. wahiragana: 0x308F,
  24043. wakatakana: 0x30EF,
  24044. wakatakanahalfwidth: 0xFF9C,
  24045. wakorean: 0x3158,
  24046. wasmallhiragana: 0x308E,
  24047. wasmallkatakana: 0x30EE,
  24048. wattosquare: 0x3357,
  24049. wavedash: 0x301C,
  24050. wavyunderscorevertical: 0xFE34,
  24051. wawarabic: 0x0648,
  24052. wawfinalarabic: 0xFEEE,
  24053. wawhamzaabovearabic: 0x0624,
  24054. wawhamzaabovefinalarabic: 0xFE86,
  24055. wbsquare: 0x33DD,
  24056. wcircle: 0x24E6,
  24057. wcircumflex: 0x0175,
  24058. wdieresis: 0x1E85,
  24059. wdotaccent: 0x1E87,
  24060. wdotbelow: 0x1E89,
  24061. wehiragana: 0x3091,
  24062. weierstrass: 0x2118,
  24063. wekatakana: 0x30F1,
  24064. wekorean: 0x315E,
  24065. weokorean: 0x315D,
  24066. wgrave: 0x1E81,
  24067. whitebullet: 0x25E6,
  24068. whitecircle: 0x25CB,
  24069. whitecircleinverse: 0x25D9,
  24070. whitecornerbracketleft: 0x300E,
  24071. whitecornerbracketleftvertical: 0xFE43,
  24072. whitecornerbracketright: 0x300F,
  24073. whitecornerbracketrightvertical: 0xFE44,
  24074. whitediamond: 0x25C7,
  24075. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24076. whitedownpointingsmalltriangle: 0x25BF,
  24077. whitedownpointingtriangle: 0x25BD,
  24078. whiteleftpointingsmalltriangle: 0x25C3,
  24079. whiteleftpointingtriangle: 0x25C1,
  24080. whitelenticularbracketleft: 0x3016,
  24081. whitelenticularbracketright: 0x3017,
  24082. whiterightpointingsmalltriangle: 0x25B9,
  24083. whiterightpointingtriangle: 0x25B7,
  24084. whitesmallsquare: 0x25AB,
  24085. whitesmilingface: 0x263A,
  24086. whitesquare: 0x25A1,
  24087. whitestar: 0x2606,
  24088. whitetelephone: 0x260F,
  24089. whitetortoiseshellbracketleft: 0x3018,
  24090. whitetortoiseshellbracketright: 0x3019,
  24091. whiteuppointingsmalltriangle: 0x25B5,
  24092. whiteuppointingtriangle: 0x25B3,
  24093. wihiragana: 0x3090,
  24094. wikatakana: 0x30F0,
  24095. wikorean: 0x315F,
  24096. wmonospace: 0xFF57,
  24097. wohiragana: 0x3092,
  24098. wokatakana: 0x30F2,
  24099. wokatakanahalfwidth: 0xFF66,
  24100. won: 0x20A9,
  24101. wonmonospace: 0xFFE6,
  24102. wowaenthai: 0x0E27,
  24103. wparen: 0x24B2,
  24104. wring: 0x1E98,
  24105. wsuperior: 0x02B7,
  24106. wturned: 0x028D,
  24107. wynn: 0x01BF,
  24108. x: 0x0078,
  24109. xabovecmb: 0x033D,
  24110. xbopomofo: 0x3112,
  24111. xcircle: 0x24E7,
  24112. xdieresis: 0x1E8D,
  24113. xdotaccent: 0x1E8B,
  24114. xeharmenian: 0x056D,
  24115. xi: 0x03BE,
  24116. xmonospace: 0xFF58,
  24117. xparen: 0x24B3,
  24118. xsuperior: 0x02E3,
  24119. y: 0x0079,
  24120. yaadosquare: 0x334E,
  24121. yabengali: 0x09AF,
  24122. yacute: 0x00FD,
  24123. yadeva: 0x092F,
  24124. yaekorean: 0x3152,
  24125. yagujarati: 0x0AAF,
  24126. yagurmukhi: 0x0A2F,
  24127. yahiragana: 0x3084,
  24128. yakatakana: 0x30E4,
  24129. yakatakanahalfwidth: 0xFF94,
  24130. yakorean: 0x3151,
  24131. yamakkanthai: 0x0E4E,
  24132. yasmallhiragana: 0x3083,
  24133. yasmallkatakana: 0x30E3,
  24134. yasmallkatakanahalfwidth: 0xFF6C,
  24135. yatcyrillic: 0x0463,
  24136. ycircle: 0x24E8,
  24137. ycircumflex: 0x0177,
  24138. ydieresis: 0x00FF,
  24139. ydotaccent: 0x1E8F,
  24140. ydotbelow: 0x1EF5,
  24141. yeharabic: 0x064A,
  24142. yehbarreearabic: 0x06D2,
  24143. yehbarreefinalarabic: 0xFBAF,
  24144. yehfinalarabic: 0xFEF2,
  24145. yehhamzaabovearabic: 0x0626,
  24146. yehhamzaabovefinalarabic: 0xFE8A,
  24147. yehhamzaaboveinitialarabic: 0xFE8B,
  24148. yehhamzaabovemedialarabic: 0xFE8C,
  24149. yehinitialarabic: 0xFEF3,
  24150. yehmedialarabic: 0xFEF4,
  24151. yehmeeminitialarabic: 0xFCDD,
  24152. yehmeemisolatedarabic: 0xFC58,
  24153. yehnoonfinalarabic: 0xFC94,
  24154. yehthreedotsbelowarabic: 0x06D1,
  24155. yekorean: 0x3156,
  24156. yen: 0x00A5,
  24157. yenmonospace: 0xFFE5,
  24158. yeokorean: 0x3155,
  24159. yeorinhieuhkorean: 0x3186,
  24160. yerahbenyomohebrew: 0x05AA,
  24161. yerahbenyomolefthebrew: 0x05AA,
  24162. yericyrillic: 0x044B,
  24163. yerudieresiscyrillic: 0x04F9,
  24164. yesieungkorean: 0x3181,
  24165. yesieungpansioskorean: 0x3183,
  24166. yesieungsioskorean: 0x3182,
  24167. yetivhebrew: 0x059A,
  24168. ygrave: 0x1EF3,
  24169. yhook: 0x01B4,
  24170. yhookabove: 0x1EF7,
  24171. yiarmenian: 0x0575,
  24172. yicyrillic: 0x0457,
  24173. yikorean: 0x3162,
  24174. yinyang: 0x262F,
  24175. yiwnarmenian: 0x0582,
  24176. ymonospace: 0xFF59,
  24177. yod: 0x05D9,
  24178. yoddagesh: 0xFB39,
  24179. yoddageshhebrew: 0xFB39,
  24180. yodhebrew: 0x05D9,
  24181. yodyodhebrew: 0x05F2,
  24182. yodyodpatahhebrew: 0xFB1F,
  24183. yohiragana: 0x3088,
  24184. yoikorean: 0x3189,
  24185. yokatakana: 0x30E8,
  24186. yokatakanahalfwidth: 0xFF96,
  24187. yokorean: 0x315B,
  24188. yosmallhiragana: 0x3087,
  24189. yosmallkatakana: 0x30E7,
  24190. yosmallkatakanahalfwidth: 0xFF6E,
  24191. yotgreek: 0x03F3,
  24192. yoyaekorean: 0x3188,
  24193. yoyakorean: 0x3187,
  24194. yoyakthai: 0x0E22,
  24195. yoyingthai: 0x0E0D,
  24196. yparen: 0x24B4,
  24197. ypogegrammeni: 0x037A,
  24198. ypogegrammenigreekcmb: 0x0345,
  24199. yr: 0x01A6,
  24200. yring: 0x1E99,
  24201. ysuperior: 0x02B8,
  24202. ytilde: 0x1EF9,
  24203. yturned: 0x028E,
  24204. yuhiragana: 0x3086,
  24205. yuikorean: 0x318C,
  24206. yukatakana: 0x30E6,
  24207. yukatakanahalfwidth: 0xFF95,
  24208. yukorean: 0x3160,
  24209. yusbigcyrillic: 0x046B,
  24210. yusbigiotifiedcyrillic: 0x046D,
  24211. yuslittlecyrillic: 0x0467,
  24212. yuslittleiotifiedcyrillic: 0x0469,
  24213. yusmallhiragana: 0x3085,
  24214. yusmallkatakana: 0x30E5,
  24215. yusmallkatakanahalfwidth: 0xFF6D,
  24216. yuyekorean: 0x318B,
  24217. yuyeokorean: 0x318A,
  24218. yyabengali: 0x09DF,
  24219. yyadeva: 0x095F,
  24220. z: 0x007A,
  24221. zaarmenian: 0x0566,
  24222. zacute: 0x017A,
  24223. zadeva: 0x095B,
  24224. zagurmukhi: 0x0A5B,
  24225. zaharabic: 0x0638,
  24226. zahfinalarabic: 0xFEC6,
  24227. zahinitialarabic: 0xFEC7,
  24228. zahiragana: 0x3056,
  24229. zahmedialarabic: 0xFEC8,
  24230. zainarabic: 0x0632,
  24231. zainfinalarabic: 0xFEB0,
  24232. zakatakana: 0x30B6,
  24233. zaqefgadolhebrew: 0x0595,
  24234. zaqefqatanhebrew: 0x0594,
  24235. zarqahebrew: 0x0598,
  24236. zayin: 0x05D6,
  24237. zayindagesh: 0xFB36,
  24238. zayindageshhebrew: 0xFB36,
  24239. zayinhebrew: 0x05D6,
  24240. zbopomofo: 0x3117,
  24241. zcaron: 0x017E,
  24242. zcircle: 0x24E9,
  24243. zcircumflex: 0x1E91,
  24244. zcurl: 0x0291,
  24245. zdot: 0x017C,
  24246. zdotaccent: 0x017C,
  24247. zdotbelow: 0x1E93,
  24248. zecyrillic: 0x0437,
  24249. zedescendercyrillic: 0x0499,
  24250. zedieresiscyrillic: 0x04DF,
  24251. zehiragana: 0x305C,
  24252. zekatakana: 0x30BC,
  24253. zero: 0x0030,
  24254. zeroarabic: 0x0660,
  24255. zerobengali: 0x09E6,
  24256. zerodeva: 0x0966,
  24257. zerogujarati: 0x0AE6,
  24258. zerogurmukhi: 0x0A66,
  24259. zerohackarabic: 0x0660,
  24260. zeroinferior: 0x2080,
  24261. zeromonospace: 0xFF10,
  24262. zerooldstyle: 0xF730,
  24263. zeropersian: 0x06F0,
  24264. zerosuperior: 0x2070,
  24265. zerothai: 0x0E50,
  24266. zerowidthjoiner: 0xFEFF,
  24267. zerowidthnonjoiner: 0x200C,
  24268. zerowidthspace: 0x200B,
  24269. zeta: 0x03B6,
  24270. zhbopomofo: 0x3113,
  24271. zhearmenian: 0x056A,
  24272. zhebrevecyrillic: 0x04C2,
  24273. zhecyrillic: 0x0436,
  24274. zhedescendercyrillic: 0x0497,
  24275. zhedieresiscyrillic: 0x04DD,
  24276. zihiragana: 0x3058,
  24277. zikatakana: 0x30B8,
  24278. zinorhebrew: 0x05AE,
  24279. zlinebelow: 0x1E95,
  24280. zmonospace: 0xFF5A,
  24281. zohiragana: 0x305E,
  24282. zokatakana: 0x30BE,
  24283. zparen: 0x24B5,
  24284. zretroflexhook: 0x0290,
  24285. zstroke: 0x01B6,
  24286. zuhiragana: 0x305A,
  24287. zukatakana: 0x30BA,
  24288. '.notdef': 0x0000
  24289. };
  24290. var DingbatsGlyphsUnicode = {
  24291. space: 0x0020,
  24292. a1: 0x2701,
  24293. a2: 0x2702,
  24294. a202: 0x2703,
  24295. a3: 0x2704,
  24296. a4: 0x260E,
  24297. a5: 0x2706,
  24298. a119: 0x2707,
  24299. a118: 0x2708,
  24300. a117: 0x2709,
  24301. a11: 0x261B,
  24302. a12: 0x261E,
  24303. a13: 0x270C,
  24304. a14: 0x270D,
  24305. a15: 0x270E,
  24306. a16: 0x270F,
  24307. a105: 0x2710,
  24308. a17: 0x2711,
  24309. a18: 0x2712,
  24310. a19: 0x2713,
  24311. a20: 0x2714,
  24312. a21: 0x2715,
  24313. a22: 0x2716,
  24314. a23: 0x2717,
  24315. a24: 0x2718,
  24316. a25: 0x2719,
  24317. a26: 0x271A,
  24318. a27: 0x271B,
  24319. a28: 0x271C,
  24320. a6: 0x271D,
  24321. a7: 0x271E,
  24322. a8: 0x271F,
  24323. a9: 0x2720,
  24324. a10: 0x2721,
  24325. a29: 0x2722,
  24326. a30: 0x2723,
  24327. a31: 0x2724,
  24328. a32: 0x2725,
  24329. a33: 0x2726,
  24330. a34: 0x2727,
  24331. a35: 0x2605,
  24332. a36: 0x2729,
  24333. a37: 0x272A,
  24334. a38: 0x272B,
  24335. a39: 0x272C,
  24336. a40: 0x272D,
  24337. a41: 0x272E,
  24338. a42: 0x272F,
  24339. a43: 0x2730,
  24340. a44: 0x2731,
  24341. a45: 0x2732,
  24342. a46: 0x2733,
  24343. a47: 0x2734,
  24344. a48: 0x2735,
  24345. a49: 0x2736,
  24346. a50: 0x2737,
  24347. a51: 0x2738,
  24348. a52: 0x2739,
  24349. a53: 0x273A,
  24350. a54: 0x273B,
  24351. a55: 0x273C,
  24352. a56: 0x273D,
  24353. a57: 0x273E,
  24354. a58: 0x273F,
  24355. a59: 0x2740,
  24356. a60: 0x2741,
  24357. a61: 0x2742,
  24358. a62: 0x2743,
  24359. a63: 0x2744,
  24360. a64: 0x2745,
  24361. a65: 0x2746,
  24362. a66: 0x2747,
  24363. a67: 0x2748,
  24364. a68: 0x2749,
  24365. a69: 0x274A,
  24366. a70: 0x274B,
  24367. a71: 0x25CF,
  24368. a72: 0x274D,
  24369. a73: 0x25A0,
  24370. a74: 0x274F,
  24371. a203: 0x2750,
  24372. a75: 0x2751,
  24373. a204: 0x2752,
  24374. a76: 0x25B2,
  24375. a77: 0x25BC,
  24376. a78: 0x25C6,
  24377. a79: 0x2756,
  24378. a81: 0x25D7,
  24379. a82: 0x2758,
  24380. a83: 0x2759,
  24381. a84: 0x275A,
  24382. a97: 0x275B,
  24383. a98: 0x275C,
  24384. a99: 0x275D,
  24385. a100: 0x275E,
  24386. a101: 0x2761,
  24387. a102: 0x2762,
  24388. a103: 0x2763,
  24389. a104: 0x2764,
  24390. a106: 0x2765,
  24391. a107: 0x2766,
  24392. a108: 0x2767,
  24393. a112: 0x2663,
  24394. a111: 0x2666,
  24395. a110: 0x2665,
  24396. a109: 0x2660,
  24397. a120: 0x2460,
  24398. a121: 0x2461,
  24399. a122: 0x2462,
  24400. a123: 0x2463,
  24401. a124: 0x2464,
  24402. a125: 0x2465,
  24403. a126: 0x2466,
  24404. a127: 0x2467,
  24405. a128: 0x2468,
  24406. a129: 0x2469,
  24407. a130: 0x2776,
  24408. a131: 0x2777,
  24409. a132: 0x2778,
  24410. a133: 0x2779,
  24411. a134: 0x277A,
  24412. a135: 0x277B,
  24413. a136: 0x277C,
  24414. a137: 0x277D,
  24415. a138: 0x277E,
  24416. a139: 0x277F,
  24417. a140: 0x2780,
  24418. a141: 0x2781,
  24419. a142: 0x2782,
  24420. a143: 0x2783,
  24421. a144: 0x2784,
  24422. a145: 0x2785,
  24423. a146: 0x2786,
  24424. a147: 0x2787,
  24425. a148: 0x2788,
  24426. a149: 0x2789,
  24427. a150: 0x278A,
  24428. a151: 0x278B,
  24429. a152: 0x278C,
  24430. a153: 0x278D,
  24431. a154: 0x278E,
  24432. a155: 0x278F,
  24433. a156: 0x2790,
  24434. a157: 0x2791,
  24435. a158: 0x2792,
  24436. a159: 0x2793,
  24437. a160: 0x2794,
  24438. a161: 0x2192,
  24439. a163: 0x2194,
  24440. a164: 0x2195,
  24441. a196: 0x2798,
  24442. a165: 0x2799,
  24443. a192: 0x279A,
  24444. a166: 0x279B,
  24445. a167: 0x279C,
  24446. a168: 0x279D,
  24447. a169: 0x279E,
  24448. a170: 0x279F,
  24449. a171: 0x27A0,
  24450. a172: 0x27A1,
  24451. a173: 0x27A2,
  24452. a162: 0x27A3,
  24453. a174: 0x27A4,
  24454. a175: 0x27A5,
  24455. a176: 0x27A6,
  24456. a177: 0x27A7,
  24457. a178: 0x27A8,
  24458. a179: 0x27A9,
  24459. a193: 0x27AA,
  24460. a180: 0x27AB,
  24461. a199: 0x27AC,
  24462. a181: 0x27AD,
  24463. a200: 0x27AE,
  24464. a182: 0x27AF,
  24465. a201: 0x27B1,
  24466. a183: 0x27B2,
  24467. a184: 0x27B3,
  24468. a197: 0x27B4,
  24469. a185: 0x27B5,
  24470. a194: 0x27B6,
  24471. a198: 0x27B7,
  24472. a186: 0x27B8,
  24473. a195: 0x27B9,
  24474. a187: 0x27BA,
  24475. a188: 0x27BB,
  24476. a189: 0x27BC,
  24477. a190: 0x27BD,
  24478. a191: 0x27BE,
  24479. a89: 0x2768, // 0xF8D7
  24480. a90: 0x2769, // 0xF8D8
  24481. a93: 0x276A, // 0xF8D9
  24482. a94: 0x276B, // 0xF8DA
  24483. a91: 0x276C, // 0xF8DB
  24484. a92: 0x276D, // 0xF8DC
  24485. a205: 0x276E, // 0xF8DD
  24486. a85: 0x276F, // 0xF8DE
  24487. a206: 0x2770, // 0xF8DF
  24488. a86: 0x2771, // 0xF8E0
  24489. a87: 0x2772, // 0xF8E1
  24490. a88: 0x2773, // 0xF8E2
  24491. a95: 0x2774, // 0xF8E3
  24492. a96: 0x2775, // 0xF8E4
  24493. '.notdef': 0x0000
  24494. };
  24495. var PDFImage = (function PDFImageClosure() {
  24496. /**
  24497. * Decode the image in the main thread if it supported. Resovles the promise
  24498. * when the image data is ready.
  24499. */
  24500. function handleImageData(handler, xref, res, image) {
  24501. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24502. // For natively supported jpegs send them to the main thread for decoding.
  24503. var dict = image.dict;
  24504. var colorSpace = dict.get('ColorSpace', 'CS');
  24505. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24506. var numComps = colorSpace.numComps;
  24507. var decodePromise = handler.sendWithPromise('JpegDecode',
  24508. [image.getIR(), numComps]);
  24509. return decodePromise.then(function (message) {
  24510. var data = message.data;
  24511. return new Stream(data, 0, data.length, image.dict);
  24512. });
  24513. } else {
  24514. return Promise.resolve(image);
  24515. }
  24516. }
  24517. /**
  24518. * Decode and clamp a value. The formula is different from the spec because we
  24519. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24520. */
  24521. function decodeAndClamp(value, addend, coefficient, max) {
  24522. value = addend + value * coefficient;
  24523. // Clamp the value to the range
  24524. return (value < 0 ? 0 : (value > max ? max : value));
  24525. }
  24526. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24527. this.image = image;
  24528. var dict = image.dict;
  24529. if (dict.has('Filter')) {
  24530. var filter = dict.get('Filter').name;
  24531. if (filter === 'JPXDecode') {
  24532. var jpxImage = new JpxImage();
  24533. jpxImage.parseImageProperties(image.stream);
  24534. image.stream.reset();
  24535. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24536. image.numComps = jpxImage.componentsCount;
  24537. } else if (filter === 'JBIG2Decode') {
  24538. image.bitsPerComponent = 1;
  24539. image.numComps = 1;
  24540. }
  24541. }
  24542. // TODO cache rendered images?
  24543. this.width = dict.get('Width', 'W');
  24544. this.height = dict.get('Height', 'H');
  24545. if (this.width < 1 || this.height < 1) {
  24546. error('Invalid image width: ' + this.width + ' or height: ' +
  24547. this.height);
  24548. }
  24549. this.interpolate = dict.get('Interpolate', 'I') || false;
  24550. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24551. this.matte = dict.get('Matte') || false;
  24552. var bitsPerComponent = image.bitsPerComponent;
  24553. if (!bitsPerComponent) {
  24554. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24555. if (!bitsPerComponent) {
  24556. if (this.imageMask) {
  24557. bitsPerComponent = 1;
  24558. } else {
  24559. error('Bits per component missing in image: ' + this.imageMask);
  24560. }
  24561. }
  24562. }
  24563. this.bpc = bitsPerComponent;
  24564. if (!this.imageMask) {
  24565. var colorSpace = dict.get('ColorSpace', 'CS');
  24566. if (!colorSpace) {
  24567. info('JPX images (which do not require color spaces)');
  24568. switch (image.numComps) {
  24569. case 1:
  24570. colorSpace = Name.get('DeviceGray');
  24571. break;
  24572. case 3:
  24573. colorSpace = Name.get('DeviceRGB');
  24574. break;
  24575. case 4:
  24576. colorSpace = Name.get('DeviceCMYK');
  24577. break;
  24578. default:
  24579. error('JPX images with ' + this.numComps +
  24580. ' color components not supported.');
  24581. }
  24582. }
  24583. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24584. this.numComps = this.colorSpace.numComps;
  24585. }
  24586. this.decode = dict.get('Decode', 'D');
  24587. this.needsDecode = false;
  24588. if (this.decode &&
  24589. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24590. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24591. this.needsDecode = true;
  24592. // Do some preprocessing to avoid more math.
  24593. var max = (1 << bitsPerComponent) - 1;
  24594. this.decodeCoefficients = [];
  24595. this.decodeAddends = [];
  24596. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24597. var dmin = this.decode[i];
  24598. var dmax = this.decode[i + 1];
  24599. this.decodeCoefficients[j] = dmax - dmin;
  24600. this.decodeAddends[j] = max * dmin;
  24601. }
  24602. }
  24603. if (smask) {
  24604. this.smask = new PDFImage(xref, res, smask, false);
  24605. } else if (mask) {
  24606. if (isStream(mask)) {
  24607. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24608. } else {
  24609. // Color key mask (just an array).
  24610. this.mask = mask;
  24611. }
  24612. }
  24613. }
  24614. /**
  24615. * Handles processing of image data and returns the Promise that is resolved
  24616. * with a PDFImage when the image is ready to be used.
  24617. */
  24618. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24619. res, image, inline) {
  24620. var imagePromise = handleImageData(handler, xref, res, image);
  24621. var smaskPromise;
  24622. var maskPromise;
  24623. var smask = image.dict.get('SMask');
  24624. var mask = image.dict.get('Mask');
  24625. if (smask) {
  24626. smaskPromise = handleImageData(handler, xref, res, smask);
  24627. maskPromise = Promise.resolve(null);
  24628. } else {
  24629. smaskPromise = Promise.resolve(null);
  24630. if (mask) {
  24631. if (isStream(mask)) {
  24632. maskPromise = handleImageData(handler, xref, res, mask);
  24633. } else if (isArray(mask)) {
  24634. maskPromise = Promise.resolve(mask);
  24635. } else {
  24636. warn('Unsupported mask format.');
  24637. maskPromise = Promise.resolve(null);
  24638. }
  24639. } else {
  24640. maskPromise = Promise.resolve(null);
  24641. }
  24642. }
  24643. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24644. function(results) {
  24645. var imageData = results[0];
  24646. var smaskData = results[1];
  24647. var maskData = results[2];
  24648. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24649. });
  24650. };
  24651. /**
  24652. * Resize an image using the nearest neighbor algorithm. Currently only
  24653. * supports one and three component images.
  24654. * @param {TypedArray} pixels The original image with one component.
  24655. * @param {Number} bpc Number of bits per component.
  24656. * @param {Number} components Number of color components, 1 or 3 is supported.
  24657. * @param {Number} w1 Original width.
  24658. * @param {Number} h1 Original height.
  24659. * @param {Number} w2 New width.
  24660. * @param {Number} h2 New height.
  24661. * @param {TypedArray} dest (Optional) The destination buffer.
  24662. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24663. * @return {TypedArray} Resized image data.
  24664. */
  24665. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24666. w1, h1, w2, h2, dest, alpha01) {
  24667. if (components !== 1 && components !== 3) {
  24668. error('Unsupported component count for resizing.');
  24669. }
  24670. var length = w2 * h2 * components;
  24671. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24672. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24673. var xRatio = w1 / w2;
  24674. var yRatio = h1 / h2;
  24675. var i, j, py, newIndex = 0, oldIndex;
  24676. var xScaled = new Uint16Array(w2);
  24677. var w1Scanline = w1 * components;
  24678. if (alpha01 !== 1) {
  24679. alpha01 = 0;
  24680. }
  24681. for (j = 0; j < w2; j++) {
  24682. xScaled[j] = Math.floor(j * xRatio) * components;
  24683. }
  24684. if (components === 1) {
  24685. for (i = 0; i < h2; i++) {
  24686. py = Math.floor(i * yRatio) * w1Scanline;
  24687. for (j = 0; j < w2; j++) {
  24688. oldIndex = py + xScaled[j];
  24689. temp[newIndex++] = pixels[oldIndex];
  24690. }
  24691. }
  24692. } else if (components === 3) {
  24693. for (i = 0; i < h2; i++) {
  24694. py = Math.floor(i * yRatio) * w1Scanline;
  24695. for (j = 0; j < w2; j++) {
  24696. oldIndex = py + xScaled[j];
  24697. temp[newIndex++] = pixels[oldIndex++];
  24698. temp[newIndex++] = pixels[oldIndex++];
  24699. temp[newIndex++] = pixels[oldIndex++];
  24700. newIndex += alpha01;
  24701. }
  24702. }
  24703. }
  24704. return temp;
  24705. };
  24706. PDFImage.createMask =
  24707. function PDFImage_createMask(imgArray, width, height,
  24708. imageIsFromDecodeStream, inverseDecode) {
  24709. // |imgArray| might not contain full data for every pixel of the mask, so
  24710. // we need to distinguish between |computedLength| and |actualLength|.
  24711. // In particular, if inverseDecode is true, then the array we return must
  24712. // have a length of |computedLength|.
  24713. var computedLength = ((width + 7) >> 3) * height;
  24714. var actualLength = imgArray.byteLength;
  24715. var haveFullData = computedLength === actualLength;
  24716. var data, i;
  24717. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24718. // imgArray came from a DecodeStream and its data is in an appropriate
  24719. // form, so we can just transfer it.
  24720. data = imgArray;
  24721. } else if (!inverseDecode) {
  24722. data = new Uint8Array(actualLength);
  24723. data.set(imgArray);
  24724. } else {
  24725. data = new Uint8Array(computedLength);
  24726. data.set(imgArray);
  24727. for (i = actualLength; i < computedLength; i++) {
  24728. data[i] = 0xff;
  24729. }
  24730. }
  24731. // If necessary, invert the original mask data (but not any extra we might
  24732. // have added above). It's safe to modify the array -- whether it's the
  24733. // original or a copy, we're about to transfer it anyway, so nothing else
  24734. // in this thread can be relying on its contents.
  24735. if (inverseDecode) {
  24736. for (i = 0; i < actualLength; i++) {
  24737. data[i] = ~data[i];
  24738. }
  24739. }
  24740. return {data: data, width: width, height: height};
  24741. };
  24742. PDFImage.prototype = {
  24743. get drawWidth() {
  24744. return Math.max(this.width,
  24745. this.smask && this.smask.width || 0,
  24746. this.mask && this.mask.width || 0);
  24747. },
  24748. get drawHeight() {
  24749. return Math.max(this.height,
  24750. this.smask && this.smask.height || 0,
  24751. this.mask && this.mask.height || 0);
  24752. },
  24753. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24754. var bpc = this.bpc;
  24755. var numComps = this.numComps;
  24756. var decodeAddends = this.decodeAddends;
  24757. var decodeCoefficients = this.decodeCoefficients;
  24758. var max = (1 << bpc) - 1;
  24759. var i, ii;
  24760. if (bpc === 1) {
  24761. // If the buffer needed decode that means it just needs to be inverted.
  24762. for (i = 0, ii = buffer.length; i < ii; i++) {
  24763. buffer[i] = +!(buffer[i]);
  24764. }
  24765. return;
  24766. }
  24767. var index = 0;
  24768. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24769. for (var j = 0; j < numComps; j++) {
  24770. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24771. decodeCoefficients[j], max);
  24772. index++;
  24773. }
  24774. }
  24775. },
  24776. getComponents: function PDFImage_getComponents(buffer) {
  24777. var bpc = this.bpc;
  24778. // This image doesn't require any extra work.
  24779. if (bpc === 8) {
  24780. return buffer;
  24781. }
  24782. var width = this.width;
  24783. var height = this.height;
  24784. var numComps = this.numComps;
  24785. var length = width * height * numComps;
  24786. var bufferPos = 0;
  24787. var output = (bpc <= 8 ? new Uint8Array(length) :
  24788. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24789. var rowComps = width * numComps;
  24790. var max = (1 << bpc) - 1;
  24791. var i = 0, ii, buf;
  24792. if (bpc === 1) {
  24793. // Optimization for reading 1 bpc images.
  24794. var mask, loop1End, loop2End;
  24795. for (var j = 0; j < height; j++) {
  24796. loop1End = i + (rowComps & ~7);
  24797. loop2End = i + rowComps;
  24798. // unroll loop for all full bytes
  24799. while (i < loop1End) {
  24800. buf = buffer[bufferPos++];
  24801. output[i] = (buf >> 7) & 1;
  24802. output[i + 1] = (buf >> 6) & 1;
  24803. output[i + 2] = (buf >> 5) & 1;
  24804. output[i + 3] = (buf >> 4) & 1;
  24805. output[i + 4] = (buf >> 3) & 1;
  24806. output[i + 5] = (buf >> 2) & 1;
  24807. output[i + 6] = (buf >> 1) & 1;
  24808. output[i + 7] = buf & 1;
  24809. i += 8;
  24810. }
  24811. // handle remaing bits
  24812. if (i < loop2End) {
  24813. buf = buffer[bufferPos++];
  24814. mask = 128;
  24815. while (i < loop2End) {
  24816. output[i++] = +!!(buf & mask);
  24817. mask >>= 1;
  24818. }
  24819. }
  24820. }
  24821. } else {
  24822. // The general case that handles all other bpc values.
  24823. var bits = 0;
  24824. buf = 0;
  24825. for (i = 0, ii = length; i < ii; ++i) {
  24826. if (i % rowComps === 0) {
  24827. buf = 0;
  24828. bits = 0;
  24829. }
  24830. while (bits < bpc) {
  24831. buf = (buf << 8) | buffer[bufferPos++];
  24832. bits += 8;
  24833. }
  24834. var remainingBits = bits - bpc;
  24835. var value = buf >> remainingBits;
  24836. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  24837. buf = buf & ((1 << remainingBits) - 1);
  24838. bits = remainingBits;
  24839. }
  24840. }
  24841. return output;
  24842. },
  24843. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  24844. actualHeight, image) {
  24845. var smask = this.smask;
  24846. var mask = this.mask;
  24847. var alphaBuf, sw, sh, i, ii, j;
  24848. if (smask) {
  24849. sw = smask.width;
  24850. sh = smask.height;
  24851. alphaBuf = new Uint8Array(sw * sh);
  24852. smask.fillGrayBuffer(alphaBuf);
  24853. if (sw !== width || sh !== height) {
  24854. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  24855. height);
  24856. }
  24857. } else if (mask) {
  24858. if (mask instanceof PDFImage) {
  24859. sw = mask.width;
  24860. sh = mask.height;
  24861. alphaBuf = new Uint8Array(sw * sh);
  24862. mask.numComps = 1;
  24863. mask.fillGrayBuffer(alphaBuf);
  24864. // Need to invert values in rgbaBuf
  24865. for (i = 0, ii = sw * sh; i < ii; ++i) {
  24866. alphaBuf[i] = 255 - alphaBuf[i];
  24867. }
  24868. if (sw !== width || sh !== height) {
  24869. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  24870. height);
  24871. }
  24872. } else if (isArray(mask)) {
  24873. // Color key mask: if any of the compontents are outside the range
  24874. // then they should be painted.
  24875. alphaBuf = new Uint8Array(width * height);
  24876. var numComps = this.numComps;
  24877. for (i = 0, ii = width * height; i < ii; ++i) {
  24878. var opacity = 0;
  24879. var imageOffset = i * numComps;
  24880. for (j = 0; j < numComps; ++j) {
  24881. var color = image[imageOffset + j];
  24882. var maskOffset = j * 2;
  24883. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  24884. opacity = 255;
  24885. break;
  24886. }
  24887. }
  24888. alphaBuf[i] = opacity;
  24889. }
  24890. } else {
  24891. error('Unknown mask format.');
  24892. }
  24893. }
  24894. if (alphaBuf) {
  24895. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24896. rgbaBuf[j] = alphaBuf[i];
  24897. }
  24898. } else {
  24899. // No mask.
  24900. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24901. rgbaBuf[j] = 255;
  24902. }
  24903. }
  24904. },
  24905. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  24906. var matte = this.smask && this.smask.matte;
  24907. if (!matte) {
  24908. return;
  24909. }
  24910. var matteRgb = this.colorSpace.getRgb(matte, 0);
  24911. var matteR = matteRgb[0];
  24912. var matteG = matteRgb[1];
  24913. var matteB = matteRgb[2];
  24914. var length = width * height * 4;
  24915. var r, g, b;
  24916. for (var i = 0; i < length; i += 4) {
  24917. var alpha = buffer[i + 3];
  24918. if (alpha === 0) {
  24919. // according formula we have to get Infinity in all components
  24920. // making it white (typical paper color) should be okay
  24921. buffer[i] = 255;
  24922. buffer[i + 1] = 255;
  24923. buffer[i + 2] = 255;
  24924. continue;
  24925. }
  24926. var k = 255 / alpha;
  24927. r = (buffer[i] - matteR) * k + matteR;
  24928. g = (buffer[i + 1] - matteG) * k + matteG;
  24929. b = (buffer[i + 2] - matteB) * k + matteB;
  24930. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  24931. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  24932. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  24933. }
  24934. },
  24935. createImageData: function PDFImage_createImageData(forceRGBA) {
  24936. var drawWidth = this.drawWidth;
  24937. var drawHeight = this.drawHeight;
  24938. var imgData = { // other fields are filled in below
  24939. width: drawWidth,
  24940. height: drawHeight
  24941. };
  24942. var numComps = this.numComps;
  24943. var originalWidth = this.width;
  24944. var originalHeight = this.height;
  24945. var bpc = this.bpc;
  24946. // Rows start at byte boundary.
  24947. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  24948. var imgArray;
  24949. if (!forceRGBA) {
  24950. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  24951. // without any complications, we pass a same-sized copy to the main
  24952. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  24953. // of memory for many scanned documents. It's also much faster.
  24954. //
  24955. // Similarly, if it is a 24-bit-per pixel RGB image without any
  24956. // complications, we avoid expanding by 1.333x to RGBA form.
  24957. var kind;
  24958. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  24959. kind = ImageKind.GRAYSCALE_1BPP;
  24960. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  24961. !this.needsDecode) {
  24962. kind = ImageKind.RGB_24BPP;
  24963. }
  24964. if (kind && !this.smask && !this.mask &&
  24965. drawWidth === originalWidth && drawHeight === originalHeight) {
  24966. imgData.kind = kind;
  24967. imgArray = this.getImageBytes(originalHeight * rowBytes);
  24968. // If imgArray came from a DecodeStream, we're safe to transfer it
  24969. // (and thus neuter it) because it will constitute the entire
  24970. // DecodeStream's data. But if it came from a Stream, we need to
  24971. // copy it because it'll only be a portion of the Stream's data, and
  24972. // the rest will be read later on.
  24973. if (this.image instanceof DecodeStream) {
  24974. imgData.data = imgArray;
  24975. } else {
  24976. var newArray = new Uint8Array(imgArray.length);
  24977. newArray.set(imgArray);
  24978. imgData.data = newArray;
  24979. }
  24980. if (this.needsDecode) {
  24981. // Invert the buffer (which must be grayscale if we reached here).
  24982. assert(kind === ImageKind.GRAYSCALE_1BPP);
  24983. var buffer = imgData.data;
  24984. for (var i = 0, ii = buffer.length; i < ii; i++) {
  24985. buffer[i] ^= 0xff;
  24986. }
  24987. }
  24988. return imgData;
  24989. }
  24990. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  24991. imgData.kind = ImageKind.RGB_24BPP;
  24992. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  24993. drawWidth, drawHeight, true);
  24994. return imgData;
  24995. }
  24996. }
  24997. imgArray = this.getImageBytes(originalHeight * rowBytes);
  24998. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  24999. var actualHeight = 0 | (imgArray.length / rowBytes *
  25000. drawHeight / originalHeight);
  25001. var comps = this.getComponents(imgArray);
  25002. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25003. // more compact RGB_24BPP form if allowable.
  25004. var alpha01, maybeUndoPreblend;
  25005. if (!forceRGBA && !this.smask && !this.mask) {
  25006. imgData.kind = ImageKind.RGB_24BPP;
  25007. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25008. alpha01 = 0;
  25009. maybeUndoPreblend = false;
  25010. } else {
  25011. imgData.kind = ImageKind.RGBA_32BPP;
  25012. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25013. alpha01 = 1;
  25014. maybeUndoPreblend = true;
  25015. // Color key masking (opacity) must be performed before decoding.
  25016. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25017. comps);
  25018. }
  25019. if (this.needsDecode) {
  25020. this.decodeBuffer(comps);
  25021. }
  25022. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25023. drawWidth, drawHeight, actualHeight, bpc, comps,
  25024. alpha01);
  25025. if (maybeUndoPreblend) {
  25026. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25027. }
  25028. return imgData;
  25029. },
  25030. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25031. var numComps = this.numComps;
  25032. if (numComps !== 1) {
  25033. error('Reading gray scale from a color image: ' + numComps);
  25034. }
  25035. var width = this.width;
  25036. var height = this.height;
  25037. var bpc = this.bpc;
  25038. // rows start at byte boundary
  25039. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25040. var imgArray = this.getImageBytes(height * rowBytes);
  25041. var comps = this.getComponents(imgArray);
  25042. var i, length;
  25043. if (bpc === 1) {
  25044. // inline decoding (= inversion) for 1 bpc images
  25045. length = width * height;
  25046. if (this.needsDecode) {
  25047. // invert and scale to {0, 255}
  25048. for (i = 0; i < length; ++i) {
  25049. buffer[i] = (comps[i] - 1) & 255;
  25050. }
  25051. } else {
  25052. // scale to {0, 255}
  25053. for (i = 0; i < length; ++i) {
  25054. buffer[i] = (-comps[i]) & 255;
  25055. }
  25056. }
  25057. return;
  25058. }
  25059. if (this.needsDecode) {
  25060. this.decodeBuffer(comps);
  25061. }
  25062. length = width * height;
  25063. // we aren't using a colorspace so we need to scale the value
  25064. var scale = 255 / ((1 << bpc) - 1);
  25065. for (i = 0; i < length; ++i) {
  25066. buffer[i] = (scale * comps[i]) | 0;
  25067. }
  25068. },
  25069. getImageBytes: function PDFImage_getImageBytes(length,
  25070. drawWidth, drawHeight,
  25071. forceRGB) {
  25072. this.image.reset();
  25073. this.image.drawWidth = drawWidth || this.width;
  25074. this.image.drawHeight = drawHeight || this.height;
  25075. this.image.forceRGB = !!forceRGB;
  25076. return this.image.getBytes(length);
  25077. }
  25078. };
  25079. return PDFImage;
  25080. })();
  25081. // The Metrics object contains glyph widths (in glyph space units).
  25082. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25083. // space unit corresponds to 1/1000th of text space unit.
  25084. var Metrics = {
  25085. 'Courier': 600,
  25086. 'Courier-Bold': 600,
  25087. 'Courier-BoldOblique': 600,
  25088. 'Courier-Oblique': 600,
  25089. 'Helvetica' : {
  25090. 'space': 278,
  25091. 'exclam': 278,
  25092. 'quotedbl': 355,
  25093. 'numbersign': 556,
  25094. 'dollar': 556,
  25095. 'percent': 889,
  25096. 'ampersand': 667,
  25097. 'quoteright': 222,
  25098. 'parenleft': 333,
  25099. 'parenright': 333,
  25100. 'asterisk': 389,
  25101. 'plus': 584,
  25102. 'comma': 278,
  25103. 'hyphen': 333,
  25104. 'period': 278,
  25105. 'slash': 278,
  25106. 'zero': 556,
  25107. 'one': 556,
  25108. 'two': 556,
  25109. 'three': 556,
  25110. 'four': 556,
  25111. 'five': 556,
  25112. 'six': 556,
  25113. 'seven': 556,
  25114. 'eight': 556,
  25115. 'nine': 556,
  25116. 'colon': 278,
  25117. 'semicolon': 278,
  25118. 'less': 584,
  25119. 'equal': 584,
  25120. 'greater': 584,
  25121. 'question': 556,
  25122. 'at': 1015,
  25123. 'A': 667,
  25124. 'B': 667,
  25125. 'C': 722,
  25126. 'D': 722,
  25127. 'E': 667,
  25128. 'F': 611,
  25129. 'G': 778,
  25130. 'H': 722,
  25131. 'I': 278,
  25132. 'J': 500,
  25133. 'K': 667,
  25134. 'L': 556,
  25135. 'M': 833,
  25136. 'N': 722,
  25137. 'O': 778,
  25138. 'P': 667,
  25139. 'Q': 778,
  25140. 'R': 722,
  25141. 'S': 667,
  25142. 'T': 611,
  25143. 'U': 722,
  25144. 'V': 667,
  25145. 'W': 944,
  25146. 'X': 667,
  25147. 'Y': 667,
  25148. 'Z': 611,
  25149. 'bracketleft': 278,
  25150. 'backslash': 278,
  25151. 'bracketright': 278,
  25152. 'asciicircum': 469,
  25153. 'underscore': 556,
  25154. 'quoteleft': 222,
  25155. 'a': 556,
  25156. 'b': 556,
  25157. 'c': 500,
  25158. 'd': 556,
  25159. 'e': 556,
  25160. 'f': 278,
  25161. 'g': 556,
  25162. 'h': 556,
  25163. 'i': 222,
  25164. 'j': 222,
  25165. 'k': 500,
  25166. 'l': 222,
  25167. 'm': 833,
  25168. 'n': 556,
  25169. 'o': 556,
  25170. 'p': 556,
  25171. 'q': 556,
  25172. 'r': 333,
  25173. 's': 500,
  25174. 't': 278,
  25175. 'u': 556,
  25176. 'v': 500,
  25177. 'w': 722,
  25178. 'x': 500,
  25179. 'y': 500,
  25180. 'z': 500,
  25181. 'braceleft': 334,
  25182. 'bar': 260,
  25183. 'braceright': 334,
  25184. 'asciitilde': 584,
  25185. 'exclamdown': 333,
  25186. 'cent': 556,
  25187. 'sterling': 556,
  25188. 'fraction': 167,
  25189. 'yen': 556,
  25190. 'florin': 556,
  25191. 'section': 556,
  25192. 'currency': 556,
  25193. 'quotesingle': 191,
  25194. 'quotedblleft': 333,
  25195. 'guillemotleft': 556,
  25196. 'guilsinglleft': 333,
  25197. 'guilsinglright': 333,
  25198. 'fi': 500,
  25199. 'fl': 500,
  25200. 'endash': 556,
  25201. 'dagger': 556,
  25202. 'daggerdbl': 556,
  25203. 'periodcentered': 278,
  25204. 'paragraph': 537,
  25205. 'bullet': 350,
  25206. 'quotesinglbase': 222,
  25207. 'quotedblbase': 333,
  25208. 'quotedblright': 333,
  25209. 'guillemotright': 556,
  25210. 'ellipsis': 1000,
  25211. 'perthousand': 1000,
  25212. 'questiondown': 611,
  25213. 'grave': 333,
  25214. 'acute': 333,
  25215. 'circumflex': 333,
  25216. 'tilde': 333,
  25217. 'macron': 333,
  25218. 'breve': 333,
  25219. 'dotaccent': 333,
  25220. 'dieresis': 333,
  25221. 'ring': 333,
  25222. 'cedilla': 333,
  25223. 'hungarumlaut': 333,
  25224. 'ogonek': 333,
  25225. 'caron': 333,
  25226. 'emdash': 1000,
  25227. 'AE': 1000,
  25228. 'ordfeminine': 370,
  25229. 'Lslash': 556,
  25230. 'Oslash': 778,
  25231. 'OE': 1000,
  25232. 'ordmasculine': 365,
  25233. 'ae': 889,
  25234. 'dotlessi': 278,
  25235. 'lslash': 222,
  25236. 'oslash': 611,
  25237. 'oe': 944,
  25238. 'germandbls': 611,
  25239. 'Idieresis': 278,
  25240. 'eacute': 556,
  25241. 'abreve': 556,
  25242. 'uhungarumlaut': 556,
  25243. 'ecaron': 556,
  25244. 'Ydieresis': 667,
  25245. 'divide': 584,
  25246. 'Yacute': 667,
  25247. 'Acircumflex': 667,
  25248. 'aacute': 556,
  25249. 'Ucircumflex': 722,
  25250. 'yacute': 500,
  25251. 'scommaaccent': 500,
  25252. 'ecircumflex': 556,
  25253. 'Uring': 722,
  25254. 'Udieresis': 722,
  25255. 'aogonek': 556,
  25256. 'Uacute': 722,
  25257. 'uogonek': 556,
  25258. 'Edieresis': 667,
  25259. 'Dcroat': 722,
  25260. 'commaaccent': 250,
  25261. 'copyright': 737,
  25262. 'Emacron': 667,
  25263. 'ccaron': 500,
  25264. 'aring': 556,
  25265. 'Ncommaaccent': 722,
  25266. 'lacute': 222,
  25267. 'agrave': 556,
  25268. 'Tcommaaccent': 611,
  25269. 'Cacute': 722,
  25270. 'atilde': 556,
  25271. 'Edotaccent': 667,
  25272. 'scaron': 500,
  25273. 'scedilla': 500,
  25274. 'iacute': 278,
  25275. 'lozenge': 471,
  25276. 'Rcaron': 722,
  25277. 'Gcommaaccent': 778,
  25278. 'ucircumflex': 556,
  25279. 'acircumflex': 556,
  25280. 'Amacron': 667,
  25281. 'rcaron': 333,
  25282. 'ccedilla': 500,
  25283. 'Zdotaccent': 611,
  25284. 'Thorn': 667,
  25285. 'Omacron': 778,
  25286. 'Racute': 722,
  25287. 'Sacute': 667,
  25288. 'dcaron': 643,
  25289. 'Umacron': 722,
  25290. 'uring': 556,
  25291. 'threesuperior': 333,
  25292. 'Ograve': 778,
  25293. 'Agrave': 667,
  25294. 'Abreve': 667,
  25295. 'multiply': 584,
  25296. 'uacute': 556,
  25297. 'Tcaron': 611,
  25298. 'partialdiff': 476,
  25299. 'ydieresis': 500,
  25300. 'Nacute': 722,
  25301. 'icircumflex': 278,
  25302. 'Ecircumflex': 667,
  25303. 'adieresis': 556,
  25304. 'edieresis': 556,
  25305. 'cacute': 500,
  25306. 'nacute': 556,
  25307. 'umacron': 556,
  25308. 'Ncaron': 722,
  25309. 'Iacute': 278,
  25310. 'plusminus': 584,
  25311. 'brokenbar': 260,
  25312. 'registered': 737,
  25313. 'Gbreve': 778,
  25314. 'Idotaccent': 278,
  25315. 'summation': 600,
  25316. 'Egrave': 667,
  25317. 'racute': 333,
  25318. 'omacron': 556,
  25319. 'Zacute': 611,
  25320. 'Zcaron': 611,
  25321. 'greaterequal': 549,
  25322. 'Eth': 722,
  25323. 'Ccedilla': 722,
  25324. 'lcommaaccent': 222,
  25325. 'tcaron': 317,
  25326. 'eogonek': 556,
  25327. 'Uogonek': 722,
  25328. 'Aacute': 667,
  25329. 'Adieresis': 667,
  25330. 'egrave': 556,
  25331. 'zacute': 500,
  25332. 'iogonek': 222,
  25333. 'Oacute': 778,
  25334. 'oacute': 556,
  25335. 'amacron': 556,
  25336. 'sacute': 500,
  25337. 'idieresis': 278,
  25338. 'Ocircumflex': 778,
  25339. 'Ugrave': 722,
  25340. 'Delta': 612,
  25341. 'thorn': 556,
  25342. 'twosuperior': 333,
  25343. 'Odieresis': 778,
  25344. 'mu': 556,
  25345. 'igrave': 278,
  25346. 'ohungarumlaut': 556,
  25347. 'Eogonek': 667,
  25348. 'dcroat': 556,
  25349. 'threequarters': 834,
  25350. 'Scedilla': 667,
  25351. 'lcaron': 299,
  25352. 'Kcommaaccent': 667,
  25353. 'Lacute': 556,
  25354. 'trademark': 1000,
  25355. 'edotaccent': 556,
  25356. 'Igrave': 278,
  25357. 'Imacron': 278,
  25358. 'Lcaron': 556,
  25359. 'onehalf': 834,
  25360. 'lessequal': 549,
  25361. 'ocircumflex': 556,
  25362. 'ntilde': 556,
  25363. 'Uhungarumlaut': 722,
  25364. 'Eacute': 667,
  25365. 'emacron': 556,
  25366. 'gbreve': 556,
  25367. 'onequarter': 834,
  25368. 'Scaron': 667,
  25369. 'Scommaaccent': 667,
  25370. 'Ohungarumlaut': 778,
  25371. 'degree': 400,
  25372. 'ograve': 556,
  25373. 'Ccaron': 722,
  25374. 'ugrave': 556,
  25375. 'radical': 453,
  25376. 'Dcaron': 722,
  25377. 'rcommaaccent': 333,
  25378. 'Ntilde': 722,
  25379. 'otilde': 556,
  25380. 'Rcommaaccent': 722,
  25381. 'Lcommaaccent': 556,
  25382. 'Atilde': 667,
  25383. 'Aogonek': 667,
  25384. 'Aring': 667,
  25385. 'Otilde': 778,
  25386. 'zdotaccent': 500,
  25387. 'Ecaron': 667,
  25388. 'Iogonek': 278,
  25389. 'kcommaaccent': 500,
  25390. 'minus': 584,
  25391. 'Icircumflex': 278,
  25392. 'ncaron': 556,
  25393. 'tcommaaccent': 278,
  25394. 'logicalnot': 584,
  25395. 'odieresis': 556,
  25396. 'udieresis': 556,
  25397. 'notequal': 549,
  25398. 'gcommaaccent': 556,
  25399. 'eth': 556,
  25400. 'zcaron': 500,
  25401. 'ncommaaccent': 556,
  25402. 'onesuperior': 333,
  25403. 'imacron': 278,
  25404. 'Euro': 556
  25405. },
  25406. 'Helvetica-Bold': {
  25407. 'space': 278,
  25408. 'exclam': 333,
  25409. 'quotedbl': 474,
  25410. 'numbersign': 556,
  25411. 'dollar': 556,
  25412. 'percent': 889,
  25413. 'ampersand': 722,
  25414. 'quoteright': 278,
  25415. 'parenleft': 333,
  25416. 'parenright': 333,
  25417. 'asterisk': 389,
  25418. 'plus': 584,
  25419. 'comma': 278,
  25420. 'hyphen': 333,
  25421. 'period': 278,
  25422. 'slash': 278,
  25423. 'zero': 556,
  25424. 'one': 556,
  25425. 'two': 556,
  25426. 'three': 556,
  25427. 'four': 556,
  25428. 'five': 556,
  25429. 'six': 556,
  25430. 'seven': 556,
  25431. 'eight': 556,
  25432. 'nine': 556,
  25433. 'colon': 333,
  25434. 'semicolon': 333,
  25435. 'less': 584,
  25436. 'equal': 584,
  25437. 'greater': 584,
  25438. 'question': 611,
  25439. 'at': 975,
  25440. 'A': 722,
  25441. 'B': 722,
  25442. 'C': 722,
  25443. 'D': 722,
  25444. 'E': 667,
  25445. 'F': 611,
  25446. 'G': 778,
  25447. 'H': 722,
  25448. 'I': 278,
  25449. 'J': 556,
  25450. 'K': 722,
  25451. 'L': 611,
  25452. 'M': 833,
  25453. 'N': 722,
  25454. 'O': 778,
  25455. 'P': 667,
  25456. 'Q': 778,
  25457. 'R': 722,
  25458. 'S': 667,
  25459. 'T': 611,
  25460. 'U': 722,
  25461. 'V': 667,
  25462. 'W': 944,
  25463. 'X': 667,
  25464. 'Y': 667,
  25465. 'Z': 611,
  25466. 'bracketleft': 333,
  25467. 'backslash': 278,
  25468. 'bracketright': 333,
  25469. 'asciicircum': 584,
  25470. 'underscore': 556,
  25471. 'quoteleft': 278,
  25472. 'a': 556,
  25473. 'b': 611,
  25474. 'c': 556,
  25475. 'd': 611,
  25476. 'e': 556,
  25477. 'f': 333,
  25478. 'g': 611,
  25479. 'h': 611,
  25480. 'i': 278,
  25481. 'j': 278,
  25482. 'k': 556,
  25483. 'l': 278,
  25484. 'm': 889,
  25485. 'n': 611,
  25486. 'o': 611,
  25487. 'p': 611,
  25488. 'q': 611,
  25489. 'r': 389,
  25490. 's': 556,
  25491. 't': 333,
  25492. 'u': 611,
  25493. 'v': 556,
  25494. 'w': 778,
  25495. 'x': 556,
  25496. 'y': 556,
  25497. 'z': 500,
  25498. 'braceleft': 389,
  25499. 'bar': 280,
  25500. 'braceright': 389,
  25501. 'asciitilde': 584,
  25502. 'exclamdown': 333,
  25503. 'cent': 556,
  25504. 'sterling': 556,
  25505. 'fraction': 167,
  25506. 'yen': 556,
  25507. 'florin': 556,
  25508. 'section': 556,
  25509. 'currency': 556,
  25510. 'quotesingle': 238,
  25511. 'quotedblleft': 500,
  25512. 'guillemotleft': 556,
  25513. 'guilsinglleft': 333,
  25514. 'guilsinglright': 333,
  25515. 'fi': 611,
  25516. 'fl': 611,
  25517. 'endash': 556,
  25518. 'dagger': 556,
  25519. 'daggerdbl': 556,
  25520. 'periodcentered': 278,
  25521. 'paragraph': 556,
  25522. 'bullet': 350,
  25523. 'quotesinglbase': 278,
  25524. 'quotedblbase': 500,
  25525. 'quotedblright': 500,
  25526. 'guillemotright': 556,
  25527. 'ellipsis': 1000,
  25528. 'perthousand': 1000,
  25529. 'questiondown': 611,
  25530. 'grave': 333,
  25531. 'acute': 333,
  25532. 'circumflex': 333,
  25533. 'tilde': 333,
  25534. 'macron': 333,
  25535. 'breve': 333,
  25536. 'dotaccent': 333,
  25537. 'dieresis': 333,
  25538. 'ring': 333,
  25539. 'cedilla': 333,
  25540. 'hungarumlaut': 333,
  25541. 'ogonek': 333,
  25542. 'caron': 333,
  25543. 'emdash': 1000,
  25544. 'AE': 1000,
  25545. 'ordfeminine': 370,
  25546. 'Lslash': 611,
  25547. 'Oslash': 778,
  25548. 'OE': 1000,
  25549. 'ordmasculine': 365,
  25550. 'ae': 889,
  25551. 'dotlessi': 278,
  25552. 'lslash': 278,
  25553. 'oslash': 611,
  25554. 'oe': 944,
  25555. 'germandbls': 611,
  25556. 'Idieresis': 278,
  25557. 'eacute': 556,
  25558. 'abreve': 556,
  25559. 'uhungarumlaut': 611,
  25560. 'ecaron': 556,
  25561. 'Ydieresis': 667,
  25562. 'divide': 584,
  25563. 'Yacute': 667,
  25564. 'Acircumflex': 722,
  25565. 'aacute': 556,
  25566. 'Ucircumflex': 722,
  25567. 'yacute': 556,
  25568. 'scommaaccent': 556,
  25569. 'ecircumflex': 556,
  25570. 'Uring': 722,
  25571. 'Udieresis': 722,
  25572. 'aogonek': 556,
  25573. 'Uacute': 722,
  25574. 'uogonek': 611,
  25575. 'Edieresis': 667,
  25576. 'Dcroat': 722,
  25577. 'commaaccent': 250,
  25578. 'copyright': 737,
  25579. 'Emacron': 667,
  25580. 'ccaron': 556,
  25581. 'aring': 556,
  25582. 'Ncommaaccent': 722,
  25583. 'lacute': 278,
  25584. 'agrave': 556,
  25585. 'Tcommaaccent': 611,
  25586. 'Cacute': 722,
  25587. 'atilde': 556,
  25588. 'Edotaccent': 667,
  25589. 'scaron': 556,
  25590. 'scedilla': 556,
  25591. 'iacute': 278,
  25592. 'lozenge': 494,
  25593. 'Rcaron': 722,
  25594. 'Gcommaaccent': 778,
  25595. 'ucircumflex': 611,
  25596. 'acircumflex': 556,
  25597. 'Amacron': 722,
  25598. 'rcaron': 389,
  25599. 'ccedilla': 556,
  25600. 'Zdotaccent': 611,
  25601. 'Thorn': 667,
  25602. 'Omacron': 778,
  25603. 'Racute': 722,
  25604. 'Sacute': 667,
  25605. 'dcaron': 743,
  25606. 'Umacron': 722,
  25607. 'uring': 611,
  25608. 'threesuperior': 333,
  25609. 'Ograve': 778,
  25610. 'Agrave': 722,
  25611. 'Abreve': 722,
  25612. 'multiply': 584,
  25613. 'uacute': 611,
  25614. 'Tcaron': 611,
  25615. 'partialdiff': 494,
  25616. 'ydieresis': 556,
  25617. 'Nacute': 722,
  25618. 'icircumflex': 278,
  25619. 'Ecircumflex': 667,
  25620. 'adieresis': 556,
  25621. 'edieresis': 556,
  25622. 'cacute': 556,
  25623. 'nacute': 611,
  25624. 'umacron': 611,
  25625. 'Ncaron': 722,
  25626. 'Iacute': 278,
  25627. 'plusminus': 584,
  25628. 'brokenbar': 280,
  25629. 'registered': 737,
  25630. 'Gbreve': 778,
  25631. 'Idotaccent': 278,
  25632. 'summation': 600,
  25633. 'Egrave': 667,
  25634. 'racute': 389,
  25635. 'omacron': 611,
  25636. 'Zacute': 611,
  25637. 'Zcaron': 611,
  25638. 'greaterequal': 549,
  25639. 'Eth': 722,
  25640. 'Ccedilla': 722,
  25641. 'lcommaaccent': 278,
  25642. 'tcaron': 389,
  25643. 'eogonek': 556,
  25644. 'Uogonek': 722,
  25645. 'Aacute': 722,
  25646. 'Adieresis': 722,
  25647. 'egrave': 556,
  25648. 'zacute': 500,
  25649. 'iogonek': 278,
  25650. 'Oacute': 778,
  25651. 'oacute': 611,
  25652. 'amacron': 556,
  25653. 'sacute': 556,
  25654. 'idieresis': 278,
  25655. 'Ocircumflex': 778,
  25656. 'Ugrave': 722,
  25657. 'Delta': 612,
  25658. 'thorn': 611,
  25659. 'twosuperior': 333,
  25660. 'Odieresis': 778,
  25661. 'mu': 611,
  25662. 'igrave': 278,
  25663. 'ohungarumlaut': 611,
  25664. 'Eogonek': 667,
  25665. 'dcroat': 611,
  25666. 'threequarters': 834,
  25667. 'Scedilla': 667,
  25668. 'lcaron': 400,
  25669. 'Kcommaaccent': 722,
  25670. 'Lacute': 611,
  25671. 'trademark': 1000,
  25672. 'edotaccent': 556,
  25673. 'Igrave': 278,
  25674. 'Imacron': 278,
  25675. 'Lcaron': 611,
  25676. 'onehalf': 834,
  25677. 'lessequal': 549,
  25678. 'ocircumflex': 611,
  25679. 'ntilde': 611,
  25680. 'Uhungarumlaut': 722,
  25681. 'Eacute': 667,
  25682. 'emacron': 556,
  25683. 'gbreve': 611,
  25684. 'onequarter': 834,
  25685. 'Scaron': 667,
  25686. 'Scommaaccent': 667,
  25687. 'Ohungarumlaut': 778,
  25688. 'degree': 400,
  25689. 'ograve': 611,
  25690. 'Ccaron': 722,
  25691. 'ugrave': 611,
  25692. 'radical': 549,
  25693. 'Dcaron': 722,
  25694. 'rcommaaccent': 389,
  25695. 'Ntilde': 722,
  25696. 'otilde': 611,
  25697. 'Rcommaaccent': 722,
  25698. 'Lcommaaccent': 611,
  25699. 'Atilde': 722,
  25700. 'Aogonek': 722,
  25701. 'Aring': 722,
  25702. 'Otilde': 778,
  25703. 'zdotaccent': 500,
  25704. 'Ecaron': 667,
  25705. 'Iogonek': 278,
  25706. 'kcommaaccent': 556,
  25707. 'minus': 584,
  25708. 'Icircumflex': 278,
  25709. 'ncaron': 611,
  25710. 'tcommaaccent': 333,
  25711. 'logicalnot': 584,
  25712. 'odieresis': 611,
  25713. 'udieresis': 611,
  25714. 'notequal': 549,
  25715. 'gcommaaccent': 611,
  25716. 'eth': 611,
  25717. 'zcaron': 500,
  25718. 'ncommaaccent': 611,
  25719. 'onesuperior': 333,
  25720. 'imacron': 278,
  25721. 'Euro': 556
  25722. },
  25723. 'Helvetica-BoldOblique': {
  25724. 'space': 278,
  25725. 'exclam': 333,
  25726. 'quotedbl': 474,
  25727. 'numbersign': 556,
  25728. 'dollar': 556,
  25729. 'percent': 889,
  25730. 'ampersand': 722,
  25731. 'quoteright': 278,
  25732. 'parenleft': 333,
  25733. 'parenright': 333,
  25734. 'asterisk': 389,
  25735. 'plus': 584,
  25736. 'comma': 278,
  25737. 'hyphen': 333,
  25738. 'period': 278,
  25739. 'slash': 278,
  25740. 'zero': 556,
  25741. 'one': 556,
  25742. 'two': 556,
  25743. 'three': 556,
  25744. 'four': 556,
  25745. 'five': 556,
  25746. 'six': 556,
  25747. 'seven': 556,
  25748. 'eight': 556,
  25749. 'nine': 556,
  25750. 'colon': 333,
  25751. 'semicolon': 333,
  25752. 'less': 584,
  25753. 'equal': 584,
  25754. 'greater': 584,
  25755. 'question': 611,
  25756. 'at': 975,
  25757. 'A': 722,
  25758. 'B': 722,
  25759. 'C': 722,
  25760. 'D': 722,
  25761. 'E': 667,
  25762. 'F': 611,
  25763. 'G': 778,
  25764. 'H': 722,
  25765. 'I': 278,
  25766. 'J': 556,
  25767. 'K': 722,
  25768. 'L': 611,
  25769. 'M': 833,
  25770. 'N': 722,
  25771. 'O': 778,
  25772. 'P': 667,
  25773. 'Q': 778,
  25774. 'R': 722,
  25775. 'S': 667,
  25776. 'T': 611,
  25777. 'U': 722,
  25778. 'V': 667,
  25779. 'W': 944,
  25780. 'X': 667,
  25781. 'Y': 667,
  25782. 'Z': 611,
  25783. 'bracketleft': 333,
  25784. 'backslash': 278,
  25785. 'bracketright': 333,
  25786. 'asciicircum': 584,
  25787. 'underscore': 556,
  25788. 'quoteleft': 278,
  25789. 'a': 556,
  25790. 'b': 611,
  25791. 'c': 556,
  25792. 'd': 611,
  25793. 'e': 556,
  25794. 'f': 333,
  25795. 'g': 611,
  25796. 'h': 611,
  25797. 'i': 278,
  25798. 'j': 278,
  25799. 'k': 556,
  25800. 'l': 278,
  25801. 'm': 889,
  25802. 'n': 611,
  25803. 'o': 611,
  25804. 'p': 611,
  25805. 'q': 611,
  25806. 'r': 389,
  25807. 's': 556,
  25808. 't': 333,
  25809. 'u': 611,
  25810. 'v': 556,
  25811. 'w': 778,
  25812. 'x': 556,
  25813. 'y': 556,
  25814. 'z': 500,
  25815. 'braceleft': 389,
  25816. 'bar': 280,
  25817. 'braceright': 389,
  25818. 'asciitilde': 584,
  25819. 'exclamdown': 333,
  25820. 'cent': 556,
  25821. 'sterling': 556,
  25822. 'fraction': 167,
  25823. 'yen': 556,
  25824. 'florin': 556,
  25825. 'section': 556,
  25826. 'currency': 556,
  25827. 'quotesingle': 238,
  25828. 'quotedblleft': 500,
  25829. 'guillemotleft': 556,
  25830. 'guilsinglleft': 333,
  25831. 'guilsinglright': 333,
  25832. 'fi': 611,
  25833. 'fl': 611,
  25834. 'endash': 556,
  25835. 'dagger': 556,
  25836. 'daggerdbl': 556,
  25837. 'periodcentered': 278,
  25838. 'paragraph': 556,
  25839. 'bullet': 350,
  25840. 'quotesinglbase': 278,
  25841. 'quotedblbase': 500,
  25842. 'quotedblright': 500,
  25843. 'guillemotright': 556,
  25844. 'ellipsis': 1000,
  25845. 'perthousand': 1000,
  25846. 'questiondown': 611,
  25847. 'grave': 333,
  25848. 'acute': 333,
  25849. 'circumflex': 333,
  25850. 'tilde': 333,
  25851. 'macron': 333,
  25852. 'breve': 333,
  25853. 'dotaccent': 333,
  25854. 'dieresis': 333,
  25855. 'ring': 333,
  25856. 'cedilla': 333,
  25857. 'hungarumlaut': 333,
  25858. 'ogonek': 333,
  25859. 'caron': 333,
  25860. 'emdash': 1000,
  25861. 'AE': 1000,
  25862. 'ordfeminine': 370,
  25863. 'Lslash': 611,
  25864. 'Oslash': 778,
  25865. 'OE': 1000,
  25866. 'ordmasculine': 365,
  25867. 'ae': 889,
  25868. 'dotlessi': 278,
  25869. 'lslash': 278,
  25870. 'oslash': 611,
  25871. 'oe': 944,
  25872. 'germandbls': 611,
  25873. 'Idieresis': 278,
  25874. 'eacute': 556,
  25875. 'abreve': 556,
  25876. 'uhungarumlaut': 611,
  25877. 'ecaron': 556,
  25878. 'Ydieresis': 667,
  25879. 'divide': 584,
  25880. 'Yacute': 667,
  25881. 'Acircumflex': 722,
  25882. 'aacute': 556,
  25883. 'Ucircumflex': 722,
  25884. 'yacute': 556,
  25885. 'scommaaccent': 556,
  25886. 'ecircumflex': 556,
  25887. 'Uring': 722,
  25888. 'Udieresis': 722,
  25889. 'aogonek': 556,
  25890. 'Uacute': 722,
  25891. 'uogonek': 611,
  25892. 'Edieresis': 667,
  25893. 'Dcroat': 722,
  25894. 'commaaccent': 250,
  25895. 'copyright': 737,
  25896. 'Emacron': 667,
  25897. 'ccaron': 556,
  25898. 'aring': 556,
  25899. 'Ncommaaccent': 722,
  25900. 'lacute': 278,
  25901. 'agrave': 556,
  25902. 'Tcommaaccent': 611,
  25903. 'Cacute': 722,
  25904. 'atilde': 556,
  25905. 'Edotaccent': 667,
  25906. 'scaron': 556,
  25907. 'scedilla': 556,
  25908. 'iacute': 278,
  25909. 'lozenge': 494,
  25910. 'Rcaron': 722,
  25911. 'Gcommaaccent': 778,
  25912. 'ucircumflex': 611,
  25913. 'acircumflex': 556,
  25914. 'Amacron': 722,
  25915. 'rcaron': 389,
  25916. 'ccedilla': 556,
  25917. 'Zdotaccent': 611,
  25918. 'Thorn': 667,
  25919. 'Omacron': 778,
  25920. 'Racute': 722,
  25921. 'Sacute': 667,
  25922. 'dcaron': 743,
  25923. 'Umacron': 722,
  25924. 'uring': 611,
  25925. 'threesuperior': 333,
  25926. 'Ograve': 778,
  25927. 'Agrave': 722,
  25928. 'Abreve': 722,
  25929. 'multiply': 584,
  25930. 'uacute': 611,
  25931. 'Tcaron': 611,
  25932. 'partialdiff': 494,
  25933. 'ydieresis': 556,
  25934. 'Nacute': 722,
  25935. 'icircumflex': 278,
  25936. 'Ecircumflex': 667,
  25937. 'adieresis': 556,
  25938. 'edieresis': 556,
  25939. 'cacute': 556,
  25940. 'nacute': 611,
  25941. 'umacron': 611,
  25942. 'Ncaron': 722,
  25943. 'Iacute': 278,
  25944. 'plusminus': 584,
  25945. 'brokenbar': 280,
  25946. 'registered': 737,
  25947. 'Gbreve': 778,
  25948. 'Idotaccent': 278,
  25949. 'summation': 600,
  25950. 'Egrave': 667,
  25951. 'racute': 389,
  25952. 'omacron': 611,
  25953. 'Zacute': 611,
  25954. 'Zcaron': 611,
  25955. 'greaterequal': 549,
  25956. 'Eth': 722,
  25957. 'Ccedilla': 722,
  25958. 'lcommaaccent': 278,
  25959. 'tcaron': 389,
  25960. 'eogonek': 556,
  25961. 'Uogonek': 722,
  25962. 'Aacute': 722,
  25963. 'Adieresis': 722,
  25964. 'egrave': 556,
  25965. 'zacute': 500,
  25966. 'iogonek': 278,
  25967. 'Oacute': 778,
  25968. 'oacute': 611,
  25969. 'amacron': 556,
  25970. 'sacute': 556,
  25971. 'idieresis': 278,
  25972. 'Ocircumflex': 778,
  25973. 'Ugrave': 722,
  25974. 'Delta': 612,
  25975. 'thorn': 611,
  25976. 'twosuperior': 333,
  25977. 'Odieresis': 778,
  25978. 'mu': 611,
  25979. 'igrave': 278,
  25980. 'ohungarumlaut': 611,
  25981. 'Eogonek': 667,
  25982. 'dcroat': 611,
  25983. 'threequarters': 834,
  25984. 'Scedilla': 667,
  25985. 'lcaron': 400,
  25986. 'Kcommaaccent': 722,
  25987. 'Lacute': 611,
  25988. 'trademark': 1000,
  25989. 'edotaccent': 556,
  25990. 'Igrave': 278,
  25991. 'Imacron': 278,
  25992. 'Lcaron': 611,
  25993. 'onehalf': 834,
  25994. 'lessequal': 549,
  25995. 'ocircumflex': 611,
  25996. 'ntilde': 611,
  25997. 'Uhungarumlaut': 722,
  25998. 'Eacute': 667,
  25999. 'emacron': 556,
  26000. 'gbreve': 611,
  26001. 'onequarter': 834,
  26002. 'Scaron': 667,
  26003. 'Scommaaccent': 667,
  26004. 'Ohungarumlaut': 778,
  26005. 'degree': 400,
  26006. 'ograve': 611,
  26007. 'Ccaron': 722,
  26008. 'ugrave': 611,
  26009. 'radical': 549,
  26010. 'Dcaron': 722,
  26011. 'rcommaaccent': 389,
  26012. 'Ntilde': 722,
  26013. 'otilde': 611,
  26014. 'Rcommaaccent': 722,
  26015. 'Lcommaaccent': 611,
  26016. 'Atilde': 722,
  26017. 'Aogonek': 722,
  26018. 'Aring': 722,
  26019. 'Otilde': 778,
  26020. 'zdotaccent': 500,
  26021. 'Ecaron': 667,
  26022. 'Iogonek': 278,
  26023. 'kcommaaccent': 556,
  26024. 'minus': 584,
  26025. 'Icircumflex': 278,
  26026. 'ncaron': 611,
  26027. 'tcommaaccent': 333,
  26028. 'logicalnot': 584,
  26029. 'odieresis': 611,
  26030. 'udieresis': 611,
  26031. 'notequal': 549,
  26032. 'gcommaaccent': 611,
  26033. 'eth': 611,
  26034. 'zcaron': 500,
  26035. 'ncommaaccent': 611,
  26036. 'onesuperior': 333,
  26037. 'imacron': 278,
  26038. 'Euro': 556
  26039. },
  26040. 'Helvetica-Oblique' : {
  26041. 'space': 278,
  26042. 'exclam': 278,
  26043. 'quotedbl': 355,
  26044. 'numbersign': 556,
  26045. 'dollar': 556,
  26046. 'percent': 889,
  26047. 'ampersand': 667,
  26048. 'quoteright': 222,
  26049. 'parenleft': 333,
  26050. 'parenright': 333,
  26051. 'asterisk': 389,
  26052. 'plus': 584,
  26053. 'comma': 278,
  26054. 'hyphen': 333,
  26055. 'period': 278,
  26056. 'slash': 278,
  26057. 'zero': 556,
  26058. 'one': 556,
  26059. 'two': 556,
  26060. 'three': 556,
  26061. 'four': 556,
  26062. 'five': 556,
  26063. 'six': 556,
  26064. 'seven': 556,
  26065. 'eight': 556,
  26066. 'nine': 556,
  26067. 'colon': 278,
  26068. 'semicolon': 278,
  26069. 'less': 584,
  26070. 'equal': 584,
  26071. 'greater': 584,
  26072. 'question': 556,
  26073. 'at': 1015,
  26074. 'A': 667,
  26075. 'B': 667,
  26076. 'C': 722,
  26077. 'D': 722,
  26078. 'E': 667,
  26079. 'F': 611,
  26080. 'G': 778,
  26081. 'H': 722,
  26082. 'I': 278,
  26083. 'J': 500,
  26084. 'K': 667,
  26085. 'L': 556,
  26086. 'M': 833,
  26087. 'N': 722,
  26088. 'O': 778,
  26089. 'P': 667,
  26090. 'Q': 778,
  26091. 'R': 722,
  26092. 'S': 667,
  26093. 'T': 611,
  26094. 'U': 722,
  26095. 'V': 667,
  26096. 'W': 944,
  26097. 'X': 667,
  26098. 'Y': 667,
  26099. 'Z': 611,
  26100. 'bracketleft': 278,
  26101. 'backslash': 278,
  26102. 'bracketright': 278,
  26103. 'asciicircum': 469,
  26104. 'underscore': 556,
  26105. 'quoteleft': 222,
  26106. 'a': 556,
  26107. 'b': 556,
  26108. 'c': 500,
  26109. 'd': 556,
  26110. 'e': 556,
  26111. 'f': 278,
  26112. 'g': 556,
  26113. 'h': 556,
  26114. 'i': 222,
  26115. 'j': 222,
  26116. 'k': 500,
  26117. 'l': 222,
  26118. 'm': 833,
  26119. 'n': 556,
  26120. 'o': 556,
  26121. 'p': 556,
  26122. 'q': 556,
  26123. 'r': 333,
  26124. 's': 500,
  26125. 't': 278,
  26126. 'u': 556,
  26127. 'v': 500,
  26128. 'w': 722,
  26129. 'x': 500,
  26130. 'y': 500,
  26131. 'z': 500,
  26132. 'braceleft': 334,
  26133. 'bar': 260,
  26134. 'braceright': 334,
  26135. 'asciitilde': 584,
  26136. 'exclamdown': 333,
  26137. 'cent': 556,
  26138. 'sterling': 556,
  26139. 'fraction': 167,
  26140. 'yen': 556,
  26141. 'florin': 556,
  26142. 'section': 556,
  26143. 'currency': 556,
  26144. 'quotesingle': 191,
  26145. 'quotedblleft': 333,
  26146. 'guillemotleft': 556,
  26147. 'guilsinglleft': 333,
  26148. 'guilsinglright': 333,
  26149. 'fi': 500,
  26150. 'fl': 500,
  26151. 'endash': 556,
  26152. 'dagger': 556,
  26153. 'daggerdbl': 556,
  26154. 'periodcentered': 278,
  26155. 'paragraph': 537,
  26156. 'bullet': 350,
  26157. 'quotesinglbase': 222,
  26158. 'quotedblbase': 333,
  26159. 'quotedblright': 333,
  26160. 'guillemotright': 556,
  26161. 'ellipsis': 1000,
  26162. 'perthousand': 1000,
  26163. 'questiondown': 611,
  26164. 'grave': 333,
  26165. 'acute': 333,
  26166. 'circumflex': 333,
  26167. 'tilde': 333,
  26168. 'macron': 333,
  26169. 'breve': 333,
  26170. 'dotaccent': 333,
  26171. 'dieresis': 333,
  26172. 'ring': 333,
  26173. 'cedilla': 333,
  26174. 'hungarumlaut': 333,
  26175. 'ogonek': 333,
  26176. 'caron': 333,
  26177. 'emdash': 1000,
  26178. 'AE': 1000,
  26179. 'ordfeminine': 370,
  26180. 'Lslash': 556,
  26181. 'Oslash': 778,
  26182. 'OE': 1000,
  26183. 'ordmasculine': 365,
  26184. 'ae': 889,
  26185. 'dotlessi': 278,
  26186. 'lslash': 222,
  26187. 'oslash': 611,
  26188. 'oe': 944,
  26189. 'germandbls': 611,
  26190. 'Idieresis': 278,
  26191. 'eacute': 556,
  26192. 'abreve': 556,
  26193. 'uhungarumlaut': 556,
  26194. 'ecaron': 556,
  26195. 'Ydieresis': 667,
  26196. 'divide': 584,
  26197. 'Yacute': 667,
  26198. 'Acircumflex': 667,
  26199. 'aacute': 556,
  26200. 'Ucircumflex': 722,
  26201. 'yacute': 500,
  26202. 'scommaaccent': 500,
  26203. 'ecircumflex': 556,
  26204. 'Uring': 722,
  26205. 'Udieresis': 722,
  26206. 'aogonek': 556,
  26207. 'Uacute': 722,
  26208. 'uogonek': 556,
  26209. 'Edieresis': 667,
  26210. 'Dcroat': 722,
  26211. 'commaaccent': 250,
  26212. 'copyright': 737,
  26213. 'Emacron': 667,
  26214. 'ccaron': 500,
  26215. 'aring': 556,
  26216. 'Ncommaaccent': 722,
  26217. 'lacute': 222,
  26218. 'agrave': 556,
  26219. 'Tcommaaccent': 611,
  26220. 'Cacute': 722,
  26221. 'atilde': 556,
  26222. 'Edotaccent': 667,
  26223. 'scaron': 500,
  26224. 'scedilla': 500,
  26225. 'iacute': 278,
  26226. 'lozenge': 471,
  26227. 'Rcaron': 722,
  26228. 'Gcommaaccent': 778,
  26229. 'ucircumflex': 556,
  26230. 'acircumflex': 556,
  26231. 'Amacron': 667,
  26232. 'rcaron': 333,
  26233. 'ccedilla': 500,
  26234. 'Zdotaccent': 611,
  26235. 'Thorn': 667,
  26236. 'Omacron': 778,
  26237. 'Racute': 722,
  26238. 'Sacute': 667,
  26239. 'dcaron': 643,
  26240. 'Umacron': 722,
  26241. 'uring': 556,
  26242. 'threesuperior': 333,
  26243. 'Ograve': 778,
  26244. 'Agrave': 667,
  26245. 'Abreve': 667,
  26246. 'multiply': 584,
  26247. 'uacute': 556,
  26248. 'Tcaron': 611,
  26249. 'partialdiff': 476,
  26250. 'ydieresis': 500,
  26251. 'Nacute': 722,
  26252. 'icircumflex': 278,
  26253. 'Ecircumflex': 667,
  26254. 'adieresis': 556,
  26255. 'edieresis': 556,
  26256. 'cacute': 500,
  26257. 'nacute': 556,
  26258. 'umacron': 556,
  26259. 'Ncaron': 722,
  26260. 'Iacute': 278,
  26261. 'plusminus': 584,
  26262. 'brokenbar': 260,
  26263. 'registered': 737,
  26264. 'Gbreve': 778,
  26265. 'Idotaccent': 278,
  26266. 'summation': 600,
  26267. 'Egrave': 667,
  26268. 'racute': 333,
  26269. 'omacron': 556,
  26270. 'Zacute': 611,
  26271. 'Zcaron': 611,
  26272. 'greaterequal': 549,
  26273. 'Eth': 722,
  26274. 'Ccedilla': 722,
  26275. 'lcommaaccent': 222,
  26276. 'tcaron': 317,
  26277. 'eogonek': 556,
  26278. 'Uogonek': 722,
  26279. 'Aacute': 667,
  26280. 'Adieresis': 667,
  26281. 'egrave': 556,
  26282. 'zacute': 500,
  26283. 'iogonek': 222,
  26284. 'Oacute': 778,
  26285. 'oacute': 556,
  26286. 'amacron': 556,
  26287. 'sacute': 500,
  26288. 'idieresis': 278,
  26289. 'Ocircumflex': 778,
  26290. 'Ugrave': 722,
  26291. 'Delta': 612,
  26292. 'thorn': 556,
  26293. 'twosuperior': 333,
  26294. 'Odieresis': 778,
  26295. 'mu': 556,
  26296. 'igrave': 278,
  26297. 'ohungarumlaut': 556,
  26298. 'Eogonek': 667,
  26299. 'dcroat': 556,
  26300. 'threequarters': 834,
  26301. 'Scedilla': 667,
  26302. 'lcaron': 299,
  26303. 'Kcommaaccent': 667,
  26304. 'Lacute': 556,
  26305. 'trademark': 1000,
  26306. 'edotaccent': 556,
  26307. 'Igrave': 278,
  26308. 'Imacron': 278,
  26309. 'Lcaron': 556,
  26310. 'onehalf': 834,
  26311. 'lessequal': 549,
  26312. 'ocircumflex': 556,
  26313. 'ntilde': 556,
  26314. 'Uhungarumlaut': 722,
  26315. 'Eacute': 667,
  26316. 'emacron': 556,
  26317. 'gbreve': 556,
  26318. 'onequarter': 834,
  26319. 'Scaron': 667,
  26320. 'Scommaaccent': 667,
  26321. 'Ohungarumlaut': 778,
  26322. 'degree': 400,
  26323. 'ograve': 556,
  26324. 'Ccaron': 722,
  26325. 'ugrave': 556,
  26326. 'radical': 453,
  26327. 'Dcaron': 722,
  26328. 'rcommaaccent': 333,
  26329. 'Ntilde': 722,
  26330. 'otilde': 556,
  26331. 'Rcommaaccent': 722,
  26332. 'Lcommaaccent': 556,
  26333. 'Atilde': 667,
  26334. 'Aogonek': 667,
  26335. 'Aring': 667,
  26336. 'Otilde': 778,
  26337. 'zdotaccent': 500,
  26338. 'Ecaron': 667,
  26339. 'Iogonek': 278,
  26340. 'kcommaaccent': 500,
  26341. 'minus': 584,
  26342. 'Icircumflex': 278,
  26343. 'ncaron': 556,
  26344. 'tcommaaccent': 278,
  26345. 'logicalnot': 584,
  26346. 'odieresis': 556,
  26347. 'udieresis': 556,
  26348. 'notequal': 549,
  26349. 'gcommaaccent': 556,
  26350. 'eth': 556,
  26351. 'zcaron': 500,
  26352. 'ncommaaccent': 556,
  26353. 'onesuperior': 333,
  26354. 'imacron': 278,
  26355. 'Euro': 556
  26356. },
  26357. 'Symbol': {
  26358. 'space': 250,
  26359. 'exclam': 333,
  26360. 'universal': 713,
  26361. 'numbersign': 500,
  26362. 'existential': 549,
  26363. 'percent': 833,
  26364. 'ampersand': 778,
  26365. 'suchthat': 439,
  26366. 'parenleft': 333,
  26367. 'parenright': 333,
  26368. 'asteriskmath': 500,
  26369. 'plus': 549,
  26370. 'comma': 250,
  26371. 'minus': 549,
  26372. 'period': 250,
  26373. 'slash': 278,
  26374. 'zero': 500,
  26375. 'one': 500,
  26376. 'two': 500,
  26377. 'three': 500,
  26378. 'four': 500,
  26379. 'five': 500,
  26380. 'six': 500,
  26381. 'seven': 500,
  26382. 'eight': 500,
  26383. 'nine': 500,
  26384. 'colon': 278,
  26385. 'semicolon': 278,
  26386. 'less': 549,
  26387. 'equal': 549,
  26388. 'greater': 549,
  26389. 'question': 444,
  26390. 'congruent': 549,
  26391. 'Alpha': 722,
  26392. 'Beta': 667,
  26393. 'Chi': 722,
  26394. 'Delta': 612,
  26395. 'Epsilon': 611,
  26396. 'Phi': 763,
  26397. 'Gamma': 603,
  26398. 'Eta': 722,
  26399. 'Iota': 333,
  26400. 'theta1': 631,
  26401. 'Kappa': 722,
  26402. 'Lambda': 686,
  26403. 'Mu': 889,
  26404. 'Nu': 722,
  26405. 'Omicron': 722,
  26406. 'Pi': 768,
  26407. 'Theta': 741,
  26408. 'Rho': 556,
  26409. 'Sigma': 592,
  26410. 'Tau': 611,
  26411. 'Upsilon': 690,
  26412. 'sigma1': 439,
  26413. 'Omega': 768,
  26414. 'Xi': 645,
  26415. 'Psi': 795,
  26416. 'Zeta': 611,
  26417. 'bracketleft': 333,
  26418. 'therefore': 863,
  26419. 'bracketright': 333,
  26420. 'perpendicular': 658,
  26421. 'underscore': 500,
  26422. 'radicalex': 500,
  26423. 'alpha': 631,
  26424. 'beta': 549,
  26425. 'chi': 549,
  26426. 'delta': 494,
  26427. 'epsilon': 439,
  26428. 'phi': 521,
  26429. 'gamma': 411,
  26430. 'eta': 603,
  26431. 'iota': 329,
  26432. 'phi1': 603,
  26433. 'kappa': 549,
  26434. 'lambda': 549,
  26435. 'mu': 576,
  26436. 'nu': 521,
  26437. 'omicron': 549,
  26438. 'pi': 549,
  26439. 'theta': 521,
  26440. 'rho': 549,
  26441. 'sigma': 603,
  26442. 'tau': 439,
  26443. 'upsilon': 576,
  26444. 'omega1': 713,
  26445. 'omega': 686,
  26446. 'xi': 493,
  26447. 'psi': 686,
  26448. 'zeta': 494,
  26449. 'braceleft': 480,
  26450. 'bar': 200,
  26451. 'braceright': 480,
  26452. 'similar': 549,
  26453. 'Euro': 750,
  26454. 'Upsilon1': 620,
  26455. 'minute': 247,
  26456. 'lessequal': 549,
  26457. 'fraction': 167,
  26458. 'infinity': 713,
  26459. 'florin': 500,
  26460. 'club': 753,
  26461. 'diamond': 753,
  26462. 'heart': 753,
  26463. 'spade': 753,
  26464. 'arrowboth': 1042,
  26465. 'arrowleft': 987,
  26466. 'arrowup': 603,
  26467. 'arrowright': 987,
  26468. 'arrowdown': 603,
  26469. 'degree': 400,
  26470. 'plusminus': 549,
  26471. 'second': 411,
  26472. 'greaterequal': 549,
  26473. 'multiply': 549,
  26474. 'proportional': 713,
  26475. 'partialdiff': 494,
  26476. 'bullet': 460,
  26477. 'divide': 549,
  26478. 'notequal': 549,
  26479. 'equivalence': 549,
  26480. 'approxequal': 549,
  26481. 'ellipsis': 1000,
  26482. 'arrowvertex': 603,
  26483. 'arrowhorizex': 1000,
  26484. 'carriagereturn': 658,
  26485. 'aleph': 823,
  26486. 'Ifraktur': 686,
  26487. 'Rfraktur': 795,
  26488. 'weierstrass': 987,
  26489. 'circlemultiply': 768,
  26490. 'circleplus': 768,
  26491. 'emptyset': 823,
  26492. 'intersection': 768,
  26493. 'union': 768,
  26494. 'propersuperset': 713,
  26495. 'reflexsuperset': 713,
  26496. 'notsubset': 713,
  26497. 'propersubset': 713,
  26498. 'reflexsubset': 713,
  26499. 'element': 713,
  26500. 'notelement': 713,
  26501. 'angle': 768,
  26502. 'gradient': 713,
  26503. 'registerserif': 790,
  26504. 'copyrightserif': 790,
  26505. 'trademarkserif': 890,
  26506. 'product': 823,
  26507. 'radical': 549,
  26508. 'dotmath': 250,
  26509. 'logicalnot': 713,
  26510. 'logicaland': 603,
  26511. 'logicalor': 603,
  26512. 'arrowdblboth': 1042,
  26513. 'arrowdblleft': 987,
  26514. 'arrowdblup': 603,
  26515. 'arrowdblright': 987,
  26516. 'arrowdbldown': 603,
  26517. 'lozenge': 494,
  26518. 'angleleft': 329,
  26519. 'registersans': 790,
  26520. 'copyrightsans': 790,
  26521. 'trademarksans': 786,
  26522. 'summation': 713,
  26523. 'parenlefttp': 384,
  26524. 'parenleftex': 384,
  26525. 'parenleftbt': 384,
  26526. 'bracketlefttp': 384,
  26527. 'bracketleftex': 384,
  26528. 'bracketleftbt': 384,
  26529. 'bracelefttp': 494,
  26530. 'braceleftmid': 494,
  26531. 'braceleftbt': 494,
  26532. 'braceex': 494,
  26533. 'angleright': 329,
  26534. 'integral': 274,
  26535. 'integraltp': 686,
  26536. 'integralex': 686,
  26537. 'integralbt': 686,
  26538. 'parenrighttp': 384,
  26539. 'parenrightex': 384,
  26540. 'parenrightbt': 384,
  26541. 'bracketrighttp': 384,
  26542. 'bracketrightex': 384,
  26543. 'bracketrightbt': 384,
  26544. 'bracerighttp': 494,
  26545. 'bracerightmid': 494,
  26546. 'bracerightbt': 494,
  26547. 'apple': 790
  26548. },
  26549. 'Times-Roman': {
  26550. 'space': 250,
  26551. 'exclam': 333,
  26552. 'quotedbl': 408,
  26553. 'numbersign': 500,
  26554. 'dollar': 500,
  26555. 'percent': 833,
  26556. 'ampersand': 778,
  26557. 'quoteright': 333,
  26558. 'parenleft': 333,
  26559. 'parenright': 333,
  26560. 'asterisk': 500,
  26561. 'plus': 564,
  26562. 'comma': 250,
  26563. 'hyphen': 333,
  26564. 'period': 250,
  26565. 'slash': 278,
  26566. 'zero': 500,
  26567. 'one': 500,
  26568. 'two': 500,
  26569. 'three': 500,
  26570. 'four': 500,
  26571. 'five': 500,
  26572. 'six': 500,
  26573. 'seven': 500,
  26574. 'eight': 500,
  26575. 'nine': 500,
  26576. 'colon': 278,
  26577. 'semicolon': 278,
  26578. 'less': 564,
  26579. 'equal': 564,
  26580. 'greater': 564,
  26581. 'question': 444,
  26582. 'at': 921,
  26583. 'A': 722,
  26584. 'B': 667,
  26585. 'C': 667,
  26586. 'D': 722,
  26587. 'E': 611,
  26588. 'F': 556,
  26589. 'G': 722,
  26590. 'H': 722,
  26591. 'I': 333,
  26592. 'J': 389,
  26593. 'K': 722,
  26594. 'L': 611,
  26595. 'M': 889,
  26596. 'N': 722,
  26597. 'O': 722,
  26598. 'P': 556,
  26599. 'Q': 722,
  26600. 'R': 667,
  26601. 'S': 556,
  26602. 'T': 611,
  26603. 'U': 722,
  26604. 'V': 722,
  26605. 'W': 944,
  26606. 'X': 722,
  26607. 'Y': 722,
  26608. 'Z': 611,
  26609. 'bracketleft': 333,
  26610. 'backslash': 278,
  26611. 'bracketright': 333,
  26612. 'asciicircum': 469,
  26613. 'underscore': 500,
  26614. 'quoteleft': 333,
  26615. 'a': 444,
  26616. 'b': 500,
  26617. 'c': 444,
  26618. 'd': 500,
  26619. 'e': 444,
  26620. 'f': 333,
  26621. 'g': 500,
  26622. 'h': 500,
  26623. 'i': 278,
  26624. 'j': 278,
  26625. 'k': 500,
  26626. 'l': 278,
  26627. 'm': 778,
  26628. 'n': 500,
  26629. 'o': 500,
  26630. 'p': 500,
  26631. 'q': 500,
  26632. 'r': 333,
  26633. 's': 389,
  26634. 't': 278,
  26635. 'u': 500,
  26636. 'v': 500,
  26637. 'w': 722,
  26638. 'x': 500,
  26639. 'y': 500,
  26640. 'z': 444,
  26641. 'braceleft': 480,
  26642. 'bar': 200,
  26643. 'braceright': 480,
  26644. 'asciitilde': 541,
  26645. 'exclamdown': 333,
  26646. 'cent': 500,
  26647. 'sterling': 500,
  26648. 'fraction': 167,
  26649. 'yen': 500,
  26650. 'florin': 500,
  26651. 'section': 500,
  26652. 'currency': 500,
  26653. 'quotesingle': 180,
  26654. 'quotedblleft': 444,
  26655. 'guillemotleft': 500,
  26656. 'guilsinglleft': 333,
  26657. 'guilsinglright': 333,
  26658. 'fi': 556,
  26659. 'fl': 556,
  26660. 'endash': 500,
  26661. 'dagger': 500,
  26662. 'daggerdbl': 500,
  26663. 'periodcentered': 250,
  26664. 'paragraph': 453,
  26665. 'bullet': 350,
  26666. 'quotesinglbase': 333,
  26667. 'quotedblbase': 444,
  26668. 'quotedblright': 444,
  26669. 'guillemotright': 500,
  26670. 'ellipsis': 1000,
  26671. 'perthousand': 1000,
  26672. 'questiondown': 444,
  26673. 'grave': 333,
  26674. 'acute': 333,
  26675. 'circumflex': 333,
  26676. 'tilde': 333,
  26677. 'macron': 333,
  26678. 'breve': 333,
  26679. 'dotaccent': 333,
  26680. 'dieresis': 333,
  26681. 'ring': 333,
  26682. 'cedilla': 333,
  26683. 'hungarumlaut': 333,
  26684. 'ogonek': 333,
  26685. 'caron': 333,
  26686. 'emdash': 1000,
  26687. 'AE': 889,
  26688. 'ordfeminine': 276,
  26689. 'Lslash': 611,
  26690. 'Oslash': 722,
  26691. 'OE': 889,
  26692. 'ordmasculine': 310,
  26693. 'ae': 667,
  26694. 'dotlessi': 278,
  26695. 'lslash': 278,
  26696. 'oslash': 500,
  26697. 'oe': 722,
  26698. 'germandbls': 500,
  26699. 'Idieresis': 333,
  26700. 'eacute': 444,
  26701. 'abreve': 444,
  26702. 'uhungarumlaut': 500,
  26703. 'ecaron': 444,
  26704. 'Ydieresis': 722,
  26705. 'divide': 564,
  26706. 'Yacute': 722,
  26707. 'Acircumflex': 722,
  26708. 'aacute': 444,
  26709. 'Ucircumflex': 722,
  26710. 'yacute': 500,
  26711. 'scommaaccent': 389,
  26712. 'ecircumflex': 444,
  26713. 'Uring': 722,
  26714. 'Udieresis': 722,
  26715. 'aogonek': 444,
  26716. 'Uacute': 722,
  26717. 'uogonek': 500,
  26718. 'Edieresis': 611,
  26719. 'Dcroat': 722,
  26720. 'commaaccent': 250,
  26721. 'copyright': 760,
  26722. 'Emacron': 611,
  26723. 'ccaron': 444,
  26724. 'aring': 444,
  26725. 'Ncommaaccent': 722,
  26726. 'lacute': 278,
  26727. 'agrave': 444,
  26728. 'Tcommaaccent': 611,
  26729. 'Cacute': 667,
  26730. 'atilde': 444,
  26731. 'Edotaccent': 611,
  26732. 'scaron': 389,
  26733. 'scedilla': 389,
  26734. 'iacute': 278,
  26735. 'lozenge': 471,
  26736. 'Rcaron': 667,
  26737. 'Gcommaaccent': 722,
  26738. 'ucircumflex': 500,
  26739. 'acircumflex': 444,
  26740. 'Amacron': 722,
  26741. 'rcaron': 333,
  26742. 'ccedilla': 444,
  26743. 'Zdotaccent': 611,
  26744. 'Thorn': 556,
  26745. 'Omacron': 722,
  26746. 'Racute': 667,
  26747. 'Sacute': 556,
  26748. 'dcaron': 588,
  26749. 'Umacron': 722,
  26750. 'uring': 500,
  26751. 'threesuperior': 300,
  26752. 'Ograve': 722,
  26753. 'Agrave': 722,
  26754. 'Abreve': 722,
  26755. 'multiply': 564,
  26756. 'uacute': 500,
  26757. 'Tcaron': 611,
  26758. 'partialdiff': 476,
  26759. 'ydieresis': 500,
  26760. 'Nacute': 722,
  26761. 'icircumflex': 278,
  26762. 'Ecircumflex': 611,
  26763. 'adieresis': 444,
  26764. 'edieresis': 444,
  26765. 'cacute': 444,
  26766. 'nacute': 500,
  26767. 'umacron': 500,
  26768. 'Ncaron': 722,
  26769. 'Iacute': 333,
  26770. 'plusminus': 564,
  26771. 'brokenbar': 200,
  26772. 'registered': 760,
  26773. 'Gbreve': 722,
  26774. 'Idotaccent': 333,
  26775. 'summation': 600,
  26776. 'Egrave': 611,
  26777. 'racute': 333,
  26778. 'omacron': 500,
  26779. 'Zacute': 611,
  26780. 'Zcaron': 611,
  26781. 'greaterequal': 549,
  26782. 'Eth': 722,
  26783. 'Ccedilla': 667,
  26784. 'lcommaaccent': 278,
  26785. 'tcaron': 326,
  26786. 'eogonek': 444,
  26787. 'Uogonek': 722,
  26788. 'Aacute': 722,
  26789. 'Adieresis': 722,
  26790. 'egrave': 444,
  26791. 'zacute': 444,
  26792. 'iogonek': 278,
  26793. 'Oacute': 722,
  26794. 'oacute': 500,
  26795. 'amacron': 444,
  26796. 'sacute': 389,
  26797. 'idieresis': 278,
  26798. 'Ocircumflex': 722,
  26799. 'Ugrave': 722,
  26800. 'Delta': 612,
  26801. 'thorn': 500,
  26802. 'twosuperior': 300,
  26803. 'Odieresis': 722,
  26804. 'mu': 500,
  26805. 'igrave': 278,
  26806. 'ohungarumlaut': 500,
  26807. 'Eogonek': 611,
  26808. 'dcroat': 500,
  26809. 'threequarters': 750,
  26810. 'Scedilla': 556,
  26811. 'lcaron': 344,
  26812. 'Kcommaaccent': 722,
  26813. 'Lacute': 611,
  26814. 'trademark': 980,
  26815. 'edotaccent': 444,
  26816. 'Igrave': 333,
  26817. 'Imacron': 333,
  26818. 'Lcaron': 611,
  26819. 'onehalf': 750,
  26820. 'lessequal': 549,
  26821. 'ocircumflex': 500,
  26822. 'ntilde': 500,
  26823. 'Uhungarumlaut': 722,
  26824. 'Eacute': 611,
  26825. 'emacron': 444,
  26826. 'gbreve': 500,
  26827. 'onequarter': 750,
  26828. 'Scaron': 556,
  26829. 'Scommaaccent': 556,
  26830. 'Ohungarumlaut': 722,
  26831. 'degree': 400,
  26832. 'ograve': 500,
  26833. 'Ccaron': 667,
  26834. 'ugrave': 500,
  26835. 'radical': 453,
  26836. 'Dcaron': 722,
  26837. 'rcommaaccent': 333,
  26838. 'Ntilde': 722,
  26839. 'otilde': 500,
  26840. 'Rcommaaccent': 667,
  26841. 'Lcommaaccent': 611,
  26842. 'Atilde': 722,
  26843. 'Aogonek': 722,
  26844. 'Aring': 722,
  26845. 'Otilde': 722,
  26846. 'zdotaccent': 444,
  26847. 'Ecaron': 611,
  26848. 'Iogonek': 333,
  26849. 'kcommaaccent': 500,
  26850. 'minus': 564,
  26851. 'Icircumflex': 333,
  26852. 'ncaron': 500,
  26853. 'tcommaaccent': 278,
  26854. 'logicalnot': 564,
  26855. 'odieresis': 500,
  26856. 'udieresis': 500,
  26857. 'notequal': 549,
  26858. 'gcommaaccent': 500,
  26859. 'eth': 500,
  26860. 'zcaron': 444,
  26861. 'ncommaaccent': 500,
  26862. 'onesuperior': 300,
  26863. 'imacron': 278,
  26864. 'Euro': 500
  26865. },
  26866. 'Times-Bold': {
  26867. 'space': 250,
  26868. 'exclam': 333,
  26869. 'quotedbl': 555,
  26870. 'numbersign': 500,
  26871. 'dollar': 500,
  26872. 'percent': 1000,
  26873. 'ampersand': 833,
  26874. 'quoteright': 333,
  26875. 'parenleft': 333,
  26876. 'parenright': 333,
  26877. 'asterisk': 500,
  26878. 'plus': 570,
  26879. 'comma': 250,
  26880. 'hyphen': 333,
  26881. 'period': 250,
  26882. 'slash': 278,
  26883. 'zero': 500,
  26884. 'one': 500,
  26885. 'two': 500,
  26886. 'three': 500,
  26887. 'four': 500,
  26888. 'five': 500,
  26889. 'six': 500,
  26890. 'seven': 500,
  26891. 'eight': 500,
  26892. 'nine': 500,
  26893. 'colon': 333,
  26894. 'semicolon': 333,
  26895. 'less': 570,
  26896. 'equal': 570,
  26897. 'greater': 570,
  26898. 'question': 500,
  26899. 'at': 930,
  26900. 'A': 722,
  26901. 'B': 667,
  26902. 'C': 722,
  26903. 'D': 722,
  26904. 'E': 667,
  26905. 'F': 611,
  26906. 'G': 778,
  26907. 'H': 778,
  26908. 'I': 389,
  26909. 'J': 500,
  26910. 'K': 778,
  26911. 'L': 667,
  26912. 'M': 944,
  26913. 'N': 722,
  26914. 'O': 778,
  26915. 'P': 611,
  26916. 'Q': 778,
  26917. 'R': 722,
  26918. 'S': 556,
  26919. 'T': 667,
  26920. 'U': 722,
  26921. 'V': 722,
  26922. 'W': 1000,
  26923. 'X': 722,
  26924. 'Y': 722,
  26925. 'Z': 667,
  26926. 'bracketleft': 333,
  26927. 'backslash': 278,
  26928. 'bracketright': 333,
  26929. 'asciicircum': 581,
  26930. 'underscore': 500,
  26931. 'quoteleft': 333,
  26932. 'a': 500,
  26933. 'b': 556,
  26934. 'c': 444,
  26935. 'd': 556,
  26936. 'e': 444,
  26937. 'f': 333,
  26938. 'g': 500,
  26939. 'h': 556,
  26940. 'i': 278,
  26941. 'j': 333,
  26942. 'k': 556,
  26943. 'l': 278,
  26944. 'm': 833,
  26945. 'n': 556,
  26946. 'o': 500,
  26947. 'p': 556,
  26948. 'q': 556,
  26949. 'r': 444,
  26950. 's': 389,
  26951. 't': 333,
  26952. 'u': 556,
  26953. 'v': 500,
  26954. 'w': 722,
  26955. 'x': 500,
  26956. 'y': 500,
  26957. 'z': 444,
  26958. 'braceleft': 394,
  26959. 'bar': 220,
  26960. 'braceright': 394,
  26961. 'asciitilde': 520,
  26962. 'exclamdown': 333,
  26963. 'cent': 500,
  26964. 'sterling': 500,
  26965. 'fraction': 167,
  26966. 'yen': 500,
  26967. 'florin': 500,
  26968. 'section': 500,
  26969. 'currency': 500,
  26970. 'quotesingle': 278,
  26971. 'quotedblleft': 500,
  26972. 'guillemotleft': 500,
  26973. 'guilsinglleft': 333,
  26974. 'guilsinglright': 333,
  26975. 'fi': 556,
  26976. 'fl': 556,
  26977. 'endash': 500,
  26978. 'dagger': 500,
  26979. 'daggerdbl': 500,
  26980. 'periodcentered': 250,
  26981. 'paragraph': 540,
  26982. 'bullet': 350,
  26983. 'quotesinglbase': 333,
  26984. 'quotedblbase': 500,
  26985. 'quotedblright': 500,
  26986. 'guillemotright': 500,
  26987. 'ellipsis': 1000,
  26988. 'perthousand': 1000,
  26989. 'questiondown': 500,
  26990. 'grave': 333,
  26991. 'acute': 333,
  26992. 'circumflex': 333,
  26993. 'tilde': 333,
  26994. 'macron': 333,
  26995. 'breve': 333,
  26996. 'dotaccent': 333,
  26997. 'dieresis': 333,
  26998. 'ring': 333,
  26999. 'cedilla': 333,
  27000. 'hungarumlaut': 333,
  27001. 'ogonek': 333,
  27002. 'caron': 333,
  27003. 'emdash': 1000,
  27004. 'AE': 1000,
  27005. 'ordfeminine': 300,
  27006. 'Lslash': 667,
  27007. 'Oslash': 778,
  27008. 'OE': 1000,
  27009. 'ordmasculine': 330,
  27010. 'ae': 722,
  27011. 'dotlessi': 278,
  27012. 'lslash': 278,
  27013. 'oslash': 500,
  27014. 'oe': 722,
  27015. 'germandbls': 556,
  27016. 'Idieresis': 389,
  27017. 'eacute': 444,
  27018. 'abreve': 500,
  27019. 'uhungarumlaut': 556,
  27020. 'ecaron': 444,
  27021. 'Ydieresis': 722,
  27022. 'divide': 570,
  27023. 'Yacute': 722,
  27024. 'Acircumflex': 722,
  27025. 'aacute': 500,
  27026. 'Ucircumflex': 722,
  27027. 'yacute': 500,
  27028. 'scommaaccent': 389,
  27029. 'ecircumflex': 444,
  27030. 'Uring': 722,
  27031. 'Udieresis': 722,
  27032. 'aogonek': 500,
  27033. 'Uacute': 722,
  27034. 'uogonek': 556,
  27035. 'Edieresis': 667,
  27036. 'Dcroat': 722,
  27037. 'commaaccent': 250,
  27038. 'copyright': 747,
  27039. 'Emacron': 667,
  27040. 'ccaron': 444,
  27041. 'aring': 500,
  27042. 'Ncommaaccent': 722,
  27043. 'lacute': 278,
  27044. 'agrave': 500,
  27045. 'Tcommaaccent': 667,
  27046. 'Cacute': 722,
  27047. 'atilde': 500,
  27048. 'Edotaccent': 667,
  27049. 'scaron': 389,
  27050. 'scedilla': 389,
  27051. 'iacute': 278,
  27052. 'lozenge': 494,
  27053. 'Rcaron': 722,
  27054. 'Gcommaaccent': 778,
  27055. 'ucircumflex': 556,
  27056. 'acircumflex': 500,
  27057. 'Amacron': 722,
  27058. 'rcaron': 444,
  27059. 'ccedilla': 444,
  27060. 'Zdotaccent': 667,
  27061. 'Thorn': 611,
  27062. 'Omacron': 778,
  27063. 'Racute': 722,
  27064. 'Sacute': 556,
  27065. 'dcaron': 672,
  27066. 'Umacron': 722,
  27067. 'uring': 556,
  27068. 'threesuperior': 300,
  27069. 'Ograve': 778,
  27070. 'Agrave': 722,
  27071. 'Abreve': 722,
  27072. 'multiply': 570,
  27073. 'uacute': 556,
  27074. 'Tcaron': 667,
  27075. 'partialdiff': 494,
  27076. 'ydieresis': 500,
  27077. 'Nacute': 722,
  27078. 'icircumflex': 278,
  27079. 'Ecircumflex': 667,
  27080. 'adieresis': 500,
  27081. 'edieresis': 444,
  27082. 'cacute': 444,
  27083. 'nacute': 556,
  27084. 'umacron': 556,
  27085. 'Ncaron': 722,
  27086. 'Iacute': 389,
  27087. 'plusminus': 570,
  27088. 'brokenbar': 220,
  27089. 'registered': 747,
  27090. 'Gbreve': 778,
  27091. 'Idotaccent': 389,
  27092. 'summation': 600,
  27093. 'Egrave': 667,
  27094. 'racute': 444,
  27095. 'omacron': 500,
  27096. 'Zacute': 667,
  27097. 'Zcaron': 667,
  27098. 'greaterequal': 549,
  27099. 'Eth': 722,
  27100. 'Ccedilla': 722,
  27101. 'lcommaaccent': 278,
  27102. 'tcaron': 416,
  27103. 'eogonek': 444,
  27104. 'Uogonek': 722,
  27105. 'Aacute': 722,
  27106. 'Adieresis': 722,
  27107. 'egrave': 444,
  27108. 'zacute': 444,
  27109. 'iogonek': 278,
  27110. 'Oacute': 778,
  27111. 'oacute': 500,
  27112. 'amacron': 500,
  27113. 'sacute': 389,
  27114. 'idieresis': 278,
  27115. 'Ocircumflex': 778,
  27116. 'Ugrave': 722,
  27117. 'Delta': 612,
  27118. 'thorn': 556,
  27119. 'twosuperior': 300,
  27120. 'Odieresis': 778,
  27121. 'mu': 556,
  27122. 'igrave': 278,
  27123. 'ohungarumlaut': 500,
  27124. 'Eogonek': 667,
  27125. 'dcroat': 556,
  27126. 'threequarters': 750,
  27127. 'Scedilla': 556,
  27128. 'lcaron': 394,
  27129. 'Kcommaaccent': 778,
  27130. 'Lacute': 667,
  27131. 'trademark': 1000,
  27132. 'edotaccent': 444,
  27133. 'Igrave': 389,
  27134. 'Imacron': 389,
  27135. 'Lcaron': 667,
  27136. 'onehalf': 750,
  27137. 'lessequal': 549,
  27138. 'ocircumflex': 500,
  27139. 'ntilde': 556,
  27140. 'Uhungarumlaut': 722,
  27141. 'Eacute': 667,
  27142. 'emacron': 444,
  27143. 'gbreve': 500,
  27144. 'onequarter': 750,
  27145. 'Scaron': 556,
  27146. 'Scommaaccent': 556,
  27147. 'Ohungarumlaut': 778,
  27148. 'degree': 400,
  27149. 'ograve': 500,
  27150. 'Ccaron': 722,
  27151. 'ugrave': 556,
  27152. 'radical': 549,
  27153. 'Dcaron': 722,
  27154. 'rcommaaccent': 444,
  27155. 'Ntilde': 722,
  27156. 'otilde': 500,
  27157. 'Rcommaaccent': 722,
  27158. 'Lcommaaccent': 667,
  27159. 'Atilde': 722,
  27160. 'Aogonek': 722,
  27161. 'Aring': 722,
  27162. 'Otilde': 778,
  27163. 'zdotaccent': 444,
  27164. 'Ecaron': 667,
  27165. 'Iogonek': 389,
  27166. 'kcommaaccent': 556,
  27167. 'minus': 570,
  27168. 'Icircumflex': 389,
  27169. 'ncaron': 556,
  27170. 'tcommaaccent': 333,
  27171. 'logicalnot': 570,
  27172. 'odieresis': 500,
  27173. 'udieresis': 556,
  27174. 'notequal': 549,
  27175. 'gcommaaccent': 500,
  27176. 'eth': 500,
  27177. 'zcaron': 444,
  27178. 'ncommaaccent': 556,
  27179. 'onesuperior': 300,
  27180. 'imacron': 278,
  27181. 'Euro': 500
  27182. },
  27183. 'Times-BoldItalic': {
  27184. 'space': 250,
  27185. 'exclam': 389,
  27186. 'quotedbl': 555,
  27187. 'numbersign': 500,
  27188. 'dollar': 500,
  27189. 'percent': 833,
  27190. 'ampersand': 778,
  27191. 'quoteright': 333,
  27192. 'parenleft': 333,
  27193. 'parenright': 333,
  27194. 'asterisk': 500,
  27195. 'plus': 570,
  27196. 'comma': 250,
  27197. 'hyphen': 333,
  27198. 'period': 250,
  27199. 'slash': 278,
  27200. 'zero': 500,
  27201. 'one': 500,
  27202. 'two': 500,
  27203. 'three': 500,
  27204. 'four': 500,
  27205. 'five': 500,
  27206. 'six': 500,
  27207. 'seven': 500,
  27208. 'eight': 500,
  27209. 'nine': 500,
  27210. 'colon': 333,
  27211. 'semicolon': 333,
  27212. 'less': 570,
  27213. 'equal': 570,
  27214. 'greater': 570,
  27215. 'question': 500,
  27216. 'at': 832,
  27217. 'A': 667,
  27218. 'B': 667,
  27219. 'C': 667,
  27220. 'D': 722,
  27221. 'E': 667,
  27222. 'F': 667,
  27223. 'G': 722,
  27224. 'H': 778,
  27225. 'I': 389,
  27226. 'J': 500,
  27227. 'K': 667,
  27228. 'L': 611,
  27229. 'M': 889,
  27230. 'N': 722,
  27231. 'O': 722,
  27232. 'P': 611,
  27233. 'Q': 722,
  27234. 'R': 667,
  27235. 'S': 556,
  27236. 'T': 611,
  27237. 'U': 722,
  27238. 'V': 667,
  27239. 'W': 889,
  27240. 'X': 667,
  27241. 'Y': 611,
  27242. 'Z': 611,
  27243. 'bracketleft': 333,
  27244. 'backslash': 278,
  27245. 'bracketright': 333,
  27246. 'asciicircum': 570,
  27247. 'underscore': 500,
  27248. 'quoteleft': 333,
  27249. 'a': 500,
  27250. 'b': 500,
  27251. 'c': 444,
  27252. 'd': 500,
  27253. 'e': 444,
  27254. 'f': 333,
  27255. 'g': 500,
  27256. 'h': 556,
  27257. 'i': 278,
  27258. 'j': 278,
  27259. 'k': 500,
  27260. 'l': 278,
  27261. 'm': 778,
  27262. 'n': 556,
  27263. 'o': 500,
  27264. 'p': 500,
  27265. 'q': 500,
  27266. 'r': 389,
  27267. 's': 389,
  27268. 't': 278,
  27269. 'u': 556,
  27270. 'v': 444,
  27271. 'w': 667,
  27272. 'x': 500,
  27273. 'y': 444,
  27274. 'z': 389,
  27275. 'braceleft': 348,
  27276. 'bar': 220,
  27277. 'braceright': 348,
  27278. 'asciitilde': 570,
  27279. 'exclamdown': 389,
  27280. 'cent': 500,
  27281. 'sterling': 500,
  27282. 'fraction': 167,
  27283. 'yen': 500,
  27284. 'florin': 500,
  27285. 'section': 500,
  27286. 'currency': 500,
  27287. 'quotesingle': 278,
  27288. 'quotedblleft': 500,
  27289. 'guillemotleft': 500,
  27290. 'guilsinglleft': 333,
  27291. 'guilsinglright': 333,
  27292. 'fi': 556,
  27293. 'fl': 556,
  27294. 'endash': 500,
  27295. 'dagger': 500,
  27296. 'daggerdbl': 500,
  27297. 'periodcentered': 250,
  27298. 'paragraph': 500,
  27299. 'bullet': 350,
  27300. 'quotesinglbase': 333,
  27301. 'quotedblbase': 500,
  27302. 'quotedblright': 500,
  27303. 'guillemotright': 500,
  27304. 'ellipsis': 1000,
  27305. 'perthousand': 1000,
  27306. 'questiondown': 500,
  27307. 'grave': 333,
  27308. 'acute': 333,
  27309. 'circumflex': 333,
  27310. 'tilde': 333,
  27311. 'macron': 333,
  27312. 'breve': 333,
  27313. 'dotaccent': 333,
  27314. 'dieresis': 333,
  27315. 'ring': 333,
  27316. 'cedilla': 333,
  27317. 'hungarumlaut': 333,
  27318. 'ogonek': 333,
  27319. 'caron': 333,
  27320. 'emdash': 1000,
  27321. 'AE': 944,
  27322. 'ordfeminine': 266,
  27323. 'Lslash': 611,
  27324. 'Oslash': 722,
  27325. 'OE': 944,
  27326. 'ordmasculine': 300,
  27327. 'ae': 722,
  27328. 'dotlessi': 278,
  27329. 'lslash': 278,
  27330. 'oslash': 500,
  27331. 'oe': 722,
  27332. 'germandbls': 500,
  27333. 'Idieresis': 389,
  27334. 'eacute': 444,
  27335. 'abreve': 500,
  27336. 'uhungarumlaut': 556,
  27337. 'ecaron': 444,
  27338. 'Ydieresis': 611,
  27339. 'divide': 570,
  27340. 'Yacute': 611,
  27341. 'Acircumflex': 667,
  27342. 'aacute': 500,
  27343. 'Ucircumflex': 722,
  27344. 'yacute': 444,
  27345. 'scommaaccent': 389,
  27346. 'ecircumflex': 444,
  27347. 'Uring': 722,
  27348. 'Udieresis': 722,
  27349. 'aogonek': 500,
  27350. 'Uacute': 722,
  27351. 'uogonek': 556,
  27352. 'Edieresis': 667,
  27353. 'Dcroat': 722,
  27354. 'commaaccent': 250,
  27355. 'copyright': 747,
  27356. 'Emacron': 667,
  27357. 'ccaron': 444,
  27358. 'aring': 500,
  27359. 'Ncommaaccent': 722,
  27360. 'lacute': 278,
  27361. 'agrave': 500,
  27362. 'Tcommaaccent': 611,
  27363. 'Cacute': 667,
  27364. 'atilde': 500,
  27365. 'Edotaccent': 667,
  27366. 'scaron': 389,
  27367. 'scedilla': 389,
  27368. 'iacute': 278,
  27369. 'lozenge': 494,
  27370. 'Rcaron': 667,
  27371. 'Gcommaaccent': 722,
  27372. 'ucircumflex': 556,
  27373. 'acircumflex': 500,
  27374. 'Amacron': 667,
  27375. 'rcaron': 389,
  27376. 'ccedilla': 444,
  27377. 'Zdotaccent': 611,
  27378. 'Thorn': 611,
  27379. 'Omacron': 722,
  27380. 'Racute': 667,
  27381. 'Sacute': 556,
  27382. 'dcaron': 608,
  27383. 'Umacron': 722,
  27384. 'uring': 556,
  27385. 'threesuperior': 300,
  27386. 'Ograve': 722,
  27387. 'Agrave': 667,
  27388. 'Abreve': 667,
  27389. 'multiply': 570,
  27390. 'uacute': 556,
  27391. 'Tcaron': 611,
  27392. 'partialdiff': 494,
  27393. 'ydieresis': 444,
  27394. 'Nacute': 722,
  27395. 'icircumflex': 278,
  27396. 'Ecircumflex': 667,
  27397. 'adieresis': 500,
  27398. 'edieresis': 444,
  27399. 'cacute': 444,
  27400. 'nacute': 556,
  27401. 'umacron': 556,
  27402. 'Ncaron': 722,
  27403. 'Iacute': 389,
  27404. 'plusminus': 570,
  27405. 'brokenbar': 220,
  27406. 'registered': 747,
  27407. 'Gbreve': 722,
  27408. 'Idotaccent': 389,
  27409. 'summation': 600,
  27410. 'Egrave': 667,
  27411. 'racute': 389,
  27412. 'omacron': 500,
  27413. 'Zacute': 611,
  27414. 'Zcaron': 611,
  27415. 'greaterequal': 549,
  27416. 'Eth': 722,
  27417. 'Ccedilla': 667,
  27418. 'lcommaaccent': 278,
  27419. 'tcaron': 366,
  27420. 'eogonek': 444,
  27421. 'Uogonek': 722,
  27422. 'Aacute': 667,
  27423. 'Adieresis': 667,
  27424. 'egrave': 444,
  27425. 'zacute': 389,
  27426. 'iogonek': 278,
  27427. 'Oacute': 722,
  27428. 'oacute': 500,
  27429. 'amacron': 500,
  27430. 'sacute': 389,
  27431. 'idieresis': 278,
  27432. 'Ocircumflex': 722,
  27433. 'Ugrave': 722,
  27434. 'Delta': 612,
  27435. 'thorn': 500,
  27436. 'twosuperior': 300,
  27437. 'Odieresis': 722,
  27438. 'mu': 576,
  27439. 'igrave': 278,
  27440. 'ohungarumlaut': 500,
  27441. 'Eogonek': 667,
  27442. 'dcroat': 500,
  27443. 'threequarters': 750,
  27444. 'Scedilla': 556,
  27445. 'lcaron': 382,
  27446. 'Kcommaaccent': 667,
  27447. 'Lacute': 611,
  27448. 'trademark': 1000,
  27449. 'edotaccent': 444,
  27450. 'Igrave': 389,
  27451. 'Imacron': 389,
  27452. 'Lcaron': 611,
  27453. 'onehalf': 750,
  27454. 'lessequal': 549,
  27455. 'ocircumflex': 500,
  27456. 'ntilde': 556,
  27457. 'Uhungarumlaut': 722,
  27458. 'Eacute': 667,
  27459. 'emacron': 444,
  27460. 'gbreve': 500,
  27461. 'onequarter': 750,
  27462. 'Scaron': 556,
  27463. 'Scommaaccent': 556,
  27464. 'Ohungarumlaut': 722,
  27465. 'degree': 400,
  27466. 'ograve': 500,
  27467. 'Ccaron': 667,
  27468. 'ugrave': 556,
  27469. 'radical': 549,
  27470. 'Dcaron': 722,
  27471. 'rcommaaccent': 389,
  27472. 'Ntilde': 722,
  27473. 'otilde': 500,
  27474. 'Rcommaaccent': 667,
  27475. 'Lcommaaccent': 611,
  27476. 'Atilde': 667,
  27477. 'Aogonek': 667,
  27478. 'Aring': 667,
  27479. 'Otilde': 722,
  27480. 'zdotaccent': 389,
  27481. 'Ecaron': 667,
  27482. 'Iogonek': 389,
  27483. 'kcommaaccent': 500,
  27484. 'minus': 606,
  27485. 'Icircumflex': 389,
  27486. 'ncaron': 556,
  27487. 'tcommaaccent': 278,
  27488. 'logicalnot': 606,
  27489. 'odieresis': 500,
  27490. 'udieresis': 556,
  27491. 'notequal': 549,
  27492. 'gcommaaccent': 500,
  27493. 'eth': 500,
  27494. 'zcaron': 389,
  27495. 'ncommaaccent': 556,
  27496. 'onesuperior': 300,
  27497. 'imacron': 278,
  27498. 'Euro': 500
  27499. },
  27500. 'Times-Italic': {
  27501. 'space': 250,
  27502. 'exclam': 333,
  27503. 'quotedbl': 420,
  27504. 'numbersign': 500,
  27505. 'dollar': 500,
  27506. 'percent': 833,
  27507. 'ampersand': 778,
  27508. 'quoteright': 333,
  27509. 'parenleft': 333,
  27510. 'parenright': 333,
  27511. 'asterisk': 500,
  27512. 'plus': 675,
  27513. 'comma': 250,
  27514. 'hyphen': 333,
  27515. 'period': 250,
  27516. 'slash': 278,
  27517. 'zero': 500,
  27518. 'one': 500,
  27519. 'two': 500,
  27520. 'three': 500,
  27521. 'four': 500,
  27522. 'five': 500,
  27523. 'six': 500,
  27524. 'seven': 500,
  27525. 'eight': 500,
  27526. 'nine': 500,
  27527. 'colon': 333,
  27528. 'semicolon': 333,
  27529. 'less': 675,
  27530. 'equal': 675,
  27531. 'greater': 675,
  27532. 'question': 500,
  27533. 'at': 920,
  27534. 'A': 611,
  27535. 'B': 611,
  27536. 'C': 667,
  27537. 'D': 722,
  27538. 'E': 611,
  27539. 'F': 611,
  27540. 'G': 722,
  27541. 'H': 722,
  27542. 'I': 333,
  27543. 'J': 444,
  27544. 'K': 667,
  27545. 'L': 556,
  27546. 'M': 833,
  27547. 'N': 667,
  27548. 'O': 722,
  27549. 'P': 611,
  27550. 'Q': 722,
  27551. 'R': 611,
  27552. 'S': 500,
  27553. 'T': 556,
  27554. 'U': 722,
  27555. 'V': 611,
  27556. 'W': 833,
  27557. 'X': 611,
  27558. 'Y': 556,
  27559. 'Z': 556,
  27560. 'bracketleft': 389,
  27561. 'backslash': 278,
  27562. 'bracketright': 389,
  27563. 'asciicircum': 422,
  27564. 'underscore': 500,
  27565. 'quoteleft': 333,
  27566. 'a': 500,
  27567. 'b': 500,
  27568. 'c': 444,
  27569. 'd': 500,
  27570. 'e': 444,
  27571. 'f': 278,
  27572. 'g': 500,
  27573. 'h': 500,
  27574. 'i': 278,
  27575. 'j': 278,
  27576. 'k': 444,
  27577. 'l': 278,
  27578. 'm': 722,
  27579. 'n': 500,
  27580. 'o': 500,
  27581. 'p': 500,
  27582. 'q': 500,
  27583. 'r': 389,
  27584. 's': 389,
  27585. 't': 278,
  27586. 'u': 500,
  27587. 'v': 444,
  27588. 'w': 667,
  27589. 'x': 444,
  27590. 'y': 444,
  27591. 'z': 389,
  27592. 'braceleft': 400,
  27593. 'bar': 275,
  27594. 'braceright': 400,
  27595. 'asciitilde': 541,
  27596. 'exclamdown': 389,
  27597. 'cent': 500,
  27598. 'sterling': 500,
  27599. 'fraction': 167,
  27600. 'yen': 500,
  27601. 'florin': 500,
  27602. 'section': 500,
  27603. 'currency': 500,
  27604. 'quotesingle': 214,
  27605. 'quotedblleft': 556,
  27606. 'guillemotleft': 500,
  27607. 'guilsinglleft': 333,
  27608. 'guilsinglright': 333,
  27609. 'fi': 500,
  27610. 'fl': 500,
  27611. 'endash': 500,
  27612. 'dagger': 500,
  27613. 'daggerdbl': 500,
  27614. 'periodcentered': 250,
  27615. 'paragraph': 523,
  27616. 'bullet': 350,
  27617. 'quotesinglbase': 333,
  27618. 'quotedblbase': 556,
  27619. 'quotedblright': 556,
  27620. 'guillemotright': 500,
  27621. 'ellipsis': 889,
  27622. 'perthousand': 1000,
  27623. 'questiondown': 500,
  27624. 'grave': 333,
  27625. 'acute': 333,
  27626. 'circumflex': 333,
  27627. 'tilde': 333,
  27628. 'macron': 333,
  27629. 'breve': 333,
  27630. 'dotaccent': 333,
  27631. 'dieresis': 333,
  27632. 'ring': 333,
  27633. 'cedilla': 333,
  27634. 'hungarumlaut': 333,
  27635. 'ogonek': 333,
  27636. 'caron': 333,
  27637. 'emdash': 889,
  27638. 'AE': 889,
  27639. 'ordfeminine': 276,
  27640. 'Lslash': 556,
  27641. 'Oslash': 722,
  27642. 'OE': 944,
  27643. 'ordmasculine': 310,
  27644. 'ae': 667,
  27645. 'dotlessi': 278,
  27646. 'lslash': 278,
  27647. 'oslash': 500,
  27648. 'oe': 667,
  27649. 'germandbls': 500,
  27650. 'Idieresis': 333,
  27651. 'eacute': 444,
  27652. 'abreve': 500,
  27653. 'uhungarumlaut': 500,
  27654. 'ecaron': 444,
  27655. 'Ydieresis': 556,
  27656. 'divide': 675,
  27657. 'Yacute': 556,
  27658. 'Acircumflex': 611,
  27659. 'aacute': 500,
  27660. 'Ucircumflex': 722,
  27661. 'yacute': 444,
  27662. 'scommaaccent': 389,
  27663. 'ecircumflex': 444,
  27664. 'Uring': 722,
  27665. 'Udieresis': 722,
  27666. 'aogonek': 500,
  27667. 'Uacute': 722,
  27668. 'uogonek': 500,
  27669. 'Edieresis': 611,
  27670. 'Dcroat': 722,
  27671. 'commaaccent': 250,
  27672. 'copyright': 760,
  27673. 'Emacron': 611,
  27674. 'ccaron': 444,
  27675. 'aring': 500,
  27676. 'Ncommaaccent': 667,
  27677. 'lacute': 278,
  27678. 'agrave': 500,
  27679. 'Tcommaaccent': 556,
  27680. 'Cacute': 667,
  27681. 'atilde': 500,
  27682. 'Edotaccent': 611,
  27683. 'scaron': 389,
  27684. 'scedilla': 389,
  27685. 'iacute': 278,
  27686. 'lozenge': 471,
  27687. 'Rcaron': 611,
  27688. 'Gcommaaccent': 722,
  27689. 'ucircumflex': 500,
  27690. 'acircumflex': 500,
  27691. 'Amacron': 611,
  27692. 'rcaron': 389,
  27693. 'ccedilla': 444,
  27694. 'Zdotaccent': 556,
  27695. 'Thorn': 611,
  27696. 'Omacron': 722,
  27697. 'Racute': 611,
  27698. 'Sacute': 500,
  27699. 'dcaron': 544,
  27700. 'Umacron': 722,
  27701. 'uring': 500,
  27702. 'threesuperior': 300,
  27703. 'Ograve': 722,
  27704. 'Agrave': 611,
  27705. 'Abreve': 611,
  27706. 'multiply': 675,
  27707. 'uacute': 500,
  27708. 'Tcaron': 556,
  27709. 'partialdiff': 476,
  27710. 'ydieresis': 444,
  27711. 'Nacute': 667,
  27712. 'icircumflex': 278,
  27713. 'Ecircumflex': 611,
  27714. 'adieresis': 500,
  27715. 'edieresis': 444,
  27716. 'cacute': 444,
  27717. 'nacute': 500,
  27718. 'umacron': 500,
  27719. 'Ncaron': 667,
  27720. 'Iacute': 333,
  27721. 'plusminus': 675,
  27722. 'brokenbar': 275,
  27723. 'registered': 760,
  27724. 'Gbreve': 722,
  27725. 'Idotaccent': 333,
  27726. 'summation': 600,
  27727. 'Egrave': 611,
  27728. 'racute': 389,
  27729. 'omacron': 500,
  27730. 'Zacute': 556,
  27731. 'Zcaron': 556,
  27732. 'greaterequal': 549,
  27733. 'Eth': 722,
  27734. 'Ccedilla': 667,
  27735. 'lcommaaccent': 278,
  27736. 'tcaron': 300,
  27737. 'eogonek': 444,
  27738. 'Uogonek': 722,
  27739. 'Aacute': 611,
  27740. 'Adieresis': 611,
  27741. 'egrave': 444,
  27742. 'zacute': 389,
  27743. 'iogonek': 278,
  27744. 'Oacute': 722,
  27745. 'oacute': 500,
  27746. 'amacron': 500,
  27747. 'sacute': 389,
  27748. 'idieresis': 278,
  27749. 'Ocircumflex': 722,
  27750. 'Ugrave': 722,
  27751. 'Delta': 612,
  27752. 'thorn': 500,
  27753. 'twosuperior': 300,
  27754. 'Odieresis': 722,
  27755. 'mu': 500,
  27756. 'igrave': 278,
  27757. 'ohungarumlaut': 500,
  27758. 'Eogonek': 611,
  27759. 'dcroat': 500,
  27760. 'threequarters': 750,
  27761. 'Scedilla': 500,
  27762. 'lcaron': 300,
  27763. 'Kcommaaccent': 667,
  27764. 'Lacute': 556,
  27765. 'trademark': 980,
  27766. 'edotaccent': 444,
  27767. 'Igrave': 333,
  27768. 'Imacron': 333,
  27769. 'Lcaron': 611,
  27770. 'onehalf': 750,
  27771. 'lessequal': 549,
  27772. 'ocircumflex': 500,
  27773. 'ntilde': 500,
  27774. 'Uhungarumlaut': 722,
  27775. 'Eacute': 611,
  27776. 'emacron': 444,
  27777. 'gbreve': 500,
  27778. 'onequarter': 750,
  27779. 'Scaron': 500,
  27780. 'Scommaaccent': 500,
  27781. 'Ohungarumlaut': 722,
  27782. 'degree': 400,
  27783. 'ograve': 500,
  27784. 'Ccaron': 667,
  27785. 'ugrave': 500,
  27786. 'radical': 453,
  27787. 'Dcaron': 722,
  27788. 'rcommaaccent': 389,
  27789. 'Ntilde': 667,
  27790. 'otilde': 500,
  27791. 'Rcommaaccent': 611,
  27792. 'Lcommaaccent': 556,
  27793. 'Atilde': 611,
  27794. 'Aogonek': 611,
  27795. 'Aring': 611,
  27796. 'Otilde': 722,
  27797. 'zdotaccent': 389,
  27798. 'Ecaron': 611,
  27799. 'Iogonek': 333,
  27800. 'kcommaaccent': 444,
  27801. 'minus': 675,
  27802. 'Icircumflex': 333,
  27803. 'ncaron': 500,
  27804. 'tcommaaccent': 278,
  27805. 'logicalnot': 675,
  27806. 'odieresis': 500,
  27807. 'udieresis': 500,
  27808. 'notequal': 549,
  27809. 'gcommaaccent': 500,
  27810. 'eth': 500,
  27811. 'zcaron': 389,
  27812. 'ncommaaccent': 500,
  27813. 'onesuperior': 300,
  27814. 'imacron': 278,
  27815. 'Euro': 500
  27816. },
  27817. 'ZapfDingbats': {
  27818. 'space': 278,
  27819. 'a1': 974,
  27820. 'a2': 961,
  27821. 'a202': 974,
  27822. 'a3': 980,
  27823. 'a4': 719,
  27824. 'a5': 789,
  27825. 'a119': 790,
  27826. 'a118': 791,
  27827. 'a117': 690,
  27828. 'a11': 960,
  27829. 'a12': 939,
  27830. 'a13': 549,
  27831. 'a14': 855,
  27832. 'a15': 911,
  27833. 'a16': 933,
  27834. 'a105': 911,
  27835. 'a17': 945,
  27836. 'a18': 974,
  27837. 'a19': 755,
  27838. 'a20': 846,
  27839. 'a21': 762,
  27840. 'a22': 761,
  27841. 'a23': 571,
  27842. 'a24': 677,
  27843. 'a25': 763,
  27844. 'a26': 760,
  27845. 'a27': 759,
  27846. 'a28': 754,
  27847. 'a6': 494,
  27848. 'a7': 552,
  27849. 'a8': 537,
  27850. 'a9': 577,
  27851. 'a10': 692,
  27852. 'a29': 786,
  27853. 'a30': 788,
  27854. 'a31': 788,
  27855. 'a32': 790,
  27856. 'a33': 793,
  27857. 'a34': 794,
  27858. 'a35': 816,
  27859. 'a36': 823,
  27860. 'a37': 789,
  27861. 'a38': 841,
  27862. 'a39': 823,
  27863. 'a40': 833,
  27864. 'a41': 816,
  27865. 'a42': 831,
  27866. 'a43': 923,
  27867. 'a44': 744,
  27868. 'a45': 723,
  27869. 'a46': 749,
  27870. 'a47': 790,
  27871. 'a48': 792,
  27872. 'a49': 695,
  27873. 'a50': 776,
  27874. 'a51': 768,
  27875. 'a52': 792,
  27876. 'a53': 759,
  27877. 'a54': 707,
  27878. 'a55': 708,
  27879. 'a56': 682,
  27880. 'a57': 701,
  27881. 'a58': 826,
  27882. 'a59': 815,
  27883. 'a60': 789,
  27884. 'a61': 789,
  27885. 'a62': 707,
  27886. 'a63': 687,
  27887. 'a64': 696,
  27888. 'a65': 689,
  27889. 'a66': 786,
  27890. 'a67': 787,
  27891. 'a68': 713,
  27892. 'a69': 791,
  27893. 'a70': 785,
  27894. 'a71': 791,
  27895. 'a72': 873,
  27896. 'a73': 761,
  27897. 'a74': 762,
  27898. 'a203': 762,
  27899. 'a75': 759,
  27900. 'a204': 759,
  27901. 'a76': 892,
  27902. 'a77': 892,
  27903. 'a78': 788,
  27904. 'a79': 784,
  27905. 'a81': 438,
  27906. 'a82': 138,
  27907. 'a83': 277,
  27908. 'a84': 415,
  27909. 'a97': 392,
  27910. 'a98': 392,
  27911. 'a99': 668,
  27912. 'a100': 668,
  27913. 'a89': 390,
  27914. 'a90': 390,
  27915. 'a93': 317,
  27916. 'a94': 317,
  27917. 'a91': 276,
  27918. 'a92': 276,
  27919. 'a205': 509,
  27920. 'a85': 509,
  27921. 'a206': 410,
  27922. 'a86': 410,
  27923. 'a87': 234,
  27924. 'a88': 234,
  27925. 'a95': 334,
  27926. 'a96': 334,
  27927. 'a101': 732,
  27928. 'a102': 544,
  27929. 'a103': 544,
  27930. 'a104': 910,
  27931. 'a106': 667,
  27932. 'a107': 760,
  27933. 'a108': 760,
  27934. 'a112': 776,
  27935. 'a111': 595,
  27936. 'a110': 694,
  27937. 'a109': 626,
  27938. 'a120': 788,
  27939. 'a121': 788,
  27940. 'a122': 788,
  27941. 'a123': 788,
  27942. 'a124': 788,
  27943. 'a125': 788,
  27944. 'a126': 788,
  27945. 'a127': 788,
  27946. 'a128': 788,
  27947. 'a129': 788,
  27948. 'a130': 788,
  27949. 'a131': 788,
  27950. 'a132': 788,
  27951. 'a133': 788,
  27952. 'a134': 788,
  27953. 'a135': 788,
  27954. 'a136': 788,
  27955. 'a137': 788,
  27956. 'a138': 788,
  27957. 'a139': 788,
  27958. 'a140': 788,
  27959. 'a141': 788,
  27960. 'a142': 788,
  27961. 'a143': 788,
  27962. 'a144': 788,
  27963. 'a145': 788,
  27964. 'a146': 788,
  27965. 'a147': 788,
  27966. 'a148': 788,
  27967. 'a149': 788,
  27968. 'a150': 788,
  27969. 'a151': 788,
  27970. 'a152': 788,
  27971. 'a153': 788,
  27972. 'a154': 788,
  27973. 'a155': 788,
  27974. 'a156': 788,
  27975. 'a157': 788,
  27976. 'a158': 788,
  27977. 'a159': 788,
  27978. 'a160': 894,
  27979. 'a161': 838,
  27980. 'a163': 1016,
  27981. 'a164': 458,
  27982. 'a196': 748,
  27983. 'a165': 924,
  27984. 'a192': 748,
  27985. 'a166': 918,
  27986. 'a167': 927,
  27987. 'a168': 928,
  27988. 'a169': 928,
  27989. 'a170': 834,
  27990. 'a171': 873,
  27991. 'a172': 828,
  27992. 'a173': 924,
  27993. 'a162': 924,
  27994. 'a174': 917,
  27995. 'a175': 930,
  27996. 'a176': 931,
  27997. 'a177': 463,
  27998. 'a178': 883,
  27999. 'a179': 836,
  28000. 'a193': 836,
  28001. 'a180': 867,
  28002. 'a199': 867,
  28003. 'a181': 696,
  28004. 'a200': 696,
  28005. 'a182': 874,
  28006. 'a201': 874,
  28007. 'a183': 760,
  28008. 'a184': 946,
  28009. 'a197': 771,
  28010. 'a185': 865,
  28011. 'a194': 771,
  28012. 'a198': 888,
  28013. 'a186': 967,
  28014. 'a195': 888,
  28015. 'a187': 831,
  28016. 'a188': 873,
  28017. 'a189': 927,
  28018. 'a190': 970,
  28019. 'a191': 918
  28020. }
  28021. };
  28022. var EOF = {};
  28023. function isEOF(v) {
  28024. return (v === EOF);
  28025. }
  28026. var Parser = (function ParserClosure() {
  28027. function Parser(lexer, allowStreams, xref) {
  28028. this.lexer = lexer;
  28029. this.allowStreams = allowStreams;
  28030. this.xref = xref;
  28031. this.imageCache = {
  28032. length: 0,
  28033. adler32: 0,
  28034. stream: null
  28035. };
  28036. this.refill();
  28037. }
  28038. Parser.prototype = {
  28039. refill: function Parser_refill() {
  28040. this.buf1 = this.lexer.getObj();
  28041. this.buf2 = this.lexer.getObj();
  28042. },
  28043. shift: function Parser_shift() {
  28044. if (isCmd(this.buf2, 'ID')) {
  28045. this.buf1 = this.buf2;
  28046. this.buf2 = null;
  28047. } else {
  28048. this.buf1 = this.buf2;
  28049. this.buf2 = this.lexer.getObj();
  28050. }
  28051. },
  28052. getObj: function Parser_getObj(cipherTransform) {
  28053. var buf1 = this.buf1;
  28054. this.shift();
  28055. if (buf1 instanceof Cmd) {
  28056. switch (buf1.cmd) {
  28057. case 'BI': // inline image
  28058. return this.makeInlineImage(cipherTransform);
  28059. case '[': // array
  28060. var array = [];
  28061. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28062. array.push(this.getObj(cipherTransform));
  28063. }
  28064. if (isEOF(this.buf1)) {
  28065. error('End of file inside array');
  28066. }
  28067. this.shift();
  28068. return array;
  28069. case '<<': // dictionary or stream
  28070. var dict = new Dict(this.xref);
  28071. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28072. if (!isName(this.buf1)) {
  28073. info('Malformed dictionary: key must be a name object');
  28074. this.shift();
  28075. continue;
  28076. }
  28077. var key = this.buf1.name;
  28078. this.shift();
  28079. if (isEOF(this.buf1)) {
  28080. break;
  28081. }
  28082. dict.set(key, this.getObj(cipherTransform));
  28083. }
  28084. if (isEOF(this.buf1)) {
  28085. error('End of file inside dictionary');
  28086. }
  28087. // Stream objects are not allowed inside content streams or
  28088. // object streams.
  28089. if (isCmd(this.buf2, 'stream')) {
  28090. return (this.allowStreams ?
  28091. this.makeStream(dict, cipherTransform) : dict);
  28092. }
  28093. this.shift();
  28094. return dict;
  28095. default: // simple object
  28096. return buf1;
  28097. }
  28098. }
  28099. if (isInt(buf1)) { // indirect reference or integer
  28100. var num = buf1;
  28101. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28102. var ref = new Ref(num, this.buf1);
  28103. this.shift();
  28104. this.shift();
  28105. return ref;
  28106. }
  28107. return num;
  28108. }
  28109. if (isString(buf1)) { // string
  28110. var str = buf1;
  28111. if (cipherTransform) {
  28112. str = cipherTransform.decryptString(str);
  28113. }
  28114. return str;
  28115. }
  28116. // simple object
  28117. return buf1;
  28118. },
  28119. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28120. var lexer = this.lexer;
  28121. var stream = lexer.stream;
  28122. // parse dictionary
  28123. var dict = new Dict(null);
  28124. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28125. if (!isName(this.buf1)) {
  28126. error('Dictionary key must be a name object');
  28127. }
  28128. var key = this.buf1.name;
  28129. this.shift();
  28130. if (isEOF(this.buf1)) {
  28131. break;
  28132. }
  28133. dict.set(key, this.getObj(cipherTransform));
  28134. }
  28135. // parse image stream
  28136. var startPos = stream.pos;
  28137. // searching for the /EI\s/
  28138. var state = 0, ch, i, ii;
  28139. var E = 0x45, I = 0x49, SPACE = 0x20, NL = 0xA, CR = 0xD;
  28140. while ((ch = stream.getByte()) !== -1) {
  28141. if (state === 0) {
  28142. state = (ch === E) ? 1 : 0;
  28143. } else if (state === 1) {
  28144. state = (ch === I) ? 2 : 0;
  28145. } else {
  28146. assert(state === 2);
  28147. if (ch === SPACE || ch === NL || ch === CR) {
  28148. // Let's check the next five bytes are ASCII... just be sure.
  28149. var n = 5;
  28150. var followingBytes = stream.peekBytes(n);
  28151. for (i = 0; i < n; i++) {
  28152. ch = followingBytes[i];
  28153. if (ch !== NL && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28154. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28155. // it's binary stuff. Resetting the state.
  28156. state = 0;
  28157. break;
  28158. }
  28159. }
  28160. if (state === 2) {
  28161. break; // finished!
  28162. }
  28163. } else {
  28164. state = 0;
  28165. }
  28166. }
  28167. }
  28168. var length = (stream.pos - 4) - startPos;
  28169. var imageStream = stream.makeSubStream(startPos, length, dict);
  28170. // trying to cache repeat images, first we are trying to "warm up" caching
  28171. // using length, then comparing adler32
  28172. var MAX_LENGTH_TO_CACHE = 1000;
  28173. var cacheImage = false, adler32;
  28174. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  28175. var imageBytes = imageStream.getBytes();
  28176. imageStream.reset();
  28177. var a = 1;
  28178. var b = 0;
  28179. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28180. a = (a + (imageBytes[i] & 0xff)) % 65521;
  28181. b = (b + a) % 65521;
  28182. }
  28183. adler32 = (b << 16) | a;
  28184. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  28185. this.buf2 = Cmd.get('EI');
  28186. this.shift();
  28187. this.imageCache.stream.reset();
  28188. return this.imageCache.stream;
  28189. }
  28190. cacheImage = true;
  28191. }
  28192. if (!cacheImage && !this.imageCache.stream) {
  28193. this.imageCache.length = length;
  28194. this.imageCache.stream = null;
  28195. }
  28196. if (cipherTransform) {
  28197. imageStream = cipherTransform.createStream(imageStream, length);
  28198. }
  28199. imageStream = this.filter(imageStream, dict, length);
  28200. imageStream.dict = dict;
  28201. if (cacheImage) {
  28202. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28203. this.imageCache.adler32 = adler32;
  28204. this.imageCache.stream = imageStream;
  28205. }
  28206. this.buf2 = Cmd.get('EI');
  28207. this.shift();
  28208. return imageStream;
  28209. },
  28210. fetchIfRef: function Parser_fetchIfRef(obj) {
  28211. // not relying on the xref.fetchIfRef -- xref might not be set
  28212. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28213. },
  28214. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28215. var lexer = this.lexer;
  28216. var stream = lexer.stream;
  28217. // get stream start position
  28218. lexer.skipToNextLine();
  28219. var pos = stream.pos - 1;
  28220. // get length
  28221. var length = this.fetchIfRef(dict.get('Length'));
  28222. if (!isInt(length)) {
  28223. info('Bad ' + length + ' attribute in stream');
  28224. length = 0;
  28225. }
  28226. // skip over the stream data
  28227. stream.pos = pos + length;
  28228. lexer.nextChar();
  28229. this.shift(); // '>>'
  28230. this.shift(); // 'stream'
  28231. if (!isCmd(this.buf1, 'endstream')) {
  28232. // bad stream length, scanning for endstream
  28233. stream.pos = pos;
  28234. var SCAN_BLOCK_SIZE = 2048;
  28235. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28236. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28237. 0x61, 0x6D];
  28238. var skipped = 0, found = false, i, j;
  28239. while (stream.pos < stream.end) {
  28240. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28241. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28242. if (scanLength <= 0) {
  28243. break;
  28244. }
  28245. found = false;
  28246. for (i = 0, j = 0; i < scanLength; i++) {
  28247. var b = scanBytes[i];
  28248. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28249. i -= j;
  28250. j = 0;
  28251. } else {
  28252. j++;
  28253. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28254. i++;
  28255. found = true;
  28256. break;
  28257. }
  28258. }
  28259. }
  28260. if (found) {
  28261. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28262. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28263. break;
  28264. }
  28265. skipped += scanLength;
  28266. stream.pos += scanLength;
  28267. }
  28268. if (!found) {
  28269. error('Missing endstream');
  28270. }
  28271. length = skipped;
  28272. lexer.nextChar();
  28273. this.shift();
  28274. this.shift();
  28275. }
  28276. this.shift(); // 'endstream'
  28277. stream = stream.makeSubStream(pos, length, dict);
  28278. if (cipherTransform) {
  28279. stream = cipherTransform.createStream(stream, length);
  28280. }
  28281. stream = this.filter(stream, dict, length);
  28282. stream.dict = dict;
  28283. return stream;
  28284. },
  28285. filter: function Parser_filter(stream, dict, length) {
  28286. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28287. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28288. if (isName(filter)) {
  28289. return this.makeFilter(stream, filter.name, length, params);
  28290. }
  28291. var maybeLength = length;
  28292. if (isArray(filter)) {
  28293. var filterArray = filter;
  28294. var paramsArray = params;
  28295. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28296. filter = filterArray[i];
  28297. if (!isName(filter)) {
  28298. error('Bad filter name: ' + filter);
  28299. }
  28300. params = null;
  28301. if (isArray(paramsArray) && (i in paramsArray)) {
  28302. params = paramsArray[i];
  28303. }
  28304. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28305. // after the first stream the length variable is invalid
  28306. maybeLength = null;
  28307. }
  28308. }
  28309. return stream;
  28310. },
  28311. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28312. if (stream.dict.get('Length') === 0) {
  28313. return new NullStream(stream);
  28314. }
  28315. try {
  28316. if (params) {
  28317. params = this.fetchIfRef(params);
  28318. }
  28319. var xrefStreamStats = this.xref.stats.streamTypes;
  28320. if (name === 'FlateDecode' || name === 'Fl') {
  28321. xrefStreamStats[StreamType.FLATE] = true;
  28322. if (params) {
  28323. return new PredictorStream(new FlateStream(stream, maybeLength),
  28324. maybeLength, params);
  28325. }
  28326. return new FlateStream(stream, maybeLength);
  28327. }
  28328. if (name === 'LZWDecode' || name === 'LZW') {
  28329. xrefStreamStats[StreamType.LZW] = true;
  28330. var earlyChange = 1;
  28331. if (params) {
  28332. if (params.has('EarlyChange')) {
  28333. earlyChange = params.get('EarlyChange');
  28334. }
  28335. return new PredictorStream(
  28336. new LZWStream(stream, maybeLength, earlyChange),
  28337. maybeLength, params);
  28338. }
  28339. return new LZWStream(stream, maybeLength, earlyChange);
  28340. }
  28341. if (name === 'DCTDecode' || name === 'DCT') {
  28342. // According to the specification: for inline images, the ID operator
  28343. // shall be followed by a single whitespace character (unless it uses
  28344. // ASCII85Decode or ASCIIHexDecode filters).
  28345. // In practice this only seems to be followed for inline JPEG images,
  28346. // and generally ignoring the first byte of the stream if it is a
  28347. // whitespace char can even *cause* issues (e.g. in the CCITTFaxDecode
  28348. // filters used in issue2984.pdf).
  28349. // Hence when the first byte of the stream of an inline JPEG image is
  28350. // a whitespace character, we thus simply skip over it.
  28351. if (isCmd(this.buf1, 'ID')) {
  28352. var firstByte = stream.peekByte();
  28353. if (firstByte === 0x0A /* LF */ || firstByte === 0x0D /* CR */ ||
  28354. firstByte === 0x20 /* SPACE */) {
  28355. stream.skip();
  28356. }
  28357. }
  28358. xrefStreamStats[StreamType.DCT] = true;
  28359. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28360. }
  28361. if (name === 'JPXDecode' || name === 'JPX') {
  28362. xrefStreamStats[StreamType.JPX] = true;
  28363. return new JpxStream(stream, maybeLength, stream.dict);
  28364. }
  28365. if (name === 'ASCII85Decode' || name === 'A85') {
  28366. xrefStreamStats[StreamType.A85] = true;
  28367. return new Ascii85Stream(stream, maybeLength);
  28368. }
  28369. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28370. xrefStreamStats[StreamType.AHX] = true;
  28371. return new AsciiHexStream(stream, maybeLength);
  28372. }
  28373. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28374. xrefStreamStats[StreamType.CCF] = true;
  28375. return new CCITTFaxStream(stream, maybeLength, params);
  28376. }
  28377. if (name === 'RunLengthDecode' || name === 'RL') {
  28378. xrefStreamStats[StreamType.RL] = true;
  28379. return new RunLengthStream(stream, maybeLength);
  28380. }
  28381. if (name === 'JBIG2Decode') {
  28382. xrefStreamStats[StreamType.JBIG] = true;
  28383. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28384. }
  28385. warn('filter "' + name + '" not supported yet');
  28386. return stream;
  28387. } catch (ex) {
  28388. if (ex instanceof MissingDataException) {
  28389. throw ex;
  28390. }
  28391. warn('Invalid stream: \"' + ex + '\"');
  28392. return new NullStream(stream);
  28393. }
  28394. }
  28395. };
  28396. return Parser;
  28397. })();
  28398. var Lexer = (function LexerClosure() {
  28399. function Lexer(stream, knownCommands) {
  28400. this.stream = stream;
  28401. this.nextChar();
  28402. // While lexing, we build up many strings one char at a time. Using += for
  28403. // this can result in lots of garbage strings. It's better to build an
  28404. // array of single-char strings and then join() them together at the end.
  28405. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28406. // purpose uses less memory than using a new array for each string.
  28407. this.strBuf = [];
  28408. // The PDFs might have "glued" commands with other commands, operands or
  28409. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28410. // commands and their prefixes. The prefixes are built the following way:
  28411. // if there a command that is a prefix of the other valid command or
  28412. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28413. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28414. // other commands or literals as a prefix. The knowCommands is optional.
  28415. this.knownCommands = knownCommands;
  28416. }
  28417. Lexer.isSpace = function Lexer_isSpace(ch) {
  28418. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28419. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28420. };
  28421. // A '1' in this array means the character is white space. A '1' or
  28422. // '2' means the character ends a name or command.
  28423. var specialChars = [
  28424. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28426. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28440. ];
  28441. function toHexDigit(ch) {
  28442. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28443. return ch & 0x0F;
  28444. }
  28445. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28446. // 'A'-'F', 'a'-'f'
  28447. return (ch & 0x0F) + 9;
  28448. }
  28449. return -1;
  28450. }
  28451. Lexer.prototype = {
  28452. nextChar: function Lexer_nextChar() {
  28453. return (this.currentChar = this.stream.getByte());
  28454. },
  28455. peekChar: function Lexer_peekChar() {
  28456. return this.stream.peekByte();
  28457. },
  28458. getNumber: function Lexer_getNumber() {
  28459. var ch = this.currentChar;
  28460. var eNotation = false;
  28461. var divideBy = 0; // different from 0 if it's a floating point value
  28462. var sign = 1;
  28463. if (ch === 0x2D) { // '-'
  28464. sign = -1;
  28465. ch = this.nextChar();
  28466. } else if (ch === 0x2B) { // '+'
  28467. ch = this.nextChar();
  28468. }
  28469. if (ch === 0x2E) { // '.'
  28470. divideBy = 10;
  28471. ch = this.nextChar();
  28472. }
  28473. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28474. error('Invalid number: ' + String.fromCharCode(ch));
  28475. return 0;
  28476. }
  28477. var baseValue = ch - 0x30; // '0'
  28478. var powerValue = 0;
  28479. var powerValueSign = 1;
  28480. while ((ch = this.nextChar()) >= 0) {
  28481. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28482. var currentDigit = ch - 0x30; // '0'
  28483. if (eNotation) { // We are after an 'e' or 'E'
  28484. powerValue = powerValue * 10 + currentDigit;
  28485. } else {
  28486. if (divideBy !== 0) { // We are after a point
  28487. divideBy *= 10;
  28488. }
  28489. baseValue = baseValue * 10 + currentDigit;
  28490. }
  28491. } else if (ch === 0x2E) { // '.'
  28492. if (divideBy === 0) {
  28493. divideBy = 1;
  28494. } else {
  28495. // A number can have only one '.'
  28496. break;
  28497. }
  28498. } else if (ch === 0x2D) { // '-'
  28499. // ignore minus signs in the middle of numbers to match
  28500. // Adobe's behavior
  28501. warn('Badly formated number');
  28502. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28503. // 'E' can be either a scientific notation or the beginning of a new
  28504. // operator
  28505. ch = this.peekChar();
  28506. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28507. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28508. this.nextChar(); // Consume the sign character
  28509. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28510. // The 'E' must be the beginning of a new operator
  28511. break;
  28512. }
  28513. eNotation = true;
  28514. } else {
  28515. // the last character doesn't belong to us
  28516. break;
  28517. }
  28518. }
  28519. if (divideBy !== 0) {
  28520. baseValue /= divideBy;
  28521. }
  28522. if (eNotation) {
  28523. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28524. }
  28525. return sign * baseValue;
  28526. },
  28527. getString: function Lexer_getString() {
  28528. var numParen = 1;
  28529. var done = false;
  28530. var strBuf = this.strBuf;
  28531. strBuf.length = 0;
  28532. var ch = this.nextChar();
  28533. while (true) {
  28534. var charBuffered = false;
  28535. switch (ch | 0) {
  28536. case -1:
  28537. warn('Unterminated string');
  28538. done = true;
  28539. break;
  28540. case 0x28: // '('
  28541. ++numParen;
  28542. strBuf.push('(');
  28543. break;
  28544. case 0x29: // ')'
  28545. if (--numParen === 0) {
  28546. this.nextChar(); // consume strings ')'
  28547. done = true;
  28548. } else {
  28549. strBuf.push(')');
  28550. }
  28551. break;
  28552. case 0x5C: // '\\'
  28553. ch = this.nextChar();
  28554. switch (ch) {
  28555. case -1:
  28556. warn('Unterminated string');
  28557. done = true;
  28558. break;
  28559. case 0x6E: // 'n'
  28560. strBuf.push('\n');
  28561. break;
  28562. case 0x72: // 'r'
  28563. strBuf.push('\r');
  28564. break;
  28565. case 0x74: // 't'
  28566. strBuf.push('\t');
  28567. break;
  28568. case 0x62: // 'b'
  28569. strBuf.push('\b');
  28570. break;
  28571. case 0x66: // 'f'
  28572. strBuf.push('\f');
  28573. break;
  28574. case 0x5C: // '\'
  28575. case 0x28: // '('
  28576. case 0x29: // ')'
  28577. strBuf.push(String.fromCharCode(ch));
  28578. break;
  28579. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28580. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28581. var x = ch & 0x0F;
  28582. ch = this.nextChar();
  28583. charBuffered = true;
  28584. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28585. x = (x << 3) + (ch & 0x0F);
  28586. ch = this.nextChar();
  28587. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28588. charBuffered = false;
  28589. x = (x << 3) + (ch & 0x0F);
  28590. }
  28591. }
  28592. strBuf.push(String.fromCharCode(x));
  28593. break;
  28594. case 0x0D: // CR
  28595. if (this.peekChar() === 0x0A) { // LF
  28596. this.nextChar();
  28597. }
  28598. break;
  28599. case 0x0A: // LF
  28600. break;
  28601. default:
  28602. strBuf.push(String.fromCharCode(ch));
  28603. break;
  28604. }
  28605. break;
  28606. default:
  28607. strBuf.push(String.fromCharCode(ch));
  28608. break;
  28609. }
  28610. if (done) {
  28611. break;
  28612. }
  28613. if (!charBuffered) {
  28614. ch = this.nextChar();
  28615. }
  28616. }
  28617. return strBuf.join('');
  28618. },
  28619. getName: function Lexer_getName() {
  28620. var ch;
  28621. var strBuf = this.strBuf;
  28622. strBuf.length = 0;
  28623. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28624. if (ch === 0x23) { // '#'
  28625. ch = this.nextChar();
  28626. var x = toHexDigit(ch);
  28627. if (x !== -1) {
  28628. var x2 = toHexDigit(this.nextChar());
  28629. if (x2 === -1) {
  28630. error('Illegal digit in hex char in name: ' + x2);
  28631. }
  28632. strBuf.push(String.fromCharCode((x << 4) | x2));
  28633. } else {
  28634. strBuf.push('#', String.fromCharCode(ch));
  28635. }
  28636. } else {
  28637. strBuf.push(String.fromCharCode(ch));
  28638. }
  28639. }
  28640. if (strBuf.length > 128) {
  28641. error('Warning: name token is longer than allowed by the spec: ' +
  28642. strBuf.length);
  28643. }
  28644. return Name.get(strBuf.join(''));
  28645. },
  28646. getHexString: function Lexer_getHexString() {
  28647. var strBuf = this.strBuf;
  28648. strBuf.length = 0;
  28649. var ch = this.currentChar;
  28650. var isFirstHex = true;
  28651. var firstDigit;
  28652. var secondDigit;
  28653. while (true) {
  28654. if (ch < 0) {
  28655. warn('Unterminated hex string');
  28656. break;
  28657. } else if (ch === 0x3E) { // '>'
  28658. this.nextChar();
  28659. break;
  28660. } else if (specialChars[ch] === 1) {
  28661. ch = this.nextChar();
  28662. continue;
  28663. } else {
  28664. if (isFirstHex) {
  28665. firstDigit = toHexDigit(ch);
  28666. if (firstDigit === -1) {
  28667. warn('Ignoring invalid character "' + ch + '" in hex string');
  28668. ch = this.nextChar();
  28669. continue;
  28670. }
  28671. } else {
  28672. secondDigit = toHexDigit(ch);
  28673. if (secondDigit === -1) {
  28674. warn('Ignoring invalid character "' + ch + '" in hex string');
  28675. ch = this.nextChar();
  28676. continue;
  28677. }
  28678. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28679. }
  28680. isFirstHex = !isFirstHex;
  28681. ch = this.nextChar();
  28682. }
  28683. }
  28684. return strBuf.join('');
  28685. },
  28686. getObj: function Lexer_getObj() {
  28687. // skip whitespace and comments
  28688. var comment = false;
  28689. var ch = this.currentChar;
  28690. while (true) {
  28691. if (ch < 0) {
  28692. return EOF;
  28693. }
  28694. if (comment) {
  28695. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28696. comment = false;
  28697. }
  28698. } else if (ch === 0x25) { // '%'
  28699. comment = true;
  28700. } else if (specialChars[ch] !== 1) {
  28701. break;
  28702. }
  28703. ch = this.nextChar();
  28704. }
  28705. // start reading token
  28706. switch (ch | 0) {
  28707. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28708. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28709. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28710. return this.getNumber();
  28711. case 0x28: // '('
  28712. return this.getString();
  28713. case 0x2F: // '/'
  28714. return this.getName();
  28715. // array punctuation
  28716. case 0x5B: // '['
  28717. this.nextChar();
  28718. return Cmd.get('[');
  28719. case 0x5D: // ']'
  28720. this.nextChar();
  28721. return Cmd.get(']');
  28722. // hex string or dict punctuation
  28723. case 0x3C: // '<'
  28724. ch = this.nextChar();
  28725. if (ch === 0x3C) {
  28726. // dict punctuation
  28727. this.nextChar();
  28728. return Cmd.get('<<');
  28729. }
  28730. return this.getHexString();
  28731. // dict punctuation
  28732. case 0x3E: // '>'
  28733. ch = this.nextChar();
  28734. if (ch === 0x3E) {
  28735. this.nextChar();
  28736. return Cmd.get('>>');
  28737. }
  28738. return Cmd.get('>');
  28739. case 0x7B: // '{'
  28740. this.nextChar();
  28741. return Cmd.get('{');
  28742. case 0x7D: // '}'
  28743. this.nextChar();
  28744. return Cmd.get('}');
  28745. case 0x29: // ')'
  28746. error('Illegal character: ' + ch);
  28747. break;
  28748. }
  28749. // command
  28750. var str = String.fromCharCode(ch);
  28751. var knownCommands = this.knownCommands;
  28752. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28753. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28754. // stop if known command is found and next character does not make
  28755. // the str a command
  28756. var possibleCommand = str + String.fromCharCode(ch);
  28757. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28758. break;
  28759. }
  28760. if (str.length === 128) {
  28761. error('Command token too long: ' + str.length);
  28762. }
  28763. str = possibleCommand;
  28764. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28765. }
  28766. if (str === 'true') {
  28767. return true;
  28768. }
  28769. if (str === 'false') {
  28770. return false;
  28771. }
  28772. if (str === 'null') {
  28773. return null;
  28774. }
  28775. return Cmd.get(str);
  28776. },
  28777. skipToNextLine: function Lexer_skipToNextLine() {
  28778. var ch = this.currentChar;
  28779. while (ch >= 0) {
  28780. if (ch === 0x0D) { // CR
  28781. ch = this.nextChar();
  28782. if (ch === 0x0A) { // LF
  28783. this.nextChar();
  28784. }
  28785. break;
  28786. } else if (ch === 0x0A) { // LF
  28787. this.nextChar();
  28788. break;
  28789. }
  28790. ch = this.nextChar();
  28791. }
  28792. }
  28793. };
  28794. return Lexer;
  28795. })();
  28796. var Linearization = {
  28797. create: function LinearizationCreate(stream) {
  28798. function getInt(name, allowZeroValue) {
  28799. var obj = linDict.get(name);
  28800. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28801. return obj;
  28802. }
  28803. throw new Error('The "' + name + '" parameter in the linearization ' +
  28804. 'dictionary is invalid.');
  28805. }
  28806. function getHints() {
  28807. var hints = linDict.get('H'), hintsLength, item;
  28808. if (isArray(hints) &&
  28809. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28810. for (var index = 0; index < hintsLength; index++) {
  28811. if (!(isInt(item = hints[index]) && item > 0)) {
  28812. throw new Error('Hint (' + index +
  28813. ') in the linearization dictionary is invalid.');
  28814. }
  28815. }
  28816. return hints;
  28817. }
  28818. throw new Error('Hint array in the linearization dictionary is invalid.');
  28819. }
  28820. var parser = new Parser(new Lexer(stream), false, null);
  28821. var obj1 = parser.getObj();
  28822. var obj2 = parser.getObj();
  28823. var obj3 = parser.getObj();
  28824. var linDict = parser.getObj();
  28825. var obj, length;
  28826. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28827. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28828. return null; // No valid linearization dictionary found.
  28829. } else if ((length = getInt('L')) !== stream.length) {
  28830. throw new Error('The "L" parameter in the linearization dictionary ' +
  28831. 'does not equal the stream length.');
  28832. }
  28833. return {
  28834. length: length,
  28835. hints: getHints(),
  28836. objectNumberFirst: getInt('O'),
  28837. endFirst: getInt('E'),
  28838. numPages: getInt('N'),
  28839. mainXRefEntriesOffset: getInt('T'),
  28840. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28841. };
  28842. }
  28843. };
  28844. var PostScriptParser = (function PostScriptParserClosure() {
  28845. function PostScriptParser(lexer) {
  28846. this.lexer = lexer;
  28847. this.operators = [];
  28848. this.token = null;
  28849. this.prev = null;
  28850. }
  28851. PostScriptParser.prototype = {
  28852. nextToken: function PostScriptParser_nextToken() {
  28853. this.prev = this.token;
  28854. this.token = this.lexer.getToken();
  28855. },
  28856. accept: function PostScriptParser_accept(type) {
  28857. if (this.token.type === type) {
  28858. this.nextToken();
  28859. return true;
  28860. }
  28861. return false;
  28862. },
  28863. expect: function PostScriptParser_expect(type) {
  28864. if (this.accept(type)) {
  28865. return true;
  28866. }
  28867. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  28868. type + '.');
  28869. },
  28870. parse: function PostScriptParser_parse() {
  28871. this.nextToken();
  28872. this.expect(PostScriptTokenTypes.LBRACE);
  28873. this.parseBlock();
  28874. this.expect(PostScriptTokenTypes.RBRACE);
  28875. return this.operators;
  28876. },
  28877. parseBlock: function PostScriptParser_parseBlock() {
  28878. while (true) {
  28879. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  28880. this.operators.push(this.prev.value);
  28881. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  28882. this.operators.push(this.prev.value);
  28883. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28884. this.parseCondition();
  28885. } else {
  28886. return;
  28887. }
  28888. }
  28889. },
  28890. parseCondition: function PostScriptParser_parseCondition() {
  28891. // Add two place holders that will be updated later
  28892. var conditionLocation = this.operators.length;
  28893. this.operators.push(null, null);
  28894. this.parseBlock();
  28895. this.expect(PostScriptTokenTypes.RBRACE);
  28896. if (this.accept(PostScriptTokenTypes.IF)) {
  28897. // The true block is right after the 'if' so it just falls through on
  28898. // true else it jumps and skips the true block.
  28899. this.operators[conditionLocation] = this.operators.length;
  28900. this.operators[conditionLocation + 1] = 'jz';
  28901. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28902. var jumpLocation = this.operators.length;
  28903. this.operators.push(null, null);
  28904. var endOfTrue = this.operators.length;
  28905. this.parseBlock();
  28906. this.expect(PostScriptTokenTypes.RBRACE);
  28907. this.expect(PostScriptTokenTypes.IFELSE);
  28908. // The jump is added at the end of the true block to skip the false
  28909. // block.
  28910. this.operators[jumpLocation] = this.operators.length;
  28911. this.operators[jumpLocation + 1] = 'j';
  28912. this.operators[conditionLocation] = endOfTrue;
  28913. this.operators[conditionLocation + 1] = 'jz';
  28914. } else {
  28915. error('PS Function: error parsing conditional.');
  28916. }
  28917. }
  28918. };
  28919. return PostScriptParser;
  28920. })();
  28921. var PostScriptTokenTypes = {
  28922. LBRACE: 0,
  28923. RBRACE: 1,
  28924. NUMBER: 2,
  28925. OPERATOR: 3,
  28926. IF: 4,
  28927. IFELSE: 5
  28928. };
  28929. var PostScriptToken = (function PostScriptTokenClosure() {
  28930. function PostScriptToken(type, value) {
  28931. this.type = type;
  28932. this.value = value;
  28933. }
  28934. var opCache = {};
  28935. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  28936. var opValue = opCache[op];
  28937. if (opValue) {
  28938. return opValue;
  28939. }
  28940. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  28941. };
  28942. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  28943. '{');
  28944. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  28945. '}');
  28946. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  28947. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  28948. 'IFELSE');
  28949. return PostScriptToken;
  28950. })();
  28951. var PostScriptLexer = (function PostScriptLexerClosure() {
  28952. function PostScriptLexer(stream) {
  28953. this.stream = stream;
  28954. this.nextChar();
  28955. this.strBuf = [];
  28956. }
  28957. PostScriptLexer.prototype = {
  28958. nextChar: function PostScriptLexer_nextChar() {
  28959. return (this.currentChar = this.stream.getByte());
  28960. },
  28961. getToken: function PostScriptLexer_getToken() {
  28962. var comment = false;
  28963. var ch = this.currentChar;
  28964. // skip comments
  28965. while (true) {
  28966. if (ch < 0) {
  28967. return EOF;
  28968. }
  28969. if (comment) {
  28970. if (ch === 0x0A || ch === 0x0D) {
  28971. comment = false;
  28972. }
  28973. } else if (ch === 0x25) { // '%'
  28974. comment = true;
  28975. } else if (!Lexer.isSpace(ch)) {
  28976. break;
  28977. }
  28978. ch = this.nextChar();
  28979. }
  28980. switch (ch | 0) {
  28981. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28982. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28983. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28984. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  28985. this.getNumber());
  28986. case 0x7B: // '{'
  28987. this.nextChar();
  28988. return PostScriptToken.LBRACE;
  28989. case 0x7D: // '}'
  28990. this.nextChar();
  28991. return PostScriptToken.RBRACE;
  28992. }
  28993. // operator
  28994. var strBuf = this.strBuf;
  28995. strBuf.length = 0;
  28996. strBuf[0] = String.fromCharCode(ch);
  28997. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  28998. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  28999. strBuf.push(String.fromCharCode(ch));
  29000. }
  29001. var str = strBuf.join('');
  29002. switch (str.toLowerCase()) {
  29003. case 'if':
  29004. return PostScriptToken.IF;
  29005. case 'ifelse':
  29006. return PostScriptToken.IFELSE;
  29007. default:
  29008. return PostScriptToken.getOperator(str);
  29009. }
  29010. },
  29011. getNumber: function PostScriptLexer_getNumber() {
  29012. var ch = this.currentChar;
  29013. var strBuf = this.strBuf;
  29014. strBuf.length = 0;
  29015. strBuf[0] = String.fromCharCode(ch);
  29016. while ((ch = this.nextChar()) >= 0) {
  29017. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29018. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29019. strBuf.push(String.fromCharCode(ch));
  29020. } else {
  29021. break;
  29022. }
  29023. }
  29024. var value = parseFloat(strBuf.join(''));
  29025. if (isNaN(value)) {
  29026. error('Invalid floating point number: ' + value);
  29027. }
  29028. return value;
  29029. }
  29030. };
  29031. return PostScriptLexer;
  29032. })();
  29033. var Stream = (function StreamClosure() {
  29034. function Stream(arrayBuffer, start, length, dict) {
  29035. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29036. arrayBuffer : new Uint8Array(arrayBuffer));
  29037. this.start = start || 0;
  29038. this.pos = this.start;
  29039. this.end = (start + length) || this.bytes.length;
  29040. this.dict = dict;
  29041. }
  29042. // required methods for a stream. if a particular stream does not
  29043. // implement these, an error should be thrown
  29044. Stream.prototype = {
  29045. get length() {
  29046. return this.end - this.start;
  29047. },
  29048. get isEmpty() {
  29049. return this.length === 0;
  29050. },
  29051. getByte: function Stream_getByte() {
  29052. if (this.pos >= this.end) {
  29053. return -1;
  29054. }
  29055. return this.bytes[this.pos++];
  29056. },
  29057. getUint16: function Stream_getUint16() {
  29058. var b0 = this.getByte();
  29059. var b1 = this.getByte();
  29060. return (b0 << 8) + b1;
  29061. },
  29062. getInt32: function Stream_getInt32() {
  29063. var b0 = this.getByte();
  29064. var b1 = this.getByte();
  29065. var b2 = this.getByte();
  29066. var b3 = this.getByte();
  29067. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29068. },
  29069. // returns subarray of original buffer
  29070. // should only be read
  29071. getBytes: function Stream_getBytes(length) {
  29072. var bytes = this.bytes;
  29073. var pos = this.pos;
  29074. var strEnd = this.end;
  29075. if (!length) {
  29076. return bytes.subarray(pos, strEnd);
  29077. }
  29078. var end = pos + length;
  29079. if (end > strEnd) {
  29080. end = strEnd;
  29081. }
  29082. this.pos = end;
  29083. return bytes.subarray(pos, end);
  29084. },
  29085. peekByte: function Stream_peekByte() {
  29086. var peekedByte = this.getByte();
  29087. this.pos--;
  29088. return peekedByte;
  29089. },
  29090. peekBytes: function Stream_peekBytes(length) {
  29091. var bytes = this.getBytes(length);
  29092. this.pos -= bytes.length;
  29093. return bytes;
  29094. },
  29095. skip: function Stream_skip(n) {
  29096. if (!n) {
  29097. n = 1;
  29098. }
  29099. this.pos += n;
  29100. },
  29101. reset: function Stream_reset() {
  29102. this.pos = this.start;
  29103. },
  29104. moveStart: function Stream_moveStart() {
  29105. this.start = this.pos;
  29106. },
  29107. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29108. return new Stream(this.bytes.buffer, start, length, dict);
  29109. },
  29110. isStream: true
  29111. };
  29112. return Stream;
  29113. })();
  29114. var StringStream = (function StringStreamClosure() {
  29115. function StringStream(str) {
  29116. var length = str.length;
  29117. var bytes = new Uint8Array(length);
  29118. for (var n = 0; n < length; ++n) {
  29119. bytes[n] = str.charCodeAt(n);
  29120. }
  29121. Stream.call(this, bytes);
  29122. }
  29123. StringStream.prototype = Stream.prototype;
  29124. return StringStream;
  29125. })();
  29126. // super class for the decoding streams
  29127. var DecodeStream = (function DecodeStreamClosure() {
  29128. // Lots of DecodeStreams are created whose buffers are never used. For these
  29129. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29130. // having special cases that would be required if we used |null| for an empty
  29131. // buffer.
  29132. var emptyBuffer = new Uint8Array(0);
  29133. function DecodeStream(maybeMinBufferLength) {
  29134. this.pos = 0;
  29135. this.bufferLength = 0;
  29136. this.eof = false;
  29137. this.buffer = emptyBuffer;
  29138. this.minBufferLength = 512;
  29139. if (maybeMinBufferLength) {
  29140. // Compute the first power of two that is as big as maybeMinBufferLength.
  29141. while (this.minBufferLength < maybeMinBufferLength) {
  29142. this.minBufferLength *= 2;
  29143. }
  29144. }
  29145. }
  29146. DecodeStream.prototype = {
  29147. get isEmpty() {
  29148. while (!this.eof && this.bufferLength === 0) {
  29149. this.readBlock();
  29150. }
  29151. return this.bufferLength === 0;
  29152. },
  29153. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29154. var buffer = this.buffer;
  29155. if (requested <= buffer.byteLength) {
  29156. return buffer;
  29157. }
  29158. var size = this.minBufferLength;
  29159. while (size < requested) {
  29160. size *= 2;
  29161. }
  29162. var buffer2 = new Uint8Array(size);
  29163. buffer2.set(buffer);
  29164. return (this.buffer = buffer2);
  29165. },
  29166. getByte: function DecodeStream_getByte() {
  29167. var pos = this.pos;
  29168. while (this.bufferLength <= pos) {
  29169. if (this.eof) {
  29170. return -1;
  29171. }
  29172. this.readBlock();
  29173. }
  29174. return this.buffer[this.pos++];
  29175. },
  29176. getUint16: function DecodeStream_getUint16() {
  29177. var b0 = this.getByte();
  29178. var b1 = this.getByte();
  29179. return (b0 << 8) + b1;
  29180. },
  29181. getInt32: function DecodeStream_getInt32() {
  29182. var b0 = this.getByte();
  29183. var b1 = this.getByte();
  29184. var b2 = this.getByte();
  29185. var b3 = this.getByte();
  29186. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29187. },
  29188. getBytes: function DecodeStream_getBytes(length) {
  29189. var end, pos = this.pos;
  29190. if (length) {
  29191. this.ensureBuffer(pos + length);
  29192. end = pos + length;
  29193. while (!this.eof && this.bufferLength < end) {
  29194. this.readBlock();
  29195. }
  29196. var bufEnd = this.bufferLength;
  29197. if (end > bufEnd) {
  29198. end = bufEnd;
  29199. }
  29200. } else {
  29201. while (!this.eof) {
  29202. this.readBlock();
  29203. }
  29204. end = this.bufferLength;
  29205. }
  29206. this.pos = end;
  29207. return this.buffer.subarray(pos, end);
  29208. },
  29209. peekByte: function DecodeStream_peekByte() {
  29210. var peekedByte = this.getByte();
  29211. this.pos--;
  29212. return peekedByte;
  29213. },
  29214. peekBytes: function DecodeStream_peekBytes(length) {
  29215. var bytes = this.getBytes(length);
  29216. this.pos -= bytes.length;
  29217. return bytes;
  29218. },
  29219. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29220. var end = start + length;
  29221. while (this.bufferLength <= end && !this.eof) {
  29222. this.readBlock();
  29223. }
  29224. return new Stream(this.buffer, start, length, dict);
  29225. },
  29226. skip: function DecodeStream_skip(n) {
  29227. if (!n) {
  29228. n = 1;
  29229. }
  29230. this.pos += n;
  29231. },
  29232. reset: function DecodeStream_reset() {
  29233. this.pos = 0;
  29234. },
  29235. getBaseStreams: function DecodeStream_getBaseStreams() {
  29236. if (this.str && this.str.getBaseStreams) {
  29237. return this.str.getBaseStreams();
  29238. }
  29239. return [];
  29240. }
  29241. };
  29242. return DecodeStream;
  29243. })();
  29244. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29245. function StreamsSequenceStream(streams) {
  29246. this.streams = streams;
  29247. DecodeStream.call(this, /* maybeLength = */ null);
  29248. }
  29249. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29250. StreamsSequenceStream.prototype.readBlock =
  29251. function streamSequenceStreamReadBlock() {
  29252. var streams = this.streams;
  29253. if (streams.length === 0) {
  29254. this.eof = true;
  29255. return;
  29256. }
  29257. var stream = streams.shift();
  29258. var chunk = stream.getBytes();
  29259. var bufferLength = this.bufferLength;
  29260. var newLength = bufferLength + chunk.length;
  29261. var buffer = this.ensureBuffer(newLength);
  29262. buffer.set(chunk, bufferLength);
  29263. this.bufferLength = newLength;
  29264. };
  29265. StreamsSequenceStream.prototype.getBaseStreams =
  29266. function StreamsSequenceStream_getBaseStreams() {
  29267. var baseStreams = [];
  29268. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29269. var stream = this.streams[i];
  29270. if (stream.getBaseStreams) {
  29271. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29272. }
  29273. }
  29274. return baseStreams;
  29275. };
  29276. return StreamsSequenceStream;
  29277. })();
  29278. var FlateStream = (function FlateStreamClosure() {
  29279. var codeLenCodeMap = new Uint32Array([
  29280. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29281. ]);
  29282. var lengthDecode = new Uint32Array([
  29283. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29284. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29285. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29286. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29287. ]);
  29288. var distDecode = new Uint32Array([
  29289. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29290. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29291. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29292. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29293. ]);
  29294. var fixedLitCodeTab = [new Uint32Array([
  29295. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29296. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29297. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29298. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29299. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29300. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29301. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29302. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29303. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29304. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29305. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29306. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29307. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29308. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29309. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29310. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29311. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29312. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29313. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29314. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29315. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29316. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29317. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29318. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29319. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29320. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29321. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29322. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29323. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29324. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29325. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29326. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29327. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29328. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29329. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29330. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29331. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29332. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29333. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29334. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29335. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29336. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29337. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29338. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29339. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29340. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29341. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29342. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29343. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29344. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29345. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29346. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29347. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29348. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29349. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29350. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29351. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29352. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29353. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29354. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29355. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29356. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29357. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29358. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29359. ]), 9];
  29360. var fixedDistCodeTab = [new Uint32Array([
  29361. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29362. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29363. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29364. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29365. ]), 5];
  29366. function FlateStream(str, maybeLength) {
  29367. this.str = str;
  29368. this.dict = str.dict;
  29369. var cmf = str.getByte();
  29370. var flg = str.getByte();
  29371. if (cmf === -1 || flg === -1) {
  29372. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29373. }
  29374. if ((cmf & 0x0f) !== 0x08) {
  29375. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29376. }
  29377. if ((((cmf << 8) + flg) % 31) !== 0) {
  29378. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29379. }
  29380. if (flg & 0x20) {
  29381. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29382. }
  29383. this.codeSize = 0;
  29384. this.codeBuf = 0;
  29385. DecodeStream.call(this, maybeLength);
  29386. }
  29387. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29388. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29389. var str = this.str;
  29390. var codeSize = this.codeSize;
  29391. var codeBuf = this.codeBuf;
  29392. var b;
  29393. while (codeSize < bits) {
  29394. if ((b = str.getByte()) === -1) {
  29395. error('Bad encoding in flate stream');
  29396. }
  29397. codeBuf |= b << codeSize;
  29398. codeSize += 8;
  29399. }
  29400. b = codeBuf & ((1 << bits) - 1);
  29401. this.codeBuf = codeBuf >> bits;
  29402. this.codeSize = codeSize -= bits;
  29403. return b;
  29404. };
  29405. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29406. var str = this.str;
  29407. var codes = table[0];
  29408. var maxLen = table[1];
  29409. var codeSize = this.codeSize;
  29410. var codeBuf = this.codeBuf;
  29411. var b;
  29412. while (codeSize < maxLen) {
  29413. if ((b = str.getByte()) === -1) {
  29414. // premature end of stream. code might however still be valid.
  29415. // codeSize < codeLen check below guards against incomplete codeVal.
  29416. break;
  29417. }
  29418. codeBuf |= (b << codeSize);
  29419. codeSize += 8;
  29420. }
  29421. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29422. var codeLen = code >> 16;
  29423. var codeVal = code & 0xffff;
  29424. if (codeLen < 1 || codeSize < codeLen) {
  29425. error('Bad encoding in flate stream');
  29426. }
  29427. this.codeBuf = (codeBuf >> codeLen);
  29428. this.codeSize = (codeSize - codeLen);
  29429. return codeVal;
  29430. };
  29431. FlateStream.prototype.generateHuffmanTable =
  29432. function flateStreamGenerateHuffmanTable(lengths) {
  29433. var n = lengths.length;
  29434. // find max code length
  29435. var maxLen = 0;
  29436. var i;
  29437. for (i = 0; i < n; ++i) {
  29438. if (lengths[i] > maxLen) {
  29439. maxLen = lengths[i];
  29440. }
  29441. }
  29442. // build the table
  29443. var size = 1 << maxLen;
  29444. var codes = new Uint32Array(size);
  29445. for (var len = 1, code = 0, skip = 2;
  29446. len <= maxLen;
  29447. ++len, code <<= 1, skip <<= 1) {
  29448. for (var val = 0; val < n; ++val) {
  29449. if (lengths[val] === len) {
  29450. // bit-reverse the code
  29451. var code2 = 0;
  29452. var t = code;
  29453. for (i = 0; i < len; ++i) {
  29454. code2 = (code2 << 1) | (t & 1);
  29455. t >>= 1;
  29456. }
  29457. // fill the table entries
  29458. for (i = code2; i < size; i += skip) {
  29459. codes[i] = (len << 16) | val;
  29460. }
  29461. ++code;
  29462. }
  29463. }
  29464. }
  29465. return [codes, maxLen];
  29466. };
  29467. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29468. var buffer, len;
  29469. var str = this.str;
  29470. // read block header
  29471. var hdr = this.getBits(3);
  29472. if (hdr & 1) {
  29473. this.eof = true;
  29474. }
  29475. hdr >>= 1;
  29476. if (hdr === 0) { // uncompressed block
  29477. var b;
  29478. if ((b = str.getByte()) === -1) {
  29479. error('Bad block header in flate stream');
  29480. }
  29481. var blockLen = b;
  29482. if ((b = str.getByte()) === -1) {
  29483. error('Bad block header in flate stream');
  29484. }
  29485. blockLen |= (b << 8);
  29486. if ((b = str.getByte()) === -1) {
  29487. error('Bad block header in flate stream');
  29488. }
  29489. var check = b;
  29490. if ((b = str.getByte()) === -1) {
  29491. error('Bad block header in flate stream');
  29492. }
  29493. check |= (b << 8);
  29494. if (check !== (~blockLen & 0xffff) &&
  29495. (blockLen !== 0 || check !== 0)) {
  29496. // Ignoring error for bad "empty" block (see issue 1277)
  29497. error('Bad uncompressed block length in flate stream');
  29498. }
  29499. this.codeBuf = 0;
  29500. this.codeSize = 0;
  29501. var bufferLength = this.bufferLength;
  29502. buffer = this.ensureBuffer(bufferLength + blockLen);
  29503. var end = bufferLength + blockLen;
  29504. this.bufferLength = end;
  29505. if (blockLen === 0) {
  29506. if (str.peekByte() === -1) {
  29507. this.eof = true;
  29508. }
  29509. } else {
  29510. for (var n = bufferLength; n < end; ++n) {
  29511. if ((b = str.getByte()) === -1) {
  29512. this.eof = true;
  29513. break;
  29514. }
  29515. buffer[n] = b;
  29516. }
  29517. }
  29518. return;
  29519. }
  29520. var litCodeTable;
  29521. var distCodeTable;
  29522. if (hdr === 1) { // compressed block, fixed codes
  29523. litCodeTable = fixedLitCodeTab;
  29524. distCodeTable = fixedDistCodeTab;
  29525. } else if (hdr === 2) { // compressed block, dynamic codes
  29526. var numLitCodes = this.getBits(5) + 257;
  29527. var numDistCodes = this.getBits(5) + 1;
  29528. var numCodeLenCodes = this.getBits(4) + 4;
  29529. // build the code lengths code table
  29530. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29531. var i;
  29532. for (i = 0; i < numCodeLenCodes; ++i) {
  29533. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29534. }
  29535. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29536. // build the literal and distance code tables
  29537. len = 0;
  29538. i = 0;
  29539. var codes = numLitCodes + numDistCodes;
  29540. var codeLengths = new Uint8Array(codes);
  29541. var bitsLength, bitsOffset, what;
  29542. while (i < codes) {
  29543. var code = this.getCode(codeLenCodeTab);
  29544. if (code === 16) {
  29545. bitsLength = 2; bitsOffset = 3; what = len;
  29546. } else if (code === 17) {
  29547. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29548. } else if (code === 18) {
  29549. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29550. } else {
  29551. codeLengths[i++] = len = code;
  29552. continue;
  29553. }
  29554. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29555. while (repeatLength-- > 0) {
  29556. codeLengths[i++] = what;
  29557. }
  29558. }
  29559. litCodeTable =
  29560. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29561. distCodeTable =
  29562. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29563. } else {
  29564. error('Unknown block type in flate stream');
  29565. }
  29566. buffer = this.buffer;
  29567. var limit = buffer ? buffer.length : 0;
  29568. var pos = this.bufferLength;
  29569. while (true) {
  29570. var code1 = this.getCode(litCodeTable);
  29571. if (code1 < 256) {
  29572. if (pos + 1 >= limit) {
  29573. buffer = this.ensureBuffer(pos + 1);
  29574. limit = buffer.length;
  29575. }
  29576. buffer[pos++] = code1;
  29577. continue;
  29578. }
  29579. if (code1 === 256) {
  29580. this.bufferLength = pos;
  29581. return;
  29582. }
  29583. code1 -= 257;
  29584. code1 = lengthDecode[code1];
  29585. var code2 = code1 >> 16;
  29586. if (code2 > 0) {
  29587. code2 = this.getBits(code2);
  29588. }
  29589. len = (code1 & 0xffff) + code2;
  29590. code1 = this.getCode(distCodeTable);
  29591. code1 = distDecode[code1];
  29592. code2 = code1 >> 16;
  29593. if (code2 > 0) {
  29594. code2 = this.getBits(code2);
  29595. }
  29596. var dist = (code1 & 0xffff) + code2;
  29597. if (pos + len >= limit) {
  29598. buffer = this.ensureBuffer(pos + len);
  29599. limit = buffer.length;
  29600. }
  29601. for (var k = 0; k < len; ++k, ++pos) {
  29602. buffer[pos] = buffer[pos - dist];
  29603. }
  29604. }
  29605. };
  29606. return FlateStream;
  29607. })();
  29608. var PredictorStream = (function PredictorStreamClosure() {
  29609. function PredictorStream(str, maybeLength, params) {
  29610. var predictor = this.predictor = params.get('Predictor') || 1;
  29611. if (predictor <= 1) {
  29612. return str; // no prediction
  29613. }
  29614. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  29615. error('Unsupported predictor: ' + predictor);
  29616. }
  29617. if (predictor === 2) {
  29618. this.readBlock = this.readBlockTiff;
  29619. } else {
  29620. this.readBlock = this.readBlockPng;
  29621. }
  29622. this.str = str;
  29623. this.dict = str.dict;
  29624. var colors = this.colors = params.get('Colors') || 1;
  29625. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29626. var columns = this.columns = params.get('Columns') || 1;
  29627. this.pixBytes = (colors * bits + 7) >> 3;
  29628. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29629. DecodeStream.call(this, maybeLength);
  29630. return this;
  29631. }
  29632. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29633. PredictorStream.prototype.readBlockTiff =
  29634. function predictorStreamReadBlockTiff() {
  29635. var rowBytes = this.rowBytes;
  29636. var bufferLength = this.bufferLength;
  29637. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29638. var bits = this.bits;
  29639. var colors = this.colors;
  29640. var rawBytes = this.str.getBytes(rowBytes);
  29641. this.eof = !rawBytes.length;
  29642. if (this.eof) {
  29643. return;
  29644. }
  29645. var inbuf = 0, outbuf = 0;
  29646. var inbits = 0, outbits = 0;
  29647. var pos = bufferLength;
  29648. var i;
  29649. if (bits === 1) {
  29650. for (i = 0; i < rowBytes; ++i) {
  29651. var c = rawBytes[i];
  29652. inbuf = (inbuf << 8) | c;
  29653. // bitwise addition is exclusive or
  29654. // first shift inbuf and then add
  29655. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  29656. // truncate inbuf (assumes colors < 16)
  29657. inbuf &= 0xFFFF;
  29658. }
  29659. } else if (bits === 8) {
  29660. for (i = 0; i < colors; ++i) {
  29661. buffer[pos++] = rawBytes[i];
  29662. }
  29663. for (; i < rowBytes; ++i) {
  29664. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  29665. pos++;
  29666. }
  29667. } else {
  29668. var compArray = new Uint8Array(colors + 1);
  29669. var bitMask = (1 << bits) - 1;
  29670. var j = 0, k = bufferLength;
  29671. var columns = this.columns;
  29672. for (i = 0; i < columns; ++i) {
  29673. for (var kk = 0; kk < colors; ++kk) {
  29674. if (inbits < bits) {
  29675. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  29676. inbits += 8;
  29677. }
  29678. compArray[kk] = (compArray[kk] +
  29679. (inbuf >> (inbits - bits))) & bitMask;
  29680. inbits -= bits;
  29681. outbuf = (outbuf << bits) | compArray[kk];
  29682. outbits += bits;
  29683. if (outbits >= 8) {
  29684. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  29685. outbits -= 8;
  29686. }
  29687. }
  29688. }
  29689. if (outbits > 0) {
  29690. buffer[k++] = (outbuf << (8 - outbits)) +
  29691. (inbuf & ((1 << (8 - outbits)) - 1));
  29692. }
  29693. }
  29694. this.bufferLength += rowBytes;
  29695. };
  29696. PredictorStream.prototype.readBlockPng =
  29697. function predictorStreamReadBlockPng() {
  29698. var rowBytes = this.rowBytes;
  29699. var pixBytes = this.pixBytes;
  29700. var predictor = this.str.getByte();
  29701. var rawBytes = this.str.getBytes(rowBytes);
  29702. this.eof = !rawBytes.length;
  29703. if (this.eof) {
  29704. return;
  29705. }
  29706. var bufferLength = this.bufferLength;
  29707. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29708. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  29709. if (prevRow.length === 0) {
  29710. prevRow = new Uint8Array(rowBytes);
  29711. }
  29712. var i, j = bufferLength, up, c;
  29713. switch (predictor) {
  29714. case 0:
  29715. for (i = 0; i < rowBytes; ++i) {
  29716. buffer[j++] = rawBytes[i];
  29717. }
  29718. break;
  29719. case 1:
  29720. for (i = 0; i < pixBytes; ++i) {
  29721. buffer[j++] = rawBytes[i];
  29722. }
  29723. for (; i < rowBytes; ++i) {
  29724. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  29725. j++;
  29726. }
  29727. break;
  29728. case 2:
  29729. for (i = 0; i < rowBytes; ++i) {
  29730. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  29731. }
  29732. break;
  29733. case 3:
  29734. for (i = 0; i < pixBytes; ++i) {
  29735. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  29736. }
  29737. for (; i < rowBytes; ++i) {
  29738. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  29739. rawBytes[i]) & 0xFF;
  29740. j++;
  29741. }
  29742. break;
  29743. case 4:
  29744. // we need to save the up left pixels values. the simplest way
  29745. // is to create a new buffer
  29746. for (i = 0; i < pixBytes; ++i) {
  29747. up = prevRow[i];
  29748. c = rawBytes[i];
  29749. buffer[j++] = up + c;
  29750. }
  29751. for (; i < rowBytes; ++i) {
  29752. up = prevRow[i];
  29753. var upLeft = prevRow[i - pixBytes];
  29754. var left = buffer[j - pixBytes];
  29755. var p = left + up - upLeft;
  29756. var pa = p - left;
  29757. if (pa < 0) {
  29758. pa = -pa;
  29759. }
  29760. var pb = p - up;
  29761. if (pb < 0) {
  29762. pb = -pb;
  29763. }
  29764. var pc = p - upLeft;
  29765. if (pc < 0) {
  29766. pc = -pc;
  29767. }
  29768. c = rawBytes[i];
  29769. if (pa <= pb && pa <= pc) {
  29770. buffer[j++] = left + c;
  29771. } else if (pb <= pc) {
  29772. buffer[j++] = up + c;
  29773. } else {
  29774. buffer[j++] = upLeft + c;
  29775. }
  29776. }
  29777. break;
  29778. default:
  29779. error('Unsupported predictor: ' + predictor);
  29780. }
  29781. this.bufferLength += rowBytes;
  29782. };
  29783. return PredictorStream;
  29784. })();
  29785. /**
  29786. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  29787. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  29788. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  29789. * a library to decode these images and the stream behaves like all the other
  29790. * DecodeStreams.
  29791. */
  29792. var JpegStream = (function JpegStreamClosure() {
  29793. function JpegStream(stream, maybeLength, dict, xref) {
  29794. // TODO: per poppler, some images may have 'junk' before that
  29795. // need to be removed
  29796. this.stream = stream;
  29797. this.maybeLength = maybeLength;
  29798. this.dict = dict;
  29799. DecodeStream.call(this, maybeLength);
  29800. }
  29801. JpegStream.prototype = Object.create(DecodeStream.prototype);
  29802. Object.defineProperty(JpegStream.prototype, 'bytes', {
  29803. get: function JpegStream_bytes() {
  29804. // If this.maybeLength is null, we'll get the entire stream.
  29805. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29806. },
  29807. configurable: true
  29808. });
  29809. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  29810. if (this.bufferLength) {
  29811. return;
  29812. }
  29813. try {
  29814. var jpegImage = new JpegImage();
  29815. // checking if values needs to be transformed before conversion
  29816. if (this.dict && isArray(this.dict.get('Decode'))) {
  29817. var decodeArr = this.dict.get('Decode');
  29818. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  29819. var decodeArrLength = decodeArr.length;
  29820. var transform = new Int32Array(decodeArrLength);
  29821. var transformNeeded = false;
  29822. var maxValue = (1 << bitsPerComponent) - 1;
  29823. for (var i = 0; i < decodeArrLength; i += 2) {
  29824. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  29825. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  29826. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  29827. transformNeeded = true;
  29828. }
  29829. }
  29830. if (transformNeeded) {
  29831. jpegImage.decodeTransform = transform;
  29832. }
  29833. }
  29834. jpegImage.parse(this.bytes);
  29835. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  29836. this.forceRGB);
  29837. this.buffer = data;
  29838. this.bufferLength = data.length;
  29839. this.eof = true;
  29840. } catch (e) {
  29841. error('JPEG error: ' + e);
  29842. }
  29843. };
  29844. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  29845. this.ensureBuffer();
  29846. return this.buffer;
  29847. };
  29848. JpegStream.prototype.getIR = function JpegStream_getIR() {
  29849. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  29850. };
  29851. /**
  29852. * Checks if the image can be decoded and displayed by the browser without any
  29853. * further processing such as color space conversions.
  29854. */
  29855. JpegStream.prototype.isNativelySupported =
  29856. function JpegStream_isNativelySupported(xref, res) {
  29857. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29858. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  29859. };
  29860. /**
  29861. * Checks if the image can be decoded by the browser.
  29862. */
  29863. JpegStream.prototype.isNativelyDecodable =
  29864. function JpegStream_isNativelyDecodable(xref, res) {
  29865. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29866. var numComps = cs.numComps;
  29867. return numComps === 1 || numComps === 3;
  29868. };
  29869. return JpegStream;
  29870. })();
  29871. /**
  29872. * For JPEG 2000's we use a library to decode these images and
  29873. * the stream behaves like all the other DecodeStreams.
  29874. */
  29875. var JpxStream = (function JpxStreamClosure() {
  29876. function JpxStream(stream, maybeLength, dict) {
  29877. this.stream = stream;
  29878. this.maybeLength = maybeLength;
  29879. this.dict = dict;
  29880. DecodeStream.call(this, maybeLength);
  29881. }
  29882. JpxStream.prototype = Object.create(DecodeStream.prototype);
  29883. Object.defineProperty(JpxStream.prototype, 'bytes', {
  29884. get: function JpxStream_bytes() {
  29885. // If this.maybeLength is null, we'll get the entire stream.
  29886. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29887. },
  29888. configurable: true
  29889. });
  29890. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  29891. if (this.bufferLength) {
  29892. return;
  29893. }
  29894. var jpxImage = new JpxImage();
  29895. jpxImage.parse(this.bytes);
  29896. var width = jpxImage.width;
  29897. var height = jpxImage.height;
  29898. var componentsCount = jpxImage.componentsCount;
  29899. var tileCount = jpxImage.tiles.length;
  29900. if (tileCount === 1) {
  29901. this.buffer = jpxImage.tiles[0].items;
  29902. } else {
  29903. var data = new Uint8Array(width * height * componentsCount);
  29904. for (var k = 0; k < tileCount; k++) {
  29905. var tileComponents = jpxImage.tiles[k];
  29906. var tileWidth = tileComponents.width;
  29907. var tileHeight = tileComponents.height;
  29908. var tileLeft = tileComponents.left;
  29909. var tileTop = tileComponents.top;
  29910. var src = tileComponents.items;
  29911. var srcPosition = 0;
  29912. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  29913. var imgRowSize = width * componentsCount;
  29914. var tileRowSize = tileWidth * componentsCount;
  29915. for (var j = 0; j < tileHeight; j++) {
  29916. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  29917. data.set(rowBytes, dataPosition);
  29918. srcPosition += tileRowSize;
  29919. dataPosition += imgRowSize;
  29920. }
  29921. }
  29922. this.buffer = data;
  29923. }
  29924. this.bufferLength = this.buffer.length;
  29925. this.eof = true;
  29926. };
  29927. return JpxStream;
  29928. })();
  29929. /**
  29930. * For JBIG2's we use a library to decode these images and
  29931. * the stream behaves like all the other DecodeStreams.
  29932. */
  29933. var Jbig2Stream = (function Jbig2StreamClosure() {
  29934. function Jbig2Stream(stream, maybeLength, dict) {
  29935. this.stream = stream;
  29936. this.maybeLength = maybeLength;
  29937. this.dict = dict;
  29938. DecodeStream.call(this, maybeLength);
  29939. }
  29940. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  29941. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  29942. get: function Jbig2Stream_bytes() {
  29943. // If this.maybeLength is null, we'll get the entire stream.
  29944. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29945. },
  29946. configurable: true
  29947. });
  29948. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  29949. if (this.bufferLength) {
  29950. return;
  29951. }
  29952. var jbig2Image = new Jbig2Image();
  29953. var chunks = [], xref = this.dict.xref;
  29954. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  29955. // According to the PDF specification, DecodeParms can be either
  29956. // a dictionary, or an array whose elements are dictionaries.
  29957. if (isArray(decodeParams)) {
  29958. if (decodeParams.length > 1) {
  29959. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  29960. 'not supported.');
  29961. }
  29962. decodeParams = xref.fetchIfRef(decodeParams[0]);
  29963. }
  29964. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  29965. var globalsStream = decodeParams.get('JBIG2Globals');
  29966. var globals = globalsStream.getBytes();
  29967. chunks.push({data: globals, start: 0, end: globals.length});
  29968. }
  29969. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  29970. var data = jbig2Image.parseChunks(chunks);
  29971. var dataLength = data.length;
  29972. // JBIG2 had black as 1 and white as 0, inverting the colors
  29973. for (var i = 0; i < dataLength; i++) {
  29974. data[i] ^= 0xFF;
  29975. }
  29976. this.buffer = data;
  29977. this.bufferLength = dataLength;
  29978. this.eof = true;
  29979. };
  29980. return Jbig2Stream;
  29981. })();
  29982. var DecryptStream = (function DecryptStreamClosure() {
  29983. function DecryptStream(str, maybeLength, decrypt) {
  29984. this.str = str;
  29985. this.dict = str.dict;
  29986. this.decrypt = decrypt;
  29987. this.nextChunk = null;
  29988. this.initialized = false;
  29989. DecodeStream.call(this, maybeLength);
  29990. }
  29991. var chunkSize = 512;
  29992. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  29993. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  29994. var chunk;
  29995. if (this.initialized) {
  29996. chunk = this.nextChunk;
  29997. } else {
  29998. chunk = this.str.getBytes(chunkSize);
  29999. this.initialized = true;
  30000. }
  30001. if (!chunk || chunk.length === 0) {
  30002. this.eof = true;
  30003. return;
  30004. }
  30005. this.nextChunk = this.str.getBytes(chunkSize);
  30006. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30007. var decrypt = this.decrypt;
  30008. chunk = decrypt(chunk, !hasMoreData);
  30009. var bufferLength = this.bufferLength;
  30010. var i, n = chunk.length;
  30011. var buffer = this.ensureBuffer(bufferLength + n);
  30012. for (i = 0; i < n; i++) {
  30013. buffer[bufferLength++] = chunk[i];
  30014. }
  30015. this.bufferLength = bufferLength;
  30016. };
  30017. return DecryptStream;
  30018. })();
  30019. var Ascii85Stream = (function Ascii85StreamClosure() {
  30020. function Ascii85Stream(str, maybeLength) {
  30021. this.str = str;
  30022. this.dict = str.dict;
  30023. this.input = new Uint8Array(5);
  30024. // Most streams increase in size when decoded, but Ascii85 streams
  30025. // typically shrink by ~20%.
  30026. if (maybeLength) {
  30027. maybeLength = 0.8 * maybeLength;
  30028. }
  30029. DecodeStream.call(this, maybeLength);
  30030. }
  30031. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30032. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30033. var TILDA_CHAR = 0x7E; // '~'
  30034. var Z_LOWER_CHAR = 0x7A; // 'z'
  30035. var EOF = -1;
  30036. var str = this.str;
  30037. var c = str.getByte();
  30038. while (Lexer.isSpace(c)) {
  30039. c = str.getByte();
  30040. }
  30041. if (c === EOF || c === TILDA_CHAR) {
  30042. this.eof = true;
  30043. return;
  30044. }
  30045. var bufferLength = this.bufferLength, buffer;
  30046. var i;
  30047. // special code for z
  30048. if (c === Z_LOWER_CHAR) {
  30049. buffer = this.ensureBuffer(bufferLength + 4);
  30050. for (i = 0; i < 4; ++i) {
  30051. buffer[bufferLength + i] = 0;
  30052. }
  30053. this.bufferLength += 4;
  30054. } else {
  30055. var input = this.input;
  30056. input[0] = c;
  30057. for (i = 1; i < 5; ++i) {
  30058. c = str.getByte();
  30059. while (Lexer.isSpace(c)) {
  30060. c = str.getByte();
  30061. }
  30062. input[i] = c;
  30063. if (c === EOF || c === TILDA_CHAR) {
  30064. break;
  30065. }
  30066. }
  30067. buffer = this.ensureBuffer(bufferLength + i - 1);
  30068. this.bufferLength += i - 1;
  30069. // partial ending;
  30070. if (i < 5) {
  30071. for (; i < 5; ++i) {
  30072. input[i] = 0x21 + 84;
  30073. }
  30074. this.eof = true;
  30075. }
  30076. var t = 0;
  30077. for (i = 0; i < 5; ++i) {
  30078. t = t * 85 + (input[i] - 0x21);
  30079. }
  30080. for (i = 3; i >= 0; --i) {
  30081. buffer[bufferLength + i] = t & 0xFF;
  30082. t >>= 8;
  30083. }
  30084. }
  30085. };
  30086. return Ascii85Stream;
  30087. })();
  30088. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30089. function AsciiHexStream(str, maybeLength) {
  30090. this.str = str;
  30091. this.dict = str.dict;
  30092. this.firstDigit = -1;
  30093. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30094. // by 50%.
  30095. if (maybeLength) {
  30096. maybeLength = 0.5 * maybeLength;
  30097. }
  30098. DecodeStream.call(this, maybeLength);
  30099. }
  30100. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30101. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30102. var UPSTREAM_BLOCK_SIZE = 8000;
  30103. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30104. if (!bytes.length) {
  30105. this.eof = true;
  30106. return;
  30107. }
  30108. var maxDecodeLength = (bytes.length + 1) >> 1;
  30109. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30110. var bufferLength = this.bufferLength;
  30111. var firstDigit = this.firstDigit;
  30112. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30113. var ch = bytes[i], digit;
  30114. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30115. digit = ch & 0x0F;
  30116. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30117. // 'A'-'Z', 'a'-'z'
  30118. digit = (ch & 0x0F) + 9;
  30119. } else if (ch === 0x3E) { // '>'
  30120. this.eof = true;
  30121. break;
  30122. } else { // probably whitespace
  30123. continue; // ignoring
  30124. }
  30125. if (firstDigit < 0) {
  30126. firstDigit = digit;
  30127. } else {
  30128. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30129. firstDigit = -1;
  30130. }
  30131. }
  30132. if (firstDigit >= 0 && this.eof) {
  30133. // incomplete byte
  30134. buffer[bufferLength++] = (firstDigit << 4);
  30135. firstDigit = -1;
  30136. }
  30137. this.firstDigit = firstDigit;
  30138. this.bufferLength = bufferLength;
  30139. };
  30140. return AsciiHexStream;
  30141. })();
  30142. var RunLengthStream = (function RunLengthStreamClosure() {
  30143. function RunLengthStream(str, maybeLength) {
  30144. this.str = str;
  30145. this.dict = str.dict;
  30146. DecodeStream.call(this, maybeLength);
  30147. }
  30148. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30149. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30150. // The repeatHeader has following format. The first byte defines type of run
  30151. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30152. // (in addition to the second byte from the header), n = 129 through 255 -
  30153. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30154. var repeatHeader = this.str.getBytes(2);
  30155. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30156. this.eof = true;
  30157. return;
  30158. }
  30159. var buffer;
  30160. var bufferLength = this.bufferLength;
  30161. var n = repeatHeader[0];
  30162. if (n < 128) {
  30163. // copy n bytes
  30164. buffer = this.ensureBuffer(bufferLength + n + 1);
  30165. buffer[bufferLength++] = repeatHeader[1];
  30166. if (n > 0) {
  30167. var source = this.str.getBytes(n);
  30168. buffer.set(source, bufferLength);
  30169. bufferLength += n;
  30170. }
  30171. } else {
  30172. n = 257 - n;
  30173. var b = repeatHeader[1];
  30174. buffer = this.ensureBuffer(bufferLength + n + 1);
  30175. for (var i = 0; i < n; i++) {
  30176. buffer[bufferLength++] = b;
  30177. }
  30178. }
  30179. this.bufferLength = bufferLength;
  30180. };
  30181. return RunLengthStream;
  30182. })();
  30183. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30184. var ccittEOL = -2;
  30185. var twoDimPass = 0;
  30186. var twoDimHoriz = 1;
  30187. var twoDimVert0 = 2;
  30188. var twoDimVertR1 = 3;
  30189. var twoDimVertL1 = 4;
  30190. var twoDimVertR2 = 5;
  30191. var twoDimVertL2 = 6;
  30192. var twoDimVertR3 = 7;
  30193. var twoDimVertL3 = 8;
  30194. var twoDimTable = [
  30195. [-1, -1], [-1, -1], // 000000x
  30196. [7, twoDimVertL3], // 0000010
  30197. [7, twoDimVertR3], // 0000011
  30198. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30199. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30200. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30201. [4, twoDimPass], [4, twoDimPass],
  30202. [4, twoDimPass], [4, twoDimPass],
  30203. [4, twoDimPass], [4, twoDimPass],
  30204. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30205. [3, twoDimHoriz], [3, twoDimHoriz],
  30206. [3, twoDimHoriz], [3, twoDimHoriz],
  30207. [3, twoDimHoriz], [3, twoDimHoriz],
  30208. [3, twoDimHoriz], [3, twoDimHoriz],
  30209. [3, twoDimHoriz], [3, twoDimHoriz],
  30210. [3, twoDimHoriz], [3, twoDimHoriz],
  30211. [3, twoDimHoriz], [3, twoDimHoriz],
  30212. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30213. [3, twoDimVertL1], [3, twoDimVertL1],
  30214. [3, twoDimVertL1], [3, twoDimVertL1],
  30215. [3, twoDimVertL1], [3, twoDimVertL1],
  30216. [3, twoDimVertL1], [3, twoDimVertL1],
  30217. [3, twoDimVertL1], [3, twoDimVertL1],
  30218. [3, twoDimVertL1], [3, twoDimVertL1],
  30219. [3, twoDimVertL1], [3, twoDimVertL1],
  30220. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30221. [3, twoDimVertR1], [3, twoDimVertR1],
  30222. [3, twoDimVertR1], [3, twoDimVertR1],
  30223. [3, twoDimVertR1], [3, twoDimVertR1],
  30224. [3, twoDimVertR1], [3, twoDimVertR1],
  30225. [3, twoDimVertR1], [3, twoDimVertR1],
  30226. [3, twoDimVertR1], [3, twoDimVertR1],
  30227. [3, twoDimVertR1], [3, twoDimVertR1],
  30228. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30229. [1, twoDimVert0], [1, twoDimVert0],
  30230. [1, twoDimVert0], [1, twoDimVert0],
  30231. [1, twoDimVert0], [1, twoDimVert0],
  30232. [1, twoDimVert0], [1, twoDimVert0],
  30233. [1, twoDimVert0], [1, twoDimVert0],
  30234. [1, twoDimVert0], [1, twoDimVert0],
  30235. [1, twoDimVert0], [1, twoDimVert0],
  30236. [1, twoDimVert0], [1, twoDimVert0],
  30237. [1, twoDimVert0], [1, twoDimVert0],
  30238. [1, twoDimVert0], [1, twoDimVert0],
  30239. [1, twoDimVert0], [1, twoDimVert0],
  30240. [1, twoDimVert0], [1, twoDimVert0],
  30241. [1, twoDimVert0], [1, twoDimVert0],
  30242. [1, twoDimVert0], [1, twoDimVert0],
  30243. [1, twoDimVert0], [1, twoDimVert0],
  30244. [1, twoDimVert0], [1, twoDimVert0],
  30245. [1, twoDimVert0], [1, twoDimVert0],
  30246. [1, twoDimVert0], [1, twoDimVert0],
  30247. [1, twoDimVert0], [1, twoDimVert0],
  30248. [1, twoDimVert0], [1, twoDimVert0],
  30249. [1, twoDimVert0], [1, twoDimVert0],
  30250. [1, twoDimVert0], [1, twoDimVert0],
  30251. [1, twoDimVert0], [1, twoDimVert0],
  30252. [1, twoDimVert0], [1, twoDimVert0],
  30253. [1, twoDimVert0], [1, twoDimVert0],
  30254. [1, twoDimVert0], [1, twoDimVert0],
  30255. [1, twoDimVert0], [1, twoDimVert0],
  30256. [1, twoDimVert0], [1, twoDimVert0],
  30257. [1, twoDimVert0], [1, twoDimVert0],
  30258. [1, twoDimVert0], [1, twoDimVert0],
  30259. [1, twoDimVert0], [1, twoDimVert0]
  30260. ];
  30261. var whiteTable1 = [
  30262. [-1, -1], // 00000
  30263. [12, ccittEOL], // 00001
  30264. [-1, -1], [-1, -1], // 0001x
  30265. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30266. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30267. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30268. [11, 1792], [11, 1792], // 1000x
  30269. [12, 1984], // 10010
  30270. [12, 2048], // 10011
  30271. [12, 2112], // 10100
  30272. [12, 2176], // 10101
  30273. [12, 2240], // 10110
  30274. [12, 2304], // 10111
  30275. [11, 1856], [11, 1856], // 1100x
  30276. [11, 1920], [11, 1920], // 1101x
  30277. [12, 2368], // 11100
  30278. [12, 2432], // 11101
  30279. [12, 2496], // 11110
  30280. [12, 2560] // 11111
  30281. ];
  30282. var whiteTable2 = [
  30283. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30284. [8, 29], [8, 29], // 00000010x
  30285. [8, 30], [8, 30], // 00000011x
  30286. [8, 45], [8, 45], // 00000100x
  30287. [8, 46], [8, 46], // 00000101x
  30288. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30289. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30290. [8, 47], [8, 47], // 00001010x
  30291. [8, 48], [8, 48], // 00001011x
  30292. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30293. [6, 13], [6, 13], [6, 13], [6, 13],
  30294. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30295. [8, 33], [8, 33], // 00010010x
  30296. [8, 34], [8, 34], // 00010011x
  30297. [8, 35], [8, 35], // 00010100x
  30298. [8, 36], [8, 36], // 00010101x
  30299. [8, 37], [8, 37], // 00010110x
  30300. [8, 38], [8, 38], // 00010111x
  30301. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30302. [8, 31], [8, 31], // 00011010x
  30303. [8, 32], [8, 32], // 00011011x
  30304. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30305. [6, 1], [6, 1], [6, 1], [6, 1],
  30306. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30307. [6, 12], [6, 12], [6, 12], [6, 12],
  30308. [8, 53], [8, 53], // 00100100x
  30309. [8, 54], [8, 54], // 00100101x
  30310. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30311. [8, 39], [8, 39], // 00101000x
  30312. [8, 40], [8, 40], // 00101001x
  30313. [8, 41], [8, 41], // 00101010x
  30314. [8, 42], [8, 42], // 00101011x
  30315. [8, 43], [8, 43], // 00101100x
  30316. [8, 44], [8, 44], // 00101101x
  30317. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30318. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30319. [8, 61], [8, 61], // 00110010x
  30320. [8, 62], [8, 62], // 00110011x
  30321. [8, 63], [8, 63], // 00110100x
  30322. [8, 0], [8, 0], // 00110101x
  30323. [8, 320], [8, 320], // 00110110x
  30324. [8, 384], [8, 384], // 00110111x
  30325. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30326. [5, 10], [5, 10], [5, 10], [5, 10],
  30327. [5, 10], [5, 10], [5, 10], [5, 10],
  30328. [5, 10], [5, 10], [5, 10], [5, 10],
  30329. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30330. [5, 11], [5, 11], [5, 11], [5, 11],
  30331. [5, 11], [5, 11], [5, 11], [5, 11],
  30332. [5, 11], [5, 11], [5, 11], [5, 11],
  30333. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30334. [8, 59], [8, 59], // 01001010x
  30335. [8, 60], [8, 60], // 01001011x
  30336. [9, 1472], // 010011000
  30337. [9, 1536], // 010011001
  30338. [9, 1600], // 010011010
  30339. [9, 1728], // 010011011
  30340. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30341. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30342. [8, 49], [8, 49], // 01010010x
  30343. [8, 50], [8, 50], // 01010011x
  30344. [8, 51], [8, 51], // 01010100x
  30345. [8, 52], [8, 52], // 01010101x
  30346. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30347. [8, 55], [8, 55], // 01011000x
  30348. [8, 56], [8, 56], // 01011001x
  30349. [8, 57], [8, 57], // 01011010x
  30350. [8, 58], [8, 58], // 01011011x
  30351. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30352. [6, 192], [6, 192], [6, 192], [6, 192],
  30353. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30354. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30355. [8, 448], [8, 448], // 01100100x
  30356. [8, 512], [8, 512], // 01100101x
  30357. [9, 704], // 011001100
  30358. [9, 768], // 011001101
  30359. [8, 640], [8, 640], // 01100111x
  30360. [8, 576], [8, 576], // 01101000x
  30361. [9, 832], // 011010010
  30362. [9, 896], // 011010011
  30363. [9, 960], // 011010100
  30364. [9, 1024], // 011010101
  30365. [9, 1088], // 011010110
  30366. [9, 1152], // 011010111
  30367. [9, 1216], // 011011000
  30368. [9, 1280], // 011011001
  30369. [9, 1344], // 011011010
  30370. [9, 1408], // 011011011
  30371. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30372. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30373. [4, 2], [4, 2], [4, 2], [4, 2],
  30374. [4, 2], [4, 2], [4, 2], [4, 2],
  30375. [4, 2], [4, 2], [4, 2], [4, 2],
  30376. [4, 2], [4, 2], [4, 2], [4, 2],
  30377. [4, 2], [4, 2], [4, 2], [4, 2],
  30378. [4, 2], [4, 2], [4, 2], [4, 2],
  30379. [4, 2], [4, 2], [4, 2], [4, 2],
  30380. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30381. [4, 3], [4, 3], [4, 3], [4, 3],
  30382. [4, 3], [4, 3], [4, 3], [4, 3],
  30383. [4, 3], [4, 3], [4, 3], [4, 3],
  30384. [4, 3], [4, 3], [4, 3], [4, 3],
  30385. [4, 3], [4, 3], [4, 3], [4, 3],
  30386. [4, 3], [4, 3], [4, 3], [4, 3],
  30387. [4, 3], [4, 3], [4, 3], [4, 3],
  30388. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30389. [5, 128], [5, 128], [5, 128], [5, 128],
  30390. [5, 128], [5, 128], [5, 128], [5, 128],
  30391. [5, 128], [5, 128], [5, 128], [5, 128],
  30392. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30393. [5, 8], [5, 8], [5, 8], [5, 8],
  30394. [5, 8], [5, 8], [5, 8], [5, 8],
  30395. [5, 8], [5, 8], [5, 8], [5, 8],
  30396. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30397. [5, 9], [5, 9], [5, 9], [5, 9],
  30398. [5, 9], [5, 9], [5, 9], [5, 9],
  30399. [5, 9], [5, 9], [5, 9], [5, 9],
  30400. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30401. [6, 16], [6, 16], [6, 16], [6, 16],
  30402. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30403. [6, 17], [6, 17], [6, 17], [6, 17],
  30404. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30405. [4, 4], [4, 4], [4, 4], [4, 4],
  30406. [4, 4], [4, 4], [4, 4], [4, 4],
  30407. [4, 4], [4, 4], [4, 4], [4, 4],
  30408. [4, 4], [4, 4], [4, 4], [4, 4],
  30409. [4, 4], [4, 4], [4, 4], [4, 4],
  30410. [4, 4], [4, 4], [4, 4], [4, 4],
  30411. [4, 4], [4, 4], [4, 4], [4, 4],
  30412. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30413. [4, 5], [4, 5], [4, 5], [4, 5],
  30414. [4, 5], [4, 5], [4, 5], [4, 5],
  30415. [4, 5], [4, 5], [4, 5], [4, 5],
  30416. [4, 5], [4, 5], [4, 5], [4, 5],
  30417. [4, 5], [4, 5], [4, 5], [4, 5],
  30418. [4, 5], [4, 5], [4, 5], [4, 5],
  30419. [4, 5], [4, 5], [4, 5], [4, 5],
  30420. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30421. [6, 14], [6, 14], [6, 14], [6, 14],
  30422. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30423. [6, 15], [6, 15], [6, 15], [6, 15],
  30424. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30425. [5, 64], [5, 64], [5, 64], [5, 64],
  30426. [5, 64], [5, 64], [5, 64], [5, 64],
  30427. [5, 64], [5, 64], [5, 64], [5, 64],
  30428. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30429. [4, 6], [4, 6], [4, 6], [4, 6],
  30430. [4, 6], [4, 6], [4, 6], [4, 6],
  30431. [4, 6], [4, 6], [4, 6], [4, 6],
  30432. [4, 6], [4, 6], [4, 6], [4, 6],
  30433. [4, 6], [4, 6], [4, 6], [4, 6],
  30434. [4, 6], [4, 6], [4, 6], [4, 6],
  30435. [4, 6], [4, 6], [4, 6], [4, 6],
  30436. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30437. [4, 7], [4, 7], [4, 7], [4, 7],
  30438. [4, 7], [4, 7], [4, 7], [4, 7],
  30439. [4, 7], [4, 7], [4, 7], [4, 7],
  30440. [4, 7], [4, 7], [4, 7], [4, 7],
  30441. [4, 7], [4, 7], [4, 7], [4, 7],
  30442. [4, 7], [4, 7], [4, 7], [4, 7],
  30443. [4, 7], [4, 7], [4, 7], [4, 7]
  30444. ];
  30445. var blackTable1 = [
  30446. [-1, -1], [-1, -1], // 000000000000x
  30447. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30448. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30449. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30450. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30451. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30452. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30453. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30454. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30455. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30456. [12, 1984], [12, 1984], // 000000010010x
  30457. [12, 2048], [12, 2048], // 000000010011x
  30458. [12, 2112], [12, 2112], // 000000010100x
  30459. [12, 2176], [12, 2176], // 000000010101x
  30460. [12, 2240], [12, 2240], // 000000010110x
  30461. [12, 2304], [12, 2304], // 000000010111x
  30462. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30463. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30464. [12, 2368], [12, 2368], // 000000011100x
  30465. [12, 2432], [12, 2432], // 000000011101x
  30466. [12, 2496], [12, 2496], // 000000011110x
  30467. [12, 2560], [12, 2560], // 000000011111x
  30468. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30469. [10, 18], [10, 18], [10, 18], [10, 18],
  30470. [12, 52], [12, 52], // 000000100100x
  30471. [13, 640], // 0000001001010
  30472. [13, 704], // 0000001001011
  30473. [13, 768], // 0000001001100
  30474. [13, 832], // 0000001001101
  30475. [12, 55], [12, 55], // 000000100111x
  30476. [12, 56], [12, 56], // 000000101000x
  30477. [13, 1280], // 0000001010010
  30478. [13, 1344], // 0000001010011
  30479. [13, 1408], // 0000001010100
  30480. [13, 1472], // 0000001010101
  30481. [12, 59], [12, 59], // 000000101011x
  30482. [12, 60], [12, 60], // 000000101100x
  30483. [13, 1536], // 0000001011010
  30484. [13, 1600], // 0000001011011
  30485. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30486. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30487. [13, 1664], // 0000001100100
  30488. [13, 1728], // 0000001100101
  30489. [12, 320], [12, 320], // 000000110011x
  30490. [12, 384], [12, 384], // 000000110100x
  30491. [12, 448], [12, 448], // 000000110101x
  30492. [13, 512], // 0000001101100
  30493. [13, 576], // 0000001101101
  30494. [12, 53], [12, 53], // 000000110111x
  30495. [12, 54], [12, 54], // 000000111000x
  30496. [13, 896], // 0000001110010
  30497. [13, 960], // 0000001110011
  30498. [13, 1024], // 0000001110100
  30499. [13, 1088], // 0000001110101
  30500. [13, 1152], // 0000001110110
  30501. [13, 1216], // 0000001110111
  30502. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30503. [10, 64], [10, 64], [10, 64], [10, 64]
  30504. ];
  30505. var blackTable2 = [
  30506. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30507. [8, 13], [8, 13], [8, 13], [8, 13],
  30508. [8, 13], [8, 13], [8, 13], [8, 13],
  30509. [8, 13], [8, 13], [8, 13], [8, 13],
  30510. [11, 23], [11, 23], // 00000101000x
  30511. [12, 50], // 000001010010
  30512. [12, 51], // 000001010011
  30513. [12, 44], // 000001010100
  30514. [12, 45], // 000001010101
  30515. [12, 46], // 000001010110
  30516. [12, 47], // 000001010111
  30517. [12, 57], // 000001011000
  30518. [12, 58], // 000001011001
  30519. [12, 61], // 000001011010
  30520. [12, 256], // 000001011011
  30521. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30522. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30523. [12, 48], // 000001100100
  30524. [12, 49], // 000001100101
  30525. [12, 62], // 000001100110
  30526. [12, 63], // 000001100111
  30527. [12, 30], // 000001101000
  30528. [12, 31], // 000001101001
  30529. [12, 32], // 000001101010
  30530. [12, 33], // 000001101011
  30531. [12, 40], // 000001101100
  30532. [12, 41], // 000001101101
  30533. [11, 22], [11, 22], // 00000110111x
  30534. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30535. [8, 14], [8, 14], [8, 14], [8, 14],
  30536. [8, 14], [8, 14], [8, 14], [8, 14],
  30537. [8, 14], [8, 14], [8, 14], [8, 14],
  30538. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30539. [7, 10], [7, 10], [7, 10], [7, 10],
  30540. [7, 10], [7, 10], [7, 10], [7, 10],
  30541. [7, 10], [7, 10], [7, 10], [7, 10],
  30542. [7, 10], [7, 10], [7, 10], [7, 10],
  30543. [7, 10], [7, 10], [7, 10], [7, 10],
  30544. [7, 10], [7, 10], [7, 10], [7, 10],
  30545. [7, 10], [7, 10], [7, 10], [7, 10],
  30546. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30547. [7, 11], [7, 11], [7, 11], [7, 11],
  30548. [7, 11], [7, 11], [7, 11], [7, 11],
  30549. [7, 11], [7, 11], [7, 11], [7, 11],
  30550. [7, 11], [7, 11], [7, 11], [7, 11],
  30551. [7, 11], [7, 11], [7, 11], [7, 11],
  30552. [7, 11], [7, 11], [7, 11], [7, 11],
  30553. [7, 11], [7, 11], [7, 11], [7, 11],
  30554. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30555. [9, 15], [9, 15], [9, 15], [9, 15],
  30556. [12, 128], // 000011001000
  30557. [12, 192], // 000011001001
  30558. [12, 26], // 000011001010
  30559. [12, 27], // 000011001011
  30560. [12, 28], // 000011001100
  30561. [12, 29], // 000011001101
  30562. [11, 19], [11, 19], // 00001100111x
  30563. [11, 20], [11, 20], // 00001101000x
  30564. [12, 34], // 000011010010
  30565. [12, 35], // 000011010011
  30566. [12, 36], // 000011010100
  30567. [12, 37], // 000011010101
  30568. [12, 38], // 000011010110
  30569. [12, 39], // 000011010111
  30570. [11, 21], [11, 21], // 00001101100x
  30571. [12, 42], // 000011011010
  30572. [12, 43], // 000011011011
  30573. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30574. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30575. [7, 12], [7, 12], [7, 12], [7, 12],
  30576. [7, 12], [7, 12], [7, 12], [7, 12],
  30577. [7, 12], [7, 12], [7, 12], [7, 12],
  30578. [7, 12], [7, 12], [7, 12], [7, 12],
  30579. [7, 12], [7, 12], [7, 12], [7, 12],
  30580. [7, 12], [7, 12], [7, 12], [7, 12],
  30581. [7, 12], [7, 12], [7, 12], [7, 12]
  30582. ];
  30583. var blackTable3 = [
  30584. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30585. [6, 9], // 000100
  30586. [6, 8], // 000101
  30587. [5, 7], [5, 7], // 00011x
  30588. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30589. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30590. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30591. [3, 1], [3, 1], [3, 1], [3, 1],
  30592. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30593. [3, 4], [3, 4], [3, 4], [3, 4],
  30594. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30595. [2, 3], [2, 3], [2, 3], [2, 3],
  30596. [2, 3], [2, 3], [2, 3], [2, 3],
  30597. [2, 3], [2, 3], [2, 3], [2, 3],
  30598. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  30599. [2, 2], [2, 2], [2, 2], [2, 2],
  30600. [2, 2], [2, 2], [2, 2], [2, 2],
  30601. [2, 2], [2, 2], [2, 2], [2, 2]
  30602. ];
  30603. function CCITTFaxStream(str, maybeLength, params) {
  30604. this.str = str;
  30605. this.dict = str.dict;
  30606. params = params || Dict.empty;
  30607. this.encoding = params.get('K') || 0;
  30608. this.eoline = params.get('EndOfLine') || false;
  30609. this.byteAlign = params.get('EncodedByteAlign') || false;
  30610. this.columns = params.get('Columns') || 1728;
  30611. this.rows = params.get('Rows') || 0;
  30612. var eoblock = params.get('EndOfBlock');
  30613. if (eoblock === null || eoblock === undefined) {
  30614. eoblock = true;
  30615. }
  30616. this.eoblock = eoblock;
  30617. this.black = params.get('BlackIs1') || false;
  30618. this.codingLine = new Uint32Array(this.columns + 1);
  30619. this.refLine = new Uint32Array(this.columns + 2);
  30620. this.codingLine[0] = this.columns;
  30621. this.codingPos = 0;
  30622. this.row = 0;
  30623. this.nextLine2D = this.encoding < 0;
  30624. this.inputBits = 0;
  30625. this.inputBuf = 0;
  30626. this.outputBits = 0;
  30627. var code1;
  30628. while ((code1 = this.lookBits(12)) === 0) {
  30629. this.eatBits(1);
  30630. }
  30631. if (code1 === 1) {
  30632. this.eatBits(12);
  30633. }
  30634. if (this.encoding > 0) {
  30635. this.nextLine2D = !this.lookBits(1);
  30636. this.eatBits(1);
  30637. }
  30638. DecodeStream.call(this, maybeLength);
  30639. }
  30640. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30641. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30642. while (!this.eof) {
  30643. var c = this.lookChar();
  30644. this.ensureBuffer(this.bufferLength + 1);
  30645. this.buffer[this.bufferLength++] = c;
  30646. }
  30647. };
  30648. CCITTFaxStream.prototype.addPixels =
  30649. function ccittFaxStreamAddPixels(a1, blackPixels) {
  30650. var codingLine = this.codingLine;
  30651. var codingPos = this.codingPos;
  30652. if (a1 > codingLine[codingPos]) {
  30653. if (a1 > this.columns) {
  30654. info('row is wrong length');
  30655. this.err = true;
  30656. a1 = this.columns;
  30657. }
  30658. if ((codingPos & 1) ^ blackPixels) {
  30659. ++codingPos;
  30660. }
  30661. codingLine[codingPos] = a1;
  30662. }
  30663. this.codingPos = codingPos;
  30664. };
  30665. CCITTFaxStream.prototype.addPixelsNeg =
  30666. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30667. var codingLine = this.codingLine;
  30668. var codingPos = this.codingPos;
  30669. if (a1 > codingLine[codingPos]) {
  30670. if (a1 > this.columns) {
  30671. info('row is wrong length');
  30672. this.err = true;
  30673. a1 = this.columns;
  30674. }
  30675. if ((codingPos & 1) ^ blackPixels) {
  30676. ++codingPos;
  30677. }
  30678. codingLine[codingPos] = a1;
  30679. } else if (a1 < codingLine[codingPos]) {
  30680. if (a1 < 0) {
  30681. info('invalid code');
  30682. this.err = true;
  30683. a1 = 0;
  30684. }
  30685. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30686. --codingPos;
  30687. }
  30688. codingLine[codingPos] = a1;
  30689. }
  30690. this.codingPos = codingPos;
  30691. };
  30692. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30693. var refLine = this.refLine;
  30694. var codingLine = this.codingLine;
  30695. var columns = this.columns;
  30696. var refPos, blackPixels, bits, i;
  30697. if (this.outputBits === 0) {
  30698. if (this.eof) {
  30699. return null;
  30700. }
  30701. this.err = false;
  30702. var code1, code2, code3;
  30703. if (this.nextLine2D) {
  30704. for (i = 0; codingLine[i] < columns; ++i) {
  30705. refLine[i] = codingLine[i];
  30706. }
  30707. refLine[i++] = columns;
  30708. refLine[i] = columns;
  30709. codingLine[0] = 0;
  30710. this.codingPos = 0;
  30711. refPos = 0;
  30712. blackPixels = 0;
  30713. while (codingLine[this.codingPos] < columns) {
  30714. code1 = this.getTwoDimCode();
  30715. switch (code1) {
  30716. case twoDimPass:
  30717. this.addPixels(refLine[refPos + 1], blackPixels);
  30718. if (refLine[refPos + 1] < columns) {
  30719. refPos += 2;
  30720. }
  30721. break;
  30722. case twoDimHoriz:
  30723. code1 = code2 = 0;
  30724. if (blackPixels) {
  30725. do {
  30726. code1 += (code3 = this.getBlackCode());
  30727. } while (code3 >= 64);
  30728. do {
  30729. code2 += (code3 = this.getWhiteCode());
  30730. } while (code3 >= 64);
  30731. } else {
  30732. do {
  30733. code1 += (code3 = this.getWhiteCode());
  30734. } while (code3 >= 64);
  30735. do {
  30736. code2 += (code3 = this.getBlackCode());
  30737. } while (code3 >= 64);
  30738. }
  30739. this.addPixels(codingLine[this.codingPos] +
  30740. code1, blackPixels);
  30741. if (codingLine[this.codingPos] < columns) {
  30742. this.addPixels(codingLine[this.codingPos] + code2,
  30743. blackPixels ^ 1);
  30744. }
  30745. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30746. refLine[refPos] < columns) {
  30747. refPos += 2;
  30748. }
  30749. break;
  30750. case twoDimVertR3:
  30751. this.addPixels(refLine[refPos] + 3, blackPixels);
  30752. blackPixels ^= 1;
  30753. if (codingLine[this.codingPos] < columns) {
  30754. ++refPos;
  30755. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30756. refLine[refPos] < columns) {
  30757. refPos += 2;
  30758. }
  30759. }
  30760. break;
  30761. case twoDimVertR2:
  30762. this.addPixels(refLine[refPos] + 2, blackPixels);
  30763. blackPixels ^= 1;
  30764. if (codingLine[this.codingPos] < columns) {
  30765. ++refPos;
  30766. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30767. refLine[refPos] < columns) {
  30768. refPos += 2;
  30769. }
  30770. }
  30771. break;
  30772. case twoDimVertR1:
  30773. this.addPixels(refLine[refPos] + 1, blackPixels);
  30774. blackPixels ^= 1;
  30775. if (codingLine[this.codingPos] < columns) {
  30776. ++refPos;
  30777. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30778. refLine[refPos] < columns) {
  30779. refPos += 2;
  30780. }
  30781. }
  30782. break;
  30783. case twoDimVert0:
  30784. this.addPixels(refLine[refPos], blackPixels);
  30785. blackPixels ^= 1;
  30786. if (codingLine[this.codingPos] < columns) {
  30787. ++refPos;
  30788. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30789. refLine[refPos] < columns) {
  30790. refPos += 2;
  30791. }
  30792. }
  30793. break;
  30794. case twoDimVertL3:
  30795. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30796. blackPixels ^= 1;
  30797. if (codingLine[this.codingPos] < columns) {
  30798. if (refPos > 0) {
  30799. --refPos;
  30800. } else {
  30801. ++refPos;
  30802. }
  30803. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30804. refLine[refPos] < columns) {
  30805. refPos += 2;
  30806. }
  30807. }
  30808. break;
  30809. case twoDimVertL2:
  30810. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30811. blackPixels ^= 1;
  30812. if (codingLine[this.codingPos] < columns) {
  30813. if (refPos > 0) {
  30814. --refPos;
  30815. } else {
  30816. ++refPos;
  30817. }
  30818. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30819. refLine[refPos] < columns) {
  30820. refPos += 2;
  30821. }
  30822. }
  30823. break;
  30824. case twoDimVertL1:
  30825. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30826. blackPixels ^= 1;
  30827. if (codingLine[this.codingPos] < columns) {
  30828. if (refPos > 0) {
  30829. --refPos;
  30830. } else {
  30831. ++refPos;
  30832. }
  30833. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30834. refLine[refPos] < columns) {
  30835. refPos += 2;
  30836. }
  30837. }
  30838. break;
  30839. case EOF:
  30840. this.addPixels(columns, 0);
  30841. this.eof = true;
  30842. break;
  30843. default:
  30844. info('bad 2d code');
  30845. this.addPixels(columns, 0);
  30846. this.err = true;
  30847. }
  30848. }
  30849. } else {
  30850. codingLine[0] = 0;
  30851. this.codingPos = 0;
  30852. blackPixels = 0;
  30853. while (codingLine[this.codingPos] < columns) {
  30854. code1 = 0;
  30855. if (blackPixels) {
  30856. do {
  30857. code1 += (code3 = this.getBlackCode());
  30858. } while (code3 >= 64);
  30859. } else {
  30860. do {
  30861. code1 += (code3 = this.getWhiteCode());
  30862. } while (code3 >= 64);
  30863. }
  30864. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30865. blackPixels ^= 1;
  30866. }
  30867. }
  30868. var gotEOL = false;
  30869. if (!this.eoblock && this.row === this.rows - 1) {
  30870. this.eof = true;
  30871. } else if (this.eoline || !this.byteAlign) {
  30872. code1 = this.lookBits(12);
  30873. if (this.eoline) {
  30874. while (code1 !== EOF && code1 !== 1) {
  30875. this.eatBits(1);
  30876. code1 = this.lookBits(12);
  30877. }
  30878. } else {
  30879. while (code1 === 0) {
  30880. this.eatBits(1);
  30881. code1 = this.lookBits(12);
  30882. }
  30883. }
  30884. if (code1 === 1) {
  30885. this.eatBits(12);
  30886. gotEOL = true;
  30887. } else if (code1 === EOF) {
  30888. this.eof = true;
  30889. }
  30890. }
  30891. if (this.byteAlign && !gotEOL) {
  30892. this.inputBits &= ~7;
  30893. }
  30894. if (!this.eof && this.encoding > 0) {
  30895. this.nextLine2D = !this.lookBits(1);
  30896. this.eatBits(1);
  30897. }
  30898. if (this.eoblock && gotEOL && this.byteAlign) {
  30899. code1 = this.lookBits(12);
  30900. if (code1 === 1) {
  30901. this.eatBits(12);
  30902. if (this.encoding > 0) {
  30903. this.lookBits(1);
  30904. this.eatBits(1);
  30905. }
  30906. if (this.encoding >= 0) {
  30907. for (i = 0; i < 4; ++i) {
  30908. code1 = this.lookBits(12);
  30909. if (code1 !== 1) {
  30910. info('bad rtc code: ' + code1);
  30911. }
  30912. this.eatBits(12);
  30913. if (this.encoding > 0) {
  30914. this.lookBits(1);
  30915. this.eatBits(1);
  30916. }
  30917. }
  30918. }
  30919. this.eof = true;
  30920. }
  30921. } else if (this.err && this.eoline) {
  30922. while (true) {
  30923. code1 = this.lookBits(13);
  30924. if (code1 === EOF) {
  30925. this.eof = true;
  30926. return null;
  30927. }
  30928. if ((code1 >> 1) === 1) {
  30929. break;
  30930. }
  30931. this.eatBits(1);
  30932. }
  30933. this.eatBits(12);
  30934. if (this.encoding > 0) {
  30935. this.eatBits(1);
  30936. this.nextLine2D = !(code1 & 1);
  30937. }
  30938. }
  30939. if (codingLine[0] > 0) {
  30940. this.outputBits = codingLine[this.codingPos = 0];
  30941. } else {
  30942. this.outputBits = codingLine[this.codingPos = 1];
  30943. }
  30944. this.row++;
  30945. }
  30946. var c;
  30947. if (this.outputBits >= 8) {
  30948. c = (this.codingPos & 1) ? 0 : 0xFF;
  30949. this.outputBits -= 8;
  30950. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30951. this.codingPos++;
  30952. this.outputBits = (codingLine[this.codingPos] -
  30953. codingLine[this.codingPos - 1]);
  30954. }
  30955. } else {
  30956. bits = 8;
  30957. c = 0;
  30958. do {
  30959. if (this.outputBits > bits) {
  30960. c <<= bits;
  30961. if (!(this.codingPos & 1)) {
  30962. c |= 0xFF >> (8 - bits);
  30963. }
  30964. this.outputBits -= bits;
  30965. bits = 0;
  30966. } else {
  30967. c <<= this.outputBits;
  30968. if (!(this.codingPos & 1)) {
  30969. c |= 0xFF >> (8 - this.outputBits);
  30970. }
  30971. bits -= this.outputBits;
  30972. this.outputBits = 0;
  30973. if (codingLine[this.codingPos] < columns) {
  30974. this.codingPos++;
  30975. this.outputBits = (codingLine[this.codingPos] -
  30976. codingLine[this.codingPos - 1]);
  30977. } else if (bits > 0) {
  30978. c <<= bits;
  30979. bits = 0;
  30980. }
  30981. }
  30982. } while (bits);
  30983. }
  30984. if (this.black) {
  30985. c ^= 0xFF;
  30986. }
  30987. return c;
  30988. };
  30989. // This functions returns the code found from the table.
  30990. // The start and end parameters set the boundaries for searching the table.
  30991. // The limit parameter is optional. Function returns an array with three
  30992. // values. The first array element indicates whether a valid code is being
  30993. // returned. The second array element is the actual code. The third array
  30994. // element indicates whether EOF was reached.
  30995. CCITTFaxStream.prototype.findTableCode =
  30996. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30997. var limitValue = limit || 0;
  30998. for (var i = start; i <= end; ++i) {
  30999. var code = this.lookBits(i);
  31000. if (code === EOF) {
  31001. return [true, 1, false];
  31002. }
  31003. if (i < end) {
  31004. code <<= end - i;
  31005. }
  31006. if (!limitValue || code >= limitValue) {
  31007. var p = table[code - limitValue];
  31008. if (p[0] === i) {
  31009. this.eatBits(i);
  31010. return [true, p[1], true];
  31011. }
  31012. }
  31013. }
  31014. return [false, 0, false];
  31015. };
  31016. CCITTFaxStream.prototype.getTwoDimCode =
  31017. function ccittFaxStreamGetTwoDimCode() {
  31018. var code = 0;
  31019. var p;
  31020. if (this.eoblock) {
  31021. code = this.lookBits(7);
  31022. p = twoDimTable[code];
  31023. if (p && p[0] > 0) {
  31024. this.eatBits(p[0]);
  31025. return p[1];
  31026. }
  31027. } else {
  31028. var result = this.findTableCode(1, 7, twoDimTable);
  31029. if (result[0] && result[2]) {
  31030. return result[1];
  31031. }
  31032. }
  31033. info('Bad two dim code');
  31034. return EOF;
  31035. };
  31036. CCITTFaxStream.prototype.getWhiteCode =
  31037. function ccittFaxStreamGetWhiteCode() {
  31038. var code = 0;
  31039. var p;
  31040. if (this.eoblock) {
  31041. code = this.lookBits(12);
  31042. if (code === EOF) {
  31043. return 1;
  31044. }
  31045. if ((code >> 5) === 0) {
  31046. p = whiteTable1[code];
  31047. } else {
  31048. p = whiteTable2[code >> 3];
  31049. }
  31050. if (p[0] > 0) {
  31051. this.eatBits(p[0]);
  31052. return p[1];
  31053. }
  31054. } else {
  31055. var result = this.findTableCode(1, 9, whiteTable2);
  31056. if (result[0]) {
  31057. return result[1];
  31058. }
  31059. result = this.findTableCode(11, 12, whiteTable1);
  31060. if (result[0]) {
  31061. return result[1];
  31062. }
  31063. }
  31064. info('bad white code');
  31065. this.eatBits(1);
  31066. return 1;
  31067. };
  31068. CCITTFaxStream.prototype.getBlackCode =
  31069. function ccittFaxStreamGetBlackCode() {
  31070. var code, p;
  31071. if (this.eoblock) {
  31072. code = this.lookBits(13);
  31073. if (code === EOF) {
  31074. return 1;
  31075. }
  31076. if ((code >> 7) === 0) {
  31077. p = blackTable1[code];
  31078. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31079. p = blackTable2[(code >> 1) - 64];
  31080. } else {
  31081. p = blackTable3[code >> 7];
  31082. }
  31083. if (p[0] > 0) {
  31084. this.eatBits(p[0]);
  31085. return p[1];
  31086. }
  31087. } else {
  31088. var result = this.findTableCode(2, 6, blackTable3);
  31089. if (result[0]) {
  31090. return result[1];
  31091. }
  31092. result = this.findTableCode(7, 12, blackTable2, 64);
  31093. if (result[0]) {
  31094. return result[1];
  31095. }
  31096. result = this.findTableCode(10, 13, blackTable1);
  31097. if (result[0]) {
  31098. return result[1];
  31099. }
  31100. }
  31101. info('bad black code');
  31102. this.eatBits(1);
  31103. return 1;
  31104. };
  31105. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31106. var c;
  31107. while (this.inputBits < n) {
  31108. if ((c = this.str.getByte()) === -1) {
  31109. if (this.inputBits === 0) {
  31110. return EOF;
  31111. }
  31112. return ((this.inputBuf << (n - this.inputBits)) &
  31113. (0xFFFF >> (16 - n)));
  31114. }
  31115. this.inputBuf = (this.inputBuf << 8) + c;
  31116. this.inputBits += 8;
  31117. }
  31118. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31119. };
  31120. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31121. if ((this.inputBits -= n) < 0) {
  31122. this.inputBits = 0;
  31123. }
  31124. };
  31125. return CCITTFaxStream;
  31126. })();
  31127. var LZWStream = (function LZWStreamClosure() {
  31128. function LZWStream(str, maybeLength, earlyChange) {
  31129. this.str = str;
  31130. this.dict = str.dict;
  31131. this.cachedData = 0;
  31132. this.bitsCached = 0;
  31133. var maxLzwDictionarySize = 4096;
  31134. var lzwState = {
  31135. earlyChange: earlyChange,
  31136. codeLength: 9,
  31137. nextCode: 258,
  31138. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31139. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31140. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31141. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31142. currentSequenceLength: 0
  31143. };
  31144. for (var i = 0; i < 256; ++i) {
  31145. lzwState.dictionaryValues[i] = i;
  31146. lzwState.dictionaryLengths[i] = 1;
  31147. }
  31148. this.lzwState = lzwState;
  31149. DecodeStream.call(this, maybeLength);
  31150. }
  31151. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31152. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31153. var bitsCached = this.bitsCached;
  31154. var cachedData = this.cachedData;
  31155. while (bitsCached < n) {
  31156. var c = this.str.getByte();
  31157. if (c === -1) {
  31158. this.eof = true;
  31159. return null;
  31160. }
  31161. cachedData = (cachedData << 8) | c;
  31162. bitsCached += 8;
  31163. }
  31164. this.bitsCached = (bitsCached -= n);
  31165. this.cachedData = cachedData;
  31166. this.lastCode = null;
  31167. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31168. };
  31169. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31170. var blockSize = 512;
  31171. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31172. var i, j, q;
  31173. var lzwState = this.lzwState;
  31174. if (!lzwState) {
  31175. return; // eof was found
  31176. }
  31177. var earlyChange = lzwState.earlyChange;
  31178. var nextCode = lzwState.nextCode;
  31179. var dictionaryValues = lzwState.dictionaryValues;
  31180. var dictionaryLengths = lzwState.dictionaryLengths;
  31181. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31182. var codeLength = lzwState.codeLength;
  31183. var prevCode = lzwState.prevCode;
  31184. var currentSequence = lzwState.currentSequence;
  31185. var currentSequenceLength = lzwState.currentSequenceLength;
  31186. var decodedLength = 0;
  31187. var currentBufferLength = this.bufferLength;
  31188. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31189. for (i = 0; i < blockSize; i++) {
  31190. var code = this.readBits(codeLength);
  31191. var hasPrev = currentSequenceLength > 0;
  31192. if (code < 256) {
  31193. currentSequence[0] = code;
  31194. currentSequenceLength = 1;
  31195. } else if (code >= 258) {
  31196. if (code < nextCode) {
  31197. currentSequenceLength = dictionaryLengths[code];
  31198. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31199. currentSequence[j] = dictionaryValues[q];
  31200. q = dictionaryPrevCodes[q];
  31201. }
  31202. } else {
  31203. currentSequence[currentSequenceLength++] = currentSequence[0];
  31204. }
  31205. } else if (code === 256) {
  31206. codeLength = 9;
  31207. nextCode = 258;
  31208. currentSequenceLength = 0;
  31209. continue;
  31210. } else {
  31211. this.eof = true;
  31212. delete this.lzwState;
  31213. break;
  31214. }
  31215. if (hasPrev) {
  31216. dictionaryPrevCodes[nextCode] = prevCode;
  31217. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31218. dictionaryValues[nextCode] = currentSequence[0];
  31219. nextCode++;
  31220. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31221. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31222. 0.6931471805599453 + 1, 12) | 0;
  31223. }
  31224. prevCode = code;
  31225. decodedLength += currentSequenceLength;
  31226. if (estimatedDecodedSize < decodedLength) {
  31227. do {
  31228. estimatedDecodedSize += decodedSizeDelta;
  31229. } while (estimatedDecodedSize < decodedLength);
  31230. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31231. }
  31232. for (j = 0; j < currentSequenceLength; j++) {
  31233. buffer[currentBufferLength++] = currentSequence[j];
  31234. }
  31235. }
  31236. lzwState.nextCode = nextCode;
  31237. lzwState.codeLength = codeLength;
  31238. lzwState.prevCode = prevCode;
  31239. lzwState.currentSequenceLength = currentSequenceLength;
  31240. this.bufferLength = currentBufferLength;
  31241. };
  31242. return LZWStream;
  31243. })();
  31244. var NullStream = (function NullStreamClosure() {
  31245. function NullStream() {
  31246. Stream.call(this, new Uint8Array(0));
  31247. }
  31248. NullStream.prototype = Stream.prototype;
  31249. return NullStream;
  31250. })();
  31251. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31252. setup: function wphSetup(handler) {
  31253. var pdfManager;
  31254. function loadDocument(recoveryMode) {
  31255. var loadDocumentCapability = createPromiseCapability();
  31256. var parseSuccess = function parseSuccess() {
  31257. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31258. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31259. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31260. Promise.all([numPagesPromise, fingerprintPromise,
  31261. encryptedPromise]).then(function onDocReady(results) {
  31262. var doc = {
  31263. numPages: results[0],
  31264. fingerprint: results[1],
  31265. encrypted: !!results[2],
  31266. };
  31267. loadDocumentCapability.resolve(doc);
  31268. },
  31269. parseFailure);
  31270. };
  31271. var parseFailure = function parseFailure(e) {
  31272. loadDocumentCapability.reject(e);
  31273. };
  31274. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31275. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31276. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31277. parseSuccess, parseFailure);
  31278. }, parseFailure);
  31279. }, parseFailure);
  31280. return loadDocumentCapability.promise;
  31281. }
  31282. function getPdfManager(data) {
  31283. var pdfManagerCapability = createPromiseCapability();
  31284. var source = data.source;
  31285. var disableRange = data.disableRange;
  31286. if (source.data) {
  31287. try {
  31288. pdfManager = new LocalPdfManager(source.data, source.password);
  31289. pdfManagerCapability.resolve();
  31290. } catch (ex) {
  31291. pdfManagerCapability.reject(ex);
  31292. }
  31293. return pdfManagerCapability.promise;
  31294. } else if (source.chunkedViewerLoading) {
  31295. try {
  31296. pdfManager = new NetworkPdfManager(source, handler);
  31297. pdfManagerCapability.resolve();
  31298. } catch (ex) {
  31299. pdfManagerCapability.reject(ex);
  31300. }
  31301. return pdfManagerCapability.promise;
  31302. }
  31303. var networkManager = new NetworkManager(source.url, {
  31304. httpHeaders: source.httpHeaders,
  31305. withCredentials: source.withCredentials
  31306. });
  31307. var fullRequestXhrId = networkManager.requestFull({
  31308. onHeadersReceived: function onHeadersReceived() {
  31309. if (disableRange) {
  31310. return;
  31311. }
  31312. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31313. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31314. return;
  31315. }
  31316. var contentEncoding =
  31317. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31318. if (contentEncoding !== 'identity') {
  31319. return;
  31320. }
  31321. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31322. length = parseInt(length, 10);
  31323. if (!isInt(length)) {
  31324. return;
  31325. }
  31326. source.length = length;
  31327. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31328. // The file size is smaller than the size of two chunks, so it does
  31329. // not make any sense to abort the request and retry with a range
  31330. // request.
  31331. return;
  31332. }
  31333. // NOTE: by cancelling the full request, and then issuing range
  31334. // requests, there will be an issue for sites where you can only
  31335. // request the pdf once. However, if this is the case, then the
  31336. // server should not be returning that it can support range requests.
  31337. networkManager.abortRequest(fullRequestXhrId);
  31338. try {
  31339. pdfManager = new NetworkPdfManager(source, handler);
  31340. pdfManagerCapability.resolve(pdfManager);
  31341. } catch (ex) {
  31342. pdfManagerCapability.reject(ex);
  31343. }
  31344. },
  31345. onDone: function onDone(args) {
  31346. // the data is array, instantiating directly from it
  31347. try {
  31348. pdfManager = new LocalPdfManager(args.chunk, source.password);
  31349. pdfManagerCapability.resolve();
  31350. } catch (ex) {
  31351. pdfManagerCapability.reject(ex);
  31352. }
  31353. },
  31354. onError: function onError(status) {
  31355. var exception;
  31356. if (status === 404) {
  31357. exception = new MissingPDFException('Missing PDF "' +
  31358. source.url + '".');
  31359. handler.send('MissingPDF', exception);
  31360. } else {
  31361. exception = new UnexpectedResponseException(
  31362. 'Unexpected server response (' + status +
  31363. ') while retrieving PDF "' + source.url + '".', status);
  31364. handler.send('UnexpectedResponse', exception);
  31365. }
  31366. },
  31367. onProgress: function onProgress(evt) {
  31368. handler.send('DocProgress', {
  31369. loaded: evt.loaded,
  31370. total: evt.lengthComputable ? evt.total : source.length
  31371. });
  31372. }
  31373. });
  31374. return pdfManagerCapability.promise;
  31375. }
  31376. handler.on('test', function wphSetupTest(data) {
  31377. // check if Uint8Array can be sent to worker
  31378. if (!(data instanceof Uint8Array)) {
  31379. handler.send('test', false);
  31380. return;
  31381. }
  31382. // making sure postMessage transfers are working
  31383. var supportTransfers = data[0] === 255;
  31384. handler.postMessageTransfers = supportTransfers;
  31385. // check if the response property is supported by xhr
  31386. var xhr = new XMLHttpRequest();
  31387. var responseExists = 'response' in xhr;
  31388. // check if the property is actually implemented
  31389. try {
  31390. var dummy = xhr.responseType;
  31391. } catch (e) {
  31392. responseExists = false;
  31393. }
  31394. if (!responseExists) {
  31395. handler.send('test', false);
  31396. return;
  31397. }
  31398. handler.send('test', {
  31399. supportTypedArray: true,
  31400. supportTransfers: supportTransfers
  31401. });
  31402. });
  31403. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31404. var onSuccess = function(doc) {
  31405. handler.send('GetDoc', { pdfInfo: doc });
  31406. };
  31407. var onFailure = function(e) {
  31408. if (e instanceof PasswordException) {
  31409. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31410. handler.send('NeedPassword', e);
  31411. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31412. handler.send('IncorrectPassword', e);
  31413. }
  31414. } else if (e instanceof InvalidPDFException) {
  31415. handler.send('InvalidPDF', e);
  31416. } else if (e instanceof MissingPDFException) {
  31417. handler.send('MissingPDF', e);
  31418. } else if (e instanceof UnexpectedResponseException) {
  31419. handler.send('UnexpectedResponse', e);
  31420. } else {
  31421. handler.send('UnknownError',
  31422. new UnknownErrorException(e.message, e.toString()));
  31423. }
  31424. };
  31425. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31426. -1 : data.maxImageSize;
  31427. PDFJS.disableFontFace = data.disableFontFace;
  31428. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31429. PDFJS.verbosity = data.verbosity;
  31430. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31431. null : data.cMapUrl;
  31432. PDFJS.cMapPacked = data.cMapPacked === true;
  31433. getPdfManager(data).then(function () {
  31434. pdfManager.onLoadedStream().then(function(stream) {
  31435. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31436. });
  31437. }).then(function pdfManagerReady() {
  31438. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31439. // Try again with recoveryMode == true
  31440. if (!(ex instanceof XRefParseException)) {
  31441. if (ex instanceof PasswordException) {
  31442. // after password exception prepare to receive a new password
  31443. // to repeat loading
  31444. pdfManager.passwordChanged().then(pdfManagerReady);
  31445. }
  31446. onFailure(ex);
  31447. return;
  31448. }
  31449. pdfManager.requestLoadedStream();
  31450. pdfManager.onLoadedStream().then(function() {
  31451. loadDocument(true).then(onSuccess, onFailure);
  31452. });
  31453. }, onFailure);
  31454. }, onFailure);
  31455. });
  31456. handler.on('GetPage', function wphSetupGetPage(data) {
  31457. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31458. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31459. var refPromise = pdfManager.ensure(page, 'ref');
  31460. var viewPromise = pdfManager.ensure(page, 'view');
  31461. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31462. function(results) {
  31463. return {
  31464. rotate: results[0],
  31465. ref: results[1],
  31466. view: results[2]
  31467. };
  31468. });
  31469. });
  31470. });
  31471. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31472. var ref = new Ref(data.ref.num, data.ref.gen);
  31473. var catalog = pdfManager.pdfDocument.catalog;
  31474. return catalog.getPageIndex(ref);
  31475. });
  31476. handler.on('GetDestinations',
  31477. function wphSetupGetDestinations(data) {
  31478. return pdfManager.ensureCatalog('destinations');
  31479. }
  31480. );
  31481. handler.on('GetAttachments',
  31482. function wphSetupGetAttachments(data) {
  31483. return pdfManager.ensureCatalog('attachments');
  31484. }
  31485. );
  31486. handler.on('GetJavaScript',
  31487. function wphSetupGetJavaScript(data) {
  31488. return pdfManager.ensureCatalog('javaScript');
  31489. }
  31490. );
  31491. handler.on('GetOutline',
  31492. function wphSetupGetOutline(data) {
  31493. return pdfManager.ensureCatalog('documentOutline');
  31494. }
  31495. );
  31496. handler.on('GetMetadata',
  31497. function wphSetupGetMetadata(data) {
  31498. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31499. pdfManager.ensureCatalog('metadata')]);
  31500. }
  31501. );
  31502. handler.on('GetData', function wphSetupGetData(data) {
  31503. pdfManager.requestLoadedStream();
  31504. return pdfManager.onLoadedStream().then(function(stream) {
  31505. return stream.bytes;
  31506. });
  31507. });
  31508. handler.on('GetStats',
  31509. function wphSetupGetStats(data) {
  31510. return pdfManager.pdfDocument.xref.stats;
  31511. }
  31512. );
  31513. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31514. pdfManager.updatePassword(data);
  31515. });
  31516. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31517. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31518. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31519. });
  31520. });
  31521. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31522. pdfManager.getPage(data.pageIndex).then(function(page) {
  31523. var pageNum = data.pageIndex + 1;
  31524. var start = Date.now();
  31525. // Pre compile the pdf page and fetch the fonts/images.
  31526. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31527. info('page=' + pageNum + ' - getOperatorList: time=' +
  31528. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31529. }, function(e) {
  31530. var minimumStackMessage =
  31531. 'worker.js: while trying to getPage() and getOperatorList()';
  31532. var wrappedException;
  31533. // Turn the error into an obj that can be serialized
  31534. if (typeof e === 'string') {
  31535. wrappedException = {
  31536. message: e,
  31537. stack: minimumStackMessage
  31538. };
  31539. } else if (typeof e === 'object') {
  31540. wrappedException = {
  31541. message: e.message || e.toString(),
  31542. stack: e.stack || minimumStackMessage
  31543. };
  31544. } else {
  31545. wrappedException = {
  31546. message: 'Unknown exception type: ' + (typeof e),
  31547. stack: minimumStackMessage
  31548. };
  31549. }
  31550. handler.send('PageError', {
  31551. pageNum: pageNum,
  31552. error: wrappedException,
  31553. intent: data.intent
  31554. });
  31555. });
  31556. });
  31557. }, this);
  31558. handler.on('GetTextContent', function wphExtractText(data) {
  31559. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31560. var pageNum = data.pageIndex + 1;
  31561. var start = Date.now();
  31562. return page.extractTextContent().then(function(textContent) {
  31563. info('text indexing: page=' + pageNum + ' - time=' +
  31564. (Date.now() - start) + 'ms');
  31565. return textContent;
  31566. });
  31567. });
  31568. });
  31569. handler.on('Cleanup', function wphCleanup(data) {
  31570. return pdfManager.cleanup();
  31571. });
  31572. handler.on('Terminate', function wphTerminate(data) {
  31573. pdfManager.terminate();
  31574. });
  31575. }
  31576. };
  31577. var consoleTimer = {};
  31578. var workerConsole = {
  31579. log: function log() {
  31580. var args = Array.prototype.slice.call(arguments);
  31581. globalScope.postMessage({
  31582. action: 'console_log',
  31583. data: args
  31584. });
  31585. },
  31586. error: function error() {
  31587. var args = Array.prototype.slice.call(arguments);
  31588. globalScope.postMessage({
  31589. action: 'console_error',
  31590. data: args
  31591. });
  31592. throw 'pdf.js execution error';
  31593. },
  31594. time: function time(name) {
  31595. consoleTimer[name] = Date.now();
  31596. },
  31597. timeEnd: function timeEnd(name) {
  31598. var time = consoleTimer[name];
  31599. if (!time) {
  31600. error('Unknown timer name ' + name);
  31601. }
  31602. this.log('Timer:', name, Date.now() - time);
  31603. }
  31604. };
  31605. // Worker thread?
  31606. if (typeof window === 'undefined') {
  31607. if (!('console' in globalScope)) {
  31608. globalScope.console = workerConsole;
  31609. }
  31610. // Listen for unsupported features so we can pass them on to the main thread.
  31611. PDFJS.UnsupportedManager.listen(function (msg) {
  31612. globalScope.postMessage({
  31613. action: '_unsupported_feature',
  31614. data: msg
  31615. });
  31616. });
  31617. var handler = new MessageHandler('worker_processor', this);
  31618. WorkerMessageHandler.setup(handler);
  31619. }
  31620. /* This class implements the QM Coder decoding as defined in
  31621. * JPEG 2000 Part I Final Committee Draft Version 1.0
  31622. * Annex C.3 Arithmetic decoding procedure
  31623. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  31624. *
  31625. * The arithmetic decoder is used in conjunction with context models to decode
  31626. * JPEG2000 and JBIG2 streams.
  31627. */
  31628. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  31629. // Table C-2
  31630. var QeTable = [
  31631. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  31632. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  31633. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  31634. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  31635. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  31636. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  31637. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  31638. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  31639. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  31640. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  31641. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  31642. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  31643. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  31644. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  31645. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  31646. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  31647. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  31648. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  31649. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  31650. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  31651. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  31652. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  31653. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  31654. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  31655. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  31656. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  31657. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  31658. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  31659. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  31660. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  31661. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  31662. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  31663. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  31664. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  31665. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  31666. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  31667. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  31668. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  31669. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  31670. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  31671. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  31672. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  31673. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  31674. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  31675. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  31676. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  31677. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  31678. ];
  31679. // C.3.5 Initialisation of the decoder (INITDEC)
  31680. function ArithmeticDecoder(data, start, end) {
  31681. this.data = data;
  31682. this.bp = start;
  31683. this.dataEnd = end;
  31684. this.chigh = data[start];
  31685. this.clow = 0;
  31686. this.byteIn();
  31687. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  31688. this.clow = (this.clow << 7) & 0xFFFF;
  31689. this.ct -= 7;
  31690. this.a = 0x8000;
  31691. }
  31692. ArithmeticDecoder.prototype = {
  31693. // C.3.4 Compressed data input (BYTEIN)
  31694. byteIn: function ArithmeticDecoder_byteIn() {
  31695. var data = this.data;
  31696. var bp = this.bp;
  31697. if (data[bp] === 0xFF) {
  31698. var b1 = data[bp + 1];
  31699. if (b1 > 0x8F) {
  31700. this.clow += 0xFF00;
  31701. this.ct = 8;
  31702. } else {
  31703. bp++;
  31704. this.clow += (data[bp] << 9);
  31705. this.ct = 7;
  31706. this.bp = bp;
  31707. }
  31708. } else {
  31709. bp++;
  31710. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  31711. this.ct = 8;
  31712. this.bp = bp;
  31713. }
  31714. if (this.clow > 0xFFFF) {
  31715. this.chigh += (this.clow >> 16);
  31716. this.clow &= 0xFFFF;
  31717. }
  31718. },
  31719. // C.3.2 Decoding a decision (DECODE)
  31720. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  31721. // contexts are packed into 1 byte:
  31722. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  31723. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  31724. var qeTableIcx = QeTable[cx_index];
  31725. var qeIcx = qeTableIcx.qe;
  31726. var d;
  31727. var a = this.a - qeIcx;
  31728. if (this.chigh < qeIcx) {
  31729. // exchangeLps
  31730. if (a < qeIcx) {
  31731. a = qeIcx;
  31732. d = cx_mps;
  31733. cx_index = qeTableIcx.nmps;
  31734. } else {
  31735. a = qeIcx;
  31736. d = 1 ^ cx_mps;
  31737. if (qeTableIcx.switchFlag === 1) {
  31738. cx_mps = d;
  31739. }
  31740. cx_index = qeTableIcx.nlps;
  31741. }
  31742. } else {
  31743. this.chigh -= qeIcx;
  31744. if ((a & 0x8000) !== 0) {
  31745. this.a = a;
  31746. return cx_mps;
  31747. }
  31748. // exchangeMps
  31749. if (a < qeIcx) {
  31750. d = 1 ^ cx_mps;
  31751. if (qeTableIcx.switchFlag === 1) {
  31752. cx_mps = d;
  31753. }
  31754. cx_index = qeTableIcx.nlps;
  31755. } else {
  31756. d = cx_mps;
  31757. cx_index = qeTableIcx.nmps;
  31758. }
  31759. }
  31760. // C.3.3 renormD;
  31761. do {
  31762. if (this.ct === 0) {
  31763. this.byteIn();
  31764. }
  31765. a <<= 1;
  31766. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  31767. this.clow = (this.clow << 1) & 0xFFFF;
  31768. this.ct--;
  31769. } while ((a & 0x8000) === 0);
  31770. this.a = a;
  31771. contexts[pos] = cx_index << 1 | cx_mps;
  31772. return d;
  31773. }
  31774. };
  31775. return ArithmeticDecoder;
  31776. })();
  31777. var JpegImage = (function jpegImage() {
  31778. var dctZigZag = new Uint8Array([
  31779. 0,
  31780. 1, 8,
  31781. 16, 9, 2,
  31782. 3, 10, 17, 24,
  31783. 32, 25, 18, 11, 4,
  31784. 5, 12, 19, 26, 33, 40,
  31785. 48, 41, 34, 27, 20, 13, 6,
  31786. 7, 14, 21, 28, 35, 42, 49, 56,
  31787. 57, 50, 43, 36, 29, 22, 15,
  31788. 23, 30, 37, 44, 51, 58,
  31789. 59, 52, 45, 38, 31,
  31790. 39, 46, 53, 60,
  31791. 61, 54, 47,
  31792. 55, 62,
  31793. 63
  31794. ]);
  31795. var dctCos1 = 4017; // cos(pi/16)
  31796. var dctSin1 = 799; // sin(pi/16)
  31797. var dctCos3 = 3406; // cos(3*pi/16)
  31798. var dctSin3 = 2276; // sin(3*pi/16)
  31799. var dctCos6 = 1567; // cos(6*pi/16)
  31800. var dctSin6 = 3784; // sin(6*pi/16)
  31801. var dctSqrt2 = 5793; // sqrt(2)
  31802. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  31803. function constructor() {
  31804. }
  31805. function buildHuffmanTable(codeLengths, values) {
  31806. var k = 0, code = [], i, j, length = 16;
  31807. while (length > 0 && !codeLengths[length - 1]) {
  31808. length--;
  31809. }
  31810. code.push({children: [], index: 0});
  31811. var p = code[0], q;
  31812. for (i = 0; i < length; i++) {
  31813. for (j = 0; j < codeLengths[i]; j++) {
  31814. p = code.pop();
  31815. p.children[p.index] = values[k];
  31816. while (p.index > 0) {
  31817. p = code.pop();
  31818. }
  31819. p.index++;
  31820. code.push(p);
  31821. while (code.length <= i) {
  31822. code.push(q = {children: [], index: 0});
  31823. p.children[p.index] = q.children;
  31824. p = q;
  31825. }
  31826. k++;
  31827. }
  31828. if (i + 1 < length) {
  31829. // p here points to last code
  31830. code.push(q = {children: [], index: 0});
  31831. p.children[p.index] = q.children;
  31832. p = q;
  31833. }
  31834. }
  31835. return code[0].children;
  31836. }
  31837. function getBlockBufferOffset(component, row, col) {
  31838. return 64 * ((component.blocksPerLine + 1) * row + col);
  31839. }
  31840. function decodeScan(data, offset, frame, components, resetInterval,
  31841. spectralStart, spectralEnd, successivePrev, successive) {
  31842. var precision = frame.precision;
  31843. var samplesPerLine = frame.samplesPerLine;
  31844. var scanLines = frame.scanLines;
  31845. var mcusPerLine = frame.mcusPerLine;
  31846. var progressive = frame.progressive;
  31847. var maxH = frame.maxH, maxV = frame.maxV;
  31848. var startOffset = offset, bitsData = 0, bitsCount = 0;
  31849. function readBit() {
  31850. if (bitsCount > 0) {
  31851. bitsCount--;
  31852. return (bitsData >> bitsCount) & 1;
  31853. }
  31854. bitsData = data[offset++];
  31855. if (bitsData === 0xFF) {
  31856. var nextByte = data[offset++];
  31857. if (nextByte) {
  31858. throw 'unexpected marker: ' +
  31859. ((bitsData << 8) | nextByte).toString(16);
  31860. }
  31861. // unstuff 0
  31862. }
  31863. bitsCount = 7;
  31864. return bitsData >>> 7;
  31865. }
  31866. function decodeHuffman(tree) {
  31867. var node = tree;
  31868. var bit;
  31869. while ((bit = readBit()) !== null) {
  31870. node = node[bit];
  31871. if (typeof node === 'number') {
  31872. return node;
  31873. }
  31874. if (typeof node !== 'object') {
  31875. throw 'invalid huffman sequence';
  31876. }
  31877. }
  31878. return null;
  31879. }
  31880. function receive(length) {
  31881. var n = 0;
  31882. while (length > 0) {
  31883. var bit = readBit();
  31884. if (bit === null) {
  31885. return;
  31886. }
  31887. n = (n << 1) | bit;
  31888. length--;
  31889. }
  31890. return n;
  31891. }
  31892. function receiveAndExtend(length) {
  31893. if (length === 1) {
  31894. return readBit() === 1 ? 1 : -1;
  31895. }
  31896. var n = receive(length);
  31897. if (n >= 1 << (length - 1)) {
  31898. return n;
  31899. }
  31900. return n + (-1 << length) + 1;
  31901. }
  31902. function decodeBaseline(component, offset) {
  31903. var t = decodeHuffman(component.huffmanTableDC);
  31904. var diff = t === 0 ? 0 : receiveAndExtend(t);
  31905. component.blockData[offset] = (component.pred += diff);
  31906. var k = 1;
  31907. while (k < 64) {
  31908. var rs = decodeHuffman(component.huffmanTableAC);
  31909. var s = rs & 15, r = rs >> 4;
  31910. if (s === 0) {
  31911. if (r < 15) {
  31912. break;
  31913. }
  31914. k += 16;
  31915. continue;
  31916. }
  31917. k += r;
  31918. var z = dctZigZag[k];
  31919. component.blockData[offset + z] = receiveAndExtend(s);
  31920. k++;
  31921. }
  31922. }
  31923. function decodeDCFirst(component, offset) {
  31924. var t = decodeHuffman(component.huffmanTableDC);
  31925. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  31926. component.blockData[offset] = (component.pred += diff);
  31927. }
  31928. function decodeDCSuccessive(component, offset) {
  31929. component.blockData[offset] |= readBit() << successive;
  31930. }
  31931. var eobrun = 0;
  31932. function decodeACFirst(component, offset) {
  31933. if (eobrun > 0) {
  31934. eobrun--;
  31935. return;
  31936. }
  31937. var k = spectralStart, e = spectralEnd;
  31938. while (k <= e) {
  31939. var rs = decodeHuffman(component.huffmanTableAC);
  31940. var s = rs & 15, r = rs >> 4;
  31941. if (s === 0) {
  31942. if (r < 15) {
  31943. eobrun = receive(r) + (1 << r) - 1;
  31944. break;
  31945. }
  31946. k += 16;
  31947. continue;
  31948. }
  31949. k += r;
  31950. var z = dctZigZag[k];
  31951. component.blockData[offset + z] =
  31952. receiveAndExtend(s) * (1 << successive);
  31953. k++;
  31954. }
  31955. }
  31956. var successiveACState = 0, successiveACNextValue;
  31957. function decodeACSuccessive(component, offset) {
  31958. var k = spectralStart;
  31959. var e = spectralEnd;
  31960. var r = 0;
  31961. var s;
  31962. var rs;
  31963. while (k <= e) {
  31964. var z = dctZigZag[k];
  31965. switch (successiveACState) {
  31966. case 0: // initial state
  31967. rs = decodeHuffman(component.huffmanTableAC);
  31968. s = rs & 15;
  31969. r = rs >> 4;
  31970. if (s === 0) {
  31971. if (r < 15) {
  31972. eobrun = receive(r) + (1 << r);
  31973. successiveACState = 4;
  31974. } else {
  31975. r = 16;
  31976. successiveACState = 1;
  31977. }
  31978. } else {
  31979. if (s !== 1) {
  31980. throw 'invalid ACn encoding';
  31981. }
  31982. successiveACNextValue = receiveAndExtend(s);
  31983. successiveACState = r ? 2 : 3;
  31984. }
  31985. continue;
  31986. case 1: // skipping r zero items
  31987. case 2:
  31988. if (component.blockData[offset + z]) {
  31989. component.blockData[offset + z] += (readBit() << successive);
  31990. } else {
  31991. r--;
  31992. if (r === 0) {
  31993. successiveACState = successiveACState === 2 ? 3 : 0;
  31994. }
  31995. }
  31996. break;
  31997. case 3: // set value for a zero item
  31998. if (component.blockData[offset + z]) {
  31999. component.blockData[offset + z] += (readBit() << successive);
  32000. } else {
  32001. component.blockData[offset + z] =
  32002. successiveACNextValue << successive;
  32003. successiveACState = 0;
  32004. }
  32005. break;
  32006. case 4: // eob
  32007. if (component.blockData[offset + z]) {
  32008. component.blockData[offset + z] += (readBit() << successive);
  32009. }
  32010. break;
  32011. }
  32012. k++;
  32013. }
  32014. if (successiveACState === 4) {
  32015. eobrun--;
  32016. if (eobrun === 0) {
  32017. successiveACState = 0;
  32018. }
  32019. }
  32020. }
  32021. function decodeMcu(component, decode, mcu, row, col) {
  32022. var mcuRow = (mcu / mcusPerLine) | 0;
  32023. var mcuCol = mcu % mcusPerLine;
  32024. var blockRow = mcuRow * component.v + row;
  32025. var blockCol = mcuCol * component.h + col;
  32026. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32027. decode(component, offset);
  32028. }
  32029. function decodeBlock(component, decode, mcu) {
  32030. var blockRow = (mcu / component.blocksPerLine) | 0;
  32031. var blockCol = mcu % component.blocksPerLine;
  32032. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32033. decode(component, offset);
  32034. }
  32035. var componentsLength = components.length;
  32036. var component, i, j, k, n;
  32037. var decodeFn;
  32038. if (progressive) {
  32039. if (spectralStart === 0) {
  32040. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32041. } else {
  32042. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32043. }
  32044. } else {
  32045. decodeFn = decodeBaseline;
  32046. }
  32047. var mcu = 0, marker;
  32048. var mcuExpected;
  32049. if (componentsLength === 1) {
  32050. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32051. } else {
  32052. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32053. }
  32054. if (!resetInterval) {
  32055. resetInterval = mcuExpected;
  32056. }
  32057. var h, v;
  32058. while (mcu < mcuExpected) {
  32059. // reset interval stuff
  32060. for (i = 0; i < componentsLength; i++) {
  32061. components[i].pred = 0;
  32062. }
  32063. eobrun = 0;
  32064. if (componentsLength === 1) {
  32065. component = components[0];
  32066. for (n = 0; n < resetInterval; n++) {
  32067. decodeBlock(component, decodeFn, mcu);
  32068. mcu++;
  32069. }
  32070. } else {
  32071. for (n = 0; n < resetInterval; n++) {
  32072. for (i = 0; i < componentsLength; i++) {
  32073. component = components[i];
  32074. h = component.h;
  32075. v = component.v;
  32076. for (j = 0; j < v; j++) {
  32077. for (k = 0; k < h; k++) {
  32078. decodeMcu(component, decodeFn, mcu, j, k);
  32079. }
  32080. }
  32081. }
  32082. mcu++;
  32083. }
  32084. }
  32085. // find marker
  32086. bitsCount = 0;
  32087. marker = (data[offset] << 8) | data[offset + 1];
  32088. if (marker <= 0xFF00) {
  32089. throw 'marker was not found';
  32090. }
  32091. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32092. offset += 2;
  32093. } else {
  32094. break;
  32095. }
  32096. }
  32097. return offset - startOffset;
  32098. }
  32099. // A port of poppler's IDCT method which in turn is taken from:
  32100. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32101. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32102. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32103. // 988-991.
  32104. function quantizeAndInverse(component, blockBufferOffset, p) {
  32105. var qt = component.quantizationTable, blockData = component.blockData;
  32106. var v0, v1, v2, v3, v4, v5, v6, v7;
  32107. var p0, p1, p2, p3, p4, p5, p6, p7;
  32108. var t;
  32109. // inverse DCT on rows
  32110. for (var row = 0; row < 64; row += 8) {
  32111. // gather block data
  32112. p0 = blockData[blockBufferOffset + row];
  32113. p1 = blockData[blockBufferOffset + row + 1];
  32114. p2 = blockData[blockBufferOffset + row + 2];
  32115. p3 = blockData[blockBufferOffset + row + 3];
  32116. p4 = blockData[blockBufferOffset + row + 4];
  32117. p5 = blockData[blockBufferOffset + row + 5];
  32118. p6 = blockData[blockBufferOffset + row + 6];
  32119. p7 = blockData[blockBufferOffset + row + 7];
  32120. // dequant p0
  32121. p0 *= qt[row];
  32122. // check for all-zero AC coefficients
  32123. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32124. t = (dctSqrt2 * p0 + 512) >> 10;
  32125. p[row] = t;
  32126. p[row + 1] = t;
  32127. p[row + 2] = t;
  32128. p[row + 3] = t;
  32129. p[row + 4] = t;
  32130. p[row + 5] = t;
  32131. p[row + 6] = t;
  32132. p[row + 7] = t;
  32133. continue;
  32134. }
  32135. // dequant p1 ... p7
  32136. p1 *= qt[row + 1];
  32137. p2 *= qt[row + 2];
  32138. p3 *= qt[row + 3];
  32139. p4 *= qt[row + 4];
  32140. p5 *= qt[row + 5];
  32141. p6 *= qt[row + 6];
  32142. p7 *= qt[row + 7];
  32143. // stage 4
  32144. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32145. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32146. v2 = p2;
  32147. v3 = p6;
  32148. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32149. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32150. v5 = p3 << 4;
  32151. v6 = p5 << 4;
  32152. // stage 3
  32153. v0 = (v0 + v1 + 1) >> 1;
  32154. v1 = v0 - v1;
  32155. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32156. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32157. v3 = t;
  32158. v4 = (v4 + v6 + 1) >> 1;
  32159. v6 = v4 - v6;
  32160. v7 = (v7 + v5 + 1) >> 1;
  32161. v5 = v7 - v5;
  32162. // stage 2
  32163. v0 = (v0 + v3 + 1) >> 1;
  32164. v3 = v0 - v3;
  32165. v1 = (v1 + v2 + 1) >> 1;
  32166. v2 = v1 - v2;
  32167. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32168. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32169. v7 = t;
  32170. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32171. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32172. v6 = t;
  32173. // stage 1
  32174. p[row] = v0 + v7;
  32175. p[row + 7] = v0 - v7;
  32176. p[row + 1] = v1 + v6;
  32177. p[row + 6] = v1 - v6;
  32178. p[row + 2] = v2 + v5;
  32179. p[row + 5] = v2 - v5;
  32180. p[row + 3] = v3 + v4;
  32181. p[row + 4] = v3 - v4;
  32182. }
  32183. // inverse DCT on columns
  32184. for (var col = 0; col < 8; ++col) {
  32185. p0 = p[col];
  32186. p1 = p[col + 8];
  32187. p2 = p[col + 16];
  32188. p3 = p[col + 24];
  32189. p4 = p[col + 32];
  32190. p5 = p[col + 40];
  32191. p6 = p[col + 48];
  32192. p7 = p[col + 56];
  32193. // check for all-zero AC coefficients
  32194. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32195. t = (dctSqrt2 * p0 + 8192) >> 14;
  32196. // convert to 8 bit
  32197. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32198. blockData[blockBufferOffset + col] = t;
  32199. blockData[blockBufferOffset + col + 8] = t;
  32200. blockData[blockBufferOffset + col + 16] = t;
  32201. blockData[blockBufferOffset + col + 24] = t;
  32202. blockData[blockBufferOffset + col + 32] = t;
  32203. blockData[blockBufferOffset + col + 40] = t;
  32204. blockData[blockBufferOffset + col + 48] = t;
  32205. blockData[blockBufferOffset + col + 56] = t;
  32206. continue;
  32207. }
  32208. // stage 4
  32209. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32210. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32211. v2 = p2;
  32212. v3 = p6;
  32213. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32214. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32215. v5 = p3;
  32216. v6 = p5;
  32217. // stage 3
  32218. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32219. // converting to UInt8 range later.
  32220. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32221. v1 = v0 - v1;
  32222. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32223. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32224. v3 = t;
  32225. v4 = (v4 + v6 + 1) >> 1;
  32226. v6 = v4 - v6;
  32227. v7 = (v7 + v5 + 1) >> 1;
  32228. v5 = v7 - v5;
  32229. // stage 2
  32230. v0 = (v0 + v3 + 1) >> 1;
  32231. v3 = v0 - v3;
  32232. v1 = (v1 + v2 + 1) >> 1;
  32233. v2 = v1 - v2;
  32234. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32235. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32236. v7 = t;
  32237. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32238. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32239. v6 = t;
  32240. // stage 1
  32241. p0 = v0 + v7;
  32242. p7 = v0 - v7;
  32243. p1 = v1 + v6;
  32244. p6 = v1 - v6;
  32245. p2 = v2 + v5;
  32246. p5 = v2 - v5;
  32247. p3 = v3 + v4;
  32248. p4 = v3 - v4;
  32249. // convert to 8-bit integers
  32250. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32251. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32252. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32253. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32254. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32255. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32256. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32257. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32258. // store block data
  32259. blockData[blockBufferOffset + col] = p0;
  32260. blockData[blockBufferOffset + col + 8] = p1;
  32261. blockData[blockBufferOffset + col + 16] = p2;
  32262. blockData[blockBufferOffset + col + 24] = p3;
  32263. blockData[blockBufferOffset + col + 32] = p4;
  32264. blockData[blockBufferOffset + col + 40] = p5;
  32265. blockData[blockBufferOffset + col + 48] = p6;
  32266. blockData[blockBufferOffset + col + 56] = p7;
  32267. }
  32268. }
  32269. function buildComponentData(frame, component) {
  32270. var blocksPerLine = component.blocksPerLine;
  32271. var blocksPerColumn = component.blocksPerColumn;
  32272. var computationBuffer = new Int16Array(64);
  32273. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32274. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32275. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32276. quantizeAndInverse(component, offset, computationBuffer);
  32277. }
  32278. }
  32279. return component.blockData;
  32280. }
  32281. function clamp0to255(a) {
  32282. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32283. }
  32284. constructor.prototype = {
  32285. parse: function parse(data) {
  32286. function readUint16() {
  32287. var value = (data[offset] << 8) | data[offset + 1];
  32288. offset += 2;
  32289. return value;
  32290. }
  32291. function readDataBlock() {
  32292. var length = readUint16();
  32293. var array = data.subarray(offset, offset + length - 2);
  32294. offset += array.length;
  32295. return array;
  32296. }
  32297. function prepareComponents(frame) {
  32298. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32299. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32300. for (var i = 0; i < frame.components.length; i++) {
  32301. component = frame.components[i];
  32302. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32303. component.h / frame.maxH);
  32304. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32305. component.v / frame.maxV);
  32306. var blocksPerLineForMcu = mcusPerLine * component.h;
  32307. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32308. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32309. (blocksPerLineForMcu + 1);
  32310. component.blockData = new Int16Array(blocksBufferSize);
  32311. component.blocksPerLine = blocksPerLine;
  32312. component.blocksPerColumn = blocksPerColumn;
  32313. }
  32314. frame.mcusPerLine = mcusPerLine;
  32315. frame.mcusPerColumn = mcusPerColumn;
  32316. }
  32317. var offset = 0, length = data.length;
  32318. var jfif = null;
  32319. var adobe = null;
  32320. var pixels = null;
  32321. var frame, resetInterval;
  32322. var quantizationTables = [];
  32323. var huffmanTablesAC = [], huffmanTablesDC = [];
  32324. var fileMarker = readUint16();
  32325. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32326. throw 'SOI not found';
  32327. }
  32328. fileMarker = readUint16();
  32329. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32330. var i, j, l;
  32331. switch(fileMarker) {
  32332. case 0xFFE0: // APP0 (Application Specific)
  32333. case 0xFFE1: // APP1
  32334. case 0xFFE2: // APP2
  32335. case 0xFFE3: // APP3
  32336. case 0xFFE4: // APP4
  32337. case 0xFFE5: // APP5
  32338. case 0xFFE6: // APP6
  32339. case 0xFFE7: // APP7
  32340. case 0xFFE8: // APP8
  32341. case 0xFFE9: // APP9
  32342. case 0xFFEA: // APP10
  32343. case 0xFFEB: // APP11
  32344. case 0xFFEC: // APP12
  32345. case 0xFFED: // APP13
  32346. case 0xFFEE: // APP14
  32347. case 0xFFEF: // APP15
  32348. case 0xFFFE: // COM (Comment)
  32349. var appData = readDataBlock();
  32350. if (fileMarker === 0xFFE0) {
  32351. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32352. appData[2] === 0x49 && appData[3] === 0x46 &&
  32353. appData[4] === 0) { // 'JFIF\x00'
  32354. jfif = {
  32355. version: { major: appData[5], minor: appData[6] },
  32356. densityUnits: appData[7],
  32357. xDensity: (appData[8] << 8) | appData[9],
  32358. yDensity: (appData[10] << 8) | appData[11],
  32359. thumbWidth: appData[12],
  32360. thumbHeight: appData[13],
  32361. thumbData: appData.subarray(14, 14 +
  32362. 3 * appData[12] * appData[13])
  32363. };
  32364. }
  32365. }
  32366. // TODO APP1 - Exif
  32367. if (fileMarker === 0xFFEE) {
  32368. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32369. appData[2] === 0x6F && appData[3] === 0x62 &&
  32370. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32371. adobe = {
  32372. version: appData[6],
  32373. flags0: (appData[7] << 8) | appData[8],
  32374. flags1: (appData[9] << 8) | appData[10],
  32375. transformCode: appData[11]
  32376. };
  32377. }
  32378. }
  32379. break;
  32380. case 0xFFDB: // DQT (Define Quantization Tables)
  32381. var quantizationTablesLength = readUint16();
  32382. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32383. var z;
  32384. while (offset < quantizationTablesEnd) {
  32385. var quantizationTableSpec = data[offset++];
  32386. var tableData = new Uint16Array(64);
  32387. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32388. for (j = 0; j < 64; j++) {
  32389. z = dctZigZag[j];
  32390. tableData[z] = data[offset++];
  32391. }
  32392. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32393. for (j = 0; j < 64; j++) {
  32394. z = dctZigZag[j];
  32395. tableData[z] = readUint16();
  32396. }
  32397. } else {
  32398. throw 'DQT: invalid table spec';
  32399. }
  32400. quantizationTables[quantizationTableSpec & 15] = tableData;
  32401. }
  32402. break;
  32403. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32404. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32405. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32406. if (frame) {
  32407. throw 'Only single frame JPEGs supported';
  32408. }
  32409. readUint16(); // skip data length
  32410. frame = {};
  32411. frame.extended = (fileMarker === 0xFFC1);
  32412. frame.progressive = (fileMarker === 0xFFC2);
  32413. frame.precision = data[offset++];
  32414. frame.scanLines = readUint16();
  32415. frame.samplesPerLine = readUint16();
  32416. frame.components = [];
  32417. frame.componentIds = {};
  32418. var componentsCount = data[offset++], componentId;
  32419. var maxH = 0, maxV = 0;
  32420. for (i = 0; i < componentsCount; i++) {
  32421. componentId = data[offset];
  32422. var h = data[offset + 1] >> 4;
  32423. var v = data[offset + 1] & 15;
  32424. if (maxH < h) {
  32425. maxH = h;
  32426. }
  32427. if (maxV < v) {
  32428. maxV = v;
  32429. }
  32430. var qId = data[offset + 2];
  32431. l = frame.components.push({
  32432. h: h,
  32433. v: v,
  32434. quantizationTable: quantizationTables[qId]
  32435. });
  32436. frame.componentIds[componentId] = l - 1;
  32437. offset += 3;
  32438. }
  32439. frame.maxH = maxH;
  32440. frame.maxV = maxV;
  32441. prepareComponents(frame);
  32442. break;
  32443. case 0xFFC4: // DHT (Define Huffman Tables)
  32444. var huffmanLength = readUint16();
  32445. for (i = 2; i < huffmanLength;) {
  32446. var huffmanTableSpec = data[offset++];
  32447. var codeLengths = new Uint8Array(16);
  32448. var codeLengthSum = 0;
  32449. for (j = 0; j < 16; j++, offset++) {
  32450. codeLengthSum += (codeLengths[j] = data[offset]);
  32451. }
  32452. var huffmanValues = new Uint8Array(codeLengthSum);
  32453. for (j = 0; j < codeLengthSum; j++, offset++) {
  32454. huffmanValues[j] = data[offset];
  32455. }
  32456. i += 17 + codeLengthSum;
  32457. ((huffmanTableSpec >> 4) === 0 ?
  32458. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32459. buildHuffmanTable(codeLengths, huffmanValues);
  32460. }
  32461. break;
  32462. case 0xFFDD: // DRI (Define Restart Interval)
  32463. readUint16(); // skip data length
  32464. resetInterval = readUint16();
  32465. break;
  32466. case 0xFFDA: // SOS (Start of Scan)
  32467. var scanLength = readUint16();
  32468. var selectorsCount = data[offset++];
  32469. var components = [], component;
  32470. for (i = 0; i < selectorsCount; i++) {
  32471. var componentIndex = frame.componentIds[data[offset++]];
  32472. component = frame.components[componentIndex];
  32473. var tableSpec = data[offset++];
  32474. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32475. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32476. components.push(component);
  32477. }
  32478. var spectralStart = data[offset++];
  32479. var spectralEnd = data[offset++];
  32480. var successiveApproximation = data[offset++];
  32481. var processed = decodeScan(data, offset,
  32482. frame, components, resetInterval,
  32483. spectralStart, spectralEnd,
  32484. successiveApproximation >> 4, successiveApproximation & 15);
  32485. offset += processed;
  32486. break;
  32487. default:
  32488. if (data[offset - 3] === 0xFF &&
  32489. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32490. // could be incorrect encoding -- last 0xFF byte of the previous
  32491. // block was eaten by the encoder
  32492. offset -= 3;
  32493. break;
  32494. }
  32495. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32496. }
  32497. fileMarker = readUint16();
  32498. }
  32499. this.width = frame.samplesPerLine;
  32500. this.height = frame.scanLines;
  32501. this.jfif = jfif;
  32502. this.adobe = adobe;
  32503. this.components = [];
  32504. for (i = 0; i < frame.components.length; i++) {
  32505. component = frame.components[i];
  32506. this.components.push({
  32507. output: buildComponentData(frame, component),
  32508. scaleX: component.h / frame.maxH,
  32509. scaleY: component.v / frame.maxV,
  32510. blocksPerLine: component.blocksPerLine,
  32511. blocksPerColumn: component.blocksPerColumn
  32512. });
  32513. }
  32514. this.numComponents = this.components.length;
  32515. },
  32516. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32517. var scaleX = this.width / width, scaleY = this.height / height;
  32518. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32519. var x, y, i, j, k;
  32520. var index;
  32521. var offset = 0;
  32522. var output;
  32523. var numComponents = this.components.length;
  32524. var dataLength = width * height * numComponents;
  32525. var data = new Uint8Array(dataLength);
  32526. var xScaleBlockOffset = new Uint32Array(width);
  32527. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32528. for (i = 0; i < numComponents; i++) {
  32529. component = this.components[i];
  32530. componentScaleX = component.scaleX * scaleX;
  32531. componentScaleY = component.scaleY * scaleY;
  32532. offset = i;
  32533. output = component.output;
  32534. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32535. // precalculate the xScaleBlockOffset
  32536. for (x = 0; x < width; x++) {
  32537. j = 0 | (x * componentScaleX);
  32538. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32539. }
  32540. // linearize the blocks of the component
  32541. for (y = 0; y < height; y++) {
  32542. j = 0 | (y * componentScaleY);
  32543. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  32544. for (x = 0; x < width; x++) {
  32545. data[offset] = output[index + xScaleBlockOffset[x]];
  32546. offset += numComponents;
  32547. }
  32548. }
  32549. }
  32550. // decodeTransform will contains pairs of multiplier (-256..256) and
  32551. // additive
  32552. var transform = this.decodeTransform;
  32553. if (transform) {
  32554. for (i = 0; i < dataLength;) {
  32555. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  32556. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  32557. }
  32558. }
  32559. }
  32560. return data;
  32561. },
  32562. _isColorConversionNeeded: function isColorConversionNeeded() {
  32563. if (this.adobe && this.adobe.transformCode) {
  32564. // The adobe transform marker overrides any previous setting
  32565. return true;
  32566. } else if (this.numComponents === 3) {
  32567. return true;
  32568. } else {
  32569. return false;
  32570. }
  32571. },
  32572. _convertYccToRgb: function convertYccToRgb(data) {
  32573. var Y, Cb, Cr;
  32574. for (var i = 0, length = data.length; i < length; i += 3) {
  32575. Y = data[i ];
  32576. Cb = data[i + 1];
  32577. Cr = data[i + 2];
  32578. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  32579. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  32580. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  32581. }
  32582. return data;
  32583. },
  32584. _convertYcckToRgb: function convertYcckToRgb(data) {
  32585. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  32586. var offset = 0;
  32587. for (var i = 0, length = data.length; i < length; i += 4) {
  32588. Y = data[i];
  32589. Cb = data[i + 1];
  32590. Cr = data[i + 2];
  32591. k = data[i + 3];
  32592. CbCb = Cb * Cb;
  32593. CbCr = Cb * Cr;
  32594. CbY = Cb * Y;
  32595. Cbk = Cb * k;
  32596. CrCr = Cr * Cr;
  32597. Crk = Cr * k;
  32598. CrY = Cr * Y;
  32599. YY = Y * Y;
  32600. Yk = Y * k;
  32601. kk = k * k;
  32602. var r = - 122.67195406894 -
  32603. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  32604. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  32605. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  32606. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  32607. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  32608. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  32609. 0.000336197177618394 * kk + 0.484791561490776 * k;
  32610. var g = 107.268039397724 +
  32611. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  32612. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  32613. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  32614. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  32615. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  32616. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  32617. 0.000318913117588328 * kk - 0.213742400323665 * k;
  32618. var b = - 20.810012546947 -
  32619. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  32620. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  32621. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  32622. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  32623. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  32624. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  32625. 0.000343531996510555 * kk + 0.24165260232407 * k;
  32626. data[offset++] = clamp0to255(r);
  32627. data[offset++] = clamp0to255(g);
  32628. data[offset++] = clamp0to255(b);
  32629. }
  32630. return data;
  32631. },
  32632. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  32633. var Y, Cb, Cr;
  32634. for (var i = 0, length = data.length; i < length; i += 4) {
  32635. Y = data[i];
  32636. Cb = data[i + 1];
  32637. Cr = data[i + 2];
  32638. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  32639. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  32640. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  32641. // K in data[i + 3] is unchanged
  32642. }
  32643. return data;
  32644. },
  32645. _convertCmykToRgb: function convertCmykToRgb(data) {
  32646. var c, m, y, k;
  32647. var offset = 0;
  32648. var min = -255 * 255 * 255;
  32649. var scale = 1 / 255 / 255;
  32650. for (var i = 0, length = data.length; i < length; i += 4) {
  32651. c = data[i];
  32652. m = data[i + 1];
  32653. y = data[i + 2];
  32654. k = data[i + 3];
  32655. var r =
  32656. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32657. 18.82290502165302 * y + 212.25662451639585 * k -
  32658. 72734.4411664936) +
  32659. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  32660. 17.873870861415444 * k - 1401.7366389350734) +
  32661. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32662. 4465.541406466231) -
  32663. k * (21.86122147463605 * k + 48317.86113160301);
  32664. var g =
  32665. c * (8.841041422036149 * c + 60.118027045597366 * m +
  32666. 6.871425592049007 * y + 31.159100130055922 * k -
  32667. 20220.756542821975) +
  32668. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32669. 131.35250912493976 * k - 48691.05921601825) +
  32670. y * (4.444339102852739 * y + 9.8632861493405 * k -
  32671. 6341.191035517494) -
  32672. k * (20.737325471181034 * k + 47890.15695978492);
  32673. var b =
  32674. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32675. 30.89978309703729 * y - 0.23883238689178934 * k -
  32676. 3616.812083916688) +
  32677. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32678. 50.606957656360734 * k - 28620.90484698408) +
  32679. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  32680. 49363.43385999684) -
  32681. k * (22.33816807309886 * k + 45932.16563550634);
  32682. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  32683. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  32684. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  32685. }
  32686. return data;
  32687. },
  32688. getData: function getData(width, height, forceRGBoutput) {
  32689. if (this.numComponents > 4) {
  32690. throw 'Unsupported color mode';
  32691. }
  32692. // type of data: Uint8Array(width * height * numComponents)
  32693. var data = this._getLinearizedBlockData(width, height);
  32694. if (this.numComponents === 3) {
  32695. return this._convertYccToRgb(data);
  32696. } else if (this.numComponents === 4) {
  32697. if (this._isColorConversionNeeded()) {
  32698. if (forceRGBoutput) {
  32699. return this._convertYcckToRgb(data);
  32700. } else {
  32701. return this._convertYcckToCmyk(data);
  32702. }
  32703. } else if (forceRGBoutput) {
  32704. return this._convertCmykToRgb(data);
  32705. }
  32706. }
  32707. return data;
  32708. }
  32709. };
  32710. return constructor;
  32711. })();
  32712. var JpxImage = (function JpxImageClosure() {
  32713. // Table E.1
  32714. var SubbandsGainLog2 = {
  32715. 'LL': 0,
  32716. 'LH': 1,
  32717. 'HL': 1,
  32718. 'HH': 2
  32719. };
  32720. function JpxImage() {
  32721. this.failOnCorruptedImage = false;
  32722. }
  32723. JpxImage.prototype = {
  32724. parse: function JpxImage_parse(data) {
  32725. var head = readUint16(data, 0);
  32726. // No box header, immediate start of codestream (SOC)
  32727. if (head === 0xFF4F) {
  32728. this.parseCodestream(data, 0, data.length);
  32729. return;
  32730. }
  32731. var position = 0, length = data.length;
  32732. while (position < length) {
  32733. var headerSize = 8;
  32734. var lbox = readUint32(data, position);
  32735. var tbox = readUint32(data, position + 4);
  32736. position += headerSize;
  32737. if (lbox === 1) {
  32738. // XLBox: read UInt64 according to spec.
  32739. // JavaScript's int precision of 53 bit should be sufficient here.
  32740. lbox = readUint32(data, position) * 4294967296 +
  32741. readUint32(data, position + 4);
  32742. position += 8;
  32743. headerSize += 8;
  32744. }
  32745. if (lbox === 0) {
  32746. lbox = length - position + headerSize;
  32747. }
  32748. if (lbox < headerSize) {
  32749. throw new Error('JPX Error: Invalid box field size');
  32750. }
  32751. var dataLength = lbox - headerSize;
  32752. var jumpDataLength = true;
  32753. switch (tbox) {
  32754. case 0x6A501A1A: // 'jP\032\032'
  32755. // TODO
  32756. break;
  32757. case 0x6A703268: // 'jp2h'
  32758. jumpDataLength = false; // parsing child boxes
  32759. break;
  32760. case 0x636F6C72: // 'colr'
  32761. // TODO
  32762. break;
  32763. case 0x6A703263: // 'jp2c'
  32764. this.parseCodestream(data, position, position + dataLength);
  32765. break;
  32766. }
  32767. if (jumpDataLength) {
  32768. position += dataLength;
  32769. }
  32770. }
  32771. },
  32772. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  32773. var newByte = stream.getByte();
  32774. while (newByte >= 0) {
  32775. var oldByte = newByte;
  32776. newByte = stream.getByte();
  32777. var code = (oldByte << 8) | newByte;
  32778. // Image and tile size (SIZ)
  32779. if (code === 0xFF51) {
  32780. stream.skip(4);
  32781. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  32782. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  32783. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  32784. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  32785. stream.skip(16);
  32786. var Csiz = stream.getUint16(); // Byte 36
  32787. this.width = Xsiz - XOsiz;
  32788. this.height = Ysiz - YOsiz;
  32789. this.componentsCount = Csiz;
  32790. // Results are always returned as Uint8Arrays
  32791. this.bitsPerComponent = 8;
  32792. return;
  32793. }
  32794. }
  32795. throw new Error('JPX Error: No size marker found in JPX stream');
  32796. },
  32797. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  32798. var context = {};
  32799. try {
  32800. var doNotRecover = false;
  32801. var position = start;
  32802. while (position + 1 < end) {
  32803. var code = readUint16(data, position);
  32804. position += 2;
  32805. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  32806. switch (code) {
  32807. case 0xFF4F: // Start of codestream (SOC)
  32808. context.mainHeader = true;
  32809. break;
  32810. case 0xFFD9: // End of codestream (EOC)
  32811. break;
  32812. case 0xFF51: // Image and tile size (SIZ)
  32813. length = readUint16(data, position);
  32814. var siz = {};
  32815. siz.Xsiz = readUint32(data, position + 4);
  32816. siz.Ysiz = readUint32(data, position + 8);
  32817. siz.XOsiz = readUint32(data, position + 12);
  32818. siz.YOsiz = readUint32(data, position + 16);
  32819. siz.XTsiz = readUint32(data, position + 20);
  32820. siz.YTsiz = readUint32(data, position + 24);
  32821. siz.XTOsiz = readUint32(data, position + 28);
  32822. siz.YTOsiz = readUint32(data, position + 32);
  32823. var componentsCount = readUint16(data, position + 36);
  32824. siz.Csiz = componentsCount;
  32825. var components = [];
  32826. j = position + 38;
  32827. for (var i = 0; i < componentsCount; i++) {
  32828. var component = {
  32829. precision: (data[j] & 0x7F) + 1,
  32830. isSigned: !!(data[j] & 0x80),
  32831. XRsiz: data[j + 1],
  32832. YRsiz: data[j + 1]
  32833. };
  32834. calculateComponentDimensions(component, siz);
  32835. components.push(component);
  32836. }
  32837. context.SIZ = siz;
  32838. context.components = components;
  32839. calculateTileGrids(context, components);
  32840. context.QCC = [];
  32841. context.COC = [];
  32842. break;
  32843. case 0xFF55: // Tile-part lengths, main header (TLM)
  32844. var Ltlm = readUint16(data, position); // Marker segment length
  32845. // Skip tile length markers
  32846. position += Ltlm;
  32847. break;
  32848. case 0xFF5C: // Quantization default (QCD)
  32849. length = readUint16(data, position);
  32850. var qcd = {};
  32851. j = position + 2;
  32852. sqcd = data[j++];
  32853. switch (sqcd & 0x1F) {
  32854. case 0:
  32855. spqcdSize = 8;
  32856. scalarExpounded = true;
  32857. break;
  32858. case 1:
  32859. spqcdSize = 16;
  32860. scalarExpounded = false;
  32861. break;
  32862. case 2:
  32863. spqcdSize = 16;
  32864. scalarExpounded = true;
  32865. break;
  32866. default:
  32867. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32868. }
  32869. qcd.noQuantization = (spqcdSize === 8);
  32870. qcd.scalarExpounded = scalarExpounded;
  32871. qcd.guardBits = sqcd >> 5;
  32872. spqcds = [];
  32873. while (j < length + position) {
  32874. var spqcd = {};
  32875. if (spqcdSize === 8) {
  32876. spqcd.epsilon = data[j++] >> 3;
  32877. spqcd.mu = 0;
  32878. } else {
  32879. spqcd.epsilon = data[j] >> 3;
  32880. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32881. j += 2;
  32882. }
  32883. spqcds.push(spqcd);
  32884. }
  32885. qcd.SPqcds = spqcds;
  32886. if (context.mainHeader) {
  32887. context.QCD = qcd;
  32888. } else {
  32889. context.currentTile.QCD = qcd;
  32890. context.currentTile.QCC = [];
  32891. }
  32892. break;
  32893. case 0xFF5D: // Quantization component (QCC)
  32894. length = readUint16(data, position);
  32895. var qcc = {};
  32896. j = position + 2;
  32897. var cqcc;
  32898. if (context.SIZ.Csiz < 257) {
  32899. cqcc = data[j++];
  32900. } else {
  32901. cqcc = readUint16(data, j);
  32902. j += 2;
  32903. }
  32904. sqcd = data[j++];
  32905. switch (sqcd & 0x1F) {
  32906. case 0:
  32907. spqcdSize = 8;
  32908. scalarExpounded = true;
  32909. break;
  32910. case 1:
  32911. spqcdSize = 16;
  32912. scalarExpounded = false;
  32913. break;
  32914. case 2:
  32915. spqcdSize = 16;
  32916. scalarExpounded = true;
  32917. break;
  32918. default:
  32919. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32920. }
  32921. qcc.noQuantization = (spqcdSize === 8);
  32922. qcc.scalarExpounded = scalarExpounded;
  32923. qcc.guardBits = sqcd >> 5;
  32924. spqcds = [];
  32925. while (j < (length + position)) {
  32926. spqcd = {};
  32927. if (spqcdSize === 8) {
  32928. spqcd.epsilon = data[j++] >> 3;
  32929. spqcd.mu = 0;
  32930. } else {
  32931. spqcd.epsilon = data[j] >> 3;
  32932. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32933. j += 2;
  32934. }
  32935. spqcds.push(spqcd);
  32936. }
  32937. qcc.SPqcds = spqcds;
  32938. if (context.mainHeader) {
  32939. context.QCC[cqcc] = qcc;
  32940. } else {
  32941. context.currentTile.QCC[cqcc] = qcc;
  32942. }
  32943. break;
  32944. case 0xFF52: // Coding style default (COD)
  32945. length = readUint16(data, position);
  32946. var cod = {};
  32947. j = position + 2;
  32948. var scod = data[j++];
  32949. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  32950. cod.sopMarkerUsed = !!(scod & 2);
  32951. cod.ephMarkerUsed = !!(scod & 4);
  32952. cod.progressionOrder = data[j++];
  32953. cod.layersCount = readUint16(data, j);
  32954. j += 2;
  32955. cod.multipleComponentTransform = data[j++];
  32956. cod.decompositionLevelsCount = data[j++];
  32957. cod.xcb = (data[j++] & 0xF) + 2;
  32958. cod.ycb = (data[j++] & 0xF) + 2;
  32959. var blockStyle = data[j++];
  32960. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  32961. cod.resetContextProbabilities = !!(blockStyle & 2);
  32962. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  32963. cod.verticalyStripe = !!(blockStyle & 8);
  32964. cod.predictableTermination = !!(blockStyle & 16);
  32965. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  32966. cod.reversibleTransformation = data[j++];
  32967. if (cod.entropyCoderWithCustomPrecincts) {
  32968. var precinctsSizes = [];
  32969. while (j < length + position) {
  32970. var precinctsSize = data[j++];
  32971. precinctsSizes.push({
  32972. PPx: precinctsSize & 0xF,
  32973. PPy: precinctsSize >> 4
  32974. });
  32975. }
  32976. cod.precinctsSizes = precinctsSizes;
  32977. }
  32978. var unsupported = [];
  32979. if (cod.sopMarkerUsed) {
  32980. unsupported.push('sopMarkerUsed');
  32981. }
  32982. if (cod.ephMarkerUsed) {
  32983. unsupported.push('ephMarkerUsed');
  32984. }
  32985. if (cod.selectiveArithmeticCodingBypass) {
  32986. unsupported.push('selectiveArithmeticCodingBypass');
  32987. }
  32988. if (cod.resetContextProbabilities) {
  32989. unsupported.push('resetContextProbabilities');
  32990. }
  32991. if (cod.terminationOnEachCodingPass) {
  32992. unsupported.push('terminationOnEachCodingPass');
  32993. }
  32994. if (cod.verticalyStripe) {
  32995. unsupported.push('verticalyStripe');
  32996. }
  32997. if (cod.predictableTermination) {
  32998. unsupported.push('predictableTermination');
  32999. }
  33000. if (unsupported.length > 0) {
  33001. doNotRecover = true;
  33002. throw new Error('JPX Error: Unsupported COD options (' +
  33003. unsupported.join(', ') + ')');
  33004. }
  33005. if (context.mainHeader) {
  33006. context.COD = cod;
  33007. } else {
  33008. context.currentTile.COD = cod;
  33009. context.currentTile.COC = [];
  33010. }
  33011. break;
  33012. case 0xFF90: // Start of tile-part (SOT)
  33013. length = readUint16(data, position);
  33014. tile = {};
  33015. tile.index = readUint16(data, position + 2);
  33016. tile.length = readUint32(data, position + 4);
  33017. tile.dataEnd = tile.length + position - 2;
  33018. tile.partIndex = data[position + 8];
  33019. tile.partsCount = data[position + 9];
  33020. context.mainHeader = false;
  33021. if (tile.partIndex === 0) {
  33022. // reset component specific settings
  33023. tile.COD = context.COD;
  33024. tile.COC = context.COC.slice(0); // clone of the global COC
  33025. tile.QCD = context.QCD;
  33026. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33027. }
  33028. context.currentTile = tile;
  33029. break;
  33030. case 0xFF93: // Start of data (SOD)
  33031. tile = context.currentTile;
  33032. if (tile.partIndex === 0) {
  33033. initializeTile(context, tile.index);
  33034. buildPackets(context);
  33035. }
  33036. // moving to the end of the data
  33037. length = tile.dataEnd - position;
  33038. parseTilePackets(context, data, position, length);
  33039. break;
  33040. case 0xFF64: // Comment (COM)
  33041. length = readUint16(data, position);
  33042. // skipping content
  33043. break;
  33044. case 0xFF53: // Coding style component (COC)
  33045. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33046. 'not implemented');
  33047. default:
  33048. throw new Error('JPX Error: Unknown codestream code: ' +
  33049. code.toString(16));
  33050. }
  33051. position += length;
  33052. }
  33053. } catch (e) {
  33054. if (doNotRecover || this.failOnCorruptedImage) {
  33055. throw e;
  33056. } else {
  33057. warn('Trying to recover from ' + e.message);
  33058. }
  33059. }
  33060. this.tiles = transformComponents(context);
  33061. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33062. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33063. this.componentsCount = context.SIZ.Csiz;
  33064. }
  33065. };
  33066. function calculateComponentDimensions(component, siz) {
  33067. // Section B.2 Component mapping
  33068. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33069. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33070. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33071. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33072. component.width = component.x1 - component.x0;
  33073. component.height = component.y1 - component.y0;
  33074. }
  33075. function calculateTileGrids(context, components) {
  33076. var siz = context.SIZ;
  33077. // Section B.3 Division into tile and tile-components
  33078. var tile, tiles = [];
  33079. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33080. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33081. for (var q = 0; q < numYtiles; q++) {
  33082. for (var p = 0; p < numXtiles; p++) {
  33083. tile = {};
  33084. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33085. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33086. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33087. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33088. tile.width = tile.tx1 - tile.tx0;
  33089. tile.height = tile.ty1 - tile.ty0;
  33090. tile.components = [];
  33091. tiles.push(tile);
  33092. }
  33093. }
  33094. context.tiles = tiles;
  33095. var componentsCount = siz.Csiz;
  33096. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33097. var component = components[i];
  33098. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33099. var tileComponent = {};
  33100. tile = tiles[j];
  33101. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33102. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33103. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33104. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33105. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33106. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33107. tile.components[i] = tileComponent;
  33108. }
  33109. }
  33110. }
  33111. function getBlocksDimensions(context, component, r) {
  33112. var codOrCoc = component.codingStyleParameters;
  33113. var result = {};
  33114. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33115. result.PPx = 15;
  33116. result.PPy = 15;
  33117. } else {
  33118. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33119. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33120. }
  33121. // calculate codeblock size as described in section B.7
  33122. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33123. Math.min(codOrCoc.xcb, result.PPx));
  33124. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33125. Math.min(codOrCoc.ycb, result.PPy));
  33126. return result;
  33127. }
  33128. function buildPrecincts(context, resolution, dimensions) {
  33129. // Section B.6 Division resolution to precincts
  33130. var precinctWidth = 1 << dimensions.PPx;
  33131. var precinctHeight = 1 << dimensions.PPy;
  33132. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33133. Math.ceil(resolution.trx1 / precinctWidth) -
  33134. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33135. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33136. Math.ceil(resolution.try1 / precinctHeight) -
  33137. Math.floor(resolution.try0 / precinctHeight) : 0);
  33138. var numprecincts = numprecinctswide * numprecinctshigh;
  33139. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  33140. precinctWidth;
  33141. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  33142. precinctHeight;
  33143. resolution.precinctParameters = {
  33144. precinctXOffset: precinctXOffset,
  33145. precinctYOffset: precinctYOffset,
  33146. precinctWidth: precinctWidth,
  33147. precinctHeight: precinctHeight,
  33148. numprecinctswide: numprecinctswide,
  33149. numprecinctshigh: numprecinctshigh,
  33150. numprecincts: numprecincts
  33151. };
  33152. }
  33153. function buildCodeblocks(context, subband, dimensions) {
  33154. // Section B.7 Division sub-band into code-blocks
  33155. var xcb_ = dimensions.xcb_;
  33156. var ycb_ = dimensions.ycb_;
  33157. var codeblockWidth = 1 << xcb_;
  33158. var codeblockHeight = 1 << ycb_;
  33159. var cbx0 = subband.tbx0 >> xcb_;
  33160. var cby0 = subband.tby0 >> ycb_;
  33161. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33162. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33163. var precinctParameters = subband.resolution.precinctParameters;
  33164. var codeblocks = [];
  33165. var precincts = [];
  33166. var i, j, codeblock, precinctNumber;
  33167. for (j = cby0; j < cby1; j++) {
  33168. for (i = cbx0; i < cbx1; i++) {
  33169. codeblock = {
  33170. cbx: i,
  33171. cby: j,
  33172. tbx0: codeblockWidth * i,
  33173. tby0: codeblockHeight * j,
  33174. tbx1: codeblockWidth * (i + 1),
  33175. tby1: codeblockHeight * (j + 1)
  33176. };
  33177. // calculate precinct number
  33178. var pi = Math.floor((codeblock.tbx0 -
  33179. precinctParameters.precinctXOffset) /
  33180. precinctParameters.precinctWidth);
  33181. var pj = Math.floor((codeblock.tby0 -
  33182. precinctParameters.precinctYOffset) /
  33183. precinctParameters.precinctHeight);
  33184. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  33185. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33186. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33187. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33188. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33189. codeblock.precinctNumber = precinctNumber;
  33190. codeblock.subbandType = subband.type;
  33191. codeblock.Lblock = 3;
  33192. codeblocks.push(codeblock);
  33193. // building precinct for the sub-band
  33194. var precinct = precincts[precinctNumber];
  33195. if (precinct !== undefined) {
  33196. if (i < precinct.cbxMin) {
  33197. precinct.cbxMin = i;
  33198. } else if (i > precinct.cbxMax) {
  33199. precinct.cbxMax = i;
  33200. }
  33201. if (j < precinct.cbyMin) {
  33202. precinct.cbxMin = j;
  33203. } else if (j > precinct.cbyMax) {
  33204. precinct.cbyMax = j;
  33205. }
  33206. } else {
  33207. precincts[precinctNumber] = precinct = {
  33208. cbxMin: i,
  33209. cbyMin: j,
  33210. cbxMax: i,
  33211. cbyMax: j
  33212. };
  33213. }
  33214. codeblock.precinct = precinct;
  33215. }
  33216. }
  33217. subband.codeblockParameters = {
  33218. codeblockWidth: xcb_,
  33219. codeblockHeight: ycb_,
  33220. numcodeblockwide: cbx1 - cbx0 + 1,
  33221. numcodeblockhigh: cby1 - cby0 + 1
  33222. };
  33223. subband.codeblocks = codeblocks;
  33224. subband.precincts = precincts;
  33225. }
  33226. function createPacket(resolution, precinctNumber, layerNumber) {
  33227. var precinctCodeblocks = [];
  33228. // Section B.10.8 Order of info in packet
  33229. var subbands = resolution.subbands;
  33230. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33231. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33232. var subband = subbands[i];
  33233. var codeblocks = subband.codeblocks;
  33234. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33235. var codeblock = codeblocks[j];
  33236. if (codeblock.precinctNumber !== precinctNumber) {
  33237. continue;
  33238. }
  33239. precinctCodeblocks.push(codeblock);
  33240. }
  33241. }
  33242. return {
  33243. layerNumber: layerNumber,
  33244. codeblocks: precinctCodeblocks
  33245. };
  33246. }
  33247. function LayerResolutionComponentPositionIterator(context) {
  33248. var siz = context.SIZ;
  33249. var tileIndex = context.currentTile.index;
  33250. var tile = context.tiles[tileIndex];
  33251. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33252. var componentsCount = siz.Csiz;
  33253. var maxDecompositionLevelsCount = 0;
  33254. for (var q = 0; q < componentsCount; q++) {
  33255. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33256. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33257. }
  33258. var l = 0, r = 0, i = 0, k = 0;
  33259. this.nextPacket = function JpxImage_nextPacket() {
  33260. // Section B.12.1.1 Layer-resolution-component-position
  33261. for (; l < layersCount; l++) {
  33262. for (; r <= maxDecompositionLevelsCount; r++) {
  33263. for (; i < componentsCount; i++) {
  33264. var component = tile.components[i];
  33265. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33266. continue;
  33267. }
  33268. var resolution = component.resolutions[r];
  33269. var numprecincts = resolution.precinctParameters.numprecincts;
  33270. for (; k < numprecincts;) {
  33271. var packet = createPacket(resolution, k, l);
  33272. k++;
  33273. return packet;
  33274. }
  33275. k = 0;
  33276. }
  33277. i = 0;
  33278. }
  33279. r = 0;
  33280. }
  33281. throw new Error('JPX Error: Out of packets');
  33282. };
  33283. }
  33284. function ResolutionLayerComponentPositionIterator(context) {
  33285. var siz = context.SIZ;
  33286. var tileIndex = context.currentTile.index;
  33287. var tile = context.tiles[tileIndex];
  33288. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33289. var componentsCount = siz.Csiz;
  33290. var maxDecompositionLevelsCount = 0;
  33291. for (var q = 0; q < componentsCount; q++) {
  33292. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33293. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33294. }
  33295. var r = 0, l = 0, i = 0, k = 0;
  33296. this.nextPacket = function JpxImage_nextPacket() {
  33297. // Section B.12.1.2 Resolution-layer-component-position
  33298. for (; r <= maxDecompositionLevelsCount; r++) {
  33299. for (; l < layersCount; l++) {
  33300. for (; i < componentsCount; i++) {
  33301. var component = tile.components[i];
  33302. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33303. continue;
  33304. }
  33305. var resolution = component.resolutions[r];
  33306. var numprecincts = resolution.precinctParameters.numprecincts;
  33307. for (; k < numprecincts;) {
  33308. var packet = createPacket(resolution, k, l);
  33309. k++;
  33310. return packet;
  33311. }
  33312. k = 0;
  33313. }
  33314. i = 0;
  33315. }
  33316. l = 0;
  33317. }
  33318. throw new Error('JPX Error: Out of packets');
  33319. };
  33320. }
  33321. function buildPackets(context) {
  33322. var siz = context.SIZ;
  33323. var tileIndex = context.currentTile.index;
  33324. var tile = context.tiles[tileIndex];
  33325. var componentsCount = siz.Csiz;
  33326. // Creating resolutions and sub-bands for each component
  33327. for (var c = 0; c < componentsCount; c++) {
  33328. var component = tile.components[c];
  33329. var decompositionLevelsCount =
  33330. component.codingStyleParameters.decompositionLevelsCount;
  33331. // Section B.5 Resolution levels and sub-bands
  33332. var resolutions = [];
  33333. var subbands = [];
  33334. for (var r = 0; r <= decompositionLevelsCount; r++) {
  33335. var blocksDimensions = getBlocksDimensions(context, component, r);
  33336. var resolution = {};
  33337. var scale = 1 << (decompositionLevelsCount - r);
  33338. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  33339. resolution.try0 = Math.ceil(component.tcy0 / scale);
  33340. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  33341. resolution.try1 = Math.ceil(component.tcy1 / scale);
  33342. buildPrecincts(context, resolution, blocksDimensions);
  33343. resolutions.push(resolution);
  33344. var subband;
  33345. if (r === 0) {
  33346. // one sub-band (LL) with last decomposition
  33347. subband = {};
  33348. subband.type = 'LL';
  33349. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  33350. subband.tby0 = Math.ceil(component.tcy0 / scale);
  33351. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  33352. subband.tby1 = Math.ceil(component.tcy1 / scale);
  33353. subband.resolution = resolution;
  33354. buildCodeblocks(context, subband, blocksDimensions);
  33355. subbands.push(subband);
  33356. resolution.subbands = [subband];
  33357. } else {
  33358. var bscale = 1 << (decompositionLevelsCount - r + 1);
  33359. var resolutionSubbands = [];
  33360. // three sub-bands (HL, LH and HH) with rest of decompositions
  33361. subband = {};
  33362. subband.type = 'HL';
  33363. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33364. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  33365. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33366. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  33367. subband.resolution = resolution;
  33368. buildCodeblocks(context, subband, blocksDimensions);
  33369. subbands.push(subband);
  33370. resolutionSubbands.push(subband);
  33371. subband = {};
  33372. subband.type = 'LH';
  33373. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  33374. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33375. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  33376. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33377. subband.resolution = resolution;
  33378. buildCodeblocks(context, subband, blocksDimensions);
  33379. subbands.push(subband);
  33380. resolutionSubbands.push(subband);
  33381. subband = {};
  33382. subband.type = 'HH';
  33383. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33384. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33385. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33386. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33387. subband.resolution = resolution;
  33388. buildCodeblocks(context, subband, blocksDimensions);
  33389. subbands.push(subband);
  33390. resolutionSubbands.push(subband);
  33391. resolution.subbands = resolutionSubbands;
  33392. }
  33393. }
  33394. component.resolutions = resolutions;
  33395. component.subbands = subbands;
  33396. }
  33397. // Generate the packets sequence
  33398. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  33399. switch (progressionOrder) {
  33400. case 0:
  33401. tile.packetsIterator =
  33402. new LayerResolutionComponentPositionIterator(context);
  33403. break;
  33404. case 1:
  33405. tile.packetsIterator =
  33406. new ResolutionLayerComponentPositionIterator(context);
  33407. break;
  33408. default:
  33409. throw new Error('JPX Error: Unsupported progression order ' +
  33410. progressionOrder);
  33411. }
  33412. }
  33413. function parseTilePackets(context, data, offset, dataLength) {
  33414. var position = 0;
  33415. var buffer, bufferSize = 0, skipNextBit = false;
  33416. function readBits(count) {
  33417. while (bufferSize < count) {
  33418. var b = data[offset + position];
  33419. position++;
  33420. if (skipNextBit) {
  33421. buffer = (buffer << 7) | b;
  33422. bufferSize += 7;
  33423. skipNextBit = false;
  33424. } else {
  33425. buffer = (buffer << 8) | b;
  33426. bufferSize += 8;
  33427. }
  33428. if (b === 0xFF) {
  33429. skipNextBit = true;
  33430. }
  33431. }
  33432. bufferSize -= count;
  33433. return (buffer >>> bufferSize) & ((1 << count) - 1);
  33434. }
  33435. function alignToByte() {
  33436. bufferSize = 0;
  33437. if (skipNextBit) {
  33438. position++;
  33439. skipNextBit = false;
  33440. }
  33441. }
  33442. function readCodingpasses() {
  33443. if (readBits(1) === 0) {
  33444. return 1;
  33445. }
  33446. if (readBits(1) === 0) {
  33447. return 2;
  33448. }
  33449. var value = readBits(2);
  33450. if (value < 3) {
  33451. return value + 3;
  33452. }
  33453. value = readBits(5);
  33454. if (value < 31) {
  33455. return value + 6;
  33456. }
  33457. value = readBits(7);
  33458. return value + 37;
  33459. }
  33460. var tileIndex = context.currentTile.index;
  33461. var tile = context.tiles[tileIndex];
  33462. var packetsIterator = tile.packetsIterator;
  33463. while (position < dataLength) {
  33464. var packet = packetsIterator.nextPacket();
  33465. if (!readBits(1)) {
  33466. alignToByte();
  33467. continue;
  33468. }
  33469. var layerNumber = packet.layerNumber;
  33470. var queue = [], codeblock;
  33471. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  33472. codeblock = packet.codeblocks[i];
  33473. var precinct = codeblock.precinct;
  33474. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  33475. var codeblockRow = codeblock.cby - precinct.cbyMin;
  33476. var codeblockIncluded = false;
  33477. var firstTimeInclusion = false;
  33478. var valueReady;
  33479. if ('included' in codeblock) {
  33480. codeblockIncluded = !!readBits(1);
  33481. } else {
  33482. // reading inclusion tree
  33483. precinct = codeblock.precinct;
  33484. var inclusionTree, zeroBitPlanesTree;
  33485. if ('inclusionTree' in precinct) {
  33486. inclusionTree = precinct.inclusionTree;
  33487. } else {
  33488. // building inclusion and zero bit-planes trees
  33489. var width = precinct.cbxMax - precinct.cbxMin + 1;
  33490. var height = precinct.cbyMax - precinct.cbyMin + 1;
  33491. inclusionTree = new InclusionTree(width, height, layerNumber);
  33492. zeroBitPlanesTree = new TagTree(width, height);
  33493. precinct.inclusionTree = inclusionTree;
  33494. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  33495. }
  33496. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  33497. while (true) {
  33498. if (readBits(1)) {
  33499. valueReady = !inclusionTree.nextLevel();
  33500. if (valueReady) {
  33501. codeblock.included = true;
  33502. codeblockIncluded = firstTimeInclusion = true;
  33503. break;
  33504. }
  33505. } else {
  33506. inclusionTree.incrementValue(layerNumber);
  33507. break;
  33508. }
  33509. }
  33510. }
  33511. }
  33512. if (!codeblockIncluded) {
  33513. continue;
  33514. }
  33515. if (firstTimeInclusion) {
  33516. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  33517. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  33518. while (true) {
  33519. if (readBits(1)) {
  33520. valueReady = !zeroBitPlanesTree.nextLevel();
  33521. if (valueReady) {
  33522. break;
  33523. }
  33524. } else {
  33525. zeroBitPlanesTree.incrementValue();
  33526. }
  33527. }
  33528. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  33529. }
  33530. var codingpasses = readCodingpasses();
  33531. while (readBits(1)) {
  33532. codeblock.Lblock++;
  33533. }
  33534. var codingpassesLog2 = log2(codingpasses);
  33535. // rounding down log2
  33536. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  33537. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  33538. var codedDataLength = readBits(bits);
  33539. queue.push({
  33540. codeblock: codeblock,
  33541. codingpasses: codingpasses,
  33542. dataLength: codedDataLength
  33543. });
  33544. }
  33545. alignToByte();
  33546. while (queue.length > 0) {
  33547. var packetItem = queue.shift();
  33548. codeblock = packetItem.codeblock;
  33549. if (!('data' in codeblock)) {
  33550. codeblock.data = [];
  33551. }
  33552. codeblock.data.push({
  33553. data: data,
  33554. start: offset + position,
  33555. end: offset + position + packetItem.dataLength,
  33556. codingpasses: packetItem.codingpasses
  33557. });
  33558. position += packetItem.dataLength;
  33559. }
  33560. }
  33561. return position;
  33562. }
  33563. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  33564. delta, mb, reversible, segmentationSymbolUsed) {
  33565. var x0 = subband.tbx0;
  33566. var y0 = subband.tby0;
  33567. var width = subband.tbx1 - subband.tbx0;
  33568. var codeblocks = subband.codeblocks;
  33569. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  33570. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  33571. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  33572. var codeblock = codeblocks[i];
  33573. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  33574. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  33575. if (blockWidth === 0 || blockHeight === 0) {
  33576. continue;
  33577. }
  33578. if (!('data' in codeblock)) {
  33579. continue;
  33580. }
  33581. var bitModel, currentCodingpassType;
  33582. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  33583. codeblock.zeroBitPlanes, mb);
  33584. currentCodingpassType = 2; // first bit plane starts from cleanup
  33585. // collect data
  33586. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  33587. var j, jj, dataItem;
  33588. for (j = 0, jj = data.length; j < jj; j++) {
  33589. dataItem = data[j];
  33590. totalLength += dataItem.end - dataItem.start;
  33591. codingpasses += dataItem.codingpasses;
  33592. }
  33593. var encodedData = new Uint8Array(totalLength);
  33594. var position = 0;
  33595. for (j = 0, jj = data.length; j < jj; j++) {
  33596. dataItem = data[j];
  33597. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  33598. encodedData.set(chunk, position);
  33599. position += chunk.length;
  33600. }
  33601. // decoding the item
  33602. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  33603. bitModel.setDecoder(decoder);
  33604. for (j = 0; j < codingpasses; j++) {
  33605. switch (currentCodingpassType) {
  33606. case 0:
  33607. bitModel.runSignificancePropogationPass();
  33608. break;
  33609. case 1:
  33610. bitModel.runMagnitudeRefinementPass();
  33611. break;
  33612. case 2:
  33613. bitModel.runCleanupPass();
  33614. if (segmentationSymbolUsed) {
  33615. bitModel.checkSegmentationSymbol();
  33616. }
  33617. break;
  33618. }
  33619. currentCodingpassType = (currentCodingpassType + 1) % 3;
  33620. }
  33621. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  33622. var sign = bitModel.coefficentsSign;
  33623. var magnitude = bitModel.coefficentsMagnitude;
  33624. var bitsDecoded = bitModel.bitsDecoded;
  33625. var magnitudeCorrection = reversible ? 0 : 0.5;
  33626. var k, n, nb;
  33627. position = 0;
  33628. // Do the interleaving of Section F.3.3 here, so we do not need
  33629. // to copy later. LL level is not interleaved, just copied.
  33630. var interleave = (subband.type !== 'LL');
  33631. for (j = 0; j < blockHeight; j++) {
  33632. var row = (offset / width) | 0; // row in the non-interleaved subband
  33633. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  33634. for (k = 0; k < blockWidth; k++) {
  33635. n = magnitude[position];
  33636. if (n !== 0) {
  33637. n = (n + magnitudeCorrection) * delta;
  33638. if (sign[position] !== 0) {
  33639. n = -n;
  33640. }
  33641. nb = bitsDecoded[position];
  33642. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  33643. if (reversible && (nb >= mb)) {
  33644. coefficients[pos] = n;
  33645. } else {
  33646. coefficients[pos] = n * (1 << (mb - nb));
  33647. }
  33648. }
  33649. offset++;
  33650. position++;
  33651. }
  33652. offset += width - blockWidth;
  33653. }
  33654. }
  33655. }
  33656. function transformTile(context, tile, c) {
  33657. var component = tile.components[c];
  33658. var codingStyleParameters = component.codingStyleParameters;
  33659. var quantizationParameters = component.quantizationParameters;
  33660. var decompositionLevelsCount =
  33661. codingStyleParameters.decompositionLevelsCount;
  33662. var spqcds = quantizationParameters.SPqcds;
  33663. var scalarExpounded = quantizationParameters.scalarExpounded;
  33664. var guardBits = quantizationParameters.guardBits;
  33665. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  33666. var precision = context.components[c].precision;
  33667. var reversible = codingStyleParameters.reversibleTransformation;
  33668. var transform = (reversible ? new ReversibleTransform() :
  33669. new IrreversibleTransform());
  33670. var subbandCoefficients = [];
  33671. var b = 0;
  33672. for (var i = 0; i <= decompositionLevelsCount; i++) {
  33673. var resolution = component.resolutions[i];
  33674. var width = resolution.trx1 - resolution.trx0;
  33675. var height = resolution.try1 - resolution.try0;
  33676. // Allocate space for the whole sublevel.
  33677. var coefficients = new Float32Array(width * height);
  33678. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  33679. var mu, epsilon;
  33680. if (!scalarExpounded) {
  33681. // formula E-5
  33682. mu = spqcds[0].mu;
  33683. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  33684. } else {
  33685. mu = spqcds[b].mu;
  33686. epsilon = spqcds[b].epsilon;
  33687. b++;
  33688. }
  33689. var subband = resolution.subbands[j];
  33690. var gainLog2 = SubbandsGainLog2[subband.type];
  33691. // calulate quantization coefficient (Section E.1.1.1)
  33692. var delta = (reversible ? 1 :
  33693. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  33694. var mb = (guardBits + epsilon - 1);
  33695. // In the first resolution level, copyCoefficients will fill the
  33696. // whole array with coefficients. In the succeding passes,
  33697. // copyCoefficients will consecutively fill in the values that belong
  33698. // to the interleaved positions of the HL, LH, and HH coefficients.
  33699. // The LL coefficients will then be interleaved in Transform.iterate().
  33700. copyCoefficients(coefficients, width, height, subband, delta, mb,
  33701. reversible, segmentationSymbolUsed);
  33702. }
  33703. subbandCoefficients.push({
  33704. width: width,
  33705. height: height,
  33706. items: coefficients
  33707. });
  33708. }
  33709. var result = transform.calculate(subbandCoefficients,
  33710. component.tcx0, component.tcy0);
  33711. return {
  33712. left: component.tcx0,
  33713. top: component.tcy0,
  33714. width: result.width,
  33715. height: result.height,
  33716. items: result.items
  33717. };
  33718. }
  33719. function transformComponents(context) {
  33720. var siz = context.SIZ;
  33721. var components = context.components;
  33722. var componentsCount = siz.Csiz;
  33723. var resultImages = [];
  33724. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  33725. var tile = context.tiles[i];
  33726. var transformedTiles = [];
  33727. var c;
  33728. for (c = 0; c < componentsCount; c++) {
  33729. transformedTiles[c] = transformTile(context, tile, c);
  33730. }
  33731. var tile0 = transformedTiles[0];
  33732. var out = new Uint8Array(tile0.items.length * componentsCount);
  33733. var result = {
  33734. left: tile0.left,
  33735. top: tile0.top,
  33736. width: tile0.width,
  33737. height: tile0.height,
  33738. items: out
  33739. };
  33740. // Section G.2.2 Inverse multi component transform
  33741. var shift, offset, max, min, maxK;
  33742. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  33743. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  33744. var fourComponents = componentsCount === 4;
  33745. var y0items = transformedTiles[0].items;
  33746. var y1items = transformedTiles[1].items;
  33747. var y2items = transformedTiles[2].items;
  33748. var y3items = fourComponents ? transformedTiles[3].items : null;
  33749. // HACK: The multiple component transform formulas below assume that
  33750. // all components have the same precision. With this in mind, we
  33751. // compute shift and offset only once.
  33752. shift = components[0].precision - 8;
  33753. offset = (128 << shift) + 0.5;
  33754. max = 255 * (1 << shift);
  33755. maxK = max * 0.5;
  33756. min = -maxK;
  33757. var component0 = tile.components[0];
  33758. var alpha01 = componentsCount - 3;
  33759. jj = y0items.length;
  33760. if (!component0.codingStyleParameters.reversibleTransformation) {
  33761. // inverse irreversible multiple component transform
  33762. for (j = 0; j < jj; j++, pos += alpha01) {
  33763. y0 = y0items[j] + offset;
  33764. y1 = y1items[j];
  33765. y2 = y2items[j];
  33766. r = y0 + 1.402 * y2;
  33767. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  33768. b = y0 + 1.772 * y1;
  33769. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33770. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33771. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33772. }
  33773. } else {
  33774. // inverse reversible multiple component transform
  33775. for (j = 0; j < jj; j++, pos += alpha01) {
  33776. y0 = y0items[j] + offset;
  33777. y1 = y1items[j];
  33778. y2 = y2items[j];
  33779. g = y0 - ((y2 + y1) >> 2);
  33780. r = g + y2;
  33781. b = g + y1;
  33782. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33783. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33784. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33785. }
  33786. }
  33787. if (fourComponents) {
  33788. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  33789. k = y3items[j];
  33790. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  33791. }
  33792. }
  33793. } else { // no multi-component transform
  33794. for (c = 0; c < componentsCount; c++) {
  33795. var items = transformedTiles[c].items;
  33796. shift = components[c].precision - 8;
  33797. offset = (128 << shift) + 0.5;
  33798. max = (127.5 * (1 << shift));
  33799. min = -max;
  33800. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  33801. val = items[j];
  33802. out[pos] = val <= min ? 0 :
  33803. val >= max ? 255 : (val + offset) >> shift;
  33804. pos += componentsCount;
  33805. }
  33806. }
  33807. }
  33808. resultImages.push(result);
  33809. }
  33810. return resultImages;
  33811. }
  33812. function initializeTile(context, tileIndex) {
  33813. var siz = context.SIZ;
  33814. var componentsCount = siz.Csiz;
  33815. var tile = context.tiles[tileIndex];
  33816. for (var c = 0; c < componentsCount; c++) {
  33817. var component = tile.components[c];
  33818. var qcdOrQcc = (c in context.currentTile.QCC ?
  33819. context.currentTile.QCC[c] : context.currentTile.QCD);
  33820. component.quantizationParameters = qcdOrQcc;
  33821. var codOrCoc = (c in context.currentTile.COC ?
  33822. context.currentTile.COC[c] : context.currentTile.COD);
  33823. component.codingStyleParameters = codOrCoc;
  33824. }
  33825. tile.codingStyleDefaultParameters = context.currentTile.COD;
  33826. }
  33827. // Section B.10.2 Tag trees
  33828. var TagTree = (function TagTreeClosure() {
  33829. function TagTree(width, height) {
  33830. var levelsLength = log2(Math.max(width, height)) + 1;
  33831. this.levels = [];
  33832. for (var i = 0; i < levelsLength; i++) {
  33833. var level = {
  33834. width: width,
  33835. height: height,
  33836. items: []
  33837. };
  33838. this.levels.push(level);
  33839. width = Math.ceil(width / 2);
  33840. height = Math.ceil(height / 2);
  33841. }
  33842. }
  33843. TagTree.prototype = {
  33844. reset: function TagTree_reset(i, j) {
  33845. var currentLevel = 0, value = 0, level;
  33846. while (currentLevel < this.levels.length) {
  33847. level = this.levels[currentLevel];
  33848. var index = i + j * level.width;
  33849. if (index in level.items) {
  33850. value = level.items[index];
  33851. break;
  33852. }
  33853. level.index = index;
  33854. i >>= 1;
  33855. j >>= 1;
  33856. currentLevel++;
  33857. }
  33858. currentLevel--;
  33859. level = this.levels[currentLevel];
  33860. level.items[level.index] = value;
  33861. this.currentLevel = currentLevel;
  33862. delete this.value;
  33863. },
  33864. incrementValue: function TagTree_incrementValue() {
  33865. var level = this.levels[this.currentLevel];
  33866. level.items[level.index]++;
  33867. },
  33868. nextLevel: function TagTree_nextLevel() {
  33869. var currentLevel = this.currentLevel;
  33870. var level = this.levels[currentLevel];
  33871. var value = level.items[level.index];
  33872. currentLevel--;
  33873. if (currentLevel < 0) {
  33874. this.value = value;
  33875. return false;
  33876. }
  33877. this.currentLevel = currentLevel;
  33878. level = this.levels[currentLevel];
  33879. level.items[level.index] = value;
  33880. return true;
  33881. }
  33882. };
  33883. return TagTree;
  33884. })();
  33885. var InclusionTree = (function InclusionTreeClosure() {
  33886. function InclusionTree(width, height, defaultValue) {
  33887. var levelsLength = log2(Math.max(width, height)) + 1;
  33888. this.levels = [];
  33889. for (var i = 0; i < levelsLength; i++) {
  33890. var items = new Uint8Array(width * height);
  33891. for (var j = 0, jj = items.length; j < jj; j++) {
  33892. items[j] = defaultValue;
  33893. }
  33894. var level = {
  33895. width: width,
  33896. height: height,
  33897. items: items
  33898. };
  33899. this.levels.push(level);
  33900. width = Math.ceil(width / 2);
  33901. height = Math.ceil(height / 2);
  33902. }
  33903. }
  33904. InclusionTree.prototype = {
  33905. reset: function InclusionTree_reset(i, j, stopValue) {
  33906. var currentLevel = 0;
  33907. while (currentLevel < this.levels.length) {
  33908. var level = this.levels[currentLevel];
  33909. var index = i + j * level.width;
  33910. level.index = index;
  33911. var value = level.items[index];
  33912. if (value === 0xFF) {
  33913. break;
  33914. }
  33915. if (value > stopValue) {
  33916. this.currentLevel = currentLevel;
  33917. // already know about this one, propagating the value to top levels
  33918. this.propagateValues();
  33919. return false;
  33920. }
  33921. i >>= 1;
  33922. j >>= 1;
  33923. currentLevel++;
  33924. }
  33925. this.currentLevel = currentLevel - 1;
  33926. return true;
  33927. },
  33928. incrementValue: function InclusionTree_incrementValue(stopValue) {
  33929. var level = this.levels[this.currentLevel];
  33930. level.items[level.index] = stopValue + 1;
  33931. this.propagateValues();
  33932. },
  33933. propagateValues: function InclusionTree_propagateValues() {
  33934. var levelIndex = this.currentLevel;
  33935. var level = this.levels[levelIndex];
  33936. var currentValue = level.items[level.index];
  33937. while (--levelIndex >= 0) {
  33938. level = this.levels[levelIndex];
  33939. level.items[level.index] = currentValue;
  33940. }
  33941. },
  33942. nextLevel: function InclusionTree_nextLevel() {
  33943. var currentLevel = this.currentLevel;
  33944. var level = this.levels[currentLevel];
  33945. var value = level.items[level.index];
  33946. level.items[level.index] = 0xFF;
  33947. currentLevel--;
  33948. if (currentLevel < 0) {
  33949. return false;
  33950. }
  33951. this.currentLevel = currentLevel;
  33952. level = this.levels[currentLevel];
  33953. level.items[level.index] = value;
  33954. return true;
  33955. }
  33956. };
  33957. return InclusionTree;
  33958. })();
  33959. // Section D. Coefficient bit modeling
  33960. var BitModel = (function BitModelClosure() {
  33961. var UNIFORM_CONTEXT = 17;
  33962. var RUNLENGTH_CONTEXT = 18;
  33963. // Table D-1
  33964. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  33965. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  33966. var LLAndLHContextsLabel = new Uint8Array([
  33967. 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,
  33968. 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,
  33969. 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
  33970. ]);
  33971. var HLContextLabel = new Uint8Array([
  33972. 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,
  33973. 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,
  33974. 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
  33975. ]);
  33976. var HHContextLabel = new Uint8Array([
  33977. 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,
  33978. 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,
  33979. 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
  33980. ]);
  33981. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  33982. this.width = width;
  33983. this.height = height;
  33984. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  33985. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  33986. var coefficientCount = width * height;
  33987. // coefficients outside the encoding region treated as insignificant
  33988. // add border state cells for significanceState
  33989. this.neighborsSignificance = new Uint8Array(coefficientCount);
  33990. this.coefficentsSign = new Uint8Array(coefficientCount);
  33991. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  33992. mb > 6 ? new Uint16Array(coefficientCount) :
  33993. new Uint8Array(coefficientCount);
  33994. this.processingFlags = new Uint8Array(coefficientCount);
  33995. var bitsDecoded = new Uint8Array(coefficientCount);
  33996. if (zeroBitPlanes !== 0) {
  33997. for (var i = 0; i < coefficientCount; i++) {
  33998. bitsDecoded[i] = zeroBitPlanes;
  33999. }
  34000. }
  34001. this.bitsDecoded = bitsDecoded;
  34002. this.reset();
  34003. }
  34004. BitModel.prototype = {
  34005. setDecoder: function BitModel_setDecoder(decoder) {
  34006. this.decoder = decoder;
  34007. },
  34008. reset: function BitModel_reset() {
  34009. // We have 17 contexts that are accessed via context labels,
  34010. // plus the uniform and runlength context.
  34011. this.contexts = new Int8Array(19);
  34012. // Contexts are packed into 1 byte:
  34013. // highest 7 bits carry the index, lowest bit carries mps
  34014. this.contexts[0] = (4 << 1) | 0;
  34015. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34016. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34017. },
  34018. setNeighborsSignificance:
  34019. function BitModel_setNeighborsSignificance(row, column, index) {
  34020. var neighborsSignificance = this.neighborsSignificance;
  34021. var width = this.width, height = this.height;
  34022. var left = (column > 0);
  34023. var right = (column + 1 < width);
  34024. var i;
  34025. if (row > 0) {
  34026. i = index - width;
  34027. if (left) {
  34028. neighborsSignificance[i - 1] += 0x10;
  34029. }
  34030. if (right) {
  34031. neighborsSignificance[i + 1] += 0x10;
  34032. }
  34033. neighborsSignificance[i] += 0x04;
  34034. }
  34035. if (row + 1 < height) {
  34036. i = index + width;
  34037. if (left) {
  34038. neighborsSignificance[i - 1] += 0x10;
  34039. }
  34040. if (right) {
  34041. neighborsSignificance[i + 1] += 0x10;
  34042. }
  34043. neighborsSignificance[i] += 0x04;
  34044. }
  34045. if (left) {
  34046. neighborsSignificance[index - 1] += 0x01;
  34047. }
  34048. if (right) {
  34049. neighborsSignificance[index + 1] += 0x01;
  34050. }
  34051. neighborsSignificance[index] |= 0x80;
  34052. },
  34053. runSignificancePropogationPass:
  34054. function BitModel_runSignificancePropogationPass() {
  34055. var decoder = this.decoder;
  34056. var width = this.width, height = this.height;
  34057. var coefficentsMagnitude = this.coefficentsMagnitude;
  34058. var coefficentsSign = this.coefficentsSign;
  34059. var neighborsSignificance = this.neighborsSignificance;
  34060. var processingFlags = this.processingFlags;
  34061. var contexts = this.contexts;
  34062. var labels = this.contextLabelTable;
  34063. var bitsDecoded = this.bitsDecoded;
  34064. var processedInverseMask = ~1;
  34065. var processedMask = 1;
  34066. var firstMagnitudeBitMask = 2;
  34067. for (var i0 = 0; i0 < height; i0 += 4) {
  34068. for (var j = 0; j < width; j++) {
  34069. var index = i0 * width + j;
  34070. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34071. var i = i0 + i1;
  34072. if (i >= height) {
  34073. break;
  34074. }
  34075. // clear processed flag first
  34076. processingFlags[index] &= processedInverseMask;
  34077. if (coefficentsMagnitude[index] ||
  34078. !neighborsSignificance[index]) {
  34079. continue;
  34080. }
  34081. var contextLabel = labels[neighborsSignificance[index]];
  34082. var decision = decoder.readBit(contexts, contextLabel);
  34083. if (decision) {
  34084. var sign = this.decodeSignBit(i, j, index);
  34085. coefficentsSign[index] = sign;
  34086. coefficentsMagnitude[index] = 1;
  34087. this.setNeighborsSignificance(i, j, index);
  34088. processingFlags[index] |= firstMagnitudeBitMask;
  34089. }
  34090. bitsDecoded[index]++;
  34091. processingFlags[index] |= processedMask;
  34092. }
  34093. }
  34094. }
  34095. },
  34096. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34097. var width = this.width, height = this.height;
  34098. var coefficentsMagnitude = this.coefficentsMagnitude;
  34099. var coefficentsSign = this.coefficentsSign;
  34100. var contribution, sign0, sign1, significance1;
  34101. var contextLabel, decoded;
  34102. // calculate horizontal contribution
  34103. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34104. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34105. sign1 = coefficentsSign[index + 1];
  34106. if (significance1) {
  34107. sign0 = coefficentsSign[index - 1];
  34108. contribution = 1 - sign1 - sign0;
  34109. } else {
  34110. contribution = 1 - sign1 - sign1;
  34111. }
  34112. } else if (significance1) {
  34113. sign0 = coefficentsSign[index - 1];
  34114. contribution = 1 - sign0 - sign0;
  34115. } else {
  34116. contribution = 0;
  34117. }
  34118. var horizontalContribution = 3 * contribution;
  34119. // calculate vertical contribution and combine with the horizontal
  34120. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34121. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34122. sign1 = coefficentsSign[index + width];
  34123. if (significance1) {
  34124. sign0 = coefficentsSign[index - width];
  34125. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34126. } else {
  34127. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34128. }
  34129. } else if (significance1) {
  34130. sign0 = coefficentsSign[index - width];
  34131. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34132. } else {
  34133. contribution = horizontalContribution;
  34134. }
  34135. if (contribution >= 0) {
  34136. contextLabel = 9 + contribution;
  34137. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34138. } else {
  34139. contextLabel = 9 - contribution;
  34140. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34141. }
  34142. return decoded;
  34143. },
  34144. runMagnitudeRefinementPass:
  34145. function BitModel_runMagnitudeRefinementPass() {
  34146. var decoder = this.decoder;
  34147. var width = this.width, height = this.height;
  34148. var coefficentsMagnitude = this.coefficentsMagnitude;
  34149. var neighborsSignificance = this.neighborsSignificance;
  34150. var contexts = this.contexts;
  34151. var bitsDecoded = this.bitsDecoded;
  34152. var processingFlags = this.processingFlags;
  34153. var processedMask = 1;
  34154. var firstMagnitudeBitMask = 2;
  34155. var length = width * height;
  34156. var width4 = width * 4;
  34157. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  34158. indexNext = Math.min(length, index0 + width4);
  34159. for (var j = 0; j < width; j++) {
  34160. for (var index = index0 + j; index < indexNext; index += width) {
  34161. // significant but not those that have just become
  34162. if (!coefficentsMagnitude[index] ||
  34163. (processingFlags[index] & processedMask) !== 0) {
  34164. continue;
  34165. }
  34166. var contextLabel = 16;
  34167. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  34168. processingFlags[index] ^= firstMagnitudeBitMask;
  34169. // first refinement
  34170. var significance = neighborsSignificance[index] & 127;
  34171. contextLabel = significance === 0 ? 15 : 14;
  34172. }
  34173. var bit = decoder.readBit(contexts, contextLabel);
  34174. coefficentsMagnitude[index] =
  34175. (coefficentsMagnitude[index] << 1) | bit;
  34176. bitsDecoded[index]++;
  34177. processingFlags[index] |= processedMask;
  34178. }
  34179. }
  34180. }
  34181. },
  34182. runCleanupPass: function BitModel_runCleanupPass() {
  34183. var decoder = this.decoder;
  34184. var width = this.width, height = this.height;
  34185. var neighborsSignificance = this.neighborsSignificance;
  34186. var coefficentsMagnitude = this.coefficentsMagnitude;
  34187. var coefficentsSign = this.coefficentsSign;
  34188. var contexts = this.contexts;
  34189. var labels = this.contextLabelTable;
  34190. var bitsDecoded = this.bitsDecoded;
  34191. var processingFlags = this.processingFlags;
  34192. var processedMask = 1;
  34193. var firstMagnitudeBitMask = 2;
  34194. var oneRowDown = width;
  34195. var twoRowsDown = width * 2;
  34196. var threeRowsDown = width * 3;
  34197. var iNext;
  34198. for (var i0 = 0; i0 < height; i0 = iNext) {
  34199. iNext = Math.min(i0 + 4, height);
  34200. var indexBase = i0 * width;
  34201. var checkAllEmpty = i0 + 3 < height;
  34202. for (var j = 0; j < width; j++) {
  34203. var index0 = indexBase + j;
  34204. // using the property: labels[neighborsSignificance[index]] === 0
  34205. // when neighborsSignificance[index] === 0
  34206. var allEmpty = (checkAllEmpty &&
  34207. processingFlags[index0] === 0 &&
  34208. processingFlags[index0 + oneRowDown] === 0 &&
  34209. processingFlags[index0 + twoRowsDown] === 0 &&
  34210. processingFlags[index0 + threeRowsDown] === 0 &&
  34211. neighborsSignificance[index0] === 0 &&
  34212. neighborsSignificance[index0 + oneRowDown] === 0 &&
  34213. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  34214. neighborsSignificance[index0 + threeRowsDown] === 0);
  34215. var i1 = 0, index = index0;
  34216. var i = i0, sign;
  34217. if (allEmpty) {
  34218. var hasSignificantCoefficent =
  34219. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  34220. if (!hasSignificantCoefficent) {
  34221. bitsDecoded[index0]++;
  34222. bitsDecoded[index0 + oneRowDown]++;
  34223. bitsDecoded[index0 + twoRowsDown]++;
  34224. bitsDecoded[index0 + threeRowsDown]++;
  34225. continue; // next column
  34226. }
  34227. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34228. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34229. if (i1 !== 0) {
  34230. i = i0 + i1;
  34231. index += i1 * width;
  34232. }
  34233. sign = this.decodeSignBit(i, j, index);
  34234. coefficentsSign[index] = sign;
  34235. coefficentsMagnitude[index] = 1;
  34236. this.setNeighborsSignificance(i, j, index);
  34237. processingFlags[index] |= firstMagnitudeBitMask;
  34238. index = index0;
  34239. for (var i2 = i0; i2 <= i; i2++, index += width) {
  34240. bitsDecoded[index]++;
  34241. }
  34242. i1++;
  34243. }
  34244. for (i = i0 + i1; i < iNext; i++, index += width) {
  34245. if (coefficentsMagnitude[index] ||
  34246. (processingFlags[index] & processedMask) !== 0) {
  34247. continue;
  34248. }
  34249. var contextLabel = labels[neighborsSignificance[index]];
  34250. var decision = decoder.readBit(contexts, contextLabel);
  34251. if (decision === 1) {
  34252. sign = this.decodeSignBit(i, j, index);
  34253. coefficentsSign[index] = sign;
  34254. coefficentsMagnitude[index] = 1;
  34255. this.setNeighborsSignificance(i, j, index);
  34256. processingFlags[index] |= firstMagnitudeBitMask;
  34257. }
  34258. bitsDecoded[index]++;
  34259. }
  34260. }
  34261. }
  34262. },
  34263. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  34264. var decoder = this.decoder;
  34265. var contexts = this.contexts;
  34266. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  34267. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  34268. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34269. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34270. if (symbol !== 0xA) {
  34271. throw new Error('JPX Error: Invalid segmentation symbol');
  34272. }
  34273. }
  34274. };
  34275. return BitModel;
  34276. })();
  34277. // Section F, Discrete wavelet transformation
  34278. var Transform = (function TransformClosure() {
  34279. function Transform() {}
  34280. Transform.prototype.calculate =
  34281. function transformCalculate(subbands, u0, v0) {
  34282. var ll = subbands[0];
  34283. for (var i = 1, ii = subbands.length; i < ii; i++) {
  34284. ll = this.iterate(ll, subbands[i], u0, v0);
  34285. }
  34286. return ll;
  34287. };
  34288. Transform.prototype.extend = function extend(buffer, offset, size) {
  34289. // Section F.3.7 extending... using max extension of 4
  34290. var i1 = offset - 1, j1 = offset + 1;
  34291. var i2 = offset + size - 2, j2 = offset + size;
  34292. buffer[i1--] = buffer[j1++];
  34293. buffer[j2++] = buffer[i2--];
  34294. buffer[i1--] = buffer[j1++];
  34295. buffer[j2++] = buffer[i2--];
  34296. buffer[i1--] = buffer[j1++];
  34297. buffer[j2++] = buffer[i2--];
  34298. buffer[i1] = buffer[j1];
  34299. buffer[j2] = buffer[i2];
  34300. };
  34301. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  34302. u0, v0) {
  34303. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  34304. var width = hl_lh_hh.width;
  34305. var height = hl_lh_hh.height;
  34306. var items = hl_lh_hh.items;
  34307. var i, j, k, l, u, v;
  34308. // Interleave LL according to Section F.3.3
  34309. for (k = 0, i = 0; i < llHeight; i++) {
  34310. l = i * 2 * width;
  34311. for (j = 0; j < llWidth; j++, k++, l += 2) {
  34312. items[l] = llItems[k];
  34313. }
  34314. }
  34315. // The LL band is not needed anymore.
  34316. llItems = ll.items = null;
  34317. var bufferPadding = 4;
  34318. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  34319. // Section F.3.4 HOR_SR
  34320. if (width === 1) {
  34321. // if width = 1, when u0 even keep items as is, when odd divide by 2
  34322. if ((u0 & 1) !== 0) {
  34323. for (v = 0, k = 0; v < height; v++, k += width) {
  34324. items[k] *= 0.5;
  34325. }
  34326. }
  34327. } else {
  34328. for (v = 0, k = 0; v < height; v++, k += width) {
  34329. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  34330. this.extend(rowBuffer, bufferPadding, width);
  34331. this.filter(rowBuffer, bufferPadding, width);
  34332. items.set(
  34333. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  34334. k);
  34335. }
  34336. }
  34337. // Accesses to the items array can take long, because it may not fit into
  34338. // CPU cache and has to be fetched from main memory. Since subsequent
  34339. // accesses to the items array are not local when reading columns, we
  34340. // have a cache miss every time. To reduce cache misses, get up to
  34341. // 'numBuffers' items at a time and store them into the individual
  34342. // buffers. The colBuffers should be small enough to fit into CPU cache.
  34343. var numBuffers = 16;
  34344. var colBuffers = [];
  34345. for (i = 0; i < numBuffers; i++) {
  34346. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  34347. }
  34348. var b, currentBuffer = 0;
  34349. ll = bufferPadding + height;
  34350. // Section F.3.5 VER_SR
  34351. if (height === 1) {
  34352. // if height = 1, when v0 even keep items as is, when odd divide by 2
  34353. if ((v0 & 1) !== 0) {
  34354. for (u = 0; u < width; u++) {
  34355. items[u] *= 0.5;
  34356. }
  34357. }
  34358. } else {
  34359. for (u = 0; u < width; u++) {
  34360. // if we ran out of buffers, copy several image columns at once
  34361. if (currentBuffer === 0) {
  34362. numBuffers = Math.min(width - u, numBuffers);
  34363. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  34364. for (b = 0; b < numBuffers; b++) {
  34365. colBuffers[b][l] = items[k + b];
  34366. }
  34367. }
  34368. currentBuffer = numBuffers;
  34369. }
  34370. currentBuffer--;
  34371. var buffer = colBuffers[currentBuffer];
  34372. this.extend(buffer, bufferPadding, height);
  34373. this.filter(buffer, bufferPadding, height);
  34374. // If this is last buffer in this group of buffers, flush all buffers.
  34375. if (currentBuffer === 0) {
  34376. k = u - numBuffers + 1;
  34377. for (l = bufferPadding; l < ll; k += width, l++) {
  34378. for (b = 0; b < numBuffers; b++) {
  34379. items[k + b] = colBuffers[b][l];
  34380. }
  34381. }
  34382. }
  34383. }
  34384. }
  34385. return {
  34386. width: width,
  34387. height: height,
  34388. items: items
  34389. };
  34390. };
  34391. return Transform;
  34392. })();
  34393. // Section 3.8.2 Irreversible 9-7 filter
  34394. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  34395. function IrreversibleTransform() {
  34396. Transform.call(this);
  34397. }
  34398. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  34399. IrreversibleTransform.prototype.filter =
  34400. function irreversibleTransformFilter(x, offset, length) {
  34401. var len = length >> 1;
  34402. offset = offset | 0;
  34403. var j, n, current, next;
  34404. var alpha = -1.586134342059924;
  34405. var beta = -0.052980118572961;
  34406. var gamma = 0.882911075530934;
  34407. var delta = 0.443506852043971;
  34408. var K = 1.230174104914001;
  34409. var K_ = 1 / K;
  34410. // step 1 is combined with step 3
  34411. // step 2
  34412. j = offset - 3;
  34413. for (n = len + 4; n--; j += 2) {
  34414. x[j] *= K_;
  34415. }
  34416. // step 1 & 3
  34417. j = offset - 2;
  34418. current = delta * x[j -1];
  34419. for (n = len + 3; n--; j += 2) {
  34420. next = delta * x[j + 1];
  34421. x[j] = K * x[j] - current - next;
  34422. if (n--) {
  34423. j += 2;
  34424. current = delta * x[j + 1];
  34425. x[j] = K * x[j] - current - next;
  34426. } else {
  34427. break;
  34428. }
  34429. }
  34430. // step 4
  34431. j = offset - 1;
  34432. current = gamma * x[j - 1];
  34433. for (n = len + 2; n--; j += 2) {
  34434. next = gamma * x[j + 1];
  34435. x[j] -= current + next;
  34436. if (n--) {
  34437. j += 2;
  34438. current = gamma * x[j + 1];
  34439. x[j] -= current + next;
  34440. } else {
  34441. break;
  34442. }
  34443. }
  34444. // step 5
  34445. j = offset;
  34446. current = beta * x[j - 1];
  34447. for (n = len + 1; n--; j += 2) {
  34448. next = beta * x[j + 1];
  34449. x[j] -= current + next;
  34450. if (n--) {
  34451. j += 2;
  34452. current = beta * x[j + 1];
  34453. x[j] -= current + next;
  34454. } else {
  34455. break;
  34456. }
  34457. }
  34458. // step 6
  34459. if (len !== 0) {
  34460. j = offset + 1;
  34461. current = alpha * x[j - 1];
  34462. for (n = len; n--; j += 2) {
  34463. next = alpha * x[j + 1];
  34464. x[j] -= current + next;
  34465. if (n--) {
  34466. j += 2;
  34467. current = alpha * x[j + 1];
  34468. x[j] -= current + next;
  34469. } else {
  34470. break;
  34471. }
  34472. }
  34473. }
  34474. };
  34475. return IrreversibleTransform;
  34476. })();
  34477. // Section 3.8.1 Reversible 5-3 filter
  34478. var ReversibleTransform = (function ReversibleTransformClosure() {
  34479. function ReversibleTransform() {
  34480. Transform.call(this);
  34481. }
  34482. ReversibleTransform.prototype = Object.create(Transform.prototype);
  34483. ReversibleTransform.prototype.filter =
  34484. function reversibleTransformFilter(x, offset, length) {
  34485. var len = length >> 1;
  34486. offset = offset | 0;
  34487. var j, n;
  34488. for (j = offset, n = len + 1; n--; j += 2) {
  34489. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  34490. }
  34491. for (j = offset + 1, n = len; n--; j += 2) {
  34492. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  34493. }
  34494. };
  34495. return ReversibleTransform;
  34496. })();
  34497. return JpxImage;
  34498. })();
  34499. var Jbig2Image = (function Jbig2ImageClosure() {
  34500. // Utility data structures
  34501. function ContextCache() {}
  34502. ContextCache.prototype = {
  34503. getContexts: function(id) {
  34504. if (id in this) {
  34505. return this[id];
  34506. }
  34507. return (this[id] = new Int8Array(1 << 16));
  34508. }
  34509. };
  34510. function DecodingContext(data, start, end) {
  34511. this.data = data;
  34512. this.start = start;
  34513. this.end = end;
  34514. }
  34515. DecodingContext.prototype = {
  34516. get decoder() {
  34517. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  34518. return shadow(this, 'decoder', decoder);
  34519. },
  34520. get contextCache() {
  34521. var cache = new ContextCache();
  34522. return shadow(this, 'contextCache', cache);
  34523. }
  34524. };
  34525. // Annex A. Arithmetic Integer Decoding Procedure
  34526. // A.2 Procedure for decoding values
  34527. function decodeInteger(contextCache, procedure, decoder) {
  34528. var contexts = contextCache.getContexts(procedure);
  34529. var prev = 1;
  34530. function readBits(length) {
  34531. var v = 0;
  34532. for (var i = 0; i < length; i++) {
  34533. var bit = decoder.readBit(contexts, prev);
  34534. prev = (prev < 256 ? (prev << 1) | bit :
  34535. (((prev << 1) | bit) & 511) | 256);
  34536. v = (v << 1) | bit;
  34537. }
  34538. return v >>> 0;
  34539. }
  34540. var sign = readBits(1);
  34541. var value = readBits(1) ?
  34542. (readBits(1) ?
  34543. (readBits(1) ?
  34544. (readBits(1) ?
  34545. (readBits(1) ?
  34546. (readBits(32) + 4436) :
  34547. readBits(12) + 340) :
  34548. readBits(8) + 84) :
  34549. readBits(6) + 20) :
  34550. readBits(4) + 4) :
  34551. readBits(2);
  34552. return (sign === 0 ? value : (value > 0 ? -value : null));
  34553. }
  34554. // A.3 The IAID decoding procedure
  34555. function decodeIAID(contextCache, decoder, codeLength) {
  34556. var contexts = contextCache.getContexts('IAID');
  34557. var prev = 1;
  34558. for (var i = 0; i < codeLength; i++) {
  34559. var bit = decoder.readBit(contexts, prev);
  34560. prev = (prev << 1) | bit;
  34561. }
  34562. if (codeLength < 31) {
  34563. return prev & ((1 << codeLength) - 1);
  34564. }
  34565. return prev & 0x7FFFFFFF;
  34566. }
  34567. // 7.3 Segment types
  34568. var SegmentTypes = [
  34569. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  34570. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  34571. null, null, null, null, null, 'patternDictionary', null, null, null,
  34572. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  34573. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  34574. null, null, null, null, null, 'IntermediateGenericRegion', null,
  34575. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  34576. 'IntermediateGenericRefinementRegion', null,
  34577. 'ImmediateGenericRefinementRegion',
  34578. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  34579. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  34580. 'Tables', null, null, null, null, null, null, null, null,
  34581. 'Extension'
  34582. ];
  34583. var CodingTemplates = [
  34584. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  34585. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  34586. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  34587. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  34588. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  34589. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  34590. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  34591. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  34592. {x: -1, y: 0}],
  34593. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  34594. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  34595. ];
  34596. var RefinementTemplates = [
  34597. {
  34598. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  34599. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  34600. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  34601. },
  34602. {
  34603. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  34604. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  34605. {x: 0, y: 1}, {x: 1, y: 1}]
  34606. }
  34607. ];
  34608. // See 6.2.5.7 Decoding the bitmap.
  34609. var ReusedContexts = [
  34610. 0x9B25, // 10011 0110010 0101
  34611. 0x0795, // 0011 110010 101
  34612. 0x00E5, // 001 11001 01
  34613. 0x0195 // 011001 0101
  34614. ];
  34615. var RefinementReusedContexts = [
  34616. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  34617. 0x0008 // '0000' + '001000'
  34618. ];
  34619. function decodeBitmapTemplate0(width, height, decodingContext) {
  34620. var decoder = decodingContext.decoder;
  34621. var contexts = decodingContext.contextCache.getContexts('GB');
  34622. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  34623. // ...ooooo....
  34624. // ..ooooooo... Context template for current pixel (X)
  34625. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  34626. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  34627. for (i = 0; i < height; i++) {
  34628. row = bitmap[i] = new Uint8Array(width);
  34629. row1 = (i < 1) ? row : bitmap[i - 1];
  34630. row2 = (i < 2) ? row : bitmap[i - 2];
  34631. // At the beginning of each row:
  34632. // Fill contextLabel with pixels that are above/right of (X)
  34633. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  34634. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  34635. (row1[3] << 4);
  34636. for (j = 0; j < width; j++) {
  34637. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  34638. // At each pixel: Clear contextLabel pixels that are shifted
  34639. // out of the context, then add new ones.
  34640. // If j + n is out of range at the right image border, then
  34641. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  34642. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  34643. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  34644. }
  34645. }
  34646. return bitmap;
  34647. }
  34648. // 6.2 Generic Region Decoding Procedure
  34649. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  34650. decodingContext) {
  34651. if (mmr) {
  34652. error('JBIG2 error: MMR encoding is not supported');
  34653. }
  34654. // Use optimized version for the most common case
  34655. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  34656. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  34657. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  34658. return decodeBitmapTemplate0(width, height, decodingContext);
  34659. }
  34660. var useskip = !!skip;
  34661. var template = CodingTemplates[templateIndex].concat(at);
  34662. // Sorting is non-standard, and it is not required. But sorting increases
  34663. // the number of template bits that can be reused from the previous
  34664. // contextLabel in the main loop.
  34665. template.sort(function (a, b) {
  34666. return (a.y - b.y) || (a.x - b.x);
  34667. });
  34668. var templateLength = template.length;
  34669. var templateX = new Int8Array(templateLength);
  34670. var templateY = new Int8Array(templateLength);
  34671. var changingTemplateEntries = [];
  34672. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  34673. var c, k;
  34674. for (k = 0; k < templateLength; k++) {
  34675. templateX[k] = template[k].x;
  34676. templateY[k] = template[k].y;
  34677. minX = Math.min(minX, template[k].x);
  34678. maxX = Math.max(maxX, template[k].x);
  34679. minY = Math.min(minY, template[k].y);
  34680. // Check if the template pixel appears in two consecutive context labels,
  34681. // so it can be reused. Otherwise, we add it to the list of changing
  34682. // template entries.
  34683. if (k < templateLength - 1 &&
  34684. template[k].y === template[k + 1].y &&
  34685. template[k].x === template[k + 1].x - 1) {
  34686. reuseMask |= 1 << (templateLength - 1 - k);
  34687. } else {
  34688. changingTemplateEntries.push(k);
  34689. }
  34690. }
  34691. var changingEntriesLength = changingTemplateEntries.length;
  34692. var changingTemplateX = new Int8Array(changingEntriesLength);
  34693. var changingTemplateY = new Int8Array(changingEntriesLength);
  34694. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  34695. for (c = 0; c < changingEntriesLength; c++) {
  34696. k = changingTemplateEntries[c];
  34697. changingTemplateX[c] = template[k].x;
  34698. changingTemplateY[c] = template[k].y;
  34699. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  34700. }
  34701. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  34702. var sbb_left = -minX;
  34703. var sbb_top = -minY;
  34704. var sbb_right = width - maxX;
  34705. var pseudoPixelContext = ReusedContexts[templateIndex];
  34706. var row = new Uint8Array(width);
  34707. var bitmap = [];
  34708. var decoder = decodingContext.decoder;
  34709. var contexts = decodingContext.contextCache.getContexts('GB');
  34710. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  34711. for (var i = 0; i < height; i++) {
  34712. if (prediction) {
  34713. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34714. ltp ^= sltp;
  34715. if (ltp) {
  34716. bitmap.push(row); // duplicate previous row
  34717. continue;
  34718. }
  34719. }
  34720. row = new Uint8Array(row);
  34721. bitmap.push(row);
  34722. for (j = 0; j < width; j++) {
  34723. if (useskip && skip[i][j]) {
  34724. row[j] = 0;
  34725. continue;
  34726. }
  34727. // Are we in the middle of a scanline, so we can reuse contextLabel
  34728. // bits?
  34729. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  34730. // If yes, we can just shift the bits that are reusable and only
  34731. // fetch the remaining ones.
  34732. contextLabel = (contextLabel << 1) & reuseMask;
  34733. for (k = 0; k < changingEntriesLength; k++) {
  34734. i0 = i + changingTemplateY[k];
  34735. j0 = j + changingTemplateX[k];
  34736. bit = bitmap[i0][j0];
  34737. if (bit) {
  34738. bit = changingTemplateBit[k];
  34739. contextLabel |= bit;
  34740. }
  34741. }
  34742. } else {
  34743. // compute the contextLabel from scratch
  34744. contextLabel = 0;
  34745. shift = templateLength - 1;
  34746. for (k = 0; k < templateLength; k++, shift--) {
  34747. j0 = j + templateX[k];
  34748. if (j0 >= 0 && j0 < width) {
  34749. i0 = i + templateY[k];
  34750. if (i0 >= 0) {
  34751. bit = bitmap[i0][j0];
  34752. if (bit) {
  34753. contextLabel |= bit << shift;
  34754. }
  34755. }
  34756. }
  34757. }
  34758. }
  34759. var pixel = decoder.readBit(contexts, contextLabel);
  34760. row[j] = pixel;
  34761. }
  34762. }
  34763. return bitmap;
  34764. }
  34765. // 6.3.2 Generic Refinement Region Decoding Procedure
  34766. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  34767. offsetX, offsetY, prediction, at,
  34768. decodingContext) {
  34769. var codingTemplate = RefinementTemplates[templateIndex].coding;
  34770. if (templateIndex === 0) {
  34771. codingTemplate = codingTemplate.concat([at[0]]);
  34772. }
  34773. var codingTemplateLength = codingTemplate.length;
  34774. var codingTemplateX = new Int32Array(codingTemplateLength);
  34775. var codingTemplateY = new Int32Array(codingTemplateLength);
  34776. var k;
  34777. for (k = 0; k < codingTemplateLength; k++) {
  34778. codingTemplateX[k] = codingTemplate[k].x;
  34779. codingTemplateY[k] = codingTemplate[k].y;
  34780. }
  34781. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  34782. if (templateIndex === 0) {
  34783. referenceTemplate = referenceTemplate.concat([at[1]]);
  34784. }
  34785. var referenceTemplateLength = referenceTemplate.length;
  34786. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  34787. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  34788. for (k = 0; k < referenceTemplateLength; k++) {
  34789. referenceTemplateX[k] = referenceTemplate[k].x;
  34790. referenceTemplateY[k] = referenceTemplate[k].y;
  34791. }
  34792. var referenceWidth = referenceBitmap[0].length;
  34793. var referenceHeight = referenceBitmap.length;
  34794. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  34795. var bitmap = [];
  34796. var decoder = decodingContext.decoder;
  34797. var contexts = decodingContext.contextCache.getContexts('GR');
  34798. var ltp = 0;
  34799. for (var i = 0; i < height; i++) {
  34800. if (prediction) {
  34801. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34802. ltp ^= sltp;
  34803. if (ltp) {
  34804. error('JBIG2 error: prediction is not supported');
  34805. }
  34806. }
  34807. var row = new Uint8Array(width);
  34808. bitmap.push(row);
  34809. for (var j = 0; j < width; j++) {
  34810. var i0, j0;
  34811. var contextLabel = 0;
  34812. for (k = 0; k < codingTemplateLength; k++) {
  34813. i0 = i + codingTemplateY[k];
  34814. j0 = j + codingTemplateX[k];
  34815. if (i0 < 0 || j0 < 0 || j0 >= width) {
  34816. contextLabel <<= 1; // out of bound pixel
  34817. } else {
  34818. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  34819. }
  34820. }
  34821. for (k = 0; k < referenceTemplateLength; k++) {
  34822. i0 = i + referenceTemplateY[k] + offsetY;
  34823. j0 = j + referenceTemplateX[k] + offsetX;
  34824. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  34825. j0 >= referenceWidth) {
  34826. contextLabel <<= 1; // out of bound pixel
  34827. } else {
  34828. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  34829. }
  34830. }
  34831. var pixel = decoder.readBit(contexts, contextLabel);
  34832. row[j] = pixel;
  34833. }
  34834. }
  34835. return bitmap;
  34836. }
  34837. // 6.5.5 Decoding the symbol dictionary
  34838. function decodeSymbolDictionary(huffman, refinement, symbols,
  34839. numberOfNewSymbols, numberOfExportedSymbols,
  34840. huffmanTables, templateIndex, at,
  34841. refinementTemplateIndex, refinementAt,
  34842. decodingContext) {
  34843. if (huffman) {
  34844. error('JBIG2 error: huffman is not supported');
  34845. }
  34846. var newSymbols = [];
  34847. var currentHeight = 0;
  34848. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  34849. var decoder = decodingContext.decoder;
  34850. var contextCache = decodingContext.contextCache;
  34851. while (newSymbols.length < numberOfNewSymbols) {
  34852. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  34853. currentHeight += deltaHeight;
  34854. var currentWidth = 0;
  34855. var totalWidth = 0;
  34856. while (true) {
  34857. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  34858. if (deltaWidth === null) {
  34859. break; // OOB
  34860. }
  34861. currentWidth += deltaWidth;
  34862. totalWidth += currentWidth;
  34863. var bitmap;
  34864. if (refinement) {
  34865. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  34866. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  34867. if (numberOfInstances > 1) {
  34868. bitmap = decodeTextRegion(huffman, refinement,
  34869. currentWidth, currentHeight, 0,
  34870. numberOfInstances, 1, //strip size
  34871. symbols.concat(newSymbols),
  34872. symbolCodeLength,
  34873. 0, //transposed
  34874. 0, //ds offset
  34875. 1, //top left 7.4.3.1.1
  34876. 0, //OR operator
  34877. huffmanTables,
  34878. refinementTemplateIndex, refinementAt,
  34879. decodingContext);
  34880. } else {
  34881. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34882. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34883. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34884. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  34885. newSymbols[symbolId - symbols.length]);
  34886. bitmap = decodeRefinement(currentWidth, currentHeight,
  34887. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  34888. decodingContext);
  34889. }
  34890. } else {
  34891. // 6.5.8.1 Direct-coded symbol bitmap
  34892. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  34893. templateIndex, false, null, at, decodingContext);
  34894. }
  34895. newSymbols.push(bitmap);
  34896. }
  34897. }
  34898. // 6.5.10 Exported symbols
  34899. var exportedSymbols = [];
  34900. var flags = [], currentFlag = false;
  34901. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  34902. while (flags.length < totalSymbolsLength) {
  34903. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  34904. while (runLength--) {
  34905. flags.push(currentFlag);
  34906. }
  34907. currentFlag = !currentFlag;
  34908. }
  34909. for (var i = 0, ii = symbols.length; i < ii; i++) {
  34910. if (flags[i]) {
  34911. exportedSymbols.push(symbols[i]);
  34912. }
  34913. }
  34914. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  34915. if (flags[i]) {
  34916. exportedSymbols.push(newSymbols[j]);
  34917. }
  34918. }
  34919. return exportedSymbols;
  34920. }
  34921. function decodeTextRegion(huffman, refinement, width, height,
  34922. defaultPixelValue, numberOfSymbolInstances,
  34923. stripSize, inputSymbols, symbolCodeLength,
  34924. transposed, dsOffset, referenceCorner,
  34925. combinationOperator, huffmanTables,
  34926. refinementTemplateIndex, refinementAt,
  34927. decodingContext) {
  34928. if (huffman) {
  34929. error('JBIG2 error: huffman is not supported');
  34930. }
  34931. // Prepare bitmap
  34932. var bitmap = [];
  34933. var i, row;
  34934. for (i = 0; i < height; i++) {
  34935. row = new Uint8Array(width);
  34936. if (defaultPixelValue) {
  34937. for (var j = 0; j < width; j++) {
  34938. row[j] = defaultPixelValue;
  34939. }
  34940. }
  34941. bitmap.push(row);
  34942. }
  34943. var decoder = decodingContext.decoder;
  34944. var contextCache = decodingContext.contextCache;
  34945. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  34946. var firstS = 0;
  34947. i = 0;
  34948. while (i < numberOfSymbolInstances) {
  34949. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  34950. stripT += deltaT;
  34951. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  34952. firstS += deltaFirstS;
  34953. var currentS = firstS;
  34954. do {
  34955. var currentT = (stripSize === 1 ? 0 :
  34956. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  34957. var t = stripSize * stripT + currentT;
  34958. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34959. var applyRefinement = (refinement &&
  34960. decodeInteger(contextCache, 'IARI', decoder));
  34961. var symbolBitmap = inputSymbols[symbolId];
  34962. var symbolWidth = symbolBitmap[0].length;
  34963. var symbolHeight = symbolBitmap.length;
  34964. if (applyRefinement) {
  34965. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  34966. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  34967. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34968. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34969. symbolWidth += rdw;
  34970. symbolHeight += rdh;
  34971. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  34972. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  34973. (rdh >> 1) + rdy, false, refinementAt,
  34974. decodingContext);
  34975. }
  34976. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  34977. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  34978. var s2, t2, symbolRow;
  34979. if (transposed) {
  34980. // Place Symbol Bitmap from T1,S1
  34981. for (s2 = 0; s2 < symbolHeight; s2++) {
  34982. row = bitmap[offsetS + s2];
  34983. if (!row) {
  34984. continue;
  34985. }
  34986. symbolRow = symbolBitmap[s2];
  34987. // To ignore Parts of Symbol bitmap which goes
  34988. // outside bitmap region
  34989. var maxWidth = Math.min(width - offsetT, symbolWidth);
  34990. switch (combinationOperator) {
  34991. case 0: // OR
  34992. for (t2 = 0; t2 < maxWidth; t2++) {
  34993. row[offsetT + t2] |= symbolRow[t2];
  34994. }
  34995. break;
  34996. case 2: // XOR
  34997. for (t2 = 0; t2 < maxWidth; t2++) {
  34998. row[offsetT + t2] ^= symbolRow[t2];
  34999. }
  35000. break;
  35001. default:
  35002. error('JBIG2 error: operator ' + combinationOperator +
  35003. ' is not supported');
  35004. }
  35005. }
  35006. currentS += symbolHeight - 1;
  35007. } else {
  35008. for (t2 = 0; t2 < symbolHeight; t2++) {
  35009. row = bitmap[offsetT + t2];
  35010. if (!row) {
  35011. continue;
  35012. }
  35013. symbolRow = symbolBitmap[t2];
  35014. switch (combinationOperator) {
  35015. case 0: // OR
  35016. for (s2 = 0; s2 < symbolWidth; s2++) {
  35017. row[offsetS + s2] |= symbolRow[s2];
  35018. }
  35019. break;
  35020. case 2: // XOR
  35021. for (s2 = 0; s2 < symbolWidth; s2++) {
  35022. row[offsetS + s2] ^= symbolRow[s2];
  35023. }
  35024. break;
  35025. default:
  35026. error('JBIG2 error: operator ' + combinationOperator +
  35027. ' is not supported');
  35028. }
  35029. }
  35030. currentS += symbolWidth - 1;
  35031. }
  35032. i++;
  35033. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35034. if (deltaS === null) {
  35035. break; // OOB
  35036. }
  35037. currentS += deltaS + dsOffset;
  35038. } while (true);
  35039. }
  35040. return bitmap;
  35041. }
  35042. function readSegmentHeader(data, start) {
  35043. var segmentHeader = {};
  35044. segmentHeader.number = readUint32(data, start);
  35045. var flags = data[start + 4];
  35046. var segmentType = flags & 0x3F;
  35047. if (!SegmentTypes[segmentType]) {
  35048. error('JBIG2 error: invalid segment type: ' + segmentType);
  35049. }
  35050. segmentHeader.type = segmentType;
  35051. segmentHeader.typeName = SegmentTypes[segmentType];
  35052. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35053. var pageAssociationFieldSize = !!(flags & 0x40);
  35054. var referredFlags = data[start + 5];
  35055. var referredToCount = (referredFlags >> 5) & 7;
  35056. var retainBits = [referredFlags & 31];
  35057. var position = start + 6;
  35058. if (referredFlags === 7) {
  35059. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35060. position += 3;
  35061. var bytes = (referredToCount + 7) >> 3;
  35062. retainBits[0] = data[position++];
  35063. while (--bytes > 0) {
  35064. retainBits.push(data[position++]);
  35065. }
  35066. } else if (referredFlags === 5 || referredFlags === 6) {
  35067. error('JBIG2 error: invalid referred-to flags');
  35068. }
  35069. segmentHeader.retainBits = retainBits;
  35070. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35071. (segmentHeader.number <= 65536 ? 2 : 4));
  35072. var referredTo = [];
  35073. var i, ii;
  35074. for (i = 0; i < referredToCount; i++) {
  35075. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35076. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35077. readUint32(data, position)));
  35078. referredTo.push(number);
  35079. position += referredToSegmentNumberSize;
  35080. }
  35081. segmentHeader.referredTo = referredTo;
  35082. if (!pageAssociationFieldSize) {
  35083. segmentHeader.pageAssociation = data[position++];
  35084. } else {
  35085. segmentHeader.pageAssociation = readUint32(data, position);
  35086. position += 4;
  35087. }
  35088. segmentHeader.length = readUint32(data, position);
  35089. position += 4;
  35090. if (segmentHeader.length === 0xFFFFFFFF) {
  35091. // 7.2.7 Segment data length, unknown segment length
  35092. if (segmentType === 38) { // ImmediateGenericRegion
  35093. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35094. var genericRegionSegmentFlags = data[position +
  35095. RegionSegmentInformationFieldLength];
  35096. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35097. // searching for the segment end
  35098. var searchPatternLength = 6;
  35099. var searchPattern = new Uint8Array(searchPatternLength);
  35100. if (!genericRegionMmr) {
  35101. searchPattern[0] = 0xFF;
  35102. searchPattern[1] = 0xAC;
  35103. }
  35104. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35105. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35106. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35107. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35108. for (i = position, ii = data.length; i < ii; i++) {
  35109. var j = 0;
  35110. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35111. j++;
  35112. }
  35113. if (j === searchPatternLength) {
  35114. segmentHeader.length = i + searchPatternLength;
  35115. break;
  35116. }
  35117. }
  35118. if (segmentHeader.length === 0xFFFFFFFF) {
  35119. error('JBIG2 error: segment end was not found');
  35120. }
  35121. } else {
  35122. error('JBIG2 error: invalid unknown segment length');
  35123. }
  35124. }
  35125. segmentHeader.headerEnd = position;
  35126. return segmentHeader;
  35127. }
  35128. function readSegments(header, data, start, end) {
  35129. var segments = [];
  35130. var position = start;
  35131. while (position < end) {
  35132. var segmentHeader = readSegmentHeader(data, position);
  35133. position = segmentHeader.headerEnd;
  35134. var segment = {
  35135. header: segmentHeader,
  35136. data: data
  35137. };
  35138. if (!header.randomAccess) {
  35139. segment.start = position;
  35140. position += segmentHeader.length;
  35141. segment.end = position;
  35142. }
  35143. segments.push(segment);
  35144. if (segmentHeader.type === 51) {
  35145. break; // end of file is found
  35146. }
  35147. }
  35148. if (header.randomAccess) {
  35149. for (var i = 0, ii = segments.length; i < ii; i++) {
  35150. segments[i].start = position;
  35151. position += segments[i].header.length;
  35152. segments[i].end = position;
  35153. }
  35154. }
  35155. return segments;
  35156. }
  35157. // 7.4.1 Region segment information field
  35158. function readRegionSegmentInformation(data, start) {
  35159. return {
  35160. width: readUint32(data, start),
  35161. height: readUint32(data, start + 4),
  35162. x: readUint32(data, start + 8),
  35163. y: readUint32(data, start + 12),
  35164. combinationOperator: data[start + 16] & 7
  35165. };
  35166. }
  35167. var RegionSegmentInformationFieldLength = 17;
  35168. function processSegment(segment, visitor) {
  35169. var header = segment.header;
  35170. var data = segment.data, position = segment.start, end = segment.end;
  35171. var args, at, i, atLength;
  35172. switch (header.type) {
  35173. case 0: // SymbolDictionary
  35174. // 7.4.2 Symbol dictionary segment syntax
  35175. var dictionary = {};
  35176. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  35177. dictionary.huffman = !!(dictionaryFlags & 1);
  35178. dictionary.refinement = !!(dictionaryFlags & 2);
  35179. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  35180. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  35181. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  35182. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  35183. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  35184. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  35185. dictionary.template = (dictionaryFlags >> 10) & 3;
  35186. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  35187. position += 2;
  35188. if (!dictionary.huffman) {
  35189. atLength = dictionary.template === 0 ? 4 : 1;
  35190. at = [];
  35191. for (i = 0; i < atLength; i++) {
  35192. at.push({
  35193. x: readInt8(data, position),
  35194. y: readInt8(data, position + 1)
  35195. });
  35196. position += 2;
  35197. }
  35198. dictionary.at = at;
  35199. }
  35200. if (dictionary.refinement && !dictionary.refinementTemplate) {
  35201. at = [];
  35202. for (i = 0; i < 2; i++) {
  35203. at.push({
  35204. x: readInt8(data, position),
  35205. y: readInt8(data, position + 1)
  35206. });
  35207. position += 2;
  35208. }
  35209. dictionary.refinementAt = at;
  35210. }
  35211. dictionary.numberOfExportedSymbols = readUint32(data, position);
  35212. position += 4;
  35213. dictionary.numberOfNewSymbols = readUint32(data, position);
  35214. position += 4;
  35215. args = [dictionary, header.number, header.referredTo,
  35216. data, position, end];
  35217. break;
  35218. case 6: // ImmediateTextRegion
  35219. case 7: // ImmediateLosslessTextRegion
  35220. var textRegion = {};
  35221. textRegion.info = readRegionSegmentInformation(data, position);
  35222. position += RegionSegmentInformationFieldLength;
  35223. var textRegionSegmentFlags = readUint16(data, position);
  35224. position += 2;
  35225. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  35226. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  35227. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  35228. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  35229. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  35230. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  35231. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  35232. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  35233. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  35234. if (textRegion.huffman) {
  35235. var textRegionHuffmanFlags = readUint16(data, position);
  35236. position += 2;
  35237. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  35238. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  35239. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  35240. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  35241. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  35242. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  35243. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  35244. textRegion.huffmanRefinementSizeSelector =
  35245. !!(textRegionHuffmanFlags & 14);
  35246. }
  35247. if (textRegion.refinement && !textRegion.refinementTemplate) {
  35248. at = [];
  35249. for (i = 0; i < 2; i++) {
  35250. at.push({
  35251. x: readInt8(data, position),
  35252. y: readInt8(data, position + 1)
  35253. });
  35254. position += 2;
  35255. }
  35256. textRegion.refinementAt = at;
  35257. }
  35258. textRegion.numberOfSymbolInstances = readUint32(data, position);
  35259. position += 4;
  35260. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  35261. if (textRegion.huffman) {
  35262. error('JBIG2 error: huffman is not supported');
  35263. }
  35264. args = [textRegion, header.referredTo, data, position, end];
  35265. break;
  35266. case 38: // ImmediateGenericRegion
  35267. case 39: // ImmediateLosslessGenericRegion
  35268. var genericRegion = {};
  35269. genericRegion.info = readRegionSegmentInformation(data, position);
  35270. position += RegionSegmentInformationFieldLength;
  35271. var genericRegionSegmentFlags = data[position++];
  35272. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  35273. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  35274. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  35275. if (!genericRegion.mmr) {
  35276. atLength = genericRegion.template === 0 ? 4 : 1;
  35277. at = [];
  35278. for (i = 0; i < atLength; i++) {
  35279. at.push({
  35280. x: readInt8(data, position),
  35281. y: readInt8(data, position + 1)
  35282. });
  35283. position += 2;
  35284. }
  35285. genericRegion.at = at;
  35286. }
  35287. args = [genericRegion, data, position, end];
  35288. break;
  35289. case 48: // PageInformation
  35290. var pageInfo = {
  35291. width: readUint32(data, position),
  35292. height: readUint32(data, position + 4),
  35293. resolutionX: readUint32(data, position + 8),
  35294. resolutionY: readUint32(data, position + 12)
  35295. };
  35296. if (pageInfo.height === 0xFFFFFFFF) {
  35297. delete pageInfo.height;
  35298. }
  35299. var pageSegmentFlags = data[position + 16];
  35300. var pageStripingInformatiom = readUint16(data, position + 17);
  35301. pageInfo.lossless = !!(pageSegmentFlags & 1);
  35302. pageInfo.refinement = !!(pageSegmentFlags & 2);
  35303. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  35304. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  35305. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  35306. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  35307. args = [pageInfo];
  35308. break;
  35309. case 49: // EndOfPage
  35310. break;
  35311. case 50: // EndOfStripe
  35312. break;
  35313. case 51: // EndOfFile
  35314. break;
  35315. case 62: // 7.4.15 defines 2 extension types which
  35316. // are comments and can be ignored.
  35317. break;
  35318. default:
  35319. error('JBIG2 error: segment type ' + header.typeName + '(' +
  35320. header.type + ') is not implemented');
  35321. }
  35322. var callbackName = 'on' + header.typeName;
  35323. if (callbackName in visitor) {
  35324. visitor[callbackName].apply(visitor, args);
  35325. }
  35326. }
  35327. function processSegments(segments, visitor) {
  35328. for (var i = 0, ii = segments.length; i < ii; i++) {
  35329. processSegment(segments[i], visitor);
  35330. }
  35331. }
  35332. function parseJbig2(data, start, end) {
  35333. var position = start;
  35334. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  35335. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  35336. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  35337. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  35338. error('JBIG2 error: invalid header');
  35339. }
  35340. var header = {};
  35341. position += 8;
  35342. var flags = data[position++];
  35343. header.randomAccess = !(flags & 1);
  35344. if (!(flags & 2)) {
  35345. header.numberOfPages = readUint32(data, position);
  35346. position += 4;
  35347. }
  35348. var segments = readSegments(header, data, position, end);
  35349. error('Not implemented');
  35350. // processSegments(segments, new SimpleSegmentVisitor());
  35351. }
  35352. function parseJbig2Chunks(chunks) {
  35353. var visitor = new SimpleSegmentVisitor();
  35354. for (var i = 0, ii = chunks.length; i < ii; i++) {
  35355. var chunk = chunks[i];
  35356. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  35357. processSegments(segments, visitor);
  35358. }
  35359. return visitor.buffer;
  35360. }
  35361. function SimpleSegmentVisitor() {}
  35362. SimpleSegmentVisitor.prototype = {
  35363. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  35364. this.currentPageInfo = info;
  35365. var rowSize = (info.width + 7) >> 3;
  35366. var buffer = new Uint8Array(rowSize * info.height);
  35367. // The contents of ArrayBuffers are initialized to 0.
  35368. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  35369. if (info.defaultPixelValue) {
  35370. for (var i = 0, ii = buffer.length; i < ii; i++) {
  35371. buffer[i] = 0xFF;
  35372. }
  35373. }
  35374. this.buffer = buffer;
  35375. },
  35376. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  35377. var pageInfo = this.currentPageInfo;
  35378. var width = regionInfo.width, height = regionInfo.height;
  35379. var rowSize = (pageInfo.width + 7) >> 3;
  35380. var combinationOperator = pageInfo.combinationOperatorOverride ?
  35381. regionInfo.combinationOperator : pageInfo.combinationOperator;
  35382. var buffer = this.buffer;
  35383. var mask0 = 128 >> (regionInfo.x & 7);
  35384. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  35385. var i, j, mask, offset;
  35386. switch (combinationOperator) {
  35387. case 0: // OR
  35388. for (i = 0; i < height; i++) {
  35389. mask = mask0;
  35390. offset = offset0;
  35391. for (j = 0; j < width; j++) {
  35392. if (bitmap[i][j]) {
  35393. buffer[offset] |= mask;
  35394. }
  35395. mask >>= 1;
  35396. if (!mask) {
  35397. mask = 128;
  35398. offset++;
  35399. }
  35400. }
  35401. offset0 += rowSize;
  35402. }
  35403. break;
  35404. case 2: // XOR
  35405. for (i = 0; i < height; i++) {
  35406. mask = mask0;
  35407. offset = offset0;
  35408. for (j = 0; j < width; j++) {
  35409. if (bitmap[i][j]) {
  35410. buffer[offset] ^= mask;
  35411. }
  35412. mask >>= 1;
  35413. if (!mask) {
  35414. mask = 128;
  35415. offset++;
  35416. }
  35417. }
  35418. offset0 += rowSize;
  35419. }
  35420. break;
  35421. default:
  35422. error('JBIG2 error: operator ' + combinationOperator +
  35423. ' is not supported');
  35424. }
  35425. },
  35426. onImmediateGenericRegion:
  35427. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  35428. start, end) {
  35429. var regionInfo = region.info;
  35430. var decodingContext = new DecodingContext(data, start, end);
  35431. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  35432. region.template, region.prediction, null,
  35433. region.at, decodingContext);
  35434. this.drawBitmap(regionInfo, bitmap);
  35435. },
  35436. onImmediateLosslessGenericRegion:
  35437. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  35438. this.onImmediateGenericRegion.apply(this, arguments);
  35439. },
  35440. onSymbolDictionary:
  35441. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  35442. currentSegment,
  35443. referredSegments,
  35444. data, start, end) {
  35445. var huffmanTables;
  35446. if (dictionary.huffman) {
  35447. error('JBIG2 error: huffman is not supported');
  35448. }
  35449. // Combines exported symbols from all referred segments
  35450. var symbols = this.symbols;
  35451. if (!symbols) {
  35452. this.symbols = symbols = {};
  35453. }
  35454. var inputSymbols = [];
  35455. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  35456. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  35457. }
  35458. var decodingContext = new DecodingContext(data, start, end);
  35459. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  35460. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  35461. dictionary.numberOfExportedSymbols, huffmanTables,
  35462. dictionary.template, dictionary.at,
  35463. dictionary.refinementTemplate, dictionary.refinementAt,
  35464. decodingContext);
  35465. },
  35466. onImmediateTextRegion:
  35467. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  35468. referredSegments,
  35469. data, start, end) {
  35470. var regionInfo = region.info;
  35471. var huffmanTables;
  35472. // Combines exported symbols from all referred segments
  35473. var symbols = this.symbols;
  35474. var inputSymbols = [];
  35475. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  35476. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  35477. }
  35478. var symbolCodeLength = log2(inputSymbols.length);
  35479. var decodingContext = new DecodingContext(data, start, end);
  35480. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  35481. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  35482. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  35483. symbolCodeLength, region.transposed, region.dsOffset,
  35484. region.referenceCorner, region.combinationOperator, huffmanTables,
  35485. region.refinementTemplate, region.refinementAt, decodingContext);
  35486. this.drawBitmap(regionInfo, bitmap);
  35487. },
  35488. onImmediateLosslessTextRegion:
  35489. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  35490. this.onImmediateTextRegion.apply(this, arguments);
  35491. }
  35492. };
  35493. function Jbig2Image() {}
  35494. Jbig2Image.prototype = {
  35495. parseChunks: function Jbig2Image_parseChunks(chunks) {
  35496. return parseJbig2Chunks(chunks);
  35497. }
  35498. };
  35499. return Jbig2Image;
  35500. })();
  35501. var bidi = PDFJS.bidi = (function bidiClosure() {
  35502. // Character types for symbols from 0000 to 00FF.
  35503. var baseTypes = [
  35504. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  35505. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35506. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  35507. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  35508. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  35509. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35510. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  35511. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35512. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35513. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  35514. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35515. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35516. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  35517. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  35518. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35519. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35520. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35521. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35522. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  35523. ];
  35524. // Character types for symbols from 0600 to 06FF
  35525. var arabicTypes = [
  35526. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35527. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  35528. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35529. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35530. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35531. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35532. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  35533. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  35534. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  35535. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  35536. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35537. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35538. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35539. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35540. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35541. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35542. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35543. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35544. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  35545. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  35546. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35547. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  35548. ];
  35549. function isOdd(i) {
  35550. return (i & 1) !== 0;
  35551. }
  35552. function isEven(i) {
  35553. return (i & 1) === 0;
  35554. }
  35555. function findUnequal(arr, start, value) {
  35556. for (var j = start, jj = arr.length; j < jj; ++j) {
  35557. if (arr[j] !== value) {
  35558. return j;
  35559. }
  35560. }
  35561. return j;
  35562. }
  35563. function setValues(arr, start, end, value) {
  35564. for (var j = start; j < end; ++j) {
  35565. arr[j] = value;
  35566. }
  35567. }
  35568. function reverseValues(arr, start, end) {
  35569. for (var i = start, j = end - 1; i < j; ++i, --j) {
  35570. var temp = arr[i];
  35571. arr[i] = arr[j];
  35572. arr[j] = temp;
  35573. }
  35574. }
  35575. function createBidiText(str, isLTR, vertical) {
  35576. return {
  35577. str: str,
  35578. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  35579. };
  35580. }
  35581. // These are used in bidi(), which is called frequently. We re-use them on
  35582. // each call to avoid unnecessary allocations.
  35583. var chars = [];
  35584. var types = [];
  35585. function bidi(str, startLevel, vertical) {
  35586. var isLTR = true;
  35587. var strLength = str.length;
  35588. if (strLength === 0 || vertical) {
  35589. return createBidiText(str, isLTR, vertical);
  35590. }
  35591. // Get types and fill arrays
  35592. chars.length = strLength;
  35593. types.length = strLength;
  35594. var numBidi = 0;
  35595. var i, ii;
  35596. for (i = 0; i < strLength; ++i) {
  35597. chars[i] = str.charAt(i);
  35598. var charCode = str.charCodeAt(i);
  35599. var charType = 'L';
  35600. if (charCode <= 0x00ff) {
  35601. charType = baseTypes[charCode];
  35602. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  35603. charType = 'R';
  35604. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  35605. charType = arabicTypes[charCode & 0xff];
  35606. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  35607. charType = 'AL';
  35608. }
  35609. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  35610. numBidi++;
  35611. }
  35612. types[i] = charType;
  35613. }
  35614. // Detect the bidi method
  35615. // - If there are no rtl characters then no bidi needed
  35616. // - If less than 30% chars are rtl then string is primarily ltr
  35617. // - If more than 30% chars are rtl then string is primarily rtl
  35618. if (numBidi === 0) {
  35619. isLTR = true;
  35620. return createBidiText(str, isLTR);
  35621. }
  35622. if (startLevel === -1) {
  35623. if ((strLength / numBidi) < 0.3) {
  35624. isLTR = true;
  35625. startLevel = 0;
  35626. } else {
  35627. isLTR = false;
  35628. startLevel = 1;
  35629. }
  35630. }
  35631. var levels = [];
  35632. for (i = 0; i < strLength; ++i) {
  35633. levels[i] = startLevel;
  35634. }
  35635. /*
  35636. X1-X10: skip most of this, since we are NOT doing the embeddings.
  35637. */
  35638. var e = (isOdd(startLevel) ? 'R' : 'L');
  35639. var sor = e;
  35640. var eor = sor;
  35641. /*
  35642. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  35643. type of the NSM to the type of the previous character. If the NSM is at the
  35644. start of the level run, it will get the type of sor.
  35645. */
  35646. var lastType = sor;
  35647. for (i = 0; i < strLength; ++i) {
  35648. if (types[i] === 'NSM') {
  35649. types[i] = lastType;
  35650. } else {
  35651. lastType = types[i];
  35652. }
  35653. }
  35654. /*
  35655. W2. Search backwards from each instance of a European number until the
  35656. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  35657. the type of the European number to Arabic number.
  35658. */
  35659. lastType = sor;
  35660. var t;
  35661. for (i = 0; i < strLength; ++i) {
  35662. t = types[i];
  35663. if (t === 'EN') {
  35664. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  35665. } else if (t === 'R' || t === 'L' || t === 'AL') {
  35666. lastType = t;
  35667. }
  35668. }
  35669. /*
  35670. W3. Change all ALs to R.
  35671. */
  35672. for (i = 0; i < strLength; ++i) {
  35673. t = types[i];
  35674. if (t === 'AL') {
  35675. types[i] = 'R';
  35676. }
  35677. }
  35678. /*
  35679. W4. A single European separator between two European numbers changes to a
  35680. European number. A single common separator between two numbers of the same
  35681. type changes to that type:
  35682. */
  35683. for (i = 1; i < strLength - 1; ++i) {
  35684. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  35685. types[i] = 'EN';
  35686. }
  35687. if (types[i] === 'CS' &&
  35688. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  35689. types[i + 1] === types[i - 1]) {
  35690. types[i] = types[i - 1];
  35691. }
  35692. }
  35693. /*
  35694. W5. A sequence of European terminators adjacent to European numbers changes
  35695. to all European numbers:
  35696. */
  35697. for (i = 0; i < strLength; ++i) {
  35698. if (types[i] === 'EN') {
  35699. // do before
  35700. var j;
  35701. for (j = i - 1; j >= 0; --j) {
  35702. if (types[j] !== 'ET') {
  35703. break;
  35704. }
  35705. types[j] = 'EN';
  35706. }
  35707. // do after
  35708. for (j = i + 1; j < strLength; --j) {
  35709. if (types[j] !== 'ET') {
  35710. break;
  35711. }
  35712. types[j] = 'EN';
  35713. }
  35714. }
  35715. }
  35716. /*
  35717. W6. Otherwise, separators and terminators change to Other Neutral:
  35718. */
  35719. for (i = 0; i < strLength; ++i) {
  35720. t = types[i];
  35721. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  35722. types[i] = 'ON';
  35723. }
  35724. }
  35725. /*
  35726. W7. Search backwards from each instance of a European number until the
  35727. first strong type (R, L, or sor) is found. If an L is found, then change
  35728. the type of the European number to L.
  35729. */
  35730. lastType = sor;
  35731. for (i = 0; i < strLength; ++i) {
  35732. t = types[i];
  35733. if (t === 'EN') {
  35734. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  35735. } else if (t === 'R' || t === 'L') {
  35736. lastType = t;
  35737. }
  35738. }
  35739. /*
  35740. N1. A sequence of neutrals takes the direction of the surrounding strong
  35741. text if the text on both sides has the same direction. European and Arabic
  35742. numbers are treated as though they were R. Start-of-level-run (sor) and
  35743. end-of-level-run (eor) are used at level run boundaries.
  35744. */
  35745. for (i = 0; i < strLength; ++i) {
  35746. if (types[i] === 'ON') {
  35747. var end = findUnequal(types, i + 1, 'ON');
  35748. var before = sor;
  35749. if (i > 0) {
  35750. before = types[i - 1];
  35751. }
  35752. var after = eor;
  35753. if (end + 1 < strLength) {
  35754. after = types[end + 1];
  35755. }
  35756. if (before !== 'L') {
  35757. before = 'R';
  35758. }
  35759. if (after !== 'L') {
  35760. after = 'R';
  35761. }
  35762. if (before === after) {
  35763. setValues(types, i, end, before);
  35764. }
  35765. i = end - 1; // reset to end (-1 so next iteration is ok)
  35766. }
  35767. }
  35768. /*
  35769. N2. Any remaining neutrals take the embedding direction.
  35770. */
  35771. for (i = 0; i < strLength; ++i) {
  35772. if (types[i] === 'ON') {
  35773. types[i] = e;
  35774. }
  35775. }
  35776. /*
  35777. I1. For all characters with an even (left-to-right) embedding direction,
  35778. those of type R go up one level and those of type AN or EN go up two
  35779. levels.
  35780. I2. For all characters with an odd (right-to-left) embedding direction,
  35781. those of type L, EN or AN go up one level.
  35782. */
  35783. for (i = 0; i < strLength; ++i) {
  35784. t = types[i];
  35785. if (isEven(levels[i])) {
  35786. if (t === 'R') {
  35787. levels[i] += 1;
  35788. } else if (t === 'AN' || t === 'EN') {
  35789. levels[i] += 2;
  35790. }
  35791. } else { // isOdd
  35792. if (t === 'L' || t === 'AN' || t === 'EN') {
  35793. levels[i] += 1;
  35794. }
  35795. }
  35796. }
  35797. /*
  35798. L1. On each line, reset the embedding level of the following characters to
  35799. the paragraph embedding level:
  35800. segment separators,
  35801. paragraph separators,
  35802. any sequence of whitespace characters preceding a segment separator or
  35803. paragraph separator, and any sequence of white space characters at the end
  35804. of the line.
  35805. */
  35806. // don't bother as text is only single line
  35807. /*
  35808. L2. From the highest level found in the text to the lowest odd level on
  35809. each line, reverse any contiguous sequence of characters that are at that
  35810. level or higher.
  35811. */
  35812. // find highest level & lowest odd level
  35813. var highestLevel = -1;
  35814. var lowestOddLevel = 99;
  35815. var level;
  35816. for (i = 0, ii = levels.length; i < ii; ++i) {
  35817. level = levels[i];
  35818. if (highestLevel < level) {
  35819. highestLevel = level;
  35820. }
  35821. if (lowestOddLevel > level && isOdd(level)) {
  35822. lowestOddLevel = level;
  35823. }
  35824. }
  35825. // now reverse between those limits
  35826. for (level = highestLevel; level >= lowestOddLevel; --level) {
  35827. // find segments to reverse
  35828. var start = -1;
  35829. for (i = 0, ii = levels.length; i < ii; ++i) {
  35830. if (levels[i] < level) {
  35831. if (start >= 0) {
  35832. reverseValues(chars, start, i);
  35833. start = -1;
  35834. }
  35835. } else if (start < 0) {
  35836. start = i;
  35837. }
  35838. }
  35839. if (start >= 0) {
  35840. reverseValues(chars, start, levels.length);
  35841. }
  35842. }
  35843. /*
  35844. L3. Combining marks applied to a right-to-left base character will at this
  35845. point precede their base character. If the rendering engine expects them to
  35846. follow the base characters in the final display process, then the ordering
  35847. of the marks and the base character must be reversed.
  35848. */
  35849. // don't bother for now
  35850. /*
  35851. L4. A character that possesses the mirrored property as specified by
  35852. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  35853. directionality of that character is R.
  35854. */
  35855. // don't mirror as characters are already mirrored in the pdf
  35856. // Finally, return string
  35857. var result = '';
  35858. for (i = 0, ii = chars.length; i < ii; ++i) {
  35859. var ch = chars[i];
  35860. if (ch !== '<' && ch !== '>') {
  35861. result += ch;
  35862. }
  35863. }
  35864. return createBidiText(result, isLTR);
  35865. }
  35866. return bidi;
  35867. })();
  35868. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  35869. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  35870. /* Copyright 2014 Opera Software ASA
  35871. *
  35872. * Licensed under the Apache License, Version 2.0 (the "License");
  35873. * you may not use this file except in compliance with the License.
  35874. * You may obtain a copy of the License at
  35875. *
  35876. * http://www.apache.org/licenses/LICENSE-2.0
  35877. *
  35878. * Unless required by applicable law or agreed to in writing, software
  35879. * distributed under the License is distributed on an "AS IS" BASIS,
  35880. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  35881. * See the License for the specific language governing permissions and
  35882. * limitations under the License.
  35883. *
  35884. *
  35885. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  35886. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  35887. */
  35888. /* globals Uint32ArrayView */
  35889. 'use strict';
  35890. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  35891. // Workaround for missing math precison in JS.
  35892. var MASK_HIGH = 0xffff0000;
  35893. var MASK_LOW = 0xffff;
  35894. function MurmurHash3_64 (seed) {
  35895. var SEED = 0xc3d2e1f0;
  35896. this.h1 = seed ? seed & 0xffffffff : SEED;
  35897. this.h2 = seed ? seed & 0xffffffff : SEED;
  35898. }
  35899. var alwaysUseUint32ArrayView = false;
  35900. // old webkits have issues with non-aligned arrays
  35901. try {
  35902. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  35903. } catch (e) {
  35904. alwaysUseUint32ArrayView = true;
  35905. }
  35906. MurmurHash3_64.prototype = {
  35907. update: function MurmurHash3_64_update(input) {
  35908. var useUint32ArrayView = alwaysUseUint32ArrayView;
  35909. var i;
  35910. if (typeof input === 'string') {
  35911. var data = new Uint8Array(input.length * 2);
  35912. var length = 0;
  35913. for (i = 0; i < input.length; i++) {
  35914. var code = input.charCodeAt(i);
  35915. if (code <= 0xff) {
  35916. data[length++] = code;
  35917. }
  35918. else {
  35919. data[length++] = code >>> 8;
  35920. data[length++] = code & 0xff;
  35921. }
  35922. }
  35923. } else if (input instanceof Uint8Array) {
  35924. data = input;
  35925. length = data.length;
  35926. } else if (typeof input === 'object' && ('length' in input)) {
  35927. // processing regular arrays as well, e.g. for IE9
  35928. data = input;
  35929. length = data.length;
  35930. useUint32ArrayView = true;
  35931. } else {
  35932. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  35933. 'Input must be a string or array.');
  35934. }
  35935. var blockCounts = length >> 2;
  35936. var tailLength = length - blockCounts * 4;
  35937. // we don't care about endianness here
  35938. var dataUint32 = useUint32ArrayView ?
  35939. new Uint32ArrayView(data, blockCounts) :
  35940. new Uint32Array(data.buffer, 0, blockCounts);
  35941. var k1 = 0;
  35942. var k2 = 0;
  35943. var h1 = this.h1;
  35944. var h2 = this.h2;
  35945. var C1 = 0xcc9e2d51;
  35946. var C2 = 0x1b873593;
  35947. var C1_LOW = C1 & MASK_LOW;
  35948. var C2_LOW = C2 & MASK_LOW;
  35949. for (i = 0; i < blockCounts; i++) {
  35950. if (i & 1) {
  35951. k1 = dataUint32[i];
  35952. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  35953. k1 = k1 << 15 | k1 >>> 17;
  35954. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  35955. h1 ^= k1;
  35956. h1 = h1 << 13 | h1 >>> 19;
  35957. h1 = h1 * 5 + 0xe6546b64;
  35958. } else {
  35959. k2 = dataUint32[i];
  35960. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  35961. k2 = k2 << 15 | k2 >>> 17;
  35962. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  35963. h2 ^= k2;
  35964. h2 = h2 << 13 | h2 >>> 19;
  35965. h2 = h2 * 5 + 0xe6546b64;
  35966. }
  35967. }
  35968. k1 = 0;
  35969. switch (tailLength) {
  35970. case 3:
  35971. k1 ^= data[blockCounts * 4 + 2] << 16;
  35972. /* falls through */
  35973. case 2:
  35974. k1 ^= data[blockCounts * 4 + 1] << 8;
  35975. /* falls through */
  35976. case 1:
  35977. k1 ^= data[blockCounts * 4];
  35978. /* falls through */
  35979. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  35980. k1 = k1 << 15 | k1 >>> 17;
  35981. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  35982. if (blockCounts & 1) {
  35983. h1 ^= k1;
  35984. } else {
  35985. h2 ^= k1;
  35986. }
  35987. }
  35988. this.h1 = h1;
  35989. this.h2 = h2;
  35990. return this;
  35991. },
  35992. hexdigest: function MurmurHash3_64_hexdigest () {
  35993. var h1 = this.h1;
  35994. var h2 = this.h2;
  35995. h1 ^= h2 >>> 1;
  35996. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  35997. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  35998. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  35999. h1 ^= h2 >>> 1;
  36000. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36001. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36002. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36003. h1 ^= h2 >>> 1;
  36004. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36005. var hex = (arr[i] >>> 0).toString(16);
  36006. while (hex.length < 8) {
  36007. hex = '0' + hex;
  36008. }
  36009. str += hex;
  36010. }
  36011. return str;
  36012. }
  36013. };
  36014. return MurmurHash3_64;
  36015. })();
  36016. }).call((typeof window === 'undefined') ? this : window);
  36017. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36018. // workerSrc is not set -- using last script url to define default location
  36019. PDFJS.workerSrc = (function () {
  36020. 'use strict';
  36021. var scriptTagContainer = document.body ||
  36022. document.getElementsByTagName('head')[0];
  36023. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36024. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36025. })();
  36026. }