pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547
  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.884';
  24. PDFJS.build = 'fb6d87c';
  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 array = new Uint8Array(length);
  1469. for (var i = 0; i < length; i++) {
  1470. array[i] = data.charCodeAt(i) & 0xFF;
  1471. }
  1472. return array.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_requestFull(listeners) {
  1486. return this.request(listeners);
  1487. },
  1488. request: function NetworkManager_request(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. if (args.onProgressiveData) {
  1511. xhr.responseType = 'moz-chunked-arraybuffer';
  1512. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1513. pendingRequest.onProgressiveData = args.onProgressiveData;
  1514. pendingRequest.mozChunked = true;
  1515. } else {
  1516. xhr.responseType = 'arraybuffer';
  1517. }
  1518. } else {
  1519. xhr.responseType = 'arraybuffer';
  1520. }
  1521. if (args.onError) {
  1522. xhr.onerror = function(evt) {
  1523. args.onError(xhr.status);
  1524. };
  1525. }
  1526. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1527. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1528. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1529. pendingRequest.onDone = args.onDone;
  1530. pendingRequest.onError = args.onError;
  1531. pendingRequest.onProgress = args.onProgress;
  1532. xhr.send(null);
  1533. return xhrId;
  1534. },
  1535. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1536. var pendingRequest = this.pendingRequests[xhrId];
  1537. if (!pendingRequest) {
  1538. // Maybe abortRequest was called...
  1539. return;
  1540. }
  1541. if (pendingRequest.mozChunked) {
  1542. var chunk = getArrayBuffer(pendingRequest.xhr);
  1543. pendingRequest.onProgressiveData(chunk);
  1544. }
  1545. var onProgress = pendingRequest.onProgress;
  1546. if (onProgress) {
  1547. onProgress(evt);
  1548. }
  1549. },
  1550. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1551. var pendingRequest = this.pendingRequests[xhrId];
  1552. if (!pendingRequest) {
  1553. // Maybe abortRequest was called...
  1554. return;
  1555. }
  1556. var xhr = pendingRequest.xhr;
  1557. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1558. pendingRequest.onHeadersReceived();
  1559. delete pendingRequest.onHeadersReceived;
  1560. }
  1561. if (xhr.readyState !== 4) {
  1562. return;
  1563. }
  1564. if (!(xhrId in this.pendingRequests)) {
  1565. // The XHR request might have been aborted in onHeadersReceived()
  1566. // callback, in which case we should abort request
  1567. return;
  1568. }
  1569. delete this.pendingRequests[xhrId];
  1570. // success status == 0 can be on ftp, file and other protocols
  1571. if (xhr.status === 0 && this.isHttp) {
  1572. if (pendingRequest.onError) {
  1573. pendingRequest.onError(xhr.status);
  1574. }
  1575. return;
  1576. }
  1577. var xhrStatus = xhr.status || OK_RESPONSE;
  1578. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1579. // "A server MAY ignore the Range header". This means it's possible to
  1580. // get a 200 rather than a 206 response from a range request.
  1581. var ok_response_on_range_request =
  1582. xhrStatus === OK_RESPONSE &&
  1583. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1584. if (!ok_response_on_range_request &&
  1585. xhrStatus !== pendingRequest.expectedStatus) {
  1586. if (pendingRequest.onError) {
  1587. pendingRequest.onError(xhr.status);
  1588. }
  1589. return;
  1590. }
  1591. this.loadedRequests[xhrId] = true;
  1592. var chunk = getArrayBuffer(xhr);
  1593. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1594. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1595. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1596. var begin = parseInt(matches[1], 10);
  1597. pendingRequest.onDone({
  1598. begin: begin,
  1599. chunk: chunk
  1600. });
  1601. } else if (pendingRequest.onProgressiveData) {
  1602. pendingRequest.onDone(null);
  1603. } else {
  1604. pendingRequest.onDone({
  1605. begin: 0,
  1606. chunk: chunk
  1607. });
  1608. }
  1609. },
  1610. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1611. for (var xhrId in this.pendingRequests) {
  1612. return true;
  1613. }
  1614. return false;
  1615. },
  1616. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1617. return this.pendingRequests[xhrId].xhr;
  1618. },
  1619. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1620. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1621. },
  1622. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1623. return xhrId in this.pendingRequests;
  1624. },
  1625. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1626. return xhrId in this.loadedRequests;
  1627. },
  1628. abortAllRequests: function NetworkManager_abortAllRequests() {
  1629. for (var xhrId in this.pendingRequests) {
  1630. this.abortRequest(xhrId | 0);
  1631. }
  1632. },
  1633. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1634. var xhr = this.pendingRequests[xhrId].xhr;
  1635. delete this.pendingRequests[xhrId];
  1636. xhr.abort();
  1637. }
  1638. };
  1639. return NetworkManager;
  1640. })();
  1641. var ChunkedStream = (function ChunkedStreamClosure() {
  1642. function ChunkedStream(length, chunkSize, manager) {
  1643. this.bytes = new Uint8Array(length);
  1644. this.start = 0;
  1645. this.pos = 0;
  1646. this.end = length;
  1647. this.chunkSize = chunkSize;
  1648. this.loadedChunks = [];
  1649. this.numChunksLoaded = 0;
  1650. this.numChunks = Math.ceil(length / chunkSize);
  1651. this.manager = manager;
  1652. this.progressiveDataLength = 0;
  1653. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1654. }
  1655. // required methods for a stream. if a particular stream does not
  1656. // implement these, an error should be thrown
  1657. ChunkedStream.prototype = {
  1658. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1659. var chunks = [];
  1660. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1661. if (!this.loadedChunks[chunk]) {
  1662. chunks.push(chunk);
  1663. }
  1664. }
  1665. return chunks;
  1666. },
  1667. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1668. return [this];
  1669. },
  1670. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1671. return this.numChunksLoaded === this.numChunks;
  1672. },
  1673. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1674. var end = begin + chunk.byteLength;
  1675. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1676. // Using this.length is inaccurate here since this.start can be moved
  1677. // See ChunkedStream.moveStart()
  1678. var length = this.bytes.length;
  1679. assert(end % this.chunkSize === 0 || end === length,
  1680. 'Bad end offset: ' + end);
  1681. this.bytes.set(new Uint8Array(chunk), begin);
  1682. var chunkSize = this.chunkSize;
  1683. var beginChunk = Math.floor(begin / chunkSize);
  1684. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1685. var curChunk;
  1686. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1687. if (!this.loadedChunks[curChunk]) {
  1688. this.loadedChunks[curChunk] = true;
  1689. ++this.numChunksLoaded;
  1690. }
  1691. }
  1692. },
  1693. onReceiveProgressiveData:
  1694. function ChunkedStream_onReceiveProgressiveData(data) {
  1695. var position = this.progressiveDataLength;
  1696. var beginChunk = Math.floor(position / this.chunkSize);
  1697. this.bytes.set(new Uint8Array(data), position);
  1698. position += data.byteLength;
  1699. this.progressiveDataLength = position;
  1700. var endChunk = position >= this.end ? this.numChunks :
  1701. Math.floor(position / this.chunkSize);
  1702. var curChunk;
  1703. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1704. if (!this.loadedChunks[curChunk]) {
  1705. this.loadedChunks[curChunk] = true;
  1706. ++this.numChunksLoaded;
  1707. }
  1708. }
  1709. },
  1710. ensureByte: function ChunkedStream_ensureByte(pos) {
  1711. var chunk = Math.floor(pos / this.chunkSize);
  1712. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1713. return;
  1714. }
  1715. if (!this.loadedChunks[chunk]) {
  1716. throw new MissingDataException(pos, pos + 1);
  1717. }
  1718. this.lastSuccessfulEnsureByteChunk = chunk;
  1719. },
  1720. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1721. if (begin >= end) {
  1722. return;
  1723. }
  1724. if (end <= this.progressiveDataLength) {
  1725. return;
  1726. }
  1727. var chunkSize = this.chunkSize;
  1728. var beginChunk = Math.floor(begin / chunkSize);
  1729. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1730. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1731. if (!this.loadedChunks[chunk]) {
  1732. throw new MissingDataException(begin, end);
  1733. }
  1734. }
  1735. },
  1736. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1737. var chunk, n;
  1738. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1739. if (!this.loadedChunks[chunk]) {
  1740. return chunk;
  1741. }
  1742. }
  1743. // Wrap around to beginning
  1744. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1745. if (!this.loadedChunks[chunk]) {
  1746. return chunk;
  1747. }
  1748. }
  1749. return null;
  1750. },
  1751. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1752. return !!this.loadedChunks[chunk];
  1753. },
  1754. get length() {
  1755. return this.end - this.start;
  1756. },
  1757. get isEmpty() {
  1758. return this.length === 0;
  1759. },
  1760. getByte: function ChunkedStream_getByte() {
  1761. var pos = this.pos;
  1762. if (pos >= this.end) {
  1763. return -1;
  1764. }
  1765. this.ensureByte(pos);
  1766. return this.bytes[this.pos++];
  1767. },
  1768. getUint16: function ChunkedStream_getUint16() {
  1769. var b0 = this.getByte();
  1770. var b1 = this.getByte();
  1771. return (b0 << 8) + b1;
  1772. },
  1773. getInt32: function ChunkedStream_getInt32() {
  1774. var b0 = this.getByte();
  1775. var b1 = this.getByte();
  1776. var b2 = this.getByte();
  1777. var b3 = this.getByte();
  1778. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1779. },
  1780. // returns subarray of original buffer
  1781. // should only be read
  1782. getBytes: function ChunkedStream_getBytes(length) {
  1783. var bytes = this.bytes;
  1784. var pos = this.pos;
  1785. var strEnd = this.end;
  1786. if (!length) {
  1787. this.ensureRange(pos, strEnd);
  1788. return bytes.subarray(pos, strEnd);
  1789. }
  1790. var end = pos + length;
  1791. if (end > strEnd) {
  1792. end = strEnd;
  1793. }
  1794. this.ensureRange(pos, end);
  1795. this.pos = end;
  1796. return bytes.subarray(pos, end);
  1797. },
  1798. peekByte: function ChunkedStream_peekByte() {
  1799. var peekedByte = this.getByte();
  1800. this.pos--;
  1801. return peekedByte;
  1802. },
  1803. peekBytes: function ChunkedStream_peekBytes(length) {
  1804. var bytes = this.getBytes(length);
  1805. this.pos -= bytes.length;
  1806. return bytes;
  1807. },
  1808. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1809. this.ensureRange(begin, end);
  1810. return this.bytes.subarray(begin, end);
  1811. },
  1812. skip: function ChunkedStream_skip(n) {
  1813. if (!n) {
  1814. n = 1;
  1815. }
  1816. this.pos += n;
  1817. },
  1818. reset: function ChunkedStream_reset() {
  1819. this.pos = this.start;
  1820. },
  1821. moveStart: function ChunkedStream_moveStart() {
  1822. this.start = this.pos;
  1823. },
  1824. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1825. this.ensureRange(start, start + length);
  1826. function ChunkedStreamSubstream() {}
  1827. ChunkedStreamSubstream.prototype = Object.create(this);
  1828. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1829. var chunkSize = this.chunkSize;
  1830. var beginChunk = Math.floor(this.start / chunkSize);
  1831. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1832. var missingChunks = [];
  1833. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1834. if (!this.loadedChunks[chunk]) {
  1835. missingChunks.push(chunk);
  1836. }
  1837. }
  1838. return missingChunks;
  1839. };
  1840. var subStream = new ChunkedStreamSubstream();
  1841. subStream.pos = subStream.start = start;
  1842. subStream.end = start + length || this.end;
  1843. subStream.dict = dict;
  1844. return subStream;
  1845. },
  1846. isStream: true
  1847. };
  1848. return ChunkedStream;
  1849. })();
  1850. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1851. function ChunkedStreamManager(length, chunkSize, url, args) {
  1852. this.stream = new ChunkedStream(length, chunkSize, this);
  1853. this.length = length;
  1854. this.chunkSize = chunkSize;
  1855. this.url = url;
  1856. this.disableAutoFetch = args.disableAutoFetch;
  1857. var msgHandler = this.msgHandler = args.msgHandler;
  1858. if (args.chunkedViewerLoading) {
  1859. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1860. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1861. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1862. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1863. };
  1864. } else {
  1865. var getXhr = function getXhr() {
  1866. return new XMLHttpRequest();
  1867. };
  1868. this.networkManager = new NetworkManager(this.url, {
  1869. getXhr: getXhr,
  1870. httpHeaders: args.httpHeaders,
  1871. withCredentials: args.withCredentials
  1872. });
  1873. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1874. this.networkManager.requestRange(begin, end, {
  1875. onDone: this.onReceiveData.bind(this),
  1876. onProgress: this.onProgress.bind(this)
  1877. });
  1878. };
  1879. }
  1880. this.currRequestId = 0;
  1881. this.chunksNeededByRequest = {};
  1882. this.requestsByChunk = {};
  1883. this.callbacksByRequest = {};
  1884. this.progressiveDataLength = 0;
  1885. this._loadedStreamCapability = createPromiseCapability();
  1886. if (args.initialData) {
  1887. this.onReceiveData({chunk: args.initialData});
  1888. }
  1889. }
  1890. ChunkedStreamManager.prototype = {
  1891. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1892. return this._loadedStreamCapability.promise;
  1893. },
  1894. // Get all the chunks that are not yet loaded and groups them into
  1895. // contiguous ranges to load in as few requests as possible
  1896. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1897. var missingChunks = this.stream.getMissingChunks();
  1898. this.requestChunks(missingChunks);
  1899. return this._loadedStreamCapability.promise;
  1900. },
  1901. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1902. callback) {
  1903. var requestId = this.currRequestId++;
  1904. var chunksNeeded;
  1905. var i, ii;
  1906. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1907. for (i = 0, ii = chunks.length; i < ii; i++) {
  1908. if (!this.stream.hasChunk(chunks[i])) {
  1909. chunksNeeded[chunks[i]] = true;
  1910. }
  1911. }
  1912. if (isEmptyObj(chunksNeeded)) {
  1913. if (callback) {
  1914. callback();
  1915. }
  1916. return;
  1917. }
  1918. this.callbacksByRequest[requestId] = callback;
  1919. var chunksToRequest = [];
  1920. for (var chunk in chunksNeeded) {
  1921. chunk = chunk | 0;
  1922. if (!(chunk in this.requestsByChunk)) {
  1923. this.requestsByChunk[chunk] = [];
  1924. chunksToRequest.push(chunk);
  1925. }
  1926. this.requestsByChunk[chunk].push(requestId);
  1927. }
  1928. if (!chunksToRequest.length) {
  1929. return;
  1930. }
  1931. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1932. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1933. var groupedChunk = groupedChunksToRequest[i];
  1934. var begin = groupedChunk.beginChunk * this.chunkSize;
  1935. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1936. this.sendRequest(begin, end);
  1937. }
  1938. },
  1939. getStream: function ChunkedStreamManager_getStream() {
  1940. return this.stream;
  1941. },
  1942. // Loads any chunks in the requested range that are not yet loaded
  1943. requestRange: function ChunkedStreamManager_requestRange(
  1944. begin, end, callback) {
  1945. end = Math.min(end, this.length);
  1946. var beginChunk = this.getBeginChunk(begin);
  1947. var endChunk = this.getEndChunk(end);
  1948. var chunks = [];
  1949. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1950. chunks.push(chunk);
  1951. }
  1952. this.requestChunks(chunks, callback);
  1953. },
  1954. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1955. callback) {
  1956. ranges = ranges || [];
  1957. var chunksToRequest = [];
  1958. for (var i = 0; i < ranges.length; i++) {
  1959. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1960. var endChunk = this.getEndChunk(ranges[i].end);
  1961. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1962. if (chunksToRequest.indexOf(chunk) < 0) {
  1963. chunksToRequest.push(chunk);
  1964. }
  1965. }
  1966. }
  1967. chunksToRequest.sort(function(a, b) { return a - b; });
  1968. this.requestChunks(chunksToRequest, callback);
  1969. },
  1970. // Groups a sorted array of chunks into as few continguous larger
  1971. // chunks as possible
  1972. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1973. var groupedChunks = [];
  1974. var beginChunk = -1;
  1975. var prevChunk = -1;
  1976. for (var i = 0; i < chunks.length; ++i) {
  1977. var chunk = chunks[i];
  1978. if (beginChunk < 0) {
  1979. beginChunk = chunk;
  1980. }
  1981. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1982. groupedChunks.push({ beginChunk: beginChunk,
  1983. endChunk: prevChunk + 1 });
  1984. beginChunk = chunk;
  1985. }
  1986. if (i + 1 === chunks.length) {
  1987. groupedChunks.push({ beginChunk: beginChunk,
  1988. endChunk: chunk + 1 });
  1989. }
  1990. prevChunk = chunk;
  1991. }
  1992. return groupedChunks;
  1993. },
  1994. onProgress: function ChunkedStreamManager_onProgress(args) {
  1995. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1996. args.loaded);
  1997. this.msgHandler.send('DocProgress', {
  1998. loaded: bytesLoaded,
  1999. total: this.length
  2000. });
  2001. },
  2002. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2003. var chunk = args.chunk;
  2004. var isProgressive = args.begin === undefined;
  2005. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2006. var end = begin + chunk.byteLength;
  2007. var beginChunk = Math.floor(begin / this.chunkSize);
  2008. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2009. Math.ceil(end / this.chunkSize);
  2010. if (isProgressive) {
  2011. this.stream.onReceiveProgressiveData(chunk);
  2012. this.progressiveDataLength = end;
  2013. } else {
  2014. this.stream.onReceiveData(begin, chunk);
  2015. }
  2016. if (this.stream.allChunksLoaded()) {
  2017. this._loadedStreamCapability.resolve(this.stream);
  2018. }
  2019. var loadedRequests = [];
  2020. var i, requestId;
  2021. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2022. // The server might return more chunks than requested
  2023. var requestIds = this.requestsByChunk[chunk] || [];
  2024. delete this.requestsByChunk[chunk];
  2025. for (i = 0; i < requestIds.length; ++i) {
  2026. requestId = requestIds[i];
  2027. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2028. if (chunk in chunksNeeded) {
  2029. delete chunksNeeded[chunk];
  2030. }
  2031. if (!isEmptyObj(chunksNeeded)) {
  2032. continue;
  2033. }
  2034. loadedRequests.push(requestId);
  2035. }
  2036. }
  2037. // If there are no pending requests, automatically fetch the next
  2038. // unfetched chunk of the PDF
  2039. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2040. var nextEmptyChunk;
  2041. if (this.stream.numChunksLoaded === 1) {
  2042. // This is a special optimization so that after fetching the first
  2043. // chunk, rather than fetching the second chunk, we fetch the last
  2044. // chunk.
  2045. var lastChunk = this.stream.numChunks - 1;
  2046. if (!this.stream.hasChunk(lastChunk)) {
  2047. nextEmptyChunk = lastChunk;
  2048. }
  2049. } else {
  2050. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2051. }
  2052. if (isInt(nextEmptyChunk)) {
  2053. this.requestChunks([nextEmptyChunk]);
  2054. }
  2055. }
  2056. for (i = 0; i < loadedRequests.length; ++i) {
  2057. requestId = loadedRequests[i];
  2058. var callback = this.callbacksByRequest[requestId];
  2059. delete this.callbacksByRequest[requestId];
  2060. if (callback) {
  2061. callback();
  2062. }
  2063. }
  2064. this.msgHandler.send('DocProgress', {
  2065. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2066. total: this.length
  2067. });
  2068. },
  2069. onError: function ChunkedStreamManager_onError(err) {
  2070. this._loadedStreamCapability.reject(err);
  2071. },
  2072. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2073. var chunk = Math.floor(begin / this.chunkSize);
  2074. return chunk;
  2075. },
  2076. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2077. if (end % this.chunkSize === 0) {
  2078. return end / this.chunkSize;
  2079. }
  2080. // 0 -> 0
  2081. // 1 -> 1
  2082. // 99 -> 1
  2083. // 100 -> 1
  2084. // 101 -> 2
  2085. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2086. return chunk;
  2087. }
  2088. };
  2089. return ChunkedStreamManager;
  2090. })();
  2091. // The maximum number of bytes fetched per range request
  2092. var RANGE_CHUNK_SIZE = 65536;
  2093. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2094. var BasePdfManager = (function BasePdfManagerClosure() {
  2095. function BasePdfManager() {
  2096. throw new Error('Cannot initialize BaseManagerManager');
  2097. }
  2098. BasePdfManager.prototype = {
  2099. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2100. throw new NotImplementedException();
  2101. },
  2102. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2103. return this.ensure(this.pdfDocument, prop, args);
  2104. },
  2105. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2106. return this.ensure(this.pdfDocument.xref, prop, args);
  2107. },
  2108. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2109. return this.ensure(this.pdfDocument.catalog, prop, args);
  2110. },
  2111. getPage: function BasePdfManager_pagePage(pageIndex) {
  2112. return this.pdfDocument.getPage(pageIndex);
  2113. },
  2114. cleanup: function BasePdfManager_cleanup() {
  2115. return this.pdfDocument.cleanup();
  2116. },
  2117. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2118. return new NotImplementedException();
  2119. },
  2120. requestRange: function BasePdfManager_ensure(begin, end) {
  2121. return new NotImplementedException();
  2122. },
  2123. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2124. return new NotImplementedException();
  2125. },
  2126. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2127. return new NotImplementedException();
  2128. },
  2129. updatePassword: function BasePdfManager_updatePassword(password) {
  2130. this.pdfDocument.xref.password = this.password = password;
  2131. if (this._passwordChangedCapability) {
  2132. this._passwordChangedCapability.resolve();
  2133. }
  2134. },
  2135. passwordChanged: function BasePdfManager_passwordChanged() {
  2136. this._passwordChangedCapability = createPromiseCapability();
  2137. return this._passwordChangedCapability.promise;
  2138. },
  2139. terminate: function BasePdfManager_terminate() {
  2140. return new NotImplementedException();
  2141. }
  2142. };
  2143. return BasePdfManager;
  2144. })();
  2145. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2146. function LocalPdfManager(data, password) {
  2147. var stream = new Stream(data);
  2148. this.pdfDocument = new PDFDocument(this, stream, password);
  2149. this._loadedStreamCapability = createPromiseCapability();
  2150. this._loadedStreamCapability.resolve(stream);
  2151. }
  2152. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2153. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2154. LocalPdfManager.prototype.ensure =
  2155. function LocalPdfManager_ensure(obj, prop, args) {
  2156. return new Promise(function (resolve, reject) {
  2157. try {
  2158. var value = obj[prop];
  2159. var result;
  2160. if (typeof value === 'function') {
  2161. result = value.apply(obj, args);
  2162. } else {
  2163. result = value;
  2164. }
  2165. resolve(result);
  2166. } catch (e) {
  2167. reject(e);
  2168. }
  2169. });
  2170. };
  2171. LocalPdfManager.prototype.requestRange =
  2172. function LocalPdfManager_requestRange(begin, end) {
  2173. return Promise.resolve();
  2174. };
  2175. LocalPdfManager.prototype.requestLoadedStream =
  2176. function LocalPdfManager_requestLoadedStream() {
  2177. };
  2178. LocalPdfManager.prototype.onLoadedStream =
  2179. function LocalPdfManager_getLoadedStream() {
  2180. return this._loadedStreamCapability.promise;
  2181. };
  2182. LocalPdfManager.prototype.terminate =
  2183. function LocalPdfManager_terminate() {
  2184. return;
  2185. };
  2186. return LocalPdfManager;
  2187. })();
  2188. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2189. function NetworkPdfManager(args, msgHandler) {
  2190. this.msgHandler = msgHandler;
  2191. var params = {
  2192. msgHandler: msgHandler,
  2193. httpHeaders: args.httpHeaders,
  2194. withCredentials: args.withCredentials,
  2195. chunkedViewerLoading: args.chunkedViewerLoading,
  2196. disableAutoFetch: args.disableAutoFetch,
  2197. initialData: args.initialData
  2198. };
  2199. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2200. args.url, params);
  2201. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2202. args.password);
  2203. }
  2204. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2205. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2206. NetworkPdfManager.prototype.ensure =
  2207. function NetworkPdfManager_ensure(obj, prop, args) {
  2208. var pdfManager = this;
  2209. return new Promise(function (resolve, reject) {
  2210. function ensureHelper() {
  2211. try {
  2212. var result;
  2213. var value = obj[prop];
  2214. if (typeof value === 'function') {
  2215. result = value.apply(obj, args);
  2216. } else {
  2217. result = value;
  2218. }
  2219. resolve(result);
  2220. } catch(e) {
  2221. if (!(e instanceof MissingDataException)) {
  2222. reject(e);
  2223. return;
  2224. }
  2225. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2226. }
  2227. }
  2228. ensureHelper();
  2229. });
  2230. };
  2231. NetworkPdfManager.prototype.requestRange =
  2232. function NetworkPdfManager_requestRange(begin, end) {
  2233. return new Promise(function (resolve) {
  2234. this.streamManager.requestRange(begin, end, function() {
  2235. resolve();
  2236. });
  2237. }.bind(this));
  2238. };
  2239. NetworkPdfManager.prototype.requestLoadedStream =
  2240. function NetworkPdfManager_requestLoadedStream() {
  2241. this.streamManager.requestAllChunks();
  2242. };
  2243. NetworkPdfManager.prototype.sendProgressiveData =
  2244. function NetworkPdfManager_sendProgressiveData(chunk) {
  2245. this.streamManager.onReceiveData({ chunk: chunk });
  2246. };
  2247. NetworkPdfManager.prototype.onLoadedStream =
  2248. function NetworkPdfManager_getLoadedStream() {
  2249. return this.streamManager.onLoadedStream();
  2250. };
  2251. NetworkPdfManager.prototype.terminate =
  2252. function NetworkPdfManager_terminate() {
  2253. this.streamManager.networkManager.abortAllRequests();
  2254. };
  2255. return NetworkPdfManager;
  2256. })();
  2257. var Page = (function PageClosure() {
  2258. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2259. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2260. this.pdfManager = pdfManager;
  2261. this.pageIndex = pageIndex;
  2262. this.pageDict = pageDict;
  2263. this.xref = xref;
  2264. this.ref = ref;
  2265. this.fontCache = fontCache;
  2266. this.idCounters = {
  2267. obj: 0
  2268. };
  2269. this.resourcesPromise = null;
  2270. }
  2271. Page.prototype = {
  2272. getPageProp: function Page_getPageProp(key) {
  2273. return this.pageDict.get(key);
  2274. },
  2275. getInheritedPageProp: function Page_inheritPageProp(key) {
  2276. var dict = this.pageDict;
  2277. var value = dict.get(key);
  2278. while (value === undefined) {
  2279. dict = dict.get('Parent');
  2280. if (!dict) {
  2281. break;
  2282. }
  2283. value = dict.get(key);
  2284. }
  2285. return value;
  2286. },
  2287. get content() {
  2288. return this.getPageProp('Contents');
  2289. },
  2290. get resources() {
  2291. var value = this.getInheritedPageProp('Resources');
  2292. // For robustness: The spec states that a \Resources entry has to be
  2293. // present, but can be empty. Some document omit it still. In this case
  2294. // return an empty dictionary:
  2295. if (value === undefined) {
  2296. value = Dict.empty;
  2297. }
  2298. return shadow(this, 'resources', value);
  2299. },
  2300. get mediaBox() {
  2301. var obj = this.getInheritedPageProp('MediaBox');
  2302. // Reset invalid media box to letter size.
  2303. if (!isArray(obj) || obj.length !== 4) {
  2304. obj = LETTER_SIZE_MEDIABOX;
  2305. }
  2306. return shadow(this, 'mediaBox', obj);
  2307. },
  2308. get view() {
  2309. var mediaBox = this.mediaBox;
  2310. var cropBox = this.getInheritedPageProp('CropBox');
  2311. if (!isArray(cropBox) || cropBox.length !== 4) {
  2312. return shadow(this, 'view', mediaBox);
  2313. }
  2314. // From the spec, 6th ed., p.963:
  2315. // "The crop, bleed, trim, and art boxes should not ordinarily
  2316. // extend beyond the boundaries of the media box. If they do, they are
  2317. // effectively reduced to their intersection with the media box."
  2318. cropBox = Util.intersect(cropBox, mediaBox);
  2319. if (!cropBox) {
  2320. return shadow(this, 'view', mediaBox);
  2321. }
  2322. return shadow(this, 'view', cropBox);
  2323. },
  2324. get annotationRefs() {
  2325. return shadow(this, 'annotationRefs',
  2326. this.getInheritedPageProp('Annots'));
  2327. },
  2328. get rotate() {
  2329. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2330. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2331. if (rotate % 90 !== 0) {
  2332. rotate = 0;
  2333. } else if (rotate >= 360) {
  2334. rotate = rotate % 360;
  2335. } else if (rotate < 0) {
  2336. // The spec doesn't cover negatives, assume its counterclockwise
  2337. // rotation. The following is the other implementation of modulo.
  2338. rotate = ((rotate % 360) + 360) % 360;
  2339. }
  2340. return shadow(this, 'rotate', rotate);
  2341. },
  2342. getContentStream: function Page_getContentStream() {
  2343. var content = this.content;
  2344. var stream;
  2345. if (isArray(content)) {
  2346. // fetching items
  2347. var xref = this.xref;
  2348. var i, n = content.length;
  2349. var streams = [];
  2350. for (i = 0; i < n; ++i) {
  2351. streams.push(xref.fetchIfRef(content[i]));
  2352. }
  2353. stream = new StreamsSequenceStream(streams);
  2354. } else if (isStream(content)) {
  2355. stream = content;
  2356. } else {
  2357. // replacing non-existent page content with empty one
  2358. stream = new NullStream();
  2359. }
  2360. return stream;
  2361. },
  2362. loadResources: function Page_loadResources(keys) {
  2363. if (!this.resourcesPromise) {
  2364. // TODO: add async getInheritedPageProp and remove this.
  2365. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2366. }
  2367. return this.resourcesPromise.then(function resourceSuccess() {
  2368. var objectLoader = new ObjectLoader(this.resources.map,
  2369. keys,
  2370. this.xref);
  2371. return objectLoader.load();
  2372. }.bind(this));
  2373. },
  2374. getOperatorList: function Page_getOperatorList(handler, intent) {
  2375. var self = this;
  2376. var pdfManager = this.pdfManager;
  2377. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2378. []);
  2379. var resourcesPromise = this.loadResources([
  2380. 'ExtGState',
  2381. 'ColorSpace',
  2382. 'Pattern',
  2383. 'Shading',
  2384. 'XObject',
  2385. 'Font'
  2386. // ProcSet
  2387. // Properties
  2388. ]);
  2389. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2390. handler, this.pageIndex,
  2391. 'p' + this.pageIndex + '_',
  2392. this.idCounters,
  2393. this.fontCache);
  2394. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2395. var pageListPromise = dataPromises.then(function(data) {
  2396. var contentStream = data[0];
  2397. var opList = new OperatorList(intent, handler, self.pageIndex);
  2398. handler.send('StartRenderPage', {
  2399. transparency: partialEvaluator.hasBlendModes(self.resources),
  2400. pageIndex: self.pageIndex,
  2401. intent: intent
  2402. });
  2403. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2404. opList).then(function () {
  2405. return opList;
  2406. });
  2407. });
  2408. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2409. return Promise.all([pageListPromise, annotationsPromise]).then(
  2410. function(datas) {
  2411. var pageOpList = datas[0];
  2412. var annotations = datas[1];
  2413. if (annotations.length === 0) {
  2414. pageOpList.flush(true);
  2415. return pageOpList;
  2416. }
  2417. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2418. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2419. return annotationsReadyPromise.then(function () {
  2420. pageOpList.flush(true);
  2421. return pageOpList;
  2422. });
  2423. });
  2424. },
  2425. extractTextContent: function Page_extractTextContent() {
  2426. var handler = {
  2427. on: function nullHandlerOn() {},
  2428. send: function nullHandlerSend() {}
  2429. };
  2430. var self = this;
  2431. var pdfManager = this.pdfManager;
  2432. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2433. []);
  2434. var resourcesPromise = this.loadResources([
  2435. 'ExtGState',
  2436. 'XObject',
  2437. 'Font'
  2438. ]);
  2439. var dataPromises = Promise.all([contentStreamPromise,
  2440. resourcesPromise]);
  2441. return dataPromises.then(function(data) {
  2442. var contentStream = data[0];
  2443. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2444. handler, self.pageIndex,
  2445. 'p' + self.pageIndex + '_',
  2446. self.idCounters,
  2447. self.fontCache);
  2448. return partialEvaluator.getTextContent(contentStream,
  2449. self.resources);
  2450. });
  2451. },
  2452. getAnnotationsData: function Page_getAnnotationsData() {
  2453. var annotations = this.annotations;
  2454. var annotationsData = [];
  2455. for (var i = 0, n = annotations.length; i < n; ++i) {
  2456. annotationsData.push(annotations[i].getData());
  2457. }
  2458. return annotationsData;
  2459. },
  2460. get annotations() {
  2461. var annotations = [];
  2462. var annotationRefs = (this.annotationRefs || []);
  2463. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2464. var annotationRef = annotationRefs[i];
  2465. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2466. if (annotation) {
  2467. annotations.push(annotation);
  2468. }
  2469. }
  2470. return shadow(this, 'annotations', annotations);
  2471. }
  2472. };
  2473. return Page;
  2474. })();
  2475. /**
  2476. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2477. * `PDFDoc`, this one doesn't have any job management code.
  2478. * Right now there exists one PDFDocument on the main thread + one object
  2479. * for each worker. If there is no worker support enabled, there are two
  2480. * `PDFDocument` objects on the main thread created.
  2481. */
  2482. var PDFDocument = (function PDFDocumentClosure() {
  2483. function PDFDocument(pdfManager, arg, password) {
  2484. if (isStream(arg)) {
  2485. init.call(this, pdfManager, arg, password);
  2486. } else if (isArrayBuffer(arg)) {
  2487. init.call(this, pdfManager, new Stream(arg), password);
  2488. } else {
  2489. error('PDFDocument: Unknown argument type');
  2490. }
  2491. }
  2492. function init(pdfManager, stream, password) {
  2493. assert(stream.length > 0, 'stream must have data');
  2494. this.pdfManager = pdfManager;
  2495. this.stream = stream;
  2496. var xref = new XRef(this.stream, password, pdfManager);
  2497. this.xref = xref;
  2498. }
  2499. function find(stream, needle, limit, backwards) {
  2500. var pos = stream.pos;
  2501. var end = stream.end;
  2502. var strBuf = [];
  2503. if (pos + limit > end) {
  2504. limit = end - pos;
  2505. }
  2506. for (var n = 0; n < limit; ++n) {
  2507. strBuf.push(String.fromCharCode(stream.getByte()));
  2508. }
  2509. var str = strBuf.join('');
  2510. stream.pos = pos;
  2511. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2512. if (index === -1) {
  2513. return false; /* not found */
  2514. }
  2515. stream.pos += index;
  2516. return true; /* found */
  2517. }
  2518. var DocumentInfoValidators = {
  2519. get entries() {
  2520. // Lazily build this since all the validation functions below are not
  2521. // defined until after this file loads.
  2522. return shadow(this, 'entries', {
  2523. Title: isString,
  2524. Author: isString,
  2525. Subject: isString,
  2526. Keywords: isString,
  2527. Creator: isString,
  2528. Producer: isString,
  2529. CreationDate: isString,
  2530. ModDate: isString,
  2531. Trapped: isName
  2532. });
  2533. }
  2534. };
  2535. PDFDocument.prototype = {
  2536. parse: function PDFDocument_parse(recoveryMode) {
  2537. this.setup(recoveryMode);
  2538. try {
  2539. // checking if AcroForm is present
  2540. this.acroForm = this.catalog.catDict.get('AcroForm');
  2541. if (this.acroForm) {
  2542. this.xfa = this.acroForm.get('XFA');
  2543. var fields = this.acroForm.get('Fields');
  2544. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2545. !this.xfa) {
  2546. // no fields and no XFA -- not a form (?)
  2547. this.acroForm = null;
  2548. }
  2549. }
  2550. } catch (ex) {
  2551. info('Something wrong with AcroForm entry');
  2552. this.acroForm = null;
  2553. }
  2554. },
  2555. get linearization() {
  2556. var linearization = null;
  2557. if (this.stream.length) {
  2558. try {
  2559. linearization = Linearization.create(this.stream);
  2560. } catch (err) {
  2561. if (err instanceof MissingDataException) {
  2562. throw err;
  2563. }
  2564. info(err);
  2565. }
  2566. }
  2567. // shadow the prototype getter with a data property
  2568. return shadow(this, 'linearization', linearization);
  2569. },
  2570. get startXRef() {
  2571. var stream = this.stream;
  2572. var startXRef = 0;
  2573. var linearization = this.linearization;
  2574. if (linearization) {
  2575. // Find end of first obj.
  2576. stream.reset();
  2577. if (find(stream, 'endobj', 1024)) {
  2578. startXRef = stream.pos + 6;
  2579. }
  2580. } else {
  2581. // Find startxref by jumping backward from the end of the file.
  2582. var step = 1024;
  2583. var found = false, pos = stream.end;
  2584. while (!found && pos > 0) {
  2585. pos -= step - 'startxref'.length;
  2586. if (pos < 0) {
  2587. pos = 0;
  2588. }
  2589. stream.pos = pos;
  2590. found = find(stream, 'startxref', step, true);
  2591. }
  2592. if (found) {
  2593. stream.skip(9);
  2594. var ch;
  2595. do {
  2596. ch = stream.getByte();
  2597. } while (Lexer.isSpace(ch));
  2598. var str = '';
  2599. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2600. str += String.fromCharCode(ch);
  2601. ch = stream.getByte();
  2602. }
  2603. startXRef = parseInt(str, 10);
  2604. if (isNaN(startXRef)) {
  2605. startXRef = 0;
  2606. }
  2607. }
  2608. }
  2609. // shadow the prototype getter with a data property
  2610. return shadow(this, 'startXRef', startXRef);
  2611. },
  2612. get mainXRefEntriesOffset() {
  2613. var mainXRefEntriesOffset = 0;
  2614. var linearization = this.linearization;
  2615. if (linearization) {
  2616. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2617. }
  2618. // shadow the prototype getter with a data property
  2619. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2620. },
  2621. // Find the header, remove leading garbage and setup the stream
  2622. // starting from the header.
  2623. checkHeader: function PDFDocument_checkHeader() {
  2624. var stream = this.stream;
  2625. stream.reset();
  2626. if (find(stream, '%PDF-', 1024)) {
  2627. // Found the header, trim off any garbage before it.
  2628. stream.moveStart();
  2629. // Reading file format version
  2630. var MAX_VERSION_LENGTH = 12;
  2631. var version = '', ch;
  2632. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2633. if (version.length >= MAX_VERSION_LENGTH) {
  2634. break;
  2635. }
  2636. version += String.fromCharCode(ch);
  2637. }
  2638. // removing "%PDF-"-prefix
  2639. this.pdfFormatVersion = version.substring(5);
  2640. return;
  2641. }
  2642. // May not be a PDF file, continue anyway.
  2643. },
  2644. parseStartXRef: function PDFDocument_parseStartXRef() {
  2645. var startXRef = this.startXRef;
  2646. this.xref.setStartXRef(startXRef);
  2647. },
  2648. setup: function PDFDocument_setup(recoveryMode) {
  2649. this.xref.parse(recoveryMode);
  2650. this.catalog = new Catalog(this.pdfManager, this.xref);
  2651. },
  2652. get numPages() {
  2653. var linearization = this.linearization;
  2654. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2655. // shadow the prototype getter
  2656. return shadow(this, 'numPages', num);
  2657. },
  2658. get documentInfo() {
  2659. var docInfo = {
  2660. PDFFormatVersion: this.pdfFormatVersion,
  2661. IsAcroFormPresent: !!this.acroForm,
  2662. IsXFAPresent: !!this.xfa
  2663. };
  2664. var infoDict;
  2665. try {
  2666. infoDict = this.xref.trailer.get('Info');
  2667. } catch (err) {
  2668. info('The document information dictionary is invalid.');
  2669. }
  2670. if (infoDict) {
  2671. var validEntries = DocumentInfoValidators.entries;
  2672. // Only fill the document info with valid entries from the spec.
  2673. for (var key in validEntries) {
  2674. if (infoDict.has(key)) {
  2675. var value = infoDict.get(key);
  2676. // Make sure the value conforms to the spec.
  2677. if (validEntries[key](value)) {
  2678. docInfo[key] = (typeof value !== 'string' ?
  2679. value : stringToPDFString(value));
  2680. } else {
  2681. info('Bad value in document info for "' + key + '"');
  2682. }
  2683. }
  2684. }
  2685. }
  2686. return shadow(this, 'documentInfo', docInfo);
  2687. },
  2688. get fingerprint() {
  2689. var xref = this.xref, hash, fileID = '';
  2690. if (xref.trailer.has('ID')) {
  2691. hash = stringToBytes(xref.trailer.get('ID')[0]);
  2692. } else {
  2693. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  2694. }
  2695. for (var i = 0, n = hash.length; i < n; i++) {
  2696. fileID += hash[i].toString(16);
  2697. }
  2698. return shadow(this, 'fingerprint', fileID);
  2699. },
  2700. getPage: function PDFDocument_getPage(pageIndex) {
  2701. return this.catalog.getPage(pageIndex);
  2702. },
  2703. cleanup: function PDFDocument_cleanup() {
  2704. return this.catalog.cleanup();
  2705. }
  2706. };
  2707. return PDFDocument;
  2708. })();
  2709. var Name = (function NameClosure() {
  2710. function Name(name) {
  2711. this.name = name;
  2712. }
  2713. Name.prototype = {};
  2714. var nameCache = {};
  2715. Name.get = function Name_get(name) {
  2716. var nameValue = nameCache[name];
  2717. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2718. };
  2719. return Name;
  2720. })();
  2721. var Cmd = (function CmdClosure() {
  2722. function Cmd(cmd) {
  2723. this.cmd = cmd;
  2724. }
  2725. Cmd.prototype = {};
  2726. var cmdCache = {};
  2727. Cmd.get = function Cmd_get(cmd) {
  2728. var cmdValue = cmdCache[cmd];
  2729. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2730. };
  2731. return Cmd;
  2732. })();
  2733. var Dict = (function DictClosure() {
  2734. var nonSerializable = function nonSerializableClosure() {
  2735. return nonSerializable; // creating closure on some variable
  2736. };
  2737. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2738. 'Background': true,
  2739. 'ExtGState': true,
  2740. 'Halftone': true,
  2741. 'Layout': true,
  2742. 'Mask': true,
  2743. 'Pagination': true,
  2744. 'Printing': true
  2745. };
  2746. function isRecursionAllowedFor(dict) {
  2747. if (!isName(dict.Type)) {
  2748. return true;
  2749. }
  2750. var dictType = dict.Type.name;
  2751. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2752. }
  2753. // xref is optional
  2754. function Dict(xref) {
  2755. // Map should only be used internally, use functions below to access.
  2756. this.map = Object.create(null);
  2757. this.xref = xref;
  2758. this.objId = null;
  2759. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2760. }
  2761. Dict.prototype = {
  2762. assignXref: function Dict_assignXref(newXref) {
  2763. this.xref = newXref;
  2764. },
  2765. // automatically dereferences Ref objects
  2766. get: function Dict_get(key1, key2, key3) {
  2767. var value;
  2768. var xref = this.xref;
  2769. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2770. typeof key2 === 'undefined') {
  2771. return xref ? xref.fetchIfRef(value) : value;
  2772. }
  2773. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2774. typeof key3 === 'undefined') {
  2775. return xref ? xref.fetchIfRef(value) : value;
  2776. }
  2777. value = this.map[key3] || null;
  2778. return xref ? xref.fetchIfRef(value) : value;
  2779. },
  2780. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2781. getAsync: function Dict_getAsync(key1, key2, key3) {
  2782. var value;
  2783. var xref = this.xref;
  2784. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2785. typeof key2 === 'undefined') {
  2786. if (xref) {
  2787. return xref.fetchIfRefAsync(value);
  2788. }
  2789. return Promise.resolve(value);
  2790. }
  2791. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2792. typeof key3 === 'undefined') {
  2793. if (xref) {
  2794. return xref.fetchIfRefAsync(value);
  2795. }
  2796. return Promise.resolve(value);
  2797. }
  2798. value = this.map[key3] || null;
  2799. if (xref) {
  2800. return xref.fetchIfRefAsync(value);
  2801. }
  2802. return Promise.resolve(value);
  2803. },
  2804. // no dereferencing
  2805. getRaw: function Dict_getRaw(key) {
  2806. return this.map[key];
  2807. },
  2808. // creates new map and dereferences all Refs
  2809. getAll: function Dict_getAll() {
  2810. var all = Object.create(null);
  2811. var queue = null;
  2812. var key, obj;
  2813. for (key in this.map) {
  2814. obj = this.get(key);
  2815. if (obj instanceof Dict) {
  2816. if (isRecursionAllowedFor(obj)) {
  2817. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2818. } else {
  2819. all[key] = this.getRaw(key);
  2820. }
  2821. } else {
  2822. all[key] = obj;
  2823. }
  2824. }
  2825. if (!queue) {
  2826. return all;
  2827. }
  2828. // trying to take cyclic references into the account
  2829. var processed = Object.create(null);
  2830. while (queue.length > 0) {
  2831. var item = queue.shift();
  2832. var itemObj = item.obj;
  2833. var objId = itemObj.objId;
  2834. if (objId && objId in processed) {
  2835. item.target[item.key] = processed[objId];
  2836. continue;
  2837. }
  2838. var dereferenced = Object.create(null);
  2839. for (key in itemObj.map) {
  2840. obj = itemObj.get(key);
  2841. if (obj instanceof Dict) {
  2842. if (isRecursionAllowedFor(obj)) {
  2843. queue.push({target: dereferenced, key: key, obj: obj});
  2844. } else {
  2845. dereferenced[key] = itemObj.getRaw(key);
  2846. }
  2847. } else {
  2848. dereferenced[key] = obj;
  2849. }
  2850. }
  2851. if (objId) {
  2852. processed[objId] = dereferenced;
  2853. }
  2854. item.target[item.key] = dereferenced;
  2855. }
  2856. return all;
  2857. },
  2858. set: function Dict_set(key, value) {
  2859. this.map[key] = value;
  2860. },
  2861. has: function Dict_has(key) {
  2862. return key in this.map;
  2863. },
  2864. forEach: function Dict_forEach(callback) {
  2865. for (var key in this.map) {
  2866. callback(key, this.get(key));
  2867. }
  2868. }
  2869. };
  2870. Dict.empty = new Dict(null);
  2871. return Dict;
  2872. })();
  2873. var Ref = (function RefClosure() {
  2874. function Ref(num, gen) {
  2875. this.num = num;
  2876. this.gen = gen;
  2877. }
  2878. Ref.prototype = {
  2879. toString: function Ref_toString() {
  2880. // This function is hot, so we make the string as compact as possible.
  2881. // |this.gen| is almost always zero, so we treat that case specially.
  2882. var str = this.num + 'R';
  2883. if (this.gen !== 0) {
  2884. str += this.gen;
  2885. }
  2886. return str;
  2887. }
  2888. };
  2889. return Ref;
  2890. })();
  2891. // The reference is identified by number and generation.
  2892. // This structure stores only one instance of the reference.
  2893. var RefSet = (function RefSetClosure() {
  2894. function RefSet() {
  2895. this.dict = {};
  2896. }
  2897. RefSet.prototype = {
  2898. has: function RefSet_has(ref) {
  2899. return ref.toString() in this.dict;
  2900. },
  2901. put: function RefSet_put(ref) {
  2902. this.dict[ref.toString()] = true;
  2903. },
  2904. remove: function RefSet_remove(ref) {
  2905. delete this.dict[ref.toString()];
  2906. }
  2907. };
  2908. return RefSet;
  2909. })();
  2910. var RefSetCache = (function RefSetCacheClosure() {
  2911. function RefSetCache() {
  2912. this.dict = Object.create(null);
  2913. }
  2914. RefSetCache.prototype = {
  2915. get: function RefSetCache_get(ref) {
  2916. return this.dict[ref.toString()];
  2917. },
  2918. has: function RefSetCache_has(ref) {
  2919. return ref.toString() in this.dict;
  2920. },
  2921. put: function RefSetCache_put(ref, obj) {
  2922. this.dict[ref.toString()] = obj;
  2923. },
  2924. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2925. this.dict[ref.toString()] = this.get(aliasRef);
  2926. },
  2927. forEach: function RefSetCache_forEach(fn, thisArg) {
  2928. for (var i in this.dict) {
  2929. fn.call(thisArg, this.dict[i]);
  2930. }
  2931. },
  2932. clear: function RefSetCache_clear() {
  2933. this.dict = Object.create(null);
  2934. }
  2935. };
  2936. return RefSetCache;
  2937. })();
  2938. var Catalog = (function CatalogClosure() {
  2939. function Catalog(pdfManager, xref) {
  2940. this.pdfManager = pdfManager;
  2941. this.xref = xref;
  2942. this.catDict = xref.getCatalogObj();
  2943. this.fontCache = new RefSetCache();
  2944. assert(isDict(this.catDict),
  2945. 'catalog object is not a dictionary');
  2946. this.pagePromises = [];
  2947. }
  2948. Catalog.prototype = {
  2949. get metadata() {
  2950. var streamRef = this.catDict.getRaw('Metadata');
  2951. if (!isRef(streamRef)) {
  2952. return shadow(this, 'metadata', null);
  2953. }
  2954. var encryptMetadata = (!this.xref.encrypt ? false :
  2955. this.xref.encrypt.encryptMetadata);
  2956. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2957. var metadata;
  2958. if (stream && isDict(stream.dict)) {
  2959. var type = stream.dict.get('Type');
  2960. var subtype = stream.dict.get('Subtype');
  2961. if (isName(type) && isName(subtype) &&
  2962. type.name === 'Metadata' && subtype.name === 'XML') {
  2963. // XXX: This should examine the charset the XML document defines,
  2964. // however since there are currently no real means to decode
  2965. // arbitrary charsets, let's just hope that the author of the PDF
  2966. // was reasonable enough to stick with the XML default charset,
  2967. // which is UTF-8.
  2968. try {
  2969. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2970. } catch (e) {
  2971. info('Skipping invalid metadata.');
  2972. }
  2973. }
  2974. }
  2975. return shadow(this, 'metadata', metadata);
  2976. },
  2977. get toplevelPagesDict() {
  2978. var pagesObj = this.catDict.get('Pages');
  2979. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2980. // shadow the prototype getter
  2981. return shadow(this, 'toplevelPagesDict', pagesObj);
  2982. },
  2983. get documentOutline() {
  2984. var obj = null;
  2985. try {
  2986. obj = this.readDocumentOutline();
  2987. } catch (ex) {
  2988. if (ex instanceof MissingDataException) {
  2989. throw ex;
  2990. }
  2991. warn('Unable to read document outline');
  2992. }
  2993. return shadow(this, 'documentOutline', obj);
  2994. },
  2995. readDocumentOutline: function Catalog_readDocumentOutline() {
  2996. var xref = this.xref;
  2997. var obj = this.catDict.get('Outlines');
  2998. var root = { items: [] };
  2999. if (isDict(obj)) {
  3000. obj = obj.getRaw('First');
  3001. var processed = new RefSet();
  3002. if (isRef(obj)) {
  3003. var queue = [{obj: obj, parent: root}];
  3004. // to avoid recursion keeping track of the items
  3005. // in the processed dictionary
  3006. processed.put(obj);
  3007. while (queue.length > 0) {
  3008. var i = queue.shift();
  3009. var outlineDict = xref.fetchIfRef(i.obj);
  3010. if (outlineDict === null) {
  3011. continue;
  3012. }
  3013. if (!outlineDict.has('Title')) {
  3014. error('Invalid outline item');
  3015. }
  3016. var dest = outlineDict.get('A');
  3017. if (dest) {
  3018. dest = dest.get('D');
  3019. } else if (outlineDict.has('Dest')) {
  3020. dest = outlineDict.getRaw('Dest');
  3021. if (isName(dest)) {
  3022. dest = dest.name;
  3023. }
  3024. }
  3025. var title = outlineDict.get('Title');
  3026. var outlineItem = {
  3027. dest: dest,
  3028. title: stringToPDFString(title),
  3029. color: outlineDict.get('C') || [0, 0, 0],
  3030. count: outlineDict.get('Count'),
  3031. bold: !!(outlineDict.get('F') & 2),
  3032. italic: !!(outlineDict.get('F') & 1),
  3033. items: []
  3034. };
  3035. i.parent.items.push(outlineItem);
  3036. obj = outlineDict.getRaw('First');
  3037. if (isRef(obj) && !processed.has(obj)) {
  3038. queue.push({obj: obj, parent: outlineItem});
  3039. processed.put(obj);
  3040. }
  3041. obj = outlineDict.getRaw('Next');
  3042. if (isRef(obj) && !processed.has(obj)) {
  3043. queue.push({obj: obj, parent: i.parent});
  3044. processed.put(obj);
  3045. }
  3046. }
  3047. }
  3048. }
  3049. return (root.items.length > 0 ? root.items : null);
  3050. },
  3051. get numPages() {
  3052. var obj = this.toplevelPagesDict.get('Count');
  3053. assert(
  3054. isInt(obj),
  3055. 'page count in top level pages object is not an integer'
  3056. );
  3057. // shadow the prototype getter
  3058. return shadow(this, 'num', obj);
  3059. },
  3060. get destinations() {
  3061. function fetchDestination(dest) {
  3062. return isDict(dest) ? dest.get('D') : dest;
  3063. }
  3064. var xref = this.xref;
  3065. var dests = {}, nameTreeRef, nameDictionaryRef;
  3066. var obj = this.catDict.get('Names');
  3067. if (obj && obj.has('Dests')) {
  3068. nameTreeRef = obj.getRaw('Dests');
  3069. } else if (this.catDict.has('Dests')) {
  3070. nameDictionaryRef = this.catDict.get('Dests');
  3071. }
  3072. if (nameDictionaryRef) {
  3073. // reading simple destination dictionary
  3074. obj = nameDictionaryRef;
  3075. obj.forEach(function catalogForEach(key, value) {
  3076. if (!value) {
  3077. return;
  3078. }
  3079. dests[key] = fetchDestination(value);
  3080. });
  3081. }
  3082. if (nameTreeRef) {
  3083. var nameTree = new NameTree(nameTreeRef, xref);
  3084. var names = nameTree.getAll();
  3085. for (var name in names) {
  3086. if (!names.hasOwnProperty(name)) {
  3087. continue;
  3088. }
  3089. dests[name] = fetchDestination(names[name]);
  3090. }
  3091. }
  3092. return shadow(this, 'destinations', dests);
  3093. },
  3094. get attachments() {
  3095. var xref = this.xref;
  3096. var attachments = null, nameTreeRef;
  3097. var obj = this.catDict.get('Names');
  3098. if (obj) {
  3099. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3100. }
  3101. if (nameTreeRef) {
  3102. var nameTree = new NameTree(nameTreeRef, xref);
  3103. var names = nameTree.getAll();
  3104. for (var name in names) {
  3105. if (!names.hasOwnProperty(name)) {
  3106. continue;
  3107. }
  3108. var fs = new FileSpec(names[name], xref);
  3109. if (!attachments) {
  3110. attachments = {};
  3111. }
  3112. attachments[stringToPDFString(name)] = fs.serializable;
  3113. }
  3114. }
  3115. return shadow(this, 'attachments', attachments);
  3116. },
  3117. get javaScript() {
  3118. var xref = this.xref;
  3119. var obj = this.catDict.get('Names');
  3120. var javaScript = [];
  3121. if (obj && obj.has('JavaScript')) {
  3122. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3123. var names = nameTree.getAll();
  3124. for (var name in names) {
  3125. if (!names.hasOwnProperty(name)) {
  3126. continue;
  3127. }
  3128. // We don't really use the JavaScript right now. This code is
  3129. // defensive so we don't cause errors on document load.
  3130. var jsDict = names[name];
  3131. if (!isDict(jsDict)) {
  3132. continue;
  3133. }
  3134. var type = jsDict.get('S');
  3135. if (!isName(type) || type.name !== 'JavaScript') {
  3136. continue;
  3137. }
  3138. var js = jsDict.get('JS');
  3139. if (!isString(js) && !isStream(js)) {
  3140. continue;
  3141. }
  3142. if (isStream(js)) {
  3143. js = bytesToString(js.getBytes());
  3144. }
  3145. javaScript.push(stringToPDFString(js));
  3146. }
  3147. }
  3148. // Append OpenAction actions to javaScript array
  3149. var openactionDict = this.catDict.get('OpenAction');
  3150. if (isDict(openactionDict)) {
  3151. var objType = openactionDict.get('Type');
  3152. var actionType = openactionDict.get('S');
  3153. var action = openactionDict.get('N');
  3154. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3155. isName(actionType) && actionType.name === 'Named' &&
  3156. isName(action) && action.name === 'Print');
  3157. if (isPrintAction) {
  3158. javaScript.push('print(true);');
  3159. }
  3160. }
  3161. return shadow(this, 'javaScript', javaScript);
  3162. },
  3163. cleanup: function Catalog_cleanup() {
  3164. var promises = [];
  3165. this.fontCache.forEach(function (promise) {
  3166. promises.push(promise);
  3167. });
  3168. return Promise.all(promises).then(function (translatedFonts) {
  3169. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3170. var font = translatedFonts[i].dict;
  3171. delete font.translated;
  3172. }
  3173. this.fontCache.clear();
  3174. }.bind(this));
  3175. },
  3176. getPage: function Catalog_getPage(pageIndex) {
  3177. if (!(pageIndex in this.pagePromises)) {
  3178. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3179. function (a) {
  3180. var dict = a[0];
  3181. var ref = a[1];
  3182. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3183. this.fontCache);
  3184. }.bind(this)
  3185. );
  3186. }
  3187. return this.pagePromises[pageIndex];
  3188. },
  3189. getPageDict: function Catalog_getPageDict(pageIndex) {
  3190. var capability = createPromiseCapability();
  3191. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3192. var currentPageIndex = 0;
  3193. var xref = this.xref;
  3194. function next() {
  3195. while (nodesToVisit.length) {
  3196. var currentNode = nodesToVisit.pop();
  3197. if (isRef(currentNode)) {
  3198. xref.fetchAsync(currentNode).then(function (obj) {
  3199. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3200. if (pageIndex === currentPageIndex) {
  3201. capability.resolve([obj, currentNode]);
  3202. } else {
  3203. currentPageIndex++;
  3204. next();
  3205. }
  3206. return;
  3207. }
  3208. nodesToVisit.push(obj);
  3209. next();
  3210. }, capability.reject);
  3211. return;
  3212. }
  3213. // must be a child page dictionary
  3214. assert(
  3215. isDict(currentNode),
  3216. 'page dictionary kid reference points to wrong type of object'
  3217. );
  3218. var count = currentNode.get('Count');
  3219. // Skip nodes where the page can't be.
  3220. if (currentPageIndex + count <= pageIndex) {
  3221. currentPageIndex += count;
  3222. continue;
  3223. }
  3224. var kids = currentNode.get('Kids');
  3225. assert(isArray(kids), 'page dictionary kids object is not an array');
  3226. if (count === kids.length) {
  3227. // Nodes that don't have the page have been skipped and this is the
  3228. // bottom of the tree which means the page requested must be a
  3229. // descendant of this pages node. Ideally we would just resolve the
  3230. // promise with the page ref here, but there is the case where more
  3231. // pages nodes could link to single a page (see issue 3666 pdf). To
  3232. // handle this push it back on the queue so if it is a pages node it
  3233. // will be descended into.
  3234. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3235. currentPageIndex = pageIndex;
  3236. continue;
  3237. } else {
  3238. for (var last = kids.length - 1; last >= 0; last--) {
  3239. nodesToVisit.push(kids[last]);
  3240. }
  3241. }
  3242. }
  3243. capability.reject('Page index ' + pageIndex + ' not found.');
  3244. }
  3245. next();
  3246. return capability.promise;
  3247. },
  3248. getPageIndex: function Catalog_getPageIndex(ref) {
  3249. // The page tree nodes have the count of all the leaves below them. To get
  3250. // how many pages are before we just have to walk up the tree and keep
  3251. // adding the count of siblings to the left of the node.
  3252. var xref = this.xref;
  3253. function pagesBeforeRef(kidRef) {
  3254. var total = 0;
  3255. var parentRef;
  3256. return xref.fetchAsync(kidRef).then(function (node) {
  3257. if (!node) {
  3258. return null;
  3259. }
  3260. parentRef = node.getRaw('Parent');
  3261. return node.getAsync('Parent');
  3262. }).then(function (parent) {
  3263. if (!parent) {
  3264. return null;
  3265. }
  3266. return parent.getAsync('Kids');
  3267. }).then(function (kids) {
  3268. if (!kids) {
  3269. return null;
  3270. }
  3271. var kidPromises = [];
  3272. var found = false;
  3273. for (var i = 0; i < kids.length; i++) {
  3274. var kid = kids[i];
  3275. assert(isRef(kid), 'kids must be a ref');
  3276. if (kid.num === kidRef.num) {
  3277. found = true;
  3278. break;
  3279. }
  3280. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3281. if (kid.has('Count')) {
  3282. var count = kid.get('Count');
  3283. total += count;
  3284. } else { // page leaf node
  3285. total++;
  3286. }
  3287. }));
  3288. }
  3289. if (!found) {
  3290. error('kid ref not found in parents kids');
  3291. }
  3292. return Promise.all(kidPromises).then(function () {
  3293. return [total, parentRef];
  3294. });
  3295. });
  3296. }
  3297. var total = 0;
  3298. function next(ref) {
  3299. return pagesBeforeRef(ref).then(function (args) {
  3300. if (!args) {
  3301. return total;
  3302. }
  3303. var count = args[0];
  3304. var parentRef = args[1];
  3305. total += count;
  3306. return next(parentRef);
  3307. });
  3308. }
  3309. return next(ref);
  3310. }
  3311. };
  3312. return Catalog;
  3313. })();
  3314. var XRef = (function XRefClosure() {
  3315. function XRef(stream, password) {
  3316. this.stream = stream;
  3317. this.entries = [];
  3318. this.xrefstms = {};
  3319. // prepare the XRef cache
  3320. this.cache = [];
  3321. this.password = password;
  3322. this.stats = {
  3323. streamTypes: [],
  3324. fontTypes: []
  3325. };
  3326. }
  3327. XRef.prototype = {
  3328. setStartXRef: function XRef_setStartXRef(startXRef) {
  3329. // Store the starting positions of xref tables as we process them
  3330. // so we can recover from missing data errors
  3331. this.startXRefQueue = [startXRef];
  3332. },
  3333. parse: function XRef_parse(recoveryMode) {
  3334. var trailerDict;
  3335. if (!recoveryMode) {
  3336. trailerDict = this.readXRef();
  3337. } else {
  3338. warn('Indexing all PDF objects');
  3339. trailerDict = this.indexObjects();
  3340. }
  3341. trailerDict.assignXref(this);
  3342. this.trailer = trailerDict;
  3343. var encrypt = trailerDict.get('Encrypt');
  3344. if (encrypt) {
  3345. var ids = trailerDict.get('ID');
  3346. var fileId = (ids && ids.length) ? ids[0] : '';
  3347. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3348. this.password);
  3349. }
  3350. // get the root dictionary (catalog) object
  3351. if (!(this.root = trailerDict.get('Root'))) {
  3352. error('Invalid root reference');
  3353. }
  3354. },
  3355. processXRefTable: function XRef_processXRefTable(parser) {
  3356. if (!('tableState' in this)) {
  3357. // Stores state of the table as we process it so we can resume
  3358. // from middle of table in case of missing data error
  3359. this.tableState = {
  3360. entryNum: 0,
  3361. streamPos: parser.lexer.stream.pos,
  3362. parserBuf1: parser.buf1,
  3363. parserBuf2: parser.buf2
  3364. };
  3365. }
  3366. var obj = this.readXRefTable(parser);
  3367. // Sanity check
  3368. if (!isCmd(obj, 'trailer')) {
  3369. error('Invalid XRef table: could not find trailer dictionary');
  3370. }
  3371. // Read trailer dictionary, e.g.
  3372. // trailer
  3373. // << /Size 22
  3374. // /Root 20R
  3375. // /Info 10R
  3376. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3377. // >>
  3378. // The parser goes through the entire stream << ... >> and provides
  3379. // a getter interface for the key-value table
  3380. var dict = parser.getObj();
  3381. // The pdflib PDF generator can generate a nested trailer dictionary
  3382. if (!isDict(dict) && dict.dict) {
  3383. dict = dict.dict;
  3384. }
  3385. if (!isDict(dict)) {
  3386. error('Invalid XRef table: could not parse trailer dictionary');
  3387. }
  3388. delete this.tableState;
  3389. return dict;
  3390. },
  3391. readXRefTable: function XRef_readXRefTable(parser) {
  3392. // Example of cross-reference table:
  3393. // xref
  3394. // 0 1 <-- subsection header (first obj #, obj count)
  3395. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3396. // 23 2 <-- subsection header ... and so on ...
  3397. // 0000025518 00002 n
  3398. // 0000025635 00000 n
  3399. // trailer
  3400. // ...
  3401. var stream = parser.lexer.stream;
  3402. var tableState = this.tableState;
  3403. stream.pos = tableState.streamPos;
  3404. parser.buf1 = tableState.parserBuf1;
  3405. parser.buf2 = tableState.parserBuf2;
  3406. // Outer loop is over subsection headers
  3407. var obj;
  3408. while (true) {
  3409. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3410. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3411. break;
  3412. }
  3413. tableState.firstEntryNum = obj;
  3414. tableState.entryCount = parser.getObj();
  3415. }
  3416. var first = tableState.firstEntryNum;
  3417. var count = tableState.entryCount;
  3418. if (!isInt(first) || !isInt(count)) {
  3419. error('Invalid XRef table: wrong types in subsection header');
  3420. }
  3421. // Inner loop is over objects themselves
  3422. for (var i = tableState.entryNum; i < count; i++) {
  3423. tableState.streamPos = stream.pos;
  3424. tableState.entryNum = i;
  3425. tableState.parserBuf1 = parser.buf1;
  3426. tableState.parserBuf2 = parser.buf2;
  3427. var entry = {};
  3428. entry.offset = parser.getObj();
  3429. entry.gen = parser.getObj();
  3430. var type = parser.getObj();
  3431. if (isCmd(type, 'f')) {
  3432. entry.free = true;
  3433. } else if (isCmd(type, 'n')) {
  3434. entry.uncompressed = true;
  3435. }
  3436. // Validate entry obj
  3437. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3438. !(entry.free || entry.uncompressed)) {
  3439. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3440. }
  3441. if (!this.entries[i + first]) {
  3442. this.entries[i + first] = entry;
  3443. }
  3444. }
  3445. tableState.entryNum = 0;
  3446. tableState.streamPos = stream.pos;
  3447. tableState.parserBuf1 = parser.buf1;
  3448. tableState.parserBuf2 = parser.buf2;
  3449. delete tableState.firstEntryNum;
  3450. delete tableState.entryCount;
  3451. }
  3452. // Per issue 3248: hp scanners generate bad XRef
  3453. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3454. // shifting the entries
  3455. this.entries.shift();
  3456. }
  3457. // Sanity check: as per spec, first object must be free
  3458. if (this.entries[0] && !this.entries[0].free) {
  3459. error('Invalid XRef table: unexpected first object');
  3460. }
  3461. return obj;
  3462. },
  3463. processXRefStream: function XRef_processXRefStream(stream) {
  3464. if (!('streamState' in this)) {
  3465. // Stores state of the stream as we process it so we can resume
  3466. // from middle of stream in case of missing data error
  3467. var streamParameters = stream.dict;
  3468. var byteWidths = streamParameters.get('W');
  3469. var range = streamParameters.get('Index');
  3470. if (!range) {
  3471. range = [0, streamParameters.get('Size')];
  3472. }
  3473. this.streamState = {
  3474. entryRanges: range,
  3475. byteWidths: byteWidths,
  3476. entryNum: 0,
  3477. streamPos: stream.pos
  3478. };
  3479. }
  3480. this.readXRefStream(stream);
  3481. delete this.streamState;
  3482. return stream.dict;
  3483. },
  3484. readXRefStream: function XRef_readXRefStream(stream) {
  3485. var i, j;
  3486. var streamState = this.streamState;
  3487. stream.pos = streamState.streamPos;
  3488. var byteWidths = streamState.byteWidths;
  3489. var typeFieldWidth = byteWidths[0];
  3490. var offsetFieldWidth = byteWidths[1];
  3491. var generationFieldWidth = byteWidths[2];
  3492. var entryRanges = streamState.entryRanges;
  3493. while (entryRanges.length > 0) {
  3494. var first = entryRanges[0];
  3495. var n = entryRanges[1];
  3496. if (!isInt(first) || !isInt(n)) {
  3497. error('Invalid XRef range fields: ' + first + ', ' + n);
  3498. }
  3499. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3500. !isInt(generationFieldWidth)) {
  3501. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3502. }
  3503. for (i = streamState.entryNum; i < n; ++i) {
  3504. streamState.entryNum = i;
  3505. streamState.streamPos = stream.pos;
  3506. var type = 0, offset = 0, generation = 0;
  3507. for (j = 0; j < typeFieldWidth; ++j) {
  3508. type = (type << 8) | stream.getByte();
  3509. }
  3510. // if type field is absent, its default value is 1
  3511. if (typeFieldWidth === 0) {
  3512. type = 1;
  3513. }
  3514. for (j = 0; j < offsetFieldWidth; ++j) {
  3515. offset = (offset << 8) | stream.getByte();
  3516. }
  3517. for (j = 0; j < generationFieldWidth; ++j) {
  3518. generation = (generation << 8) | stream.getByte();
  3519. }
  3520. var entry = {};
  3521. entry.offset = offset;
  3522. entry.gen = generation;
  3523. switch (type) {
  3524. case 0:
  3525. entry.free = true;
  3526. break;
  3527. case 1:
  3528. entry.uncompressed = true;
  3529. break;
  3530. case 2:
  3531. break;
  3532. default:
  3533. error('Invalid XRef entry type: ' + type);
  3534. }
  3535. if (!this.entries[first + i]) {
  3536. this.entries[first + i] = entry;
  3537. }
  3538. }
  3539. streamState.entryNum = 0;
  3540. streamState.streamPos = stream.pos;
  3541. entryRanges.splice(0, 2);
  3542. }
  3543. },
  3544. indexObjects: function XRef_indexObjects() {
  3545. // Simple scan through the PDF content to find objects,
  3546. // trailers and XRef streams.
  3547. function readToken(data, offset) {
  3548. var token = '', ch = data[offset];
  3549. while (ch !== 13 && ch !== 10) {
  3550. if (++offset >= data.length) {
  3551. break;
  3552. }
  3553. token += String.fromCharCode(ch);
  3554. ch = data[offset];
  3555. }
  3556. return token;
  3557. }
  3558. function skipUntil(data, offset, what) {
  3559. var length = what.length, dataLength = data.length;
  3560. var skipped = 0;
  3561. // finding byte sequence
  3562. while (offset < dataLength) {
  3563. var i = 0;
  3564. while (i < length && data[offset + i] === what[i]) {
  3565. ++i;
  3566. }
  3567. if (i >= length) {
  3568. break; // sequence found
  3569. }
  3570. offset++;
  3571. skipped++;
  3572. }
  3573. return skipped;
  3574. }
  3575. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3576. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3577. 101, 102]);
  3578. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3579. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3580. var stream = this.stream;
  3581. stream.pos = 0;
  3582. var buffer = stream.getBytes();
  3583. var position = stream.start, length = buffer.length;
  3584. var trailers = [], xrefStms = [];
  3585. while (position < length) {
  3586. var ch = buffer[position];
  3587. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3588. ++position;
  3589. continue;
  3590. }
  3591. if (ch === 37) { // %-comment
  3592. do {
  3593. ++position;
  3594. if (position >= length) {
  3595. break;
  3596. }
  3597. ch = buffer[position];
  3598. } while (ch !== 13 && ch !== 10);
  3599. continue;
  3600. }
  3601. var token = readToken(buffer, position);
  3602. var m;
  3603. if (token === 'xref') {
  3604. position += skipUntil(buffer, position, trailerBytes);
  3605. trailers.push(position);
  3606. position += skipUntil(buffer, position, startxrefBytes);
  3607. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3608. this.entries[m[1]] = {
  3609. offset: position,
  3610. gen: m[2] | 0,
  3611. uncompressed: true
  3612. };
  3613. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3614. var content = buffer.subarray(position, position + contentLength);
  3615. // checking XRef stream suspect
  3616. // (it shall have '/XRef' and next char is not a letter)
  3617. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3618. if (xrefTagOffset < contentLength &&
  3619. content[xrefTagOffset + 5] < 64) {
  3620. xrefStms.push(position);
  3621. this.xrefstms[position] = 1; // don't read it recursively
  3622. }
  3623. position += contentLength;
  3624. } else {
  3625. position += token.length + 1;
  3626. }
  3627. }
  3628. // reading XRef streams
  3629. var i, ii;
  3630. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3631. this.startXRefQueue.push(xrefStms[i]);
  3632. this.readXRef(/* recoveryMode */ true);
  3633. }
  3634. // finding main trailer
  3635. var dict;
  3636. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3637. stream.pos = trailers[i];
  3638. var parser = new Parser(new Lexer(stream), true, this);
  3639. var obj = parser.getObj();
  3640. if (!isCmd(obj, 'trailer')) {
  3641. continue;
  3642. }
  3643. // read the trailer dictionary
  3644. if (!isDict(dict = parser.getObj())) {
  3645. continue;
  3646. }
  3647. // taking the first one with 'ID'
  3648. if (dict.has('ID')) {
  3649. return dict;
  3650. }
  3651. }
  3652. // no tailer with 'ID', taking last one (if exists)
  3653. if (dict) {
  3654. return dict;
  3655. }
  3656. // nothing helps
  3657. // calling error() would reject worker with an UnknownErrorException.
  3658. throw new InvalidPDFException('Invalid PDF structure');
  3659. },
  3660. readXRef: function XRef_readXRef(recoveryMode) {
  3661. var stream = this.stream;
  3662. try {
  3663. while (this.startXRefQueue.length) {
  3664. var startXRef = this.startXRefQueue[0];
  3665. stream.pos = startXRef + stream.start;
  3666. var parser = new Parser(new Lexer(stream), true, this);
  3667. var obj = parser.getObj();
  3668. var dict;
  3669. // Get dictionary
  3670. if (isCmd(obj, 'xref')) {
  3671. // Parse end-of-file XRef
  3672. dict = this.processXRefTable(parser);
  3673. if (!this.topDict) {
  3674. this.topDict = dict;
  3675. }
  3676. // Recursively get other XRefs 'XRefStm', if any
  3677. obj = dict.get('XRefStm');
  3678. if (isInt(obj)) {
  3679. var pos = obj;
  3680. // ignore previously loaded xref streams
  3681. // (possible infinite recursion)
  3682. if (!(pos in this.xrefstms)) {
  3683. this.xrefstms[pos] = 1;
  3684. this.startXRefQueue.push(pos);
  3685. }
  3686. }
  3687. } else if (isInt(obj)) {
  3688. // Parse in-stream XRef
  3689. if (!isInt(parser.getObj()) ||
  3690. !isCmd(parser.getObj(), 'obj') ||
  3691. !isStream(obj = parser.getObj())) {
  3692. error('Invalid XRef stream');
  3693. }
  3694. dict = this.processXRefStream(obj);
  3695. if (!this.topDict) {
  3696. this.topDict = dict;
  3697. }
  3698. if (!dict) {
  3699. error('Failed to read XRef stream');
  3700. }
  3701. } else {
  3702. error('Invalid XRef stream header');
  3703. }
  3704. // Recursively get previous dictionary, if any
  3705. obj = dict.get('Prev');
  3706. if (isInt(obj)) {
  3707. this.startXRefQueue.push(obj);
  3708. } else if (isRef(obj)) {
  3709. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3710. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3711. this.startXRefQueue.push(obj.num);
  3712. }
  3713. this.startXRefQueue.shift();
  3714. }
  3715. return this.topDict;
  3716. } catch (e) {
  3717. if (e instanceof MissingDataException) {
  3718. throw e;
  3719. }
  3720. info('(while reading XRef): ' + e);
  3721. }
  3722. if (recoveryMode) {
  3723. return;
  3724. }
  3725. throw new XRefParseException();
  3726. },
  3727. getEntry: function XRef_getEntry(i) {
  3728. var xrefEntry = this.entries[i];
  3729. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3730. return xrefEntry;
  3731. }
  3732. return null;
  3733. },
  3734. fetchIfRef: function XRef_fetchIfRef(obj) {
  3735. if (!isRef(obj)) {
  3736. return obj;
  3737. }
  3738. return this.fetch(obj);
  3739. },
  3740. fetch: function XRef_fetch(ref, suppressEncryption) {
  3741. assert(isRef(ref), 'ref object is not a reference');
  3742. var num = ref.num;
  3743. if (num in this.cache) {
  3744. var cacheEntry = this.cache[num];
  3745. return cacheEntry;
  3746. }
  3747. var xrefEntry = this.getEntry(num);
  3748. // the referenced entry can be free
  3749. if (xrefEntry === null) {
  3750. return (this.cache[num] = null);
  3751. }
  3752. if (xrefEntry.uncompressed) {
  3753. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3754. } else {
  3755. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3756. }
  3757. if (isDict(xrefEntry)){
  3758. xrefEntry.objId = ref.toString();
  3759. } else if (isStream(xrefEntry)) {
  3760. xrefEntry.dict.objId = ref.toString();
  3761. }
  3762. return xrefEntry;
  3763. },
  3764. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3765. suppressEncryption) {
  3766. var gen = ref.gen;
  3767. var num = ref.num;
  3768. if (xrefEntry.gen !== gen) {
  3769. error('inconsistent generation in XRef');
  3770. }
  3771. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3772. this.stream.start);
  3773. var parser = new Parser(new Lexer(stream), true, this);
  3774. var obj1 = parser.getObj();
  3775. var obj2 = parser.getObj();
  3776. var obj3 = parser.getObj();
  3777. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3778. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3779. !isCmd(obj3)) {
  3780. error('bad XRef entry');
  3781. }
  3782. if (!isCmd(obj3, 'obj')) {
  3783. // some bad PDFs use "obj1234" and really mean 1234
  3784. if (obj3.cmd.indexOf('obj') === 0) {
  3785. num = parseInt(obj3.cmd.substring(3), 10);
  3786. if (!isNaN(num)) {
  3787. return num;
  3788. }
  3789. }
  3790. error('bad XRef entry');
  3791. }
  3792. if (this.encrypt && !suppressEncryption) {
  3793. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3794. } else {
  3795. xrefEntry = parser.getObj();
  3796. }
  3797. if (!isStream(xrefEntry)) {
  3798. this.cache[num] = xrefEntry;
  3799. }
  3800. return xrefEntry;
  3801. },
  3802. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3803. suppressEncryption) {
  3804. var tableOffset = xrefEntry.offset;
  3805. var stream = this.fetch(new Ref(tableOffset, 0));
  3806. if (!isStream(stream)) {
  3807. error('bad ObjStm stream');
  3808. }
  3809. var first = stream.dict.get('First');
  3810. var n = stream.dict.get('N');
  3811. if (!isInt(first) || !isInt(n)) {
  3812. error('invalid first and n parameters for ObjStm stream');
  3813. }
  3814. var parser = new Parser(new Lexer(stream), false, this);
  3815. parser.allowStreams = true;
  3816. var i, entries = [], num, nums = [];
  3817. // read the object numbers to populate cache
  3818. for (i = 0; i < n; ++i) {
  3819. num = parser.getObj();
  3820. if (!isInt(num)) {
  3821. error('invalid object number in the ObjStm stream: ' + num);
  3822. }
  3823. nums.push(num);
  3824. var offset = parser.getObj();
  3825. if (!isInt(offset)) {
  3826. error('invalid object offset in the ObjStm stream: ' + offset);
  3827. }
  3828. }
  3829. // read stream objects for cache
  3830. for (i = 0; i < n; ++i) {
  3831. entries.push(parser.getObj());
  3832. num = nums[i];
  3833. var entry = this.entries[num];
  3834. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3835. this.cache[num] = entries[i];
  3836. }
  3837. }
  3838. xrefEntry = entries[xrefEntry.gen];
  3839. if (xrefEntry === undefined) {
  3840. error('bad XRef entry for compressed object');
  3841. }
  3842. return xrefEntry;
  3843. },
  3844. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3845. if (!isRef(obj)) {
  3846. return Promise.resolve(obj);
  3847. }
  3848. return this.fetchAsync(obj);
  3849. },
  3850. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3851. var streamManager = this.stream.manager;
  3852. var xref = this;
  3853. return new Promise(function tryFetch(resolve, reject) {
  3854. try {
  3855. resolve(xref.fetch(ref, suppressEncryption));
  3856. } catch (e) {
  3857. if (e instanceof MissingDataException) {
  3858. streamManager.requestRange(e.begin, e.end, function () {
  3859. tryFetch(resolve, reject);
  3860. });
  3861. return;
  3862. }
  3863. reject(e);
  3864. }
  3865. });
  3866. },
  3867. getCatalogObj: function XRef_getCatalogObj() {
  3868. return this.root;
  3869. }
  3870. };
  3871. return XRef;
  3872. })();
  3873. /**
  3874. * A NameTree is like a Dict but has some advantageous properties, see the
  3875. * spec (7.9.6) for more details.
  3876. * TODO: implement all the Dict functions and make this more efficent.
  3877. */
  3878. var NameTree = (function NameTreeClosure() {
  3879. function NameTree(root, xref) {
  3880. this.root = root;
  3881. this.xref = xref;
  3882. }
  3883. NameTree.prototype = {
  3884. getAll: function NameTree_getAll() {
  3885. var dict = {};
  3886. if (!this.root) {
  3887. return dict;
  3888. }
  3889. var xref = this.xref;
  3890. // reading name tree
  3891. var processed = new RefSet();
  3892. processed.put(this.root);
  3893. var queue = [this.root];
  3894. while (queue.length > 0) {
  3895. var i, n;
  3896. var obj = xref.fetchIfRef(queue.shift());
  3897. if (!isDict(obj)) {
  3898. continue;
  3899. }
  3900. if (obj.has('Kids')) {
  3901. var kids = obj.get('Kids');
  3902. for (i = 0, n = kids.length; i < n; i++) {
  3903. var kid = kids[i];
  3904. if (processed.has(kid)) {
  3905. error('invalid destinations');
  3906. }
  3907. queue.push(kid);
  3908. processed.put(kid);
  3909. }
  3910. continue;
  3911. }
  3912. var names = obj.get('Names');
  3913. if (names) {
  3914. for (i = 0, n = names.length; i < n; i += 2) {
  3915. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3916. }
  3917. }
  3918. }
  3919. return dict;
  3920. }
  3921. };
  3922. return NameTree;
  3923. })();
  3924. /**
  3925. * "A PDF file can refer to the contents of another file by using a File
  3926. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  3927. * NOTE: Only embedded files are supported (as part of the attachments support)
  3928. * TODO: support the 'URL' file system (with caching if !/V), portable
  3929. * collections attributes and related files (/RF)
  3930. */
  3931. var FileSpec = (function FileSpecClosure() {
  3932. function FileSpec(root, xref) {
  3933. if (!root || !isDict(root)) {
  3934. return;
  3935. }
  3936. this.xref = xref;
  3937. this.root = root;
  3938. if (root.has('FS')) {
  3939. this.fs = root.get('FS');
  3940. }
  3941. this.description = root.has('Desc') ?
  3942. stringToPDFString(root.get('Desc')) :
  3943. '';
  3944. if (root.has('RF')) {
  3945. warn('Related file specifications are not supported');
  3946. }
  3947. this.contentAvailable = true;
  3948. if (!root.has('EF')) {
  3949. this.contentAvailable = false;
  3950. warn('Non-embedded file specifications are not supported');
  3951. }
  3952. }
  3953. function pickPlatformItem(dict) {
  3954. // Look for the filename in this order:
  3955. // UF, F, Unix, Mac, DOS
  3956. if (dict.has('UF')) {
  3957. return dict.get('UF');
  3958. } else if (dict.has('F')) {
  3959. return dict.get('F');
  3960. } else if (dict.has('Unix')) {
  3961. return dict.get('Unix');
  3962. } else if (dict.has('Mac')) {
  3963. return dict.get('Mac');
  3964. } else if (dict.has('DOS')) {
  3965. return dict.get('DOS');
  3966. } else {
  3967. return null;
  3968. }
  3969. }
  3970. FileSpec.prototype = {
  3971. get filename() {
  3972. if (!this._filename && this.root) {
  3973. var filename = pickPlatformItem(this.root) || 'unnamed';
  3974. this._filename = stringToPDFString(filename).
  3975. replace(/\\\\/g, '\\').
  3976. replace(/\\\//g, '/').
  3977. replace(/\\/g, '/');
  3978. }
  3979. return this._filename;
  3980. },
  3981. get content() {
  3982. if (!this.contentAvailable) {
  3983. return null;
  3984. }
  3985. if (!this.contentRef && this.root) {
  3986. this.contentRef = pickPlatformItem(this.root.get('EF'));
  3987. }
  3988. var content = null;
  3989. if (this.contentRef) {
  3990. var xref = this.xref;
  3991. var fileObj = xref.fetchIfRef(this.contentRef);
  3992. if (fileObj && isStream(fileObj)) {
  3993. content = fileObj.getBytes();
  3994. } else {
  3995. warn('Embedded file specification points to non-existing/invalid ' +
  3996. 'content');
  3997. }
  3998. } else {
  3999. warn('Embedded file specification does not have a content');
  4000. }
  4001. return content;
  4002. },
  4003. get serializable() {
  4004. return {
  4005. filename: this.filename,
  4006. content: this.content
  4007. };
  4008. }
  4009. };
  4010. return FileSpec;
  4011. })();
  4012. /**
  4013. * A helper for loading missing data in object graphs. It traverses the graph
  4014. * depth first and queues up any objects that have missing data. Once it has
  4015. * has traversed as many objects that are available it attempts to bundle the
  4016. * missing data requests and then resume from the nodes that weren't ready.
  4017. *
  4018. * NOTE: It provides protection from circular references by keeping track of
  4019. * of loaded references. However, you must be careful not to load any graphs
  4020. * that have references to the catalog or other pages since that will cause the
  4021. * entire PDF document object graph to be traversed.
  4022. */
  4023. var ObjectLoader = (function() {
  4024. function mayHaveChildren(value) {
  4025. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4026. }
  4027. function addChildren(node, nodesToVisit) {
  4028. var value;
  4029. if (isDict(node) || isStream(node)) {
  4030. var map;
  4031. if (isDict(node)) {
  4032. map = node.map;
  4033. } else {
  4034. map = node.dict.map;
  4035. }
  4036. for (var key in map) {
  4037. value = map[key];
  4038. if (mayHaveChildren(value)) {
  4039. nodesToVisit.push(value);
  4040. }
  4041. }
  4042. } else if (isArray(node)) {
  4043. for (var i = 0, ii = node.length; i < ii; i++) {
  4044. value = node[i];
  4045. if (mayHaveChildren(value)) {
  4046. nodesToVisit.push(value);
  4047. }
  4048. }
  4049. }
  4050. }
  4051. function ObjectLoader(obj, keys, xref) {
  4052. this.obj = obj;
  4053. this.keys = keys;
  4054. this.xref = xref;
  4055. this.refSet = null;
  4056. }
  4057. ObjectLoader.prototype = {
  4058. load: function ObjectLoader_load() {
  4059. var keys = this.keys;
  4060. this.capability = createPromiseCapability();
  4061. // Don't walk the graph if all the data is already loaded.
  4062. if (!(this.xref.stream instanceof ChunkedStream) ||
  4063. this.xref.stream.getMissingChunks().length === 0) {
  4064. this.capability.resolve();
  4065. return this.capability.promise;
  4066. }
  4067. this.refSet = new RefSet();
  4068. // Setup the initial nodes to visit.
  4069. var nodesToVisit = [];
  4070. for (var i = 0; i < keys.length; i++) {
  4071. nodesToVisit.push(this.obj[keys[i]]);
  4072. }
  4073. this.walk(nodesToVisit);
  4074. return this.capability.promise;
  4075. },
  4076. walk: function ObjectLoader_walk(nodesToVisit) {
  4077. var nodesToRevisit = [];
  4078. var pendingRequests = [];
  4079. // DFS walk of the object graph.
  4080. while (nodesToVisit.length) {
  4081. var currentNode = nodesToVisit.pop();
  4082. // Only references or chunked streams can cause missing data exceptions.
  4083. if (isRef(currentNode)) {
  4084. // Skip nodes that have already been visited.
  4085. if (this.refSet.has(currentNode)) {
  4086. continue;
  4087. }
  4088. try {
  4089. var ref = currentNode;
  4090. this.refSet.put(ref);
  4091. currentNode = this.xref.fetch(currentNode);
  4092. } catch (e) {
  4093. if (!(e instanceof MissingDataException)) {
  4094. throw e;
  4095. }
  4096. nodesToRevisit.push(currentNode);
  4097. pendingRequests.push({ begin: e.begin, end: e.end });
  4098. }
  4099. }
  4100. if (currentNode && currentNode.getBaseStreams) {
  4101. var baseStreams = currentNode.getBaseStreams();
  4102. var foundMissingData = false;
  4103. for (var i = 0; i < baseStreams.length; i++) {
  4104. var stream = baseStreams[i];
  4105. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4106. foundMissingData = true;
  4107. pendingRequests.push({
  4108. begin: stream.start,
  4109. end: stream.end
  4110. });
  4111. }
  4112. }
  4113. if (foundMissingData) {
  4114. nodesToRevisit.push(currentNode);
  4115. }
  4116. }
  4117. addChildren(currentNode, nodesToVisit);
  4118. }
  4119. if (pendingRequests.length) {
  4120. this.xref.stream.manager.requestRanges(pendingRequests,
  4121. function pendingRequestCallback() {
  4122. nodesToVisit = nodesToRevisit;
  4123. for (var i = 0; i < nodesToRevisit.length; i++) {
  4124. var node = nodesToRevisit[i];
  4125. // Remove any reference nodes from the currrent refset so they
  4126. // aren't skipped when we revist them.
  4127. if (isRef(node)) {
  4128. this.refSet.remove(node);
  4129. }
  4130. }
  4131. this.walk(nodesToVisit);
  4132. }.bind(this));
  4133. return;
  4134. }
  4135. // Everything is loaded.
  4136. this.refSet = null;
  4137. this.capability.resolve();
  4138. }
  4139. };
  4140. return ObjectLoader;
  4141. })();
  4142. var ISOAdobeCharset = [
  4143. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4144. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4145. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4146. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4147. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4148. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4149. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4150. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4151. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4152. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4153. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4154. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4155. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4156. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4157. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4158. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4159. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4160. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4161. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4162. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4163. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4164. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4165. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4166. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4167. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4168. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4169. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4170. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4171. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4172. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4173. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4174. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4175. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4176. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4177. ];
  4178. var ExpertCharset = [
  4179. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4180. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4181. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4182. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4183. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4184. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4185. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4186. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4187. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4188. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4189. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4190. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4191. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4192. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4193. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4194. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4195. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4196. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4197. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4198. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4199. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4200. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4201. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4202. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4203. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4204. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4205. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4206. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4207. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4208. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4209. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4210. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4211. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4212. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4213. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4214. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4215. 'Ydieresissmall'
  4216. ];
  4217. var ExpertSubsetCharset = [
  4218. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4219. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4220. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4221. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4222. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4223. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4224. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4225. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4226. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4227. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4228. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4229. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4230. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4231. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4232. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4233. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4234. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4235. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4236. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4237. 'periodinferior', 'commainferior'
  4238. ];
  4239. var DEFAULT_ICON_SIZE = 22; // px
  4240. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4241. var Annotation = (function AnnotationClosure() {
  4242. // 12.5.5: Algorithm: Appearance streams
  4243. function getTransformMatrix(rect, bbox, matrix) {
  4244. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4245. var minX = bounds[0];
  4246. var minY = bounds[1];
  4247. var maxX = bounds[2];
  4248. var maxY = bounds[3];
  4249. if (minX === maxX || minY === maxY) {
  4250. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4251. // just apply the transform for rect
  4252. return [1, 0, 0, 1, rect[0], rect[1]];
  4253. }
  4254. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4255. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4256. return [
  4257. xRatio,
  4258. 0,
  4259. 0,
  4260. yRatio,
  4261. rect[0] - minX * xRatio,
  4262. rect[1] - minY * yRatio
  4263. ];
  4264. }
  4265. function getDefaultAppearance(dict) {
  4266. var appearanceState = dict.get('AP');
  4267. if (!isDict(appearanceState)) {
  4268. return;
  4269. }
  4270. var appearance;
  4271. var appearances = appearanceState.get('N');
  4272. if (isDict(appearances)) {
  4273. var as = dict.get('AS');
  4274. if (as && appearances.has(as.name)) {
  4275. appearance = appearances.get(as.name);
  4276. }
  4277. } else {
  4278. appearance = appearances;
  4279. }
  4280. return appearance;
  4281. }
  4282. function Annotation(params) {
  4283. var dict = params.dict;
  4284. var data = this.data = {};
  4285. data.subtype = dict.get('Subtype').name;
  4286. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4287. data.rect = Util.normalizeRect(rect);
  4288. data.annotationFlags = dict.get('F');
  4289. var color = dict.get('C');
  4290. if (isArray(color) && color.length === 3) {
  4291. // TODO(mack): currently only supporting rgb; need support different
  4292. // colorspaces
  4293. data.color = color;
  4294. } else {
  4295. data.color = [0, 0, 0];
  4296. }
  4297. // Some types of annotations have border style dict which has more
  4298. // info than the border array
  4299. if (dict.has('BS')) {
  4300. var borderStyle = dict.get('BS');
  4301. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4302. } else {
  4303. var borderArray = dict.get('Border') || [0, 0, 1];
  4304. data.borderWidth = borderArray[2] || 0;
  4305. // TODO: implement proper support for annotations with line dash patterns.
  4306. var dashArray = borderArray[3];
  4307. if (data.borderWidth > 0 && dashArray) {
  4308. if (!isArray(dashArray)) {
  4309. // Ignore the border if dashArray is not actually an array,
  4310. // this is consistent with the behaviour in Adobe Reader.
  4311. data.borderWidth = 0;
  4312. } else {
  4313. var dashArrayLength = dashArray.length;
  4314. if (dashArrayLength > 0) {
  4315. // According to the PDF specification: the elements in a dashArray
  4316. // shall be numbers that are nonnegative and not all equal to zero.
  4317. var isInvalid = false;
  4318. var numPositive = 0;
  4319. for (var i = 0; i < dashArrayLength; i++) {
  4320. var validNumber = (+dashArray[i] >= 0);
  4321. if (!validNumber) {
  4322. isInvalid = true;
  4323. break;
  4324. } else if (dashArray[i] > 0) {
  4325. numPositive++;
  4326. }
  4327. }
  4328. if (isInvalid || numPositive === 0) {
  4329. data.borderWidth = 0;
  4330. }
  4331. }
  4332. }
  4333. }
  4334. }
  4335. this.appearance = getDefaultAppearance(dict);
  4336. data.hasAppearance = !!this.appearance;
  4337. data.id = params.ref.num;
  4338. }
  4339. Annotation.prototype = {
  4340. getData: function Annotation_getData() {
  4341. return this.data;
  4342. },
  4343. isInvisible: function Annotation_isInvisible() {
  4344. var data = this.data;
  4345. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4346. return false;
  4347. } else {
  4348. return !!(data &&
  4349. data.annotationFlags && // Default: not invisible
  4350. data.annotationFlags & 0x1); // Invisible
  4351. }
  4352. },
  4353. isViewable: function Annotation_isViewable() {
  4354. var data = this.data;
  4355. return !!(!this.isInvisible() &&
  4356. data &&
  4357. (!data.annotationFlags ||
  4358. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4359. data.rect); // rectangle is necessary
  4360. },
  4361. isPrintable: function Annotation_isPrintable() {
  4362. var data = this.data;
  4363. return !!(!this.isInvisible() &&
  4364. data &&
  4365. data.annotationFlags && // Default: not printable
  4366. data.annotationFlags & 0x4 && // Print
  4367. !(data.annotationFlags & 0x2) && // Hidden
  4368. data.rect); // rectangle is necessary
  4369. },
  4370. loadResources: function Annotation_loadResources(keys) {
  4371. return new Promise(function (resolve, reject) {
  4372. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4373. if (!resources) {
  4374. resolve();
  4375. return;
  4376. }
  4377. var objectLoader = new ObjectLoader(resources.map,
  4378. keys,
  4379. resources.xref);
  4380. objectLoader.load().then(function() {
  4381. resolve(resources);
  4382. }, reject);
  4383. }, reject);
  4384. }.bind(this));
  4385. },
  4386. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4387. if (!this.appearance) {
  4388. return Promise.resolve(new OperatorList());
  4389. }
  4390. var data = this.data;
  4391. var appearanceDict = this.appearance.dict;
  4392. var resourcesPromise = this.loadResources([
  4393. 'ExtGState',
  4394. 'ColorSpace',
  4395. 'Pattern',
  4396. 'Shading',
  4397. 'XObject',
  4398. 'Font'
  4399. // ProcSet
  4400. // Properties
  4401. ]);
  4402. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4403. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4404. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4405. var self = this;
  4406. return resourcesPromise.then(function(resources) {
  4407. var opList = new OperatorList();
  4408. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4409. return evaluator.getOperatorList(self.appearance, resources, opList).
  4410. then(function () {
  4411. opList.addOp(OPS.endAnnotation, []);
  4412. self.appearance.reset();
  4413. return opList;
  4414. });
  4415. });
  4416. }
  4417. };
  4418. Annotation.getConstructor =
  4419. function Annotation_getConstructor(subtype, fieldType) {
  4420. if (!subtype) {
  4421. return;
  4422. }
  4423. // TODO(mack): Implement FreeText annotations
  4424. if (subtype === 'Link') {
  4425. return LinkAnnotation;
  4426. } else if (subtype === 'Text') {
  4427. return TextAnnotation;
  4428. } else if (subtype === 'Widget') {
  4429. if (!fieldType) {
  4430. return;
  4431. }
  4432. if (fieldType === 'Tx') {
  4433. return TextWidgetAnnotation;
  4434. } else {
  4435. return WidgetAnnotation;
  4436. }
  4437. } else {
  4438. return Annotation;
  4439. }
  4440. };
  4441. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4442. var dict = xref.fetchIfRef(ref);
  4443. if (!isDict(dict)) {
  4444. return;
  4445. }
  4446. var subtype = dict.get('Subtype');
  4447. subtype = isName(subtype) ? subtype.name : '';
  4448. if (!subtype) {
  4449. return;
  4450. }
  4451. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4452. fieldType = isName(fieldType) ? fieldType.name : '';
  4453. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4454. if (!Constructor) {
  4455. return;
  4456. }
  4457. var params = {
  4458. dict: dict,
  4459. ref: ref,
  4460. };
  4461. var annotation = new Constructor(params);
  4462. if (annotation.isViewable() || annotation.isPrintable()) {
  4463. return annotation;
  4464. } else {
  4465. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4466. warn('unimplemented annotation type: ' + subtype);
  4467. }
  4468. }
  4469. };
  4470. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4471. annotations, opList, pdfManager, partialEvaluator, intent) {
  4472. function reject(e) {
  4473. annotationsReadyCapability.reject(e);
  4474. }
  4475. var annotationsReadyCapability = createPromiseCapability();
  4476. var annotationPromises = [];
  4477. for (var i = 0, n = annotations.length; i < n; ++i) {
  4478. if (intent === 'display' && annotations[i].isViewable() ||
  4479. intent === 'print' && annotations[i].isPrintable()) {
  4480. annotationPromises.push(
  4481. annotations[i].getOperatorList(partialEvaluator));
  4482. }
  4483. }
  4484. Promise.all(annotationPromises).then(function(datas) {
  4485. opList.addOp(OPS.beginAnnotations, []);
  4486. for (var i = 0, n = datas.length; i < n; ++i) {
  4487. var annotOpList = datas[i];
  4488. opList.addOpList(annotOpList);
  4489. }
  4490. opList.addOp(OPS.endAnnotations, []);
  4491. annotationsReadyCapability.resolve();
  4492. }, reject);
  4493. return annotationsReadyCapability.promise;
  4494. };
  4495. return Annotation;
  4496. })();
  4497. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4498. function WidgetAnnotation(params) {
  4499. Annotation.call(this, params);
  4500. var dict = params.dict;
  4501. var data = this.data;
  4502. data.fieldValue = stringToPDFString(
  4503. Util.getInheritableProperty(dict, 'V') || '');
  4504. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4505. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4506. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4507. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4508. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4509. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4510. // Building the full field name by collecting the field and
  4511. // its ancestors 'T' data and joining them using '.'.
  4512. var fieldName = [];
  4513. var namedItem = dict;
  4514. var ref = params.ref;
  4515. while (namedItem) {
  4516. var parent = namedItem.get('Parent');
  4517. var parentRef = namedItem.getRaw('Parent');
  4518. var name = namedItem.get('T');
  4519. if (name) {
  4520. fieldName.unshift(stringToPDFString(name));
  4521. } else {
  4522. // The field name is absent, that means more than one field
  4523. // with the same name may exist. Replacing the empty name
  4524. // with the '`' plus index in the parent's 'Kids' array.
  4525. // This is not in the PDF spec but necessary to id the
  4526. // the input controls.
  4527. var kids = parent.get('Kids');
  4528. var j, jj;
  4529. for (j = 0, jj = kids.length; j < jj; j++) {
  4530. var kidRef = kids[j];
  4531. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4532. break;
  4533. }
  4534. }
  4535. fieldName.unshift('`' + j);
  4536. }
  4537. namedItem = parent;
  4538. ref = parentRef;
  4539. }
  4540. data.fullName = fieldName.join('.');
  4541. }
  4542. var parent = Annotation.prototype;
  4543. Util.inherit(WidgetAnnotation, Annotation, {
  4544. isViewable: function WidgetAnnotation_isViewable() {
  4545. if (this.data.fieldType === 'Sig') {
  4546. warn('unimplemented annotation type: Widget signature');
  4547. return false;
  4548. }
  4549. return parent.isViewable.call(this);
  4550. }
  4551. });
  4552. return WidgetAnnotation;
  4553. })();
  4554. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4555. function TextWidgetAnnotation(params) {
  4556. WidgetAnnotation.call(this, params);
  4557. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4558. this.data.annotationType = AnnotationType.WIDGET;
  4559. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4560. }
  4561. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4562. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4563. if (this.appearance) {
  4564. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4565. }
  4566. var opList = new OperatorList();
  4567. var data = this.data;
  4568. // Even if there is an appearance stream, ignore it. This is the
  4569. // behaviour used by Adobe Reader.
  4570. if (!data.defaultAppearance) {
  4571. return Promise.resolve(opList);
  4572. }
  4573. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4574. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4575. then(function () {
  4576. return opList;
  4577. });
  4578. }
  4579. });
  4580. return TextWidgetAnnotation;
  4581. })();
  4582. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4583. function InteractiveAnnotation(params) {
  4584. Annotation.call(this, params);
  4585. this.data.hasHtml = true;
  4586. }
  4587. Util.inherit(InteractiveAnnotation, Annotation, { });
  4588. return InteractiveAnnotation;
  4589. })();
  4590. var TextAnnotation = (function TextAnnotationClosure() {
  4591. function TextAnnotation(params) {
  4592. InteractiveAnnotation.call(this, params);
  4593. var dict = params.dict;
  4594. var data = this.data;
  4595. var content = dict.get('Contents');
  4596. var title = dict.get('T');
  4597. data.annotationType = AnnotationType.TEXT;
  4598. data.content = stringToPDFString(content || '');
  4599. data.title = stringToPDFString(title || '');
  4600. if (data.hasAppearance) {
  4601. data.name = 'NoIcon';
  4602. } else {
  4603. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4604. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4605. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4606. }
  4607. if (dict.has('C')) {
  4608. data.hasBgColor = true;
  4609. }
  4610. }
  4611. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4612. return TextAnnotation;
  4613. })();
  4614. var LinkAnnotation = (function LinkAnnotationClosure() {
  4615. function LinkAnnotation(params) {
  4616. InteractiveAnnotation.call(this, params);
  4617. var dict = params.dict;
  4618. var data = this.data;
  4619. data.annotationType = AnnotationType.LINK;
  4620. var action = dict.get('A');
  4621. if (action) {
  4622. var linkType = action.get('S').name;
  4623. if (linkType === 'URI') {
  4624. var url = action.get('URI');
  4625. if (isName(url)) {
  4626. // Some bad PDFs do not put parentheses around relative URLs.
  4627. url = '/' + url.name;
  4628. } else if (url) {
  4629. url = addDefaultProtocolToUrl(url);
  4630. }
  4631. // TODO: pdf spec mentions urls can be relative to a Base
  4632. // entry in the dictionary.
  4633. if (!isValidUrl(url, false)) {
  4634. url = '';
  4635. }
  4636. data.url = url;
  4637. } else if (linkType === 'GoTo') {
  4638. data.dest = action.get('D');
  4639. } else if (linkType === 'GoToR') {
  4640. var urlDict = action.get('F');
  4641. if (isDict(urlDict)) {
  4642. // We assume that the 'url' is a Filspec dictionary
  4643. // and fetch the url without checking any further
  4644. url = urlDict.get('F') || '';
  4645. }
  4646. // TODO: pdf reference says that GoToR
  4647. // can also have 'NewWindow' attribute
  4648. if (!isValidUrl(url, false)) {
  4649. url = '';
  4650. }
  4651. data.url = url;
  4652. data.dest = action.get('D');
  4653. } else if (linkType === 'Named') {
  4654. data.action = action.get('N').name;
  4655. } else {
  4656. warn('unrecognized link type: ' + linkType);
  4657. }
  4658. } else if (dict.has('Dest')) {
  4659. // simple destination link
  4660. var dest = dict.get('Dest');
  4661. data.dest = isName(dest) ? dest.name : dest;
  4662. }
  4663. }
  4664. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4665. function addDefaultProtocolToUrl(url) {
  4666. if (url && url.indexOf('www.') === 0) {
  4667. return ('http://' + url);
  4668. }
  4669. return url;
  4670. }
  4671. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  4672. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  4673. return false;
  4674. }
  4675. });
  4676. return LinkAnnotation;
  4677. })();
  4678. var PDFFunction = (function PDFFunctionClosure() {
  4679. var CONSTRUCT_SAMPLED = 0;
  4680. var CONSTRUCT_INTERPOLATED = 2;
  4681. var CONSTRUCT_STICHED = 3;
  4682. var CONSTRUCT_POSTSCRIPT = 4;
  4683. return {
  4684. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4685. str) {
  4686. var i, ii;
  4687. var length = 1;
  4688. for (i = 0, ii = size.length; i < ii; i++) {
  4689. length *= size[i];
  4690. }
  4691. length *= outputSize;
  4692. var array = new Array(length);
  4693. var codeSize = 0;
  4694. var codeBuf = 0;
  4695. // 32 is a valid bps so shifting won't work
  4696. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4697. var strBytes = str.getBytes((length * bps + 7) / 8);
  4698. var strIdx = 0;
  4699. for (i = 0; i < length; i++) {
  4700. while (codeSize < bps) {
  4701. codeBuf <<= 8;
  4702. codeBuf |= strBytes[strIdx++];
  4703. codeSize += 8;
  4704. }
  4705. codeSize -= bps;
  4706. array[i] = (codeBuf >> codeSize) * sampleMul;
  4707. codeBuf &= (1 << codeSize) - 1;
  4708. }
  4709. return array;
  4710. },
  4711. getIR: function PDFFunction_getIR(xref, fn) {
  4712. var dict = fn.dict;
  4713. if (!dict) {
  4714. dict = fn;
  4715. }
  4716. var types = [this.constructSampled,
  4717. null,
  4718. this.constructInterpolated,
  4719. this.constructStiched,
  4720. this.constructPostScript];
  4721. var typeNum = dict.get('FunctionType');
  4722. var typeFn = types[typeNum];
  4723. if (!typeFn) {
  4724. error('Unknown type of function');
  4725. }
  4726. return typeFn.call(this, fn, dict, xref);
  4727. },
  4728. fromIR: function PDFFunction_fromIR(IR) {
  4729. var type = IR[0];
  4730. switch (type) {
  4731. case CONSTRUCT_SAMPLED:
  4732. return this.constructSampledFromIR(IR);
  4733. case CONSTRUCT_INTERPOLATED:
  4734. return this.constructInterpolatedFromIR(IR);
  4735. case CONSTRUCT_STICHED:
  4736. return this.constructStichedFromIR(IR);
  4737. //case CONSTRUCT_POSTSCRIPT:
  4738. default:
  4739. return this.constructPostScriptFromIR(IR);
  4740. }
  4741. },
  4742. parse: function PDFFunction_parse(xref, fn) {
  4743. var IR = this.getIR(xref, fn);
  4744. return this.fromIR(IR);
  4745. },
  4746. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4747. if (!isArray(fnObj)) {
  4748. // not an array -- parsing as regular function
  4749. return this.parse(xref, fnObj);
  4750. }
  4751. var fnArray = [];
  4752. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4753. var obj = xref.fetchIfRef(fnObj[j]);
  4754. fnArray.push(PDFFunction.parse(xref, obj));
  4755. }
  4756. return function (src, srcOffset, dest, destOffset) {
  4757. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4758. fnArray[i](src, srcOffset, dest, destOffset + i);
  4759. }
  4760. };
  4761. },
  4762. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4763. function toMultiArray(arr) {
  4764. var inputLength = arr.length;
  4765. var out = [];
  4766. var index = 0;
  4767. for (var i = 0; i < inputLength; i += 2) {
  4768. out[index] = [arr[i], arr[i + 1]];
  4769. ++index;
  4770. }
  4771. return out;
  4772. }
  4773. var domain = dict.get('Domain');
  4774. var range = dict.get('Range');
  4775. if (!domain || !range) {
  4776. error('No domain or range');
  4777. }
  4778. var inputSize = domain.length / 2;
  4779. var outputSize = range.length / 2;
  4780. domain = toMultiArray(domain);
  4781. range = toMultiArray(range);
  4782. var size = dict.get('Size');
  4783. var bps = dict.get('BitsPerSample');
  4784. var order = dict.get('Order') || 1;
  4785. if (order !== 1) {
  4786. // No description how cubic spline interpolation works in PDF32000:2008
  4787. // As in poppler, ignoring order, linear interpolation may work as good
  4788. info('No support for cubic spline interpolation: ' + order);
  4789. }
  4790. var encode = dict.get('Encode');
  4791. if (!encode) {
  4792. encode = [];
  4793. for (var i = 0; i < inputSize; ++i) {
  4794. encode.push(0);
  4795. encode.push(size[i] - 1);
  4796. }
  4797. }
  4798. encode = toMultiArray(encode);
  4799. var decode = dict.get('Decode');
  4800. if (!decode) {
  4801. decode = range;
  4802. } else {
  4803. decode = toMultiArray(decode);
  4804. }
  4805. var samples = this.getSampleArray(size, outputSize, bps, str);
  4806. return [
  4807. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4808. outputSize, Math.pow(2, bps) - 1, range
  4809. ];
  4810. },
  4811. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4812. // See chapter 3, page 109 of the PDF reference
  4813. function interpolate(x, xmin, xmax, ymin, ymax) {
  4814. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4815. }
  4816. return function constructSampledFromIRResult(src, srcOffset,
  4817. dest, destOffset) {
  4818. // See chapter 3, page 110 of the PDF reference.
  4819. var m = IR[1];
  4820. var domain = IR[2];
  4821. var encode = IR[3];
  4822. var decode = IR[4];
  4823. var samples = IR[5];
  4824. var size = IR[6];
  4825. var n = IR[7];
  4826. //var mask = IR[8];
  4827. var range = IR[9];
  4828. // Building the cube vertices: its part and sample index
  4829. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4830. var cubeVertices = 1 << m;
  4831. var cubeN = new Float64Array(cubeVertices);
  4832. var cubeVertex = new Uint32Array(cubeVertices);
  4833. var i, j;
  4834. for (j = 0; j < cubeVertices; j++) {
  4835. cubeN[j] = 1;
  4836. }
  4837. var k = n, pos = 1;
  4838. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4839. for (i = 0; i < m; ++i) {
  4840. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4841. var domain_2i = domain[i][0];
  4842. var domain_2i_1 = domain[i][1];
  4843. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4844. domain_2i_1);
  4845. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4846. // Encode_2i, Encode_2i+1)
  4847. var e = interpolate(xi, domain_2i, domain_2i_1,
  4848. encode[i][0], encode[i][1]);
  4849. // e_i' = min(max(e_i, 0), Size_i - 1)
  4850. var size_i = size[i];
  4851. e = Math.min(Math.max(e, 0), size_i - 1);
  4852. // Adjusting the cube: N and vertex sample index
  4853. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4854. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4855. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4856. var offset0 = e0 * k;
  4857. var offset1 = offset0 + k; // e1 * k
  4858. for (j = 0; j < cubeVertices; j++) {
  4859. if (j & pos) {
  4860. cubeN[j] *= n1;
  4861. cubeVertex[j] += offset1;
  4862. } else {
  4863. cubeN[j] *= n0;
  4864. cubeVertex[j] += offset0;
  4865. }
  4866. }
  4867. k *= size_i;
  4868. pos <<= 1;
  4869. }
  4870. for (j = 0; j < n; ++j) {
  4871. // Sum all cube vertices' samples portions
  4872. var rj = 0;
  4873. for (i = 0; i < cubeVertices; i++) {
  4874. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4875. }
  4876. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4877. // Decode_2j, Decode_2j+1)
  4878. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  4879. // y_j = min(max(r_j, range_2j), range_2j+1)
  4880. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  4881. range[j][1]);
  4882. }
  4883. };
  4884. },
  4885. constructInterpolated: function PDFFunction_constructInterpolated(str,
  4886. dict) {
  4887. var c0 = dict.get('C0') || [0];
  4888. var c1 = dict.get('C1') || [1];
  4889. var n = dict.get('N');
  4890. if (!isArray(c0) || !isArray(c1)) {
  4891. error('Illegal dictionary for interpolated function');
  4892. }
  4893. var length = c0.length;
  4894. var diff = [];
  4895. for (var i = 0; i < length; ++i) {
  4896. diff.push(c1[i] - c0[i]);
  4897. }
  4898. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  4899. },
  4900. constructInterpolatedFromIR:
  4901. function PDFFunction_constructInterpolatedFromIR(IR) {
  4902. var c0 = IR[1];
  4903. var diff = IR[2];
  4904. var n = IR[3];
  4905. var length = diff.length;
  4906. return function constructInterpolatedFromIRResult(src, srcOffset,
  4907. dest, destOffset) {
  4908. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  4909. for (var j = 0; j < length; ++j) {
  4910. dest[destOffset + j] = c0[j] + (x * diff[j]);
  4911. }
  4912. };
  4913. },
  4914. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  4915. var domain = dict.get('Domain');
  4916. if (!domain) {
  4917. error('No domain');
  4918. }
  4919. var inputSize = domain.length / 2;
  4920. if (inputSize !== 1) {
  4921. error('Bad domain for stiched function');
  4922. }
  4923. var fnRefs = dict.get('Functions');
  4924. var fns = [];
  4925. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  4926. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  4927. }
  4928. var bounds = dict.get('Bounds');
  4929. var encode = dict.get('Encode');
  4930. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  4931. },
  4932. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  4933. var domain = IR[1];
  4934. var bounds = IR[2];
  4935. var encode = IR[3];
  4936. var fnsIR = IR[4];
  4937. var fns = [];
  4938. var tmpBuf = new Float32Array(1);
  4939. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  4940. fns.push(PDFFunction.fromIR(fnsIR[i]));
  4941. }
  4942. return function constructStichedFromIRResult(src, srcOffset,
  4943. dest, destOffset) {
  4944. var clip = function constructStichedFromIRClip(v, min, max) {
  4945. if (v > max) {
  4946. v = max;
  4947. } else if (v < min) {
  4948. v = min;
  4949. }
  4950. return v;
  4951. };
  4952. // clip to domain
  4953. var v = clip(src[srcOffset], domain[0], domain[1]);
  4954. // calulate which bound the value is in
  4955. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  4956. if (v < bounds[i]) {
  4957. break;
  4958. }
  4959. }
  4960. // encode value into domain of function
  4961. var dmin = domain[0];
  4962. if (i > 0) {
  4963. dmin = bounds[i - 1];
  4964. }
  4965. var dmax = domain[1];
  4966. if (i < bounds.length) {
  4967. dmax = bounds[i];
  4968. }
  4969. var rmin = encode[2 * i];
  4970. var rmax = encode[2 * i + 1];
  4971. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  4972. // call the appropriate function
  4973. fns[i](tmpBuf, 0, dest, destOffset);
  4974. };
  4975. },
  4976. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  4977. xref) {
  4978. var domain = dict.get('Domain');
  4979. var range = dict.get('Range');
  4980. if (!domain) {
  4981. error('No domain.');
  4982. }
  4983. if (!range) {
  4984. error('No range.');
  4985. }
  4986. var lexer = new PostScriptLexer(fn);
  4987. var parser = new PostScriptParser(lexer);
  4988. var code = parser.parse();
  4989. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  4990. },
  4991. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  4992. IR) {
  4993. var domain = IR[1];
  4994. var range = IR[2];
  4995. var code = IR[3];
  4996. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  4997. if (compiled) {
  4998. // Compiled function consists of simple expressions such as addition,
  4999. // subtraction, Math.max, and also contains 'var' and 'return'
  5000. // statements. See the generation in the PostScriptCompiler below.
  5001. /*jshint -W054 */
  5002. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5003. }
  5004. info('Unable to compile PS function');
  5005. var numOutputs = range.length >> 1;
  5006. var numInputs = domain.length >> 1;
  5007. var evaluator = new PostScriptEvaluator(code);
  5008. // Cache the values for a big speed up, the cache size is limited though
  5009. // since the number of possible values can be huge from a PS function.
  5010. var cache = {};
  5011. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5012. // seen in our tests.
  5013. var MAX_CACHE_SIZE = 2048 * 4;
  5014. var cache_available = MAX_CACHE_SIZE;
  5015. var tmpBuf = new Float32Array(numInputs);
  5016. return function constructPostScriptFromIRResult(src, srcOffset,
  5017. dest, destOffset) {
  5018. var i, value;
  5019. var key = '';
  5020. var input = tmpBuf;
  5021. for (i = 0; i < numInputs; i++) {
  5022. value = src[srcOffset + i];
  5023. input[i] = value;
  5024. key += value + '_';
  5025. }
  5026. var cachedValue = cache[key];
  5027. if (cachedValue !== undefined) {
  5028. cachedValue.set(dest, destOffset);
  5029. return;
  5030. }
  5031. var output = new Float32Array(numOutputs);
  5032. var stack = evaluator.execute(input);
  5033. var stackIndex = stack.length - numOutputs;
  5034. for (i = 0; i < numOutputs; i++) {
  5035. value = stack[stackIndex + i];
  5036. var bound = range[i * 2];
  5037. if (value < bound) {
  5038. value = bound;
  5039. } else {
  5040. bound = range[i * 2 +1];
  5041. if (value > bound) {
  5042. value = bound;
  5043. }
  5044. }
  5045. output[i] = value;
  5046. }
  5047. if (cache_available > 0) {
  5048. cache_available--;
  5049. cache[key] = output;
  5050. }
  5051. output.set(dest, destOffset);
  5052. };
  5053. }
  5054. };
  5055. })();
  5056. function isPDFFunction(v) {
  5057. var fnDict;
  5058. if (typeof v !== 'object') {
  5059. return false;
  5060. } else if (isDict(v)) {
  5061. fnDict = v;
  5062. } else if (isStream(v)) {
  5063. fnDict = v.dict;
  5064. } else {
  5065. return false;
  5066. }
  5067. return fnDict.has('FunctionType');
  5068. }
  5069. var PostScriptStack = (function PostScriptStackClosure() {
  5070. var MAX_STACK_SIZE = 100;
  5071. function PostScriptStack(initialStack) {
  5072. this.stack = !initialStack ? [] :
  5073. Array.prototype.slice.call(initialStack, 0);
  5074. }
  5075. PostScriptStack.prototype = {
  5076. push: function PostScriptStack_push(value) {
  5077. if (this.stack.length >= MAX_STACK_SIZE) {
  5078. error('PostScript function stack overflow.');
  5079. }
  5080. this.stack.push(value);
  5081. },
  5082. pop: function PostScriptStack_pop() {
  5083. if (this.stack.length <= 0) {
  5084. error('PostScript function stack underflow.');
  5085. }
  5086. return this.stack.pop();
  5087. },
  5088. copy: function PostScriptStack_copy(n) {
  5089. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5090. error('PostScript function stack overflow.');
  5091. }
  5092. var stack = this.stack;
  5093. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5094. stack.push(stack[i]);
  5095. }
  5096. },
  5097. index: function PostScriptStack_index(n) {
  5098. this.push(this.stack[this.stack.length - n - 1]);
  5099. },
  5100. // rotate the last n stack elements p times
  5101. roll: function PostScriptStack_roll(n, p) {
  5102. var stack = this.stack;
  5103. var l = stack.length - n;
  5104. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5105. for (i = l, j = r; i < j; i++, j--) {
  5106. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5107. }
  5108. for (i = l, j = c - 1; i < j; i++, j--) {
  5109. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5110. }
  5111. for (i = c, j = r; i < j; i++, j--) {
  5112. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5113. }
  5114. }
  5115. };
  5116. return PostScriptStack;
  5117. })();
  5118. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5119. function PostScriptEvaluator(operators) {
  5120. this.operators = operators;
  5121. }
  5122. PostScriptEvaluator.prototype = {
  5123. execute: function PostScriptEvaluator_execute(initialStack) {
  5124. var stack = new PostScriptStack(initialStack);
  5125. var counter = 0;
  5126. var operators = this.operators;
  5127. var length = operators.length;
  5128. var operator, a, b;
  5129. while (counter < length) {
  5130. operator = operators[counter++];
  5131. if (typeof operator === 'number') {
  5132. // Operator is really an operand and should be pushed to the stack.
  5133. stack.push(operator);
  5134. continue;
  5135. }
  5136. switch (operator) {
  5137. // non standard ps operators
  5138. case 'jz': // jump if false
  5139. b = stack.pop();
  5140. a = stack.pop();
  5141. if (!a) {
  5142. counter = b;
  5143. }
  5144. break;
  5145. case 'j': // jump
  5146. a = stack.pop();
  5147. counter = a;
  5148. break;
  5149. // all ps operators in alphabetical order (excluding if/ifelse)
  5150. case 'abs':
  5151. a = stack.pop();
  5152. stack.push(Math.abs(a));
  5153. break;
  5154. case 'add':
  5155. b = stack.pop();
  5156. a = stack.pop();
  5157. stack.push(a + b);
  5158. break;
  5159. case 'and':
  5160. b = stack.pop();
  5161. a = stack.pop();
  5162. if (isBool(a) && isBool(b)) {
  5163. stack.push(a && b);
  5164. } else {
  5165. stack.push(a & b);
  5166. }
  5167. break;
  5168. case 'atan':
  5169. a = stack.pop();
  5170. stack.push(Math.atan(a));
  5171. break;
  5172. case 'bitshift':
  5173. b = stack.pop();
  5174. a = stack.pop();
  5175. if (a > 0) {
  5176. stack.push(a << b);
  5177. } else {
  5178. stack.push(a >> b);
  5179. }
  5180. break;
  5181. case 'ceiling':
  5182. a = stack.pop();
  5183. stack.push(Math.ceil(a));
  5184. break;
  5185. case 'copy':
  5186. a = stack.pop();
  5187. stack.copy(a);
  5188. break;
  5189. case 'cos':
  5190. a = stack.pop();
  5191. stack.push(Math.cos(a));
  5192. break;
  5193. case 'cvi':
  5194. a = stack.pop() | 0;
  5195. stack.push(a);
  5196. break;
  5197. case 'cvr':
  5198. // noop
  5199. break;
  5200. case 'div':
  5201. b = stack.pop();
  5202. a = stack.pop();
  5203. stack.push(a / b);
  5204. break;
  5205. case 'dup':
  5206. stack.copy(1);
  5207. break;
  5208. case 'eq':
  5209. b = stack.pop();
  5210. a = stack.pop();
  5211. stack.push(a === b);
  5212. break;
  5213. case 'exch':
  5214. stack.roll(2, 1);
  5215. break;
  5216. case 'exp':
  5217. b = stack.pop();
  5218. a = stack.pop();
  5219. stack.push(Math.pow(a, b));
  5220. break;
  5221. case 'false':
  5222. stack.push(false);
  5223. break;
  5224. case 'floor':
  5225. a = stack.pop();
  5226. stack.push(Math.floor(a));
  5227. break;
  5228. case 'ge':
  5229. b = stack.pop();
  5230. a = stack.pop();
  5231. stack.push(a >= b);
  5232. break;
  5233. case 'gt':
  5234. b = stack.pop();
  5235. a = stack.pop();
  5236. stack.push(a > b);
  5237. break;
  5238. case 'idiv':
  5239. b = stack.pop();
  5240. a = stack.pop();
  5241. stack.push((a / b) | 0);
  5242. break;
  5243. case 'index':
  5244. a = stack.pop();
  5245. stack.index(a);
  5246. break;
  5247. case 'le':
  5248. b = stack.pop();
  5249. a = stack.pop();
  5250. stack.push(a <= b);
  5251. break;
  5252. case 'ln':
  5253. a = stack.pop();
  5254. stack.push(Math.log(a));
  5255. break;
  5256. case 'log':
  5257. a = stack.pop();
  5258. stack.push(Math.log(a) / Math.LN10);
  5259. break;
  5260. case 'lt':
  5261. b = stack.pop();
  5262. a = stack.pop();
  5263. stack.push(a < b);
  5264. break;
  5265. case 'mod':
  5266. b = stack.pop();
  5267. a = stack.pop();
  5268. stack.push(a % b);
  5269. break;
  5270. case 'mul':
  5271. b = stack.pop();
  5272. a = stack.pop();
  5273. stack.push(a * b);
  5274. break;
  5275. case 'ne':
  5276. b = stack.pop();
  5277. a = stack.pop();
  5278. stack.push(a !== b);
  5279. break;
  5280. case 'neg':
  5281. a = stack.pop();
  5282. stack.push(-a);
  5283. break;
  5284. case 'not':
  5285. a = stack.pop();
  5286. if (isBool(a)) {
  5287. stack.push(!a);
  5288. } else {
  5289. stack.push(~a);
  5290. }
  5291. break;
  5292. case 'or':
  5293. b = stack.pop();
  5294. a = stack.pop();
  5295. if (isBool(a) && isBool(b)) {
  5296. stack.push(a || b);
  5297. } else {
  5298. stack.push(a | b);
  5299. }
  5300. break;
  5301. case 'pop':
  5302. stack.pop();
  5303. break;
  5304. case 'roll':
  5305. b = stack.pop();
  5306. a = stack.pop();
  5307. stack.roll(a, b);
  5308. break;
  5309. case 'round':
  5310. a = stack.pop();
  5311. stack.push(Math.round(a));
  5312. break;
  5313. case 'sin':
  5314. a = stack.pop();
  5315. stack.push(Math.sin(a));
  5316. break;
  5317. case 'sqrt':
  5318. a = stack.pop();
  5319. stack.push(Math.sqrt(a));
  5320. break;
  5321. case 'sub':
  5322. b = stack.pop();
  5323. a = stack.pop();
  5324. stack.push(a - b);
  5325. break;
  5326. case 'true':
  5327. stack.push(true);
  5328. break;
  5329. case 'truncate':
  5330. a = stack.pop();
  5331. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5332. stack.push(a);
  5333. break;
  5334. case 'xor':
  5335. b = stack.pop();
  5336. a = stack.pop();
  5337. if (isBool(a) && isBool(b)) {
  5338. stack.push(a !== b);
  5339. } else {
  5340. stack.push(a ^ b);
  5341. }
  5342. break;
  5343. default:
  5344. error('Unknown operator ' + operator);
  5345. break;
  5346. }
  5347. }
  5348. return stack.stack;
  5349. }
  5350. };
  5351. return PostScriptEvaluator;
  5352. })();
  5353. // Most of the PDFs functions consist of simple operations such as:
  5354. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5355. //
  5356. // We can compile most of such programs, and at the same moment, we can
  5357. // optimize some expressions using basic math properties. Keeping track of
  5358. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5359. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5360. function AstNode(type) {
  5361. this.type = type;
  5362. }
  5363. AstNode.prototype.visit = function (visitor) {
  5364. throw new Error('abstract method');
  5365. };
  5366. function AstArgument(index, min, max) {
  5367. AstNode.call(this, 'args');
  5368. this.index = index;
  5369. this.min = min;
  5370. this.max = max;
  5371. }
  5372. AstArgument.prototype = Object.create(AstNode.prototype);
  5373. AstArgument.prototype.visit = function (visitor) {
  5374. visitor.visitArgument(this);
  5375. };
  5376. function AstLiteral(number) {
  5377. AstNode.call(this, 'literal');
  5378. this.number = number;
  5379. this.min = number;
  5380. this.max = number;
  5381. }
  5382. AstLiteral.prototype = Object.create(AstNode.prototype);
  5383. AstLiteral.prototype.visit = function (visitor) {
  5384. visitor.visitLiteral(this);
  5385. };
  5386. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5387. AstNode.call(this, 'binary');
  5388. this.op = op;
  5389. this.arg1 = arg1;
  5390. this.arg2 = arg2;
  5391. this.min = min;
  5392. this.max = max;
  5393. }
  5394. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5395. AstBinaryOperation.prototype.visit = function (visitor) {
  5396. visitor.visitBinaryOperation(this);
  5397. };
  5398. function AstMin(arg, max) {
  5399. AstNode.call(this, 'max');
  5400. this.arg = arg;
  5401. this.min = arg.min;
  5402. this.max = max;
  5403. }
  5404. AstMin.prototype = Object.create(AstNode.prototype);
  5405. AstMin.prototype.visit = function (visitor) {
  5406. visitor.visitMin(this);
  5407. };
  5408. function AstVariable(index, min, max) {
  5409. AstNode.call(this, 'var');
  5410. this.index = index;
  5411. this.min = min;
  5412. this.max = max;
  5413. }
  5414. AstVariable.prototype = Object.create(AstNode.prototype);
  5415. AstVariable.prototype.visit = function (visitor) {
  5416. visitor.visitVariable(this);
  5417. };
  5418. function AstVariableDefinition(variable, arg) {
  5419. AstNode.call(this, 'definition');
  5420. this.variable = variable;
  5421. this.arg = arg;
  5422. }
  5423. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5424. AstVariableDefinition.prototype.visit = function (visitor) {
  5425. visitor.visitVariableDefinition(this);
  5426. };
  5427. function ExpressionBuilderVisitor() {
  5428. this.parts = [];
  5429. }
  5430. ExpressionBuilderVisitor.prototype = {
  5431. visitArgument: function (arg) {
  5432. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5433. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5434. },
  5435. visitVariable: function (variable) {
  5436. this.parts.push('v', variable.index);
  5437. },
  5438. visitLiteral: function (literal) {
  5439. this.parts.push(literal.number);
  5440. },
  5441. visitBinaryOperation: function (operation) {
  5442. this.parts.push('(');
  5443. operation.arg1.visit(this);
  5444. this.parts.push(' ', operation.op, ' ');
  5445. operation.arg2.visit(this);
  5446. this.parts.push(')');
  5447. },
  5448. visitVariableDefinition: function (definition) {
  5449. this.parts.push('var ');
  5450. definition.variable.visit(this);
  5451. this.parts.push(' = ');
  5452. definition.arg.visit(this);
  5453. this.parts.push(';');
  5454. },
  5455. visitMin: function (max) {
  5456. this.parts.push('Math.min(');
  5457. max.arg.visit(this);
  5458. this.parts.push(', ', max.max, ')');
  5459. },
  5460. toString: function () {
  5461. return this.parts.join('');
  5462. }
  5463. };
  5464. function buildAddOperation(num1, num2) {
  5465. if (num2.type === 'literal' && num2.number === 0) {
  5466. // optimization: second operand is 0
  5467. return num1;
  5468. }
  5469. if (num1.type === 'literal' && num1.number === 0) {
  5470. // optimization: first operand is 0
  5471. return num2;
  5472. }
  5473. if (num2.type === 'literal' && num1.type === 'literal') {
  5474. // optimization: operands operand are literals
  5475. return new AstLiteral(num1.number + num2.number);
  5476. }
  5477. return new AstBinaryOperation('+', num1, num2,
  5478. num1.min + num2.min, num1.max + num2.max);
  5479. }
  5480. function buildMulOperation(num1, num2) {
  5481. if (num2.type === 'literal') {
  5482. // optimization: second operands is a literal...
  5483. if (num2.number === 0) {
  5484. return new AstLiteral(0); // and it's 0
  5485. } else if (num2.number === 1) {
  5486. return num1; // and it's 1
  5487. } else if (num1.type === 'literal') {
  5488. // ... and first operands is a literal too
  5489. return new AstLiteral(num1.number * num2.number);
  5490. }
  5491. }
  5492. if (num1.type === 'literal') {
  5493. // optimization: first operands is a literal...
  5494. if (num1.number === 0) {
  5495. return new AstLiteral(0); // and it's 0
  5496. } else if (num1.number === 1) {
  5497. return num2; // and it's 1
  5498. }
  5499. }
  5500. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5501. num1.max * num2.min, num1.max * num2.max);
  5502. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5503. num1.max * num2.min, num1.max * num2.max);
  5504. return new AstBinaryOperation('*', num1, num2, min, max);
  5505. }
  5506. function buildSubOperation(num1, num2) {
  5507. if (num2.type === 'literal') {
  5508. // optimization: second operands is a literal...
  5509. if (num2.number === 0) {
  5510. return num1; // ... and it's 0
  5511. } else if (num1.type === 'literal') {
  5512. // ... and first operands is a literal too
  5513. return new AstLiteral(num1.number - num2.number);
  5514. }
  5515. }
  5516. if (num2.type === 'binary' && num2.op === '-' &&
  5517. num1.type === 'literal' && num1.number === 1 &&
  5518. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5519. // optimization for case: 1 - (1 - x)
  5520. return num2.arg2;
  5521. }
  5522. return new AstBinaryOperation('-', num1, num2,
  5523. num1.min - num2.max, num1.max - num2.min);
  5524. }
  5525. function buildMinOperation(num1, max) {
  5526. if (num1.min >= max) {
  5527. // optimization: num1 min value is not less than required max
  5528. return new AstLiteral(max); // just returning max
  5529. } else if (num1.max <= max) {
  5530. // optimization: num1 max value is not greater than required max
  5531. return num1; // just returning an argument
  5532. }
  5533. return new AstMin(num1, max);
  5534. }
  5535. function PostScriptCompiler() {}
  5536. PostScriptCompiler.prototype = {
  5537. compile: function PostScriptCompiler_compile(code, domain, range) {
  5538. var stack = [];
  5539. var i, ii;
  5540. var instructions = [];
  5541. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5542. var lastRegister = 0;
  5543. var n, j, min, max;
  5544. var num1, num2, ast1, ast2, tmpVar, item;
  5545. for (i = 0; i < inputSize; i++) {
  5546. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5547. }
  5548. for (i = 0, ii = code.length; i < ii; i++) {
  5549. item = code[i];
  5550. if (typeof item === 'number') {
  5551. stack.push(new AstLiteral(item));
  5552. continue;
  5553. }
  5554. switch (item) {
  5555. case 'add':
  5556. if (stack.length < 2) {
  5557. return null;
  5558. }
  5559. num2 = stack.pop();
  5560. num1 = stack.pop();
  5561. stack.push(buildAddOperation(num1, num2));
  5562. break;
  5563. case 'cvr':
  5564. if (stack.length < 1) {
  5565. return null;
  5566. }
  5567. break;
  5568. case 'mul':
  5569. if (stack.length < 2) {
  5570. return null;
  5571. }
  5572. num2 = stack.pop();
  5573. num1 = stack.pop();
  5574. stack.push(buildMulOperation(num1, num2));
  5575. break;
  5576. case 'sub':
  5577. if (stack.length < 2) {
  5578. return null;
  5579. }
  5580. num2 = stack.pop();
  5581. num1 = stack.pop();
  5582. stack.push(buildSubOperation(num1, num2));
  5583. break;
  5584. case 'exch':
  5585. if (stack.length < 2) {
  5586. return null;
  5587. }
  5588. ast1 = stack.pop(); ast2 = stack.pop();
  5589. stack.push(ast1, ast2);
  5590. break;
  5591. case 'pop':
  5592. if (stack.length < 1) {
  5593. return null;
  5594. }
  5595. stack.pop();
  5596. break;
  5597. case 'index':
  5598. if (stack.length < 1) {
  5599. return null;
  5600. }
  5601. num1 = stack.pop();
  5602. if (num1.type !== 'literal') {
  5603. return null;
  5604. }
  5605. n = num1.number;
  5606. if (n < 0 || (n|0) !== n || stack.length < n) {
  5607. return null;
  5608. }
  5609. ast1 = stack[stack.length - n - 1];
  5610. if (ast1.type === 'literal' || ast1.type === 'var') {
  5611. stack.push(ast1);
  5612. break;
  5613. }
  5614. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5615. stack[stack.length - n - 1] = tmpVar;
  5616. stack.push(tmpVar);
  5617. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5618. break;
  5619. case 'dup':
  5620. if (stack.length < 1) {
  5621. return null;
  5622. }
  5623. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5624. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5625. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5626. // special case of the commands sequence for the min operation
  5627. num1 = stack.pop();
  5628. stack.push(buildMinOperation(num1, code[i + 1]));
  5629. i += 6;
  5630. break;
  5631. }
  5632. ast1 = stack[stack.length - 1];
  5633. if (ast1.type === 'literal' || ast1.type === 'var') {
  5634. // we don't have to save into intermediate variable a literal or
  5635. // variable.
  5636. stack.push(ast1);
  5637. break;
  5638. }
  5639. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5640. stack[stack.length - 1] = tmpVar;
  5641. stack.push(tmpVar);
  5642. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5643. break;
  5644. case 'roll':
  5645. if (stack.length < 2) {
  5646. return null;
  5647. }
  5648. num2 = stack.pop();
  5649. num1 = stack.pop();
  5650. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5651. // both roll operands must be numbers
  5652. return null;
  5653. }
  5654. j = num2.number;
  5655. n = num1.number;
  5656. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5657. // ... and integers
  5658. return null;
  5659. }
  5660. j = ((j % n) + n) % n;
  5661. if (j === 0) {
  5662. break; // just skipping -- there are nothing to rotate
  5663. }
  5664. Array.prototype.push.apply(stack,
  5665. stack.splice(stack.length - n, n - j));
  5666. break;
  5667. default:
  5668. return null; // unsupported operator
  5669. }
  5670. }
  5671. if (stack.length !== outputSize) {
  5672. return null;
  5673. }
  5674. var result = [];
  5675. instructions.forEach(function (instruction) {
  5676. var statementBuilder = new ExpressionBuilderVisitor();
  5677. instruction.visit(statementBuilder);
  5678. result.push(statementBuilder.toString());
  5679. });
  5680. stack.forEach(function (expr, i) {
  5681. var statementBuilder = new ExpressionBuilderVisitor();
  5682. expr.visit(statementBuilder);
  5683. var min = range[i * 2], max = range[i * 2 + 1];
  5684. var out = [statementBuilder.toString()];
  5685. if (min > expr.min) {
  5686. out.unshift('Math.max(', min, ', ');
  5687. out.push(')');
  5688. }
  5689. if (max < expr.max) {
  5690. out.unshift('Math.min(', max, ', ');
  5691. out.push(')');
  5692. }
  5693. out.unshift('dest[destOffset + ', i, '] = ');
  5694. out.push(';');
  5695. result.push(out.join(''));
  5696. });
  5697. return result.join('\n');
  5698. }
  5699. };
  5700. return PostScriptCompiler;
  5701. })();
  5702. var ColorSpace = (function ColorSpaceClosure() {
  5703. // Constructor should define this.numComps, this.defaultColor, this.name
  5704. function ColorSpace() {
  5705. error('should not call ColorSpace constructor');
  5706. }
  5707. ColorSpace.prototype = {
  5708. /**
  5709. * Converts the color value to the RGB color. The color components are
  5710. * located in the src array starting from the srcOffset. Returns the array
  5711. * of the rgb components, each value ranging from [0,255].
  5712. */
  5713. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5714. var rgb = new Uint8Array(3);
  5715. this.getRgbItem(src, srcOffset, rgb, 0);
  5716. return rgb;
  5717. },
  5718. /**
  5719. * Converts the color value to the RGB color, similar to the getRgb method.
  5720. * The result placed into the dest array starting from the destOffset.
  5721. */
  5722. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5723. dest, destOffset) {
  5724. error('Should not call ColorSpace.getRgbItem');
  5725. },
  5726. /**
  5727. * Converts the specified number of the color values to the RGB colors.
  5728. * The colors are located in the src array starting from the srcOffset.
  5729. * The result is placed into the dest array starting from the destOffset.
  5730. * The src array items shall be in [0,2^bits) range, the dest array items
  5731. * will be in [0,255] range. alpha01 indicates how many alpha components
  5732. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5733. * array).
  5734. */
  5735. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5736. dest, destOffset, bits,
  5737. alpha01) {
  5738. error('Should not call ColorSpace.getRgbBuffer');
  5739. },
  5740. /**
  5741. * Determines the number of bytes required to store the result of the
  5742. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5743. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5744. */
  5745. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5746. alpha01) {
  5747. error('Should not call ColorSpace.getOutputLength');
  5748. },
  5749. /**
  5750. * Returns true if source data will be equal the result/output data.
  5751. */
  5752. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5753. return false;
  5754. },
  5755. /**
  5756. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5757. * how many alpha components there are in the dest array; it will be either
  5758. * 0 (RGB array) or 1 (RGBA array).
  5759. */
  5760. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5761. originalHeight, width, height,
  5762. actualHeight, bpc, comps, alpha01) {
  5763. var count = originalWidth * originalHeight;
  5764. var rgbBuf = null;
  5765. var numComponentColors = 1 << bpc;
  5766. var needsResizing = originalHeight !== height || originalWidth !== width;
  5767. var i, ii;
  5768. if (this.isPassthrough(bpc)) {
  5769. rgbBuf = comps;
  5770. } else if (this.numComps === 1 && count > numComponentColors &&
  5771. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5772. // Optimization: create a color map when there is just one component and
  5773. // we are converting more colors than the size of the color map. We
  5774. // don't build the map if the colorspace is gray or rgb since those
  5775. // methods are faster than building a map. This mainly offers big speed
  5776. // ups for indexed and alternate colorspaces.
  5777. //
  5778. // TODO it may be worth while to cache the color map. While running
  5779. // testing I never hit a cache so I will leave that out for now (perhaps
  5780. // we are reparsing colorspaces too much?).
  5781. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5782. new Uint16Array(numComponentColors);
  5783. var key;
  5784. for (i = 0; i < numComponentColors; i++) {
  5785. allColors[i] = i;
  5786. }
  5787. var colorMap = new Uint8Array(numComponentColors * 3);
  5788. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5789. /* alpha01 = */ 0);
  5790. var destPos, rgbPos;
  5791. if (!needsResizing) {
  5792. // Fill in the RGB values directly into |dest|.
  5793. destPos = 0;
  5794. for (i = 0; i < count; ++i) {
  5795. key = comps[i] * 3;
  5796. dest[destPos++] = colorMap[key];
  5797. dest[destPos++] = colorMap[key + 1];
  5798. dest[destPos++] = colorMap[key + 2];
  5799. destPos += alpha01;
  5800. }
  5801. } else {
  5802. rgbBuf = new Uint8Array(count * 3);
  5803. rgbPos = 0;
  5804. for (i = 0; i < count; ++i) {
  5805. key = comps[i] * 3;
  5806. rgbBuf[rgbPos++] = colorMap[key];
  5807. rgbBuf[rgbPos++] = colorMap[key + 1];
  5808. rgbBuf[rgbPos++] = colorMap[key + 2];
  5809. }
  5810. }
  5811. } else {
  5812. if (!needsResizing) {
  5813. // Fill in the RGB values directly into |dest|.
  5814. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5815. alpha01);
  5816. } else {
  5817. rgbBuf = new Uint8Array(count * 3);
  5818. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5819. /* alpha01 = */ 0);
  5820. }
  5821. }
  5822. if (rgbBuf) {
  5823. if (needsResizing) {
  5824. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5825. height, dest, alpha01);
  5826. } else {
  5827. rgbPos = 0;
  5828. destPos = 0;
  5829. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5830. dest[destPos++] = rgbBuf[rgbPos++];
  5831. dest[destPos++] = rgbBuf[rgbPos++];
  5832. dest[destPos++] = rgbBuf[rgbPos++];
  5833. destPos += alpha01;
  5834. }
  5835. }
  5836. }
  5837. },
  5838. /**
  5839. * True if the colorspace has components in the default range of [0, 1].
  5840. * This should be true for all colorspaces except for lab color spaces
  5841. * which are [0,100], [-128, 127], [-128, 127].
  5842. */
  5843. usesZeroToOneRange: true
  5844. };
  5845. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5846. var IR = ColorSpace.parseToIR(cs, xref, res);
  5847. if (IR instanceof AlternateCS) {
  5848. return IR;
  5849. }
  5850. return ColorSpace.fromIR(IR);
  5851. };
  5852. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5853. var name = isArray(IR) ? IR[0] : IR;
  5854. var whitePoint, blackPoint, gamma;
  5855. switch (name) {
  5856. case 'DeviceGrayCS':
  5857. return this.singletons.gray;
  5858. case 'DeviceRgbCS':
  5859. return this.singletons.rgb;
  5860. case 'DeviceCmykCS':
  5861. return this.singletons.cmyk;
  5862. case 'CalGrayCS':
  5863. whitePoint = IR[1].WhitePoint;
  5864. blackPoint = IR[1].BlackPoint;
  5865. gamma = IR[1].Gamma;
  5866. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5867. case 'CalRGBCS':
  5868. whitePoint = IR[1].WhitePoint;
  5869. blackPoint = IR[1].BlackPoint;
  5870. gamma = IR[1].Gamma;
  5871. var matrix = IR[1].Matrix;
  5872. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5873. case 'PatternCS':
  5874. var basePatternCS = IR[1];
  5875. if (basePatternCS) {
  5876. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5877. }
  5878. return new PatternCS(basePatternCS);
  5879. case 'IndexedCS':
  5880. var baseIndexedCS = IR[1];
  5881. var hiVal = IR[2];
  5882. var lookup = IR[3];
  5883. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  5884. case 'AlternateCS':
  5885. var numComps = IR[1];
  5886. var alt = IR[2];
  5887. var tintFnIR = IR[3];
  5888. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  5889. PDFFunction.fromIR(tintFnIR));
  5890. case 'LabCS':
  5891. whitePoint = IR[1].WhitePoint;
  5892. blackPoint = IR[1].BlackPoint;
  5893. var range = IR[1].Range;
  5894. return new LabCS(whitePoint, blackPoint, range);
  5895. default:
  5896. error('Unknown name ' + name);
  5897. }
  5898. return null;
  5899. };
  5900. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  5901. if (isName(cs)) {
  5902. var colorSpaces = res.get('ColorSpace');
  5903. if (isDict(colorSpaces)) {
  5904. var refcs = colorSpaces.get(cs.name);
  5905. if (refcs) {
  5906. cs = refcs;
  5907. }
  5908. }
  5909. }
  5910. cs = xref.fetchIfRef(cs);
  5911. var mode;
  5912. if (isName(cs)) {
  5913. mode = cs.name;
  5914. this.mode = mode;
  5915. switch (mode) {
  5916. case 'DeviceGray':
  5917. case 'G':
  5918. return 'DeviceGrayCS';
  5919. case 'DeviceRGB':
  5920. case 'RGB':
  5921. return 'DeviceRgbCS';
  5922. case 'DeviceCMYK':
  5923. case 'CMYK':
  5924. return 'DeviceCmykCS';
  5925. case 'Pattern':
  5926. return ['PatternCS', null];
  5927. default:
  5928. error('unrecognized colorspace ' + mode);
  5929. }
  5930. } else if (isArray(cs)) {
  5931. mode = cs[0].name;
  5932. this.mode = mode;
  5933. var numComps, params;
  5934. switch (mode) {
  5935. case 'DeviceGray':
  5936. case 'G':
  5937. return 'DeviceGrayCS';
  5938. case 'DeviceRGB':
  5939. case 'RGB':
  5940. return 'DeviceRgbCS';
  5941. case 'DeviceCMYK':
  5942. case 'CMYK':
  5943. return 'DeviceCmykCS';
  5944. case 'CalGray':
  5945. params = cs[1].getAll();
  5946. return ['CalGrayCS', params];
  5947. case 'CalRGB':
  5948. params = cs[1].getAll();
  5949. return ['CalRGBCS', params];
  5950. case 'ICCBased':
  5951. var stream = xref.fetchIfRef(cs[1]);
  5952. var dict = stream.dict;
  5953. numComps = dict.get('N');
  5954. if (numComps === 1) {
  5955. return 'DeviceGrayCS';
  5956. } else if (numComps === 3) {
  5957. return 'DeviceRgbCS';
  5958. } else if (numComps === 4) {
  5959. return 'DeviceCmykCS';
  5960. }
  5961. break;
  5962. case 'Pattern':
  5963. var basePatternCS = cs[1];
  5964. if (basePatternCS) {
  5965. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  5966. }
  5967. return ['PatternCS', basePatternCS];
  5968. case 'Indexed':
  5969. case 'I':
  5970. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  5971. var hiVal = cs[2] + 1;
  5972. var lookup = xref.fetchIfRef(cs[3]);
  5973. if (isStream(lookup)) {
  5974. lookup = lookup.getBytes();
  5975. }
  5976. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  5977. case 'Separation':
  5978. case 'DeviceN':
  5979. var name = cs[1];
  5980. numComps = 1;
  5981. if (isName(name)) {
  5982. numComps = 1;
  5983. } else if (isArray(name)) {
  5984. numComps = name.length;
  5985. }
  5986. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  5987. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  5988. return ['AlternateCS', numComps, alt, tintFnIR];
  5989. case 'Lab':
  5990. params = cs[1].getAll();
  5991. return ['LabCS', params];
  5992. default:
  5993. error('unimplemented color space object "' + mode + '"');
  5994. }
  5995. } else {
  5996. error('unrecognized color space object: "' + cs + '"');
  5997. }
  5998. return null;
  5999. };
  6000. /**
  6001. * Checks if a decode map matches the default decode map for a color space.
  6002. * This handles the general decode maps where there are two values per
  6003. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6004. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6005. * slightly different.
  6006. * @param {Array} decode Decode map (usually from an image).
  6007. * @param {Number} n Number of components the color space has.
  6008. */
  6009. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6010. if (!decode) {
  6011. return true;
  6012. }
  6013. if (n * 2 !== decode.length) {
  6014. warn('The decode map is not the correct length');
  6015. return true;
  6016. }
  6017. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6018. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6019. return false;
  6020. }
  6021. }
  6022. return true;
  6023. };
  6024. ColorSpace.singletons = {
  6025. get gray() {
  6026. return shadow(this, 'gray', new DeviceGrayCS());
  6027. },
  6028. get rgb() {
  6029. return shadow(this, 'rgb', new DeviceRgbCS());
  6030. },
  6031. get cmyk() {
  6032. return shadow(this, 'cmyk', new DeviceCmykCS());
  6033. }
  6034. };
  6035. return ColorSpace;
  6036. })();
  6037. /**
  6038. * Alternate color space handles both Separation and DeviceN color spaces. A
  6039. * Separation color space is actually just a DeviceN with one color component.
  6040. * Both color spaces use a tinting function to convert colors to a base color
  6041. * space.
  6042. */
  6043. var AlternateCS = (function AlternateCSClosure() {
  6044. function AlternateCS(numComps, base, tintFn) {
  6045. this.name = 'Alternate';
  6046. this.numComps = numComps;
  6047. this.defaultColor = new Float32Array(numComps);
  6048. for (var i = 0; i < numComps; ++i) {
  6049. this.defaultColor[i] = 1;
  6050. }
  6051. this.base = base;
  6052. this.tintFn = tintFn;
  6053. this.tmpBuf = new Float32Array(base.numComps);
  6054. }
  6055. AlternateCS.prototype = {
  6056. getRgb: ColorSpace.prototype.getRgb,
  6057. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6058. dest, destOffset) {
  6059. var tmpBuf = this.tmpBuf;
  6060. this.tintFn(src, srcOffset, tmpBuf, 0);
  6061. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6062. },
  6063. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6064. dest, destOffset, bits,
  6065. alpha01) {
  6066. var tintFn = this.tintFn;
  6067. var base = this.base;
  6068. var scale = 1 / ((1 << bits) - 1);
  6069. var baseNumComps = base.numComps;
  6070. var usesZeroToOneRange = base.usesZeroToOneRange;
  6071. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6072. alpha01 === 0;
  6073. var pos = isPassthrough ? destOffset : 0;
  6074. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6075. var numComps = this.numComps;
  6076. var scaled = new Float32Array(numComps);
  6077. var tinted = new Float32Array(baseNumComps);
  6078. var i, j;
  6079. if (usesZeroToOneRange) {
  6080. for (i = 0; i < count; i++) {
  6081. for (j = 0; j < numComps; j++) {
  6082. scaled[j] = src[srcOffset++] * scale;
  6083. }
  6084. tintFn(scaled, 0, tinted, 0);
  6085. for (j = 0; j < baseNumComps; j++) {
  6086. baseBuf[pos++] = tinted[j] * 255;
  6087. }
  6088. }
  6089. } else {
  6090. for (i = 0; i < count; i++) {
  6091. for (j = 0; j < numComps; j++) {
  6092. scaled[j] = src[srcOffset++] * scale;
  6093. }
  6094. tintFn(scaled, 0, tinted, 0);
  6095. base.getRgbItem(tinted, 0, baseBuf, pos);
  6096. pos += baseNumComps;
  6097. }
  6098. }
  6099. if (!isPassthrough) {
  6100. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6101. }
  6102. },
  6103. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6104. alpha01) {
  6105. return this.base.getOutputLength(inputLength *
  6106. this.base.numComps / this.numComps,
  6107. alpha01);
  6108. },
  6109. isPassthrough: ColorSpace.prototype.isPassthrough,
  6110. fillRgb: ColorSpace.prototype.fillRgb,
  6111. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6112. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6113. },
  6114. usesZeroToOneRange: true
  6115. };
  6116. return AlternateCS;
  6117. })();
  6118. var PatternCS = (function PatternCSClosure() {
  6119. function PatternCS(baseCS) {
  6120. this.name = 'Pattern';
  6121. this.base = baseCS;
  6122. }
  6123. PatternCS.prototype = {};
  6124. return PatternCS;
  6125. })();
  6126. var IndexedCS = (function IndexedCSClosure() {
  6127. function IndexedCS(base, highVal, lookup) {
  6128. this.name = 'Indexed';
  6129. this.numComps = 1;
  6130. this.defaultColor = new Uint8Array([0]);
  6131. this.base = base;
  6132. this.highVal = highVal;
  6133. var baseNumComps = base.numComps;
  6134. var length = baseNumComps * highVal;
  6135. var lookupArray;
  6136. if (isStream(lookup)) {
  6137. lookupArray = new Uint8Array(length);
  6138. var bytes = lookup.getBytes(length);
  6139. lookupArray.set(bytes);
  6140. } else if (isString(lookup)) {
  6141. lookupArray = new Uint8Array(length);
  6142. for (var i = 0; i < length; ++i) {
  6143. lookupArray[i] = lookup.charCodeAt(i);
  6144. }
  6145. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6146. lookupArray = lookup;
  6147. } else {
  6148. error('Unrecognized lookup table: ' + lookup);
  6149. }
  6150. this.lookup = lookupArray;
  6151. }
  6152. IndexedCS.prototype = {
  6153. getRgb: ColorSpace.prototype.getRgb,
  6154. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6155. dest, destOffset) {
  6156. var numComps = this.base.numComps;
  6157. var start = src[srcOffset] * numComps;
  6158. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6159. },
  6160. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6161. dest, destOffset, bits,
  6162. alpha01) {
  6163. var base = this.base;
  6164. var numComps = base.numComps;
  6165. var outputDelta = base.getOutputLength(numComps, alpha01);
  6166. var lookup = this.lookup;
  6167. for (var i = 0; i < count; ++i) {
  6168. var lookupPos = src[srcOffset++] * numComps;
  6169. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6170. destOffset += outputDelta;
  6171. }
  6172. },
  6173. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6174. return this.base.getOutputLength(inputLength * this.base.numComps,
  6175. alpha01);
  6176. },
  6177. isPassthrough: ColorSpace.prototype.isPassthrough,
  6178. fillRgb: ColorSpace.prototype.fillRgb,
  6179. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6180. // indexed color maps shouldn't be changed
  6181. return true;
  6182. },
  6183. usesZeroToOneRange: true
  6184. };
  6185. return IndexedCS;
  6186. })();
  6187. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6188. function DeviceGrayCS() {
  6189. this.name = 'DeviceGray';
  6190. this.numComps = 1;
  6191. this.defaultColor = new Float32Array([0]);
  6192. }
  6193. DeviceGrayCS.prototype = {
  6194. getRgb: ColorSpace.prototype.getRgb,
  6195. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6196. dest, destOffset) {
  6197. var c = (src[srcOffset] * 255) | 0;
  6198. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6199. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6200. },
  6201. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6202. dest, destOffset, bits,
  6203. alpha01) {
  6204. var scale = 255 / ((1 << bits) - 1);
  6205. var j = srcOffset, q = destOffset;
  6206. for (var i = 0; i < count; ++i) {
  6207. var c = (scale * src[j++]) | 0;
  6208. dest[q++] = c;
  6209. dest[q++] = c;
  6210. dest[q++] = c;
  6211. q += alpha01;
  6212. }
  6213. },
  6214. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6215. alpha01) {
  6216. return inputLength * (3 + alpha01);
  6217. },
  6218. isPassthrough: ColorSpace.prototype.isPassthrough,
  6219. fillRgb: ColorSpace.prototype.fillRgb,
  6220. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6221. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6222. },
  6223. usesZeroToOneRange: true
  6224. };
  6225. return DeviceGrayCS;
  6226. })();
  6227. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6228. function DeviceRgbCS() {
  6229. this.name = 'DeviceRGB';
  6230. this.numComps = 3;
  6231. this.defaultColor = new Float32Array([0, 0, 0]);
  6232. }
  6233. DeviceRgbCS.prototype = {
  6234. getRgb: ColorSpace.prototype.getRgb,
  6235. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6236. dest, destOffset) {
  6237. var r = (src[srcOffset] * 255) | 0;
  6238. var g = (src[srcOffset + 1] * 255) | 0;
  6239. var b = (src[srcOffset + 2] * 255) | 0;
  6240. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6241. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6242. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6243. },
  6244. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6245. dest, destOffset, bits,
  6246. alpha01) {
  6247. if (bits === 8 && alpha01 === 0) {
  6248. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6249. return;
  6250. }
  6251. var scale = 255 / ((1 << bits) - 1);
  6252. var j = srcOffset, q = destOffset;
  6253. for (var i = 0; i < count; ++i) {
  6254. dest[q++] = (scale * src[j++]) | 0;
  6255. dest[q++] = (scale * src[j++]) | 0;
  6256. dest[q++] = (scale * src[j++]) | 0;
  6257. q += alpha01;
  6258. }
  6259. },
  6260. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6261. alpha01) {
  6262. return (inputLength * (3 + alpha01) / 3) | 0;
  6263. },
  6264. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6265. return bits === 8;
  6266. },
  6267. fillRgb: ColorSpace.prototype.fillRgb,
  6268. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6269. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6270. },
  6271. usesZeroToOneRange: true
  6272. };
  6273. return DeviceRgbCS;
  6274. })();
  6275. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6276. // The coefficients below was found using numerical analysis: the method of
  6277. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6278. // where color_value is the tabular value from the table of sampled RGB colors
  6279. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6280. // CMYK color conversion using the estimation below:
  6281. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6282. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6283. var c = src[srcOffset + 0] * srcScale;
  6284. var m = src[srcOffset + 1] * srcScale;
  6285. var y = src[srcOffset + 2] * srcScale;
  6286. var k = src[srcOffset + 3] * srcScale;
  6287. var r =
  6288. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6289. 18.82290502165302 * y + 212.25662451639585 * k +
  6290. -285.2331026137004) +
  6291. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6292. -17.873870861415444 * k - 5.497006427196366) +
  6293. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6294. 17.5119270841813) +
  6295. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6296. var g =
  6297. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6298. 6.871425592049007 * y + 31.159100130055922 * k +
  6299. -79.2970844816548) +
  6300. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6301. 131.35250912493976 * k - 190.9453302588951) +
  6302. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6303. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6304. var b =
  6305. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6306. 30.89978309703729 * y - 0.23883238689178934 * k +
  6307. -14.183576799673286) +
  6308. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6309. 50.606957656360734 * k - 112.23884253719248) +
  6310. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6311. -193.58209356861505) +
  6312. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6313. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6314. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6315. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6316. }
  6317. function DeviceCmykCS() {
  6318. this.name = 'DeviceCMYK';
  6319. this.numComps = 4;
  6320. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6321. }
  6322. DeviceCmykCS.prototype = {
  6323. getRgb: ColorSpace.prototype.getRgb,
  6324. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6325. dest, destOffset) {
  6326. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6327. },
  6328. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6329. dest, destOffset, bits,
  6330. alpha01) {
  6331. var scale = 1 / ((1 << bits) - 1);
  6332. for (var i = 0; i < count; i++) {
  6333. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6334. srcOffset += 4;
  6335. destOffset += 3 + alpha01;
  6336. }
  6337. },
  6338. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6339. alpha01) {
  6340. return (inputLength / 4 * (3 + alpha01)) | 0;
  6341. },
  6342. isPassthrough: ColorSpace.prototype.isPassthrough,
  6343. fillRgb: ColorSpace.prototype.fillRgb,
  6344. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6345. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6346. },
  6347. usesZeroToOneRange: true
  6348. };
  6349. return DeviceCmykCS;
  6350. })();
  6351. //
  6352. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6353. //
  6354. var CalGrayCS = (function CalGrayCSClosure() {
  6355. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6356. this.name = 'CalGray';
  6357. this.numComps = 1;
  6358. this.defaultColor = new Float32Array([0]);
  6359. if (!whitePoint) {
  6360. error('WhitePoint missing - required for color space CalGray');
  6361. }
  6362. blackPoint = blackPoint || [0, 0, 0];
  6363. gamma = gamma || 1;
  6364. // Translate arguments to spec variables.
  6365. this.XW = whitePoint[0];
  6366. this.YW = whitePoint[1];
  6367. this.ZW = whitePoint[2];
  6368. this.XB = blackPoint[0];
  6369. this.YB = blackPoint[1];
  6370. this.ZB = blackPoint[2];
  6371. this.G = gamma;
  6372. // Validate variables as per spec.
  6373. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6374. error('Invalid WhitePoint components for ' + this.name +
  6375. ', no fallback available');
  6376. }
  6377. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6378. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6379. this.XB = this.YB = this.ZB = 0;
  6380. }
  6381. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6382. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6383. ', ZB: ' + this.ZB + ', only default values are supported.');
  6384. }
  6385. if (this.G < 1) {
  6386. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6387. ', falling back to default');
  6388. this.G = 1;
  6389. }
  6390. }
  6391. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6392. // A represents a gray component of a calibrated gray space.
  6393. // A <---> AG in the spec
  6394. var A = src[srcOffset] * scale;
  6395. var AG = Math.pow(A, cs.G);
  6396. // Computes L as per spec. ( = cs.YW * AG )
  6397. // Except if other than default BlackPoint values are used.
  6398. var L = cs.YW * AG;
  6399. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6400. // Convert values to rgb range [0, 255].
  6401. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6402. dest[destOffset] = val;
  6403. dest[destOffset + 1] = val;
  6404. dest[destOffset + 2] = val;
  6405. }
  6406. CalGrayCS.prototype = {
  6407. getRgb: ColorSpace.prototype.getRgb,
  6408. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6409. dest, destOffset) {
  6410. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6411. },
  6412. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6413. dest, destOffset, bits,
  6414. alpha01) {
  6415. var scale = 1 / ((1 << bits) - 1);
  6416. for (var i = 0; i < count; ++i) {
  6417. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6418. srcOffset += 1;
  6419. destOffset += 3 + alpha01;
  6420. }
  6421. },
  6422. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6423. return inputLength * (3 + alpha01);
  6424. },
  6425. isPassthrough: ColorSpace.prototype.isPassthrough,
  6426. fillRgb: ColorSpace.prototype.fillRgb,
  6427. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6428. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6429. },
  6430. usesZeroToOneRange: true
  6431. };
  6432. return CalGrayCS;
  6433. })();
  6434. //
  6435. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6436. //
  6437. var CalRGBCS = (function CalRGBCSClosure() {
  6438. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6439. // matrices.
  6440. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6441. 0.8951, 0.2664, -0.1614,
  6442. -0.7502, 1.7135, 0.0367,
  6443. 0.0389, -0.0685, 1.0296]);
  6444. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6445. 0.9869929, -0.1470543, 0.1599627,
  6446. 0.4323053, 0.5183603, 0.0492912,
  6447. -0.0085287, 0.0400428, 0.9684867]);
  6448. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6449. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6450. 3.2404542, -1.5371385, -0.4985314,
  6451. -0.9692660, 1.8760108, 0.0415560,
  6452. 0.0556434, -0.2040259, 1.0572252]);
  6453. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6454. var tempNormalizeMatrix = new Float32Array(3);
  6455. var tempConvertMatrix1 = new Float32Array(3);
  6456. var tempConvertMatrix2 = new Float32Array(3);
  6457. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6458. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6459. this.name = 'CalRGB';
  6460. this.numComps = 3;
  6461. this.defaultColor = new Float32Array(3);
  6462. if (!whitePoint) {
  6463. error('WhitePoint missing - required for color space CalRGB');
  6464. }
  6465. blackPoint = blackPoint || new Float32Array(3);
  6466. gamma = gamma || new Float32Array([1, 1, 1]);
  6467. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6468. // Translate arguments to spec variables.
  6469. var XW = whitePoint[0];
  6470. var YW = whitePoint[1];
  6471. var ZW = whitePoint[2];
  6472. this.whitePoint = whitePoint;
  6473. var XB = blackPoint[0];
  6474. var YB = blackPoint[1];
  6475. var ZB = blackPoint[2];
  6476. this.blackPoint = blackPoint;
  6477. this.GR = gamma[0];
  6478. this.GG = gamma[1];
  6479. this.GB = gamma[2];
  6480. this.MXA = matrix[0];
  6481. this.MYA = matrix[1];
  6482. this.MZA = matrix[2];
  6483. this.MXB = matrix[3];
  6484. this.MYB = matrix[4];
  6485. this.MZB = matrix[5];
  6486. this.MXC = matrix[6];
  6487. this.MYC = matrix[7];
  6488. this.MZC = matrix[8];
  6489. // Validate variables as per spec.
  6490. if (XW < 0 || ZW < 0 || YW !== 1) {
  6491. error('Invalid WhitePoint components for ' + this.name +
  6492. ', no fallback available');
  6493. }
  6494. if (XB < 0 || YB < 0 || ZB < 0) {
  6495. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6496. ', ' + ZB + '], falling back to default');
  6497. this.blackPoint = new Float32Array(3);
  6498. }
  6499. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6500. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6501. '] for ' + this.name + ', falling back to default');
  6502. this.GR = this.GG = this.GB = 1;
  6503. }
  6504. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6505. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6506. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6507. info('Invalid Matrix for ' + this.name + ' [' +
  6508. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6509. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6510. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6511. '], falling back to default');
  6512. this.MXA = this.MYB = this.MZC = 1;
  6513. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6514. }
  6515. }
  6516. function matrixProduct(a, b, result) {
  6517. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6518. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6519. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6520. }
  6521. function convertToFlat(sourceWhitePoint, LMS, result) {
  6522. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6523. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6524. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6525. }
  6526. function convertToD65(sourceWhitePoint, LMS, result) {
  6527. var D65X = 0.95047;
  6528. var D65Y = 1;
  6529. var D65Z = 1.08883;
  6530. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6531. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6532. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6533. }
  6534. function sRGBTransferFunction(color) {
  6535. // See http://en.wikipedia.org/wiki/SRGB.
  6536. if (color <= 0.0031308){
  6537. return adjustToRange(0, 1, 12.92 * color);
  6538. }
  6539. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6540. }
  6541. function adjustToRange(min, max, value) {
  6542. return Math.max(min, Math.min(max, value));
  6543. }
  6544. function decodeL(L) {
  6545. if (L < 0) {
  6546. return -decodeL(-L);
  6547. }
  6548. if (L > 8.0) {
  6549. return Math.pow(((L + 16) / 116), 3);
  6550. }
  6551. return L * DECODE_L_CONSTANT;
  6552. }
  6553. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6554. // In case the blackPoint is already the default blackPoint then there is
  6555. // no need to do compensation.
  6556. if (sourceBlackPoint[0] === 0 &&
  6557. sourceBlackPoint[1] === 0 &&
  6558. sourceBlackPoint[2] === 0) {
  6559. result[0] = XYZ_Flat[0];
  6560. result[1] = XYZ_Flat[1];
  6561. result[2] = XYZ_Flat[2];
  6562. return;
  6563. }
  6564. // For the blackPoint calculation details, please see
  6565. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6566. // AdobeBPC.pdf.
  6567. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6568. var zeroDecodeL = decodeL(0);
  6569. var X_DST = zeroDecodeL;
  6570. var X_SRC = decodeL(sourceBlackPoint[0]);
  6571. var Y_DST = zeroDecodeL;
  6572. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6573. var Z_DST = zeroDecodeL;
  6574. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6575. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6576. var X_Offset = 1 - X_Scale;
  6577. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6578. var Y_Offset = 1 - Y_Scale;
  6579. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6580. var Z_Offset = 1 - Z_Scale;
  6581. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6582. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6583. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6584. }
  6585. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6586. // In case the whitePoint is already flat then there is no need to do
  6587. // normalization.
  6588. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6589. result[0] = XYZ_In[0];
  6590. result[1] = XYZ_In[1];
  6591. result[2] = XYZ_In[2];
  6592. return;
  6593. }
  6594. var LMS = result;
  6595. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6596. var LMS_Flat = tempNormalizeMatrix;
  6597. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6598. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6599. }
  6600. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6601. var LMS = result;
  6602. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6603. var LMS_D65 = tempNormalizeMatrix;
  6604. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6605. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6606. }
  6607. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6608. // A, B and C represent a red, green and blue components of a calibrated
  6609. // rgb space.
  6610. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6611. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6612. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6613. // A <---> AGR in the spec
  6614. // B <---> BGG in the spec
  6615. // C <---> CGB in the spec
  6616. var AGR = Math.pow(A, cs.GR);
  6617. var BGG = Math.pow(B, cs.GG);
  6618. var CGB = Math.pow(C, cs.GB);
  6619. // Computes intermediate variables L, M, N as per spec.
  6620. // To decode X, Y, Z values map L, M, N directly to them.
  6621. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6622. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6623. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6624. // The following calculations are based on this document:
  6625. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6626. // AdobeBPC.pdf.
  6627. var XYZ = tempConvertMatrix1;
  6628. XYZ[0] = X;
  6629. XYZ[1] = Y;
  6630. XYZ[2] = Z;
  6631. var XYZ_Flat = tempConvertMatrix2;
  6632. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6633. var XYZ_Black = tempConvertMatrix1;
  6634. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6635. var XYZ_D65 = tempConvertMatrix2;
  6636. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6637. var SRGB = tempConvertMatrix1;
  6638. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6639. var sR = sRGBTransferFunction(SRGB[0]);
  6640. var sG = sRGBTransferFunction(SRGB[1]);
  6641. var sB = sRGBTransferFunction(SRGB[2]);
  6642. // Convert the values to rgb range [0, 255].
  6643. dest[destOffset] = Math.round(sR * 255);
  6644. dest[destOffset + 1] = Math.round(sG * 255);
  6645. dest[destOffset + 2] = Math.round(sB * 255);
  6646. }
  6647. CalRGBCS.prototype = {
  6648. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6649. var rgb = new Uint8Array(3);
  6650. this.getRgbItem(src, srcOffset, rgb, 0);
  6651. return rgb;
  6652. },
  6653. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6654. dest, destOffset) {
  6655. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6656. },
  6657. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6658. dest, destOffset, bits,
  6659. alpha01) {
  6660. var scale = 1 / ((1 << bits) - 1);
  6661. for (var i = 0; i < count; ++i) {
  6662. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6663. srcOffset += 3;
  6664. destOffset += 3 + alpha01;
  6665. }
  6666. },
  6667. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6668. return (inputLength * (3 + alpha01) / 3) | 0;
  6669. },
  6670. isPassthrough: ColorSpace.prototype.isPassthrough,
  6671. fillRgb: ColorSpace.prototype.fillRgb,
  6672. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6673. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6674. },
  6675. usesZeroToOneRange: true
  6676. };
  6677. return CalRGBCS;
  6678. })();
  6679. //
  6680. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6681. //
  6682. var LabCS = (function LabCSClosure() {
  6683. function LabCS(whitePoint, blackPoint, range) {
  6684. this.name = 'Lab';
  6685. this.numComps = 3;
  6686. this.defaultColor = new Float32Array([0, 0, 0]);
  6687. if (!whitePoint) {
  6688. error('WhitePoint missing - required for color space Lab');
  6689. }
  6690. blackPoint = blackPoint || [0, 0, 0];
  6691. range = range || [-100, 100, -100, 100];
  6692. // Translate args to spec variables
  6693. this.XW = whitePoint[0];
  6694. this.YW = whitePoint[1];
  6695. this.ZW = whitePoint[2];
  6696. this.amin = range[0];
  6697. this.amax = range[1];
  6698. this.bmin = range[2];
  6699. this.bmax = range[3];
  6700. // These are here just for completeness - the spec doesn't offer any
  6701. // formulas that use BlackPoint in Lab
  6702. this.XB = blackPoint[0];
  6703. this.YB = blackPoint[1];
  6704. this.ZB = blackPoint[2];
  6705. // Validate vars as per spec
  6706. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6707. error('Invalid WhitePoint components, no fallback available');
  6708. }
  6709. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6710. info('Invalid BlackPoint, falling back to default');
  6711. this.XB = this.YB = this.ZB = 0;
  6712. }
  6713. if (this.amin > this.amax || this.bmin > this.bmax) {
  6714. info('Invalid Range, falling back to defaults');
  6715. this.amin = -100;
  6716. this.amax = 100;
  6717. this.bmin = -100;
  6718. this.bmax = 100;
  6719. }
  6720. }
  6721. // Function g(x) from spec
  6722. function fn_g(x) {
  6723. if (x >= 6 / 29) {
  6724. return x * x * x;
  6725. } else {
  6726. return (108 / 841) * (x - 4 / 29);
  6727. }
  6728. }
  6729. function decode(value, high1, low2, high2) {
  6730. return low2 + (value) * (high2 - low2) / (high1);
  6731. }
  6732. // If decoding is needed maxVal should be 2^bits per component - 1.
  6733. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6734. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6735. // not the usual [0, 1]. If a command like setFillColor is used the src
  6736. // values will already be within the correct range. However, if we are
  6737. // converting an image we have to map the values to the correct range given
  6738. // above.
  6739. // Ls,as,bs <---> L*,a*,b* in the spec
  6740. var Ls = src[srcOffset];
  6741. var as = src[srcOffset + 1];
  6742. var bs = src[srcOffset + 2];
  6743. if (maxVal !== false) {
  6744. Ls = decode(Ls, maxVal, 0, 100);
  6745. as = decode(as, maxVal, cs.amin, cs.amax);
  6746. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6747. }
  6748. // Adjust limits of 'as' and 'bs'
  6749. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6750. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6751. // Computes intermediate variables X,Y,Z as per spec
  6752. var M = (Ls + 16) / 116;
  6753. var L = M + (as / 500);
  6754. var N = M - (bs / 200);
  6755. var X = cs.XW * fn_g(L);
  6756. var Y = cs.YW * fn_g(M);
  6757. var Z = cs.ZW * fn_g(N);
  6758. var r, g, b;
  6759. // Using different conversions for D50 and D65 white points,
  6760. // per http://www.color.org/srgb.pdf
  6761. if (cs.ZW < 1) {
  6762. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6763. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6764. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6765. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6766. } else {
  6767. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6768. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6769. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6770. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6771. }
  6772. // clamp color values to [0,1] range then convert to [0,255] range.
  6773. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6774. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6775. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6776. }
  6777. LabCS.prototype = {
  6778. getRgb: ColorSpace.prototype.getRgb,
  6779. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6780. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6781. },
  6782. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6783. dest, destOffset, bits,
  6784. alpha01) {
  6785. var maxVal = (1 << bits) - 1;
  6786. for (var i = 0; i < count; i++) {
  6787. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6788. srcOffset += 3;
  6789. destOffset += 3 + alpha01;
  6790. }
  6791. },
  6792. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6793. return (inputLength * (3 + alpha01) / 3) | 0;
  6794. },
  6795. isPassthrough: ColorSpace.prototype.isPassthrough,
  6796. fillRgb: ColorSpace.prototype.fillRgb,
  6797. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6798. // XXX: Decoding is handled with the lab conversion because of the strange
  6799. // ranges that are used.
  6800. return true;
  6801. },
  6802. usesZeroToOneRange: false
  6803. };
  6804. return LabCS;
  6805. })();
  6806. var ARCFourCipher = (function ARCFourCipherClosure() {
  6807. function ARCFourCipher(key) {
  6808. this.a = 0;
  6809. this.b = 0;
  6810. var s = new Uint8Array(256);
  6811. var i, j = 0, tmp, keyLength = key.length;
  6812. for (i = 0; i < 256; ++i) {
  6813. s[i] = i;
  6814. }
  6815. for (i = 0; i < 256; ++i) {
  6816. tmp = s[i];
  6817. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6818. s[i] = s[j];
  6819. s[j] = tmp;
  6820. }
  6821. this.s = s;
  6822. }
  6823. ARCFourCipher.prototype = {
  6824. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6825. var i, n = data.length, tmp, tmp2;
  6826. var a = this.a, b = this.b, s = this.s;
  6827. var output = new Uint8Array(n);
  6828. for (i = 0; i < n; ++i) {
  6829. a = (a + 1) & 0xFF;
  6830. tmp = s[a];
  6831. b = (b + tmp) & 0xFF;
  6832. tmp2 = s[b];
  6833. s[a] = tmp2;
  6834. s[b] = tmp;
  6835. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6836. }
  6837. this.a = a;
  6838. this.b = b;
  6839. return output;
  6840. }
  6841. };
  6842. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6843. return ARCFourCipher;
  6844. })();
  6845. var calculateMD5 = (function calculateMD5Closure() {
  6846. var r = new Uint8Array([
  6847. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6848. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6849. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6850. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6851. var k = new Int32Array([
  6852. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6853. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6854. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6855. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6856. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6857. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6858. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6859. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6860. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6861. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6862. -145523070, -1120210379, 718787259, -343485551]);
  6863. function hash(data, offset, length) {
  6864. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6865. // pre-processing
  6866. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6867. var padded = new Uint8Array(paddedLength);
  6868. var i, j, n;
  6869. for (i = 0; i < length; ++i) {
  6870. padded[i] = data[offset++];
  6871. }
  6872. padded[i++] = 0x80;
  6873. n = paddedLength - 8;
  6874. while (i < n) {
  6875. padded[i++] = 0;
  6876. }
  6877. padded[i++] = (length << 3) & 0xFF;
  6878. padded[i++] = (length >> 5) & 0xFF;
  6879. padded[i++] = (length >> 13) & 0xFF;
  6880. padded[i++] = (length >> 21) & 0xFF;
  6881. padded[i++] = (length >>> 29) & 0xFF;
  6882. padded[i++] = 0;
  6883. padded[i++] = 0;
  6884. padded[i++] = 0;
  6885. var w = new Int32Array(16);
  6886. for (i = 0; i < paddedLength;) {
  6887. for (j = 0; j < 16; ++j, i += 4) {
  6888. w[j] = (padded[i] | (padded[i + 1] << 8) |
  6889. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  6890. }
  6891. var a = h0, b = h1, c = h2, d = h3, f, g;
  6892. for (j = 0; j < 64; ++j) {
  6893. if (j < 16) {
  6894. f = (b & c) | ((~b) & d);
  6895. g = j;
  6896. } else if (j < 32) {
  6897. f = (d & b) | ((~d) & c);
  6898. g = (5 * j + 1) & 15;
  6899. } else if (j < 48) {
  6900. f = b ^ c ^ d;
  6901. g = (3 * j + 5) & 15;
  6902. } else {
  6903. f = c ^ (b | (~d));
  6904. g = (7 * j) & 15;
  6905. }
  6906. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  6907. d = c;
  6908. c = b;
  6909. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  6910. a = tmp;
  6911. }
  6912. h0 = (h0 + a) | 0;
  6913. h1 = (h1 + b) | 0;
  6914. h2 = (h2 + c) | 0;
  6915. h3 = (h3 + d) | 0;
  6916. }
  6917. return new Uint8Array([
  6918. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  6919. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  6920. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  6921. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  6922. ]);
  6923. }
  6924. return hash;
  6925. })();
  6926. var Word64 = (function Word64Closure() {
  6927. function Word64(highInteger, lowInteger) {
  6928. this.high = highInteger | 0;
  6929. this.low = lowInteger | 0;
  6930. }
  6931. Word64.prototype = {
  6932. and: function Word64_and(word) {
  6933. this.high &= word.high;
  6934. this.low &= word.low;
  6935. },
  6936. xor: function Word64_xor(word) {
  6937. this.high ^= word.high;
  6938. this.low ^= word.low;
  6939. },
  6940. or: function Word64_or(word) {
  6941. this.high |= word.high;
  6942. this.low |= word.low;
  6943. },
  6944. shiftRight: function Word64_shiftRight(places) {
  6945. if (places >= 32) {
  6946. this.low = (this.high >>> (places - 32)) | 0;
  6947. this.high = 0;
  6948. } else {
  6949. this.low = (this.low >>> places) | (this.high << (32 - places));
  6950. this.high = (this.high >>> places) | 0;
  6951. }
  6952. },
  6953. shiftLeft: function Word64_shiftLeft(places) {
  6954. if (places >= 32) {
  6955. this.high = this.low << (places - 32);
  6956. this.low = 0;
  6957. } else {
  6958. this.high = (this.high << places) | (this.low >>> (32 - places));
  6959. this.low = this.low << places;
  6960. }
  6961. },
  6962. rotateRight: function Word64_rotateRight(places) {
  6963. var low, high;
  6964. if (places & 32) {
  6965. high = this.low;
  6966. low = this.high;
  6967. } else {
  6968. low = this.low;
  6969. high = this.high;
  6970. }
  6971. places &= 31;
  6972. this.low = (low >>> places) | (high << (32 - places));
  6973. this.high = (high >>> places) | (low << (32 - places));
  6974. },
  6975. not: function Word64_not() {
  6976. this.high = ~this.high;
  6977. this.low = ~this.low;
  6978. },
  6979. add: function Word64_add(word) {
  6980. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  6981. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  6982. if (lowAdd > 0xFFFFFFFF) {
  6983. highAdd += 1;
  6984. }
  6985. this.low = lowAdd | 0;
  6986. this.high = highAdd | 0;
  6987. },
  6988. copyTo: function Word64_copyTo(bytes, offset) {
  6989. bytes[offset] = (this.high >>> 24) & 0xFF;
  6990. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  6991. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  6992. bytes[offset + 3] = this.high & 0xFF;
  6993. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  6994. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  6995. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  6996. bytes[offset + 7] = this.low & 0xFF;
  6997. },
  6998. assign: function Word64_assign(word) {
  6999. this.high = word.high;
  7000. this.low = word.low;
  7001. }
  7002. };
  7003. return Word64;
  7004. })();
  7005. var calculateSHA256 = (function calculateSHA256Closure() {
  7006. function rotr(x, n) {
  7007. return (x >>> n) | (x << 32 - n);
  7008. }
  7009. function ch(x, y, z) {
  7010. return (x & y) ^ (~x & z);
  7011. }
  7012. function maj(x, y, z) {
  7013. return (x & y) ^ (x & z) ^ (y & z);
  7014. }
  7015. function sigma(x) {
  7016. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7017. }
  7018. function sigmaPrime(x) {
  7019. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7020. }
  7021. function littleSigma(x) {
  7022. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7023. }
  7024. function littleSigmaPrime(x) {
  7025. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7026. }
  7027. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7028. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7029. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7030. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7031. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7032. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7033. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7034. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7035. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7036. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7037. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7038. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7039. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7040. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7041. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7042. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7043. function hash(data, offset, length) {
  7044. // initial hash values
  7045. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7046. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7047. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7048. // pre-processing
  7049. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7050. var padded = new Uint8Array(paddedLength);
  7051. var i, j, n;
  7052. for (i = 0; i < length; ++i) {
  7053. padded[i] = data[offset++];
  7054. }
  7055. padded[i++] = 0x80;
  7056. n = paddedLength - 8;
  7057. while (i < n) {
  7058. padded[i++] = 0;
  7059. }
  7060. padded[i++] = 0;
  7061. padded[i++] = 0;
  7062. padded[i++] = 0;
  7063. padded[i++] = (length >>> 29) & 0xFF;
  7064. padded[i++] = (length >> 21) & 0xFF;
  7065. padded[i++] = (length >> 13) & 0xFF;
  7066. padded[i++] = (length >> 5) & 0xFF;
  7067. padded[i++] = (length << 3) & 0xFF;
  7068. var w = new Uint32Array(64);
  7069. // for each 512 bit block
  7070. for (i = 0; i < paddedLength;) {
  7071. for (j = 0; j < 16; ++j) {
  7072. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7073. (padded[i + 2] << 8) | (padded[i + 3]));
  7074. i += 4;
  7075. }
  7076. for (j = 16; j < 64; ++j) {
  7077. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7078. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7079. }
  7080. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7081. f = h5, g = h6, h = h7, t1, t2;
  7082. for (j = 0; j < 64; ++j) {
  7083. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7084. t2 = sigma(a) + maj(a, b, c);
  7085. h = g;
  7086. g = f;
  7087. f = e;
  7088. e = (d + t1) | 0;
  7089. d = c;
  7090. c = b;
  7091. b = a;
  7092. a = (t1 + t2) | 0;
  7093. }
  7094. h0 = (h0 + a) | 0;
  7095. h1 = (h1 + b) | 0;
  7096. h2 = (h2 + c) | 0;
  7097. h3 = (h3 + d) | 0;
  7098. h4 = (h4 + e) | 0;
  7099. h5 = (h5 + f) | 0;
  7100. h6 = (h6 + g) | 0;
  7101. h7 = (h7 + h) | 0;
  7102. }
  7103. return new Uint8Array([
  7104. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7105. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7106. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7107. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7108. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7109. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7110. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7111. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7112. ]);
  7113. }
  7114. return hash;
  7115. })();
  7116. var calculateSHA512 = (function calculateSHA512Closure() {
  7117. function ch(result, x, y, z, tmp) {
  7118. result.assign(x);
  7119. result.and(y);
  7120. tmp.assign(x);
  7121. tmp.not();
  7122. tmp.and(z);
  7123. result.xor(tmp);
  7124. }
  7125. function maj(result, x, y, z, tmp) {
  7126. result.assign(x);
  7127. result.and(y);
  7128. tmp.assign(x);
  7129. tmp.and(z);
  7130. result.xor(tmp);
  7131. tmp.assign(y);
  7132. tmp.and(z);
  7133. result.xor(tmp);
  7134. }
  7135. function sigma(result, x, tmp) {
  7136. result.assign(x);
  7137. result.rotateRight(28);
  7138. tmp.assign(x);
  7139. tmp.rotateRight(34);
  7140. result.xor(tmp);
  7141. tmp.assign(x);
  7142. tmp.rotateRight(39);
  7143. result.xor(tmp);
  7144. }
  7145. function sigmaPrime(result, x, tmp) {
  7146. result.assign(x);
  7147. result.rotateRight(14);
  7148. tmp.assign(x);
  7149. tmp.rotateRight(18);
  7150. result.xor(tmp);
  7151. tmp.assign(x);
  7152. tmp.rotateRight(41);
  7153. result.xor(tmp);
  7154. }
  7155. function littleSigma(result, x, tmp) {
  7156. result.assign(x);
  7157. result.rotateRight(1);
  7158. tmp.assign(x);
  7159. tmp.rotateRight(8);
  7160. result.xor(tmp);
  7161. tmp.assign(x);
  7162. tmp.shiftRight(7);
  7163. result.xor(tmp);
  7164. }
  7165. function littleSigmaPrime(result, x, tmp) {
  7166. result.assign(x);
  7167. result.rotateRight(19);
  7168. tmp.assign(x);
  7169. tmp.rotateRight(61);
  7170. result.xor(tmp);
  7171. tmp.assign(x);
  7172. tmp.shiftRight(6);
  7173. result.xor(tmp);
  7174. }
  7175. var k = [
  7176. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7177. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7178. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7179. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7180. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7181. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7182. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7183. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7184. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7185. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7186. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7187. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7188. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7189. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7190. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7191. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7192. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7193. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7194. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7195. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7196. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7197. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7198. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7199. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7200. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7201. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7202. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7203. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7204. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7205. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7206. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7207. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7208. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7209. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7210. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7211. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7212. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7213. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7214. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7215. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7216. function hash(data, offset, length, mode384) {
  7217. mode384 = !!mode384;
  7218. // initial hash values
  7219. var h0, h1, h2, h3, h4, h5, h6, h7;
  7220. if (!mode384) {
  7221. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7222. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7223. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7224. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7225. h4 = new Word64(0x510e527f, 0xade682d1);
  7226. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7227. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7228. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7229. }
  7230. else {
  7231. // SHA384 is exactly the same
  7232. // except with different starting values and a trimmed result
  7233. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7234. h1 = new Word64(0x629a292a, 0x367cd507);
  7235. h2 = new Word64(0x9159015a, 0x3070dd17);
  7236. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7237. h4 = new Word64(0x67332667, 0xffc00b31);
  7238. h5 = new Word64(0x8eb44a87, 0x68581511);
  7239. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7240. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7241. }
  7242. // pre-processing
  7243. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7244. var padded = new Uint8Array(paddedLength);
  7245. var i, j, n;
  7246. for (i = 0; i < length; ++i) {
  7247. padded[i] = data[offset++];
  7248. }
  7249. padded[i++] = 0x80;
  7250. n = paddedLength - 16;
  7251. while (i < n) {
  7252. padded[i++] = 0;
  7253. }
  7254. padded[i++] = 0;
  7255. padded[i++] = 0;
  7256. padded[i++] = 0;
  7257. padded[i++] = 0;
  7258. padded[i++] = 0;
  7259. padded[i++] = 0;
  7260. padded[i++] = 0;
  7261. padded[i++] = 0;
  7262. padded[i++] = 0;
  7263. padded[i++] = 0;
  7264. padded[i++] = 0;
  7265. padded[i++] = (length >>> 29) & 0xFF;
  7266. padded[i++] = (length >> 21) & 0xFF;
  7267. padded[i++] = (length >> 13) & 0xFF;
  7268. padded[i++] = (length >> 5) & 0xFF;
  7269. padded[i++] = (length << 3) & 0xFF;
  7270. var w = new Array(80);
  7271. for (i = 0; i < 80; i++) {
  7272. w[i] = new Word64(0, 0);
  7273. }
  7274. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7275. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7276. var g = new Word64(0, 0), h = new Word64(0, 0);
  7277. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7278. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7279. // for each 1024 bit block
  7280. for (i = 0; i < paddedLength;) {
  7281. for (j = 0; j < 16; ++j) {
  7282. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7283. (padded[i + 2] << 8) | (padded[i + 3]);
  7284. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7285. (padded[i + 6]) << 8 | (padded[i + 7]);
  7286. i += 8;
  7287. }
  7288. for (j = 16; j < 80; ++j) {
  7289. tmp3 = w[j];
  7290. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7291. tmp3.add(w[j - 7]);
  7292. littleSigma(tmp1, w[j - 15], tmp2);
  7293. tmp3.add(tmp1);
  7294. tmp3.add(w[j - 16]);
  7295. }
  7296. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7297. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7298. for (j = 0; j < 80; ++j) {
  7299. t1.assign(h);
  7300. sigmaPrime(tmp1, e, tmp2);
  7301. t1.add(tmp1);
  7302. ch(tmp1, e, f, g, tmp2);
  7303. t1.add(tmp1);
  7304. t1.add(k[j]);
  7305. t1.add(w[j]);
  7306. sigma(t2, a, tmp2);
  7307. maj(tmp1, a, b, c, tmp2);
  7308. t2.add(tmp1);
  7309. tmp3 = h;
  7310. h = g;
  7311. g = f;
  7312. f = e;
  7313. d.add(t1);
  7314. e = d;
  7315. d = c;
  7316. c = b;
  7317. b = a;
  7318. tmp3.assign(t1);
  7319. tmp3.add(t2);
  7320. a = tmp3;
  7321. }
  7322. h0.add(a);
  7323. h1.add(b);
  7324. h2.add(c);
  7325. h3.add(d);
  7326. h4.add(e);
  7327. h5.add(f);
  7328. h6.add(g);
  7329. h7.add(h);
  7330. }
  7331. var result;
  7332. if (!mode384) {
  7333. result = new Uint8Array(64);
  7334. h0.copyTo(result,0);
  7335. h1.copyTo(result,8);
  7336. h2.copyTo(result,16);
  7337. h3.copyTo(result,24);
  7338. h4.copyTo(result,32);
  7339. h5.copyTo(result,40);
  7340. h6.copyTo(result,48);
  7341. h7.copyTo(result,56);
  7342. }
  7343. else {
  7344. result = new Uint8Array(48);
  7345. h0.copyTo(result,0);
  7346. h1.copyTo(result,8);
  7347. h2.copyTo(result,16);
  7348. h3.copyTo(result,24);
  7349. h4.copyTo(result,32);
  7350. h5.copyTo(result,40);
  7351. }
  7352. return result;
  7353. }
  7354. return hash;
  7355. })();
  7356. var calculateSHA384 = (function calculateSHA384Closure() {
  7357. function hash(data, offset, length) {
  7358. return calculateSHA512(data, offset, length, true);
  7359. }
  7360. return hash;
  7361. })();
  7362. var NullCipher = (function NullCipherClosure() {
  7363. function NullCipher() {
  7364. }
  7365. NullCipher.prototype = {
  7366. decryptBlock: function NullCipher_decryptBlock(data) {
  7367. return data;
  7368. }
  7369. };
  7370. return NullCipher;
  7371. })();
  7372. var AES128Cipher = (function AES128CipherClosure() {
  7373. var rcon = new Uint8Array([
  7374. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7375. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7376. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7377. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7378. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7379. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7380. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7381. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7382. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7383. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7384. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7385. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7386. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7387. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7388. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7389. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7390. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7391. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7392. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7393. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7394. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7395. 0x74, 0xe8, 0xcb, 0x8d]);
  7396. var s = new Uint8Array([
  7397. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7398. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7399. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7400. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7401. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7402. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7403. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7404. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7405. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7406. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7407. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7408. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7409. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7410. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7411. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7412. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7413. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7414. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7415. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7416. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7417. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7418. 0xb0, 0x54, 0xbb, 0x16]);
  7419. var inv_s = new Uint8Array([
  7420. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7421. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7422. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7423. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7424. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7425. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7426. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7427. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7428. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7429. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7430. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7431. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7432. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7433. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7434. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7435. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7436. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7437. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7438. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7439. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7440. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7441. 0x55, 0x21, 0x0c, 0x7d]);
  7442. var mixCol = new Uint8Array(256);
  7443. for (var i = 0; i < 256; i++) {
  7444. if (i < 128) {
  7445. mixCol[i] = i << 1;
  7446. } else {
  7447. mixCol[i] = (i << 1) ^ 0x1b;
  7448. }
  7449. }
  7450. var mix = new Uint32Array([
  7451. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7452. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7453. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7454. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7455. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7456. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7457. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7458. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7459. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7460. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7461. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7462. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7463. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7464. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7465. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7466. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7467. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7468. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7469. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7470. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7471. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7472. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7473. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7474. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7475. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7476. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7477. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7478. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7479. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7480. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7481. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7482. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7483. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7484. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7485. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7486. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7487. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7488. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7489. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7490. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7491. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7492. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7493. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7494. function expandKey128(cipherKey) {
  7495. var b = 176, result = new Uint8Array(b);
  7496. result.set(cipherKey);
  7497. for (var j = 16, i = 1; j < b; ++i) {
  7498. // RotWord
  7499. var t1 = result[j - 3], t2 = result[j - 2],
  7500. t3 = result[j - 1], t4 = result[j - 4];
  7501. // SubWord
  7502. t1 = s[t1];
  7503. t2 = s[t2];
  7504. t3 = s[t3];
  7505. t4 = s[t4];
  7506. // Rcon
  7507. t1 = t1 ^ rcon[i];
  7508. for (var n = 0; n < 4; ++n) {
  7509. result[j] = (t1 ^= result[j - 16]);
  7510. j++;
  7511. result[j] = (t2 ^= result[j - 16]);
  7512. j++;
  7513. result[j] = (t3 ^= result[j - 16]);
  7514. j++;
  7515. result[j] = (t4 ^= result[j - 16]);
  7516. j++;
  7517. }
  7518. }
  7519. return result;
  7520. }
  7521. function decrypt128(input, key) {
  7522. var state = new Uint8Array(16);
  7523. state.set(input);
  7524. var i, j, k;
  7525. var t, u, v;
  7526. // AddRoundKey
  7527. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7528. state[j] ^= key[k];
  7529. }
  7530. for (i = 9; i >= 1; --i) {
  7531. // InvShiftRows
  7532. t = state[13];
  7533. state[13] = state[9];
  7534. state[9] = state[5];
  7535. state[5] = state[1];
  7536. state[1] = t;
  7537. t = state[14];
  7538. u = state[10];
  7539. state[14] = state[6];
  7540. state[10] = state[2];
  7541. state[6] = t;
  7542. state[2] = u;
  7543. t = state[15];
  7544. u = state[11];
  7545. v = state[7];
  7546. state[15] = state[3];
  7547. state[11] = t;
  7548. state[7] = u;
  7549. state[3] = v;
  7550. // InvSubBytes
  7551. for (j = 0; j < 16; ++j) {
  7552. state[j] = inv_s[state[j]];
  7553. }
  7554. // AddRoundKey
  7555. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7556. state[j] ^= key[k];
  7557. }
  7558. // InvMixColumns
  7559. for (j = 0; j < 16; j += 4) {
  7560. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7561. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7562. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7563. (s3 >>> 24) ^ (s3 << 8));
  7564. state[j] = (t >>> 24) & 0xFF;
  7565. state[j + 1] = (t >> 16) & 0xFF;
  7566. state[j + 2] = (t >> 8) & 0xFF;
  7567. state[j + 3] = t & 0xFF;
  7568. }
  7569. }
  7570. // InvShiftRows
  7571. t = state[13];
  7572. state[13] = state[9];
  7573. state[9] = state[5];
  7574. state[5] = state[1];
  7575. state[1] = t;
  7576. t = state[14];
  7577. u = state[10];
  7578. state[14] = state[6];
  7579. state[10] = state[2];
  7580. state[6] = t;
  7581. state[2] = u;
  7582. t = state[15];
  7583. u = state[11];
  7584. v = state[7];
  7585. state[15] = state[3];
  7586. state[11] = t;
  7587. state[7] = u;
  7588. state[3] = v;
  7589. for (j = 0; j < 16; ++j) {
  7590. // InvSubBytes
  7591. state[j] = inv_s[state[j]];
  7592. // AddRoundKey
  7593. state[j] ^= key[j];
  7594. }
  7595. return state;
  7596. }
  7597. function encrypt128(input, key) {
  7598. var t, u, v, k;
  7599. var state = new Uint8Array(16);
  7600. state.set(input);
  7601. for (j = 0; j < 16; ++j) {
  7602. // AddRoundKey
  7603. state[j] ^= key[j];
  7604. }
  7605. for (i = 1; i < 10; i++) {
  7606. //SubBytes
  7607. for (j = 0; j < 16; ++j) {
  7608. state[j] = s[state[j]];
  7609. }
  7610. //ShiftRows
  7611. v = state[1];
  7612. state[1] = state[5];
  7613. state[5] = state[9];
  7614. state[9] = state[13];
  7615. state[13] = v;
  7616. v = state[2];
  7617. u = state[6];
  7618. state[2] = state[10];
  7619. state[6] = state[14];
  7620. state[10] = v;
  7621. state[14] = u;
  7622. v = state[3];
  7623. u = state[7];
  7624. t = state[11];
  7625. state[3] = state[15];
  7626. state[7] = v;
  7627. state[11] = u;
  7628. state[15] = t;
  7629. //MixColumns
  7630. for (var j = 0; j < 16; j += 4) {
  7631. var s0 = state[j + 0], s1 = state[j + 1];
  7632. var s2 = state[j + 2], s3 = state[j + 3];
  7633. t = s0 ^ s1 ^ s2 ^ s3;
  7634. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7635. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7636. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7637. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7638. }
  7639. //AddRoundKey
  7640. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7641. state[j] ^= key[k];
  7642. }
  7643. }
  7644. //SubBytes
  7645. for (j = 0; j < 16; ++j) {
  7646. state[j] = s[state[j]];
  7647. }
  7648. //ShiftRows
  7649. v = state[1];
  7650. state[1] = state[5];
  7651. state[5] = state[9];
  7652. state[9] = state[13];
  7653. state[13] = v;
  7654. v = state[2];
  7655. u = state[6];
  7656. state[2] = state[10];
  7657. state[6] = state[14];
  7658. state[10] = v;
  7659. state[14] = u;
  7660. v = state[3];
  7661. u = state[7];
  7662. t = state[11];
  7663. state[3] = state[15];
  7664. state[7] = v;
  7665. state[11] = u;
  7666. state[15] = t;
  7667. //AddRoundKey
  7668. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7669. state[j] ^= key[k];
  7670. }
  7671. return state;
  7672. }
  7673. function AES128Cipher(key) {
  7674. this.key = expandKey128(key);
  7675. this.buffer = new Uint8Array(16);
  7676. this.bufferPosition = 0;
  7677. }
  7678. function decryptBlock2(data, finalize) {
  7679. var i, j, ii, sourceLength = data.length,
  7680. buffer = this.buffer, bufferLength = this.bufferPosition,
  7681. result = [], iv = this.iv;
  7682. for (i = 0; i < sourceLength; ++i) {
  7683. buffer[bufferLength] = data[i];
  7684. ++bufferLength;
  7685. if (bufferLength < 16) {
  7686. continue;
  7687. }
  7688. // buffer is full, decrypting
  7689. var plain = decrypt128(buffer, this.key);
  7690. // xor-ing the IV vector to get plain text
  7691. for (j = 0; j < 16; ++j) {
  7692. plain[j] ^= iv[j];
  7693. }
  7694. iv = buffer;
  7695. result.push(plain);
  7696. buffer = new Uint8Array(16);
  7697. bufferLength = 0;
  7698. }
  7699. // saving incomplete buffer
  7700. this.buffer = buffer;
  7701. this.bufferLength = bufferLength;
  7702. this.iv = iv;
  7703. if (result.length === 0) {
  7704. return new Uint8Array([]);
  7705. }
  7706. // combining plain text blocks into one
  7707. var outputLength = 16 * result.length;
  7708. if (finalize) {
  7709. // undo a padding that is described in RFC 2898
  7710. var lastBlock = result[result.length - 1];
  7711. var psLen = lastBlock[15];
  7712. if (psLen <= 16) {
  7713. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7714. if (lastBlock[i] !== psLen) {
  7715. // Invalid padding, assume that the block has no padding.
  7716. psLen = 0;
  7717. break;
  7718. }
  7719. }
  7720. outputLength -= psLen;
  7721. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7722. }
  7723. }
  7724. var output = new Uint8Array(outputLength);
  7725. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7726. output.set(result[i], j);
  7727. }
  7728. return output;
  7729. }
  7730. AES128Cipher.prototype = {
  7731. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7732. var i, sourceLength = data.length;
  7733. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7734. // waiting for IV values -- they are at the start of the stream
  7735. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7736. buffer[bufferLength] = data[i];
  7737. }
  7738. if (bufferLength < 16) {
  7739. // need more data
  7740. this.bufferLength = bufferLength;
  7741. return new Uint8Array([]);
  7742. }
  7743. this.iv = buffer;
  7744. this.buffer = new Uint8Array(16);
  7745. this.bufferLength = 0;
  7746. // starting decryption
  7747. this.decryptBlock = decryptBlock2;
  7748. return this.decryptBlock(data.subarray(16), finalize);
  7749. },
  7750. encrypt: function AES128Cipher_encrypt(data, iv) {
  7751. var i, j, ii, sourceLength = data.length,
  7752. buffer = this.buffer, bufferLength = this.bufferPosition,
  7753. result = [];
  7754. if (!iv) {
  7755. iv = new Uint8Array(16);
  7756. }
  7757. for (i = 0; i < sourceLength; ++i) {
  7758. buffer[bufferLength] = data[i];
  7759. ++bufferLength;
  7760. if (bufferLength < 16) {
  7761. continue;
  7762. }
  7763. for (j = 0; j < 16; ++j) {
  7764. buffer[j] ^= iv[j];
  7765. }
  7766. // buffer is full, encrypting
  7767. var cipher = encrypt128(buffer, this.key);
  7768. iv = cipher;
  7769. result.push(cipher);
  7770. buffer = new Uint8Array(16);
  7771. bufferLength = 0;
  7772. }
  7773. // saving incomplete buffer
  7774. this.buffer = buffer;
  7775. this.bufferLength = bufferLength;
  7776. this.iv = iv;
  7777. if (result.length === 0) {
  7778. return new Uint8Array([]);
  7779. }
  7780. // combining plain text blocks into one
  7781. var outputLength = 16 * result.length;
  7782. var output = new Uint8Array(outputLength);
  7783. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7784. output.set(result[i], j);
  7785. }
  7786. return output;
  7787. }
  7788. };
  7789. return AES128Cipher;
  7790. })();
  7791. var AES256Cipher = (function AES256CipherClosure() {
  7792. var rcon = new Uint8Array([
  7793. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7794. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7795. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7796. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7797. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7798. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7799. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7800. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7801. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7802. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7803. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7804. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7805. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7806. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7807. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7808. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7809. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7810. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7811. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7812. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7813. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7814. 0x74, 0xe8, 0xcb, 0x8d]);
  7815. var s = new Uint8Array([
  7816. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7817. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7818. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7819. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7820. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7821. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7822. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7823. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7824. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7825. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7826. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7827. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7828. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7829. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7830. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7831. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7832. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7833. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7834. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7835. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7836. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7837. 0xb0, 0x54, 0xbb, 0x16]);
  7838. var inv_s = new Uint8Array([
  7839. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7840. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7841. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7842. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7843. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7844. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7845. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7846. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7847. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7848. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7849. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7850. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7851. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7852. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7853. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7854. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7855. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7856. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7857. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7858. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7859. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7860. 0x55, 0x21, 0x0c, 0x7d]);
  7861. var mixCol = new Uint8Array(256);
  7862. for (var i = 0; i < 256; i++) {
  7863. if (i < 128) {
  7864. mixCol[i] = i << 1;
  7865. } else {
  7866. mixCol[i] = (i << 1) ^ 0x1b;
  7867. }
  7868. }
  7869. var mix = new Uint32Array([
  7870. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7871. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7872. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7873. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7874. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7875. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7876. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7877. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7878. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7879. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7880. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7881. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7882. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7883. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7884. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7885. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7886. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7887. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7888. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7889. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7890. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7891. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7892. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7893. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7894. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7895. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7896. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7897. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7898. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7899. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7900. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7901. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7902. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7903. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7904. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7905. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7906. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7907. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7908. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7909. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7910. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7911. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7912. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7913. function expandKey256(cipherKey) {
  7914. var b = 240, result = new Uint8Array(b);
  7915. var r = 1;
  7916. result.set(cipherKey);
  7917. for (var j = 32, i = 1; j < b; ++i) {
  7918. if (j % 32 === 16) {
  7919. t1 = s[t1];
  7920. t2 = s[t2];
  7921. t3 = s[t3];
  7922. t4 = s[t4];
  7923. } else if (j % 32 === 0) {
  7924. // RotWord
  7925. var t1 = result[j - 3], t2 = result[j - 2],
  7926. t3 = result[j - 1], t4 = result[j - 4];
  7927. // SubWord
  7928. t1 = s[t1];
  7929. t2 = s[t2];
  7930. t3 = s[t3];
  7931. t4 = s[t4];
  7932. // Rcon
  7933. t1 = t1 ^ r;
  7934. if ((r <<= 1) >= 256) {
  7935. r = (r ^ 0x1b) & 0xFF;
  7936. }
  7937. }
  7938. for (var n = 0; n < 4; ++n) {
  7939. result[j] = (t1 ^= result[j - 32]);
  7940. j++;
  7941. result[j] = (t2 ^= result[j - 32]);
  7942. j++;
  7943. result[j] = (t3 ^= result[j - 32]);
  7944. j++;
  7945. result[j] = (t4 ^= result[j - 32]);
  7946. j++;
  7947. }
  7948. }
  7949. return result;
  7950. }
  7951. function decrypt256(input, key) {
  7952. var state = new Uint8Array(16);
  7953. state.set(input);
  7954. var i, j, k;
  7955. var t, u, v;
  7956. // AddRoundKey
  7957. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7958. state[j] ^= key[k];
  7959. }
  7960. for (i = 13; i >= 1; --i) {
  7961. // InvShiftRows
  7962. t = state[13];
  7963. state[13] = state[9];
  7964. state[9] = state[5];
  7965. state[5] = state[1];
  7966. state[1] = t;
  7967. t = state[14];
  7968. u = state[10];
  7969. state[14] = state[6];
  7970. state[10] = state[2];
  7971. state[6] = t;
  7972. state[2] = u;
  7973. t = state[15];
  7974. u = state[11];
  7975. v = state[7];
  7976. state[15] = state[3];
  7977. state[11] = t;
  7978. state[7] = u;
  7979. state[3] = v;
  7980. // InvSubBytes
  7981. for (j = 0; j < 16; ++j) {
  7982. state[j] = inv_s[state[j]];
  7983. }
  7984. // AddRoundKey
  7985. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7986. state[j] ^= key[k];
  7987. }
  7988. // InvMixColumns
  7989. for (j = 0; j < 16; j += 4) {
  7990. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7991. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7992. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7993. (s3 >>> 24) ^ (s3 << 8));
  7994. state[j] = (t >>> 24) & 0xFF;
  7995. state[j + 1] = (t >> 16) & 0xFF;
  7996. state[j + 2] = (t >> 8) & 0xFF;
  7997. state[j + 3] = t & 0xFF;
  7998. }
  7999. }
  8000. // InvShiftRows
  8001. t = state[13];
  8002. state[13] = state[9];
  8003. state[9] = state[5];
  8004. state[5] = state[1];
  8005. state[1] = t;
  8006. t = state[14];
  8007. u = state[10];
  8008. state[14] = state[6];
  8009. state[10] = state[2];
  8010. state[6] = t;
  8011. state[2] = u;
  8012. t = state[15];
  8013. u = state[11];
  8014. v = state[7];
  8015. state[15] = state[3];
  8016. state[11] = t;
  8017. state[7] = u;
  8018. state[3] = v;
  8019. for (j = 0; j < 16; ++j) {
  8020. // InvSubBytes
  8021. state[j] = inv_s[state[j]];
  8022. // AddRoundKey
  8023. state[j] ^= key[j];
  8024. }
  8025. return state;
  8026. }
  8027. function encrypt256(input, key) {
  8028. var t, u, v, k;
  8029. var state = new Uint8Array(16);
  8030. state.set(input);
  8031. for (j = 0; j < 16; ++j) {
  8032. // AddRoundKey
  8033. state[j] ^= key[j];
  8034. }
  8035. for (i = 1; i < 14; i++) {
  8036. //SubBytes
  8037. for (j = 0; j < 16; ++j) {
  8038. state[j] = s[state[j]];
  8039. }
  8040. //ShiftRows
  8041. v = state[1];
  8042. state[1] = state[5];
  8043. state[5] = state[9];
  8044. state[9] = state[13];
  8045. state[13] = v;
  8046. v = state[2];
  8047. u = state[6];
  8048. state[2] = state[10];
  8049. state[6] = state[14];
  8050. state[10] = v;
  8051. state[14] = u;
  8052. v = state[3];
  8053. u = state[7];
  8054. t = state[11];
  8055. state[3] = state[15];
  8056. state[7] = v;
  8057. state[11] = u;
  8058. state[15] = t;
  8059. //MixColumns
  8060. for (var j = 0; j < 16; j += 4) {
  8061. var s0 = state[j + 0], s1 = state[j + 1];
  8062. var s2 = state[j + 2], s3 = state[j + 3];
  8063. t = s0 ^ s1 ^ s2 ^ s3;
  8064. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8065. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8066. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8067. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8068. }
  8069. //AddRoundKey
  8070. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8071. state[j] ^= key[k];
  8072. }
  8073. }
  8074. //SubBytes
  8075. for (j = 0; j < 16; ++j) {
  8076. state[j] = s[state[j]];
  8077. }
  8078. //ShiftRows
  8079. v = state[1];
  8080. state[1] = state[5];
  8081. state[5] = state[9];
  8082. state[9] = state[13];
  8083. state[13] = v;
  8084. v = state[2];
  8085. u = state[6];
  8086. state[2] = state[10];
  8087. state[6] = state[14];
  8088. state[10] = v;
  8089. state[14] = u;
  8090. v = state[3];
  8091. u = state[7];
  8092. t = state[11];
  8093. state[3] = state[15];
  8094. state[7] = v;
  8095. state[11] = u;
  8096. state[15] = t;
  8097. //AddRoundKey
  8098. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8099. state[j] ^= key[k];
  8100. }
  8101. return state;
  8102. }
  8103. function AES256Cipher(key) {
  8104. this.key = expandKey256(key);
  8105. this.buffer = new Uint8Array(16);
  8106. this.bufferPosition = 0;
  8107. }
  8108. function decryptBlock2(data, finalize) {
  8109. var i, j, ii, sourceLength = data.length,
  8110. buffer = this.buffer, bufferLength = this.bufferPosition,
  8111. result = [], iv = this.iv;
  8112. for (i = 0; i < sourceLength; ++i) {
  8113. buffer[bufferLength] = data[i];
  8114. ++bufferLength;
  8115. if (bufferLength < 16) {
  8116. continue;
  8117. }
  8118. // buffer is full, decrypting
  8119. var plain = decrypt256(buffer, this.key);
  8120. // xor-ing the IV vector to get plain text
  8121. for (j = 0; j < 16; ++j) {
  8122. plain[j] ^= iv[j];
  8123. }
  8124. iv = buffer;
  8125. result.push(plain);
  8126. buffer = new Uint8Array(16);
  8127. bufferLength = 0;
  8128. }
  8129. // saving incomplete buffer
  8130. this.buffer = buffer;
  8131. this.bufferLength = bufferLength;
  8132. this.iv = iv;
  8133. if (result.length === 0) {
  8134. return new Uint8Array([]);
  8135. }
  8136. // combining plain text blocks into one
  8137. var outputLength = 16 * result.length;
  8138. if (finalize) {
  8139. // undo a padding that is described in RFC 2898
  8140. var lastBlock = result[result.length - 1];
  8141. var psLen = lastBlock[15];
  8142. if (psLen <= 16) {
  8143. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8144. if (lastBlock[i] !== psLen) {
  8145. // Invalid padding, assume that the block has no padding.
  8146. psLen = 0;
  8147. break;
  8148. }
  8149. }
  8150. outputLength -= psLen;
  8151. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8152. }
  8153. }
  8154. var output = new Uint8Array(outputLength);
  8155. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8156. output.set(result[i], j);
  8157. }
  8158. return output;
  8159. }
  8160. AES256Cipher.prototype = {
  8161. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8162. var i, sourceLength = data.length;
  8163. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8164. // if not supplied an IV wait for IV values
  8165. // they are at the start of the stream
  8166. if (iv) {
  8167. this.iv = iv;
  8168. } else {
  8169. for (i = 0; bufferLength < 16 &&
  8170. i < sourceLength; ++i, ++bufferLength) {
  8171. buffer[bufferLength] = data[i];
  8172. }
  8173. if (bufferLength < 16) {
  8174. //need more data
  8175. this.bufferLength = bufferLength;
  8176. return new Uint8Array([]);
  8177. }
  8178. this.iv = buffer;
  8179. data = data.subarray(16);
  8180. }
  8181. this.buffer = new Uint8Array(16);
  8182. this.bufferLength = 0;
  8183. // starting decryption
  8184. this.decryptBlock = decryptBlock2;
  8185. return this.decryptBlock(data, finalize);
  8186. },
  8187. encrypt: function AES256Cipher_encrypt(data, iv) {
  8188. var i, j, ii, sourceLength = data.length,
  8189. buffer = this.buffer, bufferLength = this.bufferPosition,
  8190. result = [];
  8191. if (!iv) {
  8192. iv = new Uint8Array(16);
  8193. }
  8194. for (i = 0; i < sourceLength; ++i) {
  8195. buffer[bufferLength] = data[i];
  8196. ++bufferLength;
  8197. if (bufferLength < 16) {
  8198. continue;
  8199. }
  8200. for (j = 0; j < 16; ++j) {
  8201. buffer[j] ^= iv[j];
  8202. }
  8203. // buffer is full, encrypting
  8204. var cipher = encrypt256(buffer, this.key);
  8205. this.iv = cipher;
  8206. result.push(cipher);
  8207. buffer = new Uint8Array(16);
  8208. bufferLength = 0;
  8209. }
  8210. // saving incomplete buffer
  8211. this.buffer = buffer;
  8212. this.bufferLength = bufferLength;
  8213. this.iv = iv;
  8214. if (result.length === 0) {
  8215. return new Uint8Array([]);
  8216. }
  8217. // combining plain text blocks into one
  8218. var outputLength = 16 * result.length;
  8219. var output = new Uint8Array(outputLength);
  8220. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8221. output.set(result[i], j);
  8222. }
  8223. return output;
  8224. }
  8225. };
  8226. return AES256Cipher;
  8227. })();
  8228. var PDF17 = (function PDF17Closure() {
  8229. function compareByteArrays(array1, array2) {
  8230. if (array1.length !== array2.length) {
  8231. return false;
  8232. }
  8233. for (var i = 0; i < array1.length; i++) {
  8234. if (array1[i] !== array2[i]) {
  8235. return false;
  8236. }
  8237. }
  8238. return true;
  8239. }
  8240. function PDF17() {
  8241. }
  8242. PDF17.prototype = {
  8243. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8244. ownerValidationSalt,
  8245. userBytes,
  8246. ownerPassword) {
  8247. var hashData = new Uint8Array(password.length + 56);
  8248. hashData.set(password, 0);
  8249. hashData.set(ownerValidationSalt, password.length);
  8250. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8251. var result = calculateSHA256(hashData, 0, hashData.length);
  8252. return compareByteArrays(result, ownerPassword);
  8253. },
  8254. checkUserPassword: function PDF17_checkUserPassword(password,
  8255. userValidationSalt,
  8256. userPassword) {
  8257. var hashData = new Uint8Array(password.length + 8);
  8258. hashData.set(password, 0);
  8259. hashData.set(userValidationSalt, password.length);
  8260. var result = calculateSHA256(hashData, 0, hashData.length);
  8261. return compareByteArrays(result, userPassword);
  8262. },
  8263. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8264. ownerEncryption) {
  8265. var hashData = new Uint8Array(password.length + 56);
  8266. hashData.set(password, 0);
  8267. hashData.set(ownerKeySalt, password.length);
  8268. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8269. var key = calculateSHA256(hashData, 0, hashData.length);
  8270. var cipher = new AES256Cipher(key);
  8271. return cipher.decryptBlock(ownerEncryption,
  8272. false,
  8273. new Uint8Array(16));
  8274. },
  8275. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8276. userEncryption) {
  8277. var hashData = new Uint8Array(password.length + 8);
  8278. hashData.set(password, 0);
  8279. hashData.set(userKeySalt, password.length);
  8280. //key is the decryption key for the UE string
  8281. var key = calculateSHA256(hashData, 0, hashData.length);
  8282. var cipher = new AES256Cipher(key);
  8283. return cipher.decryptBlock(userEncryption,
  8284. false,
  8285. new Uint8Array(16));
  8286. }
  8287. };
  8288. return PDF17;
  8289. })();
  8290. var PDF20 = (function PDF20Closure() {
  8291. function concatArrays(array1, array2) {
  8292. var t = new Uint8Array(array1.length + array2.length);
  8293. t.set(array1, 0);
  8294. t.set(array2, array1.length);
  8295. return t;
  8296. }
  8297. function calculatePDF20Hash(password, input, userBytes) {
  8298. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8299. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8300. var e = [0];
  8301. var i = 0;
  8302. while (i < 64 || e[e.length - 1] > i - 32) {
  8303. var arrayLength = password.length + k.length + userBytes.length;
  8304. var k1 = new Uint8Array(arrayLength * 64);
  8305. var array = concatArrays(password, k);
  8306. array = concatArrays(array, userBytes);
  8307. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8308. k1.set(array, pos);
  8309. }
  8310. //AES128 CBC NO PADDING with
  8311. //first 16 bytes of k as the key and the second 16 as the iv.
  8312. var cipher = new AES128Cipher(k.subarray(0, 16));
  8313. e = cipher.encrypt(k1, k.subarray(16, 32));
  8314. //Now we have to take the first 16 bytes of an unsigned
  8315. //big endian integer... and compute the remainder
  8316. //modulo 3.... That is a fairly large number and
  8317. //JavaScript isn't going to handle that well...
  8318. //So we're using a trick that allows us to perform
  8319. //modulo math byte by byte
  8320. var remainder = 0;
  8321. for (var z = 0; z < 16; z++) {
  8322. remainder *= (256 % 3);
  8323. remainder %= 3;
  8324. remainder += ((e[z] >>> 0) % 3);
  8325. remainder %= 3;
  8326. }
  8327. if (remainder === 0) {
  8328. k = calculateSHA256(e, 0, e.length);
  8329. }
  8330. else if (remainder === 1) {
  8331. k = calculateSHA384(e, 0, e.length);
  8332. }
  8333. else if (remainder === 2) {
  8334. k = calculateSHA512(e, 0, e.length);
  8335. }
  8336. i++;
  8337. }
  8338. return k.subarray(0, 32);
  8339. }
  8340. function PDF20() {
  8341. }
  8342. function compareByteArrays(array1, array2) {
  8343. if (array1.length !== array2.length) {
  8344. return false;
  8345. }
  8346. for (var i = 0; i < array1.length; i++) {
  8347. if (array1[i] !== array2[i]) {
  8348. return false;
  8349. }
  8350. }
  8351. return true;
  8352. }
  8353. PDF20.prototype = {
  8354. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8355. return calculatePDF20Hash(password, concatBytes, userBytes);
  8356. },
  8357. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8358. ownerValidationSalt,
  8359. userBytes,
  8360. ownerPassword) {
  8361. var hashData = new Uint8Array(password.length + 56);
  8362. hashData.set(password, 0);
  8363. hashData.set(ownerValidationSalt, password.length);
  8364. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8365. var result = calculatePDF20Hash(password, hashData, userBytes);
  8366. return compareByteArrays(result, ownerPassword);
  8367. },
  8368. checkUserPassword: function PDF20_checkUserPassword(password,
  8369. userValidationSalt,
  8370. userPassword) {
  8371. var hashData = new Uint8Array(password.length + 8);
  8372. hashData.set(password, 0);
  8373. hashData.set(userValidationSalt, password.length);
  8374. var result = calculatePDF20Hash(password, hashData, []);
  8375. return compareByteArrays(result, userPassword);
  8376. },
  8377. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8378. ownerEncryption) {
  8379. var hashData = new Uint8Array(password.length + 56);
  8380. hashData.set(password, 0);
  8381. hashData.set(ownerKeySalt, password.length);
  8382. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8383. var key = calculatePDF20Hash(password, hashData, userBytes);
  8384. var cipher = new AES256Cipher(key);
  8385. return cipher.decryptBlock(ownerEncryption,
  8386. false,
  8387. new Uint8Array(16));
  8388. },
  8389. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8390. userEncryption) {
  8391. var hashData = new Uint8Array(password.length + 8);
  8392. hashData.set(password, 0);
  8393. hashData.set(userKeySalt, password.length);
  8394. //key is the decryption key for the UE string
  8395. var key = calculatePDF20Hash(password, hashData, []);
  8396. var cipher = new AES256Cipher(key);
  8397. return cipher.decryptBlock(userEncryption,
  8398. false,
  8399. new Uint8Array(16));
  8400. }
  8401. };
  8402. return PDF20;
  8403. })();
  8404. var CipherTransform = (function CipherTransformClosure() {
  8405. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8406. this.stringCipherConstructor = stringCipherConstructor;
  8407. this.streamCipherConstructor = streamCipherConstructor;
  8408. }
  8409. CipherTransform.prototype = {
  8410. createStream: function CipherTransform_createStream(stream, length) {
  8411. var cipher = new this.streamCipherConstructor();
  8412. return new DecryptStream(stream, length,
  8413. function cipherTransformDecryptStream(data, finalize) {
  8414. return cipher.decryptBlock(data, finalize);
  8415. }
  8416. );
  8417. },
  8418. decryptString: function CipherTransform_decryptString(s) {
  8419. var cipher = new this.stringCipherConstructor();
  8420. var data = stringToBytes(s);
  8421. data = cipher.decryptBlock(data, true);
  8422. return bytesToString(data);
  8423. }
  8424. };
  8425. return CipherTransform;
  8426. })();
  8427. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8428. var defaultPasswordBytes = new Uint8Array([
  8429. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8430. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8431. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8432. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8433. function createEncryptionKey20(revision, password, ownerPassword,
  8434. ownerValidationSalt, ownerKeySalt, uBytes,
  8435. userPassword, userValidationSalt, userKeySalt,
  8436. ownerEncryption, userEncryption, perms) {
  8437. if (password) {
  8438. var passwordLength = Math.min(127, password.length);
  8439. password = password.subarray(0, passwordLength);
  8440. } else {
  8441. password = [];
  8442. }
  8443. var pdfAlgorithm;
  8444. if (revision === 6) {
  8445. pdfAlgorithm = new PDF20();
  8446. } else {
  8447. pdfAlgorithm = new PDF17();
  8448. }
  8449. if (pdfAlgorithm) {
  8450. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8451. userPassword)) {
  8452. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8453. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8454. uBytes,
  8455. ownerPassword)) {
  8456. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8457. ownerEncryption);
  8458. }
  8459. }
  8460. return null;
  8461. }
  8462. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8463. flags, revision, keyLength, encryptMetadata) {
  8464. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8465. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8466. if (password) {
  8467. n = Math.min(32, password.length);
  8468. for (; i < n; ++i) {
  8469. hashData[i] = password[i];
  8470. }
  8471. }
  8472. j = 0;
  8473. while (i < 32) {
  8474. hashData[i++] = defaultPasswordBytes[j++];
  8475. }
  8476. // as now the padded password in the hashData[0..i]
  8477. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8478. hashData[i++] = ownerPassword[j];
  8479. }
  8480. hashData[i++] = flags & 0xFF;
  8481. hashData[i++] = (flags >> 8) & 0xFF;
  8482. hashData[i++] = (flags >> 16) & 0xFF;
  8483. hashData[i++] = (flags >>> 24) & 0xFF;
  8484. for (j = 0, n = fileId.length; j < n; ++j) {
  8485. hashData[i++] = fileId[j];
  8486. }
  8487. if (revision >= 4 && !encryptMetadata) {
  8488. hashData[i++] = 0xFF;
  8489. hashData[i++] = 0xFF;
  8490. hashData[i++] = 0xFF;
  8491. hashData[i++] = 0xFF;
  8492. }
  8493. var hash = calculateMD5(hashData, 0, i);
  8494. var keyLengthInBytes = keyLength >> 3;
  8495. if (revision >= 3) {
  8496. for (j = 0; j < 50; ++j) {
  8497. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8498. }
  8499. }
  8500. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8501. var cipher, checkData;
  8502. if (revision >= 3) {
  8503. for (i = 0; i < 32; ++i) {
  8504. hashData[i] = defaultPasswordBytes[i];
  8505. }
  8506. for (j = 0, n = fileId.length; j < n; ++j) {
  8507. hashData[i++] = fileId[j];
  8508. }
  8509. cipher = new ARCFourCipher(encryptionKey);
  8510. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8511. n = encryptionKey.length;
  8512. var derivedKey = new Uint8Array(n), k;
  8513. for (j = 1; j <= 19; ++j) {
  8514. for (k = 0; k < n; ++k) {
  8515. derivedKey[k] = encryptionKey[k] ^ j;
  8516. }
  8517. cipher = new ARCFourCipher(derivedKey);
  8518. checkData = cipher.encryptBlock(checkData);
  8519. }
  8520. for (j = 0, n = checkData.length; j < n; ++j) {
  8521. if (userPassword[j] !== checkData[j]) {
  8522. return null;
  8523. }
  8524. }
  8525. } else {
  8526. cipher = new ARCFourCipher(encryptionKey);
  8527. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8528. for (j = 0, n = checkData.length; j < n; ++j) {
  8529. if (userPassword[j] !== checkData[j]) {
  8530. return null;
  8531. }
  8532. }
  8533. }
  8534. return encryptionKey;
  8535. }
  8536. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8537. var hashData = new Uint8Array(32), i = 0, j, n;
  8538. n = Math.min(32, password.length);
  8539. for (; i < n; ++i) {
  8540. hashData[i] = password[i];
  8541. }
  8542. j = 0;
  8543. while (i < 32) {
  8544. hashData[i++] = defaultPasswordBytes[j++];
  8545. }
  8546. var hash = calculateMD5(hashData, 0, i);
  8547. var keyLengthInBytes = keyLength >> 3;
  8548. if (revision >= 3) {
  8549. for (j = 0; j < 50; ++j) {
  8550. hash = calculateMD5(hash, 0, hash.length);
  8551. }
  8552. }
  8553. var cipher, userPassword;
  8554. if (revision >= 3) {
  8555. userPassword = ownerPassword;
  8556. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8557. for (j = 19; j >= 0; j--) {
  8558. for (k = 0; k < keyLengthInBytes; ++k) {
  8559. derivedKey[k] = hash[k] ^ j;
  8560. }
  8561. cipher = new ARCFourCipher(derivedKey);
  8562. userPassword = cipher.encryptBlock(userPassword);
  8563. }
  8564. } else {
  8565. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8566. userPassword = cipher.encryptBlock(ownerPassword);
  8567. }
  8568. return userPassword;
  8569. }
  8570. var identityName = Name.get('Identity');
  8571. function CipherTransformFactory(dict, fileId, password) {
  8572. var filter = dict.get('Filter');
  8573. if (!isName(filter) || filter.name !== 'Standard') {
  8574. error('unknown encryption method');
  8575. }
  8576. this.dict = dict;
  8577. var algorithm = dict.get('V');
  8578. if (!isInt(algorithm) ||
  8579. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8580. algorithm !== 5)) {
  8581. error('unsupported encryption algorithm');
  8582. }
  8583. this.algorithm = algorithm;
  8584. var keyLength = dict.get('Length') || 40;
  8585. if (!isInt(keyLength) ||
  8586. keyLength < 40 || (keyLength % 8) !== 0) {
  8587. error('invalid key length');
  8588. }
  8589. // prepare keys
  8590. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8591. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8592. var flags = dict.get('P');
  8593. var revision = dict.get('R');
  8594. // meaningful when V is 4 or 5
  8595. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8596. dict.get('EncryptMetadata') !== false);
  8597. this.encryptMetadata = encryptMetadata;
  8598. var fileIdBytes = stringToBytes(fileId);
  8599. var passwordBytes;
  8600. if (password) {
  8601. passwordBytes = stringToBytes(password);
  8602. }
  8603. var encryptionKey;
  8604. if (algorithm !== 5) {
  8605. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8606. ownerPassword, userPassword, flags,
  8607. revision, keyLength, encryptMetadata);
  8608. }
  8609. else {
  8610. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8611. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8612. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8613. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8614. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8615. var ownerEncryption = stringToBytes(dict.get('OE'));
  8616. var userEncryption = stringToBytes(dict.get('UE'));
  8617. var perms = stringToBytes(dict.get('Perms'));
  8618. encryptionKey =
  8619. createEncryptionKey20(revision, passwordBytes,
  8620. ownerPassword, ownerValidationSalt,
  8621. ownerKeySalt, uBytes,
  8622. userPassword, userValidationSalt,
  8623. userKeySalt, ownerEncryption,
  8624. userEncryption, perms);
  8625. }
  8626. if (!encryptionKey && !password) {
  8627. throw new PasswordException('No password given',
  8628. PasswordResponses.NEED_PASSWORD);
  8629. } else if (!encryptionKey && password) {
  8630. // Attempting use the password as an owner password
  8631. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8632. revision, keyLength);
  8633. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8634. ownerPassword, userPassword, flags,
  8635. revision, keyLength, encryptMetadata);
  8636. }
  8637. if (!encryptionKey) {
  8638. throw new PasswordException('Incorrect Password',
  8639. PasswordResponses.INCORRECT_PASSWORD);
  8640. }
  8641. this.encryptionKey = encryptionKey;
  8642. if (algorithm >= 4) {
  8643. this.cf = dict.get('CF');
  8644. this.stmf = dict.get('StmF') || identityName;
  8645. this.strf = dict.get('StrF') || identityName;
  8646. this.eff = dict.get('EFF') || this.strf;
  8647. }
  8648. }
  8649. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8650. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8651. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8652. key[i] = encryptionKey[i];
  8653. }
  8654. key[i++] = num & 0xFF;
  8655. key[i++] = (num >> 8) & 0xFF;
  8656. key[i++] = (num >> 16) & 0xFF;
  8657. key[i++] = gen & 0xFF;
  8658. key[i++] = (gen >> 8) & 0xFF;
  8659. if (isAes) {
  8660. key[i++] = 0x73;
  8661. key[i++] = 0x41;
  8662. key[i++] = 0x6C;
  8663. key[i++] = 0x54;
  8664. }
  8665. var hash = calculateMD5(key, 0, i);
  8666. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8667. }
  8668. function buildCipherConstructor(cf, name, num, gen, key) {
  8669. var cryptFilter = cf.get(name.name);
  8670. var cfm;
  8671. if (cryptFilter !== null && cryptFilter !== undefined) {
  8672. cfm = cryptFilter.get('CFM');
  8673. }
  8674. if (!cfm || cfm.name === 'None') {
  8675. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8676. return new NullCipher();
  8677. };
  8678. }
  8679. if ('V2' === cfm.name) {
  8680. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8681. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8682. };
  8683. }
  8684. if ('AESV2' === cfm.name) {
  8685. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8686. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8687. };
  8688. }
  8689. if ('AESV3' === cfm.name) {
  8690. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8691. return new AES256Cipher(key);
  8692. };
  8693. }
  8694. error('Unknown crypto method');
  8695. }
  8696. CipherTransformFactory.prototype = {
  8697. createCipherTransform:
  8698. function CipherTransformFactory_createCipherTransform(num, gen) {
  8699. if (this.algorithm === 4 || this.algorithm === 5) {
  8700. return new CipherTransform(
  8701. buildCipherConstructor(this.cf, this.stmf,
  8702. num, gen, this.encryptionKey),
  8703. buildCipherConstructor(this.cf, this.strf,
  8704. num, gen, this.encryptionKey));
  8705. }
  8706. // algorithms 1 and 2
  8707. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8708. var cipherConstructor = function buildCipherCipherConstructor() {
  8709. return new ARCFourCipher(key);
  8710. };
  8711. return new CipherTransform(cipherConstructor, cipherConstructor);
  8712. }
  8713. };
  8714. return CipherTransformFactory;
  8715. })();
  8716. var PatternType = {
  8717. FUNCTION_BASED: 1,
  8718. AXIAL: 2,
  8719. RADIAL: 3,
  8720. FREE_FORM_MESH: 4,
  8721. LATTICE_FORM_MESH: 5,
  8722. COONS_PATCH_MESH: 6,
  8723. TENSOR_PATCH_MESH: 7
  8724. };
  8725. var Pattern = (function PatternClosure() {
  8726. // Constructor should define this.getPattern
  8727. function Pattern() {
  8728. error('should not call Pattern constructor');
  8729. }
  8730. Pattern.prototype = {
  8731. // Input: current Canvas context
  8732. // Output: the appropriate fillStyle or strokeStyle
  8733. getPattern: function Pattern_getPattern(ctx) {
  8734. error('Should not call Pattern.getStyle: ' + ctx);
  8735. }
  8736. };
  8737. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8738. res) {
  8739. var dict = isStream(shading) ? shading.dict : shading;
  8740. var type = dict.get('ShadingType');
  8741. switch (type) {
  8742. case PatternType.AXIAL:
  8743. case PatternType.RADIAL:
  8744. // Both radial and axial shadings are handled by RadialAxial shading.
  8745. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8746. case PatternType.FREE_FORM_MESH:
  8747. case PatternType.LATTICE_FORM_MESH:
  8748. case PatternType.COONS_PATCH_MESH:
  8749. case PatternType.TENSOR_PATCH_MESH:
  8750. return new Shadings.Mesh(shading, matrix, xref, res);
  8751. default:
  8752. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8753. return new Shadings.Dummy();
  8754. }
  8755. };
  8756. return Pattern;
  8757. })();
  8758. var Shadings = {};
  8759. // A small number to offset the first/last color stops so we can insert ones to
  8760. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8761. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8762. // internally so we have to go bigger.
  8763. Shadings.SMALL_NUMBER = 1e-2;
  8764. // Radial and axial shading have very similar implementations
  8765. // If needed, the implementations can be broken into two classes
  8766. Shadings.RadialAxial = (function RadialAxialClosure() {
  8767. function RadialAxial(dict, matrix, xref, res) {
  8768. this.matrix = matrix;
  8769. this.coordsArr = dict.get('Coords');
  8770. this.shadingType = dict.get('ShadingType');
  8771. this.type = 'Pattern';
  8772. var cs = dict.get('ColorSpace', 'CS');
  8773. cs = ColorSpace.parse(cs, xref, res);
  8774. this.cs = cs;
  8775. var t0 = 0.0, t1 = 1.0;
  8776. if (dict.has('Domain')) {
  8777. var domainArr = dict.get('Domain');
  8778. t0 = domainArr[0];
  8779. t1 = domainArr[1];
  8780. }
  8781. var extendStart = false, extendEnd = false;
  8782. if (dict.has('Extend')) {
  8783. var extendArr = dict.get('Extend');
  8784. extendStart = extendArr[0];
  8785. extendEnd = extendArr[1];
  8786. }
  8787. if (this.shadingType === PatternType.RADIAL &&
  8788. (!extendStart || !extendEnd)) {
  8789. // Radial gradient only currently works if either circle is fully within
  8790. // the other circle.
  8791. var x1 = this.coordsArr[0];
  8792. var y1 = this.coordsArr[1];
  8793. var r1 = this.coordsArr[2];
  8794. var x2 = this.coordsArr[3];
  8795. var y2 = this.coordsArr[4];
  8796. var r2 = this.coordsArr[5];
  8797. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8798. if (r1 <= r2 + distance &&
  8799. r2 <= r1 + distance) {
  8800. warn('Unsupported radial gradient.');
  8801. }
  8802. }
  8803. this.extendStart = extendStart;
  8804. this.extendEnd = extendEnd;
  8805. var fnObj = dict.get('Function');
  8806. var fn = PDFFunction.parseArray(xref, fnObj);
  8807. // 10 samples seems good enough for now, but probably won't work
  8808. // if there are sharp color changes. Ideally, we would implement
  8809. // the spec faithfully and add lossless optimizations.
  8810. var diff = t1 - t0;
  8811. var step = diff / 10;
  8812. var colorStops = this.colorStops = [];
  8813. // Protect against bad domains so we don't end up in an infinte loop below.
  8814. if (t0 >= t1 || step <= 0) {
  8815. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8816. // now.
  8817. info('Bad shading domain.');
  8818. return;
  8819. }
  8820. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8821. var rgbColor;
  8822. for (var i = t0; i <= t1; i += step) {
  8823. ratio[0] = i;
  8824. fn(ratio, 0, color, 0);
  8825. rgbColor = cs.getRgb(color, 0);
  8826. var cssColor = Util.makeCssRgb(rgbColor);
  8827. colorStops.push([(i - t0) / diff, cssColor]);
  8828. }
  8829. var background = 'transparent';
  8830. if (dict.has('Background')) {
  8831. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8832. background = Util.makeCssRgb(rgbColor);
  8833. }
  8834. if (!extendStart) {
  8835. // Insert a color stop at the front and offset the first real color stop
  8836. // so it doesn't conflict with the one we insert.
  8837. colorStops.unshift([0, background]);
  8838. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8839. }
  8840. if (!extendEnd) {
  8841. // Same idea as above in extendStart but for the end.
  8842. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8843. colorStops.push([1, background]);
  8844. }
  8845. this.colorStops = colorStops;
  8846. }
  8847. RadialAxial.prototype = {
  8848. getIR: function RadialAxial_getIR() {
  8849. var coordsArr = this.coordsArr;
  8850. var shadingType = this.shadingType;
  8851. var type, p0, p1, r0, r1;
  8852. if (shadingType === PatternType.AXIAL) {
  8853. p0 = [coordsArr[0], coordsArr[1]];
  8854. p1 = [coordsArr[2], coordsArr[3]];
  8855. r0 = null;
  8856. r1 = null;
  8857. type = 'axial';
  8858. } else if (shadingType === PatternType.RADIAL) {
  8859. p0 = [coordsArr[0], coordsArr[1]];
  8860. p1 = [coordsArr[3], coordsArr[4]];
  8861. r0 = coordsArr[2];
  8862. r1 = coordsArr[5];
  8863. type = 'radial';
  8864. } else {
  8865. error('getPattern type unknown: ' + shadingType);
  8866. }
  8867. var matrix = this.matrix;
  8868. if (matrix) {
  8869. p0 = Util.applyTransform(p0, matrix);
  8870. p1 = Util.applyTransform(p1, matrix);
  8871. }
  8872. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  8873. }
  8874. };
  8875. return RadialAxial;
  8876. })();
  8877. // All mesh shading. For now, they will be presented as set of the triangles
  8878. // to be drawn on the canvas and rgb color for each vertex.
  8879. Shadings.Mesh = (function MeshClosure() {
  8880. function MeshStreamReader(stream, context) {
  8881. this.stream = stream;
  8882. this.context = context;
  8883. this.buffer = 0;
  8884. this.bufferLength = 0;
  8885. var numComps = context.numComps;
  8886. this.tmpCompsBuf = new Float32Array(numComps);
  8887. var csNumComps = context.colorSpace;
  8888. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  8889. this.tmpCompsBuf;
  8890. }
  8891. MeshStreamReader.prototype = {
  8892. get hasData() {
  8893. if (this.stream.end) {
  8894. return this.stream.pos < this.stream.end;
  8895. }
  8896. if (this.bufferLength > 0) {
  8897. return true;
  8898. }
  8899. var nextByte = this.stream.getByte();
  8900. if (nextByte < 0) {
  8901. return false;
  8902. }
  8903. this.buffer = nextByte;
  8904. this.bufferLength = 8;
  8905. return true;
  8906. },
  8907. readBits: function MeshStreamReader_readBits(n) {
  8908. var buffer = this.buffer;
  8909. var bufferLength = this.bufferLength;
  8910. if (n === 32) {
  8911. if (bufferLength === 0) {
  8912. return ((this.stream.getByte() << 24) |
  8913. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  8914. this.stream.getByte()) >>> 0;
  8915. }
  8916. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  8917. (this.stream.getByte() << 8) | this.stream.getByte();
  8918. var nextByte = this.stream.getByte();
  8919. this.buffer = nextByte & ((1 << bufferLength) - 1);
  8920. return ((buffer << (8 - bufferLength)) |
  8921. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  8922. }
  8923. if (n === 8 && bufferLength === 0) {
  8924. return this.stream.getByte();
  8925. }
  8926. while (bufferLength < n) {
  8927. buffer = (buffer << 8) | this.stream.getByte();
  8928. bufferLength += 8;
  8929. }
  8930. bufferLength -= n;
  8931. this.bufferLength = bufferLength;
  8932. this.buffer = buffer & ((1 << bufferLength) - 1);
  8933. return buffer >> bufferLength;
  8934. },
  8935. align: function MeshStreamReader_align() {
  8936. this.buffer = 0;
  8937. this.bufferLength = 0;
  8938. },
  8939. readFlag: function MeshStreamReader_readFlag() {
  8940. return this.readBits(this.context.bitsPerFlag);
  8941. },
  8942. readCoordinate: function MeshStreamReader_readCoordinate() {
  8943. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  8944. var xi = this.readBits(bitsPerCoordinate);
  8945. var yi = this.readBits(bitsPerCoordinate);
  8946. var decode = this.context.decode;
  8947. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  8948. 2.3283064365386963e-10; // 2 ^ -32
  8949. return [
  8950. xi * scale * (decode[1] - decode[0]) + decode[0],
  8951. yi * scale * (decode[3] - decode[2]) + decode[2]
  8952. ];
  8953. },
  8954. readComponents: function MeshStreamReader_readComponents() {
  8955. var numComps = this.context.numComps;
  8956. var bitsPerComponent = this.context.bitsPerComponent;
  8957. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  8958. 2.3283064365386963e-10; // 2 ^ -32
  8959. var decode = this.context.decode;
  8960. var components = this.tmpCompsBuf;
  8961. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  8962. var ci = this.readBits(bitsPerComponent);
  8963. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  8964. }
  8965. var color = this.tmpCsCompsBuf;
  8966. if (this.context.colorFn) {
  8967. this.context.colorFn(components, 0, color, 0);
  8968. }
  8969. return this.context.colorSpace.getRgb(color, 0);
  8970. }
  8971. };
  8972. function decodeType4Shading(mesh, reader) {
  8973. var coords = mesh.coords;
  8974. var colors = mesh.colors;
  8975. var operators = [];
  8976. var ps = []; // not maintaining cs since that will match ps
  8977. var verticesLeft = 0; // assuming we have all data to start a new triangle
  8978. while (reader.hasData) {
  8979. var f = reader.readFlag();
  8980. var coord = reader.readCoordinate();
  8981. var color = reader.readComponents();
  8982. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  8983. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  8984. switch (f) {
  8985. case 0:
  8986. verticesLeft = 3;
  8987. break;
  8988. case 1:
  8989. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  8990. verticesLeft = 1;
  8991. break;
  8992. case 2:
  8993. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  8994. verticesLeft = 1;
  8995. break;
  8996. }
  8997. operators.push(f);
  8998. }
  8999. ps.push(coords.length);
  9000. coords.push(coord);
  9001. colors.push(color);
  9002. verticesLeft--;
  9003. reader.align();
  9004. }
  9005. var psPacked = new Int32Array(ps);
  9006. mesh.figures.push({
  9007. type: 'triangles',
  9008. coords: psPacked,
  9009. colors: psPacked
  9010. });
  9011. }
  9012. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9013. var coords = mesh.coords;
  9014. var colors = mesh.colors;
  9015. var ps = []; // not maintaining cs since that will match ps
  9016. while (reader.hasData) {
  9017. var coord = reader.readCoordinate();
  9018. var color = reader.readComponents();
  9019. ps.push(coords.length);
  9020. coords.push(coord);
  9021. colors.push(color);
  9022. }
  9023. var psPacked = new Int32Array(ps);
  9024. mesh.figures.push({
  9025. type: 'lattice',
  9026. coords: psPacked,
  9027. colors: psPacked,
  9028. verticesPerRow: verticesPerRow
  9029. });
  9030. }
  9031. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9032. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9033. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9034. var getB = (function getBClosure() {
  9035. function buildB(count) {
  9036. var lut = [];
  9037. for (var i = 0; i <= count; i++) {
  9038. var t = i / count, t_ = 1 - t;
  9039. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9040. 3 * t * t * t_, t * t * t]));
  9041. }
  9042. return lut;
  9043. }
  9044. var cache = [];
  9045. return function getB(count) {
  9046. if (!cache[count]) {
  9047. cache[count] = buildB(count);
  9048. }
  9049. return cache[count];
  9050. };
  9051. })();
  9052. function buildFigureFromPatch(mesh, index) {
  9053. var figure = mesh.figures[index];
  9054. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9055. var coords = mesh.coords, colors = mesh.colors;
  9056. var pi = figure.coords;
  9057. var ci = figure.colors;
  9058. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9059. coords[pi[12]][0], coords[pi[15]][0]);
  9060. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9061. coords[pi[12]][1], coords[pi[15]][1]);
  9062. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9063. coords[pi[12]][0], coords[pi[15]][0]);
  9064. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9065. coords[pi[12]][1], coords[pi[15]][1]);
  9066. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9067. (mesh.bounds[2] - mesh.bounds[0]));
  9068. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9069. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9070. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9071. (mesh.bounds[3] - mesh.bounds[1]));
  9072. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9073. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9074. var verticesPerRow = splitXBy + 1;
  9075. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9076. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9077. var k = 0;
  9078. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9079. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9080. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9081. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9082. for (var row = 0; row <= splitYBy; row++) {
  9083. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9084. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9085. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9086. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9087. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9088. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9089. for (var col = 0; col <= splitXBy; col++, k++) {
  9090. if ((row === 0 || row === splitYBy) &&
  9091. (col === 0 || col === splitXBy)) {
  9092. continue;
  9093. }
  9094. var x = 0, y = 0;
  9095. var q = 0;
  9096. for (var i = 0; i <= 3; i++) {
  9097. for (var j = 0; j <= 3; j++, q++) {
  9098. var m = bRow[row][i] * bCol[col][j];
  9099. x += coords[pi[q]][0] * m;
  9100. y += coords[pi[q]][1] * m;
  9101. }
  9102. }
  9103. figureCoords[k] = coords.length;
  9104. coords.push([x, y]);
  9105. figureColors[k] = colors.length;
  9106. var newColor = new Uint8Array(3);
  9107. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9108. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9109. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9110. colors.push(newColor);
  9111. }
  9112. }
  9113. figureCoords[0] = pi[0];
  9114. figureColors[0] = ci[0];
  9115. figureCoords[splitXBy] = pi[3];
  9116. figureColors[splitXBy] = ci[1];
  9117. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9118. figureColors[verticesPerRow * splitYBy] = ci[2];
  9119. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9120. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9121. mesh.figures[index] = {
  9122. type: 'lattice',
  9123. coords: figureCoords,
  9124. colors: figureColors,
  9125. verticesPerRow: verticesPerRow
  9126. };
  9127. }
  9128. function decodeType6Shading(mesh, reader) {
  9129. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9130. var coords = mesh.coords;
  9131. var colors = mesh.colors;
  9132. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9133. var cs = new Int32Array(4); // c00, c30, c03, c33
  9134. while (reader.hasData) {
  9135. var f = reader.readFlag();
  9136. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9137. var i, ii;
  9138. var pi = coords.length;
  9139. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9140. coords.push(reader.readCoordinate());
  9141. }
  9142. var ci = colors.length;
  9143. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9144. colors.push(reader.readComponents());
  9145. }
  9146. var tmp1, tmp2, tmp3, tmp4;
  9147. switch (f) {
  9148. case 0:
  9149. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9150. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9151. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9152. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9153. cs[2] = ci + 1; cs[3] = ci + 2;
  9154. cs[0] = ci; cs[1] = ci + 3;
  9155. break;
  9156. case 1:
  9157. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9158. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9159. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9160. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9161. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9162. tmp1 = cs[2]; tmp2 = cs[3];
  9163. cs[2] = ci + 1; cs[3] = ci;
  9164. cs[0] = tmp1; cs[1] = tmp2;
  9165. break;
  9166. case 2:
  9167. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9168. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9169. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9170. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9171. cs[2] = cs[3]; cs[3] = ci + 1;
  9172. cs[0] = cs[1]; cs[1] = ci;
  9173. break;
  9174. case 3:
  9175. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9176. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9177. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9178. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9179. cs[2] = cs[0]; cs[3] = cs[1];
  9180. cs[0] = ci; cs[1] = ci + 1;
  9181. break;
  9182. }
  9183. // set p11, p12, p21, p22
  9184. ps[5] = coords.length;
  9185. coords.push([
  9186. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9187. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9188. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9189. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9190. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9191. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9192. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9193. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9194. ]);
  9195. ps[6] = coords.length;
  9196. coords.push([
  9197. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9198. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9199. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9200. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9201. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9202. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9203. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9204. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9205. ]);
  9206. ps[9] = coords.length;
  9207. coords.push([
  9208. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9209. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9210. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9211. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9212. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9213. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9214. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9215. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9216. ]);
  9217. ps[10] = coords.length;
  9218. coords.push([
  9219. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9220. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9221. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9222. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9223. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9224. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9225. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9226. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9227. ]);
  9228. mesh.figures.push({
  9229. type: 'patch',
  9230. coords: new Int32Array(ps), // making copies of ps and cs
  9231. colors: new Int32Array(cs)
  9232. });
  9233. }
  9234. }
  9235. function decodeType7Shading(mesh, reader) {
  9236. var coords = mesh.coords;
  9237. var colors = mesh.colors;
  9238. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9239. var cs = new Int32Array(4); // c00, c30, c03, c33
  9240. while (reader.hasData) {
  9241. var f = reader.readFlag();
  9242. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9243. var i, ii;
  9244. var pi = coords.length;
  9245. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9246. coords.push(reader.readCoordinate());
  9247. }
  9248. var ci = colors.length;
  9249. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9250. colors.push(reader.readComponents());
  9251. }
  9252. var tmp1, tmp2, tmp3, tmp4;
  9253. switch (f) {
  9254. case 0:
  9255. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9256. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9257. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9258. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9259. cs[2] = ci + 1; cs[3] = ci + 2;
  9260. cs[0] = ci; cs[1] = ci + 3;
  9261. break;
  9262. case 1:
  9263. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9264. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9265. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9266. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9267. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9268. tmp1 = cs[2]; tmp2 = cs[3];
  9269. cs[2] = ci + 1; cs[3] = ci;
  9270. cs[0] = tmp1; cs[1] = tmp2;
  9271. break;
  9272. case 2:
  9273. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9274. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9275. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9276. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9277. cs[2] = cs[3]; cs[3] = ci + 1;
  9278. cs[0] = cs[1]; cs[1] = ci;
  9279. break;
  9280. case 3:
  9281. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9282. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9283. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9284. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9285. cs[2] = cs[0]; cs[3] = cs[1];
  9286. cs[0] = ci; cs[1] = ci + 1;
  9287. break;
  9288. }
  9289. mesh.figures.push({
  9290. type: 'patch',
  9291. coords: new Int32Array(ps), // making copies of ps and cs
  9292. colors: new Int32Array(cs)
  9293. });
  9294. }
  9295. }
  9296. function updateBounds(mesh) {
  9297. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9298. maxX = minX, maxY = minY;
  9299. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9300. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9301. minX = minX > x ? x : minX;
  9302. minY = minY > y ? y : minY;
  9303. maxX = maxX < x ? x : maxX;
  9304. maxY = maxY < y ? y : maxY;
  9305. }
  9306. mesh.bounds = [minX, minY, maxX, maxY];
  9307. }
  9308. function packData(mesh) {
  9309. var i, ii, j, jj;
  9310. var coords = mesh.coords;
  9311. var coordsPacked = new Float32Array(coords.length * 2);
  9312. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9313. var xy = coords[i];
  9314. coordsPacked[j++] = xy[0];
  9315. coordsPacked[j++] = xy[1];
  9316. }
  9317. mesh.coords = coordsPacked;
  9318. var colors = mesh.colors;
  9319. var colorsPacked = new Uint8Array(colors.length * 3);
  9320. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9321. var c = colors[i];
  9322. colorsPacked[j++] = c[0];
  9323. colorsPacked[j++] = c[1];
  9324. colorsPacked[j++] = c[2];
  9325. }
  9326. mesh.colors = colorsPacked;
  9327. var figures = mesh.figures;
  9328. for (i = 0, ii = figures.length; i < ii; i++) {
  9329. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9330. for (j = 0, jj = ps.length; j < jj; j++) {
  9331. ps[j] *= 2;
  9332. cs[j] *= 3;
  9333. }
  9334. }
  9335. }
  9336. function Mesh(stream, matrix, xref, res) {
  9337. assert(isStream(stream), 'Mesh data is not a stream');
  9338. var dict = stream.dict;
  9339. this.matrix = matrix;
  9340. this.shadingType = dict.get('ShadingType');
  9341. this.type = 'Pattern';
  9342. this.bbox = dict.get('BBox');
  9343. var cs = dict.get('ColorSpace', 'CS');
  9344. cs = ColorSpace.parse(cs, xref, res);
  9345. this.cs = cs;
  9346. this.background = dict.has('Background') ?
  9347. cs.getRgb(dict.get('Background'), 0) : null;
  9348. var fnObj = dict.get('Function');
  9349. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9350. this.coords = [];
  9351. this.colors = [];
  9352. this.figures = [];
  9353. var decodeContext = {
  9354. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9355. bitsPerComponent: dict.get('BitsPerComponent'),
  9356. bitsPerFlag: dict.get('BitsPerFlag'),
  9357. decode: dict.get('Decode'),
  9358. colorFn: fn,
  9359. colorSpace: cs,
  9360. numComps: fn ? 1 : cs.numComps
  9361. };
  9362. var reader = new MeshStreamReader(stream, decodeContext);
  9363. var patchMesh = false;
  9364. switch (this.shadingType) {
  9365. case PatternType.FREE_FORM_MESH:
  9366. decodeType4Shading(this, reader);
  9367. break;
  9368. case PatternType.LATTICE_FORM_MESH:
  9369. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9370. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9371. decodeType5Shading(this, reader, verticesPerRow);
  9372. break;
  9373. case PatternType.COONS_PATCH_MESH:
  9374. decodeType6Shading(this, reader);
  9375. patchMesh = true;
  9376. break;
  9377. case PatternType.TENSOR_PATCH_MESH:
  9378. decodeType7Shading(this, reader);
  9379. patchMesh = true;
  9380. break;
  9381. default:
  9382. error('Unsupported mesh type.');
  9383. break;
  9384. }
  9385. if (patchMesh) {
  9386. // dirty bounds calculation for determining, how dense shall be triangles
  9387. updateBounds(this);
  9388. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9389. buildFigureFromPatch(this, i);
  9390. }
  9391. }
  9392. // calculate bounds
  9393. updateBounds(this);
  9394. packData(this);
  9395. }
  9396. Mesh.prototype = {
  9397. getIR: function Mesh_getIR() {
  9398. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9399. this.bounds, this.matrix, this.bbox, this.background];
  9400. }
  9401. };
  9402. return Mesh;
  9403. })();
  9404. Shadings.Dummy = (function DummyClosure() {
  9405. function Dummy() {
  9406. this.type = 'Pattern';
  9407. }
  9408. Dummy.prototype = {
  9409. getIR: function Dummy_getIR() {
  9410. return ['Dummy'];
  9411. }
  9412. };
  9413. return Dummy;
  9414. })();
  9415. function getTilingPatternIR(operatorList, dict, args) {
  9416. var matrix = dict.get('Matrix');
  9417. var bbox = dict.get('BBox');
  9418. var xstep = dict.get('XStep');
  9419. var ystep = dict.get('YStep');
  9420. var paintType = dict.get('PaintType');
  9421. var tilingType = dict.get('TilingType');
  9422. return [
  9423. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9424. paintType, tilingType
  9425. ];
  9426. }
  9427. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9428. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9429. uniquePrefix, idCounters, fontCache) {
  9430. this.pdfManager = pdfManager;
  9431. this.xref = xref;
  9432. this.handler = handler;
  9433. this.pageIndex = pageIndex;
  9434. this.uniquePrefix = uniquePrefix;
  9435. this.idCounters = idCounters;
  9436. this.fontCache = fontCache;
  9437. }
  9438. // Trying to minimize Date.now() usage and check every 100 time
  9439. var TIME_SLOT_DURATION_MS = 20;
  9440. var CHECK_TIME_EVERY = 100;
  9441. function TimeSlotManager() {
  9442. this.reset();
  9443. }
  9444. TimeSlotManager.prototype = {
  9445. check: function TimeSlotManager_check() {
  9446. if (++this.checked < CHECK_TIME_EVERY) {
  9447. return false;
  9448. }
  9449. this.checked = 0;
  9450. return this.endTime <= Date.now();
  9451. },
  9452. reset: function TimeSlotManager_reset() {
  9453. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9454. this.checked = 0;
  9455. }
  9456. };
  9457. var deferred = Promise.resolve();
  9458. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9459. PartialEvaluator.prototype = {
  9460. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9461. if (!isDict(resources)) {
  9462. return false;
  9463. }
  9464. var processed = Object.create(null);
  9465. if (resources.objId) {
  9466. processed[resources.objId] = true;
  9467. }
  9468. var nodes = [resources];
  9469. while (nodes.length) {
  9470. var key;
  9471. var node = nodes.shift();
  9472. // First check the current resources for blend modes.
  9473. var graphicStates = node.get('ExtGState');
  9474. if (isDict(graphicStates)) {
  9475. graphicStates = graphicStates.getAll();
  9476. for (key in graphicStates) {
  9477. var graphicState = graphicStates[key];
  9478. var bm = graphicState['BM'];
  9479. if (isName(bm) && bm.name !== 'Normal') {
  9480. return true;
  9481. }
  9482. }
  9483. }
  9484. // Descend into the XObjects to look for more resources and blend modes.
  9485. var xObjects = node.get('XObject');
  9486. if (!isDict(xObjects)) {
  9487. continue;
  9488. }
  9489. xObjects = xObjects.getAll();
  9490. for (key in xObjects) {
  9491. var xObject = xObjects[key];
  9492. if (!isStream(xObject)) {
  9493. continue;
  9494. }
  9495. if (xObject.dict.objId) {
  9496. if (processed[xObject.dict.objId]) {
  9497. // stream has objId and is processed already
  9498. continue;
  9499. }
  9500. processed[xObject.dict.objId] = true;
  9501. }
  9502. var xResources = xObject.dict.get('Resources');
  9503. // Checking objId to detect an infinite loop.
  9504. if (isDict(xResources) &&
  9505. (!xResources.objId || !processed[xResources.objId])) {
  9506. nodes.push(xResources);
  9507. if (xResources.objId) {
  9508. processed[xResources.objId] = true;
  9509. }
  9510. }
  9511. }
  9512. }
  9513. return false;
  9514. },
  9515. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9516. xobj, smask,
  9517. operatorList,
  9518. initialState) {
  9519. var matrix = xobj.dict.get('Matrix');
  9520. var bbox = xobj.dict.get('BBox');
  9521. var group = xobj.dict.get('Group');
  9522. if (group) {
  9523. var groupOptions = {
  9524. matrix: matrix,
  9525. bbox: bbox,
  9526. smask: smask,
  9527. isolated: false,
  9528. knockout: false
  9529. };
  9530. var groupSubtype = group.get('S');
  9531. var colorSpace;
  9532. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9533. groupOptions.isolated = (group.get('I') || false);
  9534. groupOptions.knockout = (group.get('K') || false);
  9535. colorSpace = (group.has('CS') ?
  9536. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9537. }
  9538. if (smask && smask.backdrop) {
  9539. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9540. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9541. }
  9542. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9543. }
  9544. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9545. return this.getOperatorList(xobj,
  9546. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9547. then(function () {
  9548. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9549. if (group) {
  9550. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9551. }
  9552. });
  9553. },
  9554. buildPaintImageXObject:
  9555. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9556. inline, operatorList,
  9557. cacheKey, cache) {
  9558. var self = this;
  9559. var dict = image.dict;
  9560. var w = dict.get('Width', 'W');
  9561. var h = dict.get('Height', 'H');
  9562. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9563. warn('Image dimensions are missing, or not numbers.');
  9564. return;
  9565. }
  9566. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9567. warn('Image exceeded maximum allowed size and was removed.');
  9568. return;
  9569. }
  9570. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9571. var imgData, args;
  9572. if (imageMask) {
  9573. // This depends on a tmpCanvas being filled with the
  9574. // current fillStyle, such that processing the pixel
  9575. // data can't be done here. Instead of creating a
  9576. // complete PDFImage, only read the information needed
  9577. // for later.
  9578. var width = dict.get('Width', 'W');
  9579. var height = dict.get('Height', 'H');
  9580. var bitStrideLength = (width + 7) >> 3;
  9581. var imgArray = image.getBytes(bitStrideLength * height);
  9582. var decode = dict.get('Decode', 'D');
  9583. var inverseDecode = (!!decode && decode[0] > 0);
  9584. imgData = PDFImage.createMask(imgArray, width, height,
  9585. image instanceof DecodeStream,
  9586. inverseDecode);
  9587. imgData.cached = true;
  9588. args = [imgData];
  9589. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9590. if (cacheKey) {
  9591. cache.key = cacheKey;
  9592. cache.fn = OPS.paintImageMaskXObject;
  9593. cache.args = args;
  9594. }
  9595. return;
  9596. }
  9597. var softMask = (dict.get('SMask', 'SM') || false);
  9598. var mask = (dict.get('Mask') || false);
  9599. var SMALL_IMAGE_DIMENSIONS = 200;
  9600. // Inlining small images into the queue as RGB data
  9601. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9602. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9603. var imageObj = new PDFImage(this.xref, resources, image,
  9604. inline, null, null);
  9605. // We force the use of RGBA_32BPP images here, because we can't handle
  9606. // any other kind.
  9607. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9608. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9609. return;
  9610. }
  9611. // If there is no imageMask, create the PDFImage and a lot
  9612. // of image processing can be done here.
  9613. var uniquePrefix = (this.uniquePrefix || '');
  9614. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9615. operatorList.addDependency(objId);
  9616. args = [objId, w, h];
  9617. if (!softMask && !mask && image instanceof JpegStream &&
  9618. image.isNativelySupported(this.xref, resources)) {
  9619. // These JPEGs don't need any more processing so we can just send it.
  9620. operatorList.addOp(OPS.paintJpegXObject, args);
  9621. this.handler.send('obj',
  9622. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9623. return;
  9624. }
  9625. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9626. then(function(imageObj) {
  9627. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9628. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9629. [imgData.data.buffer]);
  9630. }).then(null, function (reason) {
  9631. warn('Unable to decode image: ' + reason);
  9632. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9633. });
  9634. operatorList.addOp(OPS.paintImageXObject, args);
  9635. if (cacheKey) {
  9636. cache.key = cacheKey;
  9637. cache.fn = OPS.paintImageXObject;
  9638. cache.args = args;
  9639. }
  9640. },
  9641. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9642. operatorList,
  9643. stateManager) {
  9644. var smaskContent = smask.get('G');
  9645. var smaskOptions = {
  9646. subtype: smask.get('S').name,
  9647. backdrop: smask.get('BC')
  9648. };
  9649. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9650. operatorList, stateManager.state.clone());
  9651. },
  9652. handleTilingType:
  9653. function PartialEvaluator_handleTilingType(fn, args, resources,
  9654. pattern, patternDict,
  9655. operatorList) {
  9656. // Create an IR of the pattern code.
  9657. var tilingOpList = new OperatorList();
  9658. return this.getOperatorList(pattern,
  9659. (patternDict.get('Resources') || resources), tilingOpList).
  9660. then(function () {
  9661. // Add the dependencies to the parent operator list so they are
  9662. // resolved before sub operator list is executed synchronously.
  9663. operatorList.addDependencies(tilingOpList.dependencies);
  9664. operatorList.addOp(fn, getTilingPatternIR({
  9665. fnArray: tilingOpList.fnArray,
  9666. argsArray: tilingOpList.argsArray
  9667. }, patternDict, args));
  9668. });
  9669. },
  9670. handleSetFont:
  9671. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9672. operatorList, state) {
  9673. // TODO(mack): Not needed?
  9674. var fontName;
  9675. if (fontArgs) {
  9676. fontArgs = fontArgs.slice();
  9677. fontName = fontArgs[0].name;
  9678. }
  9679. var self = this;
  9680. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9681. function (translated) {
  9682. if (!translated.font.isType3Font) {
  9683. return translated;
  9684. }
  9685. return translated.loadType3Data(self, resources, operatorList).then(
  9686. function () {
  9687. return translated;
  9688. });
  9689. }).then(function (translated) {
  9690. state.font = translated.font;
  9691. translated.send(self.handler);
  9692. return translated.loadedName;
  9693. });
  9694. },
  9695. handleText: function PartialEvaluator_handleText(chars, state) {
  9696. var font = state.font;
  9697. var glyphs = font.charsToGlyphs(chars);
  9698. var isAddToPathSet = !!(state.textRenderingMode &
  9699. TextRenderingMode.ADD_TO_PATH_FLAG);
  9700. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9701. var buildPath = function (fontChar) {
  9702. if (!font.renderer.hasBuiltPath(fontChar)) {
  9703. var path = font.renderer.getPathJs(fontChar);
  9704. this.handler.send('commonobj', [
  9705. font.loadedName + '_path_' + fontChar,
  9706. 'FontPath',
  9707. path
  9708. ]);
  9709. }
  9710. }.bind(this);
  9711. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9712. var glyph = glyphs[i];
  9713. if (glyph === null) {
  9714. continue;
  9715. }
  9716. buildPath(glyph.fontChar);
  9717. // If the glyph has an accent we need to build a path for its
  9718. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9719. var accent = glyph.accent;
  9720. if (accent && accent.fontChar) {
  9721. buildPath(accent.fontChar);
  9722. }
  9723. }
  9724. }
  9725. return glyphs;
  9726. },
  9727. setGState: function PartialEvaluator_setGState(resources, gState,
  9728. operatorList, xref,
  9729. stateManager) {
  9730. // This array holds the converted/processed state data.
  9731. var gStateObj = [];
  9732. var gStateMap = gState.map;
  9733. var self = this;
  9734. var promise = Promise.resolve();
  9735. for (var key in gStateMap) {
  9736. var value = gStateMap[key];
  9737. switch (key) {
  9738. case 'Type':
  9739. break;
  9740. case 'LW':
  9741. case 'LC':
  9742. case 'LJ':
  9743. case 'ML':
  9744. case 'D':
  9745. case 'RI':
  9746. case 'FL':
  9747. case 'CA':
  9748. case 'ca':
  9749. gStateObj.push([key, value]);
  9750. break;
  9751. case 'Font':
  9752. promise = promise.then(function () {
  9753. return self.handleSetFont(resources, null, value[0],
  9754. operatorList, stateManager.state).
  9755. then(function (loadedName) {
  9756. operatorList.addDependency(loadedName);
  9757. gStateObj.push([key, [loadedName, value[1]]]);
  9758. });
  9759. });
  9760. break;
  9761. case 'BM':
  9762. gStateObj.push([key, value]);
  9763. break;
  9764. case 'SMask':
  9765. if (isName(value) && value.name === 'None') {
  9766. gStateObj.push([key, false]);
  9767. break;
  9768. }
  9769. var dict = xref.fetchIfRef(value);
  9770. if (isDict(dict)) {
  9771. promise = promise.then(function () {
  9772. return self.handleSMask(dict, resources, operatorList,
  9773. stateManager);
  9774. });
  9775. gStateObj.push([key, true]);
  9776. } else {
  9777. warn('Unsupported SMask type');
  9778. }
  9779. break;
  9780. // Only generate info log messages for the following since
  9781. // they are unlikely to have a big impact on the rendering.
  9782. case 'OP':
  9783. case 'op':
  9784. case 'OPM':
  9785. case 'BG':
  9786. case 'BG2':
  9787. case 'UCR':
  9788. case 'UCR2':
  9789. case 'TR':
  9790. case 'TR2':
  9791. case 'HT':
  9792. case 'SM':
  9793. case 'SA':
  9794. case 'AIS':
  9795. case 'TK':
  9796. // TODO implement these operators.
  9797. info('graphic state operator ' + key);
  9798. break;
  9799. default:
  9800. info('Unknown graphic state operator ' + key);
  9801. break;
  9802. }
  9803. }
  9804. return promise.then(function () {
  9805. if (gStateObj.length >= 0) {
  9806. operatorList.addOp(OPS.setGState, [gStateObj]);
  9807. }
  9808. });
  9809. },
  9810. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9811. resources) {
  9812. function errorFont() {
  9813. return Promise.resolve(new TranslatedFont('g_font_error',
  9814. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9815. }
  9816. var fontRef;
  9817. if (font) { // Loading by ref.
  9818. assert(isRef(font));
  9819. fontRef = font;
  9820. } else { // Loading by name.
  9821. var fontRes = resources.get('Font');
  9822. if (fontRes) {
  9823. fontRef = fontRes.getRaw(fontName);
  9824. } else {
  9825. warn('fontRes not available');
  9826. return errorFont();
  9827. }
  9828. }
  9829. if (!fontRef) {
  9830. warn('fontRef not available');
  9831. return errorFont();
  9832. }
  9833. if (this.fontCache.has(fontRef)) {
  9834. return this.fontCache.get(fontRef);
  9835. }
  9836. font = xref.fetchIfRef(fontRef);
  9837. if (!isDict(font)) {
  9838. return errorFont();
  9839. }
  9840. // We are holding font.translated references just for fontRef that are not
  9841. // dictionaries (Dict). See explanation below.
  9842. if (font.translated) {
  9843. return font.translated;
  9844. }
  9845. var fontCapability = createPromiseCapability();
  9846. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9847. var descriptor = preEvaluatedFont.descriptor;
  9848. var fontID = fontRef.num + '_' + fontRef.gen;
  9849. if (isDict(descriptor)) {
  9850. if (!descriptor.fontAliases) {
  9851. descriptor.fontAliases = Object.create(null);
  9852. }
  9853. var fontAliases = descriptor.fontAliases;
  9854. var hash = preEvaluatedFont.hash;
  9855. if (fontAliases[hash]) {
  9856. var aliasFontRef = fontAliases[hash].aliasRef;
  9857. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9858. this.fontCache.putAlias(fontRef, aliasFontRef);
  9859. return this.fontCache.get(fontRef);
  9860. }
  9861. }
  9862. if (!fontAliases[hash]) {
  9863. fontAliases[hash] = {
  9864. fontID: Font.getFontID()
  9865. };
  9866. }
  9867. fontAliases[hash].aliasRef = fontRef;
  9868. fontID = fontAliases[hash].fontID;
  9869. }
  9870. // Workaround for bad PDF generators that don't reference fonts
  9871. // properly, i.e. by not using an object identifier.
  9872. // Check if the fontRef is a Dict (as opposed to a standard object),
  9873. // in which case we don't cache the font and instead reference it by
  9874. // fontName in font.loadedName below.
  9875. var fontRefIsDict = isDict(fontRef);
  9876. if (!fontRefIsDict) {
  9877. this.fontCache.put(fontRef, fontCapability.promise);
  9878. }
  9879. // Keep track of each font we translated so the caller can
  9880. // load them asynchronously before calling display on a page.
  9881. font.loadedName = 'g_font_' + (fontRefIsDict ?
  9882. fontName.replace(/\W/g, '') : fontID);
  9883. font.translated = fontCapability.promise;
  9884. // TODO move promises into translate font
  9885. var translatedPromise;
  9886. try {
  9887. translatedPromise = Promise.resolve(
  9888. this.translateFont(preEvaluatedFont, xref));
  9889. } catch (e) {
  9890. translatedPromise = Promise.reject(e);
  9891. }
  9892. translatedPromise.then(function (translatedFont) {
  9893. if (translatedFont.fontType !== undefined) {
  9894. var xrefFontStats = xref.stats.fontTypes;
  9895. xrefFontStats[translatedFont.fontType] = true;
  9896. }
  9897. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9898. translatedFont, font));
  9899. }, function (reason) {
  9900. // TODO fontCapability.reject?
  9901. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  9902. try {
  9903. // error, but it's still nice to have font type reported
  9904. var descriptor = preEvaluatedFont.descriptor;
  9905. var fontFile3 = descriptor && descriptor.get('FontFile3');
  9906. var subtype = fontFile3 && fontFile3.get('Subtype');
  9907. var fontType = getFontType(preEvaluatedFont.type,
  9908. subtype && subtype.name);
  9909. var xrefFontStats = xref.stats.fontTypes;
  9910. xrefFontStats[fontType] = true;
  9911. } catch (ex) { }
  9912. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9913. new ErrorFont(reason instanceof Error ? reason.message : reason),
  9914. font));
  9915. });
  9916. return fontCapability.promise;
  9917. },
  9918. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  9919. var lastIndex = operatorList.length - 1;
  9920. if (!args) {
  9921. args = [];
  9922. }
  9923. if (lastIndex < 0 ||
  9924. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  9925. operatorList.addOp(OPS.constructPath, [[fn], args]);
  9926. } else {
  9927. var opArgs = operatorList.argsArray[lastIndex];
  9928. opArgs[0].push(fn);
  9929. Array.prototype.push.apply(opArgs[1], args);
  9930. }
  9931. },
  9932. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  9933. cs, patterns, resources, xref) {
  9934. // compile tiling patterns
  9935. var patternName = args[args.length - 1];
  9936. // SCN/scn applies patterns along with normal colors
  9937. var pattern;
  9938. if (isName(patternName) &&
  9939. (pattern = patterns.get(patternName.name))) {
  9940. var dict = (isStream(pattern) ? pattern.dict : pattern);
  9941. var typeNum = dict.get('PatternType');
  9942. if (typeNum === TILING_PATTERN) {
  9943. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  9944. return this.handleTilingType(fn, color, resources, pattern,
  9945. dict, operatorList);
  9946. } else if (typeNum === SHADING_PATTERN) {
  9947. var shading = dict.get('Shading');
  9948. var matrix = dict.get('Matrix');
  9949. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  9950. operatorList.addOp(fn, pattern.getIR());
  9951. return Promise.resolve();
  9952. } else {
  9953. return Promise.reject('Unknown PatternType: ' + typeNum);
  9954. }
  9955. }
  9956. // TODO shall we fail here?
  9957. operatorList.addOp(fn, args);
  9958. return Promise.resolve();
  9959. },
  9960. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  9961. resources,
  9962. operatorList,
  9963. initialState) {
  9964. var self = this;
  9965. var xref = this.xref;
  9966. var imageCache = {};
  9967. assert(operatorList);
  9968. resources = (resources || Dict.empty);
  9969. var xobjs = (resources.get('XObject') || Dict.empty);
  9970. var patterns = (resources.get('Pattern') || Dict.empty);
  9971. var stateManager = new StateManager(initialState || new EvalState());
  9972. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9973. var timeSlotManager = new TimeSlotManager();
  9974. return new Promise(function next(resolve, reject) {
  9975. timeSlotManager.reset();
  9976. var stop, operation = {}, i, ii, cs;
  9977. while (!(stop = timeSlotManager.check())) {
  9978. // The arguments parsed by read() are used beyond this loop, so we
  9979. // cannot reuse the same array on each iteration. Therefore we pass
  9980. // in |null| as the initial value (see the comment on
  9981. // EvaluatorPreprocessor_read() for why).
  9982. operation.args = null;
  9983. if (!(preprocessor.read(operation))) {
  9984. break;
  9985. }
  9986. var args = operation.args;
  9987. var fn = operation.fn;
  9988. switch (fn | 0) {
  9989. case OPS.paintXObject:
  9990. if (args[0].code) {
  9991. break;
  9992. }
  9993. // eagerly compile XForm objects
  9994. var name = args[0].name;
  9995. if (imageCache.key === name) {
  9996. operatorList.addOp(imageCache.fn, imageCache.args);
  9997. args = null;
  9998. continue;
  9999. }
  10000. var xobj = xobjs.get(name);
  10001. if (xobj) {
  10002. assert(isStream(xobj), 'XObject should be a stream');
  10003. var type = xobj.dict.get('Subtype');
  10004. assert(isName(type),
  10005. 'XObject should have a Name subtype');
  10006. if (type.name === 'Form') {
  10007. stateManager.save();
  10008. return self.buildFormXObject(resources, xobj, null,
  10009. operatorList,
  10010. stateManager.state.clone()).
  10011. then(function () {
  10012. stateManager.restore();
  10013. next(resolve, reject);
  10014. }, reject);
  10015. } else if (type.name === 'Image') {
  10016. self.buildPaintImageXObject(resources, xobj, false,
  10017. operatorList, name, imageCache);
  10018. args = null;
  10019. continue;
  10020. } else if (type.name === 'PS') {
  10021. // PostScript XObjects are unused when viewing documents.
  10022. // See section 4.7.1 of Adobe's PDF reference.
  10023. info('Ignored XObject subtype PS');
  10024. continue;
  10025. } else {
  10026. error('Unhandled XObject subtype ' + type.name);
  10027. }
  10028. }
  10029. break;
  10030. case OPS.setFont:
  10031. var fontSize = args[1];
  10032. // eagerly collect all fonts
  10033. return self.handleSetFont(resources, args, null,
  10034. operatorList, stateManager.state).
  10035. then(function (loadedName) {
  10036. operatorList.addDependency(loadedName);
  10037. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10038. next(resolve, reject);
  10039. }, reject);
  10040. case OPS.endInlineImage:
  10041. var cacheKey = args[0].cacheKey;
  10042. if (cacheKey && imageCache.key === cacheKey) {
  10043. operatorList.addOp(imageCache.fn, imageCache.args);
  10044. args = null;
  10045. continue;
  10046. }
  10047. self.buildPaintImageXObject(resources, args[0], true,
  10048. operatorList, cacheKey, imageCache);
  10049. args = null;
  10050. continue;
  10051. case OPS.showText:
  10052. args[0] = self.handleText(args[0], stateManager.state);
  10053. break;
  10054. case OPS.showSpacedText:
  10055. var arr = args[0];
  10056. var combinedGlyphs = [];
  10057. var arrLength = arr.length;
  10058. for (i = 0; i < arrLength; ++i) {
  10059. var arrItem = arr[i];
  10060. if (isString(arrItem)) {
  10061. Array.prototype.push.apply(combinedGlyphs,
  10062. self.handleText(arrItem, stateManager.state));
  10063. } else if (isNum(arrItem)) {
  10064. combinedGlyphs.push(arrItem);
  10065. }
  10066. }
  10067. args[0] = combinedGlyphs;
  10068. fn = OPS.showText;
  10069. break;
  10070. case OPS.nextLineShowText:
  10071. operatorList.addOp(OPS.nextLine);
  10072. args[0] = self.handleText(args[0], stateManager.state);
  10073. fn = OPS.showText;
  10074. break;
  10075. case OPS.nextLineSetSpacingShowText:
  10076. operatorList.addOp(OPS.nextLine);
  10077. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10078. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10079. args[0] = self.handleText(args[0], stateManager.state);
  10080. fn = OPS.showText;
  10081. break;
  10082. case OPS.setTextRenderingMode:
  10083. stateManager.state.textRenderingMode = args[0];
  10084. break;
  10085. case OPS.setFillColorSpace:
  10086. stateManager.state.fillColorSpace =
  10087. ColorSpace.parse(args[0], xref, resources);
  10088. continue;
  10089. case OPS.setStrokeColorSpace:
  10090. stateManager.state.strokeColorSpace =
  10091. ColorSpace.parse(args[0], xref, resources);
  10092. continue;
  10093. case OPS.setFillColor:
  10094. cs = stateManager.state.fillColorSpace;
  10095. args = cs.getRgb(args, 0);
  10096. fn = OPS.setFillRGBColor;
  10097. break;
  10098. case OPS.setStrokeColor:
  10099. cs = stateManager.state.strokeColorSpace;
  10100. args = cs.getRgb(args, 0);
  10101. fn = OPS.setStrokeRGBColor;
  10102. break;
  10103. case OPS.setFillGray:
  10104. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10105. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10106. fn = OPS.setFillRGBColor;
  10107. break;
  10108. case OPS.setStrokeGray:
  10109. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10110. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10111. fn = OPS.setStrokeRGBColor;
  10112. break;
  10113. case OPS.setFillCMYKColor:
  10114. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10115. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10116. fn = OPS.setFillRGBColor;
  10117. break;
  10118. case OPS.setStrokeCMYKColor:
  10119. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10120. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10121. fn = OPS.setStrokeRGBColor;
  10122. break;
  10123. case OPS.setFillRGBColor:
  10124. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10125. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10126. break;
  10127. case OPS.setStrokeRGBColor:
  10128. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10129. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10130. break;
  10131. case OPS.setFillColorN:
  10132. cs = stateManager.state.fillColorSpace;
  10133. if (cs.name === 'Pattern') {
  10134. return self.handleColorN(operatorList, OPS.setFillColorN,
  10135. args, cs, patterns, resources, xref).then(function() {
  10136. next(resolve, reject);
  10137. }, reject);
  10138. }
  10139. args = cs.getRgb(args, 0);
  10140. fn = OPS.setFillRGBColor;
  10141. break;
  10142. case OPS.setStrokeColorN:
  10143. cs = stateManager.state.strokeColorSpace;
  10144. if (cs.name === 'Pattern') {
  10145. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10146. args, cs, patterns, resources, xref).then(function() {
  10147. next(resolve, reject);
  10148. }, reject);
  10149. }
  10150. args = cs.getRgb(args, 0);
  10151. fn = OPS.setStrokeRGBColor;
  10152. break;
  10153. case OPS.shadingFill:
  10154. var shadingRes = resources.get('Shading');
  10155. if (!shadingRes) {
  10156. error('No shading resource found');
  10157. }
  10158. var shading = shadingRes.get(args[0].name);
  10159. if (!shading) {
  10160. error('No shading object found');
  10161. }
  10162. var shadingFill = Pattern.parseShading(shading, null, xref,
  10163. resources);
  10164. var patternIR = shadingFill.getIR();
  10165. args = [patternIR];
  10166. fn = OPS.shadingFill;
  10167. break;
  10168. case OPS.setGState:
  10169. var dictName = args[0];
  10170. var extGState = resources.get('ExtGState');
  10171. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10172. break;
  10173. }
  10174. var gState = extGState.get(dictName.name);
  10175. return self.setGState(resources, gState, operatorList, xref,
  10176. stateManager).then(function() {
  10177. next(resolve, reject);
  10178. }, reject);
  10179. case OPS.moveTo:
  10180. case OPS.lineTo:
  10181. case OPS.curveTo:
  10182. case OPS.curveTo2:
  10183. case OPS.curveTo3:
  10184. case OPS.closePath:
  10185. self.buildPath(operatorList, fn, args);
  10186. continue;
  10187. case OPS.rectangle:
  10188. self.buildPath(operatorList, fn, args);
  10189. continue;
  10190. }
  10191. operatorList.addOp(fn, args);
  10192. }
  10193. if (stop) {
  10194. deferred.then(function () {
  10195. next(resolve, reject);
  10196. });
  10197. return;
  10198. }
  10199. // Some PDFs don't close all restores inside object/form.
  10200. // Closing those for them.
  10201. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10202. operatorList.addOp(OPS.restore, []);
  10203. }
  10204. resolve();
  10205. });
  10206. },
  10207. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10208. stateManager) {
  10209. stateManager = (stateManager || new StateManager(new TextState()));
  10210. var textContent = {
  10211. items: [],
  10212. styles: Object.create(null)
  10213. };
  10214. var bidiTexts = textContent.items;
  10215. var SPACE_FACTOR = 0.35;
  10216. var MULTI_SPACE_FACTOR = 1.5;
  10217. var self = this;
  10218. var xref = this.xref;
  10219. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10220. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10221. var xobjs = null;
  10222. var xobjsCache = {};
  10223. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10224. var textState;
  10225. function newTextChunk() {
  10226. var font = textState.font;
  10227. if (!(font.loadedName in textContent.styles)) {
  10228. textContent.styles[font.loadedName] = {
  10229. fontFamily: font.fallbackName,
  10230. ascent: font.ascent,
  10231. descent: font.descent,
  10232. vertical: font.vertical
  10233. };
  10234. }
  10235. return {
  10236. // |str| is initially an array which we push individual chars to, and
  10237. // then runBidi() overwrites it with the final string.
  10238. str: [],
  10239. dir: null,
  10240. width: 0,
  10241. height: 0,
  10242. transform: null,
  10243. fontName: font.loadedName
  10244. };
  10245. }
  10246. function runBidi(textChunk) {
  10247. var str = textChunk.str.join('');
  10248. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10249. textChunk.str = bidiResult.str;
  10250. textChunk.dir = bidiResult.dir;
  10251. return textChunk;
  10252. }
  10253. function handleSetFont(fontName, fontRef) {
  10254. return self.loadFont(fontName, fontRef, xref, resources).
  10255. then(function (translated) {
  10256. textState.font = translated.font;
  10257. textState.fontMatrix = translated.font.fontMatrix ||
  10258. FONT_IDENTITY_MATRIX;
  10259. });
  10260. }
  10261. function buildTextGeometry(chars, textChunk) {
  10262. var font = textState.font;
  10263. textChunk = textChunk || newTextChunk();
  10264. if (!textChunk.transform) {
  10265. // 9.4.4 Text Space Details
  10266. var tsm = [textState.fontSize * textState.textHScale, 0,
  10267. 0, textState.fontSize,
  10268. 0, textState.textRise];
  10269. var trm = textChunk.transform = Util.transform(textState.ctm,
  10270. Util.transform(textState.textMatrix, tsm));
  10271. if (!font.vertical) {
  10272. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10273. } else {
  10274. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10275. }
  10276. }
  10277. var width = 0;
  10278. var height = 0;
  10279. var glyphs = font.charsToGlyphs(chars);
  10280. var defaultVMetrics = font.defaultVMetrics;
  10281. for (var i = 0; i < glyphs.length; i++) {
  10282. var glyph = glyphs[i];
  10283. if (!glyph) { // Previous glyph was a space.
  10284. width += textState.wordSpacing * textState.textHScale;
  10285. continue;
  10286. }
  10287. var vMetricX = null;
  10288. var vMetricY = null;
  10289. var glyphWidth = null;
  10290. if (font.vertical) {
  10291. if (glyph.vmetric) {
  10292. glyphWidth = glyph.vmetric[0];
  10293. vMetricX = glyph.vmetric[1];
  10294. vMetricY = glyph.vmetric[2];
  10295. } else {
  10296. glyphWidth = glyph.width;
  10297. vMetricX = glyph.width * 0.5;
  10298. vMetricY = defaultVMetrics[2];
  10299. }
  10300. } else {
  10301. glyphWidth = glyph.width;
  10302. }
  10303. var glyphUnicode = glyph.unicode;
  10304. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10305. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10306. }
  10307. glyphUnicode = reverseIfRtl(glyphUnicode);
  10308. // The following will calculate the x and y of the individual glyphs.
  10309. // if (font.vertical) {
  10310. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10311. // textState.fontMatrix[0];
  10312. // tsm[5] -= vMetricY * textState.fontSize *
  10313. // textState.fontMatrix[0];
  10314. // }
  10315. // var trm = Util.transform(textState.textMatrix, tsm);
  10316. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10317. // var x = pt[0];
  10318. // var y = pt[1];
  10319. var tx = 0;
  10320. var ty = 0;
  10321. if (!font.vertical) {
  10322. var w0 = glyphWidth * textState.fontMatrix[0];
  10323. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10324. textState.textHScale;
  10325. width += tx;
  10326. } else {
  10327. var w1 = glyphWidth * textState.fontMatrix[0];
  10328. ty = w1 * textState.fontSize + textState.charSpacing;
  10329. height += ty;
  10330. }
  10331. textState.translateTextMatrix(tx, ty);
  10332. textChunk.str.push(glyphUnicode);
  10333. }
  10334. var a = textState.textLineMatrix[0];
  10335. var b = textState.textLineMatrix[1];
  10336. var scaleLineX = Math.sqrt(a * a + b * b);
  10337. a = textState.ctm[0];
  10338. b = textState.ctm[1];
  10339. var scaleCtmX = Math.sqrt(a * a + b * b);
  10340. if (!font.vertical) {
  10341. textChunk.width += width * scaleCtmX * scaleLineX;
  10342. } else {
  10343. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10344. }
  10345. return textChunk;
  10346. }
  10347. var timeSlotManager = new TimeSlotManager();
  10348. return new Promise(function next(resolve, reject) {
  10349. timeSlotManager.reset();
  10350. var stop, operation = {}, args = [];
  10351. while (!(stop = timeSlotManager.check())) {
  10352. // The arguments parsed by read() are not used beyond this loop, so
  10353. // we can reuse the same array on every iteration, thus avoiding
  10354. // unnecessary allocations.
  10355. args.length = 0;
  10356. operation.args = args;
  10357. if (!(preprocessor.read(operation))) {
  10358. break;
  10359. }
  10360. textState = stateManager.state;
  10361. var fn = operation.fn;
  10362. args = operation.args;
  10363. switch (fn | 0) {
  10364. case OPS.setFont:
  10365. textState.fontSize = args[1];
  10366. return handleSetFont(args[0].name).then(function() {
  10367. next(resolve, reject);
  10368. }, reject);
  10369. case OPS.setTextRise:
  10370. textState.textRise = args[0];
  10371. break;
  10372. case OPS.setHScale:
  10373. textState.textHScale = args[0] / 100;
  10374. break;
  10375. case OPS.setLeading:
  10376. textState.leading = args[0];
  10377. break;
  10378. case OPS.moveText:
  10379. textState.translateTextLineMatrix(args[0], args[1]);
  10380. textState.textMatrix = textState.textLineMatrix.slice();
  10381. break;
  10382. case OPS.setLeadingMoveText:
  10383. textState.leading = -args[1];
  10384. textState.translateTextLineMatrix(args[0], args[1]);
  10385. textState.textMatrix = textState.textLineMatrix.slice();
  10386. break;
  10387. case OPS.nextLine:
  10388. textState.carriageReturn();
  10389. break;
  10390. case OPS.setTextMatrix:
  10391. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10392. args[4], args[5]);
  10393. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10394. args[4], args[5]);
  10395. break;
  10396. case OPS.setCharSpacing:
  10397. textState.charSpacing = args[0];
  10398. break;
  10399. case OPS.setWordSpacing:
  10400. textState.wordSpacing = args[0];
  10401. break;
  10402. case OPS.beginText:
  10403. textState.textMatrix = IDENTITY_MATRIX.slice();
  10404. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10405. break;
  10406. case OPS.showSpacedText:
  10407. var items = args[0];
  10408. var textChunk = newTextChunk();
  10409. var offset;
  10410. for (var j = 0, jj = items.length; j < jj; j++) {
  10411. if (typeof items[j] === 'string') {
  10412. buildTextGeometry(items[j], textChunk);
  10413. } else {
  10414. var val = items[j] / 1000;
  10415. if (!textState.font.vertical) {
  10416. offset = -val * textState.fontSize * textState.textHScale *
  10417. textState.textMatrix[0];
  10418. textState.translateTextMatrix(offset, 0);
  10419. textChunk.width += offset;
  10420. } else {
  10421. offset = -val * textState.fontSize *
  10422. textState.textMatrix[3];
  10423. textState.translateTextMatrix(0, offset);
  10424. textChunk.height += offset;
  10425. }
  10426. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10427. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10428. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10429. fakeSpaces = Math.round(fakeSpaces);
  10430. while (fakeSpaces--) {
  10431. textChunk.str.push(' ');
  10432. }
  10433. } else if (fakeSpaces > SPACE_FACTOR) {
  10434. textChunk.str.push(' ');
  10435. }
  10436. }
  10437. }
  10438. }
  10439. bidiTexts.push(runBidi(textChunk));
  10440. break;
  10441. case OPS.showText:
  10442. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10443. break;
  10444. case OPS.nextLineShowText:
  10445. textState.carriageReturn();
  10446. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10447. break;
  10448. case OPS.nextLineSetSpacingShowText:
  10449. textState.wordSpacing = args[0];
  10450. textState.charSpacing = args[1];
  10451. textState.carriageReturn();
  10452. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10453. break;
  10454. case OPS.paintXObject:
  10455. if (args[0].code) {
  10456. break;
  10457. }
  10458. if (!xobjs) {
  10459. xobjs = (resources.get('XObject') || Dict.empty);
  10460. }
  10461. var name = args[0].name;
  10462. if (xobjsCache.key === name) {
  10463. if (xobjsCache.texts) {
  10464. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10465. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10466. }
  10467. break;
  10468. }
  10469. var xobj = xobjs.get(name);
  10470. if (!xobj) {
  10471. break;
  10472. }
  10473. assert(isStream(xobj), 'XObject should be a stream');
  10474. var type = xobj.dict.get('Subtype');
  10475. assert(isName(type),
  10476. 'XObject should have a Name subtype');
  10477. if ('Form' !== type.name) {
  10478. xobjsCache.key = name;
  10479. xobjsCache.texts = null;
  10480. break;
  10481. }
  10482. stateManager.save();
  10483. var matrix = xobj.dict.get('Matrix');
  10484. if (isArray(matrix) && matrix.length === 6) {
  10485. stateManager.transform(matrix);
  10486. }
  10487. return self.getTextContent(xobj,
  10488. xobj.dict.get('Resources') || resources, stateManager).
  10489. then(function (formTextContent) {
  10490. Util.appendToArray(bidiTexts, formTextContent.items);
  10491. Util.extendObj(textContent.styles, formTextContent.styles);
  10492. stateManager.restore();
  10493. xobjsCache.key = name;
  10494. xobjsCache.texts = formTextContent;
  10495. next(resolve, reject);
  10496. }, reject);
  10497. case OPS.setGState:
  10498. var dictName = args[0];
  10499. var extGState = resources.get('ExtGState');
  10500. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10501. break;
  10502. }
  10503. var gsStateMap = extGState.get(dictName.name);
  10504. var gsStateFont = null;
  10505. for (var key in gsStateMap) {
  10506. if (key === 'Font') {
  10507. assert(!gsStateFont);
  10508. gsStateFont = gsStateMap[key];
  10509. }
  10510. }
  10511. if (gsStateFont) {
  10512. textState.fontSize = gsStateFont[1];
  10513. return handleSetFont(gsStateFont[0]).then(function() {
  10514. next(resolve, reject);
  10515. }, reject);
  10516. }
  10517. break;
  10518. } // switch
  10519. } // while
  10520. if (stop) {
  10521. deferred.then(function () {
  10522. next(resolve, reject);
  10523. });
  10524. return;
  10525. }
  10526. resolve(textContent);
  10527. });
  10528. },
  10529. extractDataStructures: function
  10530. partialEvaluatorExtractDataStructures(dict, baseDict,
  10531. xref, properties) {
  10532. // 9.10.2
  10533. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10534. if (toUnicode) {
  10535. properties.toUnicode = this.readToUnicode(toUnicode);
  10536. }
  10537. if (properties.composite) {
  10538. // CIDSystemInfo helps to match CID to glyphs
  10539. var cidSystemInfo = dict.get('CIDSystemInfo');
  10540. if (isDict(cidSystemInfo)) {
  10541. properties.cidSystemInfo = {
  10542. registry: cidSystemInfo.get('Registry'),
  10543. ordering: cidSystemInfo.get('Ordering'),
  10544. supplement: cidSystemInfo.get('Supplement')
  10545. };
  10546. }
  10547. var cidToGidMap = dict.get('CIDToGIDMap');
  10548. if (isStream(cidToGidMap)) {
  10549. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10550. }
  10551. }
  10552. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10553. // and depends on the font type. The base encoding and differences are
  10554. // read here, but the encoding that is actually used is chosen during
  10555. // glyph mapping in the font.
  10556. // TODO: Loading the built in encoding in the font would allow the
  10557. // differences to be merged in here not require us to hold on to it.
  10558. var differences = [];
  10559. var baseEncodingName = null;
  10560. var encoding;
  10561. if (dict.has('Encoding')) {
  10562. encoding = dict.get('Encoding');
  10563. if (isDict(encoding)) {
  10564. baseEncodingName = encoding.get('BaseEncoding');
  10565. baseEncodingName = (isName(baseEncodingName) ?
  10566. baseEncodingName.name : null);
  10567. // Load the differences between the base and original
  10568. if (encoding.has('Differences')) {
  10569. var diffEncoding = encoding.get('Differences');
  10570. var index = 0;
  10571. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10572. var data = diffEncoding[j];
  10573. if (isNum(data)) {
  10574. index = data;
  10575. } else {
  10576. differences[index++] = data.name;
  10577. }
  10578. }
  10579. }
  10580. } else if (isName(encoding)) {
  10581. baseEncodingName = encoding.name;
  10582. } else {
  10583. error('Encoding is not a Name nor a Dict');
  10584. }
  10585. // According to table 114 if the encoding is a named encoding it must be
  10586. // one of these predefined encodings.
  10587. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10588. baseEncodingName !== 'MacExpertEncoding' &&
  10589. baseEncodingName !== 'WinAnsiEncoding')) {
  10590. baseEncodingName = null;
  10591. }
  10592. }
  10593. if (baseEncodingName) {
  10594. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10595. } else {
  10596. encoding = (properties.type === 'TrueType' ?
  10597. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10598. // The Symbolic attribute can be misused for regular fonts
  10599. // Heuristic: we have to check if the font is a standard one also
  10600. if (!!(properties.flags & FontFlags.Symbolic)) {
  10601. encoding = Encodings.MacRomanEncoding;
  10602. if (!properties.file) {
  10603. if (/Symbol/i.test(properties.name)) {
  10604. encoding = Encodings.SymbolSetEncoding;
  10605. } else if (/Dingbats/i.test(properties.name)) {
  10606. encoding = Encodings.ZapfDingbatsEncoding;
  10607. }
  10608. }
  10609. }
  10610. properties.defaultEncoding = encoding;
  10611. }
  10612. properties.differences = differences;
  10613. properties.baseEncodingName = baseEncodingName;
  10614. properties.dict = dict;
  10615. },
  10616. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10617. var cmap, cmapObj = toUnicode;
  10618. if (isName(cmapObj)) {
  10619. cmap = CMapFactory.create(cmapObj,
  10620. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10621. return new ToUnicodeMap(cmap);
  10622. } else if (isStream(cmapObj)) {
  10623. cmap = CMapFactory.create(cmapObj,
  10624. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10625. // Convert UTF-16BE
  10626. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10627. // to iterate over all keys.
  10628. cmap.forEach(function(token, i) {
  10629. var str = [];
  10630. for (var k = 0; k < token.length; k += 2) {
  10631. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10632. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10633. str.push(w1);
  10634. continue;
  10635. }
  10636. k += 2;
  10637. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10638. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10639. }
  10640. cmap[i] = String.fromCharCode.apply(String, str);
  10641. });
  10642. return new ToUnicodeMap(cmap);
  10643. }
  10644. return null;
  10645. },
  10646. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10647. // Extract the encoding from the CIDToGIDMap
  10648. var glyphsData = cidToGidStream.getBytes();
  10649. // Set encoding 0 to later verify the font has an encoding
  10650. var result = [];
  10651. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10652. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10653. if (glyphID === 0) {
  10654. continue;
  10655. }
  10656. var code = j >> 1;
  10657. result[code] = glyphID;
  10658. }
  10659. return result;
  10660. },
  10661. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10662. descriptor,
  10663. properties) {
  10664. var glyphsWidths = [];
  10665. var defaultWidth = 0;
  10666. var glyphsVMetrics = [];
  10667. var defaultVMetrics;
  10668. var i, ii, j, jj, start, code, widths;
  10669. if (properties.composite) {
  10670. defaultWidth = dict.get('DW') || 1000;
  10671. widths = dict.get('W');
  10672. if (widths) {
  10673. for (i = 0, ii = widths.length; i < ii; i++) {
  10674. start = widths[i++];
  10675. code = xref.fetchIfRef(widths[i]);
  10676. if (isArray(code)) {
  10677. for (j = 0, jj = code.length; j < jj; j++) {
  10678. glyphsWidths[start++] = code[j];
  10679. }
  10680. } else {
  10681. var width = widths[++i];
  10682. for (j = start; j <= code; j++) {
  10683. glyphsWidths[j] = width;
  10684. }
  10685. }
  10686. }
  10687. }
  10688. if (properties.vertical) {
  10689. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10690. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10691. vmetrics = dict.get('W2');
  10692. if (vmetrics) {
  10693. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10694. start = vmetrics[i++];
  10695. code = xref.fetchIfRef(vmetrics[i]);
  10696. if (isArray(code)) {
  10697. for (j = 0, jj = code.length; j < jj; j++) {
  10698. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10699. }
  10700. } else {
  10701. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10702. for (j = start; j <= code; j++) {
  10703. glyphsVMetrics[j] = vmetric;
  10704. }
  10705. }
  10706. }
  10707. }
  10708. }
  10709. } else {
  10710. var firstChar = properties.firstChar;
  10711. widths = dict.get('Widths');
  10712. if (widths) {
  10713. j = firstChar;
  10714. for (i = 0, ii = widths.length; i < ii; i++) {
  10715. glyphsWidths[j++] = widths[i];
  10716. }
  10717. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10718. } else {
  10719. // Trying get the BaseFont metrics (see comment above).
  10720. var baseFontName = dict.get('BaseFont');
  10721. if (isName(baseFontName)) {
  10722. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10723. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10724. properties);
  10725. defaultWidth = metrics.defaultWidth;
  10726. }
  10727. }
  10728. }
  10729. // Heuristic: detection of monospace font by checking all non-zero widths
  10730. var isMonospace = true;
  10731. var firstWidth = defaultWidth;
  10732. for (var glyph in glyphsWidths) {
  10733. var glyphWidth = glyphsWidths[glyph];
  10734. if (!glyphWidth) {
  10735. continue;
  10736. }
  10737. if (!firstWidth) {
  10738. firstWidth = glyphWidth;
  10739. continue;
  10740. }
  10741. if (firstWidth !== glyphWidth) {
  10742. isMonospace = false;
  10743. break;
  10744. }
  10745. }
  10746. if (isMonospace) {
  10747. properties.flags |= FontFlags.FixedPitch;
  10748. }
  10749. properties.defaultWidth = defaultWidth;
  10750. properties.widths = glyphsWidths;
  10751. properties.defaultVMetrics = defaultVMetrics;
  10752. properties.vmetrics = glyphsVMetrics;
  10753. },
  10754. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10755. // Simulating descriptor flags attribute
  10756. var fontNameWoStyle = baseFontName.split('-')[0];
  10757. return (fontNameWoStyle in serifFonts) ||
  10758. (fontNameWoStyle.search(/serif/gi) !== -1);
  10759. },
  10760. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10761. var defaultWidth = 0;
  10762. var widths = [];
  10763. var monospace = false;
  10764. var lookupName = (stdFontMap[name] || name);
  10765. if (!(lookupName in Metrics)) {
  10766. // Use default fonts for looking up font metrics if the passed
  10767. // font is not a base font
  10768. if (this.isSerifFont(name)) {
  10769. lookupName = 'Times-Roman';
  10770. } else {
  10771. lookupName = 'Helvetica';
  10772. }
  10773. }
  10774. var glyphWidths = Metrics[lookupName];
  10775. if (isNum(glyphWidths)) {
  10776. defaultWidth = glyphWidths;
  10777. monospace = true;
  10778. } else {
  10779. widths = glyphWidths;
  10780. }
  10781. return {
  10782. defaultWidth: defaultWidth,
  10783. monospace: monospace,
  10784. widths: widths
  10785. };
  10786. },
  10787. buildCharCodeToWidth:
  10788. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10789. properties) {
  10790. var widths = Object.create(null);
  10791. var differences = properties.differences;
  10792. var encoding = properties.defaultEncoding;
  10793. for (var charCode = 0; charCode < 256; charCode++) {
  10794. if (charCode in differences &&
  10795. widthsByGlyphName[differences[charCode]]) {
  10796. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10797. continue;
  10798. }
  10799. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10800. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10801. continue;
  10802. }
  10803. }
  10804. return widths;
  10805. },
  10806. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10807. var baseDict = dict;
  10808. var type = dict.get('Subtype');
  10809. assert(isName(type), 'invalid font Subtype');
  10810. var composite = false;
  10811. var uint8array;
  10812. if (type.name === 'Type0') {
  10813. // If font is a composite
  10814. // - get the descendant font
  10815. // - set the type according to the descendant font
  10816. // - get the FontDescriptor from the descendant font
  10817. var df = dict.get('DescendantFonts');
  10818. if (!df) {
  10819. error('Descendant fonts are not specified');
  10820. }
  10821. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10822. type = dict.get('Subtype');
  10823. assert(isName(type), 'invalid font Subtype');
  10824. composite = true;
  10825. }
  10826. var descriptor = dict.get('FontDescriptor');
  10827. if (descriptor) {
  10828. var hash = new MurmurHash3_64();
  10829. var encoding = baseDict.getRaw('Encoding');
  10830. if (isName(encoding)) {
  10831. hash.update(encoding.name);
  10832. } else if (isRef(encoding)) {
  10833. hash.update(encoding.num + '_' + encoding.gen);
  10834. }
  10835. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10836. if (isStream(toUnicode)) {
  10837. var stream = toUnicode.str || toUnicode;
  10838. uint8array = stream.buffer ?
  10839. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10840. new Uint8Array(stream.bytes.buffer,
  10841. stream.start, stream.end - stream.start);
  10842. hash.update(uint8array);
  10843. } else if (isName(toUnicode)) {
  10844. hash.update(toUnicode.name);
  10845. }
  10846. var widths = dict.get('Widths') || baseDict.get('Widths');
  10847. if (widths) {
  10848. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10849. hash.update(uint8array);
  10850. }
  10851. }
  10852. return {
  10853. descriptor: descriptor,
  10854. dict: dict,
  10855. baseDict: baseDict,
  10856. composite: composite,
  10857. type: type.name,
  10858. hash: hash ? hash.hexdigest() : ''
  10859. };
  10860. },
  10861. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10862. xref) {
  10863. var baseDict = preEvaluatedFont.baseDict;
  10864. var dict = preEvaluatedFont.dict;
  10865. var composite = preEvaluatedFont.composite;
  10866. var descriptor = preEvaluatedFont.descriptor;
  10867. var type = preEvaluatedFont.type;
  10868. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  10869. var properties;
  10870. if (!descriptor) {
  10871. if (type === 'Type3') {
  10872. // FontDescriptor is only required for Type3 fonts when the document
  10873. // is a tagged pdf. Create a barbebones one to get by.
  10874. descriptor = new Dict(null);
  10875. descriptor.set('FontName', Name.get(type));
  10876. } else {
  10877. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  10878. // FontDescriptor was not required.
  10879. // This case is here for compatibility.
  10880. var baseFontName = dict.get('BaseFont');
  10881. if (!isName(baseFontName)) {
  10882. error('Base font is not specified');
  10883. }
  10884. // Using base font name as a font name.
  10885. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  10886. var metrics = this.getBaseFontMetrics(baseFontName);
  10887. // Simulating descriptor flags attribute
  10888. var fontNameWoStyle = baseFontName.split('-')[0];
  10889. var flags =
  10890. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  10891. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  10892. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  10893. FontFlags.Nonsymbolic);
  10894. properties = {
  10895. type: type,
  10896. name: baseFontName,
  10897. widths: metrics.widths,
  10898. defaultWidth: metrics.defaultWidth,
  10899. flags: flags,
  10900. firstChar: 0,
  10901. lastChar: maxCharIndex
  10902. };
  10903. this.extractDataStructures(dict, dict, xref, properties);
  10904. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  10905. properties);
  10906. return new Font(baseFontName, null, properties);
  10907. }
  10908. }
  10909. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  10910. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  10911. // to ignore this rule when a variant of a standart font is used.
  10912. // TODO Fill the width array depending on which of the base font this is
  10913. // a variant.
  10914. var firstChar = (dict.get('FirstChar') || 0);
  10915. var lastChar = (dict.get('LastChar') || maxCharIndex);
  10916. var fontName = descriptor.get('FontName');
  10917. var baseFont = dict.get('BaseFont');
  10918. // Some bad PDFs have a string as the font name.
  10919. if (isString(fontName)) {
  10920. fontName = Name.get(fontName);
  10921. }
  10922. if (isString(baseFont)) {
  10923. baseFont = Name.get(baseFont);
  10924. }
  10925. if (type !== 'Type3') {
  10926. var fontNameStr = fontName && fontName.name;
  10927. var baseFontStr = baseFont && baseFont.name;
  10928. if (fontNameStr !== baseFontStr) {
  10929. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  10930. '" but should be the same as the Font\'s BaseFont "' +
  10931. baseFontStr + '"');
  10932. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  10933. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  10934. if (fontNameStr && baseFontStr &&
  10935. baseFontStr.indexOf(fontNameStr) === 0) {
  10936. fontName = baseFont;
  10937. }
  10938. }
  10939. }
  10940. fontName = (fontName || baseFont);
  10941. assert(isName(fontName), 'invalid font name');
  10942. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  10943. if (fontFile) {
  10944. if (fontFile.dict) {
  10945. var subtype = fontFile.dict.get('Subtype');
  10946. if (subtype) {
  10947. subtype = subtype.name;
  10948. }
  10949. var length1 = fontFile.dict.get('Length1');
  10950. var length2 = fontFile.dict.get('Length2');
  10951. }
  10952. }
  10953. properties = {
  10954. type: type,
  10955. name: fontName.name,
  10956. subtype: subtype,
  10957. file: fontFile,
  10958. length1: length1,
  10959. length2: length2,
  10960. loadedName: baseDict.loadedName,
  10961. composite: composite,
  10962. wideChars: composite,
  10963. fixedPitch: false,
  10964. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  10965. firstChar: firstChar || 0,
  10966. lastChar: (lastChar || maxCharIndex),
  10967. bbox: descriptor.get('FontBBox'),
  10968. ascent: descriptor.get('Ascent'),
  10969. descent: descriptor.get('Descent'),
  10970. xHeight: descriptor.get('XHeight'),
  10971. capHeight: descriptor.get('CapHeight'),
  10972. flags: descriptor.get('Flags'),
  10973. italicAngle: descriptor.get('ItalicAngle'),
  10974. coded: false
  10975. };
  10976. if (composite) {
  10977. var cidEncoding = baseDict.get('Encoding');
  10978. if (isName(cidEncoding)) {
  10979. properties.cidEncoding = cidEncoding.name;
  10980. }
  10981. properties.cMap = CMapFactory.create(cidEncoding,
  10982. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10983. properties.vertical = properties.cMap.vertical;
  10984. }
  10985. this.extractDataStructures(dict, baseDict, xref, properties);
  10986. this.extractWidths(dict, xref, descriptor, properties);
  10987. if (type === 'Type3') {
  10988. properties.isType3Font = true;
  10989. }
  10990. return new Font(fontName.name, fontFile, properties);
  10991. }
  10992. };
  10993. return PartialEvaluator;
  10994. })();
  10995. var TranslatedFont = (function TranslatedFontClosure() {
  10996. function TranslatedFont(loadedName, font, dict) {
  10997. this.loadedName = loadedName;
  10998. this.font = font;
  10999. this.dict = dict;
  11000. this.type3Loaded = null;
  11001. this.sent = false;
  11002. }
  11003. TranslatedFont.prototype = {
  11004. send: function (handler) {
  11005. if (this.sent) {
  11006. return;
  11007. }
  11008. var fontData = this.font.exportData();
  11009. handler.send('commonobj', [
  11010. this.loadedName,
  11011. 'Font',
  11012. fontData
  11013. ]);
  11014. this.sent = true;
  11015. },
  11016. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11017. assert(this.font.isType3Font);
  11018. if (this.type3Loaded) {
  11019. return this.type3Loaded;
  11020. }
  11021. var translatedFont = this.font;
  11022. var loadCharProcsPromise = Promise.resolve();
  11023. var charProcs = this.dict.get('CharProcs').getAll();
  11024. var fontResources = this.dict.get('Resources') || resources;
  11025. var charProcKeys = Object.keys(charProcs);
  11026. var charProcOperatorList = {};
  11027. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11028. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11029. var glyphStream = charProcs[key];
  11030. var operatorList = new OperatorList();
  11031. return evaluator.getOperatorList(glyphStream, fontResources,
  11032. operatorList).then(function () {
  11033. charProcOperatorList[key] = operatorList.getIR();
  11034. // Add the dependencies to the parent operator list so they are
  11035. // resolved before sub operator list is executed synchronously.
  11036. parentOperatorList.addDependencies(operatorList.dependencies);
  11037. }, function (reason) {
  11038. warn('Type3 font resource \"' + key + '\" is not available');
  11039. var operatorList = new OperatorList();
  11040. charProcOperatorList[key] = operatorList.getIR();
  11041. });
  11042. }.bind(this, charProcKeys[i]));
  11043. }
  11044. this.type3Loaded = loadCharProcsPromise.then(function () {
  11045. translatedFont.charProcOperatorList = charProcOperatorList;
  11046. });
  11047. return this.type3Loaded;
  11048. }
  11049. };
  11050. return TranslatedFont;
  11051. })();
  11052. var OperatorList = (function OperatorListClosure() {
  11053. var CHUNK_SIZE = 1000;
  11054. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11055. function getTransfers(queue) {
  11056. var transfers = [];
  11057. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11058. for (var i = 0, ii = queue.length; i < ii; i++) {
  11059. switch (fnArray[i]) {
  11060. case OPS.paintInlineImageXObject:
  11061. case OPS.paintInlineImageXObjectGroup:
  11062. case OPS.paintImageMaskXObject:
  11063. var arg = argsArray[i][0]; // first param in imgData
  11064. if (!arg.cached) {
  11065. transfers.push(arg.data.buffer);
  11066. }
  11067. break;
  11068. }
  11069. }
  11070. return transfers;
  11071. }
  11072. function OperatorList(intent, messageHandler, pageIndex) {
  11073. this.messageHandler = messageHandler;
  11074. this.fnArray = [];
  11075. this.argsArray = [];
  11076. this.dependencies = {};
  11077. this.pageIndex = pageIndex;
  11078. this.intent = intent;
  11079. }
  11080. OperatorList.prototype = {
  11081. get length() {
  11082. return this.argsArray.length;
  11083. },
  11084. addOp: function(fn, args) {
  11085. this.fnArray.push(fn);
  11086. this.argsArray.push(args);
  11087. if (this.messageHandler) {
  11088. if (this.fnArray.length >= CHUNK_SIZE) {
  11089. this.flush();
  11090. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11091. (fn === OPS.restore || fn === OPS.endText)) {
  11092. // heuristic to flush on boundary of restore or endText
  11093. this.flush();
  11094. }
  11095. }
  11096. },
  11097. addDependency: function(dependency) {
  11098. if (dependency in this.dependencies) {
  11099. return;
  11100. }
  11101. this.dependencies[dependency] = true;
  11102. this.addOp(OPS.dependency, [dependency]);
  11103. },
  11104. addDependencies: function(dependencies) {
  11105. for (var key in dependencies) {
  11106. this.addDependency(key);
  11107. }
  11108. },
  11109. addOpList: function(opList) {
  11110. Util.extendObj(this.dependencies, opList.dependencies);
  11111. for (var i = 0, ii = opList.length; i < ii; i++) {
  11112. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11113. }
  11114. },
  11115. getIR: function() {
  11116. return {
  11117. fnArray: this.fnArray,
  11118. argsArray: this.argsArray,
  11119. length: this.length
  11120. };
  11121. },
  11122. flush: function(lastChunk) {
  11123. if (this.intent !== 'oplist') {
  11124. new QueueOptimizer().optimize(this);
  11125. }
  11126. var transfers = getTransfers(this);
  11127. this.messageHandler.send('RenderPageChunk', {
  11128. operatorList: {
  11129. fnArray: this.fnArray,
  11130. argsArray: this.argsArray,
  11131. lastChunk: lastChunk,
  11132. length: this.length
  11133. },
  11134. pageIndex: this.pageIndex,
  11135. intent: this.intent
  11136. }, transfers);
  11137. this.dependencies = {};
  11138. this.fnArray.length = 0;
  11139. this.argsArray.length = 0;
  11140. }
  11141. };
  11142. return OperatorList;
  11143. })();
  11144. var StateManager = (function StateManagerClosure() {
  11145. function StateManager(initialState) {
  11146. this.state = initialState;
  11147. this.stateStack = [];
  11148. }
  11149. StateManager.prototype = {
  11150. save: function () {
  11151. var old = this.state;
  11152. this.stateStack.push(this.state);
  11153. this.state = old.clone();
  11154. },
  11155. restore: function () {
  11156. var prev = this.stateStack.pop();
  11157. if (prev) {
  11158. this.state = prev;
  11159. }
  11160. },
  11161. transform: function (args) {
  11162. this.state.ctm = Util.transform(this.state.ctm, args);
  11163. }
  11164. };
  11165. return StateManager;
  11166. })();
  11167. var TextState = (function TextStateClosure() {
  11168. function TextState() {
  11169. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11170. this.fontSize = 0;
  11171. this.font = null;
  11172. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11173. this.textMatrix = IDENTITY_MATRIX.slice();
  11174. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11175. this.charSpacing = 0;
  11176. this.wordSpacing = 0;
  11177. this.leading = 0;
  11178. this.textHScale = 1;
  11179. this.textRise = 0;
  11180. }
  11181. TextState.prototype = {
  11182. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11183. var m = this.textMatrix;
  11184. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11185. },
  11186. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11187. var m = this.textLineMatrix;
  11188. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11189. },
  11190. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11191. var m = this.textMatrix;
  11192. m[4] = m[0] * x + m[2] * y + m[4];
  11193. m[5] = m[1] * x + m[3] * y + m[5];
  11194. },
  11195. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11196. var m = this.textLineMatrix;
  11197. m[4] = m[0] * x + m[2] * y + m[4];
  11198. m[5] = m[1] * x + m[3] * y + m[5];
  11199. },
  11200. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11201. // 9.4.4 Text Space Details
  11202. var tsm = [this.fontSize * this.textHScale, 0,
  11203. 0, this.fontSize,
  11204. 0, this.textRise];
  11205. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11206. },
  11207. carriageReturn: function TextState_carriageReturn() {
  11208. this.translateTextLineMatrix(0, -this.leading);
  11209. this.textMatrix = this.textLineMatrix.slice();
  11210. },
  11211. clone: function TextState_clone() {
  11212. var clone = Object.create(this);
  11213. clone.textMatrix = this.textMatrix.slice();
  11214. clone.textLineMatrix = this.textLineMatrix.slice();
  11215. clone.fontMatrix = this.fontMatrix.slice();
  11216. return clone;
  11217. }
  11218. };
  11219. return TextState;
  11220. })();
  11221. var EvalState = (function EvalStateClosure() {
  11222. function EvalState() {
  11223. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11224. this.font = null;
  11225. this.textRenderingMode = TextRenderingMode.FILL;
  11226. this.fillColorSpace = ColorSpace.singletons.gray;
  11227. this.strokeColorSpace = ColorSpace.singletons.gray;
  11228. }
  11229. EvalState.prototype = {
  11230. clone: function CanvasExtraState_clone() {
  11231. return Object.create(this);
  11232. },
  11233. };
  11234. return EvalState;
  11235. })();
  11236. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11237. // Specifies properties for each command
  11238. //
  11239. // If variableArgs === true: [0, `numArgs`] expected
  11240. // If variableArgs === false: exactly `numArgs` expected
  11241. var OP_MAP = {
  11242. // Graphic state
  11243. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11244. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11245. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11246. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11247. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11248. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11249. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11250. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11251. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11252. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11253. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11254. // Path
  11255. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11256. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11257. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11258. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11259. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11260. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11261. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11262. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11263. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11264. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11265. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11266. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11267. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11268. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11269. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11270. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11271. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11272. // Clipping
  11273. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11274. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11275. // Text
  11276. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11277. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11278. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11279. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11280. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11281. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11282. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11283. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11284. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11285. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11286. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11287. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11288. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11289. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11290. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11291. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11292. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11293. variableArgs: false },
  11294. // Type3 fonts
  11295. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11296. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11297. // Color
  11298. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11299. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11300. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11301. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11302. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11303. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11304. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11305. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11306. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11307. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11308. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11309. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11310. // Shading
  11311. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11312. // Images
  11313. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11314. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11315. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11316. // XObjects
  11317. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11318. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11319. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11320. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11321. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11322. variableArgs: false },
  11323. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11324. // Compatibility
  11325. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11326. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11327. // (reserved partial commands for the lexer)
  11328. BM: null,
  11329. BD: null,
  11330. 'true': null,
  11331. fa: null,
  11332. fal: null,
  11333. fals: null,
  11334. 'false': null,
  11335. nu: null,
  11336. nul: null,
  11337. 'null': null
  11338. };
  11339. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11340. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11341. // dictionary
  11342. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11343. this.stateManager = stateManager;
  11344. this.nonProcessedArgs = [];
  11345. }
  11346. EvaluatorPreprocessor.prototype = {
  11347. get savedStatesDepth() {
  11348. return this.stateManager.stateStack.length;
  11349. },
  11350. // |operation| is an object with two fields:
  11351. //
  11352. // - |fn| is an out param.
  11353. //
  11354. // - |args| is an inout param. On entry, it should have one of two values.
  11355. //
  11356. // - An empty array. This indicates that the caller is providing the
  11357. // array in which the args will be stored in. The caller should use
  11358. // this value if it can reuse a single array for each call to read().
  11359. //
  11360. // - |null|. This indicates that the caller needs this function to create
  11361. // the array in which any args are stored in. If there are zero args,
  11362. // this function will leave |operation.args| as |null| (thus avoiding
  11363. // allocations that would occur if we used an empty array to represent
  11364. // zero arguments). Otherwise, it will replace |null| with a new array
  11365. // containing the arguments. The caller should use this value if it
  11366. // cannot reuse an array for each call to read().
  11367. //
  11368. // These two modes are present because this function is very hot and so
  11369. // avoiding allocations where possible is worthwhile.
  11370. //
  11371. read: function EvaluatorPreprocessor_read(operation) {
  11372. var args = operation.args;
  11373. while (true) {
  11374. var obj = this.parser.getObj();
  11375. if (isCmd(obj)) {
  11376. var cmd = obj.cmd;
  11377. // Check that the command is valid
  11378. var opSpec = OP_MAP[cmd];
  11379. if (!opSpec) {
  11380. warn('Unknown command "' + cmd + '"');
  11381. continue;
  11382. }
  11383. var fn = opSpec.id;
  11384. var numArgs = opSpec.numArgs;
  11385. var argsLength = args !== null ? args.length : 0;
  11386. if (!opSpec.variableArgs) {
  11387. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11388. if (argsLength !== numArgs) {
  11389. var nonProcessedArgs = this.nonProcessedArgs;
  11390. while (argsLength > numArgs) {
  11391. nonProcessedArgs.push(args.shift());
  11392. argsLength--;
  11393. }
  11394. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11395. if (!args) {
  11396. args = [];
  11397. }
  11398. args.unshift(nonProcessedArgs.pop());
  11399. argsLength++;
  11400. }
  11401. }
  11402. if (argsLength < numArgs) {
  11403. // If we receive too few args, it's not possible to possible
  11404. // to execute the command, so skip the command
  11405. info('Command ' + fn + ': because expected ' +
  11406. numArgs + ' args, but received ' + argsLength +
  11407. ' args; skipping');
  11408. args = null;
  11409. continue;
  11410. }
  11411. } else if (argsLength > numArgs) {
  11412. info('Command ' + fn + ': expected [0,' + numArgs +
  11413. '] args, but received ' + argsLength + ' args');
  11414. }
  11415. // TODO figure out how to type-check vararg functions
  11416. this.preprocessCommand(fn, args);
  11417. operation.fn = fn;
  11418. operation.args = args;
  11419. return true;
  11420. } else {
  11421. if (isEOF(obj)) {
  11422. return false; // no more commands
  11423. }
  11424. // argument
  11425. if (obj !== null) {
  11426. if (!args) {
  11427. args = [];
  11428. }
  11429. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11430. assert(args.length <= 33, 'Too many arguments');
  11431. }
  11432. }
  11433. }
  11434. },
  11435. preprocessCommand:
  11436. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11437. switch (fn | 0) {
  11438. case OPS.save:
  11439. this.stateManager.save();
  11440. break;
  11441. case OPS.restore:
  11442. this.stateManager.restore();
  11443. break;
  11444. case OPS.transform:
  11445. this.stateManager.transform(args);
  11446. break;
  11447. }
  11448. }
  11449. };
  11450. return EvaluatorPreprocessor;
  11451. })();
  11452. var QueueOptimizer = (function QueueOptimizerClosure() {
  11453. function addState(parentState, pattern, fn) {
  11454. var state = parentState;
  11455. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11456. var item = pattern[i];
  11457. state = (state[item] || (state[item] = []));
  11458. }
  11459. state[pattern[pattern.length - 1]] = fn;
  11460. }
  11461. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11462. argsArray) {
  11463. // Handles special case of mainly LaTeX documents which use image masks to
  11464. // draw lines with the current fill style.
  11465. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11466. // have been found at iFirstSave.
  11467. var iFirstPIMXO = iFirstSave + 2;
  11468. for (var i = 0; i < count; i++) {
  11469. var arg = argsArray[iFirstPIMXO + 4 * i];
  11470. var imageMask = arg.length === 1 && arg[0];
  11471. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11472. (!imageMask.data.length ||
  11473. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11474. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11475. continue;
  11476. }
  11477. break;
  11478. }
  11479. return count - i;
  11480. }
  11481. var InitialState = [];
  11482. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11483. // sequences with one |paintInlineImageXObjectGroup| operation.
  11484. addState(InitialState,
  11485. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11486. function foundInlineImageGroup(context) {
  11487. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11488. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11489. var MAX_WIDTH = 1000;
  11490. var IMAGE_PADDING = 1;
  11491. var fnArray = context.fnArray, argsArray = context.argsArray;
  11492. var curr = context.iCurr;
  11493. var iFirstSave = curr - 3;
  11494. var iFirstTransform = curr - 2;
  11495. var iFirstPIIXO = curr - 1;
  11496. // Look for the quartets.
  11497. var i = iFirstSave + 4;
  11498. var ii = fnArray.length;
  11499. while (i + 3 < ii) {
  11500. if (fnArray[i] !== OPS.save ||
  11501. fnArray[i + 1] !== OPS.transform ||
  11502. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11503. fnArray[i + 3] !== OPS.restore) {
  11504. break; // ops don't match
  11505. }
  11506. i += 4;
  11507. }
  11508. // At this point, i is the index of the first op past the last valid
  11509. // quartet.
  11510. var count = Math.min((i - iFirstSave) / 4,
  11511. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11512. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11513. return i;
  11514. }
  11515. // assuming that heights of those image is too small (~1 pixel)
  11516. // packing as much as possible by lines
  11517. var maxX = 0;
  11518. var map = [], maxLineHeight = 0;
  11519. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11520. var q;
  11521. for (q = 0; q < count; q++) {
  11522. var transform = argsArray[iFirstTransform + (q << 2)];
  11523. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11524. if (currentX + img.width > MAX_WIDTH) {
  11525. // starting new line
  11526. maxX = Math.max(maxX, currentX);
  11527. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11528. currentX = 0;
  11529. maxLineHeight = 0;
  11530. }
  11531. map.push({
  11532. transform: transform,
  11533. x: currentX, y: currentY,
  11534. w: img.width, h: img.height
  11535. });
  11536. currentX += img.width + 2 * IMAGE_PADDING;
  11537. maxLineHeight = Math.max(maxLineHeight, img.height);
  11538. }
  11539. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11540. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11541. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11542. var imgRowSize = imgWidth << 2;
  11543. for (q = 0; q < count; q++) {
  11544. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11545. // Copy image by lines and extends pixels into padding.
  11546. var rowSize = map[q].w << 2;
  11547. var dataOffset = 0;
  11548. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11549. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11550. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11551. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11552. dataOffset += rowSize;
  11553. offset += imgRowSize;
  11554. }
  11555. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11556. while (offset >= 0) {
  11557. data[offset - 4] = data[offset];
  11558. data[offset - 3] = data[offset + 1];
  11559. data[offset - 2] = data[offset + 2];
  11560. data[offset - 1] = data[offset + 3];
  11561. data[offset + rowSize] = data[offset + rowSize - 4];
  11562. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11563. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11564. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11565. offset -= imgRowSize;
  11566. }
  11567. }
  11568. // Replace queue items.
  11569. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11570. argsArray.splice(iFirstSave, count * 4,
  11571. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11572. data: imgData }, map]);
  11573. return iFirstSave + 1;
  11574. });
  11575. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11576. // sequences with one |paintImageMaskXObjectGroup| or one
  11577. // |paintImageMaskXObjectRepeat| operation.
  11578. addState(InitialState,
  11579. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11580. function foundImageMaskGroup(context) {
  11581. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11582. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11583. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11584. var fnArray = context.fnArray, argsArray = context.argsArray;
  11585. var curr = context.iCurr;
  11586. var iFirstSave = curr - 3;
  11587. var iFirstTransform = curr - 2;
  11588. var iFirstPIMXO = curr - 1;
  11589. // Look for the quartets.
  11590. var i = iFirstSave + 4;
  11591. var ii = fnArray.length;
  11592. while (i + 3 < ii) {
  11593. if (fnArray[i] !== OPS.save ||
  11594. fnArray[i + 1] !== OPS.transform ||
  11595. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11596. fnArray[i + 3] !== OPS.restore) {
  11597. break; // ops don't match
  11598. }
  11599. i += 4;
  11600. }
  11601. // At this point, i is the index of the first op past the last valid
  11602. // quartet.
  11603. var count = (i - iFirstSave) / 4;
  11604. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11605. argsArray);
  11606. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11607. return i;
  11608. }
  11609. var q;
  11610. var isSameImage = false;
  11611. var iTransform, transformArgs;
  11612. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11613. if (argsArray[iFirstTransform][1] === 0 &&
  11614. argsArray[iFirstTransform][2] === 0) {
  11615. isSameImage = true;
  11616. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11617. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11618. iTransform = iFirstTransform + 4;
  11619. var iPIMXO = iFirstPIMXO + 4;
  11620. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11621. transformArgs = argsArray[iTransform];
  11622. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11623. transformArgs[0] !== firstTransformArg0 ||
  11624. transformArgs[1] !== 0 ||
  11625. transformArgs[2] !== 0 ||
  11626. transformArgs[3] !== firstTransformArg3) {
  11627. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11628. isSameImage = false;
  11629. } else {
  11630. count = q;
  11631. }
  11632. break; // different image or transform
  11633. }
  11634. }
  11635. }
  11636. if (isSameImage) {
  11637. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11638. var positions = new Float32Array(count * 2);
  11639. iTransform = iFirstTransform;
  11640. for (q = 0; q < count; q++, iTransform += 4) {
  11641. transformArgs = argsArray[iTransform];
  11642. positions[(q << 1)] = transformArgs[4];
  11643. positions[(q << 1) + 1] = transformArgs[5];
  11644. }
  11645. // Replace queue items.
  11646. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11647. argsArray.splice(iFirstSave, count * 4,
  11648. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11649. } else {
  11650. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11651. var images = [];
  11652. for (q = 0; q < count; q++) {
  11653. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11654. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11655. images.push({ data: maskParams.data, width: maskParams.width,
  11656. height: maskParams.height,
  11657. transform: transformArgs });
  11658. }
  11659. // Replace queue items.
  11660. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11661. argsArray.splice(iFirstSave, count * 4, [images]);
  11662. }
  11663. return iFirstSave + 1;
  11664. });
  11665. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11666. // with one paintImageXObjectRepeat operation, if the |transform| and
  11667. // |paintImageXObjectRepeat| ops are appropriate.
  11668. addState(InitialState,
  11669. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11670. function (context) {
  11671. var MIN_IMAGES_IN_BLOCK = 3;
  11672. var MAX_IMAGES_IN_BLOCK = 1000;
  11673. var fnArray = context.fnArray, argsArray = context.argsArray;
  11674. var curr = context.iCurr;
  11675. var iFirstSave = curr - 3;
  11676. var iFirstTransform = curr - 2;
  11677. var iFirstPIXO = curr - 1;
  11678. var iFirstRestore = curr;
  11679. if (argsArray[iFirstTransform][1] !== 0 ||
  11680. argsArray[iFirstTransform][2] !== 0) {
  11681. return iFirstRestore + 1; // transform has the wrong form
  11682. }
  11683. // Look for the quartets.
  11684. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11685. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11686. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11687. var i = iFirstSave + 4;
  11688. var ii = fnArray.length;
  11689. while (i + 3 < ii) {
  11690. if (fnArray[i] !== OPS.save ||
  11691. fnArray[i + 1] !== OPS.transform ||
  11692. fnArray[i + 2] !== OPS.paintImageXObject ||
  11693. fnArray[i + 3] !== OPS.restore) {
  11694. break; // ops don't match
  11695. }
  11696. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11697. argsArray[i + 1][1] !== 0 ||
  11698. argsArray[i + 1][2] !== 0 ||
  11699. argsArray[i + 1][3] !== firstTransformArg3) {
  11700. break; // transforms don't match
  11701. }
  11702. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11703. break; // images don't match
  11704. }
  11705. i += 4;
  11706. }
  11707. // At this point, i is the index of the first op past the last valid
  11708. // quartet.
  11709. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11710. if (count < MIN_IMAGES_IN_BLOCK) {
  11711. return i;
  11712. }
  11713. // Extract the (x,y) positions from all of the matching transforms.
  11714. var positions = new Float32Array(count * 2);
  11715. var iTransform = iFirstTransform;
  11716. for (var q = 0; q < count; q++, iTransform += 4) {
  11717. var transformArgs = argsArray[iTransform];
  11718. positions[(q << 1)] = transformArgs[4];
  11719. positions[(q << 1) + 1] = transformArgs[5];
  11720. }
  11721. // Replace queue items.
  11722. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11723. positions];
  11724. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11725. argsArray.splice(iFirstSave, count * 4, args);
  11726. return iFirstSave + 1;
  11727. });
  11728. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11729. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11730. // sequences, if the font for each one is the same.
  11731. addState(InitialState,
  11732. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11733. function (context) {
  11734. var MIN_CHARS_IN_BLOCK = 3;
  11735. var MAX_CHARS_IN_BLOCK = 1000;
  11736. var fnArray = context.fnArray, argsArray = context.argsArray;
  11737. var curr = context.iCurr;
  11738. var iFirstBeginText = curr - 4;
  11739. var iFirstSetFont = curr - 3;
  11740. var iFirstSetTextMatrix = curr - 2;
  11741. var iFirstShowText = curr - 1;
  11742. var iFirstEndText = curr;
  11743. // Look for the quintets.
  11744. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11745. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11746. var i = iFirstBeginText + 5;
  11747. var ii = fnArray.length;
  11748. while (i + 4 < ii) {
  11749. if (fnArray[i] !== OPS.beginText ||
  11750. fnArray[i + 1] !== OPS.setFont ||
  11751. fnArray[i + 2] !== OPS.setTextMatrix ||
  11752. fnArray[i + 3] !== OPS.showText ||
  11753. fnArray[i + 4] !== OPS.endText) {
  11754. break; // ops don't match
  11755. }
  11756. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11757. argsArray[i + 1][1] !== firstSetFontArg1) {
  11758. break; // fonts don't match
  11759. }
  11760. i += 5;
  11761. }
  11762. // At this point, i is the index of the first op past the last valid
  11763. // quintet.
  11764. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11765. if (count < MIN_CHARS_IN_BLOCK) {
  11766. return i;
  11767. }
  11768. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11769. // showText, endText), include that as well. (E.g. <something> might be
  11770. // |dependency|.)
  11771. var iFirst = iFirstBeginText;
  11772. if (iFirstBeginText >= 4 &&
  11773. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11774. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11775. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11776. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11777. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11778. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11779. count++;
  11780. iFirst -= 5;
  11781. }
  11782. // Remove (endText, beginText, setFont) trios.
  11783. var iEndText = iFirst + 4;
  11784. for (var q = 1; q < count; q++) {
  11785. fnArray.splice(iEndText, 3);
  11786. argsArray.splice(iEndText, 3);
  11787. iEndText += 2;
  11788. }
  11789. return iEndText + 1;
  11790. });
  11791. function QueueOptimizer() {}
  11792. QueueOptimizer.prototype = {
  11793. optimize: function QueueOptimizer_optimize(queue) {
  11794. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11795. var context = {
  11796. iCurr: 0,
  11797. fnArray: fnArray,
  11798. argsArray: argsArray
  11799. };
  11800. var state;
  11801. var i = 0, ii = fnArray.length;
  11802. while (i < ii) {
  11803. state = (state || InitialState)[fnArray[i]];
  11804. if (typeof state === 'function') { // we found some handler
  11805. context.iCurr = i;
  11806. // state() returns the index of the first non-matching op (if we
  11807. // didn't match) or the first op past the modified ops (if we did
  11808. // match and replace).
  11809. i = state(context);
  11810. state = undefined; // reset the state machine
  11811. ii = context.fnArray.length;
  11812. } else {
  11813. i++;
  11814. }
  11815. }
  11816. }
  11817. };
  11818. return QueueOptimizer;
  11819. })();
  11820. var BUILT_IN_CMAPS = [
  11821. // << Start unicode maps.
  11822. 'Adobe-GB1-UCS2',
  11823. 'Adobe-CNS1-UCS2',
  11824. 'Adobe-Japan1-UCS2',
  11825. 'Adobe-Korea1-UCS2',
  11826. // >> End unicode maps.
  11827. '78-EUC-H',
  11828. '78-EUC-V',
  11829. '78-H',
  11830. '78-RKSJ-H',
  11831. '78-RKSJ-V',
  11832. '78-V',
  11833. '78ms-RKSJ-H',
  11834. '78ms-RKSJ-V',
  11835. '83pv-RKSJ-H',
  11836. '90ms-RKSJ-H',
  11837. '90ms-RKSJ-V',
  11838. '90msp-RKSJ-H',
  11839. '90msp-RKSJ-V',
  11840. '90pv-RKSJ-H',
  11841. '90pv-RKSJ-V',
  11842. 'Add-H',
  11843. 'Add-RKSJ-H',
  11844. 'Add-RKSJ-V',
  11845. 'Add-V',
  11846. 'Adobe-CNS1-0',
  11847. 'Adobe-CNS1-1',
  11848. 'Adobe-CNS1-2',
  11849. 'Adobe-CNS1-3',
  11850. 'Adobe-CNS1-4',
  11851. 'Adobe-CNS1-5',
  11852. 'Adobe-CNS1-6',
  11853. 'Adobe-GB1-0',
  11854. 'Adobe-GB1-1',
  11855. 'Adobe-GB1-2',
  11856. 'Adobe-GB1-3',
  11857. 'Adobe-GB1-4',
  11858. 'Adobe-GB1-5',
  11859. 'Adobe-Japan1-0',
  11860. 'Adobe-Japan1-1',
  11861. 'Adobe-Japan1-2',
  11862. 'Adobe-Japan1-3',
  11863. 'Adobe-Japan1-4',
  11864. 'Adobe-Japan1-5',
  11865. 'Adobe-Japan1-6',
  11866. 'Adobe-Korea1-0',
  11867. 'Adobe-Korea1-1',
  11868. 'Adobe-Korea1-2',
  11869. 'B5-H',
  11870. 'B5-V',
  11871. 'B5pc-H',
  11872. 'B5pc-V',
  11873. 'CNS-EUC-H',
  11874. 'CNS-EUC-V',
  11875. 'CNS1-H',
  11876. 'CNS1-V',
  11877. 'CNS2-H',
  11878. 'CNS2-V',
  11879. 'ETHK-B5-H',
  11880. 'ETHK-B5-V',
  11881. 'ETen-B5-H',
  11882. 'ETen-B5-V',
  11883. 'ETenms-B5-H',
  11884. 'ETenms-B5-V',
  11885. 'EUC-H',
  11886. 'EUC-V',
  11887. 'Ext-H',
  11888. 'Ext-RKSJ-H',
  11889. 'Ext-RKSJ-V',
  11890. 'Ext-V',
  11891. 'GB-EUC-H',
  11892. 'GB-EUC-V',
  11893. 'GB-H',
  11894. 'GB-V',
  11895. 'GBK-EUC-H',
  11896. 'GBK-EUC-V',
  11897. 'GBK2K-H',
  11898. 'GBK2K-V',
  11899. 'GBKp-EUC-H',
  11900. 'GBKp-EUC-V',
  11901. 'GBT-EUC-H',
  11902. 'GBT-EUC-V',
  11903. 'GBT-H',
  11904. 'GBT-V',
  11905. 'GBTpc-EUC-H',
  11906. 'GBTpc-EUC-V',
  11907. 'GBpc-EUC-H',
  11908. 'GBpc-EUC-V',
  11909. 'H',
  11910. 'HKdla-B5-H',
  11911. 'HKdla-B5-V',
  11912. 'HKdlb-B5-H',
  11913. 'HKdlb-B5-V',
  11914. 'HKgccs-B5-H',
  11915. 'HKgccs-B5-V',
  11916. 'HKm314-B5-H',
  11917. 'HKm314-B5-V',
  11918. 'HKm471-B5-H',
  11919. 'HKm471-B5-V',
  11920. 'HKscs-B5-H',
  11921. 'HKscs-B5-V',
  11922. 'Hankaku',
  11923. 'Hiragana',
  11924. 'KSC-EUC-H',
  11925. 'KSC-EUC-V',
  11926. 'KSC-H',
  11927. 'KSC-Johab-H',
  11928. 'KSC-Johab-V',
  11929. 'KSC-V',
  11930. 'KSCms-UHC-H',
  11931. 'KSCms-UHC-HW-H',
  11932. 'KSCms-UHC-HW-V',
  11933. 'KSCms-UHC-V',
  11934. 'KSCpc-EUC-H',
  11935. 'KSCpc-EUC-V',
  11936. 'Katakana',
  11937. 'NWP-H',
  11938. 'NWP-V',
  11939. 'RKSJ-H',
  11940. 'RKSJ-V',
  11941. 'Roman',
  11942. 'UniCNS-UCS2-H',
  11943. 'UniCNS-UCS2-V',
  11944. 'UniCNS-UTF16-H',
  11945. 'UniCNS-UTF16-V',
  11946. 'UniCNS-UTF32-H',
  11947. 'UniCNS-UTF32-V',
  11948. 'UniCNS-UTF8-H',
  11949. 'UniCNS-UTF8-V',
  11950. 'UniGB-UCS2-H',
  11951. 'UniGB-UCS2-V',
  11952. 'UniGB-UTF16-H',
  11953. 'UniGB-UTF16-V',
  11954. 'UniGB-UTF32-H',
  11955. 'UniGB-UTF32-V',
  11956. 'UniGB-UTF8-H',
  11957. 'UniGB-UTF8-V',
  11958. 'UniJIS-UCS2-H',
  11959. 'UniJIS-UCS2-HW-H',
  11960. 'UniJIS-UCS2-HW-V',
  11961. 'UniJIS-UCS2-V',
  11962. 'UniJIS-UTF16-H',
  11963. 'UniJIS-UTF16-V',
  11964. 'UniJIS-UTF32-H',
  11965. 'UniJIS-UTF32-V',
  11966. 'UniJIS-UTF8-H',
  11967. 'UniJIS-UTF8-V',
  11968. 'UniJIS2004-UTF16-H',
  11969. 'UniJIS2004-UTF16-V',
  11970. 'UniJIS2004-UTF32-H',
  11971. 'UniJIS2004-UTF32-V',
  11972. 'UniJIS2004-UTF8-H',
  11973. 'UniJIS2004-UTF8-V',
  11974. 'UniJISPro-UCS2-HW-V',
  11975. 'UniJISPro-UCS2-V',
  11976. 'UniJISPro-UTF8-V',
  11977. 'UniJISX0213-UTF32-H',
  11978. 'UniJISX0213-UTF32-V',
  11979. 'UniJISX02132004-UTF32-H',
  11980. 'UniJISX02132004-UTF32-V',
  11981. 'UniKS-UCS2-H',
  11982. 'UniKS-UCS2-V',
  11983. 'UniKS-UTF16-H',
  11984. 'UniKS-UTF16-V',
  11985. 'UniKS-UTF32-H',
  11986. 'UniKS-UTF32-V',
  11987. 'UniKS-UTF8-H',
  11988. 'UniKS-UTF8-V',
  11989. 'V',
  11990. 'WP-Symbol'];
  11991. // CMap, not to be confused with TrueType's cmap.
  11992. var CMap = (function CMapClosure() {
  11993. function CMap(builtInCMap) {
  11994. // Codespace ranges are stored as follows:
  11995. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  11996. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  11997. this.codespaceRanges = [[], [], [], []];
  11998. this.numCodespaceRanges = 0;
  11999. // Map entries have one of two forms.
  12000. // - cid chars are 16-bit unsigned integers, stored as integers.
  12001. // - bf chars are variable-length byte sequences, stored as strings, with
  12002. // one byte per character.
  12003. this._map = [];
  12004. this.vertical = false;
  12005. this.useCMap = null;
  12006. this.builtInCMap = builtInCMap;
  12007. }
  12008. CMap.prototype = {
  12009. addCodespaceRange: function(n, low, high) {
  12010. this.codespaceRanges[n - 1].push(low, high);
  12011. this.numCodespaceRanges++;
  12012. },
  12013. mapCidRange: function(low, high, dstLow) {
  12014. while (low <= high) {
  12015. this._map[low++] = dstLow++;
  12016. }
  12017. },
  12018. mapBfRange: function(low, high, dstLow) {
  12019. var lastByte = dstLow.length - 1;
  12020. while (low <= high) {
  12021. this._map[low++] = dstLow;
  12022. // Only the last byte has to be incremented.
  12023. dstLow = dstLow.substr(0, lastByte) +
  12024. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12025. }
  12026. },
  12027. mapBfRangeToArray: function(low, high, array) {
  12028. var i = 0, ii = array.length;
  12029. while (low <= high && i < ii) {
  12030. this._map[low] = array[i++];
  12031. ++low;
  12032. }
  12033. },
  12034. // This is used for both bf and cid chars.
  12035. mapOne: function(src, dst) {
  12036. this._map[src] = dst;
  12037. },
  12038. lookup: function(code) {
  12039. return this._map[code];
  12040. },
  12041. contains: function(code) {
  12042. return this._map[code] !== undefined;
  12043. },
  12044. forEach: function(callback) {
  12045. // Most maps have fewer than 65536 entries, and for those we use normal
  12046. // array iteration. But really sparse tables are possible -- e.g. with
  12047. // indices in the *billions*. For such tables we use for..in, which isn't
  12048. // ideal because it stringifies the indices for all present elements, but
  12049. // it does avoid iterating over every undefined entry.
  12050. var map = this._map;
  12051. var length = map.length;
  12052. var i;
  12053. if (length <= 0x10000) {
  12054. for (i = 0; i < length; i++) {
  12055. if (map[i] !== undefined) {
  12056. callback(i, map[i]);
  12057. }
  12058. }
  12059. } else {
  12060. for (i in this._map) {
  12061. callback(i, map[i]);
  12062. }
  12063. }
  12064. },
  12065. charCodeOf: function(value) {
  12066. return this._map.indexOf(value);
  12067. },
  12068. getMap: function() {
  12069. return this._map;
  12070. },
  12071. readCharCode: function(str, offset, out) {
  12072. var c = 0;
  12073. var codespaceRanges = this.codespaceRanges;
  12074. var codespaceRangesLen = this.codespaceRanges.length;
  12075. // 9.7.6.2 CMap Mapping
  12076. // The code length is at most 4.
  12077. for (var n = 0; n < codespaceRangesLen; n++) {
  12078. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12079. // Check each codespace range to see if it falls within.
  12080. var codespaceRange = codespaceRanges[n];
  12081. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12082. var low = codespaceRange[k++];
  12083. var high = codespaceRange[k++];
  12084. if (c >= low && c <= high) {
  12085. out.charcode = c;
  12086. out.length = n + 1;
  12087. return;
  12088. }
  12089. }
  12090. }
  12091. out.charcode = 0;
  12092. out.length = 1;
  12093. }
  12094. };
  12095. return CMap;
  12096. })();
  12097. // A special case of CMap, where the _map array implicitly has a length of
  12098. // 65535 and each element is equal to its index.
  12099. var IdentityCMap = (function IdentityCMapClosure() {
  12100. function IdentityCMap(vertical, n) {
  12101. CMap.call(this);
  12102. this.vertical = vertical;
  12103. this.addCodespaceRange(n, 0, 0xffff);
  12104. }
  12105. Util.inherit(IdentityCMap, CMap, {});
  12106. IdentityCMap.prototype = {
  12107. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12108. mapCidRange: function(low, high, dstLow) {
  12109. error('should not call mapCidRange');
  12110. },
  12111. mapBfRange: function(low, high, dstLow) {
  12112. error('should not call mapBfRange');
  12113. },
  12114. mapBfRangeToArray: function(low, high, array) {
  12115. error('should not call mapBfRangeToArray');
  12116. },
  12117. mapOne: function(src, dst) {
  12118. error('should not call mapCidOne');
  12119. },
  12120. lookup: function(code) {
  12121. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12122. },
  12123. contains: function(code) {
  12124. return isInt(code) && code <= 0xffff;
  12125. },
  12126. forEach: function(callback) {
  12127. for (var i = 0; i <= 0xffff; i++) {
  12128. callback(i, i);
  12129. }
  12130. },
  12131. charCodeOf: function(value) {
  12132. return (isInt(value) && value <= 0xffff) ? value : -1;
  12133. },
  12134. getMap: function() {
  12135. // Sometimes identity maps must be instantiated, but it's rare.
  12136. var map = new Array(0x10000);
  12137. for (var i = 0; i <= 0xffff; i++) {
  12138. map[i] = i;
  12139. }
  12140. return map;
  12141. },
  12142. readCharCode: CMap.prototype.readCharCode
  12143. };
  12144. return IdentityCMap;
  12145. })();
  12146. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12147. function fetchBinaryData(url) {
  12148. var nonBinaryRequest = PDFJS.disableWorker;
  12149. var request = new XMLHttpRequest();
  12150. request.open('GET', url, false);
  12151. if (!nonBinaryRequest) {
  12152. try {
  12153. request.responseType = 'arraybuffer';
  12154. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12155. } catch (e) {
  12156. nonBinaryRequest = true;
  12157. }
  12158. }
  12159. if (nonBinaryRequest && request.overrideMimeType) {
  12160. request.overrideMimeType('text/plain; charset=x-user-defined');
  12161. }
  12162. request.send(null);
  12163. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12164. error('Unable to get binary cMap at: ' + url);
  12165. }
  12166. if (nonBinaryRequest) {
  12167. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12168. return ch.charCodeAt(0) & 255;
  12169. });
  12170. return new Uint8Array(data);
  12171. }
  12172. return new Uint8Array(request.response);
  12173. }
  12174. function hexToInt(a, size) {
  12175. var n = 0;
  12176. for (var i = 0; i <= size; i++) {
  12177. n = (n << 8) | a[i];
  12178. }
  12179. return n >>> 0;
  12180. }
  12181. function hexToStr(a, size) {
  12182. // This code is hot. Special-case some common values to avoid creating an
  12183. // object with subarray().
  12184. if (size === 1) {
  12185. return String.fromCharCode(a[0], a[1]);
  12186. }
  12187. if (size === 3) {
  12188. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12189. }
  12190. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12191. }
  12192. function addHex(a, b, size) {
  12193. var c = 0;
  12194. for (var i = size; i >= 0; i--) {
  12195. c += a[i] + b[i];
  12196. a[i] = c & 255;
  12197. c >>= 8;
  12198. }
  12199. }
  12200. function incHex(a, size) {
  12201. var c = 1;
  12202. for (var i = size; i >= 0 && c > 0; i--) {
  12203. c += a[i];
  12204. a[i] = c & 255;
  12205. c >>= 8;
  12206. }
  12207. }
  12208. var MAX_NUM_SIZE = 16;
  12209. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12210. function BinaryCMapStream(data) {
  12211. this.buffer = data;
  12212. this.pos = 0;
  12213. this.end = data.length;
  12214. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12215. }
  12216. BinaryCMapStream.prototype = {
  12217. readByte: function () {
  12218. if (this.pos >= this.end) {
  12219. return -1;
  12220. }
  12221. return this.buffer[this.pos++];
  12222. },
  12223. readNumber: function () {
  12224. var n = 0;
  12225. var last;
  12226. do {
  12227. var b = this.readByte();
  12228. if (b < 0) {
  12229. error('unexpected EOF in bcmap');
  12230. }
  12231. last = !(b & 0x80);
  12232. n = (n << 7) | (b & 0x7F);
  12233. } while (!last);
  12234. return n;
  12235. },
  12236. readSigned: function () {
  12237. var n = this.readNumber();
  12238. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12239. },
  12240. readHex: function (num, size) {
  12241. num.set(this.buffer.subarray(this.pos,
  12242. this.pos + size + 1));
  12243. this.pos += size + 1;
  12244. },
  12245. readHexNumber: function (num, size) {
  12246. var last;
  12247. var stack = this.tmpBuf, sp = 0;
  12248. do {
  12249. var b = this.readByte();
  12250. if (b < 0) {
  12251. error('unexpected EOF in bcmap');
  12252. }
  12253. last = !(b & 0x80);
  12254. stack[sp++] = b & 0x7F;
  12255. } while (!last);
  12256. var i = size, buffer = 0, bufferSize = 0;
  12257. while (i >= 0) {
  12258. while (bufferSize < 8 && stack.length > 0) {
  12259. buffer = (stack[--sp] << bufferSize) | buffer;
  12260. bufferSize += 7;
  12261. }
  12262. num[i] = buffer & 255;
  12263. i--;
  12264. buffer >>= 8;
  12265. bufferSize -= 8;
  12266. }
  12267. },
  12268. readHexSigned: function (num, size) {
  12269. this.readHexNumber(num, size);
  12270. var sign = num[size] & 1 ? 255 : 0;
  12271. var c = 0;
  12272. for (var i = 0; i <= size; i++) {
  12273. c = ((c & 1) << 8) | num[i];
  12274. num[i] = (c >> 1) ^ sign;
  12275. }
  12276. },
  12277. readString: function () {
  12278. var len = this.readNumber();
  12279. var s = '';
  12280. for (var i = 0; i < len; i++) {
  12281. s += String.fromCharCode(this.readNumber());
  12282. }
  12283. return s;
  12284. }
  12285. };
  12286. function processBinaryCMap(url, cMap, extend) {
  12287. var data = fetchBinaryData(url);
  12288. var stream = new BinaryCMapStream(data);
  12289. var header = stream.readByte();
  12290. cMap.vertical = !!(header & 1);
  12291. var useCMap = null;
  12292. var start = new Uint8Array(MAX_NUM_SIZE);
  12293. var end = new Uint8Array(MAX_NUM_SIZE);
  12294. var char = new Uint8Array(MAX_NUM_SIZE);
  12295. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12296. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12297. var code;
  12298. var b;
  12299. while ((b = stream.readByte()) >= 0) {
  12300. var type = b >> 5;
  12301. if (type === 7) { // metadata, e.g. comment or usecmap
  12302. switch (b & 0x1F) {
  12303. case 0:
  12304. stream.readString(); // skipping comment
  12305. break;
  12306. case 1:
  12307. useCMap = stream.readString();
  12308. break;
  12309. }
  12310. continue;
  12311. }
  12312. var sequence = !!(b & 0x10);
  12313. var dataSize = b & 15;
  12314. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12315. var ucs2DataSize = 1;
  12316. var subitemsCount = stream.readNumber();
  12317. var i;
  12318. switch (type) {
  12319. case 0: // codespacerange
  12320. stream.readHex(start, dataSize);
  12321. stream.readHexNumber(end, dataSize);
  12322. addHex(end, start, dataSize);
  12323. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12324. hexToInt(end, dataSize));
  12325. for (i = 1; i < subitemsCount; i++) {
  12326. incHex(end, dataSize);
  12327. stream.readHexNumber(start, dataSize);
  12328. addHex(start, end, dataSize);
  12329. stream.readHexNumber(end, dataSize);
  12330. addHex(end, start, dataSize);
  12331. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12332. hexToInt(end, dataSize));
  12333. }
  12334. break;
  12335. case 1: // notdefrange
  12336. stream.readHex(start, dataSize);
  12337. stream.readHexNumber(end, dataSize);
  12338. addHex(end, start, dataSize);
  12339. code = stream.readNumber();
  12340. // undefined range, skipping
  12341. for (i = 1; i < subitemsCount; i++) {
  12342. incHex(end, dataSize);
  12343. stream.readHexNumber(start, dataSize);
  12344. addHex(start, end, dataSize);
  12345. stream.readHexNumber(end, dataSize);
  12346. addHex(end, start, dataSize);
  12347. code = stream.readNumber();
  12348. // nop
  12349. }
  12350. break;
  12351. case 2: // cidchar
  12352. stream.readHex(char, dataSize);
  12353. code = stream.readNumber();
  12354. cMap.mapOne(hexToInt(char, dataSize), code);
  12355. for (i = 1; i < subitemsCount; i++) {
  12356. incHex(char, dataSize);
  12357. if (!sequence) {
  12358. stream.readHexNumber(tmp, dataSize);
  12359. addHex(char, tmp, dataSize);
  12360. }
  12361. code = stream.readSigned() + (code + 1);
  12362. cMap.mapOne(hexToInt(char, dataSize), code);
  12363. }
  12364. break;
  12365. case 3: // cidrange
  12366. stream.readHex(start, dataSize);
  12367. stream.readHexNumber(end, dataSize);
  12368. addHex(end, start, dataSize);
  12369. code = stream.readNumber();
  12370. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12371. code);
  12372. for (i = 1; i < subitemsCount; i++) {
  12373. incHex(end, dataSize);
  12374. if (!sequence) {
  12375. stream.readHexNumber(start, dataSize);
  12376. addHex(start, end, dataSize);
  12377. } else {
  12378. start.set(end);
  12379. }
  12380. stream.readHexNumber(end, dataSize);
  12381. addHex(end, start, dataSize);
  12382. code = stream.readNumber();
  12383. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12384. code);
  12385. }
  12386. break;
  12387. case 4: // bfchar
  12388. stream.readHex(char, ucs2DataSize);
  12389. stream.readHex(charCode, dataSize);
  12390. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12391. hexToStr(charCode, dataSize));
  12392. for (i = 1; i < subitemsCount; i++) {
  12393. incHex(char, ucs2DataSize);
  12394. if (!sequence) {
  12395. stream.readHexNumber(tmp, ucs2DataSize);
  12396. addHex(char, tmp, ucs2DataSize);
  12397. }
  12398. incHex(charCode, dataSize);
  12399. stream.readHexSigned(tmp, dataSize);
  12400. addHex(charCode, tmp, dataSize);
  12401. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12402. hexToStr(charCode, dataSize));
  12403. }
  12404. break;
  12405. case 5: // bfrange
  12406. stream.readHex(start, ucs2DataSize);
  12407. stream.readHexNumber(end, ucs2DataSize);
  12408. addHex(end, start, ucs2DataSize);
  12409. stream.readHex(charCode, dataSize);
  12410. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12411. hexToInt(end, ucs2DataSize),
  12412. hexToStr(charCode, dataSize));
  12413. for (i = 1; i < subitemsCount; i++) {
  12414. incHex(end, ucs2DataSize);
  12415. if (!sequence) {
  12416. stream.readHexNumber(start, ucs2DataSize);
  12417. addHex(start, end, ucs2DataSize);
  12418. } else {
  12419. start.set(end);
  12420. }
  12421. stream.readHexNumber(end, ucs2DataSize);
  12422. addHex(end, start, ucs2DataSize);
  12423. stream.readHex(charCode, dataSize);
  12424. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12425. hexToInt(end, ucs2DataSize),
  12426. hexToStr(charCode, dataSize));
  12427. }
  12428. break;
  12429. default:
  12430. error('Unknown type: ' + type);
  12431. break;
  12432. }
  12433. }
  12434. if (useCMap) {
  12435. extend(useCMap);
  12436. }
  12437. return cMap;
  12438. }
  12439. function BinaryCMapReader() {}
  12440. BinaryCMapReader.prototype = {
  12441. read: processBinaryCMap
  12442. };
  12443. return BinaryCMapReader;
  12444. })();
  12445. var CMapFactory = (function CMapFactoryClosure() {
  12446. function strToInt(str) {
  12447. var a = 0;
  12448. for (var i = 0; i < str.length; i++) {
  12449. a = (a << 8) | str.charCodeAt(i);
  12450. }
  12451. return a >>> 0;
  12452. }
  12453. function expectString(obj) {
  12454. if (!isString(obj)) {
  12455. error('Malformed CMap: expected string.');
  12456. }
  12457. }
  12458. function expectInt(obj) {
  12459. if (!isInt(obj)) {
  12460. error('Malformed CMap: expected int.');
  12461. }
  12462. }
  12463. function parseBfChar(cMap, lexer) {
  12464. while (true) {
  12465. var obj = lexer.getObj();
  12466. if (isEOF(obj)) {
  12467. break;
  12468. }
  12469. if (isCmd(obj, 'endbfchar')) {
  12470. return;
  12471. }
  12472. expectString(obj);
  12473. var src = strToInt(obj);
  12474. obj = lexer.getObj();
  12475. // TODO are /dstName used?
  12476. expectString(obj);
  12477. var dst = obj;
  12478. cMap.mapOne(src, dst);
  12479. }
  12480. }
  12481. function parseBfRange(cMap, lexer) {
  12482. while (true) {
  12483. var obj = lexer.getObj();
  12484. if (isEOF(obj)) {
  12485. break;
  12486. }
  12487. if (isCmd(obj, 'endbfrange')) {
  12488. return;
  12489. }
  12490. expectString(obj);
  12491. var low = strToInt(obj);
  12492. obj = lexer.getObj();
  12493. expectString(obj);
  12494. var high = strToInt(obj);
  12495. obj = lexer.getObj();
  12496. if (isInt(obj) || isString(obj)) {
  12497. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12498. cMap.mapBfRange(low, high, dstLow);
  12499. } else if (isCmd(obj, '[')) {
  12500. obj = lexer.getObj();
  12501. var array = [];
  12502. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12503. array.push(obj);
  12504. obj = lexer.getObj();
  12505. }
  12506. cMap.mapBfRangeToArray(low, high, array);
  12507. } else {
  12508. break;
  12509. }
  12510. }
  12511. error('Invalid bf range.');
  12512. }
  12513. function parseCidChar(cMap, lexer) {
  12514. while (true) {
  12515. var obj = lexer.getObj();
  12516. if (isEOF(obj)) {
  12517. break;
  12518. }
  12519. if (isCmd(obj, 'endcidchar')) {
  12520. return;
  12521. }
  12522. expectString(obj);
  12523. var src = strToInt(obj);
  12524. obj = lexer.getObj();
  12525. expectInt(obj);
  12526. var dst = obj;
  12527. cMap.mapOne(src, dst);
  12528. }
  12529. }
  12530. function parseCidRange(cMap, lexer) {
  12531. while (true) {
  12532. var obj = lexer.getObj();
  12533. if (isEOF(obj)) {
  12534. break;
  12535. }
  12536. if (isCmd(obj, 'endcidrange')) {
  12537. return;
  12538. }
  12539. expectString(obj);
  12540. var low = strToInt(obj);
  12541. obj = lexer.getObj();
  12542. expectString(obj);
  12543. var high = strToInt(obj);
  12544. obj = lexer.getObj();
  12545. expectInt(obj);
  12546. var dstLow = obj;
  12547. cMap.mapCidRange(low, high, dstLow);
  12548. }
  12549. }
  12550. function parseCodespaceRange(cMap, lexer) {
  12551. while (true) {
  12552. var obj = lexer.getObj();
  12553. if (isEOF(obj)) {
  12554. break;
  12555. }
  12556. if (isCmd(obj, 'endcodespacerange')) {
  12557. return;
  12558. }
  12559. if (!isString(obj)) {
  12560. break;
  12561. }
  12562. var low = strToInt(obj);
  12563. obj = lexer.getObj();
  12564. if (!isString(obj)) {
  12565. break;
  12566. }
  12567. var high = strToInt(obj);
  12568. cMap.addCodespaceRange(obj.length, low, high);
  12569. }
  12570. error('Invalid codespace range.');
  12571. }
  12572. function parseWMode(cMap, lexer) {
  12573. var obj = lexer.getObj();
  12574. if (isInt(obj)) {
  12575. cMap.vertical = !!obj;
  12576. }
  12577. }
  12578. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12579. var previous;
  12580. var embededUseCMap;
  12581. objLoop: while (true) {
  12582. var obj = lexer.getObj();
  12583. if (isEOF(obj)) {
  12584. break;
  12585. } else if (isName(obj)) {
  12586. if (obj.name === 'WMode') {
  12587. parseWMode(cMap, lexer);
  12588. }
  12589. previous = obj;
  12590. } else if (isCmd(obj)) {
  12591. switch (obj.cmd) {
  12592. case 'endcmap':
  12593. break objLoop;
  12594. case 'usecmap':
  12595. if (isName(previous)) {
  12596. embededUseCMap = previous.name;
  12597. }
  12598. break;
  12599. case 'begincodespacerange':
  12600. parseCodespaceRange(cMap, lexer);
  12601. break;
  12602. case 'beginbfchar':
  12603. parseBfChar(cMap, lexer);
  12604. break;
  12605. case 'begincidchar':
  12606. parseCidChar(cMap, lexer);
  12607. break;
  12608. case 'beginbfrange':
  12609. parseBfRange(cMap, lexer);
  12610. break;
  12611. case 'begincidrange':
  12612. parseCidRange(cMap, lexer);
  12613. break;
  12614. }
  12615. }
  12616. }
  12617. if (!useCMap && embededUseCMap) {
  12618. // Load the usecmap definition from the file only if there wasn't one
  12619. // specified.
  12620. useCMap = embededUseCMap;
  12621. }
  12622. if (useCMap) {
  12623. extendCMap(cMap, builtInCMapParams, useCMap);
  12624. }
  12625. }
  12626. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12627. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12628. // If there aren't any code space ranges defined clone all the parent ones
  12629. // into this cMap.
  12630. if (cMap.numCodespaceRanges === 0) {
  12631. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12632. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12633. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12634. }
  12635. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12636. }
  12637. // Merge the map into the current one, making sure not to override
  12638. // any previously defined entries.
  12639. cMap.useCMap.forEach(function(key, value) {
  12640. if (!cMap.contains(key)) {
  12641. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12642. }
  12643. });
  12644. }
  12645. function parseBinaryCMap(name, builtInCMapParams) {
  12646. var url = builtInCMapParams.url + name + '.bcmap';
  12647. var cMap = new CMap(true);
  12648. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12649. extendCMap(cMap, builtInCMapParams, useCMap);
  12650. });
  12651. return cMap;
  12652. }
  12653. function createBuiltInCMap(name, builtInCMapParams) {
  12654. if (name === 'Identity-H') {
  12655. return new IdentityCMap(false, 2);
  12656. } else if (name === 'Identity-V') {
  12657. return new IdentityCMap(true, 2);
  12658. }
  12659. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12660. error('Unknown cMap name: ' + name);
  12661. }
  12662. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12663. if (builtInCMapParams.packed) {
  12664. return parseBinaryCMap(name, builtInCMapParams);
  12665. }
  12666. var request = new XMLHttpRequest();
  12667. var url = builtInCMapParams.url + name;
  12668. request.open('GET', url, false);
  12669. request.send(null);
  12670. if (!request.responseText) {
  12671. error('Unable to get cMap at: ' + url);
  12672. }
  12673. var cMap = new CMap(true);
  12674. var lexer = new Lexer(new StringStream(request.responseText));
  12675. parseCMap(cMap, lexer, builtInCMapParams, null);
  12676. return cMap;
  12677. }
  12678. return {
  12679. create: function (encoding, builtInCMapParams, useCMap) {
  12680. if (isName(encoding)) {
  12681. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12682. } else if (isStream(encoding)) {
  12683. var cMap = new CMap();
  12684. var lexer = new Lexer(encoding);
  12685. try {
  12686. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12687. } catch (e) {
  12688. warn('Invalid CMap data. ' + e);
  12689. }
  12690. return cMap;
  12691. }
  12692. error('Encoding required.');
  12693. }
  12694. };
  12695. })();
  12696. // Unicode Private Use Area
  12697. var PRIVATE_USE_OFFSET_START = 0xE000;
  12698. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12699. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12700. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12701. // except for Type 3 fonts
  12702. var PDF_GLYPH_SPACE_UNITS = 1000;
  12703. // Hinting is currently disabled due to unknown problems on windows
  12704. // in tracemonkey and various other pdfs with type1 fonts.
  12705. var HINTING_ENABLED = false;
  12706. // Accented charactars are not displayed properly on windows, using this flag
  12707. // to control analysis of seac charstrings.
  12708. var SEAC_ANALYSIS_ENABLED = false;
  12709. var FontFlags = {
  12710. FixedPitch: 1,
  12711. Serif: 2,
  12712. Symbolic: 4,
  12713. Script: 8,
  12714. Nonsymbolic: 32,
  12715. Italic: 64,
  12716. AllCap: 65536,
  12717. SmallCap: 131072,
  12718. ForceBold: 262144
  12719. };
  12720. var Encodings = {
  12721. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12722. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12723. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12724. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12725. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12726. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12727. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12728. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12729. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12730. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12731. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12732. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12733. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12734. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12735. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12736. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12737. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12738. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12739. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12740. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12741. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12742. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12743. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12744. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12745. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12746. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12747. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12748. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12749. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12750. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12751. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12752. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12753. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12754. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12755. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12756. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12757. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12758. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12759. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12760. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12761. 'Ydieresissmall'],
  12762. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12763. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12764. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12765. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12766. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12767. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12768. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12769. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12770. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12771. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12772. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12773. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12774. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12775. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12776. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12777. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12778. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12779. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12780. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12781. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12782. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12783. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12784. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12785. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12786. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12787. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12788. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12789. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12790. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12791. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12792. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12793. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12794. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12795. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12796. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12797. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12798. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12799. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12800. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12801. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12802. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12803. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12804. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12805. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12806. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12807. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12808. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12809. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12810. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12811. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12812. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12813. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12814. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12815. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12816. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12817. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12818. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12819. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12820. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12821. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12822. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12823. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12824. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12825. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12826. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12827. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12828. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12829. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12830. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12831. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12832. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12833. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12834. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12835. 'ogonek', 'caron'],
  12836. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12837. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12838. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12839. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12840. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12841. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12842. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12843. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12844. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12845. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12846. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12847. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12848. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12849. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12850. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12851. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12852. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12853. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12854. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12855. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12856. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12857. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12858. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12859. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12860. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12861. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12862. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12863. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12864. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12865. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12866. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12867. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12868. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12869. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12870. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12871. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12872. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12873. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  12874. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  12875. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  12876. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  12877. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  12878. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  12879. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  12880. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  12881. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  12882. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  12883. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  12884. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  12885. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  12886. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  12887. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  12888. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  12889. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  12890. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  12891. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  12892. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  12893. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  12894. 'ydieresis'],
  12895. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12896. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12897. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  12898. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  12899. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  12900. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  12901. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  12902. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  12903. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  12904. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  12905. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  12906. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  12907. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  12908. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  12909. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  12910. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12911. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  12912. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  12913. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  12914. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  12915. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  12916. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  12917. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  12918. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  12919. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  12920. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  12921. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  12922. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  12923. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  12924. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  12925. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  12926. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  12927. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  12928. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  12929. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  12930. 'bracerightbt'],
  12931. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12932. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12933. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  12934. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  12935. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  12936. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  12937. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  12938. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  12939. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  12940. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  12941. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  12942. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  12943. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  12944. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  12945. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  12946. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  12947. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  12948. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  12949. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  12950. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  12951. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  12952. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  12953. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  12954. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  12955. };
  12956. /**
  12957. * Hold a map of decoded fonts and of the standard fourteen Type1
  12958. * fonts and their acronyms.
  12959. */
  12960. var stdFontMap = {
  12961. 'ArialNarrow': 'Helvetica',
  12962. 'ArialNarrow-Bold': 'Helvetica-Bold',
  12963. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  12964. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  12965. 'ArialBlack': 'Helvetica',
  12966. 'ArialBlack-Bold': 'Helvetica-Bold',
  12967. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  12968. 'ArialBlack-Italic': 'Helvetica-Oblique',
  12969. 'Arial': 'Helvetica',
  12970. 'Arial-Bold': 'Helvetica-Bold',
  12971. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  12972. 'Arial-Italic': 'Helvetica-Oblique',
  12973. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  12974. 'Arial-BoldMT': 'Helvetica-Bold',
  12975. 'Arial-ItalicMT': 'Helvetica-Oblique',
  12976. 'ArialMT': 'Helvetica',
  12977. 'Courier-Bold': 'Courier-Bold',
  12978. 'Courier-BoldItalic': 'Courier-BoldOblique',
  12979. 'Courier-Italic': 'Courier-Oblique',
  12980. 'CourierNew': 'Courier',
  12981. 'CourierNew-Bold': 'Courier-Bold',
  12982. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  12983. 'CourierNew-Italic': 'Courier-Oblique',
  12984. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  12985. 'CourierNewPS-BoldMT': 'Courier-Bold',
  12986. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  12987. 'CourierNewPSMT': 'Courier',
  12988. 'Helvetica-Bold': 'Helvetica-Bold',
  12989. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  12990. 'Helvetica-Italic': 'Helvetica-Oblique',
  12991. 'Symbol-Bold': 'Symbol',
  12992. 'Symbol-BoldItalic': 'Symbol',
  12993. 'Symbol-Italic': 'Symbol',
  12994. 'TimesNewRoman': 'Times-Roman',
  12995. 'TimesNewRoman-Bold': 'Times-Bold',
  12996. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  12997. 'TimesNewRoman-Italic': 'Times-Italic',
  12998. 'TimesNewRomanPS': 'Times-Roman',
  12999. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13000. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13001. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13002. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13003. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13004. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13005. 'TimesNewRomanPSMT': 'Times-Roman',
  13006. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13007. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13008. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13009. };
  13010. /**
  13011. * Holds the map of the non-standard fonts that might be included as a standard
  13012. * fonts without glyph data.
  13013. */
  13014. var nonStdFontMap = {
  13015. 'ComicSansMS': 'Comic Sans MS',
  13016. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13017. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13018. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13019. 'LucidaConsole': 'Courier',
  13020. 'LucidaConsole-Bold': 'Courier-Bold',
  13021. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13022. 'LucidaConsole-Italic': 'Courier-Oblique',
  13023. 'MS-Gothic': 'MS Gothic',
  13024. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13025. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13026. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13027. 'MS-Mincho': 'MS Mincho',
  13028. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13029. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13030. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13031. 'MS-PGothic': 'MS PGothic',
  13032. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13033. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13034. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13035. 'MS-PMincho': 'MS PMincho',
  13036. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13037. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13038. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  13039. };
  13040. var serifFonts = {
  13041. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13042. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13043. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13044. 'Arno': true, 'Aster': true, 'Aurora': true,
  13045. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13046. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13047. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13048. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13049. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13050. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13051. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13052. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13053. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13054. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13055. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13056. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13057. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13058. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13059. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13060. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13061. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13062. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13063. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13064. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13065. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13066. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13067. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13068. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13069. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13070. 'Miller': true, 'Minion': true, 'Modern': true,
  13071. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13072. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13073. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13074. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13075. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13076. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13077. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13078. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13079. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13080. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13081. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13082. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13083. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13084. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13085. };
  13086. var symbolsFonts = {
  13087. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13088. };
  13089. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13090. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13091. // glyphs, but common for some set of the standard fonts.
  13092. var GlyphMapForStandardFonts = {
  13093. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13094. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13095. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13096. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13097. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13098. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13099. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13100. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13101. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13102. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13103. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13104. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13105. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13106. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13107. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13108. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13109. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13110. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13111. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13112. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13113. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13114. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13115. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13116. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13117. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13118. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13119. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13120. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13121. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13122. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13123. '298': 380, '305': 963,
  13124. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13125. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13126. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13127. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13128. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13129. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13130. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13131. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13132. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13133. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13134. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13135. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13136. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13137. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13138. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13139. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13140. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13141. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13142. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13143. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13144. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13145. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13146. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13147. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13148. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13149. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13150. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13151. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13152. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13153. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13154. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13155. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13156. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13157. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13158. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13159. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13160. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13161. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13162. };
  13163. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13164. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13165. // to the similar equivalents in the normal characters range.
  13166. var SpecialPUASymbols = {
  13167. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13168. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13169. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13170. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13171. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13172. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13173. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13174. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13175. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13176. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13177. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13178. '63742': 0x23AD, // bracerightmid (0xF8FE)
  13179. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13180. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13181. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13182. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13183. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13184. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13185. '63723': 0x239B, // parenlefttp (0xF8EB)
  13186. '63724': 0x239C, // parenleftex (0xF8EC)
  13187. '63725': 0x239D, // parenleftbt (0xF8ED)
  13188. '63734': 0x239E, // parenrighttp (0xF8F6)
  13189. '63735': 0x239F, // parenrightex (0xF8F7)
  13190. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13191. };
  13192. function mapSpecialUnicodeValues(code) {
  13193. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13194. return 0;
  13195. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13196. return (SpecialPUASymbols[code] || code);
  13197. }
  13198. return code;
  13199. }
  13200. var UnicodeRanges = [
  13201. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13202. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13203. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13204. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13205. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13206. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13207. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13208. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13209. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13210. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13211. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13212. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13213. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13214. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13215. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13216. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13217. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13218. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13219. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13220. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13221. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13222. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13223. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13224. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13225. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13226. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13227. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13228. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13229. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13230. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13231. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13232. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13233. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13234. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13235. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13236. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13237. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13238. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13239. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13240. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13241. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13242. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13243. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13244. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13245. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13246. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13247. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13248. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13249. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13250. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13251. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13252. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13253. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13254. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13255. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13256. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13257. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13258. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13259. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13260. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13261. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13262. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13263. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13264. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13265. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13266. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13267. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13268. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13269. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13270. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13271. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13272. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13273. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13274. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13275. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13276. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13277. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13278. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13279. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13280. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13281. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13282. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13283. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13284. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13285. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13286. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13287. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13288. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13289. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13290. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13291. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13292. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13293. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13294. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13295. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13296. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13297. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13298. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13299. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13300. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13301. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13302. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13303. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13304. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13305. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13306. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13307. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13308. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13309. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13310. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13311. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13312. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13313. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13314. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13315. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13316. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13317. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13318. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13319. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13320. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13321. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13322. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13323. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13324. ];
  13325. var MacStandardGlyphOrdering = [
  13326. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13327. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13328. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13329. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13330. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13331. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13332. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13333. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13334. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13335. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13336. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13337. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13338. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13339. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13340. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13341. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13342. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13343. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13344. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13345. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13346. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13347. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13348. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13349. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13350. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13351. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13352. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13353. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13354. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13355. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13356. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13357. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13358. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13359. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13360. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13361. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13362. function getUnicodeRangeFor(value) {
  13363. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13364. var range = UnicodeRanges[i];
  13365. if (value >= range.begin && value < range.end) {
  13366. return i;
  13367. }
  13368. }
  13369. return -1;
  13370. }
  13371. function isRTLRangeFor(value) {
  13372. var range = UnicodeRanges[13];
  13373. if (value >= range.begin && value < range.end) {
  13374. return true;
  13375. }
  13376. range = UnicodeRanges[11];
  13377. if (value >= range.begin && value < range.end) {
  13378. return true;
  13379. }
  13380. return false;
  13381. }
  13382. // The normalization table is obtained by filtering the Unicode characters
  13383. // database with <compat> entries.
  13384. var NormalizedUnicodes = {
  13385. '\u00A8': '\u0020\u0308',
  13386. '\u00AF': '\u0020\u0304',
  13387. '\u00B4': '\u0020\u0301',
  13388. '\u00B5': '\u03BC',
  13389. '\u00B8': '\u0020\u0327',
  13390. '\u0132': '\u0049\u004A',
  13391. '\u0133': '\u0069\u006A',
  13392. '\u013F': '\u004C\u00B7',
  13393. '\u0140': '\u006C\u00B7',
  13394. '\u0149': '\u02BC\u006E',
  13395. '\u017F': '\u0073',
  13396. '\u01C4': '\u0044\u017D',
  13397. '\u01C5': '\u0044\u017E',
  13398. '\u01C6': '\u0064\u017E',
  13399. '\u01C7': '\u004C\u004A',
  13400. '\u01C8': '\u004C\u006A',
  13401. '\u01C9': '\u006C\u006A',
  13402. '\u01CA': '\u004E\u004A',
  13403. '\u01CB': '\u004E\u006A',
  13404. '\u01CC': '\u006E\u006A',
  13405. '\u01F1': '\u0044\u005A',
  13406. '\u01F2': '\u0044\u007A',
  13407. '\u01F3': '\u0064\u007A',
  13408. '\u02D8': '\u0020\u0306',
  13409. '\u02D9': '\u0020\u0307',
  13410. '\u02DA': '\u0020\u030A',
  13411. '\u02DB': '\u0020\u0328',
  13412. '\u02DC': '\u0020\u0303',
  13413. '\u02DD': '\u0020\u030B',
  13414. '\u037A': '\u0020\u0345',
  13415. '\u0384': '\u0020\u0301',
  13416. '\u03D0': '\u03B2',
  13417. '\u03D1': '\u03B8',
  13418. '\u03D2': '\u03A5',
  13419. '\u03D5': '\u03C6',
  13420. '\u03D6': '\u03C0',
  13421. '\u03F0': '\u03BA',
  13422. '\u03F1': '\u03C1',
  13423. '\u03F2': '\u03C2',
  13424. '\u03F4': '\u0398',
  13425. '\u03F5': '\u03B5',
  13426. '\u03F9': '\u03A3',
  13427. '\u0587': '\u0565\u0582',
  13428. '\u0675': '\u0627\u0674',
  13429. '\u0676': '\u0648\u0674',
  13430. '\u0677': '\u06C7\u0674',
  13431. '\u0678': '\u064A\u0674',
  13432. '\u0E33': '\u0E4D\u0E32',
  13433. '\u0EB3': '\u0ECD\u0EB2',
  13434. '\u0EDC': '\u0EAB\u0E99',
  13435. '\u0EDD': '\u0EAB\u0EA1',
  13436. '\u0F77': '\u0FB2\u0F81',
  13437. '\u0F79': '\u0FB3\u0F81',
  13438. '\u1E9A': '\u0061\u02BE',
  13439. '\u1FBD': '\u0020\u0313',
  13440. '\u1FBF': '\u0020\u0313',
  13441. '\u1FC0': '\u0020\u0342',
  13442. '\u1FFE': '\u0020\u0314',
  13443. '\u2002': '\u0020',
  13444. '\u2003': '\u0020',
  13445. '\u2004': '\u0020',
  13446. '\u2005': '\u0020',
  13447. '\u2006': '\u0020',
  13448. '\u2008': '\u0020',
  13449. '\u2009': '\u0020',
  13450. '\u200A': '\u0020',
  13451. '\u2017': '\u0020\u0333',
  13452. '\u2024': '\u002E',
  13453. '\u2025': '\u002E\u002E',
  13454. '\u2026': '\u002E\u002E\u002E',
  13455. '\u2033': '\u2032\u2032',
  13456. '\u2034': '\u2032\u2032\u2032',
  13457. '\u2036': '\u2035\u2035',
  13458. '\u2037': '\u2035\u2035\u2035',
  13459. '\u203C': '\u0021\u0021',
  13460. '\u203E': '\u0020\u0305',
  13461. '\u2047': '\u003F\u003F',
  13462. '\u2048': '\u003F\u0021',
  13463. '\u2049': '\u0021\u003F',
  13464. '\u2057': '\u2032\u2032\u2032\u2032',
  13465. '\u205F': '\u0020',
  13466. '\u20A8': '\u0052\u0073',
  13467. '\u2100': '\u0061\u002F\u0063',
  13468. '\u2101': '\u0061\u002F\u0073',
  13469. '\u2103': '\u00B0\u0043',
  13470. '\u2105': '\u0063\u002F\u006F',
  13471. '\u2106': '\u0063\u002F\u0075',
  13472. '\u2107': '\u0190',
  13473. '\u2109': '\u00B0\u0046',
  13474. '\u2116': '\u004E\u006F',
  13475. '\u2121': '\u0054\u0045\u004C',
  13476. '\u2135': '\u05D0',
  13477. '\u2136': '\u05D1',
  13478. '\u2137': '\u05D2',
  13479. '\u2138': '\u05D3',
  13480. '\u213B': '\u0046\u0041\u0058',
  13481. '\u2160': '\u0049',
  13482. '\u2161': '\u0049\u0049',
  13483. '\u2162': '\u0049\u0049\u0049',
  13484. '\u2163': '\u0049\u0056',
  13485. '\u2164': '\u0056',
  13486. '\u2165': '\u0056\u0049',
  13487. '\u2166': '\u0056\u0049\u0049',
  13488. '\u2167': '\u0056\u0049\u0049\u0049',
  13489. '\u2168': '\u0049\u0058',
  13490. '\u2169': '\u0058',
  13491. '\u216A': '\u0058\u0049',
  13492. '\u216B': '\u0058\u0049\u0049',
  13493. '\u216C': '\u004C',
  13494. '\u216D': '\u0043',
  13495. '\u216E': '\u0044',
  13496. '\u216F': '\u004D',
  13497. '\u2170': '\u0069',
  13498. '\u2171': '\u0069\u0069',
  13499. '\u2172': '\u0069\u0069\u0069',
  13500. '\u2173': '\u0069\u0076',
  13501. '\u2174': '\u0076',
  13502. '\u2175': '\u0076\u0069',
  13503. '\u2176': '\u0076\u0069\u0069',
  13504. '\u2177': '\u0076\u0069\u0069\u0069',
  13505. '\u2178': '\u0069\u0078',
  13506. '\u2179': '\u0078',
  13507. '\u217A': '\u0078\u0069',
  13508. '\u217B': '\u0078\u0069\u0069',
  13509. '\u217C': '\u006C',
  13510. '\u217D': '\u0063',
  13511. '\u217E': '\u0064',
  13512. '\u217F': '\u006D',
  13513. '\u222C': '\u222B\u222B',
  13514. '\u222D': '\u222B\u222B\u222B',
  13515. '\u222F': '\u222E\u222E',
  13516. '\u2230': '\u222E\u222E\u222E',
  13517. '\u2474': '\u0028\u0031\u0029',
  13518. '\u2475': '\u0028\u0032\u0029',
  13519. '\u2476': '\u0028\u0033\u0029',
  13520. '\u2477': '\u0028\u0034\u0029',
  13521. '\u2478': '\u0028\u0035\u0029',
  13522. '\u2479': '\u0028\u0036\u0029',
  13523. '\u247A': '\u0028\u0037\u0029',
  13524. '\u247B': '\u0028\u0038\u0029',
  13525. '\u247C': '\u0028\u0039\u0029',
  13526. '\u247D': '\u0028\u0031\u0030\u0029',
  13527. '\u247E': '\u0028\u0031\u0031\u0029',
  13528. '\u247F': '\u0028\u0031\u0032\u0029',
  13529. '\u2480': '\u0028\u0031\u0033\u0029',
  13530. '\u2481': '\u0028\u0031\u0034\u0029',
  13531. '\u2482': '\u0028\u0031\u0035\u0029',
  13532. '\u2483': '\u0028\u0031\u0036\u0029',
  13533. '\u2484': '\u0028\u0031\u0037\u0029',
  13534. '\u2485': '\u0028\u0031\u0038\u0029',
  13535. '\u2486': '\u0028\u0031\u0039\u0029',
  13536. '\u2487': '\u0028\u0032\u0030\u0029',
  13537. '\u2488': '\u0031\u002E',
  13538. '\u2489': '\u0032\u002E',
  13539. '\u248A': '\u0033\u002E',
  13540. '\u248B': '\u0034\u002E',
  13541. '\u248C': '\u0035\u002E',
  13542. '\u248D': '\u0036\u002E',
  13543. '\u248E': '\u0037\u002E',
  13544. '\u248F': '\u0038\u002E',
  13545. '\u2490': '\u0039\u002E',
  13546. '\u2491': '\u0031\u0030\u002E',
  13547. '\u2492': '\u0031\u0031\u002E',
  13548. '\u2493': '\u0031\u0032\u002E',
  13549. '\u2494': '\u0031\u0033\u002E',
  13550. '\u2495': '\u0031\u0034\u002E',
  13551. '\u2496': '\u0031\u0035\u002E',
  13552. '\u2497': '\u0031\u0036\u002E',
  13553. '\u2498': '\u0031\u0037\u002E',
  13554. '\u2499': '\u0031\u0038\u002E',
  13555. '\u249A': '\u0031\u0039\u002E',
  13556. '\u249B': '\u0032\u0030\u002E',
  13557. '\u249C': '\u0028\u0061\u0029',
  13558. '\u249D': '\u0028\u0062\u0029',
  13559. '\u249E': '\u0028\u0063\u0029',
  13560. '\u249F': '\u0028\u0064\u0029',
  13561. '\u24A0': '\u0028\u0065\u0029',
  13562. '\u24A1': '\u0028\u0066\u0029',
  13563. '\u24A2': '\u0028\u0067\u0029',
  13564. '\u24A3': '\u0028\u0068\u0029',
  13565. '\u24A4': '\u0028\u0069\u0029',
  13566. '\u24A5': '\u0028\u006A\u0029',
  13567. '\u24A6': '\u0028\u006B\u0029',
  13568. '\u24A7': '\u0028\u006C\u0029',
  13569. '\u24A8': '\u0028\u006D\u0029',
  13570. '\u24A9': '\u0028\u006E\u0029',
  13571. '\u24AA': '\u0028\u006F\u0029',
  13572. '\u24AB': '\u0028\u0070\u0029',
  13573. '\u24AC': '\u0028\u0071\u0029',
  13574. '\u24AD': '\u0028\u0072\u0029',
  13575. '\u24AE': '\u0028\u0073\u0029',
  13576. '\u24AF': '\u0028\u0074\u0029',
  13577. '\u24B0': '\u0028\u0075\u0029',
  13578. '\u24B1': '\u0028\u0076\u0029',
  13579. '\u24B2': '\u0028\u0077\u0029',
  13580. '\u24B3': '\u0028\u0078\u0029',
  13581. '\u24B4': '\u0028\u0079\u0029',
  13582. '\u24B5': '\u0028\u007A\u0029',
  13583. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13584. '\u2A74': '\u003A\u003A\u003D',
  13585. '\u2A75': '\u003D\u003D',
  13586. '\u2A76': '\u003D\u003D\u003D',
  13587. '\u2E9F': '\u6BCD',
  13588. '\u2EF3': '\u9F9F',
  13589. '\u2F00': '\u4E00',
  13590. '\u2F01': '\u4E28',
  13591. '\u2F02': '\u4E36',
  13592. '\u2F03': '\u4E3F',
  13593. '\u2F04': '\u4E59',
  13594. '\u2F05': '\u4E85',
  13595. '\u2F06': '\u4E8C',
  13596. '\u2F07': '\u4EA0',
  13597. '\u2F08': '\u4EBA',
  13598. '\u2F09': '\u513F',
  13599. '\u2F0A': '\u5165',
  13600. '\u2F0B': '\u516B',
  13601. '\u2F0C': '\u5182',
  13602. '\u2F0D': '\u5196',
  13603. '\u2F0E': '\u51AB',
  13604. '\u2F0F': '\u51E0',
  13605. '\u2F10': '\u51F5',
  13606. '\u2F11': '\u5200',
  13607. '\u2F12': '\u529B',
  13608. '\u2F13': '\u52F9',
  13609. '\u2F14': '\u5315',
  13610. '\u2F15': '\u531A',
  13611. '\u2F16': '\u5338',
  13612. '\u2F17': '\u5341',
  13613. '\u2F18': '\u535C',
  13614. '\u2F19': '\u5369',
  13615. '\u2F1A': '\u5382',
  13616. '\u2F1B': '\u53B6',
  13617. '\u2F1C': '\u53C8',
  13618. '\u2F1D': '\u53E3',
  13619. '\u2F1E': '\u56D7',
  13620. '\u2F1F': '\u571F',
  13621. '\u2F20': '\u58EB',
  13622. '\u2F21': '\u5902',
  13623. '\u2F22': '\u590A',
  13624. '\u2F23': '\u5915',
  13625. '\u2F24': '\u5927',
  13626. '\u2F25': '\u5973',
  13627. '\u2F26': '\u5B50',
  13628. '\u2F27': '\u5B80',
  13629. '\u2F28': '\u5BF8',
  13630. '\u2F29': '\u5C0F',
  13631. '\u2F2A': '\u5C22',
  13632. '\u2F2B': '\u5C38',
  13633. '\u2F2C': '\u5C6E',
  13634. '\u2F2D': '\u5C71',
  13635. '\u2F2E': '\u5DDB',
  13636. '\u2F2F': '\u5DE5',
  13637. '\u2F30': '\u5DF1',
  13638. '\u2F31': '\u5DFE',
  13639. '\u2F32': '\u5E72',
  13640. '\u2F33': '\u5E7A',
  13641. '\u2F34': '\u5E7F',
  13642. '\u2F35': '\u5EF4',
  13643. '\u2F36': '\u5EFE',
  13644. '\u2F37': '\u5F0B',
  13645. '\u2F38': '\u5F13',
  13646. '\u2F39': '\u5F50',
  13647. '\u2F3A': '\u5F61',
  13648. '\u2F3B': '\u5F73',
  13649. '\u2F3C': '\u5FC3',
  13650. '\u2F3D': '\u6208',
  13651. '\u2F3E': '\u6236',
  13652. '\u2F3F': '\u624B',
  13653. '\u2F40': '\u652F',
  13654. '\u2F41': '\u6534',
  13655. '\u2F42': '\u6587',
  13656. '\u2F43': '\u6597',
  13657. '\u2F44': '\u65A4',
  13658. '\u2F45': '\u65B9',
  13659. '\u2F46': '\u65E0',
  13660. '\u2F47': '\u65E5',
  13661. '\u2F48': '\u66F0',
  13662. '\u2F49': '\u6708',
  13663. '\u2F4A': '\u6728',
  13664. '\u2F4B': '\u6B20',
  13665. '\u2F4C': '\u6B62',
  13666. '\u2F4D': '\u6B79',
  13667. '\u2F4E': '\u6BB3',
  13668. '\u2F4F': '\u6BCB',
  13669. '\u2F50': '\u6BD4',
  13670. '\u2F51': '\u6BDB',
  13671. '\u2F52': '\u6C0F',
  13672. '\u2F53': '\u6C14',
  13673. '\u2F54': '\u6C34',
  13674. '\u2F55': '\u706B',
  13675. '\u2F56': '\u722A',
  13676. '\u2F57': '\u7236',
  13677. '\u2F58': '\u723B',
  13678. '\u2F59': '\u723F',
  13679. '\u2F5A': '\u7247',
  13680. '\u2F5B': '\u7259',
  13681. '\u2F5C': '\u725B',
  13682. '\u2F5D': '\u72AC',
  13683. '\u2F5E': '\u7384',
  13684. '\u2F5F': '\u7389',
  13685. '\u2F60': '\u74DC',
  13686. '\u2F61': '\u74E6',
  13687. '\u2F62': '\u7518',
  13688. '\u2F63': '\u751F',
  13689. '\u2F64': '\u7528',
  13690. '\u2F65': '\u7530',
  13691. '\u2F66': '\u758B',
  13692. '\u2F67': '\u7592',
  13693. '\u2F68': '\u7676',
  13694. '\u2F69': '\u767D',
  13695. '\u2F6A': '\u76AE',
  13696. '\u2F6B': '\u76BF',
  13697. '\u2F6C': '\u76EE',
  13698. '\u2F6D': '\u77DB',
  13699. '\u2F6E': '\u77E2',
  13700. '\u2F6F': '\u77F3',
  13701. '\u2F70': '\u793A',
  13702. '\u2F71': '\u79B8',
  13703. '\u2F72': '\u79BE',
  13704. '\u2F73': '\u7A74',
  13705. '\u2F74': '\u7ACB',
  13706. '\u2F75': '\u7AF9',
  13707. '\u2F76': '\u7C73',
  13708. '\u2F77': '\u7CF8',
  13709. '\u2F78': '\u7F36',
  13710. '\u2F79': '\u7F51',
  13711. '\u2F7A': '\u7F8A',
  13712. '\u2F7B': '\u7FBD',
  13713. '\u2F7C': '\u8001',
  13714. '\u2F7D': '\u800C',
  13715. '\u2F7E': '\u8012',
  13716. '\u2F7F': '\u8033',
  13717. '\u2F80': '\u807F',
  13718. '\u2F81': '\u8089',
  13719. '\u2F82': '\u81E3',
  13720. '\u2F83': '\u81EA',
  13721. '\u2F84': '\u81F3',
  13722. '\u2F85': '\u81FC',
  13723. '\u2F86': '\u820C',
  13724. '\u2F87': '\u821B',
  13725. '\u2F88': '\u821F',
  13726. '\u2F89': '\u826E',
  13727. '\u2F8A': '\u8272',
  13728. '\u2F8B': '\u8278',
  13729. '\u2F8C': '\u864D',
  13730. '\u2F8D': '\u866B',
  13731. '\u2F8E': '\u8840',
  13732. '\u2F8F': '\u884C',
  13733. '\u2F90': '\u8863',
  13734. '\u2F91': '\u897E',
  13735. '\u2F92': '\u898B',
  13736. '\u2F93': '\u89D2',
  13737. '\u2F94': '\u8A00',
  13738. '\u2F95': '\u8C37',
  13739. '\u2F96': '\u8C46',
  13740. '\u2F97': '\u8C55',
  13741. '\u2F98': '\u8C78',
  13742. '\u2F99': '\u8C9D',
  13743. '\u2F9A': '\u8D64',
  13744. '\u2F9B': '\u8D70',
  13745. '\u2F9C': '\u8DB3',
  13746. '\u2F9D': '\u8EAB',
  13747. '\u2F9E': '\u8ECA',
  13748. '\u2F9F': '\u8F9B',
  13749. '\u2FA0': '\u8FB0',
  13750. '\u2FA1': '\u8FB5',
  13751. '\u2FA2': '\u9091',
  13752. '\u2FA3': '\u9149',
  13753. '\u2FA4': '\u91C6',
  13754. '\u2FA5': '\u91CC',
  13755. '\u2FA6': '\u91D1',
  13756. '\u2FA7': '\u9577',
  13757. '\u2FA8': '\u9580',
  13758. '\u2FA9': '\u961C',
  13759. '\u2FAA': '\u96B6',
  13760. '\u2FAB': '\u96B9',
  13761. '\u2FAC': '\u96E8',
  13762. '\u2FAD': '\u9751',
  13763. '\u2FAE': '\u975E',
  13764. '\u2FAF': '\u9762',
  13765. '\u2FB0': '\u9769',
  13766. '\u2FB1': '\u97CB',
  13767. '\u2FB2': '\u97ED',
  13768. '\u2FB3': '\u97F3',
  13769. '\u2FB4': '\u9801',
  13770. '\u2FB5': '\u98A8',
  13771. '\u2FB6': '\u98DB',
  13772. '\u2FB7': '\u98DF',
  13773. '\u2FB8': '\u9996',
  13774. '\u2FB9': '\u9999',
  13775. '\u2FBA': '\u99AC',
  13776. '\u2FBB': '\u9AA8',
  13777. '\u2FBC': '\u9AD8',
  13778. '\u2FBD': '\u9ADF',
  13779. '\u2FBE': '\u9B25',
  13780. '\u2FBF': '\u9B2F',
  13781. '\u2FC0': '\u9B32',
  13782. '\u2FC1': '\u9B3C',
  13783. '\u2FC2': '\u9B5A',
  13784. '\u2FC3': '\u9CE5',
  13785. '\u2FC4': '\u9E75',
  13786. '\u2FC5': '\u9E7F',
  13787. '\u2FC6': '\u9EA5',
  13788. '\u2FC7': '\u9EBB',
  13789. '\u2FC8': '\u9EC3',
  13790. '\u2FC9': '\u9ECD',
  13791. '\u2FCA': '\u9ED1',
  13792. '\u2FCB': '\u9EF9',
  13793. '\u2FCC': '\u9EFD',
  13794. '\u2FCD': '\u9F0E',
  13795. '\u2FCE': '\u9F13',
  13796. '\u2FCF': '\u9F20',
  13797. '\u2FD0': '\u9F3B',
  13798. '\u2FD1': '\u9F4A',
  13799. '\u2FD2': '\u9F52',
  13800. '\u2FD3': '\u9F8D',
  13801. '\u2FD4': '\u9F9C',
  13802. '\u2FD5': '\u9FA0',
  13803. '\u3036': '\u3012',
  13804. '\u3038': '\u5341',
  13805. '\u3039': '\u5344',
  13806. '\u303A': '\u5345',
  13807. '\u309B': '\u0020\u3099',
  13808. '\u309C': '\u0020\u309A',
  13809. '\u3131': '\u1100',
  13810. '\u3132': '\u1101',
  13811. '\u3133': '\u11AA',
  13812. '\u3134': '\u1102',
  13813. '\u3135': '\u11AC',
  13814. '\u3136': '\u11AD',
  13815. '\u3137': '\u1103',
  13816. '\u3138': '\u1104',
  13817. '\u3139': '\u1105',
  13818. '\u313A': '\u11B0',
  13819. '\u313B': '\u11B1',
  13820. '\u313C': '\u11B2',
  13821. '\u313D': '\u11B3',
  13822. '\u313E': '\u11B4',
  13823. '\u313F': '\u11B5',
  13824. '\u3140': '\u111A',
  13825. '\u3141': '\u1106',
  13826. '\u3142': '\u1107',
  13827. '\u3143': '\u1108',
  13828. '\u3144': '\u1121',
  13829. '\u3145': '\u1109',
  13830. '\u3146': '\u110A',
  13831. '\u3147': '\u110B',
  13832. '\u3148': '\u110C',
  13833. '\u3149': '\u110D',
  13834. '\u314A': '\u110E',
  13835. '\u314B': '\u110F',
  13836. '\u314C': '\u1110',
  13837. '\u314D': '\u1111',
  13838. '\u314E': '\u1112',
  13839. '\u314F': '\u1161',
  13840. '\u3150': '\u1162',
  13841. '\u3151': '\u1163',
  13842. '\u3152': '\u1164',
  13843. '\u3153': '\u1165',
  13844. '\u3154': '\u1166',
  13845. '\u3155': '\u1167',
  13846. '\u3156': '\u1168',
  13847. '\u3157': '\u1169',
  13848. '\u3158': '\u116A',
  13849. '\u3159': '\u116B',
  13850. '\u315A': '\u116C',
  13851. '\u315B': '\u116D',
  13852. '\u315C': '\u116E',
  13853. '\u315D': '\u116F',
  13854. '\u315E': '\u1170',
  13855. '\u315F': '\u1171',
  13856. '\u3160': '\u1172',
  13857. '\u3161': '\u1173',
  13858. '\u3162': '\u1174',
  13859. '\u3163': '\u1175',
  13860. '\u3164': '\u1160',
  13861. '\u3165': '\u1114',
  13862. '\u3166': '\u1115',
  13863. '\u3167': '\u11C7',
  13864. '\u3168': '\u11C8',
  13865. '\u3169': '\u11CC',
  13866. '\u316A': '\u11CE',
  13867. '\u316B': '\u11D3',
  13868. '\u316C': '\u11D7',
  13869. '\u316D': '\u11D9',
  13870. '\u316E': '\u111C',
  13871. '\u316F': '\u11DD',
  13872. '\u3170': '\u11DF',
  13873. '\u3171': '\u111D',
  13874. '\u3172': '\u111E',
  13875. '\u3173': '\u1120',
  13876. '\u3174': '\u1122',
  13877. '\u3175': '\u1123',
  13878. '\u3176': '\u1127',
  13879. '\u3177': '\u1129',
  13880. '\u3178': '\u112B',
  13881. '\u3179': '\u112C',
  13882. '\u317A': '\u112D',
  13883. '\u317B': '\u112E',
  13884. '\u317C': '\u112F',
  13885. '\u317D': '\u1132',
  13886. '\u317E': '\u1136',
  13887. '\u317F': '\u1140',
  13888. '\u3180': '\u1147',
  13889. '\u3181': '\u114C',
  13890. '\u3182': '\u11F1',
  13891. '\u3183': '\u11F2',
  13892. '\u3184': '\u1157',
  13893. '\u3185': '\u1158',
  13894. '\u3186': '\u1159',
  13895. '\u3187': '\u1184',
  13896. '\u3188': '\u1185',
  13897. '\u3189': '\u1188',
  13898. '\u318A': '\u1191',
  13899. '\u318B': '\u1192',
  13900. '\u318C': '\u1194',
  13901. '\u318D': '\u119E',
  13902. '\u318E': '\u11A1',
  13903. '\u3200': '\u0028\u1100\u0029',
  13904. '\u3201': '\u0028\u1102\u0029',
  13905. '\u3202': '\u0028\u1103\u0029',
  13906. '\u3203': '\u0028\u1105\u0029',
  13907. '\u3204': '\u0028\u1106\u0029',
  13908. '\u3205': '\u0028\u1107\u0029',
  13909. '\u3206': '\u0028\u1109\u0029',
  13910. '\u3207': '\u0028\u110B\u0029',
  13911. '\u3208': '\u0028\u110C\u0029',
  13912. '\u3209': '\u0028\u110E\u0029',
  13913. '\u320A': '\u0028\u110F\u0029',
  13914. '\u320B': '\u0028\u1110\u0029',
  13915. '\u320C': '\u0028\u1111\u0029',
  13916. '\u320D': '\u0028\u1112\u0029',
  13917. '\u320E': '\u0028\u1100\u1161\u0029',
  13918. '\u320F': '\u0028\u1102\u1161\u0029',
  13919. '\u3210': '\u0028\u1103\u1161\u0029',
  13920. '\u3211': '\u0028\u1105\u1161\u0029',
  13921. '\u3212': '\u0028\u1106\u1161\u0029',
  13922. '\u3213': '\u0028\u1107\u1161\u0029',
  13923. '\u3214': '\u0028\u1109\u1161\u0029',
  13924. '\u3215': '\u0028\u110B\u1161\u0029',
  13925. '\u3216': '\u0028\u110C\u1161\u0029',
  13926. '\u3217': '\u0028\u110E\u1161\u0029',
  13927. '\u3218': '\u0028\u110F\u1161\u0029',
  13928. '\u3219': '\u0028\u1110\u1161\u0029',
  13929. '\u321A': '\u0028\u1111\u1161\u0029',
  13930. '\u321B': '\u0028\u1112\u1161\u0029',
  13931. '\u321C': '\u0028\u110C\u116E\u0029',
  13932. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  13933. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  13934. '\u3220': '\u0028\u4E00\u0029',
  13935. '\u3221': '\u0028\u4E8C\u0029',
  13936. '\u3222': '\u0028\u4E09\u0029',
  13937. '\u3223': '\u0028\u56DB\u0029',
  13938. '\u3224': '\u0028\u4E94\u0029',
  13939. '\u3225': '\u0028\u516D\u0029',
  13940. '\u3226': '\u0028\u4E03\u0029',
  13941. '\u3227': '\u0028\u516B\u0029',
  13942. '\u3228': '\u0028\u4E5D\u0029',
  13943. '\u3229': '\u0028\u5341\u0029',
  13944. '\u322A': '\u0028\u6708\u0029',
  13945. '\u322B': '\u0028\u706B\u0029',
  13946. '\u322C': '\u0028\u6C34\u0029',
  13947. '\u322D': '\u0028\u6728\u0029',
  13948. '\u322E': '\u0028\u91D1\u0029',
  13949. '\u322F': '\u0028\u571F\u0029',
  13950. '\u3230': '\u0028\u65E5\u0029',
  13951. '\u3231': '\u0028\u682A\u0029',
  13952. '\u3232': '\u0028\u6709\u0029',
  13953. '\u3233': '\u0028\u793E\u0029',
  13954. '\u3234': '\u0028\u540D\u0029',
  13955. '\u3235': '\u0028\u7279\u0029',
  13956. '\u3236': '\u0028\u8CA1\u0029',
  13957. '\u3237': '\u0028\u795D\u0029',
  13958. '\u3238': '\u0028\u52B4\u0029',
  13959. '\u3239': '\u0028\u4EE3\u0029',
  13960. '\u323A': '\u0028\u547C\u0029',
  13961. '\u323B': '\u0028\u5B66\u0029',
  13962. '\u323C': '\u0028\u76E3\u0029',
  13963. '\u323D': '\u0028\u4F01\u0029',
  13964. '\u323E': '\u0028\u8CC7\u0029',
  13965. '\u323F': '\u0028\u5354\u0029',
  13966. '\u3240': '\u0028\u796D\u0029',
  13967. '\u3241': '\u0028\u4F11\u0029',
  13968. '\u3242': '\u0028\u81EA\u0029',
  13969. '\u3243': '\u0028\u81F3\u0029',
  13970. '\u32C0': '\u0031\u6708',
  13971. '\u32C1': '\u0032\u6708',
  13972. '\u32C2': '\u0033\u6708',
  13973. '\u32C3': '\u0034\u6708',
  13974. '\u32C4': '\u0035\u6708',
  13975. '\u32C5': '\u0036\u6708',
  13976. '\u32C6': '\u0037\u6708',
  13977. '\u32C7': '\u0038\u6708',
  13978. '\u32C8': '\u0039\u6708',
  13979. '\u32C9': '\u0031\u0030\u6708',
  13980. '\u32CA': '\u0031\u0031\u6708',
  13981. '\u32CB': '\u0031\u0032\u6708',
  13982. '\u3358': '\u0030\u70B9',
  13983. '\u3359': '\u0031\u70B9',
  13984. '\u335A': '\u0032\u70B9',
  13985. '\u335B': '\u0033\u70B9',
  13986. '\u335C': '\u0034\u70B9',
  13987. '\u335D': '\u0035\u70B9',
  13988. '\u335E': '\u0036\u70B9',
  13989. '\u335F': '\u0037\u70B9',
  13990. '\u3360': '\u0038\u70B9',
  13991. '\u3361': '\u0039\u70B9',
  13992. '\u3362': '\u0031\u0030\u70B9',
  13993. '\u3363': '\u0031\u0031\u70B9',
  13994. '\u3364': '\u0031\u0032\u70B9',
  13995. '\u3365': '\u0031\u0033\u70B9',
  13996. '\u3366': '\u0031\u0034\u70B9',
  13997. '\u3367': '\u0031\u0035\u70B9',
  13998. '\u3368': '\u0031\u0036\u70B9',
  13999. '\u3369': '\u0031\u0037\u70B9',
  14000. '\u336A': '\u0031\u0038\u70B9',
  14001. '\u336B': '\u0031\u0039\u70B9',
  14002. '\u336C': '\u0032\u0030\u70B9',
  14003. '\u336D': '\u0032\u0031\u70B9',
  14004. '\u336E': '\u0032\u0032\u70B9',
  14005. '\u336F': '\u0032\u0033\u70B9',
  14006. '\u3370': '\u0032\u0034\u70B9',
  14007. '\u33E0': '\u0031\u65E5',
  14008. '\u33E1': '\u0032\u65E5',
  14009. '\u33E2': '\u0033\u65E5',
  14010. '\u33E3': '\u0034\u65E5',
  14011. '\u33E4': '\u0035\u65E5',
  14012. '\u33E5': '\u0036\u65E5',
  14013. '\u33E6': '\u0037\u65E5',
  14014. '\u33E7': '\u0038\u65E5',
  14015. '\u33E8': '\u0039\u65E5',
  14016. '\u33E9': '\u0031\u0030\u65E5',
  14017. '\u33EA': '\u0031\u0031\u65E5',
  14018. '\u33EB': '\u0031\u0032\u65E5',
  14019. '\u33EC': '\u0031\u0033\u65E5',
  14020. '\u33ED': '\u0031\u0034\u65E5',
  14021. '\u33EE': '\u0031\u0035\u65E5',
  14022. '\u33EF': '\u0031\u0036\u65E5',
  14023. '\u33F0': '\u0031\u0037\u65E5',
  14024. '\u33F1': '\u0031\u0038\u65E5',
  14025. '\u33F2': '\u0031\u0039\u65E5',
  14026. '\u33F3': '\u0032\u0030\u65E5',
  14027. '\u33F4': '\u0032\u0031\u65E5',
  14028. '\u33F5': '\u0032\u0032\u65E5',
  14029. '\u33F6': '\u0032\u0033\u65E5',
  14030. '\u33F7': '\u0032\u0034\u65E5',
  14031. '\u33F8': '\u0032\u0035\u65E5',
  14032. '\u33F9': '\u0032\u0036\u65E5',
  14033. '\u33FA': '\u0032\u0037\u65E5',
  14034. '\u33FB': '\u0032\u0038\u65E5',
  14035. '\u33FC': '\u0032\u0039\u65E5',
  14036. '\u33FD': '\u0033\u0030\u65E5',
  14037. '\u33FE': '\u0033\u0031\u65E5',
  14038. '\uFB00': '\u0066\u0066',
  14039. '\uFB01': '\u0066\u0069',
  14040. '\uFB02': '\u0066\u006C',
  14041. '\uFB03': '\u0066\u0066\u0069',
  14042. '\uFB04': '\u0066\u0066\u006C',
  14043. '\uFB05': '\u017F\u0074',
  14044. '\uFB06': '\u0073\u0074',
  14045. '\uFB13': '\u0574\u0576',
  14046. '\uFB14': '\u0574\u0565',
  14047. '\uFB15': '\u0574\u056B',
  14048. '\uFB16': '\u057E\u0576',
  14049. '\uFB17': '\u0574\u056D',
  14050. '\uFB4F': '\u05D0\u05DC',
  14051. '\uFB50': '\u0671',
  14052. '\uFB51': '\u0671',
  14053. '\uFB52': '\u067B',
  14054. '\uFB53': '\u067B',
  14055. '\uFB54': '\u067B',
  14056. '\uFB55': '\u067B',
  14057. '\uFB56': '\u067E',
  14058. '\uFB57': '\u067E',
  14059. '\uFB58': '\u067E',
  14060. '\uFB59': '\u067E',
  14061. '\uFB5A': '\u0680',
  14062. '\uFB5B': '\u0680',
  14063. '\uFB5C': '\u0680',
  14064. '\uFB5D': '\u0680',
  14065. '\uFB5E': '\u067A',
  14066. '\uFB5F': '\u067A',
  14067. '\uFB60': '\u067A',
  14068. '\uFB61': '\u067A',
  14069. '\uFB62': '\u067F',
  14070. '\uFB63': '\u067F',
  14071. '\uFB64': '\u067F',
  14072. '\uFB65': '\u067F',
  14073. '\uFB66': '\u0679',
  14074. '\uFB67': '\u0679',
  14075. '\uFB68': '\u0679',
  14076. '\uFB69': '\u0679',
  14077. '\uFB6A': '\u06A4',
  14078. '\uFB6B': '\u06A4',
  14079. '\uFB6C': '\u06A4',
  14080. '\uFB6D': '\u06A4',
  14081. '\uFB6E': '\u06A6',
  14082. '\uFB6F': '\u06A6',
  14083. '\uFB70': '\u06A6',
  14084. '\uFB71': '\u06A6',
  14085. '\uFB72': '\u0684',
  14086. '\uFB73': '\u0684',
  14087. '\uFB74': '\u0684',
  14088. '\uFB75': '\u0684',
  14089. '\uFB76': '\u0683',
  14090. '\uFB77': '\u0683',
  14091. '\uFB78': '\u0683',
  14092. '\uFB79': '\u0683',
  14093. '\uFB7A': '\u0686',
  14094. '\uFB7B': '\u0686',
  14095. '\uFB7C': '\u0686',
  14096. '\uFB7D': '\u0686',
  14097. '\uFB7E': '\u0687',
  14098. '\uFB7F': '\u0687',
  14099. '\uFB80': '\u0687',
  14100. '\uFB81': '\u0687',
  14101. '\uFB82': '\u068D',
  14102. '\uFB83': '\u068D',
  14103. '\uFB84': '\u068C',
  14104. '\uFB85': '\u068C',
  14105. '\uFB86': '\u068E',
  14106. '\uFB87': '\u068E',
  14107. '\uFB88': '\u0688',
  14108. '\uFB89': '\u0688',
  14109. '\uFB8A': '\u0698',
  14110. '\uFB8B': '\u0698',
  14111. '\uFB8C': '\u0691',
  14112. '\uFB8D': '\u0691',
  14113. '\uFB8E': '\u06A9',
  14114. '\uFB8F': '\u06A9',
  14115. '\uFB90': '\u06A9',
  14116. '\uFB91': '\u06A9',
  14117. '\uFB92': '\u06AF',
  14118. '\uFB93': '\u06AF',
  14119. '\uFB94': '\u06AF',
  14120. '\uFB95': '\u06AF',
  14121. '\uFB96': '\u06B3',
  14122. '\uFB97': '\u06B3',
  14123. '\uFB98': '\u06B3',
  14124. '\uFB99': '\u06B3',
  14125. '\uFB9A': '\u06B1',
  14126. '\uFB9B': '\u06B1',
  14127. '\uFB9C': '\u06B1',
  14128. '\uFB9D': '\u06B1',
  14129. '\uFB9E': '\u06BA',
  14130. '\uFB9F': '\u06BA',
  14131. '\uFBA0': '\u06BB',
  14132. '\uFBA1': '\u06BB',
  14133. '\uFBA2': '\u06BB',
  14134. '\uFBA3': '\u06BB',
  14135. '\uFBA4': '\u06C0',
  14136. '\uFBA5': '\u06C0',
  14137. '\uFBA6': '\u06C1',
  14138. '\uFBA7': '\u06C1',
  14139. '\uFBA8': '\u06C1',
  14140. '\uFBA9': '\u06C1',
  14141. '\uFBAA': '\u06BE',
  14142. '\uFBAB': '\u06BE',
  14143. '\uFBAC': '\u06BE',
  14144. '\uFBAD': '\u06BE',
  14145. '\uFBAE': '\u06D2',
  14146. '\uFBAF': '\u06D2',
  14147. '\uFBB0': '\u06D3',
  14148. '\uFBB1': '\u06D3',
  14149. '\uFBD3': '\u06AD',
  14150. '\uFBD4': '\u06AD',
  14151. '\uFBD5': '\u06AD',
  14152. '\uFBD6': '\u06AD',
  14153. '\uFBD7': '\u06C7',
  14154. '\uFBD8': '\u06C7',
  14155. '\uFBD9': '\u06C6',
  14156. '\uFBDA': '\u06C6',
  14157. '\uFBDB': '\u06C8',
  14158. '\uFBDC': '\u06C8',
  14159. '\uFBDD': '\u0677',
  14160. '\uFBDE': '\u06CB',
  14161. '\uFBDF': '\u06CB',
  14162. '\uFBE0': '\u06C5',
  14163. '\uFBE1': '\u06C5',
  14164. '\uFBE2': '\u06C9',
  14165. '\uFBE3': '\u06C9',
  14166. '\uFBE4': '\u06D0',
  14167. '\uFBE5': '\u06D0',
  14168. '\uFBE6': '\u06D0',
  14169. '\uFBE7': '\u06D0',
  14170. '\uFBE8': '\u0649',
  14171. '\uFBE9': '\u0649',
  14172. '\uFBEA': '\u0626\u0627',
  14173. '\uFBEB': '\u0626\u0627',
  14174. '\uFBEC': '\u0626\u06D5',
  14175. '\uFBED': '\u0626\u06D5',
  14176. '\uFBEE': '\u0626\u0648',
  14177. '\uFBEF': '\u0626\u0648',
  14178. '\uFBF0': '\u0626\u06C7',
  14179. '\uFBF1': '\u0626\u06C7',
  14180. '\uFBF2': '\u0626\u06C6',
  14181. '\uFBF3': '\u0626\u06C6',
  14182. '\uFBF4': '\u0626\u06C8',
  14183. '\uFBF5': '\u0626\u06C8',
  14184. '\uFBF6': '\u0626\u06D0',
  14185. '\uFBF7': '\u0626\u06D0',
  14186. '\uFBF8': '\u0626\u06D0',
  14187. '\uFBF9': '\u0626\u0649',
  14188. '\uFBFA': '\u0626\u0649',
  14189. '\uFBFB': '\u0626\u0649',
  14190. '\uFBFC': '\u06CC',
  14191. '\uFBFD': '\u06CC',
  14192. '\uFBFE': '\u06CC',
  14193. '\uFBFF': '\u06CC',
  14194. '\uFC00': '\u0626\u062C',
  14195. '\uFC01': '\u0626\u062D',
  14196. '\uFC02': '\u0626\u0645',
  14197. '\uFC03': '\u0626\u0649',
  14198. '\uFC04': '\u0626\u064A',
  14199. '\uFC05': '\u0628\u062C',
  14200. '\uFC06': '\u0628\u062D',
  14201. '\uFC07': '\u0628\u062E',
  14202. '\uFC08': '\u0628\u0645',
  14203. '\uFC09': '\u0628\u0649',
  14204. '\uFC0A': '\u0628\u064A',
  14205. '\uFC0B': '\u062A\u062C',
  14206. '\uFC0C': '\u062A\u062D',
  14207. '\uFC0D': '\u062A\u062E',
  14208. '\uFC0E': '\u062A\u0645',
  14209. '\uFC0F': '\u062A\u0649',
  14210. '\uFC10': '\u062A\u064A',
  14211. '\uFC11': '\u062B\u062C',
  14212. '\uFC12': '\u062B\u0645',
  14213. '\uFC13': '\u062B\u0649',
  14214. '\uFC14': '\u062B\u064A',
  14215. '\uFC15': '\u062C\u062D',
  14216. '\uFC16': '\u062C\u0645',
  14217. '\uFC17': '\u062D\u062C',
  14218. '\uFC18': '\u062D\u0645',
  14219. '\uFC19': '\u062E\u062C',
  14220. '\uFC1A': '\u062E\u062D',
  14221. '\uFC1B': '\u062E\u0645',
  14222. '\uFC1C': '\u0633\u062C',
  14223. '\uFC1D': '\u0633\u062D',
  14224. '\uFC1E': '\u0633\u062E',
  14225. '\uFC1F': '\u0633\u0645',
  14226. '\uFC20': '\u0635\u062D',
  14227. '\uFC21': '\u0635\u0645',
  14228. '\uFC22': '\u0636\u062C',
  14229. '\uFC23': '\u0636\u062D',
  14230. '\uFC24': '\u0636\u062E',
  14231. '\uFC25': '\u0636\u0645',
  14232. '\uFC26': '\u0637\u062D',
  14233. '\uFC27': '\u0637\u0645',
  14234. '\uFC28': '\u0638\u0645',
  14235. '\uFC29': '\u0639\u062C',
  14236. '\uFC2A': '\u0639\u0645',
  14237. '\uFC2B': '\u063A\u062C',
  14238. '\uFC2C': '\u063A\u0645',
  14239. '\uFC2D': '\u0641\u062C',
  14240. '\uFC2E': '\u0641\u062D',
  14241. '\uFC2F': '\u0641\u062E',
  14242. '\uFC30': '\u0641\u0645',
  14243. '\uFC31': '\u0641\u0649',
  14244. '\uFC32': '\u0641\u064A',
  14245. '\uFC33': '\u0642\u062D',
  14246. '\uFC34': '\u0642\u0645',
  14247. '\uFC35': '\u0642\u0649',
  14248. '\uFC36': '\u0642\u064A',
  14249. '\uFC37': '\u0643\u0627',
  14250. '\uFC38': '\u0643\u062C',
  14251. '\uFC39': '\u0643\u062D',
  14252. '\uFC3A': '\u0643\u062E',
  14253. '\uFC3B': '\u0643\u0644',
  14254. '\uFC3C': '\u0643\u0645',
  14255. '\uFC3D': '\u0643\u0649',
  14256. '\uFC3E': '\u0643\u064A',
  14257. '\uFC3F': '\u0644\u062C',
  14258. '\uFC40': '\u0644\u062D',
  14259. '\uFC41': '\u0644\u062E',
  14260. '\uFC42': '\u0644\u0645',
  14261. '\uFC43': '\u0644\u0649',
  14262. '\uFC44': '\u0644\u064A',
  14263. '\uFC45': '\u0645\u062C',
  14264. '\uFC46': '\u0645\u062D',
  14265. '\uFC47': '\u0645\u062E',
  14266. '\uFC48': '\u0645\u0645',
  14267. '\uFC49': '\u0645\u0649',
  14268. '\uFC4A': '\u0645\u064A',
  14269. '\uFC4B': '\u0646\u062C',
  14270. '\uFC4C': '\u0646\u062D',
  14271. '\uFC4D': '\u0646\u062E',
  14272. '\uFC4E': '\u0646\u0645',
  14273. '\uFC4F': '\u0646\u0649',
  14274. '\uFC50': '\u0646\u064A',
  14275. '\uFC51': '\u0647\u062C',
  14276. '\uFC52': '\u0647\u0645',
  14277. '\uFC53': '\u0647\u0649',
  14278. '\uFC54': '\u0647\u064A',
  14279. '\uFC55': '\u064A\u062C',
  14280. '\uFC56': '\u064A\u062D',
  14281. '\uFC57': '\u064A\u062E',
  14282. '\uFC58': '\u064A\u0645',
  14283. '\uFC59': '\u064A\u0649',
  14284. '\uFC5A': '\u064A\u064A',
  14285. '\uFC5B': '\u0630\u0670',
  14286. '\uFC5C': '\u0631\u0670',
  14287. '\uFC5D': '\u0649\u0670',
  14288. '\uFC5E': '\u0020\u064C\u0651',
  14289. '\uFC5F': '\u0020\u064D\u0651',
  14290. '\uFC60': '\u0020\u064E\u0651',
  14291. '\uFC61': '\u0020\u064F\u0651',
  14292. '\uFC62': '\u0020\u0650\u0651',
  14293. '\uFC63': '\u0020\u0651\u0670',
  14294. '\uFC64': '\u0626\u0631',
  14295. '\uFC65': '\u0626\u0632',
  14296. '\uFC66': '\u0626\u0645',
  14297. '\uFC67': '\u0626\u0646',
  14298. '\uFC68': '\u0626\u0649',
  14299. '\uFC69': '\u0626\u064A',
  14300. '\uFC6A': '\u0628\u0631',
  14301. '\uFC6B': '\u0628\u0632',
  14302. '\uFC6C': '\u0628\u0645',
  14303. '\uFC6D': '\u0628\u0646',
  14304. '\uFC6E': '\u0628\u0649',
  14305. '\uFC6F': '\u0628\u064A',
  14306. '\uFC70': '\u062A\u0631',
  14307. '\uFC71': '\u062A\u0632',
  14308. '\uFC72': '\u062A\u0645',
  14309. '\uFC73': '\u062A\u0646',
  14310. '\uFC74': '\u062A\u0649',
  14311. '\uFC75': '\u062A\u064A',
  14312. '\uFC76': '\u062B\u0631',
  14313. '\uFC77': '\u062B\u0632',
  14314. '\uFC78': '\u062B\u0645',
  14315. '\uFC79': '\u062B\u0646',
  14316. '\uFC7A': '\u062B\u0649',
  14317. '\uFC7B': '\u062B\u064A',
  14318. '\uFC7C': '\u0641\u0649',
  14319. '\uFC7D': '\u0641\u064A',
  14320. '\uFC7E': '\u0642\u0649',
  14321. '\uFC7F': '\u0642\u064A',
  14322. '\uFC80': '\u0643\u0627',
  14323. '\uFC81': '\u0643\u0644',
  14324. '\uFC82': '\u0643\u0645',
  14325. '\uFC83': '\u0643\u0649',
  14326. '\uFC84': '\u0643\u064A',
  14327. '\uFC85': '\u0644\u0645',
  14328. '\uFC86': '\u0644\u0649',
  14329. '\uFC87': '\u0644\u064A',
  14330. '\uFC88': '\u0645\u0627',
  14331. '\uFC89': '\u0645\u0645',
  14332. '\uFC8A': '\u0646\u0631',
  14333. '\uFC8B': '\u0646\u0632',
  14334. '\uFC8C': '\u0646\u0645',
  14335. '\uFC8D': '\u0646\u0646',
  14336. '\uFC8E': '\u0646\u0649',
  14337. '\uFC8F': '\u0646\u064A',
  14338. '\uFC90': '\u0649\u0670',
  14339. '\uFC91': '\u064A\u0631',
  14340. '\uFC92': '\u064A\u0632',
  14341. '\uFC93': '\u064A\u0645',
  14342. '\uFC94': '\u064A\u0646',
  14343. '\uFC95': '\u064A\u0649',
  14344. '\uFC96': '\u064A\u064A',
  14345. '\uFC97': '\u0626\u062C',
  14346. '\uFC98': '\u0626\u062D',
  14347. '\uFC99': '\u0626\u062E',
  14348. '\uFC9A': '\u0626\u0645',
  14349. '\uFC9B': '\u0626\u0647',
  14350. '\uFC9C': '\u0628\u062C',
  14351. '\uFC9D': '\u0628\u062D',
  14352. '\uFC9E': '\u0628\u062E',
  14353. '\uFC9F': '\u0628\u0645',
  14354. '\uFCA0': '\u0628\u0647',
  14355. '\uFCA1': '\u062A\u062C',
  14356. '\uFCA2': '\u062A\u062D',
  14357. '\uFCA3': '\u062A\u062E',
  14358. '\uFCA4': '\u062A\u0645',
  14359. '\uFCA5': '\u062A\u0647',
  14360. '\uFCA6': '\u062B\u0645',
  14361. '\uFCA7': '\u062C\u062D',
  14362. '\uFCA8': '\u062C\u0645',
  14363. '\uFCA9': '\u062D\u062C',
  14364. '\uFCAA': '\u062D\u0645',
  14365. '\uFCAB': '\u062E\u062C',
  14366. '\uFCAC': '\u062E\u0645',
  14367. '\uFCAD': '\u0633\u062C',
  14368. '\uFCAE': '\u0633\u062D',
  14369. '\uFCAF': '\u0633\u062E',
  14370. '\uFCB0': '\u0633\u0645',
  14371. '\uFCB1': '\u0635\u062D',
  14372. '\uFCB2': '\u0635\u062E',
  14373. '\uFCB3': '\u0635\u0645',
  14374. '\uFCB4': '\u0636\u062C',
  14375. '\uFCB5': '\u0636\u062D',
  14376. '\uFCB6': '\u0636\u062E',
  14377. '\uFCB7': '\u0636\u0645',
  14378. '\uFCB8': '\u0637\u062D',
  14379. '\uFCB9': '\u0638\u0645',
  14380. '\uFCBA': '\u0639\u062C',
  14381. '\uFCBB': '\u0639\u0645',
  14382. '\uFCBC': '\u063A\u062C',
  14383. '\uFCBD': '\u063A\u0645',
  14384. '\uFCBE': '\u0641\u062C',
  14385. '\uFCBF': '\u0641\u062D',
  14386. '\uFCC0': '\u0641\u062E',
  14387. '\uFCC1': '\u0641\u0645',
  14388. '\uFCC2': '\u0642\u062D',
  14389. '\uFCC3': '\u0642\u0645',
  14390. '\uFCC4': '\u0643\u062C',
  14391. '\uFCC5': '\u0643\u062D',
  14392. '\uFCC6': '\u0643\u062E',
  14393. '\uFCC7': '\u0643\u0644',
  14394. '\uFCC8': '\u0643\u0645',
  14395. '\uFCC9': '\u0644\u062C',
  14396. '\uFCCA': '\u0644\u062D',
  14397. '\uFCCB': '\u0644\u062E',
  14398. '\uFCCC': '\u0644\u0645',
  14399. '\uFCCD': '\u0644\u0647',
  14400. '\uFCCE': '\u0645\u062C',
  14401. '\uFCCF': '\u0645\u062D',
  14402. '\uFCD0': '\u0645\u062E',
  14403. '\uFCD1': '\u0645\u0645',
  14404. '\uFCD2': '\u0646\u062C',
  14405. '\uFCD3': '\u0646\u062D',
  14406. '\uFCD4': '\u0646\u062E',
  14407. '\uFCD5': '\u0646\u0645',
  14408. '\uFCD6': '\u0646\u0647',
  14409. '\uFCD7': '\u0647\u062C',
  14410. '\uFCD8': '\u0647\u0645',
  14411. '\uFCD9': '\u0647\u0670',
  14412. '\uFCDA': '\u064A\u062C',
  14413. '\uFCDB': '\u064A\u062D',
  14414. '\uFCDC': '\u064A\u062E',
  14415. '\uFCDD': '\u064A\u0645',
  14416. '\uFCDE': '\u064A\u0647',
  14417. '\uFCDF': '\u0626\u0645',
  14418. '\uFCE0': '\u0626\u0647',
  14419. '\uFCE1': '\u0628\u0645',
  14420. '\uFCE2': '\u0628\u0647',
  14421. '\uFCE3': '\u062A\u0645',
  14422. '\uFCE4': '\u062A\u0647',
  14423. '\uFCE5': '\u062B\u0645',
  14424. '\uFCE6': '\u062B\u0647',
  14425. '\uFCE7': '\u0633\u0645',
  14426. '\uFCE8': '\u0633\u0647',
  14427. '\uFCE9': '\u0634\u0645',
  14428. '\uFCEA': '\u0634\u0647',
  14429. '\uFCEB': '\u0643\u0644',
  14430. '\uFCEC': '\u0643\u0645',
  14431. '\uFCED': '\u0644\u0645',
  14432. '\uFCEE': '\u0646\u0645',
  14433. '\uFCEF': '\u0646\u0647',
  14434. '\uFCF0': '\u064A\u0645',
  14435. '\uFCF1': '\u064A\u0647',
  14436. '\uFCF2': '\u0640\u064E\u0651',
  14437. '\uFCF3': '\u0640\u064F\u0651',
  14438. '\uFCF4': '\u0640\u0650\u0651',
  14439. '\uFCF5': '\u0637\u0649',
  14440. '\uFCF6': '\u0637\u064A',
  14441. '\uFCF7': '\u0639\u0649',
  14442. '\uFCF8': '\u0639\u064A',
  14443. '\uFCF9': '\u063A\u0649',
  14444. '\uFCFA': '\u063A\u064A',
  14445. '\uFCFB': '\u0633\u0649',
  14446. '\uFCFC': '\u0633\u064A',
  14447. '\uFCFD': '\u0634\u0649',
  14448. '\uFCFE': '\u0634\u064A',
  14449. '\uFCFF': '\u062D\u0649',
  14450. '\uFD00': '\u062D\u064A',
  14451. '\uFD01': '\u062C\u0649',
  14452. '\uFD02': '\u062C\u064A',
  14453. '\uFD03': '\u062E\u0649',
  14454. '\uFD04': '\u062E\u064A',
  14455. '\uFD05': '\u0635\u0649',
  14456. '\uFD06': '\u0635\u064A',
  14457. '\uFD07': '\u0636\u0649',
  14458. '\uFD08': '\u0636\u064A',
  14459. '\uFD09': '\u0634\u062C',
  14460. '\uFD0A': '\u0634\u062D',
  14461. '\uFD0B': '\u0634\u062E',
  14462. '\uFD0C': '\u0634\u0645',
  14463. '\uFD0D': '\u0634\u0631',
  14464. '\uFD0E': '\u0633\u0631',
  14465. '\uFD0F': '\u0635\u0631',
  14466. '\uFD10': '\u0636\u0631',
  14467. '\uFD11': '\u0637\u0649',
  14468. '\uFD12': '\u0637\u064A',
  14469. '\uFD13': '\u0639\u0649',
  14470. '\uFD14': '\u0639\u064A',
  14471. '\uFD15': '\u063A\u0649',
  14472. '\uFD16': '\u063A\u064A',
  14473. '\uFD17': '\u0633\u0649',
  14474. '\uFD18': '\u0633\u064A',
  14475. '\uFD19': '\u0634\u0649',
  14476. '\uFD1A': '\u0634\u064A',
  14477. '\uFD1B': '\u062D\u0649',
  14478. '\uFD1C': '\u062D\u064A',
  14479. '\uFD1D': '\u062C\u0649',
  14480. '\uFD1E': '\u062C\u064A',
  14481. '\uFD1F': '\u062E\u0649',
  14482. '\uFD20': '\u062E\u064A',
  14483. '\uFD21': '\u0635\u0649',
  14484. '\uFD22': '\u0635\u064A',
  14485. '\uFD23': '\u0636\u0649',
  14486. '\uFD24': '\u0636\u064A',
  14487. '\uFD25': '\u0634\u062C',
  14488. '\uFD26': '\u0634\u062D',
  14489. '\uFD27': '\u0634\u062E',
  14490. '\uFD28': '\u0634\u0645',
  14491. '\uFD29': '\u0634\u0631',
  14492. '\uFD2A': '\u0633\u0631',
  14493. '\uFD2B': '\u0635\u0631',
  14494. '\uFD2C': '\u0636\u0631',
  14495. '\uFD2D': '\u0634\u062C',
  14496. '\uFD2E': '\u0634\u062D',
  14497. '\uFD2F': '\u0634\u062E',
  14498. '\uFD30': '\u0634\u0645',
  14499. '\uFD31': '\u0633\u0647',
  14500. '\uFD32': '\u0634\u0647',
  14501. '\uFD33': '\u0637\u0645',
  14502. '\uFD34': '\u0633\u062C',
  14503. '\uFD35': '\u0633\u062D',
  14504. '\uFD36': '\u0633\u062E',
  14505. '\uFD37': '\u0634\u062C',
  14506. '\uFD38': '\u0634\u062D',
  14507. '\uFD39': '\u0634\u062E',
  14508. '\uFD3A': '\u0637\u0645',
  14509. '\uFD3B': '\u0638\u0645',
  14510. '\uFD3C': '\u0627\u064B',
  14511. '\uFD3D': '\u0627\u064B',
  14512. '\uFD50': '\u062A\u062C\u0645',
  14513. '\uFD51': '\u062A\u062D\u062C',
  14514. '\uFD52': '\u062A\u062D\u062C',
  14515. '\uFD53': '\u062A\u062D\u0645',
  14516. '\uFD54': '\u062A\u062E\u0645',
  14517. '\uFD55': '\u062A\u0645\u062C',
  14518. '\uFD56': '\u062A\u0645\u062D',
  14519. '\uFD57': '\u062A\u0645\u062E',
  14520. '\uFD58': '\u062C\u0645\u062D',
  14521. '\uFD59': '\u062C\u0645\u062D',
  14522. '\uFD5A': '\u062D\u0645\u064A',
  14523. '\uFD5B': '\u062D\u0645\u0649',
  14524. '\uFD5C': '\u0633\u062D\u062C',
  14525. '\uFD5D': '\u0633\u062C\u062D',
  14526. '\uFD5E': '\u0633\u062C\u0649',
  14527. '\uFD5F': '\u0633\u0645\u062D',
  14528. '\uFD60': '\u0633\u0645\u062D',
  14529. '\uFD61': '\u0633\u0645\u062C',
  14530. '\uFD62': '\u0633\u0645\u0645',
  14531. '\uFD63': '\u0633\u0645\u0645',
  14532. '\uFD64': '\u0635\u062D\u062D',
  14533. '\uFD65': '\u0635\u062D\u062D',
  14534. '\uFD66': '\u0635\u0645\u0645',
  14535. '\uFD67': '\u0634\u062D\u0645',
  14536. '\uFD68': '\u0634\u062D\u0645',
  14537. '\uFD69': '\u0634\u062C\u064A',
  14538. '\uFD6A': '\u0634\u0645\u062E',
  14539. '\uFD6B': '\u0634\u0645\u062E',
  14540. '\uFD6C': '\u0634\u0645\u0645',
  14541. '\uFD6D': '\u0634\u0645\u0645',
  14542. '\uFD6E': '\u0636\u062D\u0649',
  14543. '\uFD6F': '\u0636\u062E\u0645',
  14544. '\uFD70': '\u0636\u062E\u0645',
  14545. '\uFD71': '\u0637\u0645\u062D',
  14546. '\uFD72': '\u0637\u0645\u062D',
  14547. '\uFD73': '\u0637\u0645\u0645',
  14548. '\uFD74': '\u0637\u0645\u064A',
  14549. '\uFD75': '\u0639\u062C\u0645',
  14550. '\uFD76': '\u0639\u0645\u0645',
  14551. '\uFD77': '\u0639\u0645\u0645',
  14552. '\uFD78': '\u0639\u0645\u0649',
  14553. '\uFD79': '\u063A\u0645\u0645',
  14554. '\uFD7A': '\u063A\u0645\u064A',
  14555. '\uFD7B': '\u063A\u0645\u0649',
  14556. '\uFD7C': '\u0641\u062E\u0645',
  14557. '\uFD7D': '\u0641\u062E\u0645',
  14558. '\uFD7E': '\u0642\u0645\u062D',
  14559. '\uFD7F': '\u0642\u0645\u0645',
  14560. '\uFD80': '\u0644\u062D\u0645',
  14561. '\uFD81': '\u0644\u062D\u064A',
  14562. '\uFD82': '\u0644\u062D\u0649',
  14563. '\uFD83': '\u0644\u062C\u062C',
  14564. '\uFD84': '\u0644\u062C\u062C',
  14565. '\uFD85': '\u0644\u062E\u0645',
  14566. '\uFD86': '\u0644\u062E\u0645',
  14567. '\uFD87': '\u0644\u0645\u062D',
  14568. '\uFD88': '\u0644\u0645\u062D',
  14569. '\uFD89': '\u0645\u062D\u062C',
  14570. '\uFD8A': '\u0645\u062D\u0645',
  14571. '\uFD8B': '\u0645\u062D\u064A',
  14572. '\uFD8C': '\u0645\u062C\u062D',
  14573. '\uFD8D': '\u0645\u062C\u0645',
  14574. '\uFD8E': '\u0645\u062E\u062C',
  14575. '\uFD8F': '\u0645\u062E\u0645',
  14576. '\uFD92': '\u0645\u062C\u062E',
  14577. '\uFD93': '\u0647\u0645\u062C',
  14578. '\uFD94': '\u0647\u0645\u0645',
  14579. '\uFD95': '\u0646\u062D\u0645',
  14580. '\uFD96': '\u0646\u062D\u0649',
  14581. '\uFD97': '\u0646\u062C\u0645',
  14582. '\uFD98': '\u0646\u062C\u0645',
  14583. '\uFD99': '\u0646\u062C\u0649',
  14584. '\uFD9A': '\u0646\u0645\u064A',
  14585. '\uFD9B': '\u0646\u0645\u0649',
  14586. '\uFD9C': '\u064A\u0645\u0645',
  14587. '\uFD9D': '\u064A\u0645\u0645',
  14588. '\uFD9E': '\u0628\u062E\u064A',
  14589. '\uFD9F': '\u062A\u062C\u064A',
  14590. '\uFDA0': '\u062A\u062C\u0649',
  14591. '\uFDA1': '\u062A\u062E\u064A',
  14592. '\uFDA2': '\u062A\u062E\u0649',
  14593. '\uFDA3': '\u062A\u0645\u064A',
  14594. '\uFDA4': '\u062A\u0645\u0649',
  14595. '\uFDA5': '\u062C\u0645\u064A',
  14596. '\uFDA6': '\u062C\u062D\u0649',
  14597. '\uFDA7': '\u062C\u0645\u0649',
  14598. '\uFDA8': '\u0633\u062E\u0649',
  14599. '\uFDA9': '\u0635\u062D\u064A',
  14600. '\uFDAA': '\u0634\u062D\u064A',
  14601. '\uFDAB': '\u0636\u062D\u064A',
  14602. '\uFDAC': '\u0644\u062C\u064A',
  14603. '\uFDAD': '\u0644\u0645\u064A',
  14604. '\uFDAE': '\u064A\u062D\u064A',
  14605. '\uFDAF': '\u064A\u062C\u064A',
  14606. '\uFDB0': '\u064A\u0645\u064A',
  14607. '\uFDB1': '\u0645\u0645\u064A',
  14608. '\uFDB2': '\u0642\u0645\u064A',
  14609. '\uFDB3': '\u0646\u062D\u064A',
  14610. '\uFDB4': '\u0642\u0645\u062D',
  14611. '\uFDB5': '\u0644\u062D\u0645',
  14612. '\uFDB6': '\u0639\u0645\u064A',
  14613. '\uFDB7': '\u0643\u0645\u064A',
  14614. '\uFDB8': '\u0646\u062C\u062D',
  14615. '\uFDB9': '\u0645\u062E\u064A',
  14616. '\uFDBA': '\u0644\u062C\u0645',
  14617. '\uFDBB': '\u0643\u0645\u0645',
  14618. '\uFDBC': '\u0644\u062C\u0645',
  14619. '\uFDBD': '\u0646\u062C\u062D',
  14620. '\uFDBE': '\u062C\u062D\u064A',
  14621. '\uFDBF': '\u062D\u062C\u064A',
  14622. '\uFDC0': '\u0645\u062C\u064A',
  14623. '\uFDC1': '\u0641\u0645\u064A',
  14624. '\uFDC2': '\u0628\u062D\u064A',
  14625. '\uFDC3': '\u0643\u0645\u0645',
  14626. '\uFDC4': '\u0639\u062C\u0645',
  14627. '\uFDC5': '\u0635\u0645\u0645',
  14628. '\uFDC6': '\u0633\u062E\u064A',
  14629. '\uFDC7': '\u0646\u062C\u064A',
  14630. '\uFE49': '\u203E',
  14631. '\uFE4A': '\u203E',
  14632. '\uFE4B': '\u203E',
  14633. '\uFE4C': '\u203E',
  14634. '\uFE4D': '\u005F',
  14635. '\uFE4E': '\u005F',
  14636. '\uFE4F': '\u005F',
  14637. '\uFE80': '\u0621',
  14638. '\uFE81': '\u0622',
  14639. '\uFE82': '\u0622',
  14640. '\uFE83': '\u0623',
  14641. '\uFE84': '\u0623',
  14642. '\uFE85': '\u0624',
  14643. '\uFE86': '\u0624',
  14644. '\uFE87': '\u0625',
  14645. '\uFE88': '\u0625',
  14646. '\uFE89': '\u0626',
  14647. '\uFE8A': '\u0626',
  14648. '\uFE8B': '\u0626',
  14649. '\uFE8C': '\u0626',
  14650. '\uFE8D': '\u0627',
  14651. '\uFE8E': '\u0627',
  14652. '\uFE8F': '\u0628',
  14653. '\uFE90': '\u0628',
  14654. '\uFE91': '\u0628',
  14655. '\uFE92': '\u0628',
  14656. '\uFE93': '\u0629',
  14657. '\uFE94': '\u0629',
  14658. '\uFE95': '\u062A',
  14659. '\uFE96': '\u062A',
  14660. '\uFE97': '\u062A',
  14661. '\uFE98': '\u062A',
  14662. '\uFE99': '\u062B',
  14663. '\uFE9A': '\u062B',
  14664. '\uFE9B': '\u062B',
  14665. '\uFE9C': '\u062B',
  14666. '\uFE9D': '\u062C',
  14667. '\uFE9E': '\u062C',
  14668. '\uFE9F': '\u062C',
  14669. '\uFEA0': '\u062C',
  14670. '\uFEA1': '\u062D',
  14671. '\uFEA2': '\u062D',
  14672. '\uFEA3': '\u062D',
  14673. '\uFEA4': '\u062D',
  14674. '\uFEA5': '\u062E',
  14675. '\uFEA6': '\u062E',
  14676. '\uFEA7': '\u062E',
  14677. '\uFEA8': '\u062E',
  14678. '\uFEA9': '\u062F',
  14679. '\uFEAA': '\u062F',
  14680. '\uFEAB': '\u0630',
  14681. '\uFEAC': '\u0630',
  14682. '\uFEAD': '\u0631',
  14683. '\uFEAE': '\u0631',
  14684. '\uFEAF': '\u0632',
  14685. '\uFEB0': '\u0632',
  14686. '\uFEB1': '\u0633',
  14687. '\uFEB2': '\u0633',
  14688. '\uFEB3': '\u0633',
  14689. '\uFEB4': '\u0633',
  14690. '\uFEB5': '\u0634',
  14691. '\uFEB6': '\u0634',
  14692. '\uFEB7': '\u0634',
  14693. '\uFEB8': '\u0634',
  14694. '\uFEB9': '\u0635',
  14695. '\uFEBA': '\u0635',
  14696. '\uFEBB': '\u0635',
  14697. '\uFEBC': '\u0635',
  14698. '\uFEBD': '\u0636',
  14699. '\uFEBE': '\u0636',
  14700. '\uFEBF': '\u0636',
  14701. '\uFEC0': '\u0636',
  14702. '\uFEC1': '\u0637',
  14703. '\uFEC2': '\u0637',
  14704. '\uFEC3': '\u0637',
  14705. '\uFEC4': '\u0637',
  14706. '\uFEC5': '\u0638',
  14707. '\uFEC6': '\u0638',
  14708. '\uFEC7': '\u0638',
  14709. '\uFEC8': '\u0638',
  14710. '\uFEC9': '\u0639',
  14711. '\uFECA': '\u0639',
  14712. '\uFECB': '\u0639',
  14713. '\uFECC': '\u0639',
  14714. '\uFECD': '\u063A',
  14715. '\uFECE': '\u063A',
  14716. '\uFECF': '\u063A',
  14717. '\uFED0': '\u063A',
  14718. '\uFED1': '\u0641',
  14719. '\uFED2': '\u0641',
  14720. '\uFED3': '\u0641',
  14721. '\uFED4': '\u0641',
  14722. '\uFED5': '\u0642',
  14723. '\uFED6': '\u0642',
  14724. '\uFED7': '\u0642',
  14725. '\uFED8': '\u0642',
  14726. '\uFED9': '\u0643',
  14727. '\uFEDA': '\u0643',
  14728. '\uFEDB': '\u0643',
  14729. '\uFEDC': '\u0643',
  14730. '\uFEDD': '\u0644',
  14731. '\uFEDE': '\u0644',
  14732. '\uFEDF': '\u0644',
  14733. '\uFEE0': '\u0644',
  14734. '\uFEE1': '\u0645',
  14735. '\uFEE2': '\u0645',
  14736. '\uFEE3': '\u0645',
  14737. '\uFEE4': '\u0645',
  14738. '\uFEE5': '\u0646',
  14739. '\uFEE6': '\u0646',
  14740. '\uFEE7': '\u0646',
  14741. '\uFEE8': '\u0646',
  14742. '\uFEE9': '\u0647',
  14743. '\uFEEA': '\u0647',
  14744. '\uFEEB': '\u0647',
  14745. '\uFEEC': '\u0647',
  14746. '\uFEED': '\u0648',
  14747. '\uFEEE': '\u0648',
  14748. '\uFEEF': '\u0649',
  14749. '\uFEF0': '\u0649',
  14750. '\uFEF1': '\u064A',
  14751. '\uFEF2': '\u064A',
  14752. '\uFEF3': '\u064A',
  14753. '\uFEF4': '\u064A',
  14754. '\uFEF5': '\u0644\u0622',
  14755. '\uFEF6': '\u0644\u0622',
  14756. '\uFEF7': '\u0644\u0623',
  14757. '\uFEF8': '\u0644\u0623',
  14758. '\uFEF9': '\u0644\u0625',
  14759. '\uFEFA': '\u0644\u0625',
  14760. '\uFEFB': '\u0644\u0627',
  14761. '\uFEFC': '\u0644\u0627'
  14762. };
  14763. function reverseIfRtl(chars) {
  14764. var charsLength = chars.length;
  14765. //reverse an arabic ligature
  14766. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14767. return chars;
  14768. }
  14769. var s = '';
  14770. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14771. s += chars[ii];
  14772. }
  14773. return s;
  14774. }
  14775. function adjustWidths(properties) {
  14776. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14777. return;
  14778. }
  14779. // adjusting width to fontMatrix scale
  14780. var scale = 0.001 / properties.fontMatrix[0];
  14781. var glyphsWidths = properties.widths;
  14782. for (var glyph in glyphsWidths) {
  14783. glyphsWidths[glyph] *= scale;
  14784. }
  14785. properties.defaultWidth *= scale;
  14786. }
  14787. function getFontType(type, subtype) {
  14788. switch (type) {
  14789. case 'Type1':
  14790. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14791. case 'CIDFontType0':
  14792. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14793. FontType.CIDFONTTYPE0;
  14794. case 'OpenType':
  14795. return FontType.OPENTYPE;
  14796. case 'TrueType':
  14797. return FontType.TRUETYPE;
  14798. case 'CIDFontType2':
  14799. return FontType.CIDFONTTYPE2;
  14800. case 'MMType1':
  14801. return FontType.MMTYPE1;
  14802. case 'Type0':
  14803. return FontType.TYPE0;
  14804. default:
  14805. return FontType.UNKNOWN;
  14806. }
  14807. }
  14808. var Glyph = (function GlyphClosure() {
  14809. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14810. this.fontChar = fontChar;
  14811. this.unicode = unicode;
  14812. this.accent = accent;
  14813. this.width = width;
  14814. this.vmetric = vmetric;
  14815. this.operatorListId = operatorListId;
  14816. }
  14817. Glyph.prototype.matchesForCache =
  14818. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14819. return this.fontChar === fontChar &&
  14820. this.unicode === unicode &&
  14821. this.accent === accent &&
  14822. this.width === width &&
  14823. this.vmetric === vmetric &&
  14824. this.operatorListId === operatorListId;
  14825. };
  14826. return Glyph;
  14827. })();
  14828. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14829. function ToUnicodeMap(cmap) {
  14830. // The elements of this._map can be integers or strings, depending on how
  14831. // |cmap| was created.
  14832. this._map = cmap;
  14833. }
  14834. ToUnicodeMap.prototype = {
  14835. get length() {
  14836. return this._map.length;
  14837. },
  14838. forEach: function(callback) {
  14839. for (var charCode in this._map) {
  14840. callback(charCode, this._map[charCode].charCodeAt(0));
  14841. }
  14842. },
  14843. get: function(i) {
  14844. return this._map[i];
  14845. },
  14846. charCodeOf: function(v) {
  14847. return this._map.indexOf(v);
  14848. }
  14849. };
  14850. return ToUnicodeMap;
  14851. })();
  14852. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14853. function IdentityToUnicodeMap(firstChar, lastChar) {
  14854. this.firstChar = firstChar;
  14855. this.lastChar = lastChar;
  14856. }
  14857. IdentityToUnicodeMap.prototype = {
  14858. get length() {
  14859. error('should not access .length');
  14860. },
  14861. forEach: function (callback) {
  14862. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  14863. callback(i, i);
  14864. }
  14865. },
  14866. get: function (i) {
  14867. if (this.firstChar <= i && i <= this.lastChar) {
  14868. return String.fromCharCode(i);
  14869. }
  14870. return undefined;
  14871. },
  14872. charCodeOf: function (v) {
  14873. error('should not call .charCodeOf');
  14874. }
  14875. };
  14876. return IdentityToUnicodeMap;
  14877. })();
  14878. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  14879. function writeInt16(dest, offset, num) {
  14880. dest[offset] = (num >> 8) & 0xFF;
  14881. dest[offset + 1] = num & 0xFF;
  14882. }
  14883. function writeInt32(dest, offset, num) {
  14884. dest[offset] = (num >> 24) & 0xFF;
  14885. dest[offset + 1] = (num >> 16) & 0xFF;
  14886. dest[offset + 2] = (num >> 8) & 0xFF;
  14887. dest[offset + 3] = num & 0xFF;
  14888. }
  14889. function writeData(dest, offset, data) {
  14890. var i, ii;
  14891. if (data instanceof Uint8Array) {
  14892. dest.set(data, offset);
  14893. } else if (typeof data === 'string') {
  14894. for (i = 0, ii = data.length; i < ii; i++) {
  14895. dest[offset++] = data.charCodeAt(i) & 0xFF;
  14896. }
  14897. } else {
  14898. // treating everything else as array
  14899. for (i = 0, ii = data.length; i < ii; i++) {
  14900. dest[offset++] = data[i] & 0xFF;
  14901. }
  14902. }
  14903. }
  14904. function OpenTypeFileBuilder(sfnt) {
  14905. this.sfnt = sfnt;
  14906. this.tables = Object.create(null);
  14907. }
  14908. OpenTypeFileBuilder.getSearchParams =
  14909. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  14910. var maxPower2 = 1, log2 = 0;
  14911. while ((maxPower2 ^ entriesCount) > maxPower2) {
  14912. maxPower2 <<= 1;
  14913. log2++;
  14914. }
  14915. var searchRange = maxPower2 * entrySize;
  14916. return {
  14917. range: searchRange,
  14918. entry: log2,
  14919. rangeShift: entrySize * entriesCount - searchRange
  14920. };
  14921. };
  14922. var OTF_HEADER_SIZE = 12;
  14923. var OTF_TABLE_ENTRY_SIZE = 16;
  14924. OpenTypeFileBuilder.prototype = {
  14925. toArray: function OpenTypeFileBuilder_toArray() {
  14926. var sfnt = this.sfnt;
  14927. // Tables needs to be written by ascendant alphabetic order
  14928. var tables = this.tables;
  14929. var tablesNames = Object.keys(tables);
  14930. tablesNames.sort();
  14931. var numTables = tablesNames.length;
  14932. var i, j, jj, table, tableName;
  14933. // layout the tables data
  14934. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  14935. var tableOffsets = [offset];
  14936. for (i = 0; i < numTables; i++) {
  14937. table = tables[tablesNames[i]];
  14938. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  14939. offset += paddedLength;
  14940. tableOffsets.push(offset);
  14941. }
  14942. var file = new Uint8Array(offset);
  14943. // write the table data first (mostly for checksum)
  14944. for (i = 0; i < numTables; i++) {
  14945. table = tables[tablesNames[i]];
  14946. writeData(file, tableOffsets[i], table);
  14947. }
  14948. // sfnt version (4 bytes)
  14949. if (sfnt === 'true') {
  14950. // Windows hates the Mac TrueType sfnt version number
  14951. sfnt = string32(0x00010000);
  14952. }
  14953. file[0] = sfnt.charCodeAt(0) & 0xFF;
  14954. file[1] = sfnt.charCodeAt(1) & 0xFF;
  14955. file[2] = sfnt.charCodeAt(2) & 0xFF;
  14956. file[3] = sfnt.charCodeAt(3) & 0xFF;
  14957. // numTables (2 bytes)
  14958. writeInt16(file, 4, numTables);
  14959. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  14960. // searchRange (2 bytes)
  14961. writeInt16(file, 6, searchParams.range);
  14962. // entrySelector (2 bytes)
  14963. writeInt16(file, 8, searchParams.entry);
  14964. // rangeShift (2 bytes)
  14965. writeInt16(file, 10, searchParams.rangeShift);
  14966. offset = OTF_HEADER_SIZE;
  14967. // writing table entries
  14968. for (i = 0; i < numTables; i++) {
  14969. tableName = tablesNames[i];
  14970. file[offset] = tableName.charCodeAt(0) & 0xFF;
  14971. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  14972. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  14973. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  14974. // checksum
  14975. var checksum = 0;
  14976. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  14977. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  14978. (file[j + 2] << 8) + file[j + 3];
  14979. checksum = (checksum + quad) | 0;
  14980. }
  14981. writeInt32(file, offset + 4, checksum);
  14982. // offset
  14983. writeInt32(file, offset + 8, tableOffsets[i]);
  14984. // length
  14985. writeInt32(file, offset + 12, tables[tableName].length);
  14986. offset += OTF_TABLE_ENTRY_SIZE;
  14987. }
  14988. return file;
  14989. },
  14990. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  14991. if (tag in this.tables) {
  14992. throw new Error('Table ' + tag + ' already exists');
  14993. }
  14994. this.tables[tag] = data;
  14995. }
  14996. };
  14997. return OpenTypeFileBuilder;
  14998. })();
  14999. /**
  15000. * 'Font' is the class the outside world should use, it encapsulate all the font
  15001. * decoding logics whatever type it is (assuming the font type is supported).
  15002. *
  15003. * For example to read a Type1 font and to attach it to the document:
  15004. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15005. * type1Font.bind();
  15006. */
  15007. var Font = (function FontClosure() {
  15008. function Font(name, file, properties) {
  15009. var charCode, glyphName, fontChar;
  15010. this.name = name;
  15011. this.loadedName = properties.loadedName;
  15012. this.isType3Font = properties.isType3Font;
  15013. this.sizes = [];
  15014. this.glyphCache = {};
  15015. var names = name.split('+');
  15016. names = names.length > 1 ? names[1] : names[0];
  15017. names = names.split(/[-,_]/g)[0];
  15018. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15019. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15020. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15021. var type = properties.type;
  15022. var subtype = properties.subtype;
  15023. this.type = type;
  15024. this.fallbackName = (this.isMonospace ? 'monospace' :
  15025. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15026. this.differences = properties.differences;
  15027. this.widths = properties.widths;
  15028. this.defaultWidth = properties.defaultWidth;
  15029. this.composite = properties.composite;
  15030. this.wideChars = properties.wideChars;
  15031. this.cMap = properties.cMap;
  15032. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15033. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15034. this.fontMatrix = properties.fontMatrix;
  15035. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15036. this.toFontChar = [];
  15037. if (properties.type === 'Type3') {
  15038. for (charCode = 0; charCode < 256; charCode++) {
  15039. this.toFontChar[charCode] = (this.differences[charCode] ||
  15040. properties.defaultEncoding[charCode]);
  15041. }
  15042. this.fontType = FontType.TYPE3;
  15043. return;
  15044. }
  15045. this.cidEncoding = properties.cidEncoding;
  15046. this.vertical = properties.vertical;
  15047. if (this.vertical) {
  15048. this.vmetrics = properties.vmetrics;
  15049. this.defaultVMetrics = properties.defaultVMetrics;
  15050. }
  15051. if (!file || file.isEmpty) {
  15052. if (file) {
  15053. // Some bad PDF generators will include empty font files,
  15054. // attempting to recover by assuming that no file exists.
  15055. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15056. }
  15057. this.missingFile = true;
  15058. // The file data is not specified. Trying to fix the font name
  15059. // to be used with the canvas.font.
  15060. var fontName = name.replace(/[,_]/g, '-');
  15061. var isStandardFont = fontName in stdFontMap;
  15062. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15063. this.bold = (fontName.search(/bold/gi) !== -1);
  15064. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15065. (fontName.search(/italic/gi) !== -1));
  15066. // Use 'name' instead of 'fontName' here because the original
  15067. // name ArialBlack for example will be replaced by Helvetica.
  15068. this.black = (name.search(/Black/g) !== -1);
  15069. // if at least one width is present, remeasure all chars when exists
  15070. this.remeasure = Object.keys(this.widths).length > 0;
  15071. if (isStandardFont && type === 'CIDFontType2' &&
  15072. properties.cidEncoding.indexOf('Identity-') === 0) {
  15073. // Standard fonts might be embedded as CID font without glyph mapping.
  15074. // Building one based on GlyphMapForStandardFonts.
  15075. var map = [];
  15076. for (var code in GlyphMapForStandardFonts) {
  15077. map[+code] = GlyphMapForStandardFonts[code];
  15078. }
  15079. this.toFontChar = map;
  15080. this.toUnicode = new ToUnicodeMap(map);
  15081. } else if (/Symbol/i.test(fontName)) {
  15082. var symbols = Encodings.SymbolSetEncoding;
  15083. for (charCode in symbols) {
  15084. fontChar = GlyphsUnicode[symbols[charCode]];
  15085. if (!fontChar) {
  15086. continue;
  15087. }
  15088. this.toFontChar[charCode] = fontChar;
  15089. }
  15090. for (charCode in properties.differences) {
  15091. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15092. if (!fontChar) {
  15093. continue;
  15094. }
  15095. this.toFontChar[charCode] = fontChar;
  15096. }
  15097. } else if (/Dingbats/i.test(fontName)) {
  15098. var dingbats = Encodings.ZapfDingbatsEncoding;
  15099. for (charCode in dingbats) {
  15100. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15101. if (!fontChar) {
  15102. continue;
  15103. }
  15104. this.toFontChar[charCode] = fontChar;
  15105. }
  15106. for (charCode in properties.differences) {
  15107. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15108. if (!fontChar) {
  15109. continue;
  15110. }
  15111. this.toFontChar[charCode] = fontChar;
  15112. }
  15113. } else if (isStandardFont) {
  15114. this.toFontChar = [];
  15115. for (charCode in properties.defaultEncoding) {
  15116. glyphName = (properties.differences[charCode] ||
  15117. properties.defaultEncoding[charCode]);
  15118. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15119. }
  15120. } else {
  15121. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15122. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15123. if (notCidFont) {
  15124. glyphName = (properties.differences[charCode] ||
  15125. properties.defaultEncoding[charCode]);
  15126. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15127. }
  15128. this.toFontChar[charCode] = unicodeCharCode;
  15129. }.bind(this));
  15130. }
  15131. this.loadedName = fontName.split('-')[0];
  15132. this.loading = false;
  15133. this.fontType = getFontType(type, subtype);
  15134. return;
  15135. }
  15136. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15137. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15138. // Some TrueType fonts by mistake claim Type1C
  15139. if (isTrueTypeFile(file)) {
  15140. subtype = 'TrueType';
  15141. } else {
  15142. type = 'Type1';
  15143. }
  15144. }
  15145. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15146. type = 'CIDFontType0';
  15147. }
  15148. // XXX: Temporarily change the type for open type so we trigger a warning.
  15149. // This should be removed when we add support for open type.
  15150. if (subtype === 'OpenType') {
  15151. type = 'OpenType';
  15152. }
  15153. var data;
  15154. switch (type) {
  15155. case 'MMType1':
  15156. info('MMType1 font (' + name + '), falling back to Type1.');
  15157. /* falls through */
  15158. case 'Type1':
  15159. case 'CIDFontType0':
  15160. this.mimetype = 'font/opentype';
  15161. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15162. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15163. adjustWidths(properties);
  15164. // Wrap the CFF data inside an OTF font file
  15165. data = this.convert(name, cff, properties);
  15166. break;
  15167. case 'OpenType':
  15168. case 'TrueType':
  15169. case 'CIDFontType2':
  15170. this.mimetype = 'font/opentype';
  15171. // Repair the TrueType file. It is can be damaged in the point of
  15172. // view of the sanitizer
  15173. data = this.checkAndRepair(name, file, properties);
  15174. if (this.isOpenType) {
  15175. type = 'OpenType';
  15176. }
  15177. break;
  15178. default:
  15179. error('Font ' + type + ' is not supported');
  15180. break;
  15181. }
  15182. this.data = data;
  15183. this.fontType = getFontType(type, subtype);
  15184. // Transfer some properties again that could change during font conversion
  15185. this.fontMatrix = properties.fontMatrix;
  15186. this.widths = properties.widths;
  15187. this.defaultWidth = properties.defaultWidth;
  15188. this.encoding = properties.baseEncoding;
  15189. this.seacMap = properties.seacMap;
  15190. this.loading = true;
  15191. }
  15192. Font.getFontID = (function () {
  15193. var ID = 1;
  15194. return function Font_getFontID() {
  15195. return String(ID++);
  15196. };
  15197. })();
  15198. function int16(b0, b1) {
  15199. return (b0 << 8) + b1;
  15200. }
  15201. function int32(b0, b1, b2, b3) {
  15202. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15203. }
  15204. function string16(value) {
  15205. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15206. }
  15207. function safeString16(value) {
  15208. // clamp value to the 16-bit int range
  15209. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15210. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15211. }
  15212. function isTrueTypeFile(file) {
  15213. var header = file.peekBytes(4);
  15214. return readUint32(header, 0) === 0x00010000;
  15215. }
  15216. /**
  15217. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15218. * with their unicode value. It also moves char codes that are in known
  15219. * problematic locations.
  15220. * @return {Object} Two properties:
  15221. * 'toFontChar' - maps original char codes(the value that will be read
  15222. * from commands such as show text) to the char codes that will be used in the
  15223. * font that we build
  15224. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15225. */
  15226. function adjustMapping(charCodeToGlyphId, properties) {
  15227. var toUnicode = properties.toUnicode;
  15228. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15229. var isIdentityUnicode =
  15230. properties.toUnicode instanceof IdentityToUnicodeMap;
  15231. var isCidFontType2 = (properties.type === 'CIDFontType2');
  15232. var newMap = Object.create(null);
  15233. var toFontChar = [];
  15234. var usedFontCharCodes = [];
  15235. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15236. for (var originalCharCode in charCodeToGlyphId) {
  15237. originalCharCode |= 0;
  15238. var glyphId = charCodeToGlyphId[originalCharCode];
  15239. var fontCharCode = originalCharCode;
  15240. // First try to map the value to a unicode position if a non identity map
  15241. // was created.
  15242. if (!isIdentityUnicode) {
  15243. if (toUnicode.get(originalCharCode) !== undefined) {
  15244. var unicode = toUnicode.get(fontCharCode);
  15245. // TODO: Try to map ligatures to the correct spot.
  15246. if (unicode.length === 1) {
  15247. fontCharCode = unicode.charCodeAt(0);
  15248. }
  15249. } else if (isCidFontType2) {
  15250. // For CIDFontType2, move characters not present in toUnicode
  15251. // to the private use area (fixes bug 1028735 and issue 4881).
  15252. fontCharCode = nextAvailableFontCharCode;
  15253. }
  15254. }
  15255. // Try to move control characters, special characters and already mapped
  15256. // characters to the private use area since they will not be drawn by
  15257. // canvas if left in their current position. Also, move characters if the
  15258. // font was symbolic and there is only an identity unicode map since the
  15259. // characters probably aren't in the correct position (fixes an issue
  15260. // with firefox and thuluthfont).
  15261. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15262. fontCharCode <= 0x1f || // Control chars
  15263. fontCharCode === 0x7F || // Control char
  15264. fontCharCode === 0xAD || // Soft hyphen
  15265. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15266. // Prevent drawing characters in the specials unicode block.
  15267. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15268. (isSymbolic && isIdentityUnicode)) &&
  15269. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15270. // Loop to try and find a free spot in the private use area.
  15271. do {
  15272. fontCharCode = nextAvailableFontCharCode++;
  15273. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15274. fontCharCode = 0xF020;
  15275. nextAvailableFontCharCode = fontCharCode + 1;
  15276. }
  15277. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15278. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15279. }
  15280. newMap[fontCharCode] = glyphId;
  15281. toFontChar[originalCharCode] = fontCharCode;
  15282. usedFontCharCodes[fontCharCode] = true;
  15283. }
  15284. return {
  15285. toFontChar: toFontChar,
  15286. charCodeToGlyphId: newMap,
  15287. nextAvailableFontCharCode: nextAvailableFontCharCode
  15288. };
  15289. }
  15290. function getRanges(glyphs) {
  15291. // Array.sort() sorts by characters, not numerically, so convert to an
  15292. // array of characters.
  15293. var codes = [];
  15294. for (var charCode in glyphs) {
  15295. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15296. }
  15297. codes.sort(function fontGetRangesSort(a, b) {
  15298. return a.fontCharCode - b.fontCharCode;
  15299. });
  15300. // Split the sorted codes into ranges.
  15301. var ranges = [];
  15302. var length = codes.length;
  15303. for (var n = 0; n < length; ) {
  15304. var start = codes[n].fontCharCode;
  15305. var codeIndices = [codes[n].glyphId];
  15306. ++n;
  15307. var end = start;
  15308. while (n < length && end + 1 === codes[n].fontCharCode) {
  15309. codeIndices.push(codes[n].glyphId);
  15310. ++end;
  15311. ++n;
  15312. if (end === 0xFFFF) {
  15313. break;
  15314. }
  15315. }
  15316. ranges.push([start, end, codeIndices]);
  15317. }
  15318. return ranges;
  15319. }
  15320. function createCmapTable(glyphs) {
  15321. var ranges = getRanges(glyphs);
  15322. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15323. var cmap = '\x00\x00' + // version
  15324. string16(numTables) + // numTables
  15325. '\x00\x03' + // platformID
  15326. '\x00\x01' + // encodingID
  15327. string32(4 + numTables * 8); // start of the table record
  15328. var i, ii, j, jj;
  15329. for (i = ranges.length - 1; i >= 0; --i) {
  15330. if (ranges[i][0] <= 0xFFFF) { break; }
  15331. }
  15332. var bmpLength = i + 1;
  15333. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15334. ranges[i][1] = 0xFFFE;
  15335. }
  15336. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15337. var segCount = bmpLength + trailingRangesCount;
  15338. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15339. // Fill up the 4 parallel arrays describing the segments.
  15340. var startCount = '';
  15341. var endCount = '';
  15342. var idDeltas = '';
  15343. var idRangeOffsets = '';
  15344. var glyphsIds = '';
  15345. var bias = 0;
  15346. var range, start, end, codes;
  15347. for (i = 0, ii = bmpLength; i < ii; i++) {
  15348. range = ranges[i];
  15349. start = range[0];
  15350. end = range[1];
  15351. startCount += string16(start);
  15352. endCount += string16(end);
  15353. codes = range[2];
  15354. var contiguous = true;
  15355. for (j = 1, jj = codes.length; j < jj; ++j) {
  15356. if (codes[j] !== codes[j - 1] + 1) {
  15357. contiguous = false;
  15358. break;
  15359. }
  15360. }
  15361. if (!contiguous) {
  15362. var offset = (segCount - i) * 2 + bias * 2;
  15363. bias += (end - start + 1);
  15364. idDeltas += string16(0);
  15365. idRangeOffsets += string16(offset);
  15366. for (j = 0, jj = codes.length; j < jj; ++j) {
  15367. glyphsIds += string16(codes[j]);
  15368. }
  15369. } else {
  15370. var startCode = codes[0];
  15371. idDeltas += string16((startCode - start) & 0xFFFF);
  15372. idRangeOffsets += string16(0);
  15373. }
  15374. }
  15375. if (trailingRangesCount > 0) {
  15376. endCount += '\xFF\xFF';
  15377. startCount += '\xFF\xFF';
  15378. idDeltas += '\x00\x01';
  15379. idRangeOffsets += '\x00\x00';
  15380. }
  15381. var format314 = '\x00\x00' + // language
  15382. string16(2 * segCount) +
  15383. string16(searchParams.range) +
  15384. string16(searchParams.entry) +
  15385. string16(searchParams.rangeShift) +
  15386. endCount + '\x00\x00' + startCount +
  15387. idDeltas + idRangeOffsets + glyphsIds;
  15388. var format31012 = '';
  15389. var header31012 = '';
  15390. if (numTables > 1) {
  15391. cmap += '\x00\x03' + // platformID
  15392. '\x00\x0A' + // encodingID
  15393. string32(4 + numTables * 8 +
  15394. 4 + format314.length); // start of the table record
  15395. format31012 = '';
  15396. for (i = 0, ii = ranges.length; i < ii; i++) {
  15397. range = ranges[i];
  15398. start = range[0];
  15399. codes = range[2];
  15400. var code = codes[0];
  15401. for (j = 1, jj = codes.length; j < jj; ++j) {
  15402. if (codes[j] !== codes[j - 1] + 1) {
  15403. end = range[0] + j - 1;
  15404. format31012 += string32(start) + // startCharCode
  15405. string32(end) + // endCharCode
  15406. string32(code); // startGlyphID
  15407. start = end + 1;
  15408. code = codes[j];
  15409. }
  15410. }
  15411. format31012 += string32(start) + // startCharCode
  15412. string32(range[1]) + // endCharCode
  15413. string32(code); // startGlyphID
  15414. }
  15415. header31012 = '\x00\x0C' + // format
  15416. '\x00\x00' + // reserved
  15417. string32(format31012.length + 16) + // length
  15418. '\x00\x00\x00\x00' + // language
  15419. string32(format31012.length / 12); // nGroups
  15420. }
  15421. return cmap + '\x00\x04' + // format
  15422. string16(format314.length + 4) + // length
  15423. format314 + header31012 + format31012;
  15424. }
  15425. function validateOS2Table(os2) {
  15426. var stream = new Stream(os2.data);
  15427. var version = stream.getUint16();
  15428. // TODO verify all OS/2 tables fields, but currently we validate only those
  15429. // that give us issues
  15430. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15431. var selection = stream.getUint16();
  15432. if (version < 4 && (selection & 0x0300)) {
  15433. return false;
  15434. }
  15435. var firstChar = stream.getUint16();
  15436. var lastChar = stream.getUint16();
  15437. if (firstChar > lastChar) {
  15438. return false;
  15439. }
  15440. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15441. var usWinAscent = stream.getUint16();
  15442. if (usWinAscent === 0) { // makes font unreadable by windows
  15443. return false;
  15444. }
  15445. // OS/2 appears to be valid, resetting some fields
  15446. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15447. return true;
  15448. }
  15449. function createOS2Table(properties, charstrings, override) {
  15450. override = override || {
  15451. unitsPerEm: 0,
  15452. yMax: 0,
  15453. yMin: 0,
  15454. ascent: 0,
  15455. descent: 0
  15456. };
  15457. var ulUnicodeRange1 = 0;
  15458. var ulUnicodeRange2 = 0;
  15459. var ulUnicodeRange3 = 0;
  15460. var ulUnicodeRange4 = 0;
  15461. var firstCharIndex = null;
  15462. var lastCharIndex = 0;
  15463. if (charstrings) {
  15464. for (var code in charstrings) {
  15465. code |= 0;
  15466. if (firstCharIndex > code || !firstCharIndex) {
  15467. firstCharIndex = code;
  15468. }
  15469. if (lastCharIndex < code) {
  15470. lastCharIndex = code;
  15471. }
  15472. var position = getUnicodeRangeFor(code);
  15473. if (position < 32) {
  15474. ulUnicodeRange1 |= 1 << position;
  15475. } else if (position < 64) {
  15476. ulUnicodeRange2 |= 1 << position - 32;
  15477. } else if (position < 96) {
  15478. ulUnicodeRange3 |= 1 << position - 64;
  15479. } else if (position < 123) {
  15480. ulUnicodeRange4 |= 1 << position - 96;
  15481. } else {
  15482. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15483. }
  15484. }
  15485. } else {
  15486. // TODO
  15487. firstCharIndex = 0;
  15488. lastCharIndex = 255;
  15489. }
  15490. var bbox = properties.bbox || [0, 0, 0, 0];
  15491. var unitsPerEm = (override.unitsPerEm ||
  15492. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15493. // if the font units differ to the PDF glyph space units
  15494. // then scale up the values
  15495. var scale = (properties.ascentScaled ? 1.0 :
  15496. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15497. var typoAscent = (override.ascent ||
  15498. Math.round(scale * (properties.ascent || bbox[3])));
  15499. var typoDescent = (override.descent ||
  15500. Math.round(scale * (properties.descent || bbox[1])));
  15501. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15502. typoDescent = -typoDescent; // fixing incorrect descent
  15503. }
  15504. var winAscent = override.yMax || typoAscent;
  15505. var winDescent = -override.yMin || -typoDescent;
  15506. return '\x00\x03' + // version
  15507. '\x02\x24' + // xAvgCharWidth
  15508. '\x01\xF4' + // usWeightClass
  15509. '\x00\x05' + // usWidthClass
  15510. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15511. '\x02\x8A' + // ySubscriptXSize
  15512. '\x02\xBB' + // ySubscriptYSize
  15513. '\x00\x00' + // ySubscriptXOffset
  15514. '\x00\x8C' + // ySubscriptYOffset
  15515. '\x02\x8A' + // ySuperScriptXSize
  15516. '\x02\xBB' + // ySuperScriptYSize
  15517. '\x00\x00' + // ySuperScriptXOffset
  15518. '\x01\xDF' + // ySuperScriptYOffset
  15519. '\x00\x31' + // yStrikeOutSize
  15520. '\x01\x02' + // yStrikeOutPosition
  15521. '\x00\x00' + // sFamilyClass
  15522. '\x00\x00\x06' +
  15523. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15524. '\x00\x00\x00\x00\x00\x00' + // Panose
  15525. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15526. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15527. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15528. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15529. '\x2A\x32\x31\x2A' + // achVendID
  15530. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15531. string16(firstCharIndex ||
  15532. properties.firstChar) + // usFirstCharIndex
  15533. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15534. string16(typoAscent) + // sTypoAscender
  15535. string16(typoDescent) + // sTypoDescender
  15536. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15537. string16(winAscent) + // usWinAscent
  15538. string16(winDescent) + // usWinDescent
  15539. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15540. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15541. string16(properties.xHeight) + // sxHeight
  15542. string16(properties.capHeight) + // sCapHeight
  15543. string16(0) + // usDefaultChar
  15544. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15545. '\x00\x03'; // usMaxContext
  15546. }
  15547. function createPostTable(properties) {
  15548. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15549. return ('\x00\x03\x00\x00' + // Version number
  15550. string32(angle) + // italicAngle
  15551. '\x00\x00' + // underlinePosition
  15552. '\x00\x00' + // underlineThickness
  15553. string32(properties.fixedPitch) + // isFixedPitch
  15554. '\x00\x00\x00\x00' + // minMemType42
  15555. '\x00\x00\x00\x00' + // maxMemType42
  15556. '\x00\x00\x00\x00' + // minMemType1
  15557. '\x00\x00\x00\x00'); // maxMemType1
  15558. }
  15559. function createNameTable(name, proto) {
  15560. if (!proto) {
  15561. proto = [[], []]; // no strings and unicode strings
  15562. }
  15563. var strings = [
  15564. proto[0][0] || 'Original licence', // 0.Copyright
  15565. proto[0][1] || name, // 1.Font family
  15566. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15567. proto[0][3] || 'uniqueID', // 3.Unique ID
  15568. proto[0][4] || name, // 4.Full font name
  15569. proto[0][5] || 'Version 0.11', // 5.Version
  15570. proto[0][6] || '', // 6.Postscript name
  15571. proto[0][7] || 'Unknown', // 7.Trademark
  15572. proto[0][8] || 'Unknown', // 8.Manufacturer
  15573. proto[0][9] || 'Unknown' // 9.Designer
  15574. ];
  15575. // Mac want 1-byte per character strings while Windows want
  15576. // 2-bytes per character, so duplicate the names table
  15577. var stringsUnicode = [];
  15578. var i, ii, j, jj, str;
  15579. for (i = 0, ii = strings.length; i < ii; i++) {
  15580. str = proto[1][i] || strings[i];
  15581. var strBufUnicode = [];
  15582. for (j = 0, jj = str.length; j < jj; j++) {
  15583. strBufUnicode.push(string16(str.charCodeAt(j)));
  15584. }
  15585. stringsUnicode.push(strBufUnicode.join(''));
  15586. }
  15587. var names = [strings, stringsUnicode];
  15588. var platforms = ['\x00\x01', '\x00\x03'];
  15589. var encodings = ['\x00\x00', '\x00\x01'];
  15590. var languages = ['\x00\x00', '\x04\x09'];
  15591. var namesRecordCount = strings.length * platforms.length;
  15592. var nameTable =
  15593. '\x00\x00' + // format
  15594. string16(namesRecordCount) + // Number of names Record
  15595. string16(namesRecordCount * 12 + 6); // Storage
  15596. // Build the name records field
  15597. var strOffset = 0;
  15598. for (i = 0, ii = platforms.length; i < ii; i++) {
  15599. var strs = names[i];
  15600. for (j = 0, jj = strs.length; j < jj; j++) {
  15601. str = strs[j];
  15602. var nameRecord =
  15603. platforms[i] + // platform ID
  15604. encodings[i] + // encoding ID
  15605. languages[i] + // language ID
  15606. string16(j) + // name ID
  15607. string16(str.length) +
  15608. string16(strOffset);
  15609. nameTable += nameRecord;
  15610. strOffset += str.length;
  15611. }
  15612. }
  15613. nameTable += strings.join('') + stringsUnicode.join('');
  15614. return nameTable;
  15615. }
  15616. Font.prototype = {
  15617. name: null,
  15618. font: null,
  15619. mimetype: null,
  15620. encoding: null,
  15621. get renderer() {
  15622. var renderer = FontRendererFactory.create(this);
  15623. return shadow(this, 'renderer', renderer);
  15624. },
  15625. exportData: function Font_exportData() {
  15626. var data = {};
  15627. for (var i in this) {
  15628. if (this.hasOwnProperty(i)) {
  15629. data[i] = this[i];
  15630. }
  15631. }
  15632. return data;
  15633. },
  15634. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15635. function readTableEntry(file) {
  15636. var tag = bytesToString(file.getBytes(4));
  15637. var checksum = file.getInt32();
  15638. var offset = file.getInt32() >>> 0;
  15639. var length = file.getInt32() >>> 0;
  15640. // Read the table associated data
  15641. var previousPosition = file.pos;
  15642. file.pos = file.start ? file.start : 0;
  15643. file.skip(offset);
  15644. var data = file.getBytes(length);
  15645. file.pos = previousPosition;
  15646. if (tag === 'head') {
  15647. // clearing checksum adjustment
  15648. data[8] = data[9] = data[10] = data[11] = 0;
  15649. data[17] |= 0x20; //Set font optimized for cleartype flag
  15650. }
  15651. return {
  15652. tag: tag,
  15653. checksum: checksum,
  15654. length: length,
  15655. offset: offset,
  15656. data: data
  15657. };
  15658. }
  15659. function readOpenTypeHeader(ttf) {
  15660. return {
  15661. version: bytesToString(ttf.getBytes(4)),
  15662. numTables: ttf.getUint16(),
  15663. searchRange: ttf.getUint16(),
  15664. entrySelector: ttf.getUint16(),
  15665. rangeShift: ttf.getUint16()
  15666. };
  15667. }
  15668. /**
  15669. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15670. * PDF spec
  15671. */
  15672. function readCmapTable(cmap, font, isSymbolicFont) {
  15673. var segment;
  15674. var start = (font.start ? font.start : 0) + cmap.offset;
  15675. font.pos = start;
  15676. var version = font.getUint16();
  15677. var numTables = font.getUint16();
  15678. var potentialTable;
  15679. var canBreak = false;
  15680. // There's an order of preference in terms of which cmap subtable to
  15681. // use:
  15682. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15683. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15684. // The following takes advantage of the fact that the tables are sorted
  15685. // to work.
  15686. for (var i = 0; i < numTables; i++) {
  15687. var platformId = font.getUint16();
  15688. var encodingId = font.getUint16();
  15689. var offset = font.getInt32() >>> 0;
  15690. var useTable = false;
  15691. if (platformId === 1 && encodingId === 0) {
  15692. useTable = true;
  15693. // Continue the loop since there still may be a higher priority
  15694. // table.
  15695. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15696. useTable = true;
  15697. canBreak = true;
  15698. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15699. useTable = true;
  15700. canBreak = true;
  15701. }
  15702. if (useTable) {
  15703. potentialTable = {
  15704. platformId: platformId,
  15705. encodingId: encodingId,
  15706. offset: offset
  15707. };
  15708. }
  15709. if (canBreak) {
  15710. break;
  15711. }
  15712. }
  15713. if (!potentialTable) {
  15714. warn('Could not find a preferred cmap table.');
  15715. return {
  15716. platformId: -1,
  15717. encodingId: -1,
  15718. mappings: [],
  15719. hasShortCmap: false
  15720. };
  15721. }
  15722. font.pos = start + potentialTable.offset;
  15723. var format = font.getUint16();
  15724. var length = font.getUint16();
  15725. var language = font.getUint16();
  15726. var hasShortCmap = false;
  15727. var mappings = [];
  15728. var j, glyphId;
  15729. // TODO(mack): refactor this cmap subtable reading logic out
  15730. if (format === 0) {
  15731. for (j = 0; j < 256; j++) {
  15732. var index = font.getByte();
  15733. if (!index) {
  15734. continue;
  15735. }
  15736. mappings.push({
  15737. charCode: j,
  15738. glyphId: index
  15739. });
  15740. }
  15741. hasShortCmap = true;
  15742. } else if (format === 4) {
  15743. // re-creating the table in format 4 since the encoding
  15744. // might be changed
  15745. var segCount = (font.getUint16() >> 1);
  15746. font.getBytes(6); // skipping range fields
  15747. var segIndex, segments = [];
  15748. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15749. segments.push({ end: font.getUint16() });
  15750. }
  15751. font.getUint16();
  15752. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15753. segments[segIndex].start = font.getUint16();
  15754. }
  15755. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15756. segments[segIndex].delta = font.getUint16();
  15757. }
  15758. var offsetsCount = 0;
  15759. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15760. segment = segments[segIndex];
  15761. var rangeOffset = font.getUint16();
  15762. if (!rangeOffset) {
  15763. segment.offsetIndex = -1;
  15764. continue;
  15765. }
  15766. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15767. segment.offsetIndex = offsetIndex;
  15768. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15769. segment.end - segment.start + 1);
  15770. }
  15771. var offsets = [];
  15772. for (j = 0; j < offsetsCount; j++) {
  15773. offsets.push(font.getUint16());
  15774. }
  15775. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15776. segment = segments[segIndex];
  15777. start = segment.start;
  15778. var end = segment.end;
  15779. var delta = segment.delta;
  15780. offsetIndex = segment.offsetIndex;
  15781. for (j = start; j <= end; j++) {
  15782. if (j === 0xFFFF) {
  15783. continue;
  15784. }
  15785. glyphId = (offsetIndex < 0 ?
  15786. j : offsets[offsetIndex + j - start]);
  15787. glyphId = (glyphId + delta) & 0xFFFF;
  15788. if (glyphId === 0) {
  15789. continue;
  15790. }
  15791. mappings.push({
  15792. charCode: j,
  15793. glyphId: glyphId
  15794. });
  15795. }
  15796. }
  15797. } else if (format === 6) {
  15798. // Format 6 is a 2-bytes dense mapping, which means the font data
  15799. // lives glue together even if they are pretty far in the unicode
  15800. // table. (This looks weird, so I can have missed something), this
  15801. // works on Linux but seems to fails on Mac so let's rewrite the
  15802. // cmap table to a 3-1-4 style
  15803. var firstCode = font.getUint16();
  15804. var entryCount = font.getUint16();
  15805. for (j = 0; j < entryCount; j++) {
  15806. glyphId = font.getUint16();
  15807. var charCode = firstCode + j;
  15808. mappings.push({
  15809. charCode: charCode,
  15810. glyphId: glyphId
  15811. });
  15812. }
  15813. } else {
  15814. error('cmap table has unsupported format: ' + format);
  15815. }
  15816. // removing duplicate entries
  15817. mappings.sort(function (a, b) {
  15818. return a.charCode - b.charCode;
  15819. });
  15820. for (i = 1; i < mappings.length; i++) {
  15821. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15822. mappings.splice(i, 1);
  15823. i--;
  15824. }
  15825. }
  15826. return {
  15827. platformId: potentialTable.platformId,
  15828. encodingId: potentialTable.encodingId,
  15829. mappings: mappings,
  15830. hasShortCmap: hasShortCmap
  15831. };
  15832. }
  15833. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15834. if (!header) {
  15835. if (metrics) {
  15836. metrics.data = null;
  15837. }
  15838. return;
  15839. }
  15840. font.pos = (font.start ? font.start : 0) + header.offset;
  15841. font.pos += header.length - 2;
  15842. var numOfMetrics = font.getUint16();
  15843. if (numOfMetrics > numGlyphs) {
  15844. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  15845. 'greater than the numGlyphs (' + numGlyphs + ')');
  15846. // Reduce numOfMetrics if it is greater than numGlyphs
  15847. numOfMetrics = numGlyphs;
  15848. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  15849. header.data[35] = numOfMetrics & 0x00ff;
  15850. }
  15851. var numOfSidebearings = numGlyphs - numOfMetrics;
  15852. var numMissing = numOfSidebearings -
  15853. ((metrics.length - numOfMetrics * 4) >> 1);
  15854. if (numMissing > 0) {
  15855. // For each missing glyph, we set both the width and lsb to 0 (zero).
  15856. // Since we need to add two properties for each glyph, this explains
  15857. // the use of |numMissing * 2| when initializing the typed array.
  15858. var entries = new Uint8Array(metrics.length + numMissing * 2);
  15859. entries.set(metrics.data);
  15860. metrics.data = entries;
  15861. }
  15862. }
  15863. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  15864. hintsValid) {
  15865. if (sourceEnd - sourceStart <= 12) {
  15866. // glyph with data less than 12 is invalid one
  15867. return 0;
  15868. }
  15869. var glyf = source.subarray(sourceStart, sourceEnd);
  15870. var contoursCount = (glyf[0] << 8) | glyf[1];
  15871. if (contoursCount & 0x8000) {
  15872. // complex glyph, writing as is
  15873. dest.set(glyf, destStart);
  15874. return glyf.length;
  15875. }
  15876. var i, j = 10, flagsCount = 0;
  15877. for (i = 0; i < contoursCount; i++) {
  15878. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  15879. flagsCount = endPoint + 1;
  15880. j += 2;
  15881. }
  15882. // skipping instructions
  15883. var instructionsStart = j;
  15884. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  15885. j += 2 + instructionsLength;
  15886. var instructionsEnd = j;
  15887. // validating flags
  15888. var coordinatesLength = 0;
  15889. for (i = 0; i < flagsCount; i++) {
  15890. var flag = glyf[j++];
  15891. if (flag & 0xC0) {
  15892. // reserved flags must be zero, cleaning up
  15893. glyf[j - 1] = flag & 0x3F;
  15894. }
  15895. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  15896. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  15897. coordinatesLength += xyLength;
  15898. if (flag & 8) {
  15899. var repeat = glyf[j++];
  15900. i += repeat;
  15901. coordinatesLength += repeat * xyLength;
  15902. }
  15903. }
  15904. // glyph without coordinates will be rejected
  15905. if (coordinatesLength === 0) {
  15906. return 0;
  15907. }
  15908. var glyphDataLength = j + coordinatesLength;
  15909. if (glyphDataLength > glyf.length) {
  15910. // not enough data for coordinates
  15911. return 0;
  15912. }
  15913. if (!hintsValid && instructionsLength > 0) {
  15914. dest.set(glyf.subarray(0, instructionsStart), destStart);
  15915. dest.set([0, 0], destStart + instructionsStart);
  15916. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  15917. destStart + instructionsStart + 2);
  15918. glyphDataLength -= instructionsLength;
  15919. if (glyf.length - glyphDataLength > 3) {
  15920. glyphDataLength = (glyphDataLength + 3) & ~3;
  15921. }
  15922. return glyphDataLength;
  15923. }
  15924. if (glyf.length - glyphDataLength > 3) {
  15925. // truncating and aligning to 4 bytes the long glyph data
  15926. glyphDataLength = (glyphDataLength + 3) & ~3;
  15927. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  15928. return glyphDataLength;
  15929. }
  15930. // glyph data is fine
  15931. dest.set(glyf, destStart);
  15932. return glyf.length;
  15933. }
  15934. function sanitizeHead(head, numGlyphs, locaLength) {
  15935. var data = head.data;
  15936. // Validate version:
  15937. // Should always be 0x00010000
  15938. var version = int32(data[0], data[1], data[2], data[3]);
  15939. if (version >> 16 !== 1) {
  15940. info('Attempting to fix invalid version in head table: ' + version);
  15941. data[0] = 0;
  15942. data[1] = 1;
  15943. data[2] = 0;
  15944. data[3] = 0;
  15945. }
  15946. var indexToLocFormat = int16(data[50], data[51]);
  15947. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  15948. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  15949. indexToLocFormat);
  15950. // The value of indexToLocFormat should be 0 if the loca table
  15951. // consists of short offsets, and should be 1 if the loca table
  15952. // consists of long offsets.
  15953. //
  15954. // The number of entries in the loca table should be numGlyphs + 1.
  15955. //
  15956. // Using this information, we can work backwards to deduce if the
  15957. // size of each offset in the loca table, and thus figure out the
  15958. // appropriate value for indexToLocFormat.
  15959. var numGlyphsPlusOne = numGlyphs + 1;
  15960. if (locaLength === numGlyphsPlusOne << 1) {
  15961. // 0x0000 indicates the loca table consists of short offsets
  15962. data[50] = 0;
  15963. data[51] = 0;
  15964. } else if (locaLength === numGlyphsPlusOne << 2) {
  15965. // 0x0001 indicates the loca table consists of long offsets
  15966. data[50] = 0;
  15967. data[51] = 1;
  15968. } else {
  15969. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  15970. }
  15971. }
  15972. }
  15973. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  15974. isGlyphLocationsLong, hintsValid,
  15975. dupFirstEntry) {
  15976. var itemSize, itemDecode, itemEncode;
  15977. if (isGlyphLocationsLong) {
  15978. itemSize = 4;
  15979. itemDecode = function fontItemDecodeLong(data, offset) {
  15980. return (data[offset] << 24) | (data[offset + 1] << 16) |
  15981. (data[offset + 2] << 8) | data[offset + 3];
  15982. };
  15983. itemEncode = function fontItemEncodeLong(data, offset, value) {
  15984. data[offset] = (value >>> 24) & 0xFF;
  15985. data[offset + 1] = (value >> 16) & 0xFF;
  15986. data[offset + 2] = (value >> 8) & 0xFF;
  15987. data[offset + 3] = value & 0xFF;
  15988. };
  15989. } else {
  15990. itemSize = 2;
  15991. itemDecode = function fontItemDecode(data, offset) {
  15992. return (data[offset] << 9) | (data[offset + 1] << 1);
  15993. };
  15994. itemEncode = function fontItemEncode(data, offset, value) {
  15995. data[offset] = (value >> 9) & 0xFF;
  15996. data[offset + 1] = (value >> 1) & 0xFF;
  15997. };
  15998. }
  15999. var locaData = loca.data;
  16000. var locaDataSize = itemSize * (1 + numGlyphs);
  16001. // is loca.data too short or long?
  16002. if (locaData.length !== locaDataSize) {
  16003. locaData = new Uint8Array(locaDataSize);
  16004. locaData.set(loca.data.subarray(0, locaDataSize));
  16005. loca.data = locaData;
  16006. }
  16007. // removing the invalid glyphs
  16008. var oldGlyfData = glyf.data;
  16009. var oldGlyfDataLength = oldGlyfData.length;
  16010. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16011. var startOffset = itemDecode(locaData, 0);
  16012. var writeOffset = 0;
  16013. itemEncode(locaData, 0, writeOffset);
  16014. var i, j;
  16015. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16016. var endOffset = itemDecode(locaData, j);
  16017. if (endOffset > oldGlyfDataLength &&
  16018. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16019. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16020. // the glyf table size, which makes last glyph out of range.
  16021. endOffset = oldGlyfDataLength;
  16022. }
  16023. if (endOffset > oldGlyfDataLength) {
  16024. // glyph end offset points outside glyf data, rejecting the glyph
  16025. itemEncode(locaData, j, writeOffset);
  16026. startOffset = endOffset;
  16027. continue;
  16028. }
  16029. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16030. newGlyfData, writeOffset, hintsValid);
  16031. writeOffset += newLength;
  16032. itemEncode(locaData, j, writeOffset);
  16033. startOffset = endOffset;
  16034. }
  16035. if (writeOffset === 0) {
  16036. // glyf table cannot be empty -- redoing the glyf and loca tables
  16037. // to have single glyph with one point
  16038. var simpleGlyph = new Uint8Array(
  16039. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16040. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16041. itemEncode(locaData, j, simpleGlyph.length);
  16042. }
  16043. glyf.data = simpleGlyph;
  16044. return;
  16045. }
  16046. if (dupFirstEntry) {
  16047. var firstEntryLength = itemDecode(locaData, itemSize);
  16048. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16049. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16050. } else {
  16051. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16052. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16053. }
  16054. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16055. itemEncode(loca.data, locaData.length - itemSize,
  16056. writeOffset + firstEntryLength);
  16057. } else {
  16058. glyf.data = newGlyfData.subarray(0, writeOffset);
  16059. }
  16060. }
  16061. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16062. var start = (font.start ? font.start : 0) + post.offset;
  16063. font.pos = start;
  16064. var length = post.length, end = start + length;
  16065. var version = font.getInt32();
  16066. // skip rest to the tables
  16067. font.getBytes(28);
  16068. var glyphNames;
  16069. var valid = true;
  16070. var i;
  16071. switch (version) {
  16072. case 0x00010000:
  16073. glyphNames = MacStandardGlyphOrdering;
  16074. break;
  16075. case 0x00020000:
  16076. var numGlyphs = font.getUint16();
  16077. if (numGlyphs !== maxpNumGlyphs) {
  16078. valid = false;
  16079. break;
  16080. }
  16081. var glyphNameIndexes = [];
  16082. for (i = 0; i < numGlyphs; ++i) {
  16083. var index = font.getUint16();
  16084. if (index >= 32768) {
  16085. valid = false;
  16086. break;
  16087. }
  16088. glyphNameIndexes.push(index);
  16089. }
  16090. if (!valid) {
  16091. break;
  16092. }
  16093. var customNames = [];
  16094. var strBuf = [];
  16095. while (font.pos < end) {
  16096. var stringLength = font.getByte();
  16097. strBuf.length = stringLength;
  16098. for (i = 0; i < stringLength; ++i) {
  16099. strBuf[i] = String.fromCharCode(font.getByte());
  16100. }
  16101. customNames.push(strBuf.join(''));
  16102. }
  16103. glyphNames = [];
  16104. for (i = 0; i < numGlyphs; ++i) {
  16105. var j = glyphNameIndexes[i];
  16106. if (j < 258) {
  16107. glyphNames.push(MacStandardGlyphOrdering[j]);
  16108. continue;
  16109. }
  16110. glyphNames.push(customNames[j - 258]);
  16111. }
  16112. break;
  16113. case 0x00030000:
  16114. break;
  16115. default:
  16116. warn('Unknown/unsupported post table version ' + version);
  16117. valid = false;
  16118. break;
  16119. }
  16120. properties.glyphNames = glyphNames;
  16121. return valid;
  16122. }
  16123. function readNameTable(nameTable) {
  16124. var start = (font.start ? font.start : 0) + nameTable.offset;
  16125. font.pos = start;
  16126. var names = [[], []];
  16127. var length = nameTable.length, end = start + length;
  16128. var format = font.getUint16();
  16129. var FORMAT_0_HEADER_LENGTH = 6;
  16130. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16131. // unsupported name table format or table "too" small
  16132. return names;
  16133. }
  16134. var numRecords = font.getUint16();
  16135. var stringsStart = font.getUint16();
  16136. var records = [];
  16137. var NAME_RECORD_LENGTH = 12;
  16138. var i, ii;
  16139. for (i = 0; i < numRecords &&
  16140. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16141. var r = {
  16142. platform: font.getUint16(),
  16143. encoding: font.getUint16(),
  16144. language: font.getUint16(),
  16145. name: font.getUint16(),
  16146. length: font.getUint16(),
  16147. offset: font.getUint16()
  16148. };
  16149. // using only Macintosh and Windows platform/encoding names
  16150. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16151. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16152. records.push(r);
  16153. }
  16154. }
  16155. for (i = 0, ii = records.length; i < ii; i++) {
  16156. var record = records[i];
  16157. var pos = start + stringsStart + record.offset;
  16158. if (pos + record.length > end) {
  16159. continue; // outside of name table, ignoring
  16160. }
  16161. font.pos = pos;
  16162. var nameIndex = record.name;
  16163. if (record.encoding) {
  16164. // unicode
  16165. var str = '';
  16166. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16167. str += String.fromCharCode(font.getUint16());
  16168. }
  16169. names[1][nameIndex] = str;
  16170. } else {
  16171. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16172. }
  16173. }
  16174. return names;
  16175. }
  16176. var TTOpsStackDeltas = [
  16177. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16178. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16179. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16180. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16181. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16182. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16183. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16184. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16185. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16186. // 0xC0-DF == -1 and 0xE0-FF == -2
  16187. function sanitizeTTProgram(table, ttContext) {
  16188. var data = table.data;
  16189. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16190. var stack = [];
  16191. var callstack = [];
  16192. var functionsCalled = [];
  16193. var tooComplexToFollowFunctions =
  16194. ttContext.tooComplexToFollowFunctions;
  16195. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16196. for (var ii = data.length; i < ii;) {
  16197. var op = data[i++];
  16198. // The TrueType instruction set docs can be found at
  16199. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16200. if (op === 0x40) { // NPUSHB - pushes n bytes
  16201. n = data[i++];
  16202. if (inFDEF || inELSE) {
  16203. i += n;
  16204. } else {
  16205. for (j = 0; j < n; j++) {
  16206. stack.push(data[i++]);
  16207. }
  16208. }
  16209. } else if (op === 0x41) { // NPUSHW - pushes n words
  16210. n = data[i++];
  16211. if (inFDEF || inELSE) {
  16212. i += n * 2;
  16213. } else {
  16214. for (j = 0; j < n; j++) {
  16215. b = data[i++];
  16216. stack.push((b << 8) | data[i++]);
  16217. }
  16218. }
  16219. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16220. n = op - 0xB0 + 1;
  16221. if (inFDEF || inELSE) {
  16222. i += n;
  16223. } else {
  16224. for (j = 0; j < n; j++) {
  16225. stack.push(data[i++]);
  16226. }
  16227. }
  16228. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16229. n = op - 0xB8 + 1;
  16230. if (inFDEF || inELSE) {
  16231. i += n * 2;
  16232. } else {
  16233. for (j = 0; j < n; j++) {
  16234. b = data[i++];
  16235. stack.push((b << 8) | data[i++]);
  16236. }
  16237. }
  16238. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16239. if (!inFDEF && !inELSE) {
  16240. // collecting inforamtion about which functions are used
  16241. funcId = stack[stack.length - 1];
  16242. ttContext.functionsUsed[funcId] = true;
  16243. if (funcId in ttContext.functionsStackDeltas) {
  16244. stack.length += ttContext.functionsStackDeltas[funcId];
  16245. } else if (funcId in ttContext.functionsDefined &&
  16246. functionsCalled.indexOf(funcId) < 0) {
  16247. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16248. functionsCalled.push(funcId);
  16249. pc = ttContext.functionsDefined[funcId];
  16250. if (!pc) {
  16251. warn('TT: CALL non-existent function');
  16252. ttContext.hintsValid = false;
  16253. return;
  16254. }
  16255. data = pc.data;
  16256. i = pc.i;
  16257. }
  16258. }
  16259. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16260. if (inFDEF || inELSE) {
  16261. warn('TT: nested FDEFs not allowed');
  16262. tooComplexToFollowFunctions = true;
  16263. }
  16264. inFDEF = true;
  16265. // collecting inforamtion about which functions are defined
  16266. lastDeff = i;
  16267. funcId = stack.pop();
  16268. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16269. } else if (op === 0x2D) { // ENDF - end of function
  16270. if (inFDEF) {
  16271. inFDEF = false;
  16272. lastEndf = i;
  16273. } else {
  16274. pc = callstack.pop();
  16275. if (!pc) {
  16276. warn('TT: ENDF bad stack');
  16277. ttContext.hintsValid = false;
  16278. return;
  16279. }
  16280. funcId = functionsCalled.pop();
  16281. data = pc.data;
  16282. i = pc.i;
  16283. ttContext.functionsStackDeltas[funcId] =
  16284. stack.length - pc.stackTop;
  16285. }
  16286. } else if (op === 0x89) { // IDEF - instruction definition
  16287. if (inFDEF || inELSE) {
  16288. warn('TT: nested IDEFs not allowed');
  16289. tooComplexToFollowFunctions = true;
  16290. }
  16291. inFDEF = true;
  16292. // recording it as a function to track ENDF
  16293. lastDeff = i;
  16294. } else if (op === 0x58) { // IF
  16295. ++ifLevel;
  16296. } else if (op === 0x1B) { // ELSE
  16297. inELSE = ifLevel;
  16298. } else if (op === 0x59) { // EIF
  16299. if (inELSE === ifLevel) {
  16300. inELSE = 0;
  16301. }
  16302. --ifLevel;
  16303. } else if (op === 0x1C) { // JMPR
  16304. if (!inFDEF && !inELSE) {
  16305. var offset = stack[stack.length - 1];
  16306. // only jumping forward to prevent infinite loop
  16307. if (offset > 0) {
  16308. i += offset - 1;
  16309. }
  16310. }
  16311. }
  16312. // Adjusting stack not extactly, but just enough to get function id
  16313. if (!inFDEF && !inELSE) {
  16314. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16315. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16316. if (op >= 0x71 && op <= 0x75) {
  16317. n = stack.pop();
  16318. if (n === n) {
  16319. stackDelta = -n * 2;
  16320. }
  16321. }
  16322. while (stackDelta < 0 && stack.length > 0) {
  16323. stack.pop();
  16324. stackDelta++;
  16325. }
  16326. while (stackDelta > 0) {
  16327. stack.push(NaN); // pushing any number into stack
  16328. stackDelta--;
  16329. }
  16330. }
  16331. }
  16332. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16333. var content = [data];
  16334. if (i > data.length) {
  16335. content.push(new Uint8Array(i - data.length));
  16336. }
  16337. if (lastDeff > lastEndf) {
  16338. warn('TT: complementing a missing function tail');
  16339. // new function definition started, but not finished
  16340. // complete function by [CLEAR, ENDF]
  16341. content.push(new Uint8Array([0x22, 0x2D]));
  16342. }
  16343. foldTTTable(table, content);
  16344. }
  16345. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16346. if (ttContext.tooComplexToFollowFunctions) {
  16347. return;
  16348. }
  16349. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16350. warn('TT: more functions defined than expected');
  16351. ttContext.hintsValid = false;
  16352. return;
  16353. }
  16354. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16355. if (j > maxFunctionDefs) {
  16356. warn('TT: invalid function id: ' + j);
  16357. ttContext.hintsValid = false;
  16358. return;
  16359. }
  16360. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16361. warn('TT: undefined function: ' + j);
  16362. ttContext.hintsValid = false;
  16363. return;
  16364. }
  16365. }
  16366. }
  16367. function foldTTTable(table, content) {
  16368. if (content.length > 1) {
  16369. // concatenating the content items
  16370. var newLength = 0;
  16371. var j, jj;
  16372. for (j = 0, jj = content.length; j < jj; j++) {
  16373. newLength += content[j].length;
  16374. }
  16375. newLength = (newLength + 3) & ~3;
  16376. var result = new Uint8Array(newLength);
  16377. var pos = 0;
  16378. for (j = 0, jj = content.length; j < jj; j++) {
  16379. result.set(content[j], pos);
  16380. pos += content[j].length;
  16381. }
  16382. table.data = result;
  16383. table.length = newLength;
  16384. }
  16385. }
  16386. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16387. var ttContext = {
  16388. functionsDefined: [],
  16389. functionsUsed: [],
  16390. functionsStackDeltas: [],
  16391. tooComplexToFollowFunctions: false,
  16392. hintsValid: true
  16393. };
  16394. if (fpgm) {
  16395. sanitizeTTProgram(fpgm, ttContext);
  16396. }
  16397. if (prep) {
  16398. sanitizeTTProgram(prep, ttContext);
  16399. }
  16400. if (fpgm) {
  16401. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16402. }
  16403. if (cvt && (cvt.length & 1)) {
  16404. var cvtData = new Uint8Array(cvt.length + 1);
  16405. cvtData.set(cvt.data);
  16406. cvt.data = cvtData;
  16407. }
  16408. return ttContext.hintsValid;
  16409. }
  16410. // The following steps modify the original font data, making copy
  16411. font = new Stream(new Uint8Array(font.getBytes()));
  16412. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16413. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16414. var header = readOpenTypeHeader(font);
  16415. var numTables = header.numTables;
  16416. var cff, cffFile;
  16417. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16418. hmtx: null, maxp: null, name: null, post: null };
  16419. var table;
  16420. for (var i = 0; i < numTables; i++) {
  16421. table = readTableEntry(font);
  16422. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16423. continue; // skipping table if it's not a required or optional table
  16424. }
  16425. if (table.length === 0) {
  16426. continue; // skipping empty tables
  16427. }
  16428. tables[table.tag] = table;
  16429. }
  16430. var isTrueType = !tables['CFF '];
  16431. if (!isTrueType) {
  16432. // OpenType font
  16433. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16434. // no major tables: throwing everything at CFFFont
  16435. cffFile = new Stream(tables['CFF '].data);
  16436. cff = new CFFFont(cffFile, properties);
  16437. return this.convert(name, cff, properties);
  16438. }
  16439. delete tables.glyf;
  16440. delete tables.loca;
  16441. delete tables.fpgm;
  16442. delete tables.prep;
  16443. delete tables['cvt '];
  16444. this.isOpenType = true;
  16445. } else {
  16446. if (!tables.glyf || !tables.loca) {
  16447. error('Required "glyf" or "loca" tables are not found');
  16448. }
  16449. this.isOpenType = false;
  16450. }
  16451. if (!tables.maxp) {
  16452. error('Required "maxp" table is not found');
  16453. }
  16454. font.pos = (font.start || 0) + tables.maxp.offset;
  16455. var version = font.getInt32();
  16456. var numGlyphs = font.getUint16();
  16457. var maxFunctionDefs = 0;
  16458. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16459. // maxZones can be invalid
  16460. font.pos += 8;
  16461. var maxZones = font.getUint16();
  16462. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16463. tables.maxp.data[14] = 0;
  16464. tables.maxp.data[15] = 2;
  16465. }
  16466. font.pos += 4;
  16467. maxFunctionDefs = font.getUint16();
  16468. }
  16469. var dupFirstEntry = false;
  16470. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16471. properties.toUnicode.get(0) > '\u0000') {
  16472. // oracle's defect (see 3427), duplicating first entry
  16473. dupFirstEntry = true;
  16474. numGlyphs++;
  16475. tables.maxp.data[4] = numGlyphs >> 8;
  16476. tables.maxp.data[5] = numGlyphs & 255;
  16477. }
  16478. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16479. tables['cvt '], maxFunctionDefs);
  16480. if (!hintsValid) {
  16481. delete tables.fpgm;
  16482. delete tables.prep;
  16483. delete tables['cvt '];
  16484. }
  16485. // Ensure the hmtx table contains the advance width and
  16486. // sidebearings information for numGlyphs in the maxp table
  16487. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16488. if (!tables.head) {
  16489. error('Required "head" table is not found');
  16490. }
  16491. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16492. if (isTrueType) {
  16493. var isGlyphLocationsLong = int16(tables.head.data[50],
  16494. tables.head.data[51]);
  16495. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16496. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16497. }
  16498. if (!tables.hhea) {
  16499. error('Required "hhea" table is not found');
  16500. }
  16501. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16502. // Sometimes it's 0. That needs to be fixed
  16503. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16504. tables.hhea.data[10] = 0xFF;
  16505. tables.hhea.data[11] = 0xFF;
  16506. }
  16507. // The 'post' table has glyphs names.
  16508. if (tables.post) {
  16509. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16510. if (!valid) {
  16511. tables.post = null;
  16512. }
  16513. }
  16514. var charCodeToGlyphId = [], charCode;
  16515. if (properties.type === 'CIDFontType2') {
  16516. var cidToGidMap = properties.cidToGidMap || [];
  16517. var cidToGidMapLength = cidToGidMap.length;
  16518. properties.cMap.forEach(function(charCode, cid) {
  16519. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16520. var glyphId = -1;
  16521. if (cidToGidMapLength === 0) {
  16522. glyphId = charCode;
  16523. } else if (cidToGidMap[cid] !== undefined) {
  16524. glyphId = cidToGidMap[cid];
  16525. }
  16526. if (glyphId >= 0 && glyphId < numGlyphs) {
  16527. charCodeToGlyphId[charCode] = glyphId;
  16528. }
  16529. });
  16530. if (dupFirstEntry) {
  16531. charCodeToGlyphId[0] = numGlyphs - 1;
  16532. }
  16533. } else {
  16534. // Most of the following logic in this code branch is based on the
  16535. // 9.6.6.4 of the PDF spec.
  16536. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16537. var cmapPlatformId = cmapTable.platformId;
  16538. var cmapEncodingId = cmapTable.encodingId;
  16539. var cmapMappings = cmapTable.mappings;
  16540. var cmapMappingsLength = cmapMappings.length;
  16541. var hasEncoding = properties.differences.length ||
  16542. !!properties.baseEncodingName;
  16543. // The spec seems to imply that if the font is symbolic the encoding
  16544. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16545. // where the the font is symbolic and it has an encoding.
  16546. if (hasEncoding &&
  16547. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16548. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16549. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16550. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16551. // When no preferred cmap table was found and |baseEncodingName| is
  16552. // one of the predefined encodings, we seem to obtain a better
  16553. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16554. // TODO: Note that this is a hack which should be removed as soon as
  16555. // we have proper support for more exotic cmap tables.
  16556. var baseEncoding = [];
  16557. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16558. properties.baseEncodingName === 'WinAnsiEncoding') {
  16559. baseEncoding = Encodings[properties.baseEncodingName];
  16560. }
  16561. for (charCode = 0; charCode < 256; charCode++) {
  16562. var glyphName;
  16563. if (this.differences && charCode in this.differences) {
  16564. glyphName = this.differences[charCode];
  16565. } else if (charCode in baseEncoding &&
  16566. baseEncoding[charCode] !== '') {
  16567. glyphName = baseEncoding[charCode];
  16568. } else {
  16569. glyphName = Encodings.StandardEncoding[charCode];
  16570. }
  16571. if (!glyphName) {
  16572. continue;
  16573. }
  16574. var unicodeOrCharCode;
  16575. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16576. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16577. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16578. // TODO: the encoding needs to be updated with mac os table.
  16579. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16580. }
  16581. var found = false;
  16582. for (i = 0; i < cmapMappingsLength; ++i) {
  16583. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16584. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16585. found = true;
  16586. break;
  16587. }
  16588. }
  16589. if (!found && properties.glyphNames) {
  16590. // Try to map using the post table. There are currently no known
  16591. // pdfs that this fixes.
  16592. var glyphId = properties.glyphNames.indexOf(glyphName);
  16593. if (glyphId > 0) {
  16594. charCodeToGlyphId[charCode] = glyphId;
  16595. }
  16596. }
  16597. }
  16598. } else {
  16599. // For (3, 0) cmap tables:
  16600. // The charcode key being stored in charCodeToGlyphId is the lower
  16601. // byte of the two-byte charcodes of the cmap table since according to
  16602. // the spec: 'each byte from the string shall be prepended with the
  16603. // high byte of the range [of charcodes in the cmap table], to form
  16604. // a two-byte character, which shall be used to select the
  16605. // associated glyph description from the subtable'.
  16606. //
  16607. // For (1, 0) cmap tables:
  16608. // 'single bytes from the string shall be used to look up the
  16609. // associated glyph descriptions from the subtable'. This means
  16610. // charcodes in the cmap will be single bytes, so no-op since
  16611. // glyph.charCode & 0xFF === glyph.charCode
  16612. for (i = 0; i < cmapMappingsLength; ++i) {
  16613. charCode = cmapMappings[i].charCode & 0xFF;
  16614. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16615. }
  16616. }
  16617. }
  16618. if (charCodeToGlyphId.length === 0) {
  16619. // defines at least one glyph
  16620. charCodeToGlyphId[0] = 0;
  16621. }
  16622. // Converting glyphs and ids into font's cmap table
  16623. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16624. this.toFontChar = newMapping.toFontChar;
  16625. tables.cmap = {
  16626. tag: 'cmap',
  16627. data: createCmapTable(newMapping.charCodeToGlyphId)
  16628. };
  16629. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16630. // extract some more font properties from the OpenType head and
  16631. // hhea tables; yMin and descent value are always negative
  16632. var override = {
  16633. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16634. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16635. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16636. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16637. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16638. };
  16639. tables['OS/2'] = {
  16640. tag: 'OS/2',
  16641. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16642. override)
  16643. };
  16644. }
  16645. // Rewrite the 'post' table if needed
  16646. if (!tables.post) {
  16647. tables.post = {
  16648. tag: 'post',
  16649. data: createPostTable(properties)
  16650. };
  16651. }
  16652. if (!isTrueType) {
  16653. try {
  16654. // Trying to repair CFF file
  16655. cffFile = new Stream(tables['CFF '].data);
  16656. var parser = new CFFParser(cffFile, properties);
  16657. cff = parser.parse();
  16658. var compiler = new CFFCompiler(cff);
  16659. tables['CFF '].data = compiler.compile();
  16660. } catch (e) {
  16661. warn('Failed to compile font ' + properties.loadedName);
  16662. }
  16663. }
  16664. // Re-creating 'name' table
  16665. if (!tables.name) {
  16666. tables.name = {
  16667. tag: 'name',
  16668. data: createNameTable(this.name)
  16669. };
  16670. } else {
  16671. // ... using existing 'name' table as prototype
  16672. var namePrototype = readNameTable(tables.name);
  16673. tables.name.data = createNameTable(name, namePrototype);
  16674. }
  16675. var builder = new OpenTypeFileBuilder(header.version);
  16676. for (var tableTag in tables) {
  16677. builder.addTable(tableTag, tables[tableTag].data);
  16678. }
  16679. return builder.toArray();
  16680. },
  16681. convert: function Font_convert(fontName, font, properties) {
  16682. // TODO: Check the charstring widths to determine this.
  16683. properties.fixedPitch = false;
  16684. var mapping = font.getGlyphMapping(properties);
  16685. var newMapping = adjustMapping(mapping, properties);
  16686. this.toFontChar = newMapping.toFontChar;
  16687. var numGlyphs = font.numGlyphs;
  16688. function getCharCodes(charCodeToGlyphId, glyphId) {
  16689. var charCodes = null;
  16690. for (var charCode in charCodeToGlyphId) {
  16691. if (glyphId === charCodeToGlyphId[charCode]) {
  16692. if (!charCodes) {
  16693. charCodes = [];
  16694. }
  16695. charCodes.push(charCode | 0);
  16696. }
  16697. }
  16698. return charCodes;
  16699. }
  16700. function createCharCode(charCodeToGlyphId, glyphId) {
  16701. for (var charCode in charCodeToGlyphId) {
  16702. if (glyphId === charCodeToGlyphId[charCode]) {
  16703. return charCode | 0;
  16704. }
  16705. }
  16706. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16707. glyphId;
  16708. return newMapping.nextAvailableFontCharCode++;
  16709. }
  16710. var seacs = font.seacs;
  16711. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16712. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16713. var charset = font.getCharset();
  16714. var seacMap = Object.create(null);
  16715. for (var glyphId in seacs) {
  16716. glyphId |= 0;
  16717. var seac = seacs[glyphId];
  16718. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16719. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16720. var baseGlyphId = charset.indexOf(baseGlyphName);
  16721. var accentGlyphId = charset.indexOf(accentGlyphName);
  16722. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16723. continue;
  16724. }
  16725. var accentOffset = {
  16726. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16727. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16728. };
  16729. var charCodes = getCharCodes(mapping, glyphId);
  16730. if (!charCodes) {
  16731. // There's no point in mapping it if the char code was never mapped
  16732. // to begin with.
  16733. continue;
  16734. }
  16735. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16736. var charCode = charCodes[i];
  16737. // Find a fontCharCode that maps to the base and accent glyphs.
  16738. // If one doesn't exists, create it.
  16739. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16740. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16741. baseGlyphId);
  16742. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16743. accentGlyphId);
  16744. seacMap[charCode] = {
  16745. baseFontCharCode: baseFontCharCode,
  16746. accentFontCharCode: accentFontCharCode,
  16747. accentOffset: accentOffset
  16748. };
  16749. }
  16750. }
  16751. properties.seacMap = seacMap;
  16752. }
  16753. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16754. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16755. // PostScript Font Program
  16756. builder.addTable('CFF ', font.data);
  16757. // OS/2 and Windows Specific metrics
  16758. builder.addTable('OS/2', createOS2Table(properties,
  16759. newMapping.charCodeToGlyphId));
  16760. // Character to glyphs mapping
  16761. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16762. // Font header
  16763. builder.addTable('head',
  16764. '\x00\x01\x00\x00' + // Version number
  16765. '\x00\x00\x10\x00' + // fontRevision
  16766. '\x00\x00\x00\x00' + // checksumAdjustement
  16767. '\x5F\x0F\x3C\xF5' + // magicNumber
  16768. '\x00\x00' + // Flags
  16769. safeString16(unitsPerEm) + // unitsPerEM
  16770. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16771. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16772. '\x00\x00' + // xMin
  16773. safeString16(properties.descent) + // yMin
  16774. '\x0F\xFF' + // xMax
  16775. safeString16(properties.ascent) + // yMax
  16776. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16777. '\x00\x11' + // lowestRecPPEM
  16778. '\x00\x00' + // fontDirectionHint
  16779. '\x00\x00' + // indexToLocFormat
  16780. '\x00\x00'); // glyphDataFormat
  16781. // Horizontal header
  16782. builder.addTable('hhea',
  16783. '\x00\x01\x00\x00' + // Version number
  16784. safeString16(properties.ascent) + // Typographic Ascent
  16785. safeString16(properties.descent) + // Typographic Descent
  16786. '\x00\x00' + // Line Gap
  16787. '\xFF\xFF' + // advanceWidthMax
  16788. '\x00\x00' + // minLeftSidebearing
  16789. '\x00\x00' + // minRightSidebearing
  16790. '\x00\x00' + // xMaxExtent
  16791. safeString16(properties.capHeight) + // caretSlopeRise
  16792. safeString16(Math.tan(properties.italicAngle) *
  16793. properties.xHeight) + // caretSlopeRun
  16794. '\x00\x00' + // caretOffset
  16795. '\x00\x00' + // -reserved-
  16796. '\x00\x00' + // -reserved-
  16797. '\x00\x00' + // -reserved-
  16798. '\x00\x00' + // -reserved-
  16799. '\x00\x00' + // metricDataFormat
  16800. string16(numGlyphs)); // Number of HMetrics
  16801. // Horizontal metrics
  16802. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16803. var charstrings = font.charstrings;
  16804. var cffWidths = font.cff ? font.cff.widths : null;
  16805. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16806. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16807. var width = 0;
  16808. if (charstrings) {
  16809. var charstring = charstrings[i - 1];
  16810. width = 'width' in charstring ? charstring.width : 0;
  16811. } else if (cffWidths) {
  16812. width = Math.ceil(cffWidths[i] || 0);
  16813. }
  16814. hmtx += string16(width) + string16(0);
  16815. }
  16816. return hmtx;
  16817. })());
  16818. // Maximum profile
  16819. builder.addTable('maxp',
  16820. '\x00\x00\x50\x00' + // Version number
  16821. string16(numGlyphs)); // Num of glyphs
  16822. // Naming tables
  16823. builder.addTable('name', createNameTable(fontName));
  16824. // PostScript informations
  16825. builder.addTable('post', createPostTable(properties));
  16826. return builder.toArray();
  16827. },
  16828. /**
  16829. * Builds a char code to unicode map based on section 9.10 of the spec.
  16830. * @param {Object} properties Font properties object.
  16831. * @return {Object} A ToUnicodeMap object.
  16832. */
  16833. buildToUnicode: function Font_buildToUnicode(properties) {
  16834. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16835. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16836. return properties.toUnicode;
  16837. }
  16838. // According to the spec if the font is a simple font we should only map
  16839. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16840. // the differences array only contains adobe standard or symbol set names,
  16841. // in pratice it seems better to always try to create a toUnicode
  16842. // map based of the default encoding.
  16843. var toUnicode, charcode;
  16844. if (!properties.composite /* is simple font */) {
  16845. toUnicode = [];
  16846. var encoding = properties.defaultEncoding.slice();
  16847. var baseEncodingName = properties.baseEncodingName;
  16848. // Merge in the differences array.
  16849. var differences = properties.differences;
  16850. for (charcode in differences) {
  16851. encoding[charcode] = differences[charcode];
  16852. }
  16853. for (charcode in encoding) {
  16854. // a) Map the character code to a character name.
  16855. var glyphName = encoding[charcode];
  16856. // b) Look up the character name in the Adobe Glyph List (see the
  16857. // Bibliography) to obtain the corresponding Unicode value.
  16858. if (glyphName === '') {
  16859. continue;
  16860. } else if (GlyphsUnicode[glyphName] === undefined) {
  16861. // (undocumented) c) Few heuristics to recognize unknown glyphs
  16862. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  16863. var code = 0;
  16864. switch (glyphName[0]) {
  16865. case 'G': // Gxx glyph
  16866. if (glyphName.length === 3) {
  16867. code = parseInt(glyphName.substr(1), 16);
  16868. }
  16869. break;
  16870. case 'g': // g00xx glyph
  16871. if (glyphName.length === 5) {
  16872. code = parseInt(glyphName.substr(1), 16);
  16873. }
  16874. break;
  16875. case 'C': // Cddd glyph
  16876. case 'c': // cddd glyph
  16877. if (glyphName.length >= 3) {
  16878. code = +glyphName.substr(1);
  16879. }
  16880. break;
  16881. }
  16882. if (code) {
  16883. // If |baseEncodingName| is one the predefined encodings,
  16884. // and |code| equals |charcode|, using the glyph defined in the
  16885. // baseEncoding seems to yield a better |toUnicode| mapping
  16886. // (fixes issue 5070).
  16887. if (baseEncodingName && code === +charcode) {
  16888. var baseEncoding = Encodings[baseEncodingName];
  16889. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  16890. toUnicode[charcode] =
  16891. String.fromCharCode(GlyphsUnicode[glyphName]);
  16892. continue;
  16893. }
  16894. }
  16895. toUnicode[charcode] = String.fromCharCode(code);
  16896. }
  16897. continue;
  16898. }
  16899. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  16900. }
  16901. return new ToUnicodeMap(toUnicode);
  16902. }
  16903. // If the font is a composite font that uses one of the predefined CMaps
  16904. // listed in Table 118 (except Identity–H and Identity–V) or whose
  16905. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  16906. // Adobe-Korea1 character collection:
  16907. if (properties.composite && (
  16908. (properties.cMap.builtInCMap &&
  16909. !(properties.cMap instanceof IdentityCMap)) ||
  16910. (properties.cidSystemInfo.registry === 'Adobe' &&
  16911. (properties.cidSystemInfo.ordering === 'GB1' ||
  16912. properties.cidSystemInfo.ordering === 'CNS1' ||
  16913. properties.cidSystemInfo.ordering === 'Japan1' ||
  16914. properties.cidSystemInfo.ordering === 'Korea1')))) {
  16915. // Then:
  16916. // a) Map the character code to a character identifier (CID) according
  16917. // to the font’s CMap.
  16918. // b) Obtain the registry and ordering of the character collection used
  16919. // by the font’s CMap (for example, Adobe and Japan1) from its
  16920. // CIDSystemInfo dictionary.
  16921. var registry = properties.cidSystemInfo.registry;
  16922. var ordering = properties.cidSystemInfo.ordering;
  16923. // c) Construct a second CMap name by concatenating the registry and
  16924. // ordering obtained in step (b) in the format registry–ordering–UCS2
  16925. // (for example, Adobe–Japan1–UCS2).
  16926. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  16927. // d) Obtain the CMap with the name constructed in step (c) (available
  16928. // from the ASN Web site; see the Bibliography).
  16929. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  16930. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16931. var cMap = properties.cMap;
  16932. toUnicode = [];
  16933. cMap.forEach(function(charcode, cid) {
  16934. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16935. // e) Map the CID obtained in step (a) according to the CMap obtained
  16936. // in step (d), producing a Unicode value.
  16937. var ucs2 = ucs2CMap.lookup(cid);
  16938. if (ucs2) {
  16939. toUnicode[charcode] =
  16940. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  16941. ucs2.charCodeAt(1));
  16942. }
  16943. });
  16944. return new ToUnicodeMap(toUnicode);
  16945. }
  16946. // The viewer's choice, just use an identity map.
  16947. return new IdentityToUnicodeMap(properties.firstChar,
  16948. properties.lastChar);
  16949. },
  16950. get spaceWidth() {
  16951. if ('_shadowWidth' in this) {
  16952. return this._shadowWidth;
  16953. }
  16954. // trying to estimate space character width
  16955. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  16956. var width;
  16957. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  16958. var glyphName = possibleSpaceReplacements[i];
  16959. // if possible, getting width by glyph name
  16960. if (glyphName in this.widths) {
  16961. width = this.widths[glyphName];
  16962. break;
  16963. }
  16964. var glyphUnicode = GlyphsUnicode[glyphName];
  16965. // finding the charcode via unicodeToCID map
  16966. var charcode = 0;
  16967. if (this.composite) {
  16968. if (this.cMap.contains(glyphUnicode)) {
  16969. charcode = this.cMap.lookup(glyphUnicode);
  16970. }
  16971. }
  16972. // ... via toUnicode map
  16973. if (!charcode && 'toUnicode' in this) {
  16974. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  16975. }
  16976. // setting it to unicode if negative or undefined
  16977. if (charcode <= 0) {
  16978. charcode = glyphUnicode;
  16979. }
  16980. // trying to get width via charcode
  16981. width = this.widths[charcode];
  16982. if (width) {
  16983. break; // the non-zero width found
  16984. }
  16985. }
  16986. width = width || this.defaultWidth;
  16987. // Do not shadow the property here. See discussion:
  16988. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  16989. this._shadowWidth = width;
  16990. return width;
  16991. },
  16992. charToGlyph: function Font_charToGlyph(charcode) {
  16993. var fontCharCode, width, operatorListId;
  16994. var widthCode = charcode;
  16995. if (this.cMap && this.cMap.contains(charcode)) {
  16996. widthCode = this.cMap.lookup(charcode);
  16997. }
  16998. width = this.widths[widthCode];
  16999. width = isNum(width) ? width : this.defaultWidth;
  17000. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17001. var unicode = this.toUnicode.get(charcode) || charcode;
  17002. if (typeof unicode === 'number') {
  17003. unicode = String.fromCharCode(unicode);
  17004. }
  17005. // First try the toFontChar map, if it's not there then try falling
  17006. // back to the char code.
  17007. fontCharCode = this.toFontChar[charcode] || charcode;
  17008. if (this.missingFile) {
  17009. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17010. }
  17011. if (this.isType3Font) {
  17012. // Font char code in this case is actually a glyph name.
  17013. operatorListId = fontCharCode;
  17014. }
  17015. var accent = null;
  17016. if (this.seacMap && this.seacMap[charcode]) {
  17017. var seac = this.seacMap[charcode];
  17018. fontCharCode = seac.baseFontCharCode;
  17019. accent = {
  17020. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17021. offset: seac.accentOffset
  17022. };
  17023. }
  17024. var fontChar = String.fromCharCode(fontCharCode);
  17025. var glyph = this.glyphCache[charcode];
  17026. if (!glyph ||
  17027. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17028. operatorListId)) {
  17029. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17030. operatorListId);
  17031. this.glyphCache[charcode] = glyph;
  17032. }
  17033. return glyph;
  17034. },
  17035. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17036. var charsCache = this.charsCache;
  17037. var glyphs, glyph, charcode;
  17038. // if we translated this string before, just grab it from the cache
  17039. if (charsCache) {
  17040. glyphs = charsCache[chars];
  17041. if (glyphs) {
  17042. return glyphs;
  17043. }
  17044. }
  17045. // lazily create the translation cache
  17046. if (!charsCache) {
  17047. charsCache = this.charsCache = Object.create(null);
  17048. }
  17049. glyphs = [];
  17050. var charsCacheKey = chars;
  17051. var i = 0, ii;
  17052. if (this.cMap) {
  17053. // composite fonts have multi-byte strings convert the string from
  17054. // single-byte to multi-byte
  17055. var c = {};
  17056. while (i < chars.length) {
  17057. this.cMap.readCharCode(chars, i, c);
  17058. charcode = c.charcode;
  17059. var length = c.length;
  17060. i += length;
  17061. glyph = this.charToGlyph(charcode);
  17062. glyphs.push(glyph);
  17063. // placing null after each word break charcode (ASCII SPACE)
  17064. // Ignore occurences of 0x20 in multiple-byte codes.
  17065. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17066. glyphs.push(null);
  17067. }
  17068. }
  17069. } else {
  17070. for (i = 0, ii = chars.length; i < ii; ++i) {
  17071. charcode = chars.charCodeAt(i);
  17072. glyph = this.charToGlyph(charcode);
  17073. glyphs.push(glyph);
  17074. if (charcode === 0x20) {
  17075. glyphs.push(null);
  17076. }
  17077. }
  17078. }
  17079. // Enter the translated string into the cache
  17080. return (charsCache[charsCacheKey] = glyphs);
  17081. }
  17082. };
  17083. return Font;
  17084. })();
  17085. var ErrorFont = (function ErrorFontClosure() {
  17086. function ErrorFont(error) {
  17087. this.error = error;
  17088. this.loadedName = 'g_font_error';
  17089. this.loading = false;
  17090. }
  17091. ErrorFont.prototype = {
  17092. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17093. return [];
  17094. },
  17095. exportData: function ErrorFont_exportData() {
  17096. return {error: this.error};
  17097. }
  17098. };
  17099. return ErrorFont;
  17100. })();
  17101. /**
  17102. * Shared logic for building a char code to glyph id mapping for Type1 and
  17103. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17104. * @param {Object} properties Font properties object.
  17105. * @param {Object} builtInEncoding The encoding contained within the actual font
  17106. * data.
  17107. * @param {Array} Array of glyph names where the index is the glyph ID.
  17108. * @returns {Object} A char code to glyph ID map.
  17109. */
  17110. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17111. var charCodeToGlyphId = Object.create(null);
  17112. var glyphId, charCode, baseEncoding;
  17113. if (properties.baseEncodingName) {
  17114. // If a valid base encoding name was used, the mapping is initialized with
  17115. // that.
  17116. baseEncoding = Encodings[properties.baseEncodingName];
  17117. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17118. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17119. if (glyphId >= 0) {
  17120. charCodeToGlyphId[charCode] = glyphId;
  17121. }
  17122. }
  17123. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17124. // For a symbolic font the encoding should be the fonts built-in
  17125. // encoding.
  17126. for (charCode in builtInEncoding) {
  17127. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17128. }
  17129. } else {
  17130. // For non-symbolic fonts that don't have a base encoding the standard
  17131. // encoding should be used.
  17132. baseEncoding = Encodings.StandardEncoding;
  17133. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17134. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17135. if (glyphId >= 0) {
  17136. charCodeToGlyphId[charCode] = glyphId;
  17137. }
  17138. }
  17139. }
  17140. // Lastly, merge in the differences.
  17141. var differences = properties.differences;
  17142. if (differences) {
  17143. for (charCode in differences) {
  17144. var glyphName = differences[charCode];
  17145. glyphId = glyphNames.indexOf(glyphName);
  17146. if (glyphId >= 0) {
  17147. charCodeToGlyphId[charCode] = glyphId;
  17148. }
  17149. }
  17150. }
  17151. return charCodeToGlyphId;
  17152. }
  17153. /*
  17154. * CharStrings are encoded following the the CharString Encoding sequence
  17155. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17156. * The value in a byte indicates a command, a number, or subsequent bytes
  17157. * that are to be interpreted in a special way.
  17158. *
  17159. * CharString Number Encoding:
  17160. * A CharString byte containing the values from 32 through 255 inclusive
  17161. * indicate an integer. These values are decoded in four ranges.
  17162. *
  17163. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17164. * indicate the integer v - 139. Thus, the integer values from -107 through
  17165. * 107 inclusive may be encoded in single byte.
  17166. *
  17167. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17168. * indicates an integer involving the next byte, w, according to the formula:
  17169. * [(v - 247) x 256] + w + 108
  17170. *
  17171. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17172. * indicates an integer involving the next byte, w, according to the formula:
  17173. * -[(v - 251) * 256] - w - 108
  17174. *
  17175. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17176. * are a two complement signed integer. The first of these bytes contains the
  17177. * highest order bits, the second byte contains the next higher order bits
  17178. * and the fourth byte contain the lowest order bits.
  17179. *
  17180. *
  17181. * CharString Command Encoding:
  17182. * CharStrings commands are encoded in 1 or 2 bytes.
  17183. *
  17184. * Single byte commands are encoded in 1 byte that contains a value between
  17185. * 0 and 31 inclusive.
  17186. * If a command byte contains the value 12, then the value in the next byte
  17187. * indicates a command. This "escape" mechanism allows many extra commands
  17188. * to be encoded and this encoding technique helps to minimize the length of
  17189. * the charStrings.
  17190. */
  17191. var Type1CharString = (function Type1CharStringClosure() {
  17192. var COMMAND_MAP = {
  17193. 'hstem': [1],
  17194. 'vstem': [3],
  17195. 'vmoveto': [4],
  17196. 'rlineto': [5],
  17197. 'hlineto': [6],
  17198. 'vlineto': [7],
  17199. 'rrcurveto': [8],
  17200. 'callsubr': [10],
  17201. 'flex': [12, 35],
  17202. 'drop' : [12, 18],
  17203. 'endchar': [14],
  17204. 'rmoveto': [21],
  17205. 'hmoveto': [22],
  17206. 'vhcurveto': [30],
  17207. 'hvcurveto': [31]
  17208. };
  17209. function Type1CharString() {
  17210. this.width = 0;
  17211. this.lsb = 0;
  17212. this.flexing = false;
  17213. this.output = [];
  17214. this.stack = [];
  17215. }
  17216. Type1CharString.prototype = {
  17217. convert: function Type1CharString_convert(encoded, subrs) {
  17218. var count = encoded.length;
  17219. var error = false;
  17220. var wx, sbx, subrNumber;
  17221. for (var i = 0; i < count; i++) {
  17222. var value = encoded[i];
  17223. if (value < 32) {
  17224. if (value === 12) {
  17225. value = (value << 8) + encoded[++i];
  17226. }
  17227. switch (value) {
  17228. case 1: // hstem
  17229. if (!HINTING_ENABLED) {
  17230. this.stack = [];
  17231. break;
  17232. }
  17233. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17234. break;
  17235. case 3: // vstem
  17236. if (!HINTING_ENABLED) {
  17237. this.stack = [];
  17238. break;
  17239. }
  17240. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17241. break;
  17242. case 4: // vmoveto
  17243. if (this.flexing) {
  17244. if (this.stack.length < 1) {
  17245. error = true;
  17246. break;
  17247. }
  17248. // Add the dx for flex and but also swap the values so they are
  17249. // the right order.
  17250. var dy = this.stack.pop();
  17251. this.stack.push(0, dy);
  17252. break;
  17253. }
  17254. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17255. break;
  17256. case 5: // rlineto
  17257. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17258. break;
  17259. case 6: // hlineto
  17260. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17261. break;
  17262. case 7: // vlineto
  17263. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17264. break;
  17265. case 8: // rrcurveto
  17266. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17267. break;
  17268. case 9: // closepath
  17269. // closepath is a Type1 command that does not take argument and is
  17270. // useless in Type2 and it can simply be ignored.
  17271. this.stack = [];
  17272. break;
  17273. case 10: // callsubr
  17274. if (this.stack.length < 1) {
  17275. error = true;
  17276. break;
  17277. }
  17278. subrNumber = this.stack.pop();
  17279. error = this.convert(subrs[subrNumber], subrs);
  17280. break;
  17281. case 11: // return
  17282. return error;
  17283. case 13: // hsbw
  17284. if (this.stack.length < 2) {
  17285. error = true;
  17286. break;
  17287. }
  17288. // To convert to type2 we have to move the width value to the
  17289. // first part of the charstring and then use hmoveto with lsb.
  17290. wx = this.stack.pop();
  17291. sbx = this.stack.pop();
  17292. this.lsb = sbx;
  17293. this.width = wx;
  17294. this.stack.push(wx, sbx);
  17295. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17296. break;
  17297. case 14: // endchar
  17298. this.output.push(COMMAND_MAP.endchar[0]);
  17299. break;
  17300. case 21: // rmoveto
  17301. if (this.flexing) {
  17302. break;
  17303. }
  17304. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17305. break;
  17306. case 22: // hmoveto
  17307. if (this.flexing) {
  17308. // Add the dy for flex.
  17309. this.stack.push(0);
  17310. break;
  17311. }
  17312. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17313. break;
  17314. case 30: // vhcurveto
  17315. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17316. break;
  17317. case 31: // hvcurveto
  17318. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17319. break;
  17320. case (12 << 8) + 0: // dotsection
  17321. // dotsection is a Type1 command to specify some hinting feature
  17322. // for dots that do not take a parameter and it can safely be
  17323. // ignored for Type2.
  17324. this.stack = [];
  17325. break;
  17326. case (12 << 8) + 1: // vstem3
  17327. if (!HINTING_ENABLED) {
  17328. this.stack = [];
  17329. break;
  17330. }
  17331. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17332. // multiple parameters, so instead of returning [vh]stem3 take a
  17333. // shortcut and return [vhstem] instead.
  17334. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17335. break;
  17336. case (12 << 8) + 2: // hstem3
  17337. if (!HINTING_ENABLED) {
  17338. this.stack = [];
  17339. break;
  17340. }
  17341. // See vstem3.
  17342. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17343. break;
  17344. case (12 << 8) + 6: // seac
  17345. // seac is like type 2's special endchar but it doesn't use the
  17346. // first argument asb, so remove it.
  17347. if (SEAC_ANALYSIS_ENABLED) {
  17348. this.seac = this.stack.splice(-4, 4);
  17349. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17350. } else {
  17351. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17352. }
  17353. break;
  17354. case (12 << 8) + 7: // sbw
  17355. if (this.stack.length < 4) {
  17356. error = true;
  17357. break;
  17358. }
  17359. // To convert to type2 we have to move the width value to the
  17360. // first part of the charstring and then use rmoveto with
  17361. // (dx, dy). The height argument will not be used for vmtx and
  17362. // vhea tables reconstruction -- ignoring it.
  17363. var wy = this.stack.pop();
  17364. wx = this.stack.pop();
  17365. var sby = this.stack.pop();
  17366. sbx = this.stack.pop();
  17367. this.lsb = sbx;
  17368. this.width = wx;
  17369. this.stack.push(wx, sbx, sby);
  17370. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17371. break;
  17372. case (12 << 8) + 12: // div
  17373. if (this.stack.length < 2) {
  17374. error = true;
  17375. break;
  17376. }
  17377. var num2 = this.stack.pop();
  17378. var num1 = this.stack.pop();
  17379. this.stack.push(num1 / num2);
  17380. break;
  17381. case (12 << 8) + 16: // callothersubr
  17382. if (this.stack.length < 2) {
  17383. error = true;
  17384. break;
  17385. }
  17386. subrNumber = this.stack.pop();
  17387. var numArgs = this.stack.pop();
  17388. if (subrNumber === 0 && numArgs === 3) {
  17389. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17390. this.stack.push(
  17391. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17392. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17393. flexArgs[4], // bcp2x
  17394. flexArgs[5], // bcp2y
  17395. flexArgs[6], // p2x
  17396. flexArgs[7], // p2y
  17397. flexArgs[8], // bcp3x
  17398. flexArgs[9], // bcp3y
  17399. flexArgs[10], // bcp4x
  17400. flexArgs[11], // bcp4y
  17401. flexArgs[12], // p3x
  17402. flexArgs[13], // p3y
  17403. flexArgs[14] // flexDepth
  17404. // 15 = finalx unused by flex
  17405. // 16 = finaly unused by flex
  17406. );
  17407. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17408. this.flexing = false;
  17409. this.stack.push(flexArgs[15], flexArgs[16]);
  17410. } else if (subrNumber === 1 && numArgs === 0) {
  17411. this.flexing = true;
  17412. }
  17413. break;
  17414. case (12 << 8) + 17: // pop
  17415. // Ignore this since it is only used with othersubr.
  17416. break;
  17417. case (12 << 8) + 33: // setcurrentpoint
  17418. // Ignore for now.
  17419. this.stack = [];
  17420. break;
  17421. default:
  17422. warn('Unknown type 1 charstring command of "' + value + '"');
  17423. break;
  17424. }
  17425. if (error) {
  17426. break;
  17427. }
  17428. continue;
  17429. } else if (value <= 246) {
  17430. value = value - 139;
  17431. } else if (value <= 250) {
  17432. value = ((value - 247) * 256) + encoded[++i] + 108;
  17433. } else if (value <= 254) {
  17434. value = -((value - 251) * 256) - encoded[++i] - 108;
  17435. } else {
  17436. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17437. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17438. }
  17439. this.stack.push(value);
  17440. }
  17441. return error;
  17442. },
  17443. executeCommand: function(howManyArgs, command, keepStack) {
  17444. var stackLength = this.stack.length;
  17445. if (howManyArgs > stackLength) {
  17446. return true;
  17447. }
  17448. var start = stackLength - howManyArgs;
  17449. for (var i = start; i < stackLength; i++) {
  17450. var value = this.stack[i];
  17451. if (value === (value | 0)) { // int
  17452. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17453. } else { // fixed point
  17454. value = (65536 * value) | 0;
  17455. this.output.push(255,
  17456. (value >> 24) & 0xFF,
  17457. (value >> 16) & 0xFF,
  17458. (value >> 8) & 0xFF,
  17459. value & 0xFF);
  17460. }
  17461. }
  17462. this.output.push.apply(this.output, command);
  17463. if (keepStack) {
  17464. this.stack.splice(start, howManyArgs);
  17465. } else {
  17466. this.stack.length = 0;
  17467. }
  17468. return false;
  17469. }
  17470. };
  17471. return Type1CharString;
  17472. })();
  17473. /*
  17474. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17475. * program. Some of its logic depends on the Type2 charstrings
  17476. * structure.
  17477. * Note: this doesn't really parse the font since that would require evaluation
  17478. * of PostScript, but it is possible in most cases to extract what we need
  17479. * without a full parse.
  17480. */
  17481. var Type1Parser = (function Type1ParserClosure() {
  17482. /*
  17483. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17484. * of Plaintext Bytes. The function took a key as a parameter which can be
  17485. * for decrypting the eexec block of for decoding charStrings.
  17486. */
  17487. var EEXEC_ENCRYPT_KEY = 55665;
  17488. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17489. function isHexDigit(code) {
  17490. return code >= 48 && code <= 57 || // '0'-'9'
  17491. code >= 65 && code <= 70 || // 'A'-'F'
  17492. code >= 97 && code <= 102; // 'a'-'f'
  17493. }
  17494. function decrypt(data, key, discardNumber) {
  17495. var r = key | 0, c1 = 52845, c2 = 22719;
  17496. var count = data.length;
  17497. var decrypted = new Uint8Array(count);
  17498. for (var i = 0; i < count; i++) {
  17499. var value = data[i];
  17500. decrypted[i] = value ^ (r >> 8);
  17501. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17502. }
  17503. return Array.prototype.slice.call(decrypted, discardNumber);
  17504. }
  17505. function decryptAscii(data, key, discardNumber) {
  17506. var r = key | 0, c1 = 52845, c2 = 22719;
  17507. var count = data.length, maybeLength = count >>> 1;
  17508. var decrypted = new Uint8Array(maybeLength);
  17509. var i, j;
  17510. for (i = 0, j = 0; i < count; i++) {
  17511. var digit1 = data[i];
  17512. if (!isHexDigit(digit1)) {
  17513. continue;
  17514. }
  17515. i++;
  17516. var digit2;
  17517. while (i < count && !isHexDigit(digit2 = data[i])) {
  17518. i++;
  17519. }
  17520. if (i < count) {
  17521. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17522. decrypted[j++] = value ^ (r >> 8);
  17523. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17524. }
  17525. }
  17526. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17527. }
  17528. function isSpecial(c) {
  17529. return c === 0x2F || // '/'
  17530. c === 0x5B || c === 0x5D || // '[', ']'
  17531. c === 0x7B || c === 0x7D || // '{', '}'
  17532. c === 0x28 || c === 0x29; // '(', ')'
  17533. }
  17534. function Type1Parser(stream, encrypted) {
  17535. if (encrypted) {
  17536. var data = stream.getBytes();
  17537. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17538. isHexDigit(data[2]) && isHexDigit(data[3]));
  17539. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17540. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17541. }
  17542. this.stream = stream;
  17543. this.nextChar();
  17544. }
  17545. Type1Parser.prototype = {
  17546. readNumberArray: function Type1Parser_readNumberArray() {
  17547. this.getToken(); // read '[' or '{' (arrays can start with either)
  17548. var array = [];
  17549. while (true) {
  17550. var token = this.getToken();
  17551. if (token === null || token === ']' || token === '}') {
  17552. break;
  17553. }
  17554. array.push(parseFloat(token || 0));
  17555. }
  17556. return array;
  17557. },
  17558. readNumber: function Type1Parser_readNumber() {
  17559. var token = this.getToken();
  17560. return parseFloat(token || 0);
  17561. },
  17562. readInt: function Type1Parser_readInt() {
  17563. // Use '| 0' to prevent setting a double into length such as the double
  17564. // does not flow into the loop variable.
  17565. var token = this.getToken();
  17566. return parseInt(token || 0, 10) | 0;
  17567. },
  17568. readBoolean: function Type1Parser_readBoolean() {
  17569. var token = this.getToken();
  17570. // Use 1 and 0 since that's what type2 charstrings use.
  17571. return token === 'true' ? 1 : 0;
  17572. },
  17573. nextChar : function Type1_nextChar() {
  17574. return (this.currentChar = this.stream.getByte());
  17575. },
  17576. getToken: function Type1Parser_getToken() {
  17577. // Eat whitespace and comments.
  17578. var comment = false;
  17579. var ch = this.currentChar;
  17580. while (true) {
  17581. if (ch === -1) {
  17582. return null;
  17583. }
  17584. if (comment) {
  17585. if (ch === 0x0A || ch === 0x0D) {
  17586. comment = false;
  17587. }
  17588. } else if (ch === 0x25) { // '%'
  17589. comment = true;
  17590. } else if (!Lexer.isSpace(ch)) {
  17591. break;
  17592. }
  17593. ch = this.nextChar();
  17594. }
  17595. if (isSpecial(ch)) {
  17596. this.nextChar();
  17597. return String.fromCharCode(ch);
  17598. }
  17599. var token = '';
  17600. do {
  17601. token += String.fromCharCode(ch);
  17602. ch = this.nextChar();
  17603. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17604. return token;
  17605. },
  17606. /*
  17607. * Returns an object containing a Subrs array and a CharStrings
  17608. * array extracted from and eexec encrypted block of data
  17609. */
  17610. extractFontProgram: function Type1Parser_extractFontProgram() {
  17611. var stream = this.stream;
  17612. var subrs = [], charstrings = [];
  17613. var program = {
  17614. subrs: [],
  17615. charstrings: [],
  17616. properties: {
  17617. 'privateData': {
  17618. 'lenIV': 4
  17619. }
  17620. }
  17621. };
  17622. var token, length, data, lenIV, encoded;
  17623. while ((token = this.getToken()) !== null) {
  17624. if (token !== '/') {
  17625. continue;
  17626. }
  17627. token = this.getToken();
  17628. switch (token) {
  17629. case 'CharStrings':
  17630. // The number immediately following CharStrings must be greater or
  17631. // equal to the number of CharStrings.
  17632. this.getToken();
  17633. this.getToken(); // read in 'dict'
  17634. this.getToken(); // read in 'dup'
  17635. this.getToken(); // read in 'begin'
  17636. while(true) {
  17637. token = this.getToken();
  17638. if (token === null || token === 'end') {
  17639. break;
  17640. }
  17641. if (token !== '/') {
  17642. continue;
  17643. }
  17644. var glyph = this.getToken();
  17645. length = this.readInt();
  17646. this.getToken(); // read in 'RD' or '-|'
  17647. data = stream.makeSubStream(stream.pos, length);
  17648. lenIV = program.properties.privateData['lenIV'];
  17649. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17650. // Skip past the required space and binary data.
  17651. stream.skip(length);
  17652. this.nextChar();
  17653. token = this.getToken(); // read in 'ND' or '|-'
  17654. if (token === 'noaccess') {
  17655. this.getToken(); // read in 'def'
  17656. }
  17657. charstrings.push({
  17658. glyph: glyph,
  17659. encoded: encoded
  17660. });
  17661. }
  17662. break;
  17663. case 'Subrs':
  17664. var num = this.readInt();
  17665. this.getToken(); // read in 'array'
  17666. while ((token = this.getToken()) === 'dup') {
  17667. var index = this.readInt();
  17668. length = this.readInt();
  17669. this.getToken(); // read in 'RD' or '-|'
  17670. data = stream.makeSubStream(stream.pos, length);
  17671. lenIV = program.properties.privateData['lenIV'];
  17672. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17673. // Skip past the required space and binary data.
  17674. stream.skip(length);
  17675. this.nextChar();
  17676. token = this.getToken(); // read in 'NP' or '|'
  17677. if (token === 'noaccess') {
  17678. this.getToken(); // read in 'put'
  17679. }
  17680. subrs[index] = encoded;
  17681. }
  17682. break;
  17683. case 'BlueValues':
  17684. case 'OtherBlues':
  17685. case 'FamilyBlues':
  17686. case 'FamilyOtherBlues':
  17687. var blueArray = this.readNumberArray();
  17688. // *Blue* values may contain invalid data: disables reading of
  17689. // those values when hinting is disabled.
  17690. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17691. HINTING_ENABLED) {
  17692. program.properties.privateData[token] = blueArray;
  17693. }
  17694. break;
  17695. case 'StemSnapH':
  17696. case 'StemSnapV':
  17697. program.properties.privateData[token] = this.readNumberArray();
  17698. break;
  17699. case 'StdHW':
  17700. case 'StdVW':
  17701. program.properties.privateData[token] =
  17702. this.readNumberArray()[0];
  17703. break;
  17704. case 'BlueShift':
  17705. case 'lenIV':
  17706. case 'BlueFuzz':
  17707. case 'BlueScale':
  17708. case 'LanguageGroup':
  17709. case 'ExpansionFactor':
  17710. program.properties.privateData[token] = this.readNumber();
  17711. break;
  17712. case 'ForceBold':
  17713. program.properties.privateData[token] = this.readBoolean();
  17714. break;
  17715. }
  17716. }
  17717. for (var i = 0; i < charstrings.length; i++) {
  17718. glyph = charstrings[i].glyph;
  17719. encoded = charstrings[i].encoded;
  17720. var charString = new Type1CharString();
  17721. var error = charString.convert(encoded, subrs);
  17722. var output = charString.output;
  17723. if (error) {
  17724. // It seems when FreeType encounters an error while evaluating a glyph
  17725. // that it completely ignores the glyph so we'll mimic that behaviour
  17726. // here and put an endchar to make the validator happy.
  17727. output = [14];
  17728. }
  17729. program.charstrings.push({
  17730. glyphName: glyph,
  17731. charstring: output,
  17732. width: charString.width,
  17733. lsb: charString.lsb,
  17734. seac: charString.seac
  17735. });
  17736. }
  17737. return program;
  17738. },
  17739. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17740. var token;
  17741. while ((token = this.getToken()) !== null) {
  17742. if (token !== '/') {
  17743. continue;
  17744. }
  17745. token = this.getToken();
  17746. switch (token) {
  17747. case 'FontMatrix':
  17748. var matrix = this.readNumberArray();
  17749. properties.fontMatrix = matrix;
  17750. break;
  17751. case 'Encoding':
  17752. var encodingArg = this.getToken();
  17753. var encoding;
  17754. if (!/^\d+$/.test(encodingArg)) {
  17755. // encoding name is specified
  17756. encoding = Encodings[encodingArg];
  17757. } else {
  17758. encoding = [];
  17759. var size = parseInt(encodingArg, 10) | 0;
  17760. this.getToken(); // read in 'array'
  17761. for (var j = 0; j < size; j++) {
  17762. token = this.getToken();
  17763. // skipping till first dup or def (e.g. ignoring for statement)
  17764. while (token !== 'dup' && token !== 'def') {
  17765. token = this.getToken();
  17766. if (token === null) {
  17767. return; // invalid header
  17768. }
  17769. }
  17770. if (token === 'def') {
  17771. break; // read all array data
  17772. }
  17773. var index = this.readInt();
  17774. this.getToken(); // read in '/'
  17775. var glyph = this.getToken();
  17776. encoding[index] = glyph;
  17777. this.getToken(); // read the in 'put'
  17778. }
  17779. }
  17780. properties.builtInEncoding = encoding;
  17781. break;
  17782. case 'FontBBox':
  17783. var fontBBox = this.readNumberArray();
  17784. // adjusting ascent/descent
  17785. properties.ascent = fontBBox[3];
  17786. properties.descent = fontBBox[1];
  17787. properties.ascentScaled = true;
  17788. break;
  17789. }
  17790. }
  17791. }
  17792. };
  17793. return Type1Parser;
  17794. })();
  17795. /**
  17796. * The CFF class takes a Type1 file and wrap it into a
  17797. * 'Compact Font Format' which itself embed Type2 charstrings.
  17798. */
  17799. var CFFStandardStrings = [
  17800. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17801. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17802. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17803. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17804. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17805. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17806. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17807. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17808. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17809. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17810. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17811. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17812. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17813. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17814. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17815. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17816. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17817. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17818. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17819. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17820. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17821. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17822. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17823. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17824. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17825. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17826. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17827. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17828. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17829. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17830. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17831. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17832. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17833. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17834. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17835. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  17836. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  17837. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  17838. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  17839. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  17840. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  17841. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  17842. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  17843. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  17844. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  17845. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  17846. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  17847. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  17848. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  17849. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  17850. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  17851. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  17852. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  17853. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  17854. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  17855. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  17856. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  17857. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  17858. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  17859. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  17860. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  17861. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  17862. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  17863. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  17864. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  17865. ];
  17866. // Type1Font is also a CIDFontType0.
  17867. var Type1Font = function Type1Font(name, file, properties) {
  17868. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  17869. // Also, length1 and length2 might be off by 6 bytes as well.
  17870. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  17871. var PFB_HEADER_SIZE = 6;
  17872. var headerBlockLength = properties.length1;
  17873. var eexecBlockLength = properties.length2;
  17874. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  17875. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  17876. if (pfbHeaderPresent) {
  17877. file.skip(PFB_HEADER_SIZE);
  17878. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17879. (pfbHeader[3] << 8) | pfbHeader[2];
  17880. }
  17881. // Get the data block containing glyphs and subrs informations
  17882. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  17883. var headerBlockParser = new Type1Parser(headerBlock);
  17884. headerBlockParser.extractFontHeader(properties);
  17885. if (pfbHeaderPresent) {
  17886. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  17887. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17888. (pfbHeader[3] << 8) | pfbHeader[2];
  17889. }
  17890. // Decrypt the data blocks and retrieve it's content
  17891. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  17892. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  17893. var data = eexecBlockParser.extractFontProgram();
  17894. for (var info in data.properties) {
  17895. properties[info] = data.properties[info];
  17896. }
  17897. var charstrings = data.charstrings;
  17898. var type2Charstrings = this.getType2Charstrings(charstrings);
  17899. var subrs = this.getType2Subrs(data.subrs);
  17900. this.charstrings = charstrings;
  17901. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  17902. subrs, properties);
  17903. this.seacs = this.getSeacs(data.charstrings);
  17904. };
  17905. Type1Font.prototype = {
  17906. get numGlyphs() {
  17907. return this.charstrings.length + 1;
  17908. },
  17909. getCharset: function Type1Font_getCharset() {
  17910. var charset = ['.notdef'];
  17911. var charstrings = this.charstrings;
  17912. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17913. charset.push(charstrings[glyphId].glyphName);
  17914. }
  17915. return charset;
  17916. },
  17917. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  17918. var charstrings = this.charstrings;
  17919. var glyphNames = ['.notdef'], glyphId;
  17920. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17921. glyphNames.push(charstrings[glyphId].glyphName);
  17922. }
  17923. var encoding = properties.builtInEncoding;
  17924. if (encoding) {
  17925. var builtInEncoding = {};
  17926. for (var charCode in encoding) {
  17927. glyphId = glyphNames.indexOf(encoding[charCode]);
  17928. if (glyphId >= 0) {
  17929. builtInEncoding[charCode] = glyphId;
  17930. }
  17931. }
  17932. }
  17933. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  17934. },
  17935. getSeacs: function Type1Font_getSeacs(charstrings) {
  17936. var i, ii;
  17937. var seacMap = [];
  17938. for (i = 0, ii = charstrings.length; i < ii; i++) {
  17939. var charstring = charstrings[i];
  17940. if (charstring.seac) {
  17941. // Offset by 1 for .notdef
  17942. seacMap[i + 1] = charstring.seac;
  17943. }
  17944. }
  17945. return seacMap;
  17946. },
  17947. getType2Charstrings: function Type1Font_getType2Charstrings(
  17948. type1Charstrings) {
  17949. var type2Charstrings = [];
  17950. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  17951. type2Charstrings.push(type1Charstrings[i].charstring);
  17952. }
  17953. return type2Charstrings;
  17954. },
  17955. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  17956. var bias = 0;
  17957. var count = type1Subrs.length;
  17958. if (count < 1133) {
  17959. bias = 107;
  17960. } else if (count < 33769) {
  17961. bias = 1131;
  17962. } else {
  17963. bias = 32768;
  17964. }
  17965. // Add a bunch of empty subrs to deal with the Type2 bias
  17966. var type2Subrs = [];
  17967. var i;
  17968. for (i = 0; i < bias; i++) {
  17969. type2Subrs.push([0x0B]);
  17970. }
  17971. for (i = 0; i < count; i++) {
  17972. type2Subrs.push(type1Subrs[i]);
  17973. }
  17974. return type2Subrs;
  17975. },
  17976. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  17977. var cff = new CFF();
  17978. cff.header = new CFFHeader(1, 0, 4, 4);
  17979. cff.names = [name];
  17980. var topDict = new CFFTopDict();
  17981. // CFF strings IDs 0...390 are predefined names, so refering
  17982. // to entries in our own String INDEX starts at SID 391.
  17983. topDict.setByName('version', 391);
  17984. topDict.setByName('Notice', 392);
  17985. topDict.setByName('FullName', 393);
  17986. topDict.setByName('FamilyName', 394);
  17987. topDict.setByName('Weight', 395);
  17988. topDict.setByName('Encoding', null); // placeholder
  17989. topDict.setByName('FontMatrix', properties.fontMatrix);
  17990. topDict.setByName('FontBBox', properties.bbox);
  17991. topDict.setByName('charset', null); // placeholder
  17992. topDict.setByName('CharStrings', null); // placeholder
  17993. topDict.setByName('Private', null); // placeholder
  17994. cff.topDict = topDict;
  17995. var strings = new CFFStrings();
  17996. strings.add('Version 0.11'); // Version
  17997. strings.add('See original notice'); // Notice
  17998. strings.add(name); // FullName
  17999. strings.add(name); // FamilyName
  18000. strings.add('Medium'); // Weight
  18001. cff.strings = strings;
  18002. cff.globalSubrIndex = new CFFIndex();
  18003. var count = glyphs.length;
  18004. var charsetArray = [0];
  18005. var i, ii;
  18006. for (i = 0; i < count; i++) {
  18007. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18008. // TODO: Insert the string and correctly map it. Previously it was
  18009. // thought mapping names that aren't in the standard strings to .notdef
  18010. // was fine, however in issue818 when mapping them all to .notdef the
  18011. // adieresis glyph no longer worked.
  18012. if (index === -1) {
  18013. index = 0;
  18014. }
  18015. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18016. }
  18017. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18018. var charStringsIndex = new CFFIndex();
  18019. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18020. for (i = 0; i < count; i++) {
  18021. charStringsIndex.add(glyphs[i]);
  18022. }
  18023. cff.charStrings = charStringsIndex;
  18024. var privateDict = new CFFPrivateDict();
  18025. privateDict.setByName('Subrs', null); // placeholder
  18026. var fields = [
  18027. 'BlueValues',
  18028. 'OtherBlues',
  18029. 'FamilyBlues',
  18030. 'FamilyOtherBlues',
  18031. 'StemSnapH',
  18032. 'StemSnapV',
  18033. 'BlueShift',
  18034. 'BlueFuzz',
  18035. 'BlueScale',
  18036. 'LanguageGroup',
  18037. 'ExpansionFactor',
  18038. 'ForceBold',
  18039. 'StdHW',
  18040. 'StdVW'
  18041. ];
  18042. for (i = 0, ii = fields.length; i < ii; i++) {
  18043. var field = fields[i];
  18044. if (!properties.privateData.hasOwnProperty(field)) {
  18045. continue;
  18046. }
  18047. var value = properties.privateData[field];
  18048. if (isArray(value)) {
  18049. // All of the private dictionary array data in CFF must be stored as
  18050. // "delta-encoded" numbers.
  18051. for (var j = value.length - 1; j > 0; j--) {
  18052. value[j] -= value[j - 1]; // ... difference from previous value
  18053. }
  18054. }
  18055. privateDict.setByName(field, value);
  18056. }
  18057. cff.topDict.privateDict = privateDict;
  18058. var subrIndex = new CFFIndex();
  18059. for (i = 0, ii = subrs.length; i < ii; i++) {
  18060. subrIndex.add(subrs[i]);
  18061. }
  18062. privateDict.subrsIndex = subrIndex;
  18063. var compiler = new CFFCompiler(cff);
  18064. return compiler.compile();
  18065. }
  18066. };
  18067. var CFFFont = (function CFFFontClosure() {
  18068. function CFFFont(file, properties) {
  18069. this.properties = properties;
  18070. var parser = new CFFParser(file, properties);
  18071. this.cff = parser.parse();
  18072. var compiler = new CFFCompiler(this.cff);
  18073. this.seacs = this.cff.seacs;
  18074. try {
  18075. this.data = compiler.compile();
  18076. } catch (e) {
  18077. warn('Failed to compile font ' + properties.loadedName);
  18078. // There may have just been an issue with the compiler, set the data
  18079. // anyway and hope the font loaded.
  18080. this.data = file;
  18081. }
  18082. }
  18083. CFFFont.prototype = {
  18084. get numGlyphs() {
  18085. return this.cff.charStrings.count;
  18086. },
  18087. getCharset: function CFFFont_getCharset() {
  18088. return this.cff.charset.charset;
  18089. },
  18090. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18091. var cff = this.cff;
  18092. var properties = this.properties;
  18093. var charsets = cff.charset.charset;
  18094. var charCodeToGlyphId;
  18095. var glyphId;
  18096. if (properties.composite) {
  18097. charCodeToGlyphId = Object.create(null);
  18098. if (cff.isCIDFont) {
  18099. // If the font is actually a CID font then we should use the charset
  18100. // to map CIDs to GIDs.
  18101. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18102. var cid = charsets[glyphId];
  18103. var charCode = properties.cMap.charCodeOf(cid);
  18104. charCodeToGlyphId[charCode] = glyphId;
  18105. }
  18106. } else {
  18107. // If it is NOT actually a CID font then CIDs should be mapped
  18108. // directly to GIDs.
  18109. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18110. charCodeToGlyphId[glyphId] = glyphId;
  18111. }
  18112. }
  18113. return charCodeToGlyphId;
  18114. }
  18115. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18116. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18117. return charCodeToGlyphId;
  18118. }
  18119. };
  18120. return CFFFont;
  18121. })();
  18122. var CFFParser = (function CFFParserClosure() {
  18123. var CharstringValidationData = [
  18124. null,
  18125. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18126. null,
  18127. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18128. { id: 'vmoveto', min: 1, stackClearing: true },
  18129. { id: 'rlineto', min: 2, resetStack: true },
  18130. { id: 'hlineto', min: 1, resetStack: true },
  18131. { id: 'vlineto', min: 1, resetStack: true },
  18132. { id: 'rrcurveto', min: 6, resetStack: true },
  18133. null,
  18134. { id: 'callsubr', min: 1, undefStack: true },
  18135. { id: 'return', min: 0, undefStack: true },
  18136. null, // 12
  18137. null,
  18138. { id: 'endchar', min: 0, stackClearing: true },
  18139. null,
  18140. null,
  18141. null,
  18142. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18143. { id: 'hintmask', min: 0, stackClearing: true },
  18144. { id: 'cntrmask', min: 0, stackClearing: true },
  18145. { id: 'rmoveto', min: 2, stackClearing: true },
  18146. { id: 'hmoveto', min: 1, stackClearing: true },
  18147. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18148. { id: 'rcurveline', min: 8, resetStack: true },
  18149. { id: 'rlinecurve', min: 8, resetStack: true },
  18150. { id: 'vvcurveto', min: 4, resetStack: true },
  18151. { id: 'hhcurveto', min: 4, resetStack: true },
  18152. null, // shortint
  18153. { id: 'callgsubr', min: 1, undefStack: true },
  18154. { id: 'vhcurveto', min: 4, resetStack: true },
  18155. { id: 'hvcurveto', min: 4, resetStack: true }
  18156. ];
  18157. var CharstringValidationData12 = [
  18158. null,
  18159. null,
  18160. null,
  18161. { id: 'and', min: 2, stackDelta: -1 },
  18162. { id: 'or', min: 2, stackDelta: -1 },
  18163. { id: 'not', min: 1, stackDelta: 0 },
  18164. null,
  18165. null,
  18166. null,
  18167. { id: 'abs', min: 1, stackDelta: 0 },
  18168. { id: 'add', min: 2, stackDelta: -1,
  18169. stackFn: function stack_div(stack, index) {
  18170. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18171. }
  18172. },
  18173. { id: 'sub', min: 2, stackDelta: -1,
  18174. stackFn: function stack_div(stack, index) {
  18175. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18176. }
  18177. },
  18178. { id: 'div', min: 2, stackDelta: -1,
  18179. stackFn: function stack_div(stack, index) {
  18180. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18181. }
  18182. },
  18183. null,
  18184. { id: 'neg', min: 1, stackDelta: 0,
  18185. stackFn: function stack_div(stack, index) {
  18186. stack[index - 1] = -stack[index - 1];
  18187. }
  18188. },
  18189. { id: 'eq', min: 2, stackDelta: -1 },
  18190. null,
  18191. null,
  18192. { id: 'drop', min: 1, stackDelta: -1 },
  18193. null,
  18194. { id: 'put', min: 2, stackDelta: -2 },
  18195. { id: 'get', min: 1, stackDelta: 0 },
  18196. { id: 'ifelse', min: 4, stackDelta: -3 },
  18197. { id: 'random', min: 0, stackDelta: 1 },
  18198. { id: 'mul', min: 2, stackDelta: -1,
  18199. stackFn: function stack_div(stack, index) {
  18200. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18201. }
  18202. },
  18203. null,
  18204. { id: 'sqrt', min: 1, stackDelta: 0 },
  18205. { id: 'dup', min: 1, stackDelta: 1 },
  18206. { id: 'exch', min: 2, stackDelta: 0 },
  18207. { id: 'index', min: 2, stackDelta: 0 },
  18208. { id: 'roll', min: 3, stackDelta: -2 },
  18209. null,
  18210. null,
  18211. null,
  18212. { id: 'hflex', min: 7, resetStack: true },
  18213. { id: 'flex', min: 13, resetStack: true },
  18214. { id: 'hflex1', min: 9, resetStack: true },
  18215. { id: 'flex1', min: 11, resetStack: true }
  18216. ];
  18217. function CFFParser(file, properties) {
  18218. this.bytes = file.getBytes();
  18219. this.properties = properties;
  18220. }
  18221. CFFParser.prototype = {
  18222. parse: function CFFParser_parse() {
  18223. var properties = this.properties;
  18224. var cff = new CFF();
  18225. this.cff = cff;
  18226. // The first five sections must be in order, all the others are reached
  18227. // via offsets contained in one of the below.
  18228. var header = this.parseHeader();
  18229. var nameIndex = this.parseIndex(header.endPos);
  18230. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18231. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18232. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18233. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18234. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18235. cff.header = header.obj;
  18236. cff.names = this.parseNameIndex(nameIndex.obj);
  18237. cff.strings = this.parseStringIndex(stringIndex.obj);
  18238. cff.topDict = topDict;
  18239. cff.globalSubrIndex = globalSubrIndex.obj;
  18240. this.parsePrivateDict(cff.topDict);
  18241. cff.isCIDFont = topDict.hasName('ROS');
  18242. var charStringOffset = topDict.getByName('CharStrings');
  18243. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18244. cff.charStrings = charStringsAndSeacs.charStrings;
  18245. cff.seacs = charStringsAndSeacs.seacs;
  18246. cff.widths = charStringsAndSeacs.widths;
  18247. var fontMatrix = topDict.getByName('FontMatrix');
  18248. if (fontMatrix) {
  18249. properties.fontMatrix = fontMatrix;
  18250. }
  18251. var fontBBox = topDict.getByName('FontBBox');
  18252. if (fontBBox) {
  18253. // adjusting ascent/descent
  18254. properties.ascent = fontBBox[3];
  18255. properties.descent = fontBBox[1];
  18256. properties.ascentScaled = true;
  18257. }
  18258. var charset, encoding;
  18259. if (cff.isCIDFont) {
  18260. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18261. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18262. var dictRaw = fdArrayIndex.get(i);
  18263. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18264. cff.strings);
  18265. this.parsePrivateDict(fontDict);
  18266. cff.fdArray.push(fontDict);
  18267. }
  18268. // cid fonts don't have an encoding
  18269. encoding = null;
  18270. charset = this.parseCharsets(topDict.getByName('charset'),
  18271. cff.charStrings.count, cff.strings, true);
  18272. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18273. cff.charStrings.count);
  18274. } else {
  18275. charset = this.parseCharsets(topDict.getByName('charset'),
  18276. cff.charStrings.count, cff.strings, false);
  18277. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18278. properties,
  18279. cff.strings, charset.charset);
  18280. }
  18281. cff.charset = charset;
  18282. cff.encoding = encoding;
  18283. return cff;
  18284. },
  18285. parseHeader: function CFFParser_parseHeader() {
  18286. var bytes = this.bytes;
  18287. var bytesLength = bytes.length;
  18288. var offset = 0;
  18289. // Prevent an infinite loop, by checking that the offset is within the
  18290. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18291. while (offset < bytesLength && bytes[offset] !== 1) {
  18292. ++offset;
  18293. }
  18294. if (offset >= bytesLength) {
  18295. error('Invalid CFF header');
  18296. } else if (offset !== 0) {
  18297. info('cff data is shifted');
  18298. bytes = bytes.subarray(offset);
  18299. this.bytes = bytes;
  18300. }
  18301. var major = bytes[0];
  18302. var minor = bytes[1];
  18303. var hdrSize = bytes[2];
  18304. var offSize = bytes[3];
  18305. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18306. return { obj: header, endPos: hdrSize };
  18307. },
  18308. parseDict: function CFFParser_parseDict(dict) {
  18309. var pos = 0;
  18310. function parseOperand() {
  18311. var value = dict[pos++];
  18312. if (value === 30) {
  18313. return parseFloatOperand(pos);
  18314. } else if (value === 28) {
  18315. value = dict[pos++];
  18316. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18317. return value;
  18318. } else if (value === 29) {
  18319. value = dict[pos++];
  18320. value = (value << 8) | dict[pos++];
  18321. value = (value << 8) | dict[pos++];
  18322. value = (value << 8) | dict[pos++];
  18323. return value;
  18324. } else if (value >= 32 && value <= 246) {
  18325. return value - 139;
  18326. } else if (value >= 247 && value <= 250) {
  18327. return ((value - 247) * 256) + dict[pos++] + 108;
  18328. } else if (value >= 251 && value <= 254) {
  18329. return -((value - 251) * 256) - dict[pos++] - 108;
  18330. } else {
  18331. error('255 is not a valid DICT command');
  18332. }
  18333. return -1;
  18334. }
  18335. function parseFloatOperand() {
  18336. var str = '';
  18337. var eof = 15;
  18338. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18339. '9', '.', 'E', 'E-', null, '-'];
  18340. var length = dict.length;
  18341. while (pos < length) {
  18342. var b = dict[pos++];
  18343. var b1 = b >> 4;
  18344. var b2 = b & 15;
  18345. if (b1 === eof) {
  18346. break;
  18347. }
  18348. str += lookup[b1];
  18349. if (b2 === eof) {
  18350. break;
  18351. }
  18352. str += lookup[b2];
  18353. }
  18354. return parseFloat(str);
  18355. }
  18356. var operands = [];
  18357. var entries = [];
  18358. pos = 0;
  18359. var end = dict.length;
  18360. while (pos < end) {
  18361. var b = dict[pos];
  18362. if (b <= 21) {
  18363. if (b === 12) {
  18364. b = (b << 8) | dict[++pos];
  18365. }
  18366. entries.push([b, operands]);
  18367. operands = [];
  18368. ++pos;
  18369. } else {
  18370. operands.push(parseOperand());
  18371. }
  18372. }
  18373. return entries;
  18374. },
  18375. parseIndex: function CFFParser_parseIndex(pos) {
  18376. var cffIndex = new CFFIndex();
  18377. var bytes = this.bytes;
  18378. var count = (bytes[pos++] << 8) | bytes[pos++];
  18379. var offsets = [];
  18380. var end = pos;
  18381. var i, ii;
  18382. if (count !== 0) {
  18383. var offsetSize = bytes[pos++];
  18384. // add 1 for offset to determine size of last object
  18385. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18386. for (i = 0, ii = count + 1; i < ii; ++i) {
  18387. var offset = 0;
  18388. for (var j = 0; j < offsetSize; ++j) {
  18389. offset <<= 8;
  18390. offset += bytes[pos++];
  18391. }
  18392. offsets.push(startPos + offset);
  18393. }
  18394. end = offsets[count];
  18395. }
  18396. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18397. var offsetStart = offsets[i];
  18398. var offsetEnd = offsets[i + 1];
  18399. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18400. }
  18401. return {obj: cffIndex, endPos: end};
  18402. },
  18403. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18404. var names = [];
  18405. for (var i = 0, ii = index.count; i < ii; ++i) {
  18406. var name = index.get(i);
  18407. // OTS doesn't allow names to be over 127 characters.
  18408. var length = Math.min(name.length, 127);
  18409. var data = [];
  18410. // OTS also only permits certain characters in the name.
  18411. for (var j = 0; j < length; ++j) {
  18412. var c = name[j];
  18413. if (j === 0 && c === 0) {
  18414. data[j] = c;
  18415. continue;
  18416. }
  18417. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18418. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18419. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18420. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18421. data[j] = 95;
  18422. continue;
  18423. }
  18424. data[j] = c;
  18425. }
  18426. names.push(bytesToString(data));
  18427. }
  18428. return names;
  18429. },
  18430. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18431. var strings = new CFFStrings();
  18432. for (var i = 0, ii = index.count; i < ii; ++i) {
  18433. var data = index.get(i);
  18434. strings.add(bytesToString(data));
  18435. }
  18436. return strings;
  18437. },
  18438. createDict: function CFFParser_createDict(Type, dict, strings) {
  18439. var cffDict = new Type(strings);
  18440. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18441. var pair = dict[i];
  18442. var key = pair[0];
  18443. var value = pair[1];
  18444. cffDict.setByKey(key, value);
  18445. }
  18446. return cffDict;
  18447. },
  18448. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18449. var charStrings = this.parseIndex(charStringOffset).obj;
  18450. var seacs = [];
  18451. var widths = [];
  18452. var count = charStrings.count;
  18453. for (var i = 0; i < count; i++) {
  18454. var charstring = charStrings.get(i);
  18455. var stackSize = 0;
  18456. var stack = [];
  18457. var undefStack = true;
  18458. var hints = 0;
  18459. var valid = true;
  18460. var data = charstring;
  18461. var length = data.length;
  18462. var firstStackClearing = true;
  18463. for (var j = 0; j < length;) {
  18464. var value = data[j++];
  18465. var validationCommand = null;
  18466. if (value === 12) {
  18467. var q = data[j++];
  18468. if (q === 0) {
  18469. // The CFF specification state that the 'dotsection' command
  18470. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18471. // charstrings processors should support them. Unfortunately
  18472. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18473. // is replaced by a useless (0, hmoveto).
  18474. data[j - 2] = 139;
  18475. data[j - 1] = 22;
  18476. stackSize = 0;
  18477. } else {
  18478. validationCommand = CharstringValidationData12[q];
  18479. }
  18480. } else if (value === 28) { // number (16 bit)
  18481. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18482. j += 2;
  18483. stackSize++;
  18484. } else if (value === 14) {
  18485. if (stackSize >= 4) {
  18486. stackSize -= 4;
  18487. if (SEAC_ANALYSIS_ENABLED) {
  18488. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18489. valid = false;
  18490. }
  18491. }
  18492. validationCommand = CharstringValidationData[value];
  18493. } else if (value >= 32 && value <= 246) { // number
  18494. stack[stackSize] = value - 139;
  18495. stackSize++;
  18496. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18497. stack[stackSize] = (value < 251 ?
  18498. ((value - 247) << 8) + data[j] + 108 :
  18499. -((value - 251) << 8) - data[j] - 108);
  18500. j++;
  18501. stackSize++;
  18502. } else if (value === 255) { // number (32 bit)
  18503. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18504. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18505. j += 4;
  18506. stackSize++;
  18507. } else if (value === 19 || value === 20) {
  18508. hints += stackSize >> 1;
  18509. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18510. stackSize %= 2;
  18511. validationCommand = CharstringValidationData[value];
  18512. } else {
  18513. validationCommand = CharstringValidationData[value];
  18514. }
  18515. if (validationCommand) {
  18516. if (validationCommand.stem) {
  18517. hints += stackSize >> 1;
  18518. }
  18519. if ('min' in validationCommand) {
  18520. if (!undefStack && stackSize < validationCommand.min) {
  18521. warn('Not enough parameters for ' + validationCommand.id +
  18522. '; actual: ' + stackSize +
  18523. ', expected: ' + validationCommand.min);
  18524. valid = false;
  18525. break;
  18526. }
  18527. }
  18528. if (firstStackClearing && validationCommand.stackClearing) {
  18529. firstStackClearing = false;
  18530. // the optional character width can be found before the first
  18531. // stack-clearing command arguments
  18532. stackSize -= validationCommand.min;
  18533. if (stackSize >= 2 && validationCommand.stem) {
  18534. // there are even amount of arguments for stem commands
  18535. stackSize %= 2;
  18536. } else if (stackSize > 1) {
  18537. warn('Found too many parameters for stack-clearing command');
  18538. }
  18539. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18540. widths[i] = stack[stackSize - 1];
  18541. }
  18542. }
  18543. if ('stackDelta' in validationCommand) {
  18544. if ('stackFn' in validationCommand) {
  18545. validationCommand.stackFn(stack, stackSize);
  18546. }
  18547. stackSize += validationCommand.stackDelta;
  18548. } else if (validationCommand.stackClearing) {
  18549. stackSize = 0;
  18550. } else if (validationCommand.resetStack) {
  18551. stackSize = 0;
  18552. undefStack = false;
  18553. } else if (validationCommand.undefStack) {
  18554. stackSize = 0;
  18555. undefStack = true;
  18556. firstStackClearing = false;
  18557. }
  18558. }
  18559. }
  18560. if (!valid) {
  18561. // resetting invalid charstring to single 'endchar'
  18562. charStrings.set(i, new Uint8Array([14]));
  18563. }
  18564. }
  18565. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18566. },
  18567. emptyPrivateDictionary:
  18568. function CFFParser_emptyPrivateDictionary(parentDict) {
  18569. var privateDict = this.createDict(CFFPrivateDict, [],
  18570. parentDict.strings);
  18571. parentDict.setByKey(18, [0, 0]);
  18572. parentDict.privateDict = privateDict;
  18573. },
  18574. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18575. // no private dict, do nothing
  18576. if (!parentDict.hasName('Private')) {
  18577. this.emptyPrivateDictionary(parentDict);
  18578. return;
  18579. }
  18580. var privateOffset = parentDict.getByName('Private');
  18581. // make sure the params are formatted correctly
  18582. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18583. parentDict.removeByName('Private');
  18584. return;
  18585. }
  18586. var size = privateOffset[0];
  18587. var offset = privateOffset[1];
  18588. // remove empty dicts or ones that refer to invalid location
  18589. if (size === 0 || offset >= this.bytes.length) {
  18590. this.emptyPrivateDictionary(parentDict);
  18591. return;
  18592. }
  18593. var privateDictEnd = offset + size;
  18594. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18595. var dict = this.parseDict(dictData);
  18596. var privateDict = this.createDict(CFFPrivateDict, dict,
  18597. parentDict.strings);
  18598. parentDict.privateDict = privateDict;
  18599. // Parse the Subrs index also since it's relative to the private dict.
  18600. if (!privateDict.getByName('Subrs')) {
  18601. return;
  18602. }
  18603. var subrsOffset = privateDict.getByName('Subrs');
  18604. var relativeOffset = offset + subrsOffset;
  18605. // Validate the offset.
  18606. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18607. this.emptyPrivateDictionary(parentDict);
  18608. return;
  18609. }
  18610. var subrsIndex = this.parseIndex(relativeOffset);
  18611. privateDict.subrsIndex = subrsIndex.obj;
  18612. },
  18613. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18614. if (pos === 0) {
  18615. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18616. ISOAdobeCharset);
  18617. } else if (pos === 1) {
  18618. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18619. ExpertCharset);
  18620. } else if (pos === 2) {
  18621. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18622. ExpertSubsetCharset);
  18623. }
  18624. var bytes = this.bytes;
  18625. var start = pos;
  18626. var format = bytes[pos++];
  18627. var charset = ['.notdef'];
  18628. var id, count, i;
  18629. // subtract 1 for the .notdef glyph
  18630. length -= 1;
  18631. switch (format) {
  18632. case 0:
  18633. for (i = 0; i < length; i++) {
  18634. id = (bytes[pos++] << 8) | bytes[pos++];
  18635. charset.push(cid ? id : strings.get(id));
  18636. }
  18637. break;
  18638. case 1:
  18639. while (charset.length <= length) {
  18640. id = (bytes[pos++] << 8) | bytes[pos++];
  18641. count = bytes[pos++];
  18642. for (i = 0; i <= count; i++) {
  18643. charset.push(cid ? id++ : strings.get(id++));
  18644. }
  18645. }
  18646. break;
  18647. case 2:
  18648. while (charset.length <= length) {
  18649. id = (bytes[pos++] << 8) | bytes[pos++];
  18650. count = (bytes[pos++] << 8) | bytes[pos++];
  18651. for (i = 0; i <= count; i++) {
  18652. charset.push(cid ? id++ : strings.get(id++));
  18653. }
  18654. }
  18655. break;
  18656. default:
  18657. error('Unknown charset format');
  18658. }
  18659. // Raw won't be needed if we actually compile the charset.
  18660. var end = pos;
  18661. var raw = bytes.subarray(start, end);
  18662. return new CFFCharset(false, format, charset, raw);
  18663. },
  18664. parseEncoding: function CFFParser_parseEncoding(pos,
  18665. properties,
  18666. strings,
  18667. charset) {
  18668. var encoding = {};
  18669. var bytes = this.bytes;
  18670. var predefined = false;
  18671. var hasSupplement = false;
  18672. var format, i, ii;
  18673. var raw = null;
  18674. function readSupplement() {
  18675. var supplementsCount = bytes[pos++];
  18676. for (i = 0; i < supplementsCount; i++) {
  18677. var code = bytes[pos++];
  18678. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18679. encoding[code] = charset.indexOf(strings.get(sid));
  18680. }
  18681. }
  18682. if (pos === 0 || pos === 1) {
  18683. predefined = true;
  18684. format = pos;
  18685. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18686. Encodings.StandardEncoding;
  18687. for (i = 0, ii = charset.length; i < ii; i++) {
  18688. var index = baseEncoding.indexOf(charset[i]);
  18689. if (index !== -1) {
  18690. encoding[index] = i;
  18691. }
  18692. }
  18693. } else {
  18694. var dataStart = pos;
  18695. format = bytes[pos++];
  18696. switch (format & 0x7f) {
  18697. case 0:
  18698. var glyphsCount = bytes[pos++];
  18699. for (i = 1; i <= glyphsCount; i++) {
  18700. encoding[bytes[pos++]] = i;
  18701. }
  18702. break;
  18703. case 1:
  18704. var rangesCount = bytes[pos++];
  18705. var gid = 1;
  18706. for (i = 0; i < rangesCount; i++) {
  18707. var start = bytes[pos++];
  18708. var left = bytes[pos++];
  18709. for (var j = start; j <= start + left; j++) {
  18710. encoding[j] = gid++;
  18711. }
  18712. }
  18713. break;
  18714. default:
  18715. error('Unknow encoding format: ' + format + ' in CFF');
  18716. break;
  18717. }
  18718. var dataEnd = pos;
  18719. if (format & 0x80) {
  18720. // The font sanitizer does not support CFF encoding with a
  18721. // supplement, since the encoding is not really used to map
  18722. // between gid to glyph, let's overwrite what is declared in
  18723. // the top dictionary to let the sanitizer think the font use
  18724. // StandardEncoding, that's a lie but that's ok.
  18725. bytes[dataStart] &= 0x7f;
  18726. readSupplement();
  18727. hasSupplement = true;
  18728. }
  18729. raw = bytes.subarray(dataStart, dataEnd);
  18730. }
  18731. format = format & 0x7f;
  18732. return new CFFEncoding(predefined, format, encoding, raw);
  18733. },
  18734. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18735. var start = pos;
  18736. var bytes = this.bytes;
  18737. var format = bytes[pos++];
  18738. var fdSelect = [];
  18739. var i;
  18740. switch (format) {
  18741. case 0:
  18742. for (i = 0; i < length; ++i) {
  18743. var id = bytes[pos++];
  18744. fdSelect.push(id);
  18745. }
  18746. break;
  18747. case 3:
  18748. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18749. for (i = 0; i < rangesCount; ++i) {
  18750. var first = (bytes[pos++] << 8) | bytes[pos++];
  18751. var fdIndex = bytes[pos++];
  18752. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18753. for (var j = first; j < next; ++j) {
  18754. fdSelect.push(fdIndex);
  18755. }
  18756. }
  18757. // Advance past the sentinel(next).
  18758. pos += 2;
  18759. break;
  18760. default:
  18761. error('Unknown fdselect format ' + format);
  18762. break;
  18763. }
  18764. var end = pos;
  18765. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18766. }
  18767. };
  18768. return CFFParser;
  18769. })();
  18770. // Compact Font Format
  18771. var CFF = (function CFFClosure() {
  18772. function CFF() {
  18773. this.header = null;
  18774. this.names = [];
  18775. this.topDict = null;
  18776. this.strings = new CFFStrings();
  18777. this.globalSubrIndex = null;
  18778. // The following could really be per font, but since we only have one font
  18779. // store them here.
  18780. this.encoding = null;
  18781. this.charset = null;
  18782. this.charStrings = null;
  18783. this.fdArray = [];
  18784. this.fdSelect = null;
  18785. this.isCIDFont = false;
  18786. }
  18787. return CFF;
  18788. })();
  18789. var CFFHeader = (function CFFHeaderClosure() {
  18790. function CFFHeader(major, minor, hdrSize, offSize) {
  18791. this.major = major;
  18792. this.minor = minor;
  18793. this.hdrSize = hdrSize;
  18794. this.offSize = offSize;
  18795. }
  18796. return CFFHeader;
  18797. })();
  18798. var CFFStrings = (function CFFStringsClosure() {
  18799. function CFFStrings() {
  18800. this.strings = [];
  18801. }
  18802. CFFStrings.prototype = {
  18803. get: function CFFStrings_get(index) {
  18804. if (index >= 0 && index <= 390) {
  18805. return CFFStandardStrings[index];
  18806. }
  18807. if (index - 391 <= this.strings.length) {
  18808. return this.strings[index - 391];
  18809. }
  18810. return CFFStandardStrings[0];
  18811. },
  18812. add: function CFFStrings_add(value) {
  18813. this.strings.push(value);
  18814. },
  18815. get count() {
  18816. return this.strings.length;
  18817. }
  18818. };
  18819. return CFFStrings;
  18820. })();
  18821. var CFFIndex = (function CFFIndexClosure() {
  18822. function CFFIndex() {
  18823. this.objects = [];
  18824. this.length = 0;
  18825. }
  18826. CFFIndex.prototype = {
  18827. add: function CFFIndex_add(data) {
  18828. this.length += data.length;
  18829. this.objects.push(data);
  18830. },
  18831. set: function CFFIndex_set(index, data) {
  18832. this.length += data.length - this.objects[index].length;
  18833. this.objects[index] = data;
  18834. },
  18835. get: function CFFIndex_get(index) {
  18836. return this.objects[index];
  18837. },
  18838. get count() {
  18839. return this.objects.length;
  18840. }
  18841. };
  18842. return CFFIndex;
  18843. })();
  18844. var CFFDict = (function CFFDictClosure() {
  18845. function CFFDict(tables, strings) {
  18846. this.keyToNameMap = tables.keyToNameMap;
  18847. this.nameToKeyMap = tables.nameToKeyMap;
  18848. this.defaults = tables.defaults;
  18849. this.types = tables.types;
  18850. this.opcodes = tables.opcodes;
  18851. this.order = tables.order;
  18852. this.strings = strings;
  18853. this.values = {};
  18854. }
  18855. CFFDict.prototype = {
  18856. // value should always be an array
  18857. setByKey: function CFFDict_setByKey(key, value) {
  18858. if (!(key in this.keyToNameMap)) {
  18859. return false;
  18860. }
  18861. // ignore empty values
  18862. if (value.length === 0) {
  18863. return true;
  18864. }
  18865. var type = this.types[key];
  18866. // remove the array wrapping these types of values
  18867. if (type === 'num' || type === 'sid' || type === 'offset') {
  18868. value = value[0];
  18869. }
  18870. this.values[key] = value;
  18871. return true;
  18872. },
  18873. setByName: function CFFDict_setByName(name, value) {
  18874. if (!(name in this.nameToKeyMap)) {
  18875. error('Invalid dictionary name "' + name + '"');
  18876. }
  18877. this.values[this.nameToKeyMap[name]] = value;
  18878. },
  18879. hasName: function CFFDict_hasName(name) {
  18880. return this.nameToKeyMap[name] in this.values;
  18881. },
  18882. getByName: function CFFDict_getByName(name) {
  18883. if (!(name in this.nameToKeyMap)) {
  18884. error('Invalid dictionary name "' + name + '"');
  18885. }
  18886. var key = this.nameToKeyMap[name];
  18887. if (!(key in this.values)) {
  18888. return this.defaults[key];
  18889. }
  18890. return this.values[key];
  18891. },
  18892. removeByName: function CFFDict_removeByName(name) {
  18893. delete this.values[this.nameToKeyMap[name]];
  18894. }
  18895. };
  18896. CFFDict.createTables = function CFFDict_createTables(layout) {
  18897. var tables = {
  18898. keyToNameMap: {},
  18899. nameToKeyMap: {},
  18900. defaults: {},
  18901. types: {},
  18902. opcodes: {},
  18903. order: []
  18904. };
  18905. for (var i = 0, ii = layout.length; i < ii; ++i) {
  18906. var entry = layout[i];
  18907. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  18908. tables.keyToNameMap[key] = entry[1];
  18909. tables.nameToKeyMap[entry[1]] = key;
  18910. tables.types[key] = entry[2];
  18911. tables.defaults[key] = entry[3];
  18912. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  18913. tables.order.push(key);
  18914. }
  18915. return tables;
  18916. };
  18917. return CFFDict;
  18918. })();
  18919. var CFFTopDict = (function CFFTopDictClosure() {
  18920. var layout = [
  18921. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  18922. [[12, 20], 'SyntheticBase', 'num', null],
  18923. [0, 'version', 'sid', null],
  18924. [1, 'Notice', 'sid', null],
  18925. [[12, 0], 'Copyright', 'sid', null],
  18926. [2, 'FullName', 'sid', null],
  18927. [3, 'FamilyName', 'sid', null],
  18928. [4, 'Weight', 'sid', null],
  18929. [[12, 1], 'isFixedPitch', 'num', 0],
  18930. [[12, 2], 'ItalicAngle', 'num', 0],
  18931. [[12, 3], 'UnderlinePosition', 'num', -100],
  18932. [[12, 4], 'UnderlineThickness', 'num', 50],
  18933. [[12, 5], 'PaintType', 'num', 0],
  18934. [[12, 6], 'CharstringType', 'num', 2],
  18935. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  18936. [0.001, 0, 0, 0.001, 0, 0]],
  18937. [13, 'UniqueID', 'num', null],
  18938. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  18939. [[12, 8], 'StrokeWidth', 'num', 0],
  18940. [14, 'XUID', 'array', null],
  18941. [15, 'charset', 'offset', 0],
  18942. [16, 'Encoding', 'offset', 0],
  18943. [17, 'CharStrings', 'offset', 0],
  18944. [18, 'Private', ['offset', 'offset'], null],
  18945. [[12, 21], 'PostScript', 'sid', null],
  18946. [[12, 22], 'BaseFontName', 'sid', null],
  18947. [[12, 23], 'BaseFontBlend', 'delta', null],
  18948. [[12, 31], 'CIDFontVersion', 'num', 0],
  18949. [[12, 32], 'CIDFontRevision', 'num', 0],
  18950. [[12, 33], 'CIDFontType', 'num', 0],
  18951. [[12, 34], 'CIDCount', 'num', 8720],
  18952. [[12, 35], 'UIDBase', 'num', null],
  18953. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  18954. // before FDArray.
  18955. [[12, 37], 'FDSelect', 'offset', null],
  18956. [[12, 36], 'FDArray', 'offset', null],
  18957. [[12, 38], 'FontName', 'sid', null]
  18958. ];
  18959. var tables = null;
  18960. function CFFTopDict(strings) {
  18961. if (tables === null) {
  18962. tables = CFFDict.createTables(layout);
  18963. }
  18964. CFFDict.call(this, tables, strings);
  18965. this.privateDict = null;
  18966. }
  18967. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  18968. return CFFTopDict;
  18969. })();
  18970. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  18971. var layout = [
  18972. [6, 'BlueValues', 'delta', null],
  18973. [7, 'OtherBlues', 'delta', null],
  18974. [8, 'FamilyBlues', 'delta', null],
  18975. [9, 'FamilyOtherBlues', 'delta', null],
  18976. [[12, 9], 'BlueScale', 'num', 0.039625],
  18977. [[12, 10], 'BlueShift', 'num', 7],
  18978. [[12, 11], 'BlueFuzz', 'num', 1],
  18979. [10, 'StdHW', 'num', null],
  18980. [11, 'StdVW', 'num', null],
  18981. [[12, 12], 'StemSnapH', 'delta', null],
  18982. [[12, 13], 'StemSnapV', 'delta', null],
  18983. [[12, 14], 'ForceBold', 'num', 0],
  18984. [[12, 17], 'LanguageGroup', 'num', 0],
  18985. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  18986. [[12, 19], 'initialRandomSeed', 'num', 0],
  18987. [20, 'defaultWidthX', 'num', 0],
  18988. [21, 'nominalWidthX', 'num', 0],
  18989. [19, 'Subrs', 'offset', null]
  18990. ];
  18991. var tables = null;
  18992. function CFFPrivateDict(strings) {
  18993. if (tables === null) {
  18994. tables = CFFDict.createTables(layout);
  18995. }
  18996. CFFDict.call(this, tables, strings);
  18997. this.subrsIndex = null;
  18998. }
  18999. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19000. return CFFPrivateDict;
  19001. })();
  19002. var CFFCharsetPredefinedTypes = {
  19003. ISO_ADOBE: 0,
  19004. EXPERT: 1,
  19005. EXPERT_SUBSET: 2
  19006. };
  19007. var CFFCharset = (function CFFCharsetClosure() {
  19008. function CFFCharset(predefined, format, charset, raw) {
  19009. this.predefined = predefined;
  19010. this.format = format;
  19011. this.charset = charset;
  19012. this.raw = raw;
  19013. }
  19014. return CFFCharset;
  19015. })();
  19016. var CFFEncoding = (function CFFEncodingClosure() {
  19017. function CFFEncoding(predefined, format, encoding, raw) {
  19018. this.predefined = predefined;
  19019. this.format = format;
  19020. this.encoding = encoding;
  19021. this.raw = raw;
  19022. }
  19023. return CFFEncoding;
  19024. })();
  19025. var CFFFDSelect = (function CFFFDSelectClosure() {
  19026. function CFFFDSelect(fdSelect, raw) {
  19027. this.fdSelect = fdSelect;
  19028. this.raw = raw;
  19029. }
  19030. return CFFFDSelect;
  19031. })();
  19032. // Helper class to keep track of where an offset is within the data and helps
  19033. // filling in that offset once it's known.
  19034. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19035. function CFFOffsetTracker() {
  19036. this.offsets = {};
  19037. }
  19038. CFFOffsetTracker.prototype = {
  19039. isTracking: function CFFOffsetTracker_isTracking(key) {
  19040. return key in this.offsets;
  19041. },
  19042. track: function CFFOffsetTracker_track(key, location) {
  19043. if (key in this.offsets) {
  19044. error('Already tracking location of ' + key);
  19045. }
  19046. this.offsets[key] = location;
  19047. },
  19048. offset: function CFFOffsetTracker_offset(value) {
  19049. for (var key in this.offsets) {
  19050. this.offsets[key] += value;
  19051. }
  19052. },
  19053. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19054. values,
  19055. output) {
  19056. if (!(key in this.offsets)) {
  19057. error('Not tracking location of ' + key);
  19058. }
  19059. var data = output.data;
  19060. var dataOffset = this.offsets[key];
  19061. var size = 5;
  19062. for (var i = 0, ii = values.length; i < ii; ++i) {
  19063. var offset0 = i * size + dataOffset;
  19064. var offset1 = offset0 + 1;
  19065. var offset2 = offset0 + 2;
  19066. var offset3 = offset0 + 3;
  19067. var offset4 = offset0 + 4;
  19068. // It's easy to screw up offsets so perform this sanity check.
  19069. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19070. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19071. error('writing to an offset that is not empty');
  19072. }
  19073. var value = values[i];
  19074. data[offset0] = 0x1d;
  19075. data[offset1] = (value >> 24) & 0xFF;
  19076. data[offset2] = (value >> 16) & 0xFF;
  19077. data[offset3] = (value >> 8) & 0xFF;
  19078. data[offset4] = value & 0xFF;
  19079. }
  19080. }
  19081. };
  19082. return CFFOffsetTracker;
  19083. })();
  19084. // Takes a CFF and converts it to the binary representation.
  19085. var CFFCompiler = (function CFFCompilerClosure() {
  19086. function CFFCompiler(cff) {
  19087. this.cff = cff;
  19088. }
  19089. CFFCompiler.prototype = {
  19090. compile: function CFFCompiler_compile() {
  19091. var cff = this.cff;
  19092. var output = {
  19093. data: [],
  19094. length: 0,
  19095. add: function CFFCompiler_add(data) {
  19096. this.data = this.data.concat(data);
  19097. this.length = this.data.length;
  19098. }
  19099. };
  19100. // Compile the five entries that must be in order.
  19101. var header = this.compileHeader(cff.header);
  19102. output.add(header);
  19103. var nameIndex = this.compileNameIndex(cff.names);
  19104. output.add(nameIndex);
  19105. if (cff.isCIDFont) {
  19106. // The spec is unclear on how font matrices should relate to each other
  19107. // when there is one in the main top dict and the sub top dicts.
  19108. // Windows handles this differently than linux and osx so we have to
  19109. // normalize to work on all.
  19110. // Rules based off of some mailing list discussions:
  19111. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19112. // - If no main font matrix and there is a subfont matrix, use the
  19113. // subfont matrix.
  19114. // - If both have matrices, concat together.
  19115. // - If neither have matrices, use default.
  19116. // To make this work on all platforms we move the top matrix into each
  19117. // sub top dict and concat if necessary.
  19118. if (cff.topDict.hasName('FontMatrix')) {
  19119. var base = cff.topDict.getByName('FontMatrix');
  19120. cff.topDict.removeByName('FontMatrix');
  19121. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19122. var subDict = cff.fdArray[i];
  19123. var matrix = base.slice(0);
  19124. if (subDict.hasName('FontMatrix')) {
  19125. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19126. }
  19127. subDict.setByName('FontMatrix', matrix);
  19128. }
  19129. }
  19130. }
  19131. var compiled = this.compileTopDicts([cff.topDict],
  19132. output.length,
  19133. cff.isCIDFont);
  19134. output.add(compiled.output);
  19135. var topDictTracker = compiled.trackers[0];
  19136. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19137. output.add(stringIndex);
  19138. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19139. output.add(globalSubrIndex);
  19140. // Now start on the other entries that have no specfic order.
  19141. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19142. if (cff.encoding.predefined) {
  19143. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19144. output);
  19145. } else {
  19146. var encoding = this.compileEncoding(cff.encoding);
  19147. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19148. output.add(encoding);
  19149. }
  19150. }
  19151. if (cff.charset && cff.topDict.hasName('charset')) {
  19152. if (cff.charset.predefined) {
  19153. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19154. output);
  19155. } else {
  19156. var charset = this.compileCharset(cff.charset);
  19157. topDictTracker.setEntryLocation('charset', [output.length], output);
  19158. output.add(charset);
  19159. }
  19160. }
  19161. var charStrings = this.compileCharStrings(cff.charStrings);
  19162. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19163. output.add(charStrings);
  19164. if (cff.isCIDFont) {
  19165. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19166. // and linux don't seem to care.
  19167. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19168. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19169. output.add(fdSelect);
  19170. // It is unclear if the sub font dictionary can have CID related
  19171. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19172. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19173. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19174. output.add(compiled.output);
  19175. var fontDictTrackers = compiled.trackers;
  19176. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19177. }
  19178. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19179. // If the font data ends with INDEX whose object data is zero-length,
  19180. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19181. output.add([0]);
  19182. return output.data;
  19183. },
  19184. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19185. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19186. return this.encodeInteger(value);
  19187. } else {
  19188. return this.encodeFloat(value);
  19189. }
  19190. },
  19191. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19192. var value = num.toString();
  19193. // rounding inaccurate doubles
  19194. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19195. if (m) {
  19196. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19197. value = (Math.round(num * epsilon) / epsilon).toString();
  19198. }
  19199. var nibbles = '';
  19200. var i, ii;
  19201. for (i = 0, ii = value.length; i < ii; ++i) {
  19202. var a = value[i];
  19203. if (a === 'e') {
  19204. nibbles += value[++i] === '-' ? 'c' : 'b';
  19205. } else if (a === '.') {
  19206. nibbles += 'a';
  19207. } else if (a === '-') {
  19208. nibbles += 'e';
  19209. } else {
  19210. nibbles += a;
  19211. }
  19212. }
  19213. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19214. var out = [30];
  19215. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19216. out.push(parseInt(nibbles.substr(i, 2), 16));
  19217. }
  19218. return out;
  19219. },
  19220. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19221. var code;
  19222. if (value >= -107 && value <= 107) {
  19223. code = [value + 139];
  19224. } else if (value >= 108 && value <= 1131) {
  19225. value = [value - 108];
  19226. code = [(value >> 8) + 247, value & 0xFF];
  19227. } else if (value >= -1131 && value <= -108) {
  19228. value = -value - 108;
  19229. code = [(value >> 8) + 251, value & 0xFF];
  19230. } else if (value >= -32768 && value <= 32767) {
  19231. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19232. } else {
  19233. code = [0x1d,
  19234. (value >> 24) & 0xFF,
  19235. (value >> 16) & 0xFF,
  19236. (value >> 8) & 0xFF,
  19237. value & 0xFF];
  19238. }
  19239. return code;
  19240. },
  19241. compileHeader: function CFFCompiler_compileHeader(header) {
  19242. return [
  19243. header.major,
  19244. header.minor,
  19245. header.hdrSize,
  19246. header.offSize
  19247. ];
  19248. },
  19249. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19250. var nameIndex = new CFFIndex();
  19251. for (var i = 0, ii = names.length; i < ii; ++i) {
  19252. nameIndex.add(stringToBytes(names[i]));
  19253. }
  19254. return this.compileIndex(nameIndex);
  19255. },
  19256. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19257. length,
  19258. removeCidKeys) {
  19259. var fontDictTrackers = [];
  19260. var fdArrayIndex = new CFFIndex();
  19261. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19262. var fontDict = dicts[i];
  19263. if (removeCidKeys) {
  19264. fontDict.removeByName('CIDFontVersion');
  19265. fontDict.removeByName('CIDFontRevision');
  19266. fontDict.removeByName('CIDFontType');
  19267. fontDict.removeByName('CIDCount');
  19268. fontDict.removeByName('UIDBase');
  19269. }
  19270. var fontDictTracker = new CFFOffsetTracker();
  19271. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19272. fontDictTrackers.push(fontDictTracker);
  19273. fdArrayIndex.add(fontDictData);
  19274. fontDictTracker.offset(length);
  19275. }
  19276. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19277. return {
  19278. trackers: fontDictTrackers,
  19279. output: fdArrayIndex
  19280. };
  19281. },
  19282. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19283. trackers,
  19284. output) {
  19285. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19286. var fontDict = dicts[i];
  19287. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19288. 'There must be an private dictionary.');
  19289. var privateDict = fontDict.privateDict;
  19290. var privateDictTracker = new CFFOffsetTracker();
  19291. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19292. var outputLength = output.length;
  19293. privateDictTracker.offset(outputLength);
  19294. if (!privateDictData.length) {
  19295. // The private dictionary was empty, set the output length to zero to
  19296. // ensure the offset length isn't out of bounds in the eyes of the
  19297. // sanitizer.
  19298. outputLength = 0;
  19299. }
  19300. trackers[i].setEntryLocation('Private',
  19301. [privateDictData.length, outputLength],
  19302. output);
  19303. output.add(privateDictData);
  19304. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19305. var subrs = this.compileIndex(privateDict.subrsIndex);
  19306. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19307. output);
  19308. output.add(subrs);
  19309. }
  19310. }
  19311. },
  19312. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19313. var out = [];
  19314. // The dictionary keys must be in a certain order.
  19315. var order = dict.order;
  19316. for (var i = 0; i < order.length; ++i) {
  19317. var key = order[i];
  19318. if (!(key in dict.values)) {
  19319. continue;
  19320. }
  19321. var values = dict.values[key];
  19322. var types = dict.types[key];
  19323. if (!isArray(types)) {
  19324. types = [types];
  19325. }
  19326. if (!isArray(values)) {
  19327. values = [values];
  19328. }
  19329. // Remove any empty dict values.
  19330. if (values.length === 0) {
  19331. continue;
  19332. }
  19333. for (var j = 0, jj = types.length; j < jj; ++j) {
  19334. var type = types[j];
  19335. var value = values[j];
  19336. switch (type) {
  19337. case 'num':
  19338. case 'sid':
  19339. out = out.concat(this.encodeNumber(value));
  19340. break;
  19341. case 'offset':
  19342. // For offsets we just insert a 32bit integer so we don't have to
  19343. // deal with figuring out the length of the offset when it gets
  19344. // replaced later on by the compiler.
  19345. var name = dict.keyToNameMap[key];
  19346. // Some offsets have the offset and the length, so just record the
  19347. // position of the first one.
  19348. if (!offsetTracker.isTracking(name)) {
  19349. offsetTracker.track(name, out.length);
  19350. }
  19351. out = out.concat([0x1d, 0, 0, 0, 0]);
  19352. break;
  19353. case 'array':
  19354. case 'delta':
  19355. out = out.concat(this.encodeNumber(value));
  19356. for (var k = 1, kk = values.length; k < kk; ++k) {
  19357. out = out.concat(this.encodeNumber(values[k]));
  19358. }
  19359. break;
  19360. default:
  19361. error('Unknown data type of ' + type);
  19362. break;
  19363. }
  19364. }
  19365. out = out.concat(dict.opcodes[key]);
  19366. }
  19367. return out;
  19368. },
  19369. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19370. var stringIndex = new CFFIndex();
  19371. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19372. stringIndex.add(stringToBytes(strings[i]));
  19373. }
  19374. return this.compileIndex(stringIndex);
  19375. },
  19376. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19377. var globalSubrIndex = this.cff.globalSubrIndex;
  19378. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19379. },
  19380. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19381. return this.compileIndex(charStrings);
  19382. },
  19383. compileCharset: function CFFCompiler_compileCharset(charset) {
  19384. return this.compileTypedArray(charset.raw);
  19385. },
  19386. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19387. return this.compileTypedArray(encoding.raw);
  19388. },
  19389. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19390. return this.compileTypedArray(fdSelect);
  19391. },
  19392. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19393. var out = [];
  19394. for (var i = 0, ii = data.length; i < ii; ++i) {
  19395. out[i] = data[i];
  19396. }
  19397. return out;
  19398. },
  19399. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19400. trackers = trackers || [];
  19401. var objects = index.objects;
  19402. // First 2 bytes contains the number of objects contained into this index
  19403. var count = objects.length;
  19404. // If there is no object, just create an index. This technically
  19405. // should just be [0, 0] but OTS has an issue with that.
  19406. if (count === 0) {
  19407. return [0, 0, 0];
  19408. }
  19409. var data = [(count >> 8) & 0xFF, count & 0xff];
  19410. var lastOffset = 1, i;
  19411. for (i = 0; i < count; ++i) {
  19412. lastOffset += objects[i].length;
  19413. }
  19414. var offsetSize;
  19415. if (lastOffset < 0x100) {
  19416. offsetSize = 1;
  19417. } else if (lastOffset < 0x10000) {
  19418. offsetSize = 2;
  19419. } else if (lastOffset < 0x1000000) {
  19420. offsetSize = 3;
  19421. } else {
  19422. offsetSize = 4;
  19423. }
  19424. // Next byte contains the offset size use to reference object in the file
  19425. data.push(offsetSize);
  19426. // Add another offset after this one because we need a new offset
  19427. var relativeOffset = 1;
  19428. for (i = 0; i < count + 1; i++) {
  19429. if (offsetSize === 1) {
  19430. data.push(relativeOffset & 0xFF);
  19431. } else if (offsetSize === 2) {
  19432. data.push((relativeOffset >> 8) & 0xFF,
  19433. relativeOffset & 0xFF);
  19434. } else if (offsetSize === 3) {
  19435. data.push((relativeOffset >> 16) & 0xFF,
  19436. (relativeOffset >> 8) & 0xFF,
  19437. relativeOffset & 0xFF);
  19438. } else {
  19439. data.push((relativeOffset >>> 24) & 0xFF,
  19440. (relativeOffset >> 16) & 0xFF,
  19441. (relativeOffset >> 8) & 0xFF,
  19442. relativeOffset & 0xFF);
  19443. }
  19444. if (objects[i]) {
  19445. relativeOffset += objects[i].length;
  19446. }
  19447. }
  19448. for (i = 0; i < count; i++) {
  19449. // Notify the tracker where the object will be offset in the data.
  19450. if (trackers[i]) {
  19451. trackers[i].offset(data.length);
  19452. }
  19453. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19454. data.push(objects[i][j]);
  19455. }
  19456. }
  19457. return data;
  19458. }
  19459. };
  19460. return CFFCompiler;
  19461. })();
  19462. // Workaround for seac on Windows.
  19463. (function checkSeacSupport() {
  19464. if (/Windows/.test(navigator.userAgent)) {
  19465. SEAC_ANALYSIS_ENABLED = true;
  19466. }
  19467. })();
  19468. // Workaround for Private Use Area characters in Chrome on Windows
  19469. // http://code.google.com/p/chromium/issues/detail?id=122465
  19470. // https://github.com/mozilla/pdf.js/issues/1689
  19471. (function checkChromeWindows() {
  19472. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19473. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19474. }
  19475. })();
  19476. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19477. function getLong(data, offset) {
  19478. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19479. (data[offset + 2] << 8) | data[offset + 3];
  19480. }
  19481. function getUshort(data, offset) {
  19482. return (data[offset] << 8) | data[offset + 1];
  19483. }
  19484. function parseCmap(data, start, end) {
  19485. var offset = (getUshort(data, start + 2) === 1 ?
  19486. getLong(data, start + 8) : getLong(data, start + 16));
  19487. var format = getUshort(data, start + offset);
  19488. var length, ranges, p, i;
  19489. if (format === 4) {
  19490. length = getUshort(data, start + offset + 2);
  19491. var segCount = getUshort(data, start + offset + 6) >> 1;
  19492. p = start + offset + 14;
  19493. ranges = [];
  19494. for (i = 0; i < segCount; i++, p += 2) {
  19495. ranges[i] = {end: getUshort(data, p)};
  19496. }
  19497. p += 2;
  19498. for (i = 0; i < segCount; i++, p += 2) {
  19499. ranges[i].start = getUshort(data, p);
  19500. }
  19501. for (i = 0; i < segCount; i++, p += 2) {
  19502. ranges[i].idDelta = getUshort(data, p);
  19503. }
  19504. for (i = 0; i < segCount; i++, p += 2) {
  19505. var idOffset = getUshort(data, p);
  19506. if (idOffset === 0) {
  19507. continue;
  19508. }
  19509. ranges[i].ids = [];
  19510. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19511. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19512. idOffset += 2;
  19513. }
  19514. }
  19515. return ranges;
  19516. } else if (format === 12) {
  19517. length = getLong(data, start + offset + 4);
  19518. var groups = getLong(data, start + offset + 12);
  19519. p = start + offset + 16;
  19520. ranges = [];
  19521. for (i = 0; i < groups; i++) {
  19522. ranges.push({
  19523. start: getLong(data, p),
  19524. end: getLong(data, p + 4),
  19525. idDelta: getLong(data, p + 8) - getLong(data, p)
  19526. });
  19527. p += 12;
  19528. }
  19529. return ranges;
  19530. }
  19531. error('not supported cmap: ' + format);
  19532. }
  19533. function parseCff(data, start, end) {
  19534. var properties = {};
  19535. var parser = new CFFParser(new Stream(data, start, end - start),
  19536. properties);
  19537. var cff = parser.parse();
  19538. return {
  19539. glyphs: cff.charStrings.objects,
  19540. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19541. cff.topDict.privateDict.subrsIndex.objects),
  19542. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19543. };
  19544. }
  19545. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19546. var itemSize, itemDecode;
  19547. if (isGlyphLocationsLong) {
  19548. itemSize = 4;
  19549. itemDecode = function fontItemDecodeLong(data, offset) {
  19550. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19551. (data[offset + 2] << 8) | data[offset + 3];
  19552. };
  19553. } else {
  19554. itemSize = 2;
  19555. itemDecode = function fontItemDecode(data, offset) {
  19556. return (data[offset] << 9) | (data[offset + 1] << 1);
  19557. };
  19558. }
  19559. var glyphs = [];
  19560. var startOffset = itemDecode(loca, 0);
  19561. for (var j = itemSize; j < loca.length; j += itemSize) {
  19562. var endOffset = itemDecode(loca, j);
  19563. glyphs.push(glyf.subarray(startOffset, endOffset));
  19564. startOffset = endOffset;
  19565. }
  19566. return glyphs;
  19567. }
  19568. function lookupCmap(ranges, unicode) {
  19569. var code = unicode.charCodeAt(0);
  19570. var l = 0, r = ranges.length - 1;
  19571. while (l < r) {
  19572. var c = (l + r + 1) >> 1;
  19573. if (code < ranges[c].start) {
  19574. r = c - 1;
  19575. } else {
  19576. l = c;
  19577. }
  19578. }
  19579. if (ranges[l].start <= code && code <= ranges[l].end) {
  19580. return (ranges[l].idDelta + (ranges[l].ids ?
  19581. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19582. }
  19583. return 0;
  19584. }
  19585. function compileGlyf(code, js, font) {
  19586. function moveTo(x, y) {
  19587. js.push('c.moveTo(' + x + ',' + y + ');');
  19588. }
  19589. function lineTo(x, y) {
  19590. js.push('c.lineTo(' + x + ',' + y + ');');
  19591. }
  19592. function quadraticCurveTo(xa, ya, x, y) {
  19593. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19594. x + ',' + y + ');');
  19595. }
  19596. var i = 0;
  19597. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19598. var flags;
  19599. var x = 0, y = 0;
  19600. i += 10;
  19601. if (numberOfContours < 0) {
  19602. // composite glyph
  19603. do {
  19604. flags = (code[i] << 8) | code[i + 1];
  19605. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19606. i += 4;
  19607. var arg1, arg2;
  19608. if ((flags & 0x01)) {
  19609. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19610. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19611. i += 4;
  19612. } else {
  19613. arg1 = code[i++]; arg2 = code[i++];
  19614. }
  19615. if ((flags & 0x02)) {
  19616. x = arg1;
  19617. y = arg2;
  19618. } else {
  19619. x = 0; y = 0; // TODO "they are points" ?
  19620. }
  19621. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19622. if ((flags & 0x08)) {
  19623. scaleX =
  19624. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19625. i += 2;
  19626. } else if ((flags & 0x40)) {
  19627. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19628. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19629. i += 4;
  19630. } else if ((flags & 0x80)) {
  19631. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19632. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19633. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19634. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19635. i += 8;
  19636. }
  19637. var subglyph = font.glyphs[glyphIndex];
  19638. if (subglyph) {
  19639. js.push('c.save();');
  19640. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19641. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19642. compileGlyf(subglyph, js, font);
  19643. js.push('c.restore();');
  19644. }
  19645. } while ((flags & 0x20));
  19646. } else {
  19647. // simple glyph
  19648. var endPtsOfContours = [];
  19649. var j, jj;
  19650. for (j = 0; j < numberOfContours; j++) {
  19651. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19652. i += 2;
  19653. }
  19654. var instructionLength = (code[i] << 8) | code[i + 1];
  19655. i += 2 + instructionLength; // skipping the instructions
  19656. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19657. var points = [];
  19658. while (points.length < numberOfPoints) {
  19659. flags = code[i++];
  19660. var repeat = 1;
  19661. if ((flags & 0x08)) {
  19662. repeat += code[i++];
  19663. }
  19664. while (repeat-- > 0) {
  19665. points.push({flags: flags});
  19666. }
  19667. }
  19668. for (j = 0; j < numberOfPoints; j++) {
  19669. switch (points[j].flags & 0x12) {
  19670. case 0x00:
  19671. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19672. i += 2;
  19673. break;
  19674. case 0x02:
  19675. x -= code[i++];
  19676. break;
  19677. case 0x12:
  19678. x += code[i++];
  19679. break;
  19680. }
  19681. points[j].x = x;
  19682. }
  19683. for (j = 0; j < numberOfPoints; j++) {
  19684. switch (points[j].flags & 0x24) {
  19685. case 0x00:
  19686. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19687. i += 2;
  19688. break;
  19689. case 0x04:
  19690. y -= code[i++];
  19691. break;
  19692. case 0x24:
  19693. y += code[i++];
  19694. break;
  19695. }
  19696. points[j].y = y;
  19697. }
  19698. var startPoint = 0;
  19699. for (i = 0; i < numberOfContours; i++) {
  19700. var endPoint = endPtsOfContours[i];
  19701. // contours might have implicit points, which is located in the middle
  19702. // between two neighboring off-curve points
  19703. var contour = points.slice(startPoint, endPoint + 1);
  19704. if ((contour[0].flags & 1)) {
  19705. contour.push(contour[0]); // using start point at the contour end
  19706. } else if ((contour[contour.length - 1].flags & 1)) {
  19707. // first is off-curve point, trying to use one from the end
  19708. contour.unshift(contour[contour.length - 1]);
  19709. } else {
  19710. // start and end are off-curve points, creating implicit one
  19711. var p = {
  19712. flags: 1,
  19713. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19714. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19715. };
  19716. contour.unshift(p);
  19717. contour.push(p);
  19718. }
  19719. moveTo(contour[0].x, contour[0].y);
  19720. for (j = 1, jj = contour.length; j < jj; j++) {
  19721. if ((contour[j].flags & 1)) {
  19722. lineTo(contour[j].x, contour[j].y);
  19723. } else if ((contour[j + 1].flags & 1)){
  19724. quadraticCurveTo(contour[j].x, contour[j].y,
  19725. contour[j + 1].x, contour[j + 1].y);
  19726. j++;
  19727. } else {
  19728. quadraticCurveTo(contour[j].x, contour[j].y,
  19729. (contour[j].x + contour[j + 1].x) / 2,
  19730. (contour[j].y + contour[j + 1].y) / 2);
  19731. }
  19732. }
  19733. startPoint = endPoint + 1;
  19734. }
  19735. }
  19736. }
  19737. function compileCharString(code, js, font) {
  19738. var stack = [];
  19739. var x = 0, y = 0;
  19740. var stems = 0;
  19741. function moveTo(x, y) {
  19742. js.push('c.moveTo(' + x + ',' + y + ');');
  19743. }
  19744. function lineTo(x, y) {
  19745. js.push('c.lineTo(' + x + ',' + y + ');');
  19746. }
  19747. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19748. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19749. x + ',' + y + ');');
  19750. }
  19751. function parse(code) {
  19752. var i = 0;
  19753. while (i < code.length) {
  19754. var stackClean = false;
  19755. var v = code[i++];
  19756. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19757. switch (v) {
  19758. case 1: // hstem
  19759. stems += stack.length >> 1;
  19760. stackClean = true;
  19761. break;
  19762. case 3: // vstem
  19763. stems += stack.length >> 1;
  19764. stackClean = true;
  19765. break;
  19766. case 4: // vmoveto
  19767. y += stack.pop();
  19768. moveTo(x, y);
  19769. stackClean = true;
  19770. break;
  19771. case 5: // rlineto
  19772. while (stack.length > 0) {
  19773. x += stack.shift();
  19774. y += stack.shift();
  19775. lineTo(x, y);
  19776. }
  19777. break;
  19778. case 6: // hlineto
  19779. while (stack.length > 0) {
  19780. x += stack.shift();
  19781. lineTo(x, y);
  19782. if (stack.length === 0) {
  19783. break;
  19784. }
  19785. y += stack.shift();
  19786. lineTo(x, y);
  19787. }
  19788. break;
  19789. case 7: // vlineto
  19790. while (stack.length > 0) {
  19791. y += stack.shift();
  19792. lineTo(x, y);
  19793. if (stack.length === 0) {
  19794. break;
  19795. }
  19796. x += stack.shift();
  19797. lineTo(x, y);
  19798. }
  19799. break;
  19800. case 8: // rrcurveto
  19801. while (stack.length > 0) {
  19802. xa = x + stack.shift(); ya = y + stack.shift();
  19803. xb = xa + stack.shift(); yb = ya + stack.shift();
  19804. x = xb + stack.shift(); y = yb + stack.shift();
  19805. bezierCurveTo(xa, ya, xb, yb, x, y);
  19806. }
  19807. break;
  19808. case 10: // callsubr
  19809. n = stack.pop() + font.subrsBias;
  19810. subrCode = font.subrs[n];
  19811. if (subrCode) {
  19812. parse(subrCode);
  19813. }
  19814. break;
  19815. case 11: // return
  19816. return;
  19817. case 12:
  19818. v = code[i++];
  19819. switch (v) {
  19820. case 34: // flex
  19821. xa = x + stack.shift();
  19822. xb = xa + stack.shift(); y1 = y + stack.shift();
  19823. x = xb + stack.shift();
  19824. bezierCurveTo(xa, y, xb, y1, x, y1);
  19825. xa = x + stack.shift();
  19826. xb = xa + stack.shift();
  19827. x = xb + stack.shift();
  19828. bezierCurveTo(xa, y1, xb, y, x, y);
  19829. break;
  19830. case 35: // flex
  19831. xa = x + stack.shift(); ya = y + stack.shift();
  19832. xb = xa + stack.shift(); yb = ya + stack.shift();
  19833. x = xb + stack.shift(); y = yb + stack.shift();
  19834. bezierCurveTo(xa, ya, xb, yb, x, y);
  19835. xa = x + stack.shift(); ya = y + stack.shift();
  19836. xb = xa + stack.shift(); yb = ya + stack.shift();
  19837. x = xb + stack.shift(); y = yb + stack.shift();
  19838. bezierCurveTo(xa, ya, xb, yb, x, y);
  19839. stack.pop(); // fd
  19840. break;
  19841. case 36: // hflex1
  19842. xa = x + stack.shift(); y1 = y + stack.shift();
  19843. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19844. x = xb + stack.shift();
  19845. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19846. xa = x + stack.shift();
  19847. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19848. x = xb + stack.shift();
  19849. bezierCurveTo(xa, y2, xb, y3, x, y);
  19850. break;
  19851. case 37: // flex1
  19852. var x0 = x, y0 = y;
  19853. xa = x + stack.shift(); ya = y + stack.shift();
  19854. xb = xa + stack.shift(); yb = ya + stack.shift();
  19855. x = xb + stack.shift(); y = yb + stack.shift();
  19856. bezierCurveTo(xa, ya, xb, yb, x, y);
  19857. xa = x + stack.shift(); ya = y + stack.shift();
  19858. xb = xa + stack.shift(); yb = ya + stack.shift();
  19859. x = xb; y = yb;
  19860. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19861. x += stack.shift();
  19862. } else {
  19863. y += stack.shift();
  19864. }
  19865. bezierCurveTo(xa, ya, xb, yb, x, y);
  19866. break;
  19867. default:
  19868. error('unknown operator: 12 ' + v);
  19869. }
  19870. break;
  19871. case 14: // endchar
  19872. if (stack.length >= 4) {
  19873. var achar = stack.pop();
  19874. var bchar = stack.pop();
  19875. y = stack.pop();
  19876. x = stack.pop();
  19877. js.push('c.save();');
  19878. js.push('c.translate('+ x + ',' + y + ');');
  19879. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19880. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19881. compileCharString(font.glyphs[gid], js, font);
  19882. js.push('c.restore();');
  19883. gid = lookupCmap(font.cmap, String.fromCharCode(
  19884. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19885. compileCharString(font.glyphs[gid], js, font);
  19886. }
  19887. return;
  19888. case 18: // hstemhm
  19889. stems += stack.length >> 1;
  19890. stackClean = true;
  19891. break;
  19892. case 19: // hintmask
  19893. stems += stack.length >> 1;
  19894. i += (stems + 7) >> 3;
  19895. stackClean = true;
  19896. break;
  19897. case 20: // cntrmask
  19898. stems += stack.length >> 1;
  19899. i += (stems + 7) >> 3;
  19900. stackClean = true;
  19901. break;
  19902. case 21: // rmoveto
  19903. y += stack.pop();
  19904. x += stack.pop();
  19905. moveTo(x, y);
  19906. stackClean = true;
  19907. break;
  19908. case 22: // hmoveto
  19909. x += stack.pop();
  19910. moveTo(x, y);
  19911. stackClean = true;
  19912. break;
  19913. case 23: // vstemhm
  19914. stems += stack.length >> 1;
  19915. stackClean = true;
  19916. break;
  19917. case 24: // rcurveline
  19918. while (stack.length > 2) {
  19919. xa = x + stack.shift(); ya = y + stack.shift();
  19920. xb = xa + stack.shift(); yb = ya + stack.shift();
  19921. x = xb + stack.shift(); y = yb + stack.shift();
  19922. bezierCurveTo(xa, ya, xb, yb, x, y);
  19923. }
  19924. x += stack.shift();
  19925. y += stack.shift();
  19926. lineTo(x, y);
  19927. break;
  19928. case 25: // rlinecurve
  19929. while (stack.length > 6) {
  19930. x += stack.shift();
  19931. y += stack.shift();
  19932. lineTo(x, y);
  19933. }
  19934. xa = x + stack.shift(); ya = y + stack.shift();
  19935. xb = xa + stack.shift(); yb = ya + stack.shift();
  19936. x = xb + stack.shift(); y = yb + stack.shift();
  19937. bezierCurveTo(xa, ya, xb, yb, x, y);
  19938. break;
  19939. case 26: // vvcurveto
  19940. if (stack.length % 2) {
  19941. x += stack.shift();
  19942. }
  19943. while (stack.length > 0) {
  19944. xa = x; ya = y + stack.shift();
  19945. xb = xa + stack.shift(); yb = ya + stack.shift();
  19946. x = xb; y = yb + stack.shift();
  19947. bezierCurveTo(xa, ya, xb, yb, x, y);
  19948. }
  19949. break;
  19950. case 27: // hhcurveto
  19951. if (stack.length % 2) {
  19952. y += stack.shift();
  19953. }
  19954. while (stack.length > 0) {
  19955. xa = x + stack.shift(); ya = y;
  19956. xb = xa + stack.shift(); yb = ya + stack.shift();
  19957. x = xb + stack.shift(); y = yb;
  19958. bezierCurveTo(xa, ya, xb, yb, x, y);
  19959. }
  19960. break;
  19961. case 28:
  19962. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19963. i += 2;
  19964. break;
  19965. case 29: // callgsubr
  19966. n = stack.pop() + font.gsubrsBias;
  19967. subrCode = font.gsubrs[n];
  19968. if (subrCode) {
  19969. parse(subrCode);
  19970. }
  19971. break;
  19972. case 30: // vhcurveto
  19973. while (stack.length > 0) {
  19974. xa = x; ya = y + stack.shift();
  19975. xb = xa + stack.shift(); yb = ya + stack.shift();
  19976. x = xb + stack.shift();
  19977. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19978. bezierCurveTo(xa, ya, xb, yb, x, y);
  19979. if (stack.length === 0) {
  19980. break;
  19981. }
  19982. xa = x + stack.shift(); ya = y;
  19983. xb = xa + stack.shift(); yb = ya + stack.shift();
  19984. y = yb + stack.shift();
  19985. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19986. bezierCurveTo(xa, ya, xb, yb, x, y);
  19987. }
  19988. break;
  19989. case 31: // hvcurveto
  19990. while (stack.length > 0) {
  19991. xa = x + stack.shift(); ya = y;
  19992. xb = xa + stack.shift(); yb = ya + stack.shift();
  19993. y = yb + stack.shift();
  19994. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19995. bezierCurveTo(xa, ya, xb, yb, x, y);
  19996. if (stack.length === 0) {
  19997. break;
  19998. }
  19999. xa = x; ya = y + stack.shift();
  20000. xb = xa + stack.shift(); yb = ya + stack.shift();
  20001. x = xb + stack.shift();
  20002. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20003. bezierCurveTo(xa, ya, xb, yb, x, y);
  20004. }
  20005. break;
  20006. default:
  20007. if (v < 32) {
  20008. error('unknown operator: ' + v);
  20009. }
  20010. if (v < 247) {
  20011. stack.push(v - 139);
  20012. } else if (v < 251) {
  20013. stack.push((v - 247) * 256 + code[i++] + 108);
  20014. } else if (v < 255) {
  20015. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20016. } else {
  20017. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20018. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20019. i += 4;
  20020. }
  20021. break;
  20022. }
  20023. if (stackClean) {
  20024. stack.length = 0;
  20025. }
  20026. }
  20027. }
  20028. parse(code);
  20029. }
  20030. var noop = '';
  20031. function CompiledFont(fontMatrix) {
  20032. this.compiledGlyphs = {};
  20033. this.fontMatrix = fontMatrix;
  20034. }
  20035. CompiledFont.prototype = {
  20036. getPathJs: function (unicode) {
  20037. var gid = lookupCmap(this.cmap, unicode);
  20038. var fn = this.compiledGlyphs[gid];
  20039. if (!fn) {
  20040. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20041. }
  20042. return fn;
  20043. },
  20044. compileGlyph: function (code) {
  20045. if (!code || code.length === 0 || code[0] === 14) {
  20046. return noop;
  20047. }
  20048. var js = [];
  20049. js.push('c.save();');
  20050. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20051. js.push('c.scale(size, -size);');
  20052. this.compileGlyphImpl(code, js);
  20053. js.push('c.restore();');
  20054. return js.join('\n');
  20055. },
  20056. compileGlyphImpl: function () {
  20057. error('Children classes should implement this.');
  20058. },
  20059. hasBuiltPath: function (unicode) {
  20060. var gid = lookupCmap(this.cmap, unicode);
  20061. return gid in this.compiledGlyphs;
  20062. }
  20063. };
  20064. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20065. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20066. CompiledFont.call(this, fontMatrix);
  20067. this.glyphs = glyphs;
  20068. this.cmap = cmap;
  20069. this.compiledGlyphs = [];
  20070. }
  20071. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20072. compileGlyphImpl: function (code, js) {
  20073. compileGlyf(code, js, this);
  20074. }
  20075. });
  20076. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20077. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20078. CompiledFont.call(this, fontMatrix);
  20079. this.glyphs = cffInfo.glyphs;
  20080. this.gsubrs = cffInfo.gsubrs || [];
  20081. this.subrs = cffInfo.subrs || [];
  20082. this.cmap = cmap;
  20083. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20084. this.compiledGlyphs = [];
  20085. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20086. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20087. this.subrsBias = (this.subrs.length < 1240 ?
  20088. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20089. }
  20090. Util.inherit(Type2Compiled, CompiledFont, {
  20091. compileGlyphImpl: function (code, js) {
  20092. compileCharString(code, js, this);
  20093. }
  20094. });
  20095. return {
  20096. create: function FontRendererFactory_create(font) {
  20097. var data = new Uint8Array(font.data);
  20098. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20099. var numTables = getUshort(data, 4);
  20100. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20101. var tag = bytesToString(data.subarray(p, p + 4));
  20102. var offset = getLong(data, p + 8);
  20103. var length = getLong(data, p + 12);
  20104. switch (tag) {
  20105. case 'cmap':
  20106. cmap = parseCmap(data, offset, offset + length);
  20107. break;
  20108. case 'glyf':
  20109. glyf = data.subarray(offset, offset + length);
  20110. break;
  20111. case 'loca':
  20112. loca = data.subarray(offset, offset + length);
  20113. break;
  20114. case 'head':
  20115. unitsPerEm = getUshort(data, offset + 18);
  20116. indexToLocFormat = getUshort(data, offset + 50);
  20117. break;
  20118. case 'CFF ':
  20119. cff = parseCff(data, offset, offset + length);
  20120. break;
  20121. }
  20122. }
  20123. if (glyf) {
  20124. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20125. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20126. return new TrueTypeCompiled(
  20127. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20128. } else {
  20129. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20130. }
  20131. }
  20132. };
  20133. })();
  20134. var GlyphsUnicode = {
  20135. A: 0x0041,
  20136. AE: 0x00C6,
  20137. AEacute: 0x01FC,
  20138. AEmacron: 0x01E2,
  20139. AEsmall: 0xF7E6,
  20140. Aacute: 0x00C1,
  20141. Aacutesmall: 0xF7E1,
  20142. Abreve: 0x0102,
  20143. Abreveacute: 0x1EAE,
  20144. Abrevecyrillic: 0x04D0,
  20145. Abrevedotbelow: 0x1EB6,
  20146. Abrevegrave: 0x1EB0,
  20147. Abrevehookabove: 0x1EB2,
  20148. Abrevetilde: 0x1EB4,
  20149. Acaron: 0x01CD,
  20150. Acircle: 0x24B6,
  20151. Acircumflex: 0x00C2,
  20152. Acircumflexacute: 0x1EA4,
  20153. Acircumflexdotbelow: 0x1EAC,
  20154. Acircumflexgrave: 0x1EA6,
  20155. Acircumflexhookabove: 0x1EA8,
  20156. Acircumflexsmall: 0xF7E2,
  20157. Acircumflextilde: 0x1EAA,
  20158. Acute: 0xF6C9,
  20159. Acutesmall: 0xF7B4,
  20160. Acyrillic: 0x0410,
  20161. Adblgrave: 0x0200,
  20162. Adieresis: 0x00C4,
  20163. Adieresiscyrillic: 0x04D2,
  20164. Adieresismacron: 0x01DE,
  20165. Adieresissmall: 0xF7E4,
  20166. Adotbelow: 0x1EA0,
  20167. Adotmacron: 0x01E0,
  20168. Agrave: 0x00C0,
  20169. Agravesmall: 0xF7E0,
  20170. Ahookabove: 0x1EA2,
  20171. Aiecyrillic: 0x04D4,
  20172. Ainvertedbreve: 0x0202,
  20173. Alpha: 0x0391,
  20174. Alphatonos: 0x0386,
  20175. Amacron: 0x0100,
  20176. Amonospace: 0xFF21,
  20177. Aogonek: 0x0104,
  20178. Aring: 0x00C5,
  20179. Aringacute: 0x01FA,
  20180. Aringbelow: 0x1E00,
  20181. Aringsmall: 0xF7E5,
  20182. Asmall: 0xF761,
  20183. Atilde: 0x00C3,
  20184. Atildesmall: 0xF7E3,
  20185. Aybarmenian: 0x0531,
  20186. B: 0x0042,
  20187. Bcircle: 0x24B7,
  20188. Bdotaccent: 0x1E02,
  20189. Bdotbelow: 0x1E04,
  20190. Becyrillic: 0x0411,
  20191. Benarmenian: 0x0532,
  20192. Beta: 0x0392,
  20193. Bhook: 0x0181,
  20194. Blinebelow: 0x1E06,
  20195. Bmonospace: 0xFF22,
  20196. Brevesmall: 0xF6F4,
  20197. Bsmall: 0xF762,
  20198. Btopbar: 0x0182,
  20199. C: 0x0043,
  20200. Caarmenian: 0x053E,
  20201. Cacute: 0x0106,
  20202. Caron: 0xF6CA,
  20203. Caronsmall: 0xF6F5,
  20204. Ccaron: 0x010C,
  20205. Ccedilla: 0x00C7,
  20206. Ccedillaacute: 0x1E08,
  20207. Ccedillasmall: 0xF7E7,
  20208. Ccircle: 0x24B8,
  20209. Ccircumflex: 0x0108,
  20210. Cdot: 0x010A,
  20211. Cdotaccent: 0x010A,
  20212. Cedillasmall: 0xF7B8,
  20213. Chaarmenian: 0x0549,
  20214. Cheabkhasiancyrillic: 0x04BC,
  20215. Checyrillic: 0x0427,
  20216. Chedescenderabkhasiancyrillic: 0x04BE,
  20217. Chedescendercyrillic: 0x04B6,
  20218. Chedieresiscyrillic: 0x04F4,
  20219. Cheharmenian: 0x0543,
  20220. Chekhakassiancyrillic: 0x04CB,
  20221. Cheverticalstrokecyrillic: 0x04B8,
  20222. Chi: 0x03A7,
  20223. Chook: 0x0187,
  20224. Circumflexsmall: 0xF6F6,
  20225. Cmonospace: 0xFF23,
  20226. Coarmenian: 0x0551,
  20227. Csmall: 0xF763,
  20228. D: 0x0044,
  20229. DZ: 0x01F1,
  20230. DZcaron: 0x01C4,
  20231. Daarmenian: 0x0534,
  20232. Dafrican: 0x0189,
  20233. Dcaron: 0x010E,
  20234. Dcedilla: 0x1E10,
  20235. Dcircle: 0x24B9,
  20236. Dcircumflexbelow: 0x1E12,
  20237. Dcroat: 0x0110,
  20238. Ddotaccent: 0x1E0A,
  20239. Ddotbelow: 0x1E0C,
  20240. Decyrillic: 0x0414,
  20241. Deicoptic: 0x03EE,
  20242. Delta: 0x2206,
  20243. Deltagreek: 0x0394,
  20244. Dhook: 0x018A,
  20245. Dieresis: 0xF6CB,
  20246. DieresisAcute: 0xF6CC,
  20247. DieresisGrave: 0xF6CD,
  20248. Dieresissmall: 0xF7A8,
  20249. Digammagreek: 0x03DC,
  20250. Djecyrillic: 0x0402,
  20251. Dlinebelow: 0x1E0E,
  20252. Dmonospace: 0xFF24,
  20253. Dotaccentsmall: 0xF6F7,
  20254. Dslash: 0x0110,
  20255. Dsmall: 0xF764,
  20256. Dtopbar: 0x018B,
  20257. Dz: 0x01F2,
  20258. Dzcaron: 0x01C5,
  20259. Dzeabkhasiancyrillic: 0x04E0,
  20260. Dzecyrillic: 0x0405,
  20261. Dzhecyrillic: 0x040F,
  20262. E: 0x0045,
  20263. Eacute: 0x00C9,
  20264. Eacutesmall: 0xF7E9,
  20265. Ebreve: 0x0114,
  20266. Ecaron: 0x011A,
  20267. Ecedillabreve: 0x1E1C,
  20268. Echarmenian: 0x0535,
  20269. Ecircle: 0x24BA,
  20270. Ecircumflex: 0x00CA,
  20271. Ecircumflexacute: 0x1EBE,
  20272. Ecircumflexbelow: 0x1E18,
  20273. Ecircumflexdotbelow: 0x1EC6,
  20274. Ecircumflexgrave: 0x1EC0,
  20275. Ecircumflexhookabove: 0x1EC2,
  20276. Ecircumflexsmall: 0xF7EA,
  20277. Ecircumflextilde: 0x1EC4,
  20278. Ecyrillic: 0x0404,
  20279. Edblgrave: 0x0204,
  20280. Edieresis: 0x00CB,
  20281. Edieresissmall: 0xF7EB,
  20282. Edot: 0x0116,
  20283. Edotaccent: 0x0116,
  20284. Edotbelow: 0x1EB8,
  20285. Efcyrillic: 0x0424,
  20286. Egrave: 0x00C8,
  20287. Egravesmall: 0xF7E8,
  20288. Eharmenian: 0x0537,
  20289. Ehookabove: 0x1EBA,
  20290. Eightroman: 0x2167,
  20291. Einvertedbreve: 0x0206,
  20292. Eiotifiedcyrillic: 0x0464,
  20293. Elcyrillic: 0x041B,
  20294. Elevenroman: 0x216A,
  20295. Emacron: 0x0112,
  20296. Emacronacute: 0x1E16,
  20297. Emacrongrave: 0x1E14,
  20298. Emcyrillic: 0x041C,
  20299. Emonospace: 0xFF25,
  20300. Encyrillic: 0x041D,
  20301. Endescendercyrillic: 0x04A2,
  20302. Eng: 0x014A,
  20303. Enghecyrillic: 0x04A4,
  20304. Enhookcyrillic: 0x04C7,
  20305. Eogonek: 0x0118,
  20306. Eopen: 0x0190,
  20307. Epsilon: 0x0395,
  20308. Epsilontonos: 0x0388,
  20309. Ercyrillic: 0x0420,
  20310. Ereversed: 0x018E,
  20311. Ereversedcyrillic: 0x042D,
  20312. Escyrillic: 0x0421,
  20313. Esdescendercyrillic: 0x04AA,
  20314. Esh: 0x01A9,
  20315. Esmall: 0xF765,
  20316. Eta: 0x0397,
  20317. Etarmenian: 0x0538,
  20318. Etatonos: 0x0389,
  20319. Eth: 0x00D0,
  20320. Ethsmall: 0xF7F0,
  20321. Etilde: 0x1EBC,
  20322. Etildebelow: 0x1E1A,
  20323. Euro: 0x20AC,
  20324. Ezh: 0x01B7,
  20325. Ezhcaron: 0x01EE,
  20326. Ezhreversed: 0x01B8,
  20327. F: 0x0046,
  20328. Fcircle: 0x24BB,
  20329. Fdotaccent: 0x1E1E,
  20330. Feharmenian: 0x0556,
  20331. Feicoptic: 0x03E4,
  20332. Fhook: 0x0191,
  20333. Fitacyrillic: 0x0472,
  20334. Fiveroman: 0x2164,
  20335. Fmonospace: 0xFF26,
  20336. Fourroman: 0x2163,
  20337. Fsmall: 0xF766,
  20338. G: 0x0047,
  20339. GBsquare: 0x3387,
  20340. Gacute: 0x01F4,
  20341. Gamma: 0x0393,
  20342. Gammaafrican: 0x0194,
  20343. Gangiacoptic: 0x03EA,
  20344. Gbreve: 0x011E,
  20345. Gcaron: 0x01E6,
  20346. Gcedilla: 0x0122,
  20347. Gcircle: 0x24BC,
  20348. Gcircumflex: 0x011C,
  20349. Gcommaaccent: 0x0122,
  20350. Gdot: 0x0120,
  20351. Gdotaccent: 0x0120,
  20352. Gecyrillic: 0x0413,
  20353. Ghadarmenian: 0x0542,
  20354. Ghemiddlehookcyrillic: 0x0494,
  20355. Ghestrokecyrillic: 0x0492,
  20356. Gheupturncyrillic: 0x0490,
  20357. Ghook: 0x0193,
  20358. Gimarmenian: 0x0533,
  20359. Gjecyrillic: 0x0403,
  20360. Gmacron: 0x1E20,
  20361. Gmonospace: 0xFF27,
  20362. Grave: 0xF6CE,
  20363. Gravesmall: 0xF760,
  20364. Gsmall: 0xF767,
  20365. Gsmallhook: 0x029B,
  20366. Gstroke: 0x01E4,
  20367. H: 0x0048,
  20368. H18533: 0x25CF,
  20369. H18543: 0x25AA,
  20370. H18551: 0x25AB,
  20371. H22073: 0x25A1,
  20372. HPsquare: 0x33CB,
  20373. Haabkhasiancyrillic: 0x04A8,
  20374. Hadescendercyrillic: 0x04B2,
  20375. Hardsigncyrillic: 0x042A,
  20376. Hbar: 0x0126,
  20377. Hbrevebelow: 0x1E2A,
  20378. Hcedilla: 0x1E28,
  20379. Hcircle: 0x24BD,
  20380. Hcircumflex: 0x0124,
  20381. Hdieresis: 0x1E26,
  20382. Hdotaccent: 0x1E22,
  20383. Hdotbelow: 0x1E24,
  20384. Hmonospace: 0xFF28,
  20385. Hoarmenian: 0x0540,
  20386. Horicoptic: 0x03E8,
  20387. Hsmall: 0xF768,
  20388. Hungarumlaut: 0xF6CF,
  20389. Hungarumlautsmall: 0xF6F8,
  20390. Hzsquare: 0x3390,
  20391. I: 0x0049,
  20392. IAcyrillic: 0x042F,
  20393. IJ: 0x0132,
  20394. IUcyrillic: 0x042E,
  20395. Iacute: 0x00CD,
  20396. Iacutesmall: 0xF7ED,
  20397. Ibreve: 0x012C,
  20398. Icaron: 0x01CF,
  20399. Icircle: 0x24BE,
  20400. Icircumflex: 0x00CE,
  20401. Icircumflexsmall: 0xF7EE,
  20402. Icyrillic: 0x0406,
  20403. Idblgrave: 0x0208,
  20404. Idieresis: 0x00CF,
  20405. Idieresisacute: 0x1E2E,
  20406. Idieresiscyrillic: 0x04E4,
  20407. Idieresissmall: 0xF7EF,
  20408. Idot: 0x0130,
  20409. Idotaccent: 0x0130,
  20410. Idotbelow: 0x1ECA,
  20411. Iebrevecyrillic: 0x04D6,
  20412. Iecyrillic: 0x0415,
  20413. Ifraktur: 0x2111,
  20414. Igrave: 0x00CC,
  20415. Igravesmall: 0xF7EC,
  20416. Ihookabove: 0x1EC8,
  20417. Iicyrillic: 0x0418,
  20418. Iinvertedbreve: 0x020A,
  20419. Iishortcyrillic: 0x0419,
  20420. Imacron: 0x012A,
  20421. Imacroncyrillic: 0x04E2,
  20422. Imonospace: 0xFF29,
  20423. Iniarmenian: 0x053B,
  20424. Iocyrillic: 0x0401,
  20425. Iogonek: 0x012E,
  20426. Iota: 0x0399,
  20427. Iotaafrican: 0x0196,
  20428. Iotadieresis: 0x03AA,
  20429. Iotatonos: 0x038A,
  20430. Ismall: 0xF769,
  20431. Istroke: 0x0197,
  20432. Itilde: 0x0128,
  20433. Itildebelow: 0x1E2C,
  20434. Izhitsacyrillic: 0x0474,
  20435. Izhitsadblgravecyrillic: 0x0476,
  20436. J: 0x004A,
  20437. Jaarmenian: 0x0541,
  20438. Jcircle: 0x24BF,
  20439. Jcircumflex: 0x0134,
  20440. Jecyrillic: 0x0408,
  20441. Jheharmenian: 0x054B,
  20442. Jmonospace: 0xFF2A,
  20443. Jsmall: 0xF76A,
  20444. K: 0x004B,
  20445. KBsquare: 0x3385,
  20446. KKsquare: 0x33CD,
  20447. Kabashkircyrillic: 0x04A0,
  20448. Kacute: 0x1E30,
  20449. Kacyrillic: 0x041A,
  20450. Kadescendercyrillic: 0x049A,
  20451. Kahookcyrillic: 0x04C3,
  20452. Kappa: 0x039A,
  20453. Kastrokecyrillic: 0x049E,
  20454. Kaverticalstrokecyrillic: 0x049C,
  20455. Kcaron: 0x01E8,
  20456. Kcedilla: 0x0136,
  20457. Kcircle: 0x24C0,
  20458. Kcommaaccent: 0x0136,
  20459. Kdotbelow: 0x1E32,
  20460. Keharmenian: 0x0554,
  20461. Kenarmenian: 0x053F,
  20462. Khacyrillic: 0x0425,
  20463. Kheicoptic: 0x03E6,
  20464. Khook: 0x0198,
  20465. Kjecyrillic: 0x040C,
  20466. Klinebelow: 0x1E34,
  20467. Kmonospace: 0xFF2B,
  20468. Koppacyrillic: 0x0480,
  20469. Koppagreek: 0x03DE,
  20470. Ksicyrillic: 0x046E,
  20471. Ksmall: 0xF76B,
  20472. L: 0x004C,
  20473. LJ: 0x01C7,
  20474. LL: 0xF6BF,
  20475. Lacute: 0x0139,
  20476. Lambda: 0x039B,
  20477. Lcaron: 0x013D,
  20478. Lcedilla: 0x013B,
  20479. Lcircle: 0x24C1,
  20480. Lcircumflexbelow: 0x1E3C,
  20481. Lcommaaccent: 0x013B,
  20482. Ldot: 0x013F,
  20483. Ldotaccent: 0x013F,
  20484. Ldotbelow: 0x1E36,
  20485. Ldotbelowmacron: 0x1E38,
  20486. Liwnarmenian: 0x053C,
  20487. Lj: 0x01C8,
  20488. Ljecyrillic: 0x0409,
  20489. Llinebelow: 0x1E3A,
  20490. Lmonospace: 0xFF2C,
  20491. Lslash: 0x0141,
  20492. Lslashsmall: 0xF6F9,
  20493. Lsmall: 0xF76C,
  20494. M: 0x004D,
  20495. MBsquare: 0x3386,
  20496. Macron: 0xF6D0,
  20497. Macronsmall: 0xF7AF,
  20498. Macute: 0x1E3E,
  20499. Mcircle: 0x24C2,
  20500. Mdotaccent: 0x1E40,
  20501. Mdotbelow: 0x1E42,
  20502. Menarmenian: 0x0544,
  20503. Mmonospace: 0xFF2D,
  20504. Msmall: 0xF76D,
  20505. Mturned: 0x019C,
  20506. Mu: 0x039C,
  20507. N: 0x004E,
  20508. NJ: 0x01CA,
  20509. Nacute: 0x0143,
  20510. Ncaron: 0x0147,
  20511. Ncedilla: 0x0145,
  20512. Ncircle: 0x24C3,
  20513. Ncircumflexbelow: 0x1E4A,
  20514. Ncommaaccent: 0x0145,
  20515. Ndotaccent: 0x1E44,
  20516. Ndotbelow: 0x1E46,
  20517. Nhookleft: 0x019D,
  20518. Nineroman: 0x2168,
  20519. Nj: 0x01CB,
  20520. Njecyrillic: 0x040A,
  20521. Nlinebelow: 0x1E48,
  20522. Nmonospace: 0xFF2E,
  20523. Nowarmenian: 0x0546,
  20524. Nsmall: 0xF76E,
  20525. Ntilde: 0x00D1,
  20526. Ntildesmall: 0xF7F1,
  20527. Nu: 0x039D,
  20528. O: 0x004F,
  20529. OE: 0x0152,
  20530. OEsmall: 0xF6FA,
  20531. Oacute: 0x00D3,
  20532. Oacutesmall: 0xF7F3,
  20533. Obarredcyrillic: 0x04E8,
  20534. Obarreddieresiscyrillic: 0x04EA,
  20535. Obreve: 0x014E,
  20536. Ocaron: 0x01D1,
  20537. Ocenteredtilde: 0x019F,
  20538. Ocircle: 0x24C4,
  20539. Ocircumflex: 0x00D4,
  20540. Ocircumflexacute: 0x1ED0,
  20541. Ocircumflexdotbelow: 0x1ED8,
  20542. Ocircumflexgrave: 0x1ED2,
  20543. Ocircumflexhookabove: 0x1ED4,
  20544. Ocircumflexsmall: 0xF7F4,
  20545. Ocircumflextilde: 0x1ED6,
  20546. Ocyrillic: 0x041E,
  20547. Odblacute: 0x0150,
  20548. Odblgrave: 0x020C,
  20549. Odieresis: 0x00D6,
  20550. Odieresiscyrillic: 0x04E6,
  20551. Odieresissmall: 0xF7F6,
  20552. Odotbelow: 0x1ECC,
  20553. Ogoneksmall: 0xF6FB,
  20554. Ograve: 0x00D2,
  20555. Ogravesmall: 0xF7F2,
  20556. Oharmenian: 0x0555,
  20557. Ohm: 0x2126,
  20558. Ohookabove: 0x1ECE,
  20559. Ohorn: 0x01A0,
  20560. Ohornacute: 0x1EDA,
  20561. Ohorndotbelow: 0x1EE2,
  20562. Ohorngrave: 0x1EDC,
  20563. Ohornhookabove: 0x1EDE,
  20564. Ohorntilde: 0x1EE0,
  20565. Ohungarumlaut: 0x0150,
  20566. Oi: 0x01A2,
  20567. Oinvertedbreve: 0x020E,
  20568. Omacron: 0x014C,
  20569. Omacronacute: 0x1E52,
  20570. Omacrongrave: 0x1E50,
  20571. Omega: 0x2126,
  20572. Omegacyrillic: 0x0460,
  20573. Omegagreek: 0x03A9,
  20574. Omegaroundcyrillic: 0x047A,
  20575. Omegatitlocyrillic: 0x047C,
  20576. Omegatonos: 0x038F,
  20577. Omicron: 0x039F,
  20578. Omicrontonos: 0x038C,
  20579. Omonospace: 0xFF2F,
  20580. Oneroman: 0x2160,
  20581. Oogonek: 0x01EA,
  20582. Oogonekmacron: 0x01EC,
  20583. Oopen: 0x0186,
  20584. Oslash: 0x00D8,
  20585. Oslashacute: 0x01FE,
  20586. Oslashsmall: 0xF7F8,
  20587. Osmall: 0xF76F,
  20588. Ostrokeacute: 0x01FE,
  20589. Otcyrillic: 0x047E,
  20590. Otilde: 0x00D5,
  20591. Otildeacute: 0x1E4C,
  20592. Otildedieresis: 0x1E4E,
  20593. Otildesmall: 0xF7F5,
  20594. P: 0x0050,
  20595. Pacute: 0x1E54,
  20596. Pcircle: 0x24C5,
  20597. Pdotaccent: 0x1E56,
  20598. Pecyrillic: 0x041F,
  20599. Peharmenian: 0x054A,
  20600. Pemiddlehookcyrillic: 0x04A6,
  20601. Phi: 0x03A6,
  20602. Phook: 0x01A4,
  20603. Pi: 0x03A0,
  20604. Piwrarmenian: 0x0553,
  20605. Pmonospace: 0xFF30,
  20606. Psi: 0x03A8,
  20607. Psicyrillic: 0x0470,
  20608. Psmall: 0xF770,
  20609. Q: 0x0051,
  20610. Qcircle: 0x24C6,
  20611. Qmonospace: 0xFF31,
  20612. Qsmall: 0xF771,
  20613. R: 0x0052,
  20614. Raarmenian: 0x054C,
  20615. Racute: 0x0154,
  20616. Rcaron: 0x0158,
  20617. Rcedilla: 0x0156,
  20618. Rcircle: 0x24C7,
  20619. Rcommaaccent: 0x0156,
  20620. Rdblgrave: 0x0210,
  20621. Rdotaccent: 0x1E58,
  20622. Rdotbelow: 0x1E5A,
  20623. Rdotbelowmacron: 0x1E5C,
  20624. Reharmenian: 0x0550,
  20625. Rfraktur: 0x211C,
  20626. Rho: 0x03A1,
  20627. Ringsmall: 0xF6FC,
  20628. Rinvertedbreve: 0x0212,
  20629. Rlinebelow: 0x1E5E,
  20630. Rmonospace: 0xFF32,
  20631. Rsmall: 0xF772,
  20632. Rsmallinverted: 0x0281,
  20633. Rsmallinvertedsuperior: 0x02B6,
  20634. S: 0x0053,
  20635. SF010000: 0x250C,
  20636. SF020000: 0x2514,
  20637. SF030000: 0x2510,
  20638. SF040000: 0x2518,
  20639. SF050000: 0x253C,
  20640. SF060000: 0x252C,
  20641. SF070000: 0x2534,
  20642. SF080000: 0x251C,
  20643. SF090000: 0x2524,
  20644. SF100000: 0x2500,
  20645. SF110000: 0x2502,
  20646. SF190000: 0x2561,
  20647. SF200000: 0x2562,
  20648. SF210000: 0x2556,
  20649. SF220000: 0x2555,
  20650. SF230000: 0x2563,
  20651. SF240000: 0x2551,
  20652. SF250000: 0x2557,
  20653. SF260000: 0x255D,
  20654. SF270000: 0x255C,
  20655. SF280000: 0x255B,
  20656. SF360000: 0x255E,
  20657. SF370000: 0x255F,
  20658. SF380000: 0x255A,
  20659. SF390000: 0x2554,
  20660. SF400000: 0x2569,
  20661. SF410000: 0x2566,
  20662. SF420000: 0x2560,
  20663. SF430000: 0x2550,
  20664. SF440000: 0x256C,
  20665. SF450000: 0x2567,
  20666. SF460000: 0x2568,
  20667. SF470000: 0x2564,
  20668. SF480000: 0x2565,
  20669. SF490000: 0x2559,
  20670. SF500000: 0x2558,
  20671. SF510000: 0x2552,
  20672. SF520000: 0x2553,
  20673. SF530000: 0x256B,
  20674. SF540000: 0x256A,
  20675. Sacute: 0x015A,
  20676. Sacutedotaccent: 0x1E64,
  20677. Sampigreek: 0x03E0,
  20678. Scaron: 0x0160,
  20679. Scarondotaccent: 0x1E66,
  20680. Scaronsmall: 0xF6FD,
  20681. Scedilla: 0x015E,
  20682. Schwa: 0x018F,
  20683. Schwacyrillic: 0x04D8,
  20684. Schwadieresiscyrillic: 0x04DA,
  20685. Scircle: 0x24C8,
  20686. Scircumflex: 0x015C,
  20687. Scommaaccent: 0x0218,
  20688. Sdotaccent: 0x1E60,
  20689. Sdotbelow: 0x1E62,
  20690. Sdotbelowdotaccent: 0x1E68,
  20691. Seharmenian: 0x054D,
  20692. Sevenroman: 0x2166,
  20693. Shaarmenian: 0x0547,
  20694. Shacyrillic: 0x0428,
  20695. Shchacyrillic: 0x0429,
  20696. Sheicoptic: 0x03E2,
  20697. Shhacyrillic: 0x04BA,
  20698. Shimacoptic: 0x03EC,
  20699. Sigma: 0x03A3,
  20700. Sixroman: 0x2165,
  20701. Smonospace: 0xFF33,
  20702. Softsigncyrillic: 0x042C,
  20703. Ssmall: 0xF773,
  20704. Stigmagreek: 0x03DA,
  20705. T: 0x0054,
  20706. Tau: 0x03A4,
  20707. Tbar: 0x0166,
  20708. Tcaron: 0x0164,
  20709. Tcedilla: 0x0162,
  20710. Tcircle: 0x24C9,
  20711. Tcircumflexbelow: 0x1E70,
  20712. Tcommaaccent: 0x0162,
  20713. Tdotaccent: 0x1E6A,
  20714. Tdotbelow: 0x1E6C,
  20715. Tecyrillic: 0x0422,
  20716. Tedescendercyrillic: 0x04AC,
  20717. Tenroman: 0x2169,
  20718. Tetsecyrillic: 0x04B4,
  20719. Theta: 0x0398,
  20720. Thook: 0x01AC,
  20721. Thorn: 0x00DE,
  20722. Thornsmall: 0xF7FE,
  20723. Threeroman: 0x2162,
  20724. Tildesmall: 0xF6FE,
  20725. Tiwnarmenian: 0x054F,
  20726. Tlinebelow: 0x1E6E,
  20727. Tmonospace: 0xFF34,
  20728. Toarmenian: 0x0539,
  20729. Tonefive: 0x01BC,
  20730. Tonesix: 0x0184,
  20731. Tonetwo: 0x01A7,
  20732. Tretroflexhook: 0x01AE,
  20733. Tsecyrillic: 0x0426,
  20734. Tshecyrillic: 0x040B,
  20735. Tsmall: 0xF774,
  20736. Twelveroman: 0x216B,
  20737. Tworoman: 0x2161,
  20738. U: 0x0055,
  20739. Uacute: 0x00DA,
  20740. Uacutesmall: 0xF7FA,
  20741. Ubreve: 0x016C,
  20742. Ucaron: 0x01D3,
  20743. Ucircle: 0x24CA,
  20744. Ucircumflex: 0x00DB,
  20745. Ucircumflexbelow: 0x1E76,
  20746. Ucircumflexsmall: 0xF7FB,
  20747. Ucyrillic: 0x0423,
  20748. Udblacute: 0x0170,
  20749. Udblgrave: 0x0214,
  20750. Udieresis: 0x00DC,
  20751. Udieresisacute: 0x01D7,
  20752. Udieresisbelow: 0x1E72,
  20753. Udieresiscaron: 0x01D9,
  20754. Udieresiscyrillic: 0x04F0,
  20755. Udieresisgrave: 0x01DB,
  20756. Udieresismacron: 0x01D5,
  20757. Udieresissmall: 0xF7FC,
  20758. Udotbelow: 0x1EE4,
  20759. Ugrave: 0x00D9,
  20760. Ugravesmall: 0xF7F9,
  20761. Uhookabove: 0x1EE6,
  20762. Uhorn: 0x01AF,
  20763. Uhornacute: 0x1EE8,
  20764. Uhorndotbelow: 0x1EF0,
  20765. Uhorngrave: 0x1EEA,
  20766. Uhornhookabove: 0x1EEC,
  20767. Uhorntilde: 0x1EEE,
  20768. Uhungarumlaut: 0x0170,
  20769. Uhungarumlautcyrillic: 0x04F2,
  20770. Uinvertedbreve: 0x0216,
  20771. Ukcyrillic: 0x0478,
  20772. Umacron: 0x016A,
  20773. Umacroncyrillic: 0x04EE,
  20774. Umacrondieresis: 0x1E7A,
  20775. Umonospace: 0xFF35,
  20776. Uogonek: 0x0172,
  20777. Upsilon: 0x03A5,
  20778. Upsilon1: 0x03D2,
  20779. Upsilonacutehooksymbolgreek: 0x03D3,
  20780. Upsilonafrican: 0x01B1,
  20781. Upsilondieresis: 0x03AB,
  20782. Upsilondieresishooksymbolgreek: 0x03D4,
  20783. Upsilonhooksymbol: 0x03D2,
  20784. Upsilontonos: 0x038E,
  20785. Uring: 0x016E,
  20786. Ushortcyrillic: 0x040E,
  20787. Usmall: 0xF775,
  20788. Ustraightcyrillic: 0x04AE,
  20789. Ustraightstrokecyrillic: 0x04B0,
  20790. Utilde: 0x0168,
  20791. Utildeacute: 0x1E78,
  20792. Utildebelow: 0x1E74,
  20793. V: 0x0056,
  20794. Vcircle: 0x24CB,
  20795. Vdotbelow: 0x1E7E,
  20796. Vecyrillic: 0x0412,
  20797. Vewarmenian: 0x054E,
  20798. Vhook: 0x01B2,
  20799. Vmonospace: 0xFF36,
  20800. Voarmenian: 0x0548,
  20801. Vsmall: 0xF776,
  20802. Vtilde: 0x1E7C,
  20803. W: 0x0057,
  20804. Wacute: 0x1E82,
  20805. Wcircle: 0x24CC,
  20806. Wcircumflex: 0x0174,
  20807. Wdieresis: 0x1E84,
  20808. Wdotaccent: 0x1E86,
  20809. Wdotbelow: 0x1E88,
  20810. Wgrave: 0x1E80,
  20811. Wmonospace: 0xFF37,
  20812. Wsmall: 0xF777,
  20813. X: 0x0058,
  20814. Xcircle: 0x24CD,
  20815. Xdieresis: 0x1E8C,
  20816. Xdotaccent: 0x1E8A,
  20817. Xeharmenian: 0x053D,
  20818. Xi: 0x039E,
  20819. Xmonospace: 0xFF38,
  20820. Xsmall: 0xF778,
  20821. Y: 0x0059,
  20822. Yacute: 0x00DD,
  20823. Yacutesmall: 0xF7FD,
  20824. Yatcyrillic: 0x0462,
  20825. Ycircle: 0x24CE,
  20826. Ycircumflex: 0x0176,
  20827. Ydieresis: 0x0178,
  20828. Ydieresissmall: 0xF7FF,
  20829. Ydotaccent: 0x1E8E,
  20830. Ydotbelow: 0x1EF4,
  20831. Yericyrillic: 0x042B,
  20832. Yerudieresiscyrillic: 0x04F8,
  20833. Ygrave: 0x1EF2,
  20834. Yhook: 0x01B3,
  20835. Yhookabove: 0x1EF6,
  20836. Yiarmenian: 0x0545,
  20837. Yicyrillic: 0x0407,
  20838. Yiwnarmenian: 0x0552,
  20839. Ymonospace: 0xFF39,
  20840. Ysmall: 0xF779,
  20841. Ytilde: 0x1EF8,
  20842. Yusbigcyrillic: 0x046A,
  20843. Yusbigiotifiedcyrillic: 0x046C,
  20844. Yuslittlecyrillic: 0x0466,
  20845. Yuslittleiotifiedcyrillic: 0x0468,
  20846. Z: 0x005A,
  20847. Zaarmenian: 0x0536,
  20848. Zacute: 0x0179,
  20849. Zcaron: 0x017D,
  20850. Zcaronsmall: 0xF6FF,
  20851. Zcircle: 0x24CF,
  20852. Zcircumflex: 0x1E90,
  20853. Zdot: 0x017B,
  20854. Zdotaccent: 0x017B,
  20855. Zdotbelow: 0x1E92,
  20856. Zecyrillic: 0x0417,
  20857. Zedescendercyrillic: 0x0498,
  20858. Zedieresiscyrillic: 0x04DE,
  20859. Zeta: 0x0396,
  20860. Zhearmenian: 0x053A,
  20861. Zhebrevecyrillic: 0x04C1,
  20862. Zhecyrillic: 0x0416,
  20863. Zhedescendercyrillic: 0x0496,
  20864. Zhedieresiscyrillic: 0x04DC,
  20865. Zlinebelow: 0x1E94,
  20866. Zmonospace: 0xFF3A,
  20867. Zsmall: 0xF77A,
  20868. Zstroke: 0x01B5,
  20869. a: 0x0061,
  20870. aabengali: 0x0986,
  20871. aacute: 0x00E1,
  20872. aadeva: 0x0906,
  20873. aagujarati: 0x0A86,
  20874. aagurmukhi: 0x0A06,
  20875. aamatragurmukhi: 0x0A3E,
  20876. aarusquare: 0x3303,
  20877. aavowelsignbengali: 0x09BE,
  20878. aavowelsigndeva: 0x093E,
  20879. aavowelsigngujarati: 0x0ABE,
  20880. abbreviationmarkarmenian: 0x055F,
  20881. abbreviationsigndeva: 0x0970,
  20882. abengali: 0x0985,
  20883. abopomofo: 0x311A,
  20884. abreve: 0x0103,
  20885. abreveacute: 0x1EAF,
  20886. abrevecyrillic: 0x04D1,
  20887. abrevedotbelow: 0x1EB7,
  20888. abrevegrave: 0x1EB1,
  20889. abrevehookabove: 0x1EB3,
  20890. abrevetilde: 0x1EB5,
  20891. acaron: 0x01CE,
  20892. acircle: 0x24D0,
  20893. acircumflex: 0x00E2,
  20894. acircumflexacute: 0x1EA5,
  20895. acircumflexdotbelow: 0x1EAD,
  20896. acircumflexgrave: 0x1EA7,
  20897. acircumflexhookabove: 0x1EA9,
  20898. acircumflextilde: 0x1EAB,
  20899. acute: 0x00B4,
  20900. acutebelowcmb: 0x0317,
  20901. acutecmb: 0x0301,
  20902. acutecomb: 0x0301,
  20903. acutedeva: 0x0954,
  20904. acutelowmod: 0x02CF,
  20905. acutetonecmb: 0x0341,
  20906. acyrillic: 0x0430,
  20907. adblgrave: 0x0201,
  20908. addakgurmukhi: 0x0A71,
  20909. adeva: 0x0905,
  20910. adieresis: 0x00E4,
  20911. adieresiscyrillic: 0x04D3,
  20912. adieresismacron: 0x01DF,
  20913. adotbelow: 0x1EA1,
  20914. adotmacron: 0x01E1,
  20915. ae: 0x00E6,
  20916. aeacute: 0x01FD,
  20917. aekorean: 0x3150,
  20918. aemacron: 0x01E3,
  20919. afii00208: 0x2015,
  20920. afii08941: 0x20A4,
  20921. afii10017: 0x0410,
  20922. afii10018: 0x0411,
  20923. afii10019: 0x0412,
  20924. afii10020: 0x0413,
  20925. afii10021: 0x0414,
  20926. afii10022: 0x0415,
  20927. afii10023: 0x0401,
  20928. afii10024: 0x0416,
  20929. afii10025: 0x0417,
  20930. afii10026: 0x0418,
  20931. afii10027: 0x0419,
  20932. afii10028: 0x041A,
  20933. afii10029: 0x041B,
  20934. afii10030: 0x041C,
  20935. afii10031: 0x041D,
  20936. afii10032: 0x041E,
  20937. afii10033: 0x041F,
  20938. afii10034: 0x0420,
  20939. afii10035: 0x0421,
  20940. afii10036: 0x0422,
  20941. afii10037: 0x0423,
  20942. afii10038: 0x0424,
  20943. afii10039: 0x0425,
  20944. afii10040: 0x0426,
  20945. afii10041: 0x0427,
  20946. afii10042: 0x0428,
  20947. afii10043: 0x0429,
  20948. afii10044: 0x042A,
  20949. afii10045: 0x042B,
  20950. afii10046: 0x042C,
  20951. afii10047: 0x042D,
  20952. afii10048: 0x042E,
  20953. afii10049: 0x042F,
  20954. afii10050: 0x0490,
  20955. afii10051: 0x0402,
  20956. afii10052: 0x0403,
  20957. afii10053: 0x0404,
  20958. afii10054: 0x0405,
  20959. afii10055: 0x0406,
  20960. afii10056: 0x0407,
  20961. afii10057: 0x0408,
  20962. afii10058: 0x0409,
  20963. afii10059: 0x040A,
  20964. afii10060: 0x040B,
  20965. afii10061: 0x040C,
  20966. afii10062: 0x040E,
  20967. afii10063: 0xF6C4,
  20968. afii10064: 0xF6C5,
  20969. afii10065: 0x0430,
  20970. afii10066: 0x0431,
  20971. afii10067: 0x0432,
  20972. afii10068: 0x0433,
  20973. afii10069: 0x0434,
  20974. afii10070: 0x0435,
  20975. afii10071: 0x0451,
  20976. afii10072: 0x0436,
  20977. afii10073: 0x0437,
  20978. afii10074: 0x0438,
  20979. afii10075: 0x0439,
  20980. afii10076: 0x043A,
  20981. afii10077: 0x043B,
  20982. afii10078: 0x043C,
  20983. afii10079: 0x043D,
  20984. afii10080: 0x043E,
  20985. afii10081: 0x043F,
  20986. afii10082: 0x0440,
  20987. afii10083: 0x0441,
  20988. afii10084: 0x0442,
  20989. afii10085: 0x0443,
  20990. afii10086: 0x0444,
  20991. afii10087: 0x0445,
  20992. afii10088: 0x0446,
  20993. afii10089: 0x0447,
  20994. afii10090: 0x0448,
  20995. afii10091: 0x0449,
  20996. afii10092: 0x044A,
  20997. afii10093: 0x044B,
  20998. afii10094: 0x044C,
  20999. afii10095: 0x044D,
  21000. afii10096: 0x044E,
  21001. afii10097: 0x044F,
  21002. afii10098: 0x0491,
  21003. afii10099: 0x0452,
  21004. afii10100: 0x0453,
  21005. afii10101: 0x0454,
  21006. afii10102: 0x0455,
  21007. afii10103: 0x0456,
  21008. afii10104: 0x0457,
  21009. afii10105: 0x0458,
  21010. afii10106: 0x0459,
  21011. afii10107: 0x045A,
  21012. afii10108: 0x045B,
  21013. afii10109: 0x045C,
  21014. afii10110: 0x045E,
  21015. afii10145: 0x040F,
  21016. afii10146: 0x0462,
  21017. afii10147: 0x0472,
  21018. afii10148: 0x0474,
  21019. afii10192: 0xF6C6,
  21020. afii10193: 0x045F,
  21021. afii10194: 0x0463,
  21022. afii10195: 0x0473,
  21023. afii10196: 0x0475,
  21024. afii10831: 0xF6C7,
  21025. afii10832: 0xF6C8,
  21026. afii10846: 0x04D9,
  21027. afii299: 0x200E,
  21028. afii300: 0x200F,
  21029. afii301: 0x200D,
  21030. afii57381: 0x066A,
  21031. afii57388: 0x060C,
  21032. afii57392: 0x0660,
  21033. afii57393: 0x0661,
  21034. afii57394: 0x0662,
  21035. afii57395: 0x0663,
  21036. afii57396: 0x0664,
  21037. afii57397: 0x0665,
  21038. afii57398: 0x0666,
  21039. afii57399: 0x0667,
  21040. afii57400: 0x0668,
  21041. afii57401: 0x0669,
  21042. afii57403: 0x061B,
  21043. afii57407: 0x061F,
  21044. afii57409: 0x0621,
  21045. afii57410: 0x0622,
  21046. afii57411: 0x0623,
  21047. afii57412: 0x0624,
  21048. afii57413: 0x0625,
  21049. afii57414: 0x0626,
  21050. afii57415: 0x0627,
  21051. afii57416: 0x0628,
  21052. afii57417: 0x0629,
  21053. afii57418: 0x062A,
  21054. afii57419: 0x062B,
  21055. afii57420: 0x062C,
  21056. afii57421: 0x062D,
  21057. afii57422: 0x062E,
  21058. afii57423: 0x062F,
  21059. afii57424: 0x0630,
  21060. afii57425: 0x0631,
  21061. afii57426: 0x0632,
  21062. afii57427: 0x0633,
  21063. afii57428: 0x0634,
  21064. afii57429: 0x0635,
  21065. afii57430: 0x0636,
  21066. afii57431: 0x0637,
  21067. afii57432: 0x0638,
  21068. afii57433: 0x0639,
  21069. afii57434: 0x063A,
  21070. afii57440: 0x0640,
  21071. afii57441: 0x0641,
  21072. afii57442: 0x0642,
  21073. afii57443: 0x0643,
  21074. afii57444: 0x0644,
  21075. afii57445: 0x0645,
  21076. afii57446: 0x0646,
  21077. afii57448: 0x0648,
  21078. afii57449: 0x0649,
  21079. afii57450: 0x064A,
  21080. afii57451: 0x064B,
  21081. afii57452: 0x064C,
  21082. afii57453: 0x064D,
  21083. afii57454: 0x064E,
  21084. afii57455: 0x064F,
  21085. afii57456: 0x0650,
  21086. afii57457: 0x0651,
  21087. afii57458: 0x0652,
  21088. afii57470: 0x0647,
  21089. afii57505: 0x06A4,
  21090. afii57506: 0x067E,
  21091. afii57507: 0x0686,
  21092. afii57508: 0x0698,
  21093. afii57509: 0x06AF,
  21094. afii57511: 0x0679,
  21095. afii57512: 0x0688,
  21096. afii57513: 0x0691,
  21097. afii57514: 0x06BA,
  21098. afii57519: 0x06D2,
  21099. afii57534: 0x06D5,
  21100. afii57636: 0x20AA,
  21101. afii57645: 0x05BE,
  21102. afii57658: 0x05C3,
  21103. afii57664: 0x05D0,
  21104. afii57665: 0x05D1,
  21105. afii57666: 0x05D2,
  21106. afii57667: 0x05D3,
  21107. afii57668: 0x05D4,
  21108. afii57669: 0x05D5,
  21109. afii57670: 0x05D6,
  21110. afii57671: 0x05D7,
  21111. afii57672: 0x05D8,
  21112. afii57673: 0x05D9,
  21113. afii57674: 0x05DA,
  21114. afii57675: 0x05DB,
  21115. afii57676: 0x05DC,
  21116. afii57677: 0x05DD,
  21117. afii57678: 0x05DE,
  21118. afii57679: 0x05DF,
  21119. afii57680: 0x05E0,
  21120. afii57681: 0x05E1,
  21121. afii57682: 0x05E2,
  21122. afii57683: 0x05E3,
  21123. afii57684: 0x05E4,
  21124. afii57685: 0x05E5,
  21125. afii57686: 0x05E6,
  21126. afii57687: 0x05E7,
  21127. afii57688: 0x05E8,
  21128. afii57689: 0x05E9,
  21129. afii57690: 0x05EA,
  21130. afii57694: 0xFB2A,
  21131. afii57695: 0xFB2B,
  21132. afii57700: 0xFB4B,
  21133. afii57705: 0xFB1F,
  21134. afii57716: 0x05F0,
  21135. afii57717: 0x05F1,
  21136. afii57718: 0x05F2,
  21137. afii57723: 0xFB35,
  21138. afii57793: 0x05B4,
  21139. afii57794: 0x05B5,
  21140. afii57795: 0x05B6,
  21141. afii57796: 0x05BB,
  21142. afii57797: 0x05B8,
  21143. afii57798: 0x05B7,
  21144. afii57799: 0x05B0,
  21145. afii57800: 0x05B2,
  21146. afii57801: 0x05B1,
  21147. afii57802: 0x05B3,
  21148. afii57803: 0x05C2,
  21149. afii57804: 0x05C1,
  21150. afii57806: 0x05B9,
  21151. afii57807: 0x05BC,
  21152. afii57839: 0x05BD,
  21153. afii57841: 0x05BF,
  21154. afii57842: 0x05C0,
  21155. afii57929: 0x02BC,
  21156. afii61248: 0x2105,
  21157. afii61289: 0x2113,
  21158. afii61352: 0x2116,
  21159. afii61573: 0x202C,
  21160. afii61574: 0x202D,
  21161. afii61575: 0x202E,
  21162. afii61664: 0x200C,
  21163. afii63167: 0x066D,
  21164. afii64937: 0x02BD,
  21165. agrave: 0x00E0,
  21166. agujarati: 0x0A85,
  21167. agurmukhi: 0x0A05,
  21168. ahiragana: 0x3042,
  21169. ahookabove: 0x1EA3,
  21170. aibengali: 0x0990,
  21171. aibopomofo: 0x311E,
  21172. aideva: 0x0910,
  21173. aiecyrillic: 0x04D5,
  21174. aigujarati: 0x0A90,
  21175. aigurmukhi: 0x0A10,
  21176. aimatragurmukhi: 0x0A48,
  21177. ainarabic: 0x0639,
  21178. ainfinalarabic: 0xFECA,
  21179. aininitialarabic: 0xFECB,
  21180. ainmedialarabic: 0xFECC,
  21181. ainvertedbreve: 0x0203,
  21182. aivowelsignbengali: 0x09C8,
  21183. aivowelsigndeva: 0x0948,
  21184. aivowelsigngujarati: 0x0AC8,
  21185. akatakana: 0x30A2,
  21186. akatakanahalfwidth: 0xFF71,
  21187. akorean: 0x314F,
  21188. alef: 0x05D0,
  21189. alefarabic: 0x0627,
  21190. alefdageshhebrew: 0xFB30,
  21191. aleffinalarabic: 0xFE8E,
  21192. alefhamzaabovearabic: 0x0623,
  21193. alefhamzaabovefinalarabic: 0xFE84,
  21194. alefhamzabelowarabic: 0x0625,
  21195. alefhamzabelowfinalarabic: 0xFE88,
  21196. alefhebrew: 0x05D0,
  21197. aleflamedhebrew: 0xFB4F,
  21198. alefmaddaabovearabic: 0x0622,
  21199. alefmaddaabovefinalarabic: 0xFE82,
  21200. alefmaksuraarabic: 0x0649,
  21201. alefmaksurafinalarabic: 0xFEF0,
  21202. alefmaksurainitialarabic: 0xFEF3,
  21203. alefmaksuramedialarabic: 0xFEF4,
  21204. alefpatahhebrew: 0xFB2E,
  21205. alefqamatshebrew: 0xFB2F,
  21206. aleph: 0x2135,
  21207. allequal: 0x224C,
  21208. alpha: 0x03B1,
  21209. alphatonos: 0x03AC,
  21210. amacron: 0x0101,
  21211. amonospace: 0xFF41,
  21212. ampersand: 0x0026,
  21213. ampersandmonospace: 0xFF06,
  21214. ampersandsmall: 0xF726,
  21215. amsquare: 0x33C2,
  21216. anbopomofo: 0x3122,
  21217. angbopomofo: 0x3124,
  21218. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21219. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21220. angkhankhuthai: 0x0E5A,
  21221. angle: 0x2220,
  21222. anglebracketleft: 0x3008,
  21223. anglebracketleftvertical: 0xFE3F,
  21224. anglebracketright: 0x3009,
  21225. anglebracketrightvertical: 0xFE40,
  21226. angleleft: 0x2329,
  21227. angleright: 0x232A,
  21228. angstrom: 0x212B,
  21229. anoteleia: 0x0387,
  21230. anudattadeva: 0x0952,
  21231. anusvarabengali: 0x0982,
  21232. anusvaradeva: 0x0902,
  21233. anusvaragujarati: 0x0A82,
  21234. aogonek: 0x0105,
  21235. apaatosquare: 0x3300,
  21236. aparen: 0x249C,
  21237. apostrophearmenian: 0x055A,
  21238. apostrophemod: 0x02BC,
  21239. apple: 0xF8FF,
  21240. approaches: 0x2250,
  21241. approxequal: 0x2248,
  21242. approxequalorimage: 0x2252,
  21243. approximatelyequal: 0x2245,
  21244. araeaekorean: 0x318E,
  21245. araeakorean: 0x318D,
  21246. arc: 0x2312,
  21247. arighthalfring: 0x1E9A,
  21248. aring: 0x00E5,
  21249. aringacute: 0x01FB,
  21250. aringbelow: 0x1E01,
  21251. arrowboth: 0x2194,
  21252. arrowdashdown: 0x21E3,
  21253. arrowdashleft: 0x21E0,
  21254. arrowdashright: 0x21E2,
  21255. arrowdashup: 0x21E1,
  21256. arrowdblboth: 0x21D4,
  21257. arrowdbldown: 0x21D3,
  21258. arrowdblleft: 0x21D0,
  21259. arrowdblright: 0x21D2,
  21260. arrowdblup: 0x21D1,
  21261. arrowdown: 0x2193,
  21262. arrowdownleft: 0x2199,
  21263. arrowdownright: 0x2198,
  21264. arrowdownwhite: 0x21E9,
  21265. arrowheaddownmod: 0x02C5,
  21266. arrowheadleftmod: 0x02C2,
  21267. arrowheadrightmod: 0x02C3,
  21268. arrowheadupmod: 0x02C4,
  21269. arrowhorizex: 0xF8E7,
  21270. arrowleft: 0x2190,
  21271. arrowleftdbl: 0x21D0,
  21272. arrowleftdblstroke: 0x21CD,
  21273. arrowleftoverright: 0x21C6,
  21274. arrowleftwhite: 0x21E6,
  21275. arrowright: 0x2192,
  21276. arrowrightdblstroke: 0x21CF,
  21277. arrowrightheavy: 0x279E,
  21278. arrowrightoverleft: 0x21C4,
  21279. arrowrightwhite: 0x21E8,
  21280. arrowtableft: 0x21E4,
  21281. arrowtabright: 0x21E5,
  21282. arrowup: 0x2191,
  21283. arrowupdn: 0x2195,
  21284. arrowupdnbse: 0x21A8,
  21285. arrowupdownbase: 0x21A8,
  21286. arrowupleft: 0x2196,
  21287. arrowupleftofdown: 0x21C5,
  21288. arrowupright: 0x2197,
  21289. arrowupwhite: 0x21E7,
  21290. arrowvertex: 0xF8E6,
  21291. asciicircum: 0x005E,
  21292. asciicircummonospace: 0xFF3E,
  21293. asciitilde: 0x007E,
  21294. asciitildemonospace: 0xFF5E,
  21295. ascript: 0x0251,
  21296. ascriptturned: 0x0252,
  21297. asmallhiragana: 0x3041,
  21298. asmallkatakana: 0x30A1,
  21299. asmallkatakanahalfwidth: 0xFF67,
  21300. asterisk: 0x002A,
  21301. asteriskaltonearabic: 0x066D,
  21302. asteriskarabic: 0x066D,
  21303. asteriskmath: 0x2217,
  21304. asteriskmonospace: 0xFF0A,
  21305. asterisksmall: 0xFE61,
  21306. asterism: 0x2042,
  21307. asuperior: 0xF6E9,
  21308. asymptoticallyequal: 0x2243,
  21309. at: 0x0040,
  21310. atilde: 0x00E3,
  21311. atmonospace: 0xFF20,
  21312. atsmall: 0xFE6B,
  21313. aturned: 0x0250,
  21314. aubengali: 0x0994,
  21315. aubopomofo: 0x3120,
  21316. audeva: 0x0914,
  21317. augujarati: 0x0A94,
  21318. augurmukhi: 0x0A14,
  21319. aulengthmarkbengali: 0x09D7,
  21320. aumatragurmukhi: 0x0A4C,
  21321. auvowelsignbengali: 0x09CC,
  21322. auvowelsigndeva: 0x094C,
  21323. auvowelsigngujarati: 0x0ACC,
  21324. avagrahadeva: 0x093D,
  21325. aybarmenian: 0x0561,
  21326. ayin: 0x05E2,
  21327. ayinaltonehebrew: 0xFB20,
  21328. ayinhebrew: 0x05E2,
  21329. b: 0x0062,
  21330. babengali: 0x09AC,
  21331. backslash: 0x005C,
  21332. backslashmonospace: 0xFF3C,
  21333. badeva: 0x092C,
  21334. bagujarati: 0x0AAC,
  21335. bagurmukhi: 0x0A2C,
  21336. bahiragana: 0x3070,
  21337. bahtthai: 0x0E3F,
  21338. bakatakana: 0x30D0,
  21339. bar: 0x007C,
  21340. barmonospace: 0xFF5C,
  21341. bbopomofo: 0x3105,
  21342. bcircle: 0x24D1,
  21343. bdotaccent: 0x1E03,
  21344. bdotbelow: 0x1E05,
  21345. beamedsixteenthnotes: 0x266C,
  21346. because: 0x2235,
  21347. becyrillic: 0x0431,
  21348. beharabic: 0x0628,
  21349. behfinalarabic: 0xFE90,
  21350. behinitialarabic: 0xFE91,
  21351. behiragana: 0x3079,
  21352. behmedialarabic: 0xFE92,
  21353. behmeeminitialarabic: 0xFC9F,
  21354. behmeemisolatedarabic: 0xFC08,
  21355. behnoonfinalarabic: 0xFC6D,
  21356. bekatakana: 0x30D9,
  21357. benarmenian: 0x0562,
  21358. bet: 0x05D1,
  21359. beta: 0x03B2,
  21360. betasymbolgreek: 0x03D0,
  21361. betdagesh: 0xFB31,
  21362. betdageshhebrew: 0xFB31,
  21363. bethebrew: 0x05D1,
  21364. betrafehebrew: 0xFB4C,
  21365. bhabengali: 0x09AD,
  21366. bhadeva: 0x092D,
  21367. bhagujarati: 0x0AAD,
  21368. bhagurmukhi: 0x0A2D,
  21369. bhook: 0x0253,
  21370. bihiragana: 0x3073,
  21371. bikatakana: 0x30D3,
  21372. bilabialclick: 0x0298,
  21373. bindigurmukhi: 0x0A02,
  21374. birusquare: 0x3331,
  21375. blackcircle: 0x25CF,
  21376. blackdiamond: 0x25C6,
  21377. blackdownpointingtriangle: 0x25BC,
  21378. blackleftpointingpointer: 0x25C4,
  21379. blackleftpointingtriangle: 0x25C0,
  21380. blacklenticularbracketleft: 0x3010,
  21381. blacklenticularbracketleftvertical: 0xFE3B,
  21382. blacklenticularbracketright: 0x3011,
  21383. blacklenticularbracketrightvertical: 0xFE3C,
  21384. blacklowerlefttriangle: 0x25E3,
  21385. blacklowerrighttriangle: 0x25E2,
  21386. blackrectangle: 0x25AC,
  21387. blackrightpointingpointer: 0x25BA,
  21388. blackrightpointingtriangle: 0x25B6,
  21389. blacksmallsquare: 0x25AA,
  21390. blacksmilingface: 0x263B,
  21391. blacksquare: 0x25A0,
  21392. blackstar: 0x2605,
  21393. blackupperlefttriangle: 0x25E4,
  21394. blackupperrighttriangle: 0x25E5,
  21395. blackuppointingsmalltriangle: 0x25B4,
  21396. blackuppointingtriangle: 0x25B2,
  21397. blank: 0x2423,
  21398. blinebelow: 0x1E07,
  21399. block: 0x2588,
  21400. bmonospace: 0xFF42,
  21401. bobaimaithai: 0x0E1A,
  21402. bohiragana: 0x307C,
  21403. bokatakana: 0x30DC,
  21404. bparen: 0x249D,
  21405. bqsquare: 0x33C3,
  21406. braceex: 0xF8F4,
  21407. braceleft: 0x007B,
  21408. braceleftbt: 0xF8F3,
  21409. braceleftmid: 0xF8F2,
  21410. braceleftmonospace: 0xFF5B,
  21411. braceleftsmall: 0xFE5B,
  21412. bracelefttp: 0xF8F1,
  21413. braceleftvertical: 0xFE37,
  21414. braceright: 0x007D,
  21415. bracerightbt: 0xF8FE,
  21416. bracerightmid: 0xF8FD,
  21417. bracerightmonospace: 0xFF5D,
  21418. bracerightsmall: 0xFE5C,
  21419. bracerighttp: 0xF8FC,
  21420. bracerightvertical: 0xFE38,
  21421. bracketleft: 0x005B,
  21422. bracketleftbt: 0xF8F0,
  21423. bracketleftex: 0xF8EF,
  21424. bracketleftmonospace: 0xFF3B,
  21425. bracketlefttp: 0xF8EE,
  21426. bracketright: 0x005D,
  21427. bracketrightbt: 0xF8FB,
  21428. bracketrightex: 0xF8FA,
  21429. bracketrightmonospace: 0xFF3D,
  21430. bracketrighttp: 0xF8F9,
  21431. breve: 0x02D8,
  21432. brevebelowcmb: 0x032E,
  21433. brevecmb: 0x0306,
  21434. breveinvertedbelowcmb: 0x032F,
  21435. breveinvertedcmb: 0x0311,
  21436. breveinverteddoublecmb: 0x0361,
  21437. bridgebelowcmb: 0x032A,
  21438. bridgeinvertedbelowcmb: 0x033A,
  21439. brokenbar: 0x00A6,
  21440. bstroke: 0x0180,
  21441. bsuperior: 0xF6EA,
  21442. btopbar: 0x0183,
  21443. buhiragana: 0x3076,
  21444. bukatakana: 0x30D6,
  21445. bullet: 0x2022,
  21446. bulletinverse: 0x25D8,
  21447. bulletoperator: 0x2219,
  21448. bullseye: 0x25CE,
  21449. c: 0x0063,
  21450. caarmenian: 0x056E,
  21451. cabengali: 0x099A,
  21452. cacute: 0x0107,
  21453. cadeva: 0x091A,
  21454. cagujarati: 0x0A9A,
  21455. cagurmukhi: 0x0A1A,
  21456. calsquare: 0x3388,
  21457. candrabindubengali: 0x0981,
  21458. candrabinducmb: 0x0310,
  21459. candrabindudeva: 0x0901,
  21460. candrabindugujarati: 0x0A81,
  21461. capslock: 0x21EA,
  21462. careof: 0x2105,
  21463. caron: 0x02C7,
  21464. caronbelowcmb: 0x032C,
  21465. caroncmb: 0x030C,
  21466. carriagereturn: 0x21B5,
  21467. cbopomofo: 0x3118,
  21468. ccaron: 0x010D,
  21469. ccedilla: 0x00E7,
  21470. ccedillaacute: 0x1E09,
  21471. ccircle: 0x24D2,
  21472. ccircumflex: 0x0109,
  21473. ccurl: 0x0255,
  21474. cdot: 0x010B,
  21475. cdotaccent: 0x010B,
  21476. cdsquare: 0x33C5,
  21477. cedilla: 0x00B8,
  21478. cedillacmb: 0x0327,
  21479. cent: 0x00A2,
  21480. centigrade: 0x2103,
  21481. centinferior: 0xF6DF,
  21482. centmonospace: 0xFFE0,
  21483. centoldstyle: 0xF7A2,
  21484. centsuperior: 0xF6E0,
  21485. chaarmenian: 0x0579,
  21486. chabengali: 0x099B,
  21487. chadeva: 0x091B,
  21488. chagujarati: 0x0A9B,
  21489. chagurmukhi: 0x0A1B,
  21490. chbopomofo: 0x3114,
  21491. cheabkhasiancyrillic: 0x04BD,
  21492. checkmark: 0x2713,
  21493. checyrillic: 0x0447,
  21494. chedescenderabkhasiancyrillic: 0x04BF,
  21495. chedescendercyrillic: 0x04B7,
  21496. chedieresiscyrillic: 0x04F5,
  21497. cheharmenian: 0x0573,
  21498. chekhakassiancyrillic: 0x04CC,
  21499. cheverticalstrokecyrillic: 0x04B9,
  21500. chi: 0x03C7,
  21501. chieuchacirclekorean: 0x3277,
  21502. chieuchaparenkorean: 0x3217,
  21503. chieuchcirclekorean: 0x3269,
  21504. chieuchkorean: 0x314A,
  21505. chieuchparenkorean: 0x3209,
  21506. chochangthai: 0x0E0A,
  21507. chochanthai: 0x0E08,
  21508. chochingthai: 0x0E09,
  21509. chochoethai: 0x0E0C,
  21510. chook: 0x0188,
  21511. cieucacirclekorean: 0x3276,
  21512. cieucaparenkorean: 0x3216,
  21513. cieuccirclekorean: 0x3268,
  21514. cieuckorean: 0x3148,
  21515. cieucparenkorean: 0x3208,
  21516. cieucuparenkorean: 0x321C,
  21517. circle: 0x25CB,
  21518. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21519. circlemultiply: 0x2297,
  21520. circleot: 0x2299,
  21521. circleplus: 0x2295,
  21522. circlepostalmark: 0x3036,
  21523. circlewithlefthalfblack: 0x25D0,
  21524. circlewithrighthalfblack: 0x25D1,
  21525. circumflex: 0x02C6,
  21526. circumflexbelowcmb: 0x032D,
  21527. circumflexcmb: 0x0302,
  21528. clear: 0x2327,
  21529. clickalveolar: 0x01C2,
  21530. clickdental: 0x01C0,
  21531. clicklateral: 0x01C1,
  21532. clickretroflex: 0x01C3,
  21533. club: 0x2663,
  21534. clubsuitblack: 0x2663,
  21535. clubsuitwhite: 0x2667,
  21536. cmcubedsquare: 0x33A4,
  21537. cmonospace: 0xFF43,
  21538. cmsquaredsquare: 0x33A0,
  21539. coarmenian: 0x0581,
  21540. colon: 0x003A,
  21541. colonmonetary: 0x20A1,
  21542. colonmonospace: 0xFF1A,
  21543. colonsign: 0x20A1,
  21544. colonsmall: 0xFE55,
  21545. colontriangularhalfmod: 0x02D1,
  21546. colontriangularmod: 0x02D0,
  21547. comma: 0x002C,
  21548. commaabovecmb: 0x0313,
  21549. commaaboverightcmb: 0x0315,
  21550. commaaccent: 0xF6C3,
  21551. commaarabic: 0x060C,
  21552. commaarmenian: 0x055D,
  21553. commainferior: 0xF6E1,
  21554. commamonospace: 0xFF0C,
  21555. commareversedabovecmb: 0x0314,
  21556. commareversedmod: 0x02BD,
  21557. commasmall: 0xFE50,
  21558. commasuperior: 0xF6E2,
  21559. commaturnedabovecmb: 0x0312,
  21560. commaturnedmod: 0x02BB,
  21561. compass: 0x263C,
  21562. congruent: 0x2245,
  21563. contourintegral: 0x222E,
  21564. control: 0x2303,
  21565. controlACK: 0x0006,
  21566. controlBEL: 0x0007,
  21567. controlBS: 0x0008,
  21568. controlCAN: 0x0018,
  21569. controlCR: 0x000D,
  21570. controlDC1: 0x0011,
  21571. controlDC2: 0x0012,
  21572. controlDC3: 0x0013,
  21573. controlDC4: 0x0014,
  21574. controlDEL: 0x007F,
  21575. controlDLE: 0x0010,
  21576. controlEM: 0x0019,
  21577. controlENQ: 0x0005,
  21578. controlEOT: 0x0004,
  21579. controlESC: 0x001B,
  21580. controlETB: 0x0017,
  21581. controlETX: 0x0003,
  21582. controlFF: 0x000C,
  21583. controlFS: 0x001C,
  21584. controlGS: 0x001D,
  21585. controlHT: 0x0009,
  21586. controlLF: 0x000A,
  21587. controlNAK: 0x0015,
  21588. controlRS: 0x001E,
  21589. controlSI: 0x000F,
  21590. controlSO: 0x000E,
  21591. controlSOT: 0x0002,
  21592. controlSTX: 0x0001,
  21593. controlSUB: 0x001A,
  21594. controlSYN: 0x0016,
  21595. controlUS: 0x001F,
  21596. controlVT: 0x000B,
  21597. copyright: 0x00A9,
  21598. copyrightsans: 0xF8E9,
  21599. copyrightserif: 0xF6D9,
  21600. cornerbracketleft: 0x300C,
  21601. cornerbracketlefthalfwidth: 0xFF62,
  21602. cornerbracketleftvertical: 0xFE41,
  21603. cornerbracketright: 0x300D,
  21604. cornerbracketrighthalfwidth: 0xFF63,
  21605. cornerbracketrightvertical: 0xFE42,
  21606. corporationsquare: 0x337F,
  21607. cosquare: 0x33C7,
  21608. coverkgsquare: 0x33C6,
  21609. cparen: 0x249E,
  21610. cruzeiro: 0x20A2,
  21611. cstretched: 0x0297,
  21612. curlyand: 0x22CF,
  21613. curlyor: 0x22CE,
  21614. currency: 0x00A4,
  21615. cyrBreve: 0xF6D1,
  21616. cyrFlex: 0xF6D2,
  21617. cyrbreve: 0xF6D4,
  21618. cyrflex: 0xF6D5,
  21619. d: 0x0064,
  21620. daarmenian: 0x0564,
  21621. dabengali: 0x09A6,
  21622. dadarabic: 0x0636,
  21623. dadeva: 0x0926,
  21624. dadfinalarabic: 0xFEBE,
  21625. dadinitialarabic: 0xFEBF,
  21626. dadmedialarabic: 0xFEC0,
  21627. dagesh: 0x05BC,
  21628. dageshhebrew: 0x05BC,
  21629. dagger: 0x2020,
  21630. daggerdbl: 0x2021,
  21631. dagujarati: 0x0AA6,
  21632. dagurmukhi: 0x0A26,
  21633. dahiragana: 0x3060,
  21634. dakatakana: 0x30C0,
  21635. dalarabic: 0x062F,
  21636. dalet: 0x05D3,
  21637. daletdagesh: 0xFB33,
  21638. daletdageshhebrew: 0xFB33,
  21639. dalethebrew: 0x05D3,
  21640. dalfinalarabic: 0xFEAA,
  21641. dammaarabic: 0x064F,
  21642. dammalowarabic: 0x064F,
  21643. dammatanaltonearabic: 0x064C,
  21644. dammatanarabic: 0x064C,
  21645. danda: 0x0964,
  21646. dargahebrew: 0x05A7,
  21647. dargalefthebrew: 0x05A7,
  21648. dasiapneumatacyrilliccmb: 0x0485,
  21649. dblGrave: 0xF6D3,
  21650. dblanglebracketleft: 0x300A,
  21651. dblanglebracketleftvertical: 0xFE3D,
  21652. dblanglebracketright: 0x300B,
  21653. dblanglebracketrightvertical: 0xFE3E,
  21654. dblarchinvertedbelowcmb: 0x032B,
  21655. dblarrowleft: 0x21D4,
  21656. dblarrowright: 0x21D2,
  21657. dbldanda: 0x0965,
  21658. dblgrave: 0xF6D6,
  21659. dblgravecmb: 0x030F,
  21660. dblintegral: 0x222C,
  21661. dbllowline: 0x2017,
  21662. dbllowlinecmb: 0x0333,
  21663. dbloverlinecmb: 0x033F,
  21664. dblprimemod: 0x02BA,
  21665. dblverticalbar: 0x2016,
  21666. dblverticallineabovecmb: 0x030E,
  21667. dbopomofo: 0x3109,
  21668. dbsquare: 0x33C8,
  21669. dcaron: 0x010F,
  21670. dcedilla: 0x1E11,
  21671. dcircle: 0x24D3,
  21672. dcircumflexbelow: 0x1E13,
  21673. dcroat: 0x0111,
  21674. ddabengali: 0x09A1,
  21675. ddadeva: 0x0921,
  21676. ddagujarati: 0x0AA1,
  21677. ddagurmukhi: 0x0A21,
  21678. ddalarabic: 0x0688,
  21679. ddalfinalarabic: 0xFB89,
  21680. dddhadeva: 0x095C,
  21681. ddhabengali: 0x09A2,
  21682. ddhadeva: 0x0922,
  21683. ddhagujarati: 0x0AA2,
  21684. ddhagurmukhi: 0x0A22,
  21685. ddotaccent: 0x1E0B,
  21686. ddotbelow: 0x1E0D,
  21687. decimalseparatorarabic: 0x066B,
  21688. decimalseparatorpersian: 0x066B,
  21689. decyrillic: 0x0434,
  21690. degree: 0x00B0,
  21691. dehihebrew: 0x05AD,
  21692. dehiragana: 0x3067,
  21693. deicoptic: 0x03EF,
  21694. dekatakana: 0x30C7,
  21695. deleteleft: 0x232B,
  21696. deleteright: 0x2326,
  21697. delta: 0x03B4,
  21698. deltaturned: 0x018D,
  21699. denominatorminusonenumeratorbengali: 0x09F8,
  21700. dezh: 0x02A4,
  21701. dhabengali: 0x09A7,
  21702. dhadeva: 0x0927,
  21703. dhagujarati: 0x0AA7,
  21704. dhagurmukhi: 0x0A27,
  21705. dhook: 0x0257,
  21706. dialytikatonos: 0x0385,
  21707. dialytikatonoscmb: 0x0344,
  21708. diamond: 0x2666,
  21709. diamondsuitwhite: 0x2662,
  21710. dieresis: 0x00A8,
  21711. dieresisacute: 0xF6D7,
  21712. dieresisbelowcmb: 0x0324,
  21713. dieresiscmb: 0x0308,
  21714. dieresisgrave: 0xF6D8,
  21715. dieresistonos: 0x0385,
  21716. dihiragana: 0x3062,
  21717. dikatakana: 0x30C2,
  21718. dittomark: 0x3003,
  21719. divide: 0x00F7,
  21720. divides: 0x2223,
  21721. divisionslash: 0x2215,
  21722. djecyrillic: 0x0452,
  21723. dkshade: 0x2593,
  21724. dlinebelow: 0x1E0F,
  21725. dlsquare: 0x3397,
  21726. dmacron: 0x0111,
  21727. dmonospace: 0xFF44,
  21728. dnblock: 0x2584,
  21729. dochadathai: 0x0E0E,
  21730. dodekthai: 0x0E14,
  21731. dohiragana: 0x3069,
  21732. dokatakana: 0x30C9,
  21733. dollar: 0x0024,
  21734. dollarinferior: 0xF6E3,
  21735. dollarmonospace: 0xFF04,
  21736. dollaroldstyle: 0xF724,
  21737. dollarsmall: 0xFE69,
  21738. dollarsuperior: 0xF6E4,
  21739. dong: 0x20AB,
  21740. dorusquare: 0x3326,
  21741. dotaccent: 0x02D9,
  21742. dotaccentcmb: 0x0307,
  21743. dotbelowcmb: 0x0323,
  21744. dotbelowcomb: 0x0323,
  21745. dotkatakana: 0x30FB,
  21746. dotlessi: 0x0131,
  21747. dotlessj: 0xF6BE,
  21748. dotlessjstrokehook: 0x0284,
  21749. dotmath: 0x22C5,
  21750. dottedcircle: 0x25CC,
  21751. doubleyodpatah: 0xFB1F,
  21752. doubleyodpatahhebrew: 0xFB1F,
  21753. downtackbelowcmb: 0x031E,
  21754. downtackmod: 0x02D5,
  21755. dparen: 0x249F,
  21756. dsuperior: 0xF6EB,
  21757. dtail: 0x0256,
  21758. dtopbar: 0x018C,
  21759. duhiragana: 0x3065,
  21760. dukatakana: 0x30C5,
  21761. dz: 0x01F3,
  21762. dzaltone: 0x02A3,
  21763. dzcaron: 0x01C6,
  21764. dzcurl: 0x02A5,
  21765. dzeabkhasiancyrillic: 0x04E1,
  21766. dzecyrillic: 0x0455,
  21767. dzhecyrillic: 0x045F,
  21768. e: 0x0065,
  21769. eacute: 0x00E9,
  21770. earth: 0x2641,
  21771. ebengali: 0x098F,
  21772. ebopomofo: 0x311C,
  21773. ebreve: 0x0115,
  21774. ecandradeva: 0x090D,
  21775. ecandragujarati: 0x0A8D,
  21776. ecandravowelsigndeva: 0x0945,
  21777. ecandravowelsigngujarati: 0x0AC5,
  21778. ecaron: 0x011B,
  21779. ecedillabreve: 0x1E1D,
  21780. echarmenian: 0x0565,
  21781. echyiwnarmenian: 0x0587,
  21782. ecircle: 0x24D4,
  21783. ecircumflex: 0x00EA,
  21784. ecircumflexacute: 0x1EBF,
  21785. ecircumflexbelow: 0x1E19,
  21786. ecircumflexdotbelow: 0x1EC7,
  21787. ecircumflexgrave: 0x1EC1,
  21788. ecircumflexhookabove: 0x1EC3,
  21789. ecircumflextilde: 0x1EC5,
  21790. ecyrillic: 0x0454,
  21791. edblgrave: 0x0205,
  21792. edeva: 0x090F,
  21793. edieresis: 0x00EB,
  21794. edot: 0x0117,
  21795. edotaccent: 0x0117,
  21796. edotbelow: 0x1EB9,
  21797. eegurmukhi: 0x0A0F,
  21798. eematragurmukhi: 0x0A47,
  21799. efcyrillic: 0x0444,
  21800. egrave: 0x00E8,
  21801. egujarati: 0x0A8F,
  21802. eharmenian: 0x0567,
  21803. ehbopomofo: 0x311D,
  21804. ehiragana: 0x3048,
  21805. ehookabove: 0x1EBB,
  21806. eibopomofo: 0x311F,
  21807. eight: 0x0038,
  21808. eightarabic: 0x0668,
  21809. eightbengali: 0x09EE,
  21810. eightcircle: 0x2467,
  21811. eightcircleinversesansserif: 0x2791,
  21812. eightdeva: 0x096E,
  21813. eighteencircle: 0x2471,
  21814. eighteenparen: 0x2485,
  21815. eighteenperiod: 0x2499,
  21816. eightgujarati: 0x0AEE,
  21817. eightgurmukhi: 0x0A6E,
  21818. eighthackarabic: 0x0668,
  21819. eighthangzhou: 0x3028,
  21820. eighthnotebeamed: 0x266B,
  21821. eightideographicparen: 0x3227,
  21822. eightinferior: 0x2088,
  21823. eightmonospace: 0xFF18,
  21824. eightoldstyle: 0xF738,
  21825. eightparen: 0x247B,
  21826. eightperiod: 0x248F,
  21827. eightpersian: 0x06F8,
  21828. eightroman: 0x2177,
  21829. eightsuperior: 0x2078,
  21830. eightthai: 0x0E58,
  21831. einvertedbreve: 0x0207,
  21832. eiotifiedcyrillic: 0x0465,
  21833. ekatakana: 0x30A8,
  21834. ekatakanahalfwidth: 0xFF74,
  21835. ekonkargurmukhi: 0x0A74,
  21836. ekorean: 0x3154,
  21837. elcyrillic: 0x043B,
  21838. element: 0x2208,
  21839. elevencircle: 0x246A,
  21840. elevenparen: 0x247E,
  21841. elevenperiod: 0x2492,
  21842. elevenroman: 0x217A,
  21843. ellipsis: 0x2026,
  21844. ellipsisvertical: 0x22EE,
  21845. emacron: 0x0113,
  21846. emacronacute: 0x1E17,
  21847. emacrongrave: 0x1E15,
  21848. emcyrillic: 0x043C,
  21849. emdash: 0x2014,
  21850. emdashvertical: 0xFE31,
  21851. emonospace: 0xFF45,
  21852. emphasismarkarmenian: 0x055B,
  21853. emptyset: 0x2205,
  21854. enbopomofo: 0x3123,
  21855. encyrillic: 0x043D,
  21856. endash: 0x2013,
  21857. endashvertical: 0xFE32,
  21858. endescendercyrillic: 0x04A3,
  21859. eng: 0x014B,
  21860. engbopomofo: 0x3125,
  21861. enghecyrillic: 0x04A5,
  21862. enhookcyrillic: 0x04C8,
  21863. enspace: 0x2002,
  21864. eogonek: 0x0119,
  21865. eokorean: 0x3153,
  21866. eopen: 0x025B,
  21867. eopenclosed: 0x029A,
  21868. eopenreversed: 0x025C,
  21869. eopenreversedclosed: 0x025E,
  21870. eopenreversedhook: 0x025D,
  21871. eparen: 0x24A0,
  21872. epsilon: 0x03B5,
  21873. epsilontonos: 0x03AD,
  21874. equal: 0x003D,
  21875. equalmonospace: 0xFF1D,
  21876. equalsmall: 0xFE66,
  21877. equalsuperior: 0x207C,
  21878. equivalence: 0x2261,
  21879. erbopomofo: 0x3126,
  21880. ercyrillic: 0x0440,
  21881. ereversed: 0x0258,
  21882. ereversedcyrillic: 0x044D,
  21883. escyrillic: 0x0441,
  21884. esdescendercyrillic: 0x04AB,
  21885. esh: 0x0283,
  21886. eshcurl: 0x0286,
  21887. eshortdeva: 0x090E,
  21888. eshortvowelsigndeva: 0x0946,
  21889. eshreversedloop: 0x01AA,
  21890. eshsquatreversed: 0x0285,
  21891. esmallhiragana: 0x3047,
  21892. esmallkatakana: 0x30A7,
  21893. esmallkatakanahalfwidth: 0xFF6A,
  21894. estimated: 0x212E,
  21895. esuperior: 0xF6EC,
  21896. eta: 0x03B7,
  21897. etarmenian: 0x0568,
  21898. etatonos: 0x03AE,
  21899. eth: 0x00F0,
  21900. etilde: 0x1EBD,
  21901. etildebelow: 0x1E1B,
  21902. etnahtafoukhhebrew: 0x0591,
  21903. etnahtafoukhlefthebrew: 0x0591,
  21904. etnahtahebrew: 0x0591,
  21905. etnahtalefthebrew: 0x0591,
  21906. eturned: 0x01DD,
  21907. eukorean: 0x3161,
  21908. euro: 0x20AC,
  21909. evowelsignbengali: 0x09C7,
  21910. evowelsigndeva: 0x0947,
  21911. evowelsigngujarati: 0x0AC7,
  21912. exclam: 0x0021,
  21913. exclamarmenian: 0x055C,
  21914. exclamdbl: 0x203C,
  21915. exclamdown: 0x00A1,
  21916. exclamdownsmall: 0xF7A1,
  21917. exclammonospace: 0xFF01,
  21918. exclamsmall: 0xF721,
  21919. existential: 0x2203,
  21920. ezh: 0x0292,
  21921. ezhcaron: 0x01EF,
  21922. ezhcurl: 0x0293,
  21923. ezhreversed: 0x01B9,
  21924. ezhtail: 0x01BA,
  21925. f: 0x0066,
  21926. fadeva: 0x095E,
  21927. fagurmukhi: 0x0A5E,
  21928. fahrenheit: 0x2109,
  21929. fathaarabic: 0x064E,
  21930. fathalowarabic: 0x064E,
  21931. fathatanarabic: 0x064B,
  21932. fbopomofo: 0x3108,
  21933. fcircle: 0x24D5,
  21934. fdotaccent: 0x1E1F,
  21935. feharabic: 0x0641,
  21936. feharmenian: 0x0586,
  21937. fehfinalarabic: 0xFED2,
  21938. fehinitialarabic: 0xFED3,
  21939. fehmedialarabic: 0xFED4,
  21940. feicoptic: 0x03E5,
  21941. female: 0x2640,
  21942. ff: 0xFB00,
  21943. ffi: 0xFB03,
  21944. ffl: 0xFB04,
  21945. fi: 0xFB01,
  21946. fifteencircle: 0x246E,
  21947. fifteenparen: 0x2482,
  21948. fifteenperiod: 0x2496,
  21949. figuredash: 0x2012,
  21950. filledbox: 0x25A0,
  21951. filledrect: 0x25AC,
  21952. finalkaf: 0x05DA,
  21953. finalkafdagesh: 0xFB3A,
  21954. finalkafdageshhebrew: 0xFB3A,
  21955. finalkafhebrew: 0x05DA,
  21956. finalmem: 0x05DD,
  21957. finalmemhebrew: 0x05DD,
  21958. finalnun: 0x05DF,
  21959. finalnunhebrew: 0x05DF,
  21960. finalpe: 0x05E3,
  21961. finalpehebrew: 0x05E3,
  21962. finaltsadi: 0x05E5,
  21963. finaltsadihebrew: 0x05E5,
  21964. firsttonechinese: 0x02C9,
  21965. fisheye: 0x25C9,
  21966. fitacyrillic: 0x0473,
  21967. five: 0x0035,
  21968. fivearabic: 0x0665,
  21969. fivebengali: 0x09EB,
  21970. fivecircle: 0x2464,
  21971. fivecircleinversesansserif: 0x278E,
  21972. fivedeva: 0x096B,
  21973. fiveeighths: 0x215D,
  21974. fivegujarati: 0x0AEB,
  21975. fivegurmukhi: 0x0A6B,
  21976. fivehackarabic: 0x0665,
  21977. fivehangzhou: 0x3025,
  21978. fiveideographicparen: 0x3224,
  21979. fiveinferior: 0x2085,
  21980. fivemonospace: 0xFF15,
  21981. fiveoldstyle: 0xF735,
  21982. fiveparen: 0x2478,
  21983. fiveperiod: 0x248C,
  21984. fivepersian: 0x06F5,
  21985. fiveroman: 0x2174,
  21986. fivesuperior: 0x2075,
  21987. fivethai: 0x0E55,
  21988. fl: 0xFB02,
  21989. florin: 0x0192,
  21990. fmonospace: 0xFF46,
  21991. fmsquare: 0x3399,
  21992. fofanthai: 0x0E1F,
  21993. fofathai: 0x0E1D,
  21994. fongmanthai: 0x0E4F,
  21995. forall: 0x2200,
  21996. four: 0x0034,
  21997. fourarabic: 0x0664,
  21998. fourbengali: 0x09EA,
  21999. fourcircle: 0x2463,
  22000. fourcircleinversesansserif: 0x278D,
  22001. fourdeva: 0x096A,
  22002. fourgujarati: 0x0AEA,
  22003. fourgurmukhi: 0x0A6A,
  22004. fourhackarabic: 0x0664,
  22005. fourhangzhou: 0x3024,
  22006. fourideographicparen: 0x3223,
  22007. fourinferior: 0x2084,
  22008. fourmonospace: 0xFF14,
  22009. fournumeratorbengali: 0x09F7,
  22010. fouroldstyle: 0xF734,
  22011. fourparen: 0x2477,
  22012. fourperiod: 0x248B,
  22013. fourpersian: 0x06F4,
  22014. fourroman: 0x2173,
  22015. foursuperior: 0x2074,
  22016. fourteencircle: 0x246D,
  22017. fourteenparen: 0x2481,
  22018. fourteenperiod: 0x2495,
  22019. fourthai: 0x0E54,
  22020. fourthtonechinese: 0x02CB,
  22021. fparen: 0x24A1,
  22022. fraction: 0x2044,
  22023. franc: 0x20A3,
  22024. g: 0x0067,
  22025. gabengali: 0x0997,
  22026. gacute: 0x01F5,
  22027. gadeva: 0x0917,
  22028. gafarabic: 0x06AF,
  22029. gaffinalarabic: 0xFB93,
  22030. gafinitialarabic: 0xFB94,
  22031. gafmedialarabic: 0xFB95,
  22032. gagujarati: 0x0A97,
  22033. gagurmukhi: 0x0A17,
  22034. gahiragana: 0x304C,
  22035. gakatakana: 0x30AC,
  22036. gamma: 0x03B3,
  22037. gammalatinsmall: 0x0263,
  22038. gammasuperior: 0x02E0,
  22039. gangiacoptic: 0x03EB,
  22040. gbopomofo: 0x310D,
  22041. gbreve: 0x011F,
  22042. gcaron: 0x01E7,
  22043. gcedilla: 0x0123,
  22044. gcircle: 0x24D6,
  22045. gcircumflex: 0x011D,
  22046. gcommaaccent: 0x0123,
  22047. gdot: 0x0121,
  22048. gdotaccent: 0x0121,
  22049. gecyrillic: 0x0433,
  22050. gehiragana: 0x3052,
  22051. gekatakana: 0x30B2,
  22052. geometricallyequal: 0x2251,
  22053. gereshaccenthebrew: 0x059C,
  22054. gereshhebrew: 0x05F3,
  22055. gereshmuqdamhebrew: 0x059D,
  22056. germandbls: 0x00DF,
  22057. gershayimaccenthebrew: 0x059E,
  22058. gershayimhebrew: 0x05F4,
  22059. getamark: 0x3013,
  22060. ghabengali: 0x0998,
  22061. ghadarmenian: 0x0572,
  22062. ghadeva: 0x0918,
  22063. ghagujarati: 0x0A98,
  22064. ghagurmukhi: 0x0A18,
  22065. ghainarabic: 0x063A,
  22066. ghainfinalarabic: 0xFECE,
  22067. ghaininitialarabic: 0xFECF,
  22068. ghainmedialarabic: 0xFED0,
  22069. ghemiddlehookcyrillic: 0x0495,
  22070. ghestrokecyrillic: 0x0493,
  22071. gheupturncyrillic: 0x0491,
  22072. ghhadeva: 0x095A,
  22073. ghhagurmukhi: 0x0A5A,
  22074. ghook: 0x0260,
  22075. ghzsquare: 0x3393,
  22076. gihiragana: 0x304E,
  22077. gikatakana: 0x30AE,
  22078. gimarmenian: 0x0563,
  22079. gimel: 0x05D2,
  22080. gimeldagesh: 0xFB32,
  22081. gimeldageshhebrew: 0xFB32,
  22082. gimelhebrew: 0x05D2,
  22083. gjecyrillic: 0x0453,
  22084. glottalinvertedstroke: 0x01BE,
  22085. glottalstop: 0x0294,
  22086. glottalstopinverted: 0x0296,
  22087. glottalstopmod: 0x02C0,
  22088. glottalstopreversed: 0x0295,
  22089. glottalstopreversedmod: 0x02C1,
  22090. glottalstopreversedsuperior: 0x02E4,
  22091. glottalstopstroke: 0x02A1,
  22092. glottalstopstrokereversed: 0x02A2,
  22093. gmacron: 0x1E21,
  22094. gmonospace: 0xFF47,
  22095. gohiragana: 0x3054,
  22096. gokatakana: 0x30B4,
  22097. gparen: 0x24A2,
  22098. gpasquare: 0x33AC,
  22099. gradient: 0x2207,
  22100. grave: 0x0060,
  22101. gravebelowcmb: 0x0316,
  22102. gravecmb: 0x0300,
  22103. gravecomb: 0x0300,
  22104. gravedeva: 0x0953,
  22105. gravelowmod: 0x02CE,
  22106. gravemonospace: 0xFF40,
  22107. gravetonecmb: 0x0340,
  22108. greater: 0x003E,
  22109. greaterequal: 0x2265,
  22110. greaterequalorless: 0x22DB,
  22111. greatermonospace: 0xFF1E,
  22112. greaterorequivalent: 0x2273,
  22113. greaterorless: 0x2277,
  22114. greateroverequal: 0x2267,
  22115. greatersmall: 0xFE65,
  22116. gscript: 0x0261,
  22117. gstroke: 0x01E5,
  22118. guhiragana: 0x3050,
  22119. guillemotleft: 0x00AB,
  22120. guillemotright: 0x00BB,
  22121. guilsinglleft: 0x2039,
  22122. guilsinglright: 0x203A,
  22123. gukatakana: 0x30B0,
  22124. guramusquare: 0x3318,
  22125. gysquare: 0x33C9,
  22126. h: 0x0068,
  22127. haabkhasiancyrillic: 0x04A9,
  22128. haaltonearabic: 0x06C1,
  22129. habengali: 0x09B9,
  22130. hadescendercyrillic: 0x04B3,
  22131. hadeva: 0x0939,
  22132. hagujarati: 0x0AB9,
  22133. hagurmukhi: 0x0A39,
  22134. haharabic: 0x062D,
  22135. hahfinalarabic: 0xFEA2,
  22136. hahinitialarabic: 0xFEA3,
  22137. hahiragana: 0x306F,
  22138. hahmedialarabic: 0xFEA4,
  22139. haitusquare: 0x332A,
  22140. hakatakana: 0x30CF,
  22141. hakatakanahalfwidth: 0xFF8A,
  22142. halantgurmukhi: 0x0A4D,
  22143. hamzaarabic: 0x0621,
  22144. hamzalowarabic: 0x0621,
  22145. hangulfiller: 0x3164,
  22146. hardsigncyrillic: 0x044A,
  22147. harpoonleftbarbup: 0x21BC,
  22148. harpoonrightbarbup: 0x21C0,
  22149. hasquare: 0x33CA,
  22150. hatafpatah: 0x05B2,
  22151. hatafpatah16: 0x05B2,
  22152. hatafpatah23: 0x05B2,
  22153. hatafpatah2f: 0x05B2,
  22154. hatafpatahhebrew: 0x05B2,
  22155. hatafpatahnarrowhebrew: 0x05B2,
  22156. hatafpatahquarterhebrew: 0x05B2,
  22157. hatafpatahwidehebrew: 0x05B2,
  22158. hatafqamats: 0x05B3,
  22159. hatafqamats1b: 0x05B3,
  22160. hatafqamats28: 0x05B3,
  22161. hatafqamats34: 0x05B3,
  22162. hatafqamatshebrew: 0x05B3,
  22163. hatafqamatsnarrowhebrew: 0x05B3,
  22164. hatafqamatsquarterhebrew: 0x05B3,
  22165. hatafqamatswidehebrew: 0x05B3,
  22166. hatafsegol: 0x05B1,
  22167. hatafsegol17: 0x05B1,
  22168. hatafsegol24: 0x05B1,
  22169. hatafsegol30: 0x05B1,
  22170. hatafsegolhebrew: 0x05B1,
  22171. hatafsegolnarrowhebrew: 0x05B1,
  22172. hatafsegolquarterhebrew: 0x05B1,
  22173. hatafsegolwidehebrew: 0x05B1,
  22174. hbar: 0x0127,
  22175. hbopomofo: 0x310F,
  22176. hbrevebelow: 0x1E2B,
  22177. hcedilla: 0x1E29,
  22178. hcircle: 0x24D7,
  22179. hcircumflex: 0x0125,
  22180. hdieresis: 0x1E27,
  22181. hdotaccent: 0x1E23,
  22182. hdotbelow: 0x1E25,
  22183. he: 0x05D4,
  22184. heart: 0x2665,
  22185. heartsuitblack: 0x2665,
  22186. heartsuitwhite: 0x2661,
  22187. hedagesh: 0xFB34,
  22188. hedageshhebrew: 0xFB34,
  22189. hehaltonearabic: 0x06C1,
  22190. heharabic: 0x0647,
  22191. hehebrew: 0x05D4,
  22192. hehfinalaltonearabic: 0xFBA7,
  22193. hehfinalalttwoarabic: 0xFEEA,
  22194. hehfinalarabic: 0xFEEA,
  22195. hehhamzaabovefinalarabic: 0xFBA5,
  22196. hehhamzaaboveisolatedarabic: 0xFBA4,
  22197. hehinitialaltonearabic: 0xFBA8,
  22198. hehinitialarabic: 0xFEEB,
  22199. hehiragana: 0x3078,
  22200. hehmedialaltonearabic: 0xFBA9,
  22201. hehmedialarabic: 0xFEEC,
  22202. heiseierasquare: 0x337B,
  22203. hekatakana: 0x30D8,
  22204. hekatakanahalfwidth: 0xFF8D,
  22205. hekutaarusquare: 0x3336,
  22206. henghook: 0x0267,
  22207. herutusquare: 0x3339,
  22208. het: 0x05D7,
  22209. hethebrew: 0x05D7,
  22210. hhook: 0x0266,
  22211. hhooksuperior: 0x02B1,
  22212. hieuhacirclekorean: 0x327B,
  22213. hieuhaparenkorean: 0x321B,
  22214. hieuhcirclekorean: 0x326D,
  22215. hieuhkorean: 0x314E,
  22216. hieuhparenkorean: 0x320D,
  22217. hihiragana: 0x3072,
  22218. hikatakana: 0x30D2,
  22219. hikatakanahalfwidth: 0xFF8B,
  22220. hiriq: 0x05B4,
  22221. hiriq14: 0x05B4,
  22222. hiriq21: 0x05B4,
  22223. hiriq2d: 0x05B4,
  22224. hiriqhebrew: 0x05B4,
  22225. hiriqnarrowhebrew: 0x05B4,
  22226. hiriqquarterhebrew: 0x05B4,
  22227. hiriqwidehebrew: 0x05B4,
  22228. hlinebelow: 0x1E96,
  22229. hmonospace: 0xFF48,
  22230. hoarmenian: 0x0570,
  22231. hohipthai: 0x0E2B,
  22232. hohiragana: 0x307B,
  22233. hokatakana: 0x30DB,
  22234. hokatakanahalfwidth: 0xFF8E,
  22235. holam: 0x05B9,
  22236. holam19: 0x05B9,
  22237. holam26: 0x05B9,
  22238. holam32: 0x05B9,
  22239. holamhebrew: 0x05B9,
  22240. holamnarrowhebrew: 0x05B9,
  22241. holamquarterhebrew: 0x05B9,
  22242. holamwidehebrew: 0x05B9,
  22243. honokhukthai: 0x0E2E,
  22244. hookabovecomb: 0x0309,
  22245. hookcmb: 0x0309,
  22246. hookpalatalizedbelowcmb: 0x0321,
  22247. hookretroflexbelowcmb: 0x0322,
  22248. hoonsquare: 0x3342,
  22249. horicoptic: 0x03E9,
  22250. horizontalbar: 0x2015,
  22251. horncmb: 0x031B,
  22252. hotsprings: 0x2668,
  22253. house: 0x2302,
  22254. hparen: 0x24A3,
  22255. hsuperior: 0x02B0,
  22256. hturned: 0x0265,
  22257. huhiragana: 0x3075,
  22258. huiitosquare: 0x3333,
  22259. hukatakana: 0x30D5,
  22260. hukatakanahalfwidth: 0xFF8C,
  22261. hungarumlaut: 0x02DD,
  22262. hungarumlautcmb: 0x030B,
  22263. hv: 0x0195,
  22264. hyphen: 0x002D,
  22265. hypheninferior: 0xF6E5,
  22266. hyphenmonospace: 0xFF0D,
  22267. hyphensmall: 0xFE63,
  22268. hyphensuperior: 0xF6E6,
  22269. hyphentwo: 0x2010,
  22270. i: 0x0069,
  22271. iacute: 0x00ED,
  22272. iacyrillic: 0x044F,
  22273. ibengali: 0x0987,
  22274. ibopomofo: 0x3127,
  22275. ibreve: 0x012D,
  22276. icaron: 0x01D0,
  22277. icircle: 0x24D8,
  22278. icircumflex: 0x00EE,
  22279. icyrillic: 0x0456,
  22280. idblgrave: 0x0209,
  22281. ideographearthcircle: 0x328F,
  22282. ideographfirecircle: 0x328B,
  22283. ideographicallianceparen: 0x323F,
  22284. ideographiccallparen: 0x323A,
  22285. ideographiccentrecircle: 0x32A5,
  22286. ideographicclose: 0x3006,
  22287. ideographiccomma: 0x3001,
  22288. ideographiccommaleft: 0xFF64,
  22289. ideographiccongratulationparen: 0x3237,
  22290. ideographiccorrectcircle: 0x32A3,
  22291. ideographicearthparen: 0x322F,
  22292. ideographicenterpriseparen: 0x323D,
  22293. ideographicexcellentcircle: 0x329D,
  22294. ideographicfestivalparen: 0x3240,
  22295. ideographicfinancialcircle: 0x3296,
  22296. ideographicfinancialparen: 0x3236,
  22297. ideographicfireparen: 0x322B,
  22298. ideographichaveparen: 0x3232,
  22299. ideographichighcircle: 0x32A4,
  22300. ideographiciterationmark: 0x3005,
  22301. ideographiclaborcircle: 0x3298,
  22302. ideographiclaborparen: 0x3238,
  22303. ideographicleftcircle: 0x32A7,
  22304. ideographiclowcircle: 0x32A6,
  22305. ideographicmedicinecircle: 0x32A9,
  22306. ideographicmetalparen: 0x322E,
  22307. ideographicmoonparen: 0x322A,
  22308. ideographicnameparen: 0x3234,
  22309. ideographicperiod: 0x3002,
  22310. ideographicprintcircle: 0x329E,
  22311. ideographicreachparen: 0x3243,
  22312. ideographicrepresentparen: 0x3239,
  22313. ideographicresourceparen: 0x323E,
  22314. ideographicrightcircle: 0x32A8,
  22315. ideographicsecretcircle: 0x3299,
  22316. ideographicselfparen: 0x3242,
  22317. ideographicsocietyparen: 0x3233,
  22318. ideographicspace: 0x3000,
  22319. ideographicspecialparen: 0x3235,
  22320. ideographicstockparen: 0x3231,
  22321. ideographicstudyparen: 0x323B,
  22322. ideographicsunparen: 0x3230,
  22323. ideographicsuperviseparen: 0x323C,
  22324. ideographicwaterparen: 0x322C,
  22325. ideographicwoodparen: 0x322D,
  22326. ideographiczero: 0x3007,
  22327. ideographmetalcircle: 0x328E,
  22328. ideographmooncircle: 0x328A,
  22329. ideographnamecircle: 0x3294,
  22330. ideographsuncircle: 0x3290,
  22331. ideographwatercircle: 0x328C,
  22332. ideographwoodcircle: 0x328D,
  22333. ideva: 0x0907,
  22334. idieresis: 0x00EF,
  22335. idieresisacute: 0x1E2F,
  22336. idieresiscyrillic: 0x04E5,
  22337. idotbelow: 0x1ECB,
  22338. iebrevecyrillic: 0x04D7,
  22339. iecyrillic: 0x0435,
  22340. ieungacirclekorean: 0x3275,
  22341. ieungaparenkorean: 0x3215,
  22342. ieungcirclekorean: 0x3267,
  22343. ieungkorean: 0x3147,
  22344. ieungparenkorean: 0x3207,
  22345. igrave: 0x00EC,
  22346. igujarati: 0x0A87,
  22347. igurmukhi: 0x0A07,
  22348. ihiragana: 0x3044,
  22349. ihookabove: 0x1EC9,
  22350. iibengali: 0x0988,
  22351. iicyrillic: 0x0438,
  22352. iideva: 0x0908,
  22353. iigujarati: 0x0A88,
  22354. iigurmukhi: 0x0A08,
  22355. iimatragurmukhi: 0x0A40,
  22356. iinvertedbreve: 0x020B,
  22357. iishortcyrillic: 0x0439,
  22358. iivowelsignbengali: 0x09C0,
  22359. iivowelsigndeva: 0x0940,
  22360. iivowelsigngujarati: 0x0AC0,
  22361. ij: 0x0133,
  22362. ikatakana: 0x30A4,
  22363. ikatakanahalfwidth: 0xFF72,
  22364. ikorean: 0x3163,
  22365. ilde: 0x02DC,
  22366. iluyhebrew: 0x05AC,
  22367. imacron: 0x012B,
  22368. imacroncyrillic: 0x04E3,
  22369. imageorapproximatelyequal: 0x2253,
  22370. imatragurmukhi: 0x0A3F,
  22371. imonospace: 0xFF49,
  22372. increment: 0x2206,
  22373. infinity: 0x221E,
  22374. iniarmenian: 0x056B,
  22375. integral: 0x222B,
  22376. integralbottom: 0x2321,
  22377. integralbt: 0x2321,
  22378. integralex: 0xF8F5,
  22379. integraltop: 0x2320,
  22380. integraltp: 0x2320,
  22381. intersection: 0x2229,
  22382. intisquare: 0x3305,
  22383. invbullet: 0x25D8,
  22384. invcircle: 0x25D9,
  22385. invsmileface: 0x263B,
  22386. iocyrillic: 0x0451,
  22387. iogonek: 0x012F,
  22388. iota: 0x03B9,
  22389. iotadieresis: 0x03CA,
  22390. iotadieresistonos: 0x0390,
  22391. iotalatin: 0x0269,
  22392. iotatonos: 0x03AF,
  22393. iparen: 0x24A4,
  22394. irigurmukhi: 0x0A72,
  22395. ismallhiragana: 0x3043,
  22396. ismallkatakana: 0x30A3,
  22397. ismallkatakanahalfwidth: 0xFF68,
  22398. issharbengali: 0x09FA,
  22399. istroke: 0x0268,
  22400. isuperior: 0xF6ED,
  22401. iterationhiragana: 0x309D,
  22402. iterationkatakana: 0x30FD,
  22403. itilde: 0x0129,
  22404. itildebelow: 0x1E2D,
  22405. iubopomofo: 0x3129,
  22406. iucyrillic: 0x044E,
  22407. ivowelsignbengali: 0x09BF,
  22408. ivowelsigndeva: 0x093F,
  22409. ivowelsigngujarati: 0x0ABF,
  22410. izhitsacyrillic: 0x0475,
  22411. izhitsadblgravecyrillic: 0x0477,
  22412. j: 0x006A,
  22413. jaarmenian: 0x0571,
  22414. jabengali: 0x099C,
  22415. jadeva: 0x091C,
  22416. jagujarati: 0x0A9C,
  22417. jagurmukhi: 0x0A1C,
  22418. jbopomofo: 0x3110,
  22419. jcaron: 0x01F0,
  22420. jcircle: 0x24D9,
  22421. jcircumflex: 0x0135,
  22422. jcrossedtail: 0x029D,
  22423. jdotlessstroke: 0x025F,
  22424. jecyrillic: 0x0458,
  22425. jeemarabic: 0x062C,
  22426. jeemfinalarabic: 0xFE9E,
  22427. jeeminitialarabic: 0xFE9F,
  22428. jeemmedialarabic: 0xFEA0,
  22429. jeharabic: 0x0698,
  22430. jehfinalarabic: 0xFB8B,
  22431. jhabengali: 0x099D,
  22432. jhadeva: 0x091D,
  22433. jhagujarati: 0x0A9D,
  22434. jhagurmukhi: 0x0A1D,
  22435. jheharmenian: 0x057B,
  22436. jis: 0x3004,
  22437. jmonospace: 0xFF4A,
  22438. jparen: 0x24A5,
  22439. jsuperior: 0x02B2,
  22440. k: 0x006B,
  22441. kabashkircyrillic: 0x04A1,
  22442. kabengali: 0x0995,
  22443. kacute: 0x1E31,
  22444. kacyrillic: 0x043A,
  22445. kadescendercyrillic: 0x049B,
  22446. kadeva: 0x0915,
  22447. kaf: 0x05DB,
  22448. kafarabic: 0x0643,
  22449. kafdagesh: 0xFB3B,
  22450. kafdageshhebrew: 0xFB3B,
  22451. kaffinalarabic: 0xFEDA,
  22452. kafhebrew: 0x05DB,
  22453. kafinitialarabic: 0xFEDB,
  22454. kafmedialarabic: 0xFEDC,
  22455. kafrafehebrew: 0xFB4D,
  22456. kagujarati: 0x0A95,
  22457. kagurmukhi: 0x0A15,
  22458. kahiragana: 0x304B,
  22459. kahookcyrillic: 0x04C4,
  22460. kakatakana: 0x30AB,
  22461. kakatakanahalfwidth: 0xFF76,
  22462. kappa: 0x03BA,
  22463. kappasymbolgreek: 0x03F0,
  22464. kapyeounmieumkorean: 0x3171,
  22465. kapyeounphieuphkorean: 0x3184,
  22466. kapyeounpieupkorean: 0x3178,
  22467. kapyeounssangpieupkorean: 0x3179,
  22468. karoriisquare: 0x330D,
  22469. kashidaautoarabic: 0x0640,
  22470. kashidaautonosidebearingarabic: 0x0640,
  22471. kasmallkatakana: 0x30F5,
  22472. kasquare: 0x3384,
  22473. kasraarabic: 0x0650,
  22474. kasratanarabic: 0x064D,
  22475. kastrokecyrillic: 0x049F,
  22476. katahiraprolongmarkhalfwidth: 0xFF70,
  22477. kaverticalstrokecyrillic: 0x049D,
  22478. kbopomofo: 0x310E,
  22479. kcalsquare: 0x3389,
  22480. kcaron: 0x01E9,
  22481. kcedilla: 0x0137,
  22482. kcircle: 0x24DA,
  22483. kcommaaccent: 0x0137,
  22484. kdotbelow: 0x1E33,
  22485. keharmenian: 0x0584,
  22486. kehiragana: 0x3051,
  22487. kekatakana: 0x30B1,
  22488. kekatakanahalfwidth: 0xFF79,
  22489. kenarmenian: 0x056F,
  22490. kesmallkatakana: 0x30F6,
  22491. kgreenlandic: 0x0138,
  22492. khabengali: 0x0996,
  22493. khacyrillic: 0x0445,
  22494. khadeva: 0x0916,
  22495. khagujarati: 0x0A96,
  22496. khagurmukhi: 0x0A16,
  22497. khaharabic: 0x062E,
  22498. khahfinalarabic: 0xFEA6,
  22499. khahinitialarabic: 0xFEA7,
  22500. khahmedialarabic: 0xFEA8,
  22501. kheicoptic: 0x03E7,
  22502. khhadeva: 0x0959,
  22503. khhagurmukhi: 0x0A59,
  22504. khieukhacirclekorean: 0x3278,
  22505. khieukhaparenkorean: 0x3218,
  22506. khieukhcirclekorean: 0x326A,
  22507. khieukhkorean: 0x314B,
  22508. khieukhparenkorean: 0x320A,
  22509. khokhaithai: 0x0E02,
  22510. khokhonthai: 0x0E05,
  22511. khokhuatthai: 0x0E03,
  22512. khokhwaithai: 0x0E04,
  22513. khomutthai: 0x0E5B,
  22514. khook: 0x0199,
  22515. khorakhangthai: 0x0E06,
  22516. khzsquare: 0x3391,
  22517. kihiragana: 0x304D,
  22518. kikatakana: 0x30AD,
  22519. kikatakanahalfwidth: 0xFF77,
  22520. kiroguramusquare: 0x3315,
  22521. kiromeetorusquare: 0x3316,
  22522. kirosquare: 0x3314,
  22523. kiyeokacirclekorean: 0x326E,
  22524. kiyeokaparenkorean: 0x320E,
  22525. kiyeokcirclekorean: 0x3260,
  22526. kiyeokkorean: 0x3131,
  22527. kiyeokparenkorean: 0x3200,
  22528. kiyeoksioskorean: 0x3133,
  22529. kjecyrillic: 0x045C,
  22530. klinebelow: 0x1E35,
  22531. klsquare: 0x3398,
  22532. kmcubedsquare: 0x33A6,
  22533. kmonospace: 0xFF4B,
  22534. kmsquaredsquare: 0x33A2,
  22535. kohiragana: 0x3053,
  22536. kohmsquare: 0x33C0,
  22537. kokaithai: 0x0E01,
  22538. kokatakana: 0x30B3,
  22539. kokatakanahalfwidth: 0xFF7A,
  22540. kooposquare: 0x331E,
  22541. koppacyrillic: 0x0481,
  22542. koreanstandardsymbol: 0x327F,
  22543. koroniscmb: 0x0343,
  22544. kparen: 0x24A6,
  22545. kpasquare: 0x33AA,
  22546. ksicyrillic: 0x046F,
  22547. ktsquare: 0x33CF,
  22548. kturned: 0x029E,
  22549. kuhiragana: 0x304F,
  22550. kukatakana: 0x30AF,
  22551. kukatakanahalfwidth: 0xFF78,
  22552. kvsquare: 0x33B8,
  22553. kwsquare: 0x33BE,
  22554. l: 0x006C,
  22555. labengali: 0x09B2,
  22556. lacute: 0x013A,
  22557. ladeva: 0x0932,
  22558. lagujarati: 0x0AB2,
  22559. lagurmukhi: 0x0A32,
  22560. lakkhangyaothai: 0x0E45,
  22561. lamaleffinalarabic: 0xFEFC,
  22562. lamalefhamzaabovefinalarabic: 0xFEF8,
  22563. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22564. lamalefhamzabelowfinalarabic: 0xFEFA,
  22565. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22566. lamalefisolatedarabic: 0xFEFB,
  22567. lamalefmaddaabovefinalarabic: 0xFEF6,
  22568. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22569. lamarabic: 0x0644,
  22570. lambda: 0x03BB,
  22571. lambdastroke: 0x019B,
  22572. lamed: 0x05DC,
  22573. lameddagesh: 0xFB3C,
  22574. lameddageshhebrew: 0xFB3C,
  22575. lamedhebrew: 0x05DC,
  22576. lamfinalarabic: 0xFEDE,
  22577. lamhahinitialarabic: 0xFCCA,
  22578. laminitialarabic: 0xFEDF,
  22579. lamjeeminitialarabic: 0xFCC9,
  22580. lamkhahinitialarabic: 0xFCCB,
  22581. lamlamhehisolatedarabic: 0xFDF2,
  22582. lammedialarabic: 0xFEE0,
  22583. lammeemhahinitialarabic: 0xFD88,
  22584. lammeeminitialarabic: 0xFCCC,
  22585. largecircle: 0x25EF,
  22586. lbar: 0x019A,
  22587. lbelt: 0x026C,
  22588. lbopomofo: 0x310C,
  22589. lcaron: 0x013E,
  22590. lcedilla: 0x013C,
  22591. lcircle: 0x24DB,
  22592. lcircumflexbelow: 0x1E3D,
  22593. lcommaaccent: 0x013C,
  22594. ldot: 0x0140,
  22595. ldotaccent: 0x0140,
  22596. ldotbelow: 0x1E37,
  22597. ldotbelowmacron: 0x1E39,
  22598. leftangleabovecmb: 0x031A,
  22599. lefttackbelowcmb: 0x0318,
  22600. less: 0x003C,
  22601. lessequal: 0x2264,
  22602. lessequalorgreater: 0x22DA,
  22603. lessmonospace: 0xFF1C,
  22604. lessorequivalent: 0x2272,
  22605. lessorgreater: 0x2276,
  22606. lessoverequal: 0x2266,
  22607. lesssmall: 0xFE64,
  22608. lezh: 0x026E,
  22609. lfblock: 0x258C,
  22610. lhookretroflex: 0x026D,
  22611. lira: 0x20A4,
  22612. liwnarmenian: 0x056C,
  22613. lj: 0x01C9,
  22614. ljecyrillic: 0x0459,
  22615. ll: 0xF6C0,
  22616. lladeva: 0x0933,
  22617. llagujarati: 0x0AB3,
  22618. llinebelow: 0x1E3B,
  22619. llladeva: 0x0934,
  22620. llvocalicbengali: 0x09E1,
  22621. llvocalicdeva: 0x0961,
  22622. llvocalicvowelsignbengali: 0x09E3,
  22623. llvocalicvowelsigndeva: 0x0963,
  22624. lmiddletilde: 0x026B,
  22625. lmonospace: 0xFF4C,
  22626. lmsquare: 0x33D0,
  22627. lochulathai: 0x0E2C,
  22628. logicaland: 0x2227,
  22629. logicalnot: 0x00AC,
  22630. logicalnotreversed: 0x2310,
  22631. logicalor: 0x2228,
  22632. lolingthai: 0x0E25,
  22633. longs: 0x017F,
  22634. lowlinecenterline: 0xFE4E,
  22635. lowlinecmb: 0x0332,
  22636. lowlinedashed: 0xFE4D,
  22637. lozenge: 0x25CA,
  22638. lparen: 0x24A7,
  22639. lslash: 0x0142,
  22640. lsquare: 0x2113,
  22641. lsuperior: 0xF6EE,
  22642. ltshade: 0x2591,
  22643. luthai: 0x0E26,
  22644. lvocalicbengali: 0x098C,
  22645. lvocalicdeva: 0x090C,
  22646. lvocalicvowelsignbengali: 0x09E2,
  22647. lvocalicvowelsigndeva: 0x0962,
  22648. lxsquare: 0x33D3,
  22649. m: 0x006D,
  22650. mabengali: 0x09AE,
  22651. macron: 0x00AF,
  22652. macronbelowcmb: 0x0331,
  22653. macroncmb: 0x0304,
  22654. macronlowmod: 0x02CD,
  22655. macronmonospace: 0xFFE3,
  22656. macute: 0x1E3F,
  22657. madeva: 0x092E,
  22658. magujarati: 0x0AAE,
  22659. magurmukhi: 0x0A2E,
  22660. mahapakhhebrew: 0x05A4,
  22661. mahapakhlefthebrew: 0x05A4,
  22662. mahiragana: 0x307E,
  22663. maichattawalowleftthai: 0xF895,
  22664. maichattawalowrightthai: 0xF894,
  22665. maichattawathai: 0x0E4B,
  22666. maichattawaupperleftthai: 0xF893,
  22667. maieklowleftthai: 0xF88C,
  22668. maieklowrightthai: 0xF88B,
  22669. maiekthai: 0x0E48,
  22670. maiekupperleftthai: 0xF88A,
  22671. maihanakatleftthai: 0xF884,
  22672. maihanakatthai: 0x0E31,
  22673. maitaikhuleftthai: 0xF889,
  22674. maitaikhuthai: 0x0E47,
  22675. maitholowleftthai: 0xF88F,
  22676. maitholowrightthai: 0xF88E,
  22677. maithothai: 0x0E49,
  22678. maithoupperleftthai: 0xF88D,
  22679. maitrilowleftthai: 0xF892,
  22680. maitrilowrightthai: 0xF891,
  22681. maitrithai: 0x0E4A,
  22682. maitriupperleftthai: 0xF890,
  22683. maiyamokthai: 0x0E46,
  22684. makatakana: 0x30DE,
  22685. makatakanahalfwidth: 0xFF8F,
  22686. male: 0x2642,
  22687. mansyonsquare: 0x3347,
  22688. maqafhebrew: 0x05BE,
  22689. mars: 0x2642,
  22690. masoracirclehebrew: 0x05AF,
  22691. masquare: 0x3383,
  22692. mbopomofo: 0x3107,
  22693. mbsquare: 0x33D4,
  22694. mcircle: 0x24DC,
  22695. mcubedsquare: 0x33A5,
  22696. mdotaccent: 0x1E41,
  22697. mdotbelow: 0x1E43,
  22698. meemarabic: 0x0645,
  22699. meemfinalarabic: 0xFEE2,
  22700. meeminitialarabic: 0xFEE3,
  22701. meemmedialarabic: 0xFEE4,
  22702. meemmeeminitialarabic: 0xFCD1,
  22703. meemmeemisolatedarabic: 0xFC48,
  22704. meetorusquare: 0x334D,
  22705. mehiragana: 0x3081,
  22706. meizierasquare: 0x337E,
  22707. mekatakana: 0x30E1,
  22708. mekatakanahalfwidth: 0xFF92,
  22709. mem: 0x05DE,
  22710. memdagesh: 0xFB3E,
  22711. memdageshhebrew: 0xFB3E,
  22712. memhebrew: 0x05DE,
  22713. menarmenian: 0x0574,
  22714. merkhahebrew: 0x05A5,
  22715. merkhakefulahebrew: 0x05A6,
  22716. merkhakefulalefthebrew: 0x05A6,
  22717. merkhalefthebrew: 0x05A5,
  22718. mhook: 0x0271,
  22719. mhzsquare: 0x3392,
  22720. middledotkatakanahalfwidth: 0xFF65,
  22721. middot: 0x00B7,
  22722. mieumacirclekorean: 0x3272,
  22723. mieumaparenkorean: 0x3212,
  22724. mieumcirclekorean: 0x3264,
  22725. mieumkorean: 0x3141,
  22726. mieumpansioskorean: 0x3170,
  22727. mieumparenkorean: 0x3204,
  22728. mieumpieupkorean: 0x316E,
  22729. mieumsioskorean: 0x316F,
  22730. mihiragana: 0x307F,
  22731. mikatakana: 0x30DF,
  22732. mikatakanahalfwidth: 0xFF90,
  22733. minus: 0x2212,
  22734. minusbelowcmb: 0x0320,
  22735. minuscircle: 0x2296,
  22736. minusmod: 0x02D7,
  22737. minusplus: 0x2213,
  22738. minute: 0x2032,
  22739. miribaarusquare: 0x334A,
  22740. mirisquare: 0x3349,
  22741. mlonglegturned: 0x0270,
  22742. mlsquare: 0x3396,
  22743. mmcubedsquare: 0x33A3,
  22744. mmonospace: 0xFF4D,
  22745. mmsquaredsquare: 0x339F,
  22746. mohiragana: 0x3082,
  22747. mohmsquare: 0x33C1,
  22748. mokatakana: 0x30E2,
  22749. mokatakanahalfwidth: 0xFF93,
  22750. molsquare: 0x33D6,
  22751. momathai: 0x0E21,
  22752. moverssquare: 0x33A7,
  22753. moverssquaredsquare: 0x33A8,
  22754. mparen: 0x24A8,
  22755. mpasquare: 0x33AB,
  22756. mssquare: 0x33B3,
  22757. msuperior: 0xF6EF,
  22758. mturned: 0x026F,
  22759. mu: 0x00B5,
  22760. mu1: 0x00B5,
  22761. muasquare: 0x3382,
  22762. muchgreater: 0x226B,
  22763. muchless: 0x226A,
  22764. mufsquare: 0x338C,
  22765. mugreek: 0x03BC,
  22766. mugsquare: 0x338D,
  22767. muhiragana: 0x3080,
  22768. mukatakana: 0x30E0,
  22769. mukatakanahalfwidth: 0xFF91,
  22770. mulsquare: 0x3395,
  22771. multiply: 0x00D7,
  22772. mumsquare: 0x339B,
  22773. munahhebrew: 0x05A3,
  22774. munahlefthebrew: 0x05A3,
  22775. musicalnote: 0x266A,
  22776. musicalnotedbl: 0x266B,
  22777. musicflatsign: 0x266D,
  22778. musicsharpsign: 0x266F,
  22779. mussquare: 0x33B2,
  22780. muvsquare: 0x33B6,
  22781. muwsquare: 0x33BC,
  22782. mvmegasquare: 0x33B9,
  22783. mvsquare: 0x33B7,
  22784. mwmegasquare: 0x33BF,
  22785. mwsquare: 0x33BD,
  22786. n: 0x006E,
  22787. nabengali: 0x09A8,
  22788. nabla: 0x2207,
  22789. nacute: 0x0144,
  22790. nadeva: 0x0928,
  22791. nagujarati: 0x0AA8,
  22792. nagurmukhi: 0x0A28,
  22793. nahiragana: 0x306A,
  22794. nakatakana: 0x30CA,
  22795. nakatakanahalfwidth: 0xFF85,
  22796. napostrophe: 0x0149,
  22797. nasquare: 0x3381,
  22798. nbopomofo: 0x310B,
  22799. nbspace: 0x00A0,
  22800. ncaron: 0x0148,
  22801. ncedilla: 0x0146,
  22802. ncircle: 0x24DD,
  22803. ncircumflexbelow: 0x1E4B,
  22804. ncommaaccent: 0x0146,
  22805. ndotaccent: 0x1E45,
  22806. ndotbelow: 0x1E47,
  22807. nehiragana: 0x306D,
  22808. nekatakana: 0x30CD,
  22809. nekatakanahalfwidth: 0xFF88,
  22810. newsheqelsign: 0x20AA,
  22811. nfsquare: 0x338B,
  22812. ngabengali: 0x0999,
  22813. ngadeva: 0x0919,
  22814. ngagujarati: 0x0A99,
  22815. ngagurmukhi: 0x0A19,
  22816. ngonguthai: 0x0E07,
  22817. nhiragana: 0x3093,
  22818. nhookleft: 0x0272,
  22819. nhookretroflex: 0x0273,
  22820. nieunacirclekorean: 0x326F,
  22821. nieunaparenkorean: 0x320F,
  22822. nieuncieuckorean: 0x3135,
  22823. nieuncirclekorean: 0x3261,
  22824. nieunhieuhkorean: 0x3136,
  22825. nieunkorean: 0x3134,
  22826. nieunpansioskorean: 0x3168,
  22827. nieunparenkorean: 0x3201,
  22828. nieunsioskorean: 0x3167,
  22829. nieuntikeutkorean: 0x3166,
  22830. nihiragana: 0x306B,
  22831. nikatakana: 0x30CB,
  22832. nikatakanahalfwidth: 0xFF86,
  22833. nikhahitleftthai: 0xF899,
  22834. nikhahitthai: 0x0E4D,
  22835. nine: 0x0039,
  22836. ninearabic: 0x0669,
  22837. ninebengali: 0x09EF,
  22838. ninecircle: 0x2468,
  22839. ninecircleinversesansserif: 0x2792,
  22840. ninedeva: 0x096F,
  22841. ninegujarati: 0x0AEF,
  22842. ninegurmukhi: 0x0A6F,
  22843. ninehackarabic: 0x0669,
  22844. ninehangzhou: 0x3029,
  22845. nineideographicparen: 0x3228,
  22846. nineinferior: 0x2089,
  22847. ninemonospace: 0xFF19,
  22848. nineoldstyle: 0xF739,
  22849. nineparen: 0x247C,
  22850. nineperiod: 0x2490,
  22851. ninepersian: 0x06F9,
  22852. nineroman: 0x2178,
  22853. ninesuperior: 0x2079,
  22854. nineteencircle: 0x2472,
  22855. nineteenparen: 0x2486,
  22856. nineteenperiod: 0x249A,
  22857. ninethai: 0x0E59,
  22858. nj: 0x01CC,
  22859. njecyrillic: 0x045A,
  22860. nkatakana: 0x30F3,
  22861. nkatakanahalfwidth: 0xFF9D,
  22862. nlegrightlong: 0x019E,
  22863. nlinebelow: 0x1E49,
  22864. nmonospace: 0xFF4E,
  22865. nmsquare: 0x339A,
  22866. nnabengali: 0x09A3,
  22867. nnadeva: 0x0923,
  22868. nnagujarati: 0x0AA3,
  22869. nnagurmukhi: 0x0A23,
  22870. nnnadeva: 0x0929,
  22871. nohiragana: 0x306E,
  22872. nokatakana: 0x30CE,
  22873. nokatakanahalfwidth: 0xFF89,
  22874. nonbreakingspace: 0x00A0,
  22875. nonenthai: 0x0E13,
  22876. nonuthai: 0x0E19,
  22877. noonarabic: 0x0646,
  22878. noonfinalarabic: 0xFEE6,
  22879. noonghunnaarabic: 0x06BA,
  22880. noonghunnafinalarabic: 0xFB9F,
  22881. nooninitialarabic: 0xFEE7,
  22882. noonjeeminitialarabic: 0xFCD2,
  22883. noonjeemisolatedarabic: 0xFC4B,
  22884. noonmedialarabic: 0xFEE8,
  22885. noonmeeminitialarabic: 0xFCD5,
  22886. noonmeemisolatedarabic: 0xFC4E,
  22887. noonnoonfinalarabic: 0xFC8D,
  22888. notcontains: 0x220C,
  22889. notelement: 0x2209,
  22890. notelementof: 0x2209,
  22891. notequal: 0x2260,
  22892. notgreater: 0x226F,
  22893. notgreaternorequal: 0x2271,
  22894. notgreaternorless: 0x2279,
  22895. notidentical: 0x2262,
  22896. notless: 0x226E,
  22897. notlessnorequal: 0x2270,
  22898. notparallel: 0x2226,
  22899. notprecedes: 0x2280,
  22900. notsubset: 0x2284,
  22901. notsucceeds: 0x2281,
  22902. notsuperset: 0x2285,
  22903. nowarmenian: 0x0576,
  22904. nparen: 0x24A9,
  22905. nssquare: 0x33B1,
  22906. nsuperior: 0x207F,
  22907. ntilde: 0x00F1,
  22908. nu: 0x03BD,
  22909. nuhiragana: 0x306C,
  22910. nukatakana: 0x30CC,
  22911. nukatakanahalfwidth: 0xFF87,
  22912. nuktabengali: 0x09BC,
  22913. nuktadeva: 0x093C,
  22914. nuktagujarati: 0x0ABC,
  22915. nuktagurmukhi: 0x0A3C,
  22916. numbersign: 0x0023,
  22917. numbersignmonospace: 0xFF03,
  22918. numbersignsmall: 0xFE5F,
  22919. numeralsigngreek: 0x0374,
  22920. numeralsignlowergreek: 0x0375,
  22921. numero: 0x2116,
  22922. nun: 0x05E0,
  22923. nundagesh: 0xFB40,
  22924. nundageshhebrew: 0xFB40,
  22925. nunhebrew: 0x05E0,
  22926. nvsquare: 0x33B5,
  22927. nwsquare: 0x33BB,
  22928. nyabengali: 0x099E,
  22929. nyadeva: 0x091E,
  22930. nyagujarati: 0x0A9E,
  22931. nyagurmukhi: 0x0A1E,
  22932. o: 0x006F,
  22933. oacute: 0x00F3,
  22934. oangthai: 0x0E2D,
  22935. obarred: 0x0275,
  22936. obarredcyrillic: 0x04E9,
  22937. obarreddieresiscyrillic: 0x04EB,
  22938. obengali: 0x0993,
  22939. obopomofo: 0x311B,
  22940. obreve: 0x014F,
  22941. ocandradeva: 0x0911,
  22942. ocandragujarati: 0x0A91,
  22943. ocandravowelsigndeva: 0x0949,
  22944. ocandravowelsigngujarati: 0x0AC9,
  22945. ocaron: 0x01D2,
  22946. ocircle: 0x24DE,
  22947. ocircumflex: 0x00F4,
  22948. ocircumflexacute: 0x1ED1,
  22949. ocircumflexdotbelow: 0x1ED9,
  22950. ocircumflexgrave: 0x1ED3,
  22951. ocircumflexhookabove: 0x1ED5,
  22952. ocircumflextilde: 0x1ED7,
  22953. ocyrillic: 0x043E,
  22954. odblacute: 0x0151,
  22955. odblgrave: 0x020D,
  22956. odeva: 0x0913,
  22957. odieresis: 0x00F6,
  22958. odieresiscyrillic: 0x04E7,
  22959. odotbelow: 0x1ECD,
  22960. oe: 0x0153,
  22961. oekorean: 0x315A,
  22962. ogonek: 0x02DB,
  22963. ogonekcmb: 0x0328,
  22964. ograve: 0x00F2,
  22965. ogujarati: 0x0A93,
  22966. oharmenian: 0x0585,
  22967. ohiragana: 0x304A,
  22968. ohookabove: 0x1ECF,
  22969. ohorn: 0x01A1,
  22970. ohornacute: 0x1EDB,
  22971. ohorndotbelow: 0x1EE3,
  22972. ohorngrave: 0x1EDD,
  22973. ohornhookabove: 0x1EDF,
  22974. ohorntilde: 0x1EE1,
  22975. ohungarumlaut: 0x0151,
  22976. oi: 0x01A3,
  22977. oinvertedbreve: 0x020F,
  22978. okatakana: 0x30AA,
  22979. okatakanahalfwidth: 0xFF75,
  22980. okorean: 0x3157,
  22981. olehebrew: 0x05AB,
  22982. omacron: 0x014D,
  22983. omacronacute: 0x1E53,
  22984. omacrongrave: 0x1E51,
  22985. omdeva: 0x0950,
  22986. omega: 0x03C9,
  22987. omega1: 0x03D6,
  22988. omegacyrillic: 0x0461,
  22989. omegalatinclosed: 0x0277,
  22990. omegaroundcyrillic: 0x047B,
  22991. omegatitlocyrillic: 0x047D,
  22992. omegatonos: 0x03CE,
  22993. omgujarati: 0x0AD0,
  22994. omicron: 0x03BF,
  22995. omicrontonos: 0x03CC,
  22996. omonospace: 0xFF4F,
  22997. one: 0x0031,
  22998. onearabic: 0x0661,
  22999. onebengali: 0x09E7,
  23000. onecircle: 0x2460,
  23001. onecircleinversesansserif: 0x278A,
  23002. onedeva: 0x0967,
  23003. onedotenleader: 0x2024,
  23004. oneeighth: 0x215B,
  23005. onefitted: 0xF6DC,
  23006. onegujarati: 0x0AE7,
  23007. onegurmukhi: 0x0A67,
  23008. onehackarabic: 0x0661,
  23009. onehalf: 0x00BD,
  23010. onehangzhou: 0x3021,
  23011. oneideographicparen: 0x3220,
  23012. oneinferior: 0x2081,
  23013. onemonospace: 0xFF11,
  23014. onenumeratorbengali: 0x09F4,
  23015. oneoldstyle: 0xF731,
  23016. oneparen: 0x2474,
  23017. oneperiod: 0x2488,
  23018. onepersian: 0x06F1,
  23019. onequarter: 0x00BC,
  23020. oneroman: 0x2170,
  23021. onesuperior: 0x00B9,
  23022. onethai: 0x0E51,
  23023. onethird: 0x2153,
  23024. oogonek: 0x01EB,
  23025. oogonekmacron: 0x01ED,
  23026. oogurmukhi: 0x0A13,
  23027. oomatragurmukhi: 0x0A4B,
  23028. oopen: 0x0254,
  23029. oparen: 0x24AA,
  23030. openbullet: 0x25E6,
  23031. option: 0x2325,
  23032. ordfeminine: 0x00AA,
  23033. ordmasculine: 0x00BA,
  23034. orthogonal: 0x221F,
  23035. oshortdeva: 0x0912,
  23036. oshortvowelsigndeva: 0x094A,
  23037. oslash: 0x00F8,
  23038. oslashacute: 0x01FF,
  23039. osmallhiragana: 0x3049,
  23040. osmallkatakana: 0x30A9,
  23041. osmallkatakanahalfwidth: 0xFF6B,
  23042. ostrokeacute: 0x01FF,
  23043. osuperior: 0xF6F0,
  23044. otcyrillic: 0x047F,
  23045. otilde: 0x00F5,
  23046. otildeacute: 0x1E4D,
  23047. otildedieresis: 0x1E4F,
  23048. oubopomofo: 0x3121,
  23049. overline: 0x203E,
  23050. overlinecenterline: 0xFE4A,
  23051. overlinecmb: 0x0305,
  23052. overlinedashed: 0xFE49,
  23053. overlinedblwavy: 0xFE4C,
  23054. overlinewavy: 0xFE4B,
  23055. overscore: 0x00AF,
  23056. ovowelsignbengali: 0x09CB,
  23057. ovowelsigndeva: 0x094B,
  23058. ovowelsigngujarati: 0x0ACB,
  23059. p: 0x0070,
  23060. paampssquare: 0x3380,
  23061. paasentosquare: 0x332B,
  23062. pabengali: 0x09AA,
  23063. pacute: 0x1E55,
  23064. padeva: 0x092A,
  23065. pagedown: 0x21DF,
  23066. pageup: 0x21DE,
  23067. pagujarati: 0x0AAA,
  23068. pagurmukhi: 0x0A2A,
  23069. pahiragana: 0x3071,
  23070. paiyannoithai: 0x0E2F,
  23071. pakatakana: 0x30D1,
  23072. palatalizationcyrilliccmb: 0x0484,
  23073. palochkacyrillic: 0x04C0,
  23074. pansioskorean: 0x317F,
  23075. paragraph: 0x00B6,
  23076. parallel: 0x2225,
  23077. parenleft: 0x0028,
  23078. parenleftaltonearabic: 0xFD3E,
  23079. parenleftbt: 0xF8ED,
  23080. parenleftex: 0xF8EC,
  23081. parenleftinferior: 0x208D,
  23082. parenleftmonospace: 0xFF08,
  23083. parenleftsmall: 0xFE59,
  23084. parenleftsuperior: 0x207D,
  23085. parenlefttp: 0xF8EB,
  23086. parenleftvertical: 0xFE35,
  23087. parenright: 0x0029,
  23088. parenrightaltonearabic: 0xFD3F,
  23089. parenrightbt: 0xF8F8,
  23090. parenrightex: 0xF8F7,
  23091. parenrightinferior: 0x208E,
  23092. parenrightmonospace: 0xFF09,
  23093. parenrightsmall: 0xFE5A,
  23094. parenrightsuperior: 0x207E,
  23095. parenrighttp: 0xF8F6,
  23096. parenrightvertical: 0xFE36,
  23097. partialdiff: 0x2202,
  23098. paseqhebrew: 0x05C0,
  23099. pashtahebrew: 0x0599,
  23100. pasquare: 0x33A9,
  23101. patah: 0x05B7,
  23102. patah11: 0x05B7,
  23103. patah1d: 0x05B7,
  23104. patah2a: 0x05B7,
  23105. patahhebrew: 0x05B7,
  23106. patahnarrowhebrew: 0x05B7,
  23107. patahquarterhebrew: 0x05B7,
  23108. patahwidehebrew: 0x05B7,
  23109. pazerhebrew: 0x05A1,
  23110. pbopomofo: 0x3106,
  23111. pcircle: 0x24DF,
  23112. pdotaccent: 0x1E57,
  23113. pe: 0x05E4,
  23114. pecyrillic: 0x043F,
  23115. pedagesh: 0xFB44,
  23116. pedageshhebrew: 0xFB44,
  23117. peezisquare: 0x333B,
  23118. pefinaldageshhebrew: 0xFB43,
  23119. peharabic: 0x067E,
  23120. peharmenian: 0x057A,
  23121. pehebrew: 0x05E4,
  23122. pehfinalarabic: 0xFB57,
  23123. pehinitialarabic: 0xFB58,
  23124. pehiragana: 0x307A,
  23125. pehmedialarabic: 0xFB59,
  23126. pekatakana: 0x30DA,
  23127. pemiddlehookcyrillic: 0x04A7,
  23128. perafehebrew: 0xFB4E,
  23129. percent: 0x0025,
  23130. percentarabic: 0x066A,
  23131. percentmonospace: 0xFF05,
  23132. percentsmall: 0xFE6A,
  23133. period: 0x002E,
  23134. periodarmenian: 0x0589,
  23135. periodcentered: 0x00B7,
  23136. periodhalfwidth: 0xFF61,
  23137. periodinferior: 0xF6E7,
  23138. periodmonospace: 0xFF0E,
  23139. periodsmall: 0xFE52,
  23140. periodsuperior: 0xF6E8,
  23141. perispomenigreekcmb: 0x0342,
  23142. perpendicular: 0x22A5,
  23143. perthousand: 0x2030,
  23144. peseta: 0x20A7,
  23145. pfsquare: 0x338A,
  23146. phabengali: 0x09AB,
  23147. phadeva: 0x092B,
  23148. phagujarati: 0x0AAB,
  23149. phagurmukhi: 0x0A2B,
  23150. phi: 0x03C6,
  23151. phi1: 0x03D5,
  23152. phieuphacirclekorean: 0x327A,
  23153. phieuphaparenkorean: 0x321A,
  23154. phieuphcirclekorean: 0x326C,
  23155. phieuphkorean: 0x314D,
  23156. phieuphparenkorean: 0x320C,
  23157. philatin: 0x0278,
  23158. phinthuthai: 0x0E3A,
  23159. phisymbolgreek: 0x03D5,
  23160. phook: 0x01A5,
  23161. phophanthai: 0x0E1E,
  23162. phophungthai: 0x0E1C,
  23163. phosamphaothai: 0x0E20,
  23164. pi: 0x03C0,
  23165. pieupacirclekorean: 0x3273,
  23166. pieupaparenkorean: 0x3213,
  23167. pieupcieuckorean: 0x3176,
  23168. pieupcirclekorean: 0x3265,
  23169. pieupkiyeokkorean: 0x3172,
  23170. pieupkorean: 0x3142,
  23171. pieupparenkorean: 0x3205,
  23172. pieupsioskiyeokkorean: 0x3174,
  23173. pieupsioskorean: 0x3144,
  23174. pieupsiostikeutkorean: 0x3175,
  23175. pieupthieuthkorean: 0x3177,
  23176. pieuptikeutkorean: 0x3173,
  23177. pihiragana: 0x3074,
  23178. pikatakana: 0x30D4,
  23179. pisymbolgreek: 0x03D6,
  23180. piwrarmenian: 0x0583,
  23181. plus: 0x002B,
  23182. plusbelowcmb: 0x031F,
  23183. pluscircle: 0x2295,
  23184. plusminus: 0x00B1,
  23185. plusmod: 0x02D6,
  23186. plusmonospace: 0xFF0B,
  23187. plussmall: 0xFE62,
  23188. plussuperior: 0x207A,
  23189. pmonospace: 0xFF50,
  23190. pmsquare: 0x33D8,
  23191. pohiragana: 0x307D,
  23192. pointingindexdownwhite: 0x261F,
  23193. pointingindexleftwhite: 0x261C,
  23194. pointingindexrightwhite: 0x261E,
  23195. pointingindexupwhite: 0x261D,
  23196. pokatakana: 0x30DD,
  23197. poplathai: 0x0E1B,
  23198. postalmark: 0x3012,
  23199. postalmarkface: 0x3020,
  23200. pparen: 0x24AB,
  23201. precedes: 0x227A,
  23202. prescription: 0x211E,
  23203. primemod: 0x02B9,
  23204. primereversed: 0x2035,
  23205. product: 0x220F,
  23206. projective: 0x2305,
  23207. prolongedkana: 0x30FC,
  23208. propellor: 0x2318,
  23209. propersubset: 0x2282,
  23210. propersuperset: 0x2283,
  23211. proportion: 0x2237,
  23212. proportional: 0x221D,
  23213. psi: 0x03C8,
  23214. psicyrillic: 0x0471,
  23215. psilipneumatacyrilliccmb: 0x0486,
  23216. pssquare: 0x33B0,
  23217. puhiragana: 0x3077,
  23218. pukatakana: 0x30D7,
  23219. pvsquare: 0x33B4,
  23220. pwsquare: 0x33BA,
  23221. q: 0x0071,
  23222. qadeva: 0x0958,
  23223. qadmahebrew: 0x05A8,
  23224. qafarabic: 0x0642,
  23225. qaffinalarabic: 0xFED6,
  23226. qafinitialarabic: 0xFED7,
  23227. qafmedialarabic: 0xFED8,
  23228. qamats: 0x05B8,
  23229. qamats10: 0x05B8,
  23230. qamats1a: 0x05B8,
  23231. qamats1c: 0x05B8,
  23232. qamats27: 0x05B8,
  23233. qamats29: 0x05B8,
  23234. qamats33: 0x05B8,
  23235. qamatsde: 0x05B8,
  23236. qamatshebrew: 0x05B8,
  23237. qamatsnarrowhebrew: 0x05B8,
  23238. qamatsqatanhebrew: 0x05B8,
  23239. qamatsqatannarrowhebrew: 0x05B8,
  23240. qamatsqatanquarterhebrew: 0x05B8,
  23241. qamatsqatanwidehebrew: 0x05B8,
  23242. qamatsquarterhebrew: 0x05B8,
  23243. qamatswidehebrew: 0x05B8,
  23244. qarneyparahebrew: 0x059F,
  23245. qbopomofo: 0x3111,
  23246. qcircle: 0x24E0,
  23247. qhook: 0x02A0,
  23248. qmonospace: 0xFF51,
  23249. qof: 0x05E7,
  23250. qofdagesh: 0xFB47,
  23251. qofdageshhebrew: 0xFB47,
  23252. qofhebrew: 0x05E7,
  23253. qparen: 0x24AC,
  23254. quarternote: 0x2669,
  23255. qubuts: 0x05BB,
  23256. qubuts18: 0x05BB,
  23257. qubuts25: 0x05BB,
  23258. qubuts31: 0x05BB,
  23259. qubutshebrew: 0x05BB,
  23260. qubutsnarrowhebrew: 0x05BB,
  23261. qubutsquarterhebrew: 0x05BB,
  23262. qubutswidehebrew: 0x05BB,
  23263. question: 0x003F,
  23264. questionarabic: 0x061F,
  23265. questionarmenian: 0x055E,
  23266. questiondown: 0x00BF,
  23267. questiondownsmall: 0xF7BF,
  23268. questiongreek: 0x037E,
  23269. questionmonospace: 0xFF1F,
  23270. questionsmall: 0xF73F,
  23271. quotedbl: 0x0022,
  23272. quotedblbase: 0x201E,
  23273. quotedblleft: 0x201C,
  23274. quotedblmonospace: 0xFF02,
  23275. quotedblprime: 0x301E,
  23276. quotedblprimereversed: 0x301D,
  23277. quotedblright: 0x201D,
  23278. quoteleft: 0x2018,
  23279. quoteleftreversed: 0x201B,
  23280. quotereversed: 0x201B,
  23281. quoteright: 0x2019,
  23282. quoterightn: 0x0149,
  23283. quotesinglbase: 0x201A,
  23284. quotesingle: 0x0027,
  23285. quotesinglemonospace: 0xFF07,
  23286. r: 0x0072,
  23287. raarmenian: 0x057C,
  23288. rabengali: 0x09B0,
  23289. racute: 0x0155,
  23290. radeva: 0x0930,
  23291. radical: 0x221A,
  23292. radicalex: 0xF8E5,
  23293. radoverssquare: 0x33AE,
  23294. radoverssquaredsquare: 0x33AF,
  23295. radsquare: 0x33AD,
  23296. rafe: 0x05BF,
  23297. rafehebrew: 0x05BF,
  23298. ragujarati: 0x0AB0,
  23299. ragurmukhi: 0x0A30,
  23300. rahiragana: 0x3089,
  23301. rakatakana: 0x30E9,
  23302. rakatakanahalfwidth: 0xFF97,
  23303. ralowerdiagonalbengali: 0x09F1,
  23304. ramiddlediagonalbengali: 0x09F0,
  23305. ramshorn: 0x0264,
  23306. ratio: 0x2236,
  23307. rbopomofo: 0x3116,
  23308. rcaron: 0x0159,
  23309. rcedilla: 0x0157,
  23310. rcircle: 0x24E1,
  23311. rcommaaccent: 0x0157,
  23312. rdblgrave: 0x0211,
  23313. rdotaccent: 0x1E59,
  23314. rdotbelow: 0x1E5B,
  23315. rdotbelowmacron: 0x1E5D,
  23316. referencemark: 0x203B,
  23317. reflexsubset: 0x2286,
  23318. reflexsuperset: 0x2287,
  23319. registered: 0x00AE,
  23320. registersans: 0xF8E8,
  23321. registerserif: 0xF6DA,
  23322. reharabic: 0x0631,
  23323. reharmenian: 0x0580,
  23324. rehfinalarabic: 0xFEAE,
  23325. rehiragana: 0x308C,
  23326. rekatakana: 0x30EC,
  23327. rekatakanahalfwidth: 0xFF9A,
  23328. resh: 0x05E8,
  23329. reshdageshhebrew: 0xFB48,
  23330. reshhebrew: 0x05E8,
  23331. reversedtilde: 0x223D,
  23332. reviahebrew: 0x0597,
  23333. reviamugrashhebrew: 0x0597,
  23334. revlogicalnot: 0x2310,
  23335. rfishhook: 0x027E,
  23336. rfishhookreversed: 0x027F,
  23337. rhabengali: 0x09DD,
  23338. rhadeva: 0x095D,
  23339. rho: 0x03C1,
  23340. rhook: 0x027D,
  23341. rhookturned: 0x027B,
  23342. rhookturnedsuperior: 0x02B5,
  23343. rhosymbolgreek: 0x03F1,
  23344. rhotichookmod: 0x02DE,
  23345. rieulacirclekorean: 0x3271,
  23346. rieulaparenkorean: 0x3211,
  23347. rieulcirclekorean: 0x3263,
  23348. rieulhieuhkorean: 0x3140,
  23349. rieulkiyeokkorean: 0x313A,
  23350. rieulkiyeoksioskorean: 0x3169,
  23351. rieulkorean: 0x3139,
  23352. rieulmieumkorean: 0x313B,
  23353. rieulpansioskorean: 0x316C,
  23354. rieulparenkorean: 0x3203,
  23355. rieulphieuphkorean: 0x313F,
  23356. rieulpieupkorean: 0x313C,
  23357. rieulpieupsioskorean: 0x316B,
  23358. rieulsioskorean: 0x313D,
  23359. rieulthieuthkorean: 0x313E,
  23360. rieultikeutkorean: 0x316A,
  23361. rieulyeorinhieuhkorean: 0x316D,
  23362. rightangle: 0x221F,
  23363. righttackbelowcmb: 0x0319,
  23364. righttriangle: 0x22BF,
  23365. rihiragana: 0x308A,
  23366. rikatakana: 0x30EA,
  23367. rikatakanahalfwidth: 0xFF98,
  23368. ring: 0x02DA,
  23369. ringbelowcmb: 0x0325,
  23370. ringcmb: 0x030A,
  23371. ringhalfleft: 0x02BF,
  23372. ringhalfleftarmenian: 0x0559,
  23373. ringhalfleftbelowcmb: 0x031C,
  23374. ringhalfleftcentered: 0x02D3,
  23375. ringhalfright: 0x02BE,
  23376. ringhalfrightbelowcmb: 0x0339,
  23377. ringhalfrightcentered: 0x02D2,
  23378. rinvertedbreve: 0x0213,
  23379. rittorusquare: 0x3351,
  23380. rlinebelow: 0x1E5F,
  23381. rlongleg: 0x027C,
  23382. rlonglegturned: 0x027A,
  23383. rmonospace: 0xFF52,
  23384. rohiragana: 0x308D,
  23385. rokatakana: 0x30ED,
  23386. rokatakanahalfwidth: 0xFF9B,
  23387. roruathai: 0x0E23,
  23388. rparen: 0x24AD,
  23389. rrabengali: 0x09DC,
  23390. rradeva: 0x0931,
  23391. rragurmukhi: 0x0A5C,
  23392. rreharabic: 0x0691,
  23393. rrehfinalarabic: 0xFB8D,
  23394. rrvocalicbengali: 0x09E0,
  23395. rrvocalicdeva: 0x0960,
  23396. rrvocalicgujarati: 0x0AE0,
  23397. rrvocalicvowelsignbengali: 0x09C4,
  23398. rrvocalicvowelsigndeva: 0x0944,
  23399. rrvocalicvowelsigngujarati: 0x0AC4,
  23400. rsuperior: 0xF6F1,
  23401. rtblock: 0x2590,
  23402. rturned: 0x0279,
  23403. rturnedsuperior: 0x02B4,
  23404. ruhiragana: 0x308B,
  23405. rukatakana: 0x30EB,
  23406. rukatakanahalfwidth: 0xFF99,
  23407. rupeemarkbengali: 0x09F2,
  23408. rupeesignbengali: 0x09F3,
  23409. rupiah: 0xF6DD,
  23410. ruthai: 0x0E24,
  23411. rvocalicbengali: 0x098B,
  23412. rvocalicdeva: 0x090B,
  23413. rvocalicgujarati: 0x0A8B,
  23414. rvocalicvowelsignbengali: 0x09C3,
  23415. rvocalicvowelsigndeva: 0x0943,
  23416. rvocalicvowelsigngujarati: 0x0AC3,
  23417. s: 0x0073,
  23418. sabengali: 0x09B8,
  23419. sacute: 0x015B,
  23420. sacutedotaccent: 0x1E65,
  23421. sadarabic: 0x0635,
  23422. sadeva: 0x0938,
  23423. sadfinalarabic: 0xFEBA,
  23424. sadinitialarabic: 0xFEBB,
  23425. sadmedialarabic: 0xFEBC,
  23426. sagujarati: 0x0AB8,
  23427. sagurmukhi: 0x0A38,
  23428. sahiragana: 0x3055,
  23429. sakatakana: 0x30B5,
  23430. sakatakanahalfwidth: 0xFF7B,
  23431. sallallahoualayhewasallamarabic: 0xFDFA,
  23432. samekh: 0x05E1,
  23433. samekhdagesh: 0xFB41,
  23434. samekhdageshhebrew: 0xFB41,
  23435. samekhhebrew: 0x05E1,
  23436. saraaathai: 0x0E32,
  23437. saraaethai: 0x0E41,
  23438. saraaimaimalaithai: 0x0E44,
  23439. saraaimaimuanthai: 0x0E43,
  23440. saraamthai: 0x0E33,
  23441. saraathai: 0x0E30,
  23442. saraethai: 0x0E40,
  23443. saraiileftthai: 0xF886,
  23444. saraiithai: 0x0E35,
  23445. saraileftthai: 0xF885,
  23446. saraithai: 0x0E34,
  23447. saraothai: 0x0E42,
  23448. saraueeleftthai: 0xF888,
  23449. saraueethai: 0x0E37,
  23450. saraueleftthai: 0xF887,
  23451. sarauethai: 0x0E36,
  23452. sarauthai: 0x0E38,
  23453. sarauuthai: 0x0E39,
  23454. sbopomofo: 0x3119,
  23455. scaron: 0x0161,
  23456. scarondotaccent: 0x1E67,
  23457. scedilla: 0x015F,
  23458. schwa: 0x0259,
  23459. schwacyrillic: 0x04D9,
  23460. schwadieresiscyrillic: 0x04DB,
  23461. schwahook: 0x025A,
  23462. scircle: 0x24E2,
  23463. scircumflex: 0x015D,
  23464. scommaaccent: 0x0219,
  23465. sdotaccent: 0x1E61,
  23466. sdotbelow: 0x1E63,
  23467. sdotbelowdotaccent: 0x1E69,
  23468. seagullbelowcmb: 0x033C,
  23469. second: 0x2033,
  23470. secondtonechinese: 0x02CA,
  23471. section: 0x00A7,
  23472. seenarabic: 0x0633,
  23473. seenfinalarabic: 0xFEB2,
  23474. seeninitialarabic: 0xFEB3,
  23475. seenmedialarabic: 0xFEB4,
  23476. segol: 0x05B6,
  23477. segol13: 0x05B6,
  23478. segol1f: 0x05B6,
  23479. segol2c: 0x05B6,
  23480. segolhebrew: 0x05B6,
  23481. segolnarrowhebrew: 0x05B6,
  23482. segolquarterhebrew: 0x05B6,
  23483. segoltahebrew: 0x0592,
  23484. segolwidehebrew: 0x05B6,
  23485. seharmenian: 0x057D,
  23486. sehiragana: 0x305B,
  23487. sekatakana: 0x30BB,
  23488. sekatakanahalfwidth: 0xFF7E,
  23489. semicolon: 0x003B,
  23490. semicolonarabic: 0x061B,
  23491. semicolonmonospace: 0xFF1B,
  23492. semicolonsmall: 0xFE54,
  23493. semivoicedmarkkana: 0x309C,
  23494. semivoicedmarkkanahalfwidth: 0xFF9F,
  23495. sentisquare: 0x3322,
  23496. sentosquare: 0x3323,
  23497. seven: 0x0037,
  23498. sevenarabic: 0x0667,
  23499. sevenbengali: 0x09ED,
  23500. sevencircle: 0x2466,
  23501. sevencircleinversesansserif: 0x2790,
  23502. sevendeva: 0x096D,
  23503. seveneighths: 0x215E,
  23504. sevengujarati: 0x0AED,
  23505. sevengurmukhi: 0x0A6D,
  23506. sevenhackarabic: 0x0667,
  23507. sevenhangzhou: 0x3027,
  23508. sevenideographicparen: 0x3226,
  23509. seveninferior: 0x2087,
  23510. sevenmonospace: 0xFF17,
  23511. sevenoldstyle: 0xF737,
  23512. sevenparen: 0x247A,
  23513. sevenperiod: 0x248E,
  23514. sevenpersian: 0x06F7,
  23515. sevenroman: 0x2176,
  23516. sevensuperior: 0x2077,
  23517. seventeencircle: 0x2470,
  23518. seventeenparen: 0x2484,
  23519. seventeenperiod: 0x2498,
  23520. seventhai: 0x0E57,
  23521. sfthyphen: 0x00AD,
  23522. shaarmenian: 0x0577,
  23523. shabengali: 0x09B6,
  23524. shacyrillic: 0x0448,
  23525. shaddaarabic: 0x0651,
  23526. shaddadammaarabic: 0xFC61,
  23527. shaddadammatanarabic: 0xFC5E,
  23528. shaddafathaarabic: 0xFC60,
  23529. shaddakasraarabic: 0xFC62,
  23530. shaddakasratanarabic: 0xFC5F,
  23531. shade: 0x2592,
  23532. shadedark: 0x2593,
  23533. shadelight: 0x2591,
  23534. shademedium: 0x2592,
  23535. shadeva: 0x0936,
  23536. shagujarati: 0x0AB6,
  23537. shagurmukhi: 0x0A36,
  23538. shalshelethebrew: 0x0593,
  23539. shbopomofo: 0x3115,
  23540. shchacyrillic: 0x0449,
  23541. sheenarabic: 0x0634,
  23542. sheenfinalarabic: 0xFEB6,
  23543. sheeninitialarabic: 0xFEB7,
  23544. sheenmedialarabic: 0xFEB8,
  23545. sheicoptic: 0x03E3,
  23546. sheqel: 0x20AA,
  23547. sheqelhebrew: 0x20AA,
  23548. sheva: 0x05B0,
  23549. sheva115: 0x05B0,
  23550. sheva15: 0x05B0,
  23551. sheva22: 0x05B0,
  23552. sheva2e: 0x05B0,
  23553. shevahebrew: 0x05B0,
  23554. shevanarrowhebrew: 0x05B0,
  23555. shevaquarterhebrew: 0x05B0,
  23556. shevawidehebrew: 0x05B0,
  23557. shhacyrillic: 0x04BB,
  23558. shimacoptic: 0x03ED,
  23559. shin: 0x05E9,
  23560. shindagesh: 0xFB49,
  23561. shindageshhebrew: 0xFB49,
  23562. shindageshshindot: 0xFB2C,
  23563. shindageshshindothebrew: 0xFB2C,
  23564. shindageshsindot: 0xFB2D,
  23565. shindageshsindothebrew: 0xFB2D,
  23566. shindothebrew: 0x05C1,
  23567. shinhebrew: 0x05E9,
  23568. shinshindot: 0xFB2A,
  23569. shinshindothebrew: 0xFB2A,
  23570. shinsindot: 0xFB2B,
  23571. shinsindothebrew: 0xFB2B,
  23572. shook: 0x0282,
  23573. sigma: 0x03C3,
  23574. sigma1: 0x03C2,
  23575. sigmafinal: 0x03C2,
  23576. sigmalunatesymbolgreek: 0x03F2,
  23577. sihiragana: 0x3057,
  23578. sikatakana: 0x30B7,
  23579. sikatakanahalfwidth: 0xFF7C,
  23580. siluqhebrew: 0x05BD,
  23581. siluqlefthebrew: 0x05BD,
  23582. similar: 0x223C,
  23583. sindothebrew: 0x05C2,
  23584. siosacirclekorean: 0x3274,
  23585. siosaparenkorean: 0x3214,
  23586. sioscieuckorean: 0x317E,
  23587. sioscirclekorean: 0x3266,
  23588. sioskiyeokkorean: 0x317A,
  23589. sioskorean: 0x3145,
  23590. siosnieunkorean: 0x317B,
  23591. siosparenkorean: 0x3206,
  23592. siospieupkorean: 0x317D,
  23593. siostikeutkorean: 0x317C,
  23594. six: 0x0036,
  23595. sixarabic: 0x0666,
  23596. sixbengali: 0x09EC,
  23597. sixcircle: 0x2465,
  23598. sixcircleinversesansserif: 0x278F,
  23599. sixdeva: 0x096C,
  23600. sixgujarati: 0x0AEC,
  23601. sixgurmukhi: 0x0A6C,
  23602. sixhackarabic: 0x0666,
  23603. sixhangzhou: 0x3026,
  23604. sixideographicparen: 0x3225,
  23605. sixinferior: 0x2086,
  23606. sixmonospace: 0xFF16,
  23607. sixoldstyle: 0xF736,
  23608. sixparen: 0x2479,
  23609. sixperiod: 0x248D,
  23610. sixpersian: 0x06F6,
  23611. sixroman: 0x2175,
  23612. sixsuperior: 0x2076,
  23613. sixteencircle: 0x246F,
  23614. sixteencurrencydenominatorbengali: 0x09F9,
  23615. sixteenparen: 0x2483,
  23616. sixteenperiod: 0x2497,
  23617. sixthai: 0x0E56,
  23618. slash: 0x002F,
  23619. slashmonospace: 0xFF0F,
  23620. slong: 0x017F,
  23621. slongdotaccent: 0x1E9B,
  23622. smileface: 0x263A,
  23623. smonospace: 0xFF53,
  23624. sofpasuqhebrew: 0x05C3,
  23625. softhyphen: 0x00AD,
  23626. softsigncyrillic: 0x044C,
  23627. sohiragana: 0x305D,
  23628. sokatakana: 0x30BD,
  23629. sokatakanahalfwidth: 0xFF7F,
  23630. soliduslongoverlaycmb: 0x0338,
  23631. solidusshortoverlaycmb: 0x0337,
  23632. sorusithai: 0x0E29,
  23633. sosalathai: 0x0E28,
  23634. sosothai: 0x0E0B,
  23635. sosuathai: 0x0E2A,
  23636. space: 0x0020,
  23637. spacehackarabic: 0x0020,
  23638. spade: 0x2660,
  23639. spadesuitblack: 0x2660,
  23640. spadesuitwhite: 0x2664,
  23641. sparen: 0x24AE,
  23642. squarebelowcmb: 0x033B,
  23643. squarecc: 0x33C4,
  23644. squarecm: 0x339D,
  23645. squarediagonalcrosshatchfill: 0x25A9,
  23646. squarehorizontalfill: 0x25A4,
  23647. squarekg: 0x338F,
  23648. squarekm: 0x339E,
  23649. squarekmcapital: 0x33CE,
  23650. squareln: 0x33D1,
  23651. squarelog: 0x33D2,
  23652. squaremg: 0x338E,
  23653. squaremil: 0x33D5,
  23654. squaremm: 0x339C,
  23655. squaremsquared: 0x33A1,
  23656. squareorthogonalcrosshatchfill: 0x25A6,
  23657. squareupperlefttolowerrightfill: 0x25A7,
  23658. squareupperrighttolowerleftfill: 0x25A8,
  23659. squareverticalfill: 0x25A5,
  23660. squarewhitewithsmallblack: 0x25A3,
  23661. srsquare: 0x33DB,
  23662. ssabengali: 0x09B7,
  23663. ssadeva: 0x0937,
  23664. ssagujarati: 0x0AB7,
  23665. ssangcieuckorean: 0x3149,
  23666. ssanghieuhkorean: 0x3185,
  23667. ssangieungkorean: 0x3180,
  23668. ssangkiyeokkorean: 0x3132,
  23669. ssangnieunkorean: 0x3165,
  23670. ssangpieupkorean: 0x3143,
  23671. ssangsioskorean: 0x3146,
  23672. ssangtikeutkorean: 0x3138,
  23673. ssuperior: 0xF6F2,
  23674. sterling: 0x00A3,
  23675. sterlingmonospace: 0xFFE1,
  23676. strokelongoverlaycmb: 0x0336,
  23677. strokeshortoverlaycmb: 0x0335,
  23678. subset: 0x2282,
  23679. subsetnotequal: 0x228A,
  23680. subsetorequal: 0x2286,
  23681. succeeds: 0x227B,
  23682. suchthat: 0x220B,
  23683. suhiragana: 0x3059,
  23684. sukatakana: 0x30B9,
  23685. sukatakanahalfwidth: 0xFF7D,
  23686. sukunarabic: 0x0652,
  23687. summation: 0x2211,
  23688. sun: 0x263C,
  23689. superset: 0x2283,
  23690. supersetnotequal: 0x228B,
  23691. supersetorequal: 0x2287,
  23692. svsquare: 0x33DC,
  23693. syouwaerasquare: 0x337C,
  23694. t: 0x0074,
  23695. tabengali: 0x09A4,
  23696. tackdown: 0x22A4,
  23697. tackleft: 0x22A3,
  23698. tadeva: 0x0924,
  23699. tagujarati: 0x0AA4,
  23700. tagurmukhi: 0x0A24,
  23701. taharabic: 0x0637,
  23702. tahfinalarabic: 0xFEC2,
  23703. tahinitialarabic: 0xFEC3,
  23704. tahiragana: 0x305F,
  23705. tahmedialarabic: 0xFEC4,
  23706. taisyouerasquare: 0x337D,
  23707. takatakana: 0x30BF,
  23708. takatakanahalfwidth: 0xFF80,
  23709. tatweelarabic: 0x0640,
  23710. tau: 0x03C4,
  23711. tav: 0x05EA,
  23712. tavdages: 0xFB4A,
  23713. tavdagesh: 0xFB4A,
  23714. tavdageshhebrew: 0xFB4A,
  23715. tavhebrew: 0x05EA,
  23716. tbar: 0x0167,
  23717. tbopomofo: 0x310A,
  23718. tcaron: 0x0165,
  23719. tccurl: 0x02A8,
  23720. tcedilla: 0x0163,
  23721. tcheharabic: 0x0686,
  23722. tchehfinalarabic: 0xFB7B,
  23723. tchehinitialarabic: 0xFB7C,
  23724. tchehmedialarabic: 0xFB7D,
  23725. tcircle: 0x24E3,
  23726. tcircumflexbelow: 0x1E71,
  23727. tcommaaccent: 0x0163,
  23728. tdieresis: 0x1E97,
  23729. tdotaccent: 0x1E6B,
  23730. tdotbelow: 0x1E6D,
  23731. tecyrillic: 0x0442,
  23732. tedescendercyrillic: 0x04AD,
  23733. teharabic: 0x062A,
  23734. tehfinalarabic: 0xFE96,
  23735. tehhahinitialarabic: 0xFCA2,
  23736. tehhahisolatedarabic: 0xFC0C,
  23737. tehinitialarabic: 0xFE97,
  23738. tehiragana: 0x3066,
  23739. tehjeeminitialarabic: 0xFCA1,
  23740. tehjeemisolatedarabic: 0xFC0B,
  23741. tehmarbutaarabic: 0x0629,
  23742. tehmarbutafinalarabic: 0xFE94,
  23743. tehmedialarabic: 0xFE98,
  23744. tehmeeminitialarabic: 0xFCA4,
  23745. tehmeemisolatedarabic: 0xFC0E,
  23746. tehnoonfinalarabic: 0xFC73,
  23747. tekatakana: 0x30C6,
  23748. tekatakanahalfwidth: 0xFF83,
  23749. telephone: 0x2121,
  23750. telephoneblack: 0x260E,
  23751. telishagedolahebrew: 0x05A0,
  23752. telishaqetanahebrew: 0x05A9,
  23753. tencircle: 0x2469,
  23754. tenideographicparen: 0x3229,
  23755. tenparen: 0x247D,
  23756. tenperiod: 0x2491,
  23757. tenroman: 0x2179,
  23758. tesh: 0x02A7,
  23759. tet: 0x05D8,
  23760. tetdagesh: 0xFB38,
  23761. tetdageshhebrew: 0xFB38,
  23762. tethebrew: 0x05D8,
  23763. tetsecyrillic: 0x04B5,
  23764. tevirhebrew: 0x059B,
  23765. tevirlefthebrew: 0x059B,
  23766. thabengali: 0x09A5,
  23767. thadeva: 0x0925,
  23768. thagujarati: 0x0AA5,
  23769. thagurmukhi: 0x0A25,
  23770. thalarabic: 0x0630,
  23771. thalfinalarabic: 0xFEAC,
  23772. thanthakhatlowleftthai: 0xF898,
  23773. thanthakhatlowrightthai: 0xF897,
  23774. thanthakhatthai: 0x0E4C,
  23775. thanthakhatupperleftthai: 0xF896,
  23776. theharabic: 0x062B,
  23777. thehfinalarabic: 0xFE9A,
  23778. thehinitialarabic: 0xFE9B,
  23779. thehmedialarabic: 0xFE9C,
  23780. thereexists: 0x2203,
  23781. therefore: 0x2234,
  23782. theta: 0x03B8,
  23783. theta1: 0x03D1,
  23784. thetasymbolgreek: 0x03D1,
  23785. thieuthacirclekorean: 0x3279,
  23786. thieuthaparenkorean: 0x3219,
  23787. thieuthcirclekorean: 0x326B,
  23788. thieuthkorean: 0x314C,
  23789. thieuthparenkorean: 0x320B,
  23790. thirteencircle: 0x246C,
  23791. thirteenparen: 0x2480,
  23792. thirteenperiod: 0x2494,
  23793. thonangmonthothai: 0x0E11,
  23794. thook: 0x01AD,
  23795. thophuthaothai: 0x0E12,
  23796. thorn: 0x00FE,
  23797. thothahanthai: 0x0E17,
  23798. thothanthai: 0x0E10,
  23799. thothongthai: 0x0E18,
  23800. thothungthai: 0x0E16,
  23801. thousandcyrillic: 0x0482,
  23802. thousandsseparatorarabic: 0x066C,
  23803. thousandsseparatorpersian: 0x066C,
  23804. three: 0x0033,
  23805. threearabic: 0x0663,
  23806. threebengali: 0x09E9,
  23807. threecircle: 0x2462,
  23808. threecircleinversesansserif: 0x278C,
  23809. threedeva: 0x0969,
  23810. threeeighths: 0x215C,
  23811. threegujarati: 0x0AE9,
  23812. threegurmukhi: 0x0A69,
  23813. threehackarabic: 0x0663,
  23814. threehangzhou: 0x3023,
  23815. threeideographicparen: 0x3222,
  23816. threeinferior: 0x2083,
  23817. threemonospace: 0xFF13,
  23818. threenumeratorbengali: 0x09F6,
  23819. threeoldstyle: 0xF733,
  23820. threeparen: 0x2476,
  23821. threeperiod: 0x248A,
  23822. threepersian: 0x06F3,
  23823. threequarters: 0x00BE,
  23824. threequartersemdash: 0xF6DE,
  23825. threeroman: 0x2172,
  23826. threesuperior: 0x00B3,
  23827. threethai: 0x0E53,
  23828. thzsquare: 0x3394,
  23829. tihiragana: 0x3061,
  23830. tikatakana: 0x30C1,
  23831. tikatakanahalfwidth: 0xFF81,
  23832. tikeutacirclekorean: 0x3270,
  23833. tikeutaparenkorean: 0x3210,
  23834. tikeutcirclekorean: 0x3262,
  23835. tikeutkorean: 0x3137,
  23836. tikeutparenkorean: 0x3202,
  23837. tilde: 0x02DC,
  23838. tildebelowcmb: 0x0330,
  23839. tildecmb: 0x0303,
  23840. tildecomb: 0x0303,
  23841. tildedoublecmb: 0x0360,
  23842. tildeoperator: 0x223C,
  23843. tildeoverlaycmb: 0x0334,
  23844. tildeverticalcmb: 0x033E,
  23845. timescircle: 0x2297,
  23846. tipehahebrew: 0x0596,
  23847. tipehalefthebrew: 0x0596,
  23848. tippigurmukhi: 0x0A70,
  23849. titlocyrilliccmb: 0x0483,
  23850. tiwnarmenian: 0x057F,
  23851. tlinebelow: 0x1E6F,
  23852. tmonospace: 0xFF54,
  23853. toarmenian: 0x0569,
  23854. tohiragana: 0x3068,
  23855. tokatakana: 0x30C8,
  23856. tokatakanahalfwidth: 0xFF84,
  23857. tonebarextrahighmod: 0x02E5,
  23858. tonebarextralowmod: 0x02E9,
  23859. tonebarhighmod: 0x02E6,
  23860. tonebarlowmod: 0x02E8,
  23861. tonebarmidmod: 0x02E7,
  23862. tonefive: 0x01BD,
  23863. tonesix: 0x0185,
  23864. tonetwo: 0x01A8,
  23865. tonos: 0x0384,
  23866. tonsquare: 0x3327,
  23867. topatakthai: 0x0E0F,
  23868. tortoiseshellbracketleft: 0x3014,
  23869. tortoiseshellbracketleftsmall: 0xFE5D,
  23870. tortoiseshellbracketleftvertical: 0xFE39,
  23871. tortoiseshellbracketright: 0x3015,
  23872. tortoiseshellbracketrightsmall: 0xFE5E,
  23873. tortoiseshellbracketrightvertical: 0xFE3A,
  23874. totaothai: 0x0E15,
  23875. tpalatalhook: 0x01AB,
  23876. tparen: 0x24AF,
  23877. trademark: 0x2122,
  23878. trademarksans: 0xF8EA,
  23879. trademarkserif: 0xF6DB,
  23880. tretroflexhook: 0x0288,
  23881. triagdn: 0x25BC,
  23882. triaglf: 0x25C4,
  23883. triagrt: 0x25BA,
  23884. triagup: 0x25B2,
  23885. ts: 0x02A6,
  23886. tsadi: 0x05E6,
  23887. tsadidagesh: 0xFB46,
  23888. tsadidageshhebrew: 0xFB46,
  23889. tsadihebrew: 0x05E6,
  23890. tsecyrillic: 0x0446,
  23891. tsere: 0x05B5,
  23892. tsere12: 0x05B5,
  23893. tsere1e: 0x05B5,
  23894. tsere2b: 0x05B5,
  23895. tserehebrew: 0x05B5,
  23896. tserenarrowhebrew: 0x05B5,
  23897. tserequarterhebrew: 0x05B5,
  23898. tserewidehebrew: 0x05B5,
  23899. tshecyrillic: 0x045B,
  23900. tsuperior: 0xF6F3,
  23901. ttabengali: 0x099F,
  23902. ttadeva: 0x091F,
  23903. ttagujarati: 0x0A9F,
  23904. ttagurmukhi: 0x0A1F,
  23905. tteharabic: 0x0679,
  23906. ttehfinalarabic: 0xFB67,
  23907. ttehinitialarabic: 0xFB68,
  23908. ttehmedialarabic: 0xFB69,
  23909. tthabengali: 0x09A0,
  23910. tthadeva: 0x0920,
  23911. tthagujarati: 0x0AA0,
  23912. tthagurmukhi: 0x0A20,
  23913. tturned: 0x0287,
  23914. tuhiragana: 0x3064,
  23915. tukatakana: 0x30C4,
  23916. tukatakanahalfwidth: 0xFF82,
  23917. tusmallhiragana: 0x3063,
  23918. tusmallkatakana: 0x30C3,
  23919. tusmallkatakanahalfwidth: 0xFF6F,
  23920. twelvecircle: 0x246B,
  23921. twelveparen: 0x247F,
  23922. twelveperiod: 0x2493,
  23923. twelveroman: 0x217B,
  23924. twentycircle: 0x2473,
  23925. twentyhangzhou: 0x5344,
  23926. twentyparen: 0x2487,
  23927. twentyperiod: 0x249B,
  23928. two: 0x0032,
  23929. twoarabic: 0x0662,
  23930. twobengali: 0x09E8,
  23931. twocircle: 0x2461,
  23932. twocircleinversesansserif: 0x278B,
  23933. twodeva: 0x0968,
  23934. twodotenleader: 0x2025,
  23935. twodotleader: 0x2025,
  23936. twodotleadervertical: 0xFE30,
  23937. twogujarati: 0x0AE8,
  23938. twogurmukhi: 0x0A68,
  23939. twohackarabic: 0x0662,
  23940. twohangzhou: 0x3022,
  23941. twoideographicparen: 0x3221,
  23942. twoinferior: 0x2082,
  23943. twomonospace: 0xFF12,
  23944. twonumeratorbengali: 0x09F5,
  23945. twooldstyle: 0xF732,
  23946. twoparen: 0x2475,
  23947. twoperiod: 0x2489,
  23948. twopersian: 0x06F2,
  23949. tworoman: 0x2171,
  23950. twostroke: 0x01BB,
  23951. twosuperior: 0x00B2,
  23952. twothai: 0x0E52,
  23953. twothirds: 0x2154,
  23954. u: 0x0075,
  23955. uacute: 0x00FA,
  23956. ubar: 0x0289,
  23957. ubengali: 0x0989,
  23958. ubopomofo: 0x3128,
  23959. ubreve: 0x016D,
  23960. ucaron: 0x01D4,
  23961. ucircle: 0x24E4,
  23962. ucircumflex: 0x00FB,
  23963. ucircumflexbelow: 0x1E77,
  23964. ucyrillic: 0x0443,
  23965. udattadeva: 0x0951,
  23966. udblacute: 0x0171,
  23967. udblgrave: 0x0215,
  23968. udeva: 0x0909,
  23969. udieresis: 0x00FC,
  23970. udieresisacute: 0x01D8,
  23971. udieresisbelow: 0x1E73,
  23972. udieresiscaron: 0x01DA,
  23973. udieresiscyrillic: 0x04F1,
  23974. udieresisgrave: 0x01DC,
  23975. udieresismacron: 0x01D6,
  23976. udotbelow: 0x1EE5,
  23977. ugrave: 0x00F9,
  23978. ugujarati: 0x0A89,
  23979. ugurmukhi: 0x0A09,
  23980. uhiragana: 0x3046,
  23981. uhookabove: 0x1EE7,
  23982. uhorn: 0x01B0,
  23983. uhornacute: 0x1EE9,
  23984. uhorndotbelow: 0x1EF1,
  23985. uhorngrave: 0x1EEB,
  23986. uhornhookabove: 0x1EED,
  23987. uhorntilde: 0x1EEF,
  23988. uhungarumlaut: 0x0171,
  23989. uhungarumlautcyrillic: 0x04F3,
  23990. uinvertedbreve: 0x0217,
  23991. ukatakana: 0x30A6,
  23992. ukatakanahalfwidth: 0xFF73,
  23993. ukcyrillic: 0x0479,
  23994. ukorean: 0x315C,
  23995. umacron: 0x016B,
  23996. umacroncyrillic: 0x04EF,
  23997. umacrondieresis: 0x1E7B,
  23998. umatragurmukhi: 0x0A41,
  23999. umonospace: 0xFF55,
  24000. underscore: 0x005F,
  24001. underscoredbl: 0x2017,
  24002. underscoremonospace: 0xFF3F,
  24003. underscorevertical: 0xFE33,
  24004. underscorewavy: 0xFE4F,
  24005. union: 0x222A,
  24006. universal: 0x2200,
  24007. uogonek: 0x0173,
  24008. uparen: 0x24B0,
  24009. upblock: 0x2580,
  24010. upperdothebrew: 0x05C4,
  24011. upsilon: 0x03C5,
  24012. upsilondieresis: 0x03CB,
  24013. upsilondieresistonos: 0x03B0,
  24014. upsilonlatin: 0x028A,
  24015. upsilontonos: 0x03CD,
  24016. uptackbelowcmb: 0x031D,
  24017. uptackmod: 0x02D4,
  24018. uragurmukhi: 0x0A73,
  24019. uring: 0x016F,
  24020. ushortcyrillic: 0x045E,
  24021. usmallhiragana: 0x3045,
  24022. usmallkatakana: 0x30A5,
  24023. usmallkatakanahalfwidth: 0xFF69,
  24024. ustraightcyrillic: 0x04AF,
  24025. ustraightstrokecyrillic: 0x04B1,
  24026. utilde: 0x0169,
  24027. utildeacute: 0x1E79,
  24028. utildebelow: 0x1E75,
  24029. uubengali: 0x098A,
  24030. uudeva: 0x090A,
  24031. uugujarati: 0x0A8A,
  24032. uugurmukhi: 0x0A0A,
  24033. uumatragurmukhi: 0x0A42,
  24034. uuvowelsignbengali: 0x09C2,
  24035. uuvowelsigndeva: 0x0942,
  24036. uuvowelsigngujarati: 0x0AC2,
  24037. uvowelsignbengali: 0x09C1,
  24038. uvowelsigndeva: 0x0941,
  24039. uvowelsigngujarati: 0x0AC1,
  24040. v: 0x0076,
  24041. vadeva: 0x0935,
  24042. vagujarati: 0x0AB5,
  24043. vagurmukhi: 0x0A35,
  24044. vakatakana: 0x30F7,
  24045. vav: 0x05D5,
  24046. vavdagesh: 0xFB35,
  24047. vavdagesh65: 0xFB35,
  24048. vavdageshhebrew: 0xFB35,
  24049. vavhebrew: 0x05D5,
  24050. vavholam: 0xFB4B,
  24051. vavholamhebrew: 0xFB4B,
  24052. vavvavhebrew: 0x05F0,
  24053. vavyodhebrew: 0x05F1,
  24054. vcircle: 0x24E5,
  24055. vdotbelow: 0x1E7F,
  24056. vecyrillic: 0x0432,
  24057. veharabic: 0x06A4,
  24058. vehfinalarabic: 0xFB6B,
  24059. vehinitialarabic: 0xFB6C,
  24060. vehmedialarabic: 0xFB6D,
  24061. vekatakana: 0x30F9,
  24062. venus: 0x2640,
  24063. verticalbar: 0x007C,
  24064. verticallineabovecmb: 0x030D,
  24065. verticallinebelowcmb: 0x0329,
  24066. verticallinelowmod: 0x02CC,
  24067. verticallinemod: 0x02C8,
  24068. vewarmenian: 0x057E,
  24069. vhook: 0x028B,
  24070. vikatakana: 0x30F8,
  24071. viramabengali: 0x09CD,
  24072. viramadeva: 0x094D,
  24073. viramagujarati: 0x0ACD,
  24074. visargabengali: 0x0983,
  24075. visargadeva: 0x0903,
  24076. visargagujarati: 0x0A83,
  24077. vmonospace: 0xFF56,
  24078. voarmenian: 0x0578,
  24079. voicediterationhiragana: 0x309E,
  24080. voicediterationkatakana: 0x30FE,
  24081. voicedmarkkana: 0x309B,
  24082. voicedmarkkanahalfwidth: 0xFF9E,
  24083. vokatakana: 0x30FA,
  24084. vparen: 0x24B1,
  24085. vtilde: 0x1E7D,
  24086. vturned: 0x028C,
  24087. vuhiragana: 0x3094,
  24088. vukatakana: 0x30F4,
  24089. w: 0x0077,
  24090. wacute: 0x1E83,
  24091. waekorean: 0x3159,
  24092. wahiragana: 0x308F,
  24093. wakatakana: 0x30EF,
  24094. wakatakanahalfwidth: 0xFF9C,
  24095. wakorean: 0x3158,
  24096. wasmallhiragana: 0x308E,
  24097. wasmallkatakana: 0x30EE,
  24098. wattosquare: 0x3357,
  24099. wavedash: 0x301C,
  24100. wavyunderscorevertical: 0xFE34,
  24101. wawarabic: 0x0648,
  24102. wawfinalarabic: 0xFEEE,
  24103. wawhamzaabovearabic: 0x0624,
  24104. wawhamzaabovefinalarabic: 0xFE86,
  24105. wbsquare: 0x33DD,
  24106. wcircle: 0x24E6,
  24107. wcircumflex: 0x0175,
  24108. wdieresis: 0x1E85,
  24109. wdotaccent: 0x1E87,
  24110. wdotbelow: 0x1E89,
  24111. wehiragana: 0x3091,
  24112. weierstrass: 0x2118,
  24113. wekatakana: 0x30F1,
  24114. wekorean: 0x315E,
  24115. weokorean: 0x315D,
  24116. wgrave: 0x1E81,
  24117. whitebullet: 0x25E6,
  24118. whitecircle: 0x25CB,
  24119. whitecircleinverse: 0x25D9,
  24120. whitecornerbracketleft: 0x300E,
  24121. whitecornerbracketleftvertical: 0xFE43,
  24122. whitecornerbracketright: 0x300F,
  24123. whitecornerbracketrightvertical: 0xFE44,
  24124. whitediamond: 0x25C7,
  24125. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24126. whitedownpointingsmalltriangle: 0x25BF,
  24127. whitedownpointingtriangle: 0x25BD,
  24128. whiteleftpointingsmalltriangle: 0x25C3,
  24129. whiteleftpointingtriangle: 0x25C1,
  24130. whitelenticularbracketleft: 0x3016,
  24131. whitelenticularbracketright: 0x3017,
  24132. whiterightpointingsmalltriangle: 0x25B9,
  24133. whiterightpointingtriangle: 0x25B7,
  24134. whitesmallsquare: 0x25AB,
  24135. whitesmilingface: 0x263A,
  24136. whitesquare: 0x25A1,
  24137. whitestar: 0x2606,
  24138. whitetelephone: 0x260F,
  24139. whitetortoiseshellbracketleft: 0x3018,
  24140. whitetortoiseshellbracketright: 0x3019,
  24141. whiteuppointingsmalltriangle: 0x25B5,
  24142. whiteuppointingtriangle: 0x25B3,
  24143. wihiragana: 0x3090,
  24144. wikatakana: 0x30F0,
  24145. wikorean: 0x315F,
  24146. wmonospace: 0xFF57,
  24147. wohiragana: 0x3092,
  24148. wokatakana: 0x30F2,
  24149. wokatakanahalfwidth: 0xFF66,
  24150. won: 0x20A9,
  24151. wonmonospace: 0xFFE6,
  24152. wowaenthai: 0x0E27,
  24153. wparen: 0x24B2,
  24154. wring: 0x1E98,
  24155. wsuperior: 0x02B7,
  24156. wturned: 0x028D,
  24157. wynn: 0x01BF,
  24158. x: 0x0078,
  24159. xabovecmb: 0x033D,
  24160. xbopomofo: 0x3112,
  24161. xcircle: 0x24E7,
  24162. xdieresis: 0x1E8D,
  24163. xdotaccent: 0x1E8B,
  24164. xeharmenian: 0x056D,
  24165. xi: 0x03BE,
  24166. xmonospace: 0xFF58,
  24167. xparen: 0x24B3,
  24168. xsuperior: 0x02E3,
  24169. y: 0x0079,
  24170. yaadosquare: 0x334E,
  24171. yabengali: 0x09AF,
  24172. yacute: 0x00FD,
  24173. yadeva: 0x092F,
  24174. yaekorean: 0x3152,
  24175. yagujarati: 0x0AAF,
  24176. yagurmukhi: 0x0A2F,
  24177. yahiragana: 0x3084,
  24178. yakatakana: 0x30E4,
  24179. yakatakanahalfwidth: 0xFF94,
  24180. yakorean: 0x3151,
  24181. yamakkanthai: 0x0E4E,
  24182. yasmallhiragana: 0x3083,
  24183. yasmallkatakana: 0x30E3,
  24184. yasmallkatakanahalfwidth: 0xFF6C,
  24185. yatcyrillic: 0x0463,
  24186. ycircle: 0x24E8,
  24187. ycircumflex: 0x0177,
  24188. ydieresis: 0x00FF,
  24189. ydotaccent: 0x1E8F,
  24190. ydotbelow: 0x1EF5,
  24191. yeharabic: 0x064A,
  24192. yehbarreearabic: 0x06D2,
  24193. yehbarreefinalarabic: 0xFBAF,
  24194. yehfinalarabic: 0xFEF2,
  24195. yehhamzaabovearabic: 0x0626,
  24196. yehhamzaabovefinalarabic: 0xFE8A,
  24197. yehhamzaaboveinitialarabic: 0xFE8B,
  24198. yehhamzaabovemedialarabic: 0xFE8C,
  24199. yehinitialarabic: 0xFEF3,
  24200. yehmedialarabic: 0xFEF4,
  24201. yehmeeminitialarabic: 0xFCDD,
  24202. yehmeemisolatedarabic: 0xFC58,
  24203. yehnoonfinalarabic: 0xFC94,
  24204. yehthreedotsbelowarabic: 0x06D1,
  24205. yekorean: 0x3156,
  24206. yen: 0x00A5,
  24207. yenmonospace: 0xFFE5,
  24208. yeokorean: 0x3155,
  24209. yeorinhieuhkorean: 0x3186,
  24210. yerahbenyomohebrew: 0x05AA,
  24211. yerahbenyomolefthebrew: 0x05AA,
  24212. yericyrillic: 0x044B,
  24213. yerudieresiscyrillic: 0x04F9,
  24214. yesieungkorean: 0x3181,
  24215. yesieungpansioskorean: 0x3183,
  24216. yesieungsioskorean: 0x3182,
  24217. yetivhebrew: 0x059A,
  24218. ygrave: 0x1EF3,
  24219. yhook: 0x01B4,
  24220. yhookabove: 0x1EF7,
  24221. yiarmenian: 0x0575,
  24222. yicyrillic: 0x0457,
  24223. yikorean: 0x3162,
  24224. yinyang: 0x262F,
  24225. yiwnarmenian: 0x0582,
  24226. ymonospace: 0xFF59,
  24227. yod: 0x05D9,
  24228. yoddagesh: 0xFB39,
  24229. yoddageshhebrew: 0xFB39,
  24230. yodhebrew: 0x05D9,
  24231. yodyodhebrew: 0x05F2,
  24232. yodyodpatahhebrew: 0xFB1F,
  24233. yohiragana: 0x3088,
  24234. yoikorean: 0x3189,
  24235. yokatakana: 0x30E8,
  24236. yokatakanahalfwidth: 0xFF96,
  24237. yokorean: 0x315B,
  24238. yosmallhiragana: 0x3087,
  24239. yosmallkatakana: 0x30E7,
  24240. yosmallkatakanahalfwidth: 0xFF6E,
  24241. yotgreek: 0x03F3,
  24242. yoyaekorean: 0x3188,
  24243. yoyakorean: 0x3187,
  24244. yoyakthai: 0x0E22,
  24245. yoyingthai: 0x0E0D,
  24246. yparen: 0x24B4,
  24247. ypogegrammeni: 0x037A,
  24248. ypogegrammenigreekcmb: 0x0345,
  24249. yr: 0x01A6,
  24250. yring: 0x1E99,
  24251. ysuperior: 0x02B8,
  24252. ytilde: 0x1EF9,
  24253. yturned: 0x028E,
  24254. yuhiragana: 0x3086,
  24255. yuikorean: 0x318C,
  24256. yukatakana: 0x30E6,
  24257. yukatakanahalfwidth: 0xFF95,
  24258. yukorean: 0x3160,
  24259. yusbigcyrillic: 0x046B,
  24260. yusbigiotifiedcyrillic: 0x046D,
  24261. yuslittlecyrillic: 0x0467,
  24262. yuslittleiotifiedcyrillic: 0x0469,
  24263. yusmallhiragana: 0x3085,
  24264. yusmallkatakana: 0x30E5,
  24265. yusmallkatakanahalfwidth: 0xFF6D,
  24266. yuyekorean: 0x318B,
  24267. yuyeokorean: 0x318A,
  24268. yyabengali: 0x09DF,
  24269. yyadeva: 0x095F,
  24270. z: 0x007A,
  24271. zaarmenian: 0x0566,
  24272. zacute: 0x017A,
  24273. zadeva: 0x095B,
  24274. zagurmukhi: 0x0A5B,
  24275. zaharabic: 0x0638,
  24276. zahfinalarabic: 0xFEC6,
  24277. zahinitialarabic: 0xFEC7,
  24278. zahiragana: 0x3056,
  24279. zahmedialarabic: 0xFEC8,
  24280. zainarabic: 0x0632,
  24281. zainfinalarabic: 0xFEB0,
  24282. zakatakana: 0x30B6,
  24283. zaqefgadolhebrew: 0x0595,
  24284. zaqefqatanhebrew: 0x0594,
  24285. zarqahebrew: 0x0598,
  24286. zayin: 0x05D6,
  24287. zayindagesh: 0xFB36,
  24288. zayindageshhebrew: 0xFB36,
  24289. zayinhebrew: 0x05D6,
  24290. zbopomofo: 0x3117,
  24291. zcaron: 0x017E,
  24292. zcircle: 0x24E9,
  24293. zcircumflex: 0x1E91,
  24294. zcurl: 0x0291,
  24295. zdot: 0x017C,
  24296. zdotaccent: 0x017C,
  24297. zdotbelow: 0x1E93,
  24298. zecyrillic: 0x0437,
  24299. zedescendercyrillic: 0x0499,
  24300. zedieresiscyrillic: 0x04DF,
  24301. zehiragana: 0x305C,
  24302. zekatakana: 0x30BC,
  24303. zero: 0x0030,
  24304. zeroarabic: 0x0660,
  24305. zerobengali: 0x09E6,
  24306. zerodeva: 0x0966,
  24307. zerogujarati: 0x0AE6,
  24308. zerogurmukhi: 0x0A66,
  24309. zerohackarabic: 0x0660,
  24310. zeroinferior: 0x2080,
  24311. zeromonospace: 0xFF10,
  24312. zerooldstyle: 0xF730,
  24313. zeropersian: 0x06F0,
  24314. zerosuperior: 0x2070,
  24315. zerothai: 0x0E50,
  24316. zerowidthjoiner: 0xFEFF,
  24317. zerowidthnonjoiner: 0x200C,
  24318. zerowidthspace: 0x200B,
  24319. zeta: 0x03B6,
  24320. zhbopomofo: 0x3113,
  24321. zhearmenian: 0x056A,
  24322. zhebrevecyrillic: 0x04C2,
  24323. zhecyrillic: 0x0436,
  24324. zhedescendercyrillic: 0x0497,
  24325. zhedieresiscyrillic: 0x04DD,
  24326. zihiragana: 0x3058,
  24327. zikatakana: 0x30B8,
  24328. zinorhebrew: 0x05AE,
  24329. zlinebelow: 0x1E95,
  24330. zmonospace: 0xFF5A,
  24331. zohiragana: 0x305E,
  24332. zokatakana: 0x30BE,
  24333. zparen: 0x24B5,
  24334. zretroflexhook: 0x0290,
  24335. zstroke: 0x01B6,
  24336. zuhiragana: 0x305A,
  24337. zukatakana: 0x30BA,
  24338. '.notdef': 0x0000
  24339. };
  24340. var DingbatsGlyphsUnicode = {
  24341. space: 0x0020,
  24342. a1: 0x2701,
  24343. a2: 0x2702,
  24344. a202: 0x2703,
  24345. a3: 0x2704,
  24346. a4: 0x260E,
  24347. a5: 0x2706,
  24348. a119: 0x2707,
  24349. a118: 0x2708,
  24350. a117: 0x2709,
  24351. a11: 0x261B,
  24352. a12: 0x261E,
  24353. a13: 0x270C,
  24354. a14: 0x270D,
  24355. a15: 0x270E,
  24356. a16: 0x270F,
  24357. a105: 0x2710,
  24358. a17: 0x2711,
  24359. a18: 0x2712,
  24360. a19: 0x2713,
  24361. a20: 0x2714,
  24362. a21: 0x2715,
  24363. a22: 0x2716,
  24364. a23: 0x2717,
  24365. a24: 0x2718,
  24366. a25: 0x2719,
  24367. a26: 0x271A,
  24368. a27: 0x271B,
  24369. a28: 0x271C,
  24370. a6: 0x271D,
  24371. a7: 0x271E,
  24372. a8: 0x271F,
  24373. a9: 0x2720,
  24374. a10: 0x2721,
  24375. a29: 0x2722,
  24376. a30: 0x2723,
  24377. a31: 0x2724,
  24378. a32: 0x2725,
  24379. a33: 0x2726,
  24380. a34: 0x2727,
  24381. a35: 0x2605,
  24382. a36: 0x2729,
  24383. a37: 0x272A,
  24384. a38: 0x272B,
  24385. a39: 0x272C,
  24386. a40: 0x272D,
  24387. a41: 0x272E,
  24388. a42: 0x272F,
  24389. a43: 0x2730,
  24390. a44: 0x2731,
  24391. a45: 0x2732,
  24392. a46: 0x2733,
  24393. a47: 0x2734,
  24394. a48: 0x2735,
  24395. a49: 0x2736,
  24396. a50: 0x2737,
  24397. a51: 0x2738,
  24398. a52: 0x2739,
  24399. a53: 0x273A,
  24400. a54: 0x273B,
  24401. a55: 0x273C,
  24402. a56: 0x273D,
  24403. a57: 0x273E,
  24404. a58: 0x273F,
  24405. a59: 0x2740,
  24406. a60: 0x2741,
  24407. a61: 0x2742,
  24408. a62: 0x2743,
  24409. a63: 0x2744,
  24410. a64: 0x2745,
  24411. a65: 0x2746,
  24412. a66: 0x2747,
  24413. a67: 0x2748,
  24414. a68: 0x2749,
  24415. a69: 0x274A,
  24416. a70: 0x274B,
  24417. a71: 0x25CF,
  24418. a72: 0x274D,
  24419. a73: 0x25A0,
  24420. a74: 0x274F,
  24421. a203: 0x2750,
  24422. a75: 0x2751,
  24423. a204: 0x2752,
  24424. a76: 0x25B2,
  24425. a77: 0x25BC,
  24426. a78: 0x25C6,
  24427. a79: 0x2756,
  24428. a81: 0x25D7,
  24429. a82: 0x2758,
  24430. a83: 0x2759,
  24431. a84: 0x275A,
  24432. a97: 0x275B,
  24433. a98: 0x275C,
  24434. a99: 0x275D,
  24435. a100: 0x275E,
  24436. a101: 0x2761,
  24437. a102: 0x2762,
  24438. a103: 0x2763,
  24439. a104: 0x2764,
  24440. a106: 0x2765,
  24441. a107: 0x2766,
  24442. a108: 0x2767,
  24443. a112: 0x2663,
  24444. a111: 0x2666,
  24445. a110: 0x2665,
  24446. a109: 0x2660,
  24447. a120: 0x2460,
  24448. a121: 0x2461,
  24449. a122: 0x2462,
  24450. a123: 0x2463,
  24451. a124: 0x2464,
  24452. a125: 0x2465,
  24453. a126: 0x2466,
  24454. a127: 0x2467,
  24455. a128: 0x2468,
  24456. a129: 0x2469,
  24457. a130: 0x2776,
  24458. a131: 0x2777,
  24459. a132: 0x2778,
  24460. a133: 0x2779,
  24461. a134: 0x277A,
  24462. a135: 0x277B,
  24463. a136: 0x277C,
  24464. a137: 0x277D,
  24465. a138: 0x277E,
  24466. a139: 0x277F,
  24467. a140: 0x2780,
  24468. a141: 0x2781,
  24469. a142: 0x2782,
  24470. a143: 0x2783,
  24471. a144: 0x2784,
  24472. a145: 0x2785,
  24473. a146: 0x2786,
  24474. a147: 0x2787,
  24475. a148: 0x2788,
  24476. a149: 0x2789,
  24477. a150: 0x278A,
  24478. a151: 0x278B,
  24479. a152: 0x278C,
  24480. a153: 0x278D,
  24481. a154: 0x278E,
  24482. a155: 0x278F,
  24483. a156: 0x2790,
  24484. a157: 0x2791,
  24485. a158: 0x2792,
  24486. a159: 0x2793,
  24487. a160: 0x2794,
  24488. a161: 0x2192,
  24489. a163: 0x2194,
  24490. a164: 0x2195,
  24491. a196: 0x2798,
  24492. a165: 0x2799,
  24493. a192: 0x279A,
  24494. a166: 0x279B,
  24495. a167: 0x279C,
  24496. a168: 0x279D,
  24497. a169: 0x279E,
  24498. a170: 0x279F,
  24499. a171: 0x27A0,
  24500. a172: 0x27A1,
  24501. a173: 0x27A2,
  24502. a162: 0x27A3,
  24503. a174: 0x27A4,
  24504. a175: 0x27A5,
  24505. a176: 0x27A6,
  24506. a177: 0x27A7,
  24507. a178: 0x27A8,
  24508. a179: 0x27A9,
  24509. a193: 0x27AA,
  24510. a180: 0x27AB,
  24511. a199: 0x27AC,
  24512. a181: 0x27AD,
  24513. a200: 0x27AE,
  24514. a182: 0x27AF,
  24515. a201: 0x27B1,
  24516. a183: 0x27B2,
  24517. a184: 0x27B3,
  24518. a197: 0x27B4,
  24519. a185: 0x27B5,
  24520. a194: 0x27B6,
  24521. a198: 0x27B7,
  24522. a186: 0x27B8,
  24523. a195: 0x27B9,
  24524. a187: 0x27BA,
  24525. a188: 0x27BB,
  24526. a189: 0x27BC,
  24527. a190: 0x27BD,
  24528. a191: 0x27BE,
  24529. a89: 0x2768, // 0xF8D7
  24530. a90: 0x2769, // 0xF8D8
  24531. a93: 0x276A, // 0xF8D9
  24532. a94: 0x276B, // 0xF8DA
  24533. a91: 0x276C, // 0xF8DB
  24534. a92: 0x276D, // 0xF8DC
  24535. a205: 0x276E, // 0xF8DD
  24536. a85: 0x276F, // 0xF8DE
  24537. a206: 0x2770, // 0xF8DF
  24538. a86: 0x2771, // 0xF8E0
  24539. a87: 0x2772, // 0xF8E1
  24540. a88: 0x2773, // 0xF8E2
  24541. a95: 0x2774, // 0xF8E3
  24542. a96: 0x2775, // 0xF8E4
  24543. '.notdef': 0x0000
  24544. };
  24545. var PDFImage = (function PDFImageClosure() {
  24546. /**
  24547. * Decode the image in the main thread if it supported. Resovles the promise
  24548. * when the image data is ready.
  24549. */
  24550. function handleImageData(handler, xref, res, image) {
  24551. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24552. // For natively supported jpegs send them to the main thread for decoding.
  24553. var dict = image.dict;
  24554. var colorSpace = dict.get('ColorSpace', 'CS');
  24555. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24556. var numComps = colorSpace.numComps;
  24557. var decodePromise = handler.sendWithPromise('JpegDecode',
  24558. [image.getIR(), numComps]);
  24559. return decodePromise.then(function (message) {
  24560. var data = message.data;
  24561. return new Stream(data, 0, data.length, image.dict);
  24562. });
  24563. } else {
  24564. return Promise.resolve(image);
  24565. }
  24566. }
  24567. /**
  24568. * Decode and clamp a value. The formula is different from the spec because we
  24569. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24570. */
  24571. function decodeAndClamp(value, addend, coefficient, max) {
  24572. value = addend + value * coefficient;
  24573. // Clamp the value to the range
  24574. return (value < 0 ? 0 : (value > max ? max : value));
  24575. }
  24576. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24577. this.image = image;
  24578. var dict = image.dict;
  24579. if (dict.has('Filter')) {
  24580. var filter = dict.get('Filter').name;
  24581. if (filter === 'JPXDecode') {
  24582. var jpxImage = new JpxImage();
  24583. jpxImage.parseImageProperties(image.stream);
  24584. image.stream.reset();
  24585. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24586. image.numComps = jpxImage.componentsCount;
  24587. } else if (filter === 'JBIG2Decode') {
  24588. image.bitsPerComponent = 1;
  24589. image.numComps = 1;
  24590. }
  24591. }
  24592. // TODO cache rendered images?
  24593. this.width = dict.get('Width', 'W');
  24594. this.height = dict.get('Height', 'H');
  24595. if (this.width < 1 || this.height < 1) {
  24596. error('Invalid image width: ' + this.width + ' or height: ' +
  24597. this.height);
  24598. }
  24599. this.interpolate = dict.get('Interpolate', 'I') || false;
  24600. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24601. this.matte = dict.get('Matte') || false;
  24602. var bitsPerComponent = image.bitsPerComponent;
  24603. if (!bitsPerComponent) {
  24604. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24605. if (!bitsPerComponent) {
  24606. if (this.imageMask) {
  24607. bitsPerComponent = 1;
  24608. } else {
  24609. error('Bits per component missing in image: ' + this.imageMask);
  24610. }
  24611. }
  24612. }
  24613. this.bpc = bitsPerComponent;
  24614. if (!this.imageMask) {
  24615. var colorSpace = dict.get('ColorSpace', 'CS');
  24616. if (!colorSpace) {
  24617. info('JPX images (which do not require color spaces)');
  24618. switch (image.numComps) {
  24619. case 1:
  24620. colorSpace = Name.get('DeviceGray');
  24621. break;
  24622. case 3:
  24623. colorSpace = Name.get('DeviceRGB');
  24624. break;
  24625. case 4:
  24626. colorSpace = Name.get('DeviceCMYK');
  24627. break;
  24628. default:
  24629. error('JPX images with ' + this.numComps +
  24630. ' color components not supported.');
  24631. }
  24632. }
  24633. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24634. this.numComps = this.colorSpace.numComps;
  24635. }
  24636. this.decode = dict.get('Decode', 'D');
  24637. this.needsDecode = false;
  24638. if (this.decode &&
  24639. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24640. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24641. this.needsDecode = true;
  24642. // Do some preprocessing to avoid more math.
  24643. var max = (1 << bitsPerComponent) - 1;
  24644. this.decodeCoefficients = [];
  24645. this.decodeAddends = [];
  24646. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24647. var dmin = this.decode[i];
  24648. var dmax = this.decode[i + 1];
  24649. this.decodeCoefficients[j] = dmax - dmin;
  24650. this.decodeAddends[j] = max * dmin;
  24651. }
  24652. }
  24653. if (smask) {
  24654. this.smask = new PDFImage(xref, res, smask, false);
  24655. } else if (mask) {
  24656. if (isStream(mask)) {
  24657. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24658. } else {
  24659. // Color key mask (just an array).
  24660. this.mask = mask;
  24661. }
  24662. }
  24663. }
  24664. /**
  24665. * Handles processing of image data and returns the Promise that is resolved
  24666. * with a PDFImage when the image is ready to be used.
  24667. */
  24668. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24669. res, image, inline) {
  24670. var imagePromise = handleImageData(handler, xref, res, image);
  24671. var smaskPromise;
  24672. var maskPromise;
  24673. var smask = image.dict.get('SMask');
  24674. var mask = image.dict.get('Mask');
  24675. if (smask) {
  24676. smaskPromise = handleImageData(handler, xref, res, smask);
  24677. maskPromise = Promise.resolve(null);
  24678. } else {
  24679. smaskPromise = Promise.resolve(null);
  24680. if (mask) {
  24681. if (isStream(mask)) {
  24682. maskPromise = handleImageData(handler, xref, res, mask);
  24683. } else if (isArray(mask)) {
  24684. maskPromise = Promise.resolve(mask);
  24685. } else {
  24686. warn('Unsupported mask format.');
  24687. maskPromise = Promise.resolve(null);
  24688. }
  24689. } else {
  24690. maskPromise = Promise.resolve(null);
  24691. }
  24692. }
  24693. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24694. function(results) {
  24695. var imageData = results[0];
  24696. var smaskData = results[1];
  24697. var maskData = results[2];
  24698. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24699. });
  24700. };
  24701. /**
  24702. * Resize an image using the nearest neighbor algorithm. Currently only
  24703. * supports one and three component images.
  24704. * @param {TypedArray} pixels The original image with one component.
  24705. * @param {Number} bpc Number of bits per component.
  24706. * @param {Number} components Number of color components, 1 or 3 is supported.
  24707. * @param {Number} w1 Original width.
  24708. * @param {Number} h1 Original height.
  24709. * @param {Number} w2 New width.
  24710. * @param {Number} h2 New height.
  24711. * @param {TypedArray} dest (Optional) The destination buffer.
  24712. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24713. * @return {TypedArray} Resized image data.
  24714. */
  24715. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24716. w1, h1, w2, h2, dest, alpha01) {
  24717. if (components !== 1 && components !== 3) {
  24718. error('Unsupported component count for resizing.');
  24719. }
  24720. var length = w2 * h2 * components;
  24721. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24722. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24723. var xRatio = w1 / w2;
  24724. var yRatio = h1 / h2;
  24725. var i, j, py, newIndex = 0, oldIndex;
  24726. var xScaled = new Uint16Array(w2);
  24727. var w1Scanline = w1 * components;
  24728. if (alpha01 !== 1) {
  24729. alpha01 = 0;
  24730. }
  24731. for (j = 0; j < w2; j++) {
  24732. xScaled[j] = Math.floor(j * xRatio) * components;
  24733. }
  24734. if (components === 1) {
  24735. for (i = 0; i < h2; i++) {
  24736. py = Math.floor(i * yRatio) * w1Scanline;
  24737. for (j = 0; j < w2; j++) {
  24738. oldIndex = py + xScaled[j];
  24739. temp[newIndex++] = pixels[oldIndex];
  24740. }
  24741. }
  24742. } else if (components === 3) {
  24743. for (i = 0; i < h2; i++) {
  24744. py = Math.floor(i * yRatio) * w1Scanline;
  24745. for (j = 0; j < w2; j++) {
  24746. oldIndex = py + xScaled[j];
  24747. temp[newIndex++] = pixels[oldIndex++];
  24748. temp[newIndex++] = pixels[oldIndex++];
  24749. temp[newIndex++] = pixels[oldIndex++];
  24750. newIndex += alpha01;
  24751. }
  24752. }
  24753. }
  24754. return temp;
  24755. };
  24756. PDFImage.createMask =
  24757. function PDFImage_createMask(imgArray, width, height,
  24758. imageIsFromDecodeStream, inverseDecode) {
  24759. // |imgArray| might not contain full data for every pixel of the mask, so
  24760. // we need to distinguish between |computedLength| and |actualLength|.
  24761. // In particular, if inverseDecode is true, then the array we return must
  24762. // have a length of |computedLength|.
  24763. var computedLength = ((width + 7) >> 3) * height;
  24764. var actualLength = imgArray.byteLength;
  24765. var haveFullData = computedLength === actualLength;
  24766. var data, i;
  24767. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24768. // imgArray came from a DecodeStream and its data is in an appropriate
  24769. // form, so we can just transfer it.
  24770. data = imgArray;
  24771. } else if (!inverseDecode) {
  24772. data = new Uint8Array(actualLength);
  24773. data.set(imgArray);
  24774. } else {
  24775. data = new Uint8Array(computedLength);
  24776. data.set(imgArray);
  24777. for (i = actualLength; i < computedLength; i++) {
  24778. data[i] = 0xff;
  24779. }
  24780. }
  24781. // If necessary, invert the original mask data (but not any extra we might
  24782. // have added above). It's safe to modify the array -- whether it's the
  24783. // original or a copy, we're about to transfer it anyway, so nothing else
  24784. // in this thread can be relying on its contents.
  24785. if (inverseDecode) {
  24786. for (i = 0; i < actualLength; i++) {
  24787. data[i] = ~data[i];
  24788. }
  24789. }
  24790. return {data: data, width: width, height: height};
  24791. };
  24792. PDFImage.prototype = {
  24793. get drawWidth() {
  24794. return Math.max(this.width,
  24795. this.smask && this.smask.width || 0,
  24796. this.mask && this.mask.width || 0);
  24797. },
  24798. get drawHeight() {
  24799. return Math.max(this.height,
  24800. this.smask && this.smask.height || 0,
  24801. this.mask && this.mask.height || 0);
  24802. },
  24803. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24804. var bpc = this.bpc;
  24805. var numComps = this.numComps;
  24806. var decodeAddends = this.decodeAddends;
  24807. var decodeCoefficients = this.decodeCoefficients;
  24808. var max = (1 << bpc) - 1;
  24809. var i, ii;
  24810. if (bpc === 1) {
  24811. // If the buffer needed decode that means it just needs to be inverted.
  24812. for (i = 0, ii = buffer.length; i < ii; i++) {
  24813. buffer[i] = +!(buffer[i]);
  24814. }
  24815. return;
  24816. }
  24817. var index = 0;
  24818. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24819. for (var j = 0; j < numComps; j++) {
  24820. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24821. decodeCoefficients[j], max);
  24822. index++;
  24823. }
  24824. }
  24825. },
  24826. getComponents: function PDFImage_getComponents(buffer) {
  24827. var bpc = this.bpc;
  24828. // This image doesn't require any extra work.
  24829. if (bpc === 8) {
  24830. return buffer;
  24831. }
  24832. var width = this.width;
  24833. var height = this.height;
  24834. var numComps = this.numComps;
  24835. var length = width * height * numComps;
  24836. var bufferPos = 0;
  24837. var output = (bpc <= 8 ? new Uint8Array(length) :
  24838. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24839. var rowComps = width * numComps;
  24840. var max = (1 << bpc) - 1;
  24841. var i = 0, ii, buf;
  24842. if (bpc === 1) {
  24843. // Optimization for reading 1 bpc images.
  24844. var mask, loop1End, loop2End;
  24845. for (var j = 0; j < height; j++) {
  24846. loop1End = i + (rowComps & ~7);
  24847. loop2End = i + rowComps;
  24848. // unroll loop for all full bytes
  24849. while (i < loop1End) {
  24850. buf = buffer[bufferPos++];
  24851. output[i] = (buf >> 7) & 1;
  24852. output[i + 1] = (buf >> 6) & 1;
  24853. output[i + 2] = (buf >> 5) & 1;
  24854. output[i + 3] = (buf >> 4) & 1;
  24855. output[i + 4] = (buf >> 3) & 1;
  24856. output[i + 5] = (buf >> 2) & 1;
  24857. output[i + 6] = (buf >> 1) & 1;
  24858. output[i + 7] = buf & 1;
  24859. i += 8;
  24860. }
  24861. // handle remaing bits
  24862. if (i < loop2End) {
  24863. buf = buffer[bufferPos++];
  24864. mask = 128;
  24865. while (i < loop2End) {
  24866. output[i++] = +!!(buf & mask);
  24867. mask >>= 1;
  24868. }
  24869. }
  24870. }
  24871. } else {
  24872. // The general case that handles all other bpc values.
  24873. var bits = 0;
  24874. buf = 0;
  24875. for (i = 0, ii = length; i < ii; ++i) {
  24876. if (i % rowComps === 0) {
  24877. buf = 0;
  24878. bits = 0;
  24879. }
  24880. while (bits < bpc) {
  24881. buf = (buf << 8) | buffer[bufferPos++];
  24882. bits += 8;
  24883. }
  24884. var remainingBits = bits - bpc;
  24885. var value = buf >> remainingBits;
  24886. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  24887. buf = buf & ((1 << remainingBits) - 1);
  24888. bits = remainingBits;
  24889. }
  24890. }
  24891. return output;
  24892. },
  24893. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  24894. actualHeight, image) {
  24895. var smask = this.smask;
  24896. var mask = this.mask;
  24897. var alphaBuf, sw, sh, i, ii, j;
  24898. if (smask) {
  24899. sw = smask.width;
  24900. sh = smask.height;
  24901. alphaBuf = new Uint8Array(sw * sh);
  24902. smask.fillGrayBuffer(alphaBuf);
  24903. if (sw !== width || sh !== height) {
  24904. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  24905. height);
  24906. }
  24907. } else if (mask) {
  24908. if (mask instanceof PDFImage) {
  24909. sw = mask.width;
  24910. sh = mask.height;
  24911. alphaBuf = new Uint8Array(sw * sh);
  24912. mask.numComps = 1;
  24913. mask.fillGrayBuffer(alphaBuf);
  24914. // Need to invert values in rgbaBuf
  24915. for (i = 0, ii = sw * sh; i < ii; ++i) {
  24916. alphaBuf[i] = 255 - alphaBuf[i];
  24917. }
  24918. if (sw !== width || sh !== height) {
  24919. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  24920. height);
  24921. }
  24922. } else if (isArray(mask)) {
  24923. // Color key mask: if any of the compontents are outside the range
  24924. // then they should be painted.
  24925. alphaBuf = new Uint8Array(width * height);
  24926. var numComps = this.numComps;
  24927. for (i = 0, ii = width * height; i < ii; ++i) {
  24928. var opacity = 0;
  24929. var imageOffset = i * numComps;
  24930. for (j = 0; j < numComps; ++j) {
  24931. var color = image[imageOffset + j];
  24932. var maskOffset = j * 2;
  24933. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  24934. opacity = 255;
  24935. break;
  24936. }
  24937. }
  24938. alphaBuf[i] = opacity;
  24939. }
  24940. } else {
  24941. error('Unknown mask format.');
  24942. }
  24943. }
  24944. if (alphaBuf) {
  24945. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24946. rgbaBuf[j] = alphaBuf[i];
  24947. }
  24948. } else {
  24949. // No mask.
  24950. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24951. rgbaBuf[j] = 255;
  24952. }
  24953. }
  24954. },
  24955. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  24956. var matte = this.smask && this.smask.matte;
  24957. if (!matte) {
  24958. return;
  24959. }
  24960. var matteRgb = this.colorSpace.getRgb(matte, 0);
  24961. var matteR = matteRgb[0];
  24962. var matteG = matteRgb[1];
  24963. var matteB = matteRgb[2];
  24964. var length = width * height * 4;
  24965. var r, g, b;
  24966. for (var i = 0; i < length; i += 4) {
  24967. var alpha = buffer[i + 3];
  24968. if (alpha === 0) {
  24969. // according formula we have to get Infinity in all components
  24970. // making it white (typical paper color) should be okay
  24971. buffer[i] = 255;
  24972. buffer[i + 1] = 255;
  24973. buffer[i + 2] = 255;
  24974. continue;
  24975. }
  24976. var k = 255 / alpha;
  24977. r = (buffer[i] - matteR) * k + matteR;
  24978. g = (buffer[i + 1] - matteG) * k + matteG;
  24979. b = (buffer[i + 2] - matteB) * k + matteB;
  24980. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  24981. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  24982. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  24983. }
  24984. },
  24985. createImageData: function PDFImage_createImageData(forceRGBA) {
  24986. var drawWidth = this.drawWidth;
  24987. var drawHeight = this.drawHeight;
  24988. var imgData = { // other fields are filled in below
  24989. width: drawWidth,
  24990. height: drawHeight
  24991. };
  24992. var numComps = this.numComps;
  24993. var originalWidth = this.width;
  24994. var originalHeight = this.height;
  24995. var bpc = this.bpc;
  24996. // Rows start at byte boundary.
  24997. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  24998. var imgArray;
  24999. if (!forceRGBA) {
  25000. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25001. // without any complications, we pass a same-sized copy to the main
  25002. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25003. // of memory for many scanned documents. It's also much faster.
  25004. //
  25005. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25006. // complications, we avoid expanding by 1.333x to RGBA form.
  25007. var kind;
  25008. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25009. kind = ImageKind.GRAYSCALE_1BPP;
  25010. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25011. !this.needsDecode) {
  25012. kind = ImageKind.RGB_24BPP;
  25013. }
  25014. if (kind && !this.smask && !this.mask &&
  25015. drawWidth === originalWidth && drawHeight === originalHeight) {
  25016. imgData.kind = kind;
  25017. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25018. // If imgArray came from a DecodeStream, we're safe to transfer it
  25019. // (and thus neuter it) because it will constitute the entire
  25020. // DecodeStream's data. But if it came from a Stream, we need to
  25021. // copy it because it'll only be a portion of the Stream's data, and
  25022. // the rest will be read later on.
  25023. if (this.image instanceof DecodeStream) {
  25024. imgData.data = imgArray;
  25025. } else {
  25026. var newArray = new Uint8Array(imgArray.length);
  25027. newArray.set(imgArray);
  25028. imgData.data = newArray;
  25029. }
  25030. if (this.needsDecode) {
  25031. // Invert the buffer (which must be grayscale if we reached here).
  25032. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25033. var buffer = imgData.data;
  25034. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25035. buffer[i] ^= 0xff;
  25036. }
  25037. }
  25038. return imgData;
  25039. }
  25040. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25041. imgData.kind = ImageKind.RGB_24BPP;
  25042. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25043. drawWidth, drawHeight, true);
  25044. return imgData;
  25045. }
  25046. }
  25047. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25048. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25049. var actualHeight = 0 | (imgArray.length / rowBytes *
  25050. drawHeight / originalHeight);
  25051. var comps = this.getComponents(imgArray);
  25052. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25053. // more compact RGB_24BPP form if allowable.
  25054. var alpha01, maybeUndoPreblend;
  25055. if (!forceRGBA && !this.smask && !this.mask) {
  25056. imgData.kind = ImageKind.RGB_24BPP;
  25057. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25058. alpha01 = 0;
  25059. maybeUndoPreblend = false;
  25060. } else {
  25061. imgData.kind = ImageKind.RGBA_32BPP;
  25062. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25063. alpha01 = 1;
  25064. maybeUndoPreblend = true;
  25065. // Color key masking (opacity) must be performed before decoding.
  25066. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25067. comps);
  25068. }
  25069. if (this.needsDecode) {
  25070. this.decodeBuffer(comps);
  25071. }
  25072. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25073. drawWidth, drawHeight, actualHeight, bpc, comps,
  25074. alpha01);
  25075. if (maybeUndoPreblend) {
  25076. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25077. }
  25078. return imgData;
  25079. },
  25080. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25081. var numComps = this.numComps;
  25082. if (numComps !== 1) {
  25083. error('Reading gray scale from a color image: ' + numComps);
  25084. }
  25085. var width = this.width;
  25086. var height = this.height;
  25087. var bpc = this.bpc;
  25088. // rows start at byte boundary
  25089. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25090. var imgArray = this.getImageBytes(height * rowBytes);
  25091. var comps = this.getComponents(imgArray);
  25092. var i, length;
  25093. if (bpc === 1) {
  25094. // inline decoding (= inversion) for 1 bpc images
  25095. length = width * height;
  25096. if (this.needsDecode) {
  25097. // invert and scale to {0, 255}
  25098. for (i = 0; i < length; ++i) {
  25099. buffer[i] = (comps[i] - 1) & 255;
  25100. }
  25101. } else {
  25102. // scale to {0, 255}
  25103. for (i = 0; i < length; ++i) {
  25104. buffer[i] = (-comps[i]) & 255;
  25105. }
  25106. }
  25107. return;
  25108. }
  25109. if (this.needsDecode) {
  25110. this.decodeBuffer(comps);
  25111. }
  25112. length = width * height;
  25113. // we aren't using a colorspace so we need to scale the value
  25114. var scale = 255 / ((1 << bpc) - 1);
  25115. for (i = 0; i < length; ++i) {
  25116. buffer[i] = (scale * comps[i]) | 0;
  25117. }
  25118. },
  25119. getImageBytes: function PDFImage_getImageBytes(length,
  25120. drawWidth, drawHeight,
  25121. forceRGB) {
  25122. this.image.reset();
  25123. this.image.drawWidth = drawWidth || this.width;
  25124. this.image.drawHeight = drawHeight || this.height;
  25125. this.image.forceRGB = !!forceRGB;
  25126. return this.image.getBytes(length);
  25127. }
  25128. };
  25129. return PDFImage;
  25130. })();
  25131. // The Metrics object contains glyph widths (in glyph space units).
  25132. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25133. // space unit corresponds to 1/1000th of text space unit.
  25134. var Metrics = {
  25135. 'Courier': 600,
  25136. 'Courier-Bold': 600,
  25137. 'Courier-BoldOblique': 600,
  25138. 'Courier-Oblique': 600,
  25139. 'Helvetica' : {
  25140. 'space': 278,
  25141. 'exclam': 278,
  25142. 'quotedbl': 355,
  25143. 'numbersign': 556,
  25144. 'dollar': 556,
  25145. 'percent': 889,
  25146. 'ampersand': 667,
  25147. 'quoteright': 222,
  25148. 'parenleft': 333,
  25149. 'parenright': 333,
  25150. 'asterisk': 389,
  25151. 'plus': 584,
  25152. 'comma': 278,
  25153. 'hyphen': 333,
  25154. 'period': 278,
  25155. 'slash': 278,
  25156. 'zero': 556,
  25157. 'one': 556,
  25158. 'two': 556,
  25159. 'three': 556,
  25160. 'four': 556,
  25161. 'five': 556,
  25162. 'six': 556,
  25163. 'seven': 556,
  25164. 'eight': 556,
  25165. 'nine': 556,
  25166. 'colon': 278,
  25167. 'semicolon': 278,
  25168. 'less': 584,
  25169. 'equal': 584,
  25170. 'greater': 584,
  25171. 'question': 556,
  25172. 'at': 1015,
  25173. 'A': 667,
  25174. 'B': 667,
  25175. 'C': 722,
  25176. 'D': 722,
  25177. 'E': 667,
  25178. 'F': 611,
  25179. 'G': 778,
  25180. 'H': 722,
  25181. 'I': 278,
  25182. 'J': 500,
  25183. 'K': 667,
  25184. 'L': 556,
  25185. 'M': 833,
  25186. 'N': 722,
  25187. 'O': 778,
  25188. 'P': 667,
  25189. 'Q': 778,
  25190. 'R': 722,
  25191. 'S': 667,
  25192. 'T': 611,
  25193. 'U': 722,
  25194. 'V': 667,
  25195. 'W': 944,
  25196. 'X': 667,
  25197. 'Y': 667,
  25198. 'Z': 611,
  25199. 'bracketleft': 278,
  25200. 'backslash': 278,
  25201. 'bracketright': 278,
  25202. 'asciicircum': 469,
  25203. 'underscore': 556,
  25204. 'quoteleft': 222,
  25205. 'a': 556,
  25206. 'b': 556,
  25207. 'c': 500,
  25208. 'd': 556,
  25209. 'e': 556,
  25210. 'f': 278,
  25211. 'g': 556,
  25212. 'h': 556,
  25213. 'i': 222,
  25214. 'j': 222,
  25215. 'k': 500,
  25216. 'l': 222,
  25217. 'm': 833,
  25218. 'n': 556,
  25219. 'o': 556,
  25220. 'p': 556,
  25221. 'q': 556,
  25222. 'r': 333,
  25223. 's': 500,
  25224. 't': 278,
  25225. 'u': 556,
  25226. 'v': 500,
  25227. 'w': 722,
  25228. 'x': 500,
  25229. 'y': 500,
  25230. 'z': 500,
  25231. 'braceleft': 334,
  25232. 'bar': 260,
  25233. 'braceright': 334,
  25234. 'asciitilde': 584,
  25235. 'exclamdown': 333,
  25236. 'cent': 556,
  25237. 'sterling': 556,
  25238. 'fraction': 167,
  25239. 'yen': 556,
  25240. 'florin': 556,
  25241. 'section': 556,
  25242. 'currency': 556,
  25243. 'quotesingle': 191,
  25244. 'quotedblleft': 333,
  25245. 'guillemotleft': 556,
  25246. 'guilsinglleft': 333,
  25247. 'guilsinglright': 333,
  25248. 'fi': 500,
  25249. 'fl': 500,
  25250. 'endash': 556,
  25251. 'dagger': 556,
  25252. 'daggerdbl': 556,
  25253. 'periodcentered': 278,
  25254. 'paragraph': 537,
  25255. 'bullet': 350,
  25256. 'quotesinglbase': 222,
  25257. 'quotedblbase': 333,
  25258. 'quotedblright': 333,
  25259. 'guillemotright': 556,
  25260. 'ellipsis': 1000,
  25261. 'perthousand': 1000,
  25262. 'questiondown': 611,
  25263. 'grave': 333,
  25264. 'acute': 333,
  25265. 'circumflex': 333,
  25266. 'tilde': 333,
  25267. 'macron': 333,
  25268. 'breve': 333,
  25269. 'dotaccent': 333,
  25270. 'dieresis': 333,
  25271. 'ring': 333,
  25272. 'cedilla': 333,
  25273. 'hungarumlaut': 333,
  25274. 'ogonek': 333,
  25275. 'caron': 333,
  25276. 'emdash': 1000,
  25277. 'AE': 1000,
  25278. 'ordfeminine': 370,
  25279. 'Lslash': 556,
  25280. 'Oslash': 778,
  25281. 'OE': 1000,
  25282. 'ordmasculine': 365,
  25283. 'ae': 889,
  25284. 'dotlessi': 278,
  25285. 'lslash': 222,
  25286. 'oslash': 611,
  25287. 'oe': 944,
  25288. 'germandbls': 611,
  25289. 'Idieresis': 278,
  25290. 'eacute': 556,
  25291. 'abreve': 556,
  25292. 'uhungarumlaut': 556,
  25293. 'ecaron': 556,
  25294. 'Ydieresis': 667,
  25295. 'divide': 584,
  25296. 'Yacute': 667,
  25297. 'Acircumflex': 667,
  25298. 'aacute': 556,
  25299. 'Ucircumflex': 722,
  25300. 'yacute': 500,
  25301. 'scommaaccent': 500,
  25302. 'ecircumflex': 556,
  25303. 'Uring': 722,
  25304. 'Udieresis': 722,
  25305. 'aogonek': 556,
  25306. 'Uacute': 722,
  25307. 'uogonek': 556,
  25308. 'Edieresis': 667,
  25309. 'Dcroat': 722,
  25310. 'commaaccent': 250,
  25311. 'copyright': 737,
  25312. 'Emacron': 667,
  25313. 'ccaron': 500,
  25314. 'aring': 556,
  25315. 'Ncommaaccent': 722,
  25316. 'lacute': 222,
  25317. 'agrave': 556,
  25318. 'Tcommaaccent': 611,
  25319. 'Cacute': 722,
  25320. 'atilde': 556,
  25321. 'Edotaccent': 667,
  25322. 'scaron': 500,
  25323. 'scedilla': 500,
  25324. 'iacute': 278,
  25325. 'lozenge': 471,
  25326. 'Rcaron': 722,
  25327. 'Gcommaaccent': 778,
  25328. 'ucircumflex': 556,
  25329. 'acircumflex': 556,
  25330. 'Amacron': 667,
  25331. 'rcaron': 333,
  25332. 'ccedilla': 500,
  25333. 'Zdotaccent': 611,
  25334. 'Thorn': 667,
  25335. 'Omacron': 778,
  25336. 'Racute': 722,
  25337. 'Sacute': 667,
  25338. 'dcaron': 643,
  25339. 'Umacron': 722,
  25340. 'uring': 556,
  25341. 'threesuperior': 333,
  25342. 'Ograve': 778,
  25343. 'Agrave': 667,
  25344. 'Abreve': 667,
  25345. 'multiply': 584,
  25346. 'uacute': 556,
  25347. 'Tcaron': 611,
  25348. 'partialdiff': 476,
  25349. 'ydieresis': 500,
  25350. 'Nacute': 722,
  25351. 'icircumflex': 278,
  25352. 'Ecircumflex': 667,
  25353. 'adieresis': 556,
  25354. 'edieresis': 556,
  25355. 'cacute': 500,
  25356. 'nacute': 556,
  25357. 'umacron': 556,
  25358. 'Ncaron': 722,
  25359. 'Iacute': 278,
  25360. 'plusminus': 584,
  25361. 'brokenbar': 260,
  25362. 'registered': 737,
  25363. 'Gbreve': 778,
  25364. 'Idotaccent': 278,
  25365. 'summation': 600,
  25366. 'Egrave': 667,
  25367. 'racute': 333,
  25368. 'omacron': 556,
  25369. 'Zacute': 611,
  25370. 'Zcaron': 611,
  25371. 'greaterequal': 549,
  25372. 'Eth': 722,
  25373. 'Ccedilla': 722,
  25374. 'lcommaaccent': 222,
  25375. 'tcaron': 317,
  25376. 'eogonek': 556,
  25377. 'Uogonek': 722,
  25378. 'Aacute': 667,
  25379. 'Adieresis': 667,
  25380. 'egrave': 556,
  25381. 'zacute': 500,
  25382. 'iogonek': 222,
  25383. 'Oacute': 778,
  25384. 'oacute': 556,
  25385. 'amacron': 556,
  25386. 'sacute': 500,
  25387. 'idieresis': 278,
  25388. 'Ocircumflex': 778,
  25389. 'Ugrave': 722,
  25390. 'Delta': 612,
  25391. 'thorn': 556,
  25392. 'twosuperior': 333,
  25393. 'Odieresis': 778,
  25394. 'mu': 556,
  25395. 'igrave': 278,
  25396. 'ohungarumlaut': 556,
  25397. 'Eogonek': 667,
  25398. 'dcroat': 556,
  25399. 'threequarters': 834,
  25400. 'Scedilla': 667,
  25401. 'lcaron': 299,
  25402. 'Kcommaaccent': 667,
  25403. 'Lacute': 556,
  25404. 'trademark': 1000,
  25405. 'edotaccent': 556,
  25406. 'Igrave': 278,
  25407. 'Imacron': 278,
  25408. 'Lcaron': 556,
  25409. 'onehalf': 834,
  25410. 'lessequal': 549,
  25411. 'ocircumflex': 556,
  25412. 'ntilde': 556,
  25413. 'Uhungarumlaut': 722,
  25414. 'Eacute': 667,
  25415. 'emacron': 556,
  25416. 'gbreve': 556,
  25417. 'onequarter': 834,
  25418. 'Scaron': 667,
  25419. 'Scommaaccent': 667,
  25420. 'Ohungarumlaut': 778,
  25421. 'degree': 400,
  25422. 'ograve': 556,
  25423. 'Ccaron': 722,
  25424. 'ugrave': 556,
  25425. 'radical': 453,
  25426. 'Dcaron': 722,
  25427. 'rcommaaccent': 333,
  25428. 'Ntilde': 722,
  25429. 'otilde': 556,
  25430. 'Rcommaaccent': 722,
  25431. 'Lcommaaccent': 556,
  25432. 'Atilde': 667,
  25433. 'Aogonek': 667,
  25434. 'Aring': 667,
  25435. 'Otilde': 778,
  25436. 'zdotaccent': 500,
  25437. 'Ecaron': 667,
  25438. 'Iogonek': 278,
  25439. 'kcommaaccent': 500,
  25440. 'minus': 584,
  25441. 'Icircumflex': 278,
  25442. 'ncaron': 556,
  25443. 'tcommaaccent': 278,
  25444. 'logicalnot': 584,
  25445. 'odieresis': 556,
  25446. 'udieresis': 556,
  25447. 'notequal': 549,
  25448. 'gcommaaccent': 556,
  25449. 'eth': 556,
  25450. 'zcaron': 500,
  25451. 'ncommaaccent': 556,
  25452. 'onesuperior': 333,
  25453. 'imacron': 278,
  25454. 'Euro': 556
  25455. },
  25456. 'Helvetica-Bold': {
  25457. 'space': 278,
  25458. 'exclam': 333,
  25459. 'quotedbl': 474,
  25460. 'numbersign': 556,
  25461. 'dollar': 556,
  25462. 'percent': 889,
  25463. 'ampersand': 722,
  25464. 'quoteright': 278,
  25465. 'parenleft': 333,
  25466. 'parenright': 333,
  25467. 'asterisk': 389,
  25468. 'plus': 584,
  25469. 'comma': 278,
  25470. 'hyphen': 333,
  25471. 'period': 278,
  25472. 'slash': 278,
  25473. 'zero': 556,
  25474. 'one': 556,
  25475. 'two': 556,
  25476. 'three': 556,
  25477. 'four': 556,
  25478. 'five': 556,
  25479. 'six': 556,
  25480. 'seven': 556,
  25481. 'eight': 556,
  25482. 'nine': 556,
  25483. 'colon': 333,
  25484. 'semicolon': 333,
  25485. 'less': 584,
  25486. 'equal': 584,
  25487. 'greater': 584,
  25488. 'question': 611,
  25489. 'at': 975,
  25490. 'A': 722,
  25491. 'B': 722,
  25492. 'C': 722,
  25493. 'D': 722,
  25494. 'E': 667,
  25495. 'F': 611,
  25496. 'G': 778,
  25497. 'H': 722,
  25498. 'I': 278,
  25499. 'J': 556,
  25500. 'K': 722,
  25501. 'L': 611,
  25502. 'M': 833,
  25503. 'N': 722,
  25504. 'O': 778,
  25505. 'P': 667,
  25506. 'Q': 778,
  25507. 'R': 722,
  25508. 'S': 667,
  25509. 'T': 611,
  25510. 'U': 722,
  25511. 'V': 667,
  25512. 'W': 944,
  25513. 'X': 667,
  25514. 'Y': 667,
  25515. 'Z': 611,
  25516. 'bracketleft': 333,
  25517. 'backslash': 278,
  25518. 'bracketright': 333,
  25519. 'asciicircum': 584,
  25520. 'underscore': 556,
  25521. 'quoteleft': 278,
  25522. 'a': 556,
  25523. 'b': 611,
  25524. 'c': 556,
  25525. 'd': 611,
  25526. 'e': 556,
  25527. 'f': 333,
  25528. 'g': 611,
  25529. 'h': 611,
  25530. 'i': 278,
  25531. 'j': 278,
  25532. 'k': 556,
  25533. 'l': 278,
  25534. 'm': 889,
  25535. 'n': 611,
  25536. 'o': 611,
  25537. 'p': 611,
  25538. 'q': 611,
  25539. 'r': 389,
  25540. 's': 556,
  25541. 't': 333,
  25542. 'u': 611,
  25543. 'v': 556,
  25544. 'w': 778,
  25545. 'x': 556,
  25546. 'y': 556,
  25547. 'z': 500,
  25548. 'braceleft': 389,
  25549. 'bar': 280,
  25550. 'braceright': 389,
  25551. 'asciitilde': 584,
  25552. 'exclamdown': 333,
  25553. 'cent': 556,
  25554. 'sterling': 556,
  25555. 'fraction': 167,
  25556. 'yen': 556,
  25557. 'florin': 556,
  25558. 'section': 556,
  25559. 'currency': 556,
  25560. 'quotesingle': 238,
  25561. 'quotedblleft': 500,
  25562. 'guillemotleft': 556,
  25563. 'guilsinglleft': 333,
  25564. 'guilsinglright': 333,
  25565. 'fi': 611,
  25566. 'fl': 611,
  25567. 'endash': 556,
  25568. 'dagger': 556,
  25569. 'daggerdbl': 556,
  25570. 'periodcentered': 278,
  25571. 'paragraph': 556,
  25572. 'bullet': 350,
  25573. 'quotesinglbase': 278,
  25574. 'quotedblbase': 500,
  25575. 'quotedblright': 500,
  25576. 'guillemotright': 556,
  25577. 'ellipsis': 1000,
  25578. 'perthousand': 1000,
  25579. 'questiondown': 611,
  25580. 'grave': 333,
  25581. 'acute': 333,
  25582. 'circumflex': 333,
  25583. 'tilde': 333,
  25584. 'macron': 333,
  25585. 'breve': 333,
  25586. 'dotaccent': 333,
  25587. 'dieresis': 333,
  25588. 'ring': 333,
  25589. 'cedilla': 333,
  25590. 'hungarumlaut': 333,
  25591. 'ogonek': 333,
  25592. 'caron': 333,
  25593. 'emdash': 1000,
  25594. 'AE': 1000,
  25595. 'ordfeminine': 370,
  25596. 'Lslash': 611,
  25597. 'Oslash': 778,
  25598. 'OE': 1000,
  25599. 'ordmasculine': 365,
  25600. 'ae': 889,
  25601. 'dotlessi': 278,
  25602. 'lslash': 278,
  25603. 'oslash': 611,
  25604. 'oe': 944,
  25605. 'germandbls': 611,
  25606. 'Idieresis': 278,
  25607. 'eacute': 556,
  25608. 'abreve': 556,
  25609. 'uhungarumlaut': 611,
  25610. 'ecaron': 556,
  25611. 'Ydieresis': 667,
  25612. 'divide': 584,
  25613. 'Yacute': 667,
  25614. 'Acircumflex': 722,
  25615. 'aacute': 556,
  25616. 'Ucircumflex': 722,
  25617. 'yacute': 556,
  25618. 'scommaaccent': 556,
  25619. 'ecircumflex': 556,
  25620. 'Uring': 722,
  25621. 'Udieresis': 722,
  25622. 'aogonek': 556,
  25623. 'Uacute': 722,
  25624. 'uogonek': 611,
  25625. 'Edieresis': 667,
  25626. 'Dcroat': 722,
  25627. 'commaaccent': 250,
  25628. 'copyright': 737,
  25629. 'Emacron': 667,
  25630. 'ccaron': 556,
  25631. 'aring': 556,
  25632. 'Ncommaaccent': 722,
  25633. 'lacute': 278,
  25634. 'agrave': 556,
  25635. 'Tcommaaccent': 611,
  25636. 'Cacute': 722,
  25637. 'atilde': 556,
  25638. 'Edotaccent': 667,
  25639. 'scaron': 556,
  25640. 'scedilla': 556,
  25641. 'iacute': 278,
  25642. 'lozenge': 494,
  25643. 'Rcaron': 722,
  25644. 'Gcommaaccent': 778,
  25645. 'ucircumflex': 611,
  25646. 'acircumflex': 556,
  25647. 'Amacron': 722,
  25648. 'rcaron': 389,
  25649. 'ccedilla': 556,
  25650. 'Zdotaccent': 611,
  25651. 'Thorn': 667,
  25652. 'Omacron': 778,
  25653. 'Racute': 722,
  25654. 'Sacute': 667,
  25655. 'dcaron': 743,
  25656. 'Umacron': 722,
  25657. 'uring': 611,
  25658. 'threesuperior': 333,
  25659. 'Ograve': 778,
  25660. 'Agrave': 722,
  25661. 'Abreve': 722,
  25662. 'multiply': 584,
  25663. 'uacute': 611,
  25664. 'Tcaron': 611,
  25665. 'partialdiff': 494,
  25666. 'ydieresis': 556,
  25667. 'Nacute': 722,
  25668. 'icircumflex': 278,
  25669. 'Ecircumflex': 667,
  25670. 'adieresis': 556,
  25671. 'edieresis': 556,
  25672. 'cacute': 556,
  25673. 'nacute': 611,
  25674. 'umacron': 611,
  25675. 'Ncaron': 722,
  25676. 'Iacute': 278,
  25677. 'plusminus': 584,
  25678. 'brokenbar': 280,
  25679. 'registered': 737,
  25680. 'Gbreve': 778,
  25681. 'Idotaccent': 278,
  25682. 'summation': 600,
  25683. 'Egrave': 667,
  25684. 'racute': 389,
  25685. 'omacron': 611,
  25686. 'Zacute': 611,
  25687. 'Zcaron': 611,
  25688. 'greaterequal': 549,
  25689. 'Eth': 722,
  25690. 'Ccedilla': 722,
  25691. 'lcommaaccent': 278,
  25692. 'tcaron': 389,
  25693. 'eogonek': 556,
  25694. 'Uogonek': 722,
  25695. 'Aacute': 722,
  25696. 'Adieresis': 722,
  25697. 'egrave': 556,
  25698. 'zacute': 500,
  25699. 'iogonek': 278,
  25700. 'Oacute': 778,
  25701. 'oacute': 611,
  25702. 'amacron': 556,
  25703. 'sacute': 556,
  25704. 'idieresis': 278,
  25705. 'Ocircumflex': 778,
  25706. 'Ugrave': 722,
  25707. 'Delta': 612,
  25708. 'thorn': 611,
  25709. 'twosuperior': 333,
  25710. 'Odieresis': 778,
  25711. 'mu': 611,
  25712. 'igrave': 278,
  25713. 'ohungarumlaut': 611,
  25714. 'Eogonek': 667,
  25715. 'dcroat': 611,
  25716. 'threequarters': 834,
  25717. 'Scedilla': 667,
  25718. 'lcaron': 400,
  25719. 'Kcommaaccent': 722,
  25720. 'Lacute': 611,
  25721. 'trademark': 1000,
  25722. 'edotaccent': 556,
  25723. 'Igrave': 278,
  25724. 'Imacron': 278,
  25725. 'Lcaron': 611,
  25726. 'onehalf': 834,
  25727. 'lessequal': 549,
  25728. 'ocircumflex': 611,
  25729. 'ntilde': 611,
  25730. 'Uhungarumlaut': 722,
  25731. 'Eacute': 667,
  25732. 'emacron': 556,
  25733. 'gbreve': 611,
  25734. 'onequarter': 834,
  25735. 'Scaron': 667,
  25736. 'Scommaaccent': 667,
  25737. 'Ohungarumlaut': 778,
  25738. 'degree': 400,
  25739. 'ograve': 611,
  25740. 'Ccaron': 722,
  25741. 'ugrave': 611,
  25742. 'radical': 549,
  25743. 'Dcaron': 722,
  25744. 'rcommaaccent': 389,
  25745. 'Ntilde': 722,
  25746. 'otilde': 611,
  25747. 'Rcommaaccent': 722,
  25748. 'Lcommaaccent': 611,
  25749. 'Atilde': 722,
  25750. 'Aogonek': 722,
  25751. 'Aring': 722,
  25752. 'Otilde': 778,
  25753. 'zdotaccent': 500,
  25754. 'Ecaron': 667,
  25755. 'Iogonek': 278,
  25756. 'kcommaaccent': 556,
  25757. 'minus': 584,
  25758. 'Icircumflex': 278,
  25759. 'ncaron': 611,
  25760. 'tcommaaccent': 333,
  25761. 'logicalnot': 584,
  25762. 'odieresis': 611,
  25763. 'udieresis': 611,
  25764. 'notequal': 549,
  25765. 'gcommaaccent': 611,
  25766. 'eth': 611,
  25767. 'zcaron': 500,
  25768. 'ncommaaccent': 611,
  25769. 'onesuperior': 333,
  25770. 'imacron': 278,
  25771. 'Euro': 556
  25772. },
  25773. 'Helvetica-BoldOblique': {
  25774. 'space': 278,
  25775. 'exclam': 333,
  25776. 'quotedbl': 474,
  25777. 'numbersign': 556,
  25778. 'dollar': 556,
  25779. 'percent': 889,
  25780. 'ampersand': 722,
  25781. 'quoteright': 278,
  25782. 'parenleft': 333,
  25783. 'parenright': 333,
  25784. 'asterisk': 389,
  25785. 'plus': 584,
  25786. 'comma': 278,
  25787. 'hyphen': 333,
  25788. 'period': 278,
  25789. 'slash': 278,
  25790. 'zero': 556,
  25791. 'one': 556,
  25792. 'two': 556,
  25793. 'three': 556,
  25794. 'four': 556,
  25795. 'five': 556,
  25796. 'six': 556,
  25797. 'seven': 556,
  25798. 'eight': 556,
  25799. 'nine': 556,
  25800. 'colon': 333,
  25801. 'semicolon': 333,
  25802. 'less': 584,
  25803. 'equal': 584,
  25804. 'greater': 584,
  25805. 'question': 611,
  25806. 'at': 975,
  25807. 'A': 722,
  25808. 'B': 722,
  25809. 'C': 722,
  25810. 'D': 722,
  25811. 'E': 667,
  25812. 'F': 611,
  25813. 'G': 778,
  25814. 'H': 722,
  25815. 'I': 278,
  25816. 'J': 556,
  25817. 'K': 722,
  25818. 'L': 611,
  25819. 'M': 833,
  25820. 'N': 722,
  25821. 'O': 778,
  25822. 'P': 667,
  25823. 'Q': 778,
  25824. 'R': 722,
  25825. 'S': 667,
  25826. 'T': 611,
  25827. 'U': 722,
  25828. 'V': 667,
  25829. 'W': 944,
  25830. 'X': 667,
  25831. 'Y': 667,
  25832. 'Z': 611,
  25833. 'bracketleft': 333,
  25834. 'backslash': 278,
  25835. 'bracketright': 333,
  25836. 'asciicircum': 584,
  25837. 'underscore': 556,
  25838. 'quoteleft': 278,
  25839. 'a': 556,
  25840. 'b': 611,
  25841. 'c': 556,
  25842. 'd': 611,
  25843. 'e': 556,
  25844. 'f': 333,
  25845. 'g': 611,
  25846. 'h': 611,
  25847. 'i': 278,
  25848. 'j': 278,
  25849. 'k': 556,
  25850. 'l': 278,
  25851. 'm': 889,
  25852. 'n': 611,
  25853. 'o': 611,
  25854. 'p': 611,
  25855. 'q': 611,
  25856. 'r': 389,
  25857. 's': 556,
  25858. 't': 333,
  25859. 'u': 611,
  25860. 'v': 556,
  25861. 'w': 778,
  25862. 'x': 556,
  25863. 'y': 556,
  25864. 'z': 500,
  25865. 'braceleft': 389,
  25866. 'bar': 280,
  25867. 'braceright': 389,
  25868. 'asciitilde': 584,
  25869. 'exclamdown': 333,
  25870. 'cent': 556,
  25871. 'sterling': 556,
  25872. 'fraction': 167,
  25873. 'yen': 556,
  25874. 'florin': 556,
  25875. 'section': 556,
  25876. 'currency': 556,
  25877. 'quotesingle': 238,
  25878. 'quotedblleft': 500,
  25879. 'guillemotleft': 556,
  25880. 'guilsinglleft': 333,
  25881. 'guilsinglright': 333,
  25882. 'fi': 611,
  25883. 'fl': 611,
  25884. 'endash': 556,
  25885. 'dagger': 556,
  25886. 'daggerdbl': 556,
  25887. 'periodcentered': 278,
  25888. 'paragraph': 556,
  25889. 'bullet': 350,
  25890. 'quotesinglbase': 278,
  25891. 'quotedblbase': 500,
  25892. 'quotedblright': 500,
  25893. 'guillemotright': 556,
  25894. 'ellipsis': 1000,
  25895. 'perthousand': 1000,
  25896. 'questiondown': 611,
  25897. 'grave': 333,
  25898. 'acute': 333,
  25899. 'circumflex': 333,
  25900. 'tilde': 333,
  25901. 'macron': 333,
  25902. 'breve': 333,
  25903. 'dotaccent': 333,
  25904. 'dieresis': 333,
  25905. 'ring': 333,
  25906. 'cedilla': 333,
  25907. 'hungarumlaut': 333,
  25908. 'ogonek': 333,
  25909. 'caron': 333,
  25910. 'emdash': 1000,
  25911. 'AE': 1000,
  25912. 'ordfeminine': 370,
  25913. 'Lslash': 611,
  25914. 'Oslash': 778,
  25915. 'OE': 1000,
  25916. 'ordmasculine': 365,
  25917. 'ae': 889,
  25918. 'dotlessi': 278,
  25919. 'lslash': 278,
  25920. 'oslash': 611,
  25921. 'oe': 944,
  25922. 'germandbls': 611,
  25923. 'Idieresis': 278,
  25924. 'eacute': 556,
  25925. 'abreve': 556,
  25926. 'uhungarumlaut': 611,
  25927. 'ecaron': 556,
  25928. 'Ydieresis': 667,
  25929. 'divide': 584,
  25930. 'Yacute': 667,
  25931. 'Acircumflex': 722,
  25932. 'aacute': 556,
  25933. 'Ucircumflex': 722,
  25934. 'yacute': 556,
  25935. 'scommaaccent': 556,
  25936. 'ecircumflex': 556,
  25937. 'Uring': 722,
  25938. 'Udieresis': 722,
  25939. 'aogonek': 556,
  25940. 'Uacute': 722,
  25941. 'uogonek': 611,
  25942. 'Edieresis': 667,
  25943. 'Dcroat': 722,
  25944. 'commaaccent': 250,
  25945. 'copyright': 737,
  25946. 'Emacron': 667,
  25947. 'ccaron': 556,
  25948. 'aring': 556,
  25949. 'Ncommaaccent': 722,
  25950. 'lacute': 278,
  25951. 'agrave': 556,
  25952. 'Tcommaaccent': 611,
  25953. 'Cacute': 722,
  25954. 'atilde': 556,
  25955. 'Edotaccent': 667,
  25956. 'scaron': 556,
  25957. 'scedilla': 556,
  25958. 'iacute': 278,
  25959. 'lozenge': 494,
  25960. 'Rcaron': 722,
  25961. 'Gcommaaccent': 778,
  25962. 'ucircumflex': 611,
  25963. 'acircumflex': 556,
  25964. 'Amacron': 722,
  25965. 'rcaron': 389,
  25966. 'ccedilla': 556,
  25967. 'Zdotaccent': 611,
  25968. 'Thorn': 667,
  25969. 'Omacron': 778,
  25970. 'Racute': 722,
  25971. 'Sacute': 667,
  25972. 'dcaron': 743,
  25973. 'Umacron': 722,
  25974. 'uring': 611,
  25975. 'threesuperior': 333,
  25976. 'Ograve': 778,
  25977. 'Agrave': 722,
  25978. 'Abreve': 722,
  25979. 'multiply': 584,
  25980. 'uacute': 611,
  25981. 'Tcaron': 611,
  25982. 'partialdiff': 494,
  25983. 'ydieresis': 556,
  25984. 'Nacute': 722,
  25985. 'icircumflex': 278,
  25986. 'Ecircumflex': 667,
  25987. 'adieresis': 556,
  25988. 'edieresis': 556,
  25989. 'cacute': 556,
  25990. 'nacute': 611,
  25991. 'umacron': 611,
  25992. 'Ncaron': 722,
  25993. 'Iacute': 278,
  25994. 'plusminus': 584,
  25995. 'brokenbar': 280,
  25996. 'registered': 737,
  25997. 'Gbreve': 778,
  25998. 'Idotaccent': 278,
  25999. 'summation': 600,
  26000. 'Egrave': 667,
  26001. 'racute': 389,
  26002. 'omacron': 611,
  26003. 'Zacute': 611,
  26004. 'Zcaron': 611,
  26005. 'greaterequal': 549,
  26006. 'Eth': 722,
  26007. 'Ccedilla': 722,
  26008. 'lcommaaccent': 278,
  26009. 'tcaron': 389,
  26010. 'eogonek': 556,
  26011. 'Uogonek': 722,
  26012. 'Aacute': 722,
  26013. 'Adieresis': 722,
  26014. 'egrave': 556,
  26015. 'zacute': 500,
  26016. 'iogonek': 278,
  26017. 'Oacute': 778,
  26018. 'oacute': 611,
  26019. 'amacron': 556,
  26020. 'sacute': 556,
  26021. 'idieresis': 278,
  26022. 'Ocircumflex': 778,
  26023. 'Ugrave': 722,
  26024. 'Delta': 612,
  26025. 'thorn': 611,
  26026. 'twosuperior': 333,
  26027. 'Odieresis': 778,
  26028. 'mu': 611,
  26029. 'igrave': 278,
  26030. 'ohungarumlaut': 611,
  26031. 'Eogonek': 667,
  26032. 'dcroat': 611,
  26033. 'threequarters': 834,
  26034. 'Scedilla': 667,
  26035. 'lcaron': 400,
  26036. 'Kcommaaccent': 722,
  26037. 'Lacute': 611,
  26038. 'trademark': 1000,
  26039. 'edotaccent': 556,
  26040. 'Igrave': 278,
  26041. 'Imacron': 278,
  26042. 'Lcaron': 611,
  26043. 'onehalf': 834,
  26044. 'lessequal': 549,
  26045. 'ocircumflex': 611,
  26046. 'ntilde': 611,
  26047. 'Uhungarumlaut': 722,
  26048. 'Eacute': 667,
  26049. 'emacron': 556,
  26050. 'gbreve': 611,
  26051. 'onequarter': 834,
  26052. 'Scaron': 667,
  26053. 'Scommaaccent': 667,
  26054. 'Ohungarumlaut': 778,
  26055. 'degree': 400,
  26056. 'ograve': 611,
  26057. 'Ccaron': 722,
  26058. 'ugrave': 611,
  26059. 'radical': 549,
  26060. 'Dcaron': 722,
  26061. 'rcommaaccent': 389,
  26062. 'Ntilde': 722,
  26063. 'otilde': 611,
  26064. 'Rcommaaccent': 722,
  26065. 'Lcommaaccent': 611,
  26066. 'Atilde': 722,
  26067. 'Aogonek': 722,
  26068. 'Aring': 722,
  26069. 'Otilde': 778,
  26070. 'zdotaccent': 500,
  26071. 'Ecaron': 667,
  26072. 'Iogonek': 278,
  26073. 'kcommaaccent': 556,
  26074. 'minus': 584,
  26075. 'Icircumflex': 278,
  26076. 'ncaron': 611,
  26077. 'tcommaaccent': 333,
  26078. 'logicalnot': 584,
  26079. 'odieresis': 611,
  26080. 'udieresis': 611,
  26081. 'notequal': 549,
  26082. 'gcommaaccent': 611,
  26083. 'eth': 611,
  26084. 'zcaron': 500,
  26085. 'ncommaaccent': 611,
  26086. 'onesuperior': 333,
  26087. 'imacron': 278,
  26088. 'Euro': 556
  26089. },
  26090. 'Helvetica-Oblique' : {
  26091. 'space': 278,
  26092. 'exclam': 278,
  26093. 'quotedbl': 355,
  26094. 'numbersign': 556,
  26095. 'dollar': 556,
  26096. 'percent': 889,
  26097. 'ampersand': 667,
  26098. 'quoteright': 222,
  26099. 'parenleft': 333,
  26100. 'parenright': 333,
  26101. 'asterisk': 389,
  26102. 'plus': 584,
  26103. 'comma': 278,
  26104. 'hyphen': 333,
  26105. 'period': 278,
  26106. 'slash': 278,
  26107. 'zero': 556,
  26108. 'one': 556,
  26109. 'two': 556,
  26110. 'three': 556,
  26111. 'four': 556,
  26112. 'five': 556,
  26113. 'six': 556,
  26114. 'seven': 556,
  26115. 'eight': 556,
  26116. 'nine': 556,
  26117. 'colon': 278,
  26118. 'semicolon': 278,
  26119. 'less': 584,
  26120. 'equal': 584,
  26121. 'greater': 584,
  26122. 'question': 556,
  26123. 'at': 1015,
  26124. 'A': 667,
  26125. 'B': 667,
  26126. 'C': 722,
  26127. 'D': 722,
  26128. 'E': 667,
  26129. 'F': 611,
  26130. 'G': 778,
  26131. 'H': 722,
  26132. 'I': 278,
  26133. 'J': 500,
  26134. 'K': 667,
  26135. 'L': 556,
  26136. 'M': 833,
  26137. 'N': 722,
  26138. 'O': 778,
  26139. 'P': 667,
  26140. 'Q': 778,
  26141. 'R': 722,
  26142. 'S': 667,
  26143. 'T': 611,
  26144. 'U': 722,
  26145. 'V': 667,
  26146. 'W': 944,
  26147. 'X': 667,
  26148. 'Y': 667,
  26149. 'Z': 611,
  26150. 'bracketleft': 278,
  26151. 'backslash': 278,
  26152. 'bracketright': 278,
  26153. 'asciicircum': 469,
  26154. 'underscore': 556,
  26155. 'quoteleft': 222,
  26156. 'a': 556,
  26157. 'b': 556,
  26158. 'c': 500,
  26159. 'd': 556,
  26160. 'e': 556,
  26161. 'f': 278,
  26162. 'g': 556,
  26163. 'h': 556,
  26164. 'i': 222,
  26165. 'j': 222,
  26166. 'k': 500,
  26167. 'l': 222,
  26168. 'm': 833,
  26169. 'n': 556,
  26170. 'o': 556,
  26171. 'p': 556,
  26172. 'q': 556,
  26173. 'r': 333,
  26174. 's': 500,
  26175. 't': 278,
  26176. 'u': 556,
  26177. 'v': 500,
  26178. 'w': 722,
  26179. 'x': 500,
  26180. 'y': 500,
  26181. 'z': 500,
  26182. 'braceleft': 334,
  26183. 'bar': 260,
  26184. 'braceright': 334,
  26185. 'asciitilde': 584,
  26186. 'exclamdown': 333,
  26187. 'cent': 556,
  26188. 'sterling': 556,
  26189. 'fraction': 167,
  26190. 'yen': 556,
  26191. 'florin': 556,
  26192. 'section': 556,
  26193. 'currency': 556,
  26194. 'quotesingle': 191,
  26195. 'quotedblleft': 333,
  26196. 'guillemotleft': 556,
  26197. 'guilsinglleft': 333,
  26198. 'guilsinglright': 333,
  26199. 'fi': 500,
  26200. 'fl': 500,
  26201. 'endash': 556,
  26202. 'dagger': 556,
  26203. 'daggerdbl': 556,
  26204. 'periodcentered': 278,
  26205. 'paragraph': 537,
  26206. 'bullet': 350,
  26207. 'quotesinglbase': 222,
  26208. 'quotedblbase': 333,
  26209. 'quotedblright': 333,
  26210. 'guillemotright': 556,
  26211. 'ellipsis': 1000,
  26212. 'perthousand': 1000,
  26213. 'questiondown': 611,
  26214. 'grave': 333,
  26215. 'acute': 333,
  26216. 'circumflex': 333,
  26217. 'tilde': 333,
  26218. 'macron': 333,
  26219. 'breve': 333,
  26220. 'dotaccent': 333,
  26221. 'dieresis': 333,
  26222. 'ring': 333,
  26223. 'cedilla': 333,
  26224. 'hungarumlaut': 333,
  26225. 'ogonek': 333,
  26226. 'caron': 333,
  26227. 'emdash': 1000,
  26228. 'AE': 1000,
  26229. 'ordfeminine': 370,
  26230. 'Lslash': 556,
  26231. 'Oslash': 778,
  26232. 'OE': 1000,
  26233. 'ordmasculine': 365,
  26234. 'ae': 889,
  26235. 'dotlessi': 278,
  26236. 'lslash': 222,
  26237. 'oslash': 611,
  26238. 'oe': 944,
  26239. 'germandbls': 611,
  26240. 'Idieresis': 278,
  26241. 'eacute': 556,
  26242. 'abreve': 556,
  26243. 'uhungarumlaut': 556,
  26244. 'ecaron': 556,
  26245. 'Ydieresis': 667,
  26246. 'divide': 584,
  26247. 'Yacute': 667,
  26248. 'Acircumflex': 667,
  26249. 'aacute': 556,
  26250. 'Ucircumflex': 722,
  26251. 'yacute': 500,
  26252. 'scommaaccent': 500,
  26253. 'ecircumflex': 556,
  26254. 'Uring': 722,
  26255. 'Udieresis': 722,
  26256. 'aogonek': 556,
  26257. 'Uacute': 722,
  26258. 'uogonek': 556,
  26259. 'Edieresis': 667,
  26260. 'Dcroat': 722,
  26261. 'commaaccent': 250,
  26262. 'copyright': 737,
  26263. 'Emacron': 667,
  26264. 'ccaron': 500,
  26265. 'aring': 556,
  26266. 'Ncommaaccent': 722,
  26267. 'lacute': 222,
  26268. 'agrave': 556,
  26269. 'Tcommaaccent': 611,
  26270. 'Cacute': 722,
  26271. 'atilde': 556,
  26272. 'Edotaccent': 667,
  26273. 'scaron': 500,
  26274. 'scedilla': 500,
  26275. 'iacute': 278,
  26276. 'lozenge': 471,
  26277. 'Rcaron': 722,
  26278. 'Gcommaaccent': 778,
  26279. 'ucircumflex': 556,
  26280. 'acircumflex': 556,
  26281. 'Amacron': 667,
  26282. 'rcaron': 333,
  26283. 'ccedilla': 500,
  26284. 'Zdotaccent': 611,
  26285. 'Thorn': 667,
  26286. 'Omacron': 778,
  26287. 'Racute': 722,
  26288. 'Sacute': 667,
  26289. 'dcaron': 643,
  26290. 'Umacron': 722,
  26291. 'uring': 556,
  26292. 'threesuperior': 333,
  26293. 'Ograve': 778,
  26294. 'Agrave': 667,
  26295. 'Abreve': 667,
  26296. 'multiply': 584,
  26297. 'uacute': 556,
  26298. 'Tcaron': 611,
  26299. 'partialdiff': 476,
  26300. 'ydieresis': 500,
  26301. 'Nacute': 722,
  26302. 'icircumflex': 278,
  26303. 'Ecircumflex': 667,
  26304. 'adieresis': 556,
  26305. 'edieresis': 556,
  26306. 'cacute': 500,
  26307. 'nacute': 556,
  26308. 'umacron': 556,
  26309. 'Ncaron': 722,
  26310. 'Iacute': 278,
  26311. 'plusminus': 584,
  26312. 'brokenbar': 260,
  26313. 'registered': 737,
  26314. 'Gbreve': 778,
  26315. 'Idotaccent': 278,
  26316. 'summation': 600,
  26317. 'Egrave': 667,
  26318. 'racute': 333,
  26319. 'omacron': 556,
  26320. 'Zacute': 611,
  26321. 'Zcaron': 611,
  26322. 'greaterequal': 549,
  26323. 'Eth': 722,
  26324. 'Ccedilla': 722,
  26325. 'lcommaaccent': 222,
  26326. 'tcaron': 317,
  26327. 'eogonek': 556,
  26328. 'Uogonek': 722,
  26329. 'Aacute': 667,
  26330. 'Adieresis': 667,
  26331. 'egrave': 556,
  26332. 'zacute': 500,
  26333. 'iogonek': 222,
  26334. 'Oacute': 778,
  26335. 'oacute': 556,
  26336. 'amacron': 556,
  26337. 'sacute': 500,
  26338. 'idieresis': 278,
  26339. 'Ocircumflex': 778,
  26340. 'Ugrave': 722,
  26341. 'Delta': 612,
  26342. 'thorn': 556,
  26343. 'twosuperior': 333,
  26344. 'Odieresis': 778,
  26345. 'mu': 556,
  26346. 'igrave': 278,
  26347. 'ohungarumlaut': 556,
  26348. 'Eogonek': 667,
  26349. 'dcroat': 556,
  26350. 'threequarters': 834,
  26351. 'Scedilla': 667,
  26352. 'lcaron': 299,
  26353. 'Kcommaaccent': 667,
  26354. 'Lacute': 556,
  26355. 'trademark': 1000,
  26356. 'edotaccent': 556,
  26357. 'Igrave': 278,
  26358. 'Imacron': 278,
  26359. 'Lcaron': 556,
  26360. 'onehalf': 834,
  26361. 'lessequal': 549,
  26362. 'ocircumflex': 556,
  26363. 'ntilde': 556,
  26364. 'Uhungarumlaut': 722,
  26365. 'Eacute': 667,
  26366. 'emacron': 556,
  26367. 'gbreve': 556,
  26368. 'onequarter': 834,
  26369. 'Scaron': 667,
  26370. 'Scommaaccent': 667,
  26371. 'Ohungarumlaut': 778,
  26372. 'degree': 400,
  26373. 'ograve': 556,
  26374. 'Ccaron': 722,
  26375. 'ugrave': 556,
  26376. 'radical': 453,
  26377. 'Dcaron': 722,
  26378. 'rcommaaccent': 333,
  26379. 'Ntilde': 722,
  26380. 'otilde': 556,
  26381. 'Rcommaaccent': 722,
  26382. 'Lcommaaccent': 556,
  26383. 'Atilde': 667,
  26384. 'Aogonek': 667,
  26385. 'Aring': 667,
  26386. 'Otilde': 778,
  26387. 'zdotaccent': 500,
  26388. 'Ecaron': 667,
  26389. 'Iogonek': 278,
  26390. 'kcommaaccent': 500,
  26391. 'minus': 584,
  26392. 'Icircumflex': 278,
  26393. 'ncaron': 556,
  26394. 'tcommaaccent': 278,
  26395. 'logicalnot': 584,
  26396. 'odieresis': 556,
  26397. 'udieresis': 556,
  26398. 'notequal': 549,
  26399. 'gcommaaccent': 556,
  26400. 'eth': 556,
  26401. 'zcaron': 500,
  26402. 'ncommaaccent': 556,
  26403. 'onesuperior': 333,
  26404. 'imacron': 278,
  26405. 'Euro': 556
  26406. },
  26407. 'Symbol': {
  26408. 'space': 250,
  26409. 'exclam': 333,
  26410. 'universal': 713,
  26411. 'numbersign': 500,
  26412. 'existential': 549,
  26413. 'percent': 833,
  26414. 'ampersand': 778,
  26415. 'suchthat': 439,
  26416. 'parenleft': 333,
  26417. 'parenright': 333,
  26418. 'asteriskmath': 500,
  26419. 'plus': 549,
  26420. 'comma': 250,
  26421. 'minus': 549,
  26422. 'period': 250,
  26423. 'slash': 278,
  26424. 'zero': 500,
  26425. 'one': 500,
  26426. 'two': 500,
  26427. 'three': 500,
  26428. 'four': 500,
  26429. 'five': 500,
  26430. 'six': 500,
  26431. 'seven': 500,
  26432. 'eight': 500,
  26433. 'nine': 500,
  26434. 'colon': 278,
  26435. 'semicolon': 278,
  26436. 'less': 549,
  26437. 'equal': 549,
  26438. 'greater': 549,
  26439. 'question': 444,
  26440. 'congruent': 549,
  26441. 'Alpha': 722,
  26442. 'Beta': 667,
  26443. 'Chi': 722,
  26444. 'Delta': 612,
  26445. 'Epsilon': 611,
  26446. 'Phi': 763,
  26447. 'Gamma': 603,
  26448. 'Eta': 722,
  26449. 'Iota': 333,
  26450. 'theta1': 631,
  26451. 'Kappa': 722,
  26452. 'Lambda': 686,
  26453. 'Mu': 889,
  26454. 'Nu': 722,
  26455. 'Omicron': 722,
  26456. 'Pi': 768,
  26457. 'Theta': 741,
  26458. 'Rho': 556,
  26459. 'Sigma': 592,
  26460. 'Tau': 611,
  26461. 'Upsilon': 690,
  26462. 'sigma1': 439,
  26463. 'Omega': 768,
  26464. 'Xi': 645,
  26465. 'Psi': 795,
  26466. 'Zeta': 611,
  26467. 'bracketleft': 333,
  26468. 'therefore': 863,
  26469. 'bracketright': 333,
  26470. 'perpendicular': 658,
  26471. 'underscore': 500,
  26472. 'radicalex': 500,
  26473. 'alpha': 631,
  26474. 'beta': 549,
  26475. 'chi': 549,
  26476. 'delta': 494,
  26477. 'epsilon': 439,
  26478. 'phi': 521,
  26479. 'gamma': 411,
  26480. 'eta': 603,
  26481. 'iota': 329,
  26482. 'phi1': 603,
  26483. 'kappa': 549,
  26484. 'lambda': 549,
  26485. 'mu': 576,
  26486. 'nu': 521,
  26487. 'omicron': 549,
  26488. 'pi': 549,
  26489. 'theta': 521,
  26490. 'rho': 549,
  26491. 'sigma': 603,
  26492. 'tau': 439,
  26493. 'upsilon': 576,
  26494. 'omega1': 713,
  26495. 'omega': 686,
  26496. 'xi': 493,
  26497. 'psi': 686,
  26498. 'zeta': 494,
  26499. 'braceleft': 480,
  26500. 'bar': 200,
  26501. 'braceright': 480,
  26502. 'similar': 549,
  26503. 'Euro': 750,
  26504. 'Upsilon1': 620,
  26505. 'minute': 247,
  26506. 'lessequal': 549,
  26507. 'fraction': 167,
  26508. 'infinity': 713,
  26509. 'florin': 500,
  26510. 'club': 753,
  26511. 'diamond': 753,
  26512. 'heart': 753,
  26513. 'spade': 753,
  26514. 'arrowboth': 1042,
  26515. 'arrowleft': 987,
  26516. 'arrowup': 603,
  26517. 'arrowright': 987,
  26518. 'arrowdown': 603,
  26519. 'degree': 400,
  26520. 'plusminus': 549,
  26521. 'second': 411,
  26522. 'greaterequal': 549,
  26523. 'multiply': 549,
  26524. 'proportional': 713,
  26525. 'partialdiff': 494,
  26526. 'bullet': 460,
  26527. 'divide': 549,
  26528. 'notequal': 549,
  26529. 'equivalence': 549,
  26530. 'approxequal': 549,
  26531. 'ellipsis': 1000,
  26532. 'arrowvertex': 603,
  26533. 'arrowhorizex': 1000,
  26534. 'carriagereturn': 658,
  26535. 'aleph': 823,
  26536. 'Ifraktur': 686,
  26537. 'Rfraktur': 795,
  26538. 'weierstrass': 987,
  26539. 'circlemultiply': 768,
  26540. 'circleplus': 768,
  26541. 'emptyset': 823,
  26542. 'intersection': 768,
  26543. 'union': 768,
  26544. 'propersuperset': 713,
  26545. 'reflexsuperset': 713,
  26546. 'notsubset': 713,
  26547. 'propersubset': 713,
  26548. 'reflexsubset': 713,
  26549. 'element': 713,
  26550. 'notelement': 713,
  26551. 'angle': 768,
  26552. 'gradient': 713,
  26553. 'registerserif': 790,
  26554. 'copyrightserif': 790,
  26555. 'trademarkserif': 890,
  26556. 'product': 823,
  26557. 'radical': 549,
  26558. 'dotmath': 250,
  26559. 'logicalnot': 713,
  26560. 'logicaland': 603,
  26561. 'logicalor': 603,
  26562. 'arrowdblboth': 1042,
  26563. 'arrowdblleft': 987,
  26564. 'arrowdblup': 603,
  26565. 'arrowdblright': 987,
  26566. 'arrowdbldown': 603,
  26567. 'lozenge': 494,
  26568. 'angleleft': 329,
  26569. 'registersans': 790,
  26570. 'copyrightsans': 790,
  26571. 'trademarksans': 786,
  26572. 'summation': 713,
  26573. 'parenlefttp': 384,
  26574. 'parenleftex': 384,
  26575. 'parenleftbt': 384,
  26576. 'bracketlefttp': 384,
  26577. 'bracketleftex': 384,
  26578. 'bracketleftbt': 384,
  26579. 'bracelefttp': 494,
  26580. 'braceleftmid': 494,
  26581. 'braceleftbt': 494,
  26582. 'braceex': 494,
  26583. 'angleright': 329,
  26584. 'integral': 274,
  26585. 'integraltp': 686,
  26586. 'integralex': 686,
  26587. 'integralbt': 686,
  26588. 'parenrighttp': 384,
  26589. 'parenrightex': 384,
  26590. 'parenrightbt': 384,
  26591. 'bracketrighttp': 384,
  26592. 'bracketrightex': 384,
  26593. 'bracketrightbt': 384,
  26594. 'bracerighttp': 494,
  26595. 'bracerightmid': 494,
  26596. 'bracerightbt': 494,
  26597. 'apple': 790
  26598. },
  26599. 'Times-Roman': {
  26600. 'space': 250,
  26601. 'exclam': 333,
  26602. 'quotedbl': 408,
  26603. 'numbersign': 500,
  26604. 'dollar': 500,
  26605. 'percent': 833,
  26606. 'ampersand': 778,
  26607. 'quoteright': 333,
  26608. 'parenleft': 333,
  26609. 'parenright': 333,
  26610. 'asterisk': 500,
  26611. 'plus': 564,
  26612. 'comma': 250,
  26613. 'hyphen': 333,
  26614. 'period': 250,
  26615. 'slash': 278,
  26616. 'zero': 500,
  26617. 'one': 500,
  26618. 'two': 500,
  26619. 'three': 500,
  26620. 'four': 500,
  26621. 'five': 500,
  26622. 'six': 500,
  26623. 'seven': 500,
  26624. 'eight': 500,
  26625. 'nine': 500,
  26626. 'colon': 278,
  26627. 'semicolon': 278,
  26628. 'less': 564,
  26629. 'equal': 564,
  26630. 'greater': 564,
  26631. 'question': 444,
  26632. 'at': 921,
  26633. 'A': 722,
  26634. 'B': 667,
  26635. 'C': 667,
  26636. 'D': 722,
  26637. 'E': 611,
  26638. 'F': 556,
  26639. 'G': 722,
  26640. 'H': 722,
  26641. 'I': 333,
  26642. 'J': 389,
  26643. 'K': 722,
  26644. 'L': 611,
  26645. 'M': 889,
  26646. 'N': 722,
  26647. 'O': 722,
  26648. 'P': 556,
  26649. 'Q': 722,
  26650. 'R': 667,
  26651. 'S': 556,
  26652. 'T': 611,
  26653. 'U': 722,
  26654. 'V': 722,
  26655. 'W': 944,
  26656. 'X': 722,
  26657. 'Y': 722,
  26658. 'Z': 611,
  26659. 'bracketleft': 333,
  26660. 'backslash': 278,
  26661. 'bracketright': 333,
  26662. 'asciicircum': 469,
  26663. 'underscore': 500,
  26664. 'quoteleft': 333,
  26665. 'a': 444,
  26666. 'b': 500,
  26667. 'c': 444,
  26668. 'd': 500,
  26669. 'e': 444,
  26670. 'f': 333,
  26671. 'g': 500,
  26672. 'h': 500,
  26673. 'i': 278,
  26674. 'j': 278,
  26675. 'k': 500,
  26676. 'l': 278,
  26677. 'm': 778,
  26678. 'n': 500,
  26679. 'o': 500,
  26680. 'p': 500,
  26681. 'q': 500,
  26682. 'r': 333,
  26683. 's': 389,
  26684. 't': 278,
  26685. 'u': 500,
  26686. 'v': 500,
  26687. 'w': 722,
  26688. 'x': 500,
  26689. 'y': 500,
  26690. 'z': 444,
  26691. 'braceleft': 480,
  26692. 'bar': 200,
  26693. 'braceright': 480,
  26694. 'asciitilde': 541,
  26695. 'exclamdown': 333,
  26696. 'cent': 500,
  26697. 'sterling': 500,
  26698. 'fraction': 167,
  26699. 'yen': 500,
  26700. 'florin': 500,
  26701. 'section': 500,
  26702. 'currency': 500,
  26703. 'quotesingle': 180,
  26704. 'quotedblleft': 444,
  26705. 'guillemotleft': 500,
  26706. 'guilsinglleft': 333,
  26707. 'guilsinglright': 333,
  26708. 'fi': 556,
  26709. 'fl': 556,
  26710. 'endash': 500,
  26711. 'dagger': 500,
  26712. 'daggerdbl': 500,
  26713. 'periodcentered': 250,
  26714. 'paragraph': 453,
  26715. 'bullet': 350,
  26716. 'quotesinglbase': 333,
  26717. 'quotedblbase': 444,
  26718. 'quotedblright': 444,
  26719. 'guillemotright': 500,
  26720. 'ellipsis': 1000,
  26721. 'perthousand': 1000,
  26722. 'questiondown': 444,
  26723. 'grave': 333,
  26724. 'acute': 333,
  26725. 'circumflex': 333,
  26726. 'tilde': 333,
  26727. 'macron': 333,
  26728. 'breve': 333,
  26729. 'dotaccent': 333,
  26730. 'dieresis': 333,
  26731. 'ring': 333,
  26732. 'cedilla': 333,
  26733. 'hungarumlaut': 333,
  26734. 'ogonek': 333,
  26735. 'caron': 333,
  26736. 'emdash': 1000,
  26737. 'AE': 889,
  26738. 'ordfeminine': 276,
  26739. 'Lslash': 611,
  26740. 'Oslash': 722,
  26741. 'OE': 889,
  26742. 'ordmasculine': 310,
  26743. 'ae': 667,
  26744. 'dotlessi': 278,
  26745. 'lslash': 278,
  26746. 'oslash': 500,
  26747. 'oe': 722,
  26748. 'germandbls': 500,
  26749. 'Idieresis': 333,
  26750. 'eacute': 444,
  26751. 'abreve': 444,
  26752. 'uhungarumlaut': 500,
  26753. 'ecaron': 444,
  26754. 'Ydieresis': 722,
  26755. 'divide': 564,
  26756. 'Yacute': 722,
  26757. 'Acircumflex': 722,
  26758. 'aacute': 444,
  26759. 'Ucircumflex': 722,
  26760. 'yacute': 500,
  26761. 'scommaaccent': 389,
  26762. 'ecircumflex': 444,
  26763. 'Uring': 722,
  26764. 'Udieresis': 722,
  26765. 'aogonek': 444,
  26766. 'Uacute': 722,
  26767. 'uogonek': 500,
  26768. 'Edieresis': 611,
  26769. 'Dcroat': 722,
  26770. 'commaaccent': 250,
  26771. 'copyright': 760,
  26772. 'Emacron': 611,
  26773. 'ccaron': 444,
  26774. 'aring': 444,
  26775. 'Ncommaaccent': 722,
  26776. 'lacute': 278,
  26777. 'agrave': 444,
  26778. 'Tcommaaccent': 611,
  26779. 'Cacute': 667,
  26780. 'atilde': 444,
  26781. 'Edotaccent': 611,
  26782. 'scaron': 389,
  26783. 'scedilla': 389,
  26784. 'iacute': 278,
  26785. 'lozenge': 471,
  26786. 'Rcaron': 667,
  26787. 'Gcommaaccent': 722,
  26788. 'ucircumflex': 500,
  26789. 'acircumflex': 444,
  26790. 'Amacron': 722,
  26791. 'rcaron': 333,
  26792. 'ccedilla': 444,
  26793. 'Zdotaccent': 611,
  26794. 'Thorn': 556,
  26795. 'Omacron': 722,
  26796. 'Racute': 667,
  26797. 'Sacute': 556,
  26798. 'dcaron': 588,
  26799. 'Umacron': 722,
  26800. 'uring': 500,
  26801. 'threesuperior': 300,
  26802. 'Ograve': 722,
  26803. 'Agrave': 722,
  26804. 'Abreve': 722,
  26805. 'multiply': 564,
  26806. 'uacute': 500,
  26807. 'Tcaron': 611,
  26808. 'partialdiff': 476,
  26809. 'ydieresis': 500,
  26810. 'Nacute': 722,
  26811. 'icircumflex': 278,
  26812. 'Ecircumflex': 611,
  26813. 'adieresis': 444,
  26814. 'edieresis': 444,
  26815. 'cacute': 444,
  26816. 'nacute': 500,
  26817. 'umacron': 500,
  26818. 'Ncaron': 722,
  26819. 'Iacute': 333,
  26820. 'plusminus': 564,
  26821. 'brokenbar': 200,
  26822. 'registered': 760,
  26823. 'Gbreve': 722,
  26824. 'Idotaccent': 333,
  26825. 'summation': 600,
  26826. 'Egrave': 611,
  26827. 'racute': 333,
  26828. 'omacron': 500,
  26829. 'Zacute': 611,
  26830. 'Zcaron': 611,
  26831. 'greaterequal': 549,
  26832. 'Eth': 722,
  26833. 'Ccedilla': 667,
  26834. 'lcommaaccent': 278,
  26835. 'tcaron': 326,
  26836. 'eogonek': 444,
  26837. 'Uogonek': 722,
  26838. 'Aacute': 722,
  26839. 'Adieresis': 722,
  26840. 'egrave': 444,
  26841. 'zacute': 444,
  26842. 'iogonek': 278,
  26843. 'Oacute': 722,
  26844. 'oacute': 500,
  26845. 'amacron': 444,
  26846. 'sacute': 389,
  26847. 'idieresis': 278,
  26848. 'Ocircumflex': 722,
  26849. 'Ugrave': 722,
  26850. 'Delta': 612,
  26851. 'thorn': 500,
  26852. 'twosuperior': 300,
  26853. 'Odieresis': 722,
  26854. 'mu': 500,
  26855. 'igrave': 278,
  26856. 'ohungarumlaut': 500,
  26857. 'Eogonek': 611,
  26858. 'dcroat': 500,
  26859. 'threequarters': 750,
  26860. 'Scedilla': 556,
  26861. 'lcaron': 344,
  26862. 'Kcommaaccent': 722,
  26863. 'Lacute': 611,
  26864. 'trademark': 980,
  26865. 'edotaccent': 444,
  26866. 'Igrave': 333,
  26867. 'Imacron': 333,
  26868. 'Lcaron': 611,
  26869. 'onehalf': 750,
  26870. 'lessequal': 549,
  26871. 'ocircumflex': 500,
  26872. 'ntilde': 500,
  26873. 'Uhungarumlaut': 722,
  26874. 'Eacute': 611,
  26875. 'emacron': 444,
  26876. 'gbreve': 500,
  26877. 'onequarter': 750,
  26878. 'Scaron': 556,
  26879. 'Scommaaccent': 556,
  26880. 'Ohungarumlaut': 722,
  26881. 'degree': 400,
  26882. 'ograve': 500,
  26883. 'Ccaron': 667,
  26884. 'ugrave': 500,
  26885. 'radical': 453,
  26886. 'Dcaron': 722,
  26887. 'rcommaaccent': 333,
  26888. 'Ntilde': 722,
  26889. 'otilde': 500,
  26890. 'Rcommaaccent': 667,
  26891. 'Lcommaaccent': 611,
  26892. 'Atilde': 722,
  26893. 'Aogonek': 722,
  26894. 'Aring': 722,
  26895. 'Otilde': 722,
  26896. 'zdotaccent': 444,
  26897. 'Ecaron': 611,
  26898. 'Iogonek': 333,
  26899. 'kcommaaccent': 500,
  26900. 'minus': 564,
  26901. 'Icircumflex': 333,
  26902. 'ncaron': 500,
  26903. 'tcommaaccent': 278,
  26904. 'logicalnot': 564,
  26905. 'odieresis': 500,
  26906. 'udieresis': 500,
  26907. 'notequal': 549,
  26908. 'gcommaaccent': 500,
  26909. 'eth': 500,
  26910. 'zcaron': 444,
  26911. 'ncommaaccent': 500,
  26912. 'onesuperior': 300,
  26913. 'imacron': 278,
  26914. 'Euro': 500
  26915. },
  26916. 'Times-Bold': {
  26917. 'space': 250,
  26918. 'exclam': 333,
  26919. 'quotedbl': 555,
  26920. 'numbersign': 500,
  26921. 'dollar': 500,
  26922. 'percent': 1000,
  26923. 'ampersand': 833,
  26924. 'quoteright': 333,
  26925. 'parenleft': 333,
  26926. 'parenright': 333,
  26927. 'asterisk': 500,
  26928. 'plus': 570,
  26929. 'comma': 250,
  26930. 'hyphen': 333,
  26931. 'period': 250,
  26932. 'slash': 278,
  26933. 'zero': 500,
  26934. 'one': 500,
  26935. 'two': 500,
  26936. 'three': 500,
  26937. 'four': 500,
  26938. 'five': 500,
  26939. 'six': 500,
  26940. 'seven': 500,
  26941. 'eight': 500,
  26942. 'nine': 500,
  26943. 'colon': 333,
  26944. 'semicolon': 333,
  26945. 'less': 570,
  26946. 'equal': 570,
  26947. 'greater': 570,
  26948. 'question': 500,
  26949. 'at': 930,
  26950. 'A': 722,
  26951. 'B': 667,
  26952. 'C': 722,
  26953. 'D': 722,
  26954. 'E': 667,
  26955. 'F': 611,
  26956. 'G': 778,
  26957. 'H': 778,
  26958. 'I': 389,
  26959. 'J': 500,
  26960. 'K': 778,
  26961. 'L': 667,
  26962. 'M': 944,
  26963. 'N': 722,
  26964. 'O': 778,
  26965. 'P': 611,
  26966. 'Q': 778,
  26967. 'R': 722,
  26968. 'S': 556,
  26969. 'T': 667,
  26970. 'U': 722,
  26971. 'V': 722,
  26972. 'W': 1000,
  26973. 'X': 722,
  26974. 'Y': 722,
  26975. 'Z': 667,
  26976. 'bracketleft': 333,
  26977. 'backslash': 278,
  26978. 'bracketright': 333,
  26979. 'asciicircum': 581,
  26980. 'underscore': 500,
  26981. 'quoteleft': 333,
  26982. 'a': 500,
  26983. 'b': 556,
  26984. 'c': 444,
  26985. 'd': 556,
  26986. 'e': 444,
  26987. 'f': 333,
  26988. 'g': 500,
  26989. 'h': 556,
  26990. 'i': 278,
  26991. 'j': 333,
  26992. 'k': 556,
  26993. 'l': 278,
  26994. 'm': 833,
  26995. 'n': 556,
  26996. 'o': 500,
  26997. 'p': 556,
  26998. 'q': 556,
  26999. 'r': 444,
  27000. 's': 389,
  27001. 't': 333,
  27002. 'u': 556,
  27003. 'v': 500,
  27004. 'w': 722,
  27005. 'x': 500,
  27006. 'y': 500,
  27007. 'z': 444,
  27008. 'braceleft': 394,
  27009. 'bar': 220,
  27010. 'braceright': 394,
  27011. 'asciitilde': 520,
  27012. 'exclamdown': 333,
  27013. 'cent': 500,
  27014. 'sterling': 500,
  27015. 'fraction': 167,
  27016. 'yen': 500,
  27017. 'florin': 500,
  27018. 'section': 500,
  27019. 'currency': 500,
  27020. 'quotesingle': 278,
  27021. 'quotedblleft': 500,
  27022. 'guillemotleft': 500,
  27023. 'guilsinglleft': 333,
  27024. 'guilsinglright': 333,
  27025. 'fi': 556,
  27026. 'fl': 556,
  27027. 'endash': 500,
  27028. 'dagger': 500,
  27029. 'daggerdbl': 500,
  27030. 'periodcentered': 250,
  27031. 'paragraph': 540,
  27032. 'bullet': 350,
  27033. 'quotesinglbase': 333,
  27034. 'quotedblbase': 500,
  27035. 'quotedblright': 500,
  27036. 'guillemotright': 500,
  27037. 'ellipsis': 1000,
  27038. 'perthousand': 1000,
  27039. 'questiondown': 500,
  27040. 'grave': 333,
  27041. 'acute': 333,
  27042. 'circumflex': 333,
  27043. 'tilde': 333,
  27044. 'macron': 333,
  27045. 'breve': 333,
  27046. 'dotaccent': 333,
  27047. 'dieresis': 333,
  27048. 'ring': 333,
  27049. 'cedilla': 333,
  27050. 'hungarumlaut': 333,
  27051. 'ogonek': 333,
  27052. 'caron': 333,
  27053. 'emdash': 1000,
  27054. 'AE': 1000,
  27055. 'ordfeminine': 300,
  27056. 'Lslash': 667,
  27057. 'Oslash': 778,
  27058. 'OE': 1000,
  27059. 'ordmasculine': 330,
  27060. 'ae': 722,
  27061. 'dotlessi': 278,
  27062. 'lslash': 278,
  27063. 'oslash': 500,
  27064. 'oe': 722,
  27065. 'germandbls': 556,
  27066. 'Idieresis': 389,
  27067. 'eacute': 444,
  27068. 'abreve': 500,
  27069. 'uhungarumlaut': 556,
  27070. 'ecaron': 444,
  27071. 'Ydieresis': 722,
  27072. 'divide': 570,
  27073. 'Yacute': 722,
  27074. 'Acircumflex': 722,
  27075. 'aacute': 500,
  27076. 'Ucircumflex': 722,
  27077. 'yacute': 500,
  27078. 'scommaaccent': 389,
  27079. 'ecircumflex': 444,
  27080. 'Uring': 722,
  27081. 'Udieresis': 722,
  27082. 'aogonek': 500,
  27083. 'Uacute': 722,
  27084. 'uogonek': 556,
  27085. 'Edieresis': 667,
  27086. 'Dcroat': 722,
  27087. 'commaaccent': 250,
  27088. 'copyright': 747,
  27089. 'Emacron': 667,
  27090. 'ccaron': 444,
  27091. 'aring': 500,
  27092. 'Ncommaaccent': 722,
  27093. 'lacute': 278,
  27094. 'agrave': 500,
  27095. 'Tcommaaccent': 667,
  27096. 'Cacute': 722,
  27097. 'atilde': 500,
  27098. 'Edotaccent': 667,
  27099. 'scaron': 389,
  27100. 'scedilla': 389,
  27101. 'iacute': 278,
  27102. 'lozenge': 494,
  27103. 'Rcaron': 722,
  27104. 'Gcommaaccent': 778,
  27105. 'ucircumflex': 556,
  27106. 'acircumflex': 500,
  27107. 'Amacron': 722,
  27108. 'rcaron': 444,
  27109. 'ccedilla': 444,
  27110. 'Zdotaccent': 667,
  27111. 'Thorn': 611,
  27112. 'Omacron': 778,
  27113. 'Racute': 722,
  27114. 'Sacute': 556,
  27115. 'dcaron': 672,
  27116. 'Umacron': 722,
  27117. 'uring': 556,
  27118. 'threesuperior': 300,
  27119. 'Ograve': 778,
  27120. 'Agrave': 722,
  27121. 'Abreve': 722,
  27122. 'multiply': 570,
  27123. 'uacute': 556,
  27124. 'Tcaron': 667,
  27125. 'partialdiff': 494,
  27126. 'ydieresis': 500,
  27127. 'Nacute': 722,
  27128. 'icircumflex': 278,
  27129. 'Ecircumflex': 667,
  27130. 'adieresis': 500,
  27131. 'edieresis': 444,
  27132. 'cacute': 444,
  27133. 'nacute': 556,
  27134. 'umacron': 556,
  27135. 'Ncaron': 722,
  27136. 'Iacute': 389,
  27137. 'plusminus': 570,
  27138. 'brokenbar': 220,
  27139. 'registered': 747,
  27140. 'Gbreve': 778,
  27141. 'Idotaccent': 389,
  27142. 'summation': 600,
  27143. 'Egrave': 667,
  27144. 'racute': 444,
  27145. 'omacron': 500,
  27146. 'Zacute': 667,
  27147. 'Zcaron': 667,
  27148. 'greaterequal': 549,
  27149. 'Eth': 722,
  27150. 'Ccedilla': 722,
  27151. 'lcommaaccent': 278,
  27152. 'tcaron': 416,
  27153. 'eogonek': 444,
  27154. 'Uogonek': 722,
  27155. 'Aacute': 722,
  27156. 'Adieresis': 722,
  27157. 'egrave': 444,
  27158. 'zacute': 444,
  27159. 'iogonek': 278,
  27160. 'Oacute': 778,
  27161. 'oacute': 500,
  27162. 'amacron': 500,
  27163. 'sacute': 389,
  27164. 'idieresis': 278,
  27165. 'Ocircumflex': 778,
  27166. 'Ugrave': 722,
  27167. 'Delta': 612,
  27168. 'thorn': 556,
  27169. 'twosuperior': 300,
  27170. 'Odieresis': 778,
  27171. 'mu': 556,
  27172. 'igrave': 278,
  27173. 'ohungarumlaut': 500,
  27174. 'Eogonek': 667,
  27175. 'dcroat': 556,
  27176. 'threequarters': 750,
  27177. 'Scedilla': 556,
  27178. 'lcaron': 394,
  27179. 'Kcommaaccent': 778,
  27180. 'Lacute': 667,
  27181. 'trademark': 1000,
  27182. 'edotaccent': 444,
  27183. 'Igrave': 389,
  27184. 'Imacron': 389,
  27185. 'Lcaron': 667,
  27186. 'onehalf': 750,
  27187. 'lessequal': 549,
  27188. 'ocircumflex': 500,
  27189. 'ntilde': 556,
  27190. 'Uhungarumlaut': 722,
  27191. 'Eacute': 667,
  27192. 'emacron': 444,
  27193. 'gbreve': 500,
  27194. 'onequarter': 750,
  27195. 'Scaron': 556,
  27196. 'Scommaaccent': 556,
  27197. 'Ohungarumlaut': 778,
  27198. 'degree': 400,
  27199. 'ograve': 500,
  27200. 'Ccaron': 722,
  27201. 'ugrave': 556,
  27202. 'radical': 549,
  27203. 'Dcaron': 722,
  27204. 'rcommaaccent': 444,
  27205. 'Ntilde': 722,
  27206. 'otilde': 500,
  27207. 'Rcommaaccent': 722,
  27208. 'Lcommaaccent': 667,
  27209. 'Atilde': 722,
  27210. 'Aogonek': 722,
  27211. 'Aring': 722,
  27212. 'Otilde': 778,
  27213. 'zdotaccent': 444,
  27214. 'Ecaron': 667,
  27215. 'Iogonek': 389,
  27216. 'kcommaaccent': 556,
  27217. 'minus': 570,
  27218. 'Icircumflex': 389,
  27219. 'ncaron': 556,
  27220. 'tcommaaccent': 333,
  27221. 'logicalnot': 570,
  27222. 'odieresis': 500,
  27223. 'udieresis': 556,
  27224. 'notequal': 549,
  27225. 'gcommaaccent': 500,
  27226. 'eth': 500,
  27227. 'zcaron': 444,
  27228. 'ncommaaccent': 556,
  27229. 'onesuperior': 300,
  27230. 'imacron': 278,
  27231. 'Euro': 500
  27232. },
  27233. 'Times-BoldItalic': {
  27234. 'space': 250,
  27235. 'exclam': 389,
  27236. 'quotedbl': 555,
  27237. 'numbersign': 500,
  27238. 'dollar': 500,
  27239. 'percent': 833,
  27240. 'ampersand': 778,
  27241. 'quoteright': 333,
  27242. 'parenleft': 333,
  27243. 'parenright': 333,
  27244. 'asterisk': 500,
  27245. 'plus': 570,
  27246. 'comma': 250,
  27247. 'hyphen': 333,
  27248. 'period': 250,
  27249. 'slash': 278,
  27250. 'zero': 500,
  27251. 'one': 500,
  27252. 'two': 500,
  27253. 'three': 500,
  27254. 'four': 500,
  27255. 'five': 500,
  27256. 'six': 500,
  27257. 'seven': 500,
  27258. 'eight': 500,
  27259. 'nine': 500,
  27260. 'colon': 333,
  27261. 'semicolon': 333,
  27262. 'less': 570,
  27263. 'equal': 570,
  27264. 'greater': 570,
  27265. 'question': 500,
  27266. 'at': 832,
  27267. 'A': 667,
  27268. 'B': 667,
  27269. 'C': 667,
  27270. 'D': 722,
  27271. 'E': 667,
  27272. 'F': 667,
  27273. 'G': 722,
  27274. 'H': 778,
  27275. 'I': 389,
  27276. 'J': 500,
  27277. 'K': 667,
  27278. 'L': 611,
  27279. 'M': 889,
  27280. 'N': 722,
  27281. 'O': 722,
  27282. 'P': 611,
  27283. 'Q': 722,
  27284. 'R': 667,
  27285. 'S': 556,
  27286. 'T': 611,
  27287. 'U': 722,
  27288. 'V': 667,
  27289. 'W': 889,
  27290. 'X': 667,
  27291. 'Y': 611,
  27292. 'Z': 611,
  27293. 'bracketleft': 333,
  27294. 'backslash': 278,
  27295. 'bracketright': 333,
  27296. 'asciicircum': 570,
  27297. 'underscore': 500,
  27298. 'quoteleft': 333,
  27299. 'a': 500,
  27300. 'b': 500,
  27301. 'c': 444,
  27302. 'd': 500,
  27303. 'e': 444,
  27304. 'f': 333,
  27305. 'g': 500,
  27306. 'h': 556,
  27307. 'i': 278,
  27308. 'j': 278,
  27309. 'k': 500,
  27310. 'l': 278,
  27311. 'm': 778,
  27312. 'n': 556,
  27313. 'o': 500,
  27314. 'p': 500,
  27315. 'q': 500,
  27316. 'r': 389,
  27317. 's': 389,
  27318. 't': 278,
  27319. 'u': 556,
  27320. 'v': 444,
  27321. 'w': 667,
  27322. 'x': 500,
  27323. 'y': 444,
  27324. 'z': 389,
  27325. 'braceleft': 348,
  27326. 'bar': 220,
  27327. 'braceright': 348,
  27328. 'asciitilde': 570,
  27329. 'exclamdown': 389,
  27330. 'cent': 500,
  27331. 'sterling': 500,
  27332. 'fraction': 167,
  27333. 'yen': 500,
  27334. 'florin': 500,
  27335. 'section': 500,
  27336. 'currency': 500,
  27337. 'quotesingle': 278,
  27338. 'quotedblleft': 500,
  27339. 'guillemotleft': 500,
  27340. 'guilsinglleft': 333,
  27341. 'guilsinglright': 333,
  27342. 'fi': 556,
  27343. 'fl': 556,
  27344. 'endash': 500,
  27345. 'dagger': 500,
  27346. 'daggerdbl': 500,
  27347. 'periodcentered': 250,
  27348. 'paragraph': 500,
  27349. 'bullet': 350,
  27350. 'quotesinglbase': 333,
  27351. 'quotedblbase': 500,
  27352. 'quotedblright': 500,
  27353. 'guillemotright': 500,
  27354. 'ellipsis': 1000,
  27355. 'perthousand': 1000,
  27356. 'questiondown': 500,
  27357. 'grave': 333,
  27358. 'acute': 333,
  27359. 'circumflex': 333,
  27360. 'tilde': 333,
  27361. 'macron': 333,
  27362. 'breve': 333,
  27363. 'dotaccent': 333,
  27364. 'dieresis': 333,
  27365. 'ring': 333,
  27366. 'cedilla': 333,
  27367. 'hungarumlaut': 333,
  27368. 'ogonek': 333,
  27369. 'caron': 333,
  27370. 'emdash': 1000,
  27371. 'AE': 944,
  27372. 'ordfeminine': 266,
  27373. 'Lslash': 611,
  27374. 'Oslash': 722,
  27375. 'OE': 944,
  27376. 'ordmasculine': 300,
  27377. 'ae': 722,
  27378. 'dotlessi': 278,
  27379. 'lslash': 278,
  27380. 'oslash': 500,
  27381. 'oe': 722,
  27382. 'germandbls': 500,
  27383. 'Idieresis': 389,
  27384. 'eacute': 444,
  27385. 'abreve': 500,
  27386. 'uhungarumlaut': 556,
  27387. 'ecaron': 444,
  27388. 'Ydieresis': 611,
  27389. 'divide': 570,
  27390. 'Yacute': 611,
  27391. 'Acircumflex': 667,
  27392. 'aacute': 500,
  27393. 'Ucircumflex': 722,
  27394. 'yacute': 444,
  27395. 'scommaaccent': 389,
  27396. 'ecircumflex': 444,
  27397. 'Uring': 722,
  27398. 'Udieresis': 722,
  27399. 'aogonek': 500,
  27400. 'Uacute': 722,
  27401. 'uogonek': 556,
  27402. 'Edieresis': 667,
  27403. 'Dcroat': 722,
  27404. 'commaaccent': 250,
  27405. 'copyright': 747,
  27406. 'Emacron': 667,
  27407. 'ccaron': 444,
  27408. 'aring': 500,
  27409. 'Ncommaaccent': 722,
  27410. 'lacute': 278,
  27411. 'agrave': 500,
  27412. 'Tcommaaccent': 611,
  27413. 'Cacute': 667,
  27414. 'atilde': 500,
  27415. 'Edotaccent': 667,
  27416. 'scaron': 389,
  27417. 'scedilla': 389,
  27418. 'iacute': 278,
  27419. 'lozenge': 494,
  27420. 'Rcaron': 667,
  27421. 'Gcommaaccent': 722,
  27422. 'ucircumflex': 556,
  27423. 'acircumflex': 500,
  27424. 'Amacron': 667,
  27425. 'rcaron': 389,
  27426. 'ccedilla': 444,
  27427. 'Zdotaccent': 611,
  27428. 'Thorn': 611,
  27429. 'Omacron': 722,
  27430. 'Racute': 667,
  27431. 'Sacute': 556,
  27432. 'dcaron': 608,
  27433. 'Umacron': 722,
  27434. 'uring': 556,
  27435. 'threesuperior': 300,
  27436. 'Ograve': 722,
  27437. 'Agrave': 667,
  27438. 'Abreve': 667,
  27439. 'multiply': 570,
  27440. 'uacute': 556,
  27441. 'Tcaron': 611,
  27442. 'partialdiff': 494,
  27443. 'ydieresis': 444,
  27444. 'Nacute': 722,
  27445. 'icircumflex': 278,
  27446. 'Ecircumflex': 667,
  27447. 'adieresis': 500,
  27448. 'edieresis': 444,
  27449. 'cacute': 444,
  27450. 'nacute': 556,
  27451. 'umacron': 556,
  27452. 'Ncaron': 722,
  27453. 'Iacute': 389,
  27454. 'plusminus': 570,
  27455. 'brokenbar': 220,
  27456. 'registered': 747,
  27457. 'Gbreve': 722,
  27458. 'Idotaccent': 389,
  27459. 'summation': 600,
  27460. 'Egrave': 667,
  27461. 'racute': 389,
  27462. 'omacron': 500,
  27463. 'Zacute': 611,
  27464. 'Zcaron': 611,
  27465. 'greaterequal': 549,
  27466. 'Eth': 722,
  27467. 'Ccedilla': 667,
  27468. 'lcommaaccent': 278,
  27469. 'tcaron': 366,
  27470. 'eogonek': 444,
  27471. 'Uogonek': 722,
  27472. 'Aacute': 667,
  27473. 'Adieresis': 667,
  27474. 'egrave': 444,
  27475. 'zacute': 389,
  27476. 'iogonek': 278,
  27477. 'Oacute': 722,
  27478. 'oacute': 500,
  27479. 'amacron': 500,
  27480. 'sacute': 389,
  27481. 'idieresis': 278,
  27482. 'Ocircumflex': 722,
  27483. 'Ugrave': 722,
  27484. 'Delta': 612,
  27485. 'thorn': 500,
  27486. 'twosuperior': 300,
  27487. 'Odieresis': 722,
  27488. 'mu': 576,
  27489. 'igrave': 278,
  27490. 'ohungarumlaut': 500,
  27491. 'Eogonek': 667,
  27492. 'dcroat': 500,
  27493. 'threequarters': 750,
  27494. 'Scedilla': 556,
  27495. 'lcaron': 382,
  27496. 'Kcommaaccent': 667,
  27497. 'Lacute': 611,
  27498. 'trademark': 1000,
  27499. 'edotaccent': 444,
  27500. 'Igrave': 389,
  27501. 'Imacron': 389,
  27502. 'Lcaron': 611,
  27503. 'onehalf': 750,
  27504. 'lessequal': 549,
  27505. 'ocircumflex': 500,
  27506. 'ntilde': 556,
  27507. 'Uhungarumlaut': 722,
  27508. 'Eacute': 667,
  27509. 'emacron': 444,
  27510. 'gbreve': 500,
  27511. 'onequarter': 750,
  27512. 'Scaron': 556,
  27513. 'Scommaaccent': 556,
  27514. 'Ohungarumlaut': 722,
  27515. 'degree': 400,
  27516. 'ograve': 500,
  27517. 'Ccaron': 667,
  27518. 'ugrave': 556,
  27519. 'radical': 549,
  27520. 'Dcaron': 722,
  27521. 'rcommaaccent': 389,
  27522. 'Ntilde': 722,
  27523. 'otilde': 500,
  27524. 'Rcommaaccent': 667,
  27525. 'Lcommaaccent': 611,
  27526. 'Atilde': 667,
  27527. 'Aogonek': 667,
  27528. 'Aring': 667,
  27529. 'Otilde': 722,
  27530. 'zdotaccent': 389,
  27531. 'Ecaron': 667,
  27532. 'Iogonek': 389,
  27533. 'kcommaaccent': 500,
  27534. 'minus': 606,
  27535. 'Icircumflex': 389,
  27536. 'ncaron': 556,
  27537. 'tcommaaccent': 278,
  27538. 'logicalnot': 606,
  27539. 'odieresis': 500,
  27540. 'udieresis': 556,
  27541. 'notequal': 549,
  27542. 'gcommaaccent': 500,
  27543. 'eth': 500,
  27544. 'zcaron': 389,
  27545. 'ncommaaccent': 556,
  27546. 'onesuperior': 300,
  27547. 'imacron': 278,
  27548. 'Euro': 500
  27549. },
  27550. 'Times-Italic': {
  27551. 'space': 250,
  27552. 'exclam': 333,
  27553. 'quotedbl': 420,
  27554. 'numbersign': 500,
  27555. 'dollar': 500,
  27556. 'percent': 833,
  27557. 'ampersand': 778,
  27558. 'quoteright': 333,
  27559. 'parenleft': 333,
  27560. 'parenright': 333,
  27561. 'asterisk': 500,
  27562. 'plus': 675,
  27563. 'comma': 250,
  27564. 'hyphen': 333,
  27565. 'period': 250,
  27566. 'slash': 278,
  27567. 'zero': 500,
  27568. 'one': 500,
  27569. 'two': 500,
  27570. 'three': 500,
  27571. 'four': 500,
  27572. 'five': 500,
  27573. 'six': 500,
  27574. 'seven': 500,
  27575. 'eight': 500,
  27576. 'nine': 500,
  27577. 'colon': 333,
  27578. 'semicolon': 333,
  27579. 'less': 675,
  27580. 'equal': 675,
  27581. 'greater': 675,
  27582. 'question': 500,
  27583. 'at': 920,
  27584. 'A': 611,
  27585. 'B': 611,
  27586. 'C': 667,
  27587. 'D': 722,
  27588. 'E': 611,
  27589. 'F': 611,
  27590. 'G': 722,
  27591. 'H': 722,
  27592. 'I': 333,
  27593. 'J': 444,
  27594. 'K': 667,
  27595. 'L': 556,
  27596. 'M': 833,
  27597. 'N': 667,
  27598. 'O': 722,
  27599. 'P': 611,
  27600. 'Q': 722,
  27601. 'R': 611,
  27602. 'S': 500,
  27603. 'T': 556,
  27604. 'U': 722,
  27605. 'V': 611,
  27606. 'W': 833,
  27607. 'X': 611,
  27608. 'Y': 556,
  27609. 'Z': 556,
  27610. 'bracketleft': 389,
  27611. 'backslash': 278,
  27612. 'bracketright': 389,
  27613. 'asciicircum': 422,
  27614. 'underscore': 500,
  27615. 'quoteleft': 333,
  27616. 'a': 500,
  27617. 'b': 500,
  27618. 'c': 444,
  27619. 'd': 500,
  27620. 'e': 444,
  27621. 'f': 278,
  27622. 'g': 500,
  27623. 'h': 500,
  27624. 'i': 278,
  27625. 'j': 278,
  27626. 'k': 444,
  27627. 'l': 278,
  27628. 'm': 722,
  27629. 'n': 500,
  27630. 'o': 500,
  27631. 'p': 500,
  27632. 'q': 500,
  27633. 'r': 389,
  27634. 's': 389,
  27635. 't': 278,
  27636. 'u': 500,
  27637. 'v': 444,
  27638. 'w': 667,
  27639. 'x': 444,
  27640. 'y': 444,
  27641. 'z': 389,
  27642. 'braceleft': 400,
  27643. 'bar': 275,
  27644. 'braceright': 400,
  27645. 'asciitilde': 541,
  27646. 'exclamdown': 389,
  27647. 'cent': 500,
  27648. 'sterling': 500,
  27649. 'fraction': 167,
  27650. 'yen': 500,
  27651. 'florin': 500,
  27652. 'section': 500,
  27653. 'currency': 500,
  27654. 'quotesingle': 214,
  27655. 'quotedblleft': 556,
  27656. 'guillemotleft': 500,
  27657. 'guilsinglleft': 333,
  27658. 'guilsinglright': 333,
  27659. 'fi': 500,
  27660. 'fl': 500,
  27661. 'endash': 500,
  27662. 'dagger': 500,
  27663. 'daggerdbl': 500,
  27664. 'periodcentered': 250,
  27665. 'paragraph': 523,
  27666. 'bullet': 350,
  27667. 'quotesinglbase': 333,
  27668. 'quotedblbase': 556,
  27669. 'quotedblright': 556,
  27670. 'guillemotright': 500,
  27671. 'ellipsis': 889,
  27672. 'perthousand': 1000,
  27673. 'questiondown': 500,
  27674. 'grave': 333,
  27675. 'acute': 333,
  27676. 'circumflex': 333,
  27677. 'tilde': 333,
  27678. 'macron': 333,
  27679. 'breve': 333,
  27680. 'dotaccent': 333,
  27681. 'dieresis': 333,
  27682. 'ring': 333,
  27683. 'cedilla': 333,
  27684. 'hungarumlaut': 333,
  27685. 'ogonek': 333,
  27686. 'caron': 333,
  27687. 'emdash': 889,
  27688. 'AE': 889,
  27689. 'ordfeminine': 276,
  27690. 'Lslash': 556,
  27691. 'Oslash': 722,
  27692. 'OE': 944,
  27693. 'ordmasculine': 310,
  27694. 'ae': 667,
  27695. 'dotlessi': 278,
  27696. 'lslash': 278,
  27697. 'oslash': 500,
  27698. 'oe': 667,
  27699. 'germandbls': 500,
  27700. 'Idieresis': 333,
  27701. 'eacute': 444,
  27702. 'abreve': 500,
  27703. 'uhungarumlaut': 500,
  27704. 'ecaron': 444,
  27705. 'Ydieresis': 556,
  27706. 'divide': 675,
  27707. 'Yacute': 556,
  27708. 'Acircumflex': 611,
  27709. 'aacute': 500,
  27710. 'Ucircumflex': 722,
  27711. 'yacute': 444,
  27712. 'scommaaccent': 389,
  27713. 'ecircumflex': 444,
  27714. 'Uring': 722,
  27715. 'Udieresis': 722,
  27716. 'aogonek': 500,
  27717. 'Uacute': 722,
  27718. 'uogonek': 500,
  27719. 'Edieresis': 611,
  27720. 'Dcroat': 722,
  27721. 'commaaccent': 250,
  27722. 'copyright': 760,
  27723. 'Emacron': 611,
  27724. 'ccaron': 444,
  27725. 'aring': 500,
  27726. 'Ncommaaccent': 667,
  27727. 'lacute': 278,
  27728. 'agrave': 500,
  27729. 'Tcommaaccent': 556,
  27730. 'Cacute': 667,
  27731. 'atilde': 500,
  27732. 'Edotaccent': 611,
  27733. 'scaron': 389,
  27734. 'scedilla': 389,
  27735. 'iacute': 278,
  27736. 'lozenge': 471,
  27737. 'Rcaron': 611,
  27738. 'Gcommaaccent': 722,
  27739. 'ucircumflex': 500,
  27740. 'acircumflex': 500,
  27741. 'Amacron': 611,
  27742. 'rcaron': 389,
  27743. 'ccedilla': 444,
  27744. 'Zdotaccent': 556,
  27745. 'Thorn': 611,
  27746. 'Omacron': 722,
  27747. 'Racute': 611,
  27748. 'Sacute': 500,
  27749. 'dcaron': 544,
  27750. 'Umacron': 722,
  27751. 'uring': 500,
  27752. 'threesuperior': 300,
  27753. 'Ograve': 722,
  27754. 'Agrave': 611,
  27755. 'Abreve': 611,
  27756. 'multiply': 675,
  27757. 'uacute': 500,
  27758. 'Tcaron': 556,
  27759. 'partialdiff': 476,
  27760. 'ydieresis': 444,
  27761. 'Nacute': 667,
  27762. 'icircumflex': 278,
  27763. 'Ecircumflex': 611,
  27764. 'adieresis': 500,
  27765. 'edieresis': 444,
  27766. 'cacute': 444,
  27767. 'nacute': 500,
  27768. 'umacron': 500,
  27769. 'Ncaron': 667,
  27770. 'Iacute': 333,
  27771. 'plusminus': 675,
  27772. 'brokenbar': 275,
  27773. 'registered': 760,
  27774. 'Gbreve': 722,
  27775. 'Idotaccent': 333,
  27776. 'summation': 600,
  27777. 'Egrave': 611,
  27778. 'racute': 389,
  27779. 'omacron': 500,
  27780. 'Zacute': 556,
  27781. 'Zcaron': 556,
  27782. 'greaterequal': 549,
  27783. 'Eth': 722,
  27784. 'Ccedilla': 667,
  27785. 'lcommaaccent': 278,
  27786. 'tcaron': 300,
  27787. 'eogonek': 444,
  27788. 'Uogonek': 722,
  27789. 'Aacute': 611,
  27790. 'Adieresis': 611,
  27791. 'egrave': 444,
  27792. 'zacute': 389,
  27793. 'iogonek': 278,
  27794. 'Oacute': 722,
  27795. 'oacute': 500,
  27796. 'amacron': 500,
  27797. 'sacute': 389,
  27798. 'idieresis': 278,
  27799. 'Ocircumflex': 722,
  27800. 'Ugrave': 722,
  27801. 'Delta': 612,
  27802. 'thorn': 500,
  27803. 'twosuperior': 300,
  27804. 'Odieresis': 722,
  27805. 'mu': 500,
  27806. 'igrave': 278,
  27807. 'ohungarumlaut': 500,
  27808. 'Eogonek': 611,
  27809. 'dcroat': 500,
  27810. 'threequarters': 750,
  27811. 'Scedilla': 500,
  27812. 'lcaron': 300,
  27813. 'Kcommaaccent': 667,
  27814. 'Lacute': 556,
  27815. 'trademark': 980,
  27816. 'edotaccent': 444,
  27817. 'Igrave': 333,
  27818. 'Imacron': 333,
  27819. 'Lcaron': 611,
  27820. 'onehalf': 750,
  27821. 'lessequal': 549,
  27822. 'ocircumflex': 500,
  27823. 'ntilde': 500,
  27824. 'Uhungarumlaut': 722,
  27825. 'Eacute': 611,
  27826. 'emacron': 444,
  27827. 'gbreve': 500,
  27828. 'onequarter': 750,
  27829. 'Scaron': 500,
  27830. 'Scommaaccent': 500,
  27831. 'Ohungarumlaut': 722,
  27832. 'degree': 400,
  27833. 'ograve': 500,
  27834. 'Ccaron': 667,
  27835. 'ugrave': 500,
  27836. 'radical': 453,
  27837. 'Dcaron': 722,
  27838. 'rcommaaccent': 389,
  27839. 'Ntilde': 667,
  27840. 'otilde': 500,
  27841. 'Rcommaaccent': 611,
  27842. 'Lcommaaccent': 556,
  27843. 'Atilde': 611,
  27844. 'Aogonek': 611,
  27845. 'Aring': 611,
  27846. 'Otilde': 722,
  27847. 'zdotaccent': 389,
  27848. 'Ecaron': 611,
  27849. 'Iogonek': 333,
  27850. 'kcommaaccent': 444,
  27851. 'minus': 675,
  27852. 'Icircumflex': 333,
  27853. 'ncaron': 500,
  27854. 'tcommaaccent': 278,
  27855. 'logicalnot': 675,
  27856. 'odieresis': 500,
  27857. 'udieresis': 500,
  27858. 'notequal': 549,
  27859. 'gcommaaccent': 500,
  27860. 'eth': 500,
  27861. 'zcaron': 389,
  27862. 'ncommaaccent': 500,
  27863. 'onesuperior': 300,
  27864. 'imacron': 278,
  27865. 'Euro': 500
  27866. },
  27867. 'ZapfDingbats': {
  27868. 'space': 278,
  27869. 'a1': 974,
  27870. 'a2': 961,
  27871. 'a202': 974,
  27872. 'a3': 980,
  27873. 'a4': 719,
  27874. 'a5': 789,
  27875. 'a119': 790,
  27876. 'a118': 791,
  27877. 'a117': 690,
  27878. 'a11': 960,
  27879. 'a12': 939,
  27880. 'a13': 549,
  27881. 'a14': 855,
  27882. 'a15': 911,
  27883. 'a16': 933,
  27884. 'a105': 911,
  27885. 'a17': 945,
  27886. 'a18': 974,
  27887. 'a19': 755,
  27888. 'a20': 846,
  27889. 'a21': 762,
  27890. 'a22': 761,
  27891. 'a23': 571,
  27892. 'a24': 677,
  27893. 'a25': 763,
  27894. 'a26': 760,
  27895. 'a27': 759,
  27896. 'a28': 754,
  27897. 'a6': 494,
  27898. 'a7': 552,
  27899. 'a8': 537,
  27900. 'a9': 577,
  27901. 'a10': 692,
  27902. 'a29': 786,
  27903. 'a30': 788,
  27904. 'a31': 788,
  27905. 'a32': 790,
  27906. 'a33': 793,
  27907. 'a34': 794,
  27908. 'a35': 816,
  27909. 'a36': 823,
  27910. 'a37': 789,
  27911. 'a38': 841,
  27912. 'a39': 823,
  27913. 'a40': 833,
  27914. 'a41': 816,
  27915. 'a42': 831,
  27916. 'a43': 923,
  27917. 'a44': 744,
  27918. 'a45': 723,
  27919. 'a46': 749,
  27920. 'a47': 790,
  27921. 'a48': 792,
  27922. 'a49': 695,
  27923. 'a50': 776,
  27924. 'a51': 768,
  27925. 'a52': 792,
  27926. 'a53': 759,
  27927. 'a54': 707,
  27928. 'a55': 708,
  27929. 'a56': 682,
  27930. 'a57': 701,
  27931. 'a58': 826,
  27932. 'a59': 815,
  27933. 'a60': 789,
  27934. 'a61': 789,
  27935. 'a62': 707,
  27936. 'a63': 687,
  27937. 'a64': 696,
  27938. 'a65': 689,
  27939. 'a66': 786,
  27940. 'a67': 787,
  27941. 'a68': 713,
  27942. 'a69': 791,
  27943. 'a70': 785,
  27944. 'a71': 791,
  27945. 'a72': 873,
  27946. 'a73': 761,
  27947. 'a74': 762,
  27948. 'a203': 762,
  27949. 'a75': 759,
  27950. 'a204': 759,
  27951. 'a76': 892,
  27952. 'a77': 892,
  27953. 'a78': 788,
  27954. 'a79': 784,
  27955. 'a81': 438,
  27956. 'a82': 138,
  27957. 'a83': 277,
  27958. 'a84': 415,
  27959. 'a97': 392,
  27960. 'a98': 392,
  27961. 'a99': 668,
  27962. 'a100': 668,
  27963. 'a89': 390,
  27964. 'a90': 390,
  27965. 'a93': 317,
  27966. 'a94': 317,
  27967. 'a91': 276,
  27968. 'a92': 276,
  27969. 'a205': 509,
  27970. 'a85': 509,
  27971. 'a206': 410,
  27972. 'a86': 410,
  27973. 'a87': 234,
  27974. 'a88': 234,
  27975. 'a95': 334,
  27976. 'a96': 334,
  27977. 'a101': 732,
  27978. 'a102': 544,
  27979. 'a103': 544,
  27980. 'a104': 910,
  27981. 'a106': 667,
  27982. 'a107': 760,
  27983. 'a108': 760,
  27984. 'a112': 776,
  27985. 'a111': 595,
  27986. 'a110': 694,
  27987. 'a109': 626,
  27988. 'a120': 788,
  27989. 'a121': 788,
  27990. 'a122': 788,
  27991. 'a123': 788,
  27992. 'a124': 788,
  27993. 'a125': 788,
  27994. 'a126': 788,
  27995. 'a127': 788,
  27996. 'a128': 788,
  27997. 'a129': 788,
  27998. 'a130': 788,
  27999. 'a131': 788,
  28000. 'a132': 788,
  28001. 'a133': 788,
  28002. 'a134': 788,
  28003. 'a135': 788,
  28004. 'a136': 788,
  28005. 'a137': 788,
  28006. 'a138': 788,
  28007. 'a139': 788,
  28008. 'a140': 788,
  28009. 'a141': 788,
  28010. 'a142': 788,
  28011. 'a143': 788,
  28012. 'a144': 788,
  28013. 'a145': 788,
  28014. 'a146': 788,
  28015. 'a147': 788,
  28016. 'a148': 788,
  28017. 'a149': 788,
  28018. 'a150': 788,
  28019. 'a151': 788,
  28020. 'a152': 788,
  28021. 'a153': 788,
  28022. 'a154': 788,
  28023. 'a155': 788,
  28024. 'a156': 788,
  28025. 'a157': 788,
  28026. 'a158': 788,
  28027. 'a159': 788,
  28028. 'a160': 894,
  28029. 'a161': 838,
  28030. 'a163': 1016,
  28031. 'a164': 458,
  28032. 'a196': 748,
  28033. 'a165': 924,
  28034. 'a192': 748,
  28035. 'a166': 918,
  28036. 'a167': 927,
  28037. 'a168': 928,
  28038. 'a169': 928,
  28039. 'a170': 834,
  28040. 'a171': 873,
  28041. 'a172': 828,
  28042. 'a173': 924,
  28043. 'a162': 924,
  28044. 'a174': 917,
  28045. 'a175': 930,
  28046. 'a176': 931,
  28047. 'a177': 463,
  28048. 'a178': 883,
  28049. 'a179': 836,
  28050. 'a193': 836,
  28051. 'a180': 867,
  28052. 'a199': 867,
  28053. 'a181': 696,
  28054. 'a200': 696,
  28055. 'a182': 874,
  28056. 'a201': 874,
  28057. 'a183': 760,
  28058. 'a184': 946,
  28059. 'a197': 771,
  28060. 'a185': 865,
  28061. 'a194': 771,
  28062. 'a198': 888,
  28063. 'a186': 967,
  28064. 'a195': 888,
  28065. 'a187': 831,
  28066. 'a188': 873,
  28067. 'a189': 927,
  28068. 'a190': 970,
  28069. 'a191': 918
  28070. }
  28071. };
  28072. var EOF = {};
  28073. function isEOF(v) {
  28074. return (v === EOF);
  28075. }
  28076. var Parser = (function ParserClosure() {
  28077. function Parser(lexer, allowStreams, xref) {
  28078. this.lexer = lexer;
  28079. this.allowStreams = allowStreams;
  28080. this.xref = xref;
  28081. this.imageCache = {
  28082. length: 0,
  28083. adler32: 0,
  28084. stream: null
  28085. };
  28086. this.refill();
  28087. }
  28088. Parser.prototype = {
  28089. refill: function Parser_refill() {
  28090. this.buf1 = this.lexer.getObj();
  28091. this.buf2 = this.lexer.getObj();
  28092. },
  28093. shift: function Parser_shift() {
  28094. if (isCmd(this.buf2, 'ID')) {
  28095. this.buf1 = this.buf2;
  28096. this.buf2 = null;
  28097. } else {
  28098. this.buf1 = this.buf2;
  28099. this.buf2 = this.lexer.getObj();
  28100. }
  28101. },
  28102. getObj: function Parser_getObj(cipherTransform) {
  28103. var buf1 = this.buf1;
  28104. this.shift();
  28105. if (buf1 instanceof Cmd) {
  28106. switch (buf1.cmd) {
  28107. case 'BI': // inline image
  28108. return this.makeInlineImage(cipherTransform);
  28109. case '[': // array
  28110. var array = [];
  28111. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28112. array.push(this.getObj(cipherTransform));
  28113. }
  28114. if (isEOF(this.buf1)) {
  28115. error('End of file inside array');
  28116. }
  28117. this.shift();
  28118. return array;
  28119. case '<<': // dictionary or stream
  28120. var dict = new Dict(this.xref);
  28121. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28122. if (!isName(this.buf1)) {
  28123. info('Malformed dictionary: key must be a name object');
  28124. this.shift();
  28125. continue;
  28126. }
  28127. var key = this.buf1.name;
  28128. this.shift();
  28129. if (isEOF(this.buf1)) {
  28130. break;
  28131. }
  28132. dict.set(key, this.getObj(cipherTransform));
  28133. }
  28134. if (isEOF(this.buf1)) {
  28135. error('End of file inside dictionary');
  28136. }
  28137. // Stream objects are not allowed inside content streams or
  28138. // object streams.
  28139. if (isCmd(this.buf2, 'stream')) {
  28140. return (this.allowStreams ?
  28141. this.makeStream(dict, cipherTransform) : dict);
  28142. }
  28143. this.shift();
  28144. return dict;
  28145. default: // simple object
  28146. return buf1;
  28147. }
  28148. }
  28149. if (isInt(buf1)) { // indirect reference or integer
  28150. var num = buf1;
  28151. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28152. var ref = new Ref(num, this.buf1);
  28153. this.shift();
  28154. this.shift();
  28155. return ref;
  28156. }
  28157. return num;
  28158. }
  28159. if (isString(buf1)) { // string
  28160. var str = buf1;
  28161. if (cipherTransform) {
  28162. str = cipherTransform.decryptString(str);
  28163. }
  28164. return str;
  28165. }
  28166. // simple object
  28167. return buf1;
  28168. },
  28169. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28170. var lexer = this.lexer;
  28171. var stream = lexer.stream;
  28172. // parse dictionary
  28173. var dict = new Dict(null);
  28174. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28175. if (!isName(this.buf1)) {
  28176. error('Dictionary key must be a name object');
  28177. }
  28178. var key = this.buf1.name;
  28179. this.shift();
  28180. if (isEOF(this.buf1)) {
  28181. break;
  28182. }
  28183. dict.set(key, this.getObj(cipherTransform));
  28184. }
  28185. // parse image stream
  28186. var startPos = stream.pos;
  28187. // searching for the /EI\s/
  28188. var state = 0, ch, i, ii;
  28189. var E = 0x45, I = 0x49, SPACE = 0x20, NL = 0xA, CR = 0xD;
  28190. while ((ch = stream.getByte()) !== -1) {
  28191. if (state === 0) {
  28192. state = (ch === E) ? 1 : 0;
  28193. } else if (state === 1) {
  28194. state = (ch === I) ? 2 : 0;
  28195. } else {
  28196. assert(state === 2);
  28197. if (ch === SPACE || ch === NL || ch === CR) {
  28198. // Let's check the next five bytes are ASCII... just be sure.
  28199. var n = 5;
  28200. var followingBytes = stream.peekBytes(n);
  28201. for (i = 0; i < n; i++) {
  28202. ch = followingBytes[i];
  28203. if (ch !== NL && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28204. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28205. // it's binary stuff. Resetting the state.
  28206. state = 0;
  28207. break;
  28208. }
  28209. }
  28210. if (state === 2) {
  28211. break; // finished!
  28212. }
  28213. } else {
  28214. state = 0;
  28215. }
  28216. }
  28217. }
  28218. var length = (stream.pos - 4) - startPos;
  28219. var imageStream = stream.makeSubStream(startPos, length, dict);
  28220. // trying to cache repeat images, first we are trying to "warm up" caching
  28221. // using length, then comparing adler32
  28222. var MAX_LENGTH_TO_CACHE = 1000;
  28223. var cacheImage = false, adler32;
  28224. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  28225. var imageBytes = imageStream.getBytes();
  28226. imageStream.reset();
  28227. var a = 1;
  28228. var b = 0;
  28229. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28230. a = (a + (imageBytes[i] & 0xff)) % 65521;
  28231. b = (b + a) % 65521;
  28232. }
  28233. adler32 = (b << 16) | a;
  28234. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  28235. this.buf2 = Cmd.get('EI');
  28236. this.shift();
  28237. this.imageCache.stream.reset();
  28238. return this.imageCache.stream;
  28239. }
  28240. cacheImage = true;
  28241. }
  28242. if (!cacheImage && !this.imageCache.stream) {
  28243. this.imageCache.length = length;
  28244. this.imageCache.stream = null;
  28245. }
  28246. if (cipherTransform) {
  28247. imageStream = cipherTransform.createStream(imageStream, length);
  28248. }
  28249. imageStream = this.filter(imageStream, dict, length);
  28250. imageStream.dict = dict;
  28251. if (cacheImage) {
  28252. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28253. this.imageCache.adler32 = adler32;
  28254. this.imageCache.stream = imageStream;
  28255. }
  28256. this.buf2 = Cmd.get('EI');
  28257. this.shift();
  28258. return imageStream;
  28259. },
  28260. fetchIfRef: function Parser_fetchIfRef(obj) {
  28261. // not relying on the xref.fetchIfRef -- xref might not be set
  28262. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28263. },
  28264. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28265. var lexer = this.lexer;
  28266. var stream = lexer.stream;
  28267. // get stream start position
  28268. lexer.skipToNextLine();
  28269. var pos = stream.pos - 1;
  28270. // get length
  28271. var length = this.fetchIfRef(dict.get('Length'));
  28272. if (!isInt(length)) {
  28273. info('Bad ' + length + ' attribute in stream');
  28274. length = 0;
  28275. }
  28276. // skip over the stream data
  28277. stream.pos = pos + length;
  28278. lexer.nextChar();
  28279. this.shift(); // '>>'
  28280. this.shift(); // 'stream'
  28281. if (!isCmd(this.buf1, 'endstream')) {
  28282. // bad stream length, scanning for endstream
  28283. stream.pos = pos;
  28284. var SCAN_BLOCK_SIZE = 2048;
  28285. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28286. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28287. 0x61, 0x6D];
  28288. var skipped = 0, found = false, i, j;
  28289. while (stream.pos < stream.end) {
  28290. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28291. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28292. if (scanLength <= 0) {
  28293. break;
  28294. }
  28295. found = false;
  28296. for (i = 0, j = 0; i < scanLength; i++) {
  28297. var b = scanBytes[i];
  28298. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28299. i -= j;
  28300. j = 0;
  28301. } else {
  28302. j++;
  28303. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28304. i++;
  28305. found = true;
  28306. break;
  28307. }
  28308. }
  28309. }
  28310. if (found) {
  28311. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28312. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28313. break;
  28314. }
  28315. skipped += scanLength;
  28316. stream.pos += scanLength;
  28317. }
  28318. if (!found) {
  28319. error('Missing endstream');
  28320. }
  28321. length = skipped;
  28322. lexer.nextChar();
  28323. this.shift();
  28324. this.shift();
  28325. }
  28326. this.shift(); // 'endstream'
  28327. stream = stream.makeSubStream(pos, length, dict);
  28328. if (cipherTransform) {
  28329. stream = cipherTransform.createStream(stream, length);
  28330. }
  28331. stream = this.filter(stream, dict, length);
  28332. stream.dict = dict;
  28333. return stream;
  28334. },
  28335. filter: function Parser_filter(stream, dict, length) {
  28336. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28337. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28338. if (isName(filter)) {
  28339. return this.makeFilter(stream, filter.name, length, params);
  28340. }
  28341. var maybeLength = length;
  28342. if (isArray(filter)) {
  28343. var filterArray = filter;
  28344. var paramsArray = params;
  28345. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28346. filter = filterArray[i];
  28347. if (!isName(filter)) {
  28348. error('Bad filter name: ' + filter);
  28349. }
  28350. params = null;
  28351. if (isArray(paramsArray) && (i in paramsArray)) {
  28352. params = paramsArray[i];
  28353. }
  28354. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28355. // after the first stream the length variable is invalid
  28356. maybeLength = null;
  28357. }
  28358. }
  28359. return stream;
  28360. },
  28361. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28362. if (stream.dict.get('Length') === 0) {
  28363. return new NullStream(stream);
  28364. }
  28365. try {
  28366. if (params) {
  28367. params = this.fetchIfRef(params);
  28368. }
  28369. var xrefStreamStats = this.xref.stats.streamTypes;
  28370. if (name === 'FlateDecode' || name === 'Fl') {
  28371. xrefStreamStats[StreamType.FLATE] = true;
  28372. if (params) {
  28373. return new PredictorStream(new FlateStream(stream, maybeLength),
  28374. maybeLength, params);
  28375. }
  28376. return new FlateStream(stream, maybeLength);
  28377. }
  28378. if (name === 'LZWDecode' || name === 'LZW') {
  28379. xrefStreamStats[StreamType.LZW] = true;
  28380. var earlyChange = 1;
  28381. if (params) {
  28382. if (params.has('EarlyChange')) {
  28383. earlyChange = params.get('EarlyChange');
  28384. }
  28385. return new PredictorStream(
  28386. new LZWStream(stream, maybeLength, earlyChange),
  28387. maybeLength, params);
  28388. }
  28389. return new LZWStream(stream, maybeLength, earlyChange);
  28390. }
  28391. if (name === 'DCTDecode' || name === 'DCT') {
  28392. // According to the specification: for inline images, the ID operator
  28393. // shall be followed by a single whitespace character (unless it uses
  28394. // ASCII85Decode or ASCIIHexDecode filters).
  28395. // In practice this only seems to be followed for inline JPEG images,
  28396. // and generally ignoring the first byte of the stream if it is a
  28397. // whitespace char can even *cause* issues (e.g. in the CCITTFaxDecode
  28398. // filters used in issue2984.pdf).
  28399. // Hence when the first byte of the stream of an inline JPEG image is
  28400. // a whitespace character, we thus simply skip over it.
  28401. if (isCmd(this.buf1, 'ID')) {
  28402. var firstByte = stream.peekByte();
  28403. if (firstByte === 0x0A /* LF */ || firstByte === 0x0D /* CR */ ||
  28404. firstByte === 0x20 /* SPACE */) {
  28405. stream.skip();
  28406. }
  28407. }
  28408. xrefStreamStats[StreamType.DCT] = true;
  28409. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28410. }
  28411. if (name === 'JPXDecode' || name === 'JPX') {
  28412. xrefStreamStats[StreamType.JPX] = true;
  28413. return new JpxStream(stream, maybeLength, stream.dict);
  28414. }
  28415. if (name === 'ASCII85Decode' || name === 'A85') {
  28416. xrefStreamStats[StreamType.A85] = true;
  28417. return new Ascii85Stream(stream, maybeLength);
  28418. }
  28419. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28420. xrefStreamStats[StreamType.AHX] = true;
  28421. return new AsciiHexStream(stream, maybeLength);
  28422. }
  28423. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28424. xrefStreamStats[StreamType.CCF] = true;
  28425. return new CCITTFaxStream(stream, maybeLength, params);
  28426. }
  28427. if (name === 'RunLengthDecode' || name === 'RL') {
  28428. xrefStreamStats[StreamType.RL] = true;
  28429. return new RunLengthStream(stream, maybeLength);
  28430. }
  28431. if (name === 'JBIG2Decode') {
  28432. xrefStreamStats[StreamType.JBIG] = true;
  28433. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28434. }
  28435. warn('filter "' + name + '" not supported yet');
  28436. return stream;
  28437. } catch (ex) {
  28438. if (ex instanceof MissingDataException) {
  28439. throw ex;
  28440. }
  28441. warn('Invalid stream: \"' + ex + '\"');
  28442. return new NullStream(stream);
  28443. }
  28444. }
  28445. };
  28446. return Parser;
  28447. })();
  28448. var Lexer = (function LexerClosure() {
  28449. function Lexer(stream, knownCommands) {
  28450. this.stream = stream;
  28451. this.nextChar();
  28452. // While lexing, we build up many strings one char at a time. Using += for
  28453. // this can result in lots of garbage strings. It's better to build an
  28454. // array of single-char strings and then join() them together at the end.
  28455. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28456. // purpose uses less memory than using a new array for each string.
  28457. this.strBuf = [];
  28458. // The PDFs might have "glued" commands with other commands, operands or
  28459. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28460. // commands and their prefixes. The prefixes are built the following way:
  28461. // if there a command that is a prefix of the other valid command or
  28462. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28463. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28464. // other commands or literals as a prefix. The knowCommands is optional.
  28465. this.knownCommands = knownCommands;
  28466. }
  28467. Lexer.isSpace = function Lexer_isSpace(ch) {
  28468. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28469. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28470. };
  28471. // A '1' in this array means the character is white space. A '1' or
  28472. // '2' means the character ends a name or command.
  28473. var specialChars = [
  28474. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28476. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28490. ];
  28491. function toHexDigit(ch) {
  28492. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28493. return ch & 0x0F;
  28494. }
  28495. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28496. // 'A'-'F', 'a'-'f'
  28497. return (ch & 0x0F) + 9;
  28498. }
  28499. return -1;
  28500. }
  28501. Lexer.prototype = {
  28502. nextChar: function Lexer_nextChar() {
  28503. return (this.currentChar = this.stream.getByte());
  28504. },
  28505. peekChar: function Lexer_peekChar() {
  28506. return this.stream.peekByte();
  28507. },
  28508. getNumber: function Lexer_getNumber() {
  28509. var ch = this.currentChar;
  28510. var eNotation = false;
  28511. var divideBy = 0; // different from 0 if it's a floating point value
  28512. var sign = 1;
  28513. if (ch === 0x2D) { // '-'
  28514. sign = -1;
  28515. ch = this.nextChar();
  28516. } else if (ch === 0x2B) { // '+'
  28517. ch = this.nextChar();
  28518. }
  28519. if (ch === 0x2E) { // '.'
  28520. divideBy = 10;
  28521. ch = this.nextChar();
  28522. }
  28523. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28524. error('Invalid number: ' + String.fromCharCode(ch));
  28525. return 0;
  28526. }
  28527. var baseValue = ch - 0x30; // '0'
  28528. var powerValue = 0;
  28529. var powerValueSign = 1;
  28530. while ((ch = this.nextChar()) >= 0) {
  28531. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28532. var currentDigit = ch - 0x30; // '0'
  28533. if (eNotation) { // We are after an 'e' or 'E'
  28534. powerValue = powerValue * 10 + currentDigit;
  28535. } else {
  28536. if (divideBy !== 0) { // We are after a point
  28537. divideBy *= 10;
  28538. }
  28539. baseValue = baseValue * 10 + currentDigit;
  28540. }
  28541. } else if (ch === 0x2E) { // '.'
  28542. if (divideBy === 0) {
  28543. divideBy = 1;
  28544. } else {
  28545. // A number can have only one '.'
  28546. break;
  28547. }
  28548. } else if (ch === 0x2D) { // '-'
  28549. // ignore minus signs in the middle of numbers to match
  28550. // Adobe's behavior
  28551. warn('Badly formated number');
  28552. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28553. // 'E' can be either a scientific notation or the beginning of a new
  28554. // operator
  28555. ch = this.peekChar();
  28556. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28557. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28558. this.nextChar(); // Consume the sign character
  28559. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28560. // The 'E' must be the beginning of a new operator
  28561. break;
  28562. }
  28563. eNotation = true;
  28564. } else {
  28565. // the last character doesn't belong to us
  28566. break;
  28567. }
  28568. }
  28569. if (divideBy !== 0) {
  28570. baseValue /= divideBy;
  28571. }
  28572. if (eNotation) {
  28573. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28574. }
  28575. return sign * baseValue;
  28576. },
  28577. getString: function Lexer_getString() {
  28578. var numParen = 1;
  28579. var done = false;
  28580. var strBuf = this.strBuf;
  28581. strBuf.length = 0;
  28582. var ch = this.nextChar();
  28583. while (true) {
  28584. var charBuffered = false;
  28585. switch (ch | 0) {
  28586. case -1:
  28587. warn('Unterminated string');
  28588. done = true;
  28589. break;
  28590. case 0x28: // '('
  28591. ++numParen;
  28592. strBuf.push('(');
  28593. break;
  28594. case 0x29: // ')'
  28595. if (--numParen === 0) {
  28596. this.nextChar(); // consume strings ')'
  28597. done = true;
  28598. } else {
  28599. strBuf.push(')');
  28600. }
  28601. break;
  28602. case 0x5C: // '\\'
  28603. ch = this.nextChar();
  28604. switch (ch) {
  28605. case -1:
  28606. warn('Unterminated string');
  28607. done = true;
  28608. break;
  28609. case 0x6E: // 'n'
  28610. strBuf.push('\n');
  28611. break;
  28612. case 0x72: // 'r'
  28613. strBuf.push('\r');
  28614. break;
  28615. case 0x74: // 't'
  28616. strBuf.push('\t');
  28617. break;
  28618. case 0x62: // 'b'
  28619. strBuf.push('\b');
  28620. break;
  28621. case 0x66: // 'f'
  28622. strBuf.push('\f');
  28623. break;
  28624. case 0x5C: // '\'
  28625. case 0x28: // '('
  28626. case 0x29: // ')'
  28627. strBuf.push(String.fromCharCode(ch));
  28628. break;
  28629. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28630. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28631. var x = ch & 0x0F;
  28632. ch = this.nextChar();
  28633. charBuffered = true;
  28634. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28635. x = (x << 3) + (ch & 0x0F);
  28636. ch = this.nextChar();
  28637. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28638. charBuffered = false;
  28639. x = (x << 3) + (ch & 0x0F);
  28640. }
  28641. }
  28642. strBuf.push(String.fromCharCode(x));
  28643. break;
  28644. case 0x0D: // CR
  28645. if (this.peekChar() === 0x0A) { // LF
  28646. this.nextChar();
  28647. }
  28648. break;
  28649. case 0x0A: // LF
  28650. break;
  28651. default:
  28652. strBuf.push(String.fromCharCode(ch));
  28653. break;
  28654. }
  28655. break;
  28656. default:
  28657. strBuf.push(String.fromCharCode(ch));
  28658. break;
  28659. }
  28660. if (done) {
  28661. break;
  28662. }
  28663. if (!charBuffered) {
  28664. ch = this.nextChar();
  28665. }
  28666. }
  28667. return strBuf.join('');
  28668. },
  28669. getName: function Lexer_getName() {
  28670. var ch;
  28671. var strBuf = this.strBuf;
  28672. strBuf.length = 0;
  28673. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28674. if (ch === 0x23) { // '#'
  28675. ch = this.nextChar();
  28676. var x = toHexDigit(ch);
  28677. if (x !== -1) {
  28678. var x2 = toHexDigit(this.nextChar());
  28679. if (x2 === -1) {
  28680. error('Illegal digit in hex char in name: ' + x2);
  28681. }
  28682. strBuf.push(String.fromCharCode((x << 4) | x2));
  28683. } else {
  28684. strBuf.push('#', String.fromCharCode(ch));
  28685. }
  28686. } else {
  28687. strBuf.push(String.fromCharCode(ch));
  28688. }
  28689. }
  28690. if (strBuf.length > 128) {
  28691. error('Warning: name token is longer than allowed by the spec: ' +
  28692. strBuf.length);
  28693. }
  28694. return Name.get(strBuf.join(''));
  28695. },
  28696. getHexString: function Lexer_getHexString() {
  28697. var strBuf = this.strBuf;
  28698. strBuf.length = 0;
  28699. var ch = this.currentChar;
  28700. var isFirstHex = true;
  28701. var firstDigit;
  28702. var secondDigit;
  28703. while (true) {
  28704. if (ch < 0) {
  28705. warn('Unterminated hex string');
  28706. break;
  28707. } else if (ch === 0x3E) { // '>'
  28708. this.nextChar();
  28709. break;
  28710. } else if (specialChars[ch] === 1) {
  28711. ch = this.nextChar();
  28712. continue;
  28713. } else {
  28714. if (isFirstHex) {
  28715. firstDigit = toHexDigit(ch);
  28716. if (firstDigit === -1) {
  28717. warn('Ignoring invalid character "' + ch + '" in hex string');
  28718. ch = this.nextChar();
  28719. continue;
  28720. }
  28721. } else {
  28722. secondDigit = toHexDigit(ch);
  28723. if (secondDigit === -1) {
  28724. warn('Ignoring invalid character "' + ch + '" in hex string');
  28725. ch = this.nextChar();
  28726. continue;
  28727. }
  28728. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28729. }
  28730. isFirstHex = !isFirstHex;
  28731. ch = this.nextChar();
  28732. }
  28733. }
  28734. return strBuf.join('');
  28735. },
  28736. getObj: function Lexer_getObj() {
  28737. // skip whitespace and comments
  28738. var comment = false;
  28739. var ch = this.currentChar;
  28740. while (true) {
  28741. if (ch < 0) {
  28742. return EOF;
  28743. }
  28744. if (comment) {
  28745. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28746. comment = false;
  28747. }
  28748. } else if (ch === 0x25) { // '%'
  28749. comment = true;
  28750. } else if (specialChars[ch] !== 1) {
  28751. break;
  28752. }
  28753. ch = this.nextChar();
  28754. }
  28755. // start reading token
  28756. switch (ch | 0) {
  28757. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28758. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28759. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28760. return this.getNumber();
  28761. case 0x28: // '('
  28762. return this.getString();
  28763. case 0x2F: // '/'
  28764. return this.getName();
  28765. // array punctuation
  28766. case 0x5B: // '['
  28767. this.nextChar();
  28768. return Cmd.get('[');
  28769. case 0x5D: // ']'
  28770. this.nextChar();
  28771. return Cmd.get(']');
  28772. // hex string or dict punctuation
  28773. case 0x3C: // '<'
  28774. ch = this.nextChar();
  28775. if (ch === 0x3C) {
  28776. // dict punctuation
  28777. this.nextChar();
  28778. return Cmd.get('<<');
  28779. }
  28780. return this.getHexString();
  28781. // dict punctuation
  28782. case 0x3E: // '>'
  28783. ch = this.nextChar();
  28784. if (ch === 0x3E) {
  28785. this.nextChar();
  28786. return Cmd.get('>>');
  28787. }
  28788. return Cmd.get('>');
  28789. case 0x7B: // '{'
  28790. this.nextChar();
  28791. return Cmd.get('{');
  28792. case 0x7D: // '}'
  28793. this.nextChar();
  28794. return Cmd.get('}');
  28795. case 0x29: // ')'
  28796. error('Illegal character: ' + ch);
  28797. break;
  28798. }
  28799. // command
  28800. var str = String.fromCharCode(ch);
  28801. var knownCommands = this.knownCommands;
  28802. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28803. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28804. // stop if known command is found and next character does not make
  28805. // the str a command
  28806. var possibleCommand = str + String.fromCharCode(ch);
  28807. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28808. break;
  28809. }
  28810. if (str.length === 128) {
  28811. error('Command token too long: ' + str.length);
  28812. }
  28813. str = possibleCommand;
  28814. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28815. }
  28816. if (str === 'true') {
  28817. return true;
  28818. }
  28819. if (str === 'false') {
  28820. return false;
  28821. }
  28822. if (str === 'null') {
  28823. return null;
  28824. }
  28825. return Cmd.get(str);
  28826. },
  28827. skipToNextLine: function Lexer_skipToNextLine() {
  28828. var ch = this.currentChar;
  28829. while (ch >= 0) {
  28830. if (ch === 0x0D) { // CR
  28831. ch = this.nextChar();
  28832. if (ch === 0x0A) { // LF
  28833. this.nextChar();
  28834. }
  28835. break;
  28836. } else if (ch === 0x0A) { // LF
  28837. this.nextChar();
  28838. break;
  28839. }
  28840. ch = this.nextChar();
  28841. }
  28842. }
  28843. };
  28844. return Lexer;
  28845. })();
  28846. var Linearization = {
  28847. create: function LinearizationCreate(stream) {
  28848. function getInt(name, allowZeroValue) {
  28849. var obj = linDict.get(name);
  28850. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28851. return obj;
  28852. }
  28853. throw new Error('The "' + name + '" parameter in the linearization ' +
  28854. 'dictionary is invalid.');
  28855. }
  28856. function getHints() {
  28857. var hints = linDict.get('H'), hintsLength, item;
  28858. if (isArray(hints) &&
  28859. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28860. for (var index = 0; index < hintsLength; index++) {
  28861. if (!(isInt(item = hints[index]) && item > 0)) {
  28862. throw new Error('Hint (' + index +
  28863. ') in the linearization dictionary is invalid.');
  28864. }
  28865. }
  28866. return hints;
  28867. }
  28868. throw new Error('Hint array in the linearization dictionary is invalid.');
  28869. }
  28870. var parser = new Parser(new Lexer(stream), false, null);
  28871. var obj1 = parser.getObj();
  28872. var obj2 = parser.getObj();
  28873. var obj3 = parser.getObj();
  28874. var linDict = parser.getObj();
  28875. var obj, length;
  28876. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28877. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28878. return null; // No valid linearization dictionary found.
  28879. } else if ((length = getInt('L')) !== stream.length) {
  28880. throw new Error('The "L" parameter in the linearization dictionary ' +
  28881. 'does not equal the stream length.');
  28882. }
  28883. return {
  28884. length: length,
  28885. hints: getHints(),
  28886. objectNumberFirst: getInt('O'),
  28887. endFirst: getInt('E'),
  28888. numPages: getInt('N'),
  28889. mainXRefEntriesOffset: getInt('T'),
  28890. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28891. };
  28892. }
  28893. };
  28894. var PostScriptParser = (function PostScriptParserClosure() {
  28895. function PostScriptParser(lexer) {
  28896. this.lexer = lexer;
  28897. this.operators = [];
  28898. this.token = null;
  28899. this.prev = null;
  28900. }
  28901. PostScriptParser.prototype = {
  28902. nextToken: function PostScriptParser_nextToken() {
  28903. this.prev = this.token;
  28904. this.token = this.lexer.getToken();
  28905. },
  28906. accept: function PostScriptParser_accept(type) {
  28907. if (this.token.type === type) {
  28908. this.nextToken();
  28909. return true;
  28910. }
  28911. return false;
  28912. },
  28913. expect: function PostScriptParser_expect(type) {
  28914. if (this.accept(type)) {
  28915. return true;
  28916. }
  28917. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  28918. type + '.');
  28919. },
  28920. parse: function PostScriptParser_parse() {
  28921. this.nextToken();
  28922. this.expect(PostScriptTokenTypes.LBRACE);
  28923. this.parseBlock();
  28924. this.expect(PostScriptTokenTypes.RBRACE);
  28925. return this.operators;
  28926. },
  28927. parseBlock: function PostScriptParser_parseBlock() {
  28928. while (true) {
  28929. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  28930. this.operators.push(this.prev.value);
  28931. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  28932. this.operators.push(this.prev.value);
  28933. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28934. this.parseCondition();
  28935. } else {
  28936. return;
  28937. }
  28938. }
  28939. },
  28940. parseCondition: function PostScriptParser_parseCondition() {
  28941. // Add two place holders that will be updated later
  28942. var conditionLocation = this.operators.length;
  28943. this.operators.push(null, null);
  28944. this.parseBlock();
  28945. this.expect(PostScriptTokenTypes.RBRACE);
  28946. if (this.accept(PostScriptTokenTypes.IF)) {
  28947. // The true block is right after the 'if' so it just falls through on
  28948. // true else it jumps and skips the true block.
  28949. this.operators[conditionLocation] = this.operators.length;
  28950. this.operators[conditionLocation + 1] = 'jz';
  28951. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28952. var jumpLocation = this.operators.length;
  28953. this.operators.push(null, null);
  28954. var endOfTrue = this.operators.length;
  28955. this.parseBlock();
  28956. this.expect(PostScriptTokenTypes.RBRACE);
  28957. this.expect(PostScriptTokenTypes.IFELSE);
  28958. // The jump is added at the end of the true block to skip the false
  28959. // block.
  28960. this.operators[jumpLocation] = this.operators.length;
  28961. this.operators[jumpLocation + 1] = 'j';
  28962. this.operators[conditionLocation] = endOfTrue;
  28963. this.operators[conditionLocation + 1] = 'jz';
  28964. } else {
  28965. error('PS Function: error parsing conditional.');
  28966. }
  28967. }
  28968. };
  28969. return PostScriptParser;
  28970. })();
  28971. var PostScriptTokenTypes = {
  28972. LBRACE: 0,
  28973. RBRACE: 1,
  28974. NUMBER: 2,
  28975. OPERATOR: 3,
  28976. IF: 4,
  28977. IFELSE: 5
  28978. };
  28979. var PostScriptToken = (function PostScriptTokenClosure() {
  28980. function PostScriptToken(type, value) {
  28981. this.type = type;
  28982. this.value = value;
  28983. }
  28984. var opCache = {};
  28985. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  28986. var opValue = opCache[op];
  28987. if (opValue) {
  28988. return opValue;
  28989. }
  28990. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  28991. };
  28992. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  28993. '{');
  28994. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  28995. '}');
  28996. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  28997. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  28998. 'IFELSE');
  28999. return PostScriptToken;
  29000. })();
  29001. var PostScriptLexer = (function PostScriptLexerClosure() {
  29002. function PostScriptLexer(stream) {
  29003. this.stream = stream;
  29004. this.nextChar();
  29005. this.strBuf = [];
  29006. }
  29007. PostScriptLexer.prototype = {
  29008. nextChar: function PostScriptLexer_nextChar() {
  29009. return (this.currentChar = this.stream.getByte());
  29010. },
  29011. getToken: function PostScriptLexer_getToken() {
  29012. var comment = false;
  29013. var ch = this.currentChar;
  29014. // skip comments
  29015. while (true) {
  29016. if (ch < 0) {
  29017. return EOF;
  29018. }
  29019. if (comment) {
  29020. if (ch === 0x0A || ch === 0x0D) {
  29021. comment = false;
  29022. }
  29023. } else if (ch === 0x25) { // '%'
  29024. comment = true;
  29025. } else if (!Lexer.isSpace(ch)) {
  29026. break;
  29027. }
  29028. ch = this.nextChar();
  29029. }
  29030. switch (ch | 0) {
  29031. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29032. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29033. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29034. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29035. this.getNumber());
  29036. case 0x7B: // '{'
  29037. this.nextChar();
  29038. return PostScriptToken.LBRACE;
  29039. case 0x7D: // '}'
  29040. this.nextChar();
  29041. return PostScriptToken.RBRACE;
  29042. }
  29043. // operator
  29044. var strBuf = this.strBuf;
  29045. strBuf.length = 0;
  29046. strBuf[0] = String.fromCharCode(ch);
  29047. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29048. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29049. strBuf.push(String.fromCharCode(ch));
  29050. }
  29051. var str = strBuf.join('');
  29052. switch (str.toLowerCase()) {
  29053. case 'if':
  29054. return PostScriptToken.IF;
  29055. case 'ifelse':
  29056. return PostScriptToken.IFELSE;
  29057. default:
  29058. return PostScriptToken.getOperator(str);
  29059. }
  29060. },
  29061. getNumber: function PostScriptLexer_getNumber() {
  29062. var ch = this.currentChar;
  29063. var strBuf = this.strBuf;
  29064. strBuf.length = 0;
  29065. strBuf[0] = String.fromCharCode(ch);
  29066. while ((ch = this.nextChar()) >= 0) {
  29067. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29068. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29069. strBuf.push(String.fromCharCode(ch));
  29070. } else {
  29071. break;
  29072. }
  29073. }
  29074. var value = parseFloat(strBuf.join(''));
  29075. if (isNaN(value)) {
  29076. error('Invalid floating point number: ' + value);
  29077. }
  29078. return value;
  29079. }
  29080. };
  29081. return PostScriptLexer;
  29082. })();
  29083. var Stream = (function StreamClosure() {
  29084. function Stream(arrayBuffer, start, length, dict) {
  29085. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29086. arrayBuffer : new Uint8Array(arrayBuffer));
  29087. this.start = start || 0;
  29088. this.pos = this.start;
  29089. this.end = (start + length) || this.bytes.length;
  29090. this.dict = dict;
  29091. }
  29092. // required methods for a stream. if a particular stream does not
  29093. // implement these, an error should be thrown
  29094. Stream.prototype = {
  29095. get length() {
  29096. return this.end - this.start;
  29097. },
  29098. get isEmpty() {
  29099. return this.length === 0;
  29100. },
  29101. getByte: function Stream_getByte() {
  29102. if (this.pos >= this.end) {
  29103. return -1;
  29104. }
  29105. return this.bytes[this.pos++];
  29106. },
  29107. getUint16: function Stream_getUint16() {
  29108. var b0 = this.getByte();
  29109. var b1 = this.getByte();
  29110. return (b0 << 8) + b1;
  29111. },
  29112. getInt32: function Stream_getInt32() {
  29113. var b0 = this.getByte();
  29114. var b1 = this.getByte();
  29115. var b2 = this.getByte();
  29116. var b3 = this.getByte();
  29117. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29118. },
  29119. // returns subarray of original buffer
  29120. // should only be read
  29121. getBytes: function Stream_getBytes(length) {
  29122. var bytes = this.bytes;
  29123. var pos = this.pos;
  29124. var strEnd = this.end;
  29125. if (!length) {
  29126. return bytes.subarray(pos, strEnd);
  29127. }
  29128. var end = pos + length;
  29129. if (end > strEnd) {
  29130. end = strEnd;
  29131. }
  29132. this.pos = end;
  29133. return bytes.subarray(pos, end);
  29134. },
  29135. peekByte: function Stream_peekByte() {
  29136. var peekedByte = this.getByte();
  29137. this.pos--;
  29138. return peekedByte;
  29139. },
  29140. peekBytes: function Stream_peekBytes(length) {
  29141. var bytes = this.getBytes(length);
  29142. this.pos -= bytes.length;
  29143. return bytes;
  29144. },
  29145. skip: function Stream_skip(n) {
  29146. if (!n) {
  29147. n = 1;
  29148. }
  29149. this.pos += n;
  29150. },
  29151. reset: function Stream_reset() {
  29152. this.pos = this.start;
  29153. },
  29154. moveStart: function Stream_moveStart() {
  29155. this.start = this.pos;
  29156. },
  29157. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29158. return new Stream(this.bytes.buffer, start, length, dict);
  29159. },
  29160. isStream: true
  29161. };
  29162. return Stream;
  29163. })();
  29164. var StringStream = (function StringStreamClosure() {
  29165. function StringStream(str) {
  29166. var length = str.length;
  29167. var bytes = new Uint8Array(length);
  29168. for (var n = 0; n < length; ++n) {
  29169. bytes[n] = str.charCodeAt(n);
  29170. }
  29171. Stream.call(this, bytes);
  29172. }
  29173. StringStream.prototype = Stream.prototype;
  29174. return StringStream;
  29175. })();
  29176. // super class for the decoding streams
  29177. var DecodeStream = (function DecodeStreamClosure() {
  29178. // Lots of DecodeStreams are created whose buffers are never used. For these
  29179. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29180. // having special cases that would be required if we used |null| for an empty
  29181. // buffer.
  29182. var emptyBuffer = new Uint8Array(0);
  29183. function DecodeStream(maybeMinBufferLength) {
  29184. this.pos = 0;
  29185. this.bufferLength = 0;
  29186. this.eof = false;
  29187. this.buffer = emptyBuffer;
  29188. this.minBufferLength = 512;
  29189. if (maybeMinBufferLength) {
  29190. // Compute the first power of two that is as big as maybeMinBufferLength.
  29191. while (this.minBufferLength < maybeMinBufferLength) {
  29192. this.minBufferLength *= 2;
  29193. }
  29194. }
  29195. }
  29196. DecodeStream.prototype = {
  29197. get isEmpty() {
  29198. while (!this.eof && this.bufferLength === 0) {
  29199. this.readBlock();
  29200. }
  29201. return this.bufferLength === 0;
  29202. },
  29203. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29204. var buffer = this.buffer;
  29205. if (requested <= buffer.byteLength) {
  29206. return buffer;
  29207. }
  29208. var size = this.minBufferLength;
  29209. while (size < requested) {
  29210. size *= 2;
  29211. }
  29212. var buffer2 = new Uint8Array(size);
  29213. buffer2.set(buffer);
  29214. return (this.buffer = buffer2);
  29215. },
  29216. getByte: function DecodeStream_getByte() {
  29217. var pos = this.pos;
  29218. while (this.bufferLength <= pos) {
  29219. if (this.eof) {
  29220. return -1;
  29221. }
  29222. this.readBlock();
  29223. }
  29224. return this.buffer[this.pos++];
  29225. },
  29226. getUint16: function DecodeStream_getUint16() {
  29227. var b0 = this.getByte();
  29228. var b1 = this.getByte();
  29229. return (b0 << 8) + b1;
  29230. },
  29231. getInt32: function DecodeStream_getInt32() {
  29232. var b0 = this.getByte();
  29233. var b1 = this.getByte();
  29234. var b2 = this.getByte();
  29235. var b3 = this.getByte();
  29236. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29237. },
  29238. getBytes: function DecodeStream_getBytes(length) {
  29239. var end, pos = this.pos;
  29240. if (length) {
  29241. this.ensureBuffer(pos + length);
  29242. end = pos + length;
  29243. while (!this.eof && this.bufferLength < end) {
  29244. this.readBlock();
  29245. }
  29246. var bufEnd = this.bufferLength;
  29247. if (end > bufEnd) {
  29248. end = bufEnd;
  29249. }
  29250. } else {
  29251. while (!this.eof) {
  29252. this.readBlock();
  29253. }
  29254. end = this.bufferLength;
  29255. }
  29256. this.pos = end;
  29257. return this.buffer.subarray(pos, end);
  29258. },
  29259. peekByte: function DecodeStream_peekByte() {
  29260. var peekedByte = this.getByte();
  29261. this.pos--;
  29262. return peekedByte;
  29263. },
  29264. peekBytes: function DecodeStream_peekBytes(length) {
  29265. var bytes = this.getBytes(length);
  29266. this.pos -= bytes.length;
  29267. return bytes;
  29268. },
  29269. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29270. var end = start + length;
  29271. while (this.bufferLength <= end && !this.eof) {
  29272. this.readBlock();
  29273. }
  29274. return new Stream(this.buffer, start, length, dict);
  29275. },
  29276. skip: function DecodeStream_skip(n) {
  29277. if (!n) {
  29278. n = 1;
  29279. }
  29280. this.pos += n;
  29281. },
  29282. reset: function DecodeStream_reset() {
  29283. this.pos = 0;
  29284. },
  29285. getBaseStreams: function DecodeStream_getBaseStreams() {
  29286. if (this.str && this.str.getBaseStreams) {
  29287. return this.str.getBaseStreams();
  29288. }
  29289. return [];
  29290. }
  29291. };
  29292. return DecodeStream;
  29293. })();
  29294. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29295. function StreamsSequenceStream(streams) {
  29296. this.streams = streams;
  29297. DecodeStream.call(this, /* maybeLength = */ null);
  29298. }
  29299. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29300. StreamsSequenceStream.prototype.readBlock =
  29301. function streamSequenceStreamReadBlock() {
  29302. var streams = this.streams;
  29303. if (streams.length === 0) {
  29304. this.eof = true;
  29305. return;
  29306. }
  29307. var stream = streams.shift();
  29308. var chunk = stream.getBytes();
  29309. var bufferLength = this.bufferLength;
  29310. var newLength = bufferLength + chunk.length;
  29311. var buffer = this.ensureBuffer(newLength);
  29312. buffer.set(chunk, bufferLength);
  29313. this.bufferLength = newLength;
  29314. };
  29315. StreamsSequenceStream.prototype.getBaseStreams =
  29316. function StreamsSequenceStream_getBaseStreams() {
  29317. var baseStreams = [];
  29318. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29319. var stream = this.streams[i];
  29320. if (stream.getBaseStreams) {
  29321. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29322. }
  29323. }
  29324. return baseStreams;
  29325. };
  29326. return StreamsSequenceStream;
  29327. })();
  29328. var FlateStream = (function FlateStreamClosure() {
  29329. var codeLenCodeMap = new Uint32Array([
  29330. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29331. ]);
  29332. var lengthDecode = new Uint32Array([
  29333. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29334. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29335. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29336. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29337. ]);
  29338. var distDecode = new Uint32Array([
  29339. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29340. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29341. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29342. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29343. ]);
  29344. var fixedLitCodeTab = [new Uint32Array([
  29345. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29346. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29347. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29348. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29349. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29350. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29351. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29352. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29353. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29354. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29355. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29356. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29357. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29358. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29359. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29360. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29361. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29362. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29363. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29364. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29365. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29366. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29367. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29368. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29369. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29370. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29371. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29372. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29373. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29374. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29375. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29376. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29377. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29378. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29379. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29380. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29381. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29382. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29383. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29384. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29385. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29386. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29387. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29388. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29389. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29390. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29391. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29392. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29393. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29394. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29395. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29396. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29397. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29398. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29399. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29400. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29401. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29402. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29403. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29404. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29405. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29406. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29407. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29408. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29409. ]), 9];
  29410. var fixedDistCodeTab = [new Uint32Array([
  29411. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29412. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29413. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29414. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29415. ]), 5];
  29416. function FlateStream(str, maybeLength) {
  29417. this.str = str;
  29418. this.dict = str.dict;
  29419. var cmf = str.getByte();
  29420. var flg = str.getByte();
  29421. if (cmf === -1 || flg === -1) {
  29422. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29423. }
  29424. if ((cmf & 0x0f) !== 0x08) {
  29425. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29426. }
  29427. if ((((cmf << 8) + flg) % 31) !== 0) {
  29428. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29429. }
  29430. if (flg & 0x20) {
  29431. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29432. }
  29433. this.codeSize = 0;
  29434. this.codeBuf = 0;
  29435. DecodeStream.call(this, maybeLength);
  29436. }
  29437. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29438. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29439. var str = this.str;
  29440. var codeSize = this.codeSize;
  29441. var codeBuf = this.codeBuf;
  29442. var b;
  29443. while (codeSize < bits) {
  29444. if ((b = str.getByte()) === -1) {
  29445. error('Bad encoding in flate stream');
  29446. }
  29447. codeBuf |= b << codeSize;
  29448. codeSize += 8;
  29449. }
  29450. b = codeBuf & ((1 << bits) - 1);
  29451. this.codeBuf = codeBuf >> bits;
  29452. this.codeSize = codeSize -= bits;
  29453. return b;
  29454. };
  29455. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29456. var str = this.str;
  29457. var codes = table[0];
  29458. var maxLen = table[1];
  29459. var codeSize = this.codeSize;
  29460. var codeBuf = this.codeBuf;
  29461. var b;
  29462. while (codeSize < maxLen) {
  29463. if ((b = str.getByte()) === -1) {
  29464. // premature end of stream. code might however still be valid.
  29465. // codeSize < codeLen check below guards against incomplete codeVal.
  29466. break;
  29467. }
  29468. codeBuf |= (b << codeSize);
  29469. codeSize += 8;
  29470. }
  29471. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29472. var codeLen = code >> 16;
  29473. var codeVal = code & 0xffff;
  29474. if (codeLen < 1 || codeSize < codeLen) {
  29475. error('Bad encoding in flate stream');
  29476. }
  29477. this.codeBuf = (codeBuf >> codeLen);
  29478. this.codeSize = (codeSize - codeLen);
  29479. return codeVal;
  29480. };
  29481. FlateStream.prototype.generateHuffmanTable =
  29482. function flateStreamGenerateHuffmanTable(lengths) {
  29483. var n = lengths.length;
  29484. // find max code length
  29485. var maxLen = 0;
  29486. var i;
  29487. for (i = 0; i < n; ++i) {
  29488. if (lengths[i] > maxLen) {
  29489. maxLen = lengths[i];
  29490. }
  29491. }
  29492. // build the table
  29493. var size = 1 << maxLen;
  29494. var codes = new Uint32Array(size);
  29495. for (var len = 1, code = 0, skip = 2;
  29496. len <= maxLen;
  29497. ++len, code <<= 1, skip <<= 1) {
  29498. for (var val = 0; val < n; ++val) {
  29499. if (lengths[val] === len) {
  29500. // bit-reverse the code
  29501. var code2 = 0;
  29502. var t = code;
  29503. for (i = 0; i < len; ++i) {
  29504. code2 = (code2 << 1) | (t & 1);
  29505. t >>= 1;
  29506. }
  29507. // fill the table entries
  29508. for (i = code2; i < size; i += skip) {
  29509. codes[i] = (len << 16) | val;
  29510. }
  29511. ++code;
  29512. }
  29513. }
  29514. }
  29515. return [codes, maxLen];
  29516. };
  29517. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29518. var buffer, len;
  29519. var str = this.str;
  29520. // read block header
  29521. var hdr = this.getBits(3);
  29522. if (hdr & 1) {
  29523. this.eof = true;
  29524. }
  29525. hdr >>= 1;
  29526. if (hdr === 0) { // uncompressed block
  29527. var b;
  29528. if ((b = str.getByte()) === -1) {
  29529. error('Bad block header in flate stream');
  29530. }
  29531. var blockLen = b;
  29532. if ((b = str.getByte()) === -1) {
  29533. error('Bad block header in flate stream');
  29534. }
  29535. blockLen |= (b << 8);
  29536. if ((b = str.getByte()) === -1) {
  29537. error('Bad block header in flate stream');
  29538. }
  29539. var check = b;
  29540. if ((b = str.getByte()) === -1) {
  29541. error('Bad block header in flate stream');
  29542. }
  29543. check |= (b << 8);
  29544. if (check !== (~blockLen & 0xffff) &&
  29545. (blockLen !== 0 || check !== 0)) {
  29546. // Ignoring error for bad "empty" block (see issue 1277)
  29547. error('Bad uncompressed block length in flate stream');
  29548. }
  29549. this.codeBuf = 0;
  29550. this.codeSize = 0;
  29551. var bufferLength = this.bufferLength;
  29552. buffer = this.ensureBuffer(bufferLength + blockLen);
  29553. var end = bufferLength + blockLen;
  29554. this.bufferLength = end;
  29555. if (blockLen === 0) {
  29556. if (str.peekByte() === -1) {
  29557. this.eof = true;
  29558. }
  29559. } else {
  29560. for (var n = bufferLength; n < end; ++n) {
  29561. if ((b = str.getByte()) === -1) {
  29562. this.eof = true;
  29563. break;
  29564. }
  29565. buffer[n] = b;
  29566. }
  29567. }
  29568. return;
  29569. }
  29570. var litCodeTable;
  29571. var distCodeTable;
  29572. if (hdr === 1) { // compressed block, fixed codes
  29573. litCodeTable = fixedLitCodeTab;
  29574. distCodeTable = fixedDistCodeTab;
  29575. } else if (hdr === 2) { // compressed block, dynamic codes
  29576. var numLitCodes = this.getBits(5) + 257;
  29577. var numDistCodes = this.getBits(5) + 1;
  29578. var numCodeLenCodes = this.getBits(4) + 4;
  29579. // build the code lengths code table
  29580. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29581. var i;
  29582. for (i = 0; i < numCodeLenCodes; ++i) {
  29583. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29584. }
  29585. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29586. // build the literal and distance code tables
  29587. len = 0;
  29588. i = 0;
  29589. var codes = numLitCodes + numDistCodes;
  29590. var codeLengths = new Uint8Array(codes);
  29591. var bitsLength, bitsOffset, what;
  29592. while (i < codes) {
  29593. var code = this.getCode(codeLenCodeTab);
  29594. if (code === 16) {
  29595. bitsLength = 2; bitsOffset = 3; what = len;
  29596. } else if (code === 17) {
  29597. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29598. } else if (code === 18) {
  29599. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29600. } else {
  29601. codeLengths[i++] = len = code;
  29602. continue;
  29603. }
  29604. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29605. while (repeatLength-- > 0) {
  29606. codeLengths[i++] = what;
  29607. }
  29608. }
  29609. litCodeTable =
  29610. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29611. distCodeTable =
  29612. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29613. } else {
  29614. error('Unknown block type in flate stream');
  29615. }
  29616. buffer = this.buffer;
  29617. var limit = buffer ? buffer.length : 0;
  29618. var pos = this.bufferLength;
  29619. while (true) {
  29620. var code1 = this.getCode(litCodeTable);
  29621. if (code1 < 256) {
  29622. if (pos + 1 >= limit) {
  29623. buffer = this.ensureBuffer(pos + 1);
  29624. limit = buffer.length;
  29625. }
  29626. buffer[pos++] = code1;
  29627. continue;
  29628. }
  29629. if (code1 === 256) {
  29630. this.bufferLength = pos;
  29631. return;
  29632. }
  29633. code1 -= 257;
  29634. code1 = lengthDecode[code1];
  29635. var code2 = code1 >> 16;
  29636. if (code2 > 0) {
  29637. code2 = this.getBits(code2);
  29638. }
  29639. len = (code1 & 0xffff) + code2;
  29640. code1 = this.getCode(distCodeTable);
  29641. code1 = distDecode[code1];
  29642. code2 = code1 >> 16;
  29643. if (code2 > 0) {
  29644. code2 = this.getBits(code2);
  29645. }
  29646. var dist = (code1 & 0xffff) + code2;
  29647. if (pos + len >= limit) {
  29648. buffer = this.ensureBuffer(pos + len);
  29649. limit = buffer.length;
  29650. }
  29651. for (var k = 0; k < len; ++k, ++pos) {
  29652. buffer[pos] = buffer[pos - dist];
  29653. }
  29654. }
  29655. };
  29656. return FlateStream;
  29657. })();
  29658. var PredictorStream = (function PredictorStreamClosure() {
  29659. function PredictorStream(str, maybeLength, params) {
  29660. var predictor = this.predictor = params.get('Predictor') || 1;
  29661. if (predictor <= 1) {
  29662. return str; // no prediction
  29663. }
  29664. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  29665. error('Unsupported predictor: ' + predictor);
  29666. }
  29667. if (predictor === 2) {
  29668. this.readBlock = this.readBlockTiff;
  29669. } else {
  29670. this.readBlock = this.readBlockPng;
  29671. }
  29672. this.str = str;
  29673. this.dict = str.dict;
  29674. var colors = this.colors = params.get('Colors') || 1;
  29675. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29676. var columns = this.columns = params.get('Columns') || 1;
  29677. this.pixBytes = (colors * bits + 7) >> 3;
  29678. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29679. DecodeStream.call(this, maybeLength);
  29680. return this;
  29681. }
  29682. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29683. PredictorStream.prototype.readBlockTiff =
  29684. function predictorStreamReadBlockTiff() {
  29685. var rowBytes = this.rowBytes;
  29686. var bufferLength = this.bufferLength;
  29687. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29688. var bits = this.bits;
  29689. var colors = this.colors;
  29690. var rawBytes = this.str.getBytes(rowBytes);
  29691. this.eof = !rawBytes.length;
  29692. if (this.eof) {
  29693. return;
  29694. }
  29695. var inbuf = 0, outbuf = 0;
  29696. var inbits = 0, outbits = 0;
  29697. var pos = bufferLength;
  29698. var i;
  29699. if (bits === 1) {
  29700. for (i = 0; i < rowBytes; ++i) {
  29701. var c = rawBytes[i];
  29702. inbuf = (inbuf << 8) | c;
  29703. // bitwise addition is exclusive or
  29704. // first shift inbuf and then add
  29705. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  29706. // truncate inbuf (assumes colors < 16)
  29707. inbuf &= 0xFFFF;
  29708. }
  29709. } else if (bits === 8) {
  29710. for (i = 0; i < colors; ++i) {
  29711. buffer[pos++] = rawBytes[i];
  29712. }
  29713. for (; i < rowBytes; ++i) {
  29714. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  29715. pos++;
  29716. }
  29717. } else {
  29718. var compArray = new Uint8Array(colors + 1);
  29719. var bitMask = (1 << bits) - 1;
  29720. var j = 0, k = bufferLength;
  29721. var columns = this.columns;
  29722. for (i = 0; i < columns; ++i) {
  29723. for (var kk = 0; kk < colors; ++kk) {
  29724. if (inbits < bits) {
  29725. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  29726. inbits += 8;
  29727. }
  29728. compArray[kk] = (compArray[kk] +
  29729. (inbuf >> (inbits - bits))) & bitMask;
  29730. inbits -= bits;
  29731. outbuf = (outbuf << bits) | compArray[kk];
  29732. outbits += bits;
  29733. if (outbits >= 8) {
  29734. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  29735. outbits -= 8;
  29736. }
  29737. }
  29738. }
  29739. if (outbits > 0) {
  29740. buffer[k++] = (outbuf << (8 - outbits)) +
  29741. (inbuf & ((1 << (8 - outbits)) - 1));
  29742. }
  29743. }
  29744. this.bufferLength += rowBytes;
  29745. };
  29746. PredictorStream.prototype.readBlockPng =
  29747. function predictorStreamReadBlockPng() {
  29748. var rowBytes = this.rowBytes;
  29749. var pixBytes = this.pixBytes;
  29750. var predictor = this.str.getByte();
  29751. var rawBytes = this.str.getBytes(rowBytes);
  29752. this.eof = !rawBytes.length;
  29753. if (this.eof) {
  29754. return;
  29755. }
  29756. var bufferLength = this.bufferLength;
  29757. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29758. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  29759. if (prevRow.length === 0) {
  29760. prevRow = new Uint8Array(rowBytes);
  29761. }
  29762. var i, j = bufferLength, up, c;
  29763. switch (predictor) {
  29764. case 0:
  29765. for (i = 0; i < rowBytes; ++i) {
  29766. buffer[j++] = rawBytes[i];
  29767. }
  29768. break;
  29769. case 1:
  29770. for (i = 0; i < pixBytes; ++i) {
  29771. buffer[j++] = rawBytes[i];
  29772. }
  29773. for (; i < rowBytes; ++i) {
  29774. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  29775. j++;
  29776. }
  29777. break;
  29778. case 2:
  29779. for (i = 0; i < rowBytes; ++i) {
  29780. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  29781. }
  29782. break;
  29783. case 3:
  29784. for (i = 0; i < pixBytes; ++i) {
  29785. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  29786. }
  29787. for (; i < rowBytes; ++i) {
  29788. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  29789. rawBytes[i]) & 0xFF;
  29790. j++;
  29791. }
  29792. break;
  29793. case 4:
  29794. // we need to save the up left pixels values. the simplest way
  29795. // is to create a new buffer
  29796. for (i = 0; i < pixBytes; ++i) {
  29797. up = prevRow[i];
  29798. c = rawBytes[i];
  29799. buffer[j++] = up + c;
  29800. }
  29801. for (; i < rowBytes; ++i) {
  29802. up = prevRow[i];
  29803. var upLeft = prevRow[i - pixBytes];
  29804. var left = buffer[j - pixBytes];
  29805. var p = left + up - upLeft;
  29806. var pa = p - left;
  29807. if (pa < 0) {
  29808. pa = -pa;
  29809. }
  29810. var pb = p - up;
  29811. if (pb < 0) {
  29812. pb = -pb;
  29813. }
  29814. var pc = p - upLeft;
  29815. if (pc < 0) {
  29816. pc = -pc;
  29817. }
  29818. c = rawBytes[i];
  29819. if (pa <= pb && pa <= pc) {
  29820. buffer[j++] = left + c;
  29821. } else if (pb <= pc) {
  29822. buffer[j++] = up + c;
  29823. } else {
  29824. buffer[j++] = upLeft + c;
  29825. }
  29826. }
  29827. break;
  29828. default:
  29829. error('Unsupported predictor: ' + predictor);
  29830. }
  29831. this.bufferLength += rowBytes;
  29832. };
  29833. return PredictorStream;
  29834. })();
  29835. /**
  29836. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  29837. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  29838. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  29839. * a library to decode these images and the stream behaves like all the other
  29840. * DecodeStreams.
  29841. */
  29842. var JpegStream = (function JpegStreamClosure() {
  29843. function JpegStream(stream, maybeLength, dict, xref) {
  29844. // TODO: per poppler, some images may have 'junk' before that
  29845. // need to be removed
  29846. this.stream = stream;
  29847. this.maybeLength = maybeLength;
  29848. this.dict = dict;
  29849. DecodeStream.call(this, maybeLength);
  29850. }
  29851. JpegStream.prototype = Object.create(DecodeStream.prototype);
  29852. Object.defineProperty(JpegStream.prototype, 'bytes', {
  29853. get: function JpegStream_bytes() {
  29854. // If this.maybeLength is null, we'll get the entire stream.
  29855. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29856. },
  29857. configurable: true
  29858. });
  29859. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  29860. if (this.bufferLength) {
  29861. return;
  29862. }
  29863. try {
  29864. var jpegImage = new JpegImage();
  29865. // checking if values needs to be transformed before conversion
  29866. if (this.dict && isArray(this.dict.get('Decode'))) {
  29867. var decodeArr = this.dict.get('Decode');
  29868. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  29869. var decodeArrLength = decodeArr.length;
  29870. var transform = new Int32Array(decodeArrLength);
  29871. var transformNeeded = false;
  29872. var maxValue = (1 << bitsPerComponent) - 1;
  29873. for (var i = 0; i < decodeArrLength; i += 2) {
  29874. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  29875. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  29876. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  29877. transformNeeded = true;
  29878. }
  29879. }
  29880. if (transformNeeded) {
  29881. jpegImage.decodeTransform = transform;
  29882. }
  29883. }
  29884. jpegImage.parse(this.bytes);
  29885. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  29886. this.forceRGB);
  29887. this.buffer = data;
  29888. this.bufferLength = data.length;
  29889. this.eof = true;
  29890. } catch (e) {
  29891. error('JPEG error: ' + e);
  29892. }
  29893. };
  29894. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  29895. this.ensureBuffer();
  29896. return this.buffer;
  29897. };
  29898. JpegStream.prototype.getIR = function JpegStream_getIR() {
  29899. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  29900. };
  29901. /**
  29902. * Checks if the image can be decoded and displayed by the browser without any
  29903. * further processing such as color space conversions.
  29904. */
  29905. JpegStream.prototype.isNativelySupported =
  29906. function JpegStream_isNativelySupported(xref, res) {
  29907. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29908. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  29909. };
  29910. /**
  29911. * Checks if the image can be decoded by the browser.
  29912. */
  29913. JpegStream.prototype.isNativelyDecodable =
  29914. function JpegStream_isNativelyDecodable(xref, res) {
  29915. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29916. var numComps = cs.numComps;
  29917. return numComps === 1 || numComps === 3;
  29918. };
  29919. return JpegStream;
  29920. })();
  29921. /**
  29922. * For JPEG 2000's we use a library to decode these images and
  29923. * the stream behaves like all the other DecodeStreams.
  29924. */
  29925. var JpxStream = (function JpxStreamClosure() {
  29926. function JpxStream(stream, maybeLength, dict) {
  29927. this.stream = stream;
  29928. this.maybeLength = maybeLength;
  29929. this.dict = dict;
  29930. DecodeStream.call(this, maybeLength);
  29931. }
  29932. JpxStream.prototype = Object.create(DecodeStream.prototype);
  29933. Object.defineProperty(JpxStream.prototype, 'bytes', {
  29934. get: function JpxStream_bytes() {
  29935. // If this.maybeLength is null, we'll get the entire stream.
  29936. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29937. },
  29938. configurable: true
  29939. });
  29940. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  29941. if (this.bufferLength) {
  29942. return;
  29943. }
  29944. var jpxImage = new JpxImage();
  29945. jpxImage.parse(this.bytes);
  29946. var width = jpxImage.width;
  29947. var height = jpxImage.height;
  29948. var componentsCount = jpxImage.componentsCount;
  29949. var tileCount = jpxImage.tiles.length;
  29950. if (tileCount === 1) {
  29951. this.buffer = jpxImage.tiles[0].items;
  29952. } else {
  29953. var data = new Uint8Array(width * height * componentsCount);
  29954. for (var k = 0; k < tileCount; k++) {
  29955. var tileComponents = jpxImage.tiles[k];
  29956. var tileWidth = tileComponents.width;
  29957. var tileHeight = tileComponents.height;
  29958. var tileLeft = tileComponents.left;
  29959. var tileTop = tileComponents.top;
  29960. var src = tileComponents.items;
  29961. var srcPosition = 0;
  29962. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  29963. var imgRowSize = width * componentsCount;
  29964. var tileRowSize = tileWidth * componentsCount;
  29965. for (var j = 0; j < tileHeight; j++) {
  29966. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  29967. data.set(rowBytes, dataPosition);
  29968. srcPosition += tileRowSize;
  29969. dataPosition += imgRowSize;
  29970. }
  29971. }
  29972. this.buffer = data;
  29973. }
  29974. this.bufferLength = this.buffer.length;
  29975. this.eof = true;
  29976. };
  29977. return JpxStream;
  29978. })();
  29979. /**
  29980. * For JBIG2's we use a library to decode these images and
  29981. * the stream behaves like all the other DecodeStreams.
  29982. */
  29983. var Jbig2Stream = (function Jbig2StreamClosure() {
  29984. function Jbig2Stream(stream, maybeLength, dict) {
  29985. this.stream = stream;
  29986. this.maybeLength = maybeLength;
  29987. this.dict = dict;
  29988. DecodeStream.call(this, maybeLength);
  29989. }
  29990. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  29991. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  29992. get: function Jbig2Stream_bytes() {
  29993. // If this.maybeLength is null, we'll get the entire stream.
  29994. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29995. },
  29996. configurable: true
  29997. });
  29998. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  29999. if (this.bufferLength) {
  30000. return;
  30001. }
  30002. var jbig2Image = new Jbig2Image();
  30003. var chunks = [], xref = this.dict.xref;
  30004. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30005. // According to the PDF specification, DecodeParms can be either
  30006. // a dictionary, or an array whose elements are dictionaries.
  30007. if (isArray(decodeParams)) {
  30008. if (decodeParams.length > 1) {
  30009. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30010. 'not supported.');
  30011. }
  30012. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30013. }
  30014. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30015. var globalsStream = decodeParams.get('JBIG2Globals');
  30016. var globals = globalsStream.getBytes();
  30017. chunks.push({data: globals, start: 0, end: globals.length});
  30018. }
  30019. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30020. var data = jbig2Image.parseChunks(chunks);
  30021. var dataLength = data.length;
  30022. // JBIG2 had black as 1 and white as 0, inverting the colors
  30023. for (var i = 0; i < dataLength; i++) {
  30024. data[i] ^= 0xFF;
  30025. }
  30026. this.buffer = data;
  30027. this.bufferLength = dataLength;
  30028. this.eof = true;
  30029. };
  30030. return Jbig2Stream;
  30031. })();
  30032. var DecryptStream = (function DecryptStreamClosure() {
  30033. function DecryptStream(str, maybeLength, decrypt) {
  30034. this.str = str;
  30035. this.dict = str.dict;
  30036. this.decrypt = decrypt;
  30037. this.nextChunk = null;
  30038. this.initialized = false;
  30039. DecodeStream.call(this, maybeLength);
  30040. }
  30041. var chunkSize = 512;
  30042. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30043. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30044. var chunk;
  30045. if (this.initialized) {
  30046. chunk = this.nextChunk;
  30047. } else {
  30048. chunk = this.str.getBytes(chunkSize);
  30049. this.initialized = true;
  30050. }
  30051. if (!chunk || chunk.length === 0) {
  30052. this.eof = true;
  30053. return;
  30054. }
  30055. this.nextChunk = this.str.getBytes(chunkSize);
  30056. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30057. var decrypt = this.decrypt;
  30058. chunk = decrypt(chunk, !hasMoreData);
  30059. var bufferLength = this.bufferLength;
  30060. var i, n = chunk.length;
  30061. var buffer = this.ensureBuffer(bufferLength + n);
  30062. for (i = 0; i < n; i++) {
  30063. buffer[bufferLength++] = chunk[i];
  30064. }
  30065. this.bufferLength = bufferLength;
  30066. };
  30067. return DecryptStream;
  30068. })();
  30069. var Ascii85Stream = (function Ascii85StreamClosure() {
  30070. function Ascii85Stream(str, maybeLength) {
  30071. this.str = str;
  30072. this.dict = str.dict;
  30073. this.input = new Uint8Array(5);
  30074. // Most streams increase in size when decoded, but Ascii85 streams
  30075. // typically shrink by ~20%.
  30076. if (maybeLength) {
  30077. maybeLength = 0.8 * maybeLength;
  30078. }
  30079. DecodeStream.call(this, maybeLength);
  30080. }
  30081. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30082. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30083. var TILDA_CHAR = 0x7E; // '~'
  30084. var Z_LOWER_CHAR = 0x7A; // 'z'
  30085. var EOF = -1;
  30086. var str = this.str;
  30087. var c = str.getByte();
  30088. while (Lexer.isSpace(c)) {
  30089. c = str.getByte();
  30090. }
  30091. if (c === EOF || c === TILDA_CHAR) {
  30092. this.eof = true;
  30093. return;
  30094. }
  30095. var bufferLength = this.bufferLength, buffer;
  30096. var i;
  30097. // special code for z
  30098. if (c === Z_LOWER_CHAR) {
  30099. buffer = this.ensureBuffer(bufferLength + 4);
  30100. for (i = 0; i < 4; ++i) {
  30101. buffer[bufferLength + i] = 0;
  30102. }
  30103. this.bufferLength += 4;
  30104. } else {
  30105. var input = this.input;
  30106. input[0] = c;
  30107. for (i = 1; i < 5; ++i) {
  30108. c = str.getByte();
  30109. while (Lexer.isSpace(c)) {
  30110. c = str.getByte();
  30111. }
  30112. input[i] = c;
  30113. if (c === EOF || c === TILDA_CHAR) {
  30114. break;
  30115. }
  30116. }
  30117. buffer = this.ensureBuffer(bufferLength + i - 1);
  30118. this.bufferLength += i - 1;
  30119. // partial ending;
  30120. if (i < 5) {
  30121. for (; i < 5; ++i) {
  30122. input[i] = 0x21 + 84;
  30123. }
  30124. this.eof = true;
  30125. }
  30126. var t = 0;
  30127. for (i = 0; i < 5; ++i) {
  30128. t = t * 85 + (input[i] - 0x21);
  30129. }
  30130. for (i = 3; i >= 0; --i) {
  30131. buffer[bufferLength + i] = t & 0xFF;
  30132. t >>= 8;
  30133. }
  30134. }
  30135. };
  30136. return Ascii85Stream;
  30137. })();
  30138. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30139. function AsciiHexStream(str, maybeLength) {
  30140. this.str = str;
  30141. this.dict = str.dict;
  30142. this.firstDigit = -1;
  30143. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30144. // by 50%.
  30145. if (maybeLength) {
  30146. maybeLength = 0.5 * maybeLength;
  30147. }
  30148. DecodeStream.call(this, maybeLength);
  30149. }
  30150. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30151. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30152. var UPSTREAM_BLOCK_SIZE = 8000;
  30153. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30154. if (!bytes.length) {
  30155. this.eof = true;
  30156. return;
  30157. }
  30158. var maxDecodeLength = (bytes.length + 1) >> 1;
  30159. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30160. var bufferLength = this.bufferLength;
  30161. var firstDigit = this.firstDigit;
  30162. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30163. var ch = bytes[i], digit;
  30164. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30165. digit = ch & 0x0F;
  30166. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30167. // 'A'-'Z', 'a'-'z'
  30168. digit = (ch & 0x0F) + 9;
  30169. } else if (ch === 0x3E) { // '>'
  30170. this.eof = true;
  30171. break;
  30172. } else { // probably whitespace
  30173. continue; // ignoring
  30174. }
  30175. if (firstDigit < 0) {
  30176. firstDigit = digit;
  30177. } else {
  30178. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30179. firstDigit = -1;
  30180. }
  30181. }
  30182. if (firstDigit >= 0 && this.eof) {
  30183. // incomplete byte
  30184. buffer[bufferLength++] = (firstDigit << 4);
  30185. firstDigit = -1;
  30186. }
  30187. this.firstDigit = firstDigit;
  30188. this.bufferLength = bufferLength;
  30189. };
  30190. return AsciiHexStream;
  30191. })();
  30192. var RunLengthStream = (function RunLengthStreamClosure() {
  30193. function RunLengthStream(str, maybeLength) {
  30194. this.str = str;
  30195. this.dict = str.dict;
  30196. DecodeStream.call(this, maybeLength);
  30197. }
  30198. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30199. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30200. // The repeatHeader has following format. The first byte defines type of run
  30201. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30202. // (in addition to the second byte from the header), n = 129 through 255 -
  30203. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30204. var repeatHeader = this.str.getBytes(2);
  30205. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30206. this.eof = true;
  30207. return;
  30208. }
  30209. var buffer;
  30210. var bufferLength = this.bufferLength;
  30211. var n = repeatHeader[0];
  30212. if (n < 128) {
  30213. // copy n bytes
  30214. buffer = this.ensureBuffer(bufferLength + n + 1);
  30215. buffer[bufferLength++] = repeatHeader[1];
  30216. if (n > 0) {
  30217. var source = this.str.getBytes(n);
  30218. buffer.set(source, bufferLength);
  30219. bufferLength += n;
  30220. }
  30221. } else {
  30222. n = 257 - n;
  30223. var b = repeatHeader[1];
  30224. buffer = this.ensureBuffer(bufferLength + n + 1);
  30225. for (var i = 0; i < n; i++) {
  30226. buffer[bufferLength++] = b;
  30227. }
  30228. }
  30229. this.bufferLength = bufferLength;
  30230. };
  30231. return RunLengthStream;
  30232. })();
  30233. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30234. var ccittEOL = -2;
  30235. var twoDimPass = 0;
  30236. var twoDimHoriz = 1;
  30237. var twoDimVert0 = 2;
  30238. var twoDimVertR1 = 3;
  30239. var twoDimVertL1 = 4;
  30240. var twoDimVertR2 = 5;
  30241. var twoDimVertL2 = 6;
  30242. var twoDimVertR3 = 7;
  30243. var twoDimVertL3 = 8;
  30244. var twoDimTable = [
  30245. [-1, -1], [-1, -1], // 000000x
  30246. [7, twoDimVertL3], // 0000010
  30247. [7, twoDimVertR3], // 0000011
  30248. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30249. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30250. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30251. [4, twoDimPass], [4, twoDimPass],
  30252. [4, twoDimPass], [4, twoDimPass],
  30253. [4, twoDimPass], [4, twoDimPass],
  30254. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30255. [3, twoDimHoriz], [3, twoDimHoriz],
  30256. [3, twoDimHoriz], [3, twoDimHoriz],
  30257. [3, twoDimHoriz], [3, twoDimHoriz],
  30258. [3, twoDimHoriz], [3, twoDimHoriz],
  30259. [3, twoDimHoriz], [3, twoDimHoriz],
  30260. [3, twoDimHoriz], [3, twoDimHoriz],
  30261. [3, twoDimHoriz], [3, twoDimHoriz],
  30262. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30263. [3, twoDimVertL1], [3, twoDimVertL1],
  30264. [3, twoDimVertL1], [3, twoDimVertL1],
  30265. [3, twoDimVertL1], [3, twoDimVertL1],
  30266. [3, twoDimVertL1], [3, twoDimVertL1],
  30267. [3, twoDimVertL1], [3, twoDimVertL1],
  30268. [3, twoDimVertL1], [3, twoDimVertL1],
  30269. [3, twoDimVertL1], [3, twoDimVertL1],
  30270. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30271. [3, twoDimVertR1], [3, twoDimVertR1],
  30272. [3, twoDimVertR1], [3, twoDimVertR1],
  30273. [3, twoDimVertR1], [3, twoDimVertR1],
  30274. [3, twoDimVertR1], [3, twoDimVertR1],
  30275. [3, twoDimVertR1], [3, twoDimVertR1],
  30276. [3, twoDimVertR1], [3, twoDimVertR1],
  30277. [3, twoDimVertR1], [3, twoDimVertR1],
  30278. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30279. [1, twoDimVert0], [1, twoDimVert0],
  30280. [1, twoDimVert0], [1, twoDimVert0],
  30281. [1, twoDimVert0], [1, twoDimVert0],
  30282. [1, twoDimVert0], [1, twoDimVert0],
  30283. [1, twoDimVert0], [1, twoDimVert0],
  30284. [1, twoDimVert0], [1, twoDimVert0],
  30285. [1, twoDimVert0], [1, twoDimVert0],
  30286. [1, twoDimVert0], [1, twoDimVert0],
  30287. [1, twoDimVert0], [1, twoDimVert0],
  30288. [1, twoDimVert0], [1, twoDimVert0],
  30289. [1, twoDimVert0], [1, twoDimVert0],
  30290. [1, twoDimVert0], [1, twoDimVert0],
  30291. [1, twoDimVert0], [1, twoDimVert0],
  30292. [1, twoDimVert0], [1, twoDimVert0],
  30293. [1, twoDimVert0], [1, twoDimVert0],
  30294. [1, twoDimVert0], [1, twoDimVert0],
  30295. [1, twoDimVert0], [1, twoDimVert0],
  30296. [1, twoDimVert0], [1, twoDimVert0],
  30297. [1, twoDimVert0], [1, twoDimVert0],
  30298. [1, twoDimVert0], [1, twoDimVert0],
  30299. [1, twoDimVert0], [1, twoDimVert0],
  30300. [1, twoDimVert0], [1, twoDimVert0],
  30301. [1, twoDimVert0], [1, twoDimVert0],
  30302. [1, twoDimVert0], [1, twoDimVert0],
  30303. [1, twoDimVert0], [1, twoDimVert0],
  30304. [1, twoDimVert0], [1, twoDimVert0],
  30305. [1, twoDimVert0], [1, twoDimVert0],
  30306. [1, twoDimVert0], [1, twoDimVert0],
  30307. [1, twoDimVert0], [1, twoDimVert0],
  30308. [1, twoDimVert0], [1, twoDimVert0],
  30309. [1, twoDimVert0], [1, twoDimVert0]
  30310. ];
  30311. var whiteTable1 = [
  30312. [-1, -1], // 00000
  30313. [12, ccittEOL], // 00001
  30314. [-1, -1], [-1, -1], // 0001x
  30315. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30316. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30317. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30318. [11, 1792], [11, 1792], // 1000x
  30319. [12, 1984], // 10010
  30320. [12, 2048], // 10011
  30321. [12, 2112], // 10100
  30322. [12, 2176], // 10101
  30323. [12, 2240], // 10110
  30324. [12, 2304], // 10111
  30325. [11, 1856], [11, 1856], // 1100x
  30326. [11, 1920], [11, 1920], // 1101x
  30327. [12, 2368], // 11100
  30328. [12, 2432], // 11101
  30329. [12, 2496], // 11110
  30330. [12, 2560] // 11111
  30331. ];
  30332. var whiteTable2 = [
  30333. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30334. [8, 29], [8, 29], // 00000010x
  30335. [8, 30], [8, 30], // 00000011x
  30336. [8, 45], [8, 45], // 00000100x
  30337. [8, 46], [8, 46], // 00000101x
  30338. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30339. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30340. [8, 47], [8, 47], // 00001010x
  30341. [8, 48], [8, 48], // 00001011x
  30342. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30343. [6, 13], [6, 13], [6, 13], [6, 13],
  30344. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30345. [8, 33], [8, 33], // 00010010x
  30346. [8, 34], [8, 34], // 00010011x
  30347. [8, 35], [8, 35], // 00010100x
  30348. [8, 36], [8, 36], // 00010101x
  30349. [8, 37], [8, 37], // 00010110x
  30350. [8, 38], [8, 38], // 00010111x
  30351. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30352. [8, 31], [8, 31], // 00011010x
  30353. [8, 32], [8, 32], // 00011011x
  30354. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30355. [6, 1], [6, 1], [6, 1], [6, 1],
  30356. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30357. [6, 12], [6, 12], [6, 12], [6, 12],
  30358. [8, 53], [8, 53], // 00100100x
  30359. [8, 54], [8, 54], // 00100101x
  30360. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30361. [8, 39], [8, 39], // 00101000x
  30362. [8, 40], [8, 40], // 00101001x
  30363. [8, 41], [8, 41], // 00101010x
  30364. [8, 42], [8, 42], // 00101011x
  30365. [8, 43], [8, 43], // 00101100x
  30366. [8, 44], [8, 44], // 00101101x
  30367. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30368. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30369. [8, 61], [8, 61], // 00110010x
  30370. [8, 62], [8, 62], // 00110011x
  30371. [8, 63], [8, 63], // 00110100x
  30372. [8, 0], [8, 0], // 00110101x
  30373. [8, 320], [8, 320], // 00110110x
  30374. [8, 384], [8, 384], // 00110111x
  30375. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30376. [5, 10], [5, 10], [5, 10], [5, 10],
  30377. [5, 10], [5, 10], [5, 10], [5, 10],
  30378. [5, 10], [5, 10], [5, 10], [5, 10],
  30379. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30380. [5, 11], [5, 11], [5, 11], [5, 11],
  30381. [5, 11], [5, 11], [5, 11], [5, 11],
  30382. [5, 11], [5, 11], [5, 11], [5, 11],
  30383. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30384. [8, 59], [8, 59], // 01001010x
  30385. [8, 60], [8, 60], // 01001011x
  30386. [9, 1472], // 010011000
  30387. [9, 1536], // 010011001
  30388. [9, 1600], // 010011010
  30389. [9, 1728], // 010011011
  30390. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30391. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30392. [8, 49], [8, 49], // 01010010x
  30393. [8, 50], [8, 50], // 01010011x
  30394. [8, 51], [8, 51], // 01010100x
  30395. [8, 52], [8, 52], // 01010101x
  30396. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30397. [8, 55], [8, 55], // 01011000x
  30398. [8, 56], [8, 56], // 01011001x
  30399. [8, 57], [8, 57], // 01011010x
  30400. [8, 58], [8, 58], // 01011011x
  30401. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30402. [6, 192], [6, 192], [6, 192], [6, 192],
  30403. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30404. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30405. [8, 448], [8, 448], // 01100100x
  30406. [8, 512], [8, 512], // 01100101x
  30407. [9, 704], // 011001100
  30408. [9, 768], // 011001101
  30409. [8, 640], [8, 640], // 01100111x
  30410. [8, 576], [8, 576], // 01101000x
  30411. [9, 832], // 011010010
  30412. [9, 896], // 011010011
  30413. [9, 960], // 011010100
  30414. [9, 1024], // 011010101
  30415. [9, 1088], // 011010110
  30416. [9, 1152], // 011010111
  30417. [9, 1216], // 011011000
  30418. [9, 1280], // 011011001
  30419. [9, 1344], // 011011010
  30420. [9, 1408], // 011011011
  30421. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30422. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30423. [4, 2], [4, 2], [4, 2], [4, 2],
  30424. [4, 2], [4, 2], [4, 2], [4, 2],
  30425. [4, 2], [4, 2], [4, 2], [4, 2],
  30426. [4, 2], [4, 2], [4, 2], [4, 2],
  30427. [4, 2], [4, 2], [4, 2], [4, 2],
  30428. [4, 2], [4, 2], [4, 2], [4, 2],
  30429. [4, 2], [4, 2], [4, 2], [4, 2],
  30430. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30431. [4, 3], [4, 3], [4, 3], [4, 3],
  30432. [4, 3], [4, 3], [4, 3], [4, 3],
  30433. [4, 3], [4, 3], [4, 3], [4, 3],
  30434. [4, 3], [4, 3], [4, 3], [4, 3],
  30435. [4, 3], [4, 3], [4, 3], [4, 3],
  30436. [4, 3], [4, 3], [4, 3], [4, 3],
  30437. [4, 3], [4, 3], [4, 3], [4, 3],
  30438. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30439. [5, 128], [5, 128], [5, 128], [5, 128],
  30440. [5, 128], [5, 128], [5, 128], [5, 128],
  30441. [5, 128], [5, 128], [5, 128], [5, 128],
  30442. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30443. [5, 8], [5, 8], [5, 8], [5, 8],
  30444. [5, 8], [5, 8], [5, 8], [5, 8],
  30445. [5, 8], [5, 8], [5, 8], [5, 8],
  30446. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30447. [5, 9], [5, 9], [5, 9], [5, 9],
  30448. [5, 9], [5, 9], [5, 9], [5, 9],
  30449. [5, 9], [5, 9], [5, 9], [5, 9],
  30450. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30451. [6, 16], [6, 16], [6, 16], [6, 16],
  30452. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30453. [6, 17], [6, 17], [6, 17], [6, 17],
  30454. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30455. [4, 4], [4, 4], [4, 4], [4, 4],
  30456. [4, 4], [4, 4], [4, 4], [4, 4],
  30457. [4, 4], [4, 4], [4, 4], [4, 4],
  30458. [4, 4], [4, 4], [4, 4], [4, 4],
  30459. [4, 4], [4, 4], [4, 4], [4, 4],
  30460. [4, 4], [4, 4], [4, 4], [4, 4],
  30461. [4, 4], [4, 4], [4, 4], [4, 4],
  30462. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30463. [4, 5], [4, 5], [4, 5], [4, 5],
  30464. [4, 5], [4, 5], [4, 5], [4, 5],
  30465. [4, 5], [4, 5], [4, 5], [4, 5],
  30466. [4, 5], [4, 5], [4, 5], [4, 5],
  30467. [4, 5], [4, 5], [4, 5], [4, 5],
  30468. [4, 5], [4, 5], [4, 5], [4, 5],
  30469. [4, 5], [4, 5], [4, 5], [4, 5],
  30470. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30471. [6, 14], [6, 14], [6, 14], [6, 14],
  30472. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30473. [6, 15], [6, 15], [6, 15], [6, 15],
  30474. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30475. [5, 64], [5, 64], [5, 64], [5, 64],
  30476. [5, 64], [5, 64], [5, 64], [5, 64],
  30477. [5, 64], [5, 64], [5, 64], [5, 64],
  30478. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30479. [4, 6], [4, 6], [4, 6], [4, 6],
  30480. [4, 6], [4, 6], [4, 6], [4, 6],
  30481. [4, 6], [4, 6], [4, 6], [4, 6],
  30482. [4, 6], [4, 6], [4, 6], [4, 6],
  30483. [4, 6], [4, 6], [4, 6], [4, 6],
  30484. [4, 6], [4, 6], [4, 6], [4, 6],
  30485. [4, 6], [4, 6], [4, 6], [4, 6],
  30486. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30487. [4, 7], [4, 7], [4, 7], [4, 7],
  30488. [4, 7], [4, 7], [4, 7], [4, 7],
  30489. [4, 7], [4, 7], [4, 7], [4, 7],
  30490. [4, 7], [4, 7], [4, 7], [4, 7],
  30491. [4, 7], [4, 7], [4, 7], [4, 7],
  30492. [4, 7], [4, 7], [4, 7], [4, 7],
  30493. [4, 7], [4, 7], [4, 7], [4, 7]
  30494. ];
  30495. var blackTable1 = [
  30496. [-1, -1], [-1, -1], // 000000000000x
  30497. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30498. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30499. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30500. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30501. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30502. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30503. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30504. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30505. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30506. [12, 1984], [12, 1984], // 000000010010x
  30507. [12, 2048], [12, 2048], // 000000010011x
  30508. [12, 2112], [12, 2112], // 000000010100x
  30509. [12, 2176], [12, 2176], // 000000010101x
  30510. [12, 2240], [12, 2240], // 000000010110x
  30511. [12, 2304], [12, 2304], // 000000010111x
  30512. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30513. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30514. [12, 2368], [12, 2368], // 000000011100x
  30515. [12, 2432], [12, 2432], // 000000011101x
  30516. [12, 2496], [12, 2496], // 000000011110x
  30517. [12, 2560], [12, 2560], // 000000011111x
  30518. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30519. [10, 18], [10, 18], [10, 18], [10, 18],
  30520. [12, 52], [12, 52], // 000000100100x
  30521. [13, 640], // 0000001001010
  30522. [13, 704], // 0000001001011
  30523. [13, 768], // 0000001001100
  30524. [13, 832], // 0000001001101
  30525. [12, 55], [12, 55], // 000000100111x
  30526. [12, 56], [12, 56], // 000000101000x
  30527. [13, 1280], // 0000001010010
  30528. [13, 1344], // 0000001010011
  30529. [13, 1408], // 0000001010100
  30530. [13, 1472], // 0000001010101
  30531. [12, 59], [12, 59], // 000000101011x
  30532. [12, 60], [12, 60], // 000000101100x
  30533. [13, 1536], // 0000001011010
  30534. [13, 1600], // 0000001011011
  30535. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30536. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30537. [13, 1664], // 0000001100100
  30538. [13, 1728], // 0000001100101
  30539. [12, 320], [12, 320], // 000000110011x
  30540. [12, 384], [12, 384], // 000000110100x
  30541. [12, 448], [12, 448], // 000000110101x
  30542. [13, 512], // 0000001101100
  30543. [13, 576], // 0000001101101
  30544. [12, 53], [12, 53], // 000000110111x
  30545. [12, 54], [12, 54], // 000000111000x
  30546. [13, 896], // 0000001110010
  30547. [13, 960], // 0000001110011
  30548. [13, 1024], // 0000001110100
  30549. [13, 1088], // 0000001110101
  30550. [13, 1152], // 0000001110110
  30551. [13, 1216], // 0000001110111
  30552. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30553. [10, 64], [10, 64], [10, 64], [10, 64]
  30554. ];
  30555. var blackTable2 = [
  30556. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30557. [8, 13], [8, 13], [8, 13], [8, 13],
  30558. [8, 13], [8, 13], [8, 13], [8, 13],
  30559. [8, 13], [8, 13], [8, 13], [8, 13],
  30560. [11, 23], [11, 23], // 00000101000x
  30561. [12, 50], // 000001010010
  30562. [12, 51], // 000001010011
  30563. [12, 44], // 000001010100
  30564. [12, 45], // 000001010101
  30565. [12, 46], // 000001010110
  30566. [12, 47], // 000001010111
  30567. [12, 57], // 000001011000
  30568. [12, 58], // 000001011001
  30569. [12, 61], // 000001011010
  30570. [12, 256], // 000001011011
  30571. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30572. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30573. [12, 48], // 000001100100
  30574. [12, 49], // 000001100101
  30575. [12, 62], // 000001100110
  30576. [12, 63], // 000001100111
  30577. [12, 30], // 000001101000
  30578. [12, 31], // 000001101001
  30579. [12, 32], // 000001101010
  30580. [12, 33], // 000001101011
  30581. [12, 40], // 000001101100
  30582. [12, 41], // 000001101101
  30583. [11, 22], [11, 22], // 00000110111x
  30584. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30585. [8, 14], [8, 14], [8, 14], [8, 14],
  30586. [8, 14], [8, 14], [8, 14], [8, 14],
  30587. [8, 14], [8, 14], [8, 14], [8, 14],
  30588. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30589. [7, 10], [7, 10], [7, 10], [7, 10],
  30590. [7, 10], [7, 10], [7, 10], [7, 10],
  30591. [7, 10], [7, 10], [7, 10], [7, 10],
  30592. [7, 10], [7, 10], [7, 10], [7, 10],
  30593. [7, 10], [7, 10], [7, 10], [7, 10],
  30594. [7, 10], [7, 10], [7, 10], [7, 10],
  30595. [7, 10], [7, 10], [7, 10], [7, 10],
  30596. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30597. [7, 11], [7, 11], [7, 11], [7, 11],
  30598. [7, 11], [7, 11], [7, 11], [7, 11],
  30599. [7, 11], [7, 11], [7, 11], [7, 11],
  30600. [7, 11], [7, 11], [7, 11], [7, 11],
  30601. [7, 11], [7, 11], [7, 11], [7, 11],
  30602. [7, 11], [7, 11], [7, 11], [7, 11],
  30603. [7, 11], [7, 11], [7, 11], [7, 11],
  30604. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30605. [9, 15], [9, 15], [9, 15], [9, 15],
  30606. [12, 128], // 000011001000
  30607. [12, 192], // 000011001001
  30608. [12, 26], // 000011001010
  30609. [12, 27], // 000011001011
  30610. [12, 28], // 000011001100
  30611. [12, 29], // 000011001101
  30612. [11, 19], [11, 19], // 00001100111x
  30613. [11, 20], [11, 20], // 00001101000x
  30614. [12, 34], // 000011010010
  30615. [12, 35], // 000011010011
  30616. [12, 36], // 000011010100
  30617. [12, 37], // 000011010101
  30618. [12, 38], // 000011010110
  30619. [12, 39], // 000011010111
  30620. [11, 21], [11, 21], // 00001101100x
  30621. [12, 42], // 000011011010
  30622. [12, 43], // 000011011011
  30623. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30624. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30625. [7, 12], [7, 12], [7, 12], [7, 12],
  30626. [7, 12], [7, 12], [7, 12], [7, 12],
  30627. [7, 12], [7, 12], [7, 12], [7, 12],
  30628. [7, 12], [7, 12], [7, 12], [7, 12],
  30629. [7, 12], [7, 12], [7, 12], [7, 12],
  30630. [7, 12], [7, 12], [7, 12], [7, 12],
  30631. [7, 12], [7, 12], [7, 12], [7, 12]
  30632. ];
  30633. var blackTable3 = [
  30634. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30635. [6, 9], // 000100
  30636. [6, 8], // 000101
  30637. [5, 7], [5, 7], // 00011x
  30638. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30639. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30640. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30641. [3, 1], [3, 1], [3, 1], [3, 1],
  30642. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30643. [3, 4], [3, 4], [3, 4], [3, 4],
  30644. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30645. [2, 3], [2, 3], [2, 3], [2, 3],
  30646. [2, 3], [2, 3], [2, 3], [2, 3],
  30647. [2, 3], [2, 3], [2, 3], [2, 3],
  30648. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  30649. [2, 2], [2, 2], [2, 2], [2, 2],
  30650. [2, 2], [2, 2], [2, 2], [2, 2],
  30651. [2, 2], [2, 2], [2, 2], [2, 2]
  30652. ];
  30653. function CCITTFaxStream(str, maybeLength, params) {
  30654. this.str = str;
  30655. this.dict = str.dict;
  30656. params = params || Dict.empty;
  30657. this.encoding = params.get('K') || 0;
  30658. this.eoline = params.get('EndOfLine') || false;
  30659. this.byteAlign = params.get('EncodedByteAlign') || false;
  30660. this.columns = params.get('Columns') || 1728;
  30661. this.rows = params.get('Rows') || 0;
  30662. var eoblock = params.get('EndOfBlock');
  30663. if (eoblock === null || eoblock === undefined) {
  30664. eoblock = true;
  30665. }
  30666. this.eoblock = eoblock;
  30667. this.black = params.get('BlackIs1') || false;
  30668. this.codingLine = new Uint32Array(this.columns + 1);
  30669. this.refLine = new Uint32Array(this.columns + 2);
  30670. this.codingLine[0] = this.columns;
  30671. this.codingPos = 0;
  30672. this.row = 0;
  30673. this.nextLine2D = this.encoding < 0;
  30674. this.inputBits = 0;
  30675. this.inputBuf = 0;
  30676. this.outputBits = 0;
  30677. var code1;
  30678. while ((code1 = this.lookBits(12)) === 0) {
  30679. this.eatBits(1);
  30680. }
  30681. if (code1 === 1) {
  30682. this.eatBits(12);
  30683. }
  30684. if (this.encoding > 0) {
  30685. this.nextLine2D = !this.lookBits(1);
  30686. this.eatBits(1);
  30687. }
  30688. DecodeStream.call(this, maybeLength);
  30689. }
  30690. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30691. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30692. while (!this.eof) {
  30693. var c = this.lookChar();
  30694. this.ensureBuffer(this.bufferLength + 1);
  30695. this.buffer[this.bufferLength++] = c;
  30696. }
  30697. };
  30698. CCITTFaxStream.prototype.addPixels =
  30699. function ccittFaxStreamAddPixels(a1, blackPixels) {
  30700. var codingLine = this.codingLine;
  30701. var codingPos = this.codingPos;
  30702. if (a1 > codingLine[codingPos]) {
  30703. if (a1 > this.columns) {
  30704. info('row is wrong length');
  30705. this.err = true;
  30706. a1 = this.columns;
  30707. }
  30708. if ((codingPos & 1) ^ blackPixels) {
  30709. ++codingPos;
  30710. }
  30711. codingLine[codingPos] = a1;
  30712. }
  30713. this.codingPos = codingPos;
  30714. };
  30715. CCITTFaxStream.prototype.addPixelsNeg =
  30716. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30717. var codingLine = this.codingLine;
  30718. var codingPos = this.codingPos;
  30719. if (a1 > codingLine[codingPos]) {
  30720. if (a1 > this.columns) {
  30721. info('row is wrong length');
  30722. this.err = true;
  30723. a1 = this.columns;
  30724. }
  30725. if ((codingPos & 1) ^ blackPixels) {
  30726. ++codingPos;
  30727. }
  30728. codingLine[codingPos] = a1;
  30729. } else if (a1 < codingLine[codingPos]) {
  30730. if (a1 < 0) {
  30731. info('invalid code');
  30732. this.err = true;
  30733. a1 = 0;
  30734. }
  30735. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30736. --codingPos;
  30737. }
  30738. codingLine[codingPos] = a1;
  30739. }
  30740. this.codingPos = codingPos;
  30741. };
  30742. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30743. var refLine = this.refLine;
  30744. var codingLine = this.codingLine;
  30745. var columns = this.columns;
  30746. var refPos, blackPixels, bits, i;
  30747. if (this.outputBits === 0) {
  30748. if (this.eof) {
  30749. return null;
  30750. }
  30751. this.err = false;
  30752. var code1, code2, code3;
  30753. if (this.nextLine2D) {
  30754. for (i = 0; codingLine[i] < columns; ++i) {
  30755. refLine[i] = codingLine[i];
  30756. }
  30757. refLine[i++] = columns;
  30758. refLine[i] = columns;
  30759. codingLine[0] = 0;
  30760. this.codingPos = 0;
  30761. refPos = 0;
  30762. blackPixels = 0;
  30763. while (codingLine[this.codingPos] < columns) {
  30764. code1 = this.getTwoDimCode();
  30765. switch (code1) {
  30766. case twoDimPass:
  30767. this.addPixels(refLine[refPos + 1], blackPixels);
  30768. if (refLine[refPos + 1] < columns) {
  30769. refPos += 2;
  30770. }
  30771. break;
  30772. case twoDimHoriz:
  30773. code1 = code2 = 0;
  30774. if (blackPixels) {
  30775. do {
  30776. code1 += (code3 = this.getBlackCode());
  30777. } while (code3 >= 64);
  30778. do {
  30779. code2 += (code3 = this.getWhiteCode());
  30780. } while (code3 >= 64);
  30781. } else {
  30782. do {
  30783. code1 += (code3 = this.getWhiteCode());
  30784. } while (code3 >= 64);
  30785. do {
  30786. code2 += (code3 = this.getBlackCode());
  30787. } while (code3 >= 64);
  30788. }
  30789. this.addPixels(codingLine[this.codingPos] +
  30790. code1, blackPixels);
  30791. if (codingLine[this.codingPos] < columns) {
  30792. this.addPixels(codingLine[this.codingPos] + code2,
  30793. blackPixels ^ 1);
  30794. }
  30795. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30796. refLine[refPos] < columns) {
  30797. refPos += 2;
  30798. }
  30799. break;
  30800. case twoDimVertR3:
  30801. this.addPixels(refLine[refPos] + 3, blackPixels);
  30802. blackPixels ^= 1;
  30803. if (codingLine[this.codingPos] < columns) {
  30804. ++refPos;
  30805. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30806. refLine[refPos] < columns) {
  30807. refPos += 2;
  30808. }
  30809. }
  30810. break;
  30811. case twoDimVertR2:
  30812. this.addPixels(refLine[refPos] + 2, blackPixels);
  30813. blackPixels ^= 1;
  30814. if (codingLine[this.codingPos] < columns) {
  30815. ++refPos;
  30816. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30817. refLine[refPos] < columns) {
  30818. refPos += 2;
  30819. }
  30820. }
  30821. break;
  30822. case twoDimVertR1:
  30823. this.addPixels(refLine[refPos] + 1, blackPixels);
  30824. blackPixels ^= 1;
  30825. if (codingLine[this.codingPos] < columns) {
  30826. ++refPos;
  30827. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30828. refLine[refPos] < columns) {
  30829. refPos += 2;
  30830. }
  30831. }
  30832. break;
  30833. case twoDimVert0:
  30834. this.addPixels(refLine[refPos], blackPixels);
  30835. blackPixels ^= 1;
  30836. if (codingLine[this.codingPos] < columns) {
  30837. ++refPos;
  30838. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30839. refLine[refPos] < columns) {
  30840. refPos += 2;
  30841. }
  30842. }
  30843. break;
  30844. case twoDimVertL3:
  30845. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30846. blackPixels ^= 1;
  30847. if (codingLine[this.codingPos] < columns) {
  30848. if (refPos > 0) {
  30849. --refPos;
  30850. } else {
  30851. ++refPos;
  30852. }
  30853. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30854. refLine[refPos] < columns) {
  30855. refPos += 2;
  30856. }
  30857. }
  30858. break;
  30859. case twoDimVertL2:
  30860. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30861. blackPixels ^= 1;
  30862. if (codingLine[this.codingPos] < columns) {
  30863. if (refPos > 0) {
  30864. --refPos;
  30865. } else {
  30866. ++refPos;
  30867. }
  30868. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30869. refLine[refPos] < columns) {
  30870. refPos += 2;
  30871. }
  30872. }
  30873. break;
  30874. case twoDimVertL1:
  30875. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30876. blackPixels ^= 1;
  30877. if (codingLine[this.codingPos] < columns) {
  30878. if (refPos > 0) {
  30879. --refPos;
  30880. } else {
  30881. ++refPos;
  30882. }
  30883. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30884. refLine[refPos] < columns) {
  30885. refPos += 2;
  30886. }
  30887. }
  30888. break;
  30889. case EOF:
  30890. this.addPixels(columns, 0);
  30891. this.eof = true;
  30892. break;
  30893. default:
  30894. info('bad 2d code');
  30895. this.addPixels(columns, 0);
  30896. this.err = true;
  30897. }
  30898. }
  30899. } else {
  30900. codingLine[0] = 0;
  30901. this.codingPos = 0;
  30902. blackPixels = 0;
  30903. while (codingLine[this.codingPos] < columns) {
  30904. code1 = 0;
  30905. if (blackPixels) {
  30906. do {
  30907. code1 += (code3 = this.getBlackCode());
  30908. } while (code3 >= 64);
  30909. } else {
  30910. do {
  30911. code1 += (code3 = this.getWhiteCode());
  30912. } while (code3 >= 64);
  30913. }
  30914. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30915. blackPixels ^= 1;
  30916. }
  30917. }
  30918. var gotEOL = false;
  30919. if (!this.eoblock && this.row === this.rows - 1) {
  30920. this.eof = true;
  30921. } else if (this.eoline || !this.byteAlign) {
  30922. code1 = this.lookBits(12);
  30923. if (this.eoline) {
  30924. while (code1 !== EOF && code1 !== 1) {
  30925. this.eatBits(1);
  30926. code1 = this.lookBits(12);
  30927. }
  30928. } else {
  30929. while (code1 === 0) {
  30930. this.eatBits(1);
  30931. code1 = this.lookBits(12);
  30932. }
  30933. }
  30934. if (code1 === 1) {
  30935. this.eatBits(12);
  30936. gotEOL = true;
  30937. } else if (code1 === EOF) {
  30938. this.eof = true;
  30939. }
  30940. }
  30941. if (this.byteAlign && !gotEOL) {
  30942. this.inputBits &= ~7;
  30943. }
  30944. if (!this.eof && this.encoding > 0) {
  30945. this.nextLine2D = !this.lookBits(1);
  30946. this.eatBits(1);
  30947. }
  30948. if (this.eoblock && gotEOL && this.byteAlign) {
  30949. code1 = this.lookBits(12);
  30950. if (code1 === 1) {
  30951. this.eatBits(12);
  30952. if (this.encoding > 0) {
  30953. this.lookBits(1);
  30954. this.eatBits(1);
  30955. }
  30956. if (this.encoding >= 0) {
  30957. for (i = 0; i < 4; ++i) {
  30958. code1 = this.lookBits(12);
  30959. if (code1 !== 1) {
  30960. info('bad rtc code: ' + code1);
  30961. }
  30962. this.eatBits(12);
  30963. if (this.encoding > 0) {
  30964. this.lookBits(1);
  30965. this.eatBits(1);
  30966. }
  30967. }
  30968. }
  30969. this.eof = true;
  30970. }
  30971. } else if (this.err && this.eoline) {
  30972. while (true) {
  30973. code1 = this.lookBits(13);
  30974. if (code1 === EOF) {
  30975. this.eof = true;
  30976. return null;
  30977. }
  30978. if ((code1 >> 1) === 1) {
  30979. break;
  30980. }
  30981. this.eatBits(1);
  30982. }
  30983. this.eatBits(12);
  30984. if (this.encoding > 0) {
  30985. this.eatBits(1);
  30986. this.nextLine2D = !(code1 & 1);
  30987. }
  30988. }
  30989. if (codingLine[0] > 0) {
  30990. this.outputBits = codingLine[this.codingPos = 0];
  30991. } else {
  30992. this.outputBits = codingLine[this.codingPos = 1];
  30993. }
  30994. this.row++;
  30995. }
  30996. var c;
  30997. if (this.outputBits >= 8) {
  30998. c = (this.codingPos & 1) ? 0 : 0xFF;
  30999. this.outputBits -= 8;
  31000. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31001. this.codingPos++;
  31002. this.outputBits = (codingLine[this.codingPos] -
  31003. codingLine[this.codingPos - 1]);
  31004. }
  31005. } else {
  31006. bits = 8;
  31007. c = 0;
  31008. do {
  31009. if (this.outputBits > bits) {
  31010. c <<= bits;
  31011. if (!(this.codingPos & 1)) {
  31012. c |= 0xFF >> (8 - bits);
  31013. }
  31014. this.outputBits -= bits;
  31015. bits = 0;
  31016. } else {
  31017. c <<= this.outputBits;
  31018. if (!(this.codingPos & 1)) {
  31019. c |= 0xFF >> (8 - this.outputBits);
  31020. }
  31021. bits -= this.outputBits;
  31022. this.outputBits = 0;
  31023. if (codingLine[this.codingPos] < columns) {
  31024. this.codingPos++;
  31025. this.outputBits = (codingLine[this.codingPos] -
  31026. codingLine[this.codingPos - 1]);
  31027. } else if (bits > 0) {
  31028. c <<= bits;
  31029. bits = 0;
  31030. }
  31031. }
  31032. } while (bits);
  31033. }
  31034. if (this.black) {
  31035. c ^= 0xFF;
  31036. }
  31037. return c;
  31038. };
  31039. // This functions returns the code found from the table.
  31040. // The start and end parameters set the boundaries for searching the table.
  31041. // The limit parameter is optional. Function returns an array with three
  31042. // values. The first array element indicates whether a valid code is being
  31043. // returned. The second array element is the actual code. The third array
  31044. // element indicates whether EOF was reached.
  31045. CCITTFaxStream.prototype.findTableCode =
  31046. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31047. var limitValue = limit || 0;
  31048. for (var i = start; i <= end; ++i) {
  31049. var code = this.lookBits(i);
  31050. if (code === EOF) {
  31051. return [true, 1, false];
  31052. }
  31053. if (i < end) {
  31054. code <<= end - i;
  31055. }
  31056. if (!limitValue || code >= limitValue) {
  31057. var p = table[code - limitValue];
  31058. if (p[0] === i) {
  31059. this.eatBits(i);
  31060. return [true, p[1], true];
  31061. }
  31062. }
  31063. }
  31064. return [false, 0, false];
  31065. };
  31066. CCITTFaxStream.prototype.getTwoDimCode =
  31067. function ccittFaxStreamGetTwoDimCode() {
  31068. var code = 0;
  31069. var p;
  31070. if (this.eoblock) {
  31071. code = this.lookBits(7);
  31072. p = twoDimTable[code];
  31073. if (p && p[0] > 0) {
  31074. this.eatBits(p[0]);
  31075. return p[1];
  31076. }
  31077. } else {
  31078. var result = this.findTableCode(1, 7, twoDimTable);
  31079. if (result[0] && result[2]) {
  31080. return result[1];
  31081. }
  31082. }
  31083. info('Bad two dim code');
  31084. return EOF;
  31085. };
  31086. CCITTFaxStream.prototype.getWhiteCode =
  31087. function ccittFaxStreamGetWhiteCode() {
  31088. var code = 0;
  31089. var p;
  31090. if (this.eoblock) {
  31091. code = this.lookBits(12);
  31092. if (code === EOF) {
  31093. return 1;
  31094. }
  31095. if ((code >> 5) === 0) {
  31096. p = whiteTable1[code];
  31097. } else {
  31098. p = whiteTable2[code >> 3];
  31099. }
  31100. if (p[0] > 0) {
  31101. this.eatBits(p[0]);
  31102. return p[1];
  31103. }
  31104. } else {
  31105. var result = this.findTableCode(1, 9, whiteTable2);
  31106. if (result[0]) {
  31107. return result[1];
  31108. }
  31109. result = this.findTableCode(11, 12, whiteTable1);
  31110. if (result[0]) {
  31111. return result[1];
  31112. }
  31113. }
  31114. info('bad white code');
  31115. this.eatBits(1);
  31116. return 1;
  31117. };
  31118. CCITTFaxStream.prototype.getBlackCode =
  31119. function ccittFaxStreamGetBlackCode() {
  31120. var code, p;
  31121. if (this.eoblock) {
  31122. code = this.lookBits(13);
  31123. if (code === EOF) {
  31124. return 1;
  31125. }
  31126. if ((code >> 7) === 0) {
  31127. p = blackTable1[code];
  31128. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31129. p = blackTable2[(code >> 1) - 64];
  31130. } else {
  31131. p = blackTable3[code >> 7];
  31132. }
  31133. if (p[0] > 0) {
  31134. this.eatBits(p[0]);
  31135. return p[1];
  31136. }
  31137. } else {
  31138. var result = this.findTableCode(2, 6, blackTable3);
  31139. if (result[0]) {
  31140. return result[1];
  31141. }
  31142. result = this.findTableCode(7, 12, blackTable2, 64);
  31143. if (result[0]) {
  31144. return result[1];
  31145. }
  31146. result = this.findTableCode(10, 13, blackTable1);
  31147. if (result[0]) {
  31148. return result[1];
  31149. }
  31150. }
  31151. info('bad black code');
  31152. this.eatBits(1);
  31153. return 1;
  31154. };
  31155. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31156. var c;
  31157. while (this.inputBits < n) {
  31158. if ((c = this.str.getByte()) === -1) {
  31159. if (this.inputBits === 0) {
  31160. return EOF;
  31161. }
  31162. return ((this.inputBuf << (n - this.inputBits)) &
  31163. (0xFFFF >> (16 - n)));
  31164. }
  31165. this.inputBuf = (this.inputBuf << 8) + c;
  31166. this.inputBits += 8;
  31167. }
  31168. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31169. };
  31170. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31171. if ((this.inputBits -= n) < 0) {
  31172. this.inputBits = 0;
  31173. }
  31174. };
  31175. return CCITTFaxStream;
  31176. })();
  31177. var LZWStream = (function LZWStreamClosure() {
  31178. function LZWStream(str, maybeLength, earlyChange) {
  31179. this.str = str;
  31180. this.dict = str.dict;
  31181. this.cachedData = 0;
  31182. this.bitsCached = 0;
  31183. var maxLzwDictionarySize = 4096;
  31184. var lzwState = {
  31185. earlyChange: earlyChange,
  31186. codeLength: 9,
  31187. nextCode: 258,
  31188. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31189. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31190. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31191. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31192. currentSequenceLength: 0
  31193. };
  31194. for (var i = 0; i < 256; ++i) {
  31195. lzwState.dictionaryValues[i] = i;
  31196. lzwState.dictionaryLengths[i] = 1;
  31197. }
  31198. this.lzwState = lzwState;
  31199. DecodeStream.call(this, maybeLength);
  31200. }
  31201. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31202. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31203. var bitsCached = this.bitsCached;
  31204. var cachedData = this.cachedData;
  31205. while (bitsCached < n) {
  31206. var c = this.str.getByte();
  31207. if (c === -1) {
  31208. this.eof = true;
  31209. return null;
  31210. }
  31211. cachedData = (cachedData << 8) | c;
  31212. bitsCached += 8;
  31213. }
  31214. this.bitsCached = (bitsCached -= n);
  31215. this.cachedData = cachedData;
  31216. this.lastCode = null;
  31217. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31218. };
  31219. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31220. var blockSize = 512;
  31221. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31222. var i, j, q;
  31223. var lzwState = this.lzwState;
  31224. if (!lzwState) {
  31225. return; // eof was found
  31226. }
  31227. var earlyChange = lzwState.earlyChange;
  31228. var nextCode = lzwState.nextCode;
  31229. var dictionaryValues = lzwState.dictionaryValues;
  31230. var dictionaryLengths = lzwState.dictionaryLengths;
  31231. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31232. var codeLength = lzwState.codeLength;
  31233. var prevCode = lzwState.prevCode;
  31234. var currentSequence = lzwState.currentSequence;
  31235. var currentSequenceLength = lzwState.currentSequenceLength;
  31236. var decodedLength = 0;
  31237. var currentBufferLength = this.bufferLength;
  31238. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31239. for (i = 0; i < blockSize; i++) {
  31240. var code = this.readBits(codeLength);
  31241. var hasPrev = currentSequenceLength > 0;
  31242. if (code < 256) {
  31243. currentSequence[0] = code;
  31244. currentSequenceLength = 1;
  31245. } else if (code >= 258) {
  31246. if (code < nextCode) {
  31247. currentSequenceLength = dictionaryLengths[code];
  31248. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31249. currentSequence[j] = dictionaryValues[q];
  31250. q = dictionaryPrevCodes[q];
  31251. }
  31252. } else {
  31253. currentSequence[currentSequenceLength++] = currentSequence[0];
  31254. }
  31255. } else if (code === 256) {
  31256. codeLength = 9;
  31257. nextCode = 258;
  31258. currentSequenceLength = 0;
  31259. continue;
  31260. } else {
  31261. this.eof = true;
  31262. delete this.lzwState;
  31263. break;
  31264. }
  31265. if (hasPrev) {
  31266. dictionaryPrevCodes[nextCode] = prevCode;
  31267. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31268. dictionaryValues[nextCode] = currentSequence[0];
  31269. nextCode++;
  31270. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31271. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31272. 0.6931471805599453 + 1, 12) | 0;
  31273. }
  31274. prevCode = code;
  31275. decodedLength += currentSequenceLength;
  31276. if (estimatedDecodedSize < decodedLength) {
  31277. do {
  31278. estimatedDecodedSize += decodedSizeDelta;
  31279. } while (estimatedDecodedSize < decodedLength);
  31280. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31281. }
  31282. for (j = 0; j < currentSequenceLength; j++) {
  31283. buffer[currentBufferLength++] = currentSequence[j];
  31284. }
  31285. }
  31286. lzwState.nextCode = nextCode;
  31287. lzwState.codeLength = codeLength;
  31288. lzwState.prevCode = prevCode;
  31289. lzwState.currentSequenceLength = currentSequenceLength;
  31290. this.bufferLength = currentBufferLength;
  31291. };
  31292. return LZWStream;
  31293. })();
  31294. var NullStream = (function NullStreamClosure() {
  31295. function NullStream() {
  31296. Stream.call(this, new Uint8Array(0));
  31297. }
  31298. NullStream.prototype = Stream.prototype;
  31299. return NullStream;
  31300. })();
  31301. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31302. setup: function wphSetup(handler) {
  31303. var pdfManager;
  31304. function loadDocument(recoveryMode) {
  31305. var loadDocumentCapability = createPromiseCapability();
  31306. var parseSuccess = function parseSuccess() {
  31307. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31308. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31309. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31310. Promise.all([numPagesPromise, fingerprintPromise,
  31311. encryptedPromise]).then(function onDocReady(results) {
  31312. var doc = {
  31313. numPages: results[0],
  31314. fingerprint: results[1],
  31315. encrypted: !!results[2],
  31316. };
  31317. loadDocumentCapability.resolve(doc);
  31318. },
  31319. parseFailure);
  31320. };
  31321. var parseFailure = function parseFailure(e) {
  31322. loadDocumentCapability.reject(e);
  31323. };
  31324. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31325. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31326. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31327. parseSuccess, parseFailure);
  31328. }, parseFailure);
  31329. }, parseFailure);
  31330. return loadDocumentCapability.promise;
  31331. }
  31332. function getPdfManager(data) {
  31333. var pdfManagerCapability = createPromiseCapability();
  31334. var source = data.source;
  31335. var disableRange = data.disableRange;
  31336. if (source.data) {
  31337. try {
  31338. pdfManager = new LocalPdfManager(source.data, source.password);
  31339. pdfManagerCapability.resolve();
  31340. } catch (ex) {
  31341. pdfManagerCapability.reject(ex);
  31342. }
  31343. return pdfManagerCapability.promise;
  31344. } else if (source.chunkedViewerLoading) {
  31345. try {
  31346. pdfManager = new NetworkPdfManager(source, handler);
  31347. pdfManagerCapability.resolve();
  31348. } catch (ex) {
  31349. pdfManagerCapability.reject(ex);
  31350. }
  31351. return pdfManagerCapability.promise;
  31352. }
  31353. var networkManager = new NetworkManager(source.url, {
  31354. httpHeaders: source.httpHeaders,
  31355. withCredentials: source.withCredentials
  31356. });
  31357. var cachedChunks = [];
  31358. var fullRequestXhrId = networkManager.requestFull({
  31359. onHeadersReceived: function onHeadersReceived() {
  31360. if (disableRange) {
  31361. return;
  31362. }
  31363. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31364. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31365. return;
  31366. }
  31367. var contentEncoding =
  31368. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31369. if (contentEncoding !== 'identity') {
  31370. return;
  31371. }
  31372. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31373. length = parseInt(length, 10);
  31374. if (!isInt(length)) {
  31375. return;
  31376. }
  31377. source.length = length;
  31378. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31379. // The file size is smaller than the size of two chunks, so it does
  31380. // not make any sense to abort the request and retry with a range
  31381. // request.
  31382. return;
  31383. }
  31384. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31385. // We can continue fetching when progressive loading is enabled,
  31386. // and we don't need the autoFetch feature.
  31387. source.disableAutoFetch = true;
  31388. } else {
  31389. // NOTE: by cancelling the full request, and then issuing range
  31390. // requests, there will be an issue for sites where you can only
  31391. // request the pdf once. However, if this is the case, then the
  31392. // server should not be returning that it can support range
  31393. // requests.
  31394. networkManager.abortRequest(fullRequestXhrId);
  31395. }
  31396. try {
  31397. pdfManager = new NetworkPdfManager(source, handler);
  31398. pdfManagerCapability.resolve(pdfManager);
  31399. } catch (ex) {
  31400. pdfManagerCapability.reject(ex);
  31401. }
  31402. },
  31403. onProgressiveData: source.disableStream ? null :
  31404. function onProgressiveData(chunk) {
  31405. if (!pdfManager) {
  31406. cachedChunks.push(chunk);
  31407. return;
  31408. }
  31409. pdfManager.sendProgressiveData(chunk);
  31410. },
  31411. onDone: function onDone(args) {
  31412. if (pdfManager) {
  31413. return; // already processed
  31414. }
  31415. var pdfFile;
  31416. if (args === null) {
  31417. // TODO add some streaming manager, e.g. for unknown length files.
  31418. // The data was returned in the onProgressiveData, combining...
  31419. var pdfFileLength = 0, pos = 0;
  31420. cachedChunks.forEach(function (chunk) {
  31421. pdfFileLength += chunk.byteLength;
  31422. });
  31423. if (source.length && pdfFileLength !== source.length) {
  31424. warn('reported HTTP length is different from actual');
  31425. }
  31426. var pdfFileArray = new Uint8Array(pdfFileLength);
  31427. cachedChunks.forEach(function (chunk) {
  31428. pdfFileArray.set(new Uint8Array(chunk), pos);
  31429. pos += chunk.byteLength;
  31430. });
  31431. pdfFile = pdfFileArray.buffer;
  31432. } else {
  31433. pdfFile = args.chunk;
  31434. }
  31435. // the data is array, instantiating directly from it
  31436. try {
  31437. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31438. pdfManagerCapability.resolve();
  31439. } catch (ex) {
  31440. pdfManagerCapability.reject(ex);
  31441. }
  31442. },
  31443. onError: function onError(status) {
  31444. var exception;
  31445. if (status === 404) {
  31446. exception = new MissingPDFException('Missing PDF "' +
  31447. source.url + '".');
  31448. handler.send('MissingPDF', exception);
  31449. } else {
  31450. exception = new UnexpectedResponseException(
  31451. 'Unexpected server response (' + status +
  31452. ') while retrieving PDF "' + source.url + '".', status);
  31453. handler.send('UnexpectedResponse', exception);
  31454. }
  31455. },
  31456. onProgress: function onProgress(evt) {
  31457. handler.send('DocProgress', {
  31458. loaded: evt.loaded,
  31459. total: evt.lengthComputable ? evt.total : source.length
  31460. });
  31461. }
  31462. });
  31463. return pdfManagerCapability.promise;
  31464. }
  31465. handler.on('test', function wphSetupTest(data) {
  31466. // check if Uint8Array can be sent to worker
  31467. if (!(data instanceof Uint8Array)) {
  31468. handler.send('test', false);
  31469. return;
  31470. }
  31471. // making sure postMessage transfers are working
  31472. var supportTransfers = data[0] === 255;
  31473. handler.postMessageTransfers = supportTransfers;
  31474. // check if the response property is supported by xhr
  31475. var xhr = new XMLHttpRequest();
  31476. var responseExists = 'response' in xhr;
  31477. // check if the property is actually implemented
  31478. try {
  31479. var dummy = xhr.responseType;
  31480. } catch (e) {
  31481. responseExists = false;
  31482. }
  31483. if (!responseExists) {
  31484. handler.send('test', false);
  31485. return;
  31486. }
  31487. handler.send('test', {
  31488. supportTypedArray: true,
  31489. supportTransfers: supportTransfers
  31490. });
  31491. });
  31492. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31493. var onSuccess = function(doc) {
  31494. handler.send('GetDoc', { pdfInfo: doc });
  31495. };
  31496. var onFailure = function(e) {
  31497. if (e instanceof PasswordException) {
  31498. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31499. handler.send('NeedPassword', e);
  31500. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31501. handler.send('IncorrectPassword', e);
  31502. }
  31503. } else if (e instanceof InvalidPDFException) {
  31504. handler.send('InvalidPDF', e);
  31505. } else if (e instanceof MissingPDFException) {
  31506. handler.send('MissingPDF', e);
  31507. } else if (e instanceof UnexpectedResponseException) {
  31508. handler.send('UnexpectedResponse', e);
  31509. } else {
  31510. handler.send('UnknownError',
  31511. new UnknownErrorException(e.message, e.toString()));
  31512. }
  31513. };
  31514. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31515. -1 : data.maxImageSize;
  31516. PDFJS.disableFontFace = data.disableFontFace;
  31517. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31518. PDFJS.verbosity = data.verbosity;
  31519. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31520. null : data.cMapUrl;
  31521. PDFJS.cMapPacked = data.cMapPacked === true;
  31522. getPdfManager(data).then(function () {
  31523. handler.send('PDFManagerReady', null);
  31524. pdfManager.onLoadedStream().then(function(stream) {
  31525. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31526. });
  31527. }).then(function pdfManagerReady() {
  31528. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31529. // Try again with recoveryMode == true
  31530. if (!(ex instanceof XRefParseException)) {
  31531. if (ex instanceof PasswordException) {
  31532. // after password exception prepare to receive a new password
  31533. // to repeat loading
  31534. pdfManager.passwordChanged().then(pdfManagerReady);
  31535. }
  31536. onFailure(ex);
  31537. return;
  31538. }
  31539. pdfManager.requestLoadedStream();
  31540. pdfManager.onLoadedStream().then(function() {
  31541. loadDocument(true).then(onSuccess, onFailure);
  31542. });
  31543. }, onFailure);
  31544. }, onFailure);
  31545. });
  31546. handler.on('GetPage', function wphSetupGetPage(data) {
  31547. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31548. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31549. var refPromise = pdfManager.ensure(page, 'ref');
  31550. var viewPromise = pdfManager.ensure(page, 'view');
  31551. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31552. function(results) {
  31553. return {
  31554. rotate: results[0],
  31555. ref: results[1],
  31556. view: results[2]
  31557. };
  31558. });
  31559. });
  31560. });
  31561. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31562. var ref = new Ref(data.ref.num, data.ref.gen);
  31563. var catalog = pdfManager.pdfDocument.catalog;
  31564. return catalog.getPageIndex(ref);
  31565. });
  31566. handler.on('GetDestinations',
  31567. function wphSetupGetDestinations(data) {
  31568. return pdfManager.ensureCatalog('destinations');
  31569. }
  31570. );
  31571. handler.on('GetAttachments',
  31572. function wphSetupGetAttachments(data) {
  31573. return pdfManager.ensureCatalog('attachments');
  31574. }
  31575. );
  31576. handler.on('GetJavaScript',
  31577. function wphSetupGetJavaScript(data) {
  31578. return pdfManager.ensureCatalog('javaScript');
  31579. }
  31580. );
  31581. handler.on('GetOutline',
  31582. function wphSetupGetOutline(data) {
  31583. return pdfManager.ensureCatalog('documentOutline');
  31584. }
  31585. );
  31586. handler.on('GetMetadata',
  31587. function wphSetupGetMetadata(data) {
  31588. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31589. pdfManager.ensureCatalog('metadata')]);
  31590. }
  31591. );
  31592. handler.on('GetData', function wphSetupGetData(data) {
  31593. pdfManager.requestLoadedStream();
  31594. return pdfManager.onLoadedStream().then(function(stream) {
  31595. return stream.bytes;
  31596. });
  31597. });
  31598. handler.on('GetStats',
  31599. function wphSetupGetStats(data) {
  31600. return pdfManager.pdfDocument.xref.stats;
  31601. }
  31602. );
  31603. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31604. pdfManager.updatePassword(data);
  31605. });
  31606. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31607. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31608. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31609. });
  31610. });
  31611. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31612. pdfManager.getPage(data.pageIndex).then(function(page) {
  31613. var pageNum = data.pageIndex + 1;
  31614. var start = Date.now();
  31615. // Pre compile the pdf page and fetch the fonts/images.
  31616. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31617. info('page=' + pageNum + ' - getOperatorList: time=' +
  31618. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31619. }, function(e) {
  31620. var minimumStackMessage =
  31621. 'worker.js: while trying to getPage() and getOperatorList()';
  31622. var wrappedException;
  31623. // Turn the error into an obj that can be serialized
  31624. if (typeof e === 'string') {
  31625. wrappedException = {
  31626. message: e,
  31627. stack: minimumStackMessage
  31628. };
  31629. } else if (typeof e === 'object') {
  31630. wrappedException = {
  31631. message: e.message || e.toString(),
  31632. stack: e.stack || minimumStackMessage
  31633. };
  31634. } else {
  31635. wrappedException = {
  31636. message: 'Unknown exception type: ' + (typeof e),
  31637. stack: minimumStackMessage
  31638. };
  31639. }
  31640. handler.send('PageError', {
  31641. pageNum: pageNum,
  31642. error: wrappedException,
  31643. intent: data.intent
  31644. });
  31645. });
  31646. });
  31647. }, this);
  31648. handler.on('GetTextContent', function wphExtractText(data) {
  31649. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31650. var pageNum = data.pageIndex + 1;
  31651. var start = Date.now();
  31652. return page.extractTextContent().then(function(textContent) {
  31653. info('text indexing: page=' + pageNum + ' - time=' +
  31654. (Date.now() - start) + 'ms');
  31655. return textContent;
  31656. });
  31657. });
  31658. });
  31659. handler.on('Cleanup', function wphCleanup(data) {
  31660. return pdfManager.cleanup();
  31661. });
  31662. handler.on('Terminate', function wphTerminate(data) {
  31663. pdfManager.terminate();
  31664. });
  31665. }
  31666. };
  31667. var consoleTimer = {};
  31668. var workerConsole = {
  31669. log: function log() {
  31670. var args = Array.prototype.slice.call(arguments);
  31671. globalScope.postMessage({
  31672. action: 'console_log',
  31673. data: args
  31674. });
  31675. },
  31676. error: function error() {
  31677. var args = Array.prototype.slice.call(arguments);
  31678. globalScope.postMessage({
  31679. action: 'console_error',
  31680. data: args
  31681. });
  31682. throw 'pdf.js execution error';
  31683. },
  31684. time: function time(name) {
  31685. consoleTimer[name] = Date.now();
  31686. },
  31687. timeEnd: function timeEnd(name) {
  31688. var time = consoleTimer[name];
  31689. if (!time) {
  31690. error('Unknown timer name ' + name);
  31691. }
  31692. this.log('Timer:', name, Date.now() - time);
  31693. }
  31694. };
  31695. // Worker thread?
  31696. if (typeof window === 'undefined') {
  31697. if (!('console' in globalScope)) {
  31698. globalScope.console = workerConsole;
  31699. }
  31700. // Listen for unsupported features so we can pass them on to the main thread.
  31701. PDFJS.UnsupportedManager.listen(function (msg) {
  31702. globalScope.postMessage({
  31703. action: '_unsupported_feature',
  31704. data: msg
  31705. });
  31706. });
  31707. var handler = new MessageHandler('worker_processor', this);
  31708. WorkerMessageHandler.setup(handler);
  31709. }
  31710. /* This class implements the QM Coder decoding as defined in
  31711. * JPEG 2000 Part I Final Committee Draft Version 1.0
  31712. * Annex C.3 Arithmetic decoding procedure
  31713. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  31714. *
  31715. * The arithmetic decoder is used in conjunction with context models to decode
  31716. * JPEG2000 and JBIG2 streams.
  31717. */
  31718. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  31719. // Table C-2
  31720. var QeTable = [
  31721. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  31722. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  31723. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  31724. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  31725. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  31726. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  31727. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  31728. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  31729. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  31730. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  31731. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  31732. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  31733. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  31734. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  31735. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  31736. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  31737. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  31738. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  31739. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  31740. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  31741. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  31742. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  31743. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  31744. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  31745. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  31746. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  31747. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  31748. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  31749. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  31750. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  31751. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  31752. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  31753. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  31754. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  31755. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  31756. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  31757. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  31758. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  31759. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  31760. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  31761. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  31762. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  31763. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  31764. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  31765. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  31766. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  31767. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  31768. ];
  31769. // C.3.5 Initialisation of the decoder (INITDEC)
  31770. function ArithmeticDecoder(data, start, end) {
  31771. this.data = data;
  31772. this.bp = start;
  31773. this.dataEnd = end;
  31774. this.chigh = data[start];
  31775. this.clow = 0;
  31776. this.byteIn();
  31777. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  31778. this.clow = (this.clow << 7) & 0xFFFF;
  31779. this.ct -= 7;
  31780. this.a = 0x8000;
  31781. }
  31782. ArithmeticDecoder.prototype = {
  31783. // C.3.4 Compressed data input (BYTEIN)
  31784. byteIn: function ArithmeticDecoder_byteIn() {
  31785. var data = this.data;
  31786. var bp = this.bp;
  31787. if (data[bp] === 0xFF) {
  31788. var b1 = data[bp + 1];
  31789. if (b1 > 0x8F) {
  31790. this.clow += 0xFF00;
  31791. this.ct = 8;
  31792. } else {
  31793. bp++;
  31794. this.clow += (data[bp] << 9);
  31795. this.ct = 7;
  31796. this.bp = bp;
  31797. }
  31798. } else {
  31799. bp++;
  31800. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  31801. this.ct = 8;
  31802. this.bp = bp;
  31803. }
  31804. if (this.clow > 0xFFFF) {
  31805. this.chigh += (this.clow >> 16);
  31806. this.clow &= 0xFFFF;
  31807. }
  31808. },
  31809. // C.3.2 Decoding a decision (DECODE)
  31810. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  31811. // contexts are packed into 1 byte:
  31812. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  31813. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  31814. var qeTableIcx = QeTable[cx_index];
  31815. var qeIcx = qeTableIcx.qe;
  31816. var d;
  31817. var a = this.a - qeIcx;
  31818. if (this.chigh < qeIcx) {
  31819. // exchangeLps
  31820. if (a < qeIcx) {
  31821. a = qeIcx;
  31822. d = cx_mps;
  31823. cx_index = qeTableIcx.nmps;
  31824. } else {
  31825. a = qeIcx;
  31826. d = 1 ^ cx_mps;
  31827. if (qeTableIcx.switchFlag === 1) {
  31828. cx_mps = d;
  31829. }
  31830. cx_index = qeTableIcx.nlps;
  31831. }
  31832. } else {
  31833. this.chigh -= qeIcx;
  31834. if ((a & 0x8000) !== 0) {
  31835. this.a = a;
  31836. return cx_mps;
  31837. }
  31838. // exchangeMps
  31839. if (a < qeIcx) {
  31840. d = 1 ^ cx_mps;
  31841. if (qeTableIcx.switchFlag === 1) {
  31842. cx_mps = d;
  31843. }
  31844. cx_index = qeTableIcx.nlps;
  31845. } else {
  31846. d = cx_mps;
  31847. cx_index = qeTableIcx.nmps;
  31848. }
  31849. }
  31850. // C.3.3 renormD;
  31851. do {
  31852. if (this.ct === 0) {
  31853. this.byteIn();
  31854. }
  31855. a <<= 1;
  31856. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  31857. this.clow = (this.clow << 1) & 0xFFFF;
  31858. this.ct--;
  31859. } while ((a & 0x8000) === 0);
  31860. this.a = a;
  31861. contexts[pos] = cx_index << 1 | cx_mps;
  31862. return d;
  31863. }
  31864. };
  31865. return ArithmeticDecoder;
  31866. })();
  31867. var JpegImage = (function jpegImage() {
  31868. var dctZigZag = new Uint8Array([
  31869. 0,
  31870. 1, 8,
  31871. 16, 9, 2,
  31872. 3, 10, 17, 24,
  31873. 32, 25, 18, 11, 4,
  31874. 5, 12, 19, 26, 33, 40,
  31875. 48, 41, 34, 27, 20, 13, 6,
  31876. 7, 14, 21, 28, 35, 42, 49, 56,
  31877. 57, 50, 43, 36, 29, 22, 15,
  31878. 23, 30, 37, 44, 51, 58,
  31879. 59, 52, 45, 38, 31,
  31880. 39, 46, 53, 60,
  31881. 61, 54, 47,
  31882. 55, 62,
  31883. 63
  31884. ]);
  31885. var dctCos1 = 4017; // cos(pi/16)
  31886. var dctSin1 = 799; // sin(pi/16)
  31887. var dctCos3 = 3406; // cos(3*pi/16)
  31888. var dctSin3 = 2276; // sin(3*pi/16)
  31889. var dctCos6 = 1567; // cos(6*pi/16)
  31890. var dctSin6 = 3784; // sin(6*pi/16)
  31891. var dctSqrt2 = 5793; // sqrt(2)
  31892. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  31893. function constructor() {
  31894. }
  31895. function buildHuffmanTable(codeLengths, values) {
  31896. var k = 0, code = [], i, j, length = 16;
  31897. while (length > 0 && !codeLengths[length - 1]) {
  31898. length--;
  31899. }
  31900. code.push({children: [], index: 0});
  31901. var p = code[0], q;
  31902. for (i = 0; i < length; i++) {
  31903. for (j = 0; j < codeLengths[i]; j++) {
  31904. p = code.pop();
  31905. p.children[p.index] = values[k];
  31906. while (p.index > 0) {
  31907. p = code.pop();
  31908. }
  31909. p.index++;
  31910. code.push(p);
  31911. while (code.length <= i) {
  31912. code.push(q = {children: [], index: 0});
  31913. p.children[p.index] = q.children;
  31914. p = q;
  31915. }
  31916. k++;
  31917. }
  31918. if (i + 1 < length) {
  31919. // p here points to last code
  31920. code.push(q = {children: [], index: 0});
  31921. p.children[p.index] = q.children;
  31922. p = q;
  31923. }
  31924. }
  31925. return code[0].children;
  31926. }
  31927. function getBlockBufferOffset(component, row, col) {
  31928. return 64 * ((component.blocksPerLine + 1) * row + col);
  31929. }
  31930. function decodeScan(data, offset, frame, components, resetInterval,
  31931. spectralStart, spectralEnd, successivePrev, successive) {
  31932. var precision = frame.precision;
  31933. var samplesPerLine = frame.samplesPerLine;
  31934. var scanLines = frame.scanLines;
  31935. var mcusPerLine = frame.mcusPerLine;
  31936. var progressive = frame.progressive;
  31937. var maxH = frame.maxH, maxV = frame.maxV;
  31938. var startOffset = offset, bitsData = 0, bitsCount = 0;
  31939. function readBit() {
  31940. if (bitsCount > 0) {
  31941. bitsCount--;
  31942. return (bitsData >> bitsCount) & 1;
  31943. }
  31944. bitsData = data[offset++];
  31945. if (bitsData === 0xFF) {
  31946. var nextByte = data[offset++];
  31947. if (nextByte) {
  31948. throw 'unexpected marker: ' +
  31949. ((bitsData << 8) | nextByte).toString(16);
  31950. }
  31951. // unstuff 0
  31952. }
  31953. bitsCount = 7;
  31954. return bitsData >>> 7;
  31955. }
  31956. function decodeHuffman(tree) {
  31957. var node = tree;
  31958. var bit;
  31959. while ((bit = readBit()) !== null) {
  31960. node = node[bit];
  31961. if (typeof node === 'number') {
  31962. return node;
  31963. }
  31964. if (typeof node !== 'object') {
  31965. throw 'invalid huffman sequence';
  31966. }
  31967. }
  31968. return null;
  31969. }
  31970. function receive(length) {
  31971. var n = 0;
  31972. while (length > 0) {
  31973. var bit = readBit();
  31974. if (bit === null) {
  31975. return;
  31976. }
  31977. n = (n << 1) | bit;
  31978. length--;
  31979. }
  31980. return n;
  31981. }
  31982. function receiveAndExtend(length) {
  31983. if (length === 1) {
  31984. return readBit() === 1 ? 1 : -1;
  31985. }
  31986. var n = receive(length);
  31987. if (n >= 1 << (length - 1)) {
  31988. return n;
  31989. }
  31990. return n + (-1 << length) + 1;
  31991. }
  31992. function decodeBaseline(component, offset) {
  31993. var t = decodeHuffman(component.huffmanTableDC);
  31994. var diff = t === 0 ? 0 : receiveAndExtend(t);
  31995. component.blockData[offset] = (component.pred += diff);
  31996. var k = 1;
  31997. while (k < 64) {
  31998. var rs = decodeHuffman(component.huffmanTableAC);
  31999. var s = rs & 15, r = rs >> 4;
  32000. if (s === 0) {
  32001. if (r < 15) {
  32002. break;
  32003. }
  32004. k += 16;
  32005. continue;
  32006. }
  32007. k += r;
  32008. var z = dctZigZag[k];
  32009. component.blockData[offset + z] = receiveAndExtend(s);
  32010. k++;
  32011. }
  32012. }
  32013. function decodeDCFirst(component, offset) {
  32014. var t = decodeHuffman(component.huffmanTableDC);
  32015. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32016. component.blockData[offset] = (component.pred += diff);
  32017. }
  32018. function decodeDCSuccessive(component, offset) {
  32019. component.blockData[offset] |= readBit() << successive;
  32020. }
  32021. var eobrun = 0;
  32022. function decodeACFirst(component, offset) {
  32023. if (eobrun > 0) {
  32024. eobrun--;
  32025. return;
  32026. }
  32027. var k = spectralStart, e = spectralEnd;
  32028. while (k <= e) {
  32029. var rs = decodeHuffman(component.huffmanTableAC);
  32030. var s = rs & 15, r = rs >> 4;
  32031. if (s === 0) {
  32032. if (r < 15) {
  32033. eobrun = receive(r) + (1 << r) - 1;
  32034. break;
  32035. }
  32036. k += 16;
  32037. continue;
  32038. }
  32039. k += r;
  32040. var z = dctZigZag[k];
  32041. component.blockData[offset + z] =
  32042. receiveAndExtend(s) * (1 << successive);
  32043. k++;
  32044. }
  32045. }
  32046. var successiveACState = 0, successiveACNextValue;
  32047. function decodeACSuccessive(component, offset) {
  32048. var k = spectralStart;
  32049. var e = spectralEnd;
  32050. var r = 0;
  32051. var s;
  32052. var rs;
  32053. while (k <= e) {
  32054. var z = dctZigZag[k];
  32055. switch (successiveACState) {
  32056. case 0: // initial state
  32057. rs = decodeHuffman(component.huffmanTableAC);
  32058. s = rs & 15;
  32059. r = rs >> 4;
  32060. if (s === 0) {
  32061. if (r < 15) {
  32062. eobrun = receive(r) + (1 << r);
  32063. successiveACState = 4;
  32064. } else {
  32065. r = 16;
  32066. successiveACState = 1;
  32067. }
  32068. } else {
  32069. if (s !== 1) {
  32070. throw 'invalid ACn encoding';
  32071. }
  32072. successiveACNextValue = receiveAndExtend(s);
  32073. successiveACState = r ? 2 : 3;
  32074. }
  32075. continue;
  32076. case 1: // skipping r zero items
  32077. case 2:
  32078. if (component.blockData[offset + z]) {
  32079. component.blockData[offset + z] += (readBit() << successive);
  32080. } else {
  32081. r--;
  32082. if (r === 0) {
  32083. successiveACState = successiveACState === 2 ? 3 : 0;
  32084. }
  32085. }
  32086. break;
  32087. case 3: // set value for a zero item
  32088. if (component.blockData[offset + z]) {
  32089. component.blockData[offset + z] += (readBit() << successive);
  32090. } else {
  32091. component.blockData[offset + z] =
  32092. successiveACNextValue << successive;
  32093. successiveACState = 0;
  32094. }
  32095. break;
  32096. case 4: // eob
  32097. if (component.blockData[offset + z]) {
  32098. component.blockData[offset + z] += (readBit() << successive);
  32099. }
  32100. break;
  32101. }
  32102. k++;
  32103. }
  32104. if (successiveACState === 4) {
  32105. eobrun--;
  32106. if (eobrun === 0) {
  32107. successiveACState = 0;
  32108. }
  32109. }
  32110. }
  32111. function decodeMcu(component, decode, mcu, row, col) {
  32112. var mcuRow = (mcu / mcusPerLine) | 0;
  32113. var mcuCol = mcu % mcusPerLine;
  32114. var blockRow = mcuRow * component.v + row;
  32115. var blockCol = mcuCol * component.h + col;
  32116. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32117. decode(component, offset);
  32118. }
  32119. function decodeBlock(component, decode, mcu) {
  32120. var blockRow = (mcu / component.blocksPerLine) | 0;
  32121. var blockCol = mcu % component.blocksPerLine;
  32122. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32123. decode(component, offset);
  32124. }
  32125. var componentsLength = components.length;
  32126. var component, i, j, k, n;
  32127. var decodeFn;
  32128. if (progressive) {
  32129. if (spectralStart === 0) {
  32130. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32131. } else {
  32132. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32133. }
  32134. } else {
  32135. decodeFn = decodeBaseline;
  32136. }
  32137. var mcu = 0, marker;
  32138. var mcuExpected;
  32139. if (componentsLength === 1) {
  32140. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32141. } else {
  32142. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32143. }
  32144. if (!resetInterval) {
  32145. resetInterval = mcuExpected;
  32146. }
  32147. var h, v;
  32148. while (mcu < mcuExpected) {
  32149. // reset interval stuff
  32150. for (i = 0; i < componentsLength; i++) {
  32151. components[i].pred = 0;
  32152. }
  32153. eobrun = 0;
  32154. if (componentsLength === 1) {
  32155. component = components[0];
  32156. for (n = 0; n < resetInterval; n++) {
  32157. decodeBlock(component, decodeFn, mcu);
  32158. mcu++;
  32159. }
  32160. } else {
  32161. for (n = 0; n < resetInterval; n++) {
  32162. for (i = 0; i < componentsLength; i++) {
  32163. component = components[i];
  32164. h = component.h;
  32165. v = component.v;
  32166. for (j = 0; j < v; j++) {
  32167. for (k = 0; k < h; k++) {
  32168. decodeMcu(component, decodeFn, mcu, j, k);
  32169. }
  32170. }
  32171. }
  32172. mcu++;
  32173. }
  32174. }
  32175. // find marker
  32176. bitsCount = 0;
  32177. marker = (data[offset] << 8) | data[offset + 1];
  32178. if (marker <= 0xFF00) {
  32179. throw 'marker was not found';
  32180. }
  32181. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32182. offset += 2;
  32183. } else {
  32184. break;
  32185. }
  32186. }
  32187. return offset - startOffset;
  32188. }
  32189. // A port of poppler's IDCT method which in turn is taken from:
  32190. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32191. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32192. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32193. // 988-991.
  32194. function quantizeAndInverse(component, blockBufferOffset, p) {
  32195. var qt = component.quantizationTable, blockData = component.blockData;
  32196. var v0, v1, v2, v3, v4, v5, v6, v7;
  32197. var p0, p1, p2, p3, p4, p5, p6, p7;
  32198. var t;
  32199. // inverse DCT on rows
  32200. for (var row = 0; row < 64; row += 8) {
  32201. // gather block data
  32202. p0 = blockData[blockBufferOffset + row];
  32203. p1 = blockData[blockBufferOffset + row + 1];
  32204. p2 = blockData[blockBufferOffset + row + 2];
  32205. p3 = blockData[blockBufferOffset + row + 3];
  32206. p4 = blockData[blockBufferOffset + row + 4];
  32207. p5 = blockData[blockBufferOffset + row + 5];
  32208. p6 = blockData[blockBufferOffset + row + 6];
  32209. p7 = blockData[blockBufferOffset + row + 7];
  32210. // dequant p0
  32211. p0 *= qt[row];
  32212. // check for all-zero AC coefficients
  32213. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32214. t = (dctSqrt2 * p0 + 512) >> 10;
  32215. p[row] = t;
  32216. p[row + 1] = t;
  32217. p[row + 2] = t;
  32218. p[row + 3] = t;
  32219. p[row + 4] = t;
  32220. p[row + 5] = t;
  32221. p[row + 6] = t;
  32222. p[row + 7] = t;
  32223. continue;
  32224. }
  32225. // dequant p1 ... p7
  32226. p1 *= qt[row + 1];
  32227. p2 *= qt[row + 2];
  32228. p3 *= qt[row + 3];
  32229. p4 *= qt[row + 4];
  32230. p5 *= qt[row + 5];
  32231. p6 *= qt[row + 6];
  32232. p7 *= qt[row + 7];
  32233. // stage 4
  32234. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32235. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32236. v2 = p2;
  32237. v3 = p6;
  32238. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32239. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32240. v5 = p3 << 4;
  32241. v6 = p5 << 4;
  32242. // stage 3
  32243. v0 = (v0 + v1 + 1) >> 1;
  32244. v1 = v0 - v1;
  32245. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32246. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32247. v3 = t;
  32248. v4 = (v4 + v6 + 1) >> 1;
  32249. v6 = v4 - v6;
  32250. v7 = (v7 + v5 + 1) >> 1;
  32251. v5 = v7 - v5;
  32252. // stage 2
  32253. v0 = (v0 + v3 + 1) >> 1;
  32254. v3 = v0 - v3;
  32255. v1 = (v1 + v2 + 1) >> 1;
  32256. v2 = v1 - v2;
  32257. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32258. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32259. v7 = t;
  32260. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32261. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32262. v6 = t;
  32263. // stage 1
  32264. p[row] = v0 + v7;
  32265. p[row + 7] = v0 - v7;
  32266. p[row + 1] = v1 + v6;
  32267. p[row + 6] = v1 - v6;
  32268. p[row + 2] = v2 + v5;
  32269. p[row + 5] = v2 - v5;
  32270. p[row + 3] = v3 + v4;
  32271. p[row + 4] = v3 - v4;
  32272. }
  32273. // inverse DCT on columns
  32274. for (var col = 0; col < 8; ++col) {
  32275. p0 = p[col];
  32276. p1 = p[col + 8];
  32277. p2 = p[col + 16];
  32278. p3 = p[col + 24];
  32279. p4 = p[col + 32];
  32280. p5 = p[col + 40];
  32281. p6 = p[col + 48];
  32282. p7 = p[col + 56];
  32283. // check for all-zero AC coefficients
  32284. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32285. t = (dctSqrt2 * p0 + 8192) >> 14;
  32286. // convert to 8 bit
  32287. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32288. blockData[blockBufferOffset + col] = t;
  32289. blockData[blockBufferOffset + col + 8] = t;
  32290. blockData[blockBufferOffset + col + 16] = t;
  32291. blockData[blockBufferOffset + col + 24] = t;
  32292. blockData[blockBufferOffset + col + 32] = t;
  32293. blockData[blockBufferOffset + col + 40] = t;
  32294. blockData[blockBufferOffset + col + 48] = t;
  32295. blockData[blockBufferOffset + col + 56] = t;
  32296. continue;
  32297. }
  32298. // stage 4
  32299. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32300. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32301. v2 = p2;
  32302. v3 = p6;
  32303. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32304. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32305. v5 = p3;
  32306. v6 = p5;
  32307. // stage 3
  32308. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32309. // converting to UInt8 range later.
  32310. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32311. v1 = v0 - v1;
  32312. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32313. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32314. v3 = t;
  32315. v4 = (v4 + v6 + 1) >> 1;
  32316. v6 = v4 - v6;
  32317. v7 = (v7 + v5 + 1) >> 1;
  32318. v5 = v7 - v5;
  32319. // stage 2
  32320. v0 = (v0 + v3 + 1) >> 1;
  32321. v3 = v0 - v3;
  32322. v1 = (v1 + v2 + 1) >> 1;
  32323. v2 = v1 - v2;
  32324. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32325. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32326. v7 = t;
  32327. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32328. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32329. v6 = t;
  32330. // stage 1
  32331. p0 = v0 + v7;
  32332. p7 = v0 - v7;
  32333. p1 = v1 + v6;
  32334. p6 = v1 - v6;
  32335. p2 = v2 + v5;
  32336. p5 = v2 - v5;
  32337. p3 = v3 + v4;
  32338. p4 = v3 - v4;
  32339. // convert to 8-bit integers
  32340. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32341. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32342. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32343. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32344. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32345. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32346. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32347. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32348. // store block data
  32349. blockData[blockBufferOffset + col] = p0;
  32350. blockData[blockBufferOffset + col + 8] = p1;
  32351. blockData[blockBufferOffset + col + 16] = p2;
  32352. blockData[blockBufferOffset + col + 24] = p3;
  32353. blockData[blockBufferOffset + col + 32] = p4;
  32354. blockData[blockBufferOffset + col + 40] = p5;
  32355. blockData[blockBufferOffset + col + 48] = p6;
  32356. blockData[blockBufferOffset + col + 56] = p7;
  32357. }
  32358. }
  32359. function buildComponentData(frame, component) {
  32360. var blocksPerLine = component.blocksPerLine;
  32361. var blocksPerColumn = component.blocksPerColumn;
  32362. var computationBuffer = new Int16Array(64);
  32363. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32364. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32365. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32366. quantizeAndInverse(component, offset, computationBuffer);
  32367. }
  32368. }
  32369. return component.blockData;
  32370. }
  32371. function clamp0to255(a) {
  32372. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32373. }
  32374. constructor.prototype = {
  32375. parse: function parse(data) {
  32376. function readUint16() {
  32377. var value = (data[offset] << 8) | data[offset + 1];
  32378. offset += 2;
  32379. return value;
  32380. }
  32381. function readDataBlock() {
  32382. var length = readUint16();
  32383. var array = data.subarray(offset, offset + length - 2);
  32384. offset += array.length;
  32385. return array;
  32386. }
  32387. function prepareComponents(frame) {
  32388. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32389. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32390. for (var i = 0; i < frame.components.length; i++) {
  32391. component = frame.components[i];
  32392. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32393. component.h / frame.maxH);
  32394. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32395. component.v / frame.maxV);
  32396. var blocksPerLineForMcu = mcusPerLine * component.h;
  32397. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32398. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32399. (blocksPerLineForMcu + 1);
  32400. component.blockData = new Int16Array(blocksBufferSize);
  32401. component.blocksPerLine = blocksPerLine;
  32402. component.blocksPerColumn = blocksPerColumn;
  32403. }
  32404. frame.mcusPerLine = mcusPerLine;
  32405. frame.mcusPerColumn = mcusPerColumn;
  32406. }
  32407. var offset = 0, length = data.length;
  32408. var jfif = null;
  32409. var adobe = null;
  32410. var pixels = null;
  32411. var frame, resetInterval;
  32412. var quantizationTables = [];
  32413. var huffmanTablesAC = [], huffmanTablesDC = [];
  32414. var fileMarker = readUint16();
  32415. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32416. throw 'SOI not found';
  32417. }
  32418. fileMarker = readUint16();
  32419. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32420. var i, j, l;
  32421. switch(fileMarker) {
  32422. case 0xFFE0: // APP0 (Application Specific)
  32423. case 0xFFE1: // APP1
  32424. case 0xFFE2: // APP2
  32425. case 0xFFE3: // APP3
  32426. case 0xFFE4: // APP4
  32427. case 0xFFE5: // APP5
  32428. case 0xFFE6: // APP6
  32429. case 0xFFE7: // APP7
  32430. case 0xFFE8: // APP8
  32431. case 0xFFE9: // APP9
  32432. case 0xFFEA: // APP10
  32433. case 0xFFEB: // APP11
  32434. case 0xFFEC: // APP12
  32435. case 0xFFED: // APP13
  32436. case 0xFFEE: // APP14
  32437. case 0xFFEF: // APP15
  32438. case 0xFFFE: // COM (Comment)
  32439. var appData = readDataBlock();
  32440. if (fileMarker === 0xFFE0) {
  32441. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32442. appData[2] === 0x49 && appData[3] === 0x46 &&
  32443. appData[4] === 0) { // 'JFIF\x00'
  32444. jfif = {
  32445. version: { major: appData[5], minor: appData[6] },
  32446. densityUnits: appData[7],
  32447. xDensity: (appData[8] << 8) | appData[9],
  32448. yDensity: (appData[10] << 8) | appData[11],
  32449. thumbWidth: appData[12],
  32450. thumbHeight: appData[13],
  32451. thumbData: appData.subarray(14, 14 +
  32452. 3 * appData[12] * appData[13])
  32453. };
  32454. }
  32455. }
  32456. // TODO APP1 - Exif
  32457. if (fileMarker === 0xFFEE) {
  32458. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32459. appData[2] === 0x6F && appData[3] === 0x62 &&
  32460. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32461. adobe = {
  32462. version: appData[6],
  32463. flags0: (appData[7] << 8) | appData[8],
  32464. flags1: (appData[9] << 8) | appData[10],
  32465. transformCode: appData[11]
  32466. };
  32467. }
  32468. }
  32469. break;
  32470. case 0xFFDB: // DQT (Define Quantization Tables)
  32471. var quantizationTablesLength = readUint16();
  32472. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32473. var z;
  32474. while (offset < quantizationTablesEnd) {
  32475. var quantizationTableSpec = data[offset++];
  32476. var tableData = new Uint16Array(64);
  32477. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32478. for (j = 0; j < 64; j++) {
  32479. z = dctZigZag[j];
  32480. tableData[z] = data[offset++];
  32481. }
  32482. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32483. for (j = 0; j < 64; j++) {
  32484. z = dctZigZag[j];
  32485. tableData[z] = readUint16();
  32486. }
  32487. } else {
  32488. throw 'DQT: invalid table spec';
  32489. }
  32490. quantizationTables[quantizationTableSpec & 15] = tableData;
  32491. }
  32492. break;
  32493. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32494. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32495. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32496. if (frame) {
  32497. throw 'Only single frame JPEGs supported';
  32498. }
  32499. readUint16(); // skip data length
  32500. frame = {};
  32501. frame.extended = (fileMarker === 0xFFC1);
  32502. frame.progressive = (fileMarker === 0xFFC2);
  32503. frame.precision = data[offset++];
  32504. frame.scanLines = readUint16();
  32505. frame.samplesPerLine = readUint16();
  32506. frame.components = [];
  32507. frame.componentIds = {};
  32508. var componentsCount = data[offset++], componentId;
  32509. var maxH = 0, maxV = 0;
  32510. for (i = 0; i < componentsCount; i++) {
  32511. componentId = data[offset];
  32512. var h = data[offset + 1] >> 4;
  32513. var v = data[offset + 1] & 15;
  32514. if (maxH < h) {
  32515. maxH = h;
  32516. }
  32517. if (maxV < v) {
  32518. maxV = v;
  32519. }
  32520. var qId = data[offset + 2];
  32521. l = frame.components.push({
  32522. h: h,
  32523. v: v,
  32524. quantizationTable: quantizationTables[qId]
  32525. });
  32526. frame.componentIds[componentId] = l - 1;
  32527. offset += 3;
  32528. }
  32529. frame.maxH = maxH;
  32530. frame.maxV = maxV;
  32531. prepareComponents(frame);
  32532. break;
  32533. case 0xFFC4: // DHT (Define Huffman Tables)
  32534. var huffmanLength = readUint16();
  32535. for (i = 2; i < huffmanLength;) {
  32536. var huffmanTableSpec = data[offset++];
  32537. var codeLengths = new Uint8Array(16);
  32538. var codeLengthSum = 0;
  32539. for (j = 0; j < 16; j++, offset++) {
  32540. codeLengthSum += (codeLengths[j] = data[offset]);
  32541. }
  32542. var huffmanValues = new Uint8Array(codeLengthSum);
  32543. for (j = 0; j < codeLengthSum; j++, offset++) {
  32544. huffmanValues[j] = data[offset];
  32545. }
  32546. i += 17 + codeLengthSum;
  32547. ((huffmanTableSpec >> 4) === 0 ?
  32548. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32549. buildHuffmanTable(codeLengths, huffmanValues);
  32550. }
  32551. break;
  32552. case 0xFFDD: // DRI (Define Restart Interval)
  32553. readUint16(); // skip data length
  32554. resetInterval = readUint16();
  32555. break;
  32556. case 0xFFDA: // SOS (Start of Scan)
  32557. var scanLength = readUint16();
  32558. var selectorsCount = data[offset++];
  32559. var components = [], component;
  32560. for (i = 0; i < selectorsCount; i++) {
  32561. var componentIndex = frame.componentIds[data[offset++]];
  32562. component = frame.components[componentIndex];
  32563. var tableSpec = data[offset++];
  32564. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32565. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32566. components.push(component);
  32567. }
  32568. var spectralStart = data[offset++];
  32569. var spectralEnd = data[offset++];
  32570. var successiveApproximation = data[offset++];
  32571. var processed = decodeScan(data, offset,
  32572. frame, components, resetInterval,
  32573. spectralStart, spectralEnd,
  32574. successiveApproximation >> 4, successiveApproximation & 15);
  32575. offset += processed;
  32576. break;
  32577. default:
  32578. if (data[offset - 3] === 0xFF &&
  32579. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32580. // could be incorrect encoding -- last 0xFF byte of the previous
  32581. // block was eaten by the encoder
  32582. offset -= 3;
  32583. break;
  32584. }
  32585. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32586. }
  32587. fileMarker = readUint16();
  32588. }
  32589. this.width = frame.samplesPerLine;
  32590. this.height = frame.scanLines;
  32591. this.jfif = jfif;
  32592. this.adobe = adobe;
  32593. this.components = [];
  32594. for (i = 0; i < frame.components.length; i++) {
  32595. component = frame.components[i];
  32596. this.components.push({
  32597. output: buildComponentData(frame, component),
  32598. scaleX: component.h / frame.maxH,
  32599. scaleY: component.v / frame.maxV,
  32600. blocksPerLine: component.blocksPerLine,
  32601. blocksPerColumn: component.blocksPerColumn
  32602. });
  32603. }
  32604. this.numComponents = this.components.length;
  32605. },
  32606. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32607. var scaleX = this.width / width, scaleY = this.height / height;
  32608. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32609. var x, y, i, j, k;
  32610. var index;
  32611. var offset = 0;
  32612. var output;
  32613. var numComponents = this.components.length;
  32614. var dataLength = width * height * numComponents;
  32615. var data = new Uint8Array(dataLength);
  32616. var xScaleBlockOffset = new Uint32Array(width);
  32617. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32618. for (i = 0; i < numComponents; i++) {
  32619. component = this.components[i];
  32620. componentScaleX = component.scaleX * scaleX;
  32621. componentScaleY = component.scaleY * scaleY;
  32622. offset = i;
  32623. output = component.output;
  32624. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32625. // precalculate the xScaleBlockOffset
  32626. for (x = 0; x < width; x++) {
  32627. j = 0 | (x * componentScaleX);
  32628. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32629. }
  32630. // linearize the blocks of the component
  32631. for (y = 0; y < height; y++) {
  32632. j = 0 | (y * componentScaleY);
  32633. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  32634. for (x = 0; x < width; x++) {
  32635. data[offset] = output[index + xScaleBlockOffset[x]];
  32636. offset += numComponents;
  32637. }
  32638. }
  32639. }
  32640. // decodeTransform will contains pairs of multiplier (-256..256) and
  32641. // additive
  32642. var transform = this.decodeTransform;
  32643. if (transform) {
  32644. for (i = 0; i < dataLength;) {
  32645. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  32646. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  32647. }
  32648. }
  32649. }
  32650. return data;
  32651. },
  32652. _isColorConversionNeeded: function isColorConversionNeeded() {
  32653. if (this.adobe && this.adobe.transformCode) {
  32654. // The adobe transform marker overrides any previous setting
  32655. return true;
  32656. } else if (this.numComponents === 3) {
  32657. return true;
  32658. } else {
  32659. return false;
  32660. }
  32661. },
  32662. _convertYccToRgb: function convertYccToRgb(data) {
  32663. var Y, Cb, Cr;
  32664. for (var i = 0, length = data.length; i < length; i += 3) {
  32665. Y = data[i ];
  32666. Cb = data[i + 1];
  32667. Cr = data[i + 2];
  32668. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  32669. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  32670. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  32671. }
  32672. return data;
  32673. },
  32674. _convertYcckToRgb: function convertYcckToRgb(data) {
  32675. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  32676. var offset = 0;
  32677. for (var i = 0, length = data.length; i < length; i += 4) {
  32678. Y = data[i];
  32679. Cb = data[i + 1];
  32680. Cr = data[i + 2];
  32681. k = data[i + 3];
  32682. CbCb = Cb * Cb;
  32683. CbCr = Cb * Cr;
  32684. CbY = Cb * Y;
  32685. Cbk = Cb * k;
  32686. CrCr = Cr * Cr;
  32687. Crk = Cr * k;
  32688. CrY = Cr * Y;
  32689. YY = Y * Y;
  32690. Yk = Y * k;
  32691. kk = k * k;
  32692. var r = - 122.67195406894 -
  32693. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  32694. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  32695. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  32696. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  32697. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  32698. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  32699. 0.000336197177618394 * kk + 0.484791561490776 * k;
  32700. var g = 107.268039397724 +
  32701. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  32702. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  32703. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  32704. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  32705. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  32706. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  32707. 0.000318913117588328 * kk - 0.213742400323665 * k;
  32708. var b = - 20.810012546947 -
  32709. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  32710. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  32711. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  32712. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  32713. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  32714. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  32715. 0.000343531996510555 * kk + 0.24165260232407 * k;
  32716. data[offset++] = clamp0to255(r);
  32717. data[offset++] = clamp0to255(g);
  32718. data[offset++] = clamp0to255(b);
  32719. }
  32720. return data;
  32721. },
  32722. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  32723. var Y, Cb, Cr;
  32724. for (var i = 0, length = data.length; i < length; i += 4) {
  32725. Y = data[i];
  32726. Cb = data[i + 1];
  32727. Cr = data[i + 2];
  32728. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  32729. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  32730. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  32731. // K in data[i + 3] is unchanged
  32732. }
  32733. return data;
  32734. },
  32735. _convertCmykToRgb: function convertCmykToRgb(data) {
  32736. var c, m, y, k;
  32737. var offset = 0;
  32738. var min = -255 * 255 * 255;
  32739. var scale = 1 / 255 / 255;
  32740. for (var i = 0, length = data.length; i < length; i += 4) {
  32741. c = data[i];
  32742. m = data[i + 1];
  32743. y = data[i + 2];
  32744. k = data[i + 3];
  32745. var r =
  32746. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32747. 18.82290502165302 * y + 212.25662451639585 * k -
  32748. 72734.4411664936) +
  32749. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  32750. 17.873870861415444 * k - 1401.7366389350734) +
  32751. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32752. 4465.541406466231) -
  32753. k * (21.86122147463605 * k + 48317.86113160301);
  32754. var g =
  32755. c * (8.841041422036149 * c + 60.118027045597366 * m +
  32756. 6.871425592049007 * y + 31.159100130055922 * k -
  32757. 20220.756542821975) +
  32758. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32759. 131.35250912493976 * k - 48691.05921601825) +
  32760. y * (4.444339102852739 * y + 9.8632861493405 * k -
  32761. 6341.191035517494) -
  32762. k * (20.737325471181034 * k + 47890.15695978492);
  32763. var b =
  32764. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32765. 30.89978309703729 * y - 0.23883238689178934 * k -
  32766. 3616.812083916688) +
  32767. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32768. 50.606957656360734 * k - 28620.90484698408) +
  32769. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  32770. 49363.43385999684) -
  32771. k * (22.33816807309886 * k + 45932.16563550634);
  32772. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  32773. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  32774. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  32775. }
  32776. return data;
  32777. },
  32778. getData: function getData(width, height, forceRGBoutput) {
  32779. if (this.numComponents > 4) {
  32780. throw 'Unsupported color mode';
  32781. }
  32782. // type of data: Uint8Array(width * height * numComponents)
  32783. var data = this._getLinearizedBlockData(width, height);
  32784. if (this.numComponents === 3) {
  32785. return this._convertYccToRgb(data);
  32786. } else if (this.numComponents === 4) {
  32787. if (this._isColorConversionNeeded()) {
  32788. if (forceRGBoutput) {
  32789. return this._convertYcckToRgb(data);
  32790. } else {
  32791. return this._convertYcckToCmyk(data);
  32792. }
  32793. } else if (forceRGBoutput) {
  32794. return this._convertCmykToRgb(data);
  32795. }
  32796. }
  32797. return data;
  32798. }
  32799. };
  32800. return constructor;
  32801. })();
  32802. var JpxImage = (function JpxImageClosure() {
  32803. // Table E.1
  32804. var SubbandsGainLog2 = {
  32805. 'LL': 0,
  32806. 'LH': 1,
  32807. 'HL': 1,
  32808. 'HH': 2
  32809. };
  32810. function JpxImage() {
  32811. this.failOnCorruptedImage = false;
  32812. }
  32813. JpxImage.prototype = {
  32814. parse: function JpxImage_parse(data) {
  32815. var head = readUint16(data, 0);
  32816. // No box header, immediate start of codestream (SOC)
  32817. if (head === 0xFF4F) {
  32818. this.parseCodestream(data, 0, data.length);
  32819. return;
  32820. }
  32821. var position = 0, length = data.length;
  32822. while (position < length) {
  32823. var headerSize = 8;
  32824. var lbox = readUint32(data, position);
  32825. var tbox = readUint32(data, position + 4);
  32826. position += headerSize;
  32827. if (lbox === 1) {
  32828. // XLBox: read UInt64 according to spec.
  32829. // JavaScript's int precision of 53 bit should be sufficient here.
  32830. lbox = readUint32(data, position) * 4294967296 +
  32831. readUint32(data, position + 4);
  32832. position += 8;
  32833. headerSize += 8;
  32834. }
  32835. if (lbox === 0) {
  32836. lbox = length - position + headerSize;
  32837. }
  32838. if (lbox < headerSize) {
  32839. throw new Error('JPX Error: Invalid box field size');
  32840. }
  32841. var dataLength = lbox - headerSize;
  32842. var jumpDataLength = true;
  32843. switch (tbox) {
  32844. case 0x6A501A1A: // 'jP\032\032'
  32845. // TODO
  32846. break;
  32847. case 0x6A703268: // 'jp2h'
  32848. jumpDataLength = false; // parsing child boxes
  32849. break;
  32850. case 0x636F6C72: // 'colr'
  32851. // TODO
  32852. break;
  32853. case 0x6A703263: // 'jp2c'
  32854. this.parseCodestream(data, position, position + dataLength);
  32855. break;
  32856. }
  32857. if (jumpDataLength) {
  32858. position += dataLength;
  32859. }
  32860. }
  32861. },
  32862. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  32863. var newByte = stream.getByte();
  32864. while (newByte >= 0) {
  32865. var oldByte = newByte;
  32866. newByte = stream.getByte();
  32867. var code = (oldByte << 8) | newByte;
  32868. // Image and tile size (SIZ)
  32869. if (code === 0xFF51) {
  32870. stream.skip(4);
  32871. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  32872. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  32873. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  32874. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  32875. stream.skip(16);
  32876. var Csiz = stream.getUint16(); // Byte 36
  32877. this.width = Xsiz - XOsiz;
  32878. this.height = Ysiz - YOsiz;
  32879. this.componentsCount = Csiz;
  32880. // Results are always returned as Uint8Arrays
  32881. this.bitsPerComponent = 8;
  32882. return;
  32883. }
  32884. }
  32885. throw new Error('JPX Error: No size marker found in JPX stream');
  32886. },
  32887. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  32888. var context = {};
  32889. try {
  32890. var doNotRecover = false;
  32891. var position = start;
  32892. while (position + 1 < end) {
  32893. var code = readUint16(data, position);
  32894. position += 2;
  32895. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  32896. switch (code) {
  32897. case 0xFF4F: // Start of codestream (SOC)
  32898. context.mainHeader = true;
  32899. break;
  32900. case 0xFFD9: // End of codestream (EOC)
  32901. break;
  32902. case 0xFF51: // Image and tile size (SIZ)
  32903. length = readUint16(data, position);
  32904. var siz = {};
  32905. siz.Xsiz = readUint32(data, position + 4);
  32906. siz.Ysiz = readUint32(data, position + 8);
  32907. siz.XOsiz = readUint32(data, position + 12);
  32908. siz.YOsiz = readUint32(data, position + 16);
  32909. siz.XTsiz = readUint32(data, position + 20);
  32910. siz.YTsiz = readUint32(data, position + 24);
  32911. siz.XTOsiz = readUint32(data, position + 28);
  32912. siz.YTOsiz = readUint32(data, position + 32);
  32913. var componentsCount = readUint16(data, position + 36);
  32914. siz.Csiz = componentsCount;
  32915. var components = [];
  32916. j = position + 38;
  32917. for (var i = 0; i < componentsCount; i++) {
  32918. var component = {
  32919. precision: (data[j] & 0x7F) + 1,
  32920. isSigned: !!(data[j] & 0x80),
  32921. XRsiz: data[j + 1],
  32922. YRsiz: data[j + 1]
  32923. };
  32924. calculateComponentDimensions(component, siz);
  32925. components.push(component);
  32926. }
  32927. context.SIZ = siz;
  32928. context.components = components;
  32929. calculateTileGrids(context, components);
  32930. context.QCC = [];
  32931. context.COC = [];
  32932. break;
  32933. case 0xFF55: // Tile-part lengths, main header (TLM)
  32934. var Ltlm = readUint16(data, position); // Marker segment length
  32935. // Skip tile length markers
  32936. position += Ltlm;
  32937. break;
  32938. case 0xFF5C: // Quantization default (QCD)
  32939. length = readUint16(data, position);
  32940. var qcd = {};
  32941. j = position + 2;
  32942. sqcd = data[j++];
  32943. switch (sqcd & 0x1F) {
  32944. case 0:
  32945. spqcdSize = 8;
  32946. scalarExpounded = true;
  32947. break;
  32948. case 1:
  32949. spqcdSize = 16;
  32950. scalarExpounded = false;
  32951. break;
  32952. case 2:
  32953. spqcdSize = 16;
  32954. scalarExpounded = true;
  32955. break;
  32956. default:
  32957. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32958. }
  32959. qcd.noQuantization = (spqcdSize === 8);
  32960. qcd.scalarExpounded = scalarExpounded;
  32961. qcd.guardBits = sqcd >> 5;
  32962. spqcds = [];
  32963. while (j < length + position) {
  32964. var spqcd = {};
  32965. if (spqcdSize === 8) {
  32966. spqcd.epsilon = data[j++] >> 3;
  32967. spqcd.mu = 0;
  32968. } else {
  32969. spqcd.epsilon = data[j] >> 3;
  32970. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32971. j += 2;
  32972. }
  32973. spqcds.push(spqcd);
  32974. }
  32975. qcd.SPqcds = spqcds;
  32976. if (context.mainHeader) {
  32977. context.QCD = qcd;
  32978. } else {
  32979. context.currentTile.QCD = qcd;
  32980. context.currentTile.QCC = [];
  32981. }
  32982. break;
  32983. case 0xFF5D: // Quantization component (QCC)
  32984. length = readUint16(data, position);
  32985. var qcc = {};
  32986. j = position + 2;
  32987. var cqcc;
  32988. if (context.SIZ.Csiz < 257) {
  32989. cqcc = data[j++];
  32990. } else {
  32991. cqcc = readUint16(data, j);
  32992. j += 2;
  32993. }
  32994. sqcd = data[j++];
  32995. switch (sqcd & 0x1F) {
  32996. case 0:
  32997. spqcdSize = 8;
  32998. scalarExpounded = true;
  32999. break;
  33000. case 1:
  33001. spqcdSize = 16;
  33002. scalarExpounded = false;
  33003. break;
  33004. case 2:
  33005. spqcdSize = 16;
  33006. scalarExpounded = true;
  33007. break;
  33008. default:
  33009. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33010. }
  33011. qcc.noQuantization = (spqcdSize === 8);
  33012. qcc.scalarExpounded = scalarExpounded;
  33013. qcc.guardBits = sqcd >> 5;
  33014. spqcds = [];
  33015. while (j < (length + position)) {
  33016. spqcd = {};
  33017. if (spqcdSize === 8) {
  33018. spqcd.epsilon = data[j++] >> 3;
  33019. spqcd.mu = 0;
  33020. } else {
  33021. spqcd.epsilon = data[j] >> 3;
  33022. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33023. j += 2;
  33024. }
  33025. spqcds.push(spqcd);
  33026. }
  33027. qcc.SPqcds = spqcds;
  33028. if (context.mainHeader) {
  33029. context.QCC[cqcc] = qcc;
  33030. } else {
  33031. context.currentTile.QCC[cqcc] = qcc;
  33032. }
  33033. break;
  33034. case 0xFF52: // Coding style default (COD)
  33035. length = readUint16(data, position);
  33036. var cod = {};
  33037. j = position + 2;
  33038. var scod = data[j++];
  33039. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33040. cod.sopMarkerUsed = !!(scod & 2);
  33041. cod.ephMarkerUsed = !!(scod & 4);
  33042. cod.progressionOrder = data[j++];
  33043. cod.layersCount = readUint16(data, j);
  33044. j += 2;
  33045. cod.multipleComponentTransform = data[j++];
  33046. cod.decompositionLevelsCount = data[j++];
  33047. cod.xcb = (data[j++] & 0xF) + 2;
  33048. cod.ycb = (data[j++] & 0xF) + 2;
  33049. var blockStyle = data[j++];
  33050. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33051. cod.resetContextProbabilities = !!(blockStyle & 2);
  33052. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33053. cod.verticalyStripe = !!(blockStyle & 8);
  33054. cod.predictableTermination = !!(blockStyle & 16);
  33055. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33056. cod.reversibleTransformation = data[j++];
  33057. if (cod.entropyCoderWithCustomPrecincts) {
  33058. var precinctsSizes = [];
  33059. while (j < length + position) {
  33060. var precinctsSize = data[j++];
  33061. precinctsSizes.push({
  33062. PPx: precinctsSize & 0xF,
  33063. PPy: precinctsSize >> 4
  33064. });
  33065. }
  33066. cod.precinctsSizes = precinctsSizes;
  33067. }
  33068. var unsupported = [];
  33069. if (cod.sopMarkerUsed) {
  33070. unsupported.push('sopMarkerUsed');
  33071. }
  33072. if (cod.ephMarkerUsed) {
  33073. unsupported.push('ephMarkerUsed');
  33074. }
  33075. if (cod.selectiveArithmeticCodingBypass) {
  33076. unsupported.push('selectiveArithmeticCodingBypass');
  33077. }
  33078. if (cod.resetContextProbabilities) {
  33079. unsupported.push('resetContextProbabilities');
  33080. }
  33081. if (cod.terminationOnEachCodingPass) {
  33082. unsupported.push('terminationOnEachCodingPass');
  33083. }
  33084. if (cod.verticalyStripe) {
  33085. unsupported.push('verticalyStripe');
  33086. }
  33087. if (cod.predictableTermination) {
  33088. unsupported.push('predictableTermination');
  33089. }
  33090. if (unsupported.length > 0) {
  33091. doNotRecover = true;
  33092. throw new Error('JPX Error: Unsupported COD options (' +
  33093. unsupported.join(', ') + ')');
  33094. }
  33095. if (context.mainHeader) {
  33096. context.COD = cod;
  33097. } else {
  33098. context.currentTile.COD = cod;
  33099. context.currentTile.COC = [];
  33100. }
  33101. break;
  33102. case 0xFF90: // Start of tile-part (SOT)
  33103. length = readUint16(data, position);
  33104. tile = {};
  33105. tile.index = readUint16(data, position + 2);
  33106. tile.length = readUint32(data, position + 4);
  33107. tile.dataEnd = tile.length + position - 2;
  33108. tile.partIndex = data[position + 8];
  33109. tile.partsCount = data[position + 9];
  33110. context.mainHeader = false;
  33111. if (tile.partIndex === 0) {
  33112. // reset component specific settings
  33113. tile.COD = context.COD;
  33114. tile.COC = context.COC.slice(0); // clone of the global COC
  33115. tile.QCD = context.QCD;
  33116. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33117. }
  33118. context.currentTile = tile;
  33119. break;
  33120. case 0xFF93: // Start of data (SOD)
  33121. tile = context.currentTile;
  33122. if (tile.partIndex === 0) {
  33123. initializeTile(context, tile.index);
  33124. buildPackets(context);
  33125. }
  33126. // moving to the end of the data
  33127. length = tile.dataEnd - position;
  33128. parseTilePackets(context, data, position, length);
  33129. break;
  33130. case 0xFF64: // Comment (COM)
  33131. length = readUint16(data, position);
  33132. // skipping content
  33133. break;
  33134. case 0xFF53: // Coding style component (COC)
  33135. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33136. 'not implemented');
  33137. default:
  33138. throw new Error('JPX Error: Unknown codestream code: ' +
  33139. code.toString(16));
  33140. }
  33141. position += length;
  33142. }
  33143. } catch (e) {
  33144. if (doNotRecover || this.failOnCorruptedImage) {
  33145. throw e;
  33146. } else {
  33147. warn('Trying to recover from ' + e.message);
  33148. }
  33149. }
  33150. this.tiles = transformComponents(context);
  33151. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33152. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33153. this.componentsCount = context.SIZ.Csiz;
  33154. }
  33155. };
  33156. function calculateComponentDimensions(component, siz) {
  33157. // Section B.2 Component mapping
  33158. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33159. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33160. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33161. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33162. component.width = component.x1 - component.x0;
  33163. component.height = component.y1 - component.y0;
  33164. }
  33165. function calculateTileGrids(context, components) {
  33166. var siz = context.SIZ;
  33167. // Section B.3 Division into tile and tile-components
  33168. var tile, tiles = [];
  33169. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33170. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33171. for (var q = 0; q < numYtiles; q++) {
  33172. for (var p = 0; p < numXtiles; p++) {
  33173. tile = {};
  33174. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33175. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33176. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33177. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33178. tile.width = tile.tx1 - tile.tx0;
  33179. tile.height = tile.ty1 - tile.ty0;
  33180. tile.components = [];
  33181. tiles.push(tile);
  33182. }
  33183. }
  33184. context.tiles = tiles;
  33185. var componentsCount = siz.Csiz;
  33186. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33187. var component = components[i];
  33188. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33189. var tileComponent = {};
  33190. tile = tiles[j];
  33191. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33192. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33193. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33194. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33195. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33196. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33197. tile.components[i] = tileComponent;
  33198. }
  33199. }
  33200. }
  33201. function getBlocksDimensions(context, component, r) {
  33202. var codOrCoc = component.codingStyleParameters;
  33203. var result = {};
  33204. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33205. result.PPx = 15;
  33206. result.PPy = 15;
  33207. } else {
  33208. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33209. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33210. }
  33211. // calculate codeblock size as described in section B.7
  33212. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33213. Math.min(codOrCoc.xcb, result.PPx));
  33214. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33215. Math.min(codOrCoc.ycb, result.PPy));
  33216. return result;
  33217. }
  33218. function buildPrecincts(context, resolution, dimensions) {
  33219. // Section B.6 Division resolution to precincts
  33220. var precinctWidth = 1 << dimensions.PPx;
  33221. var precinctHeight = 1 << dimensions.PPy;
  33222. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33223. Math.ceil(resolution.trx1 / precinctWidth) -
  33224. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33225. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33226. Math.ceil(resolution.try1 / precinctHeight) -
  33227. Math.floor(resolution.try0 / precinctHeight) : 0);
  33228. var numprecincts = numprecinctswide * numprecinctshigh;
  33229. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  33230. precinctWidth;
  33231. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  33232. precinctHeight;
  33233. resolution.precinctParameters = {
  33234. precinctXOffset: precinctXOffset,
  33235. precinctYOffset: precinctYOffset,
  33236. precinctWidth: precinctWidth,
  33237. precinctHeight: precinctHeight,
  33238. numprecinctswide: numprecinctswide,
  33239. numprecinctshigh: numprecinctshigh,
  33240. numprecincts: numprecincts
  33241. };
  33242. }
  33243. function buildCodeblocks(context, subband, dimensions) {
  33244. // Section B.7 Division sub-band into code-blocks
  33245. var xcb_ = dimensions.xcb_;
  33246. var ycb_ = dimensions.ycb_;
  33247. var codeblockWidth = 1 << xcb_;
  33248. var codeblockHeight = 1 << ycb_;
  33249. var cbx0 = subband.tbx0 >> xcb_;
  33250. var cby0 = subband.tby0 >> ycb_;
  33251. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33252. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33253. var precinctParameters = subband.resolution.precinctParameters;
  33254. var codeblocks = [];
  33255. var precincts = [];
  33256. var i, j, codeblock, precinctNumber;
  33257. for (j = cby0; j < cby1; j++) {
  33258. for (i = cbx0; i < cbx1; i++) {
  33259. codeblock = {
  33260. cbx: i,
  33261. cby: j,
  33262. tbx0: codeblockWidth * i,
  33263. tby0: codeblockHeight * j,
  33264. tbx1: codeblockWidth * (i + 1),
  33265. tby1: codeblockHeight * (j + 1)
  33266. };
  33267. // calculate precinct number
  33268. var pi = Math.floor((codeblock.tbx0 -
  33269. precinctParameters.precinctXOffset) /
  33270. precinctParameters.precinctWidth);
  33271. var pj = Math.floor((codeblock.tby0 -
  33272. precinctParameters.precinctYOffset) /
  33273. precinctParameters.precinctHeight);
  33274. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  33275. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33276. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33277. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33278. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33279. codeblock.precinctNumber = precinctNumber;
  33280. codeblock.subbandType = subband.type;
  33281. codeblock.Lblock = 3;
  33282. codeblocks.push(codeblock);
  33283. // building precinct for the sub-band
  33284. var precinct = precincts[precinctNumber];
  33285. if (precinct !== undefined) {
  33286. if (i < precinct.cbxMin) {
  33287. precinct.cbxMin = i;
  33288. } else if (i > precinct.cbxMax) {
  33289. precinct.cbxMax = i;
  33290. }
  33291. if (j < precinct.cbyMin) {
  33292. precinct.cbxMin = j;
  33293. } else if (j > precinct.cbyMax) {
  33294. precinct.cbyMax = j;
  33295. }
  33296. } else {
  33297. precincts[precinctNumber] = precinct = {
  33298. cbxMin: i,
  33299. cbyMin: j,
  33300. cbxMax: i,
  33301. cbyMax: j
  33302. };
  33303. }
  33304. codeblock.precinct = precinct;
  33305. }
  33306. }
  33307. subband.codeblockParameters = {
  33308. codeblockWidth: xcb_,
  33309. codeblockHeight: ycb_,
  33310. numcodeblockwide: cbx1 - cbx0 + 1,
  33311. numcodeblockhigh: cby1 - cby0 + 1
  33312. };
  33313. subband.codeblocks = codeblocks;
  33314. subband.precincts = precincts;
  33315. }
  33316. function createPacket(resolution, precinctNumber, layerNumber) {
  33317. var precinctCodeblocks = [];
  33318. // Section B.10.8 Order of info in packet
  33319. var subbands = resolution.subbands;
  33320. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33321. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33322. var subband = subbands[i];
  33323. var codeblocks = subband.codeblocks;
  33324. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33325. var codeblock = codeblocks[j];
  33326. if (codeblock.precinctNumber !== precinctNumber) {
  33327. continue;
  33328. }
  33329. precinctCodeblocks.push(codeblock);
  33330. }
  33331. }
  33332. return {
  33333. layerNumber: layerNumber,
  33334. codeblocks: precinctCodeblocks
  33335. };
  33336. }
  33337. function LayerResolutionComponentPositionIterator(context) {
  33338. var siz = context.SIZ;
  33339. var tileIndex = context.currentTile.index;
  33340. var tile = context.tiles[tileIndex];
  33341. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33342. var componentsCount = siz.Csiz;
  33343. var maxDecompositionLevelsCount = 0;
  33344. for (var q = 0; q < componentsCount; q++) {
  33345. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33346. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33347. }
  33348. var l = 0, r = 0, i = 0, k = 0;
  33349. this.nextPacket = function JpxImage_nextPacket() {
  33350. // Section B.12.1.1 Layer-resolution-component-position
  33351. for (; l < layersCount; l++) {
  33352. for (; r <= maxDecompositionLevelsCount; r++) {
  33353. for (; i < componentsCount; i++) {
  33354. var component = tile.components[i];
  33355. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33356. continue;
  33357. }
  33358. var resolution = component.resolutions[r];
  33359. var numprecincts = resolution.precinctParameters.numprecincts;
  33360. for (; k < numprecincts;) {
  33361. var packet = createPacket(resolution, k, l);
  33362. k++;
  33363. return packet;
  33364. }
  33365. k = 0;
  33366. }
  33367. i = 0;
  33368. }
  33369. r = 0;
  33370. }
  33371. throw new Error('JPX Error: Out of packets');
  33372. };
  33373. }
  33374. function ResolutionLayerComponentPositionIterator(context) {
  33375. var siz = context.SIZ;
  33376. var tileIndex = context.currentTile.index;
  33377. var tile = context.tiles[tileIndex];
  33378. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33379. var componentsCount = siz.Csiz;
  33380. var maxDecompositionLevelsCount = 0;
  33381. for (var q = 0; q < componentsCount; q++) {
  33382. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33383. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33384. }
  33385. var r = 0, l = 0, i = 0, k = 0;
  33386. this.nextPacket = function JpxImage_nextPacket() {
  33387. // Section B.12.1.2 Resolution-layer-component-position
  33388. for (; r <= maxDecompositionLevelsCount; r++) {
  33389. for (; l < layersCount; l++) {
  33390. for (; i < componentsCount; i++) {
  33391. var component = tile.components[i];
  33392. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33393. continue;
  33394. }
  33395. var resolution = component.resolutions[r];
  33396. var numprecincts = resolution.precinctParameters.numprecincts;
  33397. for (; k < numprecincts;) {
  33398. var packet = createPacket(resolution, k, l);
  33399. k++;
  33400. return packet;
  33401. }
  33402. k = 0;
  33403. }
  33404. i = 0;
  33405. }
  33406. l = 0;
  33407. }
  33408. throw new Error('JPX Error: Out of packets');
  33409. };
  33410. }
  33411. function buildPackets(context) {
  33412. var siz = context.SIZ;
  33413. var tileIndex = context.currentTile.index;
  33414. var tile = context.tiles[tileIndex];
  33415. var componentsCount = siz.Csiz;
  33416. // Creating resolutions and sub-bands for each component
  33417. for (var c = 0; c < componentsCount; c++) {
  33418. var component = tile.components[c];
  33419. var decompositionLevelsCount =
  33420. component.codingStyleParameters.decompositionLevelsCount;
  33421. // Section B.5 Resolution levels and sub-bands
  33422. var resolutions = [];
  33423. var subbands = [];
  33424. for (var r = 0; r <= decompositionLevelsCount; r++) {
  33425. var blocksDimensions = getBlocksDimensions(context, component, r);
  33426. var resolution = {};
  33427. var scale = 1 << (decompositionLevelsCount - r);
  33428. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  33429. resolution.try0 = Math.ceil(component.tcy0 / scale);
  33430. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  33431. resolution.try1 = Math.ceil(component.tcy1 / scale);
  33432. buildPrecincts(context, resolution, blocksDimensions);
  33433. resolutions.push(resolution);
  33434. var subband;
  33435. if (r === 0) {
  33436. // one sub-band (LL) with last decomposition
  33437. subband = {};
  33438. subband.type = 'LL';
  33439. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  33440. subband.tby0 = Math.ceil(component.tcy0 / scale);
  33441. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  33442. subband.tby1 = Math.ceil(component.tcy1 / scale);
  33443. subband.resolution = resolution;
  33444. buildCodeblocks(context, subband, blocksDimensions);
  33445. subbands.push(subband);
  33446. resolution.subbands = [subband];
  33447. } else {
  33448. var bscale = 1 << (decompositionLevelsCount - r + 1);
  33449. var resolutionSubbands = [];
  33450. // three sub-bands (HL, LH and HH) with rest of decompositions
  33451. subband = {};
  33452. subband.type = 'HL';
  33453. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33454. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  33455. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33456. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  33457. subband.resolution = resolution;
  33458. buildCodeblocks(context, subband, blocksDimensions);
  33459. subbands.push(subband);
  33460. resolutionSubbands.push(subband);
  33461. subband = {};
  33462. subband.type = 'LH';
  33463. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  33464. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33465. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  33466. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33467. subband.resolution = resolution;
  33468. buildCodeblocks(context, subband, blocksDimensions);
  33469. subbands.push(subband);
  33470. resolutionSubbands.push(subband);
  33471. subband = {};
  33472. subband.type = 'HH';
  33473. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33474. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33475. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33476. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33477. subband.resolution = resolution;
  33478. buildCodeblocks(context, subband, blocksDimensions);
  33479. subbands.push(subband);
  33480. resolutionSubbands.push(subband);
  33481. resolution.subbands = resolutionSubbands;
  33482. }
  33483. }
  33484. component.resolutions = resolutions;
  33485. component.subbands = subbands;
  33486. }
  33487. // Generate the packets sequence
  33488. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  33489. switch (progressionOrder) {
  33490. case 0:
  33491. tile.packetsIterator =
  33492. new LayerResolutionComponentPositionIterator(context);
  33493. break;
  33494. case 1:
  33495. tile.packetsIterator =
  33496. new ResolutionLayerComponentPositionIterator(context);
  33497. break;
  33498. default:
  33499. throw new Error('JPX Error: Unsupported progression order ' +
  33500. progressionOrder);
  33501. }
  33502. }
  33503. function parseTilePackets(context, data, offset, dataLength) {
  33504. var position = 0;
  33505. var buffer, bufferSize = 0, skipNextBit = false;
  33506. function readBits(count) {
  33507. while (bufferSize < count) {
  33508. var b = data[offset + position];
  33509. position++;
  33510. if (skipNextBit) {
  33511. buffer = (buffer << 7) | b;
  33512. bufferSize += 7;
  33513. skipNextBit = false;
  33514. } else {
  33515. buffer = (buffer << 8) | b;
  33516. bufferSize += 8;
  33517. }
  33518. if (b === 0xFF) {
  33519. skipNextBit = true;
  33520. }
  33521. }
  33522. bufferSize -= count;
  33523. return (buffer >>> bufferSize) & ((1 << count) - 1);
  33524. }
  33525. function alignToByte() {
  33526. bufferSize = 0;
  33527. if (skipNextBit) {
  33528. position++;
  33529. skipNextBit = false;
  33530. }
  33531. }
  33532. function readCodingpasses() {
  33533. if (readBits(1) === 0) {
  33534. return 1;
  33535. }
  33536. if (readBits(1) === 0) {
  33537. return 2;
  33538. }
  33539. var value = readBits(2);
  33540. if (value < 3) {
  33541. return value + 3;
  33542. }
  33543. value = readBits(5);
  33544. if (value < 31) {
  33545. return value + 6;
  33546. }
  33547. value = readBits(7);
  33548. return value + 37;
  33549. }
  33550. var tileIndex = context.currentTile.index;
  33551. var tile = context.tiles[tileIndex];
  33552. var packetsIterator = tile.packetsIterator;
  33553. while (position < dataLength) {
  33554. var packet = packetsIterator.nextPacket();
  33555. if (!readBits(1)) {
  33556. alignToByte();
  33557. continue;
  33558. }
  33559. var layerNumber = packet.layerNumber;
  33560. var queue = [], codeblock;
  33561. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  33562. codeblock = packet.codeblocks[i];
  33563. var precinct = codeblock.precinct;
  33564. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  33565. var codeblockRow = codeblock.cby - precinct.cbyMin;
  33566. var codeblockIncluded = false;
  33567. var firstTimeInclusion = false;
  33568. var valueReady;
  33569. if ('included' in codeblock) {
  33570. codeblockIncluded = !!readBits(1);
  33571. } else {
  33572. // reading inclusion tree
  33573. precinct = codeblock.precinct;
  33574. var inclusionTree, zeroBitPlanesTree;
  33575. if ('inclusionTree' in precinct) {
  33576. inclusionTree = precinct.inclusionTree;
  33577. } else {
  33578. // building inclusion and zero bit-planes trees
  33579. var width = precinct.cbxMax - precinct.cbxMin + 1;
  33580. var height = precinct.cbyMax - precinct.cbyMin + 1;
  33581. inclusionTree = new InclusionTree(width, height, layerNumber);
  33582. zeroBitPlanesTree = new TagTree(width, height);
  33583. precinct.inclusionTree = inclusionTree;
  33584. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  33585. }
  33586. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  33587. while (true) {
  33588. if (readBits(1)) {
  33589. valueReady = !inclusionTree.nextLevel();
  33590. if (valueReady) {
  33591. codeblock.included = true;
  33592. codeblockIncluded = firstTimeInclusion = true;
  33593. break;
  33594. }
  33595. } else {
  33596. inclusionTree.incrementValue(layerNumber);
  33597. break;
  33598. }
  33599. }
  33600. }
  33601. }
  33602. if (!codeblockIncluded) {
  33603. continue;
  33604. }
  33605. if (firstTimeInclusion) {
  33606. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  33607. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  33608. while (true) {
  33609. if (readBits(1)) {
  33610. valueReady = !zeroBitPlanesTree.nextLevel();
  33611. if (valueReady) {
  33612. break;
  33613. }
  33614. } else {
  33615. zeroBitPlanesTree.incrementValue();
  33616. }
  33617. }
  33618. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  33619. }
  33620. var codingpasses = readCodingpasses();
  33621. while (readBits(1)) {
  33622. codeblock.Lblock++;
  33623. }
  33624. var codingpassesLog2 = log2(codingpasses);
  33625. // rounding down log2
  33626. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  33627. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  33628. var codedDataLength = readBits(bits);
  33629. queue.push({
  33630. codeblock: codeblock,
  33631. codingpasses: codingpasses,
  33632. dataLength: codedDataLength
  33633. });
  33634. }
  33635. alignToByte();
  33636. while (queue.length > 0) {
  33637. var packetItem = queue.shift();
  33638. codeblock = packetItem.codeblock;
  33639. if (!('data' in codeblock)) {
  33640. codeblock.data = [];
  33641. }
  33642. codeblock.data.push({
  33643. data: data,
  33644. start: offset + position,
  33645. end: offset + position + packetItem.dataLength,
  33646. codingpasses: packetItem.codingpasses
  33647. });
  33648. position += packetItem.dataLength;
  33649. }
  33650. }
  33651. return position;
  33652. }
  33653. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  33654. delta, mb, reversible, segmentationSymbolUsed) {
  33655. var x0 = subband.tbx0;
  33656. var y0 = subband.tby0;
  33657. var width = subband.tbx1 - subband.tbx0;
  33658. var codeblocks = subband.codeblocks;
  33659. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  33660. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  33661. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  33662. var codeblock = codeblocks[i];
  33663. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  33664. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  33665. if (blockWidth === 0 || blockHeight === 0) {
  33666. continue;
  33667. }
  33668. if (!('data' in codeblock)) {
  33669. continue;
  33670. }
  33671. var bitModel, currentCodingpassType;
  33672. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  33673. codeblock.zeroBitPlanes, mb);
  33674. currentCodingpassType = 2; // first bit plane starts from cleanup
  33675. // collect data
  33676. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  33677. var j, jj, dataItem;
  33678. for (j = 0, jj = data.length; j < jj; j++) {
  33679. dataItem = data[j];
  33680. totalLength += dataItem.end - dataItem.start;
  33681. codingpasses += dataItem.codingpasses;
  33682. }
  33683. var encodedData = new Uint8Array(totalLength);
  33684. var position = 0;
  33685. for (j = 0, jj = data.length; j < jj; j++) {
  33686. dataItem = data[j];
  33687. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  33688. encodedData.set(chunk, position);
  33689. position += chunk.length;
  33690. }
  33691. // decoding the item
  33692. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  33693. bitModel.setDecoder(decoder);
  33694. for (j = 0; j < codingpasses; j++) {
  33695. switch (currentCodingpassType) {
  33696. case 0:
  33697. bitModel.runSignificancePropogationPass();
  33698. break;
  33699. case 1:
  33700. bitModel.runMagnitudeRefinementPass();
  33701. break;
  33702. case 2:
  33703. bitModel.runCleanupPass();
  33704. if (segmentationSymbolUsed) {
  33705. bitModel.checkSegmentationSymbol();
  33706. }
  33707. break;
  33708. }
  33709. currentCodingpassType = (currentCodingpassType + 1) % 3;
  33710. }
  33711. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  33712. var sign = bitModel.coefficentsSign;
  33713. var magnitude = bitModel.coefficentsMagnitude;
  33714. var bitsDecoded = bitModel.bitsDecoded;
  33715. var magnitudeCorrection = reversible ? 0 : 0.5;
  33716. var k, n, nb;
  33717. position = 0;
  33718. // Do the interleaving of Section F.3.3 here, so we do not need
  33719. // to copy later. LL level is not interleaved, just copied.
  33720. var interleave = (subband.type !== 'LL');
  33721. for (j = 0; j < blockHeight; j++) {
  33722. var row = (offset / width) | 0; // row in the non-interleaved subband
  33723. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  33724. for (k = 0; k < blockWidth; k++) {
  33725. n = magnitude[position];
  33726. if (n !== 0) {
  33727. n = (n + magnitudeCorrection) * delta;
  33728. if (sign[position] !== 0) {
  33729. n = -n;
  33730. }
  33731. nb = bitsDecoded[position];
  33732. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  33733. if (reversible && (nb >= mb)) {
  33734. coefficients[pos] = n;
  33735. } else {
  33736. coefficients[pos] = n * (1 << (mb - nb));
  33737. }
  33738. }
  33739. offset++;
  33740. position++;
  33741. }
  33742. offset += width - blockWidth;
  33743. }
  33744. }
  33745. }
  33746. function transformTile(context, tile, c) {
  33747. var component = tile.components[c];
  33748. var codingStyleParameters = component.codingStyleParameters;
  33749. var quantizationParameters = component.quantizationParameters;
  33750. var decompositionLevelsCount =
  33751. codingStyleParameters.decompositionLevelsCount;
  33752. var spqcds = quantizationParameters.SPqcds;
  33753. var scalarExpounded = quantizationParameters.scalarExpounded;
  33754. var guardBits = quantizationParameters.guardBits;
  33755. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  33756. var precision = context.components[c].precision;
  33757. var reversible = codingStyleParameters.reversibleTransformation;
  33758. var transform = (reversible ? new ReversibleTransform() :
  33759. new IrreversibleTransform());
  33760. var subbandCoefficients = [];
  33761. var b = 0;
  33762. for (var i = 0; i <= decompositionLevelsCount; i++) {
  33763. var resolution = component.resolutions[i];
  33764. var width = resolution.trx1 - resolution.trx0;
  33765. var height = resolution.try1 - resolution.try0;
  33766. // Allocate space for the whole sublevel.
  33767. var coefficients = new Float32Array(width * height);
  33768. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  33769. var mu, epsilon;
  33770. if (!scalarExpounded) {
  33771. // formula E-5
  33772. mu = spqcds[0].mu;
  33773. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  33774. } else {
  33775. mu = spqcds[b].mu;
  33776. epsilon = spqcds[b].epsilon;
  33777. b++;
  33778. }
  33779. var subband = resolution.subbands[j];
  33780. var gainLog2 = SubbandsGainLog2[subband.type];
  33781. // calulate quantization coefficient (Section E.1.1.1)
  33782. var delta = (reversible ? 1 :
  33783. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  33784. var mb = (guardBits + epsilon - 1);
  33785. // In the first resolution level, copyCoefficients will fill the
  33786. // whole array with coefficients. In the succeding passes,
  33787. // copyCoefficients will consecutively fill in the values that belong
  33788. // to the interleaved positions of the HL, LH, and HH coefficients.
  33789. // The LL coefficients will then be interleaved in Transform.iterate().
  33790. copyCoefficients(coefficients, width, height, subband, delta, mb,
  33791. reversible, segmentationSymbolUsed);
  33792. }
  33793. subbandCoefficients.push({
  33794. width: width,
  33795. height: height,
  33796. items: coefficients
  33797. });
  33798. }
  33799. var result = transform.calculate(subbandCoefficients,
  33800. component.tcx0, component.tcy0);
  33801. return {
  33802. left: component.tcx0,
  33803. top: component.tcy0,
  33804. width: result.width,
  33805. height: result.height,
  33806. items: result.items
  33807. };
  33808. }
  33809. function transformComponents(context) {
  33810. var siz = context.SIZ;
  33811. var components = context.components;
  33812. var componentsCount = siz.Csiz;
  33813. var resultImages = [];
  33814. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  33815. var tile = context.tiles[i];
  33816. var transformedTiles = [];
  33817. var c;
  33818. for (c = 0; c < componentsCount; c++) {
  33819. transformedTiles[c] = transformTile(context, tile, c);
  33820. }
  33821. var tile0 = transformedTiles[0];
  33822. var out = new Uint8Array(tile0.items.length * componentsCount);
  33823. var result = {
  33824. left: tile0.left,
  33825. top: tile0.top,
  33826. width: tile0.width,
  33827. height: tile0.height,
  33828. items: out
  33829. };
  33830. // Section G.2.2 Inverse multi component transform
  33831. var shift, offset, max, min, maxK;
  33832. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  33833. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  33834. var fourComponents = componentsCount === 4;
  33835. var y0items = transformedTiles[0].items;
  33836. var y1items = transformedTiles[1].items;
  33837. var y2items = transformedTiles[2].items;
  33838. var y3items = fourComponents ? transformedTiles[3].items : null;
  33839. // HACK: The multiple component transform formulas below assume that
  33840. // all components have the same precision. With this in mind, we
  33841. // compute shift and offset only once.
  33842. shift = components[0].precision - 8;
  33843. offset = (128 << shift) + 0.5;
  33844. max = 255 * (1 << shift);
  33845. maxK = max * 0.5;
  33846. min = -maxK;
  33847. var component0 = tile.components[0];
  33848. var alpha01 = componentsCount - 3;
  33849. jj = y0items.length;
  33850. if (!component0.codingStyleParameters.reversibleTransformation) {
  33851. // inverse irreversible multiple component transform
  33852. for (j = 0; j < jj; j++, pos += alpha01) {
  33853. y0 = y0items[j] + offset;
  33854. y1 = y1items[j];
  33855. y2 = y2items[j];
  33856. r = y0 + 1.402 * y2;
  33857. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  33858. b = y0 + 1.772 * y1;
  33859. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33860. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33861. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33862. }
  33863. } else {
  33864. // inverse reversible multiple component transform
  33865. for (j = 0; j < jj; j++, pos += alpha01) {
  33866. y0 = y0items[j] + offset;
  33867. y1 = y1items[j];
  33868. y2 = y2items[j];
  33869. g = y0 - ((y2 + y1) >> 2);
  33870. r = g + y2;
  33871. b = g + y1;
  33872. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33873. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33874. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33875. }
  33876. }
  33877. if (fourComponents) {
  33878. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  33879. k = y3items[j];
  33880. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  33881. }
  33882. }
  33883. } else { // no multi-component transform
  33884. for (c = 0; c < componentsCount; c++) {
  33885. var items = transformedTiles[c].items;
  33886. shift = components[c].precision - 8;
  33887. offset = (128 << shift) + 0.5;
  33888. max = (127.5 * (1 << shift));
  33889. min = -max;
  33890. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  33891. val = items[j];
  33892. out[pos] = val <= min ? 0 :
  33893. val >= max ? 255 : (val + offset) >> shift;
  33894. pos += componentsCount;
  33895. }
  33896. }
  33897. }
  33898. resultImages.push(result);
  33899. }
  33900. return resultImages;
  33901. }
  33902. function initializeTile(context, tileIndex) {
  33903. var siz = context.SIZ;
  33904. var componentsCount = siz.Csiz;
  33905. var tile = context.tiles[tileIndex];
  33906. for (var c = 0; c < componentsCount; c++) {
  33907. var component = tile.components[c];
  33908. var qcdOrQcc = (c in context.currentTile.QCC ?
  33909. context.currentTile.QCC[c] : context.currentTile.QCD);
  33910. component.quantizationParameters = qcdOrQcc;
  33911. var codOrCoc = (c in context.currentTile.COC ?
  33912. context.currentTile.COC[c] : context.currentTile.COD);
  33913. component.codingStyleParameters = codOrCoc;
  33914. }
  33915. tile.codingStyleDefaultParameters = context.currentTile.COD;
  33916. }
  33917. // Section B.10.2 Tag trees
  33918. var TagTree = (function TagTreeClosure() {
  33919. function TagTree(width, height) {
  33920. var levelsLength = log2(Math.max(width, height)) + 1;
  33921. this.levels = [];
  33922. for (var i = 0; i < levelsLength; i++) {
  33923. var level = {
  33924. width: width,
  33925. height: height,
  33926. items: []
  33927. };
  33928. this.levels.push(level);
  33929. width = Math.ceil(width / 2);
  33930. height = Math.ceil(height / 2);
  33931. }
  33932. }
  33933. TagTree.prototype = {
  33934. reset: function TagTree_reset(i, j) {
  33935. var currentLevel = 0, value = 0, level;
  33936. while (currentLevel < this.levels.length) {
  33937. level = this.levels[currentLevel];
  33938. var index = i + j * level.width;
  33939. if (index in level.items) {
  33940. value = level.items[index];
  33941. break;
  33942. }
  33943. level.index = index;
  33944. i >>= 1;
  33945. j >>= 1;
  33946. currentLevel++;
  33947. }
  33948. currentLevel--;
  33949. level = this.levels[currentLevel];
  33950. level.items[level.index] = value;
  33951. this.currentLevel = currentLevel;
  33952. delete this.value;
  33953. },
  33954. incrementValue: function TagTree_incrementValue() {
  33955. var level = this.levels[this.currentLevel];
  33956. level.items[level.index]++;
  33957. },
  33958. nextLevel: function TagTree_nextLevel() {
  33959. var currentLevel = this.currentLevel;
  33960. var level = this.levels[currentLevel];
  33961. var value = level.items[level.index];
  33962. currentLevel--;
  33963. if (currentLevel < 0) {
  33964. this.value = value;
  33965. return false;
  33966. }
  33967. this.currentLevel = currentLevel;
  33968. level = this.levels[currentLevel];
  33969. level.items[level.index] = value;
  33970. return true;
  33971. }
  33972. };
  33973. return TagTree;
  33974. })();
  33975. var InclusionTree = (function InclusionTreeClosure() {
  33976. function InclusionTree(width, height, defaultValue) {
  33977. var levelsLength = log2(Math.max(width, height)) + 1;
  33978. this.levels = [];
  33979. for (var i = 0; i < levelsLength; i++) {
  33980. var items = new Uint8Array(width * height);
  33981. for (var j = 0, jj = items.length; j < jj; j++) {
  33982. items[j] = defaultValue;
  33983. }
  33984. var level = {
  33985. width: width,
  33986. height: height,
  33987. items: items
  33988. };
  33989. this.levels.push(level);
  33990. width = Math.ceil(width / 2);
  33991. height = Math.ceil(height / 2);
  33992. }
  33993. }
  33994. InclusionTree.prototype = {
  33995. reset: function InclusionTree_reset(i, j, stopValue) {
  33996. var currentLevel = 0;
  33997. while (currentLevel < this.levels.length) {
  33998. var level = this.levels[currentLevel];
  33999. var index = i + j * level.width;
  34000. level.index = index;
  34001. var value = level.items[index];
  34002. if (value === 0xFF) {
  34003. break;
  34004. }
  34005. if (value > stopValue) {
  34006. this.currentLevel = currentLevel;
  34007. // already know about this one, propagating the value to top levels
  34008. this.propagateValues();
  34009. return false;
  34010. }
  34011. i >>= 1;
  34012. j >>= 1;
  34013. currentLevel++;
  34014. }
  34015. this.currentLevel = currentLevel - 1;
  34016. return true;
  34017. },
  34018. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34019. var level = this.levels[this.currentLevel];
  34020. level.items[level.index] = stopValue + 1;
  34021. this.propagateValues();
  34022. },
  34023. propagateValues: function InclusionTree_propagateValues() {
  34024. var levelIndex = this.currentLevel;
  34025. var level = this.levels[levelIndex];
  34026. var currentValue = level.items[level.index];
  34027. while (--levelIndex >= 0) {
  34028. level = this.levels[levelIndex];
  34029. level.items[level.index] = currentValue;
  34030. }
  34031. },
  34032. nextLevel: function InclusionTree_nextLevel() {
  34033. var currentLevel = this.currentLevel;
  34034. var level = this.levels[currentLevel];
  34035. var value = level.items[level.index];
  34036. level.items[level.index] = 0xFF;
  34037. currentLevel--;
  34038. if (currentLevel < 0) {
  34039. return false;
  34040. }
  34041. this.currentLevel = currentLevel;
  34042. level = this.levels[currentLevel];
  34043. level.items[level.index] = value;
  34044. return true;
  34045. }
  34046. };
  34047. return InclusionTree;
  34048. })();
  34049. // Section D. Coefficient bit modeling
  34050. var BitModel = (function BitModelClosure() {
  34051. var UNIFORM_CONTEXT = 17;
  34052. var RUNLENGTH_CONTEXT = 18;
  34053. // Table D-1
  34054. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34055. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34056. var LLAndLHContextsLabel = new Uint8Array([
  34057. 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,
  34058. 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,
  34059. 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
  34060. ]);
  34061. var HLContextLabel = new Uint8Array([
  34062. 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,
  34063. 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,
  34064. 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
  34065. ]);
  34066. var HHContextLabel = new Uint8Array([
  34067. 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,
  34068. 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,
  34069. 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
  34070. ]);
  34071. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34072. this.width = width;
  34073. this.height = height;
  34074. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34075. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34076. var coefficientCount = width * height;
  34077. // coefficients outside the encoding region treated as insignificant
  34078. // add border state cells for significanceState
  34079. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34080. this.coefficentsSign = new Uint8Array(coefficientCount);
  34081. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34082. mb > 6 ? new Uint16Array(coefficientCount) :
  34083. new Uint8Array(coefficientCount);
  34084. this.processingFlags = new Uint8Array(coefficientCount);
  34085. var bitsDecoded = new Uint8Array(coefficientCount);
  34086. if (zeroBitPlanes !== 0) {
  34087. for (var i = 0; i < coefficientCount; i++) {
  34088. bitsDecoded[i] = zeroBitPlanes;
  34089. }
  34090. }
  34091. this.bitsDecoded = bitsDecoded;
  34092. this.reset();
  34093. }
  34094. BitModel.prototype = {
  34095. setDecoder: function BitModel_setDecoder(decoder) {
  34096. this.decoder = decoder;
  34097. },
  34098. reset: function BitModel_reset() {
  34099. // We have 17 contexts that are accessed via context labels,
  34100. // plus the uniform and runlength context.
  34101. this.contexts = new Int8Array(19);
  34102. // Contexts are packed into 1 byte:
  34103. // highest 7 bits carry the index, lowest bit carries mps
  34104. this.contexts[0] = (4 << 1) | 0;
  34105. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34106. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34107. },
  34108. setNeighborsSignificance:
  34109. function BitModel_setNeighborsSignificance(row, column, index) {
  34110. var neighborsSignificance = this.neighborsSignificance;
  34111. var width = this.width, height = this.height;
  34112. var left = (column > 0);
  34113. var right = (column + 1 < width);
  34114. var i;
  34115. if (row > 0) {
  34116. i = index - width;
  34117. if (left) {
  34118. neighborsSignificance[i - 1] += 0x10;
  34119. }
  34120. if (right) {
  34121. neighborsSignificance[i + 1] += 0x10;
  34122. }
  34123. neighborsSignificance[i] += 0x04;
  34124. }
  34125. if (row + 1 < height) {
  34126. i = index + width;
  34127. if (left) {
  34128. neighborsSignificance[i - 1] += 0x10;
  34129. }
  34130. if (right) {
  34131. neighborsSignificance[i + 1] += 0x10;
  34132. }
  34133. neighborsSignificance[i] += 0x04;
  34134. }
  34135. if (left) {
  34136. neighborsSignificance[index - 1] += 0x01;
  34137. }
  34138. if (right) {
  34139. neighborsSignificance[index + 1] += 0x01;
  34140. }
  34141. neighborsSignificance[index] |= 0x80;
  34142. },
  34143. runSignificancePropogationPass:
  34144. function BitModel_runSignificancePropogationPass() {
  34145. var decoder = this.decoder;
  34146. var width = this.width, height = this.height;
  34147. var coefficentsMagnitude = this.coefficentsMagnitude;
  34148. var coefficentsSign = this.coefficentsSign;
  34149. var neighborsSignificance = this.neighborsSignificance;
  34150. var processingFlags = this.processingFlags;
  34151. var contexts = this.contexts;
  34152. var labels = this.contextLabelTable;
  34153. var bitsDecoded = this.bitsDecoded;
  34154. var processedInverseMask = ~1;
  34155. var processedMask = 1;
  34156. var firstMagnitudeBitMask = 2;
  34157. for (var i0 = 0; i0 < height; i0 += 4) {
  34158. for (var j = 0; j < width; j++) {
  34159. var index = i0 * width + j;
  34160. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34161. var i = i0 + i1;
  34162. if (i >= height) {
  34163. break;
  34164. }
  34165. // clear processed flag first
  34166. processingFlags[index] &= processedInverseMask;
  34167. if (coefficentsMagnitude[index] ||
  34168. !neighborsSignificance[index]) {
  34169. continue;
  34170. }
  34171. var contextLabel = labels[neighborsSignificance[index]];
  34172. var decision = decoder.readBit(contexts, contextLabel);
  34173. if (decision) {
  34174. var sign = this.decodeSignBit(i, j, index);
  34175. coefficentsSign[index] = sign;
  34176. coefficentsMagnitude[index] = 1;
  34177. this.setNeighborsSignificance(i, j, index);
  34178. processingFlags[index] |= firstMagnitudeBitMask;
  34179. }
  34180. bitsDecoded[index]++;
  34181. processingFlags[index] |= processedMask;
  34182. }
  34183. }
  34184. }
  34185. },
  34186. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34187. var width = this.width, height = this.height;
  34188. var coefficentsMagnitude = this.coefficentsMagnitude;
  34189. var coefficentsSign = this.coefficentsSign;
  34190. var contribution, sign0, sign1, significance1;
  34191. var contextLabel, decoded;
  34192. // calculate horizontal contribution
  34193. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34194. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34195. sign1 = coefficentsSign[index + 1];
  34196. if (significance1) {
  34197. sign0 = coefficentsSign[index - 1];
  34198. contribution = 1 - sign1 - sign0;
  34199. } else {
  34200. contribution = 1 - sign1 - sign1;
  34201. }
  34202. } else if (significance1) {
  34203. sign0 = coefficentsSign[index - 1];
  34204. contribution = 1 - sign0 - sign0;
  34205. } else {
  34206. contribution = 0;
  34207. }
  34208. var horizontalContribution = 3 * contribution;
  34209. // calculate vertical contribution and combine with the horizontal
  34210. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34211. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34212. sign1 = coefficentsSign[index + width];
  34213. if (significance1) {
  34214. sign0 = coefficentsSign[index - width];
  34215. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34216. } else {
  34217. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34218. }
  34219. } else if (significance1) {
  34220. sign0 = coefficentsSign[index - width];
  34221. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34222. } else {
  34223. contribution = horizontalContribution;
  34224. }
  34225. if (contribution >= 0) {
  34226. contextLabel = 9 + contribution;
  34227. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34228. } else {
  34229. contextLabel = 9 - contribution;
  34230. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34231. }
  34232. return decoded;
  34233. },
  34234. runMagnitudeRefinementPass:
  34235. function BitModel_runMagnitudeRefinementPass() {
  34236. var decoder = this.decoder;
  34237. var width = this.width, height = this.height;
  34238. var coefficentsMagnitude = this.coefficentsMagnitude;
  34239. var neighborsSignificance = this.neighborsSignificance;
  34240. var contexts = this.contexts;
  34241. var bitsDecoded = this.bitsDecoded;
  34242. var processingFlags = this.processingFlags;
  34243. var processedMask = 1;
  34244. var firstMagnitudeBitMask = 2;
  34245. var length = width * height;
  34246. var width4 = width * 4;
  34247. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  34248. indexNext = Math.min(length, index0 + width4);
  34249. for (var j = 0; j < width; j++) {
  34250. for (var index = index0 + j; index < indexNext; index += width) {
  34251. // significant but not those that have just become
  34252. if (!coefficentsMagnitude[index] ||
  34253. (processingFlags[index] & processedMask) !== 0) {
  34254. continue;
  34255. }
  34256. var contextLabel = 16;
  34257. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  34258. processingFlags[index] ^= firstMagnitudeBitMask;
  34259. // first refinement
  34260. var significance = neighborsSignificance[index] & 127;
  34261. contextLabel = significance === 0 ? 15 : 14;
  34262. }
  34263. var bit = decoder.readBit(contexts, contextLabel);
  34264. coefficentsMagnitude[index] =
  34265. (coefficentsMagnitude[index] << 1) | bit;
  34266. bitsDecoded[index]++;
  34267. processingFlags[index] |= processedMask;
  34268. }
  34269. }
  34270. }
  34271. },
  34272. runCleanupPass: function BitModel_runCleanupPass() {
  34273. var decoder = this.decoder;
  34274. var width = this.width, height = this.height;
  34275. var neighborsSignificance = this.neighborsSignificance;
  34276. var coefficentsMagnitude = this.coefficentsMagnitude;
  34277. var coefficentsSign = this.coefficentsSign;
  34278. var contexts = this.contexts;
  34279. var labels = this.contextLabelTable;
  34280. var bitsDecoded = this.bitsDecoded;
  34281. var processingFlags = this.processingFlags;
  34282. var processedMask = 1;
  34283. var firstMagnitudeBitMask = 2;
  34284. var oneRowDown = width;
  34285. var twoRowsDown = width * 2;
  34286. var threeRowsDown = width * 3;
  34287. var iNext;
  34288. for (var i0 = 0; i0 < height; i0 = iNext) {
  34289. iNext = Math.min(i0 + 4, height);
  34290. var indexBase = i0 * width;
  34291. var checkAllEmpty = i0 + 3 < height;
  34292. for (var j = 0; j < width; j++) {
  34293. var index0 = indexBase + j;
  34294. // using the property: labels[neighborsSignificance[index]] === 0
  34295. // when neighborsSignificance[index] === 0
  34296. var allEmpty = (checkAllEmpty &&
  34297. processingFlags[index0] === 0 &&
  34298. processingFlags[index0 + oneRowDown] === 0 &&
  34299. processingFlags[index0 + twoRowsDown] === 0 &&
  34300. processingFlags[index0 + threeRowsDown] === 0 &&
  34301. neighborsSignificance[index0] === 0 &&
  34302. neighborsSignificance[index0 + oneRowDown] === 0 &&
  34303. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  34304. neighborsSignificance[index0 + threeRowsDown] === 0);
  34305. var i1 = 0, index = index0;
  34306. var i = i0, sign;
  34307. if (allEmpty) {
  34308. var hasSignificantCoefficent =
  34309. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  34310. if (!hasSignificantCoefficent) {
  34311. bitsDecoded[index0]++;
  34312. bitsDecoded[index0 + oneRowDown]++;
  34313. bitsDecoded[index0 + twoRowsDown]++;
  34314. bitsDecoded[index0 + threeRowsDown]++;
  34315. continue; // next column
  34316. }
  34317. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34318. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34319. if (i1 !== 0) {
  34320. i = i0 + i1;
  34321. index += i1 * width;
  34322. }
  34323. sign = this.decodeSignBit(i, j, index);
  34324. coefficentsSign[index] = sign;
  34325. coefficentsMagnitude[index] = 1;
  34326. this.setNeighborsSignificance(i, j, index);
  34327. processingFlags[index] |= firstMagnitudeBitMask;
  34328. index = index0;
  34329. for (var i2 = i0; i2 <= i; i2++, index += width) {
  34330. bitsDecoded[index]++;
  34331. }
  34332. i1++;
  34333. }
  34334. for (i = i0 + i1; i < iNext; i++, index += width) {
  34335. if (coefficentsMagnitude[index] ||
  34336. (processingFlags[index] & processedMask) !== 0) {
  34337. continue;
  34338. }
  34339. var contextLabel = labels[neighborsSignificance[index]];
  34340. var decision = decoder.readBit(contexts, contextLabel);
  34341. if (decision === 1) {
  34342. sign = this.decodeSignBit(i, j, index);
  34343. coefficentsSign[index] = sign;
  34344. coefficentsMagnitude[index] = 1;
  34345. this.setNeighborsSignificance(i, j, index);
  34346. processingFlags[index] |= firstMagnitudeBitMask;
  34347. }
  34348. bitsDecoded[index]++;
  34349. }
  34350. }
  34351. }
  34352. },
  34353. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  34354. var decoder = this.decoder;
  34355. var contexts = this.contexts;
  34356. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  34357. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  34358. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34359. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34360. if (symbol !== 0xA) {
  34361. throw new Error('JPX Error: Invalid segmentation symbol');
  34362. }
  34363. }
  34364. };
  34365. return BitModel;
  34366. })();
  34367. // Section F, Discrete wavelet transformation
  34368. var Transform = (function TransformClosure() {
  34369. function Transform() {}
  34370. Transform.prototype.calculate =
  34371. function transformCalculate(subbands, u0, v0) {
  34372. var ll = subbands[0];
  34373. for (var i = 1, ii = subbands.length; i < ii; i++) {
  34374. ll = this.iterate(ll, subbands[i], u0, v0);
  34375. }
  34376. return ll;
  34377. };
  34378. Transform.prototype.extend = function extend(buffer, offset, size) {
  34379. // Section F.3.7 extending... using max extension of 4
  34380. var i1 = offset - 1, j1 = offset + 1;
  34381. var i2 = offset + size - 2, j2 = offset + size;
  34382. buffer[i1--] = buffer[j1++];
  34383. buffer[j2++] = buffer[i2--];
  34384. buffer[i1--] = buffer[j1++];
  34385. buffer[j2++] = buffer[i2--];
  34386. buffer[i1--] = buffer[j1++];
  34387. buffer[j2++] = buffer[i2--];
  34388. buffer[i1] = buffer[j1];
  34389. buffer[j2] = buffer[i2];
  34390. };
  34391. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  34392. u0, v0) {
  34393. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  34394. var width = hl_lh_hh.width;
  34395. var height = hl_lh_hh.height;
  34396. var items = hl_lh_hh.items;
  34397. var i, j, k, l, u, v;
  34398. // Interleave LL according to Section F.3.3
  34399. for (k = 0, i = 0; i < llHeight; i++) {
  34400. l = i * 2 * width;
  34401. for (j = 0; j < llWidth; j++, k++, l += 2) {
  34402. items[l] = llItems[k];
  34403. }
  34404. }
  34405. // The LL band is not needed anymore.
  34406. llItems = ll.items = null;
  34407. var bufferPadding = 4;
  34408. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  34409. // Section F.3.4 HOR_SR
  34410. if (width === 1) {
  34411. // if width = 1, when u0 even keep items as is, when odd divide by 2
  34412. if ((u0 & 1) !== 0) {
  34413. for (v = 0, k = 0; v < height; v++, k += width) {
  34414. items[k] *= 0.5;
  34415. }
  34416. }
  34417. } else {
  34418. for (v = 0, k = 0; v < height; v++, k += width) {
  34419. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  34420. this.extend(rowBuffer, bufferPadding, width);
  34421. this.filter(rowBuffer, bufferPadding, width);
  34422. items.set(
  34423. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  34424. k);
  34425. }
  34426. }
  34427. // Accesses to the items array can take long, because it may not fit into
  34428. // CPU cache and has to be fetched from main memory. Since subsequent
  34429. // accesses to the items array are not local when reading columns, we
  34430. // have a cache miss every time. To reduce cache misses, get up to
  34431. // 'numBuffers' items at a time and store them into the individual
  34432. // buffers. The colBuffers should be small enough to fit into CPU cache.
  34433. var numBuffers = 16;
  34434. var colBuffers = [];
  34435. for (i = 0; i < numBuffers; i++) {
  34436. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  34437. }
  34438. var b, currentBuffer = 0;
  34439. ll = bufferPadding + height;
  34440. // Section F.3.5 VER_SR
  34441. if (height === 1) {
  34442. // if height = 1, when v0 even keep items as is, when odd divide by 2
  34443. if ((v0 & 1) !== 0) {
  34444. for (u = 0; u < width; u++) {
  34445. items[u] *= 0.5;
  34446. }
  34447. }
  34448. } else {
  34449. for (u = 0; u < width; u++) {
  34450. // if we ran out of buffers, copy several image columns at once
  34451. if (currentBuffer === 0) {
  34452. numBuffers = Math.min(width - u, numBuffers);
  34453. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  34454. for (b = 0; b < numBuffers; b++) {
  34455. colBuffers[b][l] = items[k + b];
  34456. }
  34457. }
  34458. currentBuffer = numBuffers;
  34459. }
  34460. currentBuffer--;
  34461. var buffer = colBuffers[currentBuffer];
  34462. this.extend(buffer, bufferPadding, height);
  34463. this.filter(buffer, bufferPadding, height);
  34464. // If this is last buffer in this group of buffers, flush all buffers.
  34465. if (currentBuffer === 0) {
  34466. k = u - numBuffers + 1;
  34467. for (l = bufferPadding; l < ll; k += width, l++) {
  34468. for (b = 0; b < numBuffers; b++) {
  34469. items[k + b] = colBuffers[b][l];
  34470. }
  34471. }
  34472. }
  34473. }
  34474. }
  34475. return {
  34476. width: width,
  34477. height: height,
  34478. items: items
  34479. };
  34480. };
  34481. return Transform;
  34482. })();
  34483. // Section 3.8.2 Irreversible 9-7 filter
  34484. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  34485. function IrreversibleTransform() {
  34486. Transform.call(this);
  34487. }
  34488. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  34489. IrreversibleTransform.prototype.filter =
  34490. function irreversibleTransformFilter(x, offset, length) {
  34491. var len = length >> 1;
  34492. offset = offset | 0;
  34493. var j, n, current, next;
  34494. var alpha = -1.586134342059924;
  34495. var beta = -0.052980118572961;
  34496. var gamma = 0.882911075530934;
  34497. var delta = 0.443506852043971;
  34498. var K = 1.230174104914001;
  34499. var K_ = 1 / K;
  34500. // step 1 is combined with step 3
  34501. // step 2
  34502. j = offset - 3;
  34503. for (n = len + 4; n--; j += 2) {
  34504. x[j] *= K_;
  34505. }
  34506. // step 1 & 3
  34507. j = offset - 2;
  34508. current = delta * x[j -1];
  34509. for (n = len + 3; n--; j += 2) {
  34510. next = delta * x[j + 1];
  34511. x[j] = K * x[j] - current - next;
  34512. if (n--) {
  34513. j += 2;
  34514. current = delta * x[j + 1];
  34515. x[j] = K * x[j] - current - next;
  34516. } else {
  34517. break;
  34518. }
  34519. }
  34520. // step 4
  34521. j = offset - 1;
  34522. current = gamma * x[j - 1];
  34523. for (n = len + 2; n--; j += 2) {
  34524. next = gamma * x[j + 1];
  34525. x[j] -= current + next;
  34526. if (n--) {
  34527. j += 2;
  34528. current = gamma * x[j + 1];
  34529. x[j] -= current + next;
  34530. } else {
  34531. break;
  34532. }
  34533. }
  34534. // step 5
  34535. j = offset;
  34536. current = beta * x[j - 1];
  34537. for (n = len + 1; n--; j += 2) {
  34538. next = beta * x[j + 1];
  34539. x[j] -= current + next;
  34540. if (n--) {
  34541. j += 2;
  34542. current = beta * x[j + 1];
  34543. x[j] -= current + next;
  34544. } else {
  34545. break;
  34546. }
  34547. }
  34548. // step 6
  34549. if (len !== 0) {
  34550. j = offset + 1;
  34551. current = alpha * x[j - 1];
  34552. for (n = len; n--; j += 2) {
  34553. next = alpha * x[j + 1];
  34554. x[j] -= current + next;
  34555. if (n--) {
  34556. j += 2;
  34557. current = alpha * x[j + 1];
  34558. x[j] -= current + next;
  34559. } else {
  34560. break;
  34561. }
  34562. }
  34563. }
  34564. };
  34565. return IrreversibleTransform;
  34566. })();
  34567. // Section 3.8.1 Reversible 5-3 filter
  34568. var ReversibleTransform = (function ReversibleTransformClosure() {
  34569. function ReversibleTransform() {
  34570. Transform.call(this);
  34571. }
  34572. ReversibleTransform.prototype = Object.create(Transform.prototype);
  34573. ReversibleTransform.prototype.filter =
  34574. function reversibleTransformFilter(x, offset, length) {
  34575. var len = length >> 1;
  34576. offset = offset | 0;
  34577. var j, n;
  34578. for (j = offset, n = len + 1; n--; j += 2) {
  34579. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  34580. }
  34581. for (j = offset + 1, n = len; n--; j += 2) {
  34582. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  34583. }
  34584. };
  34585. return ReversibleTransform;
  34586. })();
  34587. return JpxImage;
  34588. })();
  34589. var Jbig2Image = (function Jbig2ImageClosure() {
  34590. // Utility data structures
  34591. function ContextCache() {}
  34592. ContextCache.prototype = {
  34593. getContexts: function(id) {
  34594. if (id in this) {
  34595. return this[id];
  34596. }
  34597. return (this[id] = new Int8Array(1 << 16));
  34598. }
  34599. };
  34600. function DecodingContext(data, start, end) {
  34601. this.data = data;
  34602. this.start = start;
  34603. this.end = end;
  34604. }
  34605. DecodingContext.prototype = {
  34606. get decoder() {
  34607. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  34608. return shadow(this, 'decoder', decoder);
  34609. },
  34610. get contextCache() {
  34611. var cache = new ContextCache();
  34612. return shadow(this, 'contextCache', cache);
  34613. }
  34614. };
  34615. // Annex A. Arithmetic Integer Decoding Procedure
  34616. // A.2 Procedure for decoding values
  34617. function decodeInteger(contextCache, procedure, decoder) {
  34618. var contexts = contextCache.getContexts(procedure);
  34619. var prev = 1;
  34620. function readBits(length) {
  34621. var v = 0;
  34622. for (var i = 0; i < length; i++) {
  34623. var bit = decoder.readBit(contexts, prev);
  34624. prev = (prev < 256 ? (prev << 1) | bit :
  34625. (((prev << 1) | bit) & 511) | 256);
  34626. v = (v << 1) | bit;
  34627. }
  34628. return v >>> 0;
  34629. }
  34630. var sign = readBits(1);
  34631. var value = readBits(1) ?
  34632. (readBits(1) ?
  34633. (readBits(1) ?
  34634. (readBits(1) ?
  34635. (readBits(1) ?
  34636. (readBits(32) + 4436) :
  34637. readBits(12) + 340) :
  34638. readBits(8) + 84) :
  34639. readBits(6) + 20) :
  34640. readBits(4) + 4) :
  34641. readBits(2);
  34642. return (sign === 0 ? value : (value > 0 ? -value : null));
  34643. }
  34644. // A.3 The IAID decoding procedure
  34645. function decodeIAID(contextCache, decoder, codeLength) {
  34646. var contexts = contextCache.getContexts('IAID');
  34647. var prev = 1;
  34648. for (var i = 0; i < codeLength; i++) {
  34649. var bit = decoder.readBit(contexts, prev);
  34650. prev = (prev << 1) | bit;
  34651. }
  34652. if (codeLength < 31) {
  34653. return prev & ((1 << codeLength) - 1);
  34654. }
  34655. return prev & 0x7FFFFFFF;
  34656. }
  34657. // 7.3 Segment types
  34658. var SegmentTypes = [
  34659. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  34660. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  34661. null, null, null, null, null, 'patternDictionary', null, null, null,
  34662. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  34663. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  34664. null, null, null, null, null, 'IntermediateGenericRegion', null,
  34665. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  34666. 'IntermediateGenericRefinementRegion', null,
  34667. 'ImmediateGenericRefinementRegion',
  34668. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  34669. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  34670. 'Tables', null, null, null, null, null, null, null, null,
  34671. 'Extension'
  34672. ];
  34673. var CodingTemplates = [
  34674. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  34675. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  34676. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  34677. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  34678. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  34679. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  34680. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  34681. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  34682. {x: -1, y: 0}],
  34683. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  34684. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  34685. ];
  34686. var RefinementTemplates = [
  34687. {
  34688. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  34689. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  34690. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  34691. },
  34692. {
  34693. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  34694. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  34695. {x: 0, y: 1}, {x: 1, y: 1}]
  34696. }
  34697. ];
  34698. // See 6.2.5.7 Decoding the bitmap.
  34699. var ReusedContexts = [
  34700. 0x9B25, // 10011 0110010 0101
  34701. 0x0795, // 0011 110010 101
  34702. 0x00E5, // 001 11001 01
  34703. 0x0195 // 011001 0101
  34704. ];
  34705. var RefinementReusedContexts = [
  34706. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  34707. 0x0008 // '0000' + '001000'
  34708. ];
  34709. function decodeBitmapTemplate0(width, height, decodingContext) {
  34710. var decoder = decodingContext.decoder;
  34711. var contexts = decodingContext.contextCache.getContexts('GB');
  34712. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  34713. // ...ooooo....
  34714. // ..ooooooo... Context template for current pixel (X)
  34715. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  34716. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  34717. for (i = 0; i < height; i++) {
  34718. row = bitmap[i] = new Uint8Array(width);
  34719. row1 = (i < 1) ? row : bitmap[i - 1];
  34720. row2 = (i < 2) ? row : bitmap[i - 2];
  34721. // At the beginning of each row:
  34722. // Fill contextLabel with pixels that are above/right of (X)
  34723. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  34724. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  34725. (row1[3] << 4);
  34726. for (j = 0; j < width; j++) {
  34727. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  34728. // At each pixel: Clear contextLabel pixels that are shifted
  34729. // out of the context, then add new ones.
  34730. // If j + n is out of range at the right image border, then
  34731. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  34732. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  34733. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  34734. }
  34735. }
  34736. return bitmap;
  34737. }
  34738. // 6.2 Generic Region Decoding Procedure
  34739. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  34740. decodingContext) {
  34741. if (mmr) {
  34742. error('JBIG2 error: MMR encoding is not supported');
  34743. }
  34744. // Use optimized version for the most common case
  34745. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  34746. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  34747. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  34748. return decodeBitmapTemplate0(width, height, decodingContext);
  34749. }
  34750. var useskip = !!skip;
  34751. var template = CodingTemplates[templateIndex].concat(at);
  34752. // Sorting is non-standard, and it is not required. But sorting increases
  34753. // the number of template bits that can be reused from the previous
  34754. // contextLabel in the main loop.
  34755. template.sort(function (a, b) {
  34756. return (a.y - b.y) || (a.x - b.x);
  34757. });
  34758. var templateLength = template.length;
  34759. var templateX = new Int8Array(templateLength);
  34760. var templateY = new Int8Array(templateLength);
  34761. var changingTemplateEntries = [];
  34762. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  34763. var c, k;
  34764. for (k = 0; k < templateLength; k++) {
  34765. templateX[k] = template[k].x;
  34766. templateY[k] = template[k].y;
  34767. minX = Math.min(minX, template[k].x);
  34768. maxX = Math.max(maxX, template[k].x);
  34769. minY = Math.min(minY, template[k].y);
  34770. // Check if the template pixel appears in two consecutive context labels,
  34771. // so it can be reused. Otherwise, we add it to the list of changing
  34772. // template entries.
  34773. if (k < templateLength - 1 &&
  34774. template[k].y === template[k + 1].y &&
  34775. template[k].x === template[k + 1].x - 1) {
  34776. reuseMask |= 1 << (templateLength - 1 - k);
  34777. } else {
  34778. changingTemplateEntries.push(k);
  34779. }
  34780. }
  34781. var changingEntriesLength = changingTemplateEntries.length;
  34782. var changingTemplateX = new Int8Array(changingEntriesLength);
  34783. var changingTemplateY = new Int8Array(changingEntriesLength);
  34784. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  34785. for (c = 0; c < changingEntriesLength; c++) {
  34786. k = changingTemplateEntries[c];
  34787. changingTemplateX[c] = template[k].x;
  34788. changingTemplateY[c] = template[k].y;
  34789. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  34790. }
  34791. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  34792. var sbb_left = -minX;
  34793. var sbb_top = -minY;
  34794. var sbb_right = width - maxX;
  34795. var pseudoPixelContext = ReusedContexts[templateIndex];
  34796. var row = new Uint8Array(width);
  34797. var bitmap = [];
  34798. var decoder = decodingContext.decoder;
  34799. var contexts = decodingContext.contextCache.getContexts('GB');
  34800. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  34801. for (var i = 0; i < height; i++) {
  34802. if (prediction) {
  34803. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34804. ltp ^= sltp;
  34805. if (ltp) {
  34806. bitmap.push(row); // duplicate previous row
  34807. continue;
  34808. }
  34809. }
  34810. row = new Uint8Array(row);
  34811. bitmap.push(row);
  34812. for (j = 0; j < width; j++) {
  34813. if (useskip && skip[i][j]) {
  34814. row[j] = 0;
  34815. continue;
  34816. }
  34817. // Are we in the middle of a scanline, so we can reuse contextLabel
  34818. // bits?
  34819. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  34820. // If yes, we can just shift the bits that are reusable and only
  34821. // fetch the remaining ones.
  34822. contextLabel = (contextLabel << 1) & reuseMask;
  34823. for (k = 0; k < changingEntriesLength; k++) {
  34824. i0 = i + changingTemplateY[k];
  34825. j0 = j + changingTemplateX[k];
  34826. bit = bitmap[i0][j0];
  34827. if (bit) {
  34828. bit = changingTemplateBit[k];
  34829. contextLabel |= bit;
  34830. }
  34831. }
  34832. } else {
  34833. // compute the contextLabel from scratch
  34834. contextLabel = 0;
  34835. shift = templateLength - 1;
  34836. for (k = 0; k < templateLength; k++, shift--) {
  34837. j0 = j + templateX[k];
  34838. if (j0 >= 0 && j0 < width) {
  34839. i0 = i + templateY[k];
  34840. if (i0 >= 0) {
  34841. bit = bitmap[i0][j0];
  34842. if (bit) {
  34843. contextLabel |= bit << shift;
  34844. }
  34845. }
  34846. }
  34847. }
  34848. }
  34849. var pixel = decoder.readBit(contexts, contextLabel);
  34850. row[j] = pixel;
  34851. }
  34852. }
  34853. return bitmap;
  34854. }
  34855. // 6.3.2 Generic Refinement Region Decoding Procedure
  34856. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  34857. offsetX, offsetY, prediction, at,
  34858. decodingContext) {
  34859. var codingTemplate = RefinementTemplates[templateIndex].coding;
  34860. if (templateIndex === 0) {
  34861. codingTemplate = codingTemplate.concat([at[0]]);
  34862. }
  34863. var codingTemplateLength = codingTemplate.length;
  34864. var codingTemplateX = new Int32Array(codingTemplateLength);
  34865. var codingTemplateY = new Int32Array(codingTemplateLength);
  34866. var k;
  34867. for (k = 0; k < codingTemplateLength; k++) {
  34868. codingTemplateX[k] = codingTemplate[k].x;
  34869. codingTemplateY[k] = codingTemplate[k].y;
  34870. }
  34871. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  34872. if (templateIndex === 0) {
  34873. referenceTemplate = referenceTemplate.concat([at[1]]);
  34874. }
  34875. var referenceTemplateLength = referenceTemplate.length;
  34876. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  34877. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  34878. for (k = 0; k < referenceTemplateLength; k++) {
  34879. referenceTemplateX[k] = referenceTemplate[k].x;
  34880. referenceTemplateY[k] = referenceTemplate[k].y;
  34881. }
  34882. var referenceWidth = referenceBitmap[0].length;
  34883. var referenceHeight = referenceBitmap.length;
  34884. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  34885. var bitmap = [];
  34886. var decoder = decodingContext.decoder;
  34887. var contexts = decodingContext.contextCache.getContexts('GR');
  34888. var ltp = 0;
  34889. for (var i = 0; i < height; i++) {
  34890. if (prediction) {
  34891. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34892. ltp ^= sltp;
  34893. if (ltp) {
  34894. error('JBIG2 error: prediction is not supported');
  34895. }
  34896. }
  34897. var row = new Uint8Array(width);
  34898. bitmap.push(row);
  34899. for (var j = 0; j < width; j++) {
  34900. var i0, j0;
  34901. var contextLabel = 0;
  34902. for (k = 0; k < codingTemplateLength; k++) {
  34903. i0 = i + codingTemplateY[k];
  34904. j0 = j + codingTemplateX[k];
  34905. if (i0 < 0 || j0 < 0 || j0 >= width) {
  34906. contextLabel <<= 1; // out of bound pixel
  34907. } else {
  34908. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  34909. }
  34910. }
  34911. for (k = 0; k < referenceTemplateLength; k++) {
  34912. i0 = i + referenceTemplateY[k] + offsetY;
  34913. j0 = j + referenceTemplateX[k] + offsetX;
  34914. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  34915. j0 >= referenceWidth) {
  34916. contextLabel <<= 1; // out of bound pixel
  34917. } else {
  34918. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  34919. }
  34920. }
  34921. var pixel = decoder.readBit(contexts, contextLabel);
  34922. row[j] = pixel;
  34923. }
  34924. }
  34925. return bitmap;
  34926. }
  34927. // 6.5.5 Decoding the symbol dictionary
  34928. function decodeSymbolDictionary(huffman, refinement, symbols,
  34929. numberOfNewSymbols, numberOfExportedSymbols,
  34930. huffmanTables, templateIndex, at,
  34931. refinementTemplateIndex, refinementAt,
  34932. decodingContext) {
  34933. if (huffman) {
  34934. error('JBIG2 error: huffman is not supported');
  34935. }
  34936. var newSymbols = [];
  34937. var currentHeight = 0;
  34938. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  34939. var decoder = decodingContext.decoder;
  34940. var contextCache = decodingContext.contextCache;
  34941. while (newSymbols.length < numberOfNewSymbols) {
  34942. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  34943. currentHeight += deltaHeight;
  34944. var currentWidth = 0;
  34945. var totalWidth = 0;
  34946. while (true) {
  34947. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  34948. if (deltaWidth === null) {
  34949. break; // OOB
  34950. }
  34951. currentWidth += deltaWidth;
  34952. totalWidth += currentWidth;
  34953. var bitmap;
  34954. if (refinement) {
  34955. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  34956. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  34957. if (numberOfInstances > 1) {
  34958. bitmap = decodeTextRegion(huffman, refinement,
  34959. currentWidth, currentHeight, 0,
  34960. numberOfInstances, 1, //strip size
  34961. symbols.concat(newSymbols),
  34962. symbolCodeLength,
  34963. 0, //transposed
  34964. 0, //ds offset
  34965. 1, //top left 7.4.3.1.1
  34966. 0, //OR operator
  34967. huffmanTables,
  34968. refinementTemplateIndex, refinementAt,
  34969. decodingContext);
  34970. } else {
  34971. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34972. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34973. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34974. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  34975. newSymbols[symbolId - symbols.length]);
  34976. bitmap = decodeRefinement(currentWidth, currentHeight,
  34977. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  34978. decodingContext);
  34979. }
  34980. } else {
  34981. // 6.5.8.1 Direct-coded symbol bitmap
  34982. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  34983. templateIndex, false, null, at, decodingContext);
  34984. }
  34985. newSymbols.push(bitmap);
  34986. }
  34987. }
  34988. // 6.5.10 Exported symbols
  34989. var exportedSymbols = [];
  34990. var flags = [], currentFlag = false;
  34991. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  34992. while (flags.length < totalSymbolsLength) {
  34993. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  34994. while (runLength--) {
  34995. flags.push(currentFlag);
  34996. }
  34997. currentFlag = !currentFlag;
  34998. }
  34999. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35000. if (flags[i]) {
  35001. exportedSymbols.push(symbols[i]);
  35002. }
  35003. }
  35004. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35005. if (flags[i]) {
  35006. exportedSymbols.push(newSymbols[j]);
  35007. }
  35008. }
  35009. return exportedSymbols;
  35010. }
  35011. function decodeTextRegion(huffman, refinement, width, height,
  35012. defaultPixelValue, numberOfSymbolInstances,
  35013. stripSize, inputSymbols, symbolCodeLength,
  35014. transposed, dsOffset, referenceCorner,
  35015. combinationOperator, huffmanTables,
  35016. refinementTemplateIndex, refinementAt,
  35017. decodingContext) {
  35018. if (huffman) {
  35019. error('JBIG2 error: huffman is not supported');
  35020. }
  35021. // Prepare bitmap
  35022. var bitmap = [];
  35023. var i, row;
  35024. for (i = 0; i < height; i++) {
  35025. row = new Uint8Array(width);
  35026. if (defaultPixelValue) {
  35027. for (var j = 0; j < width; j++) {
  35028. row[j] = defaultPixelValue;
  35029. }
  35030. }
  35031. bitmap.push(row);
  35032. }
  35033. var decoder = decodingContext.decoder;
  35034. var contextCache = decodingContext.contextCache;
  35035. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35036. var firstS = 0;
  35037. i = 0;
  35038. while (i < numberOfSymbolInstances) {
  35039. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35040. stripT += deltaT;
  35041. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35042. firstS += deltaFirstS;
  35043. var currentS = firstS;
  35044. do {
  35045. var currentT = (stripSize === 1 ? 0 :
  35046. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35047. var t = stripSize * stripT + currentT;
  35048. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35049. var applyRefinement = (refinement &&
  35050. decodeInteger(contextCache, 'IARI', decoder));
  35051. var symbolBitmap = inputSymbols[symbolId];
  35052. var symbolWidth = symbolBitmap[0].length;
  35053. var symbolHeight = symbolBitmap.length;
  35054. if (applyRefinement) {
  35055. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35056. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35057. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35058. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35059. symbolWidth += rdw;
  35060. symbolHeight += rdh;
  35061. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35062. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35063. (rdh >> 1) + rdy, false, refinementAt,
  35064. decodingContext);
  35065. }
  35066. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35067. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35068. var s2, t2, symbolRow;
  35069. if (transposed) {
  35070. // Place Symbol Bitmap from T1,S1
  35071. for (s2 = 0; s2 < symbolHeight; s2++) {
  35072. row = bitmap[offsetS + s2];
  35073. if (!row) {
  35074. continue;
  35075. }
  35076. symbolRow = symbolBitmap[s2];
  35077. // To ignore Parts of Symbol bitmap which goes
  35078. // outside bitmap region
  35079. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35080. switch (combinationOperator) {
  35081. case 0: // OR
  35082. for (t2 = 0; t2 < maxWidth; t2++) {
  35083. row[offsetT + t2] |= symbolRow[t2];
  35084. }
  35085. break;
  35086. case 2: // XOR
  35087. for (t2 = 0; t2 < maxWidth; t2++) {
  35088. row[offsetT + t2] ^= symbolRow[t2];
  35089. }
  35090. break;
  35091. default:
  35092. error('JBIG2 error: operator ' + combinationOperator +
  35093. ' is not supported');
  35094. }
  35095. }
  35096. currentS += symbolHeight - 1;
  35097. } else {
  35098. for (t2 = 0; t2 < symbolHeight; t2++) {
  35099. row = bitmap[offsetT + t2];
  35100. if (!row) {
  35101. continue;
  35102. }
  35103. symbolRow = symbolBitmap[t2];
  35104. switch (combinationOperator) {
  35105. case 0: // OR
  35106. for (s2 = 0; s2 < symbolWidth; s2++) {
  35107. row[offsetS + s2] |= symbolRow[s2];
  35108. }
  35109. break;
  35110. case 2: // XOR
  35111. for (s2 = 0; s2 < symbolWidth; s2++) {
  35112. row[offsetS + s2] ^= symbolRow[s2];
  35113. }
  35114. break;
  35115. default:
  35116. error('JBIG2 error: operator ' + combinationOperator +
  35117. ' is not supported');
  35118. }
  35119. }
  35120. currentS += symbolWidth - 1;
  35121. }
  35122. i++;
  35123. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35124. if (deltaS === null) {
  35125. break; // OOB
  35126. }
  35127. currentS += deltaS + dsOffset;
  35128. } while (true);
  35129. }
  35130. return bitmap;
  35131. }
  35132. function readSegmentHeader(data, start) {
  35133. var segmentHeader = {};
  35134. segmentHeader.number = readUint32(data, start);
  35135. var flags = data[start + 4];
  35136. var segmentType = flags & 0x3F;
  35137. if (!SegmentTypes[segmentType]) {
  35138. error('JBIG2 error: invalid segment type: ' + segmentType);
  35139. }
  35140. segmentHeader.type = segmentType;
  35141. segmentHeader.typeName = SegmentTypes[segmentType];
  35142. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35143. var pageAssociationFieldSize = !!(flags & 0x40);
  35144. var referredFlags = data[start + 5];
  35145. var referredToCount = (referredFlags >> 5) & 7;
  35146. var retainBits = [referredFlags & 31];
  35147. var position = start + 6;
  35148. if (referredFlags === 7) {
  35149. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35150. position += 3;
  35151. var bytes = (referredToCount + 7) >> 3;
  35152. retainBits[0] = data[position++];
  35153. while (--bytes > 0) {
  35154. retainBits.push(data[position++]);
  35155. }
  35156. } else if (referredFlags === 5 || referredFlags === 6) {
  35157. error('JBIG2 error: invalid referred-to flags');
  35158. }
  35159. segmentHeader.retainBits = retainBits;
  35160. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35161. (segmentHeader.number <= 65536 ? 2 : 4));
  35162. var referredTo = [];
  35163. var i, ii;
  35164. for (i = 0; i < referredToCount; i++) {
  35165. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35166. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35167. readUint32(data, position)));
  35168. referredTo.push(number);
  35169. position += referredToSegmentNumberSize;
  35170. }
  35171. segmentHeader.referredTo = referredTo;
  35172. if (!pageAssociationFieldSize) {
  35173. segmentHeader.pageAssociation = data[position++];
  35174. } else {
  35175. segmentHeader.pageAssociation = readUint32(data, position);
  35176. position += 4;
  35177. }
  35178. segmentHeader.length = readUint32(data, position);
  35179. position += 4;
  35180. if (segmentHeader.length === 0xFFFFFFFF) {
  35181. // 7.2.7 Segment data length, unknown segment length
  35182. if (segmentType === 38) { // ImmediateGenericRegion
  35183. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35184. var genericRegionSegmentFlags = data[position +
  35185. RegionSegmentInformationFieldLength];
  35186. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35187. // searching for the segment end
  35188. var searchPatternLength = 6;
  35189. var searchPattern = new Uint8Array(searchPatternLength);
  35190. if (!genericRegionMmr) {
  35191. searchPattern[0] = 0xFF;
  35192. searchPattern[1] = 0xAC;
  35193. }
  35194. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35195. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35196. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35197. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35198. for (i = position, ii = data.length; i < ii; i++) {
  35199. var j = 0;
  35200. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35201. j++;
  35202. }
  35203. if (j === searchPatternLength) {
  35204. segmentHeader.length = i + searchPatternLength;
  35205. break;
  35206. }
  35207. }
  35208. if (segmentHeader.length === 0xFFFFFFFF) {
  35209. error('JBIG2 error: segment end was not found');
  35210. }
  35211. } else {
  35212. error('JBIG2 error: invalid unknown segment length');
  35213. }
  35214. }
  35215. segmentHeader.headerEnd = position;
  35216. return segmentHeader;
  35217. }
  35218. function readSegments(header, data, start, end) {
  35219. var segments = [];
  35220. var position = start;
  35221. while (position < end) {
  35222. var segmentHeader = readSegmentHeader(data, position);
  35223. position = segmentHeader.headerEnd;
  35224. var segment = {
  35225. header: segmentHeader,
  35226. data: data
  35227. };
  35228. if (!header.randomAccess) {
  35229. segment.start = position;
  35230. position += segmentHeader.length;
  35231. segment.end = position;
  35232. }
  35233. segments.push(segment);
  35234. if (segmentHeader.type === 51) {
  35235. break; // end of file is found
  35236. }
  35237. }
  35238. if (header.randomAccess) {
  35239. for (var i = 0, ii = segments.length; i < ii; i++) {
  35240. segments[i].start = position;
  35241. position += segments[i].header.length;
  35242. segments[i].end = position;
  35243. }
  35244. }
  35245. return segments;
  35246. }
  35247. // 7.4.1 Region segment information field
  35248. function readRegionSegmentInformation(data, start) {
  35249. return {
  35250. width: readUint32(data, start),
  35251. height: readUint32(data, start + 4),
  35252. x: readUint32(data, start + 8),
  35253. y: readUint32(data, start + 12),
  35254. combinationOperator: data[start + 16] & 7
  35255. };
  35256. }
  35257. var RegionSegmentInformationFieldLength = 17;
  35258. function processSegment(segment, visitor) {
  35259. var header = segment.header;
  35260. var data = segment.data, position = segment.start, end = segment.end;
  35261. var args, at, i, atLength;
  35262. switch (header.type) {
  35263. case 0: // SymbolDictionary
  35264. // 7.4.2 Symbol dictionary segment syntax
  35265. var dictionary = {};
  35266. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  35267. dictionary.huffman = !!(dictionaryFlags & 1);
  35268. dictionary.refinement = !!(dictionaryFlags & 2);
  35269. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  35270. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  35271. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  35272. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  35273. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  35274. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  35275. dictionary.template = (dictionaryFlags >> 10) & 3;
  35276. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  35277. position += 2;
  35278. if (!dictionary.huffman) {
  35279. atLength = dictionary.template === 0 ? 4 : 1;
  35280. at = [];
  35281. for (i = 0; i < atLength; i++) {
  35282. at.push({
  35283. x: readInt8(data, position),
  35284. y: readInt8(data, position + 1)
  35285. });
  35286. position += 2;
  35287. }
  35288. dictionary.at = at;
  35289. }
  35290. if (dictionary.refinement && !dictionary.refinementTemplate) {
  35291. at = [];
  35292. for (i = 0; i < 2; i++) {
  35293. at.push({
  35294. x: readInt8(data, position),
  35295. y: readInt8(data, position + 1)
  35296. });
  35297. position += 2;
  35298. }
  35299. dictionary.refinementAt = at;
  35300. }
  35301. dictionary.numberOfExportedSymbols = readUint32(data, position);
  35302. position += 4;
  35303. dictionary.numberOfNewSymbols = readUint32(data, position);
  35304. position += 4;
  35305. args = [dictionary, header.number, header.referredTo,
  35306. data, position, end];
  35307. break;
  35308. case 6: // ImmediateTextRegion
  35309. case 7: // ImmediateLosslessTextRegion
  35310. var textRegion = {};
  35311. textRegion.info = readRegionSegmentInformation(data, position);
  35312. position += RegionSegmentInformationFieldLength;
  35313. var textRegionSegmentFlags = readUint16(data, position);
  35314. position += 2;
  35315. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  35316. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  35317. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  35318. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  35319. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  35320. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  35321. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  35322. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  35323. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  35324. if (textRegion.huffman) {
  35325. var textRegionHuffmanFlags = readUint16(data, position);
  35326. position += 2;
  35327. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  35328. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  35329. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  35330. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  35331. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  35332. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  35333. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  35334. textRegion.huffmanRefinementSizeSelector =
  35335. !!(textRegionHuffmanFlags & 14);
  35336. }
  35337. if (textRegion.refinement && !textRegion.refinementTemplate) {
  35338. at = [];
  35339. for (i = 0; i < 2; i++) {
  35340. at.push({
  35341. x: readInt8(data, position),
  35342. y: readInt8(data, position + 1)
  35343. });
  35344. position += 2;
  35345. }
  35346. textRegion.refinementAt = at;
  35347. }
  35348. textRegion.numberOfSymbolInstances = readUint32(data, position);
  35349. position += 4;
  35350. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  35351. if (textRegion.huffman) {
  35352. error('JBIG2 error: huffman is not supported');
  35353. }
  35354. args = [textRegion, header.referredTo, data, position, end];
  35355. break;
  35356. case 38: // ImmediateGenericRegion
  35357. case 39: // ImmediateLosslessGenericRegion
  35358. var genericRegion = {};
  35359. genericRegion.info = readRegionSegmentInformation(data, position);
  35360. position += RegionSegmentInformationFieldLength;
  35361. var genericRegionSegmentFlags = data[position++];
  35362. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  35363. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  35364. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  35365. if (!genericRegion.mmr) {
  35366. atLength = genericRegion.template === 0 ? 4 : 1;
  35367. at = [];
  35368. for (i = 0; i < atLength; i++) {
  35369. at.push({
  35370. x: readInt8(data, position),
  35371. y: readInt8(data, position + 1)
  35372. });
  35373. position += 2;
  35374. }
  35375. genericRegion.at = at;
  35376. }
  35377. args = [genericRegion, data, position, end];
  35378. break;
  35379. case 48: // PageInformation
  35380. var pageInfo = {
  35381. width: readUint32(data, position),
  35382. height: readUint32(data, position + 4),
  35383. resolutionX: readUint32(data, position + 8),
  35384. resolutionY: readUint32(data, position + 12)
  35385. };
  35386. if (pageInfo.height === 0xFFFFFFFF) {
  35387. delete pageInfo.height;
  35388. }
  35389. var pageSegmentFlags = data[position + 16];
  35390. var pageStripingInformatiom = readUint16(data, position + 17);
  35391. pageInfo.lossless = !!(pageSegmentFlags & 1);
  35392. pageInfo.refinement = !!(pageSegmentFlags & 2);
  35393. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  35394. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  35395. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  35396. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  35397. args = [pageInfo];
  35398. break;
  35399. case 49: // EndOfPage
  35400. break;
  35401. case 50: // EndOfStripe
  35402. break;
  35403. case 51: // EndOfFile
  35404. break;
  35405. case 62: // 7.4.15 defines 2 extension types which
  35406. // are comments and can be ignored.
  35407. break;
  35408. default:
  35409. error('JBIG2 error: segment type ' + header.typeName + '(' +
  35410. header.type + ') is not implemented');
  35411. }
  35412. var callbackName = 'on' + header.typeName;
  35413. if (callbackName in visitor) {
  35414. visitor[callbackName].apply(visitor, args);
  35415. }
  35416. }
  35417. function processSegments(segments, visitor) {
  35418. for (var i = 0, ii = segments.length; i < ii; i++) {
  35419. processSegment(segments[i], visitor);
  35420. }
  35421. }
  35422. function parseJbig2(data, start, end) {
  35423. var position = start;
  35424. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  35425. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  35426. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  35427. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  35428. error('JBIG2 error: invalid header');
  35429. }
  35430. var header = {};
  35431. position += 8;
  35432. var flags = data[position++];
  35433. header.randomAccess = !(flags & 1);
  35434. if (!(flags & 2)) {
  35435. header.numberOfPages = readUint32(data, position);
  35436. position += 4;
  35437. }
  35438. var segments = readSegments(header, data, position, end);
  35439. error('Not implemented');
  35440. // processSegments(segments, new SimpleSegmentVisitor());
  35441. }
  35442. function parseJbig2Chunks(chunks) {
  35443. var visitor = new SimpleSegmentVisitor();
  35444. for (var i = 0, ii = chunks.length; i < ii; i++) {
  35445. var chunk = chunks[i];
  35446. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  35447. processSegments(segments, visitor);
  35448. }
  35449. return visitor.buffer;
  35450. }
  35451. function SimpleSegmentVisitor() {}
  35452. SimpleSegmentVisitor.prototype = {
  35453. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  35454. this.currentPageInfo = info;
  35455. var rowSize = (info.width + 7) >> 3;
  35456. var buffer = new Uint8Array(rowSize * info.height);
  35457. // The contents of ArrayBuffers are initialized to 0.
  35458. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  35459. if (info.defaultPixelValue) {
  35460. for (var i = 0, ii = buffer.length; i < ii; i++) {
  35461. buffer[i] = 0xFF;
  35462. }
  35463. }
  35464. this.buffer = buffer;
  35465. },
  35466. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  35467. var pageInfo = this.currentPageInfo;
  35468. var width = regionInfo.width, height = regionInfo.height;
  35469. var rowSize = (pageInfo.width + 7) >> 3;
  35470. var combinationOperator = pageInfo.combinationOperatorOverride ?
  35471. regionInfo.combinationOperator : pageInfo.combinationOperator;
  35472. var buffer = this.buffer;
  35473. var mask0 = 128 >> (regionInfo.x & 7);
  35474. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  35475. var i, j, mask, offset;
  35476. switch (combinationOperator) {
  35477. case 0: // OR
  35478. for (i = 0; i < height; i++) {
  35479. mask = mask0;
  35480. offset = offset0;
  35481. for (j = 0; j < width; j++) {
  35482. if (bitmap[i][j]) {
  35483. buffer[offset] |= mask;
  35484. }
  35485. mask >>= 1;
  35486. if (!mask) {
  35487. mask = 128;
  35488. offset++;
  35489. }
  35490. }
  35491. offset0 += rowSize;
  35492. }
  35493. break;
  35494. case 2: // XOR
  35495. for (i = 0; i < height; i++) {
  35496. mask = mask0;
  35497. offset = offset0;
  35498. for (j = 0; j < width; j++) {
  35499. if (bitmap[i][j]) {
  35500. buffer[offset] ^= mask;
  35501. }
  35502. mask >>= 1;
  35503. if (!mask) {
  35504. mask = 128;
  35505. offset++;
  35506. }
  35507. }
  35508. offset0 += rowSize;
  35509. }
  35510. break;
  35511. default:
  35512. error('JBIG2 error: operator ' + combinationOperator +
  35513. ' is not supported');
  35514. }
  35515. },
  35516. onImmediateGenericRegion:
  35517. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  35518. start, end) {
  35519. var regionInfo = region.info;
  35520. var decodingContext = new DecodingContext(data, start, end);
  35521. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  35522. region.template, region.prediction, null,
  35523. region.at, decodingContext);
  35524. this.drawBitmap(regionInfo, bitmap);
  35525. },
  35526. onImmediateLosslessGenericRegion:
  35527. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  35528. this.onImmediateGenericRegion.apply(this, arguments);
  35529. },
  35530. onSymbolDictionary:
  35531. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  35532. currentSegment,
  35533. referredSegments,
  35534. data, start, end) {
  35535. var huffmanTables;
  35536. if (dictionary.huffman) {
  35537. error('JBIG2 error: huffman is not supported');
  35538. }
  35539. // Combines exported symbols from all referred segments
  35540. var symbols = this.symbols;
  35541. if (!symbols) {
  35542. this.symbols = symbols = {};
  35543. }
  35544. var inputSymbols = [];
  35545. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  35546. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  35547. }
  35548. var decodingContext = new DecodingContext(data, start, end);
  35549. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  35550. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  35551. dictionary.numberOfExportedSymbols, huffmanTables,
  35552. dictionary.template, dictionary.at,
  35553. dictionary.refinementTemplate, dictionary.refinementAt,
  35554. decodingContext);
  35555. },
  35556. onImmediateTextRegion:
  35557. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  35558. referredSegments,
  35559. data, start, end) {
  35560. var regionInfo = region.info;
  35561. var huffmanTables;
  35562. // Combines exported symbols from all referred segments
  35563. var symbols = this.symbols;
  35564. var inputSymbols = [];
  35565. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  35566. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  35567. }
  35568. var symbolCodeLength = log2(inputSymbols.length);
  35569. var decodingContext = new DecodingContext(data, start, end);
  35570. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  35571. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  35572. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  35573. symbolCodeLength, region.transposed, region.dsOffset,
  35574. region.referenceCorner, region.combinationOperator, huffmanTables,
  35575. region.refinementTemplate, region.refinementAt, decodingContext);
  35576. this.drawBitmap(regionInfo, bitmap);
  35577. },
  35578. onImmediateLosslessTextRegion:
  35579. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  35580. this.onImmediateTextRegion.apply(this, arguments);
  35581. }
  35582. };
  35583. function Jbig2Image() {}
  35584. Jbig2Image.prototype = {
  35585. parseChunks: function Jbig2Image_parseChunks(chunks) {
  35586. return parseJbig2Chunks(chunks);
  35587. }
  35588. };
  35589. return Jbig2Image;
  35590. })();
  35591. var bidi = PDFJS.bidi = (function bidiClosure() {
  35592. // Character types for symbols from 0000 to 00FF.
  35593. var baseTypes = [
  35594. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  35595. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35596. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  35597. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  35598. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  35599. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35600. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  35601. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35602. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35603. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  35604. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35605. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35606. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  35607. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  35608. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35609. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35610. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35611. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35612. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  35613. ];
  35614. // Character types for symbols from 0600 to 06FF
  35615. var arabicTypes = [
  35616. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35617. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  35618. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35619. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35620. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35621. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35622. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  35623. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  35624. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  35625. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  35626. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35627. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35628. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35629. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35630. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35631. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35632. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35633. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35634. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  35635. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  35636. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35637. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  35638. ];
  35639. function isOdd(i) {
  35640. return (i & 1) !== 0;
  35641. }
  35642. function isEven(i) {
  35643. return (i & 1) === 0;
  35644. }
  35645. function findUnequal(arr, start, value) {
  35646. for (var j = start, jj = arr.length; j < jj; ++j) {
  35647. if (arr[j] !== value) {
  35648. return j;
  35649. }
  35650. }
  35651. return j;
  35652. }
  35653. function setValues(arr, start, end, value) {
  35654. for (var j = start; j < end; ++j) {
  35655. arr[j] = value;
  35656. }
  35657. }
  35658. function reverseValues(arr, start, end) {
  35659. for (var i = start, j = end - 1; i < j; ++i, --j) {
  35660. var temp = arr[i];
  35661. arr[i] = arr[j];
  35662. arr[j] = temp;
  35663. }
  35664. }
  35665. function createBidiText(str, isLTR, vertical) {
  35666. return {
  35667. str: str,
  35668. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  35669. };
  35670. }
  35671. // These are used in bidi(), which is called frequently. We re-use them on
  35672. // each call to avoid unnecessary allocations.
  35673. var chars = [];
  35674. var types = [];
  35675. function bidi(str, startLevel, vertical) {
  35676. var isLTR = true;
  35677. var strLength = str.length;
  35678. if (strLength === 0 || vertical) {
  35679. return createBidiText(str, isLTR, vertical);
  35680. }
  35681. // Get types and fill arrays
  35682. chars.length = strLength;
  35683. types.length = strLength;
  35684. var numBidi = 0;
  35685. var i, ii;
  35686. for (i = 0; i < strLength; ++i) {
  35687. chars[i] = str.charAt(i);
  35688. var charCode = str.charCodeAt(i);
  35689. var charType = 'L';
  35690. if (charCode <= 0x00ff) {
  35691. charType = baseTypes[charCode];
  35692. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  35693. charType = 'R';
  35694. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  35695. charType = arabicTypes[charCode & 0xff];
  35696. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  35697. charType = 'AL';
  35698. }
  35699. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  35700. numBidi++;
  35701. }
  35702. types[i] = charType;
  35703. }
  35704. // Detect the bidi method
  35705. // - If there are no rtl characters then no bidi needed
  35706. // - If less than 30% chars are rtl then string is primarily ltr
  35707. // - If more than 30% chars are rtl then string is primarily rtl
  35708. if (numBidi === 0) {
  35709. isLTR = true;
  35710. return createBidiText(str, isLTR);
  35711. }
  35712. if (startLevel === -1) {
  35713. if ((strLength / numBidi) < 0.3) {
  35714. isLTR = true;
  35715. startLevel = 0;
  35716. } else {
  35717. isLTR = false;
  35718. startLevel = 1;
  35719. }
  35720. }
  35721. var levels = [];
  35722. for (i = 0; i < strLength; ++i) {
  35723. levels[i] = startLevel;
  35724. }
  35725. /*
  35726. X1-X10: skip most of this, since we are NOT doing the embeddings.
  35727. */
  35728. var e = (isOdd(startLevel) ? 'R' : 'L');
  35729. var sor = e;
  35730. var eor = sor;
  35731. /*
  35732. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  35733. type of the NSM to the type of the previous character. If the NSM is at the
  35734. start of the level run, it will get the type of sor.
  35735. */
  35736. var lastType = sor;
  35737. for (i = 0; i < strLength; ++i) {
  35738. if (types[i] === 'NSM') {
  35739. types[i] = lastType;
  35740. } else {
  35741. lastType = types[i];
  35742. }
  35743. }
  35744. /*
  35745. W2. Search backwards from each instance of a European number until the
  35746. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  35747. the type of the European number to Arabic number.
  35748. */
  35749. lastType = sor;
  35750. var t;
  35751. for (i = 0; i < strLength; ++i) {
  35752. t = types[i];
  35753. if (t === 'EN') {
  35754. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  35755. } else if (t === 'R' || t === 'L' || t === 'AL') {
  35756. lastType = t;
  35757. }
  35758. }
  35759. /*
  35760. W3. Change all ALs to R.
  35761. */
  35762. for (i = 0; i < strLength; ++i) {
  35763. t = types[i];
  35764. if (t === 'AL') {
  35765. types[i] = 'R';
  35766. }
  35767. }
  35768. /*
  35769. W4. A single European separator between two European numbers changes to a
  35770. European number. A single common separator between two numbers of the same
  35771. type changes to that type:
  35772. */
  35773. for (i = 1; i < strLength - 1; ++i) {
  35774. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  35775. types[i] = 'EN';
  35776. }
  35777. if (types[i] === 'CS' &&
  35778. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  35779. types[i + 1] === types[i - 1]) {
  35780. types[i] = types[i - 1];
  35781. }
  35782. }
  35783. /*
  35784. W5. A sequence of European terminators adjacent to European numbers changes
  35785. to all European numbers:
  35786. */
  35787. for (i = 0; i < strLength; ++i) {
  35788. if (types[i] === 'EN') {
  35789. // do before
  35790. var j;
  35791. for (j = i - 1; j >= 0; --j) {
  35792. if (types[j] !== 'ET') {
  35793. break;
  35794. }
  35795. types[j] = 'EN';
  35796. }
  35797. // do after
  35798. for (j = i + 1; j < strLength; --j) {
  35799. if (types[j] !== 'ET') {
  35800. break;
  35801. }
  35802. types[j] = 'EN';
  35803. }
  35804. }
  35805. }
  35806. /*
  35807. W6. Otherwise, separators and terminators change to Other Neutral:
  35808. */
  35809. for (i = 0; i < strLength; ++i) {
  35810. t = types[i];
  35811. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  35812. types[i] = 'ON';
  35813. }
  35814. }
  35815. /*
  35816. W7. Search backwards from each instance of a European number until the
  35817. first strong type (R, L, or sor) is found. If an L is found, then change
  35818. the type of the European number to L.
  35819. */
  35820. lastType = sor;
  35821. for (i = 0; i < strLength; ++i) {
  35822. t = types[i];
  35823. if (t === 'EN') {
  35824. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  35825. } else if (t === 'R' || t === 'L') {
  35826. lastType = t;
  35827. }
  35828. }
  35829. /*
  35830. N1. A sequence of neutrals takes the direction of the surrounding strong
  35831. text if the text on both sides has the same direction. European and Arabic
  35832. numbers are treated as though they were R. Start-of-level-run (sor) and
  35833. end-of-level-run (eor) are used at level run boundaries.
  35834. */
  35835. for (i = 0; i < strLength; ++i) {
  35836. if (types[i] === 'ON') {
  35837. var end = findUnequal(types, i + 1, 'ON');
  35838. var before = sor;
  35839. if (i > 0) {
  35840. before = types[i - 1];
  35841. }
  35842. var after = eor;
  35843. if (end + 1 < strLength) {
  35844. after = types[end + 1];
  35845. }
  35846. if (before !== 'L') {
  35847. before = 'R';
  35848. }
  35849. if (after !== 'L') {
  35850. after = 'R';
  35851. }
  35852. if (before === after) {
  35853. setValues(types, i, end, before);
  35854. }
  35855. i = end - 1; // reset to end (-1 so next iteration is ok)
  35856. }
  35857. }
  35858. /*
  35859. N2. Any remaining neutrals take the embedding direction.
  35860. */
  35861. for (i = 0; i < strLength; ++i) {
  35862. if (types[i] === 'ON') {
  35863. types[i] = e;
  35864. }
  35865. }
  35866. /*
  35867. I1. For all characters with an even (left-to-right) embedding direction,
  35868. those of type R go up one level and those of type AN or EN go up two
  35869. levels.
  35870. I2. For all characters with an odd (right-to-left) embedding direction,
  35871. those of type L, EN or AN go up one level.
  35872. */
  35873. for (i = 0; i < strLength; ++i) {
  35874. t = types[i];
  35875. if (isEven(levels[i])) {
  35876. if (t === 'R') {
  35877. levels[i] += 1;
  35878. } else if (t === 'AN' || t === 'EN') {
  35879. levels[i] += 2;
  35880. }
  35881. } else { // isOdd
  35882. if (t === 'L' || t === 'AN' || t === 'EN') {
  35883. levels[i] += 1;
  35884. }
  35885. }
  35886. }
  35887. /*
  35888. L1. On each line, reset the embedding level of the following characters to
  35889. the paragraph embedding level:
  35890. segment separators,
  35891. paragraph separators,
  35892. any sequence of whitespace characters preceding a segment separator or
  35893. paragraph separator, and any sequence of white space characters at the end
  35894. of the line.
  35895. */
  35896. // don't bother as text is only single line
  35897. /*
  35898. L2. From the highest level found in the text to the lowest odd level on
  35899. each line, reverse any contiguous sequence of characters that are at that
  35900. level or higher.
  35901. */
  35902. // find highest level & lowest odd level
  35903. var highestLevel = -1;
  35904. var lowestOddLevel = 99;
  35905. var level;
  35906. for (i = 0, ii = levels.length; i < ii; ++i) {
  35907. level = levels[i];
  35908. if (highestLevel < level) {
  35909. highestLevel = level;
  35910. }
  35911. if (lowestOddLevel > level && isOdd(level)) {
  35912. lowestOddLevel = level;
  35913. }
  35914. }
  35915. // now reverse between those limits
  35916. for (level = highestLevel; level >= lowestOddLevel; --level) {
  35917. // find segments to reverse
  35918. var start = -1;
  35919. for (i = 0, ii = levels.length; i < ii; ++i) {
  35920. if (levels[i] < level) {
  35921. if (start >= 0) {
  35922. reverseValues(chars, start, i);
  35923. start = -1;
  35924. }
  35925. } else if (start < 0) {
  35926. start = i;
  35927. }
  35928. }
  35929. if (start >= 0) {
  35930. reverseValues(chars, start, levels.length);
  35931. }
  35932. }
  35933. /*
  35934. L3. Combining marks applied to a right-to-left base character will at this
  35935. point precede their base character. If the rendering engine expects them to
  35936. follow the base characters in the final display process, then the ordering
  35937. of the marks and the base character must be reversed.
  35938. */
  35939. // don't bother for now
  35940. /*
  35941. L4. A character that possesses the mirrored property as specified by
  35942. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  35943. directionality of that character is R.
  35944. */
  35945. // don't mirror as characters are already mirrored in the pdf
  35946. // Finally, return string
  35947. var result = '';
  35948. for (i = 0, ii = chars.length; i < ii; ++i) {
  35949. var ch = chars[i];
  35950. if (ch !== '<' && ch !== '>') {
  35951. result += ch;
  35952. }
  35953. }
  35954. return createBidiText(result, isLTR);
  35955. }
  35956. return bidi;
  35957. })();
  35958. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  35959. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  35960. /* Copyright 2014 Opera Software ASA
  35961. *
  35962. * Licensed under the Apache License, Version 2.0 (the "License");
  35963. * you may not use this file except in compliance with the License.
  35964. * You may obtain a copy of the License at
  35965. *
  35966. * http://www.apache.org/licenses/LICENSE-2.0
  35967. *
  35968. * Unless required by applicable law or agreed to in writing, software
  35969. * distributed under the License is distributed on an "AS IS" BASIS,
  35970. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  35971. * See the License for the specific language governing permissions and
  35972. * limitations under the License.
  35973. *
  35974. *
  35975. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  35976. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  35977. */
  35978. /* globals Uint32ArrayView */
  35979. 'use strict';
  35980. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  35981. // Workaround for missing math precison in JS.
  35982. var MASK_HIGH = 0xffff0000;
  35983. var MASK_LOW = 0xffff;
  35984. function MurmurHash3_64 (seed) {
  35985. var SEED = 0xc3d2e1f0;
  35986. this.h1 = seed ? seed & 0xffffffff : SEED;
  35987. this.h2 = seed ? seed & 0xffffffff : SEED;
  35988. }
  35989. var alwaysUseUint32ArrayView = false;
  35990. // old webkits have issues with non-aligned arrays
  35991. try {
  35992. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  35993. } catch (e) {
  35994. alwaysUseUint32ArrayView = true;
  35995. }
  35996. MurmurHash3_64.prototype = {
  35997. update: function MurmurHash3_64_update(input) {
  35998. var useUint32ArrayView = alwaysUseUint32ArrayView;
  35999. var i;
  36000. if (typeof input === 'string') {
  36001. var data = new Uint8Array(input.length * 2);
  36002. var length = 0;
  36003. for (i = 0; i < input.length; i++) {
  36004. var code = input.charCodeAt(i);
  36005. if (code <= 0xff) {
  36006. data[length++] = code;
  36007. }
  36008. else {
  36009. data[length++] = code >>> 8;
  36010. data[length++] = code & 0xff;
  36011. }
  36012. }
  36013. } else if (input instanceof Uint8Array) {
  36014. data = input;
  36015. length = data.length;
  36016. } else if (typeof input === 'object' && ('length' in input)) {
  36017. // processing regular arrays as well, e.g. for IE9
  36018. data = input;
  36019. length = data.length;
  36020. useUint32ArrayView = true;
  36021. } else {
  36022. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36023. 'Input must be a string or array.');
  36024. }
  36025. var blockCounts = length >> 2;
  36026. var tailLength = length - blockCounts * 4;
  36027. // we don't care about endianness here
  36028. var dataUint32 = useUint32ArrayView ?
  36029. new Uint32ArrayView(data, blockCounts) :
  36030. new Uint32Array(data.buffer, 0, blockCounts);
  36031. var k1 = 0;
  36032. var k2 = 0;
  36033. var h1 = this.h1;
  36034. var h2 = this.h2;
  36035. var C1 = 0xcc9e2d51;
  36036. var C2 = 0x1b873593;
  36037. var C1_LOW = C1 & MASK_LOW;
  36038. var C2_LOW = C2 & MASK_LOW;
  36039. for (i = 0; i < blockCounts; i++) {
  36040. if (i & 1) {
  36041. k1 = dataUint32[i];
  36042. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36043. k1 = k1 << 15 | k1 >>> 17;
  36044. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36045. h1 ^= k1;
  36046. h1 = h1 << 13 | h1 >>> 19;
  36047. h1 = h1 * 5 + 0xe6546b64;
  36048. } else {
  36049. k2 = dataUint32[i];
  36050. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36051. k2 = k2 << 15 | k2 >>> 17;
  36052. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36053. h2 ^= k2;
  36054. h2 = h2 << 13 | h2 >>> 19;
  36055. h2 = h2 * 5 + 0xe6546b64;
  36056. }
  36057. }
  36058. k1 = 0;
  36059. switch (tailLength) {
  36060. case 3:
  36061. k1 ^= data[blockCounts * 4 + 2] << 16;
  36062. /* falls through */
  36063. case 2:
  36064. k1 ^= data[blockCounts * 4 + 1] << 8;
  36065. /* falls through */
  36066. case 1:
  36067. k1 ^= data[blockCounts * 4];
  36068. /* falls through */
  36069. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36070. k1 = k1 << 15 | k1 >>> 17;
  36071. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36072. if (blockCounts & 1) {
  36073. h1 ^= k1;
  36074. } else {
  36075. h2 ^= k1;
  36076. }
  36077. }
  36078. this.h1 = h1;
  36079. this.h2 = h2;
  36080. return this;
  36081. },
  36082. hexdigest: function MurmurHash3_64_hexdigest () {
  36083. var h1 = this.h1;
  36084. var h2 = this.h2;
  36085. h1 ^= h2 >>> 1;
  36086. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36087. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36088. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36089. h1 ^= h2 >>> 1;
  36090. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36091. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36092. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36093. h1 ^= h2 >>> 1;
  36094. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36095. var hex = (arr[i] >>> 0).toString(16);
  36096. while (hex.length < 8) {
  36097. hex = '0' + hex;
  36098. }
  36099. str += hex;
  36100. }
  36101. return str;
  36102. }
  36103. };
  36104. return MurmurHash3_64;
  36105. })();
  36106. }).call((typeof window === 'undefined') ? this : window);
  36107. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36108. // workerSrc is not set -- using last script url to define default location
  36109. PDFJS.workerSrc = (function () {
  36110. 'use strict';
  36111. var scriptTagContainer = document.body ||
  36112. document.getElementsByTagName('head')[0];
  36113. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36114. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36115. })();
  36116. }