pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702
  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.1.546';
  24. PDFJS.build = 'b3a9a0d';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. var globalScope = (typeof window === 'undefined') ? this : window;
  29. var isWorker = (typeof window === 'undefined');
  30. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  31. var TextRenderingMode = {
  32. FILL: 0,
  33. STROKE: 1,
  34. FILL_STROKE: 2,
  35. INVISIBLE: 3,
  36. FILL_ADD_TO_PATH: 4,
  37. STROKE_ADD_TO_PATH: 5,
  38. FILL_STROKE_ADD_TO_PATH: 6,
  39. ADD_TO_PATH: 7,
  40. FILL_STROKE_MASK: 3,
  41. ADD_TO_PATH_FLAG: 4
  42. };
  43. var ImageKind = {
  44. GRAYSCALE_1BPP: 1,
  45. RGB_24BPP: 2,
  46. RGBA_32BPP: 3
  47. };
  48. var AnnotationType = {
  49. WIDGET: 1,
  50. TEXT: 2,
  51. LINK: 3
  52. };
  53. var AnnotationBorderStyleType = {
  54. SOLID: 1,
  55. DASHED: 2,
  56. BEVELED: 3,
  57. INSET: 4,
  58. UNDERLINE: 5
  59. };
  60. var StreamType = {
  61. UNKNOWN: 0,
  62. FLATE: 1,
  63. LZW: 2,
  64. DCT: 3,
  65. JPX: 4,
  66. JBIG: 5,
  67. A85: 6,
  68. AHX: 7,
  69. CCF: 8,
  70. RL: 9
  71. };
  72. var FontType = {
  73. UNKNOWN: 0,
  74. TYPE1: 1,
  75. TYPE1C: 2,
  76. CIDFONTTYPE0: 3,
  77. CIDFONTTYPE0C: 4,
  78. TRUETYPE: 5,
  79. CIDFONTTYPE2: 6,
  80. TYPE3: 7,
  81. OPENTYPE: 8,
  82. TYPE0: 9,
  83. MMTYPE1: 10
  84. };
  85. // The global PDFJS object exposes the API
  86. // In production, it will be declared outside a global wrapper
  87. // In development, it will be declared here
  88. if (!globalScope.PDFJS) {
  89. globalScope.PDFJS = {};
  90. }
  91. globalScope.PDFJS.pdfBug = false;
  92. PDFJS.VERBOSITY_LEVELS = {
  93. errors: 0,
  94. warnings: 1,
  95. infos: 5
  96. };
  97. // All the possible operations for an operator list.
  98. var OPS = PDFJS.OPS = {
  99. // Intentionally start from 1 so it is easy to spot bad operators that will be
  100. // 0's.
  101. dependency: 1,
  102. setLineWidth: 2,
  103. setLineCap: 3,
  104. setLineJoin: 4,
  105. setMiterLimit: 5,
  106. setDash: 6,
  107. setRenderingIntent: 7,
  108. setFlatness: 8,
  109. setGState: 9,
  110. save: 10,
  111. restore: 11,
  112. transform: 12,
  113. moveTo: 13,
  114. lineTo: 14,
  115. curveTo: 15,
  116. curveTo2: 16,
  117. curveTo3: 17,
  118. closePath: 18,
  119. rectangle: 19,
  120. stroke: 20,
  121. closeStroke: 21,
  122. fill: 22,
  123. eoFill: 23,
  124. fillStroke: 24,
  125. eoFillStroke: 25,
  126. closeFillStroke: 26,
  127. closeEOFillStroke: 27,
  128. endPath: 28,
  129. clip: 29,
  130. eoClip: 30,
  131. beginText: 31,
  132. endText: 32,
  133. setCharSpacing: 33,
  134. setWordSpacing: 34,
  135. setHScale: 35,
  136. setLeading: 36,
  137. setFont: 37,
  138. setTextRenderingMode: 38,
  139. setTextRise: 39,
  140. moveText: 40,
  141. setLeadingMoveText: 41,
  142. setTextMatrix: 42,
  143. nextLine: 43,
  144. showText: 44,
  145. showSpacedText: 45,
  146. nextLineShowText: 46,
  147. nextLineSetSpacingShowText: 47,
  148. setCharWidth: 48,
  149. setCharWidthAndBounds: 49,
  150. setStrokeColorSpace: 50,
  151. setFillColorSpace: 51,
  152. setStrokeColor: 52,
  153. setStrokeColorN: 53,
  154. setFillColor: 54,
  155. setFillColorN: 55,
  156. setStrokeGray: 56,
  157. setFillGray: 57,
  158. setStrokeRGBColor: 58,
  159. setFillRGBColor: 59,
  160. setStrokeCMYKColor: 60,
  161. setFillCMYKColor: 61,
  162. shadingFill: 62,
  163. beginInlineImage: 63,
  164. beginImageData: 64,
  165. endInlineImage: 65,
  166. paintXObject: 66,
  167. markPoint: 67,
  168. markPointProps: 68,
  169. beginMarkedContent: 69,
  170. beginMarkedContentProps: 70,
  171. endMarkedContent: 71,
  172. beginCompat: 72,
  173. endCompat: 73,
  174. paintFormXObjectBegin: 74,
  175. paintFormXObjectEnd: 75,
  176. beginGroup: 76,
  177. endGroup: 77,
  178. beginAnnotations: 78,
  179. endAnnotations: 79,
  180. beginAnnotation: 80,
  181. endAnnotation: 81,
  182. paintJpegXObject: 82,
  183. paintImageMaskXObject: 83,
  184. paintImageMaskXObjectGroup: 84,
  185. paintImageXObject: 85,
  186. paintInlineImageXObject: 86,
  187. paintInlineImageXObjectGroup: 87,
  188. paintImageXObjectRepeat: 88,
  189. paintImageMaskXObjectRepeat: 89,
  190. paintSolidColorImageMask: 90,
  191. constructPath: 91
  192. };
  193. // A notice for devs. These are good for things that are helpful to devs, such
  194. // as warning that Workers were disabled, which is important to devs but not
  195. // end users.
  196. function info(msg) {
  197. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  198. console.log('Info: ' + msg);
  199. }
  200. }
  201. // Non-fatal warnings.
  202. function warn(msg) {
  203. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  204. console.log('Warning: ' + msg);
  205. }
  206. }
  207. // Fatal errors that should trigger the fallback UI and halt execution by
  208. // throwing an exception.
  209. function error(msg) {
  210. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  211. console.log('Error: ' + msg);
  212. console.log(backtrace());
  213. }
  214. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  215. throw new Error(msg);
  216. }
  217. function backtrace() {
  218. try {
  219. throw new Error();
  220. } catch (e) {
  221. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  222. }
  223. }
  224. function assert(cond, msg) {
  225. if (!cond) {
  226. error(msg);
  227. }
  228. }
  229. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  230. unknown: 'unknown',
  231. forms: 'forms',
  232. javaScript: 'javaScript',
  233. smask: 'smask',
  234. shadingPattern: 'shadingPattern',
  235. font: 'font'
  236. };
  237. var UnsupportedManager = PDFJS.UnsupportedManager =
  238. (function UnsupportedManagerClosure() {
  239. var listeners = [];
  240. return {
  241. listen: function (cb) {
  242. listeners.push(cb);
  243. },
  244. notify: function (featureId) {
  245. warn('Unsupported feature "' + featureId + '"');
  246. for (var i = 0, ii = listeners.length; i < ii; i++) {
  247. listeners[i](featureId);
  248. }
  249. }
  250. };
  251. })();
  252. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  253. // absolute URL, it will be returned as is.
  254. function combineUrl(baseUrl, url) {
  255. if (!url) {
  256. return baseUrl;
  257. }
  258. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  259. return url;
  260. }
  261. var i;
  262. if (url.charAt(0) === '/') {
  263. // absolute path
  264. i = baseUrl.indexOf('://');
  265. if (url.charAt(1) === '/') {
  266. ++i;
  267. } else {
  268. i = baseUrl.indexOf('/', i + 3);
  269. }
  270. return baseUrl.substring(0, i) + url;
  271. } else {
  272. // relative path
  273. var pathLength = baseUrl.length;
  274. i = baseUrl.lastIndexOf('#');
  275. pathLength = i >= 0 ? i : pathLength;
  276. i = baseUrl.lastIndexOf('?', pathLength);
  277. pathLength = i >= 0 ? i : pathLength;
  278. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  279. return baseUrl.substring(0, prefixLength + 1) + url;
  280. }
  281. }
  282. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  283. function isValidUrl(url, allowRelative) {
  284. if (!url) {
  285. return false;
  286. }
  287. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  288. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  289. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  290. if (!protocol) {
  291. return allowRelative;
  292. }
  293. protocol = protocol[0].toLowerCase();
  294. switch (protocol) {
  295. case 'http':
  296. case 'https':
  297. case 'ftp':
  298. case 'mailto':
  299. case 'tel':
  300. return true;
  301. default:
  302. return false;
  303. }
  304. }
  305. PDFJS.isValidUrl = isValidUrl;
  306. function shadow(obj, prop, value) {
  307. Object.defineProperty(obj, prop, { value: value,
  308. enumerable: true,
  309. configurable: true,
  310. writable: false });
  311. return value;
  312. }
  313. PDFJS.shadow = shadow;
  314. var LinkTarget = PDFJS.LinkTarget = {
  315. NONE: 0, // Default value.
  316. SELF: 1,
  317. BLANK: 2,
  318. PARENT: 3,
  319. TOP: 4,
  320. };
  321. var LinkTargetStringMap = [
  322. '',
  323. '_self',
  324. '_blank',
  325. '_parent',
  326. '_top'
  327. ];
  328. function isExternalLinkTargetSet() {
  329. if (PDFJS.openExternalLinksInNewWindow) {
  330. warn('PDFJS.openExternalLinksInNewWindow is deprecated, ' +
  331. 'use PDFJS.externalLinkTarget instead.');
  332. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  333. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  334. }
  335. // Reset the deprecated parameter, to suppress further warnings.
  336. PDFJS.openExternalLinksInNewWindow = false;
  337. }
  338. switch (PDFJS.externalLinkTarget) {
  339. case LinkTarget.NONE:
  340. return false;
  341. case LinkTarget.SELF:
  342. case LinkTarget.BLANK:
  343. case LinkTarget.PARENT:
  344. case LinkTarget.TOP:
  345. return true;
  346. }
  347. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  348. // Reset the external link target, to suppress further warnings.
  349. PDFJS.externalLinkTarget = LinkTarget.NONE;
  350. return false;
  351. }
  352. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  353. var PasswordResponses = PDFJS.PasswordResponses = {
  354. NEED_PASSWORD: 1,
  355. INCORRECT_PASSWORD: 2
  356. };
  357. var PasswordException = (function PasswordExceptionClosure() {
  358. function PasswordException(msg, code) {
  359. this.name = 'PasswordException';
  360. this.message = msg;
  361. this.code = code;
  362. }
  363. PasswordException.prototype = new Error();
  364. PasswordException.constructor = PasswordException;
  365. return PasswordException;
  366. })();
  367. PDFJS.PasswordException = PasswordException;
  368. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  369. function UnknownErrorException(msg, details) {
  370. this.name = 'UnknownErrorException';
  371. this.message = msg;
  372. this.details = details;
  373. }
  374. UnknownErrorException.prototype = new Error();
  375. UnknownErrorException.constructor = UnknownErrorException;
  376. return UnknownErrorException;
  377. })();
  378. PDFJS.UnknownErrorException = UnknownErrorException;
  379. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  380. function InvalidPDFException(msg) {
  381. this.name = 'InvalidPDFException';
  382. this.message = msg;
  383. }
  384. InvalidPDFException.prototype = new Error();
  385. InvalidPDFException.constructor = InvalidPDFException;
  386. return InvalidPDFException;
  387. })();
  388. PDFJS.InvalidPDFException = InvalidPDFException;
  389. var MissingPDFException = (function MissingPDFExceptionClosure() {
  390. function MissingPDFException(msg) {
  391. this.name = 'MissingPDFException';
  392. this.message = msg;
  393. }
  394. MissingPDFException.prototype = new Error();
  395. MissingPDFException.constructor = MissingPDFException;
  396. return MissingPDFException;
  397. })();
  398. PDFJS.MissingPDFException = MissingPDFException;
  399. var UnexpectedResponseException =
  400. (function UnexpectedResponseExceptionClosure() {
  401. function UnexpectedResponseException(msg, status) {
  402. this.name = 'UnexpectedResponseException';
  403. this.message = msg;
  404. this.status = status;
  405. }
  406. UnexpectedResponseException.prototype = new Error();
  407. UnexpectedResponseException.constructor = UnexpectedResponseException;
  408. return UnexpectedResponseException;
  409. })();
  410. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  411. var NotImplementedException = (function NotImplementedExceptionClosure() {
  412. function NotImplementedException(msg) {
  413. this.message = msg;
  414. }
  415. NotImplementedException.prototype = new Error();
  416. NotImplementedException.prototype.name = 'NotImplementedException';
  417. NotImplementedException.constructor = NotImplementedException;
  418. return NotImplementedException;
  419. })();
  420. var MissingDataException = (function MissingDataExceptionClosure() {
  421. function MissingDataException(begin, end) {
  422. this.begin = begin;
  423. this.end = end;
  424. this.message = 'Missing data [' + begin + ', ' + end + ')';
  425. }
  426. MissingDataException.prototype = new Error();
  427. MissingDataException.prototype.name = 'MissingDataException';
  428. MissingDataException.constructor = MissingDataException;
  429. return MissingDataException;
  430. })();
  431. var XRefParseException = (function XRefParseExceptionClosure() {
  432. function XRefParseException(msg) {
  433. this.message = msg;
  434. }
  435. XRefParseException.prototype = new Error();
  436. XRefParseException.prototype.name = 'XRefParseException';
  437. XRefParseException.constructor = XRefParseException;
  438. return XRefParseException;
  439. })();
  440. function bytesToString(bytes) {
  441. assert(bytes !== null && typeof bytes === 'object' &&
  442. bytes.length !== undefined, 'Invalid argument for bytesToString');
  443. var length = bytes.length;
  444. var MAX_ARGUMENT_COUNT = 8192;
  445. if (length < MAX_ARGUMENT_COUNT) {
  446. return String.fromCharCode.apply(null, bytes);
  447. }
  448. var strBuf = [];
  449. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  450. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  451. var chunk = bytes.subarray(i, chunkEnd);
  452. strBuf.push(String.fromCharCode.apply(null, chunk));
  453. }
  454. return strBuf.join('');
  455. }
  456. function stringToBytes(str) {
  457. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  458. var length = str.length;
  459. var bytes = new Uint8Array(length);
  460. for (var i = 0; i < length; ++i) {
  461. bytes[i] = str.charCodeAt(i) & 0xFF;
  462. }
  463. return bytes;
  464. }
  465. function string32(value) {
  466. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  467. (value >> 8) & 0xff, value & 0xff);
  468. }
  469. function log2(x) {
  470. var n = 1, i = 0;
  471. while (x > n) {
  472. n <<= 1;
  473. i++;
  474. }
  475. return i;
  476. }
  477. function readInt8(data, start) {
  478. return (data[start] << 24) >> 24;
  479. }
  480. function readUint16(data, offset) {
  481. return (data[offset] << 8) | data[offset + 1];
  482. }
  483. function readUint32(data, offset) {
  484. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  485. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  486. }
  487. // Lazy test the endianness of the platform
  488. // NOTE: This will be 'true' for simulated TypedArrays
  489. function isLittleEndian() {
  490. var buffer8 = new Uint8Array(2);
  491. buffer8[0] = 1;
  492. var buffer16 = new Uint16Array(buffer8.buffer);
  493. return (buffer16[0] === 1);
  494. }
  495. Object.defineProperty(PDFJS, 'isLittleEndian', {
  496. configurable: true,
  497. get: function PDFJS_isLittleEndian() {
  498. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  499. }
  500. });
  501. // Lazy test if the userAgent support CanvasTypedArrays
  502. function hasCanvasTypedArrays() {
  503. var canvas = document.createElement('canvas');
  504. canvas.width = canvas.height = 1;
  505. var ctx = canvas.getContext('2d');
  506. var imageData = ctx.createImageData(1, 1);
  507. return (typeof imageData.data.buffer !== 'undefined');
  508. }
  509. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  510. configurable: true,
  511. get: function PDFJS_hasCanvasTypedArrays() {
  512. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  513. }
  514. });
  515. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  516. function Uint32ArrayView(buffer, length) {
  517. this.buffer = buffer;
  518. this.byteLength = buffer.length;
  519. this.length = length === undefined ? (this.byteLength >> 2) : length;
  520. ensureUint32ArrayViewProps(this.length);
  521. }
  522. Uint32ArrayView.prototype = Object.create(null);
  523. var uint32ArrayViewSetters = 0;
  524. function createUint32ArrayProp(index) {
  525. return {
  526. get: function () {
  527. var buffer = this.buffer, offset = index << 2;
  528. return (buffer[offset] | (buffer[offset + 1] << 8) |
  529. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  530. },
  531. set: function (value) {
  532. var buffer = this.buffer, offset = index << 2;
  533. buffer[offset] = value & 255;
  534. buffer[offset + 1] = (value >> 8) & 255;
  535. buffer[offset + 2] = (value >> 16) & 255;
  536. buffer[offset + 3] = (value >>> 24) & 255;
  537. }
  538. };
  539. }
  540. function ensureUint32ArrayViewProps(length) {
  541. while (uint32ArrayViewSetters < length) {
  542. Object.defineProperty(Uint32ArrayView.prototype,
  543. uint32ArrayViewSetters,
  544. createUint32ArrayProp(uint32ArrayViewSetters));
  545. uint32ArrayViewSetters++;
  546. }
  547. }
  548. return Uint32ArrayView;
  549. })();
  550. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  551. var Util = PDFJS.Util = (function UtilClosure() {
  552. function Util() {}
  553. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  554. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  555. // creating many intermediate strings.
  556. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  557. rgbBuf[1] = r;
  558. rgbBuf[3] = g;
  559. rgbBuf[5] = b;
  560. return rgbBuf.join('');
  561. };
  562. // Concatenates two transformation matrices together and returns the result.
  563. Util.transform = function Util_transform(m1, m2) {
  564. return [
  565. m1[0] * m2[0] + m1[2] * m2[1],
  566. m1[1] * m2[0] + m1[3] * m2[1],
  567. m1[0] * m2[2] + m1[2] * m2[3],
  568. m1[1] * m2[2] + m1[3] * m2[3],
  569. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  570. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  571. ];
  572. };
  573. // For 2d affine transforms
  574. Util.applyTransform = function Util_applyTransform(p, m) {
  575. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  576. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  577. return [xt, yt];
  578. };
  579. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  580. var d = m[0] * m[3] - m[1] * m[2];
  581. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  582. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  583. return [xt, yt];
  584. };
  585. // Applies the transform to the rectangle and finds the minimum axially
  586. // aligned bounding box.
  587. Util.getAxialAlignedBoundingBox =
  588. function Util_getAxialAlignedBoundingBox(r, m) {
  589. var p1 = Util.applyTransform(r, m);
  590. var p2 = Util.applyTransform(r.slice(2, 4), m);
  591. var p3 = Util.applyTransform([r[0], r[3]], m);
  592. var p4 = Util.applyTransform([r[2], r[1]], m);
  593. return [
  594. Math.min(p1[0], p2[0], p3[0], p4[0]),
  595. Math.min(p1[1], p2[1], p3[1], p4[1]),
  596. Math.max(p1[0], p2[0], p3[0], p4[0]),
  597. Math.max(p1[1], p2[1], p3[1], p4[1])
  598. ];
  599. };
  600. Util.inverseTransform = function Util_inverseTransform(m) {
  601. var d = m[0] * m[3] - m[1] * m[2];
  602. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  603. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  604. };
  605. // Apply a generic 3d matrix M on a 3-vector v:
  606. // | a b c | | X |
  607. // | d e f | x | Y |
  608. // | g h i | | Z |
  609. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  610. // with v as [X,Y,Z]
  611. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  612. return [
  613. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  614. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  615. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  616. ];
  617. };
  618. // This calculation uses Singular Value Decomposition.
  619. // The SVD can be represented with formula A = USV. We are interested in the
  620. // matrix S here because it represents the scale values.
  621. Util.singularValueDecompose2dScale =
  622. function Util_singularValueDecompose2dScale(m) {
  623. var transpose = [m[0], m[2], m[1], m[3]];
  624. // Multiply matrix m with its transpose.
  625. var a = m[0] * transpose[0] + m[1] * transpose[2];
  626. var b = m[0] * transpose[1] + m[1] * transpose[3];
  627. var c = m[2] * transpose[0] + m[3] * transpose[2];
  628. var d = m[2] * transpose[1] + m[3] * transpose[3];
  629. // Solve the second degree polynomial to get roots.
  630. var first = (a + d) / 2;
  631. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  632. var sx = first + second || 1;
  633. var sy = first - second || 1;
  634. // Scale values are the square roots of the eigenvalues.
  635. return [Math.sqrt(sx), Math.sqrt(sy)];
  636. };
  637. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  638. // For coordinate systems whose origin lies in the bottom-left, this
  639. // means normalization to (BL,TR) ordering. For systems with origin in the
  640. // top-left, this means (TL,BR) ordering.
  641. Util.normalizeRect = function Util_normalizeRect(rect) {
  642. var r = rect.slice(0); // clone rect
  643. if (rect[0] > rect[2]) {
  644. r[0] = rect[2];
  645. r[2] = rect[0];
  646. }
  647. if (rect[1] > rect[3]) {
  648. r[1] = rect[3];
  649. r[3] = rect[1];
  650. }
  651. return r;
  652. };
  653. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  654. // intersection of rect1 and rect2. If no intersection, returns 'false'
  655. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  656. Util.intersect = function Util_intersect(rect1, rect2) {
  657. function compare(a, b) {
  658. return a - b;
  659. }
  660. // Order points along the axes
  661. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  662. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  663. result = [];
  664. rect1 = Util.normalizeRect(rect1);
  665. rect2 = Util.normalizeRect(rect2);
  666. // X: first and second points belong to different rectangles?
  667. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  668. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  669. // Intersection must be between second and third points
  670. result[0] = orderedX[1];
  671. result[2] = orderedX[2];
  672. } else {
  673. return false;
  674. }
  675. // Y: first and second points belong to different rectangles?
  676. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  677. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  678. // Intersection must be between second and third points
  679. result[1] = orderedY[1];
  680. result[3] = orderedY[2];
  681. } else {
  682. return false;
  683. }
  684. return result;
  685. };
  686. Util.sign = function Util_sign(num) {
  687. return num < 0 ? -1 : 1;
  688. };
  689. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  690. Array.prototype.push.apply(arr1, arr2);
  691. };
  692. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  693. Array.prototype.unshift.apply(arr1, arr2);
  694. };
  695. Util.extendObj = function extendObj(obj1, obj2) {
  696. for (var key in obj2) {
  697. obj1[key] = obj2[key];
  698. }
  699. };
  700. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  701. name) {
  702. while (dict && !dict.has(name)) {
  703. dict = dict.get('Parent');
  704. }
  705. if (!dict) {
  706. return null;
  707. }
  708. return dict.get(name);
  709. };
  710. Util.inherit = function Util_inherit(sub, base, prototype) {
  711. sub.prototype = Object.create(base.prototype);
  712. sub.prototype.constructor = sub;
  713. for (var prop in prototype) {
  714. sub.prototype[prop] = prototype[prop];
  715. }
  716. };
  717. Util.loadScript = function Util_loadScript(src, callback) {
  718. var script = document.createElement('script');
  719. var loaded = false;
  720. script.setAttribute('src', src);
  721. if (callback) {
  722. script.onload = function() {
  723. if (!loaded) {
  724. callback();
  725. }
  726. loaded = true;
  727. };
  728. }
  729. document.getElementsByTagName('head')[0].appendChild(script);
  730. };
  731. return Util;
  732. })();
  733. /**
  734. * PDF page viewport created based on scale, rotation and offset.
  735. * @class
  736. * @alias PDFJS.PageViewport
  737. */
  738. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  739. /**
  740. * @constructor
  741. * @private
  742. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  743. * @param scale {number} scale of the viewport.
  744. * @param rotation {number} rotations of the viewport in degrees.
  745. * @param offsetX {number} offset X
  746. * @param offsetY {number} offset Y
  747. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  748. */
  749. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  750. this.viewBox = viewBox;
  751. this.scale = scale;
  752. this.rotation = rotation;
  753. this.offsetX = offsetX;
  754. this.offsetY = offsetY;
  755. // creating transform to convert pdf coordinate system to the normal
  756. // canvas like coordinates taking in account scale and rotation
  757. var centerX = (viewBox[2] + viewBox[0]) / 2;
  758. var centerY = (viewBox[3] + viewBox[1]) / 2;
  759. var rotateA, rotateB, rotateC, rotateD;
  760. rotation = rotation % 360;
  761. rotation = rotation < 0 ? rotation + 360 : rotation;
  762. switch (rotation) {
  763. case 180:
  764. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  765. break;
  766. case 90:
  767. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  768. break;
  769. case 270:
  770. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  771. break;
  772. //case 0:
  773. default:
  774. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  775. break;
  776. }
  777. if (dontFlip) {
  778. rotateC = -rotateC; rotateD = -rotateD;
  779. }
  780. var offsetCanvasX, offsetCanvasY;
  781. var width, height;
  782. if (rotateA === 0) {
  783. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  784. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  785. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  786. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  787. } else {
  788. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  789. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  790. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  791. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  792. }
  793. // creating transform for the following operations:
  794. // translate(-centerX, -centerY), rotate and flip vertically,
  795. // scale, and translate(offsetCanvasX, offsetCanvasY)
  796. this.transform = [
  797. rotateA * scale,
  798. rotateB * scale,
  799. rotateC * scale,
  800. rotateD * scale,
  801. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  802. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  803. ];
  804. this.width = width;
  805. this.height = height;
  806. this.fontScale = scale;
  807. }
  808. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  809. /**
  810. * Clones viewport with additional properties.
  811. * @param args {Object} (optional) If specified, may contain the 'scale' or
  812. * 'rotation' properties to override the corresponding properties in
  813. * the cloned viewport.
  814. * @returns {PDFJS.PageViewport} Cloned viewport.
  815. */
  816. clone: function PageViewPort_clone(args) {
  817. args = args || {};
  818. var scale = 'scale' in args ? args.scale : this.scale;
  819. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  820. return new PageViewport(this.viewBox.slice(), scale, rotation,
  821. this.offsetX, this.offsetY, args.dontFlip);
  822. },
  823. /**
  824. * Converts PDF point to the viewport coordinates. For examples, useful for
  825. * converting PDF location into canvas pixel coordinates.
  826. * @param x {number} X coordinate.
  827. * @param y {number} Y coordinate.
  828. * @returns {Object} Object that contains 'x' and 'y' properties of the
  829. * point in the viewport coordinate space.
  830. * @see {@link convertToPdfPoint}
  831. * @see {@link convertToViewportRectangle}
  832. */
  833. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  834. return Util.applyTransform([x, y], this.transform);
  835. },
  836. /**
  837. * Converts PDF rectangle to the viewport coordinates.
  838. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  839. * @returns {Array} Contains corresponding coordinates of the rectangle
  840. * in the viewport coordinate space.
  841. * @see {@link convertToViewportPoint}
  842. */
  843. convertToViewportRectangle:
  844. function PageViewport_convertToViewportRectangle(rect) {
  845. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  846. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  847. return [tl[0], tl[1], br[0], br[1]];
  848. },
  849. /**
  850. * Converts viewport coordinates to the PDF location. For examples, useful
  851. * for converting canvas pixel location into PDF one.
  852. * @param x {number} X coordinate.
  853. * @param y {number} Y coordinate.
  854. * @returns {Object} Object that contains 'x' and 'y' properties of the
  855. * point in the PDF coordinate space.
  856. * @see {@link convertToViewportPoint}
  857. */
  858. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  859. return Util.applyInverseTransform([x, y], this.transform);
  860. }
  861. };
  862. return PageViewport;
  863. })();
  864. var PDFStringTranslateTable = [
  865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  866. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  867. 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,
  868. 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,
  869. 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,
  870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  871. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  872. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  873. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  874. ];
  875. function stringToPDFString(str) {
  876. var i, n = str.length, strBuf = [];
  877. if (str[0] === '\xFE' && str[1] === '\xFF') {
  878. // UTF16BE BOM
  879. for (i = 2; i < n; i += 2) {
  880. strBuf.push(String.fromCharCode(
  881. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  882. }
  883. } else {
  884. for (i = 0; i < n; ++i) {
  885. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  886. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  887. }
  888. }
  889. return strBuf.join('');
  890. }
  891. function stringToUTF8String(str) {
  892. return decodeURIComponent(escape(str));
  893. }
  894. function utf8StringToString(str) {
  895. return unescape(encodeURIComponent(str));
  896. }
  897. function isEmptyObj(obj) {
  898. for (var key in obj) {
  899. return false;
  900. }
  901. return true;
  902. }
  903. function isBool(v) {
  904. return typeof v === 'boolean';
  905. }
  906. function isInt(v) {
  907. return typeof v === 'number' && ((v | 0) === v);
  908. }
  909. function isNum(v) {
  910. return typeof v === 'number';
  911. }
  912. function isString(v) {
  913. return typeof v === 'string';
  914. }
  915. function isName(v) {
  916. return v instanceof Name;
  917. }
  918. function isCmd(v, cmd) {
  919. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  920. }
  921. function isDict(v, type) {
  922. if (!(v instanceof Dict)) {
  923. return false;
  924. }
  925. if (!type) {
  926. return true;
  927. }
  928. var dictType = v.get('Type');
  929. return isName(dictType) && dictType.name === type;
  930. }
  931. function isArray(v) {
  932. return v instanceof Array;
  933. }
  934. function isStream(v) {
  935. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  936. }
  937. function isArrayBuffer(v) {
  938. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  939. }
  940. function isRef(v) {
  941. return v instanceof Ref;
  942. }
  943. /**
  944. * Promise Capability object.
  945. *
  946. * @typedef {Object} PromiseCapability
  947. * @property {Promise} promise - A promise object.
  948. * @property {function} resolve - Fullfills the promise.
  949. * @property {function} reject - Rejects the promise.
  950. */
  951. /**
  952. * Creates a promise capability object.
  953. * @alias PDFJS.createPromiseCapability
  954. *
  955. * @return {PromiseCapability} A capability object contains:
  956. * - a Promise, resolve and reject methods.
  957. */
  958. function createPromiseCapability() {
  959. var capability = {};
  960. capability.promise = new Promise(function (resolve, reject) {
  961. capability.resolve = resolve;
  962. capability.reject = reject;
  963. });
  964. return capability;
  965. }
  966. PDFJS.createPromiseCapability = createPromiseCapability;
  967. /**
  968. * Polyfill for Promises:
  969. * The following promise implementation tries to generally implement the
  970. * Promise/A+ spec. Some notable differences from other promise libaries are:
  971. * - There currently isn't a seperate deferred and promise object.
  972. * - Unhandled rejections eventually show an error if they aren't handled.
  973. *
  974. * Based off of the work in:
  975. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  976. */
  977. (function PromiseClosure() {
  978. if (globalScope.Promise) {
  979. // Promises existing in the DOM/Worker, checking presence of all/resolve
  980. if (typeof globalScope.Promise.all !== 'function') {
  981. globalScope.Promise.all = function (iterable) {
  982. var count = 0, results = [], resolve, reject;
  983. var promise = new globalScope.Promise(function (resolve_, reject_) {
  984. resolve = resolve_;
  985. reject = reject_;
  986. });
  987. iterable.forEach(function (p, i) {
  988. count++;
  989. p.then(function (result) {
  990. results[i] = result;
  991. count--;
  992. if (count === 0) {
  993. resolve(results);
  994. }
  995. }, reject);
  996. });
  997. if (count === 0) {
  998. resolve(results);
  999. }
  1000. return promise;
  1001. };
  1002. }
  1003. if (typeof globalScope.Promise.resolve !== 'function') {
  1004. globalScope.Promise.resolve = function (value) {
  1005. return new globalScope.Promise(function (resolve) { resolve(value); });
  1006. };
  1007. }
  1008. if (typeof globalScope.Promise.reject !== 'function') {
  1009. globalScope.Promise.reject = function (reason) {
  1010. return new globalScope.Promise(function (resolve, reject) {
  1011. reject(reason);
  1012. });
  1013. };
  1014. }
  1015. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1016. globalScope.Promise.prototype.catch = function (onReject) {
  1017. return globalScope.Promise.prototype.then(undefined, onReject);
  1018. };
  1019. }
  1020. return;
  1021. }
  1022. var STATUS_PENDING = 0;
  1023. var STATUS_RESOLVED = 1;
  1024. var STATUS_REJECTED = 2;
  1025. // In an attempt to avoid silent exceptions, unhandled rejections are
  1026. // tracked and if they aren't handled in a certain amount of time an
  1027. // error is logged.
  1028. var REJECTION_TIMEOUT = 500;
  1029. var HandlerManager = {
  1030. handlers: [],
  1031. running: false,
  1032. unhandledRejections: [],
  1033. pendingRejectionCheck: false,
  1034. scheduleHandlers: function scheduleHandlers(promise) {
  1035. if (promise._status === STATUS_PENDING) {
  1036. return;
  1037. }
  1038. this.handlers = this.handlers.concat(promise._handlers);
  1039. promise._handlers = [];
  1040. if (this.running) {
  1041. return;
  1042. }
  1043. this.running = true;
  1044. setTimeout(this.runHandlers.bind(this), 0);
  1045. },
  1046. runHandlers: function runHandlers() {
  1047. var RUN_TIMEOUT = 1; // ms
  1048. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1049. while (this.handlers.length > 0) {
  1050. var handler = this.handlers.shift();
  1051. var nextStatus = handler.thisPromise._status;
  1052. var nextValue = handler.thisPromise._value;
  1053. try {
  1054. if (nextStatus === STATUS_RESOLVED) {
  1055. if (typeof handler.onResolve === 'function') {
  1056. nextValue = handler.onResolve(nextValue);
  1057. }
  1058. } else if (typeof handler.onReject === 'function') {
  1059. nextValue = handler.onReject(nextValue);
  1060. nextStatus = STATUS_RESOLVED;
  1061. if (handler.thisPromise._unhandledRejection) {
  1062. this.removeUnhandeledRejection(handler.thisPromise);
  1063. }
  1064. }
  1065. } catch (ex) {
  1066. nextStatus = STATUS_REJECTED;
  1067. nextValue = ex;
  1068. }
  1069. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1070. if (Date.now() >= timeoutAt) {
  1071. break;
  1072. }
  1073. }
  1074. if (this.handlers.length > 0) {
  1075. setTimeout(this.runHandlers.bind(this), 0);
  1076. return;
  1077. }
  1078. this.running = false;
  1079. },
  1080. addUnhandledRejection: function addUnhandledRejection(promise) {
  1081. this.unhandledRejections.push({
  1082. promise: promise,
  1083. time: Date.now()
  1084. });
  1085. this.scheduleRejectionCheck();
  1086. },
  1087. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1088. promise._unhandledRejection = false;
  1089. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1090. if (this.unhandledRejections[i].promise === promise) {
  1091. this.unhandledRejections.splice(i);
  1092. i--;
  1093. }
  1094. }
  1095. },
  1096. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1097. if (this.pendingRejectionCheck) {
  1098. return;
  1099. }
  1100. this.pendingRejectionCheck = true;
  1101. setTimeout(function rejectionCheck() {
  1102. this.pendingRejectionCheck = false;
  1103. var now = Date.now();
  1104. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1105. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1106. var unhandled = this.unhandledRejections[i].promise._value;
  1107. var msg = 'Unhandled rejection: ' + unhandled;
  1108. if (unhandled.stack) {
  1109. msg += '\n' + unhandled.stack;
  1110. }
  1111. warn(msg);
  1112. this.unhandledRejections.splice(i);
  1113. i--;
  1114. }
  1115. }
  1116. if (this.unhandledRejections.length) {
  1117. this.scheduleRejectionCheck();
  1118. }
  1119. }.bind(this), REJECTION_TIMEOUT);
  1120. }
  1121. };
  1122. function Promise(resolver) {
  1123. this._status = STATUS_PENDING;
  1124. this._handlers = [];
  1125. try {
  1126. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1127. } catch (e) {
  1128. this._reject(e);
  1129. }
  1130. }
  1131. /**
  1132. * Builds a promise that is resolved when all the passed in promises are
  1133. * resolved.
  1134. * @param {array} array of data and/or promises to wait for.
  1135. * @return {Promise} New dependant promise.
  1136. */
  1137. Promise.all = function Promise_all(promises) {
  1138. var resolveAll, rejectAll;
  1139. var deferred = new Promise(function (resolve, reject) {
  1140. resolveAll = resolve;
  1141. rejectAll = reject;
  1142. });
  1143. var unresolved = promises.length;
  1144. var results = [];
  1145. if (unresolved === 0) {
  1146. resolveAll(results);
  1147. return deferred;
  1148. }
  1149. function reject(reason) {
  1150. if (deferred._status === STATUS_REJECTED) {
  1151. return;
  1152. }
  1153. results = [];
  1154. rejectAll(reason);
  1155. }
  1156. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1157. var promise = promises[i];
  1158. var resolve = (function(i) {
  1159. return function(value) {
  1160. if (deferred._status === STATUS_REJECTED) {
  1161. return;
  1162. }
  1163. results[i] = value;
  1164. unresolved--;
  1165. if (unresolved === 0) {
  1166. resolveAll(results);
  1167. }
  1168. };
  1169. })(i);
  1170. if (Promise.isPromise(promise)) {
  1171. promise.then(resolve, reject);
  1172. } else {
  1173. resolve(promise);
  1174. }
  1175. }
  1176. return deferred;
  1177. };
  1178. /**
  1179. * Checks if the value is likely a promise (has a 'then' function).
  1180. * @return {boolean} true if value is thenable
  1181. */
  1182. Promise.isPromise = function Promise_isPromise(value) {
  1183. return value && typeof value.then === 'function';
  1184. };
  1185. /**
  1186. * Creates resolved promise
  1187. * @param value resolve value
  1188. * @returns {Promise}
  1189. */
  1190. Promise.resolve = function Promise_resolve(value) {
  1191. return new Promise(function (resolve) { resolve(value); });
  1192. };
  1193. /**
  1194. * Creates rejected promise
  1195. * @param reason rejection value
  1196. * @returns {Promise}
  1197. */
  1198. Promise.reject = function Promise_reject(reason) {
  1199. return new Promise(function (resolve, reject) { reject(reason); });
  1200. };
  1201. Promise.prototype = {
  1202. _status: null,
  1203. _value: null,
  1204. _handlers: null,
  1205. _unhandledRejection: null,
  1206. _updateStatus: function Promise__updateStatus(status, value) {
  1207. if (this._status === STATUS_RESOLVED ||
  1208. this._status === STATUS_REJECTED) {
  1209. return;
  1210. }
  1211. if (status === STATUS_RESOLVED &&
  1212. Promise.isPromise(value)) {
  1213. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1214. this._updateStatus.bind(this, STATUS_REJECTED));
  1215. return;
  1216. }
  1217. this._status = status;
  1218. this._value = value;
  1219. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1220. this._unhandledRejection = true;
  1221. HandlerManager.addUnhandledRejection(this);
  1222. }
  1223. HandlerManager.scheduleHandlers(this);
  1224. },
  1225. _resolve: function Promise_resolve(value) {
  1226. this._updateStatus(STATUS_RESOLVED, value);
  1227. },
  1228. _reject: function Promise_reject(reason) {
  1229. this._updateStatus(STATUS_REJECTED, reason);
  1230. },
  1231. then: function Promise_then(onResolve, onReject) {
  1232. var nextPromise = new Promise(function (resolve, reject) {
  1233. this.resolve = resolve;
  1234. this.reject = reject;
  1235. });
  1236. this._handlers.push({
  1237. thisPromise: this,
  1238. onResolve: onResolve,
  1239. onReject: onReject,
  1240. nextPromise: nextPromise
  1241. });
  1242. HandlerManager.scheduleHandlers(this);
  1243. return nextPromise;
  1244. },
  1245. catch: function Promise_catch(onReject) {
  1246. return this.then(undefined, onReject);
  1247. }
  1248. };
  1249. globalScope.Promise = Promise;
  1250. })();
  1251. var StatTimer = (function StatTimerClosure() {
  1252. function rpad(str, pad, length) {
  1253. while (str.length < length) {
  1254. str += pad;
  1255. }
  1256. return str;
  1257. }
  1258. function StatTimer() {
  1259. this.started = {};
  1260. this.times = [];
  1261. this.enabled = true;
  1262. }
  1263. StatTimer.prototype = {
  1264. time: function StatTimer_time(name) {
  1265. if (!this.enabled) {
  1266. return;
  1267. }
  1268. if (name in this.started) {
  1269. warn('Timer is already running for ' + name);
  1270. }
  1271. this.started[name] = Date.now();
  1272. },
  1273. timeEnd: function StatTimer_timeEnd(name) {
  1274. if (!this.enabled) {
  1275. return;
  1276. }
  1277. if (!(name in this.started)) {
  1278. warn('Timer has not been started for ' + name);
  1279. }
  1280. this.times.push({
  1281. 'name': name,
  1282. 'start': this.started[name],
  1283. 'end': Date.now()
  1284. });
  1285. // Remove timer from started so it can be called again.
  1286. delete this.started[name];
  1287. },
  1288. toString: function StatTimer_toString() {
  1289. var i, ii;
  1290. var times = this.times;
  1291. var out = '';
  1292. // Find the longest name for padding purposes.
  1293. var longest = 0;
  1294. for (i = 0, ii = times.length; i < ii; ++i) {
  1295. var name = times[i]['name'];
  1296. if (name.length > longest) {
  1297. longest = name.length;
  1298. }
  1299. }
  1300. for (i = 0, ii = times.length; i < ii; ++i) {
  1301. var span = times[i];
  1302. var duration = span.end - span.start;
  1303. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1304. }
  1305. return out;
  1306. }
  1307. };
  1308. return StatTimer;
  1309. })();
  1310. PDFJS.createBlob = function createBlob(data, contentType) {
  1311. if (typeof Blob !== 'undefined') {
  1312. return new Blob([data], { type: contentType });
  1313. }
  1314. // Blob builder is deprecated in FF14 and removed in FF18.
  1315. var bb = new MozBlobBuilder();
  1316. bb.append(data);
  1317. return bb.getBlob(contentType);
  1318. };
  1319. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1320. // Blob/createObjectURL is not available, falling back to data schema.
  1321. var digits =
  1322. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1323. return function createObjectURL(data, contentType) {
  1324. if (!PDFJS.disableCreateObjectURL &&
  1325. typeof URL !== 'undefined' && URL.createObjectURL) {
  1326. var blob = PDFJS.createBlob(data, contentType);
  1327. return URL.createObjectURL(blob);
  1328. }
  1329. var buffer = 'data:' + contentType + ';base64,';
  1330. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1331. var b1 = data[i] & 0xFF;
  1332. var b2 = data[i + 1] & 0xFF;
  1333. var b3 = data[i + 2] & 0xFF;
  1334. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1335. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1336. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1337. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1338. }
  1339. return buffer;
  1340. };
  1341. })();
  1342. function MessageHandler(name, comObj) {
  1343. this.name = name;
  1344. this.comObj = comObj;
  1345. this.callbackIndex = 1;
  1346. this.postMessageTransfers = true;
  1347. var callbacksCapabilities = this.callbacksCapabilities = {};
  1348. var ah = this.actionHandler = {};
  1349. ah['console_log'] = [function ahConsoleLog(data) {
  1350. console.log.apply(console, data);
  1351. }];
  1352. ah['console_error'] = [function ahConsoleError(data) {
  1353. console.error.apply(console, data);
  1354. }];
  1355. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1356. UnsupportedManager.notify(data);
  1357. }];
  1358. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1359. var data = event.data;
  1360. if (data.isReply) {
  1361. var callbackId = data.callbackId;
  1362. if (data.callbackId in callbacksCapabilities) {
  1363. var callback = callbacksCapabilities[callbackId];
  1364. delete callbacksCapabilities[callbackId];
  1365. if ('error' in data) {
  1366. callback.reject(data.error);
  1367. } else {
  1368. callback.resolve(data.data);
  1369. }
  1370. } else {
  1371. error('Cannot resolve callback ' + callbackId);
  1372. }
  1373. } else if (data.action in ah) {
  1374. var action = ah[data.action];
  1375. if (data.callbackId) {
  1376. Promise.resolve().then(function () {
  1377. return action[0].call(action[1], data.data);
  1378. }).then(function (result) {
  1379. comObj.postMessage({
  1380. isReply: true,
  1381. callbackId: data.callbackId,
  1382. data: result
  1383. });
  1384. }, function (reason) {
  1385. if (reason instanceof Error) {
  1386. // Serialize error to avoid "DataCloneError"
  1387. reason = reason + '';
  1388. }
  1389. comObj.postMessage({
  1390. isReply: true,
  1391. callbackId: data.callbackId,
  1392. error: reason
  1393. });
  1394. });
  1395. } else {
  1396. action[0].call(action[1], data.data);
  1397. }
  1398. } else {
  1399. error('Unknown action from worker: ' + data.action);
  1400. }
  1401. };
  1402. }
  1403. MessageHandler.prototype = {
  1404. on: function messageHandlerOn(actionName, handler, scope) {
  1405. var ah = this.actionHandler;
  1406. if (ah[actionName]) {
  1407. error('There is already an actionName called "' + actionName + '"');
  1408. }
  1409. ah[actionName] = [handler, scope];
  1410. },
  1411. /**
  1412. * Sends a message to the comObj to invoke the action with the supplied data.
  1413. * @param {String} actionName Action to call.
  1414. * @param {JSON} data JSON data to send.
  1415. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1416. */
  1417. send: function messageHandlerSend(actionName, data, transfers) {
  1418. var message = {
  1419. action: actionName,
  1420. data: data
  1421. };
  1422. this.postMessage(message, transfers);
  1423. },
  1424. /**
  1425. * Sends a message to the comObj to invoke the action with the supplied data.
  1426. * Expects that other side will callback with the response.
  1427. * @param {String} actionName Action to call.
  1428. * @param {JSON} data JSON data to send.
  1429. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1430. * @returns {Promise} Promise to be resolved with response data.
  1431. */
  1432. sendWithPromise:
  1433. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1434. var callbackId = this.callbackIndex++;
  1435. var message = {
  1436. action: actionName,
  1437. data: data,
  1438. callbackId: callbackId
  1439. };
  1440. var capability = createPromiseCapability();
  1441. this.callbacksCapabilities[callbackId] = capability;
  1442. try {
  1443. this.postMessage(message, transfers);
  1444. } catch (e) {
  1445. capability.reject(e);
  1446. }
  1447. return capability.promise;
  1448. },
  1449. /**
  1450. * Sends raw message to the comObj.
  1451. * @private
  1452. * @param message {Object} Raw message.
  1453. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1454. */
  1455. postMessage: function (message, transfers) {
  1456. if (transfers && this.postMessageTransfers) {
  1457. this.comObj.postMessage(message, transfers);
  1458. } else {
  1459. this.comObj.postMessage(message);
  1460. }
  1461. }
  1462. };
  1463. function loadJpegStream(id, imageUrl, objs) {
  1464. var img = new Image();
  1465. img.onload = (function loadJpegStream_onloadClosure() {
  1466. objs.resolve(id, img);
  1467. });
  1468. img.onerror = (function loadJpegStream_onerrorClosure() {
  1469. objs.resolve(id, null);
  1470. warn('Error during JPEG image loading');
  1471. });
  1472. img.src = imageUrl;
  1473. }
  1474. var NetworkManager = (function NetworkManagerClosure() {
  1475. var OK_RESPONSE = 200;
  1476. var PARTIAL_CONTENT_RESPONSE = 206;
  1477. function NetworkManager(url, args) {
  1478. this.url = url;
  1479. args = args || {};
  1480. this.isHttp = /^https?:/i.test(url);
  1481. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1482. this.withCredentials = args.withCredentials || false;
  1483. this.getXhr = args.getXhr ||
  1484. function NetworkManager_getXhr() {
  1485. return new XMLHttpRequest();
  1486. };
  1487. this.currXhrId = 0;
  1488. this.pendingRequests = {};
  1489. this.loadedRequests = {};
  1490. }
  1491. function getArrayBuffer(xhr) {
  1492. var data = xhr.response;
  1493. if (typeof data !== 'string') {
  1494. return data;
  1495. }
  1496. var length = data.length;
  1497. var array = new Uint8Array(length);
  1498. for (var i = 0; i < length; i++) {
  1499. array[i] = data.charCodeAt(i) & 0xFF;
  1500. }
  1501. return array.buffer;
  1502. }
  1503. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1504. try {
  1505. var x = new XMLHttpRequest();
  1506. // Firefox 37- required .open() to be called before setting responseType.
  1507. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1508. // Even though the URL is not visited, .open() could fail if the URL is
  1509. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1510. // When this error occurs, this feature detection method will mistakenly
  1511. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1512. x.open('GET', 'https://example.com');
  1513. x.responseType = 'moz-chunked-arraybuffer';
  1514. return x.responseType === 'moz-chunked-arraybuffer';
  1515. } catch (e) {
  1516. return false;
  1517. }
  1518. })();
  1519. NetworkManager.prototype = {
  1520. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1521. var args = {
  1522. begin: begin,
  1523. end: end
  1524. };
  1525. for (var prop in listeners) {
  1526. args[prop] = listeners[prop];
  1527. }
  1528. return this.request(args);
  1529. },
  1530. requestFull: function NetworkManager_requestFull(listeners) {
  1531. return this.request(listeners);
  1532. },
  1533. request: function NetworkManager_request(args) {
  1534. var xhr = this.getXhr();
  1535. var xhrId = this.currXhrId++;
  1536. var pendingRequest = this.pendingRequests[xhrId] = {
  1537. xhr: xhr
  1538. };
  1539. xhr.open('GET', this.url);
  1540. xhr.withCredentials = this.withCredentials;
  1541. for (var property in this.httpHeaders) {
  1542. var value = this.httpHeaders[property];
  1543. if (typeof value === 'undefined') {
  1544. continue;
  1545. }
  1546. xhr.setRequestHeader(property, value);
  1547. }
  1548. if (this.isHttp && 'begin' in args && 'end' in args) {
  1549. var rangeStr = args.begin + '-' + (args.end - 1);
  1550. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1551. pendingRequest.expectedStatus = 206;
  1552. } else {
  1553. pendingRequest.expectedStatus = 200;
  1554. }
  1555. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1556. if (useMozChunkedLoading) {
  1557. xhr.responseType = 'moz-chunked-arraybuffer';
  1558. pendingRequest.onProgressiveData = args.onProgressiveData;
  1559. pendingRequest.mozChunked = true;
  1560. } else {
  1561. xhr.responseType = 'arraybuffer';
  1562. }
  1563. if (args.onError) {
  1564. xhr.onerror = function(evt) {
  1565. args.onError(xhr.status);
  1566. };
  1567. }
  1568. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1569. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1570. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1571. pendingRequest.onDone = args.onDone;
  1572. pendingRequest.onError = args.onError;
  1573. pendingRequest.onProgress = args.onProgress;
  1574. xhr.send(null);
  1575. return xhrId;
  1576. },
  1577. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1578. var pendingRequest = this.pendingRequests[xhrId];
  1579. if (!pendingRequest) {
  1580. // Maybe abortRequest was called...
  1581. return;
  1582. }
  1583. if (pendingRequest.mozChunked) {
  1584. var chunk = getArrayBuffer(pendingRequest.xhr);
  1585. pendingRequest.onProgressiveData(chunk);
  1586. }
  1587. var onProgress = pendingRequest.onProgress;
  1588. if (onProgress) {
  1589. onProgress(evt);
  1590. }
  1591. },
  1592. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1593. var pendingRequest = this.pendingRequests[xhrId];
  1594. if (!pendingRequest) {
  1595. // Maybe abortRequest was called...
  1596. return;
  1597. }
  1598. var xhr = pendingRequest.xhr;
  1599. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1600. pendingRequest.onHeadersReceived();
  1601. delete pendingRequest.onHeadersReceived;
  1602. }
  1603. if (xhr.readyState !== 4) {
  1604. return;
  1605. }
  1606. if (!(xhrId in this.pendingRequests)) {
  1607. // The XHR request might have been aborted in onHeadersReceived()
  1608. // callback, in which case we should abort request
  1609. return;
  1610. }
  1611. delete this.pendingRequests[xhrId];
  1612. // success status == 0 can be on ftp, file and other protocols
  1613. if (xhr.status === 0 && this.isHttp) {
  1614. if (pendingRequest.onError) {
  1615. pendingRequest.onError(xhr.status);
  1616. }
  1617. return;
  1618. }
  1619. var xhrStatus = xhr.status || OK_RESPONSE;
  1620. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1621. // "A server MAY ignore the Range header". This means it's possible to
  1622. // get a 200 rather than a 206 response from a range request.
  1623. var ok_response_on_range_request =
  1624. xhrStatus === OK_RESPONSE &&
  1625. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1626. if (!ok_response_on_range_request &&
  1627. xhrStatus !== pendingRequest.expectedStatus) {
  1628. if (pendingRequest.onError) {
  1629. pendingRequest.onError(xhr.status);
  1630. }
  1631. return;
  1632. }
  1633. this.loadedRequests[xhrId] = true;
  1634. var chunk = getArrayBuffer(xhr);
  1635. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1636. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1637. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1638. var begin = parseInt(matches[1], 10);
  1639. pendingRequest.onDone({
  1640. begin: begin,
  1641. chunk: chunk
  1642. });
  1643. } else if (pendingRequest.onProgressiveData) {
  1644. pendingRequest.onDone(null);
  1645. } else {
  1646. pendingRequest.onDone({
  1647. begin: 0,
  1648. chunk: chunk
  1649. });
  1650. }
  1651. },
  1652. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1653. for (var xhrId in this.pendingRequests) {
  1654. return true;
  1655. }
  1656. return false;
  1657. },
  1658. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1659. return this.pendingRequests[xhrId].xhr;
  1660. },
  1661. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1662. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1663. },
  1664. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1665. return xhrId in this.pendingRequests;
  1666. },
  1667. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1668. return xhrId in this.loadedRequests;
  1669. },
  1670. abortAllRequests: function NetworkManager_abortAllRequests() {
  1671. for (var xhrId in this.pendingRequests) {
  1672. this.abortRequest(xhrId | 0);
  1673. }
  1674. },
  1675. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1676. var xhr = this.pendingRequests[xhrId].xhr;
  1677. delete this.pendingRequests[xhrId];
  1678. xhr.abort();
  1679. }
  1680. };
  1681. return NetworkManager;
  1682. })();
  1683. var ChunkedStream = (function ChunkedStreamClosure() {
  1684. function ChunkedStream(length, chunkSize, manager) {
  1685. this.bytes = new Uint8Array(length);
  1686. this.start = 0;
  1687. this.pos = 0;
  1688. this.end = length;
  1689. this.chunkSize = chunkSize;
  1690. this.loadedChunks = [];
  1691. this.numChunksLoaded = 0;
  1692. this.numChunks = Math.ceil(length / chunkSize);
  1693. this.manager = manager;
  1694. this.progressiveDataLength = 0;
  1695. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1696. }
  1697. // required methods for a stream. if a particular stream does not
  1698. // implement these, an error should be thrown
  1699. ChunkedStream.prototype = {
  1700. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1701. var chunks = [];
  1702. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1703. if (!this.loadedChunks[chunk]) {
  1704. chunks.push(chunk);
  1705. }
  1706. }
  1707. return chunks;
  1708. },
  1709. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1710. return [this];
  1711. },
  1712. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1713. return this.numChunksLoaded === this.numChunks;
  1714. },
  1715. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1716. var end = begin + chunk.byteLength;
  1717. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1718. // Using this.length is inaccurate here since this.start can be moved
  1719. // See ChunkedStream.moveStart()
  1720. var length = this.bytes.length;
  1721. assert(end % this.chunkSize === 0 || end === length,
  1722. 'Bad end offset: ' + end);
  1723. this.bytes.set(new Uint8Array(chunk), begin);
  1724. var chunkSize = this.chunkSize;
  1725. var beginChunk = Math.floor(begin / chunkSize);
  1726. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1727. var curChunk;
  1728. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1729. if (!this.loadedChunks[curChunk]) {
  1730. this.loadedChunks[curChunk] = true;
  1731. ++this.numChunksLoaded;
  1732. }
  1733. }
  1734. },
  1735. onReceiveProgressiveData:
  1736. function ChunkedStream_onReceiveProgressiveData(data) {
  1737. var position = this.progressiveDataLength;
  1738. var beginChunk = Math.floor(position / this.chunkSize);
  1739. this.bytes.set(new Uint8Array(data), position);
  1740. position += data.byteLength;
  1741. this.progressiveDataLength = position;
  1742. var endChunk = position >= this.end ? this.numChunks :
  1743. Math.floor(position / this.chunkSize);
  1744. var curChunk;
  1745. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1746. if (!this.loadedChunks[curChunk]) {
  1747. this.loadedChunks[curChunk] = true;
  1748. ++this.numChunksLoaded;
  1749. }
  1750. }
  1751. },
  1752. ensureByte: function ChunkedStream_ensureByte(pos) {
  1753. var chunk = Math.floor(pos / this.chunkSize);
  1754. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1755. return;
  1756. }
  1757. if (!this.loadedChunks[chunk]) {
  1758. throw new MissingDataException(pos, pos + 1);
  1759. }
  1760. this.lastSuccessfulEnsureByteChunk = chunk;
  1761. },
  1762. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1763. if (begin >= end) {
  1764. return;
  1765. }
  1766. if (end <= this.progressiveDataLength) {
  1767. return;
  1768. }
  1769. var chunkSize = this.chunkSize;
  1770. var beginChunk = Math.floor(begin / chunkSize);
  1771. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1772. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1773. if (!this.loadedChunks[chunk]) {
  1774. throw new MissingDataException(begin, end);
  1775. }
  1776. }
  1777. },
  1778. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1779. var chunk, numChunks = this.numChunks;
  1780. for (var i = 0; i < numChunks; ++i) {
  1781. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  1782. if (!this.loadedChunks[chunk]) {
  1783. return chunk;
  1784. }
  1785. }
  1786. return null;
  1787. },
  1788. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1789. return !!this.loadedChunks[chunk];
  1790. },
  1791. get length() {
  1792. return this.end - this.start;
  1793. },
  1794. get isEmpty() {
  1795. return this.length === 0;
  1796. },
  1797. getByte: function ChunkedStream_getByte() {
  1798. var pos = this.pos;
  1799. if (pos >= this.end) {
  1800. return -1;
  1801. }
  1802. this.ensureByte(pos);
  1803. return this.bytes[this.pos++];
  1804. },
  1805. getUint16: function ChunkedStream_getUint16() {
  1806. var b0 = this.getByte();
  1807. var b1 = this.getByte();
  1808. if (b0 === -1 || b1 === -1) {
  1809. return -1;
  1810. }
  1811. return (b0 << 8) + b1;
  1812. },
  1813. getInt32: function ChunkedStream_getInt32() {
  1814. var b0 = this.getByte();
  1815. var b1 = this.getByte();
  1816. var b2 = this.getByte();
  1817. var b3 = this.getByte();
  1818. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1819. },
  1820. // returns subarray of original buffer
  1821. // should only be read
  1822. getBytes: function ChunkedStream_getBytes(length) {
  1823. var bytes = this.bytes;
  1824. var pos = this.pos;
  1825. var strEnd = this.end;
  1826. if (!length) {
  1827. this.ensureRange(pos, strEnd);
  1828. return bytes.subarray(pos, strEnd);
  1829. }
  1830. var end = pos + length;
  1831. if (end > strEnd) {
  1832. end = strEnd;
  1833. }
  1834. this.ensureRange(pos, end);
  1835. this.pos = end;
  1836. return bytes.subarray(pos, end);
  1837. },
  1838. peekByte: function ChunkedStream_peekByte() {
  1839. var peekedByte = this.getByte();
  1840. this.pos--;
  1841. return peekedByte;
  1842. },
  1843. peekBytes: function ChunkedStream_peekBytes(length) {
  1844. var bytes = this.getBytes(length);
  1845. this.pos -= bytes.length;
  1846. return bytes;
  1847. },
  1848. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1849. this.ensureRange(begin, end);
  1850. return this.bytes.subarray(begin, end);
  1851. },
  1852. skip: function ChunkedStream_skip(n) {
  1853. if (!n) {
  1854. n = 1;
  1855. }
  1856. this.pos += n;
  1857. },
  1858. reset: function ChunkedStream_reset() {
  1859. this.pos = this.start;
  1860. },
  1861. moveStart: function ChunkedStream_moveStart() {
  1862. this.start = this.pos;
  1863. },
  1864. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1865. this.ensureRange(start, start + length);
  1866. function ChunkedStreamSubstream() {}
  1867. ChunkedStreamSubstream.prototype = Object.create(this);
  1868. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1869. var chunkSize = this.chunkSize;
  1870. var beginChunk = Math.floor(this.start / chunkSize);
  1871. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1872. var missingChunks = [];
  1873. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1874. if (!this.loadedChunks[chunk]) {
  1875. missingChunks.push(chunk);
  1876. }
  1877. }
  1878. return missingChunks;
  1879. };
  1880. var subStream = new ChunkedStreamSubstream();
  1881. subStream.pos = subStream.start = start;
  1882. subStream.end = start + length || this.end;
  1883. subStream.dict = dict;
  1884. return subStream;
  1885. },
  1886. isStream: true
  1887. };
  1888. return ChunkedStream;
  1889. })();
  1890. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1891. function ChunkedStreamManager(length, chunkSize, url, args) {
  1892. this.stream = new ChunkedStream(length, chunkSize, this);
  1893. this.length = length;
  1894. this.chunkSize = chunkSize;
  1895. this.url = url;
  1896. this.disableAutoFetch = args.disableAutoFetch;
  1897. var msgHandler = this.msgHandler = args.msgHandler;
  1898. if (args.chunkedViewerLoading) {
  1899. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1900. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1901. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1902. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1903. };
  1904. } else {
  1905. var getXhr = function getXhr() {
  1906. return new XMLHttpRequest();
  1907. };
  1908. this.networkManager = new NetworkManager(this.url, {
  1909. getXhr: getXhr,
  1910. httpHeaders: args.httpHeaders,
  1911. withCredentials: args.withCredentials
  1912. });
  1913. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1914. this.networkManager.requestRange(begin, end, {
  1915. onDone: this.onReceiveData.bind(this),
  1916. onProgress: this.onProgress.bind(this)
  1917. });
  1918. };
  1919. }
  1920. this.currRequestId = 0;
  1921. this.chunksNeededByRequest = {};
  1922. this.requestsByChunk = {};
  1923. this.callbacksByRequest = {};
  1924. this.progressiveDataLength = 0;
  1925. this._loadedStreamCapability = createPromiseCapability();
  1926. if (args.initialData) {
  1927. this.onReceiveData({chunk: args.initialData});
  1928. }
  1929. }
  1930. ChunkedStreamManager.prototype = {
  1931. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1932. return this._loadedStreamCapability.promise;
  1933. },
  1934. // Get all the chunks that are not yet loaded and groups them into
  1935. // contiguous ranges to load in as few requests as possible
  1936. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1937. var missingChunks = this.stream.getMissingChunks();
  1938. this.requestChunks(missingChunks);
  1939. return this._loadedStreamCapability.promise;
  1940. },
  1941. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1942. callback) {
  1943. var requestId = this.currRequestId++;
  1944. var chunksNeeded;
  1945. var i, ii;
  1946. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1947. for (i = 0, ii = chunks.length; i < ii; i++) {
  1948. if (!this.stream.hasChunk(chunks[i])) {
  1949. chunksNeeded[chunks[i]] = true;
  1950. }
  1951. }
  1952. if (isEmptyObj(chunksNeeded)) {
  1953. if (callback) {
  1954. callback();
  1955. }
  1956. return;
  1957. }
  1958. this.callbacksByRequest[requestId] = callback;
  1959. var chunksToRequest = [];
  1960. for (var chunk in chunksNeeded) {
  1961. chunk = chunk | 0;
  1962. if (!(chunk in this.requestsByChunk)) {
  1963. this.requestsByChunk[chunk] = [];
  1964. chunksToRequest.push(chunk);
  1965. }
  1966. this.requestsByChunk[chunk].push(requestId);
  1967. }
  1968. if (!chunksToRequest.length) {
  1969. return;
  1970. }
  1971. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1972. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1973. var groupedChunk = groupedChunksToRequest[i];
  1974. var begin = groupedChunk.beginChunk * this.chunkSize;
  1975. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1976. this.sendRequest(begin, end);
  1977. }
  1978. },
  1979. getStream: function ChunkedStreamManager_getStream() {
  1980. return this.stream;
  1981. },
  1982. // Loads any chunks in the requested range that are not yet loaded
  1983. requestRange: function ChunkedStreamManager_requestRange(
  1984. begin, end, callback) {
  1985. end = Math.min(end, this.length);
  1986. var beginChunk = this.getBeginChunk(begin);
  1987. var endChunk = this.getEndChunk(end);
  1988. var chunks = [];
  1989. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1990. chunks.push(chunk);
  1991. }
  1992. this.requestChunks(chunks, callback);
  1993. },
  1994. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1995. callback) {
  1996. ranges = ranges || [];
  1997. var chunksToRequest = [];
  1998. for (var i = 0; i < ranges.length; i++) {
  1999. var beginChunk = this.getBeginChunk(ranges[i].begin);
  2000. var endChunk = this.getEndChunk(ranges[i].end);
  2001. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  2002. if (chunksToRequest.indexOf(chunk) < 0) {
  2003. chunksToRequest.push(chunk);
  2004. }
  2005. }
  2006. }
  2007. chunksToRequest.sort(function(a, b) { return a - b; });
  2008. this.requestChunks(chunksToRequest, callback);
  2009. },
  2010. // Groups a sorted array of chunks into as few contiguous larger
  2011. // chunks as possible
  2012. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  2013. var groupedChunks = [];
  2014. var beginChunk = -1;
  2015. var prevChunk = -1;
  2016. for (var i = 0; i < chunks.length; ++i) {
  2017. var chunk = chunks[i];
  2018. if (beginChunk < 0) {
  2019. beginChunk = chunk;
  2020. }
  2021. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  2022. groupedChunks.push({ beginChunk: beginChunk,
  2023. endChunk: prevChunk + 1 });
  2024. beginChunk = chunk;
  2025. }
  2026. if (i + 1 === chunks.length) {
  2027. groupedChunks.push({ beginChunk: beginChunk,
  2028. endChunk: chunk + 1 });
  2029. }
  2030. prevChunk = chunk;
  2031. }
  2032. return groupedChunks;
  2033. },
  2034. onProgress: function ChunkedStreamManager_onProgress(args) {
  2035. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2036. args.loaded);
  2037. this.msgHandler.send('DocProgress', {
  2038. loaded: bytesLoaded,
  2039. total: this.length
  2040. });
  2041. },
  2042. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2043. var chunk = args.chunk;
  2044. var isProgressive = args.begin === undefined;
  2045. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2046. var end = begin + chunk.byteLength;
  2047. var beginChunk = Math.floor(begin / this.chunkSize);
  2048. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2049. Math.ceil(end / this.chunkSize);
  2050. if (isProgressive) {
  2051. this.stream.onReceiveProgressiveData(chunk);
  2052. this.progressiveDataLength = end;
  2053. } else {
  2054. this.stream.onReceiveData(begin, chunk);
  2055. }
  2056. if (this.stream.allChunksLoaded()) {
  2057. this._loadedStreamCapability.resolve(this.stream);
  2058. }
  2059. var loadedRequests = [];
  2060. var i, requestId;
  2061. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2062. // The server might return more chunks than requested
  2063. var requestIds = this.requestsByChunk[chunk] || [];
  2064. delete this.requestsByChunk[chunk];
  2065. for (i = 0; i < requestIds.length; ++i) {
  2066. requestId = requestIds[i];
  2067. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2068. if (chunk in chunksNeeded) {
  2069. delete chunksNeeded[chunk];
  2070. }
  2071. if (!isEmptyObj(chunksNeeded)) {
  2072. continue;
  2073. }
  2074. loadedRequests.push(requestId);
  2075. }
  2076. }
  2077. // If there are no pending requests, automatically fetch the next
  2078. // unfetched chunk of the PDF
  2079. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2080. var nextEmptyChunk;
  2081. if (this.stream.numChunksLoaded === 1) {
  2082. // This is a special optimization so that after fetching the first
  2083. // chunk, rather than fetching the second chunk, we fetch the last
  2084. // chunk.
  2085. var lastChunk = this.stream.numChunks - 1;
  2086. if (!this.stream.hasChunk(lastChunk)) {
  2087. nextEmptyChunk = lastChunk;
  2088. }
  2089. } else {
  2090. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2091. }
  2092. if (isInt(nextEmptyChunk)) {
  2093. this.requestChunks([nextEmptyChunk]);
  2094. }
  2095. }
  2096. for (i = 0; i < loadedRequests.length; ++i) {
  2097. requestId = loadedRequests[i];
  2098. var callback = this.callbacksByRequest[requestId];
  2099. delete this.callbacksByRequest[requestId];
  2100. if (callback) {
  2101. callback();
  2102. }
  2103. }
  2104. this.msgHandler.send('DocProgress', {
  2105. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2106. total: this.length
  2107. });
  2108. },
  2109. onError: function ChunkedStreamManager_onError(err) {
  2110. this._loadedStreamCapability.reject(err);
  2111. },
  2112. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2113. var chunk = Math.floor(begin / this.chunkSize);
  2114. return chunk;
  2115. },
  2116. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2117. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2118. return chunk;
  2119. }
  2120. };
  2121. return ChunkedStreamManager;
  2122. })();
  2123. // The maximum number of bytes fetched per range request
  2124. var RANGE_CHUNK_SIZE = 65536;
  2125. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2126. var BasePdfManager = (function BasePdfManagerClosure() {
  2127. function BasePdfManager() {
  2128. throw new Error('Cannot initialize BaseManagerManager');
  2129. }
  2130. BasePdfManager.prototype = {
  2131. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2132. throw new NotImplementedException();
  2133. },
  2134. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2135. return this.ensure(this.pdfDocument, prop, args);
  2136. },
  2137. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2138. return this.ensure(this.pdfDocument.xref, prop, args);
  2139. },
  2140. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2141. return this.ensure(this.pdfDocument.catalog, prop, args);
  2142. },
  2143. getPage: function BasePdfManager_pagePage(pageIndex) {
  2144. return this.pdfDocument.getPage(pageIndex);
  2145. },
  2146. cleanup: function BasePdfManager_cleanup() {
  2147. return this.pdfDocument.cleanup();
  2148. },
  2149. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2150. return new NotImplementedException();
  2151. },
  2152. requestRange: function BasePdfManager_ensure(begin, end) {
  2153. return new NotImplementedException();
  2154. },
  2155. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2156. return new NotImplementedException();
  2157. },
  2158. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2159. return new NotImplementedException();
  2160. },
  2161. updatePassword: function BasePdfManager_updatePassword(password) {
  2162. this.pdfDocument.xref.password = this.password = password;
  2163. if (this._passwordChangedCapability) {
  2164. this._passwordChangedCapability.resolve();
  2165. }
  2166. },
  2167. passwordChanged: function BasePdfManager_passwordChanged() {
  2168. this._passwordChangedCapability = createPromiseCapability();
  2169. return this._passwordChangedCapability.promise;
  2170. },
  2171. terminate: function BasePdfManager_terminate() {
  2172. return new NotImplementedException();
  2173. }
  2174. };
  2175. return BasePdfManager;
  2176. })();
  2177. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2178. function LocalPdfManager(data, password) {
  2179. var stream = new Stream(data);
  2180. this.pdfDocument = new PDFDocument(this, stream, password);
  2181. this._loadedStreamCapability = createPromiseCapability();
  2182. this._loadedStreamCapability.resolve(stream);
  2183. }
  2184. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2185. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2186. LocalPdfManager.prototype.ensure =
  2187. function LocalPdfManager_ensure(obj, prop, args) {
  2188. return new Promise(function (resolve, reject) {
  2189. try {
  2190. var value = obj[prop];
  2191. var result;
  2192. if (typeof value === 'function') {
  2193. result = value.apply(obj, args);
  2194. } else {
  2195. result = value;
  2196. }
  2197. resolve(result);
  2198. } catch (e) {
  2199. reject(e);
  2200. }
  2201. });
  2202. };
  2203. LocalPdfManager.prototype.requestRange =
  2204. function LocalPdfManager_requestRange(begin, end) {
  2205. return Promise.resolve();
  2206. };
  2207. LocalPdfManager.prototype.requestLoadedStream =
  2208. function LocalPdfManager_requestLoadedStream() {
  2209. };
  2210. LocalPdfManager.prototype.onLoadedStream =
  2211. function LocalPdfManager_getLoadedStream() {
  2212. return this._loadedStreamCapability.promise;
  2213. };
  2214. LocalPdfManager.prototype.terminate =
  2215. function LocalPdfManager_terminate() {
  2216. return;
  2217. };
  2218. return LocalPdfManager;
  2219. })();
  2220. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2221. function NetworkPdfManager(args, msgHandler) {
  2222. this.msgHandler = msgHandler;
  2223. var params = {
  2224. msgHandler: msgHandler,
  2225. httpHeaders: args.httpHeaders,
  2226. withCredentials: args.withCredentials,
  2227. chunkedViewerLoading: args.chunkedViewerLoading,
  2228. disableAutoFetch: args.disableAutoFetch,
  2229. initialData: args.initialData
  2230. };
  2231. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2232. args.url, params);
  2233. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2234. args.password);
  2235. }
  2236. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2237. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2238. NetworkPdfManager.prototype.ensure =
  2239. function NetworkPdfManager_ensure(obj, prop, args) {
  2240. var pdfManager = this;
  2241. return new Promise(function (resolve, reject) {
  2242. function ensureHelper() {
  2243. try {
  2244. var result;
  2245. var value = obj[prop];
  2246. if (typeof value === 'function') {
  2247. result = value.apply(obj, args);
  2248. } else {
  2249. result = value;
  2250. }
  2251. resolve(result);
  2252. } catch(e) {
  2253. if (!(e instanceof MissingDataException)) {
  2254. reject(e);
  2255. return;
  2256. }
  2257. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2258. }
  2259. }
  2260. ensureHelper();
  2261. });
  2262. };
  2263. NetworkPdfManager.prototype.requestRange =
  2264. function NetworkPdfManager_requestRange(begin, end) {
  2265. return new Promise(function (resolve) {
  2266. this.streamManager.requestRange(begin, end, function() {
  2267. resolve();
  2268. });
  2269. }.bind(this));
  2270. };
  2271. NetworkPdfManager.prototype.requestLoadedStream =
  2272. function NetworkPdfManager_requestLoadedStream() {
  2273. this.streamManager.requestAllChunks();
  2274. };
  2275. NetworkPdfManager.prototype.sendProgressiveData =
  2276. function NetworkPdfManager_sendProgressiveData(chunk) {
  2277. this.streamManager.onReceiveData({ chunk: chunk });
  2278. };
  2279. NetworkPdfManager.prototype.onLoadedStream =
  2280. function NetworkPdfManager_getLoadedStream() {
  2281. return this.streamManager.onLoadedStream();
  2282. };
  2283. NetworkPdfManager.prototype.terminate =
  2284. function NetworkPdfManager_terminate() {
  2285. this.streamManager.networkManager.abortAllRequests();
  2286. };
  2287. return NetworkPdfManager;
  2288. })();
  2289. var Page = (function PageClosure() {
  2290. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2291. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2292. this.pdfManager = pdfManager;
  2293. this.pageIndex = pageIndex;
  2294. this.pageDict = pageDict;
  2295. this.xref = xref;
  2296. this.ref = ref;
  2297. this.fontCache = fontCache;
  2298. this.idCounters = {
  2299. obj: 0
  2300. };
  2301. this.resourcesPromise = null;
  2302. }
  2303. Page.prototype = {
  2304. getPageProp: function Page_getPageProp(key) {
  2305. return this.pageDict.get(key);
  2306. },
  2307. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  2308. var dict = this.pageDict, valueArray = null, loopCount = 0;
  2309. var MAX_LOOP_COUNT = 100;
  2310. // Always walk up the entire parent chain, to be able to find
  2311. // e.g. \Resources placed on multiple levels of the tree.
  2312. while (dict) {
  2313. var value = dict.get(key);
  2314. if (value) {
  2315. if (!valueArray) {
  2316. valueArray = [];
  2317. }
  2318. valueArray.push(value);
  2319. }
  2320. if (++loopCount > MAX_LOOP_COUNT) {
  2321. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  2322. break;
  2323. }
  2324. dict = dict.get('Parent');
  2325. }
  2326. if (!valueArray) {
  2327. return Dict.empty;
  2328. }
  2329. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  2330. loopCount > MAX_LOOP_COUNT) {
  2331. return valueArray[0];
  2332. }
  2333. return Dict.merge(this.xref, valueArray);
  2334. },
  2335. get content() {
  2336. return this.getPageProp('Contents');
  2337. },
  2338. get resources() {
  2339. // For robustness: The spec states that a \Resources entry has to be
  2340. // present, but can be empty. Some document omit it still, in this case
  2341. // we return an empty dictionary.
  2342. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  2343. },
  2344. get mediaBox() {
  2345. var obj = this.getInheritedPageProp('MediaBox');
  2346. // Reset invalid media box to letter size.
  2347. if (!isArray(obj) || obj.length !== 4) {
  2348. obj = LETTER_SIZE_MEDIABOX;
  2349. }
  2350. return shadow(this, 'mediaBox', obj);
  2351. },
  2352. get view() {
  2353. var mediaBox = this.mediaBox;
  2354. var cropBox = this.getInheritedPageProp('CropBox');
  2355. if (!isArray(cropBox) || cropBox.length !== 4) {
  2356. return shadow(this, 'view', mediaBox);
  2357. }
  2358. // From the spec, 6th ed., p.963:
  2359. // "The crop, bleed, trim, and art boxes should not ordinarily
  2360. // extend beyond the boundaries of the media box. If they do, they are
  2361. // effectively reduced to their intersection with the media box."
  2362. cropBox = Util.intersect(cropBox, mediaBox);
  2363. if (!cropBox) {
  2364. return shadow(this, 'view', mediaBox);
  2365. }
  2366. return shadow(this, 'view', cropBox);
  2367. },
  2368. get rotate() {
  2369. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2370. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2371. if (rotate % 90 !== 0) {
  2372. rotate = 0;
  2373. } else if (rotate >= 360) {
  2374. rotate = rotate % 360;
  2375. } else if (rotate < 0) {
  2376. // The spec doesn't cover negatives, assume its counterclockwise
  2377. // rotation. The following is the other implementation of modulo.
  2378. rotate = ((rotate % 360) + 360) % 360;
  2379. }
  2380. return shadow(this, 'rotate', rotate);
  2381. },
  2382. getContentStream: function Page_getContentStream() {
  2383. var content = this.content;
  2384. var stream;
  2385. if (isArray(content)) {
  2386. // fetching items
  2387. var xref = this.xref;
  2388. var i, n = content.length;
  2389. var streams = [];
  2390. for (i = 0; i < n; ++i) {
  2391. streams.push(xref.fetchIfRef(content[i]));
  2392. }
  2393. stream = new StreamsSequenceStream(streams);
  2394. } else if (isStream(content)) {
  2395. stream = content;
  2396. } else {
  2397. // replacing non-existent page content with empty one
  2398. stream = new NullStream();
  2399. }
  2400. return stream;
  2401. },
  2402. loadResources: function Page_loadResources(keys) {
  2403. if (!this.resourcesPromise) {
  2404. // TODO: add async getInheritedPageProp and remove this.
  2405. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2406. }
  2407. return this.resourcesPromise.then(function resourceSuccess() {
  2408. var objectLoader = new ObjectLoader(this.resources.map,
  2409. keys,
  2410. this.xref);
  2411. return objectLoader.load();
  2412. }.bind(this));
  2413. },
  2414. getOperatorList: function Page_getOperatorList(handler, intent) {
  2415. var self = this;
  2416. var pdfManager = this.pdfManager;
  2417. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2418. []);
  2419. var resourcesPromise = this.loadResources([
  2420. 'ExtGState',
  2421. 'ColorSpace',
  2422. 'Pattern',
  2423. 'Shading',
  2424. 'XObject',
  2425. 'Font'
  2426. // ProcSet
  2427. // Properties
  2428. ]);
  2429. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2430. handler, this.pageIndex,
  2431. 'p' + this.pageIndex + '_',
  2432. this.idCounters,
  2433. this.fontCache);
  2434. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2435. var pageListPromise = dataPromises.then(function(data) {
  2436. var contentStream = data[0];
  2437. var opList = new OperatorList(intent, handler, self.pageIndex);
  2438. handler.send('StartRenderPage', {
  2439. transparency: partialEvaluator.hasBlendModes(self.resources),
  2440. pageIndex: self.pageIndex,
  2441. intent: intent
  2442. });
  2443. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2444. opList).then(function () {
  2445. return opList;
  2446. });
  2447. });
  2448. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2449. return Promise.all([pageListPromise, annotationsPromise]).then(
  2450. function(datas) {
  2451. var pageOpList = datas[0];
  2452. var annotations = datas[1];
  2453. if (annotations.length === 0) {
  2454. pageOpList.flush(true);
  2455. return pageOpList;
  2456. }
  2457. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2458. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2459. return annotationsReadyPromise.then(function () {
  2460. pageOpList.flush(true);
  2461. return pageOpList;
  2462. });
  2463. });
  2464. },
  2465. extractTextContent: function Page_extractTextContent() {
  2466. var handler = {
  2467. on: function nullHandlerOn() {},
  2468. send: function nullHandlerSend() {}
  2469. };
  2470. var self = this;
  2471. var pdfManager = this.pdfManager;
  2472. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2473. []);
  2474. var resourcesPromise = this.loadResources([
  2475. 'ExtGState',
  2476. 'XObject',
  2477. 'Font'
  2478. ]);
  2479. var dataPromises = Promise.all([contentStreamPromise,
  2480. resourcesPromise]);
  2481. return dataPromises.then(function(data) {
  2482. var contentStream = data[0];
  2483. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2484. handler, self.pageIndex,
  2485. 'p' + self.pageIndex + '_',
  2486. self.idCounters,
  2487. self.fontCache);
  2488. return partialEvaluator.getTextContent(contentStream,
  2489. self.resources);
  2490. });
  2491. },
  2492. getAnnotationsData: function Page_getAnnotationsData() {
  2493. var annotations = this.annotations;
  2494. var annotationsData = [];
  2495. for (var i = 0, n = annotations.length; i < n; ++i) {
  2496. annotationsData.push(annotations[i].data);
  2497. }
  2498. return annotationsData;
  2499. },
  2500. get annotations() {
  2501. var annotations = [];
  2502. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  2503. var annotationFactory = new AnnotationFactory();
  2504. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2505. var annotationRef = annotationRefs[i];
  2506. var annotation = annotationFactory.create(this.xref, annotationRef);
  2507. if (annotation &&
  2508. (annotation.isViewable() || annotation.isPrintable())) {
  2509. annotations.push(annotation);
  2510. }
  2511. }
  2512. return shadow(this, 'annotations', annotations);
  2513. }
  2514. };
  2515. return Page;
  2516. })();
  2517. /**
  2518. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2519. * `PDFDoc`, this one doesn't have any job management code.
  2520. * Right now there exists one PDFDocument on the main thread + one object
  2521. * for each worker. If there is no worker support enabled, there are two
  2522. * `PDFDocument` objects on the main thread created.
  2523. */
  2524. var PDFDocument = (function PDFDocumentClosure() {
  2525. var FINGERPRINT_FIRST_BYTES = 1024;
  2526. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2527. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2528. function PDFDocument(pdfManager, arg, password) {
  2529. if (isStream(arg)) {
  2530. init.call(this, pdfManager, arg, password);
  2531. } else if (isArrayBuffer(arg)) {
  2532. init.call(this, pdfManager, new Stream(arg), password);
  2533. } else {
  2534. error('PDFDocument: Unknown argument type');
  2535. }
  2536. }
  2537. function init(pdfManager, stream, password) {
  2538. assert(stream.length > 0, 'stream must have data');
  2539. this.pdfManager = pdfManager;
  2540. this.stream = stream;
  2541. var xref = new XRef(this.stream, password, pdfManager);
  2542. this.xref = xref;
  2543. }
  2544. function find(stream, needle, limit, backwards) {
  2545. var pos = stream.pos;
  2546. var end = stream.end;
  2547. var strBuf = [];
  2548. if (pos + limit > end) {
  2549. limit = end - pos;
  2550. }
  2551. for (var n = 0; n < limit; ++n) {
  2552. strBuf.push(String.fromCharCode(stream.getByte()));
  2553. }
  2554. var str = strBuf.join('');
  2555. stream.pos = pos;
  2556. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2557. if (index === -1) {
  2558. return false; /* not found */
  2559. }
  2560. stream.pos += index;
  2561. return true; /* found */
  2562. }
  2563. var DocumentInfoValidators = {
  2564. get entries() {
  2565. // Lazily build this since all the validation functions below are not
  2566. // defined until after this file loads.
  2567. return shadow(this, 'entries', {
  2568. Title: isString,
  2569. Author: isString,
  2570. Subject: isString,
  2571. Keywords: isString,
  2572. Creator: isString,
  2573. Producer: isString,
  2574. CreationDate: isString,
  2575. ModDate: isString,
  2576. Trapped: isName
  2577. });
  2578. }
  2579. };
  2580. PDFDocument.prototype = {
  2581. parse: function PDFDocument_parse(recoveryMode) {
  2582. this.setup(recoveryMode);
  2583. var version = this.catalog.catDict.get('Version');
  2584. if (isName(version)) {
  2585. this.pdfFormatVersion = version.name;
  2586. }
  2587. try {
  2588. // checking if AcroForm is present
  2589. this.acroForm = this.catalog.catDict.get('AcroForm');
  2590. if (this.acroForm) {
  2591. this.xfa = this.acroForm.get('XFA');
  2592. var fields = this.acroForm.get('Fields');
  2593. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2594. !this.xfa) {
  2595. // no fields and no XFA -- not a form (?)
  2596. this.acroForm = null;
  2597. }
  2598. }
  2599. } catch (ex) {
  2600. info('Something wrong with AcroForm entry');
  2601. this.acroForm = null;
  2602. }
  2603. },
  2604. get linearization() {
  2605. var linearization = null;
  2606. if (this.stream.length) {
  2607. try {
  2608. linearization = Linearization.create(this.stream);
  2609. } catch (err) {
  2610. if (err instanceof MissingDataException) {
  2611. throw err;
  2612. }
  2613. info(err);
  2614. }
  2615. }
  2616. // shadow the prototype getter with a data property
  2617. return shadow(this, 'linearization', linearization);
  2618. },
  2619. get startXRef() {
  2620. var stream = this.stream;
  2621. var startXRef = 0;
  2622. var linearization = this.linearization;
  2623. if (linearization) {
  2624. // Find end of first obj.
  2625. stream.reset();
  2626. if (find(stream, 'endobj', 1024)) {
  2627. startXRef = stream.pos + 6;
  2628. }
  2629. } else {
  2630. // Find startxref by jumping backward from the end of the file.
  2631. var step = 1024;
  2632. var found = false, pos = stream.end;
  2633. while (!found && pos > 0) {
  2634. pos -= step - 'startxref'.length;
  2635. if (pos < 0) {
  2636. pos = 0;
  2637. }
  2638. stream.pos = pos;
  2639. found = find(stream, 'startxref', step, true);
  2640. }
  2641. if (found) {
  2642. stream.skip(9);
  2643. var ch;
  2644. do {
  2645. ch = stream.getByte();
  2646. } while (Lexer.isSpace(ch));
  2647. var str = '';
  2648. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2649. str += String.fromCharCode(ch);
  2650. ch = stream.getByte();
  2651. }
  2652. startXRef = parseInt(str, 10);
  2653. if (isNaN(startXRef)) {
  2654. startXRef = 0;
  2655. }
  2656. }
  2657. }
  2658. // shadow the prototype getter with a data property
  2659. return shadow(this, 'startXRef', startXRef);
  2660. },
  2661. get mainXRefEntriesOffset() {
  2662. var mainXRefEntriesOffset = 0;
  2663. var linearization = this.linearization;
  2664. if (linearization) {
  2665. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2666. }
  2667. // shadow the prototype getter with a data property
  2668. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2669. },
  2670. // Find the header, remove leading garbage and setup the stream
  2671. // starting from the header.
  2672. checkHeader: function PDFDocument_checkHeader() {
  2673. var stream = this.stream;
  2674. stream.reset();
  2675. if (find(stream, '%PDF-', 1024)) {
  2676. // Found the header, trim off any garbage before it.
  2677. stream.moveStart();
  2678. // Reading file format version
  2679. var MAX_VERSION_LENGTH = 12;
  2680. var version = '', ch;
  2681. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2682. if (version.length >= MAX_VERSION_LENGTH) {
  2683. break;
  2684. }
  2685. version += String.fromCharCode(ch);
  2686. }
  2687. if (!this.pdfFormatVersion) {
  2688. // removing "%PDF-"-prefix
  2689. this.pdfFormatVersion = version.substring(5);
  2690. }
  2691. return;
  2692. }
  2693. // May not be a PDF file, continue anyway.
  2694. },
  2695. parseStartXRef: function PDFDocument_parseStartXRef() {
  2696. var startXRef = this.startXRef;
  2697. this.xref.setStartXRef(startXRef);
  2698. },
  2699. setup: function PDFDocument_setup(recoveryMode) {
  2700. this.xref.parse(recoveryMode);
  2701. this.catalog = new Catalog(this.pdfManager, this.xref);
  2702. },
  2703. get numPages() {
  2704. var linearization = this.linearization;
  2705. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2706. // shadow the prototype getter
  2707. return shadow(this, 'numPages', num);
  2708. },
  2709. get documentInfo() {
  2710. var docInfo = {
  2711. PDFFormatVersion: this.pdfFormatVersion,
  2712. IsAcroFormPresent: !!this.acroForm,
  2713. IsXFAPresent: !!this.xfa
  2714. };
  2715. var infoDict;
  2716. try {
  2717. infoDict = this.xref.trailer.get('Info');
  2718. } catch (err) {
  2719. info('The document information dictionary is invalid.');
  2720. }
  2721. if (infoDict) {
  2722. var validEntries = DocumentInfoValidators.entries;
  2723. // Only fill the document info with valid entries from the spec.
  2724. for (var key in validEntries) {
  2725. if (infoDict.has(key)) {
  2726. var value = infoDict.get(key);
  2727. // Make sure the value conforms to the spec.
  2728. if (validEntries[key](value)) {
  2729. docInfo[key] = (typeof value !== 'string' ?
  2730. value : stringToPDFString(value));
  2731. } else {
  2732. info('Bad value in document info for "' + key + '"');
  2733. }
  2734. }
  2735. }
  2736. }
  2737. return shadow(this, 'documentInfo', docInfo);
  2738. },
  2739. get fingerprint() {
  2740. var xref = this.xref, hash, fileID = '';
  2741. var idArray = xref.trailer.get('ID');
  2742. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  2743. idArray[0] !== EMPTY_FINGERPRINT) {
  2744. hash = stringToBytes(idArray[0]);
  2745. } else {
  2746. if (this.stream.ensureRange) {
  2747. this.stream.ensureRange(0,
  2748. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2749. }
  2750. hash = calculateMD5(this.stream.bytes.subarray(0,
  2751. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2752. }
  2753. for (var i = 0, n = hash.length; i < n; i++) {
  2754. var hex = hash[i].toString(16);
  2755. fileID += hex.length === 1 ? '0' + hex : hex;
  2756. }
  2757. return shadow(this, 'fingerprint', fileID);
  2758. },
  2759. getPage: function PDFDocument_getPage(pageIndex) {
  2760. return this.catalog.getPage(pageIndex);
  2761. },
  2762. cleanup: function PDFDocument_cleanup() {
  2763. return this.catalog.cleanup();
  2764. }
  2765. };
  2766. return PDFDocument;
  2767. })();
  2768. var Name = (function NameClosure() {
  2769. function Name(name) {
  2770. this.name = name;
  2771. }
  2772. Name.prototype = {};
  2773. var nameCache = {};
  2774. Name.get = function Name_get(name) {
  2775. var nameValue = nameCache[name];
  2776. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2777. };
  2778. return Name;
  2779. })();
  2780. var Cmd = (function CmdClosure() {
  2781. function Cmd(cmd) {
  2782. this.cmd = cmd;
  2783. }
  2784. Cmd.prototype = {};
  2785. var cmdCache = {};
  2786. Cmd.get = function Cmd_get(cmd) {
  2787. var cmdValue = cmdCache[cmd];
  2788. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2789. };
  2790. return Cmd;
  2791. })();
  2792. var Dict = (function DictClosure() {
  2793. var nonSerializable = function nonSerializableClosure() {
  2794. return nonSerializable; // creating closure on some variable
  2795. };
  2796. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2797. 'Background': true,
  2798. 'ExtGState': true,
  2799. 'Halftone': true,
  2800. 'Layout': true,
  2801. 'Mask': true,
  2802. 'Pagination': true,
  2803. 'Printing': true
  2804. };
  2805. function isRecursionAllowedFor(dict) {
  2806. if (!isName(dict.Type)) {
  2807. return true;
  2808. }
  2809. var dictType = dict.Type.name;
  2810. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2811. }
  2812. // xref is optional
  2813. function Dict(xref) {
  2814. // Map should only be used internally, use functions below to access.
  2815. this.map = Object.create(null);
  2816. this.xref = xref;
  2817. this.objId = null;
  2818. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2819. }
  2820. Dict.prototype = {
  2821. assignXref: function Dict_assignXref(newXref) {
  2822. this.xref = newXref;
  2823. },
  2824. // automatically dereferences Ref objects
  2825. get: function Dict_get(key1, key2, key3) {
  2826. var value;
  2827. var xref = this.xref;
  2828. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2829. typeof key2 === 'undefined') {
  2830. return xref ? xref.fetchIfRef(value) : value;
  2831. }
  2832. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2833. typeof key3 === 'undefined') {
  2834. return xref ? xref.fetchIfRef(value) : value;
  2835. }
  2836. value = this.map[key3] || null;
  2837. return xref ? xref.fetchIfRef(value) : value;
  2838. },
  2839. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2840. getAsync: function Dict_getAsync(key1, key2, key3) {
  2841. var value;
  2842. var xref = this.xref;
  2843. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2844. typeof key2 === 'undefined') {
  2845. if (xref) {
  2846. return xref.fetchIfRefAsync(value);
  2847. }
  2848. return Promise.resolve(value);
  2849. }
  2850. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2851. typeof key3 === 'undefined') {
  2852. if (xref) {
  2853. return xref.fetchIfRefAsync(value);
  2854. }
  2855. return Promise.resolve(value);
  2856. }
  2857. value = this.map[key3] || null;
  2858. if (xref) {
  2859. return xref.fetchIfRefAsync(value);
  2860. }
  2861. return Promise.resolve(value);
  2862. },
  2863. // Same as get(), but dereferences all elements if the result is an Array.
  2864. getArray: function Dict_getArray(key1, key2, key3) {
  2865. var value = this.get(key1, key2, key3);
  2866. var xref = this.xref;
  2867. if (!isArray(value) || !xref) {
  2868. return value;
  2869. }
  2870. value = value.slice(); // Ensure that we don't modify the Dict data.
  2871. for (var i = 0, ii = value.length; i < ii; i++) {
  2872. if (!isRef(value[i])) {
  2873. continue;
  2874. }
  2875. value[i] = xref.fetch(value[i]);
  2876. }
  2877. return value;
  2878. },
  2879. // no dereferencing
  2880. getRaw: function Dict_getRaw(key) {
  2881. return this.map[key];
  2882. },
  2883. // creates new map and dereferences all Refs
  2884. getAll: function Dict_getAll() {
  2885. var all = Object.create(null);
  2886. var queue = null;
  2887. var key, obj;
  2888. for (key in this.map) {
  2889. obj = this.get(key);
  2890. if (obj instanceof Dict) {
  2891. if (isRecursionAllowedFor(obj)) {
  2892. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2893. } else {
  2894. all[key] = this.getRaw(key);
  2895. }
  2896. } else {
  2897. all[key] = obj;
  2898. }
  2899. }
  2900. if (!queue) {
  2901. return all;
  2902. }
  2903. // trying to take cyclic references into the account
  2904. var processed = Object.create(null);
  2905. while (queue.length > 0) {
  2906. var item = queue.shift();
  2907. var itemObj = item.obj;
  2908. var objId = itemObj.objId;
  2909. if (objId && objId in processed) {
  2910. item.target[item.key] = processed[objId];
  2911. continue;
  2912. }
  2913. var dereferenced = Object.create(null);
  2914. for (key in itemObj.map) {
  2915. obj = itemObj.get(key);
  2916. if (obj instanceof Dict) {
  2917. if (isRecursionAllowedFor(obj)) {
  2918. queue.push({target: dereferenced, key: key, obj: obj});
  2919. } else {
  2920. dereferenced[key] = itemObj.getRaw(key);
  2921. }
  2922. } else {
  2923. dereferenced[key] = obj;
  2924. }
  2925. }
  2926. if (objId) {
  2927. processed[objId] = dereferenced;
  2928. }
  2929. item.target[item.key] = dereferenced;
  2930. }
  2931. return all;
  2932. },
  2933. getKeys: function Dict_getKeys() {
  2934. return Object.keys(this.map);
  2935. },
  2936. set: function Dict_set(key, value) {
  2937. this.map[key] = value;
  2938. },
  2939. has: function Dict_has(key) {
  2940. return key in this.map;
  2941. },
  2942. forEach: function Dict_forEach(callback) {
  2943. for (var key in this.map) {
  2944. callback(key, this.get(key));
  2945. }
  2946. }
  2947. };
  2948. Dict.empty = new Dict(null);
  2949. Dict.merge = function Dict_merge(xref, dictArray) {
  2950. var mergedDict = new Dict(xref);
  2951. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  2952. var dict = dictArray[i];
  2953. if (!isDict(dict)) {
  2954. continue;
  2955. }
  2956. for (var keyName in dict.map) {
  2957. if (mergedDict.map[keyName]) {
  2958. continue;
  2959. }
  2960. mergedDict.map[keyName] = dict.map[keyName];
  2961. }
  2962. }
  2963. return mergedDict;
  2964. };
  2965. return Dict;
  2966. })();
  2967. var Ref = (function RefClosure() {
  2968. function Ref(num, gen) {
  2969. this.num = num;
  2970. this.gen = gen;
  2971. }
  2972. Ref.prototype = {
  2973. toString: function Ref_toString() {
  2974. // This function is hot, so we make the string as compact as possible.
  2975. // |this.gen| is almost always zero, so we treat that case specially.
  2976. var str = this.num + 'R';
  2977. if (this.gen !== 0) {
  2978. str += this.gen;
  2979. }
  2980. return str;
  2981. }
  2982. };
  2983. return Ref;
  2984. })();
  2985. // The reference is identified by number and generation.
  2986. // This structure stores only one instance of the reference.
  2987. var RefSet = (function RefSetClosure() {
  2988. function RefSet() {
  2989. this.dict = {};
  2990. }
  2991. RefSet.prototype = {
  2992. has: function RefSet_has(ref) {
  2993. return ref.toString() in this.dict;
  2994. },
  2995. put: function RefSet_put(ref) {
  2996. this.dict[ref.toString()] = true;
  2997. },
  2998. remove: function RefSet_remove(ref) {
  2999. delete this.dict[ref.toString()];
  3000. }
  3001. };
  3002. return RefSet;
  3003. })();
  3004. var RefSetCache = (function RefSetCacheClosure() {
  3005. function RefSetCache() {
  3006. this.dict = Object.create(null);
  3007. }
  3008. RefSetCache.prototype = {
  3009. get: function RefSetCache_get(ref) {
  3010. return this.dict[ref.toString()];
  3011. },
  3012. has: function RefSetCache_has(ref) {
  3013. return ref.toString() in this.dict;
  3014. },
  3015. put: function RefSetCache_put(ref, obj) {
  3016. this.dict[ref.toString()] = obj;
  3017. },
  3018. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  3019. this.dict[ref.toString()] = this.get(aliasRef);
  3020. },
  3021. forEach: function RefSetCache_forEach(fn, thisArg) {
  3022. for (var i in this.dict) {
  3023. fn.call(thisArg, this.dict[i]);
  3024. }
  3025. },
  3026. clear: function RefSetCache_clear() {
  3027. this.dict = Object.create(null);
  3028. }
  3029. };
  3030. return RefSetCache;
  3031. })();
  3032. var Catalog = (function CatalogClosure() {
  3033. function Catalog(pdfManager, xref) {
  3034. this.pdfManager = pdfManager;
  3035. this.xref = xref;
  3036. this.catDict = xref.getCatalogObj();
  3037. this.fontCache = new RefSetCache();
  3038. assert(isDict(this.catDict),
  3039. 'catalog object is not a dictionary');
  3040. this.pagePromises = [];
  3041. }
  3042. Catalog.prototype = {
  3043. get metadata() {
  3044. var streamRef = this.catDict.getRaw('Metadata');
  3045. if (!isRef(streamRef)) {
  3046. return shadow(this, 'metadata', null);
  3047. }
  3048. var encryptMetadata = (!this.xref.encrypt ? false :
  3049. this.xref.encrypt.encryptMetadata);
  3050. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  3051. var metadata;
  3052. if (stream && isDict(stream.dict)) {
  3053. var type = stream.dict.get('Type');
  3054. var subtype = stream.dict.get('Subtype');
  3055. if (isName(type) && isName(subtype) &&
  3056. type.name === 'Metadata' && subtype.name === 'XML') {
  3057. // XXX: This should examine the charset the XML document defines,
  3058. // however since there are currently no real means to decode
  3059. // arbitrary charsets, let's just hope that the author of the PDF
  3060. // was reasonable enough to stick with the XML default charset,
  3061. // which is UTF-8.
  3062. try {
  3063. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  3064. } catch (e) {
  3065. info('Skipping invalid metadata.');
  3066. }
  3067. }
  3068. }
  3069. return shadow(this, 'metadata', metadata);
  3070. },
  3071. get toplevelPagesDict() {
  3072. var pagesObj = this.catDict.get('Pages');
  3073. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3074. // shadow the prototype getter
  3075. return shadow(this, 'toplevelPagesDict', pagesObj);
  3076. },
  3077. get documentOutline() {
  3078. var obj = null;
  3079. try {
  3080. obj = this.readDocumentOutline();
  3081. } catch (ex) {
  3082. if (ex instanceof MissingDataException) {
  3083. throw ex;
  3084. }
  3085. warn('Unable to read document outline');
  3086. }
  3087. return shadow(this, 'documentOutline', obj);
  3088. },
  3089. readDocumentOutline: function Catalog_readDocumentOutline() {
  3090. var xref = this.xref;
  3091. var obj = this.catDict.get('Outlines');
  3092. var root = { items: [] };
  3093. if (isDict(obj)) {
  3094. obj = obj.getRaw('First');
  3095. var processed = new RefSet();
  3096. if (isRef(obj)) {
  3097. var queue = [{obj: obj, parent: root}];
  3098. // to avoid recursion keeping track of the items
  3099. // in the processed dictionary
  3100. processed.put(obj);
  3101. while (queue.length > 0) {
  3102. var i = queue.shift();
  3103. var outlineDict = xref.fetchIfRef(i.obj);
  3104. if (outlineDict === null) {
  3105. continue;
  3106. }
  3107. if (!outlineDict.has('Title')) {
  3108. error('Invalid outline item');
  3109. }
  3110. var dest = outlineDict.get('A');
  3111. if (dest) {
  3112. dest = dest.get('D');
  3113. } else if (outlineDict.has('Dest')) {
  3114. dest = outlineDict.getRaw('Dest');
  3115. if (isName(dest)) {
  3116. dest = dest.name;
  3117. }
  3118. }
  3119. var title = outlineDict.get('Title');
  3120. var outlineItem = {
  3121. dest: dest,
  3122. title: stringToPDFString(title),
  3123. color: outlineDict.get('C') || [0, 0, 0],
  3124. count: outlineDict.get('Count'),
  3125. bold: !!(outlineDict.get('F') & 2),
  3126. italic: !!(outlineDict.get('F') & 1),
  3127. items: []
  3128. };
  3129. i.parent.items.push(outlineItem);
  3130. obj = outlineDict.getRaw('First');
  3131. if (isRef(obj) && !processed.has(obj)) {
  3132. queue.push({obj: obj, parent: outlineItem});
  3133. processed.put(obj);
  3134. }
  3135. obj = outlineDict.getRaw('Next');
  3136. if (isRef(obj) && !processed.has(obj)) {
  3137. queue.push({obj: obj, parent: i.parent});
  3138. processed.put(obj);
  3139. }
  3140. }
  3141. }
  3142. }
  3143. return (root.items.length > 0 ? root.items : null);
  3144. },
  3145. get numPages() {
  3146. var obj = this.toplevelPagesDict.get('Count');
  3147. assert(
  3148. isInt(obj),
  3149. 'page count in top level pages object is not an integer'
  3150. );
  3151. // shadow the prototype getter
  3152. return shadow(this, 'num', obj);
  3153. },
  3154. get destinations() {
  3155. function fetchDestination(dest) {
  3156. return isDict(dest) ? dest.get('D') : dest;
  3157. }
  3158. var xref = this.xref;
  3159. var dests = {}, nameTreeRef, nameDictionaryRef;
  3160. var obj = this.catDict.get('Names');
  3161. if (obj && obj.has('Dests')) {
  3162. nameTreeRef = obj.getRaw('Dests');
  3163. } else if (this.catDict.has('Dests')) {
  3164. nameDictionaryRef = this.catDict.get('Dests');
  3165. }
  3166. if (nameDictionaryRef) {
  3167. // reading simple destination dictionary
  3168. obj = nameDictionaryRef;
  3169. obj.forEach(function catalogForEach(key, value) {
  3170. if (!value) {
  3171. return;
  3172. }
  3173. dests[key] = fetchDestination(value);
  3174. });
  3175. }
  3176. if (nameTreeRef) {
  3177. var nameTree = new NameTree(nameTreeRef, xref);
  3178. var names = nameTree.getAll();
  3179. for (var name in names) {
  3180. if (!names.hasOwnProperty(name)) {
  3181. continue;
  3182. }
  3183. dests[name] = fetchDestination(names[name]);
  3184. }
  3185. }
  3186. return shadow(this, 'destinations', dests);
  3187. },
  3188. getDestination: function Catalog_getDestination(destinationId) {
  3189. function fetchDestination(dest) {
  3190. return isDict(dest) ? dest.get('D') : dest;
  3191. }
  3192. var xref = this.xref;
  3193. var dest = null, nameTreeRef, nameDictionaryRef;
  3194. var obj = this.catDict.get('Names');
  3195. if (obj && obj.has('Dests')) {
  3196. nameTreeRef = obj.getRaw('Dests');
  3197. } else if (this.catDict.has('Dests')) {
  3198. nameDictionaryRef = this.catDict.get('Dests');
  3199. }
  3200. if (nameDictionaryRef) { // Simple destination dictionary.
  3201. var value = nameDictionaryRef.get(destinationId);
  3202. if (value) {
  3203. dest = fetchDestination(value);
  3204. }
  3205. }
  3206. if (nameTreeRef) {
  3207. var nameTree = new NameTree(nameTreeRef, xref);
  3208. dest = fetchDestination(nameTree.get(destinationId));
  3209. }
  3210. return dest;
  3211. },
  3212. get attachments() {
  3213. var xref = this.xref;
  3214. var attachments = null, nameTreeRef;
  3215. var obj = this.catDict.get('Names');
  3216. if (obj) {
  3217. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3218. }
  3219. if (nameTreeRef) {
  3220. var nameTree = new NameTree(nameTreeRef, xref);
  3221. var names = nameTree.getAll();
  3222. for (var name in names) {
  3223. if (!names.hasOwnProperty(name)) {
  3224. continue;
  3225. }
  3226. var fs = new FileSpec(names[name], xref);
  3227. if (!attachments) {
  3228. attachments = {};
  3229. }
  3230. attachments[stringToPDFString(name)] = fs.serializable;
  3231. }
  3232. }
  3233. return shadow(this, 'attachments', attachments);
  3234. },
  3235. get javaScript() {
  3236. var xref = this.xref;
  3237. var obj = this.catDict.get('Names');
  3238. var javaScript = [];
  3239. function appendIfJavaScriptDict(jsDict) {
  3240. var type = jsDict.get('S');
  3241. if (!isName(type) || type.name !== 'JavaScript') {
  3242. return;
  3243. }
  3244. var js = jsDict.get('JS');
  3245. if (isStream(js)) {
  3246. js = bytesToString(js.getBytes());
  3247. } else if (!isString(js)) {
  3248. return;
  3249. }
  3250. javaScript.push(stringToPDFString(js));
  3251. }
  3252. if (obj && obj.has('JavaScript')) {
  3253. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3254. var names = nameTree.getAll();
  3255. for (var name in names) {
  3256. if (!names.hasOwnProperty(name)) {
  3257. continue;
  3258. }
  3259. // We don't really use the JavaScript right now. This code is
  3260. // defensive so we don't cause errors on document load.
  3261. var jsDict = names[name];
  3262. if (isDict(jsDict)) {
  3263. appendIfJavaScriptDict(jsDict);
  3264. }
  3265. }
  3266. }
  3267. // Append OpenAction actions to javaScript array
  3268. var openactionDict = this.catDict.get('OpenAction');
  3269. if (isDict(openactionDict, 'Action')) {
  3270. var actionType = openactionDict.get('S');
  3271. if (isName(actionType) && actionType.name === 'Named') {
  3272. // The named Print action is not a part of the PDF 1.7 specification,
  3273. // but is supported by many PDF readers/writers (including Adobe's).
  3274. var action = openactionDict.get('N');
  3275. if (isName(action) && action.name === 'Print') {
  3276. javaScript.push('print({});');
  3277. }
  3278. } else {
  3279. appendIfJavaScriptDict(openactionDict);
  3280. }
  3281. }
  3282. return shadow(this, 'javaScript', javaScript);
  3283. },
  3284. cleanup: function Catalog_cleanup() {
  3285. var promises = [];
  3286. this.fontCache.forEach(function (promise) {
  3287. promises.push(promise);
  3288. });
  3289. return Promise.all(promises).then(function (translatedFonts) {
  3290. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3291. var font = translatedFonts[i].dict;
  3292. delete font.translated;
  3293. }
  3294. this.fontCache.clear();
  3295. }.bind(this));
  3296. },
  3297. getPage: function Catalog_getPage(pageIndex) {
  3298. if (!(pageIndex in this.pagePromises)) {
  3299. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3300. function (a) {
  3301. var dict = a[0];
  3302. var ref = a[1];
  3303. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3304. this.fontCache);
  3305. }.bind(this)
  3306. );
  3307. }
  3308. return this.pagePromises[pageIndex];
  3309. },
  3310. getPageDict: function Catalog_getPageDict(pageIndex) {
  3311. var capability = createPromiseCapability();
  3312. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3313. var currentPageIndex = 0;
  3314. var xref = this.xref;
  3315. var checkAllKids = false;
  3316. function next() {
  3317. while (nodesToVisit.length) {
  3318. var currentNode = nodesToVisit.pop();
  3319. if (isRef(currentNode)) {
  3320. xref.fetchAsync(currentNode).then(function (obj) {
  3321. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3322. if (pageIndex === currentPageIndex) {
  3323. capability.resolve([obj, currentNode]);
  3324. } else {
  3325. currentPageIndex++;
  3326. next();
  3327. }
  3328. return;
  3329. }
  3330. nodesToVisit.push(obj);
  3331. next();
  3332. }, capability.reject);
  3333. return;
  3334. }
  3335. // Must be a child page dictionary.
  3336. assert(
  3337. isDict(currentNode),
  3338. 'page dictionary kid reference points to wrong type of object'
  3339. );
  3340. var count = currentNode.get('Count');
  3341. // If the current node doesn't have any children, avoid getting stuck
  3342. // in an empty node further down in the tree (see issue5644.pdf).
  3343. if (count === 0) {
  3344. checkAllKids = true;
  3345. }
  3346. // Skip nodes where the page can't be.
  3347. if (currentPageIndex + count <= pageIndex) {
  3348. currentPageIndex += count;
  3349. continue;
  3350. }
  3351. var kids = currentNode.get('Kids');
  3352. assert(isArray(kids), 'page dictionary kids object is not an array');
  3353. if (!checkAllKids && count === kids.length) {
  3354. // Nodes that don't have the page have been skipped and this is the
  3355. // bottom of the tree which means the page requested must be a
  3356. // descendant of this pages node. Ideally we would just resolve the
  3357. // promise with the page ref here, but there is the case where more
  3358. // pages nodes could link to single a page (see issue 3666 pdf). To
  3359. // handle this push it back on the queue so if it is a pages node it
  3360. // will be descended into.
  3361. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3362. currentPageIndex = pageIndex;
  3363. continue;
  3364. } else {
  3365. for (var last = kids.length - 1; last >= 0; last--) {
  3366. nodesToVisit.push(kids[last]);
  3367. }
  3368. }
  3369. }
  3370. capability.reject('Page index ' + pageIndex + ' not found.');
  3371. }
  3372. next();
  3373. return capability.promise;
  3374. },
  3375. getPageIndex: function Catalog_getPageIndex(ref) {
  3376. // The page tree nodes have the count of all the leaves below them. To get
  3377. // how many pages are before we just have to walk up the tree and keep
  3378. // adding the count of siblings to the left of the node.
  3379. var xref = this.xref;
  3380. function pagesBeforeRef(kidRef) {
  3381. var total = 0;
  3382. var parentRef;
  3383. return xref.fetchAsync(kidRef).then(function (node) {
  3384. if (!node) {
  3385. return null;
  3386. }
  3387. parentRef = node.getRaw('Parent');
  3388. return node.getAsync('Parent');
  3389. }).then(function (parent) {
  3390. if (!parent) {
  3391. return null;
  3392. }
  3393. return parent.getAsync('Kids');
  3394. }).then(function (kids) {
  3395. if (!kids) {
  3396. return null;
  3397. }
  3398. var kidPromises = [];
  3399. var found = false;
  3400. for (var i = 0; i < kids.length; i++) {
  3401. var kid = kids[i];
  3402. assert(isRef(kid), 'kids must be a ref');
  3403. if (kid.num === kidRef.num) {
  3404. found = true;
  3405. break;
  3406. }
  3407. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3408. if (kid.has('Count')) {
  3409. var count = kid.get('Count');
  3410. total += count;
  3411. } else { // page leaf node
  3412. total++;
  3413. }
  3414. }));
  3415. }
  3416. if (!found) {
  3417. error('kid ref not found in parents kids');
  3418. }
  3419. return Promise.all(kidPromises).then(function () {
  3420. return [total, parentRef];
  3421. });
  3422. });
  3423. }
  3424. var total = 0;
  3425. function next(ref) {
  3426. return pagesBeforeRef(ref).then(function (args) {
  3427. if (!args) {
  3428. return total;
  3429. }
  3430. var count = args[0];
  3431. var parentRef = args[1];
  3432. total += count;
  3433. return next(parentRef);
  3434. });
  3435. }
  3436. return next(ref);
  3437. }
  3438. };
  3439. return Catalog;
  3440. })();
  3441. var XRef = (function XRefClosure() {
  3442. function XRef(stream, password) {
  3443. this.stream = stream;
  3444. this.entries = [];
  3445. this.xrefstms = {};
  3446. // prepare the XRef cache
  3447. this.cache = [];
  3448. this.password = password;
  3449. this.stats = {
  3450. streamTypes: [],
  3451. fontTypes: []
  3452. };
  3453. }
  3454. XRef.prototype = {
  3455. setStartXRef: function XRef_setStartXRef(startXRef) {
  3456. // Store the starting positions of xref tables as we process them
  3457. // so we can recover from missing data errors
  3458. this.startXRefQueue = [startXRef];
  3459. },
  3460. parse: function XRef_parse(recoveryMode) {
  3461. var trailerDict;
  3462. if (!recoveryMode) {
  3463. trailerDict = this.readXRef();
  3464. } else {
  3465. warn('Indexing all PDF objects');
  3466. trailerDict = this.indexObjects();
  3467. }
  3468. trailerDict.assignXref(this);
  3469. this.trailer = trailerDict;
  3470. var encrypt = trailerDict.get('Encrypt');
  3471. if (encrypt) {
  3472. var ids = trailerDict.get('ID');
  3473. var fileId = (ids && ids.length) ? ids[0] : '';
  3474. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3475. this.password);
  3476. }
  3477. // get the root dictionary (catalog) object
  3478. if (!(this.root = trailerDict.get('Root'))) {
  3479. error('Invalid root reference');
  3480. }
  3481. },
  3482. processXRefTable: function XRef_processXRefTable(parser) {
  3483. if (!('tableState' in this)) {
  3484. // Stores state of the table as we process it so we can resume
  3485. // from middle of table in case of missing data error
  3486. this.tableState = {
  3487. entryNum: 0,
  3488. streamPos: parser.lexer.stream.pos,
  3489. parserBuf1: parser.buf1,
  3490. parserBuf2: parser.buf2
  3491. };
  3492. }
  3493. var obj = this.readXRefTable(parser);
  3494. // Sanity check
  3495. if (!isCmd(obj, 'trailer')) {
  3496. error('Invalid XRef table: could not find trailer dictionary');
  3497. }
  3498. // Read trailer dictionary, e.g.
  3499. // trailer
  3500. // << /Size 22
  3501. // /Root 20R
  3502. // /Info 10R
  3503. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3504. // >>
  3505. // The parser goes through the entire stream << ... >> and provides
  3506. // a getter interface for the key-value table
  3507. var dict = parser.getObj();
  3508. // The pdflib PDF generator can generate a nested trailer dictionary
  3509. if (!isDict(dict) && dict.dict) {
  3510. dict = dict.dict;
  3511. }
  3512. if (!isDict(dict)) {
  3513. error('Invalid XRef table: could not parse trailer dictionary');
  3514. }
  3515. delete this.tableState;
  3516. return dict;
  3517. },
  3518. readXRefTable: function XRef_readXRefTable(parser) {
  3519. // Example of cross-reference table:
  3520. // xref
  3521. // 0 1 <-- subsection header (first obj #, obj count)
  3522. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3523. // 23 2 <-- subsection header ... and so on ...
  3524. // 0000025518 00002 n
  3525. // 0000025635 00000 n
  3526. // trailer
  3527. // ...
  3528. var stream = parser.lexer.stream;
  3529. var tableState = this.tableState;
  3530. stream.pos = tableState.streamPos;
  3531. parser.buf1 = tableState.parserBuf1;
  3532. parser.buf2 = tableState.parserBuf2;
  3533. // Outer loop is over subsection headers
  3534. var obj;
  3535. while (true) {
  3536. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3537. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3538. break;
  3539. }
  3540. tableState.firstEntryNum = obj;
  3541. tableState.entryCount = parser.getObj();
  3542. }
  3543. var first = tableState.firstEntryNum;
  3544. var count = tableState.entryCount;
  3545. if (!isInt(first) || !isInt(count)) {
  3546. error('Invalid XRef table: wrong types in subsection header');
  3547. }
  3548. // Inner loop is over objects themselves
  3549. for (var i = tableState.entryNum; i < count; i++) {
  3550. tableState.streamPos = stream.pos;
  3551. tableState.entryNum = i;
  3552. tableState.parserBuf1 = parser.buf1;
  3553. tableState.parserBuf2 = parser.buf2;
  3554. var entry = {};
  3555. entry.offset = parser.getObj();
  3556. entry.gen = parser.getObj();
  3557. var type = parser.getObj();
  3558. if (isCmd(type, 'f')) {
  3559. entry.free = true;
  3560. } else if (isCmd(type, 'n')) {
  3561. entry.uncompressed = true;
  3562. }
  3563. // Validate entry obj
  3564. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3565. !(entry.free || entry.uncompressed)) {
  3566. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3567. }
  3568. if (!this.entries[i + first]) {
  3569. this.entries[i + first] = entry;
  3570. }
  3571. }
  3572. tableState.entryNum = 0;
  3573. tableState.streamPos = stream.pos;
  3574. tableState.parserBuf1 = parser.buf1;
  3575. tableState.parserBuf2 = parser.buf2;
  3576. delete tableState.firstEntryNum;
  3577. delete tableState.entryCount;
  3578. }
  3579. // Per issue 3248: hp scanners generate bad XRef
  3580. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3581. // shifting the entries
  3582. this.entries.shift();
  3583. }
  3584. // Sanity check: as per spec, first object must be free
  3585. if (this.entries[0] && !this.entries[0].free) {
  3586. error('Invalid XRef table: unexpected first object');
  3587. }
  3588. return obj;
  3589. },
  3590. processXRefStream: function XRef_processXRefStream(stream) {
  3591. if (!('streamState' in this)) {
  3592. // Stores state of the stream as we process it so we can resume
  3593. // from middle of stream in case of missing data error
  3594. var streamParameters = stream.dict;
  3595. var byteWidths = streamParameters.get('W');
  3596. var range = streamParameters.get('Index');
  3597. if (!range) {
  3598. range = [0, streamParameters.get('Size')];
  3599. }
  3600. this.streamState = {
  3601. entryRanges: range,
  3602. byteWidths: byteWidths,
  3603. entryNum: 0,
  3604. streamPos: stream.pos
  3605. };
  3606. }
  3607. this.readXRefStream(stream);
  3608. delete this.streamState;
  3609. return stream.dict;
  3610. },
  3611. readXRefStream: function XRef_readXRefStream(stream) {
  3612. var i, j;
  3613. var streamState = this.streamState;
  3614. stream.pos = streamState.streamPos;
  3615. var byteWidths = streamState.byteWidths;
  3616. var typeFieldWidth = byteWidths[0];
  3617. var offsetFieldWidth = byteWidths[1];
  3618. var generationFieldWidth = byteWidths[2];
  3619. var entryRanges = streamState.entryRanges;
  3620. while (entryRanges.length > 0) {
  3621. var first = entryRanges[0];
  3622. var n = entryRanges[1];
  3623. if (!isInt(first) || !isInt(n)) {
  3624. error('Invalid XRef range fields: ' + first + ', ' + n);
  3625. }
  3626. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3627. !isInt(generationFieldWidth)) {
  3628. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3629. }
  3630. for (i = streamState.entryNum; i < n; ++i) {
  3631. streamState.entryNum = i;
  3632. streamState.streamPos = stream.pos;
  3633. var type = 0, offset = 0, generation = 0;
  3634. for (j = 0; j < typeFieldWidth; ++j) {
  3635. type = (type << 8) | stream.getByte();
  3636. }
  3637. // if type field is absent, its default value is 1
  3638. if (typeFieldWidth === 0) {
  3639. type = 1;
  3640. }
  3641. for (j = 0; j < offsetFieldWidth; ++j) {
  3642. offset = (offset << 8) | stream.getByte();
  3643. }
  3644. for (j = 0; j < generationFieldWidth; ++j) {
  3645. generation = (generation << 8) | stream.getByte();
  3646. }
  3647. var entry = {};
  3648. entry.offset = offset;
  3649. entry.gen = generation;
  3650. switch (type) {
  3651. case 0:
  3652. entry.free = true;
  3653. break;
  3654. case 1:
  3655. entry.uncompressed = true;
  3656. break;
  3657. case 2:
  3658. break;
  3659. default:
  3660. error('Invalid XRef entry type: ' + type);
  3661. }
  3662. if (!this.entries[first + i]) {
  3663. this.entries[first + i] = entry;
  3664. }
  3665. }
  3666. streamState.entryNum = 0;
  3667. streamState.streamPos = stream.pos;
  3668. entryRanges.splice(0, 2);
  3669. }
  3670. },
  3671. indexObjects: function XRef_indexObjects() {
  3672. // Simple scan through the PDF content to find objects,
  3673. // trailers and XRef streams.
  3674. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  3675. var PERCENT = 0x25, LT = 0x3C;
  3676. function readToken(data, offset) {
  3677. var token = '', ch = data[offset];
  3678. while (ch !== LF && ch !== CR && ch !== LT) {
  3679. if (++offset >= data.length) {
  3680. break;
  3681. }
  3682. token += String.fromCharCode(ch);
  3683. ch = data[offset];
  3684. }
  3685. return token;
  3686. }
  3687. function skipUntil(data, offset, what) {
  3688. var length = what.length, dataLength = data.length;
  3689. var skipped = 0;
  3690. // finding byte sequence
  3691. while (offset < dataLength) {
  3692. var i = 0;
  3693. while (i < length && data[offset + i] === what[i]) {
  3694. ++i;
  3695. }
  3696. if (i >= length) {
  3697. break; // sequence found
  3698. }
  3699. offset++;
  3700. skipped++;
  3701. }
  3702. return skipped;
  3703. }
  3704. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  3705. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3706. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3707. 101, 102]);
  3708. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3709. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3710. // Clear out any existing entries, since they may be bogus.
  3711. this.entries.length = 0;
  3712. var stream = this.stream;
  3713. stream.pos = 0;
  3714. var buffer = stream.getBytes();
  3715. var position = stream.start, length = buffer.length;
  3716. var trailers = [], xrefStms = [];
  3717. while (position < length) {
  3718. var ch = buffer[position];
  3719. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  3720. ++position;
  3721. continue;
  3722. }
  3723. if (ch === PERCENT) { // %-comment
  3724. do {
  3725. ++position;
  3726. if (position >= length) {
  3727. break;
  3728. }
  3729. ch = buffer[position];
  3730. } while (ch !== LF && ch !== CR);
  3731. continue;
  3732. }
  3733. var token = readToken(buffer, position);
  3734. var m;
  3735. if (token.indexOf('xref') === 0 &&
  3736. (token.length === 4 || /\s/.test(token[4]))) {
  3737. position += skipUntil(buffer, position, trailerBytes);
  3738. trailers.push(position);
  3739. position += skipUntil(buffer, position, startxrefBytes);
  3740. } else if ((m = objRegExp.exec(token))) {
  3741. if (typeof this.entries[m[1]] === 'undefined') {
  3742. this.entries[m[1]] = {
  3743. offset: position - stream.start,
  3744. gen: m[2] | 0,
  3745. uncompressed: true
  3746. };
  3747. }
  3748. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3749. var content = buffer.subarray(position, position + contentLength);
  3750. // checking XRef stream suspect
  3751. // (it shall have '/XRef' and next char is not a letter)
  3752. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3753. if (xrefTagOffset < contentLength &&
  3754. content[xrefTagOffset + 5] < 64) {
  3755. xrefStms.push(position - stream.start);
  3756. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  3757. }
  3758. position += contentLength;
  3759. } else if (token.indexOf('trailer') === 0 &&
  3760. (token.length === 7 || /\s/.test(token[7]))) {
  3761. trailers.push(position);
  3762. position += skipUntil(buffer, position, startxrefBytes);
  3763. } else {
  3764. position += token.length + 1;
  3765. }
  3766. }
  3767. // reading XRef streams
  3768. var i, ii;
  3769. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3770. this.startXRefQueue.push(xrefStms[i]);
  3771. this.readXRef(/* recoveryMode */ true);
  3772. }
  3773. // finding main trailer
  3774. var dict;
  3775. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3776. stream.pos = trailers[i];
  3777. var parser = new Parser(new Lexer(stream), true, this);
  3778. var obj = parser.getObj();
  3779. if (!isCmd(obj, 'trailer')) {
  3780. continue;
  3781. }
  3782. // read the trailer dictionary
  3783. if (!isDict(dict = parser.getObj())) {
  3784. continue;
  3785. }
  3786. // taking the first one with 'ID'
  3787. if (dict.has('ID')) {
  3788. return dict;
  3789. }
  3790. }
  3791. // no tailer with 'ID', taking last one (if exists)
  3792. if (dict) {
  3793. return dict;
  3794. }
  3795. // nothing helps
  3796. // calling error() would reject worker with an UnknownErrorException.
  3797. throw new InvalidPDFException('Invalid PDF structure');
  3798. },
  3799. readXRef: function XRef_readXRef(recoveryMode) {
  3800. var stream = this.stream;
  3801. try {
  3802. while (this.startXRefQueue.length) {
  3803. var startXRef = this.startXRefQueue[0];
  3804. stream.pos = startXRef + stream.start;
  3805. var parser = new Parser(new Lexer(stream), true, this);
  3806. var obj = parser.getObj();
  3807. var dict;
  3808. // Get dictionary
  3809. if (isCmd(obj, 'xref')) {
  3810. // Parse end-of-file XRef
  3811. dict = this.processXRefTable(parser);
  3812. if (!this.topDict) {
  3813. this.topDict = dict;
  3814. }
  3815. // Recursively get other XRefs 'XRefStm', if any
  3816. obj = dict.get('XRefStm');
  3817. if (isInt(obj)) {
  3818. var pos = obj;
  3819. // ignore previously loaded xref streams
  3820. // (possible infinite recursion)
  3821. if (!(pos in this.xrefstms)) {
  3822. this.xrefstms[pos] = 1;
  3823. this.startXRefQueue.push(pos);
  3824. }
  3825. }
  3826. } else if (isInt(obj)) {
  3827. // Parse in-stream XRef
  3828. if (!isInt(parser.getObj()) ||
  3829. !isCmd(parser.getObj(), 'obj') ||
  3830. !isStream(obj = parser.getObj())) {
  3831. error('Invalid XRef stream');
  3832. }
  3833. dict = this.processXRefStream(obj);
  3834. if (!this.topDict) {
  3835. this.topDict = dict;
  3836. }
  3837. if (!dict) {
  3838. error('Failed to read XRef stream');
  3839. }
  3840. } else {
  3841. error('Invalid XRef stream header');
  3842. }
  3843. // Recursively get previous dictionary, if any
  3844. obj = dict.get('Prev');
  3845. if (isInt(obj)) {
  3846. this.startXRefQueue.push(obj);
  3847. } else if (isRef(obj)) {
  3848. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3849. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3850. this.startXRefQueue.push(obj.num);
  3851. }
  3852. this.startXRefQueue.shift();
  3853. }
  3854. return this.topDict;
  3855. } catch (e) {
  3856. if (e instanceof MissingDataException) {
  3857. throw e;
  3858. }
  3859. info('(while reading XRef): ' + e);
  3860. }
  3861. if (recoveryMode) {
  3862. return;
  3863. }
  3864. throw new XRefParseException();
  3865. },
  3866. getEntry: function XRef_getEntry(i) {
  3867. var xrefEntry = this.entries[i];
  3868. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3869. return xrefEntry;
  3870. }
  3871. return null;
  3872. },
  3873. fetchIfRef: function XRef_fetchIfRef(obj) {
  3874. if (!isRef(obj)) {
  3875. return obj;
  3876. }
  3877. return this.fetch(obj);
  3878. },
  3879. fetch: function XRef_fetch(ref, suppressEncryption) {
  3880. assert(isRef(ref), 'ref object is not a reference');
  3881. var num = ref.num;
  3882. if (num in this.cache) {
  3883. var cacheEntry = this.cache[num];
  3884. return cacheEntry;
  3885. }
  3886. var xrefEntry = this.getEntry(num);
  3887. // the referenced entry can be free
  3888. if (xrefEntry === null) {
  3889. return (this.cache[num] = null);
  3890. }
  3891. if (xrefEntry.uncompressed) {
  3892. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3893. } else {
  3894. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3895. }
  3896. if (isDict(xrefEntry)){
  3897. xrefEntry.objId = ref.toString();
  3898. } else if (isStream(xrefEntry)) {
  3899. xrefEntry.dict.objId = ref.toString();
  3900. }
  3901. return xrefEntry;
  3902. },
  3903. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3904. suppressEncryption) {
  3905. var gen = ref.gen;
  3906. var num = ref.num;
  3907. if (xrefEntry.gen !== gen) {
  3908. error('inconsistent generation in XRef');
  3909. }
  3910. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3911. this.stream.start);
  3912. var parser = new Parser(new Lexer(stream), true, this);
  3913. var obj1 = parser.getObj();
  3914. var obj2 = parser.getObj();
  3915. var obj3 = parser.getObj();
  3916. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3917. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3918. !isCmd(obj3)) {
  3919. error('bad XRef entry');
  3920. }
  3921. if (!isCmd(obj3, 'obj')) {
  3922. // some bad PDFs use "obj1234" and really mean 1234
  3923. if (obj3.cmd.indexOf('obj') === 0) {
  3924. num = parseInt(obj3.cmd.substring(3), 10);
  3925. if (!isNaN(num)) {
  3926. return num;
  3927. }
  3928. }
  3929. error('bad XRef entry');
  3930. }
  3931. if (this.encrypt && !suppressEncryption) {
  3932. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3933. } else {
  3934. xrefEntry = parser.getObj();
  3935. }
  3936. if (!isStream(xrefEntry)) {
  3937. this.cache[num] = xrefEntry;
  3938. }
  3939. return xrefEntry;
  3940. },
  3941. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3942. suppressEncryption) {
  3943. var tableOffset = xrefEntry.offset;
  3944. var stream = this.fetch(new Ref(tableOffset, 0));
  3945. if (!isStream(stream)) {
  3946. error('bad ObjStm stream');
  3947. }
  3948. var first = stream.dict.get('First');
  3949. var n = stream.dict.get('N');
  3950. if (!isInt(first) || !isInt(n)) {
  3951. error('invalid first and n parameters for ObjStm stream');
  3952. }
  3953. var parser = new Parser(new Lexer(stream), false, this);
  3954. parser.allowStreams = true;
  3955. var i, entries = [], num, nums = [];
  3956. // read the object numbers to populate cache
  3957. for (i = 0; i < n; ++i) {
  3958. num = parser.getObj();
  3959. if (!isInt(num)) {
  3960. error('invalid object number in the ObjStm stream: ' + num);
  3961. }
  3962. nums.push(num);
  3963. var offset = parser.getObj();
  3964. if (!isInt(offset)) {
  3965. error('invalid object offset in the ObjStm stream: ' + offset);
  3966. }
  3967. }
  3968. // read stream objects for cache
  3969. for (i = 0; i < n; ++i) {
  3970. entries.push(parser.getObj());
  3971. num = nums[i];
  3972. var entry = this.entries[num];
  3973. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3974. this.cache[num] = entries[i];
  3975. }
  3976. }
  3977. xrefEntry = entries[xrefEntry.gen];
  3978. if (xrefEntry === undefined) {
  3979. error('bad XRef entry for compressed object');
  3980. }
  3981. return xrefEntry;
  3982. },
  3983. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3984. if (!isRef(obj)) {
  3985. return Promise.resolve(obj);
  3986. }
  3987. return this.fetchAsync(obj);
  3988. },
  3989. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3990. var streamManager = this.stream.manager;
  3991. var xref = this;
  3992. return new Promise(function tryFetch(resolve, reject) {
  3993. try {
  3994. resolve(xref.fetch(ref, suppressEncryption));
  3995. } catch (e) {
  3996. if (e instanceof MissingDataException) {
  3997. streamManager.requestRange(e.begin, e.end, function () {
  3998. tryFetch(resolve, reject);
  3999. });
  4000. return;
  4001. }
  4002. reject(e);
  4003. }
  4004. });
  4005. },
  4006. getCatalogObj: function XRef_getCatalogObj() {
  4007. return this.root;
  4008. }
  4009. };
  4010. return XRef;
  4011. })();
  4012. /**
  4013. * A NameTree is like a Dict but has some advantageous properties, see the
  4014. * spec (7.9.6) for more details.
  4015. * TODO: implement all the Dict functions and make this more efficent.
  4016. */
  4017. var NameTree = (function NameTreeClosure() {
  4018. function NameTree(root, xref) {
  4019. this.root = root;
  4020. this.xref = xref;
  4021. }
  4022. NameTree.prototype = {
  4023. getAll: function NameTree_getAll() {
  4024. var dict = {};
  4025. if (!this.root) {
  4026. return dict;
  4027. }
  4028. var xref = this.xref;
  4029. // reading name tree
  4030. var processed = new RefSet();
  4031. processed.put(this.root);
  4032. var queue = [this.root];
  4033. while (queue.length > 0) {
  4034. var i, n;
  4035. var obj = xref.fetchIfRef(queue.shift());
  4036. if (!isDict(obj)) {
  4037. continue;
  4038. }
  4039. if (obj.has('Kids')) {
  4040. var kids = obj.get('Kids');
  4041. for (i = 0, n = kids.length; i < n; i++) {
  4042. var kid = kids[i];
  4043. if (processed.has(kid)) {
  4044. error('invalid destinations');
  4045. }
  4046. queue.push(kid);
  4047. processed.put(kid);
  4048. }
  4049. continue;
  4050. }
  4051. var names = obj.get('Names');
  4052. if (names) {
  4053. for (i = 0, n = names.length; i < n; i += 2) {
  4054. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  4055. }
  4056. }
  4057. }
  4058. return dict;
  4059. },
  4060. get: function NameTree_get(destinationId) {
  4061. if (!this.root) {
  4062. return null;
  4063. }
  4064. var xref = this.xref;
  4065. var kidsOrNames = xref.fetchIfRef(this.root);
  4066. var loopCount = 0;
  4067. var MAX_NAMES_LEVELS = 10;
  4068. var l, r, m;
  4069. // Perform a binary search to quickly find the entry that
  4070. // contains the named destination we are looking for.
  4071. while (kidsOrNames.has('Kids')) {
  4072. loopCount++;
  4073. if (loopCount > MAX_NAMES_LEVELS) {
  4074. warn('Search depth limit for named destionations has been reached.');
  4075. return null;
  4076. }
  4077. var kids = kidsOrNames.get('Kids');
  4078. if (!isArray(kids)) {
  4079. return null;
  4080. }
  4081. l = 0;
  4082. r = kids.length - 1;
  4083. while (l <= r) {
  4084. m = (l + r) >> 1;
  4085. var kid = xref.fetchIfRef(kids[m]);
  4086. var limits = kid.get('Limits');
  4087. if (destinationId < xref.fetchIfRef(limits[0])) {
  4088. r = m - 1;
  4089. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  4090. l = m + 1;
  4091. } else {
  4092. kidsOrNames = xref.fetchIfRef(kids[m]);
  4093. break;
  4094. }
  4095. }
  4096. if (l > r) {
  4097. return null;
  4098. }
  4099. }
  4100. // If we get here, then we have found the right entry. Now
  4101. // go through the named destinations in the Named dictionary
  4102. // until we find the exact destination we're looking for.
  4103. var names = kidsOrNames.get('Names');
  4104. if (isArray(names)) {
  4105. // Perform a binary search to reduce the lookup time.
  4106. l = 0;
  4107. r = names.length - 2;
  4108. while (l <= r) {
  4109. // Check only even indices (0, 2, 4, ...) because the
  4110. // odd indices contain the actual D array.
  4111. m = (l + r) & ~1;
  4112. if (destinationId < xref.fetchIfRef(names[m])) {
  4113. r = m - 2;
  4114. } else if (destinationId > xref.fetchIfRef(names[m])) {
  4115. l = m + 2;
  4116. } else {
  4117. return xref.fetchIfRef(names[m + 1]);
  4118. }
  4119. }
  4120. }
  4121. return null;
  4122. }
  4123. };
  4124. return NameTree;
  4125. })();
  4126. /**
  4127. * "A PDF file can refer to the contents of another file by using a File
  4128. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4129. * NOTE: Only embedded files are supported (as part of the attachments support)
  4130. * TODO: support the 'URL' file system (with caching if !/V), portable
  4131. * collections attributes and related files (/RF)
  4132. */
  4133. var FileSpec = (function FileSpecClosure() {
  4134. function FileSpec(root, xref) {
  4135. if (!root || !isDict(root)) {
  4136. return;
  4137. }
  4138. this.xref = xref;
  4139. this.root = root;
  4140. if (root.has('FS')) {
  4141. this.fs = root.get('FS');
  4142. }
  4143. this.description = root.has('Desc') ?
  4144. stringToPDFString(root.get('Desc')) :
  4145. '';
  4146. if (root.has('RF')) {
  4147. warn('Related file specifications are not supported');
  4148. }
  4149. this.contentAvailable = true;
  4150. if (!root.has('EF')) {
  4151. this.contentAvailable = false;
  4152. warn('Non-embedded file specifications are not supported');
  4153. }
  4154. }
  4155. function pickPlatformItem(dict) {
  4156. // Look for the filename in this order:
  4157. // UF, F, Unix, Mac, DOS
  4158. if (dict.has('UF')) {
  4159. return dict.get('UF');
  4160. } else if (dict.has('F')) {
  4161. return dict.get('F');
  4162. } else if (dict.has('Unix')) {
  4163. return dict.get('Unix');
  4164. } else if (dict.has('Mac')) {
  4165. return dict.get('Mac');
  4166. } else if (dict.has('DOS')) {
  4167. return dict.get('DOS');
  4168. } else {
  4169. return null;
  4170. }
  4171. }
  4172. FileSpec.prototype = {
  4173. get filename() {
  4174. if (!this._filename && this.root) {
  4175. var filename = pickPlatformItem(this.root) || 'unnamed';
  4176. this._filename = stringToPDFString(filename).
  4177. replace(/\\\\/g, '\\').
  4178. replace(/\\\//g, '/').
  4179. replace(/\\/g, '/');
  4180. }
  4181. return this._filename;
  4182. },
  4183. get content() {
  4184. if (!this.contentAvailable) {
  4185. return null;
  4186. }
  4187. if (!this.contentRef && this.root) {
  4188. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4189. }
  4190. var content = null;
  4191. if (this.contentRef) {
  4192. var xref = this.xref;
  4193. var fileObj = xref.fetchIfRef(this.contentRef);
  4194. if (fileObj && isStream(fileObj)) {
  4195. content = fileObj.getBytes();
  4196. } else {
  4197. warn('Embedded file specification points to non-existing/invalid ' +
  4198. 'content');
  4199. }
  4200. } else {
  4201. warn('Embedded file specification does not have a content');
  4202. }
  4203. return content;
  4204. },
  4205. get serializable() {
  4206. return {
  4207. filename: this.filename,
  4208. content: this.content
  4209. };
  4210. }
  4211. };
  4212. return FileSpec;
  4213. })();
  4214. /**
  4215. * A helper for loading missing data in object graphs. It traverses the graph
  4216. * depth first and queues up any objects that have missing data. Once it has
  4217. * has traversed as many objects that are available it attempts to bundle the
  4218. * missing data requests and then resume from the nodes that weren't ready.
  4219. *
  4220. * NOTE: It provides protection from circular references by keeping track of
  4221. * of loaded references. However, you must be careful not to load any graphs
  4222. * that have references to the catalog or other pages since that will cause the
  4223. * entire PDF document object graph to be traversed.
  4224. */
  4225. var ObjectLoader = (function() {
  4226. function mayHaveChildren(value) {
  4227. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4228. }
  4229. function addChildren(node, nodesToVisit) {
  4230. var value;
  4231. if (isDict(node) || isStream(node)) {
  4232. var map;
  4233. if (isDict(node)) {
  4234. map = node.map;
  4235. } else {
  4236. map = node.dict.map;
  4237. }
  4238. for (var key in map) {
  4239. value = map[key];
  4240. if (mayHaveChildren(value)) {
  4241. nodesToVisit.push(value);
  4242. }
  4243. }
  4244. } else if (isArray(node)) {
  4245. for (var i = 0, ii = node.length; i < ii; i++) {
  4246. value = node[i];
  4247. if (mayHaveChildren(value)) {
  4248. nodesToVisit.push(value);
  4249. }
  4250. }
  4251. }
  4252. }
  4253. function ObjectLoader(obj, keys, xref) {
  4254. this.obj = obj;
  4255. this.keys = keys;
  4256. this.xref = xref;
  4257. this.refSet = null;
  4258. }
  4259. ObjectLoader.prototype = {
  4260. load: function ObjectLoader_load() {
  4261. var keys = this.keys;
  4262. this.capability = createPromiseCapability();
  4263. // Don't walk the graph if all the data is already loaded.
  4264. if (!(this.xref.stream instanceof ChunkedStream) ||
  4265. this.xref.stream.getMissingChunks().length === 0) {
  4266. this.capability.resolve();
  4267. return this.capability.promise;
  4268. }
  4269. this.refSet = new RefSet();
  4270. // Setup the initial nodes to visit.
  4271. var nodesToVisit = [];
  4272. for (var i = 0; i < keys.length; i++) {
  4273. nodesToVisit.push(this.obj[keys[i]]);
  4274. }
  4275. this.walk(nodesToVisit);
  4276. return this.capability.promise;
  4277. },
  4278. walk: function ObjectLoader_walk(nodesToVisit) {
  4279. var nodesToRevisit = [];
  4280. var pendingRequests = [];
  4281. // DFS walk of the object graph.
  4282. while (nodesToVisit.length) {
  4283. var currentNode = nodesToVisit.pop();
  4284. // Only references or chunked streams can cause missing data exceptions.
  4285. if (isRef(currentNode)) {
  4286. // Skip nodes that have already been visited.
  4287. if (this.refSet.has(currentNode)) {
  4288. continue;
  4289. }
  4290. try {
  4291. var ref = currentNode;
  4292. this.refSet.put(ref);
  4293. currentNode = this.xref.fetch(currentNode);
  4294. } catch (e) {
  4295. if (!(e instanceof MissingDataException)) {
  4296. throw e;
  4297. }
  4298. nodesToRevisit.push(currentNode);
  4299. pendingRequests.push({ begin: e.begin, end: e.end });
  4300. }
  4301. }
  4302. if (currentNode && currentNode.getBaseStreams) {
  4303. var baseStreams = currentNode.getBaseStreams();
  4304. var foundMissingData = false;
  4305. for (var i = 0; i < baseStreams.length; i++) {
  4306. var stream = baseStreams[i];
  4307. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4308. foundMissingData = true;
  4309. pendingRequests.push({
  4310. begin: stream.start,
  4311. end: stream.end
  4312. });
  4313. }
  4314. }
  4315. if (foundMissingData) {
  4316. nodesToRevisit.push(currentNode);
  4317. }
  4318. }
  4319. addChildren(currentNode, nodesToVisit);
  4320. }
  4321. if (pendingRequests.length) {
  4322. this.xref.stream.manager.requestRanges(pendingRequests,
  4323. function pendingRequestCallback() {
  4324. nodesToVisit = nodesToRevisit;
  4325. for (var i = 0; i < nodesToRevisit.length; i++) {
  4326. var node = nodesToRevisit[i];
  4327. // Remove any reference nodes from the currrent refset so they
  4328. // aren't skipped when we revist them.
  4329. if (isRef(node)) {
  4330. this.refSet.remove(node);
  4331. }
  4332. }
  4333. this.walk(nodesToVisit);
  4334. }.bind(this));
  4335. return;
  4336. }
  4337. // Everything is loaded.
  4338. this.refSet = null;
  4339. this.capability.resolve();
  4340. }
  4341. };
  4342. return ObjectLoader;
  4343. })();
  4344. var ISOAdobeCharset = [
  4345. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4346. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4347. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4348. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4349. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4350. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4351. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4352. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4353. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4354. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4355. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4356. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4357. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4358. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4359. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4360. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4361. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4362. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4363. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4364. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4365. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4366. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4367. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4368. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4369. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4370. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4371. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4372. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4373. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4374. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4375. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4376. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4377. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4378. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4379. ];
  4380. var ExpertCharset = [
  4381. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4382. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4383. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4384. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4385. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4386. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4387. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4388. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4389. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4390. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4391. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4392. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4393. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4394. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4395. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4396. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4397. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4398. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4399. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4400. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4401. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4402. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4403. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4404. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4405. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4406. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4407. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4408. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4409. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4410. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4411. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4412. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4413. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4414. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4415. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4416. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4417. 'Ydieresissmall'
  4418. ];
  4419. var ExpertSubsetCharset = [
  4420. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4421. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4422. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4423. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4424. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4425. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4426. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4427. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4428. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4429. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4430. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4431. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4432. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4433. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4434. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4435. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4436. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4437. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4438. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4439. 'periodinferior', 'commainferior'
  4440. ];
  4441. var DEFAULT_ICON_SIZE = 22; // px
  4442. /**
  4443. * @constructor
  4444. */
  4445. function AnnotationFactory() {}
  4446. AnnotationFactory.prototype = {
  4447. /**
  4448. * @param {XRef} xref
  4449. * @param {Object} ref
  4450. * @returns {Annotation}
  4451. */
  4452. create: function AnnotationFactory_create(xref, ref) {
  4453. var dict = xref.fetchIfRef(ref);
  4454. if (!isDict(dict)) {
  4455. return;
  4456. }
  4457. // Determine the annotation's subtype.
  4458. var subtype = dict.get('Subtype');
  4459. subtype = isName(subtype) ? subtype.name : '';
  4460. // Return the right annotation object based on the subtype and field type.
  4461. var parameters = {
  4462. dict: dict,
  4463. ref: ref
  4464. };
  4465. switch (subtype) {
  4466. case 'Link':
  4467. return new LinkAnnotation(parameters);
  4468. case 'Text':
  4469. return new TextAnnotation(parameters);
  4470. case 'Widget':
  4471. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4472. if (isName(fieldType) && fieldType.name === 'Tx') {
  4473. return new TextWidgetAnnotation(parameters);
  4474. }
  4475. return new WidgetAnnotation(parameters);
  4476. default:
  4477. warn('Unimplemented annotation type "' + subtype + '", ' +
  4478. 'falling back to base annotation');
  4479. return new Annotation(parameters);
  4480. }
  4481. }
  4482. };
  4483. var Annotation = (function AnnotationClosure() {
  4484. // 12.5.5: Algorithm: Appearance streams
  4485. function getTransformMatrix(rect, bbox, matrix) {
  4486. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4487. var minX = bounds[0];
  4488. var minY = bounds[1];
  4489. var maxX = bounds[2];
  4490. var maxY = bounds[3];
  4491. if (minX === maxX || minY === maxY) {
  4492. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4493. // just apply the transform for rect
  4494. return [1, 0, 0, 1, rect[0], rect[1]];
  4495. }
  4496. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4497. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4498. return [
  4499. xRatio,
  4500. 0,
  4501. 0,
  4502. yRatio,
  4503. rect[0] - minX * xRatio,
  4504. rect[1] - minY * yRatio
  4505. ];
  4506. }
  4507. function getDefaultAppearance(dict) {
  4508. var appearanceState = dict.get('AP');
  4509. if (!isDict(appearanceState)) {
  4510. return;
  4511. }
  4512. var appearance;
  4513. var appearances = appearanceState.get('N');
  4514. if (isDict(appearances)) {
  4515. var as = dict.get('AS');
  4516. if (as && appearances.has(as.name)) {
  4517. appearance = appearances.get(as.name);
  4518. }
  4519. } else {
  4520. appearance = appearances;
  4521. }
  4522. return appearance;
  4523. }
  4524. function Annotation(params) {
  4525. var dict = params.dict;
  4526. var data = this.data = {};
  4527. data.subtype = dict.get('Subtype').name;
  4528. data.annotationFlags = dict.get('F');
  4529. this.setRectangle(dict.get('Rect'));
  4530. data.rect = this.rectangle;
  4531. this.setColor(dict.get('C'));
  4532. data.color = this.color;
  4533. this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
  4534. this.setBorderStyle(dict);
  4535. this.appearance = getDefaultAppearance(dict);
  4536. data.hasAppearance = !!this.appearance;
  4537. data.id = params.ref.num;
  4538. }
  4539. Annotation.prototype = {
  4540. /**
  4541. * Set the rectangle.
  4542. *
  4543. * @public
  4544. * @memberof Annotation
  4545. * @param {Array} rectangle - The rectangle array with exactly four entries
  4546. */
  4547. setRectangle: function Annotation_setRectangle(rectangle) {
  4548. if (isArray(rectangle) && rectangle.length === 4) {
  4549. this.rectangle = Util.normalizeRect(rectangle);
  4550. } else {
  4551. this.rectangle = [0, 0, 0, 0];
  4552. }
  4553. },
  4554. /**
  4555. * Set the color and take care of color space conversion.
  4556. *
  4557. * @public
  4558. * @memberof Annotation
  4559. * @param {Array} color - The color array containing either 0
  4560. * (transparent), 1 (grayscale), 3 (RGB) or
  4561. * 4 (CMYK) elements
  4562. */
  4563. setColor: function Annotation_setColor(color) {
  4564. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  4565. if (!isArray(color)) {
  4566. this.color = rgbColor;
  4567. return;
  4568. }
  4569. switch (color.length) {
  4570. case 0: // Transparent, which we indicate with a null value
  4571. this.color = null;
  4572. break;
  4573. case 1: // Convert grayscale to RGB
  4574. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  4575. this.color = rgbColor;
  4576. break;
  4577. case 3: // Convert RGB percentages to RGB
  4578. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  4579. this.color = rgbColor;
  4580. break;
  4581. case 4: // Convert CMYK to RGB
  4582. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  4583. this.color = rgbColor;
  4584. break;
  4585. default:
  4586. this.color = rgbColor;
  4587. break;
  4588. }
  4589. },
  4590. /**
  4591. * Set the border style (as AnnotationBorderStyle object).
  4592. *
  4593. * @public
  4594. * @memberof Annotation
  4595. * @param {Dict} borderStyle - The border style dictionary
  4596. */
  4597. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  4598. if (!isDict(borderStyle)) {
  4599. return;
  4600. }
  4601. if (borderStyle.has('BS')) {
  4602. var dict = borderStyle.get('BS');
  4603. var dictType;
  4604. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  4605. dictType.name === 'Border')) {
  4606. this.borderStyle.setWidth(dict.get('W'));
  4607. this.borderStyle.setStyle(dict.get('S'));
  4608. this.borderStyle.setDashArray(dict.get('D'));
  4609. }
  4610. } else if (borderStyle.has('Border')) {
  4611. var array = borderStyle.get('Border');
  4612. if (isArray(array) && array.length >= 3) {
  4613. this.borderStyle.setHorizontalCornerRadius(array[0]);
  4614. this.borderStyle.setVerticalCornerRadius(array[1]);
  4615. this.borderStyle.setWidth(array[2]);
  4616. if (array.length === 4) { // Dash array available
  4617. this.borderStyle.setDashArray(array[3]);
  4618. }
  4619. }
  4620. } else {
  4621. // There are no border entries in the dictionary. According to the
  4622. // specification, we should draw a solid border of width 1 in that
  4623. // case, but Adobe Reader did not implement that part of the
  4624. // specification and instead draws no border at all, so we do the same.
  4625. // See also https://github.com/mozilla/pdf.js/issues/6179.
  4626. this.borderStyle.setWidth(0);
  4627. }
  4628. },
  4629. isInvisible: function Annotation_isInvisible() {
  4630. var data = this.data;
  4631. return !!(data &&
  4632. data.annotationFlags && // Default: not invisible
  4633. data.annotationFlags & 0x1); // Invisible
  4634. },
  4635. isViewable: function Annotation_isViewable() {
  4636. var data = this.data;
  4637. return !!(!this.isInvisible() &&
  4638. data &&
  4639. (!data.annotationFlags ||
  4640. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4641. data.rect); // rectangle is necessary
  4642. },
  4643. isPrintable: function Annotation_isPrintable() {
  4644. var data = this.data;
  4645. return !!(!this.isInvisible() &&
  4646. data &&
  4647. data.annotationFlags && // Default: not printable
  4648. data.annotationFlags & 0x4 && // Print
  4649. !(data.annotationFlags & 0x2) && // Hidden
  4650. data.rect); // rectangle is necessary
  4651. },
  4652. loadResources: function Annotation_loadResources(keys) {
  4653. return new Promise(function (resolve, reject) {
  4654. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4655. if (!resources) {
  4656. resolve();
  4657. return;
  4658. }
  4659. var objectLoader = new ObjectLoader(resources.map,
  4660. keys,
  4661. resources.xref);
  4662. objectLoader.load().then(function() {
  4663. resolve(resources);
  4664. }, reject);
  4665. }, reject);
  4666. }.bind(this));
  4667. },
  4668. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4669. if (!this.appearance) {
  4670. return Promise.resolve(new OperatorList());
  4671. }
  4672. var data = this.data;
  4673. var appearanceDict = this.appearance.dict;
  4674. var resourcesPromise = this.loadResources([
  4675. 'ExtGState',
  4676. 'ColorSpace',
  4677. 'Pattern',
  4678. 'Shading',
  4679. 'XObject',
  4680. 'Font'
  4681. // ProcSet
  4682. // Properties
  4683. ]);
  4684. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4685. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4686. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4687. var self = this;
  4688. return resourcesPromise.then(function(resources) {
  4689. var opList = new OperatorList();
  4690. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4691. return evaluator.getOperatorList(self.appearance, resources, opList).
  4692. then(function () {
  4693. opList.addOp(OPS.endAnnotation, []);
  4694. self.appearance.reset();
  4695. return opList;
  4696. });
  4697. });
  4698. }
  4699. };
  4700. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4701. annotations, opList, pdfManager, partialEvaluator, intent) {
  4702. function reject(e) {
  4703. annotationsReadyCapability.reject(e);
  4704. }
  4705. var annotationsReadyCapability = createPromiseCapability();
  4706. var annotationPromises = [];
  4707. for (var i = 0, n = annotations.length; i < n; ++i) {
  4708. if (intent === 'display' && annotations[i].isViewable() ||
  4709. intent === 'print' && annotations[i].isPrintable()) {
  4710. annotationPromises.push(
  4711. annotations[i].getOperatorList(partialEvaluator));
  4712. }
  4713. }
  4714. Promise.all(annotationPromises).then(function(datas) {
  4715. opList.addOp(OPS.beginAnnotations, []);
  4716. for (var i = 0, n = datas.length; i < n; ++i) {
  4717. var annotOpList = datas[i];
  4718. opList.addOpList(annotOpList);
  4719. }
  4720. opList.addOp(OPS.endAnnotations, []);
  4721. annotationsReadyCapability.resolve();
  4722. }, reject);
  4723. return annotationsReadyCapability.promise;
  4724. };
  4725. return Annotation;
  4726. })();
  4727. /**
  4728. * Contains all data regarding an annotation's border style.
  4729. *
  4730. * @class
  4731. */
  4732. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  4733. /**
  4734. * @constructor
  4735. * @private
  4736. */
  4737. function AnnotationBorderStyle() {
  4738. this.width = 1;
  4739. this.style = AnnotationBorderStyleType.SOLID;
  4740. this.dashArray = [3];
  4741. this.horizontalCornerRadius = 0;
  4742. this.verticalCornerRadius = 0;
  4743. }
  4744. AnnotationBorderStyle.prototype = {
  4745. /**
  4746. * Set the width.
  4747. *
  4748. * @public
  4749. * @memberof AnnotationBorderStyle
  4750. * @param {integer} width - The width
  4751. */
  4752. setWidth: function AnnotationBorderStyle_setWidth(width) {
  4753. if (width === (width | 0)) {
  4754. this.width = width;
  4755. }
  4756. },
  4757. /**
  4758. * Set the style.
  4759. *
  4760. * @public
  4761. * @memberof AnnotationBorderStyle
  4762. * @param {Object} style - The style object
  4763. * @see {@link shared/util.js}
  4764. */
  4765. setStyle: function AnnotationBorderStyle_setStyle(style) {
  4766. if (!style) {
  4767. return;
  4768. }
  4769. switch (style.name) {
  4770. case 'S':
  4771. this.style = AnnotationBorderStyleType.SOLID;
  4772. break;
  4773. case 'D':
  4774. this.style = AnnotationBorderStyleType.DASHED;
  4775. break;
  4776. case 'B':
  4777. this.style = AnnotationBorderStyleType.BEVELED;
  4778. break;
  4779. case 'I':
  4780. this.style = AnnotationBorderStyleType.INSET;
  4781. break;
  4782. case 'U':
  4783. this.style = AnnotationBorderStyleType.UNDERLINE;
  4784. break;
  4785. default:
  4786. break;
  4787. }
  4788. },
  4789. /**
  4790. * Set the dash array.
  4791. *
  4792. * @public
  4793. * @memberof AnnotationBorderStyle
  4794. * @param {Array} dashArray - The dash array with at least one element
  4795. */
  4796. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  4797. // We validate the dash array, but we do not use it because CSS does not
  4798. // allow us to change spacing of dashes. For more information, visit
  4799. // http://www.w3.org/TR/css3-background/#the-border-style.
  4800. if (isArray(dashArray) && dashArray.length > 0) {
  4801. // According to the PDF specification: the elements in a dashArray
  4802. // shall be numbers that are nonnegative and not all equal to zero.
  4803. var isValid = true;
  4804. var allZeros = true;
  4805. for (var i = 0, len = dashArray.length; i < len; i++) {
  4806. var element = dashArray[i];
  4807. var validNumber = (+element >= 0);
  4808. if (!validNumber) {
  4809. isValid = false;
  4810. break;
  4811. } else if (element > 0) {
  4812. allZeros = false;
  4813. }
  4814. }
  4815. if (isValid && !allZeros) {
  4816. this.dashArray = dashArray;
  4817. } else {
  4818. this.width = 0; // Adobe behavior when the array is invalid.
  4819. }
  4820. } else if (dashArray) {
  4821. this.width = 0; // Adobe behavior when the array is invalid.
  4822. }
  4823. },
  4824. /**
  4825. * Set the horizontal corner radius (from a Border dictionary).
  4826. *
  4827. * @public
  4828. * @memberof AnnotationBorderStyle
  4829. * @param {integer} radius - The horizontal corner radius
  4830. */
  4831. setHorizontalCornerRadius:
  4832. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  4833. if (radius === (radius | 0)) {
  4834. this.horizontalCornerRadius = radius;
  4835. }
  4836. },
  4837. /**
  4838. * Set the vertical corner radius (from a Border dictionary).
  4839. *
  4840. * @public
  4841. * @memberof AnnotationBorderStyle
  4842. * @param {integer} radius - The vertical corner radius
  4843. */
  4844. setVerticalCornerRadius:
  4845. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  4846. if (radius === (radius | 0)) {
  4847. this.verticalCornerRadius = radius;
  4848. }
  4849. }
  4850. };
  4851. return AnnotationBorderStyle;
  4852. })();
  4853. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4854. function WidgetAnnotation(params) {
  4855. Annotation.call(this, params);
  4856. var dict = params.dict;
  4857. var data = this.data;
  4858. data.fieldValue = stringToPDFString(
  4859. Util.getInheritableProperty(dict, 'V') || '');
  4860. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4861. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4862. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4863. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4864. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4865. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4866. // Building the full field name by collecting the field and
  4867. // its ancestors 'T' data and joining them using '.'.
  4868. var fieldName = [];
  4869. var namedItem = dict;
  4870. var ref = params.ref;
  4871. while (namedItem) {
  4872. var parent = namedItem.get('Parent');
  4873. var parentRef = namedItem.getRaw('Parent');
  4874. var name = namedItem.get('T');
  4875. if (name) {
  4876. fieldName.unshift(stringToPDFString(name));
  4877. } else if (parent && ref) {
  4878. // The field name is absent, that means more than one field
  4879. // with the same name may exist. Replacing the empty name
  4880. // with the '`' plus index in the parent's 'Kids' array.
  4881. // This is not in the PDF spec but necessary to id the
  4882. // the input controls.
  4883. var kids = parent.get('Kids');
  4884. var j, jj;
  4885. for (j = 0, jj = kids.length; j < jj; j++) {
  4886. var kidRef = kids[j];
  4887. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4888. break;
  4889. }
  4890. }
  4891. fieldName.unshift('`' + j);
  4892. }
  4893. namedItem = parent;
  4894. ref = parentRef;
  4895. }
  4896. data.fullName = fieldName.join('.');
  4897. }
  4898. var parent = Annotation.prototype;
  4899. Util.inherit(WidgetAnnotation, Annotation, {
  4900. isViewable: function WidgetAnnotation_isViewable() {
  4901. if (this.data.fieldType === 'Sig') {
  4902. warn('unimplemented annotation type: Widget signature');
  4903. return false;
  4904. }
  4905. return parent.isViewable.call(this);
  4906. }
  4907. });
  4908. return WidgetAnnotation;
  4909. })();
  4910. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4911. function TextWidgetAnnotation(params) {
  4912. WidgetAnnotation.call(this, params);
  4913. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4914. this.data.annotationType = AnnotationType.WIDGET;
  4915. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4916. }
  4917. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4918. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4919. if (this.appearance) {
  4920. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4921. }
  4922. var opList = new OperatorList();
  4923. var data = this.data;
  4924. // Even if there is an appearance stream, ignore it. This is the
  4925. // behaviour used by Adobe Reader.
  4926. if (!data.defaultAppearance) {
  4927. return Promise.resolve(opList);
  4928. }
  4929. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4930. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4931. then(function () {
  4932. return opList;
  4933. });
  4934. }
  4935. });
  4936. return TextWidgetAnnotation;
  4937. })();
  4938. var TextAnnotation = (function TextAnnotationClosure() {
  4939. function TextAnnotation(params) {
  4940. Annotation.call(this, params);
  4941. var dict = params.dict;
  4942. var data = this.data;
  4943. var content = dict.get('Contents');
  4944. var title = dict.get('T');
  4945. data.annotationType = AnnotationType.TEXT;
  4946. data.content = stringToPDFString(content || '');
  4947. data.title = stringToPDFString(title || '');
  4948. data.hasHtml = true;
  4949. if (data.hasAppearance) {
  4950. data.name = 'NoIcon';
  4951. } else {
  4952. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4953. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4954. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4955. }
  4956. if (dict.has('C')) {
  4957. data.hasBgColor = true;
  4958. }
  4959. }
  4960. Util.inherit(TextAnnotation, Annotation, { });
  4961. return TextAnnotation;
  4962. })();
  4963. var LinkAnnotation = (function LinkAnnotationClosure() {
  4964. function LinkAnnotation(params) {
  4965. Annotation.call(this, params);
  4966. var dict = params.dict;
  4967. var data = this.data;
  4968. data.annotationType = AnnotationType.LINK;
  4969. data.hasHtml = true;
  4970. var action = dict.get('A');
  4971. if (action && isDict(action)) {
  4972. var linkType = action.get('S').name;
  4973. if (linkType === 'URI') {
  4974. var url = action.get('URI');
  4975. if (isName(url)) {
  4976. // Some bad PDFs do not put parentheses around relative URLs.
  4977. url = '/' + url.name;
  4978. } else if (url) {
  4979. url = addDefaultProtocolToUrl(url);
  4980. }
  4981. // TODO: pdf spec mentions urls can be relative to a Base
  4982. // entry in the dictionary.
  4983. if (!isValidUrl(url, false)) {
  4984. url = '';
  4985. }
  4986. // According to ISO 32000-1:2008, section 12.6.4.7,
  4987. // URI should to be encoded in 7-bit ASCII.
  4988. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  4989. try {
  4990. data.url = stringToUTF8String(url);
  4991. } catch (e) {
  4992. // Fall back to a simple copy.
  4993. data.url = url;
  4994. }
  4995. } else if (linkType === 'GoTo') {
  4996. data.dest = action.get('D');
  4997. } else if (linkType === 'GoToR') {
  4998. var urlDict = action.get('F');
  4999. if (isDict(urlDict)) {
  5000. // We assume that the 'url' is a Filspec dictionary
  5001. // and fetch the url without checking any further
  5002. url = urlDict.get('F') || '';
  5003. }
  5004. // TODO: pdf reference says that GoToR
  5005. // can also have 'NewWindow' attribute
  5006. if (!isValidUrl(url, false)) {
  5007. url = '';
  5008. }
  5009. data.url = url;
  5010. data.dest = action.get('D');
  5011. } else if (linkType === 'Named') {
  5012. data.action = action.get('N').name;
  5013. } else {
  5014. warn('unrecognized link type: ' + linkType);
  5015. }
  5016. } else if (dict.has('Dest')) {
  5017. // simple destination link
  5018. var dest = dict.get('Dest');
  5019. data.dest = isName(dest) ? dest.name : dest;
  5020. }
  5021. }
  5022. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  5023. function addDefaultProtocolToUrl(url) {
  5024. if (url && url.indexOf('www.') === 0) {
  5025. return ('http://' + url);
  5026. }
  5027. return url;
  5028. }
  5029. Util.inherit(LinkAnnotation, Annotation, { });
  5030. return LinkAnnotation;
  5031. })();
  5032. var PDFFunction = (function PDFFunctionClosure() {
  5033. var CONSTRUCT_SAMPLED = 0;
  5034. var CONSTRUCT_INTERPOLATED = 2;
  5035. var CONSTRUCT_STICHED = 3;
  5036. var CONSTRUCT_POSTSCRIPT = 4;
  5037. return {
  5038. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  5039. str) {
  5040. var i, ii;
  5041. var length = 1;
  5042. for (i = 0, ii = size.length; i < ii; i++) {
  5043. length *= size[i];
  5044. }
  5045. length *= outputSize;
  5046. var array = new Array(length);
  5047. var codeSize = 0;
  5048. var codeBuf = 0;
  5049. // 32 is a valid bps so shifting won't work
  5050. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  5051. var strBytes = str.getBytes((length * bps + 7) / 8);
  5052. var strIdx = 0;
  5053. for (i = 0; i < length; i++) {
  5054. while (codeSize < bps) {
  5055. codeBuf <<= 8;
  5056. codeBuf |= strBytes[strIdx++];
  5057. codeSize += 8;
  5058. }
  5059. codeSize -= bps;
  5060. array[i] = (codeBuf >> codeSize) * sampleMul;
  5061. codeBuf &= (1 << codeSize) - 1;
  5062. }
  5063. return array;
  5064. },
  5065. getIR: function PDFFunction_getIR(xref, fn) {
  5066. var dict = fn.dict;
  5067. if (!dict) {
  5068. dict = fn;
  5069. }
  5070. var types = [this.constructSampled,
  5071. null,
  5072. this.constructInterpolated,
  5073. this.constructStiched,
  5074. this.constructPostScript];
  5075. var typeNum = dict.get('FunctionType');
  5076. var typeFn = types[typeNum];
  5077. if (!typeFn) {
  5078. error('Unknown type of function');
  5079. }
  5080. return typeFn.call(this, fn, dict, xref);
  5081. },
  5082. fromIR: function PDFFunction_fromIR(IR) {
  5083. var type = IR[0];
  5084. switch (type) {
  5085. case CONSTRUCT_SAMPLED:
  5086. return this.constructSampledFromIR(IR);
  5087. case CONSTRUCT_INTERPOLATED:
  5088. return this.constructInterpolatedFromIR(IR);
  5089. case CONSTRUCT_STICHED:
  5090. return this.constructStichedFromIR(IR);
  5091. //case CONSTRUCT_POSTSCRIPT:
  5092. default:
  5093. return this.constructPostScriptFromIR(IR);
  5094. }
  5095. },
  5096. parse: function PDFFunction_parse(xref, fn) {
  5097. var IR = this.getIR(xref, fn);
  5098. return this.fromIR(IR);
  5099. },
  5100. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  5101. if (!isArray(fnObj)) {
  5102. // not an array -- parsing as regular function
  5103. return this.parse(xref, fnObj);
  5104. }
  5105. var fnArray = [];
  5106. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  5107. var obj = xref.fetchIfRef(fnObj[j]);
  5108. fnArray.push(PDFFunction.parse(xref, obj));
  5109. }
  5110. return function (src, srcOffset, dest, destOffset) {
  5111. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  5112. fnArray[i](src, srcOffset, dest, destOffset + i);
  5113. }
  5114. };
  5115. },
  5116. constructSampled: function PDFFunction_constructSampled(str, dict) {
  5117. function toMultiArray(arr) {
  5118. var inputLength = arr.length;
  5119. var out = [];
  5120. var index = 0;
  5121. for (var i = 0; i < inputLength; i += 2) {
  5122. out[index] = [arr[i], arr[i + 1]];
  5123. ++index;
  5124. }
  5125. return out;
  5126. }
  5127. var domain = dict.get('Domain');
  5128. var range = dict.get('Range');
  5129. if (!domain || !range) {
  5130. error('No domain or range');
  5131. }
  5132. var inputSize = domain.length / 2;
  5133. var outputSize = range.length / 2;
  5134. domain = toMultiArray(domain);
  5135. range = toMultiArray(range);
  5136. var size = dict.get('Size');
  5137. var bps = dict.get('BitsPerSample');
  5138. var order = dict.get('Order') || 1;
  5139. if (order !== 1) {
  5140. // No description how cubic spline interpolation works in PDF32000:2008
  5141. // As in poppler, ignoring order, linear interpolation may work as good
  5142. info('No support for cubic spline interpolation: ' + order);
  5143. }
  5144. var encode = dict.get('Encode');
  5145. if (!encode) {
  5146. encode = [];
  5147. for (var i = 0; i < inputSize; ++i) {
  5148. encode.push(0);
  5149. encode.push(size[i] - 1);
  5150. }
  5151. }
  5152. encode = toMultiArray(encode);
  5153. var decode = dict.get('Decode');
  5154. if (!decode) {
  5155. decode = range;
  5156. } else {
  5157. decode = toMultiArray(decode);
  5158. }
  5159. var samples = this.getSampleArray(size, outputSize, bps, str);
  5160. return [
  5161. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  5162. outputSize, Math.pow(2, bps) - 1, range
  5163. ];
  5164. },
  5165. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  5166. // See chapter 3, page 109 of the PDF reference
  5167. function interpolate(x, xmin, xmax, ymin, ymax) {
  5168. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  5169. }
  5170. return function constructSampledFromIRResult(src, srcOffset,
  5171. dest, destOffset) {
  5172. // See chapter 3, page 110 of the PDF reference.
  5173. var m = IR[1];
  5174. var domain = IR[2];
  5175. var encode = IR[3];
  5176. var decode = IR[4];
  5177. var samples = IR[5];
  5178. var size = IR[6];
  5179. var n = IR[7];
  5180. //var mask = IR[8];
  5181. var range = IR[9];
  5182. // Building the cube vertices: its part and sample index
  5183. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  5184. var cubeVertices = 1 << m;
  5185. var cubeN = new Float64Array(cubeVertices);
  5186. var cubeVertex = new Uint32Array(cubeVertices);
  5187. var i, j;
  5188. for (j = 0; j < cubeVertices; j++) {
  5189. cubeN[j] = 1;
  5190. }
  5191. var k = n, pos = 1;
  5192. // Map x_i to y_j for 0 <= i < m using the sampled function.
  5193. for (i = 0; i < m; ++i) {
  5194. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  5195. var domain_2i = domain[i][0];
  5196. var domain_2i_1 = domain[i][1];
  5197. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  5198. domain_2i_1);
  5199. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  5200. // Encode_2i, Encode_2i+1)
  5201. var e = interpolate(xi, domain_2i, domain_2i_1,
  5202. encode[i][0], encode[i][1]);
  5203. // e_i' = min(max(e_i, 0), Size_i - 1)
  5204. var size_i = size[i];
  5205. e = Math.min(Math.max(e, 0), size_i - 1);
  5206. // Adjusting the cube: N and vertex sample index
  5207. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  5208. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  5209. var n1 = e - e0; // (e - e0) / (e1 - e0);
  5210. var offset0 = e0 * k;
  5211. var offset1 = offset0 + k; // e1 * k
  5212. for (j = 0; j < cubeVertices; j++) {
  5213. if (j & pos) {
  5214. cubeN[j] *= n1;
  5215. cubeVertex[j] += offset1;
  5216. } else {
  5217. cubeN[j] *= n0;
  5218. cubeVertex[j] += offset0;
  5219. }
  5220. }
  5221. k *= size_i;
  5222. pos <<= 1;
  5223. }
  5224. for (j = 0; j < n; ++j) {
  5225. // Sum all cube vertices' samples portions
  5226. var rj = 0;
  5227. for (i = 0; i < cubeVertices; i++) {
  5228. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5229. }
  5230. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5231. // Decode_2j, Decode_2j+1)
  5232. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5233. // y_j = min(max(r_j, range_2j), range_2j+1)
  5234. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5235. range[j][1]);
  5236. }
  5237. };
  5238. },
  5239. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5240. dict) {
  5241. var c0 = dict.get('C0') || [0];
  5242. var c1 = dict.get('C1') || [1];
  5243. var n = dict.get('N');
  5244. if (!isArray(c0) || !isArray(c1)) {
  5245. error('Illegal dictionary for interpolated function');
  5246. }
  5247. var length = c0.length;
  5248. var diff = [];
  5249. for (var i = 0; i < length; ++i) {
  5250. diff.push(c1[i] - c0[i]);
  5251. }
  5252. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5253. },
  5254. constructInterpolatedFromIR:
  5255. function PDFFunction_constructInterpolatedFromIR(IR) {
  5256. var c0 = IR[1];
  5257. var diff = IR[2];
  5258. var n = IR[3];
  5259. var length = diff.length;
  5260. return function constructInterpolatedFromIRResult(src, srcOffset,
  5261. dest, destOffset) {
  5262. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5263. for (var j = 0; j < length; ++j) {
  5264. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5265. }
  5266. };
  5267. },
  5268. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5269. var domain = dict.get('Domain');
  5270. if (!domain) {
  5271. error('No domain');
  5272. }
  5273. var inputSize = domain.length / 2;
  5274. if (inputSize !== 1) {
  5275. error('Bad domain for stiched function');
  5276. }
  5277. var fnRefs = dict.get('Functions');
  5278. var fns = [];
  5279. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5280. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5281. }
  5282. var bounds = dict.get('Bounds');
  5283. var encode = dict.get('Encode');
  5284. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5285. },
  5286. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5287. var domain = IR[1];
  5288. var bounds = IR[2];
  5289. var encode = IR[3];
  5290. var fnsIR = IR[4];
  5291. var fns = [];
  5292. var tmpBuf = new Float32Array(1);
  5293. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5294. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5295. }
  5296. return function constructStichedFromIRResult(src, srcOffset,
  5297. dest, destOffset) {
  5298. var clip = function constructStichedFromIRClip(v, min, max) {
  5299. if (v > max) {
  5300. v = max;
  5301. } else if (v < min) {
  5302. v = min;
  5303. }
  5304. return v;
  5305. };
  5306. // clip to domain
  5307. var v = clip(src[srcOffset], domain[0], domain[1]);
  5308. // calulate which bound the value is in
  5309. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5310. if (v < bounds[i]) {
  5311. break;
  5312. }
  5313. }
  5314. // encode value into domain of function
  5315. var dmin = domain[0];
  5316. if (i > 0) {
  5317. dmin = bounds[i - 1];
  5318. }
  5319. var dmax = domain[1];
  5320. if (i < bounds.length) {
  5321. dmax = bounds[i];
  5322. }
  5323. var rmin = encode[2 * i];
  5324. var rmax = encode[2 * i + 1];
  5325. // Prevent the value from becoming NaN as a result
  5326. // of division by zero (fixes issue6113.pdf).
  5327. tmpBuf[0] = dmin === dmax ? rmin :
  5328. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5329. // call the appropriate function
  5330. fns[i](tmpBuf, 0, dest, destOffset);
  5331. };
  5332. },
  5333. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5334. xref) {
  5335. var domain = dict.get('Domain');
  5336. var range = dict.get('Range');
  5337. if (!domain) {
  5338. error('No domain.');
  5339. }
  5340. if (!range) {
  5341. error('No range.');
  5342. }
  5343. var lexer = new PostScriptLexer(fn);
  5344. var parser = new PostScriptParser(lexer);
  5345. var code = parser.parse();
  5346. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5347. },
  5348. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5349. IR) {
  5350. var domain = IR[1];
  5351. var range = IR[2];
  5352. var code = IR[3];
  5353. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5354. if (compiled) {
  5355. // Compiled function consists of simple expressions such as addition,
  5356. // subtraction, Math.max, and also contains 'var' and 'return'
  5357. // statements. See the generation in the PostScriptCompiler below.
  5358. /*jshint -W054 */
  5359. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5360. }
  5361. info('Unable to compile PS function');
  5362. var numOutputs = range.length >> 1;
  5363. var numInputs = domain.length >> 1;
  5364. var evaluator = new PostScriptEvaluator(code);
  5365. // Cache the values for a big speed up, the cache size is limited though
  5366. // since the number of possible values can be huge from a PS function.
  5367. var cache = {};
  5368. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5369. // seen in our tests.
  5370. var MAX_CACHE_SIZE = 2048 * 4;
  5371. var cache_available = MAX_CACHE_SIZE;
  5372. var tmpBuf = new Float32Array(numInputs);
  5373. return function constructPostScriptFromIRResult(src, srcOffset,
  5374. dest, destOffset) {
  5375. var i, value;
  5376. var key = '';
  5377. var input = tmpBuf;
  5378. for (i = 0; i < numInputs; i++) {
  5379. value = src[srcOffset + i];
  5380. input[i] = value;
  5381. key += value + '_';
  5382. }
  5383. var cachedValue = cache[key];
  5384. if (cachedValue !== undefined) {
  5385. dest.set(cachedValue, destOffset);
  5386. return;
  5387. }
  5388. var output = new Float32Array(numOutputs);
  5389. var stack = evaluator.execute(input);
  5390. var stackIndex = stack.length - numOutputs;
  5391. for (i = 0; i < numOutputs; i++) {
  5392. value = stack[stackIndex + i];
  5393. var bound = range[i * 2];
  5394. if (value < bound) {
  5395. value = bound;
  5396. } else {
  5397. bound = range[i * 2 +1];
  5398. if (value > bound) {
  5399. value = bound;
  5400. }
  5401. }
  5402. output[i] = value;
  5403. }
  5404. if (cache_available > 0) {
  5405. cache_available--;
  5406. cache[key] = output;
  5407. }
  5408. dest.set(output, destOffset);
  5409. };
  5410. }
  5411. };
  5412. })();
  5413. function isPDFFunction(v) {
  5414. var fnDict;
  5415. if (typeof v !== 'object') {
  5416. return false;
  5417. } else if (isDict(v)) {
  5418. fnDict = v;
  5419. } else if (isStream(v)) {
  5420. fnDict = v.dict;
  5421. } else {
  5422. return false;
  5423. }
  5424. return fnDict.has('FunctionType');
  5425. }
  5426. var PostScriptStack = (function PostScriptStackClosure() {
  5427. var MAX_STACK_SIZE = 100;
  5428. function PostScriptStack(initialStack) {
  5429. this.stack = !initialStack ? [] :
  5430. Array.prototype.slice.call(initialStack, 0);
  5431. }
  5432. PostScriptStack.prototype = {
  5433. push: function PostScriptStack_push(value) {
  5434. if (this.stack.length >= MAX_STACK_SIZE) {
  5435. error('PostScript function stack overflow.');
  5436. }
  5437. this.stack.push(value);
  5438. },
  5439. pop: function PostScriptStack_pop() {
  5440. if (this.stack.length <= 0) {
  5441. error('PostScript function stack underflow.');
  5442. }
  5443. return this.stack.pop();
  5444. },
  5445. copy: function PostScriptStack_copy(n) {
  5446. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5447. error('PostScript function stack overflow.');
  5448. }
  5449. var stack = this.stack;
  5450. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5451. stack.push(stack[i]);
  5452. }
  5453. },
  5454. index: function PostScriptStack_index(n) {
  5455. this.push(this.stack[this.stack.length - n - 1]);
  5456. },
  5457. // rotate the last n stack elements p times
  5458. roll: function PostScriptStack_roll(n, p) {
  5459. var stack = this.stack;
  5460. var l = stack.length - n;
  5461. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5462. for (i = l, j = r; i < j; i++, j--) {
  5463. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5464. }
  5465. for (i = l, j = c - 1; i < j; i++, j--) {
  5466. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5467. }
  5468. for (i = c, j = r; i < j; i++, j--) {
  5469. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5470. }
  5471. }
  5472. };
  5473. return PostScriptStack;
  5474. })();
  5475. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5476. function PostScriptEvaluator(operators) {
  5477. this.operators = operators;
  5478. }
  5479. PostScriptEvaluator.prototype = {
  5480. execute: function PostScriptEvaluator_execute(initialStack) {
  5481. var stack = new PostScriptStack(initialStack);
  5482. var counter = 0;
  5483. var operators = this.operators;
  5484. var length = operators.length;
  5485. var operator, a, b;
  5486. while (counter < length) {
  5487. operator = operators[counter++];
  5488. if (typeof operator === 'number') {
  5489. // Operator is really an operand and should be pushed to the stack.
  5490. stack.push(operator);
  5491. continue;
  5492. }
  5493. switch (operator) {
  5494. // non standard ps operators
  5495. case 'jz': // jump if false
  5496. b = stack.pop();
  5497. a = stack.pop();
  5498. if (!a) {
  5499. counter = b;
  5500. }
  5501. break;
  5502. case 'j': // jump
  5503. a = stack.pop();
  5504. counter = a;
  5505. break;
  5506. // all ps operators in alphabetical order (excluding if/ifelse)
  5507. case 'abs':
  5508. a = stack.pop();
  5509. stack.push(Math.abs(a));
  5510. break;
  5511. case 'add':
  5512. b = stack.pop();
  5513. a = stack.pop();
  5514. stack.push(a + b);
  5515. break;
  5516. case 'and':
  5517. b = stack.pop();
  5518. a = stack.pop();
  5519. if (isBool(a) && isBool(b)) {
  5520. stack.push(a && b);
  5521. } else {
  5522. stack.push(a & b);
  5523. }
  5524. break;
  5525. case 'atan':
  5526. a = stack.pop();
  5527. stack.push(Math.atan(a));
  5528. break;
  5529. case 'bitshift':
  5530. b = stack.pop();
  5531. a = stack.pop();
  5532. if (a > 0) {
  5533. stack.push(a << b);
  5534. } else {
  5535. stack.push(a >> b);
  5536. }
  5537. break;
  5538. case 'ceiling':
  5539. a = stack.pop();
  5540. stack.push(Math.ceil(a));
  5541. break;
  5542. case 'copy':
  5543. a = stack.pop();
  5544. stack.copy(a);
  5545. break;
  5546. case 'cos':
  5547. a = stack.pop();
  5548. stack.push(Math.cos(a));
  5549. break;
  5550. case 'cvi':
  5551. a = stack.pop() | 0;
  5552. stack.push(a);
  5553. break;
  5554. case 'cvr':
  5555. // noop
  5556. break;
  5557. case 'div':
  5558. b = stack.pop();
  5559. a = stack.pop();
  5560. stack.push(a / b);
  5561. break;
  5562. case 'dup':
  5563. stack.copy(1);
  5564. break;
  5565. case 'eq':
  5566. b = stack.pop();
  5567. a = stack.pop();
  5568. stack.push(a === b);
  5569. break;
  5570. case 'exch':
  5571. stack.roll(2, 1);
  5572. break;
  5573. case 'exp':
  5574. b = stack.pop();
  5575. a = stack.pop();
  5576. stack.push(Math.pow(a, b));
  5577. break;
  5578. case 'false':
  5579. stack.push(false);
  5580. break;
  5581. case 'floor':
  5582. a = stack.pop();
  5583. stack.push(Math.floor(a));
  5584. break;
  5585. case 'ge':
  5586. b = stack.pop();
  5587. a = stack.pop();
  5588. stack.push(a >= b);
  5589. break;
  5590. case 'gt':
  5591. b = stack.pop();
  5592. a = stack.pop();
  5593. stack.push(a > b);
  5594. break;
  5595. case 'idiv':
  5596. b = stack.pop();
  5597. a = stack.pop();
  5598. stack.push((a / b) | 0);
  5599. break;
  5600. case 'index':
  5601. a = stack.pop();
  5602. stack.index(a);
  5603. break;
  5604. case 'le':
  5605. b = stack.pop();
  5606. a = stack.pop();
  5607. stack.push(a <= b);
  5608. break;
  5609. case 'ln':
  5610. a = stack.pop();
  5611. stack.push(Math.log(a));
  5612. break;
  5613. case 'log':
  5614. a = stack.pop();
  5615. stack.push(Math.log(a) / Math.LN10);
  5616. break;
  5617. case 'lt':
  5618. b = stack.pop();
  5619. a = stack.pop();
  5620. stack.push(a < b);
  5621. break;
  5622. case 'mod':
  5623. b = stack.pop();
  5624. a = stack.pop();
  5625. stack.push(a % b);
  5626. break;
  5627. case 'mul':
  5628. b = stack.pop();
  5629. a = stack.pop();
  5630. stack.push(a * b);
  5631. break;
  5632. case 'ne':
  5633. b = stack.pop();
  5634. a = stack.pop();
  5635. stack.push(a !== b);
  5636. break;
  5637. case 'neg':
  5638. a = stack.pop();
  5639. stack.push(-a);
  5640. break;
  5641. case 'not':
  5642. a = stack.pop();
  5643. if (isBool(a)) {
  5644. stack.push(!a);
  5645. } else {
  5646. stack.push(~a);
  5647. }
  5648. break;
  5649. case 'or':
  5650. b = stack.pop();
  5651. a = stack.pop();
  5652. if (isBool(a) && isBool(b)) {
  5653. stack.push(a || b);
  5654. } else {
  5655. stack.push(a | b);
  5656. }
  5657. break;
  5658. case 'pop':
  5659. stack.pop();
  5660. break;
  5661. case 'roll':
  5662. b = stack.pop();
  5663. a = stack.pop();
  5664. stack.roll(a, b);
  5665. break;
  5666. case 'round':
  5667. a = stack.pop();
  5668. stack.push(Math.round(a));
  5669. break;
  5670. case 'sin':
  5671. a = stack.pop();
  5672. stack.push(Math.sin(a));
  5673. break;
  5674. case 'sqrt':
  5675. a = stack.pop();
  5676. stack.push(Math.sqrt(a));
  5677. break;
  5678. case 'sub':
  5679. b = stack.pop();
  5680. a = stack.pop();
  5681. stack.push(a - b);
  5682. break;
  5683. case 'true':
  5684. stack.push(true);
  5685. break;
  5686. case 'truncate':
  5687. a = stack.pop();
  5688. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5689. stack.push(a);
  5690. break;
  5691. case 'xor':
  5692. b = stack.pop();
  5693. a = stack.pop();
  5694. if (isBool(a) && isBool(b)) {
  5695. stack.push(a !== b);
  5696. } else {
  5697. stack.push(a ^ b);
  5698. }
  5699. break;
  5700. default:
  5701. error('Unknown operator ' + operator);
  5702. break;
  5703. }
  5704. }
  5705. return stack.stack;
  5706. }
  5707. };
  5708. return PostScriptEvaluator;
  5709. })();
  5710. // Most of the PDFs functions consist of simple operations such as:
  5711. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5712. //
  5713. // We can compile most of such programs, and at the same moment, we can
  5714. // optimize some expressions using basic math properties. Keeping track of
  5715. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5716. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5717. function AstNode(type) {
  5718. this.type = type;
  5719. }
  5720. AstNode.prototype.visit = function (visitor) {
  5721. throw new Error('abstract method');
  5722. };
  5723. function AstArgument(index, min, max) {
  5724. AstNode.call(this, 'args');
  5725. this.index = index;
  5726. this.min = min;
  5727. this.max = max;
  5728. }
  5729. AstArgument.prototype = Object.create(AstNode.prototype);
  5730. AstArgument.prototype.visit = function (visitor) {
  5731. visitor.visitArgument(this);
  5732. };
  5733. function AstLiteral(number) {
  5734. AstNode.call(this, 'literal');
  5735. this.number = number;
  5736. this.min = number;
  5737. this.max = number;
  5738. }
  5739. AstLiteral.prototype = Object.create(AstNode.prototype);
  5740. AstLiteral.prototype.visit = function (visitor) {
  5741. visitor.visitLiteral(this);
  5742. };
  5743. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5744. AstNode.call(this, 'binary');
  5745. this.op = op;
  5746. this.arg1 = arg1;
  5747. this.arg2 = arg2;
  5748. this.min = min;
  5749. this.max = max;
  5750. }
  5751. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5752. AstBinaryOperation.prototype.visit = function (visitor) {
  5753. visitor.visitBinaryOperation(this);
  5754. };
  5755. function AstMin(arg, max) {
  5756. AstNode.call(this, 'max');
  5757. this.arg = arg;
  5758. this.min = arg.min;
  5759. this.max = max;
  5760. }
  5761. AstMin.prototype = Object.create(AstNode.prototype);
  5762. AstMin.prototype.visit = function (visitor) {
  5763. visitor.visitMin(this);
  5764. };
  5765. function AstVariable(index, min, max) {
  5766. AstNode.call(this, 'var');
  5767. this.index = index;
  5768. this.min = min;
  5769. this.max = max;
  5770. }
  5771. AstVariable.prototype = Object.create(AstNode.prototype);
  5772. AstVariable.prototype.visit = function (visitor) {
  5773. visitor.visitVariable(this);
  5774. };
  5775. function AstVariableDefinition(variable, arg) {
  5776. AstNode.call(this, 'definition');
  5777. this.variable = variable;
  5778. this.arg = arg;
  5779. }
  5780. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5781. AstVariableDefinition.prototype.visit = function (visitor) {
  5782. visitor.visitVariableDefinition(this);
  5783. };
  5784. function ExpressionBuilderVisitor() {
  5785. this.parts = [];
  5786. }
  5787. ExpressionBuilderVisitor.prototype = {
  5788. visitArgument: function (arg) {
  5789. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5790. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5791. },
  5792. visitVariable: function (variable) {
  5793. this.parts.push('v', variable.index);
  5794. },
  5795. visitLiteral: function (literal) {
  5796. this.parts.push(literal.number);
  5797. },
  5798. visitBinaryOperation: function (operation) {
  5799. this.parts.push('(');
  5800. operation.arg1.visit(this);
  5801. this.parts.push(' ', operation.op, ' ');
  5802. operation.arg2.visit(this);
  5803. this.parts.push(')');
  5804. },
  5805. visitVariableDefinition: function (definition) {
  5806. this.parts.push('var ');
  5807. definition.variable.visit(this);
  5808. this.parts.push(' = ');
  5809. definition.arg.visit(this);
  5810. this.parts.push(';');
  5811. },
  5812. visitMin: function (max) {
  5813. this.parts.push('Math.min(');
  5814. max.arg.visit(this);
  5815. this.parts.push(', ', max.max, ')');
  5816. },
  5817. toString: function () {
  5818. return this.parts.join('');
  5819. }
  5820. };
  5821. function buildAddOperation(num1, num2) {
  5822. if (num2.type === 'literal' && num2.number === 0) {
  5823. // optimization: second operand is 0
  5824. return num1;
  5825. }
  5826. if (num1.type === 'literal' && num1.number === 0) {
  5827. // optimization: first operand is 0
  5828. return num2;
  5829. }
  5830. if (num2.type === 'literal' && num1.type === 'literal') {
  5831. // optimization: operands operand are literals
  5832. return new AstLiteral(num1.number + num2.number);
  5833. }
  5834. return new AstBinaryOperation('+', num1, num2,
  5835. num1.min + num2.min, num1.max + num2.max);
  5836. }
  5837. function buildMulOperation(num1, num2) {
  5838. if (num2.type === 'literal') {
  5839. // optimization: second operands is a literal...
  5840. if (num2.number === 0) {
  5841. return new AstLiteral(0); // and it's 0
  5842. } else if (num2.number === 1) {
  5843. return num1; // and it's 1
  5844. } else if (num1.type === 'literal') {
  5845. // ... and first operands is a literal too
  5846. return new AstLiteral(num1.number * num2.number);
  5847. }
  5848. }
  5849. if (num1.type === 'literal') {
  5850. // optimization: first operands is a literal...
  5851. if (num1.number === 0) {
  5852. return new AstLiteral(0); // and it's 0
  5853. } else if (num1.number === 1) {
  5854. return num2; // and it's 1
  5855. }
  5856. }
  5857. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5858. num1.max * num2.min, num1.max * num2.max);
  5859. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5860. num1.max * num2.min, num1.max * num2.max);
  5861. return new AstBinaryOperation('*', num1, num2, min, max);
  5862. }
  5863. function buildSubOperation(num1, num2) {
  5864. if (num2.type === 'literal') {
  5865. // optimization: second operands is a literal...
  5866. if (num2.number === 0) {
  5867. return num1; // ... and it's 0
  5868. } else if (num1.type === 'literal') {
  5869. // ... and first operands is a literal too
  5870. return new AstLiteral(num1.number - num2.number);
  5871. }
  5872. }
  5873. if (num2.type === 'binary' && num2.op === '-' &&
  5874. num1.type === 'literal' && num1.number === 1 &&
  5875. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5876. // optimization for case: 1 - (1 - x)
  5877. return num2.arg2;
  5878. }
  5879. return new AstBinaryOperation('-', num1, num2,
  5880. num1.min - num2.max, num1.max - num2.min);
  5881. }
  5882. function buildMinOperation(num1, max) {
  5883. if (num1.min >= max) {
  5884. // optimization: num1 min value is not less than required max
  5885. return new AstLiteral(max); // just returning max
  5886. } else if (num1.max <= max) {
  5887. // optimization: num1 max value is not greater than required max
  5888. return num1; // just returning an argument
  5889. }
  5890. return new AstMin(num1, max);
  5891. }
  5892. function PostScriptCompiler() {}
  5893. PostScriptCompiler.prototype = {
  5894. compile: function PostScriptCompiler_compile(code, domain, range) {
  5895. var stack = [];
  5896. var i, ii;
  5897. var instructions = [];
  5898. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5899. var lastRegister = 0;
  5900. var n, j, min, max;
  5901. var num1, num2, ast1, ast2, tmpVar, item;
  5902. for (i = 0; i < inputSize; i++) {
  5903. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5904. }
  5905. for (i = 0, ii = code.length; i < ii; i++) {
  5906. item = code[i];
  5907. if (typeof item === 'number') {
  5908. stack.push(new AstLiteral(item));
  5909. continue;
  5910. }
  5911. switch (item) {
  5912. case 'add':
  5913. if (stack.length < 2) {
  5914. return null;
  5915. }
  5916. num2 = stack.pop();
  5917. num1 = stack.pop();
  5918. stack.push(buildAddOperation(num1, num2));
  5919. break;
  5920. case 'cvr':
  5921. if (stack.length < 1) {
  5922. return null;
  5923. }
  5924. break;
  5925. case 'mul':
  5926. if (stack.length < 2) {
  5927. return null;
  5928. }
  5929. num2 = stack.pop();
  5930. num1 = stack.pop();
  5931. stack.push(buildMulOperation(num1, num2));
  5932. break;
  5933. case 'sub':
  5934. if (stack.length < 2) {
  5935. return null;
  5936. }
  5937. num2 = stack.pop();
  5938. num1 = stack.pop();
  5939. stack.push(buildSubOperation(num1, num2));
  5940. break;
  5941. case 'exch':
  5942. if (stack.length < 2) {
  5943. return null;
  5944. }
  5945. ast1 = stack.pop(); ast2 = stack.pop();
  5946. stack.push(ast1, ast2);
  5947. break;
  5948. case 'pop':
  5949. if (stack.length < 1) {
  5950. return null;
  5951. }
  5952. stack.pop();
  5953. break;
  5954. case 'index':
  5955. if (stack.length < 1) {
  5956. return null;
  5957. }
  5958. num1 = stack.pop();
  5959. if (num1.type !== 'literal') {
  5960. return null;
  5961. }
  5962. n = num1.number;
  5963. if (n < 0 || (n|0) !== n || stack.length < n) {
  5964. return null;
  5965. }
  5966. ast1 = stack[stack.length - n - 1];
  5967. if (ast1.type === 'literal' || ast1.type === 'var') {
  5968. stack.push(ast1);
  5969. break;
  5970. }
  5971. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5972. stack[stack.length - n - 1] = tmpVar;
  5973. stack.push(tmpVar);
  5974. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5975. break;
  5976. case 'dup':
  5977. if (stack.length < 1) {
  5978. return null;
  5979. }
  5980. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5981. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5982. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5983. // special case of the commands sequence for the min operation
  5984. num1 = stack.pop();
  5985. stack.push(buildMinOperation(num1, code[i + 1]));
  5986. i += 6;
  5987. break;
  5988. }
  5989. ast1 = stack[stack.length - 1];
  5990. if (ast1.type === 'literal' || ast1.type === 'var') {
  5991. // we don't have to save into intermediate variable a literal or
  5992. // variable.
  5993. stack.push(ast1);
  5994. break;
  5995. }
  5996. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5997. stack[stack.length - 1] = tmpVar;
  5998. stack.push(tmpVar);
  5999. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  6000. break;
  6001. case 'roll':
  6002. if (stack.length < 2) {
  6003. return null;
  6004. }
  6005. num2 = stack.pop();
  6006. num1 = stack.pop();
  6007. if (num2.type !== 'literal' || num1.type !== 'literal') {
  6008. // both roll operands must be numbers
  6009. return null;
  6010. }
  6011. j = num2.number;
  6012. n = num1.number;
  6013. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  6014. // ... and integers
  6015. return null;
  6016. }
  6017. j = ((j % n) + n) % n;
  6018. if (j === 0) {
  6019. break; // just skipping -- there are nothing to rotate
  6020. }
  6021. Array.prototype.push.apply(stack,
  6022. stack.splice(stack.length - n, n - j));
  6023. break;
  6024. default:
  6025. return null; // unsupported operator
  6026. }
  6027. }
  6028. if (stack.length !== outputSize) {
  6029. return null;
  6030. }
  6031. var result = [];
  6032. instructions.forEach(function (instruction) {
  6033. var statementBuilder = new ExpressionBuilderVisitor();
  6034. instruction.visit(statementBuilder);
  6035. result.push(statementBuilder.toString());
  6036. });
  6037. stack.forEach(function (expr, i) {
  6038. var statementBuilder = new ExpressionBuilderVisitor();
  6039. expr.visit(statementBuilder);
  6040. var min = range[i * 2], max = range[i * 2 + 1];
  6041. var out = [statementBuilder.toString()];
  6042. if (min > expr.min) {
  6043. out.unshift('Math.max(', min, ', ');
  6044. out.push(')');
  6045. }
  6046. if (max < expr.max) {
  6047. out.unshift('Math.min(', max, ', ');
  6048. out.push(')');
  6049. }
  6050. out.unshift('dest[destOffset + ', i, '] = ');
  6051. out.push(';');
  6052. result.push(out.join(''));
  6053. });
  6054. return result.join('\n');
  6055. }
  6056. };
  6057. return PostScriptCompiler;
  6058. })();
  6059. var ColorSpace = (function ColorSpaceClosure() {
  6060. // Constructor should define this.numComps, this.defaultColor, this.name
  6061. function ColorSpace() {
  6062. error('should not call ColorSpace constructor');
  6063. }
  6064. ColorSpace.prototype = {
  6065. /**
  6066. * Converts the color value to the RGB color. The color components are
  6067. * located in the src array starting from the srcOffset. Returns the array
  6068. * of the rgb components, each value ranging from [0,255].
  6069. */
  6070. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  6071. var rgb = new Uint8Array(3);
  6072. this.getRgbItem(src, srcOffset, rgb, 0);
  6073. return rgb;
  6074. },
  6075. /**
  6076. * Converts the color value to the RGB color, similar to the getRgb method.
  6077. * The result placed into the dest array starting from the destOffset.
  6078. */
  6079. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  6080. dest, destOffset) {
  6081. error('Should not call ColorSpace.getRgbItem');
  6082. },
  6083. /**
  6084. * Converts the specified number of the color values to the RGB colors.
  6085. * The colors are located in the src array starting from the srcOffset.
  6086. * The result is placed into the dest array starting from the destOffset.
  6087. * The src array items shall be in [0,2^bits) range, the dest array items
  6088. * will be in [0,255] range. alpha01 indicates how many alpha components
  6089. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  6090. * array).
  6091. */
  6092. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  6093. dest, destOffset, bits,
  6094. alpha01) {
  6095. error('Should not call ColorSpace.getRgbBuffer');
  6096. },
  6097. /**
  6098. * Determines the number of bytes required to store the result of the
  6099. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  6100. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  6101. */
  6102. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  6103. alpha01) {
  6104. error('Should not call ColorSpace.getOutputLength');
  6105. },
  6106. /**
  6107. * Returns true if source data will be equal the result/output data.
  6108. */
  6109. isPassthrough: function ColorSpace_isPassthrough(bits) {
  6110. return false;
  6111. },
  6112. /**
  6113. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  6114. * how many alpha components there are in the dest array; it will be either
  6115. * 0 (RGB array) or 1 (RGBA array).
  6116. */
  6117. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  6118. originalHeight, width, height,
  6119. actualHeight, bpc, comps, alpha01) {
  6120. var count = originalWidth * originalHeight;
  6121. var rgbBuf = null;
  6122. var numComponentColors = 1 << bpc;
  6123. var needsResizing = originalHeight !== height || originalWidth !== width;
  6124. var i, ii;
  6125. if (this.isPassthrough(bpc)) {
  6126. rgbBuf = comps;
  6127. } else if (this.numComps === 1 && count > numComponentColors &&
  6128. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  6129. // Optimization: create a color map when there is just one component and
  6130. // we are converting more colors than the size of the color map. We
  6131. // don't build the map if the colorspace is gray or rgb since those
  6132. // methods are faster than building a map. This mainly offers big speed
  6133. // ups for indexed and alternate colorspaces.
  6134. //
  6135. // TODO it may be worth while to cache the color map. While running
  6136. // testing I never hit a cache so I will leave that out for now (perhaps
  6137. // we are reparsing colorspaces too much?).
  6138. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  6139. new Uint16Array(numComponentColors);
  6140. var key;
  6141. for (i = 0; i < numComponentColors; i++) {
  6142. allColors[i] = i;
  6143. }
  6144. var colorMap = new Uint8Array(numComponentColors * 3);
  6145. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  6146. /* alpha01 = */ 0);
  6147. var destPos, rgbPos;
  6148. if (!needsResizing) {
  6149. // Fill in the RGB values directly into |dest|.
  6150. destPos = 0;
  6151. for (i = 0; i < count; ++i) {
  6152. key = comps[i] * 3;
  6153. dest[destPos++] = colorMap[key];
  6154. dest[destPos++] = colorMap[key + 1];
  6155. dest[destPos++] = colorMap[key + 2];
  6156. destPos += alpha01;
  6157. }
  6158. } else {
  6159. rgbBuf = new Uint8Array(count * 3);
  6160. rgbPos = 0;
  6161. for (i = 0; i < count; ++i) {
  6162. key = comps[i] * 3;
  6163. rgbBuf[rgbPos++] = colorMap[key];
  6164. rgbBuf[rgbPos++] = colorMap[key + 1];
  6165. rgbBuf[rgbPos++] = colorMap[key + 2];
  6166. }
  6167. }
  6168. } else {
  6169. if (!needsResizing) {
  6170. // Fill in the RGB values directly into |dest|.
  6171. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  6172. alpha01);
  6173. } else {
  6174. rgbBuf = new Uint8Array(count * 3);
  6175. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  6176. /* alpha01 = */ 0);
  6177. }
  6178. }
  6179. if (rgbBuf) {
  6180. if (needsResizing) {
  6181. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  6182. height, dest, alpha01);
  6183. } else {
  6184. rgbPos = 0;
  6185. destPos = 0;
  6186. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  6187. dest[destPos++] = rgbBuf[rgbPos++];
  6188. dest[destPos++] = rgbBuf[rgbPos++];
  6189. dest[destPos++] = rgbBuf[rgbPos++];
  6190. destPos += alpha01;
  6191. }
  6192. }
  6193. }
  6194. },
  6195. /**
  6196. * True if the colorspace has components in the default range of [0, 1].
  6197. * This should be true for all colorspaces except for lab color spaces
  6198. * which are [0,100], [-128, 127], [-128, 127].
  6199. */
  6200. usesZeroToOneRange: true
  6201. };
  6202. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  6203. var IR = ColorSpace.parseToIR(cs, xref, res);
  6204. if (IR instanceof AlternateCS) {
  6205. return IR;
  6206. }
  6207. return ColorSpace.fromIR(IR);
  6208. };
  6209. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  6210. var name = isArray(IR) ? IR[0] : IR;
  6211. var whitePoint, blackPoint, gamma;
  6212. switch (name) {
  6213. case 'DeviceGrayCS':
  6214. return this.singletons.gray;
  6215. case 'DeviceRgbCS':
  6216. return this.singletons.rgb;
  6217. case 'DeviceCmykCS':
  6218. return this.singletons.cmyk;
  6219. case 'CalGrayCS':
  6220. whitePoint = IR[1].WhitePoint;
  6221. blackPoint = IR[1].BlackPoint;
  6222. gamma = IR[1].Gamma;
  6223. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6224. case 'CalRGBCS':
  6225. whitePoint = IR[1].WhitePoint;
  6226. blackPoint = IR[1].BlackPoint;
  6227. gamma = IR[1].Gamma;
  6228. var matrix = IR[1].Matrix;
  6229. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6230. case 'PatternCS':
  6231. var basePatternCS = IR[1];
  6232. if (basePatternCS) {
  6233. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6234. }
  6235. return new PatternCS(basePatternCS);
  6236. case 'IndexedCS':
  6237. var baseIndexedCS = IR[1];
  6238. var hiVal = IR[2];
  6239. var lookup = IR[3];
  6240. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6241. case 'AlternateCS':
  6242. var numComps = IR[1];
  6243. var alt = IR[2];
  6244. var tintFnIR = IR[3];
  6245. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6246. PDFFunction.fromIR(tintFnIR));
  6247. case 'LabCS':
  6248. whitePoint = IR[1].WhitePoint;
  6249. blackPoint = IR[1].BlackPoint;
  6250. var range = IR[1].Range;
  6251. return new LabCS(whitePoint, blackPoint, range);
  6252. default:
  6253. error('Unknown name ' + name);
  6254. }
  6255. return null;
  6256. };
  6257. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6258. if (isName(cs)) {
  6259. var colorSpaces = res.get('ColorSpace');
  6260. if (isDict(colorSpaces)) {
  6261. var refcs = colorSpaces.get(cs.name);
  6262. if (refcs) {
  6263. cs = refcs;
  6264. }
  6265. }
  6266. }
  6267. cs = xref.fetchIfRef(cs);
  6268. var mode;
  6269. if (isName(cs)) {
  6270. mode = cs.name;
  6271. this.mode = mode;
  6272. switch (mode) {
  6273. case 'DeviceGray':
  6274. case 'G':
  6275. return 'DeviceGrayCS';
  6276. case 'DeviceRGB':
  6277. case 'RGB':
  6278. return 'DeviceRgbCS';
  6279. case 'DeviceCMYK':
  6280. case 'CMYK':
  6281. return 'DeviceCmykCS';
  6282. case 'Pattern':
  6283. return ['PatternCS', null];
  6284. default:
  6285. error('unrecognized colorspace ' + mode);
  6286. }
  6287. } else if (isArray(cs)) {
  6288. mode = xref.fetchIfRef(cs[0]).name;
  6289. this.mode = mode;
  6290. var numComps, params, alt;
  6291. switch (mode) {
  6292. case 'DeviceGray':
  6293. case 'G':
  6294. return 'DeviceGrayCS';
  6295. case 'DeviceRGB':
  6296. case 'RGB':
  6297. return 'DeviceRgbCS';
  6298. case 'DeviceCMYK':
  6299. case 'CMYK':
  6300. return 'DeviceCmykCS';
  6301. case 'CalGray':
  6302. params = xref.fetchIfRef(cs[1]).getAll();
  6303. return ['CalGrayCS', params];
  6304. case 'CalRGB':
  6305. params = xref.fetchIfRef(cs[1]).getAll();
  6306. return ['CalRGBCS', params];
  6307. case 'ICCBased':
  6308. var stream = xref.fetchIfRef(cs[1]);
  6309. var dict = stream.dict;
  6310. numComps = dict.get('N');
  6311. alt = dict.get('Alternate');
  6312. if (alt) {
  6313. var altIR = ColorSpace.parseToIR(alt, xref, res);
  6314. // Parse the /Alternate CS to ensure that the number of components
  6315. // are correct, and also (indirectly) that it is not a PatternCS.
  6316. var altCS = ColorSpace.fromIR(altIR);
  6317. if (altCS.numComps === numComps) {
  6318. return altIR;
  6319. }
  6320. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  6321. }
  6322. if (numComps === 1) {
  6323. return 'DeviceGrayCS';
  6324. } else if (numComps === 3) {
  6325. return 'DeviceRgbCS';
  6326. } else if (numComps === 4) {
  6327. return 'DeviceCmykCS';
  6328. }
  6329. break;
  6330. case 'Pattern':
  6331. var basePatternCS = cs[1] || null;
  6332. if (basePatternCS) {
  6333. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6334. }
  6335. return ['PatternCS', basePatternCS];
  6336. case 'Indexed':
  6337. case 'I':
  6338. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6339. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  6340. var lookup = xref.fetchIfRef(cs[3]);
  6341. if (isStream(lookup)) {
  6342. lookup = lookup.getBytes();
  6343. }
  6344. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6345. case 'Separation':
  6346. case 'DeviceN':
  6347. var name = xref.fetchIfRef(cs[1]);
  6348. numComps = 1;
  6349. if (isName(name)) {
  6350. numComps = 1;
  6351. } else if (isArray(name)) {
  6352. numComps = name.length;
  6353. }
  6354. alt = ColorSpace.parseToIR(cs[2], xref, res);
  6355. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6356. return ['AlternateCS', numComps, alt, tintFnIR];
  6357. case 'Lab':
  6358. params = xref.fetchIfRef(cs[1]).getAll();
  6359. return ['LabCS', params];
  6360. default:
  6361. error('unimplemented color space object "' + mode + '"');
  6362. }
  6363. } else {
  6364. error('unrecognized color space object: "' + cs + '"');
  6365. }
  6366. return null;
  6367. };
  6368. /**
  6369. * Checks if a decode map matches the default decode map for a color space.
  6370. * This handles the general decode maps where there are two values per
  6371. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6372. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6373. * slightly different.
  6374. * @param {Array} decode Decode map (usually from an image).
  6375. * @param {Number} n Number of components the color space has.
  6376. */
  6377. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6378. if (!isArray(decode)) {
  6379. return true;
  6380. }
  6381. if (n * 2 !== decode.length) {
  6382. warn('The decode map is not the correct length');
  6383. return true;
  6384. }
  6385. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6386. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6387. return false;
  6388. }
  6389. }
  6390. return true;
  6391. };
  6392. ColorSpace.singletons = {
  6393. get gray() {
  6394. return shadow(this, 'gray', new DeviceGrayCS());
  6395. },
  6396. get rgb() {
  6397. return shadow(this, 'rgb', new DeviceRgbCS());
  6398. },
  6399. get cmyk() {
  6400. return shadow(this, 'cmyk', new DeviceCmykCS());
  6401. }
  6402. };
  6403. return ColorSpace;
  6404. })();
  6405. /**
  6406. * Alternate color space handles both Separation and DeviceN color spaces. A
  6407. * Separation color space is actually just a DeviceN with one color component.
  6408. * Both color spaces use a tinting function to convert colors to a base color
  6409. * space.
  6410. */
  6411. var AlternateCS = (function AlternateCSClosure() {
  6412. function AlternateCS(numComps, base, tintFn) {
  6413. this.name = 'Alternate';
  6414. this.numComps = numComps;
  6415. this.defaultColor = new Float32Array(numComps);
  6416. for (var i = 0; i < numComps; ++i) {
  6417. this.defaultColor[i] = 1;
  6418. }
  6419. this.base = base;
  6420. this.tintFn = tintFn;
  6421. this.tmpBuf = new Float32Array(base.numComps);
  6422. }
  6423. AlternateCS.prototype = {
  6424. getRgb: ColorSpace.prototype.getRgb,
  6425. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6426. dest, destOffset) {
  6427. var tmpBuf = this.tmpBuf;
  6428. this.tintFn(src, srcOffset, tmpBuf, 0);
  6429. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6430. },
  6431. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6432. dest, destOffset, bits,
  6433. alpha01) {
  6434. var tintFn = this.tintFn;
  6435. var base = this.base;
  6436. var scale = 1 / ((1 << bits) - 1);
  6437. var baseNumComps = base.numComps;
  6438. var usesZeroToOneRange = base.usesZeroToOneRange;
  6439. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6440. alpha01 === 0;
  6441. var pos = isPassthrough ? destOffset : 0;
  6442. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6443. var numComps = this.numComps;
  6444. var scaled = new Float32Array(numComps);
  6445. var tinted = new Float32Array(baseNumComps);
  6446. var i, j;
  6447. if (usesZeroToOneRange) {
  6448. for (i = 0; i < count; i++) {
  6449. for (j = 0; j < numComps; j++) {
  6450. scaled[j] = src[srcOffset++] * scale;
  6451. }
  6452. tintFn(scaled, 0, tinted, 0);
  6453. for (j = 0; j < baseNumComps; j++) {
  6454. baseBuf[pos++] = tinted[j] * 255;
  6455. }
  6456. }
  6457. } else {
  6458. for (i = 0; i < count; i++) {
  6459. for (j = 0; j < numComps; j++) {
  6460. scaled[j] = src[srcOffset++] * scale;
  6461. }
  6462. tintFn(scaled, 0, tinted, 0);
  6463. base.getRgbItem(tinted, 0, baseBuf, pos);
  6464. pos += baseNumComps;
  6465. }
  6466. }
  6467. if (!isPassthrough) {
  6468. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6469. }
  6470. },
  6471. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6472. alpha01) {
  6473. return this.base.getOutputLength(inputLength *
  6474. this.base.numComps / this.numComps,
  6475. alpha01);
  6476. },
  6477. isPassthrough: ColorSpace.prototype.isPassthrough,
  6478. fillRgb: ColorSpace.prototype.fillRgb,
  6479. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6480. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6481. },
  6482. usesZeroToOneRange: true
  6483. };
  6484. return AlternateCS;
  6485. })();
  6486. var PatternCS = (function PatternCSClosure() {
  6487. function PatternCS(baseCS) {
  6488. this.name = 'Pattern';
  6489. this.base = baseCS;
  6490. }
  6491. PatternCS.prototype = {};
  6492. return PatternCS;
  6493. })();
  6494. var IndexedCS = (function IndexedCSClosure() {
  6495. function IndexedCS(base, highVal, lookup) {
  6496. this.name = 'Indexed';
  6497. this.numComps = 1;
  6498. this.defaultColor = new Uint8Array([0]);
  6499. this.base = base;
  6500. this.highVal = highVal;
  6501. var baseNumComps = base.numComps;
  6502. var length = baseNumComps * highVal;
  6503. var lookupArray;
  6504. if (isStream(lookup)) {
  6505. lookupArray = new Uint8Array(length);
  6506. var bytes = lookup.getBytes(length);
  6507. lookupArray.set(bytes);
  6508. } else if (isString(lookup)) {
  6509. lookupArray = new Uint8Array(length);
  6510. for (var i = 0; i < length; ++i) {
  6511. lookupArray[i] = lookup.charCodeAt(i);
  6512. }
  6513. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6514. lookupArray = lookup;
  6515. } else {
  6516. error('Unrecognized lookup table: ' + lookup);
  6517. }
  6518. this.lookup = lookupArray;
  6519. }
  6520. IndexedCS.prototype = {
  6521. getRgb: ColorSpace.prototype.getRgb,
  6522. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6523. dest, destOffset) {
  6524. var numComps = this.base.numComps;
  6525. var start = src[srcOffset] * numComps;
  6526. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6527. },
  6528. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6529. dest, destOffset, bits,
  6530. alpha01) {
  6531. var base = this.base;
  6532. var numComps = base.numComps;
  6533. var outputDelta = base.getOutputLength(numComps, alpha01);
  6534. var lookup = this.lookup;
  6535. for (var i = 0; i < count; ++i) {
  6536. var lookupPos = src[srcOffset++] * numComps;
  6537. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6538. destOffset += outputDelta;
  6539. }
  6540. },
  6541. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6542. return this.base.getOutputLength(inputLength * this.base.numComps,
  6543. alpha01);
  6544. },
  6545. isPassthrough: ColorSpace.prototype.isPassthrough,
  6546. fillRgb: ColorSpace.prototype.fillRgb,
  6547. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6548. // indexed color maps shouldn't be changed
  6549. return true;
  6550. },
  6551. usesZeroToOneRange: true
  6552. };
  6553. return IndexedCS;
  6554. })();
  6555. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6556. function DeviceGrayCS() {
  6557. this.name = 'DeviceGray';
  6558. this.numComps = 1;
  6559. this.defaultColor = new Float32Array([0]);
  6560. }
  6561. DeviceGrayCS.prototype = {
  6562. getRgb: ColorSpace.prototype.getRgb,
  6563. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6564. dest, destOffset) {
  6565. var c = (src[srcOffset] * 255) | 0;
  6566. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6567. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6568. },
  6569. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6570. dest, destOffset, bits,
  6571. alpha01) {
  6572. var scale = 255 / ((1 << bits) - 1);
  6573. var j = srcOffset, q = destOffset;
  6574. for (var i = 0; i < count; ++i) {
  6575. var c = (scale * src[j++]) | 0;
  6576. dest[q++] = c;
  6577. dest[q++] = c;
  6578. dest[q++] = c;
  6579. q += alpha01;
  6580. }
  6581. },
  6582. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6583. alpha01) {
  6584. return inputLength * (3 + alpha01);
  6585. },
  6586. isPassthrough: ColorSpace.prototype.isPassthrough,
  6587. fillRgb: ColorSpace.prototype.fillRgb,
  6588. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6589. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6590. },
  6591. usesZeroToOneRange: true
  6592. };
  6593. return DeviceGrayCS;
  6594. })();
  6595. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6596. function DeviceRgbCS() {
  6597. this.name = 'DeviceRGB';
  6598. this.numComps = 3;
  6599. this.defaultColor = new Float32Array([0, 0, 0]);
  6600. }
  6601. DeviceRgbCS.prototype = {
  6602. getRgb: ColorSpace.prototype.getRgb,
  6603. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6604. dest, destOffset) {
  6605. var r = (src[srcOffset] * 255) | 0;
  6606. var g = (src[srcOffset + 1] * 255) | 0;
  6607. var b = (src[srcOffset + 2] * 255) | 0;
  6608. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6609. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6610. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6611. },
  6612. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6613. dest, destOffset, bits,
  6614. alpha01) {
  6615. if (bits === 8 && alpha01 === 0) {
  6616. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6617. return;
  6618. }
  6619. var scale = 255 / ((1 << bits) - 1);
  6620. var j = srcOffset, q = destOffset;
  6621. for (var i = 0; i < count; ++i) {
  6622. dest[q++] = (scale * src[j++]) | 0;
  6623. dest[q++] = (scale * src[j++]) | 0;
  6624. dest[q++] = (scale * src[j++]) | 0;
  6625. q += alpha01;
  6626. }
  6627. },
  6628. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6629. alpha01) {
  6630. return (inputLength * (3 + alpha01) / 3) | 0;
  6631. },
  6632. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6633. return bits === 8;
  6634. },
  6635. fillRgb: ColorSpace.prototype.fillRgb,
  6636. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6637. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6638. },
  6639. usesZeroToOneRange: true
  6640. };
  6641. return DeviceRgbCS;
  6642. })();
  6643. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6644. // The coefficients below was found using numerical analysis: the method of
  6645. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6646. // where color_value is the tabular value from the table of sampled RGB colors
  6647. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6648. // CMYK color conversion using the estimation below:
  6649. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6650. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6651. var c = src[srcOffset + 0] * srcScale;
  6652. var m = src[srcOffset + 1] * srcScale;
  6653. var y = src[srcOffset + 2] * srcScale;
  6654. var k = src[srcOffset + 3] * srcScale;
  6655. var r =
  6656. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6657. 18.82290502165302 * y + 212.25662451639585 * k +
  6658. -285.2331026137004) +
  6659. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6660. -17.873870861415444 * k - 5.497006427196366) +
  6661. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6662. 17.5119270841813) +
  6663. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6664. var g =
  6665. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6666. 6.871425592049007 * y + 31.159100130055922 * k +
  6667. -79.2970844816548) +
  6668. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6669. 131.35250912493976 * k - 190.9453302588951) +
  6670. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6671. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6672. var b =
  6673. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6674. 30.89978309703729 * y - 0.23883238689178934 * k +
  6675. -14.183576799673286) +
  6676. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6677. 50.606957656360734 * k - 112.23884253719248) +
  6678. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6679. -193.58209356861505) +
  6680. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6681. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6682. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6683. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6684. }
  6685. function DeviceCmykCS() {
  6686. this.name = 'DeviceCMYK';
  6687. this.numComps = 4;
  6688. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6689. }
  6690. DeviceCmykCS.prototype = {
  6691. getRgb: ColorSpace.prototype.getRgb,
  6692. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6693. dest, destOffset) {
  6694. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6695. },
  6696. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6697. dest, destOffset, bits,
  6698. alpha01) {
  6699. var scale = 1 / ((1 << bits) - 1);
  6700. for (var i = 0; i < count; i++) {
  6701. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6702. srcOffset += 4;
  6703. destOffset += 3 + alpha01;
  6704. }
  6705. },
  6706. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6707. alpha01) {
  6708. return (inputLength / 4 * (3 + alpha01)) | 0;
  6709. },
  6710. isPassthrough: ColorSpace.prototype.isPassthrough,
  6711. fillRgb: ColorSpace.prototype.fillRgb,
  6712. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6713. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6714. },
  6715. usesZeroToOneRange: true
  6716. };
  6717. return DeviceCmykCS;
  6718. })();
  6719. //
  6720. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6721. //
  6722. var CalGrayCS = (function CalGrayCSClosure() {
  6723. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6724. this.name = 'CalGray';
  6725. this.numComps = 1;
  6726. this.defaultColor = new Float32Array([0]);
  6727. if (!whitePoint) {
  6728. error('WhitePoint missing - required for color space CalGray');
  6729. }
  6730. blackPoint = blackPoint || [0, 0, 0];
  6731. gamma = gamma || 1;
  6732. // Translate arguments to spec variables.
  6733. this.XW = whitePoint[0];
  6734. this.YW = whitePoint[1];
  6735. this.ZW = whitePoint[2];
  6736. this.XB = blackPoint[0];
  6737. this.YB = blackPoint[1];
  6738. this.ZB = blackPoint[2];
  6739. this.G = gamma;
  6740. // Validate variables as per spec.
  6741. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6742. error('Invalid WhitePoint components for ' + this.name +
  6743. ', no fallback available');
  6744. }
  6745. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6746. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6747. this.XB = this.YB = this.ZB = 0;
  6748. }
  6749. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6750. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6751. ', ZB: ' + this.ZB + ', only default values are supported.');
  6752. }
  6753. if (this.G < 1) {
  6754. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6755. ', falling back to default');
  6756. this.G = 1;
  6757. }
  6758. }
  6759. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6760. // A represents a gray component of a calibrated gray space.
  6761. // A <---> AG in the spec
  6762. var A = src[srcOffset] * scale;
  6763. var AG = Math.pow(A, cs.G);
  6764. // Computes L as per spec. ( = cs.YW * AG )
  6765. // Except if other than default BlackPoint values are used.
  6766. var L = cs.YW * AG;
  6767. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6768. // Convert values to rgb range [0, 255].
  6769. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6770. dest[destOffset] = val;
  6771. dest[destOffset + 1] = val;
  6772. dest[destOffset + 2] = val;
  6773. }
  6774. CalGrayCS.prototype = {
  6775. getRgb: ColorSpace.prototype.getRgb,
  6776. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6777. dest, destOffset) {
  6778. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6779. },
  6780. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6781. dest, destOffset, bits,
  6782. alpha01) {
  6783. var scale = 1 / ((1 << bits) - 1);
  6784. for (var i = 0; i < count; ++i) {
  6785. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6786. srcOffset += 1;
  6787. destOffset += 3 + alpha01;
  6788. }
  6789. },
  6790. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6791. return inputLength * (3 + alpha01);
  6792. },
  6793. isPassthrough: ColorSpace.prototype.isPassthrough,
  6794. fillRgb: ColorSpace.prototype.fillRgb,
  6795. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6796. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6797. },
  6798. usesZeroToOneRange: true
  6799. };
  6800. return CalGrayCS;
  6801. })();
  6802. //
  6803. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6804. //
  6805. var CalRGBCS = (function CalRGBCSClosure() {
  6806. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6807. // matrices.
  6808. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6809. 0.8951, 0.2664, -0.1614,
  6810. -0.7502, 1.7135, 0.0367,
  6811. 0.0389, -0.0685, 1.0296]);
  6812. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6813. 0.9869929, -0.1470543, 0.1599627,
  6814. 0.4323053, 0.5183603, 0.0492912,
  6815. -0.0085287, 0.0400428, 0.9684867]);
  6816. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6817. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6818. 3.2404542, -1.5371385, -0.4985314,
  6819. -0.9692660, 1.8760108, 0.0415560,
  6820. 0.0556434, -0.2040259, 1.0572252]);
  6821. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6822. var tempNormalizeMatrix = new Float32Array(3);
  6823. var tempConvertMatrix1 = new Float32Array(3);
  6824. var tempConvertMatrix2 = new Float32Array(3);
  6825. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6826. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6827. this.name = 'CalRGB';
  6828. this.numComps = 3;
  6829. this.defaultColor = new Float32Array(3);
  6830. if (!whitePoint) {
  6831. error('WhitePoint missing - required for color space CalRGB');
  6832. }
  6833. blackPoint = blackPoint || new Float32Array(3);
  6834. gamma = gamma || new Float32Array([1, 1, 1]);
  6835. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6836. // Translate arguments to spec variables.
  6837. var XW = whitePoint[0];
  6838. var YW = whitePoint[1];
  6839. var ZW = whitePoint[2];
  6840. this.whitePoint = whitePoint;
  6841. var XB = blackPoint[0];
  6842. var YB = blackPoint[1];
  6843. var ZB = blackPoint[2];
  6844. this.blackPoint = blackPoint;
  6845. this.GR = gamma[0];
  6846. this.GG = gamma[1];
  6847. this.GB = gamma[2];
  6848. this.MXA = matrix[0];
  6849. this.MYA = matrix[1];
  6850. this.MZA = matrix[2];
  6851. this.MXB = matrix[3];
  6852. this.MYB = matrix[4];
  6853. this.MZB = matrix[5];
  6854. this.MXC = matrix[6];
  6855. this.MYC = matrix[7];
  6856. this.MZC = matrix[8];
  6857. // Validate variables as per spec.
  6858. if (XW < 0 || ZW < 0 || YW !== 1) {
  6859. error('Invalid WhitePoint components for ' + this.name +
  6860. ', no fallback available');
  6861. }
  6862. if (XB < 0 || YB < 0 || ZB < 0) {
  6863. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6864. ', ' + ZB + '], falling back to default');
  6865. this.blackPoint = new Float32Array(3);
  6866. }
  6867. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6868. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6869. '] for ' + this.name + ', falling back to default');
  6870. this.GR = this.GG = this.GB = 1;
  6871. }
  6872. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6873. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6874. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6875. info('Invalid Matrix for ' + this.name + ' [' +
  6876. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6877. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6878. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6879. '], falling back to default');
  6880. this.MXA = this.MYB = this.MZC = 1;
  6881. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6882. }
  6883. }
  6884. function matrixProduct(a, b, result) {
  6885. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6886. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6887. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6888. }
  6889. function convertToFlat(sourceWhitePoint, LMS, result) {
  6890. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6891. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6892. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6893. }
  6894. function convertToD65(sourceWhitePoint, LMS, result) {
  6895. var D65X = 0.95047;
  6896. var D65Y = 1;
  6897. var D65Z = 1.08883;
  6898. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6899. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6900. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6901. }
  6902. function sRGBTransferFunction(color) {
  6903. // See http://en.wikipedia.org/wiki/SRGB.
  6904. if (color <= 0.0031308){
  6905. return adjustToRange(0, 1, 12.92 * color);
  6906. }
  6907. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6908. }
  6909. function adjustToRange(min, max, value) {
  6910. return Math.max(min, Math.min(max, value));
  6911. }
  6912. function decodeL(L) {
  6913. if (L < 0) {
  6914. return -decodeL(-L);
  6915. }
  6916. if (L > 8.0) {
  6917. return Math.pow(((L + 16) / 116), 3);
  6918. }
  6919. return L * DECODE_L_CONSTANT;
  6920. }
  6921. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6922. // In case the blackPoint is already the default blackPoint then there is
  6923. // no need to do compensation.
  6924. if (sourceBlackPoint[0] === 0 &&
  6925. sourceBlackPoint[1] === 0 &&
  6926. sourceBlackPoint[2] === 0) {
  6927. result[0] = XYZ_Flat[0];
  6928. result[1] = XYZ_Flat[1];
  6929. result[2] = XYZ_Flat[2];
  6930. return;
  6931. }
  6932. // For the blackPoint calculation details, please see
  6933. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6934. // AdobeBPC.pdf.
  6935. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6936. var zeroDecodeL = decodeL(0);
  6937. var X_DST = zeroDecodeL;
  6938. var X_SRC = decodeL(sourceBlackPoint[0]);
  6939. var Y_DST = zeroDecodeL;
  6940. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6941. var Z_DST = zeroDecodeL;
  6942. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6943. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6944. var X_Offset = 1 - X_Scale;
  6945. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6946. var Y_Offset = 1 - Y_Scale;
  6947. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6948. var Z_Offset = 1 - Z_Scale;
  6949. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6950. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6951. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6952. }
  6953. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6954. // In case the whitePoint is already flat then there is no need to do
  6955. // normalization.
  6956. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6957. result[0] = XYZ_In[0];
  6958. result[1] = XYZ_In[1];
  6959. result[2] = XYZ_In[2];
  6960. return;
  6961. }
  6962. var LMS = result;
  6963. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6964. var LMS_Flat = tempNormalizeMatrix;
  6965. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6966. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6967. }
  6968. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6969. var LMS = result;
  6970. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6971. var LMS_D65 = tempNormalizeMatrix;
  6972. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6973. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6974. }
  6975. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6976. // A, B and C represent a red, green and blue components of a calibrated
  6977. // rgb space.
  6978. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6979. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6980. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6981. // A <---> AGR in the spec
  6982. // B <---> BGG in the spec
  6983. // C <---> CGB in the spec
  6984. var AGR = Math.pow(A, cs.GR);
  6985. var BGG = Math.pow(B, cs.GG);
  6986. var CGB = Math.pow(C, cs.GB);
  6987. // Computes intermediate variables L, M, N as per spec.
  6988. // To decode X, Y, Z values map L, M, N directly to them.
  6989. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6990. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6991. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6992. // The following calculations are based on this document:
  6993. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6994. // AdobeBPC.pdf.
  6995. var XYZ = tempConvertMatrix1;
  6996. XYZ[0] = X;
  6997. XYZ[1] = Y;
  6998. XYZ[2] = Z;
  6999. var XYZ_Flat = tempConvertMatrix2;
  7000. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  7001. var XYZ_Black = tempConvertMatrix1;
  7002. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  7003. var XYZ_D65 = tempConvertMatrix2;
  7004. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  7005. var SRGB = tempConvertMatrix1;
  7006. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  7007. var sR = sRGBTransferFunction(SRGB[0]);
  7008. var sG = sRGBTransferFunction(SRGB[1]);
  7009. var sB = sRGBTransferFunction(SRGB[2]);
  7010. // Convert the values to rgb range [0, 255].
  7011. dest[destOffset] = Math.round(sR * 255);
  7012. dest[destOffset + 1] = Math.round(sG * 255);
  7013. dest[destOffset + 2] = Math.round(sB * 255);
  7014. }
  7015. CalRGBCS.prototype = {
  7016. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  7017. var rgb = new Uint8Array(3);
  7018. this.getRgbItem(src, srcOffset, rgb, 0);
  7019. return rgb;
  7020. },
  7021. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  7022. dest, destOffset) {
  7023. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  7024. },
  7025. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  7026. dest, destOffset, bits,
  7027. alpha01) {
  7028. var scale = 1 / ((1 << bits) - 1);
  7029. for (var i = 0; i < count; ++i) {
  7030. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  7031. srcOffset += 3;
  7032. destOffset += 3 + alpha01;
  7033. }
  7034. },
  7035. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  7036. return (inputLength * (3 + alpha01) / 3) | 0;
  7037. },
  7038. isPassthrough: ColorSpace.prototype.isPassthrough,
  7039. fillRgb: ColorSpace.prototype.fillRgb,
  7040. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  7041. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7042. },
  7043. usesZeroToOneRange: true
  7044. };
  7045. return CalRGBCS;
  7046. })();
  7047. //
  7048. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  7049. //
  7050. var LabCS = (function LabCSClosure() {
  7051. function LabCS(whitePoint, blackPoint, range) {
  7052. this.name = 'Lab';
  7053. this.numComps = 3;
  7054. this.defaultColor = new Float32Array([0, 0, 0]);
  7055. if (!whitePoint) {
  7056. error('WhitePoint missing - required for color space Lab');
  7057. }
  7058. blackPoint = blackPoint || [0, 0, 0];
  7059. range = range || [-100, 100, -100, 100];
  7060. // Translate args to spec variables
  7061. this.XW = whitePoint[0];
  7062. this.YW = whitePoint[1];
  7063. this.ZW = whitePoint[2];
  7064. this.amin = range[0];
  7065. this.amax = range[1];
  7066. this.bmin = range[2];
  7067. this.bmax = range[3];
  7068. // These are here just for completeness - the spec doesn't offer any
  7069. // formulas that use BlackPoint in Lab
  7070. this.XB = blackPoint[0];
  7071. this.YB = blackPoint[1];
  7072. this.ZB = blackPoint[2];
  7073. // Validate vars as per spec
  7074. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  7075. error('Invalid WhitePoint components, no fallback available');
  7076. }
  7077. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  7078. info('Invalid BlackPoint, falling back to default');
  7079. this.XB = this.YB = this.ZB = 0;
  7080. }
  7081. if (this.amin > this.amax || this.bmin > this.bmax) {
  7082. info('Invalid Range, falling back to defaults');
  7083. this.amin = -100;
  7084. this.amax = 100;
  7085. this.bmin = -100;
  7086. this.bmax = 100;
  7087. }
  7088. }
  7089. // Function g(x) from spec
  7090. function fn_g(x) {
  7091. if (x >= 6 / 29) {
  7092. return x * x * x;
  7093. } else {
  7094. return (108 / 841) * (x - 4 / 29);
  7095. }
  7096. }
  7097. function decode(value, high1, low2, high2) {
  7098. return low2 + (value) * (high2 - low2) / (high1);
  7099. }
  7100. // If decoding is needed maxVal should be 2^bits per component - 1.
  7101. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  7102. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  7103. // not the usual [0, 1]. If a command like setFillColor is used the src
  7104. // values will already be within the correct range. However, if we are
  7105. // converting an image we have to map the values to the correct range given
  7106. // above.
  7107. // Ls,as,bs <---> L*,a*,b* in the spec
  7108. var Ls = src[srcOffset];
  7109. var as = src[srcOffset + 1];
  7110. var bs = src[srcOffset + 2];
  7111. if (maxVal !== false) {
  7112. Ls = decode(Ls, maxVal, 0, 100);
  7113. as = decode(as, maxVal, cs.amin, cs.amax);
  7114. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  7115. }
  7116. // Adjust limits of 'as' and 'bs'
  7117. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  7118. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  7119. // Computes intermediate variables X,Y,Z as per spec
  7120. var M = (Ls + 16) / 116;
  7121. var L = M + (as / 500);
  7122. var N = M - (bs / 200);
  7123. var X = cs.XW * fn_g(L);
  7124. var Y = cs.YW * fn_g(M);
  7125. var Z = cs.ZW * fn_g(N);
  7126. var r, g, b;
  7127. // Using different conversions for D50 and D65 white points,
  7128. // per http://www.color.org/srgb.pdf
  7129. if (cs.ZW < 1) {
  7130. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  7131. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  7132. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  7133. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  7134. } else {
  7135. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  7136. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  7137. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  7138. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  7139. }
  7140. // clamp color values to [0,1] range then convert to [0,255] range.
  7141. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  7142. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  7143. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  7144. }
  7145. LabCS.prototype = {
  7146. getRgb: ColorSpace.prototype.getRgb,
  7147. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  7148. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  7149. },
  7150. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  7151. dest, destOffset, bits,
  7152. alpha01) {
  7153. var maxVal = (1 << bits) - 1;
  7154. for (var i = 0; i < count; i++) {
  7155. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  7156. srcOffset += 3;
  7157. destOffset += 3 + alpha01;
  7158. }
  7159. },
  7160. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  7161. return (inputLength * (3 + alpha01) / 3) | 0;
  7162. },
  7163. isPassthrough: ColorSpace.prototype.isPassthrough,
  7164. fillRgb: ColorSpace.prototype.fillRgb,
  7165. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  7166. // XXX: Decoding is handled with the lab conversion because of the strange
  7167. // ranges that are used.
  7168. return true;
  7169. },
  7170. usesZeroToOneRange: false
  7171. };
  7172. return LabCS;
  7173. })();
  7174. var ARCFourCipher = (function ARCFourCipherClosure() {
  7175. function ARCFourCipher(key) {
  7176. this.a = 0;
  7177. this.b = 0;
  7178. var s = new Uint8Array(256);
  7179. var i, j = 0, tmp, keyLength = key.length;
  7180. for (i = 0; i < 256; ++i) {
  7181. s[i] = i;
  7182. }
  7183. for (i = 0; i < 256; ++i) {
  7184. tmp = s[i];
  7185. j = (j + tmp + key[i % keyLength]) & 0xFF;
  7186. s[i] = s[j];
  7187. s[j] = tmp;
  7188. }
  7189. this.s = s;
  7190. }
  7191. ARCFourCipher.prototype = {
  7192. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  7193. var i, n = data.length, tmp, tmp2;
  7194. var a = this.a, b = this.b, s = this.s;
  7195. var output = new Uint8Array(n);
  7196. for (i = 0; i < n; ++i) {
  7197. a = (a + 1) & 0xFF;
  7198. tmp = s[a];
  7199. b = (b + tmp) & 0xFF;
  7200. tmp2 = s[b];
  7201. s[a] = tmp2;
  7202. s[b] = tmp;
  7203. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  7204. }
  7205. this.a = a;
  7206. this.b = b;
  7207. return output;
  7208. }
  7209. };
  7210. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  7211. return ARCFourCipher;
  7212. })();
  7213. var calculateMD5 = (function calculateMD5Closure() {
  7214. var r = new Uint8Array([
  7215. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  7216. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  7217. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  7218. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  7219. var k = new Int32Array([
  7220. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  7221. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  7222. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  7223. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  7224. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  7225. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  7226. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  7227. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  7228. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  7229. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  7230. -145523070, -1120210379, 718787259, -343485551]);
  7231. function hash(data, offset, length) {
  7232. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7233. // pre-processing
  7234. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7235. var padded = new Uint8Array(paddedLength);
  7236. var i, j, n;
  7237. for (i = 0; i < length; ++i) {
  7238. padded[i] = data[offset++];
  7239. }
  7240. padded[i++] = 0x80;
  7241. n = paddedLength - 8;
  7242. while (i < n) {
  7243. padded[i++] = 0;
  7244. }
  7245. padded[i++] = (length << 3) & 0xFF;
  7246. padded[i++] = (length >> 5) & 0xFF;
  7247. padded[i++] = (length >> 13) & 0xFF;
  7248. padded[i++] = (length >> 21) & 0xFF;
  7249. padded[i++] = (length >>> 29) & 0xFF;
  7250. padded[i++] = 0;
  7251. padded[i++] = 0;
  7252. padded[i++] = 0;
  7253. var w = new Int32Array(16);
  7254. for (i = 0; i < paddedLength;) {
  7255. for (j = 0; j < 16; ++j, i += 4) {
  7256. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7257. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7258. }
  7259. var a = h0, b = h1, c = h2, d = h3, f, g;
  7260. for (j = 0; j < 64; ++j) {
  7261. if (j < 16) {
  7262. f = (b & c) | ((~b) & d);
  7263. g = j;
  7264. } else if (j < 32) {
  7265. f = (d & b) | ((~d) & c);
  7266. g = (5 * j + 1) & 15;
  7267. } else if (j < 48) {
  7268. f = b ^ c ^ d;
  7269. g = (3 * j + 5) & 15;
  7270. } else {
  7271. f = c ^ (b | (~d));
  7272. g = (7 * j) & 15;
  7273. }
  7274. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7275. d = c;
  7276. c = b;
  7277. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7278. a = tmp;
  7279. }
  7280. h0 = (h0 + a) | 0;
  7281. h1 = (h1 + b) | 0;
  7282. h2 = (h2 + c) | 0;
  7283. h3 = (h3 + d) | 0;
  7284. }
  7285. return new Uint8Array([
  7286. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7287. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7288. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7289. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7290. ]);
  7291. }
  7292. return hash;
  7293. })();
  7294. var Word64 = (function Word64Closure() {
  7295. function Word64(highInteger, lowInteger) {
  7296. this.high = highInteger | 0;
  7297. this.low = lowInteger | 0;
  7298. }
  7299. Word64.prototype = {
  7300. and: function Word64_and(word) {
  7301. this.high &= word.high;
  7302. this.low &= word.low;
  7303. },
  7304. xor: function Word64_xor(word) {
  7305. this.high ^= word.high;
  7306. this.low ^= word.low;
  7307. },
  7308. or: function Word64_or(word) {
  7309. this.high |= word.high;
  7310. this.low |= word.low;
  7311. },
  7312. shiftRight: function Word64_shiftRight(places) {
  7313. if (places >= 32) {
  7314. this.low = (this.high >>> (places - 32)) | 0;
  7315. this.high = 0;
  7316. } else {
  7317. this.low = (this.low >>> places) | (this.high << (32 - places));
  7318. this.high = (this.high >>> places) | 0;
  7319. }
  7320. },
  7321. shiftLeft: function Word64_shiftLeft(places) {
  7322. if (places >= 32) {
  7323. this.high = this.low << (places - 32);
  7324. this.low = 0;
  7325. } else {
  7326. this.high = (this.high << places) | (this.low >>> (32 - places));
  7327. this.low = this.low << places;
  7328. }
  7329. },
  7330. rotateRight: function Word64_rotateRight(places) {
  7331. var low, high;
  7332. if (places & 32) {
  7333. high = this.low;
  7334. low = this.high;
  7335. } else {
  7336. low = this.low;
  7337. high = this.high;
  7338. }
  7339. places &= 31;
  7340. this.low = (low >>> places) | (high << (32 - places));
  7341. this.high = (high >>> places) | (low << (32 - places));
  7342. },
  7343. not: function Word64_not() {
  7344. this.high = ~this.high;
  7345. this.low = ~this.low;
  7346. },
  7347. add: function Word64_add(word) {
  7348. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7349. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7350. if (lowAdd > 0xFFFFFFFF) {
  7351. highAdd += 1;
  7352. }
  7353. this.low = lowAdd | 0;
  7354. this.high = highAdd | 0;
  7355. },
  7356. copyTo: function Word64_copyTo(bytes, offset) {
  7357. bytes[offset] = (this.high >>> 24) & 0xFF;
  7358. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7359. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7360. bytes[offset + 3] = this.high & 0xFF;
  7361. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7362. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7363. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7364. bytes[offset + 7] = this.low & 0xFF;
  7365. },
  7366. assign: function Word64_assign(word) {
  7367. this.high = word.high;
  7368. this.low = word.low;
  7369. }
  7370. };
  7371. return Word64;
  7372. })();
  7373. var calculateSHA256 = (function calculateSHA256Closure() {
  7374. function rotr(x, n) {
  7375. return (x >>> n) | (x << 32 - n);
  7376. }
  7377. function ch(x, y, z) {
  7378. return (x & y) ^ (~x & z);
  7379. }
  7380. function maj(x, y, z) {
  7381. return (x & y) ^ (x & z) ^ (y & z);
  7382. }
  7383. function sigma(x) {
  7384. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7385. }
  7386. function sigmaPrime(x) {
  7387. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7388. }
  7389. function littleSigma(x) {
  7390. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7391. }
  7392. function littleSigmaPrime(x) {
  7393. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7394. }
  7395. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7396. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7397. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7398. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7399. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7400. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7401. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7402. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7403. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7404. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7405. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7406. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7407. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7408. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7409. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7410. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7411. function hash(data, offset, length) {
  7412. // initial hash values
  7413. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7414. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7415. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7416. // pre-processing
  7417. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7418. var padded = new Uint8Array(paddedLength);
  7419. var i, j, n;
  7420. for (i = 0; i < length; ++i) {
  7421. padded[i] = data[offset++];
  7422. }
  7423. padded[i++] = 0x80;
  7424. n = paddedLength - 8;
  7425. while (i < n) {
  7426. padded[i++] = 0;
  7427. }
  7428. padded[i++] = 0;
  7429. padded[i++] = 0;
  7430. padded[i++] = 0;
  7431. padded[i++] = (length >>> 29) & 0xFF;
  7432. padded[i++] = (length >> 21) & 0xFF;
  7433. padded[i++] = (length >> 13) & 0xFF;
  7434. padded[i++] = (length >> 5) & 0xFF;
  7435. padded[i++] = (length << 3) & 0xFF;
  7436. var w = new Uint32Array(64);
  7437. // for each 512 bit block
  7438. for (i = 0; i < paddedLength;) {
  7439. for (j = 0; j < 16; ++j) {
  7440. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7441. (padded[i + 2] << 8) | (padded[i + 3]));
  7442. i += 4;
  7443. }
  7444. for (j = 16; j < 64; ++j) {
  7445. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7446. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7447. }
  7448. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7449. f = h5, g = h6, h = h7, t1, t2;
  7450. for (j = 0; j < 64; ++j) {
  7451. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7452. t2 = sigma(a) + maj(a, b, c);
  7453. h = g;
  7454. g = f;
  7455. f = e;
  7456. e = (d + t1) | 0;
  7457. d = c;
  7458. c = b;
  7459. b = a;
  7460. a = (t1 + t2) | 0;
  7461. }
  7462. h0 = (h0 + a) | 0;
  7463. h1 = (h1 + b) | 0;
  7464. h2 = (h2 + c) | 0;
  7465. h3 = (h3 + d) | 0;
  7466. h4 = (h4 + e) | 0;
  7467. h5 = (h5 + f) | 0;
  7468. h6 = (h6 + g) | 0;
  7469. h7 = (h7 + h) | 0;
  7470. }
  7471. return new Uint8Array([
  7472. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7473. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7474. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7475. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7476. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7477. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7478. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7479. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7480. ]);
  7481. }
  7482. return hash;
  7483. })();
  7484. var calculateSHA512 = (function calculateSHA512Closure() {
  7485. function ch(result, x, y, z, tmp) {
  7486. result.assign(x);
  7487. result.and(y);
  7488. tmp.assign(x);
  7489. tmp.not();
  7490. tmp.and(z);
  7491. result.xor(tmp);
  7492. }
  7493. function maj(result, x, y, z, tmp) {
  7494. result.assign(x);
  7495. result.and(y);
  7496. tmp.assign(x);
  7497. tmp.and(z);
  7498. result.xor(tmp);
  7499. tmp.assign(y);
  7500. tmp.and(z);
  7501. result.xor(tmp);
  7502. }
  7503. function sigma(result, x, tmp) {
  7504. result.assign(x);
  7505. result.rotateRight(28);
  7506. tmp.assign(x);
  7507. tmp.rotateRight(34);
  7508. result.xor(tmp);
  7509. tmp.assign(x);
  7510. tmp.rotateRight(39);
  7511. result.xor(tmp);
  7512. }
  7513. function sigmaPrime(result, x, tmp) {
  7514. result.assign(x);
  7515. result.rotateRight(14);
  7516. tmp.assign(x);
  7517. tmp.rotateRight(18);
  7518. result.xor(tmp);
  7519. tmp.assign(x);
  7520. tmp.rotateRight(41);
  7521. result.xor(tmp);
  7522. }
  7523. function littleSigma(result, x, tmp) {
  7524. result.assign(x);
  7525. result.rotateRight(1);
  7526. tmp.assign(x);
  7527. tmp.rotateRight(8);
  7528. result.xor(tmp);
  7529. tmp.assign(x);
  7530. tmp.shiftRight(7);
  7531. result.xor(tmp);
  7532. }
  7533. function littleSigmaPrime(result, x, tmp) {
  7534. result.assign(x);
  7535. result.rotateRight(19);
  7536. tmp.assign(x);
  7537. tmp.rotateRight(61);
  7538. result.xor(tmp);
  7539. tmp.assign(x);
  7540. tmp.shiftRight(6);
  7541. result.xor(tmp);
  7542. }
  7543. var k = [
  7544. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7545. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7546. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7547. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7548. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7549. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7550. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7551. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7552. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7553. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7554. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7555. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7556. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7557. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7558. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7559. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7560. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7561. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7562. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7563. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7564. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7565. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7566. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7567. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7568. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7569. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7570. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7571. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7572. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7573. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7574. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7575. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7576. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7577. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7578. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7579. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7580. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7581. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7582. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7583. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7584. function hash(data, offset, length, mode384) {
  7585. mode384 = !!mode384;
  7586. // initial hash values
  7587. var h0, h1, h2, h3, h4, h5, h6, h7;
  7588. if (!mode384) {
  7589. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7590. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7591. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7592. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7593. h4 = new Word64(0x510e527f, 0xade682d1);
  7594. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7595. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7596. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7597. }
  7598. else {
  7599. // SHA384 is exactly the same
  7600. // except with different starting values and a trimmed result
  7601. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7602. h1 = new Word64(0x629a292a, 0x367cd507);
  7603. h2 = new Word64(0x9159015a, 0x3070dd17);
  7604. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7605. h4 = new Word64(0x67332667, 0xffc00b31);
  7606. h5 = new Word64(0x8eb44a87, 0x68581511);
  7607. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7608. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7609. }
  7610. // pre-processing
  7611. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7612. var padded = new Uint8Array(paddedLength);
  7613. var i, j, n;
  7614. for (i = 0; i < length; ++i) {
  7615. padded[i] = data[offset++];
  7616. }
  7617. padded[i++] = 0x80;
  7618. n = paddedLength - 16;
  7619. while (i < n) {
  7620. padded[i++] = 0;
  7621. }
  7622. padded[i++] = 0;
  7623. padded[i++] = 0;
  7624. padded[i++] = 0;
  7625. padded[i++] = 0;
  7626. padded[i++] = 0;
  7627. padded[i++] = 0;
  7628. padded[i++] = 0;
  7629. padded[i++] = 0;
  7630. padded[i++] = 0;
  7631. padded[i++] = 0;
  7632. padded[i++] = 0;
  7633. padded[i++] = (length >>> 29) & 0xFF;
  7634. padded[i++] = (length >> 21) & 0xFF;
  7635. padded[i++] = (length >> 13) & 0xFF;
  7636. padded[i++] = (length >> 5) & 0xFF;
  7637. padded[i++] = (length << 3) & 0xFF;
  7638. var w = new Array(80);
  7639. for (i = 0; i < 80; i++) {
  7640. w[i] = new Word64(0, 0);
  7641. }
  7642. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7643. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7644. var g = new Word64(0, 0), h = new Word64(0, 0);
  7645. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7646. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7647. // for each 1024 bit block
  7648. for (i = 0; i < paddedLength;) {
  7649. for (j = 0; j < 16; ++j) {
  7650. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7651. (padded[i + 2] << 8) | (padded[i + 3]);
  7652. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7653. (padded[i + 6]) << 8 | (padded[i + 7]);
  7654. i += 8;
  7655. }
  7656. for (j = 16; j < 80; ++j) {
  7657. tmp3 = w[j];
  7658. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7659. tmp3.add(w[j - 7]);
  7660. littleSigma(tmp1, w[j - 15], tmp2);
  7661. tmp3.add(tmp1);
  7662. tmp3.add(w[j - 16]);
  7663. }
  7664. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7665. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7666. for (j = 0; j < 80; ++j) {
  7667. t1.assign(h);
  7668. sigmaPrime(tmp1, e, tmp2);
  7669. t1.add(tmp1);
  7670. ch(tmp1, e, f, g, tmp2);
  7671. t1.add(tmp1);
  7672. t1.add(k[j]);
  7673. t1.add(w[j]);
  7674. sigma(t2, a, tmp2);
  7675. maj(tmp1, a, b, c, tmp2);
  7676. t2.add(tmp1);
  7677. tmp3 = h;
  7678. h = g;
  7679. g = f;
  7680. f = e;
  7681. d.add(t1);
  7682. e = d;
  7683. d = c;
  7684. c = b;
  7685. b = a;
  7686. tmp3.assign(t1);
  7687. tmp3.add(t2);
  7688. a = tmp3;
  7689. }
  7690. h0.add(a);
  7691. h1.add(b);
  7692. h2.add(c);
  7693. h3.add(d);
  7694. h4.add(e);
  7695. h5.add(f);
  7696. h6.add(g);
  7697. h7.add(h);
  7698. }
  7699. var result;
  7700. if (!mode384) {
  7701. result = new Uint8Array(64);
  7702. h0.copyTo(result,0);
  7703. h1.copyTo(result,8);
  7704. h2.copyTo(result,16);
  7705. h3.copyTo(result,24);
  7706. h4.copyTo(result,32);
  7707. h5.copyTo(result,40);
  7708. h6.copyTo(result,48);
  7709. h7.copyTo(result,56);
  7710. }
  7711. else {
  7712. result = new Uint8Array(48);
  7713. h0.copyTo(result,0);
  7714. h1.copyTo(result,8);
  7715. h2.copyTo(result,16);
  7716. h3.copyTo(result,24);
  7717. h4.copyTo(result,32);
  7718. h5.copyTo(result,40);
  7719. }
  7720. return result;
  7721. }
  7722. return hash;
  7723. })();
  7724. var calculateSHA384 = (function calculateSHA384Closure() {
  7725. function hash(data, offset, length) {
  7726. return calculateSHA512(data, offset, length, true);
  7727. }
  7728. return hash;
  7729. })();
  7730. var NullCipher = (function NullCipherClosure() {
  7731. function NullCipher() {
  7732. }
  7733. NullCipher.prototype = {
  7734. decryptBlock: function NullCipher_decryptBlock(data) {
  7735. return data;
  7736. }
  7737. };
  7738. return NullCipher;
  7739. })();
  7740. var AES128Cipher = (function AES128CipherClosure() {
  7741. var rcon = new Uint8Array([
  7742. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7743. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7744. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7745. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7746. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7747. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7748. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7749. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7750. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7751. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7752. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7753. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7754. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7755. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7756. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7757. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7758. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7759. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7760. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7761. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7762. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7763. 0x74, 0xe8, 0xcb, 0x8d]);
  7764. var s = new Uint8Array([
  7765. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7766. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7767. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7768. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7769. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7770. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7771. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7772. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7773. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7774. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7775. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7776. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7777. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7778. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7779. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7780. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7781. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7782. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7783. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7784. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7785. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7786. 0xb0, 0x54, 0xbb, 0x16]);
  7787. var inv_s = new Uint8Array([
  7788. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7789. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7790. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7791. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7792. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7793. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7794. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7795. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7796. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7797. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7798. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7799. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7800. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7801. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7802. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7803. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7804. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7805. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7806. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7807. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7808. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7809. 0x55, 0x21, 0x0c, 0x7d]);
  7810. var mixCol = new Uint8Array(256);
  7811. for (var i = 0; i < 256; i++) {
  7812. if (i < 128) {
  7813. mixCol[i] = i << 1;
  7814. } else {
  7815. mixCol[i] = (i << 1) ^ 0x1b;
  7816. }
  7817. }
  7818. var mix = new Uint32Array([
  7819. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7820. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7821. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7822. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7823. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7824. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7825. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7826. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7827. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7828. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7829. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7830. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7831. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7832. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7833. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7834. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7835. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7836. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7837. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7838. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7839. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7840. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7841. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7842. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7843. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7844. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7845. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7846. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7847. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7848. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7849. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7850. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7851. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7852. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7853. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7854. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7855. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7856. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7857. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7858. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7859. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7860. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7861. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7862. function expandKey128(cipherKey) {
  7863. var b = 176, result = new Uint8Array(b);
  7864. result.set(cipherKey);
  7865. for (var j = 16, i = 1; j < b; ++i) {
  7866. // RotWord
  7867. var t1 = result[j - 3], t2 = result[j - 2],
  7868. t3 = result[j - 1], t4 = result[j - 4];
  7869. // SubWord
  7870. t1 = s[t1];
  7871. t2 = s[t2];
  7872. t3 = s[t3];
  7873. t4 = s[t4];
  7874. // Rcon
  7875. t1 = t1 ^ rcon[i];
  7876. for (var n = 0; n < 4; ++n) {
  7877. result[j] = (t1 ^= result[j - 16]);
  7878. j++;
  7879. result[j] = (t2 ^= result[j - 16]);
  7880. j++;
  7881. result[j] = (t3 ^= result[j - 16]);
  7882. j++;
  7883. result[j] = (t4 ^= result[j - 16]);
  7884. j++;
  7885. }
  7886. }
  7887. return result;
  7888. }
  7889. function decrypt128(input, key) {
  7890. var state = new Uint8Array(16);
  7891. state.set(input);
  7892. var i, j, k;
  7893. var t, u, v;
  7894. // AddRoundKey
  7895. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7896. state[j] ^= key[k];
  7897. }
  7898. for (i = 9; i >= 1; --i) {
  7899. // InvShiftRows
  7900. t = state[13];
  7901. state[13] = state[9];
  7902. state[9] = state[5];
  7903. state[5] = state[1];
  7904. state[1] = t;
  7905. t = state[14];
  7906. u = state[10];
  7907. state[14] = state[6];
  7908. state[10] = state[2];
  7909. state[6] = t;
  7910. state[2] = u;
  7911. t = state[15];
  7912. u = state[11];
  7913. v = state[7];
  7914. state[15] = state[3];
  7915. state[11] = t;
  7916. state[7] = u;
  7917. state[3] = v;
  7918. // InvSubBytes
  7919. for (j = 0; j < 16; ++j) {
  7920. state[j] = inv_s[state[j]];
  7921. }
  7922. // AddRoundKey
  7923. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7924. state[j] ^= key[k];
  7925. }
  7926. // InvMixColumns
  7927. for (j = 0; j < 16; j += 4) {
  7928. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7929. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7930. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7931. (s3 >>> 24) ^ (s3 << 8));
  7932. state[j] = (t >>> 24) & 0xFF;
  7933. state[j + 1] = (t >> 16) & 0xFF;
  7934. state[j + 2] = (t >> 8) & 0xFF;
  7935. state[j + 3] = t & 0xFF;
  7936. }
  7937. }
  7938. // InvShiftRows
  7939. t = state[13];
  7940. state[13] = state[9];
  7941. state[9] = state[5];
  7942. state[5] = state[1];
  7943. state[1] = t;
  7944. t = state[14];
  7945. u = state[10];
  7946. state[14] = state[6];
  7947. state[10] = state[2];
  7948. state[6] = t;
  7949. state[2] = u;
  7950. t = state[15];
  7951. u = state[11];
  7952. v = state[7];
  7953. state[15] = state[3];
  7954. state[11] = t;
  7955. state[7] = u;
  7956. state[3] = v;
  7957. for (j = 0; j < 16; ++j) {
  7958. // InvSubBytes
  7959. state[j] = inv_s[state[j]];
  7960. // AddRoundKey
  7961. state[j] ^= key[j];
  7962. }
  7963. return state;
  7964. }
  7965. function encrypt128(input, key) {
  7966. var t, u, v, k;
  7967. var state = new Uint8Array(16);
  7968. state.set(input);
  7969. for (j = 0; j < 16; ++j) {
  7970. // AddRoundKey
  7971. state[j] ^= key[j];
  7972. }
  7973. for (i = 1; i < 10; i++) {
  7974. //SubBytes
  7975. for (j = 0; j < 16; ++j) {
  7976. state[j] = s[state[j]];
  7977. }
  7978. //ShiftRows
  7979. v = state[1];
  7980. state[1] = state[5];
  7981. state[5] = state[9];
  7982. state[9] = state[13];
  7983. state[13] = v;
  7984. v = state[2];
  7985. u = state[6];
  7986. state[2] = state[10];
  7987. state[6] = state[14];
  7988. state[10] = v;
  7989. state[14] = u;
  7990. v = state[3];
  7991. u = state[7];
  7992. t = state[11];
  7993. state[3] = state[15];
  7994. state[7] = v;
  7995. state[11] = u;
  7996. state[15] = t;
  7997. //MixColumns
  7998. for (var j = 0; j < 16; j += 4) {
  7999. var s0 = state[j + 0], s1 = state[j + 1];
  8000. var s2 = state[j + 2], s3 = state[j + 3];
  8001. t = s0 ^ s1 ^ s2 ^ s3;
  8002. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8003. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8004. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8005. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8006. }
  8007. //AddRoundKey
  8008. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8009. state[j] ^= key[k];
  8010. }
  8011. }
  8012. //SubBytes
  8013. for (j = 0; j < 16; ++j) {
  8014. state[j] = s[state[j]];
  8015. }
  8016. //ShiftRows
  8017. v = state[1];
  8018. state[1] = state[5];
  8019. state[5] = state[9];
  8020. state[9] = state[13];
  8021. state[13] = v;
  8022. v = state[2];
  8023. u = state[6];
  8024. state[2] = state[10];
  8025. state[6] = state[14];
  8026. state[10] = v;
  8027. state[14] = u;
  8028. v = state[3];
  8029. u = state[7];
  8030. t = state[11];
  8031. state[3] = state[15];
  8032. state[7] = v;
  8033. state[11] = u;
  8034. state[15] = t;
  8035. //AddRoundKey
  8036. for (j = 0, k = 160; j < 16; ++j, ++k) {
  8037. state[j] ^= key[k];
  8038. }
  8039. return state;
  8040. }
  8041. function AES128Cipher(key) {
  8042. this.key = expandKey128(key);
  8043. this.buffer = new Uint8Array(16);
  8044. this.bufferPosition = 0;
  8045. }
  8046. function decryptBlock2(data, finalize) {
  8047. var i, j, ii, sourceLength = data.length,
  8048. buffer = this.buffer, bufferLength = this.bufferPosition,
  8049. result = [], iv = this.iv;
  8050. for (i = 0; i < sourceLength; ++i) {
  8051. buffer[bufferLength] = data[i];
  8052. ++bufferLength;
  8053. if (bufferLength < 16) {
  8054. continue;
  8055. }
  8056. // buffer is full, decrypting
  8057. var plain = decrypt128(buffer, this.key);
  8058. // xor-ing the IV vector to get plain text
  8059. for (j = 0; j < 16; ++j) {
  8060. plain[j] ^= iv[j];
  8061. }
  8062. iv = buffer;
  8063. result.push(plain);
  8064. buffer = new Uint8Array(16);
  8065. bufferLength = 0;
  8066. }
  8067. // saving incomplete buffer
  8068. this.buffer = buffer;
  8069. this.bufferLength = bufferLength;
  8070. this.iv = iv;
  8071. if (result.length === 0) {
  8072. return new Uint8Array([]);
  8073. }
  8074. // combining plain text blocks into one
  8075. var outputLength = 16 * result.length;
  8076. if (finalize) {
  8077. // undo a padding that is described in RFC 2898
  8078. var lastBlock = result[result.length - 1];
  8079. var psLen = lastBlock[15];
  8080. if (psLen <= 16) {
  8081. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8082. if (lastBlock[i] !== psLen) {
  8083. // Invalid padding, assume that the block has no padding.
  8084. psLen = 0;
  8085. break;
  8086. }
  8087. }
  8088. outputLength -= psLen;
  8089. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8090. }
  8091. }
  8092. var output = new Uint8Array(outputLength);
  8093. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8094. output.set(result[i], j);
  8095. }
  8096. return output;
  8097. }
  8098. AES128Cipher.prototype = {
  8099. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  8100. var i, sourceLength = data.length;
  8101. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8102. // waiting for IV values -- they are at the start of the stream
  8103. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  8104. buffer[bufferLength] = data[i];
  8105. }
  8106. if (bufferLength < 16) {
  8107. // need more data
  8108. this.bufferLength = bufferLength;
  8109. return new Uint8Array([]);
  8110. }
  8111. this.iv = buffer;
  8112. this.buffer = new Uint8Array(16);
  8113. this.bufferLength = 0;
  8114. // starting decryption
  8115. this.decryptBlock = decryptBlock2;
  8116. return this.decryptBlock(data.subarray(16), finalize);
  8117. },
  8118. encrypt: function AES128Cipher_encrypt(data, iv) {
  8119. var i, j, ii, sourceLength = data.length,
  8120. buffer = this.buffer, bufferLength = this.bufferPosition,
  8121. result = [];
  8122. if (!iv) {
  8123. iv = new Uint8Array(16);
  8124. }
  8125. for (i = 0; i < sourceLength; ++i) {
  8126. buffer[bufferLength] = data[i];
  8127. ++bufferLength;
  8128. if (bufferLength < 16) {
  8129. continue;
  8130. }
  8131. for (j = 0; j < 16; ++j) {
  8132. buffer[j] ^= iv[j];
  8133. }
  8134. // buffer is full, encrypting
  8135. var cipher = encrypt128(buffer, this.key);
  8136. iv = cipher;
  8137. result.push(cipher);
  8138. buffer = new Uint8Array(16);
  8139. bufferLength = 0;
  8140. }
  8141. // saving incomplete buffer
  8142. this.buffer = buffer;
  8143. this.bufferLength = bufferLength;
  8144. this.iv = iv;
  8145. if (result.length === 0) {
  8146. return new Uint8Array([]);
  8147. }
  8148. // combining plain text blocks into one
  8149. var outputLength = 16 * result.length;
  8150. var output = new Uint8Array(outputLength);
  8151. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8152. output.set(result[i], j);
  8153. }
  8154. return output;
  8155. }
  8156. };
  8157. return AES128Cipher;
  8158. })();
  8159. var AES256Cipher = (function AES256CipherClosure() {
  8160. var rcon = new Uint8Array([
  8161. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8162. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8163. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8164. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8165. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  8166. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  8167. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  8168. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  8169. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  8170. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  8171. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  8172. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  8173. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  8174. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  8175. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  8176. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  8177. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  8178. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8179. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8180. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8181. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8182. 0x74, 0xe8, 0xcb, 0x8d]);
  8183. var s = new Uint8Array([
  8184. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  8185. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  8186. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  8187. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  8188. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  8189. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  8190. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  8191. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  8192. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  8193. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  8194. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  8195. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8196. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8197. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8198. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8199. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8200. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8201. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8202. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8203. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8204. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8205. 0xb0, 0x54, 0xbb, 0x16]);
  8206. var inv_s = new Uint8Array([
  8207. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8208. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8209. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8210. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8211. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8212. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8213. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8214. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8215. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8216. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8217. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8218. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8219. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8220. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8221. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8222. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8223. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8224. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8225. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8226. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8227. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8228. 0x55, 0x21, 0x0c, 0x7d]);
  8229. var mixCol = new Uint8Array(256);
  8230. for (var i = 0; i < 256; i++) {
  8231. if (i < 128) {
  8232. mixCol[i] = i << 1;
  8233. } else {
  8234. mixCol[i] = (i << 1) ^ 0x1b;
  8235. }
  8236. }
  8237. var mix = new Uint32Array([
  8238. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8239. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8240. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8241. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8242. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8243. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8244. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8245. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8246. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8247. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8248. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8249. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8250. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8251. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8252. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8253. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8254. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8255. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8256. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8257. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8258. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8259. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8260. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8261. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8262. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8263. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8264. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8265. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8266. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8267. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8268. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8269. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8270. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8271. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8272. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8273. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8274. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8275. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8276. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8277. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8278. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8279. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8280. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8281. function expandKey256(cipherKey) {
  8282. var b = 240, result = new Uint8Array(b);
  8283. var r = 1;
  8284. result.set(cipherKey);
  8285. for (var j = 32, i = 1; j < b; ++i) {
  8286. if (j % 32 === 16) {
  8287. t1 = s[t1];
  8288. t2 = s[t2];
  8289. t3 = s[t3];
  8290. t4 = s[t4];
  8291. } else if (j % 32 === 0) {
  8292. // RotWord
  8293. var t1 = result[j - 3], t2 = result[j - 2],
  8294. t3 = result[j - 1], t4 = result[j - 4];
  8295. // SubWord
  8296. t1 = s[t1];
  8297. t2 = s[t2];
  8298. t3 = s[t3];
  8299. t4 = s[t4];
  8300. // Rcon
  8301. t1 = t1 ^ r;
  8302. if ((r <<= 1) >= 256) {
  8303. r = (r ^ 0x1b) & 0xFF;
  8304. }
  8305. }
  8306. for (var n = 0; n < 4; ++n) {
  8307. result[j] = (t1 ^= result[j - 32]);
  8308. j++;
  8309. result[j] = (t2 ^= result[j - 32]);
  8310. j++;
  8311. result[j] = (t3 ^= result[j - 32]);
  8312. j++;
  8313. result[j] = (t4 ^= result[j - 32]);
  8314. j++;
  8315. }
  8316. }
  8317. return result;
  8318. }
  8319. function decrypt256(input, key) {
  8320. var state = new Uint8Array(16);
  8321. state.set(input);
  8322. var i, j, k;
  8323. var t, u, v;
  8324. // AddRoundKey
  8325. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8326. state[j] ^= key[k];
  8327. }
  8328. for (i = 13; i >= 1; --i) {
  8329. // InvShiftRows
  8330. t = state[13];
  8331. state[13] = state[9];
  8332. state[9] = state[5];
  8333. state[5] = state[1];
  8334. state[1] = t;
  8335. t = state[14];
  8336. u = state[10];
  8337. state[14] = state[6];
  8338. state[10] = state[2];
  8339. state[6] = t;
  8340. state[2] = u;
  8341. t = state[15];
  8342. u = state[11];
  8343. v = state[7];
  8344. state[15] = state[3];
  8345. state[11] = t;
  8346. state[7] = u;
  8347. state[3] = v;
  8348. // InvSubBytes
  8349. for (j = 0; j < 16; ++j) {
  8350. state[j] = inv_s[state[j]];
  8351. }
  8352. // AddRoundKey
  8353. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8354. state[j] ^= key[k];
  8355. }
  8356. // InvMixColumns
  8357. for (j = 0; j < 16; j += 4) {
  8358. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8359. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8360. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8361. (s3 >>> 24) ^ (s3 << 8));
  8362. state[j] = (t >>> 24) & 0xFF;
  8363. state[j + 1] = (t >> 16) & 0xFF;
  8364. state[j + 2] = (t >> 8) & 0xFF;
  8365. state[j + 3] = t & 0xFF;
  8366. }
  8367. }
  8368. // InvShiftRows
  8369. t = state[13];
  8370. state[13] = state[9];
  8371. state[9] = state[5];
  8372. state[5] = state[1];
  8373. state[1] = t;
  8374. t = state[14];
  8375. u = state[10];
  8376. state[14] = state[6];
  8377. state[10] = state[2];
  8378. state[6] = t;
  8379. state[2] = u;
  8380. t = state[15];
  8381. u = state[11];
  8382. v = state[7];
  8383. state[15] = state[3];
  8384. state[11] = t;
  8385. state[7] = u;
  8386. state[3] = v;
  8387. for (j = 0; j < 16; ++j) {
  8388. // InvSubBytes
  8389. state[j] = inv_s[state[j]];
  8390. // AddRoundKey
  8391. state[j] ^= key[j];
  8392. }
  8393. return state;
  8394. }
  8395. function encrypt256(input, key) {
  8396. var t, u, v, k;
  8397. var state = new Uint8Array(16);
  8398. state.set(input);
  8399. for (j = 0; j < 16; ++j) {
  8400. // AddRoundKey
  8401. state[j] ^= key[j];
  8402. }
  8403. for (i = 1; i < 14; i++) {
  8404. //SubBytes
  8405. for (j = 0; j < 16; ++j) {
  8406. state[j] = s[state[j]];
  8407. }
  8408. //ShiftRows
  8409. v = state[1];
  8410. state[1] = state[5];
  8411. state[5] = state[9];
  8412. state[9] = state[13];
  8413. state[13] = v;
  8414. v = state[2];
  8415. u = state[6];
  8416. state[2] = state[10];
  8417. state[6] = state[14];
  8418. state[10] = v;
  8419. state[14] = u;
  8420. v = state[3];
  8421. u = state[7];
  8422. t = state[11];
  8423. state[3] = state[15];
  8424. state[7] = v;
  8425. state[11] = u;
  8426. state[15] = t;
  8427. //MixColumns
  8428. for (var j = 0; j < 16; j += 4) {
  8429. var s0 = state[j + 0], s1 = state[j + 1];
  8430. var s2 = state[j + 2], s3 = state[j + 3];
  8431. t = s0 ^ s1 ^ s2 ^ s3;
  8432. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8433. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8434. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8435. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8436. }
  8437. //AddRoundKey
  8438. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8439. state[j] ^= key[k];
  8440. }
  8441. }
  8442. //SubBytes
  8443. for (j = 0; j < 16; ++j) {
  8444. state[j] = s[state[j]];
  8445. }
  8446. //ShiftRows
  8447. v = state[1];
  8448. state[1] = state[5];
  8449. state[5] = state[9];
  8450. state[9] = state[13];
  8451. state[13] = v;
  8452. v = state[2];
  8453. u = state[6];
  8454. state[2] = state[10];
  8455. state[6] = state[14];
  8456. state[10] = v;
  8457. state[14] = u;
  8458. v = state[3];
  8459. u = state[7];
  8460. t = state[11];
  8461. state[3] = state[15];
  8462. state[7] = v;
  8463. state[11] = u;
  8464. state[15] = t;
  8465. //AddRoundKey
  8466. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8467. state[j] ^= key[k];
  8468. }
  8469. return state;
  8470. }
  8471. function AES256Cipher(key) {
  8472. this.key = expandKey256(key);
  8473. this.buffer = new Uint8Array(16);
  8474. this.bufferPosition = 0;
  8475. }
  8476. function decryptBlock2(data, finalize) {
  8477. var i, j, ii, sourceLength = data.length,
  8478. buffer = this.buffer, bufferLength = this.bufferPosition,
  8479. result = [], iv = this.iv;
  8480. for (i = 0; i < sourceLength; ++i) {
  8481. buffer[bufferLength] = data[i];
  8482. ++bufferLength;
  8483. if (bufferLength < 16) {
  8484. continue;
  8485. }
  8486. // buffer is full, decrypting
  8487. var plain = decrypt256(buffer, this.key);
  8488. // xor-ing the IV vector to get plain text
  8489. for (j = 0; j < 16; ++j) {
  8490. plain[j] ^= iv[j];
  8491. }
  8492. iv = buffer;
  8493. result.push(plain);
  8494. buffer = new Uint8Array(16);
  8495. bufferLength = 0;
  8496. }
  8497. // saving incomplete buffer
  8498. this.buffer = buffer;
  8499. this.bufferLength = bufferLength;
  8500. this.iv = iv;
  8501. if (result.length === 0) {
  8502. return new Uint8Array([]);
  8503. }
  8504. // combining plain text blocks into one
  8505. var outputLength = 16 * result.length;
  8506. if (finalize) {
  8507. // undo a padding that is described in RFC 2898
  8508. var lastBlock = result[result.length - 1];
  8509. var psLen = lastBlock[15];
  8510. if (psLen <= 16) {
  8511. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8512. if (lastBlock[i] !== psLen) {
  8513. // Invalid padding, assume that the block has no padding.
  8514. psLen = 0;
  8515. break;
  8516. }
  8517. }
  8518. outputLength -= psLen;
  8519. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8520. }
  8521. }
  8522. var output = new Uint8Array(outputLength);
  8523. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8524. output.set(result[i], j);
  8525. }
  8526. return output;
  8527. }
  8528. AES256Cipher.prototype = {
  8529. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8530. var i, sourceLength = data.length;
  8531. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8532. // if not supplied an IV wait for IV values
  8533. // they are at the start of the stream
  8534. if (iv) {
  8535. this.iv = iv;
  8536. } else {
  8537. for (i = 0; bufferLength < 16 &&
  8538. i < sourceLength; ++i, ++bufferLength) {
  8539. buffer[bufferLength] = data[i];
  8540. }
  8541. if (bufferLength < 16) {
  8542. //need more data
  8543. this.bufferLength = bufferLength;
  8544. return new Uint8Array([]);
  8545. }
  8546. this.iv = buffer;
  8547. data = data.subarray(16);
  8548. }
  8549. this.buffer = new Uint8Array(16);
  8550. this.bufferLength = 0;
  8551. // starting decryption
  8552. this.decryptBlock = decryptBlock2;
  8553. return this.decryptBlock(data, finalize);
  8554. },
  8555. encrypt: function AES256Cipher_encrypt(data, iv) {
  8556. var i, j, ii, sourceLength = data.length,
  8557. buffer = this.buffer, bufferLength = this.bufferPosition,
  8558. result = [];
  8559. if (!iv) {
  8560. iv = new Uint8Array(16);
  8561. }
  8562. for (i = 0; i < sourceLength; ++i) {
  8563. buffer[bufferLength] = data[i];
  8564. ++bufferLength;
  8565. if (bufferLength < 16) {
  8566. continue;
  8567. }
  8568. for (j = 0; j < 16; ++j) {
  8569. buffer[j] ^= iv[j];
  8570. }
  8571. // buffer is full, encrypting
  8572. var cipher = encrypt256(buffer, this.key);
  8573. this.iv = cipher;
  8574. result.push(cipher);
  8575. buffer = new Uint8Array(16);
  8576. bufferLength = 0;
  8577. }
  8578. // saving incomplete buffer
  8579. this.buffer = buffer;
  8580. this.bufferLength = bufferLength;
  8581. this.iv = iv;
  8582. if (result.length === 0) {
  8583. return new Uint8Array([]);
  8584. }
  8585. // combining plain text blocks into one
  8586. var outputLength = 16 * result.length;
  8587. var output = new Uint8Array(outputLength);
  8588. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8589. output.set(result[i], j);
  8590. }
  8591. return output;
  8592. }
  8593. };
  8594. return AES256Cipher;
  8595. })();
  8596. var PDF17 = (function PDF17Closure() {
  8597. function compareByteArrays(array1, array2) {
  8598. if (array1.length !== array2.length) {
  8599. return false;
  8600. }
  8601. for (var i = 0; i < array1.length; i++) {
  8602. if (array1[i] !== array2[i]) {
  8603. return false;
  8604. }
  8605. }
  8606. return true;
  8607. }
  8608. function PDF17() {
  8609. }
  8610. PDF17.prototype = {
  8611. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8612. ownerValidationSalt,
  8613. userBytes,
  8614. ownerPassword) {
  8615. var hashData = new Uint8Array(password.length + 56);
  8616. hashData.set(password, 0);
  8617. hashData.set(ownerValidationSalt, password.length);
  8618. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8619. var result = calculateSHA256(hashData, 0, hashData.length);
  8620. return compareByteArrays(result, ownerPassword);
  8621. },
  8622. checkUserPassword: function PDF17_checkUserPassword(password,
  8623. userValidationSalt,
  8624. userPassword) {
  8625. var hashData = new Uint8Array(password.length + 8);
  8626. hashData.set(password, 0);
  8627. hashData.set(userValidationSalt, password.length);
  8628. var result = calculateSHA256(hashData, 0, hashData.length);
  8629. return compareByteArrays(result, userPassword);
  8630. },
  8631. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8632. ownerEncryption) {
  8633. var hashData = new Uint8Array(password.length + 56);
  8634. hashData.set(password, 0);
  8635. hashData.set(ownerKeySalt, password.length);
  8636. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8637. var key = calculateSHA256(hashData, 0, hashData.length);
  8638. var cipher = new AES256Cipher(key);
  8639. return cipher.decryptBlock(ownerEncryption,
  8640. false,
  8641. new Uint8Array(16));
  8642. },
  8643. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8644. userEncryption) {
  8645. var hashData = new Uint8Array(password.length + 8);
  8646. hashData.set(password, 0);
  8647. hashData.set(userKeySalt, password.length);
  8648. //key is the decryption key for the UE string
  8649. var key = calculateSHA256(hashData, 0, hashData.length);
  8650. var cipher = new AES256Cipher(key);
  8651. return cipher.decryptBlock(userEncryption,
  8652. false,
  8653. new Uint8Array(16));
  8654. }
  8655. };
  8656. return PDF17;
  8657. })();
  8658. var PDF20 = (function PDF20Closure() {
  8659. function concatArrays(array1, array2) {
  8660. var t = new Uint8Array(array1.length + array2.length);
  8661. t.set(array1, 0);
  8662. t.set(array2, array1.length);
  8663. return t;
  8664. }
  8665. function calculatePDF20Hash(password, input, userBytes) {
  8666. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8667. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8668. var e = [0];
  8669. var i = 0;
  8670. while (i < 64 || e[e.length - 1] > i - 32) {
  8671. var arrayLength = password.length + k.length + userBytes.length;
  8672. var k1 = new Uint8Array(arrayLength * 64);
  8673. var array = concatArrays(password, k);
  8674. array = concatArrays(array, userBytes);
  8675. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8676. k1.set(array, pos);
  8677. }
  8678. //AES128 CBC NO PADDING with
  8679. //first 16 bytes of k as the key and the second 16 as the iv.
  8680. var cipher = new AES128Cipher(k.subarray(0, 16));
  8681. e = cipher.encrypt(k1, k.subarray(16, 32));
  8682. //Now we have to take the first 16 bytes of an unsigned
  8683. //big endian integer... and compute the remainder
  8684. //modulo 3.... That is a fairly large number and
  8685. //JavaScript isn't going to handle that well...
  8686. //So we're using a trick that allows us to perform
  8687. //modulo math byte by byte
  8688. var remainder = 0;
  8689. for (var z = 0; z < 16; z++) {
  8690. remainder *= (256 % 3);
  8691. remainder %= 3;
  8692. remainder += ((e[z] >>> 0) % 3);
  8693. remainder %= 3;
  8694. }
  8695. if (remainder === 0) {
  8696. k = calculateSHA256(e, 0, e.length);
  8697. }
  8698. else if (remainder === 1) {
  8699. k = calculateSHA384(e, 0, e.length);
  8700. }
  8701. else if (remainder === 2) {
  8702. k = calculateSHA512(e, 0, e.length);
  8703. }
  8704. i++;
  8705. }
  8706. return k.subarray(0, 32);
  8707. }
  8708. function PDF20() {
  8709. }
  8710. function compareByteArrays(array1, array2) {
  8711. if (array1.length !== array2.length) {
  8712. return false;
  8713. }
  8714. for (var i = 0; i < array1.length; i++) {
  8715. if (array1[i] !== array2[i]) {
  8716. return false;
  8717. }
  8718. }
  8719. return true;
  8720. }
  8721. PDF20.prototype = {
  8722. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8723. return calculatePDF20Hash(password, concatBytes, userBytes);
  8724. },
  8725. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8726. ownerValidationSalt,
  8727. userBytes,
  8728. ownerPassword) {
  8729. var hashData = new Uint8Array(password.length + 56);
  8730. hashData.set(password, 0);
  8731. hashData.set(ownerValidationSalt, password.length);
  8732. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8733. var result = calculatePDF20Hash(password, hashData, userBytes);
  8734. return compareByteArrays(result, ownerPassword);
  8735. },
  8736. checkUserPassword: function PDF20_checkUserPassword(password,
  8737. userValidationSalt,
  8738. userPassword) {
  8739. var hashData = new Uint8Array(password.length + 8);
  8740. hashData.set(password, 0);
  8741. hashData.set(userValidationSalt, password.length);
  8742. var result = calculatePDF20Hash(password, hashData, []);
  8743. return compareByteArrays(result, userPassword);
  8744. },
  8745. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8746. ownerEncryption) {
  8747. var hashData = new Uint8Array(password.length + 56);
  8748. hashData.set(password, 0);
  8749. hashData.set(ownerKeySalt, password.length);
  8750. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8751. var key = calculatePDF20Hash(password, hashData, userBytes);
  8752. var cipher = new AES256Cipher(key);
  8753. return cipher.decryptBlock(ownerEncryption,
  8754. false,
  8755. new Uint8Array(16));
  8756. },
  8757. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8758. userEncryption) {
  8759. var hashData = new Uint8Array(password.length + 8);
  8760. hashData.set(password, 0);
  8761. hashData.set(userKeySalt, password.length);
  8762. //key is the decryption key for the UE string
  8763. var key = calculatePDF20Hash(password, hashData, []);
  8764. var cipher = new AES256Cipher(key);
  8765. return cipher.decryptBlock(userEncryption,
  8766. false,
  8767. new Uint8Array(16));
  8768. }
  8769. };
  8770. return PDF20;
  8771. })();
  8772. var CipherTransform = (function CipherTransformClosure() {
  8773. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8774. this.stringCipherConstructor = stringCipherConstructor;
  8775. this.streamCipherConstructor = streamCipherConstructor;
  8776. }
  8777. CipherTransform.prototype = {
  8778. createStream: function CipherTransform_createStream(stream, length) {
  8779. var cipher = new this.streamCipherConstructor();
  8780. return new DecryptStream(stream, length,
  8781. function cipherTransformDecryptStream(data, finalize) {
  8782. return cipher.decryptBlock(data, finalize);
  8783. }
  8784. );
  8785. },
  8786. decryptString: function CipherTransform_decryptString(s) {
  8787. var cipher = new this.stringCipherConstructor();
  8788. var data = stringToBytes(s);
  8789. data = cipher.decryptBlock(data, true);
  8790. return bytesToString(data);
  8791. }
  8792. };
  8793. return CipherTransform;
  8794. })();
  8795. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8796. var defaultPasswordBytes = new Uint8Array([
  8797. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8798. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8799. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8800. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8801. function createEncryptionKey20(revision, password, ownerPassword,
  8802. ownerValidationSalt, ownerKeySalt, uBytes,
  8803. userPassword, userValidationSalt, userKeySalt,
  8804. ownerEncryption, userEncryption, perms) {
  8805. if (password) {
  8806. var passwordLength = Math.min(127, password.length);
  8807. password = password.subarray(0, passwordLength);
  8808. } else {
  8809. password = [];
  8810. }
  8811. var pdfAlgorithm;
  8812. if (revision === 6) {
  8813. pdfAlgorithm = new PDF20();
  8814. } else {
  8815. pdfAlgorithm = new PDF17();
  8816. }
  8817. if (pdfAlgorithm) {
  8818. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8819. userPassword)) {
  8820. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8821. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  8822. ownerValidationSalt,
  8823. uBytes,
  8824. ownerPassword)) {
  8825. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8826. ownerEncryption);
  8827. }
  8828. }
  8829. return null;
  8830. }
  8831. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8832. flags, revision, keyLength, encryptMetadata) {
  8833. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8834. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8835. if (password) {
  8836. n = Math.min(32, password.length);
  8837. for (; i < n; ++i) {
  8838. hashData[i] = password[i];
  8839. }
  8840. }
  8841. j = 0;
  8842. while (i < 32) {
  8843. hashData[i++] = defaultPasswordBytes[j++];
  8844. }
  8845. // as now the padded password in the hashData[0..i]
  8846. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8847. hashData[i++] = ownerPassword[j];
  8848. }
  8849. hashData[i++] = flags & 0xFF;
  8850. hashData[i++] = (flags >> 8) & 0xFF;
  8851. hashData[i++] = (flags >> 16) & 0xFF;
  8852. hashData[i++] = (flags >>> 24) & 0xFF;
  8853. for (j = 0, n = fileId.length; j < n; ++j) {
  8854. hashData[i++] = fileId[j];
  8855. }
  8856. if (revision >= 4 && !encryptMetadata) {
  8857. hashData[i++] = 0xFF;
  8858. hashData[i++] = 0xFF;
  8859. hashData[i++] = 0xFF;
  8860. hashData[i++] = 0xFF;
  8861. }
  8862. var hash = calculateMD5(hashData, 0, i);
  8863. var keyLengthInBytes = keyLength >> 3;
  8864. if (revision >= 3) {
  8865. for (j = 0; j < 50; ++j) {
  8866. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8867. }
  8868. }
  8869. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8870. var cipher, checkData;
  8871. if (revision >= 3) {
  8872. for (i = 0; i < 32; ++i) {
  8873. hashData[i] = defaultPasswordBytes[i];
  8874. }
  8875. for (j = 0, n = fileId.length; j < n; ++j) {
  8876. hashData[i++] = fileId[j];
  8877. }
  8878. cipher = new ARCFourCipher(encryptionKey);
  8879. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8880. n = encryptionKey.length;
  8881. var derivedKey = new Uint8Array(n), k;
  8882. for (j = 1; j <= 19; ++j) {
  8883. for (k = 0; k < n; ++k) {
  8884. derivedKey[k] = encryptionKey[k] ^ j;
  8885. }
  8886. cipher = new ARCFourCipher(derivedKey);
  8887. checkData = cipher.encryptBlock(checkData);
  8888. }
  8889. for (j = 0, n = checkData.length; j < n; ++j) {
  8890. if (userPassword[j] !== checkData[j]) {
  8891. return null;
  8892. }
  8893. }
  8894. } else {
  8895. cipher = new ARCFourCipher(encryptionKey);
  8896. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8897. for (j = 0, n = checkData.length; j < n; ++j) {
  8898. if (userPassword[j] !== checkData[j]) {
  8899. return null;
  8900. }
  8901. }
  8902. }
  8903. return encryptionKey;
  8904. }
  8905. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8906. var hashData = new Uint8Array(32), i = 0, j, n;
  8907. n = Math.min(32, password.length);
  8908. for (; i < n; ++i) {
  8909. hashData[i] = password[i];
  8910. }
  8911. j = 0;
  8912. while (i < 32) {
  8913. hashData[i++] = defaultPasswordBytes[j++];
  8914. }
  8915. var hash = calculateMD5(hashData, 0, i);
  8916. var keyLengthInBytes = keyLength >> 3;
  8917. if (revision >= 3) {
  8918. for (j = 0; j < 50; ++j) {
  8919. hash = calculateMD5(hash, 0, hash.length);
  8920. }
  8921. }
  8922. var cipher, userPassword;
  8923. if (revision >= 3) {
  8924. userPassword = ownerPassword;
  8925. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8926. for (j = 19; j >= 0; j--) {
  8927. for (k = 0; k < keyLengthInBytes; ++k) {
  8928. derivedKey[k] = hash[k] ^ j;
  8929. }
  8930. cipher = new ARCFourCipher(derivedKey);
  8931. userPassword = cipher.encryptBlock(userPassword);
  8932. }
  8933. } else {
  8934. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8935. userPassword = cipher.encryptBlock(ownerPassword);
  8936. }
  8937. return userPassword;
  8938. }
  8939. var identityName = Name.get('Identity');
  8940. function CipherTransformFactory(dict, fileId, password) {
  8941. var filter = dict.get('Filter');
  8942. if (!isName(filter) || filter.name !== 'Standard') {
  8943. error('unknown encryption method');
  8944. }
  8945. this.dict = dict;
  8946. var algorithm = dict.get('V');
  8947. if (!isInt(algorithm) ||
  8948. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8949. algorithm !== 5)) {
  8950. error('unsupported encryption algorithm');
  8951. }
  8952. this.algorithm = algorithm;
  8953. var keyLength = dict.get('Length') || 40;
  8954. if (!isInt(keyLength) ||
  8955. keyLength < 40 || (keyLength % 8) !== 0) {
  8956. error('invalid key length');
  8957. }
  8958. // prepare keys
  8959. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8960. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8961. var flags = dict.get('P');
  8962. var revision = dict.get('R');
  8963. // meaningful when V is 4 or 5
  8964. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8965. dict.get('EncryptMetadata') !== false);
  8966. this.encryptMetadata = encryptMetadata;
  8967. var fileIdBytes = stringToBytes(fileId);
  8968. var passwordBytes;
  8969. if (password) {
  8970. if (revision === 6) {
  8971. try {
  8972. password = utf8StringToString(password);
  8973. } catch (ex) {
  8974. warn('CipherTransformFactory: ' +
  8975. 'Unable to convert UTF8 encoded password.');
  8976. }
  8977. }
  8978. passwordBytes = stringToBytes(password);
  8979. }
  8980. var encryptionKey;
  8981. if (algorithm !== 5) {
  8982. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8983. ownerPassword, userPassword, flags,
  8984. revision, keyLength, encryptMetadata);
  8985. }
  8986. else {
  8987. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8988. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8989. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8990. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8991. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8992. var ownerEncryption = stringToBytes(dict.get('OE'));
  8993. var userEncryption = stringToBytes(dict.get('UE'));
  8994. var perms = stringToBytes(dict.get('Perms'));
  8995. encryptionKey =
  8996. createEncryptionKey20(revision, passwordBytes,
  8997. ownerPassword, ownerValidationSalt,
  8998. ownerKeySalt, uBytes,
  8999. userPassword, userValidationSalt,
  9000. userKeySalt, ownerEncryption,
  9001. userEncryption, perms);
  9002. }
  9003. if (!encryptionKey && !password) {
  9004. throw new PasswordException('No password given',
  9005. PasswordResponses.NEED_PASSWORD);
  9006. } else if (!encryptionKey && password) {
  9007. // Attempting use the password as an owner password
  9008. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  9009. revision, keyLength);
  9010. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  9011. ownerPassword, userPassword, flags,
  9012. revision, keyLength, encryptMetadata);
  9013. }
  9014. if (!encryptionKey) {
  9015. throw new PasswordException('Incorrect Password',
  9016. PasswordResponses.INCORRECT_PASSWORD);
  9017. }
  9018. this.encryptionKey = encryptionKey;
  9019. if (algorithm >= 4) {
  9020. this.cf = dict.get('CF');
  9021. this.stmf = dict.get('StmF') || identityName;
  9022. this.strf = dict.get('StrF') || identityName;
  9023. this.eff = dict.get('EFF') || this.stmf;
  9024. }
  9025. }
  9026. function buildObjectKey(num, gen, encryptionKey, isAes) {
  9027. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  9028. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  9029. key[i] = encryptionKey[i];
  9030. }
  9031. key[i++] = num & 0xFF;
  9032. key[i++] = (num >> 8) & 0xFF;
  9033. key[i++] = (num >> 16) & 0xFF;
  9034. key[i++] = gen & 0xFF;
  9035. key[i++] = (gen >> 8) & 0xFF;
  9036. if (isAes) {
  9037. key[i++] = 0x73;
  9038. key[i++] = 0x41;
  9039. key[i++] = 0x6C;
  9040. key[i++] = 0x54;
  9041. }
  9042. var hash = calculateMD5(key, 0, i);
  9043. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  9044. }
  9045. function buildCipherConstructor(cf, name, num, gen, key) {
  9046. var cryptFilter = cf.get(name.name);
  9047. var cfm;
  9048. if (cryptFilter !== null && cryptFilter !== undefined) {
  9049. cfm = cryptFilter.get('CFM');
  9050. }
  9051. if (!cfm || cfm.name === 'None') {
  9052. return function cipherTransformFactoryBuildCipherConstructorNone() {
  9053. return new NullCipher();
  9054. };
  9055. }
  9056. if ('V2' === cfm.name) {
  9057. return function cipherTransformFactoryBuildCipherConstructorV2() {
  9058. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  9059. };
  9060. }
  9061. if ('AESV2' === cfm.name) {
  9062. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  9063. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  9064. };
  9065. }
  9066. if ('AESV3' === cfm.name) {
  9067. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  9068. return new AES256Cipher(key);
  9069. };
  9070. }
  9071. error('Unknown crypto method');
  9072. }
  9073. CipherTransformFactory.prototype = {
  9074. createCipherTransform:
  9075. function CipherTransformFactory_createCipherTransform(num, gen) {
  9076. if (this.algorithm === 4 || this.algorithm === 5) {
  9077. return new CipherTransform(
  9078. buildCipherConstructor(this.cf, this.stmf,
  9079. num, gen, this.encryptionKey),
  9080. buildCipherConstructor(this.cf, this.strf,
  9081. num, gen, this.encryptionKey));
  9082. }
  9083. // algorithms 1 and 2
  9084. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  9085. var cipherConstructor = function buildCipherCipherConstructor() {
  9086. return new ARCFourCipher(key);
  9087. };
  9088. return new CipherTransform(cipherConstructor, cipherConstructor);
  9089. }
  9090. };
  9091. return CipherTransformFactory;
  9092. })();
  9093. var ShadingType = {
  9094. FUNCTION_BASED: 1,
  9095. AXIAL: 2,
  9096. RADIAL: 3,
  9097. FREE_FORM_MESH: 4,
  9098. LATTICE_FORM_MESH: 5,
  9099. COONS_PATCH_MESH: 6,
  9100. TENSOR_PATCH_MESH: 7
  9101. };
  9102. var Pattern = (function PatternClosure() {
  9103. // Constructor should define this.getPattern
  9104. function Pattern() {
  9105. error('should not call Pattern constructor');
  9106. }
  9107. Pattern.prototype = {
  9108. // Input: current Canvas context
  9109. // Output: the appropriate fillStyle or strokeStyle
  9110. getPattern: function Pattern_getPattern(ctx) {
  9111. error('Should not call Pattern.getStyle: ' + ctx);
  9112. }
  9113. };
  9114. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  9115. res) {
  9116. var dict = isStream(shading) ? shading.dict : shading;
  9117. var type = dict.get('ShadingType');
  9118. try {
  9119. switch (type) {
  9120. case ShadingType.AXIAL:
  9121. case ShadingType.RADIAL:
  9122. // Both radial and axial shadings are handled by RadialAxial shading.
  9123. return new Shadings.RadialAxial(dict, matrix, xref, res);
  9124. case ShadingType.FREE_FORM_MESH:
  9125. case ShadingType.LATTICE_FORM_MESH:
  9126. case ShadingType.COONS_PATCH_MESH:
  9127. case ShadingType.TENSOR_PATCH_MESH:
  9128. return new Shadings.Mesh(shading, matrix, xref, res);
  9129. default:
  9130. throw new Error('Unsupported ShadingType: ' + type);
  9131. }
  9132. } catch (ex) {
  9133. if (ex instanceof MissingDataException) {
  9134. throw ex;
  9135. }
  9136. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  9137. warn(ex);
  9138. return new Shadings.Dummy();
  9139. }
  9140. };
  9141. return Pattern;
  9142. })();
  9143. var Shadings = {};
  9144. // A small number to offset the first/last color stops so we can insert ones to
  9145. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  9146. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  9147. // internally so we have to go bigger.
  9148. Shadings.SMALL_NUMBER = 1e-2;
  9149. // Radial and axial shading have very similar implementations
  9150. // If needed, the implementations can be broken into two classes
  9151. Shadings.RadialAxial = (function RadialAxialClosure() {
  9152. function RadialAxial(dict, matrix, xref, res) {
  9153. this.matrix = matrix;
  9154. this.coordsArr = dict.get('Coords');
  9155. this.shadingType = dict.get('ShadingType');
  9156. this.type = 'Pattern';
  9157. var cs = dict.get('ColorSpace', 'CS');
  9158. cs = ColorSpace.parse(cs, xref, res);
  9159. this.cs = cs;
  9160. var t0 = 0.0, t1 = 1.0;
  9161. if (dict.has('Domain')) {
  9162. var domainArr = dict.get('Domain');
  9163. t0 = domainArr[0];
  9164. t1 = domainArr[1];
  9165. }
  9166. var extendStart = false, extendEnd = false;
  9167. if (dict.has('Extend')) {
  9168. var extendArr = dict.get('Extend');
  9169. extendStart = extendArr[0];
  9170. extendEnd = extendArr[1];
  9171. }
  9172. if (this.shadingType === ShadingType.RADIAL &&
  9173. (!extendStart || !extendEnd)) {
  9174. // Radial gradient only currently works if either circle is fully within
  9175. // the other circle.
  9176. var x1 = this.coordsArr[0];
  9177. var y1 = this.coordsArr[1];
  9178. var r1 = this.coordsArr[2];
  9179. var x2 = this.coordsArr[3];
  9180. var y2 = this.coordsArr[4];
  9181. var r2 = this.coordsArr[5];
  9182. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  9183. if (r1 <= r2 + distance &&
  9184. r2 <= r1 + distance) {
  9185. warn('Unsupported radial gradient.');
  9186. }
  9187. }
  9188. this.extendStart = extendStart;
  9189. this.extendEnd = extendEnd;
  9190. var fnObj = dict.get('Function');
  9191. var fn = PDFFunction.parseArray(xref, fnObj);
  9192. // 10 samples seems good enough for now, but probably won't work
  9193. // if there are sharp color changes. Ideally, we would implement
  9194. // the spec faithfully and add lossless optimizations.
  9195. var diff = t1 - t0;
  9196. var step = diff / 10;
  9197. var colorStops = this.colorStops = [];
  9198. // Protect against bad domains so we don't end up in an infinte loop below.
  9199. if (t0 >= t1 || step <= 0) {
  9200. // Acrobat doesn't seem to handle these cases so we'll ignore for
  9201. // now.
  9202. info('Bad shading domain.');
  9203. return;
  9204. }
  9205. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  9206. var rgbColor;
  9207. for (var i = t0; i <= t1; i += step) {
  9208. ratio[0] = i;
  9209. fn(ratio, 0, color, 0);
  9210. rgbColor = cs.getRgb(color, 0);
  9211. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9212. colorStops.push([(i - t0) / diff, cssColor]);
  9213. }
  9214. var background = 'transparent';
  9215. if (dict.has('Background')) {
  9216. rgbColor = cs.getRgb(dict.get('Background'), 0);
  9217. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9218. }
  9219. if (!extendStart) {
  9220. // Insert a color stop at the front and offset the first real color stop
  9221. // so it doesn't conflict with the one we insert.
  9222. colorStops.unshift([0, background]);
  9223. colorStops[1][0] += Shadings.SMALL_NUMBER;
  9224. }
  9225. if (!extendEnd) {
  9226. // Same idea as above in extendStart but for the end.
  9227. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  9228. colorStops.push([1, background]);
  9229. }
  9230. this.colorStops = colorStops;
  9231. }
  9232. RadialAxial.prototype = {
  9233. getIR: function RadialAxial_getIR() {
  9234. var coordsArr = this.coordsArr;
  9235. var shadingType = this.shadingType;
  9236. var type, p0, p1, r0, r1;
  9237. if (shadingType === ShadingType.AXIAL) {
  9238. p0 = [coordsArr[0], coordsArr[1]];
  9239. p1 = [coordsArr[2], coordsArr[3]];
  9240. r0 = null;
  9241. r1 = null;
  9242. type = 'axial';
  9243. } else if (shadingType === ShadingType.RADIAL) {
  9244. p0 = [coordsArr[0], coordsArr[1]];
  9245. p1 = [coordsArr[3], coordsArr[4]];
  9246. r0 = coordsArr[2];
  9247. r1 = coordsArr[5];
  9248. type = 'radial';
  9249. } else {
  9250. error('getPattern type unknown: ' + shadingType);
  9251. }
  9252. var matrix = this.matrix;
  9253. if (matrix) {
  9254. p0 = Util.applyTransform(p0, matrix);
  9255. p1 = Util.applyTransform(p1, matrix);
  9256. }
  9257. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9258. }
  9259. };
  9260. return RadialAxial;
  9261. })();
  9262. // All mesh shading. For now, they will be presented as set of the triangles
  9263. // to be drawn on the canvas and rgb color for each vertex.
  9264. Shadings.Mesh = (function MeshClosure() {
  9265. function MeshStreamReader(stream, context) {
  9266. this.stream = stream;
  9267. this.context = context;
  9268. this.buffer = 0;
  9269. this.bufferLength = 0;
  9270. var numComps = context.numComps;
  9271. this.tmpCompsBuf = new Float32Array(numComps);
  9272. var csNumComps = context.colorSpace.numComps;
  9273. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9274. this.tmpCompsBuf;
  9275. }
  9276. MeshStreamReader.prototype = {
  9277. get hasData() {
  9278. if (this.stream.end) {
  9279. return this.stream.pos < this.stream.end;
  9280. }
  9281. if (this.bufferLength > 0) {
  9282. return true;
  9283. }
  9284. var nextByte = this.stream.getByte();
  9285. if (nextByte < 0) {
  9286. return false;
  9287. }
  9288. this.buffer = nextByte;
  9289. this.bufferLength = 8;
  9290. return true;
  9291. },
  9292. readBits: function MeshStreamReader_readBits(n) {
  9293. var buffer = this.buffer;
  9294. var bufferLength = this.bufferLength;
  9295. if (n === 32) {
  9296. if (bufferLength === 0) {
  9297. return ((this.stream.getByte() << 24) |
  9298. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9299. this.stream.getByte()) >>> 0;
  9300. }
  9301. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9302. (this.stream.getByte() << 8) | this.stream.getByte();
  9303. var nextByte = this.stream.getByte();
  9304. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9305. return ((buffer << (8 - bufferLength)) |
  9306. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9307. }
  9308. if (n === 8 && bufferLength === 0) {
  9309. return this.stream.getByte();
  9310. }
  9311. while (bufferLength < n) {
  9312. buffer = (buffer << 8) | this.stream.getByte();
  9313. bufferLength += 8;
  9314. }
  9315. bufferLength -= n;
  9316. this.bufferLength = bufferLength;
  9317. this.buffer = buffer & ((1 << bufferLength) - 1);
  9318. return buffer >> bufferLength;
  9319. },
  9320. align: function MeshStreamReader_align() {
  9321. this.buffer = 0;
  9322. this.bufferLength = 0;
  9323. },
  9324. readFlag: function MeshStreamReader_readFlag() {
  9325. return this.readBits(this.context.bitsPerFlag);
  9326. },
  9327. readCoordinate: function MeshStreamReader_readCoordinate() {
  9328. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9329. var xi = this.readBits(bitsPerCoordinate);
  9330. var yi = this.readBits(bitsPerCoordinate);
  9331. var decode = this.context.decode;
  9332. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9333. 2.3283064365386963e-10; // 2 ^ -32
  9334. return [
  9335. xi * scale * (decode[1] - decode[0]) + decode[0],
  9336. yi * scale * (decode[3] - decode[2]) + decode[2]
  9337. ];
  9338. },
  9339. readComponents: function MeshStreamReader_readComponents() {
  9340. var numComps = this.context.numComps;
  9341. var bitsPerComponent = this.context.bitsPerComponent;
  9342. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9343. 2.3283064365386963e-10; // 2 ^ -32
  9344. var decode = this.context.decode;
  9345. var components = this.tmpCompsBuf;
  9346. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9347. var ci = this.readBits(bitsPerComponent);
  9348. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9349. }
  9350. var color = this.tmpCsCompsBuf;
  9351. if (this.context.colorFn) {
  9352. this.context.colorFn(components, 0, color, 0);
  9353. }
  9354. return this.context.colorSpace.getRgb(color, 0);
  9355. }
  9356. };
  9357. function decodeType4Shading(mesh, reader) {
  9358. var coords = mesh.coords;
  9359. var colors = mesh.colors;
  9360. var operators = [];
  9361. var ps = []; // not maintaining cs since that will match ps
  9362. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9363. while (reader.hasData) {
  9364. var f = reader.readFlag();
  9365. var coord = reader.readCoordinate();
  9366. var color = reader.readComponents();
  9367. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9368. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9369. switch (f) {
  9370. case 0:
  9371. verticesLeft = 3;
  9372. break;
  9373. case 1:
  9374. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9375. verticesLeft = 1;
  9376. break;
  9377. case 2:
  9378. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9379. verticesLeft = 1;
  9380. break;
  9381. }
  9382. operators.push(f);
  9383. }
  9384. ps.push(coords.length);
  9385. coords.push(coord);
  9386. colors.push(color);
  9387. verticesLeft--;
  9388. reader.align();
  9389. }
  9390. mesh.figures.push({
  9391. type: 'triangles',
  9392. coords: new Int32Array(ps),
  9393. colors: new Int32Array(ps),
  9394. });
  9395. }
  9396. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9397. var coords = mesh.coords;
  9398. var colors = mesh.colors;
  9399. var ps = []; // not maintaining cs since that will match ps
  9400. while (reader.hasData) {
  9401. var coord = reader.readCoordinate();
  9402. var color = reader.readComponents();
  9403. ps.push(coords.length);
  9404. coords.push(coord);
  9405. colors.push(color);
  9406. }
  9407. mesh.figures.push({
  9408. type: 'lattice',
  9409. coords: new Int32Array(ps),
  9410. colors: new Int32Array(ps),
  9411. verticesPerRow: verticesPerRow
  9412. });
  9413. }
  9414. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9415. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9416. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9417. var getB = (function getBClosure() {
  9418. function buildB(count) {
  9419. var lut = [];
  9420. for (var i = 0; i <= count; i++) {
  9421. var t = i / count, t_ = 1 - t;
  9422. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9423. 3 * t * t * t_, t * t * t]));
  9424. }
  9425. return lut;
  9426. }
  9427. var cache = [];
  9428. return function getB(count) {
  9429. if (!cache[count]) {
  9430. cache[count] = buildB(count);
  9431. }
  9432. return cache[count];
  9433. };
  9434. })();
  9435. function buildFigureFromPatch(mesh, index) {
  9436. var figure = mesh.figures[index];
  9437. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9438. var coords = mesh.coords, colors = mesh.colors;
  9439. var pi = figure.coords;
  9440. var ci = figure.colors;
  9441. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9442. coords[pi[12]][0], coords[pi[15]][0]);
  9443. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9444. coords[pi[12]][1], coords[pi[15]][1]);
  9445. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9446. coords[pi[12]][0], coords[pi[15]][0]);
  9447. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9448. coords[pi[12]][1], coords[pi[15]][1]);
  9449. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9450. (mesh.bounds[2] - mesh.bounds[0]));
  9451. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9452. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9453. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9454. (mesh.bounds[3] - mesh.bounds[1]));
  9455. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9456. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9457. var verticesPerRow = splitXBy + 1;
  9458. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9459. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9460. var k = 0;
  9461. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9462. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9463. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9464. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9465. for (var row = 0; row <= splitYBy; row++) {
  9466. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9467. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9468. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9469. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9470. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9471. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9472. for (var col = 0; col <= splitXBy; col++, k++) {
  9473. if ((row === 0 || row === splitYBy) &&
  9474. (col === 0 || col === splitXBy)) {
  9475. continue;
  9476. }
  9477. var x = 0, y = 0;
  9478. var q = 0;
  9479. for (var i = 0; i <= 3; i++) {
  9480. for (var j = 0; j <= 3; j++, q++) {
  9481. var m = bRow[row][i] * bCol[col][j];
  9482. x += coords[pi[q]][0] * m;
  9483. y += coords[pi[q]][1] * m;
  9484. }
  9485. }
  9486. figureCoords[k] = coords.length;
  9487. coords.push([x, y]);
  9488. figureColors[k] = colors.length;
  9489. var newColor = new Uint8Array(3);
  9490. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9491. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9492. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9493. colors.push(newColor);
  9494. }
  9495. }
  9496. figureCoords[0] = pi[0];
  9497. figureColors[0] = ci[0];
  9498. figureCoords[splitXBy] = pi[3];
  9499. figureColors[splitXBy] = ci[1];
  9500. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9501. figureColors[verticesPerRow * splitYBy] = ci[2];
  9502. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9503. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9504. mesh.figures[index] = {
  9505. type: 'lattice',
  9506. coords: figureCoords,
  9507. colors: figureColors,
  9508. verticesPerRow: verticesPerRow
  9509. };
  9510. }
  9511. function decodeType6Shading(mesh, reader) {
  9512. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9513. var coords = mesh.coords;
  9514. var colors = mesh.colors;
  9515. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9516. var cs = new Int32Array(4); // c00, c30, c03, c33
  9517. while (reader.hasData) {
  9518. var f = reader.readFlag();
  9519. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9520. var i, ii;
  9521. var pi = coords.length;
  9522. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9523. coords.push(reader.readCoordinate());
  9524. }
  9525. var ci = colors.length;
  9526. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9527. colors.push(reader.readComponents());
  9528. }
  9529. var tmp1, tmp2, tmp3, tmp4;
  9530. switch (f) {
  9531. case 0:
  9532. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9533. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9534. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9535. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9536. cs[2] = ci + 1; cs[3] = ci + 2;
  9537. cs[0] = ci; cs[1] = ci + 3;
  9538. break;
  9539. case 1:
  9540. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9541. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9542. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  9543. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  9544. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9545. tmp1 = cs[2]; tmp2 = cs[3];
  9546. cs[2] = tmp2; cs[3] = ci;
  9547. cs[0] = tmp1; cs[1] = ci + 1;
  9548. break;
  9549. case 2:
  9550. tmp1 = ps[15];
  9551. tmp2 = ps[11];
  9552. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9553. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  9554. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  9555. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9556. tmp1 = cs[3];
  9557. cs[2] = cs[1]; cs[3] = ci;
  9558. cs[0] = tmp1; cs[1] = ci + 1;
  9559. break;
  9560. case 3:
  9561. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9562. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  9563. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  9564. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9565. cs[2] = cs[0]; cs[3] = ci;
  9566. cs[0] = cs[1]; cs[1] = ci + 1;
  9567. break;
  9568. }
  9569. // set p11, p12, p21, p22
  9570. ps[5] = coords.length;
  9571. coords.push([
  9572. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9573. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9574. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9575. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9576. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9577. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9578. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9579. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9580. ]);
  9581. ps[6] = coords.length;
  9582. coords.push([
  9583. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9584. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9585. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9586. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9587. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9588. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9589. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9590. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9591. ]);
  9592. ps[9] = coords.length;
  9593. coords.push([
  9594. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9595. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9596. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9597. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9598. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9599. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9600. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9601. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9602. ]);
  9603. ps[10] = coords.length;
  9604. coords.push([
  9605. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9606. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9607. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9608. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9609. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9610. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9611. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9612. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9613. ]);
  9614. mesh.figures.push({
  9615. type: 'patch',
  9616. coords: new Int32Array(ps), // making copies of ps and cs
  9617. colors: new Int32Array(cs)
  9618. });
  9619. }
  9620. }
  9621. function decodeType7Shading(mesh, reader) {
  9622. var coords = mesh.coords;
  9623. var colors = mesh.colors;
  9624. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9625. var cs = new Int32Array(4); // c00, c30, c03, c33
  9626. while (reader.hasData) {
  9627. var f = reader.readFlag();
  9628. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9629. var i, ii;
  9630. var pi = coords.length;
  9631. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9632. coords.push(reader.readCoordinate());
  9633. }
  9634. var ci = colors.length;
  9635. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9636. colors.push(reader.readComponents());
  9637. }
  9638. var tmp1, tmp2, tmp3, tmp4;
  9639. switch (f) {
  9640. case 0:
  9641. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9642. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9643. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9644. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9645. cs[2] = ci + 1; cs[3] = ci + 2;
  9646. cs[0] = ci; cs[1] = ci + 3;
  9647. break;
  9648. case 1:
  9649. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9650. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9651. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  9652. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  9653. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9654. tmp1 = cs[2]; tmp2 = cs[3];
  9655. cs[2] = tmp2; cs[3] = ci;
  9656. cs[0] = tmp1; cs[1] = ci + 1;
  9657. break;
  9658. case 2:
  9659. tmp1 = ps[15];
  9660. tmp2 = ps[11];
  9661. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9662. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  9663. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  9664. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9665. tmp1 = cs[3];
  9666. cs[2] = cs[1]; cs[3] = ci;
  9667. cs[0] = tmp1; cs[1] = ci + 1;
  9668. break;
  9669. case 3:
  9670. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  9671. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  9672. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  9673. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  9674. cs[2] = cs[0]; cs[3] = ci;
  9675. cs[0] = cs[1]; cs[1] = ci + 1;
  9676. break;
  9677. }
  9678. mesh.figures.push({
  9679. type: 'patch',
  9680. coords: new Int32Array(ps), // making copies of ps and cs
  9681. colors: new Int32Array(cs)
  9682. });
  9683. }
  9684. }
  9685. function updateBounds(mesh) {
  9686. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9687. maxX = minX, maxY = minY;
  9688. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9689. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9690. minX = minX > x ? x : minX;
  9691. minY = minY > y ? y : minY;
  9692. maxX = maxX < x ? x : maxX;
  9693. maxY = maxY < y ? y : maxY;
  9694. }
  9695. mesh.bounds = [minX, minY, maxX, maxY];
  9696. }
  9697. function packData(mesh) {
  9698. var i, ii, j, jj;
  9699. var coords = mesh.coords;
  9700. var coordsPacked = new Float32Array(coords.length * 2);
  9701. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9702. var xy = coords[i];
  9703. coordsPacked[j++] = xy[0];
  9704. coordsPacked[j++] = xy[1];
  9705. }
  9706. mesh.coords = coordsPacked;
  9707. var colors = mesh.colors;
  9708. var colorsPacked = new Uint8Array(colors.length * 3);
  9709. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9710. var c = colors[i];
  9711. colorsPacked[j++] = c[0];
  9712. colorsPacked[j++] = c[1];
  9713. colorsPacked[j++] = c[2];
  9714. }
  9715. mesh.colors = colorsPacked;
  9716. var figures = mesh.figures;
  9717. for (i = 0, ii = figures.length; i < ii; i++) {
  9718. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9719. for (j = 0, jj = ps.length; j < jj; j++) {
  9720. ps[j] *= 2;
  9721. cs[j] *= 3;
  9722. }
  9723. }
  9724. }
  9725. function Mesh(stream, matrix, xref, res) {
  9726. assert(isStream(stream), 'Mesh data is not a stream');
  9727. var dict = stream.dict;
  9728. this.matrix = matrix;
  9729. this.shadingType = dict.get('ShadingType');
  9730. this.type = 'Pattern';
  9731. this.bbox = dict.get('BBox');
  9732. var cs = dict.get('ColorSpace', 'CS');
  9733. cs = ColorSpace.parse(cs, xref, res);
  9734. this.cs = cs;
  9735. this.background = dict.has('Background') ?
  9736. cs.getRgb(dict.get('Background'), 0) : null;
  9737. var fnObj = dict.get('Function');
  9738. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9739. this.coords = [];
  9740. this.colors = [];
  9741. this.figures = [];
  9742. var decodeContext = {
  9743. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9744. bitsPerComponent: dict.get('BitsPerComponent'),
  9745. bitsPerFlag: dict.get('BitsPerFlag'),
  9746. decode: dict.get('Decode'),
  9747. colorFn: fn,
  9748. colorSpace: cs,
  9749. numComps: fn ? 1 : cs.numComps
  9750. };
  9751. var reader = new MeshStreamReader(stream, decodeContext);
  9752. var patchMesh = false;
  9753. switch (this.shadingType) {
  9754. case ShadingType.FREE_FORM_MESH:
  9755. decodeType4Shading(this, reader);
  9756. break;
  9757. case ShadingType.LATTICE_FORM_MESH:
  9758. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9759. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9760. decodeType5Shading(this, reader, verticesPerRow);
  9761. break;
  9762. case ShadingType.COONS_PATCH_MESH:
  9763. decodeType6Shading(this, reader);
  9764. patchMesh = true;
  9765. break;
  9766. case ShadingType.TENSOR_PATCH_MESH:
  9767. decodeType7Shading(this, reader);
  9768. patchMesh = true;
  9769. break;
  9770. default:
  9771. error('Unsupported mesh type.');
  9772. break;
  9773. }
  9774. if (patchMesh) {
  9775. // dirty bounds calculation for determining, how dense shall be triangles
  9776. updateBounds(this);
  9777. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9778. buildFigureFromPatch(this, i);
  9779. }
  9780. }
  9781. // calculate bounds
  9782. updateBounds(this);
  9783. packData(this);
  9784. }
  9785. Mesh.prototype = {
  9786. getIR: function Mesh_getIR() {
  9787. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9788. this.bounds, this.matrix, this.bbox, this.background];
  9789. }
  9790. };
  9791. return Mesh;
  9792. })();
  9793. Shadings.Dummy = (function DummyClosure() {
  9794. function Dummy() {
  9795. this.type = 'Pattern';
  9796. }
  9797. Dummy.prototype = {
  9798. getIR: function Dummy_getIR() {
  9799. return ['Dummy'];
  9800. }
  9801. };
  9802. return Dummy;
  9803. })();
  9804. function getTilingPatternIR(operatorList, dict, args) {
  9805. var matrix = dict.get('Matrix');
  9806. var bbox = dict.get('BBox');
  9807. var xstep = dict.get('XStep');
  9808. var ystep = dict.get('YStep');
  9809. var paintType = dict.get('PaintType');
  9810. var tilingType = dict.get('TilingType');
  9811. return [
  9812. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9813. paintType, tilingType
  9814. ];
  9815. }
  9816. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9817. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9818. uniquePrefix, idCounters, fontCache) {
  9819. this.pdfManager = pdfManager;
  9820. this.xref = xref;
  9821. this.handler = handler;
  9822. this.pageIndex = pageIndex;
  9823. this.uniquePrefix = uniquePrefix;
  9824. this.idCounters = idCounters;
  9825. this.fontCache = fontCache;
  9826. }
  9827. // Trying to minimize Date.now() usage and check every 100 time
  9828. var TIME_SLOT_DURATION_MS = 20;
  9829. var CHECK_TIME_EVERY = 100;
  9830. function TimeSlotManager() {
  9831. this.reset();
  9832. }
  9833. TimeSlotManager.prototype = {
  9834. check: function TimeSlotManager_check() {
  9835. if (++this.checked < CHECK_TIME_EVERY) {
  9836. return false;
  9837. }
  9838. this.checked = 0;
  9839. return this.endTime <= Date.now();
  9840. },
  9841. reset: function TimeSlotManager_reset() {
  9842. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9843. this.checked = 0;
  9844. }
  9845. };
  9846. var deferred = Promise.resolve();
  9847. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9848. PartialEvaluator.prototype = {
  9849. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9850. if (!isDict(resources)) {
  9851. return false;
  9852. }
  9853. var processed = Object.create(null);
  9854. if (resources.objId) {
  9855. processed[resources.objId] = true;
  9856. }
  9857. var nodes = [resources];
  9858. while (nodes.length) {
  9859. var key;
  9860. var node = nodes.shift();
  9861. // First check the current resources for blend modes.
  9862. var graphicStates = node.get('ExtGState');
  9863. if (isDict(graphicStates)) {
  9864. graphicStates = graphicStates.getAll();
  9865. for (key in graphicStates) {
  9866. var graphicState = graphicStates[key];
  9867. var bm = graphicState['BM'];
  9868. if (isName(bm) && bm.name !== 'Normal') {
  9869. return true;
  9870. }
  9871. }
  9872. }
  9873. // Descend into the XObjects to look for more resources and blend modes.
  9874. var xObjects = node.get('XObject');
  9875. if (!isDict(xObjects)) {
  9876. continue;
  9877. }
  9878. xObjects = xObjects.getAll();
  9879. for (key in xObjects) {
  9880. var xObject = xObjects[key];
  9881. if (!isStream(xObject)) {
  9882. continue;
  9883. }
  9884. if (xObject.dict.objId) {
  9885. if (processed[xObject.dict.objId]) {
  9886. // stream has objId and is processed already
  9887. continue;
  9888. }
  9889. processed[xObject.dict.objId] = true;
  9890. }
  9891. var xResources = xObject.dict.get('Resources');
  9892. // Checking objId to detect an infinite loop.
  9893. if (isDict(xResources) &&
  9894. (!xResources.objId || !processed[xResources.objId])) {
  9895. nodes.push(xResources);
  9896. if (xResources.objId) {
  9897. processed[xResources.objId] = true;
  9898. }
  9899. }
  9900. }
  9901. }
  9902. return false;
  9903. },
  9904. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9905. xobj, smask,
  9906. operatorList,
  9907. initialState) {
  9908. var matrix = xobj.dict.getArray('Matrix');
  9909. var bbox = xobj.dict.getArray('BBox');
  9910. var group = xobj.dict.get('Group');
  9911. if (group) {
  9912. var groupOptions = {
  9913. matrix: matrix,
  9914. bbox: bbox,
  9915. smask: smask,
  9916. isolated: false,
  9917. knockout: false
  9918. };
  9919. var groupSubtype = group.get('S');
  9920. var colorSpace;
  9921. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9922. groupOptions.isolated = (group.get('I') || false);
  9923. groupOptions.knockout = (group.get('K') || false);
  9924. colorSpace = (group.has('CS') ?
  9925. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9926. }
  9927. if (smask && smask.backdrop) {
  9928. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9929. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9930. }
  9931. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9932. }
  9933. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9934. return this.getOperatorList(xobj,
  9935. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9936. then(function () {
  9937. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9938. if (group) {
  9939. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9940. }
  9941. });
  9942. },
  9943. buildPaintImageXObject:
  9944. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9945. inline, operatorList,
  9946. cacheKey, imageCache) {
  9947. var self = this;
  9948. var dict = image.dict;
  9949. var w = dict.get('Width', 'W');
  9950. var h = dict.get('Height', 'H');
  9951. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9952. warn('Image dimensions are missing, or not numbers.');
  9953. return;
  9954. }
  9955. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9956. warn('Image exceeded maximum allowed size and was removed.');
  9957. return;
  9958. }
  9959. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9960. var imgData, args;
  9961. if (imageMask) {
  9962. // This depends on a tmpCanvas being filled with the
  9963. // current fillStyle, such that processing the pixel
  9964. // data can't be done here. Instead of creating a
  9965. // complete PDFImage, only read the information needed
  9966. // for later.
  9967. var width = dict.get('Width', 'W');
  9968. var height = dict.get('Height', 'H');
  9969. var bitStrideLength = (width + 7) >> 3;
  9970. var imgArray = image.getBytes(bitStrideLength * height);
  9971. var decode = dict.get('Decode', 'D');
  9972. var inverseDecode = (!!decode && decode[0] > 0);
  9973. imgData = PDFImage.createMask(imgArray, width, height,
  9974. image instanceof DecodeStream,
  9975. inverseDecode);
  9976. imgData.cached = true;
  9977. args = [imgData];
  9978. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9979. if (cacheKey) {
  9980. imageCache[cacheKey] = {
  9981. fn: OPS.paintImageMaskXObject,
  9982. args: args
  9983. };
  9984. }
  9985. return;
  9986. }
  9987. var softMask = (dict.get('SMask', 'SM') || false);
  9988. var mask = (dict.get('Mask') || false);
  9989. var SMALL_IMAGE_DIMENSIONS = 200;
  9990. // Inlining small images into the queue as RGB data
  9991. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9992. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9993. var imageObj = new PDFImage(this.xref, resources, image,
  9994. inline, null, null);
  9995. // We force the use of RGBA_32BPP images here, because we can't handle
  9996. // any other kind.
  9997. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9998. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9999. return;
  10000. }
  10001. // If there is no imageMask, create the PDFImage and a lot
  10002. // of image processing can be done here.
  10003. var uniquePrefix = (this.uniquePrefix || '');
  10004. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  10005. operatorList.addDependency(objId);
  10006. args = [objId, w, h];
  10007. if (!softMask && !mask && image instanceof JpegStream &&
  10008. image.isNativelySupported(this.xref, resources)) {
  10009. // These JPEGs don't need any more processing so we can just send it.
  10010. operatorList.addOp(OPS.paintJpegXObject, args);
  10011. this.handler.send('obj',
  10012. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  10013. return;
  10014. }
  10015. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  10016. then(function(imageObj) {
  10017. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  10018. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  10019. [imgData.data.buffer]);
  10020. }).then(undefined, function (reason) {
  10021. warn('Unable to decode image: ' + reason);
  10022. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  10023. });
  10024. operatorList.addOp(OPS.paintImageXObject, args);
  10025. if (cacheKey) {
  10026. imageCache[cacheKey] = {
  10027. fn: OPS.paintImageXObject,
  10028. args: args
  10029. };
  10030. }
  10031. },
  10032. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  10033. operatorList,
  10034. stateManager) {
  10035. var smaskContent = smask.get('G');
  10036. var smaskOptions = {
  10037. subtype: smask.get('S').name,
  10038. backdrop: smask.get('BC')
  10039. };
  10040. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  10041. operatorList, stateManager.state.clone());
  10042. },
  10043. handleTilingType:
  10044. function PartialEvaluator_handleTilingType(fn, args, resources,
  10045. pattern, patternDict,
  10046. operatorList) {
  10047. // Create an IR of the pattern code.
  10048. var tilingOpList = new OperatorList();
  10049. // Merge the available resources, to prevent issues when the patternDict
  10050. // is missing some /Resources entries (fixes issue6541.pdf).
  10051. var resourcesArray = [patternDict.get('Resources'), resources];
  10052. var patternResources = Dict.merge(this.xref, resourcesArray);
  10053. return this.getOperatorList(pattern, patternResources, tilingOpList).then(
  10054. function () {
  10055. // Add the dependencies to the parent operator list so they are
  10056. // resolved before sub operator list is executed synchronously.
  10057. operatorList.addDependencies(tilingOpList.dependencies);
  10058. operatorList.addOp(fn, getTilingPatternIR({
  10059. fnArray: tilingOpList.fnArray,
  10060. argsArray: tilingOpList.argsArray
  10061. }, patternDict, args));
  10062. });
  10063. },
  10064. handleSetFont:
  10065. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  10066. operatorList, state) {
  10067. // TODO(mack): Not needed?
  10068. var fontName;
  10069. if (fontArgs) {
  10070. fontArgs = fontArgs.slice();
  10071. fontName = fontArgs[0].name;
  10072. }
  10073. var self = this;
  10074. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  10075. function (translated) {
  10076. if (!translated.font.isType3Font) {
  10077. return translated;
  10078. }
  10079. return translated.loadType3Data(self, resources, operatorList).then(
  10080. function () {
  10081. return translated;
  10082. });
  10083. }).then(function (translated) {
  10084. state.font = translated.font;
  10085. translated.send(self.handler);
  10086. return translated.loadedName;
  10087. });
  10088. },
  10089. handleText: function PartialEvaluator_handleText(chars, state) {
  10090. var font = state.font;
  10091. var glyphs = font.charsToGlyphs(chars);
  10092. var isAddToPathSet = !!(state.textRenderingMode &
  10093. TextRenderingMode.ADD_TO_PATH_FLAG);
  10094. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  10095. var buildPath = function (fontChar) {
  10096. if (!font.renderer.hasBuiltPath(fontChar)) {
  10097. var path = font.renderer.getPathJs(fontChar);
  10098. this.handler.send('commonobj', [
  10099. font.loadedName + '_path_' + fontChar,
  10100. 'FontPath',
  10101. path
  10102. ]);
  10103. }
  10104. }.bind(this);
  10105. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  10106. var glyph = glyphs[i];
  10107. if (glyph === null) {
  10108. continue;
  10109. }
  10110. buildPath(glyph.fontChar);
  10111. // If the glyph has an accent we need to build a path for its
  10112. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  10113. var accent = glyph.accent;
  10114. if (accent && accent.fontChar) {
  10115. buildPath(accent.fontChar);
  10116. }
  10117. }
  10118. }
  10119. return glyphs;
  10120. },
  10121. setGState: function PartialEvaluator_setGState(resources, gState,
  10122. operatorList, xref,
  10123. stateManager) {
  10124. // This array holds the converted/processed state data.
  10125. var gStateObj = [];
  10126. var gStateMap = gState.map;
  10127. var self = this;
  10128. var promise = Promise.resolve();
  10129. for (var key in gStateMap) {
  10130. var value = gStateMap[key];
  10131. switch (key) {
  10132. case 'Type':
  10133. break;
  10134. case 'LW':
  10135. case 'LC':
  10136. case 'LJ':
  10137. case 'ML':
  10138. case 'D':
  10139. case 'RI':
  10140. case 'FL':
  10141. case 'CA':
  10142. case 'ca':
  10143. gStateObj.push([key, value]);
  10144. break;
  10145. case 'Font':
  10146. promise = promise.then(function () {
  10147. return self.handleSetFont(resources, null, value[0],
  10148. operatorList, stateManager.state).
  10149. then(function (loadedName) {
  10150. operatorList.addDependency(loadedName);
  10151. gStateObj.push([key, [loadedName, value[1]]]);
  10152. });
  10153. });
  10154. break;
  10155. case 'BM':
  10156. gStateObj.push([key, value]);
  10157. break;
  10158. case 'SMask':
  10159. if (isName(value) && value.name === 'None') {
  10160. gStateObj.push([key, false]);
  10161. break;
  10162. }
  10163. var dict = xref.fetchIfRef(value);
  10164. if (isDict(dict)) {
  10165. promise = promise.then(function () {
  10166. return self.handleSMask(dict, resources, operatorList,
  10167. stateManager);
  10168. });
  10169. gStateObj.push([key, true]);
  10170. } else {
  10171. warn('Unsupported SMask type');
  10172. }
  10173. break;
  10174. // Only generate info log messages for the following since
  10175. // they are unlikely to have a big impact on the rendering.
  10176. case 'OP':
  10177. case 'op':
  10178. case 'OPM':
  10179. case 'BG':
  10180. case 'BG2':
  10181. case 'UCR':
  10182. case 'UCR2':
  10183. case 'TR':
  10184. case 'TR2':
  10185. case 'HT':
  10186. case 'SM':
  10187. case 'SA':
  10188. case 'AIS':
  10189. case 'TK':
  10190. // TODO implement these operators.
  10191. info('graphic state operator ' + key);
  10192. break;
  10193. default:
  10194. info('Unknown graphic state operator ' + key);
  10195. break;
  10196. }
  10197. }
  10198. return promise.then(function () {
  10199. if (gStateObj.length >= 0) {
  10200. operatorList.addOp(OPS.setGState, [gStateObj]);
  10201. }
  10202. });
  10203. },
  10204. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  10205. resources) {
  10206. function errorFont() {
  10207. return Promise.resolve(new TranslatedFont('g_font_error',
  10208. new ErrorFont('Font ' + fontName + ' is not available'), font));
  10209. }
  10210. var fontRef;
  10211. if (font) { // Loading by ref.
  10212. assert(isRef(font));
  10213. fontRef = font;
  10214. } else { // Loading by name.
  10215. var fontRes = resources.get('Font');
  10216. if (fontRes) {
  10217. fontRef = fontRes.getRaw(fontName);
  10218. } else {
  10219. warn('fontRes not available');
  10220. return errorFont();
  10221. }
  10222. }
  10223. if (!fontRef) {
  10224. warn('fontRef not available');
  10225. return errorFont();
  10226. }
  10227. if (this.fontCache.has(fontRef)) {
  10228. return this.fontCache.get(fontRef);
  10229. }
  10230. font = xref.fetchIfRef(fontRef);
  10231. if (!isDict(font)) {
  10232. return errorFont();
  10233. }
  10234. // We are holding font.translated references just for fontRef that are not
  10235. // dictionaries (Dict). See explanation below.
  10236. if (font.translated) {
  10237. return font.translated;
  10238. }
  10239. var fontCapability = createPromiseCapability();
  10240. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  10241. var descriptor = preEvaluatedFont.descriptor;
  10242. var fontID = fontRef.num + '_' + fontRef.gen;
  10243. if (isDict(descriptor)) {
  10244. if (!descriptor.fontAliases) {
  10245. descriptor.fontAliases = Object.create(null);
  10246. }
  10247. var fontAliases = descriptor.fontAliases;
  10248. var hash = preEvaluatedFont.hash;
  10249. if (fontAliases[hash]) {
  10250. var aliasFontRef = fontAliases[hash].aliasRef;
  10251. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10252. this.fontCache.putAlias(fontRef, aliasFontRef);
  10253. return this.fontCache.get(fontRef);
  10254. }
  10255. }
  10256. if (!fontAliases[hash]) {
  10257. fontAliases[hash] = {
  10258. fontID: Font.getFontID()
  10259. };
  10260. }
  10261. fontAliases[hash].aliasRef = fontRef;
  10262. fontID = fontAliases[hash].fontID;
  10263. }
  10264. // Workaround for bad PDF generators that don't reference fonts
  10265. // properly, i.e. by not using an object identifier.
  10266. // Check if the fontRef is a Dict (as opposed to a standard object),
  10267. // in which case we don't cache the font and instead reference it by
  10268. // fontName in font.loadedName below.
  10269. var fontRefIsDict = isDict(fontRef);
  10270. if (!fontRefIsDict) {
  10271. this.fontCache.put(fontRef, fontCapability.promise);
  10272. }
  10273. // Keep track of each font we translated so the caller can
  10274. // load them asynchronously before calling display on a page.
  10275. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10276. fontName.replace(/\W/g, '') : fontID);
  10277. font.translated = fontCapability.promise;
  10278. // TODO move promises into translate font
  10279. var translatedPromise;
  10280. try {
  10281. translatedPromise = Promise.resolve(
  10282. this.translateFont(preEvaluatedFont, xref));
  10283. } catch (e) {
  10284. translatedPromise = Promise.reject(e);
  10285. }
  10286. translatedPromise.then(function (translatedFont) {
  10287. if (translatedFont.fontType !== undefined) {
  10288. var xrefFontStats = xref.stats.fontTypes;
  10289. xrefFontStats[translatedFont.fontType] = true;
  10290. }
  10291. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10292. translatedFont, font));
  10293. }, function (reason) {
  10294. // TODO fontCapability.reject?
  10295. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10296. try {
  10297. // error, but it's still nice to have font type reported
  10298. var descriptor = preEvaluatedFont.descriptor;
  10299. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10300. var subtype = fontFile3 && fontFile3.get('Subtype');
  10301. var fontType = getFontType(preEvaluatedFont.type,
  10302. subtype && subtype.name);
  10303. var xrefFontStats = xref.stats.fontTypes;
  10304. xrefFontStats[fontType] = true;
  10305. } catch (ex) { }
  10306. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10307. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10308. font));
  10309. });
  10310. return fontCapability.promise;
  10311. },
  10312. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10313. var lastIndex = operatorList.length - 1;
  10314. if (!args) {
  10315. args = [];
  10316. }
  10317. if (lastIndex < 0 ||
  10318. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10319. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10320. } else {
  10321. var opArgs = operatorList.argsArray[lastIndex];
  10322. opArgs[0].push(fn);
  10323. Array.prototype.push.apply(opArgs[1], args);
  10324. }
  10325. },
  10326. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10327. cs, patterns, resources, xref) {
  10328. // compile tiling patterns
  10329. var patternName = args[args.length - 1];
  10330. // SCN/scn applies patterns along with normal colors
  10331. var pattern;
  10332. if (isName(patternName) &&
  10333. (pattern = patterns.get(patternName.name))) {
  10334. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10335. var typeNum = dict.get('PatternType');
  10336. if (typeNum === TILING_PATTERN) {
  10337. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10338. return this.handleTilingType(fn, color, resources, pattern,
  10339. dict, operatorList);
  10340. } else if (typeNum === SHADING_PATTERN) {
  10341. var shading = dict.get('Shading');
  10342. var matrix = dict.get('Matrix');
  10343. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10344. operatorList.addOp(fn, pattern.getIR());
  10345. return Promise.resolve();
  10346. } else {
  10347. return Promise.reject('Unknown PatternType: ' + typeNum);
  10348. }
  10349. }
  10350. // TODO shall we fail here?
  10351. operatorList.addOp(fn, args);
  10352. return Promise.resolve();
  10353. },
  10354. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10355. resources,
  10356. operatorList,
  10357. initialState) {
  10358. var self = this;
  10359. var xref = this.xref;
  10360. var imageCache = {};
  10361. assert(operatorList);
  10362. resources = (resources || Dict.empty);
  10363. var xobjs = (resources.get('XObject') || Dict.empty);
  10364. var patterns = (resources.get('Pattern') || Dict.empty);
  10365. var stateManager = new StateManager(initialState || new EvalState());
  10366. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10367. var timeSlotManager = new TimeSlotManager();
  10368. return new Promise(function next(resolve, reject) {
  10369. timeSlotManager.reset();
  10370. var stop, operation = {}, i, ii, cs;
  10371. while (!(stop = timeSlotManager.check())) {
  10372. // The arguments parsed by read() are used beyond this loop, so we
  10373. // cannot reuse the same array on each iteration. Therefore we pass
  10374. // in |null| as the initial value (see the comment on
  10375. // EvaluatorPreprocessor_read() for why).
  10376. operation.args = null;
  10377. if (!(preprocessor.read(operation))) {
  10378. break;
  10379. }
  10380. var args = operation.args;
  10381. var fn = operation.fn;
  10382. switch (fn | 0) {
  10383. case OPS.paintXObject:
  10384. if (args[0].code) {
  10385. break;
  10386. }
  10387. // eagerly compile XForm objects
  10388. var name = args[0].name;
  10389. if (!name) {
  10390. warn('XObject must be referred to by name.');
  10391. continue;
  10392. }
  10393. if (imageCache[name] !== undefined) {
  10394. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10395. args = null;
  10396. continue;
  10397. }
  10398. var xobj = xobjs.get(name);
  10399. if (xobj) {
  10400. assert(isStream(xobj), 'XObject should be a stream');
  10401. var type = xobj.dict.get('Subtype');
  10402. assert(isName(type),
  10403. 'XObject should have a Name subtype');
  10404. if (type.name === 'Form') {
  10405. stateManager.save();
  10406. return self.buildFormXObject(resources, xobj, null,
  10407. operatorList,
  10408. stateManager.state.clone()).
  10409. then(function () {
  10410. stateManager.restore();
  10411. next(resolve, reject);
  10412. }, reject);
  10413. } else if (type.name === 'Image') {
  10414. self.buildPaintImageXObject(resources, xobj, false,
  10415. operatorList, name, imageCache);
  10416. args = null;
  10417. continue;
  10418. } else if (type.name === 'PS') {
  10419. // PostScript XObjects are unused when viewing documents.
  10420. // See section 4.7.1 of Adobe's PDF reference.
  10421. info('Ignored XObject subtype PS');
  10422. continue;
  10423. } else {
  10424. error('Unhandled XObject subtype ' + type.name);
  10425. }
  10426. }
  10427. break;
  10428. case OPS.setFont:
  10429. var fontSize = args[1];
  10430. // eagerly collect all fonts
  10431. return self.handleSetFont(resources, args, null,
  10432. operatorList, stateManager.state).
  10433. then(function (loadedName) {
  10434. operatorList.addDependency(loadedName);
  10435. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10436. next(resolve, reject);
  10437. }, reject);
  10438. case OPS.endInlineImage:
  10439. var cacheKey = args[0].cacheKey;
  10440. if (cacheKey) {
  10441. var cacheEntry = imageCache[cacheKey];
  10442. if (cacheEntry !== undefined) {
  10443. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10444. args = null;
  10445. continue;
  10446. }
  10447. }
  10448. self.buildPaintImageXObject(resources, args[0], true,
  10449. operatorList, cacheKey, imageCache);
  10450. args = null;
  10451. continue;
  10452. case OPS.showText:
  10453. args[0] = self.handleText(args[0], stateManager.state);
  10454. break;
  10455. case OPS.showSpacedText:
  10456. var arr = args[0];
  10457. var combinedGlyphs = [];
  10458. var arrLength = arr.length;
  10459. var state = stateManager.state;
  10460. for (i = 0; i < arrLength; ++i) {
  10461. var arrItem = arr[i];
  10462. if (isString(arrItem)) {
  10463. Array.prototype.push.apply(combinedGlyphs,
  10464. self.handleText(arrItem, state));
  10465. } else if (isNum(arrItem)) {
  10466. combinedGlyphs.push(arrItem);
  10467. }
  10468. }
  10469. args[0] = combinedGlyphs;
  10470. fn = OPS.showText;
  10471. break;
  10472. case OPS.nextLineShowText:
  10473. operatorList.addOp(OPS.nextLine);
  10474. args[0] = self.handleText(args[0], stateManager.state);
  10475. fn = OPS.showText;
  10476. break;
  10477. case OPS.nextLineSetSpacingShowText:
  10478. operatorList.addOp(OPS.nextLine);
  10479. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10480. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10481. args[0] = self.handleText(args[0], stateManager.state);
  10482. fn = OPS.showText;
  10483. break;
  10484. case OPS.setTextRenderingMode:
  10485. stateManager.state.textRenderingMode = args[0];
  10486. break;
  10487. case OPS.setFillColorSpace:
  10488. stateManager.state.fillColorSpace =
  10489. ColorSpace.parse(args[0], xref, resources);
  10490. continue;
  10491. case OPS.setStrokeColorSpace:
  10492. stateManager.state.strokeColorSpace =
  10493. ColorSpace.parse(args[0], xref, resources);
  10494. continue;
  10495. case OPS.setFillColor:
  10496. cs = stateManager.state.fillColorSpace;
  10497. args = cs.getRgb(args, 0);
  10498. fn = OPS.setFillRGBColor;
  10499. break;
  10500. case OPS.setStrokeColor:
  10501. cs = stateManager.state.strokeColorSpace;
  10502. args = cs.getRgb(args, 0);
  10503. fn = OPS.setStrokeRGBColor;
  10504. break;
  10505. case OPS.setFillGray:
  10506. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10507. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10508. fn = OPS.setFillRGBColor;
  10509. break;
  10510. case OPS.setStrokeGray:
  10511. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10512. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10513. fn = OPS.setStrokeRGBColor;
  10514. break;
  10515. case OPS.setFillCMYKColor:
  10516. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10517. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10518. fn = OPS.setFillRGBColor;
  10519. break;
  10520. case OPS.setStrokeCMYKColor:
  10521. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10522. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10523. fn = OPS.setStrokeRGBColor;
  10524. break;
  10525. case OPS.setFillRGBColor:
  10526. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10527. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10528. break;
  10529. case OPS.setStrokeRGBColor:
  10530. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10531. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10532. break;
  10533. case OPS.setFillColorN:
  10534. cs = stateManager.state.fillColorSpace;
  10535. if (cs.name === 'Pattern') {
  10536. return self.handleColorN(operatorList, OPS.setFillColorN,
  10537. args, cs, patterns, resources, xref).then(function() {
  10538. next(resolve, reject);
  10539. }, reject);
  10540. }
  10541. args = cs.getRgb(args, 0);
  10542. fn = OPS.setFillRGBColor;
  10543. break;
  10544. case OPS.setStrokeColorN:
  10545. cs = stateManager.state.strokeColorSpace;
  10546. if (cs.name === 'Pattern') {
  10547. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10548. args, cs, patterns, resources, xref).then(function() {
  10549. next(resolve, reject);
  10550. }, reject);
  10551. }
  10552. args = cs.getRgb(args, 0);
  10553. fn = OPS.setStrokeRGBColor;
  10554. break;
  10555. case OPS.shadingFill:
  10556. var shadingRes = resources.get('Shading');
  10557. if (!shadingRes) {
  10558. error('No shading resource found');
  10559. }
  10560. var shading = shadingRes.get(args[0].name);
  10561. if (!shading) {
  10562. error('No shading object found');
  10563. }
  10564. var shadingFill = Pattern.parseShading(shading, null, xref,
  10565. resources);
  10566. var patternIR = shadingFill.getIR();
  10567. args = [patternIR];
  10568. fn = OPS.shadingFill;
  10569. break;
  10570. case OPS.setGState:
  10571. var dictName = args[0];
  10572. var extGState = resources.get('ExtGState');
  10573. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10574. break;
  10575. }
  10576. var gState = extGState.get(dictName.name);
  10577. return self.setGState(resources, gState, operatorList, xref,
  10578. stateManager).then(function() {
  10579. next(resolve, reject);
  10580. }, reject);
  10581. case OPS.moveTo:
  10582. case OPS.lineTo:
  10583. case OPS.curveTo:
  10584. case OPS.curveTo2:
  10585. case OPS.curveTo3:
  10586. case OPS.closePath:
  10587. self.buildPath(operatorList, fn, args);
  10588. continue;
  10589. case OPS.rectangle:
  10590. self.buildPath(operatorList, fn, args);
  10591. continue;
  10592. case OPS.markPoint:
  10593. case OPS.markPointProps:
  10594. case OPS.beginMarkedContent:
  10595. case OPS.beginMarkedContentProps:
  10596. case OPS.endMarkedContent:
  10597. case OPS.beginCompat:
  10598. case OPS.endCompat:
  10599. // Ignore operators where the corresponding handlers are known to
  10600. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  10601. // serialization errors and is also a bit more efficient.
  10602. // We could also try to serialize all objects in a general way,
  10603. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  10604. // but doing so is meaningless without knowing the semantics.
  10605. continue;
  10606. default:
  10607. // Note: Let's hope that the ignored operator does not have any
  10608. // non-serializable arguments, otherwise postMessage will throw
  10609. // "An object could not be cloned.".
  10610. }
  10611. operatorList.addOp(fn, args);
  10612. }
  10613. if (stop) {
  10614. deferred.then(function () {
  10615. next(resolve, reject);
  10616. });
  10617. return;
  10618. }
  10619. // Some PDFs don't close all restores inside object/form.
  10620. // Closing those for them.
  10621. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10622. operatorList.addOp(OPS.restore, []);
  10623. }
  10624. resolve();
  10625. });
  10626. },
  10627. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10628. stateManager) {
  10629. stateManager = (stateManager || new StateManager(new TextState()));
  10630. var textContent = {
  10631. items: [],
  10632. styles: Object.create(null)
  10633. };
  10634. var bidiTexts = textContent.items;
  10635. var SPACE_FACTOR = 0.3;
  10636. var MULTI_SPACE_FACTOR = 1.5;
  10637. var self = this;
  10638. var xref = this.xref;
  10639. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10640. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10641. var xobjs = null;
  10642. var xobjsCache = {};
  10643. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10644. var textState;
  10645. function newTextChunk() {
  10646. var font = textState.font;
  10647. if (!(font.loadedName in textContent.styles)) {
  10648. textContent.styles[font.loadedName] = {
  10649. fontFamily: font.fallbackName,
  10650. ascent: font.ascent,
  10651. descent: font.descent,
  10652. vertical: font.vertical
  10653. };
  10654. }
  10655. return {
  10656. // |str| is initially an array which we push individual chars to, and
  10657. // then runBidi() overwrites it with the final string.
  10658. str: [],
  10659. dir: null,
  10660. width: 0,
  10661. height: 0,
  10662. transform: null,
  10663. fontName: font.loadedName
  10664. };
  10665. }
  10666. function runBidi(textChunk) {
  10667. var str = textChunk.str.join('');
  10668. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10669. textChunk.str = bidiResult.str;
  10670. textChunk.dir = bidiResult.dir;
  10671. return textChunk;
  10672. }
  10673. function handleSetFont(fontName, fontRef) {
  10674. return self.loadFont(fontName, fontRef, xref, resources).
  10675. then(function (translated) {
  10676. textState.font = translated.font;
  10677. textState.fontMatrix = translated.font.fontMatrix ||
  10678. FONT_IDENTITY_MATRIX;
  10679. });
  10680. }
  10681. function buildTextGeometry(chars, textChunk) {
  10682. var font = textState.font;
  10683. textChunk = textChunk || newTextChunk();
  10684. if (!textChunk.transform) {
  10685. // 9.4.4 Text Space Details
  10686. var tsm = [textState.fontSize * textState.textHScale, 0,
  10687. 0, textState.fontSize,
  10688. 0, textState.textRise];
  10689. if (font.isType3Font &&
  10690. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  10691. textState.fontSize === 1) {
  10692. var glyphHeight = font.bbox[3] - font.bbox[1];
  10693. if (glyphHeight > 0) {
  10694. glyphHeight = glyphHeight * textState.fontMatrix[3];
  10695. tsm[3] *= glyphHeight;
  10696. }
  10697. }
  10698. var trm = textChunk.transform = Util.transform(textState.ctm,
  10699. Util.transform(textState.textMatrix, tsm));
  10700. if (!font.vertical) {
  10701. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10702. } else {
  10703. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10704. }
  10705. }
  10706. var width = 0;
  10707. var height = 0;
  10708. var glyphs = font.charsToGlyphs(chars);
  10709. var defaultVMetrics = font.defaultVMetrics;
  10710. for (var i = 0; i < glyphs.length; i++) {
  10711. var glyph = glyphs[i];
  10712. if (!glyph) { // Previous glyph was a space.
  10713. width += textState.wordSpacing * textState.textHScale;
  10714. continue;
  10715. }
  10716. var vMetricX = null;
  10717. var vMetricY = null;
  10718. var glyphWidth = null;
  10719. if (font.vertical) {
  10720. if (glyph.vmetric) {
  10721. glyphWidth = glyph.vmetric[0];
  10722. vMetricX = glyph.vmetric[1];
  10723. vMetricY = glyph.vmetric[2];
  10724. } else {
  10725. glyphWidth = glyph.width;
  10726. vMetricX = glyph.width * 0.5;
  10727. vMetricY = defaultVMetrics[2];
  10728. }
  10729. } else {
  10730. glyphWidth = glyph.width;
  10731. }
  10732. var glyphUnicode = glyph.unicode;
  10733. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10734. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10735. }
  10736. glyphUnicode = reverseIfRtl(glyphUnicode);
  10737. // The following will calculate the x and y of the individual glyphs.
  10738. // if (font.vertical) {
  10739. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10740. // textState.fontMatrix[0];
  10741. // tsm[5] -= vMetricY * textState.fontSize *
  10742. // textState.fontMatrix[0];
  10743. // }
  10744. // var trm = Util.transform(textState.textMatrix, tsm);
  10745. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10746. // var x = pt[0];
  10747. // var y = pt[1];
  10748. var charSpacing = 0;
  10749. if (textChunk.str.length > 0) {
  10750. // Apply char spacing only when there are chars.
  10751. // As a result there is only spacing between glyphs.
  10752. charSpacing = textState.charSpacing;
  10753. }
  10754. var tx = 0;
  10755. var ty = 0;
  10756. if (!font.vertical) {
  10757. var w0 = glyphWidth * textState.fontMatrix[0];
  10758. tx = (w0 * textState.fontSize + charSpacing) *
  10759. textState.textHScale;
  10760. width += tx;
  10761. } else {
  10762. var w1 = glyphWidth * textState.fontMatrix[0];
  10763. ty = w1 * textState.fontSize + charSpacing;
  10764. height += ty;
  10765. }
  10766. textState.translateTextMatrix(tx, ty);
  10767. textChunk.str.push(glyphUnicode);
  10768. }
  10769. var a = textState.textLineMatrix[0];
  10770. var b = textState.textLineMatrix[1];
  10771. var scaleLineX = Math.sqrt(a * a + b * b);
  10772. a = textState.ctm[0];
  10773. b = textState.ctm[1];
  10774. var scaleCtmX = Math.sqrt(a * a + b * b);
  10775. if (!font.vertical) {
  10776. textChunk.width += width * scaleCtmX * scaleLineX;
  10777. } else {
  10778. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10779. }
  10780. return textChunk;
  10781. }
  10782. var timeSlotManager = new TimeSlotManager();
  10783. return new Promise(function next(resolve, reject) {
  10784. timeSlotManager.reset();
  10785. var stop, operation = {}, args = [];
  10786. while (!(stop = timeSlotManager.check())) {
  10787. // The arguments parsed by read() are not used beyond this loop, so
  10788. // we can reuse the same array on every iteration, thus avoiding
  10789. // unnecessary allocations.
  10790. args.length = 0;
  10791. operation.args = args;
  10792. if (!(preprocessor.read(operation))) {
  10793. break;
  10794. }
  10795. textState = stateManager.state;
  10796. var fn = operation.fn;
  10797. args = operation.args;
  10798. switch (fn | 0) {
  10799. case OPS.setFont:
  10800. textState.fontSize = args[1];
  10801. return handleSetFont(args[0].name).then(function() {
  10802. next(resolve, reject);
  10803. }, reject);
  10804. case OPS.setTextRise:
  10805. textState.textRise = args[0];
  10806. break;
  10807. case OPS.setHScale:
  10808. textState.textHScale = args[0] / 100;
  10809. break;
  10810. case OPS.setLeading:
  10811. textState.leading = args[0];
  10812. break;
  10813. case OPS.moveText:
  10814. textState.translateTextLineMatrix(args[0], args[1]);
  10815. textState.textMatrix = textState.textLineMatrix.slice();
  10816. break;
  10817. case OPS.setLeadingMoveText:
  10818. textState.leading = -args[1];
  10819. textState.translateTextLineMatrix(args[0], args[1]);
  10820. textState.textMatrix = textState.textLineMatrix.slice();
  10821. break;
  10822. case OPS.nextLine:
  10823. textState.carriageReturn();
  10824. break;
  10825. case OPS.setTextMatrix:
  10826. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10827. args[4], args[5]);
  10828. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10829. args[4], args[5]);
  10830. break;
  10831. case OPS.setCharSpacing:
  10832. textState.charSpacing = args[0];
  10833. break;
  10834. case OPS.setWordSpacing:
  10835. textState.wordSpacing = args[0];
  10836. break;
  10837. case OPS.beginText:
  10838. textState.textMatrix = IDENTITY_MATRIX.slice();
  10839. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10840. break;
  10841. case OPS.showSpacedText:
  10842. var items = args[0];
  10843. var textChunk = newTextChunk();
  10844. var offset;
  10845. for (var j = 0, jj = items.length; j < jj; j++) {
  10846. if (typeof items[j] === 'string') {
  10847. buildTextGeometry(items[j], textChunk);
  10848. } else {
  10849. // PDF Specification 5.3.2 states:
  10850. // The number is expressed in thousandths of a unit of text
  10851. // space.
  10852. // This amount is subtracted from the current horizontal or
  10853. // vertical coordinate, depending on the writing mode.
  10854. // In the default coordinate system, a positive adjustment
  10855. // has the effect of moving the next glyph painted either to
  10856. // the left or down by the given amount.
  10857. var val = items[j] * textState.fontSize / 1000;
  10858. if (textState.font.vertical) {
  10859. offset = val * textState.textMatrix[3];
  10860. textState.translateTextMatrix(0, offset);
  10861. // Value needs to be added to height to paint down.
  10862. textChunk.height += offset;
  10863. } else {
  10864. offset = val * textState.textHScale *
  10865. textState.textMatrix[0];
  10866. textState.translateTextMatrix(offset, 0);
  10867. // Value needs to be subtracted from width to paint left.
  10868. textChunk.width -= offset;
  10869. }
  10870. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10871. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10872. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10873. fakeSpaces = Math.round(fakeSpaces);
  10874. while (fakeSpaces--) {
  10875. textChunk.str.push(' ');
  10876. }
  10877. } else if (fakeSpaces > SPACE_FACTOR) {
  10878. textChunk.str.push(' ');
  10879. }
  10880. }
  10881. }
  10882. }
  10883. bidiTexts.push(runBidi(textChunk));
  10884. break;
  10885. case OPS.showText:
  10886. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10887. break;
  10888. case OPS.nextLineShowText:
  10889. textState.carriageReturn();
  10890. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10891. break;
  10892. case OPS.nextLineSetSpacingShowText:
  10893. textState.wordSpacing = args[0];
  10894. textState.charSpacing = args[1];
  10895. textState.carriageReturn();
  10896. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10897. break;
  10898. case OPS.paintXObject:
  10899. if (args[0].code) {
  10900. break;
  10901. }
  10902. if (!xobjs) {
  10903. xobjs = (resources.get('XObject') || Dict.empty);
  10904. }
  10905. var name = args[0].name;
  10906. if (xobjsCache.key === name) {
  10907. if (xobjsCache.texts) {
  10908. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10909. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10910. }
  10911. break;
  10912. }
  10913. var xobj = xobjs.get(name);
  10914. if (!xobj) {
  10915. break;
  10916. }
  10917. assert(isStream(xobj), 'XObject should be a stream');
  10918. var type = xobj.dict.get('Subtype');
  10919. assert(isName(type),
  10920. 'XObject should have a Name subtype');
  10921. if ('Form' !== type.name) {
  10922. xobjsCache.key = name;
  10923. xobjsCache.texts = null;
  10924. break;
  10925. }
  10926. stateManager.save();
  10927. var matrix = xobj.dict.get('Matrix');
  10928. if (isArray(matrix) && matrix.length === 6) {
  10929. stateManager.transform(matrix);
  10930. }
  10931. return self.getTextContent(xobj,
  10932. xobj.dict.get('Resources') || resources, stateManager).
  10933. then(function (formTextContent) {
  10934. Util.appendToArray(bidiTexts, formTextContent.items);
  10935. Util.extendObj(textContent.styles, formTextContent.styles);
  10936. stateManager.restore();
  10937. xobjsCache.key = name;
  10938. xobjsCache.texts = formTextContent;
  10939. next(resolve, reject);
  10940. }, reject);
  10941. case OPS.setGState:
  10942. var dictName = args[0];
  10943. var extGState = resources.get('ExtGState');
  10944. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10945. break;
  10946. }
  10947. var gsStateMap = extGState.get(dictName.name);
  10948. var gsStateFont = null;
  10949. for (var key in gsStateMap) {
  10950. if (key === 'Font') {
  10951. assert(!gsStateFont);
  10952. gsStateFont = gsStateMap[key];
  10953. }
  10954. }
  10955. if (gsStateFont) {
  10956. textState.fontSize = gsStateFont[1];
  10957. return handleSetFont(gsStateFont[0]).then(function() {
  10958. next(resolve, reject);
  10959. }, reject);
  10960. }
  10961. break;
  10962. } // switch
  10963. } // while
  10964. if (stop) {
  10965. deferred.then(function () {
  10966. next(resolve, reject);
  10967. });
  10968. return;
  10969. }
  10970. resolve(textContent);
  10971. });
  10972. },
  10973. extractDataStructures: function
  10974. partialEvaluatorExtractDataStructures(dict, baseDict,
  10975. xref, properties) {
  10976. // 9.10.2
  10977. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10978. if (toUnicode) {
  10979. properties.toUnicode = this.readToUnicode(toUnicode);
  10980. }
  10981. if (properties.composite) {
  10982. // CIDSystemInfo helps to match CID to glyphs
  10983. var cidSystemInfo = dict.get('CIDSystemInfo');
  10984. if (isDict(cidSystemInfo)) {
  10985. properties.cidSystemInfo = {
  10986. registry: cidSystemInfo.get('Registry'),
  10987. ordering: cidSystemInfo.get('Ordering'),
  10988. supplement: cidSystemInfo.get('Supplement')
  10989. };
  10990. }
  10991. var cidToGidMap = dict.get('CIDToGIDMap');
  10992. if (isStream(cidToGidMap)) {
  10993. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10994. }
  10995. }
  10996. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10997. // and depends on the font type. The base encoding and differences are
  10998. // read here, but the encoding that is actually used is chosen during
  10999. // glyph mapping in the font.
  11000. // TODO: Loading the built in encoding in the font would allow the
  11001. // differences to be merged in here not require us to hold on to it.
  11002. var differences = [];
  11003. var baseEncodingName = null;
  11004. var encoding;
  11005. if (dict.has('Encoding')) {
  11006. encoding = dict.get('Encoding');
  11007. if (isDict(encoding)) {
  11008. baseEncodingName = encoding.get('BaseEncoding');
  11009. baseEncodingName = (isName(baseEncodingName) ?
  11010. baseEncodingName.name : null);
  11011. // Load the differences between the base and original
  11012. if (encoding.has('Differences')) {
  11013. var diffEncoding = encoding.get('Differences');
  11014. var index = 0;
  11015. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  11016. var data = diffEncoding[j];
  11017. if (isNum(data)) {
  11018. index = data;
  11019. } else if (isName(data)) {
  11020. differences[index++] = data.name;
  11021. } else if (isRef(data)) {
  11022. diffEncoding[j--] = xref.fetch(data);
  11023. continue;
  11024. } else {
  11025. error('Invalid entry in \'Differences\' array: ' + data);
  11026. }
  11027. }
  11028. }
  11029. } else if (isName(encoding)) {
  11030. baseEncodingName = encoding.name;
  11031. } else {
  11032. error('Encoding is not a Name nor a Dict');
  11033. }
  11034. // According to table 114 if the encoding is a named encoding it must be
  11035. // one of these predefined encodings.
  11036. if ((baseEncodingName !== 'MacRomanEncoding' &&
  11037. baseEncodingName !== 'MacExpertEncoding' &&
  11038. baseEncodingName !== 'WinAnsiEncoding')) {
  11039. baseEncodingName = null;
  11040. }
  11041. }
  11042. if (baseEncodingName) {
  11043. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  11044. } else {
  11045. encoding = (properties.type === 'TrueType' ?
  11046. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  11047. // The Symbolic attribute can be misused for regular fonts
  11048. // Heuristic: we have to check if the font is a standard one also
  11049. if (!!(properties.flags & FontFlags.Symbolic)) {
  11050. encoding = Encodings.MacRomanEncoding;
  11051. if (!properties.file) {
  11052. if (/Symbol/i.test(properties.name)) {
  11053. encoding = Encodings.SymbolSetEncoding;
  11054. } else if (/Dingbats/i.test(properties.name)) {
  11055. encoding = Encodings.ZapfDingbatsEncoding;
  11056. }
  11057. }
  11058. }
  11059. properties.defaultEncoding = encoding;
  11060. }
  11061. properties.differences = differences;
  11062. properties.baseEncodingName = baseEncodingName;
  11063. properties.dict = dict;
  11064. },
  11065. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  11066. var cmap, cmapObj = toUnicode;
  11067. if (isName(cmapObj)) {
  11068. cmap = CMapFactory.create(cmapObj,
  11069. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11070. if (cmap instanceof IdentityCMap) {
  11071. return new IdentityToUnicodeMap(0, 0xFFFF);
  11072. }
  11073. return new ToUnicodeMap(cmap.getMap());
  11074. } else if (isStream(cmapObj)) {
  11075. cmap = CMapFactory.create(cmapObj,
  11076. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11077. if (cmap instanceof IdentityCMap) {
  11078. return new IdentityToUnicodeMap(0, 0xFFFF);
  11079. }
  11080. var map = new Array(cmap.length);
  11081. // Convert UTF-16BE
  11082. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  11083. // to iterate over all keys.
  11084. cmap.forEach(function(charCode, token) {
  11085. var str = [];
  11086. for (var k = 0; k < token.length; k += 2) {
  11087. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11088. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  11089. str.push(w1);
  11090. continue;
  11091. }
  11092. k += 2;
  11093. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11094. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  11095. }
  11096. map[charCode] = String.fromCharCode.apply(String, str);
  11097. });
  11098. return new ToUnicodeMap(map);
  11099. }
  11100. return null;
  11101. },
  11102. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  11103. // Extract the encoding from the CIDToGIDMap
  11104. var glyphsData = cidToGidStream.getBytes();
  11105. // Set encoding 0 to later verify the font has an encoding
  11106. var result = [];
  11107. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  11108. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  11109. if (glyphID === 0) {
  11110. continue;
  11111. }
  11112. var code = j >> 1;
  11113. result[code] = glyphID;
  11114. }
  11115. return result;
  11116. },
  11117. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  11118. descriptor,
  11119. properties) {
  11120. var glyphsWidths = [];
  11121. var defaultWidth = 0;
  11122. var glyphsVMetrics = [];
  11123. var defaultVMetrics;
  11124. var i, ii, j, jj, start, code, widths;
  11125. if (properties.composite) {
  11126. defaultWidth = dict.get('DW') || 1000;
  11127. widths = dict.get('W');
  11128. if (widths) {
  11129. for (i = 0, ii = widths.length; i < ii; i++) {
  11130. start = widths[i++];
  11131. code = xref.fetchIfRef(widths[i]);
  11132. if (isArray(code)) {
  11133. for (j = 0, jj = code.length; j < jj; j++) {
  11134. glyphsWidths[start++] = code[j];
  11135. }
  11136. } else {
  11137. var width = widths[++i];
  11138. for (j = start; j <= code; j++) {
  11139. glyphsWidths[j] = width;
  11140. }
  11141. }
  11142. }
  11143. }
  11144. if (properties.vertical) {
  11145. var vmetrics = (dict.get('DW2') || [880, -1000]);
  11146. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  11147. vmetrics = dict.get('W2');
  11148. if (vmetrics) {
  11149. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  11150. start = vmetrics[i++];
  11151. code = xref.fetchIfRef(vmetrics[i]);
  11152. if (isArray(code)) {
  11153. for (j = 0, jj = code.length; j < jj; j++) {
  11154. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  11155. }
  11156. } else {
  11157. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  11158. for (j = start; j <= code; j++) {
  11159. glyphsVMetrics[j] = vmetric;
  11160. }
  11161. }
  11162. }
  11163. }
  11164. }
  11165. } else {
  11166. var firstChar = properties.firstChar;
  11167. widths = dict.get('Widths');
  11168. if (widths) {
  11169. j = firstChar;
  11170. for (i = 0, ii = widths.length; i < ii; i++) {
  11171. glyphsWidths[j++] = widths[i];
  11172. }
  11173. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  11174. } else {
  11175. // Trying get the BaseFont metrics (see comment above).
  11176. var baseFontName = dict.get('BaseFont');
  11177. if (isName(baseFontName)) {
  11178. var metrics = this.getBaseFontMetrics(baseFontName.name);
  11179. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  11180. properties);
  11181. defaultWidth = metrics.defaultWidth;
  11182. }
  11183. }
  11184. }
  11185. // Heuristic: detection of monospace font by checking all non-zero widths
  11186. var isMonospace = true;
  11187. var firstWidth = defaultWidth;
  11188. for (var glyph in glyphsWidths) {
  11189. var glyphWidth = glyphsWidths[glyph];
  11190. if (!glyphWidth) {
  11191. continue;
  11192. }
  11193. if (!firstWidth) {
  11194. firstWidth = glyphWidth;
  11195. continue;
  11196. }
  11197. if (firstWidth !== glyphWidth) {
  11198. isMonospace = false;
  11199. break;
  11200. }
  11201. }
  11202. if (isMonospace) {
  11203. properties.flags |= FontFlags.FixedPitch;
  11204. }
  11205. properties.defaultWidth = defaultWidth;
  11206. properties.widths = glyphsWidths;
  11207. properties.defaultVMetrics = defaultVMetrics;
  11208. properties.vmetrics = glyphsVMetrics;
  11209. },
  11210. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  11211. // Simulating descriptor flags attribute
  11212. var fontNameWoStyle = baseFontName.split('-')[0];
  11213. return (fontNameWoStyle in serifFonts) ||
  11214. (fontNameWoStyle.search(/serif/gi) !== -1);
  11215. },
  11216. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  11217. var defaultWidth = 0;
  11218. var widths = [];
  11219. var monospace = false;
  11220. var lookupName = (stdFontMap[name] || name);
  11221. if (!(lookupName in Metrics)) {
  11222. // Use default fonts for looking up font metrics if the passed
  11223. // font is not a base font
  11224. if (this.isSerifFont(name)) {
  11225. lookupName = 'Times-Roman';
  11226. } else {
  11227. lookupName = 'Helvetica';
  11228. }
  11229. }
  11230. var glyphWidths = Metrics[lookupName];
  11231. if (isNum(glyphWidths)) {
  11232. defaultWidth = glyphWidths;
  11233. monospace = true;
  11234. } else {
  11235. widths = glyphWidths;
  11236. }
  11237. return {
  11238. defaultWidth: defaultWidth,
  11239. monospace: monospace,
  11240. widths: widths
  11241. };
  11242. },
  11243. buildCharCodeToWidth:
  11244. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  11245. properties) {
  11246. var widths = Object.create(null);
  11247. var differences = properties.differences;
  11248. var encoding = properties.defaultEncoding;
  11249. for (var charCode = 0; charCode < 256; charCode++) {
  11250. if (charCode in differences &&
  11251. widthsByGlyphName[differences[charCode]]) {
  11252. widths[charCode] = widthsByGlyphName[differences[charCode]];
  11253. continue;
  11254. }
  11255. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  11256. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  11257. continue;
  11258. }
  11259. }
  11260. return widths;
  11261. },
  11262. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  11263. var baseDict = dict;
  11264. var type = dict.get('Subtype');
  11265. assert(isName(type), 'invalid font Subtype');
  11266. var composite = false;
  11267. var uint8array;
  11268. if (type.name === 'Type0') {
  11269. // If font is a composite
  11270. // - get the descendant font
  11271. // - set the type according to the descendant font
  11272. // - get the FontDescriptor from the descendant font
  11273. var df = dict.get('DescendantFonts');
  11274. if (!df) {
  11275. error('Descendant fonts are not specified');
  11276. }
  11277. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  11278. type = dict.get('Subtype');
  11279. assert(isName(type), 'invalid font Subtype');
  11280. composite = true;
  11281. }
  11282. var descriptor = dict.get('FontDescriptor');
  11283. if (descriptor) {
  11284. var hash = new MurmurHash3_64();
  11285. var encoding = baseDict.getRaw('Encoding');
  11286. if (isName(encoding)) {
  11287. hash.update(encoding.name);
  11288. } else if (isRef(encoding)) {
  11289. hash.update(encoding.num + '_' + encoding.gen);
  11290. } else if (isDict(encoding)) {
  11291. var keys = encoding.getKeys();
  11292. for (var i = 0, ii = keys.length; i < ii; i++) {
  11293. var entry = encoding.getRaw(keys[i]);
  11294. if (isName(entry)) {
  11295. hash.update(entry.name);
  11296. } else if (isRef(entry)) {
  11297. hash.update(entry.num + '_' + entry.gen);
  11298. } else if (isArray(entry)) { // 'Differences' entry.
  11299. // Ideally we should check the contents of the array, but to avoid
  11300. // parsing it here and then again in |extractDataStructures|,
  11301. // we only use the array length for now (fixes bug1157493.pdf).
  11302. hash.update(entry.length.toString());
  11303. }
  11304. }
  11305. }
  11306. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  11307. if (isStream(toUnicode)) {
  11308. var stream = toUnicode.str || toUnicode;
  11309. uint8array = stream.buffer ?
  11310. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  11311. new Uint8Array(stream.bytes.buffer,
  11312. stream.start, stream.end - stream.start);
  11313. hash.update(uint8array);
  11314. } else if (isName(toUnicode)) {
  11315. hash.update(toUnicode.name);
  11316. }
  11317. var widths = dict.get('Widths') || baseDict.get('Widths');
  11318. if (widths) {
  11319. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  11320. hash.update(uint8array);
  11321. }
  11322. }
  11323. return {
  11324. descriptor: descriptor,
  11325. dict: dict,
  11326. baseDict: baseDict,
  11327. composite: composite,
  11328. type: type.name,
  11329. hash: hash ? hash.hexdigest() : ''
  11330. };
  11331. },
  11332. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11333. xref) {
  11334. var baseDict = preEvaluatedFont.baseDict;
  11335. var dict = preEvaluatedFont.dict;
  11336. var composite = preEvaluatedFont.composite;
  11337. var descriptor = preEvaluatedFont.descriptor;
  11338. var type = preEvaluatedFont.type;
  11339. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11340. var properties;
  11341. if (!descriptor) {
  11342. if (type === 'Type3') {
  11343. // FontDescriptor is only required for Type3 fonts when the document
  11344. // is a tagged pdf. Create a barbebones one to get by.
  11345. descriptor = new Dict(null);
  11346. descriptor.set('FontName', Name.get(type));
  11347. descriptor.set('FontBBox', dict.get('FontBBox'));
  11348. } else {
  11349. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11350. // FontDescriptor was not required.
  11351. // This case is here for compatibility.
  11352. var baseFontName = dict.get('BaseFont');
  11353. if (!isName(baseFontName)) {
  11354. error('Base font is not specified');
  11355. }
  11356. // Using base font name as a font name.
  11357. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11358. var metrics = this.getBaseFontMetrics(baseFontName);
  11359. // Simulating descriptor flags attribute
  11360. var fontNameWoStyle = baseFontName.split('-')[0];
  11361. var flags =
  11362. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11363. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11364. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11365. FontFlags.Nonsymbolic);
  11366. properties = {
  11367. type: type,
  11368. name: baseFontName,
  11369. widths: metrics.widths,
  11370. defaultWidth: metrics.defaultWidth,
  11371. flags: flags,
  11372. firstChar: 0,
  11373. lastChar: maxCharIndex
  11374. };
  11375. this.extractDataStructures(dict, dict, xref, properties);
  11376. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11377. properties);
  11378. return new Font(baseFontName, null, properties);
  11379. }
  11380. }
  11381. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11382. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11383. // to ignore this rule when a variant of a standart font is used.
  11384. // TODO Fill the width array depending on which of the base font this is
  11385. // a variant.
  11386. var firstChar = (dict.get('FirstChar') || 0);
  11387. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11388. var fontName = descriptor.get('FontName');
  11389. var baseFont = dict.get('BaseFont');
  11390. // Some bad PDFs have a string as the font name.
  11391. if (isString(fontName)) {
  11392. fontName = Name.get(fontName);
  11393. }
  11394. if (isString(baseFont)) {
  11395. baseFont = Name.get(baseFont);
  11396. }
  11397. if (type !== 'Type3') {
  11398. var fontNameStr = fontName && fontName.name;
  11399. var baseFontStr = baseFont && baseFont.name;
  11400. if (fontNameStr !== baseFontStr) {
  11401. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11402. '" but should be the same as the Font\'s BaseFont "' +
  11403. baseFontStr + '"');
  11404. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11405. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11406. if (fontNameStr && baseFontStr &&
  11407. baseFontStr.indexOf(fontNameStr) === 0) {
  11408. fontName = baseFont;
  11409. }
  11410. }
  11411. }
  11412. fontName = (fontName || baseFont);
  11413. assert(isName(fontName), 'invalid font name');
  11414. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11415. if (fontFile) {
  11416. if (fontFile.dict) {
  11417. var subtype = fontFile.dict.get('Subtype');
  11418. if (subtype) {
  11419. subtype = subtype.name;
  11420. }
  11421. var length1 = fontFile.dict.get('Length1');
  11422. var length2 = fontFile.dict.get('Length2');
  11423. }
  11424. }
  11425. properties = {
  11426. type: type,
  11427. name: fontName.name,
  11428. subtype: subtype,
  11429. file: fontFile,
  11430. length1: length1,
  11431. length2: length2,
  11432. loadedName: baseDict.loadedName,
  11433. composite: composite,
  11434. wideChars: composite,
  11435. fixedPitch: false,
  11436. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11437. firstChar: firstChar || 0,
  11438. lastChar: (lastChar || maxCharIndex),
  11439. bbox: descriptor.get('FontBBox'),
  11440. ascent: descriptor.get('Ascent'),
  11441. descent: descriptor.get('Descent'),
  11442. xHeight: descriptor.get('XHeight'),
  11443. capHeight: descriptor.get('CapHeight'),
  11444. flags: descriptor.get('Flags'),
  11445. italicAngle: descriptor.get('ItalicAngle'),
  11446. coded: false
  11447. };
  11448. if (composite) {
  11449. var cidEncoding = baseDict.get('Encoding');
  11450. if (isName(cidEncoding)) {
  11451. properties.cidEncoding = cidEncoding.name;
  11452. }
  11453. properties.cMap = CMapFactory.create(cidEncoding,
  11454. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11455. properties.vertical = properties.cMap.vertical;
  11456. }
  11457. this.extractDataStructures(dict, baseDict, xref, properties);
  11458. this.extractWidths(dict, xref, descriptor, properties);
  11459. if (type === 'Type3') {
  11460. properties.isType3Font = true;
  11461. }
  11462. return new Font(fontName.name, fontFile, properties);
  11463. }
  11464. };
  11465. return PartialEvaluator;
  11466. })();
  11467. var TranslatedFont = (function TranslatedFontClosure() {
  11468. function TranslatedFont(loadedName, font, dict) {
  11469. this.loadedName = loadedName;
  11470. this.font = font;
  11471. this.dict = dict;
  11472. this.type3Loaded = null;
  11473. this.sent = false;
  11474. }
  11475. TranslatedFont.prototype = {
  11476. send: function (handler) {
  11477. if (this.sent) {
  11478. return;
  11479. }
  11480. var fontData = this.font.exportData();
  11481. handler.send('commonobj', [
  11482. this.loadedName,
  11483. 'Font',
  11484. fontData
  11485. ]);
  11486. this.sent = true;
  11487. },
  11488. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11489. assert(this.font.isType3Font);
  11490. if (this.type3Loaded) {
  11491. return this.type3Loaded;
  11492. }
  11493. var translatedFont = this.font;
  11494. var loadCharProcsPromise = Promise.resolve();
  11495. var charProcs = this.dict.get('CharProcs').getAll();
  11496. var fontResources = this.dict.get('Resources') || resources;
  11497. var charProcKeys = Object.keys(charProcs);
  11498. var charProcOperatorList = {};
  11499. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11500. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11501. var glyphStream = charProcs[key];
  11502. var operatorList = new OperatorList();
  11503. return evaluator.getOperatorList(glyphStream, fontResources,
  11504. operatorList).then(function () {
  11505. charProcOperatorList[key] = operatorList.getIR();
  11506. // Add the dependencies to the parent operator list so they are
  11507. // resolved before sub operator list is executed synchronously.
  11508. parentOperatorList.addDependencies(operatorList.dependencies);
  11509. }, function (reason) {
  11510. warn('Type3 font resource \"' + key + '\" is not available');
  11511. var operatorList = new OperatorList();
  11512. charProcOperatorList[key] = operatorList.getIR();
  11513. });
  11514. }.bind(this, charProcKeys[i]));
  11515. }
  11516. this.type3Loaded = loadCharProcsPromise.then(function () {
  11517. translatedFont.charProcOperatorList = charProcOperatorList;
  11518. });
  11519. return this.type3Loaded;
  11520. }
  11521. };
  11522. return TranslatedFont;
  11523. })();
  11524. var OperatorList = (function OperatorListClosure() {
  11525. var CHUNK_SIZE = 1000;
  11526. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11527. function getTransfers(queue) {
  11528. var transfers = [];
  11529. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11530. for (var i = 0, ii = queue.length; i < ii; i++) {
  11531. switch (fnArray[i]) {
  11532. case OPS.paintInlineImageXObject:
  11533. case OPS.paintInlineImageXObjectGroup:
  11534. case OPS.paintImageMaskXObject:
  11535. var arg = argsArray[i][0]; // first param in imgData
  11536. if (!arg.cached) {
  11537. transfers.push(arg.data.buffer);
  11538. }
  11539. break;
  11540. }
  11541. }
  11542. return transfers;
  11543. }
  11544. function OperatorList(intent, messageHandler, pageIndex) {
  11545. this.messageHandler = messageHandler;
  11546. this.fnArray = [];
  11547. this.argsArray = [];
  11548. this.dependencies = {};
  11549. this.pageIndex = pageIndex;
  11550. this.intent = intent;
  11551. }
  11552. OperatorList.prototype = {
  11553. get length() {
  11554. return this.argsArray.length;
  11555. },
  11556. addOp: function(fn, args) {
  11557. this.fnArray.push(fn);
  11558. this.argsArray.push(args);
  11559. if (this.messageHandler) {
  11560. if (this.fnArray.length >= CHUNK_SIZE) {
  11561. this.flush();
  11562. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11563. (fn === OPS.restore || fn === OPS.endText)) {
  11564. // heuristic to flush on boundary of restore or endText
  11565. this.flush();
  11566. }
  11567. }
  11568. },
  11569. addDependency: function(dependency) {
  11570. if (dependency in this.dependencies) {
  11571. return;
  11572. }
  11573. this.dependencies[dependency] = true;
  11574. this.addOp(OPS.dependency, [dependency]);
  11575. },
  11576. addDependencies: function(dependencies) {
  11577. for (var key in dependencies) {
  11578. this.addDependency(key);
  11579. }
  11580. },
  11581. addOpList: function(opList) {
  11582. Util.extendObj(this.dependencies, opList.dependencies);
  11583. for (var i = 0, ii = opList.length; i < ii; i++) {
  11584. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11585. }
  11586. },
  11587. getIR: function() {
  11588. return {
  11589. fnArray: this.fnArray,
  11590. argsArray: this.argsArray,
  11591. length: this.length
  11592. };
  11593. },
  11594. flush: function(lastChunk) {
  11595. if (this.intent !== 'oplist') {
  11596. new QueueOptimizer().optimize(this);
  11597. }
  11598. var transfers = getTransfers(this);
  11599. this.messageHandler.send('RenderPageChunk', {
  11600. operatorList: {
  11601. fnArray: this.fnArray,
  11602. argsArray: this.argsArray,
  11603. lastChunk: lastChunk,
  11604. length: this.length
  11605. },
  11606. pageIndex: this.pageIndex,
  11607. intent: this.intent
  11608. }, transfers);
  11609. this.dependencies = {};
  11610. this.fnArray.length = 0;
  11611. this.argsArray.length = 0;
  11612. }
  11613. };
  11614. return OperatorList;
  11615. })();
  11616. var StateManager = (function StateManagerClosure() {
  11617. function StateManager(initialState) {
  11618. this.state = initialState;
  11619. this.stateStack = [];
  11620. }
  11621. StateManager.prototype = {
  11622. save: function () {
  11623. var old = this.state;
  11624. this.stateStack.push(this.state);
  11625. this.state = old.clone();
  11626. },
  11627. restore: function () {
  11628. var prev = this.stateStack.pop();
  11629. if (prev) {
  11630. this.state = prev;
  11631. }
  11632. },
  11633. transform: function (args) {
  11634. this.state.ctm = Util.transform(this.state.ctm, args);
  11635. }
  11636. };
  11637. return StateManager;
  11638. })();
  11639. var TextState = (function TextStateClosure() {
  11640. function TextState() {
  11641. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11642. this.fontSize = 0;
  11643. this.font = null;
  11644. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11645. this.textMatrix = IDENTITY_MATRIX.slice();
  11646. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11647. this.charSpacing = 0;
  11648. this.wordSpacing = 0;
  11649. this.leading = 0;
  11650. this.textHScale = 1;
  11651. this.textRise = 0;
  11652. }
  11653. TextState.prototype = {
  11654. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11655. var m = this.textMatrix;
  11656. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11657. },
  11658. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11659. var m = this.textLineMatrix;
  11660. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11661. },
  11662. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11663. var m = this.textMatrix;
  11664. m[4] = m[0] * x + m[2] * y + m[4];
  11665. m[5] = m[1] * x + m[3] * y + m[5];
  11666. },
  11667. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11668. var m = this.textLineMatrix;
  11669. m[4] = m[0] * x + m[2] * y + m[4];
  11670. m[5] = m[1] * x + m[3] * y + m[5];
  11671. },
  11672. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11673. // 9.4.4 Text Space Details
  11674. var tsm = [this.fontSize * this.textHScale, 0,
  11675. 0, this.fontSize,
  11676. 0, this.textRise];
  11677. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11678. },
  11679. carriageReturn: function TextState_carriageReturn() {
  11680. this.translateTextLineMatrix(0, -this.leading);
  11681. this.textMatrix = this.textLineMatrix.slice();
  11682. },
  11683. clone: function TextState_clone() {
  11684. var clone = Object.create(this);
  11685. clone.textMatrix = this.textMatrix.slice();
  11686. clone.textLineMatrix = this.textLineMatrix.slice();
  11687. clone.fontMatrix = this.fontMatrix.slice();
  11688. return clone;
  11689. }
  11690. };
  11691. return TextState;
  11692. })();
  11693. var EvalState = (function EvalStateClosure() {
  11694. function EvalState() {
  11695. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11696. this.font = null;
  11697. this.textRenderingMode = TextRenderingMode.FILL;
  11698. this.fillColorSpace = ColorSpace.singletons.gray;
  11699. this.strokeColorSpace = ColorSpace.singletons.gray;
  11700. }
  11701. EvalState.prototype = {
  11702. clone: function CanvasExtraState_clone() {
  11703. return Object.create(this);
  11704. },
  11705. };
  11706. return EvalState;
  11707. })();
  11708. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11709. // Specifies properties for each command
  11710. //
  11711. // If variableArgs === true: [0, `numArgs`] expected
  11712. // If variableArgs === false: exactly `numArgs` expected
  11713. var OP_MAP = {
  11714. // Graphic state
  11715. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11716. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11717. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11718. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11719. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11720. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11721. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11722. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11723. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11724. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11725. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11726. // Path
  11727. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11728. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11729. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11730. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11731. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11732. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11733. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11734. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11735. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11736. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11737. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11738. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11739. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11740. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11741. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11742. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11743. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11744. // Clipping
  11745. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11746. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11747. // Text
  11748. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11749. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11750. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11751. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11752. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11753. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11754. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11755. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11756. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11757. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11758. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11759. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11760. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11761. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11762. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11763. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11764. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11765. variableArgs: false },
  11766. // Type3 fonts
  11767. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11768. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11769. // Color
  11770. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11771. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11772. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11773. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11774. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11775. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11776. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11777. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11778. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11779. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11780. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11781. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11782. // Shading
  11783. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11784. // Images
  11785. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11786. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11787. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11788. // XObjects
  11789. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11790. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11791. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11792. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11793. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11794. variableArgs: false },
  11795. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11796. // Compatibility
  11797. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11798. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11799. // (reserved partial commands for the lexer)
  11800. BM: null,
  11801. BD: null,
  11802. 'true': null,
  11803. fa: null,
  11804. fal: null,
  11805. fals: null,
  11806. 'false': null,
  11807. nu: null,
  11808. nul: null,
  11809. 'null': null
  11810. };
  11811. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11812. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11813. // dictionary
  11814. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11815. this.stateManager = stateManager;
  11816. this.nonProcessedArgs = [];
  11817. }
  11818. EvaluatorPreprocessor.prototype = {
  11819. get savedStatesDepth() {
  11820. return this.stateManager.stateStack.length;
  11821. },
  11822. // |operation| is an object with two fields:
  11823. //
  11824. // - |fn| is an out param.
  11825. //
  11826. // - |args| is an inout param. On entry, it should have one of two values.
  11827. //
  11828. // - An empty array. This indicates that the caller is providing the
  11829. // array in which the args will be stored in. The caller should use
  11830. // this value if it can reuse a single array for each call to read().
  11831. //
  11832. // - |null|. This indicates that the caller needs this function to create
  11833. // the array in which any args are stored in. If there are zero args,
  11834. // this function will leave |operation.args| as |null| (thus avoiding
  11835. // allocations that would occur if we used an empty array to represent
  11836. // zero arguments). Otherwise, it will replace |null| with a new array
  11837. // containing the arguments. The caller should use this value if it
  11838. // cannot reuse an array for each call to read().
  11839. //
  11840. // These two modes are present because this function is very hot and so
  11841. // avoiding allocations where possible is worthwhile.
  11842. //
  11843. read: function EvaluatorPreprocessor_read(operation) {
  11844. var args = operation.args;
  11845. while (true) {
  11846. var obj = this.parser.getObj();
  11847. if (isCmd(obj)) {
  11848. var cmd = obj.cmd;
  11849. // Check that the command is valid
  11850. var opSpec = OP_MAP[cmd];
  11851. if (!opSpec) {
  11852. warn('Unknown command "' + cmd + '"');
  11853. continue;
  11854. }
  11855. var fn = opSpec.id;
  11856. var numArgs = opSpec.numArgs;
  11857. var argsLength = args !== null ? args.length : 0;
  11858. if (!opSpec.variableArgs) {
  11859. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11860. if (argsLength !== numArgs) {
  11861. var nonProcessedArgs = this.nonProcessedArgs;
  11862. while (argsLength > numArgs) {
  11863. nonProcessedArgs.push(args.shift());
  11864. argsLength--;
  11865. }
  11866. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11867. if (!args) {
  11868. args = [];
  11869. }
  11870. args.unshift(nonProcessedArgs.pop());
  11871. argsLength++;
  11872. }
  11873. }
  11874. if (argsLength < numArgs) {
  11875. // If we receive too few args, it's not possible to possible
  11876. // to execute the command, so skip the command
  11877. info('Command ' + fn + ': because expected ' +
  11878. numArgs + ' args, but received ' + argsLength +
  11879. ' args; skipping');
  11880. args = null;
  11881. continue;
  11882. }
  11883. } else if (argsLength > numArgs) {
  11884. info('Command ' + fn + ': expected [0,' + numArgs +
  11885. '] args, but received ' + argsLength + ' args');
  11886. }
  11887. // TODO figure out how to type-check vararg functions
  11888. this.preprocessCommand(fn, args);
  11889. operation.fn = fn;
  11890. operation.args = args;
  11891. return true;
  11892. } else {
  11893. if (isEOF(obj)) {
  11894. return false; // no more commands
  11895. }
  11896. // argument
  11897. if (obj !== null) {
  11898. if (!args) {
  11899. args = [];
  11900. }
  11901. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11902. assert(args.length <= 33, 'Too many arguments');
  11903. }
  11904. }
  11905. }
  11906. },
  11907. preprocessCommand:
  11908. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11909. switch (fn | 0) {
  11910. case OPS.save:
  11911. this.stateManager.save();
  11912. break;
  11913. case OPS.restore:
  11914. this.stateManager.restore();
  11915. break;
  11916. case OPS.transform:
  11917. this.stateManager.transform(args);
  11918. break;
  11919. }
  11920. }
  11921. };
  11922. return EvaluatorPreprocessor;
  11923. })();
  11924. var QueueOptimizer = (function QueueOptimizerClosure() {
  11925. function addState(parentState, pattern, fn) {
  11926. var state = parentState;
  11927. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11928. var item = pattern[i];
  11929. state = (state[item] || (state[item] = []));
  11930. }
  11931. state[pattern[pattern.length - 1]] = fn;
  11932. }
  11933. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11934. argsArray) {
  11935. // Handles special case of mainly LaTeX documents which use image masks to
  11936. // draw lines with the current fill style.
  11937. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11938. // have been found at iFirstSave.
  11939. var iFirstPIMXO = iFirstSave + 2;
  11940. for (var i = 0; i < count; i++) {
  11941. var arg = argsArray[iFirstPIMXO + 4 * i];
  11942. var imageMask = arg.length === 1 && arg[0];
  11943. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11944. (!imageMask.data.length ||
  11945. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11946. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11947. continue;
  11948. }
  11949. break;
  11950. }
  11951. return count - i;
  11952. }
  11953. var InitialState = [];
  11954. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11955. // sequences with one |paintInlineImageXObjectGroup| operation.
  11956. addState(InitialState,
  11957. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11958. function foundInlineImageGroup(context) {
  11959. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11960. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11961. var MAX_WIDTH = 1000;
  11962. var IMAGE_PADDING = 1;
  11963. var fnArray = context.fnArray, argsArray = context.argsArray;
  11964. var curr = context.iCurr;
  11965. var iFirstSave = curr - 3;
  11966. var iFirstTransform = curr - 2;
  11967. var iFirstPIIXO = curr - 1;
  11968. // Look for the quartets.
  11969. var i = iFirstSave + 4;
  11970. var ii = fnArray.length;
  11971. while (i + 3 < ii) {
  11972. if (fnArray[i] !== OPS.save ||
  11973. fnArray[i + 1] !== OPS.transform ||
  11974. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11975. fnArray[i + 3] !== OPS.restore) {
  11976. break; // ops don't match
  11977. }
  11978. i += 4;
  11979. }
  11980. // At this point, i is the index of the first op past the last valid
  11981. // quartet.
  11982. var count = Math.min((i - iFirstSave) / 4,
  11983. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11984. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11985. return i;
  11986. }
  11987. // assuming that heights of those image is too small (~1 pixel)
  11988. // packing as much as possible by lines
  11989. var maxX = 0;
  11990. var map = [], maxLineHeight = 0;
  11991. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11992. var q;
  11993. for (q = 0; q < count; q++) {
  11994. var transform = argsArray[iFirstTransform + (q << 2)];
  11995. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11996. if (currentX + img.width > MAX_WIDTH) {
  11997. // starting new line
  11998. maxX = Math.max(maxX, currentX);
  11999. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  12000. currentX = 0;
  12001. maxLineHeight = 0;
  12002. }
  12003. map.push({
  12004. transform: transform,
  12005. x: currentX, y: currentY,
  12006. w: img.width, h: img.height
  12007. });
  12008. currentX += img.width + 2 * IMAGE_PADDING;
  12009. maxLineHeight = Math.max(maxLineHeight, img.height);
  12010. }
  12011. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  12012. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  12013. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  12014. var imgRowSize = imgWidth << 2;
  12015. for (q = 0; q < count; q++) {
  12016. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  12017. // Copy image by lines and extends pixels into padding.
  12018. var rowSize = map[q].w << 2;
  12019. var dataOffset = 0;
  12020. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  12021. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  12022. for (var k = 0, kk = map[q].h; k < kk; k++) {
  12023. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  12024. dataOffset += rowSize;
  12025. offset += imgRowSize;
  12026. }
  12027. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  12028. while (offset >= 0) {
  12029. data[offset - 4] = data[offset];
  12030. data[offset - 3] = data[offset + 1];
  12031. data[offset - 2] = data[offset + 2];
  12032. data[offset - 1] = data[offset + 3];
  12033. data[offset + rowSize] = data[offset + rowSize - 4];
  12034. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  12035. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  12036. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  12037. offset -= imgRowSize;
  12038. }
  12039. }
  12040. // Replace queue items.
  12041. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  12042. argsArray.splice(iFirstSave, count * 4,
  12043. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  12044. data: imgData }, map]);
  12045. return iFirstSave + 1;
  12046. });
  12047. // This replaces (save, transform, paintImageMaskXObject, restore)+
  12048. // sequences with one |paintImageMaskXObjectGroup| or one
  12049. // |paintImageMaskXObjectRepeat| operation.
  12050. addState(InitialState,
  12051. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  12052. function foundImageMaskGroup(context) {
  12053. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  12054. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  12055. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  12056. var fnArray = context.fnArray, argsArray = context.argsArray;
  12057. var curr = context.iCurr;
  12058. var iFirstSave = curr - 3;
  12059. var iFirstTransform = curr - 2;
  12060. var iFirstPIMXO = curr - 1;
  12061. // Look for the quartets.
  12062. var i = iFirstSave + 4;
  12063. var ii = fnArray.length;
  12064. while (i + 3 < ii) {
  12065. if (fnArray[i] !== OPS.save ||
  12066. fnArray[i + 1] !== OPS.transform ||
  12067. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  12068. fnArray[i + 3] !== OPS.restore) {
  12069. break; // ops don't match
  12070. }
  12071. i += 4;
  12072. }
  12073. // At this point, i is the index of the first op past the last valid
  12074. // quartet.
  12075. var count = (i - iFirstSave) / 4;
  12076. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  12077. argsArray);
  12078. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  12079. return i;
  12080. }
  12081. var q;
  12082. var isSameImage = false;
  12083. var iTransform, transformArgs;
  12084. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  12085. if (argsArray[iFirstTransform][1] === 0 &&
  12086. argsArray[iFirstTransform][2] === 0) {
  12087. isSameImage = true;
  12088. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12089. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12090. iTransform = iFirstTransform + 4;
  12091. var iPIMXO = iFirstPIMXO + 4;
  12092. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  12093. transformArgs = argsArray[iTransform];
  12094. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  12095. transformArgs[0] !== firstTransformArg0 ||
  12096. transformArgs[1] !== 0 ||
  12097. transformArgs[2] !== 0 ||
  12098. transformArgs[3] !== firstTransformArg3) {
  12099. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  12100. isSameImage = false;
  12101. } else {
  12102. count = q;
  12103. }
  12104. break; // different image or transform
  12105. }
  12106. }
  12107. }
  12108. if (isSameImage) {
  12109. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  12110. var positions = new Float32Array(count * 2);
  12111. iTransform = iFirstTransform;
  12112. for (q = 0; q < count; q++, iTransform += 4) {
  12113. transformArgs = argsArray[iTransform];
  12114. positions[(q << 1)] = transformArgs[4];
  12115. positions[(q << 1) + 1] = transformArgs[5];
  12116. }
  12117. // Replace queue items.
  12118. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  12119. argsArray.splice(iFirstSave, count * 4,
  12120. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  12121. } else {
  12122. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  12123. var images = [];
  12124. for (q = 0; q < count; q++) {
  12125. transformArgs = argsArray[iFirstTransform + (q << 2)];
  12126. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  12127. images.push({ data: maskParams.data, width: maskParams.width,
  12128. height: maskParams.height,
  12129. transform: transformArgs });
  12130. }
  12131. // Replace queue items.
  12132. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  12133. argsArray.splice(iFirstSave, count * 4, [images]);
  12134. }
  12135. return iFirstSave + 1;
  12136. });
  12137. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  12138. // with one paintImageXObjectRepeat operation, if the |transform| and
  12139. // |paintImageXObjectRepeat| ops are appropriate.
  12140. addState(InitialState,
  12141. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  12142. function (context) {
  12143. var MIN_IMAGES_IN_BLOCK = 3;
  12144. var MAX_IMAGES_IN_BLOCK = 1000;
  12145. var fnArray = context.fnArray, argsArray = context.argsArray;
  12146. var curr = context.iCurr;
  12147. var iFirstSave = curr - 3;
  12148. var iFirstTransform = curr - 2;
  12149. var iFirstPIXO = curr - 1;
  12150. var iFirstRestore = curr;
  12151. if (argsArray[iFirstTransform][1] !== 0 ||
  12152. argsArray[iFirstTransform][2] !== 0) {
  12153. return iFirstRestore + 1; // transform has the wrong form
  12154. }
  12155. // Look for the quartets.
  12156. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  12157. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12158. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12159. var i = iFirstSave + 4;
  12160. var ii = fnArray.length;
  12161. while (i + 3 < ii) {
  12162. if (fnArray[i] !== OPS.save ||
  12163. fnArray[i + 1] !== OPS.transform ||
  12164. fnArray[i + 2] !== OPS.paintImageXObject ||
  12165. fnArray[i + 3] !== OPS.restore) {
  12166. break; // ops don't match
  12167. }
  12168. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  12169. argsArray[i + 1][1] !== 0 ||
  12170. argsArray[i + 1][2] !== 0 ||
  12171. argsArray[i + 1][3] !== firstTransformArg3) {
  12172. break; // transforms don't match
  12173. }
  12174. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  12175. break; // images don't match
  12176. }
  12177. i += 4;
  12178. }
  12179. // At this point, i is the index of the first op past the last valid
  12180. // quartet.
  12181. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  12182. if (count < MIN_IMAGES_IN_BLOCK) {
  12183. return i;
  12184. }
  12185. // Extract the (x,y) positions from all of the matching transforms.
  12186. var positions = new Float32Array(count * 2);
  12187. var iTransform = iFirstTransform;
  12188. for (var q = 0; q < count; q++, iTransform += 4) {
  12189. var transformArgs = argsArray[iTransform];
  12190. positions[(q << 1)] = transformArgs[4];
  12191. positions[(q << 1) + 1] = transformArgs[5];
  12192. }
  12193. // Replace queue items.
  12194. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  12195. positions];
  12196. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  12197. argsArray.splice(iFirstSave, count * 4, args);
  12198. return iFirstSave + 1;
  12199. });
  12200. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  12201. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  12202. // sequences, if the font for each one is the same.
  12203. addState(InitialState,
  12204. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  12205. function (context) {
  12206. var MIN_CHARS_IN_BLOCK = 3;
  12207. var MAX_CHARS_IN_BLOCK = 1000;
  12208. var fnArray = context.fnArray, argsArray = context.argsArray;
  12209. var curr = context.iCurr;
  12210. var iFirstBeginText = curr - 4;
  12211. var iFirstSetFont = curr - 3;
  12212. var iFirstSetTextMatrix = curr - 2;
  12213. var iFirstShowText = curr - 1;
  12214. var iFirstEndText = curr;
  12215. // Look for the quintets.
  12216. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  12217. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  12218. var i = iFirstBeginText + 5;
  12219. var ii = fnArray.length;
  12220. while (i + 4 < ii) {
  12221. if (fnArray[i] !== OPS.beginText ||
  12222. fnArray[i + 1] !== OPS.setFont ||
  12223. fnArray[i + 2] !== OPS.setTextMatrix ||
  12224. fnArray[i + 3] !== OPS.showText ||
  12225. fnArray[i + 4] !== OPS.endText) {
  12226. break; // ops don't match
  12227. }
  12228. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  12229. argsArray[i + 1][1] !== firstSetFontArg1) {
  12230. break; // fonts don't match
  12231. }
  12232. i += 5;
  12233. }
  12234. // At this point, i is the index of the first op past the last valid
  12235. // quintet.
  12236. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  12237. if (count < MIN_CHARS_IN_BLOCK) {
  12238. return i;
  12239. }
  12240. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  12241. // showText, endText), include that as well. (E.g. <something> might be
  12242. // |dependency|.)
  12243. var iFirst = iFirstBeginText;
  12244. if (iFirstBeginText >= 4 &&
  12245. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  12246. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  12247. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  12248. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  12249. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  12250. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  12251. count++;
  12252. iFirst -= 5;
  12253. }
  12254. // Remove (endText, beginText, setFont) trios.
  12255. var iEndText = iFirst + 4;
  12256. for (var q = 1; q < count; q++) {
  12257. fnArray.splice(iEndText, 3);
  12258. argsArray.splice(iEndText, 3);
  12259. iEndText += 2;
  12260. }
  12261. return iEndText + 1;
  12262. });
  12263. function QueueOptimizer() {}
  12264. QueueOptimizer.prototype = {
  12265. optimize: function QueueOptimizer_optimize(queue) {
  12266. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  12267. var context = {
  12268. iCurr: 0,
  12269. fnArray: fnArray,
  12270. argsArray: argsArray
  12271. };
  12272. var state;
  12273. var i = 0, ii = fnArray.length;
  12274. while (i < ii) {
  12275. state = (state || InitialState)[fnArray[i]];
  12276. if (typeof state === 'function') { // we found some handler
  12277. context.iCurr = i;
  12278. // state() returns the index of the first non-matching op (if we
  12279. // didn't match) or the first op past the modified ops (if we did
  12280. // match and replace).
  12281. i = state(context);
  12282. state = undefined; // reset the state machine
  12283. ii = context.fnArray.length;
  12284. } else {
  12285. i++;
  12286. }
  12287. }
  12288. }
  12289. };
  12290. return QueueOptimizer;
  12291. })();
  12292. var BUILT_IN_CMAPS = [
  12293. // << Start unicode maps.
  12294. 'Adobe-GB1-UCS2',
  12295. 'Adobe-CNS1-UCS2',
  12296. 'Adobe-Japan1-UCS2',
  12297. 'Adobe-Korea1-UCS2',
  12298. // >> End unicode maps.
  12299. '78-EUC-H',
  12300. '78-EUC-V',
  12301. '78-H',
  12302. '78-RKSJ-H',
  12303. '78-RKSJ-V',
  12304. '78-V',
  12305. '78ms-RKSJ-H',
  12306. '78ms-RKSJ-V',
  12307. '83pv-RKSJ-H',
  12308. '90ms-RKSJ-H',
  12309. '90ms-RKSJ-V',
  12310. '90msp-RKSJ-H',
  12311. '90msp-RKSJ-V',
  12312. '90pv-RKSJ-H',
  12313. '90pv-RKSJ-V',
  12314. 'Add-H',
  12315. 'Add-RKSJ-H',
  12316. 'Add-RKSJ-V',
  12317. 'Add-V',
  12318. 'Adobe-CNS1-0',
  12319. 'Adobe-CNS1-1',
  12320. 'Adobe-CNS1-2',
  12321. 'Adobe-CNS1-3',
  12322. 'Adobe-CNS1-4',
  12323. 'Adobe-CNS1-5',
  12324. 'Adobe-CNS1-6',
  12325. 'Adobe-GB1-0',
  12326. 'Adobe-GB1-1',
  12327. 'Adobe-GB1-2',
  12328. 'Adobe-GB1-3',
  12329. 'Adobe-GB1-4',
  12330. 'Adobe-GB1-5',
  12331. 'Adobe-Japan1-0',
  12332. 'Adobe-Japan1-1',
  12333. 'Adobe-Japan1-2',
  12334. 'Adobe-Japan1-3',
  12335. 'Adobe-Japan1-4',
  12336. 'Adobe-Japan1-5',
  12337. 'Adobe-Japan1-6',
  12338. 'Adobe-Korea1-0',
  12339. 'Adobe-Korea1-1',
  12340. 'Adobe-Korea1-2',
  12341. 'B5-H',
  12342. 'B5-V',
  12343. 'B5pc-H',
  12344. 'B5pc-V',
  12345. 'CNS-EUC-H',
  12346. 'CNS-EUC-V',
  12347. 'CNS1-H',
  12348. 'CNS1-V',
  12349. 'CNS2-H',
  12350. 'CNS2-V',
  12351. 'ETHK-B5-H',
  12352. 'ETHK-B5-V',
  12353. 'ETen-B5-H',
  12354. 'ETen-B5-V',
  12355. 'ETenms-B5-H',
  12356. 'ETenms-B5-V',
  12357. 'EUC-H',
  12358. 'EUC-V',
  12359. 'Ext-H',
  12360. 'Ext-RKSJ-H',
  12361. 'Ext-RKSJ-V',
  12362. 'Ext-V',
  12363. 'GB-EUC-H',
  12364. 'GB-EUC-V',
  12365. 'GB-H',
  12366. 'GB-V',
  12367. 'GBK-EUC-H',
  12368. 'GBK-EUC-V',
  12369. 'GBK2K-H',
  12370. 'GBK2K-V',
  12371. 'GBKp-EUC-H',
  12372. 'GBKp-EUC-V',
  12373. 'GBT-EUC-H',
  12374. 'GBT-EUC-V',
  12375. 'GBT-H',
  12376. 'GBT-V',
  12377. 'GBTpc-EUC-H',
  12378. 'GBTpc-EUC-V',
  12379. 'GBpc-EUC-H',
  12380. 'GBpc-EUC-V',
  12381. 'H',
  12382. 'HKdla-B5-H',
  12383. 'HKdla-B5-V',
  12384. 'HKdlb-B5-H',
  12385. 'HKdlb-B5-V',
  12386. 'HKgccs-B5-H',
  12387. 'HKgccs-B5-V',
  12388. 'HKm314-B5-H',
  12389. 'HKm314-B5-V',
  12390. 'HKm471-B5-H',
  12391. 'HKm471-B5-V',
  12392. 'HKscs-B5-H',
  12393. 'HKscs-B5-V',
  12394. 'Hankaku',
  12395. 'Hiragana',
  12396. 'KSC-EUC-H',
  12397. 'KSC-EUC-V',
  12398. 'KSC-H',
  12399. 'KSC-Johab-H',
  12400. 'KSC-Johab-V',
  12401. 'KSC-V',
  12402. 'KSCms-UHC-H',
  12403. 'KSCms-UHC-HW-H',
  12404. 'KSCms-UHC-HW-V',
  12405. 'KSCms-UHC-V',
  12406. 'KSCpc-EUC-H',
  12407. 'KSCpc-EUC-V',
  12408. 'Katakana',
  12409. 'NWP-H',
  12410. 'NWP-V',
  12411. 'RKSJ-H',
  12412. 'RKSJ-V',
  12413. 'Roman',
  12414. 'UniCNS-UCS2-H',
  12415. 'UniCNS-UCS2-V',
  12416. 'UniCNS-UTF16-H',
  12417. 'UniCNS-UTF16-V',
  12418. 'UniCNS-UTF32-H',
  12419. 'UniCNS-UTF32-V',
  12420. 'UniCNS-UTF8-H',
  12421. 'UniCNS-UTF8-V',
  12422. 'UniGB-UCS2-H',
  12423. 'UniGB-UCS2-V',
  12424. 'UniGB-UTF16-H',
  12425. 'UniGB-UTF16-V',
  12426. 'UniGB-UTF32-H',
  12427. 'UniGB-UTF32-V',
  12428. 'UniGB-UTF8-H',
  12429. 'UniGB-UTF8-V',
  12430. 'UniJIS-UCS2-H',
  12431. 'UniJIS-UCS2-HW-H',
  12432. 'UniJIS-UCS2-HW-V',
  12433. 'UniJIS-UCS2-V',
  12434. 'UniJIS-UTF16-H',
  12435. 'UniJIS-UTF16-V',
  12436. 'UniJIS-UTF32-H',
  12437. 'UniJIS-UTF32-V',
  12438. 'UniJIS-UTF8-H',
  12439. 'UniJIS-UTF8-V',
  12440. 'UniJIS2004-UTF16-H',
  12441. 'UniJIS2004-UTF16-V',
  12442. 'UniJIS2004-UTF32-H',
  12443. 'UniJIS2004-UTF32-V',
  12444. 'UniJIS2004-UTF8-H',
  12445. 'UniJIS2004-UTF8-V',
  12446. 'UniJISPro-UCS2-HW-V',
  12447. 'UniJISPro-UCS2-V',
  12448. 'UniJISPro-UTF8-V',
  12449. 'UniJISX0213-UTF32-H',
  12450. 'UniJISX0213-UTF32-V',
  12451. 'UniJISX02132004-UTF32-H',
  12452. 'UniJISX02132004-UTF32-V',
  12453. 'UniKS-UCS2-H',
  12454. 'UniKS-UCS2-V',
  12455. 'UniKS-UTF16-H',
  12456. 'UniKS-UTF16-V',
  12457. 'UniKS-UTF32-H',
  12458. 'UniKS-UTF32-V',
  12459. 'UniKS-UTF8-H',
  12460. 'UniKS-UTF8-V',
  12461. 'V',
  12462. 'WP-Symbol'];
  12463. // CMap, not to be confused with TrueType's cmap.
  12464. var CMap = (function CMapClosure() {
  12465. function CMap(builtInCMap) {
  12466. // Codespace ranges are stored as follows:
  12467. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12468. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12469. this.codespaceRanges = [[], [], [], []];
  12470. this.numCodespaceRanges = 0;
  12471. // Map entries have one of two forms.
  12472. // - cid chars are 16-bit unsigned integers, stored as integers.
  12473. // - bf chars are variable-length byte sequences, stored as strings, with
  12474. // one byte per character.
  12475. this._map = [];
  12476. this.name = '';
  12477. this.vertical = false;
  12478. this.useCMap = null;
  12479. this.builtInCMap = builtInCMap;
  12480. }
  12481. CMap.prototype = {
  12482. addCodespaceRange: function(n, low, high) {
  12483. this.codespaceRanges[n - 1].push(low, high);
  12484. this.numCodespaceRanges++;
  12485. },
  12486. mapCidRange: function(low, high, dstLow) {
  12487. while (low <= high) {
  12488. this._map[low++] = dstLow++;
  12489. }
  12490. },
  12491. mapBfRange: function(low, high, dstLow) {
  12492. var lastByte = dstLow.length - 1;
  12493. while (low <= high) {
  12494. this._map[low++] = dstLow;
  12495. // Only the last byte has to be incremented.
  12496. dstLow = dstLow.substr(0, lastByte) +
  12497. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12498. }
  12499. },
  12500. mapBfRangeToArray: function(low, high, array) {
  12501. var i = 0, ii = array.length;
  12502. while (low <= high && i < ii) {
  12503. this._map[low] = array[i++];
  12504. ++low;
  12505. }
  12506. },
  12507. // This is used for both bf and cid chars.
  12508. mapOne: function(src, dst) {
  12509. this._map[src] = dst;
  12510. },
  12511. lookup: function(code) {
  12512. return this._map[code];
  12513. },
  12514. contains: function(code) {
  12515. return this._map[code] !== undefined;
  12516. },
  12517. forEach: function(callback) {
  12518. // Most maps have fewer than 65536 entries, and for those we use normal
  12519. // array iteration. But really sparse tables are possible -- e.g. with
  12520. // indices in the *billions*. For such tables we use for..in, which isn't
  12521. // ideal because it stringifies the indices for all present elements, but
  12522. // it does avoid iterating over every undefined entry.
  12523. var map = this._map;
  12524. var length = map.length;
  12525. var i;
  12526. if (length <= 0x10000) {
  12527. for (i = 0; i < length; i++) {
  12528. if (map[i] !== undefined) {
  12529. callback(i, map[i]);
  12530. }
  12531. }
  12532. } else {
  12533. for (i in this._map) {
  12534. callback(i, map[i]);
  12535. }
  12536. }
  12537. },
  12538. charCodeOf: function(value) {
  12539. return this._map.indexOf(value);
  12540. },
  12541. getMap: function() {
  12542. return this._map;
  12543. },
  12544. readCharCode: function(str, offset, out) {
  12545. var c = 0;
  12546. var codespaceRanges = this.codespaceRanges;
  12547. var codespaceRangesLen = this.codespaceRanges.length;
  12548. // 9.7.6.2 CMap Mapping
  12549. // The code length is at most 4.
  12550. for (var n = 0; n < codespaceRangesLen; n++) {
  12551. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12552. // Check each codespace range to see if it falls within.
  12553. var codespaceRange = codespaceRanges[n];
  12554. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12555. var low = codespaceRange[k++];
  12556. var high = codespaceRange[k++];
  12557. if (c >= low && c <= high) {
  12558. out.charcode = c;
  12559. out.length = n + 1;
  12560. return;
  12561. }
  12562. }
  12563. }
  12564. out.charcode = 0;
  12565. out.length = 1;
  12566. },
  12567. get length() {
  12568. return this._map.length;
  12569. },
  12570. get isIdentityCMap() {
  12571. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  12572. return false;
  12573. }
  12574. if (this._map.length !== 0x10000) {
  12575. return false;
  12576. }
  12577. for (var i = 0; i < 0x10000; i++) {
  12578. if (this._map[i] !== i) {
  12579. return false;
  12580. }
  12581. }
  12582. return true;
  12583. }
  12584. };
  12585. return CMap;
  12586. })();
  12587. // A special case of CMap, where the _map array implicitly has a length of
  12588. // 65536 and each element is equal to its index.
  12589. var IdentityCMap = (function IdentityCMapClosure() {
  12590. function IdentityCMap(vertical, n) {
  12591. CMap.call(this);
  12592. this.vertical = vertical;
  12593. this.addCodespaceRange(n, 0, 0xffff);
  12594. }
  12595. Util.inherit(IdentityCMap, CMap, {});
  12596. IdentityCMap.prototype = {
  12597. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12598. mapCidRange: function(low, high, dstLow) {
  12599. error('should not call mapCidRange');
  12600. },
  12601. mapBfRange: function(low, high, dstLow) {
  12602. error('should not call mapBfRange');
  12603. },
  12604. mapBfRangeToArray: function(low, high, array) {
  12605. error('should not call mapBfRangeToArray');
  12606. },
  12607. mapOne: function(src, dst) {
  12608. error('should not call mapCidOne');
  12609. },
  12610. lookup: function(code) {
  12611. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12612. },
  12613. contains: function(code) {
  12614. return isInt(code) && code <= 0xffff;
  12615. },
  12616. forEach: function(callback) {
  12617. for (var i = 0; i <= 0xffff; i++) {
  12618. callback(i, i);
  12619. }
  12620. },
  12621. charCodeOf: function(value) {
  12622. return (isInt(value) && value <= 0xffff) ? value : -1;
  12623. },
  12624. getMap: function() {
  12625. // Sometimes identity maps must be instantiated, but it's rare.
  12626. var map = new Array(0x10000);
  12627. for (var i = 0; i <= 0xffff; i++) {
  12628. map[i] = i;
  12629. }
  12630. return map;
  12631. },
  12632. readCharCode: CMap.prototype.readCharCode,
  12633. get length() {
  12634. return 0x10000;
  12635. },
  12636. get isIdentityCMap() {
  12637. error('should not access .isIdentityCMap');
  12638. }
  12639. };
  12640. return IdentityCMap;
  12641. })();
  12642. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12643. function fetchBinaryData(url) {
  12644. var nonBinaryRequest = PDFJS.disableWorker;
  12645. var request = new XMLHttpRequest();
  12646. request.open('GET', url, false);
  12647. if (!nonBinaryRequest) {
  12648. try {
  12649. request.responseType = 'arraybuffer';
  12650. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12651. } catch (e) {
  12652. nonBinaryRequest = true;
  12653. }
  12654. }
  12655. if (nonBinaryRequest && request.overrideMimeType) {
  12656. request.overrideMimeType('text/plain; charset=x-user-defined');
  12657. }
  12658. request.send(null);
  12659. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12660. error('Unable to get binary cMap at: ' + url);
  12661. }
  12662. if (nonBinaryRequest) {
  12663. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12664. return ch.charCodeAt(0) & 255;
  12665. });
  12666. return new Uint8Array(data);
  12667. }
  12668. return new Uint8Array(request.response);
  12669. }
  12670. function hexToInt(a, size) {
  12671. var n = 0;
  12672. for (var i = 0; i <= size; i++) {
  12673. n = (n << 8) | a[i];
  12674. }
  12675. return n >>> 0;
  12676. }
  12677. function hexToStr(a, size) {
  12678. // This code is hot. Special-case some common values to avoid creating an
  12679. // object with subarray().
  12680. if (size === 1) {
  12681. return String.fromCharCode(a[0], a[1]);
  12682. }
  12683. if (size === 3) {
  12684. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12685. }
  12686. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12687. }
  12688. function addHex(a, b, size) {
  12689. var c = 0;
  12690. for (var i = size; i >= 0; i--) {
  12691. c += a[i] + b[i];
  12692. a[i] = c & 255;
  12693. c >>= 8;
  12694. }
  12695. }
  12696. function incHex(a, size) {
  12697. var c = 1;
  12698. for (var i = size; i >= 0 && c > 0; i--) {
  12699. c += a[i];
  12700. a[i] = c & 255;
  12701. c >>= 8;
  12702. }
  12703. }
  12704. var MAX_NUM_SIZE = 16;
  12705. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12706. function BinaryCMapStream(data) {
  12707. this.buffer = data;
  12708. this.pos = 0;
  12709. this.end = data.length;
  12710. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12711. }
  12712. BinaryCMapStream.prototype = {
  12713. readByte: function () {
  12714. if (this.pos >= this.end) {
  12715. return -1;
  12716. }
  12717. return this.buffer[this.pos++];
  12718. },
  12719. readNumber: function () {
  12720. var n = 0;
  12721. var last;
  12722. do {
  12723. var b = this.readByte();
  12724. if (b < 0) {
  12725. error('unexpected EOF in bcmap');
  12726. }
  12727. last = !(b & 0x80);
  12728. n = (n << 7) | (b & 0x7F);
  12729. } while (!last);
  12730. return n;
  12731. },
  12732. readSigned: function () {
  12733. var n = this.readNumber();
  12734. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12735. },
  12736. readHex: function (num, size) {
  12737. num.set(this.buffer.subarray(this.pos,
  12738. this.pos + size + 1));
  12739. this.pos += size + 1;
  12740. },
  12741. readHexNumber: function (num, size) {
  12742. var last;
  12743. var stack = this.tmpBuf, sp = 0;
  12744. do {
  12745. var b = this.readByte();
  12746. if (b < 0) {
  12747. error('unexpected EOF in bcmap');
  12748. }
  12749. last = !(b & 0x80);
  12750. stack[sp++] = b & 0x7F;
  12751. } while (!last);
  12752. var i = size, buffer = 0, bufferSize = 0;
  12753. while (i >= 0) {
  12754. while (bufferSize < 8 && stack.length > 0) {
  12755. buffer = (stack[--sp] << bufferSize) | buffer;
  12756. bufferSize += 7;
  12757. }
  12758. num[i] = buffer & 255;
  12759. i--;
  12760. buffer >>= 8;
  12761. bufferSize -= 8;
  12762. }
  12763. },
  12764. readHexSigned: function (num, size) {
  12765. this.readHexNumber(num, size);
  12766. var sign = num[size] & 1 ? 255 : 0;
  12767. var c = 0;
  12768. for (var i = 0; i <= size; i++) {
  12769. c = ((c & 1) << 8) | num[i];
  12770. num[i] = (c >> 1) ^ sign;
  12771. }
  12772. },
  12773. readString: function () {
  12774. var len = this.readNumber();
  12775. var s = '';
  12776. for (var i = 0; i < len; i++) {
  12777. s += String.fromCharCode(this.readNumber());
  12778. }
  12779. return s;
  12780. }
  12781. };
  12782. function processBinaryCMap(url, cMap, extend) {
  12783. var data = fetchBinaryData(url);
  12784. var stream = new BinaryCMapStream(data);
  12785. var header = stream.readByte();
  12786. cMap.vertical = !!(header & 1);
  12787. var useCMap = null;
  12788. var start = new Uint8Array(MAX_NUM_SIZE);
  12789. var end = new Uint8Array(MAX_NUM_SIZE);
  12790. var char = new Uint8Array(MAX_NUM_SIZE);
  12791. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12792. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12793. var code;
  12794. var b;
  12795. while ((b = stream.readByte()) >= 0) {
  12796. var type = b >> 5;
  12797. if (type === 7) { // metadata, e.g. comment or usecmap
  12798. switch (b & 0x1F) {
  12799. case 0:
  12800. stream.readString(); // skipping comment
  12801. break;
  12802. case 1:
  12803. useCMap = stream.readString();
  12804. break;
  12805. }
  12806. continue;
  12807. }
  12808. var sequence = !!(b & 0x10);
  12809. var dataSize = b & 15;
  12810. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12811. var ucs2DataSize = 1;
  12812. var subitemsCount = stream.readNumber();
  12813. var i;
  12814. switch (type) {
  12815. case 0: // codespacerange
  12816. stream.readHex(start, dataSize);
  12817. stream.readHexNumber(end, dataSize);
  12818. addHex(end, start, dataSize);
  12819. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12820. hexToInt(end, dataSize));
  12821. for (i = 1; i < subitemsCount; i++) {
  12822. incHex(end, dataSize);
  12823. stream.readHexNumber(start, dataSize);
  12824. addHex(start, end, dataSize);
  12825. stream.readHexNumber(end, dataSize);
  12826. addHex(end, start, dataSize);
  12827. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12828. hexToInt(end, dataSize));
  12829. }
  12830. break;
  12831. case 1: // notdefrange
  12832. stream.readHex(start, dataSize);
  12833. stream.readHexNumber(end, dataSize);
  12834. addHex(end, start, dataSize);
  12835. code = stream.readNumber();
  12836. // undefined range, skipping
  12837. for (i = 1; i < subitemsCount; i++) {
  12838. incHex(end, dataSize);
  12839. stream.readHexNumber(start, dataSize);
  12840. addHex(start, end, dataSize);
  12841. stream.readHexNumber(end, dataSize);
  12842. addHex(end, start, dataSize);
  12843. code = stream.readNumber();
  12844. // nop
  12845. }
  12846. break;
  12847. case 2: // cidchar
  12848. stream.readHex(char, dataSize);
  12849. code = stream.readNumber();
  12850. cMap.mapOne(hexToInt(char, dataSize), code);
  12851. for (i = 1; i < subitemsCount; i++) {
  12852. incHex(char, dataSize);
  12853. if (!sequence) {
  12854. stream.readHexNumber(tmp, dataSize);
  12855. addHex(char, tmp, dataSize);
  12856. }
  12857. code = stream.readSigned() + (code + 1);
  12858. cMap.mapOne(hexToInt(char, dataSize), code);
  12859. }
  12860. break;
  12861. case 3: // cidrange
  12862. stream.readHex(start, dataSize);
  12863. stream.readHexNumber(end, dataSize);
  12864. addHex(end, start, dataSize);
  12865. code = stream.readNumber();
  12866. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12867. code);
  12868. for (i = 1; i < subitemsCount; i++) {
  12869. incHex(end, dataSize);
  12870. if (!sequence) {
  12871. stream.readHexNumber(start, dataSize);
  12872. addHex(start, end, dataSize);
  12873. } else {
  12874. start.set(end);
  12875. }
  12876. stream.readHexNumber(end, dataSize);
  12877. addHex(end, start, dataSize);
  12878. code = stream.readNumber();
  12879. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12880. code);
  12881. }
  12882. break;
  12883. case 4: // bfchar
  12884. stream.readHex(char, ucs2DataSize);
  12885. stream.readHex(charCode, dataSize);
  12886. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12887. hexToStr(charCode, dataSize));
  12888. for (i = 1; i < subitemsCount; i++) {
  12889. incHex(char, ucs2DataSize);
  12890. if (!sequence) {
  12891. stream.readHexNumber(tmp, ucs2DataSize);
  12892. addHex(char, tmp, ucs2DataSize);
  12893. }
  12894. incHex(charCode, dataSize);
  12895. stream.readHexSigned(tmp, dataSize);
  12896. addHex(charCode, tmp, dataSize);
  12897. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12898. hexToStr(charCode, dataSize));
  12899. }
  12900. break;
  12901. case 5: // bfrange
  12902. stream.readHex(start, ucs2DataSize);
  12903. stream.readHexNumber(end, ucs2DataSize);
  12904. addHex(end, start, ucs2DataSize);
  12905. stream.readHex(charCode, dataSize);
  12906. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12907. hexToInt(end, ucs2DataSize),
  12908. hexToStr(charCode, dataSize));
  12909. for (i = 1; i < subitemsCount; i++) {
  12910. incHex(end, ucs2DataSize);
  12911. if (!sequence) {
  12912. stream.readHexNumber(start, ucs2DataSize);
  12913. addHex(start, end, ucs2DataSize);
  12914. } else {
  12915. start.set(end);
  12916. }
  12917. stream.readHexNumber(end, ucs2DataSize);
  12918. addHex(end, start, ucs2DataSize);
  12919. stream.readHex(charCode, dataSize);
  12920. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12921. hexToInt(end, ucs2DataSize),
  12922. hexToStr(charCode, dataSize));
  12923. }
  12924. break;
  12925. default:
  12926. error('Unknown type: ' + type);
  12927. break;
  12928. }
  12929. }
  12930. if (useCMap) {
  12931. extend(useCMap);
  12932. }
  12933. return cMap;
  12934. }
  12935. function BinaryCMapReader() {}
  12936. BinaryCMapReader.prototype = {
  12937. read: processBinaryCMap
  12938. };
  12939. return BinaryCMapReader;
  12940. })();
  12941. var CMapFactory = (function CMapFactoryClosure() {
  12942. function strToInt(str) {
  12943. var a = 0;
  12944. for (var i = 0; i < str.length; i++) {
  12945. a = (a << 8) | str.charCodeAt(i);
  12946. }
  12947. return a >>> 0;
  12948. }
  12949. function expectString(obj) {
  12950. if (!isString(obj)) {
  12951. error('Malformed CMap: expected string.');
  12952. }
  12953. }
  12954. function expectInt(obj) {
  12955. if (!isInt(obj)) {
  12956. error('Malformed CMap: expected int.');
  12957. }
  12958. }
  12959. function parseBfChar(cMap, lexer) {
  12960. while (true) {
  12961. var obj = lexer.getObj();
  12962. if (isEOF(obj)) {
  12963. break;
  12964. }
  12965. if (isCmd(obj, 'endbfchar')) {
  12966. return;
  12967. }
  12968. expectString(obj);
  12969. var src = strToInt(obj);
  12970. obj = lexer.getObj();
  12971. // TODO are /dstName used?
  12972. expectString(obj);
  12973. var dst = obj;
  12974. cMap.mapOne(src, dst);
  12975. }
  12976. }
  12977. function parseBfRange(cMap, lexer) {
  12978. while (true) {
  12979. var obj = lexer.getObj();
  12980. if (isEOF(obj)) {
  12981. break;
  12982. }
  12983. if (isCmd(obj, 'endbfrange')) {
  12984. return;
  12985. }
  12986. expectString(obj);
  12987. var low = strToInt(obj);
  12988. obj = lexer.getObj();
  12989. expectString(obj);
  12990. var high = strToInt(obj);
  12991. obj = lexer.getObj();
  12992. if (isInt(obj) || isString(obj)) {
  12993. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12994. cMap.mapBfRange(low, high, dstLow);
  12995. } else if (isCmd(obj, '[')) {
  12996. obj = lexer.getObj();
  12997. var array = [];
  12998. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12999. array.push(obj);
  13000. obj = lexer.getObj();
  13001. }
  13002. cMap.mapBfRangeToArray(low, high, array);
  13003. } else {
  13004. break;
  13005. }
  13006. }
  13007. error('Invalid bf range.');
  13008. }
  13009. function parseCidChar(cMap, lexer) {
  13010. while (true) {
  13011. var obj = lexer.getObj();
  13012. if (isEOF(obj)) {
  13013. break;
  13014. }
  13015. if (isCmd(obj, 'endcidchar')) {
  13016. return;
  13017. }
  13018. expectString(obj);
  13019. var src = strToInt(obj);
  13020. obj = lexer.getObj();
  13021. expectInt(obj);
  13022. var dst = obj;
  13023. cMap.mapOne(src, dst);
  13024. }
  13025. }
  13026. function parseCidRange(cMap, lexer) {
  13027. while (true) {
  13028. var obj = lexer.getObj();
  13029. if (isEOF(obj)) {
  13030. break;
  13031. }
  13032. if (isCmd(obj, 'endcidrange')) {
  13033. return;
  13034. }
  13035. expectString(obj);
  13036. var low = strToInt(obj);
  13037. obj = lexer.getObj();
  13038. expectString(obj);
  13039. var high = strToInt(obj);
  13040. obj = lexer.getObj();
  13041. expectInt(obj);
  13042. var dstLow = obj;
  13043. cMap.mapCidRange(low, high, dstLow);
  13044. }
  13045. }
  13046. function parseCodespaceRange(cMap, lexer) {
  13047. while (true) {
  13048. var obj = lexer.getObj();
  13049. if (isEOF(obj)) {
  13050. break;
  13051. }
  13052. if (isCmd(obj, 'endcodespacerange')) {
  13053. return;
  13054. }
  13055. if (!isString(obj)) {
  13056. break;
  13057. }
  13058. var low = strToInt(obj);
  13059. obj = lexer.getObj();
  13060. if (!isString(obj)) {
  13061. break;
  13062. }
  13063. var high = strToInt(obj);
  13064. cMap.addCodespaceRange(obj.length, low, high);
  13065. }
  13066. error('Invalid codespace range.');
  13067. }
  13068. function parseWMode(cMap, lexer) {
  13069. var obj = lexer.getObj();
  13070. if (isInt(obj)) {
  13071. cMap.vertical = !!obj;
  13072. }
  13073. }
  13074. function parseCMapName(cMap, lexer) {
  13075. var obj = lexer.getObj();
  13076. if (isName(obj) && isString(obj.name)) {
  13077. cMap.name = obj.name;
  13078. }
  13079. }
  13080. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  13081. var previous;
  13082. var embededUseCMap;
  13083. objLoop: while (true) {
  13084. var obj = lexer.getObj();
  13085. if (isEOF(obj)) {
  13086. break;
  13087. } else if (isName(obj)) {
  13088. if (obj.name === 'WMode') {
  13089. parseWMode(cMap, lexer);
  13090. } else if (obj.name === 'CMapName') {
  13091. parseCMapName(cMap, lexer);
  13092. }
  13093. previous = obj;
  13094. } else if (isCmd(obj)) {
  13095. switch (obj.cmd) {
  13096. case 'endcmap':
  13097. break objLoop;
  13098. case 'usecmap':
  13099. if (isName(previous)) {
  13100. embededUseCMap = previous.name;
  13101. }
  13102. break;
  13103. case 'begincodespacerange':
  13104. parseCodespaceRange(cMap, lexer);
  13105. break;
  13106. case 'beginbfchar':
  13107. parseBfChar(cMap, lexer);
  13108. break;
  13109. case 'begincidchar':
  13110. parseCidChar(cMap, lexer);
  13111. break;
  13112. case 'beginbfrange':
  13113. parseBfRange(cMap, lexer);
  13114. break;
  13115. case 'begincidrange':
  13116. parseCidRange(cMap, lexer);
  13117. break;
  13118. }
  13119. }
  13120. }
  13121. if (!useCMap && embededUseCMap) {
  13122. // Load the usecmap definition from the file only if there wasn't one
  13123. // specified.
  13124. useCMap = embededUseCMap;
  13125. }
  13126. if (useCMap) {
  13127. extendCMap(cMap, builtInCMapParams, useCMap);
  13128. }
  13129. }
  13130. function extendCMap(cMap, builtInCMapParams, useCMap) {
  13131. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  13132. // If there aren't any code space ranges defined clone all the parent ones
  13133. // into this cMap.
  13134. if (cMap.numCodespaceRanges === 0) {
  13135. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  13136. for (var i = 0; i < useCodespaceRanges.length; i++) {
  13137. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  13138. }
  13139. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  13140. }
  13141. // Merge the map into the current one, making sure not to override
  13142. // any previously defined entries.
  13143. cMap.useCMap.forEach(function(key, value) {
  13144. if (!cMap.contains(key)) {
  13145. cMap.mapOne(key, cMap.useCMap.lookup(key));
  13146. }
  13147. });
  13148. }
  13149. function parseBinaryCMap(name, builtInCMapParams) {
  13150. var url = builtInCMapParams.url + name + '.bcmap';
  13151. var cMap = new CMap(true);
  13152. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  13153. extendCMap(cMap, builtInCMapParams, useCMap);
  13154. });
  13155. return cMap;
  13156. }
  13157. function createBuiltInCMap(name, builtInCMapParams) {
  13158. if (name === 'Identity-H') {
  13159. return new IdentityCMap(false, 2);
  13160. } else if (name === 'Identity-V') {
  13161. return new IdentityCMap(true, 2);
  13162. }
  13163. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  13164. error('Unknown cMap name: ' + name);
  13165. }
  13166. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  13167. if (builtInCMapParams.packed) {
  13168. return parseBinaryCMap(name, builtInCMapParams);
  13169. }
  13170. var request = new XMLHttpRequest();
  13171. var url = builtInCMapParams.url + name;
  13172. request.open('GET', url, false);
  13173. request.send(null);
  13174. if (!request.responseText) {
  13175. error('Unable to get cMap at: ' + url);
  13176. }
  13177. var cMap = new CMap(true);
  13178. var lexer = new Lexer(new StringStream(request.responseText));
  13179. parseCMap(cMap, lexer, builtInCMapParams, null);
  13180. return cMap;
  13181. }
  13182. return {
  13183. create: function (encoding, builtInCMapParams, useCMap) {
  13184. if (isName(encoding)) {
  13185. return createBuiltInCMap(encoding.name, builtInCMapParams);
  13186. } else if (isStream(encoding)) {
  13187. var cMap = new CMap();
  13188. var lexer = new Lexer(encoding);
  13189. try {
  13190. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  13191. } catch (e) {
  13192. warn('Invalid CMap data. ' + e);
  13193. }
  13194. if (cMap.isIdentityCMap) {
  13195. return createBuiltInCMap(cMap.name, builtInCMapParams);
  13196. }
  13197. return cMap;
  13198. }
  13199. error('Encoding required.');
  13200. }
  13201. };
  13202. })();
  13203. // Unicode Private Use Area
  13204. var PRIVATE_USE_OFFSET_START = 0xE000;
  13205. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  13206. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  13207. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  13208. // except for Type 3 fonts
  13209. var PDF_GLYPH_SPACE_UNITS = 1000;
  13210. // Hinting is currently disabled due to unknown problems on windows
  13211. // in tracemonkey and various other pdfs with type1 fonts.
  13212. var HINTING_ENABLED = false;
  13213. // Accented charactars are not displayed properly on windows, using this flag
  13214. // to control analysis of seac charstrings.
  13215. var SEAC_ANALYSIS_ENABLED = false;
  13216. var FontFlags = {
  13217. FixedPitch: 1,
  13218. Serif: 2,
  13219. Symbolic: 4,
  13220. Script: 8,
  13221. Nonsymbolic: 32,
  13222. Italic: 64,
  13223. AllCap: 65536,
  13224. SmallCap: 131072,
  13225. ForceBold: 262144
  13226. };
  13227. var Encodings = {
  13228. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13229. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13230. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  13231. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  13232. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  13233. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  13234. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  13235. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  13236. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  13237. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  13238. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  13239. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  13240. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  13241. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  13242. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  13243. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  13244. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  13245. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  13246. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  13247. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13248. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  13249. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  13250. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  13251. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  13252. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  13253. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  13254. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  13255. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  13256. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  13257. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  13258. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  13259. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  13260. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  13261. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  13262. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  13263. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  13264. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  13265. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  13266. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  13267. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  13268. 'Ydieresissmall'],
  13269. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13270. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13271. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  13272. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  13273. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  13274. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  13275. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  13276. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  13277. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  13278. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  13279. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  13280. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  13281. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  13282. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  13283. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  13284. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  13285. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  13286. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  13287. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  13288. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  13289. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  13290. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  13291. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  13292. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  13293. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  13294. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  13295. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  13296. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  13297. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  13298. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  13299. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  13300. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  13301. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  13302. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  13303. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  13304. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  13305. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  13306. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  13307. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  13308. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  13309. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13310. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13311. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13312. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13313. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13314. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13315. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13316. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13317. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13318. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13319. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13320. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  13321. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  13322. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  13323. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13324. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  13325. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  13326. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  13327. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  13328. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  13329. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  13330. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  13331. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  13332. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  13333. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  13334. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  13335. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  13336. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  13337. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  13338. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  13339. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  13340. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  13341. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  13342. 'ogonek', 'caron'],
  13343. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13344. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13345. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13346. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  13347. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13348. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13349. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13350. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13351. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13352. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  13353. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  13354. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13355. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13356. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  13357. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  13358. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  13359. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  13360. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  13361. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  13362. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  13363. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  13364. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  13365. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  13366. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  13367. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13368. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13369. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13370. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13371. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13372. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13373. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13374. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13375. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13376. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13377. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13378. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13379. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13380. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13381. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13382. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13383. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13384. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13385. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13386. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13387. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13388. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13389. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13390. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13391. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13392. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13393. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13394. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13395. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13396. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13397. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13398. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13399. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13400. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13401. 'ydieresis'],
  13402. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13403. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13404. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13405. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13406. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13407. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13408. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13409. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13410. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13411. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13412. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13413. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13414. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13415. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13416. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13417. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13418. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13419. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13420. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13421. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13422. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13423. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13424. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13425. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13426. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13427. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13428. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13429. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13430. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13431. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13432. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13433. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13434. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13435. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13436. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13437. 'bracerightbt'],
  13438. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13439. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13440. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13441. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13442. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13443. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13444. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13445. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13446. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13447. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13448. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13449. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13450. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13451. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13452. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13453. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13454. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13455. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13456. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13457. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13458. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13459. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13460. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13461. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13462. };
  13463. /**
  13464. * Hold a map of decoded fonts and of the standard fourteen Type1
  13465. * fonts and their acronyms.
  13466. */
  13467. var stdFontMap = {
  13468. 'ArialNarrow': 'Helvetica',
  13469. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13470. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13471. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13472. 'ArialBlack': 'Helvetica',
  13473. 'ArialBlack-Bold': 'Helvetica-Bold',
  13474. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13475. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13476. 'Arial': 'Helvetica',
  13477. 'Arial-Bold': 'Helvetica-Bold',
  13478. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13479. 'Arial-Italic': 'Helvetica-Oblique',
  13480. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13481. 'Arial-BoldMT': 'Helvetica-Bold',
  13482. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13483. 'ArialMT': 'Helvetica',
  13484. 'Courier-Bold': 'Courier-Bold',
  13485. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13486. 'Courier-Italic': 'Courier-Oblique',
  13487. 'CourierNew': 'Courier',
  13488. 'CourierNew-Bold': 'Courier-Bold',
  13489. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13490. 'CourierNew-Italic': 'Courier-Oblique',
  13491. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13492. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13493. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13494. 'CourierNewPSMT': 'Courier',
  13495. 'Helvetica': 'Helvetica',
  13496. 'Helvetica-Bold': 'Helvetica-Bold',
  13497. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13498. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13499. 'Helvetica-Italic': 'Helvetica-Oblique',
  13500. 'Helvetica-Oblique':'Helvetica-Oblique',
  13501. 'Symbol-Bold': 'Symbol',
  13502. 'Symbol-BoldItalic': 'Symbol',
  13503. 'Symbol-Italic': 'Symbol',
  13504. 'TimesNewRoman': 'Times-Roman',
  13505. 'TimesNewRoman-Bold': 'Times-Bold',
  13506. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13507. 'TimesNewRoman-Italic': 'Times-Italic',
  13508. 'TimesNewRomanPS': 'Times-Roman',
  13509. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13510. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13511. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13512. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13513. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13514. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13515. 'TimesNewRomanPSMT': 'Times-Roman',
  13516. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13517. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13518. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13519. };
  13520. /**
  13521. * Holds the map of the non-standard fonts that might be included as a standard
  13522. * fonts without glyph data.
  13523. */
  13524. var nonStdFontMap = {
  13525. 'CenturyGothic': 'Helvetica',
  13526. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13527. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13528. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13529. 'ComicSansMS': 'Comic Sans MS',
  13530. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13531. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13532. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13533. 'LucidaConsole': 'Courier',
  13534. 'LucidaConsole-Bold': 'Courier-Bold',
  13535. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13536. 'LucidaConsole-Italic': 'Courier-Oblique',
  13537. 'MS-Gothic': 'MS Gothic',
  13538. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13539. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13540. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13541. 'MS-Mincho': 'MS Mincho',
  13542. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13543. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13544. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13545. 'MS-PGothic': 'MS PGothic',
  13546. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13547. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13548. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13549. 'MS-PMincho': 'MS PMincho',
  13550. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13551. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13552. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13553. 'Wingdings': 'ZapfDingbats'
  13554. };
  13555. var serifFonts = {
  13556. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13557. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13558. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13559. 'Arno': true, 'Aster': true, 'Aurora': true,
  13560. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13561. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13562. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13563. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13564. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13565. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13566. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13567. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13568. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13569. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13570. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13571. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13572. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13573. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13574. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13575. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13576. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13577. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13578. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13579. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13580. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13581. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13582. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13583. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13584. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13585. 'Miller': true, 'Minion': true, 'Modern': true,
  13586. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13587. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13588. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13589. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13590. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13591. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13592. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13593. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13594. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13595. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13596. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13597. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13598. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13599. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13600. };
  13601. var symbolsFonts = {
  13602. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13603. };
  13604. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13605. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13606. // glyphs, but common for some set of the standard fonts.
  13607. var GlyphMapForStandardFonts = {
  13608. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13609. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13610. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13611. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13612. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13613. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13614. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13615. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13616. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13617. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13618. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13619. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13620. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13621. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13622. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13623. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13624. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13625. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13626. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13627. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13628. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13629. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13630. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13631. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13632. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13633. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13634. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13635. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13636. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13637. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13638. '298': 380, '305': 963,
  13639. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13640. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13641. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13642. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13643. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13644. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13645. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13646. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13647. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13648. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13649. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13650. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13651. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13652. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13653. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13654. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13655. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13656. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13657. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13658. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13659. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13660. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13661. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13662. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13663. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13664. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13665. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13666. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13667. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13668. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13669. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13670. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13671. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13672. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13673. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13674. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13675. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13676. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13677. };
  13678. // The glyph map for ArialBlack differs slightly from the glyph map used for
  13679. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  13680. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  13681. var SupplementalGlyphMapForArialBlack = {
  13682. '227': 322, '264': 261, '291': 346,
  13683. };
  13684. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13685. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13686. // to the similar equivalents in the normal characters range.
  13687. var SpecialPUASymbols = {
  13688. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13689. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13690. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13691. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13692. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13693. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13694. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13695. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13696. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13697. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13698. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13699. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13700. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13701. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13702. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13703. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13704. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13705. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13706. '63723': 0x239B, // parenlefttp (0xF8EB)
  13707. '63724': 0x239C, // parenleftex (0xF8EC)
  13708. '63725': 0x239D, // parenleftbt (0xF8ED)
  13709. '63734': 0x239E, // parenrighttp (0xF8F6)
  13710. '63735': 0x239F, // parenrightex (0xF8F7)
  13711. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13712. };
  13713. function mapSpecialUnicodeValues(code) {
  13714. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13715. return 0;
  13716. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13717. return (SpecialPUASymbols[code] || code);
  13718. }
  13719. return code;
  13720. }
  13721. var UnicodeRanges = [
  13722. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13723. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13724. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13725. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13726. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13727. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13728. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13729. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13730. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13731. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13732. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13733. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13734. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13735. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13736. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13737. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13738. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13739. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13740. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13741. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13742. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13743. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13744. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13745. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13746. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13747. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13748. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13749. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13750. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13751. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13752. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13753. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13754. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13755. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13756. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13757. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13758. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13759. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13760. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13761. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13762. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13763. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13764. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13765. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13766. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13767. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13768. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13769. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13770. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13771. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13772. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13773. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13774. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13775. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13776. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13777. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13778. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13779. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13780. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13781. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13782. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13783. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13784. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13785. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13786. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13787. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13788. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13789. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13790. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13791. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13792. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13793. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13794. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13795. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13796. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13797. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13798. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13799. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13800. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13801. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13802. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13803. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13804. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13805. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13806. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13807. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13808. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13809. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13810. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13811. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13812. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13813. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13814. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13815. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13816. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13817. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13818. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13819. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13820. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13821. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13822. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13823. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13824. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13825. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13826. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13827. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13828. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13829. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13830. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13831. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13832. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13833. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13834. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13835. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13836. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13837. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13838. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13839. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13840. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13841. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13842. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13843. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13844. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13845. ];
  13846. var MacStandardGlyphOrdering = [
  13847. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13848. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13849. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13850. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13851. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13852. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13853. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13854. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13855. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13856. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13857. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13858. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13859. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13860. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13861. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13862. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13863. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13864. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13865. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13866. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13867. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13868. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13869. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13870. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13871. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13872. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13873. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13874. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13875. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13876. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13877. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13878. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13879. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13880. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13881. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13882. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13883. function getUnicodeRangeFor(value) {
  13884. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13885. var range = UnicodeRanges[i];
  13886. if (value >= range.begin && value < range.end) {
  13887. return i;
  13888. }
  13889. }
  13890. return -1;
  13891. }
  13892. function isRTLRangeFor(value) {
  13893. var range = UnicodeRanges[13];
  13894. if (value >= range.begin && value < range.end) {
  13895. return true;
  13896. }
  13897. range = UnicodeRanges[11];
  13898. if (value >= range.begin && value < range.end) {
  13899. return true;
  13900. }
  13901. return false;
  13902. }
  13903. // The normalization table is obtained by filtering the Unicode characters
  13904. // database with <compat> entries.
  13905. var NormalizedUnicodes = {
  13906. '\u00A8': '\u0020\u0308',
  13907. '\u00AF': '\u0020\u0304',
  13908. '\u00B4': '\u0020\u0301',
  13909. '\u00B5': '\u03BC',
  13910. '\u00B8': '\u0020\u0327',
  13911. '\u0132': '\u0049\u004A',
  13912. '\u0133': '\u0069\u006A',
  13913. '\u013F': '\u004C\u00B7',
  13914. '\u0140': '\u006C\u00B7',
  13915. '\u0149': '\u02BC\u006E',
  13916. '\u017F': '\u0073',
  13917. '\u01C4': '\u0044\u017D',
  13918. '\u01C5': '\u0044\u017E',
  13919. '\u01C6': '\u0064\u017E',
  13920. '\u01C7': '\u004C\u004A',
  13921. '\u01C8': '\u004C\u006A',
  13922. '\u01C9': '\u006C\u006A',
  13923. '\u01CA': '\u004E\u004A',
  13924. '\u01CB': '\u004E\u006A',
  13925. '\u01CC': '\u006E\u006A',
  13926. '\u01F1': '\u0044\u005A',
  13927. '\u01F2': '\u0044\u007A',
  13928. '\u01F3': '\u0064\u007A',
  13929. '\u02D8': '\u0020\u0306',
  13930. '\u02D9': '\u0020\u0307',
  13931. '\u02DA': '\u0020\u030A',
  13932. '\u02DB': '\u0020\u0328',
  13933. '\u02DC': '\u0020\u0303',
  13934. '\u02DD': '\u0020\u030B',
  13935. '\u037A': '\u0020\u0345',
  13936. '\u0384': '\u0020\u0301',
  13937. '\u03D0': '\u03B2',
  13938. '\u03D1': '\u03B8',
  13939. '\u03D2': '\u03A5',
  13940. '\u03D5': '\u03C6',
  13941. '\u03D6': '\u03C0',
  13942. '\u03F0': '\u03BA',
  13943. '\u03F1': '\u03C1',
  13944. '\u03F2': '\u03C2',
  13945. '\u03F4': '\u0398',
  13946. '\u03F5': '\u03B5',
  13947. '\u03F9': '\u03A3',
  13948. '\u0587': '\u0565\u0582',
  13949. '\u0675': '\u0627\u0674',
  13950. '\u0676': '\u0648\u0674',
  13951. '\u0677': '\u06C7\u0674',
  13952. '\u0678': '\u064A\u0674',
  13953. '\u0E33': '\u0E4D\u0E32',
  13954. '\u0EB3': '\u0ECD\u0EB2',
  13955. '\u0EDC': '\u0EAB\u0E99',
  13956. '\u0EDD': '\u0EAB\u0EA1',
  13957. '\u0F77': '\u0FB2\u0F81',
  13958. '\u0F79': '\u0FB3\u0F81',
  13959. '\u1E9A': '\u0061\u02BE',
  13960. '\u1FBD': '\u0020\u0313',
  13961. '\u1FBF': '\u0020\u0313',
  13962. '\u1FC0': '\u0020\u0342',
  13963. '\u1FFE': '\u0020\u0314',
  13964. '\u2002': '\u0020',
  13965. '\u2003': '\u0020',
  13966. '\u2004': '\u0020',
  13967. '\u2005': '\u0020',
  13968. '\u2006': '\u0020',
  13969. '\u2008': '\u0020',
  13970. '\u2009': '\u0020',
  13971. '\u200A': '\u0020',
  13972. '\u2017': '\u0020\u0333',
  13973. '\u2024': '\u002E',
  13974. '\u2025': '\u002E\u002E',
  13975. '\u2026': '\u002E\u002E\u002E',
  13976. '\u2033': '\u2032\u2032',
  13977. '\u2034': '\u2032\u2032\u2032',
  13978. '\u2036': '\u2035\u2035',
  13979. '\u2037': '\u2035\u2035\u2035',
  13980. '\u203C': '\u0021\u0021',
  13981. '\u203E': '\u0020\u0305',
  13982. '\u2047': '\u003F\u003F',
  13983. '\u2048': '\u003F\u0021',
  13984. '\u2049': '\u0021\u003F',
  13985. '\u2057': '\u2032\u2032\u2032\u2032',
  13986. '\u205F': '\u0020',
  13987. '\u20A8': '\u0052\u0073',
  13988. '\u2100': '\u0061\u002F\u0063',
  13989. '\u2101': '\u0061\u002F\u0073',
  13990. '\u2103': '\u00B0\u0043',
  13991. '\u2105': '\u0063\u002F\u006F',
  13992. '\u2106': '\u0063\u002F\u0075',
  13993. '\u2107': '\u0190',
  13994. '\u2109': '\u00B0\u0046',
  13995. '\u2116': '\u004E\u006F',
  13996. '\u2121': '\u0054\u0045\u004C',
  13997. '\u2135': '\u05D0',
  13998. '\u2136': '\u05D1',
  13999. '\u2137': '\u05D2',
  14000. '\u2138': '\u05D3',
  14001. '\u213B': '\u0046\u0041\u0058',
  14002. '\u2160': '\u0049',
  14003. '\u2161': '\u0049\u0049',
  14004. '\u2162': '\u0049\u0049\u0049',
  14005. '\u2163': '\u0049\u0056',
  14006. '\u2164': '\u0056',
  14007. '\u2165': '\u0056\u0049',
  14008. '\u2166': '\u0056\u0049\u0049',
  14009. '\u2167': '\u0056\u0049\u0049\u0049',
  14010. '\u2168': '\u0049\u0058',
  14011. '\u2169': '\u0058',
  14012. '\u216A': '\u0058\u0049',
  14013. '\u216B': '\u0058\u0049\u0049',
  14014. '\u216C': '\u004C',
  14015. '\u216D': '\u0043',
  14016. '\u216E': '\u0044',
  14017. '\u216F': '\u004D',
  14018. '\u2170': '\u0069',
  14019. '\u2171': '\u0069\u0069',
  14020. '\u2172': '\u0069\u0069\u0069',
  14021. '\u2173': '\u0069\u0076',
  14022. '\u2174': '\u0076',
  14023. '\u2175': '\u0076\u0069',
  14024. '\u2176': '\u0076\u0069\u0069',
  14025. '\u2177': '\u0076\u0069\u0069\u0069',
  14026. '\u2178': '\u0069\u0078',
  14027. '\u2179': '\u0078',
  14028. '\u217A': '\u0078\u0069',
  14029. '\u217B': '\u0078\u0069\u0069',
  14030. '\u217C': '\u006C',
  14031. '\u217D': '\u0063',
  14032. '\u217E': '\u0064',
  14033. '\u217F': '\u006D',
  14034. '\u222C': '\u222B\u222B',
  14035. '\u222D': '\u222B\u222B\u222B',
  14036. '\u222F': '\u222E\u222E',
  14037. '\u2230': '\u222E\u222E\u222E',
  14038. '\u2474': '\u0028\u0031\u0029',
  14039. '\u2475': '\u0028\u0032\u0029',
  14040. '\u2476': '\u0028\u0033\u0029',
  14041. '\u2477': '\u0028\u0034\u0029',
  14042. '\u2478': '\u0028\u0035\u0029',
  14043. '\u2479': '\u0028\u0036\u0029',
  14044. '\u247A': '\u0028\u0037\u0029',
  14045. '\u247B': '\u0028\u0038\u0029',
  14046. '\u247C': '\u0028\u0039\u0029',
  14047. '\u247D': '\u0028\u0031\u0030\u0029',
  14048. '\u247E': '\u0028\u0031\u0031\u0029',
  14049. '\u247F': '\u0028\u0031\u0032\u0029',
  14050. '\u2480': '\u0028\u0031\u0033\u0029',
  14051. '\u2481': '\u0028\u0031\u0034\u0029',
  14052. '\u2482': '\u0028\u0031\u0035\u0029',
  14053. '\u2483': '\u0028\u0031\u0036\u0029',
  14054. '\u2484': '\u0028\u0031\u0037\u0029',
  14055. '\u2485': '\u0028\u0031\u0038\u0029',
  14056. '\u2486': '\u0028\u0031\u0039\u0029',
  14057. '\u2487': '\u0028\u0032\u0030\u0029',
  14058. '\u2488': '\u0031\u002E',
  14059. '\u2489': '\u0032\u002E',
  14060. '\u248A': '\u0033\u002E',
  14061. '\u248B': '\u0034\u002E',
  14062. '\u248C': '\u0035\u002E',
  14063. '\u248D': '\u0036\u002E',
  14064. '\u248E': '\u0037\u002E',
  14065. '\u248F': '\u0038\u002E',
  14066. '\u2490': '\u0039\u002E',
  14067. '\u2491': '\u0031\u0030\u002E',
  14068. '\u2492': '\u0031\u0031\u002E',
  14069. '\u2493': '\u0031\u0032\u002E',
  14070. '\u2494': '\u0031\u0033\u002E',
  14071. '\u2495': '\u0031\u0034\u002E',
  14072. '\u2496': '\u0031\u0035\u002E',
  14073. '\u2497': '\u0031\u0036\u002E',
  14074. '\u2498': '\u0031\u0037\u002E',
  14075. '\u2499': '\u0031\u0038\u002E',
  14076. '\u249A': '\u0031\u0039\u002E',
  14077. '\u249B': '\u0032\u0030\u002E',
  14078. '\u249C': '\u0028\u0061\u0029',
  14079. '\u249D': '\u0028\u0062\u0029',
  14080. '\u249E': '\u0028\u0063\u0029',
  14081. '\u249F': '\u0028\u0064\u0029',
  14082. '\u24A0': '\u0028\u0065\u0029',
  14083. '\u24A1': '\u0028\u0066\u0029',
  14084. '\u24A2': '\u0028\u0067\u0029',
  14085. '\u24A3': '\u0028\u0068\u0029',
  14086. '\u24A4': '\u0028\u0069\u0029',
  14087. '\u24A5': '\u0028\u006A\u0029',
  14088. '\u24A6': '\u0028\u006B\u0029',
  14089. '\u24A7': '\u0028\u006C\u0029',
  14090. '\u24A8': '\u0028\u006D\u0029',
  14091. '\u24A9': '\u0028\u006E\u0029',
  14092. '\u24AA': '\u0028\u006F\u0029',
  14093. '\u24AB': '\u0028\u0070\u0029',
  14094. '\u24AC': '\u0028\u0071\u0029',
  14095. '\u24AD': '\u0028\u0072\u0029',
  14096. '\u24AE': '\u0028\u0073\u0029',
  14097. '\u24AF': '\u0028\u0074\u0029',
  14098. '\u24B0': '\u0028\u0075\u0029',
  14099. '\u24B1': '\u0028\u0076\u0029',
  14100. '\u24B2': '\u0028\u0077\u0029',
  14101. '\u24B3': '\u0028\u0078\u0029',
  14102. '\u24B4': '\u0028\u0079\u0029',
  14103. '\u24B5': '\u0028\u007A\u0029',
  14104. '\u2A0C': '\u222B\u222B\u222B\u222B',
  14105. '\u2A74': '\u003A\u003A\u003D',
  14106. '\u2A75': '\u003D\u003D',
  14107. '\u2A76': '\u003D\u003D\u003D',
  14108. '\u2E9F': '\u6BCD',
  14109. '\u2EF3': '\u9F9F',
  14110. '\u2F00': '\u4E00',
  14111. '\u2F01': '\u4E28',
  14112. '\u2F02': '\u4E36',
  14113. '\u2F03': '\u4E3F',
  14114. '\u2F04': '\u4E59',
  14115. '\u2F05': '\u4E85',
  14116. '\u2F06': '\u4E8C',
  14117. '\u2F07': '\u4EA0',
  14118. '\u2F08': '\u4EBA',
  14119. '\u2F09': '\u513F',
  14120. '\u2F0A': '\u5165',
  14121. '\u2F0B': '\u516B',
  14122. '\u2F0C': '\u5182',
  14123. '\u2F0D': '\u5196',
  14124. '\u2F0E': '\u51AB',
  14125. '\u2F0F': '\u51E0',
  14126. '\u2F10': '\u51F5',
  14127. '\u2F11': '\u5200',
  14128. '\u2F12': '\u529B',
  14129. '\u2F13': '\u52F9',
  14130. '\u2F14': '\u5315',
  14131. '\u2F15': '\u531A',
  14132. '\u2F16': '\u5338',
  14133. '\u2F17': '\u5341',
  14134. '\u2F18': '\u535C',
  14135. '\u2F19': '\u5369',
  14136. '\u2F1A': '\u5382',
  14137. '\u2F1B': '\u53B6',
  14138. '\u2F1C': '\u53C8',
  14139. '\u2F1D': '\u53E3',
  14140. '\u2F1E': '\u56D7',
  14141. '\u2F1F': '\u571F',
  14142. '\u2F20': '\u58EB',
  14143. '\u2F21': '\u5902',
  14144. '\u2F22': '\u590A',
  14145. '\u2F23': '\u5915',
  14146. '\u2F24': '\u5927',
  14147. '\u2F25': '\u5973',
  14148. '\u2F26': '\u5B50',
  14149. '\u2F27': '\u5B80',
  14150. '\u2F28': '\u5BF8',
  14151. '\u2F29': '\u5C0F',
  14152. '\u2F2A': '\u5C22',
  14153. '\u2F2B': '\u5C38',
  14154. '\u2F2C': '\u5C6E',
  14155. '\u2F2D': '\u5C71',
  14156. '\u2F2E': '\u5DDB',
  14157. '\u2F2F': '\u5DE5',
  14158. '\u2F30': '\u5DF1',
  14159. '\u2F31': '\u5DFE',
  14160. '\u2F32': '\u5E72',
  14161. '\u2F33': '\u5E7A',
  14162. '\u2F34': '\u5E7F',
  14163. '\u2F35': '\u5EF4',
  14164. '\u2F36': '\u5EFE',
  14165. '\u2F37': '\u5F0B',
  14166. '\u2F38': '\u5F13',
  14167. '\u2F39': '\u5F50',
  14168. '\u2F3A': '\u5F61',
  14169. '\u2F3B': '\u5F73',
  14170. '\u2F3C': '\u5FC3',
  14171. '\u2F3D': '\u6208',
  14172. '\u2F3E': '\u6236',
  14173. '\u2F3F': '\u624B',
  14174. '\u2F40': '\u652F',
  14175. '\u2F41': '\u6534',
  14176. '\u2F42': '\u6587',
  14177. '\u2F43': '\u6597',
  14178. '\u2F44': '\u65A4',
  14179. '\u2F45': '\u65B9',
  14180. '\u2F46': '\u65E0',
  14181. '\u2F47': '\u65E5',
  14182. '\u2F48': '\u66F0',
  14183. '\u2F49': '\u6708',
  14184. '\u2F4A': '\u6728',
  14185. '\u2F4B': '\u6B20',
  14186. '\u2F4C': '\u6B62',
  14187. '\u2F4D': '\u6B79',
  14188. '\u2F4E': '\u6BB3',
  14189. '\u2F4F': '\u6BCB',
  14190. '\u2F50': '\u6BD4',
  14191. '\u2F51': '\u6BDB',
  14192. '\u2F52': '\u6C0F',
  14193. '\u2F53': '\u6C14',
  14194. '\u2F54': '\u6C34',
  14195. '\u2F55': '\u706B',
  14196. '\u2F56': '\u722A',
  14197. '\u2F57': '\u7236',
  14198. '\u2F58': '\u723B',
  14199. '\u2F59': '\u723F',
  14200. '\u2F5A': '\u7247',
  14201. '\u2F5B': '\u7259',
  14202. '\u2F5C': '\u725B',
  14203. '\u2F5D': '\u72AC',
  14204. '\u2F5E': '\u7384',
  14205. '\u2F5F': '\u7389',
  14206. '\u2F60': '\u74DC',
  14207. '\u2F61': '\u74E6',
  14208. '\u2F62': '\u7518',
  14209. '\u2F63': '\u751F',
  14210. '\u2F64': '\u7528',
  14211. '\u2F65': '\u7530',
  14212. '\u2F66': '\u758B',
  14213. '\u2F67': '\u7592',
  14214. '\u2F68': '\u7676',
  14215. '\u2F69': '\u767D',
  14216. '\u2F6A': '\u76AE',
  14217. '\u2F6B': '\u76BF',
  14218. '\u2F6C': '\u76EE',
  14219. '\u2F6D': '\u77DB',
  14220. '\u2F6E': '\u77E2',
  14221. '\u2F6F': '\u77F3',
  14222. '\u2F70': '\u793A',
  14223. '\u2F71': '\u79B8',
  14224. '\u2F72': '\u79BE',
  14225. '\u2F73': '\u7A74',
  14226. '\u2F74': '\u7ACB',
  14227. '\u2F75': '\u7AF9',
  14228. '\u2F76': '\u7C73',
  14229. '\u2F77': '\u7CF8',
  14230. '\u2F78': '\u7F36',
  14231. '\u2F79': '\u7F51',
  14232. '\u2F7A': '\u7F8A',
  14233. '\u2F7B': '\u7FBD',
  14234. '\u2F7C': '\u8001',
  14235. '\u2F7D': '\u800C',
  14236. '\u2F7E': '\u8012',
  14237. '\u2F7F': '\u8033',
  14238. '\u2F80': '\u807F',
  14239. '\u2F81': '\u8089',
  14240. '\u2F82': '\u81E3',
  14241. '\u2F83': '\u81EA',
  14242. '\u2F84': '\u81F3',
  14243. '\u2F85': '\u81FC',
  14244. '\u2F86': '\u820C',
  14245. '\u2F87': '\u821B',
  14246. '\u2F88': '\u821F',
  14247. '\u2F89': '\u826E',
  14248. '\u2F8A': '\u8272',
  14249. '\u2F8B': '\u8278',
  14250. '\u2F8C': '\u864D',
  14251. '\u2F8D': '\u866B',
  14252. '\u2F8E': '\u8840',
  14253. '\u2F8F': '\u884C',
  14254. '\u2F90': '\u8863',
  14255. '\u2F91': '\u897E',
  14256. '\u2F92': '\u898B',
  14257. '\u2F93': '\u89D2',
  14258. '\u2F94': '\u8A00',
  14259. '\u2F95': '\u8C37',
  14260. '\u2F96': '\u8C46',
  14261. '\u2F97': '\u8C55',
  14262. '\u2F98': '\u8C78',
  14263. '\u2F99': '\u8C9D',
  14264. '\u2F9A': '\u8D64',
  14265. '\u2F9B': '\u8D70',
  14266. '\u2F9C': '\u8DB3',
  14267. '\u2F9D': '\u8EAB',
  14268. '\u2F9E': '\u8ECA',
  14269. '\u2F9F': '\u8F9B',
  14270. '\u2FA0': '\u8FB0',
  14271. '\u2FA1': '\u8FB5',
  14272. '\u2FA2': '\u9091',
  14273. '\u2FA3': '\u9149',
  14274. '\u2FA4': '\u91C6',
  14275. '\u2FA5': '\u91CC',
  14276. '\u2FA6': '\u91D1',
  14277. '\u2FA7': '\u9577',
  14278. '\u2FA8': '\u9580',
  14279. '\u2FA9': '\u961C',
  14280. '\u2FAA': '\u96B6',
  14281. '\u2FAB': '\u96B9',
  14282. '\u2FAC': '\u96E8',
  14283. '\u2FAD': '\u9751',
  14284. '\u2FAE': '\u975E',
  14285. '\u2FAF': '\u9762',
  14286. '\u2FB0': '\u9769',
  14287. '\u2FB1': '\u97CB',
  14288. '\u2FB2': '\u97ED',
  14289. '\u2FB3': '\u97F3',
  14290. '\u2FB4': '\u9801',
  14291. '\u2FB5': '\u98A8',
  14292. '\u2FB6': '\u98DB',
  14293. '\u2FB7': '\u98DF',
  14294. '\u2FB8': '\u9996',
  14295. '\u2FB9': '\u9999',
  14296. '\u2FBA': '\u99AC',
  14297. '\u2FBB': '\u9AA8',
  14298. '\u2FBC': '\u9AD8',
  14299. '\u2FBD': '\u9ADF',
  14300. '\u2FBE': '\u9B25',
  14301. '\u2FBF': '\u9B2F',
  14302. '\u2FC0': '\u9B32',
  14303. '\u2FC1': '\u9B3C',
  14304. '\u2FC2': '\u9B5A',
  14305. '\u2FC3': '\u9CE5',
  14306. '\u2FC4': '\u9E75',
  14307. '\u2FC5': '\u9E7F',
  14308. '\u2FC6': '\u9EA5',
  14309. '\u2FC7': '\u9EBB',
  14310. '\u2FC8': '\u9EC3',
  14311. '\u2FC9': '\u9ECD',
  14312. '\u2FCA': '\u9ED1',
  14313. '\u2FCB': '\u9EF9',
  14314. '\u2FCC': '\u9EFD',
  14315. '\u2FCD': '\u9F0E',
  14316. '\u2FCE': '\u9F13',
  14317. '\u2FCF': '\u9F20',
  14318. '\u2FD0': '\u9F3B',
  14319. '\u2FD1': '\u9F4A',
  14320. '\u2FD2': '\u9F52',
  14321. '\u2FD3': '\u9F8D',
  14322. '\u2FD4': '\u9F9C',
  14323. '\u2FD5': '\u9FA0',
  14324. '\u3036': '\u3012',
  14325. '\u3038': '\u5341',
  14326. '\u3039': '\u5344',
  14327. '\u303A': '\u5345',
  14328. '\u309B': '\u0020\u3099',
  14329. '\u309C': '\u0020\u309A',
  14330. '\u3131': '\u1100',
  14331. '\u3132': '\u1101',
  14332. '\u3133': '\u11AA',
  14333. '\u3134': '\u1102',
  14334. '\u3135': '\u11AC',
  14335. '\u3136': '\u11AD',
  14336. '\u3137': '\u1103',
  14337. '\u3138': '\u1104',
  14338. '\u3139': '\u1105',
  14339. '\u313A': '\u11B0',
  14340. '\u313B': '\u11B1',
  14341. '\u313C': '\u11B2',
  14342. '\u313D': '\u11B3',
  14343. '\u313E': '\u11B4',
  14344. '\u313F': '\u11B5',
  14345. '\u3140': '\u111A',
  14346. '\u3141': '\u1106',
  14347. '\u3142': '\u1107',
  14348. '\u3143': '\u1108',
  14349. '\u3144': '\u1121',
  14350. '\u3145': '\u1109',
  14351. '\u3146': '\u110A',
  14352. '\u3147': '\u110B',
  14353. '\u3148': '\u110C',
  14354. '\u3149': '\u110D',
  14355. '\u314A': '\u110E',
  14356. '\u314B': '\u110F',
  14357. '\u314C': '\u1110',
  14358. '\u314D': '\u1111',
  14359. '\u314E': '\u1112',
  14360. '\u314F': '\u1161',
  14361. '\u3150': '\u1162',
  14362. '\u3151': '\u1163',
  14363. '\u3152': '\u1164',
  14364. '\u3153': '\u1165',
  14365. '\u3154': '\u1166',
  14366. '\u3155': '\u1167',
  14367. '\u3156': '\u1168',
  14368. '\u3157': '\u1169',
  14369. '\u3158': '\u116A',
  14370. '\u3159': '\u116B',
  14371. '\u315A': '\u116C',
  14372. '\u315B': '\u116D',
  14373. '\u315C': '\u116E',
  14374. '\u315D': '\u116F',
  14375. '\u315E': '\u1170',
  14376. '\u315F': '\u1171',
  14377. '\u3160': '\u1172',
  14378. '\u3161': '\u1173',
  14379. '\u3162': '\u1174',
  14380. '\u3163': '\u1175',
  14381. '\u3164': '\u1160',
  14382. '\u3165': '\u1114',
  14383. '\u3166': '\u1115',
  14384. '\u3167': '\u11C7',
  14385. '\u3168': '\u11C8',
  14386. '\u3169': '\u11CC',
  14387. '\u316A': '\u11CE',
  14388. '\u316B': '\u11D3',
  14389. '\u316C': '\u11D7',
  14390. '\u316D': '\u11D9',
  14391. '\u316E': '\u111C',
  14392. '\u316F': '\u11DD',
  14393. '\u3170': '\u11DF',
  14394. '\u3171': '\u111D',
  14395. '\u3172': '\u111E',
  14396. '\u3173': '\u1120',
  14397. '\u3174': '\u1122',
  14398. '\u3175': '\u1123',
  14399. '\u3176': '\u1127',
  14400. '\u3177': '\u1129',
  14401. '\u3178': '\u112B',
  14402. '\u3179': '\u112C',
  14403. '\u317A': '\u112D',
  14404. '\u317B': '\u112E',
  14405. '\u317C': '\u112F',
  14406. '\u317D': '\u1132',
  14407. '\u317E': '\u1136',
  14408. '\u317F': '\u1140',
  14409. '\u3180': '\u1147',
  14410. '\u3181': '\u114C',
  14411. '\u3182': '\u11F1',
  14412. '\u3183': '\u11F2',
  14413. '\u3184': '\u1157',
  14414. '\u3185': '\u1158',
  14415. '\u3186': '\u1159',
  14416. '\u3187': '\u1184',
  14417. '\u3188': '\u1185',
  14418. '\u3189': '\u1188',
  14419. '\u318A': '\u1191',
  14420. '\u318B': '\u1192',
  14421. '\u318C': '\u1194',
  14422. '\u318D': '\u119E',
  14423. '\u318E': '\u11A1',
  14424. '\u3200': '\u0028\u1100\u0029',
  14425. '\u3201': '\u0028\u1102\u0029',
  14426. '\u3202': '\u0028\u1103\u0029',
  14427. '\u3203': '\u0028\u1105\u0029',
  14428. '\u3204': '\u0028\u1106\u0029',
  14429. '\u3205': '\u0028\u1107\u0029',
  14430. '\u3206': '\u0028\u1109\u0029',
  14431. '\u3207': '\u0028\u110B\u0029',
  14432. '\u3208': '\u0028\u110C\u0029',
  14433. '\u3209': '\u0028\u110E\u0029',
  14434. '\u320A': '\u0028\u110F\u0029',
  14435. '\u320B': '\u0028\u1110\u0029',
  14436. '\u320C': '\u0028\u1111\u0029',
  14437. '\u320D': '\u0028\u1112\u0029',
  14438. '\u320E': '\u0028\u1100\u1161\u0029',
  14439. '\u320F': '\u0028\u1102\u1161\u0029',
  14440. '\u3210': '\u0028\u1103\u1161\u0029',
  14441. '\u3211': '\u0028\u1105\u1161\u0029',
  14442. '\u3212': '\u0028\u1106\u1161\u0029',
  14443. '\u3213': '\u0028\u1107\u1161\u0029',
  14444. '\u3214': '\u0028\u1109\u1161\u0029',
  14445. '\u3215': '\u0028\u110B\u1161\u0029',
  14446. '\u3216': '\u0028\u110C\u1161\u0029',
  14447. '\u3217': '\u0028\u110E\u1161\u0029',
  14448. '\u3218': '\u0028\u110F\u1161\u0029',
  14449. '\u3219': '\u0028\u1110\u1161\u0029',
  14450. '\u321A': '\u0028\u1111\u1161\u0029',
  14451. '\u321B': '\u0028\u1112\u1161\u0029',
  14452. '\u321C': '\u0028\u110C\u116E\u0029',
  14453. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14454. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14455. '\u3220': '\u0028\u4E00\u0029',
  14456. '\u3221': '\u0028\u4E8C\u0029',
  14457. '\u3222': '\u0028\u4E09\u0029',
  14458. '\u3223': '\u0028\u56DB\u0029',
  14459. '\u3224': '\u0028\u4E94\u0029',
  14460. '\u3225': '\u0028\u516D\u0029',
  14461. '\u3226': '\u0028\u4E03\u0029',
  14462. '\u3227': '\u0028\u516B\u0029',
  14463. '\u3228': '\u0028\u4E5D\u0029',
  14464. '\u3229': '\u0028\u5341\u0029',
  14465. '\u322A': '\u0028\u6708\u0029',
  14466. '\u322B': '\u0028\u706B\u0029',
  14467. '\u322C': '\u0028\u6C34\u0029',
  14468. '\u322D': '\u0028\u6728\u0029',
  14469. '\u322E': '\u0028\u91D1\u0029',
  14470. '\u322F': '\u0028\u571F\u0029',
  14471. '\u3230': '\u0028\u65E5\u0029',
  14472. '\u3231': '\u0028\u682A\u0029',
  14473. '\u3232': '\u0028\u6709\u0029',
  14474. '\u3233': '\u0028\u793E\u0029',
  14475. '\u3234': '\u0028\u540D\u0029',
  14476. '\u3235': '\u0028\u7279\u0029',
  14477. '\u3236': '\u0028\u8CA1\u0029',
  14478. '\u3237': '\u0028\u795D\u0029',
  14479. '\u3238': '\u0028\u52B4\u0029',
  14480. '\u3239': '\u0028\u4EE3\u0029',
  14481. '\u323A': '\u0028\u547C\u0029',
  14482. '\u323B': '\u0028\u5B66\u0029',
  14483. '\u323C': '\u0028\u76E3\u0029',
  14484. '\u323D': '\u0028\u4F01\u0029',
  14485. '\u323E': '\u0028\u8CC7\u0029',
  14486. '\u323F': '\u0028\u5354\u0029',
  14487. '\u3240': '\u0028\u796D\u0029',
  14488. '\u3241': '\u0028\u4F11\u0029',
  14489. '\u3242': '\u0028\u81EA\u0029',
  14490. '\u3243': '\u0028\u81F3\u0029',
  14491. '\u32C0': '\u0031\u6708',
  14492. '\u32C1': '\u0032\u6708',
  14493. '\u32C2': '\u0033\u6708',
  14494. '\u32C3': '\u0034\u6708',
  14495. '\u32C4': '\u0035\u6708',
  14496. '\u32C5': '\u0036\u6708',
  14497. '\u32C6': '\u0037\u6708',
  14498. '\u32C7': '\u0038\u6708',
  14499. '\u32C8': '\u0039\u6708',
  14500. '\u32C9': '\u0031\u0030\u6708',
  14501. '\u32CA': '\u0031\u0031\u6708',
  14502. '\u32CB': '\u0031\u0032\u6708',
  14503. '\u3358': '\u0030\u70B9',
  14504. '\u3359': '\u0031\u70B9',
  14505. '\u335A': '\u0032\u70B9',
  14506. '\u335B': '\u0033\u70B9',
  14507. '\u335C': '\u0034\u70B9',
  14508. '\u335D': '\u0035\u70B9',
  14509. '\u335E': '\u0036\u70B9',
  14510. '\u335F': '\u0037\u70B9',
  14511. '\u3360': '\u0038\u70B9',
  14512. '\u3361': '\u0039\u70B9',
  14513. '\u3362': '\u0031\u0030\u70B9',
  14514. '\u3363': '\u0031\u0031\u70B9',
  14515. '\u3364': '\u0031\u0032\u70B9',
  14516. '\u3365': '\u0031\u0033\u70B9',
  14517. '\u3366': '\u0031\u0034\u70B9',
  14518. '\u3367': '\u0031\u0035\u70B9',
  14519. '\u3368': '\u0031\u0036\u70B9',
  14520. '\u3369': '\u0031\u0037\u70B9',
  14521. '\u336A': '\u0031\u0038\u70B9',
  14522. '\u336B': '\u0031\u0039\u70B9',
  14523. '\u336C': '\u0032\u0030\u70B9',
  14524. '\u336D': '\u0032\u0031\u70B9',
  14525. '\u336E': '\u0032\u0032\u70B9',
  14526. '\u336F': '\u0032\u0033\u70B9',
  14527. '\u3370': '\u0032\u0034\u70B9',
  14528. '\u33E0': '\u0031\u65E5',
  14529. '\u33E1': '\u0032\u65E5',
  14530. '\u33E2': '\u0033\u65E5',
  14531. '\u33E3': '\u0034\u65E5',
  14532. '\u33E4': '\u0035\u65E5',
  14533. '\u33E5': '\u0036\u65E5',
  14534. '\u33E6': '\u0037\u65E5',
  14535. '\u33E7': '\u0038\u65E5',
  14536. '\u33E8': '\u0039\u65E5',
  14537. '\u33E9': '\u0031\u0030\u65E5',
  14538. '\u33EA': '\u0031\u0031\u65E5',
  14539. '\u33EB': '\u0031\u0032\u65E5',
  14540. '\u33EC': '\u0031\u0033\u65E5',
  14541. '\u33ED': '\u0031\u0034\u65E5',
  14542. '\u33EE': '\u0031\u0035\u65E5',
  14543. '\u33EF': '\u0031\u0036\u65E5',
  14544. '\u33F0': '\u0031\u0037\u65E5',
  14545. '\u33F1': '\u0031\u0038\u65E5',
  14546. '\u33F2': '\u0031\u0039\u65E5',
  14547. '\u33F3': '\u0032\u0030\u65E5',
  14548. '\u33F4': '\u0032\u0031\u65E5',
  14549. '\u33F5': '\u0032\u0032\u65E5',
  14550. '\u33F6': '\u0032\u0033\u65E5',
  14551. '\u33F7': '\u0032\u0034\u65E5',
  14552. '\u33F8': '\u0032\u0035\u65E5',
  14553. '\u33F9': '\u0032\u0036\u65E5',
  14554. '\u33FA': '\u0032\u0037\u65E5',
  14555. '\u33FB': '\u0032\u0038\u65E5',
  14556. '\u33FC': '\u0032\u0039\u65E5',
  14557. '\u33FD': '\u0033\u0030\u65E5',
  14558. '\u33FE': '\u0033\u0031\u65E5',
  14559. '\uFB00': '\u0066\u0066',
  14560. '\uFB01': '\u0066\u0069',
  14561. '\uFB02': '\u0066\u006C',
  14562. '\uFB03': '\u0066\u0066\u0069',
  14563. '\uFB04': '\u0066\u0066\u006C',
  14564. '\uFB05': '\u017F\u0074',
  14565. '\uFB06': '\u0073\u0074',
  14566. '\uFB13': '\u0574\u0576',
  14567. '\uFB14': '\u0574\u0565',
  14568. '\uFB15': '\u0574\u056B',
  14569. '\uFB16': '\u057E\u0576',
  14570. '\uFB17': '\u0574\u056D',
  14571. '\uFB4F': '\u05D0\u05DC',
  14572. '\uFB50': '\u0671',
  14573. '\uFB51': '\u0671',
  14574. '\uFB52': '\u067B',
  14575. '\uFB53': '\u067B',
  14576. '\uFB54': '\u067B',
  14577. '\uFB55': '\u067B',
  14578. '\uFB56': '\u067E',
  14579. '\uFB57': '\u067E',
  14580. '\uFB58': '\u067E',
  14581. '\uFB59': '\u067E',
  14582. '\uFB5A': '\u0680',
  14583. '\uFB5B': '\u0680',
  14584. '\uFB5C': '\u0680',
  14585. '\uFB5D': '\u0680',
  14586. '\uFB5E': '\u067A',
  14587. '\uFB5F': '\u067A',
  14588. '\uFB60': '\u067A',
  14589. '\uFB61': '\u067A',
  14590. '\uFB62': '\u067F',
  14591. '\uFB63': '\u067F',
  14592. '\uFB64': '\u067F',
  14593. '\uFB65': '\u067F',
  14594. '\uFB66': '\u0679',
  14595. '\uFB67': '\u0679',
  14596. '\uFB68': '\u0679',
  14597. '\uFB69': '\u0679',
  14598. '\uFB6A': '\u06A4',
  14599. '\uFB6B': '\u06A4',
  14600. '\uFB6C': '\u06A4',
  14601. '\uFB6D': '\u06A4',
  14602. '\uFB6E': '\u06A6',
  14603. '\uFB6F': '\u06A6',
  14604. '\uFB70': '\u06A6',
  14605. '\uFB71': '\u06A6',
  14606. '\uFB72': '\u0684',
  14607. '\uFB73': '\u0684',
  14608. '\uFB74': '\u0684',
  14609. '\uFB75': '\u0684',
  14610. '\uFB76': '\u0683',
  14611. '\uFB77': '\u0683',
  14612. '\uFB78': '\u0683',
  14613. '\uFB79': '\u0683',
  14614. '\uFB7A': '\u0686',
  14615. '\uFB7B': '\u0686',
  14616. '\uFB7C': '\u0686',
  14617. '\uFB7D': '\u0686',
  14618. '\uFB7E': '\u0687',
  14619. '\uFB7F': '\u0687',
  14620. '\uFB80': '\u0687',
  14621. '\uFB81': '\u0687',
  14622. '\uFB82': '\u068D',
  14623. '\uFB83': '\u068D',
  14624. '\uFB84': '\u068C',
  14625. '\uFB85': '\u068C',
  14626. '\uFB86': '\u068E',
  14627. '\uFB87': '\u068E',
  14628. '\uFB88': '\u0688',
  14629. '\uFB89': '\u0688',
  14630. '\uFB8A': '\u0698',
  14631. '\uFB8B': '\u0698',
  14632. '\uFB8C': '\u0691',
  14633. '\uFB8D': '\u0691',
  14634. '\uFB8E': '\u06A9',
  14635. '\uFB8F': '\u06A9',
  14636. '\uFB90': '\u06A9',
  14637. '\uFB91': '\u06A9',
  14638. '\uFB92': '\u06AF',
  14639. '\uFB93': '\u06AF',
  14640. '\uFB94': '\u06AF',
  14641. '\uFB95': '\u06AF',
  14642. '\uFB96': '\u06B3',
  14643. '\uFB97': '\u06B3',
  14644. '\uFB98': '\u06B3',
  14645. '\uFB99': '\u06B3',
  14646. '\uFB9A': '\u06B1',
  14647. '\uFB9B': '\u06B1',
  14648. '\uFB9C': '\u06B1',
  14649. '\uFB9D': '\u06B1',
  14650. '\uFB9E': '\u06BA',
  14651. '\uFB9F': '\u06BA',
  14652. '\uFBA0': '\u06BB',
  14653. '\uFBA1': '\u06BB',
  14654. '\uFBA2': '\u06BB',
  14655. '\uFBA3': '\u06BB',
  14656. '\uFBA4': '\u06C0',
  14657. '\uFBA5': '\u06C0',
  14658. '\uFBA6': '\u06C1',
  14659. '\uFBA7': '\u06C1',
  14660. '\uFBA8': '\u06C1',
  14661. '\uFBA9': '\u06C1',
  14662. '\uFBAA': '\u06BE',
  14663. '\uFBAB': '\u06BE',
  14664. '\uFBAC': '\u06BE',
  14665. '\uFBAD': '\u06BE',
  14666. '\uFBAE': '\u06D2',
  14667. '\uFBAF': '\u06D2',
  14668. '\uFBB0': '\u06D3',
  14669. '\uFBB1': '\u06D3',
  14670. '\uFBD3': '\u06AD',
  14671. '\uFBD4': '\u06AD',
  14672. '\uFBD5': '\u06AD',
  14673. '\uFBD6': '\u06AD',
  14674. '\uFBD7': '\u06C7',
  14675. '\uFBD8': '\u06C7',
  14676. '\uFBD9': '\u06C6',
  14677. '\uFBDA': '\u06C6',
  14678. '\uFBDB': '\u06C8',
  14679. '\uFBDC': '\u06C8',
  14680. '\uFBDD': '\u0677',
  14681. '\uFBDE': '\u06CB',
  14682. '\uFBDF': '\u06CB',
  14683. '\uFBE0': '\u06C5',
  14684. '\uFBE1': '\u06C5',
  14685. '\uFBE2': '\u06C9',
  14686. '\uFBE3': '\u06C9',
  14687. '\uFBE4': '\u06D0',
  14688. '\uFBE5': '\u06D0',
  14689. '\uFBE6': '\u06D0',
  14690. '\uFBE7': '\u06D0',
  14691. '\uFBE8': '\u0649',
  14692. '\uFBE9': '\u0649',
  14693. '\uFBEA': '\u0626\u0627',
  14694. '\uFBEB': '\u0626\u0627',
  14695. '\uFBEC': '\u0626\u06D5',
  14696. '\uFBED': '\u0626\u06D5',
  14697. '\uFBEE': '\u0626\u0648',
  14698. '\uFBEF': '\u0626\u0648',
  14699. '\uFBF0': '\u0626\u06C7',
  14700. '\uFBF1': '\u0626\u06C7',
  14701. '\uFBF2': '\u0626\u06C6',
  14702. '\uFBF3': '\u0626\u06C6',
  14703. '\uFBF4': '\u0626\u06C8',
  14704. '\uFBF5': '\u0626\u06C8',
  14705. '\uFBF6': '\u0626\u06D0',
  14706. '\uFBF7': '\u0626\u06D0',
  14707. '\uFBF8': '\u0626\u06D0',
  14708. '\uFBF9': '\u0626\u0649',
  14709. '\uFBFA': '\u0626\u0649',
  14710. '\uFBFB': '\u0626\u0649',
  14711. '\uFBFC': '\u06CC',
  14712. '\uFBFD': '\u06CC',
  14713. '\uFBFE': '\u06CC',
  14714. '\uFBFF': '\u06CC',
  14715. '\uFC00': '\u0626\u062C',
  14716. '\uFC01': '\u0626\u062D',
  14717. '\uFC02': '\u0626\u0645',
  14718. '\uFC03': '\u0626\u0649',
  14719. '\uFC04': '\u0626\u064A',
  14720. '\uFC05': '\u0628\u062C',
  14721. '\uFC06': '\u0628\u062D',
  14722. '\uFC07': '\u0628\u062E',
  14723. '\uFC08': '\u0628\u0645',
  14724. '\uFC09': '\u0628\u0649',
  14725. '\uFC0A': '\u0628\u064A',
  14726. '\uFC0B': '\u062A\u062C',
  14727. '\uFC0C': '\u062A\u062D',
  14728. '\uFC0D': '\u062A\u062E',
  14729. '\uFC0E': '\u062A\u0645',
  14730. '\uFC0F': '\u062A\u0649',
  14731. '\uFC10': '\u062A\u064A',
  14732. '\uFC11': '\u062B\u062C',
  14733. '\uFC12': '\u062B\u0645',
  14734. '\uFC13': '\u062B\u0649',
  14735. '\uFC14': '\u062B\u064A',
  14736. '\uFC15': '\u062C\u062D',
  14737. '\uFC16': '\u062C\u0645',
  14738. '\uFC17': '\u062D\u062C',
  14739. '\uFC18': '\u062D\u0645',
  14740. '\uFC19': '\u062E\u062C',
  14741. '\uFC1A': '\u062E\u062D',
  14742. '\uFC1B': '\u062E\u0645',
  14743. '\uFC1C': '\u0633\u062C',
  14744. '\uFC1D': '\u0633\u062D',
  14745. '\uFC1E': '\u0633\u062E',
  14746. '\uFC1F': '\u0633\u0645',
  14747. '\uFC20': '\u0635\u062D',
  14748. '\uFC21': '\u0635\u0645',
  14749. '\uFC22': '\u0636\u062C',
  14750. '\uFC23': '\u0636\u062D',
  14751. '\uFC24': '\u0636\u062E',
  14752. '\uFC25': '\u0636\u0645',
  14753. '\uFC26': '\u0637\u062D',
  14754. '\uFC27': '\u0637\u0645',
  14755. '\uFC28': '\u0638\u0645',
  14756. '\uFC29': '\u0639\u062C',
  14757. '\uFC2A': '\u0639\u0645',
  14758. '\uFC2B': '\u063A\u062C',
  14759. '\uFC2C': '\u063A\u0645',
  14760. '\uFC2D': '\u0641\u062C',
  14761. '\uFC2E': '\u0641\u062D',
  14762. '\uFC2F': '\u0641\u062E',
  14763. '\uFC30': '\u0641\u0645',
  14764. '\uFC31': '\u0641\u0649',
  14765. '\uFC32': '\u0641\u064A',
  14766. '\uFC33': '\u0642\u062D',
  14767. '\uFC34': '\u0642\u0645',
  14768. '\uFC35': '\u0642\u0649',
  14769. '\uFC36': '\u0642\u064A',
  14770. '\uFC37': '\u0643\u0627',
  14771. '\uFC38': '\u0643\u062C',
  14772. '\uFC39': '\u0643\u062D',
  14773. '\uFC3A': '\u0643\u062E',
  14774. '\uFC3B': '\u0643\u0644',
  14775. '\uFC3C': '\u0643\u0645',
  14776. '\uFC3D': '\u0643\u0649',
  14777. '\uFC3E': '\u0643\u064A',
  14778. '\uFC3F': '\u0644\u062C',
  14779. '\uFC40': '\u0644\u062D',
  14780. '\uFC41': '\u0644\u062E',
  14781. '\uFC42': '\u0644\u0645',
  14782. '\uFC43': '\u0644\u0649',
  14783. '\uFC44': '\u0644\u064A',
  14784. '\uFC45': '\u0645\u062C',
  14785. '\uFC46': '\u0645\u062D',
  14786. '\uFC47': '\u0645\u062E',
  14787. '\uFC48': '\u0645\u0645',
  14788. '\uFC49': '\u0645\u0649',
  14789. '\uFC4A': '\u0645\u064A',
  14790. '\uFC4B': '\u0646\u062C',
  14791. '\uFC4C': '\u0646\u062D',
  14792. '\uFC4D': '\u0646\u062E',
  14793. '\uFC4E': '\u0646\u0645',
  14794. '\uFC4F': '\u0646\u0649',
  14795. '\uFC50': '\u0646\u064A',
  14796. '\uFC51': '\u0647\u062C',
  14797. '\uFC52': '\u0647\u0645',
  14798. '\uFC53': '\u0647\u0649',
  14799. '\uFC54': '\u0647\u064A',
  14800. '\uFC55': '\u064A\u062C',
  14801. '\uFC56': '\u064A\u062D',
  14802. '\uFC57': '\u064A\u062E',
  14803. '\uFC58': '\u064A\u0645',
  14804. '\uFC59': '\u064A\u0649',
  14805. '\uFC5A': '\u064A\u064A',
  14806. '\uFC5B': '\u0630\u0670',
  14807. '\uFC5C': '\u0631\u0670',
  14808. '\uFC5D': '\u0649\u0670',
  14809. '\uFC5E': '\u0020\u064C\u0651',
  14810. '\uFC5F': '\u0020\u064D\u0651',
  14811. '\uFC60': '\u0020\u064E\u0651',
  14812. '\uFC61': '\u0020\u064F\u0651',
  14813. '\uFC62': '\u0020\u0650\u0651',
  14814. '\uFC63': '\u0020\u0651\u0670',
  14815. '\uFC64': '\u0626\u0631',
  14816. '\uFC65': '\u0626\u0632',
  14817. '\uFC66': '\u0626\u0645',
  14818. '\uFC67': '\u0626\u0646',
  14819. '\uFC68': '\u0626\u0649',
  14820. '\uFC69': '\u0626\u064A',
  14821. '\uFC6A': '\u0628\u0631',
  14822. '\uFC6B': '\u0628\u0632',
  14823. '\uFC6C': '\u0628\u0645',
  14824. '\uFC6D': '\u0628\u0646',
  14825. '\uFC6E': '\u0628\u0649',
  14826. '\uFC6F': '\u0628\u064A',
  14827. '\uFC70': '\u062A\u0631',
  14828. '\uFC71': '\u062A\u0632',
  14829. '\uFC72': '\u062A\u0645',
  14830. '\uFC73': '\u062A\u0646',
  14831. '\uFC74': '\u062A\u0649',
  14832. '\uFC75': '\u062A\u064A',
  14833. '\uFC76': '\u062B\u0631',
  14834. '\uFC77': '\u062B\u0632',
  14835. '\uFC78': '\u062B\u0645',
  14836. '\uFC79': '\u062B\u0646',
  14837. '\uFC7A': '\u062B\u0649',
  14838. '\uFC7B': '\u062B\u064A',
  14839. '\uFC7C': '\u0641\u0649',
  14840. '\uFC7D': '\u0641\u064A',
  14841. '\uFC7E': '\u0642\u0649',
  14842. '\uFC7F': '\u0642\u064A',
  14843. '\uFC80': '\u0643\u0627',
  14844. '\uFC81': '\u0643\u0644',
  14845. '\uFC82': '\u0643\u0645',
  14846. '\uFC83': '\u0643\u0649',
  14847. '\uFC84': '\u0643\u064A',
  14848. '\uFC85': '\u0644\u0645',
  14849. '\uFC86': '\u0644\u0649',
  14850. '\uFC87': '\u0644\u064A',
  14851. '\uFC88': '\u0645\u0627',
  14852. '\uFC89': '\u0645\u0645',
  14853. '\uFC8A': '\u0646\u0631',
  14854. '\uFC8B': '\u0646\u0632',
  14855. '\uFC8C': '\u0646\u0645',
  14856. '\uFC8D': '\u0646\u0646',
  14857. '\uFC8E': '\u0646\u0649',
  14858. '\uFC8F': '\u0646\u064A',
  14859. '\uFC90': '\u0649\u0670',
  14860. '\uFC91': '\u064A\u0631',
  14861. '\uFC92': '\u064A\u0632',
  14862. '\uFC93': '\u064A\u0645',
  14863. '\uFC94': '\u064A\u0646',
  14864. '\uFC95': '\u064A\u0649',
  14865. '\uFC96': '\u064A\u064A',
  14866. '\uFC97': '\u0626\u062C',
  14867. '\uFC98': '\u0626\u062D',
  14868. '\uFC99': '\u0626\u062E',
  14869. '\uFC9A': '\u0626\u0645',
  14870. '\uFC9B': '\u0626\u0647',
  14871. '\uFC9C': '\u0628\u062C',
  14872. '\uFC9D': '\u0628\u062D',
  14873. '\uFC9E': '\u0628\u062E',
  14874. '\uFC9F': '\u0628\u0645',
  14875. '\uFCA0': '\u0628\u0647',
  14876. '\uFCA1': '\u062A\u062C',
  14877. '\uFCA2': '\u062A\u062D',
  14878. '\uFCA3': '\u062A\u062E',
  14879. '\uFCA4': '\u062A\u0645',
  14880. '\uFCA5': '\u062A\u0647',
  14881. '\uFCA6': '\u062B\u0645',
  14882. '\uFCA7': '\u062C\u062D',
  14883. '\uFCA8': '\u062C\u0645',
  14884. '\uFCA9': '\u062D\u062C',
  14885. '\uFCAA': '\u062D\u0645',
  14886. '\uFCAB': '\u062E\u062C',
  14887. '\uFCAC': '\u062E\u0645',
  14888. '\uFCAD': '\u0633\u062C',
  14889. '\uFCAE': '\u0633\u062D',
  14890. '\uFCAF': '\u0633\u062E',
  14891. '\uFCB0': '\u0633\u0645',
  14892. '\uFCB1': '\u0635\u062D',
  14893. '\uFCB2': '\u0635\u062E',
  14894. '\uFCB3': '\u0635\u0645',
  14895. '\uFCB4': '\u0636\u062C',
  14896. '\uFCB5': '\u0636\u062D',
  14897. '\uFCB6': '\u0636\u062E',
  14898. '\uFCB7': '\u0636\u0645',
  14899. '\uFCB8': '\u0637\u062D',
  14900. '\uFCB9': '\u0638\u0645',
  14901. '\uFCBA': '\u0639\u062C',
  14902. '\uFCBB': '\u0639\u0645',
  14903. '\uFCBC': '\u063A\u062C',
  14904. '\uFCBD': '\u063A\u0645',
  14905. '\uFCBE': '\u0641\u062C',
  14906. '\uFCBF': '\u0641\u062D',
  14907. '\uFCC0': '\u0641\u062E',
  14908. '\uFCC1': '\u0641\u0645',
  14909. '\uFCC2': '\u0642\u062D',
  14910. '\uFCC3': '\u0642\u0645',
  14911. '\uFCC4': '\u0643\u062C',
  14912. '\uFCC5': '\u0643\u062D',
  14913. '\uFCC6': '\u0643\u062E',
  14914. '\uFCC7': '\u0643\u0644',
  14915. '\uFCC8': '\u0643\u0645',
  14916. '\uFCC9': '\u0644\u062C',
  14917. '\uFCCA': '\u0644\u062D',
  14918. '\uFCCB': '\u0644\u062E',
  14919. '\uFCCC': '\u0644\u0645',
  14920. '\uFCCD': '\u0644\u0647',
  14921. '\uFCCE': '\u0645\u062C',
  14922. '\uFCCF': '\u0645\u062D',
  14923. '\uFCD0': '\u0645\u062E',
  14924. '\uFCD1': '\u0645\u0645',
  14925. '\uFCD2': '\u0646\u062C',
  14926. '\uFCD3': '\u0646\u062D',
  14927. '\uFCD4': '\u0646\u062E',
  14928. '\uFCD5': '\u0646\u0645',
  14929. '\uFCD6': '\u0646\u0647',
  14930. '\uFCD7': '\u0647\u062C',
  14931. '\uFCD8': '\u0647\u0645',
  14932. '\uFCD9': '\u0647\u0670',
  14933. '\uFCDA': '\u064A\u062C',
  14934. '\uFCDB': '\u064A\u062D',
  14935. '\uFCDC': '\u064A\u062E',
  14936. '\uFCDD': '\u064A\u0645',
  14937. '\uFCDE': '\u064A\u0647',
  14938. '\uFCDF': '\u0626\u0645',
  14939. '\uFCE0': '\u0626\u0647',
  14940. '\uFCE1': '\u0628\u0645',
  14941. '\uFCE2': '\u0628\u0647',
  14942. '\uFCE3': '\u062A\u0645',
  14943. '\uFCE4': '\u062A\u0647',
  14944. '\uFCE5': '\u062B\u0645',
  14945. '\uFCE6': '\u062B\u0647',
  14946. '\uFCE7': '\u0633\u0645',
  14947. '\uFCE8': '\u0633\u0647',
  14948. '\uFCE9': '\u0634\u0645',
  14949. '\uFCEA': '\u0634\u0647',
  14950. '\uFCEB': '\u0643\u0644',
  14951. '\uFCEC': '\u0643\u0645',
  14952. '\uFCED': '\u0644\u0645',
  14953. '\uFCEE': '\u0646\u0645',
  14954. '\uFCEF': '\u0646\u0647',
  14955. '\uFCF0': '\u064A\u0645',
  14956. '\uFCF1': '\u064A\u0647',
  14957. '\uFCF2': '\u0640\u064E\u0651',
  14958. '\uFCF3': '\u0640\u064F\u0651',
  14959. '\uFCF4': '\u0640\u0650\u0651',
  14960. '\uFCF5': '\u0637\u0649',
  14961. '\uFCF6': '\u0637\u064A',
  14962. '\uFCF7': '\u0639\u0649',
  14963. '\uFCF8': '\u0639\u064A',
  14964. '\uFCF9': '\u063A\u0649',
  14965. '\uFCFA': '\u063A\u064A',
  14966. '\uFCFB': '\u0633\u0649',
  14967. '\uFCFC': '\u0633\u064A',
  14968. '\uFCFD': '\u0634\u0649',
  14969. '\uFCFE': '\u0634\u064A',
  14970. '\uFCFF': '\u062D\u0649',
  14971. '\uFD00': '\u062D\u064A',
  14972. '\uFD01': '\u062C\u0649',
  14973. '\uFD02': '\u062C\u064A',
  14974. '\uFD03': '\u062E\u0649',
  14975. '\uFD04': '\u062E\u064A',
  14976. '\uFD05': '\u0635\u0649',
  14977. '\uFD06': '\u0635\u064A',
  14978. '\uFD07': '\u0636\u0649',
  14979. '\uFD08': '\u0636\u064A',
  14980. '\uFD09': '\u0634\u062C',
  14981. '\uFD0A': '\u0634\u062D',
  14982. '\uFD0B': '\u0634\u062E',
  14983. '\uFD0C': '\u0634\u0645',
  14984. '\uFD0D': '\u0634\u0631',
  14985. '\uFD0E': '\u0633\u0631',
  14986. '\uFD0F': '\u0635\u0631',
  14987. '\uFD10': '\u0636\u0631',
  14988. '\uFD11': '\u0637\u0649',
  14989. '\uFD12': '\u0637\u064A',
  14990. '\uFD13': '\u0639\u0649',
  14991. '\uFD14': '\u0639\u064A',
  14992. '\uFD15': '\u063A\u0649',
  14993. '\uFD16': '\u063A\u064A',
  14994. '\uFD17': '\u0633\u0649',
  14995. '\uFD18': '\u0633\u064A',
  14996. '\uFD19': '\u0634\u0649',
  14997. '\uFD1A': '\u0634\u064A',
  14998. '\uFD1B': '\u062D\u0649',
  14999. '\uFD1C': '\u062D\u064A',
  15000. '\uFD1D': '\u062C\u0649',
  15001. '\uFD1E': '\u062C\u064A',
  15002. '\uFD1F': '\u062E\u0649',
  15003. '\uFD20': '\u062E\u064A',
  15004. '\uFD21': '\u0635\u0649',
  15005. '\uFD22': '\u0635\u064A',
  15006. '\uFD23': '\u0636\u0649',
  15007. '\uFD24': '\u0636\u064A',
  15008. '\uFD25': '\u0634\u062C',
  15009. '\uFD26': '\u0634\u062D',
  15010. '\uFD27': '\u0634\u062E',
  15011. '\uFD28': '\u0634\u0645',
  15012. '\uFD29': '\u0634\u0631',
  15013. '\uFD2A': '\u0633\u0631',
  15014. '\uFD2B': '\u0635\u0631',
  15015. '\uFD2C': '\u0636\u0631',
  15016. '\uFD2D': '\u0634\u062C',
  15017. '\uFD2E': '\u0634\u062D',
  15018. '\uFD2F': '\u0634\u062E',
  15019. '\uFD30': '\u0634\u0645',
  15020. '\uFD31': '\u0633\u0647',
  15021. '\uFD32': '\u0634\u0647',
  15022. '\uFD33': '\u0637\u0645',
  15023. '\uFD34': '\u0633\u062C',
  15024. '\uFD35': '\u0633\u062D',
  15025. '\uFD36': '\u0633\u062E',
  15026. '\uFD37': '\u0634\u062C',
  15027. '\uFD38': '\u0634\u062D',
  15028. '\uFD39': '\u0634\u062E',
  15029. '\uFD3A': '\u0637\u0645',
  15030. '\uFD3B': '\u0638\u0645',
  15031. '\uFD3C': '\u0627\u064B',
  15032. '\uFD3D': '\u0627\u064B',
  15033. '\uFD50': '\u062A\u062C\u0645',
  15034. '\uFD51': '\u062A\u062D\u062C',
  15035. '\uFD52': '\u062A\u062D\u062C',
  15036. '\uFD53': '\u062A\u062D\u0645',
  15037. '\uFD54': '\u062A\u062E\u0645',
  15038. '\uFD55': '\u062A\u0645\u062C',
  15039. '\uFD56': '\u062A\u0645\u062D',
  15040. '\uFD57': '\u062A\u0645\u062E',
  15041. '\uFD58': '\u062C\u0645\u062D',
  15042. '\uFD59': '\u062C\u0645\u062D',
  15043. '\uFD5A': '\u062D\u0645\u064A',
  15044. '\uFD5B': '\u062D\u0645\u0649',
  15045. '\uFD5C': '\u0633\u062D\u062C',
  15046. '\uFD5D': '\u0633\u062C\u062D',
  15047. '\uFD5E': '\u0633\u062C\u0649',
  15048. '\uFD5F': '\u0633\u0645\u062D',
  15049. '\uFD60': '\u0633\u0645\u062D',
  15050. '\uFD61': '\u0633\u0645\u062C',
  15051. '\uFD62': '\u0633\u0645\u0645',
  15052. '\uFD63': '\u0633\u0645\u0645',
  15053. '\uFD64': '\u0635\u062D\u062D',
  15054. '\uFD65': '\u0635\u062D\u062D',
  15055. '\uFD66': '\u0635\u0645\u0645',
  15056. '\uFD67': '\u0634\u062D\u0645',
  15057. '\uFD68': '\u0634\u062D\u0645',
  15058. '\uFD69': '\u0634\u062C\u064A',
  15059. '\uFD6A': '\u0634\u0645\u062E',
  15060. '\uFD6B': '\u0634\u0645\u062E',
  15061. '\uFD6C': '\u0634\u0645\u0645',
  15062. '\uFD6D': '\u0634\u0645\u0645',
  15063. '\uFD6E': '\u0636\u062D\u0649',
  15064. '\uFD6F': '\u0636\u062E\u0645',
  15065. '\uFD70': '\u0636\u062E\u0645',
  15066. '\uFD71': '\u0637\u0645\u062D',
  15067. '\uFD72': '\u0637\u0645\u062D',
  15068. '\uFD73': '\u0637\u0645\u0645',
  15069. '\uFD74': '\u0637\u0645\u064A',
  15070. '\uFD75': '\u0639\u062C\u0645',
  15071. '\uFD76': '\u0639\u0645\u0645',
  15072. '\uFD77': '\u0639\u0645\u0645',
  15073. '\uFD78': '\u0639\u0645\u0649',
  15074. '\uFD79': '\u063A\u0645\u0645',
  15075. '\uFD7A': '\u063A\u0645\u064A',
  15076. '\uFD7B': '\u063A\u0645\u0649',
  15077. '\uFD7C': '\u0641\u062E\u0645',
  15078. '\uFD7D': '\u0641\u062E\u0645',
  15079. '\uFD7E': '\u0642\u0645\u062D',
  15080. '\uFD7F': '\u0642\u0645\u0645',
  15081. '\uFD80': '\u0644\u062D\u0645',
  15082. '\uFD81': '\u0644\u062D\u064A',
  15083. '\uFD82': '\u0644\u062D\u0649',
  15084. '\uFD83': '\u0644\u062C\u062C',
  15085. '\uFD84': '\u0644\u062C\u062C',
  15086. '\uFD85': '\u0644\u062E\u0645',
  15087. '\uFD86': '\u0644\u062E\u0645',
  15088. '\uFD87': '\u0644\u0645\u062D',
  15089. '\uFD88': '\u0644\u0645\u062D',
  15090. '\uFD89': '\u0645\u062D\u062C',
  15091. '\uFD8A': '\u0645\u062D\u0645',
  15092. '\uFD8B': '\u0645\u062D\u064A',
  15093. '\uFD8C': '\u0645\u062C\u062D',
  15094. '\uFD8D': '\u0645\u062C\u0645',
  15095. '\uFD8E': '\u0645\u062E\u062C',
  15096. '\uFD8F': '\u0645\u062E\u0645',
  15097. '\uFD92': '\u0645\u062C\u062E',
  15098. '\uFD93': '\u0647\u0645\u062C',
  15099. '\uFD94': '\u0647\u0645\u0645',
  15100. '\uFD95': '\u0646\u062D\u0645',
  15101. '\uFD96': '\u0646\u062D\u0649',
  15102. '\uFD97': '\u0646\u062C\u0645',
  15103. '\uFD98': '\u0646\u062C\u0645',
  15104. '\uFD99': '\u0646\u062C\u0649',
  15105. '\uFD9A': '\u0646\u0645\u064A',
  15106. '\uFD9B': '\u0646\u0645\u0649',
  15107. '\uFD9C': '\u064A\u0645\u0645',
  15108. '\uFD9D': '\u064A\u0645\u0645',
  15109. '\uFD9E': '\u0628\u062E\u064A',
  15110. '\uFD9F': '\u062A\u062C\u064A',
  15111. '\uFDA0': '\u062A\u062C\u0649',
  15112. '\uFDA1': '\u062A\u062E\u064A',
  15113. '\uFDA2': '\u062A\u062E\u0649',
  15114. '\uFDA3': '\u062A\u0645\u064A',
  15115. '\uFDA4': '\u062A\u0645\u0649',
  15116. '\uFDA5': '\u062C\u0645\u064A',
  15117. '\uFDA6': '\u062C\u062D\u0649',
  15118. '\uFDA7': '\u062C\u0645\u0649',
  15119. '\uFDA8': '\u0633\u062E\u0649',
  15120. '\uFDA9': '\u0635\u062D\u064A',
  15121. '\uFDAA': '\u0634\u062D\u064A',
  15122. '\uFDAB': '\u0636\u062D\u064A',
  15123. '\uFDAC': '\u0644\u062C\u064A',
  15124. '\uFDAD': '\u0644\u0645\u064A',
  15125. '\uFDAE': '\u064A\u062D\u064A',
  15126. '\uFDAF': '\u064A\u062C\u064A',
  15127. '\uFDB0': '\u064A\u0645\u064A',
  15128. '\uFDB1': '\u0645\u0645\u064A',
  15129. '\uFDB2': '\u0642\u0645\u064A',
  15130. '\uFDB3': '\u0646\u062D\u064A',
  15131. '\uFDB4': '\u0642\u0645\u062D',
  15132. '\uFDB5': '\u0644\u062D\u0645',
  15133. '\uFDB6': '\u0639\u0645\u064A',
  15134. '\uFDB7': '\u0643\u0645\u064A',
  15135. '\uFDB8': '\u0646\u062C\u062D',
  15136. '\uFDB9': '\u0645\u062E\u064A',
  15137. '\uFDBA': '\u0644\u062C\u0645',
  15138. '\uFDBB': '\u0643\u0645\u0645',
  15139. '\uFDBC': '\u0644\u062C\u0645',
  15140. '\uFDBD': '\u0646\u062C\u062D',
  15141. '\uFDBE': '\u062C\u062D\u064A',
  15142. '\uFDBF': '\u062D\u062C\u064A',
  15143. '\uFDC0': '\u0645\u062C\u064A',
  15144. '\uFDC1': '\u0641\u0645\u064A',
  15145. '\uFDC2': '\u0628\u062D\u064A',
  15146. '\uFDC3': '\u0643\u0645\u0645',
  15147. '\uFDC4': '\u0639\u062C\u0645',
  15148. '\uFDC5': '\u0635\u0645\u0645',
  15149. '\uFDC6': '\u0633\u062E\u064A',
  15150. '\uFDC7': '\u0646\u062C\u064A',
  15151. '\uFE49': '\u203E',
  15152. '\uFE4A': '\u203E',
  15153. '\uFE4B': '\u203E',
  15154. '\uFE4C': '\u203E',
  15155. '\uFE4D': '\u005F',
  15156. '\uFE4E': '\u005F',
  15157. '\uFE4F': '\u005F',
  15158. '\uFE80': '\u0621',
  15159. '\uFE81': '\u0622',
  15160. '\uFE82': '\u0622',
  15161. '\uFE83': '\u0623',
  15162. '\uFE84': '\u0623',
  15163. '\uFE85': '\u0624',
  15164. '\uFE86': '\u0624',
  15165. '\uFE87': '\u0625',
  15166. '\uFE88': '\u0625',
  15167. '\uFE89': '\u0626',
  15168. '\uFE8A': '\u0626',
  15169. '\uFE8B': '\u0626',
  15170. '\uFE8C': '\u0626',
  15171. '\uFE8D': '\u0627',
  15172. '\uFE8E': '\u0627',
  15173. '\uFE8F': '\u0628',
  15174. '\uFE90': '\u0628',
  15175. '\uFE91': '\u0628',
  15176. '\uFE92': '\u0628',
  15177. '\uFE93': '\u0629',
  15178. '\uFE94': '\u0629',
  15179. '\uFE95': '\u062A',
  15180. '\uFE96': '\u062A',
  15181. '\uFE97': '\u062A',
  15182. '\uFE98': '\u062A',
  15183. '\uFE99': '\u062B',
  15184. '\uFE9A': '\u062B',
  15185. '\uFE9B': '\u062B',
  15186. '\uFE9C': '\u062B',
  15187. '\uFE9D': '\u062C',
  15188. '\uFE9E': '\u062C',
  15189. '\uFE9F': '\u062C',
  15190. '\uFEA0': '\u062C',
  15191. '\uFEA1': '\u062D',
  15192. '\uFEA2': '\u062D',
  15193. '\uFEA3': '\u062D',
  15194. '\uFEA4': '\u062D',
  15195. '\uFEA5': '\u062E',
  15196. '\uFEA6': '\u062E',
  15197. '\uFEA7': '\u062E',
  15198. '\uFEA8': '\u062E',
  15199. '\uFEA9': '\u062F',
  15200. '\uFEAA': '\u062F',
  15201. '\uFEAB': '\u0630',
  15202. '\uFEAC': '\u0630',
  15203. '\uFEAD': '\u0631',
  15204. '\uFEAE': '\u0631',
  15205. '\uFEAF': '\u0632',
  15206. '\uFEB0': '\u0632',
  15207. '\uFEB1': '\u0633',
  15208. '\uFEB2': '\u0633',
  15209. '\uFEB3': '\u0633',
  15210. '\uFEB4': '\u0633',
  15211. '\uFEB5': '\u0634',
  15212. '\uFEB6': '\u0634',
  15213. '\uFEB7': '\u0634',
  15214. '\uFEB8': '\u0634',
  15215. '\uFEB9': '\u0635',
  15216. '\uFEBA': '\u0635',
  15217. '\uFEBB': '\u0635',
  15218. '\uFEBC': '\u0635',
  15219. '\uFEBD': '\u0636',
  15220. '\uFEBE': '\u0636',
  15221. '\uFEBF': '\u0636',
  15222. '\uFEC0': '\u0636',
  15223. '\uFEC1': '\u0637',
  15224. '\uFEC2': '\u0637',
  15225. '\uFEC3': '\u0637',
  15226. '\uFEC4': '\u0637',
  15227. '\uFEC5': '\u0638',
  15228. '\uFEC6': '\u0638',
  15229. '\uFEC7': '\u0638',
  15230. '\uFEC8': '\u0638',
  15231. '\uFEC9': '\u0639',
  15232. '\uFECA': '\u0639',
  15233. '\uFECB': '\u0639',
  15234. '\uFECC': '\u0639',
  15235. '\uFECD': '\u063A',
  15236. '\uFECE': '\u063A',
  15237. '\uFECF': '\u063A',
  15238. '\uFED0': '\u063A',
  15239. '\uFED1': '\u0641',
  15240. '\uFED2': '\u0641',
  15241. '\uFED3': '\u0641',
  15242. '\uFED4': '\u0641',
  15243. '\uFED5': '\u0642',
  15244. '\uFED6': '\u0642',
  15245. '\uFED7': '\u0642',
  15246. '\uFED8': '\u0642',
  15247. '\uFED9': '\u0643',
  15248. '\uFEDA': '\u0643',
  15249. '\uFEDB': '\u0643',
  15250. '\uFEDC': '\u0643',
  15251. '\uFEDD': '\u0644',
  15252. '\uFEDE': '\u0644',
  15253. '\uFEDF': '\u0644',
  15254. '\uFEE0': '\u0644',
  15255. '\uFEE1': '\u0645',
  15256. '\uFEE2': '\u0645',
  15257. '\uFEE3': '\u0645',
  15258. '\uFEE4': '\u0645',
  15259. '\uFEE5': '\u0646',
  15260. '\uFEE6': '\u0646',
  15261. '\uFEE7': '\u0646',
  15262. '\uFEE8': '\u0646',
  15263. '\uFEE9': '\u0647',
  15264. '\uFEEA': '\u0647',
  15265. '\uFEEB': '\u0647',
  15266. '\uFEEC': '\u0647',
  15267. '\uFEED': '\u0648',
  15268. '\uFEEE': '\u0648',
  15269. '\uFEEF': '\u0649',
  15270. '\uFEF0': '\u0649',
  15271. '\uFEF1': '\u064A',
  15272. '\uFEF2': '\u064A',
  15273. '\uFEF3': '\u064A',
  15274. '\uFEF4': '\u064A',
  15275. '\uFEF5': '\u0644\u0622',
  15276. '\uFEF6': '\u0644\u0622',
  15277. '\uFEF7': '\u0644\u0623',
  15278. '\uFEF8': '\u0644\u0623',
  15279. '\uFEF9': '\u0644\u0625',
  15280. '\uFEFA': '\u0644\u0625',
  15281. '\uFEFB': '\u0644\u0627',
  15282. '\uFEFC': '\u0644\u0627'
  15283. };
  15284. function reverseIfRtl(chars) {
  15285. var charsLength = chars.length;
  15286. //reverse an arabic ligature
  15287. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  15288. return chars;
  15289. }
  15290. var s = '';
  15291. for (var ii = charsLength - 1; ii >= 0; ii--) {
  15292. s += chars[ii];
  15293. }
  15294. return s;
  15295. }
  15296. function adjustWidths(properties) {
  15297. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  15298. return;
  15299. }
  15300. // adjusting width to fontMatrix scale
  15301. var scale = 0.001 / properties.fontMatrix[0];
  15302. var glyphsWidths = properties.widths;
  15303. for (var glyph in glyphsWidths) {
  15304. glyphsWidths[glyph] *= scale;
  15305. }
  15306. properties.defaultWidth *= scale;
  15307. }
  15308. function getFontType(type, subtype) {
  15309. switch (type) {
  15310. case 'Type1':
  15311. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  15312. case 'CIDFontType0':
  15313. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  15314. FontType.CIDFONTTYPE0;
  15315. case 'OpenType':
  15316. return FontType.OPENTYPE;
  15317. case 'TrueType':
  15318. return FontType.TRUETYPE;
  15319. case 'CIDFontType2':
  15320. return FontType.CIDFONTTYPE2;
  15321. case 'MMType1':
  15322. return FontType.MMTYPE1;
  15323. case 'Type0':
  15324. return FontType.TYPE0;
  15325. default:
  15326. return FontType.UNKNOWN;
  15327. }
  15328. }
  15329. var Glyph = (function GlyphClosure() {
  15330. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15331. this.fontChar = fontChar;
  15332. this.unicode = unicode;
  15333. this.accent = accent;
  15334. this.width = width;
  15335. this.vmetric = vmetric;
  15336. this.operatorListId = operatorListId;
  15337. }
  15338. Glyph.prototype.matchesForCache =
  15339. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15340. return this.fontChar === fontChar &&
  15341. this.unicode === unicode &&
  15342. this.accent === accent &&
  15343. this.width === width &&
  15344. this.vmetric === vmetric &&
  15345. this.operatorListId === operatorListId;
  15346. };
  15347. return Glyph;
  15348. })();
  15349. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  15350. function ToUnicodeMap(cmap) {
  15351. // The elements of this._map can be integers or strings, depending on how
  15352. // |cmap| was created.
  15353. this._map = cmap;
  15354. }
  15355. ToUnicodeMap.prototype = {
  15356. get length() {
  15357. return this._map.length;
  15358. },
  15359. forEach: function(callback) {
  15360. for (var charCode in this._map) {
  15361. callback(charCode, this._map[charCode].charCodeAt(0));
  15362. }
  15363. },
  15364. has: function(i) {
  15365. return this._map[i] !== undefined;
  15366. },
  15367. get: function(i) {
  15368. return this._map[i];
  15369. },
  15370. charCodeOf: function(v) {
  15371. return this._map.indexOf(v);
  15372. }
  15373. };
  15374. return ToUnicodeMap;
  15375. })();
  15376. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15377. function IdentityToUnicodeMap(firstChar, lastChar) {
  15378. this.firstChar = firstChar;
  15379. this.lastChar = lastChar;
  15380. }
  15381. IdentityToUnicodeMap.prototype = {
  15382. get length() {
  15383. return (this.lastChar + 1) - this.firstChar;
  15384. },
  15385. forEach: function (callback) {
  15386. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15387. callback(i, i);
  15388. }
  15389. },
  15390. has: function (i) {
  15391. return this.firstChar <= i && i <= this.lastChar;
  15392. },
  15393. get: function (i) {
  15394. if (this.firstChar <= i && i <= this.lastChar) {
  15395. return String.fromCharCode(i);
  15396. }
  15397. return undefined;
  15398. },
  15399. charCodeOf: function (v) {
  15400. error('should not call .charCodeOf');
  15401. }
  15402. };
  15403. return IdentityToUnicodeMap;
  15404. })();
  15405. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15406. function writeInt16(dest, offset, num) {
  15407. dest[offset] = (num >> 8) & 0xFF;
  15408. dest[offset + 1] = num & 0xFF;
  15409. }
  15410. function writeInt32(dest, offset, num) {
  15411. dest[offset] = (num >> 24) & 0xFF;
  15412. dest[offset + 1] = (num >> 16) & 0xFF;
  15413. dest[offset + 2] = (num >> 8) & 0xFF;
  15414. dest[offset + 3] = num & 0xFF;
  15415. }
  15416. function writeData(dest, offset, data) {
  15417. var i, ii;
  15418. if (data instanceof Uint8Array) {
  15419. dest.set(data, offset);
  15420. } else if (typeof data === 'string') {
  15421. for (i = 0, ii = data.length; i < ii; i++) {
  15422. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15423. }
  15424. } else {
  15425. // treating everything else as array
  15426. for (i = 0, ii = data.length; i < ii; i++) {
  15427. dest[offset++] = data[i] & 0xFF;
  15428. }
  15429. }
  15430. }
  15431. function OpenTypeFileBuilder(sfnt) {
  15432. this.sfnt = sfnt;
  15433. this.tables = Object.create(null);
  15434. }
  15435. OpenTypeFileBuilder.getSearchParams =
  15436. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15437. var maxPower2 = 1, log2 = 0;
  15438. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15439. maxPower2 <<= 1;
  15440. log2++;
  15441. }
  15442. var searchRange = maxPower2 * entrySize;
  15443. return {
  15444. range: searchRange,
  15445. entry: log2,
  15446. rangeShift: entrySize * entriesCount - searchRange
  15447. };
  15448. };
  15449. var OTF_HEADER_SIZE = 12;
  15450. var OTF_TABLE_ENTRY_SIZE = 16;
  15451. OpenTypeFileBuilder.prototype = {
  15452. toArray: function OpenTypeFileBuilder_toArray() {
  15453. var sfnt = this.sfnt;
  15454. // Tables needs to be written by ascendant alphabetic order
  15455. var tables = this.tables;
  15456. var tablesNames = Object.keys(tables);
  15457. tablesNames.sort();
  15458. var numTables = tablesNames.length;
  15459. var i, j, jj, table, tableName;
  15460. // layout the tables data
  15461. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15462. var tableOffsets = [offset];
  15463. for (i = 0; i < numTables; i++) {
  15464. table = tables[tablesNames[i]];
  15465. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15466. offset += paddedLength;
  15467. tableOffsets.push(offset);
  15468. }
  15469. var file = new Uint8Array(offset);
  15470. // write the table data first (mostly for checksum)
  15471. for (i = 0; i < numTables; i++) {
  15472. table = tables[tablesNames[i]];
  15473. writeData(file, tableOffsets[i], table);
  15474. }
  15475. // sfnt version (4 bytes)
  15476. if (sfnt === 'true') {
  15477. // Windows hates the Mac TrueType sfnt version number
  15478. sfnt = string32(0x00010000);
  15479. }
  15480. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15481. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15482. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15483. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15484. // numTables (2 bytes)
  15485. writeInt16(file, 4, numTables);
  15486. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15487. // searchRange (2 bytes)
  15488. writeInt16(file, 6, searchParams.range);
  15489. // entrySelector (2 bytes)
  15490. writeInt16(file, 8, searchParams.entry);
  15491. // rangeShift (2 bytes)
  15492. writeInt16(file, 10, searchParams.rangeShift);
  15493. offset = OTF_HEADER_SIZE;
  15494. // writing table entries
  15495. for (i = 0; i < numTables; i++) {
  15496. tableName = tablesNames[i];
  15497. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15498. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15499. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15500. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15501. // checksum
  15502. var checksum = 0;
  15503. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15504. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15505. (file[j + 2] << 8) + file[j + 3];
  15506. checksum = (checksum + quad) | 0;
  15507. }
  15508. writeInt32(file, offset + 4, checksum);
  15509. // offset
  15510. writeInt32(file, offset + 8, tableOffsets[i]);
  15511. // length
  15512. writeInt32(file, offset + 12, tables[tableName].length);
  15513. offset += OTF_TABLE_ENTRY_SIZE;
  15514. }
  15515. return file;
  15516. },
  15517. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15518. if (tag in this.tables) {
  15519. throw new Error('Table ' + tag + ' already exists');
  15520. }
  15521. this.tables[tag] = data;
  15522. }
  15523. };
  15524. return OpenTypeFileBuilder;
  15525. })();
  15526. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  15527. // issues when they are painted on the canvas, e.g. complex-script shaping or
  15528. // control/whitespace characters. The ranges are listed in pairs: the first item
  15529. // is a code of the first problematic code, the second one is the next
  15530. // non-problematic code. The ranges must be in sorted order.
  15531. var ProblematicCharRanges = new Int32Array([
  15532. // Control characters.
  15533. 0x0000, 0x0020,
  15534. 0x007F, 0x00A1,
  15535. 0x00AD, 0x00AE,
  15536. // Chars that is used in complex-script shaping.
  15537. 0x0600, 0x0780,
  15538. 0x08A0, 0x10A0,
  15539. 0x1780, 0x1800,
  15540. // General punctuation chars.
  15541. 0x2000, 0x2010,
  15542. 0x2011, 0x2012,
  15543. 0x2028, 0x2030,
  15544. 0x205F, 0x2070,
  15545. 0x25CC, 0x25CD,
  15546. // Chars that is used in complex-script shaping.
  15547. 0xAA60, 0xAA80,
  15548. // Specials Unicode block.
  15549. 0xFFF0, 0x10000
  15550. ]);
  15551. /**
  15552. * 'Font' is the class the outside world should use, it encapsulate all the font
  15553. * decoding logics whatever type it is (assuming the font type is supported).
  15554. *
  15555. * For example to read a Type1 font and to attach it to the document:
  15556. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15557. * type1Font.bind();
  15558. */
  15559. var Font = (function FontClosure() {
  15560. function Font(name, file, properties) {
  15561. var charCode, glyphName, fontChar;
  15562. this.name = name;
  15563. this.loadedName = properties.loadedName;
  15564. this.isType3Font = properties.isType3Font;
  15565. this.sizes = [];
  15566. this.glyphCache = {};
  15567. var names = name.split('+');
  15568. names = names.length > 1 ? names[1] : names[0];
  15569. names = names.split(/[-,_]/g)[0];
  15570. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15571. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15572. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15573. var type = properties.type;
  15574. var subtype = properties.subtype;
  15575. this.type = type;
  15576. this.fallbackName = (this.isMonospace ? 'monospace' :
  15577. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15578. this.differences = properties.differences;
  15579. this.widths = properties.widths;
  15580. this.defaultWidth = properties.defaultWidth;
  15581. this.composite = properties.composite;
  15582. this.wideChars = properties.wideChars;
  15583. this.cMap = properties.cMap;
  15584. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15585. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15586. this.fontMatrix = properties.fontMatrix;
  15587. this.bbox = properties.bbox;
  15588. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15589. this.toFontChar = [];
  15590. if (properties.type === 'Type3') {
  15591. for (charCode = 0; charCode < 256; charCode++) {
  15592. this.toFontChar[charCode] = (this.differences[charCode] ||
  15593. properties.defaultEncoding[charCode]);
  15594. }
  15595. this.fontType = FontType.TYPE3;
  15596. return;
  15597. }
  15598. this.cidEncoding = properties.cidEncoding;
  15599. this.vertical = properties.vertical;
  15600. if (this.vertical) {
  15601. this.vmetrics = properties.vmetrics;
  15602. this.defaultVMetrics = properties.defaultVMetrics;
  15603. }
  15604. if (!file || file.isEmpty) {
  15605. if (file) {
  15606. // Some bad PDF generators will include empty font files,
  15607. // attempting to recover by assuming that no file exists.
  15608. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15609. }
  15610. this.missingFile = true;
  15611. // The file data is not specified. Trying to fix the font name
  15612. // to be used with the canvas.font.
  15613. var fontName = name.replace(/[,_]/g, '-');
  15614. var isStandardFont = !!stdFontMap[fontName] ||
  15615. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15616. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15617. this.bold = (fontName.search(/bold/gi) !== -1);
  15618. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15619. (fontName.search(/italic/gi) !== -1));
  15620. // Use 'name' instead of 'fontName' here because the original
  15621. // name ArialBlack for example will be replaced by Helvetica.
  15622. this.black = (name.search(/Black/g) !== -1);
  15623. // if at least one width is present, remeasure all chars when exists
  15624. this.remeasure = Object.keys(this.widths).length > 0;
  15625. if (isStandardFont && type === 'CIDFontType2' &&
  15626. properties.cidEncoding.indexOf('Identity-') === 0) {
  15627. // Standard fonts might be embedded as CID font without glyph mapping.
  15628. // Building one based on GlyphMapForStandardFonts.
  15629. var map = [];
  15630. for (charCode in GlyphMapForStandardFonts) {
  15631. map[+charCode] = GlyphMapForStandardFonts[charCode];
  15632. }
  15633. if (/ArialBlack/i.test(name)) {
  15634. for (charCode in SupplementalGlyphMapForArialBlack) {
  15635. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  15636. }
  15637. }
  15638. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15639. if (!isIdentityUnicode) {
  15640. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15641. map[+charCode] = unicodeCharCode;
  15642. });
  15643. }
  15644. this.toFontChar = map;
  15645. this.toUnicode = new ToUnicodeMap(map);
  15646. } else if (/Symbol/i.test(fontName)) {
  15647. var symbols = Encodings.SymbolSetEncoding;
  15648. for (charCode in symbols) {
  15649. fontChar = GlyphsUnicode[symbols[charCode]];
  15650. if (!fontChar) {
  15651. continue;
  15652. }
  15653. this.toFontChar[charCode] = fontChar;
  15654. }
  15655. for (charCode in properties.differences) {
  15656. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15657. if (!fontChar) {
  15658. continue;
  15659. }
  15660. this.toFontChar[charCode] = fontChar;
  15661. }
  15662. } else if (/Dingbats/i.test(fontName)) {
  15663. if (/Wingdings/i.test(name)) {
  15664. warn('Wingdings font without embedded font file, ' +
  15665. 'falling back to the ZapfDingbats encoding.');
  15666. }
  15667. var dingbats = Encodings.ZapfDingbatsEncoding;
  15668. for (charCode in dingbats) {
  15669. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15670. if (!fontChar) {
  15671. continue;
  15672. }
  15673. this.toFontChar[charCode] = fontChar;
  15674. }
  15675. for (charCode in properties.differences) {
  15676. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15677. if (!fontChar) {
  15678. continue;
  15679. }
  15680. this.toFontChar[charCode] = fontChar;
  15681. }
  15682. } else if (isStandardFont) {
  15683. this.toFontChar = [];
  15684. for (charCode in properties.defaultEncoding) {
  15685. glyphName = (properties.differences[charCode] ||
  15686. properties.defaultEncoding[charCode]);
  15687. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15688. }
  15689. } else {
  15690. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15691. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15692. if (notCidFont) {
  15693. glyphName = (properties.differences[charCode] ||
  15694. properties.defaultEncoding[charCode]);
  15695. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15696. }
  15697. this.toFontChar[charCode] = unicodeCharCode;
  15698. }.bind(this));
  15699. }
  15700. this.loadedName = fontName.split('-')[0];
  15701. this.loading = false;
  15702. this.fontType = getFontType(type, subtype);
  15703. return;
  15704. }
  15705. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15706. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15707. // Some TrueType fonts by mistake claim Type1C
  15708. if (isTrueTypeFile(file)) {
  15709. subtype = 'TrueType';
  15710. } else {
  15711. type = 'Type1';
  15712. }
  15713. }
  15714. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15715. type = 'CIDFontType0';
  15716. }
  15717. if (subtype === 'OpenType') {
  15718. type = 'OpenType';
  15719. }
  15720. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  15721. if (type === 'CIDFontType0') {
  15722. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  15723. }
  15724. var data;
  15725. switch (type) {
  15726. case 'MMType1':
  15727. info('MMType1 font (' + name + '), falling back to Type1.');
  15728. /* falls through */
  15729. case 'Type1':
  15730. case 'CIDFontType0':
  15731. this.mimetype = 'font/opentype';
  15732. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15733. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15734. adjustWidths(properties);
  15735. // Wrap the CFF data inside an OTF font file
  15736. data = this.convert(name, cff, properties);
  15737. break;
  15738. case 'OpenType':
  15739. case 'TrueType':
  15740. case 'CIDFontType2':
  15741. this.mimetype = 'font/opentype';
  15742. // Repair the TrueType file. It is can be damaged in the point of
  15743. // view of the sanitizer
  15744. data = this.checkAndRepair(name, file, properties);
  15745. if (this.isOpenType) {
  15746. type = 'OpenType';
  15747. }
  15748. break;
  15749. default:
  15750. error('Font ' + type + ' is not supported');
  15751. break;
  15752. }
  15753. this.data = data;
  15754. this.fontType = getFontType(type, subtype);
  15755. // Transfer some properties again that could change during font conversion
  15756. this.fontMatrix = properties.fontMatrix;
  15757. this.widths = properties.widths;
  15758. this.defaultWidth = properties.defaultWidth;
  15759. this.encoding = properties.baseEncoding;
  15760. this.seacMap = properties.seacMap;
  15761. this.loading = true;
  15762. }
  15763. Font.getFontID = (function () {
  15764. var ID = 1;
  15765. return function Font_getFontID() {
  15766. return String(ID++);
  15767. };
  15768. })();
  15769. function int16(b0, b1) {
  15770. return (b0 << 8) + b1;
  15771. }
  15772. function int32(b0, b1, b2, b3) {
  15773. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15774. }
  15775. function string16(value) {
  15776. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15777. }
  15778. function safeString16(value) {
  15779. // clamp value to the 16-bit int range
  15780. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15781. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15782. }
  15783. function isTrueTypeFile(file) {
  15784. var header = file.peekBytes(4);
  15785. return readUint32(header, 0) === 0x00010000;
  15786. }
  15787. function isType1File(file) {
  15788. var header = file.peekBytes(2);
  15789. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  15790. if (header[0] === 0x25 && header[1] === 0x21) {
  15791. return true;
  15792. }
  15793. // ... obviously some fonts violate that part of the specification,
  15794. // please refer to the comment in |Type1Font| below.
  15795. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  15796. return true;
  15797. }
  15798. return false;
  15799. }
  15800. /**
  15801. * Helper function for |adjustMapping|.
  15802. * @return {boolean}
  15803. */
  15804. function isProblematicUnicodeLocation(code) {
  15805. // Using binary search to find a range start.
  15806. var i = 0, j = ProblematicCharRanges.length - 1;
  15807. while (i < j) {
  15808. var c = (i + j + 1) >> 1;
  15809. if (code < ProblematicCharRanges[c]) {
  15810. j = c - 1;
  15811. } else {
  15812. i = c;
  15813. }
  15814. }
  15815. // Even index means code in problematic range.
  15816. return !(i & 1);
  15817. }
  15818. /**
  15819. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15820. * with their unicode value. It also moves char codes that are in known
  15821. * problematic locations.
  15822. * @return {Object} Two properties:
  15823. * 'toFontChar' - maps original char codes(the value that will be read
  15824. * from commands such as show text) to the char codes that will be used in the
  15825. * font that we build
  15826. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15827. */
  15828. function adjustMapping(charCodeToGlyphId, properties) {
  15829. var toUnicode = properties.toUnicode;
  15830. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15831. var isIdentityUnicode =
  15832. properties.toUnicode instanceof IdentityToUnicodeMap;
  15833. var newMap = Object.create(null);
  15834. var toFontChar = [];
  15835. var usedFontCharCodes = [];
  15836. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15837. for (var originalCharCode in charCodeToGlyphId) {
  15838. originalCharCode |= 0;
  15839. var glyphId = charCodeToGlyphId[originalCharCode];
  15840. var fontCharCode = originalCharCode;
  15841. // First try to map the value to a unicode position if a non identity map
  15842. // was created.
  15843. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15844. var unicode = toUnicode.get(fontCharCode);
  15845. // TODO: Try to map ligatures to the correct spot.
  15846. if (unicode.length === 1) {
  15847. fontCharCode = unicode.charCodeAt(0);
  15848. }
  15849. }
  15850. // Try to move control characters, special characters and already mapped
  15851. // characters to the private use area since they will not be drawn by
  15852. // canvas if left in their current position. Also, move characters if the
  15853. // font was symbolic and there is only an identity unicode map since the
  15854. // characters probably aren't in the correct position (fixes an issue
  15855. // with firefox and thuluthfont).
  15856. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15857. isProblematicUnicodeLocation(fontCharCode) ||
  15858. (isSymbolic && isIdentityUnicode)) &&
  15859. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15860. // Loop to try and find a free spot in the private use area.
  15861. do {
  15862. fontCharCode = nextAvailableFontCharCode++;
  15863. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15864. fontCharCode = 0xF020;
  15865. nextAvailableFontCharCode = fontCharCode + 1;
  15866. }
  15867. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15868. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15869. }
  15870. newMap[fontCharCode] = glyphId;
  15871. toFontChar[originalCharCode] = fontCharCode;
  15872. usedFontCharCodes[fontCharCode] = true;
  15873. }
  15874. return {
  15875. toFontChar: toFontChar,
  15876. charCodeToGlyphId: newMap,
  15877. nextAvailableFontCharCode: nextAvailableFontCharCode
  15878. };
  15879. }
  15880. function getRanges(glyphs) {
  15881. // Array.sort() sorts by characters, not numerically, so convert to an
  15882. // array of characters.
  15883. var codes = [];
  15884. for (var charCode in glyphs) {
  15885. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15886. }
  15887. codes.sort(function fontGetRangesSort(a, b) {
  15888. return a.fontCharCode - b.fontCharCode;
  15889. });
  15890. // Split the sorted codes into ranges.
  15891. var ranges = [];
  15892. var length = codes.length;
  15893. for (var n = 0; n < length; ) {
  15894. var start = codes[n].fontCharCode;
  15895. var codeIndices = [codes[n].glyphId];
  15896. ++n;
  15897. var end = start;
  15898. while (n < length && end + 1 === codes[n].fontCharCode) {
  15899. codeIndices.push(codes[n].glyphId);
  15900. ++end;
  15901. ++n;
  15902. if (end === 0xFFFF) {
  15903. break;
  15904. }
  15905. }
  15906. ranges.push([start, end, codeIndices]);
  15907. }
  15908. return ranges;
  15909. }
  15910. function createCmapTable(glyphs) {
  15911. var ranges = getRanges(glyphs);
  15912. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15913. var cmap = '\x00\x00' + // version
  15914. string16(numTables) + // numTables
  15915. '\x00\x03' + // platformID
  15916. '\x00\x01' + // encodingID
  15917. string32(4 + numTables * 8); // start of the table record
  15918. var i, ii, j, jj;
  15919. for (i = ranges.length - 1; i >= 0; --i) {
  15920. if (ranges[i][0] <= 0xFFFF) { break; }
  15921. }
  15922. var bmpLength = i + 1;
  15923. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15924. ranges[i][1] = 0xFFFE;
  15925. }
  15926. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15927. var segCount = bmpLength + trailingRangesCount;
  15928. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15929. // Fill up the 4 parallel arrays describing the segments.
  15930. var startCount = '';
  15931. var endCount = '';
  15932. var idDeltas = '';
  15933. var idRangeOffsets = '';
  15934. var glyphsIds = '';
  15935. var bias = 0;
  15936. var range, start, end, codes;
  15937. for (i = 0, ii = bmpLength; i < ii; i++) {
  15938. range = ranges[i];
  15939. start = range[0];
  15940. end = range[1];
  15941. startCount += string16(start);
  15942. endCount += string16(end);
  15943. codes = range[2];
  15944. var contiguous = true;
  15945. for (j = 1, jj = codes.length; j < jj; ++j) {
  15946. if (codes[j] !== codes[j - 1] + 1) {
  15947. contiguous = false;
  15948. break;
  15949. }
  15950. }
  15951. if (!contiguous) {
  15952. var offset = (segCount - i) * 2 + bias * 2;
  15953. bias += (end - start + 1);
  15954. idDeltas += string16(0);
  15955. idRangeOffsets += string16(offset);
  15956. for (j = 0, jj = codes.length; j < jj; ++j) {
  15957. glyphsIds += string16(codes[j]);
  15958. }
  15959. } else {
  15960. var startCode = codes[0];
  15961. idDeltas += string16((startCode - start) & 0xFFFF);
  15962. idRangeOffsets += string16(0);
  15963. }
  15964. }
  15965. if (trailingRangesCount > 0) {
  15966. endCount += '\xFF\xFF';
  15967. startCount += '\xFF\xFF';
  15968. idDeltas += '\x00\x01';
  15969. idRangeOffsets += '\x00\x00';
  15970. }
  15971. var format314 = '\x00\x00' + // language
  15972. string16(2 * segCount) +
  15973. string16(searchParams.range) +
  15974. string16(searchParams.entry) +
  15975. string16(searchParams.rangeShift) +
  15976. endCount + '\x00\x00' + startCount +
  15977. idDeltas + idRangeOffsets + glyphsIds;
  15978. var format31012 = '';
  15979. var header31012 = '';
  15980. if (numTables > 1) {
  15981. cmap += '\x00\x03' + // platformID
  15982. '\x00\x0A' + // encodingID
  15983. string32(4 + numTables * 8 +
  15984. 4 + format314.length); // start of the table record
  15985. format31012 = '';
  15986. for (i = 0, ii = ranges.length; i < ii; i++) {
  15987. range = ranges[i];
  15988. start = range[0];
  15989. codes = range[2];
  15990. var code = codes[0];
  15991. for (j = 1, jj = codes.length; j < jj; ++j) {
  15992. if (codes[j] !== codes[j - 1] + 1) {
  15993. end = range[0] + j - 1;
  15994. format31012 += string32(start) + // startCharCode
  15995. string32(end) + // endCharCode
  15996. string32(code); // startGlyphID
  15997. start = end + 1;
  15998. code = codes[j];
  15999. }
  16000. }
  16001. format31012 += string32(start) + // startCharCode
  16002. string32(range[1]) + // endCharCode
  16003. string32(code); // startGlyphID
  16004. }
  16005. header31012 = '\x00\x0C' + // format
  16006. '\x00\x00' + // reserved
  16007. string32(format31012.length + 16) + // length
  16008. '\x00\x00\x00\x00' + // language
  16009. string32(format31012.length / 12); // nGroups
  16010. }
  16011. return cmap + '\x00\x04' + // format
  16012. string16(format314.length + 4) + // length
  16013. format314 + header31012 + format31012;
  16014. }
  16015. function validateOS2Table(os2) {
  16016. var stream = new Stream(os2.data);
  16017. var version = stream.getUint16();
  16018. // TODO verify all OS/2 tables fields, but currently we validate only those
  16019. // that give us issues
  16020. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  16021. var selection = stream.getUint16();
  16022. if (version < 4 && (selection & 0x0300)) {
  16023. return false;
  16024. }
  16025. var firstChar = stream.getUint16();
  16026. var lastChar = stream.getUint16();
  16027. if (firstChar > lastChar) {
  16028. return false;
  16029. }
  16030. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  16031. var usWinAscent = stream.getUint16();
  16032. if (usWinAscent === 0) { // makes font unreadable by windows
  16033. return false;
  16034. }
  16035. // OS/2 appears to be valid, resetting some fields
  16036. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  16037. return true;
  16038. }
  16039. function createOS2Table(properties, charstrings, override) {
  16040. override = override || {
  16041. unitsPerEm: 0,
  16042. yMax: 0,
  16043. yMin: 0,
  16044. ascent: 0,
  16045. descent: 0
  16046. };
  16047. var ulUnicodeRange1 = 0;
  16048. var ulUnicodeRange2 = 0;
  16049. var ulUnicodeRange3 = 0;
  16050. var ulUnicodeRange4 = 0;
  16051. var firstCharIndex = null;
  16052. var lastCharIndex = 0;
  16053. if (charstrings) {
  16054. for (var code in charstrings) {
  16055. code |= 0;
  16056. if (firstCharIndex > code || !firstCharIndex) {
  16057. firstCharIndex = code;
  16058. }
  16059. if (lastCharIndex < code) {
  16060. lastCharIndex = code;
  16061. }
  16062. var position = getUnicodeRangeFor(code);
  16063. if (position < 32) {
  16064. ulUnicodeRange1 |= 1 << position;
  16065. } else if (position < 64) {
  16066. ulUnicodeRange2 |= 1 << position - 32;
  16067. } else if (position < 96) {
  16068. ulUnicodeRange3 |= 1 << position - 64;
  16069. } else if (position < 123) {
  16070. ulUnicodeRange4 |= 1 << position - 96;
  16071. } else {
  16072. error('Unicode ranges Bits > 123 are reserved for internal usage');
  16073. }
  16074. }
  16075. } else {
  16076. // TODO
  16077. firstCharIndex = 0;
  16078. lastCharIndex = 255;
  16079. }
  16080. var bbox = properties.bbox || [0, 0, 0, 0];
  16081. var unitsPerEm = (override.unitsPerEm ||
  16082. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  16083. // if the font units differ to the PDF glyph space units
  16084. // then scale up the values
  16085. var scale = (properties.ascentScaled ? 1.0 :
  16086. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  16087. var typoAscent = (override.ascent ||
  16088. Math.round(scale * (properties.ascent || bbox[3])));
  16089. var typoDescent = (override.descent ||
  16090. Math.round(scale * (properties.descent || bbox[1])));
  16091. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  16092. typoDescent = -typoDescent; // fixing incorrect descent
  16093. }
  16094. var winAscent = override.yMax || typoAscent;
  16095. var winDescent = -override.yMin || -typoDescent;
  16096. return '\x00\x03' + // version
  16097. '\x02\x24' + // xAvgCharWidth
  16098. '\x01\xF4' + // usWeightClass
  16099. '\x00\x05' + // usWidthClass
  16100. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  16101. '\x02\x8A' + // ySubscriptXSize
  16102. '\x02\xBB' + // ySubscriptYSize
  16103. '\x00\x00' + // ySubscriptXOffset
  16104. '\x00\x8C' + // ySubscriptYOffset
  16105. '\x02\x8A' + // ySuperScriptXSize
  16106. '\x02\xBB' + // ySuperScriptYSize
  16107. '\x00\x00' + // ySuperScriptXOffset
  16108. '\x01\xDF' + // ySuperScriptYOffset
  16109. '\x00\x31' + // yStrikeOutSize
  16110. '\x01\x02' + // yStrikeOutPosition
  16111. '\x00\x00' + // sFamilyClass
  16112. '\x00\x00\x06' +
  16113. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  16114. '\x00\x00\x00\x00\x00\x00' + // Panose
  16115. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  16116. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  16117. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  16118. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  16119. '\x2A\x32\x31\x2A' + // achVendID
  16120. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  16121. string16(firstCharIndex ||
  16122. properties.firstChar) + // usFirstCharIndex
  16123. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  16124. string16(typoAscent) + // sTypoAscender
  16125. string16(typoDescent) + // sTypoDescender
  16126. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  16127. string16(winAscent) + // usWinAscent
  16128. string16(winDescent) + // usWinDescent
  16129. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  16130. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  16131. string16(properties.xHeight) + // sxHeight
  16132. string16(properties.capHeight) + // sCapHeight
  16133. string16(0) + // usDefaultChar
  16134. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  16135. '\x00\x03'; // usMaxContext
  16136. }
  16137. function createPostTable(properties) {
  16138. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  16139. return ('\x00\x03\x00\x00' + // Version number
  16140. string32(angle) + // italicAngle
  16141. '\x00\x00' + // underlinePosition
  16142. '\x00\x00' + // underlineThickness
  16143. string32(properties.fixedPitch) + // isFixedPitch
  16144. '\x00\x00\x00\x00' + // minMemType42
  16145. '\x00\x00\x00\x00' + // maxMemType42
  16146. '\x00\x00\x00\x00' + // minMemType1
  16147. '\x00\x00\x00\x00'); // maxMemType1
  16148. }
  16149. function createNameTable(name, proto) {
  16150. if (!proto) {
  16151. proto = [[], []]; // no strings and unicode strings
  16152. }
  16153. var strings = [
  16154. proto[0][0] || 'Original licence', // 0.Copyright
  16155. proto[0][1] || name, // 1.Font family
  16156. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  16157. proto[0][3] || 'uniqueID', // 3.Unique ID
  16158. proto[0][4] || name, // 4.Full font name
  16159. proto[0][5] || 'Version 0.11', // 5.Version
  16160. proto[0][6] || '', // 6.Postscript name
  16161. proto[0][7] || 'Unknown', // 7.Trademark
  16162. proto[0][8] || 'Unknown', // 8.Manufacturer
  16163. proto[0][9] || 'Unknown' // 9.Designer
  16164. ];
  16165. // Mac want 1-byte per character strings while Windows want
  16166. // 2-bytes per character, so duplicate the names table
  16167. var stringsUnicode = [];
  16168. var i, ii, j, jj, str;
  16169. for (i = 0, ii = strings.length; i < ii; i++) {
  16170. str = proto[1][i] || strings[i];
  16171. var strBufUnicode = [];
  16172. for (j = 0, jj = str.length; j < jj; j++) {
  16173. strBufUnicode.push(string16(str.charCodeAt(j)));
  16174. }
  16175. stringsUnicode.push(strBufUnicode.join(''));
  16176. }
  16177. var names = [strings, stringsUnicode];
  16178. var platforms = ['\x00\x01', '\x00\x03'];
  16179. var encodings = ['\x00\x00', '\x00\x01'];
  16180. var languages = ['\x00\x00', '\x04\x09'];
  16181. var namesRecordCount = strings.length * platforms.length;
  16182. var nameTable =
  16183. '\x00\x00' + // format
  16184. string16(namesRecordCount) + // Number of names Record
  16185. string16(namesRecordCount * 12 + 6); // Storage
  16186. // Build the name records field
  16187. var strOffset = 0;
  16188. for (i = 0, ii = platforms.length; i < ii; i++) {
  16189. var strs = names[i];
  16190. for (j = 0, jj = strs.length; j < jj; j++) {
  16191. str = strs[j];
  16192. var nameRecord =
  16193. platforms[i] + // platform ID
  16194. encodings[i] + // encoding ID
  16195. languages[i] + // language ID
  16196. string16(j) + // name ID
  16197. string16(str.length) +
  16198. string16(strOffset);
  16199. nameTable += nameRecord;
  16200. strOffset += str.length;
  16201. }
  16202. }
  16203. nameTable += strings.join('') + stringsUnicode.join('');
  16204. return nameTable;
  16205. }
  16206. Font.prototype = {
  16207. name: null,
  16208. font: null,
  16209. mimetype: null,
  16210. encoding: null,
  16211. get renderer() {
  16212. var renderer = FontRendererFactory.create(this);
  16213. return shadow(this, 'renderer', renderer);
  16214. },
  16215. exportData: function Font_exportData() {
  16216. var data = {};
  16217. for (var i in this) {
  16218. if (this.hasOwnProperty(i)) {
  16219. data[i] = this[i];
  16220. }
  16221. }
  16222. return data;
  16223. },
  16224. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  16225. function readTableEntry(file) {
  16226. var tag = bytesToString(file.getBytes(4));
  16227. var checksum = file.getInt32();
  16228. var offset = file.getInt32() >>> 0;
  16229. var length = file.getInt32() >>> 0;
  16230. // Read the table associated data
  16231. var previousPosition = file.pos;
  16232. file.pos = file.start ? file.start : 0;
  16233. file.skip(offset);
  16234. var data = file.getBytes(length);
  16235. file.pos = previousPosition;
  16236. if (tag === 'head') {
  16237. // clearing checksum adjustment
  16238. data[8] = data[9] = data[10] = data[11] = 0;
  16239. data[17] |= 0x20; //Set font optimized for cleartype flag
  16240. }
  16241. return {
  16242. tag: tag,
  16243. checksum: checksum,
  16244. length: length,
  16245. offset: offset,
  16246. data: data
  16247. };
  16248. }
  16249. function readOpenTypeHeader(ttf) {
  16250. return {
  16251. version: bytesToString(ttf.getBytes(4)),
  16252. numTables: ttf.getUint16(),
  16253. searchRange: ttf.getUint16(),
  16254. entrySelector: ttf.getUint16(),
  16255. rangeShift: ttf.getUint16()
  16256. };
  16257. }
  16258. /**
  16259. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  16260. * PDF spec
  16261. */
  16262. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  16263. var segment;
  16264. var start = (font.start ? font.start : 0) + cmap.offset;
  16265. font.pos = start;
  16266. var version = font.getUint16();
  16267. var numTables = font.getUint16();
  16268. var potentialTable;
  16269. var canBreak = false;
  16270. // There's an order of preference in terms of which cmap subtable to
  16271. // use:
  16272. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  16273. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  16274. // The following takes advantage of the fact that the tables are sorted
  16275. // to work.
  16276. for (var i = 0; i < numTables; i++) {
  16277. var platformId = font.getUint16();
  16278. var encodingId = font.getUint16();
  16279. var offset = font.getInt32() >>> 0;
  16280. var useTable = false;
  16281. if (platformId === 0 && encodingId === 0) {
  16282. useTable = true;
  16283. // Continue the loop since there still may be a higher priority
  16284. // table.
  16285. } else if (platformId === 1 && encodingId === 0) {
  16286. useTable = true;
  16287. // Continue the loop since there still may be a higher priority
  16288. // table.
  16289. } else if (platformId === 3 && encodingId === 1 &&
  16290. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  16291. useTable = true;
  16292. if (!isSymbolicFont) {
  16293. canBreak = true;
  16294. }
  16295. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  16296. useTable = true;
  16297. canBreak = true;
  16298. }
  16299. if (useTable) {
  16300. potentialTable = {
  16301. platformId: platformId,
  16302. encodingId: encodingId,
  16303. offset: offset
  16304. };
  16305. }
  16306. if (canBreak) {
  16307. break;
  16308. }
  16309. }
  16310. if (potentialTable) {
  16311. font.pos = start + potentialTable.offset;
  16312. }
  16313. if (!potentialTable || font.peekByte() === -1) {
  16314. warn('Could not find a preferred cmap table.');
  16315. return {
  16316. platformId: -1,
  16317. encodingId: -1,
  16318. mappings: [],
  16319. hasShortCmap: false
  16320. };
  16321. }
  16322. var format = font.getUint16();
  16323. var length = font.getUint16();
  16324. var language = font.getUint16();
  16325. var hasShortCmap = false;
  16326. var mappings = [];
  16327. var j, glyphId;
  16328. // TODO(mack): refactor this cmap subtable reading logic out
  16329. if (format === 0) {
  16330. for (j = 0; j < 256; j++) {
  16331. var index = font.getByte();
  16332. if (!index) {
  16333. continue;
  16334. }
  16335. mappings.push({
  16336. charCode: j,
  16337. glyphId: index
  16338. });
  16339. }
  16340. hasShortCmap = true;
  16341. } else if (format === 4) {
  16342. // re-creating the table in format 4 since the encoding
  16343. // might be changed
  16344. var segCount = (font.getUint16() >> 1);
  16345. font.getBytes(6); // skipping range fields
  16346. var segIndex, segments = [];
  16347. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16348. segments.push({ end: font.getUint16() });
  16349. }
  16350. font.getUint16();
  16351. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16352. segments[segIndex].start = font.getUint16();
  16353. }
  16354. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16355. segments[segIndex].delta = font.getUint16();
  16356. }
  16357. var offsetsCount = 0;
  16358. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16359. segment = segments[segIndex];
  16360. var rangeOffset = font.getUint16();
  16361. if (!rangeOffset) {
  16362. segment.offsetIndex = -1;
  16363. continue;
  16364. }
  16365. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  16366. segment.offsetIndex = offsetIndex;
  16367. offsetsCount = Math.max(offsetsCount, offsetIndex +
  16368. segment.end - segment.start + 1);
  16369. }
  16370. var offsets = [];
  16371. for (j = 0; j < offsetsCount; j++) {
  16372. offsets.push(font.getUint16());
  16373. }
  16374. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16375. segment = segments[segIndex];
  16376. start = segment.start;
  16377. var end = segment.end;
  16378. var delta = segment.delta;
  16379. offsetIndex = segment.offsetIndex;
  16380. for (j = start; j <= end; j++) {
  16381. if (j === 0xFFFF) {
  16382. continue;
  16383. }
  16384. glyphId = (offsetIndex < 0 ?
  16385. j : offsets[offsetIndex + j - start]);
  16386. glyphId = (glyphId + delta) & 0xFFFF;
  16387. if (glyphId === 0) {
  16388. continue;
  16389. }
  16390. mappings.push({
  16391. charCode: j,
  16392. glyphId: glyphId
  16393. });
  16394. }
  16395. }
  16396. } else if (format === 6) {
  16397. // Format 6 is a 2-bytes dense mapping, which means the font data
  16398. // lives glue together even if they are pretty far in the unicode
  16399. // table. (This looks weird, so I can have missed something), this
  16400. // works on Linux but seems to fails on Mac so let's rewrite the
  16401. // cmap table to a 3-1-4 style
  16402. var firstCode = font.getUint16();
  16403. var entryCount = font.getUint16();
  16404. for (j = 0; j < entryCount; j++) {
  16405. glyphId = font.getUint16();
  16406. var charCode = firstCode + j;
  16407. mappings.push({
  16408. charCode: charCode,
  16409. glyphId: glyphId
  16410. });
  16411. }
  16412. } else {
  16413. warn('cmap table has unsupported format: ' + format);
  16414. return {
  16415. platformId: -1,
  16416. encodingId: -1,
  16417. mappings: [],
  16418. hasShortCmap: false
  16419. };
  16420. }
  16421. // removing duplicate entries
  16422. mappings.sort(function (a, b) {
  16423. return a.charCode - b.charCode;
  16424. });
  16425. for (i = 1; i < mappings.length; i++) {
  16426. if (mappings[i - 1].charCode === mappings[i].charCode) {
  16427. mappings.splice(i, 1);
  16428. i--;
  16429. }
  16430. }
  16431. return {
  16432. platformId: potentialTable.platformId,
  16433. encodingId: potentialTable.encodingId,
  16434. mappings: mappings,
  16435. hasShortCmap: hasShortCmap
  16436. };
  16437. }
  16438. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  16439. if (!header) {
  16440. if (metrics) {
  16441. metrics.data = null;
  16442. }
  16443. return;
  16444. }
  16445. font.pos = (font.start ? font.start : 0) + header.offset;
  16446. font.pos += header.length - 2;
  16447. var numOfMetrics = font.getUint16();
  16448. if (numOfMetrics > numGlyphs) {
  16449. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16450. 'greater than the numGlyphs (' + numGlyphs + ')');
  16451. // Reduce numOfMetrics if it is greater than numGlyphs
  16452. numOfMetrics = numGlyphs;
  16453. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16454. header.data[35] = numOfMetrics & 0x00ff;
  16455. }
  16456. var numOfSidebearings = numGlyphs - numOfMetrics;
  16457. var numMissing = numOfSidebearings -
  16458. ((metrics.length - numOfMetrics * 4) >> 1);
  16459. if (numMissing > 0) {
  16460. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16461. // Since we need to add two properties for each glyph, this explains
  16462. // the use of |numMissing * 2| when initializing the typed array.
  16463. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16464. entries.set(metrics.data);
  16465. metrics.data = entries;
  16466. }
  16467. }
  16468. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16469. hintsValid) {
  16470. if (sourceEnd - sourceStart <= 12) {
  16471. // glyph with data less than 12 is invalid one
  16472. return 0;
  16473. }
  16474. var glyf = source.subarray(sourceStart, sourceEnd);
  16475. var contoursCount = (glyf[0] << 8) | glyf[1];
  16476. if (contoursCount & 0x8000) {
  16477. // complex glyph, writing as is
  16478. dest.set(glyf, destStart);
  16479. return glyf.length;
  16480. }
  16481. var i, j = 10, flagsCount = 0;
  16482. for (i = 0; i < contoursCount; i++) {
  16483. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16484. flagsCount = endPoint + 1;
  16485. j += 2;
  16486. }
  16487. // skipping instructions
  16488. var instructionsStart = j;
  16489. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16490. j += 2 + instructionsLength;
  16491. var instructionsEnd = j;
  16492. // validating flags
  16493. var coordinatesLength = 0;
  16494. for (i = 0; i < flagsCount; i++) {
  16495. var flag = glyf[j++];
  16496. if (flag & 0xC0) {
  16497. // reserved flags must be zero, cleaning up
  16498. glyf[j - 1] = flag & 0x3F;
  16499. }
  16500. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16501. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16502. coordinatesLength += xyLength;
  16503. if (flag & 8) {
  16504. var repeat = glyf[j++];
  16505. i += repeat;
  16506. coordinatesLength += repeat * xyLength;
  16507. }
  16508. }
  16509. // glyph without coordinates will be rejected
  16510. if (coordinatesLength === 0) {
  16511. return 0;
  16512. }
  16513. var glyphDataLength = j + coordinatesLength;
  16514. if (glyphDataLength > glyf.length) {
  16515. // not enough data for coordinates
  16516. return 0;
  16517. }
  16518. if (!hintsValid && instructionsLength > 0) {
  16519. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16520. dest.set([0, 0], destStart + instructionsStart);
  16521. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16522. destStart + instructionsStart + 2);
  16523. glyphDataLength -= instructionsLength;
  16524. if (glyf.length - glyphDataLength > 3) {
  16525. glyphDataLength = (glyphDataLength + 3) & ~3;
  16526. }
  16527. return glyphDataLength;
  16528. }
  16529. if (glyf.length - glyphDataLength > 3) {
  16530. // truncating and aligning to 4 bytes the long glyph data
  16531. glyphDataLength = (glyphDataLength + 3) & ~3;
  16532. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16533. return glyphDataLength;
  16534. }
  16535. // glyph data is fine
  16536. dest.set(glyf, destStart);
  16537. return glyf.length;
  16538. }
  16539. function sanitizeHead(head, numGlyphs, locaLength) {
  16540. var data = head.data;
  16541. // Validate version:
  16542. // Should always be 0x00010000
  16543. var version = int32(data[0], data[1], data[2], data[3]);
  16544. if (version >> 16 !== 1) {
  16545. info('Attempting to fix invalid version in head table: ' + version);
  16546. data[0] = 0;
  16547. data[1] = 1;
  16548. data[2] = 0;
  16549. data[3] = 0;
  16550. }
  16551. var indexToLocFormat = int16(data[50], data[51]);
  16552. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16553. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16554. indexToLocFormat);
  16555. // The value of indexToLocFormat should be 0 if the loca table
  16556. // consists of short offsets, and should be 1 if the loca table
  16557. // consists of long offsets.
  16558. //
  16559. // The number of entries in the loca table should be numGlyphs + 1.
  16560. //
  16561. // Using this information, we can work backwards to deduce if the
  16562. // size of each offset in the loca table, and thus figure out the
  16563. // appropriate value for indexToLocFormat.
  16564. var numGlyphsPlusOne = numGlyphs + 1;
  16565. if (locaLength === numGlyphsPlusOne << 1) {
  16566. // 0x0000 indicates the loca table consists of short offsets
  16567. data[50] = 0;
  16568. data[51] = 0;
  16569. } else if (locaLength === numGlyphsPlusOne << 2) {
  16570. // 0x0001 indicates the loca table consists of long offsets
  16571. data[50] = 0;
  16572. data[51] = 1;
  16573. } else {
  16574. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16575. }
  16576. }
  16577. }
  16578. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16579. isGlyphLocationsLong, hintsValid,
  16580. dupFirstEntry) {
  16581. var itemSize, itemDecode, itemEncode;
  16582. if (isGlyphLocationsLong) {
  16583. itemSize = 4;
  16584. itemDecode = function fontItemDecodeLong(data, offset) {
  16585. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16586. (data[offset + 2] << 8) | data[offset + 3];
  16587. };
  16588. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16589. data[offset] = (value >>> 24) & 0xFF;
  16590. data[offset + 1] = (value >> 16) & 0xFF;
  16591. data[offset + 2] = (value >> 8) & 0xFF;
  16592. data[offset + 3] = value & 0xFF;
  16593. };
  16594. } else {
  16595. itemSize = 2;
  16596. itemDecode = function fontItemDecode(data, offset) {
  16597. return (data[offset] << 9) | (data[offset + 1] << 1);
  16598. };
  16599. itemEncode = function fontItemEncode(data, offset, value) {
  16600. data[offset] = (value >> 9) & 0xFF;
  16601. data[offset + 1] = (value >> 1) & 0xFF;
  16602. };
  16603. }
  16604. var locaData = loca.data;
  16605. var locaDataSize = itemSize * (1 + numGlyphs);
  16606. // is loca.data too short or long?
  16607. if (locaData.length !== locaDataSize) {
  16608. locaData = new Uint8Array(locaDataSize);
  16609. locaData.set(loca.data.subarray(0, locaDataSize));
  16610. loca.data = locaData;
  16611. }
  16612. // removing the invalid glyphs
  16613. var oldGlyfData = glyf.data;
  16614. var oldGlyfDataLength = oldGlyfData.length;
  16615. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16616. var startOffset = itemDecode(locaData, 0);
  16617. var writeOffset = 0;
  16618. var missingGlyphData = {};
  16619. itemEncode(locaData, 0, writeOffset);
  16620. var i, j;
  16621. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16622. var endOffset = itemDecode(locaData, j);
  16623. if (endOffset > oldGlyfDataLength &&
  16624. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16625. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16626. // the glyf table size, which makes last glyph out of range.
  16627. endOffset = oldGlyfDataLength;
  16628. }
  16629. if (endOffset > oldGlyfDataLength) {
  16630. // glyph end offset points outside glyf data, rejecting the glyph
  16631. itemEncode(locaData, j, writeOffset);
  16632. startOffset = endOffset;
  16633. continue;
  16634. }
  16635. if (startOffset === endOffset) {
  16636. missingGlyphData[i] = true;
  16637. }
  16638. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16639. newGlyfData, writeOffset, hintsValid);
  16640. writeOffset += newLength;
  16641. itemEncode(locaData, j, writeOffset);
  16642. startOffset = endOffset;
  16643. }
  16644. if (writeOffset === 0) {
  16645. // glyf table cannot be empty -- redoing the glyf and loca tables
  16646. // to have single glyph with one point
  16647. var simpleGlyph = new Uint8Array(
  16648. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16649. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16650. itemEncode(locaData, j, simpleGlyph.length);
  16651. }
  16652. glyf.data = simpleGlyph;
  16653. return missingGlyphData;
  16654. }
  16655. if (dupFirstEntry) {
  16656. var firstEntryLength = itemDecode(locaData, itemSize);
  16657. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16658. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16659. } else {
  16660. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16661. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16662. }
  16663. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16664. itemEncode(loca.data, locaData.length - itemSize,
  16665. writeOffset + firstEntryLength);
  16666. } else {
  16667. glyf.data = newGlyfData.subarray(0, writeOffset);
  16668. }
  16669. return missingGlyphData;
  16670. }
  16671. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16672. var start = (font.start ? font.start : 0) + post.offset;
  16673. font.pos = start;
  16674. var length = post.length, end = start + length;
  16675. var version = font.getInt32();
  16676. // skip rest to the tables
  16677. font.getBytes(28);
  16678. var glyphNames;
  16679. var valid = true;
  16680. var i;
  16681. switch (version) {
  16682. case 0x00010000:
  16683. glyphNames = MacStandardGlyphOrdering;
  16684. break;
  16685. case 0x00020000:
  16686. var numGlyphs = font.getUint16();
  16687. if (numGlyphs !== maxpNumGlyphs) {
  16688. valid = false;
  16689. break;
  16690. }
  16691. var glyphNameIndexes = [];
  16692. for (i = 0; i < numGlyphs; ++i) {
  16693. var index = font.getUint16();
  16694. if (index >= 32768) {
  16695. valid = false;
  16696. break;
  16697. }
  16698. glyphNameIndexes.push(index);
  16699. }
  16700. if (!valid) {
  16701. break;
  16702. }
  16703. var customNames = [];
  16704. var strBuf = [];
  16705. while (font.pos < end) {
  16706. var stringLength = font.getByte();
  16707. strBuf.length = stringLength;
  16708. for (i = 0; i < stringLength; ++i) {
  16709. strBuf[i] = String.fromCharCode(font.getByte());
  16710. }
  16711. customNames.push(strBuf.join(''));
  16712. }
  16713. glyphNames = [];
  16714. for (i = 0; i < numGlyphs; ++i) {
  16715. var j = glyphNameIndexes[i];
  16716. if (j < 258) {
  16717. glyphNames.push(MacStandardGlyphOrdering[j]);
  16718. continue;
  16719. }
  16720. glyphNames.push(customNames[j - 258]);
  16721. }
  16722. break;
  16723. case 0x00030000:
  16724. break;
  16725. default:
  16726. warn('Unknown/unsupported post table version ' + version);
  16727. valid = false;
  16728. if (properties.defaultEncoding) {
  16729. glyphNames = properties.defaultEncoding;
  16730. }
  16731. break;
  16732. }
  16733. properties.glyphNames = glyphNames;
  16734. return valid;
  16735. }
  16736. function readNameTable(nameTable) {
  16737. var start = (font.start ? font.start : 0) + nameTable.offset;
  16738. font.pos = start;
  16739. var names = [[], []];
  16740. var length = nameTable.length, end = start + length;
  16741. var format = font.getUint16();
  16742. var FORMAT_0_HEADER_LENGTH = 6;
  16743. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16744. // unsupported name table format or table "too" small
  16745. return names;
  16746. }
  16747. var numRecords = font.getUint16();
  16748. var stringsStart = font.getUint16();
  16749. var records = [];
  16750. var NAME_RECORD_LENGTH = 12;
  16751. var i, ii;
  16752. for (i = 0; i < numRecords &&
  16753. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16754. var r = {
  16755. platform: font.getUint16(),
  16756. encoding: font.getUint16(),
  16757. language: font.getUint16(),
  16758. name: font.getUint16(),
  16759. length: font.getUint16(),
  16760. offset: font.getUint16()
  16761. };
  16762. // using only Macintosh and Windows platform/encoding names
  16763. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16764. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16765. records.push(r);
  16766. }
  16767. }
  16768. for (i = 0, ii = records.length; i < ii; i++) {
  16769. var record = records[i];
  16770. var pos = start + stringsStart + record.offset;
  16771. if (pos + record.length > end) {
  16772. continue; // outside of name table, ignoring
  16773. }
  16774. font.pos = pos;
  16775. var nameIndex = record.name;
  16776. if (record.encoding) {
  16777. // unicode
  16778. var str = '';
  16779. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16780. str += String.fromCharCode(font.getUint16());
  16781. }
  16782. names[1][nameIndex] = str;
  16783. } else {
  16784. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16785. }
  16786. }
  16787. return names;
  16788. }
  16789. var TTOpsStackDeltas = [
  16790. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16791. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16792. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16793. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16794. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16795. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16796. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16797. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16798. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16799. // 0xC0-DF == -1 and 0xE0-FF == -2
  16800. function sanitizeTTProgram(table, ttContext) {
  16801. var data = table.data;
  16802. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16803. var stack = [];
  16804. var callstack = [];
  16805. var functionsCalled = [];
  16806. var tooComplexToFollowFunctions =
  16807. ttContext.tooComplexToFollowFunctions;
  16808. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16809. for (var ii = data.length; i < ii;) {
  16810. var op = data[i++];
  16811. // The TrueType instruction set docs can be found at
  16812. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16813. if (op === 0x40) { // NPUSHB - pushes n bytes
  16814. n = data[i++];
  16815. if (inFDEF || inELSE) {
  16816. i += n;
  16817. } else {
  16818. for (j = 0; j < n; j++) {
  16819. stack.push(data[i++]);
  16820. }
  16821. }
  16822. } else if (op === 0x41) { // NPUSHW - pushes n words
  16823. n = data[i++];
  16824. if (inFDEF || inELSE) {
  16825. i += n * 2;
  16826. } else {
  16827. for (j = 0; j < n; j++) {
  16828. b = data[i++];
  16829. stack.push((b << 8) | data[i++]);
  16830. }
  16831. }
  16832. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16833. n = op - 0xB0 + 1;
  16834. if (inFDEF || inELSE) {
  16835. i += n;
  16836. } else {
  16837. for (j = 0; j < n; j++) {
  16838. stack.push(data[i++]);
  16839. }
  16840. }
  16841. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16842. n = op - 0xB8 + 1;
  16843. if (inFDEF || inELSE) {
  16844. i += n * 2;
  16845. } else {
  16846. for (j = 0; j < n; j++) {
  16847. b = data[i++];
  16848. stack.push((b << 8) | data[i++]);
  16849. }
  16850. }
  16851. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16852. if (!inFDEF && !inELSE) {
  16853. // collecting inforamtion about which functions are used
  16854. funcId = stack[stack.length - 1];
  16855. ttContext.functionsUsed[funcId] = true;
  16856. if (funcId in ttContext.functionsStackDeltas) {
  16857. stack.length += ttContext.functionsStackDeltas[funcId];
  16858. } else if (funcId in ttContext.functionsDefined &&
  16859. functionsCalled.indexOf(funcId) < 0) {
  16860. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16861. functionsCalled.push(funcId);
  16862. pc = ttContext.functionsDefined[funcId];
  16863. if (!pc) {
  16864. warn('TT: CALL non-existent function');
  16865. ttContext.hintsValid = false;
  16866. return;
  16867. }
  16868. data = pc.data;
  16869. i = pc.i;
  16870. }
  16871. }
  16872. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16873. if (inFDEF || inELSE) {
  16874. warn('TT: nested FDEFs not allowed');
  16875. tooComplexToFollowFunctions = true;
  16876. }
  16877. inFDEF = true;
  16878. // collecting inforamtion about which functions are defined
  16879. lastDeff = i;
  16880. funcId = stack.pop();
  16881. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16882. } else if (op === 0x2D) { // ENDF - end of function
  16883. if (inFDEF) {
  16884. inFDEF = false;
  16885. lastEndf = i;
  16886. } else {
  16887. pc = callstack.pop();
  16888. if (!pc) {
  16889. warn('TT: ENDF bad stack');
  16890. ttContext.hintsValid = false;
  16891. return;
  16892. }
  16893. funcId = functionsCalled.pop();
  16894. data = pc.data;
  16895. i = pc.i;
  16896. ttContext.functionsStackDeltas[funcId] =
  16897. stack.length - pc.stackTop;
  16898. }
  16899. } else if (op === 0x89) { // IDEF - instruction definition
  16900. if (inFDEF || inELSE) {
  16901. warn('TT: nested IDEFs not allowed');
  16902. tooComplexToFollowFunctions = true;
  16903. }
  16904. inFDEF = true;
  16905. // recording it as a function to track ENDF
  16906. lastDeff = i;
  16907. } else if (op === 0x58) { // IF
  16908. ++ifLevel;
  16909. } else if (op === 0x1B) { // ELSE
  16910. inELSE = ifLevel;
  16911. } else if (op === 0x59) { // EIF
  16912. if (inELSE === ifLevel) {
  16913. inELSE = 0;
  16914. }
  16915. --ifLevel;
  16916. } else if (op === 0x1C) { // JMPR
  16917. if (!inFDEF && !inELSE) {
  16918. var offset = stack[stack.length - 1];
  16919. // only jumping forward to prevent infinite loop
  16920. if (offset > 0) {
  16921. i += offset - 1;
  16922. }
  16923. }
  16924. }
  16925. // Adjusting stack not extactly, but just enough to get function id
  16926. if (!inFDEF && !inELSE) {
  16927. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16928. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16929. if (op >= 0x71 && op <= 0x75) {
  16930. n = stack.pop();
  16931. if (n === n) {
  16932. stackDelta = -n * 2;
  16933. }
  16934. }
  16935. while (stackDelta < 0 && stack.length > 0) {
  16936. stack.pop();
  16937. stackDelta++;
  16938. }
  16939. while (stackDelta > 0) {
  16940. stack.push(NaN); // pushing any number into stack
  16941. stackDelta--;
  16942. }
  16943. }
  16944. }
  16945. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16946. var content = [data];
  16947. if (i > data.length) {
  16948. content.push(new Uint8Array(i - data.length));
  16949. }
  16950. if (lastDeff > lastEndf) {
  16951. warn('TT: complementing a missing function tail');
  16952. // new function definition started, but not finished
  16953. // complete function by [CLEAR, ENDF]
  16954. content.push(new Uint8Array([0x22, 0x2D]));
  16955. }
  16956. foldTTTable(table, content);
  16957. }
  16958. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16959. if (ttContext.tooComplexToFollowFunctions) {
  16960. return;
  16961. }
  16962. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16963. warn('TT: more functions defined than expected');
  16964. ttContext.hintsValid = false;
  16965. return;
  16966. }
  16967. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16968. if (j > maxFunctionDefs) {
  16969. warn('TT: invalid function id: ' + j);
  16970. ttContext.hintsValid = false;
  16971. return;
  16972. }
  16973. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16974. warn('TT: undefined function: ' + j);
  16975. ttContext.hintsValid = false;
  16976. return;
  16977. }
  16978. }
  16979. }
  16980. function foldTTTable(table, content) {
  16981. if (content.length > 1) {
  16982. // concatenating the content items
  16983. var newLength = 0;
  16984. var j, jj;
  16985. for (j = 0, jj = content.length; j < jj; j++) {
  16986. newLength += content[j].length;
  16987. }
  16988. newLength = (newLength + 3) & ~3;
  16989. var result = new Uint8Array(newLength);
  16990. var pos = 0;
  16991. for (j = 0, jj = content.length; j < jj; j++) {
  16992. result.set(content[j], pos);
  16993. pos += content[j].length;
  16994. }
  16995. table.data = result;
  16996. table.length = newLength;
  16997. }
  16998. }
  16999. function sanitizeTTPrograms(fpgm, prep, cvt) {
  17000. var ttContext = {
  17001. functionsDefined: [],
  17002. functionsUsed: [],
  17003. functionsStackDeltas: [],
  17004. tooComplexToFollowFunctions: false,
  17005. hintsValid: true
  17006. };
  17007. if (fpgm) {
  17008. sanitizeTTProgram(fpgm, ttContext);
  17009. }
  17010. if (prep) {
  17011. sanitizeTTProgram(prep, ttContext);
  17012. }
  17013. if (fpgm) {
  17014. checkInvalidFunctions(ttContext, maxFunctionDefs);
  17015. }
  17016. if (cvt && (cvt.length & 1)) {
  17017. var cvtData = new Uint8Array(cvt.length + 1);
  17018. cvtData.set(cvt.data);
  17019. cvt.data = cvtData;
  17020. }
  17021. return ttContext.hintsValid;
  17022. }
  17023. // The following steps modify the original font data, making copy
  17024. font = new Stream(new Uint8Array(font.getBytes()));
  17025. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  17026. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  17027. var header = readOpenTypeHeader(font);
  17028. var numTables = header.numTables;
  17029. var cff, cffFile;
  17030. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  17031. hmtx: null, maxp: null, name: null, post: null };
  17032. var table;
  17033. for (var i = 0; i < numTables; i++) {
  17034. table = readTableEntry(font);
  17035. if (VALID_TABLES.indexOf(table.tag) < 0) {
  17036. continue; // skipping table if it's not a required or optional table
  17037. }
  17038. if (table.length === 0) {
  17039. continue; // skipping empty tables
  17040. }
  17041. tables[table.tag] = table;
  17042. }
  17043. var isTrueType = !tables['CFF '];
  17044. if (!isTrueType) {
  17045. // OpenType font
  17046. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  17047. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  17048. // no major tables: throwing everything at CFFFont
  17049. cffFile = new Stream(tables['CFF '].data);
  17050. cff = new CFFFont(cffFile, properties);
  17051. return this.convert(name, cff, properties);
  17052. }
  17053. delete tables.glyf;
  17054. delete tables.loca;
  17055. delete tables.fpgm;
  17056. delete tables.prep;
  17057. delete tables['cvt '];
  17058. this.isOpenType = true;
  17059. } else {
  17060. if (!tables.glyf || !tables.loca) {
  17061. error('Required "glyf" or "loca" tables are not found');
  17062. }
  17063. this.isOpenType = false;
  17064. }
  17065. if (!tables.maxp) {
  17066. error('Required "maxp" table is not found');
  17067. }
  17068. font.pos = (font.start || 0) + tables.maxp.offset;
  17069. var version = font.getInt32();
  17070. var numGlyphs = font.getUint16();
  17071. var maxFunctionDefs = 0;
  17072. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  17073. // maxZones can be invalid
  17074. font.pos += 8;
  17075. var maxZones = font.getUint16();
  17076. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  17077. tables.maxp.data[14] = 0;
  17078. tables.maxp.data[15] = 2;
  17079. }
  17080. font.pos += 4;
  17081. maxFunctionDefs = font.getUint16();
  17082. }
  17083. var dupFirstEntry = false;
  17084. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  17085. properties.toUnicode.get(0) > '\u0000') {
  17086. // oracle's defect (see 3427), duplicating first entry
  17087. dupFirstEntry = true;
  17088. numGlyphs++;
  17089. tables.maxp.data[4] = numGlyphs >> 8;
  17090. tables.maxp.data[5] = numGlyphs & 255;
  17091. }
  17092. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  17093. tables['cvt '], maxFunctionDefs);
  17094. if (!hintsValid) {
  17095. delete tables.fpgm;
  17096. delete tables.prep;
  17097. delete tables['cvt '];
  17098. }
  17099. // Ensure the hmtx table contains the advance width and
  17100. // sidebearings information for numGlyphs in the maxp table
  17101. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  17102. if (!tables.head) {
  17103. error('Required "head" table is not found');
  17104. }
  17105. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  17106. var missingGlyphs = {};
  17107. if (isTrueType) {
  17108. var isGlyphLocationsLong = int16(tables.head.data[50],
  17109. tables.head.data[51]);
  17110. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  17111. numGlyphs, isGlyphLocationsLong,
  17112. hintsValid, dupFirstEntry);
  17113. }
  17114. if (!tables.hhea) {
  17115. error('Required "hhea" table is not found');
  17116. }
  17117. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  17118. // Sometimes it's 0. That needs to be fixed
  17119. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  17120. tables.hhea.data[10] = 0xFF;
  17121. tables.hhea.data[11] = 0xFF;
  17122. }
  17123. // The 'post' table has glyphs names.
  17124. if (tables.post) {
  17125. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  17126. if (!valid) {
  17127. tables.post = null;
  17128. }
  17129. }
  17130. var charCodeToGlyphId = [], charCode;
  17131. var toUnicode = properties.toUnicode, widths = properties.widths;
  17132. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  17133. toUnicode.length === 0x10000);
  17134. // Helper function to try to skip mapping of empty glyphs.
  17135. // Note: In some cases, just relying on the glyph data doesn't work,
  17136. // hence we also use a few heuristics to fix various PDF files.
  17137. function hasGlyph(glyphId, charCode, widthCode) {
  17138. if (!missingGlyphs[glyphId]) {
  17139. return true;
  17140. }
  17141. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  17142. return true;
  17143. }
  17144. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  17145. return true;
  17146. }
  17147. return false;
  17148. }
  17149. if (properties.type === 'CIDFontType2') {
  17150. var cidToGidMap = properties.cidToGidMap || [];
  17151. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  17152. properties.cMap.forEach(function(charCode, cid) {
  17153. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17154. var glyphId = -1;
  17155. if (isCidToGidMapEmpty) {
  17156. glyphId = charCode;
  17157. } else if (cidToGidMap[cid] !== undefined) {
  17158. glyphId = cidToGidMap[cid];
  17159. }
  17160. if (glyphId >= 0 && glyphId < numGlyphs &&
  17161. hasGlyph(glyphId, charCode, cid)) {
  17162. charCodeToGlyphId[charCode] = glyphId;
  17163. }
  17164. });
  17165. if (dupFirstEntry) {
  17166. charCodeToGlyphId[0] = numGlyphs - 1;
  17167. }
  17168. } else {
  17169. // Most of the following logic in this code branch is based on the
  17170. // 9.6.6.4 of the PDF spec.
  17171. var hasEncoding =
  17172. properties.differences.length > 0 || !!properties.baseEncodingName;
  17173. var cmapTable =
  17174. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  17175. var cmapPlatformId = cmapTable.platformId;
  17176. var cmapEncodingId = cmapTable.encodingId;
  17177. var cmapMappings = cmapTable.mappings;
  17178. var cmapMappingsLength = cmapMappings.length;
  17179. // The spec seems to imply that if the font is symbolic the encoding
  17180. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  17181. // where the the font is symbolic and it has an encoding.
  17182. if (hasEncoding &&
  17183. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  17184. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  17185. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  17186. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  17187. // When no preferred cmap table was found and |baseEncodingName| is
  17188. // one of the predefined encodings, we seem to obtain a better
  17189. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  17190. // TODO: Note that this is a hack which should be removed as soon as
  17191. // we have proper support for more exotic cmap tables.
  17192. var baseEncoding = [];
  17193. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  17194. properties.baseEncodingName === 'WinAnsiEncoding') {
  17195. baseEncoding = Encodings[properties.baseEncodingName];
  17196. }
  17197. for (charCode = 0; charCode < 256; charCode++) {
  17198. var glyphName;
  17199. if (this.differences && charCode in this.differences) {
  17200. glyphName = this.differences[charCode];
  17201. } else if (charCode in baseEncoding &&
  17202. baseEncoding[charCode] !== '') {
  17203. glyphName = baseEncoding[charCode];
  17204. } else {
  17205. glyphName = Encodings.StandardEncoding[charCode];
  17206. }
  17207. if (!glyphName) {
  17208. continue;
  17209. }
  17210. var unicodeOrCharCode, isUnicode = false;
  17211. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  17212. unicodeOrCharCode = GlyphsUnicode[glyphName];
  17213. isUnicode = true;
  17214. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  17215. // TODO: the encoding needs to be updated with mac os table.
  17216. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  17217. }
  17218. var found = false;
  17219. for (i = 0; i < cmapMappingsLength; ++i) {
  17220. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  17221. continue;
  17222. }
  17223. var code = isUnicode ? charCode : unicodeOrCharCode;
  17224. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  17225. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17226. found = true;
  17227. break;
  17228. }
  17229. }
  17230. if (!found && properties.glyphNames) {
  17231. // Try to map using the post table.
  17232. var glyphId = properties.glyphNames.indexOf(glyphName);
  17233. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  17234. charCodeToGlyphId[charCode] = glyphId;
  17235. } else {
  17236. charCodeToGlyphId[charCode] = 0; // notdef
  17237. }
  17238. }
  17239. }
  17240. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  17241. // Default Unicode semantics, use the charcodes as is.
  17242. for (i = 0; i < cmapMappingsLength; ++i) {
  17243. charCodeToGlyphId[cmapMappings[i].charCode] =
  17244. cmapMappings[i].glyphId;
  17245. }
  17246. } else {
  17247. // For (3, 0) cmap tables:
  17248. // The charcode key being stored in charCodeToGlyphId is the lower
  17249. // byte of the two-byte charcodes of the cmap table since according to
  17250. // the spec: 'each byte from the string shall be prepended with the
  17251. // high byte of the range [of charcodes in the cmap table], to form
  17252. // a two-byte character, which shall be used to select the
  17253. // associated glyph description from the subtable'.
  17254. //
  17255. // For (1, 0) cmap tables:
  17256. // 'single bytes from the string shall be used to look up the
  17257. // associated glyph descriptions from the subtable'. This means
  17258. // charcodes in the cmap will be single bytes, so no-op since
  17259. // glyph.charCode & 0xFF === glyph.charCode
  17260. for (i = 0; i < cmapMappingsLength; ++i) {
  17261. charCode = cmapMappings[i].charCode & 0xFF;
  17262. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17263. }
  17264. }
  17265. }
  17266. if (charCodeToGlyphId.length === 0) {
  17267. // defines at least one glyph
  17268. charCodeToGlyphId[0] = 0;
  17269. }
  17270. // Converting glyphs and ids into font's cmap table
  17271. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  17272. this.toFontChar = newMapping.toFontChar;
  17273. tables.cmap = {
  17274. tag: 'cmap',
  17275. data: createCmapTable(newMapping.charCodeToGlyphId)
  17276. };
  17277. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  17278. // extract some more font properties from the OpenType head and
  17279. // hhea tables; yMin and descent value are always negative
  17280. var override = {
  17281. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  17282. yMax: int16(tables.head.data[42], tables.head.data[43]),
  17283. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  17284. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  17285. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  17286. };
  17287. tables['OS/2'] = {
  17288. tag: 'OS/2',
  17289. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  17290. override)
  17291. };
  17292. }
  17293. // Rewrite the 'post' table if needed
  17294. if (!tables.post) {
  17295. tables.post = {
  17296. tag: 'post',
  17297. data: createPostTable(properties)
  17298. };
  17299. }
  17300. if (!isTrueType) {
  17301. try {
  17302. // Trying to repair CFF file
  17303. cffFile = new Stream(tables['CFF '].data);
  17304. var parser = new CFFParser(cffFile, properties);
  17305. cff = parser.parse();
  17306. var compiler = new CFFCompiler(cff);
  17307. tables['CFF '].data = compiler.compile();
  17308. } catch (e) {
  17309. warn('Failed to compile font ' + properties.loadedName);
  17310. }
  17311. }
  17312. // Re-creating 'name' table
  17313. if (!tables.name) {
  17314. tables.name = {
  17315. tag: 'name',
  17316. data: createNameTable(this.name)
  17317. };
  17318. } else {
  17319. // ... using existing 'name' table as prototype
  17320. var namePrototype = readNameTable(tables.name);
  17321. tables.name.data = createNameTable(name, namePrototype);
  17322. }
  17323. var builder = new OpenTypeFileBuilder(header.version);
  17324. for (var tableTag in tables) {
  17325. builder.addTable(tableTag, tables[tableTag].data);
  17326. }
  17327. return builder.toArray();
  17328. },
  17329. convert: function Font_convert(fontName, font, properties) {
  17330. // TODO: Check the charstring widths to determine this.
  17331. properties.fixedPitch = false;
  17332. var mapping = font.getGlyphMapping(properties);
  17333. var newMapping = adjustMapping(mapping, properties);
  17334. this.toFontChar = newMapping.toFontChar;
  17335. var numGlyphs = font.numGlyphs;
  17336. function getCharCodes(charCodeToGlyphId, glyphId) {
  17337. var charCodes = null;
  17338. for (var charCode in charCodeToGlyphId) {
  17339. if (glyphId === charCodeToGlyphId[charCode]) {
  17340. if (!charCodes) {
  17341. charCodes = [];
  17342. }
  17343. charCodes.push(charCode | 0);
  17344. }
  17345. }
  17346. return charCodes;
  17347. }
  17348. function createCharCode(charCodeToGlyphId, glyphId) {
  17349. for (var charCode in charCodeToGlyphId) {
  17350. if (glyphId === charCodeToGlyphId[charCode]) {
  17351. return charCode | 0;
  17352. }
  17353. }
  17354. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  17355. glyphId;
  17356. return newMapping.nextAvailableFontCharCode++;
  17357. }
  17358. var seacs = font.seacs;
  17359. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  17360. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  17361. var charset = font.getCharset();
  17362. var seacMap = Object.create(null);
  17363. for (var glyphId in seacs) {
  17364. glyphId |= 0;
  17365. var seac = seacs[glyphId];
  17366. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  17367. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  17368. var baseGlyphId = charset.indexOf(baseGlyphName);
  17369. var accentGlyphId = charset.indexOf(accentGlyphName);
  17370. if (baseGlyphId < 0 || accentGlyphId < 0) {
  17371. continue;
  17372. }
  17373. var accentOffset = {
  17374. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  17375. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  17376. };
  17377. var charCodes = getCharCodes(mapping, glyphId);
  17378. if (!charCodes) {
  17379. // There's no point in mapping it if the char code was never mapped
  17380. // to begin with.
  17381. continue;
  17382. }
  17383. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  17384. var charCode = charCodes[i];
  17385. // Find a fontCharCode that maps to the base and accent glyphs.
  17386. // If one doesn't exists, create it.
  17387. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  17388. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  17389. baseGlyphId);
  17390. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  17391. accentGlyphId);
  17392. seacMap[charCode] = {
  17393. baseFontCharCode: baseFontCharCode,
  17394. accentFontCharCode: accentFontCharCode,
  17395. accentOffset: accentOffset
  17396. };
  17397. }
  17398. }
  17399. properties.seacMap = seacMap;
  17400. }
  17401. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  17402. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  17403. // PostScript Font Program
  17404. builder.addTable('CFF ', font.data);
  17405. // OS/2 and Windows Specific metrics
  17406. builder.addTable('OS/2', createOS2Table(properties,
  17407. newMapping.charCodeToGlyphId));
  17408. // Character to glyphs mapping
  17409. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  17410. // Font header
  17411. builder.addTable('head',
  17412. '\x00\x01\x00\x00' + // Version number
  17413. '\x00\x00\x10\x00' + // fontRevision
  17414. '\x00\x00\x00\x00' + // checksumAdjustement
  17415. '\x5F\x0F\x3C\xF5' + // magicNumber
  17416. '\x00\x00' + // Flags
  17417. safeString16(unitsPerEm) + // unitsPerEM
  17418. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  17419. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  17420. '\x00\x00' + // xMin
  17421. safeString16(properties.descent) + // yMin
  17422. '\x0F\xFF' + // xMax
  17423. safeString16(properties.ascent) + // yMax
  17424. string16(properties.italicAngle ? 2 : 0) + // macStyle
  17425. '\x00\x11' + // lowestRecPPEM
  17426. '\x00\x00' + // fontDirectionHint
  17427. '\x00\x00' + // indexToLocFormat
  17428. '\x00\x00'); // glyphDataFormat
  17429. // Horizontal header
  17430. builder.addTable('hhea',
  17431. '\x00\x01\x00\x00' + // Version number
  17432. safeString16(properties.ascent) + // Typographic Ascent
  17433. safeString16(properties.descent) + // Typographic Descent
  17434. '\x00\x00' + // Line Gap
  17435. '\xFF\xFF' + // advanceWidthMax
  17436. '\x00\x00' + // minLeftSidebearing
  17437. '\x00\x00' + // minRightSidebearing
  17438. '\x00\x00' + // xMaxExtent
  17439. safeString16(properties.capHeight) + // caretSlopeRise
  17440. safeString16(Math.tan(properties.italicAngle) *
  17441. properties.xHeight) + // caretSlopeRun
  17442. '\x00\x00' + // caretOffset
  17443. '\x00\x00' + // -reserved-
  17444. '\x00\x00' + // -reserved-
  17445. '\x00\x00' + // -reserved-
  17446. '\x00\x00' + // -reserved-
  17447. '\x00\x00' + // metricDataFormat
  17448. string16(numGlyphs)); // Number of HMetrics
  17449. // Horizontal metrics
  17450. builder.addTable('hmtx', (function fontFieldsHmtx() {
  17451. var charstrings = font.charstrings;
  17452. var cffWidths = font.cff ? font.cff.widths : null;
  17453. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  17454. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  17455. var width = 0;
  17456. if (charstrings) {
  17457. var charstring = charstrings[i - 1];
  17458. width = 'width' in charstring ? charstring.width : 0;
  17459. } else if (cffWidths) {
  17460. width = Math.ceil(cffWidths[i] || 0);
  17461. }
  17462. hmtx += string16(width) + string16(0);
  17463. }
  17464. return hmtx;
  17465. })());
  17466. // Maximum profile
  17467. builder.addTable('maxp',
  17468. '\x00\x00\x50\x00' + // Version number
  17469. string16(numGlyphs)); // Num of glyphs
  17470. // Naming tables
  17471. builder.addTable('name', createNameTable(fontName));
  17472. // PostScript informations
  17473. builder.addTable('post', createPostTable(properties));
  17474. return builder.toArray();
  17475. },
  17476. /**
  17477. * Builds a char code to unicode map based on section 9.10 of the spec.
  17478. * @param {Object} properties Font properties object.
  17479. * @return {Object} A ToUnicodeMap object.
  17480. */
  17481. buildToUnicode: function Font_buildToUnicode(properties) {
  17482. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17483. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17484. return properties.toUnicode;
  17485. }
  17486. // According to the spec if the font is a simple font we should only map
  17487. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17488. // the differences array only contains adobe standard or symbol set names,
  17489. // in pratice it seems better to always try to create a toUnicode
  17490. // map based of the default encoding.
  17491. var toUnicode, charcode;
  17492. if (!properties.composite /* is simple font */) {
  17493. toUnicode = [];
  17494. var encoding = properties.defaultEncoding.slice();
  17495. var baseEncodingName = properties.baseEncodingName;
  17496. // Merge in the differences array.
  17497. var differences = properties.differences;
  17498. for (charcode in differences) {
  17499. encoding[charcode] = differences[charcode];
  17500. }
  17501. for (charcode in encoding) {
  17502. // a) Map the character code to a character name.
  17503. var glyphName = encoding[charcode];
  17504. // b) Look up the character name in the Adobe Glyph List (see the
  17505. // Bibliography) to obtain the corresponding Unicode value.
  17506. if (glyphName === '') {
  17507. continue;
  17508. } else if (GlyphsUnicode[glyphName] === undefined) {
  17509. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17510. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17511. var code = 0;
  17512. switch (glyphName[0]) {
  17513. case 'G': // Gxx glyph
  17514. if (glyphName.length === 3) {
  17515. code = parseInt(glyphName.substr(1), 16);
  17516. }
  17517. break;
  17518. case 'g': // g00xx glyph
  17519. if (glyphName.length === 5) {
  17520. code = parseInt(glyphName.substr(1), 16);
  17521. }
  17522. break;
  17523. case 'C': // Cddd glyph
  17524. case 'c': // cddd glyph
  17525. if (glyphName.length >= 3) {
  17526. code = +glyphName.substr(1);
  17527. }
  17528. break;
  17529. }
  17530. if (code) {
  17531. // If |baseEncodingName| is one the predefined encodings,
  17532. // and |code| equals |charcode|, using the glyph defined in the
  17533. // baseEncoding seems to yield a better |toUnicode| mapping
  17534. // (fixes issue 5070).
  17535. if (baseEncodingName && code === +charcode) {
  17536. var baseEncoding = Encodings[baseEncodingName];
  17537. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17538. toUnicode[charcode] =
  17539. String.fromCharCode(GlyphsUnicode[glyphName]);
  17540. continue;
  17541. }
  17542. }
  17543. toUnicode[charcode] = String.fromCharCode(code);
  17544. }
  17545. continue;
  17546. }
  17547. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17548. }
  17549. return new ToUnicodeMap(toUnicode);
  17550. }
  17551. // If the font is a composite font that uses one of the predefined CMaps
  17552. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17553. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17554. // Adobe-Korea1 character collection:
  17555. if (properties.composite && (
  17556. (properties.cMap.builtInCMap &&
  17557. !(properties.cMap instanceof IdentityCMap)) ||
  17558. (properties.cidSystemInfo.registry === 'Adobe' &&
  17559. (properties.cidSystemInfo.ordering === 'GB1' ||
  17560. properties.cidSystemInfo.ordering === 'CNS1' ||
  17561. properties.cidSystemInfo.ordering === 'Japan1' ||
  17562. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17563. // Then:
  17564. // a) Map the character code to a character identifier (CID) according
  17565. // to the font’s CMap.
  17566. // b) Obtain the registry and ordering of the character collection used
  17567. // by the font’s CMap (for example, Adobe and Japan1) from its
  17568. // CIDSystemInfo dictionary.
  17569. var registry = properties.cidSystemInfo.registry;
  17570. var ordering = properties.cidSystemInfo.ordering;
  17571. // c) Construct a second CMap name by concatenating the registry and
  17572. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17573. // (for example, Adobe–Japan1–UCS2).
  17574. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17575. // d) Obtain the CMap with the name constructed in step (c) (available
  17576. // from the ASN Web site; see the Bibliography).
  17577. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17578. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17579. var cMap = properties.cMap;
  17580. toUnicode = [];
  17581. cMap.forEach(function(charcode, cid) {
  17582. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17583. // e) Map the CID obtained in step (a) according to the CMap obtained
  17584. // in step (d), producing a Unicode value.
  17585. var ucs2 = ucs2CMap.lookup(cid);
  17586. if (ucs2) {
  17587. toUnicode[charcode] =
  17588. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17589. ucs2.charCodeAt(1));
  17590. }
  17591. });
  17592. return new ToUnicodeMap(toUnicode);
  17593. }
  17594. // The viewer's choice, just use an identity map.
  17595. return new IdentityToUnicodeMap(properties.firstChar,
  17596. properties.lastChar);
  17597. },
  17598. get spaceWidth() {
  17599. if ('_shadowWidth' in this) {
  17600. return this._shadowWidth;
  17601. }
  17602. // trying to estimate space character width
  17603. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17604. var width;
  17605. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17606. var glyphName = possibleSpaceReplacements[i];
  17607. // if possible, getting width by glyph name
  17608. if (glyphName in this.widths) {
  17609. width = this.widths[glyphName];
  17610. break;
  17611. }
  17612. var glyphUnicode = GlyphsUnicode[glyphName];
  17613. // finding the charcode via unicodeToCID map
  17614. var charcode = 0;
  17615. if (this.composite) {
  17616. if (this.cMap.contains(glyphUnicode)) {
  17617. charcode = this.cMap.lookup(glyphUnicode);
  17618. }
  17619. }
  17620. // ... via toUnicode map
  17621. if (!charcode && 'toUnicode' in this) {
  17622. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17623. }
  17624. // setting it to unicode if negative or undefined
  17625. if (charcode <= 0) {
  17626. charcode = glyphUnicode;
  17627. }
  17628. // trying to get width via charcode
  17629. width = this.widths[charcode];
  17630. if (width) {
  17631. break; // the non-zero width found
  17632. }
  17633. }
  17634. width = width || this.defaultWidth;
  17635. // Do not shadow the property here. See discussion:
  17636. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17637. this._shadowWidth = width;
  17638. return width;
  17639. },
  17640. charToGlyph: function Font_charToGlyph(charcode) {
  17641. var fontCharCode, width, operatorListId;
  17642. var widthCode = charcode;
  17643. if (this.cMap && this.cMap.contains(charcode)) {
  17644. widthCode = this.cMap.lookup(charcode);
  17645. }
  17646. width = this.widths[widthCode];
  17647. width = isNum(width) ? width : this.defaultWidth;
  17648. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17649. var unicode = this.toUnicode.get(charcode) || charcode;
  17650. if (typeof unicode === 'number') {
  17651. unicode = String.fromCharCode(unicode);
  17652. }
  17653. // First try the toFontChar map, if it's not there then try falling
  17654. // back to the char code.
  17655. fontCharCode = this.toFontChar[charcode] || charcode;
  17656. if (this.missingFile) {
  17657. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17658. }
  17659. if (this.isType3Font) {
  17660. // Font char code in this case is actually a glyph name.
  17661. operatorListId = fontCharCode;
  17662. }
  17663. var accent = null;
  17664. if (this.seacMap && this.seacMap[charcode]) {
  17665. var seac = this.seacMap[charcode];
  17666. fontCharCode = seac.baseFontCharCode;
  17667. accent = {
  17668. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17669. offset: seac.accentOffset
  17670. };
  17671. }
  17672. var fontChar = String.fromCharCode(fontCharCode);
  17673. var glyph = this.glyphCache[charcode];
  17674. if (!glyph ||
  17675. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17676. operatorListId)) {
  17677. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17678. operatorListId);
  17679. this.glyphCache[charcode] = glyph;
  17680. }
  17681. return glyph;
  17682. },
  17683. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17684. var charsCache = this.charsCache;
  17685. var glyphs, glyph, charcode;
  17686. // if we translated this string before, just grab it from the cache
  17687. if (charsCache) {
  17688. glyphs = charsCache[chars];
  17689. if (glyphs) {
  17690. return glyphs;
  17691. }
  17692. }
  17693. // lazily create the translation cache
  17694. if (!charsCache) {
  17695. charsCache = this.charsCache = Object.create(null);
  17696. }
  17697. glyphs = [];
  17698. var charsCacheKey = chars;
  17699. var i = 0, ii;
  17700. if (this.cMap) {
  17701. // composite fonts have multi-byte strings convert the string from
  17702. // single-byte to multi-byte
  17703. var c = {};
  17704. while (i < chars.length) {
  17705. this.cMap.readCharCode(chars, i, c);
  17706. charcode = c.charcode;
  17707. var length = c.length;
  17708. i += length;
  17709. glyph = this.charToGlyph(charcode);
  17710. glyphs.push(glyph);
  17711. // placing null after each word break charcode (ASCII SPACE)
  17712. // Ignore occurences of 0x20 in multiple-byte codes.
  17713. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17714. glyphs.push(null);
  17715. }
  17716. }
  17717. } else {
  17718. for (i = 0, ii = chars.length; i < ii; ++i) {
  17719. charcode = chars.charCodeAt(i);
  17720. glyph = this.charToGlyph(charcode);
  17721. glyphs.push(glyph);
  17722. if (charcode === 0x20) {
  17723. glyphs.push(null);
  17724. }
  17725. }
  17726. }
  17727. // Enter the translated string into the cache
  17728. return (charsCache[charsCacheKey] = glyphs);
  17729. }
  17730. };
  17731. return Font;
  17732. })();
  17733. var ErrorFont = (function ErrorFontClosure() {
  17734. function ErrorFont(error) {
  17735. this.error = error;
  17736. this.loadedName = 'g_font_error';
  17737. this.loading = false;
  17738. }
  17739. ErrorFont.prototype = {
  17740. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17741. return [];
  17742. },
  17743. exportData: function ErrorFont_exportData() {
  17744. return {error: this.error};
  17745. }
  17746. };
  17747. return ErrorFont;
  17748. })();
  17749. /**
  17750. * Shared logic for building a char code to glyph id mapping for Type1 and
  17751. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17752. * @param {Object} properties Font properties object.
  17753. * @param {Object} builtInEncoding The encoding contained within the actual font
  17754. * data.
  17755. * @param {Array} Array of glyph names where the index is the glyph ID.
  17756. * @returns {Object} A char code to glyph ID map.
  17757. */
  17758. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17759. var charCodeToGlyphId = Object.create(null);
  17760. var glyphId, charCode, baseEncoding;
  17761. if (properties.baseEncodingName) {
  17762. // If a valid base encoding name was used, the mapping is initialized with
  17763. // that.
  17764. baseEncoding = Encodings[properties.baseEncodingName];
  17765. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17766. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17767. if (glyphId >= 0) {
  17768. charCodeToGlyphId[charCode] = glyphId;
  17769. } else {
  17770. charCodeToGlyphId[charCode] = 0; // notdef
  17771. }
  17772. }
  17773. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17774. // For a symbolic font the encoding should be the fonts built-in
  17775. // encoding.
  17776. for (charCode in builtInEncoding) {
  17777. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17778. }
  17779. } else {
  17780. // For non-symbolic fonts that don't have a base encoding the standard
  17781. // encoding should be used.
  17782. baseEncoding = Encodings.StandardEncoding;
  17783. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17784. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17785. if (glyphId >= 0) {
  17786. charCodeToGlyphId[charCode] = glyphId;
  17787. } else {
  17788. charCodeToGlyphId[charCode] = 0; // notdef
  17789. }
  17790. }
  17791. }
  17792. // Lastly, merge in the differences.
  17793. var differences = properties.differences;
  17794. if (differences) {
  17795. for (charCode in differences) {
  17796. var glyphName = differences[charCode];
  17797. glyphId = glyphNames.indexOf(glyphName);
  17798. if (glyphId >= 0) {
  17799. charCodeToGlyphId[charCode] = glyphId;
  17800. } else {
  17801. charCodeToGlyphId[charCode] = 0; // notdef
  17802. }
  17803. }
  17804. }
  17805. return charCodeToGlyphId;
  17806. }
  17807. /*
  17808. * CharStrings are encoded following the the CharString Encoding sequence
  17809. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17810. * The value in a byte indicates a command, a number, or subsequent bytes
  17811. * that are to be interpreted in a special way.
  17812. *
  17813. * CharString Number Encoding:
  17814. * A CharString byte containing the values from 32 through 255 inclusive
  17815. * indicate an integer. These values are decoded in four ranges.
  17816. *
  17817. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17818. * indicate the integer v - 139. Thus, the integer values from -107 through
  17819. * 107 inclusive may be encoded in single byte.
  17820. *
  17821. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17822. * indicates an integer involving the next byte, w, according to the formula:
  17823. * [(v - 247) x 256] + w + 108
  17824. *
  17825. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17826. * indicates an integer involving the next byte, w, according to the formula:
  17827. * -[(v - 251) * 256] - w - 108
  17828. *
  17829. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17830. * are a two complement signed integer. The first of these bytes contains the
  17831. * highest order bits, the second byte contains the next higher order bits
  17832. * and the fourth byte contain the lowest order bits.
  17833. *
  17834. *
  17835. * CharString Command Encoding:
  17836. * CharStrings commands are encoded in 1 or 2 bytes.
  17837. *
  17838. * Single byte commands are encoded in 1 byte that contains a value between
  17839. * 0 and 31 inclusive.
  17840. * If a command byte contains the value 12, then the value in the next byte
  17841. * indicates a command. This "escape" mechanism allows many extra commands
  17842. * to be encoded and this encoding technique helps to minimize the length of
  17843. * the charStrings.
  17844. */
  17845. var Type1CharString = (function Type1CharStringClosure() {
  17846. var COMMAND_MAP = {
  17847. 'hstem': [1],
  17848. 'vstem': [3],
  17849. 'vmoveto': [4],
  17850. 'rlineto': [5],
  17851. 'hlineto': [6],
  17852. 'vlineto': [7],
  17853. 'rrcurveto': [8],
  17854. 'callsubr': [10],
  17855. 'flex': [12, 35],
  17856. 'drop' : [12, 18],
  17857. 'endchar': [14],
  17858. 'rmoveto': [21],
  17859. 'hmoveto': [22],
  17860. 'vhcurveto': [30],
  17861. 'hvcurveto': [31]
  17862. };
  17863. function Type1CharString() {
  17864. this.width = 0;
  17865. this.lsb = 0;
  17866. this.flexing = false;
  17867. this.output = [];
  17868. this.stack = [];
  17869. }
  17870. Type1CharString.prototype = {
  17871. convert: function Type1CharString_convert(encoded, subrs) {
  17872. var count = encoded.length;
  17873. var error = false;
  17874. var wx, sbx, subrNumber;
  17875. for (var i = 0; i < count; i++) {
  17876. var value = encoded[i];
  17877. if (value < 32) {
  17878. if (value === 12) {
  17879. value = (value << 8) + encoded[++i];
  17880. }
  17881. switch (value) {
  17882. case 1: // hstem
  17883. if (!HINTING_ENABLED) {
  17884. this.stack = [];
  17885. break;
  17886. }
  17887. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17888. break;
  17889. case 3: // vstem
  17890. if (!HINTING_ENABLED) {
  17891. this.stack = [];
  17892. break;
  17893. }
  17894. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17895. break;
  17896. case 4: // vmoveto
  17897. if (this.flexing) {
  17898. if (this.stack.length < 1) {
  17899. error = true;
  17900. break;
  17901. }
  17902. // Add the dx for flex and but also swap the values so they are
  17903. // the right order.
  17904. var dy = this.stack.pop();
  17905. this.stack.push(0, dy);
  17906. break;
  17907. }
  17908. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17909. break;
  17910. case 5: // rlineto
  17911. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17912. break;
  17913. case 6: // hlineto
  17914. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17915. break;
  17916. case 7: // vlineto
  17917. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17918. break;
  17919. case 8: // rrcurveto
  17920. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17921. break;
  17922. case 9: // closepath
  17923. // closepath is a Type1 command that does not take argument and is
  17924. // useless in Type2 and it can simply be ignored.
  17925. this.stack = [];
  17926. break;
  17927. case 10: // callsubr
  17928. if (this.stack.length < 1) {
  17929. error = true;
  17930. break;
  17931. }
  17932. subrNumber = this.stack.pop();
  17933. error = this.convert(subrs[subrNumber], subrs);
  17934. break;
  17935. case 11: // return
  17936. return error;
  17937. case 13: // hsbw
  17938. if (this.stack.length < 2) {
  17939. error = true;
  17940. break;
  17941. }
  17942. // To convert to type2 we have to move the width value to the
  17943. // first part of the charstring and then use hmoveto with lsb.
  17944. wx = this.stack.pop();
  17945. sbx = this.stack.pop();
  17946. this.lsb = sbx;
  17947. this.width = wx;
  17948. this.stack.push(wx, sbx);
  17949. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17950. break;
  17951. case 14: // endchar
  17952. this.output.push(COMMAND_MAP.endchar[0]);
  17953. break;
  17954. case 21: // rmoveto
  17955. if (this.flexing) {
  17956. break;
  17957. }
  17958. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17959. break;
  17960. case 22: // hmoveto
  17961. if (this.flexing) {
  17962. // Add the dy for flex.
  17963. this.stack.push(0);
  17964. break;
  17965. }
  17966. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17967. break;
  17968. case 30: // vhcurveto
  17969. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17970. break;
  17971. case 31: // hvcurveto
  17972. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17973. break;
  17974. case (12 << 8) + 0: // dotsection
  17975. // dotsection is a Type1 command to specify some hinting feature
  17976. // for dots that do not take a parameter and it can safely be
  17977. // ignored for Type2.
  17978. this.stack = [];
  17979. break;
  17980. case (12 << 8) + 1: // vstem3
  17981. if (!HINTING_ENABLED) {
  17982. this.stack = [];
  17983. break;
  17984. }
  17985. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17986. // multiple parameters, so instead of returning [vh]stem3 take a
  17987. // shortcut and return [vhstem] instead.
  17988. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17989. break;
  17990. case (12 << 8) + 2: // hstem3
  17991. if (!HINTING_ENABLED) {
  17992. this.stack = [];
  17993. break;
  17994. }
  17995. // See vstem3.
  17996. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17997. break;
  17998. case (12 << 8) + 6: // seac
  17999. // seac is like type 2's special endchar but it doesn't use the
  18000. // first argument asb, so remove it.
  18001. if (SEAC_ANALYSIS_ENABLED) {
  18002. this.seac = this.stack.splice(-4, 4);
  18003. error = this.executeCommand(0, COMMAND_MAP.endchar);
  18004. } else {
  18005. error = this.executeCommand(4, COMMAND_MAP.endchar);
  18006. }
  18007. break;
  18008. case (12 << 8) + 7: // sbw
  18009. if (this.stack.length < 4) {
  18010. error = true;
  18011. break;
  18012. }
  18013. // To convert to type2 we have to move the width value to the
  18014. // first part of the charstring and then use rmoveto with
  18015. // (dx, dy). The height argument will not be used for vmtx and
  18016. // vhea tables reconstruction -- ignoring it.
  18017. var wy = this.stack.pop();
  18018. wx = this.stack.pop();
  18019. var sby = this.stack.pop();
  18020. sbx = this.stack.pop();
  18021. this.lsb = sbx;
  18022. this.width = wx;
  18023. this.stack.push(wx, sbx, sby);
  18024. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  18025. break;
  18026. case (12 << 8) + 12: // div
  18027. if (this.stack.length < 2) {
  18028. error = true;
  18029. break;
  18030. }
  18031. var num2 = this.stack.pop();
  18032. var num1 = this.stack.pop();
  18033. this.stack.push(num1 / num2);
  18034. break;
  18035. case (12 << 8) + 16: // callothersubr
  18036. if (this.stack.length < 2) {
  18037. error = true;
  18038. break;
  18039. }
  18040. subrNumber = this.stack.pop();
  18041. var numArgs = this.stack.pop();
  18042. if (subrNumber === 0 && numArgs === 3) {
  18043. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  18044. this.stack.push(
  18045. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  18046. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  18047. flexArgs[4], // bcp2x
  18048. flexArgs[5], // bcp2y
  18049. flexArgs[6], // p2x
  18050. flexArgs[7], // p2y
  18051. flexArgs[8], // bcp3x
  18052. flexArgs[9], // bcp3y
  18053. flexArgs[10], // bcp4x
  18054. flexArgs[11], // bcp4y
  18055. flexArgs[12], // p3x
  18056. flexArgs[13], // p3y
  18057. flexArgs[14] // flexDepth
  18058. // 15 = finalx unused by flex
  18059. // 16 = finaly unused by flex
  18060. );
  18061. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  18062. this.flexing = false;
  18063. this.stack.push(flexArgs[15], flexArgs[16]);
  18064. } else if (subrNumber === 1 && numArgs === 0) {
  18065. this.flexing = true;
  18066. }
  18067. break;
  18068. case (12 << 8) + 17: // pop
  18069. // Ignore this since it is only used with othersubr.
  18070. break;
  18071. case (12 << 8) + 33: // setcurrentpoint
  18072. // Ignore for now.
  18073. this.stack = [];
  18074. break;
  18075. default:
  18076. warn('Unknown type 1 charstring command of "' + value + '"');
  18077. break;
  18078. }
  18079. if (error) {
  18080. break;
  18081. }
  18082. continue;
  18083. } else if (value <= 246) {
  18084. value = value - 139;
  18085. } else if (value <= 250) {
  18086. value = ((value - 247) * 256) + encoded[++i] + 108;
  18087. } else if (value <= 254) {
  18088. value = -((value - 251) * 256) - encoded[++i] - 108;
  18089. } else {
  18090. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  18091. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  18092. }
  18093. this.stack.push(value);
  18094. }
  18095. return error;
  18096. },
  18097. executeCommand: function(howManyArgs, command, keepStack) {
  18098. var stackLength = this.stack.length;
  18099. if (howManyArgs > stackLength) {
  18100. return true;
  18101. }
  18102. var start = stackLength - howManyArgs;
  18103. for (var i = start; i < stackLength; i++) {
  18104. var value = this.stack[i];
  18105. if (value === (value | 0)) { // int
  18106. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  18107. } else { // fixed point
  18108. value = (65536 * value) | 0;
  18109. this.output.push(255,
  18110. (value >> 24) & 0xFF,
  18111. (value >> 16) & 0xFF,
  18112. (value >> 8) & 0xFF,
  18113. value & 0xFF);
  18114. }
  18115. }
  18116. this.output.push.apply(this.output, command);
  18117. if (keepStack) {
  18118. this.stack.splice(start, howManyArgs);
  18119. } else {
  18120. this.stack.length = 0;
  18121. }
  18122. return false;
  18123. }
  18124. };
  18125. return Type1CharString;
  18126. })();
  18127. /*
  18128. * Type1Parser encapsulate the needed code for parsing a Type1 font
  18129. * program. Some of its logic depends on the Type2 charstrings
  18130. * structure.
  18131. * Note: this doesn't really parse the font since that would require evaluation
  18132. * of PostScript, but it is possible in most cases to extract what we need
  18133. * without a full parse.
  18134. */
  18135. var Type1Parser = (function Type1ParserClosure() {
  18136. /*
  18137. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  18138. * of Plaintext Bytes. The function took a key as a parameter which can be
  18139. * for decrypting the eexec block of for decoding charStrings.
  18140. */
  18141. var EEXEC_ENCRYPT_KEY = 55665;
  18142. var CHAR_STRS_ENCRYPT_KEY = 4330;
  18143. function isHexDigit(code) {
  18144. return code >= 48 && code <= 57 || // '0'-'9'
  18145. code >= 65 && code <= 70 || // 'A'-'F'
  18146. code >= 97 && code <= 102; // 'a'-'f'
  18147. }
  18148. function decrypt(data, key, discardNumber) {
  18149. var r = key | 0, c1 = 52845, c2 = 22719;
  18150. var count = data.length;
  18151. var decrypted = new Uint8Array(count);
  18152. for (var i = 0; i < count; i++) {
  18153. var value = data[i];
  18154. decrypted[i] = value ^ (r >> 8);
  18155. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18156. }
  18157. return Array.prototype.slice.call(decrypted, discardNumber);
  18158. }
  18159. function decryptAscii(data, key, discardNumber) {
  18160. var r = key | 0, c1 = 52845, c2 = 22719;
  18161. var count = data.length, maybeLength = count >>> 1;
  18162. var decrypted = new Uint8Array(maybeLength);
  18163. var i, j;
  18164. for (i = 0, j = 0; i < count; i++) {
  18165. var digit1 = data[i];
  18166. if (!isHexDigit(digit1)) {
  18167. continue;
  18168. }
  18169. i++;
  18170. var digit2;
  18171. while (i < count && !isHexDigit(digit2 = data[i])) {
  18172. i++;
  18173. }
  18174. if (i < count) {
  18175. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  18176. decrypted[j++] = value ^ (r >> 8);
  18177. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18178. }
  18179. }
  18180. return Array.prototype.slice.call(decrypted, discardNumber, j);
  18181. }
  18182. function isSpecial(c) {
  18183. return c === 0x2F || // '/'
  18184. c === 0x5B || c === 0x5D || // '[', ']'
  18185. c === 0x7B || c === 0x7D || // '{', '}'
  18186. c === 0x28 || c === 0x29; // '(', ')'
  18187. }
  18188. function Type1Parser(stream, encrypted) {
  18189. if (encrypted) {
  18190. var data = stream.getBytes();
  18191. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  18192. isHexDigit(data[2]) && isHexDigit(data[3]));
  18193. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  18194. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  18195. }
  18196. this.stream = stream;
  18197. this.nextChar();
  18198. }
  18199. Type1Parser.prototype = {
  18200. readNumberArray: function Type1Parser_readNumberArray() {
  18201. this.getToken(); // read '[' or '{' (arrays can start with either)
  18202. var array = [];
  18203. while (true) {
  18204. var token = this.getToken();
  18205. if (token === null || token === ']' || token === '}') {
  18206. break;
  18207. }
  18208. array.push(parseFloat(token || 0));
  18209. }
  18210. return array;
  18211. },
  18212. readNumber: function Type1Parser_readNumber() {
  18213. var token = this.getToken();
  18214. return parseFloat(token || 0);
  18215. },
  18216. readInt: function Type1Parser_readInt() {
  18217. // Use '| 0' to prevent setting a double into length such as the double
  18218. // does not flow into the loop variable.
  18219. var token = this.getToken();
  18220. return parseInt(token || 0, 10) | 0;
  18221. },
  18222. readBoolean: function Type1Parser_readBoolean() {
  18223. var token = this.getToken();
  18224. // Use 1 and 0 since that's what type2 charstrings use.
  18225. return token === 'true' ? 1 : 0;
  18226. },
  18227. nextChar : function Type1_nextChar() {
  18228. return (this.currentChar = this.stream.getByte());
  18229. },
  18230. getToken: function Type1Parser_getToken() {
  18231. // Eat whitespace and comments.
  18232. var comment = false;
  18233. var ch = this.currentChar;
  18234. while (true) {
  18235. if (ch === -1) {
  18236. return null;
  18237. }
  18238. if (comment) {
  18239. if (ch === 0x0A || ch === 0x0D) {
  18240. comment = false;
  18241. }
  18242. } else if (ch === 0x25) { // '%'
  18243. comment = true;
  18244. } else if (!Lexer.isSpace(ch)) {
  18245. break;
  18246. }
  18247. ch = this.nextChar();
  18248. }
  18249. if (isSpecial(ch)) {
  18250. this.nextChar();
  18251. return String.fromCharCode(ch);
  18252. }
  18253. var token = '';
  18254. do {
  18255. token += String.fromCharCode(ch);
  18256. ch = this.nextChar();
  18257. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  18258. return token;
  18259. },
  18260. /*
  18261. * Returns an object containing a Subrs array and a CharStrings
  18262. * array extracted from and eexec encrypted block of data
  18263. */
  18264. extractFontProgram: function Type1Parser_extractFontProgram() {
  18265. var stream = this.stream;
  18266. var subrs = [], charstrings = [];
  18267. var program = {
  18268. subrs: [],
  18269. charstrings: [],
  18270. properties: {
  18271. 'privateData': {
  18272. 'lenIV': 4
  18273. }
  18274. }
  18275. };
  18276. var token, length, data, lenIV, encoded;
  18277. while ((token = this.getToken()) !== null) {
  18278. if (token !== '/') {
  18279. continue;
  18280. }
  18281. token = this.getToken();
  18282. switch (token) {
  18283. case 'CharStrings':
  18284. // The number immediately following CharStrings must be greater or
  18285. // equal to the number of CharStrings.
  18286. this.getToken();
  18287. this.getToken(); // read in 'dict'
  18288. this.getToken(); // read in 'dup'
  18289. this.getToken(); // read in 'begin'
  18290. while(true) {
  18291. token = this.getToken();
  18292. if (token === null || token === 'end') {
  18293. break;
  18294. }
  18295. if (token !== '/') {
  18296. continue;
  18297. }
  18298. var glyph = this.getToken();
  18299. length = this.readInt();
  18300. this.getToken(); // read in 'RD' or '-|'
  18301. data = stream.makeSubStream(stream.pos, length);
  18302. lenIV = program.properties.privateData['lenIV'];
  18303. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18304. // Skip past the required space and binary data.
  18305. stream.skip(length);
  18306. this.nextChar();
  18307. token = this.getToken(); // read in 'ND' or '|-'
  18308. if (token === 'noaccess') {
  18309. this.getToken(); // read in 'def'
  18310. }
  18311. charstrings.push({
  18312. glyph: glyph,
  18313. encoded: encoded
  18314. });
  18315. }
  18316. break;
  18317. case 'Subrs':
  18318. var num = this.readInt();
  18319. this.getToken(); // read in 'array'
  18320. while ((token = this.getToken()) === 'dup') {
  18321. var index = this.readInt();
  18322. length = this.readInt();
  18323. this.getToken(); // read in 'RD' or '-|'
  18324. data = stream.makeSubStream(stream.pos, length);
  18325. lenIV = program.properties.privateData['lenIV'];
  18326. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18327. // Skip past the required space and binary data.
  18328. stream.skip(length);
  18329. this.nextChar();
  18330. token = this.getToken(); // read in 'NP' or '|'
  18331. if (token === 'noaccess') {
  18332. this.getToken(); // read in 'put'
  18333. }
  18334. subrs[index] = encoded;
  18335. }
  18336. break;
  18337. case 'BlueValues':
  18338. case 'OtherBlues':
  18339. case 'FamilyBlues':
  18340. case 'FamilyOtherBlues':
  18341. var blueArray = this.readNumberArray();
  18342. // *Blue* values may contain invalid data: disables reading of
  18343. // those values when hinting is disabled.
  18344. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  18345. HINTING_ENABLED) {
  18346. program.properties.privateData[token] = blueArray;
  18347. }
  18348. break;
  18349. case 'StemSnapH':
  18350. case 'StemSnapV':
  18351. program.properties.privateData[token] = this.readNumberArray();
  18352. break;
  18353. case 'StdHW':
  18354. case 'StdVW':
  18355. program.properties.privateData[token] =
  18356. this.readNumberArray()[0];
  18357. break;
  18358. case 'BlueShift':
  18359. case 'lenIV':
  18360. case 'BlueFuzz':
  18361. case 'BlueScale':
  18362. case 'LanguageGroup':
  18363. case 'ExpansionFactor':
  18364. program.properties.privateData[token] = this.readNumber();
  18365. break;
  18366. case 'ForceBold':
  18367. program.properties.privateData[token] = this.readBoolean();
  18368. break;
  18369. }
  18370. }
  18371. for (var i = 0; i < charstrings.length; i++) {
  18372. glyph = charstrings[i].glyph;
  18373. encoded = charstrings[i].encoded;
  18374. var charString = new Type1CharString();
  18375. var error = charString.convert(encoded, subrs);
  18376. var output = charString.output;
  18377. if (error) {
  18378. // It seems when FreeType encounters an error while evaluating a glyph
  18379. // that it completely ignores the glyph so we'll mimic that behaviour
  18380. // here and put an endchar to make the validator happy.
  18381. output = [14];
  18382. }
  18383. program.charstrings.push({
  18384. glyphName: glyph,
  18385. charstring: output,
  18386. width: charString.width,
  18387. lsb: charString.lsb,
  18388. seac: charString.seac
  18389. });
  18390. }
  18391. return program;
  18392. },
  18393. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  18394. var token;
  18395. while ((token = this.getToken()) !== null) {
  18396. if (token !== '/') {
  18397. continue;
  18398. }
  18399. token = this.getToken();
  18400. switch (token) {
  18401. case 'FontMatrix':
  18402. var matrix = this.readNumberArray();
  18403. properties.fontMatrix = matrix;
  18404. break;
  18405. case 'Encoding':
  18406. var encodingArg = this.getToken();
  18407. var encoding;
  18408. if (!/^\d+$/.test(encodingArg)) {
  18409. // encoding name is specified
  18410. encoding = Encodings[encodingArg];
  18411. } else {
  18412. encoding = [];
  18413. var size = parseInt(encodingArg, 10) | 0;
  18414. this.getToken(); // read in 'array'
  18415. for (var j = 0; j < size; j++) {
  18416. token = this.getToken();
  18417. // skipping till first dup or def (e.g. ignoring for statement)
  18418. while (token !== 'dup' && token !== 'def') {
  18419. token = this.getToken();
  18420. if (token === null) {
  18421. return; // invalid header
  18422. }
  18423. }
  18424. if (token === 'def') {
  18425. break; // read all array data
  18426. }
  18427. var index = this.readInt();
  18428. this.getToken(); // read in '/'
  18429. var glyph = this.getToken();
  18430. encoding[index] = glyph;
  18431. this.getToken(); // read the in 'put'
  18432. }
  18433. }
  18434. properties.builtInEncoding = encoding;
  18435. break;
  18436. case 'FontBBox':
  18437. var fontBBox = this.readNumberArray();
  18438. // adjusting ascent/descent
  18439. properties.ascent = fontBBox[3];
  18440. properties.descent = fontBBox[1];
  18441. properties.ascentScaled = true;
  18442. break;
  18443. }
  18444. }
  18445. }
  18446. };
  18447. return Type1Parser;
  18448. })();
  18449. /**
  18450. * The CFF class takes a Type1 file and wrap it into a
  18451. * 'Compact Font Format' which itself embed Type2 charstrings.
  18452. */
  18453. var CFFStandardStrings = [
  18454. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18455. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18456. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18457. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18458. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18459. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18460. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18461. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18462. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18463. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18464. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18465. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18466. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18467. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18468. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18469. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18470. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18471. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18472. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18473. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18474. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18475. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18476. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18477. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18478. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18479. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18480. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18481. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18482. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18483. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18484. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18485. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18486. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18487. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18488. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18489. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18490. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18491. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18492. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18493. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18494. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18495. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18496. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18497. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18498. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18499. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18500. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18501. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18502. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18503. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18504. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18505. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18506. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18507. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18508. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18509. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18510. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18511. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18512. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18513. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18514. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18515. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18516. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18517. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18518. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18519. ];
  18520. // Type1Font is also a CIDFontType0.
  18521. var Type1Font = function Type1Font(name, file, properties) {
  18522. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18523. // Also, length1 and length2 might be off by 6 bytes as well.
  18524. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18525. var PFB_HEADER_SIZE = 6;
  18526. var headerBlockLength = properties.length1;
  18527. var eexecBlockLength = properties.length2;
  18528. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18529. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18530. if (pfbHeaderPresent) {
  18531. file.skip(PFB_HEADER_SIZE);
  18532. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18533. (pfbHeader[3] << 8) | pfbHeader[2];
  18534. }
  18535. // Get the data block containing glyphs and subrs informations
  18536. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18537. var headerBlockParser = new Type1Parser(headerBlock);
  18538. headerBlockParser.extractFontHeader(properties);
  18539. if (pfbHeaderPresent) {
  18540. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18541. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18542. (pfbHeader[3] << 8) | pfbHeader[2];
  18543. }
  18544. // Decrypt the data blocks and retrieve it's content
  18545. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18546. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18547. var data = eexecBlockParser.extractFontProgram();
  18548. for (var info in data.properties) {
  18549. properties[info] = data.properties[info];
  18550. }
  18551. var charstrings = data.charstrings;
  18552. var type2Charstrings = this.getType2Charstrings(charstrings);
  18553. var subrs = this.getType2Subrs(data.subrs);
  18554. this.charstrings = charstrings;
  18555. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18556. subrs, properties);
  18557. this.seacs = this.getSeacs(data.charstrings);
  18558. };
  18559. Type1Font.prototype = {
  18560. get numGlyphs() {
  18561. return this.charstrings.length + 1;
  18562. },
  18563. getCharset: function Type1Font_getCharset() {
  18564. var charset = ['.notdef'];
  18565. var charstrings = this.charstrings;
  18566. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18567. charset.push(charstrings[glyphId].glyphName);
  18568. }
  18569. return charset;
  18570. },
  18571. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18572. var charstrings = this.charstrings;
  18573. var glyphNames = ['.notdef'], glyphId;
  18574. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18575. glyphNames.push(charstrings[glyphId].glyphName);
  18576. }
  18577. var encoding = properties.builtInEncoding;
  18578. if (encoding) {
  18579. var builtInEncoding = {};
  18580. for (var charCode in encoding) {
  18581. glyphId = glyphNames.indexOf(encoding[charCode]);
  18582. if (glyphId >= 0) {
  18583. builtInEncoding[charCode] = glyphId;
  18584. }
  18585. }
  18586. }
  18587. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18588. },
  18589. getSeacs: function Type1Font_getSeacs(charstrings) {
  18590. var i, ii;
  18591. var seacMap = [];
  18592. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18593. var charstring = charstrings[i];
  18594. if (charstring.seac) {
  18595. // Offset by 1 for .notdef
  18596. seacMap[i + 1] = charstring.seac;
  18597. }
  18598. }
  18599. return seacMap;
  18600. },
  18601. getType2Charstrings: function Type1Font_getType2Charstrings(
  18602. type1Charstrings) {
  18603. var type2Charstrings = [];
  18604. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18605. type2Charstrings.push(type1Charstrings[i].charstring);
  18606. }
  18607. return type2Charstrings;
  18608. },
  18609. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18610. var bias = 0;
  18611. var count = type1Subrs.length;
  18612. if (count < 1133) {
  18613. bias = 107;
  18614. } else if (count < 33769) {
  18615. bias = 1131;
  18616. } else {
  18617. bias = 32768;
  18618. }
  18619. // Add a bunch of empty subrs to deal with the Type2 bias
  18620. var type2Subrs = [];
  18621. var i;
  18622. for (i = 0; i < bias; i++) {
  18623. type2Subrs.push([0x0B]);
  18624. }
  18625. for (i = 0; i < count; i++) {
  18626. type2Subrs.push(type1Subrs[i]);
  18627. }
  18628. return type2Subrs;
  18629. },
  18630. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18631. var cff = new CFF();
  18632. cff.header = new CFFHeader(1, 0, 4, 4);
  18633. cff.names = [name];
  18634. var topDict = new CFFTopDict();
  18635. // CFF strings IDs 0...390 are predefined names, so refering
  18636. // to entries in our own String INDEX starts at SID 391.
  18637. topDict.setByName('version', 391);
  18638. topDict.setByName('Notice', 392);
  18639. topDict.setByName('FullName', 393);
  18640. topDict.setByName('FamilyName', 394);
  18641. topDict.setByName('Weight', 395);
  18642. topDict.setByName('Encoding', null); // placeholder
  18643. topDict.setByName('FontMatrix', properties.fontMatrix);
  18644. topDict.setByName('FontBBox', properties.bbox);
  18645. topDict.setByName('charset', null); // placeholder
  18646. topDict.setByName('CharStrings', null); // placeholder
  18647. topDict.setByName('Private', null); // placeholder
  18648. cff.topDict = topDict;
  18649. var strings = new CFFStrings();
  18650. strings.add('Version 0.11'); // Version
  18651. strings.add('See original notice'); // Notice
  18652. strings.add(name); // FullName
  18653. strings.add(name); // FamilyName
  18654. strings.add('Medium'); // Weight
  18655. cff.strings = strings;
  18656. cff.globalSubrIndex = new CFFIndex();
  18657. var count = glyphs.length;
  18658. var charsetArray = [0];
  18659. var i, ii;
  18660. for (i = 0; i < count; i++) {
  18661. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18662. // TODO: Insert the string and correctly map it. Previously it was
  18663. // thought mapping names that aren't in the standard strings to .notdef
  18664. // was fine, however in issue818 when mapping them all to .notdef the
  18665. // adieresis glyph no longer worked.
  18666. if (index === -1) {
  18667. index = 0;
  18668. }
  18669. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18670. }
  18671. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18672. var charStringsIndex = new CFFIndex();
  18673. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18674. for (i = 0; i < count; i++) {
  18675. charStringsIndex.add(glyphs[i]);
  18676. }
  18677. cff.charStrings = charStringsIndex;
  18678. var privateDict = new CFFPrivateDict();
  18679. privateDict.setByName('Subrs', null); // placeholder
  18680. var fields = [
  18681. 'BlueValues',
  18682. 'OtherBlues',
  18683. 'FamilyBlues',
  18684. 'FamilyOtherBlues',
  18685. 'StemSnapH',
  18686. 'StemSnapV',
  18687. 'BlueShift',
  18688. 'BlueFuzz',
  18689. 'BlueScale',
  18690. 'LanguageGroup',
  18691. 'ExpansionFactor',
  18692. 'ForceBold',
  18693. 'StdHW',
  18694. 'StdVW'
  18695. ];
  18696. for (i = 0, ii = fields.length; i < ii; i++) {
  18697. var field = fields[i];
  18698. if (!properties.privateData.hasOwnProperty(field)) {
  18699. continue;
  18700. }
  18701. var value = properties.privateData[field];
  18702. if (isArray(value)) {
  18703. // All of the private dictionary array data in CFF must be stored as
  18704. // "delta-encoded" numbers.
  18705. for (var j = value.length - 1; j > 0; j--) {
  18706. value[j] -= value[j - 1]; // ... difference from previous value
  18707. }
  18708. }
  18709. privateDict.setByName(field, value);
  18710. }
  18711. cff.topDict.privateDict = privateDict;
  18712. var subrIndex = new CFFIndex();
  18713. for (i = 0, ii = subrs.length; i < ii; i++) {
  18714. subrIndex.add(subrs[i]);
  18715. }
  18716. privateDict.subrsIndex = subrIndex;
  18717. var compiler = new CFFCompiler(cff);
  18718. return compiler.compile();
  18719. }
  18720. };
  18721. var CFFFont = (function CFFFontClosure() {
  18722. function CFFFont(file, properties) {
  18723. this.properties = properties;
  18724. var parser = new CFFParser(file, properties);
  18725. this.cff = parser.parse();
  18726. var compiler = new CFFCompiler(this.cff);
  18727. this.seacs = this.cff.seacs;
  18728. try {
  18729. this.data = compiler.compile();
  18730. } catch (e) {
  18731. warn('Failed to compile font ' + properties.loadedName);
  18732. // There may have just been an issue with the compiler, set the data
  18733. // anyway and hope the font loaded.
  18734. this.data = file;
  18735. }
  18736. }
  18737. CFFFont.prototype = {
  18738. get numGlyphs() {
  18739. return this.cff.charStrings.count;
  18740. },
  18741. getCharset: function CFFFont_getCharset() {
  18742. return this.cff.charset.charset;
  18743. },
  18744. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18745. var cff = this.cff;
  18746. var properties = this.properties;
  18747. var charsets = cff.charset.charset;
  18748. var charCodeToGlyphId;
  18749. var glyphId;
  18750. if (properties.composite) {
  18751. charCodeToGlyphId = Object.create(null);
  18752. if (cff.isCIDFont) {
  18753. // If the font is actually a CID font then we should use the charset
  18754. // to map CIDs to GIDs.
  18755. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18756. var cid = charsets[glyphId];
  18757. var charCode = properties.cMap.charCodeOf(cid);
  18758. charCodeToGlyphId[charCode] = glyphId;
  18759. }
  18760. } else {
  18761. // If it is NOT actually a CID font then CIDs should be mapped
  18762. // directly to GIDs.
  18763. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18764. charCodeToGlyphId[glyphId] = glyphId;
  18765. }
  18766. }
  18767. return charCodeToGlyphId;
  18768. }
  18769. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18770. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18771. return charCodeToGlyphId;
  18772. }
  18773. };
  18774. return CFFFont;
  18775. })();
  18776. var CFFParser = (function CFFParserClosure() {
  18777. var CharstringValidationData = [
  18778. null,
  18779. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18780. null,
  18781. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18782. { id: 'vmoveto', min: 1, stackClearing: true },
  18783. { id: 'rlineto', min: 2, resetStack: true },
  18784. { id: 'hlineto', min: 1, resetStack: true },
  18785. { id: 'vlineto', min: 1, resetStack: true },
  18786. { id: 'rrcurveto', min: 6, resetStack: true },
  18787. null,
  18788. { id: 'callsubr', min: 1, undefStack: true },
  18789. { id: 'return', min: 0, undefStack: true },
  18790. null, // 12
  18791. null,
  18792. { id: 'endchar', min: 0, stackClearing: true },
  18793. null,
  18794. null,
  18795. null,
  18796. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18797. { id: 'hintmask', min: 0, stackClearing: true },
  18798. { id: 'cntrmask', min: 0, stackClearing: true },
  18799. { id: 'rmoveto', min: 2, stackClearing: true },
  18800. { id: 'hmoveto', min: 1, stackClearing: true },
  18801. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18802. { id: 'rcurveline', min: 8, resetStack: true },
  18803. { id: 'rlinecurve', min: 8, resetStack: true },
  18804. { id: 'vvcurveto', min: 4, resetStack: true },
  18805. { id: 'hhcurveto', min: 4, resetStack: true },
  18806. null, // shortint
  18807. { id: 'callgsubr', min: 1, undefStack: true },
  18808. { id: 'vhcurveto', min: 4, resetStack: true },
  18809. { id: 'hvcurveto', min: 4, resetStack: true }
  18810. ];
  18811. var CharstringValidationData12 = [
  18812. null,
  18813. null,
  18814. null,
  18815. { id: 'and', min: 2, stackDelta: -1 },
  18816. { id: 'or', min: 2, stackDelta: -1 },
  18817. { id: 'not', min: 1, stackDelta: 0 },
  18818. null,
  18819. null,
  18820. null,
  18821. { id: 'abs', min: 1, stackDelta: 0 },
  18822. { id: 'add', min: 2, stackDelta: -1,
  18823. stackFn: function stack_div(stack, index) {
  18824. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18825. }
  18826. },
  18827. { id: 'sub', min: 2, stackDelta: -1,
  18828. stackFn: function stack_div(stack, index) {
  18829. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18830. }
  18831. },
  18832. { id: 'div', min: 2, stackDelta: -1,
  18833. stackFn: function stack_div(stack, index) {
  18834. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18835. }
  18836. },
  18837. null,
  18838. { id: 'neg', min: 1, stackDelta: 0,
  18839. stackFn: function stack_div(stack, index) {
  18840. stack[index - 1] = -stack[index - 1];
  18841. }
  18842. },
  18843. { id: 'eq', min: 2, stackDelta: -1 },
  18844. null,
  18845. null,
  18846. { id: 'drop', min: 1, stackDelta: -1 },
  18847. null,
  18848. { id: 'put', min: 2, stackDelta: -2 },
  18849. { id: 'get', min: 1, stackDelta: 0 },
  18850. { id: 'ifelse', min: 4, stackDelta: -3 },
  18851. { id: 'random', min: 0, stackDelta: 1 },
  18852. { id: 'mul', min: 2, stackDelta: -1,
  18853. stackFn: function stack_div(stack, index) {
  18854. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18855. }
  18856. },
  18857. null,
  18858. { id: 'sqrt', min: 1, stackDelta: 0 },
  18859. { id: 'dup', min: 1, stackDelta: 1 },
  18860. { id: 'exch', min: 2, stackDelta: 0 },
  18861. { id: 'index', min: 2, stackDelta: 0 },
  18862. { id: 'roll', min: 3, stackDelta: -2 },
  18863. null,
  18864. null,
  18865. null,
  18866. { id: 'hflex', min: 7, resetStack: true },
  18867. { id: 'flex', min: 13, resetStack: true },
  18868. { id: 'hflex1', min: 9, resetStack: true },
  18869. { id: 'flex1', min: 11, resetStack: true }
  18870. ];
  18871. function CFFParser(file, properties) {
  18872. this.bytes = file.getBytes();
  18873. this.properties = properties;
  18874. }
  18875. CFFParser.prototype = {
  18876. parse: function CFFParser_parse() {
  18877. var properties = this.properties;
  18878. var cff = new CFF();
  18879. this.cff = cff;
  18880. // The first five sections must be in order, all the others are reached
  18881. // via offsets contained in one of the below.
  18882. var header = this.parseHeader();
  18883. var nameIndex = this.parseIndex(header.endPos);
  18884. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18885. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18886. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18887. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18888. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18889. cff.header = header.obj;
  18890. cff.names = this.parseNameIndex(nameIndex.obj);
  18891. cff.strings = this.parseStringIndex(stringIndex.obj);
  18892. cff.topDict = topDict;
  18893. cff.globalSubrIndex = globalSubrIndex.obj;
  18894. this.parsePrivateDict(cff.topDict);
  18895. cff.isCIDFont = topDict.hasName('ROS');
  18896. var charStringOffset = topDict.getByName('CharStrings');
  18897. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18898. cff.charStrings = charStringsAndSeacs.charStrings;
  18899. cff.seacs = charStringsAndSeacs.seacs;
  18900. cff.widths = charStringsAndSeacs.widths;
  18901. var fontMatrix = topDict.getByName('FontMatrix');
  18902. if (fontMatrix) {
  18903. properties.fontMatrix = fontMatrix;
  18904. }
  18905. var fontBBox = topDict.getByName('FontBBox');
  18906. if (fontBBox) {
  18907. // adjusting ascent/descent
  18908. properties.ascent = fontBBox[3];
  18909. properties.descent = fontBBox[1];
  18910. properties.ascentScaled = true;
  18911. }
  18912. var charset, encoding;
  18913. if (cff.isCIDFont) {
  18914. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18915. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18916. var dictRaw = fdArrayIndex.get(i);
  18917. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18918. cff.strings);
  18919. this.parsePrivateDict(fontDict);
  18920. cff.fdArray.push(fontDict);
  18921. }
  18922. // cid fonts don't have an encoding
  18923. encoding = null;
  18924. charset = this.parseCharsets(topDict.getByName('charset'),
  18925. cff.charStrings.count, cff.strings, true);
  18926. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18927. cff.charStrings.count);
  18928. } else {
  18929. charset = this.parseCharsets(topDict.getByName('charset'),
  18930. cff.charStrings.count, cff.strings, false);
  18931. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18932. properties,
  18933. cff.strings, charset.charset);
  18934. }
  18935. cff.charset = charset;
  18936. cff.encoding = encoding;
  18937. return cff;
  18938. },
  18939. parseHeader: function CFFParser_parseHeader() {
  18940. var bytes = this.bytes;
  18941. var bytesLength = bytes.length;
  18942. var offset = 0;
  18943. // Prevent an infinite loop, by checking that the offset is within the
  18944. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18945. while (offset < bytesLength && bytes[offset] !== 1) {
  18946. ++offset;
  18947. }
  18948. if (offset >= bytesLength) {
  18949. error('Invalid CFF header');
  18950. } else if (offset !== 0) {
  18951. info('cff data is shifted');
  18952. bytes = bytes.subarray(offset);
  18953. this.bytes = bytes;
  18954. }
  18955. var major = bytes[0];
  18956. var minor = bytes[1];
  18957. var hdrSize = bytes[2];
  18958. var offSize = bytes[3];
  18959. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18960. return { obj: header, endPos: hdrSize };
  18961. },
  18962. parseDict: function CFFParser_parseDict(dict) {
  18963. var pos = 0;
  18964. function parseOperand() {
  18965. var value = dict[pos++];
  18966. if (value === 30) {
  18967. return parseFloatOperand(pos);
  18968. } else if (value === 28) {
  18969. value = dict[pos++];
  18970. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18971. return value;
  18972. } else if (value === 29) {
  18973. value = dict[pos++];
  18974. value = (value << 8) | dict[pos++];
  18975. value = (value << 8) | dict[pos++];
  18976. value = (value << 8) | dict[pos++];
  18977. return value;
  18978. } else if (value >= 32 && value <= 246) {
  18979. return value - 139;
  18980. } else if (value >= 247 && value <= 250) {
  18981. return ((value - 247) * 256) + dict[pos++] + 108;
  18982. } else if (value >= 251 && value <= 254) {
  18983. return -((value - 251) * 256) - dict[pos++] - 108;
  18984. } else {
  18985. error('255 is not a valid DICT command');
  18986. }
  18987. return -1;
  18988. }
  18989. function parseFloatOperand() {
  18990. var str = '';
  18991. var eof = 15;
  18992. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18993. '9', '.', 'E', 'E-', null, '-'];
  18994. var length = dict.length;
  18995. while (pos < length) {
  18996. var b = dict[pos++];
  18997. var b1 = b >> 4;
  18998. var b2 = b & 15;
  18999. if (b1 === eof) {
  19000. break;
  19001. }
  19002. str += lookup[b1];
  19003. if (b2 === eof) {
  19004. break;
  19005. }
  19006. str += lookup[b2];
  19007. }
  19008. return parseFloat(str);
  19009. }
  19010. var operands = [];
  19011. var entries = [];
  19012. pos = 0;
  19013. var end = dict.length;
  19014. while (pos < end) {
  19015. var b = dict[pos];
  19016. if (b <= 21) {
  19017. if (b === 12) {
  19018. b = (b << 8) | dict[++pos];
  19019. }
  19020. entries.push([b, operands]);
  19021. operands = [];
  19022. ++pos;
  19023. } else {
  19024. operands.push(parseOperand());
  19025. }
  19026. }
  19027. return entries;
  19028. },
  19029. parseIndex: function CFFParser_parseIndex(pos) {
  19030. var cffIndex = new CFFIndex();
  19031. var bytes = this.bytes;
  19032. var count = (bytes[pos++] << 8) | bytes[pos++];
  19033. var offsets = [];
  19034. var end = pos;
  19035. var i, ii;
  19036. if (count !== 0) {
  19037. var offsetSize = bytes[pos++];
  19038. // add 1 for offset to determine size of last object
  19039. var startPos = pos + ((count + 1) * offsetSize) - 1;
  19040. for (i = 0, ii = count + 1; i < ii; ++i) {
  19041. var offset = 0;
  19042. for (var j = 0; j < offsetSize; ++j) {
  19043. offset <<= 8;
  19044. offset += bytes[pos++];
  19045. }
  19046. offsets.push(startPos + offset);
  19047. }
  19048. end = offsets[count];
  19049. }
  19050. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  19051. var offsetStart = offsets[i];
  19052. var offsetEnd = offsets[i + 1];
  19053. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  19054. }
  19055. return {obj: cffIndex, endPos: end};
  19056. },
  19057. parseNameIndex: function CFFParser_parseNameIndex(index) {
  19058. var names = [];
  19059. for (var i = 0, ii = index.count; i < ii; ++i) {
  19060. var name = index.get(i);
  19061. // OTS doesn't allow names to be over 127 characters.
  19062. var length = Math.min(name.length, 127);
  19063. var data = [];
  19064. // OTS also only permits certain characters in the name.
  19065. for (var j = 0; j < length; ++j) {
  19066. var c = name[j];
  19067. if (j === 0 && c === 0) {
  19068. data[j] = c;
  19069. continue;
  19070. }
  19071. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  19072. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  19073. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  19074. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  19075. data[j] = 95;
  19076. continue;
  19077. }
  19078. data[j] = c;
  19079. }
  19080. names.push(bytesToString(data));
  19081. }
  19082. return names;
  19083. },
  19084. parseStringIndex: function CFFParser_parseStringIndex(index) {
  19085. var strings = new CFFStrings();
  19086. for (var i = 0, ii = index.count; i < ii; ++i) {
  19087. var data = index.get(i);
  19088. strings.add(bytesToString(data));
  19089. }
  19090. return strings;
  19091. },
  19092. createDict: function CFFParser_createDict(Type, dict, strings) {
  19093. var cffDict = new Type(strings);
  19094. for (var i = 0, ii = dict.length; i < ii; ++i) {
  19095. var pair = dict[i];
  19096. var key = pair[0];
  19097. var value = pair[1];
  19098. cffDict.setByKey(key, value);
  19099. }
  19100. return cffDict;
  19101. },
  19102. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  19103. var charStrings = this.parseIndex(charStringOffset).obj;
  19104. var seacs = [];
  19105. var widths = [];
  19106. var count = charStrings.count;
  19107. for (var i = 0; i < count; i++) {
  19108. var charstring = charStrings.get(i);
  19109. var stackSize = 0;
  19110. var stack = [];
  19111. var undefStack = true;
  19112. var hints = 0;
  19113. var valid = true;
  19114. var data = charstring;
  19115. var length = data.length;
  19116. var firstStackClearing = true;
  19117. for (var j = 0; j < length;) {
  19118. var value = data[j++];
  19119. var validationCommand = null;
  19120. if (value === 12) {
  19121. var q = data[j++];
  19122. if (q === 0) {
  19123. // The CFF specification state that the 'dotsection' command
  19124. // (12, 0) is deprecated and treated as a no-op, but all Type2
  19125. // charstrings processors should support them. Unfortunately
  19126. // the font sanitizer don't. As a workaround the sequence (12, 0)
  19127. // is replaced by a useless (0, hmoveto).
  19128. data[j - 2] = 139;
  19129. data[j - 1] = 22;
  19130. stackSize = 0;
  19131. } else {
  19132. validationCommand = CharstringValidationData12[q];
  19133. }
  19134. } else if (value === 28) { // number (16 bit)
  19135. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  19136. j += 2;
  19137. stackSize++;
  19138. } else if (value === 14) {
  19139. if (stackSize >= 4) {
  19140. stackSize -= 4;
  19141. if (SEAC_ANALYSIS_ENABLED) {
  19142. seacs[i] = stack.slice(stackSize, stackSize + 4);
  19143. valid = false;
  19144. }
  19145. }
  19146. validationCommand = CharstringValidationData[value];
  19147. } else if (value >= 32 && value <= 246) { // number
  19148. stack[stackSize] = value - 139;
  19149. stackSize++;
  19150. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  19151. stack[stackSize] = (value < 251 ?
  19152. ((value - 247) << 8) + data[j] + 108 :
  19153. -((value - 251) << 8) - data[j] - 108);
  19154. j++;
  19155. stackSize++;
  19156. } else if (value === 255) { // number (32 bit)
  19157. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  19158. (data[j + 2] << 8) | data[j + 3]) / 65536;
  19159. j += 4;
  19160. stackSize++;
  19161. } else if (value === 19 || value === 20) {
  19162. hints += stackSize >> 1;
  19163. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  19164. stackSize %= 2;
  19165. validationCommand = CharstringValidationData[value];
  19166. } else {
  19167. validationCommand = CharstringValidationData[value];
  19168. }
  19169. if (validationCommand) {
  19170. if (validationCommand.stem) {
  19171. hints += stackSize >> 1;
  19172. }
  19173. if ('min' in validationCommand) {
  19174. if (!undefStack && stackSize < validationCommand.min) {
  19175. warn('Not enough parameters for ' + validationCommand.id +
  19176. '; actual: ' + stackSize +
  19177. ', expected: ' + validationCommand.min);
  19178. valid = false;
  19179. break;
  19180. }
  19181. }
  19182. if (firstStackClearing && validationCommand.stackClearing) {
  19183. firstStackClearing = false;
  19184. // the optional character width can be found before the first
  19185. // stack-clearing command arguments
  19186. stackSize -= validationCommand.min;
  19187. if (stackSize >= 2 && validationCommand.stem) {
  19188. // there are even amount of arguments for stem commands
  19189. stackSize %= 2;
  19190. } else if (stackSize > 1) {
  19191. warn('Found too many parameters for stack-clearing command');
  19192. }
  19193. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  19194. widths[i] = stack[stackSize - 1];
  19195. }
  19196. }
  19197. if ('stackDelta' in validationCommand) {
  19198. if ('stackFn' in validationCommand) {
  19199. validationCommand.stackFn(stack, stackSize);
  19200. }
  19201. stackSize += validationCommand.stackDelta;
  19202. } else if (validationCommand.stackClearing) {
  19203. stackSize = 0;
  19204. } else if (validationCommand.resetStack) {
  19205. stackSize = 0;
  19206. undefStack = false;
  19207. } else if (validationCommand.undefStack) {
  19208. stackSize = 0;
  19209. undefStack = true;
  19210. firstStackClearing = false;
  19211. }
  19212. }
  19213. }
  19214. if (!valid) {
  19215. // resetting invalid charstring to single 'endchar'
  19216. charStrings.set(i, new Uint8Array([14]));
  19217. }
  19218. }
  19219. return { charStrings: charStrings, seacs: seacs, widths: widths };
  19220. },
  19221. emptyPrivateDictionary:
  19222. function CFFParser_emptyPrivateDictionary(parentDict) {
  19223. var privateDict = this.createDict(CFFPrivateDict, [],
  19224. parentDict.strings);
  19225. parentDict.setByKey(18, [0, 0]);
  19226. parentDict.privateDict = privateDict;
  19227. },
  19228. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  19229. // no private dict, do nothing
  19230. if (!parentDict.hasName('Private')) {
  19231. this.emptyPrivateDictionary(parentDict);
  19232. return;
  19233. }
  19234. var privateOffset = parentDict.getByName('Private');
  19235. // make sure the params are formatted correctly
  19236. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  19237. parentDict.removeByName('Private');
  19238. return;
  19239. }
  19240. var size = privateOffset[0];
  19241. var offset = privateOffset[1];
  19242. // remove empty dicts or ones that refer to invalid location
  19243. if (size === 0 || offset >= this.bytes.length) {
  19244. this.emptyPrivateDictionary(parentDict);
  19245. return;
  19246. }
  19247. var privateDictEnd = offset + size;
  19248. var dictData = this.bytes.subarray(offset, privateDictEnd);
  19249. var dict = this.parseDict(dictData);
  19250. var privateDict = this.createDict(CFFPrivateDict, dict,
  19251. parentDict.strings);
  19252. parentDict.privateDict = privateDict;
  19253. // Parse the Subrs index also since it's relative to the private dict.
  19254. if (!privateDict.getByName('Subrs')) {
  19255. return;
  19256. }
  19257. var subrsOffset = privateDict.getByName('Subrs');
  19258. var relativeOffset = offset + subrsOffset;
  19259. // Validate the offset.
  19260. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  19261. this.emptyPrivateDictionary(parentDict);
  19262. return;
  19263. }
  19264. var subrsIndex = this.parseIndex(relativeOffset);
  19265. privateDict.subrsIndex = subrsIndex.obj;
  19266. },
  19267. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  19268. if (pos === 0) {
  19269. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  19270. ISOAdobeCharset);
  19271. } else if (pos === 1) {
  19272. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  19273. ExpertCharset);
  19274. } else if (pos === 2) {
  19275. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  19276. ExpertSubsetCharset);
  19277. }
  19278. var bytes = this.bytes;
  19279. var start = pos;
  19280. var format = bytes[pos++];
  19281. var charset = ['.notdef'];
  19282. var id, count, i;
  19283. // subtract 1 for the .notdef glyph
  19284. length -= 1;
  19285. switch (format) {
  19286. case 0:
  19287. for (i = 0; i < length; i++) {
  19288. id = (bytes[pos++] << 8) | bytes[pos++];
  19289. charset.push(cid ? id : strings.get(id));
  19290. }
  19291. break;
  19292. case 1:
  19293. while (charset.length <= length) {
  19294. id = (bytes[pos++] << 8) | bytes[pos++];
  19295. count = bytes[pos++];
  19296. for (i = 0; i <= count; i++) {
  19297. charset.push(cid ? id++ : strings.get(id++));
  19298. }
  19299. }
  19300. break;
  19301. case 2:
  19302. while (charset.length <= length) {
  19303. id = (bytes[pos++] << 8) | bytes[pos++];
  19304. count = (bytes[pos++] << 8) | bytes[pos++];
  19305. for (i = 0; i <= count; i++) {
  19306. charset.push(cid ? id++ : strings.get(id++));
  19307. }
  19308. }
  19309. break;
  19310. default:
  19311. error('Unknown charset format');
  19312. }
  19313. // Raw won't be needed if we actually compile the charset.
  19314. var end = pos;
  19315. var raw = bytes.subarray(start, end);
  19316. return new CFFCharset(false, format, charset, raw);
  19317. },
  19318. parseEncoding: function CFFParser_parseEncoding(pos,
  19319. properties,
  19320. strings,
  19321. charset) {
  19322. var encoding = {};
  19323. var bytes = this.bytes;
  19324. var predefined = false;
  19325. var hasSupplement = false;
  19326. var format, i, ii;
  19327. var raw = null;
  19328. function readSupplement() {
  19329. var supplementsCount = bytes[pos++];
  19330. for (i = 0; i < supplementsCount; i++) {
  19331. var code = bytes[pos++];
  19332. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  19333. encoding[code] = charset.indexOf(strings.get(sid));
  19334. }
  19335. }
  19336. if (pos === 0 || pos === 1) {
  19337. predefined = true;
  19338. format = pos;
  19339. var baseEncoding = pos ? Encodings.ExpertEncoding :
  19340. Encodings.StandardEncoding;
  19341. for (i = 0, ii = charset.length; i < ii; i++) {
  19342. var index = baseEncoding.indexOf(charset[i]);
  19343. if (index !== -1) {
  19344. encoding[index] = i;
  19345. }
  19346. }
  19347. } else {
  19348. var dataStart = pos;
  19349. format = bytes[pos++];
  19350. switch (format & 0x7f) {
  19351. case 0:
  19352. var glyphsCount = bytes[pos++];
  19353. for (i = 1; i <= glyphsCount; i++) {
  19354. encoding[bytes[pos++]] = i;
  19355. }
  19356. break;
  19357. case 1:
  19358. var rangesCount = bytes[pos++];
  19359. var gid = 1;
  19360. for (i = 0; i < rangesCount; i++) {
  19361. var start = bytes[pos++];
  19362. var left = bytes[pos++];
  19363. for (var j = start; j <= start + left; j++) {
  19364. encoding[j] = gid++;
  19365. }
  19366. }
  19367. break;
  19368. default:
  19369. error('Unknow encoding format: ' + format + ' in CFF');
  19370. break;
  19371. }
  19372. var dataEnd = pos;
  19373. if (format & 0x80) {
  19374. // The font sanitizer does not support CFF encoding with a
  19375. // supplement, since the encoding is not really used to map
  19376. // between gid to glyph, let's overwrite what is declared in
  19377. // the top dictionary to let the sanitizer think the font use
  19378. // StandardEncoding, that's a lie but that's ok.
  19379. bytes[dataStart] &= 0x7f;
  19380. readSupplement();
  19381. hasSupplement = true;
  19382. }
  19383. raw = bytes.subarray(dataStart, dataEnd);
  19384. }
  19385. format = format & 0x7f;
  19386. return new CFFEncoding(predefined, format, encoding, raw);
  19387. },
  19388. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  19389. var start = pos;
  19390. var bytes = this.bytes;
  19391. var format = bytes[pos++];
  19392. var fdSelect = [];
  19393. var i;
  19394. switch (format) {
  19395. case 0:
  19396. for (i = 0; i < length; ++i) {
  19397. var id = bytes[pos++];
  19398. fdSelect.push(id);
  19399. }
  19400. break;
  19401. case 3:
  19402. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  19403. for (i = 0; i < rangesCount; ++i) {
  19404. var first = (bytes[pos++] << 8) | bytes[pos++];
  19405. var fdIndex = bytes[pos++];
  19406. var next = (bytes[pos] << 8) | bytes[pos + 1];
  19407. for (var j = first; j < next; ++j) {
  19408. fdSelect.push(fdIndex);
  19409. }
  19410. }
  19411. // Advance past the sentinel(next).
  19412. pos += 2;
  19413. break;
  19414. default:
  19415. error('Unknown fdselect format ' + format);
  19416. break;
  19417. }
  19418. var end = pos;
  19419. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  19420. }
  19421. };
  19422. return CFFParser;
  19423. })();
  19424. // Compact Font Format
  19425. var CFF = (function CFFClosure() {
  19426. function CFF() {
  19427. this.header = null;
  19428. this.names = [];
  19429. this.topDict = null;
  19430. this.strings = new CFFStrings();
  19431. this.globalSubrIndex = null;
  19432. // The following could really be per font, but since we only have one font
  19433. // store them here.
  19434. this.encoding = null;
  19435. this.charset = null;
  19436. this.charStrings = null;
  19437. this.fdArray = [];
  19438. this.fdSelect = null;
  19439. this.isCIDFont = false;
  19440. }
  19441. return CFF;
  19442. })();
  19443. var CFFHeader = (function CFFHeaderClosure() {
  19444. function CFFHeader(major, minor, hdrSize, offSize) {
  19445. this.major = major;
  19446. this.minor = minor;
  19447. this.hdrSize = hdrSize;
  19448. this.offSize = offSize;
  19449. }
  19450. return CFFHeader;
  19451. })();
  19452. var CFFStrings = (function CFFStringsClosure() {
  19453. function CFFStrings() {
  19454. this.strings = [];
  19455. }
  19456. CFFStrings.prototype = {
  19457. get: function CFFStrings_get(index) {
  19458. if (index >= 0 && index <= 390) {
  19459. return CFFStandardStrings[index];
  19460. }
  19461. if (index - 391 <= this.strings.length) {
  19462. return this.strings[index - 391];
  19463. }
  19464. return CFFStandardStrings[0];
  19465. },
  19466. add: function CFFStrings_add(value) {
  19467. this.strings.push(value);
  19468. },
  19469. get count() {
  19470. return this.strings.length;
  19471. }
  19472. };
  19473. return CFFStrings;
  19474. })();
  19475. var CFFIndex = (function CFFIndexClosure() {
  19476. function CFFIndex() {
  19477. this.objects = [];
  19478. this.length = 0;
  19479. }
  19480. CFFIndex.prototype = {
  19481. add: function CFFIndex_add(data) {
  19482. this.length += data.length;
  19483. this.objects.push(data);
  19484. },
  19485. set: function CFFIndex_set(index, data) {
  19486. this.length += data.length - this.objects[index].length;
  19487. this.objects[index] = data;
  19488. },
  19489. get: function CFFIndex_get(index) {
  19490. return this.objects[index];
  19491. },
  19492. get count() {
  19493. return this.objects.length;
  19494. }
  19495. };
  19496. return CFFIndex;
  19497. })();
  19498. var CFFDict = (function CFFDictClosure() {
  19499. function CFFDict(tables, strings) {
  19500. this.keyToNameMap = tables.keyToNameMap;
  19501. this.nameToKeyMap = tables.nameToKeyMap;
  19502. this.defaults = tables.defaults;
  19503. this.types = tables.types;
  19504. this.opcodes = tables.opcodes;
  19505. this.order = tables.order;
  19506. this.strings = strings;
  19507. this.values = {};
  19508. }
  19509. CFFDict.prototype = {
  19510. // value should always be an array
  19511. setByKey: function CFFDict_setByKey(key, value) {
  19512. if (!(key in this.keyToNameMap)) {
  19513. return false;
  19514. }
  19515. // ignore empty values
  19516. if (value.length === 0) {
  19517. return true;
  19518. }
  19519. var type = this.types[key];
  19520. // remove the array wrapping these types of values
  19521. if (type === 'num' || type === 'sid' || type === 'offset') {
  19522. value = value[0];
  19523. }
  19524. this.values[key] = value;
  19525. return true;
  19526. },
  19527. setByName: function CFFDict_setByName(name, value) {
  19528. if (!(name in this.nameToKeyMap)) {
  19529. error('Invalid dictionary name "' + name + '"');
  19530. }
  19531. this.values[this.nameToKeyMap[name]] = value;
  19532. },
  19533. hasName: function CFFDict_hasName(name) {
  19534. return this.nameToKeyMap[name] in this.values;
  19535. },
  19536. getByName: function CFFDict_getByName(name) {
  19537. if (!(name in this.nameToKeyMap)) {
  19538. error('Invalid dictionary name "' + name + '"');
  19539. }
  19540. var key = this.nameToKeyMap[name];
  19541. if (!(key in this.values)) {
  19542. return this.defaults[key];
  19543. }
  19544. return this.values[key];
  19545. },
  19546. removeByName: function CFFDict_removeByName(name) {
  19547. delete this.values[this.nameToKeyMap[name]];
  19548. }
  19549. };
  19550. CFFDict.createTables = function CFFDict_createTables(layout) {
  19551. var tables = {
  19552. keyToNameMap: {},
  19553. nameToKeyMap: {},
  19554. defaults: {},
  19555. types: {},
  19556. opcodes: {},
  19557. order: []
  19558. };
  19559. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19560. var entry = layout[i];
  19561. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19562. tables.keyToNameMap[key] = entry[1];
  19563. tables.nameToKeyMap[entry[1]] = key;
  19564. tables.types[key] = entry[2];
  19565. tables.defaults[key] = entry[3];
  19566. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19567. tables.order.push(key);
  19568. }
  19569. return tables;
  19570. };
  19571. return CFFDict;
  19572. })();
  19573. var CFFTopDict = (function CFFTopDictClosure() {
  19574. var layout = [
  19575. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19576. [[12, 20], 'SyntheticBase', 'num', null],
  19577. [0, 'version', 'sid', null],
  19578. [1, 'Notice', 'sid', null],
  19579. [[12, 0], 'Copyright', 'sid', null],
  19580. [2, 'FullName', 'sid', null],
  19581. [3, 'FamilyName', 'sid', null],
  19582. [4, 'Weight', 'sid', null],
  19583. [[12, 1], 'isFixedPitch', 'num', 0],
  19584. [[12, 2], 'ItalicAngle', 'num', 0],
  19585. [[12, 3], 'UnderlinePosition', 'num', -100],
  19586. [[12, 4], 'UnderlineThickness', 'num', 50],
  19587. [[12, 5], 'PaintType', 'num', 0],
  19588. [[12, 6], 'CharstringType', 'num', 2],
  19589. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19590. [0.001, 0, 0, 0.001, 0, 0]],
  19591. [13, 'UniqueID', 'num', null],
  19592. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19593. [[12, 8], 'StrokeWidth', 'num', 0],
  19594. [14, 'XUID', 'array', null],
  19595. [15, 'charset', 'offset', 0],
  19596. [16, 'Encoding', 'offset', 0],
  19597. [17, 'CharStrings', 'offset', 0],
  19598. [18, 'Private', ['offset', 'offset'], null],
  19599. [[12, 21], 'PostScript', 'sid', null],
  19600. [[12, 22], 'BaseFontName', 'sid', null],
  19601. [[12, 23], 'BaseFontBlend', 'delta', null],
  19602. [[12, 31], 'CIDFontVersion', 'num', 0],
  19603. [[12, 32], 'CIDFontRevision', 'num', 0],
  19604. [[12, 33], 'CIDFontType', 'num', 0],
  19605. [[12, 34], 'CIDCount', 'num', 8720],
  19606. [[12, 35], 'UIDBase', 'num', null],
  19607. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19608. // before FDArray.
  19609. [[12, 37], 'FDSelect', 'offset', null],
  19610. [[12, 36], 'FDArray', 'offset', null],
  19611. [[12, 38], 'FontName', 'sid', null]
  19612. ];
  19613. var tables = null;
  19614. function CFFTopDict(strings) {
  19615. if (tables === null) {
  19616. tables = CFFDict.createTables(layout);
  19617. }
  19618. CFFDict.call(this, tables, strings);
  19619. this.privateDict = null;
  19620. }
  19621. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19622. return CFFTopDict;
  19623. })();
  19624. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19625. var layout = [
  19626. [6, 'BlueValues', 'delta', null],
  19627. [7, 'OtherBlues', 'delta', null],
  19628. [8, 'FamilyBlues', 'delta', null],
  19629. [9, 'FamilyOtherBlues', 'delta', null],
  19630. [[12, 9], 'BlueScale', 'num', 0.039625],
  19631. [[12, 10], 'BlueShift', 'num', 7],
  19632. [[12, 11], 'BlueFuzz', 'num', 1],
  19633. [10, 'StdHW', 'num', null],
  19634. [11, 'StdVW', 'num', null],
  19635. [[12, 12], 'StemSnapH', 'delta', null],
  19636. [[12, 13], 'StemSnapV', 'delta', null],
  19637. [[12, 14], 'ForceBold', 'num', 0],
  19638. [[12, 17], 'LanguageGroup', 'num', 0],
  19639. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19640. [[12, 19], 'initialRandomSeed', 'num', 0],
  19641. [20, 'defaultWidthX', 'num', 0],
  19642. [21, 'nominalWidthX', 'num', 0],
  19643. [19, 'Subrs', 'offset', null]
  19644. ];
  19645. var tables = null;
  19646. function CFFPrivateDict(strings) {
  19647. if (tables === null) {
  19648. tables = CFFDict.createTables(layout);
  19649. }
  19650. CFFDict.call(this, tables, strings);
  19651. this.subrsIndex = null;
  19652. }
  19653. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19654. return CFFPrivateDict;
  19655. })();
  19656. var CFFCharsetPredefinedTypes = {
  19657. ISO_ADOBE: 0,
  19658. EXPERT: 1,
  19659. EXPERT_SUBSET: 2
  19660. };
  19661. var CFFCharset = (function CFFCharsetClosure() {
  19662. function CFFCharset(predefined, format, charset, raw) {
  19663. this.predefined = predefined;
  19664. this.format = format;
  19665. this.charset = charset;
  19666. this.raw = raw;
  19667. }
  19668. return CFFCharset;
  19669. })();
  19670. var CFFEncoding = (function CFFEncodingClosure() {
  19671. function CFFEncoding(predefined, format, encoding, raw) {
  19672. this.predefined = predefined;
  19673. this.format = format;
  19674. this.encoding = encoding;
  19675. this.raw = raw;
  19676. }
  19677. return CFFEncoding;
  19678. })();
  19679. var CFFFDSelect = (function CFFFDSelectClosure() {
  19680. function CFFFDSelect(fdSelect, raw) {
  19681. this.fdSelect = fdSelect;
  19682. this.raw = raw;
  19683. }
  19684. return CFFFDSelect;
  19685. })();
  19686. // Helper class to keep track of where an offset is within the data and helps
  19687. // filling in that offset once it's known.
  19688. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19689. function CFFOffsetTracker() {
  19690. this.offsets = {};
  19691. }
  19692. CFFOffsetTracker.prototype = {
  19693. isTracking: function CFFOffsetTracker_isTracking(key) {
  19694. return key in this.offsets;
  19695. },
  19696. track: function CFFOffsetTracker_track(key, location) {
  19697. if (key in this.offsets) {
  19698. error('Already tracking location of ' + key);
  19699. }
  19700. this.offsets[key] = location;
  19701. },
  19702. offset: function CFFOffsetTracker_offset(value) {
  19703. for (var key in this.offsets) {
  19704. this.offsets[key] += value;
  19705. }
  19706. },
  19707. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19708. values,
  19709. output) {
  19710. if (!(key in this.offsets)) {
  19711. error('Not tracking location of ' + key);
  19712. }
  19713. var data = output.data;
  19714. var dataOffset = this.offsets[key];
  19715. var size = 5;
  19716. for (var i = 0, ii = values.length; i < ii; ++i) {
  19717. var offset0 = i * size + dataOffset;
  19718. var offset1 = offset0 + 1;
  19719. var offset2 = offset0 + 2;
  19720. var offset3 = offset0 + 3;
  19721. var offset4 = offset0 + 4;
  19722. // It's easy to screw up offsets so perform this sanity check.
  19723. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19724. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19725. error('writing to an offset that is not empty');
  19726. }
  19727. var value = values[i];
  19728. data[offset0] = 0x1d;
  19729. data[offset1] = (value >> 24) & 0xFF;
  19730. data[offset2] = (value >> 16) & 0xFF;
  19731. data[offset3] = (value >> 8) & 0xFF;
  19732. data[offset4] = value & 0xFF;
  19733. }
  19734. }
  19735. };
  19736. return CFFOffsetTracker;
  19737. })();
  19738. // Takes a CFF and converts it to the binary representation.
  19739. var CFFCompiler = (function CFFCompilerClosure() {
  19740. function CFFCompiler(cff) {
  19741. this.cff = cff;
  19742. }
  19743. CFFCompiler.prototype = {
  19744. compile: function CFFCompiler_compile() {
  19745. var cff = this.cff;
  19746. var output = {
  19747. data: [],
  19748. length: 0,
  19749. add: function CFFCompiler_add(data) {
  19750. this.data = this.data.concat(data);
  19751. this.length = this.data.length;
  19752. }
  19753. };
  19754. // Compile the five entries that must be in order.
  19755. var header = this.compileHeader(cff.header);
  19756. output.add(header);
  19757. var nameIndex = this.compileNameIndex(cff.names);
  19758. output.add(nameIndex);
  19759. if (cff.isCIDFont) {
  19760. // The spec is unclear on how font matrices should relate to each other
  19761. // when there is one in the main top dict and the sub top dicts.
  19762. // Windows handles this differently than linux and osx so we have to
  19763. // normalize to work on all.
  19764. // Rules based off of some mailing list discussions:
  19765. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19766. // - If no main font matrix and there is a subfont matrix, use the
  19767. // subfont matrix.
  19768. // - If both have matrices, concat together.
  19769. // - If neither have matrices, use default.
  19770. // To make this work on all platforms we move the top matrix into each
  19771. // sub top dict and concat if necessary.
  19772. if (cff.topDict.hasName('FontMatrix')) {
  19773. var base = cff.topDict.getByName('FontMatrix');
  19774. cff.topDict.removeByName('FontMatrix');
  19775. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19776. var subDict = cff.fdArray[i];
  19777. var matrix = base.slice(0);
  19778. if (subDict.hasName('FontMatrix')) {
  19779. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19780. }
  19781. subDict.setByName('FontMatrix', matrix);
  19782. }
  19783. }
  19784. }
  19785. var compiled = this.compileTopDicts([cff.topDict],
  19786. output.length,
  19787. cff.isCIDFont);
  19788. output.add(compiled.output);
  19789. var topDictTracker = compiled.trackers[0];
  19790. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19791. output.add(stringIndex);
  19792. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19793. output.add(globalSubrIndex);
  19794. // Now start on the other entries that have no specfic order.
  19795. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19796. if (cff.encoding.predefined) {
  19797. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19798. output);
  19799. } else {
  19800. var encoding = this.compileEncoding(cff.encoding);
  19801. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19802. output.add(encoding);
  19803. }
  19804. }
  19805. if (cff.charset && cff.topDict.hasName('charset')) {
  19806. if (cff.charset.predefined) {
  19807. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19808. output);
  19809. } else {
  19810. var charset = this.compileCharset(cff.charset);
  19811. topDictTracker.setEntryLocation('charset', [output.length], output);
  19812. output.add(charset);
  19813. }
  19814. }
  19815. var charStrings = this.compileCharStrings(cff.charStrings);
  19816. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19817. output.add(charStrings);
  19818. if (cff.isCIDFont) {
  19819. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19820. // and linux don't seem to care.
  19821. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19822. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19823. output.add(fdSelect);
  19824. // It is unclear if the sub font dictionary can have CID related
  19825. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19826. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19827. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19828. output.add(compiled.output);
  19829. var fontDictTrackers = compiled.trackers;
  19830. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19831. }
  19832. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19833. // If the font data ends with INDEX whose object data is zero-length,
  19834. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19835. output.add([0]);
  19836. return output.data;
  19837. },
  19838. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19839. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19840. return this.encodeInteger(value);
  19841. } else {
  19842. return this.encodeFloat(value);
  19843. }
  19844. },
  19845. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19846. var value = num.toString();
  19847. // rounding inaccurate doubles
  19848. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19849. if (m) {
  19850. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19851. value = (Math.round(num * epsilon) / epsilon).toString();
  19852. }
  19853. var nibbles = '';
  19854. var i, ii;
  19855. for (i = 0, ii = value.length; i < ii; ++i) {
  19856. var a = value[i];
  19857. if (a === 'e') {
  19858. nibbles += value[++i] === '-' ? 'c' : 'b';
  19859. } else if (a === '.') {
  19860. nibbles += 'a';
  19861. } else if (a === '-') {
  19862. nibbles += 'e';
  19863. } else {
  19864. nibbles += a;
  19865. }
  19866. }
  19867. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19868. var out = [30];
  19869. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19870. out.push(parseInt(nibbles.substr(i, 2), 16));
  19871. }
  19872. return out;
  19873. },
  19874. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19875. var code;
  19876. if (value >= -107 && value <= 107) {
  19877. code = [value + 139];
  19878. } else if (value >= 108 && value <= 1131) {
  19879. value = [value - 108];
  19880. code = [(value >> 8) + 247, value & 0xFF];
  19881. } else if (value >= -1131 && value <= -108) {
  19882. value = -value - 108;
  19883. code = [(value >> 8) + 251, value & 0xFF];
  19884. } else if (value >= -32768 && value <= 32767) {
  19885. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19886. } else {
  19887. code = [0x1d,
  19888. (value >> 24) & 0xFF,
  19889. (value >> 16) & 0xFF,
  19890. (value >> 8) & 0xFF,
  19891. value & 0xFF];
  19892. }
  19893. return code;
  19894. },
  19895. compileHeader: function CFFCompiler_compileHeader(header) {
  19896. return [
  19897. header.major,
  19898. header.minor,
  19899. header.hdrSize,
  19900. header.offSize
  19901. ];
  19902. },
  19903. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19904. var nameIndex = new CFFIndex();
  19905. for (var i = 0, ii = names.length; i < ii; ++i) {
  19906. nameIndex.add(stringToBytes(names[i]));
  19907. }
  19908. return this.compileIndex(nameIndex);
  19909. },
  19910. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19911. length,
  19912. removeCidKeys) {
  19913. var fontDictTrackers = [];
  19914. var fdArrayIndex = new CFFIndex();
  19915. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19916. var fontDict = dicts[i];
  19917. if (removeCidKeys) {
  19918. fontDict.removeByName('CIDFontVersion');
  19919. fontDict.removeByName('CIDFontRevision');
  19920. fontDict.removeByName('CIDFontType');
  19921. fontDict.removeByName('CIDCount');
  19922. fontDict.removeByName('UIDBase');
  19923. }
  19924. var fontDictTracker = new CFFOffsetTracker();
  19925. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19926. fontDictTrackers.push(fontDictTracker);
  19927. fdArrayIndex.add(fontDictData);
  19928. fontDictTracker.offset(length);
  19929. }
  19930. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19931. return {
  19932. trackers: fontDictTrackers,
  19933. output: fdArrayIndex
  19934. };
  19935. },
  19936. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19937. trackers,
  19938. output) {
  19939. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19940. var fontDict = dicts[i];
  19941. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19942. 'There must be an private dictionary.');
  19943. var privateDict = fontDict.privateDict;
  19944. var privateDictTracker = new CFFOffsetTracker();
  19945. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19946. var outputLength = output.length;
  19947. privateDictTracker.offset(outputLength);
  19948. if (!privateDictData.length) {
  19949. // The private dictionary was empty, set the output length to zero to
  19950. // ensure the offset length isn't out of bounds in the eyes of the
  19951. // sanitizer.
  19952. outputLength = 0;
  19953. }
  19954. trackers[i].setEntryLocation('Private',
  19955. [privateDictData.length, outputLength],
  19956. output);
  19957. output.add(privateDictData);
  19958. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19959. var subrs = this.compileIndex(privateDict.subrsIndex);
  19960. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19961. output);
  19962. output.add(subrs);
  19963. }
  19964. }
  19965. },
  19966. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19967. var out = [];
  19968. // The dictionary keys must be in a certain order.
  19969. var order = dict.order;
  19970. for (var i = 0; i < order.length; ++i) {
  19971. var key = order[i];
  19972. if (!(key in dict.values)) {
  19973. continue;
  19974. }
  19975. var values = dict.values[key];
  19976. var types = dict.types[key];
  19977. if (!isArray(types)) {
  19978. types = [types];
  19979. }
  19980. if (!isArray(values)) {
  19981. values = [values];
  19982. }
  19983. // Remove any empty dict values.
  19984. if (values.length === 0) {
  19985. continue;
  19986. }
  19987. for (var j = 0, jj = types.length; j < jj; ++j) {
  19988. var type = types[j];
  19989. var value = values[j];
  19990. switch (type) {
  19991. case 'num':
  19992. case 'sid':
  19993. out = out.concat(this.encodeNumber(value));
  19994. break;
  19995. case 'offset':
  19996. // For offsets we just insert a 32bit integer so we don't have to
  19997. // deal with figuring out the length of the offset when it gets
  19998. // replaced later on by the compiler.
  19999. var name = dict.keyToNameMap[key];
  20000. // Some offsets have the offset and the length, so just record the
  20001. // position of the first one.
  20002. if (!offsetTracker.isTracking(name)) {
  20003. offsetTracker.track(name, out.length);
  20004. }
  20005. out = out.concat([0x1d, 0, 0, 0, 0]);
  20006. break;
  20007. case 'array':
  20008. case 'delta':
  20009. out = out.concat(this.encodeNumber(value));
  20010. for (var k = 1, kk = values.length; k < kk; ++k) {
  20011. out = out.concat(this.encodeNumber(values[k]));
  20012. }
  20013. break;
  20014. default:
  20015. error('Unknown data type of ' + type);
  20016. break;
  20017. }
  20018. }
  20019. out = out.concat(dict.opcodes[key]);
  20020. }
  20021. return out;
  20022. },
  20023. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  20024. var stringIndex = new CFFIndex();
  20025. for (var i = 0, ii = strings.length; i < ii; ++i) {
  20026. stringIndex.add(stringToBytes(strings[i]));
  20027. }
  20028. return this.compileIndex(stringIndex);
  20029. },
  20030. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  20031. var globalSubrIndex = this.cff.globalSubrIndex;
  20032. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  20033. },
  20034. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  20035. return this.compileIndex(charStrings);
  20036. },
  20037. compileCharset: function CFFCompiler_compileCharset(charset) {
  20038. return this.compileTypedArray(charset.raw);
  20039. },
  20040. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  20041. return this.compileTypedArray(encoding.raw);
  20042. },
  20043. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  20044. return this.compileTypedArray(fdSelect);
  20045. },
  20046. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  20047. var out = [];
  20048. for (var i = 0, ii = data.length; i < ii; ++i) {
  20049. out[i] = data[i];
  20050. }
  20051. return out;
  20052. },
  20053. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  20054. trackers = trackers || [];
  20055. var objects = index.objects;
  20056. // First 2 bytes contains the number of objects contained into this index
  20057. var count = objects.length;
  20058. // If there is no object, just create an index. This technically
  20059. // should just be [0, 0] but OTS has an issue with that.
  20060. if (count === 0) {
  20061. return [0, 0, 0];
  20062. }
  20063. var data = [(count >> 8) & 0xFF, count & 0xff];
  20064. var lastOffset = 1, i;
  20065. for (i = 0; i < count; ++i) {
  20066. lastOffset += objects[i].length;
  20067. }
  20068. var offsetSize;
  20069. if (lastOffset < 0x100) {
  20070. offsetSize = 1;
  20071. } else if (lastOffset < 0x10000) {
  20072. offsetSize = 2;
  20073. } else if (lastOffset < 0x1000000) {
  20074. offsetSize = 3;
  20075. } else {
  20076. offsetSize = 4;
  20077. }
  20078. // Next byte contains the offset size use to reference object in the file
  20079. data.push(offsetSize);
  20080. // Add another offset after this one because we need a new offset
  20081. var relativeOffset = 1;
  20082. for (i = 0; i < count + 1; i++) {
  20083. if (offsetSize === 1) {
  20084. data.push(relativeOffset & 0xFF);
  20085. } else if (offsetSize === 2) {
  20086. data.push((relativeOffset >> 8) & 0xFF,
  20087. relativeOffset & 0xFF);
  20088. } else if (offsetSize === 3) {
  20089. data.push((relativeOffset >> 16) & 0xFF,
  20090. (relativeOffset >> 8) & 0xFF,
  20091. relativeOffset & 0xFF);
  20092. } else {
  20093. data.push((relativeOffset >>> 24) & 0xFF,
  20094. (relativeOffset >> 16) & 0xFF,
  20095. (relativeOffset >> 8) & 0xFF,
  20096. relativeOffset & 0xFF);
  20097. }
  20098. if (objects[i]) {
  20099. relativeOffset += objects[i].length;
  20100. }
  20101. }
  20102. for (i = 0; i < count; i++) {
  20103. // Notify the tracker where the object will be offset in the data.
  20104. if (trackers[i]) {
  20105. trackers[i].offset(data.length);
  20106. }
  20107. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  20108. data.push(objects[i][j]);
  20109. }
  20110. }
  20111. return data;
  20112. }
  20113. };
  20114. return CFFCompiler;
  20115. })();
  20116. // Workaround for seac on Windows.
  20117. (function checkSeacSupport() {
  20118. if (/Windows/.test(navigator.userAgent)) {
  20119. SEAC_ANALYSIS_ENABLED = true;
  20120. }
  20121. })();
  20122. // Workaround for Private Use Area characters in Chrome on Windows
  20123. // http://code.google.com/p/chromium/issues/detail?id=122465
  20124. // https://github.com/mozilla/pdf.js/issues/1689
  20125. (function checkChromeWindows() {
  20126. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  20127. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  20128. }
  20129. })();
  20130. var FontRendererFactory = (function FontRendererFactoryClosure() {
  20131. function getLong(data, offset) {
  20132. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20133. (data[offset + 2] << 8) | data[offset + 3];
  20134. }
  20135. function getUshort(data, offset) {
  20136. return (data[offset] << 8) | data[offset + 1];
  20137. }
  20138. function parseCmap(data, start, end) {
  20139. var offset = (getUshort(data, start + 2) === 1 ?
  20140. getLong(data, start + 8) : getLong(data, start + 16));
  20141. var format = getUshort(data, start + offset);
  20142. var length, ranges, p, i;
  20143. if (format === 4) {
  20144. length = getUshort(data, start + offset + 2);
  20145. var segCount = getUshort(data, start + offset + 6) >> 1;
  20146. p = start + offset + 14;
  20147. ranges = [];
  20148. for (i = 0; i < segCount; i++, p += 2) {
  20149. ranges[i] = {end: getUshort(data, p)};
  20150. }
  20151. p += 2;
  20152. for (i = 0; i < segCount; i++, p += 2) {
  20153. ranges[i].start = getUshort(data, p);
  20154. }
  20155. for (i = 0; i < segCount; i++, p += 2) {
  20156. ranges[i].idDelta = getUshort(data, p);
  20157. }
  20158. for (i = 0; i < segCount; i++, p += 2) {
  20159. var idOffset = getUshort(data, p);
  20160. if (idOffset === 0) {
  20161. continue;
  20162. }
  20163. ranges[i].ids = [];
  20164. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  20165. ranges[i].ids[j] = getUshort(data, p + idOffset);
  20166. idOffset += 2;
  20167. }
  20168. }
  20169. return ranges;
  20170. } else if (format === 12) {
  20171. length = getLong(data, start + offset + 4);
  20172. var groups = getLong(data, start + offset + 12);
  20173. p = start + offset + 16;
  20174. ranges = [];
  20175. for (i = 0; i < groups; i++) {
  20176. ranges.push({
  20177. start: getLong(data, p),
  20178. end: getLong(data, p + 4),
  20179. idDelta: getLong(data, p + 8) - getLong(data, p)
  20180. });
  20181. p += 12;
  20182. }
  20183. return ranges;
  20184. }
  20185. error('not supported cmap: ' + format);
  20186. }
  20187. function parseCff(data, start, end) {
  20188. var properties = {};
  20189. var parser = new CFFParser(new Stream(data, start, end - start),
  20190. properties);
  20191. var cff = parser.parse();
  20192. return {
  20193. glyphs: cff.charStrings.objects,
  20194. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  20195. cff.topDict.privateDict.subrsIndex.objects),
  20196. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  20197. };
  20198. }
  20199. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  20200. var itemSize, itemDecode;
  20201. if (isGlyphLocationsLong) {
  20202. itemSize = 4;
  20203. itemDecode = function fontItemDecodeLong(data, offset) {
  20204. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20205. (data[offset + 2] << 8) | data[offset + 3];
  20206. };
  20207. } else {
  20208. itemSize = 2;
  20209. itemDecode = function fontItemDecode(data, offset) {
  20210. return (data[offset] << 9) | (data[offset + 1] << 1);
  20211. };
  20212. }
  20213. var glyphs = [];
  20214. var startOffset = itemDecode(loca, 0);
  20215. for (var j = itemSize; j < loca.length; j += itemSize) {
  20216. var endOffset = itemDecode(loca, j);
  20217. glyphs.push(glyf.subarray(startOffset, endOffset));
  20218. startOffset = endOffset;
  20219. }
  20220. return glyphs;
  20221. }
  20222. function lookupCmap(ranges, unicode) {
  20223. var code = unicode.charCodeAt(0);
  20224. var l = 0, r = ranges.length - 1;
  20225. while (l < r) {
  20226. var c = (l + r + 1) >> 1;
  20227. if (code < ranges[c].start) {
  20228. r = c - 1;
  20229. } else {
  20230. l = c;
  20231. }
  20232. }
  20233. if (ranges[l].start <= code && code <= ranges[l].end) {
  20234. return (ranges[l].idDelta + (ranges[l].ids ?
  20235. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  20236. }
  20237. return 0;
  20238. }
  20239. function compileGlyf(code, cmds, font) {
  20240. function moveTo(x, y) {
  20241. cmds.push({cmd: 'moveTo', args: [x, y]});
  20242. }
  20243. function lineTo(x, y) {
  20244. cmds.push({cmd: 'lineTo', args: [x, y]});
  20245. }
  20246. function quadraticCurveTo(xa, ya, x, y) {
  20247. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  20248. }
  20249. var i = 0;
  20250. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20251. var flags;
  20252. var x = 0, y = 0;
  20253. i += 10;
  20254. if (numberOfContours < 0) {
  20255. // composite glyph
  20256. do {
  20257. flags = (code[i] << 8) | code[i + 1];
  20258. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  20259. i += 4;
  20260. var arg1, arg2;
  20261. if ((flags & 0x01)) {
  20262. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20263. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  20264. i += 4;
  20265. } else {
  20266. arg1 = code[i++]; arg2 = code[i++];
  20267. }
  20268. if ((flags & 0x02)) {
  20269. x = arg1;
  20270. y = arg2;
  20271. } else {
  20272. x = 0; y = 0; // TODO "they are points" ?
  20273. }
  20274. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  20275. if ((flags & 0x08)) {
  20276. scaleX =
  20277. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20278. i += 2;
  20279. } else if ((flags & 0x40)) {
  20280. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20281. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20282. i += 4;
  20283. } else if ((flags & 0x80)) {
  20284. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20285. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20286. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  20287. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  20288. i += 8;
  20289. }
  20290. var subglyph = font.glyphs[glyphIndex];
  20291. if (subglyph) {
  20292. cmds.push({cmd: 'save'});
  20293. cmds.push({cmd: 'transform',
  20294. args: [scaleX, scale01, scale10, scaleY, x, y]});
  20295. compileGlyf(subglyph, cmds, font);
  20296. cmds.push({cmd: 'restore'});
  20297. }
  20298. } while ((flags & 0x20));
  20299. } else {
  20300. // simple glyph
  20301. var endPtsOfContours = [];
  20302. var j, jj;
  20303. for (j = 0; j < numberOfContours; j++) {
  20304. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  20305. i += 2;
  20306. }
  20307. var instructionLength = (code[i] << 8) | code[i + 1];
  20308. i += 2 + instructionLength; // skipping the instructions
  20309. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  20310. var points = [];
  20311. while (points.length < numberOfPoints) {
  20312. flags = code[i++];
  20313. var repeat = 1;
  20314. if ((flags & 0x08)) {
  20315. repeat += code[i++];
  20316. }
  20317. while (repeat-- > 0) {
  20318. points.push({flags: flags});
  20319. }
  20320. }
  20321. for (j = 0; j < numberOfPoints; j++) {
  20322. switch (points[j].flags & 0x12) {
  20323. case 0x00:
  20324. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20325. i += 2;
  20326. break;
  20327. case 0x02:
  20328. x -= code[i++];
  20329. break;
  20330. case 0x12:
  20331. x += code[i++];
  20332. break;
  20333. }
  20334. points[j].x = x;
  20335. }
  20336. for (j = 0; j < numberOfPoints; j++) {
  20337. switch (points[j].flags & 0x24) {
  20338. case 0x00:
  20339. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20340. i += 2;
  20341. break;
  20342. case 0x04:
  20343. y -= code[i++];
  20344. break;
  20345. case 0x24:
  20346. y += code[i++];
  20347. break;
  20348. }
  20349. points[j].y = y;
  20350. }
  20351. var startPoint = 0;
  20352. for (i = 0; i < numberOfContours; i++) {
  20353. var endPoint = endPtsOfContours[i];
  20354. // contours might have implicit points, which is located in the middle
  20355. // between two neighboring off-curve points
  20356. var contour = points.slice(startPoint, endPoint + 1);
  20357. if ((contour[0].flags & 1)) {
  20358. contour.push(contour[0]); // using start point at the contour end
  20359. } else if ((contour[contour.length - 1].flags & 1)) {
  20360. // first is off-curve point, trying to use one from the end
  20361. contour.unshift(contour[contour.length - 1]);
  20362. } else {
  20363. // start and end are off-curve points, creating implicit one
  20364. var p = {
  20365. flags: 1,
  20366. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  20367. y: (contour[0].y + contour[contour.length - 1].y) / 2
  20368. };
  20369. contour.unshift(p);
  20370. contour.push(p);
  20371. }
  20372. moveTo(contour[0].x, contour[0].y);
  20373. for (j = 1, jj = contour.length; j < jj; j++) {
  20374. if ((contour[j].flags & 1)) {
  20375. lineTo(contour[j].x, contour[j].y);
  20376. } else if ((contour[j + 1].flags & 1)){
  20377. quadraticCurveTo(contour[j].x, contour[j].y,
  20378. contour[j + 1].x, contour[j + 1].y);
  20379. j++;
  20380. } else {
  20381. quadraticCurveTo(contour[j].x, contour[j].y,
  20382. (contour[j].x + contour[j + 1].x) / 2,
  20383. (contour[j].y + contour[j + 1].y) / 2);
  20384. }
  20385. }
  20386. startPoint = endPoint + 1;
  20387. }
  20388. }
  20389. }
  20390. function compileCharString(code, cmds, font) {
  20391. var stack = [];
  20392. var x = 0, y = 0;
  20393. var stems = 0;
  20394. function moveTo(x, y) {
  20395. cmds.push({cmd: 'moveTo', args: [x, y]});
  20396. }
  20397. function lineTo(x, y) {
  20398. cmds.push({cmd: 'lineTo', args: [x, y]});
  20399. }
  20400. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  20401. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  20402. }
  20403. function parse(code) {
  20404. var i = 0;
  20405. while (i < code.length) {
  20406. var stackClean = false;
  20407. var v = code[i++];
  20408. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  20409. switch (v) {
  20410. case 1: // hstem
  20411. stems += stack.length >> 1;
  20412. stackClean = true;
  20413. break;
  20414. case 3: // vstem
  20415. stems += stack.length >> 1;
  20416. stackClean = true;
  20417. break;
  20418. case 4: // vmoveto
  20419. y += stack.pop();
  20420. moveTo(x, y);
  20421. stackClean = true;
  20422. break;
  20423. case 5: // rlineto
  20424. while (stack.length > 0) {
  20425. x += stack.shift();
  20426. y += stack.shift();
  20427. lineTo(x, y);
  20428. }
  20429. break;
  20430. case 6: // hlineto
  20431. while (stack.length > 0) {
  20432. x += stack.shift();
  20433. lineTo(x, y);
  20434. if (stack.length === 0) {
  20435. break;
  20436. }
  20437. y += stack.shift();
  20438. lineTo(x, y);
  20439. }
  20440. break;
  20441. case 7: // vlineto
  20442. while (stack.length > 0) {
  20443. y += stack.shift();
  20444. lineTo(x, y);
  20445. if (stack.length === 0) {
  20446. break;
  20447. }
  20448. x += stack.shift();
  20449. lineTo(x, y);
  20450. }
  20451. break;
  20452. case 8: // rrcurveto
  20453. while (stack.length > 0) {
  20454. xa = x + stack.shift(); ya = y + stack.shift();
  20455. xb = xa + stack.shift(); yb = ya + stack.shift();
  20456. x = xb + stack.shift(); y = yb + stack.shift();
  20457. bezierCurveTo(xa, ya, xb, yb, x, y);
  20458. }
  20459. break;
  20460. case 10: // callsubr
  20461. n = stack.pop() + font.subrsBias;
  20462. subrCode = font.subrs[n];
  20463. if (subrCode) {
  20464. parse(subrCode);
  20465. }
  20466. break;
  20467. case 11: // return
  20468. return;
  20469. case 12:
  20470. v = code[i++];
  20471. switch (v) {
  20472. case 34: // flex
  20473. xa = x + stack.shift();
  20474. xb = xa + stack.shift(); y1 = y + stack.shift();
  20475. x = xb + stack.shift();
  20476. bezierCurveTo(xa, y, xb, y1, x, y1);
  20477. xa = x + stack.shift();
  20478. xb = xa + stack.shift();
  20479. x = xb + stack.shift();
  20480. bezierCurveTo(xa, y1, xb, y, x, y);
  20481. break;
  20482. case 35: // flex
  20483. xa = x + stack.shift(); ya = y + stack.shift();
  20484. xb = xa + stack.shift(); yb = ya + stack.shift();
  20485. x = xb + stack.shift(); y = yb + stack.shift();
  20486. bezierCurveTo(xa, ya, xb, yb, x, y);
  20487. xa = x + stack.shift(); ya = y + stack.shift();
  20488. xb = xa + stack.shift(); yb = ya + stack.shift();
  20489. x = xb + stack.shift(); y = yb + stack.shift();
  20490. bezierCurveTo(xa, ya, xb, yb, x, y);
  20491. stack.pop(); // fd
  20492. break;
  20493. case 36: // hflex1
  20494. xa = x + stack.shift(); y1 = y + stack.shift();
  20495. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20496. x = xb + stack.shift();
  20497. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20498. xa = x + stack.shift();
  20499. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20500. x = xb + stack.shift();
  20501. bezierCurveTo(xa, y2, xb, y3, x, y);
  20502. break;
  20503. case 37: // flex1
  20504. var x0 = x, y0 = y;
  20505. xa = x + stack.shift(); ya = y + stack.shift();
  20506. xb = xa + stack.shift(); yb = ya + stack.shift();
  20507. x = xb + stack.shift(); y = yb + stack.shift();
  20508. bezierCurveTo(xa, ya, xb, yb, x, y);
  20509. xa = x + stack.shift(); ya = y + stack.shift();
  20510. xb = xa + stack.shift(); yb = ya + stack.shift();
  20511. x = xb; y = yb;
  20512. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20513. x += stack.shift();
  20514. } else {
  20515. y += stack.shift();
  20516. }
  20517. bezierCurveTo(xa, ya, xb, yb, x, y);
  20518. break;
  20519. default:
  20520. error('unknown operator: 12 ' + v);
  20521. }
  20522. break;
  20523. case 14: // endchar
  20524. if (stack.length >= 4) {
  20525. var achar = stack.pop();
  20526. var bchar = stack.pop();
  20527. y = stack.pop();
  20528. x = stack.pop();
  20529. cmds.push({cmd: 'save'});
  20530. cmds.push({cmd: 'translate', args: [x, y]});
  20531. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20532. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20533. compileCharString(font.glyphs[gid], cmds, font);
  20534. cmds.push({cmd: 'restore'});
  20535. gid = lookupCmap(font.cmap, String.fromCharCode(
  20536. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20537. compileCharString(font.glyphs[gid], cmds, font);
  20538. }
  20539. return;
  20540. case 18: // hstemhm
  20541. stems += stack.length >> 1;
  20542. stackClean = true;
  20543. break;
  20544. case 19: // hintmask
  20545. stems += stack.length >> 1;
  20546. i += (stems + 7) >> 3;
  20547. stackClean = true;
  20548. break;
  20549. case 20: // cntrmask
  20550. stems += stack.length >> 1;
  20551. i += (stems + 7) >> 3;
  20552. stackClean = true;
  20553. break;
  20554. case 21: // rmoveto
  20555. y += stack.pop();
  20556. x += stack.pop();
  20557. moveTo(x, y);
  20558. stackClean = true;
  20559. break;
  20560. case 22: // hmoveto
  20561. x += stack.pop();
  20562. moveTo(x, y);
  20563. stackClean = true;
  20564. break;
  20565. case 23: // vstemhm
  20566. stems += stack.length >> 1;
  20567. stackClean = true;
  20568. break;
  20569. case 24: // rcurveline
  20570. while (stack.length > 2) {
  20571. xa = x + stack.shift(); ya = y + stack.shift();
  20572. xb = xa + stack.shift(); yb = ya + stack.shift();
  20573. x = xb + stack.shift(); y = yb + stack.shift();
  20574. bezierCurveTo(xa, ya, xb, yb, x, y);
  20575. }
  20576. x += stack.shift();
  20577. y += stack.shift();
  20578. lineTo(x, y);
  20579. break;
  20580. case 25: // rlinecurve
  20581. while (stack.length > 6) {
  20582. x += stack.shift();
  20583. y += stack.shift();
  20584. lineTo(x, y);
  20585. }
  20586. xa = x + stack.shift(); ya = y + stack.shift();
  20587. xb = xa + stack.shift(); yb = ya + stack.shift();
  20588. x = xb + stack.shift(); y = yb + stack.shift();
  20589. bezierCurveTo(xa, ya, xb, yb, x, y);
  20590. break;
  20591. case 26: // vvcurveto
  20592. if (stack.length % 2) {
  20593. x += stack.shift();
  20594. }
  20595. while (stack.length > 0) {
  20596. xa = x; ya = y + stack.shift();
  20597. xb = xa + stack.shift(); yb = ya + stack.shift();
  20598. x = xb; y = yb + stack.shift();
  20599. bezierCurveTo(xa, ya, xb, yb, x, y);
  20600. }
  20601. break;
  20602. case 27: // hhcurveto
  20603. if (stack.length % 2) {
  20604. y += stack.shift();
  20605. }
  20606. while (stack.length > 0) {
  20607. xa = x + stack.shift(); ya = y;
  20608. xb = xa + stack.shift(); yb = ya + stack.shift();
  20609. x = xb + stack.shift(); y = yb;
  20610. bezierCurveTo(xa, ya, xb, yb, x, y);
  20611. }
  20612. break;
  20613. case 28:
  20614. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20615. i += 2;
  20616. break;
  20617. case 29: // callgsubr
  20618. n = stack.pop() + font.gsubrsBias;
  20619. subrCode = font.gsubrs[n];
  20620. if (subrCode) {
  20621. parse(subrCode);
  20622. }
  20623. break;
  20624. case 30: // vhcurveto
  20625. while (stack.length > 0) {
  20626. xa = x; ya = y + stack.shift();
  20627. xb = xa + stack.shift(); yb = ya + stack.shift();
  20628. x = xb + stack.shift();
  20629. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20630. bezierCurveTo(xa, ya, xb, yb, x, y);
  20631. if (stack.length === 0) {
  20632. break;
  20633. }
  20634. xa = x + stack.shift(); ya = y;
  20635. xb = xa + stack.shift(); yb = ya + stack.shift();
  20636. y = yb + stack.shift();
  20637. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20638. bezierCurveTo(xa, ya, xb, yb, x, y);
  20639. }
  20640. break;
  20641. case 31: // hvcurveto
  20642. while (stack.length > 0) {
  20643. xa = x + stack.shift(); ya = y;
  20644. xb = xa + stack.shift(); yb = ya + stack.shift();
  20645. y = yb + stack.shift();
  20646. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20647. bezierCurveTo(xa, ya, xb, yb, x, y);
  20648. if (stack.length === 0) {
  20649. break;
  20650. }
  20651. xa = x; ya = y + stack.shift();
  20652. xb = xa + stack.shift(); yb = ya + stack.shift();
  20653. x = xb + stack.shift();
  20654. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20655. bezierCurveTo(xa, ya, xb, yb, x, y);
  20656. }
  20657. break;
  20658. default:
  20659. if (v < 32) {
  20660. error('unknown operator: ' + v);
  20661. }
  20662. if (v < 247) {
  20663. stack.push(v - 139);
  20664. } else if (v < 251) {
  20665. stack.push((v - 247) * 256 + code[i++] + 108);
  20666. } else if (v < 255) {
  20667. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20668. } else {
  20669. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20670. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20671. i += 4;
  20672. }
  20673. break;
  20674. }
  20675. if (stackClean) {
  20676. stack.length = 0;
  20677. }
  20678. }
  20679. }
  20680. parse(code);
  20681. }
  20682. var noop = '';
  20683. function CompiledFont(fontMatrix) {
  20684. this.compiledGlyphs = {};
  20685. this.fontMatrix = fontMatrix;
  20686. }
  20687. CompiledFont.prototype = {
  20688. getPathJs: function (unicode) {
  20689. var gid = lookupCmap(this.cmap, unicode);
  20690. var fn = this.compiledGlyphs[gid];
  20691. if (!fn) {
  20692. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20693. }
  20694. return fn;
  20695. },
  20696. compileGlyph: function (code) {
  20697. if (!code || code.length === 0 || code[0] === 14) {
  20698. return noop;
  20699. }
  20700. var cmds = [];
  20701. cmds.push({cmd: 'save'});
  20702. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  20703. cmds.push({cmd: 'scale', args: ['size', '-size']});
  20704. this.compileGlyphImpl(code, cmds);
  20705. cmds.push({cmd: 'restore'});
  20706. return cmds;
  20707. },
  20708. compileGlyphImpl: function () {
  20709. error('Children classes should implement this.');
  20710. },
  20711. hasBuiltPath: function (unicode) {
  20712. var gid = lookupCmap(this.cmap, unicode);
  20713. return gid in this.compiledGlyphs;
  20714. }
  20715. };
  20716. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20717. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20718. CompiledFont.call(this, fontMatrix);
  20719. this.glyphs = glyphs;
  20720. this.cmap = cmap;
  20721. this.compiledGlyphs = [];
  20722. }
  20723. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20724. compileGlyphImpl: function (code, cmds) {
  20725. compileGlyf(code, cmds, this);
  20726. }
  20727. });
  20728. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20729. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20730. CompiledFont.call(this, fontMatrix);
  20731. this.glyphs = cffInfo.glyphs;
  20732. this.gsubrs = cffInfo.gsubrs || [];
  20733. this.subrs = cffInfo.subrs || [];
  20734. this.cmap = cmap;
  20735. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20736. this.compiledGlyphs = [];
  20737. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20738. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20739. this.subrsBias = (this.subrs.length < 1240 ?
  20740. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20741. }
  20742. Util.inherit(Type2Compiled, CompiledFont, {
  20743. compileGlyphImpl: function (code, cmds) {
  20744. compileCharString(code, cmds, this);
  20745. }
  20746. });
  20747. return {
  20748. create: function FontRendererFactory_create(font) {
  20749. var data = new Uint8Array(font.data);
  20750. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20751. var numTables = getUshort(data, 4);
  20752. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20753. var tag = bytesToString(data.subarray(p, p + 4));
  20754. var offset = getLong(data, p + 8);
  20755. var length = getLong(data, p + 12);
  20756. switch (tag) {
  20757. case 'cmap':
  20758. cmap = parseCmap(data, offset, offset + length);
  20759. break;
  20760. case 'glyf':
  20761. glyf = data.subarray(offset, offset + length);
  20762. break;
  20763. case 'loca':
  20764. loca = data.subarray(offset, offset + length);
  20765. break;
  20766. case 'head':
  20767. unitsPerEm = getUshort(data, offset + 18);
  20768. indexToLocFormat = getUshort(data, offset + 50);
  20769. break;
  20770. case 'CFF ':
  20771. cff = parseCff(data, offset, offset + length);
  20772. break;
  20773. }
  20774. }
  20775. if (glyf) {
  20776. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20777. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20778. return new TrueTypeCompiled(
  20779. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20780. } else {
  20781. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20782. }
  20783. }
  20784. };
  20785. })();
  20786. var GlyphsUnicode = {
  20787. A: 0x0041,
  20788. AE: 0x00C6,
  20789. AEacute: 0x01FC,
  20790. AEmacron: 0x01E2,
  20791. AEsmall: 0xF7E6,
  20792. Aacute: 0x00C1,
  20793. Aacutesmall: 0xF7E1,
  20794. Abreve: 0x0102,
  20795. Abreveacute: 0x1EAE,
  20796. Abrevecyrillic: 0x04D0,
  20797. Abrevedotbelow: 0x1EB6,
  20798. Abrevegrave: 0x1EB0,
  20799. Abrevehookabove: 0x1EB2,
  20800. Abrevetilde: 0x1EB4,
  20801. Acaron: 0x01CD,
  20802. Acircle: 0x24B6,
  20803. Acircumflex: 0x00C2,
  20804. Acircumflexacute: 0x1EA4,
  20805. Acircumflexdotbelow: 0x1EAC,
  20806. Acircumflexgrave: 0x1EA6,
  20807. Acircumflexhookabove: 0x1EA8,
  20808. Acircumflexsmall: 0xF7E2,
  20809. Acircumflextilde: 0x1EAA,
  20810. Acute: 0xF6C9,
  20811. Acutesmall: 0xF7B4,
  20812. Acyrillic: 0x0410,
  20813. Adblgrave: 0x0200,
  20814. Adieresis: 0x00C4,
  20815. Adieresiscyrillic: 0x04D2,
  20816. Adieresismacron: 0x01DE,
  20817. Adieresissmall: 0xF7E4,
  20818. Adotbelow: 0x1EA0,
  20819. Adotmacron: 0x01E0,
  20820. Agrave: 0x00C0,
  20821. Agravesmall: 0xF7E0,
  20822. Ahookabove: 0x1EA2,
  20823. Aiecyrillic: 0x04D4,
  20824. Ainvertedbreve: 0x0202,
  20825. Alpha: 0x0391,
  20826. Alphatonos: 0x0386,
  20827. Amacron: 0x0100,
  20828. Amonospace: 0xFF21,
  20829. Aogonek: 0x0104,
  20830. Aring: 0x00C5,
  20831. Aringacute: 0x01FA,
  20832. Aringbelow: 0x1E00,
  20833. Aringsmall: 0xF7E5,
  20834. Asmall: 0xF761,
  20835. Atilde: 0x00C3,
  20836. Atildesmall: 0xF7E3,
  20837. Aybarmenian: 0x0531,
  20838. B: 0x0042,
  20839. Bcircle: 0x24B7,
  20840. Bdotaccent: 0x1E02,
  20841. Bdotbelow: 0x1E04,
  20842. Becyrillic: 0x0411,
  20843. Benarmenian: 0x0532,
  20844. Beta: 0x0392,
  20845. Bhook: 0x0181,
  20846. Blinebelow: 0x1E06,
  20847. Bmonospace: 0xFF22,
  20848. Brevesmall: 0xF6F4,
  20849. Bsmall: 0xF762,
  20850. Btopbar: 0x0182,
  20851. C: 0x0043,
  20852. Caarmenian: 0x053E,
  20853. Cacute: 0x0106,
  20854. Caron: 0xF6CA,
  20855. Caronsmall: 0xF6F5,
  20856. Ccaron: 0x010C,
  20857. Ccedilla: 0x00C7,
  20858. Ccedillaacute: 0x1E08,
  20859. Ccedillasmall: 0xF7E7,
  20860. Ccircle: 0x24B8,
  20861. Ccircumflex: 0x0108,
  20862. Cdot: 0x010A,
  20863. Cdotaccent: 0x010A,
  20864. Cedillasmall: 0xF7B8,
  20865. Chaarmenian: 0x0549,
  20866. Cheabkhasiancyrillic: 0x04BC,
  20867. Checyrillic: 0x0427,
  20868. Chedescenderabkhasiancyrillic: 0x04BE,
  20869. Chedescendercyrillic: 0x04B6,
  20870. Chedieresiscyrillic: 0x04F4,
  20871. Cheharmenian: 0x0543,
  20872. Chekhakassiancyrillic: 0x04CB,
  20873. Cheverticalstrokecyrillic: 0x04B8,
  20874. Chi: 0x03A7,
  20875. Chook: 0x0187,
  20876. Circumflexsmall: 0xF6F6,
  20877. Cmonospace: 0xFF23,
  20878. Coarmenian: 0x0551,
  20879. Csmall: 0xF763,
  20880. D: 0x0044,
  20881. DZ: 0x01F1,
  20882. DZcaron: 0x01C4,
  20883. Daarmenian: 0x0534,
  20884. Dafrican: 0x0189,
  20885. Dcaron: 0x010E,
  20886. Dcedilla: 0x1E10,
  20887. Dcircle: 0x24B9,
  20888. Dcircumflexbelow: 0x1E12,
  20889. Dcroat: 0x0110,
  20890. Ddotaccent: 0x1E0A,
  20891. Ddotbelow: 0x1E0C,
  20892. Decyrillic: 0x0414,
  20893. Deicoptic: 0x03EE,
  20894. Delta: 0x2206,
  20895. Deltagreek: 0x0394,
  20896. Dhook: 0x018A,
  20897. Dieresis: 0xF6CB,
  20898. DieresisAcute: 0xF6CC,
  20899. DieresisGrave: 0xF6CD,
  20900. Dieresissmall: 0xF7A8,
  20901. Digammagreek: 0x03DC,
  20902. Djecyrillic: 0x0402,
  20903. Dlinebelow: 0x1E0E,
  20904. Dmonospace: 0xFF24,
  20905. Dotaccentsmall: 0xF6F7,
  20906. Dslash: 0x0110,
  20907. Dsmall: 0xF764,
  20908. Dtopbar: 0x018B,
  20909. Dz: 0x01F2,
  20910. Dzcaron: 0x01C5,
  20911. Dzeabkhasiancyrillic: 0x04E0,
  20912. Dzecyrillic: 0x0405,
  20913. Dzhecyrillic: 0x040F,
  20914. E: 0x0045,
  20915. Eacute: 0x00C9,
  20916. Eacutesmall: 0xF7E9,
  20917. Ebreve: 0x0114,
  20918. Ecaron: 0x011A,
  20919. Ecedillabreve: 0x1E1C,
  20920. Echarmenian: 0x0535,
  20921. Ecircle: 0x24BA,
  20922. Ecircumflex: 0x00CA,
  20923. Ecircumflexacute: 0x1EBE,
  20924. Ecircumflexbelow: 0x1E18,
  20925. Ecircumflexdotbelow: 0x1EC6,
  20926. Ecircumflexgrave: 0x1EC0,
  20927. Ecircumflexhookabove: 0x1EC2,
  20928. Ecircumflexsmall: 0xF7EA,
  20929. Ecircumflextilde: 0x1EC4,
  20930. Ecyrillic: 0x0404,
  20931. Edblgrave: 0x0204,
  20932. Edieresis: 0x00CB,
  20933. Edieresissmall: 0xF7EB,
  20934. Edot: 0x0116,
  20935. Edotaccent: 0x0116,
  20936. Edotbelow: 0x1EB8,
  20937. Efcyrillic: 0x0424,
  20938. Egrave: 0x00C8,
  20939. Egravesmall: 0xF7E8,
  20940. Eharmenian: 0x0537,
  20941. Ehookabove: 0x1EBA,
  20942. Eightroman: 0x2167,
  20943. Einvertedbreve: 0x0206,
  20944. Eiotifiedcyrillic: 0x0464,
  20945. Elcyrillic: 0x041B,
  20946. Elevenroman: 0x216A,
  20947. Emacron: 0x0112,
  20948. Emacronacute: 0x1E16,
  20949. Emacrongrave: 0x1E14,
  20950. Emcyrillic: 0x041C,
  20951. Emonospace: 0xFF25,
  20952. Encyrillic: 0x041D,
  20953. Endescendercyrillic: 0x04A2,
  20954. Eng: 0x014A,
  20955. Enghecyrillic: 0x04A4,
  20956. Enhookcyrillic: 0x04C7,
  20957. Eogonek: 0x0118,
  20958. Eopen: 0x0190,
  20959. Epsilon: 0x0395,
  20960. Epsilontonos: 0x0388,
  20961. Ercyrillic: 0x0420,
  20962. Ereversed: 0x018E,
  20963. Ereversedcyrillic: 0x042D,
  20964. Escyrillic: 0x0421,
  20965. Esdescendercyrillic: 0x04AA,
  20966. Esh: 0x01A9,
  20967. Esmall: 0xF765,
  20968. Eta: 0x0397,
  20969. Etarmenian: 0x0538,
  20970. Etatonos: 0x0389,
  20971. Eth: 0x00D0,
  20972. Ethsmall: 0xF7F0,
  20973. Etilde: 0x1EBC,
  20974. Etildebelow: 0x1E1A,
  20975. Euro: 0x20AC,
  20976. Ezh: 0x01B7,
  20977. Ezhcaron: 0x01EE,
  20978. Ezhreversed: 0x01B8,
  20979. F: 0x0046,
  20980. Fcircle: 0x24BB,
  20981. Fdotaccent: 0x1E1E,
  20982. Feharmenian: 0x0556,
  20983. Feicoptic: 0x03E4,
  20984. Fhook: 0x0191,
  20985. Fitacyrillic: 0x0472,
  20986. Fiveroman: 0x2164,
  20987. Fmonospace: 0xFF26,
  20988. Fourroman: 0x2163,
  20989. Fsmall: 0xF766,
  20990. G: 0x0047,
  20991. GBsquare: 0x3387,
  20992. Gacute: 0x01F4,
  20993. Gamma: 0x0393,
  20994. Gammaafrican: 0x0194,
  20995. Gangiacoptic: 0x03EA,
  20996. Gbreve: 0x011E,
  20997. Gcaron: 0x01E6,
  20998. Gcedilla: 0x0122,
  20999. Gcircle: 0x24BC,
  21000. Gcircumflex: 0x011C,
  21001. Gcommaaccent: 0x0122,
  21002. Gdot: 0x0120,
  21003. Gdotaccent: 0x0120,
  21004. Gecyrillic: 0x0413,
  21005. Ghadarmenian: 0x0542,
  21006. Ghemiddlehookcyrillic: 0x0494,
  21007. Ghestrokecyrillic: 0x0492,
  21008. Gheupturncyrillic: 0x0490,
  21009. Ghook: 0x0193,
  21010. Gimarmenian: 0x0533,
  21011. Gjecyrillic: 0x0403,
  21012. Gmacron: 0x1E20,
  21013. Gmonospace: 0xFF27,
  21014. Grave: 0xF6CE,
  21015. Gravesmall: 0xF760,
  21016. Gsmall: 0xF767,
  21017. Gsmallhook: 0x029B,
  21018. Gstroke: 0x01E4,
  21019. H: 0x0048,
  21020. H18533: 0x25CF,
  21021. H18543: 0x25AA,
  21022. H18551: 0x25AB,
  21023. H22073: 0x25A1,
  21024. HPsquare: 0x33CB,
  21025. Haabkhasiancyrillic: 0x04A8,
  21026. Hadescendercyrillic: 0x04B2,
  21027. Hardsigncyrillic: 0x042A,
  21028. Hbar: 0x0126,
  21029. Hbrevebelow: 0x1E2A,
  21030. Hcedilla: 0x1E28,
  21031. Hcircle: 0x24BD,
  21032. Hcircumflex: 0x0124,
  21033. Hdieresis: 0x1E26,
  21034. Hdotaccent: 0x1E22,
  21035. Hdotbelow: 0x1E24,
  21036. Hmonospace: 0xFF28,
  21037. Hoarmenian: 0x0540,
  21038. Horicoptic: 0x03E8,
  21039. Hsmall: 0xF768,
  21040. Hungarumlaut: 0xF6CF,
  21041. Hungarumlautsmall: 0xF6F8,
  21042. Hzsquare: 0x3390,
  21043. I: 0x0049,
  21044. IAcyrillic: 0x042F,
  21045. IJ: 0x0132,
  21046. IUcyrillic: 0x042E,
  21047. Iacute: 0x00CD,
  21048. Iacutesmall: 0xF7ED,
  21049. Ibreve: 0x012C,
  21050. Icaron: 0x01CF,
  21051. Icircle: 0x24BE,
  21052. Icircumflex: 0x00CE,
  21053. Icircumflexsmall: 0xF7EE,
  21054. Icyrillic: 0x0406,
  21055. Idblgrave: 0x0208,
  21056. Idieresis: 0x00CF,
  21057. Idieresisacute: 0x1E2E,
  21058. Idieresiscyrillic: 0x04E4,
  21059. Idieresissmall: 0xF7EF,
  21060. Idot: 0x0130,
  21061. Idotaccent: 0x0130,
  21062. Idotbelow: 0x1ECA,
  21063. Iebrevecyrillic: 0x04D6,
  21064. Iecyrillic: 0x0415,
  21065. Ifraktur: 0x2111,
  21066. Igrave: 0x00CC,
  21067. Igravesmall: 0xF7EC,
  21068. Ihookabove: 0x1EC8,
  21069. Iicyrillic: 0x0418,
  21070. Iinvertedbreve: 0x020A,
  21071. Iishortcyrillic: 0x0419,
  21072. Imacron: 0x012A,
  21073. Imacroncyrillic: 0x04E2,
  21074. Imonospace: 0xFF29,
  21075. Iniarmenian: 0x053B,
  21076. Iocyrillic: 0x0401,
  21077. Iogonek: 0x012E,
  21078. Iota: 0x0399,
  21079. Iotaafrican: 0x0196,
  21080. Iotadieresis: 0x03AA,
  21081. Iotatonos: 0x038A,
  21082. Ismall: 0xF769,
  21083. Istroke: 0x0197,
  21084. Itilde: 0x0128,
  21085. Itildebelow: 0x1E2C,
  21086. Izhitsacyrillic: 0x0474,
  21087. Izhitsadblgravecyrillic: 0x0476,
  21088. J: 0x004A,
  21089. Jaarmenian: 0x0541,
  21090. Jcircle: 0x24BF,
  21091. Jcircumflex: 0x0134,
  21092. Jecyrillic: 0x0408,
  21093. Jheharmenian: 0x054B,
  21094. Jmonospace: 0xFF2A,
  21095. Jsmall: 0xF76A,
  21096. K: 0x004B,
  21097. KBsquare: 0x3385,
  21098. KKsquare: 0x33CD,
  21099. Kabashkircyrillic: 0x04A0,
  21100. Kacute: 0x1E30,
  21101. Kacyrillic: 0x041A,
  21102. Kadescendercyrillic: 0x049A,
  21103. Kahookcyrillic: 0x04C3,
  21104. Kappa: 0x039A,
  21105. Kastrokecyrillic: 0x049E,
  21106. Kaverticalstrokecyrillic: 0x049C,
  21107. Kcaron: 0x01E8,
  21108. Kcedilla: 0x0136,
  21109. Kcircle: 0x24C0,
  21110. Kcommaaccent: 0x0136,
  21111. Kdotbelow: 0x1E32,
  21112. Keharmenian: 0x0554,
  21113. Kenarmenian: 0x053F,
  21114. Khacyrillic: 0x0425,
  21115. Kheicoptic: 0x03E6,
  21116. Khook: 0x0198,
  21117. Kjecyrillic: 0x040C,
  21118. Klinebelow: 0x1E34,
  21119. Kmonospace: 0xFF2B,
  21120. Koppacyrillic: 0x0480,
  21121. Koppagreek: 0x03DE,
  21122. Ksicyrillic: 0x046E,
  21123. Ksmall: 0xF76B,
  21124. L: 0x004C,
  21125. LJ: 0x01C7,
  21126. LL: 0xF6BF,
  21127. Lacute: 0x0139,
  21128. Lambda: 0x039B,
  21129. Lcaron: 0x013D,
  21130. Lcedilla: 0x013B,
  21131. Lcircle: 0x24C1,
  21132. Lcircumflexbelow: 0x1E3C,
  21133. Lcommaaccent: 0x013B,
  21134. Ldot: 0x013F,
  21135. Ldotaccent: 0x013F,
  21136. Ldotbelow: 0x1E36,
  21137. Ldotbelowmacron: 0x1E38,
  21138. Liwnarmenian: 0x053C,
  21139. Lj: 0x01C8,
  21140. Ljecyrillic: 0x0409,
  21141. Llinebelow: 0x1E3A,
  21142. Lmonospace: 0xFF2C,
  21143. Lslash: 0x0141,
  21144. Lslashsmall: 0xF6F9,
  21145. Lsmall: 0xF76C,
  21146. M: 0x004D,
  21147. MBsquare: 0x3386,
  21148. Macron: 0xF6D0,
  21149. Macronsmall: 0xF7AF,
  21150. Macute: 0x1E3E,
  21151. Mcircle: 0x24C2,
  21152. Mdotaccent: 0x1E40,
  21153. Mdotbelow: 0x1E42,
  21154. Menarmenian: 0x0544,
  21155. Mmonospace: 0xFF2D,
  21156. Msmall: 0xF76D,
  21157. Mturned: 0x019C,
  21158. Mu: 0x039C,
  21159. N: 0x004E,
  21160. NJ: 0x01CA,
  21161. Nacute: 0x0143,
  21162. Ncaron: 0x0147,
  21163. Ncedilla: 0x0145,
  21164. Ncircle: 0x24C3,
  21165. Ncircumflexbelow: 0x1E4A,
  21166. Ncommaaccent: 0x0145,
  21167. Ndotaccent: 0x1E44,
  21168. Ndotbelow: 0x1E46,
  21169. Nhookleft: 0x019D,
  21170. Nineroman: 0x2168,
  21171. Nj: 0x01CB,
  21172. Njecyrillic: 0x040A,
  21173. Nlinebelow: 0x1E48,
  21174. Nmonospace: 0xFF2E,
  21175. Nowarmenian: 0x0546,
  21176. Nsmall: 0xF76E,
  21177. Ntilde: 0x00D1,
  21178. Ntildesmall: 0xF7F1,
  21179. Nu: 0x039D,
  21180. O: 0x004F,
  21181. OE: 0x0152,
  21182. OEsmall: 0xF6FA,
  21183. Oacute: 0x00D3,
  21184. Oacutesmall: 0xF7F3,
  21185. Obarredcyrillic: 0x04E8,
  21186. Obarreddieresiscyrillic: 0x04EA,
  21187. Obreve: 0x014E,
  21188. Ocaron: 0x01D1,
  21189. Ocenteredtilde: 0x019F,
  21190. Ocircle: 0x24C4,
  21191. Ocircumflex: 0x00D4,
  21192. Ocircumflexacute: 0x1ED0,
  21193. Ocircumflexdotbelow: 0x1ED8,
  21194. Ocircumflexgrave: 0x1ED2,
  21195. Ocircumflexhookabove: 0x1ED4,
  21196. Ocircumflexsmall: 0xF7F4,
  21197. Ocircumflextilde: 0x1ED6,
  21198. Ocyrillic: 0x041E,
  21199. Odblacute: 0x0150,
  21200. Odblgrave: 0x020C,
  21201. Odieresis: 0x00D6,
  21202. Odieresiscyrillic: 0x04E6,
  21203. Odieresissmall: 0xF7F6,
  21204. Odotbelow: 0x1ECC,
  21205. Ogoneksmall: 0xF6FB,
  21206. Ograve: 0x00D2,
  21207. Ogravesmall: 0xF7F2,
  21208. Oharmenian: 0x0555,
  21209. Ohm: 0x2126,
  21210. Ohookabove: 0x1ECE,
  21211. Ohorn: 0x01A0,
  21212. Ohornacute: 0x1EDA,
  21213. Ohorndotbelow: 0x1EE2,
  21214. Ohorngrave: 0x1EDC,
  21215. Ohornhookabove: 0x1EDE,
  21216. Ohorntilde: 0x1EE0,
  21217. Ohungarumlaut: 0x0150,
  21218. Oi: 0x01A2,
  21219. Oinvertedbreve: 0x020E,
  21220. Omacron: 0x014C,
  21221. Omacronacute: 0x1E52,
  21222. Omacrongrave: 0x1E50,
  21223. Omega: 0x2126,
  21224. Omegacyrillic: 0x0460,
  21225. Omegagreek: 0x03A9,
  21226. Omegaroundcyrillic: 0x047A,
  21227. Omegatitlocyrillic: 0x047C,
  21228. Omegatonos: 0x038F,
  21229. Omicron: 0x039F,
  21230. Omicrontonos: 0x038C,
  21231. Omonospace: 0xFF2F,
  21232. Oneroman: 0x2160,
  21233. Oogonek: 0x01EA,
  21234. Oogonekmacron: 0x01EC,
  21235. Oopen: 0x0186,
  21236. Oslash: 0x00D8,
  21237. Oslashacute: 0x01FE,
  21238. Oslashsmall: 0xF7F8,
  21239. Osmall: 0xF76F,
  21240. Ostrokeacute: 0x01FE,
  21241. Otcyrillic: 0x047E,
  21242. Otilde: 0x00D5,
  21243. Otildeacute: 0x1E4C,
  21244. Otildedieresis: 0x1E4E,
  21245. Otildesmall: 0xF7F5,
  21246. P: 0x0050,
  21247. Pacute: 0x1E54,
  21248. Pcircle: 0x24C5,
  21249. Pdotaccent: 0x1E56,
  21250. Pecyrillic: 0x041F,
  21251. Peharmenian: 0x054A,
  21252. Pemiddlehookcyrillic: 0x04A6,
  21253. Phi: 0x03A6,
  21254. Phook: 0x01A4,
  21255. Pi: 0x03A0,
  21256. Piwrarmenian: 0x0553,
  21257. Pmonospace: 0xFF30,
  21258. Psi: 0x03A8,
  21259. Psicyrillic: 0x0470,
  21260. Psmall: 0xF770,
  21261. Q: 0x0051,
  21262. Qcircle: 0x24C6,
  21263. Qmonospace: 0xFF31,
  21264. Qsmall: 0xF771,
  21265. R: 0x0052,
  21266. Raarmenian: 0x054C,
  21267. Racute: 0x0154,
  21268. Rcaron: 0x0158,
  21269. Rcedilla: 0x0156,
  21270. Rcircle: 0x24C7,
  21271. Rcommaaccent: 0x0156,
  21272. Rdblgrave: 0x0210,
  21273. Rdotaccent: 0x1E58,
  21274. Rdotbelow: 0x1E5A,
  21275. Rdotbelowmacron: 0x1E5C,
  21276. Reharmenian: 0x0550,
  21277. Rfraktur: 0x211C,
  21278. Rho: 0x03A1,
  21279. Ringsmall: 0xF6FC,
  21280. Rinvertedbreve: 0x0212,
  21281. Rlinebelow: 0x1E5E,
  21282. Rmonospace: 0xFF32,
  21283. Rsmall: 0xF772,
  21284. Rsmallinverted: 0x0281,
  21285. Rsmallinvertedsuperior: 0x02B6,
  21286. S: 0x0053,
  21287. SF010000: 0x250C,
  21288. SF020000: 0x2514,
  21289. SF030000: 0x2510,
  21290. SF040000: 0x2518,
  21291. SF050000: 0x253C,
  21292. SF060000: 0x252C,
  21293. SF070000: 0x2534,
  21294. SF080000: 0x251C,
  21295. SF090000: 0x2524,
  21296. SF100000: 0x2500,
  21297. SF110000: 0x2502,
  21298. SF190000: 0x2561,
  21299. SF200000: 0x2562,
  21300. SF210000: 0x2556,
  21301. SF220000: 0x2555,
  21302. SF230000: 0x2563,
  21303. SF240000: 0x2551,
  21304. SF250000: 0x2557,
  21305. SF260000: 0x255D,
  21306. SF270000: 0x255C,
  21307. SF280000: 0x255B,
  21308. SF360000: 0x255E,
  21309. SF370000: 0x255F,
  21310. SF380000: 0x255A,
  21311. SF390000: 0x2554,
  21312. SF400000: 0x2569,
  21313. SF410000: 0x2566,
  21314. SF420000: 0x2560,
  21315. SF430000: 0x2550,
  21316. SF440000: 0x256C,
  21317. SF450000: 0x2567,
  21318. SF460000: 0x2568,
  21319. SF470000: 0x2564,
  21320. SF480000: 0x2565,
  21321. SF490000: 0x2559,
  21322. SF500000: 0x2558,
  21323. SF510000: 0x2552,
  21324. SF520000: 0x2553,
  21325. SF530000: 0x256B,
  21326. SF540000: 0x256A,
  21327. Sacute: 0x015A,
  21328. Sacutedotaccent: 0x1E64,
  21329. Sampigreek: 0x03E0,
  21330. Scaron: 0x0160,
  21331. Scarondotaccent: 0x1E66,
  21332. Scaronsmall: 0xF6FD,
  21333. Scedilla: 0x015E,
  21334. Schwa: 0x018F,
  21335. Schwacyrillic: 0x04D8,
  21336. Schwadieresiscyrillic: 0x04DA,
  21337. Scircle: 0x24C8,
  21338. Scircumflex: 0x015C,
  21339. Scommaaccent: 0x0218,
  21340. Sdotaccent: 0x1E60,
  21341. Sdotbelow: 0x1E62,
  21342. Sdotbelowdotaccent: 0x1E68,
  21343. Seharmenian: 0x054D,
  21344. Sevenroman: 0x2166,
  21345. Shaarmenian: 0x0547,
  21346. Shacyrillic: 0x0428,
  21347. Shchacyrillic: 0x0429,
  21348. Sheicoptic: 0x03E2,
  21349. Shhacyrillic: 0x04BA,
  21350. Shimacoptic: 0x03EC,
  21351. Sigma: 0x03A3,
  21352. Sixroman: 0x2165,
  21353. Smonospace: 0xFF33,
  21354. Softsigncyrillic: 0x042C,
  21355. Ssmall: 0xF773,
  21356. Stigmagreek: 0x03DA,
  21357. T: 0x0054,
  21358. Tau: 0x03A4,
  21359. Tbar: 0x0166,
  21360. Tcaron: 0x0164,
  21361. Tcedilla: 0x0162,
  21362. Tcircle: 0x24C9,
  21363. Tcircumflexbelow: 0x1E70,
  21364. Tcommaaccent: 0x0162,
  21365. Tdotaccent: 0x1E6A,
  21366. Tdotbelow: 0x1E6C,
  21367. Tecyrillic: 0x0422,
  21368. Tedescendercyrillic: 0x04AC,
  21369. Tenroman: 0x2169,
  21370. Tetsecyrillic: 0x04B4,
  21371. Theta: 0x0398,
  21372. Thook: 0x01AC,
  21373. Thorn: 0x00DE,
  21374. Thornsmall: 0xF7FE,
  21375. Threeroman: 0x2162,
  21376. Tildesmall: 0xF6FE,
  21377. Tiwnarmenian: 0x054F,
  21378. Tlinebelow: 0x1E6E,
  21379. Tmonospace: 0xFF34,
  21380. Toarmenian: 0x0539,
  21381. Tonefive: 0x01BC,
  21382. Tonesix: 0x0184,
  21383. Tonetwo: 0x01A7,
  21384. Tretroflexhook: 0x01AE,
  21385. Tsecyrillic: 0x0426,
  21386. Tshecyrillic: 0x040B,
  21387. Tsmall: 0xF774,
  21388. Twelveroman: 0x216B,
  21389. Tworoman: 0x2161,
  21390. U: 0x0055,
  21391. Uacute: 0x00DA,
  21392. Uacutesmall: 0xF7FA,
  21393. Ubreve: 0x016C,
  21394. Ucaron: 0x01D3,
  21395. Ucircle: 0x24CA,
  21396. Ucircumflex: 0x00DB,
  21397. Ucircumflexbelow: 0x1E76,
  21398. Ucircumflexsmall: 0xF7FB,
  21399. Ucyrillic: 0x0423,
  21400. Udblacute: 0x0170,
  21401. Udblgrave: 0x0214,
  21402. Udieresis: 0x00DC,
  21403. Udieresisacute: 0x01D7,
  21404. Udieresisbelow: 0x1E72,
  21405. Udieresiscaron: 0x01D9,
  21406. Udieresiscyrillic: 0x04F0,
  21407. Udieresisgrave: 0x01DB,
  21408. Udieresismacron: 0x01D5,
  21409. Udieresissmall: 0xF7FC,
  21410. Udotbelow: 0x1EE4,
  21411. Ugrave: 0x00D9,
  21412. Ugravesmall: 0xF7F9,
  21413. Uhookabove: 0x1EE6,
  21414. Uhorn: 0x01AF,
  21415. Uhornacute: 0x1EE8,
  21416. Uhorndotbelow: 0x1EF0,
  21417. Uhorngrave: 0x1EEA,
  21418. Uhornhookabove: 0x1EEC,
  21419. Uhorntilde: 0x1EEE,
  21420. Uhungarumlaut: 0x0170,
  21421. Uhungarumlautcyrillic: 0x04F2,
  21422. Uinvertedbreve: 0x0216,
  21423. Ukcyrillic: 0x0478,
  21424. Umacron: 0x016A,
  21425. Umacroncyrillic: 0x04EE,
  21426. Umacrondieresis: 0x1E7A,
  21427. Umonospace: 0xFF35,
  21428. Uogonek: 0x0172,
  21429. Upsilon: 0x03A5,
  21430. Upsilon1: 0x03D2,
  21431. Upsilonacutehooksymbolgreek: 0x03D3,
  21432. Upsilonafrican: 0x01B1,
  21433. Upsilondieresis: 0x03AB,
  21434. Upsilondieresishooksymbolgreek: 0x03D4,
  21435. Upsilonhooksymbol: 0x03D2,
  21436. Upsilontonos: 0x038E,
  21437. Uring: 0x016E,
  21438. Ushortcyrillic: 0x040E,
  21439. Usmall: 0xF775,
  21440. Ustraightcyrillic: 0x04AE,
  21441. Ustraightstrokecyrillic: 0x04B0,
  21442. Utilde: 0x0168,
  21443. Utildeacute: 0x1E78,
  21444. Utildebelow: 0x1E74,
  21445. V: 0x0056,
  21446. Vcircle: 0x24CB,
  21447. Vdotbelow: 0x1E7E,
  21448. Vecyrillic: 0x0412,
  21449. Vewarmenian: 0x054E,
  21450. Vhook: 0x01B2,
  21451. Vmonospace: 0xFF36,
  21452. Voarmenian: 0x0548,
  21453. Vsmall: 0xF776,
  21454. Vtilde: 0x1E7C,
  21455. W: 0x0057,
  21456. Wacute: 0x1E82,
  21457. Wcircle: 0x24CC,
  21458. Wcircumflex: 0x0174,
  21459. Wdieresis: 0x1E84,
  21460. Wdotaccent: 0x1E86,
  21461. Wdotbelow: 0x1E88,
  21462. Wgrave: 0x1E80,
  21463. Wmonospace: 0xFF37,
  21464. Wsmall: 0xF777,
  21465. X: 0x0058,
  21466. Xcircle: 0x24CD,
  21467. Xdieresis: 0x1E8C,
  21468. Xdotaccent: 0x1E8A,
  21469. Xeharmenian: 0x053D,
  21470. Xi: 0x039E,
  21471. Xmonospace: 0xFF38,
  21472. Xsmall: 0xF778,
  21473. Y: 0x0059,
  21474. Yacute: 0x00DD,
  21475. Yacutesmall: 0xF7FD,
  21476. Yatcyrillic: 0x0462,
  21477. Ycircle: 0x24CE,
  21478. Ycircumflex: 0x0176,
  21479. Ydieresis: 0x0178,
  21480. Ydieresissmall: 0xF7FF,
  21481. Ydotaccent: 0x1E8E,
  21482. Ydotbelow: 0x1EF4,
  21483. Yericyrillic: 0x042B,
  21484. Yerudieresiscyrillic: 0x04F8,
  21485. Ygrave: 0x1EF2,
  21486. Yhook: 0x01B3,
  21487. Yhookabove: 0x1EF6,
  21488. Yiarmenian: 0x0545,
  21489. Yicyrillic: 0x0407,
  21490. Yiwnarmenian: 0x0552,
  21491. Ymonospace: 0xFF39,
  21492. Ysmall: 0xF779,
  21493. Ytilde: 0x1EF8,
  21494. Yusbigcyrillic: 0x046A,
  21495. Yusbigiotifiedcyrillic: 0x046C,
  21496. Yuslittlecyrillic: 0x0466,
  21497. Yuslittleiotifiedcyrillic: 0x0468,
  21498. Z: 0x005A,
  21499. Zaarmenian: 0x0536,
  21500. Zacute: 0x0179,
  21501. Zcaron: 0x017D,
  21502. Zcaronsmall: 0xF6FF,
  21503. Zcircle: 0x24CF,
  21504. Zcircumflex: 0x1E90,
  21505. Zdot: 0x017B,
  21506. Zdotaccent: 0x017B,
  21507. Zdotbelow: 0x1E92,
  21508. Zecyrillic: 0x0417,
  21509. Zedescendercyrillic: 0x0498,
  21510. Zedieresiscyrillic: 0x04DE,
  21511. Zeta: 0x0396,
  21512. Zhearmenian: 0x053A,
  21513. Zhebrevecyrillic: 0x04C1,
  21514. Zhecyrillic: 0x0416,
  21515. Zhedescendercyrillic: 0x0496,
  21516. Zhedieresiscyrillic: 0x04DC,
  21517. Zlinebelow: 0x1E94,
  21518. Zmonospace: 0xFF3A,
  21519. Zsmall: 0xF77A,
  21520. Zstroke: 0x01B5,
  21521. a: 0x0061,
  21522. aabengali: 0x0986,
  21523. aacute: 0x00E1,
  21524. aadeva: 0x0906,
  21525. aagujarati: 0x0A86,
  21526. aagurmukhi: 0x0A06,
  21527. aamatragurmukhi: 0x0A3E,
  21528. aarusquare: 0x3303,
  21529. aavowelsignbengali: 0x09BE,
  21530. aavowelsigndeva: 0x093E,
  21531. aavowelsigngujarati: 0x0ABE,
  21532. abbreviationmarkarmenian: 0x055F,
  21533. abbreviationsigndeva: 0x0970,
  21534. abengali: 0x0985,
  21535. abopomofo: 0x311A,
  21536. abreve: 0x0103,
  21537. abreveacute: 0x1EAF,
  21538. abrevecyrillic: 0x04D1,
  21539. abrevedotbelow: 0x1EB7,
  21540. abrevegrave: 0x1EB1,
  21541. abrevehookabove: 0x1EB3,
  21542. abrevetilde: 0x1EB5,
  21543. acaron: 0x01CE,
  21544. acircle: 0x24D0,
  21545. acircumflex: 0x00E2,
  21546. acircumflexacute: 0x1EA5,
  21547. acircumflexdotbelow: 0x1EAD,
  21548. acircumflexgrave: 0x1EA7,
  21549. acircumflexhookabove: 0x1EA9,
  21550. acircumflextilde: 0x1EAB,
  21551. acute: 0x00B4,
  21552. acutebelowcmb: 0x0317,
  21553. acutecmb: 0x0301,
  21554. acutecomb: 0x0301,
  21555. acutedeva: 0x0954,
  21556. acutelowmod: 0x02CF,
  21557. acutetonecmb: 0x0341,
  21558. acyrillic: 0x0430,
  21559. adblgrave: 0x0201,
  21560. addakgurmukhi: 0x0A71,
  21561. adeva: 0x0905,
  21562. adieresis: 0x00E4,
  21563. adieresiscyrillic: 0x04D3,
  21564. adieresismacron: 0x01DF,
  21565. adotbelow: 0x1EA1,
  21566. adotmacron: 0x01E1,
  21567. ae: 0x00E6,
  21568. aeacute: 0x01FD,
  21569. aekorean: 0x3150,
  21570. aemacron: 0x01E3,
  21571. afii00208: 0x2015,
  21572. afii08941: 0x20A4,
  21573. afii10017: 0x0410,
  21574. afii10018: 0x0411,
  21575. afii10019: 0x0412,
  21576. afii10020: 0x0413,
  21577. afii10021: 0x0414,
  21578. afii10022: 0x0415,
  21579. afii10023: 0x0401,
  21580. afii10024: 0x0416,
  21581. afii10025: 0x0417,
  21582. afii10026: 0x0418,
  21583. afii10027: 0x0419,
  21584. afii10028: 0x041A,
  21585. afii10029: 0x041B,
  21586. afii10030: 0x041C,
  21587. afii10031: 0x041D,
  21588. afii10032: 0x041E,
  21589. afii10033: 0x041F,
  21590. afii10034: 0x0420,
  21591. afii10035: 0x0421,
  21592. afii10036: 0x0422,
  21593. afii10037: 0x0423,
  21594. afii10038: 0x0424,
  21595. afii10039: 0x0425,
  21596. afii10040: 0x0426,
  21597. afii10041: 0x0427,
  21598. afii10042: 0x0428,
  21599. afii10043: 0x0429,
  21600. afii10044: 0x042A,
  21601. afii10045: 0x042B,
  21602. afii10046: 0x042C,
  21603. afii10047: 0x042D,
  21604. afii10048: 0x042E,
  21605. afii10049: 0x042F,
  21606. afii10050: 0x0490,
  21607. afii10051: 0x0402,
  21608. afii10052: 0x0403,
  21609. afii10053: 0x0404,
  21610. afii10054: 0x0405,
  21611. afii10055: 0x0406,
  21612. afii10056: 0x0407,
  21613. afii10057: 0x0408,
  21614. afii10058: 0x0409,
  21615. afii10059: 0x040A,
  21616. afii10060: 0x040B,
  21617. afii10061: 0x040C,
  21618. afii10062: 0x040E,
  21619. afii10063: 0xF6C4,
  21620. afii10064: 0xF6C5,
  21621. afii10065: 0x0430,
  21622. afii10066: 0x0431,
  21623. afii10067: 0x0432,
  21624. afii10068: 0x0433,
  21625. afii10069: 0x0434,
  21626. afii10070: 0x0435,
  21627. afii10071: 0x0451,
  21628. afii10072: 0x0436,
  21629. afii10073: 0x0437,
  21630. afii10074: 0x0438,
  21631. afii10075: 0x0439,
  21632. afii10076: 0x043A,
  21633. afii10077: 0x043B,
  21634. afii10078: 0x043C,
  21635. afii10079: 0x043D,
  21636. afii10080: 0x043E,
  21637. afii10081: 0x043F,
  21638. afii10082: 0x0440,
  21639. afii10083: 0x0441,
  21640. afii10084: 0x0442,
  21641. afii10085: 0x0443,
  21642. afii10086: 0x0444,
  21643. afii10087: 0x0445,
  21644. afii10088: 0x0446,
  21645. afii10089: 0x0447,
  21646. afii10090: 0x0448,
  21647. afii10091: 0x0449,
  21648. afii10092: 0x044A,
  21649. afii10093: 0x044B,
  21650. afii10094: 0x044C,
  21651. afii10095: 0x044D,
  21652. afii10096: 0x044E,
  21653. afii10097: 0x044F,
  21654. afii10098: 0x0491,
  21655. afii10099: 0x0452,
  21656. afii10100: 0x0453,
  21657. afii10101: 0x0454,
  21658. afii10102: 0x0455,
  21659. afii10103: 0x0456,
  21660. afii10104: 0x0457,
  21661. afii10105: 0x0458,
  21662. afii10106: 0x0459,
  21663. afii10107: 0x045A,
  21664. afii10108: 0x045B,
  21665. afii10109: 0x045C,
  21666. afii10110: 0x045E,
  21667. afii10145: 0x040F,
  21668. afii10146: 0x0462,
  21669. afii10147: 0x0472,
  21670. afii10148: 0x0474,
  21671. afii10192: 0xF6C6,
  21672. afii10193: 0x045F,
  21673. afii10194: 0x0463,
  21674. afii10195: 0x0473,
  21675. afii10196: 0x0475,
  21676. afii10831: 0xF6C7,
  21677. afii10832: 0xF6C8,
  21678. afii10846: 0x04D9,
  21679. afii299: 0x200E,
  21680. afii300: 0x200F,
  21681. afii301: 0x200D,
  21682. afii57381: 0x066A,
  21683. afii57388: 0x060C,
  21684. afii57392: 0x0660,
  21685. afii57393: 0x0661,
  21686. afii57394: 0x0662,
  21687. afii57395: 0x0663,
  21688. afii57396: 0x0664,
  21689. afii57397: 0x0665,
  21690. afii57398: 0x0666,
  21691. afii57399: 0x0667,
  21692. afii57400: 0x0668,
  21693. afii57401: 0x0669,
  21694. afii57403: 0x061B,
  21695. afii57407: 0x061F,
  21696. afii57409: 0x0621,
  21697. afii57410: 0x0622,
  21698. afii57411: 0x0623,
  21699. afii57412: 0x0624,
  21700. afii57413: 0x0625,
  21701. afii57414: 0x0626,
  21702. afii57415: 0x0627,
  21703. afii57416: 0x0628,
  21704. afii57417: 0x0629,
  21705. afii57418: 0x062A,
  21706. afii57419: 0x062B,
  21707. afii57420: 0x062C,
  21708. afii57421: 0x062D,
  21709. afii57422: 0x062E,
  21710. afii57423: 0x062F,
  21711. afii57424: 0x0630,
  21712. afii57425: 0x0631,
  21713. afii57426: 0x0632,
  21714. afii57427: 0x0633,
  21715. afii57428: 0x0634,
  21716. afii57429: 0x0635,
  21717. afii57430: 0x0636,
  21718. afii57431: 0x0637,
  21719. afii57432: 0x0638,
  21720. afii57433: 0x0639,
  21721. afii57434: 0x063A,
  21722. afii57440: 0x0640,
  21723. afii57441: 0x0641,
  21724. afii57442: 0x0642,
  21725. afii57443: 0x0643,
  21726. afii57444: 0x0644,
  21727. afii57445: 0x0645,
  21728. afii57446: 0x0646,
  21729. afii57448: 0x0648,
  21730. afii57449: 0x0649,
  21731. afii57450: 0x064A,
  21732. afii57451: 0x064B,
  21733. afii57452: 0x064C,
  21734. afii57453: 0x064D,
  21735. afii57454: 0x064E,
  21736. afii57455: 0x064F,
  21737. afii57456: 0x0650,
  21738. afii57457: 0x0651,
  21739. afii57458: 0x0652,
  21740. afii57470: 0x0647,
  21741. afii57505: 0x06A4,
  21742. afii57506: 0x067E,
  21743. afii57507: 0x0686,
  21744. afii57508: 0x0698,
  21745. afii57509: 0x06AF,
  21746. afii57511: 0x0679,
  21747. afii57512: 0x0688,
  21748. afii57513: 0x0691,
  21749. afii57514: 0x06BA,
  21750. afii57519: 0x06D2,
  21751. afii57534: 0x06D5,
  21752. afii57636: 0x20AA,
  21753. afii57645: 0x05BE,
  21754. afii57658: 0x05C3,
  21755. afii57664: 0x05D0,
  21756. afii57665: 0x05D1,
  21757. afii57666: 0x05D2,
  21758. afii57667: 0x05D3,
  21759. afii57668: 0x05D4,
  21760. afii57669: 0x05D5,
  21761. afii57670: 0x05D6,
  21762. afii57671: 0x05D7,
  21763. afii57672: 0x05D8,
  21764. afii57673: 0x05D9,
  21765. afii57674: 0x05DA,
  21766. afii57675: 0x05DB,
  21767. afii57676: 0x05DC,
  21768. afii57677: 0x05DD,
  21769. afii57678: 0x05DE,
  21770. afii57679: 0x05DF,
  21771. afii57680: 0x05E0,
  21772. afii57681: 0x05E1,
  21773. afii57682: 0x05E2,
  21774. afii57683: 0x05E3,
  21775. afii57684: 0x05E4,
  21776. afii57685: 0x05E5,
  21777. afii57686: 0x05E6,
  21778. afii57687: 0x05E7,
  21779. afii57688: 0x05E8,
  21780. afii57689: 0x05E9,
  21781. afii57690: 0x05EA,
  21782. afii57694: 0xFB2A,
  21783. afii57695: 0xFB2B,
  21784. afii57700: 0xFB4B,
  21785. afii57705: 0xFB1F,
  21786. afii57716: 0x05F0,
  21787. afii57717: 0x05F1,
  21788. afii57718: 0x05F2,
  21789. afii57723: 0xFB35,
  21790. afii57793: 0x05B4,
  21791. afii57794: 0x05B5,
  21792. afii57795: 0x05B6,
  21793. afii57796: 0x05BB,
  21794. afii57797: 0x05B8,
  21795. afii57798: 0x05B7,
  21796. afii57799: 0x05B0,
  21797. afii57800: 0x05B2,
  21798. afii57801: 0x05B1,
  21799. afii57802: 0x05B3,
  21800. afii57803: 0x05C2,
  21801. afii57804: 0x05C1,
  21802. afii57806: 0x05B9,
  21803. afii57807: 0x05BC,
  21804. afii57839: 0x05BD,
  21805. afii57841: 0x05BF,
  21806. afii57842: 0x05C0,
  21807. afii57929: 0x02BC,
  21808. afii61248: 0x2105,
  21809. afii61289: 0x2113,
  21810. afii61352: 0x2116,
  21811. afii61573: 0x202C,
  21812. afii61574: 0x202D,
  21813. afii61575: 0x202E,
  21814. afii61664: 0x200C,
  21815. afii63167: 0x066D,
  21816. afii64937: 0x02BD,
  21817. agrave: 0x00E0,
  21818. agujarati: 0x0A85,
  21819. agurmukhi: 0x0A05,
  21820. ahiragana: 0x3042,
  21821. ahookabove: 0x1EA3,
  21822. aibengali: 0x0990,
  21823. aibopomofo: 0x311E,
  21824. aideva: 0x0910,
  21825. aiecyrillic: 0x04D5,
  21826. aigujarati: 0x0A90,
  21827. aigurmukhi: 0x0A10,
  21828. aimatragurmukhi: 0x0A48,
  21829. ainarabic: 0x0639,
  21830. ainfinalarabic: 0xFECA,
  21831. aininitialarabic: 0xFECB,
  21832. ainmedialarabic: 0xFECC,
  21833. ainvertedbreve: 0x0203,
  21834. aivowelsignbengali: 0x09C8,
  21835. aivowelsigndeva: 0x0948,
  21836. aivowelsigngujarati: 0x0AC8,
  21837. akatakana: 0x30A2,
  21838. akatakanahalfwidth: 0xFF71,
  21839. akorean: 0x314F,
  21840. alef: 0x05D0,
  21841. alefarabic: 0x0627,
  21842. alefdageshhebrew: 0xFB30,
  21843. aleffinalarabic: 0xFE8E,
  21844. alefhamzaabovearabic: 0x0623,
  21845. alefhamzaabovefinalarabic: 0xFE84,
  21846. alefhamzabelowarabic: 0x0625,
  21847. alefhamzabelowfinalarabic: 0xFE88,
  21848. alefhebrew: 0x05D0,
  21849. aleflamedhebrew: 0xFB4F,
  21850. alefmaddaabovearabic: 0x0622,
  21851. alefmaddaabovefinalarabic: 0xFE82,
  21852. alefmaksuraarabic: 0x0649,
  21853. alefmaksurafinalarabic: 0xFEF0,
  21854. alefmaksurainitialarabic: 0xFEF3,
  21855. alefmaksuramedialarabic: 0xFEF4,
  21856. alefpatahhebrew: 0xFB2E,
  21857. alefqamatshebrew: 0xFB2F,
  21858. aleph: 0x2135,
  21859. allequal: 0x224C,
  21860. alpha: 0x03B1,
  21861. alphatonos: 0x03AC,
  21862. amacron: 0x0101,
  21863. amonospace: 0xFF41,
  21864. ampersand: 0x0026,
  21865. ampersandmonospace: 0xFF06,
  21866. ampersandsmall: 0xF726,
  21867. amsquare: 0x33C2,
  21868. anbopomofo: 0x3122,
  21869. angbopomofo: 0x3124,
  21870. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21871. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21872. angkhankhuthai: 0x0E5A,
  21873. angle: 0x2220,
  21874. anglebracketleft: 0x3008,
  21875. anglebracketleftvertical: 0xFE3F,
  21876. anglebracketright: 0x3009,
  21877. anglebracketrightvertical: 0xFE40,
  21878. angleleft: 0x2329,
  21879. angleright: 0x232A,
  21880. angstrom: 0x212B,
  21881. anoteleia: 0x0387,
  21882. anudattadeva: 0x0952,
  21883. anusvarabengali: 0x0982,
  21884. anusvaradeva: 0x0902,
  21885. anusvaragujarati: 0x0A82,
  21886. aogonek: 0x0105,
  21887. apaatosquare: 0x3300,
  21888. aparen: 0x249C,
  21889. apostrophearmenian: 0x055A,
  21890. apostrophemod: 0x02BC,
  21891. apple: 0xF8FF,
  21892. approaches: 0x2250,
  21893. approxequal: 0x2248,
  21894. approxequalorimage: 0x2252,
  21895. approximatelyequal: 0x2245,
  21896. araeaekorean: 0x318E,
  21897. araeakorean: 0x318D,
  21898. arc: 0x2312,
  21899. arighthalfring: 0x1E9A,
  21900. aring: 0x00E5,
  21901. aringacute: 0x01FB,
  21902. aringbelow: 0x1E01,
  21903. arrowboth: 0x2194,
  21904. arrowdashdown: 0x21E3,
  21905. arrowdashleft: 0x21E0,
  21906. arrowdashright: 0x21E2,
  21907. arrowdashup: 0x21E1,
  21908. arrowdblboth: 0x21D4,
  21909. arrowdbldown: 0x21D3,
  21910. arrowdblleft: 0x21D0,
  21911. arrowdblright: 0x21D2,
  21912. arrowdblup: 0x21D1,
  21913. arrowdown: 0x2193,
  21914. arrowdownleft: 0x2199,
  21915. arrowdownright: 0x2198,
  21916. arrowdownwhite: 0x21E9,
  21917. arrowheaddownmod: 0x02C5,
  21918. arrowheadleftmod: 0x02C2,
  21919. arrowheadrightmod: 0x02C3,
  21920. arrowheadupmod: 0x02C4,
  21921. arrowhorizex: 0xF8E7,
  21922. arrowleft: 0x2190,
  21923. arrowleftdbl: 0x21D0,
  21924. arrowleftdblstroke: 0x21CD,
  21925. arrowleftoverright: 0x21C6,
  21926. arrowleftwhite: 0x21E6,
  21927. arrowright: 0x2192,
  21928. arrowrightdblstroke: 0x21CF,
  21929. arrowrightheavy: 0x279E,
  21930. arrowrightoverleft: 0x21C4,
  21931. arrowrightwhite: 0x21E8,
  21932. arrowtableft: 0x21E4,
  21933. arrowtabright: 0x21E5,
  21934. arrowup: 0x2191,
  21935. arrowupdn: 0x2195,
  21936. arrowupdnbse: 0x21A8,
  21937. arrowupdownbase: 0x21A8,
  21938. arrowupleft: 0x2196,
  21939. arrowupleftofdown: 0x21C5,
  21940. arrowupright: 0x2197,
  21941. arrowupwhite: 0x21E7,
  21942. arrowvertex: 0xF8E6,
  21943. asciicircum: 0x005E,
  21944. asciicircummonospace: 0xFF3E,
  21945. asciitilde: 0x007E,
  21946. asciitildemonospace: 0xFF5E,
  21947. ascript: 0x0251,
  21948. ascriptturned: 0x0252,
  21949. asmallhiragana: 0x3041,
  21950. asmallkatakana: 0x30A1,
  21951. asmallkatakanahalfwidth: 0xFF67,
  21952. asterisk: 0x002A,
  21953. asteriskaltonearabic: 0x066D,
  21954. asteriskarabic: 0x066D,
  21955. asteriskmath: 0x2217,
  21956. asteriskmonospace: 0xFF0A,
  21957. asterisksmall: 0xFE61,
  21958. asterism: 0x2042,
  21959. asuperior: 0xF6E9,
  21960. asymptoticallyequal: 0x2243,
  21961. at: 0x0040,
  21962. atilde: 0x00E3,
  21963. atmonospace: 0xFF20,
  21964. atsmall: 0xFE6B,
  21965. aturned: 0x0250,
  21966. aubengali: 0x0994,
  21967. aubopomofo: 0x3120,
  21968. audeva: 0x0914,
  21969. augujarati: 0x0A94,
  21970. augurmukhi: 0x0A14,
  21971. aulengthmarkbengali: 0x09D7,
  21972. aumatragurmukhi: 0x0A4C,
  21973. auvowelsignbengali: 0x09CC,
  21974. auvowelsigndeva: 0x094C,
  21975. auvowelsigngujarati: 0x0ACC,
  21976. avagrahadeva: 0x093D,
  21977. aybarmenian: 0x0561,
  21978. ayin: 0x05E2,
  21979. ayinaltonehebrew: 0xFB20,
  21980. ayinhebrew: 0x05E2,
  21981. b: 0x0062,
  21982. babengali: 0x09AC,
  21983. backslash: 0x005C,
  21984. backslashmonospace: 0xFF3C,
  21985. badeva: 0x092C,
  21986. bagujarati: 0x0AAC,
  21987. bagurmukhi: 0x0A2C,
  21988. bahiragana: 0x3070,
  21989. bahtthai: 0x0E3F,
  21990. bakatakana: 0x30D0,
  21991. bar: 0x007C,
  21992. barmonospace: 0xFF5C,
  21993. bbopomofo: 0x3105,
  21994. bcircle: 0x24D1,
  21995. bdotaccent: 0x1E03,
  21996. bdotbelow: 0x1E05,
  21997. beamedsixteenthnotes: 0x266C,
  21998. because: 0x2235,
  21999. becyrillic: 0x0431,
  22000. beharabic: 0x0628,
  22001. behfinalarabic: 0xFE90,
  22002. behinitialarabic: 0xFE91,
  22003. behiragana: 0x3079,
  22004. behmedialarabic: 0xFE92,
  22005. behmeeminitialarabic: 0xFC9F,
  22006. behmeemisolatedarabic: 0xFC08,
  22007. behnoonfinalarabic: 0xFC6D,
  22008. bekatakana: 0x30D9,
  22009. benarmenian: 0x0562,
  22010. bet: 0x05D1,
  22011. beta: 0x03B2,
  22012. betasymbolgreek: 0x03D0,
  22013. betdagesh: 0xFB31,
  22014. betdageshhebrew: 0xFB31,
  22015. bethebrew: 0x05D1,
  22016. betrafehebrew: 0xFB4C,
  22017. bhabengali: 0x09AD,
  22018. bhadeva: 0x092D,
  22019. bhagujarati: 0x0AAD,
  22020. bhagurmukhi: 0x0A2D,
  22021. bhook: 0x0253,
  22022. bihiragana: 0x3073,
  22023. bikatakana: 0x30D3,
  22024. bilabialclick: 0x0298,
  22025. bindigurmukhi: 0x0A02,
  22026. birusquare: 0x3331,
  22027. blackcircle: 0x25CF,
  22028. blackdiamond: 0x25C6,
  22029. blackdownpointingtriangle: 0x25BC,
  22030. blackleftpointingpointer: 0x25C4,
  22031. blackleftpointingtriangle: 0x25C0,
  22032. blacklenticularbracketleft: 0x3010,
  22033. blacklenticularbracketleftvertical: 0xFE3B,
  22034. blacklenticularbracketright: 0x3011,
  22035. blacklenticularbracketrightvertical: 0xFE3C,
  22036. blacklowerlefttriangle: 0x25E3,
  22037. blacklowerrighttriangle: 0x25E2,
  22038. blackrectangle: 0x25AC,
  22039. blackrightpointingpointer: 0x25BA,
  22040. blackrightpointingtriangle: 0x25B6,
  22041. blacksmallsquare: 0x25AA,
  22042. blacksmilingface: 0x263B,
  22043. blacksquare: 0x25A0,
  22044. blackstar: 0x2605,
  22045. blackupperlefttriangle: 0x25E4,
  22046. blackupperrighttriangle: 0x25E5,
  22047. blackuppointingsmalltriangle: 0x25B4,
  22048. blackuppointingtriangle: 0x25B2,
  22049. blank: 0x2423,
  22050. blinebelow: 0x1E07,
  22051. block: 0x2588,
  22052. bmonospace: 0xFF42,
  22053. bobaimaithai: 0x0E1A,
  22054. bohiragana: 0x307C,
  22055. bokatakana: 0x30DC,
  22056. bparen: 0x249D,
  22057. bqsquare: 0x33C3,
  22058. braceex: 0xF8F4,
  22059. braceleft: 0x007B,
  22060. braceleftbt: 0xF8F3,
  22061. braceleftmid: 0xF8F2,
  22062. braceleftmonospace: 0xFF5B,
  22063. braceleftsmall: 0xFE5B,
  22064. bracelefttp: 0xF8F1,
  22065. braceleftvertical: 0xFE37,
  22066. braceright: 0x007D,
  22067. bracerightbt: 0xF8FE,
  22068. bracerightmid: 0xF8FD,
  22069. bracerightmonospace: 0xFF5D,
  22070. bracerightsmall: 0xFE5C,
  22071. bracerighttp: 0xF8FC,
  22072. bracerightvertical: 0xFE38,
  22073. bracketleft: 0x005B,
  22074. bracketleftbt: 0xF8F0,
  22075. bracketleftex: 0xF8EF,
  22076. bracketleftmonospace: 0xFF3B,
  22077. bracketlefttp: 0xF8EE,
  22078. bracketright: 0x005D,
  22079. bracketrightbt: 0xF8FB,
  22080. bracketrightex: 0xF8FA,
  22081. bracketrightmonospace: 0xFF3D,
  22082. bracketrighttp: 0xF8F9,
  22083. breve: 0x02D8,
  22084. brevebelowcmb: 0x032E,
  22085. brevecmb: 0x0306,
  22086. breveinvertedbelowcmb: 0x032F,
  22087. breveinvertedcmb: 0x0311,
  22088. breveinverteddoublecmb: 0x0361,
  22089. bridgebelowcmb: 0x032A,
  22090. bridgeinvertedbelowcmb: 0x033A,
  22091. brokenbar: 0x00A6,
  22092. bstroke: 0x0180,
  22093. bsuperior: 0xF6EA,
  22094. btopbar: 0x0183,
  22095. buhiragana: 0x3076,
  22096. bukatakana: 0x30D6,
  22097. bullet: 0x2022,
  22098. bulletinverse: 0x25D8,
  22099. bulletoperator: 0x2219,
  22100. bullseye: 0x25CE,
  22101. c: 0x0063,
  22102. caarmenian: 0x056E,
  22103. cabengali: 0x099A,
  22104. cacute: 0x0107,
  22105. cadeva: 0x091A,
  22106. cagujarati: 0x0A9A,
  22107. cagurmukhi: 0x0A1A,
  22108. calsquare: 0x3388,
  22109. candrabindubengali: 0x0981,
  22110. candrabinducmb: 0x0310,
  22111. candrabindudeva: 0x0901,
  22112. candrabindugujarati: 0x0A81,
  22113. capslock: 0x21EA,
  22114. careof: 0x2105,
  22115. caron: 0x02C7,
  22116. caronbelowcmb: 0x032C,
  22117. caroncmb: 0x030C,
  22118. carriagereturn: 0x21B5,
  22119. cbopomofo: 0x3118,
  22120. ccaron: 0x010D,
  22121. ccedilla: 0x00E7,
  22122. ccedillaacute: 0x1E09,
  22123. ccircle: 0x24D2,
  22124. ccircumflex: 0x0109,
  22125. ccurl: 0x0255,
  22126. cdot: 0x010B,
  22127. cdotaccent: 0x010B,
  22128. cdsquare: 0x33C5,
  22129. cedilla: 0x00B8,
  22130. cedillacmb: 0x0327,
  22131. cent: 0x00A2,
  22132. centigrade: 0x2103,
  22133. centinferior: 0xF6DF,
  22134. centmonospace: 0xFFE0,
  22135. centoldstyle: 0xF7A2,
  22136. centsuperior: 0xF6E0,
  22137. chaarmenian: 0x0579,
  22138. chabengali: 0x099B,
  22139. chadeva: 0x091B,
  22140. chagujarati: 0x0A9B,
  22141. chagurmukhi: 0x0A1B,
  22142. chbopomofo: 0x3114,
  22143. cheabkhasiancyrillic: 0x04BD,
  22144. checkmark: 0x2713,
  22145. checyrillic: 0x0447,
  22146. chedescenderabkhasiancyrillic: 0x04BF,
  22147. chedescendercyrillic: 0x04B7,
  22148. chedieresiscyrillic: 0x04F5,
  22149. cheharmenian: 0x0573,
  22150. chekhakassiancyrillic: 0x04CC,
  22151. cheverticalstrokecyrillic: 0x04B9,
  22152. chi: 0x03C7,
  22153. chieuchacirclekorean: 0x3277,
  22154. chieuchaparenkorean: 0x3217,
  22155. chieuchcirclekorean: 0x3269,
  22156. chieuchkorean: 0x314A,
  22157. chieuchparenkorean: 0x3209,
  22158. chochangthai: 0x0E0A,
  22159. chochanthai: 0x0E08,
  22160. chochingthai: 0x0E09,
  22161. chochoethai: 0x0E0C,
  22162. chook: 0x0188,
  22163. cieucacirclekorean: 0x3276,
  22164. cieucaparenkorean: 0x3216,
  22165. cieuccirclekorean: 0x3268,
  22166. cieuckorean: 0x3148,
  22167. cieucparenkorean: 0x3208,
  22168. cieucuparenkorean: 0x321C,
  22169. circle: 0x25CB,
  22170. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  22171. circlemultiply: 0x2297,
  22172. circleot: 0x2299,
  22173. circleplus: 0x2295,
  22174. circlepostalmark: 0x3036,
  22175. circlewithlefthalfblack: 0x25D0,
  22176. circlewithrighthalfblack: 0x25D1,
  22177. circumflex: 0x02C6,
  22178. circumflexbelowcmb: 0x032D,
  22179. circumflexcmb: 0x0302,
  22180. clear: 0x2327,
  22181. clickalveolar: 0x01C2,
  22182. clickdental: 0x01C0,
  22183. clicklateral: 0x01C1,
  22184. clickretroflex: 0x01C3,
  22185. club: 0x2663,
  22186. clubsuitblack: 0x2663,
  22187. clubsuitwhite: 0x2667,
  22188. cmcubedsquare: 0x33A4,
  22189. cmonospace: 0xFF43,
  22190. cmsquaredsquare: 0x33A0,
  22191. coarmenian: 0x0581,
  22192. colon: 0x003A,
  22193. colonmonetary: 0x20A1,
  22194. colonmonospace: 0xFF1A,
  22195. colonsign: 0x20A1,
  22196. colonsmall: 0xFE55,
  22197. colontriangularhalfmod: 0x02D1,
  22198. colontriangularmod: 0x02D0,
  22199. comma: 0x002C,
  22200. commaabovecmb: 0x0313,
  22201. commaaboverightcmb: 0x0315,
  22202. commaaccent: 0xF6C3,
  22203. commaarabic: 0x060C,
  22204. commaarmenian: 0x055D,
  22205. commainferior: 0xF6E1,
  22206. commamonospace: 0xFF0C,
  22207. commareversedabovecmb: 0x0314,
  22208. commareversedmod: 0x02BD,
  22209. commasmall: 0xFE50,
  22210. commasuperior: 0xF6E2,
  22211. commaturnedabovecmb: 0x0312,
  22212. commaturnedmod: 0x02BB,
  22213. compass: 0x263C,
  22214. congruent: 0x2245,
  22215. contourintegral: 0x222E,
  22216. control: 0x2303,
  22217. controlACK: 0x0006,
  22218. controlBEL: 0x0007,
  22219. controlBS: 0x0008,
  22220. controlCAN: 0x0018,
  22221. controlCR: 0x000D,
  22222. controlDC1: 0x0011,
  22223. controlDC2: 0x0012,
  22224. controlDC3: 0x0013,
  22225. controlDC4: 0x0014,
  22226. controlDEL: 0x007F,
  22227. controlDLE: 0x0010,
  22228. controlEM: 0x0019,
  22229. controlENQ: 0x0005,
  22230. controlEOT: 0x0004,
  22231. controlESC: 0x001B,
  22232. controlETB: 0x0017,
  22233. controlETX: 0x0003,
  22234. controlFF: 0x000C,
  22235. controlFS: 0x001C,
  22236. controlGS: 0x001D,
  22237. controlHT: 0x0009,
  22238. controlLF: 0x000A,
  22239. controlNAK: 0x0015,
  22240. controlRS: 0x001E,
  22241. controlSI: 0x000F,
  22242. controlSO: 0x000E,
  22243. controlSOT: 0x0002,
  22244. controlSTX: 0x0001,
  22245. controlSUB: 0x001A,
  22246. controlSYN: 0x0016,
  22247. controlUS: 0x001F,
  22248. controlVT: 0x000B,
  22249. copyright: 0x00A9,
  22250. copyrightsans: 0xF8E9,
  22251. copyrightserif: 0xF6D9,
  22252. cornerbracketleft: 0x300C,
  22253. cornerbracketlefthalfwidth: 0xFF62,
  22254. cornerbracketleftvertical: 0xFE41,
  22255. cornerbracketright: 0x300D,
  22256. cornerbracketrighthalfwidth: 0xFF63,
  22257. cornerbracketrightvertical: 0xFE42,
  22258. corporationsquare: 0x337F,
  22259. cosquare: 0x33C7,
  22260. coverkgsquare: 0x33C6,
  22261. cparen: 0x249E,
  22262. cruzeiro: 0x20A2,
  22263. cstretched: 0x0297,
  22264. curlyand: 0x22CF,
  22265. curlyor: 0x22CE,
  22266. currency: 0x00A4,
  22267. cyrBreve: 0xF6D1,
  22268. cyrFlex: 0xF6D2,
  22269. cyrbreve: 0xF6D4,
  22270. cyrflex: 0xF6D5,
  22271. d: 0x0064,
  22272. daarmenian: 0x0564,
  22273. dabengali: 0x09A6,
  22274. dadarabic: 0x0636,
  22275. dadeva: 0x0926,
  22276. dadfinalarabic: 0xFEBE,
  22277. dadinitialarabic: 0xFEBF,
  22278. dadmedialarabic: 0xFEC0,
  22279. dagesh: 0x05BC,
  22280. dageshhebrew: 0x05BC,
  22281. dagger: 0x2020,
  22282. daggerdbl: 0x2021,
  22283. dagujarati: 0x0AA6,
  22284. dagurmukhi: 0x0A26,
  22285. dahiragana: 0x3060,
  22286. dakatakana: 0x30C0,
  22287. dalarabic: 0x062F,
  22288. dalet: 0x05D3,
  22289. daletdagesh: 0xFB33,
  22290. daletdageshhebrew: 0xFB33,
  22291. dalethebrew: 0x05D3,
  22292. dalfinalarabic: 0xFEAA,
  22293. dammaarabic: 0x064F,
  22294. dammalowarabic: 0x064F,
  22295. dammatanaltonearabic: 0x064C,
  22296. dammatanarabic: 0x064C,
  22297. danda: 0x0964,
  22298. dargahebrew: 0x05A7,
  22299. dargalefthebrew: 0x05A7,
  22300. dasiapneumatacyrilliccmb: 0x0485,
  22301. dblGrave: 0xF6D3,
  22302. dblanglebracketleft: 0x300A,
  22303. dblanglebracketleftvertical: 0xFE3D,
  22304. dblanglebracketright: 0x300B,
  22305. dblanglebracketrightvertical: 0xFE3E,
  22306. dblarchinvertedbelowcmb: 0x032B,
  22307. dblarrowleft: 0x21D4,
  22308. dblarrowright: 0x21D2,
  22309. dbldanda: 0x0965,
  22310. dblgrave: 0xF6D6,
  22311. dblgravecmb: 0x030F,
  22312. dblintegral: 0x222C,
  22313. dbllowline: 0x2017,
  22314. dbllowlinecmb: 0x0333,
  22315. dbloverlinecmb: 0x033F,
  22316. dblprimemod: 0x02BA,
  22317. dblverticalbar: 0x2016,
  22318. dblverticallineabovecmb: 0x030E,
  22319. dbopomofo: 0x3109,
  22320. dbsquare: 0x33C8,
  22321. dcaron: 0x010F,
  22322. dcedilla: 0x1E11,
  22323. dcircle: 0x24D3,
  22324. dcircumflexbelow: 0x1E13,
  22325. dcroat: 0x0111,
  22326. ddabengali: 0x09A1,
  22327. ddadeva: 0x0921,
  22328. ddagujarati: 0x0AA1,
  22329. ddagurmukhi: 0x0A21,
  22330. ddalarabic: 0x0688,
  22331. ddalfinalarabic: 0xFB89,
  22332. dddhadeva: 0x095C,
  22333. ddhabengali: 0x09A2,
  22334. ddhadeva: 0x0922,
  22335. ddhagujarati: 0x0AA2,
  22336. ddhagurmukhi: 0x0A22,
  22337. ddotaccent: 0x1E0B,
  22338. ddotbelow: 0x1E0D,
  22339. decimalseparatorarabic: 0x066B,
  22340. decimalseparatorpersian: 0x066B,
  22341. decyrillic: 0x0434,
  22342. degree: 0x00B0,
  22343. dehihebrew: 0x05AD,
  22344. dehiragana: 0x3067,
  22345. deicoptic: 0x03EF,
  22346. dekatakana: 0x30C7,
  22347. deleteleft: 0x232B,
  22348. deleteright: 0x2326,
  22349. delta: 0x03B4,
  22350. deltaturned: 0x018D,
  22351. denominatorminusonenumeratorbengali: 0x09F8,
  22352. dezh: 0x02A4,
  22353. dhabengali: 0x09A7,
  22354. dhadeva: 0x0927,
  22355. dhagujarati: 0x0AA7,
  22356. dhagurmukhi: 0x0A27,
  22357. dhook: 0x0257,
  22358. dialytikatonos: 0x0385,
  22359. dialytikatonoscmb: 0x0344,
  22360. diamond: 0x2666,
  22361. diamondsuitwhite: 0x2662,
  22362. dieresis: 0x00A8,
  22363. dieresisacute: 0xF6D7,
  22364. dieresisbelowcmb: 0x0324,
  22365. dieresiscmb: 0x0308,
  22366. dieresisgrave: 0xF6D8,
  22367. dieresistonos: 0x0385,
  22368. dihiragana: 0x3062,
  22369. dikatakana: 0x30C2,
  22370. dittomark: 0x3003,
  22371. divide: 0x00F7,
  22372. divides: 0x2223,
  22373. divisionslash: 0x2215,
  22374. djecyrillic: 0x0452,
  22375. dkshade: 0x2593,
  22376. dlinebelow: 0x1E0F,
  22377. dlsquare: 0x3397,
  22378. dmacron: 0x0111,
  22379. dmonospace: 0xFF44,
  22380. dnblock: 0x2584,
  22381. dochadathai: 0x0E0E,
  22382. dodekthai: 0x0E14,
  22383. dohiragana: 0x3069,
  22384. dokatakana: 0x30C9,
  22385. dollar: 0x0024,
  22386. dollarinferior: 0xF6E3,
  22387. dollarmonospace: 0xFF04,
  22388. dollaroldstyle: 0xF724,
  22389. dollarsmall: 0xFE69,
  22390. dollarsuperior: 0xF6E4,
  22391. dong: 0x20AB,
  22392. dorusquare: 0x3326,
  22393. dotaccent: 0x02D9,
  22394. dotaccentcmb: 0x0307,
  22395. dotbelowcmb: 0x0323,
  22396. dotbelowcomb: 0x0323,
  22397. dotkatakana: 0x30FB,
  22398. dotlessi: 0x0131,
  22399. dotlessj: 0xF6BE,
  22400. dotlessjstrokehook: 0x0284,
  22401. dotmath: 0x22C5,
  22402. dottedcircle: 0x25CC,
  22403. doubleyodpatah: 0xFB1F,
  22404. doubleyodpatahhebrew: 0xFB1F,
  22405. downtackbelowcmb: 0x031E,
  22406. downtackmod: 0x02D5,
  22407. dparen: 0x249F,
  22408. dsuperior: 0xF6EB,
  22409. dtail: 0x0256,
  22410. dtopbar: 0x018C,
  22411. duhiragana: 0x3065,
  22412. dukatakana: 0x30C5,
  22413. dz: 0x01F3,
  22414. dzaltone: 0x02A3,
  22415. dzcaron: 0x01C6,
  22416. dzcurl: 0x02A5,
  22417. dzeabkhasiancyrillic: 0x04E1,
  22418. dzecyrillic: 0x0455,
  22419. dzhecyrillic: 0x045F,
  22420. e: 0x0065,
  22421. eacute: 0x00E9,
  22422. earth: 0x2641,
  22423. ebengali: 0x098F,
  22424. ebopomofo: 0x311C,
  22425. ebreve: 0x0115,
  22426. ecandradeva: 0x090D,
  22427. ecandragujarati: 0x0A8D,
  22428. ecandravowelsigndeva: 0x0945,
  22429. ecandravowelsigngujarati: 0x0AC5,
  22430. ecaron: 0x011B,
  22431. ecedillabreve: 0x1E1D,
  22432. echarmenian: 0x0565,
  22433. echyiwnarmenian: 0x0587,
  22434. ecircle: 0x24D4,
  22435. ecircumflex: 0x00EA,
  22436. ecircumflexacute: 0x1EBF,
  22437. ecircumflexbelow: 0x1E19,
  22438. ecircumflexdotbelow: 0x1EC7,
  22439. ecircumflexgrave: 0x1EC1,
  22440. ecircumflexhookabove: 0x1EC3,
  22441. ecircumflextilde: 0x1EC5,
  22442. ecyrillic: 0x0454,
  22443. edblgrave: 0x0205,
  22444. edeva: 0x090F,
  22445. edieresis: 0x00EB,
  22446. edot: 0x0117,
  22447. edotaccent: 0x0117,
  22448. edotbelow: 0x1EB9,
  22449. eegurmukhi: 0x0A0F,
  22450. eematragurmukhi: 0x0A47,
  22451. efcyrillic: 0x0444,
  22452. egrave: 0x00E8,
  22453. egujarati: 0x0A8F,
  22454. eharmenian: 0x0567,
  22455. ehbopomofo: 0x311D,
  22456. ehiragana: 0x3048,
  22457. ehookabove: 0x1EBB,
  22458. eibopomofo: 0x311F,
  22459. eight: 0x0038,
  22460. eightarabic: 0x0668,
  22461. eightbengali: 0x09EE,
  22462. eightcircle: 0x2467,
  22463. eightcircleinversesansserif: 0x2791,
  22464. eightdeva: 0x096E,
  22465. eighteencircle: 0x2471,
  22466. eighteenparen: 0x2485,
  22467. eighteenperiod: 0x2499,
  22468. eightgujarati: 0x0AEE,
  22469. eightgurmukhi: 0x0A6E,
  22470. eighthackarabic: 0x0668,
  22471. eighthangzhou: 0x3028,
  22472. eighthnotebeamed: 0x266B,
  22473. eightideographicparen: 0x3227,
  22474. eightinferior: 0x2088,
  22475. eightmonospace: 0xFF18,
  22476. eightoldstyle: 0xF738,
  22477. eightparen: 0x247B,
  22478. eightperiod: 0x248F,
  22479. eightpersian: 0x06F8,
  22480. eightroman: 0x2177,
  22481. eightsuperior: 0x2078,
  22482. eightthai: 0x0E58,
  22483. einvertedbreve: 0x0207,
  22484. eiotifiedcyrillic: 0x0465,
  22485. ekatakana: 0x30A8,
  22486. ekatakanahalfwidth: 0xFF74,
  22487. ekonkargurmukhi: 0x0A74,
  22488. ekorean: 0x3154,
  22489. elcyrillic: 0x043B,
  22490. element: 0x2208,
  22491. elevencircle: 0x246A,
  22492. elevenparen: 0x247E,
  22493. elevenperiod: 0x2492,
  22494. elevenroman: 0x217A,
  22495. ellipsis: 0x2026,
  22496. ellipsisvertical: 0x22EE,
  22497. emacron: 0x0113,
  22498. emacronacute: 0x1E17,
  22499. emacrongrave: 0x1E15,
  22500. emcyrillic: 0x043C,
  22501. emdash: 0x2014,
  22502. emdashvertical: 0xFE31,
  22503. emonospace: 0xFF45,
  22504. emphasismarkarmenian: 0x055B,
  22505. emptyset: 0x2205,
  22506. enbopomofo: 0x3123,
  22507. encyrillic: 0x043D,
  22508. endash: 0x2013,
  22509. endashvertical: 0xFE32,
  22510. endescendercyrillic: 0x04A3,
  22511. eng: 0x014B,
  22512. engbopomofo: 0x3125,
  22513. enghecyrillic: 0x04A5,
  22514. enhookcyrillic: 0x04C8,
  22515. enspace: 0x2002,
  22516. eogonek: 0x0119,
  22517. eokorean: 0x3153,
  22518. eopen: 0x025B,
  22519. eopenclosed: 0x029A,
  22520. eopenreversed: 0x025C,
  22521. eopenreversedclosed: 0x025E,
  22522. eopenreversedhook: 0x025D,
  22523. eparen: 0x24A0,
  22524. epsilon: 0x03B5,
  22525. epsilontonos: 0x03AD,
  22526. equal: 0x003D,
  22527. equalmonospace: 0xFF1D,
  22528. equalsmall: 0xFE66,
  22529. equalsuperior: 0x207C,
  22530. equivalence: 0x2261,
  22531. erbopomofo: 0x3126,
  22532. ercyrillic: 0x0440,
  22533. ereversed: 0x0258,
  22534. ereversedcyrillic: 0x044D,
  22535. escyrillic: 0x0441,
  22536. esdescendercyrillic: 0x04AB,
  22537. esh: 0x0283,
  22538. eshcurl: 0x0286,
  22539. eshortdeva: 0x090E,
  22540. eshortvowelsigndeva: 0x0946,
  22541. eshreversedloop: 0x01AA,
  22542. eshsquatreversed: 0x0285,
  22543. esmallhiragana: 0x3047,
  22544. esmallkatakana: 0x30A7,
  22545. esmallkatakanahalfwidth: 0xFF6A,
  22546. estimated: 0x212E,
  22547. esuperior: 0xF6EC,
  22548. eta: 0x03B7,
  22549. etarmenian: 0x0568,
  22550. etatonos: 0x03AE,
  22551. eth: 0x00F0,
  22552. etilde: 0x1EBD,
  22553. etildebelow: 0x1E1B,
  22554. etnahtafoukhhebrew: 0x0591,
  22555. etnahtafoukhlefthebrew: 0x0591,
  22556. etnahtahebrew: 0x0591,
  22557. etnahtalefthebrew: 0x0591,
  22558. eturned: 0x01DD,
  22559. eukorean: 0x3161,
  22560. euro: 0x20AC,
  22561. evowelsignbengali: 0x09C7,
  22562. evowelsigndeva: 0x0947,
  22563. evowelsigngujarati: 0x0AC7,
  22564. exclam: 0x0021,
  22565. exclamarmenian: 0x055C,
  22566. exclamdbl: 0x203C,
  22567. exclamdown: 0x00A1,
  22568. exclamdownsmall: 0xF7A1,
  22569. exclammonospace: 0xFF01,
  22570. exclamsmall: 0xF721,
  22571. existential: 0x2203,
  22572. ezh: 0x0292,
  22573. ezhcaron: 0x01EF,
  22574. ezhcurl: 0x0293,
  22575. ezhreversed: 0x01B9,
  22576. ezhtail: 0x01BA,
  22577. f: 0x0066,
  22578. fadeva: 0x095E,
  22579. fagurmukhi: 0x0A5E,
  22580. fahrenheit: 0x2109,
  22581. fathaarabic: 0x064E,
  22582. fathalowarabic: 0x064E,
  22583. fathatanarabic: 0x064B,
  22584. fbopomofo: 0x3108,
  22585. fcircle: 0x24D5,
  22586. fdotaccent: 0x1E1F,
  22587. feharabic: 0x0641,
  22588. feharmenian: 0x0586,
  22589. fehfinalarabic: 0xFED2,
  22590. fehinitialarabic: 0xFED3,
  22591. fehmedialarabic: 0xFED4,
  22592. feicoptic: 0x03E5,
  22593. female: 0x2640,
  22594. ff: 0xFB00,
  22595. ffi: 0xFB03,
  22596. ffl: 0xFB04,
  22597. fi: 0xFB01,
  22598. fifteencircle: 0x246E,
  22599. fifteenparen: 0x2482,
  22600. fifteenperiod: 0x2496,
  22601. figuredash: 0x2012,
  22602. filledbox: 0x25A0,
  22603. filledrect: 0x25AC,
  22604. finalkaf: 0x05DA,
  22605. finalkafdagesh: 0xFB3A,
  22606. finalkafdageshhebrew: 0xFB3A,
  22607. finalkafhebrew: 0x05DA,
  22608. finalmem: 0x05DD,
  22609. finalmemhebrew: 0x05DD,
  22610. finalnun: 0x05DF,
  22611. finalnunhebrew: 0x05DF,
  22612. finalpe: 0x05E3,
  22613. finalpehebrew: 0x05E3,
  22614. finaltsadi: 0x05E5,
  22615. finaltsadihebrew: 0x05E5,
  22616. firsttonechinese: 0x02C9,
  22617. fisheye: 0x25C9,
  22618. fitacyrillic: 0x0473,
  22619. five: 0x0035,
  22620. fivearabic: 0x0665,
  22621. fivebengali: 0x09EB,
  22622. fivecircle: 0x2464,
  22623. fivecircleinversesansserif: 0x278E,
  22624. fivedeva: 0x096B,
  22625. fiveeighths: 0x215D,
  22626. fivegujarati: 0x0AEB,
  22627. fivegurmukhi: 0x0A6B,
  22628. fivehackarabic: 0x0665,
  22629. fivehangzhou: 0x3025,
  22630. fiveideographicparen: 0x3224,
  22631. fiveinferior: 0x2085,
  22632. fivemonospace: 0xFF15,
  22633. fiveoldstyle: 0xF735,
  22634. fiveparen: 0x2478,
  22635. fiveperiod: 0x248C,
  22636. fivepersian: 0x06F5,
  22637. fiveroman: 0x2174,
  22638. fivesuperior: 0x2075,
  22639. fivethai: 0x0E55,
  22640. fl: 0xFB02,
  22641. florin: 0x0192,
  22642. fmonospace: 0xFF46,
  22643. fmsquare: 0x3399,
  22644. fofanthai: 0x0E1F,
  22645. fofathai: 0x0E1D,
  22646. fongmanthai: 0x0E4F,
  22647. forall: 0x2200,
  22648. four: 0x0034,
  22649. fourarabic: 0x0664,
  22650. fourbengali: 0x09EA,
  22651. fourcircle: 0x2463,
  22652. fourcircleinversesansserif: 0x278D,
  22653. fourdeva: 0x096A,
  22654. fourgujarati: 0x0AEA,
  22655. fourgurmukhi: 0x0A6A,
  22656. fourhackarabic: 0x0664,
  22657. fourhangzhou: 0x3024,
  22658. fourideographicparen: 0x3223,
  22659. fourinferior: 0x2084,
  22660. fourmonospace: 0xFF14,
  22661. fournumeratorbengali: 0x09F7,
  22662. fouroldstyle: 0xF734,
  22663. fourparen: 0x2477,
  22664. fourperiod: 0x248B,
  22665. fourpersian: 0x06F4,
  22666. fourroman: 0x2173,
  22667. foursuperior: 0x2074,
  22668. fourteencircle: 0x246D,
  22669. fourteenparen: 0x2481,
  22670. fourteenperiod: 0x2495,
  22671. fourthai: 0x0E54,
  22672. fourthtonechinese: 0x02CB,
  22673. fparen: 0x24A1,
  22674. fraction: 0x2044,
  22675. franc: 0x20A3,
  22676. g: 0x0067,
  22677. gabengali: 0x0997,
  22678. gacute: 0x01F5,
  22679. gadeva: 0x0917,
  22680. gafarabic: 0x06AF,
  22681. gaffinalarabic: 0xFB93,
  22682. gafinitialarabic: 0xFB94,
  22683. gafmedialarabic: 0xFB95,
  22684. gagujarati: 0x0A97,
  22685. gagurmukhi: 0x0A17,
  22686. gahiragana: 0x304C,
  22687. gakatakana: 0x30AC,
  22688. gamma: 0x03B3,
  22689. gammalatinsmall: 0x0263,
  22690. gammasuperior: 0x02E0,
  22691. gangiacoptic: 0x03EB,
  22692. gbopomofo: 0x310D,
  22693. gbreve: 0x011F,
  22694. gcaron: 0x01E7,
  22695. gcedilla: 0x0123,
  22696. gcircle: 0x24D6,
  22697. gcircumflex: 0x011D,
  22698. gcommaaccent: 0x0123,
  22699. gdot: 0x0121,
  22700. gdotaccent: 0x0121,
  22701. gecyrillic: 0x0433,
  22702. gehiragana: 0x3052,
  22703. gekatakana: 0x30B2,
  22704. geometricallyequal: 0x2251,
  22705. gereshaccenthebrew: 0x059C,
  22706. gereshhebrew: 0x05F3,
  22707. gereshmuqdamhebrew: 0x059D,
  22708. germandbls: 0x00DF,
  22709. gershayimaccenthebrew: 0x059E,
  22710. gershayimhebrew: 0x05F4,
  22711. getamark: 0x3013,
  22712. ghabengali: 0x0998,
  22713. ghadarmenian: 0x0572,
  22714. ghadeva: 0x0918,
  22715. ghagujarati: 0x0A98,
  22716. ghagurmukhi: 0x0A18,
  22717. ghainarabic: 0x063A,
  22718. ghainfinalarabic: 0xFECE,
  22719. ghaininitialarabic: 0xFECF,
  22720. ghainmedialarabic: 0xFED0,
  22721. ghemiddlehookcyrillic: 0x0495,
  22722. ghestrokecyrillic: 0x0493,
  22723. gheupturncyrillic: 0x0491,
  22724. ghhadeva: 0x095A,
  22725. ghhagurmukhi: 0x0A5A,
  22726. ghook: 0x0260,
  22727. ghzsquare: 0x3393,
  22728. gihiragana: 0x304E,
  22729. gikatakana: 0x30AE,
  22730. gimarmenian: 0x0563,
  22731. gimel: 0x05D2,
  22732. gimeldagesh: 0xFB32,
  22733. gimeldageshhebrew: 0xFB32,
  22734. gimelhebrew: 0x05D2,
  22735. gjecyrillic: 0x0453,
  22736. glottalinvertedstroke: 0x01BE,
  22737. glottalstop: 0x0294,
  22738. glottalstopinverted: 0x0296,
  22739. glottalstopmod: 0x02C0,
  22740. glottalstopreversed: 0x0295,
  22741. glottalstopreversedmod: 0x02C1,
  22742. glottalstopreversedsuperior: 0x02E4,
  22743. glottalstopstroke: 0x02A1,
  22744. glottalstopstrokereversed: 0x02A2,
  22745. gmacron: 0x1E21,
  22746. gmonospace: 0xFF47,
  22747. gohiragana: 0x3054,
  22748. gokatakana: 0x30B4,
  22749. gparen: 0x24A2,
  22750. gpasquare: 0x33AC,
  22751. gradient: 0x2207,
  22752. grave: 0x0060,
  22753. gravebelowcmb: 0x0316,
  22754. gravecmb: 0x0300,
  22755. gravecomb: 0x0300,
  22756. gravedeva: 0x0953,
  22757. gravelowmod: 0x02CE,
  22758. gravemonospace: 0xFF40,
  22759. gravetonecmb: 0x0340,
  22760. greater: 0x003E,
  22761. greaterequal: 0x2265,
  22762. greaterequalorless: 0x22DB,
  22763. greatermonospace: 0xFF1E,
  22764. greaterorequivalent: 0x2273,
  22765. greaterorless: 0x2277,
  22766. greateroverequal: 0x2267,
  22767. greatersmall: 0xFE65,
  22768. gscript: 0x0261,
  22769. gstroke: 0x01E5,
  22770. guhiragana: 0x3050,
  22771. guillemotleft: 0x00AB,
  22772. guillemotright: 0x00BB,
  22773. guilsinglleft: 0x2039,
  22774. guilsinglright: 0x203A,
  22775. gukatakana: 0x30B0,
  22776. guramusquare: 0x3318,
  22777. gysquare: 0x33C9,
  22778. h: 0x0068,
  22779. haabkhasiancyrillic: 0x04A9,
  22780. haaltonearabic: 0x06C1,
  22781. habengali: 0x09B9,
  22782. hadescendercyrillic: 0x04B3,
  22783. hadeva: 0x0939,
  22784. hagujarati: 0x0AB9,
  22785. hagurmukhi: 0x0A39,
  22786. haharabic: 0x062D,
  22787. hahfinalarabic: 0xFEA2,
  22788. hahinitialarabic: 0xFEA3,
  22789. hahiragana: 0x306F,
  22790. hahmedialarabic: 0xFEA4,
  22791. haitusquare: 0x332A,
  22792. hakatakana: 0x30CF,
  22793. hakatakanahalfwidth: 0xFF8A,
  22794. halantgurmukhi: 0x0A4D,
  22795. hamzaarabic: 0x0621,
  22796. hamzalowarabic: 0x0621,
  22797. hangulfiller: 0x3164,
  22798. hardsigncyrillic: 0x044A,
  22799. harpoonleftbarbup: 0x21BC,
  22800. harpoonrightbarbup: 0x21C0,
  22801. hasquare: 0x33CA,
  22802. hatafpatah: 0x05B2,
  22803. hatafpatah16: 0x05B2,
  22804. hatafpatah23: 0x05B2,
  22805. hatafpatah2f: 0x05B2,
  22806. hatafpatahhebrew: 0x05B2,
  22807. hatafpatahnarrowhebrew: 0x05B2,
  22808. hatafpatahquarterhebrew: 0x05B2,
  22809. hatafpatahwidehebrew: 0x05B2,
  22810. hatafqamats: 0x05B3,
  22811. hatafqamats1b: 0x05B3,
  22812. hatafqamats28: 0x05B3,
  22813. hatafqamats34: 0x05B3,
  22814. hatafqamatshebrew: 0x05B3,
  22815. hatafqamatsnarrowhebrew: 0x05B3,
  22816. hatafqamatsquarterhebrew: 0x05B3,
  22817. hatafqamatswidehebrew: 0x05B3,
  22818. hatafsegol: 0x05B1,
  22819. hatafsegol17: 0x05B1,
  22820. hatafsegol24: 0x05B1,
  22821. hatafsegol30: 0x05B1,
  22822. hatafsegolhebrew: 0x05B1,
  22823. hatafsegolnarrowhebrew: 0x05B1,
  22824. hatafsegolquarterhebrew: 0x05B1,
  22825. hatafsegolwidehebrew: 0x05B1,
  22826. hbar: 0x0127,
  22827. hbopomofo: 0x310F,
  22828. hbrevebelow: 0x1E2B,
  22829. hcedilla: 0x1E29,
  22830. hcircle: 0x24D7,
  22831. hcircumflex: 0x0125,
  22832. hdieresis: 0x1E27,
  22833. hdotaccent: 0x1E23,
  22834. hdotbelow: 0x1E25,
  22835. he: 0x05D4,
  22836. heart: 0x2665,
  22837. heartsuitblack: 0x2665,
  22838. heartsuitwhite: 0x2661,
  22839. hedagesh: 0xFB34,
  22840. hedageshhebrew: 0xFB34,
  22841. hehaltonearabic: 0x06C1,
  22842. heharabic: 0x0647,
  22843. hehebrew: 0x05D4,
  22844. hehfinalaltonearabic: 0xFBA7,
  22845. hehfinalalttwoarabic: 0xFEEA,
  22846. hehfinalarabic: 0xFEEA,
  22847. hehhamzaabovefinalarabic: 0xFBA5,
  22848. hehhamzaaboveisolatedarabic: 0xFBA4,
  22849. hehinitialaltonearabic: 0xFBA8,
  22850. hehinitialarabic: 0xFEEB,
  22851. hehiragana: 0x3078,
  22852. hehmedialaltonearabic: 0xFBA9,
  22853. hehmedialarabic: 0xFEEC,
  22854. heiseierasquare: 0x337B,
  22855. hekatakana: 0x30D8,
  22856. hekatakanahalfwidth: 0xFF8D,
  22857. hekutaarusquare: 0x3336,
  22858. henghook: 0x0267,
  22859. herutusquare: 0x3339,
  22860. het: 0x05D7,
  22861. hethebrew: 0x05D7,
  22862. hhook: 0x0266,
  22863. hhooksuperior: 0x02B1,
  22864. hieuhacirclekorean: 0x327B,
  22865. hieuhaparenkorean: 0x321B,
  22866. hieuhcirclekorean: 0x326D,
  22867. hieuhkorean: 0x314E,
  22868. hieuhparenkorean: 0x320D,
  22869. hihiragana: 0x3072,
  22870. hikatakana: 0x30D2,
  22871. hikatakanahalfwidth: 0xFF8B,
  22872. hiriq: 0x05B4,
  22873. hiriq14: 0x05B4,
  22874. hiriq21: 0x05B4,
  22875. hiriq2d: 0x05B4,
  22876. hiriqhebrew: 0x05B4,
  22877. hiriqnarrowhebrew: 0x05B4,
  22878. hiriqquarterhebrew: 0x05B4,
  22879. hiriqwidehebrew: 0x05B4,
  22880. hlinebelow: 0x1E96,
  22881. hmonospace: 0xFF48,
  22882. hoarmenian: 0x0570,
  22883. hohipthai: 0x0E2B,
  22884. hohiragana: 0x307B,
  22885. hokatakana: 0x30DB,
  22886. hokatakanahalfwidth: 0xFF8E,
  22887. holam: 0x05B9,
  22888. holam19: 0x05B9,
  22889. holam26: 0x05B9,
  22890. holam32: 0x05B9,
  22891. holamhebrew: 0x05B9,
  22892. holamnarrowhebrew: 0x05B9,
  22893. holamquarterhebrew: 0x05B9,
  22894. holamwidehebrew: 0x05B9,
  22895. honokhukthai: 0x0E2E,
  22896. hookabovecomb: 0x0309,
  22897. hookcmb: 0x0309,
  22898. hookpalatalizedbelowcmb: 0x0321,
  22899. hookretroflexbelowcmb: 0x0322,
  22900. hoonsquare: 0x3342,
  22901. horicoptic: 0x03E9,
  22902. horizontalbar: 0x2015,
  22903. horncmb: 0x031B,
  22904. hotsprings: 0x2668,
  22905. house: 0x2302,
  22906. hparen: 0x24A3,
  22907. hsuperior: 0x02B0,
  22908. hturned: 0x0265,
  22909. huhiragana: 0x3075,
  22910. huiitosquare: 0x3333,
  22911. hukatakana: 0x30D5,
  22912. hukatakanahalfwidth: 0xFF8C,
  22913. hungarumlaut: 0x02DD,
  22914. hungarumlautcmb: 0x030B,
  22915. hv: 0x0195,
  22916. hyphen: 0x002D,
  22917. hypheninferior: 0xF6E5,
  22918. hyphenmonospace: 0xFF0D,
  22919. hyphensmall: 0xFE63,
  22920. hyphensuperior: 0xF6E6,
  22921. hyphentwo: 0x2010,
  22922. i: 0x0069,
  22923. iacute: 0x00ED,
  22924. iacyrillic: 0x044F,
  22925. ibengali: 0x0987,
  22926. ibopomofo: 0x3127,
  22927. ibreve: 0x012D,
  22928. icaron: 0x01D0,
  22929. icircle: 0x24D8,
  22930. icircumflex: 0x00EE,
  22931. icyrillic: 0x0456,
  22932. idblgrave: 0x0209,
  22933. ideographearthcircle: 0x328F,
  22934. ideographfirecircle: 0x328B,
  22935. ideographicallianceparen: 0x323F,
  22936. ideographiccallparen: 0x323A,
  22937. ideographiccentrecircle: 0x32A5,
  22938. ideographicclose: 0x3006,
  22939. ideographiccomma: 0x3001,
  22940. ideographiccommaleft: 0xFF64,
  22941. ideographiccongratulationparen: 0x3237,
  22942. ideographiccorrectcircle: 0x32A3,
  22943. ideographicearthparen: 0x322F,
  22944. ideographicenterpriseparen: 0x323D,
  22945. ideographicexcellentcircle: 0x329D,
  22946. ideographicfestivalparen: 0x3240,
  22947. ideographicfinancialcircle: 0x3296,
  22948. ideographicfinancialparen: 0x3236,
  22949. ideographicfireparen: 0x322B,
  22950. ideographichaveparen: 0x3232,
  22951. ideographichighcircle: 0x32A4,
  22952. ideographiciterationmark: 0x3005,
  22953. ideographiclaborcircle: 0x3298,
  22954. ideographiclaborparen: 0x3238,
  22955. ideographicleftcircle: 0x32A7,
  22956. ideographiclowcircle: 0x32A6,
  22957. ideographicmedicinecircle: 0x32A9,
  22958. ideographicmetalparen: 0x322E,
  22959. ideographicmoonparen: 0x322A,
  22960. ideographicnameparen: 0x3234,
  22961. ideographicperiod: 0x3002,
  22962. ideographicprintcircle: 0x329E,
  22963. ideographicreachparen: 0x3243,
  22964. ideographicrepresentparen: 0x3239,
  22965. ideographicresourceparen: 0x323E,
  22966. ideographicrightcircle: 0x32A8,
  22967. ideographicsecretcircle: 0x3299,
  22968. ideographicselfparen: 0x3242,
  22969. ideographicsocietyparen: 0x3233,
  22970. ideographicspace: 0x3000,
  22971. ideographicspecialparen: 0x3235,
  22972. ideographicstockparen: 0x3231,
  22973. ideographicstudyparen: 0x323B,
  22974. ideographicsunparen: 0x3230,
  22975. ideographicsuperviseparen: 0x323C,
  22976. ideographicwaterparen: 0x322C,
  22977. ideographicwoodparen: 0x322D,
  22978. ideographiczero: 0x3007,
  22979. ideographmetalcircle: 0x328E,
  22980. ideographmooncircle: 0x328A,
  22981. ideographnamecircle: 0x3294,
  22982. ideographsuncircle: 0x3290,
  22983. ideographwatercircle: 0x328C,
  22984. ideographwoodcircle: 0x328D,
  22985. ideva: 0x0907,
  22986. idieresis: 0x00EF,
  22987. idieresisacute: 0x1E2F,
  22988. idieresiscyrillic: 0x04E5,
  22989. idotbelow: 0x1ECB,
  22990. iebrevecyrillic: 0x04D7,
  22991. iecyrillic: 0x0435,
  22992. ieungacirclekorean: 0x3275,
  22993. ieungaparenkorean: 0x3215,
  22994. ieungcirclekorean: 0x3267,
  22995. ieungkorean: 0x3147,
  22996. ieungparenkorean: 0x3207,
  22997. igrave: 0x00EC,
  22998. igujarati: 0x0A87,
  22999. igurmukhi: 0x0A07,
  23000. ihiragana: 0x3044,
  23001. ihookabove: 0x1EC9,
  23002. iibengali: 0x0988,
  23003. iicyrillic: 0x0438,
  23004. iideva: 0x0908,
  23005. iigujarati: 0x0A88,
  23006. iigurmukhi: 0x0A08,
  23007. iimatragurmukhi: 0x0A40,
  23008. iinvertedbreve: 0x020B,
  23009. iishortcyrillic: 0x0439,
  23010. iivowelsignbengali: 0x09C0,
  23011. iivowelsigndeva: 0x0940,
  23012. iivowelsigngujarati: 0x0AC0,
  23013. ij: 0x0133,
  23014. ikatakana: 0x30A4,
  23015. ikatakanahalfwidth: 0xFF72,
  23016. ikorean: 0x3163,
  23017. ilde: 0x02DC,
  23018. iluyhebrew: 0x05AC,
  23019. imacron: 0x012B,
  23020. imacroncyrillic: 0x04E3,
  23021. imageorapproximatelyequal: 0x2253,
  23022. imatragurmukhi: 0x0A3F,
  23023. imonospace: 0xFF49,
  23024. increment: 0x2206,
  23025. infinity: 0x221E,
  23026. iniarmenian: 0x056B,
  23027. integral: 0x222B,
  23028. integralbottom: 0x2321,
  23029. integralbt: 0x2321,
  23030. integralex: 0xF8F5,
  23031. integraltop: 0x2320,
  23032. integraltp: 0x2320,
  23033. intersection: 0x2229,
  23034. intisquare: 0x3305,
  23035. invbullet: 0x25D8,
  23036. invcircle: 0x25D9,
  23037. invsmileface: 0x263B,
  23038. iocyrillic: 0x0451,
  23039. iogonek: 0x012F,
  23040. iota: 0x03B9,
  23041. iotadieresis: 0x03CA,
  23042. iotadieresistonos: 0x0390,
  23043. iotalatin: 0x0269,
  23044. iotatonos: 0x03AF,
  23045. iparen: 0x24A4,
  23046. irigurmukhi: 0x0A72,
  23047. ismallhiragana: 0x3043,
  23048. ismallkatakana: 0x30A3,
  23049. ismallkatakanahalfwidth: 0xFF68,
  23050. issharbengali: 0x09FA,
  23051. istroke: 0x0268,
  23052. isuperior: 0xF6ED,
  23053. iterationhiragana: 0x309D,
  23054. iterationkatakana: 0x30FD,
  23055. itilde: 0x0129,
  23056. itildebelow: 0x1E2D,
  23057. iubopomofo: 0x3129,
  23058. iucyrillic: 0x044E,
  23059. ivowelsignbengali: 0x09BF,
  23060. ivowelsigndeva: 0x093F,
  23061. ivowelsigngujarati: 0x0ABF,
  23062. izhitsacyrillic: 0x0475,
  23063. izhitsadblgravecyrillic: 0x0477,
  23064. j: 0x006A,
  23065. jaarmenian: 0x0571,
  23066. jabengali: 0x099C,
  23067. jadeva: 0x091C,
  23068. jagujarati: 0x0A9C,
  23069. jagurmukhi: 0x0A1C,
  23070. jbopomofo: 0x3110,
  23071. jcaron: 0x01F0,
  23072. jcircle: 0x24D9,
  23073. jcircumflex: 0x0135,
  23074. jcrossedtail: 0x029D,
  23075. jdotlessstroke: 0x025F,
  23076. jecyrillic: 0x0458,
  23077. jeemarabic: 0x062C,
  23078. jeemfinalarabic: 0xFE9E,
  23079. jeeminitialarabic: 0xFE9F,
  23080. jeemmedialarabic: 0xFEA0,
  23081. jeharabic: 0x0698,
  23082. jehfinalarabic: 0xFB8B,
  23083. jhabengali: 0x099D,
  23084. jhadeva: 0x091D,
  23085. jhagujarati: 0x0A9D,
  23086. jhagurmukhi: 0x0A1D,
  23087. jheharmenian: 0x057B,
  23088. jis: 0x3004,
  23089. jmonospace: 0xFF4A,
  23090. jparen: 0x24A5,
  23091. jsuperior: 0x02B2,
  23092. k: 0x006B,
  23093. kabashkircyrillic: 0x04A1,
  23094. kabengali: 0x0995,
  23095. kacute: 0x1E31,
  23096. kacyrillic: 0x043A,
  23097. kadescendercyrillic: 0x049B,
  23098. kadeva: 0x0915,
  23099. kaf: 0x05DB,
  23100. kafarabic: 0x0643,
  23101. kafdagesh: 0xFB3B,
  23102. kafdageshhebrew: 0xFB3B,
  23103. kaffinalarabic: 0xFEDA,
  23104. kafhebrew: 0x05DB,
  23105. kafinitialarabic: 0xFEDB,
  23106. kafmedialarabic: 0xFEDC,
  23107. kafrafehebrew: 0xFB4D,
  23108. kagujarati: 0x0A95,
  23109. kagurmukhi: 0x0A15,
  23110. kahiragana: 0x304B,
  23111. kahookcyrillic: 0x04C4,
  23112. kakatakana: 0x30AB,
  23113. kakatakanahalfwidth: 0xFF76,
  23114. kappa: 0x03BA,
  23115. kappasymbolgreek: 0x03F0,
  23116. kapyeounmieumkorean: 0x3171,
  23117. kapyeounphieuphkorean: 0x3184,
  23118. kapyeounpieupkorean: 0x3178,
  23119. kapyeounssangpieupkorean: 0x3179,
  23120. karoriisquare: 0x330D,
  23121. kashidaautoarabic: 0x0640,
  23122. kashidaautonosidebearingarabic: 0x0640,
  23123. kasmallkatakana: 0x30F5,
  23124. kasquare: 0x3384,
  23125. kasraarabic: 0x0650,
  23126. kasratanarabic: 0x064D,
  23127. kastrokecyrillic: 0x049F,
  23128. katahiraprolongmarkhalfwidth: 0xFF70,
  23129. kaverticalstrokecyrillic: 0x049D,
  23130. kbopomofo: 0x310E,
  23131. kcalsquare: 0x3389,
  23132. kcaron: 0x01E9,
  23133. kcedilla: 0x0137,
  23134. kcircle: 0x24DA,
  23135. kcommaaccent: 0x0137,
  23136. kdotbelow: 0x1E33,
  23137. keharmenian: 0x0584,
  23138. kehiragana: 0x3051,
  23139. kekatakana: 0x30B1,
  23140. kekatakanahalfwidth: 0xFF79,
  23141. kenarmenian: 0x056F,
  23142. kesmallkatakana: 0x30F6,
  23143. kgreenlandic: 0x0138,
  23144. khabengali: 0x0996,
  23145. khacyrillic: 0x0445,
  23146. khadeva: 0x0916,
  23147. khagujarati: 0x0A96,
  23148. khagurmukhi: 0x0A16,
  23149. khaharabic: 0x062E,
  23150. khahfinalarabic: 0xFEA6,
  23151. khahinitialarabic: 0xFEA7,
  23152. khahmedialarabic: 0xFEA8,
  23153. kheicoptic: 0x03E7,
  23154. khhadeva: 0x0959,
  23155. khhagurmukhi: 0x0A59,
  23156. khieukhacirclekorean: 0x3278,
  23157. khieukhaparenkorean: 0x3218,
  23158. khieukhcirclekorean: 0x326A,
  23159. khieukhkorean: 0x314B,
  23160. khieukhparenkorean: 0x320A,
  23161. khokhaithai: 0x0E02,
  23162. khokhonthai: 0x0E05,
  23163. khokhuatthai: 0x0E03,
  23164. khokhwaithai: 0x0E04,
  23165. khomutthai: 0x0E5B,
  23166. khook: 0x0199,
  23167. khorakhangthai: 0x0E06,
  23168. khzsquare: 0x3391,
  23169. kihiragana: 0x304D,
  23170. kikatakana: 0x30AD,
  23171. kikatakanahalfwidth: 0xFF77,
  23172. kiroguramusquare: 0x3315,
  23173. kiromeetorusquare: 0x3316,
  23174. kirosquare: 0x3314,
  23175. kiyeokacirclekorean: 0x326E,
  23176. kiyeokaparenkorean: 0x320E,
  23177. kiyeokcirclekorean: 0x3260,
  23178. kiyeokkorean: 0x3131,
  23179. kiyeokparenkorean: 0x3200,
  23180. kiyeoksioskorean: 0x3133,
  23181. kjecyrillic: 0x045C,
  23182. klinebelow: 0x1E35,
  23183. klsquare: 0x3398,
  23184. kmcubedsquare: 0x33A6,
  23185. kmonospace: 0xFF4B,
  23186. kmsquaredsquare: 0x33A2,
  23187. kohiragana: 0x3053,
  23188. kohmsquare: 0x33C0,
  23189. kokaithai: 0x0E01,
  23190. kokatakana: 0x30B3,
  23191. kokatakanahalfwidth: 0xFF7A,
  23192. kooposquare: 0x331E,
  23193. koppacyrillic: 0x0481,
  23194. koreanstandardsymbol: 0x327F,
  23195. koroniscmb: 0x0343,
  23196. kparen: 0x24A6,
  23197. kpasquare: 0x33AA,
  23198. ksicyrillic: 0x046F,
  23199. ktsquare: 0x33CF,
  23200. kturned: 0x029E,
  23201. kuhiragana: 0x304F,
  23202. kukatakana: 0x30AF,
  23203. kukatakanahalfwidth: 0xFF78,
  23204. kvsquare: 0x33B8,
  23205. kwsquare: 0x33BE,
  23206. l: 0x006C,
  23207. labengali: 0x09B2,
  23208. lacute: 0x013A,
  23209. ladeva: 0x0932,
  23210. lagujarati: 0x0AB2,
  23211. lagurmukhi: 0x0A32,
  23212. lakkhangyaothai: 0x0E45,
  23213. lamaleffinalarabic: 0xFEFC,
  23214. lamalefhamzaabovefinalarabic: 0xFEF8,
  23215. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  23216. lamalefhamzabelowfinalarabic: 0xFEFA,
  23217. lamalefhamzabelowisolatedarabic: 0xFEF9,
  23218. lamalefisolatedarabic: 0xFEFB,
  23219. lamalefmaddaabovefinalarabic: 0xFEF6,
  23220. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  23221. lamarabic: 0x0644,
  23222. lambda: 0x03BB,
  23223. lambdastroke: 0x019B,
  23224. lamed: 0x05DC,
  23225. lameddagesh: 0xFB3C,
  23226. lameddageshhebrew: 0xFB3C,
  23227. lamedhebrew: 0x05DC,
  23228. lamfinalarabic: 0xFEDE,
  23229. lamhahinitialarabic: 0xFCCA,
  23230. laminitialarabic: 0xFEDF,
  23231. lamjeeminitialarabic: 0xFCC9,
  23232. lamkhahinitialarabic: 0xFCCB,
  23233. lamlamhehisolatedarabic: 0xFDF2,
  23234. lammedialarabic: 0xFEE0,
  23235. lammeemhahinitialarabic: 0xFD88,
  23236. lammeeminitialarabic: 0xFCCC,
  23237. largecircle: 0x25EF,
  23238. lbar: 0x019A,
  23239. lbelt: 0x026C,
  23240. lbopomofo: 0x310C,
  23241. lcaron: 0x013E,
  23242. lcedilla: 0x013C,
  23243. lcircle: 0x24DB,
  23244. lcircumflexbelow: 0x1E3D,
  23245. lcommaaccent: 0x013C,
  23246. ldot: 0x0140,
  23247. ldotaccent: 0x0140,
  23248. ldotbelow: 0x1E37,
  23249. ldotbelowmacron: 0x1E39,
  23250. leftangleabovecmb: 0x031A,
  23251. lefttackbelowcmb: 0x0318,
  23252. less: 0x003C,
  23253. lessequal: 0x2264,
  23254. lessequalorgreater: 0x22DA,
  23255. lessmonospace: 0xFF1C,
  23256. lessorequivalent: 0x2272,
  23257. lessorgreater: 0x2276,
  23258. lessoverequal: 0x2266,
  23259. lesssmall: 0xFE64,
  23260. lezh: 0x026E,
  23261. lfblock: 0x258C,
  23262. lhookretroflex: 0x026D,
  23263. lira: 0x20A4,
  23264. liwnarmenian: 0x056C,
  23265. lj: 0x01C9,
  23266. ljecyrillic: 0x0459,
  23267. ll: 0xF6C0,
  23268. lladeva: 0x0933,
  23269. llagujarati: 0x0AB3,
  23270. llinebelow: 0x1E3B,
  23271. llladeva: 0x0934,
  23272. llvocalicbengali: 0x09E1,
  23273. llvocalicdeva: 0x0961,
  23274. llvocalicvowelsignbengali: 0x09E3,
  23275. llvocalicvowelsigndeva: 0x0963,
  23276. lmiddletilde: 0x026B,
  23277. lmonospace: 0xFF4C,
  23278. lmsquare: 0x33D0,
  23279. lochulathai: 0x0E2C,
  23280. logicaland: 0x2227,
  23281. logicalnot: 0x00AC,
  23282. logicalnotreversed: 0x2310,
  23283. logicalor: 0x2228,
  23284. lolingthai: 0x0E25,
  23285. longs: 0x017F,
  23286. lowlinecenterline: 0xFE4E,
  23287. lowlinecmb: 0x0332,
  23288. lowlinedashed: 0xFE4D,
  23289. lozenge: 0x25CA,
  23290. lparen: 0x24A7,
  23291. lslash: 0x0142,
  23292. lsquare: 0x2113,
  23293. lsuperior: 0xF6EE,
  23294. ltshade: 0x2591,
  23295. luthai: 0x0E26,
  23296. lvocalicbengali: 0x098C,
  23297. lvocalicdeva: 0x090C,
  23298. lvocalicvowelsignbengali: 0x09E2,
  23299. lvocalicvowelsigndeva: 0x0962,
  23300. lxsquare: 0x33D3,
  23301. m: 0x006D,
  23302. mabengali: 0x09AE,
  23303. macron: 0x00AF,
  23304. macronbelowcmb: 0x0331,
  23305. macroncmb: 0x0304,
  23306. macronlowmod: 0x02CD,
  23307. macronmonospace: 0xFFE3,
  23308. macute: 0x1E3F,
  23309. madeva: 0x092E,
  23310. magujarati: 0x0AAE,
  23311. magurmukhi: 0x0A2E,
  23312. mahapakhhebrew: 0x05A4,
  23313. mahapakhlefthebrew: 0x05A4,
  23314. mahiragana: 0x307E,
  23315. maichattawalowleftthai: 0xF895,
  23316. maichattawalowrightthai: 0xF894,
  23317. maichattawathai: 0x0E4B,
  23318. maichattawaupperleftthai: 0xF893,
  23319. maieklowleftthai: 0xF88C,
  23320. maieklowrightthai: 0xF88B,
  23321. maiekthai: 0x0E48,
  23322. maiekupperleftthai: 0xF88A,
  23323. maihanakatleftthai: 0xF884,
  23324. maihanakatthai: 0x0E31,
  23325. maitaikhuleftthai: 0xF889,
  23326. maitaikhuthai: 0x0E47,
  23327. maitholowleftthai: 0xF88F,
  23328. maitholowrightthai: 0xF88E,
  23329. maithothai: 0x0E49,
  23330. maithoupperleftthai: 0xF88D,
  23331. maitrilowleftthai: 0xF892,
  23332. maitrilowrightthai: 0xF891,
  23333. maitrithai: 0x0E4A,
  23334. maitriupperleftthai: 0xF890,
  23335. maiyamokthai: 0x0E46,
  23336. makatakana: 0x30DE,
  23337. makatakanahalfwidth: 0xFF8F,
  23338. male: 0x2642,
  23339. mansyonsquare: 0x3347,
  23340. maqafhebrew: 0x05BE,
  23341. mars: 0x2642,
  23342. masoracirclehebrew: 0x05AF,
  23343. masquare: 0x3383,
  23344. mbopomofo: 0x3107,
  23345. mbsquare: 0x33D4,
  23346. mcircle: 0x24DC,
  23347. mcubedsquare: 0x33A5,
  23348. mdotaccent: 0x1E41,
  23349. mdotbelow: 0x1E43,
  23350. meemarabic: 0x0645,
  23351. meemfinalarabic: 0xFEE2,
  23352. meeminitialarabic: 0xFEE3,
  23353. meemmedialarabic: 0xFEE4,
  23354. meemmeeminitialarabic: 0xFCD1,
  23355. meemmeemisolatedarabic: 0xFC48,
  23356. meetorusquare: 0x334D,
  23357. mehiragana: 0x3081,
  23358. meizierasquare: 0x337E,
  23359. mekatakana: 0x30E1,
  23360. mekatakanahalfwidth: 0xFF92,
  23361. mem: 0x05DE,
  23362. memdagesh: 0xFB3E,
  23363. memdageshhebrew: 0xFB3E,
  23364. memhebrew: 0x05DE,
  23365. menarmenian: 0x0574,
  23366. merkhahebrew: 0x05A5,
  23367. merkhakefulahebrew: 0x05A6,
  23368. merkhakefulalefthebrew: 0x05A6,
  23369. merkhalefthebrew: 0x05A5,
  23370. mhook: 0x0271,
  23371. mhzsquare: 0x3392,
  23372. middledotkatakanahalfwidth: 0xFF65,
  23373. middot: 0x00B7,
  23374. mieumacirclekorean: 0x3272,
  23375. mieumaparenkorean: 0x3212,
  23376. mieumcirclekorean: 0x3264,
  23377. mieumkorean: 0x3141,
  23378. mieumpansioskorean: 0x3170,
  23379. mieumparenkorean: 0x3204,
  23380. mieumpieupkorean: 0x316E,
  23381. mieumsioskorean: 0x316F,
  23382. mihiragana: 0x307F,
  23383. mikatakana: 0x30DF,
  23384. mikatakanahalfwidth: 0xFF90,
  23385. minus: 0x2212,
  23386. minusbelowcmb: 0x0320,
  23387. minuscircle: 0x2296,
  23388. minusmod: 0x02D7,
  23389. minusplus: 0x2213,
  23390. minute: 0x2032,
  23391. miribaarusquare: 0x334A,
  23392. mirisquare: 0x3349,
  23393. mlonglegturned: 0x0270,
  23394. mlsquare: 0x3396,
  23395. mmcubedsquare: 0x33A3,
  23396. mmonospace: 0xFF4D,
  23397. mmsquaredsquare: 0x339F,
  23398. mohiragana: 0x3082,
  23399. mohmsquare: 0x33C1,
  23400. mokatakana: 0x30E2,
  23401. mokatakanahalfwidth: 0xFF93,
  23402. molsquare: 0x33D6,
  23403. momathai: 0x0E21,
  23404. moverssquare: 0x33A7,
  23405. moverssquaredsquare: 0x33A8,
  23406. mparen: 0x24A8,
  23407. mpasquare: 0x33AB,
  23408. mssquare: 0x33B3,
  23409. msuperior: 0xF6EF,
  23410. mturned: 0x026F,
  23411. mu: 0x00B5,
  23412. mu1: 0x00B5,
  23413. muasquare: 0x3382,
  23414. muchgreater: 0x226B,
  23415. muchless: 0x226A,
  23416. mufsquare: 0x338C,
  23417. mugreek: 0x03BC,
  23418. mugsquare: 0x338D,
  23419. muhiragana: 0x3080,
  23420. mukatakana: 0x30E0,
  23421. mukatakanahalfwidth: 0xFF91,
  23422. mulsquare: 0x3395,
  23423. multiply: 0x00D7,
  23424. mumsquare: 0x339B,
  23425. munahhebrew: 0x05A3,
  23426. munahlefthebrew: 0x05A3,
  23427. musicalnote: 0x266A,
  23428. musicalnotedbl: 0x266B,
  23429. musicflatsign: 0x266D,
  23430. musicsharpsign: 0x266F,
  23431. mussquare: 0x33B2,
  23432. muvsquare: 0x33B6,
  23433. muwsquare: 0x33BC,
  23434. mvmegasquare: 0x33B9,
  23435. mvsquare: 0x33B7,
  23436. mwmegasquare: 0x33BF,
  23437. mwsquare: 0x33BD,
  23438. n: 0x006E,
  23439. nabengali: 0x09A8,
  23440. nabla: 0x2207,
  23441. nacute: 0x0144,
  23442. nadeva: 0x0928,
  23443. nagujarati: 0x0AA8,
  23444. nagurmukhi: 0x0A28,
  23445. nahiragana: 0x306A,
  23446. nakatakana: 0x30CA,
  23447. nakatakanahalfwidth: 0xFF85,
  23448. napostrophe: 0x0149,
  23449. nasquare: 0x3381,
  23450. nbopomofo: 0x310B,
  23451. nbspace: 0x00A0,
  23452. ncaron: 0x0148,
  23453. ncedilla: 0x0146,
  23454. ncircle: 0x24DD,
  23455. ncircumflexbelow: 0x1E4B,
  23456. ncommaaccent: 0x0146,
  23457. ndotaccent: 0x1E45,
  23458. ndotbelow: 0x1E47,
  23459. nehiragana: 0x306D,
  23460. nekatakana: 0x30CD,
  23461. nekatakanahalfwidth: 0xFF88,
  23462. newsheqelsign: 0x20AA,
  23463. nfsquare: 0x338B,
  23464. ngabengali: 0x0999,
  23465. ngadeva: 0x0919,
  23466. ngagujarati: 0x0A99,
  23467. ngagurmukhi: 0x0A19,
  23468. ngonguthai: 0x0E07,
  23469. nhiragana: 0x3093,
  23470. nhookleft: 0x0272,
  23471. nhookretroflex: 0x0273,
  23472. nieunacirclekorean: 0x326F,
  23473. nieunaparenkorean: 0x320F,
  23474. nieuncieuckorean: 0x3135,
  23475. nieuncirclekorean: 0x3261,
  23476. nieunhieuhkorean: 0x3136,
  23477. nieunkorean: 0x3134,
  23478. nieunpansioskorean: 0x3168,
  23479. nieunparenkorean: 0x3201,
  23480. nieunsioskorean: 0x3167,
  23481. nieuntikeutkorean: 0x3166,
  23482. nihiragana: 0x306B,
  23483. nikatakana: 0x30CB,
  23484. nikatakanahalfwidth: 0xFF86,
  23485. nikhahitleftthai: 0xF899,
  23486. nikhahitthai: 0x0E4D,
  23487. nine: 0x0039,
  23488. ninearabic: 0x0669,
  23489. ninebengali: 0x09EF,
  23490. ninecircle: 0x2468,
  23491. ninecircleinversesansserif: 0x2792,
  23492. ninedeva: 0x096F,
  23493. ninegujarati: 0x0AEF,
  23494. ninegurmukhi: 0x0A6F,
  23495. ninehackarabic: 0x0669,
  23496. ninehangzhou: 0x3029,
  23497. nineideographicparen: 0x3228,
  23498. nineinferior: 0x2089,
  23499. ninemonospace: 0xFF19,
  23500. nineoldstyle: 0xF739,
  23501. nineparen: 0x247C,
  23502. nineperiod: 0x2490,
  23503. ninepersian: 0x06F9,
  23504. nineroman: 0x2178,
  23505. ninesuperior: 0x2079,
  23506. nineteencircle: 0x2472,
  23507. nineteenparen: 0x2486,
  23508. nineteenperiod: 0x249A,
  23509. ninethai: 0x0E59,
  23510. nj: 0x01CC,
  23511. njecyrillic: 0x045A,
  23512. nkatakana: 0x30F3,
  23513. nkatakanahalfwidth: 0xFF9D,
  23514. nlegrightlong: 0x019E,
  23515. nlinebelow: 0x1E49,
  23516. nmonospace: 0xFF4E,
  23517. nmsquare: 0x339A,
  23518. nnabengali: 0x09A3,
  23519. nnadeva: 0x0923,
  23520. nnagujarati: 0x0AA3,
  23521. nnagurmukhi: 0x0A23,
  23522. nnnadeva: 0x0929,
  23523. nohiragana: 0x306E,
  23524. nokatakana: 0x30CE,
  23525. nokatakanahalfwidth: 0xFF89,
  23526. nonbreakingspace: 0x00A0,
  23527. nonenthai: 0x0E13,
  23528. nonuthai: 0x0E19,
  23529. noonarabic: 0x0646,
  23530. noonfinalarabic: 0xFEE6,
  23531. noonghunnaarabic: 0x06BA,
  23532. noonghunnafinalarabic: 0xFB9F,
  23533. nooninitialarabic: 0xFEE7,
  23534. noonjeeminitialarabic: 0xFCD2,
  23535. noonjeemisolatedarabic: 0xFC4B,
  23536. noonmedialarabic: 0xFEE8,
  23537. noonmeeminitialarabic: 0xFCD5,
  23538. noonmeemisolatedarabic: 0xFC4E,
  23539. noonnoonfinalarabic: 0xFC8D,
  23540. notcontains: 0x220C,
  23541. notelement: 0x2209,
  23542. notelementof: 0x2209,
  23543. notequal: 0x2260,
  23544. notgreater: 0x226F,
  23545. notgreaternorequal: 0x2271,
  23546. notgreaternorless: 0x2279,
  23547. notidentical: 0x2262,
  23548. notless: 0x226E,
  23549. notlessnorequal: 0x2270,
  23550. notparallel: 0x2226,
  23551. notprecedes: 0x2280,
  23552. notsubset: 0x2284,
  23553. notsucceeds: 0x2281,
  23554. notsuperset: 0x2285,
  23555. nowarmenian: 0x0576,
  23556. nparen: 0x24A9,
  23557. nssquare: 0x33B1,
  23558. nsuperior: 0x207F,
  23559. ntilde: 0x00F1,
  23560. nu: 0x03BD,
  23561. nuhiragana: 0x306C,
  23562. nukatakana: 0x30CC,
  23563. nukatakanahalfwidth: 0xFF87,
  23564. nuktabengali: 0x09BC,
  23565. nuktadeva: 0x093C,
  23566. nuktagujarati: 0x0ABC,
  23567. nuktagurmukhi: 0x0A3C,
  23568. numbersign: 0x0023,
  23569. numbersignmonospace: 0xFF03,
  23570. numbersignsmall: 0xFE5F,
  23571. numeralsigngreek: 0x0374,
  23572. numeralsignlowergreek: 0x0375,
  23573. numero: 0x2116,
  23574. nun: 0x05E0,
  23575. nundagesh: 0xFB40,
  23576. nundageshhebrew: 0xFB40,
  23577. nunhebrew: 0x05E0,
  23578. nvsquare: 0x33B5,
  23579. nwsquare: 0x33BB,
  23580. nyabengali: 0x099E,
  23581. nyadeva: 0x091E,
  23582. nyagujarati: 0x0A9E,
  23583. nyagurmukhi: 0x0A1E,
  23584. o: 0x006F,
  23585. oacute: 0x00F3,
  23586. oangthai: 0x0E2D,
  23587. obarred: 0x0275,
  23588. obarredcyrillic: 0x04E9,
  23589. obarreddieresiscyrillic: 0x04EB,
  23590. obengali: 0x0993,
  23591. obopomofo: 0x311B,
  23592. obreve: 0x014F,
  23593. ocandradeva: 0x0911,
  23594. ocandragujarati: 0x0A91,
  23595. ocandravowelsigndeva: 0x0949,
  23596. ocandravowelsigngujarati: 0x0AC9,
  23597. ocaron: 0x01D2,
  23598. ocircle: 0x24DE,
  23599. ocircumflex: 0x00F4,
  23600. ocircumflexacute: 0x1ED1,
  23601. ocircumflexdotbelow: 0x1ED9,
  23602. ocircumflexgrave: 0x1ED3,
  23603. ocircumflexhookabove: 0x1ED5,
  23604. ocircumflextilde: 0x1ED7,
  23605. ocyrillic: 0x043E,
  23606. odblacute: 0x0151,
  23607. odblgrave: 0x020D,
  23608. odeva: 0x0913,
  23609. odieresis: 0x00F6,
  23610. odieresiscyrillic: 0x04E7,
  23611. odotbelow: 0x1ECD,
  23612. oe: 0x0153,
  23613. oekorean: 0x315A,
  23614. ogonek: 0x02DB,
  23615. ogonekcmb: 0x0328,
  23616. ograve: 0x00F2,
  23617. ogujarati: 0x0A93,
  23618. oharmenian: 0x0585,
  23619. ohiragana: 0x304A,
  23620. ohookabove: 0x1ECF,
  23621. ohorn: 0x01A1,
  23622. ohornacute: 0x1EDB,
  23623. ohorndotbelow: 0x1EE3,
  23624. ohorngrave: 0x1EDD,
  23625. ohornhookabove: 0x1EDF,
  23626. ohorntilde: 0x1EE1,
  23627. ohungarumlaut: 0x0151,
  23628. oi: 0x01A3,
  23629. oinvertedbreve: 0x020F,
  23630. okatakana: 0x30AA,
  23631. okatakanahalfwidth: 0xFF75,
  23632. okorean: 0x3157,
  23633. olehebrew: 0x05AB,
  23634. omacron: 0x014D,
  23635. omacronacute: 0x1E53,
  23636. omacrongrave: 0x1E51,
  23637. omdeva: 0x0950,
  23638. omega: 0x03C9,
  23639. omega1: 0x03D6,
  23640. omegacyrillic: 0x0461,
  23641. omegalatinclosed: 0x0277,
  23642. omegaroundcyrillic: 0x047B,
  23643. omegatitlocyrillic: 0x047D,
  23644. omegatonos: 0x03CE,
  23645. omgujarati: 0x0AD0,
  23646. omicron: 0x03BF,
  23647. omicrontonos: 0x03CC,
  23648. omonospace: 0xFF4F,
  23649. one: 0x0031,
  23650. onearabic: 0x0661,
  23651. onebengali: 0x09E7,
  23652. onecircle: 0x2460,
  23653. onecircleinversesansserif: 0x278A,
  23654. onedeva: 0x0967,
  23655. onedotenleader: 0x2024,
  23656. oneeighth: 0x215B,
  23657. onefitted: 0xF6DC,
  23658. onegujarati: 0x0AE7,
  23659. onegurmukhi: 0x0A67,
  23660. onehackarabic: 0x0661,
  23661. onehalf: 0x00BD,
  23662. onehangzhou: 0x3021,
  23663. oneideographicparen: 0x3220,
  23664. oneinferior: 0x2081,
  23665. onemonospace: 0xFF11,
  23666. onenumeratorbengali: 0x09F4,
  23667. oneoldstyle: 0xF731,
  23668. oneparen: 0x2474,
  23669. oneperiod: 0x2488,
  23670. onepersian: 0x06F1,
  23671. onequarter: 0x00BC,
  23672. oneroman: 0x2170,
  23673. onesuperior: 0x00B9,
  23674. onethai: 0x0E51,
  23675. onethird: 0x2153,
  23676. oogonek: 0x01EB,
  23677. oogonekmacron: 0x01ED,
  23678. oogurmukhi: 0x0A13,
  23679. oomatragurmukhi: 0x0A4B,
  23680. oopen: 0x0254,
  23681. oparen: 0x24AA,
  23682. openbullet: 0x25E6,
  23683. option: 0x2325,
  23684. ordfeminine: 0x00AA,
  23685. ordmasculine: 0x00BA,
  23686. orthogonal: 0x221F,
  23687. oshortdeva: 0x0912,
  23688. oshortvowelsigndeva: 0x094A,
  23689. oslash: 0x00F8,
  23690. oslashacute: 0x01FF,
  23691. osmallhiragana: 0x3049,
  23692. osmallkatakana: 0x30A9,
  23693. osmallkatakanahalfwidth: 0xFF6B,
  23694. ostrokeacute: 0x01FF,
  23695. osuperior: 0xF6F0,
  23696. otcyrillic: 0x047F,
  23697. otilde: 0x00F5,
  23698. otildeacute: 0x1E4D,
  23699. otildedieresis: 0x1E4F,
  23700. oubopomofo: 0x3121,
  23701. overline: 0x203E,
  23702. overlinecenterline: 0xFE4A,
  23703. overlinecmb: 0x0305,
  23704. overlinedashed: 0xFE49,
  23705. overlinedblwavy: 0xFE4C,
  23706. overlinewavy: 0xFE4B,
  23707. overscore: 0x00AF,
  23708. ovowelsignbengali: 0x09CB,
  23709. ovowelsigndeva: 0x094B,
  23710. ovowelsigngujarati: 0x0ACB,
  23711. p: 0x0070,
  23712. paampssquare: 0x3380,
  23713. paasentosquare: 0x332B,
  23714. pabengali: 0x09AA,
  23715. pacute: 0x1E55,
  23716. padeva: 0x092A,
  23717. pagedown: 0x21DF,
  23718. pageup: 0x21DE,
  23719. pagujarati: 0x0AAA,
  23720. pagurmukhi: 0x0A2A,
  23721. pahiragana: 0x3071,
  23722. paiyannoithai: 0x0E2F,
  23723. pakatakana: 0x30D1,
  23724. palatalizationcyrilliccmb: 0x0484,
  23725. palochkacyrillic: 0x04C0,
  23726. pansioskorean: 0x317F,
  23727. paragraph: 0x00B6,
  23728. parallel: 0x2225,
  23729. parenleft: 0x0028,
  23730. parenleftaltonearabic: 0xFD3E,
  23731. parenleftbt: 0xF8ED,
  23732. parenleftex: 0xF8EC,
  23733. parenleftinferior: 0x208D,
  23734. parenleftmonospace: 0xFF08,
  23735. parenleftsmall: 0xFE59,
  23736. parenleftsuperior: 0x207D,
  23737. parenlefttp: 0xF8EB,
  23738. parenleftvertical: 0xFE35,
  23739. parenright: 0x0029,
  23740. parenrightaltonearabic: 0xFD3F,
  23741. parenrightbt: 0xF8F8,
  23742. parenrightex: 0xF8F7,
  23743. parenrightinferior: 0x208E,
  23744. parenrightmonospace: 0xFF09,
  23745. parenrightsmall: 0xFE5A,
  23746. parenrightsuperior: 0x207E,
  23747. parenrighttp: 0xF8F6,
  23748. parenrightvertical: 0xFE36,
  23749. partialdiff: 0x2202,
  23750. paseqhebrew: 0x05C0,
  23751. pashtahebrew: 0x0599,
  23752. pasquare: 0x33A9,
  23753. patah: 0x05B7,
  23754. patah11: 0x05B7,
  23755. patah1d: 0x05B7,
  23756. patah2a: 0x05B7,
  23757. patahhebrew: 0x05B7,
  23758. patahnarrowhebrew: 0x05B7,
  23759. patahquarterhebrew: 0x05B7,
  23760. patahwidehebrew: 0x05B7,
  23761. pazerhebrew: 0x05A1,
  23762. pbopomofo: 0x3106,
  23763. pcircle: 0x24DF,
  23764. pdotaccent: 0x1E57,
  23765. pe: 0x05E4,
  23766. pecyrillic: 0x043F,
  23767. pedagesh: 0xFB44,
  23768. pedageshhebrew: 0xFB44,
  23769. peezisquare: 0x333B,
  23770. pefinaldageshhebrew: 0xFB43,
  23771. peharabic: 0x067E,
  23772. peharmenian: 0x057A,
  23773. pehebrew: 0x05E4,
  23774. pehfinalarabic: 0xFB57,
  23775. pehinitialarabic: 0xFB58,
  23776. pehiragana: 0x307A,
  23777. pehmedialarabic: 0xFB59,
  23778. pekatakana: 0x30DA,
  23779. pemiddlehookcyrillic: 0x04A7,
  23780. perafehebrew: 0xFB4E,
  23781. percent: 0x0025,
  23782. percentarabic: 0x066A,
  23783. percentmonospace: 0xFF05,
  23784. percentsmall: 0xFE6A,
  23785. period: 0x002E,
  23786. periodarmenian: 0x0589,
  23787. periodcentered: 0x00B7,
  23788. periodhalfwidth: 0xFF61,
  23789. periodinferior: 0xF6E7,
  23790. periodmonospace: 0xFF0E,
  23791. periodsmall: 0xFE52,
  23792. periodsuperior: 0xF6E8,
  23793. perispomenigreekcmb: 0x0342,
  23794. perpendicular: 0x22A5,
  23795. perthousand: 0x2030,
  23796. peseta: 0x20A7,
  23797. pfsquare: 0x338A,
  23798. phabengali: 0x09AB,
  23799. phadeva: 0x092B,
  23800. phagujarati: 0x0AAB,
  23801. phagurmukhi: 0x0A2B,
  23802. phi: 0x03C6,
  23803. phi1: 0x03D5,
  23804. phieuphacirclekorean: 0x327A,
  23805. phieuphaparenkorean: 0x321A,
  23806. phieuphcirclekorean: 0x326C,
  23807. phieuphkorean: 0x314D,
  23808. phieuphparenkorean: 0x320C,
  23809. philatin: 0x0278,
  23810. phinthuthai: 0x0E3A,
  23811. phisymbolgreek: 0x03D5,
  23812. phook: 0x01A5,
  23813. phophanthai: 0x0E1E,
  23814. phophungthai: 0x0E1C,
  23815. phosamphaothai: 0x0E20,
  23816. pi: 0x03C0,
  23817. pieupacirclekorean: 0x3273,
  23818. pieupaparenkorean: 0x3213,
  23819. pieupcieuckorean: 0x3176,
  23820. pieupcirclekorean: 0x3265,
  23821. pieupkiyeokkorean: 0x3172,
  23822. pieupkorean: 0x3142,
  23823. pieupparenkorean: 0x3205,
  23824. pieupsioskiyeokkorean: 0x3174,
  23825. pieupsioskorean: 0x3144,
  23826. pieupsiostikeutkorean: 0x3175,
  23827. pieupthieuthkorean: 0x3177,
  23828. pieuptikeutkorean: 0x3173,
  23829. pihiragana: 0x3074,
  23830. pikatakana: 0x30D4,
  23831. pisymbolgreek: 0x03D6,
  23832. piwrarmenian: 0x0583,
  23833. plus: 0x002B,
  23834. plusbelowcmb: 0x031F,
  23835. pluscircle: 0x2295,
  23836. plusminus: 0x00B1,
  23837. plusmod: 0x02D6,
  23838. plusmonospace: 0xFF0B,
  23839. plussmall: 0xFE62,
  23840. plussuperior: 0x207A,
  23841. pmonospace: 0xFF50,
  23842. pmsquare: 0x33D8,
  23843. pohiragana: 0x307D,
  23844. pointingindexdownwhite: 0x261F,
  23845. pointingindexleftwhite: 0x261C,
  23846. pointingindexrightwhite: 0x261E,
  23847. pointingindexupwhite: 0x261D,
  23848. pokatakana: 0x30DD,
  23849. poplathai: 0x0E1B,
  23850. postalmark: 0x3012,
  23851. postalmarkface: 0x3020,
  23852. pparen: 0x24AB,
  23853. precedes: 0x227A,
  23854. prescription: 0x211E,
  23855. primemod: 0x02B9,
  23856. primereversed: 0x2035,
  23857. product: 0x220F,
  23858. projective: 0x2305,
  23859. prolongedkana: 0x30FC,
  23860. propellor: 0x2318,
  23861. propersubset: 0x2282,
  23862. propersuperset: 0x2283,
  23863. proportion: 0x2237,
  23864. proportional: 0x221D,
  23865. psi: 0x03C8,
  23866. psicyrillic: 0x0471,
  23867. psilipneumatacyrilliccmb: 0x0486,
  23868. pssquare: 0x33B0,
  23869. puhiragana: 0x3077,
  23870. pukatakana: 0x30D7,
  23871. pvsquare: 0x33B4,
  23872. pwsquare: 0x33BA,
  23873. q: 0x0071,
  23874. qadeva: 0x0958,
  23875. qadmahebrew: 0x05A8,
  23876. qafarabic: 0x0642,
  23877. qaffinalarabic: 0xFED6,
  23878. qafinitialarabic: 0xFED7,
  23879. qafmedialarabic: 0xFED8,
  23880. qamats: 0x05B8,
  23881. qamats10: 0x05B8,
  23882. qamats1a: 0x05B8,
  23883. qamats1c: 0x05B8,
  23884. qamats27: 0x05B8,
  23885. qamats29: 0x05B8,
  23886. qamats33: 0x05B8,
  23887. qamatsde: 0x05B8,
  23888. qamatshebrew: 0x05B8,
  23889. qamatsnarrowhebrew: 0x05B8,
  23890. qamatsqatanhebrew: 0x05B8,
  23891. qamatsqatannarrowhebrew: 0x05B8,
  23892. qamatsqatanquarterhebrew: 0x05B8,
  23893. qamatsqatanwidehebrew: 0x05B8,
  23894. qamatsquarterhebrew: 0x05B8,
  23895. qamatswidehebrew: 0x05B8,
  23896. qarneyparahebrew: 0x059F,
  23897. qbopomofo: 0x3111,
  23898. qcircle: 0x24E0,
  23899. qhook: 0x02A0,
  23900. qmonospace: 0xFF51,
  23901. qof: 0x05E7,
  23902. qofdagesh: 0xFB47,
  23903. qofdageshhebrew: 0xFB47,
  23904. qofhebrew: 0x05E7,
  23905. qparen: 0x24AC,
  23906. quarternote: 0x2669,
  23907. qubuts: 0x05BB,
  23908. qubuts18: 0x05BB,
  23909. qubuts25: 0x05BB,
  23910. qubuts31: 0x05BB,
  23911. qubutshebrew: 0x05BB,
  23912. qubutsnarrowhebrew: 0x05BB,
  23913. qubutsquarterhebrew: 0x05BB,
  23914. qubutswidehebrew: 0x05BB,
  23915. question: 0x003F,
  23916. questionarabic: 0x061F,
  23917. questionarmenian: 0x055E,
  23918. questiondown: 0x00BF,
  23919. questiondownsmall: 0xF7BF,
  23920. questiongreek: 0x037E,
  23921. questionmonospace: 0xFF1F,
  23922. questionsmall: 0xF73F,
  23923. quotedbl: 0x0022,
  23924. quotedblbase: 0x201E,
  23925. quotedblleft: 0x201C,
  23926. quotedblmonospace: 0xFF02,
  23927. quotedblprime: 0x301E,
  23928. quotedblprimereversed: 0x301D,
  23929. quotedblright: 0x201D,
  23930. quoteleft: 0x2018,
  23931. quoteleftreversed: 0x201B,
  23932. quotereversed: 0x201B,
  23933. quoteright: 0x2019,
  23934. quoterightn: 0x0149,
  23935. quotesinglbase: 0x201A,
  23936. quotesingle: 0x0027,
  23937. quotesinglemonospace: 0xFF07,
  23938. r: 0x0072,
  23939. raarmenian: 0x057C,
  23940. rabengali: 0x09B0,
  23941. racute: 0x0155,
  23942. radeva: 0x0930,
  23943. radical: 0x221A,
  23944. radicalex: 0xF8E5,
  23945. radoverssquare: 0x33AE,
  23946. radoverssquaredsquare: 0x33AF,
  23947. radsquare: 0x33AD,
  23948. rafe: 0x05BF,
  23949. rafehebrew: 0x05BF,
  23950. ragujarati: 0x0AB0,
  23951. ragurmukhi: 0x0A30,
  23952. rahiragana: 0x3089,
  23953. rakatakana: 0x30E9,
  23954. rakatakanahalfwidth: 0xFF97,
  23955. ralowerdiagonalbengali: 0x09F1,
  23956. ramiddlediagonalbengali: 0x09F0,
  23957. ramshorn: 0x0264,
  23958. ratio: 0x2236,
  23959. rbopomofo: 0x3116,
  23960. rcaron: 0x0159,
  23961. rcedilla: 0x0157,
  23962. rcircle: 0x24E1,
  23963. rcommaaccent: 0x0157,
  23964. rdblgrave: 0x0211,
  23965. rdotaccent: 0x1E59,
  23966. rdotbelow: 0x1E5B,
  23967. rdotbelowmacron: 0x1E5D,
  23968. referencemark: 0x203B,
  23969. reflexsubset: 0x2286,
  23970. reflexsuperset: 0x2287,
  23971. registered: 0x00AE,
  23972. registersans: 0xF8E8,
  23973. registerserif: 0xF6DA,
  23974. reharabic: 0x0631,
  23975. reharmenian: 0x0580,
  23976. rehfinalarabic: 0xFEAE,
  23977. rehiragana: 0x308C,
  23978. rekatakana: 0x30EC,
  23979. rekatakanahalfwidth: 0xFF9A,
  23980. resh: 0x05E8,
  23981. reshdageshhebrew: 0xFB48,
  23982. reshhebrew: 0x05E8,
  23983. reversedtilde: 0x223D,
  23984. reviahebrew: 0x0597,
  23985. reviamugrashhebrew: 0x0597,
  23986. revlogicalnot: 0x2310,
  23987. rfishhook: 0x027E,
  23988. rfishhookreversed: 0x027F,
  23989. rhabengali: 0x09DD,
  23990. rhadeva: 0x095D,
  23991. rho: 0x03C1,
  23992. rhook: 0x027D,
  23993. rhookturned: 0x027B,
  23994. rhookturnedsuperior: 0x02B5,
  23995. rhosymbolgreek: 0x03F1,
  23996. rhotichookmod: 0x02DE,
  23997. rieulacirclekorean: 0x3271,
  23998. rieulaparenkorean: 0x3211,
  23999. rieulcirclekorean: 0x3263,
  24000. rieulhieuhkorean: 0x3140,
  24001. rieulkiyeokkorean: 0x313A,
  24002. rieulkiyeoksioskorean: 0x3169,
  24003. rieulkorean: 0x3139,
  24004. rieulmieumkorean: 0x313B,
  24005. rieulpansioskorean: 0x316C,
  24006. rieulparenkorean: 0x3203,
  24007. rieulphieuphkorean: 0x313F,
  24008. rieulpieupkorean: 0x313C,
  24009. rieulpieupsioskorean: 0x316B,
  24010. rieulsioskorean: 0x313D,
  24011. rieulthieuthkorean: 0x313E,
  24012. rieultikeutkorean: 0x316A,
  24013. rieulyeorinhieuhkorean: 0x316D,
  24014. rightangle: 0x221F,
  24015. righttackbelowcmb: 0x0319,
  24016. righttriangle: 0x22BF,
  24017. rihiragana: 0x308A,
  24018. rikatakana: 0x30EA,
  24019. rikatakanahalfwidth: 0xFF98,
  24020. ring: 0x02DA,
  24021. ringbelowcmb: 0x0325,
  24022. ringcmb: 0x030A,
  24023. ringhalfleft: 0x02BF,
  24024. ringhalfleftarmenian: 0x0559,
  24025. ringhalfleftbelowcmb: 0x031C,
  24026. ringhalfleftcentered: 0x02D3,
  24027. ringhalfright: 0x02BE,
  24028. ringhalfrightbelowcmb: 0x0339,
  24029. ringhalfrightcentered: 0x02D2,
  24030. rinvertedbreve: 0x0213,
  24031. rittorusquare: 0x3351,
  24032. rlinebelow: 0x1E5F,
  24033. rlongleg: 0x027C,
  24034. rlonglegturned: 0x027A,
  24035. rmonospace: 0xFF52,
  24036. rohiragana: 0x308D,
  24037. rokatakana: 0x30ED,
  24038. rokatakanahalfwidth: 0xFF9B,
  24039. roruathai: 0x0E23,
  24040. rparen: 0x24AD,
  24041. rrabengali: 0x09DC,
  24042. rradeva: 0x0931,
  24043. rragurmukhi: 0x0A5C,
  24044. rreharabic: 0x0691,
  24045. rrehfinalarabic: 0xFB8D,
  24046. rrvocalicbengali: 0x09E0,
  24047. rrvocalicdeva: 0x0960,
  24048. rrvocalicgujarati: 0x0AE0,
  24049. rrvocalicvowelsignbengali: 0x09C4,
  24050. rrvocalicvowelsigndeva: 0x0944,
  24051. rrvocalicvowelsigngujarati: 0x0AC4,
  24052. rsuperior: 0xF6F1,
  24053. rtblock: 0x2590,
  24054. rturned: 0x0279,
  24055. rturnedsuperior: 0x02B4,
  24056. ruhiragana: 0x308B,
  24057. rukatakana: 0x30EB,
  24058. rukatakanahalfwidth: 0xFF99,
  24059. rupeemarkbengali: 0x09F2,
  24060. rupeesignbengali: 0x09F3,
  24061. rupiah: 0xF6DD,
  24062. ruthai: 0x0E24,
  24063. rvocalicbengali: 0x098B,
  24064. rvocalicdeva: 0x090B,
  24065. rvocalicgujarati: 0x0A8B,
  24066. rvocalicvowelsignbengali: 0x09C3,
  24067. rvocalicvowelsigndeva: 0x0943,
  24068. rvocalicvowelsigngujarati: 0x0AC3,
  24069. s: 0x0073,
  24070. sabengali: 0x09B8,
  24071. sacute: 0x015B,
  24072. sacutedotaccent: 0x1E65,
  24073. sadarabic: 0x0635,
  24074. sadeva: 0x0938,
  24075. sadfinalarabic: 0xFEBA,
  24076. sadinitialarabic: 0xFEBB,
  24077. sadmedialarabic: 0xFEBC,
  24078. sagujarati: 0x0AB8,
  24079. sagurmukhi: 0x0A38,
  24080. sahiragana: 0x3055,
  24081. sakatakana: 0x30B5,
  24082. sakatakanahalfwidth: 0xFF7B,
  24083. sallallahoualayhewasallamarabic: 0xFDFA,
  24084. samekh: 0x05E1,
  24085. samekhdagesh: 0xFB41,
  24086. samekhdageshhebrew: 0xFB41,
  24087. samekhhebrew: 0x05E1,
  24088. saraaathai: 0x0E32,
  24089. saraaethai: 0x0E41,
  24090. saraaimaimalaithai: 0x0E44,
  24091. saraaimaimuanthai: 0x0E43,
  24092. saraamthai: 0x0E33,
  24093. saraathai: 0x0E30,
  24094. saraethai: 0x0E40,
  24095. saraiileftthai: 0xF886,
  24096. saraiithai: 0x0E35,
  24097. saraileftthai: 0xF885,
  24098. saraithai: 0x0E34,
  24099. saraothai: 0x0E42,
  24100. saraueeleftthai: 0xF888,
  24101. saraueethai: 0x0E37,
  24102. saraueleftthai: 0xF887,
  24103. sarauethai: 0x0E36,
  24104. sarauthai: 0x0E38,
  24105. sarauuthai: 0x0E39,
  24106. sbopomofo: 0x3119,
  24107. scaron: 0x0161,
  24108. scarondotaccent: 0x1E67,
  24109. scedilla: 0x015F,
  24110. schwa: 0x0259,
  24111. schwacyrillic: 0x04D9,
  24112. schwadieresiscyrillic: 0x04DB,
  24113. schwahook: 0x025A,
  24114. scircle: 0x24E2,
  24115. scircumflex: 0x015D,
  24116. scommaaccent: 0x0219,
  24117. sdotaccent: 0x1E61,
  24118. sdotbelow: 0x1E63,
  24119. sdotbelowdotaccent: 0x1E69,
  24120. seagullbelowcmb: 0x033C,
  24121. second: 0x2033,
  24122. secondtonechinese: 0x02CA,
  24123. section: 0x00A7,
  24124. seenarabic: 0x0633,
  24125. seenfinalarabic: 0xFEB2,
  24126. seeninitialarabic: 0xFEB3,
  24127. seenmedialarabic: 0xFEB4,
  24128. segol: 0x05B6,
  24129. segol13: 0x05B6,
  24130. segol1f: 0x05B6,
  24131. segol2c: 0x05B6,
  24132. segolhebrew: 0x05B6,
  24133. segolnarrowhebrew: 0x05B6,
  24134. segolquarterhebrew: 0x05B6,
  24135. segoltahebrew: 0x0592,
  24136. segolwidehebrew: 0x05B6,
  24137. seharmenian: 0x057D,
  24138. sehiragana: 0x305B,
  24139. sekatakana: 0x30BB,
  24140. sekatakanahalfwidth: 0xFF7E,
  24141. semicolon: 0x003B,
  24142. semicolonarabic: 0x061B,
  24143. semicolonmonospace: 0xFF1B,
  24144. semicolonsmall: 0xFE54,
  24145. semivoicedmarkkana: 0x309C,
  24146. semivoicedmarkkanahalfwidth: 0xFF9F,
  24147. sentisquare: 0x3322,
  24148. sentosquare: 0x3323,
  24149. seven: 0x0037,
  24150. sevenarabic: 0x0667,
  24151. sevenbengali: 0x09ED,
  24152. sevencircle: 0x2466,
  24153. sevencircleinversesansserif: 0x2790,
  24154. sevendeva: 0x096D,
  24155. seveneighths: 0x215E,
  24156. sevengujarati: 0x0AED,
  24157. sevengurmukhi: 0x0A6D,
  24158. sevenhackarabic: 0x0667,
  24159. sevenhangzhou: 0x3027,
  24160. sevenideographicparen: 0x3226,
  24161. seveninferior: 0x2087,
  24162. sevenmonospace: 0xFF17,
  24163. sevenoldstyle: 0xF737,
  24164. sevenparen: 0x247A,
  24165. sevenperiod: 0x248E,
  24166. sevenpersian: 0x06F7,
  24167. sevenroman: 0x2176,
  24168. sevensuperior: 0x2077,
  24169. seventeencircle: 0x2470,
  24170. seventeenparen: 0x2484,
  24171. seventeenperiod: 0x2498,
  24172. seventhai: 0x0E57,
  24173. sfthyphen: 0x00AD,
  24174. shaarmenian: 0x0577,
  24175. shabengali: 0x09B6,
  24176. shacyrillic: 0x0448,
  24177. shaddaarabic: 0x0651,
  24178. shaddadammaarabic: 0xFC61,
  24179. shaddadammatanarabic: 0xFC5E,
  24180. shaddafathaarabic: 0xFC60,
  24181. shaddakasraarabic: 0xFC62,
  24182. shaddakasratanarabic: 0xFC5F,
  24183. shade: 0x2592,
  24184. shadedark: 0x2593,
  24185. shadelight: 0x2591,
  24186. shademedium: 0x2592,
  24187. shadeva: 0x0936,
  24188. shagujarati: 0x0AB6,
  24189. shagurmukhi: 0x0A36,
  24190. shalshelethebrew: 0x0593,
  24191. shbopomofo: 0x3115,
  24192. shchacyrillic: 0x0449,
  24193. sheenarabic: 0x0634,
  24194. sheenfinalarabic: 0xFEB6,
  24195. sheeninitialarabic: 0xFEB7,
  24196. sheenmedialarabic: 0xFEB8,
  24197. sheicoptic: 0x03E3,
  24198. sheqel: 0x20AA,
  24199. sheqelhebrew: 0x20AA,
  24200. sheva: 0x05B0,
  24201. sheva115: 0x05B0,
  24202. sheva15: 0x05B0,
  24203. sheva22: 0x05B0,
  24204. sheva2e: 0x05B0,
  24205. shevahebrew: 0x05B0,
  24206. shevanarrowhebrew: 0x05B0,
  24207. shevaquarterhebrew: 0x05B0,
  24208. shevawidehebrew: 0x05B0,
  24209. shhacyrillic: 0x04BB,
  24210. shimacoptic: 0x03ED,
  24211. shin: 0x05E9,
  24212. shindagesh: 0xFB49,
  24213. shindageshhebrew: 0xFB49,
  24214. shindageshshindot: 0xFB2C,
  24215. shindageshshindothebrew: 0xFB2C,
  24216. shindageshsindot: 0xFB2D,
  24217. shindageshsindothebrew: 0xFB2D,
  24218. shindothebrew: 0x05C1,
  24219. shinhebrew: 0x05E9,
  24220. shinshindot: 0xFB2A,
  24221. shinshindothebrew: 0xFB2A,
  24222. shinsindot: 0xFB2B,
  24223. shinsindothebrew: 0xFB2B,
  24224. shook: 0x0282,
  24225. sigma: 0x03C3,
  24226. sigma1: 0x03C2,
  24227. sigmafinal: 0x03C2,
  24228. sigmalunatesymbolgreek: 0x03F2,
  24229. sihiragana: 0x3057,
  24230. sikatakana: 0x30B7,
  24231. sikatakanahalfwidth: 0xFF7C,
  24232. siluqhebrew: 0x05BD,
  24233. siluqlefthebrew: 0x05BD,
  24234. similar: 0x223C,
  24235. sindothebrew: 0x05C2,
  24236. siosacirclekorean: 0x3274,
  24237. siosaparenkorean: 0x3214,
  24238. sioscieuckorean: 0x317E,
  24239. sioscirclekorean: 0x3266,
  24240. sioskiyeokkorean: 0x317A,
  24241. sioskorean: 0x3145,
  24242. siosnieunkorean: 0x317B,
  24243. siosparenkorean: 0x3206,
  24244. siospieupkorean: 0x317D,
  24245. siostikeutkorean: 0x317C,
  24246. six: 0x0036,
  24247. sixarabic: 0x0666,
  24248. sixbengali: 0x09EC,
  24249. sixcircle: 0x2465,
  24250. sixcircleinversesansserif: 0x278F,
  24251. sixdeva: 0x096C,
  24252. sixgujarati: 0x0AEC,
  24253. sixgurmukhi: 0x0A6C,
  24254. sixhackarabic: 0x0666,
  24255. sixhangzhou: 0x3026,
  24256. sixideographicparen: 0x3225,
  24257. sixinferior: 0x2086,
  24258. sixmonospace: 0xFF16,
  24259. sixoldstyle: 0xF736,
  24260. sixparen: 0x2479,
  24261. sixperiod: 0x248D,
  24262. sixpersian: 0x06F6,
  24263. sixroman: 0x2175,
  24264. sixsuperior: 0x2076,
  24265. sixteencircle: 0x246F,
  24266. sixteencurrencydenominatorbengali: 0x09F9,
  24267. sixteenparen: 0x2483,
  24268. sixteenperiod: 0x2497,
  24269. sixthai: 0x0E56,
  24270. slash: 0x002F,
  24271. slashmonospace: 0xFF0F,
  24272. slong: 0x017F,
  24273. slongdotaccent: 0x1E9B,
  24274. smileface: 0x263A,
  24275. smonospace: 0xFF53,
  24276. sofpasuqhebrew: 0x05C3,
  24277. softhyphen: 0x00AD,
  24278. softsigncyrillic: 0x044C,
  24279. sohiragana: 0x305D,
  24280. sokatakana: 0x30BD,
  24281. sokatakanahalfwidth: 0xFF7F,
  24282. soliduslongoverlaycmb: 0x0338,
  24283. solidusshortoverlaycmb: 0x0337,
  24284. sorusithai: 0x0E29,
  24285. sosalathai: 0x0E28,
  24286. sosothai: 0x0E0B,
  24287. sosuathai: 0x0E2A,
  24288. space: 0x0020,
  24289. spacehackarabic: 0x0020,
  24290. spade: 0x2660,
  24291. spadesuitblack: 0x2660,
  24292. spadesuitwhite: 0x2664,
  24293. sparen: 0x24AE,
  24294. squarebelowcmb: 0x033B,
  24295. squarecc: 0x33C4,
  24296. squarecm: 0x339D,
  24297. squarediagonalcrosshatchfill: 0x25A9,
  24298. squarehorizontalfill: 0x25A4,
  24299. squarekg: 0x338F,
  24300. squarekm: 0x339E,
  24301. squarekmcapital: 0x33CE,
  24302. squareln: 0x33D1,
  24303. squarelog: 0x33D2,
  24304. squaremg: 0x338E,
  24305. squaremil: 0x33D5,
  24306. squaremm: 0x339C,
  24307. squaremsquared: 0x33A1,
  24308. squareorthogonalcrosshatchfill: 0x25A6,
  24309. squareupperlefttolowerrightfill: 0x25A7,
  24310. squareupperrighttolowerleftfill: 0x25A8,
  24311. squareverticalfill: 0x25A5,
  24312. squarewhitewithsmallblack: 0x25A3,
  24313. srsquare: 0x33DB,
  24314. ssabengali: 0x09B7,
  24315. ssadeva: 0x0937,
  24316. ssagujarati: 0x0AB7,
  24317. ssangcieuckorean: 0x3149,
  24318. ssanghieuhkorean: 0x3185,
  24319. ssangieungkorean: 0x3180,
  24320. ssangkiyeokkorean: 0x3132,
  24321. ssangnieunkorean: 0x3165,
  24322. ssangpieupkorean: 0x3143,
  24323. ssangsioskorean: 0x3146,
  24324. ssangtikeutkorean: 0x3138,
  24325. ssuperior: 0xF6F2,
  24326. sterling: 0x00A3,
  24327. sterlingmonospace: 0xFFE1,
  24328. strokelongoverlaycmb: 0x0336,
  24329. strokeshortoverlaycmb: 0x0335,
  24330. subset: 0x2282,
  24331. subsetnotequal: 0x228A,
  24332. subsetorequal: 0x2286,
  24333. succeeds: 0x227B,
  24334. suchthat: 0x220B,
  24335. suhiragana: 0x3059,
  24336. sukatakana: 0x30B9,
  24337. sukatakanahalfwidth: 0xFF7D,
  24338. sukunarabic: 0x0652,
  24339. summation: 0x2211,
  24340. sun: 0x263C,
  24341. superset: 0x2283,
  24342. supersetnotequal: 0x228B,
  24343. supersetorequal: 0x2287,
  24344. svsquare: 0x33DC,
  24345. syouwaerasquare: 0x337C,
  24346. t: 0x0074,
  24347. tabengali: 0x09A4,
  24348. tackdown: 0x22A4,
  24349. tackleft: 0x22A3,
  24350. tadeva: 0x0924,
  24351. tagujarati: 0x0AA4,
  24352. tagurmukhi: 0x0A24,
  24353. taharabic: 0x0637,
  24354. tahfinalarabic: 0xFEC2,
  24355. tahinitialarabic: 0xFEC3,
  24356. tahiragana: 0x305F,
  24357. tahmedialarabic: 0xFEC4,
  24358. taisyouerasquare: 0x337D,
  24359. takatakana: 0x30BF,
  24360. takatakanahalfwidth: 0xFF80,
  24361. tatweelarabic: 0x0640,
  24362. tau: 0x03C4,
  24363. tav: 0x05EA,
  24364. tavdages: 0xFB4A,
  24365. tavdagesh: 0xFB4A,
  24366. tavdageshhebrew: 0xFB4A,
  24367. tavhebrew: 0x05EA,
  24368. tbar: 0x0167,
  24369. tbopomofo: 0x310A,
  24370. tcaron: 0x0165,
  24371. tccurl: 0x02A8,
  24372. tcedilla: 0x0163,
  24373. tcheharabic: 0x0686,
  24374. tchehfinalarabic: 0xFB7B,
  24375. tchehinitialarabic: 0xFB7C,
  24376. tchehmedialarabic: 0xFB7D,
  24377. tcircle: 0x24E3,
  24378. tcircumflexbelow: 0x1E71,
  24379. tcommaaccent: 0x0163,
  24380. tdieresis: 0x1E97,
  24381. tdotaccent: 0x1E6B,
  24382. tdotbelow: 0x1E6D,
  24383. tecyrillic: 0x0442,
  24384. tedescendercyrillic: 0x04AD,
  24385. teharabic: 0x062A,
  24386. tehfinalarabic: 0xFE96,
  24387. tehhahinitialarabic: 0xFCA2,
  24388. tehhahisolatedarabic: 0xFC0C,
  24389. tehinitialarabic: 0xFE97,
  24390. tehiragana: 0x3066,
  24391. tehjeeminitialarabic: 0xFCA1,
  24392. tehjeemisolatedarabic: 0xFC0B,
  24393. tehmarbutaarabic: 0x0629,
  24394. tehmarbutafinalarabic: 0xFE94,
  24395. tehmedialarabic: 0xFE98,
  24396. tehmeeminitialarabic: 0xFCA4,
  24397. tehmeemisolatedarabic: 0xFC0E,
  24398. tehnoonfinalarabic: 0xFC73,
  24399. tekatakana: 0x30C6,
  24400. tekatakanahalfwidth: 0xFF83,
  24401. telephone: 0x2121,
  24402. telephoneblack: 0x260E,
  24403. telishagedolahebrew: 0x05A0,
  24404. telishaqetanahebrew: 0x05A9,
  24405. tencircle: 0x2469,
  24406. tenideographicparen: 0x3229,
  24407. tenparen: 0x247D,
  24408. tenperiod: 0x2491,
  24409. tenroman: 0x2179,
  24410. tesh: 0x02A7,
  24411. tet: 0x05D8,
  24412. tetdagesh: 0xFB38,
  24413. tetdageshhebrew: 0xFB38,
  24414. tethebrew: 0x05D8,
  24415. tetsecyrillic: 0x04B5,
  24416. tevirhebrew: 0x059B,
  24417. tevirlefthebrew: 0x059B,
  24418. thabengali: 0x09A5,
  24419. thadeva: 0x0925,
  24420. thagujarati: 0x0AA5,
  24421. thagurmukhi: 0x0A25,
  24422. thalarabic: 0x0630,
  24423. thalfinalarabic: 0xFEAC,
  24424. thanthakhatlowleftthai: 0xF898,
  24425. thanthakhatlowrightthai: 0xF897,
  24426. thanthakhatthai: 0x0E4C,
  24427. thanthakhatupperleftthai: 0xF896,
  24428. theharabic: 0x062B,
  24429. thehfinalarabic: 0xFE9A,
  24430. thehinitialarabic: 0xFE9B,
  24431. thehmedialarabic: 0xFE9C,
  24432. thereexists: 0x2203,
  24433. therefore: 0x2234,
  24434. theta: 0x03B8,
  24435. theta1: 0x03D1,
  24436. thetasymbolgreek: 0x03D1,
  24437. thieuthacirclekorean: 0x3279,
  24438. thieuthaparenkorean: 0x3219,
  24439. thieuthcirclekorean: 0x326B,
  24440. thieuthkorean: 0x314C,
  24441. thieuthparenkorean: 0x320B,
  24442. thirteencircle: 0x246C,
  24443. thirteenparen: 0x2480,
  24444. thirteenperiod: 0x2494,
  24445. thonangmonthothai: 0x0E11,
  24446. thook: 0x01AD,
  24447. thophuthaothai: 0x0E12,
  24448. thorn: 0x00FE,
  24449. thothahanthai: 0x0E17,
  24450. thothanthai: 0x0E10,
  24451. thothongthai: 0x0E18,
  24452. thothungthai: 0x0E16,
  24453. thousandcyrillic: 0x0482,
  24454. thousandsseparatorarabic: 0x066C,
  24455. thousandsseparatorpersian: 0x066C,
  24456. three: 0x0033,
  24457. threearabic: 0x0663,
  24458. threebengali: 0x09E9,
  24459. threecircle: 0x2462,
  24460. threecircleinversesansserif: 0x278C,
  24461. threedeva: 0x0969,
  24462. threeeighths: 0x215C,
  24463. threegujarati: 0x0AE9,
  24464. threegurmukhi: 0x0A69,
  24465. threehackarabic: 0x0663,
  24466. threehangzhou: 0x3023,
  24467. threeideographicparen: 0x3222,
  24468. threeinferior: 0x2083,
  24469. threemonospace: 0xFF13,
  24470. threenumeratorbengali: 0x09F6,
  24471. threeoldstyle: 0xF733,
  24472. threeparen: 0x2476,
  24473. threeperiod: 0x248A,
  24474. threepersian: 0x06F3,
  24475. threequarters: 0x00BE,
  24476. threequartersemdash: 0xF6DE,
  24477. threeroman: 0x2172,
  24478. threesuperior: 0x00B3,
  24479. threethai: 0x0E53,
  24480. thzsquare: 0x3394,
  24481. tihiragana: 0x3061,
  24482. tikatakana: 0x30C1,
  24483. tikatakanahalfwidth: 0xFF81,
  24484. tikeutacirclekorean: 0x3270,
  24485. tikeutaparenkorean: 0x3210,
  24486. tikeutcirclekorean: 0x3262,
  24487. tikeutkorean: 0x3137,
  24488. tikeutparenkorean: 0x3202,
  24489. tilde: 0x02DC,
  24490. tildebelowcmb: 0x0330,
  24491. tildecmb: 0x0303,
  24492. tildecomb: 0x0303,
  24493. tildedoublecmb: 0x0360,
  24494. tildeoperator: 0x223C,
  24495. tildeoverlaycmb: 0x0334,
  24496. tildeverticalcmb: 0x033E,
  24497. timescircle: 0x2297,
  24498. tipehahebrew: 0x0596,
  24499. tipehalefthebrew: 0x0596,
  24500. tippigurmukhi: 0x0A70,
  24501. titlocyrilliccmb: 0x0483,
  24502. tiwnarmenian: 0x057F,
  24503. tlinebelow: 0x1E6F,
  24504. tmonospace: 0xFF54,
  24505. toarmenian: 0x0569,
  24506. tohiragana: 0x3068,
  24507. tokatakana: 0x30C8,
  24508. tokatakanahalfwidth: 0xFF84,
  24509. tonebarextrahighmod: 0x02E5,
  24510. tonebarextralowmod: 0x02E9,
  24511. tonebarhighmod: 0x02E6,
  24512. tonebarlowmod: 0x02E8,
  24513. tonebarmidmod: 0x02E7,
  24514. tonefive: 0x01BD,
  24515. tonesix: 0x0185,
  24516. tonetwo: 0x01A8,
  24517. tonos: 0x0384,
  24518. tonsquare: 0x3327,
  24519. topatakthai: 0x0E0F,
  24520. tortoiseshellbracketleft: 0x3014,
  24521. tortoiseshellbracketleftsmall: 0xFE5D,
  24522. tortoiseshellbracketleftvertical: 0xFE39,
  24523. tortoiseshellbracketright: 0x3015,
  24524. tortoiseshellbracketrightsmall: 0xFE5E,
  24525. tortoiseshellbracketrightvertical: 0xFE3A,
  24526. totaothai: 0x0E15,
  24527. tpalatalhook: 0x01AB,
  24528. tparen: 0x24AF,
  24529. trademark: 0x2122,
  24530. trademarksans: 0xF8EA,
  24531. trademarkserif: 0xF6DB,
  24532. tretroflexhook: 0x0288,
  24533. triagdn: 0x25BC,
  24534. triaglf: 0x25C4,
  24535. triagrt: 0x25BA,
  24536. triagup: 0x25B2,
  24537. ts: 0x02A6,
  24538. tsadi: 0x05E6,
  24539. tsadidagesh: 0xFB46,
  24540. tsadidageshhebrew: 0xFB46,
  24541. tsadihebrew: 0x05E6,
  24542. tsecyrillic: 0x0446,
  24543. tsere: 0x05B5,
  24544. tsere12: 0x05B5,
  24545. tsere1e: 0x05B5,
  24546. tsere2b: 0x05B5,
  24547. tserehebrew: 0x05B5,
  24548. tserenarrowhebrew: 0x05B5,
  24549. tserequarterhebrew: 0x05B5,
  24550. tserewidehebrew: 0x05B5,
  24551. tshecyrillic: 0x045B,
  24552. tsuperior: 0xF6F3,
  24553. ttabengali: 0x099F,
  24554. ttadeva: 0x091F,
  24555. ttagujarati: 0x0A9F,
  24556. ttagurmukhi: 0x0A1F,
  24557. tteharabic: 0x0679,
  24558. ttehfinalarabic: 0xFB67,
  24559. ttehinitialarabic: 0xFB68,
  24560. ttehmedialarabic: 0xFB69,
  24561. tthabengali: 0x09A0,
  24562. tthadeva: 0x0920,
  24563. tthagujarati: 0x0AA0,
  24564. tthagurmukhi: 0x0A20,
  24565. tturned: 0x0287,
  24566. tuhiragana: 0x3064,
  24567. tukatakana: 0x30C4,
  24568. tukatakanahalfwidth: 0xFF82,
  24569. tusmallhiragana: 0x3063,
  24570. tusmallkatakana: 0x30C3,
  24571. tusmallkatakanahalfwidth: 0xFF6F,
  24572. twelvecircle: 0x246B,
  24573. twelveparen: 0x247F,
  24574. twelveperiod: 0x2493,
  24575. twelveroman: 0x217B,
  24576. twentycircle: 0x2473,
  24577. twentyhangzhou: 0x5344,
  24578. twentyparen: 0x2487,
  24579. twentyperiod: 0x249B,
  24580. two: 0x0032,
  24581. twoarabic: 0x0662,
  24582. twobengali: 0x09E8,
  24583. twocircle: 0x2461,
  24584. twocircleinversesansserif: 0x278B,
  24585. twodeva: 0x0968,
  24586. twodotenleader: 0x2025,
  24587. twodotleader: 0x2025,
  24588. twodotleadervertical: 0xFE30,
  24589. twogujarati: 0x0AE8,
  24590. twogurmukhi: 0x0A68,
  24591. twohackarabic: 0x0662,
  24592. twohangzhou: 0x3022,
  24593. twoideographicparen: 0x3221,
  24594. twoinferior: 0x2082,
  24595. twomonospace: 0xFF12,
  24596. twonumeratorbengali: 0x09F5,
  24597. twooldstyle: 0xF732,
  24598. twoparen: 0x2475,
  24599. twoperiod: 0x2489,
  24600. twopersian: 0x06F2,
  24601. tworoman: 0x2171,
  24602. twostroke: 0x01BB,
  24603. twosuperior: 0x00B2,
  24604. twothai: 0x0E52,
  24605. twothirds: 0x2154,
  24606. u: 0x0075,
  24607. uacute: 0x00FA,
  24608. ubar: 0x0289,
  24609. ubengali: 0x0989,
  24610. ubopomofo: 0x3128,
  24611. ubreve: 0x016D,
  24612. ucaron: 0x01D4,
  24613. ucircle: 0x24E4,
  24614. ucircumflex: 0x00FB,
  24615. ucircumflexbelow: 0x1E77,
  24616. ucyrillic: 0x0443,
  24617. udattadeva: 0x0951,
  24618. udblacute: 0x0171,
  24619. udblgrave: 0x0215,
  24620. udeva: 0x0909,
  24621. udieresis: 0x00FC,
  24622. udieresisacute: 0x01D8,
  24623. udieresisbelow: 0x1E73,
  24624. udieresiscaron: 0x01DA,
  24625. udieresiscyrillic: 0x04F1,
  24626. udieresisgrave: 0x01DC,
  24627. udieresismacron: 0x01D6,
  24628. udotbelow: 0x1EE5,
  24629. ugrave: 0x00F9,
  24630. ugujarati: 0x0A89,
  24631. ugurmukhi: 0x0A09,
  24632. uhiragana: 0x3046,
  24633. uhookabove: 0x1EE7,
  24634. uhorn: 0x01B0,
  24635. uhornacute: 0x1EE9,
  24636. uhorndotbelow: 0x1EF1,
  24637. uhorngrave: 0x1EEB,
  24638. uhornhookabove: 0x1EED,
  24639. uhorntilde: 0x1EEF,
  24640. uhungarumlaut: 0x0171,
  24641. uhungarumlautcyrillic: 0x04F3,
  24642. uinvertedbreve: 0x0217,
  24643. ukatakana: 0x30A6,
  24644. ukatakanahalfwidth: 0xFF73,
  24645. ukcyrillic: 0x0479,
  24646. ukorean: 0x315C,
  24647. umacron: 0x016B,
  24648. umacroncyrillic: 0x04EF,
  24649. umacrondieresis: 0x1E7B,
  24650. umatragurmukhi: 0x0A41,
  24651. umonospace: 0xFF55,
  24652. underscore: 0x005F,
  24653. underscoredbl: 0x2017,
  24654. underscoremonospace: 0xFF3F,
  24655. underscorevertical: 0xFE33,
  24656. underscorewavy: 0xFE4F,
  24657. union: 0x222A,
  24658. universal: 0x2200,
  24659. uogonek: 0x0173,
  24660. uparen: 0x24B0,
  24661. upblock: 0x2580,
  24662. upperdothebrew: 0x05C4,
  24663. upsilon: 0x03C5,
  24664. upsilondieresis: 0x03CB,
  24665. upsilondieresistonos: 0x03B0,
  24666. upsilonlatin: 0x028A,
  24667. upsilontonos: 0x03CD,
  24668. uptackbelowcmb: 0x031D,
  24669. uptackmod: 0x02D4,
  24670. uragurmukhi: 0x0A73,
  24671. uring: 0x016F,
  24672. ushortcyrillic: 0x045E,
  24673. usmallhiragana: 0x3045,
  24674. usmallkatakana: 0x30A5,
  24675. usmallkatakanahalfwidth: 0xFF69,
  24676. ustraightcyrillic: 0x04AF,
  24677. ustraightstrokecyrillic: 0x04B1,
  24678. utilde: 0x0169,
  24679. utildeacute: 0x1E79,
  24680. utildebelow: 0x1E75,
  24681. uubengali: 0x098A,
  24682. uudeva: 0x090A,
  24683. uugujarati: 0x0A8A,
  24684. uugurmukhi: 0x0A0A,
  24685. uumatragurmukhi: 0x0A42,
  24686. uuvowelsignbengali: 0x09C2,
  24687. uuvowelsigndeva: 0x0942,
  24688. uuvowelsigngujarati: 0x0AC2,
  24689. uvowelsignbengali: 0x09C1,
  24690. uvowelsigndeva: 0x0941,
  24691. uvowelsigngujarati: 0x0AC1,
  24692. v: 0x0076,
  24693. vadeva: 0x0935,
  24694. vagujarati: 0x0AB5,
  24695. vagurmukhi: 0x0A35,
  24696. vakatakana: 0x30F7,
  24697. vav: 0x05D5,
  24698. vavdagesh: 0xFB35,
  24699. vavdagesh65: 0xFB35,
  24700. vavdageshhebrew: 0xFB35,
  24701. vavhebrew: 0x05D5,
  24702. vavholam: 0xFB4B,
  24703. vavholamhebrew: 0xFB4B,
  24704. vavvavhebrew: 0x05F0,
  24705. vavyodhebrew: 0x05F1,
  24706. vcircle: 0x24E5,
  24707. vdotbelow: 0x1E7F,
  24708. vecyrillic: 0x0432,
  24709. veharabic: 0x06A4,
  24710. vehfinalarabic: 0xFB6B,
  24711. vehinitialarabic: 0xFB6C,
  24712. vehmedialarabic: 0xFB6D,
  24713. vekatakana: 0x30F9,
  24714. venus: 0x2640,
  24715. verticalbar: 0x007C,
  24716. verticallineabovecmb: 0x030D,
  24717. verticallinebelowcmb: 0x0329,
  24718. verticallinelowmod: 0x02CC,
  24719. verticallinemod: 0x02C8,
  24720. vewarmenian: 0x057E,
  24721. vhook: 0x028B,
  24722. vikatakana: 0x30F8,
  24723. viramabengali: 0x09CD,
  24724. viramadeva: 0x094D,
  24725. viramagujarati: 0x0ACD,
  24726. visargabengali: 0x0983,
  24727. visargadeva: 0x0903,
  24728. visargagujarati: 0x0A83,
  24729. vmonospace: 0xFF56,
  24730. voarmenian: 0x0578,
  24731. voicediterationhiragana: 0x309E,
  24732. voicediterationkatakana: 0x30FE,
  24733. voicedmarkkana: 0x309B,
  24734. voicedmarkkanahalfwidth: 0xFF9E,
  24735. vokatakana: 0x30FA,
  24736. vparen: 0x24B1,
  24737. vtilde: 0x1E7D,
  24738. vturned: 0x028C,
  24739. vuhiragana: 0x3094,
  24740. vukatakana: 0x30F4,
  24741. w: 0x0077,
  24742. wacute: 0x1E83,
  24743. waekorean: 0x3159,
  24744. wahiragana: 0x308F,
  24745. wakatakana: 0x30EF,
  24746. wakatakanahalfwidth: 0xFF9C,
  24747. wakorean: 0x3158,
  24748. wasmallhiragana: 0x308E,
  24749. wasmallkatakana: 0x30EE,
  24750. wattosquare: 0x3357,
  24751. wavedash: 0x301C,
  24752. wavyunderscorevertical: 0xFE34,
  24753. wawarabic: 0x0648,
  24754. wawfinalarabic: 0xFEEE,
  24755. wawhamzaabovearabic: 0x0624,
  24756. wawhamzaabovefinalarabic: 0xFE86,
  24757. wbsquare: 0x33DD,
  24758. wcircle: 0x24E6,
  24759. wcircumflex: 0x0175,
  24760. wdieresis: 0x1E85,
  24761. wdotaccent: 0x1E87,
  24762. wdotbelow: 0x1E89,
  24763. wehiragana: 0x3091,
  24764. weierstrass: 0x2118,
  24765. wekatakana: 0x30F1,
  24766. wekorean: 0x315E,
  24767. weokorean: 0x315D,
  24768. wgrave: 0x1E81,
  24769. whitebullet: 0x25E6,
  24770. whitecircle: 0x25CB,
  24771. whitecircleinverse: 0x25D9,
  24772. whitecornerbracketleft: 0x300E,
  24773. whitecornerbracketleftvertical: 0xFE43,
  24774. whitecornerbracketright: 0x300F,
  24775. whitecornerbracketrightvertical: 0xFE44,
  24776. whitediamond: 0x25C7,
  24777. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24778. whitedownpointingsmalltriangle: 0x25BF,
  24779. whitedownpointingtriangle: 0x25BD,
  24780. whiteleftpointingsmalltriangle: 0x25C3,
  24781. whiteleftpointingtriangle: 0x25C1,
  24782. whitelenticularbracketleft: 0x3016,
  24783. whitelenticularbracketright: 0x3017,
  24784. whiterightpointingsmalltriangle: 0x25B9,
  24785. whiterightpointingtriangle: 0x25B7,
  24786. whitesmallsquare: 0x25AB,
  24787. whitesmilingface: 0x263A,
  24788. whitesquare: 0x25A1,
  24789. whitestar: 0x2606,
  24790. whitetelephone: 0x260F,
  24791. whitetortoiseshellbracketleft: 0x3018,
  24792. whitetortoiseshellbracketright: 0x3019,
  24793. whiteuppointingsmalltriangle: 0x25B5,
  24794. whiteuppointingtriangle: 0x25B3,
  24795. wihiragana: 0x3090,
  24796. wikatakana: 0x30F0,
  24797. wikorean: 0x315F,
  24798. wmonospace: 0xFF57,
  24799. wohiragana: 0x3092,
  24800. wokatakana: 0x30F2,
  24801. wokatakanahalfwidth: 0xFF66,
  24802. won: 0x20A9,
  24803. wonmonospace: 0xFFE6,
  24804. wowaenthai: 0x0E27,
  24805. wparen: 0x24B2,
  24806. wring: 0x1E98,
  24807. wsuperior: 0x02B7,
  24808. wturned: 0x028D,
  24809. wynn: 0x01BF,
  24810. x: 0x0078,
  24811. xabovecmb: 0x033D,
  24812. xbopomofo: 0x3112,
  24813. xcircle: 0x24E7,
  24814. xdieresis: 0x1E8D,
  24815. xdotaccent: 0x1E8B,
  24816. xeharmenian: 0x056D,
  24817. xi: 0x03BE,
  24818. xmonospace: 0xFF58,
  24819. xparen: 0x24B3,
  24820. xsuperior: 0x02E3,
  24821. y: 0x0079,
  24822. yaadosquare: 0x334E,
  24823. yabengali: 0x09AF,
  24824. yacute: 0x00FD,
  24825. yadeva: 0x092F,
  24826. yaekorean: 0x3152,
  24827. yagujarati: 0x0AAF,
  24828. yagurmukhi: 0x0A2F,
  24829. yahiragana: 0x3084,
  24830. yakatakana: 0x30E4,
  24831. yakatakanahalfwidth: 0xFF94,
  24832. yakorean: 0x3151,
  24833. yamakkanthai: 0x0E4E,
  24834. yasmallhiragana: 0x3083,
  24835. yasmallkatakana: 0x30E3,
  24836. yasmallkatakanahalfwidth: 0xFF6C,
  24837. yatcyrillic: 0x0463,
  24838. ycircle: 0x24E8,
  24839. ycircumflex: 0x0177,
  24840. ydieresis: 0x00FF,
  24841. ydotaccent: 0x1E8F,
  24842. ydotbelow: 0x1EF5,
  24843. yeharabic: 0x064A,
  24844. yehbarreearabic: 0x06D2,
  24845. yehbarreefinalarabic: 0xFBAF,
  24846. yehfinalarabic: 0xFEF2,
  24847. yehhamzaabovearabic: 0x0626,
  24848. yehhamzaabovefinalarabic: 0xFE8A,
  24849. yehhamzaaboveinitialarabic: 0xFE8B,
  24850. yehhamzaabovemedialarabic: 0xFE8C,
  24851. yehinitialarabic: 0xFEF3,
  24852. yehmedialarabic: 0xFEF4,
  24853. yehmeeminitialarabic: 0xFCDD,
  24854. yehmeemisolatedarabic: 0xFC58,
  24855. yehnoonfinalarabic: 0xFC94,
  24856. yehthreedotsbelowarabic: 0x06D1,
  24857. yekorean: 0x3156,
  24858. yen: 0x00A5,
  24859. yenmonospace: 0xFFE5,
  24860. yeokorean: 0x3155,
  24861. yeorinhieuhkorean: 0x3186,
  24862. yerahbenyomohebrew: 0x05AA,
  24863. yerahbenyomolefthebrew: 0x05AA,
  24864. yericyrillic: 0x044B,
  24865. yerudieresiscyrillic: 0x04F9,
  24866. yesieungkorean: 0x3181,
  24867. yesieungpansioskorean: 0x3183,
  24868. yesieungsioskorean: 0x3182,
  24869. yetivhebrew: 0x059A,
  24870. ygrave: 0x1EF3,
  24871. yhook: 0x01B4,
  24872. yhookabove: 0x1EF7,
  24873. yiarmenian: 0x0575,
  24874. yicyrillic: 0x0457,
  24875. yikorean: 0x3162,
  24876. yinyang: 0x262F,
  24877. yiwnarmenian: 0x0582,
  24878. ymonospace: 0xFF59,
  24879. yod: 0x05D9,
  24880. yoddagesh: 0xFB39,
  24881. yoddageshhebrew: 0xFB39,
  24882. yodhebrew: 0x05D9,
  24883. yodyodhebrew: 0x05F2,
  24884. yodyodpatahhebrew: 0xFB1F,
  24885. yohiragana: 0x3088,
  24886. yoikorean: 0x3189,
  24887. yokatakana: 0x30E8,
  24888. yokatakanahalfwidth: 0xFF96,
  24889. yokorean: 0x315B,
  24890. yosmallhiragana: 0x3087,
  24891. yosmallkatakana: 0x30E7,
  24892. yosmallkatakanahalfwidth: 0xFF6E,
  24893. yotgreek: 0x03F3,
  24894. yoyaekorean: 0x3188,
  24895. yoyakorean: 0x3187,
  24896. yoyakthai: 0x0E22,
  24897. yoyingthai: 0x0E0D,
  24898. yparen: 0x24B4,
  24899. ypogegrammeni: 0x037A,
  24900. ypogegrammenigreekcmb: 0x0345,
  24901. yr: 0x01A6,
  24902. yring: 0x1E99,
  24903. ysuperior: 0x02B8,
  24904. ytilde: 0x1EF9,
  24905. yturned: 0x028E,
  24906. yuhiragana: 0x3086,
  24907. yuikorean: 0x318C,
  24908. yukatakana: 0x30E6,
  24909. yukatakanahalfwidth: 0xFF95,
  24910. yukorean: 0x3160,
  24911. yusbigcyrillic: 0x046B,
  24912. yusbigiotifiedcyrillic: 0x046D,
  24913. yuslittlecyrillic: 0x0467,
  24914. yuslittleiotifiedcyrillic: 0x0469,
  24915. yusmallhiragana: 0x3085,
  24916. yusmallkatakana: 0x30E5,
  24917. yusmallkatakanahalfwidth: 0xFF6D,
  24918. yuyekorean: 0x318B,
  24919. yuyeokorean: 0x318A,
  24920. yyabengali: 0x09DF,
  24921. yyadeva: 0x095F,
  24922. z: 0x007A,
  24923. zaarmenian: 0x0566,
  24924. zacute: 0x017A,
  24925. zadeva: 0x095B,
  24926. zagurmukhi: 0x0A5B,
  24927. zaharabic: 0x0638,
  24928. zahfinalarabic: 0xFEC6,
  24929. zahinitialarabic: 0xFEC7,
  24930. zahiragana: 0x3056,
  24931. zahmedialarabic: 0xFEC8,
  24932. zainarabic: 0x0632,
  24933. zainfinalarabic: 0xFEB0,
  24934. zakatakana: 0x30B6,
  24935. zaqefgadolhebrew: 0x0595,
  24936. zaqefqatanhebrew: 0x0594,
  24937. zarqahebrew: 0x0598,
  24938. zayin: 0x05D6,
  24939. zayindagesh: 0xFB36,
  24940. zayindageshhebrew: 0xFB36,
  24941. zayinhebrew: 0x05D6,
  24942. zbopomofo: 0x3117,
  24943. zcaron: 0x017E,
  24944. zcircle: 0x24E9,
  24945. zcircumflex: 0x1E91,
  24946. zcurl: 0x0291,
  24947. zdot: 0x017C,
  24948. zdotaccent: 0x017C,
  24949. zdotbelow: 0x1E93,
  24950. zecyrillic: 0x0437,
  24951. zedescendercyrillic: 0x0499,
  24952. zedieresiscyrillic: 0x04DF,
  24953. zehiragana: 0x305C,
  24954. zekatakana: 0x30BC,
  24955. zero: 0x0030,
  24956. zeroarabic: 0x0660,
  24957. zerobengali: 0x09E6,
  24958. zerodeva: 0x0966,
  24959. zerogujarati: 0x0AE6,
  24960. zerogurmukhi: 0x0A66,
  24961. zerohackarabic: 0x0660,
  24962. zeroinferior: 0x2080,
  24963. zeromonospace: 0xFF10,
  24964. zerooldstyle: 0xF730,
  24965. zeropersian: 0x06F0,
  24966. zerosuperior: 0x2070,
  24967. zerothai: 0x0E50,
  24968. zerowidthjoiner: 0xFEFF,
  24969. zerowidthnonjoiner: 0x200C,
  24970. zerowidthspace: 0x200B,
  24971. zeta: 0x03B6,
  24972. zhbopomofo: 0x3113,
  24973. zhearmenian: 0x056A,
  24974. zhebrevecyrillic: 0x04C2,
  24975. zhecyrillic: 0x0436,
  24976. zhedescendercyrillic: 0x0497,
  24977. zhedieresiscyrillic: 0x04DD,
  24978. zihiragana: 0x3058,
  24979. zikatakana: 0x30B8,
  24980. zinorhebrew: 0x05AE,
  24981. zlinebelow: 0x1E95,
  24982. zmonospace: 0xFF5A,
  24983. zohiragana: 0x305E,
  24984. zokatakana: 0x30BE,
  24985. zparen: 0x24B5,
  24986. zretroflexhook: 0x0290,
  24987. zstroke: 0x01B6,
  24988. zuhiragana: 0x305A,
  24989. zukatakana: 0x30BA,
  24990. '.notdef': 0x0000
  24991. };
  24992. var DingbatsGlyphsUnicode = {
  24993. space: 0x0020,
  24994. a1: 0x2701,
  24995. a2: 0x2702,
  24996. a202: 0x2703,
  24997. a3: 0x2704,
  24998. a4: 0x260E,
  24999. a5: 0x2706,
  25000. a119: 0x2707,
  25001. a118: 0x2708,
  25002. a117: 0x2709,
  25003. a11: 0x261B,
  25004. a12: 0x261E,
  25005. a13: 0x270C,
  25006. a14: 0x270D,
  25007. a15: 0x270E,
  25008. a16: 0x270F,
  25009. a105: 0x2710,
  25010. a17: 0x2711,
  25011. a18: 0x2712,
  25012. a19: 0x2713,
  25013. a20: 0x2714,
  25014. a21: 0x2715,
  25015. a22: 0x2716,
  25016. a23: 0x2717,
  25017. a24: 0x2718,
  25018. a25: 0x2719,
  25019. a26: 0x271A,
  25020. a27: 0x271B,
  25021. a28: 0x271C,
  25022. a6: 0x271D,
  25023. a7: 0x271E,
  25024. a8: 0x271F,
  25025. a9: 0x2720,
  25026. a10: 0x2721,
  25027. a29: 0x2722,
  25028. a30: 0x2723,
  25029. a31: 0x2724,
  25030. a32: 0x2725,
  25031. a33: 0x2726,
  25032. a34: 0x2727,
  25033. a35: 0x2605,
  25034. a36: 0x2729,
  25035. a37: 0x272A,
  25036. a38: 0x272B,
  25037. a39: 0x272C,
  25038. a40: 0x272D,
  25039. a41: 0x272E,
  25040. a42: 0x272F,
  25041. a43: 0x2730,
  25042. a44: 0x2731,
  25043. a45: 0x2732,
  25044. a46: 0x2733,
  25045. a47: 0x2734,
  25046. a48: 0x2735,
  25047. a49: 0x2736,
  25048. a50: 0x2737,
  25049. a51: 0x2738,
  25050. a52: 0x2739,
  25051. a53: 0x273A,
  25052. a54: 0x273B,
  25053. a55: 0x273C,
  25054. a56: 0x273D,
  25055. a57: 0x273E,
  25056. a58: 0x273F,
  25057. a59: 0x2740,
  25058. a60: 0x2741,
  25059. a61: 0x2742,
  25060. a62: 0x2743,
  25061. a63: 0x2744,
  25062. a64: 0x2745,
  25063. a65: 0x2746,
  25064. a66: 0x2747,
  25065. a67: 0x2748,
  25066. a68: 0x2749,
  25067. a69: 0x274A,
  25068. a70: 0x274B,
  25069. a71: 0x25CF,
  25070. a72: 0x274D,
  25071. a73: 0x25A0,
  25072. a74: 0x274F,
  25073. a203: 0x2750,
  25074. a75: 0x2751,
  25075. a204: 0x2752,
  25076. a76: 0x25B2,
  25077. a77: 0x25BC,
  25078. a78: 0x25C6,
  25079. a79: 0x2756,
  25080. a81: 0x25D7,
  25081. a82: 0x2758,
  25082. a83: 0x2759,
  25083. a84: 0x275A,
  25084. a97: 0x275B,
  25085. a98: 0x275C,
  25086. a99: 0x275D,
  25087. a100: 0x275E,
  25088. a101: 0x2761,
  25089. a102: 0x2762,
  25090. a103: 0x2763,
  25091. a104: 0x2764,
  25092. a106: 0x2765,
  25093. a107: 0x2766,
  25094. a108: 0x2767,
  25095. a112: 0x2663,
  25096. a111: 0x2666,
  25097. a110: 0x2665,
  25098. a109: 0x2660,
  25099. a120: 0x2460,
  25100. a121: 0x2461,
  25101. a122: 0x2462,
  25102. a123: 0x2463,
  25103. a124: 0x2464,
  25104. a125: 0x2465,
  25105. a126: 0x2466,
  25106. a127: 0x2467,
  25107. a128: 0x2468,
  25108. a129: 0x2469,
  25109. a130: 0x2776,
  25110. a131: 0x2777,
  25111. a132: 0x2778,
  25112. a133: 0x2779,
  25113. a134: 0x277A,
  25114. a135: 0x277B,
  25115. a136: 0x277C,
  25116. a137: 0x277D,
  25117. a138: 0x277E,
  25118. a139: 0x277F,
  25119. a140: 0x2780,
  25120. a141: 0x2781,
  25121. a142: 0x2782,
  25122. a143: 0x2783,
  25123. a144: 0x2784,
  25124. a145: 0x2785,
  25125. a146: 0x2786,
  25126. a147: 0x2787,
  25127. a148: 0x2788,
  25128. a149: 0x2789,
  25129. a150: 0x278A,
  25130. a151: 0x278B,
  25131. a152: 0x278C,
  25132. a153: 0x278D,
  25133. a154: 0x278E,
  25134. a155: 0x278F,
  25135. a156: 0x2790,
  25136. a157: 0x2791,
  25137. a158: 0x2792,
  25138. a159: 0x2793,
  25139. a160: 0x2794,
  25140. a161: 0x2192,
  25141. a163: 0x2194,
  25142. a164: 0x2195,
  25143. a196: 0x2798,
  25144. a165: 0x2799,
  25145. a192: 0x279A,
  25146. a166: 0x279B,
  25147. a167: 0x279C,
  25148. a168: 0x279D,
  25149. a169: 0x279E,
  25150. a170: 0x279F,
  25151. a171: 0x27A0,
  25152. a172: 0x27A1,
  25153. a173: 0x27A2,
  25154. a162: 0x27A3,
  25155. a174: 0x27A4,
  25156. a175: 0x27A5,
  25157. a176: 0x27A6,
  25158. a177: 0x27A7,
  25159. a178: 0x27A8,
  25160. a179: 0x27A9,
  25161. a193: 0x27AA,
  25162. a180: 0x27AB,
  25163. a199: 0x27AC,
  25164. a181: 0x27AD,
  25165. a200: 0x27AE,
  25166. a182: 0x27AF,
  25167. a201: 0x27B1,
  25168. a183: 0x27B2,
  25169. a184: 0x27B3,
  25170. a197: 0x27B4,
  25171. a185: 0x27B5,
  25172. a194: 0x27B6,
  25173. a198: 0x27B7,
  25174. a186: 0x27B8,
  25175. a195: 0x27B9,
  25176. a187: 0x27BA,
  25177. a188: 0x27BB,
  25178. a189: 0x27BC,
  25179. a190: 0x27BD,
  25180. a191: 0x27BE,
  25181. a89: 0x2768, // 0xF8D7
  25182. a90: 0x2769, // 0xF8D8
  25183. a93: 0x276A, // 0xF8D9
  25184. a94: 0x276B, // 0xF8DA
  25185. a91: 0x276C, // 0xF8DB
  25186. a92: 0x276D, // 0xF8DC
  25187. a205: 0x276E, // 0xF8DD
  25188. a85: 0x276F, // 0xF8DE
  25189. a206: 0x2770, // 0xF8DF
  25190. a86: 0x2771, // 0xF8E0
  25191. a87: 0x2772, // 0xF8E1
  25192. a88: 0x2773, // 0xF8E2
  25193. a95: 0x2774, // 0xF8E3
  25194. a96: 0x2775, // 0xF8E4
  25195. '.notdef': 0x0000
  25196. };
  25197. var PDFImage = (function PDFImageClosure() {
  25198. /**
  25199. * Decode the image in the main thread if it supported. Resovles the promise
  25200. * when the image data is ready.
  25201. */
  25202. function handleImageData(handler, xref, res, image) {
  25203. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  25204. // For natively supported jpegs send them to the main thread for decoding.
  25205. var dict = image.dict;
  25206. var colorSpace = dict.get('ColorSpace', 'CS');
  25207. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25208. var numComps = colorSpace.numComps;
  25209. var decodePromise = handler.sendWithPromise('JpegDecode',
  25210. [image.getIR(), numComps]);
  25211. return decodePromise.then(function (message) {
  25212. var data = message.data;
  25213. return new Stream(data, 0, data.length, image.dict);
  25214. });
  25215. } else {
  25216. return Promise.resolve(image);
  25217. }
  25218. }
  25219. /**
  25220. * Decode and clamp a value. The formula is different from the spec because we
  25221. * don't decode to float range [0,1], we decode it in the [0,max] range.
  25222. */
  25223. function decodeAndClamp(value, addend, coefficient, max) {
  25224. value = addend + value * coefficient;
  25225. // Clamp the value to the range
  25226. return (value < 0 ? 0 : (value > max ? max : value));
  25227. }
  25228. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  25229. this.image = image;
  25230. var dict = image.dict;
  25231. if (dict.has('Filter')) {
  25232. var filter = dict.get('Filter').name;
  25233. if (filter === 'JPXDecode') {
  25234. var jpxImage = new JpxImage();
  25235. jpxImage.parseImageProperties(image.stream);
  25236. image.stream.reset();
  25237. image.bitsPerComponent = jpxImage.bitsPerComponent;
  25238. image.numComps = jpxImage.componentsCount;
  25239. } else if (filter === 'JBIG2Decode') {
  25240. image.bitsPerComponent = 1;
  25241. image.numComps = 1;
  25242. }
  25243. }
  25244. // TODO cache rendered images?
  25245. this.width = dict.get('Width', 'W');
  25246. this.height = dict.get('Height', 'H');
  25247. if (this.width < 1 || this.height < 1) {
  25248. error('Invalid image width: ' + this.width + ' or height: ' +
  25249. this.height);
  25250. }
  25251. this.interpolate = dict.get('Interpolate', 'I') || false;
  25252. this.imageMask = dict.get('ImageMask', 'IM') || false;
  25253. this.matte = dict.get('Matte') || false;
  25254. var bitsPerComponent = image.bitsPerComponent;
  25255. if (!bitsPerComponent) {
  25256. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  25257. if (!bitsPerComponent) {
  25258. if (this.imageMask) {
  25259. bitsPerComponent = 1;
  25260. } else {
  25261. error('Bits per component missing in image: ' + this.imageMask);
  25262. }
  25263. }
  25264. }
  25265. this.bpc = bitsPerComponent;
  25266. if (!this.imageMask) {
  25267. var colorSpace = dict.get('ColorSpace', 'CS');
  25268. if (!colorSpace) {
  25269. info('JPX images (which do not require color spaces)');
  25270. switch (image.numComps) {
  25271. case 1:
  25272. colorSpace = Name.get('DeviceGray');
  25273. break;
  25274. case 3:
  25275. colorSpace = Name.get('DeviceRGB');
  25276. break;
  25277. case 4:
  25278. colorSpace = Name.get('DeviceCMYK');
  25279. break;
  25280. default:
  25281. error('JPX images with ' + this.numComps +
  25282. ' color components not supported.');
  25283. }
  25284. }
  25285. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25286. this.numComps = this.colorSpace.numComps;
  25287. }
  25288. this.decode = dict.get('Decode', 'D');
  25289. this.needsDecode = false;
  25290. if (this.decode &&
  25291. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  25292. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  25293. this.needsDecode = true;
  25294. // Do some preprocessing to avoid more math.
  25295. var max = (1 << bitsPerComponent) - 1;
  25296. this.decodeCoefficients = [];
  25297. this.decodeAddends = [];
  25298. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  25299. var dmin = this.decode[i];
  25300. var dmax = this.decode[i + 1];
  25301. this.decodeCoefficients[j] = dmax - dmin;
  25302. this.decodeAddends[j] = max * dmin;
  25303. }
  25304. }
  25305. if (smask) {
  25306. this.smask = new PDFImage(xref, res, smask, false);
  25307. } else if (mask) {
  25308. if (isStream(mask)) {
  25309. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  25310. } else {
  25311. // Color key mask (just an array).
  25312. this.mask = mask;
  25313. }
  25314. }
  25315. }
  25316. /**
  25317. * Handles processing of image data and returns the Promise that is resolved
  25318. * with a PDFImage when the image is ready to be used.
  25319. */
  25320. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  25321. res, image, inline) {
  25322. var imagePromise = handleImageData(handler, xref, res, image);
  25323. var smaskPromise;
  25324. var maskPromise;
  25325. var smask = image.dict.get('SMask');
  25326. var mask = image.dict.get('Mask');
  25327. if (smask) {
  25328. smaskPromise = handleImageData(handler, xref, res, smask);
  25329. maskPromise = Promise.resolve(null);
  25330. } else {
  25331. smaskPromise = Promise.resolve(null);
  25332. if (mask) {
  25333. if (isStream(mask)) {
  25334. maskPromise = handleImageData(handler, xref, res, mask);
  25335. } else if (isArray(mask)) {
  25336. maskPromise = Promise.resolve(mask);
  25337. } else {
  25338. warn('Unsupported mask format.');
  25339. maskPromise = Promise.resolve(null);
  25340. }
  25341. } else {
  25342. maskPromise = Promise.resolve(null);
  25343. }
  25344. }
  25345. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  25346. function(results) {
  25347. var imageData = results[0];
  25348. var smaskData = results[1];
  25349. var maskData = results[2];
  25350. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  25351. });
  25352. };
  25353. /**
  25354. * Resize an image using the nearest neighbor algorithm. Currently only
  25355. * supports one and three component images.
  25356. * @param {TypedArray} pixels The original image with one component.
  25357. * @param {Number} bpc Number of bits per component.
  25358. * @param {Number} components Number of color components, 1 or 3 is supported.
  25359. * @param {Number} w1 Original width.
  25360. * @param {Number} h1 Original height.
  25361. * @param {Number} w2 New width.
  25362. * @param {Number} h2 New height.
  25363. * @param {TypedArray} dest (Optional) The destination buffer.
  25364. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  25365. * @return {TypedArray} Resized image data.
  25366. */
  25367. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  25368. w1, h1, w2, h2, dest, alpha01) {
  25369. if (components !== 1 && components !== 3) {
  25370. error('Unsupported component count for resizing.');
  25371. }
  25372. var length = w2 * h2 * components;
  25373. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  25374. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25375. var xRatio = w1 / w2;
  25376. var yRatio = h1 / h2;
  25377. var i, j, py, newIndex = 0, oldIndex;
  25378. var xScaled = new Uint16Array(w2);
  25379. var w1Scanline = w1 * components;
  25380. if (alpha01 !== 1) {
  25381. alpha01 = 0;
  25382. }
  25383. for (j = 0; j < w2; j++) {
  25384. xScaled[j] = Math.floor(j * xRatio) * components;
  25385. }
  25386. if (components === 1) {
  25387. for (i = 0; i < h2; i++) {
  25388. py = Math.floor(i * yRatio) * w1Scanline;
  25389. for (j = 0; j < w2; j++) {
  25390. oldIndex = py + xScaled[j];
  25391. temp[newIndex++] = pixels[oldIndex];
  25392. }
  25393. }
  25394. } else if (components === 3) {
  25395. for (i = 0; i < h2; i++) {
  25396. py = Math.floor(i * yRatio) * w1Scanline;
  25397. for (j = 0; j < w2; j++) {
  25398. oldIndex = py + xScaled[j];
  25399. temp[newIndex++] = pixels[oldIndex++];
  25400. temp[newIndex++] = pixels[oldIndex++];
  25401. temp[newIndex++] = pixels[oldIndex++];
  25402. newIndex += alpha01;
  25403. }
  25404. }
  25405. }
  25406. return temp;
  25407. };
  25408. PDFImage.createMask =
  25409. function PDFImage_createMask(imgArray, width, height,
  25410. imageIsFromDecodeStream, inverseDecode) {
  25411. // |imgArray| might not contain full data for every pixel of the mask, so
  25412. // we need to distinguish between |computedLength| and |actualLength|.
  25413. // In particular, if inverseDecode is true, then the array we return must
  25414. // have a length of |computedLength|.
  25415. var computedLength = ((width + 7) >> 3) * height;
  25416. var actualLength = imgArray.byteLength;
  25417. var haveFullData = computedLength === actualLength;
  25418. var data, i;
  25419. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  25420. // imgArray came from a DecodeStream and its data is in an appropriate
  25421. // form, so we can just transfer it.
  25422. data = imgArray;
  25423. } else if (!inverseDecode) {
  25424. data = new Uint8Array(actualLength);
  25425. data.set(imgArray);
  25426. } else {
  25427. data = new Uint8Array(computedLength);
  25428. data.set(imgArray);
  25429. for (i = actualLength; i < computedLength; i++) {
  25430. data[i] = 0xff;
  25431. }
  25432. }
  25433. // If necessary, invert the original mask data (but not any extra we might
  25434. // have added above). It's safe to modify the array -- whether it's the
  25435. // original or a copy, we're about to transfer it anyway, so nothing else
  25436. // in this thread can be relying on its contents.
  25437. if (inverseDecode) {
  25438. for (i = 0; i < actualLength; i++) {
  25439. data[i] = ~data[i];
  25440. }
  25441. }
  25442. return {data: data, width: width, height: height};
  25443. };
  25444. PDFImage.prototype = {
  25445. get drawWidth() {
  25446. return Math.max(this.width,
  25447. this.smask && this.smask.width || 0,
  25448. this.mask && this.mask.width || 0);
  25449. },
  25450. get drawHeight() {
  25451. return Math.max(this.height,
  25452. this.smask && this.smask.height || 0,
  25453. this.mask && this.mask.height || 0);
  25454. },
  25455. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  25456. var bpc = this.bpc;
  25457. var numComps = this.numComps;
  25458. var decodeAddends = this.decodeAddends;
  25459. var decodeCoefficients = this.decodeCoefficients;
  25460. var max = (1 << bpc) - 1;
  25461. var i, ii;
  25462. if (bpc === 1) {
  25463. // If the buffer needed decode that means it just needs to be inverted.
  25464. for (i = 0, ii = buffer.length; i < ii; i++) {
  25465. buffer[i] = +!(buffer[i]);
  25466. }
  25467. return;
  25468. }
  25469. var index = 0;
  25470. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25471. for (var j = 0; j < numComps; j++) {
  25472. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25473. decodeCoefficients[j], max);
  25474. index++;
  25475. }
  25476. }
  25477. },
  25478. getComponents: function PDFImage_getComponents(buffer) {
  25479. var bpc = this.bpc;
  25480. // This image doesn't require any extra work.
  25481. if (bpc === 8) {
  25482. return buffer;
  25483. }
  25484. var width = this.width;
  25485. var height = this.height;
  25486. var numComps = this.numComps;
  25487. var length = width * height * numComps;
  25488. var bufferPos = 0;
  25489. var output = (bpc <= 8 ? new Uint8Array(length) :
  25490. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25491. var rowComps = width * numComps;
  25492. var max = (1 << bpc) - 1;
  25493. var i = 0, ii, buf;
  25494. if (bpc === 1) {
  25495. // Optimization for reading 1 bpc images.
  25496. var mask, loop1End, loop2End;
  25497. for (var j = 0; j < height; j++) {
  25498. loop1End = i + (rowComps & ~7);
  25499. loop2End = i + rowComps;
  25500. // unroll loop for all full bytes
  25501. while (i < loop1End) {
  25502. buf = buffer[bufferPos++];
  25503. output[i] = (buf >> 7) & 1;
  25504. output[i + 1] = (buf >> 6) & 1;
  25505. output[i + 2] = (buf >> 5) & 1;
  25506. output[i + 3] = (buf >> 4) & 1;
  25507. output[i + 4] = (buf >> 3) & 1;
  25508. output[i + 5] = (buf >> 2) & 1;
  25509. output[i + 6] = (buf >> 1) & 1;
  25510. output[i + 7] = buf & 1;
  25511. i += 8;
  25512. }
  25513. // handle remaing bits
  25514. if (i < loop2End) {
  25515. buf = buffer[bufferPos++];
  25516. mask = 128;
  25517. while (i < loop2End) {
  25518. output[i++] = +!!(buf & mask);
  25519. mask >>= 1;
  25520. }
  25521. }
  25522. }
  25523. } else {
  25524. // The general case that handles all other bpc values.
  25525. var bits = 0;
  25526. buf = 0;
  25527. for (i = 0, ii = length; i < ii; ++i) {
  25528. if (i % rowComps === 0) {
  25529. buf = 0;
  25530. bits = 0;
  25531. }
  25532. while (bits < bpc) {
  25533. buf = (buf << 8) | buffer[bufferPos++];
  25534. bits += 8;
  25535. }
  25536. var remainingBits = bits - bpc;
  25537. var value = buf >> remainingBits;
  25538. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25539. buf = buf & ((1 << remainingBits) - 1);
  25540. bits = remainingBits;
  25541. }
  25542. }
  25543. return output;
  25544. },
  25545. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25546. actualHeight, image) {
  25547. var smask = this.smask;
  25548. var mask = this.mask;
  25549. var alphaBuf, sw, sh, i, ii, j;
  25550. if (smask) {
  25551. sw = smask.width;
  25552. sh = smask.height;
  25553. alphaBuf = new Uint8Array(sw * sh);
  25554. smask.fillGrayBuffer(alphaBuf);
  25555. if (sw !== width || sh !== height) {
  25556. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25557. height);
  25558. }
  25559. } else if (mask) {
  25560. if (mask instanceof PDFImage) {
  25561. sw = mask.width;
  25562. sh = mask.height;
  25563. alphaBuf = new Uint8Array(sw * sh);
  25564. mask.numComps = 1;
  25565. mask.fillGrayBuffer(alphaBuf);
  25566. // Need to invert values in rgbaBuf
  25567. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25568. alphaBuf[i] = 255 - alphaBuf[i];
  25569. }
  25570. if (sw !== width || sh !== height) {
  25571. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25572. height);
  25573. }
  25574. } else if (isArray(mask)) {
  25575. // Color key mask: if any of the compontents are outside the range
  25576. // then they should be painted.
  25577. alphaBuf = new Uint8Array(width * height);
  25578. var numComps = this.numComps;
  25579. for (i = 0, ii = width * height; i < ii; ++i) {
  25580. var opacity = 0;
  25581. var imageOffset = i * numComps;
  25582. for (j = 0; j < numComps; ++j) {
  25583. var color = image[imageOffset + j];
  25584. var maskOffset = j * 2;
  25585. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25586. opacity = 255;
  25587. break;
  25588. }
  25589. }
  25590. alphaBuf[i] = opacity;
  25591. }
  25592. } else {
  25593. error('Unknown mask format.');
  25594. }
  25595. }
  25596. if (alphaBuf) {
  25597. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25598. rgbaBuf[j] = alphaBuf[i];
  25599. }
  25600. } else {
  25601. // No mask.
  25602. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25603. rgbaBuf[j] = 255;
  25604. }
  25605. }
  25606. },
  25607. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25608. var matte = this.smask && this.smask.matte;
  25609. if (!matte) {
  25610. return;
  25611. }
  25612. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25613. var matteR = matteRgb[0];
  25614. var matteG = matteRgb[1];
  25615. var matteB = matteRgb[2];
  25616. var length = width * height * 4;
  25617. var r, g, b;
  25618. for (var i = 0; i < length; i += 4) {
  25619. var alpha = buffer[i + 3];
  25620. if (alpha === 0) {
  25621. // according formula we have to get Infinity in all components
  25622. // making it white (typical paper color) should be okay
  25623. buffer[i] = 255;
  25624. buffer[i + 1] = 255;
  25625. buffer[i + 2] = 255;
  25626. continue;
  25627. }
  25628. var k = 255 / alpha;
  25629. r = (buffer[i] - matteR) * k + matteR;
  25630. g = (buffer[i + 1] - matteG) * k + matteG;
  25631. b = (buffer[i + 2] - matteB) * k + matteB;
  25632. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25633. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25634. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25635. }
  25636. },
  25637. createImageData: function PDFImage_createImageData(forceRGBA) {
  25638. var drawWidth = this.drawWidth;
  25639. var drawHeight = this.drawHeight;
  25640. var imgData = { // other fields are filled in below
  25641. width: drawWidth,
  25642. height: drawHeight
  25643. };
  25644. var numComps = this.numComps;
  25645. var originalWidth = this.width;
  25646. var originalHeight = this.height;
  25647. var bpc = this.bpc;
  25648. // Rows start at byte boundary.
  25649. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25650. var imgArray;
  25651. if (!forceRGBA) {
  25652. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25653. // without any complications, we pass a same-sized copy to the main
  25654. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25655. // of memory for many scanned documents. It's also much faster.
  25656. //
  25657. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25658. // complications, we avoid expanding by 1.333x to RGBA form.
  25659. var kind;
  25660. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25661. kind = ImageKind.GRAYSCALE_1BPP;
  25662. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25663. !this.needsDecode) {
  25664. kind = ImageKind.RGB_24BPP;
  25665. }
  25666. if (kind && !this.smask && !this.mask &&
  25667. drawWidth === originalWidth && drawHeight === originalHeight) {
  25668. imgData.kind = kind;
  25669. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25670. // If imgArray came from a DecodeStream, we're safe to transfer it
  25671. // (and thus neuter it) because it will constitute the entire
  25672. // DecodeStream's data. But if it came from a Stream, we need to
  25673. // copy it because it'll only be a portion of the Stream's data, and
  25674. // the rest will be read later on.
  25675. if (this.image instanceof DecodeStream) {
  25676. imgData.data = imgArray;
  25677. } else {
  25678. var newArray = new Uint8Array(imgArray.length);
  25679. newArray.set(imgArray);
  25680. imgData.data = newArray;
  25681. }
  25682. if (this.needsDecode) {
  25683. // Invert the buffer (which must be grayscale if we reached here).
  25684. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25685. var buffer = imgData.data;
  25686. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25687. buffer[i] ^= 0xff;
  25688. }
  25689. }
  25690. return imgData;
  25691. }
  25692. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  25693. (this.colorSpace.name === 'DeviceGray' ||
  25694. this.colorSpace.name === 'DeviceRGB' ||
  25695. this.colorSpace.name === 'DeviceCMYK')) {
  25696. imgData.kind = ImageKind.RGB_24BPP;
  25697. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25698. drawWidth, drawHeight, true);
  25699. return imgData;
  25700. }
  25701. }
  25702. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25703. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25704. var actualHeight = 0 | (imgArray.length / rowBytes *
  25705. drawHeight / originalHeight);
  25706. var comps = this.getComponents(imgArray);
  25707. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25708. // more compact RGB_24BPP form if allowable.
  25709. var alpha01, maybeUndoPreblend;
  25710. if (!forceRGBA && !this.smask && !this.mask) {
  25711. imgData.kind = ImageKind.RGB_24BPP;
  25712. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25713. alpha01 = 0;
  25714. maybeUndoPreblend = false;
  25715. } else {
  25716. imgData.kind = ImageKind.RGBA_32BPP;
  25717. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25718. alpha01 = 1;
  25719. maybeUndoPreblend = true;
  25720. // Color key masking (opacity) must be performed before decoding.
  25721. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25722. comps);
  25723. }
  25724. if (this.needsDecode) {
  25725. this.decodeBuffer(comps);
  25726. }
  25727. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25728. drawWidth, drawHeight, actualHeight, bpc, comps,
  25729. alpha01);
  25730. if (maybeUndoPreblend) {
  25731. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25732. }
  25733. return imgData;
  25734. },
  25735. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25736. var numComps = this.numComps;
  25737. if (numComps !== 1) {
  25738. error('Reading gray scale from a color image: ' + numComps);
  25739. }
  25740. var width = this.width;
  25741. var height = this.height;
  25742. var bpc = this.bpc;
  25743. // rows start at byte boundary
  25744. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25745. var imgArray = this.getImageBytes(height * rowBytes);
  25746. var comps = this.getComponents(imgArray);
  25747. var i, length;
  25748. if (bpc === 1) {
  25749. // inline decoding (= inversion) for 1 bpc images
  25750. length = width * height;
  25751. if (this.needsDecode) {
  25752. // invert and scale to {0, 255}
  25753. for (i = 0; i < length; ++i) {
  25754. buffer[i] = (comps[i] - 1) & 255;
  25755. }
  25756. } else {
  25757. // scale to {0, 255}
  25758. for (i = 0; i < length; ++i) {
  25759. buffer[i] = (-comps[i]) & 255;
  25760. }
  25761. }
  25762. return;
  25763. }
  25764. if (this.needsDecode) {
  25765. this.decodeBuffer(comps);
  25766. }
  25767. length = width * height;
  25768. // we aren't using a colorspace so we need to scale the value
  25769. var scale = 255 / ((1 << bpc) - 1);
  25770. for (i = 0; i < length; ++i) {
  25771. buffer[i] = (scale * comps[i]) | 0;
  25772. }
  25773. },
  25774. getImageBytes: function PDFImage_getImageBytes(length,
  25775. drawWidth, drawHeight,
  25776. forceRGB) {
  25777. this.image.reset();
  25778. this.image.drawWidth = drawWidth || this.width;
  25779. this.image.drawHeight = drawHeight || this.height;
  25780. this.image.forceRGB = !!forceRGB;
  25781. return this.image.getBytes(length);
  25782. }
  25783. };
  25784. return PDFImage;
  25785. })();
  25786. // The Metrics object contains glyph widths (in glyph space units).
  25787. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25788. // space unit corresponds to 1/1000th of text space unit.
  25789. var Metrics = {
  25790. 'Courier': 600,
  25791. 'Courier-Bold': 600,
  25792. 'Courier-BoldOblique': 600,
  25793. 'Courier-Oblique': 600,
  25794. 'Helvetica' : {
  25795. 'space': 278,
  25796. 'exclam': 278,
  25797. 'quotedbl': 355,
  25798. 'numbersign': 556,
  25799. 'dollar': 556,
  25800. 'percent': 889,
  25801. 'ampersand': 667,
  25802. 'quoteright': 222,
  25803. 'parenleft': 333,
  25804. 'parenright': 333,
  25805. 'asterisk': 389,
  25806. 'plus': 584,
  25807. 'comma': 278,
  25808. 'hyphen': 333,
  25809. 'period': 278,
  25810. 'slash': 278,
  25811. 'zero': 556,
  25812. 'one': 556,
  25813. 'two': 556,
  25814. 'three': 556,
  25815. 'four': 556,
  25816. 'five': 556,
  25817. 'six': 556,
  25818. 'seven': 556,
  25819. 'eight': 556,
  25820. 'nine': 556,
  25821. 'colon': 278,
  25822. 'semicolon': 278,
  25823. 'less': 584,
  25824. 'equal': 584,
  25825. 'greater': 584,
  25826. 'question': 556,
  25827. 'at': 1015,
  25828. 'A': 667,
  25829. 'B': 667,
  25830. 'C': 722,
  25831. 'D': 722,
  25832. 'E': 667,
  25833. 'F': 611,
  25834. 'G': 778,
  25835. 'H': 722,
  25836. 'I': 278,
  25837. 'J': 500,
  25838. 'K': 667,
  25839. 'L': 556,
  25840. 'M': 833,
  25841. 'N': 722,
  25842. 'O': 778,
  25843. 'P': 667,
  25844. 'Q': 778,
  25845. 'R': 722,
  25846. 'S': 667,
  25847. 'T': 611,
  25848. 'U': 722,
  25849. 'V': 667,
  25850. 'W': 944,
  25851. 'X': 667,
  25852. 'Y': 667,
  25853. 'Z': 611,
  25854. 'bracketleft': 278,
  25855. 'backslash': 278,
  25856. 'bracketright': 278,
  25857. 'asciicircum': 469,
  25858. 'underscore': 556,
  25859. 'quoteleft': 222,
  25860. 'a': 556,
  25861. 'b': 556,
  25862. 'c': 500,
  25863. 'd': 556,
  25864. 'e': 556,
  25865. 'f': 278,
  25866. 'g': 556,
  25867. 'h': 556,
  25868. 'i': 222,
  25869. 'j': 222,
  25870. 'k': 500,
  25871. 'l': 222,
  25872. 'm': 833,
  25873. 'n': 556,
  25874. 'o': 556,
  25875. 'p': 556,
  25876. 'q': 556,
  25877. 'r': 333,
  25878. 's': 500,
  25879. 't': 278,
  25880. 'u': 556,
  25881. 'v': 500,
  25882. 'w': 722,
  25883. 'x': 500,
  25884. 'y': 500,
  25885. 'z': 500,
  25886. 'braceleft': 334,
  25887. 'bar': 260,
  25888. 'braceright': 334,
  25889. 'asciitilde': 584,
  25890. 'exclamdown': 333,
  25891. 'cent': 556,
  25892. 'sterling': 556,
  25893. 'fraction': 167,
  25894. 'yen': 556,
  25895. 'florin': 556,
  25896. 'section': 556,
  25897. 'currency': 556,
  25898. 'quotesingle': 191,
  25899. 'quotedblleft': 333,
  25900. 'guillemotleft': 556,
  25901. 'guilsinglleft': 333,
  25902. 'guilsinglright': 333,
  25903. 'fi': 500,
  25904. 'fl': 500,
  25905. 'endash': 556,
  25906. 'dagger': 556,
  25907. 'daggerdbl': 556,
  25908. 'periodcentered': 278,
  25909. 'paragraph': 537,
  25910. 'bullet': 350,
  25911. 'quotesinglbase': 222,
  25912. 'quotedblbase': 333,
  25913. 'quotedblright': 333,
  25914. 'guillemotright': 556,
  25915. 'ellipsis': 1000,
  25916. 'perthousand': 1000,
  25917. 'questiondown': 611,
  25918. 'grave': 333,
  25919. 'acute': 333,
  25920. 'circumflex': 333,
  25921. 'tilde': 333,
  25922. 'macron': 333,
  25923. 'breve': 333,
  25924. 'dotaccent': 333,
  25925. 'dieresis': 333,
  25926. 'ring': 333,
  25927. 'cedilla': 333,
  25928. 'hungarumlaut': 333,
  25929. 'ogonek': 333,
  25930. 'caron': 333,
  25931. 'emdash': 1000,
  25932. 'AE': 1000,
  25933. 'ordfeminine': 370,
  25934. 'Lslash': 556,
  25935. 'Oslash': 778,
  25936. 'OE': 1000,
  25937. 'ordmasculine': 365,
  25938. 'ae': 889,
  25939. 'dotlessi': 278,
  25940. 'lslash': 222,
  25941. 'oslash': 611,
  25942. 'oe': 944,
  25943. 'germandbls': 611,
  25944. 'Idieresis': 278,
  25945. 'eacute': 556,
  25946. 'abreve': 556,
  25947. 'uhungarumlaut': 556,
  25948. 'ecaron': 556,
  25949. 'Ydieresis': 667,
  25950. 'divide': 584,
  25951. 'Yacute': 667,
  25952. 'Acircumflex': 667,
  25953. 'aacute': 556,
  25954. 'Ucircumflex': 722,
  25955. 'yacute': 500,
  25956. 'scommaaccent': 500,
  25957. 'ecircumflex': 556,
  25958. 'Uring': 722,
  25959. 'Udieresis': 722,
  25960. 'aogonek': 556,
  25961. 'Uacute': 722,
  25962. 'uogonek': 556,
  25963. 'Edieresis': 667,
  25964. 'Dcroat': 722,
  25965. 'commaaccent': 250,
  25966. 'copyright': 737,
  25967. 'Emacron': 667,
  25968. 'ccaron': 500,
  25969. 'aring': 556,
  25970. 'Ncommaaccent': 722,
  25971. 'lacute': 222,
  25972. 'agrave': 556,
  25973. 'Tcommaaccent': 611,
  25974. 'Cacute': 722,
  25975. 'atilde': 556,
  25976. 'Edotaccent': 667,
  25977. 'scaron': 500,
  25978. 'scedilla': 500,
  25979. 'iacute': 278,
  25980. 'lozenge': 471,
  25981. 'Rcaron': 722,
  25982. 'Gcommaaccent': 778,
  25983. 'ucircumflex': 556,
  25984. 'acircumflex': 556,
  25985. 'Amacron': 667,
  25986. 'rcaron': 333,
  25987. 'ccedilla': 500,
  25988. 'Zdotaccent': 611,
  25989. 'Thorn': 667,
  25990. 'Omacron': 778,
  25991. 'Racute': 722,
  25992. 'Sacute': 667,
  25993. 'dcaron': 643,
  25994. 'Umacron': 722,
  25995. 'uring': 556,
  25996. 'threesuperior': 333,
  25997. 'Ograve': 778,
  25998. 'Agrave': 667,
  25999. 'Abreve': 667,
  26000. 'multiply': 584,
  26001. 'uacute': 556,
  26002. 'Tcaron': 611,
  26003. 'partialdiff': 476,
  26004. 'ydieresis': 500,
  26005. 'Nacute': 722,
  26006. 'icircumflex': 278,
  26007. 'Ecircumflex': 667,
  26008. 'adieresis': 556,
  26009. 'edieresis': 556,
  26010. 'cacute': 500,
  26011. 'nacute': 556,
  26012. 'umacron': 556,
  26013. 'Ncaron': 722,
  26014. 'Iacute': 278,
  26015. 'plusminus': 584,
  26016. 'brokenbar': 260,
  26017. 'registered': 737,
  26018. 'Gbreve': 778,
  26019. 'Idotaccent': 278,
  26020. 'summation': 600,
  26021. 'Egrave': 667,
  26022. 'racute': 333,
  26023. 'omacron': 556,
  26024. 'Zacute': 611,
  26025. 'Zcaron': 611,
  26026. 'greaterequal': 549,
  26027. 'Eth': 722,
  26028. 'Ccedilla': 722,
  26029. 'lcommaaccent': 222,
  26030. 'tcaron': 317,
  26031. 'eogonek': 556,
  26032. 'Uogonek': 722,
  26033. 'Aacute': 667,
  26034. 'Adieresis': 667,
  26035. 'egrave': 556,
  26036. 'zacute': 500,
  26037. 'iogonek': 222,
  26038. 'Oacute': 778,
  26039. 'oacute': 556,
  26040. 'amacron': 556,
  26041. 'sacute': 500,
  26042. 'idieresis': 278,
  26043. 'Ocircumflex': 778,
  26044. 'Ugrave': 722,
  26045. 'Delta': 612,
  26046. 'thorn': 556,
  26047. 'twosuperior': 333,
  26048. 'Odieresis': 778,
  26049. 'mu': 556,
  26050. 'igrave': 278,
  26051. 'ohungarumlaut': 556,
  26052. 'Eogonek': 667,
  26053. 'dcroat': 556,
  26054. 'threequarters': 834,
  26055. 'Scedilla': 667,
  26056. 'lcaron': 299,
  26057. 'Kcommaaccent': 667,
  26058. 'Lacute': 556,
  26059. 'trademark': 1000,
  26060. 'edotaccent': 556,
  26061. 'Igrave': 278,
  26062. 'Imacron': 278,
  26063. 'Lcaron': 556,
  26064. 'onehalf': 834,
  26065. 'lessequal': 549,
  26066. 'ocircumflex': 556,
  26067. 'ntilde': 556,
  26068. 'Uhungarumlaut': 722,
  26069. 'Eacute': 667,
  26070. 'emacron': 556,
  26071. 'gbreve': 556,
  26072. 'onequarter': 834,
  26073. 'Scaron': 667,
  26074. 'Scommaaccent': 667,
  26075. 'Ohungarumlaut': 778,
  26076. 'degree': 400,
  26077. 'ograve': 556,
  26078. 'Ccaron': 722,
  26079. 'ugrave': 556,
  26080. 'radical': 453,
  26081. 'Dcaron': 722,
  26082. 'rcommaaccent': 333,
  26083. 'Ntilde': 722,
  26084. 'otilde': 556,
  26085. 'Rcommaaccent': 722,
  26086. 'Lcommaaccent': 556,
  26087. 'Atilde': 667,
  26088. 'Aogonek': 667,
  26089. 'Aring': 667,
  26090. 'Otilde': 778,
  26091. 'zdotaccent': 500,
  26092. 'Ecaron': 667,
  26093. 'Iogonek': 278,
  26094. 'kcommaaccent': 500,
  26095. 'minus': 584,
  26096. 'Icircumflex': 278,
  26097. 'ncaron': 556,
  26098. 'tcommaaccent': 278,
  26099. 'logicalnot': 584,
  26100. 'odieresis': 556,
  26101. 'udieresis': 556,
  26102. 'notequal': 549,
  26103. 'gcommaaccent': 556,
  26104. 'eth': 556,
  26105. 'zcaron': 500,
  26106. 'ncommaaccent': 556,
  26107. 'onesuperior': 333,
  26108. 'imacron': 278,
  26109. 'Euro': 556
  26110. },
  26111. 'Helvetica-Bold': {
  26112. 'space': 278,
  26113. 'exclam': 333,
  26114. 'quotedbl': 474,
  26115. 'numbersign': 556,
  26116. 'dollar': 556,
  26117. 'percent': 889,
  26118. 'ampersand': 722,
  26119. 'quoteright': 278,
  26120. 'parenleft': 333,
  26121. 'parenright': 333,
  26122. 'asterisk': 389,
  26123. 'plus': 584,
  26124. 'comma': 278,
  26125. 'hyphen': 333,
  26126. 'period': 278,
  26127. 'slash': 278,
  26128. 'zero': 556,
  26129. 'one': 556,
  26130. 'two': 556,
  26131. 'three': 556,
  26132. 'four': 556,
  26133. 'five': 556,
  26134. 'six': 556,
  26135. 'seven': 556,
  26136. 'eight': 556,
  26137. 'nine': 556,
  26138. 'colon': 333,
  26139. 'semicolon': 333,
  26140. 'less': 584,
  26141. 'equal': 584,
  26142. 'greater': 584,
  26143. 'question': 611,
  26144. 'at': 975,
  26145. 'A': 722,
  26146. 'B': 722,
  26147. 'C': 722,
  26148. 'D': 722,
  26149. 'E': 667,
  26150. 'F': 611,
  26151. 'G': 778,
  26152. 'H': 722,
  26153. 'I': 278,
  26154. 'J': 556,
  26155. 'K': 722,
  26156. 'L': 611,
  26157. 'M': 833,
  26158. 'N': 722,
  26159. 'O': 778,
  26160. 'P': 667,
  26161. 'Q': 778,
  26162. 'R': 722,
  26163. 'S': 667,
  26164. 'T': 611,
  26165. 'U': 722,
  26166. 'V': 667,
  26167. 'W': 944,
  26168. 'X': 667,
  26169. 'Y': 667,
  26170. 'Z': 611,
  26171. 'bracketleft': 333,
  26172. 'backslash': 278,
  26173. 'bracketright': 333,
  26174. 'asciicircum': 584,
  26175. 'underscore': 556,
  26176. 'quoteleft': 278,
  26177. 'a': 556,
  26178. 'b': 611,
  26179. 'c': 556,
  26180. 'd': 611,
  26181. 'e': 556,
  26182. 'f': 333,
  26183. 'g': 611,
  26184. 'h': 611,
  26185. 'i': 278,
  26186. 'j': 278,
  26187. 'k': 556,
  26188. 'l': 278,
  26189. 'm': 889,
  26190. 'n': 611,
  26191. 'o': 611,
  26192. 'p': 611,
  26193. 'q': 611,
  26194. 'r': 389,
  26195. 's': 556,
  26196. 't': 333,
  26197. 'u': 611,
  26198. 'v': 556,
  26199. 'w': 778,
  26200. 'x': 556,
  26201. 'y': 556,
  26202. 'z': 500,
  26203. 'braceleft': 389,
  26204. 'bar': 280,
  26205. 'braceright': 389,
  26206. 'asciitilde': 584,
  26207. 'exclamdown': 333,
  26208. 'cent': 556,
  26209. 'sterling': 556,
  26210. 'fraction': 167,
  26211. 'yen': 556,
  26212. 'florin': 556,
  26213. 'section': 556,
  26214. 'currency': 556,
  26215. 'quotesingle': 238,
  26216. 'quotedblleft': 500,
  26217. 'guillemotleft': 556,
  26218. 'guilsinglleft': 333,
  26219. 'guilsinglright': 333,
  26220. 'fi': 611,
  26221. 'fl': 611,
  26222. 'endash': 556,
  26223. 'dagger': 556,
  26224. 'daggerdbl': 556,
  26225. 'periodcentered': 278,
  26226. 'paragraph': 556,
  26227. 'bullet': 350,
  26228. 'quotesinglbase': 278,
  26229. 'quotedblbase': 500,
  26230. 'quotedblright': 500,
  26231. 'guillemotright': 556,
  26232. 'ellipsis': 1000,
  26233. 'perthousand': 1000,
  26234. 'questiondown': 611,
  26235. 'grave': 333,
  26236. 'acute': 333,
  26237. 'circumflex': 333,
  26238. 'tilde': 333,
  26239. 'macron': 333,
  26240. 'breve': 333,
  26241. 'dotaccent': 333,
  26242. 'dieresis': 333,
  26243. 'ring': 333,
  26244. 'cedilla': 333,
  26245. 'hungarumlaut': 333,
  26246. 'ogonek': 333,
  26247. 'caron': 333,
  26248. 'emdash': 1000,
  26249. 'AE': 1000,
  26250. 'ordfeminine': 370,
  26251. 'Lslash': 611,
  26252. 'Oslash': 778,
  26253. 'OE': 1000,
  26254. 'ordmasculine': 365,
  26255. 'ae': 889,
  26256. 'dotlessi': 278,
  26257. 'lslash': 278,
  26258. 'oslash': 611,
  26259. 'oe': 944,
  26260. 'germandbls': 611,
  26261. 'Idieresis': 278,
  26262. 'eacute': 556,
  26263. 'abreve': 556,
  26264. 'uhungarumlaut': 611,
  26265. 'ecaron': 556,
  26266. 'Ydieresis': 667,
  26267. 'divide': 584,
  26268. 'Yacute': 667,
  26269. 'Acircumflex': 722,
  26270. 'aacute': 556,
  26271. 'Ucircumflex': 722,
  26272. 'yacute': 556,
  26273. 'scommaaccent': 556,
  26274. 'ecircumflex': 556,
  26275. 'Uring': 722,
  26276. 'Udieresis': 722,
  26277. 'aogonek': 556,
  26278. 'Uacute': 722,
  26279. 'uogonek': 611,
  26280. 'Edieresis': 667,
  26281. 'Dcroat': 722,
  26282. 'commaaccent': 250,
  26283. 'copyright': 737,
  26284. 'Emacron': 667,
  26285. 'ccaron': 556,
  26286. 'aring': 556,
  26287. 'Ncommaaccent': 722,
  26288. 'lacute': 278,
  26289. 'agrave': 556,
  26290. 'Tcommaaccent': 611,
  26291. 'Cacute': 722,
  26292. 'atilde': 556,
  26293. 'Edotaccent': 667,
  26294. 'scaron': 556,
  26295. 'scedilla': 556,
  26296. 'iacute': 278,
  26297. 'lozenge': 494,
  26298. 'Rcaron': 722,
  26299. 'Gcommaaccent': 778,
  26300. 'ucircumflex': 611,
  26301. 'acircumflex': 556,
  26302. 'Amacron': 722,
  26303. 'rcaron': 389,
  26304. 'ccedilla': 556,
  26305. 'Zdotaccent': 611,
  26306. 'Thorn': 667,
  26307. 'Omacron': 778,
  26308. 'Racute': 722,
  26309. 'Sacute': 667,
  26310. 'dcaron': 743,
  26311. 'Umacron': 722,
  26312. 'uring': 611,
  26313. 'threesuperior': 333,
  26314. 'Ograve': 778,
  26315. 'Agrave': 722,
  26316. 'Abreve': 722,
  26317. 'multiply': 584,
  26318. 'uacute': 611,
  26319. 'Tcaron': 611,
  26320. 'partialdiff': 494,
  26321. 'ydieresis': 556,
  26322. 'Nacute': 722,
  26323. 'icircumflex': 278,
  26324. 'Ecircumflex': 667,
  26325. 'adieresis': 556,
  26326. 'edieresis': 556,
  26327. 'cacute': 556,
  26328. 'nacute': 611,
  26329. 'umacron': 611,
  26330. 'Ncaron': 722,
  26331. 'Iacute': 278,
  26332. 'plusminus': 584,
  26333. 'brokenbar': 280,
  26334. 'registered': 737,
  26335. 'Gbreve': 778,
  26336. 'Idotaccent': 278,
  26337. 'summation': 600,
  26338. 'Egrave': 667,
  26339. 'racute': 389,
  26340. 'omacron': 611,
  26341. 'Zacute': 611,
  26342. 'Zcaron': 611,
  26343. 'greaterequal': 549,
  26344. 'Eth': 722,
  26345. 'Ccedilla': 722,
  26346. 'lcommaaccent': 278,
  26347. 'tcaron': 389,
  26348. 'eogonek': 556,
  26349. 'Uogonek': 722,
  26350. 'Aacute': 722,
  26351. 'Adieresis': 722,
  26352. 'egrave': 556,
  26353. 'zacute': 500,
  26354. 'iogonek': 278,
  26355. 'Oacute': 778,
  26356. 'oacute': 611,
  26357. 'amacron': 556,
  26358. 'sacute': 556,
  26359. 'idieresis': 278,
  26360. 'Ocircumflex': 778,
  26361. 'Ugrave': 722,
  26362. 'Delta': 612,
  26363. 'thorn': 611,
  26364. 'twosuperior': 333,
  26365. 'Odieresis': 778,
  26366. 'mu': 611,
  26367. 'igrave': 278,
  26368. 'ohungarumlaut': 611,
  26369. 'Eogonek': 667,
  26370. 'dcroat': 611,
  26371. 'threequarters': 834,
  26372. 'Scedilla': 667,
  26373. 'lcaron': 400,
  26374. 'Kcommaaccent': 722,
  26375. 'Lacute': 611,
  26376. 'trademark': 1000,
  26377. 'edotaccent': 556,
  26378. 'Igrave': 278,
  26379. 'Imacron': 278,
  26380. 'Lcaron': 611,
  26381. 'onehalf': 834,
  26382. 'lessequal': 549,
  26383. 'ocircumflex': 611,
  26384. 'ntilde': 611,
  26385. 'Uhungarumlaut': 722,
  26386. 'Eacute': 667,
  26387. 'emacron': 556,
  26388. 'gbreve': 611,
  26389. 'onequarter': 834,
  26390. 'Scaron': 667,
  26391. 'Scommaaccent': 667,
  26392. 'Ohungarumlaut': 778,
  26393. 'degree': 400,
  26394. 'ograve': 611,
  26395. 'Ccaron': 722,
  26396. 'ugrave': 611,
  26397. 'radical': 549,
  26398. 'Dcaron': 722,
  26399. 'rcommaaccent': 389,
  26400. 'Ntilde': 722,
  26401. 'otilde': 611,
  26402. 'Rcommaaccent': 722,
  26403. 'Lcommaaccent': 611,
  26404. 'Atilde': 722,
  26405. 'Aogonek': 722,
  26406. 'Aring': 722,
  26407. 'Otilde': 778,
  26408. 'zdotaccent': 500,
  26409. 'Ecaron': 667,
  26410. 'Iogonek': 278,
  26411. 'kcommaaccent': 556,
  26412. 'minus': 584,
  26413. 'Icircumflex': 278,
  26414. 'ncaron': 611,
  26415. 'tcommaaccent': 333,
  26416. 'logicalnot': 584,
  26417. 'odieresis': 611,
  26418. 'udieresis': 611,
  26419. 'notequal': 549,
  26420. 'gcommaaccent': 611,
  26421. 'eth': 611,
  26422. 'zcaron': 500,
  26423. 'ncommaaccent': 611,
  26424. 'onesuperior': 333,
  26425. 'imacron': 278,
  26426. 'Euro': 556
  26427. },
  26428. 'Helvetica-BoldOblique': {
  26429. 'space': 278,
  26430. 'exclam': 333,
  26431. 'quotedbl': 474,
  26432. 'numbersign': 556,
  26433. 'dollar': 556,
  26434. 'percent': 889,
  26435. 'ampersand': 722,
  26436. 'quoteright': 278,
  26437. 'parenleft': 333,
  26438. 'parenright': 333,
  26439. 'asterisk': 389,
  26440. 'plus': 584,
  26441. 'comma': 278,
  26442. 'hyphen': 333,
  26443. 'period': 278,
  26444. 'slash': 278,
  26445. 'zero': 556,
  26446. 'one': 556,
  26447. 'two': 556,
  26448. 'three': 556,
  26449. 'four': 556,
  26450. 'five': 556,
  26451. 'six': 556,
  26452. 'seven': 556,
  26453. 'eight': 556,
  26454. 'nine': 556,
  26455. 'colon': 333,
  26456. 'semicolon': 333,
  26457. 'less': 584,
  26458. 'equal': 584,
  26459. 'greater': 584,
  26460. 'question': 611,
  26461. 'at': 975,
  26462. 'A': 722,
  26463. 'B': 722,
  26464. 'C': 722,
  26465. 'D': 722,
  26466. 'E': 667,
  26467. 'F': 611,
  26468. 'G': 778,
  26469. 'H': 722,
  26470. 'I': 278,
  26471. 'J': 556,
  26472. 'K': 722,
  26473. 'L': 611,
  26474. 'M': 833,
  26475. 'N': 722,
  26476. 'O': 778,
  26477. 'P': 667,
  26478. 'Q': 778,
  26479. 'R': 722,
  26480. 'S': 667,
  26481. 'T': 611,
  26482. 'U': 722,
  26483. 'V': 667,
  26484. 'W': 944,
  26485. 'X': 667,
  26486. 'Y': 667,
  26487. 'Z': 611,
  26488. 'bracketleft': 333,
  26489. 'backslash': 278,
  26490. 'bracketright': 333,
  26491. 'asciicircum': 584,
  26492. 'underscore': 556,
  26493. 'quoteleft': 278,
  26494. 'a': 556,
  26495. 'b': 611,
  26496. 'c': 556,
  26497. 'd': 611,
  26498. 'e': 556,
  26499. 'f': 333,
  26500. 'g': 611,
  26501. 'h': 611,
  26502. 'i': 278,
  26503. 'j': 278,
  26504. 'k': 556,
  26505. 'l': 278,
  26506. 'm': 889,
  26507. 'n': 611,
  26508. 'o': 611,
  26509. 'p': 611,
  26510. 'q': 611,
  26511. 'r': 389,
  26512. 's': 556,
  26513. 't': 333,
  26514. 'u': 611,
  26515. 'v': 556,
  26516. 'w': 778,
  26517. 'x': 556,
  26518. 'y': 556,
  26519. 'z': 500,
  26520. 'braceleft': 389,
  26521. 'bar': 280,
  26522. 'braceright': 389,
  26523. 'asciitilde': 584,
  26524. 'exclamdown': 333,
  26525. 'cent': 556,
  26526. 'sterling': 556,
  26527. 'fraction': 167,
  26528. 'yen': 556,
  26529. 'florin': 556,
  26530. 'section': 556,
  26531. 'currency': 556,
  26532. 'quotesingle': 238,
  26533. 'quotedblleft': 500,
  26534. 'guillemotleft': 556,
  26535. 'guilsinglleft': 333,
  26536. 'guilsinglright': 333,
  26537. 'fi': 611,
  26538. 'fl': 611,
  26539. 'endash': 556,
  26540. 'dagger': 556,
  26541. 'daggerdbl': 556,
  26542. 'periodcentered': 278,
  26543. 'paragraph': 556,
  26544. 'bullet': 350,
  26545. 'quotesinglbase': 278,
  26546. 'quotedblbase': 500,
  26547. 'quotedblright': 500,
  26548. 'guillemotright': 556,
  26549. 'ellipsis': 1000,
  26550. 'perthousand': 1000,
  26551. 'questiondown': 611,
  26552. 'grave': 333,
  26553. 'acute': 333,
  26554. 'circumflex': 333,
  26555. 'tilde': 333,
  26556. 'macron': 333,
  26557. 'breve': 333,
  26558. 'dotaccent': 333,
  26559. 'dieresis': 333,
  26560. 'ring': 333,
  26561. 'cedilla': 333,
  26562. 'hungarumlaut': 333,
  26563. 'ogonek': 333,
  26564. 'caron': 333,
  26565. 'emdash': 1000,
  26566. 'AE': 1000,
  26567. 'ordfeminine': 370,
  26568. 'Lslash': 611,
  26569. 'Oslash': 778,
  26570. 'OE': 1000,
  26571. 'ordmasculine': 365,
  26572. 'ae': 889,
  26573. 'dotlessi': 278,
  26574. 'lslash': 278,
  26575. 'oslash': 611,
  26576. 'oe': 944,
  26577. 'germandbls': 611,
  26578. 'Idieresis': 278,
  26579. 'eacute': 556,
  26580. 'abreve': 556,
  26581. 'uhungarumlaut': 611,
  26582. 'ecaron': 556,
  26583. 'Ydieresis': 667,
  26584. 'divide': 584,
  26585. 'Yacute': 667,
  26586. 'Acircumflex': 722,
  26587. 'aacute': 556,
  26588. 'Ucircumflex': 722,
  26589. 'yacute': 556,
  26590. 'scommaaccent': 556,
  26591. 'ecircumflex': 556,
  26592. 'Uring': 722,
  26593. 'Udieresis': 722,
  26594. 'aogonek': 556,
  26595. 'Uacute': 722,
  26596. 'uogonek': 611,
  26597. 'Edieresis': 667,
  26598. 'Dcroat': 722,
  26599. 'commaaccent': 250,
  26600. 'copyright': 737,
  26601. 'Emacron': 667,
  26602. 'ccaron': 556,
  26603. 'aring': 556,
  26604. 'Ncommaaccent': 722,
  26605. 'lacute': 278,
  26606. 'agrave': 556,
  26607. 'Tcommaaccent': 611,
  26608. 'Cacute': 722,
  26609. 'atilde': 556,
  26610. 'Edotaccent': 667,
  26611. 'scaron': 556,
  26612. 'scedilla': 556,
  26613. 'iacute': 278,
  26614. 'lozenge': 494,
  26615. 'Rcaron': 722,
  26616. 'Gcommaaccent': 778,
  26617. 'ucircumflex': 611,
  26618. 'acircumflex': 556,
  26619. 'Amacron': 722,
  26620. 'rcaron': 389,
  26621. 'ccedilla': 556,
  26622. 'Zdotaccent': 611,
  26623. 'Thorn': 667,
  26624. 'Omacron': 778,
  26625. 'Racute': 722,
  26626. 'Sacute': 667,
  26627. 'dcaron': 743,
  26628. 'Umacron': 722,
  26629. 'uring': 611,
  26630. 'threesuperior': 333,
  26631. 'Ograve': 778,
  26632. 'Agrave': 722,
  26633. 'Abreve': 722,
  26634. 'multiply': 584,
  26635. 'uacute': 611,
  26636. 'Tcaron': 611,
  26637. 'partialdiff': 494,
  26638. 'ydieresis': 556,
  26639. 'Nacute': 722,
  26640. 'icircumflex': 278,
  26641. 'Ecircumflex': 667,
  26642. 'adieresis': 556,
  26643. 'edieresis': 556,
  26644. 'cacute': 556,
  26645. 'nacute': 611,
  26646. 'umacron': 611,
  26647. 'Ncaron': 722,
  26648. 'Iacute': 278,
  26649. 'plusminus': 584,
  26650. 'brokenbar': 280,
  26651. 'registered': 737,
  26652. 'Gbreve': 778,
  26653. 'Idotaccent': 278,
  26654. 'summation': 600,
  26655. 'Egrave': 667,
  26656. 'racute': 389,
  26657. 'omacron': 611,
  26658. 'Zacute': 611,
  26659. 'Zcaron': 611,
  26660. 'greaterequal': 549,
  26661. 'Eth': 722,
  26662. 'Ccedilla': 722,
  26663. 'lcommaaccent': 278,
  26664. 'tcaron': 389,
  26665. 'eogonek': 556,
  26666. 'Uogonek': 722,
  26667. 'Aacute': 722,
  26668. 'Adieresis': 722,
  26669. 'egrave': 556,
  26670. 'zacute': 500,
  26671. 'iogonek': 278,
  26672. 'Oacute': 778,
  26673. 'oacute': 611,
  26674. 'amacron': 556,
  26675. 'sacute': 556,
  26676. 'idieresis': 278,
  26677. 'Ocircumflex': 778,
  26678. 'Ugrave': 722,
  26679. 'Delta': 612,
  26680. 'thorn': 611,
  26681. 'twosuperior': 333,
  26682. 'Odieresis': 778,
  26683. 'mu': 611,
  26684. 'igrave': 278,
  26685. 'ohungarumlaut': 611,
  26686. 'Eogonek': 667,
  26687. 'dcroat': 611,
  26688. 'threequarters': 834,
  26689. 'Scedilla': 667,
  26690. 'lcaron': 400,
  26691. 'Kcommaaccent': 722,
  26692. 'Lacute': 611,
  26693. 'trademark': 1000,
  26694. 'edotaccent': 556,
  26695. 'Igrave': 278,
  26696. 'Imacron': 278,
  26697. 'Lcaron': 611,
  26698. 'onehalf': 834,
  26699. 'lessequal': 549,
  26700. 'ocircumflex': 611,
  26701. 'ntilde': 611,
  26702. 'Uhungarumlaut': 722,
  26703. 'Eacute': 667,
  26704. 'emacron': 556,
  26705. 'gbreve': 611,
  26706. 'onequarter': 834,
  26707. 'Scaron': 667,
  26708. 'Scommaaccent': 667,
  26709. 'Ohungarumlaut': 778,
  26710. 'degree': 400,
  26711. 'ograve': 611,
  26712. 'Ccaron': 722,
  26713. 'ugrave': 611,
  26714. 'radical': 549,
  26715. 'Dcaron': 722,
  26716. 'rcommaaccent': 389,
  26717. 'Ntilde': 722,
  26718. 'otilde': 611,
  26719. 'Rcommaaccent': 722,
  26720. 'Lcommaaccent': 611,
  26721. 'Atilde': 722,
  26722. 'Aogonek': 722,
  26723. 'Aring': 722,
  26724. 'Otilde': 778,
  26725. 'zdotaccent': 500,
  26726. 'Ecaron': 667,
  26727. 'Iogonek': 278,
  26728. 'kcommaaccent': 556,
  26729. 'minus': 584,
  26730. 'Icircumflex': 278,
  26731. 'ncaron': 611,
  26732. 'tcommaaccent': 333,
  26733. 'logicalnot': 584,
  26734. 'odieresis': 611,
  26735. 'udieresis': 611,
  26736. 'notequal': 549,
  26737. 'gcommaaccent': 611,
  26738. 'eth': 611,
  26739. 'zcaron': 500,
  26740. 'ncommaaccent': 611,
  26741. 'onesuperior': 333,
  26742. 'imacron': 278,
  26743. 'Euro': 556
  26744. },
  26745. 'Helvetica-Oblique' : {
  26746. 'space': 278,
  26747. 'exclam': 278,
  26748. 'quotedbl': 355,
  26749. 'numbersign': 556,
  26750. 'dollar': 556,
  26751. 'percent': 889,
  26752. 'ampersand': 667,
  26753. 'quoteright': 222,
  26754. 'parenleft': 333,
  26755. 'parenright': 333,
  26756. 'asterisk': 389,
  26757. 'plus': 584,
  26758. 'comma': 278,
  26759. 'hyphen': 333,
  26760. 'period': 278,
  26761. 'slash': 278,
  26762. 'zero': 556,
  26763. 'one': 556,
  26764. 'two': 556,
  26765. 'three': 556,
  26766. 'four': 556,
  26767. 'five': 556,
  26768. 'six': 556,
  26769. 'seven': 556,
  26770. 'eight': 556,
  26771. 'nine': 556,
  26772. 'colon': 278,
  26773. 'semicolon': 278,
  26774. 'less': 584,
  26775. 'equal': 584,
  26776. 'greater': 584,
  26777. 'question': 556,
  26778. 'at': 1015,
  26779. 'A': 667,
  26780. 'B': 667,
  26781. 'C': 722,
  26782. 'D': 722,
  26783. 'E': 667,
  26784. 'F': 611,
  26785. 'G': 778,
  26786. 'H': 722,
  26787. 'I': 278,
  26788. 'J': 500,
  26789. 'K': 667,
  26790. 'L': 556,
  26791. 'M': 833,
  26792. 'N': 722,
  26793. 'O': 778,
  26794. 'P': 667,
  26795. 'Q': 778,
  26796. 'R': 722,
  26797. 'S': 667,
  26798. 'T': 611,
  26799. 'U': 722,
  26800. 'V': 667,
  26801. 'W': 944,
  26802. 'X': 667,
  26803. 'Y': 667,
  26804. 'Z': 611,
  26805. 'bracketleft': 278,
  26806. 'backslash': 278,
  26807. 'bracketright': 278,
  26808. 'asciicircum': 469,
  26809. 'underscore': 556,
  26810. 'quoteleft': 222,
  26811. 'a': 556,
  26812. 'b': 556,
  26813. 'c': 500,
  26814. 'd': 556,
  26815. 'e': 556,
  26816. 'f': 278,
  26817. 'g': 556,
  26818. 'h': 556,
  26819. 'i': 222,
  26820. 'j': 222,
  26821. 'k': 500,
  26822. 'l': 222,
  26823. 'm': 833,
  26824. 'n': 556,
  26825. 'o': 556,
  26826. 'p': 556,
  26827. 'q': 556,
  26828. 'r': 333,
  26829. 's': 500,
  26830. 't': 278,
  26831. 'u': 556,
  26832. 'v': 500,
  26833. 'w': 722,
  26834. 'x': 500,
  26835. 'y': 500,
  26836. 'z': 500,
  26837. 'braceleft': 334,
  26838. 'bar': 260,
  26839. 'braceright': 334,
  26840. 'asciitilde': 584,
  26841. 'exclamdown': 333,
  26842. 'cent': 556,
  26843. 'sterling': 556,
  26844. 'fraction': 167,
  26845. 'yen': 556,
  26846. 'florin': 556,
  26847. 'section': 556,
  26848. 'currency': 556,
  26849. 'quotesingle': 191,
  26850. 'quotedblleft': 333,
  26851. 'guillemotleft': 556,
  26852. 'guilsinglleft': 333,
  26853. 'guilsinglright': 333,
  26854. 'fi': 500,
  26855. 'fl': 500,
  26856. 'endash': 556,
  26857. 'dagger': 556,
  26858. 'daggerdbl': 556,
  26859. 'periodcentered': 278,
  26860. 'paragraph': 537,
  26861. 'bullet': 350,
  26862. 'quotesinglbase': 222,
  26863. 'quotedblbase': 333,
  26864. 'quotedblright': 333,
  26865. 'guillemotright': 556,
  26866. 'ellipsis': 1000,
  26867. 'perthousand': 1000,
  26868. 'questiondown': 611,
  26869. 'grave': 333,
  26870. 'acute': 333,
  26871. 'circumflex': 333,
  26872. 'tilde': 333,
  26873. 'macron': 333,
  26874. 'breve': 333,
  26875. 'dotaccent': 333,
  26876. 'dieresis': 333,
  26877. 'ring': 333,
  26878. 'cedilla': 333,
  26879. 'hungarumlaut': 333,
  26880. 'ogonek': 333,
  26881. 'caron': 333,
  26882. 'emdash': 1000,
  26883. 'AE': 1000,
  26884. 'ordfeminine': 370,
  26885. 'Lslash': 556,
  26886. 'Oslash': 778,
  26887. 'OE': 1000,
  26888. 'ordmasculine': 365,
  26889. 'ae': 889,
  26890. 'dotlessi': 278,
  26891. 'lslash': 222,
  26892. 'oslash': 611,
  26893. 'oe': 944,
  26894. 'germandbls': 611,
  26895. 'Idieresis': 278,
  26896. 'eacute': 556,
  26897. 'abreve': 556,
  26898. 'uhungarumlaut': 556,
  26899. 'ecaron': 556,
  26900. 'Ydieresis': 667,
  26901. 'divide': 584,
  26902. 'Yacute': 667,
  26903. 'Acircumflex': 667,
  26904. 'aacute': 556,
  26905. 'Ucircumflex': 722,
  26906. 'yacute': 500,
  26907. 'scommaaccent': 500,
  26908. 'ecircumflex': 556,
  26909. 'Uring': 722,
  26910. 'Udieresis': 722,
  26911. 'aogonek': 556,
  26912. 'Uacute': 722,
  26913. 'uogonek': 556,
  26914. 'Edieresis': 667,
  26915. 'Dcroat': 722,
  26916. 'commaaccent': 250,
  26917. 'copyright': 737,
  26918. 'Emacron': 667,
  26919. 'ccaron': 500,
  26920. 'aring': 556,
  26921. 'Ncommaaccent': 722,
  26922. 'lacute': 222,
  26923. 'agrave': 556,
  26924. 'Tcommaaccent': 611,
  26925. 'Cacute': 722,
  26926. 'atilde': 556,
  26927. 'Edotaccent': 667,
  26928. 'scaron': 500,
  26929. 'scedilla': 500,
  26930. 'iacute': 278,
  26931. 'lozenge': 471,
  26932. 'Rcaron': 722,
  26933. 'Gcommaaccent': 778,
  26934. 'ucircumflex': 556,
  26935. 'acircumflex': 556,
  26936. 'Amacron': 667,
  26937. 'rcaron': 333,
  26938. 'ccedilla': 500,
  26939. 'Zdotaccent': 611,
  26940. 'Thorn': 667,
  26941. 'Omacron': 778,
  26942. 'Racute': 722,
  26943. 'Sacute': 667,
  26944. 'dcaron': 643,
  26945. 'Umacron': 722,
  26946. 'uring': 556,
  26947. 'threesuperior': 333,
  26948. 'Ograve': 778,
  26949. 'Agrave': 667,
  26950. 'Abreve': 667,
  26951. 'multiply': 584,
  26952. 'uacute': 556,
  26953. 'Tcaron': 611,
  26954. 'partialdiff': 476,
  26955. 'ydieresis': 500,
  26956. 'Nacute': 722,
  26957. 'icircumflex': 278,
  26958. 'Ecircumflex': 667,
  26959. 'adieresis': 556,
  26960. 'edieresis': 556,
  26961. 'cacute': 500,
  26962. 'nacute': 556,
  26963. 'umacron': 556,
  26964. 'Ncaron': 722,
  26965. 'Iacute': 278,
  26966. 'plusminus': 584,
  26967. 'brokenbar': 260,
  26968. 'registered': 737,
  26969. 'Gbreve': 778,
  26970. 'Idotaccent': 278,
  26971. 'summation': 600,
  26972. 'Egrave': 667,
  26973. 'racute': 333,
  26974. 'omacron': 556,
  26975. 'Zacute': 611,
  26976. 'Zcaron': 611,
  26977. 'greaterequal': 549,
  26978. 'Eth': 722,
  26979. 'Ccedilla': 722,
  26980. 'lcommaaccent': 222,
  26981. 'tcaron': 317,
  26982. 'eogonek': 556,
  26983. 'Uogonek': 722,
  26984. 'Aacute': 667,
  26985. 'Adieresis': 667,
  26986. 'egrave': 556,
  26987. 'zacute': 500,
  26988. 'iogonek': 222,
  26989. 'Oacute': 778,
  26990. 'oacute': 556,
  26991. 'amacron': 556,
  26992. 'sacute': 500,
  26993. 'idieresis': 278,
  26994. 'Ocircumflex': 778,
  26995. 'Ugrave': 722,
  26996. 'Delta': 612,
  26997. 'thorn': 556,
  26998. 'twosuperior': 333,
  26999. 'Odieresis': 778,
  27000. 'mu': 556,
  27001. 'igrave': 278,
  27002. 'ohungarumlaut': 556,
  27003. 'Eogonek': 667,
  27004. 'dcroat': 556,
  27005. 'threequarters': 834,
  27006. 'Scedilla': 667,
  27007. 'lcaron': 299,
  27008. 'Kcommaaccent': 667,
  27009. 'Lacute': 556,
  27010. 'trademark': 1000,
  27011. 'edotaccent': 556,
  27012. 'Igrave': 278,
  27013. 'Imacron': 278,
  27014. 'Lcaron': 556,
  27015. 'onehalf': 834,
  27016. 'lessequal': 549,
  27017. 'ocircumflex': 556,
  27018. 'ntilde': 556,
  27019. 'Uhungarumlaut': 722,
  27020. 'Eacute': 667,
  27021. 'emacron': 556,
  27022. 'gbreve': 556,
  27023. 'onequarter': 834,
  27024. 'Scaron': 667,
  27025. 'Scommaaccent': 667,
  27026. 'Ohungarumlaut': 778,
  27027. 'degree': 400,
  27028. 'ograve': 556,
  27029. 'Ccaron': 722,
  27030. 'ugrave': 556,
  27031. 'radical': 453,
  27032. 'Dcaron': 722,
  27033. 'rcommaaccent': 333,
  27034. 'Ntilde': 722,
  27035. 'otilde': 556,
  27036. 'Rcommaaccent': 722,
  27037. 'Lcommaaccent': 556,
  27038. 'Atilde': 667,
  27039. 'Aogonek': 667,
  27040. 'Aring': 667,
  27041. 'Otilde': 778,
  27042. 'zdotaccent': 500,
  27043. 'Ecaron': 667,
  27044. 'Iogonek': 278,
  27045. 'kcommaaccent': 500,
  27046. 'minus': 584,
  27047. 'Icircumflex': 278,
  27048. 'ncaron': 556,
  27049. 'tcommaaccent': 278,
  27050. 'logicalnot': 584,
  27051. 'odieresis': 556,
  27052. 'udieresis': 556,
  27053. 'notequal': 549,
  27054. 'gcommaaccent': 556,
  27055. 'eth': 556,
  27056. 'zcaron': 500,
  27057. 'ncommaaccent': 556,
  27058. 'onesuperior': 333,
  27059. 'imacron': 278,
  27060. 'Euro': 556
  27061. },
  27062. 'Symbol': {
  27063. 'space': 250,
  27064. 'exclam': 333,
  27065. 'universal': 713,
  27066. 'numbersign': 500,
  27067. 'existential': 549,
  27068. 'percent': 833,
  27069. 'ampersand': 778,
  27070. 'suchthat': 439,
  27071. 'parenleft': 333,
  27072. 'parenright': 333,
  27073. 'asteriskmath': 500,
  27074. 'plus': 549,
  27075. 'comma': 250,
  27076. 'minus': 549,
  27077. 'period': 250,
  27078. 'slash': 278,
  27079. 'zero': 500,
  27080. 'one': 500,
  27081. 'two': 500,
  27082. 'three': 500,
  27083. 'four': 500,
  27084. 'five': 500,
  27085. 'six': 500,
  27086. 'seven': 500,
  27087. 'eight': 500,
  27088. 'nine': 500,
  27089. 'colon': 278,
  27090. 'semicolon': 278,
  27091. 'less': 549,
  27092. 'equal': 549,
  27093. 'greater': 549,
  27094. 'question': 444,
  27095. 'congruent': 549,
  27096. 'Alpha': 722,
  27097. 'Beta': 667,
  27098. 'Chi': 722,
  27099. 'Delta': 612,
  27100. 'Epsilon': 611,
  27101. 'Phi': 763,
  27102. 'Gamma': 603,
  27103. 'Eta': 722,
  27104. 'Iota': 333,
  27105. 'theta1': 631,
  27106. 'Kappa': 722,
  27107. 'Lambda': 686,
  27108. 'Mu': 889,
  27109. 'Nu': 722,
  27110. 'Omicron': 722,
  27111. 'Pi': 768,
  27112. 'Theta': 741,
  27113. 'Rho': 556,
  27114. 'Sigma': 592,
  27115. 'Tau': 611,
  27116. 'Upsilon': 690,
  27117. 'sigma1': 439,
  27118. 'Omega': 768,
  27119. 'Xi': 645,
  27120. 'Psi': 795,
  27121. 'Zeta': 611,
  27122. 'bracketleft': 333,
  27123. 'therefore': 863,
  27124. 'bracketright': 333,
  27125. 'perpendicular': 658,
  27126. 'underscore': 500,
  27127. 'radicalex': 500,
  27128. 'alpha': 631,
  27129. 'beta': 549,
  27130. 'chi': 549,
  27131. 'delta': 494,
  27132. 'epsilon': 439,
  27133. 'phi': 521,
  27134. 'gamma': 411,
  27135. 'eta': 603,
  27136. 'iota': 329,
  27137. 'phi1': 603,
  27138. 'kappa': 549,
  27139. 'lambda': 549,
  27140. 'mu': 576,
  27141. 'nu': 521,
  27142. 'omicron': 549,
  27143. 'pi': 549,
  27144. 'theta': 521,
  27145. 'rho': 549,
  27146. 'sigma': 603,
  27147. 'tau': 439,
  27148. 'upsilon': 576,
  27149. 'omega1': 713,
  27150. 'omega': 686,
  27151. 'xi': 493,
  27152. 'psi': 686,
  27153. 'zeta': 494,
  27154. 'braceleft': 480,
  27155. 'bar': 200,
  27156. 'braceright': 480,
  27157. 'similar': 549,
  27158. 'Euro': 750,
  27159. 'Upsilon1': 620,
  27160. 'minute': 247,
  27161. 'lessequal': 549,
  27162. 'fraction': 167,
  27163. 'infinity': 713,
  27164. 'florin': 500,
  27165. 'club': 753,
  27166. 'diamond': 753,
  27167. 'heart': 753,
  27168. 'spade': 753,
  27169. 'arrowboth': 1042,
  27170. 'arrowleft': 987,
  27171. 'arrowup': 603,
  27172. 'arrowright': 987,
  27173. 'arrowdown': 603,
  27174. 'degree': 400,
  27175. 'plusminus': 549,
  27176. 'second': 411,
  27177. 'greaterequal': 549,
  27178. 'multiply': 549,
  27179. 'proportional': 713,
  27180. 'partialdiff': 494,
  27181. 'bullet': 460,
  27182. 'divide': 549,
  27183. 'notequal': 549,
  27184. 'equivalence': 549,
  27185. 'approxequal': 549,
  27186. 'ellipsis': 1000,
  27187. 'arrowvertex': 603,
  27188. 'arrowhorizex': 1000,
  27189. 'carriagereturn': 658,
  27190. 'aleph': 823,
  27191. 'Ifraktur': 686,
  27192. 'Rfraktur': 795,
  27193. 'weierstrass': 987,
  27194. 'circlemultiply': 768,
  27195. 'circleplus': 768,
  27196. 'emptyset': 823,
  27197. 'intersection': 768,
  27198. 'union': 768,
  27199. 'propersuperset': 713,
  27200. 'reflexsuperset': 713,
  27201. 'notsubset': 713,
  27202. 'propersubset': 713,
  27203. 'reflexsubset': 713,
  27204. 'element': 713,
  27205. 'notelement': 713,
  27206. 'angle': 768,
  27207. 'gradient': 713,
  27208. 'registerserif': 790,
  27209. 'copyrightserif': 790,
  27210. 'trademarkserif': 890,
  27211. 'product': 823,
  27212. 'radical': 549,
  27213. 'dotmath': 250,
  27214. 'logicalnot': 713,
  27215. 'logicaland': 603,
  27216. 'logicalor': 603,
  27217. 'arrowdblboth': 1042,
  27218. 'arrowdblleft': 987,
  27219. 'arrowdblup': 603,
  27220. 'arrowdblright': 987,
  27221. 'arrowdbldown': 603,
  27222. 'lozenge': 494,
  27223. 'angleleft': 329,
  27224. 'registersans': 790,
  27225. 'copyrightsans': 790,
  27226. 'trademarksans': 786,
  27227. 'summation': 713,
  27228. 'parenlefttp': 384,
  27229. 'parenleftex': 384,
  27230. 'parenleftbt': 384,
  27231. 'bracketlefttp': 384,
  27232. 'bracketleftex': 384,
  27233. 'bracketleftbt': 384,
  27234. 'bracelefttp': 494,
  27235. 'braceleftmid': 494,
  27236. 'braceleftbt': 494,
  27237. 'braceex': 494,
  27238. 'angleright': 329,
  27239. 'integral': 274,
  27240. 'integraltp': 686,
  27241. 'integralex': 686,
  27242. 'integralbt': 686,
  27243. 'parenrighttp': 384,
  27244. 'parenrightex': 384,
  27245. 'parenrightbt': 384,
  27246. 'bracketrighttp': 384,
  27247. 'bracketrightex': 384,
  27248. 'bracketrightbt': 384,
  27249. 'bracerighttp': 494,
  27250. 'bracerightmid': 494,
  27251. 'bracerightbt': 494,
  27252. 'apple': 790
  27253. },
  27254. 'Times-Roman': {
  27255. 'space': 250,
  27256. 'exclam': 333,
  27257. 'quotedbl': 408,
  27258. 'numbersign': 500,
  27259. 'dollar': 500,
  27260. 'percent': 833,
  27261. 'ampersand': 778,
  27262. 'quoteright': 333,
  27263. 'parenleft': 333,
  27264. 'parenright': 333,
  27265. 'asterisk': 500,
  27266. 'plus': 564,
  27267. 'comma': 250,
  27268. 'hyphen': 333,
  27269. 'period': 250,
  27270. 'slash': 278,
  27271. 'zero': 500,
  27272. 'one': 500,
  27273. 'two': 500,
  27274. 'three': 500,
  27275. 'four': 500,
  27276. 'five': 500,
  27277. 'six': 500,
  27278. 'seven': 500,
  27279. 'eight': 500,
  27280. 'nine': 500,
  27281. 'colon': 278,
  27282. 'semicolon': 278,
  27283. 'less': 564,
  27284. 'equal': 564,
  27285. 'greater': 564,
  27286. 'question': 444,
  27287. 'at': 921,
  27288. 'A': 722,
  27289. 'B': 667,
  27290. 'C': 667,
  27291. 'D': 722,
  27292. 'E': 611,
  27293. 'F': 556,
  27294. 'G': 722,
  27295. 'H': 722,
  27296. 'I': 333,
  27297. 'J': 389,
  27298. 'K': 722,
  27299. 'L': 611,
  27300. 'M': 889,
  27301. 'N': 722,
  27302. 'O': 722,
  27303. 'P': 556,
  27304. 'Q': 722,
  27305. 'R': 667,
  27306. 'S': 556,
  27307. 'T': 611,
  27308. 'U': 722,
  27309. 'V': 722,
  27310. 'W': 944,
  27311. 'X': 722,
  27312. 'Y': 722,
  27313. 'Z': 611,
  27314. 'bracketleft': 333,
  27315. 'backslash': 278,
  27316. 'bracketright': 333,
  27317. 'asciicircum': 469,
  27318. 'underscore': 500,
  27319. 'quoteleft': 333,
  27320. 'a': 444,
  27321. 'b': 500,
  27322. 'c': 444,
  27323. 'd': 500,
  27324. 'e': 444,
  27325. 'f': 333,
  27326. 'g': 500,
  27327. 'h': 500,
  27328. 'i': 278,
  27329. 'j': 278,
  27330. 'k': 500,
  27331. 'l': 278,
  27332. 'm': 778,
  27333. 'n': 500,
  27334. 'o': 500,
  27335. 'p': 500,
  27336. 'q': 500,
  27337. 'r': 333,
  27338. 's': 389,
  27339. 't': 278,
  27340. 'u': 500,
  27341. 'v': 500,
  27342. 'w': 722,
  27343. 'x': 500,
  27344. 'y': 500,
  27345. 'z': 444,
  27346. 'braceleft': 480,
  27347. 'bar': 200,
  27348. 'braceright': 480,
  27349. 'asciitilde': 541,
  27350. 'exclamdown': 333,
  27351. 'cent': 500,
  27352. 'sterling': 500,
  27353. 'fraction': 167,
  27354. 'yen': 500,
  27355. 'florin': 500,
  27356. 'section': 500,
  27357. 'currency': 500,
  27358. 'quotesingle': 180,
  27359. 'quotedblleft': 444,
  27360. 'guillemotleft': 500,
  27361. 'guilsinglleft': 333,
  27362. 'guilsinglright': 333,
  27363. 'fi': 556,
  27364. 'fl': 556,
  27365. 'endash': 500,
  27366. 'dagger': 500,
  27367. 'daggerdbl': 500,
  27368. 'periodcentered': 250,
  27369. 'paragraph': 453,
  27370. 'bullet': 350,
  27371. 'quotesinglbase': 333,
  27372. 'quotedblbase': 444,
  27373. 'quotedblright': 444,
  27374. 'guillemotright': 500,
  27375. 'ellipsis': 1000,
  27376. 'perthousand': 1000,
  27377. 'questiondown': 444,
  27378. 'grave': 333,
  27379. 'acute': 333,
  27380. 'circumflex': 333,
  27381. 'tilde': 333,
  27382. 'macron': 333,
  27383. 'breve': 333,
  27384. 'dotaccent': 333,
  27385. 'dieresis': 333,
  27386. 'ring': 333,
  27387. 'cedilla': 333,
  27388. 'hungarumlaut': 333,
  27389. 'ogonek': 333,
  27390. 'caron': 333,
  27391. 'emdash': 1000,
  27392. 'AE': 889,
  27393. 'ordfeminine': 276,
  27394. 'Lslash': 611,
  27395. 'Oslash': 722,
  27396. 'OE': 889,
  27397. 'ordmasculine': 310,
  27398. 'ae': 667,
  27399. 'dotlessi': 278,
  27400. 'lslash': 278,
  27401. 'oslash': 500,
  27402. 'oe': 722,
  27403. 'germandbls': 500,
  27404. 'Idieresis': 333,
  27405. 'eacute': 444,
  27406. 'abreve': 444,
  27407. 'uhungarumlaut': 500,
  27408. 'ecaron': 444,
  27409. 'Ydieresis': 722,
  27410. 'divide': 564,
  27411. 'Yacute': 722,
  27412. 'Acircumflex': 722,
  27413. 'aacute': 444,
  27414. 'Ucircumflex': 722,
  27415. 'yacute': 500,
  27416. 'scommaaccent': 389,
  27417. 'ecircumflex': 444,
  27418. 'Uring': 722,
  27419. 'Udieresis': 722,
  27420. 'aogonek': 444,
  27421. 'Uacute': 722,
  27422. 'uogonek': 500,
  27423. 'Edieresis': 611,
  27424. 'Dcroat': 722,
  27425. 'commaaccent': 250,
  27426. 'copyright': 760,
  27427. 'Emacron': 611,
  27428. 'ccaron': 444,
  27429. 'aring': 444,
  27430. 'Ncommaaccent': 722,
  27431. 'lacute': 278,
  27432. 'agrave': 444,
  27433. 'Tcommaaccent': 611,
  27434. 'Cacute': 667,
  27435. 'atilde': 444,
  27436. 'Edotaccent': 611,
  27437. 'scaron': 389,
  27438. 'scedilla': 389,
  27439. 'iacute': 278,
  27440. 'lozenge': 471,
  27441. 'Rcaron': 667,
  27442. 'Gcommaaccent': 722,
  27443. 'ucircumflex': 500,
  27444. 'acircumflex': 444,
  27445. 'Amacron': 722,
  27446. 'rcaron': 333,
  27447. 'ccedilla': 444,
  27448. 'Zdotaccent': 611,
  27449. 'Thorn': 556,
  27450. 'Omacron': 722,
  27451. 'Racute': 667,
  27452. 'Sacute': 556,
  27453. 'dcaron': 588,
  27454. 'Umacron': 722,
  27455. 'uring': 500,
  27456. 'threesuperior': 300,
  27457. 'Ograve': 722,
  27458. 'Agrave': 722,
  27459. 'Abreve': 722,
  27460. 'multiply': 564,
  27461. 'uacute': 500,
  27462. 'Tcaron': 611,
  27463. 'partialdiff': 476,
  27464. 'ydieresis': 500,
  27465. 'Nacute': 722,
  27466. 'icircumflex': 278,
  27467. 'Ecircumflex': 611,
  27468. 'adieresis': 444,
  27469. 'edieresis': 444,
  27470. 'cacute': 444,
  27471. 'nacute': 500,
  27472. 'umacron': 500,
  27473. 'Ncaron': 722,
  27474. 'Iacute': 333,
  27475. 'plusminus': 564,
  27476. 'brokenbar': 200,
  27477. 'registered': 760,
  27478. 'Gbreve': 722,
  27479. 'Idotaccent': 333,
  27480. 'summation': 600,
  27481. 'Egrave': 611,
  27482. 'racute': 333,
  27483. 'omacron': 500,
  27484. 'Zacute': 611,
  27485. 'Zcaron': 611,
  27486. 'greaterequal': 549,
  27487. 'Eth': 722,
  27488. 'Ccedilla': 667,
  27489. 'lcommaaccent': 278,
  27490. 'tcaron': 326,
  27491. 'eogonek': 444,
  27492. 'Uogonek': 722,
  27493. 'Aacute': 722,
  27494. 'Adieresis': 722,
  27495. 'egrave': 444,
  27496. 'zacute': 444,
  27497. 'iogonek': 278,
  27498. 'Oacute': 722,
  27499. 'oacute': 500,
  27500. 'amacron': 444,
  27501. 'sacute': 389,
  27502. 'idieresis': 278,
  27503. 'Ocircumflex': 722,
  27504. 'Ugrave': 722,
  27505. 'Delta': 612,
  27506. 'thorn': 500,
  27507. 'twosuperior': 300,
  27508. 'Odieresis': 722,
  27509. 'mu': 500,
  27510. 'igrave': 278,
  27511. 'ohungarumlaut': 500,
  27512. 'Eogonek': 611,
  27513. 'dcroat': 500,
  27514. 'threequarters': 750,
  27515. 'Scedilla': 556,
  27516. 'lcaron': 344,
  27517. 'Kcommaaccent': 722,
  27518. 'Lacute': 611,
  27519. 'trademark': 980,
  27520. 'edotaccent': 444,
  27521. 'Igrave': 333,
  27522. 'Imacron': 333,
  27523. 'Lcaron': 611,
  27524. 'onehalf': 750,
  27525. 'lessequal': 549,
  27526. 'ocircumflex': 500,
  27527. 'ntilde': 500,
  27528. 'Uhungarumlaut': 722,
  27529. 'Eacute': 611,
  27530. 'emacron': 444,
  27531. 'gbreve': 500,
  27532. 'onequarter': 750,
  27533. 'Scaron': 556,
  27534. 'Scommaaccent': 556,
  27535. 'Ohungarumlaut': 722,
  27536. 'degree': 400,
  27537. 'ograve': 500,
  27538. 'Ccaron': 667,
  27539. 'ugrave': 500,
  27540. 'radical': 453,
  27541. 'Dcaron': 722,
  27542. 'rcommaaccent': 333,
  27543. 'Ntilde': 722,
  27544. 'otilde': 500,
  27545. 'Rcommaaccent': 667,
  27546. 'Lcommaaccent': 611,
  27547. 'Atilde': 722,
  27548. 'Aogonek': 722,
  27549. 'Aring': 722,
  27550. 'Otilde': 722,
  27551. 'zdotaccent': 444,
  27552. 'Ecaron': 611,
  27553. 'Iogonek': 333,
  27554. 'kcommaaccent': 500,
  27555. 'minus': 564,
  27556. 'Icircumflex': 333,
  27557. 'ncaron': 500,
  27558. 'tcommaaccent': 278,
  27559. 'logicalnot': 564,
  27560. 'odieresis': 500,
  27561. 'udieresis': 500,
  27562. 'notequal': 549,
  27563. 'gcommaaccent': 500,
  27564. 'eth': 500,
  27565. 'zcaron': 444,
  27566. 'ncommaaccent': 500,
  27567. 'onesuperior': 300,
  27568. 'imacron': 278,
  27569. 'Euro': 500
  27570. },
  27571. 'Times-Bold': {
  27572. 'space': 250,
  27573. 'exclam': 333,
  27574. 'quotedbl': 555,
  27575. 'numbersign': 500,
  27576. 'dollar': 500,
  27577. 'percent': 1000,
  27578. 'ampersand': 833,
  27579. 'quoteright': 333,
  27580. 'parenleft': 333,
  27581. 'parenright': 333,
  27582. 'asterisk': 500,
  27583. 'plus': 570,
  27584. 'comma': 250,
  27585. 'hyphen': 333,
  27586. 'period': 250,
  27587. 'slash': 278,
  27588. 'zero': 500,
  27589. 'one': 500,
  27590. 'two': 500,
  27591. 'three': 500,
  27592. 'four': 500,
  27593. 'five': 500,
  27594. 'six': 500,
  27595. 'seven': 500,
  27596. 'eight': 500,
  27597. 'nine': 500,
  27598. 'colon': 333,
  27599. 'semicolon': 333,
  27600. 'less': 570,
  27601. 'equal': 570,
  27602. 'greater': 570,
  27603. 'question': 500,
  27604. 'at': 930,
  27605. 'A': 722,
  27606. 'B': 667,
  27607. 'C': 722,
  27608. 'D': 722,
  27609. 'E': 667,
  27610. 'F': 611,
  27611. 'G': 778,
  27612. 'H': 778,
  27613. 'I': 389,
  27614. 'J': 500,
  27615. 'K': 778,
  27616. 'L': 667,
  27617. 'M': 944,
  27618. 'N': 722,
  27619. 'O': 778,
  27620. 'P': 611,
  27621. 'Q': 778,
  27622. 'R': 722,
  27623. 'S': 556,
  27624. 'T': 667,
  27625. 'U': 722,
  27626. 'V': 722,
  27627. 'W': 1000,
  27628. 'X': 722,
  27629. 'Y': 722,
  27630. 'Z': 667,
  27631. 'bracketleft': 333,
  27632. 'backslash': 278,
  27633. 'bracketright': 333,
  27634. 'asciicircum': 581,
  27635. 'underscore': 500,
  27636. 'quoteleft': 333,
  27637. 'a': 500,
  27638. 'b': 556,
  27639. 'c': 444,
  27640. 'd': 556,
  27641. 'e': 444,
  27642. 'f': 333,
  27643. 'g': 500,
  27644. 'h': 556,
  27645. 'i': 278,
  27646. 'j': 333,
  27647. 'k': 556,
  27648. 'l': 278,
  27649. 'm': 833,
  27650. 'n': 556,
  27651. 'o': 500,
  27652. 'p': 556,
  27653. 'q': 556,
  27654. 'r': 444,
  27655. 's': 389,
  27656. 't': 333,
  27657. 'u': 556,
  27658. 'v': 500,
  27659. 'w': 722,
  27660. 'x': 500,
  27661. 'y': 500,
  27662. 'z': 444,
  27663. 'braceleft': 394,
  27664. 'bar': 220,
  27665. 'braceright': 394,
  27666. 'asciitilde': 520,
  27667. 'exclamdown': 333,
  27668. 'cent': 500,
  27669. 'sterling': 500,
  27670. 'fraction': 167,
  27671. 'yen': 500,
  27672. 'florin': 500,
  27673. 'section': 500,
  27674. 'currency': 500,
  27675. 'quotesingle': 278,
  27676. 'quotedblleft': 500,
  27677. 'guillemotleft': 500,
  27678. 'guilsinglleft': 333,
  27679. 'guilsinglright': 333,
  27680. 'fi': 556,
  27681. 'fl': 556,
  27682. 'endash': 500,
  27683. 'dagger': 500,
  27684. 'daggerdbl': 500,
  27685. 'periodcentered': 250,
  27686. 'paragraph': 540,
  27687. 'bullet': 350,
  27688. 'quotesinglbase': 333,
  27689. 'quotedblbase': 500,
  27690. 'quotedblright': 500,
  27691. 'guillemotright': 500,
  27692. 'ellipsis': 1000,
  27693. 'perthousand': 1000,
  27694. 'questiondown': 500,
  27695. 'grave': 333,
  27696. 'acute': 333,
  27697. 'circumflex': 333,
  27698. 'tilde': 333,
  27699. 'macron': 333,
  27700. 'breve': 333,
  27701. 'dotaccent': 333,
  27702. 'dieresis': 333,
  27703. 'ring': 333,
  27704. 'cedilla': 333,
  27705. 'hungarumlaut': 333,
  27706. 'ogonek': 333,
  27707. 'caron': 333,
  27708. 'emdash': 1000,
  27709. 'AE': 1000,
  27710. 'ordfeminine': 300,
  27711. 'Lslash': 667,
  27712. 'Oslash': 778,
  27713. 'OE': 1000,
  27714. 'ordmasculine': 330,
  27715. 'ae': 722,
  27716. 'dotlessi': 278,
  27717. 'lslash': 278,
  27718. 'oslash': 500,
  27719. 'oe': 722,
  27720. 'germandbls': 556,
  27721. 'Idieresis': 389,
  27722. 'eacute': 444,
  27723. 'abreve': 500,
  27724. 'uhungarumlaut': 556,
  27725. 'ecaron': 444,
  27726. 'Ydieresis': 722,
  27727. 'divide': 570,
  27728. 'Yacute': 722,
  27729. 'Acircumflex': 722,
  27730. 'aacute': 500,
  27731. 'Ucircumflex': 722,
  27732. 'yacute': 500,
  27733. 'scommaaccent': 389,
  27734. 'ecircumflex': 444,
  27735. 'Uring': 722,
  27736. 'Udieresis': 722,
  27737. 'aogonek': 500,
  27738. 'Uacute': 722,
  27739. 'uogonek': 556,
  27740. 'Edieresis': 667,
  27741. 'Dcroat': 722,
  27742. 'commaaccent': 250,
  27743. 'copyright': 747,
  27744. 'Emacron': 667,
  27745. 'ccaron': 444,
  27746. 'aring': 500,
  27747. 'Ncommaaccent': 722,
  27748. 'lacute': 278,
  27749. 'agrave': 500,
  27750. 'Tcommaaccent': 667,
  27751. 'Cacute': 722,
  27752. 'atilde': 500,
  27753. 'Edotaccent': 667,
  27754. 'scaron': 389,
  27755. 'scedilla': 389,
  27756. 'iacute': 278,
  27757. 'lozenge': 494,
  27758. 'Rcaron': 722,
  27759. 'Gcommaaccent': 778,
  27760. 'ucircumflex': 556,
  27761. 'acircumflex': 500,
  27762. 'Amacron': 722,
  27763. 'rcaron': 444,
  27764. 'ccedilla': 444,
  27765. 'Zdotaccent': 667,
  27766. 'Thorn': 611,
  27767. 'Omacron': 778,
  27768. 'Racute': 722,
  27769. 'Sacute': 556,
  27770. 'dcaron': 672,
  27771. 'Umacron': 722,
  27772. 'uring': 556,
  27773. 'threesuperior': 300,
  27774. 'Ograve': 778,
  27775. 'Agrave': 722,
  27776. 'Abreve': 722,
  27777. 'multiply': 570,
  27778. 'uacute': 556,
  27779. 'Tcaron': 667,
  27780. 'partialdiff': 494,
  27781. 'ydieresis': 500,
  27782. 'Nacute': 722,
  27783. 'icircumflex': 278,
  27784. 'Ecircumflex': 667,
  27785. 'adieresis': 500,
  27786. 'edieresis': 444,
  27787. 'cacute': 444,
  27788. 'nacute': 556,
  27789. 'umacron': 556,
  27790. 'Ncaron': 722,
  27791. 'Iacute': 389,
  27792. 'plusminus': 570,
  27793. 'brokenbar': 220,
  27794. 'registered': 747,
  27795. 'Gbreve': 778,
  27796. 'Idotaccent': 389,
  27797. 'summation': 600,
  27798. 'Egrave': 667,
  27799. 'racute': 444,
  27800. 'omacron': 500,
  27801. 'Zacute': 667,
  27802. 'Zcaron': 667,
  27803. 'greaterequal': 549,
  27804. 'Eth': 722,
  27805. 'Ccedilla': 722,
  27806. 'lcommaaccent': 278,
  27807. 'tcaron': 416,
  27808. 'eogonek': 444,
  27809. 'Uogonek': 722,
  27810. 'Aacute': 722,
  27811. 'Adieresis': 722,
  27812. 'egrave': 444,
  27813. 'zacute': 444,
  27814. 'iogonek': 278,
  27815. 'Oacute': 778,
  27816. 'oacute': 500,
  27817. 'amacron': 500,
  27818. 'sacute': 389,
  27819. 'idieresis': 278,
  27820. 'Ocircumflex': 778,
  27821. 'Ugrave': 722,
  27822. 'Delta': 612,
  27823. 'thorn': 556,
  27824. 'twosuperior': 300,
  27825. 'Odieresis': 778,
  27826. 'mu': 556,
  27827. 'igrave': 278,
  27828. 'ohungarumlaut': 500,
  27829. 'Eogonek': 667,
  27830. 'dcroat': 556,
  27831. 'threequarters': 750,
  27832. 'Scedilla': 556,
  27833. 'lcaron': 394,
  27834. 'Kcommaaccent': 778,
  27835. 'Lacute': 667,
  27836. 'trademark': 1000,
  27837. 'edotaccent': 444,
  27838. 'Igrave': 389,
  27839. 'Imacron': 389,
  27840. 'Lcaron': 667,
  27841. 'onehalf': 750,
  27842. 'lessequal': 549,
  27843. 'ocircumflex': 500,
  27844. 'ntilde': 556,
  27845. 'Uhungarumlaut': 722,
  27846. 'Eacute': 667,
  27847. 'emacron': 444,
  27848. 'gbreve': 500,
  27849. 'onequarter': 750,
  27850. 'Scaron': 556,
  27851. 'Scommaaccent': 556,
  27852. 'Ohungarumlaut': 778,
  27853. 'degree': 400,
  27854. 'ograve': 500,
  27855. 'Ccaron': 722,
  27856. 'ugrave': 556,
  27857. 'radical': 549,
  27858. 'Dcaron': 722,
  27859. 'rcommaaccent': 444,
  27860. 'Ntilde': 722,
  27861. 'otilde': 500,
  27862. 'Rcommaaccent': 722,
  27863. 'Lcommaaccent': 667,
  27864. 'Atilde': 722,
  27865. 'Aogonek': 722,
  27866. 'Aring': 722,
  27867. 'Otilde': 778,
  27868. 'zdotaccent': 444,
  27869. 'Ecaron': 667,
  27870. 'Iogonek': 389,
  27871. 'kcommaaccent': 556,
  27872. 'minus': 570,
  27873. 'Icircumflex': 389,
  27874. 'ncaron': 556,
  27875. 'tcommaaccent': 333,
  27876. 'logicalnot': 570,
  27877. 'odieresis': 500,
  27878. 'udieresis': 556,
  27879. 'notequal': 549,
  27880. 'gcommaaccent': 500,
  27881. 'eth': 500,
  27882. 'zcaron': 444,
  27883. 'ncommaaccent': 556,
  27884. 'onesuperior': 300,
  27885. 'imacron': 278,
  27886. 'Euro': 500
  27887. },
  27888. 'Times-BoldItalic': {
  27889. 'space': 250,
  27890. 'exclam': 389,
  27891. 'quotedbl': 555,
  27892. 'numbersign': 500,
  27893. 'dollar': 500,
  27894. 'percent': 833,
  27895. 'ampersand': 778,
  27896. 'quoteright': 333,
  27897. 'parenleft': 333,
  27898. 'parenright': 333,
  27899. 'asterisk': 500,
  27900. 'plus': 570,
  27901. 'comma': 250,
  27902. 'hyphen': 333,
  27903. 'period': 250,
  27904. 'slash': 278,
  27905. 'zero': 500,
  27906. 'one': 500,
  27907. 'two': 500,
  27908. 'three': 500,
  27909. 'four': 500,
  27910. 'five': 500,
  27911. 'six': 500,
  27912. 'seven': 500,
  27913. 'eight': 500,
  27914. 'nine': 500,
  27915. 'colon': 333,
  27916. 'semicolon': 333,
  27917. 'less': 570,
  27918. 'equal': 570,
  27919. 'greater': 570,
  27920. 'question': 500,
  27921. 'at': 832,
  27922. 'A': 667,
  27923. 'B': 667,
  27924. 'C': 667,
  27925. 'D': 722,
  27926. 'E': 667,
  27927. 'F': 667,
  27928. 'G': 722,
  27929. 'H': 778,
  27930. 'I': 389,
  27931. 'J': 500,
  27932. 'K': 667,
  27933. 'L': 611,
  27934. 'M': 889,
  27935. 'N': 722,
  27936. 'O': 722,
  27937. 'P': 611,
  27938. 'Q': 722,
  27939. 'R': 667,
  27940. 'S': 556,
  27941. 'T': 611,
  27942. 'U': 722,
  27943. 'V': 667,
  27944. 'W': 889,
  27945. 'X': 667,
  27946. 'Y': 611,
  27947. 'Z': 611,
  27948. 'bracketleft': 333,
  27949. 'backslash': 278,
  27950. 'bracketright': 333,
  27951. 'asciicircum': 570,
  27952. 'underscore': 500,
  27953. 'quoteleft': 333,
  27954. 'a': 500,
  27955. 'b': 500,
  27956. 'c': 444,
  27957. 'd': 500,
  27958. 'e': 444,
  27959. 'f': 333,
  27960. 'g': 500,
  27961. 'h': 556,
  27962. 'i': 278,
  27963. 'j': 278,
  27964. 'k': 500,
  27965. 'l': 278,
  27966. 'm': 778,
  27967. 'n': 556,
  27968. 'o': 500,
  27969. 'p': 500,
  27970. 'q': 500,
  27971. 'r': 389,
  27972. 's': 389,
  27973. 't': 278,
  27974. 'u': 556,
  27975. 'v': 444,
  27976. 'w': 667,
  27977. 'x': 500,
  27978. 'y': 444,
  27979. 'z': 389,
  27980. 'braceleft': 348,
  27981. 'bar': 220,
  27982. 'braceright': 348,
  27983. 'asciitilde': 570,
  27984. 'exclamdown': 389,
  27985. 'cent': 500,
  27986. 'sterling': 500,
  27987. 'fraction': 167,
  27988. 'yen': 500,
  27989. 'florin': 500,
  27990. 'section': 500,
  27991. 'currency': 500,
  27992. 'quotesingle': 278,
  27993. 'quotedblleft': 500,
  27994. 'guillemotleft': 500,
  27995. 'guilsinglleft': 333,
  27996. 'guilsinglright': 333,
  27997. 'fi': 556,
  27998. 'fl': 556,
  27999. 'endash': 500,
  28000. 'dagger': 500,
  28001. 'daggerdbl': 500,
  28002. 'periodcentered': 250,
  28003. 'paragraph': 500,
  28004. 'bullet': 350,
  28005. 'quotesinglbase': 333,
  28006. 'quotedblbase': 500,
  28007. 'quotedblright': 500,
  28008. 'guillemotright': 500,
  28009. 'ellipsis': 1000,
  28010. 'perthousand': 1000,
  28011. 'questiondown': 500,
  28012. 'grave': 333,
  28013. 'acute': 333,
  28014. 'circumflex': 333,
  28015. 'tilde': 333,
  28016. 'macron': 333,
  28017. 'breve': 333,
  28018. 'dotaccent': 333,
  28019. 'dieresis': 333,
  28020. 'ring': 333,
  28021. 'cedilla': 333,
  28022. 'hungarumlaut': 333,
  28023. 'ogonek': 333,
  28024. 'caron': 333,
  28025. 'emdash': 1000,
  28026. 'AE': 944,
  28027. 'ordfeminine': 266,
  28028. 'Lslash': 611,
  28029. 'Oslash': 722,
  28030. 'OE': 944,
  28031. 'ordmasculine': 300,
  28032. 'ae': 722,
  28033. 'dotlessi': 278,
  28034. 'lslash': 278,
  28035. 'oslash': 500,
  28036. 'oe': 722,
  28037. 'germandbls': 500,
  28038. 'Idieresis': 389,
  28039. 'eacute': 444,
  28040. 'abreve': 500,
  28041. 'uhungarumlaut': 556,
  28042. 'ecaron': 444,
  28043. 'Ydieresis': 611,
  28044. 'divide': 570,
  28045. 'Yacute': 611,
  28046. 'Acircumflex': 667,
  28047. 'aacute': 500,
  28048. 'Ucircumflex': 722,
  28049. 'yacute': 444,
  28050. 'scommaaccent': 389,
  28051. 'ecircumflex': 444,
  28052. 'Uring': 722,
  28053. 'Udieresis': 722,
  28054. 'aogonek': 500,
  28055. 'Uacute': 722,
  28056. 'uogonek': 556,
  28057. 'Edieresis': 667,
  28058. 'Dcroat': 722,
  28059. 'commaaccent': 250,
  28060. 'copyright': 747,
  28061. 'Emacron': 667,
  28062. 'ccaron': 444,
  28063. 'aring': 500,
  28064. 'Ncommaaccent': 722,
  28065. 'lacute': 278,
  28066. 'agrave': 500,
  28067. 'Tcommaaccent': 611,
  28068. 'Cacute': 667,
  28069. 'atilde': 500,
  28070. 'Edotaccent': 667,
  28071. 'scaron': 389,
  28072. 'scedilla': 389,
  28073. 'iacute': 278,
  28074. 'lozenge': 494,
  28075. 'Rcaron': 667,
  28076. 'Gcommaaccent': 722,
  28077. 'ucircumflex': 556,
  28078. 'acircumflex': 500,
  28079. 'Amacron': 667,
  28080. 'rcaron': 389,
  28081. 'ccedilla': 444,
  28082. 'Zdotaccent': 611,
  28083. 'Thorn': 611,
  28084. 'Omacron': 722,
  28085. 'Racute': 667,
  28086. 'Sacute': 556,
  28087. 'dcaron': 608,
  28088. 'Umacron': 722,
  28089. 'uring': 556,
  28090. 'threesuperior': 300,
  28091. 'Ograve': 722,
  28092. 'Agrave': 667,
  28093. 'Abreve': 667,
  28094. 'multiply': 570,
  28095. 'uacute': 556,
  28096. 'Tcaron': 611,
  28097. 'partialdiff': 494,
  28098. 'ydieresis': 444,
  28099. 'Nacute': 722,
  28100. 'icircumflex': 278,
  28101. 'Ecircumflex': 667,
  28102. 'adieresis': 500,
  28103. 'edieresis': 444,
  28104. 'cacute': 444,
  28105. 'nacute': 556,
  28106. 'umacron': 556,
  28107. 'Ncaron': 722,
  28108. 'Iacute': 389,
  28109. 'plusminus': 570,
  28110. 'brokenbar': 220,
  28111. 'registered': 747,
  28112. 'Gbreve': 722,
  28113. 'Idotaccent': 389,
  28114. 'summation': 600,
  28115. 'Egrave': 667,
  28116. 'racute': 389,
  28117. 'omacron': 500,
  28118. 'Zacute': 611,
  28119. 'Zcaron': 611,
  28120. 'greaterequal': 549,
  28121. 'Eth': 722,
  28122. 'Ccedilla': 667,
  28123. 'lcommaaccent': 278,
  28124. 'tcaron': 366,
  28125. 'eogonek': 444,
  28126. 'Uogonek': 722,
  28127. 'Aacute': 667,
  28128. 'Adieresis': 667,
  28129. 'egrave': 444,
  28130. 'zacute': 389,
  28131. 'iogonek': 278,
  28132. 'Oacute': 722,
  28133. 'oacute': 500,
  28134. 'amacron': 500,
  28135. 'sacute': 389,
  28136. 'idieresis': 278,
  28137. 'Ocircumflex': 722,
  28138. 'Ugrave': 722,
  28139. 'Delta': 612,
  28140. 'thorn': 500,
  28141. 'twosuperior': 300,
  28142. 'Odieresis': 722,
  28143. 'mu': 576,
  28144. 'igrave': 278,
  28145. 'ohungarumlaut': 500,
  28146. 'Eogonek': 667,
  28147. 'dcroat': 500,
  28148. 'threequarters': 750,
  28149. 'Scedilla': 556,
  28150. 'lcaron': 382,
  28151. 'Kcommaaccent': 667,
  28152. 'Lacute': 611,
  28153. 'trademark': 1000,
  28154. 'edotaccent': 444,
  28155. 'Igrave': 389,
  28156. 'Imacron': 389,
  28157. 'Lcaron': 611,
  28158. 'onehalf': 750,
  28159. 'lessequal': 549,
  28160. 'ocircumflex': 500,
  28161. 'ntilde': 556,
  28162. 'Uhungarumlaut': 722,
  28163. 'Eacute': 667,
  28164. 'emacron': 444,
  28165. 'gbreve': 500,
  28166. 'onequarter': 750,
  28167. 'Scaron': 556,
  28168. 'Scommaaccent': 556,
  28169. 'Ohungarumlaut': 722,
  28170. 'degree': 400,
  28171. 'ograve': 500,
  28172. 'Ccaron': 667,
  28173. 'ugrave': 556,
  28174. 'radical': 549,
  28175. 'Dcaron': 722,
  28176. 'rcommaaccent': 389,
  28177. 'Ntilde': 722,
  28178. 'otilde': 500,
  28179. 'Rcommaaccent': 667,
  28180. 'Lcommaaccent': 611,
  28181. 'Atilde': 667,
  28182. 'Aogonek': 667,
  28183. 'Aring': 667,
  28184. 'Otilde': 722,
  28185. 'zdotaccent': 389,
  28186. 'Ecaron': 667,
  28187. 'Iogonek': 389,
  28188. 'kcommaaccent': 500,
  28189. 'minus': 606,
  28190. 'Icircumflex': 389,
  28191. 'ncaron': 556,
  28192. 'tcommaaccent': 278,
  28193. 'logicalnot': 606,
  28194. 'odieresis': 500,
  28195. 'udieresis': 556,
  28196. 'notequal': 549,
  28197. 'gcommaaccent': 500,
  28198. 'eth': 500,
  28199. 'zcaron': 389,
  28200. 'ncommaaccent': 556,
  28201. 'onesuperior': 300,
  28202. 'imacron': 278,
  28203. 'Euro': 500
  28204. },
  28205. 'Times-Italic': {
  28206. 'space': 250,
  28207. 'exclam': 333,
  28208. 'quotedbl': 420,
  28209. 'numbersign': 500,
  28210. 'dollar': 500,
  28211. 'percent': 833,
  28212. 'ampersand': 778,
  28213. 'quoteright': 333,
  28214. 'parenleft': 333,
  28215. 'parenright': 333,
  28216. 'asterisk': 500,
  28217. 'plus': 675,
  28218. 'comma': 250,
  28219. 'hyphen': 333,
  28220. 'period': 250,
  28221. 'slash': 278,
  28222. 'zero': 500,
  28223. 'one': 500,
  28224. 'two': 500,
  28225. 'three': 500,
  28226. 'four': 500,
  28227. 'five': 500,
  28228. 'six': 500,
  28229. 'seven': 500,
  28230. 'eight': 500,
  28231. 'nine': 500,
  28232. 'colon': 333,
  28233. 'semicolon': 333,
  28234. 'less': 675,
  28235. 'equal': 675,
  28236. 'greater': 675,
  28237. 'question': 500,
  28238. 'at': 920,
  28239. 'A': 611,
  28240. 'B': 611,
  28241. 'C': 667,
  28242. 'D': 722,
  28243. 'E': 611,
  28244. 'F': 611,
  28245. 'G': 722,
  28246. 'H': 722,
  28247. 'I': 333,
  28248. 'J': 444,
  28249. 'K': 667,
  28250. 'L': 556,
  28251. 'M': 833,
  28252. 'N': 667,
  28253. 'O': 722,
  28254. 'P': 611,
  28255. 'Q': 722,
  28256. 'R': 611,
  28257. 'S': 500,
  28258. 'T': 556,
  28259. 'U': 722,
  28260. 'V': 611,
  28261. 'W': 833,
  28262. 'X': 611,
  28263. 'Y': 556,
  28264. 'Z': 556,
  28265. 'bracketleft': 389,
  28266. 'backslash': 278,
  28267. 'bracketright': 389,
  28268. 'asciicircum': 422,
  28269. 'underscore': 500,
  28270. 'quoteleft': 333,
  28271. 'a': 500,
  28272. 'b': 500,
  28273. 'c': 444,
  28274. 'd': 500,
  28275. 'e': 444,
  28276. 'f': 278,
  28277. 'g': 500,
  28278. 'h': 500,
  28279. 'i': 278,
  28280. 'j': 278,
  28281. 'k': 444,
  28282. 'l': 278,
  28283. 'm': 722,
  28284. 'n': 500,
  28285. 'o': 500,
  28286. 'p': 500,
  28287. 'q': 500,
  28288. 'r': 389,
  28289. 's': 389,
  28290. 't': 278,
  28291. 'u': 500,
  28292. 'v': 444,
  28293. 'w': 667,
  28294. 'x': 444,
  28295. 'y': 444,
  28296. 'z': 389,
  28297. 'braceleft': 400,
  28298. 'bar': 275,
  28299. 'braceright': 400,
  28300. 'asciitilde': 541,
  28301. 'exclamdown': 389,
  28302. 'cent': 500,
  28303. 'sterling': 500,
  28304. 'fraction': 167,
  28305. 'yen': 500,
  28306. 'florin': 500,
  28307. 'section': 500,
  28308. 'currency': 500,
  28309. 'quotesingle': 214,
  28310. 'quotedblleft': 556,
  28311. 'guillemotleft': 500,
  28312. 'guilsinglleft': 333,
  28313. 'guilsinglright': 333,
  28314. 'fi': 500,
  28315. 'fl': 500,
  28316. 'endash': 500,
  28317. 'dagger': 500,
  28318. 'daggerdbl': 500,
  28319. 'periodcentered': 250,
  28320. 'paragraph': 523,
  28321. 'bullet': 350,
  28322. 'quotesinglbase': 333,
  28323. 'quotedblbase': 556,
  28324. 'quotedblright': 556,
  28325. 'guillemotright': 500,
  28326. 'ellipsis': 889,
  28327. 'perthousand': 1000,
  28328. 'questiondown': 500,
  28329. 'grave': 333,
  28330. 'acute': 333,
  28331. 'circumflex': 333,
  28332. 'tilde': 333,
  28333. 'macron': 333,
  28334. 'breve': 333,
  28335. 'dotaccent': 333,
  28336. 'dieresis': 333,
  28337. 'ring': 333,
  28338. 'cedilla': 333,
  28339. 'hungarumlaut': 333,
  28340. 'ogonek': 333,
  28341. 'caron': 333,
  28342. 'emdash': 889,
  28343. 'AE': 889,
  28344. 'ordfeminine': 276,
  28345. 'Lslash': 556,
  28346. 'Oslash': 722,
  28347. 'OE': 944,
  28348. 'ordmasculine': 310,
  28349. 'ae': 667,
  28350. 'dotlessi': 278,
  28351. 'lslash': 278,
  28352. 'oslash': 500,
  28353. 'oe': 667,
  28354. 'germandbls': 500,
  28355. 'Idieresis': 333,
  28356. 'eacute': 444,
  28357. 'abreve': 500,
  28358. 'uhungarumlaut': 500,
  28359. 'ecaron': 444,
  28360. 'Ydieresis': 556,
  28361. 'divide': 675,
  28362. 'Yacute': 556,
  28363. 'Acircumflex': 611,
  28364. 'aacute': 500,
  28365. 'Ucircumflex': 722,
  28366. 'yacute': 444,
  28367. 'scommaaccent': 389,
  28368. 'ecircumflex': 444,
  28369. 'Uring': 722,
  28370. 'Udieresis': 722,
  28371. 'aogonek': 500,
  28372. 'Uacute': 722,
  28373. 'uogonek': 500,
  28374. 'Edieresis': 611,
  28375. 'Dcroat': 722,
  28376. 'commaaccent': 250,
  28377. 'copyright': 760,
  28378. 'Emacron': 611,
  28379. 'ccaron': 444,
  28380. 'aring': 500,
  28381. 'Ncommaaccent': 667,
  28382. 'lacute': 278,
  28383. 'agrave': 500,
  28384. 'Tcommaaccent': 556,
  28385. 'Cacute': 667,
  28386. 'atilde': 500,
  28387. 'Edotaccent': 611,
  28388. 'scaron': 389,
  28389. 'scedilla': 389,
  28390. 'iacute': 278,
  28391. 'lozenge': 471,
  28392. 'Rcaron': 611,
  28393. 'Gcommaaccent': 722,
  28394. 'ucircumflex': 500,
  28395. 'acircumflex': 500,
  28396. 'Amacron': 611,
  28397. 'rcaron': 389,
  28398. 'ccedilla': 444,
  28399. 'Zdotaccent': 556,
  28400. 'Thorn': 611,
  28401. 'Omacron': 722,
  28402. 'Racute': 611,
  28403. 'Sacute': 500,
  28404. 'dcaron': 544,
  28405. 'Umacron': 722,
  28406. 'uring': 500,
  28407. 'threesuperior': 300,
  28408. 'Ograve': 722,
  28409. 'Agrave': 611,
  28410. 'Abreve': 611,
  28411. 'multiply': 675,
  28412. 'uacute': 500,
  28413. 'Tcaron': 556,
  28414. 'partialdiff': 476,
  28415. 'ydieresis': 444,
  28416. 'Nacute': 667,
  28417. 'icircumflex': 278,
  28418. 'Ecircumflex': 611,
  28419. 'adieresis': 500,
  28420. 'edieresis': 444,
  28421. 'cacute': 444,
  28422. 'nacute': 500,
  28423. 'umacron': 500,
  28424. 'Ncaron': 667,
  28425. 'Iacute': 333,
  28426. 'plusminus': 675,
  28427. 'brokenbar': 275,
  28428. 'registered': 760,
  28429. 'Gbreve': 722,
  28430. 'Idotaccent': 333,
  28431. 'summation': 600,
  28432. 'Egrave': 611,
  28433. 'racute': 389,
  28434. 'omacron': 500,
  28435. 'Zacute': 556,
  28436. 'Zcaron': 556,
  28437. 'greaterequal': 549,
  28438. 'Eth': 722,
  28439. 'Ccedilla': 667,
  28440. 'lcommaaccent': 278,
  28441. 'tcaron': 300,
  28442. 'eogonek': 444,
  28443. 'Uogonek': 722,
  28444. 'Aacute': 611,
  28445. 'Adieresis': 611,
  28446. 'egrave': 444,
  28447. 'zacute': 389,
  28448. 'iogonek': 278,
  28449. 'Oacute': 722,
  28450. 'oacute': 500,
  28451. 'amacron': 500,
  28452. 'sacute': 389,
  28453. 'idieresis': 278,
  28454. 'Ocircumflex': 722,
  28455. 'Ugrave': 722,
  28456. 'Delta': 612,
  28457. 'thorn': 500,
  28458. 'twosuperior': 300,
  28459. 'Odieresis': 722,
  28460. 'mu': 500,
  28461. 'igrave': 278,
  28462. 'ohungarumlaut': 500,
  28463. 'Eogonek': 611,
  28464. 'dcroat': 500,
  28465. 'threequarters': 750,
  28466. 'Scedilla': 500,
  28467. 'lcaron': 300,
  28468. 'Kcommaaccent': 667,
  28469. 'Lacute': 556,
  28470. 'trademark': 980,
  28471. 'edotaccent': 444,
  28472. 'Igrave': 333,
  28473. 'Imacron': 333,
  28474. 'Lcaron': 611,
  28475. 'onehalf': 750,
  28476. 'lessequal': 549,
  28477. 'ocircumflex': 500,
  28478. 'ntilde': 500,
  28479. 'Uhungarumlaut': 722,
  28480. 'Eacute': 611,
  28481. 'emacron': 444,
  28482. 'gbreve': 500,
  28483. 'onequarter': 750,
  28484. 'Scaron': 500,
  28485. 'Scommaaccent': 500,
  28486. 'Ohungarumlaut': 722,
  28487. 'degree': 400,
  28488. 'ograve': 500,
  28489. 'Ccaron': 667,
  28490. 'ugrave': 500,
  28491. 'radical': 453,
  28492. 'Dcaron': 722,
  28493. 'rcommaaccent': 389,
  28494. 'Ntilde': 667,
  28495. 'otilde': 500,
  28496. 'Rcommaaccent': 611,
  28497. 'Lcommaaccent': 556,
  28498. 'Atilde': 611,
  28499. 'Aogonek': 611,
  28500. 'Aring': 611,
  28501. 'Otilde': 722,
  28502. 'zdotaccent': 389,
  28503. 'Ecaron': 611,
  28504. 'Iogonek': 333,
  28505. 'kcommaaccent': 444,
  28506. 'minus': 675,
  28507. 'Icircumflex': 333,
  28508. 'ncaron': 500,
  28509. 'tcommaaccent': 278,
  28510. 'logicalnot': 675,
  28511. 'odieresis': 500,
  28512. 'udieresis': 500,
  28513. 'notequal': 549,
  28514. 'gcommaaccent': 500,
  28515. 'eth': 500,
  28516. 'zcaron': 389,
  28517. 'ncommaaccent': 500,
  28518. 'onesuperior': 300,
  28519. 'imacron': 278,
  28520. 'Euro': 500
  28521. },
  28522. 'ZapfDingbats': {
  28523. 'space': 278,
  28524. 'a1': 974,
  28525. 'a2': 961,
  28526. 'a202': 974,
  28527. 'a3': 980,
  28528. 'a4': 719,
  28529. 'a5': 789,
  28530. 'a119': 790,
  28531. 'a118': 791,
  28532. 'a117': 690,
  28533. 'a11': 960,
  28534. 'a12': 939,
  28535. 'a13': 549,
  28536. 'a14': 855,
  28537. 'a15': 911,
  28538. 'a16': 933,
  28539. 'a105': 911,
  28540. 'a17': 945,
  28541. 'a18': 974,
  28542. 'a19': 755,
  28543. 'a20': 846,
  28544. 'a21': 762,
  28545. 'a22': 761,
  28546. 'a23': 571,
  28547. 'a24': 677,
  28548. 'a25': 763,
  28549. 'a26': 760,
  28550. 'a27': 759,
  28551. 'a28': 754,
  28552. 'a6': 494,
  28553. 'a7': 552,
  28554. 'a8': 537,
  28555. 'a9': 577,
  28556. 'a10': 692,
  28557. 'a29': 786,
  28558. 'a30': 788,
  28559. 'a31': 788,
  28560. 'a32': 790,
  28561. 'a33': 793,
  28562. 'a34': 794,
  28563. 'a35': 816,
  28564. 'a36': 823,
  28565. 'a37': 789,
  28566. 'a38': 841,
  28567. 'a39': 823,
  28568. 'a40': 833,
  28569. 'a41': 816,
  28570. 'a42': 831,
  28571. 'a43': 923,
  28572. 'a44': 744,
  28573. 'a45': 723,
  28574. 'a46': 749,
  28575. 'a47': 790,
  28576. 'a48': 792,
  28577. 'a49': 695,
  28578. 'a50': 776,
  28579. 'a51': 768,
  28580. 'a52': 792,
  28581. 'a53': 759,
  28582. 'a54': 707,
  28583. 'a55': 708,
  28584. 'a56': 682,
  28585. 'a57': 701,
  28586. 'a58': 826,
  28587. 'a59': 815,
  28588. 'a60': 789,
  28589. 'a61': 789,
  28590. 'a62': 707,
  28591. 'a63': 687,
  28592. 'a64': 696,
  28593. 'a65': 689,
  28594. 'a66': 786,
  28595. 'a67': 787,
  28596. 'a68': 713,
  28597. 'a69': 791,
  28598. 'a70': 785,
  28599. 'a71': 791,
  28600. 'a72': 873,
  28601. 'a73': 761,
  28602. 'a74': 762,
  28603. 'a203': 762,
  28604. 'a75': 759,
  28605. 'a204': 759,
  28606. 'a76': 892,
  28607. 'a77': 892,
  28608. 'a78': 788,
  28609. 'a79': 784,
  28610. 'a81': 438,
  28611. 'a82': 138,
  28612. 'a83': 277,
  28613. 'a84': 415,
  28614. 'a97': 392,
  28615. 'a98': 392,
  28616. 'a99': 668,
  28617. 'a100': 668,
  28618. 'a89': 390,
  28619. 'a90': 390,
  28620. 'a93': 317,
  28621. 'a94': 317,
  28622. 'a91': 276,
  28623. 'a92': 276,
  28624. 'a205': 509,
  28625. 'a85': 509,
  28626. 'a206': 410,
  28627. 'a86': 410,
  28628. 'a87': 234,
  28629. 'a88': 234,
  28630. 'a95': 334,
  28631. 'a96': 334,
  28632. 'a101': 732,
  28633. 'a102': 544,
  28634. 'a103': 544,
  28635. 'a104': 910,
  28636. 'a106': 667,
  28637. 'a107': 760,
  28638. 'a108': 760,
  28639. 'a112': 776,
  28640. 'a111': 595,
  28641. 'a110': 694,
  28642. 'a109': 626,
  28643. 'a120': 788,
  28644. 'a121': 788,
  28645. 'a122': 788,
  28646. 'a123': 788,
  28647. 'a124': 788,
  28648. 'a125': 788,
  28649. 'a126': 788,
  28650. 'a127': 788,
  28651. 'a128': 788,
  28652. 'a129': 788,
  28653. 'a130': 788,
  28654. 'a131': 788,
  28655. 'a132': 788,
  28656. 'a133': 788,
  28657. 'a134': 788,
  28658. 'a135': 788,
  28659. 'a136': 788,
  28660. 'a137': 788,
  28661. 'a138': 788,
  28662. 'a139': 788,
  28663. 'a140': 788,
  28664. 'a141': 788,
  28665. 'a142': 788,
  28666. 'a143': 788,
  28667. 'a144': 788,
  28668. 'a145': 788,
  28669. 'a146': 788,
  28670. 'a147': 788,
  28671. 'a148': 788,
  28672. 'a149': 788,
  28673. 'a150': 788,
  28674. 'a151': 788,
  28675. 'a152': 788,
  28676. 'a153': 788,
  28677. 'a154': 788,
  28678. 'a155': 788,
  28679. 'a156': 788,
  28680. 'a157': 788,
  28681. 'a158': 788,
  28682. 'a159': 788,
  28683. 'a160': 894,
  28684. 'a161': 838,
  28685. 'a163': 1016,
  28686. 'a164': 458,
  28687. 'a196': 748,
  28688. 'a165': 924,
  28689. 'a192': 748,
  28690. 'a166': 918,
  28691. 'a167': 927,
  28692. 'a168': 928,
  28693. 'a169': 928,
  28694. 'a170': 834,
  28695. 'a171': 873,
  28696. 'a172': 828,
  28697. 'a173': 924,
  28698. 'a162': 924,
  28699. 'a174': 917,
  28700. 'a175': 930,
  28701. 'a176': 931,
  28702. 'a177': 463,
  28703. 'a178': 883,
  28704. 'a179': 836,
  28705. 'a193': 836,
  28706. 'a180': 867,
  28707. 'a199': 867,
  28708. 'a181': 696,
  28709. 'a200': 696,
  28710. 'a182': 874,
  28711. 'a201': 874,
  28712. 'a183': 760,
  28713. 'a184': 946,
  28714. 'a197': 771,
  28715. 'a185': 865,
  28716. 'a194': 771,
  28717. 'a198': 888,
  28718. 'a186': 967,
  28719. 'a195': 888,
  28720. 'a187': 831,
  28721. 'a188': 873,
  28722. 'a189': 927,
  28723. 'a190': 970,
  28724. 'a191': 918
  28725. }
  28726. };
  28727. var EOF = {};
  28728. function isEOF(v) {
  28729. return (v === EOF);
  28730. }
  28731. var MAX_LENGTH_TO_CACHE = 1000;
  28732. var Parser = (function ParserClosure() {
  28733. function Parser(lexer, allowStreams, xref) {
  28734. this.lexer = lexer;
  28735. this.allowStreams = allowStreams;
  28736. this.xref = xref;
  28737. this.imageCache = {};
  28738. this.refill();
  28739. }
  28740. Parser.prototype = {
  28741. refill: function Parser_refill() {
  28742. this.buf1 = this.lexer.getObj();
  28743. this.buf2 = this.lexer.getObj();
  28744. },
  28745. shift: function Parser_shift() {
  28746. if (isCmd(this.buf2, 'ID')) {
  28747. this.buf1 = this.buf2;
  28748. this.buf2 = null;
  28749. } else {
  28750. this.buf1 = this.buf2;
  28751. this.buf2 = this.lexer.getObj();
  28752. }
  28753. },
  28754. tryShift: function Parser_tryShift() {
  28755. try {
  28756. this.shift();
  28757. return true;
  28758. } catch (e) {
  28759. if (e instanceof MissingDataException) {
  28760. throw e;
  28761. }
  28762. // Upon failure, the caller should reset this.lexer.pos to a known good
  28763. // state and call this.shift() twice to reset the buffers.
  28764. return false;
  28765. }
  28766. },
  28767. getObj: function Parser_getObj(cipherTransform) {
  28768. var buf1 = this.buf1;
  28769. this.shift();
  28770. if (buf1 instanceof Cmd) {
  28771. switch (buf1.cmd) {
  28772. case 'BI': // inline image
  28773. return this.makeInlineImage(cipherTransform);
  28774. case '[': // array
  28775. var array = [];
  28776. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28777. array.push(this.getObj(cipherTransform));
  28778. }
  28779. if (isEOF(this.buf1)) {
  28780. error('End of file inside array');
  28781. }
  28782. this.shift();
  28783. return array;
  28784. case '<<': // dictionary or stream
  28785. var dict = new Dict(this.xref);
  28786. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28787. if (!isName(this.buf1)) {
  28788. info('Malformed dictionary: key must be a name object');
  28789. this.shift();
  28790. continue;
  28791. }
  28792. var key = this.buf1.name;
  28793. this.shift();
  28794. if (isEOF(this.buf1)) {
  28795. break;
  28796. }
  28797. dict.set(key, this.getObj(cipherTransform));
  28798. }
  28799. if (isEOF(this.buf1)) {
  28800. error('End of file inside dictionary');
  28801. }
  28802. // Stream objects are not allowed inside content streams or
  28803. // object streams.
  28804. if (isCmd(this.buf2, 'stream')) {
  28805. return (this.allowStreams ?
  28806. this.makeStream(dict, cipherTransform) : dict);
  28807. }
  28808. this.shift();
  28809. return dict;
  28810. default: // simple object
  28811. return buf1;
  28812. }
  28813. }
  28814. if (isInt(buf1)) { // indirect reference or integer
  28815. var num = buf1;
  28816. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28817. var ref = new Ref(num, this.buf1);
  28818. this.shift();
  28819. this.shift();
  28820. return ref;
  28821. }
  28822. return num;
  28823. }
  28824. if (isString(buf1)) { // string
  28825. var str = buf1;
  28826. if (cipherTransform) {
  28827. str = cipherTransform.decryptString(str);
  28828. }
  28829. return str;
  28830. }
  28831. // simple object
  28832. return buf1;
  28833. },
  28834. /**
  28835. * Find the end of the stream by searching for the /EI\s/.
  28836. * @returns {number} The inline stream length.
  28837. */
  28838. findDefaultInlineStreamEnd:
  28839. function Parser_findDefaultInlineStreamEnd(stream) {
  28840. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28841. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28842. while ((ch = stream.getByte()) !== -1) {
  28843. if (state === 0) {
  28844. state = (ch === E) ? 1 : 0;
  28845. } else if (state === 1) {
  28846. state = (ch === I) ? 2 : 0;
  28847. } else {
  28848. assert(state === 2);
  28849. if (ch === SPACE || ch === LF || ch === CR) {
  28850. // Let's check the next five bytes are ASCII... just be sure.
  28851. n = 5;
  28852. followingBytes = stream.peekBytes(n);
  28853. for (i = 0; i < n; i++) {
  28854. ch = followingBytes[i];
  28855. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28856. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28857. // it's binary stuff. Resetting the state.
  28858. state = 0;
  28859. break;
  28860. }
  28861. }
  28862. if (state === 2) {
  28863. break; // Finished!
  28864. }
  28865. } else {
  28866. state = 0;
  28867. }
  28868. }
  28869. }
  28870. return ((stream.pos - 4) - startPos);
  28871. },
  28872. /**
  28873. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28874. * @returns {number} The inline stream length.
  28875. */
  28876. findDCTDecodeInlineStreamEnd:
  28877. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28878. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28879. while ((b = stream.getByte()) !== -1) {
  28880. if (b !== 0xFF) { // Not a valid marker.
  28881. continue;
  28882. }
  28883. switch (stream.getByte()) {
  28884. case 0x00: // Byte stuffing.
  28885. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28886. break;
  28887. case 0xFF: // Fill byte.
  28888. // Avoid skipping a valid marker, resetting the stream position.
  28889. stream.skip(-1);
  28890. break;
  28891. case 0xD9: // EOI
  28892. foundEOI = true;
  28893. break;
  28894. case 0xC0: // SOF0
  28895. case 0xC1: // SOF1
  28896. case 0xC2: // SOF2
  28897. case 0xC3: // SOF3
  28898. case 0xC5: // SOF5
  28899. case 0xC6: // SOF6
  28900. case 0xC7: // SOF7
  28901. case 0xC9: // SOF9
  28902. case 0xCA: // SOF10
  28903. case 0xCB: // SOF11
  28904. case 0xCD: // SOF13
  28905. case 0xCE: // SOF14
  28906. case 0xCF: // SOF15
  28907. case 0xC4: // DHT
  28908. case 0xCC: // DAC
  28909. case 0xDA: // SOS
  28910. case 0xDB: // DQT
  28911. case 0xDC: // DNL
  28912. case 0xDD: // DRI
  28913. case 0xDE: // DHP
  28914. case 0xDF: // EXP
  28915. case 0xE0: // APP0
  28916. case 0xE1: // APP1
  28917. case 0xE2: // APP2
  28918. case 0xE3: // APP3
  28919. case 0xE4: // APP4
  28920. case 0xE5: // APP5
  28921. case 0xE6: // APP6
  28922. case 0xE7: // APP7
  28923. case 0xE8: // APP8
  28924. case 0xE9: // APP9
  28925. case 0xEA: // APP10
  28926. case 0xEB: // APP11
  28927. case 0xEC: // APP12
  28928. case 0xED: // APP13
  28929. case 0xEE: // APP14
  28930. case 0xEF: // APP15
  28931. case 0xFE: // COM
  28932. // The marker should be followed by the length of the segment.
  28933. markerLength = stream.getUint16();
  28934. if (markerLength > 2) {
  28935. // |markerLength| contains the byte length of the marker segment,
  28936. // including its own length (2 bytes) and excluding the marker.
  28937. stream.skip(markerLength - 2); // Jump to the next marker.
  28938. } else {
  28939. // The marker length is invalid, resetting the stream position.
  28940. stream.skip(-2);
  28941. }
  28942. break;
  28943. }
  28944. if (foundEOI) {
  28945. break;
  28946. }
  28947. }
  28948. length = stream.pos - startPos;
  28949. if (b === -1) {
  28950. warn('Inline DCTDecode image stream: ' +
  28951. 'EOI marker not found, searching for /EI/ instead.');
  28952. stream.skip(-length); // Reset the stream position.
  28953. return this.findDefaultInlineStreamEnd(stream);
  28954. }
  28955. this.inlineStreamSkipEI(stream);
  28956. return length;
  28957. },
  28958. /**
  28959. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28960. * @returns {number} The inline stream length.
  28961. */
  28962. findASCII85DecodeInlineStreamEnd:
  28963. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28964. var TILDE = 0x7E, GT = 0x3E;
  28965. var startPos = stream.pos, ch, length;
  28966. while ((ch = stream.getByte()) !== -1) {
  28967. if (ch === TILDE && stream.peekByte() === GT) {
  28968. stream.skip();
  28969. break;
  28970. }
  28971. }
  28972. length = stream.pos - startPos;
  28973. if (ch === -1) {
  28974. warn('Inline ASCII85Decode image stream: ' +
  28975. 'EOD marker not found, searching for /EI/ instead.');
  28976. stream.skip(-length); // Reset the stream position.
  28977. return this.findDefaultInlineStreamEnd(stream);
  28978. }
  28979. this.inlineStreamSkipEI(stream);
  28980. return length;
  28981. },
  28982. /**
  28983. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28984. * @returns {number} The inline stream length.
  28985. */
  28986. findASCIIHexDecodeInlineStreamEnd:
  28987. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28988. var GT = 0x3E;
  28989. var startPos = stream.pos, ch, length;
  28990. while ((ch = stream.getByte()) !== -1) {
  28991. if (ch === GT) {
  28992. break;
  28993. }
  28994. }
  28995. length = stream.pos - startPos;
  28996. if (ch === -1) {
  28997. warn('Inline ASCIIHexDecode image stream: ' +
  28998. 'EOD marker not found, searching for /EI/ instead.');
  28999. stream.skip(-length); // Reset the stream position.
  29000. return this.findDefaultInlineStreamEnd(stream);
  29001. }
  29002. this.inlineStreamSkipEI(stream);
  29003. return length;
  29004. },
  29005. /**
  29006. * Skip over the /EI/ for streams where we search for an EOD marker.
  29007. */
  29008. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  29009. var E = 0x45, I = 0x49;
  29010. var state = 0, ch;
  29011. while ((ch = stream.getByte()) !== -1) {
  29012. if (state === 0) {
  29013. state = (ch === E) ? 1 : 0;
  29014. } else if (state === 1) {
  29015. state = (ch === I) ? 2 : 0;
  29016. } else if (state === 2) {
  29017. break;
  29018. }
  29019. }
  29020. },
  29021. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  29022. var lexer = this.lexer;
  29023. var stream = lexer.stream;
  29024. // Parse dictionary.
  29025. var dict = new Dict(this.xref);
  29026. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  29027. if (!isName(this.buf1)) {
  29028. error('Dictionary key must be a name object');
  29029. }
  29030. var key = this.buf1.name;
  29031. this.shift();
  29032. if (isEOF(this.buf1)) {
  29033. break;
  29034. }
  29035. dict.set(key, this.getObj(cipherTransform));
  29036. }
  29037. // Extract the name of the first (i.e. the current) image filter.
  29038. var filter = dict.get('Filter', 'F'), filterName;
  29039. if (isName(filter)) {
  29040. filterName = filter.name;
  29041. } else if (isArray(filter) && isName(filter[0])) {
  29042. filterName = filter[0].name;
  29043. }
  29044. // Parse image stream.
  29045. var startPos = stream.pos, length, i, ii;
  29046. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  29047. length = this.findDCTDecodeInlineStreamEnd(stream);
  29048. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  29049. length = this.findASCII85DecodeInlineStreamEnd(stream);
  29050. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  29051. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  29052. } else {
  29053. length = this.findDefaultInlineStreamEnd(stream);
  29054. }
  29055. var imageStream = stream.makeSubStream(startPos, length, dict);
  29056. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  29057. // adler32 checksum.
  29058. var adler32;
  29059. if (length < MAX_LENGTH_TO_CACHE) {
  29060. var imageBytes = imageStream.getBytes();
  29061. imageStream.reset();
  29062. var a = 1;
  29063. var b = 0;
  29064. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  29065. // No modulo required in the loop if imageBytes.length < 5552.
  29066. a += imageBytes[i] & 0xff;
  29067. b += a;
  29068. }
  29069. adler32 = ((b % 65521) << 16) | (a % 65521);
  29070. if (this.imageCache.adler32 === adler32) {
  29071. this.buf2 = Cmd.get('EI');
  29072. this.shift();
  29073. this.imageCache[adler32].reset();
  29074. return this.imageCache[adler32];
  29075. }
  29076. }
  29077. if (cipherTransform) {
  29078. imageStream = cipherTransform.createStream(imageStream, length);
  29079. }
  29080. imageStream = this.filter(imageStream, dict, length);
  29081. imageStream.dict = dict;
  29082. if (adler32 !== undefined) {
  29083. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  29084. this.imageCache[adler32] = imageStream;
  29085. }
  29086. this.buf2 = Cmd.get('EI');
  29087. this.shift();
  29088. return imageStream;
  29089. },
  29090. makeStream: function Parser_makeStream(dict, cipherTransform) {
  29091. var lexer = this.lexer;
  29092. var stream = lexer.stream;
  29093. // get stream start position
  29094. lexer.skipToNextLine();
  29095. var pos = stream.pos - 1;
  29096. // get length
  29097. var length = dict.get('Length');
  29098. if (!isInt(length)) {
  29099. info('Bad ' + length + ' attribute in stream');
  29100. length = 0;
  29101. }
  29102. // skip over the stream data
  29103. stream.pos = pos + length;
  29104. lexer.nextChar();
  29105. // Shift '>>' and check whether the new object marks the end of the stream
  29106. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  29107. this.shift(); // 'stream'
  29108. } else {
  29109. // bad stream length, scanning for endstream
  29110. stream.pos = pos;
  29111. var SCAN_BLOCK_SIZE = 2048;
  29112. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  29113. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  29114. 0x61, 0x6D];
  29115. var skipped = 0, found = false, i, j;
  29116. while (stream.pos < stream.end) {
  29117. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  29118. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  29119. if (scanLength <= 0) {
  29120. break;
  29121. }
  29122. found = false;
  29123. for (i = 0, j = 0; i < scanLength; i++) {
  29124. var b = scanBytes[i];
  29125. if (b !== ENDSTREAM_SIGNATURE[j]) {
  29126. i -= j;
  29127. j = 0;
  29128. } else {
  29129. j++;
  29130. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  29131. i++;
  29132. found = true;
  29133. break;
  29134. }
  29135. }
  29136. }
  29137. if (found) {
  29138. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  29139. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  29140. break;
  29141. }
  29142. skipped += scanLength;
  29143. stream.pos += scanLength;
  29144. }
  29145. if (!found) {
  29146. error('Missing endstream');
  29147. }
  29148. length = skipped;
  29149. lexer.nextChar();
  29150. this.shift();
  29151. this.shift();
  29152. }
  29153. this.shift(); // 'endstream'
  29154. stream = stream.makeSubStream(pos, length, dict);
  29155. if (cipherTransform) {
  29156. stream = cipherTransform.createStream(stream, length);
  29157. }
  29158. stream = this.filter(stream, dict, length);
  29159. stream.dict = dict;
  29160. return stream;
  29161. },
  29162. filter: function Parser_filter(stream, dict, length) {
  29163. var filter = dict.get('Filter', 'F');
  29164. var params = dict.get('DecodeParms', 'DP');
  29165. if (isName(filter)) {
  29166. return this.makeFilter(stream, filter.name, length, params);
  29167. }
  29168. var maybeLength = length;
  29169. if (isArray(filter)) {
  29170. var filterArray = filter;
  29171. var paramsArray = params;
  29172. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  29173. filter = filterArray[i];
  29174. if (!isName(filter)) {
  29175. error('Bad filter name: ' + filter);
  29176. }
  29177. params = null;
  29178. if (isArray(paramsArray) && (i in paramsArray)) {
  29179. params = paramsArray[i];
  29180. }
  29181. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  29182. // after the first stream the length variable is invalid
  29183. maybeLength = null;
  29184. }
  29185. }
  29186. return stream;
  29187. },
  29188. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  29189. if (stream.dict.get('Length') === 0 && !maybeLength) {
  29190. warn('Empty "' + name + '" stream.');
  29191. return new NullStream(stream);
  29192. }
  29193. try {
  29194. if (params && this.xref) {
  29195. params = this.xref.fetchIfRef(params);
  29196. }
  29197. var xrefStreamStats = this.xref.stats.streamTypes;
  29198. if (name === 'FlateDecode' || name === 'Fl') {
  29199. xrefStreamStats[StreamType.FLATE] = true;
  29200. if (params) {
  29201. return new PredictorStream(new FlateStream(stream, maybeLength),
  29202. maybeLength, params);
  29203. }
  29204. return new FlateStream(stream, maybeLength);
  29205. }
  29206. if (name === 'LZWDecode' || name === 'LZW') {
  29207. xrefStreamStats[StreamType.LZW] = true;
  29208. var earlyChange = 1;
  29209. if (params) {
  29210. if (params.has('EarlyChange')) {
  29211. earlyChange = params.get('EarlyChange');
  29212. }
  29213. return new PredictorStream(
  29214. new LZWStream(stream, maybeLength, earlyChange),
  29215. maybeLength, params);
  29216. }
  29217. return new LZWStream(stream, maybeLength, earlyChange);
  29218. }
  29219. if (name === 'DCTDecode' || name === 'DCT') {
  29220. xrefStreamStats[StreamType.DCT] = true;
  29221. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  29222. }
  29223. if (name === 'JPXDecode' || name === 'JPX') {
  29224. xrefStreamStats[StreamType.JPX] = true;
  29225. return new JpxStream(stream, maybeLength, stream.dict);
  29226. }
  29227. if (name === 'ASCII85Decode' || name === 'A85') {
  29228. xrefStreamStats[StreamType.A85] = true;
  29229. return new Ascii85Stream(stream, maybeLength);
  29230. }
  29231. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  29232. xrefStreamStats[StreamType.AHX] = true;
  29233. return new AsciiHexStream(stream, maybeLength);
  29234. }
  29235. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  29236. xrefStreamStats[StreamType.CCF] = true;
  29237. return new CCITTFaxStream(stream, maybeLength, params);
  29238. }
  29239. if (name === 'RunLengthDecode' || name === 'RL') {
  29240. xrefStreamStats[StreamType.RL] = true;
  29241. return new RunLengthStream(stream, maybeLength);
  29242. }
  29243. if (name === 'JBIG2Decode') {
  29244. xrefStreamStats[StreamType.JBIG] = true;
  29245. return new Jbig2Stream(stream, maybeLength, stream.dict);
  29246. }
  29247. warn('filter "' + name + '" not supported yet');
  29248. return stream;
  29249. } catch (ex) {
  29250. if (ex instanceof MissingDataException) {
  29251. throw ex;
  29252. }
  29253. warn('Invalid stream: \"' + ex + '\"');
  29254. return new NullStream(stream);
  29255. }
  29256. }
  29257. };
  29258. return Parser;
  29259. })();
  29260. var Lexer = (function LexerClosure() {
  29261. function Lexer(stream, knownCommands) {
  29262. this.stream = stream;
  29263. this.nextChar();
  29264. // While lexing, we build up many strings one char at a time. Using += for
  29265. // this can result in lots of garbage strings. It's better to build an
  29266. // array of single-char strings and then join() them together at the end.
  29267. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  29268. // purpose uses less memory than using a new array for each string.
  29269. this.strBuf = [];
  29270. // The PDFs might have "glued" commands with other commands, operands or
  29271. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  29272. // commands and their prefixes. The prefixes are built the following way:
  29273. // if there a command that is a prefix of the other valid command or
  29274. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  29275. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  29276. // other commands or literals as a prefix. The knowCommands is optional.
  29277. this.knownCommands = knownCommands;
  29278. }
  29279. Lexer.isSpace = function Lexer_isSpace(ch) {
  29280. // Space is one of the following characters: SPACE, TAB, CR or LF.
  29281. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  29282. };
  29283. // A '1' in this array means the character is white space. A '1' or
  29284. // '2' means the character ends a name or command.
  29285. var specialChars = [
  29286. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  29287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  29288. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  29289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  29290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  29291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  29292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  29293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  29294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  29295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  29296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  29297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  29298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  29299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  29300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  29301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  29302. ];
  29303. function toHexDigit(ch) {
  29304. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29305. return ch & 0x0F;
  29306. }
  29307. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29308. // 'A'-'F', 'a'-'f'
  29309. return (ch & 0x0F) + 9;
  29310. }
  29311. return -1;
  29312. }
  29313. Lexer.prototype = {
  29314. nextChar: function Lexer_nextChar() {
  29315. return (this.currentChar = this.stream.getByte());
  29316. },
  29317. peekChar: function Lexer_peekChar() {
  29318. return this.stream.peekByte();
  29319. },
  29320. getNumber: function Lexer_getNumber() {
  29321. var ch = this.currentChar;
  29322. var eNotation = false;
  29323. var divideBy = 0; // different from 0 if it's a floating point value
  29324. var sign = 1;
  29325. if (ch === 0x2D) { // '-'
  29326. sign = -1;
  29327. ch = this.nextChar();
  29328. if (ch === 0x2D) { // '-'
  29329. // Ignore double negative (this is consistent with Adobe Reader).
  29330. ch = this.nextChar();
  29331. }
  29332. } else if (ch === 0x2B) { // '+'
  29333. ch = this.nextChar();
  29334. }
  29335. if (ch === 0x2E) { // '.'
  29336. divideBy = 10;
  29337. ch = this.nextChar();
  29338. }
  29339. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29340. error('Invalid number: ' + String.fromCharCode(ch));
  29341. return 0;
  29342. }
  29343. var baseValue = ch - 0x30; // '0'
  29344. var powerValue = 0;
  29345. var powerValueSign = 1;
  29346. while ((ch = this.nextChar()) >= 0) {
  29347. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  29348. var currentDigit = ch - 0x30; // '0'
  29349. if (eNotation) { // We are after an 'e' or 'E'
  29350. powerValue = powerValue * 10 + currentDigit;
  29351. } else {
  29352. if (divideBy !== 0) { // We are after a point
  29353. divideBy *= 10;
  29354. }
  29355. baseValue = baseValue * 10 + currentDigit;
  29356. }
  29357. } else if (ch === 0x2E) { // '.'
  29358. if (divideBy === 0) {
  29359. divideBy = 1;
  29360. } else {
  29361. // A number can have only one '.'
  29362. break;
  29363. }
  29364. } else if (ch === 0x2D) { // '-'
  29365. // ignore minus signs in the middle of numbers to match
  29366. // Adobe's behavior
  29367. warn('Badly formated number');
  29368. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  29369. // 'E' can be either a scientific notation or the beginning of a new
  29370. // operator
  29371. ch = this.peekChar();
  29372. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  29373. powerValueSign = (ch === 0x2D) ? -1 : 1;
  29374. this.nextChar(); // Consume the sign character
  29375. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29376. // The 'E' must be the beginning of a new operator
  29377. break;
  29378. }
  29379. eNotation = true;
  29380. } else {
  29381. // the last character doesn't belong to us
  29382. break;
  29383. }
  29384. }
  29385. if (divideBy !== 0) {
  29386. baseValue /= divideBy;
  29387. }
  29388. if (eNotation) {
  29389. baseValue *= Math.pow(10, powerValueSign * powerValue);
  29390. }
  29391. return sign * baseValue;
  29392. },
  29393. getString: function Lexer_getString() {
  29394. var numParen = 1;
  29395. var done = false;
  29396. var strBuf = this.strBuf;
  29397. strBuf.length = 0;
  29398. var ch = this.nextChar();
  29399. while (true) {
  29400. var charBuffered = false;
  29401. switch (ch | 0) {
  29402. case -1:
  29403. warn('Unterminated string');
  29404. done = true;
  29405. break;
  29406. case 0x28: // '('
  29407. ++numParen;
  29408. strBuf.push('(');
  29409. break;
  29410. case 0x29: // ')'
  29411. if (--numParen === 0) {
  29412. this.nextChar(); // consume strings ')'
  29413. done = true;
  29414. } else {
  29415. strBuf.push(')');
  29416. }
  29417. break;
  29418. case 0x5C: // '\\'
  29419. ch = this.nextChar();
  29420. switch (ch) {
  29421. case -1:
  29422. warn('Unterminated string');
  29423. done = true;
  29424. break;
  29425. case 0x6E: // 'n'
  29426. strBuf.push('\n');
  29427. break;
  29428. case 0x72: // 'r'
  29429. strBuf.push('\r');
  29430. break;
  29431. case 0x74: // 't'
  29432. strBuf.push('\t');
  29433. break;
  29434. case 0x62: // 'b'
  29435. strBuf.push('\b');
  29436. break;
  29437. case 0x66: // 'f'
  29438. strBuf.push('\f');
  29439. break;
  29440. case 0x5C: // '\'
  29441. case 0x28: // '('
  29442. case 0x29: // ')'
  29443. strBuf.push(String.fromCharCode(ch));
  29444. break;
  29445. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  29446. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  29447. var x = ch & 0x0F;
  29448. ch = this.nextChar();
  29449. charBuffered = true;
  29450. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29451. x = (x << 3) + (ch & 0x0F);
  29452. ch = this.nextChar();
  29453. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29454. charBuffered = false;
  29455. x = (x << 3) + (ch & 0x0F);
  29456. }
  29457. }
  29458. strBuf.push(String.fromCharCode(x));
  29459. break;
  29460. case 0x0D: // CR
  29461. if (this.peekChar() === 0x0A) { // LF
  29462. this.nextChar();
  29463. }
  29464. break;
  29465. case 0x0A: // LF
  29466. break;
  29467. default:
  29468. strBuf.push(String.fromCharCode(ch));
  29469. break;
  29470. }
  29471. break;
  29472. default:
  29473. strBuf.push(String.fromCharCode(ch));
  29474. break;
  29475. }
  29476. if (done) {
  29477. break;
  29478. }
  29479. if (!charBuffered) {
  29480. ch = this.nextChar();
  29481. }
  29482. }
  29483. return strBuf.join('');
  29484. },
  29485. getName: function Lexer_getName() {
  29486. var ch;
  29487. var strBuf = this.strBuf;
  29488. strBuf.length = 0;
  29489. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29490. if (ch === 0x23) { // '#'
  29491. ch = this.nextChar();
  29492. var x = toHexDigit(ch);
  29493. if (x !== -1) {
  29494. var x2 = toHexDigit(this.nextChar());
  29495. if (x2 === -1) {
  29496. error('Illegal digit in hex char in name: ' + x2);
  29497. }
  29498. strBuf.push(String.fromCharCode((x << 4) | x2));
  29499. } else {
  29500. strBuf.push('#', String.fromCharCode(ch));
  29501. }
  29502. } else {
  29503. strBuf.push(String.fromCharCode(ch));
  29504. }
  29505. }
  29506. if (strBuf.length > 127) {
  29507. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  29508. }
  29509. return Name.get(strBuf.join(''));
  29510. },
  29511. getHexString: function Lexer_getHexString() {
  29512. var strBuf = this.strBuf;
  29513. strBuf.length = 0;
  29514. var ch = this.currentChar;
  29515. var isFirstHex = true;
  29516. var firstDigit;
  29517. var secondDigit;
  29518. while (true) {
  29519. if (ch < 0) {
  29520. warn('Unterminated hex string');
  29521. break;
  29522. } else if (ch === 0x3E) { // '>'
  29523. this.nextChar();
  29524. break;
  29525. } else if (specialChars[ch] === 1) {
  29526. ch = this.nextChar();
  29527. continue;
  29528. } else {
  29529. if (isFirstHex) {
  29530. firstDigit = toHexDigit(ch);
  29531. if (firstDigit === -1) {
  29532. warn('Ignoring invalid character "' + ch + '" in hex string');
  29533. ch = this.nextChar();
  29534. continue;
  29535. }
  29536. } else {
  29537. secondDigit = toHexDigit(ch);
  29538. if (secondDigit === -1) {
  29539. warn('Ignoring invalid character "' + ch + '" in hex string');
  29540. ch = this.nextChar();
  29541. continue;
  29542. }
  29543. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29544. }
  29545. isFirstHex = !isFirstHex;
  29546. ch = this.nextChar();
  29547. }
  29548. }
  29549. return strBuf.join('');
  29550. },
  29551. getObj: function Lexer_getObj() {
  29552. // skip whitespace and comments
  29553. var comment = false;
  29554. var ch = this.currentChar;
  29555. while (true) {
  29556. if (ch < 0) {
  29557. return EOF;
  29558. }
  29559. if (comment) {
  29560. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29561. comment = false;
  29562. }
  29563. } else if (ch === 0x25) { // '%'
  29564. comment = true;
  29565. } else if (specialChars[ch] !== 1) {
  29566. break;
  29567. }
  29568. ch = this.nextChar();
  29569. }
  29570. // start reading token
  29571. switch (ch | 0) {
  29572. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29573. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29574. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29575. return this.getNumber();
  29576. case 0x28: // '('
  29577. return this.getString();
  29578. case 0x2F: // '/'
  29579. return this.getName();
  29580. // array punctuation
  29581. case 0x5B: // '['
  29582. this.nextChar();
  29583. return Cmd.get('[');
  29584. case 0x5D: // ']'
  29585. this.nextChar();
  29586. return Cmd.get(']');
  29587. // hex string or dict punctuation
  29588. case 0x3C: // '<'
  29589. ch = this.nextChar();
  29590. if (ch === 0x3C) {
  29591. // dict punctuation
  29592. this.nextChar();
  29593. return Cmd.get('<<');
  29594. }
  29595. return this.getHexString();
  29596. // dict punctuation
  29597. case 0x3E: // '>'
  29598. ch = this.nextChar();
  29599. if (ch === 0x3E) {
  29600. this.nextChar();
  29601. return Cmd.get('>>');
  29602. }
  29603. return Cmd.get('>');
  29604. case 0x7B: // '{'
  29605. this.nextChar();
  29606. return Cmd.get('{');
  29607. case 0x7D: // '}'
  29608. this.nextChar();
  29609. return Cmd.get('}');
  29610. case 0x29: // ')'
  29611. error('Illegal character: ' + ch);
  29612. break;
  29613. }
  29614. // command
  29615. var str = String.fromCharCode(ch);
  29616. var knownCommands = this.knownCommands;
  29617. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29618. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29619. // stop if known command is found and next character does not make
  29620. // the str a command
  29621. var possibleCommand = str + String.fromCharCode(ch);
  29622. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29623. break;
  29624. }
  29625. if (str.length === 128) {
  29626. error('Command token too long: ' + str.length);
  29627. }
  29628. str = possibleCommand;
  29629. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29630. }
  29631. if (str === 'true') {
  29632. return true;
  29633. }
  29634. if (str === 'false') {
  29635. return false;
  29636. }
  29637. if (str === 'null') {
  29638. return null;
  29639. }
  29640. return Cmd.get(str);
  29641. },
  29642. skipToNextLine: function Lexer_skipToNextLine() {
  29643. var ch = this.currentChar;
  29644. while (ch >= 0) {
  29645. if (ch === 0x0D) { // CR
  29646. ch = this.nextChar();
  29647. if (ch === 0x0A) { // LF
  29648. this.nextChar();
  29649. }
  29650. break;
  29651. } else if (ch === 0x0A) { // LF
  29652. this.nextChar();
  29653. break;
  29654. }
  29655. ch = this.nextChar();
  29656. }
  29657. }
  29658. };
  29659. return Lexer;
  29660. })();
  29661. var Linearization = {
  29662. create: function LinearizationCreate(stream) {
  29663. function getInt(name, allowZeroValue) {
  29664. var obj = linDict.get(name);
  29665. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29666. return obj;
  29667. }
  29668. throw new Error('The "' + name + '" parameter in the linearization ' +
  29669. 'dictionary is invalid.');
  29670. }
  29671. function getHints() {
  29672. var hints = linDict.get('H'), hintsLength, item;
  29673. if (isArray(hints) &&
  29674. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29675. for (var index = 0; index < hintsLength; index++) {
  29676. if (!(isInt(item = hints[index]) && item > 0)) {
  29677. throw new Error('Hint (' + index +
  29678. ') in the linearization dictionary is invalid.');
  29679. }
  29680. }
  29681. return hints;
  29682. }
  29683. throw new Error('Hint array in the linearization dictionary is invalid.');
  29684. }
  29685. var parser = new Parser(new Lexer(stream), false, null);
  29686. var obj1 = parser.getObj();
  29687. var obj2 = parser.getObj();
  29688. var obj3 = parser.getObj();
  29689. var linDict = parser.getObj();
  29690. var obj, length;
  29691. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29692. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29693. return null; // No valid linearization dictionary found.
  29694. } else if ((length = getInt('L')) !== stream.length) {
  29695. throw new Error('The "L" parameter in the linearization dictionary ' +
  29696. 'does not equal the stream length.');
  29697. }
  29698. return {
  29699. length: length,
  29700. hints: getHints(),
  29701. objectNumberFirst: getInt('O'),
  29702. endFirst: getInt('E'),
  29703. numPages: getInt('N'),
  29704. mainXRefEntriesOffset: getInt('T'),
  29705. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29706. };
  29707. }
  29708. };
  29709. var PostScriptParser = (function PostScriptParserClosure() {
  29710. function PostScriptParser(lexer) {
  29711. this.lexer = lexer;
  29712. this.operators = [];
  29713. this.token = null;
  29714. this.prev = null;
  29715. }
  29716. PostScriptParser.prototype = {
  29717. nextToken: function PostScriptParser_nextToken() {
  29718. this.prev = this.token;
  29719. this.token = this.lexer.getToken();
  29720. },
  29721. accept: function PostScriptParser_accept(type) {
  29722. if (this.token.type === type) {
  29723. this.nextToken();
  29724. return true;
  29725. }
  29726. return false;
  29727. },
  29728. expect: function PostScriptParser_expect(type) {
  29729. if (this.accept(type)) {
  29730. return true;
  29731. }
  29732. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29733. type + '.');
  29734. },
  29735. parse: function PostScriptParser_parse() {
  29736. this.nextToken();
  29737. this.expect(PostScriptTokenTypes.LBRACE);
  29738. this.parseBlock();
  29739. this.expect(PostScriptTokenTypes.RBRACE);
  29740. return this.operators;
  29741. },
  29742. parseBlock: function PostScriptParser_parseBlock() {
  29743. while (true) {
  29744. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29745. this.operators.push(this.prev.value);
  29746. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29747. this.operators.push(this.prev.value);
  29748. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29749. this.parseCondition();
  29750. } else {
  29751. return;
  29752. }
  29753. }
  29754. },
  29755. parseCondition: function PostScriptParser_parseCondition() {
  29756. // Add two place holders that will be updated later
  29757. var conditionLocation = this.operators.length;
  29758. this.operators.push(null, null);
  29759. this.parseBlock();
  29760. this.expect(PostScriptTokenTypes.RBRACE);
  29761. if (this.accept(PostScriptTokenTypes.IF)) {
  29762. // The true block is right after the 'if' so it just falls through on
  29763. // true else it jumps and skips the true block.
  29764. this.operators[conditionLocation] = this.operators.length;
  29765. this.operators[conditionLocation + 1] = 'jz';
  29766. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29767. var jumpLocation = this.operators.length;
  29768. this.operators.push(null, null);
  29769. var endOfTrue = this.operators.length;
  29770. this.parseBlock();
  29771. this.expect(PostScriptTokenTypes.RBRACE);
  29772. this.expect(PostScriptTokenTypes.IFELSE);
  29773. // The jump is added at the end of the true block to skip the false
  29774. // block.
  29775. this.operators[jumpLocation] = this.operators.length;
  29776. this.operators[jumpLocation + 1] = 'j';
  29777. this.operators[conditionLocation] = endOfTrue;
  29778. this.operators[conditionLocation + 1] = 'jz';
  29779. } else {
  29780. error('PS Function: error parsing conditional.');
  29781. }
  29782. }
  29783. };
  29784. return PostScriptParser;
  29785. })();
  29786. var PostScriptTokenTypes = {
  29787. LBRACE: 0,
  29788. RBRACE: 1,
  29789. NUMBER: 2,
  29790. OPERATOR: 3,
  29791. IF: 4,
  29792. IFELSE: 5
  29793. };
  29794. var PostScriptToken = (function PostScriptTokenClosure() {
  29795. function PostScriptToken(type, value) {
  29796. this.type = type;
  29797. this.value = value;
  29798. }
  29799. var opCache = {};
  29800. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29801. var opValue = opCache[op];
  29802. if (opValue) {
  29803. return opValue;
  29804. }
  29805. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29806. };
  29807. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29808. '{');
  29809. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29810. '}');
  29811. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29812. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29813. 'IFELSE');
  29814. return PostScriptToken;
  29815. })();
  29816. var PostScriptLexer = (function PostScriptLexerClosure() {
  29817. function PostScriptLexer(stream) {
  29818. this.stream = stream;
  29819. this.nextChar();
  29820. this.strBuf = [];
  29821. }
  29822. PostScriptLexer.prototype = {
  29823. nextChar: function PostScriptLexer_nextChar() {
  29824. return (this.currentChar = this.stream.getByte());
  29825. },
  29826. getToken: function PostScriptLexer_getToken() {
  29827. var comment = false;
  29828. var ch = this.currentChar;
  29829. // skip comments
  29830. while (true) {
  29831. if (ch < 0) {
  29832. return EOF;
  29833. }
  29834. if (comment) {
  29835. if (ch === 0x0A || ch === 0x0D) {
  29836. comment = false;
  29837. }
  29838. } else if (ch === 0x25) { // '%'
  29839. comment = true;
  29840. } else if (!Lexer.isSpace(ch)) {
  29841. break;
  29842. }
  29843. ch = this.nextChar();
  29844. }
  29845. switch (ch | 0) {
  29846. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29847. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29848. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29849. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29850. this.getNumber());
  29851. case 0x7B: // '{'
  29852. this.nextChar();
  29853. return PostScriptToken.LBRACE;
  29854. case 0x7D: // '}'
  29855. this.nextChar();
  29856. return PostScriptToken.RBRACE;
  29857. }
  29858. // operator
  29859. var strBuf = this.strBuf;
  29860. strBuf.length = 0;
  29861. strBuf[0] = String.fromCharCode(ch);
  29862. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29863. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29864. strBuf.push(String.fromCharCode(ch));
  29865. }
  29866. var str = strBuf.join('');
  29867. switch (str.toLowerCase()) {
  29868. case 'if':
  29869. return PostScriptToken.IF;
  29870. case 'ifelse':
  29871. return PostScriptToken.IFELSE;
  29872. default:
  29873. return PostScriptToken.getOperator(str);
  29874. }
  29875. },
  29876. getNumber: function PostScriptLexer_getNumber() {
  29877. var ch = this.currentChar;
  29878. var strBuf = this.strBuf;
  29879. strBuf.length = 0;
  29880. strBuf[0] = String.fromCharCode(ch);
  29881. while ((ch = this.nextChar()) >= 0) {
  29882. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29883. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29884. strBuf.push(String.fromCharCode(ch));
  29885. } else {
  29886. break;
  29887. }
  29888. }
  29889. var value = parseFloat(strBuf.join(''));
  29890. if (isNaN(value)) {
  29891. error('Invalid floating point number: ' + value);
  29892. }
  29893. return value;
  29894. }
  29895. };
  29896. return PostScriptLexer;
  29897. })();
  29898. var Stream = (function StreamClosure() {
  29899. function Stream(arrayBuffer, start, length, dict) {
  29900. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29901. arrayBuffer : new Uint8Array(arrayBuffer));
  29902. this.start = start || 0;
  29903. this.pos = this.start;
  29904. this.end = (start + length) || this.bytes.length;
  29905. this.dict = dict;
  29906. }
  29907. // required methods for a stream. if a particular stream does not
  29908. // implement these, an error should be thrown
  29909. Stream.prototype = {
  29910. get length() {
  29911. return this.end - this.start;
  29912. },
  29913. get isEmpty() {
  29914. return this.length === 0;
  29915. },
  29916. getByte: function Stream_getByte() {
  29917. if (this.pos >= this.end) {
  29918. return -1;
  29919. }
  29920. return this.bytes[this.pos++];
  29921. },
  29922. getUint16: function Stream_getUint16() {
  29923. var b0 = this.getByte();
  29924. var b1 = this.getByte();
  29925. if (b0 === -1 || b1 === -1) {
  29926. return -1;
  29927. }
  29928. return (b0 << 8) + b1;
  29929. },
  29930. getInt32: function Stream_getInt32() {
  29931. var b0 = this.getByte();
  29932. var b1 = this.getByte();
  29933. var b2 = this.getByte();
  29934. var b3 = this.getByte();
  29935. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29936. },
  29937. // returns subarray of original buffer
  29938. // should only be read
  29939. getBytes: function Stream_getBytes(length) {
  29940. var bytes = this.bytes;
  29941. var pos = this.pos;
  29942. var strEnd = this.end;
  29943. if (!length) {
  29944. return bytes.subarray(pos, strEnd);
  29945. }
  29946. var end = pos + length;
  29947. if (end > strEnd) {
  29948. end = strEnd;
  29949. }
  29950. this.pos = end;
  29951. return bytes.subarray(pos, end);
  29952. },
  29953. peekByte: function Stream_peekByte() {
  29954. var peekedByte = this.getByte();
  29955. this.pos--;
  29956. return peekedByte;
  29957. },
  29958. peekBytes: function Stream_peekBytes(length) {
  29959. var bytes = this.getBytes(length);
  29960. this.pos -= bytes.length;
  29961. return bytes;
  29962. },
  29963. skip: function Stream_skip(n) {
  29964. if (!n) {
  29965. n = 1;
  29966. }
  29967. this.pos += n;
  29968. },
  29969. reset: function Stream_reset() {
  29970. this.pos = this.start;
  29971. },
  29972. moveStart: function Stream_moveStart() {
  29973. this.start = this.pos;
  29974. },
  29975. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29976. return new Stream(this.bytes.buffer, start, length, dict);
  29977. },
  29978. isStream: true
  29979. };
  29980. return Stream;
  29981. })();
  29982. var StringStream = (function StringStreamClosure() {
  29983. function StringStream(str) {
  29984. var length = str.length;
  29985. var bytes = new Uint8Array(length);
  29986. for (var n = 0; n < length; ++n) {
  29987. bytes[n] = str.charCodeAt(n);
  29988. }
  29989. Stream.call(this, bytes);
  29990. }
  29991. StringStream.prototype = Stream.prototype;
  29992. return StringStream;
  29993. })();
  29994. // super class for the decoding streams
  29995. var DecodeStream = (function DecodeStreamClosure() {
  29996. // Lots of DecodeStreams are created whose buffers are never used. For these
  29997. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29998. // having special cases that would be required if we used |null| for an empty
  29999. // buffer.
  30000. var emptyBuffer = new Uint8Array(0);
  30001. function DecodeStream(maybeMinBufferLength) {
  30002. this.pos = 0;
  30003. this.bufferLength = 0;
  30004. this.eof = false;
  30005. this.buffer = emptyBuffer;
  30006. this.minBufferLength = 512;
  30007. if (maybeMinBufferLength) {
  30008. // Compute the first power of two that is as big as maybeMinBufferLength.
  30009. while (this.minBufferLength < maybeMinBufferLength) {
  30010. this.minBufferLength *= 2;
  30011. }
  30012. }
  30013. }
  30014. DecodeStream.prototype = {
  30015. get isEmpty() {
  30016. while (!this.eof && this.bufferLength === 0) {
  30017. this.readBlock();
  30018. }
  30019. return this.bufferLength === 0;
  30020. },
  30021. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  30022. var buffer = this.buffer;
  30023. if (requested <= buffer.byteLength) {
  30024. return buffer;
  30025. }
  30026. var size = this.minBufferLength;
  30027. while (size < requested) {
  30028. size *= 2;
  30029. }
  30030. var buffer2 = new Uint8Array(size);
  30031. buffer2.set(buffer);
  30032. return (this.buffer = buffer2);
  30033. },
  30034. getByte: function DecodeStream_getByte() {
  30035. var pos = this.pos;
  30036. while (this.bufferLength <= pos) {
  30037. if (this.eof) {
  30038. return -1;
  30039. }
  30040. this.readBlock();
  30041. }
  30042. return this.buffer[this.pos++];
  30043. },
  30044. getUint16: function DecodeStream_getUint16() {
  30045. var b0 = this.getByte();
  30046. var b1 = this.getByte();
  30047. if (b0 === -1 || b1 === -1) {
  30048. return -1;
  30049. }
  30050. return (b0 << 8) + b1;
  30051. },
  30052. getInt32: function DecodeStream_getInt32() {
  30053. var b0 = this.getByte();
  30054. var b1 = this.getByte();
  30055. var b2 = this.getByte();
  30056. var b3 = this.getByte();
  30057. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30058. },
  30059. getBytes: function DecodeStream_getBytes(length) {
  30060. var end, pos = this.pos;
  30061. if (length) {
  30062. this.ensureBuffer(pos + length);
  30063. end = pos + length;
  30064. while (!this.eof && this.bufferLength < end) {
  30065. this.readBlock();
  30066. }
  30067. var bufEnd = this.bufferLength;
  30068. if (end > bufEnd) {
  30069. end = bufEnd;
  30070. }
  30071. } else {
  30072. while (!this.eof) {
  30073. this.readBlock();
  30074. }
  30075. end = this.bufferLength;
  30076. }
  30077. this.pos = end;
  30078. return this.buffer.subarray(pos, end);
  30079. },
  30080. peekByte: function DecodeStream_peekByte() {
  30081. var peekedByte = this.getByte();
  30082. this.pos--;
  30083. return peekedByte;
  30084. },
  30085. peekBytes: function DecodeStream_peekBytes(length) {
  30086. var bytes = this.getBytes(length);
  30087. this.pos -= bytes.length;
  30088. return bytes;
  30089. },
  30090. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  30091. var end = start + length;
  30092. while (this.bufferLength <= end && !this.eof) {
  30093. this.readBlock();
  30094. }
  30095. return new Stream(this.buffer, start, length, dict);
  30096. },
  30097. skip: function DecodeStream_skip(n) {
  30098. if (!n) {
  30099. n = 1;
  30100. }
  30101. this.pos += n;
  30102. },
  30103. reset: function DecodeStream_reset() {
  30104. this.pos = 0;
  30105. },
  30106. getBaseStreams: function DecodeStream_getBaseStreams() {
  30107. if (this.str && this.str.getBaseStreams) {
  30108. return this.str.getBaseStreams();
  30109. }
  30110. return [];
  30111. }
  30112. };
  30113. return DecodeStream;
  30114. })();
  30115. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  30116. function StreamsSequenceStream(streams) {
  30117. this.streams = streams;
  30118. DecodeStream.call(this, /* maybeLength = */ null);
  30119. }
  30120. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  30121. StreamsSequenceStream.prototype.readBlock =
  30122. function streamSequenceStreamReadBlock() {
  30123. var streams = this.streams;
  30124. if (streams.length === 0) {
  30125. this.eof = true;
  30126. return;
  30127. }
  30128. var stream = streams.shift();
  30129. var chunk = stream.getBytes();
  30130. var bufferLength = this.bufferLength;
  30131. var newLength = bufferLength + chunk.length;
  30132. var buffer = this.ensureBuffer(newLength);
  30133. buffer.set(chunk, bufferLength);
  30134. this.bufferLength = newLength;
  30135. };
  30136. StreamsSequenceStream.prototype.getBaseStreams =
  30137. function StreamsSequenceStream_getBaseStreams() {
  30138. var baseStreams = [];
  30139. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  30140. var stream = this.streams[i];
  30141. if (stream.getBaseStreams) {
  30142. Util.appendToArray(baseStreams, stream.getBaseStreams());
  30143. }
  30144. }
  30145. return baseStreams;
  30146. };
  30147. return StreamsSequenceStream;
  30148. })();
  30149. var FlateStream = (function FlateStreamClosure() {
  30150. var codeLenCodeMap = new Int32Array([
  30151. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  30152. ]);
  30153. var lengthDecode = new Int32Array([
  30154. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  30155. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  30156. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  30157. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  30158. ]);
  30159. var distDecode = new Int32Array([
  30160. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  30161. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  30162. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  30163. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  30164. ]);
  30165. var fixedLitCodeTab = [new Int32Array([
  30166. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  30167. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  30168. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  30169. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  30170. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  30171. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  30172. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  30173. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  30174. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  30175. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  30176. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  30177. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  30178. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  30179. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  30180. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  30181. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  30182. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  30183. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  30184. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  30185. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  30186. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  30187. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  30188. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  30189. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  30190. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  30191. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  30192. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  30193. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  30194. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  30195. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  30196. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  30197. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  30198. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  30199. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  30200. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  30201. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  30202. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  30203. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  30204. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  30205. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  30206. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  30207. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  30208. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  30209. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  30210. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  30211. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  30212. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  30213. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  30214. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  30215. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  30216. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  30217. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  30218. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  30219. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  30220. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  30221. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  30222. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  30223. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  30224. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  30225. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  30226. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  30227. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  30228. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  30229. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  30230. ]), 9];
  30231. var fixedDistCodeTab = [new Int32Array([
  30232. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  30233. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  30234. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  30235. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  30236. ]), 5];
  30237. function FlateStream(str, maybeLength) {
  30238. this.str = str;
  30239. this.dict = str.dict;
  30240. var cmf = str.getByte();
  30241. var flg = str.getByte();
  30242. if (cmf === -1 || flg === -1) {
  30243. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  30244. }
  30245. if ((cmf & 0x0f) !== 0x08) {
  30246. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  30247. }
  30248. if ((((cmf << 8) + flg) % 31) !== 0) {
  30249. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  30250. }
  30251. if (flg & 0x20) {
  30252. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  30253. }
  30254. this.codeSize = 0;
  30255. this.codeBuf = 0;
  30256. DecodeStream.call(this, maybeLength);
  30257. }
  30258. FlateStream.prototype = Object.create(DecodeStream.prototype);
  30259. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  30260. var str = this.str;
  30261. var codeSize = this.codeSize;
  30262. var codeBuf = this.codeBuf;
  30263. var b;
  30264. while (codeSize < bits) {
  30265. if ((b = str.getByte()) === -1) {
  30266. error('Bad encoding in flate stream');
  30267. }
  30268. codeBuf |= b << codeSize;
  30269. codeSize += 8;
  30270. }
  30271. b = codeBuf & ((1 << bits) - 1);
  30272. this.codeBuf = codeBuf >> bits;
  30273. this.codeSize = codeSize -= bits;
  30274. return b;
  30275. };
  30276. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  30277. var str = this.str;
  30278. var codes = table[0];
  30279. var maxLen = table[1];
  30280. var codeSize = this.codeSize;
  30281. var codeBuf = this.codeBuf;
  30282. var b;
  30283. while (codeSize < maxLen) {
  30284. if ((b = str.getByte()) === -1) {
  30285. // premature end of stream. code might however still be valid.
  30286. // codeSize < codeLen check below guards against incomplete codeVal.
  30287. break;
  30288. }
  30289. codeBuf |= (b << codeSize);
  30290. codeSize += 8;
  30291. }
  30292. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  30293. var codeLen = code >> 16;
  30294. var codeVal = code & 0xffff;
  30295. if (codeLen < 1 || codeSize < codeLen) {
  30296. error('Bad encoding in flate stream');
  30297. }
  30298. this.codeBuf = (codeBuf >> codeLen);
  30299. this.codeSize = (codeSize - codeLen);
  30300. return codeVal;
  30301. };
  30302. FlateStream.prototype.generateHuffmanTable =
  30303. function flateStreamGenerateHuffmanTable(lengths) {
  30304. var n = lengths.length;
  30305. // find max code length
  30306. var maxLen = 0;
  30307. var i;
  30308. for (i = 0; i < n; ++i) {
  30309. if (lengths[i] > maxLen) {
  30310. maxLen = lengths[i];
  30311. }
  30312. }
  30313. // build the table
  30314. var size = 1 << maxLen;
  30315. var codes = new Int32Array(size);
  30316. for (var len = 1, code = 0, skip = 2;
  30317. len <= maxLen;
  30318. ++len, code <<= 1, skip <<= 1) {
  30319. for (var val = 0; val < n; ++val) {
  30320. if (lengths[val] === len) {
  30321. // bit-reverse the code
  30322. var code2 = 0;
  30323. var t = code;
  30324. for (i = 0; i < len; ++i) {
  30325. code2 = (code2 << 1) | (t & 1);
  30326. t >>= 1;
  30327. }
  30328. // fill the table entries
  30329. for (i = code2; i < size; i += skip) {
  30330. codes[i] = (len << 16) | val;
  30331. }
  30332. ++code;
  30333. }
  30334. }
  30335. }
  30336. return [codes, maxLen];
  30337. };
  30338. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  30339. var buffer, len;
  30340. var str = this.str;
  30341. // read block header
  30342. var hdr = this.getBits(3);
  30343. if (hdr & 1) {
  30344. this.eof = true;
  30345. }
  30346. hdr >>= 1;
  30347. if (hdr === 0) { // uncompressed block
  30348. var b;
  30349. if ((b = str.getByte()) === -1) {
  30350. error('Bad block header in flate stream');
  30351. }
  30352. var blockLen = b;
  30353. if ((b = str.getByte()) === -1) {
  30354. error('Bad block header in flate stream');
  30355. }
  30356. blockLen |= (b << 8);
  30357. if ((b = str.getByte()) === -1) {
  30358. error('Bad block header in flate stream');
  30359. }
  30360. var check = b;
  30361. if ((b = str.getByte()) === -1) {
  30362. error('Bad block header in flate stream');
  30363. }
  30364. check |= (b << 8);
  30365. if (check !== (~blockLen & 0xffff) &&
  30366. (blockLen !== 0 || check !== 0)) {
  30367. // Ignoring error for bad "empty" block (see issue 1277)
  30368. error('Bad uncompressed block length in flate stream');
  30369. }
  30370. this.codeBuf = 0;
  30371. this.codeSize = 0;
  30372. var bufferLength = this.bufferLength;
  30373. buffer = this.ensureBuffer(bufferLength + blockLen);
  30374. var end = bufferLength + blockLen;
  30375. this.bufferLength = end;
  30376. if (blockLen === 0) {
  30377. if (str.peekByte() === -1) {
  30378. this.eof = true;
  30379. }
  30380. } else {
  30381. for (var n = bufferLength; n < end; ++n) {
  30382. if ((b = str.getByte()) === -1) {
  30383. this.eof = true;
  30384. break;
  30385. }
  30386. buffer[n] = b;
  30387. }
  30388. }
  30389. return;
  30390. }
  30391. var litCodeTable;
  30392. var distCodeTable;
  30393. if (hdr === 1) { // compressed block, fixed codes
  30394. litCodeTable = fixedLitCodeTab;
  30395. distCodeTable = fixedDistCodeTab;
  30396. } else if (hdr === 2) { // compressed block, dynamic codes
  30397. var numLitCodes = this.getBits(5) + 257;
  30398. var numDistCodes = this.getBits(5) + 1;
  30399. var numCodeLenCodes = this.getBits(4) + 4;
  30400. // build the code lengths code table
  30401. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  30402. var i;
  30403. for (i = 0; i < numCodeLenCodes; ++i) {
  30404. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  30405. }
  30406. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  30407. // build the literal and distance code tables
  30408. len = 0;
  30409. i = 0;
  30410. var codes = numLitCodes + numDistCodes;
  30411. var codeLengths = new Uint8Array(codes);
  30412. var bitsLength, bitsOffset, what;
  30413. while (i < codes) {
  30414. var code = this.getCode(codeLenCodeTab);
  30415. if (code === 16) {
  30416. bitsLength = 2; bitsOffset = 3; what = len;
  30417. } else if (code === 17) {
  30418. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  30419. } else if (code === 18) {
  30420. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  30421. } else {
  30422. codeLengths[i++] = len = code;
  30423. continue;
  30424. }
  30425. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  30426. while (repeatLength-- > 0) {
  30427. codeLengths[i++] = what;
  30428. }
  30429. }
  30430. litCodeTable =
  30431. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  30432. distCodeTable =
  30433. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  30434. } else {
  30435. error('Unknown block type in flate stream');
  30436. }
  30437. buffer = this.buffer;
  30438. var limit = buffer ? buffer.length : 0;
  30439. var pos = this.bufferLength;
  30440. while (true) {
  30441. var code1 = this.getCode(litCodeTable);
  30442. if (code1 < 256) {
  30443. if (pos + 1 >= limit) {
  30444. buffer = this.ensureBuffer(pos + 1);
  30445. limit = buffer.length;
  30446. }
  30447. buffer[pos++] = code1;
  30448. continue;
  30449. }
  30450. if (code1 === 256) {
  30451. this.bufferLength = pos;
  30452. return;
  30453. }
  30454. code1 -= 257;
  30455. code1 = lengthDecode[code1];
  30456. var code2 = code1 >> 16;
  30457. if (code2 > 0) {
  30458. code2 = this.getBits(code2);
  30459. }
  30460. len = (code1 & 0xffff) + code2;
  30461. code1 = this.getCode(distCodeTable);
  30462. code1 = distDecode[code1];
  30463. code2 = code1 >> 16;
  30464. if (code2 > 0) {
  30465. code2 = this.getBits(code2);
  30466. }
  30467. var dist = (code1 & 0xffff) + code2;
  30468. if (pos + len >= limit) {
  30469. buffer = this.ensureBuffer(pos + len);
  30470. limit = buffer.length;
  30471. }
  30472. for (var k = 0; k < len; ++k, ++pos) {
  30473. buffer[pos] = buffer[pos - dist];
  30474. }
  30475. }
  30476. };
  30477. return FlateStream;
  30478. })();
  30479. var PredictorStream = (function PredictorStreamClosure() {
  30480. function PredictorStream(str, maybeLength, params) {
  30481. var predictor = this.predictor = params.get('Predictor') || 1;
  30482. if (predictor <= 1) {
  30483. return str; // no prediction
  30484. }
  30485. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30486. error('Unsupported predictor: ' + predictor);
  30487. }
  30488. if (predictor === 2) {
  30489. this.readBlock = this.readBlockTiff;
  30490. } else {
  30491. this.readBlock = this.readBlockPng;
  30492. }
  30493. this.str = str;
  30494. this.dict = str.dict;
  30495. var colors = this.colors = params.get('Colors') || 1;
  30496. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30497. var columns = this.columns = params.get('Columns') || 1;
  30498. this.pixBytes = (colors * bits + 7) >> 3;
  30499. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30500. DecodeStream.call(this, maybeLength);
  30501. return this;
  30502. }
  30503. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30504. PredictorStream.prototype.readBlockTiff =
  30505. function predictorStreamReadBlockTiff() {
  30506. var rowBytes = this.rowBytes;
  30507. var bufferLength = this.bufferLength;
  30508. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30509. var bits = this.bits;
  30510. var colors = this.colors;
  30511. var rawBytes = this.str.getBytes(rowBytes);
  30512. this.eof = !rawBytes.length;
  30513. if (this.eof) {
  30514. return;
  30515. }
  30516. var inbuf = 0, outbuf = 0;
  30517. var inbits = 0, outbits = 0;
  30518. var pos = bufferLength;
  30519. var i;
  30520. if (bits === 1) {
  30521. for (i = 0; i < rowBytes; ++i) {
  30522. var c = rawBytes[i];
  30523. inbuf = (inbuf << 8) | c;
  30524. // bitwise addition is exclusive or
  30525. // first shift inbuf and then add
  30526. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30527. // truncate inbuf (assumes colors < 16)
  30528. inbuf &= 0xFFFF;
  30529. }
  30530. } else if (bits === 8) {
  30531. for (i = 0; i < colors; ++i) {
  30532. buffer[pos++] = rawBytes[i];
  30533. }
  30534. for (; i < rowBytes; ++i) {
  30535. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30536. pos++;
  30537. }
  30538. } else {
  30539. var compArray = new Uint8Array(colors + 1);
  30540. var bitMask = (1 << bits) - 1;
  30541. var j = 0, k = bufferLength;
  30542. var columns = this.columns;
  30543. for (i = 0; i < columns; ++i) {
  30544. for (var kk = 0; kk < colors; ++kk) {
  30545. if (inbits < bits) {
  30546. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30547. inbits += 8;
  30548. }
  30549. compArray[kk] = (compArray[kk] +
  30550. (inbuf >> (inbits - bits))) & bitMask;
  30551. inbits -= bits;
  30552. outbuf = (outbuf << bits) | compArray[kk];
  30553. outbits += bits;
  30554. if (outbits >= 8) {
  30555. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30556. outbits -= 8;
  30557. }
  30558. }
  30559. }
  30560. if (outbits > 0) {
  30561. buffer[k++] = (outbuf << (8 - outbits)) +
  30562. (inbuf & ((1 << (8 - outbits)) - 1));
  30563. }
  30564. }
  30565. this.bufferLength += rowBytes;
  30566. };
  30567. PredictorStream.prototype.readBlockPng =
  30568. function predictorStreamReadBlockPng() {
  30569. var rowBytes = this.rowBytes;
  30570. var pixBytes = this.pixBytes;
  30571. var predictor = this.str.getByte();
  30572. var rawBytes = this.str.getBytes(rowBytes);
  30573. this.eof = !rawBytes.length;
  30574. if (this.eof) {
  30575. return;
  30576. }
  30577. var bufferLength = this.bufferLength;
  30578. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30579. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30580. if (prevRow.length === 0) {
  30581. prevRow = new Uint8Array(rowBytes);
  30582. }
  30583. var i, j = bufferLength, up, c;
  30584. switch (predictor) {
  30585. case 0:
  30586. for (i = 0; i < rowBytes; ++i) {
  30587. buffer[j++] = rawBytes[i];
  30588. }
  30589. break;
  30590. case 1:
  30591. for (i = 0; i < pixBytes; ++i) {
  30592. buffer[j++] = rawBytes[i];
  30593. }
  30594. for (; i < rowBytes; ++i) {
  30595. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30596. j++;
  30597. }
  30598. break;
  30599. case 2:
  30600. for (i = 0; i < rowBytes; ++i) {
  30601. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30602. }
  30603. break;
  30604. case 3:
  30605. for (i = 0; i < pixBytes; ++i) {
  30606. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30607. }
  30608. for (; i < rowBytes; ++i) {
  30609. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30610. rawBytes[i]) & 0xFF;
  30611. j++;
  30612. }
  30613. break;
  30614. case 4:
  30615. // we need to save the up left pixels values. the simplest way
  30616. // is to create a new buffer
  30617. for (i = 0; i < pixBytes; ++i) {
  30618. up = prevRow[i];
  30619. c = rawBytes[i];
  30620. buffer[j++] = up + c;
  30621. }
  30622. for (; i < rowBytes; ++i) {
  30623. up = prevRow[i];
  30624. var upLeft = prevRow[i - pixBytes];
  30625. var left = buffer[j - pixBytes];
  30626. var p = left + up - upLeft;
  30627. var pa = p - left;
  30628. if (pa < 0) {
  30629. pa = -pa;
  30630. }
  30631. var pb = p - up;
  30632. if (pb < 0) {
  30633. pb = -pb;
  30634. }
  30635. var pc = p - upLeft;
  30636. if (pc < 0) {
  30637. pc = -pc;
  30638. }
  30639. c = rawBytes[i];
  30640. if (pa <= pb && pa <= pc) {
  30641. buffer[j++] = left + c;
  30642. } else if (pb <= pc) {
  30643. buffer[j++] = up + c;
  30644. } else {
  30645. buffer[j++] = upLeft + c;
  30646. }
  30647. }
  30648. break;
  30649. default:
  30650. error('Unsupported predictor: ' + predictor);
  30651. }
  30652. this.bufferLength += rowBytes;
  30653. };
  30654. return PredictorStream;
  30655. })();
  30656. /**
  30657. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30658. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30659. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30660. * a library to decode these images and the stream behaves like all the other
  30661. * DecodeStreams.
  30662. */
  30663. var JpegStream = (function JpegStreamClosure() {
  30664. function JpegStream(stream, maybeLength, dict, xref) {
  30665. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30666. // Note: this seems to mainly affect inline images.
  30667. var ch;
  30668. while ((ch = stream.getByte()) !== -1) {
  30669. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30670. stream.skip(-1); // Reset the stream position to the SOI.
  30671. break;
  30672. }
  30673. }
  30674. this.stream = stream;
  30675. this.maybeLength = maybeLength;
  30676. this.dict = dict;
  30677. DecodeStream.call(this, maybeLength);
  30678. }
  30679. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30680. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30681. get: function JpegStream_bytes() {
  30682. // If this.maybeLength is null, we'll get the entire stream.
  30683. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30684. },
  30685. configurable: true
  30686. });
  30687. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30688. if (this.bufferLength) {
  30689. return;
  30690. }
  30691. try {
  30692. var jpegImage = new JpegImage();
  30693. // checking if values needs to be transformed before conversion
  30694. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30695. var decodeArr = this.dict.get('Decode');
  30696. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30697. var decodeArrLength = decodeArr.length;
  30698. var transform = new Int32Array(decodeArrLength);
  30699. var transformNeeded = false;
  30700. var maxValue = (1 << bitsPerComponent) - 1;
  30701. for (var i = 0; i < decodeArrLength; i += 2) {
  30702. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30703. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30704. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30705. transformNeeded = true;
  30706. }
  30707. }
  30708. if (transformNeeded) {
  30709. jpegImage.decodeTransform = transform;
  30710. }
  30711. }
  30712. jpegImage.parse(this.bytes);
  30713. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30714. this.forceRGB);
  30715. this.buffer = data;
  30716. this.bufferLength = data.length;
  30717. this.eof = true;
  30718. } catch (e) {
  30719. error('JPEG error: ' + e);
  30720. }
  30721. };
  30722. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30723. this.ensureBuffer();
  30724. return this.buffer;
  30725. };
  30726. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30727. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30728. };
  30729. /**
  30730. * Checks if the image can be decoded and displayed by the browser without any
  30731. * further processing such as color space conversions.
  30732. */
  30733. JpegStream.prototype.isNativelySupported =
  30734. function JpegStream_isNativelySupported(xref, res) {
  30735. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30736. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  30737. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  30738. };
  30739. /**
  30740. * Checks if the image can be decoded by the browser.
  30741. */
  30742. JpegStream.prototype.isNativelyDecodable =
  30743. function JpegStream_isNativelyDecodable(xref, res) {
  30744. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30745. return (cs.numComps === 1 || cs.numComps === 3) &&
  30746. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  30747. };
  30748. return JpegStream;
  30749. })();
  30750. /**
  30751. * For JPEG 2000's we use a library to decode these images and
  30752. * the stream behaves like all the other DecodeStreams.
  30753. */
  30754. var JpxStream = (function JpxStreamClosure() {
  30755. function JpxStream(stream, maybeLength, dict) {
  30756. this.stream = stream;
  30757. this.maybeLength = maybeLength;
  30758. this.dict = dict;
  30759. DecodeStream.call(this, maybeLength);
  30760. }
  30761. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30762. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30763. get: function JpxStream_bytes() {
  30764. // If this.maybeLength is null, we'll get the entire stream.
  30765. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30766. },
  30767. configurable: true
  30768. });
  30769. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30770. if (this.bufferLength) {
  30771. return;
  30772. }
  30773. var jpxImage = new JpxImage();
  30774. jpxImage.parse(this.bytes);
  30775. var width = jpxImage.width;
  30776. var height = jpxImage.height;
  30777. var componentsCount = jpxImage.componentsCount;
  30778. var tileCount = jpxImage.tiles.length;
  30779. if (tileCount === 1) {
  30780. this.buffer = jpxImage.tiles[0].items;
  30781. } else {
  30782. var data = new Uint8Array(width * height * componentsCount);
  30783. for (var k = 0; k < tileCount; k++) {
  30784. var tileComponents = jpxImage.tiles[k];
  30785. var tileWidth = tileComponents.width;
  30786. var tileHeight = tileComponents.height;
  30787. var tileLeft = tileComponents.left;
  30788. var tileTop = tileComponents.top;
  30789. var src = tileComponents.items;
  30790. var srcPosition = 0;
  30791. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30792. var imgRowSize = width * componentsCount;
  30793. var tileRowSize = tileWidth * componentsCount;
  30794. for (var j = 0; j < tileHeight; j++) {
  30795. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30796. data.set(rowBytes, dataPosition);
  30797. srcPosition += tileRowSize;
  30798. dataPosition += imgRowSize;
  30799. }
  30800. }
  30801. this.buffer = data;
  30802. }
  30803. this.bufferLength = this.buffer.length;
  30804. this.eof = true;
  30805. };
  30806. return JpxStream;
  30807. })();
  30808. /**
  30809. * For JBIG2's we use a library to decode these images and
  30810. * the stream behaves like all the other DecodeStreams.
  30811. */
  30812. var Jbig2Stream = (function Jbig2StreamClosure() {
  30813. function Jbig2Stream(stream, maybeLength, dict) {
  30814. this.stream = stream;
  30815. this.maybeLength = maybeLength;
  30816. this.dict = dict;
  30817. DecodeStream.call(this, maybeLength);
  30818. }
  30819. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30820. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30821. get: function Jbig2Stream_bytes() {
  30822. // If this.maybeLength is null, we'll get the entire stream.
  30823. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30824. },
  30825. configurable: true
  30826. });
  30827. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30828. if (this.bufferLength) {
  30829. return;
  30830. }
  30831. var jbig2Image = new Jbig2Image();
  30832. var chunks = [], xref = this.dict.xref;
  30833. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30834. // According to the PDF specification, DecodeParms can be either
  30835. // a dictionary, or an array whose elements are dictionaries.
  30836. if (isArray(decodeParams)) {
  30837. if (decodeParams.length > 1) {
  30838. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30839. 'not supported.');
  30840. }
  30841. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30842. }
  30843. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30844. var globalsStream = decodeParams.get('JBIG2Globals');
  30845. var globals = globalsStream.getBytes();
  30846. chunks.push({data: globals, start: 0, end: globals.length});
  30847. }
  30848. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30849. var data = jbig2Image.parseChunks(chunks);
  30850. var dataLength = data.length;
  30851. // JBIG2 had black as 1 and white as 0, inverting the colors
  30852. for (var i = 0; i < dataLength; i++) {
  30853. data[i] ^= 0xFF;
  30854. }
  30855. this.buffer = data;
  30856. this.bufferLength = dataLength;
  30857. this.eof = true;
  30858. };
  30859. return Jbig2Stream;
  30860. })();
  30861. var DecryptStream = (function DecryptStreamClosure() {
  30862. function DecryptStream(str, maybeLength, decrypt) {
  30863. this.str = str;
  30864. this.dict = str.dict;
  30865. this.decrypt = decrypt;
  30866. this.nextChunk = null;
  30867. this.initialized = false;
  30868. DecodeStream.call(this, maybeLength);
  30869. }
  30870. var chunkSize = 512;
  30871. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30872. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30873. var chunk;
  30874. if (this.initialized) {
  30875. chunk = this.nextChunk;
  30876. } else {
  30877. chunk = this.str.getBytes(chunkSize);
  30878. this.initialized = true;
  30879. }
  30880. if (!chunk || chunk.length === 0) {
  30881. this.eof = true;
  30882. return;
  30883. }
  30884. this.nextChunk = this.str.getBytes(chunkSize);
  30885. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30886. var decrypt = this.decrypt;
  30887. chunk = decrypt(chunk, !hasMoreData);
  30888. var bufferLength = this.bufferLength;
  30889. var i, n = chunk.length;
  30890. var buffer = this.ensureBuffer(bufferLength + n);
  30891. for (i = 0; i < n; i++) {
  30892. buffer[bufferLength++] = chunk[i];
  30893. }
  30894. this.bufferLength = bufferLength;
  30895. };
  30896. return DecryptStream;
  30897. })();
  30898. var Ascii85Stream = (function Ascii85StreamClosure() {
  30899. function Ascii85Stream(str, maybeLength) {
  30900. this.str = str;
  30901. this.dict = str.dict;
  30902. this.input = new Uint8Array(5);
  30903. // Most streams increase in size when decoded, but Ascii85 streams
  30904. // typically shrink by ~20%.
  30905. if (maybeLength) {
  30906. maybeLength = 0.8 * maybeLength;
  30907. }
  30908. DecodeStream.call(this, maybeLength);
  30909. }
  30910. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30911. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30912. var TILDA_CHAR = 0x7E; // '~'
  30913. var Z_LOWER_CHAR = 0x7A; // 'z'
  30914. var EOF = -1;
  30915. var str = this.str;
  30916. var c = str.getByte();
  30917. while (Lexer.isSpace(c)) {
  30918. c = str.getByte();
  30919. }
  30920. if (c === EOF || c === TILDA_CHAR) {
  30921. this.eof = true;
  30922. return;
  30923. }
  30924. var bufferLength = this.bufferLength, buffer;
  30925. var i;
  30926. // special code for z
  30927. if (c === Z_LOWER_CHAR) {
  30928. buffer = this.ensureBuffer(bufferLength + 4);
  30929. for (i = 0; i < 4; ++i) {
  30930. buffer[bufferLength + i] = 0;
  30931. }
  30932. this.bufferLength += 4;
  30933. } else {
  30934. var input = this.input;
  30935. input[0] = c;
  30936. for (i = 1; i < 5; ++i) {
  30937. c = str.getByte();
  30938. while (Lexer.isSpace(c)) {
  30939. c = str.getByte();
  30940. }
  30941. input[i] = c;
  30942. if (c === EOF || c === TILDA_CHAR) {
  30943. break;
  30944. }
  30945. }
  30946. buffer = this.ensureBuffer(bufferLength + i - 1);
  30947. this.bufferLength += i - 1;
  30948. // partial ending;
  30949. if (i < 5) {
  30950. for (; i < 5; ++i) {
  30951. input[i] = 0x21 + 84;
  30952. }
  30953. this.eof = true;
  30954. }
  30955. var t = 0;
  30956. for (i = 0; i < 5; ++i) {
  30957. t = t * 85 + (input[i] - 0x21);
  30958. }
  30959. for (i = 3; i >= 0; --i) {
  30960. buffer[bufferLength + i] = t & 0xFF;
  30961. t >>= 8;
  30962. }
  30963. }
  30964. };
  30965. return Ascii85Stream;
  30966. })();
  30967. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30968. function AsciiHexStream(str, maybeLength) {
  30969. this.str = str;
  30970. this.dict = str.dict;
  30971. this.firstDigit = -1;
  30972. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30973. // by 50%.
  30974. if (maybeLength) {
  30975. maybeLength = 0.5 * maybeLength;
  30976. }
  30977. DecodeStream.call(this, maybeLength);
  30978. }
  30979. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30980. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30981. var UPSTREAM_BLOCK_SIZE = 8000;
  30982. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30983. if (!bytes.length) {
  30984. this.eof = true;
  30985. return;
  30986. }
  30987. var maxDecodeLength = (bytes.length + 1) >> 1;
  30988. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30989. var bufferLength = this.bufferLength;
  30990. var firstDigit = this.firstDigit;
  30991. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30992. var ch = bytes[i], digit;
  30993. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30994. digit = ch & 0x0F;
  30995. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30996. // 'A'-'Z', 'a'-'z'
  30997. digit = (ch & 0x0F) + 9;
  30998. } else if (ch === 0x3E) { // '>'
  30999. this.eof = true;
  31000. break;
  31001. } else { // probably whitespace
  31002. continue; // ignoring
  31003. }
  31004. if (firstDigit < 0) {
  31005. firstDigit = digit;
  31006. } else {
  31007. buffer[bufferLength++] = (firstDigit << 4) | digit;
  31008. firstDigit = -1;
  31009. }
  31010. }
  31011. if (firstDigit >= 0 && this.eof) {
  31012. // incomplete byte
  31013. buffer[bufferLength++] = (firstDigit << 4);
  31014. firstDigit = -1;
  31015. }
  31016. this.firstDigit = firstDigit;
  31017. this.bufferLength = bufferLength;
  31018. };
  31019. return AsciiHexStream;
  31020. })();
  31021. var RunLengthStream = (function RunLengthStreamClosure() {
  31022. function RunLengthStream(str, maybeLength) {
  31023. this.str = str;
  31024. this.dict = str.dict;
  31025. DecodeStream.call(this, maybeLength);
  31026. }
  31027. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  31028. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  31029. // The repeatHeader has following format. The first byte defines type of run
  31030. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  31031. // (in addition to the second byte from the header), n = 129 through 255 -
  31032. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  31033. var repeatHeader = this.str.getBytes(2);
  31034. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  31035. this.eof = true;
  31036. return;
  31037. }
  31038. var buffer;
  31039. var bufferLength = this.bufferLength;
  31040. var n = repeatHeader[0];
  31041. if (n < 128) {
  31042. // copy n bytes
  31043. buffer = this.ensureBuffer(bufferLength + n + 1);
  31044. buffer[bufferLength++] = repeatHeader[1];
  31045. if (n > 0) {
  31046. var source = this.str.getBytes(n);
  31047. buffer.set(source, bufferLength);
  31048. bufferLength += n;
  31049. }
  31050. } else {
  31051. n = 257 - n;
  31052. var b = repeatHeader[1];
  31053. buffer = this.ensureBuffer(bufferLength + n + 1);
  31054. for (var i = 0; i < n; i++) {
  31055. buffer[bufferLength++] = b;
  31056. }
  31057. }
  31058. this.bufferLength = bufferLength;
  31059. };
  31060. return RunLengthStream;
  31061. })();
  31062. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  31063. var ccittEOL = -2;
  31064. var twoDimPass = 0;
  31065. var twoDimHoriz = 1;
  31066. var twoDimVert0 = 2;
  31067. var twoDimVertR1 = 3;
  31068. var twoDimVertL1 = 4;
  31069. var twoDimVertR2 = 5;
  31070. var twoDimVertL2 = 6;
  31071. var twoDimVertR3 = 7;
  31072. var twoDimVertL3 = 8;
  31073. var twoDimTable = [
  31074. [-1, -1], [-1, -1], // 000000x
  31075. [7, twoDimVertL3], // 0000010
  31076. [7, twoDimVertR3], // 0000011
  31077. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  31078. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  31079. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  31080. [4, twoDimPass], [4, twoDimPass],
  31081. [4, twoDimPass], [4, twoDimPass],
  31082. [4, twoDimPass], [4, twoDimPass],
  31083. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  31084. [3, twoDimHoriz], [3, twoDimHoriz],
  31085. [3, twoDimHoriz], [3, twoDimHoriz],
  31086. [3, twoDimHoriz], [3, twoDimHoriz],
  31087. [3, twoDimHoriz], [3, twoDimHoriz],
  31088. [3, twoDimHoriz], [3, twoDimHoriz],
  31089. [3, twoDimHoriz], [3, twoDimHoriz],
  31090. [3, twoDimHoriz], [3, twoDimHoriz],
  31091. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  31092. [3, twoDimVertL1], [3, twoDimVertL1],
  31093. [3, twoDimVertL1], [3, twoDimVertL1],
  31094. [3, twoDimVertL1], [3, twoDimVertL1],
  31095. [3, twoDimVertL1], [3, twoDimVertL1],
  31096. [3, twoDimVertL1], [3, twoDimVertL1],
  31097. [3, twoDimVertL1], [3, twoDimVertL1],
  31098. [3, twoDimVertL1], [3, twoDimVertL1],
  31099. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  31100. [3, twoDimVertR1], [3, twoDimVertR1],
  31101. [3, twoDimVertR1], [3, twoDimVertR1],
  31102. [3, twoDimVertR1], [3, twoDimVertR1],
  31103. [3, twoDimVertR1], [3, twoDimVertR1],
  31104. [3, twoDimVertR1], [3, twoDimVertR1],
  31105. [3, twoDimVertR1], [3, twoDimVertR1],
  31106. [3, twoDimVertR1], [3, twoDimVertR1],
  31107. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  31108. [1, twoDimVert0], [1, twoDimVert0],
  31109. [1, twoDimVert0], [1, twoDimVert0],
  31110. [1, twoDimVert0], [1, twoDimVert0],
  31111. [1, twoDimVert0], [1, twoDimVert0],
  31112. [1, twoDimVert0], [1, twoDimVert0],
  31113. [1, twoDimVert0], [1, twoDimVert0],
  31114. [1, twoDimVert0], [1, twoDimVert0],
  31115. [1, twoDimVert0], [1, twoDimVert0],
  31116. [1, twoDimVert0], [1, twoDimVert0],
  31117. [1, twoDimVert0], [1, twoDimVert0],
  31118. [1, twoDimVert0], [1, twoDimVert0],
  31119. [1, twoDimVert0], [1, twoDimVert0],
  31120. [1, twoDimVert0], [1, twoDimVert0],
  31121. [1, twoDimVert0], [1, twoDimVert0],
  31122. [1, twoDimVert0], [1, twoDimVert0],
  31123. [1, twoDimVert0], [1, twoDimVert0],
  31124. [1, twoDimVert0], [1, twoDimVert0],
  31125. [1, twoDimVert0], [1, twoDimVert0],
  31126. [1, twoDimVert0], [1, twoDimVert0],
  31127. [1, twoDimVert0], [1, twoDimVert0],
  31128. [1, twoDimVert0], [1, twoDimVert0],
  31129. [1, twoDimVert0], [1, twoDimVert0],
  31130. [1, twoDimVert0], [1, twoDimVert0],
  31131. [1, twoDimVert0], [1, twoDimVert0],
  31132. [1, twoDimVert0], [1, twoDimVert0],
  31133. [1, twoDimVert0], [1, twoDimVert0],
  31134. [1, twoDimVert0], [1, twoDimVert0],
  31135. [1, twoDimVert0], [1, twoDimVert0],
  31136. [1, twoDimVert0], [1, twoDimVert0],
  31137. [1, twoDimVert0], [1, twoDimVert0],
  31138. [1, twoDimVert0], [1, twoDimVert0]
  31139. ];
  31140. var whiteTable1 = [
  31141. [-1, -1], // 00000
  31142. [12, ccittEOL], // 00001
  31143. [-1, -1], [-1, -1], // 0001x
  31144. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  31145. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  31146. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  31147. [11, 1792], [11, 1792], // 1000x
  31148. [12, 1984], // 10010
  31149. [12, 2048], // 10011
  31150. [12, 2112], // 10100
  31151. [12, 2176], // 10101
  31152. [12, 2240], // 10110
  31153. [12, 2304], // 10111
  31154. [11, 1856], [11, 1856], // 1100x
  31155. [11, 1920], [11, 1920], // 1101x
  31156. [12, 2368], // 11100
  31157. [12, 2432], // 11101
  31158. [12, 2496], // 11110
  31159. [12, 2560] // 11111
  31160. ];
  31161. var whiteTable2 = [
  31162. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  31163. [8, 29], [8, 29], // 00000010x
  31164. [8, 30], [8, 30], // 00000011x
  31165. [8, 45], [8, 45], // 00000100x
  31166. [8, 46], [8, 46], // 00000101x
  31167. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  31168. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  31169. [8, 47], [8, 47], // 00001010x
  31170. [8, 48], [8, 48], // 00001011x
  31171. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  31172. [6, 13], [6, 13], [6, 13], [6, 13],
  31173. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  31174. [8, 33], [8, 33], // 00010010x
  31175. [8, 34], [8, 34], // 00010011x
  31176. [8, 35], [8, 35], // 00010100x
  31177. [8, 36], [8, 36], // 00010101x
  31178. [8, 37], [8, 37], // 00010110x
  31179. [8, 38], [8, 38], // 00010111x
  31180. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  31181. [8, 31], [8, 31], // 00011010x
  31182. [8, 32], [8, 32], // 00011011x
  31183. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  31184. [6, 1], [6, 1], [6, 1], [6, 1],
  31185. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  31186. [6, 12], [6, 12], [6, 12], [6, 12],
  31187. [8, 53], [8, 53], // 00100100x
  31188. [8, 54], [8, 54], // 00100101x
  31189. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  31190. [8, 39], [8, 39], // 00101000x
  31191. [8, 40], [8, 40], // 00101001x
  31192. [8, 41], [8, 41], // 00101010x
  31193. [8, 42], [8, 42], // 00101011x
  31194. [8, 43], [8, 43], // 00101100x
  31195. [8, 44], [8, 44], // 00101101x
  31196. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  31197. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  31198. [8, 61], [8, 61], // 00110010x
  31199. [8, 62], [8, 62], // 00110011x
  31200. [8, 63], [8, 63], // 00110100x
  31201. [8, 0], [8, 0], // 00110101x
  31202. [8, 320], [8, 320], // 00110110x
  31203. [8, 384], [8, 384], // 00110111x
  31204. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  31205. [5, 10], [5, 10], [5, 10], [5, 10],
  31206. [5, 10], [5, 10], [5, 10], [5, 10],
  31207. [5, 10], [5, 10], [5, 10], [5, 10],
  31208. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  31209. [5, 11], [5, 11], [5, 11], [5, 11],
  31210. [5, 11], [5, 11], [5, 11], [5, 11],
  31211. [5, 11], [5, 11], [5, 11], [5, 11],
  31212. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  31213. [8, 59], [8, 59], // 01001010x
  31214. [8, 60], [8, 60], // 01001011x
  31215. [9, 1472], // 010011000
  31216. [9, 1536], // 010011001
  31217. [9, 1600], // 010011010
  31218. [9, 1728], // 010011011
  31219. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  31220. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  31221. [8, 49], [8, 49], // 01010010x
  31222. [8, 50], [8, 50], // 01010011x
  31223. [8, 51], [8, 51], // 01010100x
  31224. [8, 52], [8, 52], // 01010101x
  31225. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  31226. [8, 55], [8, 55], // 01011000x
  31227. [8, 56], [8, 56], // 01011001x
  31228. [8, 57], [8, 57], // 01011010x
  31229. [8, 58], [8, 58], // 01011011x
  31230. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  31231. [6, 192], [6, 192], [6, 192], [6, 192],
  31232. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  31233. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  31234. [8, 448], [8, 448], // 01100100x
  31235. [8, 512], [8, 512], // 01100101x
  31236. [9, 704], // 011001100
  31237. [9, 768], // 011001101
  31238. [8, 640], [8, 640], // 01100111x
  31239. [8, 576], [8, 576], // 01101000x
  31240. [9, 832], // 011010010
  31241. [9, 896], // 011010011
  31242. [9, 960], // 011010100
  31243. [9, 1024], // 011010101
  31244. [9, 1088], // 011010110
  31245. [9, 1152], // 011010111
  31246. [9, 1216], // 011011000
  31247. [9, 1280], // 011011001
  31248. [9, 1344], // 011011010
  31249. [9, 1408], // 011011011
  31250. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  31251. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  31252. [4, 2], [4, 2], [4, 2], [4, 2],
  31253. [4, 2], [4, 2], [4, 2], [4, 2],
  31254. [4, 2], [4, 2], [4, 2], [4, 2],
  31255. [4, 2], [4, 2], [4, 2], [4, 2],
  31256. [4, 2], [4, 2], [4, 2], [4, 2],
  31257. [4, 2], [4, 2], [4, 2], [4, 2],
  31258. [4, 2], [4, 2], [4, 2], [4, 2],
  31259. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  31260. [4, 3], [4, 3], [4, 3], [4, 3],
  31261. [4, 3], [4, 3], [4, 3], [4, 3],
  31262. [4, 3], [4, 3], [4, 3], [4, 3],
  31263. [4, 3], [4, 3], [4, 3], [4, 3],
  31264. [4, 3], [4, 3], [4, 3], [4, 3],
  31265. [4, 3], [4, 3], [4, 3], [4, 3],
  31266. [4, 3], [4, 3], [4, 3], [4, 3],
  31267. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  31268. [5, 128], [5, 128], [5, 128], [5, 128],
  31269. [5, 128], [5, 128], [5, 128], [5, 128],
  31270. [5, 128], [5, 128], [5, 128], [5, 128],
  31271. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  31272. [5, 8], [5, 8], [5, 8], [5, 8],
  31273. [5, 8], [5, 8], [5, 8], [5, 8],
  31274. [5, 8], [5, 8], [5, 8], [5, 8],
  31275. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  31276. [5, 9], [5, 9], [5, 9], [5, 9],
  31277. [5, 9], [5, 9], [5, 9], [5, 9],
  31278. [5, 9], [5, 9], [5, 9], [5, 9],
  31279. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  31280. [6, 16], [6, 16], [6, 16], [6, 16],
  31281. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  31282. [6, 17], [6, 17], [6, 17], [6, 17],
  31283. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  31284. [4, 4], [4, 4], [4, 4], [4, 4],
  31285. [4, 4], [4, 4], [4, 4], [4, 4],
  31286. [4, 4], [4, 4], [4, 4], [4, 4],
  31287. [4, 4], [4, 4], [4, 4], [4, 4],
  31288. [4, 4], [4, 4], [4, 4], [4, 4],
  31289. [4, 4], [4, 4], [4, 4], [4, 4],
  31290. [4, 4], [4, 4], [4, 4], [4, 4],
  31291. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  31292. [4, 5], [4, 5], [4, 5], [4, 5],
  31293. [4, 5], [4, 5], [4, 5], [4, 5],
  31294. [4, 5], [4, 5], [4, 5], [4, 5],
  31295. [4, 5], [4, 5], [4, 5], [4, 5],
  31296. [4, 5], [4, 5], [4, 5], [4, 5],
  31297. [4, 5], [4, 5], [4, 5], [4, 5],
  31298. [4, 5], [4, 5], [4, 5], [4, 5],
  31299. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  31300. [6, 14], [6, 14], [6, 14], [6, 14],
  31301. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  31302. [6, 15], [6, 15], [6, 15], [6, 15],
  31303. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  31304. [5, 64], [5, 64], [5, 64], [5, 64],
  31305. [5, 64], [5, 64], [5, 64], [5, 64],
  31306. [5, 64], [5, 64], [5, 64], [5, 64],
  31307. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  31308. [4, 6], [4, 6], [4, 6], [4, 6],
  31309. [4, 6], [4, 6], [4, 6], [4, 6],
  31310. [4, 6], [4, 6], [4, 6], [4, 6],
  31311. [4, 6], [4, 6], [4, 6], [4, 6],
  31312. [4, 6], [4, 6], [4, 6], [4, 6],
  31313. [4, 6], [4, 6], [4, 6], [4, 6],
  31314. [4, 6], [4, 6], [4, 6], [4, 6],
  31315. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  31316. [4, 7], [4, 7], [4, 7], [4, 7],
  31317. [4, 7], [4, 7], [4, 7], [4, 7],
  31318. [4, 7], [4, 7], [4, 7], [4, 7],
  31319. [4, 7], [4, 7], [4, 7], [4, 7],
  31320. [4, 7], [4, 7], [4, 7], [4, 7],
  31321. [4, 7], [4, 7], [4, 7], [4, 7],
  31322. [4, 7], [4, 7], [4, 7], [4, 7]
  31323. ];
  31324. var blackTable1 = [
  31325. [-1, -1], [-1, -1], // 000000000000x
  31326. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  31327. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  31328. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  31329. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  31330. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  31331. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  31332. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  31333. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  31334. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  31335. [12, 1984], [12, 1984], // 000000010010x
  31336. [12, 2048], [12, 2048], // 000000010011x
  31337. [12, 2112], [12, 2112], // 000000010100x
  31338. [12, 2176], [12, 2176], // 000000010101x
  31339. [12, 2240], [12, 2240], // 000000010110x
  31340. [12, 2304], [12, 2304], // 000000010111x
  31341. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  31342. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  31343. [12, 2368], [12, 2368], // 000000011100x
  31344. [12, 2432], [12, 2432], // 000000011101x
  31345. [12, 2496], [12, 2496], // 000000011110x
  31346. [12, 2560], [12, 2560], // 000000011111x
  31347. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  31348. [10, 18], [10, 18], [10, 18], [10, 18],
  31349. [12, 52], [12, 52], // 000000100100x
  31350. [13, 640], // 0000001001010
  31351. [13, 704], // 0000001001011
  31352. [13, 768], // 0000001001100
  31353. [13, 832], // 0000001001101
  31354. [12, 55], [12, 55], // 000000100111x
  31355. [12, 56], [12, 56], // 000000101000x
  31356. [13, 1280], // 0000001010010
  31357. [13, 1344], // 0000001010011
  31358. [13, 1408], // 0000001010100
  31359. [13, 1472], // 0000001010101
  31360. [12, 59], [12, 59], // 000000101011x
  31361. [12, 60], [12, 60], // 000000101100x
  31362. [13, 1536], // 0000001011010
  31363. [13, 1600], // 0000001011011
  31364. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  31365. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  31366. [13, 1664], // 0000001100100
  31367. [13, 1728], // 0000001100101
  31368. [12, 320], [12, 320], // 000000110011x
  31369. [12, 384], [12, 384], // 000000110100x
  31370. [12, 448], [12, 448], // 000000110101x
  31371. [13, 512], // 0000001101100
  31372. [13, 576], // 0000001101101
  31373. [12, 53], [12, 53], // 000000110111x
  31374. [12, 54], [12, 54], // 000000111000x
  31375. [13, 896], // 0000001110010
  31376. [13, 960], // 0000001110011
  31377. [13, 1024], // 0000001110100
  31378. [13, 1088], // 0000001110101
  31379. [13, 1152], // 0000001110110
  31380. [13, 1216], // 0000001110111
  31381. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  31382. [10, 64], [10, 64], [10, 64], [10, 64]
  31383. ];
  31384. var blackTable2 = [
  31385. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  31386. [8, 13], [8, 13], [8, 13], [8, 13],
  31387. [8, 13], [8, 13], [8, 13], [8, 13],
  31388. [8, 13], [8, 13], [8, 13], [8, 13],
  31389. [11, 23], [11, 23], // 00000101000x
  31390. [12, 50], // 000001010010
  31391. [12, 51], // 000001010011
  31392. [12, 44], // 000001010100
  31393. [12, 45], // 000001010101
  31394. [12, 46], // 000001010110
  31395. [12, 47], // 000001010111
  31396. [12, 57], // 000001011000
  31397. [12, 58], // 000001011001
  31398. [12, 61], // 000001011010
  31399. [12, 256], // 000001011011
  31400. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  31401. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  31402. [12, 48], // 000001100100
  31403. [12, 49], // 000001100101
  31404. [12, 62], // 000001100110
  31405. [12, 63], // 000001100111
  31406. [12, 30], // 000001101000
  31407. [12, 31], // 000001101001
  31408. [12, 32], // 000001101010
  31409. [12, 33], // 000001101011
  31410. [12, 40], // 000001101100
  31411. [12, 41], // 000001101101
  31412. [11, 22], [11, 22], // 00000110111x
  31413. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  31414. [8, 14], [8, 14], [8, 14], [8, 14],
  31415. [8, 14], [8, 14], [8, 14], [8, 14],
  31416. [8, 14], [8, 14], [8, 14], [8, 14],
  31417. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  31418. [7, 10], [7, 10], [7, 10], [7, 10],
  31419. [7, 10], [7, 10], [7, 10], [7, 10],
  31420. [7, 10], [7, 10], [7, 10], [7, 10],
  31421. [7, 10], [7, 10], [7, 10], [7, 10],
  31422. [7, 10], [7, 10], [7, 10], [7, 10],
  31423. [7, 10], [7, 10], [7, 10], [7, 10],
  31424. [7, 10], [7, 10], [7, 10], [7, 10],
  31425. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  31426. [7, 11], [7, 11], [7, 11], [7, 11],
  31427. [7, 11], [7, 11], [7, 11], [7, 11],
  31428. [7, 11], [7, 11], [7, 11], [7, 11],
  31429. [7, 11], [7, 11], [7, 11], [7, 11],
  31430. [7, 11], [7, 11], [7, 11], [7, 11],
  31431. [7, 11], [7, 11], [7, 11], [7, 11],
  31432. [7, 11], [7, 11], [7, 11], [7, 11],
  31433. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  31434. [9, 15], [9, 15], [9, 15], [9, 15],
  31435. [12, 128], // 000011001000
  31436. [12, 192], // 000011001001
  31437. [12, 26], // 000011001010
  31438. [12, 27], // 000011001011
  31439. [12, 28], // 000011001100
  31440. [12, 29], // 000011001101
  31441. [11, 19], [11, 19], // 00001100111x
  31442. [11, 20], [11, 20], // 00001101000x
  31443. [12, 34], // 000011010010
  31444. [12, 35], // 000011010011
  31445. [12, 36], // 000011010100
  31446. [12, 37], // 000011010101
  31447. [12, 38], // 000011010110
  31448. [12, 39], // 000011010111
  31449. [11, 21], [11, 21], // 00001101100x
  31450. [12, 42], // 000011011010
  31451. [12, 43], // 000011011011
  31452. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  31453. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  31454. [7, 12], [7, 12], [7, 12], [7, 12],
  31455. [7, 12], [7, 12], [7, 12], [7, 12],
  31456. [7, 12], [7, 12], [7, 12], [7, 12],
  31457. [7, 12], [7, 12], [7, 12], [7, 12],
  31458. [7, 12], [7, 12], [7, 12], [7, 12],
  31459. [7, 12], [7, 12], [7, 12], [7, 12],
  31460. [7, 12], [7, 12], [7, 12], [7, 12]
  31461. ];
  31462. var blackTable3 = [
  31463. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  31464. [6, 9], // 000100
  31465. [6, 8], // 000101
  31466. [5, 7], [5, 7], // 00011x
  31467. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  31468. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  31469. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  31470. [3, 1], [3, 1], [3, 1], [3, 1],
  31471. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  31472. [3, 4], [3, 4], [3, 4], [3, 4],
  31473. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  31474. [2, 3], [2, 3], [2, 3], [2, 3],
  31475. [2, 3], [2, 3], [2, 3], [2, 3],
  31476. [2, 3], [2, 3], [2, 3], [2, 3],
  31477. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31478. [2, 2], [2, 2], [2, 2], [2, 2],
  31479. [2, 2], [2, 2], [2, 2], [2, 2],
  31480. [2, 2], [2, 2], [2, 2], [2, 2]
  31481. ];
  31482. function CCITTFaxStream(str, maybeLength, params) {
  31483. this.str = str;
  31484. this.dict = str.dict;
  31485. params = params || Dict.empty;
  31486. this.encoding = params.get('K') || 0;
  31487. this.eoline = params.get('EndOfLine') || false;
  31488. this.byteAlign = params.get('EncodedByteAlign') || false;
  31489. this.columns = params.get('Columns') || 1728;
  31490. this.rows = params.get('Rows') || 0;
  31491. var eoblock = params.get('EndOfBlock');
  31492. if (eoblock === null || eoblock === undefined) {
  31493. eoblock = true;
  31494. }
  31495. this.eoblock = eoblock;
  31496. this.black = params.get('BlackIs1') || false;
  31497. this.codingLine = new Uint32Array(this.columns + 1);
  31498. this.refLine = new Uint32Array(this.columns + 2);
  31499. this.codingLine[0] = this.columns;
  31500. this.codingPos = 0;
  31501. this.row = 0;
  31502. this.nextLine2D = this.encoding < 0;
  31503. this.inputBits = 0;
  31504. this.inputBuf = 0;
  31505. this.outputBits = 0;
  31506. var code1;
  31507. while ((code1 = this.lookBits(12)) === 0) {
  31508. this.eatBits(1);
  31509. }
  31510. if (code1 === 1) {
  31511. this.eatBits(12);
  31512. }
  31513. if (this.encoding > 0) {
  31514. this.nextLine2D = !this.lookBits(1);
  31515. this.eatBits(1);
  31516. }
  31517. DecodeStream.call(this, maybeLength);
  31518. }
  31519. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31520. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31521. while (!this.eof) {
  31522. var c = this.lookChar();
  31523. this.ensureBuffer(this.bufferLength + 1);
  31524. this.buffer[this.bufferLength++] = c;
  31525. }
  31526. };
  31527. CCITTFaxStream.prototype.addPixels =
  31528. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31529. var codingLine = this.codingLine;
  31530. var codingPos = this.codingPos;
  31531. if (a1 > codingLine[codingPos]) {
  31532. if (a1 > this.columns) {
  31533. info('row is wrong length');
  31534. this.err = true;
  31535. a1 = this.columns;
  31536. }
  31537. if ((codingPos & 1) ^ blackPixels) {
  31538. ++codingPos;
  31539. }
  31540. codingLine[codingPos] = a1;
  31541. }
  31542. this.codingPos = codingPos;
  31543. };
  31544. CCITTFaxStream.prototype.addPixelsNeg =
  31545. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31546. var codingLine = this.codingLine;
  31547. var codingPos = this.codingPos;
  31548. if (a1 > codingLine[codingPos]) {
  31549. if (a1 > this.columns) {
  31550. info('row is wrong length');
  31551. this.err = true;
  31552. a1 = this.columns;
  31553. }
  31554. if ((codingPos & 1) ^ blackPixels) {
  31555. ++codingPos;
  31556. }
  31557. codingLine[codingPos] = a1;
  31558. } else if (a1 < codingLine[codingPos]) {
  31559. if (a1 < 0) {
  31560. info('invalid code');
  31561. this.err = true;
  31562. a1 = 0;
  31563. }
  31564. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31565. --codingPos;
  31566. }
  31567. codingLine[codingPos] = a1;
  31568. }
  31569. this.codingPos = codingPos;
  31570. };
  31571. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31572. var refLine = this.refLine;
  31573. var codingLine = this.codingLine;
  31574. var columns = this.columns;
  31575. var refPos, blackPixels, bits, i;
  31576. if (this.outputBits === 0) {
  31577. if (this.eof) {
  31578. return null;
  31579. }
  31580. this.err = false;
  31581. var code1, code2, code3;
  31582. if (this.nextLine2D) {
  31583. for (i = 0; codingLine[i] < columns; ++i) {
  31584. refLine[i] = codingLine[i];
  31585. }
  31586. refLine[i++] = columns;
  31587. refLine[i] = columns;
  31588. codingLine[0] = 0;
  31589. this.codingPos = 0;
  31590. refPos = 0;
  31591. blackPixels = 0;
  31592. while (codingLine[this.codingPos] < columns) {
  31593. code1 = this.getTwoDimCode();
  31594. switch (code1) {
  31595. case twoDimPass:
  31596. this.addPixels(refLine[refPos + 1], blackPixels);
  31597. if (refLine[refPos + 1] < columns) {
  31598. refPos += 2;
  31599. }
  31600. break;
  31601. case twoDimHoriz:
  31602. code1 = code2 = 0;
  31603. if (blackPixels) {
  31604. do {
  31605. code1 += (code3 = this.getBlackCode());
  31606. } while (code3 >= 64);
  31607. do {
  31608. code2 += (code3 = this.getWhiteCode());
  31609. } while (code3 >= 64);
  31610. } else {
  31611. do {
  31612. code1 += (code3 = this.getWhiteCode());
  31613. } while (code3 >= 64);
  31614. do {
  31615. code2 += (code3 = this.getBlackCode());
  31616. } while (code3 >= 64);
  31617. }
  31618. this.addPixels(codingLine[this.codingPos] +
  31619. code1, blackPixels);
  31620. if (codingLine[this.codingPos] < columns) {
  31621. this.addPixels(codingLine[this.codingPos] + code2,
  31622. blackPixels ^ 1);
  31623. }
  31624. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31625. refLine[refPos] < columns) {
  31626. refPos += 2;
  31627. }
  31628. break;
  31629. case twoDimVertR3:
  31630. this.addPixels(refLine[refPos] + 3, blackPixels);
  31631. blackPixels ^= 1;
  31632. if (codingLine[this.codingPos] < columns) {
  31633. ++refPos;
  31634. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31635. refLine[refPos] < columns) {
  31636. refPos += 2;
  31637. }
  31638. }
  31639. break;
  31640. case twoDimVertR2:
  31641. this.addPixels(refLine[refPos] + 2, blackPixels);
  31642. blackPixels ^= 1;
  31643. if (codingLine[this.codingPos] < columns) {
  31644. ++refPos;
  31645. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31646. refLine[refPos] < columns) {
  31647. refPos += 2;
  31648. }
  31649. }
  31650. break;
  31651. case twoDimVertR1:
  31652. this.addPixels(refLine[refPos] + 1, blackPixels);
  31653. blackPixels ^= 1;
  31654. if (codingLine[this.codingPos] < columns) {
  31655. ++refPos;
  31656. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31657. refLine[refPos] < columns) {
  31658. refPos += 2;
  31659. }
  31660. }
  31661. break;
  31662. case twoDimVert0:
  31663. this.addPixels(refLine[refPos], blackPixels);
  31664. blackPixels ^= 1;
  31665. if (codingLine[this.codingPos] < columns) {
  31666. ++refPos;
  31667. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31668. refLine[refPos] < columns) {
  31669. refPos += 2;
  31670. }
  31671. }
  31672. break;
  31673. case twoDimVertL3:
  31674. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31675. blackPixels ^= 1;
  31676. if (codingLine[this.codingPos] < columns) {
  31677. if (refPos > 0) {
  31678. --refPos;
  31679. } else {
  31680. ++refPos;
  31681. }
  31682. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31683. refLine[refPos] < columns) {
  31684. refPos += 2;
  31685. }
  31686. }
  31687. break;
  31688. case twoDimVertL2:
  31689. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31690. blackPixels ^= 1;
  31691. if (codingLine[this.codingPos] < columns) {
  31692. if (refPos > 0) {
  31693. --refPos;
  31694. } else {
  31695. ++refPos;
  31696. }
  31697. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31698. refLine[refPos] < columns) {
  31699. refPos += 2;
  31700. }
  31701. }
  31702. break;
  31703. case twoDimVertL1:
  31704. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31705. blackPixels ^= 1;
  31706. if (codingLine[this.codingPos] < columns) {
  31707. if (refPos > 0) {
  31708. --refPos;
  31709. } else {
  31710. ++refPos;
  31711. }
  31712. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31713. refLine[refPos] < columns) {
  31714. refPos += 2;
  31715. }
  31716. }
  31717. break;
  31718. case EOF:
  31719. this.addPixels(columns, 0);
  31720. this.eof = true;
  31721. break;
  31722. default:
  31723. info('bad 2d code');
  31724. this.addPixels(columns, 0);
  31725. this.err = true;
  31726. }
  31727. }
  31728. } else {
  31729. codingLine[0] = 0;
  31730. this.codingPos = 0;
  31731. blackPixels = 0;
  31732. while (codingLine[this.codingPos] < columns) {
  31733. code1 = 0;
  31734. if (blackPixels) {
  31735. do {
  31736. code1 += (code3 = this.getBlackCode());
  31737. } while (code3 >= 64);
  31738. } else {
  31739. do {
  31740. code1 += (code3 = this.getWhiteCode());
  31741. } while (code3 >= 64);
  31742. }
  31743. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31744. blackPixels ^= 1;
  31745. }
  31746. }
  31747. var gotEOL = false;
  31748. if (this.byteAlign) {
  31749. this.inputBits &= ~7;
  31750. }
  31751. if (!this.eoblock && this.row === this.rows - 1) {
  31752. this.eof = true;
  31753. } else {
  31754. code1 = this.lookBits(12);
  31755. if (this.eoline) {
  31756. while (code1 !== EOF && code1 !== 1) {
  31757. this.eatBits(1);
  31758. code1 = this.lookBits(12);
  31759. }
  31760. } else {
  31761. while (code1 === 0) {
  31762. this.eatBits(1);
  31763. code1 = this.lookBits(12);
  31764. }
  31765. }
  31766. if (code1 === 1) {
  31767. this.eatBits(12);
  31768. gotEOL = true;
  31769. } else if (code1 === EOF) {
  31770. this.eof = true;
  31771. }
  31772. }
  31773. if (!this.eof && this.encoding > 0) {
  31774. this.nextLine2D = !this.lookBits(1);
  31775. this.eatBits(1);
  31776. }
  31777. if (this.eoblock && gotEOL && this.byteAlign) {
  31778. code1 = this.lookBits(12);
  31779. if (code1 === 1) {
  31780. this.eatBits(12);
  31781. if (this.encoding > 0) {
  31782. this.lookBits(1);
  31783. this.eatBits(1);
  31784. }
  31785. if (this.encoding >= 0) {
  31786. for (i = 0; i < 4; ++i) {
  31787. code1 = this.lookBits(12);
  31788. if (code1 !== 1) {
  31789. info('bad rtc code: ' + code1);
  31790. }
  31791. this.eatBits(12);
  31792. if (this.encoding > 0) {
  31793. this.lookBits(1);
  31794. this.eatBits(1);
  31795. }
  31796. }
  31797. }
  31798. this.eof = true;
  31799. }
  31800. } else if (this.err && this.eoline) {
  31801. while (true) {
  31802. code1 = this.lookBits(13);
  31803. if (code1 === EOF) {
  31804. this.eof = true;
  31805. return null;
  31806. }
  31807. if ((code1 >> 1) === 1) {
  31808. break;
  31809. }
  31810. this.eatBits(1);
  31811. }
  31812. this.eatBits(12);
  31813. if (this.encoding > 0) {
  31814. this.eatBits(1);
  31815. this.nextLine2D = !(code1 & 1);
  31816. }
  31817. }
  31818. if (codingLine[0] > 0) {
  31819. this.outputBits = codingLine[this.codingPos = 0];
  31820. } else {
  31821. this.outputBits = codingLine[this.codingPos = 1];
  31822. }
  31823. this.row++;
  31824. }
  31825. var c;
  31826. if (this.outputBits >= 8) {
  31827. c = (this.codingPos & 1) ? 0 : 0xFF;
  31828. this.outputBits -= 8;
  31829. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31830. this.codingPos++;
  31831. this.outputBits = (codingLine[this.codingPos] -
  31832. codingLine[this.codingPos - 1]);
  31833. }
  31834. } else {
  31835. bits = 8;
  31836. c = 0;
  31837. do {
  31838. if (this.outputBits > bits) {
  31839. c <<= bits;
  31840. if (!(this.codingPos & 1)) {
  31841. c |= 0xFF >> (8 - bits);
  31842. }
  31843. this.outputBits -= bits;
  31844. bits = 0;
  31845. } else {
  31846. c <<= this.outputBits;
  31847. if (!(this.codingPos & 1)) {
  31848. c |= 0xFF >> (8 - this.outputBits);
  31849. }
  31850. bits -= this.outputBits;
  31851. this.outputBits = 0;
  31852. if (codingLine[this.codingPos] < columns) {
  31853. this.codingPos++;
  31854. this.outputBits = (codingLine[this.codingPos] -
  31855. codingLine[this.codingPos - 1]);
  31856. } else if (bits > 0) {
  31857. c <<= bits;
  31858. bits = 0;
  31859. }
  31860. }
  31861. } while (bits);
  31862. }
  31863. if (this.black) {
  31864. c ^= 0xFF;
  31865. }
  31866. return c;
  31867. };
  31868. // This functions returns the code found from the table.
  31869. // The start and end parameters set the boundaries for searching the table.
  31870. // The limit parameter is optional. Function returns an array with three
  31871. // values. The first array element indicates whether a valid code is being
  31872. // returned. The second array element is the actual code. The third array
  31873. // element indicates whether EOF was reached.
  31874. CCITTFaxStream.prototype.findTableCode =
  31875. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31876. var limitValue = limit || 0;
  31877. for (var i = start; i <= end; ++i) {
  31878. var code = this.lookBits(i);
  31879. if (code === EOF) {
  31880. return [true, 1, false];
  31881. }
  31882. if (i < end) {
  31883. code <<= end - i;
  31884. }
  31885. if (!limitValue || code >= limitValue) {
  31886. var p = table[code - limitValue];
  31887. if (p[0] === i) {
  31888. this.eatBits(i);
  31889. return [true, p[1], true];
  31890. }
  31891. }
  31892. }
  31893. return [false, 0, false];
  31894. };
  31895. CCITTFaxStream.prototype.getTwoDimCode =
  31896. function ccittFaxStreamGetTwoDimCode() {
  31897. var code = 0;
  31898. var p;
  31899. if (this.eoblock) {
  31900. code = this.lookBits(7);
  31901. p = twoDimTable[code];
  31902. if (p && p[0] > 0) {
  31903. this.eatBits(p[0]);
  31904. return p[1];
  31905. }
  31906. } else {
  31907. var result = this.findTableCode(1, 7, twoDimTable);
  31908. if (result[0] && result[2]) {
  31909. return result[1];
  31910. }
  31911. }
  31912. info('Bad two dim code');
  31913. return EOF;
  31914. };
  31915. CCITTFaxStream.prototype.getWhiteCode =
  31916. function ccittFaxStreamGetWhiteCode() {
  31917. var code = 0;
  31918. var p;
  31919. if (this.eoblock) {
  31920. code = this.lookBits(12);
  31921. if (code === EOF) {
  31922. return 1;
  31923. }
  31924. if ((code >> 5) === 0) {
  31925. p = whiteTable1[code];
  31926. } else {
  31927. p = whiteTable2[code >> 3];
  31928. }
  31929. if (p[0] > 0) {
  31930. this.eatBits(p[0]);
  31931. return p[1];
  31932. }
  31933. } else {
  31934. var result = this.findTableCode(1, 9, whiteTable2);
  31935. if (result[0]) {
  31936. return result[1];
  31937. }
  31938. result = this.findTableCode(11, 12, whiteTable1);
  31939. if (result[0]) {
  31940. return result[1];
  31941. }
  31942. }
  31943. info('bad white code');
  31944. this.eatBits(1);
  31945. return 1;
  31946. };
  31947. CCITTFaxStream.prototype.getBlackCode =
  31948. function ccittFaxStreamGetBlackCode() {
  31949. var code, p;
  31950. if (this.eoblock) {
  31951. code = this.lookBits(13);
  31952. if (code === EOF) {
  31953. return 1;
  31954. }
  31955. if ((code >> 7) === 0) {
  31956. p = blackTable1[code];
  31957. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31958. p = blackTable2[(code >> 1) - 64];
  31959. } else {
  31960. p = blackTable3[code >> 7];
  31961. }
  31962. if (p[0] > 0) {
  31963. this.eatBits(p[0]);
  31964. return p[1];
  31965. }
  31966. } else {
  31967. var result = this.findTableCode(2, 6, blackTable3);
  31968. if (result[0]) {
  31969. return result[1];
  31970. }
  31971. result = this.findTableCode(7, 12, blackTable2, 64);
  31972. if (result[0]) {
  31973. return result[1];
  31974. }
  31975. result = this.findTableCode(10, 13, blackTable1);
  31976. if (result[0]) {
  31977. return result[1];
  31978. }
  31979. }
  31980. info('bad black code');
  31981. this.eatBits(1);
  31982. return 1;
  31983. };
  31984. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31985. var c;
  31986. while (this.inputBits < n) {
  31987. if ((c = this.str.getByte()) === -1) {
  31988. if (this.inputBits === 0) {
  31989. return EOF;
  31990. }
  31991. return ((this.inputBuf << (n - this.inputBits)) &
  31992. (0xFFFF >> (16 - n)));
  31993. }
  31994. this.inputBuf = (this.inputBuf << 8) + c;
  31995. this.inputBits += 8;
  31996. }
  31997. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31998. };
  31999. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  32000. if ((this.inputBits -= n) < 0) {
  32001. this.inputBits = 0;
  32002. }
  32003. };
  32004. return CCITTFaxStream;
  32005. })();
  32006. var LZWStream = (function LZWStreamClosure() {
  32007. function LZWStream(str, maybeLength, earlyChange) {
  32008. this.str = str;
  32009. this.dict = str.dict;
  32010. this.cachedData = 0;
  32011. this.bitsCached = 0;
  32012. var maxLzwDictionarySize = 4096;
  32013. var lzwState = {
  32014. earlyChange: earlyChange,
  32015. codeLength: 9,
  32016. nextCode: 258,
  32017. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  32018. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  32019. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  32020. currentSequence: new Uint8Array(maxLzwDictionarySize),
  32021. currentSequenceLength: 0
  32022. };
  32023. for (var i = 0; i < 256; ++i) {
  32024. lzwState.dictionaryValues[i] = i;
  32025. lzwState.dictionaryLengths[i] = 1;
  32026. }
  32027. this.lzwState = lzwState;
  32028. DecodeStream.call(this, maybeLength);
  32029. }
  32030. LZWStream.prototype = Object.create(DecodeStream.prototype);
  32031. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  32032. var bitsCached = this.bitsCached;
  32033. var cachedData = this.cachedData;
  32034. while (bitsCached < n) {
  32035. var c = this.str.getByte();
  32036. if (c === -1) {
  32037. this.eof = true;
  32038. return null;
  32039. }
  32040. cachedData = (cachedData << 8) | c;
  32041. bitsCached += 8;
  32042. }
  32043. this.bitsCached = (bitsCached -= n);
  32044. this.cachedData = cachedData;
  32045. this.lastCode = null;
  32046. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  32047. };
  32048. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  32049. var blockSize = 512;
  32050. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  32051. var i, j, q;
  32052. var lzwState = this.lzwState;
  32053. if (!lzwState) {
  32054. return; // eof was found
  32055. }
  32056. var earlyChange = lzwState.earlyChange;
  32057. var nextCode = lzwState.nextCode;
  32058. var dictionaryValues = lzwState.dictionaryValues;
  32059. var dictionaryLengths = lzwState.dictionaryLengths;
  32060. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  32061. var codeLength = lzwState.codeLength;
  32062. var prevCode = lzwState.prevCode;
  32063. var currentSequence = lzwState.currentSequence;
  32064. var currentSequenceLength = lzwState.currentSequenceLength;
  32065. var decodedLength = 0;
  32066. var currentBufferLength = this.bufferLength;
  32067. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32068. for (i = 0; i < blockSize; i++) {
  32069. var code = this.readBits(codeLength);
  32070. var hasPrev = currentSequenceLength > 0;
  32071. if (code < 256) {
  32072. currentSequence[0] = code;
  32073. currentSequenceLength = 1;
  32074. } else if (code >= 258) {
  32075. if (code < nextCode) {
  32076. currentSequenceLength = dictionaryLengths[code];
  32077. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  32078. currentSequence[j] = dictionaryValues[q];
  32079. q = dictionaryPrevCodes[q];
  32080. }
  32081. } else {
  32082. currentSequence[currentSequenceLength++] = currentSequence[0];
  32083. }
  32084. } else if (code === 256) {
  32085. codeLength = 9;
  32086. nextCode = 258;
  32087. currentSequenceLength = 0;
  32088. continue;
  32089. } else {
  32090. this.eof = true;
  32091. delete this.lzwState;
  32092. break;
  32093. }
  32094. if (hasPrev) {
  32095. dictionaryPrevCodes[nextCode] = prevCode;
  32096. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  32097. dictionaryValues[nextCode] = currentSequence[0];
  32098. nextCode++;
  32099. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  32100. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  32101. 0.6931471805599453 + 1, 12) | 0;
  32102. }
  32103. prevCode = code;
  32104. decodedLength += currentSequenceLength;
  32105. if (estimatedDecodedSize < decodedLength) {
  32106. do {
  32107. estimatedDecodedSize += decodedSizeDelta;
  32108. } while (estimatedDecodedSize < decodedLength);
  32109. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32110. }
  32111. for (j = 0; j < currentSequenceLength; j++) {
  32112. buffer[currentBufferLength++] = currentSequence[j];
  32113. }
  32114. }
  32115. lzwState.nextCode = nextCode;
  32116. lzwState.codeLength = codeLength;
  32117. lzwState.prevCode = prevCode;
  32118. lzwState.currentSequenceLength = currentSequenceLength;
  32119. this.bufferLength = currentBufferLength;
  32120. };
  32121. return LZWStream;
  32122. })();
  32123. var NullStream = (function NullStreamClosure() {
  32124. function NullStream() {
  32125. Stream.call(this, new Uint8Array(0));
  32126. }
  32127. NullStream.prototype = Stream.prototype;
  32128. return NullStream;
  32129. })();
  32130. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  32131. setup: function wphSetup(handler) {
  32132. var pdfManager;
  32133. function loadDocument(recoveryMode) {
  32134. var loadDocumentCapability = createPromiseCapability();
  32135. var parseSuccess = function parseSuccess() {
  32136. var numPagesPromise = pdfManager.ensureDoc('numPages');
  32137. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  32138. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  32139. Promise.all([numPagesPromise, fingerprintPromise,
  32140. encryptedPromise]).then(function onDocReady(results) {
  32141. var doc = {
  32142. numPages: results[0],
  32143. fingerprint: results[1],
  32144. encrypted: !!results[2],
  32145. };
  32146. loadDocumentCapability.resolve(doc);
  32147. },
  32148. parseFailure);
  32149. };
  32150. var parseFailure = function parseFailure(e) {
  32151. loadDocumentCapability.reject(e);
  32152. };
  32153. pdfManager.ensureDoc('checkHeader', []).then(function() {
  32154. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  32155. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  32156. parseSuccess, parseFailure);
  32157. }, parseFailure);
  32158. }, parseFailure);
  32159. return loadDocumentCapability.promise;
  32160. }
  32161. function getPdfManager(data) {
  32162. var pdfManagerCapability = createPromiseCapability();
  32163. var source = data.source;
  32164. var disableRange = data.disableRange;
  32165. if (source.data) {
  32166. try {
  32167. pdfManager = new LocalPdfManager(source.data, source.password);
  32168. pdfManagerCapability.resolve();
  32169. } catch (ex) {
  32170. pdfManagerCapability.reject(ex);
  32171. }
  32172. return pdfManagerCapability.promise;
  32173. } else if (source.chunkedViewerLoading) {
  32174. try {
  32175. pdfManager = new NetworkPdfManager(source, handler);
  32176. pdfManagerCapability.resolve();
  32177. } catch (ex) {
  32178. pdfManagerCapability.reject(ex);
  32179. }
  32180. return pdfManagerCapability.promise;
  32181. }
  32182. var networkManager = new NetworkManager(source.url, {
  32183. httpHeaders: source.httpHeaders,
  32184. withCredentials: source.withCredentials
  32185. });
  32186. var cachedChunks = [];
  32187. var fullRequestXhrId = networkManager.requestFull({
  32188. onHeadersReceived: function onHeadersReceived() {
  32189. if (disableRange) {
  32190. return;
  32191. }
  32192. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  32193. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  32194. return;
  32195. }
  32196. var contentEncoding =
  32197. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  32198. if (contentEncoding !== 'identity') {
  32199. return;
  32200. }
  32201. var length = fullRequestXhr.getResponseHeader('Content-Length');
  32202. length = parseInt(length, 10);
  32203. if (!isInt(length)) {
  32204. return;
  32205. }
  32206. source.length = length;
  32207. if (length <= 2 * RANGE_CHUNK_SIZE) {
  32208. // The file size is smaller than the size of two chunks, so it does
  32209. // not make any sense to abort the request and retry with a range
  32210. // request.
  32211. return;
  32212. }
  32213. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  32214. // We can continue fetching when progressive loading is enabled,
  32215. // and we don't need the autoFetch feature.
  32216. source.disableAutoFetch = true;
  32217. } else {
  32218. // NOTE: by cancelling the full request, and then issuing range
  32219. // requests, there will be an issue for sites where you can only
  32220. // request the pdf once. However, if this is the case, then the
  32221. // server should not be returning that it can support range
  32222. // requests.
  32223. networkManager.abortRequest(fullRequestXhrId);
  32224. }
  32225. try {
  32226. pdfManager = new NetworkPdfManager(source, handler);
  32227. pdfManagerCapability.resolve(pdfManager);
  32228. } catch (ex) {
  32229. pdfManagerCapability.reject(ex);
  32230. }
  32231. },
  32232. onProgressiveData: source.disableStream ? null :
  32233. function onProgressiveData(chunk) {
  32234. if (!pdfManager) {
  32235. cachedChunks.push(chunk);
  32236. return;
  32237. }
  32238. pdfManager.sendProgressiveData(chunk);
  32239. },
  32240. onDone: function onDone(args) {
  32241. if (pdfManager) {
  32242. return; // already processed
  32243. }
  32244. var pdfFile;
  32245. if (args === null) {
  32246. // TODO add some streaming manager, e.g. for unknown length files.
  32247. // The data was returned in the onProgressiveData, combining...
  32248. var pdfFileLength = 0, pos = 0;
  32249. cachedChunks.forEach(function (chunk) {
  32250. pdfFileLength += chunk.byteLength;
  32251. });
  32252. if (source.length && pdfFileLength !== source.length) {
  32253. warn('reported HTTP length is different from actual');
  32254. }
  32255. var pdfFileArray = new Uint8Array(pdfFileLength);
  32256. cachedChunks.forEach(function (chunk) {
  32257. pdfFileArray.set(new Uint8Array(chunk), pos);
  32258. pos += chunk.byteLength;
  32259. });
  32260. pdfFile = pdfFileArray.buffer;
  32261. } else {
  32262. pdfFile = args.chunk;
  32263. }
  32264. // the data is array, instantiating directly from it
  32265. try {
  32266. pdfManager = new LocalPdfManager(pdfFile, source.password);
  32267. pdfManagerCapability.resolve();
  32268. } catch (ex) {
  32269. pdfManagerCapability.reject(ex);
  32270. }
  32271. },
  32272. onError: function onError(status) {
  32273. var exception;
  32274. if (status === 404) {
  32275. exception = new MissingPDFException('Missing PDF "' +
  32276. source.url + '".');
  32277. handler.send('MissingPDF', exception);
  32278. } else {
  32279. exception = new UnexpectedResponseException(
  32280. 'Unexpected server response (' + status +
  32281. ') while retrieving PDF "' + source.url + '".', status);
  32282. handler.send('UnexpectedResponse', exception);
  32283. }
  32284. },
  32285. onProgress: function onProgress(evt) {
  32286. handler.send('DocProgress', {
  32287. loaded: evt.loaded,
  32288. total: evt.lengthComputable ? evt.total : source.length
  32289. });
  32290. }
  32291. });
  32292. return pdfManagerCapability.promise;
  32293. }
  32294. handler.on('test', function wphSetupTest(data) {
  32295. // check if Uint8Array can be sent to worker
  32296. if (!(data instanceof Uint8Array)) {
  32297. handler.send('test', false);
  32298. return;
  32299. }
  32300. // making sure postMessage transfers are working
  32301. var supportTransfers = data[0] === 255;
  32302. handler.postMessageTransfers = supportTransfers;
  32303. // check if the response property is supported by xhr
  32304. var xhr = new XMLHttpRequest();
  32305. var responseExists = 'response' in xhr;
  32306. // check if the property is actually implemented
  32307. try {
  32308. var dummy = xhr.responseType;
  32309. } catch (e) {
  32310. responseExists = false;
  32311. }
  32312. if (!responseExists) {
  32313. handler.send('test', false);
  32314. return;
  32315. }
  32316. handler.send('test', {
  32317. supportTypedArray: true,
  32318. supportTransfers: supportTransfers
  32319. });
  32320. });
  32321. handler.on('GetDocRequest', function wphSetupDoc(data) {
  32322. var onSuccess = function(doc) {
  32323. handler.send('GetDoc', { pdfInfo: doc });
  32324. };
  32325. var onFailure = function(e) {
  32326. if (e instanceof PasswordException) {
  32327. if (e.code === PasswordResponses.NEED_PASSWORD) {
  32328. handler.send('NeedPassword', e);
  32329. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  32330. handler.send('IncorrectPassword', e);
  32331. }
  32332. } else if (e instanceof InvalidPDFException) {
  32333. handler.send('InvalidPDF', e);
  32334. } else if (e instanceof MissingPDFException) {
  32335. handler.send('MissingPDF', e);
  32336. } else if (e instanceof UnexpectedResponseException) {
  32337. handler.send('UnexpectedResponse', e);
  32338. } else {
  32339. handler.send('UnknownError',
  32340. new UnknownErrorException(e.message, e.toString()));
  32341. }
  32342. };
  32343. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  32344. -1 : data.maxImageSize;
  32345. PDFJS.disableFontFace = data.disableFontFace;
  32346. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  32347. PDFJS.verbosity = data.verbosity;
  32348. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  32349. null : data.cMapUrl;
  32350. PDFJS.cMapPacked = data.cMapPacked === true;
  32351. getPdfManager(data).then(function () {
  32352. handler.send('PDFManagerReady', null);
  32353. pdfManager.onLoadedStream().then(function(stream) {
  32354. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  32355. });
  32356. }).then(function pdfManagerReady() {
  32357. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  32358. // Try again with recoveryMode == true
  32359. if (!(ex instanceof XRefParseException)) {
  32360. if (ex instanceof PasswordException) {
  32361. // after password exception prepare to receive a new password
  32362. // to repeat loading
  32363. pdfManager.passwordChanged().then(pdfManagerReady);
  32364. }
  32365. onFailure(ex);
  32366. return;
  32367. }
  32368. pdfManager.requestLoadedStream();
  32369. pdfManager.onLoadedStream().then(function() {
  32370. loadDocument(true).then(onSuccess, onFailure);
  32371. });
  32372. }, onFailure);
  32373. }, onFailure);
  32374. });
  32375. handler.on('GetPage', function wphSetupGetPage(data) {
  32376. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32377. var rotatePromise = pdfManager.ensure(page, 'rotate');
  32378. var refPromise = pdfManager.ensure(page, 'ref');
  32379. var viewPromise = pdfManager.ensure(page, 'view');
  32380. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  32381. function(results) {
  32382. return {
  32383. rotate: results[0],
  32384. ref: results[1],
  32385. view: results[2]
  32386. };
  32387. });
  32388. });
  32389. });
  32390. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  32391. var ref = new Ref(data.ref.num, data.ref.gen);
  32392. var catalog = pdfManager.pdfDocument.catalog;
  32393. return catalog.getPageIndex(ref);
  32394. });
  32395. handler.on('GetDestinations',
  32396. function wphSetupGetDestinations(data) {
  32397. return pdfManager.ensureCatalog('destinations');
  32398. }
  32399. );
  32400. handler.on('GetDestination',
  32401. function wphSetupGetDestination(data) {
  32402. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  32403. }
  32404. );
  32405. handler.on('GetAttachments',
  32406. function wphSetupGetAttachments(data) {
  32407. return pdfManager.ensureCatalog('attachments');
  32408. }
  32409. );
  32410. handler.on('GetJavaScript',
  32411. function wphSetupGetJavaScript(data) {
  32412. return pdfManager.ensureCatalog('javaScript');
  32413. }
  32414. );
  32415. handler.on('GetOutline',
  32416. function wphSetupGetOutline(data) {
  32417. return pdfManager.ensureCatalog('documentOutline');
  32418. }
  32419. );
  32420. handler.on('GetMetadata',
  32421. function wphSetupGetMetadata(data) {
  32422. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  32423. pdfManager.ensureCatalog('metadata')]);
  32424. }
  32425. );
  32426. handler.on('GetData', function wphSetupGetData(data) {
  32427. pdfManager.requestLoadedStream();
  32428. return pdfManager.onLoadedStream().then(function(stream) {
  32429. return stream.bytes;
  32430. });
  32431. });
  32432. handler.on('GetStats',
  32433. function wphSetupGetStats(data) {
  32434. return pdfManager.pdfDocument.xref.stats;
  32435. }
  32436. );
  32437. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  32438. pdfManager.updatePassword(data);
  32439. });
  32440. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  32441. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32442. return pdfManager.ensure(page, 'getAnnotationsData', []);
  32443. });
  32444. });
  32445. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  32446. pdfManager.getPage(data.pageIndex).then(function(page) {
  32447. var pageNum = data.pageIndex + 1;
  32448. var start = Date.now();
  32449. // Pre compile the pdf page and fetch the fonts/images.
  32450. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  32451. info('page=' + pageNum + ' - getOperatorList: time=' +
  32452. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  32453. }, function(e) {
  32454. var minimumStackMessage =
  32455. 'worker.js: while trying to getPage() and getOperatorList()';
  32456. var wrappedException;
  32457. // Turn the error into an obj that can be serialized
  32458. if (typeof e === 'string') {
  32459. wrappedException = {
  32460. message: e,
  32461. stack: minimumStackMessage
  32462. };
  32463. } else if (typeof e === 'object') {
  32464. wrappedException = {
  32465. message: e.message || e.toString(),
  32466. stack: e.stack || minimumStackMessage
  32467. };
  32468. } else {
  32469. wrappedException = {
  32470. message: 'Unknown exception type: ' + (typeof e),
  32471. stack: minimumStackMessage
  32472. };
  32473. }
  32474. handler.send('PageError', {
  32475. pageNum: pageNum,
  32476. error: wrappedException,
  32477. intent: data.intent
  32478. });
  32479. });
  32480. });
  32481. }, this);
  32482. handler.on('GetTextContent', function wphExtractText(data) {
  32483. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32484. var pageNum = data.pageIndex + 1;
  32485. var start = Date.now();
  32486. return page.extractTextContent().then(function(textContent) {
  32487. info('text indexing: page=' + pageNum + ' - time=' +
  32488. (Date.now() - start) + 'ms');
  32489. return textContent;
  32490. });
  32491. });
  32492. });
  32493. handler.on('Cleanup', function wphCleanup(data) {
  32494. return pdfManager.cleanup();
  32495. });
  32496. handler.on('Terminate', function wphTerminate(data) {
  32497. pdfManager.terminate();
  32498. });
  32499. }
  32500. };
  32501. var consoleTimer = {};
  32502. var workerConsole = {
  32503. log: function log() {
  32504. var args = Array.prototype.slice.call(arguments);
  32505. globalScope.postMessage({
  32506. action: 'console_log',
  32507. data: args
  32508. });
  32509. },
  32510. error: function error() {
  32511. var args = Array.prototype.slice.call(arguments);
  32512. globalScope.postMessage({
  32513. action: 'console_error',
  32514. data: args
  32515. });
  32516. throw 'pdf.js execution error';
  32517. },
  32518. time: function time(name) {
  32519. consoleTimer[name] = Date.now();
  32520. },
  32521. timeEnd: function timeEnd(name) {
  32522. var time = consoleTimer[name];
  32523. if (!time) {
  32524. error('Unknown timer name ' + name);
  32525. }
  32526. this.log('Timer:', name, Date.now() - time);
  32527. }
  32528. };
  32529. // Worker thread?
  32530. if (typeof window === 'undefined') {
  32531. if (!('console' in globalScope)) {
  32532. globalScope.console = workerConsole;
  32533. }
  32534. // Listen for unsupported features so we can pass them on to the main thread.
  32535. PDFJS.UnsupportedManager.listen(function (msg) {
  32536. globalScope.postMessage({
  32537. action: '_unsupported_feature',
  32538. data: msg
  32539. });
  32540. });
  32541. var handler = new MessageHandler('worker_processor', this);
  32542. WorkerMessageHandler.setup(handler);
  32543. }
  32544. /* This class implements the QM Coder decoding as defined in
  32545. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32546. * Annex C.3 Arithmetic decoding procedure
  32547. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32548. *
  32549. * The arithmetic decoder is used in conjunction with context models to decode
  32550. * JPEG2000 and JBIG2 streams.
  32551. */
  32552. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32553. // Table C-2
  32554. var QeTable = [
  32555. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32556. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32557. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32558. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32559. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32560. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32561. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32562. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32563. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32564. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32565. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32566. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32567. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32568. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32569. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32570. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32571. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32572. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32573. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32574. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32575. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32576. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32577. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32578. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32579. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32580. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32581. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32582. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32583. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32584. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32585. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32586. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32587. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32588. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32589. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32590. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32591. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32592. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32593. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32594. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32595. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32596. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32597. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32598. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32599. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32600. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32601. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32602. ];
  32603. // C.3.5 Initialisation of the decoder (INITDEC)
  32604. function ArithmeticDecoder(data, start, end) {
  32605. this.data = data;
  32606. this.bp = start;
  32607. this.dataEnd = end;
  32608. this.chigh = data[start];
  32609. this.clow = 0;
  32610. this.byteIn();
  32611. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32612. this.clow = (this.clow << 7) & 0xFFFF;
  32613. this.ct -= 7;
  32614. this.a = 0x8000;
  32615. }
  32616. ArithmeticDecoder.prototype = {
  32617. // C.3.4 Compressed data input (BYTEIN)
  32618. byteIn: function ArithmeticDecoder_byteIn() {
  32619. var data = this.data;
  32620. var bp = this.bp;
  32621. if (data[bp] === 0xFF) {
  32622. var b1 = data[bp + 1];
  32623. if (b1 > 0x8F) {
  32624. this.clow += 0xFF00;
  32625. this.ct = 8;
  32626. } else {
  32627. bp++;
  32628. this.clow += (data[bp] << 9);
  32629. this.ct = 7;
  32630. this.bp = bp;
  32631. }
  32632. } else {
  32633. bp++;
  32634. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32635. this.ct = 8;
  32636. this.bp = bp;
  32637. }
  32638. if (this.clow > 0xFFFF) {
  32639. this.chigh += (this.clow >> 16);
  32640. this.clow &= 0xFFFF;
  32641. }
  32642. },
  32643. // C.3.2 Decoding a decision (DECODE)
  32644. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32645. // contexts are packed into 1 byte:
  32646. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32647. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32648. var qeTableIcx = QeTable[cx_index];
  32649. var qeIcx = qeTableIcx.qe;
  32650. var d;
  32651. var a = this.a - qeIcx;
  32652. if (this.chigh < qeIcx) {
  32653. // exchangeLps
  32654. if (a < qeIcx) {
  32655. a = qeIcx;
  32656. d = cx_mps;
  32657. cx_index = qeTableIcx.nmps;
  32658. } else {
  32659. a = qeIcx;
  32660. d = 1 ^ cx_mps;
  32661. if (qeTableIcx.switchFlag === 1) {
  32662. cx_mps = d;
  32663. }
  32664. cx_index = qeTableIcx.nlps;
  32665. }
  32666. } else {
  32667. this.chigh -= qeIcx;
  32668. if ((a & 0x8000) !== 0) {
  32669. this.a = a;
  32670. return cx_mps;
  32671. }
  32672. // exchangeMps
  32673. if (a < qeIcx) {
  32674. d = 1 ^ cx_mps;
  32675. if (qeTableIcx.switchFlag === 1) {
  32676. cx_mps = d;
  32677. }
  32678. cx_index = qeTableIcx.nlps;
  32679. } else {
  32680. d = cx_mps;
  32681. cx_index = qeTableIcx.nmps;
  32682. }
  32683. }
  32684. // C.3.3 renormD;
  32685. do {
  32686. if (this.ct === 0) {
  32687. this.byteIn();
  32688. }
  32689. a <<= 1;
  32690. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32691. this.clow = (this.clow << 1) & 0xFFFF;
  32692. this.ct--;
  32693. } while ((a & 0x8000) === 0);
  32694. this.a = a;
  32695. contexts[pos] = cx_index << 1 | cx_mps;
  32696. return d;
  32697. }
  32698. };
  32699. return ArithmeticDecoder;
  32700. })();
  32701. var JpegImage = (function jpegImage() {
  32702. var dctZigZag = new Uint8Array([
  32703. 0,
  32704. 1, 8,
  32705. 16, 9, 2,
  32706. 3, 10, 17, 24,
  32707. 32, 25, 18, 11, 4,
  32708. 5, 12, 19, 26, 33, 40,
  32709. 48, 41, 34, 27, 20, 13, 6,
  32710. 7, 14, 21, 28, 35, 42, 49, 56,
  32711. 57, 50, 43, 36, 29, 22, 15,
  32712. 23, 30, 37, 44, 51, 58,
  32713. 59, 52, 45, 38, 31,
  32714. 39, 46, 53, 60,
  32715. 61, 54, 47,
  32716. 55, 62,
  32717. 63
  32718. ]);
  32719. var dctCos1 = 4017; // cos(pi/16)
  32720. var dctSin1 = 799; // sin(pi/16)
  32721. var dctCos3 = 3406; // cos(3*pi/16)
  32722. var dctSin3 = 2276; // sin(3*pi/16)
  32723. var dctCos6 = 1567; // cos(6*pi/16)
  32724. var dctSin6 = 3784; // sin(6*pi/16)
  32725. var dctSqrt2 = 5793; // sqrt(2)
  32726. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32727. function constructor() {
  32728. }
  32729. function buildHuffmanTable(codeLengths, values) {
  32730. var k = 0, code = [], i, j, length = 16;
  32731. while (length > 0 && !codeLengths[length - 1]) {
  32732. length--;
  32733. }
  32734. code.push({children: [], index: 0});
  32735. var p = code[0], q;
  32736. for (i = 0; i < length; i++) {
  32737. for (j = 0; j < codeLengths[i]; j++) {
  32738. p = code.pop();
  32739. p.children[p.index] = values[k];
  32740. while (p.index > 0) {
  32741. p = code.pop();
  32742. }
  32743. p.index++;
  32744. code.push(p);
  32745. while (code.length <= i) {
  32746. code.push(q = {children: [], index: 0});
  32747. p.children[p.index] = q.children;
  32748. p = q;
  32749. }
  32750. k++;
  32751. }
  32752. if (i + 1 < length) {
  32753. // p here points to last code
  32754. code.push(q = {children: [], index: 0});
  32755. p.children[p.index] = q.children;
  32756. p = q;
  32757. }
  32758. }
  32759. return code[0].children;
  32760. }
  32761. function getBlockBufferOffset(component, row, col) {
  32762. return 64 * ((component.blocksPerLine + 1) * row + col);
  32763. }
  32764. function decodeScan(data, offset, frame, components, resetInterval,
  32765. spectralStart, spectralEnd, successivePrev, successive) {
  32766. var precision = frame.precision;
  32767. var samplesPerLine = frame.samplesPerLine;
  32768. var scanLines = frame.scanLines;
  32769. var mcusPerLine = frame.mcusPerLine;
  32770. var progressive = frame.progressive;
  32771. var maxH = frame.maxH, maxV = frame.maxV;
  32772. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32773. function readBit() {
  32774. if (bitsCount > 0) {
  32775. bitsCount--;
  32776. return (bitsData >> bitsCount) & 1;
  32777. }
  32778. bitsData = data[offset++];
  32779. if (bitsData === 0xFF) {
  32780. var nextByte = data[offset++];
  32781. if (nextByte) {
  32782. throw 'unexpected marker: ' +
  32783. ((bitsData << 8) | nextByte).toString(16);
  32784. }
  32785. // unstuff 0
  32786. }
  32787. bitsCount = 7;
  32788. return bitsData >>> 7;
  32789. }
  32790. function decodeHuffman(tree) {
  32791. var node = tree;
  32792. while (true) {
  32793. node = node[readBit()];
  32794. if (typeof node === 'number') {
  32795. return node;
  32796. }
  32797. if (typeof node !== 'object') {
  32798. throw 'invalid huffman sequence';
  32799. }
  32800. }
  32801. }
  32802. function receive(length) {
  32803. var n = 0;
  32804. while (length > 0) {
  32805. n = (n << 1) | readBit();
  32806. length--;
  32807. }
  32808. return n;
  32809. }
  32810. function receiveAndExtend(length) {
  32811. if (length === 1) {
  32812. return readBit() === 1 ? 1 : -1;
  32813. }
  32814. var n = receive(length);
  32815. if (n >= 1 << (length - 1)) {
  32816. return n;
  32817. }
  32818. return n + (-1 << length) + 1;
  32819. }
  32820. function decodeBaseline(component, offset) {
  32821. var t = decodeHuffman(component.huffmanTableDC);
  32822. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32823. component.blockData[offset] = (component.pred += diff);
  32824. var k = 1;
  32825. while (k < 64) {
  32826. var rs = decodeHuffman(component.huffmanTableAC);
  32827. var s = rs & 15, r = rs >> 4;
  32828. if (s === 0) {
  32829. if (r < 15) {
  32830. break;
  32831. }
  32832. k += 16;
  32833. continue;
  32834. }
  32835. k += r;
  32836. var z = dctZigZag[k];
  32837. component.blockData[offset + z] = receiveAndExtend(s);
  32838. k++;
  32839. }
  32840. }
  32841. function decodeDCFirst(component, offset) {
  32842. var t = decodeHuffman(component.huffmanTableDC);
  32843. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32844. component.blockData[offset] = (component.pred += diff);
  32845. }
  32846. function decodeDCSuccessive(component, offset) {
  32847. component.blockData[offset] |= readBit() << successive;
  32848. }
  32849. var eobrun = 0;
  32850. function decodeACFirst(component, offset) {
  32851. if (eobrun > 0) {
  32852. eobrun--;
  32853. return;
  32854. }
  32855. var k = spectralStart, e = spectralEnd;
  32856. while (k <= e) {
  32857. var rs = decodeHuffman(component.huffmanTableAC);
  32858. var s = rs & 15, r = rs >> 4;
  32859. if (s === 0) {
  32860. if (r < 15) {
  32861. eobrun = receive(r) + (1 << r) - 1;
  32862. break;
  32863. }
  32864. k += 16;
  32865. continue;
  32866. }
  32867. k += r;
  32868. var z = dctZigZag[k];
  32869. component.blockData[offset + z] =
  32870. receiveAndExtend(s) * (1 << successive);
  32871. k++;
  32872. }
  32873. }
  32874. var successiveACState = 0, successiveACNextValue;
  32875. function decodeACSuccessive(component, offset) {
  32876. var k = spectralStart;
  32877. var e = spectralEnd;
  32878. var r = 0;
  32879. var s;
  32880. var rs;
  32881. while (k <= e) {
  32882. var z = dctZigZag[k];
  32883. switch (successiveACState) {
  32884. case 0: // initial state
  32885. rs = decodeHuffman(component.huffmanTableAC);
  32886. s = rs & 15;
  32887. r = rs >> 4;
  32888. if (s === 0) {
  32889. if (r < 15) {
  32890. eobrun = receive(r) + (1 << r);
  32891. successiveACState = 4;
  32892. } else {
  32893. r = 16;
  32894. successiveACState = 1;
  32895. }
  32896. } else {
  32897. if (s !== 1) {
  32898. throw 'invalid ACn encoding';
  32899. }
  32900. successiveACNextValue = receiveAndExtend(s);
  32901. successiveACState = r ? 2 : 3;
  32902. }
  32903. continue;
  32904. case 1: // skipping r zero items
  32905. case 2:
  32906. if (component.blockData[offset + z]) {
  32907. component.blockData[offset + z] += (readBit() << successive);
  32908. } else {
  32909. r--;
  32910. if (r === 0) {
  32911. successiveACState = successiveACState === 2 ? 3 : 0;
  32912. }
  32913. }
  32914. break;
  32915. case 3: // set value for a zero item
  32916. if (component.blockData[offset + z]) {
  32917. component.blockData[offset + z] += (readBit() << successive);
  32918. } else {
  32919. component.blockData[offset + z] =
  32920. successiveACNextValue << successive;
  32921. successiveACState = 0;
  32922. }
  32923. break;
  32924. case 4: // eob
  32925. if (component.blockData[offset + z]) {
  32926. component.blockData[offset + z] += (readBit() << successive);
  32927. }
  32928. break;
  32929. }
  32930. k++;
  32931. }
  32932. if (successiveACState === 4) {
  32933. eobrun--;
  32934. if (eobrun === 0) {
  32935. successiveACState = 0;
  32936. }
  32937. }
  32938. }
  32939. function decodeMcu(component, decode, mcu, row, col) {
  32940. var mcuRow = (mcu / mcusPerLine) | 0;
  32941. var mcuCol = mcu % mcusPerLine;
  32942. var blockRow = mcuRow * component.v + row;
  32943. var blockCol = mcuCol * component.h + col;
  32944. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32945. decode(component, offset);
  32946. }
  32947. function decodeBlock(component, decode, mcu) {
  32948. var blockRow = (mcu / component.blocksPerLine) | 0;
  32949. var blockCol = mcu % component.blocksPerLine;
  32950. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32951. decode(component, offset);
  32952. }
  32953. var componentsLength = components.length;
  32954. var component, i, j, k, n;
  32955. var decodeFn;
  32956. if (progressive) {
  32957. if (spectralStart === 0) {
  32958. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32959. } else {
  32960. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32961. }
  32962. } else {
  32963. decodeFn = decodeBaseline;
  32964. }
  32965. var mcu = 0, marker;
  32966. var mcuExpected;
  32967. if (componentsLength === 1) {
  32968. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32969. } else {
  32970. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32971. }
  32972. if (!resetInterval) {
  32973. resetInterval = mcuExpected;
  32974. }
  32975. var h, v;
  32976. while (mcu < mcuExpected) {
  32977. // reset interval stuff
  32978. for (i = 0; i < componentsLength; i++) {
  32979. components[i].pred = 0;
  32980. }
  32981. eobrun = 0;
  32982. if (componentsLength === 1) {
  32983. component = components[0];
  32984. for (n = 0; n < resetInterval; n++) {
  32985. decodeBlock(component, decodeFn, mcu);
  32986. mcu++;
  32987. }
  32988. } else {
  32989. for (n = 0; n < resetInterval; n++) {
  32990. for (i = 0; i < componentsLength; i++) {
  32991. component = components[i];
  32992. h = component.h;
  32993. v = component.v;
  32994. for (j = 0; j < v; j++) {
  32995. for (k = 0; k < h; k++) {
  32996. decodeMcu(component, decodeFn, mcu, j, k);
  32997. }
  32998. }
  32999. }
  33000. mcu++;
  33001. }
  33002. }
  33003. // find marker
  33004. bitsCount = 0;
  33005. marker = (data[offset] << 8) | data[offset + 1];
  33006. if (marker <= 0xFF00) {
  33007. throw 'marker was not found';
  33008. }
  33009. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  33010. offset += 2;
  33011. } else {
  33012. break;
  33013. }
  33014. }
  33015. return offset - startOffset;
  33016. }
  33017. // A port of poppler's IDCT method which in turn is taken from:
  33018. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  33019. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  33020. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  33021. // 988-991.
  33022. function quantizeAndInverse(component, blockBufferOffset, p) {
  33023. var qt = component.quantizationTable, blockData = component.blockData;
  33024. var v0, v1, v2, v3, v4, v5, v6, v7;
  33025. var p0, p1, p2, p3, p4, p5, p6, p7;
  33026. var t;
  33027. // inverse DCT on rows
  33028. for (var row = 0; row < 64; row += 8) {
  33029. // gather block data
  33030. p0 = blockData[blockBufferOffset + row];
  33031. p1 = blockData[blockBufferOffset + row + 1];
  33032. p2 = blockData[blockBufferOffset + row + 2];
  33033. p3 = blockData[blockBufferOffset + row + 3];
  33034. p4 = blockData[blockBufferOffset + row + 4];
  33035. p5 = blockData[blockBufferOffset + row + 5];
  33036. p6 = blockData[blockBufferOffset + row + 6];
  33037. p7 = blockData[blockBufferOffset + row + 7];
  33038. // dequant p0
  33039. p0 *= qt[row];
  33040. // check for all-zero AC coefficients
  33041. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  33042. t = (dctSqrt2 * p0 + 512) >> 10;
  33043. p[row] = t;
  33044. p[row + 1] = t;
  33045. p[row + 2] = t;
  33046. p[row + 3] = t;
  33047. p[row + 4] = t;
  33048. p[row + 5] = t;
  33049. p[row + 6] = t;
  33050. p[row + 7] = t;
  33051. continue;
  33052. }
  33053. // dequant p1 ... p7
  33054. p1 *= qt[row + 1];
  33055. p2 *= qt[row + 2];
  33056. p3 *= qt[row + 3];
  33057. p4 *= qt[row + 4];
  33058. p5 *= qt[row + 5];
  33059. p6 *= qt[row + 6];
  33060. p7 *= qt[row + 7];
  33061. // stage 4
  33062. v0 = (dctSqrt2 * p0 + 128) >> 8;
  33063. v1 = (dctSqrt2 * p4 + 128) >> 8;
  33064. v2 = p2;
  33065. v3 = p6;
  33066. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  33067. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  33068. v5 = p3 << 4;
  33069. v6 = p5 << 4;
  33070. // stage 3
  33071. v0 = (v0 + v1 + 1) >> 1;
  33072. v1 = v0 - v1;
  33073. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  33074. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  33075. v3 = t;
  33076. v4 = (v4 + v6 + 1) >> 1;
  33077. v6 = v4 - v6;
  33078. v7 = (v7 + v5 + 1) >> 1;
  33079. v5 = v7 - v5;
  33080. // stage 2
  33081. v0 = (v0 + v3 + 1) >> 1;
  33082. v3 = v0 - v3;
  33083. v1 = (v1 + v2 + 1) >> 1;
  33084. v2 = v1 - v2;
  33085. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33086. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33087. v7 = t;
  33088. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  33089. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  33090. v6 = t;
  33091. // stage 1
  33092. p[row] = v0 + v7;
  33093. p[row + 7] = v0 - v7;
  33094. p[row + 1] = v1 + v6;
  33095. p[row + 6] = v1 - v6;
  33096. p[row + 2] = v2 + v5;
  33097. p[row + 5] = v2 - v5;
  33098. p[row + 3] = v3 + v4;
  33099. p[row + 4] = v3 - v4;
  33100. }
  33101. // inverse DCT on columns
  33102. for (var col = 0; col < 8; ++col) {
  33103. p0 = p[col];
  33104. p1 = p[col + 8];
  33105. p2 = p[col + 16];
  33106. p3 = p[col + 24];
  33107. p4 = p[col + 32];
  33108. p5 = p[col + 40];
  33109. p6 = p[col + 48];
  33110. p7 = p[col + 56];
  33111. // check for all-zero AC coefficients
  33112. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  33113. t = (dctSqrt2 * p0 + 8192) >> 14;
  33114. // convert to 8 bit
  33115. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  33116. blockData[blockBufferOffset + col] = t;
  33117. blockData[blockBufferOffset + col + 8] = t;
  33118. blockData[blockBufferOffset + col + 16] = t;
  33119. blockData[blockBufferOffset + col + 24] = t;
  33120. blockData[blockBufferOffset + col + 32] = t;
  33121. blockData[blockBufferOffset + col + 40] = t;
  33122. blockData[blockBufferOffset + col + 48] = t;
  33123. blockData[blockBufferOffset + col + 56] = t;
  33124. continue;
  33125. }
  33126. // stage 4
  33127. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  33128. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  33129. v2 = p2;
  33130. v3 = p6;
  33131. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  33132. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  33133. v5 = p3;
  33134. v6 = p5;
  33135. // stage 3
  33136. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  33137. // converting to UInt8 range later.
  33138. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  33139. v1 = v0 - v1;
  33140. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  33141. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  33142. v3 = t;
  33143. v4 = (v4 + v6 + 1) >> 1;
  33144. v6 = v4 - v6;
  33145. v7 = (v7 + v5 + 1) >> 1;
  33146. v5 = v7 - v5;
  33147. // stage 2
  33148. v0 = (v0 + v3 + 1) >> 1;
  33149. v3 = v0 - v3;
  33150. v1 = (v1 + v2 + 1) >> 1;
  33151. v2 = v1 - v2;
  33152. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33153. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33154. v7 = t;
  33155. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  33156. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  33157. v6 = t;
  33158. // stage 1
  33159. p0 = v0 + v7;
  33160. p7 = v0 - v7;
  33161. p1 = v1 + v6;
  33162. p6 = v1 - v6;
  33163. p2 = v2 + v5;
  33164. p5 = v2 - v5;
  33165. p3 = v3 + v4;
  33166. p4 = v3 - v4;
  33167. // convert to 8-bit integers
  33168. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  33169. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  33170. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  33171. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  33172. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  33173. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  33174. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  33175. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  33176. // store block data
  33177. blockData[blockBufferOffset + col] = p0;
  33178. blockData[blockBufferOffset + col + 8] = p1;
  33179. blockData[blockBufferOffset + col + 16] = p2;
  33180. blockData[blockBufferOffset + col + 24] = p3;
  33181. blockData[blockBufferOffset + col + 32] = p4;
  33182. blockData[blockBufferOffset + col + 40] = p5;
  33183. blockData[blockBufferOffset + col + 48] = p6;
  33184. blockData[blockBufferOffset + col + 56] = p7;
  33185. }
  33186. }
  33187. function buildComponentData(frame, component) {
  33188. var blocksPerLine = component.blocksPerLine;
  33189. var blocksPerColumn = component.blocksPerColumn;
  33190. var computationBuffer = new Int16Array(64);
  33191. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  33192. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  33193. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33194. quantizeAndInverse(component, offset, computationBuffer);
  33195. }
  33196. }
  33197. return component.blockData;
  33198. }
  33199. function clamp0to255(a) {
  33200. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  33201. }
  33202. constructor.prototype = {
  33203. parse: function parse(data) {
  33204. function readUint16() {
  33205. var value = (data[offset] << 8) | data[offset + 1];
  33206. offset += 2;
  33207. return value;
  33208. }
  33209. function readDataBlock() {
  33210. var length = readUint16();
  33211. var array = data.subarray(offset, offset + length - 2);
  33212. offset += array.length;
  33213. return array;
  33214. }
  33215. function prepareComponents(frame) {
  33216. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  33217. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  33218. for (var i = 0; i < frame.components.length; i++) {
  33219. component = frame.components[i];
  33220. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  33221. component.h / frame.maxH);
  33222. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  33223. component.v / frame.maxV);
  33224. var blocksPerLineForMcu = mcusPerLine * component.h;
  33225. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  33226. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  33227. (blocksPerLineForMcu + 1);
  33228. component.blockData = new Int16Array(blocksBufferSize);
  33229. component.blocksPerLine = blocksPerLine;
  33230. component.blocksPerColumn = blocksPerColumn;
  33231. }
  33232. frame.mcusPerLine = mcusPerLine;
  33233. frame.mcusPerColumn = mcusPerColumn;
  33234. }
  33235. var offset = 0, length = data.length;
  33236. var jfif = null;
  33237. var adobe = null;
  33238. var pixels = null;
  33239. var frame, resetInterval;
  33240. var quantizationTables = [];
  33241. var huffmanTablesAC = [], huffmanTablesDC = [];
  33242. var fileMarker = readUint16();
  33243. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  33244. throw 'SOI not found';
  33245. }
  33246. fileMarker = readUint16();
  33247. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  33248. var i, j, l;
  33249. switch(fileMarker) {
  33250. case 0xFFE0: // APP0 (Application Specific)
  33251. case 0xFFE1: // APP1
  33252. case 0xFFE2: // APP2
  33253. case 0xFFE3: // APP3
  33254. case 0xFFE4: // APP4
  33255. case 0xFFE5: // APP5
  33256. case 0xFFE6: // APP6
  33257. case 0xFFE7: // APP7
  33258. case 0xFFE8: // APP8
  33259. case 0xFFE9: // APP9
  33260. case 0xFFEA: // APP10
  33261. case 0xFFEB: // APP11
  33262. case 0xFFEC: // APP12
  33263. case 0xFFED: // APP13
  33264. case 0xFFEE: // APP14
  33265. case 0xFFEF: // APP15
  33266. case 0xFFFE: // COM (Comment)
  33267. var appData = readDataBlock();
  33268. if (fileMarker === 0xFFE0) {
  33269. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  33270. appData[2] === 0x49 && appData[3] === 0x46 &&
  33271. appData[4] === 0) { // 'JFIF\x00'
  33272. jfif = {
  33273. version: { major: appData[5], minor: appData[6] },
  33274. densityUnits: appData[7],
  33275. xDensity: (appData[8] << 8) | appData[9],
  33276. yDensity: (appData[10] << 8) | appData[11],
  33277. thumbWidth: appData[12],
  33278. thumbHeight: appData[13],
  33279. thumbData: appData.subarray(14, 14 +
  33280. 3 * appData[12] * appData[13])
  33281. };
  33282. }
  33283. }
  33284. // TODO APP1 - Exif
  33285. if (fileMarker === 0xFFEE) {
  33286. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  33287. appData[2] === 0x6F && appData[3] === 0x62 &&
  33288. appData[4] === 0x65) { // 'Adobe'
  33289. adobe = {
  33290. version: (appData[5] << 8) | appData[6],
  33291. flags0: (appData[7] << 8) | appData[8],
  33292. flags1: (appData[9] << 8) | appData[10],
  33293. transformCode: appData[11]
  33294. };
  33295. }
  33296. }
  33297. break;
  33298. case 0xFFDB: // DQT (Define Quantization Tables)
  33299. var quantizationTablesLength = readUint16();
  33300. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  33301. var z;
  33302. while (offset < quantizationTablesEnd) {
  33303. var quantizationTableSpec = data[offset++];
  33304. var tableData = new Uint16Array(64);
  33305. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  33306. for (j = 0; j < 64; j++) {
  33307. z = dctZigZag[j];
  33308. tableData[z] = data[offset++];
  33309. }
  33310. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  33311. for (j = 0; j < 64; j++) {
  33312. z = dctZigZag[j];
  33313. tableData[z] = readUint16();
  33314. }
  33315. } else {
  33316. throw 'DQT: invalid table spec';
  33317. }
  33318. quantizationTables[quantizationTableSpec & 15] = tableData;
  33319. }
  33320. break;
  33321. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  33322. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  33323. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  33324. if (frame) {
  33325. throw 'Only single frame JPEGs supported';
  33326. }
  33327. readUint16(); // skip data length
  33328. frame = {};
  33329. frame.extended = (fileMarker === 0xFFC1);
  33330. frame.progressive = (fileMarker === 0xFFC2);
  33331. frame.precision = data[offset++];
  33332. frame.scanLines = readUint16();
  33333. frame.samplesPerLine = readUint16();
  33334. frame.components = [];
  33335. frame.componentIds = {};
  33336. var componentsCount = data[offset++], componentId;
  33337. var maxH = 0, maxV = 0;
  33338. for (i = 0; i < componentsCount; i++) {
  33339. componentId = data[offset];
  33340. var h = data[offset + 1] >> 4;
  33341. var v = data[offset + 1] & 15;
  33342. if (maxH < h) {
  33343. maxH = h;
  33344. }
  33345. if (maxV < v) {
  33346. maxV = v;
  33347. }
  33348. var qId = data[offset + 2];
  33349. l = frame.components.push({
  33350. h: h,
  33351. v: v,
  33352. quantizationTable: quantizationTables[qId]
  33353. });
  33354. frame.componentIds[componentId] = l - 1;
  33355. offset += 3;
  33356. }
  33357. frame.maxH = maxH;
  33358. frame.maxV = maxV;
  33359. prepareComponents(frame);
  33360. break;
  33361. case 0xFFC4: // DHT (Define Huffman Tables)
  33362. var huffmanLength = readUint16();
  33363. for (i = 2; i < huffmanLength;) {
  33364. var huffmanTableSpec = data[offset++];
  33365. var codeLengths = new Uint8Array(16);
  33366. var codeLengthSum = 0;
  33367. for (j = 0; j < 16; j++, offset++) {
  33368. codeLengthSum += (codeLengths[j] = data[offset]);
  33369. }
  33370. var huffmanValues = new Uint8Array(codeLengthSum);
  33371. for (j = 0; j < codeLengthSum; j++, offset++) {
  33372. huffmanValues[j] = data[offset];
  33373. }
  33374. i += 17 + codeLengthSum;
  33375. ((huffmanTableSpec >> 4) === 0 ?
  33376. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  33377. buildHuffmanTable(codeLengths, huffmanValues);
  33378. }
  33379. break;
  33380. case 0xFFDD: // DRI (Define Restart Interval)
  33381. readUint16(); // skip data length
  33382. resetInterval = readUint16();
  33383. break;
  33384. case 0xFFDA: // SOS (Start of Scan)
  33385. var scanLength = readUint16();
  33386. var selectorsCount = data[offset++];
  33387. var components = [], component;
  33388. for (i = 0; i < selectorsCount; i++) {
  33389. var componentIndex = frame.componentIds[data[offset++]];
  33390. component = frame.components[componentIndex];
  33391. var tableSpec = data[offset++];
  33392. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  33393. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  33394. components.push(component);
  33395. }
  33396. var spectralStart = data[offset++];
  33397. var spectralEnd = data[offset++];
  33398. var successiveApproximation = data[offset++];
  33399. var processed = decodeScan(data, offset,
  33400. frame, components, resetInterval,
  33401. spectralStart, spectralEnd,
  33402. successiveApproximation >> 4, successiveApproximation & 15);
  33403. offset += processed;
  33404. break;
  33405. case 0xFFFF: // Fill bytes
  33406. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  33407. offset--;
  33408. }
  33409. break;
  33410. default:
  33411. if (data[offset - 3] === 0xFF &&
  33412. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  33413. // could be incorrect encoding -- last 0xFF byte of the previous
  33414. // block was eaten by the encoder
  33415. offset -= 3;
  33416. break;
  33417. }
  33418. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  33419. }
  33420. fileMarker = readUint16();
  33421. }
  33422. this.width = frame.samplesPerLine;
  33423. this.height = frame.scanLines;
  33424. this.jfif = jfif;
  33425. this.adobe = adobe;
  33426. this.components = [];
  33427. for (i = 0; i < frame.components.length; i++) {
  33428. component = frame.components[i];
  33429. this.components.push({
  33430. output: buildComponentData(frame, component),
  33431. scaleX: component.h / frame.maxH,
  33432. scaleY: component.v / frame.maxV,
  33433. blocksPerLine: component.blocksPerLine,
  33434. blocksPerColumn: component.blocksPerColumn
  33435. });
  33436. }
  33437. this.numComponents = this.components.length;
  33438. },
  33439. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  33440. var scaleX = this.width / width, scaleY = this.height / height;
  33441. var component, componentScaleX, componentScaleY, blocksPerScanline;
  33442. var x, y, i, j, k;
  33443. var index;
  33444. var offset = 0;
  33445. var output;
  33446. var numComponents = this.components.length;
  33447. var dataLength = width * height * numComponents;
  33448. var data = new Uint8Array(dataLength);
  33449. var xScaleBlockOffset = new Uint32Array(width);
  33450. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  33451. for (i = 0; i < numComponents; i++) {
  33452. component = this.components[i];
  33453. componentScaleX = component.scaleX * scaleX;
  33454. componentScaleY = component.scaleY * scaleY;
  33455. offset = i;
  33456. output = component.output;
  33457. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  33458. // precalculate the xScaleBlockOffset
  33459. for (x = 0; x < width; x++) {
  33460. j = 0 | (x * componentScaleX);
  33461. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  33462. }
  33463. // linearize the blocks of the component
  33464. for (y = 0; y < height; y++) {
  33465. j = 0 | (y * componentScaleY);
  33466. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33467. for (x = 0; x < width; x++) {
  33468. data[offset] = output[index + xScaleBlockOffset[x]];
  33469. offset += numComponents;
  33470. }
  33471. }
  33472. }
  33473. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33474. var transform = this.decodeTransform;
  33475. if (transform) {
  33476. for (i = 0; i < dataLength;) {
  33477. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33478. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33479. }
  33480. }
  33481. }
  33482. return data;
  33483. },
  33484. _isColorConversionNeeded: function isColorConversionNeeded() {
  33485. if (this.adobe && this.adobe.transformCode) {
  33486. // The adobe transform marker overrides any previous setting
  33487. return true;
  33488. } else if (this.numComponents === 3) {
  33489. return true;
  33490. } else {
  33491. return false;
  33492. }
  33493. },
  33494. _convertYccToRgb: function convertYccToRgb(data) {
  33495. var Y, Cb, Cr;
  33496. for (var i = 0, length = data.length; i < length; i += 3) {
  33497. Y = data[i ];
  33498. Cb = data[i + 1];
  33499. Cr = data[i + 2];
  33500. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33501. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33502. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33503. }
  33504. return data;
  33505. },
  33506. _convertYcckToRgb: function convertYcckToRgb(data) {
  33507. var Y, Cb, Cr, k;
  33508. var offset = 0;
  33509. for (var i = 0, length = data.length; i < length; i += 4) {
  33510. Y = data[i];
  33511. Cb = data[i + 1];
  33512. Cr = data[i + 2];
  33513. k = data[i + 3];
  33514. var r = -122.67195406894 +
  33515. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33516. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33517. 0.154362151871126) +
  33518. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33519. 0.00477271405408747 * k + 1.53380253221734) +
  33520. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33521. 0.48357088451265) +
  33522. k * (-0.000336197177618394 * k + 0.484791561490776);
  33523. var g = 107.268039397724 +
  33524. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33525. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33526. 0.176491792462875) +
  33527. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33528. 0.000770482631801132 * k - 0.151051492775562) +
  33529. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33530. 0.25802910206845) +
  33531. k * (-0.000318913117588328 * k - 0.213742400323665);
  33532. var b = -20.810012546947 +
  33533. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33534. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33535. 0.814272968359295) +
  33536. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33537. 0.000560833691242812 * k - 0.195152027534049) +
  33538. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33539. 0.116935020465145) +
  33540. k * (-0.000343531996510555 * k + 0.24165260232407);
  33541. data[offset++] = clamp0to255(r);
  33542. data[offset++] = clamp0to255(g);
  33543. data[offset++] = clamp0to255(b);
  33544. }
  33545. return data;
  33546. },
  33547. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33548. var Y, Cb, Cr;
  33549. for (var i = 0, length = data.length; i < length; i += 4) {
  33550. Y = data[i];
  33551. Cb = data[i + 1];
  33552. Cr = data[i + 2];
  33553. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33554. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33555. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33556. // K in data[i + 3] is unchanged
  33557. }
  33558. return data;
  33559. },
  33560. _convertCmykToRgb: function convertCmykToRgb(data) {
  33561. var c, m, y, k;
  33562. var offset = 0;
  33563. var min = -255 * 255 * 255;
  33564. var scale = 1 / 255 / 255;
  33565. for (var i = 0, length = data.length; i < length; i += 4) {
  33566. c = data[i];
  33567. m = data[i + 1];
  33568. y = data[i + 2];
  33569. k = data[i + 3];
  33570. var r =
  33571. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33572. 18.82290502165302 * y + 212.25662451639585 * k -
  33573. 72734.4411664936) +
  33574. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33575. 17.873870861415444 * k - 1401.7366389350734) +
  33576. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33577. 4465.541406466231) -
  33578. k * (21.86122147463605 * k + 48317.86113160301);
  33579. var g =
  33580. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33581. 6.871425592049007 * y + 31.159100130055922 * k -
  33582. 20220.756542821975) +
  33583. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33584. 131.35250912493976 * k - 48691.05921601825) +
  33585. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33586. 6341.191035517494) -
  33587. k * (20.737325471181034 * k + 47890.15695978492);
  33588. var b =
  33589. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33590. 30.89978309703729 * y - 0.23883238689178934 * k -
  33591. 3616.812083916688) +
  33592. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33593. 50.606957656360734 * k - 28620.90484698408) +
  33594. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33595. 49363.43385999684) -
  33596. k * (22.33816807309886 * k + 45932.16563550634);
  33597. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33598. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33599. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33600. }
  33601. return data;
  33602. },
  33603. getData: function getData(width, height, forceRGBoutput) {
  33604. if (this.numComponents > 4) {
  33605. throw 'Unsupported color mode';
  33606. }
  33607. // type of data: Uint8Array(width * height * numComponents)
  33608. var data = this._getLinearizedBlockData(width, height);
  33609. if (this.numComponents === 3) {
  33610. return this._convertYccToRgb(data);
  33611. } else if (this.numComponents === 4) {
  33612. if (this._isColorConversionNeeded()) {
  33613. if (forceRGBoutput) {
  33614. return this._convertYcckToRgb(data);
  33615. } else {
  33616. return this._convertYcckToCmyk(data);
  33617. }
  33618. } else if (forceRGBoutput) {
  33619. return this._convertCmykToRgb(data);
  33620. }
  33621. }
  33622. return data;
  33623. }
  33624. };
  33625. return constructor;
  33626. })();
  33627. var JpxImage = (function JpxImageClosure() {
  33628. // Table E.1
  33629. var SubbandsGainLog2 = {
  33630. 'LL': 0,
  33631. 'LH': 1,
  33632. 'HL': 1,
  33633. 'HH': 2
  33634. };
  33635. function JpxImage() {
  33636. this.failOnCorruptedImage = false;
  33637. }
  33638. JpxImage.prototype = {
  33639. parse: function JpxImage_parse(data) {
  33640. var head = readUint16(data, 0);
  33641. // No box header, immediate start of codestream (SOC)
  33642. if (head === 0xFF4F) {
  33643. this.parseCodestream(data, 0, data.length);
  33644. return;
  33645. }
  33646. var position = 0, length = data.length;
  33647. while (position < length) {
  33648. var headerSize = 8;
  33649. var lbox = readUint32(data, position);
  33650. var tbox = readUint32(data, position + 4);
  33651. position += headerSize;
  33652. if (lbox === 1) {
  33653. // XLBox: read UInt64 according to spec.
  33654. // JavaScript's int precision of 53 bit should be sufficient here.
  33655. lbox = readUint32(data, position) * 4294967296 +
  33656. readUint32(data, position + 4);
  33657. position += 8;
  33658. headerSize += 8;
  33659. }
  33660. if (lbox === 0) {
  33661. lbox = length - position + headerSize;
  33662. }
  33663. if (lbox < headerSize) {
  33664. throw new Error('JPX Error: Invalid box field size');
  33665. }
  33666. var dataLength = lbox - headerSize;
  33667. var jumpDataLength = true;
  33668. switch (tbox) {
  33669. case 0x6A703268: // 'jp2h'
  33670. jumpDataLength = false; // parsing child boxes
  33671. break;
  33672. case 0x636F6C72: // 'colr'
  33673. // Colorspaces are not used, the CS from the PDF is used.
  33674. var method = data[position];
  33675. var precedence = data[position + 1];
  33676. var approximation = data[position + 2];
  33677. if (method === 1) {
  33678. // enumerated colorspace
  33679. var colorspace = readUint32(data, position + 3);
  33680. switch (colorspace) {
  33681. case 16: // this indicates a sRGB colorspace
  33682. case 17: // this indicates a grayscale colorspace
  33683. case 18: // this indicates a YUV colorspace
  33684. break;
  33685. default:
  33686. warn('Unknown colorspace ' + colorspace);
  33687. break;
  33688. }
  33689. } else if (method === 2) {
  33690. info('ICC profile not supported');
  33691. }
  33692. break;
  33693. case 0x6A703263: // 'jp2c'
  33694. this.parseCodestream(data, position, position + dataLength);
  33695. break;
  33696. case 0x6A502020: // 'jP\024\024'
  33697. if (0x0d0a870a !== readUint32(data, position)) {
  33698. warn('Invalid JP2 signature');
  33699. }
  33700. break;
  33701. // The following header types are valid but currently not used:
  33702. case 0x6A501A1A: // 'jP\032\032'
  33703. case 0x66747970: // 'ftyp'
  33704. case 0x72726571: // 'rreq'
  33705. case 0x72657320: // 'res '
  33706. case 0x69686472: // 'ihdr'
  33707. break;
  33708. default:
  33709. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33710. (tbox >> 16) & 0xFF,
  33711. (tbox >> 8) & 0xFF,
  33712. tbox & 0xFF);
  33713. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33714. break;
  33715. }
  33716. if (jumpDataLength) {
  33717. position += dataLength;
  33718. }
  33719. }
  33720. },
  33721. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33722. var newByte = stream.getByte();
  33723. while (newByte >= 0) {
  33724. var oldByte = newByte;
  33725. newByte = stream.getByte();
  33726. var code = (oldByte << 8) | newByte;
  33727. // Image and tile size (SIZ)
  33728. if (code === 0xFF51) {
  33729. stream.skip(4);
  33730. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33731. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33732. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33733. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33734. stream.skip(16);
  33735. var Csiz = stream.getUint16(); // Byte 36
  33736. this.width = Xsiz - XOsiz;
  33737. this.height = Ysiz - YOsiz;
  33738. this.componentsCount = Csiz;
  33739. // Results are always returned as Uint8Arrays
  33740. this.bitsPerComponent = 8;
  33741. return;
  33742. }
  33743. }
  33744. throw new Error('JPX Error: No size marker found in JPX stream');
  33745. },
  33746. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33747. var context = {};
  33748. try {
  33749. var doNotRecover = false;
  33750. var position = start;
  33751. while (position + 1 < end) {
  33752. var code = readUint16(data, position);
  33753. position += 2;
  33754. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33755. switch (code) {
  33756. case 0xFF4F: // Start of codestream (SOC)
  33757. context.mainHeader = true;
  33758. break;
  33759. case 0xFFD9: // End of codestream (EOC)
  33760. break;
  33761. case 0xFF51: // Image and tile size (SIZ)
  33762. length = readUint16(data, position);
  33763. var siz = {};
  33764. siz.Xsiz = readUint32(data, position + 4);
  33765. siz.Ysiz = readUint32(data, position + 8);
  33766. siz.XOsiz = readUint32(data, position + 12);
  33767. siz.YOsiz = readUint32(data, position + 16);
  33768. siz.XTsiz = readUint32(data, position + 20);
  33769. siz.YTsiz = readUint32(data, position + 24);
  33770. siz.XTOsiz = readUint32(data, position + 28);
  33771. siz.YTOsiz = readUint32(data, position + 32);
  33772. var componentsCount = readUint16(data, position + 36);
  33773. siz.Csiz = componentsCount;
  33774. var components = [];
  33775. j = position + 38;
  33776. for (var i = 0; i < componentsCount; i++) {
  33777. var component = {
  33778. precision: (data[j] & 0x7F) + 1,
  33779. isSigned: !!(data[j] & 0x80),
  33780. XRsiz: data[j + 1],
  33781. YRsiz: data[j + 1]
  33782. };
  33783. calculateComponentDimensions(component, siz);
  33784. components.push(component);
  33785. }
  33786. context.SIZ = siz;
  33787. context.components = components;
  33788. calculateTileGrids(context, components);
  33789. context.QCC = [];
  33790. context.COC = [];
  33791. break;
  33792. case 0xFF5C: // Quantization default (QCD)
  33793. length = readUint16(data, position);
  33794. var qcd = {};
  33795. j = position + 2;
  33796. sqcd = data[j++];
  33797. switch (sqcd & 0x1F) {
  33798. case 0:
  33799. spqcdSize = 8;
  33800. scalarExpounded = true;
  33801. break;
  33802. case 1:
  33803. spqcdSize = 16;
  33804. scalarExpounded = false;
  33805. break;
  33806. case 2:
  33807. spqcdSize = 16;
  33808. scalarExpounded = true;
  33809. break;
  33810. default:
  33811. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33812. }
  33813. qcd.noQuantization = (spqcdSize === 8);
  33814. qcd.scalarExpounded = scalarExpounded;
  33815. qcd.guardBits = sqcd >> 5;
  33816. spqcds = [];
  33817. while (j < length + position) {
  33818. var spqcd = {};
  33819. if (spqcdSize === 8) {
  33820. spqcd.epsilon = data[j++] >> 3;
  33821. spqcd.mu = 0;
  33822. } else {
  33823. spqcd.epsilon = data[j] >> 3;
  33824. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33825. j += 2;
  33826. }
  33827. spqcds.push(spqcd);
  33828. }
  33829. qcd.SPqcds = spqcds;
  33830. if (context.mainHeader) {
  33831. context.QCD = qcd;
  33832. } else {
  33833. context.currentTile.QCD = qcd;
  33834. context.currentTile.QCC = [];
  33835. }
  33836. break;
  33837. case 0xFF5D: // Quantization component (QCC)
  33838. length = readUint16(data, position);
  33839. var qcc = {};
  33840. j = position + 2;
  33841. var cqcc;
  33842. if (context.SIZ.Csiz < 257) {
  33843. cqcc = data[j++];
  33844. } else {
  33845. cqcc = readUint16(data, j);
  33846. j += 2;
  33847. }
  33848. sqcd = data[j++];
  33849. switch (sqcd & 0x1F) {
  33850. case 0:
  33851. spqcdSize = 8;
  33852. scalarExpounded = true;
  33853. break;
  33854. case 1:
  33855. spqcdSize = 16;
  33856. scalarExpounded = false;
  33857. break;
  33858. case 2:
  33859. spqcdSize = 16;
  33860. scalarExpounded = true;
  33861. break;
  33862. default:
  33863. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33864. }
  33865. qcc.noQuantization = (spqcdSize === 8);
  33866. qcc.scalarExpounded = scalarExpounded;
  33867. qcc.guardBits = sqcd >> 5;
  33868. spqcds = [];
  33869. while (j < (length + position)) {
  33870. spqcd = {};
  33871. if (spqcdSize === 8) {
  33872. spqcd.epsilon = data[j++] >> 3;
  33873. spqcd.mu = 0;
  33874. } else {
  33875. spqcd.epsilon = data[j] >> 3;
  33876. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33877. j += 2;
  33878. }
  33879. spqcds.push(spqcd);
  33880. }
  33881. qcc.SPqcds = spqcds;
  33882. if (context.mainHeader) {
  33883. context.QCC[cqcc] = qcc;
  33884. } else {
  33885. context.currentTile.QCC[cqcc] = qcc;
  33886. }
  33887. break;
  33888. case 0xFF52: // Coding style default (COD)
  33889. length = readUint16(data, position);
  33890. var cod = {};
  33891. j = position + 2;
  33892. var scod = data[j++];
  33893. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33894. cod.sopMarkerUsed = !!(scod & 2);
  33895. cod.ephMarkerUsed = !!(scod & 4);
  33896. cod.progressionOrder = data[j++];
  33897. cod.layersCount = readUint16(data, j);
  33898. j += 2;
  33899. cod.multipleComponentTransform = data[j++];
  33900. cod.decompositionLevelsCount = data[j++];
  33901. cod.xcb = (data[j++] & 0xF) + 2;
  33902. cod.ycb = (data[j++] & 0xF) + 2;
  33903. var blockStyle = data[j++];
  33904. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33905. cod.resetContextProbabilities = !!(blockStyle & 2);
  33906. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33907. cod.verticalyStripe = !!(blockStyle & 8);
  33908. cod.predictableTermination = !!(blockStyle & 16);
  33909. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33910. cod.reversibleTransformation = data[j++];
  33911. if (cod.entropyCoderWithCustomPrecincts) {
  33912. var precinctsSizes = [];
  33913. while (j < length + position) {
  33914. var precinctsSize = data[j++];
  33915. precinctsSizes.push({
  33916. PPx: precinctsSize & 0xF,
  33917. PPy: precinctsSize >> 4
  33918. });
  33919. }
  33920. cod.precinctsSizes = precinctsSizes;
  33921. }
  33922. var unsupported = [];
  33923. if (cod.selectiveArithmeticCodingBypass) {
  33924. unsupported.push('selectiveArithmeticCodingBypass');
  33925. }
  33926. if (cod.resetContextProbabilities) {
  33927. unsupported.push('resetContextProbabilities');
  33928. }
  33929. if (cod.terminationOnEachCodingPass) {
  33930. unsupported.push('terminationOnEachCodingPass');
  33931. }
  33932. if (cod.verticalyStripe) {
  33933. unsupported.push('verticalyStripe');
  33934. }
  33935. if (cod.predictableTermination) {
  33936. unsupported.push('predictableTermination');
  33937. }
  33938. if (unsupported.length > 0) {
  33939. doNotRecover = true;
  33940. throw new Error('JPX Error: Unsupported COD options (' +
  33941. unsupported.join(', ') + ')');
  33942. }
  33943. if (context.mainHeader) {
  33944. context.COD = cod;
  33945. } else {
  33946. context.currentTile.COD = cod;
  33947. context.currentTile.COC = [];
  33948. }
  33949. break;
  33950. case 0xFF90: // Start of tile-part (SOT)
  33951. length = readUint16(data, position);
  33952. tile = {};
  33953. tile.index = readUint16(data, position + 2);
  33954. tile.length = readUint32(data, position + 4);
  33955. tile.dataEnd = tile.length + position - 2;
  33956. tile.partIndex = data[position + 8];
  33957. tile.partsCount = data[position + 9];
  33958. context.mainHeader = false;
  33959. if (tile.partIndex === 0) {
  33960. // reset component specific settings
  33961. tile.COD = context.COD;
  33962. tile.COC = context.COC.slice(0); // clone of the global COC
  33963. tile.QCD = context.QCD;
  33964. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33965. }
  33966. context.currentTile = tile;
  33967. break;
  33968. case 0xFF93: // Start of data (SOD)
  33969. tile = context.currentTile;
  33970. if (tile.partIndex === 0) {
  33971. initializeTile(context, tile.index);
  33972. buildPackets(context);
  33973. }
  33974. // moving to the end of the data
  33975. length = tile.dataEnd - position;
  33976. parseTilePackets(context, data, position, length);
  33977. break;
  33978. case 0xFF55: // Tile-part lengths, main header (TLM)
  33979. case 0xFF57: // Packet length, main header (PLM)
  33980. case 0xFF58: // Packet length, tile-part header (PLT)
  33981. case 0xFF64: // Comment (COM)
  33982. length = readUint16(data, position);
  33983. // skipping content
  33984. break;
  33985. case 0xFF53: // Coding style component (COC)
  33986. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33987. 'not implemented');
  33988. default:
  33989. throw new Error('JPX Error: Unknown codestream code: ' +
  33990. code.toString(16));
  33991. }
  33992. position += length;
  33993. }
  33994. } catch (e) {
  33995. if (doNotRecover || this.failOnCorruptedImage) {
  33996. throw e;
  33997. } else {
  33998. warn('Trying to recover from ' + e.message);
  33999. }
  34000. }
  34001. this.tiles = transformComponents(context);
  34002. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  34003. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  34004. this.componentsCount = context.SIZ.Csiz;
  34005. }
  34006. };
  34007. function calculateComponentDimensions(component, siz) {
  34008. // Section B.2 Component mapping
  34009. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  34010. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  34011. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  34012. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  34013. component.width = component.x1 - component.x0;
  34014. component.height = component.y1 - component.y0;
  34015. }
  34016. function calculateTileGrids(context, components) {
  34017. var siz = context.SIZ;
  34018. // Section B.3 Division into tile and tile-components
  34019. var tile, tiles = [];
  34020. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  34021. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  34022. for (var q = 0; q < numYtiles; q++) {
  34023. for (var p = 0; p < numXtiles; p++) {
  34024. tile = {};
  34025. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  34026. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  34027. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  34028. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  34029. tile.width = tile.tx1 - tile.tx0;
  34030. tile.height = tile.ty1 - tile.ty0;
  34031. tile.components = [];
  34032. tiles.push(tile);
  34033. }
  34034. }
  34035. context.tiles = tiles;
  34036. var componentsCount = siz.Csiz;
  34037. for (var i = 0, ii = componentsCount; i < ii; i++) {
  34038. var component = components[i];
  34039. for (var j = 0, jj = tiles.length; j < jj; j++) {
  34040. var tileComponent = {};
  34041. tile = tiles[j];
  34042. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  34043. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  34044. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  34045. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  34046. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  34047. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  34048. tile.components[i] = tileComponent;
  34049. }
  34050. }
  34051. }
  34052. function getBlocksDimensions(context, component, r) {
  34053. var codOrCoc = component.codingStyleParameters;
  34054. var result = {};
  34055. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  34056. result.PPx = 15;
  34057. result.PPy = 15;
  34058. } else {
  34059. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  34060. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  34061. }
  34062. // calculate codeblock size as described in section B.7
  34063. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  34064. Math.min(codOrCoc.xcb, result.PPx));
  34065. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  34066. Math.min(codOrCoc.ycb, result.PPy));
  34067. return result;
  34068. }
  34069. function buildPrecincts(context, resolution, dimensions) {
  34070. // Section B.6 Division resolution to precincts
  34071. var precinctWidth = 1 << dimensions.PPx;
  34072. var precinctHeight = 1 << dimensions.PPy;
  34073. // Jasper introduces codeblock groups for mapping each subband codeblocks
  34074. // to precincts. Precinct partition divides a resolution according to width
  34075. // and height parameters. The subband that belongs to the resolution level
  34076. // has a different size than the level, unless it is the zero resolution.
  34077. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  34078. // The precinct partitioning for a particular subband is derived from a
  34079. // partitioning of its parent LL band (i.e., the LL band at the next higher
  34080. // resolution level)... The LL band associated with each resolution level is
  34081. // divided into precincts... Each of the resulting precinct regions is then
  34082. // mapped into its child subbands (if any) at the next lower resolution
  34083. // level. This is accomplished by using the coordinate transformation
  34084. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  34085. // coordinates of a point in the LL band and child subband, respectively.
  34086. var isZeroRes = resolution.resLevel === 0;
  34087. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  34088. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  34089. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  34090. Math.ceil(resolution.trx1 / precinctWidth) -
  34091. Math.floor(resolution.trx0 / precinctWidth) : 0);
  34092. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  34093. Math.ceil(resolution.try1 / precinctHeight) -
  34094. Math.floor(resolution.try0 / precinctHeight) : 0);
  34095. var numprecincts = numprecinctswide * numprecinctshigh;
  34096. resolution.precinctParameters = {
  34097. precinctWidth: precinctWidth,
  34098. precinctHeight: precinctHeight,
  34099. numprecinctswide: numprecinctswide,
  34100. numprecinctshigh: numprecinctshigh,
  34101. numprecincts: numprecincts,
  34102. precinctWidthInSubband: precinctWidthInSubband,
  34103. precinctHeightInSubband: precinctHeightInSubband
  34104. };
  34105. }
  34106. function buildCodeblocks(context, subband, dimensions) {
  34107. // Section B.7 Division sub-band into code-blocks
  34108. var xcb_ = dimensions.xcb_;
  34109. var ycb_ = dimensions.ycb_;
  34110. var codeblockWidth = 1 << xcb_;
  34111. var codeblockHeight = 1 << ycb_;
  34112. var cbx0 = subband.tbx0 >> xcb_;
  34113. var cby0 = subband.tby0 >> ycb_;
  34114. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  34115. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  34116. var precinctParameters = subband.resolution.precinctParameters;
  34117. var codeblocks = [];
  34118. var precincts = [];
  34119. var i, j, codeblock, precinctNumber;
  34120. for (j = cby0; j < cby1; j++) {
  34121. for (i = cbx0; i < cbx1; i++) {
  34122. codeblock = {
  34123. cbx: i,
  34124. cby: j,
  34125. tbx0: codeblockWidth * i,
  34126. tby0: codeblockHeight * j,
  34127. tbx1: codeblockWidth * (i + 1),
  34128. tby1: codeblockHeight * (j + 1)
  34129. };
  34130. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  34131. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  34132. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  34133. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  34134. // Calculate precinct number for this codeblock, codeblock position
  34135. // should be relative to its subband, use actual dimension and position
  34136. // See comment about codeblock group width and height
  34137. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  34138. precinctParameters.precinctWidthInSubband);
  34139. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  34140. precinctParameters.precinctHeightInSubband);
  34141. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  34142. codeblock.precinctNumber = precinctNumber;
  34143. codeblock.subbandType = subband.type;
  34144. codeblock.Lblock = 3;
  34145. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  34146. codeblock.tby1_ <= codeblock.tby0_) {
  34147. continue;
  34148. }
  34149. codeblocks.push(codeblock);
  34150. // building precinct for the sub-band
  34151. var precinct = precincts[precinctNumber];
  34152. if (precinct !== undefined) {
  34153. if (i < precinct.cbxMin) {
  34154. precinct.cbxMin = i;
  34155. } else if (i > precinct.cbxMax) {
  34156. precinct.cbxMax = i;
  34157. }
  34158. if (j < precinct.cbyMin) {
  34159. precinct.cbxMin = j;
  34160. } else if (j > precinct.cbyMax) {
  34161. precinct.cbyMax = j;
  34162. }
  34163. } else {
  34164. precincts[precinctNumber] = precinct = {
  34165. cbxMin: i,
  34166. cbyMin: j,
  34167. cbxMax: i,
  34168. cbyMax: j
  34169. };
  34170. }
  34171. codeblock.precinct = precinct;
  34172. }
  34173. }
  34174. subband.codeblockParameters = {
  34175. codeblockWidth: xcb_,
  34176. codeblockHeight: ycb_,
  34177. numcodeblockwide: cbx1 - cbx0 + 1,
  34178. numcodeblockhigh: cby1 - cby0 + 1
  34179. };
  34180. subband.codeblocks = codeblocks;
  34181. subband.precincts = precincts;
  34182. }
  34183. function createPacket(resolution, precinctNumber, layerNumber) {
  34184. var precinctCodeblocks = [];
  34185. // Section B.10.8 Order of info in packet
  34186. var subbands = resolution.subbands;
  34187. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  34188. for (var i = 0, ii = subbands.length; i < ii; i++) {
  34189. var subband = subbands[i];
  34190. var codeblocks = subband.codeblocks;
  34191. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  34192. var codeblock = codeblocks[j];
  34193. if (codeblock.precinctNumber !== precinctNumber) {
  34194. continue;
  34195. }
  34196. precinctCodeblocks.push(codeblock);
  34197. }
  34198. }
  34199. return {
  34200. layerNumber: layerNumber,
  34201. codeblocks: precinctCodeblocks
  34202. };
  34203. }
  34204. function LayerResolutionComponentPositionIterator(context) {
  34205. var siz = context.SIZ;
  34206. var tileIndex = context.currentTile.index;
  34207. var tile = context.tiles[tileIndex];
  34208. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34209. var componentsCount = siz.Csiz;
  34210. var maxDecompositionLevelsCount = 0;
  34211. for (var q = 0; q < componentsCount; q++) {
  34212. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34213. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34214. }
  34215. var l = 0, r = 0, i = 0, k = 0;
  34216. this.nextPacket = function JpxImage_nextPacket() {
  34217. // Section B.12.1.1 Layer-resolution-component-position
  34218. for (; l < layersCount; l++) {
  34219. for (; r <= maxDecompositionLevelsCount; r++) {
  34220. for (; i < componentsCount; i++) {
  34221. var component = tile.components[i];
  34222. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34223. continue;
  34224. }
  34225. var resolution = component.resolutions[r];
  34226. var numprecincts = resolution.precinctParameters.numprecincts;
  34227. for (; k < numprecincts;) {
  34228. var packet = createPacket(resolution, k, l);
  34229. k++;
  34230. return packet;
  34231. }
  34232. k = 0;
  34233. }
  34234. i = 0;
  34235. }
  34236. r = 0;
  34237. }
  34238. throw new Error('JPX Error: Out of packets');
  34239. };
  34240. }
  34241. function ResolutionLayerComponentPositionIterator(context) {
  34242. var siz = context.SIZ;
  34243. var tileIndex = context.currentTile.index;
  34244. var tile = context.tiles[tileIndex];
  34245. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34246. var componentsCount = siz.Csiz;
  34247. var maxDecompositionLevelsCount = 0;
  34248. for (var q = 0; q < componentsCount; q++) {
  34249. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34250. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34251. }
  34252. var r = 0, l = 0, i = 0, k = 0;
  34253. this.nextPacket = function JpxImage_nextPacket() {
  34254. // Section B.12.1.2 Resolution-layer-component-position
  34255. for (; r <= maxDecompositionLevelsCount; r++) {
  34256. for (; l < layersCount; l++) {
  34257. for (; i < componentsCount; i++) {
  34258. var component = tile.components[i];
  34259. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34260. continue;
  34261. }
  34262. var resolution = component.resolutions[r];
  34263. var numprecincts = resolution.precinctParameters.numprecincts;
  34264. for (; k < numprecincts;) {
  34265. var packet = createPacket(resolution, k, l);
  34266. k++;
  34267. return packet;
  34268. }
  34269. k = 0;
  34270. }
  34271. i = 0;
  34272. }
  34273. l = 0;
  34274. }
  34275. throw new Error('JPX Error: Out of packets');
  34276. };
  34277. }
  34278. function ResolutionPositionComponentLayerIterator(context) {
  34279. var siz = context.SIZ;
  34280. var tileIndex = context.currentTile.index;
  34281. var tile = context.tiles[tileIndex];
  34282. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34283. var componentsCount = siz.Csiz;
  34284. var l, r, c, p;
  34285. var maxDecompositionLevelsCount = 0;
  34286. for (c = 0; c < componentsCount; c++) {
  34287. var component = tile.components[c];
  34288. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34289. component.codingStyleParameters.decompositionLevelsCount);
  34290. }
  34291. var maxNumPrecinctsInLevel = new Int32Array(
  34292. maxDecompositionLevelsCount + 1);
  34293. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  34294. var maxNumPrecincts = 0;
  34295. for (c = 0; c < componentsCount; ++c) {
  34296. var resolutions = tile.components[c].resolutions;
  34297. if (r < resolutions.length) {
  34298. maxNumPrecincts = Math.max(maxNumPrecincts,
  34299. resolutions[r].precinctParameters.numprecincts);
  34300. }
  34301. }
  34302. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  34303. }
  34304. l = 0;
  34305. r = 0;
  34306. c = 0;
  34307. p = 0;
  34308. this.nextPacket = function JpxImage_nextPacket() {
  34309. // Section B.12.1.3 Resolution-position-component-layer
  34310. for (; r <= maxDecompositionLevelsCount; r++) {
  34311. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  34312. for (; c < componentsCount; c++) {
  34313. var component = tile.components[c];
  34314. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34315. continue;
  34316. }
  34317. var resolution = component.resolutions[r];
  34318. var numprecincts = resolution.precinctParameters.numprecincts;
  34319. if (p >= numprecincts) {
  34320. continue;
  34321. }
  34322. for (; l < layersCount;) {
  34323. var packet = createPacket(resolution, p, l);
  34324. l++;
  34325. return packet;
  34326. }
  34327. l = 0;
  34328. }
  34329. c = 0;
  34330. }
  34331. p = 0;
  34332. }
  34333. throw new Error('JPX Error: Out of packets');
  34334. };
  34335. }
  34336. function PositionComponentResolutionLayerIterator(context) {
  34337. var siz = context.SIZ;
  34338. var tileIndex = context.currentTile.index;
  34339. var tile = context.tiles[tileIndex];
  34340. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34341. var componentsCount = siz.Csiz;
  34342. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34343. var precinctsIterationSizes = precinctsSizes;
  34344. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34345. this.nextPacket = function JpxImage_nextPacket() {
  34346. // Section B.12.1.4 Position-component-resolution-layer
  34347. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34348. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34349. for (; c < componentsCount; c++) {
  34350. var component = tile.components[c];
  34351. var decompositionLevelsCount =
  34352. component.codingStyleParameters.decompositionLevelsCount;
  34353. for (; r <= decompositionLevelsCount; r++) {
  34354. var resolution = component.resolutions[r];
  34355. var sizeInImageScale =
  34356. precinctsSizes.components[c].resolutions[r];
  34357. var k = getPrecinctIndexIfExist(
  34358. px,
  34359. py,
  34360. sizeInImageScale,
  34361. precinctsIterationSizes,
  34362. resolution);
  34363. if (k === null) {
  34364. continue;
  34365. }
  34366. for (; l < layersCount;) {
  34367. var packet = createPacket(resolution, k, l);
  34368. l++;
  34369. return packet;
  34370. }
  34371. l = 0;
  34372. }
  34373. r = 0;
  34374. }
  34375. c = 0;
  34376. }
  34377. px = 0;
  34378. }
  34379. throw new Error('JPX Error: Out of packets');
  34380. };
  34381. }
  34382. function ComponentPositionResolutionLayerIterator(context) {
  34383. var siz = context.SIZ;
  34384. var tileIndex = context.currentTile.index;
  34385. var tile = context.tiles[tileIndex];
  34386. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34387. var componentsCount = siz.Csiz;
  34388. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34389. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34390. this.nextPacket = function JpxImage_nextPacket() {
  34391. // Section B.12.1.5 Component-position-resolution-layer
  34392. for (; c < componentsCount; ++c) {
  34393. var component = tile.components[c];
  34394. var precinctsIterationSizes = precinctsSizes.components[c];
  34395. var decompositionLevelsCount =
  34396. component.codingStyleParameters.decompositionLevelsCount;
  34397. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34398. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34399. for (; r <= decompositionLevelsCount; r++) {
  34400. var resolution = component.resolutions[r];
  34401. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  34402. var k = getPrecinctIndexIfExist(
  34403. px,
  34404. py,
  34405. sizeInImageScale,
  34406. precinctsIterationSizes,
  34407. resolution);
  34408. if (k === null) {
  34409. continue;
  34410. }
  34411. for (; l < layersCount;) {
  34412. var packet = createPacket(resolution, k, l);
  34413. l++;
  34414. return packet;
  34415. }
  34416. l = 0;
  34417. }
  34418. r = 0;
  34419. }
  34420. px = 0;
  34421. }
  34422. py = 0;
  34423. }
  34424. throw new Error('JPX Error: Out of packets');
  34425. };
  34426. }
  34427. function getPrecinctIndexIfExist(
  34428. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  34429. var posX = pxIndex * precinctIterationSizes.minWidth;
  34430. var posY = pyIndex * precinctIterationSizes.minHeight;
  34431. if (posX % sizeInImageScale.width !== 0 ||
  34432. posY % sizeInImageScale.height !== 0) {
  34433. return null;
  34434. }
  34435. var startPrecinctRowIndex =
  34436. (posY / sizeInImageScale.width) *
  34437. resolution.precinctParameters.numprecinctswide;
  34438. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  34439. }
  34440. function getPrecinctSizesInImageScale(tile) {
  34441. var componentsCount = tile.components.length;
  34442. var minWidth = Number.MAX_VALUE;
  34443. var minHeight = Number.MAX_VALUE;
  34444. var maxNumWide = 0;
  34445. var maxNumHigh = 0;
  34446. var sizePerComponent = new Array(componentsCount);
  34447. for (var c = 0; c < componentsCount; c++) {
  34448. var component = tile.components[c];
  34449. var decompositionLevelsCount =
  34450. component.codingStyleParameters.decompositionLevelsCount;
  34451. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  34452. var minWidthCurrentComponent = Number.MAX_VALUE;
  34453. var minHeightCurrentComponent = Number.MAX_VALUE;
  34454. var maxNumWideCurrentComponent = 0;
  34455. var maxNumHighCurrentComponent = 0;
  34456. var scale = 1;
  34457. for (var r = decompositionLevelsCount; r >= 0; --r) {
  34458. var resolution = component.resolutions[r];
  34459. var widthCurrentResolution =
  34460. scale * resolution.precinctParameters.precinctWidth;
  34461. var heightCurrentResolution =
  34462. scale * resolution.precinctParameters.precinctHeight;
  34463. minWidthCurrentComponent = Math.min(
  34464. minWidthCurrentComponent,
  34465. widthCurrentResolution);
  34466. minHeightCurrentComponent = Math.min(
  34467. minHeightCurrentComponent,
  34468. heightCurrentResolution);
  34469. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34470. resolution.precinctParameters.numprecinctswide);
  34471. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34472. resolution.precinctParameters.numprecinctshigh);
  34473. sizePerResolution[r] = {
  34474. width: widthCurrentResolution,
  34475. height: heightCurrentResolution
  34476. };
  34477. scale <<= 1;
  34478. }
  34479. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34480. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34481. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34482. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34483. sizePerComponent[c] = {
  34484. resolutions: sizePerResolution,
  34485. minWidth: minWidthCurrentComponent,
  34486. minHeight: minHeightCurrentComponent,
  34487. maxNumWide: maxNumWideCurrentComponent,
  34488. maxNumHigh: maxNumHighCurrentComponent
  34489. };
  34490. }
  34491. return {
  34492. components: sizePerComponent,
  34493. minWidth: minWidth,
  34494. minHeight: minHeight,
  34495. maxNumWide: maxNumWide,
  34496. maxNumHigh: maxNumHigh
  34497. };
  34498. }
  34499. function buildPackets(context) {
  34500. var siz = context.SIZ;
  34501. var tileIndex = context.currentTile.index;
  34502. var tile = context.tiles[tileIndex];
  34503. var componentsCount = siz.Csiz;
  34504. // Creating resolutions and sub-bands for each component
  34505. for (var c = 0; c < componentsCount; c++) {
  34506. var component = tile.components[c];
  34507. var decompositionLevelsCount =
  34508. component.codingStyleParameters.decompositionLevelsCount;
  34509. // Section B.5 Resolution levels and sub-bands
  34510. var resolutions = [];
  34511. var subbands = [];
  34512. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34513. var blocksDimensions = getBlocksDimensions(context, component, r);
  34514. var resolution = {};
  34515. var scale = 1 << (decompositionLevelsCount - r);
  34516. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34517. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34518. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34519. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34520. resolution.resLevel = r;
  34521. buildPrecincts(context, resolution, blocksDimensions);
  34522. resolutions.push(resolution);
  34523. var subband;
  34524. if (r === 0) {
  34525. // one sub-band (LL) with last decomposition
  34526. subband = {};
  34527. subband.type = 'LL';
  34528. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34529. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34530. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34531. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34532. subband.resolution = resolution;
  34533. buildCodeblocks(context, subband, blocksDimensions);
  34534. subbands.push(subband);
  34535. resolution.subbands = [subband];
  34536. } else {
  34537. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34538. var resolutionSubbands = [];
  34539. // three sub-bands (HL, LH and HH) with rest of decompositions
  34540. subband = {};
  34541. subband.type = 'HL';
  34542. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34543. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34544. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34545. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34546. subband.resolution = resolution;
  34547. buildCodeblocks(context, subband, blocksDimensions);
  34548. subbands.push(subband);
  34549. resolutionSubbands.push(subband);
  34550. subband = {};
  34551. subband.type = 'LH';
  34552. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34553. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34554. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34555. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34556. subband.resolution = resolution;
  34557. buildCodeblocks(context, subband, blocksDimensions);
  34558. subbands.push(subband);
  34559. resolutionSubbands.push(subband);
  34560. subband = {};
  34561. subband.type = 'HH';
  34562. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34563. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34564. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34565. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34566. subband.resolution = resolution;
  34567. buildCodeblocks(context, subband, blocksDimensions);
  34568. subbands.push(subband);
  34569. resolutionSubbands.push(subband);
  34570. resolution.subbands = resolutionSubbands;
  34571. }
  34572. }
  34573. component.resolutions = resolutions;
  34574. component.subbands = subbands;
  34575. }
  34576. // Generate the packets sequence
  34577. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34578. switch (progressionOrder) {
  34579. case 0:
  34580. tile.packetsIterator =
  34581. new LayerResolutionComponentPositionIterator(context);
  34582. break;
  34583. case 1:
  34584. tile.packetsIterator =
  34585. new ResolutionLayerComponentPositionIterator(context);
  34586. break;
  34587. case 2:
  34588. tile.packetsIterator =
  34589. new ResolutionPositionComponentLayerIterator(context);
  34590. break;
  34591. case 3:
  34592. tile.packetsIterator =
  34593. new PositionComponentResolutionLayerIterator(context);
  34594. break;
  34595. case 4:
  34596. tile.packetsIterator =
  34597. new ComponentPositionResolutionLayerIterator(context);
  34598. break;
  34599. default:
  34600. throw new Error('JPX Error: Unsupported progression order ' +
  34601. progressionOrder);
  34602. }
  34603. }
  34604. function parseTilePackets(context, data, offset, dataLength) {
  34605. var position = 0;
  34606. var buffer, bufferSize = 0, skipNextBit = false;
  34607. function readBits(count) {
  34608. while (bufferSize < count) {
  34609. var b = data[offset + position];
  34610. position++;
  34611. if (skipNextBit) {
  34612. buffer = (buffer << 7) | b;
  34613. bufferSize += 7;
  34614. skipNextBit = false;
  34615. } else {
  34616. buffer = (buffer << 8) | b;
  34617. bufferSize += 8;
  34618. }
  34619. if (b === 0xFF) {
  34620. skipNextBit = true;
  34621. }
  34622. }
  34623. bufferSize -= count;
  34624. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34625. }
  34626. function skipMarkerIfEqual(value) {
  34627. if (data[offset + position - 1] === 0xFF &&
  34628. data[offset + position] === value) {
  34629. skipBytes(1);
  34630. return true;
  34631. } else if (data[offset + position] === 0xFF &&
  34632. data[offset + position + 1] === value) {
  34633. skipBytes(2);
  34634. return true;
  34635. }
  34636. return false;
  34637. }
  34638. function skipBytes(count) {
  34639. position += count;
  34640. }
  34641. function alignToByte() {
  34642. bufferSize = 0;
  34643. if (skipNextBit) {
  34644. position++;
  34645. skipNextBit = false;
  34646. }
  34647. }
  34648. function readCodingpasses() {
  34649. if (readBits(1) === 0) {
  34650. return 1;
  34651. }
  34652. if (readBits(1) === 0) {
  34653. return 2;
  34654. }
  34655. var value = readBits(2);
  34656. if (value < 3) {
  34657. return value + 3;
  34658. }
  34659. value = readBits(5);
  34660. if (value < 31) {
  34661. return value + 6;
  34662. }
  34663. value = readBits(7);
  34664. return value + 37;
  34665. }
  34666. var tileIndex = context.currentTile.index;
  34667. var tile = context.tiles[tileIndex];
  34668. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34669. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34670. var packetsIterator = tile.packetsIterator;
  34671. while (position < dataLength) {
  34672. alignToByte();
  34673. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34674. // Skip also marker segment length and packet sequence ID
  34675. skipBytes(4);
  34676. }
  34677. var packet = packetsIterator.nextPacket();
  34678. if (!readBits(1)) {
  34679. continue;
  34680. }
  34681. var layerNumber = packet.layerNumber;
  34682. var queue = [], codeblock;
  34683. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34684. codeblock = packet.codeblocks[i];
  34685. var precinct = codeblock.precinct;
  34686. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34687. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34688. var codeblockIncluded = false;
  34689. var firstTimeInclusion = false;
  34690. var valueReady;
  34691. if (codeblock['included'] !== undefined) {
  34692. codeblockIncluded = !!readBits(1);
  34693. } else {
  34694. // reading inclusion tree
  34695. precinct = codeblock.precinct;
  34696. var inclusionTree, zeroBitPlanesTree;
  34697. if (precinct['inclusionTree'] !== undefined) {
  34698. inclusionTree = precinct.inclusionTree;
  34699. } else {
  34700. // building inclusion and zero bit-planes trees
  34701. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34702. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34703. inclusionTree = new InclusionTree(width, height, layerNumber);
  34704. zeroBitPlanesTree = new TagTree(width, height);
  34705. precinct.inclusionTree = inclusionTree;
  34706. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34707. }
  34708. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34709. while (true) {
  34710. if (readBits(1)) {
  34711. valueReady = !inclusionTree.nextLevel();
  34712. if (valueReady) {
  34713. codeblock.included = true;
  34714. codeblockIncluded = firstTimeInclusion = true;
  34715. break;
  34716. }
  34717. } else {
  34718. inclusionTree.incrementValue(layerNumber);
  34719. break;
  34720. }
  34721. }
  34722. }
  34723. }
  34724. if (!codeblockIncluded) {
  34725. continue;
  34726. }
  34727. if (firstTimeInclusion) {
  34728. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34729. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34730. while (true) {
  34731. if (readBits(1)) {
  34732. valueReady = !zeroBitPlanesTree.nextLevel();
  34733. if (valueReady) {
  34734. break;
  34735. }
  34736. } else {
  34737. zeroBitPlanesTree.incrementValue();
  34738. }
  34739. }
  34740. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34741. }
  34742. var codingpasses = readCodingpasses();
  34743. while (readBits(1)) {
  34744. codeblock.Lblock++;
  34745. }
  34746. var codingpassesLog2 = log2(codingpasses);
  34747. // rounding down log2
  34748. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34749. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34750. var codedDataLength = readBits(bits);
  34751. queue.push({
  34752. codeblock: codeblock,
  34753. codingpasses: codingpasses,
  34754. dataLength: codedDataLength
  34755. });
  34756. }
  34757. alignToByte();
  34758. if (ephMarkerUsed) {
  34759. skipMarkerIfEqual(0x92);
  34760. }
  34761. while (queue.length > 0) {
  34762. var packetItem = queue.shift();
  34763. codeblock = packetItem.codeblock;
  34764. if (codeblock['data'] === undefined) {
  34765. codeblock.data = [];
  34766. }
  34767. codeblock.data.push({
  34768. data: data,
  34769. start: offset + position,
  34770. end: offset + position + packetItem.dataLength,
  34771. codingpasses: packetItem.codingpasses
  34772. });
  34773. position += packetItem.dataLength;
  34774. }
  34775. }
  34776. return position;
  34777. }
  34778. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34779. delta, mb, reversible, segmentationSymbolUsed) {
  34780. var x0 = subband.tbx0;
  34781. var y0 = subband.tby0;
  34782. var width = subband.tbx1 - subband.tbx0;
  34783. var codeblocks = subband.codeblocks;
  34784. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34785. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34786. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34787. var codeblock = codeblocks[i];
  34788. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34789. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34790. if (blockWidth === 0 || blockHeight === 0) {
  34791. continue;
  34792. }
  34793. if (codeblock['data'] === undefined) {
  34794. continue;
  34795. }
  34796. var bitModel, currentCodingpassType;
  34797. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34798. codeblock.zeroBitPlanes, mb);
  34799. currentCodingpassType = 2; // first bit plane starts from cleanup
  34800. // collect data
  34801. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34802. var j, jj, dataItem;
  34803. for (j = 0, jj = data.length; j < jj; j++) {
  34804. dataItem = data[j];
  34805. totalLength += dataItem.end - dataItem.start;
  34806. codingpasses += dataItem.codingpasses;
  34807. }
  34808. var encodedData = new Uint8Array(totalLength);
  34809. var position = 0;
  34810. for (j = 0, jj = data.length; j < jj; j++) {
  34811. dataItem = data[j];
  34812. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34813. encodedData.set(chunk, position);
  34814. position += chunk.length;
  34815. }
  34816. // decoding the item
  34817. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34818. bitModel.setDecoder(decoder);
  34819. for (j = 0; j < codingpasses; j++) {
  34820. switch (currentCodingpassType) {
  34821. case 0:
  34822. bitModel.runSignificancePropogationPass();
  34823. break;
  34824. case 1:
  34825. bitModel.runMagnitudeRefinementPass();
  34826. break;
  34827. case 2:
  34828. bitModel.runCleanupPass();
  34829. if (segmentationSymbolUsed) {
  34830. bitModel.checkSegmentationSymbol();
  34831. }
  34832. break;
  34833. }
  34834. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34835. }
  34836. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34837. var sign = bitModel.coefficentsSign;
  34838. var magnitude = bitModel.coefficentsMagnitude;
  34839. var bitsDecoded = bitModel.bitsDecoded;
  34840. var magnitudeCorrection = reversible ? 0 : 0.5;
  34841. var k, n, nb;
  34842. position = 0;
  34843. // Do the interleaving of Section F.3.3 here, so we do not need
  34844. // to copy later. LL level is not interleaved, just copied.
  34845. var interleave = (subband.type !== 'LL');
  34846. for (j = 0; j < blockHeight; j++) {
  34847. var row = (offset / width) | 0; // row in the non-interleaved subband
  34848. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34849. for (k = 0; k < blockWidth; k++) {
  34850. n = magnitude[position];
  34851. if (n !== 0) {
  34852. n = (n + magnitudeCorrection) * delta;
  34853. if (sign[position] !== 0) {
  34854. n = -n;
  34855. }
  34856. nb = bitsDecoded[position];
  34857. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34858. if (reversible && (nb >= mb)) {
  34859. coefficients[pos] = n;
  34860. } else {
  34861. coefficients[pos] = n * (1 << (mb - nb));
  34862. }
  34863. }
  34864. offset++;
  34865. position++;
  34866. }
  34867. offset += width - blockWidth;
  34868. }
  34869. }
  34870. }
  34871. function transformTile(context, tile, c) {
  34872. var component = tile.components[c];
  34873. var codingStyleParameters = component.codingStyleParameters;
  34874. var quantizationParameters = component.quantizationParameters;
  34875. var decompositionLevelsCount =
  34876. codingStyleParameters.decompositionLevelsCount;
  34877. var spqcds = quantizationParameters.SPqcds;
  34878. var scalarExpounded = quantizationParameters.scalarExpounded;
  34879. var guardBits = quantizationParameters.guardBits;
  34880. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34881. var precision = context.components[c].precision;
  34882. var reversible = codingStyleParameters.reversibleTransformation;
  34883. var transform = (reversible ? new ReversibleTransform() :
  34884. new IrreversibleTransform());
  34885. var subbandCoefficients = [];
  34886. var b = 0;
  34887. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34888. var resolution = component.resolutions[i];
  34889. var width = resolution.trx1 - resolution.trx0;
  34890. var height = resolution.try1 - resolution.try0;
  34891. // Allocate space for the whole sublevel.
  34892. var coefficients = new Float32Array(width * height);
  34893. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34894. var mu, epsilon;
  34895. if (!scalarExpounded) {
  34896. // formula E-5
  34897. mu = spqcds[0].mu;
  34898. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34899. } else {
  34900. mu = spqcds[b].mu;
  34901. epsilon = spqcds[b].epsilon;
  34902. b++;
  34903. }
  34904. var subband = resolution.subbands[j];
  34905. var gainLog2 = SubbandsGainLog2[subband.type];
  34906. // calulate quantization coefficient (Section E.1.1.1)
  34907. var delta = (reversible ? 1 :
  34908. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34909. var mb = (guardBits + epsilon - 1);
  34910. // In the first resolution level, copyCoefficients will fill the
  34911. // whole array with coefficients. In the succeding passes,
  34912. // copyCoefficients will consecutively fill in the values that belong
  34913. // to the interleaved positions of the HL, LH, and HH coefficients.
  34914. // The LL coefficients will then be interleaved in Transform.iterate().
  34915. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34916. reversible, segmentationSymbolUsed);
  34917. }
  34918. subbandCoefficients.push({
  34919. width: width,
  34920. height: height,
  34921. items: coefficients
  34922. });
  34923. }
  34924. var result = transform.calculate(subbandCoefficients,
  34925. component.tcx0, component.tcy0);
  34926. return {
  34927. left: component.tcx0,
  34928. top: component.tcy0,
  34929. width: result.width,
  34930. height: result.height,
  34931. items: result.items
  34932. };
  34933. }
  34934. function transformComponents(context) {
  34935. var siz = context.SIZ;
  34936. var components = context.components;
  34937. var componentsCount = siz.Csiz;
  34938. var resultImages = [];
  34939. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34940. var tile = context.tiles[i];
  34941. var transformedTiles = [];
  34942. var c;
  34943. for (c = 0; c < componentsCount; c++) {
  34944. transformedTiles[c] = transformTile(context, tile, c);
  34945. }
  34946. var tile0 = transformedTiles[0];
  34947. var out = new Uint8Array(tile0.items.length * componentsCount);
  34948. var result = {
  34949. left: tile0.left,
  34950. top: tile0.top,
  34951. width: tile0.width,
  34952. height: tile0.height,
  34953. items: out
  34954. };
  34955. // Section G.2.2 Inverse multi component transform
  34956. var shift, offset, max, min, maxK;
  34957. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34958. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34959. var fourComponents = componentsCount === 4;
  34960. var y0items = transformedTiles[0].items;
  34961. var y1items = transformedTiles[1].items;
  34962. var y2items = transformedTiles[2].items;
  34963. var y3items = fourComponents ? transformedTiles[3].items : null;
  34964. // HACK: The multiple component transform formulas below assume that
  34965. // all components have the same precision. With this in mind, we
  34966. // compute shift and offset only once.
  34967. shift = components[0].precision - 8;
  34968. offset = (128 << shift) + 0.5;
  34969. max = 255 * (1 << shift);
  34970. maxK = max * 0.5;
  34971. min = -maxK;
  34972. var component0 = tile.components[0];
  34973. var alpha01 = componentsCount - 3;
  34974. jj = y0items.length;
  34975. if (!component0.codingStyleParameters.reversibleTransformation) {
  34976. // inverse irreversible multiple component transform
  34977. for (j = 0; j < jj; j++, pos += alpha01) {
  34978. y0 = y0items[j] + offset;
  34979. y1 = y1items[j];
  34980. y2 = y2items[j];
  34981. r = y0 + 1.402 * y2;
  34982. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34983. b = y0 + 1.772 * y1;
  34984. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34985. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34986. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34987. }
  34988. } else {
  34989. // inverse reversible multiple component transform
  34990. for (j = 0; j < jj; j++, pos += alpha01) {
  34991. y0 = y0items[j] + offset;
  34992. y1 = y1items[j];
  34993. y2 = y2items[j];
  34994. g = y0 - ((y2 + y1) >> 2);
  34995. r = g + y2;
  34996. b = g + y1;
  34997. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34998. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34999. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  35000. }
  35001. }
  35002. if (fourComponents) {
  35003. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  35004. k = y3items[j];
  35005. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  35006. }
  35007. }
  35008. } else { // no multi-component transform
  35009. for (c = 0; c < componentsCount; c++) {
  35010. var items = transformedTiles[c].items;
  35011. shift = components[c].precision - 8;
  35012. offset = (128 << shift) + 0.5;
  35013. max = (127.5 * (1 << shift));
  35014. min = -max;
  35015. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  35016. val = items[j];
  35017. out[pos] = val <= min ? 0 :
  35018. val >= max ? 255 : (val + offset) >> shift;
  35019. pos += componentsCount;
  35020. }
  35021. }
  35022. }
  35023. resultImages.push(result);
  35024. }
  35025. return resultImages;
  35026. }
  35027. function initializeTile(context, tileIndex) {
  35028. var siz = context.SIZ;
  35029. var componentsCount = siz.Csiz;
  35030. var tile = context.tiles[tileIndex];
  35031. for (var c = 0; c < componentsCount; c++) {
  35032. var component = tile.components[c];
  35033. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  35034. context.currentTile.QCC[c] : context.currentTile.QCD);
  35035. component.quantizationParameters = qcdOrQcc;
  35036. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  35037. context.currentTile.COC[c] : context.currentTile.COD);
  35038. component.codingStyleParameters = codOrCoc;
  35039. }
  35040. tile.codingStyleDefaultParameters = context.currentTile.COD;
  35041. }
  35042. // Section B.10.2 Tag trees
  35043. var TagTree = (function TagTreeClosure() {
  35044. function TagTree(width, height) {
  35045. var levelsLength = log2(Math.max(width, height)) + 1;
  35046. this.levels = [];
  35047. for (var i = 0; i < levelsLength; i++) {
  35048. var level = {
  35049. width: width,
  35050. height: height,
  35051. items: []
  35052. };
  35053. this.levels.push(level);
  35054. width = Math.ceil(width / 2);
  35055. height = Math.ceil(height / 2);
  35056. }
  35057. }
  35058. TagTree.prototype = {
  35059. reset: function TagTree_reset(i, j) {
  35060. var currentLevel = 0, value = 0, level;
  35061. while (currentLevel < this.levels.length) {
  35062. level = this.levels[currentLevel];
  35063. var index = i + j * level.width;
  35064. if (level.items[index] !== undefined) {
  35065. value = level.items[index];
  35066. break;
  35067. }
  35068. level.index = index;
  35069. i >>= 1;
  35070. j >>= 1;
  35071. currentLevel++;
  35072. }
  35073. currentLevel--;
  35074. level = this.levels[currentLevel];
  35075. level.items[level.index] = value;
  35076. this.currentLevel = currentLevel;
  35077. delete this.value;
  35078. },
  35079. incrementValue: function TagTree_incrementValue() {
  35080. var level = this.levels[this.currentLevel];
  35081. level.items[level.index]++;
  35082. },
  35083. nextLevel: function TagTree_nextLevel() {
  35084. var currentLevel = this.currentLevel;
  35085. var level = this.levels[currentLevel];
  35086. var value = level.items[level.index];
  35087. currentLevel--;
  35088. if (currentLevel < 0) {
  35089. this.value = value;
  35090. return false;
  35091. }
  35092. this.currentLevel = currentLevel;
  35093. level = this.levels[currentLevel];
  35094. level.items[level.index] = value;
  35095. return true;
  35096. }
  35097. };
  35098. return TagTree;
  35099. })();
  35100. var InclusionTree = (function InclusionTreeClosure() {
  35101. function InclusionTree(width, height, defaultValue) {
  35102. var levelsLength = log2(Math.max(width, height)) + 1;
  35103. this.levels = [];
  35104. for (var i = 0; i < levelsLength; i++) {
  35105. var items = new Uint8Array(width * height);
  35106. for (var j = 0, jj = items.length; j < jj; j++) {
  35107. items[j] = defaultValue;
  35108. }
  35109. var level = {
  35110. width: width,
  35111. height: height,
  35112. items: items
  35113. };
  35114. this.levels.push(level);
  35115. width = Math.ceil(width / 2);
  35116. height = Math.ceil(height / 2);
  35117. }
  35118. }
  35119. InclusionTree.prototype = {
  35120. reset: function InclusionTree_reset(i, j, stopValue) {
  35121. var currentLevel = 0;
  35122. while (currentLevel < this.levels.length) {
  35123. var level = this.levels[currentLevel];
  35124. var index = i + j * level.width;
  35125. level.index = index;
  35126. var value = level.items[index];
  35127. if (value === 0xFF) {
  35128. break;
  35129. }
  35130. if (value > stopValue) {
  35131. this.currentLevel = currentLevel;
  35132. // already know about this one, propagating the value to top levels
  35133. this.propagateValues();
  35134. return false;
  35135. }
  35136. i >>= 1;
  35137. j >>= 1;
  35138. currentLevel++;
  35139. }
  35140. this.currentLevel = currentLevel - 1;
  35141. return true;
  35142. },
  35143. incrementValue: function InclusionTree_incrementValue(stopValue) {
  35144. var level = this.levels[this.currentLevel];
  35145. level.items[level.index] = stopValue + 1;
  35146. this.propagateValues();
  35147. },
  35148. propagateValues: function InclusionTree_propagateValues() {
  35149. var levelIndex = this.currentLevel;
  35150. var level = this.levels[levelIndex];
  35151. var currentValue = level.items[level.index];
  35152. while (--levelIndex >= 0) {
  35153. level = this.levels[levelIndex];
  35154. level.items[level.index] = currentValue;
  35155. }
  35156. },
  35157. nextLevel: function InclusionTree_nextLevel() {
  35158. var currentLevel = this.currentLevel;
  35159. var level = this.levels[currentLevel];
  35160. var value = level.items[level.index];
  35161. level.items[level.index] = 0xFF;
  35162. currentLevel--;
  35163. if (currentLevel < 0) {
  35164. return false;
  35165. }
  35166. this.currentLevel = currentLevel;
  35167. level = this.levels[currentLevel];
  35168. level.items[level.index] = value;
  35169. return true;
  35170. }
  35171. };
  35172. return InclusionTree;
  35173. })();
  35174. // Section D. Coefficient bit modeling
  35175. var BitModel = (function BitModelClosure() {
  35176. var UNIFORM_CONTEXT = 17;
  35177. var RUNLENGTH_CONTEXT = 18;
  35178. // Table D-1
  35179. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  35180. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  35181. var LLAndLHContextsLabel = new Uint8Array([
  35182. 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,
  35183. 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,
  35184. 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
  35185. ]);
  35186. var HLContextLabel = new Uint8Array([
  35187. 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,
  35188. 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,
  35189. 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
  35190. ]);
  35191. var HHContextLabel = new Uint8Array([
  35192. 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,
  35193. 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,
  35194. 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
  35195. ]);
  35196. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  35197. this.width = width;
  35198. this.height = height;
  35199. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  35200. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  35201. var coefficientCount = width * height;
  35202. // coefficients outside the encoding region treated as insignificant
  35203. // add border state cells for significanceState
  35204. this.neighborsSignificance = new Uint8Array(coefficientCount);
  35205. this.coefficentsSign = new Uint8Array(coefficientCount);
  35206. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  35207. mb > 6 ? new Uint16Array(coefficientCount) :
  35208. new Uint8Array(coefficientCount);
  35209. this.processingFlags = new Uint8Array(coefficientCount);
  35210. var bitsDecoded = new Uint8Array(coefficientCount);
  35211. if (zeroBitPlanes !== 0) {
  35212. for (var i = 0; i < coefficientCount; i++) {
  35213. bitsDecoded[i] = zeroBitPlanes;
  35214. }
  35215. }
  35216. this.bitsDecoded = bitsDecoded;
  35217. this.reset();
  35218. }
  35219. BitModel.prototype = {
  35220. setDecoder: function BitModel_setDecoder(decoder) {
  35221. this.decoder = decoder;
  35222. },
  35223. reset: function BitModel_reset() {
  35224. // We have 17 contexts that are accessed via context labels,
  35225. // plus the uniform and runlength context.
  35226. this.contexts = new Int8Array(19);
  35227. // Contexts are packed into 1 byte:
  35228. // highest 7 bits carry the index, lowest bit carries mps
  35229. this.contexts[0] = (4 << 1) | 0;
  35230. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  35231. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  35232. },
  35233. setNeighborsSignificance:
  35234. function BitModel_setNeighborsSignificance(row, column, index) {
  35235. var neighborsSignificance = this.neighborsSignificance;
  35236. var width = this.width, height = this.height;
  35237. var left = (column > 0);
  35238. var right = (column + 1 < width);
  35239. var i;
  35240. if (row > 0) {
  35241. i = index - width;
  35242. if (left) {
  35243. neighborsSignificance[i - 1] += 0x10;
  35244. }
  35245. if (right) {
  35246. neighborsSignificance[i + 1] += 0x10;
  35247. }
  35248. neighborsSignificance[i] += 0x04;
  35249. }
  35250. if (row + 1 < height) {
  35251. i = index + width;
  35252. if (left) {
  35253. neighborsSignificance[i - 1] += 0x10;
  35254. }
  35255. if (right) {
  35256. neighborsSignificance[i + 1] += 0x10;
  35257. }
  35258. neighborsSignificance[i] += 0x04;
  35259. }
  35260. if (left) {
  35261. neighborsSignificance[index - 1] += 0x01;
  35262. }
  35263. if (right) {
  35264. neighborsSignificance[index + 1] += 0x01;
  35265. }
  35266. neighborsSignificance[index] |= 0x80;
  35267. },
  35268. runSignificancePropogationPass:
  35269. function BitModel_runSignificancePropogationPass() {
  35270. var decoder = this.decoder;
  35271. var width = this.width, height = this.height;
  35272. var coefficentsMagnitude = this.coefficentsMagnitude;
  35273. var coefficentsSign = this.coefficentsSign;
  35274. var neighborsSignificance = this.neighborsSignificance;
  35275. var processingFlags = this.processingFlags;
  35276. var contexts = this.contexts;
  35277. var labels = this.contextLabelTable;
  35278. var bitsDecoded = this.bitsDecoded;
  35279. var processedInverseMask = ~1;
  35280. var processedMask = 1;
  35281. var firstMagnitudeBitMask = 2;
  35282. for (var i0 = 0; i0 < height; i0 += 4) {
  35283. for (var j = 0; j < width; j++) {
  35284. var index = i0 * width + j;
  35285. for (var i1 = 0; i1 < 4; i1++, index += width) {
  35286. var i = i0 + i1;
  35287. if (i >= height) {
  35288. break;
  35289. }
  35290. // clear processed flag first
  35291. processingFlags[index] &= processedInverseMask;
  35292. if (coefficentsMagnitude[index] ||
  35293. !neighborsSignificance[index]) {
  35294. continue;
  35295. }
  35296. var contextLabel = labels[neighborsSignificance[index]];
  35297. var decision = decoder.readBit(contexts, contextLabel);
  35298. if (decision) {
  35299. var sign = this.decodeSignBit(i, j, index);
  35300. coefficentsSign[index] = sign;
  35301. coefficentsMagnitude[index] = 1;
  35302. this.setNeighborsSignificance(i, j, index);
  35303. processingFlags[index] |= firstMagnitudeBitMask;
  35304. }
  35305. bitsDecoded[index]++;
  35306. processingFlags[index] |= processedMask;
  35307. }
  35308. }
  35309. }
  35310. },
  35311. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  35312. var width = this.width, height = this.height;
  35313. var coefficentsMagnitude = this.coefficentsMagnitude;
  35314. var coefficentsSign = this.coefficentsSign;
  35315. var contribution, sign0, sign1, significance1;
  35316. var contextLabel, decoded;
  35317. // calculate horizontal contribution
  35318. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  35319. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  35320. sign1 = coefficentsSign[index + 1];
  35321. if (significance1) {
  35322. sign0 = coefficentsSign[index - 1];
  35323. contribution = 1 - sign1 - sign0;
  35324. } else {
  35325. contribution = 1 - sign1 - sign1;
  35326. }
  35327. } else if (significance1) {
  35328. sign0 = coefficentsSign[index - 1];
  35329. contribution = 1 - sign0 - sign0;
  35330. } else {
  35331. contribution = 0;
  35332. }
  35333. var horizontalContribution = 3 * contribution;
  35334. // calculate vertical contribution and combine with the horizontal
  35335. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  35336. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  35337. sign1 = coefficentsSign[index + width];
  35338. if (significance1) {
  35339. sign0 = coefficentsSign[index - width];
  35340. contribution = 1 - sign1 - sign0 + horizontalContribution;
  35341. } else {
  35342. contribution = 1 - sign1 - sign1 + horizontalContribution;
  35343. }
  35344. } else if (significance1) {
  35345. sign0 = coefficentsSign[index - width];
  35346. contribution = 1 - sign0 - sign0 + horizontalContribution;
  35347. } else {
  35348. contribution = horizontalContribution;
  35349. }
  35350. if (contribution >= 0) {
  35351. contextLabel = 9 + contribution;
  35352. decoded = this.decoder.readBit(this.contexts, contextLabel);
  35353. } else {
  35354. contextLabel = 9 - contribution;
  35355. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  35356. }
  35357. return decoded;
  35358. },
  35359. runMagnitudeRefinementPass:
  35360. function BitModel_runMagnitudeRefinementPass() {
  35361. var decoder = this.decoder;
  35362. var width = this.width, height = this.height;
  35363. var coefficentsMagnitude = this.coefficentsMagnitude;
  35364. var neighborsSignificance = this.neighborsSignificance;
  35365. var contexts = this.contexts;
  35366. var bitsDecoded = this.bitsDecoded;
  35367. var processingFlags = this.processingFlags;
  35368. var processedMask = 1;
  35369. var firstMagnitudeBitMask = 2;
  35370. var length = width * height;
  35371. var width4 = width * 4;
  35372. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  35373. indexNext = Math.min(length, index0 + width4);
  35374. for (var j = 0; j < width; j++) {
  35375. for (var index = index0 + j; index < indexNext; index += width) {
  35376. // significant but not those that have just become
  35377. if (!coefficentsMagnitude[index] ||
  35378. (processingFlags[index] & processedMask) !== 0) {
  35379. continue;
  35380. }
  35381. var contextLabel = 16;
  35382. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  35383. processingFlags[index] ^= firstMagnitudeBitMask;
  35384. // first refinement
  35385. var significance = neighborsSignificance[index] & 127;
  35386. contextLabel = significance === 0 ? 15 : 14;
  35387. }
  35388. var bit = decoder.readBit(contexts, contextLabel);
  35389. coefficentsMagnitude[index] =
  35390. (coefficentsMagnitude[index] << 1) | bit;
  35391. bitsDecoded[index]++;
  35392. processingFlags[index] |= processedMask;
  35393. }
  35394. }
  35395. }
  35396. },
  35397. runCleanupPass: function BitModel_runCleanupPass() {
  35398. var decoder = this.decoder;
  35399. var width = this.width, height = this.height;
  35400. var neighborsSignificance = this.neighborsSignificance;
  35401. var coefficentsMagnitude = this.coefficentsMagnitude;
  35402. var coefficentsSign = this.coefficentsSign;
  35403. var contexts = this.contexts;
  35404. var labels = this.contextLabelTable;
  35405. var bitsDecoded = this.bitsDecoded;
  35406. var processingFlags = this.processingFlags;
  35407. var processedMask = 1;
  35408. var firstMagnitudeBitMask = 2;
  35409. var oneRowDown = width;
  35410. var twoRowsDown = width * 2;
  35411. var threeRowsDown = width * 3;
  35412. var iNext;
  35413. for (var i0 = 0; i0 < height; i0 = iNext) {
  35414. iNext = Math.min(i0 + 4, height);
  35415. var indexBase = i0 * width;
  35416. var checkAllEmpty = i0 + 3 < height;
  35417. for (var j = 0; j < width; j++) {
  35418. var index0 = indexBase + j;
  35419. // using the property: labels[neighborsSignificance[index]] === 0
  35420. // when neighborsSignificance[index] === 0
  35421. var allEmpty = (checkAllEmpty &&
  35422. processingFlags[index0] === 0 &&
  35423. processingFlags[index0 + oneRowDown] === 0 &&
  35424. processingFlags[index0 + twoRowsDown] === 0 &&
  35425. processingFlags[index0 + threeRowsDown] === 0 &&
  35426. neighborsSignificance[index0] === 0 &&
  35427. neighborsSignificance[index0 + oneRowDown] === 0 &&
  35428. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  35429. neighborsSignificance[index0 + threeRowsDown] === 0);
  35430. var i1 = 0, index = index0;
  35431. var i = i0, sign;
  35432. if (allEmpty) {
  35433. var hasSignificantCoefficent =
  35434. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  35435. if (!hasSignificantCoefficent) {
  35436. bitsDecoded[index0]++;
  35437. bitsDecoded[index0 + oneRowDown]++;
  35438. bitsDecoded[index0 + twoRowsDown]++;
  35439. bitsDecoded[index0 + threeRowsDown]++;
  35440. continue; // next column
  35441. }
  35442. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35443. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35444. if (i1 !== 0) {
  35445. i = i0 + i1;
  35446. index += i1 * width;
  35447. }
  35448. sign = this.decodeSignBit(i, j, index);
  35449. coefficentsSign[index] = sign;
  35450. coefficentsMagnitude[index] = 1;
  35451. this.setNeighborsSignificance(i, j, index);
  35452. processingFlags[index] |= firstMagnitudeBitMask;
  35453. index = index0;
  35454. for (var i2 = i0; i2 <= i; i2++, index += width) {
  35455. bitsDecoded[index]++;
  35456. }
  35457. i1++;
  35458. }
  35459. for (i = i0 + i1; i < iNext; i++, index += width) {
  35460. if (coefficentsMagnitude[index] ||
  35461. (processingFlags[index] & processedMask) !== 0) {
  35462. continue;
  35463. }
  35464. var contextLabel = labels[neighborsSignificance[index]];
  35465. var decision = decoder.readBit(contexts, contextLabel);
  35466. if (decision === 1) {
  35467. sign = this.decodeSignBit(i, j, index);
  35468. coefficentsSign[index] = sign;
  35469. coefficentsMagnitude[index] = 1;
  35470. this.setNeighborsSignificance(i, j, index);
  35471. processingFlags[index] |= firstMagnitudeBitMask;
  35472. }
  35473. bitsDecoded[index]++;
  35474. }
  35475. }
  35476. }
  35477. },
  35478. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35479. var decoder = this.decoder;
  35480. var contexts = this.contexts;
  35481. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35482. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35483. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35484. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35485. if (symbol !== 0xA) {
  35486. throw new Error('JPX Error: Invalid segmentation symbol');
  35487. }
  35488. }
  35489. };
  35490. return BitModel;
  35491. })();
  35492. // Section F, Discrete wavelet transformation
  35493. var Transform = (function TransformClosure() {
  35494. function Transform() {}
  35495. Transform.prototype.calculate =
  35496. function transformCalculate(subbands, u0, v0) {
  35497. var ll = subbands[0];
  35498. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35499. ll = this.iterate(ll, subbands[i], u0, v0);
  35500. }
  35501. return ll;
  35502. };
  35503. Transform.prototype.extend = function extend(buffer, offset, size) {
  35504. // Section F.3.7 extending... using max extension of 4
  35505. var i1 = offset - 1, j1 = offset + 1;
  35506. var i2 = offset + size - 2, j2 = offset + size;
  35507. buffer[i1--] = buffer[j1++];
  35508. buffer[j2++] = buffer[i2--];
  35509. buffer[i1--] = buffer[j1++];
  35510. buffer[j2++] = buffer[i2--];
  35511. buffer[i1--] = buffer[j1++];
  35512. buffer[j2++] = buffer[i2--];
  35513. buffer[i1] = buffer[j1];
  35514. buffer[j2] = buffer[i2];
  35515. };
  35516. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35517. u0, v0) {
  35518. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35519. var width = hl_lh_hh.width;
  35520. var height = hl_lh_hh.height;
  35521. var items = hl_lh_hh.items;
  35522. var i, j, k, l, u, v;
  35523. // Interleave LL according to Section F.3.3
  35524. for (k = 0, i = 0; i < llHeight; i++) {
  35525. l = i * 2 * width;
  35526. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35527. items[l] = llItems[k];
  35528. }
  35529. }
  35530. // The LL band is not needed anymore.
  35531. llItems = ll.items = null;
  35532. var bufferPadding = 4;
  35533. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35534. // Section F.3.4 HOR_SR
  35535. if (width === 1) {
  35536. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35537. if ((u0 & 1) !== 0) {
  35538. for (v = 0, k = 0; v < height; v++, k += width) {
  35539. items[k] *= 0.5;
  35540. }
  35541. }
  35542. } else {
  35543. for (v = 0, k = 0; v < height; v++, k += width) {
  35544. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35545. this.extend(rowBuffer, bufferPadding, width);
  35546. this.filter(rowBuffer, bufferPadding, width);
  35547. items.set(
  35548. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35549. k);
  35550. }
  35551. }
  35552. // Accesses to the items array can take long, because it may not fit into
  35553. // CPU cache and has to be fetched from main memory. Since subsequent
  35554. // accesses to the items array are not local when reading columns, we
  35555. // have a cache miss every time. To reduce cache misses, get up to
  35556. // 'numBuffers' items at a time and store them into the individual
  35557. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35558. var numBuffers = 16;
  35559. var colBuffers = [];
  35560. for (i = 0; i < numBuffers; i++) {
  35561. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35562. }
  35563. var b, currentBuffer = 0;
  35564. ll = bufferPadding + height;
  35565. // Section F.3.5 VER_SR
  35566. if (height === 1) {
  35567. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35568. if ((v0 & 1) !== 0) {
  35569. for (u = 0; u < width; u++) {
  35570. items[u] *= 0.5;
  35571. }
  35572. }
  35573. } else {
  35574. for (u = 0; u < width; u++) {
  35575. // if we ran out of buffers, copy several image columns at once
  35576. if (currentBuffer === 0) {
  35577. numBuffers = Math.min(width - u, numBuffers);
  35578. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35579. for (b = 0; b < numBuffers; b++) {
  35580. colBuffers[b][l] = items[k + b];
  35581. }
  35582. }
  35583. currentBuffer = numBuffers;
  35584. }
  35585. currentBuffer--;
  35586. var buffer = colBuffers[currentBuffer];
  35587. this.extend(buffer, bufferPadding, height);
  35588. this.filter(buffer, bufferPadding, height);
  35589. // If this is last buffer in this group of buffers, flush all buffers.
  35590. if (currentBuffer === 0) {
  35591. k = u - numBuffers + 1;
  35592. for (l = bufferPadding; l < ll; k += width, l++) {
  35593. for (b = 0; b < numBuffers; b++) {
  35594. items[k + b] = colBuffers[b][l];
  35595. }
  35596. }
  35597. }
  35598. }
  35599. }
  35600. return {
  35601. width: width,
  35602. height: height,
  35603. items: items
  35604. };
  35605. };
  35606. return Transform;
  35607. })();
  35608. // Section 3.8.2 Irreversible 9-7 filter
  35609. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35610. function IrreversibleTransform() {
  35611. Transform.call(this);
  35612. }
  35613. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35614. IrreversibleTransform.prototype.filter =
  35615. function irreversibleTransformFilter(x, offset, length) {
  35616. var len = length >> 1;
  35617. offset = offset | 0;
  35618. var j, n, current, next;
  35619. var alpha = -1.586134342059924;
  35620. var beta = -0.052980118572961;
  35621. var gamma = 0.882911075530934;
  35622. var delta = 0.443506852043971;
  35623. var K = 1.230174104914001;
  35624. var K_ = 1 / K;
  35625. // step 1 is combined with step 3
  35626. // step 2
  35627. j = offset - 3;
  35628. for (n = len + 4; n--; j += 2) {
  35629. x[j] *= K_;
  35630. }
  35631. // step 1 & 3
  35632. j = offset - 2;
  35633. current = delta * x[j -1];
  35634. for (n = len + 3; n--; j += 2) {
  35635. next = delta * x[j + 1];
  35636. x[j] = K * x[j] - current - next;
  35637. if (n--) {
  35638. j += 2;
  35639. current = delta * x[j + 1];
  35640. x[j] = K * x[j] - current - next;
  35641. } else {
  35642. break;
  35643. }
  35644. }
  35645. // step 4
  35646. j = offset - 1;
  35647. current = gamma * x[j - 1];
  35648. for (n = len + 2; n--; j += 2) {
  35649. next = gamma * x[j + 1];
  35650. x[j] -= current + next;
  35651. if (n--) {
  35652. j += 2;
  35653. current = gamma * x[j + 1];
  35654. x[j] -= current + next;
  35655. } else {
  35656. break;
  35657. }
  35658. }
  35659. // step 5
  35660. j = offset;
  35661. current = beta * x[j - 1];
  35662. for (n = len + 1; n--; j += 2) {
  35663. next = beta * x[j + 1];
  35664. x[j] -= current + next;
  35665. if (n--) {
  35666. j += 2;
  35667. current = beta * x[j + 1];
  35668. x[j] -= current + next;
  35669. } else {
  35670. break;
  35671. }
  35672. }
  35673. // step 6
  35674. if (len !== 0) {
  35675. j = offset + 1;
  35676. current = alpha * x[j - 1];
  35677. for (n = len; n--; j += 2) {
  35678. next = alpha * x[j + 1];
  35679. x[j] -= current + next;
  35680. if (n--) {
  35681. j += 2;
  35682. current = alpha * x[j + 1];
  35683. x[j] -= current + next;
  35684. } else {
  35685. break;
  35686. }
  35687. }
  35688. }
  35689. };
  35690. return IrreversibleTransform;
  35691. })();
  35692. // Section 3.8.1 Reversible 5-3 filter
  35693. var ReversibleTransform = (function ReversibleTransformClosure() {
  35694. function ReversibleTransform() {
  35695. Transform.call(this);
  35696. }
  35697. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35698. ReversibleTransform.prototype.filter =
  35699. function reversibleTransformFilter(x, offset, length) {
  35700. var len = length >> 1;
  35701. offset = offset | 0;
  35702. var j, n;
  35703. for (j = offset, n = len + 1; n--; j += 2) {
  35704. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35705. }
  35706. for (j = offset + 1, n = len; n--; j += 2) {
  35707. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35708. }
  35709. };
  35710. return ReversibleTransform;
  35711. })();
  35712. return JpxImage;
  35713. })();
  35714. var Jbig2Image = (function Jbig2ImageClosure() {
  35715. // Utility data structures
  35716. function ContextCache() {}
  35717. ContextCache.prototype = {
  35718. getContexts: function(id) {
  35719. if (id in this) {
  35720. return this[id];
  35721. }
  35722. return (this[id] = new Int8Array(1 << 16));
  35723. }
  35724. };
  35725. function DecodingContext(data, start, end) {
  35726. this.data = data;
  35727. this.start = start;
  35728. this.end = end;
  35729. }
  35730. DecodingContext.prototype = {
  35731. get decoder() {
  35732. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35733. return shadow(this, 'decoder', decoder);
  35734. },
  35735. get contextCache() {
  35736. var cache = new ContextCache();
  35737. return shadow(this, 'contextCache', cache);
  35738. }
  35739. };
  35740. // Annex A. Arithmetic Integer Decoding Procedure
  35741. // A.2 Procedure for decoding values
  35742. function decodeInteger(contextCache, procedure, decoder) {
  35743. var contexts = contextCache.getContexts(procedure);
  35744. var prev = 1;
  35745. function readBits(length) {
  35746. var v = 0;
  35747. for (var i = 0; i < length; i++) {
  35748. var bit = decoder.readBit(contexts, prev);
  35749. prev = (prev < 256 ? (prev << 1) | bit :
  35750. (((prev << 1) | bit) & 511) | 256);
  35751. v = (v << 1) | bit;
  35752. }
  35753. return v >>> 0;
  35754. }
  35755. var sign = readBits(1);
  35756. var value = readBits(1) ?
  35757. (readBits(1) ?
  35758. (readBits(1) ?
  35759. (readBits(1) ?
  35760. (readBits(1) ?
  35761. (readBits(32) + 4436) :
  35762. readBits(12) + 340) :
  35763. readBits(8) + 84) :
  35764. readBits(6) + 20) :
  35765. readBits(4) + 4) :
  35766. readBits(2);
  35767. return (sign === 0 ? value : (value > 0 ? -value : null));
  35768. }
  35769. // A.3 The IAID decoding procedure
  35770. function decodeIAID(contextCache, decoder, codeLength) {
  35771. var contexts = contextCache.getContexts('IAID');
  35772. var prev = 1;
  35773. for (var i = 0; i < codeLength; i++) {
  35774. var bit = decoder.readBit(contexts, prev);
  35775. prev = (prev << 1) | bit;
  35776. }
  35777. if (codeLength < 31) {
  35778. return prev & ((1 << codeLength) - 1);
  35779. }
  35780. return prev & 0x7FFFFFFF;
  35781. }
  35782. // 7.3 Segment types
  35783. var SegmentTypes = [
  35784. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35785. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35786. null, null, null, null, null, 'patternDictionary', null, null, null,
  35787. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35788. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35789. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35790. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35791. 'IntermediateGenericRefinementRegion', null,
  35792. 'ImmediateGenericRefinementRegion',
  35793. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35794. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35795. 'Tables', null, null, null, null, null, null, null, null,
  35796. 'Extension'
  35797. ];
  35798. var CodingTemplates = [
  35799. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35800. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35801. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35802. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35803. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35804. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35805. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35806. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35807. {x: -1, y: 0}],
  35808. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35809. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35810. ];
  35811. var RefinementTemplates = [
  35812. {
  35813. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35814. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35815. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35816. },
  35817. {
  35818. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35819. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35820. {x: 0, y: 1}, {x: 1, y: 1}]
  35821. }
  35822. ];
  35823. // See 6.2.5.7 Decoding the bitmap.
  35824. var ReusedContexts = [
  35825. 0x9B25, // 10011 0110010 0101
  35826. 0x0795, // 0011 110010 101
  35827. 0x00E5, // 001 11001 01
  35828. 0x0195 // 011001 0101
  35829. ];
  35830. var RefinementReusedContexts = [
  35831. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35832. 0x0008 // '0000' + '001000'
  35833. ];
  35834. function decodeBitmapTemplate0(width, height, decodingContext) {
  35835. var decoder = decodingContext.decoder;
  35836. var contexts = decodingContext.contextCache.getContexts('GB');
  35837. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35838. // ...ooooo....
  35839. // ..ooooooo... Context template for current pixel (X)
  35840. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35841. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35842. for (i = 0; i < height; i++) {
  35843. row = bitmap[i] = new Uint8Array(width);
  35844. row1 = (i < 1) ? row : bitmap[i - 1];
  35845. row2 = (i < 2) ? row : bitmap[i - 2];
  35846. // At the beginning of each row:
  35847. // Fill contextLabel with pixels that are above/right of (X)
  35848. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35849. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35850. (row1[3] << 4);
  35851. for (j = 0; j < width; j++) {
  35852. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35853. // At each pixel: Clear contextLabel pixels that are shifted
  35854. // out of the context, then add new ones.
  35855. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35856. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  35857. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  35858. }
  35859. }
  35860. return bitmap;
  35861. }
  35862. // 6.2 Generic Region Decoding Procedure
  35863. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35864. decodingContext) {
  35865. if (mmr) {
  35866. error('JBIG2 error: MMR encoding is not supported');
  35867. }
  35868. // Use optimized version for the most common case
  35869. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35870. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35871. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35872. return decodeBitmapTemplate0(width, height, decodingContext);
  35873. }
  35874. var useskip = !!skip;
  35875. var template = CodingTemplates[templateIndex].concat(at);
  35876. // Sorting is non-standard, and it is not required. But sorting increases
  35877. // the number of template bits that can be reused from the previous
  35878. // contextLabel in the main loop.
  35879. template.sort(function (a, b) {
  35880. return (a.y - b.y) || (a.x - b.x);
  35881. });
  35882. var templateLength = template.length;
  35883. var templateX = new Int8Array(templateLength);
  35884. var templateY = new Int8Array(templateLength);
  35885. var changingTemplateEntries = [];
  35886. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35887. var c, k;
  35888. for (k = 0; k < templateLength; k++) {
  35889. templateX[k] = template[k].x;
  35890. templateY[k] = template[k].y;
  35891. minX = Math.min(minX, template[k].x);
  35892. maxX = Math.max(maxX, template[k].x);
  35893. minY = Math.min(minY, template[k].y);
  35894. // Check if the template pixel appears in two consecutive context labels,
  35895. // so it can be reused. Otherwise, we add it to the list of changing
  35896. // template entries.
  35897. if (k < templateLength - 1 &&
  35898. template[k].y === template[k + 1].y &&
  35899. template[k].x === template[k + 1].x - 1) {
  35900. reuseMask |= 1 << (templateLength - 1 - k);
  35901. } else {
  35902. changingTemplateEntries.push(k);
  35903. }
  35904. }
  35905. var changingEntriesLength = changingTemplateEntries.length;
  35906. var changingTemplateX = new Int8Array(changingEntriesLength);
  35907. var changingTemplateY = new Int8Array(changingEntriesLength);
  35908. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35909. for (c = 0; c < changingEntriesLength; c++) {
  35910. k = changingTemplateEntries[c];
  35911. changingTemplateX[c] = template[k].x;
  35912. changingTemplateY[c] = template[k].y;
  35913. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35914. }
  35915. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35916. var sbb_left = -minX;
  35917. var sbb_top = -minY;
  35918. var sbb_right = width - maxX;
  35919. var pseudoPixelContext = ReusedContexts[templateIndex];
  35920. var row = new Uint8Array(width);
  35921. var bitmap = [];
  35922. var decoder = decodingContext.decoder;
  35923. var contexts = decodingContext.contextCache.getContexts('GB');
  35924. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35925. for (var i = 0; i < height; i++) {
  35926. if (prediction) {
  35927. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35928. ltp ^= sltp;
  35929. if (ltp) {
  35930. bitmap.push(row); // duplicate previous row
  35931. continue;
  35932. }
  35933. }
  35934. row = new Uint8Array(row);
  35935. bitmap.push(row);
  35936. for (j = 0; j < width; j++) {
  35937. if (useskip && skip[i][j]) {
  35938. row[j] = 0;
  35939. continue;
  35940. }
  35941. // Are we in the middle of a scanline, so we can reuse contextLabel
  35942. // bits?
  35943. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35944. // If yes, we can just shift the bits that are reusable and only
  35945. // fetch the remaining ones.
  35946. contextLabel = (contextLabel << 1) & reuseMask;
  35947. for (k = 0; k < changingEntriesLength; k++) {
  35948. i0 = i + changingTemplateY[k];
  35949. j0 = j + changingTemplateX[k];
  35950. bit = bitmap[i0][j0];
  35951. if (bit) {
  35952. bit = changingTemplateBit[k];
  35953. contextLabel |= bit;
  35954. }
  35955. }
  35956. } else {
  35957. // compute the contextLabel from scratch
  35958. contextLabel = 0;
  35959. shift = templateLength - 1;
  35960. for (k = 0; k < templateLength; k++, shift--) {
  35961. j0 = j + templateX[k];
  35962. if (j0 >= 0 && j0 < width) {
  35963. i0 = i + templateY[k];
  35964. if (i0 >= 0) {
  35965. bit = bitmap[i0][j0];
  35966. if (bit) {
  35967. contextLabel |= bit << shift;
  35968. }
  35969. }
  35970. }
  35971. }
  35972. }
  35973. var pixel = decoder.readBit(contexts, contextLabel);
  35974. row[j] = pixel;
  35975. }
  35976. }
  35977. return bitmap;
  35978. }
  35979. // 6.3.2 Generic Refinement Region Decoding Procedure
  35980. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35981. offsetX, offsetY, prediction, at,
  35982. decodingContext) {
  35983. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35984. if (templateIndex === 0) {
  35985. codingTemplate = codingTemplate.concat([at[0]]);
  35986. }
  35987. var codingTemplateLength = codingTemplate.length;
  35988. var codingTemplateX = new Int32Array(codingTemplateLength);
  35989. var codingTemplateY = new Int32Array(codingTemplateLength);
  35990. var k;
  35991. for (k = 0; k < codingTemplateLength; k++) {
  35992. codingTemplateX[k] = codingTemplate[k].x;
  35993. codingTemplateY[k] = codingTemplate[k].y;
  35994. }
  35995. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35996. if (templateIndex === 0) {
  35997. referenceTemplate = referenceTemplate.concat([at[1]]);
  35998. }
  35999. var referenceTemplateLength = referenceTemplate.length;
  36000. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  36001. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  36002. for (k = 0; k < referenceTemplateLength; k++) {
  36003. referenceTemplateX[k] = referenceTemplate[k].x;
  36004. referenceTemplateY[k] = referenceTemplate[k].y;
  36005. }
  36006. var referenceWidth = referenceBitmap[0].length;
  36007. var referenceHeight = referenceBitmap.length;
  36008. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  36009. var bitmap = [];
  36010. var decoder = decodingContext.decoder;
  36011. var contexts = decodingContext.contextCache.getContexts('GR');
  36012. var ltp = 0;
  36013. for (var i = 0; i < height; i++) {
  36014. if (prediction) {
  36015. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  36016. ltp ^= sltp;
  36017. if (ltp) {
  36018. error('JBIG2 error: prediction is not supported');
  36019. }
  36020. }
  36021. var row = new Uint8Array(width);
  36022. bitmap.push(row);
  36023. for (var j = 0; j < width; j++) {
  36024. var i0, j0;
  36025. var contextLabel = 0;
  36026. for (k = 0; k < codingTemplateLength; k++) {
  36027. i0 = i + codingTemplateY[k];
  36028. j0 = j + codingTemplateX[k];
  36029. if (i0 < 0 || j0 < 0 || j0 >= width) {
  36030. contextLabel <<= 1; // out of bound pixel
  36031. } else {
  36032. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  36033. }
  36034. }
  36035. for (k = 0; k < referenceTemplateLength; k++) {
  36036. i0 = i + referenceTemplateY[k] + offsetY;
  36037. j0 = j + referenceTemplateX[k] + offsetX;
  36038. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  36039. j0 >= referenceWidth) {
  36040. contextLabel <<= 1; // out of bound pixel
  36041. } else {
  36042. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  36043. }
  36044. }
  36045. var pixel = decoder.readBit(contexts, contextLabel);
  36046. row[j] = pixel;
  36047. }
  36048. }
  36049. return bitmap;
  36050. }
  36051. // 6.5.5 Decoding the symbol dictionary
  36052. function decodeSymbolDictionary(huffman, refinement, symbols,
  36053. numberOfNewSymbols, numberOfExportedSymbols,
  36054. huffmanTables, templateIndex, at,
  36055. refinementTemplateIndex, refinementAt,
  36056. decodingContext) {
  36057. if (huffman) {
  36058. error('JBIG2 error: huffman is not supported');
  36059. }
  36060. var newSymbols = [];
  36061. var currentHeight = 0;
  36062. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  36063. var decoder = decodingContext.decoder;
  36064. var contextCache = decodingContext.contextCache;
  36065. while (newSymbols.length < numberOfNewSymbols) {
  36066. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  36067. currentHeight += deltaHeight;
  36068. var currentWidth = 0;
  36069. var totalWidth = 0;
  36070. while (true) {
  36071. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  36072. if (deltaWidth === null) {
  36073. break; // OOB
  36074. }
  36075. currentWidth += deltaWidth;
  36076. totalWidth += currentWidth;
  36077. var bitmap;
  36078. if (refinement) {
  36079. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  36080. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  36081. if (numberOfInstances > 1) {
  36082. bitmap = decodeTextRegion(huffman, refinement,
  36083. currentWidth, currentHeight, 0,
  36084. numberOfInstances, 1, //strip size
  36085. symbols.concat(newSymbols),
  36086. symbolCodeLength,
  36087. 0, //transposed
  36088. 0, //ds offset
  36089. 1, //top left 7.4.3.1.1
  36090. 0, //OR operator
  36091. huffmanTables,
  36092. refinementTemplateIndex, refinementAt,
  36093. decodingContext);
  36094. } else {
  36095. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  36096. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  36097. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  36098. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  36099. newSymbols[symbolId - symbols.length]);
  36100. bitmap = decodeRefinement(currentWidth, currentHeight,
  36101. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  36102. decodingContext);
  36103. }
  36104. } else {
  36105. // 6.5.8.1 Direct-coded symbol bitmap
  36106. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  36107. templateIndex, false, null, at, decodingContext);
  36108. }
  36109. newSymbols.push(bitmap);
  36110. }
  36111. }
  36112. // 6.5.10 Exported symbols
  36113. var exportedSymbols = [];
  36114. var flags = [], currentFlag = false;
  36115. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  36116. while (flags.length < totalSymbolsLength) {
  36117. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  36118. while (runLength--) {
  36119. flags.push(currentFlag);
  36120. }
  36121. currentFlag = !currentFlag;
  36122. }
  36123. for (var i = 0, ii = symbols.length; i < ii; i++) {
  36124. if (flags[i]) {
  36125. exportedSymbols.push(symbols[i]);
  36126. }
  36127. }
  36128. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  36129. if (flags[i]) {
  36130. exportedSymbols.push(newSymbols[j]);
  36131. }
  36132. }
  36133. return exportedSymbols;
  36134. }
  36135. function decodeTextRegion(huffman, refinement, width, height,
  36136. defaultPixelValue, numberOfSymbolInstances,
  36137. stripSize, inputSymbols, symbolCodeLength,
  36138. transposed, dsOffset, referenceCorner,
  36139. combinationOperator, huffmanTables,
  36140. refinementTemplateIndex, refinementAt,
  36141. decodingContext) {
  36142. if (huffman) {
  36143. error('JBIG2 error: huffman is not supported');
  36144. }
  36145. // Prepare bitmap
  36146. var bitmap = [];
  36147. var i, row;
  36148. for (i = 0; i < height; i++) {
  36149. row = new Uint8Array(width);
  36150. if (defaultPixelValue) {
  36151. for (var j = 0; j < width; j++) {
  36152. row[j] = defaultPixelValue;
  36153. }
  36154. }
  36155. bitmap.push(row);
  36156. }
  36157. var decoder = decodingContext.decoder;
  36158. var contextCache = decodingContext.contextCache;
  36159. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36160. var firstS = 0;
  36161. i = 0;
  36162. while (i < numberOfSymbolInstances) {
  36163. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36164. stripT += deltaT;
  36165. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  36166. firstS += deltaFirstS;
  36167. var currentS = firstS;
  36168. do {
  36169. var currentT = (stripSize === 1 ? 0 :
  36170. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  36171. var t = stripSize * stripT + currentT;
  36172. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  36173. var applyRefinement = (refinement &&
  36174. decodeInteger(contextCache, 'IARI', decoder));
  36175. var symbolBitmap = inputSymbols[symbolId];
  36176. var symbolWidth = symbolBitmap[0].length;
  36177. var symbolHeight = symbolBitmap.length;
  36178. if (applyRefinement) {
  36179. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  36180. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  36181. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  36182. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  36183. symbolWidth += rdw;
  36184. symbolHeight += rdh;
  36185. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  36186. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  36187. (rdh >> 1) + rdy, false, refinementAt,
  36188. decodingContext);
  36189. }
  36190. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  36191. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  36192. var s2, t2, symbolRow;
  36193. if (transposed) {
  36194. // Place Symbol Bitmap from T1,S1
  36195. for (s2 = 0; s2 < symbolHeight; s2++) {
  36196. row = bitmap[offsetS + s2];
  36197. if (!row) {
  36198. continue;
  36199. }
  36200. symbolRow = symbolBitmap[s2];
  36201. // To ignore Parts of Symbol bitmap which goes
  36202. // outside bitmap region
  36203. var maxWidth = Math.min(width - offsetT, symbolWidth);
  36204. switch (combinationOperator) {
  36205. case 0: // OR
  36206. for (t2 = 0; t2 < maxWidth; t2++) {
  36207. row[offsetT + t2] |= symbolRow[t2];
  36208. }
  36209. break;
  36210. case 2: // XOR
  36211. for (t2 = 0; t2 < maxWidth; t2++) {
  36212. row[offsetT + t2] ^= symbolRow[t2];
  36213. }
  36214. break;
  36215. default:
  36216. error('JBIG2 error: operator ' + combinationOperator +
  36217. ' is not supported');
  36218. }
  36219. }
  36220. currentS += symbolHeight - 1;
  36221. } else {
  36222. for (t2 = 0; t2 < symbolHeight; t2++) {
  36223. row = bitmap[offsetT + t2];
  36224. if (!row) {
  36225. continue;
  36226. }
  36227. symbolRow = symbolBitmap[t2];
  36228. switch (combinationOperator) {
  36229. case 0: // OR
  36230. for (s2 = 0; s2 < symbolWidth; s2++) {
  36231. row[offsetS + s2] |= symbolRow[s2];
  36232. }
  36233. break;
  36234. case 2: // XOR
  36235. for (s2 = 0; s2 < symbolWidth; s2++) {
  36236. row[offsetS + s2] ^= symbolRow[s2];
  36237. }
  36238. break;
  36239. default:
  36240. error('JBIG2 error: operator ' + combinationOperator +
  36241. ' is not supported');
  36242. }
  36243. }
  36244. currentS += symbolWidth - 1;
  36245. }
  36246. i++;
  36247. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  36248. if (deltaS === null) {
  36249. break; // OOB
  36250. }
  36251. currentS += deltaS + dsOffset;
  36252. } while (true);
  36253. }
  36254. return bitmap;
  36255. }
  36256. function readSegmentHeader(data, start) {
  36257. var segmentHeader = {};
  36258. segmentHeader.number = readUint32(data, start);
  36259. var flags = data[start + 4];
  36260. var segmentType = flags & 0x3F;
  36261. if (!SegmentTypes[segmentType]) {
  36262. error('JBIG2 error: invalid segment type: ' + segmentType);
  36263. }
  36264. segmentHeader.type = segmentType;
  36265. segmentHeader.typeName = SegmentTypes[segmentType];
  36266. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  36267. var pageAssociationFieldSize = !!(flags & 0x40);
  36268. var referredFlags = data[start + 5];
  36269. var referredToCount = (referredFlags >> 5) & 7;
  36270. var retainBits = [referredFlags & 31];
  36271. var position = start + 6;
  36272. if (referredFlags === 7) {
  36273. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  36274. position += 3;
  36275. var bytes = (referredToCount + 7) >> 3;
  36276. retainBits[0] = data[position++];
  36277. while (--bytes > 0) {
  36278. retainBits.push(data[position++]);
  36279. }
  36280. } else if (referredFlags === 5 || referredFlags === 6) {
  36281. error('JBIG2 error: invalid referred-to flags');
  36282. }
  36283. segmentHeader.retainBits = retainBits;
  36284. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  36285. (segmentHeader.number <= 65536 ? 2 : 4));
  36286. var referredTo = [];
  36287. var i, ii;
  36288. for (i = 0; i < referredToCount; i++) {
  36289. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  36290. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  36291. readUint32(data, position)));
  36292. referredTo.push(number);
  36293. position += referredToSegmentNumberSize;
  36294. }
  36295. segmentHeader.referredTo = referredTo;
  36296. if (!pageAssociationFieldSize) {
  36297. segmentHeader.pageAssociation = data[position++];
  36298. } else {
  36299. segmentHeader.pageAssociation = readUint32(data, position);
  36300. position += 4;
  36301. }
  36302. segmentHeader.length = readUint32(data, position);
  36303. position += 4;
  36304. if (segmentHeader.length === 0xFFFFFFFF) {
  36305. // 7.2.7 Segment data length, unknown segment length
  36306. if (segmentType === 38) { // ImmediateGenericRegion
  36307. var genericRegionInfo = readRegionSegmentInformation(data, position);
  36308. var genericRegionSegmentFlags = data[position +
  36309. RegionSegmentInformationFieldLength];
  36310. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  36311. // searching for the segment end
  36312. var searchPatternLength = 6;
  36313. var searchPattern = new Uint8Array(searchPatternLength);
  36314. if (!genericRegionMmr) {
  36315. searchPattern[0] = 0xFF;
  36316. searchPattern[1] = 0xAC;
  36317. }
  36318. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  36319. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  36320. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  36321. searchPattern[5] = genericRegionInfo.height & 0xFF;
  36322. for (i = position, ii = data.length; i < ii; i++) {
  36323. var j = 0;
  36324. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  36325. j++;
  36326. }
  36327. if (j === searchPatternLength) {
  36328. segmentHeader.length = i + searchPatternLength;
  36329. break;
  36330. }
  36331. }
  36332. if (segmentHeader.length === 0xFFFFFFFF) {
  36333. error('JBIG2 error: segment end was not found');
  36334. }
  36335. } else {
  36336. error('JBIG2 error: invalid unknown segment length');
  36337. }
  36338. }
  36339. segmentHeader.headerEnd = position;
  36340. return segmentHeader;
  36341. }
  36342. function readSegments(header, data, start, end) {
  36343. var segments = [];
  36344. var position = start;
  36345. while (position < end) {
  36346. var segmentHeader = readSegmentHeader(data, position);
  36347. position = segmentHeader.headerEnd;
  36348. var segment = {
  36349. header: segmentHeader,
  36350. data: data
  36351. };
  36352. if (!header.randomAccess) {
  36353. segment.start = position;
  36354. position += segmentHeader.length;
  36355. segment.end = position;
  36356. }
  36357. segments.push(segment);
  36358. if (segmentHeader.type === 51) {
  36359. break; // end of file is found
  36360. }
  36361. }
  36362. if (header.randomAccess) {
  36363. for (var i = 0, ii = segments.length; i < ii; i++) {
  36364. segments[i].start = position;
  36365. position += segments[i].header.length;
  36366. segments[i].end = position;
  36367. }
  36368. }
  36369. return segments;
  36370. }
  36371. // 7.4.1 Region segment information field
  36372. function readRegionSegmentInformation(data, start) {
  36373. return {
  36374. width: readUint32(data, start),
  36375. height: readUint32(data, start + 4),
  36376. x: readUint32(data, start + 8),
  36377. y: readUint32(data, start + 12),
  36378. combinationOperator: data[start + 16] & 7
  36379. };
  36380. }
  36381. var RegionSegmentInformationFieldLength = 17;
  36382. function processSegment(segment, visitor) {
  36383. var header = segment.header;
  36384. var data = segment.data, position = segment.start, end = segment.end;
  36385. var args, at, i, atLength;
  36386. switch (header.type) {
  36387. case 0: // SymbolDictionary
  36388. // 7.4.2 Symbol dictionary segment syntax
  36389. var dictionary = {};
  36390. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  36391. dictionary.huffman = !!(dictionaryFlags & 1);
  36392. dictionary.refinement = !!(dictionaryFlags & 2);
  36393. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  36394. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  36395. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  36396. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  36397. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  36398. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  36399. dictionary.template = (dictionaryFlags >> 10) & 3;
  36400. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  36401. position += 2;
  36402. if (!dictionary.huffman) {
  36403. atLength = dictionary.template === 0 ? 4 : 1;
  36404. at = [];
  36405. for (i = 0; i < atLength; i++) {
  36406. at.push({
  36407. x: readInt8(data, position),
  36408. y: readInt8(data, position + 1)
  36409. });
  36410. position += 2;
  36411. }
  36412. dictionary.at = at;
  36413. }
  36414. if (dictionary.refinement && !dictionary.refinementTemplate) {
  36415. at = [];
  36416. for (i = 0; i < 2; i++) {
  36417. at.push({
  36418. x: readInt8(data, position),
  36419. y: readInt8(data, position + 1)
  36420. });
  36421. position += 2;
  36422. }
  36423. dictionary.refinementAt = at;
  36424. }
  36425. dictionary.numberOfExportedSymbols = readUint32(data, position);
  36426. position += 4;
  36427. dictionary.numberOfNewSymbols = readUint32(data, position);
  36428. position += 4;
  36429. args = [dictionary, header.number, header.referredTo,
  36430. data, position, end];
  36431. break;
  36432. case 6: // ImmediateTextRegion
  36433. case 7: // ImmediateLosslessTextRegion
  36434. var textRegion = {};
  36435. textRegion.info = readRegionSegmentInformation(data, position);
  36436. position += RegionSegmentInformationFieldLength;
  36437. var textRegionSegmentFlags = readUint16(data, position);
  36438. position += 2;
  36439. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  36440. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  36441. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  36442. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  36443. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  36444. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  36445. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  36446. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  36447. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  36448. if (textRegion.huffman) {
  36449. var textRegionHuffmanFlags = readUint16(data, position);
  36450. position += 2;
  36451. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  36452. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  36453. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  36454. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  36455. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  36456. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  36457. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  36458. textRegion.huffmanRefinementSizeSelector =
  36459. !!(textRegionHuffmanFlags & 14);
  36460. }
  36461. if (textRegion.refinement && !textRegion.refinementTemplate) {
  36462. at = [];
  36463. for (i = 0; i < 2; i++) {
  36464. at.push({
  36465. x: readInt8(data, position),
  36466. y: readInt8(data, position + 1)
  36467. });
  36468. position += 2;
  36469. }
  36470. textRegion.refinementAt = at;
  36471. }
  36472. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36473. position += 4;
  36474. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36475. if (textRegion.huffman) {
  36476. error('JBIG2 error: huffman is not supported');
  36477. }
  36478. args = [textRegion, header.referredTo, data, position, end];
  36479. break;
  36480. case 38: // ImmediateGenericRegion
  36481. case 39: // ImmediateLosslessGenericRegion
  36482. var genericRegion = {};
  36483. genericRegion.info = readRegionSegmentInformation(data, position);
  36484. position += RegionSegmentInformationFieldLength;
  36485. var genericRegionSegmentFlags = data[position++];
  36486. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36487. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36488. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36489. if (!genericRegion.mmr) {
  36490. atLength = genericRegion.template === 0 ? 4 : 1;
  36491. at = [];
  36492. for (i = 0; i < atLength; i++) {
  36493. at.push({
  36494. x: readInt8(data, position),
  36495. y: readInt8(data, position + 1)
  36496. });
  36497. position += 2;
  36498. }
  36499. genericRegion.at = at;
  36500. }
  36501. args = [genericRegion, data, position, end];
  36502. break;
  36503. case 48: // PageInformation
  36504. var pageInfo = {
  36505. width: readUint32(data, position),
  36506. height: readUint32(data, position + 4),
  36507. resolutionX: readUint32(data, position + 8),
  36508. resolutionY: readUint32(data, position + 12)
  36509. };
  36510. if (pageInfo.height === 0xFFFFFFFF) {
  36511. delete pageInfo.height;
  36512. }
  36513. var pageSegmentFlags = data[position + 16];
  36514. var pageStripingInformatiom = readUint16(data, position + 17);
  36515. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36516. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36517. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36518. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36519. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36520. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36521. args = [pageInfo];
  36522. break;
  36523. case 49: // EndOfPage
  36524. break;
  36525. case 50: // EndOfStripe
  36526. break;
  36527. case 51: // EndOfFile
  36528. break;
  36529. case 62: // 7.4.15 defines 2 extension types which
  36530. // are comments and can be ignored.
  36531. break;
  36532. default:
  36533. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36534. header.type + ') is not implemented');
  36535. }
  36536. var callbackName = 'on' + header.typeName;
  36537. if (callbackName in visitor) {
  36538. visitor[callbackName].apply(visitor, args);
  36539. }
  36540. }
  36541. function processSegments(segments, visitor) {
  36542. for (var i = 0, ii = segments.length; i < ii; i++) {
  36543. processSegment(segments[i], visitor);
  36544. }
  36545. }
  36546. function parseJbig2(data, start, end) {
  36547. var position = start;
  36548. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36549. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36550. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36551. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36552. error('JBIG2 error: invalid header');
  36553. }
  36554. var header = {};
  36555. position += 8;
  36556. var flags = data[position++];
  36557. header.randomAccess = !(flags & 1);
  36558. if (!(flags & 2)) {
  36559. header.numberOfPages = readUint32(data, position);
  36560. position += 4;
  36561. }
  36562. var segments = readSegments(header, data, position, end);
  36563. error('Not implemented');
  36564. // processSegments(segments, new SimpleSegmentVisitor());
  36565. }
  36566. function parseJbig2Chunks(chunks) {
  36567. var visitor = new SimpleSegmentVisitor();
  36568. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36569. var chunk = chunks[i];
  36570. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36571. processSegments(segments, visitor);
  36572. }
  36573. return visitor.buffer;
  36574. }
  36575. function SimpleSegmentVisitor() {}
  36576. SimpleSegmentVisitor.prototype = {
  36577. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36578. this.currentPageInfo = info;
  36579. var rowSize = (info.width + 7) >> 3;
  36580. var buffer = new Uint8Array(rowSize * info.height);
  36581. // The contents of ArrayBuffers are initialized to 0.
  36582. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36583. if (info.defaultPixelValue) {
  36584. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36585. buffer[i] = 0xFF;
  36586. }
  36587. }
  36588. this.buffer = buffer;
  36589. },
  36590. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36591. var pageInfo = this.currentPageInfo;
  36592. var width = regionInfo.width, height = regionInfo.height;
  36593. var rowSize = (pageInfo.width + 7) >> 3;
  36594. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36595. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36596. var buffer = this.buffer;
  36597. var mask0 = 128 >> (regionInfo.x & 7);
  36598. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36599. var i, j, mask, offset;
  36600. switch (combinationOperator) {
  36601. case 0: // OR
  36602. for (i = 0; i < height; i++) {
  36603. mask = mask0;
  36604. offset = offset0;
  36605. for (j = 0; j < width; j++) {
  36606. if (bitmap[i][j]) {
  36607. buffer[offset] |= mask;
  36608. }
  36609. mask >>= 1;
  36610. if (!mask) {
  36611. mask = 128;
  36612. offset++;
  36613. }
  36614. }
  36615. offset0 += rowSize;
  36616. }
  36617. break;
  36618. case 2: // XOR
  36619. for (i = 0; i < height; i++) {
  36620. mask = mask0;
  36621. offset = offset0;
  36622. for (j = 0; j < width; j++) {
  36623. if (bitmap[i][j]) {
  36624. buffer[offset] ^= mask;
  36625. }
  36626. mask >>= 1;
  36627. if (!mask) {
  36628. mask = 128;
  36629. offset++;
  36630. }
  36631. }
  36632. offset0 += rowSize;
  36633. }
  36634. break;
  36635. default:
  36636. error('JBIG2 error: operator ' + combinationOperator +
  36637. ' is not supported');
  36638. }
  36639. },
  36640. onImmediateGenericRegion:
  36641. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36642. start, end) {
  36643. var regionInfo = region.info;
  36644. var decodingContext = new DecodingContext(data, start, end);
  36645. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36646. region.template, region.prediction, null,
  36647. region.at, decodingContext);
  36648. this.drawBitmap(regionInfo, bitmap);
  36649. },
  36650. onImmediateLosslessGenericRegion:
  36651. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36652. this.onImmediateGenericRegion.apply(this, arguments);
  36653. },
  36654. onSymbolDictionary:
  36655. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36656. currentSegment,
  36657. referredSegments,
  36658. data, start, end) {
  36659. var huffmanTables;
  36660. if (dictionary.huffman) {
  36661. error('JBIG2 error: huffman is not supported');
  36662. }
  36663. // Combines exported symbols from all referred segments
  36664. var symbols = this.symbols;
  36665. if (!symbols) {
  36666. this.symbols = symbols = {};
  36667. }
  36668. var inputSymbols = [];
  36669. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36670. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36671. }
  36672. var decodingContext = new DecodingContext(data, start, end);
  36673. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36674. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36675. dictionary.numberOfExportedSymbols, huffmanTables,
  36676. dictionary.template, dictionary.at,
  36677. dictionary.refinementTemplate, dictionary.refinementAt,
  36678. decodingContext);
  36679. },
  36680. onImmediateTextRegion:
  36681. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36682. referredSegments,
  36683. data, start, end) {
  36684. var regionInfo = region.info;
  36685. var huffmanTables;
  36686. // Combines exported symbols from all referred segments
  36687. var symbols = this.symbols;
  36688. var inputSymbols = [];
  36689. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36690. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36691. }
  36692. var symbolCodeLength = log2(inputSymbols.length);
  36693. var decodingContext = new DecodingContext(data, start, end);
  36694. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36695. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36696. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36697. symbolCodeLength, region.transposed, region.dsOffset,
  36698. region.referenceCorner, region.combinationOperator, huffmanTables,
  36699. region.refinementTemplate, region.refinementAt, decodingContext);
  36700. this.drawBitmap(regionInfo, bitmap);
  36701. },
  36702. onImmediateLosslessTextRegion:
  36703. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36704. this.onImmediateTextRegion.apply(this, arguments);
  36705. }
  36706. };
  36707. function Jbig2Image() {}
  36708. Jbig2Image.prototype = {
  36709. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36710. return parseJbig2Chunks(chunks);
  36711. }
  36712. };
  36713. return Jbig2Image;
  36714. })();
  36715. var bidi = PDFJS.bidi = (function bidiClosure() {
  36716. // Character types for symbols from 0000 to 00FF.
  36717. var baseTypes = [
  36718. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36719. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36720. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36721. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36722. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36723. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36724. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36725. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36726. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36727. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36728. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36729. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36730. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36731. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36732. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36733. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36734. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36735. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36736. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36737. ];
  36738. // Character types for symbols from 0600 to 06FF
  36739. var arabicTypes = [
  36740. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36741. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36742. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36743. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36744. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36745. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36746. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36747. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36748. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36749. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36750. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36751. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36752. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36753. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36754. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36755. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36756. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36757. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36758. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36759. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36760. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36761. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36762. ];
  36763. function isOdd(i) {
  36764. return (i & 1) !== 0;
  36765. }
  36766. function isEven(i) {
  36767. return (i & 1) === 0;
  36768. }
  36769. function findUnequal(arr, start, value) {
  36770. for (var j = start, jj = arr.length; j < jj; ++j) {
  36771. if (arr[j] !== value) {
  36772. return j;
  36773. }
  36774. }
  36775. return j;
  36776. }
  36777. function setValues(arr, start, end, value) {
  36778. for (var j = start; j < end; ++j) {
  36779. arr[j] = value;
  36780. }
  36781. }
  36782. function reverseValues(arr, start, end) {
  36783. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36784. var temp = arr[i];
  36785. arr[i] = arr[j];
  36786. arr[j] = temp;
  36787. }
  36788. }
  36789. function createBidiText(str, isLTR, vertical) {
  36790. return {
  36791. str: str,
  36792. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36793. };
  36794. }
  36795. // These are used in bidi(), which is called frequently. We re-use them on
  36796. // each call to avoid unnecessary allocations.
  36797. var chars = [];
  36798. var types = [];
  36799. function bidi(str, startLevel, vertical) {
  36800. var isLTR = true;
  36801. var strLength = str.length;
  36802. if (strLength === 0 || vertical) {
  36803. return createBidiText(str, isLTR, vertical);
  36804. }
  36805. // Get types and fill arrays
  36806. chars.length = strLength;
  36807. types.length = strLength;
  36808. var numBidi = 0;
  36809. var i, ii;
  36810. for (i = 0; i < strLength; ++i) {
  36811. chars[i] = str.charAt(i);
  36812. var charCode = str.charCodeAt(i);
  36813. var charType = 'L';
  36814. if (charCode <= 0x00ff) {
  36815. charType = baseTypes[charCode];
  36816. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36817. charType = 'R';
  36818. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36819. charType = arabicTypes[charCode & 0xff];
  36820. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36821. charType = 'AL';
  36822. }
  36823. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36824. numBidi++;
  36825. }
  36826. types[i] = charType;
  36827. }
  36828. // Detect the bidi method
  36829. // - If there are no rtl characters then no bidi needed
  36830. // - If less than 30% chars are rtl then string is primarily ltr
  36831. // - If more than 30% chars are rtl then string is primarily rtl
  36832. if (numBidi === 0) {
  36833. isLTR = true;
  36834. return createBidiText(str, isLTR);
  36835. }
  36836. if (startLevel === -1) {
  36837. if ((strLength / numBidi) < 0.3) {
  36838. isLTR = true;
  36839. startLevel = 0;
  36840. } else {
  36841. isLTR = false;
  36842. startLevel = 1;
  36843. }
  36844. }
  36845. var levels = [];
  36846. for (i = 0; i < strLength; ++i) {
  36847. levels[i] = startLevel;
  36848. }
  36849. /*
  36850. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36851. */
  36852. var e = (isOdd(startLevel) ? 'R' : 'L');
  36853. var sor = e;
  36854. var eor = sor;
  36855. /*
  36856. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36857. type of the NSM to the type of the previous character. If the NSM is at the
  36858. start of the level run, it will get the type of sor.
  36859. */
  36860. var lastType = sor;
  36861. for (i = 0; i < strLength; ++i) {
  36862. if (types[i] === 'NSM') {
  36863. types[i] = lastType;
  36864. } else {
  36865. lastType = types[i];
  36866. }
  36867. }
  36868. /*
  36869. W2. Search backwards from each instance of a European number until the
  36870. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36871. the type of the European number to Arabic number.
  36872. */
  36873. lastType = sor;
  36874. var t;
  36875. for (i = 0; i < strLength; ++i) {
  36876. t = types[i];
  36877. if (t === 'EN') {
  36878. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36879. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36880. lastType = t;
  36881. }
  36882. }
  36883. /*
  36884. W3. Change all ALs to R.
  36885. */
  36886. for (i = 0; i < strLength; ++i) {
  36887. t = types[i];
  36888. if (t === 'AL') {
  36889. types[i] = 'R';
  36890. }
  36891. }
  36892. /*
  36893. W4. A single European separator between two European numbers changes to a
  36894. European number. A single common separator between two numbers of the same
  36895. type changes to that type:
  36896. */
  36897. for (i = 1; i < strLength - 1; ++i) {
  36898. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36899. types[i] = 'EN';
  36900. }
  36901. if (types[i] === 'CS' &&
  36902. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36903. types[i + 1] === types[i - 1]) {
  36904. types[i] = types[i - 1];
  36905. }
  36906. }
  36907. /*
  36908. W5. A sequence of European terminators adjacent to European numbers changes
  36909. to all European numbers:
  36910. */
  36911. for (i = 0; i < strLength; ++i) {
  36912. if (types[i] === 'EN') {
  36913. // do before
  36914. var j;
  36915. for (j = i - 1; j >= 0; --j) {
  36916. if (types[j] !== 'ET') {
  36917. break;
  36918. }
  36919. types[j] = 'EN';
  36920. }
  36921. // do after
  36922. for (j = i + 1; j < strLength; --j) {
  36923. if (types[j] !== 'ET') {
  36924. break;
  36925. }
  36926. types[j] = 'EN';
  36927. }
  36928. }
  36929. }
  36930. /*
  36931. W6. Otherwise, separators and terminators change to Other Neutral:
  36932. */
  36933. for (i = 0; i < strLength; ++i) {
  36934. t = types[i];
  36935. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36936. types[i] = 'ON';
  36937. }
  36938. }
  36939. /*
  36940. W7. Search backwards from each instance of a European number until the
  36941. first strong type (R, L, or sor) is found. If an L is found, then change
  36942. the type of the European number to L.
  36943. */
  36944. lastType = sor;
  36945. for (i = 0; i < strLength; ++i) {
  36946. t = types[i];
  36947. if (t === 'EN') {
  36948. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36949. } else if (t === 'R' || t === 'L') {
  36950. lastType = t;
  36951. }
  36952. }
  36953. /*
  36954. N1. A sequence of neutrals takes the direction of the surrounding strong
  36955. text if the text on both sides has the same direction. European and Arabic
  36956. numbers are treated as though they were R. Start-of-level-run (sor) and
  36957. end-of-level-run (eor) are used at level run boundaries.
  36958. */
  36959. for (i = 0; i < strLength; ++i) {
  36960. if (types[i] === 'ON') {
  36961. var end = findUnequal(types, i + 1, 'ON');
  36962. var before = sor;
  36963. if (i > 0) {
  36964. before = types[i - 1];
  36965. }
  36966. var after = eor;
  36967. if (end + 1 < strLength) {
  36968. after = types[end + 1];
  36969. }
  36970. if (before !== 'L') {
  36971. before = 'R';
  36972. }
  36973. if (after !== 'L') {
  36974. after = 'R';
  36975. }
  36976. if (before === after) {
  36977. setValues(types, i, end, before);
  36978. }
  36979. i = end - 1; // reset to end (-1 so next iteration is ok)
  36980. }
  36981. }
  36982. /*
  36983. N2. Any remaining neutrals take the embedding direction.
  36984. */
  36985. for (i = 0; i < strLength; ++i) {
  36986. if (types[i] === 'ON') {
  36987. types[i] = e;
  36988. }
  36989. }
  36990. /*
  36991. I1. For all characters with an even (left-to-right) embedding direction,
  36992. those of type R go up one level and those of type AN or EN go up two
  36993. levels.
  36994. I2. For all characters with an odd (right-to-left) embedding direction,
  36995. those of type L, EN or AN go up one level.
  36996. */
  36997. for (i = 0; i < strLength; ++i) {
  36998. t = types[i];
  36999. if (isEven(levels[i])) {
  37000. if (t === 'R') {
  37001. levels[i] += 1;
  37002. } else if (t === 'AN' || t === 'EN') {
  37003. levels[i] += 2;
  37004. }
  37005. } else { // isOdd
  37006. if (t === 'L' || t === 'AN' || t === 'EN') {
  37007. levels[i] += 1;
  37008. }
  37009. }
  37010. }
  37011. /*
  37012. L1. On each line, reset the embedding level of the following characters to
  37013. the paragraph embedding level:
  37014. segment separators,
  37015. paragraph separators,
  37016. any sequence of whitespace characters preceding a segment separator or
  37017. paragraph separator, and any sequence of white space characters at the end
  37018. of the line.
  37019. */
  37020. // don't bother as text is only single line
  37021. /*
  37022. L2. From the highest level found in the text to the lowest odd level on
  37023. each line, reverse any contiguous sequence of characters that are at that
  37024. level or higher.
  37025. */
  37026. // find highest level & lowest odd level
  37027. var highestLevel = -1;
  37028. var lowestOddLevel = 99;
  37029. var level;
  37030. for (i = 0, ii = levels.length; i < ii; ++i) {
  37031. level = levels[i];
  37032. if (highestLevel < level) {
  37033. highestLevel = level;
  37034. }
  37035. if (lowestOddLevel > level && isOdd(level)) {
  37036. lowestOddLevel = level;
  37037. }
  37038. }
  37039. // now reverse between those limits
  37040. for (level = highestLevel; level >= lowestOddLevel; --level) {
  37041. // find segments to reverse
  37042. var start = -1;
  37043. for (i = 0, ii = levels.length; i < ii; ++i) {
  37044. if (levels[i] < level) {
  37045. if (start >= 0) {
  37046. reverseValues(chars, start, i);
  37047. start = -1;
  37048. }
  37049. } else if (start < 0) {
  37050. start = i;
  37051. }
  37052. }
  37053. if (start >= 0) {
  37054. reverseValues(chars, start, levels.length);
  37055. }
  37056. }
  37057. /*
  37058. L3. Combining marks applied to a right-to-left base character will at this
  37059. point precede their base character. If the rendering engine expects them to
  37060. follow the base characters in the final display process, then the ordering
  37061. of the marks and the base character must be reversed.
  37062. */
  37063. // don't bother for now
  37064. /*
  37065. L4. A character that possesses the mirrored property as specified by
  37066. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  37067. directionality of that character is R.
  37068. */
  37069. // don't mirror as characters are already mirrored in the pdf
  37070. // Finally, return string
  37071. for (i = 0, ii = chars.length; i < ii; ++i) {
  37072. var ch = chars[i];
  37073. if (ch === '<' || ch === '>') {
  37074. chars[i] = '';
  37075. }
  37076. }
  37077. return createBidiText(chars.join(''), isLTR);
  37078. }
  37079. return bidi;
  37080. })();
  37081. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  37082. // Workaround for missing math precison in JS.
  37083. var MASK_HIGH = 0xffff0000;
  37084. var MASK_LOW = 0xffff;
  37085. function MurmurHash3_64 (seed) {
  37086. var SEED = 0xc3d2e1f0;
  37087. this.h1 = seed ? seed & 0xffffffff : SEED;
  37088. this.h2 = seed ? seed & 0xffffffff : SEED;
  37089. }
  37090. var alwaysUseUint32ArrayView = false;
  37091. // old webkits have issues with non-aligned arrays
  37092. try {
  37093. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  37094. } catch (e) {
  37095. alwaysUseUint32ArrayView = true;
  37096. }
  37097. MurmurHash3_64.prototype = {
  37098. update: function MurmurHash3_64_update(input) {
  37099. var useUint32ArrayView = alwaysUseUint32ArrayView;
  37100. var i;
  37101. if (typeof input === 'string') {
  37102. var data = new Uint8Array(input.length * 2);
  37103. var length = 0;
  37104. for (i = 0; i < input.length; i++) {
  37105. var code = input.charCodeAt(i);
  37106. if (code <= 0xff) {
  37107. data[length++] = code;
  37108. }
  37109. else {
  37110. data[length++] = code >>> 8;
  37111. data[length++] = code & 0xff;
  37112. }
  37113. }
  37114. } else if (input instanceof Uint8Array) {
  37115. data = input;
  37116. length = data.length;
  37117. } else if (typeof input === 'object' && ('length' in input)) {
  37118. // processing regular arrays as well, e.g. for IE9
  37119. data = input;
  37120. length = data.length;
  37121. useUint32ArrayView = true;
  37122. } else {
  37123. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  37124. 'Input must be a string or array.');
  37125. }
  37126. var blockCounts = length >> 2;
  37127. var tailLength = length - blockCounts * 4;
  37128. // we don't care about endianness here
  37129. var dataUint32 = useUint32ArrayView ?
  37130. new Uint32ArrayView(data, blockCounts) :
  37131. new Uint32Array(data.buffer, 0, blockCounts);
  37132. var k1 = 0;
  37133. var k2 = 0;
  37134. var h1 = this.h1;
  37135. var h2 = this.h2;
  37136. var C1 = 0xcc9e2d51;
  37137. var C2 = 0x1b873593;
  37138. var C1_LOW = C1 & MASK_LOW;
  37139. var C2_LOW = C2 & MASK_LOW;
  37140. for (i = 0; i < blockCounts; i++) {
  37141. if (i & 1) {
  37142. k1 = dataUint32[i];
  37143. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37144. k1 = k1 << 15 | k1 >>> 17;
  37145. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37146. h1 ^= k1;
  37147. h1 = h1 << 13 | h1 >>> 19;
  37148. h1 = h1 * 5 + 0xe6546b64;
  37149. } else {
  37150. k2 = dataUint32[i];
  37151. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  37152. k2 = k2 << 15 | k2 >>> 17;
  37153. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  37154. h2 ^= k2;
  37155. h2 = h2 << 13 | h2 >>> 19;
  37156. h2 = h2 * 5 + 0xe6546b64;
  37157. }
  37158. }
  37159. k1 = 0;
  37160. switch (tailLength) {
  37161. case 3:
  37162. k1 ^= data[blockCounts * 4 + 2] << 16;
  37163. /* falls through */
  37164. case 2:
  37165. k1 ^= data[blockCounts * 4 + 1] << 8;
  37166. /* falls through */
  37167. case 1:
  37168. k1 ^= data[blockCounts * 4];
  37169. /* falls through */
  37170. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37171. k1 = k1 << 15 | k1 >>> 17;
  37172. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37173. if (blockCounts & 1) {
  37174. h1 ^= k1;
  37175. } else {
  37176. h2 ^= k1;
  37177. }
  37178. }
  37179. this.h1 = h1;
  37180. this.h2 = h2;
  37181. return this;
  37182. },
  37183. hexdigest: function MurmurHash3_64_hexdigest () {
  37184. var h1 = this.h1;
  37185. var h2 = this.h2;
  37186. h1 ^= h2 >>> 1;
  37187. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  37188. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  37189. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  37190. h1 ^= h2 >>> 1;
  37191. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  37192. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  37193. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  37194. h1 ^= h2 >>> 1;
  37195. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  37196. var hex = (arr[i] >>> 0).toString(16);
  37197. while (hex.length < 8) {
  37198. hex = '0' + hex;
  37199. }
  37200. str += hex;
  37201. }
  37202. return str;
  37203. }
  37204. };
  37205. return MurmurHash3_64;
  37206. })();
  37207. }).call((typeof window === 'undefined') ? this : window);
  37208. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  37209. // workerSrc is not set -- using last script url to define default location
  37210. PDFJS.workerSrc = (function () {
  37211. 'use strict';
  37212. var scriptTagContainer = document.body ||
  37213. document.getElementsByTagName('head')[0];
  37214. var pdfjsSrc = scriptTagContainer.lastChild.src;
  37215. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  37216. })();
  37217. }